@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,15 @@
1
+ import { ApiCallParametersWithPagination, ApiClient, ApiListPromise, AutoPaginationMethods, PageResult, PaginatedApiProperties, PaginationEnum } from '../api';
2
+ import { RequestOptions } from '../plugins';
3
+ export declare const createIteratorMethodsForPagination: <T>(apiClient: ApiClient, requestOptionsPromise: Promise<RequestOptions>, firstPagePromise: Promise<PageResult<T>>, context: PaginatedApiProperties) => AutoPaginationMethods<T>;
4
+ export declare const createNextPageMethod: <T>(apiClient: ApiClient, context: PaginationContext, requestOptions: RequestOptions, nextPageValue: string) => ApiListPromise<T>;
5
+ export declare function hasMore(response: any, context: PaginationContext): boolean;
6
+ export declare function calculateNextPage(response: any, context: PaginationContext): string;
7
+ export interface PaginationContext {
8
+ pagination: PaginationEnum;
9
+ apiName: string;
10
+ operationId: string;
11
+ dataKey: string;
12
+ requestOptions: RequestOptions;
13
+ }
14
+ export declare function buildPaginationContext(props: ApiCallParametersWithPagination): PaginationContext;
15
+ export declare const buildPageResultPromise: <T>(client: ApiClient, requestOptionsPromise: Promise<RequestOptions>, operationProperties: PaginatedApiProperties) => Promise<PageResult<T>>;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPageResultPromise = exports.buildPaginationContext = exports.calculateNextPage = exports.hasMore = exports.createNextPageMethod = exports.createIteratorMethodsForPagination = void 0;
4
+ const api_1 = require("../api");
5
+ class SinchIterator {
6
+ constructor(apiClient, requestOptionsPromise, firstPagePromise, context) {
7
+ this.index = 0;
8
+ this.apiClient = apiClient;
9
+ this.pagePromise = firstPagePromise;
10
+ this.requestOptionsPromise = requestOptionsPromise;
11
+ this.paginatedOperationProperties = context;
12
+ }
13
+ async iterate(pageResult) {
14
+ // If there are more elements to return on the current page
15
+ if (this.index < pageResult.data.length) {
16
+ const value = pageResult.data[this.index];
17
+ this.index += 1;
18
+ return { value, done: false };
19
+ }
20
+ // If there are other pages to getch
21
+ else if (pageResult.hasNextPage) {
22
+ // Reset counter to the first index of the next page
23
+ this.index = 0;
24
+ // Reset the current page to the next one - 'getNextPage' has different implementation depending on the pagination type (TOKEN or PAGE)
25
+ this.pagePromise = this.getNextPage(pageResult);
26
+ // Recursively call the iterator on the next page
27
+ const nextPageResponse = await this.pagePromise;
28
+ return this.iterate(nextPageResponse);
29
+ }
30
+ // No more element on the current page and no more pages to fetch
31
+ return { value: undefined, done: true };
32
+ }
33
+ async getNextPage(pageResult) {
34
+ const requestOptions = await this.requestOptionsPromise;
35
+ if (this.paginatedOperationProperties.pagination === api_1.PaginationEnum.TOKEN) {
36
+ const newParams = {
37
+ pageToken: pageResult.nextPageValue,
38
+ };
39
+ return updateQueryParamsAndSendRequest(this.apiClient, newParams, requestOptions, this.paginatedOperationProperties);
40
+ }
41
+ if (this.paginatedOperationProperties.pagination === api_1.PaginationEnum.PAGE) {
42
+ const newParams = {
43
+ page: pageResult.nextPageValue,
44
+ };
45
+ return updateQueryParamsAndSendRequest(this.apiClient, newParams, requestOptions, this.paginatedOperationProperties);
46
+ }
47
+ throw new Error(`The operationId "${this.paginatedOperationProperties.operationId}" must define a pagination model`);
48
+ }
49
+ next() {
50
+ return (async () => {
51
+ return this.iterate(await this.pagePromise);
52
+ })();
53
+ }
54
+ }
55
+ const updateQueryParamsAndSendRequest = (apiClient, newParams, requestOptions, paginatedApiProperties) => {
56
+ const newQueryParams = {
57
+ ...requestOptions.queryParams,
58
+ ...newParams,
59
+ };
60
+ const newRequestOptions = {
61
+ ...requestOptions,
62
+ queryParams: newQueryParams,
63
+ };
64
+ const newUrl = apiClient.prepareUrl(requestOptions.basePath, newQueryParams);
65
+ return apiClient.processCallWithPagination({
66
+ url: newUrl,
67
+ requestOptions: newRequestOptions,
68
+ ...paginatedApiProperties,
69
+ });
70
+ };
71
+ const createIteratorMethodsForPagination = (apiClient, requestOptionsPromise, firstPagePromise, context) => {
72
+ const iterator = new SinchIterator(apiClient, requestOptionsPromise, firstPagePromise, context);
73
+ const autoPaginationMethods = {
74
+ next: () => iterator.next(),
75
+ return: () => {
76
+ return {};
77
+ },
78
+ [Symbol.asyncIterator]: () => {
79
+ return autoPaginationMethods;
80
+ },
81
+ };
82
+ return autoPaginationMethods;
83
+ };
84
+ exports.createIteratorMethodsForPagination = createIteratorMethodsForPagination;
85
+ const createNextPageMethod = (apiClient, context, requestOptions, nextPageValue) => {
86
+ let newParams;
87
+ if (context.pagination === api_1.PaginationEnum.TOKEN) {
88
+ newParams = {
89
+ pageToken: nextPageValue,
90
+ };
91
+ }
92
+ else if (context.pagination === api_1.PaginationEnum.PAGE) {
93
+ newParams = {
94
+ page: nextPageValue,
95
+ };
96
+ }
97
+ else {
98
+ throw new Error();
99
+ }
100
+ const pageResultPromise = updateQueryParamsAndSendRequest(apiClient, newParams, requestOptions, context);
101
+ const requestOptionsPromise = new Promise((resolve) => {
102
+ resolve(requestOptions);
103
+ });
104
+ // Add properties to the Promise to offer the possibility to use it as an iterator
105
+ Object.assign(pageResultPromise, (0, exports.createIteratorMethodsForPagination)(apiClient, requestOptionsPromise, pageResultPromise, context));
106
+ return pageResultPromise;
107
+ };
108
+ exports.createNextPageMethod = createNextPageMethod;
109
+ function hasMore(response, context) {
110
+ if (context.pagination === api_1.PaginationEnum.TOKEN) {
111
+ return !!response.nextPageToken;
112
+ }
113
+ if (context.pagination === api_1.PaginationEnum.PAGE) {
114
+ const requestedPageSize = context.requestOptions.queryParams?.page_size;
115
+ const pageSize = requestedPageSize ? parseInt(requestedPageSize) : response.page_size;
116
+ return checkIfThereAreMorePages(response, pageSize);
117
+ }
118
+ throw new Error(`The operation ${context.operationId} is not meant to be paginated.`);
119
+ }
120
+ exports.hasMore = hasMore;
121
+ function calculateNextPage(response, context) {
122
+ if (context.pagination === api_1.PaginationEnum.TOKEN) {
123
+ return response['nextPageToken'];
124
+ }
125
+ if (context.pagination === api_1.PaginationEnum.PAGE) {
126
+ const currentPage = response.page || 0;
127
+ const nextPage = currentPage + 1;
128
+ return nextPage.toString();
129
+ }
130
+ throw new Error(`The operation ${context.operationId} is not meant to be paginated.`);
131
+ }
132
+ exports.calculateNextPage = calculateNextPage;
133
+ function buildPaginationContext(props) {
134
+ return {
135
+ pagination: props.pagination,
136
+ apiName: props.apiName,
137
+ operationId: props.operationId,
138
+ dataKey: props.dataKey,
139
+ requestOptions: props.requestOptions,
140
+ };
141
+ }
142
+ exports.buildPaginationContext = buildPaginationContext;
143
+ const buildPageResultPromise = async (client, requestOptionsPromise, operationProperties) => {
144
+ // Await the promise in this async method and store the result in client so that they can be reused
145
+ const requestOptions = await requestOptionsPromise;
146
+ const url = client.prepareUrl(requestOptions.basePath, requestOptions.queryParams);
147
+ return client.processCallWithPagination({
148
+ url,
149
+ requestOptions,
150
+ ...operationProperties,
151
+ });
152
+ };
153
+ exports.buildPageResultPromise = buildPageResultPromise;
154
+ const checkIfThereAreMorePages = (response, requestedPageSize) => {
155
+ const lastPageNumber = calculateLastPageValue(response, requestedPageSize);
156
+ return response.page < lastPageNumber;
157
+ };
158
+ const calculateLastPageValue = (response, requestedPageSize) => {
159
+ if (invalidatePaginationDataFromResponse(response)) {
160
+ throw new Error(`Impossible to calculate the last page value with the following parameters: count=${response.count}, page=${response.page}, page_size=${response.page_size}`);
161
+ }
162
+ if (response.page_size === 0) {
163
+ // If there are no elements on the current page, there are no more pages
164
+ return response.page;
165
+ }
166
+ // The elements in the response are not enough to determine if the current page is the last one
167
+ const pageSize = requestedPageSize || response.page_size;
168
+ const itemCount = response.count;
169
+ return Math.ceil(itemCount / pageSize) - 1;
170
+ };
171
+ const invalidatePaginationDataFromResponse = (response) => {
172
+ const currentPage = response.page;
173
+ const pageSize = response.page_size;
174
+ const itemCount = response.count;
175
+ return !isNumber(currentPage) || !isNumber(pageSize) || !isNumber(itemCount);
176
+ };
177
+ const isNumber = (value) => {
178
+ return typeof value === 'number' && !isNaN(value);
179
+ };
180
+ //# sourceMappingURL=api-client-pagination-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-client-pagination-helper.js","sourceRoot":"","sources":["../../src/client/api-client-pagination-helper.ts"],"names":[],"mappings":";;;AAAA,gCAOgB;AAGhB,MAAM,aAAa;IAQjB,YACE,SAAoB,EACpB,qBAA8C,EAC9C,gBAAwC,EACxC,OAA+B;QAE/B,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC;QACpC,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,4BAA4B,GAAG,OAAO,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAAyB;QACrC,2DAA2D;QAC3D,IAAG,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACvC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;YAChB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAChC,CAAC;QACD,oCAAoC;aAC/B,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;YAChC,oDAAoD;YACpD,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;YACf,uIAAuI;YACvI,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;YAChD,iDAAiD;YACjD,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC;YAChD,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACxC,CAAC;QACD,iEAAiE;QACjE,OAAO,EAAE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iBAAqC,EAAU,EAAE;IACzG,IAAI,oCAAoC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,oFAAoF,QAAQ,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAI,eAAe,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;IAChL,CAAC;IACD,IAAI,QAAQ,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;QAC7B,wEAAwE;QACxE,OAAO,QAAQ,CAAC,IAAK,CAAC;IACxB,CAAC;IACD,+FAA+F;IAC/F,MAAM,QAAQ,GAAW,iBAAiB,IAAI,QAAQ,CAAC,SAAU,CAAC;IAClE,MAAM,SAAS,GAAW,QAAQ,CAAC,KAAM,CAAC;IAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,oCAAoC,GAAG,CAAC,QAAwB,EAAW,EAAE;IACjF,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC;IAClC,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAAC;IACpC,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { ApiClient, ApiClientOptions, ApiCallParameters, ApiCallParametersWithPagination, PageResult } from '../api';
2
+ /** Client to process the call to the API using Fetch API */
3
+ export declare class ApiFetchClient extends ApiClient {
4
+ /**
5
+ * Initialize your API Client instance with the provided configuration options.
6
+ * Default request plugins: VersionRequest
7
+ * Default response plugins: ExceptionResponse
8
+ *
9
+ * @param {ApiClientOptions} options - Configuration options for the API Client.
10
+ */
11
+ constructor(options: ApiClientOptions);
12
+ /** @inheritdoc */
13
+ processCall<T>(props: ApiCallParameters): Promise<T>;
14
+ private sinchFetch;
15
+ processCallWithPagination<T>(props: ApiCallParametersWithPagination): Promise<PageResult<T>>;
16
+ private sinchFetchWithPagination;
17
+ private buildFetchError;
18
+ private loadResponsePlugins;
19
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ApiFetchClient = void 0;
7
+ const plugins_1 = require("../plugins");
8
+ const api_1 = require("../api");
9
+ const node_fetch_1 = __importDefault(require("node-fetch"));
10
+ const api_client_helpers_1 = require("./api-client-helpers");
11
+ const api_client_pagination_helper_1 = require("./api-client-pagination-helper");
12
+ /** Client to process the call to the API using Fetch API */
13
+ class ApiFetchClient extends api_1.ApiClient {
14
+ /**
15
+ * Initialize your API Client instance with the provided configuration options.
16
+ * Default request plugins: VersionRequest
17
+ * Default response plugins: ExceptionResponse
18
+ *
19
+ * @param {ApiClientOptions} options - Configuration options for the API Client.
20
+ */
21
+ constructor(options) {
22
+ super({
23
+ ...options,
24
+ requestPlugins: [new plugins_1.VersionRequest(), ...(options.requestPlugins || [])],
25
+ responsePlugins: [
26
+ new plugins_1.ExceptionResponse(),
27
+ ...(options.responsePlugins || []),
28
+ ],
29
+ });
30
+ }
31
+ /** @inheritdoc */
32
+ async processCall(props) {
33
+ // Read the "Origin" header if existing, for logging purposes
34
+ const origin = props.requestOptions.headers.get('Origin');
35
+ const errorContext = (0, api_client_helpers_1.buildErrorContext)(props, origin);
36
+ // Declare variables
37
+ let response;
38
+ let body;
39
+ let exception;
40
+ // Execute call
41
+ try {
42
+ // Send the request with the refresh token mechanism
43
+ response = await this.sinchFetch(props, errorContext);
44
+ body = await response.text();
45
+ }
46
+ catch (error) {
47
+ this.buildFetchError(error, errorContext);
48
+ }
49
+ let result;
50
+ try {
51
+ // Try to parse the body if there is one
52
+ result = body ? JSON.parse(body) : undefined;
53
+ }
54
+ catch (error) {
55
+ exception = new api_1.ResponseJSONParseError(error.message || 'Fail to parse response body', (response && response.status) || 0, errorContext, body);
56
+ }
57
+ // Load and invoke the response plugins to transform the response
58
+ const responsePlugins = this.loadResponsePlugins(this.apiClientOptions.responsePlugins, props, response, exception, origin);
59
+ let transformedResponse = result;
60
+ for (const pluginRunner of responsePlugins) {
61
+ transformedResponse = await pluginRunner.transform(transformedResponse);
62
+ }
63
+ // If there has been an error at some point in the process, throw it
64
+ if (exception) {
65
+ throw exception;
66
+ }
67
+ // If everything went fine, we return the transformed API response
68
+ return transformedResponse;
69
+ }
70
+ async sinchFetch(apiCallParameters, errorContext) {
71
+ const response = await (0, node_fetch_1.default)(apiCallParameters.url, apiCallParameters.requestOptions);
72
+ if (response.status === 401
73
+ && response.headers.get('www-authenticate')?.includes('expired')) {
74
+ return (0, api_client_helpers_1.manageExpiredToken)(apiCallParameters, errorContext, this.apiClientOptions.requestPlugins, apiCallParameters.requestOptions, this.processCall);
75
+ }
76
+ return response;
77
+ }
78
+ processCallWithPagination(props) {
79
+ // Read the "Origin" header if existing, for logging purposes
80
+ const origin = props.requestOptions.headers.get('Origin');
81
+ const errorContext = (0, api_client_helpers_1.buildErrorContext)(props, origin);
82
+ // Execute call
83
+ return this.sinchFetchWithPagination(props, errorContext);
84
+ }
85
+ ;
86
+ async sinchFetchWithPagination(apiCallParameters, errorContext) {
87
+ const response = await (0, node_fetch_1.default)(apiCallParameters.url, apiCallParameters.requestOptions);
88
+ if (response.status === 401
89
+ && response.headers.get('www-authenticate')?.includes('expired')) {
90
+ return (0, api_client_helpers_1.manageExpiredToken)(apiCallParameters, errorContext, this.apiClientOptions.requestPlugins, apiCallParameters.requestOptions, this.processCallWithPagination);
91
+ }
92
+ // When handling pagination, we won't return the raw response but a PageResult
93
+ const body = await response.text();
94
+ const result = JSON.parse(body);
95
+ // Read the elements' array with its key
96
+ const responseData = result[apiCallParameters.dataKey];
97
+ // Build the PageResult object
98
+ const nextPage = (0, api_client_pagination_helper_1.calculateNextPage)(result, (0, api_client_pagination_helper_1.buildPaginationContext)(apiCallParameters));
99
+ return {
100
+ data: responseData,
101
+ hasNextPage: (0, api_client_pagination_helper_1.hasMore)(result, (0, api_client_pagination_helper_1.buildPaginationContext)(apiCallParameters)),
102
+ nextPageValue: nextPage,
103
+ nextPage: () => (0, api_client_pagination_helper_1.createNextPageMethod)(this, (0, api_client_pagination_helper_1.buildPaginationContext)(apiCallParameters), apiCallParameters.requestOptions, nextPage),
104
+ };
105
+ }
106
+ buildFetchError(error, errorContext) {
107
+ if (error instanceof api_1.GenericError) {
108
+ return new api_1.GenericError(error.message, errorContext);
109
+ }
110
+ else {
111
+ return new api_1.EmptyResponseError(error.message || 'Fail to fetch', errorContext, undefined);
112
+ }
113
+ }
114
+ loadResponsePlugins(responsePlugins, apiCallParameters, response, exception, origin) {
115
+ return responsePlugins
116
+ ? responsePlugins.map((plugin) => plugin.load({
117
+ response,
118
+ exception,
119
+ apiName: apiCallParameters.apiName,
120
+ operationId: apiCallParameters.operationId,
121
+ url: apiCallParameters.url,
122
+ requestOptions: apiCallParameters.requestOptions,
123
+ origin,
124
+ }))
125
+ : [];
126
+ }
127
+ }
128
+ exports.ApiFetchClient = ApiFetchClient;
129
+ //# sourceMappingURL=api-fetch-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-fetch-client.js","sourceRoot":"","sources":["../../src/client/api-fetch-client.ts"],"names":[],"mappings":";;;;;;AAAA,wCAIoB;AACpB,gCAQgB;AAChB,4DAAsD;AACtD,6DAA6E;AAC7E,iFAKwC;AAExC,4DAA4D;AAC5D,MAAa,cAAe,SAAQ,eAAS;IAE3C;;;;;;OAMG;IACH,YAAY,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F,CAAC;IACJ,CAAC;IAEO,eAAe,CAAC,KAAU,EAAE,YAA0B;QAC5D,IAAI,KAAK,YAAY,kBAAY,EAAE,CAAC;YAClC,OAAO,IAAI,kBAAY,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,wBAAkB,CAC3B,KAAK,CAAC,OAAO,IAAI,eAAe,EAChC,YAAY,EACZ,SAAS,CACV,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,mBAAmB,CACzB,eAAkD,EAClD,iBAAoC,EACpC,QAA8B,EAC9B,SAA4B,EAC5B,MAAqB;QAErB,OAAO,eAAe;YACpB,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC/B,MAAM,CAAC,IAAI,CAAC;gBACV,QAAQ;gBACR,SAAS;gBACT,OAAO,EAAE,iBAAiB,CAAC,OAAO;gBAClC,WAAW,EAAE,iBAAiB,CAAC,WAAW;gBAC1C,GAAG,EAAE,iBAAiB,CAAC,GAAG;gBAC1B,cAAc,EAAE,iBAAiB,CAAC,cAAc;gBAChD,MAAM;aACP,CAAC,CACH;YACD,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;CACF;AA3KD,wCA2KC"}
@@ -0,0 +1,2 @@
1
+ export * from './api-fetch-client';
2
+ export * from './api-client-pagination-helper';
@@ -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("./api-fetch-client"), exports);
18
+ __exportStar(require("./api-client-pagination-helper"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,iEAA+C"}
@@ -0,0 +1,38 @@
1
+ export interface SinchClientParameters extends Partial<UnifiedCredentials>, Partial<ServicePlanIdCredentials>, Partial<ApplicationCredentials> {
2
+ }
3
+ export interface UnifiedCredentials {
4
+ /** The project ID associated with the API Client. You can find this on your [Dashboard](https://dashboard.sinch.com/account/access-keys). */
5
+ projectId: string;
6
+ /** The client ID used for authentication. You can find this on your [Dashboard](https://dashboard.sinch.com/account/access-keys). */
7
+ keyId: string;
8
+ /** The client secret used for authentication. You can find this ONLY when creating a new key. */
9
+ keySecret: string;
10
+ /** The region for the SMS API. Default region is US */
11
+ region?: Region;
12
+ }
13
+ export interface ServicePlanIdCredentials {
14
+ /** Your service plan ID. You can find this on your [Dashboard](https://dashboard.sinch.com/sms/api/rest). */
15
+ servicePlanId: string;
16
+ /** Your API token. You can find this on your [Dashboard](https://dashboard.sinch.com/sms/api/rest). */
17
+ apiToken: string;
18
+ /** boolean to force the usage of the service plan Id + API token as credentials for the SMS API*/
19
+ forceServicePlanIdUsageForSmsApi?: boolean;
20
+ /** The region for the SMS API. Default region is US */
21
+ region?: Region;
22
+ }
23
+ export interface ApplicationCredentials {
24
+ /** Your Application key. You can find this on your [Dashboard](https://dashboard.sinch.com/verification/apps)*/
25
+ applicationKey: string;
26
+ /** Your Application secret. You can find this on your [Dashboard](https://dashboard.sinch.com/verification/apps)*/
27
+ applicationSecret: string;
28
+ }
29
+ export declare const isUnifiedCredentials: (credentials: any) => credentials is UnifiedCredentials;
30
+ export declare const isServicePlanIdCredentials: (credentials: any) => credentials is ServicePlanIdCredentials;
31
+ export declare enum Region {
32
+ UNITED_STATES = "us",
33
+ EUROPE = "eu",
34
+ BRAZIL = "br",
35
+ CANADA = "ca",
36
+ AUSTRALIA = "au"
37
+ }
38
+ export declare function getRegion(value: string | undefined): Region | undefined;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRegion = exports.Region = exports.isServicePlanIdCredentials = exports.isUnifiedCredentials = void 0;
4
+ const isUnifiedCredentials = (credentials) => {
5
+ const candidate = (credentials);
6
+ return candidate.projectId !== undefined
7
+ && candidate.keyId !== undefined
8
+ && candidate.keySecret !== undefined;
9
+ };
10
+ exports.isUnifiedCredentials = isUnifiedCredentials;
11
+ const isServicePlanIdCredentials = (credentials) => {
12
+ const candidate = (credentials);
13
+ return candidate.servicePlanId !== undefined
14
+ && candidate.apiToken !== undefined;
15
+ };
16
+ exports.isServicePlanIdCredentials = isServicePlanIdCredentials;
17
+ var Region;
18
+ (function (Region) {
19
+ Region["UNITED_STATES"] = "us";
20
+ Region["EUROPE"] = "eu";
21
+ Region["BRAZIL"] = "br";
22
+ Region["CANADA"] = "ca";
23
+ Region["AUSTRALIA"] = "au";
24
+ })(Region || (exports.Region = Region = {}));
25
+ function getRegion(value) {
26
+ if (!value) {
27
+ return undefined;
28
+ }
29
+ for (const region of Object.values(Region)) {
30
+ if (region === value.toLowerCase()) {
31
+ return region;
32
+ }
33
+ }
34
+ console.error(`No region exist for the value '${value}'`);
35
+ return undefined;
36
+ }
37
+ exports.getRegion = getRegion;
38
+ //# sourceMappingURL=domain-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-interface.js","sourceRoot":"","sources":["../../src/domain/domain-interface.ts"],"names":[],"mappings":";;;AAkCO,MAAM,oBAAoB,GAAG,CAAC,WAAgB,EAAqC,EAAE;IAC1F,MAAM,SAAS,GAAG,CAAC,WAAW,CAAuB,CAAC;IACtD,OAAO,SAAS,CAAC,SAAS,KAAK,SAAS;WACnC,SAAS,CAAC,KAAK,KAAK,SAAS;WAC7B,SAAS,CAAC,SAAS,KAAK,SAAS,CAAC;AACzC,CAAC,CAAC;AALW,QAAA,oBAAoB,wBAK/B;AAEK,MAAM,0BAA0B,GAAG,CAAC,WAAgB,EAA2C,EAAE;IACtG,MAAM,SAAS,GAAG,CAAC,WAAW,CAA6B,CAAC;IAC5D,OAAO,SAAS,CAAC,aAAa,KAAK,SAAS;WACvC,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC;AACxC,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC;AAEF,IAAY,MAMX;AAND,WAAY,MAAM;IAChB,8BAAoB,CAAA;IACpB,uBAAa,CAAA;IACb,uBAAa,CAAA;IACb,uBAAa,CAAA;IACb,0BAAgB,CAAA;AAClB,CAAC,EANW,MAAM,sBAAN,MAAM,QAMjB;AAED,SAAgB,SAAS,CAAC,KAAyB;IACjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,IAAI,MAAM,KAAK,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACnC,OAAO,MAAgB,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,kCAAkC,KAAK,GAAG,CAAC,CAAC;IAC1D,OAAO,SAAS,CAAC;AACnB,CAAC;AAZD,8BAYC"}
@@ -0,0 +1 @@
1
+ export * from './domain-interface';
@@ -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("./domain-interface"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/domain/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
@@ -0,0 +1 @@
1
+ export declare const sdkCoreVersion: string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdkCoreVersion = void 0;
4
+ const package_json_1 = require("@sinch/sdk-core/package.json");
5
+ exports.sdkCoreVersion = package_json_1.version;
6
+ //# sourceMappingURL=getVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getVersion.js","sourceRoot":"","sources":["../src/getVersion.ts"],"names":[],"mappings":";;;AAAA,+DAAsE;AACzD,QAAA,cAAc,GAAG,sBAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './api';
2
+ export * from './client';
3
+ export * from './domain';
4
+ export * from './plugins';
5
+ export * from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
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"), exports);
18
+ __exportStar(require("./client"), exports);
19
+ __exportStar(require("./domain"), exports);
20
+ __exportStar(require("./plugins"), exports);
21
+ __exportStar(require("./utils"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,0CAAwB"}
@@ -0,0 +1,11 @@
1
+ import { PluginRunner, RequestOptions, RequestPlugin } from '../core';
2
+ export interface AdditionalHeaders {
3
+ headers: Promise<{
4
+ [key: string]: string;
5
+ }>;
6
+ }
7
+ export declare class AdditionalHeadersRequest implements RequestPlugin {
8
+ private readonly additionalHeaders;
9
+ constructor(additionalHeaders: AdditionalHeaders);
10
+ load(): PluginRunner<RequestOptions, RequestOptions>;
11
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdditionalHeadersRequest = void 0;
4
+ class AdditionalHeadersRequest {
5
+ constructor(additionalHeaders) {
6
+ this.additionalHeaders = additionalHeaders;
7
+ }
8
+ load() {
9
+ return {
10
+ transform: async (data) => {
11
+ const headers = await this.additionalHeaders.headers;
12
+ if (headers) {
13
+ Object.keys(headers).forEach((key) => data.headers.set(key, headers[key]));
14
+ }
15
+ return data;
16
+ },
17
+ };
18
+ }
19
+ }
20
+ exports.AdditionalHeadersRequest = AdditionalHeadersRequest;
21
+ //# sourceMappingURL=additional-headers.request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"additional-headers.request.js","sourceRoot":"","sources":["../../../src/plugins/additional-headers/additional-headers.request.ts"],"names":[],"mappings":";;;AAMA,MAAa,wBAAwB;IAGnC,YAAY,iBAAoC;QAC9C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAEM,IAAI;QACT,OAAO;YACL,SAAS,EAAE,KAAK,EAAE,IAAoB,EAAE,EAAE;gBACxC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;gBACrD,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CACnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CACpC,CAAC;gBACJ,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AApBD,4DAoBC"}
@@ -0,0 +1 @@
1
+ export * from './additional-headers.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("./additional-headers.request"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/additional-headers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C"}
@@ -0,0 +1,6 @@
1
+ import { PluginRunner, RequestOptions, RequestPlugin } from '../core';
2
+ export declare class ApiTokenRequest implements RequestPlugin {
3
+ private readonly apiToken;
4
+ constructor(apiToken: string);
5
+ load(): PluginRunner<RequestOptions, RequestOptions>;
6
+ }