@paykka/card-checkout-ui 0.11.4 → 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
@@ -162,6 +162,7 @@ function createGooglePay(checkout, pay, onClick, onCanUse) {
162
162
  const loadGooglePayJS = (onload, onerror) => {
163
163
  var _a;
164
164
  if ((_a = window.google) == null ? void 0 : _a.payments) {
165
+ onload == null ? void 0 : onload();
165
166
  return;
166
167
  }
167
168
  loadScript({
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykka/card-checkout-ui",
3
- "version": "0.11.4",
3
+ "version": "0.11.6",
4
4
  "type": "module",
5
5
  "main": "dist/paykka-card-checkout-ui.umd.js",
6
6
  "module": "dist/es/index.js",
@@ -33,7 +33,7 @@
33
33
  "release:prod": "pnpm build && pnpm changeset:release",
34
34
  "release:noprod": "pnpm build && pnpm changeset:pre-exit && pnpm changeset:prelease",
35
35
  "type-check": "tsc --noEmit -p tsconfig.json --composite false",
36
- "release:npm": "npm publish --registry=https://registry.npmjs.org --access public"
36
+ "release:npm": "pnpm build && npm publish --registry=https://registry.npmjs.org --access public"
37
37
  },
38
38
  "publishConfig": {
39
39
  "registry": "https://packages.aliyun.com/640edee5a84870ae9d591e48/npm/npm-registry/"