slotlock 0.8.0 → 0.10.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +542 -0
  2. package/NOTICE +2 -0
  3. package/README.md +4 -2
  4. package/agent-server.d.ts +25 -5
  5. package/agent-server.js +152 -7
  6. package/agent-store-backend.d.ts +6 -1
  7. package/agent-store-backend.js +1068 -68
  8. package/application-api.d.ts +28 -1
  9. package/application-api.js +789 -21
  10. package/approvals.d.ts +2 -0
  11. package/approvals.js +12 -5
  12. package/assistant.d.ts +34 -8
  13. package/assistant.js +81 -26
  14. package/availability-store.d.ts +193 -0
  15. package/availability-store.js +566 -0
  16. package/booking-rules.d.ts +103 -5
  17. package/booking-rules.js +263 -15
  18. package/config.d.ts +50 -0
  19. package/config.js +107 -0
  20. package/dashboard-assistant-ui.d.ts +1 -1
  21. package/dashboard-assistant-ui.js +109 -8
  22. package/dashboard-scope.d.ts +7 -0
  23. package/dashboard-scope.js +21 -0
  24. package/dashboard.d.ts +152 -8
  25. package/dashboard.js +3868 -399
  26. package/ddl-identity.d.ts +25 -0
  27. package/ddl-identity.js +881 -0
  28. package/ddl-scim.d.ts +5 -0
  29. package/ddl-scim.js +740 -0
  30. package/ddl-sso.d.ts +15 -0
  31. package/ddl-sso.js +1033 -0
  32. package/ddl.d.ts +44 -9
  33. package/ddl.js +2872 -47
  34. package/domains.d.ts +117 -0
  35. package/domains.js +340 -0
  36. package/event-feed.d.ts +2 -2
  37. package/event-feed.js +24 -34
  38. package/holiday-import.d.ts +38 -0
  39. package/holiday-import.js +56 -0
  40. package/holidays.d.ts +38 -0
  41. package/holidays.js +209 -0
  42. package/hours.d.ts +125 -0
  43. package/hours.js +224 -0
  44. package/index.d.ts +24 -5
  45. package/index.js +17 -3
  46. package/interop.d.ts +25 -7
  47. package/interop.js +145 -17
  48. package/invitation-email.d.ts +26 -0
  49. package/invitation-email.js +73 -0
  50. package/lifecycle.d.ts +31 -0
  51. package/lifecycle.js +115 -0
  52. package/maintenance.d.ts +26 -2
  53. package/maintenance.js +70 -2
  54. package/metrics.js +3 -0
  55. package/oidc.d.ts +135 -0
  56. package/oidc.js +452 -0
  57. package/openapi.json +20172 -9850
  58. package/package.json +2 -1
  59. package/ranges.d.ts +28 -0
  60. package/ranges.js +135 -0
  61. package/resource-search.d.ts +19 -0
  62. package/resource-search.js +153 -0
  63. package/rest-api.js +7 -0
  64. package/rules.d.ts +2 -0
  65. package/rules.js +2 -0
  66. package/scim-server.d.ts +19 -0
  67. package/scim-server.js +243 -0
  68. package/scim.d.ts +180 -0
  69. package/scim.js +416 -0
  70. package/self-host.d.ts +19 -6
  71. package/self-host.js +483 -28
  72. package/slotlock.manifest.json +1 -1
  73. package/store.d.ts +637 -23
  74. package/store.js +2529 -147
  75. package/types.d.ts +230 -0
  76. package/types.js +68 -1
  77. package/workspace-domains.d.ts +146 -0
  78. package/workspace-domains.js +249 -0
  79. package/workspace-roles.d.ts +47 -0
  80. package/workspace-roles.js +304 -0
  81. package/workspace-scim.d.ts +89 -0
  82. package/workspace-scim.js +157 -0
  83. package/workspace-sso.d.ts +131 -0
  84. package/workspace-sso.js +180 -0
  85. package/workspaces.d.ts +240 -0
  86. package/workspaces.js +433 -0
package/scim.d.ts ADDED
@@ -0,0 +1,180 @@
1
+ export declare const SLOTLOCK_SCIM_CONTENT_TYPE = "application/scim+json";
2
+ export declare const SCIM_USER_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:User";
3
+ export declare const SCIM_GROUP_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:Group";
4
+ export declare const SCIM_PATCH_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:PatchOp";
5
+ export declare const SCIM_LIST_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:ListResponse";
6
+ export declare const SCIM_ERROR_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:Error";
7
+ /** A page holds at most this many resources (ServiceProviderConfig's filter.maxResults). */
8
+ export declare const SLOTLOCK_SCIM_MAX_RESULTS = 100;
9
+ /** RFC 7644 §3.12's error types Slotlock answers with. */
10
+ export type SlotlockScimErrorType = 'invalidFilter' | 'uniqueness' | 'mutability' | 'invalidSyntax' | 'invalidPath' | 'noTarget' | 'invalidValue';
11
+ /** A request refused: its status and SCIM error type. */
12
+ export declare class SlotlockScimError extends Error {
13
+ readonly status: number;
14
+ readonly scimType: SlotlockScimErrorType | null;
15
+ constructor(status: number, scimType: SlotlockScimErrorType | null, message: string);
16
+ }
17
+ /** An error body: `status` as a string, as RFC 7644 §3.12 has it. */
18
+ export declare function slotlockScimErrorBody(status: number, scimType: SlotlockScimErrorType | null, detail: string): {
19
+ schemas: string[];
20
+ status: string;
21
+ scimType?: SlotlockScimErrorType;
22
+ detail: string;
23
+ };
24
+ /** The user attributes Slotlock keeps. */
25
+ export interface SlotlockScimUserAttributes {
26
+ /** As the provider sent it; matched case-insensitively. */
27
+ userName: string;
28
+ externalId: string | null;
29
+ active: boolean;
30
+ givenName: string | null;
31
+ familyName: string | null;
32
+ displayName: string | null;
33
+ /** The work email: `emails[type eq "work"]`, else the primary one, else the first. */
34
+ workEmail: string | null;
35
+ }
36
+ /** A group's attributes, its members by their SCIM ids. */
37
+ export interface SlotlockScimGroupAttributes {
38
+ displayName: string;
39
+ externalId: string | null;
40
+ members: string[];
41
+ }
42
+ /** A SCIM boolean: true or false, or the strings Entra sends ("True", "False"). */
43
+ export declare function slotlockScimBoolean(value: unknown): boolean;
44
+ /** A user as a POST or PUT body gives it (RFC 7643 §4.1): what Slotlock keeps, the rest ignored. */
45
+ export declare function slotlockScimUserFromBody(body: unknown): SlotlockScimUserAttributes;
46
+ /** A group as a POST or PUT body gives it. */
47
+ export declare function slotlockScimGroupFromBody(body: unknown): SlotlockScimGroupAttributes;
48
+ /** One patch operation, as normalised: its op in lowercase, its path (null: the resource), its value. */
49
+ export interface SlotlockScimPatchOperation {
50
+ op: 'add' | 'replace' | 'remove';
51
+ path: string | null;
52
+ value: unknown;
53
+ }
54
+ /** A PATCH body's operations, normalised (see the top of this file). */
55
+ export declare function slotlockScimPatchOperations(body: unknown): SlotlockScimPatchOperation[];
56
+ /** A user changed by a patch, all of it or none (RFC 7644 §3.5.2: a patch is atomic). */
57
+ export declare function slotlockScimPatchUser(current: SlotlockScimUserAttributes, id: string, operations: readonly SlotlockScimPatchOperation[]): SlotlockScimUserAttributes;
58
+ /** A group changed by a patch, all of it or none. */
59
+ export declare function slotlockScimPatchGroup(current: SlotlockScimGroupAttributes, id: string, operations: readonly SlotlockScimPatchOperation[]): SlotlockScimGroupAttributes;
60
+ /** A filter Slotlock answers: `attribute eq "value"`, joined by `and`; the attributes its caller allows. */
61
+ export interface SlotlockScimFilter {
62
+ /** In lowercase, as the caller's allowed list names it. */
63
+ attribute: string;
64
+ value: string;
65
+ }
66
+ /**
67
+ * A filter (RFC 7644 §3.4.2.2) as Okta and Entra send it: `eq` comparisons of the allowed
68
+ * attributes, joined by `and`. Anything else is 400 invalidFilter.
69
+ */
70
+ export declare function slotlockScimFilter(filter: string, allowed: readonly string[]): SlotlockScimFilter[];
71
+ /** Where a resource lives, for its meta. */
72
+ export interface SlotlockScimMeta {
73
+ created: Date;
74
+ lastModified: Date;
75
+ location: string;
76
+ }
77
+ /** A user as SCIM answers it: every attribute Slotlock keeps, so a GET then PUT loses nothing. */
78
+ export declare function slotlockScimUserResource(id: string, user: SlotlockScimUserAttributes, meta: SlotlockScimMeta): {
79
+ schemas: string[];
80
+ id: string;
81
+ externalId?: string;
82
+ userName: string;
83
+ active: boolean;
84
+ name?: {
85
+ givenName?: string;
86
+ familyName?: string;
87
+ };
88
+ displayName?: string;
89
+ emails?: {
90
+ value: string;
91
+ type: string;
92
+ primary: boolean;
93
+ }[];
94
+ meta: {
95
+ resourceType: string;
96
+ created: string;
97
+ lastModified: string;
98
+ location: string;
99
+ };
100
+ };
101
+ /** A group as SCIM answers it, with its members unless asked not to. */
102
+ export declare function slotlockScimGroupResource(id: string, group: SlotlockScimGroupAttributes, meta: SlotlockScimMeta, withMembers?: boolean): {
103
+ schemas: string[];
104
+ id: string;
105
+ displayName: string;
106
+ externalId?: string;
107
+ members?: {
108
+ value: string;
109
+ }[];
110
+ meta: {
111
+ resourceType: string;
112
+ created: string;
113
+ lastModified: string;
114
+ location: string;
115
+ };
116
+ };
117
+ /** A list response; an empty one too (Entra needs it), with integer counts. */
118
+ export declare function slotlockScimList(resources: readonly unknown[], totalResults: number, startIndex: number): {
119
+ schemas: string[];
120
+ totalResults: number;
121
+ startIndex: number;
122
+ itemsPerPage: number;
123
+ Resources: readonly unknown[];
124
+ };
125
+ /** startIndex and count as a page: startIndex below 1 read as 1, count clamped to 0–100. */
126
+ export declare function slotlockScimPage(query: URLSearchParams): {
127
+ startIndex: number;
128
+ count: number;
129
+ };
130
+ /** What Slotlock supports (RFC 7643 §5): PATCH, filters up to 100 results; no bulk, sort or ETags. */
131
+ export declare function slotlockScimServiceProviderConfig(documentationUri: string): {
132
+ schemas: string[];
133
+ documentationUri: string;
134
+ patch: {
135
+ supported: boolean;
136
+ };
137
+ bulk: {
138
+ supported: boolean;
139
+ maxOperations: number;
140
+ maxPayloadSize: number;
141
+ };
142
+ filter: {
143
+ supported: boolean;
144
+ maxResults: number;
145
+ };
146
+ changePassword: {
147
+ supported: boolean;
148
+ };
149
+ sort: {
150
+ supported: boolean;
151
+ };
152
+ etag: {
153
+ supported: boolean;
154
+ };
155
+ authenticationSchemes: {
156
+ type: string;
157
+ name: string;
158
+ description: string;
159
+ primary: boolean;
160
+ }[];
161
+ meta: {
162
+ resourceType: string;
163
+ };
164
+ };
165
+ /** The resource types Slotlock serves, as a list. */
166
+ export declare function slotlockScimResourceTypes(base: string): {
167
+ schemas: string[];
168
+ totalResults: number;
169
+ startIndex: number;
170
+ itemsPerPage: number;
171
+ Resources: readonly unknown[];
172
+ };
173
+ /** The schemas of what Slotlock keeps, as a list. */
174
+ export declare function slotlockScimSchemas(base: string): {
175
+ schemas: string[];
176
+ totalResults: number;
177
+ startIndex: number;
178
+ itemsPerPage: number;
179
+ Resources: readonly unknown[];
180
+ };
package/scim.js ADDED
@@ -0,0 +1,416 @@
1
+ // SCIM 2.0 (RFC 7643, RFC 7644) as Okta and Microsoft Entra ID speak it (teams phase 5.6–5.7): the
2
+ // pure part, shared by both runtimes. Requests are normalised here before anything is applied, so
3
+ // the database sees one shape whichever provider sent it:
4
+ // - `op` in any case (Entra without `aadOptscim062020` sends "Replace");
5
+ // - booleans as JSON booleans or the strings "True"/"False" (Entra again);
6
+ // - a replace with no path whose value holds dotted or URN-qualified keys (Entra with the flag,
7
+ // Okta's deactivation) expanded into one operation per attribute;
8
+ // - Okta's group rename, which carries the group's own id in its value, accepted;
9
+ // - Entra's member removal without the flag ({"op":"Remove","path":"members","value":[{value}]})
10
+ // read as removing those members, never as clearing the list;
11
+ // - a remove with no path refused (400 noTarget), as RFC 7644 §3.5.2.2 says.
12
+ // Attributes Slotlock does not keep (Entra's enterprise extension, phone numbers, …) are ignored.
13
+ export const SLOTLOCK_SCIM_CONTENT_TYPE = 'application/scim+json';
14
+ export const SCIM_USER_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:User';
15
+ export const SCIM_GROUP_SCHEMA = 'urn:ietf:params:scim:schemas:core:2.0:Group';
16
+ export const SCIM_PATCH_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:PatchOp';
17
+ export const SCIM_LIST_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:ListResponse';
18
+ export const SCIM_ERROR_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:Error';
19
+ /** A page holds at most this many resources (ServiceProviderConfig's filter.maxResults). */
20
+ export const SLOTLOCK_SCIM_MAX_RESULTS = 100;
21
+ /** A request refused: its status and SCIM error type. */
22
+ export class SlotlockScimError extends Error {
23
+ status;
24
+ scimType;
25
+ constructor(status, scimType, message) {
26
+ super(message);
27
+ this.status = status;
28
+ this.scimType = scimType;
29
+ this.name = 'SlotlockScimError';
30
+ }
31
+ }
32
+ /** An error body: `status` as a string, as RFC 7644 §3.12 has it. */
33
+ export function slotlockScimErrorBody(status, scimType, detail) {
34
+ return { schemas: [SCIM_ERROR_SCHEMA], status: String(status), ...(scimType ? { scimType } : {}), detail };
35
+ }
36
+ const invalid = (detail) => new SlotlockScimError(400, 'invalidValue', detail);
37
+ const textOf = (value, what, max = 254) => {
38
+ if (value === null || value === undefined)
39
+ return null;
40
+ if (typeof value !== 'string' || value.length > max || /[\p{Cc}]/u.test(value))
41
+ throw invalid(`${what} must be text of at most ${max} characters`);
42
+ const trimmed = value.trim();
43
+ return trimmed === '' ? null : trimmed;
44
+ };
45
+ /** A SCIM boolean: true or false, or the strings Entra sends ("True", "False"). */
46
+ export function slotlockScimBoolean(value) {
47
+ if (value === true || value === false)
48
+ return value;
49
+ if (typeof value === 'string' && /^(true|false)$/i.test(value.trim()))
50
+ return value.trim().toLowerCase() === 'true';
51
+ throw invalid('active must be true or false');
52
+ }
53
+ /** The work email of an `emails` value: type work, else primary, else the first. */
54
+ function workEmailOf(value) {
55
+ if (value === null || value === undefined)
56
+ return null;
57
+ if (!Array.isArray(value))
58
+ throw invalid('emails must be a list');
59
+ const emails = value.filter((entry) => typeof entry === 'object' && entry !== null);
60
+ const chosen = emails.find((entry) => typeof entry.type === 'string' && entry.type.toLowerCase() === 'work') ??
61
+ emails.find((entry) => entry.primary === true || entry.primary === 'true' || entry.primary === 'True') ??
62
+ emails[0];
63
+ const address = textOf(chosen?.value, 'An email');
64
+ return address === null ? null : address.toLowerCase();
65
+ }
66
+ /** A user as a POST or PUT body gives it (RFC 7643 §4.1): what Slotlock keeps, the rest ignored. */
67
+ export function slotlockScimUserFromBody(body) {
68
+ if (typeof body !== 'object' || body === null || Array.isArray(body))
69
+ throw new SlotlockScimError(400, 'invalidSyntax', 'A user is a JSON object');
70
+ const user = body;
71
+ const userName = textOf(user.userName, 'userName');
72
+ if (userName === null)
73
+ throw invalid('userName is required');
74
+ const name = typeof user.name === 'object' && user.name !== null ? user.name : {};
75
+ return {
76
+ userName,
77
+ externalId: textOf(user.externalId, 'externalId', 255),
78
+ active: user.active === undefined ? true : slotlockScimBoolean(user.active),
79
+ givenName: textOf(name.givenName, 'name.givenName', 100),
80
+ familyName: textOf(name.familyName, 'name.familyName', 100),
81
+ displayName: textOf(user.displayName, 'displayName', 200),
82
+ workEmail: workEmailOf(user.emails),
83
+ };
84
+ }
85
+ /** A group as a POST or PUT body gives it. */
86
+ export function slotlockScimGroupFromBody(body) {
87
+ if (typeof body !== 'object' || body === null || Array.isArray(body))
88
+ throw new SlotlockScimError(400, 'invalidSyntax', 'A group is a JSON object');
89
+ const group = body;
90
+ const displayName = textOf(group.displayName, 'displayName', 200);
91
+ if (displayName === null)
92
+ throw invalid('displayName is required');
93
+ return { displayName, externalId: textOf(group.externalId, 'externalId', 255), members: membersOf(group.members) };
94
+ }
95
+ function membersOf(value) {
96
+ if (value === null || value === undefined)
97
+ return [];
98
+ if (!Array.isArray(value))
99
+ throw invalid('members must be a list');
100
+ const ids = [];
101
+ for (const entry of value) {
102
+ const id = typeof entry === 'object' && entry !== null ? entry.value : undefined;
103
+ if (typeof id !== 'string' || id.length === 0 || id.length > 64)
104
+ throw invalid('Each member is {"value": "<user id>"}');
105
+ ids.push(id);
106
+ }
107
+ return [...new Set(ids)];
108
+ }
109
+ /** A PATCH body's operations, normalised (see the top of this file). */
110
+ export function slotlockScimPatchOperations(body) {
111
+ if (typeof body !== 'object' || body === null)
112
+ throw new SlotlockScimError(400, 'invalidSyntax', 'A patch is a JSON object');
113
+ const patch = body;
114
+ const schemas = Array.isArray(patch.schemas) ? patch.schemas : [];
115
+ if (!schemas.includes(SCIM_PATCH_SCHEMA))
116
+ throw new SlotlockScimError(400, 'invalidSyntax', `A patch names the schema ${SCIM_PATCH_SCHEMA}`);
117
+ const operations = patch.Operations ?? patch.operations;
118
+ if (!Array.isArray(operations) || operations.length === 0 || operations.length > 100) {
119
+ throw new SlotlockScimError(400, 'invalidSyntax', 'A patch has 1 to 100 Operations');
120
+ }
121
+ return operations.map((operation) => {
122
+ if (typeof operation !== 'object' || operation === null)
123
+ throw new SlotlockScimError(400, 'invalidSyntax', 'Each operation is an object');
124
+ const { op, path, value } = operation;
125
+ const name = typeof op === 'string' ? op.toLowerCase() : '';
126
+ if (name !== 'add' && name !== 'replace' && name !== 'remove')
127
+ throw new SlotlockScimError(400, 'invalidSyntax', 'op is add, replace or remove');
128
+ if (path !== undefined && path !== null && (typeof path !== 'string' || path.length > 200))
129
+ throw new SlotlockScimError(400, 'invalidPath', 'path is text');
130
+ const target = typeof path === 'string' && path.trim() !== '' ? path.trim() : null;
131
+ if (name === 'remove' && target === null)
132
+ throw new SlotlockScimError(400, 'noTarget', 'A remove names its path');
133
+ return { op: name, path: target, value };
134
+ });
135
+ }
136
+ /** A path without the core schema's URN prefix, in lowercase; null for an extension's (ignored). */
137
+ function corePath(path, schema) {
138
+ const lower = path.toLowerCase();
139
+ const prefix = `${schema.toLowerCase()}:`;
140
+ if (lower.startsWith(prefix))
141
+ return lower.slice(prefix.length);
142
+ if (lower.startsWith('urn:'))
143
+ return null;
144
+ return lower;
145
+ }
146
+ /** Each attribute a path-less add or replace sets: its keys as paths (dotted or URN-qualified). */
147
+ function expand(operation) {
148
+ if (operation.path !== null)
149
+ return [operation];
150
+ if (typeof operation.value !== 'object' || operation.value === null || Array.isArray(operation.value)) {
151
+ throw invalid('An add or replace without a path holds an object of attributes');
152
+ }
153
+ return Object.entries(operation.value).map(([key, value]) => ({ op: operation.op, path: key, value }));
154
+ }
155
+ /** A user changed by a patch, all of it or none (RFC 7644 §3.5.2: a patch is atomic). */
156
+ export function slotlockScimPatchUser(current, id, operations) {
157
+ const next = { ...current };
158
+ for (const operation of operations.flatMap(expand)) {
159
+ const path = corePath(operation.path, SCIM_USER_SCHEMA);
160
+ if (path === null || path === 'schemas' || path === 'meta')
161
+ continue;
162
+ const removing = operation.op === 'remove';
163
+ const value = removing ? null : operation.value;
164
+ switch (path) {
165
+ case 'id':
166
+ if (value !== id)
167
+ throw new SlotlockScimError(400, 'mutability', 'id is read-only');
168
+ break;
169
+ case 'active':
170
+ if (removing)
171
+ throw invalid('active cannot be removed');
172
+ next.active = slotlockScimBoolean(value);
173
+ break;
174
+ case 'username': {
175
+ const userName = textOf(value, 'userName');
176
+ if (userName === null)
177
+ throw invalid('userName is required');
178
+ next.userName = userName;
179
+ break;
180
+ }
181
+ case 'externalid':
182
+ next.externalId = textOf(value, 'externalId', 255);
183
+ break;
184
+ case 'displayname':
185
+ next.displayName = textOf(value, 'displayName', 200);
186
+ break;
187
+ case 'name.givenname':
188
+ next.givenName = textOf(value, 'name.givenName', 100);
189
+ break;
190
+ case 'name.familyname':
191
+ next.familyName = textOf(value, 'name.familyName', 100);
192
+ break;
193
+ case 'name': {
194
+ const name = typeof value === 'object' && value !== null ? value : {};
195
+ next.givenName = removing ? null : textOf(name.givenName, 'name.givenName', 100);
196
+ next.familyName = removing ? null : textOf(name.familyName, 'name.familyName', 100);
197
+ break;
198
+ }
199
+ case 'emails':
200
+ next.workEmail = removing ? null : workEmailOf(value);
201
+ break;
202
+ case 'emails[type eq "work"].value':
203
+ case 'emails[type eq "work"]': {
204
+ const address = path.endsWith('.value') ? textOf(value, 'An email') : workEmailOf(value === null ? null : [value]);
205
+ next.workEmail = address === null ? null : address.toLowerCase();
206
+ break;
207
+ }
208
+ default:
209
+ // Kept nowhere in Slotlock (title, phone numbers, addresses, locale, …): ignored.
210
+ break;
211
+ }
212
+ }
213
+ return next;
214
+ }
215
+ /** A group changed by a patch, all of it or none. */
216
+ export function slotlockScimPatchGroup(current, id, operations) {
217
+ const next = { ...current, members: [...current.members] };
218
+ for (const operation of operations.flatMap(expand)) {
219
+ const raw = operation.path;
220
+ const path = corePath(raw, SCIM_GROUP_SCHEMA);
221
+ if (path === null || path === 'schemas' || path === 'meta')
222
+ continue;
223
+ const member = /^members\[value eq "([^"\\]{1,64})"\]$/.exec(path)?.[1];
224
+ if (member !== undefined) {
225
+ if (operation.op !== 'remove')
226
+ throw new SlotlockScimError(400, 'invalidPath', 'A member filter only removes');
227
+ // The id as sent (ids are case-sensitive); the path was lowercased to match its shape only.
228
+ const sent = /\[value eq "([^"\\]{1,64})"\]/i.exec(raw)?.[1] ?? member;
229
+ next.members = next.members.filter((existing) => existing !== sent);
230
+ continue;
231
+ }
232
+ switch (path) {
233
+ case 'id':
234
+ if (operation.value !== id)
235
+ throw new SlotlockScimError(400, 'mutability', 'id is read-only');
236
+ break;
237
+ case 'displayname': {
238
+ if (operation.op === 'remove')
239
+ throw invalid('displayName cannot be removed');
240
+ const displayName = textOf(operation.value, 'displayName', 200);
241
+ if (displayName === null)
242
+ throw invalid('displayName is required');
243
+ next.displayName = displayName;
244
+ break;
245
+ }
246
+ case 'externalid':
247
+ next.externalId = operation.op === 'remove' ? null : textOf(operation.value, 'externalId', 255);
248
+ break;
249
+ case 'members': {
250
+ if (operation.op === 'replace') {
251
+ next.members = membersOf(operation.value);
252
+ }
253
+ else if (operation.op === 'add') {
254
+ next.members = [...new Set([...next.members, ...membersOf(operation.value)])];
255
+ }
256
+ else if (operation.value === undefined || operation.value === null) {
257
+ // RFC 7644: a remove of the whole attribute.
258
+ next.members = [];
259
+ }
260
+ else {
261
+ // Entra without the flag: the members named, not the list.
262
+ const removed = new Set(membersOf(operation.value));
263
+ next.members = next.members.filter((existing) => !removed.has(existing));
264
+ }
265
+ break;
266
+ }
267
+ default:
268
+ break;
269
+ }
270
+ }
271
+ return next;
272
+ }
273
+ /**
274
+ * A filter (RFC 7644 §3.4.2.2) as Okta and Entra send it: `eq` comparisons of the allowed
275
+ * attributes, joined by `and`. Anything else is 400 invalidFilter.
276
+ */
277
+ export function slotlockScimFilter(filter, allowed) {
278
+ if (filter.length > 500)
279
+ throw new SlotlockScimError(400, 'invalidFilter', 'The filter is too long');
280
+ const comparisons = [];
281
+ let rest = filter.trim();
282
+ const comparison = /^([A-Za-z][A-Za-z0-9._:-]*(?:\[[A-Za-z]+ eq "[A-Za-z]+"\]\.[A-Za-z]+)?)\s+eq\s+"((?:[^"\\]|\\.){0,254})"/i;
283
+ for (;;) {
284
+ const match = comparison.exec(rest);
285
+ if (!match)
286
+ throw new SlotlockScimError(400, 'invalidFilter', 'Slotlock filters by eq, joined by and');
287
+ const attribute = corePath(match[1], SCIM_USER_SCHEMA) ?? '';
288
+ if (!allowed.includes(attribute))
289
+ throw new SlotlockScimError(400, 'invalidFilter', `Slotlock does not filter by ${match[1]}`);
290
+ let value;
291
+ try {
292
+ value = JSON.parse(`"${match[2]}"`);
293
+ }
294
+ catch {
295
+ throw new SlotlockScimError(400, 'invalidFilter', 'The filter value is not a valid string');
296
+ }
297
+ if (/\p{Cc}/u.test(value))
298
+ throw new SlotlockScimError(400, 'invalidFilter', 'The filter value holds a control character');
299
+ comparisons.push({ attribute, value });
300
+ rest = rest.slice(match[0].length).trim();
301
+ if (rest === '')
302
+ return comparisons;
303
+ const and = /^and\s+/i.exec(rest);
304
+ if (!and || comparisons.length >= 5)
305
+ throw new SlotlockScimError(400, 'invalidFilter', 'Slotlock filters by eq, joined by and');
306
+ rest = rest.slice(and[0].length);
307
+ }
308
+ }
309
+ /** A user as SCIM answers it: every attribute Slotlock keeps, so a GET then PUT loses nothing. */
310
+ export function slotlockScimUserResource(id, user, meta) {
311
+ return {
312
+ schemas: [SCIM_USER_SCHEMA],
313
+ id,
314
+ ...(user.externalId !== null ? { externalId: user.externalId } : {}),
315
+ userName: user.userName,
316
+ active: user.active,
317
+ ...(user.givenName !== null || user.familyName !== null
318
+ ? { name: { ...(user.givenName !== null ? { givenName: user.givenName } : {}), ...(user.familyName !== null ? { familyName: user.familyName } : {}) } }
319
+ : {}),
320
+ ...(user.displayName !== null ? { displayName: user.displayName } : {}),
321
+ ...(user.workEmail !== null ? { emails: [{ value: user.workEmail, type: 'work', primary: true }] } : {}),
322
+ meta: { resourceType: 'User', created: meta.created.toISOString(), lastModified: meta.lastModified.toISOString(), location: meta.location },
323
+ };
324
+ }
325
+ /** A group as SCIM answers it, with its members unless asked not to. */
326
+ export function slotlockScimGroupResource(id, group, meta, withMembers = true) {
327
+ return {
328
+ schemas: [SCIM_GROUP_SCHEMA],
329
+ id,
330
+ displayName: group.displayName,
331
+ ...(group.externalId !== null ? { externalId: group.externalId } : {}),
332
+ ...(withMembers ? { members: group.members.map((member) => ({ value: member })) } : {}),
333
+ meta: { resourceType: 'Group', created: meta.created.toISOString(), lastModified: meta.lastModified.toISOString(), location: meta.location },
334
+ };
335
+ }
336
+ /** A list response; an empty one too (Entra needs it), with integer counts. */
337
+ export function slotlockScimList(resources, totalResults, startIndex) {
338
+ return { schemas: [SCIM_LIST_SCHEMA], totalResults, startIndex, itemsPerPage: resources.length, Resources: resources };
339
+ }
340
+ /** startIndex and count as a page: startIndex below 1 read as 1, count clamped to 0–100. */
341
+ export function slotlockScimPage(query) {
342
+ const start = Number.parseInt(query.get('startIndex') ?? '1', 10);
343
+ const count = Number.parseInt(query.get('count') ?? String(SLOTLOCK_SCIM_MAX_RESULTS), 10);
344
+ return {
345
+ // Within PostgreSQL's integer: past the end answers an empty page, never an error.
346
+ startIndex: Number.isFinite(start) && start >= 1 ? Math.min(start, 2_000_000_000) : 1,
347
+ count: Number.isFinite(count) ? Math.min(Math.max(count, 0), SLOTLOCK_SCIM_MAX_RESULTS) : SLOTLOCK_SCIM_MAX_RESULTS,
348
+ };
349
+ }
350
+ /** What Slotlock supports (RFC 7643 §5): PATCH, filters up to 100 results; no bulk, sort or ETags. */
351
+ export function slotlockScimServiceProviderConfig(documentationUri) {
352
+ return {
353
+ schemas: ['urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig'],
354
+ documentationUri,
355
+ patch: { supported: true },
356
+ bulk: { supported: false, maxOperations: 0, maxPayloadSize: 0 },
357
+ filter: { supported: true, maxResults: SLOTLOCK_SCIM_MAX_RESULTS },
358
+ changePassword: { supported: false },
359
+ sort: { supported: false },
360
+ etag: { supported: false },
361
+ authenticationSchemes: [
362
+ { type: 'oauthbearertoken', name: 'Bearer token', description: 'The SCIM token from the team’s Identity settings', primary: true },
363
+ ],
364
+ meta: { resourceType: 'ServiceProviderConfig' },
365
+ };
366
+ }
367
+ /** The resource types Slotlock serves, as a list. */
368
+ export function slotlockScimResourceTypes(base) {
369
+ const types = [
370
+ { schemas: ['urn:ietf:params:scim:schemas:core:2.0:ResourceType'], id: 'User', name: 'User', endpoint: '/Users', schema: SCIM_USER_SCHEMA, meta: { resourceType: 'ResourceType', location: `${base}/ResourceTypes/User` } },
371
+ { schemas: ['urn:ietf:params:scim:schemas:core:2.0:ResourceType'], id: 'Group', name: 'Group', endpoint: '/Groups', schema: SCIM_GROUP_SCHEMA, meta: { resourceType: 'ResourceType', location: `${base}/ResourceTypes/Group` } },
372
+ ];
373
+ return slotlockScimList(types, types.length, 1);
374
+ }
375
+ const attribute = (name, type, extra = {}) => ({
376
+ name,
377
+ type,
378
+ multiValued: false,
379
+ required: false,
380
+ caseExact: false,
381
+ mutability: 'readWrite',
382
+ returned: 'default',
383
+ uniqueness: 'none',
384
+ ...extra,
385
+ });
386
+ /** The schemas of what Slotlock keeps, as a list. */
387
+ export function slotlockScimSchemas(base) {
388
+ const schemas = [
389
+ {
390
+ schemas: ['urn:ietf:params:scim:schemas:core:2.0:Schema'],
391
+ id: SCIM_USER_SCHEMA,
392
+ name: 'User',
393
+ attributes: [
394
+ attribute('userName', 'string', { required: true, uniqueness: 'server' }),
395
+ attribute('externalId', 'string', { caseExact: true }),
396
+ attribute('active', 'boolean'),
397
+ attribute('displayName', 'string'),
398
+ attribute('name', 'complex', { subAttributes: [attribute('givenName', 'string'), attribute('familyName', 'string')] }),
399
+ attribute('emails', 'complex', { multiValued: true, subAttributes: [attribute('value', 'string'), attribute('type', 'string'), attribute('primary', 'boolean')] }),
400
+ ],
401
+ meta: { resourceType: 'Schema', location: `${base}/Schemas/${SCIM_USER_SCHEMA}` },
402
+ },
403
+ {
404
+ schemas: ['urn:ietf:params:scim:schemas:core:2.0:Schema'],
405
+ id: SCIM_GROUP_SCHEMA,
406
+ name: 'Group',
407
+ attributes: [
408
+ attribute('displayName', 'string', { required: true, uniqueness: 'server' }),
409
+ attribute('externalId', 'string', { caseExact: true }),
410
+ attribute('members', 'complex', { multiValued: true, subAttributes: [attribute('value', 'string', { mutability: 'immutable' })] }),
411
+ ],
412
+ meta: { resourceType: 'Schema', location: `${base}/Schemas/${SCIM_GROUP_SCHEMA}` },
413
+ },
414
+ ];
415
+ return slotlockScimList(schemas, schemas.length, 1);
416
+ }