@strapi/data-transfer 4.14.4 → 4.14.6
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/commands/commander.d.ts +1 -0
- package/dist/commands/commander.d.ts.map +1 -0
- package/dist/commands/data-transfer.d.ts +2 -1
- package/dist/commands/data-transfer.d.ts.map +1 -0
- package/dist/commands/export/action.d.ts +1 -0
- package/dist/commands/export/action.d.ts.map +1 -0
- package/dist/commands/export/command.d.ts +1 -0
- package/dist/commands/export/command.d.ts.map +1 -0
- package/dist/commands/helpers.d.ts +1 -0
- package/dist/commands/helpers.d.ts.map +1 -0
- package/dist/commands/import/action.d.ts +1 -0
- package/dist/commands/import/action.d.ts.map +1 -0
- package/dist/commands/import/command.d.ts +1 -0
- package/dist/commands/import/command.d.ts.map +1 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/transfer/action.d.ts +1 -0
- package/dist/commands/transfer/action.d.ts.map +1 -0
- package/dist/commands/transfer/command.d.ts +1 -0
- package/dist/commands/transfer/command.d.ts.map +1 -0
- package/dist/engine/diagnostic.d.ts +1 -0
- package/dist/engine/diagnostic.d.ts.map +1 -0
- package/dist/engine/errors.d.ts +1 -0
- package/dist/engine/errors.d.ts.map +1 -0
- package/dist/engine/index.d.ts +1 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/validation/index.d.ts +1 -0
- package/dist/engine/validation/index.d.ts.map +1 -0
- package/dist/engine/validation/provider.d.ts +1 -0
- package/dist/engine/validation/provider.d.ts.map +1 -0
- package/dist/engine/validation/schemas/index.d.ts +1 -0
- package/dist/engine/validation/schemas/index.d.ts.map +1 -0
- package/dist/errors/base.d.ts +1 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/constants.d.ts +1 -0
- package/dist/errors/constants.d.ts.map +1 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/providers.d.ts +1 -0
- package/dist/errors/providers.d.ts.map +1 -0
- package/dist/file/index.d.ts +1 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/providers/destination/index.d.ts +1 -0
- package/dist/file/providers/destination/index.d.ts.map +1 -0
- package/dist/file/providers/destination/utils.d.ts +1 -0
- package/dist/file/providers/destination/utils.d.ts.map +1 -0
- package/dist/file/providers/index.d.ts +1 -0
- package/dist/file/providers/index.d.ts.map +1 -0
- package/dist/file/providers/source/index.d.ts +1 -0
- package/dist/file/providers/source/index.d.ts.map +1 -0
- package/dist/file/providers/source/utils.d.ts +1 -0
- package/dist/file/providers/source/utils.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5340 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5311 -0
- package/dist/index.mjs.map +1 -0
- package/dist/strapi/index.d.ts +1 -0
- package/dist/strapi/index.d.ts.map +1 -0
- package/dist/strapi/providers/index.d.ts +1 -0
- package/dist/strapi/providers/index.d.ts.map +1 -0
- package/dist/strapi/providers/local-destination/index.d.ts +1 -0
- package/dist/strapi/providers/local-destination/index.d.ts.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/index.d.ts +1 -0
- package/dist/strapi/providers/local-destination/strategies/index.d.ts.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.d.ts.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts.map +1 -0
- package/dist/strapi/providers/local-source/assets.d.ts +1 -0
- package/dist/strapi/providers/local-source/assets.d.ts.map +1 -0
- package/dist/strapi/providers/local-source/configuration.d.ts +1 -0
- package/dist/strapi/providers/local-source/configuration.d.ts.map +1 -0
- package/dist/strapi/providers/local-source/entities.d.ts +1 -0
- package/dist/strapi/providers/local-source/entities.d.ts.map +1 -0
- package/dist/strapi/providers/local-source/index.d.ts +1 -0
- package/dist/strapi/providers/local-source/index.d.ts.map +1 -0
- package/dist/strapi/providers/local-source/links.d.ts +1 -0
- package/dist/strapi/providers/local-source/links.d.ts.map +1 -0
- package/dist/strapi/providers/remote-destination/index.d.ts +1 -0
- package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -0
- package/dist/strapi/providers/remote-source/index.d.ts +1 -0
- package/dist/strapi/providers/remote-source/index.d.ts.map +1 -0
- package/dist/strapi/providers/utils.d.ts +1 -0
- package/dist/strapi/providers/utils.d.ts.map +1 -0
- package/dist/strapi/queries/entity.d.ts +1 -0
- package/dist/strapi/queries/entity.d.ts.map +1 -0
- package/dist/strapi/queries/index.d.ts +1 -0
- package/dist/strapi/queries/index.d.ts.map +1 -0
- package/dist/strapi/queries/link.d.ts +1 -0
- package/dist/strapi/queries/link.d.ts.map +1 -0
- package/dist/strapi/remote/constants.d.ts +1 -0
- package/dist/strapi/remote/constants.d.ts.map +1 -0
- package/dist/strapi/remote/flows/default.d.ts +1 -0
- package/dist/strapi/remote/flows/default.d.ts.map +1 -0
- package/dist/strapi/remote/flows/index.d.ts +1 -0
- package/dist/strapi/remote/flows/index.d.ts.map +1 -0
- package/dist/strapi/remote/handlers/abstract.d.ts +1 -0
- package/dist/strapi/remote/handlers/abstract.d.ts.map +1 -0
- package/dist/strapi/remote/handlers/constants.d.ts +1 -0
- package/dist/strapi/remote/handlers/constants.d.ts.map +1 -0
- package/dist/strapi/remote/handlers/index.d.ts +4 -3
- package/dist/strapi/remote/handlers/index.d.ts.map +1 -0
- package/dist/strapi/remote/handlers/pull.d.ts +1 -0
- package/dist/strapi/remote/handlers/pull.d.ts.map +1 -0
- package/dist/strapi/remote/handlers/push.d.ts +1 -0
- package/dist/strapi/remote/handlers/push.d.ts.map +1 -0
- package/dist/strapi/remote/handlers/utils.d.ts +1 -0
- package/dist/strapi/remote/handlers/utils.d.ts.map +1 -0
- package/dist/strapi/remote/index.d.ts +1 -0
- package/dist/strapi/remote/index.d.ts.map +1 -0
- package/dist/utils/components.d.ts +1 -0
- package/dist/utils/components.d.ts.map +1 -0
- package/dist/utils/encryption/decrypt.d.ts +1 -0
- package/dist/utils/encryption/decrypt.d.ts.map +1 -0
- package/dist/utils/encryption/encrypt.d.ts +1 -0
- package/dist/utils/encryption/encrypt.d.ts.map +1 -0
- package/dist/utils/encryption/index.d.ts +1 -0
- package/dist/utils/encryption/index.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/json.d.ts +1 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/middleware.d.ts +1 -0
- package/dist/utils/middleware.d.ts.map +1 -0
- package/dist/utils/providers.d.ts +1 -0
- package/dist/utils/providers.d.ts.map +1 -0
- package/dist/utils/schema.d.ts +1 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/stream.d.ts +1 -0
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/transaction.d.ts +1 -0
- package/dist/utils/transaction.d.ts.map +1 -0
- package/package.json +18 -16
- package/dist/commands/commander.js +0 -138
- package/dist/commands/commander.js.map +0 -1
- package/dist/commands/data-transfer.js +0 -359
- package/dist/commands/data-transfer.js.map +0 -1
- package/dist/commands/export/action.js +0 -156
- package/dist/commands/export/action.js.map +0 -1
- package/dist/commands/export/command.js +0 -30
- package/dist/commands/export/command.js.map +0 -1
- package/dist/commands/helpers.js +0 -87
- package/dist/commands/helpers.js.map +0 -1
- package/dist/commands/import/action.js +0 -139
- package/dist/commands/import/action.js.map +0 -1
- package/dist/commands/import/command.js +0 -75
- package/dist/commands/import/command.js.map +0 -1
- package/dist/commands/index.js +0 -13
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/transfer/action.js +0 -161
- package/dist/commands/transfer/action.js.map +0 -1
- package/dist/commands/transfer/command.js +0 -69
- package/dist/commands/transfer/command.js.map +0 -1
- package/dist/engine/diagnostic.js +0 -50
- package/dist/engine/diagnostic.js.map +0 -1
- package/dist/engine/errors.js +0 -29
- package/dist/engine/errors.js.map +0 -1
- package/dist/engine/index.js +0 -708
- package/dist/engine/index.js.map +0 -1
- package/dist/engine/validation/index.js +0 -19
- package/dist/engine/validation/index.js.map +0 -1
- package/dist/engine/validation/provider.js +0 -18
- package/dist/engine/validation/provider.js.map +0 -1
- package/dist/engine/validation/schemas/index.js +0 -70
- package/dist/engine/validation/schemas/index.js.map +0 -1
- package/dist/errors/base.js +0 -16
- package/dist/errors/base.js.map +0 -1
- package/dist/errors/constants.js +0 -9
- package/dist/errors/constants.js.map +0 -1
- package/dist/errors/index.js +0 -19
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/providers.js +0 -32
- package/dist/errors/providers.js.map +0 -1
- package/dist/file/index.js +0 -28
- package/dist/file/index.js.map +0 -1
- package/dist/file/providers/destination/index.js +0 -177
- package/dist/file/providers/destination/index.js.map +0 -1
- package/dist/file/providers/destination/utils.js +0 -62
- package/dist/file/providers/destination/utils.js.map +0 -1
- package/dist/file/providers/index.js +0 -19
- package/dist/file/providers/index.js.map +0 -1
- package/dist/file/providers/source/index.js +0 -234
- package/dist/file/providers/source/index.js.map +0 -1
- package/dist/file/providers/source/utils.js +0 -62
- package/dist/file/providers/source/utils.js.map +0 -1
- package/dist/strapi/index.js +0 -30
- package/dist/strapi/index.js.map +0 -1
- package/dist/strapi/providers/index.js +0 -23
- package/dist/strapi/providers/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/index.js +0 -360
- package/dist/strapi/providers/local-destination/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/index.js +0 -28
- package/dist/strapi/providers/local-destination/strategies/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js +0 -106
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/index.js +0 -109
- package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.js +0 -32
- package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +0 -1
- package/dist/strapi/providers/local-source/assets.js +0 -102
- package/dist/strapi/providers/local-source/assets.js.map +0 -1
- package/dist/strapi/providers/local-source/configuration.js +0 -36
- package/dist/strapi/providers/local-source/configuration.js.map +0 -1
- package/dist/strapi/providers/local-source/entities.js +0 -85
- package/dist/strapi/providers/local-source/entities.js.map +0 -1
- package/dist/strapi/providers/local-source/index.js +0 -100
- package/dist/strapi/providers/local-source/index.js.map +0 -1
- package/dist/strapi/providers/local-source/links.js +0 -23
- package/dist/strapi/providers/local-source/links.js.map +0 -1
- package/dist/strapi/providers/remote-destination/index.js +0 -270
- package/dist/strapi/providers/remote-destination/index.js.map +0 -1
- package/dist/strapi/providers/remote-source/index.js +0 -239
- package/dist/strapi/providers/remote-source/index.js.map +0 -1
- package/dist/strapi/providers/utils.js +0 -138
- package/dist/strapi/providers/utils.js.map +0 -1
- package/dist/strapi/queries/entity.js +0 -130
- package/dist/strapi/queries/entity.js.map +0 -1
- package/dist/strapi/queries/index.js +0 -29
- package/dist/strapi/queries/index.js.map +0 -1
- package/dist/strapi/queries/link.js +0 -224
- package/dist/strapi/queries/link.js.map +0 -1
- package/dist/strapi/remote/constants.js +0 -6
- package/dist/strapi/remote/constants.js.map +0 -1
- package/dist/strapi/remote/flows/default.js +0 -41
- package/dist/strapi/remote/flows/default.js.map +0 -1
- package/dist/strapi/remote/flows/index.js +0 -59
- package/dist/strapi/remote/flows/index.js.map +0 -1
- package/dist/strapi/remote/handlers/abstract.js +0 -3
- package/dist/strapi/remote/handlers/abstract.js.map +0 -1
- package/dist/strapi/remote/handlers/constants.js +0 -5
- package/dist/strapi/remote/handlers/constants.js.map +0 -1
- package/dist/strapi/remote/handlers/index.js +0 -10
- package/dist/strapi/remote/handlers/index.js.map +0 -1
- package/dist/strapi/remote/handlers/pull.js +0 -243
- package/dist/strapi/remote/handlers/pull.js.map +0 -1
- package/dist/strapi/remote/handlers/push.js +0 -311
- package/dist/strapi/remote/handlers/push.js.map +0 -1
- package/dist/strapi/remote/handlers/utils.js +0 -298
- package/dist/strapi/remote/handlers/utils.js.map +0 -1
- package/dist/strapi/remote/index.js +0 -29
- package/dist/strapi/remote/index.js.map +0 -1
- package/dist/utils/components.js +0 -381
- package/dist/utils/components.js.map +0 -1
- package/dist/utils/encryption/decrypt.js +0 -47
- package/dist/utils/encryption/decrypt.js.map +0 -1
- package/dist/utils/encryption/encrypt.js +0 -47
- package/dist/utils/encryption/encrypt.js.map +0 -1
- package/dist/utils/encryption/index.js +0 -19
- package/dist/utils/encryption/index.js.map +0 -1
- package/dist/utils/index.js +0 -33
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/json.js +0 -68
- package/dist/utils/json.js.map +0 -1
- package/dist/utils/middleware.js +0 -14
- package/dist/utils/middleware.js.map +0 -1
- package/dist/utils/providers.js +0 -11
- package/dist/utils/providers.js.map +0 -1
- package/dist/utils/schema.js +0 -29
- package/dist/utils/schema.js.map +0 -1
- package/dist/utils/stream.js +0 -59
- package/dist/utils/stream.js.map +0 -1
- package/dist/utils/transaction.js +0 -88
- package/dist/utils/transaction.js.map +0 -1
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRemoteStrapiDestinationProvider = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
const fp_1 = require("lodash/fp");
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const constants_1 = require("../../remote/constants");
|
|
9
|
-
const providers_1 = require("../../../errors/providers");
|
|
10
|
-
const jsonLength = (obj) => Buffer.byteLength(JSON.stringify(obj));
|
|
11
|
-
class RemoteStrapiDestinationProvider {
|
|
12
|
-
name = 'destination::remote-strapi';
|
|
13
|
-
type = 'destination';
|
|
14
|
-
options;
|
|
15
|
-
ws;
|
|
16
|
-
dispatcher;
|
|
17
|
-
transferID;
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.options = options;
|
|
20
|
-
this.ws = null;
|
|
21
|
-
this.dispatcher = null;
|
|
22
|
-
this.transferID = null;
|
|
23
|
-
}
|
|
24
|
-
async initTransfer() {
|
|
25
|
-
const { strategy, restore } = this.options;
|
|
26
|
-
const query = this.dispatcher?.dispatchCommand({
|
|
27
|
-
command: 'init',
|
|
28
|
-
params: { options: { strategy, restore }, transfer: 'push' },
|
|
29
|
-
});
|
|
30
|
-
const res = (await query);
|
|
31
|
-
if (!res?.transferID) {
|
|
32
|
-
throw new providers_1.ProviderTransferError('Init failed, invalid response from the server');
|
|
33
|
-
}
|
|
34
|
-
return res.transferID;
|
|
35
|
-
}
|
|
36
|
-
#startStepOnce(stage) {
|
|
37
|
-
return (0, fp_1.once)(() => this.#startStep(stage));
|
|
38
|
-
}
|
|
39
|
-
async #startStep(step) {
|
|
40
|
-
try {
|
|
41
|
-
await this.dispatcher?.dispatchTransferStep({ action: 'start', step });
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
if (e instanceof Error) {
|
|
45
|
-
return e;
|
|
46
|
-
}
|
|
47
|
-
if (typeof e === 'string') {
|
|
48
|
-
return new providers_1.ProviderTransferError(e);
|
|
49
|
-
}
|
|
50
|
-
return new providers_1.ProviderTransferError('Unexpected error');
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
async #endStep(step) {
|
|
55
|
-
try {
|
|
56
|
-
await this.dispatcher?.dispatchTransferStep({ action: 'end', step });
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
if (e instanceof Error) {
|
|
60
|
-
return e;
|
|
61
|
-
}
|
|
62
|
-
if (typeof e === 'string') {
|
|
63
|
-
return new providers_1.ProviderTransferError(e);
|
|
64
|
-
}
|
|
65
|
-
return new providers_1.ProviderTransferError('Unexpected error');
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
async #streamStep(step, data) {
|
|
70
|
-
try {
|
|
71
|
-
await this.dispatcher?.dispatchTransferStep({ action: 'stream', step, data });
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
if (e instanceof Error) {
|
|
75
|
-
return e;
|
|
76
|
-
}
|
|
77
|
-
if (typeof e === 'string') {
|
|
78
|
-
return new providers_1.ProviderTransferError(e);
|
|
79
|
-
}
|
|
80
|
-
return new providers_1.ProviderTransferError('Unexpected error');
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
#writeStream(step) {
|
|
85
|
-
const batchSize = 1024 * 1024; // 1MB;
|
|
86
|
-
const startTransferOnce = this.#startStepOnce(step);
|
|
87
|
-
let batch = [];
|
|
88
|
-
const batchLength = () => jsonLength(batch);
|
|
89
|
-
return new stream_1.Writable({
|
|
90
|
-
objectMode: true,
|
|
91
|
-
final: async (callback) => {
|
|
92
|
-
if (batch.length > 0) {
|
|
93
|
-
const streamError = await this.#streamStep(step, batch);
|
|
94
|
-
batch = [];
|
|
95
|
-
if (streamError) {
|
|
96
|
-
return callback(streamError);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const e = await this.#endStep(step);
|
|
100
|
-
callback(e);
|
|
101
|
-
},
|
|
102
|
-
write: async (chunk, _encoding, callback) => {
|
|
103
|
-
const startError = await startTransferOnce();
|
|
104
|
-
if (startError) {
|
|
105
|
-
return callback(startError);
|
|
106
|
-
}
|
|
107
|
-
batch.push(chunk);
|
|
108
|
-
if (batchLength() >= batchSize) {
|
|
109
|
-
const streamError = await this.#streamStep(step, batch);
|
|
110
|
-
batch = [];
|
|
111
|
-
if (streamError) {
|
|
112
|
-
return callback(streamError);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
callback();
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
async bootstrap() {
|
|
120
|
-
const { url, auth } = this.options;
|
|
121
|
-
const validProtocols = ['https:', 'http:'];
|
|
122
|
-
let ws;
|
|
123
|
-
if (!validProtocols.includes(url.protocol)) {
|
|
124
|
-
throw new providers_1.ProviderValidationError(`Invalid protocol "${url.protocol}"`, {
|
|
125
|
-
check: 'url',
|
|
126
|
-
details: {
|
|
127
|
-
protocol: url.protocol,
|
|
128
|
-
validProtocols,
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
const wsProtocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
133
|
-
const wsUrl = `${wsProtocol}//${url.host}${(0, utils_1.trimTrailingSlash)(url.pathname)}${constants_1.TRANSFER_PATH}/push`;
|
|
134
|
-
// No auth defined, trying public access for transfer
|
|
135
|
-
if (!auth) {
|
|
136
|
-
ws = await (0, utils_1.connectToWebsocket)(wsUrl);
|
|
137
|
-
}
|
|
138
|
-
// Common token auth, this should be the main auth method
|
|
139
|
-
else if (auth.type === 'token') {
|
|
140
|
-
const headers = { Authorization: `Bearer ${auth.token}` };
|
|
141
|
-
ws = await (0, utils_1.connectToWebsocket)(wsUrl, { headers });
|
|
142
|
-
}
|
|
143
|
-
// Invalid auth method provided
|
|
144
|
-
else {
|
|
145
|
-
throw new providers_1.ProviderValidationError('Auth method not available', {
|
|
146
|
-
check: 'auth.type',
|
|
147
|
-
details: {
|
|
148
|
-
auth: auth.type,
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
this.ws = ws;
|
|
153
|
-
const { retryMessageOptions } = this.options;
|
|
154
|
-
this.dispatcher = (0, utils_1.createDispatcher)(this.ws, retryMessageOptions);
|
|
155
|
-
this.transferID = await this.initTransfer();
|
|
156
|
-
this.dispatcher.setTransferProperties({ id: this.transferID, kind: 'push' });
|
|
157
|
-
await this.dispatcher.dispatchTransferAction('bootstrap');
|
|
158
|
-
}
|
|
159
|
-
async close() {
|
|
160
|
-
// Gracefully close the remote transfer process
|
|
161
|
-
if (this.transferID && this.dispatcher) {
|
|
162
|
-
await this.dispatcher.dispatchTransferAction('close');
|
|
163
|
-
await this.dispatcher.dispatchCommand({
|
|
164
|
-
command: 'end',
|
|
165
|
-
params: { transferID: this.transferID },
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
await new Promise((resolve) => {
|
|
169
|
-
const { ws } = this;
|
|
170
|
-
if (!ws || ws.CLOSED) {
|
|
171
|
-
resolve();
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
ws.on('close', () => resolve()).close();
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
getMetadata() {
|
|
178
|
-
return this.dispatcher?.dispatchTransferAction('getMetadata') ?? null;
|
|
179
|
-
}
|
|
180
|
-
async beforeTransfer() {
|
|
181
|
-
await this.dispatcher?.dispatchTransferAction('beforeTransfer');
|
|
182
|
-
}
|
|
183
|
-
async rollback() {
|
|
184
|
-
await this.dispatcher?.dispatchTransferAction('rollback');
|
|
185
|
-
}
|
|
186
|
-
getSchemas() {
|
|
187
|
-
if (!this.dispatcher) {
|
|
188
|
-
return Promise.resolve(null);
|
|
189
|
-
}
|
|
190
|
-
return this.dispatcher.dispatchTransferAction('getSchemas');
|
|
191
|
-
}
|
|
192
|
-
createEntitiesWriteStream() {
|
|
193
|
-
return this.#writeStream('entities');
|
|
194
|
-
}
|
|
195
|
-
createLinksWriteStream() {
|
|
196
|
-
return this.#writeStream('links');
|
|
197
|
-
}
|
|
198
|
-
createConfigurationWriteStream() {
|
|
199
|
-
return this.#writeStream('configuration');
|
|
200
|
-
}
|
|
201
|
-
createAssetsWriteStream() {
|
|
202
|
-
let batch = [];
|
|
203
|
-
let hasStarted = false;
|
|
204
|
-
const batchSize = 1024 * 1024; // 1MB;
|
|
205
|
-
const batchLength = () => {
|
|
206
|
-
return batch.reduce((acc, chunk) => (chunk.action === 'stream' ? acc + chunk.data.byteLength : acc), 0);
|
|
207
|
-
};
|
|
208
|
-
const startAssetsTransferOnce = this.#startStepOnce('assets');
|
|
209
|
-
const flush = async () => {
|
|
210
|
-
const streamError = await this.#streamStep('assets', batch);
|
|
211
|
-
batch = [];
|
|
212
|
-
return streamError;
|
|
213
|
-
};
|
|
214
|
-
const safePush = async (chunk) => {
|
|
215
|
-
batch.push(chunk);
|
|
216
|
-
if (batchLength() >= batchSize) {
|
|
217
|
-
const streamError = await flush();
|
|
218
|
-
if (streamError) {
|
|
219
|
-
throw streamError;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
return new stream_1.Writable({
|
|
224
|
-
objectMode: true,
|
|
225
|
-
final: async (callback) => {
|
|
226
|
-
if (batch.length > 0) {
|
|
227
|
-
await flush();
|
|
228
|
-
}
|
|
229
|
-
if (hasStarted) {
|
|
230
|
-
const endStepError = await this.#endStep('assets');
|
|
231
|
-
if (endStepError) {
|
|
232
|
-
return callback(endStepError);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return callback(null);
|
|
236
|
-
},
|
|
237
|
-
async write(asset, _encoding, callback) {
|
|
238
|
-
const startError = await startAssetsTransferOnce();
|
|
239
|
-
if (startError) {
|
|
240
|
-
return callback(startError);
|
|
241
|
-
}
|
|
242
|
-
hasStarted = true;
|
|
243
|
-
const assetID = (0, crypto_1.randomUUID)();
|
|
244
|
-
const { filename, filepath, stats, stream, metadata } = asset;
|
|
245
|
-
try {
|
|
246
|
-
await safePush({
|
|
247
|
-
action: 'start',
|
|
248
|
-
assetID,
|
|
249
|
-
data: { filename, filepath, stats, metadata },
|
|
250
|
-
});
|
|
251
|
-
for await (const chunk of stream) {
|
|
252
|
-
await safePush({ action: 'stream', assetID, data: chunk });
|
|
253
|
-
}
|
|
254
|
-
await safePush({ action: 'end', assetID });
|
|
255
|
-
callback();
|
|
256
|
-
}
|
|
257
|
-
catch (error) {
|
|
258
|
-
if (error instanceof Error) {
|
|
259
|
-
callback(error);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
const createRemoteStrapiDestinationProvider = (options) => {
|
|
267
|
-
return new RemoteStrapiDestinationProvider(options);
|
|
268
|
-
};
|
|
269
|
-
exports.createRemoteStrapiDestinationProvider = createRemoteStrapiDestinationProvider;
|
|
270
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strapi/providers/remote-destination/index.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AACpC,mCAAkC;AAElC,kCAAiC;AAGjC,oCAAmF;AAKnF,sDAAuD;AACvD,yDAA2F;AAY3F,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AAE3E,MAAM,+BAA+B;IACnC,IAAI,GAAG,4BAA4B,CAAC;IAEpC,IAAI,GAAiB,aAAa,CAAC;IAEnC,OAAO,CAA0C;IAEjD,EAAE,CAAmB;IAErB,UAAU,CAA6C;IAEvD,UAAU,CAAgB;IAE1B,YAAY,OAAgD;QAC1D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GA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,EAAE;wBAC1B,QAAQ,CAAC,KAAK,CAAC,CAAC;qBACjB;iBACF;YACH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAEM,MAAM,qCAAqC,GAAG,CACnD,OAAgD,EAChD,EAAE;IACF,OAAO,IAAI,+BAA+B,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC,CAAC;AAJW,QAAA,qCAAqC,yCAIhD"}
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRemoteStrapiSourceProvider = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
const fp_1 = require("lodash/fp");
|
|
6
|
-
const providers_1 = require("../../../errors/providers");
|
|
7
|
-
const constants_1 = require("../../remote/constants");
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
class RemoteStrapiSourceProvider {
|
|
10
|
-
name = 'source::remote-strapi';
|
|
11
|
-
type = 'source';
|
|
12
|
-
options;
|
|
13
|
-
ws;
|
|
14
|
-
dispatcher;
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this.options = options;
|
|
17
|
-
this.ws = null;
|
|
18
|
-
this.dispatcher = null;
|
|
19
|
-
}
|
|
20
|
-
results;
|
|
21
|
-
async #createStageReadStream(stage) {
|
|
22
|
-
const startResult = await this.#startStep(stage);
|
|
23
|
-
if (startResult instanceof Error) {
|
|
24
|
-
throw startResult;
|
|
25
|
-
}
|
|
26
|
-
const { id: processID } = startResult;
|
|
27
|
-
const stream = new stream_1.PassThrough({ objectMode: true });
|
|
28
|
-
const listener = async (raw) => {
|
|
29
|
-
const parsed = JSON.parse(raw.toString());
|
|
30
|
-
// If not a message related to our transfer process, ignore it
|
|
31
|
-
if (!parsed.uuid || parsed?.data?.type !== 'transfer' || parsed?.data?.id !== processID) {
|
|
32
|
-
this.ws?.once('message', listener);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const { uuid, data: message } = parsed;
|
|
36
|
-
const { ended, error, data } = message;
|
|
37
|
-
if (ended) {
|
|
38
|
-
await this.#respond(uuid);
|
|
39
|
-
await this.#endStep(stage);
|
|
40
|
-
stream.end();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (error) {
|
|
44
|
-
await this.#respond(uuid);
|
|
45
|
-
await this.#endStep(stage);
|
|
46
|
-
stream.destroy(error);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
// if we get a single items instead of a batch
|
|
50
|
-
// TODO V5: in v5 only allow array
|
|
51
|
-
for (const item of (0, fp_1.castArray)(data)) {
|
|
52
|
-
stream.push(item);
|
|
53
|
-
}
|
|
54
|
-
this.ws?.once('message', listener);
|
|
55
|
-
await this.#respond(uuid);
|
|
56
|
-
};
|
|
57
|
-
this.ws?.once('message', listener);
|
|
58
|
-
return stream;
|
|
59
|
-
}
|
|
60
|
-
createEntitiesReadStream() {
|
|
61
|
-
return this.#createStageReadStream('entities');
|
|
62
|
-
}
|
|
63
|
-
createLinksReadStream() {
|
|
64
|
-
return this.#createStageReadStream('links');
|
|
65
|
-
}
|
|
66
|
-
writeAsync = (stream, data) => {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
stream.write(data, (error) => {
|
|
69
|
-
if (error) {
|
|
70
|
-
reject(error);
|
|
71
|
-
}
|
|
72
|
-
resolve();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
async createAssetsReadStream() {
|
|
77
|
-
const assets = {};
|
|
78
|
-
const stream = await this.#createStageReadStream('assets');
|
|
79
|
-
const pass = new stream_1.PassThrough({ objectMode: true });
|
|
80
|
-
stream
|
|
81
|
-
.on('data', async (payload) => {
|
|
82
|
-
for (const item of payload) {
|
|
83
|
-
const { action } = item;
|
|
84
|
-
// Creates the stream to send the incoming asset through
|
|
85
|
-
if (action === 'start') {
|
|
86
|
-
// Each asset has its own stream identified by its assetID
|
|
87
|
-
assets[item.assetID] = { ...item.data, stream: new stream_1.PassThrough() };
|
|
88
|
-
await this.writeAsync(pass, assets[item.assetID]);
|
|
89
|
-
}
|
|
90
|
-
// Writes the asset data to the created stream
|
|
91
|
-
else if (action === 'stream') {
|
|
92
|
-
// Converts data into buffer
|
|
93
|
-
const rawBuffer = item.data;
|
|
94
|
-
const chunk = Buffer.from(rawBuffer.data);
|
|
95
|
-
await this.writeAsync(assets[item.assetID].stream, chunk);
|
|
96
|
-
}
|
|
97
|
-
// The asset has been transferred
|
|
98
|
-
else if (action === 'end') {
|
|
99
|
-
await new Promise((resolve, reject) => {
|
|
100
|
-
const { stream: assetStream } = assets[item.assetID];
|
|
101
|
-
assetStream
|
|
102
|
-
.on('close', () => {
|
|
103
|
-
// Deletes the stream for the asset
|
|
104
|
-
delete assets[item.assetID];
|
|
105
|
-
resolve();
|
|
106
|
-
})
|
|
107
|
-
.on('error', reject)
|
|
108
|
-
.end();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
.on('close', () => {
|
|
114
|
-
pass.end();
|
|
115
|
-
});
|
|
116
|
-
return pass;
|
|
117
|
-
}
|
|
118
|
-
createConfigurationReadStream() {
|
|
119
|
-
return this.#createStageReadStream('configuration');
|
|
120
|
-
}
|
|
121
|
-
async getMetadata() {
|
|
122
|
-
const metadata = await this.dispatcher?.dispatchTransferAction('getMetadata');
|
|
123
|
-
return metadata ?? null;
|
|
124
|
-
}
|
|
125
|
-
assertValidProtocol(url) {
|
|
126
|
-
const validProtocols = ['https:', 'http:'];
|
|
127
|
-
if (!validProtocols.includes(url.protocol)) {
|
|
128
|
-
throw new providers_1.ProviderValidationError(`Invalid protocol "${url.protocol}"`, {
|
|
129
|
-
check: 'url',
|
|
130
|
-
details: {
|
|
131
|
-
protocol: url.protocol,
|
|
132
|
-
validProtocols,
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async initTransfer() {
|
|
138
|
-
const query = this.dispatcher?.dispatchCommand({
|
|
139
|
-
command: 'init',
|
|
140
|
-
});
|
|
141
|
-
const res = (await query);
|
|
142
|
-
if (!res?.transferID) {
|
|
143
|
-
throw new providers_1.ProviderTransferError('Init failed, invalid response from the server');
|
|
144
|
-
}
|
|
145
|
-
return res.transferID;
|
|
146
|
-
}
|
|
147
|
-
async bootstrap() {
|
|
148
|
-
const { url, auth } = this.options;
|
|
149
|
-
let ws;
|
|
150
|
-
this.assertValidProtocol(url);
|
|
151
|
-
const wsProtocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
152
|
-
const wsUrl = `${wsProtocol}//${url.host}${(0, utils_1.trimTrailingSlash)(url.pathname)}${constants_1.TRANSFER_PATH}/pull`;
|
|
153
|
-
// No auth defined, trying public access for transfer
|
|
154
|
-
if (!auth) {
|
|
155
|
-
ws = await (0, utils_1.connectToWebsocket)(wsUrl);
|
|
156
|
-
}
|
|
157
|
-
// Common token auth, this should be the main auth method
|
|
158
|
-
else if (auth.type === 'token') {
|
|
159
|
-
const headers = { Authorization: `Bearer ${auth.token}` };
|
|
160
|
-
ws = await (0, utils_1.connectToWebsocket)(wsUrl, { headers });
|
|
161
|
-
}
|
|
162
|
-
// Invalid auth method provided
|
|
163
|
-
else {
|
|
164
|
-
throw new providers_1.ProviderValidationError('Auth method not available', {
|
|
165
|
-
check: 'auth.type',
|
|
166
|
-
details: {
|
|
167
|
-
auth: auth.type,
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
this.ws = ws;
|
|
172
|
-
const { retryMessageOptions } = this.options;
|
|
173
|
-
this.dispatcher = (0, utils_1.createDispatcher)(this.ws, retryMessageOptions);
|
|
174
|
-
const transferID = await this.initTransfer();
|
|
175
|
-
this.dispatcher.setTransferProperties({ id: transferID, kind: 'pull' });
|
|
176
|
-
await this.dispatcher.dispatchTransferAction('bootstrap');
|
|
177
|
-
}
|
|
178
|
-
async close() {
|
|
179
|
-
await this.dispatcher?.dispatchTransferAction('close');
|
|
180
|
-
await new Promise((resolve) => {
|
|
181
|
-
const { ws } = this;
|
|
182
|
-
if (!ws || ws.CLOSED) {
|
|
183
|
-
resolve();
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
ws.on('close', () => resolve()).close();
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
async getSchemas() {
|
|
190
|
-
const schemas = (await this.dispatcher?.dispatchTransferAction('getSchemas')) ?? null;
|
|
191
|
-
return schemas;
|
|
192
|
-
}
|
|
193
|
-
async #startStep(step) {
|
|
194
|
-
try {
|
|
195
|
-
return await this.dispatcher?.dispatchTransferStep({ action: 'start', step });
|
|
196
|
-
}
|
|
197
|
-
catch (e) {
|
|
198
|
-
if (e instanceof Error) {
|
|
199
|
-
return e;
|
|
200
|
-
}
|
|
201
|
-
if (typeof e === 'string') {
|
|
202
|
-
return new providers_1.ProviderTransferError(e);
|
|
203
|
-
}
|
|
204
|
-
return new providers_1.ProviderTransferError('Unexpected error');
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async #respond(uuid) {
|
|
208
|
-
return new Promise((resolve, reject) => {
|
|
209
|
-
this.ws?.send(JSON.stringify({ uuid }), (e) => {
|
|
210
|
-
if (e) {
|
|
211
|
-
reject(e);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
resolve(e);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
async #endStep(step) {
|
|
220
|
-
try {
|
|
221
|
-
await this.dispatcher?.dispatchTransferStep({ action: 'end', step });
|
|
222
|
-
}
|
|
223
|
-
catch (e) {
|
|
224
|
-
if (e instanceof Error) {
|
|
225
|
-
return e;
|
|
226
|
-
}
|
|
227
|
-
if (typeof e === 'string') {
|
|
228
|
-
return new providers_1.ProviderTransferError(e);
|
|
229
|
-
}
|
|
230
|
-
return new providers_1.ProviderTransferError('Unexpected error');
|
|
231
|
-
}
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const createRemoteStrapiSourceProvider = (options) => {
|
|
236
|
-
return new RemoteStrapiSourceProvider(options);
|
|
237
|
-
};
|
|
238
|
-
exports.createRemoteStrapiSourceProvider = createRemoteStrapiSourceProvider;
|
|
239
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strapi/providers/remote-source/index.ts"],"names":[],"mappings":";;;AAAA,mCAAyD;AAGzD,kCAAsC;AAatC,yDAA2F;AAC3F,sDAAuD;AAEvD,oCAAmF;AAWnF,MAAM,0BAA0B;IAC9B,IAAI,GAAG,uBAAuB,CAAC;IAE/B,IAAI,GAAiB,QAAQ,CAAC;IAE9B,OAAO,CAAqC;IAE5C,EAAE,CAAmB;IAErB,UAAU,CAA6C;IAEvD,YAAY,OAA2C;QACrD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,OAAO,CAA8C;IAErD,KAAK,CAAC,sBAAsB,CAAC,KAAwC;QACnE,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAEjD,IAAI,WAAW,YAAY,KAAK,EAAE;YAChC,MAAM,WAAW,CAAC;SACnB;QAED,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,WAA6B,CAAC;QAExD,MAAM,MAAM,GAAG,IAAI,oBAAW,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAErD,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAE1C,8DAA8D;YAC9D,IAAI,CAAC,MAAM,CAAC,I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iCAAqB,CAAC,CAAC,CAAC,CAAC;aACrC;YAED,OAAO,IAAI,iCAAqB,CAAC,kBAAkB,CAAC,CAAC;SACtD;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAEM,MAAM,gCAAgC,GAAG,CAAC,OAA2C,EAAE,EAAE;IAC9F,OAAO,IAAI,0BAA0B,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC;AAFW,QAAA,gCAAgC,oCAE3C"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.trimTrailingSlash = exports.connectToWebsocket = exports.createDispatcher = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
const ws_1 = require("ws");
|
|
6
|
-
const providers_1 = require("../../errors/providers");
|
|
7
|
-
const createDispatcher = (ws, retryMessageOptions = {
|
|
8
|
-
retryMessageMaxRetries: 5,
|
|
9
|
-
retryMessageTimeout: 15000,
|
|
10
|
-
}) => {
|
|
11
|
-
const state = {};
|
|
12
|
-
const dispatch = async (message, options = {}) => {
|
|
13
|
-
if (!ws) {
|
|
14
|
-
throw new Error('No websocket connection found');
|
|
15
|
-
}
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const uuid = (0, crypto_1.randomUUID)();
|
|
18
|
-
const payload = { ...message, uuid };
|
|
19
|
-
let numberOfTimesMessageWasSent = 0;
|
|
20
|
-
if (options.attachTransfer) {
|
|
21
|
-
Object.assign(payload, { transferID: state.transfer?.id });
|
|
22
|
-
}
|
|
23
|
-
const stringifiedPayload = JSON.stringify(payload);
|
|
24
|
-
ws.send(stringifiedPayload, (error) => {
|
|
25
|
-
if (error) {
|
|
26
|
-
reject(error);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const { retryMessageMaxRetries, retryMessageTimeout } = retryMessageOptions;
|
|
30
|
-
const sendPeriodically = () => {
|
|
31
|
-
if (numberOfTimesMessageWasSent <= retryMessageMaxRetries) {
|
|
32
|
-
numberOfTimesMessageWasSent += 1;
|
|
33
|
-
ws.send(stringifiedPayload, (error) => {
|
|
34
|
-
if (error) {
|
|
35
|
-
reject(error);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
reject(new providers_1.ProviderError('error', 'Request timed out'));
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const interval = setInterval(sendPeriodically, retryMessageTimeout);
|
|
44
|
-
const onResponse = (raw) => {
|
|
45
|
-
const response = JSON.parse(raw.toString());
|
|
46
|
-
if (response.uuid === uuid) {
|
|
47
|
-
clearInterval(interval);
|
|
48
|
-
if (response.error) {
|
|
49
|
-
const message = response.error.message;
|
|
50
|
-
const details = response.error.details?.details;
|
|
51
|
-
const step = response.error.details?.step;
|
|
52
|
-
let error = new providers_1.ProviderError('error', message, details);
|
|
53
|
-
if (step === 'transfer') {
|
|
54
|
-
error = new providers_1.ProviderTransferError(message, details);
|
|
55
|
-
}
|
|
56
|
-
else if (step === 'validation') {
|
|
57
|
-
error = new providers_1.ProviderValidationError(message, details);
|
|
58
|
-
}
|
|
59
|
-
else if (step === 'initialization') {
|
|
60
|
-
error = new providers_1.ProviderInitializationError(message);
|
|
61
|
-
}
|
|
62
|
-
return reject(error);
|
|
63
|
-
}
|
|
64
|
-
resolve(response.data ?? null);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
ws.once('message', onResponse);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
ws.once('message', onResponse);
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
const dispatchCommand = (payload) => {
|
|
74
|
-
return dispatch({ type: 'command', ...payload });
|
|
75
|
-
};
|
|
76
|
-
const dispatchTransferAction = async (action) => {
|
|
77
|
-
const payload = { type: 'transfer', kind: 'action', action };
|
|
78
|
-
return dispatch(payload, { attachTransfer: true }) ?? Promise.resolve(null);
|
|
79
|
-
};
|
|
80
|
-
const dispatchTransferStep = async (payload) => {
|
|
81
|
-
const message = {
|
|
82
|
-
type: 'transfer',
|
|
83
|
-
kind: 'step',
|
|
84
|
-
...payload,
|
|
85
|
-
};
|
|
86
|
-
return dispatch(message, { attachTransfer: true }) ?? Promise.resolve(null);
|
|
87
|
-
};
|
|
88
|
-
const setTransferProperties = (properties) => {
|
|
89
|
-
state.transfer = { ...properties };
|
|
90
|
-
};
|
|
91
|
-
return {
|
|
92
|
-
get transferID() {
|
|
93
|
-
return state.transfer?.id;
|
|
94
|
-
},
|
|
95
|
-
get transferKind() {
|
|
96
|
-
return state.transfer?.kind;
|
|
97
|
-
},
|
|
98
|
-
setTransferProperties,
|
|
99
|
-
dispatch,
|
|
100
|
-
dispatchCommand,
|
|
101
|
-
dispatchTransferAction,
|
|
102
|
-
dispatchTransferStep,
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
exports.createDispatcher = createDispatcher;
|
|
106
|
-
const connectToWebsocket = (address, options) => {
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
108
|
-
const server = new ws_1.WebSocket(address, options);
|
|
109
|
-
server.once('open', () => {
|
|
110
|
-
resolve(server);
|
|
111
|
-
});
|
|
112
|
-
server.on('unexpected-response', (_req, res) => {
|
|
113
|
-
if (res.statusCode === 401) {
|
|
114
|
-
return reject(new providers_1.ProviderInitializationError('Failed to initialize the connection: Authentication Error'));
|
|
115
|
-
}
|
|
116
|
-
if (res.statusCode === 403) {
|
|
117
|
-
return reject(new providers_1.ProviderInitializationError('Failed to initialize the connection: Authorization Error'));
|
|
118
|
-
}
|
|
119
|
-
if (res.statusCode === 404) {
|
|
120
|
-
return reject(new providers_1.ProviderInitializationError('Failed to initialize the connection: Data transfer is not enabled on the remote host'));
|
|
121
|
-
}
|
|
122
|
-
return reject(new providers_1.ProviderInitializationError(`Failed to initialize the connection: Unexpected server response ${res.statusCode}`));
|
|
123
|
-
});
|
|
124
|
-
server.once('error', (err) => {
|
|
125
|
-
reject(new providers_1.ProviderTransferError(err.message, {
|
|
126
|
-
details: {
|
|
127
|
-
error: err.message,
|
|
128
|
-
},
|
|
129
|
-
}));
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
exports.connectToWebsocket = connectToWebsocket;
|
|
134
|
-
const trimTrailingSlash = (input) => {
|
|
135
|
-
return input.replace(/\/$/, '');
|
|
136
|
-
};
|
|
137
|
-
exports.trimTrailingSlash = trimTrailingSlash;
|
|
138
|
-
//# sourceMappingURL=utils.js.map
|