@entegrasyonapp/lib 1.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 (122) hide show
  1. package/README.md +19 -0
  2. package/dist/common/client.d.ts +12 -0
  3. package/dist/common/client.d.ts.map +1 -0
  4. package/dist/common/client.js +9 -0
  5. package/dist/common/client.js.map +1 -0
  6. package/dist/common/kv-handler.d.ts +17 -0
  7. package/dist/common/kv-handler.d.ts.map +1 -0
  8. package/dist/common/kv-handler.js +24 -0
  9. package/dist/common/kv-handler.js.map +1 -0
  10. package/dist/common/request.d.ts +21 -0
  11. package/dist/common/request.d.ts.map +1 -0
  12. package/dist/common/request.js +9 -0
  13. package/dist/common/request.js.map +1 -0
  14. package/dist/index.d.ts +15 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +42 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/integrations/boyner/v1/client.d.ts +30 -0
  19. package/dist/integrations/boyner/v1/client.d.ts.map +1 -0
  20. package/dist/integrations/boyner/v1/client.js +30 -0
  21. package/dist/integrations/boyner/v1/client.js.map +1 -0
  22. package/dist/integrations/boyner/v1/index.d.ts +2 -0
  23. package/dist/integrations/boyner/v1/index.d.ts.map +1 -0
  24. package/dist/integrations/boyner/v1/index.js +6 -0
  25. package/dist/integrations/boyner/v1/index.js.map +1 -0
  26. package/dist/integrations/boyner/v1/request.d.ts +20 -0
  27. package/dist/integrations/boyner/v1/request.d.ts.map +1 -0
  28. package/dist/integrations/boyner/v1/request.js +67 -0
  29. package/dist/integrations/boyner/v1/request.js.map +1 -0
  30. package/dist/integrations/ciceksepeti/v1/client.d.ts +33 -0
  31. package/dist/integrations/ciceksepeti/v1/client.d.ts.map +1 -0
  32. package/dist/integrations/ciceksepeti/v1/client.js +39 -0
  33. package/dist/integrations/ciceksepeti/v1/client.js.map +1 -0
  34. package/dist/integrations/ciceksepeti/v1/index.d.ts +2 -0
  35. package/dist/integrations/ciceksepeti/v1/index.d.ts.map +1 -0
  36. package/dist/integrations/ciceksepeti/v1/index.js +7 -0
  37. package/dist/integrations/ciceksepeti/v1/index.js.map +1 -0
  38. package/dist/integrations/ciceksepeti/v1/request.d.ts +20 -0
  39. package/dist/integrations/ciceksepeti/v1/request.d.ts.map +1 -0
  40. package/dist/integrations/ciceksepeti/v1/request.js +63 -0
  41. package/dist/integrations/ciceksepeti/v1/request.js.map +1 -0
  42. package/dist/integrations/hepsiburada/v1/client.d.ts +42 -0
  43. package/dist/integrations/hepsiburada/v1/client.d.ts.map +1 -0
  44. package/dist/integrations/hepsiburada/v1/client.js +48 -0
  45. package/dist/integrations/hepsiburada/v1/client.js.map +1 -0
  46. package/dist/integrations/hepsiburada/v1/index.d.ts +2 -0
  47. package/dist/integrations/hepsiburada/v1/index.d.ts.map +1 -0
  48. package/dist/integrations/hepsiburada/v1/index.js +8 -0
  49. package/dist/integrations/hepsiburada/v1/index.js.map +1 -0
  50. package/dist/integrations/hepsiburada/v1/request.d.ts +20 -0
  51. package/dist/integrations/hepsiburada/v1/request.d.ts.map +1 -0
  52. package/dist/integrations/hepsiburada/v1/request.js +67 -0
  53. package/dist/integrations/hepsiburada/v1/request.js.map +1 -0
  54. package/dist/integrations/lcw/v1/client.d.ts +42 -0
  55. package/dist/integrations/lcw/v1/client.d.ts.map +1 -0
  56. package/dist/integrations/lcw/v1/client.js +42 -0
  57. package/dist/integrations/lcw/v1/client.js.map +1 -0
  58. package/dist/integrations/lcw/v1/index.d.ts +2 -0
  59. package/dist/integrations/lcw/v1/index.d.ts.map +1 -0
  60. package/dist/integrations/lcw/v1/index.js +8 -0
  61. package/dist/integrations/lcw/v1/index.js.map +1 -0
  62. package/dist/integrations/lcw/v1/request.d.ts +21 -0
  63. package/dist/integrations/lcw/v1/request.d.ts.map +1 -0
  64. package/dist/integrations/lcw/v1/request.js +97 -0
  65. package/dist/integrations/lcw/v1/request.js.map +1 -0
  66. package/dist/integrations/n11/v2/client.d.ts +29 -0
  67. package/dist/integrations/n11/v2/client.d.ts.map +1 -0
  68. package/dist/integrations/n11/v2/client.js +30 -0
  69. package/dist/integrations/n11/v2/client.js.map +1 -0
  70. package/dist/integrations/n11/v2/index.d.ts +2 -0
  71. package/dist/integrations/n11/v2/index.d.ts.map +1 -0
  72. package/dist/integrations/n11/v2/index.js +6 -0
  73. package/dist/integrations/n11/v2/index.js.map +1 -0
  74. package/dist/integrations/n11/v2/request.d.ts +20 -0
  75. package/dist/integrations/n11/v2/request.d.ts.map +1 -0
  76. package/dist/integrations/n11/v2/request.js +65 -0
  77. package/dist/integrations/n11/v2/request.js.map +1 -0
  78. package/dist/integrations/ozon/v1/client.d.ts +36 -0
  79. package/dist/integrations/ozon/v1/client.d.ts.map +1 -0
  80. package/dist/integrations/ozon/v1/client.js +38 -0
  81. package/dist/integrations/ozon/v1/client.js.map +1 -0
  82. package/dist/integrations/ozon/v1/index.d.ts +2 -0
  83. package/dist/integrations/ozon/v1/index.d.ts.map +1 -0
  84. package/dist/integrations/ozon/v1/index.js +7 -0
  85. package/dist/integrations/ozon/v1/index.js.map +1 -0
  86. package/dist/integrations/ozon/v1/request.d.ts +20 -0
  87. package/dist/integrations/ozon/v1/request.d.ts.map +1 -0
  88. package/dist/integrations/ozon/v1/request.js +65 -0
  89. package/dist/integrations/ozon/v1/request.js.map +1 -0
  90. package/dist/integrations/pttavm/v1/client.d.ts +30 -0
  91. package/dist/integrations/pttavm/v1/client.d.ts.map +1 -0
  92. package/dist/integrations/pttavm/v1/client.js +30 -0
  93. package/dist/integrations/pttavm/v1/client.js.map +1 -0
  94. package/dist/integrations/pttavm/v1/index.d.ts +2 -0
  95. package/dist/integrations/pttavm/v1/index.d.ts.map +1 -0
  96. package/dist/integrations/pttavm/v1/index.js +6 -0
  97. package/dist/integrations/pttavm/v1/index.js.map +1 -0
  98. package/dist/integrations/pttavm/v1/request.d.ts +20 -0
  99. package/dist/integrations/pttavm/v1/request.d.ts.map +1 -0
  100. package/dist/integrations/pttavm/v1/request.js +66 -0
  101. package/dist/integrations/pttavm/v1/request.js.map +1 -0
  102. package/dist/integrations/trendyol/v1/client.d.ts +35 -0
  103. package/dist/integrations/trendyol/v1/client.d.ts.map +1 -0
  104. package/dist/integrations/trendyol/v1/client.js +39 -0
  105. package/dist/integrations/trendyol/v1/client.js.map +1 -0
  106. package/dist/integrations/trendyol/v1/index.d.ts +2 -0
  107. package/dist/integrations/trendyol/v1/index.d.ts.map +1 -0
  108. package/dist/integrations/trendyol/v1/index.js +7 -0
  109. package/dist/integrations/trendyol/v1/index.js.map +1 -0
  110. package/dist/integrations/trendyol/v1/request.d.ts +20 -0
  111. package/dist/integrations/trendyol/v1/request.d.ts.map +1 -0
  112. package/dist/integrations/trendyol/v1/request.js +67 -0
  113. package/dist/integrations/trendyol/v1/request.js.map +1 -0
  114. package/dist/utils/backoff-request.d.ts +33 -0
  115. package/dist/utils/backoff-request.d.ts.map +1 -0
  116. package/dist/utils/backoff-request.js +67 -0
  117. package/dist/utils/backoff-request.js.map +1 -0
  118. package/dist/utils/request-id.d.ts +17 -0
  119. package/dist/utils/request-id.d.ts.map +1 -0
  120. package/dist/utils/request-id.js +72 -0
  121. package/dist/utils/request-id.js.map +1 -0
  122. package/package.json +45 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * Request module for Trendyol
4
+ * @package entegrasyonapp/lib
5
+ * @author Ekin Karadeniz
6
+ * @copyright 2023-2024
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Request = void 0;
13
+ const axios_1 = __importDefault(require("axios"));
14
+ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
15
+ const request_id_1 = require("../../../utils/request-id");
16
+ class Request {
17
+ client;
18
+ request;
19
+ axiosConfig;
20
+ axiosMockCallback;
21
+ constructor(client, request) {
22
+ this.client = client;
23
+ this.request = request;
24
+ if (this.request.headers == undefined) {
25
+ this.request.headers = {};
26
+ }
27
+ this.request.headers['Accept'] = this.request.headers?.['Accept'] ?? 'application/json';
28
+ this.request.headers['User-Agent'] = this.request.headers?.['User-Agent'] ?? `${this.client.params.credentials.supplierId} - Entegrasyon.app/1.0`;
29
+ if (this.request.body) {
30
+ this.request.headers['Content-Type'] = this.request.headers?.['Content-Type'] ?? 'application/json';
31
+ }
32
+ this.axiosConfig = {
33
+ baseURL: this.client.getBaseURL(),
34
+ timeout: this.client.params.options?.timeout,
35
+ proxy: this.client.params.options?.proxy,
36
+ method: this.request.method,
37
+ url: this.request.path,
38
+ params: this.request.params,
39
+ data: this.request.body,
40
+ headers: this.request.headers,
41
+ responseType: 'json',
42
+ validateStatus: (status) => {
43
+ return ![401, 403, 404].includes(status);
44
+ },
45
+ };
46
+ this.axiosConfig.auth = {
47
+ username: this.client.params.credentials.apiKey,
48
+ password: this.client.params.credentials.apiSecret
49
+ };
50
+ }
51
+ setAxiosMock(callback) {
52
+ this.axiosMockCallback = callback;
53
+ }
54
+ getRequestId() {
55
+ return (0, request_id_1.generateRequestId)(this.axiosConfig, 'trendyol-v1');
56
+ }
57
+ async send() {
58
+ // mocks will be used during the tests
59
+ if (this.axiosMockCallback != undefined) {
60
+ const mock = new axios_mock_adapter_1.default(axios_1.default);
61
+ this.axiosMockCallback(mock);
62
+ }
63
+ return (0, axios_1.default)(this.axiosConfig);
64
+ }
65
+ }
66
+ exports.Request = Request;
67
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../src/integrations/trendyol/v1/request.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,kDAAiE;AAEjE,4EAA6C;AAE7C,0DAA8D;AAE9D,MAAa,OAAO;IAII;IAAwB;IAHpC,WAAW,CAA8B;IACzC,iBAAiB,CAAY;IAErC,YAAoB,MAAc,EAAU,OAA+B;QAAvD,WAAM,GAAN,MAAM,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AAE,EAAE;gBAC/B,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7C,CAAC;SACJ,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG;YACpB,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM;YAC/C,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS;SACrD,CAAC;IACN,CAAC;IAED,YAAY,CAAC,QAAkB;QAC3B,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC;IACtC,CAAC;IAED,YAAY;QACR,OAAO,IAAA,8BAAiB,EAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,IAAI;QAEN,sCAAsC;QACtC,IAAI,IAAI,CAAC,iBAAiB,IAAI,SAAS,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,IAAI,4BAAW,CAAC,eAAK,CAAC,CAAC;YACpC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,IAAA,eAAK,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;CACJ;AArDD,0BAqDC","sourcesContent":["/**\n * Request module for Trendyol\n * @package entegrasyonapp/lib\n * @author Ekin Karadeniz\n * @copyright 2023-2024\n */\n\nimport axios, { AxiosRequestConfig, AxiosResponse } from \"axios\";\nimport { Client } from \"./client\";\nimport MockAdapter from \"axios-mock-adapter\";\nimport { IRequest, IRequestInput } from \"./../../../common/request\";\nimport { generateRequestId } from \"../../../utils/request-id\";\n\nexport class Request implements IRequest {\n private axiosConfig: Partial<AxiosRequestConfig>;\n private axiosMockCallback?: Function;\n\n constructor(private client: Client, private request: Partial<IRequestInput>) {\n if (this.request.headers == undefined) {\n this.request.headers = {};\n }\n this.request.headers['Accept'] = this.request.headers?.['Accept'] ?? 'application/json';\n this.request.headers['User-Agent'] = this.request.headers?.['User-Agent'] ?? `${this.client.params.credentials.supplierId} - Entegrasyon.app/1.0`;\n if (this.request.body) {\n this.request.headers['Content-Type'] = this.request.headers?.['Content-Type'] ?? 'application/json';\n }\n\n this.axiosConfig = {\n baseURL: this.client.getBaseURL(),\n timeout: this.client.params.options?.timeout,\n proxy: this.client.params.options?.proxy,\n method: this.request.method,\n url: this.request.path,\n params: this.request.params,\n data: this.request.body,\n headers: this.request.headers,\n responseType: 'json',\n validateStatus: (status: number) => {\n return ![401, 403, 404].includes(status);\n },\n };\n\n this.axiosConfig.auth = {\n username: this.client.params.credentials.apiKey,\n password: this.client.params.credentials.apiSecret\n };\n }\n\n setAxiosMock(callback: Function) {\n this.axiosMockCallback = callback;\n }\n\n getRequestId(): string {\n return generateRequestId(this.axiosConfig, 'trendyol-v1');\n }\n\n async send(): Promise<AxiosResponse> {\n\n // mocks will be used during the tests\n if (this.axiosMockCallback != undefined) {\n const mock = new MockAdapter(axios);\n this.axiosMockCallback(mock);\n }\n\n return axios(this.axiosConfig);\n }\n}"]}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Backoff request util
3
+ * @package entegrasyonapp/lib
4
+ * @author Ekin Karadeniz
5
+ * @copyright 2023-2024
6
+ */
7
+ import { AxiosResponse } from "axios";
8
+ import { IRequest } from "../common/request";
9
+ /**
10
+ * @param maxTry number - Maximum number of requests to be repeated (0 means no limit, 6 is default)
11
+ * @param delay number - Exponential time in milliseconds to wait before requests are sent (1000 is default)
12
+ * @param resolveHandler Function - The handler function to be used to resolve the Promise
13
+ * @param rejectHandler? Function - The handler function to be used to reject the Promise (optional)
14
+ * @param delayFilter? Function - The filter function to be used to manipulate the delay value (optional)
15
+ * @param throwErrors boolean - It throws an error exception; otherwise, it will repeat the request (false is default)
16
+ */
17
+ export interface IBackoffRequestOptions {
18
+ maxTry: number;
19
+ delay: number;
20
+ resolveHandler: (response: AxiosResponse) => boolean;
21
+ rejectHandler?: (response: AxiosResponse) => boolean;
22
+ delayFilter?: (delay: number, attempts: number) => number;
23
+ throwErrors: boolean;
24
+ }
25
+ export declare const defaultBackoffRequestOptions: IBackoffRequestOptions;
26
+ /**
27
+ * This implements the "back-off" request. More at: https://en.wikipedia.org/wiki/Exponential_backoff
28
+ * @param request IRequest
29
+ * @param customOptions IBackoffRequestOptions
30
+ * @returns Promise<AxiosResponse>
31
+ */
32
+ export declare function backoffRequest(request: IRequest, customOptions?: Partial<IBackoffRequestOptions>): Promise<AxiosResponse>;
33
+ //# sourceMappingURL=backoff-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff-request.d.ts","sourceRoot":"","sources":["../../src/utils/backoff-request.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,CAAC;IACrD,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,CAAC;IACrD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1D,WAAW,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,4BAA4B,EAAE,sBAO1C,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAqD/H"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * Backoff request util
4
+ * @package entegrasyonapp/lib
5
+ * @author Ekin Karadeniz
6
+ * @copyright 2023-2024
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.defaultBackoffRequestOptions = void 0;
10
+ exports.backoffRequest = backoffRequest;
11
+ exports.defaultBackoffRequestOptions = {
12
+ maxTry: 6,
13
+ delay: 1000,
14
+ resolveHandler: (response) => {
15
+ return (response.status == 200 && response.data != undefined);
16
+ },
17
+ throwErrors: false,
18
+ };
19
+ /**
20
+ * This implements the "back-off" request. More at: https://en.wikipedia.org/wiki/Exponential_backoff
21
+ * @param request IRequest
22
+ * @param customOptions IBackoffRequestOptions
23
+ * @returns Promise<AxiosResponse>
24
+ */
25
+ async function backoffRequest(request, customOptions) {
26
+ const options = { ...exports.defaultBackoffRequestOptions, ...customOptions };
27
+ return new Promise(async (resolve, reject) => {
28
+ let attempts = 0;
29
+ const handler = async () => {
30
+ if (options.delayFilter !== undefined) {
31
+ options.delay = options.delayFilter(options.delay, attempts);
32
+ }
33
+ try {
34
+ // Send the request and return the response.
35
+ const response = await request.send();
36
+ // Request is validated: resolve the Promise.
37
+ if (options.resolveHandler(response)) {
38
+ return resolve(response);
39
+ }
40
+ // Reject handler matched and reject the Promise.
41
+ else if (options.rejectHandler != undefined && options.rejectHandler(response)) {
42
+ return reject(response);
43
+ }
44
+ // Request is not validated: repeat the request.
45
+ else {
46
+ attempts++;
47
+ if (options.maxTry > 0 && attempts >= options.maxTry) {
48
+ return reject(response);
49
+ }
50
+ setTimeout(handler, attempts * options.delay);
51
+ }
52
+ }
53
+ catch (err) {
54
+ if (options.throwErrors) {
55
+ throw err;
56
+ }
57
+ attempts++;
58
+ if (options.maxTry > 0 && attempts >= options.maxTry) {
59
+ return reject(err);
60
+ }
61
+ setTimeout(handler, attempts * options.delay);
62
+ }
63
+ };
64
+ handler();
65
+ });
66
+ }
67
+ //# sourceMappingURL=backoff-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff-request.js","sourceRoot":"","sources":["../../src/utils/back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,EAAE,CAAC;oBACX,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;wBACnD,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;oBAC5B,CAAC;oBACD,UAAU,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;gBAClD,CAAC;YAEL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;oBACtB,MAAM,GAAG,CAAC;gBACd,CAAC;gBAED,QAAQ,EAAE,CAAC;gBACX,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;oBACnD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,CAAC;gBACD,UAAU,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;YAClD,CAAC;QAEL,CAAC,CAAC;QAEF,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["/**\n * Backoff request util\n * @package entegrasyonapp/lib\n * @author Ekin Karadeniz\n * @copyright 2023-2024\n */\n\nimport { AxiosResponse } from \"axios\";\nimport { IRequest } from \"../common/request\";\n\n/**\n * @param maxTry number - Maximum number of requests to be repeated (0 means no limit, 6 is default)\n * @param delay number - Exponential time in milliseconds to wait before requests are sent (1000 is default)\n * @param resolveHandler Function - The handler function to be used to resolve the Promise\n * @param rejectHandler? Function - The handler function to be used to reject the Promise (optional)\n * @param delayFilter? Function - The filter function to be used to manipulate the delay value (optional)\n * @param throwErrors boolean - It throws an error exception; otherwise, it will repeat the request (false is default)\n */\nexport interface IBackoffRequestOptions {\n maxTry: number;\n delay: number;\n resolveHandler: (response: AxiosResponse) => boolean;\n rejectHandler?: (response: AxiosResponse) => boolean;\n delayFilter?: (delay: number, attempts: number) => number;\n throwErrors: boolean;\n}\n\nexport const defaultBackoffRequestOptions: IBackoffRequestOptions = {\n maxTry: 6,\n delay: 1000,\n resolveHandler: (response: AxiosResponse): boolean => {\n return (response.status == 200 && response.data != undefined);\n },\n throwErrors: false,\n}\n\n/**\n * This implements the \"back-off\" request. More at: https://en.wikipedia.org/wiki/Exponential_backoff\n * @param request IRequest\n * @param customOptions IBackoffRequestOptions\n * @returns Promise<AxiosResponse>\n */\nexport async function backoffRequest(request: IRequest, customOptions?: Partial<IBackoffRequestOptions>): Promise<AxiosResponse> {\n\n const options = { ...defaultBackoffRequestOptions, ...customOptions };\n\n return new Promise(async (resolve, reject) => {\n\n let attempts = 0;\n\n const handler = async () => {\n\n if (options.delayFilter !== undefined) {\n options.delay = options.delayFilter(options.delay, attempts);\n }\n\n try {\n // Send the request and return the response.\n const response = await request.send();\n\n // Request is validated: resolve the Promise.\n if (options.resolveHandler(response)) {\n return resolve(response);\n }\n\n // Reject handler matched and reject the Promise. \n else if (options.rejectHandler != undefined && options.rejectHandler(response)) {\n return reject(response);\n }\n\n // Request is not validated: repeat the request.\n else {\n attempts++;\n if (options.maxTry > 0 && attempts >= options.maxTry) {\n return reject(response);\n }\n setTimeout(handler, attempts * options.delay);\n }\n\n } catch (err) {\n if (options.throwErrors) {\n throw err;\n }\n\n attempts++;\n if (options.maxTry > 0 && attempts >= options.maxTry) {\n return reject(err);\n }\n setTimeout(handler, attempts * options.delay);\n }\n\n };\n\n handler();\n });\n}\n"]}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Request ID util
3
+ * @package entegrasyonapp/lib
4
+ * @author Ekin Karadeniz
5
+ * @copyright 2023-2024
6
+ */
7
+ import { AxiosRequestConfig } from "axios";
8
+ /**
9
+ * Creates a unique request ID using the axiosConfig parameters. The request ID depends on the base URL, method,
10
+ * path, query parameters, headers, authentication credentials, the body of the request and the user specified salt.
11
+ * All of these values are separated by double greater-than characters (>>) and hashed with SHA1 in HEX format.
12
+ *
13
+ * @param axiosConfig AxiosRequestConfig
14
+ * @returns string
15
+ */
16
+ export declare function generateRequestId(axiosConfig: AxiosRequestConfig, salt?: any): string;
17
+ //# sourceMappingURL=request-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-id.d.ts","sourceRoot":"","sources":["../../src/utils/request-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAG3C;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,kBAAkB,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM,CAsDrF"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * Request ID util
4
+ * @package entegrasyonapp/lib
5
+ * @author Ekin Karadeniz
6
+ * @copyright 2023-2024
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.generateRequestId = generateRequestId;
10
+ const crypto_1 = require("crypto");
11
+ /**
12
+ * Creates a unique request ID using the axiosConfig parameters. The request ID depends on the base URL, method,
13
+ * path, query parameters, headers, authentication credentials, the body of the request and the user specified salt.
14
+ * All of these values are separated by double greater-than characters (>>) and hashed with SHA1 in HEX format.
15
+ *
16
+ * @param axiosConfig AxiosRequestConfig
17
+ * @returns string
18
+ */
19
+ function generateRequestId(axiosConfig, salt) {
20
+ const sha1 = (0, crypto_1.createHash)('sha1');
21
+ if (!axiosConfig.baseURL && !axiosConfig.url) {
22
+ throw new Error('Request ID cannot be created: request URL is empty.');
23
+ }
24
+ let payload = '';
25
+ if (axiosConfig.baseURL) {
26
+ payload += '>>' + axiosConfig.baseURL;
27
+ }
28
+ if (axiosConfig.method) {
29
+ payload += '>>' + axiosConfig.method;
30
+ }
31
+ if (axiosConfig.url) {
32
+ payload += '>>' + axiosConfig.url;
33
+ }
34
+ if (axiosConfig.params) {
35
+ payload += '>>';
36
+ if (typeof axiosConfig.params == 'string') {
37
+ payload += axiosConfig.params;
38
+ }
39
+ else {
40
+ payload += JSON.stringify(axiosConfig.params);
41
+ }
42
+ }
43
+ if (axiosConfig.headers) {
44
+ payload += '>>';
45
+ payload += JSON.stringify(axiosConfig.headers);
46
+ }
47
+ if (axiosConfig.auth) {
48
+ payload += '>>';
49
+ payload += JSON.stringify(axiosConfig.auth);
50
+ }
51
+ if (axiosConfig.data) {
52
+ payload += '>>';
53
+ if (typeof axiosConfig.data == 'string') {
54
+ payload += axiosConfig.data;
55
+ }
56
+ else {
57
+ payload += JSON.stringify(axiosConfig.data);
58
+ }
59
+ }
60
+ if (salt) {
61
+ payload += '>>';
62
+ if (typeof salt == 'string') {
63
+ payload += salt;
64
+ }
65
+ else {
66
+ payload += JSON.stringify(salt);
67
+ }
68
+ }
69
+ sha1.update(payload);
70
+ return sha1.digest('hex');
71
+ }
72
+ //# sourceMappingURL=request-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-id.js","sourceRoot":"","sources":["../../src/utils/request-id.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAaH,8CAsDC;AAhED,mCAAoC;AAEpC;;;;;;;GAOG;AACH,SAAgB,iBAAiB,CAAC,WAA+B,EAAE,IAAU;IACzE,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,MAAM,CAAC,CAAC;IAEhC,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;IAC1E,CAAC;IAED,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;QACtB,OAAO,IAAI,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC;IAC1C,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;QACrB,OAAO,IAAI,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC;IACzC,CAAC;IACD,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC;QAClB,O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AAO,CAAC,CAAC;IAErB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Request ID util\n * @package entegrasyonapp/lib\n * @author Ekin Karadeniz\n * @copyright 2023-2024\n */\n\nimport { AxiosRequestConfig } from \"axios\";\nimport { createHash } from \"crypto\";\n\n/**\n * Creates a unique request ID using the axiosConfig parameters. The request ID depends on the base URL, method, \n * path, query parameters, headers, authentication credentials, the body of the request and the user specified salt. \n * All of these values are separated by double greater-than characters (>>) and hashed with SHA1 in HEX format.\n * \n * @param axiosConfig AxiosRequestConfig\n * @returns string\n */\nexport function generateRequestId(axiosConfig: AxiosRequestConfig, salt?: any): string {\n const sha1 = createHash('sha1');\n\n if (!axiosConfig.baseURL && !axiosConfig.url) {\n throw new Error('Request ID cannot be created: request URL is empty.')\n }\n\n let payload = '';\n\n if (axiosConfig.baseURL) {\n payload += '>>' + axiosConfig.baseURL;\n }\n if (axiosConfig.method) {\n payload += '>>' + axiosConfig.method;\n }\n if (axiosConfig.url) {\n payload += '>>' + axiosConfig.url;\n }\n if (axiosConfig.params) {\n payload += '>>';\n if (typeof axiosConfig.params == 'string') {\n payload += axiosConfig.params;\n } else {\n payload += JSON.stringify(axiosConfig.params);\n }\n }\n if (axiosConfig.headers) {\n payload += '>>';\n payload += JSON.stringify(axiosConfig.headers);\n }\n if (axiosConfig.auth) {\n payload += '>>';\n payload += JSON.stringify(axiosConfig.auth);\n }\n if (axiosConfig.data) {\n payload += '>>';\n if (typeof axiosConfig.data == 'string') {\n payload += axiosConfig.data;\n } else {\n payload += JSON.stringify(axiosConfig.data);\n }\n }\n if (salt) {\n payload += '>>';\n if (typeof salt == 'string') {\n payload += salt;\n } else {\n payload += JSON.stringify(salt);\n }\n }\n\n sha1.update(payload);\n\n return sha1.digest('hex');\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@entegrasyonapp/lib",
3
+ "version": "1.0.0",
4
+ "description": "Entegrasyon.app libraries.",
5
+ "scripts": {
6
+ "clean": "rimraf ./dist && rimraf *.tsbuildinfo",
7
+ "build": "$npm_execpath run clean && tsc",
8
+ "test": "jest",
9
+ "prepare": "$npm_execpath run build"
10
+ },
11
+ "main": "./dist/index.js",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+ssh://git@github.com/entegrasyonapp/lib.git"
21
+ },
22
+ "author": "Ekin Karadeniz <iamdual@icloud.com> (https://github.com/iamdual)",
23
+ "engines": {
24
+ "node": ">= 20"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/entegrasyonapp/lib/issues"
28
+ },
29
+ "homepage": "https://github.com/entegrasyonapp/lib",
30
+ "devDependencies": {
31
+ "@types/jest": "^29.5.11",
32
+ "@types/node": "^20.11.0",
33
+ "jest": "^29.7.0",
34
+ "rimraf": "^5.0.5",
35
+ "ts-jest": "^29.1.1",
36
+ "ts-node": "^10.9.2",
37
+ "typescript": "^5.4.3"
38
+ },
39
+ "dependencies": {
40
+ "axios": "^1.6.8",
41
+ "axios-mock-adapter": "^1.22.0"
42
+ },
43
+ "packageManager": "yarn@3.8.5+sha512.786c27300bc8fb134a1a0630db71cfeccc2b92272c031df17ff662876e89c2df488e6819dd7f2ffaf02e021b6827f75d3eb6a6df0a10218f72a589b735db6cc2",
44
+ "types": "./dist/index.d.ts"
45
+ }