@segmentstream/ontology 0.127.0 → 0.128.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/CHANGELOG.md +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/manifest.d.ts +43 -15
- package/dist/manifest.js +7 -2
- package/dist/migrate/model.d.ts +16 -8
- package/dist/service/schemas.d.ts +4 -2
- package/dist/service/webhooks.d.ts +12 -0
- package/dist/service/webhooks.js +16 -0
- package/dist/service/workflows.js +49 -23
- package/dist/webhook-token.d.ts +19 -0
- package/dist/webhook-token.js +34 -0
- package/dist/webhooks.d.ts +21 -7
- package/dist/webhooks.js +31 -7
- package/dist/workflow.d.ts +15 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.128.0
|
|
4
|
+
|
|
5
|
+
A webhook whose provider lets the caller choose the signing secret can be signed and registered
|
|
6
|
+
from code: `signature: { scheme, generated: true, … }` takes the place of `secret`, and
|
|
7
|
+
`webhookSigningSecret(trigger)`, from `@segmentstream/ontology`, returns the secret to register.
|
|
8
|
+
SegmentStream derives it from the workspace's webhook secret and the webhook's name, so it needs
|
|
9
|
+
no storing and survives deploys; the ontology service checks deliveries with it. Like a token URL,
|
|
10
|
+
it is for the provider only.
|
|
11
|
+
|
|
3
12
|
## 0.127.0
|
|
4
13
|
|
|
5
14
|
A `find` MCP tool's `where` takes `{ "$me": [] }`, as a role scope writes `me`, for the caller's
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire
|
|
|
31
31
|
export type { MeReference } from "./me.js";
|
|
32
32
|
export { check, defineOntology } from "./ontology.js";
|
|
33
33
|
export { webhookDeliveryJsonSchema } from "./analyze.js";
|
|
34
|
-
export { webhookToken, webhookTokenMatches, webhookUrl, WebhookUrlUnavailable, WEBHOOK_ORIGIN_VARIABLE, WEBHOOK_TOKEN_CONTEXT, } from "./webhook-token.js";
|
|
34
|
+
export { webhookSigningKey, webhookSigningSecret, webhookToken, webhookTokenMatches, webhookUrl, WebhookUrlUnavailable, WEBHOOK_ORIGIN_VARIABLE, WEBHOOK_SIGNING_CONTEXT, WEBHOOK_TOKEN_CONTEXT, } from "./webhook-token.js";
|
|
35
35
|
export type { Ontology } from "./ontology.js";
|
|
36
36
|
export { AGENT_TOOL_VERBS, agentToolPermission, agentToolsOf, DEFAULT_MEMBER_PERMISSIONS, effectiveScope, generatedActionPermissions, grants, isAllowed, parsePermission, permissionsOf, principalScopes, READ_VERB, readScope, rolesGranting, scopesOf, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, WILDCARD_ENTITY_VERBS, WORKSPACE_SOURCE_PERMISSION, } from "./permissions.js";
|
|
37
37
|
export type { AgentToolVerb, ParsedPermission, PermissionHolder, RolePermissions, ScopedPermission, ScopeFilter, ScopeValue, ScopeWhere, UserMemberVerb, } from "./permissions.js";
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export { SYSTEM_PROPERTIES } from "./names.js";
|
|
|
18
18
|
export { isMe, isMeMarker, MAX_ME_HOPS, me, ME_KEY, MeMarker, mePathOf, meToWire, MeTypeId, } from "./me.js";
|
|
19
19
|
export { check, defineOntology } from "./ontology.js";
|
|
20
20
|
export { webhookDeliveryJsonSchema } from "./analyze.js";
|
|
21
|
-
export { webhookToken, webhookTokenMatches, webhookUrl, WebhookUrlUnavailable, WEBHOOK_ORIGIN_VARIABLE, WEBHOOK_TOKEN_CONTEXT, } from "./webhook-token.js";
|
|
21
|
+
export { webhookSigningKey, webhookSigningSecret, webhookToken, webhookTokenMatches, webhookUrl, WebhookUrlUnavailable, WEBHOOK_ORIGIN_VARIABLE, WEBHOOK_SIGNING_CONTEXT, WEBHOOK_TOKEN_CONTEXT, } from "./webhook-token.js";
|
|
22
22
|
export { AGENT_TOOL_VERBS, agentToolPermission, agentToolsOf, DEFAULT_MEMBER_PERMISSIONS, effectiveScope, generatedActionPermissions, grants, isAllowed, parsePermission, permissionsOf, principalScopes, READ_VERB, readScope, rolesGranting, scopesOf, USER_IDENTITY_VERBS, USER_MEMBER_VERBS, WILDCARD, WILDCARD_ENTITY_VERBS, WORKSPACE_SOURCE_PERMISSION, } from "./permissions.js";
|
|
23
23
|
export { p, PROPERTY_TYPES, propertyDefinition } from "./property.js";
|
|
24
24
|
export { ON_DELETE, rel } from "./relationship.js";
|
package/dist/manifest.d.ts
CHANGED
|
@@ -95,7 +95,9 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
|
|
|
95
95
|
* agent. Older readers ignore it, register none and let none be taken over.
|
|
96
96
|
* Within version 15, a webhook trigger's `signature` may have scheme `hmac` and carry the provider's
|
|
97
97
|
* format, written only when declared. Older readers present the scheme and ignore the format; an
|
|
98
|
-
* older publication check refuses the scheme.
|
|
98
|
+
* older publication check refuses the scheme. A signature may carry `generated: true` instead of
|
|
99
|
+
* `secret`: the platform derives the webhook's secret. Older readers find no secret name; an older
|
|
100
|
+
* publication check refuses it.
|
|
99
101
|
*/
|
|
100
102
|
export declare const MANIFEST_VERSION = 15;
|
|
101
103
|
/** The phrase used for a direction the author did not phrase. */
|
|
@@ -479,7 +481,10 @@ export declare const WebhookTriggerManifest: Schema.Struct<{
|
|
|
479
481
|
readonly description: Schema.String;
|
|
480
482
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
481
483
|
readonly scheme: Schema.String;
|
|
482
|
-
|
|
484
|
+
/** The workspace secret's name; absent when the secret is `generated`. */
|
|
485
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
486
|
+
/** The platform derives the secret for the webhook; workspace code registers it. */
|
|
487
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
483
488
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
484
489
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
485
490
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -547,7 +552,10 @@ export declare const WorkflowTriggerManifest: Schema.Union<readonly [Schema.Stru
|
|
|
547
552
|
readonly description: Schema.String;
|
|
548
553
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
549
554
|
readonly scheme: Schema.String;
|
|
550
|
-
|
|
555
|
+
/** The workspace secret's name; absent when the secret is `generated`. */
|
|
556
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
557
|
+
/** The platform derives the secret for the webhook; workspace code registers it. */
|
|
558
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
551
559
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
552
560
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
553
561
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -622,7 +630,10 @@ export declare const WorkflowManifest: Schema.Struct<{
|
|
|
622
630
|
readonly description: Schema.String;
|
|
623
631
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
624
632
|
readonly scheme: Schema.String;
|
|
625
|
-
|
|
633
|
+
/** The workspace secret's name; absent when the secret is `generated`. */
|
|
634
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
635
|
+
/** The platform derives the secret for the webhook; workspace code registers it. */
|
|
636
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
626
637
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
627
638
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
628
639
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -1326,7 +1337,10 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1326
1337
|
readonly description: Schema.String;
|
|
1327
1338
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
1328
1339
|
readonly scheme: Schema.String;
|
|
1329
|
-
|
|
1340
|
+
/** The workspace secret's name; absent when the secret is `generated`. */
|
|
1341
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
1342
|
+
/** The platform derives the secret for the webhook; workspace code registers it. */
|
|
1343
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
1330
1344
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
1331
1345
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
1332
1346
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -1603,7 +1617,6 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1603
1617
|
readonly headers?: readonly string[] | undefined;
|
|
1604
1618
|
readonly signature?: {
|
|
1605
1619
|
readonly scheme: string;
|
|
1606
|
-
readonly secret: string;
|
|
1607
1620
|
readonly message?: readonly (string | {
|
|
1608
1621
|
readonly body: true;
|
|
1609
1622
|
} | {
|
|
@@ -1621,6 +1634,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1621
1634
|
readonly tolerance?: number | undefined;
|
|
1622
1635
|
readonly header?: string | undefined;
|
|
1623
1636
|
} | undefined;
|
|
1637
|
+
readonly generated?: true | undefined;
|
|
1624
1638
|
readonly algorithm?: string | undefined;
|
|
1625
1639
|
readonly encoding?: string | undefined;
|
|
1626
1640
|
readonly signatures?: {
|
|
@@ -1632,6 +1646,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1632
1646
|
} | undefined;
|
|
1633
1647
|
readonly prefix?: string | undefined;
|
|
1634
1648
|
} | undefined;
|
|
1649
|
+
readonly secret?: string | undefined;
|
|
1635
1650
|
} | undefined;
|
|
1636
1651
|
readonly verification?: {
|
|
1637
1652
|
readonly scheme: string;
|
|
@@ -1951,7 +1966,6 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1951
1966
|
readonly headers?: readonly string[] | undefined;
|
|
1952
1967
|
readonly signature?: {
|
|
1953
1968
|
readonly scheme: string;
|
|
1954
|
-
readonly secret: string;
|
|
1955
1969
|
readonly message?: readonly (string | {
|
|
1956
1970
|
readonly body: true;
|
|
1957
1971
|
} | {
|
|
@@ -1969,6 +1983,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1969
1983
|
readonly tolerance?: number | undefined;
|
|
1970
1984
|
readonly header?: string | undefined;
|
|
1971
1985
|
} | undefined;
|
|
1986
|
+
readonly generated?: true | undefined;
|
|
1972
1987
|
readonly algorithm?: string | undefined;
|
|
1973
1988
|
readonly encoding?: string | undefined;
|
|
1974
1989
|
readonly signatures?: {
|
|
@@ -1980,6 +1995,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1980
1995
|
} | undefined;
|
|
1981
1996
|
readonly prefix?: string | undefined;
|
|
1982
1997
|
} | undefined;
|
|
1998
|
+
readonly secret?: string | undefined;
|
|
1983
1999
|
} | undefined;
|
|
1984
2000
|
readonly verification?: {
|
|
1985
2001
|
readonly scheme: string;
|
|
@@ -2301,7 +2317,6 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2301
2317
|
readonly headers?: readonly string[] | undefined;
|
|
2302
2318
|
readonly signature?: {
|
|
2303
2319
|
readonly scheme: string;
|
|
2304
|
-
readonly secret: string;
|
|
2305
2320
|
readonly message?: readonly (string | {
|
|
2306
2321
|
readonly body: true;
|
|
2307
2322
|
} | {
|
|
@@ -2319,6 +2334,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2319
2334
|
readonly tolerance?: number | undefined;
|
|
2320
2335
|
readonly header?: string | undefined;
|
|
2321
2336
|
} | undefined;
|
|
2337
|
+
readonly generated?: true | undefined;
|
|
2322
2338
|
readonly algorithm?: string | undefined;
|
|
2323
2339
|
readonly encoding?: string | undefined;
|
|
2324
2340
|
readonly signatures?: {
|
|
@@ -2330,6 +2346,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2330
2346
|
} | undefined;
|
|
2331
2347
|
readonly prefix?: string | undefined;
|
|
2332
2348
|
} | undefined;
|
|
2349
|
+
readonly secret?: string | undefined;
|
|
2333
2350
|
} | undefined;
|
|
2334
2351
|
readonly verification?: {
|
|
2335
2352
|
readonly scheme: string;
|
|
@@ -2649,7 +2666,6 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2649
2666
|
readonly headers?: readonly string[] | undefined;
|
|
2650
2667
|
readonly signature?: {
|
|
2651
2668
|
readonly scheme: string;
|
|
2652
|
-
readonly secret: string;
|
|
2653
2669
|
readonly message?: readonly (string | {
|
|
2654
2670
|
readonly body: true;
|
|
2655
2671
|
} | {
|
|
@@ -2667,6 +2683,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2667
2683
|
readonly tolerance?: number | undefined;
|
|
2668
2684
|
readonly header?: string | undefined;
|
|
2669
2685
|
} | undefined;
|
|
2686
|
+
readonly generated?: true | undefined;
|
|
2670
2687
|
readonly algorithm?: string | undefined;
|
|
2671
2688
|
readonly encoding?: string | undefined;
|
|
2672
2689
|
readonly signatures?: {
|
|
@@ -2678,6 +2695,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2678
2695
|
} | undefined;
|
|
2679
2696
|
readonly prefix?: string | undefined;
|
|
2680
2697
|
} | undefined;
|
|
2698
|
+
readonly secret?: string | undefined;
|
|
2681
2699
|
} | undefined;
|
|
2682
2700
|
readonly verification?: {
|
|
2683
2701
|
readonly scheme: string;
|
|
@@ -3195,7 +3213,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3195
3213
|
readonly description: Schema.String;
|
|
3196
3214
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
3197
3215
|
readonly scheme: Schema.String;
|
|
3198
|
-
|
|
3216
|
+
/** The workspace secret's name; absent when the secret is `generated`. */
|
|
3217
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
3218
|
+
/** The platform derives the secret for the webhook; workspace code registers it. */
|
|
3219
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
3199
3220
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
3200
3221
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
3201
3222
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -3659,7 +3680,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3659
3680
|
readonly description: Schema.String;
|
|
3660
3681
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
3661
3682
|
readonly scheme: Schema.String;
|
|
3662
|
-
|
|
3683
|
+
/** The workspace secret's name; absent when the secret is `generated`. */
|
|
3684
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
3685
|
+
/** The platform derives the secret for the webhook; workspace code registers it. */
|
|
3686
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
3663
3687
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
3664
3688
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
3665
3689
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -3928,7 +3952,6 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3928
3952
|
readonly headers?: readonly string[] | undefined;
|
|
3929
3953
|
readonly signature?: {
|
|
3930
3954
|
readonly scheme: string;
|
|
3931
|
-
readonly secret: string;
|
|
3932
3955
|
readonly message?: readonly (string | {
|
|
3933
3956
|
readonly body: true;
|
|
3934
3957
|
} | {
|
|
@@ -3946,6 +3969,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3946
3969
|
readonly tolerance?: number | undefined;
|
|
3947
3970
|
readonly header?: string | undefined;
|
|
3948
3971
|
} | undefined;
|
|
3972
|
+
readonly generated?: true | undefined;
|
|
3949
3973
|
readonly algorithm?: string | undefined;
|
|
3950
3974
|
readonly encoding?: string | undefined;
|
|
3951
3975
|
readonly signatures?: {
|
|
@@ -3957,6 +3981,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3957
3981
|
} | undefined;
|
|
3958
3982
|
readonly prefix?: string | undefined;
|
|
3959
3983
|
} | undefined;
|
|
3984
|
+
readonly secret?: string | undefined;
|
|
3960
3985
|
} | undefined;
|
|
3961
3986
|
readonly verification?: {
|
|
3962
3987
|
readonly scheme: string;
|
|
@@ -4276,7 +4301,6 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4276
4301
|
readonly headers?: readonly string[] | undefined;
|
|
4277
4302
|
readonly signature?: {
|
|
4278
4303
|
readonly scheme: string;
|
|
4279
|
-
readonly secret: string;
|
|
4280
4304
|
readonly message?: readonly (string | {
|
|
4281
4305
|
readonly body: true;
|
|
4282
4306
|
} | {
|
|
@@ -4294,6 +4318,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4294
4318
|
readonly tolerance?: number | undefined;
|
|
4295
4319
|
readonly header?: string | undefined;
|
|
4296
4320
|
} | undefined;
|
|
4321
|
+
readonly generated?: true | undefined;
|
|
4297
4322
|
readonly algorithm?: string | undefined;
|
|
4298
4323
|
readonly encoding?: string | undefined;
|
|
4299
4324
|
readonly signatures?: {
|
|
@@ -4305,6 +4330,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4305
4330
|
} | undefined;
|
|
4306
4331
|
readonly prefix?: string | undefined;
|
|
4307
4332
|
} | undefined;
|
|
4333
|
+
readonly secret?: string | undefined;
|
|
4308
4334
|
} | undefined;
|
|
4309
4335
|
readonly verification?: {
|
|
4310
4336
|
readonly scheme: string;
|
|
@@ -4630,7 +4656,6 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4630
4656
|
readonly headers?: readonly string[] | undefined;
|
|
4631
4657
|
readonly signature?: {
|
|
4632
4658
|
readonly scheme: string;
|
|
4633
|
-
readonly secret: string;
|
|
4634
4659
|
readonly message?: readonly (string | {
|
|
4635
4660
|
readonly body: true;
|
|
4636
4661
|
} | {
|
|
@@ -4648,6 +4673,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4648
4673
|
readonly tolerance?: number | undefined;
|
|
4649
4674
|
readonly header?: string | undefined;
|
|
4650
4675
|
} | undefined;
|
|
4676
|
+
readonly generated?: true | undefined;
|
|
4651
4677
|
readonly algorithm?: string | undefined;
|
|
4652
4678
|
readonly encoding?: string | undefined;
|
|
4653
4679
|
readonly signatures?: {
|
|
@@ -4659,6 +4685,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4659
4685
|
} | undefined;
|
|
4660
4686
|
readonly prefix?: string | undefined;
|
|
4661
4687
|
} | undefined;
|
|
4688
|
+
readonly secret?: string | undefined;
|
|
4662
4689
|
} | undefined;
|
|
4663
4690
|
readonly verification?: {
|
|
4664
4691
|
readonly scheme: string;
|
|
@@ -4978,7 +5005,6 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4978
5005
|
readonly headers?: readonly string[] | undefined;
|
|
4979
5006
|
readonly signature?: {
|
|
4980
5007
|
readonly scheme: string;
|
|
4981
|
-
readonly secret: string;
|
|
4982
5008
|
readonly message?: readonly (string | {
|
|
4983
5009
|
readonly body: true;
|
|
4984
5010
|
} | {
|
|
@@ -4996,6 +5022,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4996
5022
|
readonly tolerance?: number | undefined;
|
|
4997
5023
|
readonly header?: string | undefined;
|
|
4998
5024
|
} | undefined;
|
|
5025
|
+
readonly generated?: true | undefined;
|
|
4999
5026
|
readonly algorithm?: string | undefined;
|
|
5000
5027
|
readonly encoding?: string | undefined;
|
|
5001
5028
|
readonly signatures?: {
|
|
@@ -5007,6 +5034,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
5007
5034
|
} | undefined;
|
|
5008
5035
|
readonly prefix?: string | undefined;
|
|
5009
5036
|
} | undefined;
|
|
5037
|
+
readonly secret?: string | undefined;
|
|
5010
5038
|
} | undefined;
|
|
5011
5039
|
readonly verification?: {
|
|
5012
5040
|
readonly scheme: string;
|
package/dist/manifest.js
CHANGED
|
@@ -96,7 +96,9 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
|
|
|
96
96
|
* agent. Older readers ignore it, register none and let none be taken over.
|
|
97
97
|
* Within version 15, a webhook trigger's `signature` may have scheme `hmac` and carry the provider's
|
|
98
98
|
* format, written only when declared. Older readers present the scheme and ignore the format; an
|
|
99
|
-
* older publication check refuses the scheme.
|
|
99
|
+
* older publication check refuses the scheme. A signature may carry `generated: true` instead of
|
|
100
|
+
* `secret`: the platform derives the webhook's secret. Older readers find no secret name; an older
|
|
101
|
+
* publication check refuses it.
|
|
100
102
|
*/
|
|
101
103
|
export const MANIFEST_VERSION = 15;
|
|
102
104
|
/** The first version whose documents use snake_case names on the wire. */
|
|
@@ -350,7 +352,10 @@ export const WebhookTriggerManifest = Schema.Struct({
|
|
|
350
352
|
description: Schema.String,
|
|
351
353
|
signature: Schema.optionalKey(Schema.Struct({
|
|
352
354
|
scheme: Schema.String,
|
|
353
|
-
secret
|
|
355
|
+
/** The workspace secret's name; absent when the secret is `generated`. */
|
|
356
|
+
secret: Schema.optionalKey(Schema.String),
|
|
357
|
+
/** The platform derives the secret for the webhook; workspace code registers it. */
|
|
358
|
+
generated: Schema.optionalKey(Schema.Literal(true)),
|
|
354
359
|
algorithm: Schema.optionalKey(Schema.String),
|
|
355
360
|
encoding: Schema.optionalKey(Schema.String),
|
|
356
361
|
key: Schema.optionalKey(Schema.Struct({ decode: Schema.String, prefix: Schema.optionalKey(Schema.String) })),
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -448,7 +448,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
448
448
|
readonly headers?: readonly string[] | undefined;
|
|
449
449
|
readonly signature?: {
|
|
450
450
|
readonly scheme: string;
|
|
451
|
-
readonly secret: string;
|
|
452
451
|
readonly message?: readonly (string | {
|
|
453
452
|
readonly body: true;
|
|
454
453
|
} | {
|
|
@@ -466,6 +465,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
466
465
|
readonly tolerance?: number | undefined;
|
|
467
466
|
readonly header?: string | undefined;
|
|
468
467
|
} | undefined;
|
|
468
|
+
readonly generated?: true | undefined;
|
|
469
469
|
readonly algorithm?: string | undefined;
|
|
470
470
|
readonly encoding?: string | undefined;
|
|
471
471
|
readonly signatures?: {
|
|
@@ -477,6 +477,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
477
477
|
} | undefined;
|
|
478
478
|
readonly prefix?: string | undefined;
|
|
479
479
|
} | undefined;
|
|
480
|
+
readonly secret?: string | undefined;
|
|
480
481
|
} | undefined;
|
|
481
482
|
readonly verification?: {
|
|
482
483
|
readonly scheme: string;
|
|
@@ -796,7 +797,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
796
797
|
readonly headers?: readonly string[] | undefined;
|
|
797
798
|
readonly signature?: {
|
|
798
799
|
readonly scheme: string;
|
|
799
|
-
readonly secret: string;
|
|
800
800
|
readonly message?: readonly (string | {
|
|
801
801
|
readonly body: true;
|
|
802
802
|
} | {
|
|
@@ -814,6 +814,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
814
814
|
readonly tolerance?: number | undefined;
|
|
815
815
|
readonly header?: string | undefined;
|
|
816
816
|
} | undefined;
|
|
817
|
+
readonly generated?: true | undefined;
|
|
817
818
|
readonly algorithm?: string | undefined;
|
|
818
819
|
readonly encoding?: string | undefined;
|
|
819
820
|
readonly signatures?: {
|
|
@@ -825,6 +826,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
825
826
|
} | undefined;
|
|
826
827
|
readonly prefix?: string | undefined;
|
|
827
828
|
} | undefined;
|
|
829
|
+
readonly secret?: string | undefined;
|
|
828
830
|
} | undefined;
|
|
829
831
|
readonly verification?: {
|
|
830
832
|
readonly scheme: string;
|
|
@@ -1146,7 +1148,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1146
1148
|
readonly headers?: readonly string[] | undefined;
|
|
1147
1149
|
readonly signature?: {
|
|
1148
1150
|
readonly scheme: string;
|
|
1149
|
-
readonly secret: string;
|
|
1150
1151
|
readonly message?: readonly (string | {
|
|
1151
1152
|
readonly body: true;
|
|
1152
1153
|
} | {
|
|
@@ -1164,6 +1165,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1164
1165
|
readonly tolerance?: number | undefined;
|
|
1165
1166
|
readonly header?: string | undefined;
|
|
1166
1167
|
} | undefined;
|
|
1168
|
+
readonly generated?: true | undefined;
|
|
1167
1169
|
readonly algorithm?: string | undefined;
|
|
1168
1170
|
readonly encoding?: string | undefined;
|
|
1169
1171
|
readonly signatures?: {
|
|
@@ -1175,6 +1177,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1175
1177
|
} | undefined;
|
|
1176
1178
|
readonly prefix?: string | undefined;
|
|
1177
1179
|
} | undefined;
|
|
1180
|
+
readonly secret?: string | undefined;
|
|
1178
1181
|
} | undefined;
|
|
1179
1182
|
readonly verification?: {
|
|
1180
1183
|
readonly scheme: string;
|
|
@@ -1494,7 +1497,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1494
1497
|
readonly headers?: readonly string[] | undefined;
|
|
1495
1498
|
readonly signature?: {
|
|
1496
1499
|
readonly scheme: string;
|
|
1497
|
-
readonly secret: string;
|
|
1498
1500
|
readonly message?: readonly (string | {
|
|
1499
1501
|
readonly body: true;
|
|
1500
1502
|
} | {
|
|
@@ -1512,6 +1514,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1512
1514
|
readonly tolerance?: number | undefined;
|
|
1513
1515
|
readonly header?: string | undefined;
|
|
1514
1516
|
} | undefined;
|
|
1517
|
+
readonly generated?: true | undefined;
|
|
1515
1518
|
readonly algorithm?: string | undefined;
|
|
1516
1519
|
readonly encoding?: string | undefined;
|
|
1517
1520
|
readonly signatures?: {
|
|
@@ -1523,6 +1526,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1523
1526
|
} | undefined;
|
|
1524
1527
|
readonly prefix?: string | undefined;
|
|
1525
1528
|
} | undefined;
|
|
1529
|
+
readonly secret?: string | undefined;
|
|
1526
1530
|
} | undefined;
|
|
1527
1531
|
readonly verification?: {
|
|
1528
1532
|
readonly scheme: string;
|
|
@@ -1957,7 +1961,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1957
1961
|
readonly description: Schema.String;
|
|
1958
1962
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
1959
1963
|
readonly scheme: Schema.String;
|
|
1960
|
-
readonly secret: Schema.String
|
|
1964
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
1965
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
1961
1966
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
1962
1967
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
1963
1968
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -2301,7 +2306,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2301
2306
|
readonly description: Schema.String;
|
|
2302
2307
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
2303
2308
|
readonly scheme: Schema.String;
|
|
2304
|
-
readonly secret: Schema.String
|
|
2309
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
2310
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
2305
2311
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
2306
2312
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
2307
2313
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -2541,7 +2547,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2541
2547
|
readonly headers?: readonly string[] | undefined;
|
|
2542
2548
|
readonly signature?: {
|
|
2543
2549
|
readonly scheme: string;
|
|
2544
|
-
readonly secret: string;
|
|
2545
2550
|
readonly message?: readonly (string | {
|
|
2546
2551
|
readonly body: true;
|
|
2547
2552
|
} | {
|
|
@@ -2559,6 +2564,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2559
2564
|
readonly tolerance?: number | undefined;
|
|
2560
2565
|
readonly header?: string | undefined;
|
|
2561
2566
|
} | undefined;
|
|
2567
|
+
readonly generated?: true | undefined;
|
|
2562
2568
|
readonly algorithm?: string | undefined;
|
|
2563
2569
|
readonly encoding?: string | undefined;
|
|
2564
2570
|
readonly signatures?: {
|
|
@@ -2570,6 +2576,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2570
2576
|
} | undefined;
|
|
2571
2577
|
readonly prefix?: string | undefined;
|
|
2572
2578
|
} | undefined;
|
|
2579
|
+
readonly secret?: string | undefined;
|
|
2573
2580
|
} | undefined;
|
|
2574
2581
|
readonly verification?: {
|
|
2575
2582
|
readonly scheme: string;
|
|
@@ -2889,7 +2896,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2889
2896
|
readonly headers?: readonly string[] | undefined;
|
|
2890
2897
|
readonly signature?: {
|
|
2891
2898
|
readonly scheme: string;
|
|
2892
|
-
readonly secret: string;
|
|
2893
2899
|
readonly message?: readonly (string | {
|
|
2894
2900
|
readonly body: true;
|
|
2895
2901
|
} | {
|
|
@@ -2907,6 +2913,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2907
2913
|
readonly tolerance?: number | undefined;
|
|
2908
2914
|
readonly header?: string | undefined;
|
|
2909
2915
|
} | undefined;
|
|
2916
|
+
readonly generated?: true | undefined;
|
|
2910
2917
|
readonly algorithm?: string | undefined;
|
|
2911
2918
|
readonly encoding?: string | undefined;
|
|
2912
2919
|
readonly signatures?: {
|
|
@@ -2918,6 +2925,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2918
2925
|
} | undefined;
|
|
2919
2926
|
readonly prefix?: string | undefined;
|
|
2920
2927
|
} | undefined;
|
|
2928
|
+
readonly secret?: string | undefined;
|
|
2921
2929
|
} | undefined;
|
|
2922
2930
|
readonly verification?: {
|
|
2923
2931
|
readonly scheme: string;
|
|
@@ -585,7 +585,8 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
585
585
|
readonly description: Schema.String;
|
|
586
586
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
587
587
|
readonly scheme: Schema.String;
|
|
588
|
-
readonly secret: Schema.String
|
|
588
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
589
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
589
590
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
590
591
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
591
592
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -942,7 +943,8 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
942
943
|
readonly description: Schema.String;
|
|
943
944
|
readonly signature: Schema.optionalKey<Schema.Struct<{
|
|
944
945
|
readonly scheme: Schema.String;
|
|
945
|
-
readonly secret: Schema.String
|
|
946
|
+
readonly secret: Schema.optionalKey<Schema.String>;
|
|
947
|
+
readonly generated: Schema.optionalKey<Schema.Literal<true>>;
|
|
946
948
|
readonly algorithm: Schema.optionalKey<Schema.String>;
|
|
947
949
|
readonly encoding: Schema.optionalKey<Schema.String>;
|
|
948
950
|
readonly key: Schema.optionalKey<Schema.Struct<{
|
|
@@ -107,6 +107,18 @@ export declare function hmacSignature(format: WebhookHmacFormat): SignatureSchem
|
|
|
107
107
|
export declare const stripeSignature: SignatureScheme;
|
|
108
108
|
/** Meta signs exactly the raw body; its app secret stays in the backend. */
|
|
109
109
|
export declare const metaSignature: SignatureScheme;
|
|
110
|
+
/**
|
|
111
|
+
* Whether a delivery to a webhook with a generated secret carries a signature of it. The service
|
|
112
|
+
* holds the workspace's webhook secret, which the generated secret derives from, so it computes
|
|
113
|
+
* the HMAC itself and compares each candidate in constant time.
|
|
114
|
+
*/
|
|
115
|
+
export declare function generatedSignatureMatches(input: {
|
|
116
|
+
readonly webhookSecret: string;
|
|
117
|
+
readonly webhook: string;
|
|
118
|
+
readonly format: WebhookHmacFormat;
|
|
119
|
+
readonly message: Uint8Array;
|
|
120
|
+
readonly signatures: ReadonlyArray<string>;
|
|
121
|
+
}): boolean;
|
|
110
122
|
/**
|
|
111
123
|
* What checks a manifest signature: its format and that format's scheme, or `undefined` for a
|
|
112
124
|
* scheme this SDK does not know.
|
package/dist/service/webhooks.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
1
2
|
import { Effect, Redacted } from "effect";
|
|
2
3
|
import { META_SIGNATURE_FORMAT, STRIPE_SIGNATURE_FORMAT, WEBHOOK_HMAC_DIGEST_BYTES, WEBHOOK_TIMESTAMP_TOLERANCE_SECONDS, webhookHmacFormat, } from "../webhooks.js";
|
|
4
|
+
import { webhookSigningKey } from "../webhook-token.js";
|
|
3
5
|
import { fixedWindowLimiter } from "./rate-limit.js";
|
|
4
6
|
/** How long the service waits for the backend's answer before answering 503. */
|
|
5
7
|
export const WEBHOOK_VERIFY_TIMEOUT_MS = 3_000;
|
|
@@ -220,6 +222,20 @@ export function hmacSignature(format) {
|
|
|
220
222
|
export const stripeSignature = hmacSignature(STRIPE_SIGNATURE_FORMAT);
|
|
221
223
|
/** Meta signs exactly the raw body; its app secret stays in the backend. */
|
|
222
224
|
export const metaSignature = hmacSignature(META_SIGNATURE_FORMAT);
|
|
225
|
+
/**
|
|
226
|
+
* Whether a delivery to a webhook with a generated secret carries a signature of it. The service
|
|
227
|
+
* holds the workspace's webhook secret, which the generated secret derives from, so it computes
|
|
228
|
+
* the HMAC itself and compares each candidate in constant time.
|
|
229
|
+
*/
|
|
230
|
+
export function generatedSignatureMatches(input) {
|
|
231
|
+
const expected = createHmac(input.format.algorithm, webhookSigningKey(input.webhookSecret, input.webhook))
|
|
232
|
+
.update(input.message)
|
|
233
|
+
.digest();
|
|
234
|
+
return input.signatures.some((signature) => {
|
|
235
|
+
const received = Buffer.from(signature, input.format.encoding === "hex" ? "hex" : "base64");
|
|
236
|
+
return received.byteLength === expected.byteLength && timingSafeEqual(received, expected);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
223
239
|
/**
|
|
224
240
|
* What checks a manifest signature: its format and that format's scheme, or `undefined` for a
|
|
225
241
|
* scheme this SDK does not know.
|
|
@@ -15,8 +15,8 @@ import { unavailableFiles } from "../storage/file-access.js";
|
|
|
15
15
|
import { ActionRejected, PermissionDenied, } from "../errors.js";
|
|
16
16
|
import { isActionTrigger, isCronTrigger, isWebhookTrigger, } from "../manifest.js";
|
|
17
17
|
import { webhookTokenMatches } from "../webhook-token.js";
|
|
18
|
-
import { MAX_WEBHOOK_BODY_BYTES, MAX_META_WEBHOOK_BODY_BYTES, MAX_WEBHOOK_VERIFICATION_CHARS, WEBHOOK_BASE_PATH, webhookPath, } from "../webhooks.js";
|
|
19
|
-
import { readWebhookBody, signatureCheck, signatureRefusals, utf8Text, } from "./webhooks.js";
|
|
18
|
+
import { MAX_WEBHOOK_BODY_BYTES, MAX_META_WEBHOOK_BODY_BYTES, MAX_WEBHOOK_VERIFICATION_CHARS, presentedWebhookSignature, WEBHOOK_BASE_PATH, webhookPath, } from "../webhooks.js";
|
|
19
|
+
import { generatedSignatureMatches, readWebhookBody, signatureCheck, signatureRefusals, utf8Text, } from "./webhooks.js";
|
|
20
20
|
import { clientAddress } from "./rate-limit.js";
|
|
21
21
|
import { isAllowed, workflowPermission } from "../permissions.js";
|
|
22
22
|
import { OntologyActions, OntologyReads, OntologyWrites, } from "../runtime.js";
|
|
@@ -561,7 +561,9 @@ function workflowView(workflow, now) {
|
|
|
561
561
|
description: trigger.description,
|
|
562
562
|
// Never the token: whoever reads the declarations does not get the URL.
|
|
563
563
|
path: webhookPath(trigger.name),
|
|
564
|
-
signature: trigger.signature
|
|
564
|
+
signature: trigger.signature === undefined
|
|
565
|
+
? null
|
|
566
|
+
: presentedWebhookSignature(trigger.signature),
|
|
565
567
|
headers: trigger.headers ?? [],
|
|
566
568
|
connection: trigger.connection ?? null,
|
|
567
569
|
},
|
|
@@ -1349,7 +1351,11 @@ export function workflowsLayer(options) {
|
|
|
1349
1351
|
return yield* refuse("signature_throttled", 429, { "retry-after": String(wait) });
|
|
1350
1352
|
}
|
|
1351
1353
|
const checked = signatureCheck(signature);
|
|
1352
|
-
|
|
1354
|
+
const generated = signature.generated === true;
|
|
1355
|
+
if (checked === undefined ||
|
|
1356
|
+
(generated
|
|
1357
|
+
? options.webhookSecret === undefined
|
|
1358
|
+
: options.webhookVerifier === undefined)) {
|
|
1353
1359
|
return yield* refuse("scheme_unavailable", 503);
|
|
1354
1360
|
}
|
|
1355
1361
|
const { format } = checked;
|
|
@@ -1358,26 +1364,46 @@ export function workflowsLayer(options) {
|
|
|
1358
1364
|
refusals.refused(client);
|
|
1359
1365
|
return yield* refuse(content.reason, 401);
|
|
1360
1366
|
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
return yield* refuse("verification_unavailable", 503);
|
|
1367
|
+
// The platform derives a generated secret from the workspace's webhook secret, which
|
|
1368
|
+
// this service holds, so it checks the signature itself.
|
|
1369
|
+
if (generated) {
|
|
1370
|
+
if (!generatedSignatureMatches({
|
|
1371
|
+
webhookSecret: Redacted.value(options.webhookSecret),
|
|
1372
|
+
webhook: trigger.name,
|
|
1373
|
+
format,
|
|
1374
|
+
message: content.message,
|
|
1375
|
+
signatures: content.signatures,
|
|
1376
|
+
})) {
|
|
1377
|
+
refusals.refused(client);
|
|
1378
|
+
return yield* refuse("signature_invalid", 401);
|
|
1379
|
+
}
|
|
1375
1380
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
:
|
|
1381
|
+
else {
|
|
1382
|
+
const verifier = options.webhookVerifier;
|
|
1383
|
+
const verified = yield* Effect.promise(() => verifier({
|
|
1384
|
+
secret: signature.secret ?? "",
|
|
1385
|
+
algorithm: format.algorithm,
|
|
1386
|
+
encoding: format.encoding,
|
|
1387
|
+
...(format.key === undefined ? {} : { key: format.key }),
|
|
1388
|
+
message: content.message,
|
|
1389
|
+
signatures: content.signatures,
|
|
1390
|
+
identityToken: requestIdentityToken(request),
|
|
1391
|
+
requestId,
|
|
1392
|
+
}));
|
|
1393
|
+
if (verified.outcome === "unavailable") {
|
|
1394
|
+
yield* Effect.logError("ontology.webhook.verification_unavailable", verified.cause).pipe(Effect.annotateLogs({
|
|
1395
|
+
requestId,
|
|
1396
|
+
webhook: trigger.name,
|
|
1397
|
+
status: verified.status,
|
|
1398
|
+
}));
|
|
1399
|
+
return yield* refuse("verification_unavailable", 503);
|
|
1400
|
+
}
|
|
1401
|
+
if (verified.outcome !== "valid") {
|
|
1402
|
+
refusals.refused(client);
|
|
1403
|
+
return yield* refuse(verified.outcome === "secret_missing"
|
|
1404
|
+
? "signature_secret_missing"
|
|
1405
|
+
: "signature_invalid", 401);
|
|
1406
|
+
}
|
|
1381
1407
|
}
|
|
1382
1408
|
}
|
|
1383
1409
|
const text = utf8Text(body);
|
package/dist/webhook-token.d.ts
CHANGED
|
@@ -8,6 +8,14 @@ export declare const WEBHOOK_TOKEN_CONTEXT = "segmentstream.webhook.v1:";
|
|
|
8
8
|
* no token is ever stored (`tests/fixtures/ontology-webhook-token.json`).
|
|
9
9
|
*/
|
|
10
10
|
export declare function webhookToken(secret: string, name: string): string;
|
|
11
|
+
/** What a generated signing secret signs before the webhook's name, apart from its token. */
|
|
12
|
+
export declare const WEBHOOK_SIGNING_CONTEXT = "segmentstream.webhook-signature.v1:";
|
|
13
|
+
/**
|
|
14
|
+
* The signing secret the platform derives for a webhook that declares `generated: true`:
|
|
15
|
+
* `base64url(HMAC-SHA256(secret, context + name))`, 43 characters, from the workspace's webhook
|
|
16
|
+
* secret and the webhook's wire name. The provider signs deliveries with it as text.
|
|
17
|
+
*/
|
|
18
|
+
export declare function webhookSigningKey(secret: string, name: string): string;
|
|
11
19
|
/** Whether a received token is the webhook's, compared in constant time. */
|
|
12
20
|
export declare function webhookTokenMatches(secret: string, name: string, received: string): boolean;
|
|
13
21
|
/**
|
|
@@ -35,3 +43,14 @@ export declare class WebhookUrlUnavailable extends Error {
|
|
|
35
43
|
* {@link WebhookUrlUnavailable} in previews and local runs, which receive no webhooks.
|
|
36
44
|
*/
|
|
37
45
|
export declare function webhookUrl(trigger: WebhookTrigger, environment?: Readonly<Record<string, string | undefined>>): string;
|
|
46
|
+
/**
|
|
47
|
+
* The signing secret of a webhook that declares `signature: { generated: true, … }`, for workspace
|
|
48
|
+
* code to register with the provider through the webhook's connection, as BTCPay Server's or
|
|
49
|
+
* GitHub's webhook APIs take one. The ontology service checks deliveries with the same secret. It
|
|
50
|
+
* starts runs for anyone who has it, as a token URL does: send it only to the provider, never to
|
|
51
|
+
* records, logs or people.
|
|
52
|
+
*
|
|
53
|
+
* Call it in a step or an action's `prepare`. It throws {@link WebhookUrlUnavailable} in previews
|
|
54
|
+
* and local runs, and an error for a webhook whose secret is not generated.
|
|
55
|
+
*/
|
|
56
|
+
export declare function webhookSigningSecret(trigger: WebhookTrigger, environment?: Readonly<Record<string, string | undefined>>): string;
|
package/dist/webhook-token.js
CHANGED
|
@@ -12,6 +12,18 @@ export const WEBHOOK_TOKEN_CONTEXT = "segmentstream.webhook.v1:";
|
|
|
12
12
|
export function webhookToken(secret, name) {
|
|
13
13
|
return createHmac("sha256", secret).update(`${WEBHOOK_TOKEN_CONTEXT}${name}`).digest("base64url");
|
|
14
14
|
}
|
|
15
|
+
/** What a generated signing secret signs before the webhook's name, apart from its token. */
|
|
16
|
+
export const WEBHOOK_SIGNING_CONTEXT = "segmentstream.webhook-signature.v1:";
|
|
17
|
+
/**
|
|
18
|
+
* The signing secret the platform derives for a webhook that declares `generated: true`:
|
|
19
|
+
* `base64url(HMAC-SHA256(secret, context + name))`, 43 characters, from the workspace's webhook
|
|
20
|
+
* secret and the webhook's wire name. The provider signs deliveries with it as text.
|
|
21
|
+
*/
|
|
22
|
+
export function webhookSigningKey(secret, name) {
|
|
23
|
+
return createHmac("sha256", secret)
|
|
24
|
+
.update(`${WEBHOOK_SIGNING_CONTEXT}${name}`)
|
|
25
|
+
.digest("base64url");
|
|
26
|
+
}
|
|
15
27
|
/** Whether a received token is the webhook's, compared in constant time. */
|
|
16
28
|
export function webhookTokenMatches(secret, name, received) {
|
|
17
29
|
const expected = Buffer.from(webhookToken(secret, name));
|
|
@@ -63,3 +75,25 @@ export function webhookUrl(trigger, environment = process.env) {
|
|
|
63
75
|
}
|
|
64
76
|
return `${url}/${webhookToken(secret, wire)}`;
|
|
65
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* The signing secret of a webhook that declares `signature: { generated: true, … }`, for workspace
|
|
80
|
+
* code to register with the provider through the webhook's connection, as BTCPay Server's or
|
|
81
|
+
* GitHub's webhook APIs take one. The ontology service checks deliveries with the same secret. It
|
|
82
|
+
* starts runs for anyone who has it, as a token URL does: send it only to the provider, never to
|
|
83
|
+
* records, logs or people.
|
|
84
|
+
*
|
|
85
|
+
* Call it in a step or an action's `prepare`. It throws {@link WebhookUrlUnavailable} in previews
|
|
86
|
+
* and local runs, and an error for a webhook whose secret is not generated.
|
|
87
|
+
*/
|
|
88
|
+
export function webhookSigningSecret(trigger, environment = process.env) {
|
|
89
|
+
const wire = nameToWire(trigger.name);
|
|
90
|
+
if (trigger.signature?.generated !== true) {
|
|
91
|
+
throw new Error(`The webhook ${wire} does not declare signature.generated, so the platform keeps no secret ` +
|
|
92
|
+
"for it to register.");
|
|
93
|
+
}
|
|
94
|
+
const secret = environment[WEBHOOK_SECRET_VARIABLE];
|
|
95
|
+
if (!secret) {
|
|
96
|
+
throw new WebhookUrlUnavailable(wire);
|
|
97
|
+
}
|
|
98
|
+
return webhookSigningKey(secret, wire);
|
|
99
|
+
}
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -88,6 +88,26 @@ export declare const META_SIGNATURE_FORMAT: WebhookHmacFormat;
|
|
|
88
88
|
export declare function webhookHmacFormat(signature: {
|
|
89
89
|
readonly scheme: string;
|
|
90
90
|
}): WebhookHmacFormat | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Where a signature's secret comes from: a workspace secret by `secret` name, or with
|
|
93
|
+
* `generated: true` the secret the platform derives for the webhook, which workspace code reads
|
|
94
|
+
* with `webhookSigningSecret(trigger)` to register it.
|
|
95
|
+
*/
|
|
96
|
+
export interface WebhookSignatureSource {
|
|
97
|
+
readonly scheme: string;
|
|
98
|
+
readonly secret?: string | undefined;
|
|
99
|
+
readonly generated?: true | undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A signature as listings present it: its scheme and the secret's name, which reads `generated`
|
|
103
|
+
* with `generated: true` for a secret the platform derives, so readers that know only names still
|
|
104
|
+
* show something true.
|
|
105
|
+
*/
|
|
106
|
+
export declare function presentedWebhookSignature(signature: WebhookSignatureSource): {
|
|
107
|
+
readonly scheme: string;
|
|
108
|
+
readonly secret: string;
|
|
109
|
+
readonly generated?: true;
|
|
110
|
+
};
|
|
91
111
|
/** A problem with a signature declaration: the key it concerns, under `signature`, and why. */
|
|
92
112
|
export interface WebhookSignatureProblem {
|
|
93
113
|
readonly path: string;
|
|
@@ -103,13 +123,7 @@ export declare function webhookSignatureProblems(signature: unknown): ReadonlyAr
|
|
|
103
123
|
* A valid signature declaration as the manifest records it: `{ scheme, secret }` for a named
|
|
104
124
|
* scheme, and for `hmac` its format's settings, each written only when declared.
|
|
105
125
|
*/
|
|
106
|
-
export declare function webhookSignatureManifest(signature:
|
|
107
|
-
readonly scheme: string;
|
|
108
|
-
readonly secret: string;
|
|
109
|
-
} & Partial<WebhookHmacFormat>): {
|
|
110
|
-
readonly scheme: string;
|
|
111
|
-
readonly secret: string;
|
|
112
|
-
} & Partial<WebhookHmacFormat>;
|
|
126
|
+
export declare function webhookSignatureManifest(signature: WebhookSignatureSource & Partial<WebhookHmacFormat>): WebhookSignatureSource & Partial<WebhookHmacFormat>;
|
|
113
127
|
/** The most webhook triggers one ontology may declare across its workflows. */
|
|
114
128
|
export declare const MAX_WEBHOOKS = 20;
|
|
115
129
|
/** The most request headers one webhook trigger may pass to its workflow. */
|
package/dist/webhooks.js
CHANGED
|
@@ -61,6 +61,16 @@ export function webhookHmacFormat(signature) {
|
|
|
61
61
|
return undefined;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* A signature as listings present it: its scheme and the secret's name, which reads `generated`
|
|
66
|
+
* with `generated: true` for a secret the platform derives, so readers that know only names still
|
|
67
|
+
* show something true.
|
|
68
|
+
*/
|
|
69
|
+
export function presentedWebhookSignature(signature) {
|
|
70
|
+
return signature.generated === true
|
|
71
|
+
? { scheme: signature.scheme, secret: "generated", generated: true }
|
|
72
|
+
: { scheme: signature.scheme, secret: signature.secret ?? "" };
|
|
73
|
+
}
|
|
64
74
|
const FORMAT_KEYS = ["algorithm", "encoding", "key", "signatures", "timestamp", "message"];
|
|
65
75
|
const PRINTABLE = /^[\x21-\x7e]{1,16}$/;
|
|
66
76
|
const ENTRY_NAME = /^[A-Za-z0-9_.-]{1,16}$/;
|
|
@@ -82,25 +92,38 @@ export function webhookSignatureProblems(signature) {
|
|
|
82
92
|
report("", "signature is { scheme, secret }, or omitted for a provider that signs nothing.");
|
|
83
93
|
return problems;
|
|
84
94
|
}
|
|
85
|
-
const { scheme, secret } = signature;
|
|
95
|
+
const { scheme, secret, generated } = signature;
|
|
86
96
|
if (!WEBHOOK_SIGNATURE_SCHEMES.includes(scheme)) {
|
|
87
97
|
report("scheme", `${JSON.stringify(scheme) ?? "undefined"} is not a signature scheme; use one of ` +
|
|
88
98
|
`${WEBHOOK_SIGNATURE_SCHEMES.join(", ")}, or omit signature for a provider that signs ` +
|
|
89
99
|
"nothing.");
|
|
90
100
|
}
|
|
91
|
-
if (
|
|
101
|
+
if (generated !== undefined) {
|
|
102
|
+
if (generated !== true) {
|
|
103
|
+
report("generated", "generated is true, or omitted with a secret named instead.");
|
|
104
|
+
}
|
|
105
|
+
if (secret !== undefined) {
|
|
106
|
+
report("secret", "A signature names a secret or is generated: not both.");
|
|
107
|
+
}
|
|
108
|
+
if (signature.key !== undefined) {
|
|
109
|
+
report("key", "A generated secret is plain text: key, which decodes an issued secret, does not apply.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (typeof secret !== "string" || !WORKSPACE_SECRET_NAME.test(secret)) {
|
|
92
113
|
report("secret", `${JSON.stringify(secret) ?? "undefined"} is not a workspace secret name; name the ` +
|
|
93
|
-
"secret that holds the provider's signing secret, such as stripe-webhook-signing-secret
|
|
114
|
+
"secret that holds the provider's signing secret, such as stripe-webhook-signing-secret, " +
|
|
115
|
+
"or set generated: true for a secret workspace code registers.");
|
|
94
116
|
}
|
|
117
|
+
const named = ["scheme", "secret", "generated"];
|
|
95
118
|
if (scheme !== "hmac") {
|
|
96
|
-
for (const key of unknownKeys(signature,
|
|
119
|
+
for (const key of unknownKeys(signature, named)) {
|
|
97
120
|
report(key, FORMAT_KEYS.includes(key)
|
|
98
121
|
? `${key} declares a format, which only scheme "hmac" takes.`
|
|
99
122
|
: `${key} is not a signature setting.`);
|
|
100
123
|
}
|
|
101
124
|
return problems;
|
|
102
125
|
}
|
|
103
|
-
for (const key of unknownKeys(signature, [
|
|
126
|
+
for (const key of unknownKeys(signature, [...named, ...FORMAT_KEYS])) {
|
|
104
127
|
report(key, `${key} is not a signature setting.`);
|
|
105
128
|
}
|
|
106
129
|
if (!WEBHOOK_HMAC_ALGORITHMS.includes(signature.algorithm)) {
|
|
@@ -248,13 +271,14 @@ function signedHeaderProblem(name) {
|
|
|
248
271
|
* scheme, and for `hmac` its format's settings, each written only when declared.
|
|
249
272
|
*/
|
|
250
273
|
export function webhookSignatureManifest(signature) {
|
|
274
|
+
const source = signature.generated === true ? { generated: true } : { secret: signature.secret };
|
|
251
275
|
if (signature.scheme !== "hmac") {
|
|
252
|
-
return { scheme: signature.scheme,
|
|
276
|
+
return { scheme: signature.scheme, ...source };
|
|
253
277
|
}
|
|
254
278
|
const { signatures, timestamp, key, message } = signature;
|
|
255
279
|
return {
|
|
256
280
|
scheme: "hmac",
|
|
257
|
-
|
|
281
|
+
...source,
|
|
258
282
|
algorithm: signature.algorithm,
|
|
259
283
|
encoding: signature.encoding,
|
|
260
284
|
...(key === undefined
|
package/dist/workflow.d.ts
CHANGED
|
@@ -126,15 +126,24 @@ export interface ActionTrigger<Name extends string = string, Input = unknown> {
|
|
|
126
126
|
* that holds its signing secret. Without one, the webhook's URL ends in a token. `stripe` and `meta`
|
|
127
127
|
* name published formats; `hmac` declares any other HMAC format with the trigger.
|
|
128
128
|
*/
|
|
129
|
-
export type WebhookSignature = {
|
|
129
|
+
export type WebhookSignature = ({
|
|
130
130
|
readonly scheme: Exclude<WebhookSignatureScheme, "hmac">;
|
|
131
|
-
|
|
132
|
-
readonly secret: string;
|
|
133
|
-
} | ({
|
|
131
|
+
} & WebhookSignatureSecret) | ({
|
|
134
132
|
readonly scheme: "hmac";
|
|
135
|
-
|
|
133
|
+
} & WebhookSignatureSecret & WebhookHmacFormat);
|
|
134
|
+
/**
|
|
135
|
+
* The secret a signature is checked with: a workspace secret by name, whose value stays in the
|
|
136
|
+
* platform, or `generated: true`, the secret the platform derives for the webhook, which workspace
|
|
137
|
+
* code reads with `webhookSigningSecret(trigger)` to register it with the provider.
|
|
138
|
+
*/
|
|
139
|
+
export type WebhookSignatureSecret = {
|
|
140
|
+
/** A workspace secret's name, such as `stripe-webhook-signing-secret`. */
|
|
136
141
|
readonly secret: string;
|
|
137
|
-
|
|
142
|
+
readonly generated?: undefined;
|
|
143
|
+
} | {
|
|
144
|
+
readonly generated: true;
|
|
145
|
+
readonly secret?: undefined;
|
|
146
|
+
};
|
|
138
147
|
/** Meta's registration handshake; the verify token is a workspace secret, separate from the app secret. */
|
|
139
148
|
export interface WebhookVerification {
|
|
140
149
|
readonly scheme: "meta";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.128.0",
|
|
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",
|