@devrev/airsync-sdk 2.0.0-beta.4 → 2.0.0-beta.5
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/MIGRATION.md +1028 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts +6 -0
- package/dist/attachments-streaming/attachments-streaming-pool.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts +2 -2
- package/dist/attachments-streaming/attachments-streaming-pool.interfaces.d.ts.map +1 -1
- package/dist/attachments-streaming/attachments-streaming-pool.js +47 -21
- package/dist/common/constants.d.ts +3 -5
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +4 -6
- package/dist/common/helpers.d.ts +3 -21
- package/dist/common/helpers.d.ts.map +1 -1
- package/dist/common/helpers.js +6 -15
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +4 -8
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -18
- package/dist/logger/logger.d.ts +8 -63
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +0 -1
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +14 -93
- package/dist/mappers/mappers.d.ts +2 -40
- package/dist/mappers/mappers.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.d.ts +35 -154
- package/dist/mappers/mappers.interfaces.d.ts.map +1 -1
- package/dist/mappers/mappers.interfaces.js +1 -10
- package/dist/mappers/mappers.js +2 -40
- package/dist/multithreading/adapters/base-adapter.d.ts +19 -36
- package/dist/multithreading/adapters/base-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/base-adapter.js +73 -71
- package/dist/multithreading/adapters/extraction-adapter.d.ts +12 -24
- package/dist/multithreading/adapters/extraction-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/extraction-adapter.js +199 -200
- package/dist/multithreading/adapters/loading-adapter.d.ts +1 -6
- package/dist/multithreading/adapters/loading-adapter.d.ts.map +1 -1
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts +2 -12
- package/dist/multithreading/adapters/loading-adapter.helpers.d.ts.map +1 -1
- package/dist/multithreading/adapters/loading-adapter.helpers.js +2 -12
- package/dist/multithreading/adapters/loading-adapter.js +292 -314
- package/dist/multithreading/emit.d.ts +3 -2
- package/dist/multithreading/emit.d.ts.map +1 -1
- package/dist/multithreading/emit.js +3 -5
- package/dist/multithreading/process-task.d.ts +2 -12
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +45 -59
- package/dist/multithreading/spawn/spawn.d.ts +3 -9
- package/dist/multithreading/spawn/spawn.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.d.ts +6 -25
- package/dist/multithreading/spawn/spawn.helpers.d.ts.map +1 -1
- package/dist/multithreading/spawn/spawn.helpers.js +7 -49
- package/dist/multithreading/spawn/spawn.js +18 -33
- package/dist/multithreading/worker.js +2 -4
- package/dist/repo/repo.d.ts +10 -0
- 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 +4 -16
- package/dist/repo/repo.interfaces.d.ts.map +1 -1
- package/dist/repo/repo.js +23 -8
- package/dist/state/base-state.d.ts +14 -36
- package/dist/state/base-state.d.ts.map +1 -1
- package/dist/state/base-state.js +16 -38
- package/dist/state/extraction-state.d.ts +4 -19
- package/dist/state/extraction-state.d.ts.map +1 -1
- package/dist/state/extraction-state.js +6 -23
- package/dist/state/install-initial-domain-mapping.d.ts +1 -1
- package/dist/state/install-initial-domain-mapping.d.ts.map +1 -1
- package/dist/state/install-initial-domain-mapping.js +1 -3
- package/dist/state/loading-state.d.ts +1 -11
- package/dist/state/loading-state.d.ts.map +1 -1
- package/dist/state/loading-state.js +2 -12
- package/dist/state/state.d.ts +2 -2
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.interfaces.d.ts +10 -24
- package/dist/state/state.interfaces.d.ts.map +1 -1
- package/dist/state/state.interfaces.js +9 -11
- package/dist/state/state.js +3 -3
- package/dist/state/time-value-resolver.d.ts +7 -36
- package/dist/state/time-value-resolver.d.ts.map +1 -1
- package/dist/state/time-value-resolver.js +7 -40
- package/dist/testing/mock-event.d.ts +2 -10
- package/dist/testing/mock-event.d.ts.map +1 -1
- package/dist/testing/mock-event.js +3 -11
- package/dist/testing/mock-server.d.ts +4 -27
- package/dist/testing/mock-server.d.ts.map +1 -1
- package/dist/testing/mock-server.interfaces.d.ts +10 -35
- package/dist/testing/mock-server.interfaces.d.ts.map +1 -1
- package/dist/testing/mock-server.js +19 -36
- package/dist/types/common.d.ts +1 -12
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +1 -6
- package/dist/types/external-domain-metadata.d.ts +30 -171
- package/dist/types/external-domain-metadata.d.ts.map +1 -1
- package/dist/types/extraction.d.ts +35 -120
- package/dist/types/extraction.d.ts.map +1 -1
- package/dist/types/extraction.js +5 -31
- package/dist/types/loading.d.ts.map +1 -1
- package/dist/types/workers.d.ts +18 -116
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/types/workers.js +0 -6
- package/dist/uploader/uploader.d.ts +6 -58
- package/dist/uploader/uploader.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.d.ts +4 -27
- package/dist/uploader/uploader.helpers.d.ts.map +1 -1
- package/dist/uploader/uploader.helpers.js +64 -30
- package/dist/uploader/uploader.interfaces.d.ts +15 -25
- package/dist/uploader/uploader.interfaces.d.ts.map +1 -1
- package/dist/uploader/uploader.interfaces.js +8 -0
- package/dist/uploader/uploader.js +18 -84
- package/package.json +6 -4
|
@@ -12,12 +12,7 @@ const extraction_1 = require("../../types/extraction");
|
|
|
12
12
|
const loading_1 = require("../../types/loading");
|
|
13
13
|
const base_adapter_1 = require("./base-adapter");
|
|
14
14
|
const loading_adapter_helpers_1 = require("./loading-adapter.helpers");
|
|
15
|
-
/**
|
|
16
|
-
* LoadingAdapter is the adapter passed to loading tasks. It exposes the loading
|
|
17
|
-
* surface (item/attachment loading, mappers, loader reports).
|
|
18
|
-
*
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
15
|
+
/** Adapter passed to loading tasks (item/attachment loading, mappers, loader reports). @public */
|
|
21
16
|
class LoadingAdapter extends base_adapter_1.BaseAdapter {
|
|
22
17
|
constructor(params) {
|
|
23
18
|
super(params);
|
|
@@ -38,7 +33,7 @@ class LoadingAdapter extends base_adapter_1.BaseAdapter {
|
|
|
38
33
|
return this._mappers;
|
|
39
34
|
}
|
|
40
35
|
async beforeEmit() {
|
|
41
|
-
// Loading has no pre-emit work
|
|
36
|
+
// Loading has no pre-emit work.
|
|
42
37
|
}
|
|
43
38
|
buildEmitPayload(newEventType) {
|
|
44
39
|
const isLoaderEvent = Object.values(loading_1.LoaderEventType).includes(newEventType);
|
|
@@ -53,379 +48,362 @@ class LoadingAdapter extends base_adapter_1.BaseAdapter {
|
|
|
53
48
|
// Loading keeps its accumulated reports/processed files across emits.
|
|
54
49
|
}
|
|
55
50
|
async loadItemTypes({ itemTypesToLoad, }) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
console.warn('No item types to load, returning.');
|
|
62
|
-
return { status: 'success' };
|
|
63
|
-
}
|
|
64
|
-
const filesToLoad = await this.getLoaderBatches({
|
|
65
|
-
supportedItemTypes: itemTypes,
|
|
66
|
-
});
|
|
67
|
-
this.sdkState.fromDevRev = {
|
|
68
|
-
filesToLoad,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (!this.sdkState.fromDevRev ||
|
|
72
|
-
!this.sdkState.fromDevRev.filesToLoad.length) {
|
|
73
|
-
console.warn('No files to load, returning.');
|
|
51
|
+
var _a;
|
|
52
|
+
if (this.event.payload.event_type === extraction_1.EventType.StartLoadingData) {
|
|
53
|
+
const itemTypes = itemTypesToLoad.map((itemTypeToLoad) => itemTypeToLoad.itemType);
|
|
54
|
+
if (!itemTypes.length) {
|
|
55
|
+
console.warn('No item types to load, returning.');
|
|
74
56
|
return { status: 'success' };
|
|
75
57
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
58
|
+
const filesToLoad = await this.getLoaderBatches({
|
|
59
|
+
supportedItemTypes: itemTypes,
|
|
60
|
+
});
|
|
61
|
+
this.sdkState.fromDevRev = {
|
|
62
|
+
filesToLoad,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (!this.sdkState.fromDevRev ||
|
|
66
|
+
!this.sdkState.fromDevRev.filesToLoad.length) {
|
|
67
|
+
console.warn('No files to load, returning.');
|
|
68
|
+
return { status: 'success' };
|
|
69
|
+
}
|
|
70
|
+
console.log('Files to load in state', (_a = this.sdkState.fromDevRev) === null || _a === void 0 ? void 0 : _a.filesToLoad);
|
|
71
|
+
try {
|
|
72
|
+
for (const fileToLoad of this.sdkState.fromDevRev.filesToLoad) {
|
|
73
|
+
const itemTypeToLoad = itemTypesToLoad.find((itemTypeToLoad) => itemTypeToLoad.itemType === fileToLoad.itemType);
|
|
74
|
+
if (!itemTypeToLoad) {
|
|
75
|
+
console.error(`Item type to load not found for item type: ${fileToLoad.itemType}.`);
|
|
76
|
+
return {
|
|
77
|
+
status: 'error',
|
|
78
|
+
error: {
|
|
79
|
+
message: `Item type to load not found for item type: ${fileToLoad.itemType}.`,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (!fileToLoad.completed) {
|
|
84
|
+
const { response, error: transformerFileError } = await this.uploader.getJsonObjectByArtifactId({
|
|
85
|
+
artifactId: fileToLoad.id,
|
|
86
|
+
isGzipped: true,
|
|
87
|
+
});
|
|
88
|
+
if (transformerFileError) {
|
|
89
|
+
console.error(`Transformer file not found for artifact ID: ${fileToLoad.id}.`);
|
|
82
90
|
return {
|
|
83
91
|
status: 'error',
|
|
84
92
|
error: {
|
|
85
|
-
message: `
|
|
93
|
+
message: `Transformer file not found for artifact ID: ${fileToLoad.id}.`,
|
|
86
94
|
},
|
|
87
95
|
};
|
|
88
96
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
const transformerFile = response;
|
|
98
|
+
for (let i = fileToLoad.lineToProcess; i < fileToLoad.count; i++) {
|
|
99
|
+
if (this.isTimeout) {
|
|
100
|
+
console.log('Timeout detected during data loading. Returning progress to allow continuation.');
|
|
101
|
+
return { status: 'progress' };
|
|
102
|
+
}
|
|
103
|
+
const { report, rateLimit } = await this.loadItem({
|
|
104
|
+
item: transformerFile[i],
|
|
105
|
+
itemTypeToLoad,
|
|
93
106
|
});
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
status: 'error',
|
|
98
|
-
error: {
|
|
99
|
-
message: `Transformer file not found for artifact ID: ${fileToLoad.id}.`,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
107
|
+
if (rateLimit === null || rateLimit === void 0 ? void 0 : rateLimit.delay) {
|
|
108
|
+
return { status: 'delay', delaySeconds: rateLimit.delay };
|
|
102
109
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return { status: 'progress' };
|
|
108
|
-
}
|
|
109
|
-
const { report, rateLimit } = await this.loadItem({
|
|
110
|
-
item: transformerFile[i],
|
|
111
|
-
itemTypeToLoad,
|
|
110
|
+
if (report) {
|
|
111
|
+
(0, loading_adapter_helpers_1.addReportToLoaderReport)({
|
|
112
|
+
loaderReports: this.loaderReports,
|
|
113
|
+
report,
|
|
112
114
|
});
|
|
113
|
-
|
|
114
|
-
return { status: 'delay', delaySeconds: rateLimit.delay };
|
|
115
|
-
}
|
|
116
|
-
if (report) {
|
|
117
|
-
(0, loading_adapter_helpers_1.addReportToLoaderReport)({
|
|
118
|
-
loaderReports: this.loaderReports,
|
|
119
|
-
report,
|
|
120
|
-
});
|
|
121
|
-
fileToLoad.lineToProcess = fileToLoad.lineToProcess + 1;
|
|
122
|
-
}
|
|
115
|
+
fileToLoad.lineToProcess = fileToLoad.lineToProcess + 1;
|
|
123
116
|
}
|
|
124
|
-
fileToLoad.completed = true;
|
|
125
|
-
this._processedFiles.push(fileToLoad.id);
|
|
126
117
|
}
|
|
118
|
+
fileToLoad.completed = true;
|
|
119
|
+
this._processedFiles.push(fileToLoad.id);
|
|
127
120
|
}
|
|
128
121
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('Error during data loading.', (0, logger_1.serializeError)(error));
|
|
125
|
+
return {
|
|
126
|
+
status: 'error',
|
|
127
|
+
error: {
|
|
128
|
+
message: `Error during data loading. ${(0, logger_1.serializeError)(error)}`,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return { status: 'success' };
|
|
140
133
|
}
|
|
141
134
|
async getLoaderBatches({ supportedItemTypes, }) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return [];
|
|
152
|
-
}
|
|
153
|
-
const filesToLoad = (0, loading_adapter_helpers_1.getFilesToLoad)({
|
|
154
|
-
supportedItemTypes,
|
|
155
|
-
statsFile,
|
|
156
|
-
});
|
|
157
|
-
return filesToLoad;
|
|
135
|
+
var _a;
|
|
136
|
+
const statsFileArtifactId = (_a = this.event.payload.event_data) === null || _a === void 0 ? void 0 : _a.stats_file;
|
|
137
|
+
if (statsFileArtifactId) {
|
|
138
|
+
const { response, error: statsFileError } = await this.uploader.getJsonObjectByArtifactId({
|
|
139
|
+
artifactId: statsFileArtifactId,
|
|
140
|
+
});
|
|
141
|
+
const statsFile = response;
|
|
142
|
+
if (statsFileError || statsFile.length === 0) {
|
|
143
|
+
return [];
|
|
158
144
|
}
|
|
159
|
-
|
|
160
|
-
|
|
145
|
+
const filesToLoad = (0, loading_adapter_helpers_1.getFilesToLoad)({
|
|
146
|
+
supportedItemTypes,
|
|
147
|
+
statsFile,
|
|
148
|
+
});
|
|
149
|
+
return filesToLoad;
|
|
150
|
+
}
|
|
151
|
+
return [];
|
|
161
152
|
}
|
|
162
153
|
async loadAttachments({ create, }) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
154
|
+
var _a, _b;
|
|
155
|
+
if (this.event.payload.event_type === extraction_1.EventType.StartLoadingAttachments) {
|
|
156
|
+
this.sdkState.fromDevRev = {
|
|
157
|
+
filesToLoad: await this.getLoaderBatches({
|
|
158
|
+
supportedItemTypes: ['attachment'],
|
|
159
|
+
}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (!this.sdkState.fromDevRev ||
|
|
163
|
+
((_a = this.sdkState.fromDevRev) === null || _a === void 0 ? void 0 : _a.filesToLoad.length) === 0) {
|
|
164
|
+
console.log('No files to load, returning.');
|
|
165
|
+
return { status: 'success' };
|
|
166
|
+
}
|
|
167
|
+
const filesToLoad = (_b = this.sdkState.fromDevRev) === null || _b === void 0 ? void 0 : _b.filesToLoad;
|
|
168
|
+
try {
|
|
169
|
+
for (const fileToLoad of filesToLoad) {
|
|
170
|
+
if (!fileToLoad.completed) {
|
|
171
|
+
const { response, error: transformerFileError } = await this.uploader.getJsonObjectByArtifactId({
|
|
172
|
+
artifactId: fileToLoad.id,
|
|
173
|
+
isGzipped: true,
|
|
174
|
+
});
|
|
175
|
+
const transformerFile = response;
|
|
176
|
+
if (transformerFileError) {
|
|
177
|
+
console.error(`Transformer file not found for artifact ID: ${fileToLoad.id}.`);
|
|
178
|
+
return {
|
|
179
|
+
status: 'error',
|
|
180
|
+
error: {
|
|
181
|
+
message: `Transformer file not found for artifact ID: ${fileToLoad.id}.`,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
for (let i = fileToLoad.lineToProcess; i < fileToLoad.count; i++) {
|
|
186
|
+
if (this.isTimeout) {
|
|
187
|
+
console.log('Timeout detected during attachment loading. Returning progress to allow continuation.');
|
|
188
|
+
return { status: 'progress' };
|
|
189
|
+
}
|
|
190
|
+
const { report, rateLimit } = await this.loadAttachment({
|
|
191
|
+
item: transformerFile[i],
|
|
192
|
+
create,
|
|
184
193
|
});
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
console.error(`Transformer file not found for artifact ID: ${fileToLoad.id}.`);
|
|
188
|
-
return {
|
|
189
|
-
status: 'error',
|
|
190
|
-
error: {
|
|
191
|
-
message: `Transformer file not found for artifact ID: ${fileToLoad.id}.`,
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
+
if (rateLimit === null || rateLimit === void 0 ? void 0 : rateLimit.delay) {
|
|
195
|
+
return { status: 'delay', delaySeconds: rateLimit.delay };
|
|
194
196
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
const { report, rateLimit } = await this.loadAttachment({
|
|
201
|
-
item: transformerFile[i],
|
|
202
|
-
create,
|
|
197
|
+
if (report) {
|
|
198
|
+
(0, loading_adapter_helpers_1.addReportToLoaderReport)({
|
|
199
|
+
loaderReports: this.loaderReports,
|
|
200
|
+
report,
|
|
203
201
|
});
|
|
204
|
-
|
|
205
|
-
return { status: 'delay', delaySeconds: rateLimit.delay };
|
|
206
|
-
}
|
|
207
|
-
if (report) {
|
|
208
|
-
(0, loading_adapter_helpers_1.addReportToLoaderReport)({
|
|
209
|
-
loaderReports: this.loaderReports,
|
|
210
|
-
report,
|
|
211
|
-
});
|
|
212
|
-
fileToLoad.lineToProcess = fileToLoad.lineToProcess + 1;
|
|
213
|
-
}
|
|
202
|
+
fileToLoad.lineToProcess = fileToLoad.lineToProcess + 1;
|
|
214
203
|
}
|
|
215
|
-
fileToLoad.completed = true;
|
|
216
|
-
this._processedFiles.push(fileToLoad.id);
|
|
217
204
|
}
|
|
205
|
+
fileToLoad.completed = true;
|
|
206
|
+
this._processedFiles.push(fileToLoad.id);
|
|
218
207
|
}
|
|
219
208
|
}
|
|
220
|
-
|
|
221
|
-
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
console.error('Error during attachment loading.', (0, logger_1.serializeError)(error));
|
|
212
|
+
return {
|
|
213
|
+
status: 'error',
|
|
214
|
+
error: {
|
|
215
|
+
message: `Error during attachment loading. ${(0, logger_1.serializeError)(error)}`,
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return { status: 'success' };
|
|
220
|
+
}
|
|
221
|
+
async loadItem({ item, itemTypeToLoad, }) {
|
|
222
|
+
var _a;
|
|
223
|
+
const devrevId = item.id.devrev;
|
|
224
|
+
try {
|
|
225
|
+
const syncMapperRecord = await this._mappers.getByTargetId({
|
|
226
|
+
sync_unit: this.event.payload.event_context.sync_unit,
|
|
227
|
+
target: devrevId,
|
|
228
|
+
});
|
|
229
|
+
if (!syncMapperRecord) {
|
|
230
|
+
console.warn('Failed to get sync mapper record from response.');
|
|
222
231
|
return {
|
|
223
|
-
status: 'error',
|
|
224
232
|
error: {
|
|
225
|
-
message:
|
|
233
|
+
message: 'Failed to get sync mapper record from response.',
|
|
226
234
|
},
|
|
227
235
|
};
|
|
228
236
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
237
|
+
const { id, modifiedDate, delay, error } = await itemTypeToLoad.update({
|
|
238
|
+
item,
|
|
239
|
+
mappers: this._mappers,
|
|
240
|
+
event: this.event,
|
|
241
|
+
});
|
|
242
|
+
if (id) {
|
|
243
|
+
try {
|
|
244
|
+
const syncMapperRecordUpdate = await this._mappers.update(Object.assign(Object.assign({ id: syncMapperRecord.sync_mapper_record.id, sync_unit: this.event.payload.event_context.sync_unit, status: mappers_interfaces_1.SyncMapperRecordStatus.OPERATIONAL }, (modifiedDate && {
|
|
245
|
+
external_versions: {
|
|
246
|
+
add: [
|
|
247
|
+
{
|
|
248
|
+
modified_date: modifiedDate,
|
|
249
|
+
recipe_version: 0,
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
})), { external_ids: {
|
|
254
|
+
add: [id],
|
|
255
|
+
}, targets: {
|
|
256
|
+
add: [devrevId],
|
|
257
|
+
} }));
|
|
258
|
+
console.log('Successfully updated sync mapper record.', syncMapperRecordUpdate);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.warn('Failed to update sync mapper record.', (0, logger_1.serializeError)(error));
|
|
243
262
|
return {
|
|
244
263
|
error: {
|
|
245
|
-
message: 'Failed to
|
|
264
|
+
message: 'Failed to update sync mapper record' + (0, logger_1.serializeError)(error),
|
|
246
265
|
},
|
|
247
266
|
};
|
|
248
267
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
268
|
+
return {
|
|
269
|
+
report: {
|
|
270
|
+
item_type: itemTypeToLoad.itemType,
|
|
271
|
+
[loading_1.ActionType.UPDATED]: 1,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
else if (delay) {
|
|
276
|
+
console.log(`Rate limited while updating item in external system, delaying for ${delay} seconds.`);
|
|
277
|
+
return {
|
|
278
|
+
rateLimit: {
|
|
279
|
+
delay,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
console.warn('Failed to update item in external system', error);
|
|
285
|
+
return {
|
|
286
|
+
report: {
|
|
287
|
+
item_type: itemTypeToLoad.itemType,
|
|
288
|
+
[loading_1.ActionType.FAILED]: 1,
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
// TODO: Update mapper (optional)
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
296
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
297
|
+
// Create item in external system if mapper record not found
|
|
298
|
+
const { id, modifiedDate, delay, error } = await itemTypeToLoad.create({
|
|
252
299
|
item,
|
|
253
300
|
mappers: this._mappers,
|
|
254
301
|
event: this.event,
|
|
255
302
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
external_versions: {
|
|
261
|
-
add: [
|
|
303
|
+
if (id) {
|
|
304
|
+
try {
|
|
305
|
+
const syncMapperRecordCreate = await this._mappers.create(Object.assign({ sync_unit: this.event.payload.event_context.sync_unit, status: mappers_interfaces_1.SyncMapperRecordStatus.OPERATIONAL, external_ids: [id], targets: [devrevId] }, (modifiedDate && {
|
|
306
|
+
external_versions: [
|
|
262
307
|
{
|
|
263
308
|
modified_date: modifiedDate,
|
|
264
309
|
recipe_version: 0,
|
|
265
310
|
},
|
|
266
311
|
],
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
add: [id],
|
|
270
|
-
}, targets: {
|
|
271
|
-
add: [devrevId],
|
|
272
|
-
} }));
|
|
273
|
-
console.log('Successfully updated sync mapper record.', syncMapperRecordUpdate);
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
console.warn('Failed to update sync mapper record.', (0, logger_1.serializeError)(error));
|
|
277
|
-
return {
|
|
278
|
-
error: {
|
|
279
|
-
message: 'Failed to update sync mapper record' + (0, logger_1.serializeError)(error),
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
report: {
|
|
285
|
-
item_type: itemTypeToLoad.itemType,
|
|
286
|
-
[loading_1.ActionType.UPDATED]: 1,
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
else if (delay) {
|
|
291
|
-
console.log(`Rate limited while updating item in external system, delaying for ${delay} seconds.`);
|
|
292
|
-
return {
|
|
293
|
-
rateLimit: {
|
|
294
|
-
delay,
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
console.warn('Failed to update item in external system', error);
|
|
300
|
-
return {
|
|
301
|
-
report: {
|
|
302
|
-
item_type: itemTypeToLoad.itemType,
|
|
303
|
-
[loading_1.ActionType.FAILED]: 1,
|
|
304
|
-
},
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
// TODO: Update mapper (optional)
|
|
308
|
-
}
|
|
309
|
-
catch (error) {
|
|
310
|
-
if (axios_1.default.isAxiosError(error)) {
|
|
311
|
-
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
312
|
-
// Create item in external system if mapper record not found
|
|
313
|
-
const { id, modifiedDate, delay, error } = await (0, logger_1.runWithUserLogContext)(async () => {
|
|
314
|
-
return await itemTypeToLoad.create({
|
|
315
|
-
item,
|
|
316
|
-
mappers: this._mappers,
|
|
317
|
-
event: this.event,
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
if (id) {
|
|
321
|
-
// Create mapper
|
|
322
|
-
try {
|
|
323
|
-
const syncMapperRecordCreate = await this._mappers.create(Object.assign({ sync_unit: this.event.payload.event_context.sync_unit, status: mappers_interfaces_1.SyncMapperRecordStatus.OPERATIONAL, external_ids: [id], targets: [devrevId] }, (modifiedDate && {
|
|
324
|
-
external_versions: [
|
|
325
|
-
{
|
|
326
|
-
modified_date: modifiedDate,
|
|
327
|
-
recipe_version: 0,
|
|
328
|
-
},
|
|
329
|
-
],
|
|
330
|
-
})));
|
|
331
|
-
console.log('Successfully created sync mapper record.', syncMapperRecordCreate);
|
|
332
|
-
return {
|
|
333
|
-
report: {
|
|
334
|
-
item_type: itemTypeToLoad.itemType,
|
|
335
|
-
[loading_1.ActionType.CREATED]: 1,
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
catch (error) {
|
|
340
|
-
console.warn('Failed to create sync mapper record.', (0, logger_1.serializeError)(error));
|
|
341
|
-
return {
|
|
342
|
-
error: {
|
|
343
|
-
message: 'Failed to create sync mapper record. ' +
|
|
344
|
-
(0, logger_1.serializeError)(error),
|
|
345
|
-
},
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
else if (delay) {
|
|
312
|
+
})));
|
|
313
|
+
console.log('Successfully created sync mapper record.', syncMapperRecordCreate);
|
|
350
314
|
return {
|
|
351
|
-
|
|
352
|
-
|
|
315
|
+
report: {
|
|
316
|
+
item_type: itemTypeToLoad.itemType,
|
|
317
|
+
[loading_1.ActionType.CREATED]: 1,
|
|
353
318
|
},
|
|
354
319
|
};
|
|
355
320
|
}
|
|
356
|
-
|
|
357
|
-
console.warn('Failed to create
|
|
321
|
+
catch (error) {
|
|
322
|
+
console.warn('Failed to create sync mapper record.', (0, logger_1.serializeError)(error));
|
|
358
323
|
return {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
324
|
+
error: {
|
|
325
|
+
message: 'Failed to create sync mapper record. ' +
|
|
326
|
+
(0, logger_1.serializeError)(error),
|
|
362
327
|
},
|
|
363
328
|
};
|
|
364
329
|
}
|
|
365
330
|
}
|
|
331
|
+
else if (delay) {
|
|
332
|
+
return {
|
|
333
|
+
rateLimit: {
|
|
334
|
+
delay,
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
}
|
|
366
338
|
else {
|
|
367
|
-
console.warn('Failed to
|
|
339
|
+
console.warn('Failed to create item in external system.', (0, logger_1.serializeError)(error));
|
|
368
340
|
return {
|
|
369
|
-
|
|
370
|
-
|
|
341
|
+
report: {
|
|
342
|
+
item_type: itemTypeToLoad.itemType,
|
|
343
|
+
[loading_1.ActionType.FAILED]: 1,
|
|
371
344
|
},
|
|
372
345
|
};
|
|
373
346
|
}
|
|
374
347
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
348
|
+
else {
|
|
349
|
+
console.warn('Failed to get sync mapper record.', (0, logger_1.serializeError)(error));
|
|
350
|
+
return {
|
|
351
|
+
error: {
|
|
352
|
+
message: error.message,
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
}
|
|
381
356
|
}
|
|
382
|
-
|
|
357
|
+
console.warn('Failed to get sync mapper record.', (0, logger_1.serializeError)(error));
|
|
358
|
+
return {
|
|
359
|
+
error: {
|
|
360
|
+
message: 'Failed to get sync mapper record. ' + (0, logger_1.serializeError)(error),
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
}
|
|
383
364
|
}
|
|
384
365
|
async loadAttachment({ item, create, }) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
});
|
|
407
|
-
console.log('Successfully created sync mapper record.', syncMapperRecordCreate);
|
|
408
|
-
}
|
|
409
|
-
catch (error) {
|
|
410
|
-
console.warn('Failed to create sync mapper record.', (0, logger_1.serializeError)(error));
|
|
411
|
-
}
|
|
412
|
-
return {
|
|
413
|
-
report: {
|
|
414
|
-
item_type: 'attachment',
|
|
415
|
-
[loading_1.ActionType.CREATED]: 1,
|
|
416
|
-
},
|
|
417
|
-
};
|
|
366
|
+
const { id, delay, error } = await create({
|
|
367
|
+
item,
|
|
368
|
+
mappers: this._mappers,
|
|
369
|
+
event: this.event,
|
|
370
|
+
});
|
|
371
|
+
if (delay) {
|
|
372
|
+
return {
|
|
373
|
+
rateLimit: {
|
|
374
|
+
delay,
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
else if (id) {
|
|
379
|
+
try {
|
|
380
|
+
const syncMapperRecordCreate = await this._mappers.create({
|
|
381
|
+
sync_unit: this.event.payload.event_context.sync_unit,
|
|
382
|
+
external_ids: [id],
|
|
383
|
+
targets: [item.reference_id],
|
|
384
|
+
status: mappers_interfaces_1.SyncMapperRecordStatus.OPERATIONAL,
|
|
385
|
+
});
|
|
386
|
+
console.log('Successfully created sync mapper record.', syncMapperRecordCreate);
|
|
418
387
|
}
|
|
419
|
-
|
|
420
|
-
console.warn('Failed to create
|
|
421
|
-
return {
|
|
422
|
-
report: {
|
|
423
|
-
item_type: 'attachment',
|
|
424
|
-
[loading_1.ActionType.FAILED]: 1,
|
|
425
|
-
},
|
|
426
|
-
};
|
|
388
|
+
catch (error) {
|
|
389
|
+
console.warn('Failed to create sync mapper record.', (0, logger_1.serializeError)(error));
|
|
427
390
|
}
|
|
428
|
-
|
|
391
|
+
return {
|
|
392
|
+
report: {
|
|
393
|
+
item_type: 'attachments',
|
|
394
|
+
[loading_1.ActionType.CREATED]: 1,
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
console.warn('Failed to create attachment in external system', error);
|
|
400
|
+
return {
|
|
401
|
+
report: {
|
|
402
|
+
item_type: 'attachments',
|
|
403
|
+
[loading_1.ActionType.FAILED]: 1,
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
}
|
|
429
407
|
}
|
|
430
408
|
}
|
|
431
409
|
exports.LoadingAdapter = LoadingAdapter;
|