@or-sdk/deployments 1.0.1-405.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.
Files changed (52) hide show
  1. package/dist/cjs/Deployments.js +292 -0
  2. package/dist/cjs/Deployments.js.map +1 -0
  3. package/dist/cjs/constants.js +16 -0
  4. package/dist/cjs/constants.js.map +1 -0
  5. package/dist/cjs/index.js +21 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/types.js +3 -0
  8. package/dist/cjs/types.js.map +1 -0
  9. package/dist/cjs/utils/getDeleteQuery.js +12 -0
  10. package/dist/cjs/utils/getDeleteQuery.js.map +1 -0
  11. package/dist/cjs/utils/getGetQuery.js +12 -0
  12. package/dist/cjs/utils/getGetQuery.js.map +1 -0
  13. package/dist/cjs/utils/getListQuery.js +12 -0
  14. package/dist/cjs/utils/getListQuery.js.map +1 -0
  15. package/dist/cjs/utils/index.js +13 -0
  16. package/dist/cjs/utils/index.js.map +1 -0
  17. package/dist/esm/Deployments.js +194 -0
  18. package/dist/esm/Deployments.js.map +1 -0
  19. package/dist/esm/constants.js +57 -0
  20. package/dist/esm/constants.js.map +1 -0
  21. package/dist/esm/index.js +3 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/types.js +2 -0
  24. package/dist/esm/types.js.map +1 -0
  25. package/dist/esm/utils/getDeleteQuery.js +17 -0
  26. package/dist/esm/utils/getDeleteQuery.js.map +1 -0
  27. package/dist/esm/utils/getGetQuery.js +20 -0
  28. package/dist/esm/utils/getGetQuery.js.map +1 -0
  29. package/dist/esm/utils/getListQuery.js +25 -0
  30. package/dist/esm/utils/getListQuery.js.map +1 -0
  31. package/dist/esm/utils/index.js +4 -0
  32. package/dist/esm/utils/index.js.map +1 -0
  33. package/dist/types/Deployments.d.ts +17 -0
  34. package/dist/types/constants.d.ts +6 -0
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/types.d.ts +62 -0
  37. package/dist/types/utils/getDeleteQuery.d.ts +5 -0
  38. package/dist/types/utils/getGetQuery.d.ts +5 -0
  39. package/dist/types/utils/getListQuery.d.ts +5 -0
  40. package/dist/types/utils/index.d.ts +3 -0
  41. package/package.json +29 -0
  42. package/src/Deployments.ts +306 -0
  43. package/src/constants.ts +61 -0
  44. package/src/index.ts +2 -0
  45. package/src/types.ts +81 -0
  46. package/src/utils/getDeleteQuery.ts +18 -0
  47. package/src/utils/getGetQuery.ts +21 -0
  48. package/src/utils/getListQuery.ts +26 -0
  49. package/src/utils/index.ts +7 -0
  50. package/tsconfig.esm.json +9 -0
  51. package/tsconfig.json +7 -0
  52. package/tsconfig.types.json +9 -0
@@ -0,0 +1,57 @@
1
+ export const DEFAULT_PROJECTION_LIST = [
2
+ 'id',
3
+ 'data',
4
+ 'botId',
5
+ 'flowId',
6
+ 'dateDeactivated',
7
+ ];
8
+ export const QUERY_CREATE = `mutation create($entity: EntityType!, $data: CreateInput!) {
9
+ create(entity: $entity, data: $data) {
10
+ ... on Deployment {
11
+ id
12
+ data
13
+ botId
14
+ flowId
15
+ dateDeactivated
16
+ }
17
+ }
18
+ }
19
+ `;
20
+ export const QUERY_CREATE_CROSSACCOUNT = `mutation createCrossAccount($entity: EntityType!, $data: CreateInput!, $accountId: String!) {
21
+ createCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
22
+ ... on Deployment {
23
+ id
24
+ data
25
+ botId
26
+ flowId
27
+ dateDeactivated
28
+ }
29
+ }
30
+ }
31
+ `;
32
+ export const QUERY_UPDATE = `mutation update($entity: EntityType!, $data: UpdateInput!) {
33
+ update(entity: $entity, data: $data) {
34
+ ... on Deployment {
35
+ id
36
+ data
37
+ botId
38
+ flowId
39
+ dateDeactivated
40
+ }
41
+ }
42
+ }
43
+ `;
44
+ export const QUERY_UPDATE_CROSSACCOUNT = `mutation updateCrossAccount($entity: EntityType!, $data: UpdateInput!, $accountId: String!) {
45
+ updateCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
46
+ ... on Deployment {
47
+ id
48
+ data
49
+ botId
50
+ flowId
51
+ dateDeactivated
52
+ }
53
+ }
54
+ }
55
+ `;
56
+ export const ENTITY_NAME = 'DEPLOYMENT';
57
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,IAAI;IACJ,MAAM;IACN,OAAO;IACP,QAAQ;IACR,iBAAiB;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;CAW3B,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;CAWxC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;CAW3B,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;CAWxC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Deployments } from './Deployments';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { getQueryProjectionPart } from '@or-sdk/data-hub';
2
+ import { DEFAULT_PROJECTION_LIST } from '../constants';
3
+ function getDeleteQuery({ projection = [], crossAccount = false }) {
4
+ return crossAccount ?
5
+ `query getCrossAccount($entity: EntityType!, $params: GetInput!, $accountId: String!) {
6
+ getCrossAccount(entity: $entity, params: $params, accountId: $accountId)
7
+ }` :
8
+ `mutation delete($entity: EntityType!, $data: DeleteInput!) {
9
+ delete(entity: $entity, data: $data) {
10
+ ... on Deployment {${getQueryProjectionPart(projection.length ? projection : DEFAULT_PROJECTION_LIST)}
11
+ }
12
+ }
13
+ }
14
+ `;
15
+ }
16
+ export default getDeleteQuery;
17
+ //# sourceMappingURL=getDeleteQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDeleteQuery.js","sourceRoot":"","sources":["../../../src/utils/getDeleteQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,SAAS,cAAc,CAAC,EAAE,UAAU,GAAG,EAAE,EAAE,YAAY,GAAG,KAAK,EAAkD;IAC/G,OAAO,YAAY,CAAC,CAAC;QACnB;;EAEF,CAAC,CAAC;QACA;;yBAEqB,sBAAsB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAuB,CAAC;;;;CAIxG,CAAC;AACF,CAAC;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { getQueryProjectionPart } from '@or-sdk/data-hub';
2
+ import { DEFAULT_PROJECTION_LIST } from '../constants';
3
+ function getGetQuery({ projection = [], crossAccount = false }) {
4
+ return crossAccount ?
5
+ `query getCrossAccount($entity: EntityType!, $params: GetInput!, $accountId: String!) {
6
+ getCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
7
+ ... on Deployment {${getQueryProjectionPart(projection.length ? projection : DEFAULT_PROJECTION_LIST)}
8
+ }
9
+ }
10
+ }` :
11
+ `query get($entity: EntityType!, $params: GetInput!) {
12
+ get(entity: $entity, params: $params) {
13
+ ... on Deployment {${getQueryProjectionPart(projection.length ? projection : DEFAULT_PROJECTION_LIST)}
14
+ }
15
+ }
16
+ }
17
+ `;
18
+ }
19
+ export default getGetQuery;
20
+ //# sourceMappingURL=getGetQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGetQuery.js","sourceRoot":"","sources":["../../../src/utils/getGetQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,SAAS,WAAW,CAAC,EAAE,UAAU,GAAG,EAAE,EAAE,YAAY,GAAG,KAAK,EAAkD;IAC5G,OAAO,YAAY,CAAC,CAAC;QACnB;;yBAEqB,sBAAsB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAuB,CAAC;;;EAGvG,CAAC,CAAC;QACA;;yBAEqB,sBAAsB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAuB,CAAC;;;;CAIxG,CAAC;AACF,CAAC;AAED,eAAe,WAAW,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { getQueryProjectionPart } from '@or-sdk/data-hub';
2
+ import { DEFAULT_PROJECTION_LIST } from '../constants';
3
+ function getListQuery({ projection = [], crossAccount = false }) {
4
+ return crossAccount ?
5
+ `query listCrossAccount($entity: EntityType!, $params: ListInput!, $accountId: String!) {
6
+ listCrossAccount(entity: $entity, params: $params, accountId: $accountId) {
7
+ records {
8
+ ... on Deployment {${getQueryProjectionPart(projection.length ? projection : DEFAULT_PROJECTION_LIST)}
9
+ }
10
+ }
11
+ last
12
+ }
13
+ }` :
14
+ `query list($entity: EntityType!, $params: ListInput!, $sandbox: Boolean) {
15
+ list(entity: $entity, params: $params, sandbox: $sandbox) {
16
+ records {
17
+ ... on Deployment {${getQueryProjectionPart(projection.length ? projection : DEFAULT_PROJECTION_LIST)}
18
+ }
19
+ }
20
+ last
21
+ }
22
+ }`;
23
+ }
24
+ export default getListQuery;
25
+ //# sourceMappingURL=getListQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getListQuery.js","sourceRoot":"","sources":["../../../src/utils/getListQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,SAAS,YAAY,CAAC,EAAE,UAAU,GAAG,EAAE,EAAE,YAAY,GAAG,KAAK,EAAkD;IAC7G,OAAO,YAAY,CAAC,CAAC;QACnB;;;2BAGuB,sBAAsB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAuB,CAAC;;;;;EAKzG,CAAC,CAAC;QACA;;;2BAGuB,sBAAsB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,uBAAuB,CAAC;;;;;EAKzG,CAAC;AACH,CAAC;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { default as getListQuery } from './getListQuery';
2
+ export { default as getGetQuery } from './getGetQuery';
3
+ export { default as getDeleteQuery } from './getDeleteQuery';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { List } from '@or-sdk/base';
2
+ import { DeploymentsConfig, Deployment, ListDeploymentsParams } from './types';
3
+ export declare class Deployments {
4
+ private readonly dataHub;
5
+ constructor(params: DeploymentsConfig);
6
+ listDeployments({ query, projection }?: ListDeploymentsParams): Promise<List<Deployment>>;
7
+ listActiveDeployments(projection?: string[]): Promise<List<Deployment>>;
8
+ listDeploymentsByBotId(botId: string, projection?: string[]): Promise<List<Deployment>>;
9
+ listActiveDeploymentsByBotId(botId: string, projection?: string[]): Promise<List<Deployment>>;
10
+ listDeploymentsByFlowId(flowId: string, projection?: string[]): Promise<List<Deployment>>;
11
+ listActiveDeploymentsByFlowId(flowId: string, projection?: string[]): Promise<List<Deployment>>;
12
+ getDeployment(deploymentId: string, projection?: string[]): Promise<Deployment>;
13
+ deleteDeployment(deploymentId: string, projection?: string[]): Promise<Deployment>;
14
+ saveDeployment(source: Deployment): Promise<Deployment>;
15
+ createDeployment(source: Deployment): Promise<Deployment>;
16
+ updateDeployment(source: Deployment): Promise<Deployment>;
17
+ }
@@ -0,0 +1,6 @@
1
+ export declare const DEFAULT_PROJECTION_LIST: string[];
2
+ export declare const QUERY_CREATE = "mutation create($entity: EntityType!, $data: CreateInput!) {\n create(entity: $entity, data: $data) {\n ... on Deployment {\n id\n data\n botId\n flowId\n dateDeactivated\n }\n }\n}\n";
3
+ export declare const QUERY_CREATE_CROSSACCOUNT = "mutation createCrossAccount($entity: EntityType!, $data: CreateInput!, $accountId: String!) {\n createCrossAccount(entity: $entity, data: $data, accountId: $accountId) {\n ... on Deployment {\n id\n data\n botId\n flowId\n dateDeactivated\n }\n }\n}\n";
4
+ export declare const QUERY_UPDATE = "mutation update($entity: EntityType!, $data: UpdateInput!) {\n update(entity: $entity, data: $data) {\n ... on Deployment {\n id\n data\n botId\n flowId\n dateDeactivated\n }\n }\n}\n";
5
+ export declare const QUERY_UPDATE_CROSSACCOUNT = "mutation updateCrossAccount($entity: EntityType!, $data: UpdateInput!, $accountId: String!) {\n updateCrossAccount(entity: $entity, data: $data, accountId: $accountId) {\n ... on Deployment {\n id\n data\n botId\n flowId\n dateDeactivated\n }\n }\n}\n";
6
+ export declare const ENTITY_NAME = "DEPLOYMENT";
@@ -0,0 +1,2 @@
1
+ export { Deployments } from './Deployments';
2
+ export * from './types';
@@ -0,0 +1,62 @@
1
+ import { Token } from '@or-sdk/base';
2
+ export declare type DeploymentsConfig = {
3
+ token: Token;
4
+ discoveryUrl?: string;
5
+ accountId?: string;
6
+ dataHubUrl?: string;
7
+ };
8
+ export declare type Trigger = {
9
+ processed?: boolean;
10
+ name: string;
11
+ params: {
12
+ name: string;
13
+ params: {
14
+ path?: string;
15
+ method?: string;
16
+ resultExits?: unknown;
17
+ params?: unknown;
18
+ flowId?: string;
19
+ [key: string]: unknown;
20
+ };
21
+ session?: {
22
+ [key: string]: unknown;
23
+ };
24
+ state?: {
25
+ [key: string]: unknown;
26
+ };
27
+ type?: string;
28
+ [key: string]: unknown;
29
+ };
30
+ reporting: {
31
+ [key: string]: unknown;
32
+ };
33
+ target: string;
34
+ alias?: string;
35
+ source?: string;
36
+ lambda?: string;
37
+ };
38
+ export declare type Deployment = {
39
+ id?: string;
40
+ data: {
41
+ memory: number;
42
+ role: string;
43
+ alias: string;
44
+ flowVersionTimestamp: number;
45
+ flowVersion: string;
46
+ triggers: Trigger[];
47
+ timeout: number;
48
+ };
49
+ botId: string;
50
+ flowId: string;
51
+ dateDeactivated: number;
52
+ };
53
+ export declare type ListDeploymentsParams = {
54
+ query: {
55
+ id?: string | string[];
56
+ dateDeactivated?: number;
57
+ botId?: string;
58
+ flowId?: string;
59
+ [key: string]: unknown;
60
+ };
61
+ projection: string[];
62
+ };
@@ -0,0 +1,5 @@
1
+ declare function getDeleteQuery({ projection, crossAccount }: {
2
+ projection: string[];
3
+ crossAccount: boolean;
4
+ }): string;
5
+ export default getDeleteQuery;
@@ -0,0 +1,5 @@
1
+ declare function getGetQuery({ projection, crossAccount }: {
2
+ projection: string[];
3
+ crossAccount: boolean;
4
+ }): string;
5
+ export default getGetQuery;
@@ -0,0 +1,5 @@
1
+ declare function getListQuery({ projection, crossAccount }: {
2
+ projection: string[];
3
+ crossAccount: boolean;
4
+ }): string;
5
+ export default getListQuery;
@@ -0,0 +1,3 @@
1
+ export { default as getListQuery } from './getListQuery';
2
+ export { default as getGetQuery } from './getGetQuery';
3
+ export { default as getDeleteQuery } from './getDeleteQuery';
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "version": "1.0.1-405.0",
3
+ "name": "@or-sdk/deployments",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && concurrently \"npm run build:cjs\" \"npm run build:esm\" \"npm run build:types\"",
9
+ "build:watch": "concurrently -r --hide 1,2 \"npm run build:watch:cjs\" \"npm run build:watch:esm\" \"npm run build:watch:types\"",
10
+ "build:cjs": "tsc --project tsconfig.json",
11
+ "build:watch:cjs": "tsc --project tsconfig.json -w",
12
+ "build:esm": "tsc --project tsconfig.esm.json",
13
+ "build:watch:esm": "tsc --project tsconfig.esm.json -w",
14
+ "build:types": "tsc --project tsconfig.types.json",
15
+ "build:watch:types": "tsc --project tsconfig.types.json -w",
16
+ "clean": "rm -rf ./dist"
17
+ },
18
+ "devDependencies": {
19
+ "concurrently": "^6.4.0",
20
+ "typescript": "^4.4.4"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "dependencies": {
26
+ "@or-sdk/base": "^0.24.1",
27
+ "@or-sdk/data-hub": "^0.23.7"
28
+ }
29
+ }
@@ -0,0 +1,306 @@
1
+ import { List } from '@or-sdk/base';
2
+ import { DataHub, GraphqlResponse, OperationNames } from '@or-sdk/data-hub';
3
+ import { DeploymentsConfig, Deployment, ListDeploymentsParams } from './types';
4
+ import {
5
+ ENTITY_NAME,
6
+ QUERY_CREATE,
7
+ QUERY_CREATE_CROSSACCOUNT,
8
+ QUERY_UPDATE,
9
+ QUERY_UPDATE_CROSSACCOUNT,
10
+ } from './constants';
11
+ import { getGetQuery, getListQuery, getDeleteQuery } from './utils';
12
+
13
+ /**
14
+ * OneReach Deployments service client
15
+ * ## Installation:
16
+ * ```
17
+ * $ npm i @or-sdk/deployments
18
+ * ```
19
+ */
20
+ export class Deployments {
21
+ private readonly dataHub: DataHub;
22
+
23
+ /**
24
+ * ```typescript
25
+ * import { Deployments } from '@or-sdk/deployments'
26
+ * const deployments = new Deployments({token: 'my-account-token-string', discoveryUrl: 'http://example.deployments/endpoint'});
27
+ * ```
28
+ */
29
+ constructor(params: DeploymentsConfig) {
30
+ const { token, discoveryUrl, accountId, dataHubUrl } = params;
31
+
32
+ this.dataHub = new DataHub({
33
+ token,
34
+ discoveryUrl,
35
+ accountId,
36
+ dataHubUrl,
37
+ });
38
+ }
39
+
40
+ /**
41
+ * List deployments
42
+ * ```typescript
43
+ * const result = await deployments.listDeployments();
44
+ * ```
45
+ */
46
+ public async listDeployments({ query = {}, projection = [] }: ListDeploymentsParams = {} as ListDeploymentsParams): Promise<List<Deployment>> {
47
+ const variables = {
48
+ entity: ENTITY_NAME,
49
+ params: {
50
+ ids: query.id ?
51
+ Array.isArray(query.id) ?
52
+ query.id :
53
+ query.id.split(',') :
54
+ undefined,
55
+ queryParams: Array.isArray(query.id) ?
56
+ {
57
+ ...query,
58
+ id: query.id.join(','),
59
+ } :
60
+ query,
61
+ limit: 30,
62
+ },
63
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : { sandbox: false },
64
+ };
65
+
66
+ const operationName = this.dataHub.getOperationName(OperationNames.LIST);
67
+
68
+ const data = {
69
+ operationName,
70
+ query: getListQuery({
71
+ crossAccount: this.dataHub.isCrossAccount,
72
+ projection,
73
+ }),
74
+ variables,
75
+ };
76
+
77
+ return this.dataHub.getFullList<Deployment>('POST', '/graphql', data);
78
+ }
79
+
80
+ /**
81
+ * List active deployments
82
+ * ```typescript
83
+ * const result = await deployments.listActiveDeployments();
84
+ * ```
85
+ */
86
+ public async listActiveDeployments(projection: string[] = []): Promise<List<Deployment>> {
87
+ return this.listDeployments({
88
+ query: {
89
+ dateDeactivated: 0,
90
+ },
91
+ projection,
92
+ });
93
+ }
94
+
95
+ /**
96
+ * List deployments by bot id
97
+ * ```typescript
98
+ * const result = await deployments.listDeploymentsByBotId('bot-id');
99
+ * ```
100
+ */
101
+ public async listDeploymentsByBotId(botId: string, projection: string[] = []): Promise<List<Deployment>> {
102
+ return this.listDeployments({
103
+ query: {
104
+ botId,
105
+ },
106
+ projection,
107
+ });
108
+ }
109
+
110
+ /**
111
+ * List active deployments by bot id
112
+ * ```typescript
113
+ * const result = await deployments.listActiveDeploymentsByBotId('bot-id');
114
+ * ```
115
+ */
116
+ public async listActiveDeploymentsByBotId(botId: string, projection: string[] = []): Promise<List<Deployment>> {
117
+ return this.listDeployments({
118
+ query: {
119
+ botId,
120
+ dateDeactivated: 0,
121
+ },
122
+ projection,
123
+ });
124
+ }
125
+
126
+ /**
127
+ * List deployments by flow id
128
+ * ```typescript
129
+ * const result = await deployments.listDeploymentsByFlowId('flow-id');
130
+ * ```
131
+ */
132
+ public async listDeploymentsByFlowId(flowId: string, projection: string[] = []): Promise<List<Deployment>> {
133
+ return this.listDeployments({
134
+ query: {
135
+ flowId,
136
+ },
137
+ projection,
138
+ });
139
+ }
140
+
141
+ /**
142
+ * List active deployments by flow id
143
+ * ```typescript
144
+ * const result = await deployments.listActiveDeploymentsByFlowId('flow-id');
145
+ * ```
146
+ */
147
+ public async listActiveDeploymentsByFlowId(flowId: string, projection: string[] = []): Promise<List<Deployment>> {
148
+ return this.listDeployments({
149
+ query: {
150
+ flowId,
151
+ dateDeactivated: 0,
152
+ },
153
+ projection,
154
+ });
155
+ }
156
+
157
+ /**
158
+ * Get deployment
159
+ * ```typescript
160
+ * const result = await deployments.getDeployment('deployment-id');
161
+ * ```
162
+ */
163
+ public async getDeployment(deploymentId: string, projection: string[] = []): Promise<Deployment> {
164
+ const variables = {
165
+ entity: ENTITY_NAME,
166
+ params: {
167
+ id: deploymentId,
168
+ },
169
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
170
+ };
171
+
172
+ const operationName = this.dataHub.getOperationName(OperationNames.GET);
173
+
174
+ const data = {
175
+ operationName,
176
+ query: getGetQuery({
177
+ crossAccount: this.dataHub.isCrossAccount,
178
+ projection,
179
+ }),
180
+ variables,
181
+ };
182
+
183
+ const result = await this.dataHub.makeRequest<GraphqlResponse<Deployment>>({
184
+ method: 'POST',
185
+ route: '/graphql',
186
+ data,
187
+ });
188
+
189
+ return result.data[operationName] as Deployment;
190
+ }
191
+
192
+ /**
193
+ * Delete deployment
194
+ * ```typescript
195
+ * const result = await deployments.deleteDeployment('deployment-id');
196
+ * ```
197
+ */
198
+ public async deleteDeployment(deploymentId: string, projection: string[] = []): Promise<Deployment> {
199
+ if (this.dataHub.isCrossAccount) {
200
+ throw Error('Cross-account deleting is not implemented.');
201
+ }
202
+
203
+ const variables = {
204
+ entity: ENTITY_NAME,
205
+ data: {
206
+ id: deploymentId,
207
+ },
208
+ };
209
+
210
+ const operationName = this.dataHub.getOperationName(OperationNames.DELETE);
211
+
212
+ const data = {
213
+ operationName,
214
+ query: getDeleteQuery({
215
+ crossAccount: this.dataHub.isCrossAccount,
216
+ projection,
217
+ }),
218
+ variables,
219
+ };
220
+
221
+ const result = await this.dataHub.makeRequest<GraphqlResponse<Deployment>>({
222
+ method: 'POST',
223
+ route: '/graphql',
224
+ data,
225
+ });
226
+
227
+ return result.data[operationName] as Deployment;
228
+ }
229
+
230
+ /**
231
+ * Save deployment
232
+ *
233
+ * If source contains existing id - existing deployment will be updated
234
+ * ```typescript
235
+ * const result = await deployments.saveDeployment(deploymentSource);
236
+ * ```
237
+ */
238
+ public async saveDeployment(source: Deployment): Promise<Deployment> {
239
+ return source.id ? this.updateDeployment(source) : this.createDeployment(source);
240
+ }
241
+
242
+ /**
243
+ * Create deployment
244
+ * ```typescript
245
+ * const result = await deployments.createDeployment(deploymentSource);
246
+ * ```
247
+ */
248
+ public async createDeployment(source: Deployment): Promise<Deployment> {
249
+ const variables = {
250
+ entity: ENTITY_NAME,
251
+ data: {
252
+ body: source,
253
+ },
254
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
255
+ };
256
+
257
+ const operationName = this.dataHub.getOperationName(OperationNames.CREATE);
258
+
259
+ const data = {
260
+ operationName,
261
+ query: this.dataHub.isCrossAccount ? QUERY_CREATE_CROSSACCOUNT : QUERY_CREATE,
262
+ variables,
263
+ };
264
+
265
+ const result = await this.dataHub.makeRequest<GraphqlResponse<Deployment>>({
266
+ method: 'POST',
267
+ route: '/graphql',
268
+ data,
269
+ });
270
+
271
+ return result.data[operationName] as Deployment;
272
+ }
273
+
274
+ /**
275
+ * Update deployment
276
+ * ```typescript
277
+ * const result = await deployments.updateDeployment(deploymentSource);
278
+ * ```
279
+ */
280
+ public async updateDeployment(source: Deployment): Promise<Deployment> {
281
+ const variables = {
282
+ entity: ENTITY_NAME,
283
+ data: {
284
+ id: source.id,
285
+ body: source,
286
+ },
287
+ ... this.dataHub.isCrossAccount ? { accountId: this.dataHub.currentAccountId } : {},
288
+ };
289
+
290
+ const operationName = this.dataHub.getOperationName(OperationNames.UPDATE);
291
+
292
+ const data = {
293
+ operationName,
294
+ query: this.dataHub.isCrossAccount ? QUERY_UPDATE_CROSSACCOUNT : QUERY_UPDATE,
295
+ variables,
296
+ };
297
+
298
+ const result = await this.dataHub.makeRequest<GraphqlResponse<Deployment>>({
299
+ method: 'POST',
300
+ route: '/graphql',
301
+ data,
302
+ });
303
+
304
+ return result.data[operationName] as Deployment;
305
+ }
306
+ }
@@ -0,0 +1,61 @@
1
+ export const DEFAULT_PROJECTION_LIST = [
2
+ 'id',
3
+ 'data',
4
+ 'botId',
5
+ 'flowId',
6
+ 'dateDeactivated',
7
+ ];
8
+
9
+ export const QUERY_CREATE = `mutation create($entity: EntityType!, $data: CreateInput!) {
10
+ create(entity: $entity, data: $data) {
11
+ ... on Deployment {
12
+ id
13
+ data
14
+ botId
15
+ flowId
16
+ dateDeactivated
17
+ }
18
+ }
19
+ }
20
+ `;
21
+
22
+ export const QUERY_CREATE_CROSSACCOUNT = `mutation createCrossAccount($entity: EntityType!, $data: CreateInput!, $accountId: String!) {
23
+ createCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
24
+ ... on Deployment {
25
+ id
26
+ data
27
+ botId
28
+ flowId
29
+ dateDeactivated
30
+ }
31
+ }
32
+ }
33
+ `;
34
+
35
+ export const QUERY_UPDATE = `mutation update($entity: EntityType!, $data: UpdateInput!) {
36
+ update(entity: $entity, data: $data) {
37
+ ... on Deployment {
38
+ id
39
+ data
40
+ botId
41
+ flowId
42
+ dateDeactivated
43
+ }
44
+ }
45
+ }
46
+ `;
47
+
48
+ export const QUERY_UPDATE_CROSSACCOUNT = `mutation updateCrossAccount($entity: EntityType!, $data: UpdateInput!, $accountId: String!) {
49
+ updateCrossAccount(entity: $entity, data: $data, accountId: $accountId) {
50
+ ... on Deployment {
51
+ id
52
+ data
53
+ botId
54
+ flowId
55
+ dateDeactivated
56
+ }
57
+ }
58
+ }
59
+ `;
60
+
61
+ export const ENTITY_NAME = 'DEPLOYMENT';