@or-sdk/cards 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Cards.ts CHANGED
@@ -1,27 +1,47 @@
1
- import { List, makeList } from '@or-sdk/base';
2
- import { DataHubSvc, setDiff } from '@or-sdk/data-hub-svc';
3
- import { CardsConfig, Card, ListCardsParams, PaginationOptions } from './types';
1
+ import { List } from '@or-sdk/base';
2
+ import { DataHub, GraphqlResponse, GraphqlResponseCheckExecution, GraphqlResponseDelete, OperationNames } from '@or-sdk/data-hub';
3
+ import { CardsConfig, Card } from './types';
4
+ import {
5
+ ENTITY_NAME,
6
+ QUERY_LIST,
7
+ QUERY_GET,
8
+ QUERY_CREATE,
9
+ QUERY_UPDATE,
10
+ QUERY_DELETE,
11
+ QUERY_LIST_CROSSACCOUNT,
12
+ QUERY_GET_CROSSACCOUNT,
13
+ QUERY_CREATE_CROSSACCOUNT,
14
+ QUERY_UPDATE_CROSSACCOUNT,
15
+ } from './constants';
4
16
  import { Tags, Taggable, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
5
17
 
6
18
  export class Cards implements Taggable<Card> {
7
- private readonly dataHubSvc: DataHubSvc;
19
+ private readonly dataHub: DataHub;
8
20
  private readonly tags: Tags;
9
21
 
10
22
  constructor(params: CardsConfig) {
11
- const { token, discoveryUrl, accountId, dataHubSvcUrl } = params;
23
+ const { token, discoveryUrl, accountId, dataHubUrl } = params;
12
24
 
13
- this.dataHubSvc = new DataHubSvc({
25
+ this.dataHub = new DataHub({
14
26
  token,
15
27
  discoveryUrl,
16
28
  accountId,
17
- dataHubSvcUrl,
29
+ dataHubUrl,
18
30
  });
19
31
  this.tags = new Tags({
20
32
  token,
21
33
  discoveryUrl,
22
34
  accountId,
23
- dataHubSvcUrl,
35
+ dataHubUrl,
24
36
  });
37
+
38
+ }
39
+
40
+ async init() {
41
+ await Promise.all([
42
+ this.dataHub.init(),
43
+ this.tags.init(),
44
+ ]);
25
45
  }
26
46
 
27
47
  /**
@@ -30,18 +50,27 @@ export class Cards implements Taggable<Card> {
30
50
  * const cardList = await cards.listCards();
31
51
  * ```
32
52
  */
33
- public async listCards(params: ListCardsParams = {}, paginationOptions: PaginationOptions = {}): Promise<List<Card>> {
34
- const result = await this.dataHubSvc.makeRequest<Card[]>({
35
- method: 'POST',
36
- route: 'get-cards',
53
+ public async listCards(): Promise<List<Card>> {
54
+ const variables = {
55
+ entity: ENTITY_NAME,
37
56
  params: {
38
- ...params,
39
- ...paginationOptions,
40
- ... this.dataHubSvc.isCrossAccount ? { accountId: this.dataHubSvc.currentAccountId } : {},
57
+ queryParams: {},
58
+ includeDeleted: false,
59
+ includeExisting: true,
60
+ limit: 30,
41
61
  },
42
- });
62
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false },
63
+ };
64
+
65
+ const operationName = this.dataHub.getOperationName(OperationNames.LIST);
66
+
67
+ const data = {
68
+ operationName,
69
+ query: this.dataHub.isCrossAccount ? QUERY_LIST_CROSSACCOUNT : QUERY_LIST,
70
+ variables,
71
+ };
43
72
 
44
- return makeList<Card>(result);
73
+ return this.dataHub.getFullList<Card>('POST', '/graphql', data);
45
74
  }
46
75
 
47
76
  /**
@@ -51,13 +80,31 @@ export class Cards implements Taggable<Card> {
51
80
  * ```
52
81
  */
53
82
  public async getCard(id: string): Promise<Card> {
54
- return this.dataHubSvc.makeRequest<Card>({
55
- method: 'GET',
56
- route: `cards/${id}`,
83
+ const variables = {
84
+ entity: ENTITY_NAME,
57
85
  params: {
58
- ... this.dataHubSvc.isCrossAccount ? { accountId: this.dataHubSvc.currentAccountId } : {},
86
+ id,
87
+ includeDeleted: false,
88
+ includeExisting: true,
59
89
  },
90
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
91
+ };
92
+
93
+ const operationName = this.dataHub.getOperationName(OperationNames.GET);
94
+
95
+ const data = {
96
+ operationName,
97
+ query: this.dataHub.isCrossAccount ? QUERY_GET_CROSSACCOUNT : QUERY_GET,
98
+ variables,
99
+ };
100
+
101
+ const result = await this.dataHub.makeRequest<GraphqlResponse<Card>>({
102
+ method: 'POST',
103
+ route: '/graphql',
104
+ data,
60
105
  });
106
+
107
+ return result.data[operationName] as Card;
61
108
  }
62
109
 
63
110
  /**
@@ -69,7 +116,7 @@ export class Cards implements Taggable<Card> {
69
116
  * ```
70
117
  */
71
118
  public async saveCard(source: Card): Promise<Card> {
72
- return (source.id && source.id !== 'new') ? this.updateCard(source) : this.createCard(source);
119
+ return source.id ? this.updateCard(source) : this.createCard(source);
73
120
  }
74
121
 
75
122
  /**
@@ -79,21 +126,29 @@ export class Cards implements Taggable<Card> {
79
126
  * ```
80
127
  */
81
128
  public async createCard(source: Card): Promise<Card> {
82
- const result = await this.dataHubSvc.makeRequest<{ id: string; }>({
83
- method: 'POST',
84
- route: 'cards/new',
129
+ const variables = {
130
+ entity: ENTITY_NAME,
85
131
  data: {
86
- card: {
87
- ...source,
88
- id: 'new', //TODO: remove later
89
- },
90
- },
91
- params: {
92
- ... this.dataHubSvc.isCrossAccount ? { accountId: this.dataHubSvc.currentAccountId } : {},
132
+ body: source,
93
133
  },
134
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
135
+ };
136
+
137
+ const operationName = this.dataHub.getOperationName(OperationNames.CREATE);
138
+
139
+ const data = {
140
+ operationName,
141
+ query: this.dataHub.isCrossAccount ? QUERY_CREATE_CROSSACCOUNT : QUERY_CREATE,
142
+ variables,
143
+ };
144
+
145
+ const result = await this.dataHub.makeRequest<GraphqlResponse<Card>>({
146
+ method: 'POST',
147
+ route: '/graphql',
148
+ data,
94
149
  });
95
150
 
96
- return setDiff<Card>(source, result);
151
+ return result.data[operationName] as Card;
97
152
  }
98
153
 
99
154
  /**
@@ -103,18 +158,30 @@ export class Cards implements Taggable<Card> {
103
158
  * ```
104
159
  */
105
160
  public async updateCard(source: Card): Promise<Card> {
106
- const result = await this.dataHubSvc.makeRequest<{ id: string; }>({
107
- method: 'POST',
108
- route: `cards/${source.id}`,
161
+ const variables = {
162
+ entity: ENTITY_NAME,
109
163
  data: {
110
- card: source,
111
- },
112
- params: {
113
- ... this.dataHubSvc.isCrossAccount ? { accountId: this.dataHubSvc.currentAccountId } : {},
164
+ id: source.id,
165
+ body: source,
114
166
  },
167
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
168
+ };
169
+
170
+ const operationName = this.dataHub.getOperationName(OperationNames.UPDATE);
171
+
172
+ const data = {
173
+ operationName,
174
+ query: this.dataHub.isCrossAccount ? QUERY_UPDATE_CROSSACCOUNT : QUERY_UPDATE,
175
+ variables,
176
+ };
177
+
178
+ const result = await this.dataHub.makeRequest<GraphqlResponse<Card>>({
179
+ method: 'POST',
180
+ route: '/graphql',
181
+ data,
115
182
  });
116
183
 
117
- return setDiff<Card>(source, result);
184
+ return result.data[operationName] as Card;
118
185
  }
119
186
 
120
187
  /**
@@ -123,52 +190,34 @@ export class Cards implements Taggable<Card> {
123
190
  * await cards.deleteCard('card-id');
124
191
  * ```
125
192
  */
126
- public async deleteCard(cardId: string, temporarily = true): Promise<void> {
127
- return this.dataHubSvc.makeRequest<void>({
128
- method: 'DELETE',
129
- route: `cards/${cardId}`,
193
+ public async deleteCard(cardId: string): Promise<GraphqlResponseCheckExecution> {
194
+ if (this.dataHub.isCrossAccount) {
195
+ throw Error('Cross-account deleting is not implemented.');
196
+ }
197
+
198
+ const variables = {
199
+ entity: ENTITY_NAME,
130
200
  data: {
131
- temporarily,
132
- },
133
- params: {
134
- ... this.dataHubSvc.isCrossAccount ? { accountId: this.dataHubSvc.currentAccountId } : {},
201
+ id: cardId,
202
+ subscribe: true,
135
203
  },
136
- });
137
- }
204
+ };
138
205
 
139
- /**
140
- * Recover card
141
- * ```typescript
142
- * await cards.recoverCard('card-id');
143
- * ```
144
- */
145
- public async recoverCard(cardId: string): Promise<void> {
146
- return this.dataHubSvc.makeRequest<void>({
147
- method: 'PATCH',
148
- route: `cards/${cardId}`,
149
- params: {
150
- ... this.dataHubSvc.isCrossAccount ? { accountId: this.dataHubSvc.currentAccountId } : {},
151
- },
152
- });
153
- }
206
+ const operationName = this.dataHub.getOperationName(OperationNames.DELETE_TEMPORARILY);
154
207
 
155
- /**
156
- * Clone card
157
- * ```typescript
158
- * const result = await cards.cloneCard('card-id');
159
- * ```
160
- */
161
- public async cloneCard(cardId: string, keepTemplateDetails = true): Promise<Card> {
162
- return this.dataHubSvc.makeRequest<Card>({
163
- method: 'PUT',
164
- route: `cards/${cardId}`,
165
- data: {
166
- keepTemplateDetails,
167
- },
168
- params: {
169
- ... this.dataHubSvc.isCrossAccount ? { accountId: this.dataHubSvc.currentAccountId } : {},
170
- },
208
+ const data = {
209
+ operationName,
210
+ query: QUERY_DELETE,
211
+ variables,
212
+ };
213
+
214
+ const result = await this.dataHub.makeRequest<GraphqlResponse<void>>({
215
+ method: 'POST',
216
+ route: '/graphql',
217
+ data,
171
218
  });
219
+
220
+ return this.dataHub.subscribe((result.data[operationName] as GraphqlResponseDelete).requestId);
172
221
  }
173
222
 
174
223
  /**
@@ -220,5 +269,4 @@ export class Cards implements Taggable<Card> {
220
269
  },
221
270
  });
222
271
  }
223
-
224
272
  }
package/src/constants.ts CHANGED
@@ -1 +1,376 @@
1
- export { DATA_HUB_SVC_SERVICE_KEY } from '@or-sdk/data-hub-svc';
1
+ export { DATA_HUB_SERVICE_KEY } from '@or-sdk/data-hub';
2
+
3
+ export const QUERY_LIST = `query list($entity: EntityType!, $params: ListInput!, $sandbox: Boolean) {
4
+ list(entity: $entity, params: $params, sandbox: $sandbox) {
5
+ records {
6
+ ... on Card {
7
+ id
8
+ schemaVersion
9
+ dateCreated
10
+ dateModified
11
+ data {
12
+ data
13
+ form {
14
+ code
15
+ data
16
+ style
17
+ template
18
+ }
19
+ presentation {
20
+ code
21
+ data
22
+ style
23
+ template
24
+ }
25
+ tagIds
26
+ }
27
+ reference {
28
+ id
29
+ type
30
+ }
31
+ template {
32
+ category
33
+ description
34
+ help
35
+ icon
36
+ iconUrl
37
+ implicitly
38
+ label
39
+ publishedBy
40
+ tags
41
+ type
42
+ version
43
+ }
44
+ }
45
+ }
46
+ last
47
+ }
48
+ }
49
+ `;
50
+
51
+ export const QUERY_LIST_CROSSACCOUNT = `query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {
52
+ listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
53
+ records {
54
+ ... on Card {
55
+ id
56
+ schemaVersion
57
+ dateCreated
58
+ dateModified
59
+ data {
60
+ data
61
+ form {
62
+ code
63
+ data
64
+ style
65
+ template
66
+ }
67
+ presentation {
68
+ code
69
+ data
70
+ style
71
+ template
72
+ }
73
+ tagIds
74
+ }
75
+ reference {
76
+ id
77
+ type
78
+ }
79
+ template {
80
+ category
81
+ description
82
+ help
83
+ icon
84
+ iconUrl
85
+ implicitly
86
+ label
87
+ publishedBy
88
+ tags
89
+ type
90
+ version
91
+ }
92
+ }
93
+ }
94
+ last
95
+ }
96
+ }
97
+ `;
98
+
99
+ export const QUERY_GET = `query get($entity: EntityType!, $params: GetInput!) {
100
+ get(entity: $entity, params: $params) {
101
+ ... on Card {
102
+ id
103
+ schemaVersion
104
+ dateCreated
105
+ dateModified
106
+ data {
107
+ data
108
+ form {
109
+ code
110
+ data
111
+ style
112
+ template
113
+ }
114
+ presentation {
115
+ code
116
+ data
117
+ style
118
+ template
119
+ }
120
+ tagIds
121
+ }
122
+ reference {
123
+ id
124
+ type
125
+ }
126
+ template {
127
+ category
128
+ description
129
+ help
130
+ icon
131
+ iconUrl
132
+ implicitly
133
+ label
134
+ publishedBy
135
+ tags
136
+ type
137
+ version
138
+ }
139
+ }
140
+ }
141
+ }
142
+ `;
143
+
144
+ export const QUERY_GET_CROSSACCOUNT = `query getCrossAccount($entity: EntityType!, $params: GetInput!, $accountId: String!) {
145
+ getCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
146
+ ... on Card {
147
+ id
148
+ schemaVersion
149
+ dateCreated
150
+ dateModified
151
+ data {
152
+ data
153
+ form {
154
+ code
155
+ data
156
+ style
157
+ template
158
+ }
159
+ presentation {
160
+ code
161
+ data
162
+ style
163
+ template
164
+ }
165
+ tagIds
166
+ }
167
+ reference {
168
+ id
169
+ type
170
+ }
171
+ template {
172
+ category
173
+ description
174
+ help
175
+ icon
176
+ iconUrl
177
+ implicitly
178
+ label
179
+ publishedBy
180
+ tags
181
+ type
182
+ version
183
+ }
184
+ }
185
+ }
186
+ }
187
+ `;
188
+
189
+ export const QUERY_CREATE = `mutation create($entity: EntityType!, $data: CreateInput!) {
190
+ create(entity: $entity, data: $data) {
191
+ ... on Card {
192
+ id
193
+ schemaVersion
194
+ dateCreated
195
+ dateModified
196
+ data {
197
+ data
198
+ form {
199
+ code
200
+ data
201
+ style
202
+ template
203
+ }
204
+ presentation {
205
+ code
206
+ data
207
+ style
208
+ template
209
+ }
210
+ tagIds
211
+ }
212
+ reference {
213
+ id
214
+ type
215
+ }
216
+ template {
217
+ category
218
+ description
219
+ help
220
+ icon
221
+ iconUrl
222
+ implicitly
223
+ label
224
+ publishedBy
225
+ tags
226
+ type
227
+ version
228
+ }
229
+ }
230
+ }
231
+ }
232
+ `;
233
+
234
+ export const QUERY_CREATE_CROSSACCOUNT = `mutation createCrossAccount($entity: EntityType!, $data: CreateInput!, $accountId: String!) {
235
+ createCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
236
+ ... on Card {
237
+ id
238
+ schemaVersion
239
+ dateCreated
240
+ dateModified
241
+ data {
242
+ data
243
+ form {
244
+ code
245
+ data
246
+ style
247
+ template
248
+ }
249
+ presentation {
250
+ code
251
+ data
252
+ style
253
+ template
254
+ }
255
+ tagIds
256
+ }
257
+ reference {
258
+ id
259
+ type
260
+ }
261
+ template {
262
+ category
263
+ description
264
+ help
265
+ icon
266
+ iconUrl
267
+ implicitly
268
+ label
269
+ publishedBy
270
+ tags
271
+ type
272
+ version
273
+ }
274
+ }
275
+ }
276
+ }
277
+ `;
278
+
279
+ export const QUERY_UPDATE = `mutation update($entity: EntityType!, $data: UpdateInput!) {
280
+ update(entity: $entity, data: $data) {
281
+ ... on Card {
282
+ id
283
+ schemaVersion
284
+ dateCreated
285
+ dateModified
286
+ data {
287
+ data
288
+ form {
289
+ code
290
+ data
291
+ style
292
+ template
293
+ }
294
+ presentation {
295
+ code
296
+ data
297
+ style
298
+ template
299
+ }
300
+ tagIds
301
+ }
302
+ reference {
303
+ id
304
+ type
305
+ }
306
+ template {
307
+ category
308
+ description
309
+ help
310
+ icon
311
+ iconUrl
312
+ implicitly
313
+ label
314
+ publishedBy
315
+ tags
316
+ type
317
+ version
318
+ }
319
+ }
320
+ }
321
+ }
322
+ `;
323
+ export const QUERY_UPDATE_CROSSACCOUNT = `mutation updateCrossAccount($entity: EntityType!, $data: UpdateInput!, $accountId: String!) {
324
+ updateCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
325
+ ... on Card {
326
+ id
327
+ schemaVersion
328
+ dateCreated
329
+ dateModified
330
+ data {
331
+ data
332
+ form {
333
+ code
334
+ data
335
+ style
336
+ template
337
+ }
338
+ presentation {
339
+ code
340
+ data
341
+ style
342
+ template
343
+ }
344
+ tagIds
345
+ }
346
+ reference {
347
+ id
348
+ type
349
+ }
350
+ template {
351
+ category
352
+ description
353
+ help
354
+ icon
355
+ iconUrl
356
+ implicitly
357
+ label
358
+ publishedBy
359
+ tags
360
+ type
361
+ version
362
+ }
363
+ }
364
+ }
365
+ }
366
+ `;
367
+
368
+ export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
369
+ deleteTemporarily(entity: $entity, data: $data) {
370
+ ... on AsyncRequest {
371
+ requestId
372
+ }
373
+ }
374
+ }`;
375
+
376
+ export const ENTITY_NAME = 'CARD';
package/src/types.ts CHANGED
@@ -17,9 +17,9 @@ export type CardsConfig = {
17
17
  accountId?: string;
18
18
 
19
19
  /**
20
- * Url of OneReach DataHubSvc api
20
+ * Url of OneReach DataHub api
21
21
  */
22
- dataHubSvcUrl?: string;
22
+ dataHubUrl?: string;
23
23
  };
24
24
 
25
25
  export type Card = {
@@ -58,17 +58,3 @@ export type Card = {
58
58
  reference?: string | null;
59
59
  template?: string | null;
60
60
  };
61
-
62
- export type ListCardsParams = {
63
- query?: {
64
- [key: string]: unknown;
65
- };
66
- projection?: string[];
67
- group?: string[];
68
- sandbox?: boolean;
69
- };
70
-
71
- export type PaginationOptions = {
72
- limit?: number;
73
- offset?: number;
74
- };