@strapi/data-transfer 4.10.0-beta.0 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine/diagnostic.d.ts +10 -10
- package/dist/engine/diagnostic.js.map +1 -0
- package/dist/engine/errors.d.ts +2 -2
- package/dist/engine/errors.js.map +1 -0
- package/dist/engine/index.d.ts +1 -1
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/validation/index.js.map +1 -0
- package/dist/engine/validation/provider.js.map +1 -0
- package/dist/engine/validation/schemas/index.js +29 -12
- package/dist/engine/validation/schemas/index.js.map +1 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/constants.d.ts +1 -1
- package/dist/errors/constants.js.map +1 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/providers.d.ts +2 -2
- package/dist/errors/providers.js.map +1 -0
- package/dist/file/index.js.map +1 -0
- package/dist/file/providers/destination/index.d.ts +1 -0
- package/dist/file/providers/destination/index.js +2 -1
- package/dist/file/providers/destination/index.js.map +1 -0
- package/dist/file/providers/destination/utils.d.ts +1 -1
- package/dist/file/providers/destination/utils.js +2 -1
- package/dist/file/providers/destination/utils.js.map +1 -0
- package/dist/file/providers/index.js.map +1 -0
- package/dist/file/providers/source/index.d.ts +1 -1
- package/dist/file/providers/source/index.js +34 -24
- package/dist/file/providers/source/index.js.map +1 -0
- package/dist/file/providers/source/utils.d.ts +37 -0
- package/dist/file/providers/source/utils.js +62 -0
- package/dist/file/providers/source/utils.js.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/strapi/index.js.map +1 -0
- package/dist/strapi/providers/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.d.ts +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/configuration.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/index.d.ts +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -0
- package/dist/strapi/providers/local-destination/strategies/restore/links.d.ts +1 -1
- package/dist/strapi/providers/local-destination/strategies/restore/links.js.map +1 -0
- package/dist/strapi/providers/local-source/assets.js.map +1 -0
- package/dist/strapi/providers/local-source/configuration.js.map +1 -0
- package/dist/strapi/providers/local-source/entities.js.map +1 -0
- package/dist/strapi/providers/local-source/index.d.ts +1 -1
- package/dist/strapi/providers/local-source/index.js.map +1 -0
- package/dist/strapi/providers/local-source/links.js.map +1 -0
- package/dist/strapi/providers/remote-destination/index.js +4 -19
- package/dist/strapi/providers/remote-destination/index.js.map +1 -0
- package/dist/strapi/providers/remote-source/index.js +3 -4
- package/dist/strapi/providers/remote-source/index.js.map +1 -0
- package/dist/strapi/providers/utils.d.ts +8 -3
- package/dist/strapi/providers/utils.js +22 -1
- package/dist/strapi/providers/utils.js.map +1 -0
- package/dist/strapi/queries/entity.js.map +1 -0
- package/dist/strapi/queries/index.js.map +1 -0
- package/dist/strapi/queries/link.js.map +1 -0
- package/dist/strapi/remote/constants.d.ts +2 -2
- package/dist/strapi/remote/constants.js.map +1 -0
- package/dist/strapi/remote/flows/default.js.map +1 -0
- package/dist/strapi/remote/flows/index.d.ts +1 -1
- package/dist/strapi/remote/flows/index.js.map +1 -0
- package/dist/strapi/remote/handlers/abstract.d.ts +1 -1
- package/dist/strapi/remote/handlers/abstract.js.map +1 -0
- package/dist/strapi/remote/handlers/constants.d.ts +1 -1
- package/dist/strapi/remote/handlers/constants.js.map +1 -0
- package/dist/strapi/remote/handlers/index.js.map +1 -0
- package/dist/strapi/remote/handlers/pull.d.ts +1 -1
- package/dist/strapi/remote/handlers/pull.js.map +1 -0
- package/dist/strapi/remote/handlers/push.d.ts +1 -1
- package/dist/strapi/remote/handlers/push.js.map +1 -0
- package/dist/strapi/remote/handlers/utils.d.ts +1 -1
- package/dist/strapi/remote/handlers/utils.js.map +1 -0
- package/dist/strapi/remote/index.js.map +1 -0
- package/dist/utils/encryption/decrypt.js.map +1 -0
- package/dist/utils/encryption/encrypt.js.map +1 -0
- package/dist/utils/encryption/index.js.map +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json.d.ts +1 -1
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/providers.d.ts +1 -1
- package/dist/utils/providers.js.map +1 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/stream.d.ts +1 -1
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/transaction.js.map +1 -0
- package/package.json +18 -17
- package/jest.config.js +0 -14
- package/lib/engine/diagnostic.d.ts +0 -40
- package/lib/engine/diagnostic.js +0 -50
- package/lib/engine/errors.d.ts +0 -28
- package/lib/engine/errors.js +0 -29
- package/lib/engine/index.d.ts +0 -44
- package/lib/engine/index.js +0 -506
- package/lib/engine/validation/index.d.ts +0 -2
- package/lib/engine/validation/index.js +0 -19
- package/lib/engine/validation/provider.d.ts +0 -3
- package/lib/engine/validation/provider.js +0 -18
- package/lib/engine/validation/schemas/index.d.ts +0 -7
- package/lib/engine/validation/schemas/index.js +0 -53
- package/lib/errors/base.d.ts +0 -8
- package/lib/errors/base.js +0 -13
- package/lib/errors/constants.d.ts +0 -3
- package/lib/errors/constants.js +0 -9
- package/lib/errors/index.d.ts +0 -2
- package/lib/errors/index.js +0 -19
- package/lib/errors/providers.d.ts +0 -21
- package/lib/errors/providers.js +0 -32
- package/lib/file/index.d.ts +0 -1
- package/lib/file/index.js +0 -28
- package/lib/file/providers/destination/index.d.ts +0 -45
- package/lib/file/providers/destination/index.js +0 -174
- package/lib/file/providers/destination/utils.d.ts +0 -9
- package/lib/file/providers/destination/utils.js +0 -61
- package/lib/file/providers/index.d.ts +0 -2
- package/lib/file/providers/index.js +0 -19
- package/lib/file/providers/source/index.d.ts +0 -40
- package/lib/file/providers/source/index.js +0 -220
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -31
- package/lib/strapi/index.d.ts +0 -3
- package/lib/strapi/index.js +0 -30
- package/lib/strapi/providers/index.d.ts +0 -3
- package/lib/strapi/providers/index.js +0 -22
- package/lib/strapi/providers/local-destination/index.d.ts +0 -34
- package/lib/strapi/providers/local-destination/index.js +0 -220
- package/lib/strapi/providers/local-destination/strategies/index.d.ts +0 -1
- package/lib/strapi/providers/local-destination/strategies/index.js +0 -28
- package/lib/strapi/providers/local-destination/strategies/restore/configuration.d.ts +0 -5
- package/lib/strapi/providers/local-destination/strategies/restore/configuration.js +0 -51
- package/lib/strapi/providers/local-destination/strategies/restore/entities.d.ts +0 -11
- package/lib/strapi/providers/local-destination/strategies/restore/entities.js +0 -103
- package/lib/strapi/providers/local-destination/strategies/restore/index.d.ts +0 -32
- package/lib/strapi/providers/local-destination/strategies/restore/index.js +0 -107
- package/lib/strapi/providers/local-destination/strategies/restore/links.d.ts +0 -4
- package/lib/strapi/providers/local-destination/strategies/restore/links.js +0 -32
- package/lib/strapi/providers/local-source/assets.d.ts +0 -5
- package/lib/strapi/providers/local-source/assets.js +0 -31
- package/lib/strapi/providers/local-source/configuration.d.ts +0 -5
- package/lib/strapi/providers/local-source/configuration.js +0 -36
- package/lib/strapi/providers/local-source/entities.d.ts +0 -10
- package/lib/strapi/providers/local-source/entities.js +0 -85
- package/lib/strapi/providers/local-source/index.d.ts +0 -27
- package/lib/strapi/providers/local-source/index.js +0 -98
- package/lib/strapi/providers/local-source/links.d.ts +0 -5
- package/lib/strapi/providers/local-source/links.js +0 -23
- package/lib/strapi/providers/remote-destination/index.d.ts +0 -37
- package/lib/strapi/providers/remote-destination/index.js +0 -284
- package/lib/strapi/providers/remote-destination/utils.d.ts +0 -31
- package/lib/strapi/providers/remote-destination/utils.js +0 -72
- package/lib/strapi/queries/entity.d.ts +0 -19
- package/lib/strapi/queries/entity.js +0 -130
- package/lib/strapi/queries/index.d.ts +0 -2
- package/lib/strapi/queries/index.js +0 -29
- package/lib/strapi/queries/link.d.ts +0 -6
- package/lib/strapi/queries/link.js +0 -215
- package/lib/strapi/remote/constants.d.ts +0 -2
- package/lib/strapi/remote/constants.js +0 -6
- package/lib/strapi/remote/controllers/index.d.ts +0 -1
- package/lib/strapi/remote/controllers/index.js +0 -18
- package/lib/strapi/remote/controllers/push.d.ts +0 -26
- package/lib/strapi/remote/controllers/push.js +0 -116
- package/lib/strapi/remote/flows/default.d.ts +0 -3
- package/lib/strapi/remote/flows/default.js +0 -41
- package/lib/strapi/remote/flows/index.d.ts +0 -18
- package/lib/strapi/remote/flows/index.js +0 -59
- package/lib/strapi/remote/handlers.d.ts +0 -10
- package/lib/strapi/remote/handlers.js +0 -285
- package/lib/strapi/remote/index.d.ts +0 -3
- package/lib/strapi/remote/index.js +0 -30
- package/lib/utils/encryption/decrypt.d.ts +0 -11
- package/lib/utils/encryption/decrypt.js +0 -47
- package/lib/utils/encryption/encrypt.d.ts +0 -11
- package/lib/utils/encryption/encrypt.js +0 -47
- package/lib/utils/encryption/index.d.ts +0 -2
- package/lib/utils/encryption/index.js +0 -19
- package/lib/utils/index.d.ts +0 -5
- package/lib/utils/index.js +0 -32
- package/lib/utils/json.d.ts +0 -30
- package/lib/utils/json.js +0 -68
- package/lib/utils/providers.d.ts +0 -2
- package/lib/utils/providers.js +0 -11
- package/lib/utils/schema.d.ts +0 -7
- package/lib/utils/schema.js +0 -29
- package/lib/utils/stream.d.ts +0 -27
- package/lib/utils/stream.js +0 -59
- package/lib/utils/transaction.d.ts +0 -3
- package/lib/utils/transaction.js +0 -88
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createTransferHandler = void 0;
|
|
7
|
-
const crypto_1 = require("crypto");
|
|
8
|
-
const ws_1 = require("ws");
|
|
9
|
-
const push_1 = __importDefault(require("./controllers/push"));
|
|
10
|
-
const providers_1 = require("../../errors/providers");
|
|
11
|
-
const constants_1 = require("./constants");
|
|
12
|
-
const flows_1 = require("./flows");
|
|
13
|
-
const createTransferHandler = (options) => {
|
|
14
|
-
const { verify, server: serverOptions } = options;
|
|
15
|
-
// Create the websocket server
|
|
16
|
-
const wss = new ws_1.WebSocket.Server({ ...serverOptions, noServer: true });
|
|
17
|
-
return async (ctx) => {
|
|
18
|
-
const verifyAuth = (scope) => verify(ctx, scope);
|
|
19
|
-
const upgradeHeader = (ctx.request.headers.upgrade || '')
|
|
20
|
-
.split(',')
|
|
21
|
-
.map((s) => s.trim().toLowerCase());
|
|
22
|
-
if (upgradeHeader.includes('websocket')) {
|
|
23
|
-
wss.handleUpgrade(ctx.req, ctx.request.socket, Buffer.alloc(0), (ws) => {
|
|
24
|
-
// Create a connection between the client & the server
|
|
25
|
-
wss.emit('connection', ws, ctx.req);
|
|
26
|
-
const state = {};
|
|
27
|
-
let uuid;
|
|
28
|
-
function assertValidTransfer(transferState) {
|
|
29
|
-
const { transfer, controller } = transferState;
|
|
30
|
-
if (!controller || !transfer) {
|
|
31
|
-
throw new providers_1.ProviderTransferError('Invalid transfer process');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Format error & message to follow the remote transfer protocol
|
|
36
|
-
*/
|
|
37
|
-
const callback = (e = null, data) => {
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
if (!uuid && !e) {
|
|
40
|
-
reject(new Error('Missing uuid for this message'));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const payload = JSON.stringify({
|
|
44
|
-
uuid,
|
|
45
|
-
data: data ?? null,
|
|
46
|
-
error: e
|
|
47
|
-
? {
|
|
48
|
-
code: 'ERR',
|
|
49
|
-
message: e?.message,
|
|
50
|
-
}
|
|
51
|
-
: null,
|
|
52
|
-
});
|
|
53
|
-
ws.send(payload, (error) => (error ? reject(error) : resolve()));
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Wrap a function call to catch errors and answer the request with the correct format
|
|
58
|
-
*/
|
|
59
|
-
const answer = async (fn) => {
|
|
60
|
-
try {
|
|
61
|
-
const response = await fn();
|
|
62
|
-
callback(null, response);
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
if (e instanceof Error) {
|
|
66
|
-
callback(e);
|
|
67
|
-
}
|
|
68
|
-
else if (typeof e === 'string') {
|
|
69
|
-
callback(new providers_1.ProviderTransferError(e));
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
callback(new providers_1.ProviderTransferError('Unexpected error', {
|
|
73
|
-
error: e,
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const cleanup = () => {
|
|
79
|
-
delete state.controller;
|
|
80
|
-
delete state.transfer;
|
|
81
|
-
};
|
|
82
|
-
const teardown = async () => {
|
|
83
|
-
if (state.controller) {
|
|
84
|
-
await state.controller.actions.rollback();
|
|
85
|
-
}
|
|
86
|
-
cleanup();
|
|
87
|
-
};
|
|
88
|
-
const end = async (msg) => {
|
|
89
|
-
await verifyAuth(state.transfer?.kind);
|
|
90
|
-
if (msg.params.transferID !== state.transfer?.id) {
|
|
91
|
-
throw new providers_1.ProviderTransferError('Bad transfer ID provided');
|
|
92
|
-
}
|
|
93
|
-
cleanup();
|
|
94
|
-
return { ok: true };
|
|
95
|
-
};
|
|
96
|
-
const init = async (msg) => {
|
|
97
|
-
// TODO: For push transfer, we'll probably have to trigger a
|
|
98
|
-
// maintenance mode to prevent other transfer at the same time.
|
|
99
|
-
if (state.transfer || state.controller) {
|
|
100
|
-
throw new providers_1.ProviderInitializationError('Transfer already in progres');
|
|
101
|
-
}
|
|
102
|
-
const { transfer } = msg.params;
|
|
103
|
-
await verifyAuth(transfer);
|
|
104
|
-
// Push transfer
|
|
105
|
-
if (transfer === 'push') {
|
|
106
|
-
const { options: controllerOptions } = msg.params;
|
|
107
|
-
state.controller = (0, push_1.default)({
|
|
108
|
-
...controllerOptions,
|
|
109
|
-
autoDestroy: false,
|
|
110
|
-
getStrapi: () => strapi,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
// Pull or any other string
|
|
114
|
-
else {
|
|
115
|
-
throw new providers_1.ProviderTransferError(`Transfer type not implemented: "${transfer}"`, {
|
|
116
|
-
transfer,
|
|
117
|
-
validTransfers: constants_1.TRANSFER_METHODS,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
state.transfer = {
|
|
121
|
-
id: (0, crypto_1.randomUUID)(),
|
|
122
|
-
kind: transfer,
|
|
123
|
-
startedAt: Date.now(),
|
|
124
|
-
flow: (0, flows_1.createFlow)(flows_1.DEFAULT_TRANSFER_FLOW),
|
|
125
|
-
};
|
|
126
|
-
return { transferID: state.transfer.id };
|
|
127
|
-
};
|
|
128
|
-
const status = () => {
|
|
129
|
-
if (state.transfer) {
|
|
130
|
-
const { transfer } = state;
|
|
131
|
-
const elapsed = Date.now() - transfer.startedAt;
|
|
132
|
-
return {
|
|
133
|
-
active: true,
|
|
134
|
-
kind: transfer.kind,
|
|
135
|
-
startedAt: transfer.startedAt,
|
|
136
|
-
elapsed,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
return { active: false, kind: null, elapsed: null, startedAt: null };
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* On command message (init, end, status, ...)
|
|
143
|
-
*/
|
|
144
|
-
const onCommand = async (msg) => {
|
|
145
|
-
const { command } = msg;
|
|
146
|
-
if (command === 'init') {
|
|
147
|
-
await answer(() => init(msg));
|
|
148
|
-
}
|
|
149
|
-
if (command === 'end') {
|
|
150
|
-
await answer(() => {
|
|
151
|
-
assertValidTransfer(state);
|
|
152
|
-
end(msg);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
if (command === 'status') {
|
|
156
|
-
await answer(status);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const onTransferCommand = async (msg) => {
|
|
160
|
-
assertValidTransfer(state);
|
|
161
|
-
const { transferID, kind } = msg;
|
|
162
|
-
const { controller, transfer } = state;
|
|
163
|
-
await verifyAuth(transfer.kind);
|
|
164
|
-
// TODO: (re)move this check
|
|
165
|
-
// It shouldn't be possible to start a pull transfer for now, so reaching
|
|
166
|
-
// this code should be impossible too, but this has been added by security
|
|
167
|
-
if (transfer.kind === 'pull') {
|
|
168
|
-
return callback(new providers_1.ProviderTransferError('Pull transfer not implemented'));
|
|
169
|
-
}
|
|
170
|
-
if (!controller) {
|
|
171
|
-
return callback(new providers_1.ProviderTransferError("The transfer hasn't been initialized"));
|
|
172
|
-
}
|
|
173
|
-
if (!transferID) {
|
|
174
|
-
return callback(new providers_1.ProviderTransferError('Missing transfer ID'));
|
|
175
|
-
}
|
|
176
|
-
// Action
|
|
177
|
-
if (kind === 'action') {
|
|
178
|
-
const { action } = msg;
|
|
179
|
-
if (!(action in controller.actions)) {
|
|
180
|
-
return callback(new providers_1.ProviderTransferError(`Invalid action provided: "${action}"`, {
|
|
181
|
-
action,
|
|
182
|
-
validActions: Object.keys(controller.actions),
|
|
183
|
-
}));
|
|
184
|
-
}
|
|
185
|
-
const step = { kind: 'action', action };
|
|
186
|
-
const isStepRegistered = transfer.flow.has(step);
|
|
187
|
-
if (isStepRegistered) {
|
|
188
|
-
if (transfer.flow.cannot(step)) {
|
|
189
|
-
return callback(new providers_1.ProviderTransferError(`Invalid action "${action}" found for the current flow `, {
|
|
190
|
-
action,
|
|
191
|
-
}));
|
|
192
|
-
}
|
|
193
|
-
transfer.flow.set(step);
|
|
194
|
-
}
|
|
195
|
-
await answer(() => controller.actions[action]());
|
|
196
|
-
}
|
|
197
|
-
// Transfer
|
|
198
|
-
else if (kind === 'step') {
|
|
199
|
-
// We can only have push transfer message for the moment
|
|
200
|
-
const message = msg;
|
|
201
|
-
const currentStep = transfer.flow.get();
|
|
202
|
-
const step = { kind: 'transfer', stage: message.step };
|
|
203
|
-
// Lock the current transfer stage
|
|
204
|
-
if (message.action === 'start') {
|
|
205
|
-
if (currentStep?.kind === 'transfer' && currentStep.locked) {
|
|
206
|
-
return callback(new providers_1.ProviderTransferError(`It's not possible to start a new transfer stage (${message.step}) while another one is in progress (${currentStep.stage})`));
|
|
207
|
-
}
|
|
208
|
-
if (transfer.flow.cannot(step)) {
|
|
209
|
-
return callback(new providers_1.ProviderTransferError(`Invalid stage (${message.step}) provided for the current flow`, { step }));
|
|
210
|
-
}
|
|
211
|
-
transfer?.flow.set({ ...step, locked: true });
|
|
212
|
-
return callback(null, { ok: true });
|
|
213
|
-
}
|
|
214
|
-
// Stream operation on the current transfer stage
|
|
215
|
-
if (message.action === 'stream') {
|
|
216
|
-
if (currentStep?.kind === 'transfer' && !currentStep.locked) {
|
|
217
|
-
return callback(new providers_1.ProviderTransferError(`You need to initialize the transfer stage (${message.step}) before starting to stream data`));
|
|
218
|
-
}
|
|
219
|
-
if (transfer?.flow.cannot(step)) {
|
|
220
|
-
return callback(new providers_1.ProviderTransferError(`Invalid stage (${message.step}) provided for the current flow`, { step }));
|
|
221
|
-
}
|
|
222
|
-
await answer(() => controller.transfer[message.step]?.(message.data));
|
|
223
|
-
}
|
|
224
|
-
// Unlock the current transfer stage
|
|
225
|
-
if (message.action === 'end') {
|
|
226
|
-
// Cannot unlock if not locked (aka: started)
|
|
227
|
-
if (currentStep?.kind === 'transfer' && !currentStep.locked) {
|
|
228
|
-
return callback(new providers_1.ProviderTransferError(`You need to initialize the transfer stage (${message.step}) before ending it`));
|
|
229
|
-
}
|
|
230
|
-
// Cannot unlock if invalid step provided
|
|
231
|
-
if (transfer?.flow.cannot(step)) {
|
|
232
|
-
return callback(new providers_1.ProviderTransferError(`Invalid stage (${message.step}) provided for the current flow`, { step }));
|
|
233
|
-
}
|
|
234
|
-
transfer?.flow.set({ ...step, locked: false });
|
|
235
|
-
return callback(null, { ok: true });
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
ws.on('close', async () => {
|
|
240
|
-
await teardown();
|
|
241
|
-
});
|
|
242
|
-
ws.on('error', async (e) => {
|
|
243
|
-
await teardown();
|
|
244
|
-
strapi.log.error(e);
|
|
245
|
-
});
|
|
246
|
-
ws.on('message', async (raw) => {
|
|
247
|
-
try {
|
|
248
|
-
const msg = JSON.parse(raw.toString());
|
|
249
|
-
if (!msg.uuid) {
|
|
250
|
-
await callback(new providers_1.ProviderTransferError('Missing uuid in message'));
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
uuid = msg.uuid;
|
|
254
|
-
// Regular command message (init, end, status)
|
|
255
|
-
if (msg.type === 'command') {
|
|
256
|
-
await onCommand(msg);
|
|
257
|
-
}
|
|
258
|
-
// Transfer message (the transfer must be initialized first)
|
|
259
|
-
else if (msg.type === 'transfer') {
|
|
260
|
-
await onTransferCommand(msg);
|
|
261
|
-
}
|
|
262
|
-
// Invalid messages
|
|
263
|
-
else {
|
|
264
|
-
await callback(new providers_1.ProviderTransferError('Bad request'));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch (e) {
|
|
268
|
-
// Only known errors should be returned to client
|
|
269
|
-
if (e instanceof providers_1.ProviderError || e instanceof SyntaxError) {
|
|
270
|
-
await callback(e);
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
// TODO: log error to server?
|
|
274
|
-
// Unknown errors should not be sent to client
|
|
275
|
-
await callback(new providers_1.ProviderTransferError('Unknown transfer error'));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
ctx.respond = false;
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
};
|
|
284
|
-
exports.createTransferHandler = createTransferHandler;
|
|
285
|
-
//# sourceMappingURL=handlers.js.map
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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 = exports.controllers = void 0;
|
|
27
|
-
exports.controllers = __importStar(require("./controllers"));
|
|
28
|
-
exports.constants = __importStar(require("./constants"));
|
|
29
|
-
exports.handlers = __importStar(require("./handlers"));
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -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,11 +0,0 @@
|
|
|
1
|
-
import { Cipher } from 'crypto';
|
|
2
|
-
import { Algorithm } from '../../../types';
|
|
3
|
-
/**
|
|
4
|
-
* It creates a cipher instance used for encryption
|
|
5
|
-
*
|
|
6
|
-
* @param key - The encryption 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 createEncryptionCipher: (key: string, algorithm?: Algorithm) => Cipher;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createEncryptionCipher = void 0;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
// different key values depending on algorithm chosen
|
|
6
|
-
const getEncryptionStrategy = (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.createCipheriv)(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.createCipheriv)(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.createCipheriv)(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.createCipheriv)(algorithm, securityKey, initVector);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
return strategies[algorithm];
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* It creates a cipher instance used for encryption
|
|
37
|
-
*
|
|
38
|
-
* @param key - The encryption 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 createEncryptionCipher = (key, algorithm = 'aes-128-ecb') => {
|
|
44
|
-
return getEncryptionStrategy(algorithm)(key);
|
|
45
|
-
};
|
|
46
|
-
exports.createEncryptionCipher = createEncryptionCipher;
|
|
47
|
-
//# sourceMappingURL=encrypt.js.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./encrypt"), exports);
|
|
18
|
-
__exportStar(require("./decrypt"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.d.ts
DELETED
package/lib/utils/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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.transaction = exports.schema = exports.json = exports.stream = exports.encryption = void 0;
|
|
27
|
-
exports.encryption = __importStar(require("./encryption"));
|
|
28
|
-
exports.stream = __importStar(require("./stream"));
|
|
29
|
-
exports.json = __importStar(require("./json"));
|
|
30
|
-
exports.schema = __importStar(require("./schema"));
|
|
31
|
-
exports.transaction = __importStar(require("./transaction"));
|
|
32
|
-
//# sourceMappingURL=index.js.map
|
package/lib/utils/json.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compute differences between two JSON objects and returns them
|
|
3
|
-
*
|
|
4
|
-
* @param a - First object
|
|
5
|
-
* @param b - Second object
|
|
6
|
-
* @param ctx - Context used to keep track of the current path during recursion
|
|
7
|
-
*/
|
|
8
|
-
export declare const diff: (a: unknown, b: unknown, ctx?: Context) => Diff[];
|
|
9
|
-
export interface AddedDiff<T = unknown> {
|
|
10
|
-
kind: 'added';
|
|
11
|
-
path: string[];
|
|
12
|
-
type: string;
|
|
13
|
-
value: T;
|
|
14
|
-
}
|
|
15
|
-
export interface ModifiedDiff<T = unknown, P = unknown> {
|
|
16
|
-
kind: 'modified';
|
|
17
|
-
path: string[];
|
|
18
|
-
types: [string, string];
|
|
19
|
-
values: [T, P];
|
|
20
|
-
}
|
|
21
|
-
export interface DeletedDiff<T = unknown> {
|
|
22
|
-
kind: 'deleted';
|
|
23
|
-
path: string[];
|
|
24
|
-
type: string;
|
|
25
|
-
value: T;
|
|
26
|
-
}
|
|
27
|
-
export declare type Diff = AddedDiff | ModifiedDiff | DeletedDiff;
|
|
28
|
-
export interface Context {
|
|
29
|
-
path: string[];
|
|
30
|
-
}
|
package/lib/utils/json.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diff = void 0;
|
|
4
|
-
const fp_1 = require("lodash/fp");
|
|
5
|
-
const createContext = () => ({ path: [] });
|
|
6
|
-
/**
|
|
7
|
-
* Compute differences between two JSON objects and returns them
|
|
8
|
-
*
|
|
9
|
-
* @param a - First object
|
|
10
|
-
* @param b - Second object
|
|
11
|
-
* @param ctx - Context used to keep track of the current path during recursion
|
|
12
|
-
*/
|
|
13
|
-
const diff = (a, b, ctx = createContext()) => {
|
|
14
|
-
const diffs = [];
|
|
15
|
-
const { path } = ctx;
|
|
16
|
-
const aType = typeof a;
|
|
17
|
-
const bType = typeof b;
|
|
18
|
-
// Define helpers
|
|
19
|
-
const added = () => {
|
|
20
|
-
diffs.push({ kind: 'added', path, type: bType, value: b });
|
|
21
|
-
return diffs;
|
|
22
|
-
};
|
|
23
|
-
const deleted = () => {
|
|
24
|
-
diffs.push({ kind: 'deleted', path, type: aType, value: a });
|
|
25
|
-
return diffs;
|
|
26
|
-
};
|
|
27
|
-
const modified = () => {
|
|
28
|
-
diffs.push({
|
|
29
|
-
kind: 'modified',
|
|
30
|
-
path,
|
|
31
|
-
types: [aType, bType],
|
|
32
|
-
values: [a, b],
|
|
33
|
-
});
|
|
34
|
-
return diffs;
|
|
35
|
-
};
|
|
36
|
-
if ((0, fp_1.isArray)(a) && (0, fp_1.isArray)(b)) {
|
|
37
|
-
let k = 0;
|
|
38
|
-
for (const [aItem, bItem] of (0, fp_1.zip)(a, b)) {
|
|
39
|
-
const kCtx = { path: [...path, k.toString()] };
|
|
40
|
-
const kDiffs = (0, exports.diff)(aItem, bItem, kCtx);
|
|
41
|
-
diffs.push(...kDiffs);
|
|
42
|
-
k += 1;
|
|
43
|
-
}
|
|
44
|
-
return diffs;
|
|
45
|
-
}
|
|
46
|
-
if ((0, fp_1.isObject)(a) && (0, fp_1.isObject)(b)) {
|
|
47
|
-
const keys = (0, fp_1.uniq)(Object.keys(a).concat(Object.keys(b)));
|
|
48
|
-
for (const key of keys) {
|
|
49
|
-
const aValue = a[key];
|
|
50
|
-
const bValue = b[key];
|
|
51
|
-
const nestedDiffs = (0, exports.diff)(aValue, bValue, { path: [...path, key] });
|
|
52
|
-
diffs.push(...nestedDiffs);
|
|
53
|
-
}
|
|
54
|
-
return diffs;
|
|
55
|
-
}
|
|
56
|
-
if (!(0, fp_1.isEqual)(a, b)) {
|
|
57
|
-
if (aType === 'undefined') {
|
|
58
|
-
return added();
|
|
59
|
-
}
|
|
60
|
-
if (bType === 'undefined') {
|
|
61
|
-
return deleted();
|
|
62
|
-
}
|
|
63
|
-
return modified();
|
|
64
|
-
}
|
|
65
|
-
return diffs;
|
|
66
|
-
};
|
|
67
|
-
exports.diff = diff;
|
|
68
|
-
//# sourceMappingURL=json.js.map
|
package/lib/utils/providers.d.ts
DELETED
package/lib/utils/providers.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertValidStrapi = void 0;
|
|
4
|
-
const providers_1 = require("../errors/providers");
|
|
5
|
-
const assertValidStrapi = (strapi, msg = '') => {
|
|
6
|
-
if (!strapi) {
|
|
7
|
-
throw new providers_1.ProviderInitializationError(`${msg}. Strapi instance not found.`);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
exports.assertValidStrapi = assertValidStrapi;
|
|
11
|
-
//# sourceMappingURL=providers.js.map
|
package/lib/utils/schema.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="lodash" />
|
|
2
|
-
import type { Schema } from '@strapi/strapi';
|
|
3
|
-
/**
|
|
4
|
-
* Sanitize a schemas dictionnary by omiting unwanted properties
|
|
5
|
-
* The list of allowed properties can be found here: {@link VALID_SCHEMA_PROPERTIES}
|
|
6
|
-
*/
|
|
7
|
-
export declare const mapSchemasValues: (schemas: Record<string, Schema>) => import("lodash").Dictionary<Partial<Schema>>;
|
package/lib/utils/schema.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapSchemasValues = void 0;
|
|
4
|
-
const fp_1 = require("lodash/fp");
|
|
5
|
-
/**
|
|
6
|
-
* List of schema properties that should be kept when sanitizing schemas
|
|
7
|
-
*/
|
|
8
|
-
const VALID_SCHEMA_PROPERTIES = [
|
|
9
|
-
'collectionName',
|
|
10
|
-
'info',
|
|
11
|
-
'options',
|
|
12
|
-
'pluginOptions',
|
|
13
|
-
'attributes',
|
|
14
|
-
'kind',
|
|
15
|
-
'modelType',
|
|
16
|
-
'modelName',
|
|
17
|
-
'uid',
|
|
18
|
-
'plugin',
|
|
19
|
-
'globalId',
|
|
20
|
-
];
|
|
21
|
-
/**
|
|
22
|
-
* Sanitize a schemas dictionnary by omiting unwanted properties
|
|
23
|
-
* The list of allowed properties can be found here: {@link VALID_SCHEMA_PROPERTIES}
|
|
24
|
-
*/
|
|
25
|
-
const mapSchemasValues = (schemas) => {
|
|
26
|
-
return (0, fp_1.mapValues)((0, fp_1.pick)(VALID_SCHEMA_PROPERTIES), schemas);
|
|
27
|
-
};
|
|
28
|
-
exports.mapSchemasValues = mapSchemasValues;
|
|
29
|
-
//# sourceMappingURL=schema.js.map
|