@or-sdk/contacts 4.5.22 → 4.6.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 (48) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/Contacts.js +2 -2
  3. package/dist/cjs/Contacts.js.map +1 -1
  4. package/dist/cjs/__tests__/contacts-error-handling.spec.js +50 -37
  5. package/dist/cjs/__tests__/contacts-error-handling.spec.js.map +1 -1
  6. package/dist/cjs/__tests__/db-mismatch-callback.spec.js +2 -2
  7. package/dist/cjs/__tests__/db-mismatch-callback.spec.js.map +1 -1
  8. package/dist/cjs/__tests__/poll-migration.spec.js +7 -16
  9. package/dist/cjs/__tests__/poll-migration.spec.js.map +1 -1
  10. package/dist/cjs/api/baseWithPolingApi.js +2 -2
  11. package/dist/cjs/api/baseWithPolingApi.js.map +1 -1
  12. package/dist/cjs/api/migrationsApi.js +4 -3
  13. package/dist/cjs/api/migrationsApi.js.map +1 -1
  14. package/dist/cjs/apiError.js +18 -6
  15. package/dist/cjs/apiError.js.map +1 -1
  16. package/dist/cjs/utils.js +4 -3
  17. package/dist/cjs/utils.js.map +1 -1
  18. package/dist/esm/Contacts.js +2 -2
  19. package/dist/esm/Contacts.js.map +1 -1
  20. package/dist/esm/__tests__/contacts-error-handling.spec.js +33 -37
  21. package/dist/esm/__tests__/contacts-error-handling.spec.js.map +1 -1
  22. package/dist/esm/__tests__/db-mismatch-callback.spec.js +3 -3
  23. package/dist/esm/__tests__/db-mismatch-callback.spec.js.map +1 -1
  24. package/dist/esm/__tests__/poll-migration.spec.js +8 -17
  25. package/dist/esm/__tests__/poll-migration.spec.js.map +1 -1
  26. package/dist/esm/api/baseWithPolingApi.js +3 -3
  27. package/dist/esm/api/baseWithPolingApi.js.map +1 -1
  28. package/dist/esm/api/migrationsApi.js +2 -2
  29. package/dist/esm/api/migrationsApi.js.map +1 -1
  30. package/dist/esm/apiError.js +7 -6
  31. package/dist/esm/apiError.js.map +1 -1
  32. package/dist/esm/utils.js +4 -3
  33. package/dist/esm/utils.js.map +1 -1
  34. package/dist/types/api/migrationsApi.d.ts +3 -1
  35. package/dist/types/api/migrationsApi.d.ts.map +1 -1
  36. package/dist/types/apiError.d.ts +6 -5
  37. package/dist/types/apiError.d.ts.map +1 -1
  38. package/dist/types/utils.d.ts.map +1 -1
  39. package/package.json +12 -14
  40. package/src/Contacts.ts +2 -2
  41. package/src/__tests__/contacts-error-handling.spec.ts +35 -39
  42. package/src/__tests__/db-mismatch-callback.spec.ts +3 -3
  43. package/src/__tests__/poll-migration.spec.ts +30 -22
  44. package/src/api/baseWithPolingApi.ts +2 -2
  45. package/src/api/migrationsApi.ts +6 -2
  46. package/src/apiError.ts +13 -6
  47. package/src/utils.ts +8 -9
  48. package/{vitest.config.js → vitest.config.mjs} +1 -1
@@ -8,40 +8,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { MigrationState } from '@onereach/types-contacts-api';
11
- import { rest } from 'msw';
11
+ import { http, HttpResponse } from 'msw';
12
12
  import { setupServer } from 'msw/node';
13
13
  import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
14
14
  import { Contacts } from '../Contacts';
15
- let getMigrationStatusCounter = 0;
16
- let skipMigrationStatusCounterCheck = false;
17
- const server = setupServer(rest.get('https://em.url/migrations/v2/status', (_, res, ctx) => {
18
- if (!skipMigrationStatusCounterCheck && getMigrationStatusCounter > 1) {
19
- return res(ctx.json(MigrationState.Done));
20
- }
21
- getMigrationStatusCounter += 1;
22
- return res(ctx.json(MigrationState.InProgress));
23
- }), rest.get('https://em.url/migrations/launch', (_, res, ctx) => {
24
- return res(ctx.status(201));
25
- }));
15
+ const server = setupServer(http.get('https://contacts.url/migrations/launch', () => new HttpResponse(null, { status: 201 })));
26
16
  const buildContactsInstance = () => {
27
17
  return new Contacts({
28
18
  token: 'test-token',
29
- contactsApiUrl: 'https://em.url',
19
+ contactsApiUrl: 'https://contacts.url',
30
20
  });
31
21
  };
32
22
  describe('ContactsApi error handling', () => {
33
- beforeAll(() => server.listen());
23
+ beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
34
24
  afterEach(() => server.resetHandlers());
35
25
  afterAll(() => server.close());
36
26
  it('pollMigrationUntilDone returns true when migration is Done', () => __awaiter(void 0, void 0, void 0, function* () {
27
+ server.use(http.get('https://contacts.url/migrations/v2/status', () => HttpResponse.json(MigrationState.InProgress), { once: true }), http.get('https://contacts.url/migrations/v2/status', () => HttpResponse.json(MigrationState.Done)));
37
28
  const api = buildContactsInstance();
38
- const res = yield api.migrationsApi.pollMigrationUntilDone(900000, 500);
29
+ const res = yield api.migrationsApi.pollMigrationUntilDone(900000, 50, { debounceTimeout: 60 });
39
30
  expect(res).toBeTruthy();
40
31
  }));
41
32
  it('pollMigrationUntilDone returns false when timeout exceeds', () => __awaiter(void 0, void 0, void 0, function* () {
42
- skipMigrationStatusCounterCheck = true;
33
+ server.use(http.get('https://contacts.url/migrations/v2/status', () => HttpResponse.json(MigrationState.InProgress), { once: true }), http.get('https://contacts.url/migrations/v2/status', () => HttpResponse.json(MigrationState.Done)));
43
34
  const api = buildContactsInstance();
44
- const res = yield api.migrationsApi.pollMigrationUntilDone(500);
35
+ const res = yield api.migrationsApi.pollMigrationUntilDone(50, 100, { debounceTimeout: 60 });
45
36
  expect(res).toBeFalsy();
46
37
  }));
47
38
  });
@@ -1 +1 @@
1
- {"version":3,"file":"poll-migration.spec.js","sourceRoot":"","sources":["../../../src/__tests__/poll-migration.spec.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE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G,CACN,2CAA2C,EAC3C,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAC7C,CACF,CAAC;QAEF,MAAM,GAAG,GAAG,qBAAqB,EAAE,CAAC;QACpC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,sBAAsB,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7F,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { BatchProcessStatus } from '@onereach/types-contacts-api';
11
- import { CreateContactsBatchError } from '../apiError';
11
+ import { ApiError, CreateContactsBatchError } from '../apiError';
12
12
  import { FAILED_REQUEST_REPEATS, BULK_POLING_PAUSE_DURATION } from '../constants';
13
13
  import { debouncePromise } from '../utils';
14
14
  import { BaseApi } from './baseApi';
@@ -30,8 +30,8 @@ export default class BaseWithPoling extends BaseApi {
30
30
  }
31
31
  catch (e) {
32
32
  if (repeats < FAILED_REQUEST_REPEATS
33
- && 'statusCode' in e
34
- && e.statusCode === 'ERR_BAD_REQUEST') {
33
+ && e instanceof ApiError
34
+ && e.statusCode === 400) {
35
35
  (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(batchId, ' NOT FOUND IN POLING');
36
36
  return yield debouncePromise(() => __awaiter(this, void 0, void 0, function* () {
37
37
  const result = yield this.polling(batchId, polingDuration, repeats + 1);
@@ -1 +1 @@
1
- {"version":3,"file":"baseWithPolingApi.js","sourceRoot":"","sources":["../../../src/api/baseWithPolingApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAA2B,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAG3F,OAAO,EAAY,wBAAwB,EAAE,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,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC;gBACvC,CAAC,CAAC,YAAY,CAAC;QACnB,CAAC;KAAA;CACF"}
@@ -38,7 +38,7 @@ export default class MigrationsApi extends BaseApi {
38
38
  });
39
39
  }
40
40
  pollMigrationUntilDone() {
41
- return __awaiter(this, arguments, void 0, function* (timeoutMs = 900000, stepMs = 1000) {
41
+ return __awaiter(this, arguments, void 0, function* (timeoutMs = 900000, stepMs = 1000, { debounceTimeout } = {}) {
42
42
  const poll = (timeout) => __awaiter(this, void 0, void 0, function* () {
43
43
  if (timeout <= 0) {
44
44
  return false;
@@ -53,7 +53,7 @@ export default class MigrationsApi extends BaseApi {
53
53
  return debouncePromise(() => poll(timeout - stepMs), stepMs);
54
54
  });
55
55
  this.launchMigration();
56
- return debouncePromise(() => poll(timeoutMs), 3000);
56
+ return debouncePromise(() => poll(timeoutMs), debounceTimeout !== null && debounceTimeout !== void 0 ? debounceTimeout : 3000);
57
57
  });
58
58
  }
59
59
  listMigrations() {
@@ -1 +1 @@
1
- {"version":3,"file":"migrationsApi.js","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAA4B,MAAM,8BAA8B,CAAC;AAExF,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAMhD,gBAAgB;QACd,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,mBAAmB;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,sBAAsB;SAC9B,CAAC,CAAC;IACL,CAAC;IAMD,aAAa;QACX,OAAO,IAAI,CAAC,OAAO,CA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KAAK,KAAK,cAAc,CAAC,IAAI,IAAI,KAAK,KAAK,cAAc,CAAC,UAAU,EAAE,CAAC;oBACzE,IAAI,CAAC,eAAe,EAAE,CAAC;gBACzB,CAAC;gBAED,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;YAE/D,CAAC,CAAA,CAAC;YACF,IAAI,CAAC,eAAe,EAAE,CAAC;YACvB,OAAO,eAAe,CACpB,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EACrB,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,IAAI,CACxB,CAAC;QACJ,CAAC;KAAA;IAEK,cAAc;;YAClB,OAAO,IAAI,CAAC,OAAO,CAAC;gBAClB,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,aAAa;aACrB,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,sBAAsB;;YAC1B,OAAO,IAAI,CAAC,OAAO,CAAC;gBAClB,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,oBAAoB;aAC5B,CAAC,CAAC;QACL,CAAC;KAAA;CACF"}
@@ -1,14 +1,15 @@
1
- export class ApiError extends Error {
2
- constructor(statusCode, message, stack, translationKey) {
3
- super(message);
1
+ import { ApiError as BaseApiError } from '@or-sdk/base';
2
+ export class ApiError extends BaseApiError {
3
+ constructor(statusCode, message, stack, translationKey, options) {
4
+ super(message, Object.assign({ statusCode }, options));
4
5
  this.statusCode = statusCode;
5
6
  this.stack = stack;
6
7
  this.translationKey = translationKey;
7
8
  }
8
9
  }
9
- export class CreateContactsBatchError extends Error {
10
- constructor(message, failedBatchId, batchMessages, processedBatchIds) {
11
- super(message);
10
+ export class CreateContactsBatchError extends BaseApiError {
11
+ constructor(message, failedBatchId, batchMessages, processedBatchIds, options) {
12
+ super(message, Object.assign({}, options));
12
13
  this.failedBatchId = failedBatchId;
13
14
  this.batchMessages = batchMessages;
14
15
  this.processedBatchIds = processedBatchIds;
@@ -1 +1 @@
1
- {"version":3,"file":"apiError.js","sourceRoot":"","sources":["../../src/apiError.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,YACkB,UAAe,EAC/B,OAAe,EACC,KAAc,EACd,cAAuB;QAEvC,KAAK,CAAC,OAAO,CAAC,CAAC;QALC,eAAU,GAAV,UAAU,CAAK;QAEf,UAAK,GAAL,KAAK,CAAS;QACd,mBAAc,GAAd,cAAc,CAAS;IAGzC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YACE,OAAe,EACC,aAAqB,EACrB,aAAwB,EACjC,iBAA4B;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,kBAAa,GAAb,aAAa,CAAQ;QACrB,kBAAa,GAAb,aAAa,CAAW;QACjC,sBAAiB,GAAjB,iBAAiB,CAAW;IAGrC,CAAC;CACF"}
1
+ {"version":3,"file":"apiError.js","sourceRoot":"","sources":["../../src/apiError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,QAAQ,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAKzE,MAAM,OAAO,QAAS,SAAQ,YAAY;IACxC,YACkB,UAAkB,EAClC,OAAe,EACC,KAAc,EACd,cAAuB,EACvC,OAAyB;QAEzB,KAAK,CAAC,OAAO,kBACX,UAAU,IACP,OAAO,EACV,CAAC;QATa,eAAU,GAAV,UAAU,CAAQ;QAElB,UAAK,GAAL,KAAK,CAAS;QACd,mBAAc,GAAd,cAAc,CAAS;IAOzC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,YAAY;IACxD,YACE,OAAe,EACC,aAAqB,EACrB,aAAwB,EACjC,iBAA4B,EACnC,OAAyB;QAEzB,KAAK,CAAC,OAAO,oBAAO,OAAO,EAAG,CAAC;QALf,kBAAa,GAAb,aAAa,CAAQ;QACrB,kBAAa,GAAb,aAAa,CAAW;QACjC,sBAAiB,GAAjB,iBAAiB,CAAW;IAIrC,CAAC;CACF"}
package/dist/esm/utils.js CHANGED
@@ -48,10 +48,11 @@ export const chunkArrByMaxSize = (arr, maxSize) => {
48
48
  export function debouncePromise(caller, delay) {
49
49
  let timeout = null;
50
50
  return new Promise((res, rej) => {
51
- if (timeout) {
51
+ if (timeout)
52
52
  clearTimeout(timeout);
53
- }
54
- timeout = setTimeout(() => caller().then((x) => res(x)).catch((err) => rej(err)), delay);
53
+ timeout = setTimeout(() => Promise.resolve(caller())
54
+ .then((x) => res(x))
55
+ .catch((err) => rej(err)), delay);
55
56
  });
56
57
  }
57
58
  export const mergeObjects = (first, second) => {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,CAAU,CAAC;AAItF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,MAAS,EAC0C,EAAE;IACrD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAa,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QAClE,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAoC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAEzE,GAAW,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAgB,CAAC,CAAC;IAErB,mEACK,SAAS,GACT,CACD,CAAC,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,cAAc,CAAC;QAC/C,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,cAAc,EAAE,EAAE,CAC9D,GACE,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,GACtC,CAAC,MAAM,C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AAE,CAAC,CAAC,CAAC;IAC1E,IAAI,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,UAAU,eAAe,CAC7B,MAAwB,EACxB,KAAa;IAEb,IAAI,OAAO,GAA0B,IAAI,CAAC;IAE1C,OAAO,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACjC,IAAI,OAAO;YAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,GAAG,UAAU,CAClB,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;aAC5B,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACnB,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAC3B,KAAK,CACN,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA6B,EAAE,MAA8B,EAA0B,EAAE;IACpH,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -5,7 +5,9 @@ export default class MigrationsApi extends BaseApi {
5
5
  getMigrationState(): Promise<MigrationState>;
6
6
  migrationsRun(): Promise<void>;
7
7
  launchMigration(): Promise<void>;
8
- pollMigrationUntilDone(timeoutMs?: number, stepMs?: number): Promise<boolean>;
8
+ pollMigrationUntilDone(timeoutMs?: number, stepMs?: number, { debounceTimeout }?: {
9
+ debounceTimeout?: number;
10
+ }): Promise<boolean>;
9
11
  listMigrations(): Promise<MigrationListResponseDto[]>;
10
12
  dropMigrationLockTable(): Promise<void>;
11
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"migrationsApi.d.ts","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAIxF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAMhD,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAOpC,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAW5C,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAahC,sBAAsB,CAAC,SAAS,SAAS,EAAE,MAAM,SAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAuB3E,cAAc,IAAI,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAOrD,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAM9C"}
1
+ {"version":3,"file":"migrationsApi.d.ts","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAIxF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,OAAO;IAMhD,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAOpC,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAW5C,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAahC,sBAAsB,CAC1B,SAAS,SAAS,EAClB,MAAM,SAAO,EACb,EAAE,eAAe,EAAE,GAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAC;KAAO,GACtD,OAAO,CAAC,OAAO,CAAC;IAuBb,cAAc,IAAI,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAOrD,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAM9C"}
@@ -1,13 +1,14 @@
1
- export declare class ApiError extends Error {
2
- readonly statusCode: any;
1
+ import { ApiErrorOptions, ApiError as BaseApiError } from '@or-sdk/base';
2
+ export declare class ApiError extends BaseApiError {
3
+ readonly statusCode: number;
3
4
  readonly stack?: string | undefined;
4
5
  readonly translationKey?: string | undefined;
5
- constructor(statusCode: any, message: string, stack?: string | undefined, translationKey?: string | undefined);
6
+ constructor(statusCode: number, message: string, stack?: string | undefined, translationKey?: string | undefined, options?: ApiErrorOptions);
6
7
  }
7
- export declare class CreateContactsBatchError extends Error {
8
+ export declare class CreateContactsBatchError extends BaseApiError {
8
9
  readonly failedBatchId: string;
9
10
  readonly batchMessages?: string[] | undefined;
10
11
  processedBatchIds?: string[] | undefined;
11
- constructor(message: string, failedBatchId: string, batchMessages?: string[] | undefined, processedBatchIds?: string[] | undefined);
12
+ constructor(message: string, failedBatchId: string, batchMessages?: string[] | undefined, processedBatchIds?: string[] | undefined, options?: ApiErrorOptions);
12
13
  }
13
14
  //# sourceMappingURL=apiError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiError.d.ts","sourceRoot":"","sources":["../../src/apiError.ts"],"names":[],"mappings":"AAGA,qBAAa,QAAS,SAAQ,KAAK;aAEf,UAAU,EAAE,GAAG;aAEf,KAAK,CAAC,EAAE,MAAM;aACd,cAAc,CAAC,EAAE,MAAM;gBAHvB,UAAU,EAAE,GAAG,EAC/B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,MAAM,YAAA,EACd,cAAc,CAAC,EAAE,MAAM,YAAA;CAI1C;AAED,qBAAa,wBAAyB,SAAQ,KAAK;aAG/B,aAAa,EAAE,MAAM;aACrB,aAAa,CAAC,EAAE,MAAM,EAAE;IACjC,iBAAiB,CAAC,EAAE,MAAM,EAAE;gBAHnC,OAAO,EAAE,MAAM,EACC,aAAa,EAAE,MAAM,EACrB,aAAa,CAAC,EAAE,MAAM,EAAE,YAAA,EACjC,iBAAiB,CAAC,EAAE,MAAM,EAAE,YAAA;CAItC"}
1
+ {"version":3,"file":"apiError.d.ts","sourceRoot":"","sources":["../../src/apiError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AAKzE,qBAAa,QAAS,SAAQ,YAAY;aAEtB,UAAU,EAAE,MAAM;aAElB,KAAK,CAAC,EAAE,MAAM;aACd,cAAc,CAAC,EAAE,MAAM;gBAHvB,UAAU,EAAE,MAAM,EAClC,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,MAAM,YAAA,EACd,cAAc,CAAC,EAAE,MAAM,YAAA,EACvC,OAAO,CAAC,EAAE,eAAe;CAO5B;AAED,qBAAa,wBAAyB,SAAQ,YAAY;aAGtC,aAAa,EAAE,MAAM;aACrB,aAAa,CAAC,EAAE,MAAM,EAAE;IACjC,iBAAiB,CAAC,EAAE,MAAM,EAAE;gBAHnC,OAAO,EAAE,MAAM,EACC,aAAa,EAAE,MAAM,EACrB,aAAa,CAAC,EAAE,MAAM,EAAE,YAAA,EACjC,iBAAiB,CAAC,EAAE,MAAM,EAAE,YAAA,EACnC,OAAO,CAAC,EAAE,eAAe;CAI5B"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE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AAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAAE,CAAC,UACnF,CAAC,KACR,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,aAAa,GAAG,WAAW,CAkBlD,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,CAAC,OAAO,CAAC,KAAG,MAExC,CAAC;AAEV,eAAO,MAAM,iBAAiB,GAAI,CAAC,OAAO,CAAC,EAAE,WAAW,MAAM,KAAG,CAAC,EAAE,EAqCnE,CAAC;AAEF,wBAAgB,eAAe,CAAC,CAAC,EAC/B,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACxB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,CAAC,CAAC,CAYZ;AAED,eAAO,MAAM,YAAY,UAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAKjH,CAAC"}
package/package.json CHANGED
@@ -1,41 +1,39 @@
1
1
  {
2
2
  "name": "@or-sdk/contacts",
3
- "version": "4.5.22",
3
+ "version": "4.6.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
8
8
  "scripts": {
9
- "build": "pnpm clean && pnpm build:esm & pnpm build:cjs",
9
+ "build": "pnpm clean && concurrently 'pnpm:build:*(!watch)'",
10
10
  "build:cjs": "tsc --project tsconfig.json",
11
11
  "build:esm": "tsc --project tsconfig.esm.json",
12
12
  "build:types": "tsc --project tsconfig.types.json",
13
- "build:watch": "concurrently -r --hide 1,2 \"pnpm build:watch:cjs\" \"pnpm build:watch:esm\" \"pnpm build:watch:types\"",
14
- "build:watch:cjs": "tsc --project tsconfig.json -w",
15
- "build:watch:esm": "tsc --project tsconfig.esm.json -w",
16
- "build:watch:types": "tsc --project tsconfig.types.json -w",
13
+ "build:watch": "concurrently -r --hide 1,2 'pnpm:build:watch:*'",
14
+ "build:watch:cjs": "pnpm build:cjs -w",
15
+ "build:watch:esm": "pnpm build:esm -w",
16
+ "build:watch:types": "pnpm build:types -w",
17
17
  "clean": "rm -rf ./dist",
18
+ "coverage": "vitest run --coverage",
18
19
  "dev": "pnpm build:watch:esm",
19
- "test": "vitest",
20
+ "test": "vitest --run",
20
21
  "test:watch": "vitest --watch"
21
22
  },
22
23
  "dependencies": {
23
24
  "@onereach/types-contacts-api": "5.40.14",
24
- "@or-sdk/base": "^0.41.0",
25
+ "@or-sdk/base": "^0.42.0",
25
26
  "agentkeepalive": "^4.5.0",
26
27
  "uuid": "^8.3.2"
27
28
  },
28
29
  "devDependencies": {
29
- "@types/chai-spies": "^1.0.4",
30
- "@vitest/coverage-c8": "^0.31.1",
31
- "chai-spies": "^1.0.0",
32
30
  "concurrently": "9.0.1",
33
- "msw": "1.3.3",
31
+ "msw": "2.8.2",
34
32
  "typescript": "5.6.2",
35
- "vitest": "^0.31.1"
33
+ "vitest": "^3.1.3"
36
34
  },
37
35
  "publishConfig": {
38
36
  "access": "public"
39
37
  },
40
- "gitHead": "7149228fc7403ab0aa100a9af071e2ce21101718"
38
+ "gitHead": "7c8a6a4bcd0ea2a445262dd9fc5a8cfd6974c8b0"
41
39
  }
package/src/Contacts.ts CHANGED
@@ -80,11 +80,11 @@ export class Contacts extends Base {
80
80
 
81
81
  parseError(e: AxiosError): Error {
82
82
  if (e.isAxiosError) {
83
- const { code, message, stack } = e;
83
+ const { status, message, stack } = e;
84
84
  if (this.withApiErrorLog) {
85
85
  this.logApiError(e);
86
86
  }
87
- return new ApiError(code, message, stack);
87
+ return new ApiError(status ?? 0, message, stack, undefined, { cause: e });
88
88
  }
89
89
 
90
90
  const parsedError = super.parseError(e);
@@ -1,20 +1,20 @@
1
- import { AxiosError } from '@or-sdk/base';
2
- import chai from 'chai';
3
- import spies from 'chai-spies';
4
- import { rest } from 'msw';
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import { http, HttpResponse } from 'msw';
5
4
  import { setupServer } from 'msw/node';
6
- import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
5
+ import { afterAll, afterEach, beforeAll, describe, expect, it, vi, assert } from 'vitest';
7
6
 
8
7
  import { ApiError } from '../apiError';
9
8
  import { Contacts } from '../Contacts';
10
9
 
11
- chai.use(spies);
12
-
13
10
  const server = setupServer(
14
- rest.delete('https://em.url/contact/qwe', () => {
15
- throw new AxiosError('axios error', '400');
11
+ http.delete('https://contacts.url/contact/bad-request', () => {
12
+ return new HttpResponse(JSON.stringify({ error: 'bad request' }), { status: 400 });
16
13
  }),
17
- rest.delete('https://em.url/contact/asd', () => {
14
+ http.delete('https://contacts.url/contact/non-server-error', () => {
15
+ // TODO: this test is wrong, it should not be done through mock of the server
16
+ // but through the axios interceptor or something else
17
+ // because the error is not from the server
18
18
  throw new Error('not an axios error');
19
19
  }),
20
20
  );
@@ -22,49 +22,45 @@ const server = setupServer(
22
22
  const buildContactsInstance = () => {
23
23
  return new Contacts({
24
24
  token: 'test-token',
25
- contactsApiUrl: 'https://em.url',
25
+ contactsApiUrl: 'https://contacts.url',
26
26
  });
27
27
  };
28
28
 
29
29
 
30
30
  describe('ContactsApi error handling', () => {
31
- beforeAll(() => server.listen());
31
+ beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
32
32
  afterEach(() => server.resetHandlers());
33
33
  afterAll(() => server.close());
34
34
 
35
35
  it('parseError called at API call failure', async () => {
36
36
  const api = buildContactsInstance();
37
- chai.spy.on(api, ['parseError'], () => { return new Error('spy error');});
38
- await api.contactApi.deleteContact('qwe').catch(() => {
39
- // bypassing, otherwise test will fail due to unhandled error
40
- });
41
- expect(api.parseError).to.have.been.called();
37
+ vi.spyOn(api, 'parseError');
38
+ await expect(api.contactApi.deleteContact('bad-request')).rejects.toThrow();
39
+ expect(api.parseError).toBeCalled();
42
40
  });
43
41
 
44
42
 
45
- it('Axios Error is handled properly', () => {
46
- const api = buildContactsInstance();
47
- api.contactApi.deleteContact('qwe')
48
- .then(() => {
49
- expect(false).toBeTruthy();
50
- })
51
- .catch((e) => {
52
- expect(e).toBeInstanceOf(ApiError);
53
- expect(e.message).toBe('axios error');
54
- expect(e.statusCode).toBe('400');
55
- });
43
+ it('Axios Error is handled properly', async () => {
44
+ try {
45
+ const api = buildContactsInstance();
46
+ await api.contactApi.deleteContact('bad-request');
47
+ assert.fail('should not reach this line');
48
+ } catch (e) {
49
+ expect(e).toBeInstanceOf(ApiError);
50
+ expect((e as ApiError).statusCode).toBe(400);
51
+ expect((e as any).cause.response.data.error).toBe('bad request');
52
+ }
56
53
  });
57
54
 
58
- it('Error is handled properly', () => {
59
- const api = buildContactsInstance();
60
- api.contactApi.deleteContact('asd')
61
- .then(() => {
62
- expect(false).toBeTruthy();
63
- })
64
- .catch((e) => {
65
- expect(e).toBeInstanceOf(Error);
66
- expect(e.message).toBe('not an axios error');
67
- });
55
+ it('Error is handled properly', async () => {
56
+ try {
57
+ const api = buildContactsInstance();
58
+ await api.contactApi.deleteContact('non-server-error');
59
+ assert.fail('should not reach this line');
60
+ } catch (e) {
61
+ expect(e).toBeInstanceOf(ApiError);
62
+ expect((e as ApiError).statusCode).toBe(500);
63
+ expect((e as any).cause.response.data.message).toBe('not an axios error');
64
+ }
68
65
  });
69
-
70
66
  });
@@ -1,5 +1,5 @@
1
1
  import { MigrationState } from '@onereach/types-contacts-api';
2
- import { rest } from 'msw';
2
+ import { http, HttpResponse } from 'msw';
3
3
  import { setupServer } from 'msw/node';
4
4
  import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
5
5
 
@@ -7,8 +7,8 @@ import { Contacts } from '../Contacts';
7
7
 
8
8
 
9
9
  const server = setupServer(
10
- rest.get('https://em.url/migrations/v2/status', (_, res, ctx) => {
11
- return res(ctx.json(MigrationState.InProgress));
10
+ http.get('https://em.url/migrations/v2/status', () => {
11
+ return HttpResponse.json(MigrationState.InProgress);
12
12
  }),
13
13
  );
14
14
 
@@ -1,51 +1,59 @@
1
1
  import { MigrationState } from '@onereach/types-contacts-api';
2
- import { rest } from 'msw';
2
+ import { http, HttpResponse } from 'msw';
3
3
  import { setupServer } from 'msw/node';
4
4
  import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
5
5
 
6
6
  import { Contacts } from '../Contacts';
7
7
 
8
-
9
- let getMigrationStatusCounter = 0;
10
- let skipMigrationStatusCounterCheck = false;
11
-
12
8
  const server = setupServer(
13
- rest.get('https://em.url/migrations/v2/status', (_, res, ctx) => {
14
- if (!skipMigrationStatusCounterCheck && getMigrationStatusCounter > 1) {
15
- return res(ctx.json(MigrationState.Done));
16
- }
17
- getMigrationStatusCounter += 1;
18
- return res(ctx.json(MigrationState.InProgress));
19
- }),
20
- rest.get('https://em.url/migrations/launch', (_, res, ctx) => {
21
- return res(ctx.status(201));
22
- })
9
+ http.get('https://contacts.url/migrations/launch', () => new HttpResponse(null, { status: 201 }))
23
10
  );
24
11
 
25
12
  const buildContactsInstance = () => {
26
13
  return new Contacts({
27
14
  token: 'test-token',
28
- contactsApiUrl: 'https://em.url',
15
+ contactsApiUrl: 'https://contacts.url',
29
16
  });
30
17
  };
31
18
 
32
19
  describe('ContactsApi error handling', () => {
33
- beforeAll(() => server.listen());
20
+ beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
34
21
  afterEach(() => server.resetHandlers());
35
22
  afterAll(() => server.close());
36
23
 
37
24
  it('pollMigrationUntilDone returns true when migration is Done', async () => {
25
+ server.use(
26
+ http.get(
27
+ 'https://contacts.url/migrations/v2/status',
28
+ () => HttpResponse.json(MigrationState.InProgress),
29
+ { once: true },
30
+ ),
31
+ http.get(
32
+ 'https://contacts.url/migrations/v2/status',
33
+ () => HttpResponse.json(MigrationState.Done),
34
+ ),
35
+ );
36
+
38
37
  const api = buildContactsInstance();
39
- const res = await api.migrationsApi.pollMigrationUntilDone(900000, 500);
38
+ const res = await api.migrationsApi.pollMigrationUntilDone(900000, 50, { debounceTimeout: 60 });
40
39
  expect(res).toBeTruthy();
41
40
  });
42
41
 
43
42
  it('pollMigrationUntilDone returns false when timeout exceeds', async () => {
44
- skipMigrationStatusCounterCheck = true;
43
+ server.use(
44
+ http.get(
45
+ 'https://contacts.url/migrations/v2/status',
46
+ () => HttpResponse.json(MigrationState.InProgress),
47
+ { once: true },
48
+ ),
49
+ http.get(
50
+ 'https://contacts.url/migrations/v2/status',
51
+ () => HttpResponse.json(MigrationState.Done),
52
+ ),
53
+ );
54
+
45
55
  const api = buildContactsInstance();
46
- const res = await api.migrationsApi.pollMigrationUntilDone(500);
56
+ const res = await api.migrationsApi.pollMigrationUntilDone(50, 100, { debounceTimeout: 60 });
47
57
  expect(res).toBeFalsy();
48
58
  });
49
-
50
-
51
59
  });
@@ -38,8 +38,8 @@ export default class BaseWithPoling extends BaseApi {
38
38
  } catch (e) {
39
39
  if (
40
40
  repeats < FAILED_REQUEST_REPEATS
41
- && 'statusCode' in (e as object)
42
- && (e as unknown as ApiError).statusCode === 'ERR_BAD_REQUEST'
41
+ && e instanceof ApiError
42
+ && e.statusCode === 400
43
43
  ) {
44
44
  this.logger?.log(batchId, ' NOT FOUND IN POLING');
45
45
  return await debouncePromise(async () => {
@@ -54,7 +54,11 @@ export default class MigrationsApi extends BaseApi {
54
54
  * @param timeoutMs optional, time in ms during which the poling will be kept alive; default is 15m
55
55
  * @param stepMs optional, time in ms between the polling requests; default is 1s
56
56
  */
57
- async pollMigrationUntilDone(timeoutMs = 900000, stepMs = 1000): Promise<boolean> {
57
+ async pollMigrationUntilDone(
58
+ timeoutMs = 900000,
59
+ stepMs = 1000,
60
+ { debounceTimeout }: { debounceTimeout?: number; } = {},
61
+ ): Promise<boolean> {
58
62
  const poll = async (timeout: number): Promise<boolean> => {
59
63
  if (timeout <= 0) {
60
64
  return false;
@@ -73,7 +77,7 @@ export default class MigrationsApi extends BaseApi {
73
77
  this.launchMigration();
74
78
  return debouncePromise(
75
79
  () => poll(timeoutMs),
76
- 3000
80
+ debounceTimeout ?? 3000,
77
81
  );
78
82
  }
79
83
 
package/src/apiError.ts CHANGED
@@ -1,24 +1,31 @@
1
+ import { ApiErrorOptions, ApiError as BaseApiError } from '@or-sdk/base';
2
+
1
3
  /**
2
4
  * Common parent for all api errors
3
5
  */
4
- export class ApiError extends Error {
6
+ export class ApiError extends BaseApiError {
5
7
  constructor(
6
- public readonly statusCode: any,
8
+ public readonly statusCode: number,
7
9
  message: string,
8
10
  public readonly stack?: string,
9
- public readonly translationKey?: string
11
+ public readonly translationKey?: string,
12
+ options?: ApiErrorOptions
10
13
  ) {
11
- super(message);
14
+ super(message, {
15
+ statusCode,
16
+ ...options,
17
+ });
12
18
  }
13
19
  }
14
20
 
15
- export class CreateContactsBatchError extends Error {
21
+ export class CreateContactsBatchError extends BaseApiError {
16
22
  constructor(
17
23
  message: string,
18
24
  public readonly failedBatchId: string,
19
25
  public readonly batchMessages?: string[],
20
26
  public processedBatchIds?: string[],
27
+ options?: ApiErrorOptions
21
28
  ) {
22
- super(message);
29
+ super(message, { ...options });
23
30
  }
24
31
  }