@aippy/runtime 0.2.7-dev.0 → 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.
@@ -1,186 +0,0 @@
1
- import { useState as s, useEffect as y, useCallback as h } from "react";
2
- import { g as m, b as E } from "./bridge-DdAH4txB.js";
3
- const U = /* @__PURE__ */ new Map();
4
- async function S(e) {
5
- const t = m(), n = U.get(e);
6
- if (n && Date.now() - n.timestamp < (t.cacheTime || 3e5))
7
- return n.data;
8
- try {
9
- const r = await fetch(
10
- `${t.apiBaseUrl}/user/profile?targetUid=${e}`,
11
- {
12
- method: "GET",
13
- headers: {
14
- Authorization: `Bearer ${t.authToken}`,
15
- "Content-Type": "application/json"
16
- }
17
- }
18
- );
19
- if (!r.ok)
20
- throw new Error(`Failed to fetch user profile: ${r.status}`);
21
- const a = await r.json(), o = M(a, e);
22
- return U.set(e, { data: o, timestamp: Date.now() }), o;
23
- } catch (r) {
24
- return console.error("[UserSDK] Failed to fetch user profile:", r), null;
25
- }
26
- }
27
- function M(e, t) {
28
- const n = typeof e == "object" && e !== null ? e : {}, r = n.data || n.user || n;
29
- return {
30
- id: r.id || r.uid || t,
31
- displayName: r.displayName || r.nickname || r.name || "Unknown User",
32
- username: r.username || r.id || t,
33
- photoUrl: r.photoUrl || r.avatar || r.avatarUrl,
34
- online: r.online ?? !1,
35
- bio: r.bio,
36
- coverImageUrl: r.coverImageUrl,
37
- ...r
38
- };
39
- }
40
- function w(e) {
41
- e ? U.delete(e) : U.clear();
42
- }
43
- function I() {
44
- const [e, t] = s(
45
- m().currentUserId
46
- );
47
- return y(() => {
48
- t(m().currentUserId);
49
- }, []), e;
50
- }
51
- function T() {
52
- const [e, t] = s(E());
53
- return y(() => {
54
- t(E());
55
- }, []), e;
56
- }
57
- function b() {
58
- const e = I(), [t, n] = s(null), [r, a] = s(!0), [o, u] = s(!1), [g, f] = s(null), i = h(async () => {
59
- if (!e) {
60
- n(null), a(!1);
61
- return;
62
- }
63
- a(!0), u(!1), f(null);
64
- try {
65
- const c = await S(e);
66
- n(c);
67
- } catch (c) {
68
- u(!0), f(c instanceof Error ? c : new Error(String(c)));
69
- } finally {
70
- a(!1);
71
- }
72
- }, [e]);
73
- y(() => {
74
- i();
75
- }, [i]);
76
- const l = h(async () => {
77
- e && w(e), await i();
78
- }, [e, i]);
79
- return { data: t, isLoading: r, isError: o, error: g, refetch: l };
80
- }
81
- function A(e) {
82
- const { id: t } = e, [n, r] = s(null), [a, o] = s(!0), [u, g] = s(!1), [f, i] = s(null), l = h(async () => {
83
- if (!t) {
84
- r(null), o(!1);
85
- return;
86
- }
87
- o(!0), g(!1), i(null);
88
- try {
89
- const p = await S(t);
90
- r(p);
91
- } catch (p) {
92
- g(!0), i(p instanceof Error ? p : new Error(String(p)));
93
- } finally {
94
- o(!1);
95
- }
96
- }, [t]);
97
- y(() => {
98
- l();
99
- }, [l]);
100
- const c = h(async () => {
101
- w(t), await l();
102
- }, [t, l]);
103
- return { data: n, isLoading: a, isError: u, error: f, refetch: c };
104
- }
105
- function L(e = {}) {
106
- const { includeSelf: t = !0 } = e, n = I(), [r, a] = s([]), [o, u] = s(!0), [g, f] = s(!1), [i, l] = s(null), c = h(async () => {
107
- u(!0), f(!1), l(null);
108
- try {
109
- const d = [];
110
- if (t && n) {
111
- const D = await S(n);
112
- D && d.push(D);
113
- }
114
- a(d);
115
- } catch (d) {
116
- f(!0), l(d instanceof Error ? d : new Error(String(d)));
117
- } finally {
118
- u(!1);
119
- }
120
- }, [t, n]);
121
- y(() => {
122
- c();
123
- }, [c]);
124
- const p = h(async () => {
125
- w(), await c();
126
- }, [c]);
127
- return { data: r, isLoading: o, isError: g, error: i, refetch: p };
128
- }
129
- function v() {
130
- return m().currentUserId;
131
- }
132
- function k(e, t) {
133
- const n = [
134
- "Jan",
135
- "Feb",
136
- "Mar",
137
- "Apr",
138
- "May",
139
- "Jun",
140
- "Jul",
141
- "Aug",
142
- "Sep",
143
- "Oct",
144
- "Nov",
145
- "Dec"
146
- ], r = e.getHours(), a = r % 12 || 12, o = r >= 12 ? "PM" : "AM";
147
- return t.replace("MMM", n[e.getMonth()]).replace("dd", String(e.getDate()).padStart(2, "0")).replace("d", String(e.getDate())).replace("hh", String(a).padStart(2, "0")).replace("h", String(a)).replace("mm", String(e.getMinutes()).padStart(2, "0")).replace("a", o).replace("yyyy", String(e.getFullYear())).replace("yy", String(e.getFullYear()).slice(-2));
148
- }
149
- const F = {
150
- /**
151
- * Get current user ID synchronously
152
- */
153
- getCurrentUserId() {
154
- return m().currentUserId;
155
- },
156
- /**
157
- * Get current timestamp in milliseconds
158
- */
159
- getTimestampInMs() {
160
- return Date.now();
161
- },
162
- /**
163
- * Format date with given format string
164
- * @param options - Format options with timestamp and format string
165
- * @returns Formatted date string
166
- *
167
- * @example
168
- * userSessionInfo.formatDate({ timestampMs: Date.now(), formatString: 'MMM d, h:mm a' })
169
- * // Returns: "Jan 7, 10:30 PM"
170
- */
171
- formatDate(e) {
172
- const { timestampMs: t, formatString: n } = e, r = new Date(t);
173
- return k(r, n);
174
- }
175
- };
176
- export {
177
- T as a,
178
- b,
179
- A as c,
180
- L as d,
181
- w as e,
182
- S as f,
183
- v as g,
184
- F as h,
185
- I as u
186
- };