@segmentstream/ontology 0.169.0 → 0.170.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/CHANGELOG.md +19 -0
- package/dist/connection.d.ts +2 -2
- package/dist/manifest.d.ts +14 -14
- package/dist/manifest.js +1 -1
- package/dist/migrate/model.d.ts +8 -8
- package/dist/service/connections.js +4 -2
- package/dist/service/schemas.d.ts +2 -2
- package/dist/service/webhooks.d.ts +7 -0
- package/dist/service/webhooks.js +39 -1
- package/dist/webhooks.d.ts +9 -2
- package/dist/webhooks.js +13 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.170.1
|
|
4
|
+
|
|
5
|
+
A connection call that names no `api` reaches the connection's `default_api` or, when the
|
|
6
|
+
connection declares exactly one API and no default, that API, as the connections SDK's HTTP
|
|
7
|
+
client already chooses. Calls such as `nowpayments.get("/payment/123")` through a preset with one
|
|
8
|
+
API, such as `NowPaymentsConnection` or `CoinGateConnection`, no longer fail for want of a default.
|
|
9
|
+
Cloud applies the same rule to deployed ontologies without an upgrade; this release brings it to
|
|
10
|
+
local runs.
|
|
11
|
+
|
|
12
|
+
## 0.170.0
|
|
13
|
+
|
|
14
|
+
An `hmac` webhook signature can sign the body as `{ body: "sorted-json" }`: the body parsed as a
|
|
15
|
+
JSON object and written again compactly with the keys of every object sorted, as `JSON.stringify`
|
|
16
|
+
writes it, for providers that sign such a re-serialization rather than the bytes they sent, such
|
|
17
|
+
as NOWPayments' IPN (`x-nowpayments-sig`, hex HMAC-SHA512). A delivery whose body is not a JSON
|
|
18
|
+
object fails the check. `{ body: true }` still signs the raw bytes. Adding a signature to a token
|
|
19
|
+
webhook changes its URL, since a signed webhook has no token: declare the signed one beside the
|
|
20
|
+
old one while objects created before still carry the old URL.
|
|
21
|
+
|
|
3
22
|
## 0.169.0
|
|
4
23
|
|
|
5
24
|
An entity can declare `eraseFromWarehouseOnDelete: true`: deleting one of its records then erases
|
package/dist/connection.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare class ConnectionError extends ConnectionError_base {
|
|
|
47
47
|
}
|
|
48
48
|
/** One HTTP request through the connection proxy, before it is bound to a connection key. */
|
|
49
49
|
export interface ConnectionCall {
|
|
50
|
-
/** One of the connection's declared APIs;
|
|
50
|
+
/** One of the connection's declared APIs; when omitted, its `default_api`, or its only API. */
|
|
51
51
|
readonly api?: string;
|
|
52
52
|
readonly method: ConnectionMethod;
|
|
53
53
|
/** The path and query, relative to the API's base URL, such as `/people/match?reveal=true`. */
|
|
@@ -121,7 +121,7 @@ export type ConnectionHeaders = Readonly<Record<string, string>> | ReadonlyArray
|
|
|
121
121
|
export type QueryValue = string | number | boolean | ReadonlyArray<string | number | boolean>;
|
|
122
122
|
/** The options of `request` and the method helpers. */
|
|
123
123
|
export interface ConnectionRequestOptions {
|
|
124
|
-
/** One of the connection's declared APIs;
|
|
124
|
+
/** One of the connection's declared APIs; when omitted, its `default_api`, or its only API. */
|
|
125
125
|
readonly api?: string;
|
|
126
126
|
/** Appended to the path as a query string. `undefined` values are skipped. */
|
|
127
127
|
readonly query?: Readonly<Record<string, QueryValue | undefined>>;
|
package/dist/manifest.d.ts
CHANGED
|
@@ -531,7 +531,7 @@ export declare const WebhookTriggerManifest: Schema.Struct<{
|
|
|
531
531
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
532
532
|
}>>;
|
|
533
533
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
534
|
-
readonly body: Schema.
|
|
534
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
535
535
|
}>, Schema.Struct<{
|
|
536
536
|
readonly header: Schema.String;
|
|
537
537
|
}>, Schema.Struct<{
|
|
@@ -607,7 +607,7 @@ export declare const WorkflowTriggerManifest: Schema.Union<readonly [Schema.Stru
|
|
|
607
607
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
608
608
|
}>>;
|
|
609
609
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
610
|
-
readonly body: Schema.
|
|
610
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
611
611
|
}>, Schema.Struct<{
|
|
612
612
|
readonly header: Schema.String;
|
|
613
613
|
}>, Schema.Struct<{
|
|
@@ -690,7 +690,7 @@ export declare const WorkflowManifest: Schema.Struct<{
|
|
|
690
690
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
691
691
|
}>>;
|
|
692
692
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
693
|
-
readonly body: Schema.
|
|
693
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
694
694
|
}>, Schema.Struct<{
|
|
695
695
|
readonly header: Schema.String;
|
|
696
696
|
}>, Schema.Struct<{
|
|
@@ -1459,7 +1459,7 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1459
1459
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
1460
1460
|
}>>;
|
|
1461
1461
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
1462
|
-
readonly body: Schema.
|
|
1462
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
1463
1463
|
}>, Schema.Struct<{
|
|
1464
1464
|
readonly header: Schema.String;
|
|
1465
1465
|
}>, Schema.Struct<{
|
|
@@ -1739,7 +1739,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1739
1739
|
readonly signature?: {
|
|
1740
1740
|
readonly scheme: string;
|
|
1741
1741
|
readonly message?: readonly (string | {
|
|
1742
|
-
readonly body: true;
|
|
1742
|
+
readonly body: true | "sorted-json";
|
|
1743
1743
|
} | {
|
|
1744
1744
|
readonly header: string;
|
|
1745
1745
|
} | {
|
|
@@ -2117,7 +2117,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2117
2117
|
readonly signature?: {
|
|
2118
2118
|
readonly scheme: string;
|
|
2119
2119
|
readonly message?: readonly (string | {
|
|
2120
|
-
readonly body: true;
|
|
2120
|
+
readonly body: true | "sorted-json";
|
|
2121
2121
|
} | {
|
|
2122
2122
|
readonly header: string;
|
|
2123
2123
|
} | {
|
|
@@ -2497,7 +2497,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2497
2497
|
readonly signature?: {
|
|
2498
2498
|
readonly scheme: string;
|
|
2499
2499
|
readonly message?: readonly (string | {
|
|
2500
|
-
readonly body: true;
|
|
2500
|
+
readonly body: true | "sorted-json";
|
|
2501
2501
|
} | {
|
|
2502
2502
|
readonly header: string;
|
|
2503
2503
|
} | {
|
|
@@ -2875,7 +2875,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2875
2875
|
readonly signature?: {
|
|
2876
2876
|
readonly scheme: string;
|
|
2877
2877
|
readonly message?: readonly (string | {
|
|
2878
|
-
readonly body: true;
|
|
2878
|
+
readonly body: true | "sorted-json";
|
|
2879
2879
|
} | {
|
|
2880
2880
|
readonly header: string;
|
|
2881
2881
|
} | {
|
|
@@ -3503,7 +3503,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3503
3503
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
3504
3504
|
}>>;
|
|
3505
3505
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
3506
|
-
readonly body: Schema.
|
|
3506
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
3507
3507
|
}>, Schema.Struct<{
|
|
3508
3508
|
readonly header: Schema.String;
|
|
3509
3509
|
}>, Schema.Struct<{
|
|
@@ -4020,7 +4020,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4020
4020
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
4021
4021
|
}>>;
|
|
4022
4022
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
4023
|
-
readonly body: Schema.
|
|
4023
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
4024
4024
|
}>, Schema.Struct<{
|
|
4025
4025
|
readonly header: Schema.String;
|
|
4026
4026
|
}>, Schema.Struct<{
|
|
@@ -4292,7 +4292,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4292
4292
|
readonly signature?: {
|
|
4293
4293
|
readonly scheme: string;
|
|
4294
4294
|
readonly message?: readonly (string | {
|
|
4295
|
-
readonly body: true;
|
|
4295
|
+
readonly body: true | "sorted-json";
|
|
4296
4296
|
} | {
|
|
4297
4297
|
readonly header: string;
|
|
4298
4298
|
} | {
|
|
@@ -4670,7 +4670,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4670
4670
|
readonly signature?: {
|
|
4671
4671
|
readonly scheme: string;
|
|
4672
4672
|
readonly message?: readonly (string | {
|
|
4673
|
-
readonly body: true;
|
|
4673
|
+
readonly body: true | "sorted-json";
|
|
4674
4674
|
} | {
|
|
4675
4675
|
readonly header: string;
|
|
4676
4676
|
} | {
|
|
@@ -5054,7 +5054,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
5054
5054
|
readonly signature?: {
|
|
5055
5055
|
readonly scheme: string;
|
|
5056
5056
|
readonly message?: readonly (string | {
|
|
5057
|
-
readonly body: true;
|
|
5057
|
+
readonly body: true | "sorted-json";
|
|
5058
5058
|
} | {
|
|
5059
5059
|
readonly header: string;
|
|
5060
5060
|
} | {
|
|
@@ -5432,7 +5432,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
5432
5432
|
readonly signature?: {
|
|
5433
5433
|
readonly scheme: string;
|
|
5434
5434
|
readonly message?: readonly (string | {
|
|
5435
|
-
readonly body: true;
|
|
5435
|
+
readonly body: true | "sorted-json";
|
|
5436
5436
|
} | {
|
|
5437
5437
|
readonly header: string;
|
|
5438
5438
|
} | {
|
package/dist/manifest.js
CHANGED
|
@@ -395,7 +395,7 @@ export const WebhookTriggerManifest = Schema.Struct({
|
|
|
395
395
|
})),
|
|
396
396
|
message: Schema.optionalKey(Schema.Array(Schema.Union([
|
|
397
397
|
Schema.String,
|
|
398
|
-
Schema.Struct({ body: Schema.
|
|
398
|
+
Schema.Struct({ body: Schema.Literals([true, "sorted-json"]) }),
|
|
399
399
|
Schema.Struct({ header: Schema.String }),
|
|
400
400
|
Schema.Struct({ timestamp: Schema.Literal(true) }),
|
|
401
401
|
]))),
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -479,7 +479,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
479
479
|
readonly signature?: {
|
|
480
480
|
readonly scheme: string;
|
|
481
481
|
readonly message?: readonly (string | {
|
|
482
|
-
readonly body: true;
|
|
482
|
+
readonly body: true | "sorted-json";
|
|
483
483
|
} | {
|
|
484
484
|
readonly header: string;
|
|
485
485
|
} | {
|
|
@@ -857,7 +857,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
857
857
|
readonly signature?: {
|
|
858
858
|
readonly scheme: string;
|
|
859
859
|
readonly message?: readonly (string | {
|
|
860
|
-
readonly body: true;
|
|
860
|
+
readonly body: true | "sorted-json";
|
|
861
861
|
} | {
|
|
862
862
|
readonly header: string;
|
|
863
863
|
} | {
|
|
@@ -1237,7 +1237,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1237
1237
|
readonly signature?: {
|
|
1238
1238
|
readonly scheme: string;
|
|
1239
1239
|
readonly message?: readonly (string | {
|
|
1240
|
-
readonly body: true;
|
|
1240
|
+
readonly body: true | "sorted-json";
|
|
1241
1241
|
} | {
|
|
1242
1242
|
readonly header: string;
|
|
1243
1243
|
} | {
|
|
@@ -1615,7 +1615,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1615
1615
|
readonly signature?: {
|
|
1616
1616
|
readonly scheme: string;
|
|
1617
1617
|
readonly message?: readonly (string | {
|
|
1618
|
-
readonly body: true;
|
|
1618
|
+
readonly body: true | "sorted-json";
|
|
1619
1619
|
} | {
|
|
1620
1620
|
readonly header: string;
|
|
1621
1621
|
} | {
|
|
@@ -2141,7 +2141,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2141
2141
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
2142
2142
|
}>>;
|
|
2143
2143
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
2144
|
-
readonly body: Schema.
|
|
2144
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
2145
2145
|
}>, Schema.Struct<{
|
|
2146
2146
|
readonly header: Schema.String;
|
|
2147
2147
|
}>, Schema.Struct<{
|
|
@@ -2517,7 +2517,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2517
2517
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
2518
2518
|
}>>;
|
|
2519
2519
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
2520
|
-
readonly body: Schema.
|
|
2520
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
2521
2521
|
}>, Schema.Struct<{
|
|
2522
2522
|
readonly header: Schema.String;
|
|
2523
2523
|
}>, Schema.Struct<{
|
|
@@ -2758,7 +2758,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2758
2758
|
readonly signature?: {
|
|
2759
2759
|
readonly scheme: string;
|
|
2760
2760
|
readonly message?: readonly (string | {
|
|
2761
|
-
readonly body: true;
|
|
2761
|
+
readonly body: true | "sorted-json";
|
|
2762
2762
|
} | {
|
|
2763
2763
|
readonly header: string;
|
|
2764
2764
|
} | {
|
|
@@ -3136,7 +3136,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
3136
3136
|
readonly signature?: {
|
|
3137
3137
|
readonly scheme: string;
|
|
3138
3138
|
readonly message?: readonly (string | {
|
|
3139
|
-
readonly body: true;
|
|
3139
|
+
readonly body: true | "sorted-json";
|
|
3140
3140
|
} | {
|
|
3141
3141
|
readonly header: string;
|
|
3142
3142
|
} | {
|
|
@@ -223,10 +223,12 @@ export function localConnections(context, fetchImpl = fetch) {
|
|
|
223
223
|
if (granted === undefined) {
|
|
224
224
|
return Effect.fail(failure(call.connection, "not_granted", `Run the service with segmentstream exec --connection ${call.connection}.`));
|
|
225
225
|
}
|
|
226
|
-
|
|
226
|
+
// The connection's default API, or its only one, as the connections SDK's client chooses.
|
|
227
|
+
const declared = Object.keys(granted.apis);
|
|
228
|
+
const api = call.api ?? granted.defaultApi ?? (declared.length === 1 ? declared[0] : undefined);
|
|
227
229
|
if (api === undefined || !(api in granted.apis)) {
|
|
228
230
|
return Effect.fail(failure(call.connection, "invalid_request", api === undefined
|
|
229
|
-
? `The connection ${call.connection}
|
|
231
|
+
? `The connection ${call.connection} declares several APIs and no default; set api.`
|
|
230
232
|
: `The connection ${call.connection} declares no API named ${api}.`));
|
|
231
233
|
}
|
|
232
234
|
return Effect.succeed({
|
|
@@ -641,7 +641,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
641
641
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
642
642
|
}>>;
|
|
643
643
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
644
|
-
readonly body: Schema.
|
|
644
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
645
645
|
}>, Schema.Struct<{
|
|
646
646
|
readonly header: Schema.String;
|
|
647
647
|
}>, Schema.Struct<{
|
|
@@ -1032,7 +1032,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
1032
1032
|
readonly tolerance: Schema.optionalKey<Schema.Number>;
|
|
1033
1033
|
}>>;
|
|
1034
1034
|
readonly message: Schema.optionalKey<Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
1035
|
-
readonly body: Schema.
|
|
1035
|
+
readonly body: Schema.Literals<readonly [true, "sorted-json"]>;
|
|
1036
1036
|
}>, Schema.Struct<{
|
|
1037
1037
|
readonly header: Schema.String;
|
|
1038
1038
|
}>, Schema.Struct<{
|
|
@@ -107,6 +107,13 @@ export declare const STRIPE_TOLERANCE_SECONDS = 300;
|
|
|
107
107
|
* is SegmentStream's, which holds the secret.
|
|
108
108
|
*/
|
|
109
109
|
export declare function hmacSignature(format: WebhookHmacFormat): SignatureScheme;
|
|
110
|
+
/**
|
|
111
|
+
* The body re-serialized as a provider signs it with `{ body: "sorted-json" }`: parsed as a JSON
|
|
112
|
+
* object and written compactly with every object's keys sorted, exactly as
|
|
113
|
+
* `JSON.stringify(sortObject(JSON.parse(body)))` writes it in Node; arrays keep their order.
|
|
114
|
+
* `undefined` when the body is not UTF-8 JSON whose top level is an object.
|
|
115
|
+
*/
|
|
116
|
+
export declare function sortedJson(body: Uint8Array): string | undefined;
|
|
110
117
|
/**
|
|
111
118
|
* Stripe's `Stripe-Signature`: `t=<unix seconds>` and one or more `v1=<hex>`. The signed bytes are
|
|
112
119
|
* `<t>.` followed by the raw body; the HMAC is SHA-256 keyed with the whole `whsec_…` string.
|
package/dist/service/webhooks.js
CHANGED
|
@@ -197,7 +197,16 @@ export function hmacSignature(format) {
|
|
|
197
197
|
parts.push(encoder.encode(part));
|
|
198
198
|
}
|
|
199
199
|
else if ("body" in part) {
|
|
200
|
-
|
|
200
|
+
if (part.body === true) {
|
|
201
|
+
parts.push(body);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const sorted = sortedJson(body);
|
|
205
|
+
if (sorted === undefined) {
|
|
206
|
+
return { ok: false, reason: "signature_malformed" };
|
|
207
|
+
}
|
|
208
|
+
parts.push(encoder.encode(sorted));
|
|
209
|
+
}
|
|
201
210
|
}
|
|
202
211
|
else if ("timestamp" in part) {
|
|
203
212
|
parts.push(encoder.encode(timestamp ?? ""));
|
|
@@ -222,6 +231,35 @@ export function hmacSignature(format) {
|
|
|
222
231
|
return { ok: true, message, signatures };
|
|
223
232
|
};
|
|
224
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* The body re-serialized as a provider signs it with `{ body: "sorted-json" }`: parsed as a JSON
|
|
236
|
+
* object and written compactly with every object's keys sorted, exactly as
|
|
237
|
+
* `JSON.stringify(sortObject(JSON.parse(body)))` writes it in Node; arrays keep their order.
|
|
238
|
+
* `undefined` when the body is not UTF-8 JSON whose top level is an object.
|
|
239
|
+
*/
|
|
240
|
+
export function sortedJson(body) {
|
|
241
|
+
const text = utf8Text(body);
|
|
242
|
+
let parsed;
|
|
243
|
+
if (text === undefined) {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
parsed = JSON.parse(text);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
// Object.fromEntries defines each key as an own property, `__proto__` included, and
|
|
256
|
+
// JSON.stringify writes integer keys first, as it does for the provider's own sorted object.
|
|
257
|
+
return JSON.stringify(parsed, (_key, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
258
|
+
? Object.fromEntries(Object.keys(value)
|
|
259
|
+
.sort()
|
|
260
|
+
.map((key) => [key, value[key]]))
|
|
261
|
+
: value);
|
|
262
|
+
}
|
|
225
263
|
/**
|
|
226
264
|
* Stripe's `Stripe-Signature`: `t=<unix seconds>` and one or more `v1=<hex>`. The signed bytes are
|
|
227
265
|
* `<t>.` followed by the raw body; the HMAC is SHA-256 keyed with the whole `whsec_…` string.
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -18,9 +18,16 @@ export declare const WEBHOOK_SIGNATURE_ENCODINGS: readonly ["hex", "base64"];
|
|
|
18
18
|
export type WebhookSignatureEncoding = (typeof WEBHOOK_SIGNATURE_ENCODINGS)[number];
|
|
19
19
|
/** The bytes of each algorithm's digest, which a signature must decode to. */
|
|
20
20
|
export declare const WEBHOOK_HMAC_DIGEST_BYTES: Readonly<Record<WebhookHmacAlgorithm, number>>;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* How a signed message includes the delivery's body: `true` its raw bytes, `"sorted-json"` the
|
|
23
|
+
* body parsed as a JSON object and written again compactly with the keys of every object sorted,
|
|
24
|
+
* as `JSON.stringify` writes it, for providers that sign such a re-serialization.
|
|
25
|
+
*/
|
|
26
|
+
export declare const WEBHOOK_SIGNED_BODIES: readonly [true, "sorted-json"];
|
|
27
|
+
export type WebhookSignedBody = (typeof WEBHOOK_SIGNED_BODIES)[number];
|
|
28
|
+
/** One piece of the signed bytes: text, the body, a header's value or the timestamp. */
|
|
22
29
|
export type WebhookSignedPart = string | {
|
|
23
|
-
readonly body:
|
|
30
|
+
readonly body: WebhookSignedBody;
|
|
24
31
|
} | {
|
|
25
32
|
readonly header: string;
|
|
26
33
|
} | {
|
package/dist/webhooks.js
CHANGED
|
@@ -20,6 +20,12 @@ export const WEBHOOK_HMAC_DIGEST_BYTES = {
|
|
|
20
20
|
sha256: 32,
|
|
21
21
|
sha512: 64,
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* How a signed message includes the delivery's body: `true` its raw bytes, `"sorted-json"` the
|
|
25
|
+
* body parsed as a JSON object and written again compactly with the keys of every object sorted,
|
|
26
|
+
* as `JSON.stringify` writes it, for providers that sign such a re-serialization.
|
|
27
|
+
*/
|
|
28
|
+
export const WEBHOOK_SIGNED_BODIES = [true, "sorted-json"];
|
|
23
29
|
/** How far a signed timestamp may be from a delivery's arrival by default, in seconds. */
|
|
24
30
|
export const WEBHOOK_TIMESTAMP_TOLERANCE_SECONDS = 300;
|
|
25
31
|
/** The widest tolerance a format may declare, in seconds. */
|
|
@@ -241,8 +247,11 @@ export function webhookSignatureProblems(signature) {
|
|
|
241
247
|
report(at, `A text part has 1 to ${MAX_WEBHOOK_MESSAGE_TEXT} characters.`);
|
|
242
248
|
}
|
|
243
249
|
}
|
|
244
|
-
else if (isRecord(part) && Object.keys(part).length === 1 &&
|
|
250
|
+
else if (isRecord(part) && Object.keys(part).length === 1 && "body" in part) {
|
|
245
251
|
bodies += 1;
|
|
252
|
+
if (!WEBHOOK_SIGNED_BODIES.includes(part.body)) {
|
|
253
|
+
report(at, 'The body is signed as { body: true } or { body: "sorted-json" }.');
|
|
254
|
+
}
|
|
246
255
|
}
|
|
247
256
|
else if (isRecord(part) && Object.keys(part).length === 1 && part.timestamp === true) {
|
|
248
257
|
if (!timed) {
|
|
@@ -256,11 +265,11 @@ export function webhookSignatureProblems(signature) {
|
|
|
256
265
|
}
|
|
257
266
|
}
|
|
258
267
|
else {
|
|
259
|
-
report(at,
|
|
268
|
+
report(at, 'A part is text, { body: true }, { body: "sorted-json" }, { header } or { timestamp: true }.');
|
|
260
269
|
}
|
|
261
270
|
}
|
|
262
271
|
if (bodies !== 1) {
|
|
263
|
-
report("message", "message includes { body
|
|
272
|
+
report("message", "message includes the body, as { body }, exactly once.");
|
|
264
273
|
}
|
|
265
274
|
}
|
|
266
275
|
}
|
|
@@ -336,7 +345,7 @@ export function webhookSignatureManifest(signature) {
|
|
|
336
345
|
message: message.map((part) => typeof part === "string"
|
|
337
346
|
? part
|
|
338
347
|
: "body" in part
|
|
339
|
-
? { body:
|
|
348
|
+
? { body: part.body }
|
|
340
349
|
: "timestamp" in part
|
|
341
350
|
? { timestamp: true }
|
|
342
351
|
: { header: part.header }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.170.1",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|