@voltro/plugin-scim 0.84.0 → 0.86.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.js CHANGED
@@ -1,474 +1,81 @@
1
- import { Effect as e } from "effect";
2
- import { definePlugin as t, pluginInstanceName as n, tsMs as r } from "@voltro/protocol";
3
- import { checkBearer as i } from "@voltro/protocol/session";
4
- import { boolean as a, eq as o, generateId as s, id as c, json as l, queryFor as u, table as d, text as f, timestamp as p } from "@voltro/database";
5
- //#region src/scim.ts
6
- var m = "urn:ietf:params:scim:schemas:core:2.0:User", h = "urn:ietf:params:scim:schemas:core:2.0:Group", g = "urn:ietf:params:scim:api:messages:2.0:ListResponse", _ = "urn:ietf:params:scim:api:messages:2.0:Error", v = (e) => new Date(e).toISOString(), y = (e, t) => {
7
- if (typeof e == "boolean") return e;
8
- if (typeof e == "number") return Number.isFinite(e) && e !== 0;
9
- if (typeof e == "string") {
10
- let t = e.trim().toLowerCase();
11
- if (t === "true" || t === "1") return !0;
12
- if (t === "false" || t === "0" || t === "") return !1;
13
- }
14
- return t;
15
- }, b = (e) => {
16
- let t = (e ?? "").trim();
17
- return (t.toLowerCase().startsWith("urn:") ? t.slice(t.lastIndexOf(":") + 1) : t).toLowerCase();
18
- }, x = (e, t) => ({
19
- schemas: [m],
20
- id: e.id,
21
- ...e.externalId ? { externalId: e.externalId } : {},
22
- userName: e.userName,
23
- name: {
24
- givenName: e.givenName ?? "",
25
- familyName: e.familyName ?? ""
26
- },
27
- ...e.email ? { emails: [{
28
- value: e.email,
29
- primary: !0
30
- }] } : {},
31
- active: e.active,
32
- meta: {
33
- resourceType: "User",
34
- created: v(e.createdAt),
35
- lastModified: v(e.updatedAt),
36
- location: `${t}/${e.id}`
37
- }
38
- }), S = (e) => {
39
- let t = e.name ?? {}, n = e.emails ?? [], r = n.find((e) => e.primary)?.value ?? n[0]?.value ?? null;
40
- return {
41
- userName: String(e.userName ?? ""),
42
- givenName: t.givenName ?? null,
43
- familyName: t.familyName ?? null,
44
- email: r,
45
- active: e.active === void 0 || e.active === null || y(e.active, !1),
46
- externalId: e.externalId ?? null
47
- };
48
- }, C = (e, t) => {
49
- let n = t.Operations ?? t.operations ?? [], r = { ...e };
50
- for (let e of n) {
51
- let t = (e.op ?? "").toLowerCase();
52
- if (t !== "replace" && t !== "add") continue;
53
- let n = b(e.path);
54
- if (n === "active") r = {
55
- ...r,
56
- active: y(e.value, !1)
57
- };
58
- else if (n === "username") r = {
59
- ...r,
60
- userName: String(e.value)
61
- };
62
- else if (n === "" && e.value && typeof e.value == "object") for (let [t, n] of Object.entries(e.value)) {
63
- let e = t.toLowerCase();
64
- e === "active" ? r = {
65
- ...r,
66
- active: y(n, !1)
67
- } : e === "username" && (r = {
68
- ...r,
69
- userName: String(n)
70
- });
71
- }
72
- }
73
- return r;
74
- }, w = (e, t) => ({
75
- schemas: [g],
76
- totalResults: t?.totalResults ?? e.length,
77
- startIndex: t?.startIndex ?? 1,
78
- itemsPerPage: e.length,
79
- Resources: e
80
- }), T = (e, t, n) => ({
81
- schemas: [_],
82
- status: String(e),
83
- ...n ? { scimType: n } : {},
84
- detail: t
85
- }), E = (e, t) => {
86
- if (!e) return { kind: "none" };
87
- let n = /^\s*([A-Za-z][A-Za-z0-9]*)\s+eq\s+"([^"]*)"\s*$/i.exec(e);
88
- if (!n) return { kind: "invalid" };
89
- let r = t.find((e) => e.toLowerCase() === n[1].toLowerCase());
90
- return r === void 0 ? { kind: "invalid" } : {
91
- kind: "filter",
92
- attribute: r,
93
- value: n[2]
94
- };
95
- }, D = (e) => {
96
- let t = Number(e.get("startIndex")), n = Number(e.get("count"));
97
- return {
98
- startIndex: Number.isInteger(t) && t >= 1 ? t : 1,
99
- count: e.get("count") !== null && Number.isInteger(n) && n >= 0 ? n : null
100
- };
101
- }, O = (e, t) => {
102
- let n = t.Operations ?? t.operations ?? [], r = (e) => (Array.isArray(e) ? e : e === void 0 ? [] : [e]).map((e) => String(e?.value ?? e)).filter((e) => e !== "" && e !== "undefined"), i = e;
103
- for (let e of n) {
104
- let t = (e.op ?? "").toLowerCase(), n = e.path ?? "", a = /^members\[value\s+eq\s+"([^"]*)"\]$/i.exec(n);
105
- if (t === "add" && n.toLowerCase() === "members") {
106
- let t = r(e.value).filter((e) => !i.members.includes(e));
107
- i = {
108
- ...i,
109
- members: [...i.members, ...t]
110
- };
111
- } else if (t === "remove" && a) i = {
112
- ...i,
113
- members: i.members.filter((e) => e !== a[1])
114
- };
115
- else if (t === "remove" && n.toLowerCase() === "members") {
116
- let t = new Set(r(e.value));
117
- i = {
118
- ...i,
119
- members: t.size === 0 ? [] : i.members.filter((e) => !t.has(e))
120
- };
121
- } else if (t === "replace" && n.toLowerCase() === "members") i = {
122
- ...i,
123
- members: [...r(e.value)]
124
- };
125
- else if (t === "replace" && n === "displayName") i = {
126
- ...i,
127
- displayName: String(e.value)
128
- };
129
- else if (t === "replace" && n === "" && e.value && typeof e.value == "object") {
130
- let t = e.value;
131
- "displayName" in t && (i = {
132
- ...i,
133
- displayName: String(t.displayName)
134
- }), "members" in t && (i = {
135
- ...i,
136
- members: [...r(t.members)]
137
- });
138
- }
139
- }
140
- return i;
141
- }, k = (e) => ({
142
- schemas: ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
143
- documentationUri: "https://voltro.dev",
144
- patch: { supported: !0 },
145
- bulk: {
146
- supported: !1,
147
- maxOperations: 0,
148
- maxPayloadSize: 0
149
- },
150
- filter: {
151
- supported: !0,
152
- maxResults: 200
153
- },
154
- changePassword: { supported: !1 },
155
- sort: { supported: !1 },
156
- etag: { supported: !1 },
157
- authenticationSchemes: [{
158
- type: "oauthbearertoken",
159
- name: "Bearer token",
160
- description: "Static bearer token configured in the IdP SCIM settings"
161
- }],
162
- meta: {
163
- resourceType: "ServiceProviderConfig",
164
- location: e
165
- }
166
- }), A = (e, t = {}) => ({
167
- name: e,
168
- type: "string",
169
- multiValued: !1,
170
- required: !1,
171
- caseExact: !1,
172
- mutability: "readWrite",
173
- returned: "default",
174
- uniqueness: "none",
175
- ...t
176
- }), j = (e) => [{
177
- schemas: ["urn:ietf:params:scim:schemas:core:2.0:Schema"],
178
- id: m,
179
- name: "User",
180
- description: "SCIM core User",
181
- attributes: [
182
- A("userName", {
183
- required: !0,
184
- uniqueness: "server"
185
- }),
186
- A("name", {
187
- type: "complex",
188
- subAttributes: [A("givenName"), A("familyName")]
189
- }),
190
- A("emails", {
191
- type: "complex",
192
- multiValued: !0,
193
- subAttributes: [A("value"), A("primary", { type: "boolean" })]
194
- }),
195
- A("active", { type: "boolean" }),
196
- A("externalId")
197
- ],
198
- meta: {
199
- resourceType: "Schema",
200
- location: `${e}/${m}`
201
- }
202
- }, {
203
- schemas: ["urn:ietf:params:scim:schemas:core:2.0:Schema"],
204
- id: h,
205
- name: "Group",
206
- description: "SCIM core Group",
207
- attributes: [
208
- A("displayName", { required: !0 }),
209
- A("members", {
210
- type: "complex",
211
- multiValued: !0,
212
- subAttributes: [A("value")]
213
- }),
214
- A("externalId")
215
- ],
216
- meta: {
217
- resourceType: "Schema",
218
- location: `${e}/${h}`
219
- }
220
- }], M = (e) => [{
221
- schemas: ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"],
222
- id: "User",
223
- name: "User",
224
- endpoint: "/Users",
225
- schema: m,
226
- meta: {
227
- resourceType: "ResourceType",
228
- location: `${e}/ResourceTypes/User`
229
- }
230
- }, {
231
- schemas: ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"],
232
- id: "Group",
233
- name: "Group",
234
- endpoint: "/Groups",
235
- schema: h,
236
- meta: {
237
- resourceType: "ResourceType",
238
- location: `${e}/ResourceTypes/Group`
239
- }
240
- }], N = d("_voltro_scim_users", {
241
- id: c({ prefix: "scimuser" }),
242
- userName: f(),
243
- givenName: f().nullable(),
244
- familyName: f().nullable(),
245
- email: f().nullable(),
246
- active: a().default(!0),
247
- externalId: f().nullable(),
248
- createdAt: p().default("now"),
249
- updatedAt: p().default("now").onUpdate("now")
250
- }).renamedFrom("scim_users").unique("byScimUserName", ["userName"]), P = d("_voltro_scim_groups", {
251
- id: c({ prefix: "scimgroup" }),
252
- displayName: f(),
253
- externalId: f().nullable(),
254
- members: l().nullable(),
255
- createdAt: p().default("now"),
256
- updatedAt: p().default("now").onUpdate("now")
257
- }).renamedFrom("scim_groups"), F = (e, t) => t === null || e[t.attribute] === t.value, I = (e = Date.now) => {
258
- let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = 0, i = (e) => `${e}_${++r}`;
259
- return {
260
- listUsers: async (e) => [...t.values()].filter((t) => F(t, e)),
261
- getUser: async (e) => t.get(e) ?? null,
262
- createUser: async (n) => {
263
- let r = {
264
- ...n,
265
- id: i("user"),
266
- createdAt: e(),
267
- updatedAt: e()
268
- };
269
- return t.set(r.id, r), r;
270
- },
271
- putUser: async (n, r) => {
272
- if (!t.has(n)) return null;
273
- let i = {
274
- ...r,
275
- id: n,
276
- updatedAt: e()
277
- };
278
- return t.set(n, i), i;
279
- },
280
- deleteUser: async (e) => t.delete(e),
281
- listGroups: async (e) => [...n.values()].filter((t) => F(t, e)),
282
- getGroup: async (e) => n.get(e) ?? null,
283
- createGroup: async (t) => {
284
- let r = {
285
- ...t,
286
- id: i("group"),
287
- createdAt: e(),
288
- updatedAt: e()
289
- };
290
- return n.set(r.id, r), r;
291
- },
292
- putGroup: async (t, r) => {
293
- if (!n.has(t)) return null;
294
- let i = {
295
- ...r,
296
- id: t,
297
- updatedAt: e()
298
- };
299
- return n.set(t, i), i;
300
- },
301
- deleteGroup: async (e) => n.delete(e)
302
- };
303
- }, L = (e) => {
304
- let t = async (t, n) => {
305
- let r = u(t);
306
- return e.query((n ? r.where(n) : r).descriptor);
307
- }, n = (e) => ({
308
- id: String(e.id),
309
- userName: String(e.userName),
310
- givenName: e.givenName ?? null,
311
- familyName: e.familyName ?? null,
312
- email: e.email ?? null,
313
- active: !!e.active,
314
- externalId: e.externalId ?? null,
315
- createdAt: r(e.createdAt),
316
- updatedAt: r(e.updatedAt)
317
- }), i = (e) => ({
318
- id: String(e.id),
319
- displayName: String(e.displayName),
320
- externalId: e.externalId ?? null,
321
- members: e.members ?? [],
322
- createdAt: r(e.createdAt),
323
- updatedAt: r(e.updatedAt)
324
- });
325
- return {
326
- listUsers: async (e) => (await t(N, e ? o(e.attribute, e.value) : void 0)).map(n),
327
- getUser: async (e) => {
328
- let r = await t(N, o("id", e));
329
- return r[0] ? n(r[0]) : null;
330
- },
331
- createUser: async (t) => {
332
- let n = s({
333
- kind: "typeid",
334
- prefix: "scimuser"
335
- }, "_voltro_scim_users"), r = /* @__PURE__ */ new Date(), i = {
336
- id: n,
337
- ...t,
338
- createdAt: r,
339
- updatedAt: r
340
- };
341
- return await e.insert("_voltro_scim_users", i), {
342
- ...t,
343
- id: n,
344
- createdAt: r.getTime(),
345
- updatedAt: r.getTime()
346
- };
347
- },
348
- putUser: async (n, r) => (await t(N, o("id", n)))[0] ? (await e.update("_voltro_scim_users", n, {
349
- userName: r.userName,
350
- givenName: r.givenName,
351
- familyName: r.familyName,
352
- email: r.email,
353
- active: r.active,
354
- externalId: r.externalId,
355
- updatedAt: /* @__PURE__ */ new Date()
356
- }), {
357
- ...r,
358
- id: n,
359
- updatedAt: Date.now()
360
- }) : null,
361
- deleteUser: async (n) => (await t(N, o("id", n)))[0] ? (await e.delete("_voltro_scim_users", n), !0) : !1,
362
- listGroups: async (e) => (await t(P, e ? o(e.attribute, e.value) : void 0)).map(i),
363
- getGroup: async (e) => {
364
- let n = await t(P, o("id", e));
365
- return n[0] ? i(n[0]) : null;
366
- },
367
- createGroup: async (t) => {
368
- let n = s({
369
- kind: "typeid",
370
- prefix: "scimgroup"
371
- }, "_voltro_scim_groups"), r = /* @__PURE__ */ new Date(), i = {
372
- id: n,
373
- ...t,
374
- createdAt: r,
375
- updatedAt: r
376
- };
377
- return await e.insert("_voltro_scim_groups", i), {
378
- ...t,
379
- id: n,
380
- createdAt: r.getTime(),
381
- updatedAt: r.getTime()
382
- };
383
- },
384
- putGroup: async (n, r) => (await t(P, o("id", n)))[0] ? (await e.update("_voltro_scim_groups", n, {
385
- displayName: r.displayName,
386
- externalId: r.externalId,
387
- members: r.members,
388
- updatedAt: /* @__PURE__ */ new Date()
389
- }), {
390
- ...r,
391
- id: n,
392
- updatedAt: Date.now()
393
- }) : null,
394
- deleteGroup: async (n) => (await t(P, o("id", n)))[0] ? (await e.delete("_voltro_scim_groups", n), !0) : !1
395
- };
396
- }, R = (e, t) => ({
1
+ import { SCIM_ERROR_SCHEMA as e, SCIM_GROUP_SCHEMA as t, SCIM_LIST_SCHEMA as n, SCIM_USER_SCHEMA as r, applyScimGroupPatch as i, applyScimPatch as a, fromScimUser as o, parsePagination as s, parseScimFilter as c, resourceTypes as l, scimError as u, scimList as d, scimSchemas as f, serviceProviderConfig as p, toScimUser as m } from "./scim.js";
2
+ import { dataStoreScimStore as h, memoryScimStore as g, scimGroupsTable as _, scimUsersTable as v } from "./store.js";
3
+ import { Effect as y } from "effect";
4
+ import { definePlugin as b, pluginInstanceName as x } from "@voltro/protocol";
5
+ import { checkBearer as S } from "@voltro/protocol/session";
6
+ //#region src/index.ts
7
+ var C = (e, t) => ({
397
8
  status: e,
398
9
  body: JSON.stringify(t),
399
10
  contentType: "application/scim+json"
400
- }), z = (e) => {
11
+ }), w = (e) => {
401
12
  try {
402
13
  return JSON.parse(new TextDecoder().decode(e.rawBody) || "{}");
403
14
  } catch {
404
15
  return {};
405
16
  }
406
- }, B = (e, t) => {
407
- let { startIndex: n, count: r } = D(t), i = n - 1;
408
- return {
409
- page: e.slice(i, r === null ? void 0 : i + r),
410
- total: e.length,
411
- startIndex: n
412
- };
413
- }, V = () => R(400, T(400, "unsupported filter — only `<attribute> eq \"value\"` on the indexed attributes", "invalidFilter")), H = async (e, t, n) => (await e.listUsers({
17
+ }, T = () => C(400, u(400, "unsupported filter — only `<attribute> eq \"value\"` on the indexed attributes", "invalidFilter")), E = async (e, t, n) => (await e.listUsers({
414
18
  attribute: "userName",
415
19
  value: t
416
- })).some((e) => e.id !== n), U = (e) => R(409, T(409, `a user with userName '${e}' already exists`, "uniqueness")), W = async (e, t, n, r) => {
417
- if (!i(r.headers, t)) return R(401, T(401, "invalid or missing bearer token"));
418
- let [, a, o] = r.path.slice(n.length).replace(/\/+$/, "").split("/"), s = r.method.toUpperCase(), c = new URLSearchParams(r.query), l = `${n}/Users`;
419
- if (s === "GET" && !o) {
420
- if (a === "ServiceProviderConfig") return R(200, k(`${n}/ServiceProviderConfig`));
421
- if (a === "Schemas") return R(200, w(j(`${n}/Schemas`)));
422
- if (a === "ResourceTypes") return R(200, w(M(n)));
20
+ })).some((e) => e.id !== n), D = (e) => C(409, u(409, `a user with userName '${e}' already exists`, "uniqueness")), O = async (e, t, n, r) => {
21
+ if (!S(r.headers, t)) return C(401, u(401, "invalid or missing bearer token"));
22
+ let [, h, g] = r.path.slice(n.length).replace(/\/+$/, "").split("/"), _ = r.method.toUpperCase(), v = new URLSearchParams(r.query), y = `${n}/Users`;
23
+ if (_ === "GET" && !g) {
24
+ if (h === "ServiceProviderConfig") return C(200, p(`${n}/ServiceProviderConfig`));
25
+ if (h === "Schemas") return C(200, d(f(`${n}/Schemas`)));
26
+ if (h === "ResourceTypes") return C(200, d(l(n)));
423
27
  }
424
- if (a === "Users") {
425
- if (s === "GET" && !o) {
426
- let t = E(c.get("filter"), ["userName", "externalId"]);
427
- if (t.kind === "invalid") return V();
428
- let { page: n, total: r, startIndex: i } = B(await e.listUsers(t.kind === "filter" ? t : null), c);
429
- return R(200, w(n.map((e) => x(e, l)), {
430
- totalResults: r,
431
- startIndex: i
28
+ if (h === "Users") {
29
+ if (_ === "GET" && !g) {
30
+ let t = c(v.get("filter"), ["userName", "externalId"]);
31
+ if (t.kind === "invalid") return T();
32
+ let { startIndex: n, count: r } = s(v), i = await e.pageUsers(t.kind === "filter" ? t : null, {
33
+ startIndex: n,
34
+ count: Math.min(r ?? 100, 1e3)
35
+ });
36
+ return C(200, d(i.rows.map((e) => m(e, y)), {
37
+ totalResults: i.totalResults,
38
+ startIndex: n
432
39
  }));
433
40
  }
434
- if (s === "GET" && o) {
435
- let t = await e.getUser(o);
436
- return t ? R(200, x(t, l)) : R(404, T(404, "user not found"));
41
+ if (_ === "GET" && g) {
42
+ let t = await e.getUser(g);
43
+ return t ? C(200, m(t, y)) : C(404, u(404, "user not found"));
437
44
  }
438
- if (s === "POST" && !o) {
439
- let t = S(z(r));
440
- if (t.userName === "") return R(400, T(400, "userName is required", "invalidValue"));
441
- if (await H(e, t.userName)) return U(t.userName);
45
+ if (_ === "POST" && !g) {
46
+ let t = o(w(r));
47
+ if (t.userName === "") return C(400, u(400, "userName is required", "invalidValue"));
48
+ if (await E(e, t.userName)) return D(t.userName);
442
49
  try {
443
- return R(201, x(await e.createUser(t), l));
50
+ return C(201, m(await e.createUser(t), y));
444
51
  } catch (n) {
445
- if (await H(e, t.userName)) return U(t.userName);
52
+ if (await E(e, t.userName)) return D(t.userName);
446
53
  throw n;
447
54
  }
448
55
  }
449
- if (s === "PUT" && o) {
450
- let t = await e.getUser(o);
451
- if (!t) return R(404, T(404, "user not found"));
56
+ if (_ === "PUT" && g) {
57
+ let t = await e.getUser(g);
58
+ if (!t) return C(404, u(404, "user not found"));
452
59
  let n = {
453
60
  ...t,
454
- ...S(z(r))
61
+ ...o(w(r))
455
62
  };
456
- if (await H(e, n.userName, o)) return U(n.userName);
457
- let i = await e.putUser(o, n);
458
- return i ? R(200, x(i, l)) : R(404, T(404, "user not found"));
63
+ if (await E(e, n.userName, g)) return D(n.userName);
64
+ let i = await e.putUser(g, n);
65
+ return i ? C(200, m(i, y)) : C(404, u(404, "user not found"));
459
66
  }
460
- if (s === "PATCH" && o) {
461
- let t = await e.getUser(o);
462
- if (!t) return R(404, T(404, "user not found"));
463
- let n = C(t, z(r));
464
- if (n.userName !== t.userName && await H(e, n.userName, o)) return U(n.userName);
465
- let i = await e.putUser(o, n);
466
- return i ? R(200, x(i, l)) : R(404, T(404, "user not found"));
67
+ if (_ === "PATCH" && g) {
68
+ let t = await e.getUser(g);
69
+ if (!t) return C(404, u(404, "user not found"));
70
+ let n = a(t, w(r));
71
+ if (n.userName !== t.userName && await E(e, n.userName, g)) return D(n.userName);
72
+ let i = await e.putUser(g, n);
73
+ return i ? C(200, m(i, y)) : C(404, u(404, "user not found"));
467
74
  }
468
- if (s === "DELETE" && o) return await e.deleteUser(o) ? { status: 204 } : R(404, T(404, "user not found"));
75
+ if (_ === "DELETE" && g) return await e.deleteUser(g) ? { status: 204 } : C(404, u(404, "user not found"));
469
76
  }
470
- if (a === "Groups") {
471
- let t = `${n}/Groups`, i = (e) => ({
77
+ if (h === "Groups") {
78
+ let t = `${n}/Groups`, a = (e) => ({
472
79
  schemas: ["urn:ietf:params:scim:schemas:core:2.0:Group"],
473
80
  id: e.id,
474
81
  displayName: e.displayName,
@@ -479,73 +86,76 @@ var m = "urn:ietf:params:scim:schemas:core:2.0:User", h = "urn:ietf:params:scim:
479
86
  location: `${t}/${e.id}`
480
87
  }
481
88
  });
482
- if (s === "GET" && !o) {
483
- let t = E(c.get("filter"), ["displayName", "externalId"]);
484
- if (t.kind === "invalid") return V();
485
- let { page: n, total: r, startIndex: a } = B(await e.listGroups(t.kind === "filter" ? t : null), c);
486
- return R(200, w(n.map(i), {
487
- totalResults: r,
488
- startIndex: a
89
+ if (_ === "GET" && !g) {
90
+ let t = c(v.get("filter"), ["displayName", "externalId"]);
91
+ if (t.kind === "invalid") return T();
92
+ let { startIndex: n, count: r } = s(v), i = await e.pageGroups(t.kind === "filter" ? t : null, {
93
+ startIndex: n,
94
+ count: Math.min(r ?? 100, 1e3)
95
+ });
96
+ return C(200, d(i.rows.map(a), {
97
+ totalResults: i.totalResults,
98
+ startIndex: n
489
99
  }));
490
100
  }
491
- if (s === "GET" && o) {
492
- let t = await e.getGroup(o);
493
- return t ? R(200, i(t)) : R(404, T(404, "group not found"));
101
+ if (_ === "GET" && g) {
102
+ let t = await e.getGroup(g);
103
+ return t ? C(200, a(t)) : C(404, u(404, "group not found"));
494
104
  }
495
- if (s === "POST" && !o) {
496
- let t = z(r), n = (t.members ?? []).map((e) => String(e.value)).filter(Boolean);
497
- return R(201, i(await e.createGroup({
105
+ if (_ === "POST" && !g) {
106
+ let t = w(r), n = (t.members ?? []).map((e) => String(e.value)).filter(Boolean);
107
+ return C(201, a(await e.createGroup({
498
108
  displayName: String(t.displayName ?? ""),
499
109
  externalId: t.externalId ?? null,
500
110
  members: n
501
111
  })));
502
112
  }
503
- if (s === "PUT" && o) {
504
- let t = await e.getGroup(o);
505
- if (!t) return R(404, T(404, "group not found"));
506
- let n = z(r), a = (n.members ?? []).map((e) => String(e.value)).filter(Boolean), s = await e.putGroup(o, {
113
+ if (_ === "PUT" && g) {
114
+ let t = await e.getGroup(g);
115
+ if (!t) return C(404, u(404, "group not found"));
116
+ let n = w(r), i = (n.members ?? []).map((e) => String(e.value)).filter(Boolean), o = await e.putGroup(g, {
507
117
  ...t,
508
118
  displayName: String(n.displayName ?? t.displayName),
509
119
  externalId: n.externalId ?? t.externalId,
510
- members: a
120
+ members: i
511
121
  });
512
- return s ? R(200, i(s)) : R(404, T(404, "group not found"));
122
+ return o ? C(200, a(o)) : C(404, u(404, "group not found"));
513
123
  }
514
- if (s === "PATCH" && o) {
515
- let t = await e.getGroup(o);
516
- if (!t) return R(404, T(404, "group not found"));
517
- let n = await e.putGroup(o, O(t, z(r)));
518
- return n ? R(200, i(n)) : R(404, T(404, "group not found"));
124
+ if (_ === "PATCH" && g) {
125
+ let t = await e.getGroup(g);
126
+ if (!t) return C(404, u(404, "group not found"));
127
+ let n = await e.putGroup(g, i(t, w(r)));
128
+ return n ? C(200, a(n)) : C(404, u(404, "group not found"));
519
129
  }
520
- if (s === "DELETE" && o) return await e.deleteGroup(o) ? { status: 204 } : R(404, T(404, "group not found"));
130
+ if (_ === "DELETE" && g) return await e.deleteGroup(g) ? { status: 204 } : C(404, u(404, "group not found"));
521
131
  }
522
- return R(404, T(404, "unsupported SCIM endpoint"));
523
- }, G = "@voltro/plugin-scim", K = (r) => {
524
- if (r.token.trim() === "") throw Error("scimPlugin({ token }) requires a non-empty bearer token — got an empty string. SCIM exposes the full user + group directory and can deactivate accounts, so it is never mounted ungated. Set the environment variable your IdP presents (e.g. SCIM_TOKEN) and pass it through, or remove scimPlugin() from the plugin list.");
525
- let i = r.basePath ?? "/scim/v2", a = n({
526
- base: G,
527
- alias: r.alias,
528
- instance: r.name
529
- }), o;
530
- return t({
531
- name: a,
532
- baseName: G,
132
+ return C(404, u(404, "unsupported SCIM endpoint"));
133
+ }, k = "@voltro/plugin-scim", A = (e) => {
134
+ if (e.token.trim() === "") throw Error("scimPlugin({ token }) requires a non-empty bearer token — got an empty string. SCIM exposes the full user + group directory and can deactivate accounts, so it is never mounted ungated. Set the environment variable your IdP presents (e.g. SCIM_TOKEN) and pass it through, or remove scimPlugin() from the plugin list.");
135
+ let t = e.basePath ?? "/scim/v2", n = x({
136
+ base: k,
137
+ alias: e.alias,
138
+ instance: e.name
139
+ }), r;
140
+ return b({
141
+ name: n,
142
+ baseName: k,
533
143
  description: "SCIM 2.0 Users + Groups provisioning endpoints.",
534
144
  permissions: ["store:write"],
535
- extendSchema: { tables: [N, P] },
145
+ extendSchema: { tables: [v, _] },
536
146
  httpRoutes: [{
537
147
  method: "*",
538
- path: i,
148
+ path: t,
539
149
  originGuard: "exempt",
540
- handle: async (e) => o ? W(o, r.token, i, e) : R(503, T(503, "scim store not bound"))
150
+ handle: async (n) => r ? O(r, e.token, t, n) : C(503, u(503, "scim store not bound"))
541
151
  }],
542
152
  bindDataStore: (e) => {
543
- o = L(e);
153
+ r = h(e);
544
154
  },
545
- onActivate: (t) => e.sync(() => {
546
- t.logger.info("scim active", { basePath: i });
155
+ onActivate: (e) => y.sync(() => {
156
+ e.logger.info("scim active", { basePath: t });
547
157
  })
548
158
  });
549
159
  };
550
160
  //#endregion
551
- export { _ as SCIM_ERROR_SCHEMA, h as SCIM_GROUP_SCHEMA, g as SCIM_LIST_SCHEMA, m as SCIM_USER_SCHEMA, O as applyScimGroupPatch, C as applyScimPatch, L as dataStoreScimStore, S as fromScimUser, W as handleScim, W as handleScimRequest, I as memoryScimStore, D as parsePagination, E as parseScimFilter, M as resourceTypes, T as scimError, w as scimList, K as scimPlugin, j as scimSchemas, k as serviceProviderConfig, x as toScimUser };
161
+ export { e as SCIM_ERROR_SCHEMA, t as SCIM_GROUP_SCHEMA, n as SCIM_LIST_SCHEMA, r as SCIM_USER_SCHEMA, i as applyScimGroupPatch, a as applyScimPatch, h as dataStoreScimStore, o as fromScimUser, O as handleScim, O as handleScimRequest, g as memoryScimStore, s as parsePagination, c as parseScimFilter, l as resourceTypes, u as scimError, d as scimList, A as scimPlugin, f as scimSchemas, p as serviceProviderConfig, m as toScimUser };