@backmatter/studio 0.0.20 → 0.0.21

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 (57) hide show
  1. package/dist/chunks/{UiKitApp-C269OA8v.js → UiKitApp-CMMcsaX4.js} +2 -2
  2. package/dist/chunks/{WorkspaceRoutes-B4B5jjje.js → WorkspaceRoutes-DW0sLdpJ.js} +27141 -26241
  3. package/dist/chunks/dashboard-By0P4Yny.js +1879 -0
  4. package/dist/chunks/{index-7-TtXaMq.js → index-DTPUqaHE.js} +1 -1
  5. package/dist/dashboard.js +2 -2
  6. package/dist/index.js +205 -194
  7. package/dist/site-widget.css +208 -0
  8. package/dist/site-widget.js +10495 -9947
  9. package/dist/studio.css +276 -32
  10. package/package.json +2 -2
  11. package/src/App.tsx +7 -1
  12. package/src/api.ts +106 -13
  13. package/src/chat/ChatFiles.tsx +261 -0
  14. package/src/chat/ChatMessage.tsx +5 -0
  15. package/src/chat/ChatPanel.tsx +218 -14
  16. package/src/chat/ChatProvider.tsx +72 -22
  17. package/src/chat/Composer.tsx +83 -6
  18. package/src/chat/PendingFileRow.tsx +188 -0
  19. package/src/chat/chat-context.ts +7 -1
  20. package/src/chat/chat-helpers.ts +49 -0
  21. package/src/chat/chat-state.ts +17 -6
  22. package/src/chat/icons.tsx +28 -0
  23. package/src/chat/model-copy.ts +41 -0
  24. package/src/chat/pending-files.ts +236 -0
  25. package/src/chat/side-width.ts +48 -0
  26. package/src/chrome/AppShell.tsx +9 -1
  27. package/src/chrome/CommandPalette.tsx +7 -0
  28. package/src/chrome/ContentExplorerSidebar.tsx +43 -74
  29. package/src/chrome/folder-create-context.ts +56 -11
  30. package/src/chrome/hotkeys.ts +8 -0
  31. package/src/fields/FieldControl.tsx +331 -115
  32. package/src/fields/LinkFieldInput.tsx +13 -6
  33. package/src/fields/array-item-title.ts +28 -0
  34. package/src/fields/field-label.ts +8 -0
  35. package/src/host-pointer.ts +2 -0
  36. package/src/install-preview-pointer.ts +1 -0
  37. package/src/pages/BlockPicker.tsx +362 -0
  38. package/src/pages/BlocksList.tsx +39 -67
  39. package/src/pages/CliAuthorizePage.tsx +138 -25
  40. package/src/pages/DocEditorPage.tsx +95 -18
  41. package/src/pages/EmbedPublishPage.tsx +40 -2
  42. package/src/pages/LoginPage.tsx +118 -31
  43. package/src/pages/SettingsSchemaPage.tsx +19 -3
  44. package/src/pages/WorkspaceLayout.tsx +16 -1
  45. package/src/pages/block-picker.ts +116 -0
  46. package/src/pages/editor-grab.ts +61 -13
  47. package/src/pages/preview-split.ts +24 -0
  48. package/src/pages/session-preview.ts +1 -0
  49. package/src/replica/types.ts +2 -0
  50. package/src/sign-in-link.ts +45 -0
  51. package/src/site-pointer.ts +14 -1
  52. package/src/site-widget.tsx +12 -1
  53. package/src/ui/Field.tsx +26 -0
  54. package/src/workspace/schema-source.tsx +126 -0
  55. package/dist/chunks/dashboard-DeNgythd.js +0 -1779
  56. package/src/site-devbar-overlay-inject.ts +0 -15
  57. package/src/site-publish-menu.tsx +0 -33
@@ -1,1779 +0,0 @@
1
- var Xe = Object.defineProperty;
2
- var Ye = (e, t, n) => t in e ? Xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var H = (e, t, n) => Ye(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsxs as k, jsx as o, Fragment as me } from "react/jsx-runtime";
5
- import { useRef as Qe, useCallback as Ze, useSyncExternalStore as et, useState as S, useEffect as V, lazy as tt, Suspense as nt } from "react";
6
- import { X as rt, an as be, ao as st, V as R, ap as it, k as at, aq as ot, ar as Ce, as as Ie, at as qe, au as lt, av as ct, P as ze, aw as ut, ax as ie, ah as J, Z as Be, ay as dt, az as Fe, ai as ft, ak as re, aa as Q, ab as Z, Y as ae, aA as ht, W as B, aB as pt, J as we, aC as ee, aj as gt, aD as mt, aE as xt, aF as yt, f as vt, aG as bt, a6 as wt, aH as kt, aI as St, z as Et, B as Rt, I as _t, aJ as Ot, aK as Tt, aL as Pt, K as jt, aM as Lt, R as At, L as Nt, M as Ut, N as Ct, O as F, Q as It, U as qt } from "./WorkspaceRoutes-B4B5jjje.js";
7
- const te = /* @__PURE__ */ Object.create(null), W = (e) => {
8
- var t, n;
9
- return ((t = globalThis.process) == null ? void 0 : t.env) || ((n = globalThis.Deno) == null ? void 0 : n.env.toObject()) || globalThis.__env__ || (e ? te : globalThis);
10
- }, z = new Proxy(te, {
11
- get(e, t) {
12
- return W()[t] ?? te[t];
13
- },
14
- has(e, t) {
15
- return t in W() || t in te;
16
- },
17
- set(e, t, n) {
18
- const r = W(!0);
19
- return r[t] = n, !0;
20
- },
21
- deleteProperty(e, t) {
22
- if (!t) return !1;
23
- const n = W(!0);
24
- return delete n[t], !0;
25
- },
26
- ownKeys() {
27
- const e = W(!0);
28
- return Object.keys(e);
29
- }
30
- });
31
- z.NODE_ENV;
32
- var ne = class extends Error {
33
- constructor(e, t) {
34
- super(e, t), this.name = "BetterAuthError", this.message = e, this.stack = "";
35
- }
36
- };
37
- const zt = 47;
38
- function Me(e) {
39
- let t = e.length;
40
- for (; t > 0 && e.charCodeAt(t - 1) === zt; ) t--;
41
- return t === e.length ? e : e.slice(0, t);
42
- }
43
- function Bt(e) {
44
- try {
45
- return (Me(new URL(e).pathname) || "/") !== "/";
46
- } catch {
47
- throw new ne(`Invalid base URL: ${e}. Please provide a valid base URL.`);
48
- }
49
- }
50
- function Ft(e) {
51
- try {
52
- const t = new URL(e);
53
- if (t.protocol !== "http:" && t.protocol !== "https:") throw new ne(`Invalid base URL: ${e}. URL must include 'http://' or 'https://'`);
54
- } catch (t) {
55
- throw t instanceof ne ? t : new ne(`Invalid base URL: ${e}. Please provide a valid base URL.`, { cause: t });
56
- }
57
- }
58
- function oe(e, t = "/api/auth") {
59
- if (Ft(e), Bt(e)) return e;
60
- const n = Me(e);
61
- return !t || t === "/" ? n : (t = t.startsWith("/") ? t : `/${t}`, `${n}${t}`);
62
- }
63
- function Mt(e, t, n, r, s) {
64
- if (e) return oe(e, t);
65
- {
66
- const i = z.BETTER_AUTH_URL || z.NEXT_PUBLIC_BETTER_AUTH_URL || z.PUBLIC_BETTER_AUTH_URL || z.NUXT_PUBLIC_BETTER_AUTH_URL || z.NUXT_PUBLIC_AUTH_URL || (z.BASE_URL !== "/" ? z.BASE_URL : void 0);
67
- if (i) return oe(i, t);
68
- }
69
- if (typeof window < "u" && window.location) return oe(window.location.origin, t);
70
- }
71
- const Dt = {
72
- proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
73
- constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
74
- protoShort: /"__proto__"\s*:/,
75
- constructorShort: /"constructor"\s*:/
76
- }, Ht = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/, ke = {
77
- true: !0,
78
- false: !1,
79
- null: null,
80
- undefined: void 0,
81
- nan: NaN,
82
- infinity: Number.POSITIVE_INFINITY,
83
- "-infinity": Number.NEGATIVE_INFINITY
84
- }, Wt = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
85
- function $t(e) {
86
- return e instanceof Date && !isNaN(e.getTime());
87
- }
88
- function Gt(e) {
89
- const t = Wt.exec(e);
90
- if (!t) return null;
91
- const [, n, r, s, i, l, d, a, u, c, g] = t, h = new Date(Date.UTC(parseInt(n, 10), parseInt(r, 10) - 1, parseInt(s, 10), parseInt(i, 10), parseInt(l, 10), parseInt(d, 10), a ? parseInt(a.padEnd(3, "0"), 10) : 0));
92
- if (u) {
93
- const p = (parseInt(c, 10) * 60 + parseInt(g, 10)) * (u === "+" ? -1 : 1);
94
- h.setUTCMinutes(h.getUTCMinutes() + p);
95
- }
96
- return $t(h) ? h : null;
97
- }
98
- function Jt(e, t = {}) {
99
- const { strict: n = !1, warnings: r = !1, reviver: s, parseDates: i = !0 } = t;
100
- if (typeof e != "string") return e;
101
- const l = e.trim(), d = l.toLowerCase();
102
- if (d.length <= 9 && d in ke) return ke[d];
103
- if (!Ht.test(l)) {
104
- if (n) throw new SyntaxError("[better-json] Invalid JSON");
105
- return e;
106
- }
107
- if (Object.entries(Dt).some(([a, u]) => {
108
- const c = u.test(l);
109
- return c && r && console.warn(`[better-json] Detected potential prototype pollution attempt using ${a} pattern`), c;
110
- }) && n) throw new Error("[better-json] Potential prototype pollution attempt detected");
111
- try {
112
- return JSON.parse(l, (u, c) => {
113
- if (u === "__proto__" || u === "constructor" && c && typeof c == "object" && "prototype" in c) {
114
- r && console.warn(`[better-json] Dropping "${u}" key to prevent prototype pollution`);
115
- return;
116
- }
117
- if (i && typeof c == "string") {
118
- const g = Gt(c);
119
- if (g) return g;
120
- }
121
- return s ? s(u, c) : c;
122
- });
123
- } catch (a) {
124
- if (n) throw a;
125
- return e;
126
- }
127
- }
128
- function Vt(e, t = { strict: !0 }) {
129
- return Jt(e, t);
130
- }
131
- const Kt = [
132
- "javascript:",
133
- "data:",
134
- "vbscript:"
135
- ];
136
- function Xt(e) {
137
- let t;
138
- try {
139
- t = new URL(e);
140
- } catch {
141
- return !0;
142
- }
143
- return !Kt.includes(t.protocol);
144
- }
145
- const Yt = {
146
- id: "redirect",
147
- name: "Redirect",
148
- hooks: { onSuccess(e) {
149
- var t, n;
150
- if ((t = e.data) != null && t.url && ((n = e.data) != null && n.redirect) && Xt(e.data.url) && typeof window < "u" && window.location && window.location)
151
- try {
152
- window.location.href = e.data.url;
153
- } catch {
154
- }
155
- } }
156
- };
157
- let U = [], $ = 0;
158
- const xe = 4, Qt = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 });
159
- let Zt = () => {
160
- let e, t;
161
- for (; $ < U.length; ) {
162
- t = $, $ += xe;
163
- try {
164
- U[t](
165
- U[t + 1].value,
166
- U[t + 2],
167
- U[t + 3]
168
- );
169
- } catch (n) {
170
- e = n;
171
- }
172
- }
173
- if (U.length = $ = 0, e) throw e;
174
- };
175
- const Se = /* @__NO_SIDE_EFFECTS__ */ (e) => {
176
- let t = [], n = {
177
- eq: Object.is,
178
- get() {
179
- return n.lc || n.listen(() => {
180
- })(), n.value;
181
- },
182
- init: e,
183
- lc: 0,
184
- listen(r) {
185
- return n.lc = t.push(r), () => {
186
- for (let i = $; i < U.length; )
187
- U[i] === r ? U.splice(i, xe) : i += xe;
188
- let s = t.indexOf(r);
189
- ~s && (t.splice(s, 1), --n.lc || n.off());
190
- };
191
- },
192
- notify(r, s) {
193
- Qt.epoch++;
194
- let i = !U.length && !0;
195
- for (let l of t)
196
- U.push(
197
- l,
198
- n,
199
- r,
200
- s
201
- );
202
- i && Zt();
203
- },
204
- /* It will be called on last listener unsubscribing.
205
- We will redefine it in onMount and onStop. */
206
- off() {
207
- },
208
- set(r) {
209
- let s = n.value;
210
- n.eq(s, r) || (n.value = r, n.notify(s));
211
- },
212
- subscribe(r) {
213
- let s = n.listen(r);
214
- return r(n.value), s;
215
- },
216
- value: e
217
- };
218
- return n;
219
- }, en = 2, tn = 5, X = 6, Y = 10;
220
- let De = (e, t, n, r) => (e.events = e.events || {}, e.events[n + Y] || (e.events[n + Y] = r((s) => {
221
- e.events[n].reduceRight((i, l) => (l(i), i), {
222
- shared: {},
223
- ...s
224
- });
225
- })), e.events[n] = e.events[n] || [], e.events[n].push(t), () => {
226
- let s = e.events[n], i = s.indexOf(t);
227
- ~i && (s.splice(i, 1), s.length || (e.events[n + Y](), delete e.events[n + Y]));
228
- }), nn = (e, t) => De(e, t, en, (n) => {
229
- let r = e.set, s = e.setKey;
230
- return e.setKey && (e.setKey = (i, l) => {
231
- let d;
232
- if (n({
233
- abort: () => {
234
- d = !0;
235
- },
236
- changed: i,
237
- newValue: { ...e.value, [i]: l }
238
- }), !d) return s(i, l);
239
- }), e.set = (i) => {
240
- let l;
241
- if (n({ abort: () => {
242
- l = !0;
243
- }, newValue: i }), !l) return r(i);
244
- }, () => {
245
- e.set = r, e.setKey = s;
246
- };
247
- });
248
- const He = 1e3;
249
- let rn = (e, t) => De(e, (r) => {
250
- let s = t(r);
251
- s && e.events[X].push(s);
252
- }, tn, (r) => {
253
- let s = e.listen;
254
- e.listen = (...l) => (!e.lc && !e.active && (e.active = !0, r()), s(...l));
255
- let i = e.off;
256
- return e.events[X] = [], e.off = () => {
257
- i(), setTimeout(() => {
258
- if (e.active && !e.lc) {
259
- e.active = !1;
260
- for (let l of e.events[X]) l();
261
- e.events[X] = [];
262
- }
263
- }, He);
264
- }, () => {
265
- e.listen = s, e.off = i;
266
- };
267
- });
268
- function Ee(e, t) {
269
- let n = sn(t), r = e;
270
- for (let s of n) {
271
- if (r == null)
272
- return;
273
- r = r[s];
274
- }
275
- return r;
276
- }
277
- const Re = /(.*)\[(\d+)\]/;
278
- function sn(e) {
279
- return e.split(".").flatMap((t) => We(t));
280
- }
281
- function We(e) {
282
- if (Re.test(e)) {
283
- let [, t, n] = e.match(Re);
284
- return [...We(t), n];
285
- }
286
- return [e];
287
- }
288
- function an(e, t, n) {
289
- let r = new Set(t);
290
- return e.listen((s, i, l) => {
291
- (l === void 0 ? t.some(
292
- (d) => i === void 0 || // `map` keys are plain properties, but a `deepMap` key is a path into
293
- // the value, where a plain lookup would compare undefined to undefined
294
- // and never report a change.
295
- s[d] !== i[d] || Ee(s, d) !== Ee(i, d)
296
- ) : r.has(l) || r.has(l.split(/\.|\[/)[0])) && n(s, i, l);
297
- });
298
- }
299
- function _e(e) {
300
- if (typeof e != "object" || e === null) return !1;
301
- const t = Object.getPrototypeOf(e);
302
- return t === Object.prototype || t === null;
303
- }
304
- function se(e, t) {
305
- if (e === t) return !0;
306
- if (Array.isArray(e) && Array.isArray(t)) {
307
- if (e.length !== t.length) return !1;
308
- for (let n = 0; n < e.length; n++) if (!se(e[n], t[n])) return !1;
309
- return !0;
310
- }
311
- if (_e(e) && _e(t)) {
312
- const n = Object.keys(e), r = Object.keys(t);
313
- if (n.length !== r.length) return !1;
314
- for (const s of n) if (!(s in t) || !se(e[s], t[s])) return !1;
315
- return !0;
316
- }
317
- return !1;
318
- }
319
- function on(e, t) {
320
- return nn(e, ({ newValue: n, abort: r }) => {
321
- t(e.value, n) && r();
322
- });
323
- }
324
- const le = Symbol.for("better-auth:broadcast-channel"), ln = () => Math.floor(Date.now() / 1e3);
325
- var cn = class {
326
- constructor(e = "better-auth.message") {
327
- H(this, "listeners", /* @__PURE__ */ new Set());
328
- H(this, "name");
329
- this.name = e;
330
- }
331
- subscribe(e) {
332
- return this.listeners.add(e), () => {
333
- this.listeners.delete(e);
334
- };
335
- }
336
- post(e) {
337
- if (!(typeof window > "u"))
338
- try {
339
- localStorage.setItem(this.name, JSON.stringify({
340
- ...e,
341
- timestamp: ln()
342
- }));
343
- } catch {
344
- }
345
- }
346
- setup() {
347
- if (typeof window > "u" || typeof window.addEventListener > "u") return () => {
348
- };
349
- const e = (t) => {
350
- if (t.key !== this.name) return;
351
- const n = JSON.parse(t.newValue ?? "{}");
352
- (n == null ? void 0 : n.event) !== "session" || !(n != null && n.data) || this.listeners.forEach((r) => r(n));
353
- };
354
- return window.addEventListener("storage", e), () => {
355
- window.removeEventListener("storage", e);
356
- };
357
- }
358
- };
359
- function ce(e = "better-auth.message") {
360
- return globalThis[le] || (globalThis[le] = new cn(e)), globalThis[le];
361
- }
362
- const ue = Symbol.for("better-auth:focus-manager");
363
- var un = class {
364
- constructor() {
365
- H(this, "listeners", /* @__PURE__ */ new Set());
366
- }
367
- subscribe(e) {
368
- return this.listeners.add(e), () => {
369
- this.listeners.delete(e);
370
- };
371
- }
372
- setFocused(e) {
373
- this.listeners.forEach((t) => t(e));
374
- }
375
- setup() {
376
- if (typeof window > "u" || typeof document > "u" || typeof window.addEventListener > "u") return () => {
377
- };
378
- const e = () => {
379
- document.visibilityState === "visible" && this.setFocused(!0);
380
- };
381
- return document.addEventListener("visibilitychange", e, !1), () => {
382
- document.removeEventListener("visibilitychange", e, !1);
383
- };
384
- }
385
- };
386
- function Oe() {
387
- return globalThis[ue] || (globalThis[ue] = new un()), globalThis[ue];
388
- }
389
- const de = Symbol.for("better-auth:online-manager");
390
- var dn = class {
391
- constructor() {
392
- H(this, "listeners", /* @__PURE__ */ new Set());
393
- H(this, "isOnline", typeof navigator < "u" ? navigator.onLine : !0);
394
- }
395
- subscribe(e) {
396
- return this.listeners.add(e), () => {
397
- this.listeners.delete(e);
398
- };
399
- }
400
- setOnline(e) {
401
- this.isOnline = e, this.listeners.forEach((t) => t(e));
402
- }
403
- setup() {
404
- if (typeof window > "u" || typeof window.addEventListener > "u") return () => {
405
- };
406
- const e = () => this.setOnline(!0), t = () => this.setOnline(!1);
407
- return window.addEventListener("online", e, !1), window.addEventListener("offline", t, !1), () => {
408
- window.removeEventListener("online", e, !1), window.removeEventListener("offline", t, !1);
409
- };
410
- }
411
- };
412
- function fe() {
413
- return globalThis[de] || (globalThis[de] = new dn()), globalThis[de];
414
- }
415
- const he = () => Math.floor(Date.now() / 1e3), fn = 5;
416
- function hn(e) {
417
- var T, y, _;
418
- const { fetchSession: t, shouldPollSession: n = () => !0, sessionSignal: r, options: s = {} } = e, i = ((T = s.sessionOptions) == null ? void 0 : T.refetchInterval) ?? 0, l = ((y = s.sessionOptions) == null ? void 0 : y.refetchOnWindowFocus) ?? !0, d = ((_ = s.sessionOptions) == null ? void 0 : _.refetchWhenOffline) ?? !1, a = {
419
- isInitialized: !1,
420
- lastSessionRequest: 0
421
- }, u = () => d || fe().isOnline, c = (m) => {
422
- if (u()) {
423
- if ((m == null ? void 0 : m.event) === "storage") {
424
- t();
425
- return;
426
- }
427
- if ((m == null ? void 0 : m.event) === "poll") {
428
- a.lastSessionRequest = he(), t();
429
- return;
430
- }
431
- if ((m == null ? void 0 : m.event) === "visibilitychange") {
432
- if (he() - a.lastSessionRequest < fn) return;
433
- a.lastSessionRequest = he(), t();
434
- return;
435
- }
436
- t();
437
- }
438
- }, g = (m) => {
439
- ce().post({
440
- event: "session",
441
- data: { trigger: m },
442
- clientId: Math.random().toString(36).substring(7)
443
- });
444
- }, h = () => {
445
- i && i > 0 && (a.pollInterval = setInterval(() => {
446
- n() && c({ event: "poll" });
447
- }, i * 1e3));
448
- }, p = () => {
449
- a.unsubscribeBroadcast = ce().subscribe(() => {
450
- c({ event: "storage" });
451
- });
452
- }, v = () => {
453
- l && (a.unsubscribeFocus = Oe().subscribe(() => {
454
- c({ event: "visibilitychange" });
455
- }));
456
- }, b = () => {
457
- a.unsubscribeOnline = fe().subscribe((m) => {
458
- m && c({ event: "visibilitychange" });
459
- });
460
- }, x = () => {
461
- a.unsubscribeSignal = r.listen(() => {
462
- t();
463
- });
464
- };
465
- return {
466
- init: () => {
467
- a.isInitialized || (a.isInitialized = !0, h(), p(), v(), b(), x(), a.cleanupBroadcastSetup = ce().setup(), a.cleanupFocusSetup = Oe().setup(), a.cleanupOnlineSetup = fe().setup());
468
- },
469
- cleanup: () => {
470
- a.isInitialized && (a.pollInterval && (clearInterval(a.pollInterval), a.pollInterval = void 0), a.unsubscribeBroadcast && (a.unsubscribeBroadcast(), a.unsubscribeBroadcast = void 0), a.unsubscribeFocus && (a.unsubscribeFocus(), a.unsubscribeFocus = void 0), a.unsubscribeOnline && (a.unsubscribeOnline(), a.unsubscribeOnline = void 0), a.unsubscribeSignal && (a.unsubscribeSignal(), a.unsubscribeSignal = void 0), a.cleanupBroadcastSetup && (a.cleanupBroadcastSetup(), a.cleanupBroadcastSetup = void 0), a.cleanupFocusSetup && (a.cleanupFocusSetup(), a.cleanupFocusSetup = void 0), a.cleanupOnlineSetup && (a.cleanupOnlineSetup(), a.cleanupOnlineSetup = void 0), a.isInitialized = !1, a.lastSessionRequest = 0);
471
- },
472
- triggerRefetch: c,
473
- broadcastSessionUpdate: g
474
- };
475
- }
476
- const pn = () => typeof window > "u", gn = He;
477
- function mn(e, t) {
478
- if (typeof window > "u") return;
479
- const n = e.get();
480
- n.data !== null || t === null || e.set({
481
- ...n,
482
- data: t,
483
- error: null,
484
- isPending: !1
485
- });
486
- }
487
- function Te(e) {
488
- return typeof e == "object" && e !== null && "data" in e && "error" in e ? e : {
489
- data: e,
490
- error: null
491
- };
492
- }
493
- function xn(e) {
494
- return !e || e.session === null && e.user === null ? null : e;
495
- }
496
- function yn(e, t) {
497
- return se(e.data, t.data) && e.error === t.error && e.isPending === t.isPending && e.isRefetching === t.isRefetching && e.refetch === t.refetch;
498
- }
499
- function vn(e, t) {
500
- const n = /* @__PURE__ */ Se(!1);
501
- let r, s = 0, i = 0;
502
- n.listen(() => {
503
- i++, s = 0;
504
- });
505
- const l = (p) => c(p), d = /* @__PURE__ */ Se({
506
- data: null,
507
- error: null,
508
- isPending: !0,
509
- isRefetching: !1,
510
- refetch: l
511
- });
512
- on(d, yn);
513
- const a = async (p, v) => {
514
- const b = d.value;
515
- if (d.set({
516
- ...b,
517
- isPending: b.data === null,
518
- isRefetching: !0,
519
- error: null,
520
- refetch: l
521
- }), p.aborted) return "aborted";
522
- try {
523
- const x = await e("/get-session", {
524
- method: "GET",
525
- query: v == null ? void 0 : v.query,
526
- signal: p
527
- });
528
- if (p.aborted) return "aborted";
529
- let { data: E, error: P } = Te(x), T = "fresh";
530
- if (E != null && E.needsRefresh) try {
531
- const O = await e("/get-session", {
532
- method: "POST",
533
- signal: p
534
- });
535
- if (p.aborted) return "aborted";
536
- ({ data: E, error: P } = Te(O));
537
- } catch {
538
- if (p.aborted) return "aborted";
539
- T = "stale";
540
- }
541
- if (P) {
542
- const O = d.value, L = (P == null ? void 0 : P.status) === 401;
543
- return d.set({
544
- data: L ? null : O.data,
545
- error: P,
546
- isPending: !1,
547
- isRefetching: !1,
548
- refetch: l
549
- }), "failed";
550
- }
551
- const y = xn(E), _ = d.value, m = _.data != null && y != null && se(_.data, y) ? _.data : y;
552
- return d.set({
553
- data: m,
554
- error: null,
555
- isPending: !1,
556
- isRefetching: !1,
557
- refetch: l
558
- }), T;
559
- } catch (x) {
560
- if (p.aborted) return "aborted";
561
- const E = d.value;
562
- return d.set({
563
- data: E.data,
564
- error: x,
565
- isPending: !1,
566
- isRefetching: !1,
567
- refetch: l
568
- }), "failed";
569
- }
570
- }, u = () => {
571
- var b, x;
572
- const p = (x = (b = d.value.data) == null ? void 0 : b.session) == null ? void 0 : x.expiresAt, v = p instanceof Date ? p.getTime() : Number.POSITIVE_INFINITY;
573
- return Math.min(Date.now() + gn, v);
574
- }, c = (p) => {
575
- s = 0, r == null || r.cancel();
576
- const v = new AbortController(), b = {
577
- cancel: () => v.abort(),
578
- promise: Promise.resolve().then(() => v.signal.aborted ? "aborted" : a(v.signal, p)),
579
- revision: i
580
- };
581
- r = b;
582
- const x = (E) => {
583
- r === b && (r = void 0, E === "fresh" && b.revision === i && (s = u()));
584
- };
585
- return b.promise.then(x, () => x("failed")), b.promise.then(() => {
586
- });
587
- }, g = () => (r == null ? void 0 : r.revision) === i ? r.promise.then(() => {
588
- }) : Date.now() < s ? Promise.resolve() : c();
589
- let h = () => {
590
- };
591
- return rn(d, () => {
592
- let p;
593
- pn() || (p = setTimeout(() => {
594
- g();
595
- }, 0));
596
- const v = hn({
597
- fetchSession: c,
598
- shouldPollSession: () => d.value.data != null,
599
- sessionSignal: n,
600
- options: t
601
- });
602
- return v.init(), h = v.broadcastSessionUpdate, () => {
603
- p && clearTimeout(p), v.cleanup();
604
- };
605
- }), {
606
- session: d,
607
- $sessionSignal: n,
608
- broadcastSessionUpdate: (p) => h(p)
609
- };
610
- }
611
- function pe(e) {
612
- if (e === null || typeof e != "object")
613
- return !1;
614
- const t = Object.getPrototypeOf(e);
615
- return t !== null && t !== Object.prototype && Object.getPrototypeOf(t) !== null || Symbol.iterator in e ? !1 : Symbol.toStringTag in e ? Object.prototype.toString.call(e) === "[object Module]" : !0;
616
- }
617
- function ye(e, t, n = ".", r) {
618
- if (!pe(t))
619
- return ye(e, {}, n, r);
620
- const s = { ...t };
621
- for (const i of Object.keys(e)) {
622
- if (i === "__proto__" || i === "constructor")
623
- continue;
624
- const l = e[i];
625
- l != null && (r && r(s, i, l, n) || (Array.isArray(l) && Array.isArray(s[i]) ? s[i] = [...l, ...s[i]] : pe(l) && pe(s[i]) ? s[i] = ye(
626
- l,
627
- s[i],
628
- (n ? `${n}.` : "") + i.toString(),
629
- r
630
- ) : s[i] = l));
631
- }
632
- return s;
633
- }
634
- function bn(e) {
635
- return (...t) => (
636
- // eslint-disable-next-line unicorn/no-array-reduce
637
- t.reduce((n, r) => ye(n, r, "", e), {})
638
- );
639
- }
640
- const wn = bn();
641
- var kn = Object.defineProperty, Sn = Object.defineProperties, En = Object.getOwnPropertyDescriptors, Pe = Object.getOwnPropertySymbols, Rn = Object.prototype.hasOwnProperty, _n = Object.prototype.propertyIsEnumerable, je = (e, t, n) => t in e ? kn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, N = (e, t) => {
642
- for (var n in t || (t = {}))
643
- Rn.call(t, n) && je(e, n, t[n]);
644
- if (Pe)
645
- for (var n of Pe(t))
646
- _n.call(t, n) && je(e, n, t[n]);
647
- return e;
648
- }, C = (e, t) => Sn(e, En(t)), On = class extends Error {
649
- constructor(e, t, n) {
650
- super(t || e.toString(), {
651
- cause: n
652
- }), this.status = e, this.statusText = t, this.error = n, Error.captureStackTrace(this, this.constructor);
653
- }
654
- }, Tn = async (e, t) => {
655
- var n, r, s, i, l, d;
656
- let a = t || {};
657
- const u = {
658
- onRequest: [t == null ? void 0 : t.onRequest],
659
- onResponse: [t == null ? void 0 : t.onResponse],
660
- onSuccess: [t == null ? void 0 : t.onSuccess],
661
- onError: [t == null ? void 0 : t.onError],
662
- onRetry: [t == null ? void 0 : t.onRetry]
663
- };
664
- if (!t || !(t != null && t.plugins))
665
- return {
666
- url: e,
667
- options: a,
668
- hooks: u
669
- };
670
- for (const c of (t == null ? void 0 : t.plugins) || []) {
671
- if (c.init) {
672
- const g = await ((n = c.init) == null ? void 0 : n.call(c, e.toString(), t));
673
- a = g.options || a, e = g.url;
674
- }
675
- u.onRequest.push((r = c.hooks) == null ? void 0 : r.onRequest), u.onResponse.push((s = c.hooks) == null ? void 0 : s.onResponse), u.onSuccess.push((i = c.hooks) == null ? void 0 : i.onSuccess), u.onError.push((l = c.hooks) == null ? void 0 : l.onError), u.onRetry.push((d = c.hooks) == null ? void 0 : d.onRetry);
676
- }
677
- return {
678
- url: e,
679
- options: a,
680
- hooks: u
681
- };
682
- }, Le = class {
683
- constructor(e) {
684
- this.options = e;
685
- }
686
- shouldAttemptRetry(e, t) {
687
- return this.options.shouldRetry ? Promise.resolve(
688
- e < this.options.attempts && this.options.shouldRetry(t)
689
- ) : Promise.resolve(e < this.options.attempts);
690
- }
691
- getDelay() {
692
- return this.options.delay;
693
- }
694
- }, Pn = class {
695
- constructor(e) {
696
- this.options = e;
697
- }
698
- shouldAttemptRetry(e, t) {
699
- return this.options.shouldRetry ? Promise.resolve(
700
- e < this.options.attempts && this.options.shouldRetry(t)
701
- ) : Promise.resolve(e < this.options.attempts);
702
- }
703
- getDelay(e) {
704
- return Math.min(
705
- this.options.maxDelay,
706
- this.options.baseDelay * 2 ** e
707
- );
708
- }
709
- };
710
- function jn(e) {
711
- if (typeof e == "number")
712
- return new Le({
713
- type: "linear",
714
- attempts: e,
715
- delay: 1e3
716
- });
717
- switch (e.type) {
718
- case "linear":
719
- return new Le(e);
720
- case "exponential":
721
- return new Pn(e);
722
- default:
723
- throw new Error("Invalid retry strategy");
724
- }
725
- }
726
- var Ln = async (e) => {
727
- const t = {}, n = async (r) => typeof r == "function" ? await r() : r;
728
- if (e != null && e.auth) {
729
- if (e.auth.type === "Bearer") {
730
- const r = await n(e.auth.token);
731
- if (!r)
732
- return t;
733
- t.authorization = `Bearer ${r}`;
734
- } else if (e.auth.type === "Basic") {
735
- const [r, s] = await Promise.all([
736
- n(e.auth.username),
737
- n(e.auth.password)
738
- ]);
739
- if (!r || !s)
740
- return t;
741
- t.authorization = `Basic ${btoa(`${r}:${s}`)}`;
742
- } else if (e.auth.type === "Custom") {
743
- const [r, s] = await Promise.all([
744
- n(e.auth.prefix),
745
- n(e.auth.value)
746
- ]);
747
- if (!s)
748
- return t;
749
- t.authorization = `${r ?? ""} ${s}`;
750
- }
751
- }
752
- return t;
753
- }, An = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
754
- function Nn(e) {
755
- const t = e.headers.get("content-type"), n = /* @__PURE__ */ new Set([
756
- "image/svg",
757
- "application/xml",
758
- "application/xhtml",
759
- "application/html"
760
- ]);
761
- if (!t)
762
- return "json";
763
- const r = t.split(";").shift() || "";
764
- return An.test(r) ? "json" : n.has(r) || r.startsWith("text/") ? "text" : "blob";
765
- }
766
- function Un(e) {
767
- try {
768
- return JSON.parse(e), !0;
769
- } catch {
770
- return !1;
771
- }
772
- }
773
- function $e(e) {
774
- if (e === void 0)
775
- return !1;
776
- const t = typeof e;
777
- return t === "string" || t === "number" || t === "boolean" || t === null ? !0 : t !== "object" ? !1 : Array.isArray(e) ? !0 : e.buffer ? !1 : e.constructor && e.constructor.name === "Object" || typeof e.toJSON == "function";
778
- }
779
- function Ae(e) {
780
- try {
781
- return JSON.parse(e);
782
- } catch {
783
- return e;
784
- }
785
- }
786
- function Ne(e) {
787
- return typeof e == "function";
788
- }
789
- function Cn(e) {
790
- if (e != null && e.customFetchImpl)
791
- return e.customFetchImpl;
792
- if (typeof globalThis < "u" && Ne(globalThis.fetch))
793
- return globalThis.fetch;
794
- if (typeof window < "u" && Ne(window.fetch))
795
- return window.fetch;
796
- throw new Error("No fetch implementation found");
797
- }
798
- function Ge(...e) {
799
- const t = {};
800
- for (const n of e)
801
- if (n)
802
- if (n instanceof Headers)
803
- n.forEach((r, s) => {
804
- t[s] = r;
805
- });
806
- else {
807
- const r = Array.isArray(n) ? n : Object.entries(n);
808
- for (const [s, i] of r)
809
- i != null && (t[s] = i);
810
- }
811
- return t;
812
- }
813
- async function In(e) {
814
- const t = new Headers(Ge(e == null ? void 0 : e.headers, await Ln(e)));
815
- if (!t.has("content-type")) {
816
- const n = qn(e == null ? void 0 : e.body);
817
- n && t.set("content-type", n);
818
- }
819
- return t;
820
- }
821
- function qn(e) {
822
- return $e(e) ? "application/json" : null;
823
- }
824
- function zn(e) {
825
- const t = e.get("content-type");
826
- return t ? t.split(";")[0].trim().toLowerCase() : null;
827
- }
828
- function Bn(e, t) {
829
- const { body: n } = e;
830
- return n ? !$e(n) || typeof n == "string" ? n : zn(t) === "application/x-www-form-urlencoded" ? new URLSearchParams(n).toString() : JSON.stringify(n) : null;
831
- }
832
- function Fn(e, t) {
833
- var n;
834
- if (t != null && t.method)
835
- return t.method.toUpperCase();
836
- if (e.startsWith("@")) {
837
- const r = (n = e.split("@")[1]) == null ? void 0 : n.split("/")[0];
838
- return Ve.includes(r) ? r.toUpperCase() : t != null && t.body ? "POST" : "GET";
839
- }
840
- return t != null && t.body ? "POST" : "GET";
841
- }
842
- function Mn(e, t) {
843
- let n;
844
- return !(e != null && e.signal) && (e != null && e.timeout) && (n = setTimeout(() => t == null ? void 0 : t.abort(), e == null ? void 0 : e.timeout)), {
845
- abortTimeout: n,
846
- clearTimeout: () => {
847
- n && clearTimeout(n);
848
- }
849
- };
850
- }
851
- var Dn = class Je extends Error {
852
- constructor(t, n) {
853
- super(n || JSON.stringify(t, null, 2)), this.issues = t, Object.setPrototypeOf(this, Je.prototype);
854
- }
855
- };
856
- async function G(e, t) {
857
- const n = await e["~standard"].validate(t);
858
- if (n.issues)
859
- throw new Dn(n.issues);
860
- return n.value;
861
- }
862
- var Ve = ["get", "post", "put", "patch", "delete"], Hn = (e) => ({
863
- id: "apply-schema",
864
- name: "Apply Schema",
865
- version: "1.0.0",
866
- async init(t, n) {
867
- var r, s, i, l;
868
- const d = ((s = (r = e.plugins) == null ? void 0 : r.find(
869
- (a) => {
870
- var u;
871
- return (u = a.schema) != null && u.config ? t.startsWith(a.schema.config.baseURL || "") || t.startsWith(a.schema.config.prefix || "") : !1;
872
- }
873
- )) == null ? void 0 : s.schema) || e.schema;
874
- if (d) {
875
- let a = t;
876
- (i = d.config) != null && i.prefix && a.startsWith(d.config.prefix) && (a = a.replace(d.config.prefix, ""), d.config.baseURL && (t = t.replace(d.config.prefix, d.config.baseURL))), (l = d.config) != null && l.baseURL && a.startsWith(d.config.baseURL) && (a = a.replace(d.config.baseURL, "")), a.startsWith("/") && a.charAt(1) === "@" && (a = a.substring(1));
877
- const u = d.schema[a];
878
- if (u) {
879
- let c = n == null ? void 0 : n.headers;
880
- if (u.headers && !(n != null && n.disableValidation)) {
881
- const h = {};
882
- if (n != null && n.headers) {
883
- if (n.headers instanceof Headers)
884
- n.headers.forEach((b, x) => {
885
- h[x.toLowerCase()] = b;
886
- });
887
- else if (typeof n.headers == "object")
888
- for (const [b, x] of Object.entries(n.headers))
889
- x != null && (h[b.toLowerCase()] = x);
890
- }
891
- const p = await G(
892
- u.headers,
893
- h
894
- ), v = {};
895
- for (const [b, x] of Object.entries(p))
896
- v[b.toLowerCase()] = x;
897
- c = v;
898
- }
899
- let g = C(N({}, n), {
900
- method: u.method,
901
- output: u.output,
902
- headers: c
903
- });
904
- return n != null && n.disableValidation || (g = C(N({}, g), {
905
- body: u.input ? await G(u.input, n == null ? void 0 : n.body) : n == null ? void 0 : n.body,
906
- params: u.params ? await G(u.params, n == null ? void 0 : n.params) : n == null ? void 0 : n.params,
907
- query: u.query ? await G(u.query, n == null ? void 0 : n.query) : n == null ? void 0 : n.query
908
- })), {
909
- url: t,
910
- options: g
911
- };
912
- }
913
- }
914
- return {
915
- url: t,
916
- options: n
917
- };
918
- }
919
- }), Wn = (e) => {
920
- async function t(n, r) {
921
- const s = C(N(N({}, e), r), {
922
- headers: Ge(e == null ? void 0 : e.headers, r == null ? void 0 : r.headers),
923
- plugins: [...(e == null ? void 0 : e.plugins) || [], Hn(e || {}), ...(r == null ? void 0 : r.plugins) || []]
924
- });
925
- if (e != null && e.catchAllError)
926
- try {
927
- return await ve(n, s);
928
- } catch (i) {
929
- return {
930
- data: null,
931
- error: {
932
- status: 500,
933
- statusText: "Fetch Error",
934
- message: "Fetch related error. Captured by catchAllError option. See error property for more details.",
935
- error: i
936
- }
937
- };
938
- }
939
- return await ve(n, s);
940
- }
941
- return t;
942
- }, $n = (e) => e === "." || e === "..";
943
- function Gn(e, t) {
944
- let n = e;
945
- for (const [r, s] of t)
946
- n = n.replace(r, s);
947
- if ($n(n))
948
- throw new TypeError("Path parameters cannot be reserved path segments");
949
- return encodeURIComponent(n);
950
- }
951
- function Jn(e, t) {
952
- const { baseURL: n, params: r, query: s } = t || {
953
- query: {},
954
- params: {},
955
- baseURL: ""
956
- };
957
- let i = e.startsWith("http") ? e.split("/").slice(0, 3).join("/") : n || "";
958
- if (e.startsWith("@")) {
959
- const h = e.toString().split("@")[1].split("/")[0];
960
- Ve.includes(h) && (e = e.replace(`@${h}/`, "/"));
961
- }
962
- i.endsWith("/") || (i += "/");
963
- let [l, d] = e.replace(i, "").split("?");
964
- const a = new URLSearchParams(d);
965
- for (const [h, p] of Object.entries(s || {})) {
966
- if (p == null) continue;
967
- let v;
968
- if (typeof p == "string")
969
- v = p;
970
- else if (Array.isArray(p)) {
971
- for (const b of p)
972
- a.append(h, b);
973
- continue;
974
- } else
975
- v = JSON.stringify(p);
976
- a.set(h, v);
977
- }
978
- const u = /* @__PURE__ */ new Map();
979
- if (r)
980
- if (Array.isArray(r)) {
981
- const h = l.split("/").filter((p) => p.startsWith(":"));
982
- for (const [p, v] of h.entries()) {
983
- const b = r[p];
984
- u.set(v, String(b));
985
- }
986
- } else
987
- for (const [h, p] of Object.entries(r))
988
- u.set(`:${h}`, String(p));
989
- l = l.split("/").map((h) => Gn(h, u)).join("/"), l = l.replace(/^\/+/, "");
990
- let c = a.toString();
991
- return c = c.length > 0 ? `?${c}`.replace(/\+/g, "%20") : "", i.startsWith("http") ? new URL(`${l}${c}`, i) : `${i}${l}${c}`;
992
- }
993
- var ve = async (e, t) => {
994
- var n, r, s, i, l, d, a, u;
995
- const {
996
- hooks: c,
997
- url: g,
998
- options: h
999
- } = await Tn(e, t), p = Cn(h), v = new AbortController(), b = (n = h.signal) != null ? n : v.signal, x = Jn(g, h), E = await In(h), P = Bn(h, E), T = Fn(g, h), y = C(N({}, h), {
1000
- url: x,
1001
- headers: E,
1002
- body: P,
1003
- method: T,
1004
- signal: b
1005
- });
1006
- for (const j of c.onRequest)
1007
- if (j) {
1008
- const f = await j(y);
1009
- typeof f == "object" && f !== null && Object.assign(y, f);
1010
- }
1011
- ("pipeTo" in y && typeof y.pipeTo == "function" || typeof ((r = t == null ? void 0 : t.body) == null ? void 0 : r.pipe) == "function") && ("duplex" in y || (y.duplex = "half"));
1012
- const { clearTimeout: _ } = Mn(h, v);
1013
- let m = await p(y.url, y);
1014
- _();
1015
- const O = {
1016
- response: m,
1017
- request: y
1018
- };
1019
- for (const j of c.onResponse)
1020
- if (j) {
1021
- const f = await j(C(N({}, O), {
1022
- response: (s = t == null ? void 0 : t.hookOptions) != null && s.cloneResponse ? m.clone() : m
1023
- }));
1024
- f instanceof Response ? m = f : typeof f == "object" && f !== null && (m = f.response);
1025
- }
1026
- if (m.ok) {
1027
- if (!(y.method !== "HEAD"))
1028
- return {
1029
- data: "",
1030
- error: null
1031
- };
1032
- const f = Nn(m), A = {
1033
- data: null,
1034
- response: m,
1035
- request: y
1036
- };
1037
- if (f === "json" || f === "text") {
1038
- const I = await m.text(), Ke = (i = y.jsonParser) != null ? i : Ae;
1039
- A.data = await Ke(I);
1040
- } else
1041
- A.data = await m[f]();
1042
- y != null && y.output && y.output && !y.disableValidation && (A.data = await G(
1043
- y.output,
1044
- A.data
1045
- ));
1046
- for (const I of c.onSuccess)
1047
- I && await I(C(N({}, A), {
1048
- response: (l = t == null ? void 0 : t.hookOptions) != null && l.cloneResponse ? m.clone() : m
1049
- }));
1050
- return t != null && t.throw ? A.data : {
1051
- data: A.data,
1052
- error: null
1053
- };
1054
- }
1055
- const L = (d = t == null ? void 0 : t.jsonParser) != null ? d : Ae, w = await m.text(), q = Un(w), D = q ? await L(w) : null, K = {
1056
- response: m,
1057
- responseText: w,
1058
- request: y,
1059
- error: C(N({}, D), {
1060
- status: m.status,
1061
- statusText: m.statusText
1062
- })
1063
- };
1064
- for (const j of c.onError)
1065
- j && await j(C(N({}, K), {
1066
- response: (a = t == null ? void 0 : t.hookOptions) != null && a.cloneResponse ? m.clone() : m
1067
- }));
1068
- if (t != null && t.retry) {
1069
- const j = jn(t.retry), f = (u = t.retryAttempt) != null ? u : 0;
1070
- if (await j.shouldAttemptRetry(f, m)) {
1071
- for (const I of c.onRetry)
1072
- I && await I(O);
1073
- const A = j.getDelay(f);
1074
- return await new Promise((I) => setTimeout(I, A)), await ve(e, C(N({}, t), {
1075
- retryAttempt: f + 1
1076
- }));
1077
- }
1078
- }
1079
- if (t != null && t.throw)
1080
- throw new On(
1081
- m.status,
1082
- m.statusText,
1083
- q ? D : w
1084
- );
1085
- return {
1086
- data: null,
1087
- error: C(N({}, D), {
1088
- status: m.status,
1089
- statusText: m.statusText
1090
- })
1091
- };
1092
- };
1093
- const Vn = (e) => {
1094
- if (typeof process > "u") return;
1095
- const t = e ?? "/api/auth";
1096
- if (process.env.NEXT_PUBLIC_AUTH_URL) return process.env.NEXT_PUBLIC_AUTH_URL;
1097
- if (typeof window > "u") {
1098
- if (process.env.NEXTAUTH_URL) try {
1099
- return process.env.NEXTAUTH_URL;
1100
- } catch {
1101
- }
1102
- if (process.env.VERCEL_URL) try {
1103
- const n = process.env.VERCEL_URL.startsWith("http") ? "" : "https://";
1104
- return `${new URL(`${n}${process.env.VERCEL_URL}`).origin}${t}`;
1105
- } catch {
1106
- }
1107
- }
1108
- }, Kn = (e, t) => {
1109
- var O, L, w, q, D, K, j;
1110
- const n = "credentials" in Request.prototype, r = Mt(e == null ? void 0 : e.baseURL, e == null ? void 0 : e.basePath) ?? Vn(e == null ? void 0 : e.basePath) ?? "/api/auth", s = ((O = e == null ? void 0 : e.plugins) == null ? void 0 : O.flatMap((f) => f.fetchPlugins).filter((f) => f !== void 0)) || [], i = {
1111
- id: "lifecycle-hooks",
1112
- name: "lifecycle-hooks",
1113
- hooks: {
1114
- onSuccess: (L = e == null ? void 0 : e.fetchOptions) == null ? void 0 : L.onSuccess,
1115
- onError: (w = e == null ? void 0 : e.fetchOptions) == null ? void 0 : w.onError,
1116
- onRequest: (q = e == null ? void 0 : e.fetchOptions) == null ? void 0 : q.onRequest,
1117
- onResponse: (D = e == null ? void 0 : e.fetchOptions) == null ? void 0 : D.onResponse
1118
- }
1119
- }, { onSuccess: l, onError: d, onRequest: a, onResponse: u, ...c } = (e == null ? void 0 : e.fetchOptions) || {}, g = Wn({
1120
- baseURL: r,
1121
- ...n ? { credentials: "include" } : {},
1122
- method: "GET",
1123
- jsonParser(f) {
1124
- return f ? Vt(f, { strict: !1 }) : null;
1125
- },
1126
- customFetchImpl: fetch,
1127
- ...c,
1128
- plugins: [
1129
- i,
1130
- ...c.plugins || [],
1131
- ...e != null && e.disableDefaultFetchPlugins ? [] : [Yt],
1132
- ...s
1133
- ]
1134
- }), { $sessionSignal: h, session: p, broadcastSessionUpdate: v } = vn(g, e);
1135
- let b = !1;
1136
- const x = (f) => {
1137
- b || f === null || (b = !0, mn(p, f));
1138
- }, E = (e == null ? void 0 : e.plugins) || [];
1139
- let P = {};
1140
- const T = {
1141
- $sessionSignal: h,
1142
- session: p
1143
- }, y = {
1144
- "/sign-out": "POST",
1145
- "/revoke-sessions": "POST",
1146
- "/revoke-other-sessions": "POST",
1147
- "/delete-user": "POST"
1148
- }, _ = [{
1149
- signal: "$sessionSignal",
1150
- matcher(f) {
1151
- return f === "/sign-out" || f === "/update-user" || f === "/update-session" || f === "/sign-up/email" || f === "/sign-in/email" || f === "/delete-user" || f === "/verify-email" || f === "/revoke-sessions" || f === "/revoke-session" || f === "/revoke-other-sessions" || f === "/change-email" || f === "/change-password";
1152
- },
1153
- callback(f) {
1154
- f === "/sign-out" ? v("signout") : (f === "/update-user" || f === "/update-session") && v("updateUser");
1155
- }
1156
- }];
1157
- for (const f of E)
1158
- f.getAtoms && Object.assign(T, (K = f.getAtoms) == null ? void 0 : K.call(f, g)), f.pathMethods && Object.assign(y, f.pathMethods), f.atomListeners && _.push(...f.atomListeners);
1159
- const m = {
1160
- notify: (f) => {
1161
- T[f].set(!T[f].get());
1162
- },
1163
- listen: (f, A) => {
1164
- T[f].subscribe(A);
1165
- },
1166
- atoms: T
1167
- };
1168
- for (const f of E) f.getActions && (P = wn(((j = f.getActions) == null ? void 0 : j.call(f, g, m, e)) ?? {}, P));
1169
- return {
1170
- get baseURL() {
1171
- return r;
1172
- },
1173
- pluginsActions: P,
1174
- pluginsAtoms: T,
1175
- pluginPathMethods: y,
1176
- atomListeners: _,
1177
- hydrateSession: x,
1178
- $sessionSignal: h,
1179
- $fetch: g,
1180
- $store: m
1181
- };
1182
- };
1183
- function Xn(e) {
1184
- return typeof e == "object" && e !== null && "get" in e && typeof e.get == "function" && "lc" in e && typeof e.lc == "number";
1185
- }
1186
- function Yn(e) {
1187
- return e.charAt(0).toUpperCase() + e.slice(1);
1188
- }
1189
- const Qn = new RegExp("[\\p{Ll}\\d]+|\\p{Lu}+(?!\\p{Ll})|\\p{Lu}[\\p{Ll}\\d]+|\\p{Lo}+", "gu"), Zn = /['\u2019]/g;
1190
- function er(e) {
1191
- return e.replace(Zn, "").match(Qn) ?? [];
1192
- }
1193
- function tr(e) {
1194
- return er(e).map((t) => t.toLowerCase()).join("-");
1195
- }
1196
- function nr(e, t, n) {
1197
- const r = t[e], { fetchOptions: s, query: i, ...l } = n || {};
1198
- return r || (s != null && s.method ? s.method : l && Object.keys(l).length > 0 ? "POST" : "GET");
1199
- }
1200
- function rr(e, t, n, r, s) {
1201
- function i(l = []) {
1202
- return new Proxy(function() {
1203
- }, {
1204
- get(d, a) {
1205
- if (typeof a != "string" || a === "then" || a === "catch" || a === "finally") return;
1206
- const u = [...l, a];
1207
- let c = e;
1208
- for (const g of u) if (c && typeof c == "object" && g in c) c = c[g];
1209
- else {
1210
- c = void 0;
1211
- break;
1212
- }
1213
- return typeof c == "function" || Xn(c) ? c : i(u);
1214
- },
1215
- apply: async (d, a, u) => {
1216
- const c = "/" + l.map(tr).join("/"), g = u[0] || {}, h = u[1] || {}, { query: p, fetchOptions: v, ...b } = g, x = {
1217
- ...h,
1218
- ...v
1219
- }, E = nr(c, n, g);
1220
- return await t(c, {
1221
- ...x,
1222
- body: E === "GET" ? void 0 : {
1223
- ...b,
1224
- ...(x == null ? void 0 : x.body) || {}
1225
- },
1226
- query: p || (x == null ? void 0 : x.query),
1227
- method: E,
1228
- async onSuccess(P) {
1229
- var _, m;
1230
- if (await ((_ = x == null ? void 0 : x.onSuccess) == null ? void 0 : _.call(x, P)), !s || x.disableSignal) return;
1231
- const T = s.filter((O) => O.matcher(c));
1232
- if (!T.length) return;
1233
- const y = /* @__PURE__ */ new Set();
1234
- for (const O of T) {
1235
- const L = r[O.signal];
1236
- if (!L) return;
1237
- if (y.has(O.signal)) continue;
1238
- y.add(O.signal);
1239
- const w = L.get();
1240
- setTimeout(() => {
1241
- L.set(!w);
1242
- }, 10), (m = O.callback) == null || m.call(O, c);
1243
- }
1244
- }
1245
- });
1246
- }
1247
- });
1248
- }
1249
- return i();
1250
- }
1251
- function sr(e, t = {}) {
1252
- const n = Qe(e.get()), { keys: r, deps: s = [e, r] } = t, i = Ze((d) => {
1253
- const a = (u) => {
1254
- n.current !== u && (n.current = u, d());
1255
- };
1256
- return a(e.value), r != null && r.length ? an(e, r, a) : e.listen(a);
1257
- }, s), l = () => n.current;
1258
- return et(i, l, l);
1259
- }
1260
- function ir(e) {
1261
- return `use${Yn(e)}`;
1262
- }
1263
- function ar(e) {
1264
- const { pluginPathMethods: t, pluginsActions: n, pluginsAtoms: r, hydrateSession: s, $fetch: i, $store: l, atomListeners: d } = Kn(e), a = {};
1265
- for (const [u, c] of Object.entries(r)) a[ir(u)] = () => sr(c);
1266
- return rr({
1267
- ...n,
1268
- ...a,
1269
- hydrateSession: s,
1270
- $fetch: i,
1271
- $store: l
1272
- }, i, t, r, d);
1273
- }
1274
- var or = "1.7.3";
1275
- const lr = or, cr = () => ({
1276
- id: "magic-link",
1277
- version: lr,
1278
- $InferServerPlugin: {}
1279
- });
1280
- let Ue = null;
1281
- function M() {
1282
- return Ue ?? (Ue = ar({
1283
- baseURL: rt(),
1284
- plugins: [cr()]
1285
- })), Ue;
1286
- }
1287
- const ge = {
1288
- terms: "https://backmatter.app/legal/terms",
1289
- privacy: "https://backmatter.app/legal/privacy",
1290
- dpa: "https://backmatter.app/legal/dpa"
1291
- };
1292
- function ur() {
1293
- const [e] = be(), [t, n] = S(null), [r, s] = S(null), [i, l] = S(!1), [d, a] = S(null), u = e.get("token") ? e.get("email") ?? "" : "", [c, g] = S(u || (e.get("email") ?? "")), [h, p] = S(""), [v, b] = S(""), [x, E] = S("signin"), [P, T] = S(!1), y = x === "signup" && !P;
1294
- V(() => {
1295
- st().then((w) => a(w.github)).catch(() => a(!1));
1296
- }, []);
1297
- const _ = window.location.href;
1298
- async function m() {
1299
- l(!0), n(null);
1300
- try {
1301
- await M().signIn.social({
1302
- provider: "github",
1303
- callbackURL: _
1304
- });
1305
- } catch (w) {
1306
- n(w instanceof Error ? w.message : "GitHub sign-in failed"), l(!1);
1307
- }
1308
- }
1309
- async function O() {
1310
- l(!0), n(null), s(null);
1311
- const w = await M().signIn.magicLink({
1312
- email: c,
1313
- callbackURL: _
1314
- });
1315
- if (l(!1), w.error) {
1316
- n(w.error.message ?? "Could not send the magic link");
1317
- return;
1318
- }
1319
- s("Check your email for a sign-in link.");
1320
- }
1321
- async function L(w) {
1322
- w.preventDefault(), l(!0), n(null);
1323
- const q = x === "signup" ? await M().signUp.email({
1324
- email: c,
1325
- password: h,
1326
- name: v,
1327
- callbackURL: _
1328
- }) : await M().signIn.email({
1329
- email: c,
1330
- password: h,
1331
- callbackURL: _
1332
- });
1333
- if (q.error) {
1334
- n(q.error.message ?? "Sign-in failed"), l(!1);
1335
- return;
1336
- }
1337
- window.location.assign(_);
1338
- }
1339
- return /* @__PURE__ */ k("main", { ...at(ot, fr.main), children: [
1340
- /* @__PURE__ */ o("div", { className: "x10l6tqk x10a8y8t x47corl x87ps6o xlxt4rd", "aria-hidden": !0 }),
1341
- /* @__PURE__ */ k("div", { className: "x1n2onr6 x78zum5 xh8yej3 xxc7z9f xdt5ytf x6s0dn4 x2b8uid", children: [
1342
- /* @__PURE__ */ o("div", { className: "xrvj5dj x1ku5rj1 x1useyqa xsdox4t x1y5o9j5 x1n0nidx", children: /* @__PURE__ */ o(dr, {}) }),
1343
- /* @__PURE__ */ o("h1", { className: "x1ghz6dp xqjzbou xneq65o x1s688f x1b4dsll x1u7k74 x1w2vvpw", children: u ? "Join this workspace" : "Welcome back" }),
1344
- /* @__PURE__ */ o("div", { className: "x1g7u8ds", children: /* @__PURE__ */ o(R, { tone: "muted", children: u ? `Sign in as ${u}. A password or GitHub stays on this page. A magic link sends one more email.` : "Sign in with email or GitHub." }) }),
1345
- /* @__PURE__ */ k("div", { className: "x78zum5 xh8yej3 x1tfhste xdt5ytf x6s0dn4 x11cgr9k", children: [
1346
- t ? /* @__PURE__ */ o(R, { tone: "danger", children: t }) : null,
1347
- r ? /* @__PURE__ */ o(R, { tone: "muted", children: r }) : null,
1348
- /* @__PURE__ */ k("p", { className: "x1ghz6dp x1vrk1b5 x1evy7pa x111yfic xdpxx8g", children: [
1349
- "By continuing you agree to the",
1350
- " ",
1351
- /* @__PURE__ */ o("a", { href: ge.terms, className: "xqjzbou xrys4gj", children: "Terms" }),
1352
- " and the",
1353
- " ",
1354
- /* @__PURE__ */ o("a", { href: ge.dpa, className: "xqjzbou xrys4gj", children: "Data Processing Agreement" }),
1355
- ", and you acknowledge the",
1356
- " ",
1357
- /* @__PURE__ */ o("a", { href: ge.privacy, className: "xqjzbou xrys4gj", children: "Privacy policy" }),
1358
- ". A consumer who asks us to start the service now loses the 14-day right of withdrawal once it has begun."
1359
- ] }),
1360
- x === "signup" ? /* @__PURE__ */ k("label", { className: "x78zum5 xh8yej3 x3smv4v x1cy8zhl x1gg8mnh xdpxx8g x1vrk1b5 x1evy7pa xqjzbou x1ypdohk", children: [
1361
- /* @__PURE__ */ o("input", { type: "checkbox", checked: P, onChange: (w) => T(w.target.checked), className: "x1xp8n7a xmix8c7 xr9ek0c x2lah0s x1kb3qnp" }),
1362
- /* @__PURE__ */ o("span", { children: "I agree, and I ask Backmatter to start the service now." })
1363
- ] }) : null,
1364
- /* @__PURE__ */ k("form", { onSubmit: (w) => void L(w), className: "x78zum5 xh8yej3 xdt5ytf x1ndbd79", children: [
1365
- x === "signup" ? /* @__PURE__ */ o("input", { required: !0, value: v, onChange: (w) => b(w.target.value), placeholder: "Name", autoComplete: "name", className: "x9f619 xh8yej3 x1gg8mnh x173sf5p xmkeg23 x1y0btm7 x198m1os x4pepcl xf6xdpg x17ia0ru x1l3a84d" }) : null,
1366
- /* @__PURE__ */ o("input", { required: !0, type: "email", value: c, onChange: (w) => g(w.target.value), placeholder: "Email", autoComplete: "email", readOnly: !!u, ...{
1367
- 0: {
1368
- className: "x9f619 xh8yej3 x1gg8mnh x173sf5p xmkeg23 x1y0btm7 x198m1os x4pepcl xf6xdpg x17ia0ru x1l3a84d"
1369
- },
1370
- 1: {
1371
- className: "x9f619 xh8yej3 x1gg8mnh x173sf5p xmkeg23 x1y0btm7 x198m1os x4pepcl xf6xdpg x1l3a84d x10jjolp"
1372
- }
1373
- }[!!u << 0] }),
1374
- /* @__PURE__ */ o("input", { required: !0, type: "password", value: h, onChange: (w) => p(w.target.value), placeholder: "Password", autoComplete: x === "signup" ? "new-password" : "current-password", className: "x9f619 xh8yej3 x1gg8mnh x173sf5p xmkeg23 x1y0btm7 x198m1os x4pepcl xf6xdpg x17ia0ru x1l3a84d" }),
1375
- /* @__PURE__ */ o("button", { type: "submit", disabled: i || y, ...{
1376
- 0: {
1377
- className: "x3nfvp2 x9f619 xh8yej3 x1gg8mnh x6s0dn4 xl56j7k x3smv4v x161b3w3 xc342km x1e6avla xj4hn0o x1wt99x4 x1l3a84d xk50ysn x1u7k74 xggy1nq xr1c510 xx6bhzk xwji4o3 xq3txz7 xd3so5o x12w9bfk xb93eig"
1378
- },
1379
- 1: {
1380
- className: "x3nfvp2 x9f619 xh8yej3 x1gg8mnh x6s0dn4 xl56j7k x3smv4v x161b3w3 xc342km x1e6avla xj4hn0o x1wt99x4 x1l3a84d xk50ysn x1u7k74 xggy1nq xr1c510 xx6bhzk xwji4o3 xq3txz7 xd3so5o x12w9bfk xb93eig xwq05k6 x1h6gzvc x47corl"
1381
- }
1382
- }[!!(i || y) << 0], children: x === "signup" ? "Create account" : "Sign in" })
1383
- ] }),
1384
- /* @__PURE__ */ o("button", { type: "button", disabled: i || !c || y, onClick: () => void O(), ...{
1385
- 0: {
1386
- className: "x3nfvp2 x9f619 xh8yej3 x1gg8mnh x6s0dn4 xl56j7k xc342km x1e6avla xjbqb8w x1n0nidx x1vrk1b5 x1ypdohk"
1387
- },
1388
- 1: {
1389
- className: "x3nfvp2 x9f619 xh8yej3 x1gg8mnh x6s0dn4 xl56j7k xc342km x1e6avla xjbqb8w x1n0nidx x1vrk1b5 xwq05k6 x1h6gzvc x47corl"
1390
- }
1391
- }[!!(i || !c || y) << 0], children: "Email me a magic link" }),
1392
- /* @__PURE__ */ o("button", { type: "button", disabled: i, onClick: () => E(x === "signup" ? "signin" : "signup"), className: "x3nfvp2 x9f619 xh8yej3 x1gg8mnh x6s0dn4 xl56j7k xc342km x1e6avla xjbqb8w x1n0nidx x1vrk1b5 x1ypdohk", children: x === "signup" ? "I already have an account" : "Create an account" }),
1393
- /* @__PURE__ */ k("button", { type: "button", disabled: i || d !== !0 || y, onClick: () => void m(), ...{
1394
- 0: {
1395
- className: "x3nfvp2 x9f619 xh8yej3 x1gg8mnh x6s0dn4 xl56j7k x3smv4v x161b3w3 xc342km x1e6avla xj4hn0o x1wt99x4 x1l3a84d xk50ysn x1u7k74 xggy1nq xr1c510 xx6bhzk xwji4o3 xq3txz7 xd3so5o x12w9bfk xb93eig"
1396
- },
1397
- 1: {
1398
- className: "x3nfvp2 x9f619 xh8yej3 x1gg8mnh x6s0dn4 xl56j7k x3smv4v x161b3w3 xc342km x1e6avla xj4hn0o x1wt99x4 x1l3a84d xk50ysn x1u7k74 xggy1nq xr1c510 xx6bhzk xwji4o3 xq3txz7 xd3so5o x12w9bfk xb93eig xwq05k6 x1h6gzvc x47corl"
1399
- }
1400
- }[!!(i || d !== !0 || y) << 0], children: [
1401
- /* @__PURE__ */ o(it, { size: 18 }),
1402
- "Continue with GitHub"
1403
- ] })
1404
- ] })
1405
- ] })
1406
- ] });
1407
- }
1408
- function dr() {
1409
- return /* @__PURE__ */ k("svg", { width: "48", height: "48", viewBox: "0 0 48 48", fill: "none", "aria-hidden": !0, children: [
1410
- /* @__PURE__ */ o("circle", { cx: "24", cy: "24", r: "18.25", stroke: "currentColor", strokeWidth: "1.25", opacity: "0.28" }),
1411
- /* @__PURE__ */ o("circle", { cx: "24", cy: "24", r: "11.25", stroke: "currentColor", strokeWidth: "1.25", opacity: "0.55" }),
1412
- /* @__PURE__ */ o("circle", { cx: "24", cy: "24", r: "4", fill: "currentColor" })
1413
- ] });
1414
- }
1415
- const fr = {
1416
- main: {
1417
- kVAEAm: "x1n2onr6",
1418
- k1xSpc: "x78zum5",
1419
- kVQacm: "xb3r6kr",
1420
- kB7OPa: "x9f619",
1421
- kAzted: "x1ov3xa9",
1422
- kGNEyG: "x6s0dn4",
1423
- kjj79g: "xl56j7k",
1424
- kg3NbH: "xm8shrt",
1425
- kLKAdn: "x1dmhkuj",
1426
- kGO01o: "xwlwngp",
1427
- kWkggS: "xemx7gx",
1428
- kMwMTN: "xqjzbou",
1429
- $$css: !0
1430
- }
1431
- };
1432
- function hr() {
1433
- var s;
1434
- const { userId: e } = Ce(), t = Ie(), n = qe(e), r = lt(n, ((s = t.control) == null ? void 0 : s.workspaces) ?? []);
1435
- return r === "/workspaces" && n && ct(e), /* @__PURE__ */ o(ze, { to: r, replace: !0 });
1436
- }
1437
- function pr({
1438
- to: e,
1439
- title: t,
1440
- meta: n,
1441
- trailing: r
1442
- }) {
1443
- const s = /* @__PURE__ */ k(me, { children: [
1444
- /* @__PURE__ */ k("span", { className: "x78zum5 xeuugli xdt5ytf x195vfkc", children: [
1445
- /* @__PURE__ */ o("span", { className: "x17tv04q xk50ysn", children: t }),
1446
- n ? /* @__PURE__ */ o("span", { className: "x1vrk1b5 x111yfic", children: n }) : null
1447
- ] }),
1448
- r ? /* @__PURE__ */ o("span", { className: "x2lah0s x1vrk1b5 x111yfic", children: r }) : null
1449
- ] });
1450
- return e ? /* @__PURE__ */ o(ut, { to: e, className: "x78zum5 x6s0dn4 x1qughib x11cgr9k x21xpn4 x173sf5p x15jjofa x1hl2dhg xqjzbou xso031l x1q0q8m5 x4b2zrn x1t1lzn6 x1xcxyqb", children: s }) : /* @__PURE__ */ o("div", { className: "x78zum5 x6s0dn4 x1qughib x11cgr9k x21xpn4 x173sf5p x15jjofa x1hl2dhg xqjzbou xso031l x1q0q8m5 x4b2zrn x1t1lzn6 x1xcxyqb xt0e3qv", children: s });
1451
- }
1452
- function gr({
1453
- children: e
1454
- }) {
1455
- return /* @__PURE__ */ o("div", { className: "x78zum5 xdt5ytf xmkeg23 x1y0btm7 x1j0qoeq x13oidi x1hb2obb xb3r6kr", children: e });
1456
- }
1457
- function mr() {
1458
- var t;
1459
- const e = ((t = Ie().control) == null ? void 0 : t.workspaces) ?? [];
1460
- return /* @__PURE__ */ k(ie, { centered: !0, children: [
1461
- /* @__PURE__ */ o(
1462
- J,
1463
- {
1464
- title: "Workspaces",
1465
- description: "Each workspace is a site and a team.",
1466
- action: /* @__PURE__ */ o(Be, { to: "/workspaces/new", children: "New workspace" })
1467
- }
1468
- ),
1469
- e.length === 0 ? /* @__PURE__ */ o(R, { tone: "muted", children: "No workspaces yet." }) : /* @__PURE__ */ o(gr, { children: e.map((n) => /* @__PURE__ */ o(
1470
- pr,
1471
- {
1472
- to: dt(n.slug),
1473
- title: n.name,
1474
- meta: n.role
1475
- },
1476
- n.id
1477
- )) })
1478
- ] });
1479
- }
1480
- function xr() {
1481
- const e = Fe(), [t, n] = S(""), [r, s] = S(null), [i, l] = S(!1);
1482
- async function d(a) {
1483
- a.preventDefault(), l(!0), s(null);
1484
- try {
1485
- const { workspace: u } = await ht(t), c = B.getState().control;
1486
- c && B.applyControl({
1487
- ...c,
1488
- workspaces: [
1489
- ...c.workspaces,
1490
- {
1491
- id: u.id,
1492
- name: u.name,
1493
- slug: u.slug,
1494
- role: u.role
1495
- }
1496
- ]
1497
- }), e(`/${u.slug}`);
1498
- } catch (u) {
1499
- s(u instanceof Error ? u.message : "Failed to create workspace");
1500
- } finally {
1501
- l(!1);
1502
- }
1503
- }
1504
- return /* @__PURE__ */ k(ie, { children: [
1505
- /* @__PURE__ */ o(
1506
- J,
1507
- {
1508
- kicker: /* @__PURE__ */ o(ft, { to: "/workspaces", children: "← Workspaces" }),
1509
- title: "Create workspace"
1510
- }
1511
- ),
1512
- /* @__PURE__ */ o("form", { onSubmit: d, children: /* @__PURE__ */ k(re, { children: [
1513
- /* @__PURE__ */ o(Q, { label: "Name", children: /* @__PURE__ */ o(
1514
- Z,
1515
- {
1516
- required: !0,
1517
- value: t,
1518
- onChange: (a) => n(a.target.value),
1519
- placeholder: "Docs site"
1520
- }
1521
- ) }),
1522
- r ? /* @__PURE__ */ o(R, { tone: "danger", children: r }) : null,
1523
- /* @__PURE__ */ o("div", { children: /* @__PURE__ */ o(ae, { type: "submit", disabled: i, children: i ? "Creating…" : "Create workspace" }) })
1524
- ] }) })
1525
- ] });
1526
- }
1527
- function yr(e, t) {
1528
- switch (e) {
1529
- case "invite_expired":
1530
- return "This invite has expired. Ask for a new one.";
1531
- case "invite_revoked":
1532
- return "This invite was revoked.";
1533
- case "not_found":
1534
- return "This invite link is not valid.";
1535
- case "last_admin":
1536
- return "Accepting this invite would remove the last admin.";
1537
- case "email_unverified":
1538
- return "Verify this email before joining. Sign out, then choose “Email me a magic link” on the sign-in screen.";
1539
- default:
1540
- return t;
1541
- }
1542
- }
1543
- function vr() {
1544
- const [e] = be(), t = Fe(), n = e.get("token") ?? "", r = e.get("email") ?? "", [s, i] = S(null), [l, d] = S(null), [a, u] = S(!1);
1545
- V(() => {
1546
- if (!n) {
1547
- i("This invite link is missing a token.");
1548
- return;
1549
- }
1550
- let g = !1;
1551
- return pt(n).then((h) => {
1552
- g || t(`/${h.slug}`, { replace: !0 });
1553
- }).catch(async (h) => {
1554
- if (g) return;
1555
- const p = h && typeof h == "object" && "code" in h ? h.code : void 0;
1556
- if (p === "invite_email_mismatch" || p === "unauthorized") {
1557
- const b = await we().catch(() => null);
1558
- if (g) return;
1559
- d((b == null ? void 0 : b.user.email) ?? null), u(!0);
1560
- return;
1561
- }
1562
- const v = h instanceof Error ? h.message : "Could not accept invite";
1563
- i(yr(p, v));
1564
- }), () => {
1565
- g = !0;
1566
- };
1567
- }, [t, n]);
1568
- async function c() {
1569
- await M().signOut().catch(() => {
1570
- }), ee(), B.wipe(), window.location.assign(window.location.href);
1571
- }
1572
- return /* @__PURE__ */ k(ie, { centered: !0, children: [
1573
- /* @__PURE__ */ o(J, { title: "Accept invite" }),
1574
- a ? /* @__PURE__ */ k(re, { children: [
1575
- /* @__PURE__ */ o(R, { children: l ? `You're signed in as ${l}. This invite is for ${r || "someone else"}.` : `Sign in as ${r || "the invited email"} to join.` }),
1576
- /* @__PURE__ */ o(R, { size: "sm", tone: "muted", children: "Password and GitHub stay on the next screen. A magic link sends one more email to that address." }),
1577
- /* @__PURE__ */ o("div", { children: /* @__PURE__ */ o(ae, { type: "button", variant: "secondary", onClick: () => void c(), children: r ? `Sign in as ${r}` : "Sign in to continue" }) })
1578
- ] }) : s ? /* @__PURE__ */ o(R, { tone: "danger", children: s }) : /* @__PURE__ */ o(R, { tone: "muted", children: "Joining workspace…" })
1579
- ] });
1580
- }
1581
- function br() {
1582
- const { email: e, userId: t } = Ce(), [n, r] = S(""), [s, i] = S(null), [l, d] = S(null), [a, u] = S(!1);
1583
- V(() => {
1584
- we().then((g) => {
1585
- g != null && g.user.name && r(g.user.name);
1586
- });
1587
- }, []);
1588
- async function c(g) {
1589
- g.preventDefault(), u(!0), d(null), i(null);
1590
- const h = await M().updateUser({ name: n });
1591
- if (u(!1), h.error) {
1592
- d(h.error.message ?? "Could not save name");
1593
- return;
1594
- }
1595
- i("Name saved. New publishes will use it.");
1596
- }
1597
- return /* @__PURE__ */ k(ie, { children: [
1598
- /* @__PURE__ */ o(
1599
- J,
1600
- {
1601
- title: "User settings",
1602
- description: "Your account on this Backmatter instance."
1603
- }
1604
- ),
1605
- /* @__PURE__ */ k(re, { gap: "lg", children: [
1606
- /* @__PURE__ */ o(gt, { children: /* @__PURE__ */ o("form", { onSubmit: (g) => void c(g), children: /* @__PURE__ */ k(re, { children: [
1607
- /* @__PURE__ */ o(R, { as: "h2", size: "lg", weight: "medium", children: "Account" }),
1608
- /* @__PURE__ */ o(Q, { label: "Name", children: /* @__PURE__ */ o(Z, { value: n, onChange: (g) => r(g.target.value), autoComplete: "name" }) }),
1609
- /* @__PURE__ */ o(Q, { label: "Email", children: /* @__PURE__ */ o(
1610
- Z,
1611
- {
1612
- type: "email",
1613
- value: e,
1614
- readOnly: !0,
1615
- autoComplete: "off",
1616
- spellCheck: !1
1617
- }
1618
- ) }),
1619
- /* @__PURE__ */ o(Q, { label: "User ID", hint: "Stable id for this account.", children: /* @__PURE__ */ o(
1620
- Z,
1621
- {
1622
- value: t,
1623
- readOnly: !0,
1624
- autoComplete: "off",
1625
- spellCheck: !1
1626
- }
1627
- ) }),
1628
- l ? /* @__PURE__ */ o(R, { tone: "danger", children: l }) : null,
1629
- s ? /* @__PURE__ */ o(R, { tone: "muted", children: s }) : null,
1630
- /* @__PURE__ */ o("div", { children: /* @__PURE__ */ o(ae, { type: "submit", disabled: a, children: a ? "Saving…" : "Save name" }) })
1631
- ] }) }) }),
1632
- /* @__PURE__ */ k("div", { children: [
1633
- /* @__PURE__ */ o(
1634
- J,
1635
- {
1636
- title: "Connectors",
1637
- description: "Personal MCP servers that follow you across workspaces.",
1638
- compact: !0
1639
- }
1640
- ),
1641
- /* @__PURE__ */ o(mt, { scope: "user", canEdit: !0 })
1642
- ] })
1643
- ] })
1644
- ] });
1645
- }
1646
- function wr({
1647
- email: e
1648
- }) {
1649
- const [t] = be(), n = t.get("id") ?? "", [r, s] = S("idle"), [i, l] = S(null);
1650
- return /* @__PURE__ */ o("main", { className: "x78zum5 x9f619 xh8yej3 x1ov3xa9 x6s0dn4 xl56j7k x1y5dg2c x86kjsi xqjzbou", children: /* @__PURE__ */ k("div", { className: "x78zum5 xh8yej3 x1va8c73 xdt5ytf x1cy8zhl x11cgr9k x9f619 xmkeg23 x1y0btm7 x1j0qoeq x13oidi x1hb2obb x1y5dg2c x1vrk1b5", children: [
1651
- /* @__PURE__ */ o(R, { as: "h1", size: "xl", weight: "medium", children: "Allow the CLI" }),
1652
- /* @__PURE__ */ k(R, { tone: "muted", children: [
1653
- "This signs the CLI in as ",
1654
- e,
1655
- ". It can act in any workspace you belong to. It does not pick one."
1656
- ] }),
1657
- r === "done" ? /* @__PURE__ */ o(R, { children: "You can return to the terminal." }) : null,
1658
- i ? /* @__PURE__ */ o(R, { tone: "danger", children: i }) : null,
1659
- r === "done" ? null : /* @__PURE__ */ o(ae, { disabled: !n, onClick: () => {
1660
- l(null), xt(n).then(() => s("done")).catch((d) => {
1661
- s("error"), l(d instanceof Error ? d.message : "Could not approve");
1662
- });
1663
- }, children: "Allow" })
1664
- ] }) });
1665
- }
1666
- function kr({
1667
- userId: e
1668
- }) {
1669
- const [t, n] = S({
1670
- kind: "working"
1671
- });
1672
- return V(() => {
1673
- const r = yt(window.location.search);
1674
- if (!r) {
1675
- n({
1676
- kind: "error",
1677
- message: "This link is missing the workspace or the page to return to."
1678
- });
1679
- return;
1680
- }
1681
- let s = !1;
1682
- return (async () => {
1683
- try {
1684
- const {
1685
- workspace: i
1686
- } = await vt(r.workspaceId), l = bt(r.returnUrl, i.siteUrls);
1687
- if (!l) {
1688
- n({
1689
- kind: "error",
1690
- message: "That site is not listed under this workspace. Add its origin in Settings → General first."
1691
- });
1692
- return;
1693
- }
1694
- const {
1695
- ticket: d
1696
- } = await wt(i.id, {
1697
- redirect: l.redirect,
1698
- tree: e
1699
- });
1700
- if (s) return;
1701
- window.location.replace(kt(l.origin, d));
1702
- } catch (i) {
1703
- if (s) return;
1704
- n({
1705
- kind: "error",
1706
- message: i instanceof Error ? i.message : "Could not open the site."
1707
- });
1708
- }
1709
- })(), () => {
1710
- s = !0;
1711
- };
1712
- }, [e]), /* @__PURE__ */ o("div", { className: "x1ov3xa9 xrvj5dj x1ku5rj1 x1t7e3gq", children: /* @__PURE__ */ o("div", { className: "x78zum5 xdt5ytf x1ndbd79 x1lr1uin x1t7e3gq x4pepcl x1d0qn7y", children: t.kind === "working" ? /* @__PURE__ */ k(me, { children: [
1713
- /* @__PURE__ */ o(R, { size: "lg", weight: "medium", children: "Opening your site…" }),
1714
- /* @__PURE__ */ o(R, { tone: "muted", children: "Setting up editing on the site and sending you back." })
1715
- ] }) : /* @__PURE__ */ k(me, { children: [
1716
- /* @__PURE__ */ o(R, { size: "lg", weight: "medium", children: "Could not open the site" }),
1717
- /* @__PURE__ */ o(R, { tone: "muted", children: t.message }),
1718
- /* @__PURE__ */ o(Be, { to: "/", variant: "secondary", children: "Back to the dashboard" })
1719
- ] }) }) });
1720
- }
1721
- function Sr(e) {
1722
- if (!St()) return !1;
1723
- const t = e.replace(/\/$/, "") || "/";
1724
- return t === "/__ui" || /^\/__ui\/[^/]+$/.test(t);
1725
- }
1726
- const Er = tt(() => import("./UiKitApp-C269OA8v.js").then((e) => ({
1727
- default: e.UiKitApp
1728
- })));
1729
- function jr() {
1730
- return /* @__PURE__ */ o(Et, { children: /* @__PURE__ */ o(Rt, { children: /* @__PURE__ */ o(Rr, {}) }) });
1731
- }
1732
- function Rr() {
1733
- const e = _t(), [t, n] = S(() => {
1734
- const r = Ot();
1735
- return r ? {
1736
- user: r
1737
- } : "loading";
1738
- });
1739
- return V(() => {
1740
- we().then((r) => {
1741
- if (!(r != null && r.user)) {
1742
- ee(), B.wipe(), n(null);
1743
- return;
1744
- }
1745
- if (Tt(r.user), n({
1746
- user: {
1747
- id: r.user.id,
1748
- email: r.user.email
1749
- }
1750
- }), B.getState().sessionUserId !== r.user.id) {
1751
- const s = Pt(window.location.pathname);
1752
- B.hydrate(r.user.id, s ?? qe(r.user.id));
1753
- }
1754
- }).catch(() => {
1755
- ee(), B.wipe(), n(null);
1756
- });
1757
- }, []), Sr(e.pathname) ? /* @__PURE__ */ o(nt, { fallback: /* @__PURE__ */ o("div", { className: "x1y5dg2c", children: /* @__PURE__ */ o(R, { tone: "muted", children: "Loading kit…" }) }), children: /* @__PURE__ */ o(Er, {}) }) : t === "loading" ? /* @__PURE__ */ o(jt, {}) : t ? e.pathname.replace(/\/$/, "") === "/enter" ? /* @__PURE__ */ o(kr, { userId: t.user.id }) : Lt(e.pathname) ? /* @__PURE__ */ o(wr, { email: t.user.email }) : /* @__PURE__ */ o(At, { user: t.user, children: /* @__PURE__ */ o(Nt, { children: /* @__PURE__ */ o(Ut, { userId: t.user.id, email: t.user.email, onLogout: () => {
1758
- ee(), B.wipe(), M().signOut().then(() => {
1759
- n(null);
1760
- }).catch(() => {
1761
- n(null);
1762
- });
1763
- }, children: /* @__PURE__ */ k(Ct, { children: [
1764
- /* @__PURE__ */ o(F, { path: "/", element: /* @__PURE__ */ o(hr, {}) }),
1765
- /* @__PURE__ */ o(F, { path: "/workspaces", element: /* @__PURE__ */ o(mr, {}) }),
1766
- /* @__PURE__ */ o(F, { path: "/workspaces/new", element: /* @__PURE__ */ o(xr, {}) }),
1767
- /* @__PURE__ */ o(F, { path: "/invite", element: /* @__PURE__ */ o(vr, {}) }),
1768
- /* @__PURE__ */ o(F, { path: "/account", element: /* @__PURE__ */ o(br, {}) }),
1769
- /* @__PURE__ */ o(F, { path: "/workspaces/:workspaceId/*", element: /* @__PURE__ */ o(It, {}) }),
1770
- qt(),
1771
- /* @__PURE__ */ o(F, { path: "*", element: /* @__PURE__ */ o(ze, { to: "/", replace: !0 }) })
1772
- ] }) }) }) }) : /* @__PURE__ */ o(ur, {});
1773
- }
1774
- export {
1775
- jr as A,
1776
- gr as L,
1777
- pr as a,
1778
- Sr as i
1779
- };