@bymax-one/nest-auth 1.4.22 → 1.5.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.
@@ -136,6 +136,15 @@ declare const AUTH_ERROR_CODES: {
136
136
  readonly API_KEY_INVALID: "auth.api_key_invalid";
137
137
  readonly API_KEY_SCOPE_INSUFFICIENT: "auth.api_key_scope_insufficient";
138
138
  readonly API_KEY_NOT_FOUND: "auth.api_key_not_found";
139
+ readonly WORKSPACE_REQUIRED: "auth.workspace_required";
140
+ readonly WORKSPACE_NOT_FOUND: "auth.workspace_not_found";
141
+ readonly INSUFFICIENT_WORKSPACE_ROLE: "auth.insufficient_workspace_role";
142
+ readonly LAST_OWNER: "auth.last_owner";
143
+ readonly ALREADY_MEMBER: "auth.already_member";
144
+ readonly INVITATION_EMAIL_MISMATCH: "auth.invitation_email_mismatch";
145
+ readonly REGISTRATION_CLOSED: "auth.registration_closed";
146
+ readonly WORKSPACE_LIMIT_REACHED: "auth.workspace_limit_reached";
147
+ readonly WORKSPACE_PENDING_DELETION: "auth.workspace_pending_deletion";
139
148
  /**
140
149
  * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
141
150
  * which gives unhandled failures the same envelope everything else answers with.
@@ -167,6 +176,55 @@ type AuthErrorCode = (typeof AUTH_ERROR_CODES)[keyof typeof AUTH_ERROR_CODES];
167
176
  */
168
177
  declare const AUTH_ERROR_STATUS: Readonly<Record<AuthErrorCode, number>>;
169
178
 
179
+ /**
180
+ * Fills the `:placeholders` of a route of `AUTH_ROUTES` with values a caller supplies.
181
+ *
182
+ * Every place a caller-supplied value becomes part of a request path goes through here: a value that
183
+ * is put into a path by hand can leave its segment, and the library's own route constants carry
184
+ * placeholders (`sessions/:id`, `oauth/:provider`, the workspace routes) that a consumer fills too.
185
+ */
186
+ /**
187
+ * Percent-encodes one value for use as a single path segment.
188
+ *
189
+ * @param name - What the value is, for the message.
190
+ * @param value - The value.
191
+ * @returns The encoded segment.
192
+ * @throws {TypeError} For a value that is not a string, is empty, or is `.` or `..`. A URL parser
193
+ * collapses a dot segment even when it is percent-encoded, so encoding cannot keep it inside the
194
+ * segment, and an empty one would address another route (`workspaces//access`).
195
+ */
196
+ declare function pathSegment(name: string, value: unknown): string;
197
+ /**
198
+ * Fills the placeholders of a route template with percent-encoded, single-segment values.
199
+ *
200
+ * @param template - A route such as `workspaces/:workspaceId/members/:userId`.
201
+ * @param values - What each placeholder stands for.
202
+ * @returns The path.
203
+ * @throws {TypeError} When a placeholder has no value, or its value fails {@link pathSegment}.
204
+ */
205
+ declare function fillRoute(template: string, values: Readonly<Record<string, string>>): string;
206
+
207
+ /**
208
+ * Strips `/` characters from the ends of a string without a regular expression.
209
+ *
210
+ * The one implementation for every place that normalizes a base URL or a route prefix, so the same
211
+ * configuration resolves to the same path on the client, in the Next.js reader and in the shared
212
+ * route helpers.
213
+ */
214
+ /**
215
+ * Strip trailing, and optionally leading, `/` characters without a regular expression.
216
+ *
217
+ * The obvious `replace(/^\/+|\/+$/g, '')` is quadratic on a run of slashes: the `$`-anchored
218
+ * alternative backtracks over every prefix of the run, which CodeQL flags as a polynomial ReDoS. A
219
+ * pair of scans is linear and says what it does.
220
+ *
221
+ * @param value - The string to trim.
222
+ * @param leading - Whether to trim the leading run too. Default `true`. A base URL keeps its
223
+ * leading slash because a root-relative base (`/api`) is a legitimate value.
224
+ * @returns `value` with the requested runs of `/` removed.
225
+ */
226
+ declare function trimSlashes(value: string, leading?: boolean): string;
227
+
170
228
  /**
171
229
  * HTTP route paths exposed by the @bymax-one/nest-auth server controllers.
172
230
  *
@@ -181,12 +239,6 @@ declare const AUTH_ERROR_STATUS: Readonly<Record<AuthErrorCode, number>>;
181
239
  * `src/server/controllers/*.ts`. Update both sides together if a route
182
240
  * is renamed.
183
241
  */
184
- /**
185
- * Dashboard (tenant user) authentication routes.
186
- *
187
- * Mounted at the top of the auth route prefix
188
- * (`src/server/controllers/auth.controller.ts`).
189
- */
190
242
  declare const AUTH_DASHBOARD_ROUTES: {
191
243
  /** POST — register a new local (email + password) user. */
192
244
  readonly register: "register";
@@ -470,6 +522,53 @@ declare const AUTH_ROUTES: {
470
522
  /** GET — the provider redirects back here with the authorization code. */
471
523
  readonly callback: "oauth/:provider/callback";
472
524
  };
525
+ readonly workspaces: {
526
+ /**
527
+ * GET — the caller's own active memberships and the workspace they last switched to. POST on the
528
+ * same path creates a workspace.
529
+ */
530
+ readonly list: "workspaces";
531
+ /** GET — the workspace and the caller's role in it. */
532
+ readonly access: "workspaces/:workspaceId/access";
533
+ /** POST — record the workspace as the caller's last active one. */
534
+ readonly switch: "workspaces/:workspaceId/switch";
535
+ /** GET — the members of the workspace. */
536
+ readonly members: "workspaces/:workspaceId/members";
537
+ /** PATCH — rename the workspace. */
538
+ readonly rename: "workspaces/:workspaceId";
539
+ /**
540
+ * POST — schedule the workspace for deletion, re-proving the caller.
541
+ *
542
+ * POST rather than DELETE because the password travels in the body, and a payload on DELETE has
543
+ * no defined semantics (RFC 9110), so an intermediary or a generated client may drop it.
544
+ */
545
+ readonly scheduleDeletion: "workspaces/:workspaceId/schedule-deletion";
546
+ /** POST — undo a scheduled deletion within its grace period. */
547
+ readonly restore: "workspaces/:workspaceId/restore";
548
+ /**
549
+ * PATCH — change a member's role. DELETE on the same path removes the member, with no body.
550
+ */
551
+ readonly member: "workspaces/:workspaceId/members/:userId";
552
+ /** POST — leave the workspace. */
553
+ readonly leave: "workspaces/:workspaceId/leave";
554
+ /** POST — hand ownership to another member, re-proving the caller. */
555
+ readonly transferOwnership: "workspaces/:workspaceId/transfer-ownership";
556
+ /**
557
+ * POST — invite an address to the workspace (`controllers.workspaceInvitations: true`). GET on the
558
+ * same path lists the pending invitations.
559
+ */
560
+ readonly invitations: "workspaces/:workspaceId/invitations";
561
+ /** POST — send a pending invitation again under a new token. */
562
+ readonly resendInvitation: "workspaces/:workspaceId/invitations/resend";
563
+ /** POST — withdraw a pending invitation. */
564
+ readonly revokeInvitation: "workspaces/:workspaceId/invitations/revoke";
565
+ /** POST — what a token is for, without signing in. Public. */
566
+ readonly previewInvitation: "workspaces/invitations/preview";
567
+ /** POST — accept an invitation as the signed-in account it was addressed to. */
568
+ readonly acceptInvitation: "workspaces/invitations/accept";
569
+ /** POST — accept an invitation by creating the account it was addressed to. Public. */
570
+ readonly acceptInvitationSignup: "workspaces/invitations/accept-signup";
571
+ };
473
572
  };
474
573
  /**
475
574
  * Default Next.js proxy endpoints used by `createAuthClient` and the
@@ -677,6 +776,102 @@ type LoginResult = AuthResult | MfaChallengeResult;
677
776
  */
678
777
  type PlatformLoginResult = PlatformAuthResult | MfaChallengeResult;
679
778
 
779
+ /**
780
+ * Workspace shapes as the server answers them, for the client, React and Next.js entry points.
781
+ *
782
+ * Each type mirrors a view the server builds, key for key; a spec on the server side compares them,
783
+ * so a field added on one side only is a red test and not a runtime surprise. A role is a plain
784
+ * string: the hierarchy that gives roles their meaning is the host's configuration and is not
785
+ * shipped to the browser.
786
+ */
787
+ /** The lifecycle state of a workspace. */
788
+ type WorkspaceStatusClient = 'active' | 'pending_deletion' | 'suspended' | 'deleted';
789
+ /** The state of one membership. */
790
+ type MembershipStatusClient = 'active' | 'suspended';
791
+ /** A workspace. */
792
+ interface WorkspaceClient {
793
+ id: string;
794
+ name: string;
795
+ status: WorkspaceStatusClient;
796
+ /** ISO-8601 instant. */
797
+ createdAt: string;
798
+ /** When a scheduled deletion becomes final, `null` when none is scheduled. */
799
+ deletionScheduledAt: string | null;
800
+ }
801
+ /** A workspace and the caller's role in it. */
802
+ interface WorkspaceAccessClient {
803
+ workspace: WorkspaceClient;
804
+ role: string;
805
+ }
806
+ /** One page of the caller's own workspaces. */
807
+ interface WorkspaceListResult {
808
+ items: WorkspaceAccessClient[];
809
+ /** The cursor of the next page, `null` on the last one. */
810
+ nextCursor: string | null;
811
+ /** The workspace the caller last switched to, `null` when none. */
812
+ lastActiveWorkspaceId: string | null;
813
+ }
814
+ /** A member of a workspace. */
815
+ interface WorkspaceMemberClient {
816
+ userId: string;
817
+ role: string;
818
+ status: MembershipStatusClient;
819
+ invitedByUserId: string | null;
820
+ /** ISO-8601 instant. */
821
+ createdAt: string;
822
+ }
823
+ /** One page of a workspace's members. */
824
+ interface WorkspaceMemberPage {
825
+ items: WorkspaceMemberClient[];
826
+ nextCursor: string | null;
827
+ }
828
+ /** A pending invitation to a workspace. */
829
+ interface WorkspaceInvitationClient {
830
+ email: string;
831
+ role: string;
832
+ inviterUserId: string;
833
+ /** ISO-8601 instant. */
834
+ createdAt: string;
835
+ /** ISO-8601 instant. */
836
+ expiresAt: string;
837
+ resendCount: number;
838
+ }
839
+ /** One page of a workspace's pending invitations. */
840
+ interface WorkspaceInvitationPage {
841
+ items: WorkspaceInvitationClient[];
842
+ nextCursor: string | null;
843
+ }
844
+ interface InvitationPreviewBase {
845
+ workspaceName: string;
846
+ role: string;
847
+ /** The invited address with its local part masked. */
848
+ maskedEmail: string;
849
+ /** Whether the invited address already has an account, so the page offers sign-in or sign-up. */
850
+ accountExists: boolean;
851
+ }
852
+ /** What a member invitation is for. */
853
+ interface MemberInvitationPreviewClient extends InvitationPreviewBase {
854
+ kind: 'member';
855
+ inviterName: string;
856
+ }
857
+ /** What the invitation that creates a workspace's first owner is for. */
858
+ interface BootstrapInvitationPreviewClient extends InvitationPreviewBase {
859
+ kind: 'bootstrap';
860
+ }
861
+ /** What an invitation token is for, without signing in. */
862
+ type WorkspaceInvitationPreview = MemberInvitationPreviewClient | BootstrapInvitationPreviewClient;
863
+ /** Where an accepted invitation put the caller. */
864
+ interface AcceptedWorkspaceInvitation {
865
+ workspaceId: string;
866
+ role: string;
867
+ }
868
+ /** The page parameters of a list. */
869
+ interface WorkspacePageParams {
870
+ cursor?: string;
871
+ /** A positive whole number; the server clamps it to its own bounds. */
872
+ limit?: number;
873
+ }
874
+
680
875
  /**
681
876
  * @fileoverview Shared error-related type definitions for `@bymax-one/nest-auth`.
682
877
  *
@@ -975,5 +1170,5 @@ type AuthContextKind = 'dashboard' | 'platform';
975
1170
  */
976
1171
  type TokenDeliveryMode = 'cookie' | 'bearer';
977
1172
 
978
- export { AUTH_ACCESS_COOKIE_NAME, AUTH_DASHBOARD_ROUTES, AUTH_EMAIL_CHANGE_ROUTES, AUTH_ERROR_CODES, AUTH_ERROR_STATUS, AUTH_HAS_SESSION_COOKIE_NAME, AUTH_INVITATION_ROUTES, AUTH_MFA_ROUTES, AUTH_OAUTH_ROUTES, AUTH_PASSWORD_ROUTES, AUTH_PLATFORM_MFA_ROUTES, AUTH_PLATFORM_ROUTES, AUTH_PROXY_ROUTES, AUTH_REFRESH_COOKIE_NAME, AUTH_REFRESH_COOKIE_PATH, AUTH_REFRESH_SKIP_PATH_SUFFIXES, AUTH_ROUTES, AUTH_SESSION_ROUTES, AuthClientError, buildAuthRefreshSkipSuffixes };
979
- export type { AuthContextKind, AuthCookieNames, AuthErrorCode, AuthErrorResponse, AuthJwtPayload, AuthPlatformUserClient, AuthResponseCode, AuthResult, AuthUserClient, DashboardJwtPayload, LoginResult, MfaChallengeResult, MfaTempPayload, PlatformAuthResult, PlatformJwtPayload, PlatformLoginResult, TokenDeliveryMode };
1173
+ export { AUTH_ACCESS_COOKIE_NAME, AUTH_DASHBOARD_ROUTES, AUTH_EMAIL_CHANGE_ROUTES, AUTH_ERROR_CODES, AUTH_ERROR_STATUS, AUTH_HAS_SESSION_COOKIE_NAME, AUTH_INVITATION_ROUTES, AUTH_MFA_ROUTES, AUTH_OAUTH_ROUTES, AUTH_PASSWORD_ROUTES, AUTH_PLATFORM_MFA_ROUTES, AUTH_PLATFORM_ROUTES, AUTH_PROXY_ROUTES, AUTH_REFRESH_COOKIE_NAME, AUTH_REFRESH_COOKIE_PATH, AUTH_REFRESH_SKIP_PATH_SUFFIXES, AUTH_ROUTES, AUTH_SESSION_ROUTES, AuthClientError, buildAuthRefreshSkipSuffixes, fillRoute, pathSegment, trimSlashes };
1174
+ export type { AcceptedWorkspaceInvitation, AuthContextKind, AuthCookieNames, AuthErrorCode, AuthErrorResponse, AuthJwtPayload, AuthPlatformUserClient, AuthResponseCode, AuthResult, AuthUserClient, BootstrapInvitationPreviewClient, DashboardJwtPayload, LoginResult, MemberInvitationPreviewClient, MembershipStatusClient, MfaChallengeResult, MfaTempPayload, PlatformAuthResult, PlatformJwtPayload, PlatformLoginResult, TokenDeliveryMode, WorkspaceAccessClient, WorkspaceClient, WorkspaceInvitationClient, WorkspaceInvitationPage, WorkspaceInvitationPreview, WorkspaceListResult, WorkspaceMemberClient, WorkspaceMemberPage, WorkspacePageParams, WorkspaceStatusClient };
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/shared/constants/cookie-defaults.ts
5
2
  var AUTH_ACCESS_COOKIE_NAME = "access_token";
6
3
  var AUTH_REFRESH_COOKIE_NAME = "refresh_token";
@@ -18,7 +15,7 @@ var AUTH_ERROR_CODES = {
18
15
  PENDING_APPROVAL: "auth.pending_approval",
19
16
  // Tokens and sessions
20
17
  /** Internal-only: expiry. Never on the wire — collapsed onto TOKEN_INVALID, to deny an oracle
21
- * separating a token that WAS valid from one that never was. */
18
+ * separating a token that WAS valid from one that never was. */
22
19
  TOKEN_EXPIRED: "auth.token_expired",
23
20
  /** Internal-only: logout or epoch bump. Never on the wire — see TOKEN_EXPIRED. */
24
21
  TOKEN_REVOKED: "auth.token_revoked",
@@ -46,11 +43,11 @@ var AUTH_ERROR_CODES = {
46
43
  PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid",
47
44
  // OTP (email verification, password reset via OTP)
48
45
  /**
49
- * The only code an OTP failure reaches a client with. A wrong code, a record that is not in
50
- * Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
51
- * answers the same whether or not the address exists, but only writes an OTP record when it
52
- * does, so telling them apart made that uniform answer definitive after one extra request.
53
- */
46
+ * The only code an OTP failure reaches a client with. A wrong code, a record that is not in
47
+ * Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
48
+ * answers the same whether or not the address exists, but only writes an OTP record when it
49
+ * does, so telling them apart made that uniform answer definitive after one extra request.
50
+ */
54
51
  OTP_INVALID: "auth.otp_invalid",
55
52
  /** Internal-only: the OTP record was absent. Never on the wire — see {@link OTP_INVALID}. */
56
53
  OTP_EXPIRED: "auth.otp_expired",
@@ -60,21 +57,21 @@ var AUTH_ERROR_CODES = {
60
57
  INSUFFICIENT_ROLE: "auth.insufficient_role",
61
58
  FORBIDDEN: "auth.forbidden",
62
59
  /**
63
- * The request body or query failed DTO validation. Per-field failures serialize into
64
- * `error.details` as `[{ field, message }]`.
65
- */
60
+ * The request body or query failed DTO validation. Per-field failures serialize into
61
+ * `error.details` as `[{ field, message }]`.
62
+ */
66
63
  VALIDATION: "auth.validation",
67
64
  /** The caller exceeded a per-IP rate limit on an auth route. */
68
65
  TOO_MANY_REQUESTS: "auth.too_many_requests",
69
66
  /**
70
- * A state-changing request carrying the session cookie came from an origin the deployment
71
- * does not trust.
72
- */
67
+ * A state-changing request carrying the session cookie came from an origin the deployment
68
+ * does not trust.
69
+ */
73
70
  UNTRUSTED_ORIGIN: "auth.untrusted_origin",
74
71
  /**
75
- * A change to how the account authenticates was attempted without a recent authentication.
76
- * The client should send the user back through sign-in and retry.
77
- */
72
+ * A change to how the account authenticates was attempted without a recent authentication.
73
+ * The client should send the user back through sign-in and retry.
74
+ */
78
75
  REAUTHENTICATION_REQUIRED: "auth.reauthentication_required",
79
76
  // Invitations
80
77
  INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token",
@@ -87,10 +84,20 @@ var AUTH_ERROR_CODES = {
87
84
  API_KEY_INVALID: "auth.api_key_invalid",
88
85
  API_KEY_SCOPE_INSUFFICIENT: "auth.api_key_scope_insufficient",
89
86
  API_KEY_NOT_FOUND: "auth.api_key_not_found",
87
+ // Workspaces
88
+ WORKSPACE_REQUIRED: "auth.workspace_required",
89
+ WORKSPACE_NOT_FOUND: "auth.workspace_not_found",
90
+ INSUFFICIENT_WORKSPACE_ROLE: "auth.insufficient_workspace_role",
91
+ LAST_OWNER: "auth.last_owner",
92
+ ALREADY_MEMBER: "auth.already_member",
93
+ INVITATION_EMAIL_MISMATCH: "auth.invitation_email_mismatch",
94
+ REGISTRATION_CLOSED: "auth.registration_closed",
95
+ WORKSPACE_LIMIT_REACHED: "auth.workspace_limit_reached",
96
+ WORKSPACE_PENDING_DELETION: "auth.workspace_pending_deletion",
90
97
  /**
91
- * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
92
- * which gives unhandled failures the same envelope everything else answers with.
93
- */
98
+ * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
99
+ * which gives unhandled failures the same envelope everything else answers with.
100
+ */
94
101
  INTERNAL: "auth.internal"
95
102
  };
96
103
  var AUTH_ERROR_STATUS = {
@@ -134,9 +141,44 @@ var AUTH_ERROR_STATUS = {
134
141
  "auth.api_key_invalid": 401,
135
142
  "auth.api_key_scope_insufficient": 403,
136
143
  "auth.api_key_not_found": 404,
144
+ "auth.workspace_required": 400,
145
+ "auth.workspace_not_found": 404,
146
+ "auth.insufficient_workspace_role": 403,
147
+ "auth.last_owner": 409,
148
+ "auth.already_member": 409,
149
+ "auth.invitation_email_mismatch": 403,
150
+ "auth.registration_closed": 403,
151
+ "auth.workspace_limit_reached": 403,
152
+ "auth.workspace_pending_deletion": 409,
137
153
  "auth.internal": 500
138
154
  };
139
155
 
156
+ // src/shared/utils/fill-route.ts
157
+ function pathSegment(name, value) {
158
+ if (typeof value !== "string" || value === "") {
159
+ throw new TypeError(`${name} must be a non-empty string`);
160
+ }
161
+ if (value === "." || value === "..") throw new TypeError(`${name} must not be '.' or '..'`);
162
+ return encodeURIComponent(value);
163
+ }
164
+ function fillRoute(template, values) {
165
+ return template.replace(
166
+ /:([A-Za-z]+)/g,
167
+ (_match, name) => pathSegment(name, Object.entries(values).find(([key]) => key === name)?.[1])
168
+ );
169
+ }
170
+
171
+ // src/shared/utils/trim-slashes.ts
172
+ function trimSlashes(value, leading = true) {
173
+ let start = 0;
174
+ let end = value.length;
175
+ if (leading) {
176
+ while (start < end && value[start] === "/") start += 1;
177
+ }
178
+ while (end > start && value[end - 1] === "/") end -= 1;
179
+ return value.slice(start, end);
180
+ }
181
+
140
182
  // src/shared/constants/routes.ts
141
183
  var AUTH_DASHBOARD_ROUTES = {
142
184
  /** POST — register a new local (email + password) user. */
@@ -174,11 +216,11 @@ var AUTH_PASSWORD_ROUTES = {
174
216
  /** POST — submit a new password using the reset token. */
175
217
  resetPassword: "password/reset-password",
176
218
  /**
177
- * POST — change the password of the signed-in user, verifying the current one.
178
- *
179
- * The only route in this family behind the JWT guard: the rest are reached by a
180
- * caller who has no session, which is what a reset is for.
181
- */
219
+ * POST — change the password of the signed-in user, verifying the current one.
220
+ *
221
+ * The only route in this family behind the JWT guard: the rest are reached by a
222
+ * caller who has no session, which is what a reset is for.
223
+ */
182
224
  changePassword: "password/change",
183
225
  /** POST — verify the reset OTP (when `passwordReset.method = 'otp'`). */
184
226
  verifyOtp: "password/verify-otp",
@@ -213,19 +255,19 @@ var AUTH_SESSION_ROUTES = {
213
255
  /** GET — list every active session for the current user. */
214
256
  list: "sessions",
215
257
  /**
216
- * POST — revoke every session belonging to the current user except the one
217
- * making the call.
218
- *
219
- * POST rather than DELETE because the refresh token that names the current
220
- * session travels in the body under `tokenDelivery: 'bearer'`, and OpenAPI 3.0.3
221
- * defers to RFC 7231: a payload on DELETE has no defined semantics, so a
222
- * generated client drops it.
223
- */
258
+ * POST — revoke every session belonging to the current user except the one
259
+ * making the call.
260
+ *
261
+ * POST rather than DELETE because the refresh token that names the current
262
+ * session travels in the body under `tokenDelivery: 'bearer'`, and OpenAPI 3.0.3
263
+ * defers to RFC 7231: a payload on DELETE has no defined semantics, so a
264
+ * generated client drops it.
265
+ */
224
266
  revokeAll: "sessions/revoke-all",
225
267
  /**
226
- * DELETE — revoke a single session by id. The `:id` placeholder must be
227
- * substituted with the session identifier before the request is issued.
228
- */
268
+ * DELETE — revoke a single session by id. The `:id` placeholder must be
269
+ * substituted with the session identifier before the request is issued.
270
+ */
229
271
  revokeOne: "sessions/:id"
230
272
  };
231
273
  var AUTH_EMAIL_CHANGE_ROUTES = {
@@ -248,6 +290,53 @@ var AUTH_OAUTH_ROUTES = {
248
290
  /** GET — the provider redirects back here with the authorization code. */
249
291
  callback: "oauth/:provider/callback"
250
292
  };
293
+ var AUTH_WORKSPACE_ROUTES = {
294
+ /**
295
+ * GET — the caller's own active memberships and the workspace they last switched to. POST on the
296
+ * same path creates a workspace.
297
+ */
298
+ list: "workspaces",
299
+ /** GET — the workspace and the caller's role in it. */
300
+ access: "workspaces/:workspaceId/access",
301
+ /** POST — record the workspace as the caller's last active one. */
302
+ switch: "workspaces/:workspaceId/switch",
303
+ /** GET — the members of the workspace. */
304
+ members: "workspaces/:workspaceId/members",
305
+ /** PATCH — rename the workspace. */
306
+ rename: "workspaces/:workspaceId",
307
+ /**
308
+ * POST — schedule the workspace for deletion, re-proving the caller.
309
+ *
310
+ * POST rather than DELETE because the password travels in the body, and a payload on DELETE has
311
+ * no defined semantics (RFC 9110), so an intermediary or a generated client may drop it.
312
+ */
313
+ scheduleDeletion: "workspaces/:workspaceId/schedule-deletion",
314
+ /** POST — undo a scheduled deletion within its grace period. */
315
+ restore: "workspaces/:workspaceId/restore",
316
+ /**
317
+ * PATCH — change a member's role. DELETE on the same path removes the member, with no body.
318
+ */
319
+ member: "workspaces/:workspaceId/members/:userId",
320
+ /** POST — leave the workspace. */
321
+ leave: "workspaces/:workspaceId/leave",
322
+ /** POST — hand ownership to another member, re-proving the caller. */
323
+ transferOwnership: "workspaces/:workspaceId/transfer-ownership",
324
+ /**
325
+ * POST — invite an address to the workspace (`controllers.workspaceInvitations: true`). GET on the
326
+ * same path lists the pending invitations.
327
+ */
328
+ invitations: "workspaces/:workspaceId/invitations",
329
+ /** POST — send a pending invitation again under a new token. */
330
+ resendInvitation: "workspaces/:workspaceId/invitations/resend",
331
+ /** POST — withdraw a pending invitation. */
332
+ revokeInvitation: "workspaces/:workspaceId/invitations/revoke",
333
+ /** POST — what a token is for, without signing in. Public. */
334
+ previewInvitation: "workspaces/invitations/preview",
335
+ /** POST — accept an invitation as the signed-in account it was addressed to. */
336
+ acceptInvitation: "workspaces/invitations/accept",
337
+ /** POST — accept an invitation by creating the account it was addressed to. Public. */
338
+ acceptInvitationSignup: "workspaces/invitations/accept-signup"
339
+ };
251
340
  var AUTH_ROUTES = {
252
341
  dashboard: AUTH_DASHBOARD_ROUTES,
253
342
  mfa: AUTH_MFA_ROUTES,
@@ -257,7 +346,8 @@ var AUTH_ROUTES = {
257
346
  sessions: AUTH_SESSION_ROUTES,
258
347
  invitations: AUTH_INVITATION_ROUTES,
259
348
  emailChange: AUTH_EMAIL_CHANGE_ROUTES,
260
- oauth: AUTH_OAUTH_ROUTES
349
+ oauth: AUTH_OAUTH_ROUTES,
350
+ workspaces: AUTH_WORKSPACE_ROUTES
261
351
  };
262
352
  var AUTH_PROXY_ROUTES = {
263
353
  /** POST — same-domain refresh entry point (server-to-server). */
@@ -309,14 +399,6 @@ var AUTH_REFRESH_SKIP_PROXY_PATHS = [
309
399
  "/api/auth/client-refresh",
310
400
  "/api/auth/silent-refresh"
311
401
  ];
312
- function trimSlashes(value) {
313
- let start = 0;
314
- let end = value.length;
315
- while (start < end && value[start] === "/") start += 1;
316
- while (end > start && value[end - 1] === "/") end -= 1;
317
- return value.slice(start, end);
318
- }
319
- __name(trimSlashes, "trimSlashes");
320
402
  function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
321
403
  const normalized = trimSlashes(routePrefix);
322
404
  const prefix = normalized.length > 0 ? `/${normalized}` : "";
@@ -325,23 +407,10 @@ function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
325
407
  ...AUTH_REFRESH_SKIP_PROXY_PATHS
326
408
  ];
327
409
  }
328
- __name(buildAuthRefreshSkipSuffixes, "buildAuthRefreshSkipSuffixes");
329
410
  var AUTH_REFRESH_SKIP_PATH_SUFFIXES = buildAuthRefreshSkipSuffixes();
330
411
 
331
412
  // src/shared/types/auth-error.types.ts
332
413
  var AuthClientError = class extends Error {
333
- static {
334
- __name(this, "AuthClientError");
335
- }
336
- /** The HTTP status code returned by the server. */
337
- status;
338
- /**
339
- * The stable machine-readable error code from `AUTH_ERROR_CODES`,
340
- * when the server provided one.
341
- */
342
- code;
343
- /** The full parsed error body, if the response carried JSON. */
344
- body;
345
414
  constructor(message, status, body) {
346
415
  super(message);
347
416
  this.name = "AuthClientError";
@@ -350,13 +419,13 @@ var AuthClientError = class extends Error {
350
419
  this.body = body;
351
420
  }
352
421
  /**
353
- * Strips potentially sensitive request echoes from structured-logger output.
354
- *
355
- * Some servers reflect submitted DTO fields inside `ValidationPipe` 400
356
- * responses; without this override, `JSON.stringify(error)` would persist
357
- * those fields verbatim into application logs. The serialized form keeps
358
- * only the fields a log consumer actually needs to triage an auth failure.
359
- */
422
+ * Strips potentially sensitive request echoes from structured-logger output.
423
+ *
424
+ * Some servers reflect submitted DTO fields inside `ValidationPipe` 400
425
+ * responses; without this override, `JSON.stringify(error)` would persist
426
+ * those fields verbatim into application logs. The serialized form keeps
427
+ * only the fields a log consumer actually needs to triage an auth failure.
428
+ */
360
429
  toJSON() {
361
430
  return {
362
431
  name: this.name,
@@ -367,4 +436,4 @@ var AuthClientError = class extends Error {
367
436
  }
368
437
  };
369
438
 
370
- export { AUTH_ACCESS_COOKIE_NAME, AUTH_DASHBOARD_ROUTES, AUTH_EMAIL_CHANGE_ROUTES, AUTH_ERROR_CODES, AUTH_ERROR_STATUS, AUTH_HAS_SESSION_COOKIE_NAME, AUTH_INVITATION_ROUTES, AUTH_MFA_ROUTES, AUTH_OAUTH_ROUTES, AUTH_PASSWORD_ROUTES, AUTH_PLATFORM_MFA_ROUTES, AUTH_PLATFORM_ROUTES, AUTH_PROXY_ROUTES, AUTH_REFRESH_COOKIE_NAME, AUTH_REFRESH_COOKIE_PATH, AUTH_REFRESH_SKIP_PATH_SUFFIXES, AUTH_ROUTES, AUTH_SESSION_ROUTES, AuthClientError, buildAuthRefreshSkipSuffixes };
439
+ export { AUTH_ACCESS_COOKIE_NAME, AUTH_DASHBOARD_ROUTES, AUTH_EMAIL_CHANGE_ROUTES, AUTH_ERROR_CODES, AUTH_ERROR_STATUS, AUTH_HAS_SESSION_COOKIE_NAME, AUTH_INVITATION_ROUTES, AUTH_MFA_ROUTES, AUTH_OAUTH_ROUTES, AUTH_PASSWORD_ROUTES, AUTH_PLATFORM_MFA_ROUTES, AUTH_PLATFORM_ROUTES, AUTH_PROXY_ROUTES, AUTH_REFRESH_COOKIE_NAME, AUTH_REFRESH_COOKIE_PATH, AUTH_REFRESH_SKIP_PATH_SUFFIXES, AUTH_ROUTES, AUTH_SESSION_ROUTES, AuthClientError, buildAuthRefreshSkipSuffixes, fillRoute, pathSegment, trimSlashes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-auth",
3
- "version": "1.4.22",
3
+ "version": "1.5.0",
4
4
  "description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",
@@ -78,12 +78,15 @@
78
78
  "check:api": "node scripts/check-api-surface.mjs",
79
79
  "check:exports": "node scripts/check-exports.mjs",
80
80
  "check:file-length": "node scripts/check-file-length.mjs",
81
+ "check:double-assertions": "node scripts/check-double-assertions.mjs",
82
+ "check:function-length": "node scripts/check-function-length.mjs",
81
83
  "mutate:tables": "node scripts/mutate-const-tables.mjs -- pnpm exec jest --config jest.mutants.config.ts --findRelatedTests {file} --coverage=false --silent --bail=1",
82
84
  "check:published": "node scripts/check-published-surface.mjs",
83
85
  "check:runtime": "node scripts/check-consumer-runtime.mjs",
84
86
  "clean": "rm -rf dist coverage",
85
87
  "format": "prettier --write .",
86
88
  "gen:openapi-schemas": "UPDATE_OPENAPI_SCHEMAS=1 jest src/server/openapi/request-schemas.conformance.spec.ts",
89
+ "gen:openapi-security": "UPDATE_OPENAPI_SECURITY=1 jest src/server/openapi/operation-security.conformance.spec.ts",
87
90
  "format:check": "prettier --check .",
88
91
  "lint": "eslint src",
89
92
  "lint:fix": "eslint src --fix",
@@ -190,7 +193,7 @@
190
193
  "@stryker-mutator/core": "^10.0.0",
191
194
  "@stryker-mutator/jest-runner": "^10.0.0",
192
195
  "@stryker-mutator/typescript-checker": "^10.0.0",
193
- "@swc/core": "1.16.21",
196
+ "@swc/core": "1.16.22",
194
197
  "@testing-library/react": "^16.3.2",
195
198
  "@types/express": "^5.0.6",
196
199
  "@types/jest": "^30.0.0",
@@ -203,6 +206,7 @@
203
206
  "@typescript-eslint/parser": "^8.59.3",
204
207
  "class-transformer": "^0.5.1",
205
208
  "class-validator": "^0.15.1",
209
+ "esbuild": "0.28.2",
206
210
  "eslint": "^9.39.4",
207
211
  "eslint-config-prettier": "^10.1.8",
208
212
  "eslint-import-resolver-typescript": "^4.4.4",