@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.
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
-
6
3
  // src/shared/constants/cookie-defaults.ts
7
4
  var AUTH_ACCESS_COOKIE_NAME = "access_token";
8
5
  var AUTH_REFRESH_COOKIE_NAME = "refresh_token";
@@ -20,7 +17,7 @@ var AUTH_ERROR_CODES = {
20
17
  PENDING_APPROVAL: "auth.pending_approval",
21
18
  // Tokens and sessions
22
19
  /** Internal-only: expiry. Never on the wire — collapsed onto TOKEN_INVALID, to deny an oracle
23
- * separating a token that WAS valid from one that never was. */
20
+ * separating a token that WAS valid from one that never was. */
24
21
  TOKEN_EXPIRED: "auth.token_expired",
25
22
  /** Internal-only: logout or epoch bump. Never on the wire — see TOKEN_EXPIRED. */
26
23
  TOKEN_REVOKED: "auth.token_revoked",
@@ -48,11 +45,11 @@ var AUTH_ERROR_CODES = {
48
45
  PASSWORD_RESET_TOKEN_INVALID: "auth.password_reset_token_invalid",
49
46
  // OTP (email verification, password reset via OTP)
50
47
  /**
51
- * The only code an OTP failure reaches a client with. A wrong code, a record that is not in
52
- * Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
53
- * answers the same whether or not the address exists, but only writes an OTP record when it
54
- * does, so telling them apart made that uniform answer definitive after one extra request.
55
- */
48
+ * The only code an OTP failure reaches a client with. A wrong code, a record that is not in
49
+ * Redis, and an exhausted attempt ceiling are deliberately indistinguishable: `forgot-password`
50
+ * answers the same whether or not the address exists, but only writes an OTP record when it
51
+ * does, so telling them apart made that uniform answer definitive after one extra request.
52
+ */
56
53
  OTP_INVALID: "auth.otp_invalid",
57
54
  /** Internal-only: the OTP record was absent. Never on the wire — see {@link OTP_INVALID}. */
58
55
  OTP_EXPIRED: "auth.otp_expired",
@@ -62,21 +59,21 @@ var AUTH_ERROR_CODES = {
62
59
  INSUFFICIENT_ROLE: "auth.insufficient_role",
63
60
  FORBIDDEN: "auth.forbidden",
64
61
  /**
65
- * The request body or query failed DTO validation. Per-field failures serialize into
66
- * `error.details` as `[{ field, message }]`.
67
- */
62
+ * The request body or query failed DTO validation. Per-field failures serialize into
63
+ * `error.details` as `[{ field, message }]`.
64
+ */
68
65
  VALIDATION: "auth.validation",
69
66
  /** The caller exceeded a per-IP rate limit on an auth route. */
70
67
  TOO_MANY_REQUESTS: "auth.too_many_requests",
71
68
  /**
72
- * A state-changing request carrying the session cookie came from an origin the deployment
73
- * does not trust.
74
- */
69
+ * A state-changing request carrying the session cookie came from an origin the deployment
70
+ * does not trust.
71
+ */
75
72
  UNTRUSTED_ORIGIN: "auth.untrusted_origin",
76
73
  /**
77
- * A change to how the account authenticates was attempted without a recent authentication.
78
- * The client should send the user back through sign-in and retry.
79
- */
74
+ * A change to how the account authenticates was attempted without a recent authentication.
75
+ * The client should send the user back through sign-in and retry.
76
+ */
80
77
  REAUTHENTICATION_REQUIRED: "auth.reauthentication_required",
81
78
  // Invitations
82
79
  INVALID_INVITATION_TOKEN: "auth.invalid_invitation_token",
@@ -89,10 +86,20 @@ var AUTH_ERROR_CODES = {
89
86
  API_KEY_INVALID: "auth.api_key_invalid",
90
87
  API_KEY_SCOPE_INSUFFICIENT: "auth.api_key_scope_insufficient",
91
88
  API_KEY_NOT_FOUND: "auth.api_key_not_found",
89
+ // Workspaces
90
+ WORKSPACE_REQUIRED: "auth.workspace_required",
91
+ WORKSPACE_NOT_FOUND: "auth.workspace_not_found",
92
+ INSUFFICIENT_WORKSPACE_ROLE: "auth.insufficient_workspace_role",
93
+ LAST_OWNER: "auth.last_owner",
94
+ ALREADY_MEMBER: "auth.already_member",
95
+ INVITATION_EMAIL_MISMATCH: "auth.invitation_email_mismatch",
96
+ REGISTRATION_CLOSED: "auth.registration_closed",
97
+ WORKSPACE_LIMIT_REACHED: "auth.workspace_limit_reached",
98
+ WORKSPACE_PENDING_DELETION: "auth.workspace_pending_deletion",
92
99
  /**
93
- * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
94
- * which gives unhandled failures the same envelope everything else answers with.
95
- */
100
+ * An unexpected internal failure. Raised only by the server's optional `AuthExceptionFilter`,
101
+ * which gives unhandled failures the same envelope everything else answers with.
102
+ */
96
103
  INTERNAL: "auth.internal"
97
104
  };
98
105
  var AUTH_ERROR_STATUS = {
@@ -136,9 +143,44 @@ var AUTH_ERROR_STATUS = {
136
143
  "auth.api_key_invalid": 401,
137
144
  "auth.api_key_scope_insufficient": 403,
138
145
  "auth.api_key_not_found": 404,
146
+ "auth.workspace_required": 400,
147
+ "auth.workspace_not_found": 404,
148
+ "auth.insufficient_workspace_role": 403,
149
+ "auth.last_owner": 409,
150
+ "auth.already_member": 409,
151
+ "auth.invitation_email_mismatch": 403,
152
+ "auth.registration_closed": 403,
153
+ "auth.workspace_limit_reached": 403,
154
+ "auth.workspace_pending_deletion": 409,
139
155
  "auth.internal": 500
140
156
  };
141
157
 
158
+ // src/shared/utils/fill-route.ts
159
+ function pathSegment(name, value) {
160
+ if (typeof value !== "string" || value === "") {
161
+ throw new TypeError(`${name} must be a non-empty string`);
162
+ }
163
+ if (value === "." || value === "..") throw new TypeError(`${name} must not be '.' or '..'`);
164
+ return encodeURIComponent(value);
165
+ }
166
+ function fillRoute(template, values) {
167
+ return template.replace(
168
+ /:([A-Za-z]+)/g,
169
+ (_match, name) => pathSegment(name, Object.entries(values).find(([key]) => key === name)?.[1])
170
+ );
171
+ }
172
+
173
+ // src/shared/utils/trim-slashes.ts
174
+ function trimSlashes(value, leading = true) {
175
+ let start = 0;
176
+ let end = value.length;
177
+ if (leading) {
178
+ while (start < end && value[start] === "/") start += 1;
179
+ }
180
+ while (end > start && value[end - 1] === "/") end -= 1;
181
+ return value.slice(start, end);
182
+ }
183
+
142
184
  // src/shared/constants/routes.ts
143
185
  var AUTH_DASHBOARD_ROUTES = {
144
186
  /** POST — register a new local (email + password) user. */
@@ -176,11 +218,11 @@ var AUTH_PASSWORD_ROUTES = {
176
218
  /** POST — submit a new password using the reset token. */
177
219
  resetPassword: "password/reset-password",
178
220
  /**
179
- * POST — change the password of the signed-in user, verifying the current one.
180
- *
181
- * The only route in this family behind the JWT guard: the rest are reached by a
182
- * caller who has no session, which is what a reset is for.
183
- */
221
+ * POST — change the password of the signed-in user, verifying the current one.
222
+ *
223
+ * The only route in this family behind the JWT guard: the rest are reached by a
224
+ * caller who has no session, which is what a reset is for.
225
+ */
184
226
  changePassword: "password/change",
185
227
  /** POST — verify the reset OTP (when `passwordReset.method = 'otp'`). */
186
228
  verifyOtp: "password/verify-otp",
@@ -215,19 +257,19 @@ var AUTH_SESSION_ROUTES = {
215
257
  /** GET — list every active session for the current user. */
216
258
  list: "sessions",
217
259
  /**
218
- * POST — revoke every session belonging to the current user except the one
219
- * making the call.
220
- *
221
- * POST rather than DELETE because the refresh token that names the current
222
- * session travels in the body under `tokenDelivery: 'bearer'`, and OpenAPI 3.0.3
223
- * defers to RFC 7231: a payload on DELETE has no defined semantics, so a
224
- * generated client drops it.
225
- */
260
+ * POST — revoke every session belonging to the current user except the one
261
+ * making the call.
262
+ *
263
+ * POST rather than DELETE because the refresh token that names the current
264
+ * session travels in the body under `tokenDelivery: 'bearer'`, and OpenAPI 3.0.3
265
+ * defers to RFC 7231: a payload on DELETE has no defined semantics, so a
266
+ * generated client drops it.
267
+ */
226
268
  revokeAll: "sessions/revoke-all",
227
269
  /**
228
- * DELETE — revoke a single session by id. The `:id` placeholder must be
229
- * substituted with the session identifier before the request is issued.
230
- */
270
+ * DELETE — revoke a single session by id. The `:id` placeholder must be
271
+ * substituted with the session identifier before the request is issued.
272
+ */
231
273
  revokeOne: "sessions/:id"
232
274
  };
233
275
  var AUTH_EMAIL_CHANGE_ROUTES = {
@@ -250,6 +292,53 @@ var AUTH_OAUTH_ROUTES = {
250
292
  /** GET — the provider redirects back here with the authorization code. */
251
293
  callback: "oauth/:provider/callback"
252
294
  };
295
+ var AUTH_WORKSPACE_ROUTES = {
296
+ /**
297
+ * GET — the caller's own active memberships and the workspace they last switched to. POST on the
298
+ * same path creates a workspace.
299
+ */
300
+ list: "workspaces",
301
+ /** GET — the workspace and the caller's role in it. */
302
+ access: "workspaces/:workspaceId/access",
303
+ /** POST — record the workspace as the caller's last active one. */
304
+ switch: "workspaces/:workspaceId/switch",
305
+ /** GET — the members of the workspace. */
306
+ members: "workspaces/:workspaceId/members",
307
+ /** PATCH — rename the workspace. */
308
+ rename: "workspaces/:workspaceId",
309
+ /**
310
+ * POST — schedule the workspace for deletion, re-proving the caller.
311
+ *
312
+ * POST rather than DELETE because the password travels in the body, and a payload on DELETE has
313
+ * no defined semantics (RFC 9110), so an intermediary or a generated client may drop it.
314
+ */
315
+ scheduleDeletion: "workspaces/:workspaceId/schedule-deletion",
316
+ /** POST — undo a scheduled deletion within its grace period. */
317
+ restore: "workspaces/:workspaceId/restore",
318
+ /**
319
+ * PATCH — change a member's role. DELETE on the same path removes the member, with no body.
320
+ */
321
+ member: "workspaces/:workspaceId/members/:userId",
322
+ /** POST — leave the workspace. */
323
+ leave: "workspaces/:workspaceId/leave",
324
+ /** POST — hand ownership to another member, re-proving the caller. */
325
+ transferOwnership: "workspaces/:workspaceId/transfer-ownership",
326
+ /**
327
+ * POST — invite an address to the workspace (`controllers.workspaceInvitations: true`). GET on the
328
+ * same path lists the pending invitations.
329
+ */
330
+ invitations: "workspaces/:workspaceId/invitations",
331
+ /** POST — send a pending invitation again under a new token. */
332
+ resendInvitation: "workspaces/:workspaceId/invitations/resend",
333
+ /** POST — withdraw a pending invitation. */
334
+ revokeInvitation: "workspaces/:workspaceId/invitations/revoke",
335
+ /** POST — what a token is for, without signing in. Public. */
336
+ previewInvitation: "workspaces/invitations/preview",
337
+ /** POST — accept an invitation as the signed-in account it was addressed to. */
338
+ acceptInvitation: "workspaces/invitations/accept",
339
+ /** POST — accept an invitation by creating the account it was addressed to. Public. */
340
+ acceptInvitationSignup: "workspaces/invitations/accept-signup"
341
+ };
253
342
  var AUTH_ROUTES = {
254
343
  dashboard: AUTH_DASHBOARD_ROUTES,
255
344
  mfa: AUTH_MFA_ROUTES,
@@ -259,7 +348,8 @@ var AUTH_ROUTES = {
259
348
  sessions: AUTH_SESSION_ROUTES,
260
349
  invitations: AUTH_INVITATION_ROUTES,
261
350
  emailChange: AUTH_EMAIL_CHANGE_ROUTES,
262
- oauth: AUTH_OAUTH_ROUTES
351
+ oauth: AUTH_OAUTH_ROUTES,
352
+ workspaces: AUTH_WORKSPACE_ROUTES
263
353
  };
264
354
  var AUTH_PROXY_ROUTES = {
265
355
  /** POST — same-domain refresh entry point (server-to-server). */
@@ -311,14 +401,6 @@ var AUTH_REFRESH_SKIP_PROXY_PATHS = [
311
401
  "/api/auth/client-refresh",
312
402
  "/api/auth/silent-refresh"
313
403
  ];
314
- function trimSlashes(value) {
315
- let start = 0;
316
- let end = value.length;
317
- while (start < end && value[start] === "/") start += 1;
318
- while (end > start && value[end - 1] === "/") end -= 1;
319
- return value.slice(start, end);
320
- }
321
- __name(trimSlashes, "trimSlashes");
322
404
  function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
323
405
  const normalized = trimSlashes(routePrefix);
324
406
  const prefix = normalized.length > 0 ? `/${normalized}` : "";
@@ -327,23 +409,10 @@ function buildAuthRefreshSkipSuffixes(routePrefix = "auth") {
327
409
  ...AUTH_REFRESH_SKIP_PROXY_PATHS
328
410
  ];
329
411
  }
330
- __name(buildAuthRefreshSkipSuffixes, "buildAuthRefreshSkipSuffixes");
331
412
  var AUTH_REFRESH_SKIP_PATH_SUFFIXES = buildAuthRefreshSkipSuffixes();
332
413
 
333
414
  // src/shared/types/auth-error.types.ts
334
415
  var AuthClientError = class extends Error {
335
- static {
336
- __name(this, "AuthClientError");
337
- }
338
- /** The HTTP status code returned by the server. */
339
- status;
340
- /**
341
- * The stable machine-readable error code from `AUTH_ERROR_CODES`,
342
- * when the server provided one.
343
- */
344
- code;
345
- /** The full parsed error body, if the response carried JSON. */
346
- body;
347
416
  constructor(message, status, body) {
348
417
  super(message);
349
418
  this.name = "AuthClientError";
@@ -352,13 +421,13 @@ var AuthClientError = class extends Error {
352
421
  this.body = body;
353
422
  }
354
423
  /**
355
- * Strips potentially sensitive request echoes from structured-logger output.
356
- *
357
- * Some servers reflect submitted DTO fields inside `ValidationPipe` 400
358
- * responses; without this override, `JSON.stringify(error)` would persist
359
- * those fields verbatim into application logs. The serialized form keeps
360
- * only the fields a log consumer actually needs to triage an auth failure.
361
- */
424
+ * Strips potentially sensitive request echoes from structured-logger output.
425
+ *
426
+ * Some servers reflect submitted DTO fields inside `ValidationPipe` 400
427
+ * responses; without this override, `JSON.stringify(error)` would persist
428
+ * those fields verbatim into application logs. The serialized form keeps
429
+ * only the fields a log consumer actually needs to triage an auth failure.
430
+ */
362
431
  toJSON() {
363
432
  return {
364
433
  name: this.name,
@@ -389,3 +458,6 @@ exports.AUTH_ROUTES = AUTH_ROUTES;
389
458
  exports.AUTH_SESSION_ROUTES = AUTH_SESSION_ROUTES;
390
459
  exports.AuthClientError = AuthClientError;
391
460
  exports.buildAuthRefreshSkipSuffixes = buildAuthRefreshSkipSuffixes;
461
+ exports.fillRoute = fillRoute;
462
+ exports.pathSegment = pathSegment;
463
+ exports.trimSlashes = trimSlashes;
@@ -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 };