@charisol/plexo-sdk 2.0.23 → 2.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
- import { a as e } from "./brandGuide-DgoZ7spo.js";
1
+ import { a as e, g as t } from "./brandGuide-DgoZ7spo.js";
2
2
  //#region src/v2/strata/merge.ts
3
- function t(e) {
4
- return Array.isArray(e) ? `[${e.map(t).join(",")}]` : e && typeof e == "object" ? `{${Object.keys(e).sort().map((n) => `${JSON.stringify(n)}:${t(e[n])}`).join(",")}}` : JSON.stringify(e);
3
+ function n(e) {
4
+ return Array.isArray(e) ? `[${e.map(n).join(",")}]` : e && typeof e == "object" ? `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${n(e[t])}`).join(",")}}` : JSON.stringify(e);
5
5
  }
6
- var n = (e) => `${e.value}|${e.unit ?? ""}|${e.layer}|${e.type}`, r = (e) => e.name, i = (e) => t({
6
+ var r = (e) => `${e.value}|${e.unit ?? ""}|${e.layer}|${e.type}`, i = (e) => e.name, a = (e) => n({
7
7
  props: e.props ?? {},
8
8
  nodes: e.nodes ?? []
9
9
  });
10
- function a(e) {
10
+ function o(e) {
11
11
  return {
12
- tokens: Object.fromEntries(e.tokens.map((e) => [e.key, n(e)])),
13
- components: Object.fromEntries(e.components.map((e) => [r(e), i(e)]))
12
+ tokens: Object.fromEntries(e.tokens.map((e) => [e.key, r(e)])),
13
+ components: Object.fromEntries(e.components.map((e) => [i(e), a(e)]))
14
14
  };
15
15
  }
16
- function o(e, t) {
17
- let a = e.strata?.base, o = !a, s = new Map(e.tokens.map((e) => [e.key, e])), c = new Map(t.tokens.map((e) => [e.key, e])), l = {
16
+ function s(e, n) {
17
+ let o = e.strata?.base, s = !o, c = new Map(e.tokens.map((e) => [e.key, e])), l = new Map(n.tokens.map((e) => [e.key, e])), u = {
18
18
  incoming: [],
19
19
  outgoing: [],
20
20
  conflicts: [],
@@ -22,73 +22,73 @@ function o(e, t) {
22
22
  removedLocally: [],
23
23
  same: 0
24
24
  };
25
- for (let e of /* @__PURE__ */ new Set([...s.keys(), ...c.keys()])) {
26
- let t = s.get(e), r = c.get(e), i = a?.tokens[e], u = {
25
+ for (let e of /* @__PURE__ */ new Set([...c.keys(), ...l.keys()])) {
26
+ let n = c.get(e), i = l.get(e), a = o?.tokens[e], d = {
27
27
  key: e,
28
- local: t,
29
- remote: r
28
+ local: n,
29
+ remote: i
30
30
  };
31
- if (t && r) {
32
- if (n(t) === n(r)) {
33
- l.same += 1;
31
+ if (n && i) {
32
+ if (r(n) === r(i) || t(n) === t(i) && n.value === i.value) {
33
+ u.same += 1;
34
34
  continue;
35
35
  }
36
- if (o) {
37
- l.conflicts.push(u);
36
+ if (s) {
37
+ u.conflicts.push(d);
38
38
  continue;
39
39
  }
40
- let e = n(t) !== i, a = n(r) !== i;
41
- e && a ? l.conflicts.push(u) : a ? l.incoming.push(u) : e ? l.outgoing.push(u) : l.same += 1;
42
- } else t && !r ? i !== void 0 && !o ? (n(t) === i ? l.removedRemotely : l.conflicts).push(u) : l.outgoing.push(u) : r && !t && (i !== void 0 && !o ? (n(r) === i ? l.removedLocally : l.conflicts).push(u) : l.incoming.push(u));
40
+ let e = r(n) !== a, o = r(i) !== a;
41
+ e && o ? u.conflicts.push(d) : o ? u.incoming.push(d) : e ? u.outgoing.push(d) : u.same += 1;
42
+ } else n && !i ? a !== void 0 && !s ? (r(n) === a ? u.removedRemotely : u.conflicts).push(d) : u.outgoing.push(d) : i && !n && (a !== void 0 && !s ? (r(i) === a ? u.removedLocally : u.conflicts).push(d) : u.incoming.push(d));
43
43
  }
44
- let u = new Map(e.components.map((e) => [r(e), e])), d = new Map(t.components.map((e) => [r(e), e])), f = {
44
+ let d = new Map(e.components.map((e) => [i(e), e])), f = new Map(n.components.map((e) => [i(e), e])), p = {
45
45
  incoming: [],
46
46
  outgoing: [],
47
47
  conflicts: [],
48
48
  same: 0
49
49
  };
50
- for (let e of /* @__PURE__ */ new Set([...u.keys(), ...d.keys()])) {
51
- let t = u.get(e), n = d.get(e), r = a?.components[e], s = t ?? n, c = {
50
+ for (let e of /* @__PURE__ */ new Set([...d.keys(), ...f.keys()])) {
51
+ let t = d.get(e), n = f.get(e), r = o?.components[e], i = t ?? n, c = {
52
52
  id: e,
53
- name: s.name,
54
- variant: s.variant,
53
+ name: i.name,
54
+ variant: i.variant,
55
55
  local: t,
56
56
  remote: n
57
57
  };
58
58
  if (t && n) {
59
- if (i(t) === i(n)) {
60
- f.same += 1;
59
+ if (a(t) === a(n)) {
60
+ p.same += 1;
61
61
  continue;
62
62
  }
63
- if (o) {
64
- f.conflicts.push(c);
63
+ if (s) {
64
+ p.conflicts.push(c);
65
65
  continue;
66
66
  }
67
- let e = i(t) !== r, a = i(n) !== r;
68
- e && a ? f.conflicts.push(c) : a ? f.incoming.push(c) : e ? f.outgoing.push(c) : f.same += 1;
69
- } else t ? f.outgoing.push(c) : f.incoming.push(c);
67
+ let e = a(t) !== r, i = a(n) !== r;
68
+ e && i ? p.conflicts.push(c) : i ? p.incoming.push(c) : e ? p.outgoing.push(c) : p.same += 1;
69
+ } else t ? p.outgoing.push(c) : p.incoming.push(c);
70
70
  }
71
71
  return {
72
- firstSync: o,
73
- tokens: l,
74
- components: f
72
+ firstSync: s,
73
+ tokens: u,
74
+ components: p
75
75
  };
76
76
  }
77
- var s = (e) => e.tokens.incoming.length + e.tokens.outgoing.length + e.tokens.conflicts.length + e.tokens.removedRemotely.length + e.tokens.removedLocally.length + e.components.incoming.length + e.components.outgoing.length + e.components.conflicts.length > 0;
78
- function c(e) {
77
+ var c = (e) => e.tokens.incoming.length + e.tokens.outgoing.length + e.tokens.conflicts.length + e.tokens.removedRemotely.length + e.tokens.removedLocally.length + e.components.incoming.length + e.components.outgoing.length + e.components.conflicts.length > 0;
78
+ function l(e) {
79
79
  return {
80
80
  incoming: e.tokens.incoming.length + e.tokens.removedRemotely.length + e.components.incoming.length,
81
81
  outgoing: e.tokens.outgoing.length + e.tokens.removedLocally.length + e.components.outgoing.length,
82
82
  conflicts: e.tokens.conflicts.length + e.components.conflicts.length
83
83
  };
84
84
  }
85
- var l = (e) => {
85
+ var u = (e) => {
86
86
  let { id: t, createdAt: n, updatedAt: r, ...i } = e;
87
87
  return i;
88
88
  };
89
- function u(t, a, o, s, c = {}, u) {
90
- let f = s !== "push", p = s !== "pull", m = (e) => c[e] ?? "strata", h = new Map(t.tokens.map((e) => [e.key, e])), g = [], _ = [];
91
- if (f) {
89
+ function d(t, n, o, s, c = {}, l) {
90
+ let d = s !== "push", p = s !== "pull", m = (e) => c[e] ?? "strata", h = new Map(t.tokens.map((e) => [e.key, e])), g = [], _ = [];
91
+ if (d) {
92
92
  for (let e of o.tokens.incoming) e.remote && h.set(e.key, e.remote);
93
93
  for (let e of o.tokens.removedRemotely) h.delete(e.key);
94
94
  }
@@ -98,28 +98,28 @@ function u(t, a, o, s, c = {}, u) {
98
98
  }
99
99
  for (let e of o.tokens.conflicts) {
100
100
  let t = m(e.key);
101
- t === "strata" && f ? e.remote ? h.set(e.key, e.remote) : h.delete(e.key) : t === "plexo" && p && (e.local ? g.push(e.local) : _.push(e.key));
101
+ t === "strata" && d ? e.remote ? h.set(e.key, e.remote) : h.delete(e.key) : t === "plexo" && p && (e.local ? g.push(e.local) : _.push(e.key));
102
102
  }
103
- let v = new Map(t.components.map((e) => [r(e), e])), y = [];
104
- if (f) for (let e of o.components.incoming) e.remote && v.set(e.id, l(e.remote));
103
+ let v = new Map(t.components.map((e) => [i(e), e])), y = [];
104
+ if (d) for (let e of o.components.incoming) e.remote && v.set(e.id, u(e.remote));
105
105
  if (p) for (let e of o.components.outgoing) e.local && y.push(e.local);
106
106
  for (let e of o.components.conflicts) {
107
107
  let t = m(e.id);
108
- t === "strata" && f && e.remote ? v.set(e.id, l(e.remote)) : t === "plexo" && p && e.local && y.push(e.local);
108
+ t === "strata" && d && e.remote ? v.set(e.id, u(e.remote)) : t === "plexo" && p && e.local && y.push(e.local);
109
109
  }
110
- let b = new Map(a.tokens.map((e, t) => [e.key, t])), x = [...h.values()].sort((e, t) => (b.get(e.key) ?? 1e9) - (b.get(t.key) ?? 1e9)), S = e({
110
+ let b = new Map(n.tokens.map((e, t) => [e.key, t])), x = [...h.values()].sort((e, t) => (b.get(e.key) ?? 1e9) - (b.get(t.key) ?? 1e9)), S = e({
111
111
  ...t,
112
112
  tokens: x,
113
113
  components: [...v.values()]
114
114
  }), C = {
115
- variables: d(g),
116
- components: y.map(l),
115
+ variables: f(g),
116
+ components: y.map(u),
117
117
  ..._.length ? { deleteVariables: _ } : {}
118
- }, w = new Map(a.tokens.map((e) => [e.key, e]));
118
+ }, w = new Map(n.tokens.map((e) => [e.key, e]));
119
119
  for (let e of C.variables) w.set(e.key, e);
120
120
  for (let e of _) w.delete(e);
121
- let T = new Map(a.components.map((e) => [r(e), e]));
122
- for (let e of C.components) T.set(r(e), e);
121
+ let T = new Map(n.components.map((e) => [i(e), e]));
122
+ for (let e of C.components) T.set(i(e), e);
123
123
  let E = t.strata?.base ?? {
124
124
  tokens: {},
125
125
  components: {}
@@ -128,17 +128,17 @@ function u(t, a, o, s, c = {}, u) {
128
128
  components: { ...E.components }
129
129
  }, O = new Map(S.tokens.map((e) => [e.key, e]));
130
130
  for (let e of /* @__PURE__ */ new Set([...O.keys(), ...w.keys()])) {
131
- let t = O.get(e), r = w.get(e);
132
- t && r && n(t) === n(r) ? D.tokens[e] = n(t) : !t && !r && delete D.tokens[e];
131
+ let t = O.get(e), n = w.get(e);
132
+ t && n && r(t) === r(n) ? D.tokens[e] = r(t) : !t && !n && delete D.tokens[e];
133
133
  }
134
- let k = new Map(S.components.map((e) => [r(e), e]));
134
+ let k = new Map(S.components.map((e) => [i(e), e]));
135
135
  for (let e of /* @__PURE__ */ new Set([...k.keys(), ...T.keys()])) {
136
136
  let t = k.get(e), n = T.get(e);
137
- t && n && i(t) === i(n) ? D.components[e] = i(t) : !t && !n && delete D.components[e];
137
+ t && n && a(t) === a(n) ? D.components[e] = a(t) : !t && !n && delete D.components[e];
138
138
  }
139
139
  let A = {
140
- ...t.strata ?? { projectId: u?.projectId ?? "" },
141
- ...u ?? {},
140
+ ...t.strata ?? { projectId: l?.projectId ?? "" },
141
+ ...l ?? {},
142
142
  syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
143
143
  base: D
144
144
  };
@@ -151,71 +151,71 @@ function u(t, a, o, s, c = {}, u) {
151
151
  hasOutgoing: C.variables.length + C.components.length + (C.deleteVariables?.length ?? 0) > 0
152
152
  };
153
153
  }
154
- var d = (e) => [...new Map(e.map((e) => [e.key, e])).values()], f = (e) => e.replace(/^--/, "").split("-").filter(Boolean).map((e) => e[0].toUpperCase() + e.slice(1)).join(" ");
155
- function p(e) {
154
+ var f = (e) => [...new Map(e.map((e) => [e.key, e])).values()], p = (e) => e.replace(/^--/, "").split("-").filter(Boolean).map((e) => e[0].toUpperCase() + e.slice(1)).join(" ");
155
+ function m(e) {
156
156
  let { local: t, base: n, remote: r } = e, i = {
157
157
  ...t,
158
158
  strata: {
159
159
  ...t.strata ?? { projectId: "" },
160
160
  base: n
161
161
  }
162
- }, a = o(i, r), s = [...a.tokens.conflicts.map((e) => ({
162
+ }, a = s(i, r), o = [...a.tokens.conflicts.map((e) => ({
163
163
  id: e.key,
164
164
  kind: "token",
165
- label: (e.local ?? e.remote)?.name?.startsWith("--") === !1 ? (e.local ?? e.remote).name : f(e.key)
165
+ label: (e.local ?? e.remote)?.name?.startsWith("--") === !1 ? (e.local ?? e.remote).name : p(e.key)
166
166
  })), ...a.components.conflicts.map((e) => ({
167
167
  id: e.id,
168
168
  kind: "component",
169
169
  label: e.name
170
- }))], c = a.tokens.incoming.length + a.tokens.removedRemotely.length + a.components.incoming.length, l = a.tokens.outgoing.length + a.tokens.removedLocally.length + a.components.outgoing.length, d = {
171
- conflicts: s,
170
+ }))], c = a.tokens.incoming.length + a.tokens.removedRemotely.length + a.components.incoming.length, l = a.tokens.outgoing.length + a.tokens.removedLocally.length + a.components.outgoing.length, u = {
171
+ conflicts: o,
172
172
  incoming: c,
173
173
  unsynced: l,
174
174
  plan: a
175
175
  };
176
- return n ? s.length ? {
176
+ return n ? o.length ? {
177
177
  status: "needs-review",
178
178
  reason: "Some things were changed here and in Strata.",
179
- ...d
179
+ ...u
180
180
  } : c === 0 ? {
181
181
  status: "up-to-date",
182
- ...d
182
+ ...u
183
183
  } : l > 0 ? {
184
184
  status: "needs-review",
185
185
  reason: "You have changes here that haven’t been sent to Strata yet.",
186
- ...d
186
+ ...u
187
187
  } : {
188
188
  status: "safe-to-apply",
189
- merged: u(i, r, a, "pull").designSystem,
190
- ...d
189
+ merged: d(i, r, a, "pull").designSystem,
190
+ ...u
191
191
  } : {
192
- status: c + l + s.length === 0 ? "up-to-date" : "needs-review",
192
+ status: c + l + o.length === 0 ? "up-to-date" : "needs-review",
193
193
  reason: "This site hasn’t been matched up with Strata yet.",
194
- ...d
194
+ ...u
195
195
  };
196
196
  }
197
197
  //#endregion
198
198
  //#region src/v2/strata/client.ts
199
- var m = class extends Error {
199
+ var h = class extends Error {
200
200
  kind;
201
201
  status;
202
202
  details;
203
203
  constructor(e, t, n = 0, r) {
204
204
  super(e), this.name = "StrataError", this.kind = t, this.status = n, this.details = r;
205
205
  }
206
- }, h = (e) => e === "semantic" ? "semantic" : e === "component" ? "component" : "brand";
207
- function g(e) {
206
+ }, g = (e) => e === "semantic" ? "semantic" : e === "component" ? "component" : "brand";
207
+ function _(e) {
208
208
  return {
209
209
  key: String(e.key ?? e.name),
210
210
  name: String(e.name ?? e.key),
211
211
  value: String(e.value ?? ""),
212
212
  type: String(e.type ?? "string"),
213
213
  unit: e.unit === void 0 || e.unit === null || e.unit === "null" ? null : String(e.unit),
214
- layer: h(e.layer),
214
+ layer: g(e.layer),
215
215
  comment: e.comment ?? null
216
216
  };
217
217
  }
218
- function _(e) {
218
+ function v(e) {
219
219
  let { id: t, componentId: n, createdAt: r, updatedAt: i, ...a } = e;
220
220
  return {
221
221
  ...a,
@@ -225,7 +225,7 @@ function _(e) {
225
225
  nodes: Array.isArray(e.nodes) ? e.nodes : []
226
226
  };
227
227
  }
228
- function v(e) {
228
+ function y(e) {
229
229
  return {
230
230
  id: String(e.projectId ?? e.id),
231
231
  name: String(e.title ?? e.name ?? "Untitled project"),
@@ -236,7 +236,7 @@ function v(e) {
236
236
  ...e.role === "owner" || e.role === "editor" || e.role === "viewer" ? { role: e.role } : {}
237
237
  };
238
238
  }
239
- var y = (e) => ({
239
+ var b = (e) => ({
240
240
  key: e.key,
241
241
  name: e.name,
242
242
  value: e.value,
@@ -245,11 +245,11 @@ var y = (e) => ({
245
245
  layer: e.layer,
246
246
  comment: e.comment
247
247
  });
248
- function b(e) {
248
+ function x(e) {
249
249
  let t = e.fetch ?? fetch, n = e.baseUrl.replace(/\/$/, "");
250
250
  async function r(r, i = {}) {
251
251
  let a = await e.getToken();
252
- if (!a) throw new m("Connect Strata to continue.", "expired", 401);
252
+ if (!a) throw new h("Connect Strata to continue.", "expired", 401);
253
253
  let o;
254
254
  try {
255
255
  o = await t(`${n}${r}`, {
@@ -262,26 +262,26 @@ function b(e) {
262
262
  body: i.form ?? (i.body === void 0 ? void 0 : JSON.stringify(i.body))
263
263
  });
264
264
  } catch {
265
- throw new m("Couldn't reach Strata. Check your connection and try again.", "network");
265
+ throw new h("Couldn't reach Strata. Check your connection and try again.", "network");
266
266
  }
267
267
  let s = await o.json().catch(() => ({}));
268
268
  if (o.ok) return s;
269
269
  let c = s?.error?.code, l = typeof s?.error?.message == "string" ? s.error.message : typeof s?.message == "string" ? s.message : "";
270
- if (o.status === 401) throw new m("Your Strata sign-in has run out. Reconnect to keep syncing.", "expired", 401);
271
- if (o.status === 403) throw new m("You can see this Strata project but not change it. Ask its owner for edit access, or pick a project of your own.", "forbidden", 403);
272
- if (o.status === 404) throw new m("That Strata project wasn't found. It may have been deleted, or you may no longer have access.", "not_found", 404);
273
- if (o.status === 409 && c === "REVISION_CONFLICT") throw new m("Someone changed this project in Strata since you last checked. Check for updates first, then send your changes.", "conflict", 409, s.error.details);
274
- if (o.status === 409) throw new m(l || "A project with that name already exists. Choose another name.", "invalid", 409, s.error?.details);
270
+ if (o.status === 401) throw new h("Your Strata sign-in has run out. Reconnect to keep syncing.", "expired", 401);
271
+ if (o.status === 403) throw new h("You can see this Strata project but not change it. Ask its owner for edit access, or pick a project of your own.", "forbidden", 403);
272
+ if (o.status === 404) throw new h("That Strata project wasn't found. It may have been deleted, or you may no longer have access.", "not_found", 404);
273
+ if (o.status === 409 && c === "REVISION_CONFLICT") throw new h("Someone changed this project in Strata since you last checked. Check for updates first, then send your changes.", "conflict", 409, s.error.details);
274
+ if (o.status === 409) throw new h(l || "A project with that name already exists. Choose another name.", "invalid", 409, s.error?.details);
275
275
  if (o.status === 400) {
276
276
  let e = s?.error?.details?.errors, t = e?.[0];
277
- throw new m(t ? `Strata didn't accept ${t.key ?? t.component ?? "one of the changes"}: ${t.message}` : l || "Strata didn't accept those changes.", "invalid", 400, e);
277
+ throw new h(t ? `Strata didn't accept ${t.key ?? t.component ?? "one of the changes"}: ${t.message}` : l || "Strata didn't accept those changes.", "invalid", 400, e);
278
278
  }
279
- throw new m("Strata had a problem. Please try again in a moment.", "server", o.status);
279
+ throw new h("Strata had a problem. Please try again in a moment.", "server", o.status);
280
280
  }
281
281
  return {
282
282
  async listProjects() {
283
283
  let e = await r("/user/projects");
284
- return (Array.isArray(e.data) ? e.data : []).map(v);
284
+ return (Array.isArray(e.data) ? e.data : []).map(y);
285
285
  },
286
286
  async createProject(e) {
287
287
  let t = await r(e.template === "base" ? "/projects?preset=base" : "/projects", {
@@ -291,7 +291,7 @@ function b(e) {
291
291
  ...e.template === "base" && e.brandPrimary && /^#[0-9A-Fa-f]{6}$/.test(e.brandPrimary) ? { brandPrimary: e.brandPrimary } : {}
292
292
  }
293
293
  });
294
- return v(t.data ?? t);
294
+ return y(t.data ?? t);
295
295
  },
296
296
  async pull(e) {
297
297
  let t = encodeURIComponent(e);
@@ -299,15 +299,15 @@ function b(e) {
299
299
  let e = await r(`/projects/${t}/design-system`), n = e.data ?? e;
300
300
  return {
301
301
  revision: n.revision,
302
- tokens: (n.variables ?? []).map(g),
303
- components: (n.components ?? []).map(_)
302
+ tokens: (n.variables ?? []).map(_),
303
+ components: (n.components ?? []).map(v)
304
304
  };
305
305
  } catch (e) {
306
- if (!(e instanceof m) || e.kind !== "not_found" || e.status !== 404) throw e;
306
+ if (!(e instanceof h) || e.kind !== "not_found" || e.status !== 404) throw e;
307
307
  let [n, i] = await Promise.all([r(`/projects/${t}/variables`), r(`/projects/${t}/components`)]);
308
308
  return {
309
- tokens: (n.data ?? []).map(g),
310
- components: (i.data ?? []).map(_)
309
+ tokens: (n.data ?? []).map(_),
310
+ components: (i.data ?? []).map(v)
311
311
  };
312
312
  }
313
313
  },
@@ -316,7 +316,7 @@ function b(e) {
316
316
  method: "PUT",
317
317
  body: {
318
318
  ...n ? { baseRevision: n } : {},
319
- variables: t.variables.map(y),
319
+ variables: t.variables.map(b),
320
320
  components: t.components,
321
321
  ...t.deleteVariables?.length ? { deleteVariables: t.deleteVariables } : {}
322
322
  }
@@ -358,4 +358,4 @@ function b(e) {
358
358
  };
359
359
  }
360
360
  //#endregion
361
- export { g as a, a as c, c as d, v as i, s as l, _ as n, p as o, b as r, u as s, m as t, o as u };
361
+ export { _ as a, o as c, l as d, y as i, c as l, v as n, m as o, x as r, d as s, h as t, s as u };