@sso-id/node 0.1.0 → 0.2.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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './jwt.js';
2
2
  export * from './management.js';
3
+ export * from './scim.js';
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './jwt.js';
2
2
  export * from './management.js';
3
+ export * from './scim.js';
@@ -1,3 +1,4 @@
1
+ import type { ScimGroupResource, ScimUserResource } from './scim.js';
1
2
  export interface ManagementClientOptions {
2
3
  /** Tenant domain (e.g. "acme.sso.id" or "https://acme.sso.id") */
3
4
  domain: string;
@@ -23,8 +24,12 @@ export declare class ManagementClient {
23
24
  }) => Promise<unknown>;
24
25
  get: (userId: string) => Promise<unknown>;
25
26
  create: (data: Record<string, unknown>) => Promise<unknown>;
27
+ invite: (data: Record<string, unknown>) => Promise<unknown>;
26
28
  update: (userId: string, data: Record<string, unknown>) => Promise<unknown>;
27
29
  delete: (userId: string) => Promise<void>;
30
+ listRoles: (userId: string) => Promise<unknown>;
31
+ assignRole: (userId: string, roleId: string) => Promise<void>;
32
+ removeRole: (userId: string, roleId: string) => Promise<void>;
28
33
  };
29
34
  readonly roles: {
30
35
  list: () => Promise<unknown>;
@@ -37,6 +42,56 @@ export declare class ManagementClient {
37
42
  readonly organizations: {
38
43
  list: () => Promise<unknown>;
39
44
  get: (orgId: string) => Promise<unknown>;
45
+ create: (data: Record<string, unknown>) => Promise<unknown>;
46
+ update: (orgId: string, data: Record<string, unknown>) => Promise<unknown>;
47
+ delete: (orgId: string) => Promise<void>;
48
+ listUsers: (orgId: string) => Promise<unknown>;
49
+ addUser: (orgId: string, data: Record<string, unknown>) => Promise<unknown>;
50
+ removeUser: (orgId: string, userId: string) => Promise<void>;
51
+ listGroups: (orgId: string) => Promise<unknown>;
52
+ addGroup: (orgId: string, data: Record<string, unknown>) => Promise<unknown>;
53
+ removeGroup: (orgId: string, groupId: string) => Promise<void>;
54
+ };
55
+ readonly organizationUnits: {
56
+ list: () => Promise<unknown>;
57
+ listByOrganization: (orgId: string) => Promise<unknown>;
58
+ get: (orgId: string, unitId: string) => Promise<unknown>;
59
+ create: (data: Record<string, unknown>) => Promise<unknown>;
60
+ update: (unitId: string, data: Record<string, unknown>) => Promise<unknown>;
61
+ delete: (unitId: string) => Promise<void>;
62
+ listUsers: (unitId: string) => Promise<unknown>;
63
+ addUser: (data: Record<string, unknown>) => Promise<unknown>;
64
+ removeUser: (orgId: string, unitId: string, userId: string) => Promise<void>;
65
+ listGroups: (unitId: string) => Promise<unknown>;
66
+ addGroup: (data: Record<string, unknown>) => Promise<unknown>;
67
+ removeGroup: (unitId: string, groupId: string) => Promise<void>;
68
+ };
69
+ readonly groups: {
70
+ list: () => Promise<unknown>;
71
+ get: (groupId: string) => Promise<unknown>;
72
+ create: (data: Record<string, unknown>) => Promise<unknown>;
73
+ update: (groupId: string, data: Record<string, unknown>) => Promise<unknown>;
74
+ delete: (groupId: string) => Promise<void>;
75
+ listUsers: (groupId: string) => Promise<unknown>;
76
+ addUser: (groupId: string, userId: string) => Promise<unknown>;
77
+ removeUser: (groupId: string, userId: string) => Promise<void>;
78
+ };
79
+ readonly scim: {
80
+ forConnection: (connectionId?: string) => {
81
+ serviceProviderConfig: () => Promise<unknown>;
82
+ schemas: () => Promise<unknown>;
83
+ listUsers: (filter?: string) => Promise<unknown>;
84
+ getUser: (id: string) => Promise<ScimUserResource>;
85
+ createUser: (user: ScimUserResource) => Promise<ScimUserResource>;
86
+ replaceUser: (id: string, user: ScimUserResource) => Promise<ScimUserResource>;
87
+ patchUser: (id: string, patchPayload: Record<string, unknown>) => Promise<ScimUserResource>;
88
+ deleteUser: (id: string) => Promise<void>;
89
+ listGroups: (filter?: string) => Promise<unknown>;
90
+ getGroup: (id: string) => Promise<ScimGroupResource>;
91
+ createGroup: (group: ScimGroupResource) => Promise<ScimGroupResource>;
92
+ replaceGroup: (id: string, group: ScimGroupResource) => Promise<ScimGroupResource>;
93
+ deleteGroup: (id: string) => Promise<void>;
94
+ };
40
95
  };
41
96
  readonly auditLogs: {
42
97
  list: (query?: {
@@ -64,21 +64,80 @@ export class ManagementClient {
64
64
  if (query?.search)
65
65
  params.set('search', query.search);
66
66
  const qs = params.toString();
67
- return this.request('GET', `/api/v1/users${qs ? `?${qs}` : ''}`);
67
+ return this.request('GET', `/api/users${qs ? `?${qs}` : ''}`);
68
68
  },
69
- get: (userId) => this.request('GET', `/api/v1/users/${encodeURIComponent(userId)}`),
70
- create: (data) => this.request('POST', '/api/v1/users', data),
71
- update: (userId, data) => this.request('PUT', `/api/v1/users/${encodeURIComponent(userId)}`, data),
72
- delete: (userId) => this.request('DELETE', `/api/v1/users/${encodeURIComponent(userId)}`),
69
+ get: (userId) => this.request('GET', `/api/users/${encodeURIComponent(userId)}`),
70
+ create: (data) => this.request('POST', '/api/users', data),
71
+ invite: (data) => this.request('POST', '/api/users/invite', data),
72
+ update: (userId, data) => this.request('PUT', `/api/users/${encodeURIComponent(userId)}`, data),
73
+ delete: (userId) => this.request('DELETE', `/api/users/${encodeURIComponent(userId)}`),
74
+ listRoles: (userId) => this.request('GET', `/api/users/${encodeURIComponent(userId)}/roles`),
75
+ assignRole: (userId, roleId) => this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, { roleId }),
76
+ removeRole: (userId, roleId) => this.request('DELETE', `/api/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleId)}`),
73
77
  };
74
78
  roles = {
75
79
  list: () => this.request('GET', '/api/v1/roles'),
76
80
  create: (data) => this.request('POST', '/api/v1/roles', data),
77
- assignToUser: (userId, roleId) => this.request('POST', `/api/v1/users/${encodeURIComponent(userId)}/roles`, { roleId }),
81
+ assignToUser: (userId, roleId) => this.request('POST', `/api/users/${encodeURIComponent(userId)}/roles`, { roleId }),
78
82
  };
79
83
  organizations = {
80
- list: () => this.request('GET', '/api/v1/organizations'),
81
- get: (orgId) => this.request('GET', `/api/v1/organizations/${encodeURIComponent(orgId)}`),
84
+ list: () => this.request('GET', '/api/organizations'),
85
+ get: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}`),
86
+ create: (data) => this.request('POST', '/api/organizations', data),
87
+ update: (orgId, data) => this.request('PUT', `/api/organizations/${encodeURIComponent(orgId)}`, data),
88
+ delete: (orgId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}`),
89
+ listUsers: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}/users`),
90
+ addUser: (orgId, data) => this.request('POST', `/api/organizations/${encodeURIComponent(orgId)}/users`, data),
91
+ removeUser: (orgId, userId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}/users/${encodeURIComponent(userId)}`),
92
+ listGroups: (orgId) => this.request('GET', `/api/organizations/${encodeURIComponent(orgId)}/groups`),
93
+ addGroup: (orgId, data) => this.request('POST', `/api/organizations/${encodeURIComponent(orgId)}/groups`, data),
94
+ removeGroup: (orgId, groupId) => this.request('DELETE', `/api/organizations/${encodeURIComponent(orgId)}/groups/${encodeURIComponent(groupId)}`),
95
+ };
96
+ organizationUnits = {
97
+ list: () => this.request('GET', '/api/organization-units'),
98
+ listByOrganization: (orgId) => this.request('GET', `/api/organization-units/organizationunit/organization/${encodeURIComponent(orgId)}`),
99
+ get: (orgId, unitId) => this.request('GET', `/api/organization-units/organization/${encodeURIComponent(orgId)}/organizationunit/${encodeURIComponent(unitId)}`),
100
+ create: (data) => this.request('POST', '/api/organization-units', data),
101
+ update: (unitId, data) => this.request('PUT', `/api/organization-units/${encodeURIComponent(unitId)}`, data),
102
+ delete: (unitId) => this.request('DELETE', `/api/organization-units/${encodeURIComponent(unitId)}`),
103
+ listUsers: (unitId) => this.request('GET', `/api/organization-units/organizationunit/${encodeURIComponent(unitId)}/users`),
104
+ addUser: (data) => this.request('POST', '/api/organization-units/organizationunit/user', data),
105
+ removeUser: (orgId, unitId, userId) => this.request('DELETE', `/api/organization-units/organization/${encodeURIComponent(orgId)}/organizationunit/${encodeURIComponent(unitId)}/user/${encodeURIComponent(userId)}`),
106
+ listGroups: (unitId) => this.request('GET', `/api/organization-units/organizationunit/groups/${encodeURIComponent(unitId)}`),
107
+ addGroup: (data) => this.request('POST', '/api/organization-units/organizationunit/group', data),
108
+ removeGroup: (unitId, groupId) => this.request('DELETE', `/api/organization-units/organizationUnit/${encodeURIComponent(unitId)}/group/${encodeURIComponent(groupId)}`),
109
+ };
110
+ groups = {
111
+ list: () => this.request('GET', '/api/groups'),
112
+ get: (groupId) => this.request('GET', `/api/groups/${encodeURIComponent(groupId)}`),
113
+ create: (data) => this.request('POST', '/api/groups', data),
114
+ update: (groupId, data) => this.request('PUT', `/api/groups/${encodeURIComponent(groupId)}`, data),
115
+ delete: (groupId) => this.request('DELETE', `/api/groups/${encodeURIComponent(groupId)}`),
116
+ listUsers: (groupId) => this.request('GET', `/api/groups/${encodeURIComponent(groupId)}/users`),
117
+ addUser: (groupId, userId) => this.request('POST', `/api/groups/${encodeURIComponent(groupId)}/users/${encodeURIComponent(userId)}`),
118
+ removeUser: (groupId, userId) => this.request('DELETE', `/api/groups/${encodeURIComponent(groupId)}/users/${encodeURIComponent(userId)}`),
119
+ };
120
+ scim = {
121
+ forConnection: (connectionId) => {
122
+ const prefix = connectionId
123
+ ? `/api/scim/v2/connections/${encodeURIComponent(connectionId)}`
124
+ : '/api/scim/v2';
125
+ return {
126
+ serviceProviderConfig: () => this.request('GET', `${prefix}/ServiceProviderConfig`),
127
+ schemas: () => this.request('GET', `${prefix}/Schemas`),
128
+ listUsers: (filter) => this.request('GET', `${prefix}/Users${filter ? `?filter=${encodeURIComponent(filter)}` : ''}`),
129
+ getUser: (id) => this.request('GET', `${prefix}/Users/${encodeURIComponent(id)}`),
130
+ createUser: (user) => this.request('POST', `${prefix}/Users`, user),
131
+ replaceUser: (id, user) => this.request('PUT', `${prefix}/Users/${encodeURIComponent(id)}`, user),
132
+ patchUser: (id, patchPayload) => this.request('PATCH', `${prefix}/Users/${encodeURIComponent(id)}`, patchPayload),
133
+ deleteUser: (id) => this.request('DELETE', `${prefix}/Users/${encodeURIComponent(id)}`),
134
+ listGroups: (filter) => this.request('GET', `${prefix}/Groups${filter ? `?filter=${encodeURIComponent(filter)}` : ''}`),
135
+ getGroup: (id) => this.request('GET', `${prefix}/Groups/${encodeURIComponent(id)}`),
136
+ createGroup: (group) => this.request('POST', `${prefix}/Groups`, group),
137
+ replaceGroup: (id, group) => this.request('PUT', `${prefix}/Groups/${encodeURIComponent(id)}`, group),
138
+ deleteGroup: (id) => this.request('DELETE', `${prefix}/Groups/${encodeURIComponent(id)}`),
139
+ };
140
+ },
82
141
  };
83
142
  auditLogs = {
84
143
  list: (query) => {
package/dist/scim.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export declare const SCIM_CORE_USER_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:User";
2
+ export declare const SCIM_CORE_GROUP_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:Group";
3
+ export declare const SCIM_LIST_RESPONSE_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:ListResponse";
4
+ export declare const SCIM_ERROR_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:Error";
5
+ export interface ScimUserResource {
6
+ schemas?: string[];
7
+ id?: string;
8
+ externalId?: string;
9
+ userName: string;
10
+ name?: {
11
+ formatted?: string;
12
+ givenName?: string;
13
+ familyName?: string;
14
+ };
15
+ displayName?: string;
16
+ emails?: Array<{
17
+ value: string;
18
+ type?: string;
19
+ primary?: boolean;
20
+ }>;
21
+ active?: boolean;
22
+ meta?: {
23
+ resourceType?: string;
24
+ created?: string;
25
+ lastModified?: string;
26
+ };
27
+ }
28
+ export interface ScimGroupResource {
29
+ schemas?: string[];
30
+ id?: string;
31
+ externalId?: string;
32
+ displayName: string;
33
+ members?: Array<{
34
+ value: string;
35
+ display?: string;
36
+ $ref?: string;
37
+ }>;
38
+ meta?: {
39
+ resourceType?: string;
40
+ created?: string;
41
+ lastModified?: string;
42
+ };
43
+ }
44
+ export interface ScimListResponse<T> {
45
+ schemas: [typeof SCIM_LIST_RESPONSE_SCHEMA];
46
+ totalResults: number;
47
+ startIndex: number;
48
+ itemsPerPage: number;
49
+ Resources: T[];
50
+ }
51
+ export declare function verifyScimBearerToken(authHeader: string | undefined, expectedToken: string): boolean;
52
+ export declare function formatScimListResponse<T>(resources: T[], startIndex?: number, itemsPerPage?: number, totalResults?: number): ScimListResponse<T>;
53
+ export declare function formatScimError(detail: string, status: number, scimType?: string): {
54
+ scimType?: string | undefined;
55
+ schemas: string[];
56
+ detail: string;
57
+ status: string;
58
+ };
package/dist/scim.js ADDED
@@ -0,0 +1,34 @@
1
+ import { timingSafeEqual } from 'node:crypto';
2
+ export const SCIM_CORE_USER_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:User';
3
+ export const SCIM_CORE_GROUP_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:Group';
4
+ export const SCIM_LIST_RESPONSE_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:ListResponse';
5
+ export const SCIM_ERROR_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:Error';
6
+ export function verifyScimBearerToken(authHeader, expectedToken) {
7
+ if (!authHeader || !expectedToken)
8
+ return false;
9
+ const match = /^Bearer\s+(.+)$/i.exec(authHeader.trim());
10
+ if (!match)
11
+ return false;
12
+ const provided = Buffer.from(match[1]);
13
+ const expected = Buffer.from(expectedToken);
14
+ if (provided.length !== expected.length)
15
+ return false;
16
+ return timingSafeEqual(provided, expected);
17
+ }
18
+ export function formatScimListResponse(resources, startIndex = 1, itemsPerPage = resources.length, totalResults = resources.length) {
19
+ return {
20
+ schemas: [SCIM_LIST_RESPONSE_SCHEMA],
21
+ totalResults,
22
+ startIndex,
23
+ itemsPerPage,
24
+ Resources: resources,
25
+ };
26
+ }
27
+ export function formatScimError(detail, status, scimType) {
28
+ return {
29
+ schemas: [SCIM_ERROR_SCHEMA],
30
+ detail,
31
+ status: String(status),
32
+ ...(scimType ? { scimType } : {}),
33
+ };
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sso-id/node",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
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",