@unchainedshop/plugins 2.0.0-beta6 → 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.
Files changed (108) hide show
  1. package/lib/delivery/pick-mup.d.ts +1 -0
  2. package/lib/delivery/pick-mup.js +1 -1
  3. package/lib/delivery/pick-mup.js.map +1 -1
  4. package/lib/files/gridfs/gridfs-adapter.d.ts +1 -0
  5. package/lib/files/gridfs/gridfs-adapter.js +0 -1
  6. package/lib/files/gridfs/gridfs-adapter.js.map +1 -1
  7. package/lib/files/gridfs/gridfs-webhook.d.ts +1 -2
  8. package/lib/files/gridfs/gridfs-webhook.js +2 -6
  9. package/lib/files/gridfs/gridfs-webhook.js.map +1 -1
  10. package/lib/files/minio/minio-adapter.d.ts +2 -1
  11. package/lib/files/minio/minio-adapter.js +13 -7
  12. package/lib/files/minio/minio-adapter.js.map +1 -1
  13. package/lib/files/minio/minio-webhook.d.ts +1 -2
  14. package/lib/files/minio/minio-webhook.js +24 -37
  15. package/lib/files/minio/minio-webhook.js.map +1 -1
  16. package/lib/payment/apple-iap/adapter.d.ts +2 -2
  17. package/lib/payment/apple-iap/adapter.js +89 -97
  18. package/lib/payment/apple-iap/adapter.js.map +1 -1
  19. package/lib/payment/apple-iap/index.d.ts +2 -3
  20. package/lib/payment/apple-iap/index.js +2 -3
  21. package/lib/payment/apple-iap/index.js.map +1 -1
  22. package/lib/payment/cryptopay/index.d.ts +2 -3
  23. package/lib/payment/cryptopay/index.js +2 -3
  24. package/lib/payment/cryptopay/index.js.map +1 -1
  25. package/lib/payment/cryptopay/middleware.d.ts +1 -2
  26. package/lib/payment/cryptopay/middleware.js +64 -69
  27. package/lib/payment/cryptopay/middleware.js.map +1 -1
  28. package/lib/payment/datatrans-v2/api/makeFetcher.d.ts +1 -1
  29. package/lib/payment/datatrans-v2/api/makeFetcher.js +1 -1
  30. package/lib/payment/datatrans-v2/api/makeFetcher.js.map +1 -1
  31. package/lib/payment/datatrans-v2/getPaths.d.ts +1 -1
  32. package/lib/payment/datatrans-v2/getPaths.js +7 -7
  33. package/lib/payment/datatrans-v2/getPaths.js.map +1 -1
  34. package/lib/payment/datatrans-v2/index.d.ts +1 -2
  35. package/lib/payment/datatrans-v2/index.js +1 -2
  36. package/lib/payment/datatrans-v2/index.js.map +1 -1
  37. package/lib/payment/datatrans-v2/middleware.d.ts +1 -2
  38. package/lib/payment/datatrans-v2/middleware.js +54 -102
  39. package/lib/payment/datatrans-v2/middleware.js.map +1 -1
  40. package/lib/payment/postfinance-checkout/index.d.ts +1 -2
  41. package/lib/payment/postfinance-checkout/index.js +1 -2
  42. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  43. package/lib/payment/postfinance-checkout/middleware.d.ts +1 -2
  44. package/lib/payment/postfinance-checkout/middleware.js +31 -37
  45. package/lib/payment/postfinance-checkout/middleware.js.map +1 -1
  46. package/lib/payment/stripe.d.ts +1 -2
  47. package/lib/payment/stripe.js +55 -60
  48. package/lib/payment/stripe.js.map +1 -1
  49. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.d.ts +1 -0
  50. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js +1 -1
  51. package/lib/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.js.map +1 -1
  52. package/lib/plugins-index.d.ts +61 -0
  53. package/lib/plugins-index.js +100 -0
  54. package/lib/plugins-index.js.map +1 -1
  55. package/lib/pricing/utils/cache.d.ts +1 -2
  56. package/lib/warehousing/eth-minter.js +27 -40
  57. package/lib/warehousing/eth-minter.js.map +1 -1
  58. package/lib/worker/http-request.d.ts +1 -0
  59. package/lib/worker/http-request.js +0 -1
  60. package/lib/worker/http-request.js.map +1 -1
  61. package/lib/worker/update-coinbase-rates.d.ts +1 -0
  62. package/lib/worker/update-coinbase-rates.js +0 -1
  63. package/lib/worker/update-coinbase-rates.js.map +1 -1
  64. package/lib/worker/update-ecb-rates.d.ts +1 -0
  65. package/lib/worker/update-ecb-rates.js +0 -1
  66. package/lib/worker/update-ecb-rates.js.map +1 -1
  67. package/lib/worker/zombie-killer.js +1 -1
  68. package/package.json +21 -23
  69. package/src/delivery/pick-mup.ts +1 -1
  70. package/src/files/gridfs/gridfs-adapter.ts +3 -2
  71. package/src/files/gridfs/gridfs-webhook.ts +40 -46
  72. package/src/files/minio/minio-adapter.ts +13 -8
  73. package/src/files/minio/minio-webhook.ts +35 -0
  74. package/src/payment/apple-iap/adapter.ts +104 -120
  75. package/src/payment/apple-iap/index.ts +2 -4
  76. package/src/payment/cryptopay/index.ts +2 -4
  77. package/src/payment/cryptopay/middleware.ts +65 -74
  78. package/src/payment/datatrans-v2/api/makeFetcher.ts +1 -1
  79. package/src/payment/datatrans-v2/getPaths.ts +12 -11
  80. package/src/payment/datatrans-v2/index.ts +2 -3
  81. package/src/payment/datatrans-v2/middleware.ts +66 -133
  82. package/src/payment/postfinance-checkout/index.ts +2 -3
  83. package/src/payment/postfinance-checkout/middleware.ts +37 -45
  84. package/src/payment/stripe.ts +68 -83
  85. package/src/payment/worldline-saferpay/worldline-saferpay-client/api/SaferpayConnection.ts +1 -2
  86. package/src/plugins-index.ts +147 -0
  87. package/src/warehousing/eth-minter.ts +32 -48
  88. package/src/worker/http-request.ts +1 -1
  89. package/src/worker/update-coinbase-rates.ts +1 -1
  90. package/src/worker/update-ecb-rates.ts +1 -1
  91. package/src/worker/zombie-killer.ts +1 -1
  92. package/lib/payment/bity/adapter.d.ts +0 -2
  93. package/lib/payment/bity/adapter.js +0 -320
  94. package/lib/payment/bity/adapter.js.map +0 -1
  95. package/lib/payment/bity/db/BityCredentialsCollection.d.ts +0 -11
  96. package/lib/payment/bity/db/BityCredentialsCollection.js +0 -5
  97. package/lib/payment/bity/db/BityCredentialsCollection.js.map +0 -1
  98. package/lib/payment/bity/index.d.ts +0 -3
  99. package/lib/payment/bity/index.js +0 -4
  100. package/lib/payment/bity/index.js.map +0 -1
  101. package/lib/payment/bity/module/configureBityModule.d.ts +0 -11
  102. package/lib/payment/bity/module/configureBityModule.js +0 -33
  103. package/lib/payment/bity/module/configureBityModule.js.map +0 -1
  104. package/src/files/minio/minio-webhook.js +0 -54
  105. package/src/payment/bity/adapter.ts +0 -421
  106. package/src/payment/bity/db/BityCredentialsCollection.ts +0 -17
  107. package/src/payment/bity/index.ts +0 -4
  108. package/src/payment/bity/module/configureBityModule.ts +0 -46
@@ -1 +1,2 @@
1
+ /// <reference lib="dom" />
1
2
  export {};
@@ -1,6 +1,5 @@
1
1
  import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
2
2
  import later from '@breejs/later';
3
- import fetch from 'node-fetch';
4
3
  import { systemLocale } from '@unchainedshop/utils';
5
4
  const getExchangeRates = async (base) => {
6
5
  return fetch(`https://api.coinbase.com/v2/exchange-rates?currency=${base}`, {
@@ -1 +1 @@
1
- {"version":3,"file":"update-coinbase-rates.js","sourceRoot":"","sources":["../../src/worker/update-coinbase-rates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,gBAAgB,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE;IACtC,OAAO,KAAK,CAAC,uDAAuD,IAAI,EAAE,EAAE;QAC1E,MAAM,EAAE,KAAK;KACd,CAAC;SACC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACzB,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAElD,MAAM,mBAAmB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ACb,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;oBACtB,SAAS;oBACT,SAAS;iBACV,CAAC;YACJ,CAAC,CAAC;iBACD,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CACP,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,YAAY,CACzF,CAAC;YAEJ,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO;gBACL,OAAO;gBACP,MAAM,EAAE;oBACN,YAAY,EAAE,KAAK,CAAC,MAAM;iBAC3B;aACF,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,8BAA8B;oBACpC,OAAO,EAAE,gCAAgC;iBAC1C;aACF,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC;AAEpD,cAAc,CAAC,uBAAuB,CAAC,mBAAmB,EAAE;IAC1D,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,GAAG,EAAE;QACV,KAAK;IACP,CAAC;CACF,CAAC,CAAC"}
@@ -1 +1,2 @@
1
+ /// <reference lib="dom" />
1
2
  export {};
@@ -1,7 +1,6 @@
1
1
  import { WorkerAdapter, WorkerDirector } from '@unchainedshop/core-worker';
2
2
  import later from '@breejs/later';
3
3
  import xmlJs from 'xml-js';
4
- import fetch from 'node-fetch';
5
4
  const getExchangeRates = async () => {
6
5
  return fetch(`https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml`, {
7
6
  method: 'GET',
@@ -1 +1 @@
1
- {"version":3,"file":"update-ecb-rates.js","sourceRoot":"","sources":["../../src/worker/update-ecb-rates.ts"],"names":[],"mappings":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AA4B,IAAI;iBACxC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACT,OAAO;oBACL,YAAY;oBACZ,aAAa,EAAE,CAAC,CAAC,QAAQ;oBACzB,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;oBACxB,SAAS;oBACT,SAAS;iBACV,CAAC;YACJ,CAAC,CAAC;iBACD,MAAM,CACL,CAAC,IAAI,EAAE,EAAE,CACP,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,YAAY,CACzF,CAAC;YAEJ,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO;gBACL,OAAO;gBACP,MAAM,EAAE;oBACN,YAAY,EAAE,KAAK,CAAC,MAAM;iBAC3B;aACF,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,yBAAyB;oBAC/B,OAAO,EAAE,2BAA2B;iBACrC;aACF,CAAC;SACH;IACH,CAAC;CACF,CAAC;AAEF,cAAc,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;AAE/C,cAAc,CAAC,uBAAuB,CAAC,cAAc,EAAE;IACrD,QAAQ,EAAE,cAAc;IACxB,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,GAAG,EAAE;QACV,KAAK;IACP,CAAC;CACF,CAAC,CAAC"}
@@ -17,7 +17,7 @@ export const ZombieKillerWorker = {
17
17
  // Remove unreferenced product media objects
18
18
  const products = await modules.products.findProducts({}, findId);
19
19
  const deletedProductMediaCount = await modules.products.media.deleteMediaFiles({
20
- excludedProdcutIds: products.map(mapId),
20
+ excludedProductIds: products.map(mapId),
21
21
  });
22
22
  // Remove unreferenced assortment media objects
23
23
  const assortments = await modules.assortments.findAssortments({}, findId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/plugins",
3
- "version": "2.0.0-beta6",
3
+ "version": "2.0.0-beta7",
4
4
  "main": "lib/plugins-index.js",
5
5
  "types": "lib/plugins-index.d.ts",
6
6
  "exports": {
@@ -71,42 +71,40 @@
71
71
  },
72
72
  "homepage": "https://github.com/unchainedshop/unchained#readme",
73
73
  "devDependencies": {
74
- "@types/node": "^16.18.2",
75
- "@unchainedshop/api": "^2.0.0-beta6",
74
+ "@types/node": "^18.11.9",
75
+ "@unchainedshop/api": "^2.0.0-beta7",
76
76
  "@unchainedshop/client-oauth2": "^4.3.3",
77
- "@unchainedshop/core-delivery": "^2.0.0-beta6",
78
- "@unchainedshop/core-enrollments": "^2.0.0-beta6",
79
- "@unchainedshop/core-filters": "^2.0.0-beta6",
80
- "@unchainedshop/core-messaging": "^2.0.0-beta6",
81
- "@unchainedshop/core-orders": "^2.0.0-beta6",
82
- "@unchainedshop/core-payment": "^2.0.0-beta6",
83
- "@unchainedshop/core-products": "^2.0.0-beta6",
84
- "@unchainedshop/core-quotations": "^2.0.0-beta6",
85
- "@unchainedshop/core-warehousing": "^2.0.0-beta6",
86
- "@unchainedshop/core-worker": "^2.0.0-beta6",
87
- "@unchainedshop/events": "^2.0.0-beta6",
88
- "@unchainedshop/file-upload": "^2.0.0-beta6",
89
- "@unchainedshop/logger": "^2.0.0-beta6",
90
- "@unchainedshop/types": "^2.0.0-beta6",
91
- "@unchainedshop/utils": "^2.0.0-beta6",
77
+ "@unchainedshop/core-delivery": "^2.0.0-beta7",
78
+ "@unchainedshop/core-enrollments": "^2.0.0-beta7",
79
+ "@unchainedshop/core-filters": "^2.0.0-beta7",
80
+ "@unchainedshop/core-messaging": "^2.0.0-beta7",
81
+ "@unchainedshop/core-orders": "^2.0.0-beta7",
82
+ "@unchainedshop/core-payment": "^2.0.0-beta7",
83
+ "@unchainedshop/core-products": "^2.0.0-beta7",
84
+ "@unchainedshop/core-quotations": "^2.0.0-beta7",
85
+ "@unchainedshop/core-warehousing": "^2.0.0-beta7",
86
+ "@unchainedshop/core-worker": "^2.0.0-beta7",
87
+ "@unchainedshop/events": "^2.0.0-beta7",
88
+ "@unchainedshop/file-upload": "^2.0.0-beta7",
89
+ "@unchainedshop/logger": "^2.0.0-beta7",
90
+ "@unchainedshop/types": "^2.0.0-beta7",
91
+ "@unchainedshop/utils": "^2.0.0-beta7",
92
92
  "bluebird": "^3.7.2",
93
93
  "body-parser": "^1.20.0",
94
94
  "event-iterator": "^2.0.0",
95
- "jest": "^29.2.2",
95
+ "jest": "^29.3.1",
96
96
  "JSONStream": "^1.3.5",
97
97
  "minio": "^7.0.32",
98
98
  "mongodb": "^4.11.0",
99
99
  "node-sheets": "^1.2.0",
100
100
  "nodemailer": "^6.8.0",
101
101
  "open": "^8.4.0",
102
- "redis": "^4.3.1",
102
+ "redis": "^4.5.0",
103
103
  "request": "^2.88.2",
104
+ "stripe": "^10.17.0",
104
105
  "ts-jest": "^29.0.3",
105
106
  "typescript": "^4.8.4",
106
107
  "xml-js": "^1.6.11",
107
108
  "xml2js": "0.4.23"
108
- },
109
- "peerDependencies": {
110
- "node-fetch": "^2.6.7"
111
109
  }
112
110
  }
@@ -1,5 +1,5 @@
1
+ /// <reference lib="dom" />
1
2
  import { DeliveryProviderType, IDeliveryAdapter } from '@unchainedshop/types/delivery';
2
- import fetch from 'node-fetch';
3
3
  import { DeliveryAdapter, DeliveryDirector, DeliveryError } from '@unchainedshop/core-delivery';
4
4
 
5
5
  const fetchPickMupLocations = async (key: string, idsFilter?: string) => {
@@ -1,10 +1,11 @@
1
+ /// <reference lib="dom" />
1
2
  import { IFileAdapter, UploadFileData } from '@unchainedshop/types/files';
2
3
  import { FileAdapter, FileDirector, buildHashedFilename } from '@unchainedshop/file-upload';
3
4
  import mimeType from 'mime-types';
4
5
  import { URL } from 'url';
5
6
  import { Readable, pipeline as rawPipeline } from 'stream';
6
7
  import { promisify } from 'util';
7
- import fetch from 'node-fetch';
8
+ import { ReadableStream } from 'node:stream/web';
8
9
  import sign from './sign';
9
10
 
10
11
  const pipeline = promisify(rawPipeline);
@@ -98,7 +99,7 @@ export const GridFSAdapter: IFileAdapter = {
98
99
  const writeStream = await modules.gridfsFileUploads.createWriteStream(directoryName, _id, fileName);
99
100
  const response = await fetch(href, { headers });
100
101
  if (!response.ok) throw new Error(`Unexpected response for ${href}: ${response.statusText}`);
101
- await pipeline(response.body, writeStream);
102
+ await pipeline(response.body as ReadableStream, writeStream);
102
103
  const { length } = writeStream;
103
104
  const url = `/gridfs/${directoryName}/${_id}`;
104
105
 
@@ -1,4 +1,3 @@
1
- import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
2
1
  import { log, LogLevel } from '@unchainedshop/logger';
3
2
  import { buildHashedFilename } from '@unchainedshop/file-upload';
4
3
  import { pipeline as rawPipeline } from 'stream';
@@ -9,58 +8,53 @@ const pipeline = promisify(rawPipeline);
9
8
 
10
9
  const { ROOT_URL } = process.env;
11
10
 
12
- /*
13
- curl -vvv -X PUT -T /Users/pozylon/Downloads/grafik.png http://localhost:4010/gridfs/user-avatars/hans.png?e=1653059591506&s=df8626a1c9b9006249d7f1928fd530579fed57216f1bdcb83c28a8322cdc90b1
14
- */
11
+ export const gridfsHandler = async (req, res) => {
12
+ try {
13
+ const { services, modules } = req.unchainedContext;
14
+ const url = new URL(req.url, ROOT_URL);
15
+ const [, directoryName, fileName] = url.pathname.split('/');
15
16
 
16
- export default (app) =>
17
- useMiddlewareWithCurrentContext(app, '/gridfs', async (req, res) => {
18
- try {
19
- const { services, modules } = req.unchainedContext;
20
- const url = new URL(req.url, ROOT_URL);
21
- const [, directoryName, fileName] = url.pathname.split('/');
22
-
23
- if (req.method === 'PUT') {
24
- const { s: signature, e: expiryTimestamp } = req.query;
25
- const expiryDate = new Date(parseInt(expiryTimestamp, 10));
26
- const fileId = buildHashedFilename(directoryName, fileName, expiryDate);
27
- if (sign(directoryName, fileId, expiryDate.getTime()) === signature) {
28
- const file = await modules.files.findFile({ fileId });
29
- if (file.expires === null) {
30
- res.writeHead(503);
31
- res.end('File already linked');
32
- return;
33
- }
34
- const writeStream = await modules.gridfsFileUploads.createWriteStream(
35
- directoryName,
36
- fileId,
37
- fileName,
38
- );
39
- res.writeHead(200);
40
- await pipeline(req, writeStream);
41
- const { length } = writeStream;
42
- await services.files.linkFile({ fileId, size: length }, req.unchainedContext);
43
- res.end();
17
+ if (req.method === 'PUT') {
18
+ const { s: signature, e: expiryTimestamp } = req.query;
19
+ const expiryDate = new Date(parseInt(expiryTimestamp, 10));
20
+ const fileId = buildHashedFilename(directoryName, fileName, expiryDate);
21
+ if (sign(directoryName, fileId, expiryDate.getTime()) === signature) {
22
+ const file = await modules.files.findFile({ fileId });
23
+ if (file.expires === null) {
24
+ res.writeHead(503);
25
+ res.end('File already linked');
44
26
  return;
45
27
  }
46
- res.writeHead(403);
47
- res.end();
48
- return;
49
- }
50
- if (req.method === 'GET') {
51
- const fileId = fileName;
52
- const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
28
+ const writeStream = await modules.gridfsFileUploads.createWriteStream(
29
+ directoryName,
30
+ fileId,
31
+ fileName,
32
+ );
53
33
  res.writeHead(200);
54
- await pipeline(readStream, res);
34
+ await pipeline(req, writeStream);
35
+ const { length } = writeStream;
36
+ await services.files.linkFile({ fileId, size: length }, req.unchainedContext);
55
37
  res.end();
56
38
  return;
57
39
  }
58
- res.writeHead(404);
40
+ res.writeHead(403);
41
+ res.end();
42
+ return;
43
+ }
44
+ if (req.method === 'GET') {
45
+ const fileId = fileName;
46
+ const readStream = await modules.gridfsFileUploads.createReadStream(directoryName, fileId);
47
+ res.writeHead(200);
48
+ await pipeline(readStream, res);
59
49
  res.end();
60
50
  return;
61
- } catch (e) {
62
- log(e.message, { level: LogLevel.Error });
63
- res.writeHead(503);
64
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
65
51
  }
66
- });
52
+ res.writeHead(404);
53
+ res.end();
54
+ return;
55
+ } catch (e) {
56
+ log(e.message, { level: LogLevel.Error });
57
+ res.writeHead(503);
58
+ res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
59
+ }
60
+ };
@@ -6,12 +6,14 @@ import http, { OutgoingHttpHeaders } from 'http';
6
6
  import { log, LogLevel } from '@unchainedshop/logger';
7
7
  import mimeType from 'mime-types';
8
8
  import Minio from 'minio';
9
+ import AssumeRoleProvider from 'minio/dist/main/AssumeRoleProvider';
9
10
  import { Readable } from 'stream';
10
11
  import { URL } from 'url';
11
12
 
12
13
  const {
13
14
  MINIO_ACCESS_KEY,
14
15
  MINIO_REGION,
16
+ MINIO_STS_ENDPOINT,
15
17
  MINIO_SECRET_KEY,
16
18
  MINIO_ENDPOINT,
17
19
  MINIO_BUCKET_NAME,
@@ -46,12 +48,15 @@ export async function connectToMinio() {
46
48
  // eslint-disable-next-line
47
49
  // @ts-ignore
48
50
  if (NODE_ENV === 'development') minioClient?.traceOn(process.stdout);
49
-
50
- // if (credentialsProvider) {
51
- // await minioClient.setCredentialsProvider(credentialsProvider);
52
- // }
53
-
54
- client = minioClient;
51
+ if (MINIO_STS_ENDPOINT) {
52
+ const ap = new AssumeRoleProvider({
53
+ stsEndpoint: MINIO_STS_ENDPOINT,
54
+ });
55
+ // eslint-disable-next-line
56
+ // @ts-ignore
57
+ await minioClient.setCredentialsProvider(ap);
58
+ }
59
+ return minioClient;
55
60
  } catch (error) {
56
61
  log(`Exception while creating Minio client: ${error.message}`, {
57
62
  level: LogLevel.Error,
@@ -68,7 +73,7 @@ const getMimeType = (extension) => {
68
73
  return mimeType.lookup(extension);
69
74
  };
70
75
 
71
- connectToMinio().then((c) => {
76
+ connectToMinio().then(function setClient(c) {
72
77
  client = c;
73
78
  });
74
79
 
@@ -109,7 +114,7 @@ const getExpiryDate = () => new Date(new Date().getTime() + PUT_URL_EXPIRY);
109
114
  export const MinioAdapter: IFileAdapter = {
110
115
  key: 'shop.unchained.file-upload-plugin.minio',
111
116
  label: 'Uploads files into an S3 bucket using minio',
112
- version: '1.0.0',
117
+ version: '1.1.0',
113
118
 
114
119
  ...FileAdapter,
115
120
 
@@ -0,0 +1,35 @@
1
+ import { log, LogLevel } from '@unchainedshop/logger';
2
+
3
+ const { MINIO_WEBHOOK_AUTH_TOKEN } = process.env;
4
+
5
+ const isAuthorized = ({ authorization = '' }) => {
6
+ const [type, token] = authorization.split(' ');
7
+ return type === 'Bearer' && token === MINIO_WEBHOOK_AUTH_TOKEN;
8
+ };
9
+
10
+ export const minioHandler = async (req, res) => {
11
+ try {
12
+ if (req.method === 'POST' && req.body) {
13
+ const { headers } = req;
14
+ const { Records = [], EventName } = req.body;
15
+ if (EventName === 's3:ObjectCreated:Put' && isAuthorized(headers)) {
16
+ const [{ s3 }] = Records;
17
+ const { object } = s3;
18
+ const { size, contentType: type } = object;
19
+ const [fileId] = object.key.split('.');
20
+ const { services } = req.unchainedContext;
21
+ await services.files.linkFile({ fileId, type, size }, req.unchainedContext);
22
+ res.writeHead(200);
23
+ res.end();
24
+ return;
25
+ }
26
+ }
27
+ res.writeHead(404);
28
+ res.end();
29
+ return;
30
+ } catch (e) {
31
+ log(e.message, { level: LogLevel.Error });
32
+ res.writeHead(503);
33
+ res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
34
+ }
35
+ };
@@ -1,8 +1,6 @@
1
+ /// <reference lib="dom" />
1
2
  import { Context } from '@unchainedshop/types/api';
2
3
  import { IPaymentAdapter } from '@unchainedshop/types/payments';
3
- import bodyParser from 'body-parser';
4
- import fetch from 'node-fetch';
5
- import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
6
4
  import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
7
5
  import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
8
6
  import { createLogger } from '@unchainedshop/logger';
@@ -10,11 +8,7 @@ import { AppleTransactionsModule } from './module/configureAppleTransactionsModu
10
8
 
11
9
  const logger = createLogger('unchained:core-payment:iap');
12
10
 
13
- const {
14
- APPLE_IAP_SHARED_SECRET,
15
- APPLE_IAP_ENVIRONMENT = 'sandbox',
16
- APPLE_IAP_WEBHOOK_PATH = '/payment/apple-iap',
17
- } = process.env;
11
+ const { APPLE_IAP_SHARED_SECRET, APPLE_IAP_ENVIRONMENT = 'sandbox' } = process.env;
18
12
 
19
13
  // https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store
20
14
  const environments = {
@@ -88,144 +82,134 @@ const fixPeriods = async (
88
82
  );
89
83
  };
90
84
 
91
- export default (app) => {
92
- useMiddlewareWithCurrentContext(
93
- app,
94
- APPLE_IAP_WEBHOOK_PATH,
95
- bodyParser.json({
96
- strict: false,
97
- }),
98
- );
99
-
100
- useMiddlewareWithCurrentContext(app, APPLE_IAP_WEBHOOK_PATH, async (req, res) => {
101
- if (req.method === 'POST') {
102
- try {
103
- const resolvedContext = req.unchainedContext as Context;
104
- const { modules, services } = resolvedContext;
105
- const responseBody = req.body || {};
106
- if (responseBody.password !== APPLE_IAP_SHARED_SECRET) {
107
- throw new Error('shared secret not valid');
108
- }
109
-
110
- const transactions = responseBody?.unified_receipt?.latest_receipt_info; // eslint-disable-line
111
- const latestTransaction = transactions[0];
112
-
113
- if (responseBody.notification_type === AppleNotificationTypes.INITIAL_BUY) {
114
- // Find the cart to checkout
115
- const orderPayment = await modules.orders.payments.findOrderPaymentByContextData({
116
- context: {
117
- 'meta.transactionIdentifier': latestTransaction.transaction_id,
118
- },
119
- });
85
+ export const appleIAPHandler = async (req, res) => {
86
+ if (req.method === 'POST') {
87
+ try {
88
+ const resolvedContext = req.unchainedContext as Context;
89
+ const { modules, services } = resolvedContext;
90
+ const responseBody = req.body || {};
91
+ if (responseBody.password !== APPLE_IAP_SHARED_SECRET) {
92
+ throw new Error('shared secret not valid');
93
+ }
120
94
 
121
- if (!orderPayment) throw new Error('Could not find any matching order payment');
122
- const order = await modules.orders.findOrder({
123
- orderId: orderPayment.orderId,
124
- });
95
+ const transactions = responseBody?.unified_receipt?.latest_receipt_info; // eslint-disable-line
96
+ const latestTransaction = transactions[0];
125
97
 
126
- if (modules.orders.isCart(order)) {
127
- // checkout if is cart, else just ignore because the cart is already checked out
128
- // through submission of the receipt with GraphQL
129
- const checkedOut = await modules.orders.checkout(
130
- order._id,
131
- {
132
- paymentContext: {
133
- receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
134
- },
135
- },
136
- resolvedContext,
137
- );
138
- const orderId = checkedOut._id;
139
- const enrollment = await modules.enrollments.findEnrollment({
140
- orderId,
141
- });
142
- await fixPeriods(
143
- {
144
- transactionId: latestTransaction.original_transaction_id,
145
- transactions,
146
- enrollmentId: enrollment._id,
147
- orderId,
148
- },
149
- resolvedContext,
150
- );
98
+ if (responseBody.notification_type === AppleNotificationTypes.INITIAL_BUY) {
99
+ // Find the cart to checkout
100
+ const orderPayment = await modules.orders.payments.findOrderPaymentByContextData({
101
+ context: {
102
+ 'meta.transactionIdentifier': latestTransaction.transaction_id,
103
+ },
104
+ });
151
105
 
152
- logger.info(`Apple IAP Webhook: Confirmed checkout for order ${checkedOut.orderNumber}`, {
153
- orderId: checkedOut._id,
154
- });
155
- }
156
- } else {
157
- // Just store payment credentials, use the enrollments paymentProvider reference and
158
- // let the job do the rest
159
- const originalOrderPayment = await modules.orders.payments.findOrderPaymentByContextData({
160
- context: {
161
- 'meta.transactionIdentifier': latestTransaction.original_transaction_id,
162
- },
163
- });
164
- if (!originalOrderPayment) throw new Error('Could not find any matching order payment');
165
- const originalOrder = await modules.orders.findOrder({
166
- orderId: originalOrderPayment.orderId,
167
- });
168
- const enrollment = await modules.enrollments.findEnrollment({
169
- orderId: originalOrder._id,
170
- });
106
+ if (!orderPayment) throw new Error('Could not find any matching order payment');
107
+ const order = await modules.orders.findOrder({
108
+ orderId: orderPayment.orderId,
109
+ });
171
110
 
172
- await services.payment.registerPaymentCredentials(
173
- enrollment.payment.paymentProviderId,
111
+ if (modules.orders.isCart(order)) {
112
+ // checkout if is cart, else just ignore because the cart is already checked out
113
+ // through submission of the receipt with GraphQL
114
+ const checkedOut = await modules.orders.checkout(
115
+ order._id,
174
116
  {
175
- transactionContext: {
117
+ paymentContext: {
176
118
  receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
177
119
  },
178
120
  },
179
121
  resolvedContext,
180
122
  );
181
-
123
+ const orderId = checkedOut._id;
124
+ const enrollment = await modules.enrollments.findEnrollment({
125
+ orderId,
126
+ });
182
127
  await fixPeriods(
183
128
  {
184
129
  transactionId: latestTransaction.original_transaction_id,
185
130
  transactions,
186
131
  enrollmentId: enrollment._id,
187
- orderId: originalOrder._id,
132
+ orderId,
188
133
  },
189
134
  resolvedContext,
190
135
  );
191
136
 
192
- logger.info(
193
- `Apple IAP Webhook: Processed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
194
- );
137
+ logger.info(`Apple IAP Webhook: Confirmed checkout for order ${checkedOut.orderNumber}`, {
138
+ orderId: checkedOut._id,
139
+ });
140
+ }
141
+ } else {
142
+ // Just store payment credentials, use the enrollments paymentProvider reference and
143
+ // let the job do the rest
144
+ const originalOrderPayment = await modules.orders.payments.findOrderPaymentByContextData({
145
+ context: {
146
+ 'meta.transactionIdentifier': latestTransaction.original_transaction_id,
147
+ },
148
+ });
149
+ if (!originalOrderPayment) throw new Error('Could not find any matching order payment');
150
+ const originalOrder = await modules.orders.findOrder({
151
+ orderId: originalOrderPayment.orderId,
152
+ });
153
+ const enrollment = await modules.enrollments.findEnrollment({
154
+ orderId: originalOrder._id,
155
+ });
195
156
 
196
- if (responseBody.notification_type === AppleNotificationTypes.DID_RECOVER) {
197
- if (
198
- enrollment.status !== EnrollmentStatus.TERMINATED &&
199
- responseBody.auto_renew_status === 'false'
200
- ) {
201
- await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
202
- }
203
- }
157
+ await services.payment.registerPaymentCredentials(
158
+ enrollment.payment.paymentProviderId,
159
+ {
160
+ transactionContext: {
161
+ receiptData: responseBody?.unified_receipt?.latest_receipt, // eslint-disable-line
162
+ },
163
+ },
164
+ resolvedContext,
165
+ );
204
166
 
205
- if (responseBody.notification_type === AppleNotificationTypes.DID_CHANGE_RENEWAL_STATUS) {
206
- if (
207
- enrollment.status !== EnrollmentStatus.TERMINATED &&
208
- responseBody.auto_renew_status === 'false'
209
- ) {
210
- await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
211
- }
167
+ await fixPeriods(
168
+ {
169
+ transactionId: latestTransaction.original_transaction_id,
170
+ transactions,
171
+ enrollmentId: enrollment._id,
172
+ orderId: originalOrder._id,
173
+ },
174
+ resolvedContext,
175
+ );
176
+
177
+ logger.info(
178
+ `Apple IAP Webhook: Processed notification for ${latestTransaction.original_transaction_id} and type ${responseBody.notification_type}`,
179
+ );
180
+
181
+ if (responseBody.notification_type === AppleNotificationTypes.DID_RECOVER) {
182
+ if (
183
+ enrollment.status !== EnrollmentStatus.TERMINATED &&
184
+ responseBody.auto_renew_status === 'false'
185
+ ) {
186
+ await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
212
187
  }
213
- logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
214
188
  }
215
189
 
216
- res.writeHead(200);
217
- res.end();
218
- return;
219
- } catch (e) {
220
- logger.warn(`Apple IAP Webhook: ${e.message}`, e);
221
- res.writeHead(503);
222
- res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
223
- return;
190
+ if (responseBody.notification_type === AppleNotificationTypes.DID_CHANGE_RENEWAL_STATUS) {
191
+ if (
192
+ enrollment.status !== EnrollmentStatus.TERMINATED &&
193
+ responseBody.auto_renew_status === 'false'
194
+ ) {
195
+ await modules.enrollments.terminateEnrollment(enrollment, {}, resolvedContext);
196
+ }
197
+ }
198
+ logger.info(`Apple IAP Webhook: Updated enrollment from Apple`);
224
199
  }
200
+
201
+ res.writeHead(200);
202
+ res.end();
203
+ return;
204
+ } catch (e) {
205
+ logger.warn(`Apple IAP Webhook: ${e.message}`, e);
206
+ res.writeHead(503);
207
+ res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
208
+ return;
225
209
  }
226
- res.writeHead(404);
227
- res.end();
228
- });
210
+ }
211
+ res.writeHead(404);
212
+ res.end();
229
213
  };
230
214
 
231
215
  const AppleIAP: IPaymentAdapter = {
@@ -1,4 +1,2 @@
1
- import setupAppleIAP from './adapter';
2
-
3
- export default setupAppleIAP;
4
- export { configureAppleTransactionsModule } from './module/configureAppleTransactionsModule';
1
+ export * from './adapter';
2
+ export * from './module/configureAppleTransactionsModule';
@@ -1,8 +1,6 @@
1
- import setupCryptopayWebhooks from './middleware';
2
1
  import CryptopayPlugin from './plugin';
3
2
 
4
- export { configureCryptopayModule } from './module/configureCryptopayModule';
5
-
6
- export { setupCryptopayWebhooks };
3
+ export * from './middleware';
4
+ export * from './module/configureCryptopayModule';
7
5
 
8
6
  export default CryptopayPlugin;