@unmeshed/sdk 1.0.13 → 1.0.16

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/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Unmeshed Javascript / Typescript SDK
2
+
3
+ This README will guide you on how to set up Unmeshed credentials, run workers, and get started with the Unmeshed
4
+ platform. Read more about unmeshed on https://unmeshed.io/
5
+
6
+ ## About Unmeshed
7
+
8
+ Unmeshed is a ⚡ fast, low latency orchestration platform, that can be used to build 🛠️, run 🏃, and scale 📈 API and
9
+ microservices orchestration, scheduled jobs ⏰, and more with ease. Learn more on
10
+ our [🌍 main website](https://unmeshed.io) or explore
11
+ the [📖 documentation overview](https://unmeshed.io/docs/concepts/overview).
12
+
13
+ Unmeshed is built by the ex-founders of Netflix Conductor. This is the next gen platform built using similar principles
14
+ but is blazing fast and covers many more use cases.
15
+
16
+ ---
17
+
18
+ ## Installing the Unmeshed SDK
19
+
20
+ To use Unmeshed in your project, install the SDK using your preferred package manager:
21
+
22
+ ### Using npm:
23
+
24
+ ```bash
25
+ npm install @unmeshed/sdk
26
+ ```
27
+
28
+ ### Using Yarn:
29
+
30
+ ```bash
31
+ yarn add @unmeshed/sdk
32
+ ```
33
+
34
+ ## Setting Up Unmeshed Credentials
35
+
36
+ To use the Unmeshed SDK in your Node.js app, you need to initialize the `UnmeshedClient` with your credentials. Replace
37
+ the placeholder values below with your actual credentials:
38
+
39
+ ```javascript
40
+ const {UnmeshedClient} = require("@unmeshed/sdk");
41
+
42
+ const unmeshedClient = new UnmeshedClient({
43
+ baseUrl: 'http://localhost', // Replace with your Unmeshed API endpoint 🌐
44
+ port: 8080, // Replace with your Unmeshed API port 🚪
45
+ authToken: 'your-auth-token', // Replace with your API 🔒 auth token
46
+ clientId: 'your-client-id' // Replace with your API 🆔 client ID
47
+ });
48
+ ```
49
+
50
+ > **Note:** Do not expose these credentials in a browser 🌐. For browser implementations, leverage webhooks and user
51
+ > tokens 🔑 directly.
52
+
53
+ You can get started with Unmeshed by visiting our [📘 Get Started Guide](https://unmeshed.io/docs/concepts/overview).
54
+
55
+ ---
56
+
57
+ ## Running a Worker
58
+
59
+ A worker in Unmeshed processes 🌀 tasks asynchronously based on workflows or process definitions. Below is an example of
60
+ defining and starting a worker:
61
+
62
+ ### Step 1: Define a Worker Function
63
+
64
+ A worker function processes incoming tasks and returns an output:
65
+
66
+ ```javascript
67
+ let workerFunction = (input) => {
68
+ return new Promise((resolve) => {
69
+ const output = {
70
+ ...input || {},
71
+ "ranAt": new Date() // Add the current timestamp to the output 🕒
72
+ };
73
+ resolve(output);
74
+ });
75
+ };
76
+ ```
77
+
78
+ ### Step 2: Register the Worker
79
+
80
+ Define the worker configuration and register it with the `UnmeshedClient`:
81
+
82
+ ```javascript
83
+ const worker = {
84
+ worker: workerFunction,
85
+ namespace: 'default', // Namespace for the worker 🗂️
86
+ name: 'test-node-worker', // Unique name for the worker 🏷️
87
+ maxInProgress: 500 // Maximum number of in-progress tasks ⏳
88
+ };
89
+
90
+ unmeshedClient.startPolling([worker]);
91
+ ```
92
+
93
+
94
+ You can run as many workers as you want.
95
+
96
+
97
+ Et voilà — that's it! Now whenever a process definition or worker reaches this step with name test-node-worker, it will run your function
98
+
99
+ > The `startPolling` method starts the worker to listen 👂 for tasks continuously.
100
+
101
+ ### Step 3: Start Your Application
102
+
103
+ When you run your Node.js app, and the worker will start polling for tasks automatically 🤖.
104
+
105
+ ---
106
+
107
+ ## Additional Resources
108
+
109
+ - **[📖 Workers Documentation](https://unmeshed.io/docs/concepts/workers):** Learn more about workers and how to use them
110
+ effectively.
111
+ - **Use Case Highlights:**
112
+ - [🌐 API Orchestration](https://unmeshed.io/docs/use-cases/api-orchestration)
113
+ - [🧩 Microservices Orchestration](https://unmeshed.io/docs/use-cases/microservices-orchestration)
114
+ - [⏰ Scheduled Jobs](https://unmeshed.io/docs/use-cases/scheduled-jobs)
115
+
116
+ ---
117
+
118
+ ## Example Applications
119
+
120
+ 1. [express-server-example](https://github.com/unmeshed/express-server-example)
121
+ 2. [typescript-sdk-example](https://github.com/unmeshed/typescript-sdk-example)
122
+ 3. [javascript-sdk-example](https://github.com/unmeshed/javascript-sdk-example)
123
+
124
+ ---
125
+
126
+ For more details, visit our [📖 documentation](https://unmeshed.io/docs/concepts/overview). If you encounter issues, feel
127
+ free to reach out or open an issue in this repository!
128
+
@@ -0,0 +1,370 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+
3
+ declare enum ApiCallType {
4
+ SYNC = "SYNC",
5
+ ASYNC = "ASYNC",
6
+ STREAM = "STREAM"
7
+ }
8
+ interface ApiMappingData {
9
+ endpoint: string;
10
+ processDefNamespace: string;
11
+ processDefName: string;
12
+ processDefVersion: number;
13
+ authType: string;
14
+ authClaims: string;
15
+ createdBy: string;
16
+ updatedBy: string;
17
+ created: Date;
18
+ updated: Date;
19
+ }
20
+ type ApiMappingWebhookData = {
21
+ endpoint: string;
22
+ name: string;
23
+ uniqueId: string;
24
+ urlSecret: string;
25
+ description: string;
26
+ userIdentifier: string;
27
+ webhookSource: WebhookSource;
28
+ webhookSourceConfig: Record<string, string>;
29
+ expiryDate: Date;
30
+ userType: SQAuthUserType;
31
+ createdBy: string;
32
+ updatedBy: string;
33
+ created: Date;
34
+ updated: Date;
35
+ };
36
+ declare enum WebhookSource {
37
+ MS_TEAMS = "MS_TEAMS",
38
+ NOT_DEFINED = "NOT_DEFINED"
39
+ }
40
+ declare enum SQAuthUserType {
41
+ USER = "USER",
42
+ API = "API",
43
+ INTERNAL = "INTERNAL"
44
+ }
45
+ declare enum StepType {
46
+ WORKER = "WORKER",
47
+ HTTP = "HTTP",
48
+ WAIT = "WAIT",
49
+ FAIL = "FAIL",
50
+ PYTHON = "PYTHON",
51
+ JAVASCRIPT = "JAVASCRIPT",
52
+ JQ = "JQ",
53
+ MANAGED = "MANAGED",
54
+ BUILTIN = "BUILTIN",
55
+ NOOP = "NOOP",
56
+ PERSISTED_STATE = "PERSISTED_STATE",
57
+ DEPENDSON = "DEPENDSON",
58
+ INTEGRATION = "INTEGRATION",
59
+ EXIT = "EXIT",
60
+ SUB_PROCESS = "SUB_PROCESS",
61
+ LIST = "LIST",
62
+ PARALLEL = "PARALLEL",
63
+ FOREACH = "FOREACH",
64
+ SWITCH = "SWITCH"
65
+ }
66
+ declare enum StepStatus {
67
+ PENDING = "PENDING",
68
+ SCHEDULED = "SCHEDULED",
69
+ RUNNING = "RUNNING",
70
+ PAUSED = "PAUSED",
71
+ COMPLETED = "COMPLETED",
72
+ FAILED = "FAILED",
73
+ TIMED_OUT = "TIMED_OUT",
74
+ SKIPPED = "SKIPPED",
75
+ CANCELLED = "CANCELLED"
76
+ }
77
+ declare enum ProcessStatus {
78
+ RUNNING = "RUNNING",
79
+ COMPLETED = "COMPLETED",
80
+ FAILED = "FAILED",
81
+ TIMED_OUT = "TIMED_OUT",
82
+ CANCELLED = "CANCELLED",
83
+ TERMINATED = "TERMINATED",
84
+ REVIEWED = "REVIEWED"
85
+ }
86
+ declare enum ProcessTriggerType {
87
+ MANUAL = "MANUAL",
88
+ SCHEDULED = "SCHEDULED",
89
+ API_MAPPING = "API_MAPPING",
90
+ WEBHOOK = "WEBHOOK",
91
+ API = "API",
92
+ SUB_PROCESS = "SUB_PROCESS"
93
+ }
94
+ declare enum ProcessType {
95
+ STANDARD = "STANDARD",
96
+ DYNAMIC = "DYNAMIC",
97
+ API_ORCHESTRATION = "API_ORCHESTRATION",
98
+ INTERNAL = "INTERNAL"
99
+ }
100
+ type ClientProfileData = {
101
+ clientId: string;
102
+ ipAddress: string;
103
+ friendlyName: string;
104
+ userIdentifier: string;
105
+ stepQueueNames: StepQueueNameData[];
106
+ createdBy: string;
107
+ updatedBy: string;
108
+ created: Date;
109
+ updated: Date;
110
+ expiryDate: Date;
111
+ };
112
+ type FullClientProfileData = {
113
+ clientId: string;
114
+ ipAddress: string;
115
+ friendlyName: string;
116
+ userIdentifier: string;
117
+ stepQueueNames: StepQueueNameData[];
118
+ createdBy: string;
119
+ updatedBy: string;
120
+ created: Date;
121
+ updated: Date;
122
+ expiryDate: Date;
123
+ tokenValue: string;
124
+ };
125
+ type StepQueueNameData = {
126
+ orgId: number;
127
+ namespace: string;
128
+ stepType: StepType;
129
+ name: string;
130
+ };
131
+ type ProcessActionResponseData = {
132
+ count: number;
133
+ details: ProcessActionResponseDetailData[];
134
+ };
135
+ type ProcessActionResponseDetailData = {
136
+ id: string;
137
+ message: string;
138
+ error: string;
139
+ };
140
+ type ProcessData = {
141
+ processId: number;
142
+ processType: ProcessType;
143
+ triggerType: ProcessTriggerType;
144
+ namespace: string;
145
+ name: string;
146
+ version: number | null;
147
+ processDefinitionHistoryId: number | null;
148
+ requestId: string;
149
+ correlationId: string;
150
+ status: ProcessStatus;
151
+ input: Record<string, unknown>;
152
+ output: Record<string, unknown>;
153
+ stepIdCount: number | null;
154
+ shardName: string;
155
+ shardInstanceId: number | null;
156
+ stepIds: StepId[];
157
+ stepDataById: Record<number, StepData>;
158
+ created: number;
159
+ updated: number;
160
+ createdBy: string;
161
+ };
162
+ type StepData = {
163
+ id: number;
164
+ processId: number;
165
+ ref: string;
166
+ parentId: number | null;
167
+ parentRef: string | null;
168
+ namespace: string;
169
+ name: string;
170
+ type: StepType;
171
+ stepDefinitionHistoryId: number | null;
172
+ status: StepStatus;
173
+ input: Record<string, unknown>;
174
+ output: Record<string, unknown>;
175
+ workerId: string;
176
+ start: number;
177
+ schedule: number;
178
+ priority: number;
179
+ updated: number;
180
+ optional: boolean;
181
+ executionList: StepExecutionData[];
182
+ };
183
+ type StepExecutionData = {
184
+ id: number;
185
+ scheduled: number;
186
+ polled: number;
187
+ start: number;
188
+ updated: number;
189
+ executor: string;
190
+ ref: string;
191
+ runs: number;
192
+ output: Record<string, unknown>;
193
+ };
194
+ type StepId = {
195
+ id: number;
196
+ processId: number;
197
+ ref: string;
198
+ };
199
+ type ProcessRequestData = {
200
+ name: string;
201
+ namespace: string;
202
+ version: number | null;
203
+ requestId: string;
204
+ correlationId: string;
205
+ input: Record<string, unknown>;
206
+ };
207
+ type ProcessSearchRequest = {
208
+ startTimeEpoch: number;
209
+ endTimeEpoch?: number | null;
210
+ namespace: string;
211
+ processTypes: ProcessType[];
212
+ triggerTypes: ProcessTriggerType[];
213
+ names: string[];
214
+ processIds: number[];
215
+ correlationIds: string[];
216
+ requestIds: string[];
217
+ statuses: ProcessStatus[];
218
+ limit: number;
219
+ offset: number;
220
+ };
221
+ type StepSize = {
222
+ stepQueueNameData: StepQueueNameData;
223
+ size: number | null;
224
+ };
225
+ type ClientSubmitResult = {
226
+ processId: number;
227
+ stepId: number;
228
+ errorMessage: string | null;
229
+ httpStatusCode: number | null;
230
+ };
231
+ type WorkRequest = {
232
+ processId: number;
233
+ stepId: number;
234
+ stepExecutionId: number;
235
+ runCount: number;
236
+ stepName: string;
237
+ stepNamespace: string;
238
+ stepRef: string;
239
+ inputParam: Record<string, unknown>;
240
+ isOptional: boolean;
241
+ polled: number;
242
+ scheduled: number;
243
+ updated: number;
244
+ priority: number;
245
+ };
246
+ type WorkResponse = {
247
+ processId: number;
248
+ stepId: number;
249
+ stepExecutionId: number;
250
+ runCount: number;
251
+ output: Record<string, unknown>;
252
+ status: StepStatus;
253
+ rescheduleAfterSeconds: number | null;
254
+ startedAt: number;
255
+ };
256
+ type WorkResult = {
257
+ output: unknown;
258
+ taskExecutionId: string;
259
+ startTime: number;
260
+ endTime: number;
261
+ workRequest: WorkRequest;
262
+ };
263
+ interface FinalUnmeshedClientConfig {
264
+ baseUrl: string;
265
+ clientId: string;
266
+ authToken: string;
267
+ port: string | number;
268
+ timeout: number;
269
+ apiWorkerTimeout: number;
270
+ pollTimeout: number;
271
+ pollInterval: number;
272
+ responsePollInterval: number;
273
+ responsePollTimeout: number;
274
+ responseBatchSize: number;
275
+ }
276
+ interface UnmeshedClientConfig {
277
+ baseUrl: string;
278
+ clientId: string;
279
+ authToken: string;
280
+ port: string | number;
281
+ timeout?: number;
282
+ apiWorkerTimeout?: number;
283
+ pollTimeout?: number;
284
+ pollInterval?: number;
285
+ responsePollInterval?: number;
286
+ responsePollTimeout?: number;
287
+ responseBatchSize?: number;
288
+ }
289
+ interface ApiResponse<T = any> {
290
+ data: T;
291
+ status: number;
292
+ headers: Record<string, string>;
293
+ }
294
+ interface ApiError extends Error {
295
+ status?: number;
296
+ response?: {
297
+ data?: any;
298
+ status: number;
299
+ headers: Record<string, string>;
300
+ };
301
+ }
302
+ interface QueryParams {
303
+ [key: string]: string | number | boolean | undefined;
304
+ }
305
+ interface RequestConfig extends Omit<AxiosRequestConfig, "baseURL" | "url" | "method"> {
306
+ headers?: Record<string, string>;
307
+ }
308
+ interface HandleRequestConfig {
309
+ method: "get" | "post" | "put" | "delete";
310
+ endpoint: string;
311
+ params?: QueryParams;
312
+ data?: Record<string, unknown>;
313
+ config?: RequestConfig;
314
+ }
315
+ interface ClientRequestConfig {
316
+ params?: QueryParams;
317
+ data?: any;
318
+ config?: RequestConfig;
319
+ }
320
+ interface UnmeshedWorker {
321
+ (input: Record<string, any>): Promise<any>;
322
+ }
323
+ interface UnmeshedWorkerConfig {
324
+ worker: UnmeshedWorker;
325
+ namespace: string;
326
+ name: string;
327
+ maxInProgress: number;
328
+ }
329
+ interface PollRequestData {
330
+ stepQueueNameData: StepQueueNameData;
331
+ size: number;
332
+ }
333
+ interface RenewRegistrationParams {
334
+ friendlyName: string;
335
+ }
336
+
337
+ declare class UnmeshedApiClient {
338
+ private axiosInstance;
339
+ private clientId;
340
+ private _config;
341
+ constructor(unmeshedClientConfig: UnmeshedClientConfig);
342
+ private handleRequest;
343
+ private handleError;
344
+ get<T = any>(endpoint: string, params?: QueryParams, config?: RequestConfig): Promise<ApiResponse<T>>;
345
+ post<T = any>(endpoint: string, clientRequestConfig: ClientRequestConfig): Promise<ApiResponse<T>>;
346
+ put<T = any>(endpoint: string, clientRequestConfig: ClientRequestConfig): Promise<ApiResponse<T>>;
347
+ delete<T = any>(endpoint: string, clientRequestConfig: ClientRequestConfig): Promise<ApiResponse<T>>;
348
+ getClientId(): string | undefined;
349
+ get config(): FinalUnmeshedClientConfig;
350
+ }
351
+
352
+ declare class UnmeshedClient {
353
+ private client;
354
+ constructor(config: UnmeshedClientConfig);
355
+ startPolling(workers: UnmeshedWorkerConfig[]): void;
356
+ runProcessSync(ProcessRequestData: ProcessRequestData): Promise<ProcessData>;
357
+ runProcessAsync(ProcessRequestData: ProcessRequestData): Promise<ProcessData>;
358
+ getProcessData(processId: number, includeSteps: boolean): Promise<ProcessData>;
359
+ getStepData(stepId: number): Promise<StepData>;
360
+ bulkTerminate(processIds: number[], reason?: string): Promise<ProcessActionResponseData>;
361
+ bulkResume(processIds: number[]): Promise<ProcessActionResponseData>;
362
+ bulkReviewed(processIds: number[], reason?: string): Promise<ProcessActionResponseData>;
363
+ reRun(processId: number, clientId: string, version?: number): Promise<ProcessData>;
364
+ searchProcessExecution(params: ProcessSearchRequest): Promise<any>;
365
+ invokeApiMappingGet(apiClient: UnmeshedApiClient, endpoint: string, id: string, correlationId: string, apiCallType: ApiCallType): Promise<any>;
366
+ invokeApiMappingPost(endpoint: string, input: Record<string, any>, id: string, correlationId: string, apiCallType: ApiCallType): Promise<any>;
367
+ reNewRegistration(params: RenewRegistrationParams): Promise<string>;
368
+ }
369
+
370
+ export { ApiCallType, type ApiError, type ApiMappingData, type ApiMappingWebhookData, type ApiResponse, type ClientProfileData, type ClientRequestConfig, type ClientSubmitResult, type FinalUnmeshedClientConfig, type FullClientProfileData, type HandleRequestConfig, type PollRequestData, type ProcessActionResponseData, type ProcessActionResponseDetailData, type ProcessData, type ProcessRequestData, type ProcessSearchRequest, ProcessStatus, ProcessTriggerType, ProcessType, type QueryParams, type RenewRegistrationParams, type RequestConfig, SQAuthUserType, type StepData, type StepExecutionData, type StepId, type StepQueueNameData, type StepSize, StepStatus, StepType, UnmeshedClient, type UnmeshedClientConfig, type UnmeshedWorkerConfig, WebhookSource, type WorkRequest, type WorkResponse, type WorkResult };