@aippy/runtime 0.4.1-dev.1 → 0.4.2-beta.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.
Files changed (45) hide show
  1. package/README.md +35 -6
  2. package/dist/ai/errors.d.ts +1 -0
  3. package/dist/ai/index.d.ts +2 -0
  4. package/dist/ai/index.js +22 -17
  5. package/dist/ai/viggle/generate.d.ts +67 -0
  6. package/dist/ai/viggle/models.d.ts +46 -0
  7. package/dist/ai/viggle/recovery.d.ts +12 -0
  8. package/dist/{app-version-checker-Bz7FrEZz.js → app-version-checker-YVIFbytA.js} +18 -17
  9. package/dist/bridge-K3HqQwdj.js +311 -0
  10. package/dist/container-message-gRiGPin4.js +56 -0
  11. package/dist/core/env.d.ts +2 -0
  12. package/dist/core/index.js +2 -2
  13. package/dist/core/parent-message.d.ts +5 -0
  14. package/dist/core/wallet-recharge.d.ts +16 -0
  15. package/dist/helper-CJ3YV3nf.js +748 -0
  16. package/dist/{hooks-D5lkty5r.js → hooks-CMKwSLcQ.js} +1 -1
  17. package/dist/index/index.js +66 -56
  18. package/dist/index.d.ts +1 -0
  19. package/dist/ministore/app-authorization.d.ts +9 -0
  20. package/dist/ministore/authorization.d.ts +6 -0
  21. package/dist/ministore/consume.d.ts +3 -0
  22. package/dist/ministore/errors.d.ts +18 -0
  23. package/dist/ministore/index.d.ts +19 -0
  24. package/dist/ministore/index.js +99 -0
  25. package/dist/ministore/order.d.ts +1 -0
  26. package/dist/ministore/purchase.d.ts +5 -0
  27. package/dist/ministore/queries.d.ts +14 -0
  28. package/dist/ministore/recharge.d.ts +12 -0
  29. package/dist/ministore/transport.d.ts +14 -0
  30. package/dist/ministore/types.d.ts +177 -0
  31. package/dist/ministore/update-item.d.ts +3 -0
  32. package/dist/ministore/validation.d.ts +19 -0
  33. package/dist/ministore.d.ts +2 -0
  34. package/dist/recharge-o5P-y8eV.js +1036 -0
  35. package/dist/tweaks/index.js +1 -1
  36. package/dist/{useTweaks-v5wEZGGm.js → useTweaks-C7BEMpV3.js} +21 -27
  37. package/dist/user/bridge.d.ts +3 -8
  38. package/dist/user/config.d.ts +2 -0
  39. package/dist/user/index.js +3 -3
  40. package/dist/utils/app-version-requirements.json.d.ts +4 -0
  41. package/dist/utils/index.js +1 -1
  42. package/package.json +15 -3
  43. package/dist/bridge-CtB9L5kL.js +0 -259
  44. package/dist/container-message-KgL1paGV.js +0 -56
  45. package/dist/helper-CZqFi-QF.js +0 -241
package/README.md CHANGED
@@ -17,14 +17,19 @@ import { AippyConfig, mergeConfig } from '@aippy/runtime/core';
17
17
 
18
18
  const config = mergeConfig({
19
19
  debug: true,
20
- apiBaseUrl: 'https://api.example.com'
20
+ apiBaseUrl: 'https://api.example.com',
21
21
  });
22
22
  ```
23
23
 
24
24
  ### Device APIs
25
25
 
26
26
  ```typescript
27
- import { camera, geolocation, sensors, fileSystem } from '@aippy/runtime/device';
27
+ import {
28
+ camera,
29
+ geolocation,
30
+ sensors,
31
+ fileSystem,
32
+ } from '@aippy/runtime/device';
28
33
 
29
34
  // Camera
30
35
  const stream = await camera.getStream();
@@ -32,13 +37,13 @@ const photo = await camera.capturePhoto({ quality: 'high' });
32
37
 
33
38
  // Geolocation
34
39
  const position = await geolocation.getCurrentPosition();
35
- const watchId = geolocation.watchPosition((pos) => {
40
+ const watchId = geolocation.watchPosition(pos => {
36
41
  console.log('Position:', pos);
37
42
  });
38
43
 
39
44
  // Sensors
40
45
  const orientation = await sensors.getOrientation();
41
- const cleanup = sensors.watchOrientation((data) => {
46
+ const cleanup = sensors.watchOrientation(data => {
42
47
  console.log('Orientation:', data);
43
48
  });
44
49
 
@@ -78,7 +83,7 @@ const patchedCtx = patchAudioContext(ctx);
78
83
  // Unlock audio on user interaction (required on iOS)
79
84
  button.onclick = async () => {
80
85
  await patchedCtx.unlock();
81
-
86
+
82
87
  // Use native Web Audio API as normal
83
88
  const osc = patchedCtx.createOscillator();
84
89
  osc.connect(patchedCtx.destination);
@@ -90,7 +95,9 @@ button.onclick = async () => {
90
95
  ### AI (Backend Proxy Adapter)
91
96
 
92
97
  ```typescript
93
- // Default base URL: https://api.aippy.dev/api/aisdk/v1
98
+ // Default base URL: https://api.aippy.ai/aisdk/v1/ (no /api prefix)
99
+ // Resolved by core/env.ts at runtime — api.aippy.dev only when the page host
100
+ // ends in .aippynow.com or is localhost; everything else gets prod.
94
101
 
95
102
  import { streamText, experimental_generateImage as generateImage } from 'ai';
96
103
  import { aippyAIProvider } from '@aippy/runtime/ai';
@@ -120,6 +127,27 @@ const image = await generateImage({
120
127
  console.log(image.image?.base64);
121
128
  ```
122
129
 
130
+ `@aippy/runtime/ai` also exports internal-test Viggle generation with automatic recovery and
131
+ `listViggleModels` for the current user's project history. Project ticket keys
132
+ are resolved by the backend; applications do not settle tickets or pass SKU
133
+ constants. Availability depends on the matching backend/shared MiniStore
134
+ contracts and project configuration. See the [AI module](./src/ai/README.md).
135
+
136
+ ### Ministore (Internal Test Only)
137
+
138
+ `@aippy/runtime/ministore` provides project entitlement catalogs, holdings,
139
+ mall GEM balance, authorization queries, explicit settlement and records.
140
+ The SDK and its Skill are not available to external creators and are not
141
+ advertised in system prompts. An installed export does not authorize public use.
142
+ App or approved website-parent confirmation uses the specified wallet.authorize
143
+ contract and stays separate from settlement. The synchronous support check is
144
+ native-only; parent confirmation needs a matching deployed website handler.
145
+ Non-native recharge hints do not wait for funds or resume settlement.
146
+ Real host support and service acceptance remain pending; no
147
+ package publication or external enablement is performed by this work.
148
+ See the [ministore module](./src/ministore/README.md) for the verified HTTP
149
+ contract, internal-consumer requirements and recovery rules.
150
+
123
151
  ## Packages
124
152
 
125
153
  - `@aippy/runtime/core` - Core types and configuration
@@ -127,6 +155,7 @@ console.log(image.image?.base64);
127
155
  - `@aippy/runtime/utils` - Platform detection, performance monitoring, PWA utilities
128
156
  - `@aippy/runtime/audio` - iOS-compatible Web Audio API wrapper
129
157
  - `@aippy/runtime/ai` - AI SDK adapter wrapping `ai` package, routes through backend proxy
158
+ - `@aippy/runtime/ministore` - Project entitlements, GEM wallet and authorization (internal test only; App integration pending)
130
159
 
131
160
  ## Publishing
132
161
 
@@ -2,6 +2,7 @@ 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
+ * Ordinary AI credits are separate from GEM; quota errors never open GEM recharge.
5
6
  * Uses [Aippy Runtime] prefix - these errors are NOT reported to LLM.
6
7
  */
7
8
  export declare function normalizeError(response: Response, body?: unknown): AISDKError;
@@ -41,4 +41,6 @@ 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, resolveOpenAIConfig, resolveUIConfig, } from './shared';
43
43
  export { normalizeError } from './errors';
44
+ export { generateCharacter3D, generateMotion, createViggleRequestId, resumeViggleGeneration, ViggleGenerationError, type GenerateCharacter3DInput, type GenerateMotionInput, type ViggleAsset, type ViggleKind, type ViggleStage, type ResumeViggleGenerationInput, } from './viggle/generate';
45
+ export { listViggleModels, type ListViggleModelsOptions, type ViggleModel, type ViggleModelValue, type ViggleModelsPage, } from './viggle/models';
44
46
  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,21 +1,26 @@
1
- import { D as i, d as A, e as r, c as n, U as C, a as I, b as f, h as g, g as _, l as p, n as E, p as T, r as U, f as t, s as l, v as D } from "../helper-CZqFi-QF.js";
2
- import "react";
3
- import "../bridge-CtB9L5kL.js";
1
+ import { D as o, d as r, e as i, c as n, U as g, V as A, a as t, b as C, o as l, i as I, g as f, h as E, m as _, l as T, k as U, n as p, p as D, r as d, f as L, j as V, s as m, v } from "../helper-CJ3YV3nf.js";
2
+ import "../bridge-K3HqQwdj.js";
4
3
  export {
5
- i as DEFAULT_BASE_URL,
6
- A as DEFAULT_CHAT_MODEL,
7
- r as DEFAULT_CHAT_SYSTEM,
4
+ o as DEFAULT_BASE_URL,
5
+ r as DEFAULT_CHAT_MODEL,
6
+ i as DEFAULT_CHAT_SYSTEM,
8
7
  n as DEFAULT_UI_BASE_URL,
9
- C as UI_CHAT_ENDPOINT,
10
- I as aippyAIProvider,
11
- f as aippyChatConfig,
12
- g as createAIConfig,
8
+ g as UI_CHAT_ENDPOINT,
9
+ A as ViggleGenerationError,
10
+ t as aippyAIProvider,
11
+ C as aippyChatConfig,
12
+ l as createAIConfig,
13
+ I as createViggleRequestId,
14
+ f as generateCharacter3D,
15
+ E as generateMotion,
13
16
  _ as getAIConfigValue,
14
- p as loadAIConfig,
15
- E as normalizeError,
16
- T as parseAIConfig,
17
- U as resolveOpenAIConfig,
18
- t as resolveUIConfig,
19
- l as sendAIConfigToContainer,
20
- D as validateAIConfig
17
+ T as listViggleModels,
18
+ U as loadAIConfig,
19
+ p as normalizeError,
20
+ D as parseAIConfig,
21
+ d as resolveOpenAIConfig,
22
+ L as resolveUIConfig,
23
+ V as resumeViggleGeneration,
24
+ m as sendAIConfigToContainer,
25
+ v as validateAIConfig
21
26
  };
@@ -0,0 +1,67 @@
1
+ import { AISDKError } from 'ai';
2
+ export type ViggleKind = 'character' | 'motion';
3
+ export type ViggleStage = 'authorize' | 'create' | 'poll' | 'resume';
4
+ interface GenerationOptions {
5
+ /** Optional explicit idempotency key. Normal calls manage recovery internally. */
6
+ requestId?: string;
7
+ signal?: AbortSignal;
8
+ }
9
+ export interface GenerateCharacter3DInput extends GenerationOptions {
10
+ image?: Blob;
11
+ imageUrl?: string;
12
+ prompt?: string;
13
+ }
14
+ export interface GenerateMotionInput extends GenerationOptions {
15
+ text: string;
16
+ durationSeconds?: number;
17
+ }
18
+ export interface ResumeViggleGenerationInput extends GenerationOptions {
19
+ jobId: string;
20
+ kind: ViggleKind;
21
+ }
22
+ export interface ViggleAsset {
23
+ url: string;
24
+ thumbnailUrl?: string;
25
+ jobId: string;
26
+ requestId: string;
27
+ kind: ViggleKind;
28
+ /** Prepaid jobs are delivered only after the coupon consume is confirmed. */
29
+ billingState?: string;
30
+ }
31
+ interface Handle {
32
+ requestId?: string;
33
+ jobId?: string;
34
+ jobConfirmed?: boolean;
35
+ kind: ViggleKind;
36
+ stage: ViggleStage;
37
+ persist?: () => void;
38
+ clear?: () => void;
39
+ }
40
+ /** Recovery is automatic on the next call with the same input. Handles remain available for diagnostics and explicit recovery. */
41
+ export declare class ViggleGenerationError extends AISDKError {
42
+ readonly requestId?: string;
43
+ readonly jobId?: string;
44
+ /** True only after the backend confirmed that this job was persisted. */
45
+ readonly jobConfirmed: boolean;
46
+ readonly kind: ViggleKind;
47
+ readonly stage: ViggleStage;
48
+ readonly reason: string;
49
+ readonly httpStatus?: number;
50
+ readonly activeJob?: {
51
+ jobId: string;
52
+ kind: ViggleKind;
53
+ requestId: string;
54
+ sameInput: boolean;
55
+ };
56
+ constructor(message: string, handle: Handle, reason: string, cause?: unknown, httpStatus?: number, activeJob?: ViggleGenerationError['activeJob']);
57
+ }
58
+ /** One key per user action. A retry of the same action must reuse the key. */
59
+ export declare function createViggleRequestId(): string;
60
+ /** Persist a job, use/buy its project ticket, then wait for confirmed fulfillment. */
61
+ export declare function generateCharacter3D(input: GenerateCharacter3DInput): Promise<ViggleAsset>;
62
+ /** Generate a 441-joint GLB motion; quantity is one priced generation coupon. */
63
+ export declare function generateMotion(input: GenerateMotionInput): Promise<ViggleAsset>;
64
+ /** Explicit user action: recover a job with GET only, including consent/recharge. */
65
+ export declare function resumeViggleGeneration(input: ResumeViggleGenerationInput): Promise<ViggleAsset>;
66
+ export declare function viggleScope(signal: AbortSignal): () => void;
67
+ export {};
@@ -0,0 +1,46 @@
1
+ import { ViggleKind } from './generate';
2
+ export interface ListViggleModelsOptions {
3
+ kind?: ViggleKind;
4
+ /** Opaque decimal record ID; keep as a string. */
5
+ cursor?: string;
6
+ /** Raw records per page, 1–50; default 20. Filtered pages can be empty. */
7
+ limit?: number;
8
+ signal?: AbortSignal;
9
+ }
10
+ export interface ViggleModelValue {
11
+ schemaVersion: 1;
12
+ source: 'aisdk.viggle';
13
+ jobId: string;
14
+ provider: 'viggle';
15
+ kind: ViggleKind;
16
+ durationSeconds?: number;
17
+ asset: {
18
+ url: string;
19
+ format: 'vsplat' | 'glb';
20
+ thumbnailUrl?: string;
21
+ };
22
+ generatedAt: string;
23
+ }
24
+ export interface ViggleModel {
25
+ recordId: string;
26
+ benefitKey: string;
27
+ bizOrderNo: string;
28
+ jobId: string;
29
+ kind: ViggleKind;
30
+ url: string;
31
+ thumbnailUrl?: string;
32
+ durationSeconds?: number;
33
+ generatedAt: string;
34
+ consumedAt: string;
35
+ /** Original consumed-item value snapshot; independent of job retention. */
36
+ value: ViggleModelValue;
37
+ }
38
+ export interface ViggleModelsPage {
39
+ models: ViggleModel[];
40
+ nextCursor: string;
41
+ }
42
+ /** Read successful model records for the authenticated user/current project.
43
+ * Product keys are resolved by the backend, including retired products.
44
+ * This call never authorizes, recharges, purchases, generates or consumes.
45
+ */
46
+ export declare function listViggleModels(options?: ListViggleModelsOptions): Promise<ViggleModelsPage>;
@@ -0,0 +1,12 @@
1
+ export interface SavedGeneration {
2
+ requestId: string;
3
+ jobId?: string;
4
+ }
5
+ export declare function inputDigest(input: unknown): Promise<string>;
6
+ /** Hints only: server ownership, input binding, CAS and purchase authorization
7
+ * remain authoritative. Never persist prompts, images, tokens or billing data. */
8
+ export declare function recoveryKey(kind: string, digest: string): string | undefined;
9
+ export declare function readGeneration(key?: string): SavedGeneration | undefined;
10
+ export declare function saveGeneration(key: string | undefined, saved: SavedGeneration): void;
11
+ export declare function clearGeneration(key: string | undefined, requestId: string): void;
12
+ export declare function singleGeneration<T>(key: string | undefined, run: () => Promise<T>, signal: AbortSignal): Promise<T>;
@@ -156,17 +156,18 @@ class A {
156
156
  }
157
157
  }
158
158
  }
159
- const m = new A(), C = { iOS: "1.6.7", Android: "1.1.8" }, k = { iOS: "1.6.7", Android: "1.1.8" }, d = {
159
+ const m = new A(), C = { iOS: "1.6.7", Android: "1.1.8" }, k = { iOS: "1.6.7", Android: "1.1.8" }, P = { iOS: "1.21.0", Android: "1.3.7.0" }, d = {
160
160
  userCredentials: C,
161
- userInfo: k
161
+ userInfo: k,
162
+ ministore: P
162
163
  }, l = "https://cdn.aippy.ai/asset/fd292077086044ee9565bd36ac3a8b78.svg";
163
- function P() {
164
+ function V() {
164
165
  const t = m.parseAippyInfo();
165
166
  if (!t) return !1;
166
167
  const e = d.userCredentials[t.platform];
167
168
  return f(t.version, e) >= 0;
168
169
  }
169
- async function V(t, e = "update") {
170
+ async function _(t, e = "update") {
170
171
  const n = document.createElement("div");
171
172
  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";
172
173
  const r = document.createElement("div");
@@ -181,7 +182,7 @@ async function V(t, e = "update") {
181
182
  const a = document.createElement("img");
182
183
  a.src = l, a.style.cssText = "width:36px;height:36px;flex-shrink:0", r.appendChild(a);
183
184
  }
184
- const i = e === "signin" || e === "update" && P(), p = i ? t.replace(/\n/g, "") : t, s = document.createElement("span");
185
+ const i = e === "signin" || e === "update" && V(), p = i ? t.replace(/\n/g, "") : t, s = document.createElement("span");
185
186
  if (s.style.cssText = "font-size:14px;font-weight:600;color:#fff;line-height:1.4;white-space:pre-line", s.textContent = p, r.appendChild(s), i) {
186
187
  const a = e === "signin" ? "Sign in" : "Update", c = document.createElement("button");
187
188
  c.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", c.textContent = a, c.onclick = () => {
@@ -196,12 +197,12 @@ async function V(t, e = "update") {
196
197
  }
197
198
  n.appendChild(r), document.body.appendChild(n);
198
199
  }
199
- function _(t) {
200
+ function R(t) {
200
201
  const e = d[t];
201
202
  return e || (console.warn(`[AppVersionChecker] Unknown feature: ${t}`), { iOS: "999.0.0", Android: "999.0.0" });
202
203
  }
203
- function R(t) {
204
- const e = _(t), n = m.checkAppEnvironment(e), r = n.aippyInfo?.version, o = n.aippyInfo ? e[n.aippyInfo.platform] : void 0;
204
+ function I(t) {
205
+ const e = R(t), n = m.checkAppEnvironment(e), r = n.aippyInfo?.version, o = n.aippyInfo ? e[n.aippyInfo.platform] : void 0;
205
206
  switch (n.type) {
206
207
  case "new_app":
207
208
  return {
@@ -225,24 +226,24 @@ function R(t) {
225
226
  };
226
227
  }
227
228
  }
228
- function L(t) {
229
- const e = R(t);
229
+ function M(t) {
230
+ const e = I(t);
230
231
  if (!e.supported && (e.envCheck.type === "new_app" || e.envCheck.type === "old_ios_app" || e.envCheck.type === "old_android_app"))
231
- throw console.warn(`[AppVersionChecker] ${e.message}`), V(`This project needs a newer version.
232
+ throw console.warn(`[AppVersionChecker] ${e.message}`), _(`This project needs a newer version.
232
233
  Update to view it.`, "update"), v(`App version too old: ${e.message}`, x.NOT_SUPPORTED);
233
234
  return e;
234
235
  }
235
- function M() {
236
+ function N() {
236
237
  return Object.keys(d);
237
238
  }
238
239
  export {
239
240
  A as P,
240
- R as a,
241
- M as b,
241
+ I as a,
242
+ N as b,
242
243
  f as c,
243
- _ as g,
244
+ R as g,
244
245
  y as i,
245
246
  m as p,
246
- L as r,
247
- V as s
247
+ M as r,
248
+ _ as s
248
249
  };
@@ -0,0 +1,311 @@
1
+ import { a as v } from "./runtime-CmoG3v2m.js";
2
+ import { r as b, s as q, i as w } from "./app-version-checker-YVIFbytA.js";
3
+ import { c as A, a as _ } from "./errors-B3bDbQbD.js";
4
+ const F = ".aippynow.com", k = "https://api.aippy.dev", S = "https://api.aippy.ai";
5
+ function ee(e) {
6
+ return e === k || e === S;
7
+ }
8
+ let p;
9
+ function j() {
10
+ if (p) return p;
11
+ let e = S;
12
+ if (typeof window < "u" && window.location) {
13
+ const n = window.location.hostname;
14
+ (n.endsWith(F) || n === "localhost" || n === "127.0.0.1") && (e = k);
15
+ }
16
+ return p = e, e;
17
+ }
18
+ function ne() {
19
+ p = void 0;
20
+ }
21
+ function I() {
22
+ if (typeof window > "u" || !window.parent || window.parent === window)
23
+ return;
24
+ const e = window.location?.ancestorOrigins?.[0] || (typeof document < "u" ? document.referrer : "");
25
+ if (e)
26
+ try {
27
+ const { origin: n, protocol: t } = new URL(e);
28
+ return t === "https:" || t === "http:" ? n : void 0;
29
+ } catch {
30
+ return;
31
+ }
32
+ }
33
+ function P(e) {
34
+ return !!e.data && typeof e.data == "object" && !Array.isArray(e.data);
35
+ }
36
+ function U(e, n = I()) {
37
+ return typeof window < "u" && !!n && e.source === window.parent && e.origin === n && P(e);
38
+ }
39
+ function N(e) {
40
+ if (typeof window > "u" || !P(e)) return !1;
41
+ const n = window.location?.origin;
42
+ return U(e) || !!n && n !== "null" && e.source === window && e.origin === n;
43
+ }
44
+ const m = {
45
+ apiBaseUrl: `${j()}/api`,
46
+ authToken: "",
47
+ currentUserId: null
48
+ };
49
+ function H(e) {
50
+ Object.assign(m, e);
51
+ }
52
+ function J(e) {
53
+ m.authToken = e;
54
+ }
55
+ function V(e) {
56
+ m.currentUserId = e;
57
+ }
58
+ function te() {
59
+ return m.currentUserId;
60
+ }
61
+ const O = 3e3, L = 50, f = 500, c = { uid: "", token: "" };
62
+ let l = null, h = !1, a = null, u = null;
63
+ function d(e) {
64
+ return !!e && typeof e == "object" && !Array.isArray(e);
65
+ }
66
+ function D(e) {
67
+ return typeof e == "string" && e !== "" ? e : typeof e == "number" && Number.isSafeInteger(e) && e > 0 ? String(e) : null;
68
+ }
69
+ function E(e) {
70
+ if (!d(e)) return null;
71
+ let n = e;
72
+ d(n.credentials) && (n = n.credentials), d(n.user) && n.token && (n = {
73
+ uid: n.user.uid || n.user.userId || n.user.id,
74
+ token: n.token,
75
+ apiBaseUrl: n.apiBaseUrl
76
+ });
77
+ const t = D(n.uid || n.userId || n.id), i = n.token || n.authToken;
78
+ if (!t || typeof i != "string" || i === "") return null;
79
+ const r = typeof n.apiBaseUrl == "string" ? n.apiBaseUrl : void 0, s = { uid: t, token: i, apiBaseUrl: r };
80
+ return V(t), J(i), r && H({ apiBaseUrl: r }), s;
81
+ }
82
+ function T(e) {
83
+ if (!d(e)) return null;
84
+ let n = e;
85
+ d(n.userInfo) && (n = n.userInfo), d(n.user) && (n = n.user);
86
+ const t = D(n.uid || n.userId || n.id);
87
+ if (!t) return null;
88
+ const i = { ...n, uid: t };
89
+ return l = i, h = !0, i;
90
+ }
91
+ function x(e = f) {
92
+ return a ? new Promise((n) => {
93
+ const t = a.resolve;
94
+ a.resolve = (i) => {
95
+ t(i), n(i);
96
+ };
97
+ }) : new Promise((n) => {
98
+ let t, i;
99
+ const r = {
100
+ resolve: (s) => {
101
+ clearTimeout(t), i?.cancel(), a === r && (a = null), n(s);
102
+ }
103
+ };
104
+ a = r, (async () => {
105
+ let s = window.webkit?.messageHandlers?.aippyListener;
106
+ if (s || (s = await M(1500)), a === r) {
107
+ if (!s) {
108
+ r.resolve(c);
109
+ return;
110
+ }
111
+ t = setTimeout(() => r.resolve(c), e), i = v.receiveChannel.once(
112
+ "user.credentials",
113
+ (o) => {
114
+ r.resolve(E(o) || c);
115
+ }
116
+ );
117
+ try {
118
+ s.postMessage({
119
+ command: "user.getCredentials",
120
+ parameters: JSON.stringify({
121
+ timestamp: Date.now(),
122
+ endpoint: "user.credentials"
123
+ })
124
+ });
125
+ } catch {
126
+ r.resolve(c);
127
+ }
128
+ }
129
+ })();
130
+ });
131
+ }
132
+ function z(e = f) {
133
+ return new Promise((n) => {
134
+ const t = I();
135
+ if (!w() || !t) {
136
+ n(c);
137
+ return;
138
+ }
139
+ const i = setTimeout(() => {
140
+ window.removeEventListener("message", r), n(c);
141
+ }, e), r = (s) => {
142
+ if (!U(s, t) || s.data.type !== "user-credentials-response")
143
+ return;
144
+ const o = E(s.data);
145
+ o && (clearTimeout(i), window.removeEventListener("message", r), n(o));
146
+ };
147
+ window.addEventListener("message", r);
148
+ try {
149
+ window.parent.postMessage(
150
+ { type: "user-credentials-request", timestamp: Date.now() },
151
+ t
152
+ );
153
+ } catch {
154
+ clearTimeout(i), window.removeEventListener("message", r), n(c);
155
+ }
156
+ });
157
+ }
158
+ const G = () => /Aippy\/[\d.]+\/\d+\/Android/i.test(navigator.userAgent);
159
+ async function M(e = 1500) {
160
+ if (!G())
161
+ return window.webkit?.messageHandlers?.aippyListener || null;
162
+ const n = Date.now();
163
+ for (; Date.now() - n < e; ) {
164
+ const t = window.webkit?.messageHandlers?.aippyListener;
165
+ if (t) return t;
166
+ await new Promise((i) => setTimeout(i, 50));
167
+ }
168
+ return null;
169
+ }
170
+ function W(e = !1, n = f) {
171
+ return h && l && !e ? Promise.resolve(l) : u ? new Promise((t) => {
172
+ const i = u.resolve;
173
+ u.resolve = (r) => {
174
+ i(r), t(r);
175
+ };
176
+ }) : new Promise((t) => {
177
+ let i, r;
178
+ const s = {
179
+ resolve: (o) => {
180
+ clearTimeout(i), r?.cancel(), u === s && (u = null), t(o);
181
+ }
182
+ };
183
+ u = s, (async () => {
184
+ let o = window.webkit?.messageHandlers?.aippyListener;
185
+ if (o || (o = await M(1500)), u === s) {
186
+ if (!o) {
187
+ s.resolve(null);
188
+ return;
189
+ }
190
+ i = setTimeout(() => s.resolve(null), n), r = v.receiveChannel.once("user.info", (B) => {
191
+ s.resolve(T(B));
192
+ });
193
+ try {
194
+ o.postMessage({
195
+ command: "user.getUserInfo",
196
+ parameters: JSON.stringify({
197
+ timestamp: Date.now(),
198
+ endpoint: "user.info"
199
+ })
200
+ });
201
+ } catch {
202
+ s.resolve(null);
203
+ }
204
+ }
205
+ })();
206
+ });
207
+ }
208
+ function C(e = f) {
209
+ return new Promise((n) => {
210
+ const t = I();
211
+ if (!w() || !t) {
212
+ n(null);
213
+ return;
214
+ }
215
+ const i = setTimeout(() => {
216
+ window.removeEventListener("message", r), n(null);
217
+ }, e), r = (s) => {
218
+ if (!U(s, t) || s.data.type !== "user-info-response")
219
+ return;
220
+ const o = T(s.data);
221
+ o && (clearTimeout(i), window.removeEventListener("message", r), n(o));
222
+ };
223
+ window.addEventListener("message", r);
224
+ try {
225
+ window.parent.postMessage(
226
+ { type: "user-info-request", timestamp: Date.now() },
227
+ t
228
+ );
229
+ } catch {
230
+ clearTimeout(i), window.removeEventListener("message", r), n(null);
231
+ }
232
+ });
233
+ }
234
+ async function R() {
235
+ const { envCheck: e } = b("userCredentials");
236
+ switch (e.type) {
237
+ case "new_app": {
238
+ const n = await x(O);
239
+ if (!n?.token)
240
+ throw A(
241
+ "Token unavailable in app",
242
+ _.PERMISSION_DENIED
243
+ );
244
+ return n.token;
245
+ }
246
+ case "iframe": {
247
+ const n = await z(L);
248
+ if (n?.token) return n.token;
249
+ throw q(
250
+ "Sign in to continue.Open this project in the app.",
251
+ "signin"
252
+ ), A(
253
+ "Token unavailable: User needs to login",
254
+ _.PERMISSION_DENIED
255
+ );
256
+ }
257
+ default:
258
+ return "";
259
+ }
260
+ }
261
+ async function X(e = !1) {
262
+ if (h && l && !e)
263
+ return l;
264
+ const { envCheck: n } = b("userInfo");
265
+ switch (n.type) {
266
+ case "new_app":
267
+ return await W(e, O);
268
+ case "iframe":
269
+ return await C(L);
270
+ default:
271
+ return l;
272
+ }
273
+ }
274
+ async function Y(e = f) {
275
+ return w() ? await C(e) : null;
276
+ }
277
+ function g(e) {
278
+ const n = E(e);
279
+ n && a && (a.resolve(n), a = null);
280
+ }
281
+ function y(e) {
282
+ const n = T(e);
283
+ u && (u.resolve(n), u = null);
284
+ }
285
+ function $() {
286
+ typeof window > "u" || (window.processUserCredentials = g, window.processUserInfo = y, window.addEventListener("message", (e) => {
287
+ N(e) && (e.data.type === "user-credentials" && g(e.data), e.data.type === "user-info" && y(e.data));
288
+ }));
289
+ }
290
+ $();
291
+ R().catch(() => {
292
+ });
293
+ const re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
294
+ __proto__: null,
295
+ getAuthTokenAsync: R,
296
+ getUserInfoAsync: X,
297
+ getUserInfoFromParent: Y,
298
+ isInIframe: w,
299
+ processUserCredentials: g,
300
+ processUserInfo: y
301
+ }, Symbol.toStringTag, { value: "Module" }));
302
+ export {
303
+ ne as _,
304
+ I as a,
305
+ ee as b,
306
+ te as c,
307
+ re as d,
308
+ R as g,
309
+ U as i,
310
+ j as r
311
+ };