payment-kit 1.22.6 → 1.22.8

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.
@@ -1,6 +1,6 @@
1
1
  import { Auth as VendorAuth } from '@blocklet/payment-vendor';
2
2
 
3
- import { joinURL } from 'ufo';
3
+ import { joinURL, withQuery } from 'ufo';
4
4
  import { ProductVendor } from '../../../store/models';
5
5
  import dayjs from '../../dayjs';
6
6
  import logger from '../../logger';
@@ -18,33 +18,59 @@ import {
18
18
  } from './types';
19
19
  import { formatVendorUrl } from './util';
20
20
 
21
+ async function getBlockletInfo(appUrl: string): Promise<any> {
22
+ const url = joinURL(appUrl, '__blocklet__.js?type=json&noCache=1&owner=1');
23
+ try {
24
+ const blocklet = await api.get(url, { headers: { 'Content-Type': 'application/json' } });
25
+ return blocklet.data;
26
+ } catch (error: any) {
27
+ logger.error('Failed to get blocklet info', { url, error });
28
+ return null;
29
+ }
30
+ }
31
+
21
32
  const doRequestVendorData = async (
22
33
  vendor: ProductVendor,
23
34
  orderId: string,
24
- url: string,
25
- options: { shortUrl: boolean }
35
+ baseUrl: string,
36
+ options: { shortUrl: boolean; query?: Record<string, string>; type?: 'order' | 'status' }
26
37
  ) => {
27
- const { headers } = await VendorAuth.signRequestWithHeaders({});
28
38
  const name = vendor?.name;
29
39
  const key = vendor?.vendor_key;
30
- const { shortUrl } = options;
40
+ const { shortUrl, query, type } = options;
41
+ const { headers } = await VendorAuth.signRequestWithHeaders({ ...query });
42
+
43
+ let url = baseUrl;
44
+ if (query) {
45
+ url = withQuery(baseUrl, query);
46
+ }
31
47
 
32
- return fetch(url, { headers })
48
+ return fetch(url, { headers, method: 'GET' })
33
49
  .then(async (r) => {
34
50
  const data = await r.json();
35
51
  if (r.status !== 200) {
36
- logger.error('vendor status fetch failed', {
52
+ logger.error(`vendor ${type} fetch failed`, {
53
+ status: r.status,
37
54
  vendorId: vendor.id,
38
55
  vendorKey: vendor.vendor_key,
39
56
  orderId,
40
- status: r.status,
41
57
  url,
58
+ query,
42
59
  data,
43
60
  });
44
61
  throw new Error(
45
62
  `vendor status fetch failed, vendor: ${vendor.vendor_key}, orderId: ${orderId}, status: ${r.status}, url: ${url}`
46
63
  );
64
+ } else if (type === 'order') {
65
+ logger.info('vendor order fetch success', {
66
+ vendorId: vendor.id,
67
+ vendorKey: vendor.vendor_key,
68
+ orderId,
69
+ url,
70
+ query,
71
+ });
47
72
  }
73
+
48
74
  if (!shortUrl || !data.dashboardUrl) {
49
75
  return {
50
76
  ...data,
@@ -237,29 +263,22 @@ export class LauncherAdapter implements VendorAdapter {
237
263
  }
238
264
 
239
265
  async checkOrderStatus(params: CheckOrderStatusParams): Promise<CheckOrderStatusResult> {
240
- const url = joinURL(params.appUrl, '__blocklet__.js?type=json&noCache=1');
241
266
  try {
242
- const blocklet = await api.get(url, { headers: { 'Content-Type': 'application/json' } });
243
- const blockletInfo = blocklet.data;
267
+ const blockletInfo = await getBlockletInfo(params.appUrl);
244
268
 
245
269
  let status: 'processing' | 'completed' | 'failed' = 'processing';
246
270
  if (blockletInfo.status === 'running') {
247
- if (blockletInfo.componentMountPoints.every((x: any) => x.status === 'running')) {
271
+ if (!!blockletInfo.ownerDid && blockletInfo.componentMountPoints.every((x: any) => x.status === 'running')) {
248
272
  status = 'completed';
249
- } else if (blockletInfo.componentMountPoints.some((x: any) => x.status === 'failed')) {
273
+ } else if (blockletInfo.componentMountPoints.some((x: any) => ['failed', 'error'].includes(x.status))) {
250
274
  status = 'failed';
251
275
  }
252
- } else if (blockletInfo.status === 'failed') {
276
+ } else if (['failed', 'error'].includes(blockletInfo.status)) {
253
277
  status = 'failed';
254
278
  }
255
279
  return { status };
256
280
  } catch (error: any) {
257
- logger.error('Failed to check order status', {
258
- url,
259
- error: error.message,
260
- stack: error.stack,
261
- });
262
-
281
+ logger.error('Failed to check order status', { error, appUrl: params.appUrl });
263
282
  throw error;
264
283
  }
265
284
  }
@@ -273,33 +292,24 @@ export class LauncherAdapter implements VendorAdapter {
273
292
  async getOrder(
274
293
  vendor: ProductVendor,
275
294
  orderId: string,
276
- options: { shortUrl: boolean; appUrl?: string }
295
+ options: { shortUrl: boolean; appUrl?: string; ownerDid?: string; appDid?: string }
277
296
  ): Promise<any> {
278
- const { appUrl } = options;
279
- let ownerDid = '';
280
- let appDid = '';
297
+ const { appUrl, ownerDid: ownerDidParam, appDid: appDidParam } = options;
298
+ let ownerDid = ownerDidParam || '';
299
+ let appDid = appDidParam || '';
281
300
  if (appUrl) {
282
- const blockletInfoUrl = joinURL(appUrl, '__blocklet__.js?type=json&noCache=1&owner=1');
283
301
  try {
284
- const blocklet = await api.get(blockletInfoUrl, { headers: { 'Content-Type': 'application/json' } });
285
- const blockletInfo = blocklet.data;
286
-
302
+ const blockletInfo = await getBlockletInfo(appUrl);
287
303
  ownerDid = blockletInfo.ownerDid;
288
304
  appDid = blockletInfo.appId;
289
305
  } catch (error: any) {
290
- logger.error('Failed to get blocklet info', {
291
- url: blockletInfoUrl,
292
- error,
293
- });
306
+ logger.error('Failed to get blocklet info', { appUrl, error });
294
307
  }
295
308
  }
296
309
 
297
- const url = formatVendorUrl(
298
- vendor,
299
- `/api/vendor/orders/${orderId}?ownerDid=${ownerDid || ''}&appDid=${appDid || ''}`
300
- );
310
+ const url = formatVendorUrl(vendor, `/api/vendor/orders/${orderId}`);
301
311
 
302
- return doRequestVendorData(vendor, orderId, url, options);
312
+ return doRequestVendorData(vendor, orderId, url, { ...options, query: { ownerDid, appDid }, type: 'order' });
303
313
  }
304
314
 
305
315
  async connectTest(): Promise<any> {
@@ -344,12 +344,16 @@ async function executeVendorOperation({
344
344
  operation,
345
345
  shortUrl,
346
346
  appUrl,
347
+ ownerDid,
348
+ appDid,
347
349
  }: {
348
350
  vendorId: string;
349
351
  orderId: string;
350
352
  operation: 'getOrder' | 'getOrderStatus';
351
353
  shortUrl: boolean;
352
354
  appUrl?: string;
355
+ ownerDid?: string;
356
+ appDid?: string;
353
357
  }) {
354
358
  if (!vendorId || !orderId) {
355
359
  return {
@@ -370,7 +374,7 @@ async function executeVendorOperation({
370
374
 
371
375
  try {
372
376
  const vendorAdapter = await VendorFulfillmentService.getVendorAdapter(vendor.vendor_key);
373
- const data = await vendorAdapter[operation](vendor, orderId, { shortUrl, appUrl });
377
+ const data = await vendorAdapter[operation](vendor, orderId, { shortUrl, appUrl, ownerDid, appDid });
374
378
 
375
379
  return { data: { ...data, vendorType: vendor.vendor_type }, code: 200 };
376
380
  } catch (error: any) {
@@ -389,7 +393,13 @@ async function executeVendorOperation({
389
393
  }
390
394
  }
391
395
 
392
- async function processVendorOrders(sessionId: string, operation: 'getOrder' | 'getOrderStatus', shortUrl: boolean) {
396
+ async function processVendorOrders(
397
+ sessionId: string,
398
+ operation: 'getOrder' | 'getOrderStatus',
399
+ shortUrl: boolean,
400
+ ownerDid?: string,
401
+ appDid?: string
402
+ ) {
393
403
  const doc = await CheckoutSession.findByPk(sessionId);
394
404
 
395
405
  if (!doc) {
@@ -437,6 +447,8 @@ async function processVendorOrders(sessionId: string, operation: 'getOrder' | 'g
437
447
  operation,
438
448
  shortUrl,
439
449
  appUrl: item.app_url,
450
+ ownerDid,
451
+ appDid,
440
452
  });
441
453
 
442
454
  // Handle error responses from vendor functions
@@ -503,10 +515,10 @@ async function getVendorFulfillmentStatus(req: any, res: any) {
503
515
 
504
516
  async function getVendorFulfillmentDetail(req: any, res: any) {
505
517
  const { sessionId } = req.params;
506
- const { shortUrl } = req.query;
518
+ const { shortUrl, ownerDid, appDid } = req.query;
507
519
 
508
520
  try {
509
- const detail = await processVendorOrders(sessionId, 'getOrder', shortUrl === 'true');
521
+ const detail = await processVendorOrders(sessionId, 'getOrder', shortUrl === 'true', ownerDid, appDid);
510
522
  if (detail.code) {
511
523
  return res.status(detail.code).json({ error: detail.error });
512
524
  }
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.22.6
17
+ version: 1.22.8
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.22.6",
3
+ "version": "1.22.8",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "lint": "tsc --noEmit && eslint src api/src --ext .mjs,.js,.jsx,.ts,.tsx",
@@ -44,32 +44,32 @@
44
44
  ]
45
45
  },
46
46
  "dependencies": {
47
- "@abtnode/cron": "^1.17.0-beta-20251104-112713-e947b159",
48
- "@arcblock/did": "^1.26.3",
49
- "@arcblock/did-connect-react": "^3.1.54",
47
+ "@abtnode/cron": "^1.17.0",
48
+ "@arcblock/did": "^1.27.2",
49
+ "@arcblock/did-connect-react": "^3.1.60",
50
50
  "@arcblock/did-connect-storage-nedb": "^1.8.0",
51
51
  "@arcblock/did-util": "^1.27.2",
52
52
  "@arcblock/jwt": "^1.27.2",
53
- "@arcblock/react-hooks": "^3.1.54",
54
- "@arcblock/ux": "^3.1.54",
53
+ "@arcblock/react-hooks": "^3.1.60",
54
+ "@arcblock/ux": "^3.1.60",
55
55
  "@arcblock/validator": "^1.27.2",
56
- "@blocklet/did-space-js": "^1.1.35",
57
- "@blocklet/error": "^0.2.5",
58
- "@blocklet/js-sdk": "^1.17.0-beta-20251104-112713-e947b159",
59
- "@blocklet/logger": "^1.17.0-beta-20251104-112713-e947b159",
60
- "@blocklet/payment-broker-client": "1.22.6",
61
- "@blocklet/payment-react": "1.22.6",
62
- "@blocklet/payment-vendor": "1.22.6",
63
- "@blocklet/sdk": "^1.17.0-beta-20251104-112713-e947b159",
64
- "@blocklet/ui-react": "^3.1.54",
65
- "@blocklet/uploader": "^0.3.4",
66
- "@blocklet/xss": "^0.3.4",
56
+ "@blocklet/did-space-js": "^1.2.1",
57
+ "@blocklet/error": "^0.3.1",
58
+ "@blocklet/js-sdk": "^1.17.0",
59
+ "@blocklet/logger": "^1.17.0",
60
+ "@blocklet/payment-broker-client": "1.22.8",
61
+ "@blocklet/payment-react": "1.22.8",
62
+ "@blocklet/payment-vendor": "1.22.8",
63
+ "@blocklet/sdk": "^1.17.0",
64
+ "@blocklet/ui-react": "^3.1.60",
65
+ "@blocklet/uploader": "^0.3.5",
66
+ "@blocklet/xss": "^0.3.5",
67
67
  "@mui/icons-material": "^7.1.2",
68
68
  "@mui/lab": "7.0.0-beta.14",
69
69
  "@mui/material": "^7.1.2",
70
70
  "@mui/system": "^7.1.1",
71
71
  "@ocap/asset": "^1.27.2",
72
- "@ocap/client": "^1.26.3",
72
+ "@ocap/client": "^1.27.2",
73
73
  "@ocap/mcrypto": "^1.27.2",
74
74
  "@ocap/util": "^1.27.2",
75
75
  "@ocap/wallet": "^1.27.2",
@@ -127,9 +127,9 @@
127
127
  "web3": "^4.16.0"
128
128
  },
129
129
  "devDependencies": {
130
- "@abtnode/types": "^1.17.0-beta-20251104-112713-e947b159",
130
+ "@abtnode/types": "^1.17.0",
131
131
  "@arcblock/eslint-config-ts": "^0.3.3",
132
- "@blocklet/payment-types": "1.22.6",
132
+ "@blocklet/payment-types": "1.22.8",
133
133
  "@types/cookie-parser": "^1.4.9",
134
134
  "@types/cors": "^2.8.19",
135
135
  "@types/debug": "^4.1.12",
@@ -160,7 +160,7 @@
160
160
  "vite": "^7.0.0",
161
161
  "vite-node": "^3.2.4",
162
162
  "vite-plugin-babel-import": "^2.0.5",
163
- "vite-plugin-blocklet": "^0.11.2",
163
+ "vite-plugin-blocklet": "^0.12.1",
164
164
  "vite-plugin-node-polyfills": "^0.23.0",
165
165
  "vite-plugin-svgr": "^4.3.0",
166
166
  "vite-tsconfig-paths": "^5.1.4",
@@ -176,5 +176,5 @@
176
176
  "parser": "typescript"
177
177
  }
178
178
  },
179
- "gitHead": "69c7b775a4fa6ba27b5b317aa76e25db3fd4177f"
179
+ "gitHead": "14f70c4a934ae339a0a1e43bd84906015ca42138"
180
180
  }