@pikku/kysely 0.13.23 → 0.13.24

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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 0.13.24
2
+
3
+ ### Patch Changes
4
+
5
+ - f10162a: `send()` now reports the delivery id it wrote, not only the broker's job id.
6
+
7
+ `KyselyWebhookService.send()` returned `{ jobId }` straight from `queueService.add()`, and callers handed that to `getDelivery()`. That only worked because every queue in the test suite echoed the requested `jobId` back. A broker is free to assign its own identity — the JetStream queue returns a stream sequence — so on those the read-back looked up an id that was never written and 404'd.
8
+
9
+ `SendWebhookResult` gains an optional `deliveryId`, which store-backed implementations always populate.
10
+
11
+ - Updated dependencies [f10162a]
12
+ - @pikku/core@0.12.104
13
+
1
14
  ## 0.13.23
2
15
 
3
16
  ### Patch Changes
@@ -15,7 +15,7 @@ export declare class KyselyWebhookService extends QueueWebhookService {
15
15
  private initialized;
16
16
  constructor(queueService: QueueService, db: Kysely<KyselyPikkuDB>);
17
17
  init(): Promise<void>;
18
- send(input: SendWebhookInput): Promise<SendWebhookResult>;
18
+ send(input: SendWebhookInput): Promise<Required<SendWebhookResult>>;
19
19
  recordAttempt(deliveryId: string, { statusCode, responseBody, error, delivered }: WebhookAttemptResult): Promise<void>;
20
20
  /** List deliveries, most recent first — for the console webhooks view. */
21
21
  listDeliveries(opts?: {
@@ -37,7 +37,7 @@ export class KyselyWebhookService extends QueueWebhookService {
37
37
  // deliveryId doubles as the queue jobId (idempotency) and rides in the
38
38
  // payload so the worker can record attempts against this row.
39
39
  const jobId = await this.queueService.add(PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME, { ...jobData, deliveryId }, { ...options, jobId: deliveryId });
40
- return { jobId };
40
+ return { jobId, deliveryId };
41
41
  }
42
42
  async recordAttempt(deliveryId, { statusCode, responseBody, error, delivered }) {
43
43
  const now = new Date();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/kysely",
3
- "version": "0.13.23",
3
+ "version": "0.13.24",
4
4
  "description": "Kysely-backed Pikku services — workflow state, secrets, sessions, scopes and audit",
5
5
  "author": "yasser.fadl@gmail.com",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "prepublishOnly": "yarn build"
22
22
  },
23
23
  "peerDependencies": {
24
- "@pikku/core": "^0.12.98"
24
+ "@pikku/core": "^0.12.104"
25
25
  },
26
26
  "dependencies": {
27
27
  "kysely": "^0.29.5"
@@ -75,6 +75,35 @@ describe('KyselyWebhookService', () => {
75
75
  assert.equal(delivery!.attempts.length, 0)
76
76
  })
77
77
 
78
+ test('send() reports the delivery id even when the broker assigns its own', async () => {
79
+ const db = createDb()
80
+ const added: { data: any; options: any }[] = []
81
+ const queue = {
82
+ supportsResults: false,
83
+ add: async (_name: string, data: any, options: any) => {
84
+ added.push({ data, options })
85
+ return '42'
86
+ },
87
+ getJob: async () => null,
88
+ }
89
+ await applyPikkuSchemas(db, [webhookSchema])
90
+ const service = new KyselyWebhookService(queue as any, db)
91
+ await service.init()
92
+
93
+ const { jobId, deliveryId } = await service.send({
94
+ url: 'https://example.com/hook',
95
+ event: 'user.created',
96
+ data: { id: 'u1' },
97
+ organizationId: 'org-1',
98
+ })
99
+
100
+ assert.equal(jobId, '42')
101
+ assert.notEqual(deliveryId, jobId)
102
+ assert.equal(deliveryId, added[0]!.options.jobId)
103
+ assert.ok(await service.getDelivery(deliveryId!))
104
+ assert.equal(await service.getDelivery(jobId), null)
105
+ })
106
+
78
107
  test('recordAttempt() appends attempts and rolls status forward', async () => {
79
108
  const db = createDb()
80
109
  const { queue } = createQueue()
@@ -36,7 +36,9 @@ export class KyselyWebhookService extends QueueWebhookService {
36
36
  this.initialized = true
37
37
  }
38
38
 
39
- public async send(input: SendWebhookInput): Promise<SendWebhookResult> {
39
+ public async send(
40
+ input: SendWebhookInput
41
+ ): Promise<Required<SendWebhookResult>> {
40
42
  const deliveryId = globalThis.crypto.randomUUID()
41
43
  const { jobData, options } = await this.prepareDelivery(input)
42
44
 
@@ -57,7 +59,7 @@ export class KyselyWebhookService extends QueueWebhookService {
57
59
  { ...jobData, deliveryId },
58
60
  { ...options, jobId: deliveryId }
59
61
  )
60
- return { jobId }
62
+ return { jobId, deliveryId }
61
63
  }
62
64
 
63
65
  public async recordAttempt(