primitive-app 3.2.0-alpha.2 → 3.2.0-alpha.3

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, c as t, i as n, n as r, o as i, r as a, s as o, t as s } from "./lib-B7ZH2Pdd.js";
1
+ import { a as e, c as t, i as n, n as r, o as i, r as a, s as o, t as s } from "./lib-CknnILDr.js";
2
2
  import * as c from "vue";
3
3
  import { Comment as l, Fragment as u, Teleport as d, camelize as f, cloneVNode as p, computed as m, createBlock as h, createCommentVNode as g, createElementBlock as _, createElementVNode as v, createTextVNode as y, createVNode as b, customRef as x, defineComponent as S, getCurrentInstance as C, getCurrentScope as w, guardReactiveProps as T, h as E, inject as D, isRef as O, isVNode as k, markRaw as A, mergeDefaults as j, mergeProps as M, nextTick as N, normalizeClass as P, normalizeProps as ee, normalizeStyle as F, onBeforeUnmount as te, onMounted as I, onScopeDispose as ne, onUnmounted as re, onUpdated as L, openBlock as R, provide as ie, reactive as z, ref as B, renderList as V, renderSlot as H, resolveDynamicComponent as ae, toDisplayString as U, toHandlerKey as oe, toRaw as se, toRef as ce, toRefs as le, toValue as ue, triggerRef as de, unref as W, useAttrs as fe, vModelSelect as pe, vModelText as me, vShow as he, watch as G, watchEffect as ge, watchPostEffect as _e, withCtx as K, withDirectives as ve, withKeys as ye, withMemo as be, withModifiers as q } from "vue";
4
4
  import { defineStore as xe } from "pinia";
@@ -9078,29 +9078,25 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9078
9078
  J("Failed to load documents: " + Y(e)), r.value = !0;
9079
9079
  }
9080
9080
  }
9081
- let s = null, c = null;
9081
+ let s = null;
9082
9082
  I(async () => {
9083
- k.value && (j = new ResizeObserver((e) => {
9083
+ O.value && (A = new ResizeObserver((e) => {
9084
9084
  for (let t of e) {
9085
9085
  let e = t.contentRect.width;
9086
- A.value = e < 500;
9086
+ k.value = e < 500;
9087
9087
  }
9088
- }), j.observe(k.value)), o();
9089
- let e = await i.getClientAsync(), t = (e) => {
9090
- e.action === "accepted" && o();
9091
- };
9092
- e.on("invitation", t), s = () => e.off("invitation", t);
9093
- let n = () => {
9088
+ }), A.observe(O.value)), o();
9089
+ let e = await i.getClientAsync(), t = () => {
9094
9090
  o();
9095
9091
  };
9096
- e.on("documentMetadataChanged", n), c = () => e.off("documentMetadataChanged", n);
9092
+ e.on("documentMetadataChanged", t), s = () => e.off("documentMetadataChanged", t);
9097
9093
  }), re(() => {
9098
- s?.(), c?.(), j?.disconnect();
9094
+ s?.(), A?.disconnect();
9099
9095
  });
9100
- let l = m(() => t.currentDocumentId), d = m(() => n.value.find((e) => e.documentId === l.value) ?? null);
9101
- async function f(e) {
9096
+ let c = m(() => t.currentDocumentId), l = m(() => n.value.find((e) => e.documentId === c.value) ?? null);
9097
+ async function d(e) {
9102
9098
  if (t.currentDocumentId !== e) {
9103
- p.value = null;
9099
+ f.value = null;
9104
9100
  try {
9105
9101
  await t.openDocument(e);
9106
9102
  let r = n.value.find((t) => t.documentId === e);
@@ -9110,24 +9106,24 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9110
9106
  }
9111
9107
  }
9112
9108
  }
9113
- let p = B(null), x = B(!1), S = B(""), C = B(null);
9114
- G(l, () => {
9115
- p.value = null, S.value = "";
9109
+ let f = B(null), p = B(!1), x = B(""), S = B(null);
9110
+ G(c, () => {
9111
+ f.value = null, x.value = "";
9116
9112
  });
9117
- let w = B(0);
9118
- function T(e) {
9119
- w.value = e;
9113
+ let C = B(0);
9114
+ function w(e) {
9115
+ C.value = e;
9120
9116
  }
9121
- function E() {
9122
- C.value?.executeBulkDelete();
9117
+ function T() {
9118
+ S.value?.executeBulkDelete();
9123
9119
  }
9124
- function D() {
9125
- C.value?.clearSelection(), w.value = 0;
9120
+ function E() {
9121
+ S.value?.clearSelection(), C.value = 0;
9126
9122
  }
9127
- let O = m(() => {
9128
- let e = d.value?.permission;
9123
+ let D = m(() => {
9124
+ let e = l.value?.permission;
9129
9125
  return e ? e !== "reader" : !1;
9130
- }), k = B(null), A = B(!1), j = null;
9126
+ }), O = B(null), k = B(!1), A = null;
9131
9127
  return (e, t) => (R(), _("div", Rd, [
9132
9128
  b(W(Qt), {
9133
9129
  position: "bottom-right",
@@ -9135,9 +9131,9 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9135
9131
  }),
9136
9132
  b(Au, {
9137
9133
  documents: n.value,
9138
- "selected-doc-id": l.value,
9134
+ "selected-doc-id": c.value,
9139
9135
  "document-list-loaded": r.value,
9140
- onSelectDocument: f
9136
+ onSelectDocument: d
9141
9137
  }, null, 8, [
9142
9138
  "documents",
9143
9139
  "selected-doc-id",
@@ -9145,15 +9141,15 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9145
9141
  ]),
9146
9142
  v("div", zd, [v("div", {
9147
9143
  ref_key: "toolbarRef",
9148
- ref: k,
9144
+ ref: O,
9149
9145
  class: "flex items-center justify-between px-3 py-2 border-b border-border relative shrink-0"
9150
9146
  }, [
9151
- w.value > 0 ? (R(), _("div", Bd, [v("div", Vd, [v("span", Hd, U(w.value) + " selected", 1), v("button", {
9147
+ C.value > 0 ? (R(), _("div", Bd, [v("div", Vd, [v("span", Hd, U(C.value) + " selected", 1), v("button", {
9152
9148
  class: "text-[10px] text-muted-foreground hover:text-foreground",
9153
- onClick: D
9149
+ onClick: E
9154
9150
  }, " Clear ")]), v("button", {
9155
9151
  class: "px-2 py-1 text-xs text-destructive hover:bg-destructive/10 rounded flex items-center gap-1",
9156
- onClick: E
9152
+ onClick: T
9157
9153
  }, [...t[7] ||= [v("svg", {
9158
9154
  class: "w-3.5 h-3.5",
9159
9155
  fill: "none",
@@ -9165,7 +9161,7 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9165
9161
  "stroke-width": "2",
9166
9162
  d: "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
9167
9163
  })], -1), y(" Delete ", -1)]])])) : g("", !0),
9168
- v("div", Ud, [v("div", Wd, [v("span", Gd, U(d.value?.title ?? d.value?.documentId ?? "Select a document"), 1)]), l.value ? (R(), _("div", Kd, [t[8] ||= v("svg", {
9164
+ v("div", Ud, [v("div", Wd, [v("span", Gd, U(l.value?.title ?? l.value?.documentId ?? "Select a document"), 1)]), c.value ? (R(), _("div", Kd, [t[8] ||= v("svg", {
9169
9165
  class: "absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground",
9170
9166
  fill: "none",
9171
9167
  stroke: "currentColor",
@@ -9176,15 +9172,15 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9176
9172
  "stroke-width": "2",
9177
9173
  d: "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
9178
9174
  })], -1), ve(v("input", {
9179
- "onUpdate:modelValue": t[0] ||= (e) => S.value = e,
9175
+ "onUpdate:modelValue": t[0] ||= (e) => x.value = e,
9180
9176
  type: "text",
9181
- placeholder: A.value ? "Blob ID…" : "Search by blob ID…",
9182
- class: P(["pl-7 pr-2 py-1 text-xs bg-muted border border-border rounded focus:outline-none focus:ring-1 focus:ring-ring", A.value ? "w-28" : "w-44"])
9183
- }, null, 10, qd), [[me, S.value]])])) : g("", !0)]),
9184
- l.value ? (R(), _("div", Jd, [r.value ? (R(), _(u, { key: 1 }, [v("button", {
9177
+ placeholder: k.value ? "Blob ID…" : "Search by blob ID…",
9178
+ class: P(["pl-7 pr-2 py-1 text-xs bg-muted border border-border rounded focus:outline-none focus:ring-1 focus:ring-ring", k.value ? "w-28" : "w-44"])
9179
+ }, null, 10, qd), [[me, x.value]])])) : g("", !0)]),
9180
+ c.value ? (R(), _("div", Jd, [r.value ? (R(), _(u, { key: 1 }, [v("button", {
9185
9181
  class: "p-1 hover:bg-muted rounded text-muted-foreground",
9186
9182
  title: "Refresh",
9187
- onClick: t[1] ||= (e) => C.value?.refresh()
9183
+ onClick: t[1] ||= (e) => S.value?.refresh()
9188
9184
  }, [...t[11] ||= [v("svg", {
9189
9185
  class: "w-3.5 h-3.5",
9190
9186
  fill: "none",
@@ -9195,11 +9191,11 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9195
9191
  "stroke-linejoin": "round",
9196
9192
  "stroke-width": "2",
9197
9193
  d: "M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
9198
- })], -1)]]), O.value ? (R(), _("button", {
9194
+ })], -1)]]), D.value ? (R(), _("button", {
9199
9195
  key: 0,
9200
- class: P(["text-xs bg-primary text-primary-foreground rounded hover:bg-primary/90 flex items-center", A.value ? "p-1.5" : "px-2 py-1 gap-1"]),
9196
+ class: P(["text-xs bg-primary text-primary-foreground rounded hover:bg-primary/90 flex items-center", k.value ? "p-1.5" : "px-2 py-1 gap-1"]),
9201
9197
  title: "Upload",
9202
- onClick: t[2] ||= (e) => x.value = !0
9198
+ onClick: t[2] ||= (e) => p.value = !0
9203
9199
  }, [t[12] ||= v("svg", {
9204
9200
  class: "w-3 h-3 shrink-0",
9205
9201
  fill: "none",
@@ -9210,18 +9206,18 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9210
9206
  "stroke-linejoin": "round",
9211
9207
  "stroke-width": "2",
9212
9208
  d: "M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"
9213
- })], -1), A.value ? g("", !0) : (R(), _("span", Yd, "Upload"))], 2)) : g("", !0)], 64)) : (R(), _(u, { key: 0 }, [t[9] ||= v("div", { class: "w-6 h-6 bg-muted rounded animate-pulse" }, null, -1), t[10] ||= v("div", { class: "w-16 h-6 bg-muted rounded animate-pulse" }, null, -1)], 64))])) : g("", !0)
9214
- ], 512), l.value ? (R(), h(Ld, {
9209
+ })], -1), k.value ? g("", !0) : (R(), _("span", Yd, "Upload"))], 2)) : g("", !0)], 64)) : (R(), _(u, { key: 0 }, [t[9] ||= v("div", { class: "w-6 h-6 bg-muted rounded animate-pulse" }, null, -1), t[10] ||= v("div", { class: "w-16 h-6 bg-muted rounded animate-pulse" }, null, -1)], 64))])) : g("", !0)
9210
+ ], 512), c.value ? (R(), h(Ld, {
9215
9211
  key: 1,
9216
9212
  ref_key: "blobTableRef",
9217
- ref: C,
9218
- "document-id": l.value,
9219
- "search-query": S.value,
9220
- "can-write": O.value,
9221
- "upload-dialog-open": x.value,
9222
- onSelectBlob: t[3] ||= (e) => p.value = e,
9223
- "onUpdate:uploadDialogOpen": t[4] ||= (e) => x.value = e,
9224
- onSelectionChange: T
9213
+ ref: S,
9214
+ "document-id": c.value,
9215
+ "search-query": x.value,
9216
+ "can-write": D.value,
9217
+ "upload-dialog-open": p.value,
9218
+ onSelectBlob: t[3] ||= (e) => f.value = e,
9219
+ "onUpdate:uploadDialogOpen": t[4] ||= (e) => p.value = e,
9220
+ onSelectionChange: w
9225
9221
  }, null, 8, [
9226
9222
  "document-id",
9227
9223
  "search-query",
@@ -9243,11 +9239,11 @@ var Ll = { class: "relative h-full flex" }, Rl = ["title"], zl = { class: "w-64
9243
9239
  v("p", { class: "text-xs text-muted-foreground/70 mt-1" }, " Choose a document from the left panel to explore its blobs ", -1)
9244
9240
  ]]))]),
9245
9241
  v("div", Zd, [b(Cu, {
9246
- "document-id": l.value ?? "",
9247
- "selected-blob": p.value,
9248
- "can-write": O.value,
9249
- onDeleteBlob: t[5] ||= (e) => C.value?.handleExternalDelete(e),
9250
- onReloadBlobs: t[6] ||= (e) => C.value?.refresh()
9242
+ "document-id": c.value ?? "",
9243
+ "selected-blob": f.value,
9244
+ "can-write": D.value,
9245
+ onDeleteBlob: t[5] ||= (e) => S.value?.handleExternalDelete(e),
9246
+ onReloadBlobs: t[6] ||= (e) => S.value?.refresh()
9251
9247
  }, null, 8, [
9252
9248
  "document-id",
9253
9249
  "selected-blob",
@@ -10359,36 +10355,20 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10359
10355
  G(() => n.documentId, () => {
10360
10356
  a.value = [], s.value = [], c.value = [], l.value = !0, M();
10361
10357
  }, { immediate: !0 });
10362
- let N = null, ee = !1;
10363
- I(async () => {
10364
- ee = !0;
10365
- try {
10366
- let e = await i.getClientAsync();
10367
- if (!ee) return;
10368
- let r = (e) => {
10369
- e.documentId === n.documentId && (t.debug("Invitation event received – reloading sharing data", { action: e.action }), M(!0));
10370
- };
10371
- e.on("invitation", r), N = () => e.off("invitation", r);
10372
- } catch (e) {
10373
- t.warn("Could not subscribe to invitation events:", e);
10374
- }
10375
- }), re(() => {
10376
- ee = !1, N?.();
10377
- });
10378
- let F = m(() => {
10358
+ let N = m(() => {
10379
10359
  let e = a.value.find((e) => e.userId === r.value);
10380
10360
  return e ? Vf(e.permission) : !1;
10381
- }), te = m(() => {
10361
+ }), ee = m(() => {
10382
10362
  let e = a.value.find((e) => e.userId === r.value);
10383
10363
  return e ? Vf(e.permission) || e.permission === "read-write" : !1;
10384
10364
  });
10385
- function ne(e) {
10365
+ function F(e) {
10386
10366
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e);
10387
10367
  }
10388
- function L(e) {
10368
+ function te(e) {
10389
10369
  return e.split(" ").map((e) => e[0]).join("").toUpperCase().slice(0, 2);
10390
10370
  }
10391
- function ie(e) {
10371
+ function I(e) {
10392
10372
  let t = [
10393
10373
  "bg-blue-500",
10394
10374
  "bg-green-500",
@@ -10400,10 +10380,10 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10400
10380
  for (let t = 0; t < e.length; t++) n = e.charCodeAt(t) + ((n << 5) - n);
10401
10381
  return t[Math.abs(n) % t.length] ?? "bg-blue-500";
10402
10382
  }
10403
- async function z() {
10383
+ async function ne() {
10404
10384
  let e = d.value.trim().toLowerCase();
10405
10385
  if (!e) return;
10406
- if (!ne(e)) {
10386
+ if (!F(e)) {
10407
10387
  J("Please enter a valid email address.");
10408
10388
  return;
10409
10389
  }
@@ -10434,7 +10414,7 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10434
10414
  p.value = !1;
10435
10415
  }
10436
10416
  }
10437
- async function H(e) {
10417
+ async function re(e) {
10438
10418
  let r = [...s.value];
10439
10419
  s.value = s.value.filter((t) => t.email !== e);
10440
10420
  try {
@@ -10443,7 +10423,7 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10443
10423
  s.value = r, t.error("Failed to cancel invitation:", e), J("Failed to cancel invitation: " + Y(e));
10444
10424
  }
10445
10425
  }
10446
- async function ae(e, r) {
10426
+ async function L(e, r) {
10447
10427
  let o = a.value.slice();
10448
10428
  a.value = a.value.map((t) => t.userId === e ? {
10449
10429
  ...t,
@@ -10458,7 +10438,7 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10458
10438
  a.value = o, t.error("Failed to update permission:", e), J("Failed to update permission: " + Y(e));
10459
10439
  }
10460
10440
  }
10461
- async function oe(e) {
10441
+ async function ie(e) {
10462
10442
  let r = a.value.slice();
10463
10443
  a.value = a.value.filter((t) => t.userId !== e);
10464
10444
  try {
@@ -10467,30 +10447,30 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10467
10447
  a.value = r, t.error("Failed to remove permission:", e), J("Failed to remove permission: " + Y(e));
10468
10448
  }
10469
10449
  }
10470
- function se(e, t, n) {
10450
+ function z(e, t, n) {
10471
10451
  let i = a.value.find((t) => t.userId === e);
10472
- t === "remove" ? (i && (n.value = i.permission, C.value = i.name || i.email), S.value = e, w.value = e === r.value, x.value = !0) : t === "transfer-ownership" ? (i && (n.value = i.permission, O.value = i.name || i.email), D.value = e, E.value = !0) : t === "reader" && e === r.value ? (i && (n.value = i.permission), A.value = !0) : ae(e, t);
10452
+ t === "remove" ? (i && (n.value = i.permission, C.value = i.name || i.email), S.value = e, w.value = e === r.value, x.value = !0) : t === "transfer-ownership" ? (i && (n.value = i.permission, O.value = i.name || i.email), D.value = e, E.value = !0) : t === "reader" && e === r.value ? (i && (n.value = i.permission), A.value = !0) : L(e, t);
10473
10453
  }
10474
- function ce() {
10475
- j.value = !0, ae(r.value, "reader").finally(() => {
10454
+ function H() {
10455
+ j.value = !0, L(r.value, "reader").finally(() => {
10476
10456
  j.value = !1, A.value = !1;
10477
10457
  });
10478
10458
  }
10479
- function le() {
10459
+ function ae() {
10480
10460
  A.value = !1;
10481
10461
  }
10482
- function ue() {
10483
- T.value = !0, oe(S.value).finally(() => {
10462
+ function oe() {
10463
+ T.value = !0, ie(S.value).finally(() => {
10484
10464
  T.value = !1, x.value = !1, S.value = "", C.value = "", w.value = !1;
10485
10465
  });
10486
10466
  }
10487
- function de() {
10467
+ function se() {
10488
10468
  x.value = !1, S.value = "", C.value = "", w.value = !1;
10489
10469
  }
10490
- function fe(e) {
10470
+ function ce(e) {
10491
10471
  S.value = e.userId, C.value = e.name || e.email, w.value = !0, x.value = !0;
10492
10472
  }
10493
- async function he(e) {
10473
+ async function le(e) {
10494
10474
  let o = a.value.slice();
10495
10475
  a.value = a.value.map((t) => t.userId === e ? {
10496
10476
  ...t,
@@ -10514,10 +10494,10 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10514
10494
  k.value = !1, E.value = !1, D.value = "", O.value = "";
10515
10495
  }
10516
10496
  }
10517
- function ge() {
10518
- he(D.value);
10497
+ function ue() {
10498
+ le(D.value);
10519
10499
  }
10520
- function _e() {
10500
+ function de() {
10521
10501
  E.value = !1, D.value = "", O.value = "";
10522
10502
  }
10523
10503
  return (t, n) => (R(), _("div", null, [
@@ -10533,28 +10513,28 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10533
10513
  (R(!0), _(u, null, V(a.value, (e) => (R(), _("div", {
10534
10514
  key: e.userId,
10535
10515
  class: "flex items-center justify-between gap-2 text-xs"
10536
- }, [v("div", Cp, [v("div", { class: P(["w-5 h-5 rounded-full flex items-center justify-center text-[10px] text-white font-medium flex-shrink-0", ie(e.name || e.email)]) }, U(L(e.name || e.email)), 3), v("div", wp, [v("div", {
10516
+ }, [v("div", Cp, [v("div", { class: P(["w-5 h-5 rounded-full flex items-center justify-center text-[10px] text-white font-medium flex-shrink-0", I(e.name || e.email)]) }, U(te(e.name || e.email)), 3), v("div", wp, [v("div", {
10537
10517
  class: "font-medium truncate",
10538
10518
  title: e.name || e.email
10539
10519
  }, U(e.name || e.email), 9, Tp), e.name ? (R(), _("div", {
10540
10520
  key: 0,
10541
10521
  class: "text-[10px] text-muted-foreground truncate",
10542
10522
  title: e.email
10543
- }, U(e.email), 9, Ep)) : g("", !0)])]), W(Vf)(e.permission) ? (R(), _("span", Dp, " Owner ")) : te.value ? (R(), _("select", {
10523
+ }, U(e.email), 9, Ep)) : g("", !0)])]), W(Vf)(e.permission) ? (R(), _("span", Dp, " Owner ")) : ee.value ? (R(), _("select", {
10544
10524
  key: 1,
10545
10525
  value: e.permission,
10546
10526
  class: "text-[10px] px-1.5 py-0.5 bg-muted border border-border text-foreground cursor-pointer focus:outline-none focus:ring-1 focus:ring-ring rounded appearance-auto flex-shrink-0",
10547
- onChange: (t) => se(e.userId, t.target.value, t.target)
10527
+ onChange: (t) => z(e.userId, t.target.value, t.target)
10548
10528
  }, [
10549
10529
  n[8] ||= v("option", { value: "read-write" }, "Editor", -1),
10550
10530
  n[9] ||= v("option", { value: "reader" }, "Viewer", -1),
10551
10531
  n[10] ||= v("option", { disabled: "" }, "───", -1),
10552
- F.value && e.userId !== r.value && e.permission === "read-write" ? (R(), _("option", kp, " Transfer Ownership ")) : g("", !0),
10532
+ N.value && e.userId !== r.value && e.permission === "read-write" ? (R(), _("option", kp, " Transfer Ownership ")) : g("", !0),
10553
10533
  v("option", Ap, U(e.userId === r.value ? "Leave" : "Remove"), 1)
10554
10534
  ], 40, Op)) : e.userId === r.value ? (R(), _("div", jp, [v("span", Mp, U(W(zf)(e.permission)), 1), v("button", {
10555
10535
  class: "text-muted-foreground hover:text-destructive flex-shrink-0",
10556
10536
  title: "Leave document",
10557
- onClick: (t) => fe(e)
10537
+ onClick: (t) => ce(e)
10558
10538
  }, [...n[11] ||= [v("svg", {
10559
10539
  class: "w-3 h-3",
10560
10540
  fill: "none",
@@ -10584,7 +10564,7 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10584
10564
  d: "M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
10585
10565
  })]), y(" Pending invitation ")], -1)])]), v("button", {
10586
10566
  class: "text-[10px] text-muted-foreground hover:text-destructive flex-shrink-0",
10587
- onClick: (t) => H(e.email)
10567
+ onClick: (t) => re(e.email)
10588
10568
  }, " Cancel ", 8, Rp)]))), 128)),
10589
10569
  (R(!0), _(u, null, V(c.value, (e) => (R(), _("div", {
10590
10570
  key: `${e.groupType}/${e.groupId}`,
@@ -10615,7 +10595,7 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10615
10595
  type: "email",
10616
10596
  class: "w-full px-1.5 py-1 text-[10px] border border-border rounded focus:outline-none focus:ring-1 focus:ring-ring",
10617
10597
  placeholder: "Email address",
10618
- onKeydown: ye(q(z, ["prevent"]), ["enter"])
10598
+ onKeydown: ye(q(ne, ["prevent"]), ["enter"])
10619
10599
  }, null, 40, Gp), [[me, d.value]]), v("div", Kp, [
10620
10600
  ve(v("select", {
10621
10601
  "onUpdate:modelValue": n[1] ||= (e) => f.value = e,
@@ -10623,8 +10603,8 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10623
10603
  }, [...n[15] ||= [v("option", { value: "read-write" }, "Editor", -1), v("option", { value: "reader" }, "Viewer", -1)]], 512), [[pe, f.value]]),
10624
10604
  v("button", {
10625
10605
  class: "px-2 py-0.5 text-[10px] bg-primary text-primary-foreground rounded hover:bg-primary/90 disabled:opacity-50 flex items-center gap-1",
10626
- disabled: p.value || !d.value.trim() || !ne(d.value.trim()),
10627
- onClick: z
10606
+ disabled: p.value || !d.value.trim() || !F(d.value.trim()),
10607
+ onClick: ne
10628
10608
  }, [p.value ? (R(), _("span", Jp)) : g("", !0), y(" " + U(p.value ? "Sending..." : "Send"), 1)], 8, qp),
10629
10609
  v("button", {
10630
10610
  class: "px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground",
@@ -10646,10 +10626,10 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10646
10626
  "confirm-label": w.value ? "Leave" : "Remove",
10647
10627
  "confirming-label": w.value ? "Leaving..." : "Removing...",
10648
10628
  "is-deleting": T.value,
10649
- onConfirm: ue,
10650
- onCancel: de,
10629
+ onConfirm: oe,
10630
+ onCancel: se,
10651
10631
  "onUpdate:isOpen": n[5] ||= (e) => {
10652
- e || de();
10632
+ e || se();
10653
10633
  }
10654
10634
  }, null, 8, [
10655
10635
  "is-open",
@@ -10667,10 +10647,10 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10667
10647
  "confirm-label": "Change to Viewer",
10668
10648
  "confirming-label": "Changing...",
10669
10649
  "is-deleting": j.value,
10670
- onConfirm: ce,
10671
- onCancel: le,
10650
+ onConfirm: H,
10651
+ onCancel: ae,
10672
10652
  "onUpdate:isOpen": n[6] ||= (e) => {
10673
- e || le();
10653
+ e || ae();
10674
10654
  }
10675
10655
  }, null, 8, ["is-open", "is-deleting"]),
10676
10656
  b(kl, {
@@ -10681,10 +10661,10 @@ var Hf = { class: "flex items-center px-2 h-10 bg-muted border-b border-border r
10681
10661
  "confirm-label": "Transfer",
10682
10662
  "confirming-label": "Transferring...",
10683
10663
  "is-deleting": k.value,
10684
- onConfirm: ge,
10685
- onCancel: _e,
10664
+ onConfirm: ue,
10665
+ onCancel: de,
10686
10666
  "onUpdate:isOpen": n[7] ||= (e) => {
10687
- e || _e();
10667
+ e || de();
10688
10668
  }
10689
10669
  }, null, 8, [
10690
10670
  "is-open",
@@ -0,0 +1 @@
1
+ let e=require("js-bao-wss-client");var t={debug:0,info:1,warn:2,error:3,none:4},n=`warn`,r=class e{#e;scope;constructor(e,t){this.#e=e,this.scope=t}get level(){return this.#e.level}set level(e){this.setLevel(e)}debug(...e){this.#t(`debug`,e)}log(...e){this.#t(`info`,e,`log`)}warn(...e){this.#t(`warn`,e)}error(...e){this.#t(`error`,e)}shouldLog(e){return t[e]>=t[this.level]}getLevel(){return this.level}setLevel(e){e in t&&(this.#e.level=e)}forScope(t){let n=t.trim(),r=n?[...this.scope,n]:this.scope;return new e(this.#e,r)}#t(e,t,n){if(!this.shouldLog(e))return;let r=n??(e===`info`?`log`:e),i=this.scope.length?`[${this.scope.join(`:`)}]`:void 0,a=i?[i,...t]:t;console[r](...a)}},i={level:n},a=new r(i,[]).forScope(`PrimitiveApp`);function o(e){i.level=e}var s=a.forScope(`JsBaoClientService`);function c(){if(typeof window>`u`)return!1;let e=window.location.hostname;return e===`localhost`||e===`127.0.0.1`||e===`[::1]`||e.endsWith(`.localhost`)||e.endsWith(`.local`)}var l=new class{client=null;clientInitializationPromise=null;config=null;initialize(e){s.debug(`Initializing with config:`,{appId:e.appId?`${e.appId.substring(0,10)}...`:`MISSING`,apiUrl:e.apiUrl,wsUrl:e.wsUrl,oauthRedirectUri:e.oauthRedirectUri});let t=[];(!e.appId||e.appId===`MISSING_APP_ID`)&&t.push(`appId`),(!e.apiUrl||e.apiUrl===`MISSING_API_URL`)&&t.push(`apiUrl`),(!e.wsUrl||e.wsUrl===`MISSING_WS_URL`)&&t.push(`wsUrl`),(!e.oauthRedirectUri||e.oauthRedirectUri===`MISSING_OAUTH_REDIRECT_URI`)&&t.push(`oauthRedirectUri`),t.length>0&&(s.error(`❌ Configuration validation failed!`),s.error(`Missing or invalid fields:`,t),s.error(`This will cause OAuth and API calls to fail.`),s.error(`Identity (appId/apiUrl/wsUrl) comes from primitive/config.json via the primitiveEnv() Vite plugin — check that the project has one and that an environment is selected ('primitive env use <name>'). Callback and logging settings come from your .env files.`)),this.config=e}getConfig(){return this.config}async getClientAsync(){if(s.debug(`Getting client async`),this.clientInitializationPromise)return this.clientInitializationPromise;if(!this.config)throw Error(`JsBaoClientService not initialized. Call initialize() first.`);return this.clientInitializationPromise=(async()=>{s.debug(`=== INITIALIZING CLIENT ===`),s.debug(`Configuration:`,this.config);let t=await(0,e.initializeClient)(this.config);if(t.on(`status`,e=>{s.debug(`Client status changed:`,e)}),t.on(`error`,e=>{s.error(`Client error:`,e)}),this.client=t,c()&&(window.__primitiveAppClient=t,this.config?.models&&Array.isArray(this.config.models))){let e={};for(let t of this.config.models){let n=t.schema?.name;if(n){let r=n.charAt(0).toUpperCase()+n.slice(1);e[r]=t}}window.__primitiveAppModels=e,s.debug(`Registered models on window:`,Object.keys(e))}return s.debug(`=== CLIENT INITIALIZATION COMPLETE ===`),t})(),this.clientInitializationPromise}setExternalClient(e){s.debug(`Setting external client from host app`),this.client=e,this.clientInitializationPromise=Promise.resolve(e)}async clearClient(){s.debug(`Clearing client singleton...`),this.client&&(this.client.disconnect().catch(e=>{s.warn(`Background disconnect failed (this is usually harmless):`,e)}),this.client=null,this.clientInitializationPromise=null,c()&&(window.__primitiveAppClient=void 0,window.__primitiveAppModels=void 0))}};function u(e){l.initialize(e)}var d=a.forScope(`TestHarness`),f=`===TEST===`;async function p(e={}){let{networkSync:t=!1}=e,n=await l.getClientAsync(),r=`${f} ${`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}`;if(t){let{metadata:e}=await n.documents.create({title:r}),t=e.documentId,{doc:i}=await n.documents.open(t);if(!i)throw Error(`[TestHarness] Failed to open synced test document`);return n.setDefaultDocumentId(t),d.debug(`Created synced test document`,{docId:t}),m.set(t,{client:n,docId:t,networkSync:!0}),{docId:t}}let{metadata:i}=await n.documents.create({title:r,localOnly:!0}),a=i.documentId,{doc:o}=await n.documents.open(a,{waitForLoad:`local`,enableNetworkSync:!1});if(!o)throw Error(`[TestHarness] Failed to open test document`);return n.setDefaultDocumentId(a),d.debug(`Created test document`,{docId:a}),m.set(a,{client:n,docId:a,networkSync:!1}),{docId:a}}var m=new Map;async function h(e){let t=m.get(e.docId);if(!t){d.warn(`destroyTestDocument called with unknown handle`,{docId:e.docId});return}m.delete(e.docId);try{t.networkSync?await t.client.documents.delete(t.docId,{forceCloseIfOpen:!0}):(await t.client.documents.close(t.docId),await t.client.documents.evict(t.docId,{force:!0}))}catch(e){d.error(`Failed to destroy test document`,{docId:t.docId,err:e})}}async function g(){try{let e=await l.getClientAsync();d.debug(`[deleteAllTestDocuments] Starting cleanup...`),await e.syncMetadata({scope:`all`});let t=(await e.me.ownedDocuments()).filter(e=>e.title?.startsWith(f));if(t.length===0)return 0;d.debug(`[deleteAllTestDocuments] Found test documents to delete`,{count:t.length});let n=0;for(let r of t)try{e.documents.isOpen(r.documentId)&&await e.documents.close(r.documentId),await e.documents.evict(r.documentId,{force:!0}),n++}catch(e){d.error(`[deleteAllTestDocuments] Failed to delete test document`,{documentId:r.documentId,err:e})}return d.debug(`[deleteAllTestDocuments] Cleanup complete`,{evictedCount:n}),n}catch(e){return d.error(`[deleteAllTestDocuments] Top-level error during cleanup`,{err:e}),0}}function _(e){return e.flatMap(e=>e.tests.map(t=>({id:t.id,name:t.name,group:e.name,environment:t.environment??e.environment,run:t.run})))}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return _}});
@@ -72,7 +72,7 @@ var l = new class {
72
72
  oauthRedirectUri: e.oauthRedirectUri
73
73
  });
74
74
  let t = [];
75
- (!e.appId || e.appId === "MISSING_APP_ID") && t.push("appId"), (!e.apiUrl || e.apiUrl === "MISSING_API_URL") && t.push("apiUrl"), (!e.wsUrl || e.wsUrl === "MISSING_WS_URL") && t.push("wsUrl"), (!e.oauthRedirectUri || e.oauthRedirectUri === "MISSING_OAUTH_REDIRECT_URI") && t.push("oauthRedirectUri"), t.length > 0 && (s.error("❌ Configuration validation failed!"), s.error("Missing or invalid fields:", t), s.error("This will cause OAuth and API calls to fail."), s.error("Identity (appId/apiUrl/wsUrl) comes from .primitive/config.json via the primitiveEnv() Vite plugin — check that the project has one and that an environment is selected ('primitive env use <name>'). Callback and logging settings come from your .env files.")), this.config = e;
75
+ (!e.appId || e.appId === "MISSING_APP_ID") && t.push("appId"), (!e.apiUrl || e.apiUrl === "MISSING_API_URL") && t.push("apiUrl"), (!e.wsUrl || e.wsUrl === "MISSING_WS_URL") && t.push("wsUrl"), (!e.oauthRedirectUri || e.oauthRedirectUri === "MISSING_OAUTH_REDIRECT_URI") && t.push("oauthRedirectUri"), t.length > 0 && (s.error("❌ Configuration validation failed!"), s.error("Missing or invalid fields:", t), s.error("This will cause OAuth and API calls to fail."), s.error("Identity (appId/apiUrl/wsUrl) comes from primitive/config.json via the primitiveEnv() Vite plugin — check that the project has one and that an environment is selected ('primitive env use <name>'). Callback and logging settings come from your .env files.")), this.config = e;
76
76
  }
77
77
  getConfig() {
78
78
  return this.config;
@@ -77,7 +77,7 @@
77
77
  * `VITE_APP_ID`, `VITE_API_URL`, `VITE_WS_URL` and `VITE_APP_NAME` are NOT
78
78
  * authored by hand. They are filled in at build time by the `primitiveEnv()`
79
79
  * plugin (`primitive-app/vite`) from the Primitive environment selected in
80
- * `.primitive/config.json` — the one place a backend URL and app ID are typed.
80
+ * `primitive/config.json` — the one place a backend URL and app ID are typed.
81
81
  * Choose the environment with `primitive env use <name>`, or `--primitive-env`
82
82
  * on a deploy; `VITE_WS_URL` is derived from the API URL by scheme swap.
83
83
  *
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../rolldown-runtime-BNMv73og.cjs"),t=require("../lib-CFnieS8T.cjs");let n=require("js-bao-wss-client"),r=require("node:fs"),i=require("node:path");i=e.i(i,1);let a=require("vitest");var o=`000000`;function s(e,t,n){if(e)return e;throw Error(`[primitive-app/testing] Missing ${t}: pass it to registerPrimitiveTests() or set the ${n} environment variable.`)}function c(){let e=i.default.resolve(process.cwd(),`public/sql-wasm.wasm`);if(!(0,r.existsSync)(e)){console.warn(`[primitive-app/testing] ${e} not found — using the client's default database config. If client init fails to load sql-wasm.wasm, pass clientOptions.databaseConfig explicitly.`);return}return{type:`sqljs`,options:{locateFile:()=>e}}}async function l(e){let t=[],n=[];for(let[r,i]of Object.entries(e))try{let e=(await i())?.default;Array.isArray(e)?t.push(...e):e&&typeof e==`object`&&`tests`in e?t.push(e):n.push({file:r,error:Error(`Default export is not a TestGroup (expected { name, tests }).`)})}catch(e){n.push({file:r,error:e})}return{groups:t,failures:n}}async function u(e){let{models:r,testModules:i,otpCode:u=o,testTimeoutMs:d=6e4,clientOptions:f,cleanupTestDocuments:p=!0,failBelowFullScore:m=!0}=e,h=s(e.appId??process.env.VITE_APP_ID,`appId`,`VITE_APP_ID`),g=s(e.apiUrl??process.env.VITE_API_URL,`apiUrl`,`VITE_API_URL`),_=s(e.wsUrl??process.env.VITE_WS_URL,`wsUrl`,`VITE_WS_URL`),v=s(e.email??process.env.PRIMITIVE_TEST_EMAIL,`email`,`PRIMITIVE_TEST_EMAIL`),{groups:y,failures:b}=await l(i);for(let e of b)(0,a.describe)(e.file,()=>{(0,a.it)(`loads without errors`,()=>{throw e.error instanceof Error?e.error:Error(String(e.error))})});if(y.length===0){b.length===0&&console.warn(`[primitive-app/testing] No *.primitive-test.ts groups found — nothing to register.`);return}let x;(0,a.beforeAll)(async()=>{x=await(0,n.initializeClient)({apiUrl:g,wsUrl:_,appId:h,models:r,storageConfig:{type:`auto`},databaseConfig:c(),...f});try{await x.otpVerify(v,u)}catch(e){throw Error(`[primitive-app/testing] OTP sign-in failed for ${v}. The test bypass requires the app's testAccountBaseEmails whitelist to cover this address (and invite-only/domain/waitlist apps reject provisioning like any signup). Underlying error: ${e instanceof Error?e.message:String(e)}`)}t.o.initialize({apiUrl:g,wsUrl:_,appId:h,models:r,oauthRedirectUri:f?.oauthRedirectUri??process.env.VITE_OAUTH_REDIRECT_URI??`http://localhost/oauth/callback-unused-in-node-tests`,...f}),t.o.setExternalClient(x)},12e4),(0,a.afterAll)(async()=>{if(x){if(p)try{await t.r()}catch(e){console.warn(`[primitive-app/testing] Test-document cleanup failed:`,e)}await x.disconnect()}},6e4);for(let e of y)(0,a.describe)(e.name,()=>{for(let t of e.tests){if((t.environment??e.environment)===`browser`){a.it.skip(t.name,()=>{});continue}(0,a.it)(t.name,async()=>{let e=await t.run(e=>console.log(`[${t.id}] ${e}`));e&&console.log(`[${t.id}] ${e}`);let n=e?.match(/^(\d+)\/(\d+)\s*\((\d+(?:\.\d+)?)%\)/);if(m&&n&&Number(n[1])!==Number(n[2]))throw Error(`Scored below full marks: ${e}`)},d)}})}exports.PRIMITIVE_TEST_OTP_CODE=o,exports.registerPrimitiveTests=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../rolldown-runtime-BNMv73og.cjs"),t=require("../lib-Btb-Erfh.cjs");let n=require("js-bao-wss-client"),r=require("node:fs"),i=require("node:path");i=e.i(i,1);let a=require("vitest");var o=`000000`;function s(e,t,n){if(e)return e;throw Error(`[primitive-app/testing] Missing ${t}: pass it to registerPrimitiveTests() or set the ${n} environment variable.`)}function c(){let e=i.default.resolve(process.cwd(),`public/sql-wasm.wasm`);if(!(0,r.existsSync)(e)){console.warn(`[primitive-app/testing] ${e} not found — using the client's default database config. If client init fails to load sql-wasm.wasm, pass clientOptions.databaseConfig explicitly.`);return}return{type:`sqljs`,options:{locateFile:()=>e}}}async function l(e){let t=[],n=[];for(let[r,i]of Object.entries(e))try{let e=(await i())?.default;Array.isArray(e)?t.push(...e):e&&typeof e==`object`&&`tests`in e?t.push(e):n.push({file:r,error:Error(`Default export is not a TestGroup (expected { name, tests }).`)})}catch(e){n.push({file:r,error:e})}return{groups:t,failures:n}}async function u(e){let{models:r,testModules:i,otpCode:u=o,testTimeoutMs:d=6e4,clientOptions:f,cleanupTestDocuments:p=!0,failBelowFullScore:m=!0}=e,h=s(e.appId??process.env.VITE_APP_ID,`appId`,`VITE_APP_ID`),g=s(e.apiUrl??process.env.VITE_API_URL,`apiUrl`,`VITE_API_URL`),_=s(e.wsUrl??process.env.VITE_WS_URL,`wsUrl`,`VITE_WS_URL`),v=s(e.email??process.env.PRIMITIVE_TEST_EMAIL,`email`,`PRIMITIVE_TEST_EMAIL`),{groups:y,failures:b}=await l(i);for(let e of b)(0,a.describe)(e.file,()=>{(0,a.it)(`loads without errors`,()=>{throw e.error instanceof Error?e.error:Error(String(e.error))})});if(y.length===0){b.length===0&&console.warn(`[primitive-app/testing] No *.primitive-test.ts groups found — nothing to register.`);return}let x;(0,a.beforeAll)(async()=>{x=await(0,n.initializeClient)({apiUrl:g,wsUrl:_,appId:h,models:r,storageConfig:{type:`auto`},databaseConfig:c(),...f});try{await x.otpVerify(v,u)}catch(e){throw Error(`[primitive-app/testing] OTP sign-in failed for ${v}. The test bypass requires the app's testAccountBaseEmails whitelist to cover this address (and invite-only/domain/waitlist apps reject provisioning like any signup). Underlying error: ${e instanceof Error?e.message:String(e)}`)}t.o.initialize({apiUrl:g,wsUrl:_,appId:h,models:r,oauthRedirectUri:f?.oauthRedirectUri??process.env.VITE_OAUTH_REDIRECT_URI??`http://localhost/oauth/callback-unused-in-node-tests`,...f}),t.o.setExternalClient(x)},12e4),(0,a.afterAll)(async()=>{if(x){if(p)try{await t.r()}catch(e){console.warn(`[primitive-app/testing] Test-document cleanup failed:`,e)}await x.disconnect()}},6e4);for(let e of y)(0,a.describe)(e.name,()=>{for(let t of e.tests){if((t.environment??e.environment)===`browser`){a.it.skip(t.name,()=>{});continue}(0,a.it)(t.name,async()=>{let e=await t.run(e=>console.log(`[${t.id}] ${e}`));e&&console.log(`[${t.id}] ${e}`);let n=e?.match(/^(\d+)\/(\d+)\s*\((\d+(?:\.\d+)?)%\)/);if(m&&n&&Number(n[1])!==Number(n[2]))throw Error(`Scored below full marks: ${e}`)},d)}})}exports.PRIMITIVE_TEST_OTP_CODE=o,exports.registerPrimitiveTests=u;
@@ -1,4 +1,4 @@
1
- import { o as e, r as t } from "../lib-B7ZH2Pdd.js";
1
+ import { o as e, r as t } from "../lib-CknnILDr.js";
2
2
  import { initializeClient as n } from "js-bao-wss-client";
3
3
  import { existsSync as r } from "node:fs";
4
4
  import i from "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primitive-app",
3
- "version": "3.2.0-alpha.2",
3
+ "version": "3.2.0-alpha.3",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Primitive LLC",
6
6
  "type": "module",
@@ -109,7 +109,7 @@
109
109
  "eslint-plugin-vue": "~10.9.2",
110
110
  "jiti": "^2.7.0",
111
111
  "js-bao": "^0.5.1",
112
- "js-bao-wss-client": "^2.0.4",
112
+ "js-bao-wss-client": "^3.0.0",
113
113
  "npm-run-all2": "^9.0.2",
114
114
  "pinia": "^3.0.4",
115
115
  "prettier": "3.9.4",
@@ -1 +0,0 @@
1
- let e=require("js-bao-wss-client");var t={debug:0,info:1,warn:2,error:3,none:4},n=`warn`,r=class e{#e;scope;constructor(e,t){this.#e=e,this.scope=t}get level(){return this.#e.level}set level(e){this.setLevel(e)}debug(...e){this.#t(`debug`,e)}log(...e){this.#t(`info`,e,`log`)}warn(...e){this.#t(`warn`,e)}error(...e){this.#t(`error`,e)}shouldLog(e){return t[e]>=t[this.level]}getLevel(){return this.level}setLevel(e){e in t&&(this.#e.level=e)}forScope(t){let n=t.trim(),r=n?[...this.scope,n]:this.scope;return new e(this.#e,r)}#t(e,t,n){if(!this.shouldLog(e))return;let r=n??(e===`info`?`log`:e),i=this.scope.length?`[${this.scope.join(`:`)}]`:void 0,a=i?[i,...t]:t;console[r](...a)}},i={level:n},a=new r(i,[]).forScope(`PrimitiveApp`);function o(e){i.level=e}var s=a.forScope(`JsBaoClientService`);function c(){if(typeof window>`u`)return!1;let e=window.location.hostname;return e===`localhost`||e===`127.0.0.1`||e===`[::1]`||e.endsWith(`.localhost`)||e.endsWith(`.local`)}var l=new class{client=null;clientInitializationPromise=null;config=null;initialize(e){s.debug(`Initializing with config:`,{appId:e.appId?`${e.appId.substring(0,10)}...`:`MISSING`,apiUrl:e.apiUrl,wsUrl:e.wsUrl,oauthRedirectUri:e.oauthRedirectUri});let t=[];(!e.appId||e.appId===`MISSING_APP_ID`)&&t.push(`appId`),(!e.apiUrl||e.apiUrl===`MISSING_API_URL`)&&t.push(`apiUrl`),(!e.wsUrl||e.wsUrl===`MISSING_WS_URL`)&&t.push(`wsUrl`),(!e.oauthRedirectUri||e.oauthRedirectUri===`MISSING_OAUTH_REDIRECT_URI`)&&t.push(`oauthRedirectUri`),t.length>0&&(s.error(`❌ Configuration validation failed!`),s.error(`Missing or invalid fields:`,t),s.error(`This will cause OAuth and API calls to fail.`),s.error(`Identity (appId/apiUrl/wsUrl) comes from .primitive/config.json via the primitiveEnv() Vite plugin — check that the project has one and that an environment is selected ('primitive env use <name>'). Callback and logging settings come from your .env files.`)),this.config=e}getConfig(){return this.config}async getClientAsync(){if(s.debug(`Getting client async`),this.clientInitializationPromise)return this.clientInitializationPromise;if(!this.config)throw Error(`JsBaoClientService not initialized. Call initialize() first.`);return this.clientInitializationPromise=(async()=>{s.debug(`=== INITIALIZING CLIENT ===`),s.debug(`Configuration:`,this.config);let t=await(0,e.initializeClient)(this.config);if(t.on(`status`,e=>{s.debug(`Client status changed:`,e)}),t.on(`error`,e=>{s.error(`Client error:`,e)}),this.client=t,c()&&(window.__primitiveAppClient=t,this.config?.models&&Array.isArray(this.config.models))){let e={};for(let t of this.config.models){let n=t.schema?.name;if(n){let r=n.charAt(0).toUpperCase()+n.slice(1);e[r]=t}}window.__primitiveAppModels=e,s.debug(`Registered models on window:`,Object.keys(e))}return s.debug(`=== CLIENT INITIALIZATION COMPLETE ===`),t})(),this.clientInitializationPromise}setExternalClient(e){s.debug(`Setting external client from host app`),this.client=e,this.clientInitializationPromise=Promise.resolve(e)}async clearClient(){s.debug(`Clearing client singleton...`),this.client&&(this.client.disconnect().catch(e=>{s.warn(`Background disconnect failed (this is usually harmless):`,e)}),this.client=null,this.clientInitializationPromise=null,c()&&(window.__primitiveAppClient=void 0,window.__primitiveAppModels=void 0))}};function u(e){l.initialize(e)}var d=a.forScope(`TestHarness`),f=`===TEST===`;async function p(e={}){let{networkSync:t=!1}=e,n=await l.getClientAsync(),r=`${f} ${`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}`;if(t){let{metadata:e}=await n.documents.create({title:r}),t=e.documentId,{doc:i}=await n.documents.open(t);if(!i)throw Error(`[TestHarness] Failed to open synced test document`);return n.setDefaultDocumentId(t),d.debug(`Created synced test document`,{docId:t}),m.set(t,{client:n,docId:t,networkSync:!0}),{docId:t}}let{metadata:i}=await n.documents.create({title:r,localOnly:!0}),a=i.documentId,{doc:o}=await n.documents.open(a,{waitForLoad:`local`,enableNetworkSync:!1});if(!o)throw Error(`[TestHarness] Failed to open test document`);return n.setDefaultDocumentId(a),d.debug(`Created test document`,{docId:a}),m.set(a,{client:n,docId:a,networkSync:!1}),{docId:a}}var m=new Map;async function h(e){let t=m.get(e.docId);if(!t){d.warn(`destroyTestDocument called with unknown handle`,{docId:e.docId});return}m.delete(e.docId);try{t.networkSync?await t.client.documents.delete(t.docId,{forceCloseIfOpen:!0}):(await t.client.documents.close(t.docId),await t.client.documents.evict(t.docId,{force:!0}))}catch(e){d.error(`Failed to destroy test document`,{docId:t.docId,err:e})}}async function g(){try{let e=await l.getClientAsync();d.debug(`[deleteAllTestDocuments] Starting cleanup...`),await e.syncMetadata({scope:`all`});let t=(await e.me.ownedDocuments()).filter(e=>e.title?.startsWith(f));if(t.length===0)return 0;d.debug(`[deleteAllTestDocuments] Found test documents to delete`,{count:t.length});let n=0;for(let r of t)try{e.documents.isOpen(r.documentId)&&await e.documents.close(r.documentId),await e.documents.evict(r.documentId,{force:!0}),n++}catch(e){d.error(`[deleteAllTestDocuments] Failed to delete test document`,{documentId:r.documentId,err:e})}return d.debug(`[deleteAllTestDocuments] Cleanup complete`,{evictedCount:n}),n}catch(e){return d.error(`[deleteAllTestDocuments] Top-level error during cleanup`,{err:e}),0}}function _(e){return e.flatMap(e=>e.tests.map(t=>({id:t.id,name:t.name,group:e.name,environment:t.environment??e.environment,run:t.run})))}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return _}});