@or-sdk/deployer 1.5.6 → 1.6.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/CHANGELOG.md +9 -0
- package/dist/cjs/Deployer.js +88 -22
- package/dist/cjs/Deployer.js.map +1 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/{types.js → types/base.js} +1 -1
- package/dist/cjs/types/base.js.map +1 -0
- package/dist/cjs/types/flow-activation.js +3 -0
- package/dist/cjs/types/flow-activation.js.map +1 -0
- package/dist/cjs/types/flow-logs.js +3 -0
- package/dist/cjs/types/flow-logs.js.map +1 -0
- package/dist/cjs/types/index.js +3 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/esm/Deployer.js +53 -14
- package/dist/esm/Deployer.js.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/base.js +2 -0
- package/dist/esm/types/base.js.map +1 -0
- package/dist/esm/types/flow-activation.js +2 -0
- package/dist/esm/types/flow-activation.js.map +1 -0
- package/dist/esm/types/flow-logs.js +2 -0
- package/dist/esm/types/flow-logs.js.map +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/types/Deployer.d.ts +7 -13
- package/dist/types/Deployer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/base.d.ts +16 -0
- package/dist/types/types/base.d.ts.map +1 -0
- package/dist/types/{types.d.ts → types/flow-activation.d.ts} +7 -12
- package/dist/types/types/flow-activation.d.ts.map +1 -0
- package/dist/types/types/flow-logs.d.ts +81 -0
- package/dist/types/types/flow-logs.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/Deployer.ts +213 -44
- package/src/index.ts +1 -1
- package/src/types/base.ts +42 -0
- package/src/{types.ts → types/flow-activation.ts} +13 -29
- package/src/types/flow-logs.ts +132 -0
- package/src/types/index.ts +3 -0
- package/tsconfig.types.json +2 -1
- package/dist/cjs/types.js.map +0 -1
- package/dist/esm/types.js +0 -2
- package/dist/esm/types.js.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type FetchFlowLogsParams = {
|
|
2
|
+
flowId: string;
|
|
3
|
+
limit?: number;
|
|
4
|
+
filter?: string;
|
|
5
|
+
start?: Date | number | 'now';
|
|
6
|
+
end?: Date | number | 'now';
|
|
7
|
+
skipOriginal?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type FetchFlowLogsChunkParams = FetchFlowLogsParams & {
|
|
10
|
+
next?: string;
|
|
11
|
+
};
|
|
12
|
+
export type FlowLogEventMessageString = {
|
|
13
|
+
parsed: string;
|
|
14
|
+
type: 'string';
|
|
15
|
+
};
|
|
16
|
+
export type ParsedReportingEventMessage = {
|
|
17
|
+
event: {
|
|
18
|
+
EventId: string;
|
|
19
|
+
Event: string;
|
|
20
|
+
EventCategory: string;
|
|
21
|
+
EventValue: Record<string, unknown>;
|
|
22
|
+
AccountId: string;
|
|
23
|
+
FlowId: string;
|
|
24
|
+
Timestamp: string;
|
|
25
|
+
Tags?: Array<unknown>;
|
|
26
|
+
SessionId?: string;
|
|
27
|
+
BeginningSessionId?: string;
|
|
28
|
+
Version?: number;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type RuntimeEventMessage = {
|
|
33
|
+
type: 'START' | 'END' | 'REPORT';
|
|
34
|
+
message: string;
|
|
35
|
+
};
|
|
36
|
+
export type SystemEventMessage = {
|
|
37
|
+
type: string;
|
|
38
|
+
sys: string;
|
|
39
|
+
thread: string;
|
|
40
|
+
data?: Record<string, unknown>;
|
|
41
|
+
step?: {
|
|
42
|
+
stepId: string;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
};
|
|
45
|
+
session?: {
|
|
46
|
+
id: string;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type LogEventMessage = {
|
|
51
|
+
type: string;
|
|
52
|
+
msg: string;
|
|
53
|
+
thread: string;
|
|
54
|
+
data?: Record<string, unknown>;
|
|
55
|
+
step?: {
|
|
56
|
+
stepId: string;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
};
|
|
59
|
+
session?: {
|
|
60
|
+
id: string;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export type FlowLogEventMessageJson = {
|
|
65
|
+
parsed: LogEventMessage | SystemEventMessage | ParsedReportingEventMessage | RuntimeEventMessage;
|
|
66
|
+
type: 'json';
|
|
67
|
+
};
|
|
68
|
+
export type FlowLogEventMessage = FlowLogEventMessageString | FlowLogEventMessageJson;
|
|
69
|
+
export type FlowLogEvent = {
|
|
70
|
+
requestId: string;
|
|
71
|
+
message: FlowLogEventMessage;
|
|
72
|
+
timestamp: number;
|
|
73
|
+
};
|
|
74
|
+
export type FlowLogsResponse = {
|
|
75
|
+
events: FlowLogEvent[];
|
|
76
|
+
startTime: number;
|
|
77
|
+
};
|
|
78
|
+
export type FlowLogsChunkResponse = FlowLogsResponse & {
|
|
79
|
+
nextToken?: string;
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=flow-logs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-logs.d.ts","sourceRoot":"","sources":["../../../src/types/flow-logs.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,mBAAmB,GAAG;IAEhC,MAAM,EAAE,MAAM,CAAC;IAGf,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,MAAM,CAAC,EAAE,MAAM,CAAC;IAWhB,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;IAW9B,GAAG,CAAC,EAAE,IAAI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AmB,mBAAmB,CAAC;AACvC,mBAAmB,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@or-sdk/deployer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "pnpm clean && pnpm
|
|
9
|
+
"build": "pnpm clean && concurrently 'pnpm:build:*(!watch)'",
|
|
10
10
|
"build:cjs": "tsc --project tsconfig.json",
|
|
11
11
|
"build:esm": "tsc --project tsconfig.esm.json",
|
|
12
12
|
"build:types": "tsc --project tsconfig.types.json",
|
|
13
|
-
"build:watch": "concurrently
|
|
13
|
+
"build:watch": "concurrently 'pnpm:build:watch:*'",
|
|
14
14
|
"build:watch:cjs": "tsc --project tsconfig.json -w",
|
|
15
15
|
"build:watch:esm": "tsc --project tsconfig.esm.json -w",
|
|
16
16
|
"build:watch:types": "tsc --project tsconfig.types.json -w",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dev": "pnpm build:watch:esm"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@or-sdk/base": "^0.
|
|
22
|
-
"@or-sdk/step-templates": "^2.
|
|
21
|
+
"@or-sdk/base": "^0.43.0",
|
|
22
|
+
"@or-sdk/step-templates": "^2.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"concurrently": "9.0.1",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "ce62679c119c54ef41fd0d8f7084c563c3b21b24"
|
|
32
32
|
}
|
package/src/Deployer.ts
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
import { Base, timeout } from '@or-sdk/base';
|
|
2
2
|
|
|
3
3
|
import { SERVICE_KEY } from './constants';
|
|
4
|
-
import {
|
|
4
|
+
import type {
|
|
5
5
|
DeployerConfig,
|
|
6
|
-
|
|
6
|
+
FetchFlowLogsChunkParams,
|
|
7
|
+
FetchFlowLogsParams,
|
|
8
|
+
Flow, FlowLogsChunkResponse, FlowLogsResponse, PollingOptions, PollingParams,
|
|
7
9
|
PollingResult,
|
|
8
10
|
PollingResultActivateSuccess,
|
|
9
11
|
PollingResultDeactivateSuccess,
|
|
10
|
-
PollingResultError,
|
|
11
12
|
PollingResultPending,
|
|
12
13
|
} from './types';
|
|
13
14
|
|
|
14
15
|
export class Deployer extends Base {
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* You need to pass URL either to discovery API or to deployer API
|
|
19
|
+
*
|
|
20
|
+
* @example Creating instance using discovery API
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const deployer = new Deployer({
|
|
23
|
+
* token: '<token>',
|
|
24
|
+
* discoveryUrl: '<discovery-api-url>',
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Creating instance using deployer API URL
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const deployer = new Deployer({
|
|
31
|
+
* token: '<token>',
|
|
32
|
+
* deployerUrl: '<deployer-api-url>',
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
16
36
|
constructor(params: DeployerConfig) {
|
|
17
37
|
const { token, discoveryUrl, accountId, deployerUrl } = params;
|
|
18
38
|
|
|
@@ -27,16 +47,18 @@ export class Deployer extends Base {
|
|
|
27
47
|
|
|
28
48
|
/**
|
|
29
49
|
* Remove role
|
|
50
|
+
*
|
|
51
|
+
* Does not support cross-account logic.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
30
54
|
* ```typescript
|
|
31
55
|
* const result = await deployer.removeRole();
|
|
32
56
|
* ```
|
|
33
57
|
*/
|
|
34
58
|
public async removeRole(): Promise<void> {
|
|
35
|
-
const route = '/role';
|
|
36
|
-
|
|
37
59
|
return this.callApi({
|
|
38
60
|
method: 'DELETE',
|
|
39
|
-
route,
|
|
61
|
+
route: '/role',
|
|
40
62
|
params: {
|
|
41
63
|
accountId: this.currentAccountId,
|
|
42
64
|
},
|
|
@@ -44,12 +66,19 @@ export class Deployer extends Base {
|
|
|
44
66
|
}
|
|
45
67
|
|
|
46
68
|
/**
|
|
47
|
-
* Activate flow without polling
|
|
69
|
+
* Activate flow without polling.
|
|
70
|
+
*
|
|
71
|
+
* Supports cross-account logic (with super-admin token).
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
48
74
|
* ```typescript
|
|
49
75
|
* const pollingParams = await deployer.activateFlow(flowSource, false);
|
|
50
76
|
* ```
|
|
51
77
|
*/
|
|
52
|
-
public async activateFlowNoPoll(
|
|
78
|
+
public async activateFlowNoPoll(
|
|
79
|
+
{ id, data: { deploy: { role } } }: Flow,
|
|
80
|
+
interactiveDebug = false,
|
|
81
|
+
): Promise<PollingParams> {
|
|
53
82
|
if (!id) {
|
|
54
83
|
throw new Error('Id is required');
|
|
55
84
|
}
|
|
@@ -63,11 +92,9 @@ export class Deployer extends Base {
|
|
|
63
92
|
role,
|
|
64
93
|
};
|
|
65
94
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const { requestId } = await this.callApi<{requestId: string;}>({
|
|
95
|
+
const { requestId } = await this.callApi<{ requestId: string; }>({
|
|
69
96
|
method: 'POST',
|
|
70
|
-
route,
|
|
97
|
+
route: this.getPrefixedRoute('/flows/deploy'),
|
|
71
98
|
data,
|
|
72
99
|
});
|
|
73
100
|
|
|
@@ -79,21 +106,29 @@ export class Deployer extends Base {
|
|
|
79
106
|
|
|
80
107
|
/**
|
|
81
108
|
* Activates flow.
|
|
109
|
+
*
|
|
82
110
|
* Starts activation and polls progress. `progressCallback` is called on every polling
|
|
83
111
|
* while the activation is in 'pending' status.
|
|
112
|
+
*
|
|
113
|
+
* Supports cross-account logic (with super-admin token).
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
84
116
|
* ```typescript
|
|
85
|
-
* const triggerList = await
|
|
117
|
+
* const triggerList = await flows.activateFlow(flowSource, false, fnShowProgress);
|
|
86
118
|
* ```
|
|
87
|
-
* @param flowSource Flow data object. SDK uses `id` and `data.deploy.role` properties from it.
|
|
88
|
-
* @param interactiveDebug Flag to turn the debug mode on/off. `false` by default.
|
|
89
|
-
* @param progressCallback Function to call with interim activation progress results.
|
|
90
|
-
* @returns Successful activation data object that contains active triggers for the flow.
|
|
91
119
|
*/
|
|
92
120
|
public async activateFlow(
|
|
121
|
+
/** Flow data object. SDK uses `id` and `data.deploy.role` properties from it. */
|
|
93
122
|
flowSource: Flow,
|
|
123
|
+
|
|
124
|
+
/** Flag to turn the debug mode on/off. Default `false`. */
|
|
94
125
|
interactiveDebug = false,
|
|
126
|
+
|
|
127
|
+
/** Callback function to call with interim activation progress results. */
|
|
95
128
|
progressCallback?: (progress: PollingResultPending) => void,
|
|
96
|
-
|
|
129
|
+
|
|
130
|
+
/** Activation polling options */
|
|
131
|
+
pollingOptions?: PollingOptions,
|
|
97
132
|
): Promise<PollingResultActivateSuccess> {
|
|
98
133
|
const pollingParams = await this.activateFlowNoPoll(flowSource, interactiveDebug);
|
|
99
134
|
|
|
@@ -106,6 +141,10 @@ export class Deployer extends Base {
|
|
|
106
141
|
|
|
107
142
|
/**
|
|
108
143
|
* Deactivate flow without polling
|
|
144
|
+
*
|
|
145
|
+
* Supports cross-account logic (with super-admin token).
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
109
148
|
* ```typescript
|
|
110
149
|
* const pollingParams = await deployer.deactivateFlow(flowSource);
|
|
111
150
|
* ```
|
|
@@ -122,11 +161,9 @@ export class Deployer extends Base {
|
|
|
122
161
|
role,
|
|
123
162
|
};
|
|
124
163
|
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const { requestId } = await this.callApi<{requestId: string;}>({
|
|
164
|
+
const { requestId } = await this.callApi<{ requestId: string; }>({
|
|
128
165
|
method: 'DELETE',
|
|
129
|
-
route,
|
|
166
|
+
route: this.getPrefixedRoute('/flows/deploy'),
|
|
130
167
|
data,
|
|
131
168
|
});
|
|
132
169
|
|
|
@@ -138,19 +175,26 @@ export class Deployer extends Base {
|
|
|
138
175
|
|
|
139
176
|
/**
|
|
140
177
|
* Deactivates flow.
|
|
178
|
+
*
|
|
141
179
|
* Starts deactivation and polls progress. `progressCallback` is called on every polling
|
|
142
180
|
* while the deactivation is in 'pending' status.
|
|
181
|
+
*
|
|
182
|
+
* Supports cross-account logic (with super-admin token).
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
143
185
|
* ```typescript
|
|
144
|
-
* const deactivatedFlowList = await
|
|
186
|
+
* const deactivatedFlowList = await flows.deactivateFlow(flowSource, fnShowProgress);
|
|
145
187
|
* ```
|
|
146
|
-
* @param flowSource Flow data object. SDK uses `id` and `data.deploy.role` properties from it.
|
|
147
|
-
* @param progressCallback Function to call with interim deactivation progress results.
|
|
148
|
-
* @returns Successful deactivation summary data.
|
|
149
188
|
*/
|
|
150
189
|
public async deactivateFlow(
|
|
190
|
+
/** Flow data object. SDK uses `id` and `data.deploy.role` properties from it. */
|
|
151
191
|
flowSource: Flow,
|
|
192
|
+
|
|
193
|
+
/** Function to call with interim deactivation progress results. */
|
|
152
194
|
progressCallback?: (progress: PollingResultPending) => void,
|
|
153
|
-
|
|
195
|
+
|
|
196
|
+
/** Deactivation polling options */
|
|
197
|
+
pollingOptions?: PollingOptions,
|
|
154
198
|
): Promise<PollingResultDeactivateSuccess> {
|
|
155
199
|
const pollingParams = await this.deactivateFlowNoPoll(flowSource);
|
|
156
200
|
|
|
@@ -162,41 +206,44 @@ export class Deployer extends Base {
|
|
|
162
206
|
* and success or error when finished. Performs up to 100 calls with 1 second interval.
|
|
163
207
|
*
|
|
164
208
|
* Optional progressCallback is calls for every call while in pending status.
|
|
209
|
+
*
|
|
210
|
+
* Supports cross-account logic (with super-admin token).
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
165
213
|
* ```typescript
|
|
166
214
|
* const result = await deployer.pollResult(pollingParams, progressCallback);
|
|
167
215
|
* ```
|
|
168
|
-
* @param pollingParams Object with ids of the flow and the deployment process.
|
|
169
|
-
* @param progressCallback Callback function getting the interim status of the flow de/activation.
|
|
170
216
|
*/
|
|
171
217
|
public async pollResult<T>(
|
|
218
|
+
/** Flow and activation/deactivation ids. */
|
|
172
219
|
{ flowId, requestId }: PollingParams,
|
|
220
|
+
|
|
221
|
+
/** Callback function getting the interim status of the flow activation/deactivation. */
|
|
173
222
|
progressCallback?: (progress: PollingResultPending) => void,
|
|
174
|
-
|
|
223
|
+
|
|
224
|
+
/** Polling options */
|
|
225
|
+
options?: PollingOptions,
|
|
175
226
|
): Promise<T> {
|
|
176
227
|
let counter = 0;
|
|
177
228
|
const maxAttempts = options?.maxAttempts || 100;
|
|
178
229
|
const attemptDelay = options?.attemptDelay || 3000;
|
|
179
230
|
|
|
180
|
-
const route = `${ this.isCrossAccount ? `/accounts/${this.currentAccountId}` : '' }/flows/check/${flowId}/${requestId}`;
|
|
181
|
-
|
|
182
231
|
do {
|
|
183
|
-
counter
|
|
184
|
-
|
|
232
|
+
if (counter) await timeout(attemptDelay);
|
|
233
|
+
counter += 1;
|
|
185
234
|
|
|
186
235
|
const result = await this.callApi<PollingResult>({
|
|
187
236
|
method: 'GET',
|
|
188
|
-
route,
|
|
237
|
+
route: this.getPrefixedRoute(`/flows/check/${flowId}/${requestId}`),
|
|
189
238
|
});
|
|
190
239
|
|
|
191
|
-
if (
|
|
240
|
+
if ('status' in result && result.status === 'pending') {
|
|
192
241
|
if (typeof progressCallback === 'function') {
|
|
193
|
-
progressCallback(result
|
|
242
|
+
progressCallback(result);
|
|
194
243
|
}
|
|
244
|
+
} else if ('errorData' in result && result.errorData) {
|
|
245
|
+
throw result;
|
|
195
246
|
} else {
|
|
196
|
-
if ((result as PollingResultError).errorData) {
|
|
197
|
-
throw result;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
247
|
return result as T;
|
|
201
248
|
}
|
|
202
249
|
} while (counter < maxAttempts);
|
|
@@ -206,9 +253,18 @@ export class Deployer extends Base {
|
|
|
206
253
|
|
|
207
254
|
/**
|
|
208
255
|
* Only for SUPER_ADMIN.
|
|
209
|
-
*
|
|
256
|
+
*
|
|
257
|
+
* Starts the process to delete an account IAM role and disable all account flows.
|
|
258
|
+
*
|
|
210
259
|
* Additionally, it marks each deployment with a "suspended" flag to enable future resumption.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
211
262
|
* ```typescript
|
|
263
|
+
* const deployer = new Deployer({
|
|
264
|
+
* token: '<super-admin-token>',
|
|
265
|
+
* accountId: '<account-id-to-suspend>',
|
|
266
|
+
* discoveryUrl: '<discovery-api-url>',
|
|
267
|
+
* });
|
|
212
268
|
* await deployer.suspendAccount();
|
|
213
269
|
* ```
|
|
214
270
|
*/
|
|
@@ -226,9 +282,17 @@ export class Deployer extends Base {
|
|
|
226
282
|
|
|
227
283
|
/**
|
|
228
284
|
* Only for SUPER_ADMIN.
|
|
229
|
-
*
|
|
285
|
+
*
|
|
286
|
+
* Restores suspended account and activates all suspended flows.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
230
289
|
* ```typescript
|
|
231
|
-
*
|
|
290
|
+
* const deployer = new Deployer({
|
|
291
|
+
* token: '<super-admin-token>',
|
|
292
|
+
* accountId: '<account-id-to-restore>',
|
|
293
|
+
* discoveryUrl: '<discovery-api-url>',
|
|
294
|
+
* });
|
|
295
|
+
* await deployer.resumeAccount();
|
|
232
296
|
* ```
|
|
233
297
|
*/
|
|
234
298
|
public async resumeAccount(): Promise<void> {
|
|
@@ -242,4 +306,109 @@ export class Deployer extends Base {
|
|
|
242
306
|
},
|
|
243
307
|
});
|
|
244
308
|
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Fetch single chunk of flow logs
|
|
312
|
+
*
|
|
313
|
+
* To fetch all log events for given time interval see {@link fetchAllFlowLogs}.
|
|
314
|
+
*
|
|
315
|
+
* Does not support cross-account fetching (with `accountId` in Deployer constructor).
|
|
316
|
+
*
|
|
317
|
+
* @example Fetch latest chunk of logs for the flow:
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const deployer = new Deployer({token: '<token>', discoveryUrl: '<discovery-api-url>'});
|
|
320
|
+
* const logs = await deployer.fetchFlowLogsChunk({flowId: '<flow-id>'});
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example Fetch two chunks of flow logs
|
|
324
|
+
* ```typescript
|
|
325
|
+
* const deployer = new Deployer({token: '<token>', discoveryUrl: '<discovery-api-url>'});
|
|
326
|
+
* const chunk1 = await deployer.fetchFlowLogsChunk({flowId: '<flow-id>'});
|
|
327
|
+
* const chunk2 = await deployer.fetchFlowLogsChunk({
|
|
328
|
+
* flowId: '<flow-id>',
|
|
329
|
+
* next: chunk1.nextToken,
|
|
330
|
+
* });
|
|
331
|
+
* ```
|
|
332
|
+
*
|
|
333
|
+
* @example Fetch chunk of logs starting from 1 hour ago till now:
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const deployer = new Deployer({token: '<token>', discoveryUrl: '<discovery-api-url>'});
|
|
336
|
+
* const logs = await deployer.fetchFlowLogsChunk({
|
|
337
|
+
* flowId: '<flow-id>',
|
|
338
|
+
* start: Date.now() - 60 * 60 * 1000, // 60 minutes ago
|
|
339
|
+
* });
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
public async fetchFlowLogsChunk(params: FetchFlowLogsChunkParams): Promise<FlowLogsChunkResponse> {
|
|
343
|
+
const {
|
|
344
|
+
flowId,
|
|
345
|
+
limit = 50,
|
|
346
|
+
skipOriginal = true,
|
|
347
|
+
start = 'now',
|
|
348
|
+
end = 'now',
|
|
349
|
+
...options
|
|
350
|
+
} = params;
|
|
351
|
+
|
|
352
|
+
const result = await this.callApiV2<FlowLogsChunkResponse>({
|
|
353
|
+
method: 'GET',
|
|
354
|
+
route: `/flows/${flowId}/logs`,
|
|
355
|
+
params: {
|
|
356
|
+
...options,
|
|
357
|
+
limit,
|
|
358
|
+
// due to API quirk it should be either `true` or `undefined` to properly pass it
|
|
359
|
+
skipOriginal: skipOriginal || undefined,
|
|
360
|
+
start: start instanceof Date ? start.valueOf() : start,
|
|
361
|
+
end: end instanceof Date ? end.valueOf() : end,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// delete param that will always be empty array
|
|
366
|
+
if ('searchedLogStreams' in result) delete result.searchedLogStreams;
|
|
367
|
+
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Fetch all flow log events for a time interval
|
|
373
|
+
*
|
|
374
|
+
* To fetch only single chunk of log events see {@link fetchFlowLogsChunk}.
|
|
375
|
+
*
|
|
376
|
+
* Does not support cross-account fetching (with `accountId` in Deployer constructor).
|
|
377
|
+
*
|
|
378
|
+
* @example Fetch latest logs for the flow:
|
|
379
|
+
* ```typescript
|
|
380
|
+
* const deployer = new Deployer({token: '<token>', discoveryUrl: '<discovery-api-url>'});
|
|
381
|
+
* const logs = await deployer.fetchAllFlowLogs({flowId: '<flow-id>'});
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* @example Fetch all logs starting from 1 hour ago till now:
|
|
385
|
+
* ```typescript
|
|
386
|
+
* const deployer = new Deployer({token: '<token>', discoveryUrl: '<discovery-api-url>'});
|
|
387
|
+
* const logs = await deployer.fetchAllFlowLogs({
|
|
388
|
+
* flowId: '<flow-id>',
|
|
389
|
+
* start: Date.now() - 60 * 60 * 1000, // 60 minutes ago
|
|
390
|
+
* });
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
public async fetchAllFlowLogs(params: FetchFlowLogsParams): Promise<FlowLogsResponse> {
|
|
394
|
+
let next: string | undefined;
|
|
395
|
+
let result: FlowLogsResponse | undefined;
|
|
396
|
+
|
|
397
|
+
do {
|
|
398
|
+
const chunk = await this.fetchFlowLogsChunk({
|
|
399
|
+
...params,
|
|
400
|
+
next,
|
|
401
|
+
});
|
|
402
|
+
next = chunk.nextToken;
|
|
403
|
+
|
|
404
|
+
if (result == undefined) result = chunk;
|
|
405
|
+
else result.events = result.events.concat(chunk.events);
|
|
406
|
+
} while (next);
|
|
407
|
+
|
|
408
|
+
return result;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
private getPrefixedRoute(route: string): string {
|
|
412
|
+
return `${this.isCrossAccount ? `/accounts/${this.currentAccountId}` : ''}${route}`;
|
|
413
|
+
}
|
|
245
414
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Token } from '@or-sdk/base';
|
|
2
|
+
|
|
3
|
+
export type { Token };
|
|
4
|
+
|
|
5
|
+
export type DeployerConfigBase = {
|
|
6
|
+
/**
|
|
7
|
+
* OneReach token or token factory function
|
|
8
|
+
*/
|
|
9
|
+
token: Token;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Account id for cross-account requests (super admin only)
|
|
13
|
+
*/
|
|
14
|
+
accountId?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type DeployerConfigWithDiscovery = DeployerConfigBase & {
|
|
18
|
+
/**
|
|
19
|
+
* URL of OneReach ServiceDiscovery API
|
|
20
|
+
*
|
|
21
|
+
* If this is set, do not provide {@link DeployerConfig.deployerUrl}.
|
|
22
|
+
*/
|
|
23
|
+
discoveryUrl: string;
|
|
24
|
+
|
|
25
|
+
deployerUrl?: never;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type DeployerConfigWithExplicitUrls = DeployerConfigBase & {
|
|
29
|
+
/**
|
|
30
|
+
* URL of OneReach Deployer API
|
|
31
|
+
*
|
|
32
|
+
* If this is set, do not provide {@link DeployerConfig.discoveryUrl}.
|
|
33
|
+
*/
|
|
34
|
+
deployerUrl: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* URL of OneReach ServiceDiscovery API
|
|
38
|
+
*/
|
|
39
|
+
discoveryUrl?: never;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type DeployerConfig = DeployerConfigWithDiscovery | DeployerConfigWithExplicitUrls;
|
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StepTemplateRaw } from '@or-sdk/step-templates';
|
|
1
|
+
import type { StepTemplateRaw } from '@or-sdk/step-templates';
|
|
3
2
|
|
|
4
3
|
export { StepTemplateRaw } from '@or-sdk/step-templates';
|
|
5
4
|
|
|
6
|
-
export type DeployerConfig = {
|
|
7
|
-
/**
|
|
8
|
-
* token
|
|
9
|
-
*/
|
|
10
|
-
token: Token;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Url of OneReach service discovery api
|
|
14
|
-
*/
|
|
15
|
-
discoveryUrl?: string;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Account ID for cross-account requests (super admin only)
|
|
19
|
-
*/
|
|
20
|
-
accountId?: string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Url of OneReach Deployer api
|
|
24
|
-
*/
|
|
25
|
-
deployerUrl?: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
5
|
export type Step = {
|
|
29
6
|
id: string;
|
|
30
7
|
label?: string;
|
|
@@ -105,9 +82,7 @@ export type Trigger = {
|
|
|
105
82
|
path?: string;
|
|
106
83
|
};
|
|
107
84
|
};
|
|
108
|
-
reporting:
|
|
109
|
-
[key: string]: unknown;
|
|
110
|
-
}; //TODO: always empty?
|
|
85
|
+
reporting: Record<string, unknown>; //TODO: always empty?
|
|
111
86
|
processed: boolean;
|
|
112
87
|
};
|
|
113
88
|
|
|
@@ -122,7 +97,7 @@ export type PollingResultPending = {
|
|
|
122
97
|
*/
|
|
123
98
|
message?: string;
|
|
124
99
|
/**
|
|
125
|
-
* Percentage value of the flow
|
|
100
|
+
* Percentage value of the flow activation/deactivation completion.
|
|
126
101
|
*/
|
|
127
102
|
progress?: number;
|
|
128
103
|
};
|
|
@@ -165,7 +140,7 @@ export type PollingResultError = {
|
|
|
165
140
|
};
|
|
166
141
|
|
|
167
142
|
export type PollingResult =
|
|
168
|
-
PollingResultPending
|
|
143
|
+
| PollingResultPending
|
|
169
144
|
| PollingResultActivateSuccess
|
|
170
145
|
| PollingResultDeactivateSuccess
|
|
171
146
|
| PollingResultError;
|
|
@@ -174,3 +149,12 @@ export type PollingParams = {
|
|
|
174
149
|
flowId: string;
|
|
175
150
|
requestId: string;
|
|
176
151
|
};
|
|
152
|
+
|
|
153
|
+
/** Polling options */
|
|
154
|
+
export type PollingOptions = {
|
|
155
|
+
/** Maximum number of poll requests to make. Default 100. */
|
|
156
|
+
maxAttempts?: number;
|
|
157
|
+
|
|
158
|
+
/** Delay in milliseconds between each poll request. Default 3000. */
|
|
159
|
+
attemptDelay?: number;
|
|
160
|
+
}
|