@aippy/runtime 0.2.6 → 0.2.7-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/ai/config/bridge.d.ts +23 -0
- package/dist/ai/config/helper.d.ts +43 -0
- package/dist/ai/config/index.d.ts +11 -0
- package/dist/ai/config/parser.d.ts +60 -0
- package/dist/ai/config/types.d.ts +80 -0
- package/dist/ai/errors.d.ts +25 -0
- package/dist/ai/index.d.ts +46 -0
- package/dist/ai/index.js +25 -0
- package/dist/ai/openai/index.d.ts +11 -0
- package/dist/ai/openai/provider.d.ts +51 -0
- package/dist/ai/shared/config.d.ts +54 -0
- package/dist/ai/shared/fetch.d.ts +28 -0
- package/dist/ai/shared/index.d.ts +6 -0
- package/dist/ai/ui/config.d.ts +25 -0
- package/dist/ai/ui/endpoints.d.ts +12 -0
- package/dist/ai/ui/index.d.ts +13 -0
- package/dist/ai/ui/types.d.ts +21 -0
- package/dist/ai.d.ts +2 -0
- package/dist/bridge-D2d8hnO_.js +395 -0
- package/dist/container-message-DGrno17o.js +31 -0
- package/dist/core/container-message.d.ts +81 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +21 -18
- package/dist/core/native-bridge.d.ts +9 -0
- package/dist/device/index.js +121 -129
- package/dist/device/sensors.d.ts +5 -1
- package/dist/errors-CDEBaBxB.js +26 -0
- package/dist/helper-CRGxnlsu.js +261 -0
- package/dist/index/index.js +113 -52
- package/dist/index.d.ts +2 -0
- package/dist/native-bridge-BnvipFJc.js +6 -0
- package/dist/{runtime-DjBdOttl.js → runtime-CmoG3v2m.js} +55 -76
- package/dist/user/api.d.ts +9 -0
- package/dist/user/bridge.d.ts +162 -0
- package/dist/user/config.d.ts +21 -0
- package/dist/user/hooks.d.ts +74 -0
- package/dist/user/index.d.ts +12 -0
- package/dist/user/index.js +38 -0
- package/dist/user/types.d.ts +113 -0
- package/dist/user/userSessionInfo.d.ts +6 -0
- package/dist/user.d.ts +2 -0
- package/dist/userSessionInfo-SbuNZ7JR.js +229 -0
- package/package.json +50 -36
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { a as h } from "./runtime-CmoG3v2m.js";
|
|
2
|
+
import { hasNativeBridge as I } from "./native-bridge-BnvipFJc.js";
|
|
3
|
+
const v = {
|
|
4
|
+
apiBaseUrl: "https://api.aippy.dev/api",
|
|
5
|
+
authToken: "",
|
|
6
|
+
// 默认为空,由 iOS 桥接填充
|
|
7
|
+
currentUserId: null,
|
|
8
|
+
// 默认为空,由 iOS 桥接填充
|
|
9
|
+
cacheTime: 300 * 1e3
|
|
10
|
+
// 5 minutes
|
|
11
|
+
};
|
|
12
|
+
let p = { ...v };
|
|
13
|
+
function M(r) {
|
|
14
|
+
p = {
|
|
15
|
+
...v,
|
|
16
|
+
...r
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function Y() {
|
|
20
|
+
return p;
|
|
21
|
+
}
|
|
22
|
+
function k(r) {
|
|
23
|
+
p.authToken = r;
|
|
24
|
+
}
|
|
25
|
+
function C(r) {
|
|
26
|
+
p.currentUserId = r;
|
|
27
|
+
}
|
|
28
|
+
function Q() {
|
|
29
|
+
return p.authToken;
|
|
30
|
+
}
|
|
31
|
+
const c = {
|
|
32
|
+
uid: "",
|
|
33
|
+
token: "",
|
|
34
|
+
apiBaseUrl: void 0
|
|
35
|
+
}, m = 5e3;
|
|
36
|
+
let g = !1, y = !1, d = null, u = null, U = !1, a = null, l = null;
|
|
37
|
+
function f() {
|
|
38
|
+
try {
|
|
39
|
+
return typeof window < "u" && window.parent !== window;
|
|
40
|
+
} catch {
|
|
41
|
+
return !0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function q(r = m) {
|
|
45
|
+
return new Promise((e) => {
|
|
46
|
+
if (!f()) {
|
|
47
|
+
console.log("ℹ️ [UserSDK Bridge] Not in iframe, skipping parent request"), e(c);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
console.log("📤 [UserSDK Bridge] Requesting credentials from parent window");
|
|
51
|
+
const s = setTimeout(() => {
|
|
52
|
+
console.warn(`⚠️ [UserSDK Bridge] Parent request timeout (${r}ms)`), window.removeEventListener("message", n), e(c);
|
|
53
|
+
}, r), n = (o) => {
|
|
54
|
+
if (o.data && o.data.type === "user-credentials-response") {
|
|
55
|
+
console.log("📩 [UserSDK Bridge] Received credentials from parent:", o.data), clearTimeout(s), window.removeEventListener("message", n);
|
|
56
|
+
const t = B(o.data);
|
|
57
|
+
e(t || c);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener("message", n);
|
|
61
|
+
try {
|
|
62
|
+
window.parent.postMessage({
|
|
63
|
+
type: "user-credentials-request",
|
|
64
|
+
timestamp: Date.now()
|
|
65
|
+
}, "*");
|
|
66
|
+
} catch (o) {
|
|
67
|
+
console.error("❌ [UserSDK Bridge] Failed to send request to parent:", o), clearTimeout(s), window.removeEventListener("message", n), e(c);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function T(r = m) {
|
|
72
|
+
return new Promise((e) => {
|
|
73
|
+
if (!f()) {
|
|
74
|
+
console.log("ℹ️ [UserSDK Bridge] Not in iframe, skipping parent user info request"), e(null);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.log("📤 [UserSDK Bridge] Requesting user info from parent window");
|
|
78
|
+
const s = setTimeout(() => {
|
|
79
|
+
console.warn(`⚠️ [UserSDK Bridge] Parent user info request timeout (${r}ms)`), window.removeEventListener("message", n), e(null);
|
|
80
|
+
}, r), n = (o) => {
|
|
81
|
+
if (o.data && o.data.type === "user-info-response") {
|
|
82
|
+
console.log("📩 [UserSDK Bridge] Received user info from parent:", o.data), clearTimeout(s), window.removeEventListener("message", n);
|
|
83
|
+
const t = K(o.data);
|
|
84
|
+
e(t);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
window.addEventListener("message", n);
|
|
88
|
+
try {
|
|
89
|
+
window.parent.postMessage({
|
|
90
|
+
type: "user-info-request",
|
|
91
|
+
timestamp: Date.now()
|
|
92
|
+
}, "*");
|
|
93
|
+
} catch (o) {
|
|
94
|
+
console.error("❌ [UserSDK Bridge] Failed to send user info request to parent:", o), clearTimeout(s), window.removeEventListener("message", n), e(null);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function b() {
|
|
99
|
+
if (!f())
|
|
100
|
+
return null;
|
|
101
|
+
try {
|
|
102
|
+
const r = window.parent.localStorage.getItem("token"), e = window.parent.localStorage.getItem("user");
|
|
103
|
+
if (!r || !e)
|
|
104
|
+
return console.log("ℹ️ [UserSDK Bridge] Parent localStorage credentials not found"), null;
|
|
105
|
+
const s = JSON.parse(e), n = s.uid || s.userId || s.id || "";
|
|
106
|
+
if (!n)
|
|
107
|
+
return console.warn("⚠️ [UserSDK Bridge] Parent user data missing uid"), null;
|
|
108
|
+
const o = {
|
|
109
|
+
uid: String(n),
|
|
110
|
+
token: r,
|
|
111
|
+
apiBaseUrl: void 0
|
|
112
|
+
};
|
|
113
|
+
return C(o.uid), k(o.token), console.log("✅ [UserSDK Bridge] Got credentials from parent localStorage:", o.uid), d = o, g = !0, o;
|
|
114
|
+
} catch {
|
|
115
|
+
return console.log("ℹ️ [UserSDK Bridge] Cannot access parent localStorage (cross-origin), will use postMessage"), null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function P() {
|
|
119
|
+
if (!f())
|
|
120
|
+
return null;
|
|
121
|
+
try {
|
|
122
|
+
const r = window.parent.localStorage.getItem("user");
|
|
123
|
+
if (!r)
|
|
124
|
+
return console.log("ℹ️ [UserSDK Bridge] Parent localStorage user not found"), null;
|
|
125
|
+
const e = JSON.parse(r), s = e.uid || e.userId || e.id || "";
|
|
126
|
+
if (!s)
|
|
127
|
+
return console.warn("⚠️ [UserSDK Bridge] Parent user data missing uid"), null;
|
|
128
|
+
const n = {
|
|
129
|
+
uid: String(s),
|
|
130
|
+
avatar: e.avatar || e.photoUrl || e.avatarUrl || "",
|
|
131
|
+
nickName: e.nickName || e.nickname || e.displayName || "",
|
|
132
|
+
username: e.username || e.userName || "",
|
|
133
|
+
displayName: e.displayName || e.nickName || "",
|
|
134
|
+
email: e.email || "",
|
|
135
|
+
phone: e.phone || "",
|
|
136
|
+
bio: e.bio || "",
|
|
137
|
+
online: e.online || e.isOnline || !1
|
|
138
|
+
};
|
|
139
|
+
return console.log("✅ [UserSDK Bridge] Got user info from parent localStorage (fresh):", n.uid), n;
|
|
140
|
+
} catch {
|
|
141
|
+
return console.log("ℹ️ [UserSDK Bridge] Cannot access parent localStorage (cross-origin), will use postMessage"), null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function R(r = m) {
|
|
145
|
+
return g && d ? (console.log("✅ [UserSDK Bridge] Returning cached credentials"), Promise.resolve(d)) : y && !g ? (console.log("ℹ️ [UserSDK Bridge] Previous request failed, returning empty credentials"), Promise.resolve(c)) : a ? (console.log("⏳ [UserSDK Bridge] Request already pending, waiting..."), new Promise((e) => {
|
|
146
|
+
const s = a.resolve;
|
|
147
|
+
a.resolve = (n) => {
|
|
148
|
+
s(n), e(n);
|
|
149
|
+
};
|
|
150
|
+
})) : new Promise((e) => {
|
|
151
|
+
y = !0;
|
|
152
|
+
const s = window.webkit?.messageHandlers?.aippyListener;
|
|
153
|
+
if (!s) {
|
|
154
|
+
console.warn("⚠️ [UserSDK Bridge] Native bridge not available, returning empty credentials"), e(c);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const n = setTimeout(() => {
|
|
158
|
+
console.warn(`⚠️ [UserSDK Bridge] Request timeout (${r}ms), returning empty credentials`), a = null, e(c);
|
|
159
|
+
}, r);
|
|
160
|
+
a = { resolve: e, reject: () => {
|
|
161
|
+
} };
|
|
162
|
+
const o = h.receiveChannel.once("user.credentials", (t) => {
|
|
163
|
+
console.log("📩 [UserSDK Bridge] Received credentials via receiveChannel:", t), clearTimeout(n);
|
|
164
|
+
const i = B(t);
|
|
165
|
+
i ? a?.resolve(i) : a?.resolve(c), a = null;
|
|
166
|
+
});
|
|
167
|
+
try {
|
|
168
|
+
const t = {
|
|
169
|
+
command: "user.getCredentials",
|
|
170
|
+
parameters: JSON.stringify({
|
|
171
|
+
timestamp: Date.now(),
|
|
172
|
+
endpoint: "user.credentials"
|
|
173
|
+
// Tell iOS which endpoint to respond to
|
|
174
|
+
})
|
|
175
|
+
};
|
|
176
|
+
console.log("📤 [UserSDK Bridge] Requesting credentials from iOS:", t), s.postMessage(t);
|
|
177
|
+
} catch (t) {
|
|
178
|
+
console.error("❌ [UserSDK Bridge] Failed to send request to iOS:", t), clearTimeout(n), o.cancel(), a = null, e(c);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
function B(r) {
|
|
183
|
+
if (!r || typeof r != "object")
|
|
184
|
+
return console.warn("⚠️ [UserSDK Bridge] Invalid credentials data:", r), null;
|
|
185
|
+
let e = r;
|
|
186
|
+
if (e.credentials && typeof e.credentials == "object" && (console.log("📦 [UserSDK Bridge] Detected nested credentials format"), e = e.credentials), e.user && typeof e.user == "object" && e.token) {
|
|
187
|
+
console.log("📦 [UserSDK Bridge] Detected parent window format");
|
|
188
|
+
const i = e.user;
|
|
189
|
+
e = {
|
|
190
|
+
uid: i.uid || i.userId || i.id,
|
|
191
|
+
token: e.token,
|
|
192
|
+
apiBaseUrl: e.apiBaseUrl
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const s = e.uid || e.userId || e.id || "", n = e.token || e.authToken || "", o = e.apiBaseUrl || e.baseUrl;
|
|
196
|
+
if (!s || !n)
|
|
197
|
+
return console.warn("⚠️ [UserSDK Bridge] Missing uid or token in credentials:", r), null;
|
|
198
|
+
const t = { uid: String(s), token: n, apiBaseUrl: o };
|
|
199
|
+
return C(t.uid), k(n), o && M({ apiBaseUrl: o }), console.log("✅ [UserSDK Bridge] Config updated with credentials:", t.uid), d = t, g = !0, t;
|
|
200
|
+
}
|
|
201
|
+
function w(r) {
|
|
202
|
+
console.log("📩 [UserSDK Bridge] processUserCredentials called with:", r);
|
|
203
|
+
const e = B(r);
|
|
204
|
+
e && a && (a.resolve(e), a = null);
|
|
205
|
+
}
|
|
206
|
+
function K(r) {
|
|
207
|
+
if (!r || typeof r != "object")
|
|
208
|
+
return console.warn("⚠️ [UserSDK Bridge] Invalid user info data:", r), null;
|
|
209
|
+
let e = r;
|
|
210
|
+
e.userInfo && typeof e.userInfo == "object" && (console.log("📦 [UserSDK Bridge] Detected nested userInfo format"), e = e.userInfo), e.user && typeof e.user == "object" && (console.log("📦 [UserSDK Bridge] Detected nested user format"), e = e.user);
|
|
211
|
+
const s = e.uid || e.userId || e.id || "";
|
|
212
|
+
if (!s)
|
|
213
|
+
return console.warn("⚠️ [UserSDK Bridge] Missing uid in user info:", r), null;
|
|
214
|
+
const n = {
|
|
215
|
+
uid: String(s),
|
|
216
|
+
displayName: e.displayName,
|
|
217
|
+
nickname: e.nickname,
|
|
218
|
+
username: e.username,
|
|
219
|
+
photoUrl: e.photoUrl,
|
|
220
|
+
avatar: e.avatar,
|
|
221
|
+
email: e.email,
|
|
222
|
+
phone: e.phone,
|
|
223
|
+
bio: e.bio,
|
|
224
|
+
online: e.online,
|
|
225
|
+
...e
|
|
226
|
+
};
|
|
227
|
+
return console.log("✅ [UserSDK Bridge] Processed user info:", n.uid), u = n, U = !0, n;
|
|
228
|
+
}
|
|
229
|
+
function D(r) {
|
|
230
|
+
console.log("📩 [UserSDK Bridge] processUserInfo called with:", r);
|
|
231
|
+
const e = K(r);
|
|
232
|
+
e && l && (l.resolve(e), l = null);
|
|
233
|
+
}
|
|
234
|
+
function N(r = !1, e = m) {
|
|
235
|
+
return U && u && !r ? (console.log("✅ [UserSDK Bridge] Returning cached user info"), Promise.resolve(u)) : l ? (console.log("⏳ [UserSDK Bridge] User info request already pending, waiting..."), new Promise((s) => {
|
|
236
|
+
const n = l.resolve;
|
|
237
|
+
l.resolve = (o) => {
|
|
238
|
+
n(o), s(o);
|
|
239
|
+
};
|
|
240
|
+
})) : new Promise((s) => {
|
|
241
|
+
const n = window.webkit?.messageHandlers?.aippyListener;
|
|
242
|
+
if (!n) {
|
|
243
|
+
console.warn("⚠️ [UserSDK Bridge] Native bridge not available, cannot get user info"), s(null);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const o = setTimeout(() => {
|
|
247
|
+
console.warn(`⚠️ [UserSDK Bridge] User info request timeout (${e}ms)`), l = null, s(null);
|
|
248
|
+
}, e);
|
|
249
|
+
l = { resolve: s, reject: () => {
|
|
250
|
+
} };
|
|
251
|
+
const t = h.receiveChannel.once("user.info", (i) => {
|
|
252
|
+
console.log("📩 [UserSDK Bridge] Received user info via receiveChannel:", i), clearTimeout(o);
|
|
253
|
+
const L = K(i);
|
|
254
|
+
l?.resolve(L), l = null;
|
|
255
|
+
});
|
|
256
|
+
try {
|
|
257
|
+
const i = {
|
|
258
|
+
command: "user.getUserInfo",
|
|
259
|
+
parameters: JSON.stringify({
|
|
260
|
+
timestamp: Date.now(),
|
|
261
|
+
endpoint: "user.info"
|
|
262
|
+
// Tell iOS which endpoint to respond to
|
|
263
|
+
})
|
|
264
|
+
};
|
|
265
|
+
console.log("📤 [UserSDK Bridge] Requesting user info from iOS:", i), n.postMessage(i);
|
|
266
|
+
} catch (i) {
|
|
267
|
+
console.error("❌ [UserSDK Bridge] Failed to send user info request to iOS:", i), clearTimeout(o), t.cancel(), l = null, s(null);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
async function E(r = !1) {
|
|
272
|
+
return U && u && !r ? u : I() ? await N(r) : u;
|
|
273
|
+
}
|
|
274
|
+
async function j(r = m) {
|
|
275
|
+
if (!f())
|
|
276
|
+
return console.log("ℹ️ [UserSDK Bridge] Not in iframe, cannot get user info from parent"), null;
|
|
277
|
+
console.log("🔍 [UserSDK Bridge] Getting fresh user info from parent (no cache)");
|
|
278
|
+
const e = P();
|
|
279
|
+
if (e)
|
|
280
|
+
return console.log("✅ [UserSDK Bridge] Got fresh user info from parent localStorage"), e;
|
|
281
|
+
console.log("🔍 [UserSDK Bridge] Trying postMessage to parent for user info");
|
|
282
|
+
const s = await T(r);
|
|
283
|
+
return s ? (console.log("✅ [UserSDK Bridge] Got fresh user info from parent postMessage"), s) : (console.log("⚠️ [UserSDK Bridge] Could not get user info from parent"), null);
|
|
284
|
+
}
|
|
285
|
+
function F() {
|
|
286
|
+
return u;
|
|
287
|
+
}
|
|
288
|
+
function A() {
|
|
289
|
+
return U;
|
|
290
|
+
}
|
|
291
|
+
function G() {
|
|
292
|
+
u = null, U = !1, console.log("🧹 [UserSDK Bridge] Cleared cached user info");
|
|
293
|
+
}
|
|
294
|
+
function O() {
|
|
295
|
+
typeof window > "u" || (window.processUserCredentials = w, window.processUserInfo = D, window.addEventListener("message", (r) => {
|
|
296
|
+
r.data && r.data.type === "user-credentials" && (console.log("📩 [UserSDK Bridge] Received credentials via postMessage:", r.data), w(r.data)), r.data && r.data.type === "user-info" && (console.log("📩 [UserSDK Bridge] Received user info via postMessage:", r.data), D(r.data)), r.data && r.data.type === "user-info-response" && console.log("📩 [UserSDK Bridge] Received user info response from parent");
|
|
297
|
+
}), console.log("✅ [UserSDK Bridge] Bridge initialized"));
|
|
298
|
+
}
|
|
299
|
+
async function S() {
|
|
300
|
+
if (g && d) {
|
|
301
|
+
console.log("✅ [UserSDK Bridge] Already have cached credentials");
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (I()) {
|
|
305
|
+
console.log("🔍 [UserSDK Bridge] Detected iOS environment, requesting from native");
|
|
306
|
+
try {
|
|
307
|
+
if (await R(), g) {
|
|
308
|
+
console.log("✅ [UserSDK Bridge] Got credentials from iOS");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
} catch (r) {
|
|
312
|
+
console.warn("⚠️ [UserSDK Bridge] iOS request failed:", r);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (f()) {
|
|
316
|
+
if (console.log("🔍 [UserSDK Bridge] Detected iframe environment"), b()) {
|
|
317
|
+
console.log("✅ [UserSDK Bridge] Got credentials from parent localStorage");
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
console.log("🔍 [UserSDK Bridge] Trying postMessage to parent");
|
|
321
|
+
try {
|
|
322
|
+
const e = await q();
|
|
323
|
+
if (e.uid && e.token) {
|
|
324
|
+
console.log("✅ [UserSDK Bridge] Got credentials from parent postMessage");
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
} catch (e) {
|
|
328
|
+
console.warn("⚠️ [UserSDK Bridge] Parent postMessage request failed:", e);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
console.log("ℹ️ [UserSDK Bridge] No credentials source available");
|
|
332
|
+
}
|
|
333
|
+
async function _() {
|
|
334
|
+
return await S(), d?.token || "";
|
|
335
|
+
}
|
|
336
|
+
async function H() {
|
|
337
|
+
return await S(), d?.uid || "";
|
|
338
|
+
}
|
|
339
|
+
function J() {
|
|
340
|
+
return g;
|
|
341
|
+
}
|
|
342
|
+
function $() {
|
|
343
|
+
return d;
|
|
344
|
+
}
|
|
345
|
+
O();
|
|
346
|
+
S();
|
|
347
|
+
const V = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
348
|
+
__proto__: null,
|
|
349
|
+
autoRequestCredentials: S,
|
|
350
|
+
clearCachedUserInfo: G,
|
|
351
|
+
getAuthTokenAsync: _,
|
|
352
|
+
getCachedCredentials: $,
|
|
353
|
+
getCachedUserInfo: F,
|
|
354
|
+
getCurrentUserIdAsync: H,
|
|
355
|
+
getUserInfoAsync: E,
|
|
356
|
+
getUserInfoFromParent: j,
|
|
357
|
+
hasCredentials: J,
|
|
358
|
+
hasUserInfo: A,
|
|
359
|
+
initUserBridge: O,
|
|
360
|
+
isInIframe: f,
|
|
361
|
+
processUserCredentials: w,
|
|
362
|
+
processUserInfo: D,
|
|
363
|
+
requestCredentialsFromParent: q,
|
|
364
|
+
requestCredentialsFromiOS: R,
|
|
365
|
+
requestUserInfoFromParent: T,
|
|
366
|
+
requestUserInfoFromiOS: N,
|
|
367
|
+
tryGetCredentialsFromParentStorage: b,
|
|
368
|
+
tryGetUserInfoFromParentStorage: P
|
|
369
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
370
|
+
export {
|
|
371
|
+
C as a,
|
|
372
|
+
Q as b,
|
|
373
|
+
f as c,
|
|
374
|
+
q as d,
|
|
375
|
+
O as e,
|
|
376
|
+
S as f,
|
|
377
|
+
Y as g,
|
|
378
|
+
_ as h,
|
|
379
|
+
M as i,
|
|
380
|
+
H as j,
|
|
381
|
+
J as k,
|
|
382
|
+
$ as l,
|
|
383
|
+
N as m,
|
|
384
|
+
E as n,
|
|
385
|
+
F as o,
|
|
386
|
+
A as p,
|
|
387
|
+
G as q,
|
|
388
|
+
R as r,
|
|
389
|
+
k as s,
|
|
390
|
+
b as t,
|
|
391
|
+
T as u,
|
|
392
|
+
P as v,
|
|
393
|
+
j as w,
|
|
394
|
+
V as x
|
|
395
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function o(n) {
|
|
2
|
+
if (!(typeof window > "u"))
|
|
3
|
+
try {
|
|
4
|
+
const s = window.webkit?.messageHandlers?.aippyListener;
|
|
5
|
+
if (s)
|
|
6
|
+
try {
|
|
7
|
+
const e = {
|
|
8
|
+
command: "container.message",
|
|
9
|
+
parameters: n
|
|
10
|
+
};
|
|
11
|
+
s.postMessage(e), console.log("📤 [Container Message] Sent message to iOS app container:", n);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.warn("❌ [Container Message] Failed to send message to iOS app:", e);
|
|
14
|
+
}
|
|
15
|
+
if (window.parent && window.parent !== window)
|
|
16
|
+
try {
|
|
17
|
+
const e = {
|
|
18
|
+
type: "container.message",
|
|
19
|
+
data: n
|
|
20
|
+
};
|
|
21
|
+
window.parent.postMessage(e, "*"), console.log("📤 [Container Message] Sent message to parent window:", n);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.warn("❌ [Container Message] Failed to send message to parent window:", e);
|
|
24
|
+
}
|
|
25
|
+
} catch (s) {
|
|
26
|
+
console.warn("⚠️ [Container Message] Failed to send message:", s);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
o as s
|
|
31
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container message reporter for sending messages to app container
|
|
3
|
+
*
|
|
4
|
+
* This module provides a unified way to send any type of message (errors, success,
|
|
5
|
+
* warnings, info) to the app container so it can display appropriate UI (e.g., popup,
|
|
6
|
+
* dialog, toast notification).
|
|
7
|
+
*
|
|
8
|
+
* Common use cases:
|
|
9
|
+
* - Error messages requiring user action (e.g., insufficient balance, account issues)
|
|
10
|
+
* - Success notifications (e.g., payment completed, settings saved)
|
|
11
|
+
* - Warning messages (e.g., quota approaching limit)
|
|
12
|
+
* - Information messages (e.g., feature announcements)
|
|
13
|
+
*
|
|
14
|
+
* The SDK does not process or filter messages - it simply forwards whatever message data
|
|
15
|
+
* the backend provides. The backend should include a flag or field indicating that
|
|
16
|
+
* the message should be reported to the container.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { sendMessageToContainer } from '@aippy/runtime/core';
|
|
21
|
+
*
|
|
22
|
+
* // Report error message
|
|
23
|
+
* try {
|
|
24
|
+
* await someAPICall();
|
|
25
|
+
* } catch (error) {
|
|
26
|
+
* if (error.containerMessage) {
|
|
27
|
+
* sendMessageToContainer(error.containerMessage);
|
|
28
|
+
* }
|
|
29
|
+
* throw error;
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Report success message
|
|
33
|
+
* const response = await paymentAPI();
|
|
34
|
+
* if (response.containerMessage) {
|
|
35
|
+
* sendMessageToContainer(response.containerMessage);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Sends a message to the app container (iOS WebView or iframe parent)
|
|
41
|
+
*
|
|
42
|
+
* Supports two scenarios:
|
|
43
|
+
* - iOS WebView: Uses `webkit.messageHandlers.aippyListener.postMessage()`
|
|
44
|
+
* - Iframe: Uses `window.parent.postMessage()`
|
|
45
|
+
*
|
|
46
|
+
* The message data structure is determined by the backend API or caller. The SDK simply
|
|
47
|
+
* forwards it without modification. The container will interpret the message and display
|
|
48
|
+
* appropriate UI (e.g., error dialog, success toast, warning banner).
|
|
49
|
+
*
|
|
50
|
+
* @param messageData - Message data to send (structure defined by backend/caller)
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* // Error message
|
|
55
|
+
* sendMessageToContainer({
|
|
56
|
+
* type: 'error',
|
|
57
|
+
* title: 'Insufficient Balance',
|
|
58
|
+
* message: 'Your account balance is insufficient. Please top up to continue.',
|
|
59
|
+
* action: 'showPaymentDialog',
|
|
60
|
+
* redirectUrl: '/payment',
|
|
61
|
+
* buttonText: 'Top Up Now'
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // Success message
|
|
65
|
+
* sendMessageToContainer({
|
|
66
|
+
* type: 'success',
|
|
67
|
+
* title: 'Payment Successful',
|
|
68
|
+
* message: 'Your top-up has been completed successfully.',
|
|
69
|
+
* duration: 3000
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Warning message
|
|
73
|
+
* sendMessageToContainer({
|
|
74
|
+
* type: 'warning',
|
|
75
|
+
* title: 'Quota Running Low',
|
|
76
|
+
* message: 'You have 10 requests remaining this month.',
|
|
77
|
+
* action: 'showUpgradeDialog'
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function sendMessageToContainer(messageData: unknown): void;
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as d, E as v, c as m } from "../errors-CDEBaBxB.js";
|
|
2
|
+
import { s as A } from "../container-message-DGrno17o.js";
|
|
3
|
+
import { A as g, C as R, R as I, a as P, p as l } from "../runtime-CmoG3v2m.js";
|
|
2
4
|
const s = {
|
|
3
5
|
mode: "development",
|
|
4
6
|
debug: !1,
|
|
@@ -9,7 +11,7 @@ function o() {
|
|
|
9
11
|
const e = {};
|
|
10
12
|
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;
|
|
11
13
|
}
|
|
12
|
-
function
|
|
14
|
+
function p(e) {
|
|
13
15
|
const n = o();
|
|
14
16
|
return {
|
|
15
17
|
...s,
|
|
@@ -22,29 +24,30 @@ function c(e) {
|
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
|
-
const r = "0.2.
|
|
27
|
+
const r = "0.2.7-dev.1", a = {
|
|
26
28
|
version: r
|
|
27
|
-
},
|
|
28
|
-
function
|
|
29
|
+
}, t = a.version, i = "@aippy/runtime";
|
|
30
|
+
function c() {
|
|
29
31
|
return {
|
|
30
|
-
name:
|
|
31
|
-
version:
|
|
32
|
+
name: i,
|
|
33
|
+
version: t,
|
|
32
34
|
buildTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
export {
|
|
36
|
-
|
|
38
|
+
g as AippyRuntime,
|
|
37
39
|
d as AippyRuntimeError,
|
|
38
|
-
|
|
40
|
+
R as Cancellable,
|
|
39
41
|
s as DEFAULT_CONFIG,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
v as ERROR_CODES,
|
|
43
|
+
I as ReceiveChannel,
|
|
44
|
+
i as SDK_NAME,
|
|
45
|
+
t as VERSION,
|
|
46
|
+
P as aippyRuntime,
|
|
47
|
+
m as createError,
|
|
46
48
|
o as getConfigFromEnv,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
c as getVersionInfo,
|
|
50
|
+
p as mergeConfig,
|
|
51
|
+
l as processMotionData,
|
|
52
|
+
A as sendMessageToContainer
|
|
50
53
|
};
|