@meistrari/auth-nuxt 3.23.1 → 3.24.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.23.1",
4
+ "version": "3.24.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 { AdminApplicationRecord, AdminApplicationEntitlementRecord, AdminOrganization, AdminOrganizationSummary, AdminOrganizationTeamRecord, AdminUser, AdminUserAccess, CreateAdminApplicationEntitlementOptions, CreateAdminApplicationOptions, CreateAdminOrganizationOptions, CreateAdminOrganizationTeamOptions, GetAdminOrganizationOptions, GetAdminOrganizationsSummaryOptions, InviteAdminOrganizationUsersOptions, InviteAdminOrganizationUsersResult, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminOrganizationTeamsOptions, ListAdminOrganizationTeamsResult, ListAdminUsersOptions, ListAdminUsersResult, AdminMember, RemoveAdminMemberOptions, ResendAdminInviteOptions, SetAdminUserApplicationRoleOptions, SetAdminUserTeamOptions, UpdateAdminMemberRoleOptions, UpdateAdminOrganizationOptions } from '@meistrari/auth-core';
1
+ import type { AdminApplicationRecord, AdminApplicationEntitlementRecord, AdminEntitlementWithRules, AdminOrganization, AdminOrganizationSummary, AdminOrganizationTeamRecord, AdminUser, AdminUserAccess, CreateAdminApplicationEntitlementOptions, CreateAdminApplicationOptions, CreateAdminOrganizationOptions, CreateAdminOrganizationTeamOptions, GetAdminOrganizationOptions, GetAdminOrganizationsSummaryOptions, InviteAdminOrganizationUsersOptions, InviteAdminOrganizationUsersResult, ListAdminApplicationsOptions, ListAdminApplicationsResult, ListAdminOrganizationMembersOptions, ListAdminOrganizationMembersResult, ListAdminOrganizationsOptions, ListAdminOrganizationsResult, ListAdminOrganizationTeamsOptions, ListAdminOrganizationTeamsResult, ListAdminUsersOptions, ListAdminUsersResult, AdminMember, RemoveAdminMemberOptions, ResendAdminInviteOptions, SetAdminEntitlementRulesOptions, SetAdminUserApplicationRoleOptions, SetAdminUserTeamOptions, UpdateAdminEntitlementOptions, UpdateAdminMemberRoleOptions, UpdateAdminOrganizationOptions } from '@meistrari/auth-core';
2
2
  export interface UseTelaAdminReturn {
3
3
  /**
4
4
  * Lists users as a global admin, optionally with organization previews
@@ -39,6 +39,32 @@ export interface UseTelaAdminReturn {
39
39
  * @returns The created entitlement
40
40
  */
41
41
  createApplicationEntitlement: (applicationId: string, options: CreateAdminApplicationEntitlementOptions) => Promise<AdminApplicationEntitlementRecord>;
42
+ /**
43
+ * Fetches a single entitlement together with its ordered access rules.
44
+ * @param entitlementId - ID of the entitlement to fetch
45
+ * @returns The entitlement and its rules
46
+ */
47
+ getEntitlement: (entitlementId: string) => Promise<AdminEntitlementWithRules>;
48
+ /**
49
+ * Replaces all access rules on an entitlement in a single call.
50
+ * @param entitlementId - ID of the entitlement whose rules are replaced
51
+ * @param options - The full set of rules to persist
52
+ * @returns The entitlement with the saved rules
53
+ */
54
+ setEntitlementRules: (entitlementId: string, options: SetAdminEntitlementRulesOptions) => Promise<AdminEntitlementWithRules>;
55
+ /**
56
+ * Enables or disables an entitlement.
57
+ * @param entitlementId - ID of the entitlement to update
58
+ * @param options - The desired enabled state
59
+ * @returns The updated entitlement
60
+ */
61
+ updateEntitlement: (entitlementId: string, options: UpdateAdminEntitlementOptions) => Promise<AdminApplicationEntitlementRecord>;
62
+ /**
63
+ * Deletes an entitlement and all of its access rules.
64
+ * @param entitlementId - ID of the entitlement to delete
65
+ * @returns The deleted entitlement
66
+ */
67
+ deleteEntitlement: (entitlementId: string) => Promise<AdminApplicationEntitlementRecord>;
42
68
  /**
43
69
  * Lists all organizations as a global admin, optionally with member and
44
70
  * application previews and totals when a preview size is requested.
@@ -161,6 +187,9 @@ export interface UseTelaAdminReturn {
161
187
  * Composable for global admin operations.
162
188
  *
163
189
  * All operations require the authenticated user to hold the global admin role.
190
+ * The admin API authenticates first-party callers with the session cookie, so
191
+ * this client never attaches the JWT: the API reads a bearer token only as an
192
+ * internal API key and rejects anything else.
164
193
  *
165
194
  * @returns An object containing admin management functions.
166
195
  */
@@ -1,44 +1,8 @@
1
- import { useCookie, useRuntimeConfig } from "#app";
1
+ import { useRuntimeConfig } from "#app";
2
2
  import { createNuxtAuthClient } from "../shared.js";
3
- function buildApplicationsUrl(apiUrl) {
4
- const base = apiUrl.endsWith("/") ? apiUrl : `${apiUrl}/`;
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);
15
- if (options.limit !== void 0)
16
- url.searchParams.set("limit", String(options.limit));
17
- if (options.membersPreview !== void 0)
18
- url.searchParams.set("membersPreview", String(options.membersPreview));
19
- if (options.offset !== void 0)
20
- url.searchParams.set("offset", String(options.offset));
21
- if (options.orderBy)
22
- url.searchParams.set("orderBy", options.orderBy);
23
- if (options.orderDirection)
24
- url.searchParams.set("orderDirection", options.orderDirection);
25
- if (options.organizationId)
26
- url.searchParams.set("organizationId", options.organizationId);
27
- if (options.search)
28
- url.searchParams.set("search", options.search);
29
- return url;
30
- }
31
- async function parseAdminResponseError(response) {
32
- try {
33
- const body = await response.json();
34
- return body.error ?? body.message ?? response.statusText;
35
- } catch {
36
- return response.statusText;
37
- }
38
- }
39
3
  export function useTelaAdmin() {
40
- const { jwtCookieName, apiUrl } = useRuntimeConfig().public.telaAuth;
41
- const authClient = createNuxtAuthClient(apiUrl, () => useCookie(jwtCookieName).value ?? null);
4
+ const { apiUrl } = useRuntimeConfig().public.telaAuth;
5
+ const authClient = createNuxtAuthClient(apiUrl, () => null);
42
6
  async function listUsers(options) {
43
7
  return await authClient.admin.listUsers(options);
44
8
  }
@@ -46,83 +10,16 @@ export function useTelaAdmin() {
46
10
  return await authClient.admin.getUser(userId);
47
11
  }
48
12
  async function listApplications(options) {
49
- const token = useCookie(jwtCookieName).value;
50
- const headers = new Headers({ Accept: "application/json" });
51
- if (token) {
52
- headers.set("Authorization", `Bearer ${token}`);
53
- }
54
- const response = await fetch(buildListApplicationsUrl(apiUrl, options), {
55
- credentials: "include",
56
- headers
57
- });
58
- if (!response.ok) {
59
- const message = await parseAdminResponseError(response);
60
- throw new Error(`Failed to list applications: ${message}`);
61
- }
62
- return await response.json();
13
+ return await authClient.admin.listApplications(options);
63
14
  }
64
15
  async function createApplication(options) {
65
- const token = useCookie(jwtCookieName).value;
66
- const headers = new Headers({
67
- "Accept": "application/json",
68
- "Content-Type": "application/json"
69
- });
70
- if (token) {
71
- headers.set("Authorization", `Bearer ${token}`);
72
- }
73
- const response = await fetch(buildApplicationsUrl(apiUrl), {
74
- body: JSON.stringify(options),
75
- credentials: "include",
76
- headers,
77
- method: "POST"
78
- });
79
- if (!response.ok) {
80
- const message = await parseAdminResponseError(response);
81
- throw new Error(`Failed to create application: ${message}`);
82
- }
83
- return await response.json();
16
+ return await authClient.admin.createApplication(options);
84
17
  }
85
18
  async function updateApplication(applicationId, options) {
86
- const token = useCookie(jwtCookieName).value;
87
- const headers = new Headers({
88
- "Accept": "application/json",
89
- "Content-Type": "application/json"
90
- });
91
- if (token) {
92
- headers.set("Authorization", `Bearer ${token}`);
93
- }
94
- const response = await fetch(buildApplicationUrl(apiUrl, applicationId), {
95
- body: JSON.stringify(options),
96
- credentials: "include",
97
- headers,
98
- method: "PUT"
99
- });
100
- if (!response.ok) {
101
- const message = await parseAdminResponseError(response);
102
- throw new Error(`Failed to update application: ${message}`);
103
- }
104
- return await response.json();
19
+ return await authClient.admin.updateApplication(applicationId, options);
105
20
  }
106
21
  async function createApplicationEntitlement(applicationId, options) {
107
- const token = useCookie(jwtCookieName).value;
108
- const headers = new Headers({
109
- "Accept": "application/json",
110
- "Content-Type": "application/json"
111
- });
112
- if (token) {
113
- headers.set("Authorization", `Bearer ${token}`);
114
- }
115
- const response = await fetch(buildApplicationEntitlementsUrl(apiUrl, applicationId), {
116
- body: JSON.stringify(options),
117
- credentials: "include",
118
- headers,
119
- method: "POST"
120
- });
121
- if (!response.ok) {
122
- const message = await parseAdminResponseError(response);
123
- throw new Error(`Failed to add organization to application: ${message}`);
124
- }
125
- return await response.json();
22
+ return await authClient.admin.createApplicationEntitlement(applicationId, options);
126
23
  }
127
24
  async function listOrganizations(options) {
128
25
  return await authClient.admin.listOrganizations(options);
@@ -145,6 +42,18 @@ export function useTelaAdmin() {
145
42
  async function getUserAccess(userId) {
146
43
  return await authClient.admin.getUserAccess(userId);
147
44
  }
45
+ async function getEntitlement(entitlementId) {
46
+ return await authClient.admin.getEntitlement(entitlementId);
47
+ }
48
+ async function setEntitlementRules(entitlementId, options) {
49
+ return await authClient.admin.setEntitlementRules(entitlementId, options);
50
+ }
51
+ async function updateEntitlement(entitlementId, options) {
52
+ return await authClient.admin.updateEntitlement(entitlementId, options);
53
+ }
54
+ async function deleteEntitlement(entitlementId) {
55
+ return await authClient.admin.deleteEntitlement(entitlementId);
56
+ }
148
57
  async function createOrganization(options) {
149
58
  return await authClient.admin.createOrganization(options);
150
59
  }
@@ -188,6 +97,10 @@ export function useTelaAdmin() {
188
97
  createApplication,
189
98
  updateApplication,
190
99
  createApplicationEntitlement,
100
+ getEntitlement,
101
+ setEntitlementRules,
102
+ updateEntitlement,
103
+ deleteEntitlement,
191
104
  listOrganizations,
192
105
  getOrganization,
193
106
  getOrganizationsSummary,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
- "version": "3.23.1",
3
+ "version": "3.24.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.33.1",
39
+ "@meistrari/auth-core": "1.34.0",
40
40
  "jose": "6.1.3"
41
41
  },
42
42
  "peerDependencies": {