@shipfox/api-workspaces 10.2.0 → 12.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +48 -0
- package/README.md +27 -4
- package/dist/core/entities/workspace.d.ts +1 -0
- package/dist/core/entities/workspace.d.ts.map +1 -1
- package/dist/core/entities/workspace.js.map +1 -1
- package/dist/core/errors.d.ts +3 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +6 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/invitations.d.ts.map +1 -1
- package/dist/core/invitations.js +7 -4
- package/dist/core/invitations.js.map +1 -1
- package/dist/core/rate-limit.d.ts +39 -0
- package/dist/core/rate-limit.d.ts.map +1 -0
- package/dist/core/rate-limit.js +70 -0
- package/dist/core/rate-limit.js.map +1 -0
- package/dist/core/workspaces.d.ts +8 -0
- package/dist/core/workspaces.d.ts.map +1 -1
- package/dist/core/workspaces.js +47 -7
- package/dist/core/workspaces.js.map +1 -1
- package/dist/db/db.d.ts +320 -0
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/db.js +3 -1
- package/dist/db/db.js.map +1 -1
- package/dist/db/index.d.ts +4 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +3 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/memberships.d.ts +1 -0
- package/dist/db/memberships.d.ts.map +1 -1
- package/dist/db/memberships.js +2 -0
- package/dist/db/memberships.js.map +1 -1
- package/dist/db/rate-limits.d.ts +9 -0
- package/dist/db/rate-limits.d.ts.map +1 -0
- package/dist/db/rate-limits.js +43 -0
- package/dist/db/rate-limits.js.map +1 -0
- package/dist/db/schema/rate-limits.d.ts +145 -0
- package/dist/db/schema/rate-limits.d.ts.map +1 -0
- package/dist/db/schema/rate-limits.js +25 -0
- package/dist/db/schema/rate-limits.js.map +1 -0
- package/dist/db/schema/workspaces.d.ts +17 -0
- package/dist/db/schema/workspaces.d.ts.map +1 -1
- package/dist/db/schema/workspaces.js +5 -2
- package/dist/db/schema/workspaces.js.map +1 -1
- package/dist/db/workspaces.d.ts +11 -1
- package/dist/db/workspaces.d.ts.map +1 -1
- package/dist/db/workspaces.js +12 -3
- package/dist/db/workspaces.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics/instance.d.ts +6 -0
- package/dist/metrics/instance.d.ts.map +1 -1
- package/dist/metrics/instance.js +12 -0
- package/dist/metrics/instance.js.map +1 -1
- package/dist/presentation/dto/membership.d.ts.map +1 -1
- package/dist/presentation/dto/membership.js +1 -0
- package/dist/presentation/dto/membership.js.map +1 -1
- package/dist/presentation/dto/workspace.d.ts.map +1 -1
- package/dist/presentation/dto/workspace.js +1 -0
- package/dist/presentation/dto/workspace.js.map +1 -1
- package/dist/presentation/e2eRoutes/create-workspace.d.ts.map +1 -1
- package/dist/presentation/e2eRoutes/create-workspace.js +11 -1
- package/dist/presentation/e2eRoutes/create-workspace.js.map +1 -1
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +3 -2
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/presentation/routes/index.d.ts.map +1 -1
- package/dist/presentation/routes/index.js +3 -1
- package/dist/presentation/routes/index.js.map +1 -1
- package/dist/presentation/routes/invitations/create.d.ts.map +1 -1
- package/dist/presentation/routes/invitations/create.js +5 -1
- package/dist/presentation/routes/invitations/create.js.map +1 -1
- package/dist/presentation/routes/invitations/list.d.ts.map +1 -1
- package/dist/presentation/routes/invitations/list.js +5 -1
- package/dist/presentation/routes/invitations/list.js.map +1 -1
- package/dist/presentation/routes/invitations/revoke.d.ts.map +1 -1
- package/dist/presentation/routes/invitations/revoke.js +5 -1
- package/dist/presentation/routes/invitations/revoke.js.map +1 -1
- package/dist/presentation/routes/members/list.d.ts.map +1 -1
- package/dist/presentation/routes/members/list.js +5 -1
- package/dist/presentation/routes/members/list.js.map +1 -1
- package/dist/presentation/routes/members/remove.d.ts.map +1 -1
- package/dist/presentation/routes/members/remove.js +5 -1
- package/dist/presentation/routes/members/remove.js.map +1 -1
- package/dist/presentation/routes/rate-limit.d.ts +3 -0
- package/dist/presentation/routes/rate-limit.d.ts.map +1 -0
- package/dist/presentation/routes/rate-limit.js +42 -0
- package/dist/presentation/routes/rate-limit.js.map +1 -0
- package/dist/presentation/routes/workspaces/create.d.ts.map +1 -1
- package/dist/presentation/routes/workspaces/create.js +11 -1
- package/dist/presentation/routes/workspaces/create.js.map +1 -1
- package/dist/presentation/routes/workspaces/index.d.ts +2 -0
- package/dist/presentation/routes/workspaces/index.d.ts.map +1 -1
- package/dist/presentation/routes/workspaces/index.js +2 -0
- package/dist/presentation/routes/workspaces/index.js.map +1 -1
- package/dist/presentation/routes/workspaces/slug-availability.d.ts +2 -0
- package/dist/presentation/routes/workspaces/slug-availability.d.ts.map +1 -0
- package/dist/presentation/routes/workspaces/slug-availability.js +31 -0
- package/dist/presentation/routes/workspaces/slug-availability.js.map +1 -0
- package/dist/presentation/routes/workspaces/update.d.ts +2 -0
- package/dist/presentation/routes/workspaces/update.d.ts.map +1 -0
- package/dist/presentation/routes/workspaces/update.js +49 -0
- package/dist/presentation/routes/workspaces/update.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/drizzle/0000_initial.sql +2 -0
- package/drizzle/0003_dapper_talos.sql +13 -0
- package/drizzle/meta/0000_snapshot.json +23 -1
- package/drizzle/meta/0003_snapshot.json +689 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +14 -12
- package/src/core/entities/workspace.ts +1 -0
- package/src/core/errors.ts +7 -0
- package/src/core/index.ts +3 -0
- package/src/core/invitations.test.ts +8 -8
- package/src/core/invitations.ts +4 -1
- package/src/core/rate-limit.test.ts +113 -0
- package/src/core/rate-limit.ts +119 -0
- package/src/core/workspaces.test.ts +31 -3
- package/src/core/workspaces.ts +51 -4
- package/src/db/db.ts +2 -0
- package/src/db/index.ts +10 -0
- package/src/db/memberships.ts +3 -0
- package/src/db/rate-limits.test.ts +74 -0
- package/src/db/rate-limits.ts +59 -0
- package/src/db/schema/rate-limits.ts +27 -0
- package/src/db/schema/workspaces.ts +7 -2
- package/src/db/workspaces.ts +21 -1
- package/src/index.test.ts +2 -0
- package/src/index.ts +1 -0
- package/src/metrics/instance.ts +26 -0
- package/src/presentation/dto/membership.ts +1 -0
- package/src/presentation/dto/workspace.ts +1 -0
- package/src/presentation/e2eRoutes/create-workspace.ts +9 -1
- package/src/presentation/inter-module.test.ts +69 -0
- package/src/presentation/inter-module.ts +7 -4
- package/src/presentation/routes/index.ts +8 -1
- package/src/presentation/routes/invitations/create.test.ts +15 -0
- package/src/presentation/routes/invitations/create.ts +2 -1
- package/src/presentation/routes/invitations/list.test.ts +30 -0
- package/src/presentation/routes/invitations/list.ts +2 -1
- package/src/presentation/routes/invitations/revoke.test.ts +14 -0
- package/src/presentation/routes/invitations/revoke.ts +2 -1
- package/src/presentation/routes/members/list.test.ts +29 -1
- package/src/presentation/routes/members/list.ts +2 -1
- package/src/presentation/routes/members/remove.test.ts +14 -0
- package/src/presentation/routes/members/remove.ts +2 -1
- package/src/presentation/routes/rate-limit.ts +45 -0
- package/src/presentation/routes/workspaces/create.test.ts +33 -3
- package/src/presentation/routes/workspaces/create.ts +9 -1
- package/src/presentation/routes/workspaces/index.ts +2 -0
- package/src/presentation/routes/workspaces/list.test.ts +1 -0
- package/src/presentation/routes/workspaces/slug-availability.test.ts +159 -0
- package/src/presentation/routes/workspaces/slug-availability.ts +30 -0
- package/src/presentation/routes/workspaces/update.test.ts +114 -0
- package/src/presentation/routes/workspaces/update.ts +41 -0
- package/test/env.ts +1 -0
- package/test/factories/workspace.ts +3 -1
- package/test/globalSetup.ts +1 -1
- package/test/routes.ts +26 -7
- package/tsconfig.build.tsbuildinfo +1 -1
package/test/routes.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type {OutgoingHttpHeaders} from 'node:http';
|
|
2
2
|
import {AUTH_USER, buildUserContext, setUserContext} from '@shipfox/api-auth-context';
|
|
3
|
+
import {withSlugSuffix} from '@shipfox/api-common-dto';
|
|
3
4
|
import {WORKSPACES_INVITATION_SEND_REQUESTED} from '@shipfox/api-workspaces-dto';
|
|
4
|
-
import type {AuthMethod} from '@shipfox/node-fastify';
|
|
5
|
-
import {createApp, type FastifyInstance} from '@shipfox/node-fastify';
|
|
5
|
+
import type {AppConfig, AuthMethod} from '@shipfox/node-fastify';
|
|
6
|
+
import {ClientError, createApp, type FastifyInstance} from '@shipfox/node-fastify';
|
|
6
7
|
import type {Mailer, MailMessage} from '@shipfox/node-mailer';
|
|
7
8
|
import {hashOpaqueToken} from '@shipfox/node-tokens';
|
|
8
9
|
import {and, desc, eq, sql} from 'drizzle-orm';
|
|
@@ -44,6 +45,7 @@ vi.mock('#config.js', () => ({
|
|
|
44
45
|
|
|
45
46
|
const TOKEN_RE = /token=([\w\-_=]+)/;
|
|
46
47
|
const BEARER_RE = /^Bearer /u;
|
|
48
|
+
let workspaceSlugSequence = 1;
|
|
47
49
|
|
|
48
50
|
export const ROUTE_TEST_SECRET = testConfig.secret;
|
|
49
51
|
|
|
@@ -51,15 +53,19 @@ const fakeUserAuth: AuthMethod = {
|
|
|
51
53
|
name: AUTH_USER,
|
|
52
54
|
authenticate: async (request) => {
|
|
53
55
|
const raw = request.headers.authorization?.replace(BEARER_RE, '');
|
|
56
|
+
if (!raw) {
|
|
57
|
+
throw new ClientError('Authentication required', 'unauthorized', {status: 401});
|
|
58
|
+
}
|
|
54
59
|
if (raw?.startsWith('claim:')) {
|
|
55
|
-
const [, userId, email, workspaceId] = raw.split(':');
|
|
60
|
+
const [, userId, email, workspaceId, status] = raw.split(':');
|
|
56
61
|
if (!userId || !email || !workspaceId) throw new Error('Invalid test user claim token');
|
|
62
|
+
const workspaceStatus = status === 'suspended' || status === 'deleted' ? status : 'active';
|
|
57
63
|
setUserContext(
|
|
58
64
|
request,
|
|
59
65
|
buildUserContext({
|
|
60
66
|
userId,
|
|
61
67
|
email,
|
|
62
|
-
memberships: [{workspaceId, role: 'admin'}],
|
|
68
|
+
memberships: [{workspaceId, role: 'admin', workspaceStatus}],
|
|
63
69
|
}),
|
|
64
70
|
);
|
|
65
71
|
return;
|
|
@@ -74,7 +80,11 @@ const fakeUserAuth: AuthMethod = {
|
|
|
74
80
|
userId,
|
|
75
81
|
email,
|
|
76
82
|
name: encodedName ? decodeURIComponent(encodedName) : null,
|
|
77
|
-
memberships: memberships.map((m) => ({
|
|
83
|
+
memberships: memberships.map((m) => ({
|
|
84
|
+
workspaceId: m.workspaceId,
|
|
85
|
+
role: 'admin' as const,
|
|
86
|
+
workspaceStatus: 'active' as const,
|
|
87
|
+
})),
|
|
78
88
|
}),
|
|
79
89
|
);
|
|
80
90
|
},
|
|
@@ -138,8 +148,11 @@ export async function latestInvitationLinkTo(email: string): Promise<string> {
|
|
|
138
148
|
return payload?.inviteLink ?? '';
|
|
139
149
|
}
|
|
140
150
|
|
|
141
|
-
export async function createWorkspacesTestApp(
|
|
151
|
+
export async function createWorkspacesTestApp(
|
|
152
|
+
options: Pick<AppConfig, 'fastifyOptions'> = {},
|
|
153
|
+
): Promise<FastifyInstance> {
|
|
142
154
|
return await createApp({
|
|
155
|
+
...options,
|
|
143
156
|
auth: [fakeUserAuth],
|
|
144
157
|
routes: workspacesRoutes,
|
|
145
158
|
swagger: false,
|
|
@@ -212,7 +225,13 @@ export async function createWorkspace(
|
|
|
212
225
|
method: 'POST',
|
|
213
226
|
url: '/workspaces',
|
|
214
227
|
headers: {authorization: `Bearer ${token}`},
|
|
215
|
-
payload: {
|
|
228
|
+
payload: {
|
|
229
|
+
name,
|
|
230
|
+
slug: withSlugSuffix(
|
|
231
|
+
`route-workspace-${crypto.randomUUID().slice(0, 8)}`,
|
|
232
|
+
workspaceSlugSequence++,
|
|
233
|
+
),
|
|
234
|
+
},
|
|
216
235
|
});
|
|
217
236
|
|
|
218
237
|
expect(res.statusCode).toBe(201);
|