@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
@@ -6,6 +6,6 @@
6
6
  */
7
7
  export type { AIConfig, AIConfigValue, AIConfigItem, NumberAIConfigItem, BooleanAIConfigItem, TextAIConfigItem, EnumAIConfigItem, AIConfigError, } from './types';
8
8
  export type { AIConfigValues } from './helper';
9
- export { AIConfigValidationError, validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, } from './parser';
9
+ export { validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, } from './parser';
10
10
  export { sendAIConfigToContainer } from './bridge';
11
11
  export { createAIConfig } from './helper';
@@ -1,16 +1,9 @@
1
- import { AIConfig, AIConfigError } from './types';
2
- /**
3
- * Custom error class for AI configuration validation failures
4
- */
5
- export declare class AIConfigValidationError extends Error {
6
- readonly errors: AIConfigError[];
7
- constructor(message: string, errors: AIConfigError[]);
8
- }
1
+ import { AIConfig } from './types';
9
2
  /**
10
3
  * Validates an AI configuration object
11
4
  *
12
5
  * @param config - The configuration object to validate
13
- * @throws {AIConfigValidationError} If validation fails
6
+ * @throws {AippyRuntimeError} If validation fails
14
7
  */
15
8
  export declare function validateAIConfig(config: unknown): asserts config is AIConfig;
16
9
  /**
@@ -18,7 +11,7 @@ export declare function validateAIConfig(config: unknown): asserts config is AIC
18
11
  *
19
12
  * @param json - JSON string to parse
20
13
  * @returns Validated AIConfig object
21
- * @throws {AIConfigValidationError} If JSON is invalid or validation fails
14
+ * @throws {AippyRuntimeError} If JSON is invalid or validation fails
22
15
  *
23
16
  * @example
24
17
  * ```ts
@@ -34,7 +27,7 @@ export declare function parseAIConfig(json: string): AIConfig;
34
27
  *
35
28
  * @param config - Configuration object (usually from JSON import)
36
29
  * @returns Validated AIConfig object
37
- * @throws {AIConfigValidationError} If validation fails
30
+ * @throws {AippyRuntimeError} If validation fails
38
31
  *
39
32
  * @example
40
33
  * ```ts
@@ -49,7 +42,7 @@ export declare function loadAIConfig(config: unknown): AIConfig;
49
42
  * @param config - The AIConfig object
50
43
  * @param key - Configuration key to retrieve
51
44
  * @returns The value of the configuration item
52
- * @throws {Error} If the key is not found
45
+ * @throws {AippyRuntimeError} If the key is not found
53
46
  *
54
47
  * @example
55
48
  * ```ts
@@ -2,5 +2,6 @@ import { AISDKError } from 'ai';
2
2
  /**
3
3
  * Normalizes a backend error response into an AISDKError.
4
4
  * Extracts and sends appMessage to container if present in the error response.
5
+ * Uses [Aippy Runtime] prefix - these errors are NOT reported to LLM.
5
6
  */
6
7
  export declare function normalizeError(response: Response, body?: unknown): AISDKError;
@@ -41,4 +41,4 @@ export type { AippyOpenAIConfig } from './openai';
41
41
  export { aippyChatConfig, type AippyUseChatOptions, type AippyUIConfig, type AippyChatConfig, UI_CHAT_ENDPOINT, } from './ui';
42
42
  export { DEFAULT_BASE_URL, DEFAULT_UI_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_CHAT_SYSTEM, } from './shared';
43
43
  export { normalizeError } from './errors';
44
- export { type AIConfig, type AIConfigValue, type AIConfigItem, type NumberAIConfigItem, type BooleanAIConfigItem, type TextAIConfigItem, type EnumAIConfigItem, type AIConfigError, type AIConfigValues, AIConfigValidationError, validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, sendAIConfigToContainer, createAIConfig, } from './config';
44
+ export { type AIConfig, type AIConfigValue, type AIConfigItem, type NumberAIConfigItem, type BooleanAIConfigItem, type TextAIConfigItem, type EnumAIConfigItem, type AIConfigError, type AIConfigValues, validateAIConfig, parseAIConfig, loadAIConfig, getAIConfigValue, sendAIConfigToContainer, createAIConfig, } from './config';
package/dist/ai/index.js CHANGED
@@ -1,20 +1,19 @@
1
- import { A, D as r, d as n, e as C, c as e, U as E, a as I, b as _, f, g, l as T, n as p, p as t, s as U, v as D } from "../helper-BENVYOU-.js";
1
+ import { D as i, d as r, e, c as n, U as C, a as _, b as E, f as I, g as T, l as f, n as g, p, s as U, v as t } from "../helper-BjRhidue.js";
2
2
  import "react";
3
- import "../bridge-Ca3H2iN1.js";
3
+ import "../bridge-BQQ3PfSO.js";
4
4
  export {
5
- A as AIConfigValidationError,
6
- r as DEFAULT_BASE_URL,
7
- n as DEFAULT_CHAT_MODEL,
8
- C as DEFAULT_CHAT_SYSTEM,
9
- e as DEFAULT_UI_BASE_URL,
10
- E as UI_CHAT_ENDPOINT,
11
- I as aippyAIProvider,
12
- _ as aippyChatConfig,
13
- f as createAIConfig,
14
- g as getAIConfigValue,
15
- T as loadAIConfig,
16
- p as normalizeError,
17
- t as parseAIConfig,
5
+ i as DEFAULT_BASE_URL,
6
+ r as DEFAULT_CHAT_MODEL,
7
+ e as DEFAULT_CHAT_SYSTEM,
8
+ n as DEFAULT_UI_BASE_URL,
9
+ C as UI_CHAT_ENDPOINT,
10
+ _ as aippyAIProvider,
11
+ E as aippyChatConfig,
12
+ I as createAIConfig,
13
+ T as getAIConfigValue,
14
+ f as loadAIConfig,
15
+ g as normalizeError,
16
+ p as parseAIConfig,
18
17
  U as sendAIConfigToContainer,
19
- D as validateAIConfig
18
+ t as validateAIConfig
20
19
  };
@@ -2,10 +2,6 @@
2
2
  * Shared fetch utilities for Aippy AI SDK.
3
3
  * Used by both OpenAI-compatible (Core) and Data Stream Protocol (UI) paths.
4
4
  */
5
- /**
6
- * Joins a base URL with a path segment.
7
- */
8
- export declare function joinUrl(baseUrl: string, path: string): string;
9
5
  /**
10
6
  * Creates a fetch wrapper that injects Authorization header and handles error responses.
11
7
  * Error responses are intercepted and normalized errors are thrown immediately.
@@ -3,4 +3,4 @@
3
3
  * Re-exports config and fetch utilities used by both protocol paths.
4
4
  */
5
5
  export { DEFAULT_BASE_URL, DEFAULT_UI_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_CHAT_SYSTEM, resolveOpenAIConfig, resolveUIConfig, type AippyOpenAIConfig, type AippyUIConfig, type AippyChatConfig, } from './config';
6
- export { joinUrl, createAuthFetch } from './fetch';
6
+ export { createAuthFetch } from './fetch';
@@ -0,0 +1,240 @@
1
+ var l = Object.defineProperty;
2
+ var m = (r, e, n) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n;
3
+ var c = (r, e, n) => m(r, typeof e != "symbol" ? e + "" : e, n);
4
+ import { UAParser as f } from "ua-parser-js";
5
+ import { hasNativeBridge as w } from "./native-bridge-BnvipFJc.js";
6
+ import { c as h, a as g } from "./errors-B3bDbQbD.js";
7
+ function b() {
8
+ try {
9
+ return typeof window < "u" && window.parent !== window;
10
+ } catch {
11
+ return !0;
12
+ }
13
+ }
14
+ function v(r, e) {
15
+ const n = r.split(".").map(Number), t = e.split(".").map(Number), i = Math.max(n.length, t.length);
16
+ for (let o = 0; o < i; o++) {
17
+ const p = n[o] || 0, s = t[o] || 0;
18
+ if (p < s) return -1;
19
+ if (p > s) return 1;
20
+ }
21
+ return 0;
22
+ }
23
+ class x {
24
+ constructor() {
25
+ c(this, "parser");
26
+ this.parser = new f();
27
+ }
28
+ /**
29
+ * Get platform information
30
+ */
31
+ getPlatformInfo() {
32
+ const e = this.parser.getResult(), n = this.normalizePlatformName(e.os.name), t = this.normalizeBrowserName(e.browser.name), i = this.isMobileDevice(), o = !i;
33
+ return {
34
+ name: n,
35
+ version: e.os.version,
36
+ browser: t,
37
+ browserVersion: e.browser.version,
38
+ isMobile: i,
39
+ isDesktop: o
40
+ };
41
+ }
42
+ /**
43
+ * Get raw UA parser result
44
+ */
45
+ getRawParserResult() {
46
+ return this.parser.getResult();
47
+ }
48
+ /**
49
+ * Get platform capabilities
50
+ */
51
+ getCapabilities() {
52
+ return {
53
+ serviceWorker: "serviceWorker" in navigator,
54
+ pushNotifications: "PushManager" in window,
55
+ webShare: "share" in navigator,
56
+ clipboard: "clipboard" in navigator,
57
+ webRTC: !!(window.RTCPeerConnection || window.webkitRTCPeerConnection),
58
+ webGL: !!this.getWebGLContext(),
59
+ webAssembly: "WebAssembly" in window
60
+ };
61
+ }
62
+ /**
63
+ * Check if device is mobile
64
+ */
65
+ isMobileDevice() {
66
+ const e = navigator.userAgent;
67
+ return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(e) || this.isTouchDevice();
68
+ }
69
+ /**
70
+ * Check if device supports touch
71
+ */
72
+ isTouchDevice() {
73
+ return "ontouchstart" in window || navigator.maxTouchPoints > 0;
74
+ }
75
+ /**
76
+ * Check if running in standalone mode (PWA)
77
+ */
78
+ isStandalone() {
79
+ return window.matchMedia("(display-mode: standalone)").matches || window.navigator.standalone === !0;
80
+ }
81
+ /**
82
+ * Check if running in iOS Safari
83
+ */
84
+ isIOSSafari() {
85
+ const e = this.getPlatformInfo();
86
+ return e.name === "ios" && e.browser === "safari";
87
+ }
88
+ /**
89
+ * Check if running in Android Chrome
90
+ */
91
+ isAndroidChrome() {
92
+ const e = this.getPlatformInfo();
93
+ return e.name === "android" && e.browser === "chrome";
94
+ }
95
+ /**
96
+ * Check if running in Android WebView (old app version)
97
+ * Detects by checking if browser name contains "webview"
98
+ */
99
+ isAndroidWebView() {
100
+ return (this.parser.getResult().browser.name || "").toLowerCase().includes("webview");
101
+ }
102
+ /**
103
+ * Check app environment and validate version
104
+ */
105
+ checkAppEnvironment(e) {
106
+ const n = this.parseAippyInfo();
107
+ if (n) {
108
+ const t = e[n.platform], i = v(n.version, t) >= 0;
109
+ return {
110
+ type: "new_app",
111
+ isValid: i,
112
+ aippyInfo: n,
113
+ message: i ? void 0 : `App version ${n.version} < ${t}`
114
+ };
115
+ }
116
+ return w() ? {
117
+ type: "old_ios_app",
118
+ isValid: !1,
119
+ message: "Native bridge exists but no Aippy info (old iOS version)"
120
+ } : this.isAndroidWebView() ? {
121
+ type: "old_android_app",
122
+ isValid: !1,
123
+ message: "Android WebView detected but no Aippy info (old Android version)"
124
+ } : b() ? { type: "iframe", isValid: !0 } : { type: "web", isValid: !0 };
125
+ }
126
+ /**
127
+ * Parse Aippy App info from User-Agent
128
+ */
129
+ parseAippyInfo() {
130
+ const e = navigator.userAgent, n = /Aippy\/([^/]+)\/[^/]+\/(iOS|Android)/i, t = e.match(n);
131
+ if (t) {
132
+ const i = t[1];
133
+ return {
134
+ platform: t[2],
135
+ version: i
136
+ };
137
+ }
138
+ return null;
139
+ }
140
+ normalizePlatformName(e) {
141
+ if (!e) return "unknown";
142
+ const n = e.toLowerCase();
143
+ return n.includes("ios") ? "ios" : n.includes("android") ? "android" : n.includes("windows") ? "windows" : n.includes("mac") ? "macos" : n.includes("linux") ? "linux" : "unknown";
144
+ }
145
+ normalizeBrowserName(e) {
146
+ if (!e) return "unknown";
147
+ const n = e.toLowerCase();
148
+ return n.includes("chrome") ? "chrome" : n.includes("firefox") ? "firefox" : n.includes("safari") ? "safari" : n.includes("edge") ? "edge" : "unknown";
149
+ }
150
+ getWebGLContext() {
151
+ try {
152
+ const e = document.createElement("canvas");
153
+ return e.getContext("webgl") || e.getContext("experimental-webgl");
154
+ } catch {
155
+ return null;
156
+ }
157
+ }
158
+ }
159
+ const y = new x(), d = "https://cdn.aippy.ai/asset/fd292077086044ee9565bd36ac3a8b78.svg";
160
+ async function A(r, e = "update") {
161
+ const n = document.createElement("div");
162
+ n.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:12px;display:flex;align-items:flex-end;justify-content:center;z-index:999999;pointer-events:none";
163
+ const t = document.createElement("div");
164
+ t.style.cssText = "background:#323232;border-radius:32px;padding:12px 12px 12px 12px;width:370px;max-width:90%;display:flex;align-items:center;gap:8px;pointer-events:auto";
165
+ let i = !1;
166
+ try {
167
+ i = (await fetch(d, { method: "HEAD" })).ok;
168
+ } catch {
169
+ i = !1;
170
+ }
171
+ if (i) {
172
+ const a = document.createElement("img");
173
+ a.src = d, a.style.cssText = "width:36px;height:36px;flex-shrink:0", t.appendChild(a);
174
+ }
175
+ const o = document.createElement("span");
176
+ o.style.cssText = "font-size:14px;font-weight:600;color:#fff;line-height:1.4;white-space:pre-line", o.textContent = r;
177
+ const p = e === "signin" ? "Sign in" : "Update", s = document.createElement("button");
178
+ s.style.cssText = "background:#fff;color:#000;font-size:14px;font-weight:600;border:none;border-radius:32px;height:36px;min-width:80px;padding:0 16px;cursor:pointer;flex-shrink:0;white-space:nowrap", s.textContent = p, s.onclick = () => {
179
+ if (e === "signin")
180
+ try {
181
+ window.parent.postMessage({ type: "navigator.appstore" }, "*");
182
+ } catch {
183
+ }
184
+ else
185
+ window.webkit?.messageHandlers?.aippyListener?.postMessage({ command: "navigator.appstore" });
186
+ }, t.appendChild(o), t.appendChild(s), n.appendChild(t), document.body.appendChild(n);
187
+ }
188
+ const C = { iOS: "1.6.7", Android: "1.1.8" }, k = { iOS: "1.6.7", Android: "1.1.8" }, u = {
189
+ userCredentials: C,
190
+ userInfo: k
191
+ };
192
+ function P(r) {
193
+ const e = u[r];
194
+ return e || (console.warn(`[AppVersionChecker] Unknown feature: ${r}`), { iOS: "999.0.0", Android: "999.0.0" });
195
+ }
196
+ function _(r) {
197
+ const e = P(r), n = y.checkAppEnvironment(e), t = n.aippyInfo?.version, i = n.aippyInfo ? e[n.aippyInfo.platform] : void 0;
198
+ switch (n.type) {
199
+ case "new_app":
200
+ return {
201
+ supported: n.isValid,
202
+ envCheck: n,
203
+ currentVersion: t,
204
+ requiredVersion: i,
205
+ message: n.isValid ? void 0 : `App version ${t} does not support ${r}. Minimum required: ${i}`
206
+ };
207
+ case "old_ios_app":
208
+ case "old_android_app":
209
+ return {
210
+ supported: !1,
211
+ envCheck: n,
212
+ message: `Old app version detected. Please upgrade to use ${r}.`
213
+ };
214
+ default:
215
+ return {
216
+ supported: !0,
217
+ envCheck: n
218
+ };
219
+ }
220
+ }
221
+ function E(r) {
222
+ const e = _(r);
223
+ if (!e.supported && (e.envCheck.type === "new_app" || e.envCheck.type === "old_ios_app" || e.envCheck.type === "old_android_app"))
224
+ throw console.warn(`[AppVersionChecker] ${e.message}`), A("This project needs a newer version.Update to view it.", "update"), h(`App version too old: ${e.message}`, g.NOT_SUPPORTED);
225
+ return e;
226
+ }
227
+ function I() {
228
+ return Object.keys(u);
229
+ }
230
+ export {
231
+ x as P,
232
+ _ as a,
233
+ I as b,
234
+ v as c,
235
+ P as g,
236
+ b as i,
237
+ y as p,
238
+ E as r,
239
+ A as s
240
+ };
@@ -0,0 +1,237 @@
1
+ import { a as U } from "./runtime-CmoG3v2m.js";
2
+ import { r as v, s as L, i as p } from "./app-version-checker-B1UXEcy9.js";
3
+ import { c as B, a as I } from "./errors-B3bDbQbD.js";
4
+ const f = {
5
+ apiBaseUrl: "https://api.aippy.dev/api",
6
+ authToken: "",
7
+ currentUserId: null
8
+ };
9
+ function E(n) {
10
+ Object.assign(f, n);
11
+ }
12
+ function R(n) {
13
+ f.authToken = n;
14
+ }
15
+ function q(n) {
16
+ f.currentUserId = n;
17
+ }
18
+ const k = 3e3, T = 50, g = 500, c = { uid: "", token: "" };
19
+ let l = null, u = !1, a = null, t = null;
20
+ function w(n) {
21
+ if (!n || typeof n != "object") return null;
22
+ let e = n;
23
+ if (e.credentials && typeof e.credentials == "object" && (e = e.credentials), e.user && typeof e.user == "object" && e.token) {
24
+ const d = e.user;
25
+ e = { uid: d.uid || d.userId || d.id, token: e.token, apiBaseUrl: e.apiBaseUrl };
26
+ }
27
+ const r = e.uid || e.userId || e.id || "", o = e.token || e.authToken || "", s = e.apiBaseUrl;
28
+ if (!r || !o) return null;
29
+ const i = { uid: String(r), token: o, apiBaseUrl: s };
30
+ return q(i.uid), R(o), s && E({ apiBaseUrl: s }), i;
31
+ }
32
+ function m(n) {
33
+ if (console.log("🔄 [Bridge] processUserInfoData called with:", n), !n || typeof n != "object")
34
+ return console.warn("⚠️ [Bridge] Invalid data (null or not object):", n), null;
35
+ let e = n;
36
+ console.log("🔄 [Bridge] Initial obj keys:", Object.keys(e)), e.userInfo && typeof e.userInfo == "object" && (console.log("🔄 [Bridge] Unwrapping nested userInfo"), e = e.userInfo), e.user && typeof e.user == "object" && (console.log("🔄 [Bridge] Unwrapping nested user"), e = e.user), console.log("🔄 [Bridge] After unwrapping, obj:", e);
37
+ const r = e.uid || e.userId || e.id || "";
38
+ if (!r)
39
+ return console.warn("⚠️ [Bridge] No uid found in data"), null;
40
+ const o = { uid: String(r), ...e };
41
+ return console.log("✅ [Bridge] Created userInfo:", o), l = o, u = !0, console.log("✅ [Bridge] Cached userInfo, userInfoReceived = true"), o;
42
+ }
43
+ function A(n = g) {
44
+ return console.log("📱 [Bridge] requestCredentialsFromiOS called, timeout:", n), a ? (console.log("⏳ [Bridge] Pending credentials request exists, waiting..."), new Promise((e) => {
45
+ const r = a.resolve;
46
+ a.resolve = (o) => {
47
+ r(o), e(o);
48
+ };
49
+ })) : new Promise((e) => {
50
+ (async () => {
51
+ let r = window.webkit?.messageHandlers?.aippyListener;
52
+ if (console.log("📱 [Bridge] Checking aippyListener for credentials:", {
53
+ hasWebkit: !!window.webkit,
54
+ hasMessageHandlers: !!window.webkit?.messageHandlers,
55
+ hasAippyListener: !!r
56
+ }), r || (console.log("⏳ [Bridge] aippyListener not found, waiting for injection..."), r = await b(1500)), !r) {
57
+ console.warn("⚠️ [Bridge] No aippyListener found after waiting, returning empty credentials"), e(c);
58
+ return;
59
+ }
60
+ const o = setTimeout(() => {
61
+ console.warn("⏰ [Bridge] Credentials request TIMEOUT after", n, "ms"), a = null, e(c);
62
+ }, n);
63
+ a = {
64
+ resolve: (s) => {
65
+ console.log("✅ [Bridge] pendingCredentialsRequest.resolve called with:", s), clearTimeout(o), a = null, e(s);
66
+ }
67
+ }, console.log("📱 [Bridge] pendingCredentialsRequest set"), U.receiveChannel.once("user.credentials", (s) => {
68
+ console.log("📩 [Bridge] Received user.credentials via receiveChannel:", s), clearTimeout(o);
69
+ const i = w(s) || c;
70
+ a && a.resolve(i);
71
+ });
72
+ try {
73
+ const s = {
74
+ command: "user.getCredentials",
75
+ parameters: JSON.stringify({ timestamp: Date.now(), endpoint: "user.credentials" })
76
+ };
77
+ console.log("📤 [Bridge] Sending credentials request:", s), r.postMessage(s), console.log("📤 [Bridge] Credentials postMessage sent successfully");
78
+ } catch (s) {
79
+ console.error("❌ [Bridge] Failed to send credentials postMessage:", s), clearTimeout(o), a = null, e(c);
80
+ }
81
+ })();
82
+ });
83
+ }
84
+ function S(n = g) {
85
+ return new Promise((e) => {
86
+ if (!p()) {
87
+ e(c);
88
+ return;
89
+ }
90
+ const r = setTimeout(() => {
91
+ window.removeEventListener("message", o), e(c);
92
+ }, n), o = (s) => {
93
+ s.data?.type === "user-credentials-response" && (clearTimeout(r), window.removeEventListener("message", o), e(w(s.data) || c));
94
+ };
95
+ window.addEventListener("message", o);
96
+ try {
97
+ window.parent.postMessage({ type: "user-credentials-request", timestamp: Date.now() }, "*");
98
+ } catch {
99
+ clearTimeout(r), window.removeEventListener("message", o), e(c);
100
+ }
101
+ });
102
+ }
103
+ const D = () => /Aippy\/[\d.]+\/\d+\/Android/i.test(navigator.userAgent);
104
+ async function b(n = 1500) {
105
+ if (!D())
106
+ return console.log("📱 [Bridge] Not Android, skipping waitForAippyListener"), window.webkit?.messageHandlers?.aippyListener || null;
107
+ const e = Date.now(), r = 50;
108
+ for (console.log("🤖 [Bridge] Android: Waiting for aippyListener (max", n, "ms)..."); Date.now() - e < n; ) {
109
+ const o = window.webkit?.messageHandlers?.aippyListener;
110
+ if (o)
111
+ return console.log("✅ [Bridge] aippyListener became available after", Date.now() - e, "ms"), o;
112
+ await new Promise((s) => setTimeout(s, r));
113
+ }
114
+ return console.warn("⏰ [Bridge] aippyListener not available after", n, "ms"), null;
115
+ }
116
+ function O(n = !1, e = g) {
117
+ return console.log("📱 [Bridge] requestUserInfoFromiOS called:", { forceRefresh: n, timeoutMs: e }), console.log("📱 [Bridge] Cache state:", { userInfoReceived: u, cachedUserInfo: l ? "(cached)" : null }), u && l && !n ? (console.log("✅ [Bridge] Returning cached userInfo from requestUserInfoFromiOS"), Promise.resolve(l)) : t ? (console.log("⏳ [Bridge] Pending userInfo request exists, waiting..."), new Promise((r) => {
118
+ const o = t.resolve;
119
+ t.resolve = (s) => {
120
+ console.log("⏳ [Bridge] Pending request resolved:", s), o(s), r(s);
121
+ };
122
+ })) : new Promise((r) => {
123
+ (async () => {
124
+ let o = window.webkit?.messageHandlers?.aippyListener;
125
+ if (console.log("📱 [Bridge] Checking aippyListener:", {
126
+ hasWebkit: !!window.webkit,
127
+ hasMessageHandlers: !!window.webkit?.messageHandlers,
128
+ hasAippyListener: !!o
129
+ }), o || (console.log("⏳ [Bridge] aippyListener not found, waiting for injection..."), o = await b(1500)), !o) {
130
+ console.warn("⚠️ [Bridge] No aippyListener found after waiting, returning null"), r(null);
131
+ return;
132
+ }
133
+ console.log("📱 [Bridge] Setting up timeout:", e, "ms");
134
+ const s = setTimeout(() => {
135
+ console.warn("⏰ [Bridge] UserInfo request TIMEOUT after", e, "ms"), t = null, r(null);
136
+ }, e);
137
+ t = { resolve: (i) => {
138
+ console.log("✅ [Bridge] pendingUserInfoRequest.resolve called with:", i), clearTimeout(s), t = null, r(i);
139
+ } }, console.log("📱 [Bridge] pendingUserInfoRequest set"), U.receiveChannel.once("user.info", (i) => {
140
+ console.log("📩 [Bridge] Received user.info via receiveChannel:", i), clearTimeout(s);
141
+ const d = m(i);
142
+ console.log("📩 [Bridge] Processed userInfo:", d), t ? t.resolve(d) : console.warn("⚠️ [Bridge] No pendingUserInfoRequest when receiveChannel fired");
143
+ }), console.log("📱 [Bridge] receiveChannel.once registered for user.info");
144
+ try {
145
+ const i = {
146
+ command: "user.getUserInfo",
147
+ parameters: JSON.stringify({ timestamp: Date.now(), endpoint: "user.info" })
148
+ };
149
+ console.log("📤 [Bridge] Sending to aippyListener:", i), o.postMessage(i), console.log("📤 [Bridge] postMessage sent successfully");
150
+ } catch (i) {
151
+ console.error("❌ [Bridge] Failed to send postMessage:", i), clearTimeout(s), t = null, r(null);
152
+ }
153
+ })();
154
+ });
155
+ }
156
+ function C(n = g) {
157
+ return new Promise((e) => {
158
+ if (!p()) {
159
+ e(null);
160
+ return;
161
+ }
162
+ const r = setTimeout(() => {
163
+ window.removeEventListener("message", o), e(null);
164
+ }, n), o = (s) => {
165
+ s.data?.type === "user-info-response" && (clearTimeout(r), window.removeEventListener("message", o), e(m(s.data)));
166
+ };
167
+ window.addEventListener("message", o);
168
+ try {
169
+ window.parent.postMessage({ type: "user-info-request", timestamp: Date.now() }, "*");
170
+ } catch {
171
+ clearTimeout(r), window.removeEventListener("message", o), e(null);
172
+ }
173
+ });
174
+ }
175
+ async function P() {
176
+ const { envCheck: n } = v("userCredentials");
177
+ switch (n.type) {
178
+ case "new_app": {
179
+ const e = await A(k);
180
+ if (!e?.token) throw B("Token unavailable in app", I.PERMISSION_DENIED);
181
+ return e.token;
182
+ }
183
+ case "iframe": {
184
+ const e = await S(T);
185
+ if (e?.token) return e.token;
186
+ throw L("Sign in to continue.Open this project in the app.", "signin"), B("Token unavailable: User needs to login", I.PERMISSION_DENIED);
187
+ }
188
+ default:
189
+ return "";
190
+ }
191
+ }
192
+ async function _(n = !1) {
193
+ if (console.log("🔍 [Bridge] getUserInfoAsync called, forceRefresh:", n), console.log("🔍 [Bridge] Current cache state:", { userInfoReceived: u, cachedUserInfo: l }), u && l && !n)
194
+ return console.log("✅ [Bridge] Returning cached userInfo"), l;
195
+ const { envCheck: e } = v("userInfo");
196
+ switch (console.log("🔍 [Bridge] Environment check result:", e), e.type) {
197
+ case "new_app":
198
+ return console.log("📱 [Bridge] Detected new_app environment"), await O(n, k);
199
+ case "iframe":
200
+ return console.log("🖼️ [Bridge] Detected iframe environment"), await C(T);
201
+ default:
202
+ return console.log("🌐 [Bridge] Detected web environment, returning cached:", l), l;
203
+ }
204
+ }
205
+ async function H(n = g) {
206
+ return p() ? await C(n) : null;
207
+ }
208
+ function y(n) {
209
+ const e = w(n);
210
+ e && a && (a.resolve(e), a = null);
211
+ }
212
+ function h(n) {
213
+ console.log("📩 [Bridge] window.processUserInfo called with:", n), console.log("📩 [Bridge] pendingUserInfoRequest exists:", !!t);
214
+ const e = m(n);
215
+ t ? (console.log("✅ [Bridge] Resolving pendingUserInfoRequest with:", e), t.resolve(e), t = null) : (console.warn("⚠️ [Bridge] No pendingUserInfoRequest when processUserInfo called!"), console.warn("⚠️ [Bridge] UserInfo was processed but no one is waiting for it"));
216
+ }
217
+ function j() {
218
+ if (typeof window > "u") {
219
+ console.log("🔧 [Bridge] initUserBridge: window is undefined, skipping");
220
+ return;
221
+ }
222
+ console.log("🔧 [Bridge] initUserBridge: Initializing..."), console.log("🔧 [Bridge] UserAgent:", navigator.userAgent), window.processUserCredentials = y, window.processUserInfo = h, console.log("🔧 [Bridge] Exposed window.processUserCredentials and window.processUserInfo"), window.addEventListener("message", (n) => {
223
+ n.data?.type === "user-credentials" && (console.log("📩 [Bridge] Received postMessage user-credentials:", n.data), y(n.data)), n.data?.type === "user-info" && (console.log("📩 [Bridge] Received postMessage user-info:", n.data), h(n.data));
224
+ }), console.log("🔧 [Bridge] Added message event listener"), console.log("✅ [Bridge] initUserBridge complete");
225
+ }
226
+ j();
227
+ P().catch((n) => {
228
+ console.warn("[UserSDK] Auth check on load:", n.message);
229
+ });
230
+ export {
231
+ P as getAuthTokenAsync,
232
+ _ as getUserInfoAsync,
233
+ H as getUserInfoFromParent,
234
+ p as isInIframe,
235
+ y as processUserCredentials,
236
+ h as processUserInfo
237
+ };
@@ -0,0 +1,28 @@
1
+ const n = {
2
+ mode: "development",
3
+ debug: !1,
4
+ apiBaseUrl: void 0,
5
+ headers: {}
6
+ };
7
+ function o() {
8
+ const e = {};
9
+ return typeof process < "u" && process.env && (process.env.NODE_ENV && (e.mode = process.env.NODE_ENV), process.env.AIPPY_DEBUG && (e.debug = process.env.AIPPY_DEBUG === "true"), process.env.AIPPY_API_BASE_URL && (e.apiBaseUrl = process.env.AIPPY_API_BASE_URL)), e;
10
+ }
11
+ function r(e) {
12
+ const s = o();
13
+ return {
14
+ ...n,
15
+ ...s,
16
+ ...e,
17
+ headers: {
18
+ ...n.headers,
19
+ ...s.headers,
20
+ ...e?.headers
21
+ }
22
+ };
23
+ }
24
+ export {
25
+ n as D,
26
+ o as g,
27
+ r as m
28
+ };