@aippy/runtime 0.2.6 → 0.2.7-dev.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.
@@ -0,0 +1,152 @@
1
+ import { createOpenAICompatible as A } from "@ai-sdk/openai-compatible";
2
+ import "react";
3
+ import { h as p } from "./bridge-DdAH4txB.js";
4
+ import { DefaultChatTransport as l, AISDKError as a } from "ai";
5
+ const E = "https://api.aippy.dev", d = `${E}/api/aisdk/v1/`, h = `${E}/api/aisdk/v1/ui/`, g = "gpt-5-nano", _ = "";
6
+ function U(e = {}) {
7
+ return {
8
+ baseUrl: e.baseUrl ?? d
9
+ };
10
+ }
11
+ function i(e = {}) {
12
+ return {
13
+ baseUrl: e.baseUrl ?? h
14
+ };
15
+ }
16
+ function c(e, r) {
17
+ const t = e.endsWith("/") ? e : `${e}/`, n = r.startsWith("/") ? r.slice(1) : r;
18
+ return new URL(n, t).href;
19
+ }
20
+ function u() {
21
+ return async (e, r) => {
22
+ const t = await p(), n = new Headers(r?.headers);
23
+ return n.set("Authorization", `Bearer ${t}`), globalThis.fetch(e, { ...r, headers: n });
24
+ };
25
+ }
26
+ const y = [
27
+ "gpt-image-1",
28
+ "gpt-image-1-mini",
29
+ "gpt-image-1.5"
30
+ ];
31
+ function I(e) {
32
+ try {
33
+ const r = JSON.parse(e);
34
+ if (r.model && y.some((t) => r.model.startsWith(t))) {
35
+ const { response_format: t, ...n } = r;
36
+ return JSON.stringify(n);
37
+ }
38
+ } catch {
39
+ }
40
+ return e;
41
+ }
42
+ function w(e = {}) {
43
+ const { baseUrl: r } = U(e), t = u();
44
+ return A({
45
+ name: "aippy",
46
+ baseURL: r,
47
+ fetch: async (s, o) => s.toString().includes("/images/generations") && o?.method?.toUpperCase() === "POST" && o?.body ? t(s, {
48
+ ...o,
49
+ body: I(o.body)
50
+ }) : t(s, o)
51
+ });
52
+ }
53
+ const T = "/chat", O = "/completion", f = "/object";
54
+ function N(e = {}) {
55
+ const { baseUrl: r } = i(e), t = e.model ?? g, n = e.system ?? _, s = e.api ?? c(r, T), o = { model: t, system: n }, m = u();
56
+ return {
57
+ transport: new l({
58
+ api: s,
59
+ body: o,
60
+ // Ensure token is fetched fresh for every request
61
+ fetch: m
62
+ })
63
+ };
64
+ }
65
+ function D(e = {}) {
66
+ const { baseUrl: r } = i(e), t = u();
67
+ return {
68
+ api: c(r, O),
69
+ // Ensure token is fetched fresh for every request
70
+ fetch: t
71
+ };
72
+ }
73
+ async function B(e) {
74
+ const { schemaId: r, ...t } = e, { baseUrl: n } = i(t), s = await p();
75
+ return {
76
+ api: c(n, f),
77
+ headers: { Authorization: `Bearer ${s}` },
78
+ schemaId: r
79
+ };
80
+ }
81
+ async function L(e = {}) {
82
+ const { baseUrl: r } = i(e), t = await p();
83
+ return {
84
+ api: c(r, f),
85
+ headers: { Authorization: `Bearer ${t}` }
86
+ };
87
+ }
88
+ function k(e, r) {
89
+ const t = e.status;
90
+ if (r && typeof r == "object" && "error" in r) {
91
+ const n = r, s = n.error.code, o = s != null ? `AippyAIError_${s}` : `AippyAIError_${t}`;
92
+ return new a({
93
+ name: o,
94
+ message: n.error.message,
95
+ cause: {
96
+ type: n.error.type ?? void 0,
97
+ param: n.error.param ?? void 0,
98
+ status: t
99
+ }
100
+ });
101
+ }
102
+ return new a({
103
+ name: `AippyAIError_${t}`,
104
+ message: `Request failed with status ${t}`,
105
+ cause: { status: t }
106
+ });
107
+ }
108
+ function $() {
109
+ return new a({
110
+ name: "AippyAIError_MISSING_TOKEN",
111
+ message: "User token is required. Ensure user credentials are available via initUserBridge()."
112
+ });
113
+ }
114
+ function F() {
115
+ return new a({
116
+ name: "AippyAIError_REQUEST_ABORTED",
117
+ message: "Request was aborted"
118
+ });
119
+ }
120
+ function v(e) {
121
+ const r = e instanceof Error ? e.message : "Network request failed";
122
+ return new a({
123
+ name: "AippyAIError_NETWORK_ERROR",
124
+ message: r,
125
+ cause: e instanceof Error ? e : String(e)
126
+ });
127
+ }
128
+ function P(e) {
129
+ return new a({
130
+ name: "AippyAIError_PARSE_ERROR",
131
+ message: `Failed to parse response: ${e}`
132
+ });
133
+ }
134
+ export {
135
+ d as D,
136
+ T as U,
137
+ w as a,
138
+ N as b,
139
+ D as c,
140
+ B as d,
141
+ L as e,
142
+ O as f,
143
+ f as g,
144
+ h,
145
+ g as i,
146
+ _ as j,
147
+ F as k,
148
+ v as l,
149
+ $ as m,
150
+ k as n,
151
+ P as p
152
+ };
@@ -1,55 +1,101 @@
1
- import { DEFAULT_CONFIG as o, SDK_NAME as t, VERSION as r, getConfigFromEnv as i, getVersionInfo as s, mergeConfig as n } from "../core/index.js";
2
- import { a as m, A as c, C as d, E as f, R as u, b as l, c as A, p as S } from "../runtime-DjBdOttl.js";
3
- import { CameraAPI as C, FileSystemAPI as R, GeolocationAPI as x, SensorsAPI as M, camera as P, fileSystem as I, geolocation as g, hasNativeBridge as y, isMotionSupported as O, isOrientationSupported as b, requestMotionPermission as v, sensors as D, vibrate as h, watchMotion as w, watchOrientation as F } from "../device/index.js";
4
- import { c as T, a as V, P as _, b as k, p as G, d as H } from "../pwa-8DGmPqLV.js";
5
- import { a as q, b as B } from "../useTweaks-QxMRmg7i.js";
6
- import { c as L, a as W, b as j, i as z, p as J, u as Q } from "../useAudioContext-CNQQSTab.js";
7
- import { reportScore as Y, sendEvent as Z, updateScore as $ } from "../leaderboard/index.js";
1
+ import { DEFAULT_CONFIG as r, SDK_NAME as s, VERSION as o, getConfigFromEnv as t, getVersionInfo as i, mergeConfig as n } from "../core/index.js";
2
+ import { A as m, E as d, c as u } from "../errors-CDEBaBxB.js";
3
+ import { A as C, C as c, R as E, a as l, p as A } from "../runtime-CmoG3v2m.js";
4
+ import { CameraAPI as I, FileSystemAPI as U, GeolocationAPI as S, SensorsAPI as T, camera as P, fileSystem as y, geolocation as h, isMotionSupported as _, isOrientationSupported as O, requestMotionPermission as D, sensors as x, vibrate as R, watchMotion as k, watchOrientation as M } from "../device/index.js";
5
+ import { c as F, a as N, P as L, b as B, p as v, d as w } from "../pwa-8DGmPqLV.js";
6
+ import { a as H, b as j } from "../useTweaks-QxMRmg7i.js";
7
+ import { c as Q, a as V, b as J, i as z, p as K, u as W } from "../useAudioContext-CNQQSTab.js";
8
+ import { reportScore as X, sendEvent as Z, updateScore as $ } from "../leaderboard/index.js";
9
+ import { D as ae, i as re, j as se, h as oe, U as te, f as ie, g as ne, k as pe, a as me, b as de, c as ue, e as fe, d as Ce, m as ce, l as Ee, n as le, p as Ae } from "../errors-DWRVLkVz.js";
10
+ import { f as Ie, b as Ue, h as Se, l as Te, j as Pe, g as ye, k as he, e as _e, i as Oe, c as De, d as xe, r as Re, s as ke, a as Me, t as be } from "../bridge-DdAH4txB.js";
11
+ import { e as Ne, f as Le, g as Be, a as ve, u as we, b as Ge, d as He, c as je, h as qe } from "../userSessionInfo-CBk9ywXi.js";
12
+ import { h as Ve } from "../native-bridge-JAmH-zTN.js";
8
13
  export {
9
- m as AippyRuntime,
10
- c as AippyRuntimeError,
11
- C as CameraAPI,
12
- d as Cancellable,
13
- o as DEFAULT_CONFIG,
14
- f as ERROR_CODES,
15
- R as FileSystemAPI,
16
- x as GeolocationAPI,
17
- T as PWAUtils,
18
- V as PerformanceMonitor,
19
- _ as PlatformDetector,
20
- u as ReceiveChannel,
21
- t as SDK_NAME,
22
- M as SensorsAPI,
23
- r as VERSION,
14
+ C as AippyRuntime,
15
+ m as AippyRuntimeError,
16
+ I as CameraAPI,
17
+ c as Cancellable,
18
+ ae as DEFAULT_BASE_URL,
19
+ re as DEFAULT_CHAT_MODEL,
20
+ se as DEFAULT_CHAT_SYSTEM,
21
+ r as DEFAULT_CONFIG,
22
+ oe as DEFAULT_UI_BASE_URL,
23
+ d as ERROR_CODES,
24
+ U as FileSystemAPI,
25
+ S as GeolocationAPI,
26
+ F as PWAUtils,
27
+ N as PerformanceMonitor,
28
+ L as PlatformDetector,
29
+ E as ReceiveChannel,
30
+ s as SDK_NAME,
31
+ T as SensorsAPI,
32
+ te as UI_CHAT_ENDPOINT,
33
+ ie as UI_COMPLETION_ENDPOINT,
34
+ ne as UI_OBJECT_ENDPOINT,
35
+ o as VERSION,
36
+ pe as abortedError,
37
+ me as aippy,
38
+ de as aippyChatConfig,
39
+ ue as aippyCompletionConfig,
40
+ fe as aippyObjectBaseConfig,
41
+ Ce as aippyObjectConfig,
24
42
  l as aippyRuntime,
25
- q as aippyTweaks,
26
- B as aippyTweaksRuntime,
43
+ H as aippyTweaks,
44
+ j as aippyTweaksRuntime,
45
+ Ie as autoRequestCredentials,
27
46
  P as camera,
28
- A as createError,
29
- L as createHiddenMediaElement,
30
- W as createHiddenVideoElement,
31
- I as fileSystem,
32
- g as geolocation,
33
- i as getConfigFromEnv,
34
- s as getVersionInfo,
35
- y as hasNativeBridge,
36
- j as isIOSDevice,
47
+ Ne as clearProfileCache,
48
+ u as createError,
49
+ Q as createHiddenMediaElement,
50
+ V as createHiddenVideoElement,
51
+ Le as fetchUserProfile,
52
+ y as fileSystem,
53
+ h as geolocation,
54
+ Ue as getAuthToken,
55
+ Se as getAuthTokenAsync,
56
+ Te as getCachedCredentials,
57
+ t as getConfigFromEnv,
58
+ Be as getCurrentUserId,
59
+ Pe as getCurrentUserIdAsync,
60
+ ye as getUserSdkConfig,
61
+ i as getVersionInfo,
62
+ he as hasCredentials,
63
+ Ve as hasNativeBridge,
64
+ _e as initUserBridge,
65
+ Oe as initUserSdk,
66
+ J as isIOSDevice,
67
+ De as isInIframe,
37
68
  z as isMediaStreamAudioSupported,
38
- O as isMotionSupported,
39
- b as isOrientationSupported,
69
+ _ as isMotionSupported,
70
+ O as isOrientationSupported,
40
71
  n as mergeConfig,
41
- J as patchAudioContext,
42
- k as performanceMonitor,
43
- G as platform,
44
- S as processMotionData,
45
- H as pwa,
46
- Y as reportScore,
47
- v as requestMotionPermission,
72
+ ce as missingTokenError,
73
+ Ee as networkError,
74
+ le as normalizeError,
75
+ Ae as parseError,
76
+ K as patchAudioContext,
77
+ B as performanceMonitor,
78
+ v as platform,
79
+ A as processMotionData,
80
+ w as pwa,
81
+ X as reportScore,
82
+ xe as requestCredentialsFromParent,
83
+ Re as requestCredentialsFromiOS,
84
+ D as requestMotionPermission,
48
85
  Z as sendEvent,
49
- D as sensors,
86
+ x as sensors,
87
+ ke as setAuthToken,
88
+ Me as setCurrentUserId,
89
+ be as tryGetCredentialsFromParentStorage,
50
90
  $ as updateScore,
51
- Q as useAudioContext,
52
- h as vibrate,
53
- w as watchMotion,
54
- F as watchOrientation
91
+ W as useAudioContext,
92
+ ve as useAuthToken,
93
+ we as useCurrentUserId,
94
+ Ge as useGetCurrentUserProfileQuery,
95
+ He as useGetJoinedUserProfilesQuery,
96
+ je as useGetUserProfileByIdQuery,
97
+ qe as userSessionInfo,
98
+ R as vibrate,
99
+ k as watchMotion,
100
+ M as watchOrientation
55
101
  };
package/dist/index.d.ts CHANGED
@@ -4,3 +4,5 @@ export * from './utils';
4
4
  export * from './tweaks';
5
5
  export * from './audio';
6
6
  export * from './leaderboard';
7
+ export * from './ai';
8
+ export * from './user';
@@ -0,0 +1,6 @@
1
+ function a() {
2
+ return typeof window < "u" && !!window.webkit && !!window.webkit?.messageHandlers && !!window.webkit?.messageHandlers?.aippyListener;
3
+ }
4
+ export {
5
+ a as h
6
+ };
@@ -1,24 +1,6 @@
1
1
  var u = Object.defineProperty;
2
- var m = (o, e, n) => e in o ? u(o, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[e] = n;
3
- var r = (o, e, n) => m(o, typeof e != "symbol" ? e + "" : e, n);
4
- class d extends Error {
5
- constructor(n, i = "AIPPY_ERROR", t) {
6
- super(n);
7
- r(this, "code");
8
- r(this, "context");
9
- this.name = "AippyRuntimeError", this.code = i, this.context = t;
10
- }
11
- }
12
- const R = {
13
- NOT_SUPPORTED: "NOT_SUPPORTED",
14
- PERMISSION_DENIED: "PERMISSION_DENIED",
15
- INVALID_CONFIG: "INVALID_CONFIG",
16
- NETWORK_ERROR: "NETWORK_ERROR",
17
- UNKNOWN_ERROR: "UNKNOWN_ERROR"
18
- };
19
- function g(o, e = "UNKNOWN_ERROR", n) {
20
- return new d(o, R[e], n);
21
- }
2
+ var m = (o, e, t) => e in o ? u(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var r = (o, e, t) => m(o, typeof e != "symbol" ? e + "" : e, t);
22
4
  class a {
23
5
  constructor(e) {
24
6
  r(this, "cancelled", !1);
@@ -31,28 +13,28 @@ class a {
31
13
  return this.cancelled;
32
14
  }
33
15
  }
34
- class f {
16
+ class d {
35
17
  constructor() {
36
18
  r(this, "listeners", /* @__PURE__ */ new Map());
37
19
  }
38
- addEventListener(e, n) {
39
- this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(n);
20
+ addEventListener(e, t) {
21
+ this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(t);
40
22
  }
41
- removeEventListener(e, n) {
23
+ removeEventListener(e, t) {
42
24
  const i = this.listeners.get(e);
43
25
  if (i) {
44
- const t = i.indexOf(n);
45
- t > -1 && i.splice(t, 1);
26
+ const n = i.indexOf(t);
27
+ n > -1 && i.splice(n, 1);
46
28
  }
47
29
  }
48
- emit(e, n) {
30
+ emit(e, t) {
49
31
  const i = this.listeners.get(e);
50
- i && i.forEach((t) => t(n));
32
+ i && i.forEach((n) => n(t));
51
33
  }
52
34
  }
53
- class y {
35
+ class f {
54
36
  constructor() {
55
- r(this, "emitter", new f());
37
+ r(this, "emitter", new d());
56
38
  }
57
39
  /**
58
40
  * Emit a message to subscribers
@@ -63,9 +45,9 @@ class y {
63
45
  /**
64
46
  * Subscribe to messages on a specific endpoint
65
47
  */
66
- subscribe(e, n) {
67
- const i = (t) => {
68
- n(t);
48
+ subscribe(e, t) {
49
+ const i = (n) => {
50
+ t(n);
69
51
  };
70
52
  return this.emitter.addEventListener(e, i), new a(() => {
71
53
  this.emitter.removeEventListener(e, i);
@@ -74,16 +56,16 @@ class y {
74
56
  /**
75
57
  * Subscribe to a single message (auto-unsubscribe after first message)
76
58
  */
77
- once(e, n) {
78
- const i = this.subscribe(e, (t) => {
79
- i.cancel(), n(t);
59
+ once(e, t) {
60
+ const i = this.subscribe(e, (n) => {
61
+ i.cancel(), t(n);
80
62
  });
81
63
  return i;
82
64
  }
83
65
  }
84
- class h {
66
+ class y {
85
67
  constructor() {
86
- r(this, "receiveChannel", new y());
68
+ r(this, "receiveChannel", new f());
87
69
  r(this, "seq", 0);
88
70
  r(this, "motionListeners", []);
89
71
  r(this, "noListenersWarned", !1);
@@ -116,9 +98,9 @@ class h {
116
98
  isTweaksMessage(e) {
117
99
  if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
118
100
  return !1;
119
- const n = Object.keys(e);
120
- return n.length === 0 ? !1 : n.some((t) => {
121
- const c = e[t];
101
+ const t = Object.keys(e);
102
+ return t.length === 0 ? !1 : t.some((n) => {
103
+ const c = e[n];
122
104
  return typeof c == "object" && c !== null && "value" in c;
123
105
  });
124
106
  }
@@ -129,18 +111,18 @@ class h {
129
111
  * @param callback - Callback to handle received data
130
112
  * @returns Cancellable subscription
131
113
  */
132
- createSubscription(e, n, i) {
133
- const t = (this.seq++).toString(), c = {
134
- command: n.command,
114
+ createSubscription(e, t, i) {
115
+ const n = (this.seq++).toString(), c = {
116
+ command: t.command,
135
117
  parameters: {
136
- type: n.type,
118
+ type: t.type,
137
119
  action: "subscribe",
138
- endpoint: t
120
+ endpoint: n
139
121
  }
140
122
  };
141
123
  console.log("📨 [Aippy Runtime] Creating subscription with message:", JSON.stringify(c, null, 2));
142
- const l = this.receiveChannel.subscribe(t, (s) => {
143
- if (console.log(`📬 [Aippy Runtime] Received data on endpoint ${t}:`, s), s.error !== void 0) {
124
+ const p = this.receiveChannel.subscribe(n, (s) => {
125
+ if (console.log(`📬 [Aippy Runtime] Received data on endpoint ${n}:`, s), s.error !== void 0) {
144
126
  console.warn("⚠️ [Aippy Runtime] Received error, skipping:", s.error);
145
127
  return;
146
128
  }
@@ -152,14 +134,14 @@ class h {
152
134
  console.error("❌ [Aippy Runtime] Failed to send postMessage:", s);
153
135
  }
154
136
  return new a(() => {
155
- console.log(`🔌 [Aippy Runtime] Unsubscribing from endpoint ${t}`), l.cancel();
137
+ console.log(`🔌 [Aippy Runtime] Unsubscribing from endpoint ${n}`), p.cancel();
156
138
  try {
157
139
  const s = {
158
- command: n.command,
140
+ command: t.command,
159
141
  parameters: {
160
- type: n.type,
142
+ type: t.type,
161
143
  action: "unsubscribe",
162
- endpoint: t
144
+ endpoint: n
163
145
  }
164
146
  };
165
147
  e.postMessage(s), console.log("✅ [Aippy Runtime] Unsubscribe message sent:", s);
@@ -175,27 +157,27 @@ class h {
175
157
  */
176
158
  addMotionListener(e) {
177
159
  console.log("🎬 [Aippy Runtime] addMotionListener called"), this.motionListeners.push(e), console.log(`📝 [Aippy Runtime] Total motion listeners: ${this.motionListeners.length}`);
178
- const n = window.webkit?.messageHandlers?.aippyListener;
179
- if (!n)
160
+ const t = window.webkit?.messageHandlers?.aippyListener;
161
+ if (!t)
180
162
  return console.warn("⚠️ [Aippy Runtime] No webkit message handler found, using fallback mode"), () => {
181
- const t = this.motionListeners.indexOf(e);
182
- t > -1 && this.motionListeners.splice(t, 1);
163
+ const n = this.motionListeners.indexOf(e);
164
+ n > -1 && this.motionListeners.splice(n, 1);
183
165
  };
184
166
  console.log("✅ [Aippy Runtime] Webkit handler found, creating subscription");
185
167
  const i = this.createSubscription(
186
- n,
168
+ t,
187
169
  {
188
170
  command: "navigator.motion",
189
171
  type: "motion"
190
172
  },
191
- (t) => {
192
- console.log("📥 [Aippy Runtime] Received motion data from native:", t), t.motion && e(t.motion);
173
+ (n) => {
174
+ console.log("📥 [Aippy Runtime] Received motion data from native:", n), n.motion && e(n.motion);
193
175
  }
194
176
  );
195
177
  return () => {
196
178
  console.log("🧹 [Aippy Runtime] Cleaning up motion listener"), i.cancel();
197
- const t = this.motionListeners.indexOf(e);
198
- t > -1 && this.motionListeners.splice(t, 1);
179
+ const n = this.motionListeners.indexOf(e);
180
+ n > -1 && this.motionListeners.splice(n, 1);
199
181
  };
200
182
  }
201
183
  /**
@@ -208,17 +190,17 @@ class h {
208
190
  this.noListenersWarned || (console.warn("⚠️ [Aippy Runtime] No motion listeners to broadcast to"), this.noListenersWarned = !0);
209
191
  return;
210
192
  }
211
- const n = e.motion || e;
193
+ const t = e.motion || e;
212
194
  this.motionListeners.forEach((i) => {
213
195
  try {
214
- i(n);
215
- } catch (t) {
216
- console.error("⚠️ [Aippy Runtime] Error in motion listener:", t);
196
+ i(t);
197
+ } catch (n) {
198
+ console.error("⚠️ [Aippy Runtime] Error in motion listener:", n);
217
199
  }
218
200
  });
219
201
  }
220
202
  }
221
- function w(o) {
203
+ function h(o) {
222
204
  if (!o || typeof o != "object") {
223
205
  console.warn("⚠️ [Aippy Runtime] Invalid motion data type:", typeof o);
224
206
  return;
@@ -227,17 +209,14 @@ function w(o) {
227
209
  console.warn("⚠️ [Aippy Runtime] Motion data missing valid motion field");
228
210
  return;
229
211
  }
230
- p.broadcastMotionData(o);
212
+ l.broadcastMotionData(o);
231
213
  }
232
- const p = new h();
233
- typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = w);
214
+ const l = new y();
215
+ typeof window < "u" && (window.aippyRuntime = l, window.processMotionData = h);
234
216
  export {
235
- d as A,
217
+ y as A,
236
218
  a as C,
237
- R as E,
238
- y as R,
239
- h as a,
240
- p as b,
241
- g as c,
242
- w as p
219
+ f as R,
220
+ l as a,
221
+ h as p
243
222
  };
@@ -0,0 +1,9 @@
1
+ import { UserProfile } from './types';
2
+ /**
3
+ * Fetch user profile by ID from API
4
+ */
5
+ export declare function fetchUserProfile(userId: string): Promise<UserProfile | null>;
6
+ /**
7
+ * Clear profile cache
8
+ */
9
+ export declare function clearProfileCache(userId?: string): void;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * User SDK Bridge
3
+ * Handles communication with:
4
+ * - iOS native layer via window.webkit.aippyListener
5
+ * - Parent window via postMessage (iframe scenario)
6
+ */
7
+ /**
8
+ * User credentials
9
+ */
10
+ export interface IOSUserCredentials {
11
+ uid: string;
12
+ token: string;
13
+ apiBaseUrl?: string;
14
+ }
15
+ /**
16
+ * Check if running inside an iframe
17
+ */
18
+ export declare function isInIframe(): boolean;
19
+ /**
20
+ * Request user credentials from parent window (iframe scenario)
21
+ * Parent window should respond with postMessage containing credentials
22
+ *
23
+ * @param timeoutMs - Timeout in milliseconds (default: 5000)
24
+ * @returns Promise resolving to user credentials
25
+ */
26
+ export declare function requestCredentialsFromParent(timeoutMs?: number): Promise<IOSUserCredentials>;
27
+ /**
28
+ * Try to get credentials from parent localStorage directly
29
+ * This works when same-origin, otherwise falls back to postMessage
30
+ *
31
+ * localStorage format:
32
+ * - token: JWT string
33
+ * - user: JSON string with { uid, nickName, ... }
34
+ */
35
+ export declare function tryGetCredentialsFromParentStorage(): IOSUserCredentials | null;
36
+ /**
37
+ * Request user credentials from iOS native layer
38
+ * Uses aippyRuntime's message passing mechanism
39
+ *
40
+ * @param timeoutMs - Timeout in milliseconds (default: 5000)
41
+ * @returns Promise resolving to user credentials (empty if unavailable)
42
+ */
43
+ export declare function requestCredentialsFromiOS(timeoutMs?: number): Promise<IOSUserCredentials>;
44
+ /**
45
+ * Receive credentials directly from iOS or parent window
46
+ * Called via: window.processUserCredentials(data)
47
+ */
48
+ export declare function processUserCredentials(data: unknown): void;
49
+ /**
50
+ * Initialize bridge and expose to window
51
+ */
52
+ export declare function initUserBridge(): void;
53
+ /**
54
+ * Auto-request credentials on SDK load
55
+ * Tries multiple sources in order:
56
+ * 1. iOS native bridge (if available)
57
+ * 2. Parent localStorage (if in iframe, same-origin)
58
+ * 3. Parent postMessage (if in iframe, cross-origin)
59
+ */
60
+ export declare function autoRequestCredentials(): Promise<void>;
61
+ /**
62
+ * Get auth token asynchronously
63
+ * Waits for credentials if not already available
64
+ * @returns Promise resolving to token string, or "" if unavailable
65
+ */
66
+ export declare function getAuthTokenAsync(): Promise<string>;
67
+ /**
68
+ * Get current user ID asynchronously
69
+ * Waits for credentials if not already available
70
+ * @returns Promise resolving to user ID string, or "" if unavailable
71
+ */
72
+ export declare function getCurrentUserIdAsync(): Promise<string>;
73
+ /**
74
+ * Check if credentials have been received
75
+ */
76
+ export declare function hasCredentials(): boolean;
77
+ /**
78
+ * Get cached credentials (synchronous, may be null if not yet received)
79
+ */
80
+ export declare function getCachedCredentials(): IOSUserCredentials | null;
@@ -0,0 +1,21 @@
1
+ import { UserSdkConfig } from './types';
2
+ /**
3
+ * Initialize user SDK configuration
4
+ */
5
+ export declare function initUserSdk(config: Partial<UserSdkConfig>): void;
6
+ /**
7
+ * Get current user SDK configuration
8
+ */
9
+ export declare function getUserSdkConfig(): UserSdkConfig;
10
+ /**
11
+ * Update auth token
12
+ */
13
+ export declare function setAuthToken(token: string): void;
14
+ /**
15
+ * Update current user ID
16
+ */
17
+ export declare function setCurrentUserId(userId: string | null): void;
18
+ /**
19
+ * Get current auth token synchronously
20
+ */
21
+ export declare function getAuthToken(): string;