@paykka/card-checkout-ui 0.11.5 → 0.11.6

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,3 +1,4 @@
1
+ import { RequestCacheManager } from "../../../utils/request-cache-manager.js";
1
2
  import { http } from "../../http.js";
2
3
  import { getBrowserParams } from "../get-browser-params.js";
3
4
  import { checkoutMap } from "./map.js";
@@ -16,13 +17,10 @@ const getCheckoutInfo = async ({ sessionId, clientKey }, options) => {
16
17
  const checkoutInfo = await queryCheckout({ sessionId, clientKey }, options);
17
18
  return checkoutMap({ ...checkoutInfo, ...checkoutInfo == null ? void 0 : checkoutInfo.support_methods });
18
19
  };
19
- let getCheckoutInfoIns;
20
- const onceGetCheckoutInfo = async ({ sessionId, clientKey }, options) => {
21
- if (!getCheckoutInfoIns) {
22
- return getCheckoutInfoIns = getCheckoutInfo({ sessionId, clientKey }, options);
23
- } else {
24
- return getCheckoutInfoIns;
25
- }
20
+ const requestCacheManager = new RequestCacheManager();
21
+ const onceGetCheckoutInfo = async (params, options) => {
22
+ const request = getCheckoutInfo(params, options);
23
+ return requestCacheManager.cacheRequest(JSON.stringify(params), request);
26
24
  };
27
25
  export {
28
26
  onceGetCheckoutInfo
package/dist/es/core.js CHANGED
@@ -698,6 +698,36 @@ l$3.diffed = function(n2) {
698
698
  var t2 = n2.props, e2 = n2.__e;
699
699
  null != e2 && "textarea" === n2.type && "value" in t2 && t2.value !== e2.value && (e2.value = null == t2.value ? "" : t2.value);
700
700
  };
701
+ function e$1(e2, n2) {
702
+ return n2 = n2 || {}, new Promise(function(t2, r2) {
703
+ var s2 = new XMLHttpRequest(), o2 = [], u2 = {}, a2 = function e3() {
704
+ return { ok: 2 == (s2.status / 100 | 0), statusText: s2.statusText, status: s2.status, url: s2.responseURL, text: function() {
705
+ return Promise.resolve(s2.responseText);
706
+ }, json: function() {
707
+ return Promise.resolve(s2.responseText).then(JSON.parse);
708
+ }, blob: function() {
709
+ return Promise.resolve(new Blob([s2.response]));
710
+ }, clone: e3, headers: { keys: function() {
711
+ return o2;
712
+ }, entries: function() {
713
+ return o2.map(function(e4) {
714
+ return [e4, s2.getResponseHeader(e4)];
715
+ });
716
+ }, get: function(e4) {
717
+ return s2.getResponseHeader(e4);
718
+ }, has: function(e4) {
719
+ return null != s2.getResponseHeader(e4);
720
+ } } };
721
+ };
722
+ for (var i2 in s2.open(n2.method || "get", e2, true), s2.onload = function() {
723
+ s2.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm, function(e3, n3) {
724
+ u2[n3] || o2.push(u2[n3] = n3);
725
+ }), t2(a2());
726
+ }, s2.onerror = r2, s2.withCredentials = "include" == n2.credentials, n2.headers)
727
+ s2.setRequestHeader(i2, n2.headers[i2]);
728
+ s2.send(n2.body || null);
729
+ });
730
+ }
701
731
  var __assign = function() {
702
732
  __assign = Object.assign || function __assign2(t2) {
703
733
  for (var s2, i2 = 1, n2 = arguments.length; i2 < n2; i2++) {
@@ -3910,7 +3940,7 @@ function t() {
3910
3940
  }
3911
3941
  var o = void 0;
3912
3942
  var h = void 0, s$1 = 0, f = 0, v = 0;
3913
- function e$1(i2) {
3943
+ function e(i2) {
3914
3944
  if (void 0 !== o) {
3915
3945
  var t2 = i2.n;
3916
3946
  if (void 0 === t2 || t2.t !== o) {
@@ -4001,7 +4031,7 @@ u.prototype.peek = function() {
4001
4031
  }
4002
4032
  };
4003
4033
  Object.defineProperty(u.prototype, "value", { get: function() {
4004
- var i2 = e$1(this);
4034
+ var i2 = e(this);
4005
4035
  if (void 0 !== i2)
4006
4036
  i2.i = this.i;
4007
4037
  return this.v;
@@ -4132,7 +4162,7 @@ y.prototype.N = function() {
4132
4162
  Object.defineProperty(y.prototype, "value", { get: function() {
4133
4163
  if (1 & this.f)
4134
4164
  throw new Error("Cycle detected");
4135
- var i2 = e$1(this);
4165
+ var i2 = e(this);
4136
4166
  this.h();
4137
4167
  if (void 0 !== i2)
4138
4168
  i2.i = this.i;
@@ -4415,36 +4445,6 @@ function useSignal(n2) {
4415
4445
  return d$1(n2);
4416
4446
  }, []);
4417
4447
  }
4418
- function e(e2, n2) {
4419
- return n2 = n2 || {}, new Promise(function(t2, r2) {
4420
- var s2 = new XMLHttpRequest(), o2 = [], u2 = {}, a2 = function e3() {
4421
- return { ok: 2 == (s2.status / 100 | 0), statusText: s2.statusText, status: s2.status, url: s2.responseURL, text: function() {
4422
- return Promise.resolve(s2.responseText);
4423
- }, json: function() {
4424
- return Promise.resolve(s2.responseText).then(JSON.parse);
4425
- }, blob: function() {
4426
- return Promise.resolve(new Blob([s2.response]));
4427
- }, clone: e3, headers: { keys: function() {
4428
- return o2;
4429
- }, entries: function() {
4430
- return o2.map(function(e4) {
4431
- return [e4, s2.getResponseHeader(e4)];
4432
- });
4433
- }, get: function(e4) {
4434
- return s2.getResponseHeader(e4);
4435
- }, has: function(e4) {
4436
- return null != s2.getResponseHeader(e4);
4437
- } } };
4438
- };
4439
- for (var i2 in s2.open(n2.method || "get", e2, true), s2.onload = function() {
4440
- s2.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm, function(e3, n3) {
4441
- u2[n3] || o2.push(u2[n3] = n3);
4442
- }), t2(a2());
4443
- }, s2.onerror = r2, s2.withCredentials = "include" == n2.credentials, n2.headers)
4444
- s2.setRequestHeader(i2, n2.headers[i2]);
4445
- s2.send(n2.body || null);
4446
- });
4447
- }
4448
4448
  var browser = {};
4449
4449
  var canPromise$1 = function() {
4450
4450
  return typeof Promise === "function" && Promise.prototype && Promise.prototype.then;
@@ -6443,7 +6443,7 @@ export {
6443
6443
  b$1 as b,
6444
6444
  browser,
6445
6445
  d$1 as d,
6446
- e,
6446
+ e$1 as e,
6447
6447
  h$1 as h,
6448
6448
  index,
6449
6449
  inputToRGB,
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ class RequestCacheManager {
8
+ constructor() {
9
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
10
+ }
11
+ /**
12
+ * 缓存请求
13
+ * @param key 任意格式,自己控制
14
+ * @param request 请求函数
15
+ */
16
+ cacheRequest(key, request) {
17
+ const cachedRequest = this.cache.get(key);
18
+ if (cachedRequest) {
19
+ return cachedRequest;
20
+ }
21
+ const promise = request;
22
+ const wrappedPromise = promise.catch((error) => {
23
+ this.cache.delete(key);
24
+ throw error;
25
+ });
26
+ this.cache.set(key, wrappedPromise);
27
+ return wrappedPromise;
28
+ }
29
+ }
30
+ export {
31
+ RequestCacheManager
32
+ };
@@ -3,4 +3,4 @@ import type { CheckoutRes, QueryCheckoutParams } from './type';
3
3
  export * from './type';
4
4
  export * from './map';
5
5
  export declare const getCheckoutInfo: ({ sessionId, clientKey }: QueryCheckoutParams, options?: RequestOptions) => Promise<CheckoutRes>;
6
- export declare const onceGetCheckoutInfo: ({ sessionId, clientKey }: QueryCheckoutParams, options?: RequestOptions) => Promise<CheckoutRes>;
6
+ export declare const onceGetCheckoutInfo: (params: QueryCheckoutParams, options?: RequestOptions) => Promise<CheckoutRes>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 请求缓存管理器,缓存请求的 Promise 实例,避免重复请求
3
+ */
4
+ export declare class RequestCacheManager<R> {
5
+ private cache;
6
+ /**
7
+ * 缓存请求
8
+ * @param key 任意格式,自己控制
9
+ * @param request 请求函数
10
+ */
11
+ cacheRequest(key: string, request: Promise<R>): Promise<R>;
12
+ }
package/package.json CHANGED
@@ -1,67 +1,67 @@
1
- {
2
- "name": "@paykka/card-checkout-ui",
3
- "version": "0.11.5",
4
- "type": "module",
5
- "main": "dist/paykka-card-checkout-ui.umd.js",
6
- "module": "dist/es/index.js",
7
- "typings": "dist/types/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "import": "./dist/es/index.js",
11
- "require": "./dist/paykka-card-checkout-ui.umd.js",
12
- "types": "./dist/types/index.d.ts"
13
- },
14
- "./*": "./dist/*"
15
- },
16
- "files": [
17
- "dist"
18
- ],
19
- "scripts": {
20
- "dev": "vite --host",
21
- "build": "pnpm type-check && pnpm build:npm && pnpm build:inner && pnpm copy-dist-to-cdn && pnpm build:outer",
22
- "build:npm": "tsx ./build/run.ts",
23
- "build:inner": "tsx ./build/runInner.ts",
24
- "build:outer": "tsx ./build/runOuter.ts",
25
- "build:type": "tsc -p ./tsconfig.build.json",
26
- "copy-dist-to-cdn": "tsx ./build/copyDist2CDN.ts",
27
- "changeset": "changeset",
28
- "changeset:pre": "changeset pre enter beta",
29
- "changeset:pre-exit": "changeset pre exit",
30
- "changeset:version": "changeset version",
31
- "changeset:release": "changeset publish",
32
- "changeset:prelease": "changeset publish --tag beta",
33
- "release:prod": "pnpm build && pnpm changeset:release",
34
- "release:noprod": "pnpm build && pnpm changeset:pre-exit && pnpm changeset:prelease",
35
- "type-check": "tsc --noEmit -p tsconfig.json --composite false",
36
- "release:npm": "pnpm build && npm publish --registry=https://registry.npmjs.org --access public"
37
- },
38
- "publishConfig": {
39
- "registry": "https://packages.aliyun.com/640edee5a84870ae9d591e48/npm/npm-registry/"
40
- },
41
- "dependencies": {
42
- "@ctrl/tinycolor": "^4.0.3",
43
- "@fingerprintjs/fingerprintjs": "^4.2.2",
44
- "@preact/signals": "^1.3.0",
45
- "@types/applepayjs": "^14.0.9",
46
- "@types/googlepay": "^0.7.6",
47
- "@types/qrcode": "^1.5.5",
48
- "preact": "^10.24.3",
49
- "qrcode": "^1.5.4",
50
- "ts-toolbelt": "^9.6.0",
51
- "unfetch": "^5.0.0",
52
- "vue-tsc": "^2.1.10"
53
- },
54
- "devDependencies": {
55
- "@changesets/cli": "^2.27.1",
56
- "@preact/preset-vite": "^2.9.1",
57
- "@types/node": "^20.12.7",
58
- "autoprefixer": "^10.4.18",
59
- "execa": "^8.0.1",
60
- "fast-glob": "^3.3.2",
61
- "sass": "^1.71.1",
62
- "terser": "^5.42.0",
63
- "tsx": "^4.7.3",
64
- "typescript": "^5.4.5",
65
- "vite": "^5.2.10"
66
- }
67
- }
1
+ {
2
+ "name": "@paykka/card-checkout-ui",
3
+ "version": "0.11.6",
4
+ "type": "module",
5
+ "main": "dist/paykka-card-checkout-ui.umd.js",
6
+ "module": "dist/es/index.js",
7
+ "typings": "dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/es/index.js",
11
+ "require": "./dist/paykka-card-checkout-ui.umd.js",
12
+ "types": "./dist/types/index.d.ts"
13
+ },
14
+ "./*": "./dist/*"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "dev": "vite --host",
21
+ "build": "pnpm type-check && pnpm build:npm && pnpm build:inner && pnpm copy-dist-to-cdn && pnpm build:outer",
22
+ "build:npm": "tsx ./build/run.ts",
23
+ "build:inner": "tsx ./build/runInner.ts",
24
+ "build:outer": "tsx ./build/runOuter.ts",
25
+ "build:type": "tsc -p ./tsconfig.build.json",
26
+ "copy-dist-to-cdn": "tsx ./build/copyDist2CDN.ts",
27
+ "changeset": "changeset",
28
+ "changeset:pre": "changeset pre enter beta",
29
+ "changeset:pre-exit": "changeset pre exit",
30
+ "changeset:version": "changeset version",
31
+ "changeset:release": "changeset publish",
32
+ "changeset:prelease": "changeset publish --tag beta",
33
+ "release:prod": "pnpm build && pnpm changeset:release",
34
+ "release:noprod": "pnpm build && pnpm changeset:pre-exit && pnpm changeset:prelease",
35
+ "type-check": "tsc --noEmit -p tsconfig.json --composite false",
36
+ "release:npm": "pnpm build && npm publish --registry=https://registry.npmjs.org --access public"
37
+ },
38
+ "publishConfig": {
39
+ "registry": "https://packages.aliyun.com/640edee5a84870ae9d591e48/npm/npm-registry/"
40
+ },
41
+ "dependencies": {
42
+ "@ctrl/tinycolor": "^4.0.3",
43
+ "@fingerprintjs/fingerprintjs": "^4.2.2",
44
+ "@preact/signals": "^1.3.0",
45
+ "@types/applepayjs": "^14.0.9",
46
+ "@types/googlepay": "^0.7.6",
47
+ "@types/qrcode": "^1.5.5",
48
+ "preact": "^10.24.3",
49
+ "qrcode": "^1.5.4",
50
+ "ts-toolbelt": "^9.6.0",
51
+ "unfetch": "^5.0.0",
52
+ "vue-tsc": "^2.1.10"
53
+ },
54
+ "devDependencies": {
55
+ "@changesets/cli": "^2.27.1",
56
+ "@preact/preset-vite": "^2.9.1",
57
+ "@types/node": "^20.12.7",
58
+ "autoprefixer": "^10.4.18",
59
+ "execa": "^8.0.1",
60
+ "fast-glob": "^3.3.2",
61
+ "sass": "^1.71.1",
62
+ "terser": "^5.42.0",
63
+ "tsx": "^4.7.3",
64
+ "typescript": "^5.4.5",
65
+ "vite": "^5.2.10"
66
+ }
67
+ }