@unchainedshop/plugins 4.0.0-rc.15 → 4.0.0-rc.16
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/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +11 -22
- package/lib/files/gridfs/handler-express.js.map +1 -1
- package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
- package/lib/files/gridfs/handler-fastify.js +34 -9
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/minio/handler-express.d.ts.map +1 -1
- package/lib/files/minio/handler-express.js +3 -6
- package/lib/files/minio/handler-express.js.map +1 -1
- package/lib/files/minio/handler-fastify.js +1 -1
- package/lib/files/minio/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/handler-express.d.ts.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +3 -6
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +2 -2
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +3 -6
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/handler-express.js +5 -10
- package/lib/payment/datatrans-v2/handler-express.js.map +1 -1
- package/lib/payment/datatrans-v2/handler-fastify.js +4 -4
- package/lib/payment/datatrans-v2/handler-fastify.js.map +1 -1
- package/lib/payment/payrexx/handler-express.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-express.js +12 -14
- package/lib/payment/payrexx/handler-express.js.map +1 -1
- package/lib/payment/payrexx/handler-fastify.d.ts.map +1 -1
- package/lib/payment/payrexx/handler-fastify.js +20 -14
- package/lib/payment/payrexx/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +3 -6
- package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.js +2 -2
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/saferpay/handler-express.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-express.js +7 -7
- package/lib/payment/saferpay/handler-express.js.map +1 -1
- package/lib/payment/saferpay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/saferpay/handler-fastify.js +8 -4
- package/lib/payment/saferpay/handler-fastify.js.map +1 -1
- package/lib/payment/stripe/handler-express.d.ts.map +1 -1
- package/lib/payment/stripe/handler-express.js +16 -16
- package/lib/payment/stripe/handler-express.js.map +1 -1
- package/lib/payment/stripe/handler-fastify.d.ts.map +1 -1
- package/lib/payment/stripe/handler-fastify.js +24 -11
- package/lib/payment/stripe/handler-fastify.js.map +1 -1
- package/lib/worker/bulk-import.d.ts.map +1 -1
- package/lib/worker/bulk-import.js +7 -30
- package/lib/worker/bulk-import.js.map +1 -1
- package/package.json +2 -4
- package/src/files/gridfs/handler-express.ts +11 -22
- package/src/files/gridfs/handler-fastify.ts +35 -10
- package/src/files/minio/handler-express.ts +3 -6
- package/src/files/minio/handler-fastify.ts +1 -1
- package/src/payment/apple-iap/handler-express.ts +3 -6
- package/src/payment/apple-iap/handler-fastify.ts +2 -2
- package/src/payment/cryptopay/handler-express.ts +3 -6
- package/src/payment/datatrans-v2/handler-express.ts +5 -10
- package/src/payment/datatrans-v2/handler-fastify.ts +4 -4
- package/src/payment/payrexx/handler-express.ts +21 -31
- package/src/payment/payrexx/handler-fastify.ts +28 -29
- package/src/payment/postfinance-checkout/handler-express.ts +3 -6
- package/src/payment/postfinance-checkout/handler-fastify.ts +2 -2
- package/src/payment/saferpay/handler-express.ts +10 -12
- package/src/payment/saferpay/handler-fastify.ts +10 -8
- package/src/payment/stripe/handler-express.ts +24 -32
- package/src/payment/stripe/handler-fastify.ts +31 -26
- package/src/worker/bulk-import.ts +9 -49
|
@@ -21,8 +21,10 @@ export const stripeHandler = async (request, response) => {
|
|
|
21
21
|
event = stripe.webhooks.constructEvent(request.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
22
22
|
} catch (err) {
|
|
23
23
|
logger.error(`Error constructing event: ${err.message}`);
|
|
24
|
-
response.
|
|
25
|
-
|
|
24
|
+
response.status(400).send({
|
|
25
|
+
message: err.message,
|
|
26
|
+
name: err.name,
|
|
27
|
+
});
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -30,13 +32,10 @@ export const stripeHandler = async (request, response) => {
|
|
|
30
32
|
logger.info(`unhandled event type`, {
|
|
31
33
|
type: event.type,
|
|
32
34
|
});
|
|
33
|
-
response.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
35
|
+
response.status(200).send({
|
|
36
|
+
ignored: true,
|
|
37
|
+
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
38
|
+
});
|
|
40
39
|
return;
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -47,13 +46,10 @@ export const stripeHandler = async (request, response) => {
|
|
|
47
46
|
type: event.type,
|
|
48
47
|
environment: environmentInMetadata,
|
|
49
48
|
});
|
|
50
|
-
response.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
55
|
-
}),
|
|
56
|
-
);
|
|
49
|
+
response.status(200).send({
|
|
50
|
+
ignored: true,
|
|
51
|
+
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
52
|
+
});
|
|
57
53
|
return;
|
|
58
54
|
}
|
|
59
55
|
|
|
@@ -89,13 +85,10 @@ export const stripeHandler = async (request, response) => {
|
|
|
89
85
|
orderId: order._id,
|
|
90
86
|
type: event.type,
|
|
91
87
|
});
|
|
92
|
-
response.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
orderId: order._id,
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
88
|
+
response.status(200).send({
|
|
89
|
+
message: 'checkout successful',
|
|
90
|
+
orderId: order._id,
|
|
91
|
+
});
|
|
99
92
|
} else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
|
|
100
93
|
const setupIntent = event.data.object;
|
|
101
94
|
const { paymentProviderId, userId } = setupIntent.metadata || {};
|
|
@@ -118,19 +111,18 @@ export const stripeHandler = async (request, response) => {
|
|
|
118
111
|
paymentCredentialsId: paymentCredentials?._id,
|
|
119
112
|
type: event.type,
|
|
120
113
|
});
|
|
121
|
-
response.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
paymentCredentialsId: paymentCredentials?._id,
|
|
126
|
-
}),
|
|
127
|
-
);
|
|
114
|
+
response.status(200).send({
|
|
115
|
+
message: 'payment credentials registration successful',
|
|
116
|
+
paymentCredentialsId: paymentCredentials?._id,
|
|
117
|
+
});
|
|
128
118
|
}
|
|
129
119
|
} catch (error) {
|
|
130
120
|
logger.error(error, {
|
|
131
121
|
type: event.type,
|
|
132
122
|
});
|
|
133
|
-
response.
|
|
134
|
-
|
|
123
|
+
response.status(500).send({
|
|
124
|
+
message: error.message,
|
|
125
|
+
name: error.name,
|
|
126
|
+
});
|
|
135
127
|
}
|
|
136
128
|
};
|
|
@@ -28,7 +28,11 @@ export const stripeHandler: RouteHandlerMethod = async (
|
|
|
28
28
|
} catch (err) {
|
|
29
29
|
logger.error(`Error constructing event: ${err.message}`);
|
|
30
30
|
reply.status(400);
|
|
31
|
-
return reply.send(
|
|
31
|
+
return reply.send({
|
|
32
|
+
success: false,
|
|
33
|
+
message: err.message,
|
|
34
|
+
name: err.name,
|
|
35
|
+
});
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
if (!Object.values(WebhookEventTypes).includes(event.type)) {
|
|
@@ -36,12 +40,12 @@ export const stripeHandler: RouteHandlerMethod = async (
|
|
|
36
40
|
type: event.type,
|
|
37
41
|
});
|
|
38
42
|
reply.status(200);
|
|
39
|
-
return reply.send(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
43
|
+
return reply.send({
|
|
44
|
+
success: false,
|
|
45
|
+
ignored: true,
|
|
46
|
+
name: 'UNHANDLED_EVENT_TYPE',
|
|
47
|
+
message: `Unhandled event type: ${event.type}. Supported types: ${Object.values(WebhookEventTypes).join(', ')}`,
|
|
48
|
+
});
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
const environmentInMetadata = event.data?.object?.metadata?.environment || '';
|
|
@@ -52,12 +56,12 @@ export const stripeHandler: RouteHandlerMethod = async (
|
|
|
52
56
|
environment: environmentInMetadata,
|
|
53
57
|
});
|
|
54
58
|
reply.status(200);
|
|
55
|
-
return reply.send(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
);
|
|
59
|
+
return reply.send({
|
|
60
|
+
success: false,
|
|
61
|
+
ignored: true,
|
|
62
|
+
name: 'UNHANDLED_EVENT_ENVIRONMENT',
|
|
63
|
+
message: `Unhandled event environment: ${environmentInMetadata}. Supported environment: ${environmentInEnv}`,
|
|
64
|
+
});
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
logger.info(`Processing event`, {
|
|
@@ -93,12 +97,10 @@ export const stripeHandler: RouteHandlerMethod = async (
|
|
|
93
97
|
type: event.type,
|
|
94
98
|
});
|
|
95
99
|
reply.status(200);
|
|
96
|
-
return reply.send(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}),
|
|
101
|
-
);
|
|
100
|
+
return reply.send({
|
|
101
|
+
success: true,
|
|
102
|
+
orderId: order._id,
|
|
103
|
+
});
|
|
102
104
|
} else if (event.type === WebhookEventTypes.SETUP_INTENT_SUCCEEDED) {
|
|
103
105
|
const setupIntent = event.data.object;
|
|
104
106
|
const { paymentProviderId, userId } = setupIntent.metadata || {};
|
|
@@ -122,18 +124,21 @@ export const stripeHandler: RouteHandlerMethod = async (
|
|
|
122
124
|
type: event.type,
|
|
123
125
|
});
|
|
124
126
|
reply.status(200);
|
|
125
|
-
return reply.send(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
);
|
|
127
|
+
return reply.send({
|
|
128
|
+
success: true,
|
|
129
|
+
message: 'payment credentials registration successful',
|
|
130
|
+
paymentCredentialsId: paymentCredentials?._id,
|
|
131
|
+
});
|
|
131
132
|
}
|
|
132
133
|
} catch (error) {
|
|
133
134
|
logger.error(error, {
|
|
134
135
|
type: event.type,
|
|
135
136
|
});
|
|
136
137
|
reply.status(500);
|
|
137
|
-
return reply.send(
|
|
138
|
+
return reply.send({
|
|
139
|
+
success: false,
|
|
140
|
+
message: error.message,
|
|
141
|
+
name: error.name,
|
|
142
|
+
});
|
|
138
143
|
}
|
|
139
144
|
};
|
|
@@ -1,56 +1,8 @@
|
|
|
1
1
|
import { WorkerDirector, WorkerAdapter, IWorkerAdapter } from '@unchainedshop/core';
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
import JSONStream from 'JSONStream';
|
|
4
|
-
import { EventIterator } from 'event-iterator';
|
|
5
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
6
3
|
|
|
7
4
|
const logger = createLogger('unchained:worker:bulk-import');
|
|
8
5
|
|
|
9
|
-
const streamPayloadToBulkImporter = async (
|
|
10
|
-
bulkImporter,
|
|
11
|
-
payloadId,
|
|
12
|
-
unchainedAPI: Pick<UnchainedCore, 'bulkImporter' | 'modules' | 'services'>,
|
|
13
|
-
) => {
|
|
14
|
-
logger.trace(`parseAsync start`);
|
|
15
|
-
|
|
16
|
-
const readStream = await unchainedAPI.services.files.createDownloadStream({ fileId: payloadId });
|
|
17
|
-
|
|
18
|
-
if (!readStream) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
'The current file adapter does not support streams when downloading required for streamed events. Please use a different file adapter.',
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const eventIterator = new EventIterator(
|
|
25
|
-
(queue) => {
|
|
26
|
-
const jsonStream = JSONStream.parse('events.*'); // rows, ANYTHING, doc
|
|
27
|
-
jsonStream.on('data', queue.push);
|
|
28
|
-
jsonStream.on('close', queue.stop);
|
|
29
|
-
jsonStream.on('error', queue.fail);
|
|
30
|
-
|
|
31
|
-
queue.on('highWater', () => readStream.pause());
|
|
32
|
-
queue.on('lowWater', () => readStream.resume());
|
|
33
|
-
|
|
34
|
-
readStream.pipe(jsonStream);
|
|
35
|
-
readStream.on('error', queue.fail);
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
jsonStream.removeListener('data', queue.push);
|
|
39
|
-
jsonStream.removeListener('close', queue.stop);
|
|
40
|
-
jsonStream.removeListener('error', queue.fail);
|
|
41
|
-
jsonStream.destroy();
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
{ highWaterMark: 100, lowWaterMark: 5 },
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
for await (const event of eventIterator) {
|
|
48
|
-
await bulkImporter.prepare(event, unchainedAPI);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
logger.trace(`parseAsync done`);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
6
|
export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
55
7
|
...WorkerAdapter,
|
|
56
8
|
|
|
@@ -76,7 +28,15 @@ export const BulkImportWorker: IWorkerAdapter<any, Record<string, unknown>> = {
|
|
|
76
28
|
|
|
77
29
|
if (rawPayload.payloadId) {
|
|
78
30
|
// stream payload from gridfs
|
|
79
|
-
|
|
31
|
+
const readStream = await unchainedAPI.services.files.createDownloadStream({
|
|
32
|
+
fileId: rawPayload.payloadId,
|
|
33
|
+
});
|
|
34
|
+
if (!readStream) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'The current file adapter does not support streams when downloading required for streamed events. Please use a different file adapter.',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
await unchainedAPI.bulkImporter.pipeEventStream(readStream, bulkImporter, unchainedAPI);
|
|
80
40
|
} else {
|
|
81
41
|
const { events } = rawPayload;
|
|
82
42
|
if (!events?.length) throw new Error('No events submitted');
|