@devrev/airsync-sdk 2.0.0-beta.1 → 2.0.0-beta.11
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/README.md +7 -21
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +6 -7
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +4 -3
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +69 -61
- package/dist/common/constants.d.ts +15 -12
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +20 -34
- package/dist/common/helpers.d.ts +3 -27
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +6 -36
- package/dist/http/client.d.ts +4 -0
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/client.js +80 -0
- package/dist/http/errors.d.ts +8 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +31 -0
- package/dist/index.d.ts +30 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -28
- package/dist/logger/logger.d.ts +13 -70
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +4 -7
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +67 -92
- package/dist/mappers/mappers.d.ts +10 -43
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.d.ts +173 -0
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -0
- package/dist/mappers/{mappers.interface.js → mappers.interfaces.js} +1 -10
- package/dist/mappers/mappers.js +32 -46
- package/dist/multithreading/adapters/base-adapter.d.ts +39 -0
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/base-adapter.js +212 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts +49 -0
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/extraction-adapter.js +375 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts +26 -0
- package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts +12 -0
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -0
- package/dist/multithreading/{worker-adapter/worker-adapter.helpers.js → adapters/loading-adapter.helpers.js} +2 -12
- package/dist/multithreading/adapters/loading-adapter.js +279 -0
- package/dist/multithreading/emit.d.ts +11 -0
- package/dist/multithreading/emit.d.ts.map +1 -0
- package/dist/multithreading/emit.js +25 -0
- package/dist/multithreading/process-task.d.ts +6 -1
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +120 -82
- package/dist/multithreading/spawn/spawn.d.ts +10 -11
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts +12 -11
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +142 -77
- package/dist/multithreading/spawn/spawn.js +59 -75
- package/dist/multithreading/worker.js +16 -5
- package/dist/repo/repo.d.ts +14 -5
- package/dist/repo/repo.d.ts.map +1 -1
- package/dist/repo/repo.helpers.d.ts +6 -0
- package/dist/repo/repo.helpers.d.ts.map +1 -0
- package/dist/repo/repo.helpers.js +16 -0
- package/dist/repo/repo.interfaces.d.ts +11 -20
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +36 -22
- package/dist/state/base-state.d.ts +58 -0
- package/dist/state/base-state.d.ts.map +1 -0
- package/dist/state/base-state.js +242 -0
- package/dist/state/extraction-state.d.ts +14 -0
- package/dist/state/extraction-state.d.ts.map +1 -0
- package/dist/state/extraction-state.js +146 -0
- package/dist/state/install-initial-domain-mapping.d.ts +4 -0
- package/dist/state/install-initial-domain-mapping.d.ts.map +1 -0
- package/dist/{common → state}/install-initial-domain-mapping.js +5 -7
- package/dist/state/loading-state.d.ts +8 -0
- package/dist/state/loading-state.d.ts.map +1 -0
- package/dist/state/loading-state.js +29 -0
- package/dist/state/state.d.ts +3 -29
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.interfaces.d.ts +31 -12
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +17 -1
- package/dist/state/state.js +9 -164
- package/dist/state/time-value-resolver.d.ts +17 -0
- package/dist/state/time-value-resolver.d.ts.map +1 -0
- package/dist/state/time-value-resolver.js +110 -0
- package/dist/testing/mock-event.d.ts +10 -0
- package/dist/testing/mock-event.d.ts.map +1 -0
- package/dist/testing/mock-event.js +96 -0
- package/dist/testing/mock-server.d.ts +31 -0
- package/dist/testing/mock-server.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.d.ts +54 -0
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -0
- package/dist/testing/mock-server.interfaces.js +4 -0
- package/dist/testing/mock-server.js +297 -0
- package/dist/testing/test-adapters.d.ts +22 -0
- package/dist/testing/test-adapters.d.ts.map +1 -0
- package/dist/testing/test-adapters.js +32 -0
- package/dist/types/common.d.ts +4 -37
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +2 -17
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +28 -0
- package/dist/types/external-domain-metadata.d.ts +40 -162
- package/dist/types/external-domain-metadata.d.ts.map +1 -1
- package/dist/types/extraction.d.ts +135 -278
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +46 -133
- package/dist/types/loading.d.ts +15 -55
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/loading.js +1 -23
- package/dist/types/workers.d.ts +70 -103
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +1 -6
- package/dist/uploader/uploader.d.ts +10 -61
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.d.ts +7 -27
- package/dist/uploader/uploader.helpers.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.js +80 -30
- package/dist/uploader/uploader.interfaces.d.ts +19 -54
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -1
- package/dist/uploader/uploader.interfaces.js +8 -0
- package/dist/uploader/uploader.js +72 -124
- package/docs/MIGRATION.md +751 -0
- package/package.json +35 -22
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts +0 -2
- package/dist/attachments-streaming/attachments-streaming-pool.test.d.ts.map +0 -1
- package/dist/attachments-streaming/attachments-streaming-pool.test.js +0 -321
- package/dist/common/control-protocol.d.ts +0 -10
- package/dist/common/control-protocol.d.ts.map +0 -1
- package/dist/common/control-protocol.js +0 -31
- package/dist/common/errors.d.ts +0 -6
- package/dist/common/errors.d.ts.map +0 -1
- package/dist/common/errors.js +0 -4
- package/dist/common/event-type-translation.d.ts +0 -24
- package/dist/common/event-type-translation.d.ts.map +0 -1
- package/dist/common/event-type-translation.js +0 -117
- package/dist/common/install-initial-domain-mapping.d.ts +0 -4
- package/dist/common/install-initial-domain-mapping.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.d.ts +0 -2
- package/dist/common/install-initial-domain-mapping.test.d.ts.map +0 -1
- package/dist/common/install-initial-domain-mapping.test.js +0 -208
- package/dist/deprecated/adapter/index.d.ts +0 -62
- package/dist/deprecated/adapter/index.d.ts.map +0 -1
- package/dist/deprecated/adapter/index.js +0 -151
- package/dist/deprecated/common/helpers.d.ts +0 -7
- package/dist/deprecated/common/helpers.d.ts.map +0 -1
- package/dist/deprecated/common/helpers.js +0 -47
- package/dist/deprecated/demo-extractor/external_domain_metadata.json +0 -38
- package/dist/deprecated/demo-extractor/index.d.ts +0 -18
- package/dist/deprecated/demo-extractor/index.d.ts.map +0 -1
- package/dist/deprecated/demo-extractor/index.js +0 -161
- package/dist/deprecated/http/client.d.ts +0 -22
- package/dist/deprecated/http/client.d.ts.map +0 -1
- package/dist/deprecated/http/client.js +0 -161
- package/dist/deprecated/uploader/index.d.ts +0 -35
- package/dist/deprecated/uploader/index.d.ts.map +0 -1
- package/dist/deprecated/uploader/index.js +0 -161
- package/dist/http/axios-client-internal.d.ts +0 -3
- package/dist/http/axios-client-internal.d.ts.map +0 -1
- package/dist/http/axios-client-internal.js +0 -66
- package/dist/http/axios-client-internal.test.d.ts +0 -2
- package/dist/http/axios-client-internal.test.d.ts.map +0 -1
- package/dist/http/axios-client-internal.test.js +0 -154
- package/dist/http/axios-client.d.ts +0 -27
- package/dist/http/axios-client.d.ts.map +0 -1
- package/dist/http/axios-client.js +0 -57
- package/dist/http/constants.d.ts +0 -4
- package/dist/http/constants.d.ts.map +0 -1
- package/dist/http/constants.js +0 -6
- package/dist/http/index.d.ts +0 -3
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js +0 -18
- package/dist/http/types.d.ts +0 -17
- package/dist/http/types.d.ts.map +0 -1
- package/dist/http/types.js +0 -2
- package/dist/logger/logger.constants.d.ts +0 -6
- package/dist/logger/logger.constants.d.ts.map +0 -1
- package/dist/logger/logger.constants.js +0 -13
- package/dist/logger/logger.context.d.ts +0 -58
- package/dist/logger/logger.context.d.ts.map +0 -1
- package/dist/logger/logger.context.js +0 -86
- package/dist/logger/logger.test.d.ts +0 -2
- package/dist/logger/logger.test.d.ts.map +0 -1
- package/dist/logger/logger.test.js +0 -490
- package/dist/mappers/mappers.interface.d.ts +0 -294
- package/dist/mappers/mappers.interface.d.ts.map +0 -1
- package/dist/mappers/mappers.test.d.ts +0 -2
- package/dist/mappers/mappers.test.d.ts.map +0 -1
- package/dist/mappers/mappers.test.js +0 -107
- package/dist/multithreading/create-worker.test.d.ts +0 -2
- package/dist/multithreading/create-worker.test.d.ts.map +0 -1
- package/dist/multithreading/create-worker.test.js +0 -89
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts +0 -2
- package/dist/multithreading/spawn/spawn.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/spawn/spawn.helpers.test.js +0 -293
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.artifacts.test.js +0 -127
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts +0 -91
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts +0 -22
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.helpers.test.js +0 -514
- package/dist/multithreading/worker-adapter/worker-adapter.js +0 -745
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts +0 -2
- package/dist/multithreading/worker-adapter/worker-adapter.test.d.ts.map +0 -1
- package/dist/multithreading/worker-adapter/worker-adapter.test.js +0 -483
- package/dist/repo/repo.test.d.ts +0 -2
- package/dist/repo/repo.test.d.ts.map +0 -1
- package/dist/repo/repo.test.js +0 -131
- package/dist/state/state.test.d.ts +0 -2
- package/dist/state/state.test.d.ts.map +0 -1
- package/dist/state/state.test.js +0 -224
- package/dist/types/extraction.test.d.ts +0 -2
- package/dist/types/extraction.test.d.ts.map +0 -1
- package/dist/types/extraction.test.js +0 -70
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/uploader/uploader.helpers.test.d.ts +0 -2
- package/dist/uploader/uploader.helpers.test.d.ts.map +0 -1
- package/dist/uploader/uploader.helpers.test.js +0 -267
- package/dist/uploader/uploader.test.d.ts +0 -2
- package/dist/uploader/uploader.test.d.ts.map +0 -1
- package/dist/uploader/uploader.test.js +0 -589
|
@@ -1,35 +1,26 @@
|
|
|
1
|
+
import { AirSyncEvent } from '../types/extraction';
|
|
2
|
+
import { RepoOptions, RuntimeOptions } from '../types/workers';
|
|
1
3
|
import { Artifact } from '../uploader/uploader.interfaces';
|
|
2
|
-
|
|
3
|
-
import { WorkerAdapterOptions } from '../types/workers';
|
|
4
|
-
/**
|
|
5
|
-
* RepoInterface is an interface that defines the structure of a repo which is used to store and upload extracted data.
|
|
6
|
-
*/
|
|
4
|
+
/** Stores and uploads extracted data. */
|
|
7
5
|
export interface RepoInterface {
|
|
8
6
|
itemType: string;
|
|
9
7
|
normalize?: (record: object) => NormalizedItem | NormalizedAttachment;
|
|
8
|
+
overriddenOptions?: RepoOptions;
|
|
10
9
|
}
|
|
11
|
-
/**
|
|
12
|
-
* RepoFactoryInterface is an interface that defines the structure of a repo factory which is used to create a repo.
|
|
13
|
-
*/
|
|
14
10
|
export interface RepoFactoryInterface {
|
|
15
|
-
event:
|
|
11
|
+
event: AirSyncEvent;
|
|
16
12
|
itemType: string;
|
|
17
13
|
normalize?: (record: object) => NormalizedItem | NormalizedAttachment;
|
|
18
14
|
onUpload: (artifact: Artifact) => void;
|
|
19
|
-
options?:
|
|
15
|
+
options?: RuntimeOptions;
|
|
16
|
+
skipConfirmation?: boolean;
|
|
20
17
|
}
|
|
21
|
-
/**
|
|
22
|
-
* NormalizedItem is an interface of item after normalization.
|
|
23
|
-
*/
|
|
24
18
|
export interface NormalizedItem {
|
|
25
19
|
id: string;
|
|
26
20
|
created_date: string;
|
|
27
21
|
modified_date: string;
|
|
28
22
|
data: object;
|
|
29
23
|
}
|
|
30
|
-
/**
|
|
31
|
-
* NormalizedAttachment is an interface of attachment after normalization.
|
|
32
|
-
*/
|
|
33
24
|
export interface NormalizedAttachment {
|
|
34
25
|
url: string;
|
|
35
26
|
id: string;
|
|
@@ -37,10 +28,10 @@ export interface NormalizedAttachment {
|
|
|
37
28
|
parent_id: string;
|
|
38
29
|
author_id?: string;
|
|
39
30
|
inline?: boolean;
|
|
40
|
-
|
|
31
|
+
content_type?: string;
|
|
32
|
+
created_date?: string;
|
|
33
|
+
modified_date?: string;
|
|
34
|
+
grand_parent_id?: string;
|
|
41
35
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Item is an interface that defines the structure of an item.
|
|
44
|
-
*/
|
|
45
36
|
export type Item = Record<string, any>;
|
|
46
37
|
//# sourceMappingURL=repo.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repo.interfaces.d.ts","sourceRoot":"","sources":["../../src/repo/repo.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"repo.interfaces.d.ts","sourceRoot":"","sources":["../../src/repo/repo.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAE3D,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,cAAc,GAAG,oBAAoB,CAAC;IACtE,iBAAiB,CAAC,EAAE,WAAW,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,cAAc,GAAG,oBAAoB,CAAC;IACtE,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAGD,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
|
package/dist/repo/repo.js
CHANGED
|
@@ -3,13 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Repo = void 0;
|
|
4
4
|
const constants_1 = require("../common/constants");
|
|
5
5
|
const uploader_1 = require("../uploader/uploader");
|
|
6
|
+
const repo_helpers_1 = require("./repo.helpers");
|
|
6
7
|
class Repo {
|
|
7
|
-
|
|
8
|
+
/** @internal */
|
|
9
|
+
constructor({ event, itemType, normalize, onUpload, options, skipConfirmation, }) {
|
|
10
|
+
this.dateRanges = {
|
|
11
|
+
creationDate: {},
|
|
12
|
+
modifiedDate: {},
|
|
13
|
+
};
|
|
8
14
|
this.items = [];
|
|
9
15
|
this.itemType = itemType;
|
|
10
16
|
this.normalize = normalize;
|
|
11
17
|
this.onUpload = onUpload;
|
|
12
|
-
this.uploader = new uploader_1.Uploader({ event, options });
|
|
18
|
+
this.uploader = new uploader_1.Uploader({ event, options, skipConfirmation });
|
|
13
19
|
this.options = options;
|
|
14
20
|
this.uploadedArtifacts = [];
|
|
15
21
|
}
|
|
@@ -17,17 +23,33 @@ class Repo {
|
|
|
17
23
|
return this.items;
|
|
18
24
|
}
|
|
19
25
|
async upload(batch) {
|
|
26
|
+
var _a;
|
|
20
27
|
const itemsToUpload = batch || this.items;
|
|
21
28
|
if (itemsToUpload.length > 0) {
|
|
29
|
+
for (const item of itemsToUpload) {
|
|
30
|
+
const createdDate = item === null || item === void 0 ? void 0 : item.created_date;
|
|
31
|
+
if (createdDate != null) {
|
|
32
|
+
const createdMs = (0, repo_helpers_1.toValidTimestamp)(createdDate);
|
|
33
|
+
if (createdMs !== undefined) {
|
|
34
|
+
(0, repo_helpers_1.updateRange)(this.dateRanges.creationDate, createdMs);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const modifiedDate = item === null || item === void 0 ? void 0 : item.modified_date;
|
|
38
|
+
if (modifiedDate != null && modifiedDate !== '') {
|
|
39
|
+
const modifiedMs = (0, repo_helpers_1.toValidTimestamp)(modifiedDate);
|
|
40
|
+
if (modifiedMs !== undefined) {
|
|
41
|
+
(0, repo_helpers_1.updateRange)(this.dateRanges.modifiedDate, modifiedMs);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
22
45
|
console.log(`Uploading ${itemsToUpload.length} items of type ${this.itemType}. `);
|
|
23
46
|
const { artifact, error } = await this.uploader.upload(this.itemType, itemsToUpload);
|
|
24
47
|
if (error || !artifact) {
|
|
25
|
-
console.error(
|
|
26
|
-
|
|
48
|
+
console.error(`Error while uploading batch of ${itemsToUpload.length} items of type ${this.itemType}.`, error);
|
|
49
|
+
throw new Error((_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : `Upload failed for item type "${this.itemType}" without artifact.`);
|
|
27
50
|
}
|
|
28
51
|
this.onUpload(artifact);
|
|
29
52
|
this.uploadedArtifacts.push(artifact);
|
|
30
|
-
// Clear the uploaded items from the main items array if no batch was specified
|
|
31
53
|
if (!batch) {
|
|
32
54
|
this.items = [];
|
|
33
55
|
}
|
|
@@ -37,39 +59,31 @@ class Repo {
|
|
|
37
59
|
console.log(`No items to upload for type ${this.itemType}. Skipping upload.`);
|
|
38
60
|
}
|
|
39
61
|
}
|
|
62
|
+
/** Buffers items and uploads every full batch. Throws if an upload fails. */
|
|
40
63
|
async push(items) {
|
|
41
64
|
var _a;
|
|
42
65
|
let recordsToPush;
|
|
43
66
|
if (!items || items.length === 0) {
|
|
44
67
|
console.log(`No items to push for type ${this.itemType}. Skipping push.`);
|
|
45
|
-
return
|
|
68
|
+
return;
|
|
46
69
|
}
|
|
47
|
-
// Normalize items if needed
|
|
48
70
|
if (this.normalize &&
|
|
49
|
-
this.itemType != constants_1.
|
|
50
|
-
this.itemType != constants_1.
|
|
71
|
+
this.itemType != constants_1.AirSyncDefaultItemTypes.EXTERNAL_DOMAIN_METADATA &&
|
|
72
|
+
this.itemType != constants_1.SSOR_ATTACHMENT) {
|
|
51
73
|
recordsToPush = items.map((item) => this.normalize(item));
|
|
52
74
|
}
|
|
53
75
|
else {
|
|
54
76
|
recordsToPush = items;
|
|
55
77
|
}
|
|
56
|
-
// Add the new records to the items array
|
|
57
78
|
this.items.push(...recordsToPush);
|
|
58
|
-
// Upload in batches while the number of items exceeds the batch size
|
|
59
79
|
const batchSize = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.batchSize) || constants_1.ARTIFACT_BATCH_SIZE;
|
|
60
80
|
while (this.items.length >= batchSize) {
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.error('Error while uploading batch', error);
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
81
|
+
// Items leave the repo only after their batch uploaded, so a failed
|
|
82
|
+
// batch is still there for the next flush.
|
|
83
|
+
const batch = this.items.slice(0, batchSize);
|
|
84
|
+
await this.upload(batch);
|
|
85
|
+
this.items.splice(0, batchSize);
|
|
71
86
|
}
|
|
72
|
-
return true;
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
exports.Repo = Repo;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { InitialDomainMapping } from '../types/common';
|
|
2
|
+
import { AirSyncEvent } from '../types/extraction';
|
|
3
|
+
import { ExtractionScope } from '../types/workers';
|
|
4
|
+
import { SdkState, StateInterface } from './state.interfaces';
|
|
5
|
+
/**
|
|
6
|
+
* State lifecycle shared by all sync modes: connector/SDK state separation,
|
|
7
|
+
* fetch/init/post, the v1 to v2 migration shim, and the snap-in-version-gated
|
|
8
|
+
* initial domain mapping install. Subclasses seed the SDK-owned state.
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class BaseState<ConnectorState> {
|
|
11
|
+
protected _connectorState: ConnectorState;
|
|
12
|
+
protected _sdkState: SdkState;
|
|
13
|
+
protected _extractionScope: ExtractionScope;
|
|
14
|
+
protected readonly initialSdkState: SdkState;
|
|
15
|
+
protected readonly event: AirSyncEvent;
|
|
16
|
+
private workerUrl;
|
|
17
|
+
private devrevToken;
|
|
18
|
+
private syncUnitId;
|
|
19
|
+
private requestId;
|
|
20
|
+
constructor({ event, initialState }: StateInterface<ConnectorState>, initialSdkState: SdkState);
|
|
21
|
+
/** Connector-owned state; what `adapter.state` exposes to snap-in code. */
|
|
22
|
+
get state(): ConnectorState;
|
|
23
|
+
set state(value: ConnectorState);
|
|
24
|
+
/** SDK-internal bookkeeping state. Never exposed to connector code. */
|
|
25
|
+
get sdkState(): SdkState;
|
|
26
|
+
set sdkState(value: SdkState);
|
|
27
|
+
get extractionScope(): ExtractionScope;
|
|
28
|
+
/**
|
|
29
|
+
* Installs the initial domain mapping when the snap-in version in state
|
|
30
|
+
* differs from the event context. Shared by all modes so a loading run still
|
|
31
|
+
* installs the mapping if extraction has not done so.
|
|
32
|
+
*/
|
|
33
|
+
installInitialDomainMappingIfNeeded(initialDomainMapping?: InitialDomainMapping): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Fetches state from API, or creates the initial state on 404. Reads both
|
|
36
|
+
* the v2 envelope and a legacy flat v1 blob (migrated on read); always
|
|
37
|
+
* persists the v2 envelope going forward.
|
|
38
|
+
*/
|
|
39
|
+
init(initialState: ConnectorState): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Normalizes fetched state into the `{ connectorState, sdkState }` envelope.
|
|
42
|
+
* Versioned envelopes are read by `stateVersion`; unversioned ones (2.0.0
|
|
43
|
+
* betas) by their keys; anything else is a flat v1 blob split by
|
|
44
|
+
* `V1_SDK_STATE_KEYS`.
|
|
45
|
+
*/
|
|
46
|
+
private normalizeFetchedState;
|
|
47
|
+
private readEnvelope;
|
|
48
|
+
/**
|
|
49
|
+
* Posts the v2 envelope (connector and SDK state as they are now) to the
|
|
50
|
+
* API. Throws on failure so a caller can stop before a risky external write.
|
|
51
|
+
*/
|
|
52
|
+
postState(): Promise<void>;
|
|
53
|
+
fetchState(): Promise<{
|
|
54
|
+
state: string;
|
|
55
|
+
objects?: string;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=base-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-state.d.ts","sourceRoot":"","sources":["../../src/state/base-state.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAEL,QAAQ,EAER,cAAc,EAEf,MAAM,oBAAoB,CAAC;AAE5B;;;;GAIG;AACH,8BAAsB,SAAS,CAAC,cAAc;IAC5C,SAAS,CAAC,eAAe,EAAE,cAAc,CAAC;IAC1C,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC;IAC9B,SAAS,CAAC,gBAAgB,EAAE,eAAe,CAAM;IACjD,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC;IAC7C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IACvC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAS;gBAGxB,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,EACvD,eAAe,EAAE,QAAQ;IAY3B,2EAA2E;IAC3E,IAAI,KAAK,IAAI,cAAc,CAE1B;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,cAAc,EAE9B;IAED,uEAAuE;IACvE,IAAI,QAAQ,IAAI,QAAQ,CAEvB;IAED,IAAI,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAE3B;IAED,IAAI,eAAe,IAAI,eAAe,CAErC;IAED;;;;OAIG;IACG,mCAAmC,CACvC,oBAAoB,CAAC,EAAE,oBAAoB,GAC1C,OAAO,CAAC,IAAI,CAAC;IAwChB;;;;OAIG;IACG,IAAI,CAAC,YAAY,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAuDvD;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IA2C7B,OAAO,CAAC,YAAY;IAepB;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IA0C1B,UAAU,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAqBjE"}
|
|
@@ -0,0 +1,242 @@
|
|
|
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.BaseState = void 0;
|
|
7
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const client_1 = require("../http/client");
|
|
10
|
+
const logger_1 = require("../logger/logger");
|
|
11
|
+
const workers_1 = require("../types/workers");
|
|
12
|
+
const install_initial_domain_mapping_1 = require("./install-initial-domain-mapping");
|
|
13
|
+
const state_interfaces_1 = require("./state.interfaces");
|
|
14
|
+
/**
|
|
15
|
+
* State lifecycle shared by all sync modes: connector/SDK state separation,
|
|
16
|
+
* fetch/init/post, the v1 to v2 migration shim, and the snap-in-version-gated
|
|
17
|
+
* initial domain mapping install. Subclasses seed the SDK-owned state.
|
|
18
|
+
*/
|
|
19
|
+
class BaseState {
|
|
20
|
+
constructor({ event, initialState }, initialSdkState) {
|
|
21
|
+
this._extractionScope = {};
|
|
22
|
+
this.event = event;
|
|
23
|
+
this.initialSdkState = initialSdkState;
|
|
24
|
+
this._connectorState = initialState;
|
|
25
|
+
this._sdkState = Object.assign({}, initialSdkState);
|
|
26
|
+
this.workerUrl = event.payload.event_context.worker_data_url;
|
|
27
|
+
this.devrevToken = event.context.secrets.service_account_token;
|
|
28
|
+
this.syncUnitId = event.payload.event_context.sync_unit_id;
|
|
29
|
+
this.requestId = event.payload.event_context.request_id_adaas;
|
|
30
|
+
}
|
|
31
|
+
/** Connector-owned state; what `adapter.state` exposes to snap-in code. */
|
|
32
|
+
get state() {
|
|
33
|
+
return this._connectorState;
|
|
34
|
+
}
|
|
35
|
+
set state(value) {
|
|
36
|
+
this._connectorState = value;
|
|
37
|
+
}
|
|
38
|
+
/** SDK-internal bookkeeping state. Never exposed to connector code. */
|
|
39
|
+
get sdkState() {
|
|
40
|
+
return this._sdkState;
|
|
41
|
+
}
|
|
42
|
+
set sdkState(value) {
|
|
43
|
+
this._sdkState = value;
|
|
44
|
+
}
|
|
45
|
+
get extractionScope() {
|
|
46
|
+
return this._extractionScope;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Installs the initial domain mapping when the snap-in version in state
|
|
50
|
+
* differs from the event context. Shared by all modes so a loading run still
|
|
51
|
+
* installs the mapping if extraction has not done so.
|
|
52
|
+
*/
|
|
53
|
+
async installInitialDomainMappingIfNeeded(initialDomainMapping) {
|
|
54
|
+
const snapInVersionId = this.event.context.snap_in_version_id;
|
|
55
|
+
const hasSnapInVersionInState = 'snapInVersionId' in this.sdkState;
|
|
56
|
+
const shouldUpdateIDM = !hasSnapInVersionInState ||
|
|
57
|
+
this.sdkState.snapInVersionId !== snapInVersionId;
|
|
58
|
+
if (!shouldUpdateIDM) {
|
|
59
|
+
console.log(`Snap-in version in state matches the version in event context "${snapInVersionId}". Skipping initial domain mapping installation.`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
console.log(`Snap-in version in state "${this.sdkState.snapInVersionId}" does not match the version in event context "${snapInVersionId}". Installing initial domain mapping.`);
|
|
64
|
+
if (initialDomainMapping) {
|
|
65
|
+
await (0, install_initial_domain_mapping_1.installInitialDomainMapping)(this.event, initialDomainMapping);
|
|
66
|
+
this.sdkState.snapInVersionId = snapInVersionId;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error('No initial domain mapping was passed to spawn function. Skipping initial domain mapping installation.');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const errorMessage = `Error while installing initial domain mapping. ${(0, logger_1.serializeError)(error)}`;
|
|
74
|
+
console.error(errorMessage);
|
|
75
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
76
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageFailed,
|
|
77
|
+
payload: { message: errorMessage },
|
|
78
|
+
});
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Fetches state from API, or creates the initial state on 404. Reads both
|
|
84
|
+
* the v2 envelope and a legacy flat v1 blob (migrated on read); always
|
|
85
|
+
* persists the v2 envelope going forward.
|
|
86
|
+
*/
|
|
87
|
+
async init(initialState) {
|
|
88
|
+
var _a;
|
|
89
|
+
try {
|
|
90
|
+
const { state: stringifiedState, objects } = await this.fetchState();
|
|
91
|
+
if (!stringifiedState) {
|
|
92
|
+
throw new Error('No state found in response.');
|
|
93
|
+
}
|
|
94
|
+
let parsed;
|
|
95
|
+
try {
|
|
96
|
+
parsed = JSON.parse(stringifiedState);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new Error(`Failed to parse state. ${error}`);
|
|
100
|
+
}
|
|
101
|
+
const { connectorState, sdkState } = this.normalizeFetchedState(parsed);
|
|
102
|
+
this.state = connectorState;
|
|
103
|
+
this.sdkState = sdkState;
|
|
104
|
+
console.log('State fetched successfully. Current state', {
|
|
105
|
+
connectorState: (0, logger_1.getPrintableState)(this.state),
|
|
106
|
+
sdkState: (0, logger_1.getPrintableState)(this.sdkState),
|
|
107
|
+
});
|
|
108
|
+
if (objects) {
|
|
109
|
+
try {
|
|
110
|
+
this._extractionScope = JSON.parse(objects);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.warn(`Failed to parse extractionScope. ${error}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
try {
|
|
119
|
+
if (!(axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404)) {
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
console.log('State not found. Initializing state with initial state.');
|
|
123
|
+
this.state = initialState;
|
|
124
|
+
this.sdkState = Object.assign({}, this.initialSdkState);
|
|
125
|
+
await this.postState();
|
|
126
|
+
}
|
|
127
|
+
catch (initError) {
|
|
128
|
+
const errorMessage = `Failed to init state. ${(0, logger_1.serializeError)(initError)}`;
|
|
129
|
+
console.error(errorMessage);
|
|
130
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
131
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageFailed,
|
|
132
|
+
payload: { message: errorMessage },
|
|
133
|
+
});
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Normalizes fetched state into the `{ connectorState, sdkState }` envelope.
|
|
140
|
+
* Versioned envelopes are read by `stateVersion`; unversioned ones (2.0.0
|
|
141
|
+
* betas) by their keys; anything else is a flat v1 blob split by
|
|
142
|
+
* `V1_SDK_STATE_KEYS`.
|
|
143
|
+
*/
|
|
144
|
+
normalizeFetchedState(parsed) {
|
|
145
|
+
if (parsed === null || typeof parsed !== 'object') {
|
|
146
|
+
throw new Error('Fetched state is not a JSON object.');
|
|
147
|
+
}
|
|
148
|
+
const record = parsed;
|
|
149
|
+
if (record.stateVersion !== undefined) {
|
|
150
|
+
if (record.stateVersion !== state_interfaces_1.STATE_VERSION) {
|
|
151
|
+
throw new Error(`Unsupported state version ${String(record.stateVersion)}; this SDK reads version ${state_interfaces_1.STATE_VERSION}.`);
|
|
152
|
+
}
|
|
153
|
+
return this.readEnvelope(record);
|
|
154
|
+
}
|
|
155
|
+
// Envelopes written by 2.0.0 betas carry no version marker.
|
|
156
|
+
if ('connectorState' in record || 'sdkState' in record) {
|
|
157
|
+
return this.readEnvelope(record);
|
|
158
|
+
}
|
|
159
|
+
// Legacy flat v1 blob: split known SDK keys out of the connector state.
|
|
160
|
+
const connectorState = {};
|
|
161
|
+
const sdkState = {};
|
|
162
|
+
for (const [key, value] of Object.entries(record)) {
|
|
163
|
+
if (state_interfaces_1.V1_SDK_STATE_KEYS.has(key)) {
|
|
164
|
+
sdkState[key] = value;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
connectorState[key] = value;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
connectorState: connectorState,
|
|
172
|
+
sdkState: Object.assign(Object.assign({}, this.initialSdkState), sdkState),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
readEnvelope(record) {
|
|
176
|
+
if (!('connectorState' in record) || !('sdkState' in record)) {
|
|
177
|
+
throw new Error('Malformed state envelope: expected both "connectorState" and "sdkState".');
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
connectorState: record.connectorState,
|
|
181
|
+
sdkState: Object.assign(Object.assign({}, this.initialSdkState), record.sdkState),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Posts the v2 envelope (connector and SDK state as they are now) to the
|
|
186
|
+
* API. Throws on failure so a caller can stop before a risky external write.
|
|
187
|
+
*/
|
|
188
|
+
async postState() {
|
|
189
|
+
const url = this.workerUrl + '.update';
|
|
190
|
+
const envelope = {
|
|
191
|
+
stateVersion: state_interfaces_1.STATE_VERSION,
|
|
192
|
+
connectorState: this.state,
|
|
193
|
+
sdkState: this.sdkState,
|
|
194
|
+
};
|
|
195
|
+
let stringifiedState;
|
|
196
|
+
try {
|
|
197
|
+
stringifiedState = JSON.stringify(envelope);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
throw new Error(`Failed to stringify state. ${(0, logger_1.serializeError)(error)}`);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
await client_1.axiosClient.post(url, {
|
|
204
|
+
state: stringifiedState,
|
|
205
|
+
}, {
|
|
206
|
+
headers: {
|
|
207
|
+
Authorization: this.devrevToken,
|
|
208
|
+
},
|
|
209
|
+
params: {
|
|
210
|
+
sync_unit: this.syncUnitId,
|
|
211
|
+
request_id: this.requestId,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
throw new Error(`Failed to update the state. ${(0, logger_1.serializeError)(error)}`);
|
|
217
|
+
}
|
|
218
|
+
console.log('State updated successfully to', {
|
|
219
|
+
connectorState: (0, logger_1.getPrintableState)(this.state),
|
|
220
|
+
sdkState: (0, logger_1.getPrintableState)(this.sdkState),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async fetchState() {
|
|
224
|
+
var _a, _b;
|
|
225
|
+
console.log(`Fetching state with sync unit id ${this.syncUnitId} and request id ${this.requestId}.`);
|
|
226
|
+
const url = this.workerUrl + '.get';
|
|
227
|
+
const response = await client_1.axiosClient.get(url, {
|
|
228
|
+
headers: {
|
|
229
|
+
Authorization: this.devrevToken,
|
|
230
|
+
},
|
|
231
|
+
params: {
|
|
232
|
+
sync_unit: this.syncUnitId,
|
|
233
|
+
request_id: this.requestId,
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
state: (_a = response.data) === null || _a === void 0 ? void 0 : _a.state,
|
|
238
|
+
objects: (_b = response.data) === null || _b === void 0 ? void 0 : _b.objects,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
exports.BaseState = BaseState;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseState } from './base-state';
|
|
2
|
+
import { StateInterface } from './state.interfaces';
|
|
3
|
+
/** State for extraction workers: seeds extraction SDK state and adds extraction-window resolution. */
|
|
4
|
+
export declare class ExtractionState<ConnectorState> extends BaseState<ConnectorState> {
|
|
5
|
+
constructor(params: StateInterface<ConnectorState>);
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the extraction window onto the event context. StartExtractingMetadata
|
|
8
|
+
* resolves fresh from the event's TimeValues and overwrites the pending boundaries;
|
|
9
|
+
* all other events reuse those cached boundaries. Validates extract_from < extract_to.
|
|
10
|
+
*/
|
|
11
|
+
resolveExtractionWindow(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function createExtractionState<ConnectorState>({ event, initialState, initialDomainMapping, options, }: StateInterface<ConnectorState>): Promise<ExtractionState<ConnectorState>>;
|
|
14
|
+
//# sourceMappingURL=extraction-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extraction-state.d.ts","sourceRoot":"","sources":["../../src/state/extraction-state.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAsB,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGxE,sGAAsG;AACtG,qBAAa,eAAe,CAAC,cAAc,CAAE,SAAQ,SAAS,CAAC,cAAc,CAAC;gBAChE,MAAM,EAAE,cAAc,CAAC,cAAc,CAAC;IAIlD;;;;OAIG;IACH,uBAAuB,IAAI,IAAI;CA4HhC;AAED,wBAAsB,qBAAqB,CAAC,cAAc,EAAE,EAC1D,KAAK,EACL,YAAY,EACZ,oBAAoB,EACpB,OAAO,GACR,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAkB3E"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtractionState = void 0;
|
|
4
|
+
exports.createExtractionState = createExtractionState;
|
|
5
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
6
|
+
const constants_1 = require("../common/constants");
|
|
7
|
+
const logger_1 = require("../logger/logger");
|
|
8
|
+
const extraction_1 = require("../types/extraction");
|
|
9
|
+
const workers_1 = require("../types/workers");
|
|
10
|
+
const base_state_1 = require("./base-state");
|
|
11
|
+
const state_interfaces_1 = require("./state.interfaces");
|
|
12
|
+
const time_value_resolver_1 = require("./time-value-resolver");
|
|
13
|
+
/** State for extraction workers: seeds extraction SDK state and adds extraction-window resolution. */
|
|
14
|
+
class ExtractionState extends base_state_1.BaseState {
|
|
15
|
+
constructor(params) {
|
|
16
|
+
super(params, state_interfaces_1.extractionSdkState);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the extraction window onto the event context. StartExtractingMetadata
|
|
20
|
+
* resolves fresh from the event's TimeValues and overwrites the pending boundaries;
|
|
21
|
+
* all other events reuse those cached boundaries. Validates extract_from < extract_to.
|
|
22
|
+
*/
|
|
23
|
+
resolveExtractionWindow() {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const sdkState = this.sdkState;
|
|
26
|
+
const eventContext = this.event.payload.event_context;
|
|
27
|
+
const overrideExtractFrom = (value) => {
|
|
28
|
+
if (eventContext.extract_from !== undefined) {
|
|
29
|
+
eventContext.original_extract_from = eventContext.extract_from;
|
|
30
|
+
}
|
|
31
|
+
eventContext.extract_from = value;
|
|
32
|
+
};
|
|
33
|
+
if (this.event.payload.event_type === extraction_1.EventType.StartExtractingData) {
|
|
34
|
+
if (!sdkState.lastSyncStarted) {
|
|
35
|
+
sdkState.lastSyncStarted = new Date().toISOString();
|
|
36
|
+
console.log(`Setting lastSyncStarted to ${sdkState.lastSyncStarted}.`);
|
|
37
|
+
}
|
|
38
|
+
// A sync that failed before attachments must not leak its SSOR records into this one.
|
|
39
|
+
if ((_b = (_a = sdkState.toDevRev) === null || _a === void 0 ? void 0 : _a.deferredSsorArtifacts) === null || _b === void 0 ? void 0 : _b.length) {
|
|
40
|
+
sdkState.toDevRev.deferredSsorArtifacts = [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (this.event.payload.event_type === extraction_1.EventType.StartExtractingMetadata) {
|
|
44
|
+
const timeFields = [
|
|
45
|
+
{
|
|
46
|
+
source: 'extraction_start_time',
|
|
47
|
+
target: 'extract_from',
|
|
48
|
+
pending: 'pendingWorkersOldest',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
source: 'extraction_end_time',
|
|
52
|
+
target: 'extract_to',
|
|
53
|
+
pending: 'pendingWorkersNewest',
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
for (const { source, target, pending } of timeFields) {
|
|
57
|
+
const timeValue = eventContext[source];
|
|
58
|
+
if (timeValue && timeValue.type) {
|
|
59
|
+
try {
|
|
60
|
+
const resolved = (0, time_value_resolver_1.resolveTimeValue)(timeValue, sdkState);
|
|
61
|
+
if (target === 'extract_from') {
|
|
62
|
+
overrideExtractFrom(resolved);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
eventContext[target] = resolved;
|
|
66
|
+
}
|
|
67
|
+
sdkState[pending] = resolved;
|
|
68
|
+
console.log(`Resolved ${target} to ${resolved}. Stored in ${pending}.`);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const errorMessage = `Failed to resolve ${source}: ${(0, logger_1.serializeError)(error)}`;
|
|
72
|
+
console.error(errorMessage);
|
|
73
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
74
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageFailed,
|
|
75
|
+
payload: { message: errorMessage },
|
|
76
|
+
});
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (target === 'extract_from') {
|
|
81
|
+
// Non-CPv2 platforms send no TimeValue: prefer the last successful
|
|
82
|
+
// sync start, else the extract_from the platform supplied directly.
|
|
83
|
+
const fallback = sdkState.lastSuccessfulSyncStarted || eventContext.extract_from;
|
|
84
|
+
if (fallback) {
|
|
85
|
+
if (sdkState.lastSuccessfulSyncStarted) {
|
|
86
|
+
overrideExtractFrom(fallback);
|
|
87
|
+
}
|
|
88
|
+
sdkState.pendingWorkersOldest = fallback;
|
|
89
|
+
console.log(`Using ${sdkState.lastSuccessfulSyncStarted
|
|
90
|
+
? 'lastSuccessfulSyncStarted'
|
|
91
|
+
: 'platform-provided extract_from'} as extract_from: ${fallback}. Stored in pendingWorkersOldest.`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const pendingExtractFrom = sdkState.pendingWorkersOldest || sdkState.lastSuccessfulSyncStarted;
|
|
98
|
+
if (pendingExtractFrom) {
|
|
99
|
+
if (eventContext.extract_from !== pendingExtractFrom) {
|
|
100
|
+
overrideExtractFrom(pendingExtractFrom);
|
|
101
|
+
}
|
|
102
|
+
console.log(`Using ${sdkState.pendingWorkersOldest
|
|
103
|
+
? 'pendingWorkersOldest'
|
|
104
|
+
: 'lastSuccessfulSyncStarted'} as extract_from: ${pendingExtractFrom}.`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
console.log('pendingWorkersOldest is not set in state. extract_from will not be populated for this invocation.');
|
|
108
|
+
}
|
|
109
|
+
if (sdkState.pendingWorkersNewest) {
|
|
110
|
+
eventContext.extract_to = sdkState.pendingWorkersNewest;
|
|
111
|
+
console.log(`Reusing pendingWorkersNewest as extract_to: ${sdkState.pendingWorkersNewest}.`);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.log('pendingWorkersNewest is not set in state. extract_to will not be populated for this invocation.');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (eventContext.extract_from && eventContext.extract_to) {
|
|
118
|
+
if (eventContext.extract_from >= eventContext.extract_to) {
|
|
119
|
+
const errorMessage = `Invalid extraction window: extract_from (${eventContext.extract_from}) must be older than extract_to (${eventContext.extract_to}). This indicates an error in the platform.`;
|
|
120
|
+
console.error(errorMessage);
|
|
121
|
+
node_worker_threads_1.parentPort === null || node_worker_threads_1.parentPort === void 0 ? void 0 : node_worker_threads_1.parentPort.postMessage({
|
|
122
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageFailed,
|
|
123
|
+
payload: { message: errorMessage },
|
|
124
|
+
});
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.ExtractionState = ExtractionState;
|
|
131
|
+
async function createExtractionState({ event, initialState, initialDomainMapping, options, }) {
|
|
132
|
+
// Clone so the caller's initialState is never mutated.
|
|
133
|
+
const deepCloneInitialState = structuredClone(initialState);
|
|
134
|
+
const state = new ExtractionState({
|
|
135
|
+
event,
|
|
136
|
+
initialState: deepCloneInitialState,
|
|
137
|
+
initialDomainMapping,
|
|
138
|
+
options,
|
|
139
|
+
});
|
|
140
|
+
if (!constants_1.STATELESS_EVENT_TYPES.includes(event.payload.event_type)) {
|
|
141
|
+
await state.init(deepCloneInitialState);
|
|
142
|
+
await state.installInitialDomainMappingIfNeeded(initialDomainMapping);
|
|
143
|
+
state.resolveExtractionWindow();
|
|
144
|
+
}
|
|
145
|
+
return state;
|
|
146
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InitialDomainMapping } from '../types/common';
|
|
2
|
+
import { AirSyncEvent } from '../types/extraction';
|
|
3
|
+
export declare function installInitialDomainMapping(event: AirSyncEvent, initialDomainMappingJson: InitialDomainMapping): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=install-initial-domain-mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-initial-domain-mapping.d.ts","sourceRoot":"","sources":["../../src/state/install-initial-domain-mapping.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,wBAAsB,2BAA2B,CAC/C,KAAK,EAAE,YAAY,EACnB,wBAAwB,EAAE,oBAAoB,GAC7C,OAAO,CAAC,IAAI,CAAC,CAwFf"}
|