@yeepay/client-utils 4.0.5 → 4.1.0
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/dist/index.d.mts +26 -1
- package/dist/index.mjs +39 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,31 @@ import debug from "debug";
|
|
|
2
2
|
import { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from "axios";
|
|
3
3
|
export * from "@imyangyong/utils";
|
|
4
4
|
|
|
5
|
+
//#region src/aliyun-arms.d.ts
|
|
6
|
+
interface AliyunArmsCustomEvent {
|
|
7
|
+
type: string;
|
|
8
|
+
name: string;
|
|
9
|
+
group?: string;
|
|
10
|
+
value?: number;
|
|
11
|
+
properties?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface WaitForAliyunArmsOptions {
|
|
14
|
+
timeout?: number;
|
|
15
|
+
interval?: number;
|
|
16
|
+
}
|
|
17
|
+
interface AliyunArmsRum {
|
|
18
|
+
sendCustom: (payload: AliyunArmsCustomEvent) => void;
|
|
19
|
+
}
|
|
20
|
+
declare global {
|
|
21
|
+
interface Window {
|
|
22
|
+
RumSDK?: {
|
|
23
|
+
default?: Partial<AliyunArmsRum>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
declare function waitForAliyunArms(options?: WaitForAliyunArmsOptions): Promise<AliyunArmsRum | undefined>;
|
|
28
|
+
declare function sendAliyunRumCustom(payload: AliyunArmsCustomEvent, options?: WaitForAliyunArmsOptions): Promise<boolean>;
|
|
29
|
+
//#endregion
|
|
5
30
|
//#region src/debug.d.ts
|
|
6
31
|
declare const logger: Record<string, debug.Debugger> & debug.Debugger;
|
|
7
32
|
declare global {
|
|
@@ -109,4 +134,4 @@ declare function removeToken(): void;
|
|
|
109
134
|
//#region src/utils.d.ts
|
|
110
135
|
declare function getQueryObject(url?: string): Record<string, string>;
|
|
111
136
|
//#endregion
|
|
112
|
-
export { BREAKPOINTS, MEDIA_QUERIES, logger as debug, getQueryObject, getToken, isDesktop, isMobile, isTablet, removeToken, serviceFactory, setTokenFromUrl, verifySuccessCode };
|
|
137
|
+
export { AliyunArmsCustomEvent, AliyunArmsRum, BREAKPOINTS, MEDIA_QUERIES, WaitForAliyunArmsOptions, logger as debug, getQueryObject, getToken, isDesktop, isMobile, isTablet, removeToken, sendAliyunRumCustom, serviceFactory, setTokenFromUrl, verifySuccessCode, waitForAliyunArms };
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,44 @@ import Cookie from "js-cookie";
|
|
|
8
8
|
|
|
9
9
|
export * from "@imyangyong/utils"
|
|
10
10
|
|
|
11
|
+
//#region src/aliyun-arms.ts
|
|
12
|
+
const DEFAULT_TIMEOUT = 3e3;
|
|
13
|
+
const DEFAULT_INTERVAL = 100;
|
|
14
|
+
function getAliyunArmsRum() {
|
|
15
|
+
if (typeof window === "undefined") return void 0;
|
|
16
|
+
const sdk = window.RumSDK?.default;
|
|
17
|
+
if (typeof sdk?.sendCustom !== "function") return void 0;
|
|
18
|
+
return sdk;
|
|
19
|
+
}
|
|
20
|
+
function wait(ms) {
|
|
21
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
22
|
+
}
|
|
23
|
+
async function waitForAliyunArms(options = {}) {
|
|
24
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
25
|
+
const interval = options.interval ?? DEFAULT_INTERVAL;
|
|
26
|
+
const readySdk = getAliyunArmsRum();
|
|
27
|
+
if (readySdk || timeout <= 0) return readySdk;
|
|
28
|
+
const deadline = Date.now() + timeout;
|
|
29
|
+
while (Date.now() < deadline) {
|
|
30
|
+
await wait(Math.min(interval, deadline - Date.now()));
|
|
31
|
+
const sdk = getAliyunArmsRum();
|
|
32
|
+
if (sdk) return sdk;
|
|
33
|
+
}
|
|
34
|
+
return getAliyunArmsRum();
|
|
35
|
+
}
|
|
36
|
+
async function sendAliyunRumCustom(payload, options) {
|
|
37
|
+
const sdk = await waitForAliyunArms(options);
|
|
38
|
+
if (!sdk) return false;
|
|
39
|
+
try {
|
|
40
|
+
sdk.sendCustom(payload);
|
|
41
|
+
return true;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.warn("[aliyun-arms] sendCustom failed:", err);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
11
49
|
//#region src/debug.ts
|
|
12
50
|
function createLogger(namespace) {
|
|
13
51
|
return debug(namespace);
|
|
@@ -298,4 +336,4 @@ function serviceFactory(options, callbacks) {
|
|
|
298
336
|
}
|
|
299
337
|
|
|
300
338
|
//#endregion
|
|
301
|
-
export { BREAKPOINTS, MEDIA_QUERIES, logger as debug, getQueryObject, getToken, isDesktop, isMobile, isTablet, removeToken, serviceFactory, setTokenFromUrl, verifySuccessCode };
|
|
339
|
+
export { BREAKPOINTS, MEDIA_QUERIES, logger as debug, getQueryObject, getToken, isDesktop, isMobile, isTablet, removeToken, sendAliyunRumCustom, serviceFactory, setTokenFromUrl, verifySuccessCode, waitForAliyunArms };
|
package/package.json
CHANGED