@aippy/runtime 0.2.7-dev.5 → 0.2.7-dev.7

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 (41) hide show
  1. package/dist/ai/config/index.d.ts +1 -1
  2. package/dist/ai/config/parser.d.ts +5 -12
  3. package/dist/ai/errors.d.ts +1 -0
  4. package/dist/ai/index.d.ts +1 -1
  5. package/dist/ai/index.js +15 -16
  6. package/dist/ai/shared/fetch.d.ts +0 -4
  7. package/dist/ai/shared/index.d.ts +1 -1
  8. package/dist/app-version-checker-B1UXEcy9.js +240 -0
  9. package/dist/bridge-BQQ3PfSO.js +237 -0
  10. package/dist/config-B0A7gHQM.js +28 -0
  11. package/dist/container-message-YB3cWpWj.js +56 -0
  12. package/dist/core/errors.d.ts +22 -3
  13. package/dist/core/headers.d.ts +31 -0
  14. package/dist/core/index.d.ts +1 -0
  15. package/dist/core/index.js +22 -50
  16. package/dist/device/index.js +194 -194
  17. package/dist/errors-B3bDbQbD.js +40 -0
  18. package/dist/helper-BjRhidue.js +238 -0
  19. package/dist/hooks-C7VP176R.js +98 -0
  20. package/dist/index/index.js +89 -80
  21. package/dist/pwa-C5nXU0DN.js +250 -0
  22. package/dist/tweaks/index.js +1 -1
  23. package/dist/url-c26cuIpu.js +7 -0
  24. package/dist/{useTweaks-QxMRmg7i.js → useTweaks-B7Muzo78.js} +10 -9
  25. package/dist/user/hooks.d.ts +6 -2
  26. package/dist/user/index.d.ts +1 -0
  27. package/dist/user/index.js +3 -3
  28. package/dist/utils/app-version-checker.d.ts +62 -0
  29. package/dist/utils/app-version-requirements.json.d.ts +13 -0
  30. package/dist/utils/index.d.ts +2 -0
  31. package/dist/utils/index.js +17 -11
  32. package/dist/utils/ui.d.ts +3 -1
  33. package/dist/utils/url.d.ts +7 -0
  34. package/package.json +1 -1
  35. package/dist/bridge-Ca3H2iN1.js +0 -197
  36. package/dist/container-message-DGrno17o.js +0 -31
  37. package/dist/errors-CDEBaBxB.js +0 -26
  38. package/dist/helper-BENVYOU-.js +0 -247
  39. package/dist/hooks-CE9cjXHP.js +0 -46
  40. package/dist/pwa-CilSlaik.js +0 -249
  41. package/dist/ui-y5N62DqC.js +0 -175
@@ -0,0 +1,250 @@
1
+ import { c as n, a as i } from "./errors-B3bDbQbD.js";
2
+ class d {
3
+ /**
4
+ * Get Core Web Vitals metrics
5
+ */
6
+ async getCoreWebVitals() {
7
+ const e = {};
8
+ try {
9
+ const t = performance.getEntriesByName("first-contentful-paint")[0];
10
+ t && (e.fcp = t.startTime);
11
+ const r = performance.getEntriesByType("largest-contentful-paint");
12
+ if (r.length > 0) {
13
+ const o = r[r.length - 1];
14
+ e.lcp = o.startTime;
15
+ }
16
+ const a = performance.getEntriesByType("first-input");
17
+ if (a.length > 0) {
18
+ const o = a[0];
19
+ e.fid = o.processingStart - o.startTime;
20
+ }
21
+ const s = performance.getEntriesByType("layout-shift");
22
+ if (s.length > 0) {
23
+ let o = 0;
24
+ for (const p of s) {
25
+ const l = p;
26
+ l.hadRecentInput || (o += l.value);
27
+ }
28
+ e.cls = o;
29
+ }
30
+ const c = this.calculateTTI();
31
+ c && (e.tti = c);
32
+ } catch (t) {
33
+ console.warn("Failed to get Core Web Vitals:", t);
34
+ }
35
+ return e;
36
+ }
37
+ /**
38
+ * Get navigation timing metrics
39
+ */
40
+ getNavigationTiming() {
41
+ const e = performance.getEntriesByType("navigation")[0];
42
+ return e ? {
43
+ // DNS lookup time
44
+ dns: e.domainLookupEnd - e.domainLookupStart,
45
+ // TCP connection time
46
+ tcp: e.connectEnd - e.connectStart,
47
+ // Request time
48
+ request: e.responseStart - e.requestStart,
49
+ // Response time
50
+ response: e.responseEnd - e.responseStart,
51
+ // DOM processing time
52
+ domProcessing: e.domComplete - e.domInteractive,
53
+ // Total page load time
54
+ total: e.loadEventEnd - e.fetchStart
55
+ } : null;
56
+ }
57
+ /**
58
+ * Get resource timing metrics
59
+ */
60
+ getResourceTiming() {
61
+ return performance.getEntriesByType("resource").map((t) => ({
62
+ name: t.name,
63
+ duration: t.duration,
64
+ size: t.transferSize,
65
+ type: this.getResourceType(t.name)
66
+ }));
67
+ }
68
+ /**
69
+ * Measure function execution time
70
+ */
71
+ measureFunction(e, t) {
72
+ const r = e();
73
+ return t && (performance.mark(`${t}-start`), performance.mark(`${t}-end`), performance.measure(t, `${t}-start`, `${t}-end`)), r;
74
+ }
75
+ /**
76
+ * Measure async function execution time
77
+ */
78
+ async measureAsyncFunction(e, t) {
79
+ const r = await e();
80
+ return t && (performance.mark(`${t}-start`), performance.mark(`${t}-end`), performance.measure(t, `${t}-start`, `${t}-end`)), r;
81
+ }
82
+ /**
83
+ * Get memory usage (if available)
84
+ */
85
+ getMemoryUsage() {
86
+ if ("memory" in performance) {
87
+ const e = performance.memory;
88
+ return {
89
+ used: e.usedJSHeapSize,
90
+ total: e.totalJSHeapSize,
91
+ limit: e.jsHeapSizeLimit
92
+ };
93
+ }
94
+ return null;
95
+ }
96
+ calculateTTI() {
97
+ const e = performance.getEntriesByType("navigation")[0];
98
+ return e ? e.domContentLoadedEventEnd - e.fetchStart : null;
99
+ }
100
+ getResourceType(e) {
101
+ return e.includes(".js") ? "script" : e.includes(".css") ? "stylesheet" : e.includes(".png") || e.includes(".jpg") || e.includes(".gif") ? "image" : e.includes(".woff") || e.includes(".ttf") ? "font" : "other";
102
+ }
103
+ }
104
+ const m = new d();
105
+ class u {
106
+ /**
107
+ * Get PWA information
108
+ */
109
+ getPWAInfo() {
110
+ return {
111
+ isInstalled: this.isInstalled(),
112
+ isInstallable: this.isInstallable(),
113
+ canInstall: this.canInstall(),
114
+ isStandalone: this.isStandalone()
115
+ };
116
+ }
117
+ /**
118
+ * Check if PWA is installed
119
+ */
120
+ isInstalled() {
121
+ return this.isStandalone() || this.isInApp();
122
+ }
123
+ /**
124
+ * Check if PWA is installable
125
+ */
126
+ isInstallable() {
127
+ return "serviceWorker" in navigator && "PushManager" in window;
128
+ }
129
+ /**
130
+ * Check if install prompt is available
131
+ */
132
+ canInstall() {
133
+ return this.isInstallable() && !this.isInstalled();
134
+ }
135
+ /**
136
+ * Check if running in standalone mode
137
+ */
138
+ isStandalone() {
139
+ return window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === !0;
140
+ }
141
+ /**
142
+ * Check if running in app (iOS)
143
+ */
144
+ isInApp() {
145
+ return window.navigator.standalone === !0;
146
+ }
147
+ /**
148
+ * Register service worker
149
+ */
150
+ async registerServiceWorker(e) {
151
+ if (!("serviceWorker" in navigator))
152
+ return console.warn("Service Worker not supported"), null;
153
+ try {
154
+ return await navigator.serviceWorker.register(e);
155
+ } catch (t) {
156
+ return console.error("Service Worker registration failed:", t), null;
157
+ }
158
+ }
159
+ /**
160
+ * Unregister service worker
161
+ */
162
+ async unregisterServiceWorker() {
163
+ if (!("serviceWorker" in navigator))
164
+ return !1;
165
+ try {
166
+ const e = await navigator.serviceWorker.getRegistrations();
167
+ for (const t of e)
168
+ await t.unregister();
169
+ return !0;
170
+ } catch (e) {
171
+ return console.error("Service Worker unregistration failed:", e), !1;
172
+ }
173
+ }
174
+ /**
175
+ * Request notification permission
176
+ */
177
+ async requestNotificationPermission() {
178
+ if (!("Notification" in window))
179
+ throw n("Notifications not supported", i.NOT_SUPPORTED);
180
+ return Notification.permission === "granted" ? "granted" : Notification.permission === "denied" ? "denied" : await Notification.requestPermission();
181
+ }
182
+ /**
183
+ * Send notification
184
+ */
185
+ async sendNotification(e, t) {
186
+ if (!("Notification" in window))
187
+ throw n("Notifications not supported", i.NOT_SUPPORTED);
188
+ if (Notification.permission !== "granted")
189
+ throw n("Notification permission not granted", i.PERMISSION_DENIED);
190
+ const r = new Notification(e, t);
191
+ setTimeout(() => {
192
+ r.close();
193
+ }, 5e3);
194
+ }
195
+ /**
196
+ * Share content using Web Share API
197
+ */
198
+ async share(e) {
199
+ if (!("share" in navigator))
200
+ throw n("Web Share API not supported", i.NOT_SUPPORTED);
201
+ try {
202
+ await navigator.share(e);
203
+ } catch (t) {
204
+ if (t instanceof Error && t.name !== "AbortError")
205
+ throw n(`Share failed: ${t.message}`, i.OPERATION_FAILED);
206
+ }
207
+ }
208
+ /**
209
+ * Copy text to clipboard
210
+ */
211
+ async copyToClipboard(e) {
212
+ if (!("clipboard" in navigator))
213
+ throw n("Clipboard API not supported", i.NOT_SUPPORTED);
214
+ try {
215
+ await navigator.clipboard.writeText(e);
216
+ } catch (t) {
217
+ throw n(`Copy to clipboard failed: ${t instanceof Error ? t.message : "Unknown error"}`, i.OPERATION_FAILED);
218
+ }
219
+ }
220
+ /**
221
+ * Read text from clipboard
222
+ */
223
+ async readFromClipboard() {
224
+ if (!("clipboard" in navigator))
225
+ throw n("Clipboard API not supported", i.NOT_SUPPORTED);
226
+ try {
227
+ return await navigator.clipboard.readText();
228
+ } catch (e) {
229
+ throw n(`Read from clipboard failed: ${e instanceof Error ? e.message : "Unknown error"}`, i.OPERATION_FAILED);
230
+ }
231
+ }
232
+ /**
233
+ * Get install prompt event
234
+ */
235
+ getInstallPromptEvent() {
236
+ return new Promise((e) => {
237
+ const t = (r) => {
238
+ r.preventDefault(), e(r), window.removeEventListener("beforeinstallprompt", t);
239
+ };
240
+ window.addEventListener("beforeinstallprompt", t);
241
+ });
242
+ }
243
+ }
244
+ const y = new u();
245
+ export {
246
+ d as P,
247
+ u as a,
248
+ y as b,
249
+ m as p
250
+ };
@@ -1,4 +1,4 @@
1
- import { a as e, b as s } from "../useTweaks-QxMRmg7i.js";
1
+ import { a as e, b as s } from "../useTweaks-B7Muzo78.js";
2
2
  export {
3
3
  e as aippyTweaks,
4
4
  s as aippyTweaksRuntime
@@ -0,0 +1,7 @@
1
+ function o(n, t) {
2
+ const e = n.endsWith("/") ? n : `${n}/`, i = t.startsWith("/") ? t.slice(1) : t;
3
+ return new URL(i, e).href;
4
+ }
5
+ export {
6
+ o as j
7
+ };
@@ -2,7 +2,8 @@ var b = Object.defineProperty;
2
2
  var g = (n, e, t) => e in n ? b(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
3
  var r = (n, e, t) => g(n, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { useReducer as v, useEffect as m } from "react";
5
- class T {
5
+ import { b as T, a as C } from "./errors-B3bDbQbD.js";
6
+ class I {
6
7
  constructor(e) {
7
8
  r(this, "cancelled", !1);
8
9
  this.cancelFn = e;
@@ -22,13 +23,13 @@ class k {
22
23
  this.listeners.forEach((t) => t(e));
23
24
  }
24
25
  subscribe(e) {
25
- return this.listeners.push(e), new T(() => {
26
+ return this.listeners.push(e), new I(() => {
26
27
  const t = this.listeners.indexOf(e);
27
28
  t > -1 && this.listeners.splice(t, 1);
28
29
  });
29
30
  }
30
31
  }
31
- class C {
32
+ class O {
32
33
  constructor(e, t) {
33
34
  r(this, "values", {});
34
35
  r(this, "subject", new k());
@@ -51,7 +52,7 @@ class C {
51
52
  getValue(e) {
52
53
  const t = this.values[e];
53
54
  if (t === void 0)
54
- throw new Error(`Tweak key not found in values: ${e}`);
55
+ throw T(`Tweak key not found in values: ${e}`, C.INVALID_CONFIG);
55
56
  return t;
56
57
  }
57
58
  // React Hook integration
@@ -67,7 +68,7 @@ class C {
67
68
  }, [e]), t;
68
69
  }
69
70
  }
70
- class I {
71
+ class R {
71
72
  constructor() {
72
73
  r(this, "tweaksInstance", null);
73
74
  r(this, "tweaksDidWarn", !1);
@@ -80,7 +81,7 @@ class I {
80
81
  if (this.tweaksInstance)
81
82
  return this.tweaksDidWarn || (this.tweaksDidWarn = !0, console.warn("⚠️ [Aippy Tweaks] tweaks() is expected to only be called once, returning previous value")), this.tweaksInstance;
82
83
  this.originalConfig = { ...e };
83
- const t = new k(), i = new C(t, e), a = {};
84
+ const t = new k(), i = new O(t, e), a = {};
84
85
  for (const s of Object.keys(e))
85
86
  a[s] = {
86
87
  useState: () => i.useState(s)
@@ -172,11 +173,11 @@ class I {
172
173
  }
173
174
  }
174
175
  }
175
- const w = new I(), y = {
176
+ const w = new R(), y = {
176
177
  tweaks: (n) => w.tweaks(n)
177
- }, N = y.tweaks;
178
+ }, S = y.tweaks;
178
179
  typeof window < "u" && (window.aippyTweaksRuntime = y, window.processNativeData = w.processNativeData.bind(w));
179
180
  export {
180
- N as a,
181
+ S as a,
181
182
  y as b
182
183
  };
@@ -1,12 +1,16 @@
1
1
  /**
2
2
  * User SDK Hooks
3
3
  */
4
- /** Hook to get user info (avatar, nickName, username, uid) */
5
- export declare function useUserInfo(): {
4
+ export interface UserInfo {
6
5
  avatar: string;
7
6
  nickName: string;
8
7
  username: string;
9
8
  uid: string;
9
+ }
10
+ /** Hook to get user info (avatar, nickName, username, uid) with loading state */
11
+ export declare function useUserInfo(): UserInfo & {
12
+ isLoading: boolean;
13
+ refetch: () => Promise<void>;
10
14
  };
11
15
  /** Clear cached user info */
12
16
  export declare function clearUserInfoCache(): void;
@@ -2,5 +2,6 @@
2
2
  * User SDK
3
3
  */
4
4
  export { useUserInfo, clearUserInfoCache } from './hooks';
5
+ export type { UserInfo } from './hooks';
5
6
  export { getAuthTokenAsync, isInIframe } from './bridge';
6
7
  export type { IOSUserCredentials, IOSUserInfo } from './bridge';
@@ -1,6 +1,6 @@
1
- import { c as o, u as s } from "../hooks-CE9cjXHP.js";
2
- import { getAuthTokenAsync as f } from "../bridge-Ca3H2iN1.js";
3
- import { i as t } from "../ui-y5N62DqC.js";
1
+ import { c as o, u as s } from "../hooks-C7VP176R.js";
2
+ import { getAuthTokenAsync as f } from "../bridge-BQQ3PfSO.js";
3
+ import { i as t } from "../app-version-checker-B1UXEcy9.js";
4
4
  export {
5
5
  o as clearUserInfoCache,
6
6
  f as getAuthTokenAsync,
@@ -0,0 +1,62 @@
1
+ import { AppVersionConfig, AppEnvironmentCheckResult } from './platform';
2
+ import { default as versionRequirements } from './app-version-requirements.json';
3
+ /**
4
+ * Feature support check result
5
+ */
6
+ export interface FeatureSupportResult {
7
+ /** Whether the feature is supported in current environment */
8
+ supported: boolean;
9
+ /** Environment check result from platform detector */
10
+ envCheck: AppEnvironmentCheckResult;
11
+ /** Current app version (if in app) */
12
+ currentVersion?: string;
13
+ /** Minimum required version for this feature */
14
+ requiredVersion?: string;
15
+ /** Error message if not supported */
16
+ message?: string;
17
+ }
18
+ /**
19
+ * Available feature names for version checking
20
+ */
21
+ export type FeatureName = keyof typeof versionRequirements;
22
+ /**
23
+ * Get version requirements for a feature
24
+ */
25
+ export declare function getFeatureVersionRequirements(featureName: FeatureName): AppVersionConfig;
26
+ /**
27
+ * Check if app version supports a specific feature
28
+ *
29
+ * @param featureName - The feature to check (e.g., 'userCredentials', 'userInfo')
30
+ * @returns FeatureSupportResult with support status and details
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const result = checkFeatureSupport('userCredentials');
35
+ * if (!result.supported) {
36
+ * console.log('Feature not supported:', result.message);
37
+ * }
38
+ * ```
39
+ */
40
+ export declare function checkFeatureSupport(featureName: FeatureName): FeatureSupportResult;
41
+ /**
42
+ * Check feature support and handle old version automatically
43
+ *
44
+ * This is a convenience function that:
45
+ * 1. Checks if the feature is supported
46
+ * 2. If not supported due to old app version, shows an alert and throws an error
47
+ *
48
+ * @param featureName - The feature to check
49
+ * @returns FeatureSupportResult (only returns if supported or web/iframe environment)
50
+ * @throws Error if app version is too old
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const result = requireFeatureSupport('userCredentials');
55
+ * // Code here only runs if feature is supported
56
+ * ```
57
+ */
58
+ export declare function requireFeatureSupport(featureName: FeatureName): FeatureSupportResult;
59
+ /**
60
+ * Get all available feature names
61
+ */
62
+ export declare function getAvailableFeatures(): FeatureName[];
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ "userCredentials": {
3
+ "iOS": "1.6.7",
4
+ "Android": "1.1.8"
5
+ },
6
+ "userInfo": {
7
+ "iOS": "1.6.7",
8
+ "Android": "1.1.8"
9
+ }
10
+ }
11
+ ;
12
+
13
+ export default _default;
@@ -3,3 +3,5 @@ export * from './performance';
3
3
  export * from './pwa';
4
4
  export * from './types';
5
5
  export * from './ui';
6
+ export * from './url';
7
+ export * from './app-version-checker';
@@ -1,13 +1,19 @@
1
- import { P as o, c as s, i as e, p as t, s as m } from "../ui-y5N62DqC.js";
2
- import { a as f, P as i, p as n, b as c } from "../pwa-CilSlaik.js";
1
+ import { P as a, a as s, c as o, b as t, g as p, i, p as m, r as n, s as f } from "../app-version-checker-B1UXEcy9.js";
2
+ import { a as c, P as l, p as P, b as F } from "../pwa-C5nXU0DN.js";
3
+ import { j as g } from "../url-c26cuIpu.js";
3
4
  export {
4
- f as PWAUtils,
5
- i as PerformanceMonitor,
6
- o as PlatformDetector,
7
- s as compareVersions,
8
- e as isInIframe,
9
- n as performanceMonitor,
10
- t as platform,
11
- c as pwa,
12
- m as showAlert
5
+ c as PWAUtils,
6
+ l as PerformanceMonitor,
7
+ a as PlatformDetector,
8
+ s as checkFeatureSupport,
9
+ o as compareVersions,
10
+ t as getAvailableFeatures,
11
+ p as getFeatureVersionRequirements,
12
+ i as isInIframe,
13
+ g as joinUrl,
14
+ P as performanceMonitor,
15
+ m as platform,
16
+ F as pwa,
17
+ n as requireFeatureSupport,
18
+ f as showAlert
13
19
  };
@@ -2,10 +2,12 @@
2
2
  * UI Utilities
3
3
  * Common UI components for SDK modules
4
4
  */
5
+ export type AlertType = 'update' | 'signin';
5
6
  /**
6
7
  * 自定义弹窗
7
8
  * 用于在各 SDK 模块中显示提示信息
8
9
  *
9
10
  * @param message - 要显示的消息
11
+ * @param type - 弹窗类型:'update' 发送消息给原生 App,'signin' 发送消息给父窗口
10
12
  */
11
- export declare function showAlert(message: string): void;
13
+ export declare function showAlert(message: string, type?: AlertType): Promise<void>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * URL utilities for Aippy Runtime SDK.
3
+ */
4
+ /**
5
+ * Joins a base URL with a path segment.
6
+ */
7
+ export declare function joinUrl(baseUrl: string, path: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/runtime",
3
- "version": "0.2.7-dev.5",
3
+ "version": "0.2.7-dev.7",
4
4
  "description": "Aippy Runtime SDK - Runtime SDK for Aippy projects",
5
5
  "private": false,
6
6
  "type": "module",