@strapi/data-transfer 4.11.4 → 4.11.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/package.json +7 -7
- package/dist/engine/diagnostic.d.ts +0 -40
- package/dist/engine/diagnostic.js +0 -50
- package/dist/engine/diagnostic.js.map +0 -1
- package/dist/engine/errors.d.ts +0 -28
- package/dist/engine/errors.js +0 -29
- package/dist/engine/errors.js.map +0 -1
- package/dist/engine/index.d.ts +0 -62
- package/dist/engine/index.js +0 -644
- package/dist/engine/index.js.map +0 -1
- package/dist/engine/validation/index.d.ts +0 -2
- package/dist/engine/validation/index.js +0 -19
- package/dist/engine/validation/index.js.map +0 -1
- package/dist/engine/validation/provider.d.ts +0 -3
- package/dist/engine/validation/provider.js +0 -18
- package/dist/engine/validation/provider.js.map +0 -1
- package/dist/engine/validation/schemas/index.d.ts +0 -7
- package/dist/engine/validation/schemas/index.js +0 -70
- package/dist/engine/validation/schemas/index.js.map +0 -1
- package/dist/errors/base.d.ts +0 -8
- package/dist/errors/base.js +0 -13
- package/dist/errors/base.js.map +0 -1
- package/dist/errors/constants.d.ts +0 -3
- package/dist/errors/constants.js +0 -9
- package/dist/errors/constants.js.map +0 -1
- package/dist/errors/index.d.ts +0 -2
- package/dist/errors/index.js +0 -19
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/providers.d.ts +0 -21
- package/dist/errors/providers.js +0 -32
- package/dist/errors/providers.js.map +0 -1
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.js +0 -28
- package/dist/file/index.js.map +0 -1
- package/dist/file/providers/destination/index.d.ts +0 -46
- package/dist/file/providers/destination/index.js +0 -175
- package/dist/file/providers/destination/index.js.map +0 -1
- package/dist/file/providers/destination/utils.d.ts +0 -9
- package/dist/file/providers/destination/utils.js +0 -62
- package/dist/file/providers/destination/utils.js.map +0 -1
- package/dist/file/providers/index.d.ts +0 -2
- package/dist/file/providers/index.js +0 -19
- package/dist/file/providers/index.js.map +0 -1
- package/dist/file/providers/source/index.d.ts +0 -40
- package/dist/file/providers/source/index.js +0 -230
- package/dist/file/providers/source/index.js.map +0 -1
- package/dist/file/providers/source/utils.d.ts +0 -37
- package/dist/file/providers/source/utils.js +0 -62
- package/dist/file/providers/source/utils.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -31
- package/dist/index.js.map +0 -1
- package/dist/strapi/index.d.ts +0 -3
- package/dist/strapi/index.js +0 -30
- package/dist/strapi/index.js.map +0 -1
- package/dist/strapi/providers/index.d.ts +0 -4
- package/dist/strapi/providers/index.js +0 -23
- package/dist/strapi/providers/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/index.d.ts +0 -33
- package/dist/strapi/providers/local-destination/index.js +0 -225
- package/dist/strapi/providers/local-destination/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/index.d.ts +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.d.ts +0 -5
- 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.d.ts +0 -11
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js +0 -103
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +0 -32
- package/dist/strapi/providers/local-destination/strategies/restore/index.js +0 -107
- package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +0 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +0 -4
- 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.d.ts +0 -5
- package/dist/strapi/providers/local-source/assets.js +0 -31
- package/dist/strapi/providers/local-source/assets.js.map +0 -1
- package/dist/strapi/providers/local-source/configuration.d.ts +0 -5
- 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.d.ts +0 -10
- 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.d.ts +0 -26
- package/dist/strapi/providers/local-source/index.js +0 -98
- package/dist/strapi/providers/local-source/index.js.map +0 -1
- package/dist/strapi/providers/local-source/links.d.ts +0 -5
- 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.d.ts +0 -39
- package/dist/strapi/providers/remote-destination/index.js +0 -269
- package/dist/strapi/providers/remote-destination/index.js.map +0 -1
- package/dist/strapi/providers/remote-source/index.d.ts +0 -39
- 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.d.ts +0 -39
- package/dist/strapi/providers/utils.js +0 -125
- package/dist/strapi/providers/utils.js.map +0 -1
- package/dist/strapi/queries/entity.d.ts +0 -20
- package/dist/strapi/queries/entity.js +0 -130
- package/dist/strapi/queries/entity.js.map +0 -1
- package/dist/strapi/queries/index.d.ts +0 -2
- package/dist/strapi/queries/index.js +0 -29
- package/dist/strapi/queries/index.js.map +0 -1
- package/dist/strapi/queries/link.d.ts +0 -7
- package/dist/strapi/queries/link.js +0 -215
- package/dist/strapi/queries/link.js.map +0 -1
- package/dist/strapi/remote/constants.d.ts +0 -4
- package/dist/strapi/remote/constants.js +0 -6
- package/dist/strapi/remote/constants.js.map +0 -1
- package/dist/strapi/remote/flows/default.d.ts +0 -3
- 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.d.ts +0 -18
- 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.d.ts +0 -71
- 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.d.ts +0 -2
- 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.d.ts +0 -3
- 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.d.ts +0 -22
- 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.d.ts +0 -75
- package/dist/strapi/remote/handlers/push.js +0 -305
- package/dist/strapi/remote/handlers/push.js.map +0 -1
- package/dist/strapi/remote/handlers/utils.d.ts +0 -25
- package/dist/strapi/remote/handlers/utils.js +0 -200
- package/dist/strapi/remote/handlers/utils.js.map +0 -1
- package/dist/strapi/remote/index.d.ts +0 -2
- package/dist/strapi/remote/index.js +0 -29
- package/dist/strapi/remote/index.js.map +0 -1
- package/dist/utils/encryption/decrypt.d.ts +0 -11
- package/dist/utils/encryption/decrypt.js +0 -47
- package/dist/utils/encryption/decrypt.js.map +0 -1
- package/dist/utils/encryption/encrypt.d.ts +0 -11
- package/dist/utils/encryption/encrypt.js +0 -47
- package/dist/utils/encryption/encrypt.js.map +0 -1
- package/dist/utils/encryption/index.d.ts +0 -2
- package/dist/utils/encryption/index.js +0 -19
- package/dist/utils/encryption/index.js.map +0 -1
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.js +0 -33
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/json.d.ts +0 -30
- package/dist/utils/json.js +0 -68
- package/dist/utils/json.js.map +0 -1
- package/dist/utils/middleware.d.ts +0 -2
- package/dist/utils/middleware.js +0 -14
- package/dist/utils/middleware.js.map +0 -1
- package/dist/utils/providers.d.ts +0 -2
- package/dist/utils/providers.js +0 -11
- package/dist/utils/providers.js.map +0 -1
- package/dist/utils/schema.d.ts +0 -6
- package/dist/utils/schema.js +0 -29
- package/dist/utils/schema.js.map +0 -1
- package/dist/utils/stream.d.ts +0 -27
- package/dist/utils/stream.js +0 -59
- package/dist/utils/stream.js.map +0 -1
- package/dist/utils/transaction.d.ts +0 -3
- package/dist/utils/transaction.js +0 -88
- package/dist/utils/transaction.js.map +0 -1
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPushController = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
const providers_1 = require("../../../errors/providers");
|
|
7
|
-
const providers_2 = require("../../providers");
|
|
8
|
-
const flows_1 = require("../flows");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const VALID_TRANSFER_ACTIONS = [
|
|
11
|
-
'bootstrap',
|
|
12
|
-
'close',
|
|
13
|
-
'rollback',
|
|
14
|
-
'beforeTransfer',
|
|
15
|
-
'getMetadata',
|
|
16
|
-
'getSchemas',
|
|
17
|
-
];
|
|
18
|
-
const TRANSFER_KIND = 'push';
|
|
19
|
-
const writeAsync = (stream, data) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
stream.write(data, (error) => {
|
|
22
|
-
if (error) {
|
|
23
|
-
reject(error);
|
|
24
|
-
}
|
|
25
|
-
resolve();
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
exports.createPushController = (0, utils_1.handlerControllerFactory)((proto) => ({
|
|
30
|
-
isTransferStarted() {
|
|
31
|
-
return proto.isTransferStarted.call(this) && this.provider !== undefined;
|
|
32
|
-
},
|
|
33
|
-
verifyAuth() {
|
|
34
|
-
return proto.verifyAuth.call(this, TRANSFER_KIND);
|
|
35
|
-
},
|
|
36
|
-
cleanup() {
|
|
37
|
-
proto.cleanup.call(this);
|
|
38
|
-
this.streams = {};
|
|
39
|
-
this.assets = {};
|
|
40
|
-
delete this.flow;
|
|
41
|
-
delete this.provider;
|
|
42
|
-
},
|
|
43
|
-
teardown() {
|
|
44
|
-
if (this.provider) {
|
|
45
|
-
this.provider.rollback();
|
|
46
|
-
}
|
|
47
|
-
proto.teardown.call(this);
|
|
48
|
-
},
|
|
49
|
-
assertValidTransfer() {
|
|
50
|
-
proto.assertValidTransfer.call(this);
|
|
51
|
-
if (this.provider === undefined) {
|
|
52
|
-
throw new Error('Invalid Transfer Process');
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
assertValidTransferAction(action) {
|
|
56
|
-
if (VALID_TRANSFER_ACTIONS.includes(action)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
throw new providers_1.ProviderTransferError(`Invalid action provided: "${action}"`, {
|
|
60
|
-
action,
|
|
61
|
-
validActions: Object.keys(VALID_TRANSFER_ACTIONS),
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
assertValidStreamTransferStep(stage) {
|
|
65
|
-
const currentStep = this.flow?.get();
|
|
66
|
-
const nextStep = { kind: 'transfer', stage };
|
|
67
|
-
if (currentStep?.kind === 'transfer' && !currentStep.locked) {
|
|
68
|
-
throw new providers_1.ProviderTransferError(`You need to initialize the transfer stage (${nextStep}) before starting to stream data`);
|
|
69
|
-
}
|
|
70
|
-
if (this.flow?.cannot(nextStep)) {
|
|
71
|
-
throw new providers_1.ProviderTransferError(`Invalid stage (${nextStep}) provided for the current flow`, {
|
|
72
|
-
step: nextStep,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
async createWritableStreamForStep(step) {
|
|
77
|
-
const mapper = {
|
|
78
|
-
entities: () => this.provider?.createEntitiesWriteStream(),
|
|
79
|
-
links: () => this.provider?.createLinksWriteStream(),
|
|
80
|
-
configuration: () => this.provider?.createConfigurationWriteStream(),
|
|
81
|
-
assets: () => this.provider?.createAssetsWriteStream(),
|
|
82
|
-
};
|
|
83
|
-
if (!(step in mapper)) {
|
|
84
|
-
throw new Error('Invalid transfer step, impossible to create a stream');
|
|
85
|
-
}
|
|
86
|
-
if (!this.streams) {
|
|
87
|
-
throw new Error('Invalid transfer state');
|
|
88
|
-
}
|
|
89
|
-
this.streams[step] = await mapper[step]();
|
|
90
|
-
},
|
|
91
|
-
async onMessage(raw) {
|
|
92
|
-
const msg = JSON.parse(raw.toString());
|
|
93
|
-
if (!(0, utils_1.isDataTransferMessage)(msg)) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (!msg.uuid) {
|
|
97
|
-
await this.respond(undefined, new Error('Missing uuid in message'));
|
|
98
|
-
}
|
|
99
|
-
if (proto.hasUUID(msg.uuid)) {
|
|
100
|
-
const previousResponse = proto.response;
|
|
101
|
-
if (previousResponse?.uuid === msg.uuid) {
|
|
102
|
-
await this.respond(previousResponse?.uuid, previousResponse.e, previousResponse.data);
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const { uuid, type } = msg;
|
|
107
|
-
proto.addUUID(uuid);
|
|
108
|
-
// Regular command message (init, end, status)
|
|
109
|
-
if (type === 'command') {
|
|
110
|
-
const { command } = msg;
|
|
111
|
-
await this.executeAndRespond(uuid, () => {
|
|
112
|
-
this.assertValidTransferCommand(command);
|
|
113
|
-
// The status command don't have params
|
|
114
|
-
if (command === 'status') {
|
|
115
|
-
return this.status();
|
|
116
|
-
}
|
|
117
|
-
return this[command](msg.params);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
// Transfer message (the transfer must be init first)
|
|
121
|
-
else if (type === 'transfer') {
|
|
122
|
-
await this.executeAndRespond(uuid, async () => {
|
|
123
|
-
await this.verifyAuth();
|
|
124
|
-
this.assertValidTransfer();
|
|
125
|
-
return this.onTransferMessage(msg);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
// Invalid messages
|
|
129
|
-
else {
|
|
130
|
-
await this.respond(uuid, new Error('Bad Request'));
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
async onTransferMessage(msg) {
|
|
134
|
-
const { kind } = msg;
|
|
135
|
-
if (kind === 'action') {
|
|
136
|
-
return this.onTransferAction(msg);
|
|
137
|
-
}
|
|
138
|
-
if (kind === 'step') {
|
|
139
|
-
return this.onTransferStep(msg);
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
lockTransferStep(stage) {
|
|
143
|
-
const currentStep = this.flow?.get();
|
|
144
|
-
const nextStep = { kind: 'transfer', stage };
|
|
145
|
-
if (currentStep?.kind === 'transfer' && currentStep.locked) {
|
|
146
|
-
throw new providers_1.ProviderTransferError(`It's not possible to start a new transfer stage (${stage}) while another one is in progress (${currentStep.stage})`);
|
|
147
|
-
}
|
|
148
|
-
if (this.flow?.cannot(nextStep)) {
|
|
149
|
-
throw new providers_1.ProviderTransferError(`Invalid stage (${stage}) provided for the current flow`, {
|
|
150
|
-
step: nextStep,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
this.flow?.set({ ...nextStep, locked: true });
|
|
154
|
-
},
|
|
155
|
-
unlockTransferStep(stage) {
|
|
156
|
-
const currentStep = this.flow?.get();
|
|
157
|
-
const nextStep = { kind: 'transfer', stage };
|
|
158
|
-
// Cannot unlock if not locked (aka: started)
|
|
159
|
-
if (currentStep?.kind === 'transfer' && !currentStep.locked) {
|
|
160
|
-
throw new providers_1.ProviderTransferError(`You need to initialize the transfer stage (${stage}) before ending it`);
|
|
161
|
-
}
|
|
162
|
-
// Cannot unlock if invalid step provided
|
|
163
|
-
if (this.flow?.cannot(nextStep)) {
|
|
164
|
-
throw new providers_1.ProviderTransferError(`Invalid stage (${stage}) provided for the current flow`, {
|
|
165
|
-
step: nextStep,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
this.flow?.set({ ...nextStep, locked: false });
|
|
169
|
-
},
|
|
170
|
-
async onTransferStep(msg) {
|
|
171
|
-
const { step: stage } = msg;
|
|
172
|
-
if (msg.action === 'start') {
|
|
173
|
-
this.lockTransferStep(stage);
|
|
174
|
-
if (this.streams?.[stage] instanceof stream_1.Writable) {
|
|
175
|
-
throw new Error('Stream already created, something went wrong');
|
|
176
|
-
}
|
|
177
|
-
await this.createWritableStreamForStep(stage);
|
|
178
|
-
return { ok: true };
|
|
179
|
-
}
|
|
180
|
-
if (msg.action === 'stream') {
|
|
181
|
-
this.assertValidStreamTransferStep(stage);
|
|
182
|
-
// Stream operation on the current transfer stage
|
|
183
|
-
const stream = this.streams?.[stage];
|
|
184
|
-
if (!stream) {
|
|
185
|
-
throw new Error('You need to init first');
|
|
186
|
-
}
|
|
187
|
-
// Assets are nested streams
|
|
188
|
-
if (stage === 'assets') {
|
|
189
|
-
return this.streamAsset(msg.data);
|
|
190
|
-
}
|
|
191
|
-
// For all other steps
|
|
192
|
-
await Promise.all(msg.data.map((item) => writeAsync(stream, item)));
|
|
193
|
-
}
|
|
194
|
-
if (msg.action === 'end') {
|
|
195
|
-
this.unlockTransferStep(stage);
|
|
196
|
-
const stream = this.streams?.[stage];
|
|
197
|
-
if (stream && !stream.closed) {
|
|
198
|
-
await new Promise((resolve, reject) => {
|
|
199
|
-
stream.on('close', resolve).on('error', reject).end();
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
delete this.streams?.[stage];
|
|
203
|
-
return { ok: true };
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
async onTransferAction(msg) {
|
|
207
|
-
const { action } = msg;
|
|
208
|
-
this.assertValidTransferAction(action);
|
|
209
|
-
const step = { kind: 'action', action };
|
|
210
|
-
const isStepRegistered = this.flow?.has(step);
|
|
211
|
-
if (isStepRegistered) {
|
|
212
|
-
if (this.flow?.cannot(step)) {
|
|
213
|
-
throw new providers_1.ProviderTransferError(`Invalid action "${action}" found for the current flow `, {
|
|
214
|
-
action,
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
this.flow?.set(step);
|
|
218
|
-
}
|
|
219
|
-
return this.provider?.[action]();
|
|
220
|
-
},
|
|
221
|
-
async streamAsset(payload) {
|
|
222
|
-
const assetsStream = this.streams?.assets;
|
|
223
|
-
// TODO: close the stream upong receiving an 'end' event instead
|
|
224
|
-
if (payload === null) {
|
|
225
|
-
this.streams?.assets?.end();
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
for (const item of payload) {
|
|
229
|
-
const { action, assetID } = item;
|
|
230
|
-
if (!assetsStream) {
|
|
231
|
-
throw new Error('Stream not defined');
|
|
232
|
-
}
|
|
233
|
-
if (action === 'start') {
|
|
234
|
-
this.assets[assetID] = { ...item.data, stream: new stream_1.PassThrough() };
|
|
235
|
-
writeAsync(assetsStream, this.assets[assetID]);
|
|
236
|
-
}
|
|
237
|
-
if (action === 'stream') {
|
|
238
|
-
// The buffer has gone through JSON operations and is now of shape { type: "Buffer"; data: UInt8Array }
|
|
239
|
-
// We need to transform it back into a Buffer instance
|
|
240
|
-
const rawBuffer = item.data;
|
|
241
|
-
const chunk = Buffer.from(rawBuffer.data);
|
|
242
|
-
await writeAsync(this.assets[assetID].stream, chunk);
|
|
243
|
-
}
|
|
244
|
-
if (action === 'end') {
|
|
245
|
-
await new Promise((resolve, reject) => {
|
|
246
|
-
const { stream: assetStream } = this.assets[assetID];
|
|
247
|
-
assetStream
|
|
248
|
-
.on('close', () => {
|
|
249
|
-
delete this.assets[assetID];
|
|
250
|
-
resolve();
|
|
251
|
-
})
|
|
252
|
-
.on('error', reject)
|
|
253
|
-
.end();
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
onClose() {
|
|
259
|
-
this.teardown();
|
|
260
|
-
},
|
|
261
|
-
onError(err) {
|
|
262
|
-
this.teardown();
|
|
263
|
-
strapi.log.error(err);
|
|
264
|
-
},
|
|
265
|
-
// Commands
|
|
266
|
-
async init(params) {
|
|
267
|
-
if (this.transferID || this.provider) {
|
|
268
|
-
throw new Error('Transfer already in progress');
|
|
269
|
-
}
|
|
270
|
-
await this.verifyAuth();
|
|
271
|
-
this.transferID = (0, crypto_1.randomUUID)();
|
|
272
|
-
this.startedAt = Date.now();
|
|
273
|
-
this.assets = {};
|
|
274
|
-
this.streams = {};
|
|
275
|
-
this.flow = (0, flows_1.createFlow)(flows_1.DEFAULT_TRANSFER_FLOW);
|
|
276
|
-
this.provider = (0, providers_2.createLocalStrapiDestinationProvider)({
|
|
277
|
-
...params.options,
|
|
278
|
-
autoDestroy: false,
|
|
279
|
-
getStrapi: () => strapi,
|
|
280
|
-
});
|
|
281
|
-
return { transferID: this.transferID };
|
|
282
|
-
},
|
|
283
|
-
async status() {
|
|
284
|
-
const isStarted = this.isTransferStarted();
|
|
285
|
-
if (isStarted) {
|
|
286
|
-
const startedAt = this.startedAt;
|
|
287
|
-
return {
|
|
288
|
-
active: true,
|
|
289
|
-
kind: TRANSFER_KIND,
|
|
290
|
-
startedAt,
|
|
291
|
-
elapsed: Date.now() - startedAt,
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
return { active: false, kind: null, elapsed: null, startedAt: null };
|
|
295
|
-
},
|
|
296
|
-
async end(params) {
|
|
297
|
-
await this.verifyAuth();
|
|
298
|
-
if (this.transferID !== params.transferID) {
|
|
299
|
-
throw new providers_1.ProviderTransferError('Bad transfer ID provided');
|
|
300
|
-
}
|
|
301
|
-
this.cleanup();
|
|
302
|
-
return { ok: true };
|
|
303
|
-
},
|
|
304
|
-
}));
|
|
305
|
-
//# sourceMappingURL=push.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push.js","sourceRoot":"","sources":["../../../../src/strapi/remote/handlers/push.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AACpC,mCAA+C;AAK/C,yDAAkE;AAClE,+CAAuE;AACvE,oCAA6D;AAE7D,mCAA0E;AAE1E,MAAM,sBAAsB,GAAG;IAC7B,WAAW;IAC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AAU,EAAE,CAAC;QAExB,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,EAAE;YACzC,MAAM,IAAI,iCAAqB,CAAC,0BAA0B,CAAC,CAAC;SAC7D;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;QAEf,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;CACF,CAAC,CAAC,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { Context } from 'koa';
|
|
3
|
-
import type { IncomingMessage } from 'http';
|
|
4
|
-
import type { ServerOptions } from 'ws';
|
|
5
|
-
import { WebSocket, WebSocketServer } from 'ws';
|
|
6
|
-
import type { Handler } from './abstract';
|
|
7
|
-
import type { Protocol } from '../../../../types';
|
|
8
|
-
import { TransferMethod } from '../constants';
|
|
9
|
-
type WSCallback = (client: WebSocket, request: IncomingMessage) => void;
|
|
10
|
-
export interface HandlerOptions {
|
|
11
|
-
verify: (ctx: Context, scope?: TransferMethod) => Promise<void>;
|
|
12
|
-
server?: ServerOptions;
|
|
13
|
-
}
|
|
14
|
-
export declare const transformUpgradeHeader: (header?: string) => string[];
|
|
15
|
-
/**
|
|
16
|
-
* Make sure that the upgrade header is a valid websocket one
|
|
17
|
-
*/
|
|
18
|
-
export declare const assertValidHeader: (ctx: Context) => void;
|
|
19
|
-
export declare const isDataTransferMessage: (message: unknown) => message is Protocol.Client.Message;
|
|
20
|
-
/**
|
|
21
|
-
* Handle the upgrade to ws connection
|
|
22
|
-
*/
|
|
23
|
-
export declare const handleWSUpgrade: (wss: WebSocketServer, ctx: Context, callback: WSCallback) => void;
|
|
24
|
-
export declare const handlerControllerFactory: <T extends Partial<Handler>>(implementation: (proto: Handler) => T) => (options: HandlerOptions) => (ctx: Context) => Promise<void>;
|
|
25
|
-
export {};
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handlerControllerFactory = exports.handleWSUpgrade = exports.isDataTransferMessage = exports.assertValidHeader = exports.transformUpgradeHeader = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
const ws_1 = require("ws");
|
|
6
|
-
const providers_1 = require("../../../errors/providers");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
8
|
-
const transformUpgradeHeader = (header = '') => {
|
|
9
|
-
return header.split(',').map((s) => s.trim().toLowerCase());
|
|
10
|
-
};
|
|
11
|
-
exports.transformUpgradeHeader = transformUpgradeHeader;
|
|
12
|
-
/**
|
|
13
|
-
* Make sure that the upgrade header is a valid websocket one
|
|
14
|
-
*/
|
|
15
|
-
const assertValidHeader = (ctx) => {
|
|
16
|
-
const upgradeHeader = (0, exports.transformUpgradeHeader)(ctx.headers.upgrade);
|
|
17
|
-
if (!upgradeHeader.includes('websocket')) {
|
|
18
|
-
throw new Error('Invalid Header');
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
exports.assertValidHeader = assertValidHeader;
|
|
22
|
-
const isDataTransferMessage = (message) => {
|
|
23
|
-
if (!message || typeof message !== 'object') {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
const { uuid, type } = message;
|
|
27
|
-
if (typeof uuid !== 'string' || typeof type !== 'string') {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (!['command', 'transfer'].includes(type)) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
return true;
|
|
34
|
-
};
|
|
35
|
-
exports.isDataTransferMessage = isDataTransferMessage;
|
|
36
|
-
/**
|
|
37
|
-
* Handle the upgrade to ws connection
|
|
38
|
-
*/
|
|
39
|
-
const handleWSUpgrade = (wss, ctx, callback) => {
|
|
40
|
-
(0, exports.assertValidHeader)(ctx);
|
|
41
|
-
wss.handleUpgrade(ctx.req, ctx.request.socket, Buffer.alloc(0), (client, request) => {
|
|
42
|
-
// Create a connection between the client & the server
|
|
43
|
-
wss.emit('connection', client, ctx.req);
|
|
44
|
-
// Invoke the ws callback
|
|
45
|
-
callback(client, request);
|
|
46
|
-
});
|
|
47
|
-
ctx.respond = false;
|
|
48
|
-
};
|
|
49
|
-
exports.handleWSUpgrade = handleWSUpgrade;
|
|
50
|
-
// Protocol related functions
|
|
51
|
-
const handlerControllerFactory = (implementation) => (options) => {
|
|
52
|
-
const { verify, server: serverOptions } = options ?? {};
|
|
53
|
-
const wss = new ws_1.WebSocket.Server({ ...serverOptions, noServer: true });
|
|
54
|
-
return async (ctx) => {
|
|
55
|
-
(0, exports.handleWSUpgrade)(wss, ctx, (ws) => {
|
|
56
|
-
const state = { id: undefined };
|
|
57
|
-
const messageUUIDs = new Set();
|
|
58
|
-
const prototype = {
|
|
59
|
-
// Transfer ID
|
|
60
|
-
get transferID() {
|
|
61
|
-
return state.id;
|
|
62
|
-
},
|
|
63
|
-
set transferID(id) {
|
|
64
|
-
state.id = id;
|
|
65
|
-
},
|
|
66
|
-
// Started at
|
|
67
|
-
get startedAt() {
|
|
68
|
-
return state.startedAt;
|
|
69
|
-
},
|
|
70
|
-
set startedAt(timestamp) {
|
|
71
|
-
state.startedAt = timestamp;
|
|
72
|
-
},
|
|
73
|
-
get response() {
|
|
74
|
-
return state.response;
|
|
75
|
-
},
|
|
76
|
-
set response(response) {
|
|
77
|
-
state.response = response;
|
|
78
|
-
},
|
|
79
|
-
addUUID(uuid) {
|
|
80
|
-
messageUUIDs.add(uuid);
|
|
81
|
-
},
|
|
82
|
-
hasUUID(uuid) {
|
|
83
|
-
return messageUUIDs.has(uuid);
|
|
84
|
-
},
|
|
85
|
-
isTransferStarted() {
|
|
86
|
-
return this.transferID !== undefined && this.startedAt !== undefined;
|
|
87
|
-
},
|
|
88
|
-
assertValidTransfer() {
|
|
89
|
-
const isStarted = this.isTransferStarted();
|
|
90
|
-
if (!isStarted) {
|
|
91
|
-
throw new Error('Invalid Transfer Process');
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
assertValidTransferCommand(command) {
|
|
95
|
-
const isDefined = typeof this[command] === 'function';
|
|
96
|
-
const isValidTransferCommand = constants_1.VALID_TRANSFER_COMMANDS.includes(command);
|
|
97
|
-
if (!isDefined || !isValidTransferCommand) {
|
|
98
|
-
throw new Error('Invalid transfer command');
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
respond(uuid, e, data) {
|
|
102
|
-
return new Promise((resolve, reject) => {
|
|
103
|
-
if (!uuid && !e) {
|
|
104
|
-
reject(new Error('Missing uuid for this message'));
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
this.response = {
|
|
108
|
-
uuid,
|
|
109
|
-
data,
|
|
110
|
-
e,
|
|
111
|
-
};
|
|
112
|
-
const payload = JSON.stringify({
|
|
113
|
-
uuid,
|
|
114
|
-
data: data ?? null,
|
|
115
|
-
error: e
|
|
116
|
-
? {
|
|
117
|
-
code: e?.name ?? 'ERR',
|
|
118
|
-
message: e?.message,
|
|
119
|
-
}
|
|
120
|
-
: null,
|
|
121
|
-
});
|
|
122
|
-
this.send(payload, (error) => (error ? reject(error) : resolve()));
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
send(message, cb) {
|
|
126
|
-
ws.send(message, cb);
|
|
127
|
-
},
|
|
128
|
-
confirm(message) {
|
|
129
|
-
return new Promise((resolve, reject) => {
|
|
130
|
-
const uuid = (0, crypto_1.randomUUID)();
|
|
131
|
-
const payload = JSON.stringify({ uuid, data: message });
|
|
132
|
-
this.send(payload, (error) => {
|
|
133
|
-
if (error) {
|
|
134
|
-
reject(error);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
const onResponse = (raw) => {
|
|
138
|
-
const response = JSON.parse(raw.toString());
|
|
139
|
-
if (response.uuid === uuid) {
|
|
140
|
-
if (response.error) {
|
|
141
|
-
return reject(new Error(response.error.message));
|
|
142
|
-
}
|
|
143
|
-
resolve(response.data ?? null);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
ws.once('message', onResponse);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
ws.once('message', onResponse);
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
async executeAndRespond(uuid, fn) {
|
|
153
|
-
try {
|
|
154
|
-
const response = await fn();
|
|
155
|
-
this.respond(uuid, null, response);
|
|
156
|
-
}
|
|
157
|
-
catch (e) {
|
|
158
|
-
if (e instanceof Error) {
|
|
159
|
-
this.respond(uuid, e);
|
|
160
|
-
}
|
|
161
|
-
else if (typeof e === 'string') {
|
|
162
|
-
this.respond(uuid, new providers_1.ProviderTransferError(e));
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
this.respond(uuid, new providers_1.ProviderTransferError('Unexpected error', {
|
|
166
|
-
error: e,
|
|
167
|
-
}));
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
cleanup() {
|
|
172
|
-
this.transferID = undefined;
|
|
173
|
-
this.startedAt = undefined;
|
|
174
|
-
this.response = undefined;
|
|
175
|
-
},
|
|
176
|
-
teardown() {
|
|
177
|
-
this.cleanup();
|
|
178
|
-
},
|
|
179
|
-
verifyAuth(scope) {
|
|
180
|
-
return verify(ctx, scope);
|
|
181
|
-
},
|
|
182
|
-
// Transfer commands
|
|
183
|
-
init() { },
|
|
184
|
-
end() { },
|
|
185
|
-
status() { },
|
|
186
|
-
// Default prototype implementation for events
|
|
187
|
-
onMessage() { },
|
|
188
|
-
onError() { },
|
|
189
|
-
onClose() { },
|
|
190
|
-
};
|
|
191
|
-
const handler = Object.assign(Object.create(prototype), implementation(prototype));
|
|
192
|
-
// Bind ws events to handler methods
|
|
193
|
-
ws.on('close', (...args) => handler.onClose(...args));
|
|
194
|
-
ws.on('error', (...args) => handler.onError(...args));
|
|
195
|
-
ws.on('message', (...args) => handler.onMessage(...args));
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
};
|
|
199
|
-
exports.handlerControllerFactory = handlerControllerFactory;
|
|
200
|
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|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.handlers = exports.constants = void 0;
|
|
27
|
-
exports.constants = __importStar(require("./constants"));
|
|
28
|
-
exports.handlers = __importStar(require("./handlers"));
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/strapi/remote/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAyC;AACzC,uDAAuC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Cipher } from 'crypto';
|
|
2
|
-
import { Algorithm } from '../../../types';
|
|
3
|
-
/**
|
|
4
|
-
* It creates a cipher instance used for decryption
|
|
5
|
-
*
|
|
6
|
-
* @param key - The decryption key
|
|
7
|
-
* @param algorithm - The algorithm to use to create the Cipher
|
|
8
|
-
*
|
|
9
|
-
* @returns A {@link Cipher} instance created with the given key & algorithm
|
|
10
|
-
*/
|
|
11
|
-
export declare const createDecryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDecryptionCipher = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
// different key values depending on algorithm chosen
|
|
6
|
-
const getDecryptionStrategy = (algorithm) => {
|
|
7
|
-
const strategies = {
|
|
8
|
-
'aes-128-ecb'(key) {
|
|
9
|
-
const hashedKey = (0, crypto_1.scryptSync)(key, '', 16);
|
|
10
|
-
const initVector = null;
|
|
11
|
-
const securityKey = hashedKey;
|
|
12
|
-
return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
|
|
13
|
-
},
|
|
14
|
-
aes128(key) {
|
|
15
|
-
const hashedKey = (0, crypto_1.scryptSync)(key, '', 32);
|
|
16
|
-
const initVector = hashedKey.slice(16);
|
|
17
|
-
const securityKey = hashedKey.slice(0, 16);
|
|
18
|
-
return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
|
|
19
|
-
},
|
|
20
|
-
aes192(key) {
|
|
21
|
-
const hashedKey = (0, crypto_1.scryptSync)(key, '', 40);
|
|
22
|
-
const initVector = hashedKey.slice(24);
|
|
23
|
-
const securityKey = hashedKey.slice(0, 24);
|
|
24
|
-
return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
|
|
25
|
-
},
|
|
26
|
-
aes256(key) {
|
|
27
|
-
const hashedKey = (0, crypto_1.scryptSync)(key, '', 48);
|
|
28
|
-
const initVector = hashedKey.slice(32);
|
|
29
|
-
const securityKey = hashedKey.slice(0, 32);
|
|
30
|
-
return (0, crypto_1.createDecipheriv)(algorithm, securityKey, initVector);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
return strategies[algorithm];
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* It creates a cipher instance used for decryption
|
|
37
|
-
*
|
|
38
|
-
* @param key - The decryption key
|
|
39
|
-
* @param algorithm - The algorithm to use to create the Cipher
|
|
40
|
-
*
|
|
41
|
-
* @returns A {@link Cipher} instance created with the given key & algorithm
|
|
42
|
-
*/
|
|
43
|
-
const createDecryptionCipher = (key, algorithm = 'aes-128-ecb') => {
|
|
44
|
-
return getDecryptionStrategy(algorithm)(key);
|
|
45
|
-
};
|
|
46
|
-
exports.createDecryptionCipher = createDecryptionCipher;
|
|
47
|
-
//# sourceMappingURL=decrypt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../../src/utils/encryption/decrypt.ts"],"names":[],"mappings":";;;AAAA,mCAAqF;AAGrF,qDAAqD;AACrD,MAAM,qBAAqB,GAAG,CAAC,SAAoB,EAAsB,EAAE;IACzE,MAAM,UAAU,GAAe;QAC7B,aAAa,CAAC,GAAW;YACvB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,IAAI,CAAC;YAC3C,MAAM,WAAW,GAAc,SAAS,CAAC;YACzC,OAAO,IAAA,yBAAgB,EAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,CAAC,GAAW;YAChB,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,MAAM,UAAU,GAAsB,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC1D,MAAM,WAAW,GAAc,SAAS,CAAC,KAA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