@fonoster/apiserver 0.53.0 → 0.55.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/dist/core/services.d.ts +3 -0
- package/dist/usage/publishRecordedUsage.d.ts +3 -1
- package/dist/usage/publishRecordedUsage.js +5 -2
- package/dist/webhooks/createWebhooksHandlers.d.ts +3 -0
- package/dist/webhooks/createWebhooksHandlers.js +17 -6
- package/dist/webhooks/index.d.ts +3 -0
- package/package.json +11 -11
package/dist/core/services.d.ts
CHANGED
|
@@ -362,6 +362,9 @@ declare const services: Promise<[{
|
|
|
362
362
|
resendWebhookDelivery: (call: {
|
|
363
363
|
request: unknown;
|
|
364
364
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
365
|
+
getWebhookDelivery: (call: {
|
|
366
|
+
request: unknown;
|
|
367
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
365
368
|
};
|
|
366
369
|
}, {
|
|
367
370
|
definition: {
|
|
@@ -38,7 +38,9 @@ export declare function ensureRecordedUsageStream(nc: NatsConnection): Promise<v
|
|
|
38
38
|
/**
|
|
39
39
|
* Publishes one batch of unpublished usage, oldest first, each with its usage id as the message id
|
|
40
40
|
* (JetStream drops a repeat), then marks the batch published. A crash between the two only
|
|
41
|
-
* publishes the batch again.
|
|
41
|
+
* publishes the batch again. Rows without an owner are skipped and stay unpublished: there is no
|
|
42
|
+
* subject to publish them on, and one of them must not hold back the rest. Returns how many were
|
|
43
|
+
* published.
|
|
42
44
|
*/
|
|
43
45
|
export declare function publishRecordedUsageOnce(nc: NatsConnection, db: UsageSql, batch?: number): Promise<number>;
|
|
44
46
|
/**
|
|
@@ -57,13 +57,16 @@ function ensureRecordedUsageStream(nc) {
|
|
|
57
57
|
/**
|
|
58
58
|
* Publishes one batch of unpublished usage, oldest first, each with its usage id as the message id
|
|
59
59
|
* (JetStream drops a repeat), then marks the batch published. A crash between the two only
|
|
60
|
-
* publishes the batch again.
|
|
60
|
+
* publishes the batch again. Rows without an owner are skipped and stay unpublished: there is no
|
|
61
|
+
* subject to publish them on, and one of them must not hold back the rest. Returns how many were
|
|
62
|
+
* published.
|
|
61
63
|
*/
|
|
62
64
|
function publishRecordedUsageOnce(nc_1, db_1) {
|
|
63
65
|
return __awaiter(this, arguments, void 0, function* (nc, db, batch = 500) {
|
|
64
66
|
const rows = yield db.$queryRawUnsafe(`SELECT id, owner_ref, workspace_ref, app_ref, call_ref, region, region_kind, origin, meter,
|
|
65
67
|
quantity, provider, model, key_source, occurred_at
|
|
66
|
-
FROM usage_events WHERE published_at IS NULL
|
|
68
|
+
FROM usage_events WHERE published_at IS NULL AND owner_ref <> ''
|
|
69
|
+
ORDER BY recorded_at, id LIMIT $1`, batch);
|
|
67
70
|
if (!rows.length)
|
|
68
71
|
return 0;
|
|
69
72
|
const js = nc.jetstream();
|
|
@@ -34,4 +34,7 @@ export declare function createWebhooksHandlers(db: WebhooksDb, config?: Webhooks
|
|
|
34
34
|
resendWebhookDelivery: (call: {
|
|
35
35
|
request: unknown;
|
|
36
36
|
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
37
|
+
getWebhookDelivery: (call: {
|
|
38
|
+
request: unknown;
|
|
39
|
+
}, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
37
40
|
};
|
|
@@ -61,7 +61,8 @@ function toDelivery(row) {
|
|
|
61
61
|
lastStatus: (_a = row.lastStatus) !== null && _a !== void 0 ? _a : 0,
|
|
62
62
|
lastAttemptAt: seconds(row.lastAttemptAt),
|
|
63
63
|
nextAttemptAt: row.status === "pending" ? seconds(row.nextAttemptAt) : 0,
|
|
64
|
-
createdAt: seconds(row.createdAt)
|
|
64
|
+
createdAt: seconds(row.createdAt),
|
|
65
|
+
event: JSON.stringify(row.event)
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
/** Checks the URL (HTTPS) and event types the same way the dispatcher does. */
|
|
@@ -182,15 +183,24 @@ function createWebhooksHandlers(db, config = {}) {
|
|
|
182
183
|
});
|
|
183
184
|
callback(null, { items: rows.map(toDelivery) });
|
|
184
185
|
});
|
|
185
|
-
|
|
186
|
-
const resendWebhookDelivery = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const accessKeyId = workspace(call);
|
|
188
|
-
const { ref } = call.request;
|
|
186
|
+
const findDelivery = (ref, accessKeyId) => __awaiter(this, void 0, void 0, function* () {
|
|
189
187
|
const row = yield db.webhookDelivery.findFirst({
|
|
190
188
|
where: { ref, accessKeyId }
|
|
191
189
|
});
|
|
192
190
|
if (!row)
|
|
193
191
|
throw notFound(`delivery not found: ${ref}`);
|
|
192
|
+
return row;
|
|
193
|
+
});
|
|
194
|
+
/** One delivery of the caller's workspace, with the event it sends. */
|
|
195
|
+
const getWebhookDelivery = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
const row = yield findDelivery(call.request.ref, workspace(call));
|
|
197
|
+
callback(null, toDelivery(row));
|
|
198
|
+
});
|
|
199
|
+
/** Sends again now with the original event id and a fresh signature (W6). */
|
|
200
|
+
const resendWebhookDelivery = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const accessKeyId = workspace(call);
|
|
202
|
+
const { ref } = call.request;
|
|
203
|
+
yield findDelivery(ref, accessKeyId);
|
|
194
204
|
const store = yield common_1.Webhooks.PrismaWebhookStore.open(db);
|
|
195
205
|
yield store.loadDeliveries({ id: ref, workspaceRef: accessKeyId }, 1);
|
|
196
206
|
const dispatcher = new common_1.Webhooks.WebhookDispatcher({
|
|
@@ -212,6 +222,7 @@ function createWebhooksHandlers(db, config = {}) {
|
|
|
212
222
|
deleteWebhook: (0, common_1.withErrorHandling)(deleteWebhook),
|
|
213
223
|
rotateWebhookSecret: (0, common_1.withErrorHandling)(rotateWebhookSecret),
|
|
214
224
|
listWebhookDeliveries: (0, common_1.withErrorHandling)(listWebhookDeliveries),
|
|
215
|
-
resendWebhookDelivery: (0, common_1.withErrorHandling)(resendWebhookDelivery)
|
|
225
|
+
resendWebhookDelivery: (0, common_1.withErrorHandling)(resendWebhookDelivery),
|
|
226
|
+
getWebhookDelivery: (0, common_1.withErrorHandling)(getWebhookDelivery)
|
|
216
227
|
};
|
|
217
228
|
}
|
package/dist/webhooks/index.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ declare function buildWebhooksService(db: WebhooksDb): {
|
|
|
31
31
|
resendWebhookDelivery: (call: {
|
|
32
32
|
request: unknown;
|
|
33
33
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
34
|
+
getWebhookDelivery: (call: {
|
|
35
|
+
request: unknown;
|
|
36
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
34
37
|
};
|
|
35
38
|
};
|
|
36
39
|
export { buildWebhooksService };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/apiserver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "APIServer for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"fonoster-owner": "./dist/bin/owner.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@fonoster/authz": "^0.
|
|
27
|
-
"@fonoster/autopilot": "^0.
|
|
28
|
-
"@fonoster/callrecord": "^0.
|
|
29
|
-
"@fonoster/common": "^0.
|
|
30
|
-
"@fonoster/identity": "^0.
|
|
31
|
-
"@fonoster/logger": "^0.
|
|
32
|
-
"@fonoster/sipnet": "^0.
|
|
33
|
-
"@fonoster/types": "^0.
|
|
26
|
+
"@fonoster/authz": "^0.55.0",
|
|
27
|
+
"@fonoster/autopilot": "^0.55.0",
|
|
28
|
+
"@fonoster/callrecord": "^0.55.0",
|
|
29
|
+
"@fonoster/common": "^0.55.0",
|
|
30
|
+
"@fonoster/identity": "^0.55.0",
|
|
31
|
+
"@fonoster/logger": "^0.55.0",
|
|
32
|
+
"@fonoster/sipnet": "^0.55.0",
|
|
33
|
+
"@fonoster/types": "^0.55.0",
|
|
34
34
|
"@grpc/grpc-js": "~1.14.6",
|
|
35
35
|
"@prisma/client": "^6.19.1",
|
|
36
36
|
"@routr/common": "^2.24.0",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@fonoster/ops": "^0.
|
|
65
|
+
"@fonoster/ops": "^0.55.0",
|
|
66
66
|
"@types/express": "^5.0.6",
|
|
67
67
|
"@types/jsonwebtoken": "^9.0.10",
|
|
68
68
|
"@types/uuid": "^10.0.0",
|
|
69
69
|
"@types/validator": "^13.15.10"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "cc20084336978a71be4fae9619e35f652d7ec875",
|
|
72
72
|
"prisma": {
|
|
73
73
|
"seed": "tsx src/core/seed.ts"
|
|
74
74
|
}
|