@sinch/sdk-client 0.0.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 (116) hide show
  1. package/README.md +109 -0
  2. package/dist/api/api-client-options-helper.d.ts +0 -0
  3. package/dist/api/api-client-options-helper.js +39 -0
  4. package/dist/api/api-client-options-helper.js.map +1 -0
  5. package/dist/api/api-client-options.d.ts +28 -0
  6. package/dist/api/api-client-options.js +3 -0
  7. package/dist/api/api-client-options.js.map +1 -0
  8. package/dist/api/api-client.d.ts +104 -0
  9. package/dist/api/api-client.js +119 -0
  10. package/dist/api/api-client.js.map +1 -0
  11. package/dist/api/api-errors.d.ts +50 -0
  12. package/dist/api/api-errors.js +51 -0
  13. package/dist/api/api-errors.js.map +1 -0
  14. package/dist/api/api-interface.d.ts +8 -0
  15. package/dist/api/api-interface.js +3 -0
  16. package/dist/api/api-interface.js.map +1 -0
  17. package/dist/api/index.d.ts +4 -0
  18. package/dist/api/index.js +22 -0
  19. package/dist/api/index.js.map +1 -0
  20. package/dist/client/api-client-helpers.d.ts +5 -0
  21. package/dist/client/api-client-helpers.js +47 -0
  22. package/dist/client/api-client-helpers.js.map +1 -0
  23. package/dist/client/api-client-pagination-helper.d.ts +15 -0
  24. package/dist/client/api-client-pagination-helper.js +180 -0
  25. package/dist/client/api-client-pagination-helper.js.map +1 -0
  26. package/dist/client/api-fetch-client.d.ts +19 -0
  27. package/dist/client/api-fetch-client.js +129 -0
  28. package/dist/client/api-fetch-client.js.map +1 -0
  29. package/dist/client/index.d.ts +2 -0
  30. package/dist/client/index.js +19 -0
  31. package/dist/client/index.js.map +1 -0
  32. package/dist/domain/domain-interface.d.ts +38 -0
  33. package/dist/domain/domain-interface.js +38 -0
  34. package/dist/domain/domain-interface.js.map +1 -0
  35. package/dist/domain/index.d.ts +1 -0
  36. package/dist/domain/index.js +18 -0
  37. package/dist/domain/index.js.map +1 -0
  38. package/dist/getVersion.d.ts +1 -0
  39. package/dist/getVersion.js +6 -0
  40. package/dist/getVersion.js.map +1 -0
  41. package/dist/index.d.ts +5 -0
  42. package/dist/index.js +22 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/plugins/additional-headers/additional-headers.request.d.ts +11 -0
  45. package/dist/plugins/additional-headers/additional-headers.request.js +21 -0
  46. package/dist/plugins/additional-headers/additional-headers.request.js.map +1 -0
  47. package/dist/plugins/additional-headers/index.d.ts +1 -0
  48. package/dist/plugins/additional-headers/index.js +18 -0
  49. package/dist/plugins/additional-headers/index.js.map +1 -0
  50. package/dist/plugins/api-token/api-token.request.d.ts +6 -0
  51. package/dist/plugins/api-token/api-token.request.js +18 -0
  52. package/dist/plugins/api-token/api-token.request.js.map +1 -0
  53. package/dist/plugins/api-token/index.d.ts +1 -0
  54. package/dist/plugins/api-token/index.js +18 -0
  55. package/dist/plugins/api-token/index.js.map +1 -0
  56. package/dist/plugins/basicAuthentication/basic-authentication.request.d.ts +7 -0
  57. package/dist/plugins/basicAuthentication/basic-authentication.request.js +21 -0
  58. package/dist/plugins/basicAuthentication/basic-authentication.request.js.map +1 -0
  59. package/dist/plugins/basicAuthentication/index.d.ts +1 -0
  60. package/dist/plugins/basicAuthentication/index.js +18 -0
  61. package/dist/plugins/basicAuthentication/index.js.map +1 -0
  62. package/dist/plugins/core/index.d.ts +3 -0
  63. package/dist/plugins/core/index.js +20 -0
  64. package/dist/plugins/core/index.js.map +1 -0
  65. package/dist/plugins/core/plugin.d.ts +14 -0
  66. package/dist/plugins/core/plugin.js +3 -0
  67. package/dist/plugins/core/plugin.js.map +1 -0
  68. package/dist/plugins/core/request-plugin.d.ts +26 -0
  69. package/dist/plugins/core/request-plugin.js +3 -0
  70. package/dist/plugins/core/request-plugin.js.map +1 -0
  71. package/dist/plugins/core/response-plugin.d.ts +33 -0
  72. package/dist/plugins/core/response-plugin.js +3 -0
  73. package/dist/plugins/core/response-plugin.js.map +1 -0
  74. package/dist/plugins/exception/exception.response.d.ts +14 -0
  75. package/dist/plugins/exception/exception.response.js +57 -0
  76. package/dist/plugins/exception/exception.response.js.map +1 -0
  77. package/dist/plugins/exception/index.d.ts +1 -0
  78. package/dist/plugins/exception/index.js +18 -0
  79. package/dist/plugins/exception/index.js.map +1 -0
  80. package/dist/plugins/index.d.ts +8 -0
  81. package/dist/plugins/index.js +25 -0
  82. package/dist/plugins/index.js.map +1 -0
  83. package/dist/plugins/oauth2/index.d.ts +2 -0
  84. package/dist/plugins/oauth2/index.js +19 -0
  85. package/dist/plugins/oauth2/index.js.map +1 -0
  86. package/dist/plugins/oauth2/oauth2-api.d.ts +15 -0
  87. package/dist/plugins/oauth2/oauth2-api.js +26 -0
  88. package/dist/plugins/oauth2/oauth2-api.js.map +1 -0
  89. package/dist/plugins/oauth2/oauth2-token.request.d.ts +15 -0
  90. package/dist/plugins/oauth2/oauth2-token.request.js +76 -0
  91. package/dist/plugins/oauth2/oauth2-token.request.js.map +1 -0
  92. package/dist/plugins/signing/index.d.ts +1 -0
  93. package/dist/plugins/signing/index.js +18 -0
  94. package/dist/plugins/signing/index.js.map +1 -0
  95. package/dist/plugins/signing/signing.request.d.ts +10 -0
  96. package/dist/plugins/signing/signing.request.js +70 -0
  97. package/dist/plugins/signing/signing.request.js.map +1 -0
  98. package/dist/plugins/version/index.d.ts +1 -0
  99. package/dist/plugins/version/index.js +18 -0
  100. package/dist/plugins/version/index.js.map +1 -0
  101. package/dist/plugins/version/version.request.d.ts +4 -0
  102. package/dist/plugins/version/version.request.js +45 -0
  103. package/dist/plugins/version/version.request.js.map +1 -0
  104. package/dist/plugins/x-timestamp/index.d.ts +1 -0
  105. package/dist/plugins/x-timestamp/index.js +18 -0
  106. package/dist/plugins/x-timestamp/index.js.map +1 -0
  107. package/dist/plugins/x-timestamp/x-timestamp.request.d.ts +4 -0
  108. package/dist/plugins/x-timestamp/x-timestamp.request.js +15 -0
  109. package/dist/plugins/x-timestamp/x-timestamp.request.js.map +1 -0
  110. package/dist/utils/index.d.ts +1 -0
  111. package/dist/utils/index.js +18 -0
  112. package/dist/utils/index.js.map +1 -0
  113. package/dist/utils/text-to-hex.d.ts +1 -0
  114. package/dist/utils/text-to-hex.js +13 -0
  115. package/dist/utils/text-to-hex.js.map +1 -0
  116. package/package.json +42 -0
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiTokenRequest = void 0;
4
+ class ApiTokenRequest {
5
+ constructor(apiToken) {
6
+ this.apiToken = apiToken;
7
+ }
8
+ load() {
9
+ return {
10
+ transform: (data) => {
11
+ data.headers.append('Authorization', `Bearer ${this.apiToken}`);
12
+ return data;
13
+ },
14
+ };
15
+ }
16
+ }
17
+ exports.ApiTokenRequest = ApiTokenRequest;
18
+ //# sourceMappingURL=api-token.request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-token.request.js","sourceRoot":"","sources":["../../../src/plugins/api-token/api-token.request.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IAG1B,YAAY,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEM,IAAI;QACT,OAAO;YACL,SAAS,EAAE,CAAC,IAAoB,EAAE,EAAE;gBAClC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;gBAChE,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAfD,0CAeC"}
@@ -0,0 +1 @@
1
+ export * from './api-token.request';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api-token.request"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/api-token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
@@ -0,0 +1,7 @@
1
+ import { PluginRunner, RequestOptions, RequestPlugin } from '../core';
2
+ export declare class BasicAuthenticationRequest implements RequestPlugin {
3
+ private readonly userName;
4
+ private readonly password;
5
+ constructor(userName: string, password: string);
6
+ load(): PluginRunner<RequestOptions, RequestOptions>;
7
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicAuthenticationRequest = void 0;
4
+ class BasicAuthenticationRequest {
5
+ constructor(userName, password) {
6
+ this.userName = userName;
7
+ this.password = password;
8
+ }
9
+ load() {
10
+ return {
11
+ transform: (data) => {
12
+ const basicAuth = 'Basic '
13
+ + Buffer.from(`${this.userName}:${this.password}`).toString('base64');
14
+ data.headers.append('Authorization', basicAuth);
15
+ return data;
16
+ },
17
+ };
18
+ }
19
+ }
20
+ exports.BasicAuthenticationRequest = BasicAuthenticationRequest;
21
+ //# sourceMappingURL=basic-authentication.request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-authentication.request.js","sourceRoot":"","sources":["../../../src/plugins/basicAuthentication/basic-authentication.request.ts"],"names":[],"mappings":";;;AAEA,MAAa,0BAA0B;IAIrC,YAAY,QAAgB,EAAE,QAAgB;QAC5C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEM,IAAI;QACT,OAAO;YACL,SAAS,EAAE,CAAC,IAAoB,EAAE,EAAE;gBAClC,MAAM,SAAS,GACX,QAAQ;sBACR,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBACxE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AApBD,gEAoBC"}
@@ -0,0 +1 @@
1
+ export * from './basic-authentication.request';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./basic-authentication.request"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/basicAuthentication/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C"}
@@ -0,0 +1,3 @@
1
+ export * from './plugin';
2
+ export * from './request-plugin';
3
+ export * from './response-plugin';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./plugin"), exports);
18
+ __exportStar(require("./request-plugin"), exports);
19
+ __exportStar(require("./response-plugin"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,mDAAiC;AACjC,oDAAkC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Interface of a runnable plugin
3
+ */
4
+ export interface PluginRunner<T, V> {
5
+ /** Transformation function */
6
+ transform(data: V): T | Promise<T>;
7
+ }
8
+ /**
9
+ * Interface of an SDK plugin
10
+ */
11
+ export interface Plugin<T, V> {
12
+ /** Load the plugin with the context */
13
+ load(context?: Record<string, any>): PluginRunner<T, V>;
14
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/plugins/core/plugin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { Plugin, PluginRunner } from './plugin';
2
+ import { Headers, RequestInit } from 'node-fetch';
3
+ import FormData = require('form-data');
4
+ export type RequestBody = string | FormData;
5
+ export interface RequestOptions extends RequestInit {
6
+ /** Query Parameters */
7
+ queryParams?: {
8
+ [key: string]: string;
9
+ };
10
+ /** Force body to string */
11
+ body?: RequestBody;
12
+ /** Force headers to Headers type */
13
+ headers: Headers;
14
+ /** URL targeted without the query parameters */
15
+ basePath: string;
16
+ /** Path of the API*/
17
+ path?: string;
18
+ }
19
+ /**
20
+ * Interface of an SDK request plugin.
21
+ * The plugin will be run on the request of a call
22
+ */
23
+ export interface RequestPlugin extends Plugin<RequestOptions, RequestOptions> {
24
+ /** Load the plugin with the context */
25
+ load(): PluginRunner<RequestOptions, RequestOptions>;
26
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=request-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-plugin.js","sourceRoot":"","sources":["../../../src/plugins/core/request-plugin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import { Plugin, PluginRunner } from './plugin';
2
+ import { Response } from 'node-fetch';
3
+ import { RequestOptions } from './request-plugin';
4
+ /**
5
+ * Interface of an SDK response plugin.
6
+ * The plugin will be run on the response of a call
7
+ */
8
+ export interface ResponsePluginContext {
9
+ /** Response from Fetch call */
10
+ response?: Response;
11
+ /** Name of the API */
12
+ apiName: string;
13
+ /** Exception thrown during call/parse of the response */
14
+ exception?: Error;
15
+ /** Operation ID */
16
+ operationId: string;
17
+ /** Base url */
18
+ url: string;
19
+ /** Origin domain initiating the call */
20
+ origin?: string | null;
21
+ /** Request parameters */
22
+ requestOptions: RequestOptions;
23
+ }
24
+ /**
25
+ * Interface of an SDK response plugin.
26
+ * The plugin will be run on the response of a call
27
+ */
28
+ export interface ResponsePlugin<T, V = {
29
+ [key: string]: any;
30
+ }> extends Plugin<T, V> {
31
+ /** Load the plugin with the context */
32
+ load<K>(context: ResponsePluginContext): PluginRunner<T | K, V | undefined>;
33
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=response-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-plugin.js","sourceRoot":"","sources":["../../../src/plugins/core/response-plugin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { PluginRunner, ResponsePlugin, ResponsePluginContext } from '../core';
2
+ /**
3
+ * Plugin to fire an exception on wrong response / data
4
+ */
5
+ export declare class ExceptionResponse<V extends Record<string, any> | undefined = Record<string, any>> implements ResponsePlugin<V | Record<string, unknown>, V> {
6
+ private callback?;
7
+ /**
8
+ * Initialize an instance of the class, with an optional callback function for exception handling.
9
+ *
10
+ * @param {Function} [callback] - A function called in case of an exception. If provided, this function is responsible for throwing the exception or not.
11
+ */
12
+ constructor(callback?: ((res: V, error: Error | undefined) => V) | undefined);
13
+ load(context: ResponsePluginContext): PluginRunner<V | Record<string, unknown>, V>;
14
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExceptionResponse = void 0;
4
+ const api_1 = require("../../api");
5
+ /**
6
+ * Plugin to fire an exception on wrong response / data
7
+ */
8
+ class ExceptionResponse {
9
+ /**
10
+ * Initialize an instance of the class, with an optional callback function for exception handling.
11
+ *
12
+ * @param {Function} [callback] - A function called in case of an exception. If provided, this function is responsible for throwing the exception or not.
13
+ */
14
+ constructor(callback) {
15
+ this.callback = callback;
16
+ }
17
+ load(context) {
18
+ return {
19
+ transform: (res) => {
20
+ if (context.exception) {
21
+ return res;
22
+ }
23
+ const errorContext = {
24
+ apiName: context.apiName,
25
+ operationId: context.operationId,
26
+ url: context.url,
27
+ origin: context.origin,
28
+ };
29
+ let error;
30
+ if (!context.response) {
31
+ error = new api_1.EmptyResponseError('Fail to Fetch', errorContext, undefined);
32
+ }
33
+ else if (!context.response.ok) {
34
+ error = new api_1.RequestFailedError(context.response.statusText, context.response.status, errorContext, res);
35
+ }
36
+ else if (!res) {
37
+ res = {};
38
+ if (context.response.status !== 204 && context.response.status !== 200) {
39
+ res = {};
40
+ error = new api_1.EmptyResponseError(context.response.statusText, errorContext, res);
41
+ }
42
+ }
43
+ if (error) {
44
+ if (this.callback) {
45
+ return this.callback(res, error);
46
+ }
47
+ else {
48
+ throw error;
49
+ }
50
+ }
51
+ return res;
52
+ },
53
+ };
54
+ }
55
+ }
56
+ exports.ExceptionResponse = ExceptionResponse;
57
+ //# sourceMappingURL=exception.response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exception.response.js","sourceRoot":"","sources":["../../../src/plugins/exception/exception.response.ts"],"names":[],"mappings":";;;AAAA,mCAAmE;AAGnE;;GAEG;AACH,MAAa,iBAAiB;IAI9B;;;;OAIG;IACD,YAAoB,QAAkD;QAAlD,aAAQ,GAAR,QAAQ,CAA0C;IAAG,CAAC;IAEnE,IAAI,CACT,OAA8B;QAE9B,OAAO;YACL,SAAS,EAAE,CAAC,GAAM,EAAE,EAAE;gBACpB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;oBACtB,OAAO,GAAG,CAAC;gBACb,CAAC;gBAED,MAAM,YAAY,GAAG;oBACnB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,WAAW,EAAE,OAAO,CAAC,WAAW;oBAChC,GAAG,EAAE,OAAO,CAAC,GAAG;oBAChB,MAAM,EAAE,OAAO,CAAC,MAAM;iBACvB,CAAC;gBACF,IAAI,KAAwB,CAAC;gBAE7B,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;oBACtB,KAAK,GAAG,IAAI,wBAAkB,CAC5B,eAAe,EACf,YAAY,EACZ,SAAS,CACV,CAAC;gBACJ,CAAC;qBAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBAChC,KAAK,GAAG,IAAI,wBAAkB,CAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,EAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,EACvB,YAAY,EACZ,GAAG,CACJ,CAAC;gBACJ,CAAC;qBAAM,IAAI,CAAC,GAAG,EAAE,CAAC;oBAChB,GAAG,GAAG,EAAO,CAAC;oBACd,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;wBACvE,GAAG,GAAG,EAAO,CAAC;wBACd,KAAK,GAAG,IAAI,wBAAkB,CAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,EAC3B,YAAY,EACZ,GAAG,CACJ,CAAC;oBACJ,CAAC;gBACH,CAAC;gBAED,IAAI,KAAK,EAAE,CAAC;oBACV,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;wBAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;oBACnC,CAAC;yBAAM,CAAC;wBACN,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;gBACD,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAhED,8CAgEC"}
@@ -0,0 +1 @@
1
+ export * from './exception.response';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./exception.response"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/exception/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
@@ -0,0 +1,8 @@
1
+ export * from './core';
2
+ export * from './api-token';
3
+ export * from './basicAuthentication';
4
+ export * from './exception';
5
+ export * from './oauth2';
6
+ export * from './signing';
7
+ export * from './version';
8
+ export * from './x-timestamp';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./core"), exports);
18
+ __exportStar(require("./api-token"), exports);
19
+ __exportStar(require("./basicAuthentication"), exports);
20
+ __exportStar(require("./exception"), exports);
21
+ __exportStar(require("./oauth2"), exports);
22
+ __exportStar(require("./signing"), exports);
23
+ __exportStar(require("./version"), exports);
24
+ __exportStar(require("./x-timestamp"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,8CAA4B;AAC5B,wDAAsC;AACtC,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,4CAA0B;AAC1B,gDAA8B"}
@@ -0,0 +1,2 @@
1
+ export * from './oauth2-api';
2
+ export * from './oauth2-token.request';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./oauth2-api"), exports);
18
+ __exportStar(require("./oauth2-token.request"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/oauth2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,yDAAuC"}
@@ -0,0 +1,15 @@
1
+ import { Api, ApiClient } from '../../api';
2
+ export interface Response {
3
+ access_token: string;
4
+ expires_in: number;
5
+ scope: string;
6
+ token_type: string;
7
+ }
8
+ export declare class OAuth2Api implements Api {
9
+ /** @inheritDoc */
10
+ readonly apiName = "OAuth2Api";
11
+ /** @inheritDoc */
12
+ readonly client: ApiClient;
13
+ constructor(apiClient: ApiClient);
14
+ postAccessToken(): Promise<Response>;
15
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAuth2Api = void 0;
4
+ class OAuth2Api {
5
+ constructor(apiClient) {
6
+ /** @inheritDoc */
7
+ this.apiName = 'OAuth2Api';
8
+ this.client = apiClient;
9
+ }
10
+ async postAccessToken() {
11
+ const headers = {
12
+ 'Content-Type': 'application/x-www-form-urlencoded',
13
+ };
14
+ const body = `${encodeURIComponent('grant_type')}=${encodeURIComponent('client_credentials')}`;
15
+ const url = `${this.client.apiClientOptions.basePath}/oauth2/token`;
16
+ const requestOptions = await this.client.prepareOptions(url, 'POST', {}, headers, body);
17
+ return this.client.processCall({
18
+ url,
19
+ requestOptions,
20
+ apiName: this.apiName,
21
+ operationId: 'OAuth2Token',
22
+ });
23
+ }
24
+ }
25
+ exports.OAuth2Api = OAuth2Api;
26
+ //# sourceMappingURL=oauth2-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2-api.js","sourceRoot":"","sources":["../../../src/plugins/oauth2/oauth2-api.ts"],"names":[],"mappings":";;;AASA,MAAa,SAAS;IAOpB,YAAY,SAAoB;QANhC,kBAAkB;QACF,YAAO,GAAG,WAAW,CAAC;QAMpC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,eAAe;QAC1B,MAAM,OAAO,GAA8B;YACzC,cAAc,EAAE,mCAAmC;SACpD,CAAC;QACF,MAAM,IAAI,GAAG,GAAG,kBAAkB,CAAC,YAAY,CAAC,IAAI,kBAAkB,CACpE,oBAAoB,CACrB,EAAE,CAAC;QACJ,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,eAAe,CAAC;QACpE,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CACrD,GAAG,EACH,MAAM,EACN,EAAE,EACF,OAAO,EACP,IAAI,CACL,CAAC;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAW;YACvC,GAAG;YACH,cAAc;YACd,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,aAAa;SAC3B,CAAC,CAAC;IACL,CAAC;CACF;AAjCD,8BAiCC"}
@@ -0,0 +1,15 @@
1
+ import { PluginRunner, RequestOptions, RequestPlugin } from '../core';
2
+ export declare class Oauth2TokenRequest implements RequestPlugin {
3
+ private readonly apiClient;
4
+ private token;
5
+ constructor(clientId: string, clientSecret: string, authenticationUrl?: string);
6
+ private getOAuth2Token;
7
+ private buildAuthorizationHeader;
8
+ private isTokenValid;
9
+ load(): PluginRunner<RequestOptions, RequestOptions>;
10
+ invalidateToken(): void;
11
+ }
12
+ export declare enum TokenStatus {
13
+ INVALID = 0,
14
+ VALID = 1
15
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenStatus = exports.Oauth2TokenRequest = void 0;
4
+ const additional_headers_1 = require("../additional-headers");
5
+ const oauth2_api_1 = require("./oauth2-api");
6
+ const basicAuthentication_1 = require("../basicAuthentication");
7
+ const client_1 = require("../../client");
8
+ class Oauth2TokenRequest {
9
+ constructor(clientId, clientSecret, authenticationUrl) {
10
+ const basicAuthenticationPlugin = new basicAuthentication_1.BasicAuthenticationRequest(clientId, clientSecret);
11
+ if (!authenticationUrl) {
12
+ authenticationUrl = 'https://auth.sinch.com';
13
+ }
14
+ this.apiClient = new client_1.ApiFetchClient({
15
+ basePath: authenticationUrl,
16
+ requestPlugins: [basicAuthenticationPlugin],
17
+ });
18
+ }
19
+ async getOAuth2Token() {
20
+ if (this.isTokenValid()) {
21
+ return this.buildAuthorizationHeader();
22
+ }
23
+ const oauth2Api = new oauth2_api_1.OAuth2Api(this.apiClient);
24
+ try {
25
+ const response = await oauth2Api.postAccessToken();
26
+ if (response.access_token) {
27
+ this.token = {
28
+ value: response.access_token,
29
+ status: TokenStatus.VALID,
30
+ };
31
+ return this.buildAuthorizationHeader();
32
+ }
33
+ else {
34
+ this.token = {
35
+ value: '',
36
+ status: TokenStatus.INVALID,
37
+ };
38
+ console.error('No access_token has been returned. Response = ' + JSON.stringify(response));
39
+ return {};
40
+ }
41
+ }
42
+ catch (e) {
43
+ this.token = {
44
+ value: '',
45
+ status: TokenStatus.INVALID,
46
+ };
47
+ console.error('An error occurred when trying to get the authentication token - ' + e);
48
+ return {};
49
+ }
50
+ }
51
+ buildAuthorizationHeader() {
52
+ return { Authorization: `Bearer ${this.token.value}` };
53
+ }
54
+ isTokenValid() {
55
+ return (this.token
56
+ && this.token.status === TokenStatus.VALID
57
+ && this.token.value.trim().length > 0);
58
+ }
59
+ load() {
60
+ return {
61
+ transform: new additional_headers_1.AdditionalHeadersRequest({
62
+ headers: this.getOAuth2Token(),
63
+ }).load().transform,
64
+ };
65
+ }
66
+ invalidateToken() {
67
+ this.token = undefined;
68
+ }
69
+ }
70
+ exports.Oauth2TokenRequest = Oauth2TokenRequest;
71
+ var TokenStatus;
72
+ (function (TokenStatus) {
73
+ TokenStatus[TokenStatus["INVALID"] = 0] = "INVALID";
74
+ TokenStatus[TokenStatus["VALID"] = 1] = "VALID";
75
+ })(TokenStatus || (exports.TokenStatus = TokenStatus = {}));
76
+ //# sourceMappingURL=oauth2-token.request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2-token.request.js","sourceRoot":"","sources":["../../../src/plugins/oauth2/oauth2-token.request.ts"],"names":[],"mappings":";;;AACA,8DAAiE;AAEjE,6CAAyC;AACzC,gEAAoE;AACpE,yCAA8C;AAE9C,MAAa,kBAAkB;IAK7B,YACE,QAAgB,EAChB,YAAoB,EACpB,iBAA0B;QAE1B,MAAM,yBAAyB,GAAG,IAAI,gDAA0B,CAC9D,QAAQ,EACR,YAAY,CACb,CAAC;QACF,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,iBAAiB,GAAG,wBAAwB,CAAC;QAC/C,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,uBAAc,CAAC;YAClC,QAAQ,EAAE,iBAAiB;YAC3B,cAAc,EAAE,CAAC,yBAAyB,CAAC;SAC5C,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,cAAc;QAC1B,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,wBAAwB,EAAE,CAAC;QACzC,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,eAAe,EAAE,CAAC;YACnD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;gBAC1B,IAAI,CAAC,KAAK,GAAG;oBACX,KAAK,EAAE,QAAQ,CAAC,YAAY;oBAC5B,MAAM,EAAE,WAAW,CAAC,KAAK;iBAC1B,CAAC;gBACF,OAAO,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACzC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,KAAK,GAAG;oBACX,KAAK,EAAE,EAAE;oBACT,MAAM,EAAE,WAAW,CAAC,OAAO;iBAC5B,CAAC;gBACF,OAAO,CAAC,KAAK,CAAC,gDAAgD,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAC3F,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,KAAK,GAAG;gBACX,KAAK,EAAE,EAAE;gBACT,MAAM,EAAE,WAAW,CAAC,OAAO;aAC5B,CAAC;YACF,OAAO,CAAC,KAAK,CAAC,kEAAkE,GAAG,CAAC,CAAC,CAAC;YACtF,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAGO,wBAAwB;QAC9B,OAAO,EAAE,aAAa,EAAE,UAAU,IAAI,CAAC,KAAM,CAAC,KAAK,EAAE,EAAE,CAAC;IAC1D,CAAC;IAEO,YAAY;QAClB,OAAO,CACL,IAAI,CAAC,KAAK;eACP,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC,KAAK;eACvC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CACtC,CAAC;IACJ,CAAC;IAEM,IAAI;QACT,OAAO;YACL,SAAS,EAAE,IAAI,6CAAwB,CAAC;gBACtC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE;aAC/B,CAAC,CAAC,IAAI,EAAE,CAAC,SAAS;SACpB,CAAC;IACJ,CAAC;IAEM,eAAe;QACpB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACzB,CAAC;CACF;AA9ED,gDA8EC;AAOD,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,mDAAO,CAAA;IACP,+CAAK,CAAA;AACP,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB"}
@@ -0,0 +1 @@
1
+ export * from './signing.request';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./signing.request"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/signing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
@@ -0,0 +1,10 @@
1
+ import { PluginRunner, RequestOptions, RequestPlugin } from '../core';
2
+ export declare const calculateMD5: (body: string) => string;
3
+ export declare const calculateHMACSHA256: (secret: string, stringToSign: string) => string;
4
+ export declare const generateAuthorizationHeader: (httpVerb: string, contentMD5: string, contentType: string, canonicalizedHeaders: string, canonicalizedResource: string, applicationKey: string, applicationSecret: string) => string;
5
+ export declare class SigningRequest implements RequestPlugin {
6
+ private readonly applicationId;
7
+ private readonly applicationSecret;
8
+ constructor(applicationId: string, applicationSecret: string);
9
+ load(): PluginRunner<RequestOptions, RequestOptions>;
10
+ }