@or-sdk/contacts 3.1.1-beta.1619.0 → 3.1.1-beta.1627.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.
- package/dist/cjs/api/migrationsApi.js +24 -31
- package/dist/cjs/api/migrationsApi.js.map +1 -1
- package/dist/esm/api/migrationsApi.js +13 -21
- package/dist/esm/api/migrationsApi.js.map +1 -1
- package/dist/types/api/migrationsApi.d.ts +2 -1
- package/dist/types/api/migrationsApi.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/migrationsApi.ts +26 -23
|
@@ -51,7 +51,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
var lodash_1 = require("lodash");
|
|
55
54
|
var baseApi_1 = require("./baseApi");
|
|
56
55
|
var types_contacts_api_1 = require("@onereach/types-contacts-api");
|
|
57
56
|
var MigrationsApi = (function (_super) {
|
|
@@ -77,54 +76,48 @@ var MigrationsApi = (function (_super) {
|
|
|
77
76
|
route: 'migrations/run',
|
|
78
77
|
});
|
|
79
78
|
};
|
|
80
|
-
MigrationsApi.prototype.
|
|
79
|
+
MigrationsApi.prototype.launchMigration = function () {
|
|
81
80
|
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
return [2, this.apiCall({
|
|
83
|
+
method: 'GET',
|
|
84
|
+
route: 'migrations/launch',
|
|
85
|
+
})];
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
MigrationsApi.prototype.pollMigrationUntilDone = function (timeoutMs) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
var poll;
|
|
83
92
|
var _this = this;
|
|
84
93
|
return __generator(this, function (_a) {
|
|
85
94
|
switch (_a.label) {
|
|
86
|
-
case 0:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
migrationTimeout = (function () {
|
|
92
|
-
var defaultTimeout = 1000 * 60 * 30;
|
|
93
|
-
if (timeoutMs !== undefined && timeoutMs > defaultTimeout) {
|
|
94
|
-
throw new Error('Migration timeout cont not be greater of 30m');
|
|
95
|
-
}
|
|
96
|
-
return timeoutMs !== undefined ? timeoutMs : 1000 * 60 * 30;
|
|
97
|
-
})();
|
|
98
|
-
poll = function (passedTime) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
-
var start, state, end_1, debouncedPoll;
|
|
100
|
-
var _this = this;
|
|
95
|
+
case 0: return [4, this.launchMigration()];
|
|
96
|
+
case 1:
|
|
97
|
+
_a.sent();
|
|
98
|
+
poll = function (timeout) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
+
var start, state, end;
|
|
101
100
|
return __generator(this, function (_a) {
|
|
102
101
|
switch (_a.label) {
|
|
103
102
|
case 0:
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
start = performance.now();
|
|
104
|
+
if (timeout < 0) {
|
|
106
105
|
return [2, false];
|
|
107
106
|
}
|
|
108
|
-
start = performance.now();
|
|
109
107
|
return [4, this.getMigrationState()];
|
|
110
108
|
case 1:
|
|
111
109
|
state = _a.sent();
|
|
112
110
|
if (state === types_contacts_api_1.MigrationState.Done) {
|
|
113
111
|
return [2, true];
|
|
114
112
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return [2, poll(passedTime !== undefined ? passedTime : 0 + end_1 - start)];
|
|
119
|
-
}); }); }, 1000);
|
|
120
|
-
return [4, debouncedPoll()];
|
|
121
|
-
case 2: return [2, !!(_a.sent())];
|
|
122
|
-
case 3: return [2, true];
|
|
113
|
+
end = performance.now();
|
|
114
|
+
return [4, poll(timeout - end + start)];
|
|
115
|
+
case 2: return [2, _a.sent()];
|
|
123
116
|
}
|
|
124
117
|
});
|
|
125
118
|
}); };
|
|
126
|
-
return [4, poll()];
|
|
127
|
-
case
|
|
119
|
+
return [4, poll(timeoutMs !== undefined ? timeoutMs : 15 * 60 * 1000)];
|
|
120
|
+
case 2: return [2, _a.sent()];
|
|
128
121
|
}
|
|
129
122
|
});
|
|
130
123
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrationsApi.js","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"migrationsApi.js","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AACpC,mEAA8D;AAE9D;IAA2C,iCAAO;IAAlD;;IAsEA,CAAC;IAhEC,wCAAgB,GAAhB;QACE,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,mBAAmB;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,yCAAiB,GAAjB;QACE,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,sBAAsB;SAC9B,CAAC,CAAC;IACL,CAAC;IAMD,qCAAa,GAAb;QACE,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,MAAM,EAAE,KAAK;YACb,KAAK,EAAE,gBAAgB;SACxB,CAAC,CAAC;IACL,CAAC;IAQK,uCAAe,GAArB;;;gBACE,WAAO,IAAI,CAAC,OAAO,CAAC;wBAClB,MAAM,EAAE,KAAK;wBACb,KAAK,EAAE,mBAAmB;qBAC3B,CAAC,EAAC;;;KACJ;IAOK,8CAAsB,GAA5B,UAA6B,SAAkB;;;;;;4BAC7C,WAAM,IAAI,CAAC,eAAe,EAAE,EAAA;;wBAA5B,SAA4B,CAAC;wBAEvB,IAAI,GAAG,UAAO,OAAe;;;;;wCAC3B,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;wCAChC,IAAI,OAAO,GAAG,CAAC,EAAE;4CACf,WAAO,KAAK,EAAC;yCACd;wCAEa,WAAM,IAAI,CAAC,iBAAiB,EAAE,EAAA;;wCAAtC,KAAK,GAAG,SAA8B;wCAE5C,IAAI,KAAK,KAAK,mCAAc,CAAC,IAAI,EAAE;4CACjC,WAAO,IAAI,EAAC;yCACb;wCAEK,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;wCACvB,WAAM,IAAI,CAAC,OAAO,GAAG,GAAG,GAAG,KAAK,CAAC,EAAA;4CAAxC,WAAO,SAAiC,EAAC;;;6BAC1C,CAAC;wBAEK,WAAM,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,EAAA;4BAAvE,WAAO,SAAgE,EAAC;;;;KACzE;IACH,oBAAC;AAAD,CAAC,AAtED,CAA2C,iBAAO,GAsEjD"}
|
|
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { debounce } from 'lodash';
|
|
11
10
|
import { BaseApi } from './baseApi';
|
|
12
11
|
import { MigrationState } from '@onereach/types-contacts-api';
|
|
13
12
|
export default class MigrationsApi extends BaseApi {
|
|
@@ -29,37 +28,30 @@ export default class MigrationsApi extends BaseApi {
|
|
|
29
28
|
route: 'migrations/run',
|
|
30
29
|
});
|
|
31
30
|
}
|
|
32
|
-
|
|
31
|
+
launchMigration() {
|
|
33
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
this.apiCall({
|
|
33
|
+
return this.apiCall({
|
|
35
34
|
method: 'GET',
|
|
36
35
|
route: 'migrations/launch',
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if ((passedTime || 0) > migrationTimeout) {
|
|
47
|
-
timeoutCb && timeoutCb();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
pollMigrationUntilDone(timeoutMs) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
yield this.launchMigration();
|
|
42
|
+
const poll = (timeout) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const start = performance.now();
|
|
44
|
+
if (timeout < 0) {
|
|
48
45
|
return false;
|
|
49
46
|
}
|
|
50
|
-
const start = performance.now();
|
|
51
47
|
const state = yield this.getMigrationState();
|
|
52
48
|
if (state === MigrationState.Done) {
|
|
53
49
|
return true;
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const debouncedPoll = debounce(() => __awaiter(this, void 0, void 0, function* () { return poll(passedTime !== undefined ? passedTime : 0 + end - start); }), 1000);
|
|
58
|
-
return !!(yield debouncedPoll());
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
51
|
+
const end = performance.now();
|
|
52
|
+
return yield poll(timeout - end + start);
|
|
61
53
|
});
|
|
62
|
-
return yield poll();
|
|
54
|
+
return yield poll(timeoutMs !== undefined ? timeoutMs : 15 * 60 * 1000);
|
|
63
55
|
});
|
|
64
56
|
}
|
|
65
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrationsApi.js","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"migrationsApi.js","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D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C,CAAC;QAC1E,CAAC;KAAA;CACF"}
|
|
@@ -4,6 +4,7 @@ export default class MigrationsApi extends BaseApi {
|
|
|
4
4
|
migrationsStatus(): Promise<boolean>;
|
|
5
5
|
getMigrationState(): Promise<MigrationState>;
|
|
6
6
|
migrationsRun(): Promise<void>;
|
|
7
|
-
|
|
7
|
+
launchMigration(): Promise<void>;
|
|
8
|
+
pollMigrationUntilDone(timeoutMs?: number): Promise<boolean>;
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=migrationsApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrationsApi.d.ts","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrationsApi.d.ts","sourceRoot":"","sources":["../../../src/api/migrationsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,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;IAYhC,sBAAsB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAqBnE"}
|
package/package.json
CHANGED
package/src/api/migrationsApi.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { debounce } from 'lodash';
|
|
2
1
|
import { BaseApi } from './baseApi';
|
|
3
2
|
import { MigrationState } from '@onereach/types-contacts-api';
|
|
3
|
+
|
|
4
4
|
export default class MigrationsApi extends BaseApi {
|
|
5
5
|
/**
|
|
6
6
|
* Migrations status.
|
|
7
|
-
* @deprecated
|
|
8
7
|
* @description Returns true if there are pending migrations
|
|
8
|
+
* @deprecated use getMigrationState instead
|
|
9
9
|
*/
|
|
10
10
|
migrationsStatus(): Promise<boolean> {
|
|
11
11
|
return this.apiCall({
|
|
@@ -23,7 +23,7 @@ export default class MigrationsApi extends BaseApi {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @description Run all pending migrations
|
|
26
|
-
* @deprecated
|
|
26
|
+
* @deprecated use launchMigration instead
|
|
27
27
|
*/
|
|
28
28
|
migrationsRun(): Promise<void> {
|
|
29
29
|
return this.apiCall({
|
|
@@ -32,40 +32,43 @@ export default class MigrationsApi extends BaseApi {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Launches migration without waiting for its completion.
|
|
37
|
+
* Migration completion might be checked with the getMigrationState method.
|
|
38
|
+
* Also pollMigrationUntilDone might be used for waiting until the migration state
|
|
39
|
+
* is turned to Done.
|
|
40
|
+
*/
|
|
41
|
+
async launchMigration(): Promise<void> {
|
|
42
|
+
return this.apiCall({
|
|
37
43
|
method: 'GET',
|
|
38
44
|
route: 'migrations/launch',
|
|
39
45
|
});
|
|
46
|
+
}
|
|
40
47
|
|
|
41
|
-
const migrationTimeout = (() => {
|
|
42
|
-
const defaultTimeout = 1000 * 60 * 30;
|
|
43
|
-
if (timeoutMs !== undefined && timeoutMs > defaultTimeout) {
|
|
44
|
-
throw new Error('Migration timeout cont not be greater of 30m');
|
|
45
|
-
}
|
|
46
|
-
return timeoutMs !== undefined ? timeoutMs : 1000 * 60 * 30;
|
|
47
|
-
})();
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Launches migration and waits until its status turns to Done.
|
|
51
|
+
* @param timeoutMs optional, time in ms during which the poling will be kept alive; default is 15m
|
|
52
|
+
*/
|
|
53
|
+
async pollMigrationUntilDone(timeoutMs?: number): Promise<boolean> {
|
|
54
|
+
await this.launchMigration();
|
|
55
|
+
|
|
56
|
+
const poll = async (timeout: number): Promise<boolean> => {
|
|
57
|
+
const start = performance.now();
|
|
58
|
+
if (timeout < 0) {
|
|
52
59
|
return false;
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
const start = performance.now();
|
|
56
62
|
const state = await this.getMigrationState();
|
|
63
|
+
|
|
57
64
|
if (state === MigrationState.Done) {
|
|
58
65
|
return true;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const debouncedPoll = debounce(async () => poll(passedTime !== undefined ? passedTime : 0 + end - start), 1000);
|
|
64
|
-
return !!(await debouncedPoll());
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
68
|
+
const end = performance.now();
|
|
69
|
+
return await poll(timeout - end + start);
|
|
67
70
|
};
|
|
68
71
|
|
|
69
|
-
return await poll();
|
|
72
|
+
return await poll(timeoutMs !== undefined ? timeoutMs : 15 * 60 * 1000);
|
|
70
73
|
}
|
|
71
74
|
}
|