@vuetify/one 2.8.2 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,10 +35,11 @@ interface VOneIdentity {
35
35
  userHandle: string;
36
36
  primary: boolean;
37
37
  }
38
+ type VOneRole = 'super' | 'admin' | 'editor' | 'user';
38
39
  interface VOneUser {
39
40
  id: string;
40
41
  isAdmin: boolean;
41
- role: 'super' | 'admin' | 'editor' | 'user';
42
+ role: VOneRole;
42
43
  name: string;
43
44
  shortid: string;
44
45
  picture: string;
@@ -53,6 +54,10 @@ interface AuthState {
53
54
  url: string;
54
55
  dialog: Ref<boolean>;
55
56
  isLoading: ShallowRef<boolean>;
57
+ isAuthenticated: Ref<boolean>;
58
+ isSuper: Ref<boolean>;
59
+ isAdmin: Ref<boolean>;
60
+ isEditor: Ref<boolean>;
56
61
  verify: (force?: boolean) => Promise<void>;
57
62
  findIdentity: (provider: string) => VOneIdentity | undefined;
58
63
  login: (provider?: 'github' | 'discord' | 'shopify') => Promise<void>;
@@ -60,7 +65,7 @@ interface AuthState {
60
65
  lastLoginProvider: () => string | null;
61
66
  sync: () => Promise<void>;
62
67
  }
63
- declare const useAuthStore: pinia.StoreDefinition<"auth", Pick<AuthState, "isLoading" | "user" | "url" | "dialog">, Pick<AuthState, never>, Pick<AuthState, "sync" | "verify" | "findIdentity" | "login" | "logout" | "lastLoginProvider">>;
68
+ declare const useAuthStore: pinia.StoreDefinition<"auth", Pick<AuthState, "isLoading" | "user" | "url" | "dialog" | "isAuthenticated" | "isSuper" | "isAdmin" | "isEditor">, Pick<AuthState, never>, Pick<AuthState, "sync" | "verify" | "findIdentity" | "login" | "logout" | "lastLoginProvider">>;
64
69
 
65
70
  export { useAuthStore };
66
- export type { AuthState, VOneIdentity, VOneSponsorship, VOneUser };
71
+ export type { AuthState, VOneIdentity, VOneRole, VOneSponsorship, VOneUser };
@@ -1,5 +1,5 @@
1
1
  import "lodash-es";
2
- import { a as e } from "../auth-CwLSOnno.js";
2
+ import { a as e } from "../auth-CXrXnM17.js";
3
3
  import "pinia";
4
4
  import "vue";
5
5
  import "vue-router";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuetify/one",
3
- "version": "2.8.2",
3
+ "version": "2.9.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,574 +0,0 @@
1
- import { merge as O } from "lodash-es";
2
- import { defineStore as j } from "pinia";
3
- import { ref as T, reactive as z, watch as I, toRefs as M, computed as m, shallowRef as N, nextTick as X } from "vue";
4
- import { useRoute as Y, useRouter as F } from "vue-router";
5
- const _ = j("queue", () => {
6
- const e = T([]);
7
- function r(o) {
8
- const s = typeof o == "string" ? { text: o } : o;
9
- e.value.push(s);
10
- }
11
- function t(o) {
12
- r({
13
- color: "error",
14
- text: o,
15
- location: "top end",
16
- timeout: -1
17
- });
18
- }
19
- function i(o) {
20
- r({
21
- color: "success",
22
- text: o,
23
- location: "top end"
24
- });
25
- }
26
- return {
27
- queue: e,
28
- show: r,
29
- showError: t,
30
- showSuccess: i
31
- };
32
- }), G = [
33
- (e) => (e.v || (e.pwaRefresh = !0, typeof e.api == "boolean" && (e.api = e.api ? "inline" : "link-only"), typeof e.rtl == "boolean" && (e.direction = e.rtl ? "rtl" : "ltr", delete e.rtl), typeof e.theme == "object" && (e.mixedTheme = e.theme.mixed, e.theme = e.theme.system ? "system" : e.theme.dark ? "dark" : "light"), Array.isArray(e.notifications) && (e.notifications = { read: e.notifications }), typeof e.last == "object" && (e.notifications = e.notifications || {}, e.notifications.last = e.last, delete e.last), e.v = 1), e),
34
- (e) => (e.v === 1 && (Array.isArray(e.composition) && (e.composition = "composition"), Array.isArray(e.notifications?.last?.banner) || (e.notifications = e.notifications || {}, e.notifications.last = e.notifications.last || {}, e.notifications.last.banner = []), e.v = 2), e),
35
- (e) => (e.v === 2 && (e.syncSettings = !0, e.disableAds = !1, e.v = 3), e),
36
- (e) => (e.v === 3 && (e.quickbar = !1, e.v = 4), e),
37
- (e) => (e.v === 4 && (e.suits = { show: !1, elements: ["app-bar"], suit: "" }, e.notifications = e.notifications || {}, e.notifications.banners = !0, e.v = 5), e)
38
- ];
39
- function K(e) {
40
- return {
41
- version: 6,
42
- ecosystem: {
43
- bin: {
44
- wordWrap: !1
45
- },
46
- play: {
47
- showErrors: !0,
48
- wordWrap: !1
49
- },
50
- studio: {},
51
- link: {},
52
- docs: {
53
- api: e.api || "link-only",
54
- composition: e.composition || "composition",
55
- pins: {
56
- enabled: e.pins || !1,
57
- pinned: Array.isArray(e.pinned) ? e.pinned.map((r) => r.name || r).filter(Boolean) : []
58
- },
59
- mixedTheme: e.mixedTheme ?? !0,
60
- favorites: [],
61
- slashSearch: e.slashSearch || !1,
62
- railDrawer: e.railDrawer || !1
63
- }
64
- },
65
- one: {
66
- avatar: e.avatar || "",
67
- ads: {
68
- enabled: !e.disableAds,
69
- house: e.showHouseAds || !1
70
- },
71
- command: {},
72
- theme: e.theme || "system",
73
- direction: e.direction || "ltr",
74
- colors: {
75
- primary: e.colors?.one || "surface-light"
76
- },
77
- suits: {
78
- enabled: e.suits?.show || !1,
79
- elements: e.suits?.elements || ["app-bar"],
80
- suit: e.suits?.suit || ""
81
- },
82
- notifications: {
83
- enabled: e.notifications?.show ?? !0,
84
- read: e.notifications?.read || [],
85
- last: ""
86
- },
87
- banners: {
88
- enabled: e.notifications?.banners ?? !0,
89
- read: e.notifications?.last?.banner || [],
90
- last: ""
91
- },
92
- quicklinks: e.quickbar || !1,
93
- sync: e.syncSettings ?? !0,
94
- devmode: e.dev || !1
95
- }
96
- };
97
- }
98
- function H(e) {
99
- return {
100
- ...e,
101
- version: 7,
102
- ecosystem: {
103
- ...e.ecosystem,
104
- mcp: {
105
- seen: !1
106
- }
107
- }
108
- };
109
- }
110
- function Z(e) {
111
- const r = G.reduce((i, o) => o(i), e), t = K(r);
112
- return H(t);
113
- }
114
- const W = typeof window < "u", E = {
115
- version: 7,
116
- ecosystem: {
117
- bin: {
118
- wordWrap: !0
119
- },
120
- play: {
121
- showErrors: !0,
122
- wordWrap: !1
123
- },
124
- studio: {},
125
- link: {},
126
- docs: {
127
- api: "link-only",
128
- composition: "composition",
129
- pins: {
130
- enabled: !1,
131
- pinned: []
132
- },
133
- mixedTheme: !0,
134
- favorites: [],
135
- slashSearch: !1,
136
- railDrawer: !1
137
- },
138
- mcp: {
139
- seen: !1
140
- }
141
- },
142
- one: {
143
- avatar: "",
144
- ads: {
145
- enabled: !0,
146
- house: !1
147
- },
148
- command: {},
149
- theme: "system",
150
- direction: "ltr",
151
- colors: {
152
- primary: "surface-light"
153
- },
154
- suits: {
155
- enabled: !1,
156
- elements: ["app-bar"],
157
- suit: ""
158
- },
159
- notifications: {
160
- enabled: !0,
161
- read: [],
162
- last: ""
163
- },
164
- banners: {
165
- enabled: !0,
166
- read: [],
167
- last: ""
168
- },
169
- quicklinks: !1,
170
- ecosystem: {
171
- pinned: [],
172
- seen: !1
173
- },
174
- sync: !0,
175
- devmode: !1
176
- }
177
- }, D = j("user", () => {
178
- const e = z(structuredClone(E));
179
- I(e, t, { deep: !0 });
180
- function r() {
181
- if (!W)
182
- return;
183
- const o = localStorage.getItem("vuetify@user");
184
- if (o)
185
- try {
186
- const s = JSON.parse(o);
187
- if (s.version >= 7) {
188
- const u = {
189
- version: 7,
190
- ecosystem: O(structuredClone(E.ecosystem), s.ecosystem || {}),
191
- one: O(structuredClone(E.one), s.one || {})
192
- };
193
- Object.assign(e, u);
194
- } else if (s.version === 6) {
195
- const u = H(s), d = {
196
- version: 7,
197
- ecosystem: O(structuredClone(E.ecosystem), u.ecosystem || {}),
198
- one: O(structuredClone(E.one), u.one || {})
199
- };
200
- Object.assign(e, d);
201
- } else {
202
- const u = Z(s);
203
- Object.assign(e, u);
204
- }
205
- t();
206
- } catch (s) {
207
- console.error("Failed to load user settings:", s);
208
- }
209
- }
210
- function t() {
211
- W && localStorage.setItem("vuetify@user", JSON.stringify(e, null, 2));
212
- }
213
- function i() {
214
- W && (Object.assign(e, structuredClone(E)), t());
215
- }
216
- return r(), {
217
- ...M(e),
218
- load: r,
219
- save: t,
220
- reset: i
221
- };
222
- }), J = j("http", {
223
- state: () => ({
224
- url: ""
225
- }),
226
- actions: {
227
- async fetch(e, r = {}) {
228
- const t = await fetch(`${this.url}${e}`, {
229
- credentials: "include",
230
- ...r
231
- });
232
- if (!t.ok) {
233
- const i = await t.text();
234
- let o = i || `HTTP ${t.status}`;
235
- try {
236
- const s = JSON.parse(i);
237
- o = s.message || s.error || i;
238
- } catch {
239
- }
240
- throw new Error(o);
241
- }
242
- return t.status === 204 ? {} : t.json();
243
- },
244
- async post(e, r, t = {}) {
245
- return this.fetch(e, {
246
- method: "POST",
247
- headers: {
248
- "Content-Type": "application/json"
249
- },
250
- body: JSON.stringify(r),
251
- ...t
252
- });
253
- },
254
- async form(e, r, t = {}) {
255
- return this.fetch(e, {
256
- method: "POST",
257
- body: r,
258
- ...t
259
- });
260
- },
261
- async get(e, r = {}) {
262
- return this.fetch(e, r);
263
- },
264
- async delete(e, r = {}) {
265
- return this.fetch(e, {
266
- method: "DELETE",
267
- ...r
268
- });
269
- }
270
- }
271
- });
272
- function Q() {
273
- const e = Y();
274
- return m(
275
- () => e.query
276
- );
277
- }
278
- const V = j("one", () => {
279
- const e = Q(), r = F(), t = B(), i = J(), o = _(), s = N(!1), u = N(!1), d = T(null), v = T([]), g = m(() => e.value.session_id), A = m(() => d.value?.items[0].plan.interval), h = m(() => d.value?.items[0].plan.type), k = T([]), y = m(() => t.user?.sponsorships.find((n) => n.platform === "stripe" && n.tierName.startsWith("sub_"))), L = m(() => !!y.value?.tierName), c = m(() => t.user?.sponsorships.reduce((n, p) => {
280
- if (!p.isActive || p.interval === "once")
281
- return n;
282
- const b = p.interval === "month" ? p.amount : p.amount / 12;
283
- return n + b / 100;
284
- }, 0) ?? 0), a = m(() => t.user?.sponsorships.find((n) => n.tierName.startsWith("sub_") && n.isActive)), f = m(() => t.user?.sponsorships.find((n) => n.platform === "github" && n.isActive)), l = m(() => t.user?.sponsorships.find((n) => n.platform === "discord" && n.isActive)), $ = m(() => t.user?.identities.find((n) => n.provider === "shopify")), U = m(() => !i.url || t.user?.isAdmin || y.value?.isActive || k.value.some((n) => ["one", "one/team"].includes(n)));
285
- I(u, w), I(g, async (n) => {
286
- n && await R();
287
- }, { immediate: !0 }), I(e, (n) => {
288
- if (n.one !== "subscribe" || t.user)
289
- return;
290
- t.dialog = !0;
291
- const p = I(() => t.user, (b) => {
292
- b && (t.dialog = !1, p());
293
- });
294
- }, { immediate: !0 });
295
- async function R() {
296
- try {
297
- s.value = !0, await i.post("/one/activate", { sessionId: g.value }), await t.verify(!0), await q();
298
- const n = new URL(window.location.href), p = n.searchParams;
299
- p.delete("session_id"), p.delete("team"), history.pushState(null, "", n.toString());
300
- } catch (n) {
301
- o.showError(n?.message ?? "Error activating subscription, Please contact support");
302
- } finally {
303
- s.value = !1;
304
- }
305
- }
306
- async function S() {
307
- window.open(`${i.url}/one/manage`, "_blank");
308
- }
309
- async function x(n, p) {
310
- s.value = !0;
311
- const b = new URL("/one/subscribe", i.url);
312
- b.searchParams.set("interval", n), b.searchParams.set("type", p), window.location.href = b.toString();
313
- }
314
- async function C() {
315
- if (y.value)
316
- try {
317
- s.value = !0, await i.post(
318
- `/one/cancel?subscriptionId=${y.value?.tierName}`
319
- ), await t.verify(!0);
320
- } catch (n) {
321
- o.showError(n?.message ?? "Error cancelling subscription, Please contact support");
322
- } finally {
323
- s.value = !1;
324
- }
325
- }
326
- async function P(n, p) {
327
- if (y.value)
328
- try {
329
- s.value = !0, await i.post("/one/modify", {
330
- subscriptionId: y.value.tierName,
331
- interval: n,
332
- type: p
333
- }), await t.verify(!0);
334
- } catch (b) {
335
- o.showError(b?.message ?? "Error modifying subscription");
336
- } finally {
337
- s.value = !1;
338
- }
339
- }
340
- async function q() {
341
- try {
342
- s.value = !0;
343
- const n = await i.get("/one/info");
344
- return d.value = n.subscription, v.value = n.invoices, n;
345
- } catch (n) {
346
- o.showError(n?.message ?? "Error fetching subscription info");
347
- } finally {
348
- s.value = !1;
349
- }
350
- }
351
- function w() {
352
- r.push({
353
- query: {
354
- ...e.value,
355
- one: void 0
356
- }
357
- });
358
- }
359
- return {
360
- info: d,
361
- interval: A,
362
- subscriptionType: h,
363
- access: k,
364
- invoices: v,
365
- sessionId: g,
366
- subscription: y,
367
- monthlyTotal: c,
368
- hasBilling: L,
369
- isLoading: s,
370
- isOpen: u,
371
- isSubscriber: U,
372
- github: f,
373
- discord: l,
374
- shopify: $,
375
- one: a,
376
- activate: R,
377
- cancel: C,
378
- manage: S,
379
- modify: P,
380
- resetQuery: w,
381
- subscribe: x,
382
- subscriptionInfo: q
383
- };
384
- }), ee = j("team", () => {
385
- const e = Q(), r = B(), t = V(), i = J(), o = _(), s = N(!1), u = T(null), d = T(!1), v = m(() => e.value.invite), g = m(
386
- () => u.value ? t.access?.some((c) => ["one/team", "snips/team"].includes(c)) : !1
387
- );
388
- I(v, async () => {
389
- if (v.value) {
390
- r.user || (r.dialog = !0);
391
- try {
392
- s.value = !0;
393
- const c = await i.get(`/one/team/${v.value}`);
394
- u.value = c.team, d.value = !0;
395
- } catch (c) {
396
- y(), o.showError(c.message);
397
- } finally {
398
- s.value = !1;
399
- }
400
- }
401
- }, { immediate: !0 });
402
- async function A(c) {
403
- try {
404
- if (s.value = !0, !u.value)
405
- return;
406
- await i.post("/one/team/remove", { userId: c }), u.value.members = u.value.members.filter((a) => a.id !== c);
407
- } catch (a) {
408
- o.showError(a?.message ?? "Error removing user from team");
409
- } finally {
410
- s.value = !1;
411
- }
412
- }
413
- async function h() {
414
- try {
415
- s.value = !0, await i.post("/one/team/leave", { teamId: u.value?.id }), await r.verify(!0);
416
- } catch (c) {
417
- o.showError(c?.message ?? "Error leaving team");
418
- } finally {
419
- s.value = !1;
420
- }
421
- }
422
- async function k() {
423
- try {
424
- s.value = !0, await i.post("/one/team/join", { inviteCode: v.value }), await r.verify(!0), y();
425
- } catch (c) {
426
- o.showError(c?.message ?? "Error joining team");
427
- } finally {
428
- s.value = !1;
429
- }
430
- }
431
- function y() {
432
- d.value = !1;
433
- const c = new URL(window.location.href);
434
- c.searchParams.delete("invite"), window.history.replaceState({}, "", c.toString());
435
- }
436
- const L = m(() => r.user?.id === r.user?.team?.owner.id);
437
- return {
438
- team: u,
439
- teamInviteDialog: d,
440
- teamInviteCode: v,
441
- hasTeamAccess: g,
442
- isTeamOwner: L,
443
- isLoading: s,
444
- removeFromTeam: A,
445
- leaveTeam: h,
446
- joinTeam: k,
447
- clearTeamQuery: y
448
- };
449
- }), B = j("auth", () => {
450
- const e = T(!1), r = T(null), t = J(), i = D(), o = F(), s = N(!1), u = V(), d = ee(), v = _();
451
- let g = !!c();
452
- I(r, (a) => {
453
- if (!a?.settings)
454
- return;
455
- const f = localStorage.getItem("vuetify@user") || "{}";
456
- if (JSON.stringify(a.settings, null, 2) === f)
457
- return;
458
- g = !0;
459
- let l = a.settings;
460
- l.version === 6 && (l = H(l));
461
- const $ = {
462
- version: 7,
463
- ecosystem: O(structuredClone(E.ecosystem), l.ecosystem || {}),
464
- one: O(structuredClone(E.one), l.one || {})
465
- };
466
- Object.assign(i, $);
467
- }), i.$subscribe(() => {
468
- g || A(), g = !1;
469
- });
470
- async function A() {
471
- if (await X(), !(!r.value || !i.one.sync))
472
- try {
473
- await t.post("/user/settings", { settings: i.$state }), await h(!0);
474
- } catch (a) {
475
- v.showError(a?.message ?? "Error syncing settings");
476
- }
477
- }
478
- async function h(a = !1) {
479
- if (h.promise)
480
- return h.promise;
481
- if (!a && !document.cookie.includes("sx=1") && location.hostname.match(/([^.]+\.[^.]+)$/)?.[1] === new URL(t.url).hostname.match(/([^.]+\.[^.]+)$/)?.[1]) {
482
- r.value = null;
483
- return;
484
- }
485
- s.value = !0, h.promise = fetch(`${t.url}/auth/verify`, {
486
- credentials: "include",
487
- cache: a ? "reload" : void 0
488
- }).then(
489
- async (f) => {
490
- if (f.ok || f.status === 401) {
491
- const l = await f.json();
492
- r.value = l.user, u.access = l.access, d.team = l.user?.team;
493
- } else
494
- console.error(f.statusText);
495
- },
496
- () => {
497
- }
498
- ).finally(() => {
499
- s.value = !1, h.promise = null;
500
- });
501
- }
502
- h.promise = null;
503
- async function k(a = "github") {
504
- s.value = !0;
505
- const f = `${t.url}/auth/${a}/redirect`;
506
- if (a === "shopify") {
507
- window.location.assign(f + "?next=" + encodeURIComponent(window.location.href));
508
- return;
509
- }
510
- const l = 400, $ = 600, U = window.screenX + (window.innerWidth - l) / 2, R = window.screenY + (window.innerHeight - $) / 2, S = window.open(
511
- "",
512
- "vuetify:authorize:popup",
513
- `popup,left=${U},top=${R},width=${l},height=${$},resizable`
514
- );
515
- if (!S) {
516
- console.error("Failed to open popup");
517
- return;
518
- }
519
- S.location.href = f;
520
- let x = -1, C = -1;
521
- function P(w) {
522
- w.origin === t.url && w.data?.type === "auth-response" && (w.data.status === "success" ? (r.value || (localStorage.setItem("vuetify@lastLoginProvider", a), e.value = !1, o.push("/user/dashboard")), r.value = w.data.body.user, u.access = w.data.body.access, d.team = w.data.body.user?.team, A()) : console.error(w.data.message), q());
523
- }
524
- function q() {
525
- window.removeEventListener("message", P), window.clearInterval(x), window.clearTimeout(C), S?.close(), s.value = !1;
526
- }
527
- window.addEventListener("message", P), x = window.setInterval(() => {
528
- !S || S.closed ? (console.error("Auth popup closed"), q()) : S.postMessage({ type: "auth-request" }, "*");
529
- }, 1e3), C = window.setTimeout(() => {
530
- q(), console.error("Auth timed out");
531
- }, 120 * 1e3);
532
- }
533
- async function y(a) {
534
- s.value = !0;
535
- const f = a ? `/auth/${a}/logout` : "/auth/logout";
536
- try {
537
- await t.post(f), await h(!0), r.value = null;
538
- } catch (l) {
539
- v.showError(l?.message ?? "Error logging out");
540
- } finally {
541
- o.push({
542
- path: "/",
543
- query: o.currentRoute.value.query
544
- }), s.value = !1;
545
- }
546
- }
547
- function L(a) {
548
- return r.value?.identities.find((f) => f.provider === a);
549
- }
550
- function c() {
551
- return localStorage.getItem("vuetify@lastLoginProvider");
552
- }
553
- return h(), {
554
- user: r,
555
- url: t.url,
556
- dialog: e,
557
- isLoading: s,
558
- verify: h,
559
- findIdentity: L,
560
- login: k,
561
- logout: y,
562
- lastLoginProvider: c,
563
- sync: A
564
- };
565
- });
566
- export {
567
- B as a,
568
- D as b,
569
- V as c,
570
- Q as d,
571
- J as e,
572
- ee as f,
573
- _ as u
574
- };