@or-sdk/views 0.13.1 → 0.17.1

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.
Files changed (39) hide show
  1. package/dist/cjs/Views.js +97 -45
  2. package/dist/cjs/Views.js.map +1 -1
  3. package/dist/cjs/constants.js +5 -1
  4. package/dist/cjs/constants.js.map +1 -1
  5. package/dist/cjs/utils/addTagsIds.js +20 -0
  6. package/dist/cjs/utils/addTagsIds.js.map +1 -0
  7. package/dist/cjs/utils/filterTagIds.js +25 -0
  8. package/dist/cjs/utils/filterTagIds.js.map +1 -0
  9. package/dist/cjs/utils/index.js +13 -0
  10. package/dist/cjs/utils/index.js.map +1 -0
  11. package/dist/cjs/utils/removeTagIds.js +11 -0
  12. package/dist/cjs/utils/removeTagIds.js.map +1 -0
  13. package/dist/esm/Views.js +68 -41
  14. package/dist/esm/Views.js.map +1 -1
  15. package/dist/esm/constants.js +161 -0
  16. package/dist/esm/constants.js.map +1 -1
  17. package/dist/esm/utils/addTagsIds.js +9 -0
  18. package/dist/esm/utils/addTagsIds.js.map +1 -0
  19. package/dist/esm/utils/filterTagIds.js +23 -0
  20. package/dist/esm/utils/filterTagIds.js.map +1 -0
  21. package/dist/esm/utils/index.js +4 -0
  22. package/dist/esm/utils/index.js.map +1 -0
  23. package/dist/esm/utils/removeTagIds.js +9 -0
  24. package/dist/esm/utils/removeTagIds.js.map +1 -0
  25. package/dist/types/Views.d.ts +5 -1
  26. package/dist/types/constants.d.ts +4 -0
  27. package/dist/types/types.d.ts +1 -0
  28. package/dist/types/utils/addTagsIds.d.ts +3 -0
  29. package/dist/types/utils/filterTagIds.d.ts +6 -0
  30. package/dist/types/utils/index.d.ts +3 -0
  31. package/dist/types/utils/removeTagIds.d.ts +3 -0
  32. package/package.json +5 -4
  33. package/src/Views.ts +118 -23
  34. package/src/constants.ts +165 -0
  35. package/src/types.ts +4 -0
  36. package/src/utils/addTagsIds.ts +15 -0
  37. package/src/utils/filterTagIds.ts +27 -0
  38. package/src/utils/index.ts +6 -0
  39. package/src/utils/removeTagIds.ts +15 -0
@@ -30,6 +30,38 @@ export const QUERY_LIST = `query list($entity: EntityType!, $params: ListInput!,
30
30
  }
31
31
  }
32
32
  `;
33
+ export const QUERY_LIST_CROSSACCOUNT = `query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {
34
+ listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
35
+ records {
36
+ ... on View {
37
+ id
38
+ data {
39
+ data
40
+ }
41
+ cardIds
42
+ mirrorCardIds
43
+ linkId
44
+ linkType
45
+ template {
46
+ category
47
+ description
48
+ help
49
+ icon
50
+ iconUrl
51
+ implicitly
52
+ label
53
+ publishedBy
54
+ tags
55
+ type
56
+ version
57
+ }
58
+ reference
59
+ }
60
+ }
61
+ last
62
+ }
63
+ }
64
+ `;
33
65
  export const QUERY_GET = `query get($entity: EntityType!, $params: GetInput!) {
34
66
  get(entity: $entity, params: $params) {
35
67
  ... on View {
@@ -73,6 +105,49 @@ export const QUERY_GET = `query get($entity: EntityType!, $params: GetInput!) {
73
105
  }
74
106
  }
75
107
  }`;
108
+ export const QUERY_GET_CROSSACCOUNT = `query getCrossAccount($entity: EntityType!, $params: GetInput!, $accountId: String!) {
109
+ getCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
110
+ ... on View {
111
+ id
112
+ cardIds
113
+ linkId
114
+ mirrorCardIds
115
+ schemaVersion
116
+ dateCreated
117
+ dateModified
118
+ data {
119
+ data
120
+ form {
121
+ code
122
+ data
123
+ style
124
+ template
125
+ }
126
+ presentation {
127
+ code
128
+ data
129
+ style
130
+ template
131
+ }
132
+ }
133
+ linkType
134
+ reference
135
+ template {
136
+ category
137
+ description
138
+ help
139
+ icon
140
+ iconUrl
141
+ implicitly
142
+ label
143
+ publishedBy
144
+ tags
145
+ type
146
+ version
147
+ }
148
+ }
149
+ }
150
+ }`;
76
151
  export const QUERY_CREATE = `mutation create($entity: EntityType!, $data: CreateInput!) {
77
152
  create(entity: $entity, data: $data) {
78
153
  ... on View {
@@ -116,6 +191,49 @@ export const QUERY_CREATE = `mutation create($entity: EntityType!, $data: Create
116
191
  }
117
192
  }
118
193
  }`;
194
+ export const QUERY_CREATE_CROSSACCOUNT = `mutation createCrossAccount($entity: EntityType!, $data: CreateInput!, $accountId: String!) {
195
+ createCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
196
+ ... on View {
197
+ id
198
+ cardIds
199
+ linkId
200
+ mirrorCardIds
201
+ schemaVersion
202
+ dateCreated
203
+ dateModified
204
+ data {
205
+ data
206
+ form {
207
+ code
208
+ data
209
+ style
210
+ template
211
+ }
212
+ presentation {
213
+ code
214
+ data
215
+ style
216
+ template
217
+ }
218
+ }
219
+ linkType
220
+ reference
221
+ template {
222
+ category
223
+ description
224
+ help
225
+ icon
226
+ iconUrl
227
+ implicitly
228
+ label
229
+ publishedBy
230
+ tags
231
+ type
232
+ version
233
+ }
234
+ }
235
+ }
236
+ }`;
119
237
  export const QUERY_UPDATE = `mutation update($entity: EntityType!, $data: UpdateInput!) {
120
238
  update(entity: $entity, data: $data) {
121
239
  ... on View {
@@ -159,6 +277,49 @@ export const QUERY_UPDATE = `mutation update($entity: EntityType!, $data: Update
159
277
  }
160
278
  }
161
279
  }`;
280
+ export const QUERY_UPDATE_CROSSACCOUNT = `mutation updateCrossAccount($entity: EntityType!, $data: UpdateInput!, $accountId: String!) {
281
+ updateCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
282
+ ... on View {
283
+ id
284
+ cardIds
285
+ linkId
286
+ mirrorCardIds
287
+ schemaVersion
288
+ dateCreated
289
+ dateModified
290
+ data {
291
+ data
292
+ form {
293
+ code
294
+ data
295
+ style
296
+ template
297
+ }
298
+ presentation {
299
+ code
300
+ data
301
+ style
302
+ template
303
+ }
304
+ }
305
+ linkType
306
+ reference
307
+ template {
308
+ category
309
+ description
310
+ help
311
+ icon
312
+ iconUrl
313
+ implicitly
314
+ label
315
+ publishedBy
316
+ tags
317
+ type
318
+ version
319
+ }
320
+ }
321
+ }
322
+ }`;
162
323
  export const QUERY_DELETE = `mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {
163
324
  deleteTemporarily(entity: $entity, data: $data) {
164
325
  ... on AsyncRequest {
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BzB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CvB,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0C1B,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0C1B,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;EAM1B,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BzB,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BtC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CvB,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CpC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0C1B,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CvC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0C1B,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CvC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;EAM1B,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC"}
@@ -0,0 +1,9 @@
1
+ function addTagIds(source, tagIds) {
2
+ if (!Array.isArray(source.data.data.filterByTagIds)) {
3
+ source.data.data.filterByTagIds = [];
4
+ }
5
+ source.data.data.filterByTagIds = [...source.data.data.filterByTagIds, ...tagIds];
6
+ return source;
7
+ }
8
+ export default addTagIds;
9
+ //# sourceMappingURL=addTagsIds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addTagsIds.js","sourceRoot":"","sources":["../../../src/utils/addTagsIds.ts"],"names":[],"mappings":"AAIA,SAAS,SAAS,CAAC,MAAY,EAAE,MAAgB;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;KACtC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,MAAM,CAAC,CAAC;IAElF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,23 @@
1
+ function filterTagIds(source, tagIdsToFilter) {
2
+ let newIds = [];
3
+ const existingIds = [];
4
+ if (!Array.isArray(source.data.data.filterByTagIds)) {
5
+ newIds = tagIdsToFilter;
6
+ }
7
+ else {
8
+ tagIdsToFilter.forEach(tagId => {
9
+ if (source.data.data.filterByTagIds.indexOf(tagId) !== -1) {
10
+ existingIds.push(tagId);
11
+ }
12
+ else {
13
+ newIds.push(tagId);
14
+ }
15
+ });
16
+ }
17
+ return {
18
+ newIds,
19
+ existingIds,
20
+ };
21
+ }
22
+ export default filterTagIds;
23
+ //# sourceMappingURL=filterTagIds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterTagIds.js","sourceRoot":"","sources":["../../../src/utils/filterTagIds.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CAAC,MAAY,EAAE,cAAwB;IAC1D,IAAI,MAAM,GAAa,EAAE,CAAC;IAC1B,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,GAAG,cAAc,CAAC;KACzB;SAAM;QACL,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAe,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;gBAC1D,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACzB;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO;QACL,MAAM;QACN,WAAW;KACZ,CAAC;AACJ,CAAC;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { default as filterTagIds } from './filterTagIds';
2
+ export { default as addTagsIds } from './addTagsIds';
3
+ export { default as removeTagIds } from './removeTagIds';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,9 @@
1
+ function removeTagIds(source, tagIds) {
2
+ if (!Array.isArray(source.data.data.filterByTagIds)) {
3
+ source.data.data.filterByTagIds = [];
4
+ }
5
+ source.data.data.filterByTagIds = source.data.data.filterByTagIds.filter((id) => tagIds.indexOf(id) === -1);
6
+ return source;
7
+ }
8
+ export default removeTagIds;
9
+ //# sourceMappingURL=removeTagIds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeTagIds.js","sourceRoot":"","sources":["../../../src/utils/removeTagIds.ts"],"names":[],"mappings":"AAIA,SAAS,YAAY,CAAC,MAAY,EAAE,MAAgB;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QACnD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;KACtC;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEpH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,YAAY,CAAC"}
@@ -1,8 +1,10 @@
1
1
  import { List } from '@or-sdk/base';
2
2
  import { GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
3
3
  import { ViewsConfig, View } from './types';
4
- export declare class Views {
4
+ import { Taggable } from '@or-sdk/tags';
5
+ export declare class Views implements Taggable<View> {
5
6
  private readonly dataHub;
7
+ private readonly tags;
6
8
  constructor(params: ViewsConfig);
7
9
  init(): Promise<void>;
8
10
  listViews(): Promise<List<View>>;
@@ -11,4 +13,6 @@ export declare class Views {
11
13
  createView(source: View): Promise<View>;
12
14
  updateView(source: View): Promise<View>;
13
15
  deleteView(viewId: string): Promise<GraphqlResponseCheckExecution>;
16
+ addTags(source: View, tagNames: string[]): Promise<View>;
17
+ removeTags(source: View, tagNames: string[]): Promise<View>;
14
18
  }
@@ -1,6 +1,10 @@
1
1
  export declare const QUERY_LIST = "query list($entity: EntityType!, $params: ListInput!, $sandbox: Boolean) {\n list(entity: $entity, params: $params, sandbox: $sandbox) {\n records {\n ... on View {\n id\n data {\n data\n }\n cardIds\n mirrorCardIds\n linkId\n linkType\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n reference\n }\n }\n last\n }\n}\n";
2
+ export declare const QUERY_LIST_CROSSACCOUNT = "query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {\n listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {\n records {\n ... on View {\n id\n data {\n data\n }\n cardIds\n mirrorCardIds\n linkId\n linkType\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n reference\n }\n }\n last\n }\n}\n";
2
3
  export declare const QUERY_GET = "query get($entity: EntityType!, $params: GetInput!) {\n get(entity: $entity, params: $params) {\n ... on View {\n id\n cardIds\n linkId\n mirrorCardIds\n schemaVersion\n dateCreated\n dateModified\n data {\n data\n form {\n code\n data\n style\n template\n }\n presentation {\n code\n data\n style\n template\n }\n }\n linkType\n reference\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n }\n }\n}";
4
+ export declare const QUERY_GET_CROSSACCOUNT = "query getCrossAccount($entity: EntityType!, $params: GetInput!, $accountId: String!) {\n getCrossAccount(entity: $entity, params: $params, accountId: $accountId) {\n ... on View {\n id\n cardIds\n linkId\n mirrorCardIds\n schemaVersion\n dateCreated\n dateModified\n data {\n data\n form {\n code\n data\n style\n template\n }\n presentation {\n code\n data\n style\n template\n }\n }\n linkType\n reference\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n }\n }\n}";
3
5
  export declare const QUERY_CREATE = "mutation create($entity: EntityType!, $data: CreateInput!) {\n create(entity: $entity, data: $data) {\n ... on View {\n id\n cardIds\n linkId\n mirrorCardIds\n schemaVersion\n dateCreated\n dateModified\n data {\n data\n form {\n code\n data\n style\n template\n }\n presentation {\n code\n data\n style\n template\n }\n }\n linkType\n reference\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n }\n }\n}";
6
+ export declare const QUERY_CREATE_CROSSACCOUNT = "mutation createCrossAccount($entity: EntityType!, $data: CreateInput!, $accountId: String!) {\n createCrossAccount(entity: $entity, data: $data, accountId: $accountId) {\n ... on View {\n id\n cardIds\n linkId\n mirrorCardIds\n schemaVersion\n dateCreated\n dateModified\n data {\n data\n form {\n code\n data\n style\n template\n }\n presentation {\n code\n data\n style\n template\n }\n }\n linkType\n reference\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n }\n }\n}";
4
7
  export declare const QUERY_UPDATE = "mutation update($entity: EntityType!, $data: UpdateInput!) {\n update(entity: $entity, data: $data) {\n ... on View {\n id\n cardIds\n linkId\n mirrorCardIds\n schemaVersion\n dateCreated\n dateModified\n data {\n data\n form {\n code\n data\n style\n template\n }\n presentation {\n code\n data\n style\n template\n }\n }\n linkType\n reference\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n }\n }\n}";
8
+ export declare const QUERY_UPDATE_CROSSACCOUNT = "mutation updateCrossAccount($entity: EntityType!, $data: UpdateInput!, $accountId: String!) {\n updateCrossAccount(entity: $entity, data: $data, accountId: $accountId) {\n ... on View {\n id\n cardIds\n linkId\n mirrorCardIds\n schemaVersion\n dateCreated\n dateModified\n data {\n data\n form {\n code\n data\n style\n template\n }\n presentation {\n code\n data\n style\n template\n }\n }\n linkType\n reference\n template {\n category\n description\n help\n icon\n iconUrl\n implicitly\n label\n publishedBy\n tags\n type\n version\n }\n }\n }\n}";
5
9
  export declare const QUERY_DELETE = "mutation deleteTemporarily($entity: EntityType!, $data: DeleteInput!) {\n deleteTemporarily(entity: $entity, data: $data) {\n ... on AsyncRequest {\n requestId\n }\n }\n}";
6
10
  export declare const ENTITY_NAME = "VIEW";
@@ -2,6 +2,7 @@ import { Token } from '@or-sdk/base';
2
2
  export declare type ViewsConfig = {
3
3
  token: Token;
4
4
  discoveryUrl: string;
5
+ accountId?: string;
5
6
  };
6
7
  export declare type View = {
7
8
  id?: string;
@@ -0,0 +1,3 @@
1
+ import { View } from '../types';
2
+ declare function addTagIds(source: View, tagIds: string[]): View;
3
+ export default addTagIds;
@@ -0,0 +1,6 @@
1
+ import { View } from '../types';
2
+ declare function filterTagIds(source: View, tagIdsToFilter: string[]): {
3
+ newIds: string[];
4
+ existingIds: string[];
5
+ };
6
+ export default filterTagIds;
@@ -0,0 +1,3 @@
1
+ export { default as filterTagIds } from './filterTagIds';
2
+ export { default as addTagsIds } from './addTagsIds';
3
+ export { default as removeTagIds } from './removeTagIds';
@@ -0,0 +1,3 @@
1
+ import { View } from '../types';
2
+ declare function removeTagIds(source: View, tagIds: string[]): View;
3
+ export default removeTagIds;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.13.1",
2
+ "version": "0.17.1",
3
3
  "name": "@or-sdk/views",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
@@ -23,8 +23,9 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@or-sdk/base": "^0.13.1",
27
- "@or-sdk/data-hub": "^0.13.1"
26
+ "@or-sdk/base": "^0.17.1",
27
+ "@or-sdk/data-hub": "^0.17.1",
28
+ "@or-sdk/tags": "^0.17.1"
28
29
  },
29
- "gitHead": "2c86c545ff23d9464ebba1a5287cde3651ed98c1"
30
+ "gitHead": "61ede4c3b5e828ea61a8bb78a4bfc4f06852885d"
30
31
  }
package/src/Views.ts CHANGED
@@ -1,7 +1,19 @@
1
1
  import { List } from '@or-sdk/base';
2
- import { DataHub, GraphqlResponse, GraphqlResponseCheckExecution } from '@or-sdk/data-hub';
2
+ import { DataHub, GraphqlResponse, GraphqlResponseCheckExecution, GraphqlResponseDelete } from '@or-sdk/data-hub';
3
3
  import { ViewsConfig, View } from './types';
4
- import { ENTITY_NAME, QUERY_LIST, QUERY_GET, QUERY_CREATE, QUERY_UPDATE, QUERY_DELETE } from './constants';
4
+ import {
5
+ ENTITY_NAME,
6
+ QUERY_LIST,
7
+ QUERY_GET,
8
+ QUERY_CREATE,
9
+ QUERY_UPDATE,
10
+ QUERY_DELETE,
11
+ QUERY_GET_CROSSACCOUNT,
12
+ QUERY_LIST_CROSSACCOUNT,
13
+ QUERY_CREATE_CROSSACCOUNT,
14
+ QUERY_UPDATE_CROSSACCOUNT,
15
+ } from './constants';
16
+ import { Tags, Taggable, filterTagIds, addTagsIds, removeTagIds } from '@or-sdk/tags';
5
17
 
6
18
  /**
7
19
  * OneReach Views service client
@@ -10,8 +22,9 @@ import { ENTITY_NAME, QUERY_LIST, QUERY_GET, QUERY_CREATE, QUERY_UPDATE, QUERY_D
10
22
  * $ npm i @or-sdk/views
11
23
  * ```
12
24
  */
13
- export class Views {
25
+ export class Views implements Taggable<View> {
14
26
  private readonly dataHub: DataHub;
27
+ private readonly tags: Tags;
15
28
 
16
29
  /**
17
30
  * ```typescript
@@ -21,16 +34,25 @@ export class Views {
21
34
  * ```
22
35
  */
23
36
  constructor(params: ViewsConfig) {
24
- const { token, discoveryUrl } = params;
37
+ const { token, discoveryUrl, accountId } = params;
25
38
 
26
39
  this.dataHub = new DataHub({
27
40
  token,
28
41
  discoveryUrl,
42
+ accountId,
43
+ });
44
+ this.tags = new Tags({
45
+ token,
46
+ discoveryUrl,
47
+ accountId,
29
48
  });
30
49
  }
31
50
 
32
51
  async init() {
33
- await this.dataHub.init();
52
+ await Promise.all([
53
+ this.dataHub.init(),
54
+ this.tags.init(),
55
+ ]);
34
56
  }
35
57
 
36
58
  /**
@@ -48,12 +70,14 @@ export class Views {
48
70
  includeExisting: true,
49
71
  limit: 30,
50
72
  },
51
- sandbox: false,
73
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false },
52
74
  };
53
75
 
76
+ const operationName = this.dataHub.getOperationName('list');
77
+
54
78
  const data = {
55
- operationName: 'list',
56
- query: QUERY_LIST,
79
+ operationName,
80
+ query: this.dataHub.isCrossAccount ? QUERY_LIST_CROSSACCOUNT : QUERY_LIST,
57
81
  variables,
58
82
  };
59
83
 
@@ -74,21 +98,24 @@ export class Views {
74
98
  includeDeleted: false,
75
99
  includeExisting: true,
76
100
  },
101
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
77
102
  };
78
103
 
104
+ const operationName = this.dataHub.getOperationName('get');
105
+
79
106
  const data = {
80
- operationName: 'get',
81
- query: QUERY_GET,
107
+ operationName,
108
+ query: this.dataHub.isCrossAccount ? QUERY_GET_CROSSACCOUNT : QUERY_GET,
82
109
  variables,
83
110
  };
84
111
 
85
- const { data: { get: view } } = await this.dataHub.makeRequest<GraphqlResponse<'get', View>>({
112
+ const result = await this.dataHub.makeRequest<GraphqlResponse<View>>({
86
113
  method: 'POST',
87
114
  route: '/graphql',
88
115
  data,
89
116
  });
90
117
 
91
- return view;
118
+ return result.data[operationName] as View;
92
119
  }
93
120
 
94
121
  /**
@@ -115,21 +142,24 @@ export class Views {
115
142
  data: {
116
143
  body: source,
117
144
  },
145
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
118
146
  };
119
147
 
148
+ const operationName = this.dataHub.getOperationName('create');
149
+
120
150
  const data = {
121
- operationName: 'create',
122
- query: QUERY_CREATE,
151
+ operationName,
152
+ query: this.dataHub.isCrossAccount ? QUERY_CREATE_CROSSACCOUNT : QUERY_CREATE,
123
153
  variables,
124
154
  };
125
155
 
126
- const { data: { create: view } } = await this.dataHub.makeRequest<GraphqlResponse<'create', View>>({
156
+ const result = await this.dataHub.makeRequest<GraphqlResponse<View>>({
127
157
  method: 'POST',
128
158
  route: '/graphql',
129
159
  data,
130
160
  });
131
161
 
132
- return view;
162
+ return result.data[operationName] as View;
133
163
  }
134
164
 
135
165
  /**
@@ -145,21 +175,24 @@ export class Views {
145
175
  id: source.id,
146
176
  body: source,
147
177
  },
178
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
148
179
  };
149
180
 
181
+ const operationName = this.dataHub.getOperationName('update');
182
+
150
183
  const data = {
151
- operationName: 'update',
152
- query: source.id ? QUERY_UPDATE : QUERY_CREATE,
184
+ operationName,
185
+ query: this.dataHub.isCrossAccount ? QUERY_UPDATE_CROSSACCOUNT : QUERY_UPDATE,
153
186
  variables,
154
187
  };
155
188
 
156
- const { data: { update: view } } = await this.dataHub.makeRequest<GraphqlResponse<'update', View>>({
189
+ const result = await this.dataHub.makeRequest<GraphqlResponse<View>>({
157
190
  method: 'POST',
158
191
  route: '/graphql',
159
192
  data,
160
193
  });
161
194
 
162
- return view;
195
+ return result.data[operationName] as View;
163
196
  }
164
197
 
165
198
  /**
@@ -169,6 +202,10 @@ export class Views {
169
202
  * ```
170
203
  */
171
204
  public async deleteView(viewId: string): Promise<GraphqlResponseCheckExecution> {
205
+ if (this.dataHub.isCrossAccount) {
206
+ throw Error('Cross-account deleting is not implemented.');
207
+ }
208
+
172
209
  const variables = {
173
210
  entity: ENTITY_NAME,
174
211
  data: {
@@ -177,18 +214,76 @@ export class Views {
177
214
  },
178
215
  };
179
216
 
217
+ const operationName = this.dataHub.getOperationName('deleteTemporarily');
218
+
180
219
  const data = {
181
- operationName: 'deleteTemporarily',
220
+ operationName,
182
221
  query: QUERY_DELETE,
183
222
  variables,
184
223
  };
185
224
 
186
- const { data: { deleteTemporarily: { requestId } } } = await this.dataHub.makeRequest<GraphqlResponse<'deleteTemporarily', void>>({
225
+ const result = await this.dataHub.makeRequest<GraphqlResponse<void>>({
187
226
  method: 'POST',
188
227
  route: '/graphql',
189
228
  data,
190
229
  });
191
230
 
192
- return this.dataHub.subscribe(requestId);
231
+ return this.dataHub.subscribe((result.data[operationName] as GraphqlResponseDelete).requestId);
232
+ }
233
+
234
+ /**
235
+ * Add tags
236
+ * ```typescript
237
+ * const view = await views.addTags(viewSource, tagIdsArr);
238
+ * ```
239
+ */
240
+ public async addTags(source: View, tagNames: string[]): Promise<View> {
241
+ const tags = await this.tags.getMultipleTagsByName(tagNames, true);
242
+ const tagIds = tags.map(tag => tag.id!);
243
+
244
+ const { newIds } = filterTagIds(source.data.data.filterByTagIds, tagIds);
245
+
246
+ if (!newIds.length) {
247
+ throw Error('No tag IDs to add.');
248
+ }
249
+
250
+ return this.saveView({
251
+ ...source,
252
+ data: {
253
+ ...source.data,
254
+ data: {
255
+ ...source.data.data,
256
+ filterByTagIds: addTagsIds(source.data.data.filterByTagIds, newIds),
257
+ },
258
+ },
259
+ });
260
+ }
261
+
262
+ /**
263
+ * Remove tags
264
+ * ```typescript
265
+ * const view = await views.removeTags(viewSource, tagIdsArr);
266
+ * ```
267
+ */
268
+ public async removeTags(source: View, tagNames: string[]): Promise<View> {
269
+ const tags = await this.tags.getMultipleTagsByName(tagNames);
270
+ const tagIds = tags.map(tag => tag.id!);
271
+
272
+ const { existingIds } = filterTagIds(source.data.data.filterByTagIds, tagIds);
273
+
274
+ if (!existingIds.length) {
275
+ throw Error('No tag IDs to remove.');
276
+ }
277
+
278
+ return this.saveView({
279
+ ...source,
280
+ data: {
281
+ ...source.data,
282
+ data: {
283
+ ...source.data.data,
284
+ filterByTagIds: removeTagIds(source.data.data.filterByTagIds, existingIds),
285
+ },
286
+ },
287
+ });
193
288
  }
194
289
  }