@hatchet-dev/typescript-sdk 0.1.12 → 0.1.13

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.
@@ -0,0 +1,509 @@
1
+ export interface APIMeta {
2
+ auth?: APIMetaAuth;
3
+ }
4
+ export interface APIMetaAuth {
5
+ /**
6
+ * the supported types of authentication
7
+ * @example ["basic","google"]
8
+ */
9
+ schemes?: string[];
10
+ }
11
+ export interface APIErrors {
12
+ errors: APIError[];
13
+ }
14
+ export interface APIError {
15
+ /**
16
+ * a custom Hatchet error code
17
+ * @format uint64
18
+ * @example 1400
19
+ */
20
+ code?: number;
21
+ /**
22
+ * the field that this error is associated with, if applicable
23
+ * @example "name"
24
+ */
25
+ field?: string;
26
+ /**
27
+ * a description for this error
28
+ * @example "A descriptive error message"
29
+ */
30
+ description: string;
31
+ /**
32
+ * a link to the documentation for this error, if it exists
33
+ * @example "github.com/hatchet-dev/hatchet"
34
+ */
35
+ docs_link?: string;
36
+ }
37
+ /** @example {"next_page":3,"num_pages":10,"current_page":2} */
38
+ export interface PaginationResponse {
39
+ /**
40
+ * the current page
41
+ * @format int64
42
+ * @example 2
43
+ */
44
+ current_page?: number;
45
+ /**
46
+ * the next page
47
+ * @format int64
48
+ * @example 3
49
+ */
50
+ next_page?: number;
51
+ /**
52
+ * the total number of pages for listing
53
+ * @format int64
54
+ * @example 10
55
+ */
56
+ num_pages?: number;
57
+ }
58
+ export interface APIResourceMeta {
59
+ /**
60
+ * the id of this resource, in UUID format
61
+ * @format uuid
62
+ * @minLength 36
63
+ * @maxLength 36
64
+ * @example "bb214807-246e-43a5-a25d-41761d1cff9e"
65
+ */
66
+ id: string;
67
+ /**
68
+ * the time that this resource was created
69
+ * @format date-time
70
+ * @example "2022-12-13T20:06:48.888Z"
71
+ */
72
+ createdAt: string;
73
+ /**
74
+ * the time that this resource was last updated
75
+ * @format date-time
76
+ * @example "2022-12-13T20:06:48.888Z"
77
+ */
78
+ updatedAt: string;
79
+ }
80
+ export interface User {
81
+ metadata: APIResourceMeta;
82
+ /** The display name of the user. */
83
+ name?: string;
84
+ /**
85
+ * The email address of the user.
86
+ * @format email
87
+ */
88
+ email: string;
89
+ /** Whether the user has verified their email address. */
90
+ emailVerified: boolean;
91
+ }
92
+ export interface UserTenantPublic {
93
+ /**
94
+ * The email address of the user.
95
+ * @format email
96
+ */
97
+ email: string;
98
+ /** The display name of the user. */
99
+ name?: string;
100
+ }
101
+ export interface UserLoginRequest {
102
+ /**
103
+ * The email address of the user.
104
+ * @format email
105
+ */
106
+ email: string;
107
+ /** The password of the user. */
108
+ password: string;
109
+ }
110
+ export interface UserRegisterRequest {
111
+ /** The name of the user. */
112
+ name: string;
113
+ /**
114
+ * The email address of the user.
115
+ * @format email
116
+ */
117
+ email: string;
118
+ /** The password of the user. */
119
+ password: string;
120
+ }
121
+ export interface UserTenantMembershipsList {
122
+ pagination?: PaginationResponse;
123
+ rows?: TenantMember[];
124
+ }
125
+ export interface Tenant {
126
+ metadata: APIResourceMeta;
127
+ /** The name of the tenant. */
128
+ name: string;
129
+ /** The slug of the tenant. */
130
+ slug: string;
131
+ }
132
+ export interface TenantMember {
133
+ metadata: APIResourceMeta;
134
+ /** The user associated with this tenant member. */
135
+ user: UserTenantPublic;
136
+ /** The role of the user in the tenant. */
137
+ role: TenantMemberRole;
138
+ /** The tenant associated with this tenant member. */
139
+ tenant?: Tenant;
140
+ }
141
+ export interface TenantMemberList {
142
+ pagination?: PaginationResponse;
143
+ rows?: TenantMember[];
144
+ }
145
+ export declare enum TenantMemberRole {
146
+ OWNER = "OWNER",
147
+ ADMIN = "ADMIN",
148
+ MEMBER = "MEMBER"
149
+ }
150
+ export interface CreateTenantInviteRequest {
151
+ /** The email of the user to invite. */
152
+ email: string;
153
+ /** The role of the user in the tenant. */
154
+ role: TenantMemberRole;
155
+ }
156
+ export interface UpdateTenantInviteRequest {
157
+ /** The role of the user in the tenant. */
158
+ role: TenantMemberRole;
159
+ }
160
+ export interface TenantInvite {
161
+ metadata: APIResourceMeta;
162
+ /** The email of the user to invite. */
163
+ email: string;
164
+ /** The role of the user in the tenant. */
165
+ role: TenantMemberRole;
166
+ /** The tenant id associated with this tenant invite. */
167
+ tenantId: string;
168
+ /** The tenant name for the tenant. */
169
+ tenantName?: string;
170
+ /**
171
+ * The time that this invite expires.
172
+ * @format date-time
173
+ */
174
+ expires: string;
175
+ }
176
+ export interface TenantInviteList {
177
+ pagination?: PaginationResponse;
178
+ rows?: TenantInvite[];
179
+ }
180
+ export interface AcceptInviteRequest {
181
+ /**
182
+ * @minLength 36
183
+ * @maxLength 36
184
+ * @example "bb214807-246e-43a5-a25d-41761d1cff9e"
185
+ */
186
+ invite: string;
187
+ }
188
+ export interface RejectInviteRequest {
189
+ /**
190
+ * @minLength 36
191
+ * @maxLength 36
192
+ * @example "bb214807-246e-43a5-a25d-41761d1cff9e"
193
+ */
194
+ invite: string;
195
+ }
196
+ export interface TenantList {
197
+ pagination?: PaginationResponse;
198
+ rows?: Tenant[];
199
+ }
200
+ export interface CreateTenantRequest {
201
+ /** The name of the tenant. */
202
+ name: string;
203
+ /** The slug of the tenant. */
204
+ slug: string;
205
+ }
206
+ export interface Event {
207
+ metadata: APIResourceMeta;
208
+ /** The key for the event. */
209
+ key: string;
210
+ /** The tenant associated with this event. */
211
+ tenant?: Tenant;
212
+ /** The ID of the tenant associated with this event. */
213
+ tenantId: string;
214
+ /** The workflow run summary for this event. */
215
+ workflowRunSummary?: EventWorkflowRunSummary;
216
+ }
217
+ export interface EventData {
218
+ /** The data for the event (JSON bytes). */
219
+ data: string;
220
+ }
221
+ export interface EventWorkflowRunSummary {
222
+ /**
223
+ * The number of pending runs.
224
+ * @format int64
225
+ */
226
+ pending?: number;
227
+ /**
228
+ * The number of running runs.
229
+ * @format int64
230
+ */
231
+ running?: number;
232
+ /**
233
+ * The number of succeeded runs.
234
+ * @format int64
235
+ */
236
+ succeeded?: number;
237
+ /**
238
+ * The number of failed runs.
239
+ * @format int64
240
+ */
241
+ failed?: number;
242
+ }
243
+ export declare enum EventOrderByField {
244
+ CreatedAt = "createdAt"
245
+ }
246
+ export declare enum EventOrderByDirection {
247
+ Asc = "asc",
248
+ Desc = "desc"
249
+ }
250
+ export type EventSearch = string;
251
+ export interface EventKeyList {
252
+ pagination?: PaginationResponse;
253
+ rows?: EventKey[];
254
+ }
255
+ /** The key for the event. */
256
+ export type EventKey = string;
257
+ /** A workflow ID. */
258
+ export type WorkflowID = string;
259
+ export interface EventList {
260
+ pagination?: PaginationResponse;
261
+ rows?: Event[];
262
+ }
263
+ export interface ReplayEventRequest {
264
+ eventIds: string[];
265
+ }
266
+ export interface Workflow {
267
+ metadata: APIResourceMeta;
268
+ /** The name of the workflow. */
269
+ name: string;
270
+ /** The description of the workflow. */
271
+ description?: string;
272
+ versions?: WorkflowVersionMeta[];
273
+ /** The tags of the workflow. */
274
+ tags?: WorkflowTag[];
275
+ lastRun?: WorkflowRun;
276
+ /** The jobs of the workflow. */
277
+ jobs?: Job[];
278
+ }
279
+ export interface WorkflowVersionMeta {
280
+ metadata: APIResourceMeta;
281
+ /** The version of the workflow. */
282
+ version: string;
283
+ /** @format int32 */
284
+ order: number;
285
+ workflowId: string;
286
+ workflow?: Workflow;
287
+ }
288
+ export interface WorkflowVersion {
289
+ metadata: APIResourceMeta;
290
+ /** The version of the workflow. */
291
+ version: string;
292
+ /** @format int32 */
293
+ order: number;
294
+ workflowId: string;
295
+ workflow?: Workflow;
296
+ triggers?: WorkflowTriggers;
297
+ jobs?: Job[];
298
+ }
299
+ export interface WorkflowVersionDefinition {
300
+ /** The raw YAML definition of the workflow. */
301
+ rawDefinition: string;
302
+ }
303
+ export interface WorkflowTag {
304
+ /** The name of the workflow. */
305
+ name: string;
306
+ /** The description of the workflow. */
307
+ color: string;
308
+ }
309
+ export interface WorkflowList {
310
+ metadata?: APIResourceMeta;
311
+ rows?: Workflow[];
312
+ pagination?: PaginationResponse;
313
+ }
314
+ export interface WorkflowTriggers {
315
+ metadata?: APIResourceMeta;
316
+ workflow_version_id?: string;
317
+ tenant_id?: string;
318
+ events?: WorkflowTriggerEventRef[];
319
+ crons?: WorkflowTriggerCronRef[];
320
+ }
321
+ export interface WorkflowTriggerEventRef {
322
+ parent_id?: string;
323
+ event_key?: string;
324
+ }
325
+ export interface WorkflowTriggerCronRef {
326
+ parent_id?: string;
327
+ cron?: string;
328
+ }
329
+ export interface Job {
330
+ metadata: APIResourceMeta;
331
+ tenantId: string;
332
+ versionId: string;
333
+ name: string;
334
+ /** The description of the job. */
335
+ description?: string;
336
+ steps: Step[];
337
+ /** The timeout of the job. */
338
+ timeout?: string;
339
+ }
340
+ export interface Step {
341
+ metadata: APIResourceMeta;
342
+ /** The readable id of the step. */
343
+ readableId: string;
344
+ tenantId: string;
345
+ jobId: string;
346
+ action: string;
347
+ /** The timeout of the step. */
348
+ timeout?: string;
349
+ children?: string[];
350
+ parents?: string[];
351
+ }
352
+ export interface WorkflowRun {
353
+ metadata: APIResourceMeta;
354
+ tenantId: string;
355
+ workflowVersionId: string;
356
+ workflowVersion?: WorkflowVersion;
357
+ status: WorkflowRunStatus;
358
+ displayName?: string;
359
+ jobRuns?: JobRun[];
360
+ triggeredBy: WorkflowRunTriggeredBy;
361
+ input?: Record<string, any>;
362
+ error?: string;
363
+ /** @format date-time */
364
+ startedAt?: string;
365
+ /** @format date-time */
366
+ finishedAt?: string;
367
+ }
368
+ export interface WorkflowRunList {
369
+ rows?: WorkflowRun[];
370
+ pagination?: PaginationResponse;
371
+ }
372
+ export declare enum WorkflowRunStatus {
373
+ PENDING = "PENDING",
374
+ RUNNING = "RUNNING",
375
+ SUCCEEDED = "SUCCEEDED",
376
+ FAILED = "FAILED",
377
+ CANCELLED = "CANCELLED"
378
+ }
379
+ export declare enum JobRunStatus {
380
+ PENDING = "PENDING",
381
+ RUNNING = "RUNNING",
382
+ SUCCEEDED = "SUCCEEDED",
383
+ FAILED = "FAILED",
384
+ CANCELLED = "CANCELLED"
385
+ }
386
+ export declare enum StepRunStatus {
387
+ PENDING = "PENDING",
388
+ PENDING_ASSIGNMENT = "PENDING_ASSIGNMENT",
389
+ ASSIGNED = "ASSIGNED",
390
+ RUNNING = "RUNNING",
391
+ SUCCEEDED = "SUCCEEDED",
392
+ FAILED = "FAILED",
393
+ CANCELLED = "CANCELLED"
394
+ }
395
+ export interface JobRun {
396
+ metadata: APIResourceMeta;
397
+ tenantId: string;
398
+ workflowRunId: string;
399
+ workflowRun?: WorkflowRun;
400
+ jobId: string;
401
+ job?: Job;
402
+ tickerId?: string;
403
+ stepRuns?: StepRun[];
404
+ status: JobRunStatus;
405
+ result?: object;
406
+ /** @format date-time */
407
+ startedAt?: string;
408
+ /** @format date-time */
409
+ finishedAt?: string;
410
+ /** @format date-time */
411
+ timeoutAt?: string;
412
+ /** @format date-time */
413
+ cancelledAt?: string;
414
+ cancelledReason?: string;
415
+ cancelledError?: string;
416
+ }
417
+ export interface WorkflowRunTriggeredBy {
418
+ metadata: APIResourceMeta;
419
+ parentId: string;
420
+ eventId?: string;
421
+ event?: Event;
422
+ cronParentId?: string;
423
+ cronSchedule?: string;
424
+ }
425
+ export interface StepRun {
426
+ metadata: APIResourceMeta;
427
+ tenantId: string;
428
+ jobRunId: string;
429
+ jobRun?: JobRun;
430
+ stepId: string;
431
+ step?: Step;
432
+ children?: string[];
433
+ parents?: string[];
434
+ workerId?: string;
435
+ input?: string;
436
+ output?: string;
437
+ status: StepRunStatus;
438
+ /** @format date-time */
439
+ requeueAfter?: string;
440
+ result?: object;
441
+ error?: string;
442
+ /** @format date-time */
443
+ startedAt?: string;
444
+ startedAtEpoch?: number;
445
+ /** @format date-time */
446
+ finishedAt?: string;
447
+ finishedAtEpoch?: number;
448
+ /** @format date-time */
449
+ timeoutAt?: string;
450
+ timeoutAtEpoch?: number;
451
+ /** @format date-time */
452
+ cancelledAt?: string;
453
+ cancelledAtEpoch?: number;
454
+ cancelledReason?: string;
455
+ cancelledError?: string;
456
+ }
457
+ export interface WorkerList {
458
+ pagination?: PaginationResponse;
459
+ rows?: Worker[];
460
+ }
461
+ export interface Worker {
462
+ metadata: APIResourceMeta;
463
+ /** The name of the worker. */
464
+ name: string;
465
+ /**
466
+ * The time this worker last sent a heartbeat.
467
+ * @format date-time
468
+ * @example "2022-12-13T20:06:48.888Z"
469
+ */
470
+ lastHeartbeatAt?: string;
471
+ /** The actions this worker can perform. */
472
+ actions?: string[];
473
+ /** The recent step runs for this worker. */
474
+ recentStepRuns?: StepRun[];
475
+ }
476
+ export interface APIToken {
477
+ metadata: APIResourceMeta;
478
+ /**
479
+ * The name of the API token.
480
+ * @maxLength 255
481
+ */
482
+ name: string;
483
+ /**
484
+ * When the API token expires.
485
+ * @format date-time
486
+ */
487
+ expiresAt: string;
488
+ }
489
+ export interface CreateAPITokenRequest {
490
+ /**
491
+ * A name for the API token.
492
+ * @maxLength 255
493
+ */
494
+ name: string;
495
+ }
496
+ export interface CreateAPITokenResponse {
497
+ /** The API token. */
498
+ token: string;
499
+ }
500
+ export interface ListAPITokensResponse {
501
+ pagination?: PaginationResponse;
502
+ rows?: APIToken[];
503
+ }
504
+ export interface RerunStepRunRequest {
505
+ input: object;
506
+ }
507
+ export interface TriggerWorkflowRunRequest {
508
+ input: object;
509
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /* tslint:disable */
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.StepRunStatus = exports.JobRunStatus = exports.WorkflowRunStatus = exports.EventOrderByDirection = exports.EventOrderByField = exports.TenantMemberRole = void 0;
14
+ var TenantMemberRole;
15
+ (function (TenantMemberRole) {
16
+ TenantMemberRole["OWNER"] = "OWNER";
17
+ TenantMemberRole["ADMIN"] = "ADMIN";
18
+ TenantMemberRole["MEMBER"] = "MEMBER";
19
+ })(TenantMemberRole || (exports.TenantMemberRole = TenantMemberRole = {}));
20
+ var EventOrderByField;
21
+ (function (EventOrderByField) {
22
+ EventOrderByField["CreatedAt"] = "createdAt";
23
+ })(EventOrderByField || (exports.EventOrderByField = EventOrderByField = {}));
24
+ var EventOrderByDirection;
25
+ (function (EventOrderByDirection) {
26
+ EventOrderByDirection["Asc"] = "asc";
27
+ EventOrderByDirection["Desc"] = "desc";
28
+ })(EventOrderByDirection || (exports.EventOrderByDirection = EventOrderByDirection = {}));
29
+ var WorkflowRunStatus;
30
+ (function (WorkflowRunStatus) {
31
+ WorkflowRunStatus["PENDING"] = "PENDING";
32
+ WorkflowRunStatus["RUNNING"] = "RUNNING";
33
+ WorkflowRunStatus["SUCCEEDED"] = "SUCCEEDED";
34
+ WorkflowRunStatus["FAILED"] = "FAILED";
35
+ WorkflowRunStatus["CANCELLED"] = "CANCELLED";
36
+ })(WorkflowRunStatus || (exports.WorkflowRunStatus = WorkflowRunStatus = {}));
37
+ var JobRunStatus;
38
+ (function (JobRunStatus) {
39
+ JobRunStatus["PENDING"] = "PENDING";
40
+ JobRunStatus["RUNNING"] = "RUNNING";
41
+ JobRunStatus["SUCCEEDED"] = "SUCCEEDED";
42
+ JobRunStatus["FAILED"] = "FAILED";
43
+ JobRunStatus["CANCELLED"] = "CANCELLED";
44
+ })(JobRunStatus || (exports.JobRunStatus = JobRunStatus = {}));
45
+ var StepRunStatus;
46
+ (function (StepRunStatus) {
47
+ StepRunStatus["PENDING"] = "PENDING";
48
+ StepRunStatus["PENDING_ASSIGNMENT"] = "PENDING_ASSIGNMENT";
49
+ StepRunStatus["ASSIGNED"] = "ASSIGNED";
50
+ StepRunStatus["RUNNING"] = "RUNNING";
51
+ StepRunStatus["SUCCEEDED"] = "SUCCEEDED";
52
+ StepRunStatus["FAILED"] = "FAILED";
53
+ StepRunStatus["CANCELLED"] = "CANCELLED";
54
+ })(StepRunStatus || (exports.StepRunStatus = StepRunStatus = {}));
@@ -0,0 +1,41 @@
1
+ import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios';
2
+ export type QueryParamsType = Record<string | number, any>;
3
+ export interface FullRequestParams extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {
4
+ /** set parameter to `true` for call `securityWorker` for this request */
5
+ secure?: boolean;
6
+ /** request path */
7
+ path: string;
8
+ /** content type of request body */
9
+ type?: ContentType;
10
+ /** query params */
11
+ query?: QueryParamsType;
12
+ /** format of response (i.e. response.json() -> format: "json") */
13
+ format?: ResponseType;
14
+ /** request body */
15
+ body?: unknown;
16
+ }
17
+ export type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
18
+ export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {
19
+ securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
20
+ secure?: boolean;
21
+ format?: ResponseType;
22
+ }
23
+ export declare enum ContentType {
24
+ Json = "application/json",
25
+ FormData = "multipart/form-data",
26
+ UrlEncoded = "application/x-www-form-urlencoded",
27
+ Text = "text/plain"
28
+ }
29
+ export declare class HttpClient<SecurityDataType = unknown> {
30
+ instance: AxiosInstance;
31
+ private securityData;
32
+ private securityWorker?;
33
+ private secure?;
34
+ private format?;
35
+ constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig<SecurityDataType>);
36
+ setSecurityData: (data: SecurityDataType | null) => void;
37
+ protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
38
+ protected stringifyFormItem(formItem: unknown): string;
39
+ protected createFormData(input: Record<string, unknown>): FormData;
40
+ request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T, any>>;
41
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /* tslint:disable */
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __rest = (this && this.__rest) || function (s, e) {
22
+ var t = {};
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
+ t[p] = s[p];
25
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
+ t[p[i]] = s[p[i]];
29
+ }
30
+ return t;
31
+ };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.HttpClient = exports.ContentType = void 0;
37
+ const axios_1 = __importDefault(require("axios"));
38
+ var ContentType;
39
+ (function (ContentType) {
40
+ ContentType["Json"] = "application/json";
41
+ ContentType["FormData"] = "multipart/form-data";
42
+ ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
43
+ ContentType["Text"] = "text/plain";
44
+ })(ContentType || (exports.ContentType = ContentType = {}));
45
+ class HttpClient {
46
+ constructor(_a = {}) {
47
+ var { securityWorker, secure, format } = _a, axiosConfig = __rest(_a, ["securityWorker", "secure", "format"]);
48
+ this.securityData = null;
49
+ this.setSecurityData = (data) => {
50
+ this.securityData = data;
51
+ };
52
+ this.request = (_b) => __awaiter(this, void 0, void 0, function* () {
53
+ var { secure, path, type, query, format, body } = _b, params = __rest(_b, ["secure", "path", "type", "query", "format", "body"]);
54
+ const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) &&
55
+ this.securityWorker &&
56
+ (yield this.securityWorker(this.securityData))) ||
57
+ {};
58
+ const requestParams = this.mergeRequestParams(params, secureParams);
59
+ const responseFormat = format || this.format || undefined;
60
+ if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {
61
+ body = this.createFormData(body);
62
+ }
63
+ if (type === ContentType.Text && body && body !== null && typeof body !== 'string') {
64
+ body = JSON.stringify(body);
65
+ }
66
+ return this.instance.request(Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type && type !== ContentType.FormData ? { 'Content-Type': type } : {})), params: query, responseType: responseFormat, data: body, url: path }));
67
+ });
68
+ this.instance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { baseURL: axiosConfig.baseURL || '' }));
69
+ this.secure = secure;
70
+ this.format = format;
71
+ this.securityWorker = securityWorker;
72
+ }
73
+ mergeRequestParams(params1, params2) {
74
+ const method = params1.method || (params2 && params2.method);
75
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, this.instance.defaults), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, ((method &&
76
+ this.instance.defaults.headers[method.toLowerCase()]) ||
77
+ {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
78
+ }
79
+ stringifyFormItem(formItem) {
80
+ if (typeof formItem === 'object' && formItem !== null) {
81
+ return JSON.stringify(formItem);
82
+ }
83
+ else {
84
+ return `${formItem}`;
85
+ }
86
+ }
87
+ createFormData(input) {
88
+ return Object.keys(input || {}).reduce((formData, key) => {
89
+ const property = input[key];
90
+ const propertyContent = property instanceof Array ? property : [property];
91
+ for (const formItem of propertyContent) {
92
+ const isFileType = formItem instanceof Blob || formItem instanceof File;
93
+ formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
94
+ }
95
+ return formData;
96
+ }, new FormData());
97
+ }
98
+ }
99
+ exports.HttpClient = HttpClient;