@thunderid/node 1.11.0 → 1.12.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.
@@ -40,6 +40,149 @@ secure_random_bytes = __toESM(secure_random_bytes);
40
40
  let uuid = require("uuid");
41
41
  uuid = __toESM(uuid);
42
42
 
43
+ //#region src/api/access/requestAccessApi.ts
44
+ const METADATA_FIELDS = {
45
+ evaluation: "access_evaluation_endpoint",
46
+ evaluations: "access_evaluations_endpoint",
47
+ searchAction: "search_action_endpoint"
48
+ };
49
+ const trimSlash = (value) => value.replace(/\/+$/, "");
50
+ /**
51
+ * Reads the AuthZEN metadata of the server at `baseUrl` and checks that its `policy_decision_point`
52
+ * names that server exactly (apart from a trailing slash).
53
+ */
54
+ const getAuthZENConfiguration = async (operation, { baseUrl, fetcher, signal }) => {
55
+ const fetchFn = fetcher ?? fetch;
56
+ let response;
57
+ try {
58
+ response = await fetchFn(`${trimSlash(baseUrl)}/.well-known/authzen-configuration`, {
59
+ headers: { Accept: "application/json" },
60
+ method: "GET",
61
+ signal
62
+ });
63
+ } catch (error) {
64
+ throw new __thunderid_javascript.ThunderIDAPIError(`Network or parsing error: ${error instanceof Error ? error.message : "Unknown error"}`, `${operation}-NetworkError-001`, "node", 0, "Network Error");
65
+ }
66
+ if (!response.ok) throw new __thunderid_javascript.ThunderIDAPIError(await response.text().catch(() => ""), `${operation}-MetadataError-001`, "node", response.status, response.statusText, "Reading the AuthZEN metadata failed");
67
+ const metadata = await response.json();
68
+ if (typeof metadata?.policy_decision_point !== "string" || trimSlash(metadata.policy_decision_point) !== trimSlash(baseUrl)) throw new __thunderid_javascript.ThunderIDAPIError("The policy_decision_point in the AuthZEN metadata does not match the configured server.", `${operation}-MetadataError-002`, "node");
69
+ return metadata;
70
+ };
71
+ /**
72
+ * Resolves an access endpoint: an explicit override, held to the origin of `baseUrl`, else the
73
+ * server's AuthZEN metadata.
74
+ */
75
+ const resolveEndpoint = async (operation, key, config) => {
76
+ const override = config.endpoints?.[key];
77
+ if (override) {
78
+ if (new URL(override).origin !== new URL(config.baseUrl).origin) throw new __thunderid_javascript.ThunderIDAPIError(`The ${key} endpoint override is not on the origin of baseUrl.`, `${operation}-ValidationError-002`, "node", 400);
79
+ return override;
80
+ }
81
+ const endpoint = (await getAuthZENConfiguration(operation, config))[METADATA_FIELDS[key]];
82
+ if (typeof endpoint !== "string" || endpoint === "") throw new __thunderid_javascript.ThunderIDAPIError(`The AuthZEN metadata names no ${METADATA_FIELDS[key]}.`, `${operation}-MetadataError-003`, "node");
83
+ return endpoint;
84
+ };
85
+ /**
86
+ * Posts an AuthZEN request with the `Direct-Auth-Secret` header. A `4xx` or `5xx` answer is an error
87
+ * with the server's `error` as the message; 401, 403 and 404 keep distinct codes.
88
+ */
89
+ const requestAccessApi = async (operation, key, config, body) => {
90
+ try {
91
+ new URL(config.baseUrl);
92
+ } catch (error) {
93
+ throw new __thunderid_javascript.ThunderIDAPIError(`Invalid URL provided. ${error instanceof Error ? error.message : String(error)}`, `${operation}-ValidationError-001`, "node", 400, "The provided `baseUrl` does not adhere to the URL schema.");
94
+ }
95
+ if (typeof config.secret !== "string" || config.secret === "") throw new __thunderid_javascript.ThunderIDAPIError("The Direct-Auth-Secret is required for access evaluation.", `${operation}-ValidationError-003`, "node", 400);
96
+ const endpoint = await resolveEndpoint(operation, key, config);
97
+ const fetchFn = config.fetcher ?? fetch;
98
+ let response;
99
+ try {
100
+ response = await fetchFn(endpoint, {
101
+ body: JSON.stringify(body),
102
+ headers: {
103
+ Accept: "application/json",
104
+ "Content-Type": "application/json",
105
+ "Direct-Auth-Secret": config.secret
106
+ },
107
+ method: "POST",
108
+ signal: config.signal
109
+ });
110
+ } catch (error) {
111
+ throw new __thunderid_javascript.ThunderIDAPIError(`Network or parsing error: ${error instanceof Error ? error.message : "Unknown error"}`, `${operation}-NetworkError-001`, "node", 0, "Network Error");
112
+ }
113
+ if (!response.ok) {
114
+ const text = await response.text().catch(() => "");
115
+ let message = text;
116
+ try {
117
+ const parsed = JSON.parse(text);
118
+ if (typeof parsed?.error === "string" && parsed.code === void 0) message = JSON.stringify({
119
+ code: parsed.error,
120
+ message: { defaultValue: parsed.error }
121
+ });
122
+ } catch {}
123
+ let reason = "ResponseError";
124
+ if (response.status === 401) reason = "UnauthorizedError";
125
+ if (response.status === 403) reason = "ForbiddenError";
126
+ if (response.status === 404) reason = "NotFoundError";
127
+ throw new __thunderid_javascript.ThunderIDAPIError(message, `${operation}-${reason}-001`, "node", response.status, response.statusText, "Access evaluation failed");
128
+ }
129
+ return await response.json();
130
+ };
131
+ var requestAccessApi_default = requestAccessApi;
132
+
133
+ //#endregion
134
+ //#region src/api/access/evaluateAccess.ts
135
+ /**
136
+ * Asks the server's AuthZEN policy decision point whether a subject may perform an action on a resource,
137
+ * at the `access_evaluation_endpoint` from `/.well-known/authzen-configuration`.
138
+ *
139
+ * Server-side only: it is authorized by the server-level secret in the `Direct-Auth-Secret` header,
140
+ * which a browser or mobile app cannot hold.
141
+ *
142
+ * A denial is a result: `{decision: false}`, with the reason in `context`. Only a transport failure or a
143
+ * 4xx/5xx answer throws.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const {decision} = await evaluateAccess(
148
+ * {subject: {type: 'user', id: userId}, resource: {type: 'https://api.example.com/booking'}, action: {name: 'booking:read'}},
149
+ * {baseUrl: 'https://localhost:8090', secret: process.env.THUNDERID_DIRECT_AUTH_SECRET!},
150
+ * );
151
+ * ```
152
+ */
153
+ const evaluateAccess = (request, config) => requestAccessApi_default("evaluateAccess", "evaluation", config, request);
154
+ var evaluateAccess_default = evaluateAccess;
155
+
156
+ //#endregion
157
+ //#region src/api/access/evaluateAccesses.ts
158
+ /**
159
+ * Evaluates a batch of access requests at the `access_evaluations_endpoint`, and returns one decision
160
+ * per evaluation, in order. `defaults` apply to every evaluation that does not set that member itself.
161
+ *
162
+ * Server-side only, like {@link evaluateAccess}. A denial is a result, not an error.
163
+ */
164
+ const evaluateAccesses = async ({ defaults, evaluations }, config) => {
165
+ return (await requestAccessApi_default("evaluateAccesses", "evaluations", config, { evaluations: (evaluations ?? []).map((evaluation) => ({
166
+ ...defaults,
167
+ ...evaluation
168
+ })) }))?.evaluations ?? [];
169
+ };
170
+ var evaluateAccesses_default = evaluateAccesses;
171
+
172
+ //#endregion
173
+ //#region src/api/access/searchActions.ts
174
+ /**
175
+ * Asks which actions a subject may perform on a resource, at the `search_action_endpoint`
176
+ * (`/access/v1/search/action`). Server-side only, like {@link evaluateAccess}.
177
+ *
178
+ * @returns The actions the subject may perform.
179
+ */
180
+ const searchActions = async (request, config) => {
181
+ return (await requestAccessApi_default("searchActions", "searchAction", config, request))?.results ?? [];
182
+ };
183
+ var searchActions_default = searchActions;
184
+
185
+ //#endregion
43
186
  //#region src/stores/MemoryCacheStore.ts
44
187
  /**
45
188
  * In-memory key-value store backed by `memory-cache`.
@@ -241,6 +384,49 @@ const createManagementClient = (resolve) => {
241
384
  ...await config("applications", options)
242
385
  })
243
386
  },
387
+ authorizationDetailTypes: {
388
+ create: async (payload, options) => (0, __thunderid_javascript.createAuthorizationDetailType)({
389
+ payload,
390
+ ...await config("authorizationDetailTypes", options)
391
+ }),
392
+ delete: async (authorizationDetailTypeId, options) => (0, __thunderid_javascript.deleteAuthorizationDetailType)({
393
+ authorizationDetailTypeId: requireId(authorizationDetailTypeId, "deleteAuthorizationDetailType"),
394
+ ...await config("authorizationDetailTypes", options)
395
+ }),
396
+ get: async (authorizationDetailTypeId, options) => (0, __thunderid_javascript.getAuthorizationDetailType)({
397
+ authorizationDetailTypeId: requireId(authorizationDetailTypeId, "getAuthorizationDetailType"),
398
+ ...await config("authorizationDetailTypes", options)
399
+ }),
400
+ list: async ({ limit, offset,...options } = {}) => (0, __thunderid_javascript.getAuthorizationDetailTypes)({
401
+ limit,
402
+ offset,
403
+ ...await config("authorizationDetailTypes", options)
404
+ }),
405
+ update: async (authorizationDetailTypeId, payload, options) => (0, __thunderid_javascript.updateAuthorizationDetailType)({
406
+ authorizationDetailTypeId: requireId(authorizationDetailTypeId, "updateAuthorizationDetailType"),
407
+ payload,
408
+ ...await config("authorizationDetailTypes", options)
409
+ })
410
+ },
411
+ clientRegistrations: {
412
+ delete: async (clientId, options) => (0, __thunderid_javascript.deleteClientRegistration)({
413
+ clientId: requireId(clientId, "deleteClientRegistration"),
414
+ ...await config("clientRegistrations", options)
415
+ }),
416
+ get: async (clientId, options) => (0, __thunderid_javascript.getClientRegistration)({
417
+ clientId: requireId(clientId, "getClientRegistration"),
418
+ ...await config("clientRegistrations", options)
419
+ }),
420
+ register: async (payload, options) => (0, __thunderid_javascript.registerClient)({
421
+ payload,
422
+ ...await config("clientRegistrations", options)
423
+ }),
424
+ update: async (clientId, payload, options) => (0, __thunderid_javascript.updateClientRegistration)({
425
+ clientId: requireId(clientId, "updateClientRegistration"),
426
+ payload,
427
+ ...await config("clientRegistrations", options)
428
+ })
429
+ },
244
430
  configuration: {
245
431
  captureVersion: async (payload, options) => (0, __thunderid_javascript.createConfigurationVersion)({
246
432
  payload,
@@ -306,6 +492,26 @@ const createManagementClient = (resolve) => {
306
492
  ...await config("connections", options)
307
493
  })
308
494
  },
495
+ credentialConfigurations: {
496
+ create: async (payload, options) => (0, __thunderid_javascript.createCredentialConfiguration)({
497
+ payload,
498
+ ...await config("credentialConfigurations", options)
499
+ }),
500
+ delete: async (configurationId, options) => (0, __thunderid_javascript.deleteCredentialConfiguration)({
501
+ configurationId: requireId(configurationId, "deleteCredentialConfiguration"),
502
+ ...await config("credentialConfigurations", options)
503
+ }),
504
+ get: async (configurationId, options) => (0, __thunderid_javascript.getCredentialConfiguration)({
505
+ configurationId: requireId(configurationId, "getCredentialConfiguration"),
506
+ ...await config("credentialConfigurations", options)
507
+ }),
508
+ list: async (options) => (0, __thunderid_javascript.getCredentialConfigurations)(await config("credentialConfigurations", options)),
509
+ update: async (configurationId, payload, options) => (0, __thunderid_javascript.updateCredentialConfiguration)({
510
+ configurationId: requireId(configurationId, "updateCredentialConfiguration"),
511
+ payload,
512
+ ...await config("credentialConfigurations", options)
513
+ })
514
+ },
309
515
  design: {
310
516
  createLayout: async (payload, options) => (0, __thunderid_javascript.createLayout)({
311
517
  payload,
@@ -410,6 +616,49 @@ const createManagementClient = (resolve) => {
410
616
  flowId: requireId(flowId, "updateFlow"),
411
617
  payload,
412
618
  ...await config("flows", options)
619
+ }),
620
+ createSharingPolicy: async (flowId, payload, options) => (0, __thunderid_javascript.createFlowSharingPolicy)({
621
+ payload,
622
+ flowId: requireId(flowId, "createFlowSharingPolicy"),
623
+ ...await config("flows", options)
624
+ }),
625
+ deleteSharingPolicy: async (flowId, policyId, options) => (0, __thunderid_javascript.deleteFlowSharingPolicy)({
626
+ flowId: requireId(flowId, "deleteFlowSharingPolicy"),
627
+ policyId: requireId(policyId, "deleteFlowSharingPolicy"),
628
+ ...await config("flows", options)
629
+ }),
630
+ getOverlayRules: async (flowId, ouId, options) => (0, __thunderid_javascript.getFlowOverlayRules)({
631
+ flowId: requireId(flowId, "getFlowOverlayRules"),
632
+ ouId: requireId(ouId, "getFlowOverlayRules"),
633
+ ...await config("flows", options)
634
+ }),
635
+ getSharingPolicy: async (flowId, policyId, options) => (0, __thunderid_javascript.getFlowSharingPolicy)({
636
+ flowId: requireId(flowId, "getFlowSharingPolicy"),
637
+ policyId: requireId(policyId, "getFlowSharingPolicy"),
638
+ ...await config("flows", options)
639
+ }),
640
+ listSharingPolicies: async (flowId, { limit, offset,...options } = {}) => (0, __thunderid_javascript.getFlowSharingPolicies)({
641
+ flowId: requireId(flowId, "getFlowSharingPolicies"),
642
+ limit,
643
+ offset,
644
+ ...await config("flows", options)
645
+ }),
646
+ updateSharingPolicy: async (flowId, policyId, payload, options) => (0, __thunderid_javascript.updateFlowSharingPolicy)({
647
+ payload,
648
+ policyId: requireId(policyId, "updateFlowSharingPolicy"),
649
+ flowId: requireId(flowId, "updateFlowSharingPolicy"),
650
+ ...await config("flows", options)
651
+ }),
652
+ getVariables: async (flowId, ouId, options) => (0, __thunderid_javascript.getFlowVariables)({
653
+ flowId: requireId(flowId, "getFlowVariables"),
654
+ ouId: requireId(ouId, "getFlowVariables"),
655
+ ...await config("flows", options)
656
+ }),
657
+ updateVariables: async (flowId, ouId, variables, options) => (0, __thunderid_javascript.updateFlowVariables)({
658
+ flowId: requireId(flowId, "updateFlowVariables"),
659
+ ouId: requireId(ouId, "updateFlowVariables"),
660
+ variables,
661
+ ...await config("flows", options)
413
662
  })
414
663
  },
415
664
  gateways: {
@@ -463,6 +712,20 @@ const createManagementClient = (resolve) => {
463
712
  version,
464
713
  ...await config("gateways", options)
465
714
  }),
715
+ getMaster: async (gatewayId, options) => (0, __thunderid_javascript.getGatewayMaster)({
716
+ gatewayId: requireId(gatewayId, "getGatewayMaster"),
717
+ ...await config("gateways", options)
718
+ }),
719
+ getMasterHistory: async (gatewayId, options) => (0, __thunderid_javascript.getGatewayMasterHistory)({
720
+ gatewayId: requireId(gatewayId, "getGatewayMasterHistory"),
721
+ ...await config("gateways", options)
722
+ }),
723
+ getMasterResource: async (gatewayId, resourceType, resourceId, options) => (0, __thunderid_javascript.getGatewayMasterResource)({
724
+ gatewayId: requireId(gatewayId, "getGatewayMasterResource"),
725
+ resourceId: requireId(resourceId, "getGatewayMasterResource"),
726
+ resourceType: requireId(resourceType, "getGatewayMasterResource"),
727
+ ...await config("gateways", options)
728
+ }),
466
729
  getSecret: async (gatewayId, name, options) => (0, __thunderid_javascript.getGatewaySecret)({
467
730
  gatewayId: requireId(gatewayId, "getGatewaySecret"),
468
731
  name: requireId(name, "getGatewaySecret"),
@@ -523,6 +786,11 @@ const createManagementClient = (resolve) => {
523
786
  payload,
524
787
  ...await config("groups", options)
525
788
  }),
789
+ createByPath: async (path, payload, options) => (0, __thunderid_javascript.createGroupByPath)({
790
+ path,
791
+ payload,
792
+ ...await config("groups", options)
793
+ }),
526
794
  delete: async (groupId, options) => (0, __thunderid_javascript.deleteGroup)({
527
795
  groupId: requireId(groupId, "deleteGroup"),
528
796
  ...await config("groups", options)
@@ -536,6 +804,12 @@ const createManagementClient = (resolve) => {
536
804
  offset,
537
805
  ...await config("groups", options)
538
806
  }),
807
+ listByPath: async (path, { limit, offset,...options } = {}) => (0, __thunderid_javascript.getGroupsByPath)({
808
+ limit,
809
+ offset,
810
+ path,
811
+ ...await config("groups", options)
812
+ }),
539
813
  listMembers: async (groupId, { limit, offset,...options } = {}) => (0, __thunderid_javascript.getGroupMembers)({
540
814
  groupId: requireId(groupId, "getGroupMembers"),
541
815
  limit,
@@ -682,6 +956,50 @@ const createManagementClient = (resolve) => {
682
956
  ...await config("organizationUnits", options)
683
957
  })
684
958
  },
959
+ presentationDefinitions: {
960
+ create: async (payload, options) => (0, __thunderid_javascript.createPresentationDefinition)({
961
+ payload,
962
+ ...await config("presentationDefinitions", options)
963
+ }),
964
+ delete: async (definitionId, options) => (0, __thunderid_javascript.deletePresentationDefinition)({
965
+ definitionId: requireId(definitionId, "deletePresentationDefinition"),
966
+ ...await config("presentationDefinitions", options)
967
+ }),
968
+ get: async (definitionId, options) => (0, __thunderid_javascript.getPresentationDefinition)({
969
+ definitionId: requireId(definitionId, "getPresentationDefinition"),
970
+ ...await config("presentationDefinitions", options)
971
+ }),
972
+ list: async (options) => (0, __thunderid_javascript.getPresentationDefinitions)(await config("presentationDefinitions", options)),
973
+ update: async (definitionId, payload, options) => (0, __thunderid_javascript.updatePresentationDefinition)({
974
+ definitionId: requireId(definitionId, "updatePresentationDefinition"),
975
+ payload,
976
+ ...await config("presentationDefinitions", options)
977
+ })
978
+ },
979
+ projects: {
980
+ create: async (payload, options) => (0, __thunderid_javascript.createProject)({
981
+ payload,
982
+ ...await config("projects", options)
983
+ }),
984
+ delete: async (projectId, options) => (0, __thunderid_javascript.deleteProject)({
985
+ projectId: requireId(projectId, "deleteProject"),
986
+ ...await config("projects", options)
987
+ }),
988
+ get: async (projectId, options) => (0, __thunderid_javascript.getProject)({
989
+ projectId: requireId(projectId, "getProject"),
990
+ ...await config("projects", options)
991
+ }),
992
+ list: async ({ limit, offset,...options } = {}) => (0, __thunderid_javascript.getProjects)({
993
+ limit,
994
+ offset,
995
+ ...await config("projects", options)
996
+ }),
997
+ update: async (projectId, payload, options) => (0, __thunderid_javascript.updateProject)({
998
+ projectId: requireId(projectId, "updateProject"),
999
+ payload,
1000
+ ...await config("projects", options)
1001
+ })
1002
+ },
685
1003
  resourceServers: {
686
1004
  create: async (payload, options) => (0, __thunderid_javascript.createResourceServer)({
687
1005
  payload,
@@ -807,6 +1125,38 @@ const createManagementClient = (resolve) => {
807
1125
  payload,
808
1126
  roleId: requireId(roleId, "updateRole"),
809
1127
  ...await config("roles", options)
1128
+ }),
1129
+ createSharingPolicy: async (roleId, payload, options) => (0, __thunderid_javascript.createRoleSharingPolicy)({
1130
+ payload,
1131
+ roleId: requireId(roleId, "createRoleSharingPolicy"),
1132
+ ...await config("roles", options)
1133
+ }),
1134
+ deleteSharingPolicy: async (roleId, policyId, options) => (0, __thunderid_javascript.deleteRoleSharingPolicy)({
1135
+ roleId: requireId(roleId, "deleteRoleSharingPolicy"),
1136
+ policyId: requireId(policyId, "deleteRoleSharingPolicy"),
1137
+ ...await config("roles", options)
1138
+ }),
1139
+ getOverlayRules: async (roleId, ouId, options) => (0, __thunderid_javascript.getRoleOverlayRules)({
1140
+ roleId: requireId(roleId, "getRoleOverlayRules"),
1141
+ ouId: requireId(ouId, "getRoleOverlayRules"),
1142
+ ...await config("roles", options)
1143
+ }),
1144
+ getSharingPolicy: async (roleId, policyId, options) => (0, __thunderid_javascript.getRoleSharingPolicy)({
1145
+ roleId: requireId(roleId, "getRoleSharingPolicy"),
1146
+ policyId: requireId(policyId, "getRoleSharingPolicy"),
1147
+ ...await config("roles", options)
1148
+ }),
1149
+ listSharingPolicies: async (roleId, { limit, offset,...options } = {}) => (0, __thunderid_javascript.getRoleSharingPolicies)({
1150
+ roleId: requireId(roleId, "getRoleSharingPolicies"),
1151
+ limit,
1152
+ offset,
1153
+ ...await config("roles", options)
1154
+ }),
1155
+ updateSharingPolicy: async (roleId, policyId, payload, options) => (0, __thunderid_javascript.updateRoleSharingPolicy)({
1156
+ payload,
1157
+ policyId: requireId(policyId, "updateRoleSharingPolicy"),
1158
+ roleId: requireId(roleId, "updateRoleSharingPolicy"),
1159
+ ...await config("roles", options)
810
1160
  })
811
1161
  },
812
1162
  secrets: {
@@ -1102,7 +1452,7 @@ var ThunderIDNodeClient = class extends __thunderid_javascript.ThunderIDJavaScri
1102
1452
  async signIn(...args) {
1103
1453
  const [authURLCallback, userId, authorizationCode, state, signInConfig] = args;
1104
1454
  if (!userId) return Promise.reject(new __thunderid_javascript.ThunderIDAuthException("NODE-AUTH_CLIENT-SI-NF01", "No user ID was provided.", "Unable to sign in the user as no user ID was provided."));
1105
- if (await this.isSignedIn(userId)) {
1455
+ if (!Boolean(authorizationCode && state && await this.isOrganizationUnitBoundRequest(state, userId)) && await this.isSignedIn(userId)) {
1106
1456
  const sessionData$1 = await this.getStorageManager().getSessionData(userId);
1107
1457
  return Promise.resolve({
1108
1458
  accessToken: sessionData$1.access_token,
@@ -1147,6 +1497,87 @@ var ThunderIDNodeClient = class extends __thunderid_javascript.ThunderIDJavaScri
1147
1497
  if (!url) return Promise.reject(new __thunderid_javascript.ThunderIDAuthException("NODE-AUTH_CLIENT-GSIU-NF01", "Getting authorization URL failed.", "No authorization URL was returned."));
1148
1498
  return url;
1149
1499
  }
1500
+ /**
1501
+ * Starts a switch of the session `userId` to the organization unit `organizationUnitId`: builds the
1502
+ * unit's authorization URL (`{baseUrl}/ou/{ouId}/oauth2/authorize`) and hands it to `authURLCallback`
1503
+ * to redirect the user to. The server reuses the SSO session when the user can sign in there, so
1504
+ * normally no credentials are asked. Complete it with `signIn(callback, userId, code, state)` on the
1505
+ * callback: the code is redeemed at the unit's token endpoint and replaces the session's tokens.
1506
+ * Until then, and when the callback carries an error, the previous session stays as it was.
1507
+ *
1508
+ * @throws {ThunderIDAPIError} `switchOrganizationUnit-ValidationError-001` without a unit, a session or
1509
+ * a callback.
1510
+ */
1511
+ async switchOrganizationUnit(organizationUnitId, options = {}) {
1512
+ const { authURLCallback, userId,...rest } = options;
1513
+ const params = Object.fromEntries(Object.entries(rest).filter(([key]) => key !== "redirect"));
1514
+ if (typeof organizationUnitId !== "string" || organizationUnitId.trim() === "" || !userId) throw new __thunderid_javascript.ThunderIDAPIError("An organization unit identifier and a session are required.", __thunderid_javascript.OrganizationUnitSwitchErrorCodes.InvalidOrganizationUnit, "node", 400);
1515
+ if (typeof authURLCallback !== "function") throw new __thunderid_javascript.ThunderIDAPIError("An authURLCallback is required to send the user to the organization unit.", __thunderid_javascript.OrganizationUnitSwitchErrorCodes.InvalidOrganizationUnit, "node", 400);
1516
+ authURLCallback(await this.getSignInUrl({
1517
+ ...params,
1518
+ organizationUnitId
1519
+ }, userId));
1520
+ }
1521
+ /**
1522
+ * Starts a device authorization request (RFC 8628) for an input-constrained device or a CLI tool. Show
1523
+ * the user `userCode` and `verificationUri`; keep `deviceCode`, a credential, to yourself and pass it
1524
+ * to {@link pollDeviceAuthorization}. It is never logged.
1525
+ */
1526
+ async startDeviceAuthorization(options = {}) {
1527
+ return super.startDeviceAuthorization(options);
1528
+ }
1529
+ /**
1530
+ * Polls the token endpoint with the device code until the user approves, denies, or the code expires,
1531
+ * and stores the tokens for the session `userId` on approval.
1532
+ *
1533
+ * @throws {ThunderIDAPIError} `JS-AUTH_CORE-DEVICE2-HE03` when the server ends the request
1534
+ * (`access_denied`, `expired_token`), with the OAuth error in `serverError`.
1535
+ */
1536
+ async pollDeviceAuthorization(deviceCode, interval, options, userId) {
1537
+ const tokens = await super.pollDeviceAuthorization(deviceCode, interval, options, userId);
1538
+ if (userId) await this.indexSession(userId, await this.getStorageManager().getSessionData(userId));
1539
+ return tokens;
1540
+ }
1541
+ /**
1542
+ * Introspects a token (RFC 7662) at the server's introspection endpoint, authenticating as this client.
1543
+ * An inactive token is a result (`{active: false}`), not an error.
1544
+ */
1545
+ async introspectToken(token, tokenTypeHint) {
1546
+ return super.introspectToken(token, tokenTypeHint);
1547
+ }
1548
+ /**
1549
+ * The request configuration for access evaluation: the configured server, secret and overrides, with
1550
+ * a per-call secret taking precedence.
1551
+ */
1552
+ async accessEvaluationConfig(secret, signal) {
1553
+ const configData = await this.getStorageManager().getConfigData();
1554
+ const accessEvaluation = configData.accessEvaluation;
1555
+ return {
1556
+ baseUrl: configData?.baseUrl ?? "",
1557
+ endpoints: accessEvaluation?.endpoints,
1558
+ secret: secret ?? accessEvaluation?.secret ?? "",
1559
+ signal
1560
+ };
1561
+ }
1562
+ /**
1563
+ * Asks the server whether a subject may perform an action on a resource (AuthZEN). A denial is a result
1564
+ * (`decision: false`), not an error. Uses `accessEvaluation.secret`, or `options.secret`.
1565
+ */
1566
+ async evaluateAccess(request, options = {}) {
1567
+ return evaluateAccess_default(request, await this.accessEvaluationConfig(options.secret, options.signal));
1568
+ }
1569
+ /**
1570
+ * Evaluates a batch of access requests and returns one decision per evaluation, in order.
1571
+ */
1572
+ async evaluateAccesses(request, options = {}) {
1573
+ return evaluateAccesses_default(request, await this.accessEvaluationConfig(options.secret, options.signal));
1574
+ }
1575
+ /**
1576
+ * Asks which actions a subject may perform on a resource.
1577
+ */
1578
+ async searchActions(request, options = {}) {
1579
+ return searchActions_default(request, await this.accessEvaluationConfig(options.secret, options.signal));
1580
+ }
1150
1581
  async signOut(...args) {
1151
1582
  const userId = typeof args[0] === "string" ? args[0] : void 0;
1152
1583
  const signOutUrl = await this.getSignOutUrl(userId);
@@ -1697,8 +2128,11 @@ const MANAGEMENT_COLLECTIONS = {
1697
2128
  agentTypes: "agent-types",
1698
2129
  agents: "agents",
1699
2130
  applications: "applications",
2131
+ authorizationDetailTypes: "authorization-detail-types",
2132
+ clientRegistrations: "oauth2/dcr/register",
1700
2133
  configurationVersions: "configuration-versions",
1701
2134
  connections: "connections",
2135
+ credentialConfigurations: "openid4vci/credential-configurations",
1702
2136
  design: "design",
1703
2137
  export: "export",
1704
2138
  flows: "flows",
@@ -1708,6 +2142,8 @@ const MANAGEMENT_COLLECTIONS = {
1708
2142
  import: "import",
1709
2143
  notificationTemplates: "notification-templates",
1710
2144
  organizationUnits: "organization-units",
2145
+ presentationDefinitions: "openid4vp/presentation-definitions",
2146
+ projects: "projects",
1711
2147
  resourceServers: "resource-servers",
1712
2148
  roles: "roles",
1713
2149
  secrets: "secrets",
@@ -1791,10 +2227,13 @@ exports.SessionIndex = SessionIndex_default;
1791
2227
  exports.SessionUtils = SessionUtils_default;
1792
2228
  exports.ThunderIDNodeClient = ThunderIDNodeClient_default;
1793
2229
  exports.createManagementClient = createManagementClient_default;
2230
+ exports.evaluateAccess = evaluateAccess_default;
2231
+ exports.evaluateAccesses = evaluateAccesses_default;
1794
2232
  exports.generateSessionId = generateSessionId_default;
1795
2233
  exports.getManagementCollectionUrls = getManagementCollectionUrls;
1796
2234
  exports.getSessionCookieOptions = getSessionCookieOptions_default;
1797
2235
  exports.matchManagementUrl = matchManagementUrl;
2236
+ exports.searchActions = searchActions_default;
1798
2237
  Object.keys(__thunderid_javascript).forEach(function (k) {
1799
2238
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1800
2239
  enumerable: true,
package/dist/index.d.ts CHANGED
@@ -6,6 +6,10 @@ export { default as CookieConfig } from './constants/CookieConfig';
6
6
  export type { ThunderIDNodeConfig, SessionCookieConfig } from './models/config';
7
7
  export type { default as AuthURLCallback } from './models/AuthURLCallback';
8
8
  export type { ManagementCallOptions, ManagementGroupMemberInput, ManagementListOptions, ManagementRequestConfigResolver, ManagementResourceKey, ThunderIDNodeManagementClient, } from './models/management';
9
+ export type { AccessAction, AccessActionSearchRequest, AccessActionSearchResponse, AccessEvaluationRequest, AccessEvaluationRequestConfig, AccessEvaluationResponse, AccessEvaluationsRequest, AccessResource, AccessSubject, AuthZENConfiguration, } from './models/access-evaluation';
10
+ export { default as evaluateAccess } from './api/access/evaluateAccess';
11
+ export { default as evaluateAccesses } from './api/access/evaluateAccesses';
12
+ export { default as searchActions } from './api/access/searchActions';
9
13
  export { default as MemoryCacheStore } from './stores/MemoryCacheStore';
10
14
  export { default as CookieChunking } from './utils/CookieChunking';
11
15
  export { default as NodeCryptoUtils } from './utils/NodeCryptoUtils';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA;;GAEG;AAGH,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAGrE,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAGjE,YAAY,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AAC9E,YAAY,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,0BAA0B,CAAC;AACzE,YAAY,EACV,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,+BAA+B,EAC/B,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAGtE,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,iBAAiB,EAAE,yBAAyB,EAAC,MAAM,2BAA2B,CAAC;AAClG,YAAY,EAAC,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AACnF,YAAY,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAC,OAAO,IAAI,iBAAiB,EAAC,MAAM,2B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