@shipfox/api-server 2.0.0 → 3.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@shipfox/api-server",
3
3
  "license": "MIT",
4
4
  "private": false,
5
- "version": "2.0.0",
5
+ "version": "3.0.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -41,32 +41,32 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "@shipfox/api-auth": "2.0.0",
45
- "@shipfox/api-agent": "2.0.0",
46
- "@shipfox/api-dispatcher": "2.0.0",
47
- "@shipfox/annotations": "2.0.0",
48
- "@shipfox/api-integration-core": "2.0.0",
49
- "@shipfox/api-definitions": "2.0.0",
50
- "@shipfox/api-logs": "2.0.0",
51
- "@shipfox/api-projects": "2.0.0",
52
- "@shipfox/api-workspaces": "2.0.0",
53
- "@shipfox/api-triggers": "2.0.0",
44
+ "@shipfox/annotations": "3.0.0",
45
+ "@shipfox/api-agent": "3.0.0",
46
+ "@shipfox/api-auth": "3.0.0",
47
+ "@shipfox/api-definitions": "3.0.0",
48
+ "@shipfox/api-dispatcher": "3.0.0",
49
+ "@shipfox/api-integration-core": "3.0.0",
50
+ "@shipfox/api-logs": "3.0.0",
51
+ "@shipfox/api-projects": "3.0.0",
52
+ "@shipfox/api-runners": "3.0.0",
53
+ "@shipfox/api-secrets": "3.0.0",
54
+ "@shipfox/api-triggers": "3.0.0",
55
+ "@shipfox/api-workflows": "3.0.0",
56
+ "@shipfox/api-workspaces": "3.0.0",
54
57
  "@shipfox/config": "1.2.1",
55
- "@shipfox/node-fastify": "0.2.1",
56
58
  "@shipfox/node-error-monitoring": "0.1.2",
57
- "@shipfox/api-workflows": "2.0.0",
58
- "@shipfox/node-module": "0.2.0",
59
- "@shipfox/api-secrets": "2.0.0",
60
- "@shipfox/node-postgres": "0.4.1",
61
- "@shipfox/api-runners": "2.0.0",
62
- "@shipfox/node-opentelemetry": "0.5.0"
59
+ "@shipfox/node-fastify": "0.2.2",
60
+ "@shipfox/node-module": "0.3.0",
61
+ "@shipfox/node-opentelemetry": "0.5.1",
62
+ "@shipfox/node-postgres": "0.4.1"
63
63
  },
64
64
  "devDependencies": {
65
- "@shipfox/ts-config": "1.3.8",
66
65
  "@shipfox/biome": "1.8.1",
67
66
  "@shipfox/swc": "1.2.5",
68
- "@shipfox/vitest": "1.2.2",
69
- "@shipfox/typescript": "1.1.6"
67
+ "@shipfox/ts-config": "1.3.8",
68
+ "@shipfox/typescript": "1.1.6",
69
+ "@shipfox/vitest": "1.2.2"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "shipfox-swc",
@@ -17,6 +17,7 @@ const mocks = vi.hoisted(() => {
17
17
  createE2eAdminAuthMethod: vi.fn(),
18
18
  createE2eRouteGroup: vi.fn(),
19
19
  createPostgresClient: vi.fn(),
20
+ aggregateLoginMethods: vi.fn(),
20
21
  initializeModules: vi.fn(),
21
22
  listen: vi.fn(),
22
23
  logger: {error: vi.fn(), info: vi.fn()},
@@ -47,6 +48,7 @@ vi.mock('@shipfox/node-fastify', () => ({
47
48
  listen: mocks.listen,
48
49
  }));
49
50
  vi.mock('@shipfox/node-module', () => ({
51
+ aggregateLoginMethods: mocks.aggregateLoginMethods,
50
52
  initializeModules: mocks.initializeModules,
51
53
  registerModuleMetrics: mocks.registerModuleMetrics,
52
54
  resetPublishers: mocks.resetPublishers,
@@ -73,7 +75,7 @@ vi.mock('./e2e.js', () => ({
73
75
  }));
74
76
 
75
77
  function module(): ShipfoxModule {
76
- return {name: 'test'};
78
+ return {name: 'test', loginMethods: [{id: 'test-login'}]};
77
79
  }
78
80
 
79
81
  function worker(taskQueue = 'runtime-queue'): ModuleWorker {
@@ -101,6 +103,7 @@ function resetMocks(): void {
101
103
  mocks.createE2eAdminAuthMethod.mockReset();
102
104
  mocks.createE2eRouteGroup.mockReset();
103
105
  mocks.createPostgresClient.mockReset();
106
+ mocks.aggregateLoginMethods.mockReset();
104
107
  mocks.initializeModules.mockReset();
105
108
  mocks.listen.mockReset();
106
109
  mocks.logger.error.mockReset();
@@ -122,6 +125,7 @@ function resetMocks(): void {
122
125
  mocks.closeErrorMonitoring.mockResolvedValue(true);
123
126
  mocks.closePostgresClient.mockResolvedValue(undefined);
124
127
  mocks.createApp.mockResolvedValue({});
128
+ mocks.aggregateLoginMethods.mockReturnValue([{id: 'test-login'}]);
125
129
  mocks.createE2eRouteGroup.mockReturnValue([]);
126
130
  mocks.initializeModules.mockResolvedValue({
127
131
  auth: [],
@@ -166,6 +170,7 @@ describe('createServer', () => {
166
170
  await createTestServer({modules});
167
171
 
168
172
  expect(mocks.startServiceMetrics).toHaveBeenCalledWith({serviceName: 'api'});
173
+ expect(mocks.aggregateLoginMethods).toHaveBeenCalledWith({modules});
169
174
  expect(mocks.createPostgresClient).toHaveBeenCalledOnce();
170
175
  expect(mocks.initializeModules).toHaveBeenCalledWith({modules});
171
176
  expect(mocks.registerModuleMetrics).toHaveBeenCalledWith({modules});
@@ -177,6 +182,28 @@ describe('createServer', () => {
177
182
  });
178
183
  });
179
184
 
185
+ it('fails before startup side effects when no login method is configured', async () => {
186
+ const failure = new Error('No login methods are configured');
187
+ mocks.aggregateLoginMethods.mockImplementationOnce(() => {
188
+ throw failure;
189
+ });
190
+
191
+ const result = createTestServer({modules: [module()]});
192
+
193
+ await expect(result).rejects.toBe(failure);
194
+ expect(mocks.startServiceMetrics).not.toHaveBeenCalled();
195
+ expect(mocks.createPostgresClient).not.toHaveBeenCalled();
196
+ });
197
+
198
+ it('constructs and starts when a module contributes a login method', async () => {
199
+ const server = await createTestServer({modules: [module()]});
200
+
201
+ await server.start();
202
+
203
+ expect(mocks.startModuleWorkers).toHaveBeenCalledOnce();
204
+ expect(mocks.listen).toHaveBeenCalledOnce();
205
+ });
206
+
180
207
  it('starts module workers before listening for HTTP requests', async () => {
181
208
  const server = await createTestServer({modules: [module()]});
182
209
  let resolveWorkers: ((handle: ModuleWorkersHandle) => void) | undefined;
package/src/server.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {captureException, closeErrorMonitoring} from '@shipfox/node-error-monitoring';
2
2
  import {closeApp, createApp, listen} from '@shipfox/node-fastify';
3
3
  import {
4
+ aggregateLoginMethods,
4
5
  initializeModules,
5
6
  type ModuleWorker,
6
7
  type ModuleWorkersHandle,
@@ -43,6 +44,7 @@ export async function createServer(options: CreateServerOptions): Promise<Server
43
44
  hasActiveServer = true;
44
45
 
45
46
  try {
47
+ aggregateLoginMethods({modules: options.modules});
46
48
  startServiceMetrics({serviceName: 'api'});
47
49
  createPostgresClient();
48
50