@meistrari/auth-nuxt 3.13.1 → 3.15.0

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
3
  "configKey": "telaAuth",
4
- "version": "3.13.1",
4
+ "version": "3.15.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,4 +1,4 @@
1
- import type { AdminOrganization, CreateAdminOrganizationOptions, GetAdminOrganizationOptions, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminUsersOptions, ListAdminUsersResult, UpdateAdminOrganizationOptions } from '@meistrari/auth-core';
1
+ import type { AdminApplicationRecord, AdminApplicationEntitlementRecord, AdminOrganization, CreateAdminApplicationEntitlementOptions, CreateAdminApplicationOptions, CreateAdminOrganizationOptions, GetAdminOrganizationOptions, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminUsersOptions, ListAdminUsersResult, UpdateAdminOrganizationOptions } from '@meistrari/auth-core';
2
2
  export interface UseTelaAdminReturn {
3
3
  /**
4
4
  * Lists users from the Better Auth `user` table as a global admin.
@@ -12,6 +12,26 @@ export interface UseTelaAdminReturn {
12
12
  * @returns The application listing with entitlement details
13
13
  */
14
14
  listApplications: (options?: ListAdminApplicationsOptions) => Promise<ListAdminApplicationsResult>;
15
+ /**
16
+ * Creates an application as a global admin.
17
+ * @param options - Application name, URLs, logo, and authentication settings
18
+ * @returns The created application
19
+ */
20
+ createApplication: (options: CreateAdminApplicationOptions) => Promise<AdminApplicationRecord>;
21
+ /**
22
+ * Updates an application as a global admin.
23
+ * @param applicationId - ID of the application to update
24
+ * @param options - Application name, URLs, logo, and authentication settings
25
+ * @returns The updated application
26
+ */
27
+ updateApplication: (applicationId: string, options: CreateAdminApplicationOptions) => Promise<AdminApplicationRecord>;
28
+ /**
29
+ * Enables an organization for an application as a global admin.
30
+ * @param applicationId - ID of the application to update
31
+ * @param options - Organization entitlement payload
32
+ * @returns The created entitlement
33
+ */
34
+ createApplicationEntitlement: (applicationId: string, options: CreateAdminApplicationEntitlementOptions) => Promise<AdminApplicationEntitlementRecord>;
15
35
  /**
16
36
  * Lists all organizations as a global admin, optionally with member and
17
37
  * application previews and totals when a preview size is requested.
@@ -1,8 +1,17 @@
1
1
  import { useCookie, useRuntimeConfig } from "#app";
2
2
  import { createNuxtAuthClient } from "../shared.js";
3
- function buildListApplicationsUrl(apiUrl, options = {}) {
3
+ function buildApplicationsUrl(apiUrl) {
4
4
  const base = apiUrl.endsWith("/") ? apiUrl : `${apiUrl}/`;
5
- const url = new URL("applications/", base);
5
+ return new URL("applications/", base);
6
+ }
7
+ function buildApplicationUrl(apiUrl, applicationId) {
8
+ return new URL(encodeURIComponent(applicationId), buildApplicationsUrl(apiUrl));
9
+ }
10
+ function buildApplicationEntitlementsUrl(apiUrl, applicationId) {
11
+ return new URL("entitlements", `${buildApplicationUrl(apiUrl, applicationId).toString()}/`);
12
+ }
13
+ function buildListApplicationsUrl(apiUrl, options = {}) {
14
+ const url = buildApplicationsUrl(apiUrl);
6
15
  if (options.limit !== void 0)
7
16
  url.searchParams.set("limit", String(options.limit));
8
17
  if (options.membersPreview !== void 0)
@@ -49,6 +58,69 @@ export function useTelaAdmin() {
49
58
  }
50
59
  return await response.json();
51
60
  }
61
+ async function createApplication(options) {
62
+ const token = useCookie(jwtCookieName).value;
63
+ const headers = new Headers({
64
+ "Accept": "application/json",
65
+ "Content-Type": "application/json"
66
+ });
67
+ if (token) {
68
+ headers.set("Authorization", `Bearer ${token}`);
69
+ }
70
+ const response = await fetch(buildApplicationsUrl(apiUrl), {
71
+ body: JSON.stringify(options),
72
+ credentials: "include",
73
+ headers,
74
+ method: "POST"
75
+ });
76
+ if (!response.ok) {
77
+ const message = await parseAdminResponseError(response);
78
+ throw new Error(`Failed to create application: ${message}`);
79
+ }
80
+ return await response.json();
81
+ }
82
+ async function updateApplication(applicationId, options) {
83
+ const token = useCookie(jwtCookieName).value;
84
+ const headers = new Headers({
85
+ "Accept": "application/json",
86
+ "Content-Type": "application/json"
87
+ });
88
+ if (token) {
89
+ headers.set("Authorization", `Bearer ${token}`);
90
+ }
91
+ const response = await fetch(buildApplicationUrl(apiUrl, applicationId), {
92
+ body: JSON.stringify(options),
93
+ credentials: "include",
94
+ headers,
95
+ method: "PUT"
96
+ });
97
+ if (!response.ok) {
98
+ const message = await parseAdminResponseError(response);
99
+ throw new Error(`Failed to update application: ${message}`);
100
+ }
101
+ return await response.json();
102
+ }
103
+ async function createApplicationEntitlement(applicationId, options) {
104
+ const token = useCookie(jwtCookieName).value;
105
+ const headers = new Headers({
106
+ "Accept": "application/json",
107
+ "Content-Type": "application/json"
108
+ });
109
+ if (token) {
110
+ headers.set("Authorization", `Bearer ${token}`);
111
+ }
112
+ const response = await fetch(buildApplicationEntitlementsUrl(apiUrl, applicationId), {
113
+ body: JSON.stringify(options),
114
+ credentials: "include",
115
+ headers,
116
+ method: "POST"
117
+ });
118
+ if (!response.ok) {
119
+ const message = await parseAdminResponseError(response);
120
+ throw new Error(`Failed to add organization to application: ${message}`);
121
+ }
122
+ return await response.json();
123
+ }
52
124
  async function listOrganizations(options) {
53
125
  return await authClient.admin.listOrganizations(options);
54
126
  }
@@ -67,6 +139,9 @@ export function useTelaAdmin() {
67
139
  return {
68
140
  listUsers,
69
141
  listApplications,
142
+ createApplication,
143
+ updateApplication,
144
+ createApplicationEntitlement,
70
145
  listOrganizations,
71
146
  getOrganization,
72
147
  listOrganizationMembers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
- "version": "3.13.1",
3
+ "version": "3.15.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -36,7 +36,7 @@
36
36
  "docs": "nuxt-module-build prepare && typedoc"
37
37
  },
38
38
  "dependencies": {
39
- "@meistrari/auth-core": "1.24.0",
39
+ "@meistrari/auth-core": "1.26.0",
40
40
  "jose": "6.1.3"
41
41
  },
42
42
  "peerDependencies": {