celitech-sdk 1.1.86 → 1.1.87

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # Celitech TypeScript SDK 1.1.86
1
+ # Celitech TypeScript SDK 1.1.87
2
2
 
3
3
  Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
4
4
 
5
5
  ## Versions
6
6
 
7
7
  - API version: `1.1.0`
8
- - SDK version: `1.1.86`
8
+ - SDK version: `1.1.87`
9
9
 
10
10
  ## About the API
11
11
 
@@ -18,6 +18,7 @@ Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.
18
18
  - [Installation](#installation)
19
19
  - [Environment Variables](#environment-variables)
20
20
  - [Setting a Custom Timeout](#setting-a-custom-timeout)
21
+ - [Sample Usage](#sample-usage)
21
22
  - [Services](#services)
22
23
  - [Models](#models)
23
24
  - [License](#license)
@@ -57,6 +58,25 @@ You can set a custom timeout for the SDK's HTTP requests as follows:
57
58
  const celitech = new Celitech({ timeout: 10000 });
58
59
  ```
59
60
 
61
+ # Sample Usage
62
+
63
+ Below is a comprehensive example demonstrating how to authenticate and call a simple endpoint:
64
+
65
+ ```ts
66
+ import { Celitech } from 'celitech-sdk';
67
+
68
+ (async () => {
69
+ const celitech = new Celitech({
70
+ clientId: 'client-id',
71
+ clientSecret: 'client-secret',
72
+ });
73
+
74
+ const { data } = await celitech.destinations.listDestinations();
75
+
76
+ console.log(data);
77
+ })();
78
+ ```
79
+
60
80
  ## Services
61
81
 
62
82
  The SDK provides various services to interact with the API.
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ declare enum Environment {
4
4
  DEFAULT = "https://api.celitech.net/v1"
5
5
  }
6
6
 
7
- type HttpMethod$1 = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
7
+ type HttpMethod$1 = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
8
8
  interface HttpRequest {
9
9
  baseUrl: string;
10
10
  method: HttpMethod$1;
@@ -97,7 +97,7 @@ declare class Request<T> {
97
97
  private constructPath;
98
98
  }
99
99
 
100
- type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
100
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
101
101
  interface SdkConfig {
102
102
  baseUrl?: string;
103
103
  environment?: Environment;
@@ -112,7 +112,7 @@ interface HttpMetadata {
112
112
  statusText: string;
113
113
  headers: Record<string, string>;
114
114
  }
115
- interface HttpResponse<T> {
115
+ interface HttpResponse<T = unknown> {
116
116
  data?: T;
117
117
  metadata: HttpMetadata;
118
118
  raw: ArrayBuffer;
package/dist/index.js CHANGED
@@ -451,53 +451,87 @@ var RequestValidationHandler = class {
451
451
  }
452
452
  };
453
453
 
454
- // src/http/transport/request-fetch-adapter.ts
455
- var RequestFetchAdapter = class {
454
+ // src/http/transport/request-axios-adapter.ts
455
+ var import_axios = __toESM(require("axios"));
456
+ var RequestAxiosAdapter = class {
456
457
  constructor(request) {
457
458
  this.request = request;
458
- this.requestInit = {};
459
- this.setMethod(request.method);
460
- this.setHeaders(request.getHeaders());
461
- this.setBody(request.body);
462
- this.setTimeout(request.config.timeout);
459
+ this.config = {
460
+ responseType: "arraybuffer"
461
+ };
462
+ this.setHeaders();
463
+ this.setTimeout();
463
464
  }
464
465
  async send() {
465
- return fetch(this.request.constructFullUrl(), this.requestInit);
466
- }
467
- setMethod(method) {
468
- if (!method) {
469
- return;
466
+ const method = this.getMethod();
467
+ const { body } = this.request;
468
+ let axiosResponse;
469
+ try {
470
+ if (this.request.method === "POST" || this.request.method === "PUT" || this.request.method === "PATCH") {
471
+ axiosResponse = await method(this.request.constructFullUrl(), body, this.config);
472
+ } else {
473
+ axiosResponse = await method(this.request.constructFullUrl(), this.config);
474
+ }
475
+ } catch (err) {
476
+ if ((0, import_axios.isAxiosError)(err) && err.response) {
477
+ axiosResponse = err.response;
478
+ } else {
479
+ throw err;
480
+ }
470
481
  }
471
- this.requestInit = {
472
- ...this.requestInit,
473
- method
482
+ const headerRecord = {};
483
+ Object.keys(axiosResponse.headers).forEach((key) => {
484
+ headerRecord[key] = axiosResponse.headers[key];
485
+ });
486
+ const metadata = {
487
+ status: axiosResponse.status,
488
+ statusText: axiosResponse.statusText || "",
489
+ headers: headerRecord
474
490
  };
475
- }
476
- setBody(body) {
477
- if (!body) {
478
- return;
491
+ if (metadata.status >= 400) {
492
+ throw new HttpError(metadata);
479
493
  }
480
- this.requestInit = {
481
- ...this.requestInit,
482
- body
494
+ return {
495
+ metadata,
496
+ raw: axiosResponse.data.buffer.slice(
497
+ axiosResponse.data.byteOffset,
498
+ axiosResponse.data.byteOffset + axiosResponse.data.byteLength
499
+ )
483
500
  };
484
501
  }
485
- setHeaders(headers) {
486
- if (!headers) {
487
- return;
502
+ getMethod() {
503
+ if (this.request.method === "POST") {
504
+ return import_axios.default.post;
505
+ } else if (this.request.method === "GET") {
506
+ return import_axios.default.get;
507
+ } else if (this.request.method === "PUT") {
508
+ return import_axios.default.put;
509
+ } else if (this.request.method === "DELETE") {
510
+ return import_axios.default.delete;
511
+ } else if (this.request.method === "PATCH") {
512
+ return import_axios.default.patch;
513
+ } else if (this.request.method === "HEAD") {
514
+ return import_axios.default.head;
488
515
  }
489
- this.requestInit = {
490
- ...this.requestInit,
491
- headers
492
- };
516
+ throw new Error("invalid method!!!!");
493
517
  }
494
- setTimeout(timeout) {
495
- if (!timeout) {
518
+ setHeaders() {
519
+ if (!this.request.headers) {
496
520
  return;
497
521
  }
498
- this.requestInit = {
499
- ...this.requestInit,
500
- signal: AbortSignal.timeout(timeout)
522
+ const headersRecord = {};
523
+ new Headers(this.request.getHeaders()).forEach((value, key) => {
524
+ headersRecord[key] = value;
525
+ });
526
+ this.config = {
527
+ ...this.config,
528
+ headers: headersRecord
529
+ };
530
+ }
531
+ setTimeout() {
532
+ this.config = {
533
+ ...this.config,
534
+ timeout: this.request.config.timeout
501
535
  };
502
536
  }
503
537
  };
@@ -505,29 +539,7 @@ var RequestFetchAdapter = class {
505
539
  // src/http/handlers/terminating-handler.ts
506
540
  var TerminatingHandler = class {
507
541
  async handle(request) {
508
- const response = await new RequestFetchAdapter(request).send();
509
- const metadata = {
510
- status: response.status,
511
- statusText: response.statusText,
512
- headers: this.getHeaders(response)
513
- };
514
- if (metadata.status >= 400) {
515
- throw new HttpError(metadata);
516
- }
517
- return {
518
- metadata,
519
- raw: await response.clone().arrayBuffer()
520
- };
521
- }
522
- getHeaders(response) {
523
- const headers = {};
524
- response.headers.forEach((value, key) => {
525
- headers[key] = value;
526
- });
527
- return headers;
528
- }
529
- isErrorResponse(response) {
530
- return response.metadata.status >= 400;
542
+ return new RequestAxiosAdapter(request).send();
531
543
  }
532
544
  };
533
545
 
package/dist/index.mjs CHANGED
@@ -411,53 +411,87 @@ var RequestValidationHandler = class {
411
411
  }
412
412
  };
413
413
 
414
- // src/http/transport/request-fetch-adapter.ts
415
- var RequestFetchAdapter = class {
414
+ // src/http/transport/request-axios-adapter.ts
415
+ import axios, { isAxiosError } from "axios";
416
+ var RequestAxiosAdapter = class {
416
417
  constructor(request) {
417
418
  this.request = request;
418
- this.requestInit = {};
419
- this.setMethod(request.method);
420
- this.setHeaders(request.getHeaders());
421
- this.setBody(request.body);
422
- this.setTimeout(request.config.timeout);
419
+ this.config = {
420
+ responseType: "arraybuffer"
421
+ };
422
+ this.setHeaders();
423
+ this.setTimeout();
423
424
  }
424
425
  async send() {
425
- return fetch(this.request.constructFullUrl(), this.requestInit);
426
- }
427
- setMethod(method) {
428
- if (!method) {
429
- return;
426
+ const method = this.getMethod();
427
+ const { body } = this.request;
428
+ let axiosResponse;
429
+ try {
430
+ if (this.request.method === "POST" || this.request.method === "PUT" || this.request.method === "PATCH") {
431
+ axiosResponse = await method(this.request.constructFullUrl(), body, this.config);
432
+ } else {
433
+ axiosResponse = await method(this.request.constructFullUrl(), this.config);
434
+ }
435
+ } catch (err) {
436
+ if (isAxiosError(err) && err.response) {
437
+ axiosResponse = err.response;
438
+ } else {
439
+ throw err;
440
+ }
430
441
  }
431
- this.requestInit = {
432
- ...this.requestInit,
433
- method
442
+ const headerRecord = {};
443
+ Object.keys(axiosResponse.headers).forEach((key) => {
444
+ headerRecord[key] = axiosResponse.headers[key];
445
+ });
446
+ const metadata = {
447
+ status: axiosResponse.status,
448
+ statusText: axiosResponse.statusText || "",
449
+ headers: headerRecord
434
450
  };
435
- }
436
- setBody(body) {
437
- if (!body) {
438
- return;
451
+ if (metadata.status >= 400) {
452
+ throw new HttpError(metadata);
439
453
  }
440
- this.requestInit = {
441
- ...this.requestInit,
442
- body
454
+ return {
455
+ metadata,
456
+ raw: axiosResponse.data.buffer.slice(
457
+ axiosResponse.data.byteOffset,
458
+ axiosResponse.data.byteOffset + axiosResponse.data.byteLength
459
+ )
443
460
  };
444
461
  }
445
- setHeaders(headers) {
446
- if (!headers) {
447
- return;
462
+ getMethod() {
463
+ if (this.request.method === "POST") {
464
+ return axios.post;
465
+ } else if (this.request.method === "GET") {
466
+ return axios.get;
467
+ } else if (this.request.method === "PUT") {
468
+ return axios.put;
469
+ } else if (this.request.method === "DELETE") {
470
+ return axios.delete;
471
+ } else if (this.request.method === "PATCH") {
472
+ return axios.patch;
473
+ } else if (this.request.method === "HEAD") {
474
+ return axios.head;
448
475
  }
449
- this.requestInit = {
450
- ...this.requestInit,
451
- headers
452
- };
476
+ throw new Error("invalid method!!!!");
453
477
  }
454
- setTimeout(timeout) {
455
- if (!timeout) {
478
+ setHeaders() {
479
+ if (!this.request.headers) {
456
480
  return;
457
481
  }
458
- this.requestInit = {
459
- ...this.requestInit,
460
- signal: AbortSignal.timeout(timeout)
482
+ const headersRecord = {};
483
+ new Headers(this.request.getHeaders()).forEach((value, key) => {
484
+ headersRecord[key] = value;
485
+ });
486
+ this.config = {
487
+ ...this.config,
488
+ headers: headersRecord
489
+ };
490
+ }
491
+ setTimeout() {
492
+ this.config = {
493
+ ...this.config,
494
+ timeout: this.request.config.timeout
461
495
  };
462
496
  }
463
497
  };
@@ -465,29 +499,7 @@ var RequestFetchAdapter = class {
465
499
  // src/http/handlers/terminating-handler.ts
466
500
  var TerminatingHandler = class {
467
501
  async handle(request) {
468
- const response = await new RequestFetchAdapter(request).send();
469
- const metadata = {
470
- status: response.status,
471
- statusText: response.statusText,
472
- headers: this.getHeaders(response)
473
- };
474
- if (metadata.status >= 400) {
475
- throw new HttpError(metadata);
476
- }
477
- return {
478
- metadata,
479
- raw: await response.clone().arrayBuffer()
480
- };
481
- }
482
- getHeaders(response) {
483
- const headers = {};
484
- response.headers.forEach((value, key) => {
485
- headers[key] = value;
486
- });
487
- return headers;
488
- }
489
- isErrorResponse(response) {
490
- return response.metadata.status >= 400;
502
+ return new RequestAxiosAdapter(request).send();
491
503
  }
492
504
  };
493
505
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "celitech-sdk",
3
- "version": "1.1.86",
3
+ "version": "1.1.87",
4
4
  "description": "Welcome to the CELITECH API documentation! Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/) ",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/commonjs/index.js",
@@ -9,6 +9,7 @@
9
9
  "unpkg": "./dist/index.umd.js",
10
10
  "types": "./dist/commonjs/index.d.ts",
11
11
  "scripts": {
12
+ "test": "tsc --noEmit",
12
13
  "build": "tsup-node src/index.ts --format cjs,esm --dts --clean",
13
14
  "prepublishOnly": "npm run build"
14
15
  },
@@ -29,7 +30,8 @@
29
30
  "tsup": "^6.7.0"
30
31
  },
31
32
  "dependencies": {
32
- "zod": "3.22.0"
33
+ "zod": "3.22.0",
34
+ "axios": "^1.7.4"
33
35
  },
34
36
  "exports": {
35
37
  ".": {