@shipfox/api-auth 9.2.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +56 -0
  3. package/README.md +32 -8
  4. package/dist/config.d.ts +1 -0
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +4 -0
  7. package/dist/config.js.map +1 -1
  8. package/dist/core/administration.d.ts +43 -0
  9. package/dist/core/administration.d.ts.map +1 -0
  10. package/dist/core/administration.js +152 -0
  11. package/dist/core/administration.js.map +1 -0
  12. package/dist/core/auth.d.ts.map +1 -1
  13. package/dist/core/auth.js +2 -5
  14. package/dist/core/auth.js.map +1 -1
  15. package/dist/core/entities/administrator-read-model.d.ts +21 -0
  16. package/dist/core/entities/administrator-read-model.d.ts.map +1 -0
  17. package/dist/core/entities/administrator-read-model.js +3 -0
  18. package/dist/core/entities/administrator-read-model.js.map +1 -0
  19. package/dist/core/errors.d.ts +15 -0
  20. package/dist/core/errors.d.ts.map +1 -1
  21. package/dist/core/errors.js +30 -0
  22. package/dist/core/errors.js.map +1 -1
  23. package/dist/db/admin-grants.d.ts +34 -1
  24. package/dist/db/admin-grants.d.ts.map +1 -1
  25. package/dist/db/admin-grants.js +177 -5
  26. package/dist/db/admin-grants.js.map +1 -1
  27. package/dist/db/admin-users.d.ts +21 -0
  28. package/dist/db/admin-users.d.ts.map +1 -0
  29. package/dist/db/admin-users.js +32 -0
  30. package/dist/db/admin-users.js.map +1 -0
  31. package/dist/db/db.d.ts +256 -0
  32. package/dist/db/db.d.ts.map +1 -1
  33. package/dist/db/db.js +2 -0
  34. package/dist/db/db.js.map +1 -1
  35. package/dist/db/schema/admin-command-results.d.ts +142 -0
  36. package/dist/db/schema/admin-command-results.d.ts.map +1 -0
  37. package/dist/db/schema/admin-command-results.js +21 -0
  38. package/dist/db/schema/admin-command-results.js.map +1 -0
  39. package/dist/index.d.ts +2 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +12 -3
  42. package/dist/index.js.map +1 -1
  43. package/dist/metrics/instance.d.ts +1 -1
  44. package/dist/metrics/instance.d.ts.map +1 -1
  45. package/dist/metrics/instance.js.map +1 -1
  46. package/dist/presentation/routes/administration.d.ts +4 -0
  47. package/dist/presentation/routes/administration.d.ts.map +1 -0
  48. package/dist/presentation/routes/administration.js +267 -0
  49. package/dist/presentation/routes/administration.js.map +1 -0
  50. package/dist/presentation/routes/rate-limit.d.ts +1 -0
  51. package/dist/presentation/routes/rate-limit.d.ts.map +1 -1
  52. package/dist/presentation/routes/rate-limit.js +26 -1
  53. package/dist/presentation/routes/rate-limit.js.map +1 -1
  54. package/dist/tsconfig.test.tsbuildinfo +1 -1
  55. package/drizzle/0002_burly_whizzer.sql +12 -0
  56. package/drizzle/meta/0002_snapshot.json +791 -0
  57. package/drizzle/meta/_journal.json +7 -0
  58. package/package.json +10 -9
  59. package/src/config.ts +4 -0
  60. package/src/core/administration.ts +213 -0
  61. package/src/core/auth-default-signup-policy.test.ts +65 -0
  62. package/src/core/auth.test.ts +5 -0
  63. package/src/core/auth.ts +2 -3
  64. package/src/core/entities/administrator-read-model.ts +23 -0
  65. package/src/core/errors.ts +35 -0
  66. package/src/db/admin-grants.test.ts +1 -7
  67. package/src/db/admin-grants.ts +310 -5
  68. package/src/db/admin-users.ts +58 -0
  69. package/src/db/db.ts +2 -0
  70. package/src/db/schema/admin-command-results.ts +41 -0
  71. package/src/index.test.ts +6 -2
  72. package/src/index.ts +23 -2
  73. package/src/metrics/instance.ts +1 -1
  74. package/src/presentation/auth/refresh-cookie.test.ts +4 -0
  75. package/src/presentation/e2eRoutes/index.test.ts +1 -0
  76. package/src/presentation/routes/administration.test.ts +537 -0
  77. package/src/presentation/routes/administration.ts +276 -0
  78. package/src/presentation/routes/index.test.ts +1 -0
  79. package/src/presentation/routes/rate-limit.ts +26 -2
  80. package/test/globalSetup.ts +6 -2
  81. package/test/routes.ts +10 -1
  82. package/tsconfig.build.tsbuildinfo +1 -1
@@ -15,6 +15,13 @@
15
15
  "when": 1785065259979,
16
16
  "tag": "0001_brainy_shriek",
17
17
  "breakpoints": true
18
+ },
19
+ {
20
+ "idx": 2,
21
+ "version": "7",
22
+ "when": 1785075183023,
23
+ "tag": "0002_burly_whizzer",
24
+ "breakpoints": true
18
25
  }
19
26
  ]
20
27
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipfox/api-auth",
3
3
  "license": "MIT",
4
- "version": "9.2.0",
4
+ "version": "10.0.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -26,20 +26,21 @@
26
26
  "@node-rs/argon2": "^2.0.2",
27
27
  "drizzle-orm": "^0.45.2",
28
28
  "zod": "^4.4.3",
29
- "@shipfox/api-auth-context": "9.2.0",
30
- "@shipfox/api-auth-dto": "9.2.0",
31
- "@shipfox/api-email-challenges": "1.1.4",
32
- "@shipfox/api-workspaces-dto": "9.2.0",
29
+ "@shipfox/api-common-dto": "9.2.0",
30
+ "@shipfox/api-auth-context": "10.0.0",
31
+ "@shipfox/api-auth-dto": "10.0.0",
32
+ "@shipfox/api-email-challenges": "1.1.6",
33
+ "@shipfox/api-workspaces-dto": "10.0.0",
33
34
  "@shipfox/inter-module": "0.2.2",
34
35
  "@shipfox/config": "1.2.4",
35
36
  "@shipfox/node-drizzle": "0.3.4",
36
37
  "@shipfox/node-auth-root-key": "0.2.3",
37
- "@shipfox/node-fastify": "0.3.3",
38
+ "@shipfox/node-fastify": "0.4.0",
38
39
  "@shipfox/node-jwt": "0.3.2",
39
40
  "@shipfox/node-email": "0.3.4",
40
- "@shipfox/node-mailer": "0.2.3",
41
- "@shipfox/node-module": "1.0.2",
42
- "@shipfox/node-opentelemetry": "0.6.2",
41
+ "@shipfox/node-mailer": "0.2.4",
42
+ "@shipfox/node-module": "1.0.4",
43
+ "@shipfox/node-opentelemetry": "0.6.3",
43
44
  "@shipfox/node-outbox": "0.2.6",
44
45
  "@shipfox/node-postgres": "0.4.4",
45
46
  "@shipfox/node-rate-limit": "0.3.2",
package/src/config.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import {bool, createConfig, num, str} from '@shipfox/config';
2
2
 
3
3
  export const config = createConfig({
4
+ ADMIN_BOOTSTRAP_TOKEN: str({
5
+ desc: 'Deployment secret accepted once to create the first administrator owner. Set it before bootstrap and remove or rotate it after successful bootstrap.',
6
+ default: undefined,
7
+ }),
4
8
  AUTH_JWT_EXPIRES_IN: str({
5
9
  desc: 'How long an access token stays valid. Accepts a duration string such as 15m, 1h, or 7d.',
6
10
  default: '15m',
@@ -0,0 +1,213 @@
1
+ import {createHash, timingSafeEqual} from 'node:crypto';
2
+ import type {AdminRole} from '@shipfox/api-auth-dto';
3
+ import {createAdministrationActionEvent} from '@shipfox/api-common-dto';
4
+ import type {TimestampIdCursor} from '@shipfox/node-drizzle';
5
+ import {config} from '#config.js';
6
+ import {
7
+ bootstrapFirstAdminOwner as bootstrapFirstAdminOwnerInDb,
8
+ grantAdminRoleWithAudit,
9
+ listAdminGrantSummaries,
10
+ revokeAdminGrantWithAudit,
11
+ } from '#db/admin-grants.js';
12
+ import {findAdministratorUser as findAdministratorUserInDb} from '#db/admin-users.js';
13
+ import {requireAdminRole} from './admin-role.js';
14
+ import type {AdminGrant} from './entities/admin-grant.js';
15
+ import type {
16
+ AdministratorGrantSummary,
17
+ AdministratorUserSummary,
18
+ } from './entities/administrator-read-model.js';
19
+ import {
20
+ AdminBootstrapClosedError,
21
+ AdminGrantAlreadyExistsError,
22
+ AdminGrantNotFoundError,
23
+ AdminIdempotencyKeyReuseError,
24
+ InvalidAdminBootstrapTokenError,
25
+ LastAdminOwnerError,
26
+ UserNotFoundError,
27
+ } from './errors.js';
28
+
29
+ const ADMIN_OWNER_ROLE: AdminRole = 'admin-owner';
30
+ const ADMIN_OBSERVER_ROLE: AdminRole = 'admin-observer';
31
+ const BOOTSTRAP_COMMAND = 'auth.admin_grant.bootstrap';
32
+ const GRANT_COMMAND = 'auth.admin_grant.grant';
33
+ const REVOKE_COMMAND = 'auth.admin_grant.revoke';
34
+
35
+ export function hashAdministrationValue(value: string): string {
36
+ return createHash('sha256').update(value).digest('hex');
37
+ }
38
+
39
+ export function administrationCommandFingerprint(command: string, input: unknown): string {
40
+ return hashAdministrationValue(`${command}:${JSON.stringify(input)}`);
41
+ }
42
+
43
+ function bootstrapTokenMatches(candidate: string, expected: string | undefined): boolean {
44
+ if (!expected) return false;
45
+ const candidateHash = Buffer.from(hashAdministrationValue(candidate), 'hex');
46
+ const expectedHash = Buffer.from(hashAdministrationValue(expected), 'hex');
47
+ return timingSafeEqual(candidateHash, expectedHash);
48
+ }
49
+
50
+ function administrationEvent(params: {
51
+ actorId: string;
52
+ actorRole: AdminRole;
53
+ command: string;
54
+ targetType: string;
55
+ targetId: string;
56
+ reason: string;
57
+ correlationId: string;
58
+ idempotencyKeyFingerprint: string;
59
+ }) {
60
+ return createAdministrationActionEvent({
61
+ actorId: params.actorId,
62
+ actorRole: params.actorRole,
63
+ requiredRole: ADMIN_OWNER_ROLE,
64
+ command: params.command,
65
+ targetType: params.targetType,
66
+ targetId: params.targetId,
67
+ reason: params.reason,
68
+ result: 'succeeded',
69
+ correlationId: params.correlationId,
70
+ idempotencyKeyFingerprint: params.idempotencyKeyFingerprint,
71
+ occurredAt: new Date().toISOString(),
72
+ });
73
+ }
74
+
75
+ export interface AdministrationMutationContext {
76
+ actorId: string;
77
+ idempotencyKey: string;
78
+ correlationId: string;
79
+ }
80
+
81
+ export async function bootstrapFirstAdminOwner(
82
+ params: AdministrationMutationContext & {bootstrapToken: string},
83
+ ): Promise<AdminGrant> {
84
+ if (!bootstrapTokenMatches(params.bootstrapToken, config.ADMIN_BOOTSTRAP_TOKEN)) {
85
+ throw new InvalidAdminBootstrapTokenError();
86
+ }
87
+
88
+ return await bootstrapFirstAdminOwnerInDb({
89
+ userId: params.actorId,
90
+ actorId: params.actorId,
91
+ idempotencyKeyFingerprint: hashAdministrationValue(params.idempotencyKey),
92
+ requestFingerprint: administrationCommandFingerprint(BOOTSTRAP_COMMAND, {
93
+ actorId: params.actorId,
94
+ }),
95
+ event: administrationEvent({
96
+ actorId: params.actorId,
97
+ actorRole: ADMIN_OWNER_ROLE,
98
+ command: BOOTSTRAP_COMMAND,
99
+ targetType: 'user',
100
+ targetId: params.actorId,
101
+ reason: 'Initial administrator owner bootstrap',
102
+ correlationId: params.correlationId,
103
+ idempotencyKeyFingerprint: hashAdministrationValue(params.idempotencyKey),
104
+ }),
105
+ });
106
+ }
107
+
108
+ export async function findAdministratorUserSummary(
109
+ params: {actorId: string} & ({id: string; email?: never} | {email: string; id?: never}),
110
+ ): Promise<AdministratorUserSummary | undefined> {
111
+ await requireAdminRole({userId: params.actorId, minimumRole: ADMIN_OBSERVER_ROLE});
112
+
113
+ const user = await findAdministratorUserInDb(
114
+ 'id' in params ? {id: params.id} : {email: params.email},
115
+ );
116
+ if (!user) return undefined;
117
+
118
+ return user;
119
+ }
120
+
121
+ export async function listAdministratorGrantSummaries(params: {
122
+ actorId: string;
123
+ limit: number;
124
+ cursor?: TimestampIdCursor;
125
+ }): Promise<{
126
+ grants: AdministratorGrantSummary[];
127
+ nextCursor: TimestampIdCursor | null;
128
+ }> {
129
+ await requireAdminRole({userId: params.actorId, minimumRole: ADMIN_OBSERVER_ROLE});
130
+
131
+ const result = await listAdminGrantSummaries({
132
+ limit: params.limit,
133
+ ...(params.cursor ? {cursor: params.cursor} : {}),
134
+ });
135
+ return {
136
+ grants: result.rows.map((row) => ({
137
+ grantId: row.id,
138
+ role: row.role,
139
+ createdAt: row.createdAt,
140
+ revokedAt: row.revokedAt,
141
+ user: row.user,
142
+ })),
143
+ nextCursor: result.nextCursor,
144
+ };
145
+ }
146
+
147
+ export async function grantAdministratorRole(
148
+ params: AdministrationMutationContext & {userId: string; role: AdminRole; reason: string},
149
+ ): Promise<AdminGrant> {
150
+ const actorRole = await requireAdminRole({
151
+ userId: params.actorId,
152
+ minimumRole: ADMIN_OWNER_ROLE,
153
+ });
154
+ return await grantAdminRoleWithAudit({
155
+ userId: params.userId,
156
+ role: params.role,
157
+ actorId: params.actorId,
158
+ idempotencyKeyFingerprint: hashAdministrationValue(params.idempotencyKey),
159
+ requestFingerprint: administrationCommandFingerprint(GRANT_COMMAND, {
160
+ userId: params.userId,
161
+ role: params.role,
162
+ reason: params.reason,
163
+ }),
164
+ event: administrationEvent({
165
+ actorId: params.actorId,
166
+ actorRole,
167
+ command: GRANT_COMMAND,
168
+ targetType: 'user',
169
+ targetId: params.userId,
170
+ reason: params.reason,
171
+ correlationId: params.correlationId,
172
+ idempotencyKeyFingerprint: hashAdministrationValue(params.idempotencyKey),
173
+ }),
174
+ });
175
+ }
176
+
177
+ export async function revokeAdministratorGrant(
178
+ params: AdministrationMutationContext & {grantId: string; reason: string},
179
+ ): Promise<AdminGrant> {
180
+ const actorRole = await requireAdminRole({
181
+ userId: params.actorId,
182
+ minimumRole: ADMIN_OWNER_ROLE,
183
+ });
184
+ return await revokeAdminGrantWithAudit({
185
+ grantId: params.grantId,
186
+ actorId: params.actorId,
187
+ idempotencyKeyFingerprint: hashAdministrationValue(params.idempotencyKey),
188
+ requestFingerprint: administrationCommandFingerprint(REVOKE_COMMAND, {
189
+ grantId: params.grantId,
190
+ reason: params.reason,
191
+ }),
192
+ event: administrationEvent({
193
+ actorId: params.actorId,
194
+ actorRole,
195
+ command: REVOKE_COMMAND,
196
+ targetType: 'admin-grant',
197
+ targetId: params.grantId,
198
+ reason: params.reason,
199
+ correlationId: params.correlationId,
200
+ idempotencyKeyFingerprint: hashAdministrationValue(params.idempotencyKey),
201
+ }),
202
+ });
203
+ }
204
+
205
+ export {
206
+ AdminBootstrapClosedError,
207
+ AdminGrantAlreadyExistsError,
208
+ AdminGrantNotFoundError,
209
+ AdminIdempotencyKeyReuseError,
210
+ InvalidAdminBootstrapTokenError,
211
+ LastAdminOwnerError,
212
+ UserNotFoundError,
213
+ };
@@ -0,0 +1,65 @@
1
+ import {provisionUser, signup} from '#core/auth.js';
2
+
3
+ const testConfig = vi.hoisted(() => ({
4
+ AUTH_JWT_EXPIRES_IN: '15m',
5
+ AUTH_REFRESH_TOKEN_EXPIRES_IN_DAYS: 14,
6
+ AUTH_REFRESH_ROTATION_GRACE_SECONDS: 30,
7
+ AUTH_REFRESH_COOKIE_NAME: 'shipfox_refresh_token',
8
+ AUTH_SIGNUP_GATE_ENABLED: true,
9
+ AUTH_SIGNUP_ALLOWED_EMAIL_DOMAINS: 'allowed.example',
10
+ AUTH_SIGNUP_ALLOWED_EMAILS: '',
11
+ AUTH_SIGNUP_NOT_ALLOWED_MESSAGE: undefined as string | undefined,
12
+ CLIENT_BASE_URL: 'https://app.example.test',
13
+ }));
14
+
15
+ vi.mock('#config.js', () => ({config: testConfig}));
16
+
17
+ describe('low-level account creation defaults', () => {
18
+ test('signup uses the environment policy when no policy is supplied', async () => {
19
+ const email = `signup-default-${crypto.randomUUID()}@allowed.example`;
20
+
21
+ const user = await signup({email, password: 'correct horse battery staple'});
22
+
23
+ expect(user.email).toBe(email);
24
+ });
25
+
26
+ test('signup rejects an unlisted email when no policy is supplied', async () => {
27
+ const email = `signup-default-${crypto.randomUUID()}@blocked.example`;
28
+
29
+ await expect(signup({email, password: 'correct horse battery staple'})).rejects.toMatchObject({
30
+ name: 'SignupNotAllowedError',
31
+ });
32
+ });
33
+
34
+ test('provisionUser uses the environment policy when no policy is supplied', async () => {
35
+ const email = `provision-default-${crypto.randomUUID()}@allowed.example`;
36
+
37
+ const user = await provisionUser({email});
38
+
39
+ expect(user.email).toBe(email);
40
+ });
41
+
42
+ test('provisionUser rejects an unlisted email when no policy is supplied', async () => {
43
+ const email = `provision-default-${crypto.randomUUID()}@blocked.example`;
44
+
45
+ await expect(provisionUser({email})).rejects.toMatchObject({
46
+ name: 'SignupNotAllowedError',
47
+ });
48
+ });
49
+
50
+ test('an explicit policy overrides the environment policy for both paths', async () => {
51
+ const signupEmail = `signup-override-${crypto.randomUUID()}@blocked.example`;
52
+ const provisionEmail = `provision-override-${crypto.randomUUID()}@blocked.example`;
53
+ const isSignupAllowed = vi.fn().mockResolvedValue({allowed: true});
54
+ const signupPolicy = {isSignupAllowed};
55
+
56
+ await signup({
57
+ email: signupEmail,
58
+ password: 'correct horse battery staple',
59
+ signupPolicy,
60
+ });
61
+ await provisionUser({email: provisionEmail, signupPolicy});
62
+
63
+ expect(isSignupAllowed).toHaveBeenCalledTimes(2);
64
+ });
65
+ });
@@ -61,6 +61,10 @@ vi.mock('#config.js', () => ({
61
61
  AUTH_REFRESH_TOKEN_EXPIRES_IN_DAYS: 14,
62
62
  AUTH_REFRESH_ROTATION_GRACE_SECONDS: 30,
63
63
  AUTH_REFRESH_COOKIE_NAME: 'shipfox_refresh_token',
64
+ AUTH_SIGNUP_GATE_ENABLED: false,
65
+ AUTH_SIGNUP_ALLOWED_EMAIL_DOMAINS: '',
66
+ AUTH_SIGNUP_ALLOWED_EMAILS: '',
67
+ AUTH_SIGNUP_NOT_ALLOWED_MESSAGE: undefined,
64
68
  CLIENT_BASE_URL: testConfig.clientBaseUrl,
65
69
  },
66
70
  mailer: testConfig.mailer,
@@ -77,6 +81,7 @@ const workspaces = {
77
81
  preflightInvitationAcceptance: vi.fn(),
78
82
  acceptInvitation: vi.fn(),
79
83
  requireActiveMembership: vi.fn(),
84
+ getWorkspaceOperatingState: vi.fn(),
80
85
  };
81
86
 
82
87
  const login = (params: {email: string; password: string}) => coreLogin({...params, workspaces});
package/src/core/auth.ts CHANGED
@@ -49,15 +49,14 @@ import {
49
49
  import {signUserToken} from './jwt.js';
50
50
  import {hashPassword, verifyPassword} from './password.js';
51
51
  import type {SignupPolicy} from './ports.js';
52
+ import {createEnvironmentSignupPolicy} from './signup-policy.js';
52
53
 
53
54
  const RESET_TTL_HOURS = 1;
54
55
  const PASSWORD_VERIFICATION_PURPOSE = 'password-verification';
55
56
  const DEFAULT_SIGNUP_NOT_ALLOWED_MESSAGE =
56
57
  'This Shipfox deployment does not accept new accounts right now.';
57
58
 
58
- const defaultSignupPolicy: SignupPolicy = {
59
- isSignupAllowed: async () => ({allowed: true}),
60
- };
59
+ const defaultSignupPolicy: SignupPolicy = createEnvironmentSignupPolicy();
61
60
 
62
61
  async function assertSignupAllowed(params: {
63
62
  signupPolicy?: SignupPolicy | undefined;
@@ -0,0 +1,23 @@
1
+ import type {AdminRole} from '@shipfox/api-auth-dto';
2
+ import type {UserStatus} from './user.js';
3
+
4
+ export interface AdministratorUserIdentity {
5
+ id: string;
6
+ email: string;
7
+ name: string | null;
8
+ status: UserStatus;
9
+ }
10
+
11
+ export interface AdministratorUserSummary extends AdministratorUserIdentity {
12
+ emailVerifiedAt: Date | null;
13
+ createdAt: Date;
14
+ adminRole: AdminRole | null;
15
+ }
16
+
17
+ export interface AdministratorGrantSummary {
18
+ grantId: string;
19
+ role: AdminRole;
20
+ createdAt: Date;
21
+ revokedAt: Date | null;
22
+ user: AdministratorUserIdentity;
23
+ }
@@ -97,6 +97,41 @@ export class LastAdminOwnerError extends Error {
97
97
  }
98
98
  }
99
99
 
100
+ export class AdminGrantNotFoundError extends Error {
101
+ constructor() {
102
+ super('Administrator grant not found');
103
+ this.name = 'AdminGrantNotFoundError';
104
+ }
105
+ }
106
+
107
+ export class AdminGrantAlreadyExistsError extends Error {
108
+ constructor() {
109
+ super('Administrator grant already exists');
110
+ this.name = 'AdminGrantAlreadyExistsError';
111
+ }
112
+ }
113
+
114
+ export class AdminBootstrapClosedError extends Error {
115
+ constructor() {
116
+ super('First administrator owner has already been created');
117
+ this.name = 'AdminBootstrapClosedError';
118
+ }
119
+ }
120
+
121
+ export class InvalidAdminBootstrapTokenError extends Error {
122
+ constructor() {
123
+ super('Bootstrap token is invalid');
124
+ this.name = 'InvalidAdminBootstrapTokenError';
125
+ }
126
+ }
127
+
128
+ export class AdminIdempotencyKeyReuseError extends Error {
129
+ constructor() {
130
+ super('Idempotency key was already used for a different command');
131
+ this.name = 'AdminIdempotencyKeyReuseError';
132
+ }
133
+ }
134
+
100
135
  export class TokenInvalidError extends Error {
101
136
  constructor(reason?: string) {
102
137
  super(reason ? `Invalid token: ${reason}` : 'Invalid token');
@@ -1,12 +1,7 @@
1
1
  import {eq} from 'drizzle-orm';
2
2
  import {LastAdminOwnerError} from '#core/errors.js';
3
3
  import {userFactory} from '#test/index.js';
4
- import {
5
- createAdminGrant,
6
- findCurrentAdminRole,
7
- listAdminGrants,
8
- revokeAdminGrant,
9
- } from './admin-grants.js';
4
+ import {createAdminGrant, findCurrentAdminRole, revokeAdminGrant} from './admin-grants.js';
10
5
  import {db} from './db.js';
11
6
  import {users} from './schema/users.js';
12
7
 
@@ -18,7 +13,6 @@ describe('admin grants db', () => {
18
13
 
19
14
  expect(observer.userId).toBe(user.id);
20
15
  expect(await findCurrentAdminRole({userId: user.id})).toBe('admin-operator');
21
- expect((await listAdminGrants()).filter((grant) => grant.userId === user.id)).toHaveLength(2);
22
16
  });
23
17
 
24
18
  test('does not evaluate revoked grants or grants for suspended users', async () => {