@unchainedshop/plugins 2.0.0-beta5 → 2.0.0-beta7
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/delivery/pick-mup.d.ts +1 -0
- package/lib/delivery/pick-mup.js +1 -1
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +1 -0
- package/lib/files/gridfs/gridfs-adapter.js +0 -1
- package/lib/files/gridfs/gridfs-adapter.js.map +1 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts +1 -2
- package/lib/files/gridfs/gridfs-webhook.js +2 -6
- package/lib/files/gridfs/gridfs-webhook.js.map +1 -1
- package/lib/files/minio/minio-adapter.d.ts +2 -1
- package/lib/files/minio/minio-adapter.js +13 -7
- package/lib/files/minio/minio-adapter.js.map +1 -1
- package/lib/files/minio/minio-webhook.d.ts +1 -2
- package/lib/files/minio/minio-webhook.js +24 -37
- package/lib/files/minio/minio-webhook.js.map +1 -1
- package/lib/payment/apple-iap/adapter.d.ts +2 -2
- package/lib/payment/apple-iap/adapter.js +89 -97
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/index.d.ts +2 -3
- package/lib/payment/apple-iap/index.js +2 -3
- package/lib/payment/apple-iap/index.js.map +1 -1
- package/lib/payment/cryptopay/index.d.ts +2 -3
- package/lib/payment/cryptopay/index.js +2 -3
- package/lib/payment/cryptopay/index.js.map +1 -1
- package/lib/payment/cryptopay/middleware.d.ts +1 -2
- package/lib/payment/cryptopay/middleware.js +64 -69
- package/lib/payment/cryptopay/middleware.js.map +1 -1
- package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +1 -1
- package/lib/payment/datatrans-v2/api/makeFetcher.js +1 -1
- package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +1 -1
- package/lib/payment/datatrans-v2/getPaths.js +7 -7
- package/lib/payment/datatrans-v2/getPaths.js.map +1 -1
- package/lib/payment/datatrans-v2/index.d.ts +1 -2
- package/lib/payment/datatrans-v2/index.js +1 -2
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +1 -2
- package/lib/payment/datatrans-v2/middleware.js +54 -102
- package/lib/payment/datatrans-v2/middleware.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts +1 -2
- package/lib/payment/postfinance-checkout/index.js +1 -2
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +1 -2
- package/lib/payment/postfinance-checkout/middleware.js +31 -37
- package/lib/payment/postfinance-checkout/middleware.js.map +1 -1
- package/lib/payment/stripe.d.ts +1 -2
- package/lib/payment/stripe.js +55 -60
- package/lib/payment/stripe.js.map +1 -1
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +1 -0
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +1 -1
- package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -1
- package/lib/plugins-index.d.ts +61 -0
- package/lib/plugins-index.js +100 -0
- package/lib/plugins-index.js.map +1 -1
- package/lib/pricing/utils/cache.d.ts +1 -2
- package/lib/warehousing/eth-minter.js +30 -42
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/http-request.d.ts +1 -0
- package/lib/worker/http-request.js +0 -1
- package/lib/worker/http-request.js.map +1 -1
- package/lib/worker/update-coinbase-rates.d.ts +1 -0
- package/lib/worker/update-coinbase-rates.js +0 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.d.ts +1 -0
- package/lib/worker/update-ecb-rates.js +0 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/lib/worker/zombie-killer.js +1 -1
- package/package.json +21 -23
- package/src/delivery/pick-mup.ts +1 -1
- package/src/files/gridfs/gridfs-adapter.ts +3 -2
- package/src/files/gridfs/gridfs-webhook.ts +40 -46
- package/src/files/minio/minio-adapter.ts +13 -8
- package/src/files/minio/minio-webhook.ts +35 -0
- package/src/payment/apple-iap/adapter.ts +104 -120
- package/src/payment/apple-iap/index.ts +2 -4
- package/src/payment/cryptopay/index.ts +2 -4
- package/src/payment/cryptopay/middleware.ts +65 -74
- package/src/payment/datatrans-v2/api/makeFetcher.ts +1 -1
- package/src/payment/datatrans-v2/getPaths.ts +12 -11
- package/src/payment/datatrans-v2/index.ts +2 -3
- package/src/payment/datatrans-v2/middleware.ts +66 -133
- package/src/payment/postfinance-checkout/index.ts +2 -3
- package/src/payment/postfinance-checkout/middleware.ts +37 -45
- package/src/payment/stripe.ts +68 -83
- package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +1 -2
- package/src/plugins-index.ts +147 -0
- package/src/warehousing/eth-minter.ts +36 -50
- package/src/worker/http-request.ts +1 -1
- package/src/worker/update-coinbase-rates.ts +1 -1
- package/src/worker/update-ecb-rates.ts +1 -1
- package/src/worker/zombie-killer.ts +1 -1
- package/lib/payment/bity/adapter.d.ts +0 -2
- package/lib/payment/bity/adapter.js +0 -320
- package/lib/payment/bity/adapter.js.map +0 -1
- package/lib/payment/bity/db/BityCredentialsCollection.d.ts +0 -11
- package/lib/payment/bity/db/BityCredentialsCollection.js +0 -5
- package/lib/payment/bity/db/BityCredentialsCollection.js.map +0 -1
- package/lib/payment/bity/index.d.ts +0 -3
- package/lib/payment/bity/index.js +0 -4
- package/lib/payment/bity/index.js.map +0 -1
- package/lib/payment/bity/module/configureBityModule.d.ts +0 -11
- package/lib/payment/bity/module/configureBityModule.js +0 -33
- package/lib/payment/bity/module/configureBityModule.js.map +0 -1
- package/src/files/minio/minio-webhook.js +0 -54
- package/src/payment/bity/adapter.ts +0 -421
- package/src/payment/bity/db/BityCredentialsCollection.ts +0 -17
- package/src/payment/bity/index.ts +0 -4
- package/src/payment/bity/module/configureBityModule.ts +0 -46
package/src/payment/stripe.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Context } from '@unchainedshop/types/api';
|
|
2
2
|
import { IPaymentAdapter } from '@unchainedshop/types/payments';
|
|
3
|
-
import bodyParser from 'body-parser';
|
|
4
|
-
import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
|
|
5
3
|
import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
|
|
6
4
|
import { createLogger } from '@unchainedshop/logger';
|
|
7
5
|
|
|
@@ -18,96 +16,83 @@ import createStripeClient from 'stripe';
|
|
|
18
16
|
|
|
19
17
|
const logger = createLogger('unchained:core-payment:stripe');
|
|
20
18
|
|
|
21
|
-
const {
|
|
22
|
-
STRIPE_SECRET,
|
|
23
|
-
STRIPE_ENDPOINT_SECRET,
|
|
24
|
-
EMAIL_WEBSITE_NAME,
|
|
25
|
-
STRIPE_WEBHOOK_PATH = '/payment/stripe',
|
|
26
|
-
} = process.env;
|
|
19
|
+
const { STRIPE_SECRET, STRIPE_ENDPOINT_SECRET, EMAIL_WEBSITE_NAME } = process.env;
|
|
27
20
|
|
|
28
21
|
// eslint-disable-next-line
|
|
29
22
|
// @ts-ignore
|
|
30
23
|
const stripe = createStripeClient(STRIPE_SECRET);
|
|
31
24
|
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const order = await modules.orders.checkout(
|
|
66
|
-
orderPayment.orderId,
|
|
67
|
-
{
|
|
68
|
-
transactionContext: {
|
|
69
|
-
paymentIntentId: paymentIntent.id,
|
|
70
|
-
},
|
|
71
|
-
paymentContext: {
|
|
72
|
-
paymentIntentId: paymentIntent.id,
|
|
73
|
-
},
|
|
25
|
+
export const stripeHandler = async (request, response) => {
|
|
26
|
+
const sig = request.headers['stripe-signature'];
|
|
27
|
+
const resolvedContext = request.unchainedContext as Context;
|
|
28
|
+
const { modules, services } = resolvedContext;
|
|
29
|
+
|
|
30
|
+
let event;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
event = stripe.webhooks.constructEvent(request.body, sig, STRIPE_ENDPOINT_SECRET);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
response.writeHead(400);
|
|
36
|
+
response.end(`Webhook Error: ${err.message}`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
if (event.type === 'payment_intent.succeeded') {
|
|
42
|
+
const paymentIntent = event.data.object;
|
|
43
|
+
const orderPaymentId = paymentIntent.metadata?.orderPaymentId;
|
|
44
|
+
|
|
45
|
+
await modules.orders.payments.logEvent(orderPaymentId, event, resolvedContext.userId);
|
|
46
|
+
|
|
47
|
+
const orderPayment = await modules.orders.payments.findOrderPayment({
|
|
48
|
+
orderPaymentId,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const order = await modules.orders.checkout(
|
|
52
|
+
orderPayment.orderId,
|
|
53
|
+
{
|
|
54
|
+
transactionContext: {
|
|
55
|
+
paymentIntentId: paymentIntent.id,
|
|
74
56
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
logger.info(`Stripe Webhook: Unchained confirmed checkout for order ${order.orderNumber}`, {
|
|
79
|
-
orderId: order._id,
|
|
80
|
-
});
|
|
81
|
-
} else if (event.type === 'setup_intent.succeeded') {
|
|
82
|
-
const setupIntent = event.data.object;
|
|
83
|
-
const { paymentProviderId, userId } = setupIntent.metadata;
|
|
84
|
-
|
|
85
|
-
await services.payment.registerPaymentCredentials(
|
|
86
|
-
paymentProviderId,
|
|
87
|
-
{
|
|
88
|
-
transactionContext: {
|
|
89
|
-
setupIntentId: setupIntent.id,
|
|
90
|
-
},
|
|
57
|
+
paymentContext: {
|
|
58
|
+
paymentIntentId: paymentIntent.id,
|
|
91
59
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
60
|
+
},
|
|
61
|
+
resolvedContext,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
logger.info(`Stripe Webhook: Unchained confirmed checkout for order ${order.orderNumber}`, {
|
|
65
|
+
orderId: order._id,
|
|
66
|
+
});
|
|
67
|
+
} else if (event.type === 'setup_intent.succeeded') {
|
|
68
|
+
const setupIntent = event.data.object;
|
|
69
|
+
const { paymentProviderId, userId } = setupIntent.metadata;
|
|
70
|
+
|
|
71
|
+
await services.payment.registerPaymentCredentials(
|
|
72
|
+
paymentProviderId,
|
|
73
|
+
{
|
|
74
|
+
transactionContext: {
|
|
75
|
+
setupIntentId: setupIntent.id,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
resolvedContext,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
logger.info(`Stripe Webhook: Unchained registered payment credentials for ${userId}`, {
|
|
82
|
+
userId,
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
response.writeHead(404);
|
|
86
|
+
response.end();
|
|
106
87
|
return;
|
|
107
88
|
}
|
|
108
|
-
|
|
109
|
-
response.
|
|
110
|
-
|
|
89
|
+
} catch (err) {
|
|
90
|
+
response.writeHead(400);
|
|
91
|
+
response.end(`Webhook Error: ${err.message}`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// Return a 200 response to acknowledge receipt of the event
|
|
95
|
+
response.end(JSON.stringify({ received: true }));
|
|
111
96
|
};
|
|
112
97
|
|
|
113
98
|
const createRegistrationIntent = async ({ userId, name, email, paymentProviderId }, options = {}) => {
|
package/src/plugins-index.ts
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
|
|
2
|
+
import bodyParser from 'body-parser';
|
|
3
|
+
|
|
4
|
+
// Delivery
|
|
5
|
+
import './delivery/post';
|
|
6
|
+
import './delivery/pick-mup';
|
|
7
|
+
import './delivery/send-message';
|
|
8
|
+
import './delivery/stores';
|
|
9
|
+
|
|
10
|
+
// Payment
|
|
11
|
+
import './payment/invoice';
|
|
12
|
+
import './payment/invoice-prepaid';
|
|
13
|
+
import './payment/paypal-checkout';
|
|
14
|
+
import './payment/worldline-saferpay';
|
|
15
|
+
import { datatransHandler } from './payment/datatrans-v2';
|
|
16
|
+
import { configureCryptopayModule, cryptopayHandler } from './payment/cryptopay';
|
|
17
|
+
import { appleIAPHandler, configureAppleTransactionsModule } from './payment/apple-iap';
|
|
18
|
+
import { stripeHandler } from './payment/stripe';
|
|
19
|
+
import { postfinanceCheckoutHandler } from './payment/postfinance-checkout';
|
|
20
|
+
|
|
21
|
+
// Warehousing
|
|
22
|
+
import './warehousing/store';
|
|
23
|
+
import './warehousing/eth-minter';
|
|
24
|
+
|
|
25
|
+
// Pricing
|
|
26
|
+
import './pricing/discount-half-price-manual';
|
|
27
|
+
import './pricing/discount-100-off';
|
|
28
|
+
import './pricing/free-payment';
|
|
29
|
+
import './pricing/free-delivery';
|
|
30
|
+
import './pricing/order-items';
|
|
31
|
+
import './pricing/order-discount';
|
|
32
|
+
import './pricing/order-delivery';
|
|
33
|
+
import './pricing/order-payment';
|
|
34
|
+
import './pricing/product-catalog-price';
|
|
35
|
+
import './pricing/product-price-rateconversion';
|
|
36
|
+
import './pricing/product-discount';
|
|
37
|
+
import './pricing/product-swiss-tax';
|
|
38
|
+
import './pricing/delivery-swiss-tax';
|
|
39
|
+
|
|
40
|
+
// Filter & Search
|
|
41
|
+
import './filters/strict-equal';
|
|
42
|
+
import './filters/local-search';
|
|
43
|
+
|
|
44
|
+
// Quotations
|
|
45
|
+
import './quotations/manual';
|
|
46
|
+
|
|
47
|
+
// Enrollments
|
|
48
|
+
import './enrollments/licensed';
|
|
49
|
+
|
|
50
|
+
// Event Queue
|
|
51
|
+
import './events/node-event-emitter';
|
|
52
|
+
|
|
53
|
+
// Workers
|
|
54
|
+
import './worker/bulk-import';
|
|
55
|
+
import './worker/zombie-killer';
|
|
56
|
+
import './worker/message';
|
|
57
|
+
import './worker/external';
|
|
58
|
+
import './worker/http-request';
|
|
59
|
+
import './worker/heartbeat';
|
|
60
|
+
import './worker/email';
|
|
61
|
+
import './worker/sms';
|
|
62
|
+
import './worker/update-ecb-rates';
|
|
63
|
+
import './worker/update-coinbase-rates';
|
|
64
|
+
import { configureExportToken } from './worker/export-token';
|
|
65
|
+
import { configureGenerateOrderAutoscheduling } from './worker/enrollment-order-generator';
|
|
66
|
+
import { configureUpdateTokenOwnership } from './worker/update-token-ownership';
|
|
67
|
+
|
|
68
|
+
// Asset Management
|
|
69
|
+
import './files/gridfs/gridfs-adapter';
|
|
70
|
+
import { gridfsHandler } from './files/gridfs/gridfs-webhook';
|
|
71
|
+
import { configureGridFSFileUploadModule } from './files/gridfs';
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
CRYPTOPAY_WEBHOOK_PATH = '/payment/cryptopay',
|
|
75
|
+
STRIPE_WEBHOOK_PATH = '/payment/stripe',
|
|
76
|
+
PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout',
|
|
77
|
+
DATATRANS_WEBHOOK_PATH = '/payment/datatrans/webhook',
|
|
78
|
+
APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap',
|
|
79
|
+
// MINIO_PUT_SERVER_PATH = '/minio',
|
|
80
|
+
GRIDFS_PUT_SERVER_PATH = '/gridfs',
|
|
81
|
+
} = process.env;
|
|
82
|
+
|
|
83
|
+
// import './files/minio/minio-adapter';
|
|
84
|
+
// import { minioHandler } from './files/minio/minio-webhook';
|
|
85
|
+
|
|
86
|
+
export const defaultModules = {
|
|
87
|
+
appleTransactions: {
|
|
88
|
+
configure: configureAppleTransactionsModule,
|
|
89
|
+
},
|
|
90
|
+
gridfsFileUploads: {
|
|
91
|
+
configure: configureGridFSFileUploadModule,
|
|
92
|
+
},
|
|
93
|
+
cryptopay: {
|
|
94
|
+
configure: configureCryptopayModule,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const useDefaultMiddlewares = (unchainedApi, app) => {
|
|
99
|
+
useMiddlewareWithCurrentContext(app, GRIDFS_PUT_SERVER_PATH, gridfsHandler);
|
|
100
|
+
|
|
101
|
+
useMiddlewareWithCurrentContext(app, CRYPTOPAY_WEBHOOK_PATH, bodyParser.json(), cryptopayHandler);
|
|
102
|
+
|
|
103
|
+
useMiddlewareWithCurrentContext(
|
|
104
|
+
app,
|
|
105
|
+
STRIPE_WEBHOOK_PATH,
|
|
106
|
+
bodyParser.raw({ type: 'application/json' }),
|
|
107
|
+
stripeHandler,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
useMiddlewareWithCurrentContext(
|
|
111
|
+
app,
|
|
112
|
+
PFCHECKOUT_WEBHOOK_PATH,
|
|
113
|
+
bodyParser.json(),
|
|
114
|
+
postfinanceCheckoutHandler,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
useMiddlewareWithCurrentContext(
|
|
118
|
+
app,
|
|
119
|
+
DATATRANS_WEBHOOK_PATH,
|
|
120
|
+
bodyParser.text({
|
|
121
|
+
type: 'application/json',
|
|
122
|
+
}),
|
|
123
|
+
datatransHandler,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
useMiddlewareWithCurrentContext(
|
|
127
|
+
app,
|
|
128
|
+
APPLE_IAP_WEBHOOK_PATH,
|
|
129
|
+
bodyParser.json({
|
|
130
|
+
strict: false,
|
|
131
|
+
}),
|
|
132
|
+
appleIAPHandler,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// useMiddlewareWithCurrentContext(
|
|
136
|
+
// app,
|
|
137
|
+
// MINIO_PUT_SERVER_PATH,
|
|
138
|
+
// bodyParser.json({
|
|
139
|
+
// strict: false,
|
|
140
|
+
// }),
|
|
141
|
+
// minioHandler
|
|
142
|
+
// );
|
|
143
|
+
|
|
144
|
+
configureExportToken(unchainedApi);
|
|
145
|
+
configureUpdateTokenOwnership(unchainedApi);
|
|
146
|
+
configureGenerateOrderAutoscheduling();
|
|
147
|
+
};
|
|
@@ -25,6 +25,22 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
25
25
|
|
|
26
26
|
actions: (configuration, context) => {
|
|
27
27
|
const { product, orderPosition, token, modules, localeContext } = context;
|
|
28
|
+
|
|
29
|
+
const getTokensCreated = async () => {
|
|
30
|
+
const existingTokens = await modules.warehousing.findTokens(
|
|
31
|
+
product.tokenization.contractStandard === ProductContractStandard.ERC721
|
|
32
|
+
? { contractAddress: product.tokenization.contractAddress }
|
|
33
|
+
: {
|
|
34
|
+
contractAddress: product.tokenization.contractAddress,
|
|
35
|
+
chainTokenId: product.tokenization.tokenId,
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
const tokensCreated = existingTokens.reduce((acc, curToken) => {
|
|
39
|
+
return acc + curToken.quantity;
|
|
40
|
+
}, 0);
|
|
41
|
+
return tokensCreated;
|
|
42
|
+
};
|
|
43
|
+
|
|
28
44
|
return {
|
|
29
45
|
...WarehousingAdapter.actions(configuration, context),
|
|
30
46
|
|
|
@@ -37,18 +53,7 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
37
53
|
},
|
|
38
54
|
|
|
39
55
|
stock: async () => {
|
|
40
|
-
const
|
|
41
|
-
product.tokenization.contractStandard === 'ERC721'
|
|
42
|
-
? { contractAddress: product.tokenization.contractAddress }
|
|
43
|
-
: {
|
|
44
|
-
contractAddress: product.tokenization.contractAddress,
|
|
45
|
-
chainTokenId: product.tokenization.tokenId,
|
|
46
|
-
},
|
|
47
|
-
);
|
|
48
|
-
const tokensCreated = existingTokens.reduce((acc, curToken) => {
|
|
49
|
-
return acc + curToken.quantity;
|
|
50
|
-
}, 0);
|
|
51
|
-
|
|
56
|
+
const tokensCreated = await getTokensCreated();
|
|
52
57
|
return product?.tokenization?.supply ? product.tokenization.supply - tokensCreated : 0;
|
|
53
58
|
},
|
|
54
59
|
|
|
@@ -61,18 +66,7 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
61
66
|
const { contractAddress, contractStandard, tokenId } = product?.tokenization || {};
|
|
62
67
|
const _id = generateDbObjectId();
|
|
63
68
|
const meta = { contractStandard };
|
|
64
|
-
|
|
65
|
-
const existingTokens = await modules.warehousing.findTokens(
|
|
66
|
-
product.tokenization.contractStandard === 'ERC721'
|
|
67
|
-
? { contractAddress: product.tokenization.contractAddress }
|
|
68
|
-
: {
|
|
69
|
-
contractAddress: product.tokenization.contractAddress,
|
|
70
|
-
chainTokenId: product.tokenization.tokenId,
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
const tokensCreated = existingTokens.reduce((acc, curToken) => {
|
|
74
|
-
return acc + curToken.quantity;
|
|
75
|
-
}, 0);
|
|
69
|
+
const tokensCreated = await getTokensCreated();
|
|
76
70
|
|
|
77
71
|
if (contractStandard === 'ERC721') {
|
|
78
72
|
// ERC721 is non-fungible, thus every _id unique!
|
|
@@ -98,13 +92,9 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
98
92
|
];
|
|
99
93
|
},
|
|
100
94
|
|
|
101
|
-
tokenMetadata: async () => {
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
// -> use the contract to get the correct metadata uri from tokenId
|
|
105
|
-
|
|
106
|
-
// depending on the ERC, build the correct metadata json schema
|
|
107
|
-
// https://eips.ethereum.org/EIPS/eip-1155
|
|
95
|
+
tokenMetadata: async (chainTokenId) => {
|
|
96
|
+
// Metadata standards supported
|
|
97
|
+
// https://eips.ethereum.org/EIPS/eip-1155 (backward compatible with 721)
|
|
108
98
|
// https://eips.ethereum.org/EIPS/eip-721
|
|
109
99
|
|
|
110
100
|
const allLanguages = await modules.languages.findLanguages({
|
|
@@ -122,28 +112,24 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
122
112
|
locale: localeContext.normalized,
|
|
123
113
|
});
|
|
124
114
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
name: `${text.title} #${token.chainTokenId}`,
|
|
137
|
-
description: text.description,
|
|
138
|
-
image: url,
|
|
139
|
-
properties: product.meta,
|
|
140
|
-
localization,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
115
|
+
const name = `${text.title} #${chainTokenId}`;
|
|
116
|
+
|
|
117
|
+
const isDefaultLanguageActive = localeContext.language === systemLocale.language;
|
|
118
|
+
const localization = isDefaultLanguageActive
|
|
119
|
+
? {
|
|
120
|
+
uri: `${process.env.ROOT_URL}/erc-metadata/${product._id}/{locale}/${product.tokenization.tokenId}.json`,
|
|
121
|
+
default: systemLocale.language,
|
|
122
|
+
locales: allLanguages.map((lang) => lang.isoCode),
|
|
123
|
+
}
|
|
124
|
+
: undefined;
|
|
125
|
+
|
|
143
126
|
return {
|
|
144
|
-
name
|
|
127
|
+
name,
|
|
145
128
|
description: text.description,
|
|
146
129
|
image: url,
|
|
130
|
+
properties: product.tokenization.ercMetadataProperties,
|
|
131
|
+
localization,
|
|
132
|
+
...(token?.meta || {}),
|
|
147
133
|
};
|
|
148
134
|
},
|
|
149
135
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
1
2
|
import { IWorkerAdapter } from '@unchainedshop/types/worker';
|
|
2
3
|
import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
|
|
3
4
|
import later from '@breejs/later';
|
|
4
|
-
import fetch from 'node-fetch';
|
|
5
5
|
import { ProductPriceRate } from '@unchainedshop/types/products.pricing';
|
|
6
6
|
import { systemLocale } from '@unchainedshop/utils';
|
|
7
7
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
1
2
|
import { IWorkerAdapter } from '@unchainedshop/types/worker';
|
|
2
3
|
import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
|
|
3
4
|
import later from '@breejs/later';
|
|
4
5
|
import xmlJs from 'xml-js';
|
|
5
|
-
import fetch from 'node-fetch';
|
|
6
6
|
import { ProductPriceRate } from '@unchainedshop/types/products.pricing';
|
|
7
7
|
|
|
8
8
|
const getExchangeRates = async () => {
|
|
@@ -32,7 +32,7 @@ export const ZombieKillerWorker: IWorkerAdapter<
|
|
|
32
32
|
// Remove unreferenced product media objects
|
|
33
33
|
const products = await modules.products.findProducts({}, findId);
|
|
34
34
|
const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
|
|
35
|
-
|
|
35
|
+
excludedProductIds: products.map(mapId),
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// Remove unreferenced assortment media objects
|