@shipfox/api-triggers 6.0.0 → 7.0.1

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipfox/api-triggers",
3
3
  "license": "MIT",
4
- "version": "6.0.0",
4
+ "version": "7.0.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -131,3 +131,12 @@ export async function findMatchingJobListenerSubscriptions(
131
131
  );
132
132
  return rows.map(toJobListenerSubscription);
133
133
  }
134
+
135
+ export async function hasJobListenerSubscriptions(jobId: string): Promise<boolean> {
136
+ const [subscription] = await db()
137
+ .select({id: jobListenerSubscriptions.id})
138
+ .from(jobListenerSubscriptions)
139
+ .where(eq(jobListenerSubscriptions.jobId, jobId))
140
+ .limit(1);
141
+ return subscription !== undefined;
142
+ }
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ import type {WorkflowsModuleClient} from '@shipfox/api-workflows-dto/inter-modul
18
18
  import {type ShipfoxModule, subscriberFactory} from '@shipfox/node-module';
19
19
  import {db, migrationsPath, triggersOutbox} from '#db/index.js';
20
20
  import {registerTriggersServiceMetrics} from '#metrics/index.js';
21
+ import {triggersE2eRoutes} from '#presentation/e2e-routes.js';
21
22
  import {createTriggerRoutes} from '#presentation/index.js';
22
23
  import {
23
24
  createOnIntegrationEventReceived,
@@ -76,6 +77,7 @@ export function createTriggersModule({workflows}: CreateTriggersModuleOptions):
76
77
  name: 'triggers',
77
78
  database: {db, migrationsPath},
78
79
  routes: createTriggerRoutes(workflows),
80
+ e2eRoutes: [triggersE2eRoutes],
79
81
  metrics: registerTriggersServiceMetrics,
80
82
  publishers: [{name: 'triggers', table: triggersOutbox, db}],
81
83
  subscribers: [
@@ -0,0 +1,44 @@
1
+ import {closeApp, createApp} from '@shipfox/node-fastify';
2
+ import {projectJobListenerSubscriptions} from '#db/job-listener-subscriptions.js';
3
+ import {triggersE2eRoutes} from './e2e-routes.js';
4
+
5
+ describe('triggers E2E routes', () => {
6
+ afterEach(async () => {
7
+ await closeApp();
8
+ });
9
+
10
+ test('reports a listener without projected subscriptions as not ready', async () => {
11
+ const jobId = crypto.randomUUID();
12
+ const app = await createApp({routes: [triggersE2eRoutes], swagger: false});
13
+
14
+ const response = await app.inject({
15
+ method: 'GET',
16
+ url: `/triggers/listeners/${jobId}/readiness`,
17
+ });
18
+
19
+ expect(response.statusCode).toBe(200);
20
+ expect(response.json()).toEqual({ready: false});
21
+ });
22
+
23
+ test('reports a listener with projected subscriptions as ready', async () => {
24
+ const workspaceId = crypto.randomUUID();
25
+ const workflowRunId = crypto.randomUUID();
26
+ const jobId = crypto.randomUUID();
27
+ await projectJobListenerSubscriptions({
28
+ workspaceId,
29
+ workflowRunId,
30
+ jobId,
31
+ on: [{source: 'listener-source', event: 'received'}],
32
+ until: null,
33
+ });
34
+ const app = await createApp({routes: [triggersE2eRoutes], swagger: false});
35
+
36
+ const response = await app.inject({
37
+ method: 'GET',
38
+ url: `/triggers/listeners/${jobId}/readiness`,
39
+ });
40
+
41
+ expect(response.statusCode).toBe(200);
42
+ expect(response.json()).toEqual({ready: true});
43
+ });
44
+ });
@@ -0,0 +1,24 @@
1
+ import {defineRoute, type RouteGroup} from '@shipfox/node-fastify';
2
+ import {z} from 'zod';
3
+ import {hasJobListenerSubscriptions} from '#db/job-listener-subscriptions.js';
4
+
5
+ const listenerReadinessParamsSchema = z.object({jobId: z.string().uuid()});
6
+ const listenerReadinessResponseSchema = z.object({ready: z.boolean()});
7
+
8
+ const listenerReadinessRoute = defineRoute({
9
+ method: 'GET',
10
+ path: '/listeners/:jobId/readiness',
11
+ description: 'Report whether trigger subscriptions for a listener job are ready in E2E tests.',
12
+ schema: {
13
+ params: listenerReadinessParamsSchema,
14
+ response: {200: listenerReadinessResponseSchema},
15
+ },
16
+ handler: async (request) => ({
17
+ ready: await hasJobListenerSubscriptions(request.params.jobId),
18
+ }),
19
+ });
20
+
21
+ export const triggersE2eRoutes: RouteGroup = {
22
+ prefix: '/triggers',
23
+ routes: [listenerReadinessRoute],
24
+ };