@sso-id/node 0.2.8 → 0.2.9

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.
@@ -37,8 +37,27 @@ export declare class ManagementClient {
37
37
  update: (userId: string, data: Record<string, unknown>) => Promise<unknown>;
38
38
  delete: (userId: string) => Promise<void>;
39
39
  listRoles: (userId: string) => Promise<unknown>;
40
- assignRole: (userId: string, roleId: string) => Promise<void>;
40
+ assignRole: (userId: string, roleId: string, roleName?: string) => Promise<unknown>;
41
41
  removeRole: (userId: string, roleId: string) => Promise<void>;
42
+ /**
43
+ * Fetches comprehensive application-scoped details for a user:
44
+ * - Full user profile (merged from /api/users/{id} and /api/applications/{appId}/users)
45
+ * - Assigned application roles & available application roles (/api/users/{id}/roles & /api/applications/{appId}/roles)
46
+ * - Service plan subscriptions & application service plans/offers (/api/stripe/users/{id}/subscriptions & /api/stripe/service-plans/clients/{clientId}/emails/...)
47
+ */
48
+ getDetails: (userId: string) => Promise<{
49
+ profile: Record<string, any>;
50
+ roles: {
51
+ roleName: any;
52
+ roleDescription: any;
53
+ }[];
54
+ availableRoles: Record<string, any>[];
55
+ subscriptions: {
56
+ planDetails: Record<string, any>;
57
+ offers: any[];
58
+ }[];
59
+ availableServicePlans: Record<string, any>[];
60
+ }>;
42
61
  };
43
62
  readonly roles: {
44
63
  list: () => Promise<unknown>;
@@ -126,9 +126,78 @@ export class ManagementClient {
126
126
  const appId = await this.getApplicationId();
127
127
  return this.request('DELETE', `/api/applications/${encodeURIComponent(appId)}/users/${encodeURIComponent(userId)}`);
128
128
  },
129
- listRoles: (userId) => this.request('GET', `/api/users/${encodeURIComponent(userId)}/roles`),
130
- assignRole: (userId, roleId) => this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, { roleId }),
129
+ listRoles: async (userId) => {
130
+ const appId = await this.getApplicationId();
131
+ return this.request('GET', `/api/users/${encodeURIComponent(userId)}/roles?appId=${encodeURIComponent(appId)}`);
132
+ },
133
+ assignRole: async (userId, roleId, roleName) => {
134
+ const appId = await this.getApplicationId();
135
+ return this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, {
136
+ userId,
137
+ applicationId: appId,
138
+ roleId,
139
+ roleName: roleName || '',
140
+ });
141
+ },
131
142
  removeRole: (userId, roleId) => this.request('DELETE', `/api/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleId)}`),
143
+ /**
144
+ * Fetches comprehensive application-scoped details for a user:
145
+ * - Full user profile (merged from /api/users/{id} and /api/applications/{appId}/users)
146
+ * - Assigned application roles & available application roles (/api/users/{id}/roles & /api/applications/{appId}/roles)
147
+ * - Service plan subscriptions & application service plans/offers (/api/stripe/users/{id}/subscriptions & /api/stripe/service-plans/clients/{clientId}/emails/...)
148
+ */
149
+ getDetails: async (userId) => {
150
+ const appId = await this.getApplicationId();
151
+ const [appUsersRaw, fullProfileRaw, userRolesRaw, appRolesRaw, subsRaw, plansRaw] = await Promise.all([
152
+ this.request('GET', `/api/applications/${encodeURIComponent(appId)}/users`).catch(() => []),
153
+ this.request('GET', `/api/users/${encodeURIComponent(userId)}`).catch(() => null),
154
+ this.request('GET', `/api/users/${encodeURIComponent(userId)}/roles?appId=${encodeURIComponent(appId)}`).catch(() => []),
155
+ this.request('GET', `/api/applications/${encodeURIComponent(appId)}/roles`).catch(() => []),
156
+ this.request('GET', `/api/stripe/users/${encodeURIComponent(userId)}/subscriptions?appId=${encodeURIComponent(appId)}`).catch(() => []),
157
+ this.request('GET', `/api/stripe/service-plans/clients/${encodeURIComponent(this.options.clientId)}/emails/default`).catch(() => []),
158
+ ]);
159
+ const appUsers = Array.isArray(appUsersRaw) ? appUsersRaw : [];
160
+ const appUserMatch = appUsers.find((u) => String(u.userId || u.id) === userId) || {};
161
+ const profile = {
162
+ ...appUserMatch,
163
+ ...(fullProfileRaw && typeof fullProfileRaw === 'object' ? fullProfileRaw : {}),
164
+ userId,
165
+ applicationId: appId,
166
+ };
167
+ const appRoles = Array.isArray(appRolesRaw) ? appRolesRaw : [];
168
+ const rawUserRoles = Array.isArray(userRolesRaw)
169
+ ? userRolesRaw
170
+ : Array.isArray(appUserMatch.userRoles)
171
+ ? appUserMatch.userRoles
172
+ : [];
173
+ const roles = rawUserRoles.map((ur) => {
174
+ const roleDef = appRoles.find((r) => String(r.roleId) === String(ur.roleId)) || {};
175
+ return {
176
+ ...roleDef,
177
+ ...ur,
178
+ roleName: ur.roleName || roleDef.roleName || 'Application Member',
179
+ roleDescription: ur.roleDescription || roleDef.roleDescription || 'Assigned role for this application',
180
+ };
181
+ });
182
+ const servicePlans = Array.isArray(plansRaw) ? plansRaw : [];
183
+ const rawSubs = Array.isArray(subsRaw) ? subsRaw : [];
184
+ const subscriptions = rawSubs.map((s) => {
185
+ const planDef = servicePlans.find((p) => String(p.servicePlanId) === String(s.servicePlanId) ||
186
+ String(p.servicePlanName || '').toLowerCase() === String(s.subscriptionName || '').toLowerCase()) || servicePlans[0] || {};
187
+ return {
188
+ ...s,
189
+ planDetails: planDef,
190
+ offers: Array.isArray(planDef.servicePlanOffers) ? planDef.servicePlanOffers : [],
191
+ };
192
+ });
193
+ return {
194
+ profile,
195
+ roles,
196
+ availableRoles: appRoles,
197
+ subscriptions,
198
+ availableServicePlans: servicePlans,
199
+ };
200
+ },
132
201
  };
133
202
  roles = {
134
203
  list: async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sso-id/node",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "type": "module",
5
5
  "description": "Official SSO.ID Node.js SDK (RS256 JWKS JWT verification, Express/Fastify middleware, Management API client)",
6
6
  "main": "dist/index.js",