@segmentstream/ontology 0.128.1 → 0.130.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 +21 -0
- package/dist/agent-review.d.ts +5 -0
- package/dist/agent-review.js +23 -4
- package/dist/analyze.js +21 -4
- package/dist/manifest.d.ts +66 -20
- package/dist/manifest.js +10 -2
- package/dist/migrate/model.d.ts +24 -8
- package/dist/runtime/agents.d.ts +3 -1
- package/dist/runtime/agents.js +184 -55
- package/dist/runtime/service-binding.js +6 -0
- package/dist/service/agent/protocol.d.ts +7 -0
- package/dist/service/agent/protocol.js +9 -0
- package/dist/service/agent/server.js +32 -1
- package/dist/service/runtime-contract.d.ts +17 -0
- package/dist/service/schemas.d.ts +6 -2
- package/dist/service/webhooks.d.ts +12 -5
- package/dist/service/webhooks.js +10 -4
- package/dist/service/workflows.js +7 -1
- package/dist/webhooks.d.ts +14 -8
- package/dist/webhooks.js +36 -15
- package/dist/workflow.d.ts +30 -11
- package/package.json +1 -1
package/dist/webhooks.js
CHANGED
|
@@ -62,15 +62,20 @@ export function webhookHmacFormat(signature) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
-
* A signature as listings present it: its scheme and
|
|
66
|
-
*
|
|
67
|
-
* show something true.
|
|
65
|
+
* A signature as listings present it: its scheme and where its secret is. `secret` reads
|
|
66
|
+
* `generated` for a secret the platform derives and the value's key for a connection's
|
|
67
|
+
* verification value, so readers that know only names still show something true.
|
|
68
68
|
*/
|
|
69
69
|
export function presentedWebhookSignature(signature) {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
if (signature.generated === true) {
|
|
71
|
+
return { scheme: signature.scheme, secret: "generated", generated: true };
|
|
72
|
+
}
|
|
73
|
+
return signature.input !== undefined
|
|
74
|
+
? { scheme: signature.scheme, secret: signature.input, input: signature.input }
|
|
72
75
|
: { scheme: signature.scheme, secret: signature.secret ?? "" };
|
|
73
76
|
}
|
|
77
|
+
/** A verification value's key on its connection, as connections name fields: `webhook_signing_secret`. */
|
|
78
|
+
export const CONNECTION_INPUT_KEY = /^[a-z][a-z0-9_]{0,31}$/;
|
|
74
79
|
const FORMAT_KEYS = ["algorithm", "encoding", "key", "signatures", "timestamp", "message"];
|
|
75
80
|
const PRINTABLE = /^[\x21-\x7e]{1,16}$/;
|
|
76
81
|
const ENTRY_NAME = /^[A-Za-z0-9_.-]{1,16}$/;
|
|
@@ -82,23 +87,34 @@ function unknownKeys(value, known) {
|
|
|
82
87
|
}
|
|
83
88
|
/**
|
|
84
89
|
* Every problem of a webhook trigger's `signature`, as `check` and SegmentStream's publication
|
|
85
|
-
* check report them: a known scheme
|
|
86
|
-
*
|
|
90
|
+
* check report them: a known scheme, one source of the secret, and for `hmac` a complete format.
|
|
91
|
+
* Empty when the declaration is valid. That an `input` has a connection to read it from is the
|
|
92
|
+
* trigger's check.
|
|
87
93
|
*/
|
|
88
94
|
export function webhookSignatureProblems(signature) {
|
|
89
95
|
const problems = [];
|
|
90
96
|
const report = (path, message) => problems.push({ path, message });
|
|
91
97
|
if (!isRecord(signature)) {
|
|
92
|
-
report("", "signature is { scheme,
|
|
98
|
+
report("", "signature is { scheme, input }, or omitted for a provider that signs nothing.");
|
|
93
99
|
return problems;
|
|
94
100
|
}
|
|
95
|
-
const { scheme, secret, generated } = signature;
|
|
101
|
+
const { scheme, secret, generated, input } = signature;
|
|
96
102
|
if (!WEBHOOK_SIGNATURE_SCHEMES.includes(scheme)) {
|
|
97
103
|
report("scheme", `${JSON.stringify(scheme) ?? "undefined"} is not a signature scheme; use one of ` +
|
|
98
104
|
`${WEBHOOK_SIGNATURE_SCHEMES.join(", ")}, or omit signature for a provider that signs ` +
|
|
99
105
|
"nothing.");
|
|
100
106
|
}
|
|
101
|
-
if (
|
|
107
|
+
if (input !== undefined) {
|
|
108
|
+
if (typeof input !== "string" || !CONNECTION_INPUT_KEY.test(input)) {
|
|
109
|
+
report("input", `${JSON.stringify(input) ?? "undefined"} is not a connection's verification value; name ` +
|
|
110
|
+
"the value of the webhook's connection that holds the provider's signing secret, such " +
|
|
111
|
+
"as webhook_signing_secret.");
|
|
112
|
+
}
|
|
113
|
+
if (secret !== undefined || generated !== undefined) {
|
|
114
|
+
report("input", "A signature's secret is an input, generated or a named secret: one of them.");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (generated !== undefined) {
|
|
102
118
|
if (generated !== true) {
|
|
103
119
|
report("generated", "generated is true, or omitted with a secret named instead.");
|
|
104
120
|
}
|
|
@@ -110,11 +126,12 @@ export function webhookSignatureProblems(signature) {
|
|
|
110
126
|
}
|
|
111
127
|
}
|
|
112
128
|
else if (typeof secret !== "string" || !WORKSPACE_SECRET_NAME.test(secret)) {
|
|
113
|
-
report("secret", `${JSON.stringify(secret) ?? "undefined"} is not a workspace secret name;
|
|
114
|
-
"
|
|
115
|
-
"or
|
|
129
|
+
report("secret", `${JSON.stringify(secret) ?? "undefined"} is not a workspace secret name; set input to ` +
|
|
130
|
+
"the verification value of the webhook's connection that holds the provider's signing " +
|
|
131
|
+
"secret, such as webhook_signing_secret, or generated: true for a secret workspace code " +
|
|
132
|
+
"registers.");
|
|
116
133
|
}
|
|
117
|
-
const named = ["scheme", "secret", "generated"];
|
|
134
|
+
const named = ["scheme", "secret", "generated", "input"];
|
|
118
135
|
if (scheme !== "hmac") {
|
|
119
136
|
for (const key of unknownKeys(signature, named)) {
|
|
120
137
|
report(key, FORMAT_KEYS.includes(key)
|
|
@@ -271,7 +288,11 @@ function signedHeaderProblem(name) {
|
|
|
271
288
|
* scheme, and for `hmac` its format's settings, each written only when declared.
|
|
272
289
|
*/
|
|
273
290
|
export function webhookSignatureManifest(signature) {
|
|
274
|
-
const source = signature.generated === true
|
|
291
|
+
const source = signature.generated === true
|
|
292
|
+
? { generated: true }
|
|
293
|
+
: signature.input !== undefined
|
|
294
|
+
? { input: signature.input }
|
|
295
|
+
: { secret: signature.secret };
|
|
275
296
|
if (signature.scheme !== "hmac") {
|
|
276
297
|
return { scheme: signature.scheme, ...source };
|
|
277
298
|
}
|
package/dist/workflow.d.ts
CHANGED
|
@@ -122,9 +122,9 @@ export interface ActionTrigger<Name extends string = string, Input = unknown> {
|
|
|
122
122
|
readonly role?: string | undefined;
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
|
-
* Where a webhook's deliveries are checked: a provider's signature format and
|
|
126
|
-
*
|
|
127
|
-
*
|
|
125
|
+
* Where a webhook's deliveries are checked: a provider's signature format and where its signing
|
|
126
|
+
* secret is held. Without one, the webhook's URL ends in a token. `stripe` and `meta` name
|
|
127
|
+
* published formats; `hmac` declares any other HMAC format with the trigger.
|
|
128
128
|
*/
|
|
129
129
|
export type WebhookSignature = ({
|
|
130
130
|
readonly scheme: Exclude<WebhookSignatureScheme, "hmac">;
|
|
@@ -132,23 +132,42 @@ export type WebhookSignature = ({
|
|
|
132
132
|
readonly scheme: "hmac";
|
|
133
133
|
} & WebhookSignatureSecret & WebhookHmacFormat);
|
|
134
134
|
/**
|
|
135
|
-
* The secret a signature is checked with
|
|
136
|
-
*
|
|
137
|
-
*
|
|
135
|
+
* The secret a signature is checked with. `input` names a verification value of the webhook's
|
|
136
|
+
* `connection`, such as the `webhook_signing_secret` Stripe's connection declares: members paste
|
|
137
|
+
* the provider's secret on that connection, and it never leaves the platform. `generated: true` is
|
|
138
|
+
* the secret the platform derives for the webhook, which workspace code reads with
|
|
139
|
+
* `webhookSigningSecret(trigger)` to register it with the provider. `secret` names a workspace
|
|
140
|
+
* secret, the older form.
|
|
138
141
|
*/
|
|
139
142
|
export type WebhookSignatureSecret = {
|
|
140
|
-
/** A
|
|
141
|
-
readonly
|
|
143
|
+
/** A verification value of the webhook's `connection`, such as `webhook_signing_secret`. */
|
|
144
|
+
readonly input: string;
|
|
145
|
+
readonly secret?: undefined;
|
|
142
146
|
readonly generated?: undefined;
|
|
143
147
|
} | {
|
|
144
148
|
readonly generated: true;
|
|
145
149
|
readonly secret?: undefined;
|
|
150
|
+
readonly input?: undefined;
|
|
151
|
+
} | {
|
|
152
|
+
/** A workspace secret's name, such as `stripe-webhook-signing-secret`. */
|
|
153
|
+
readonly secret: string;
|
|
154
|
+
readonly generated?: undefined;
|
|
155
|
+
readonly input?: undefined;
|
|
146
156
|
};
|
|
147
|
-
/**
|
|
148
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Meta's registration handshake. The verify token is a verification value of the webhook's
|
|
159
|
+
* `connection` (`input`), or a workspace secret (`verifyToken`, the older form), separate from the
|
|
160
|
+
* app secret either way.
|
|
161
|
+
*/
|
|
162
|
+
export type WebhookVerification = {
|
|
163
|
+
readonly scheme: "meta";
|
|
164
|
+
readonly input: string;
|
|
165
|
+
readonly verifyToken?: undefined;
|
|
166
|
+
} | {
|
|
149
167
|
readonly scheme: "meta";
|
|
150
168
|
readonly verifyToken: string;
|
|
151
|
-
|
|
169
|
+
readonly input?: undefined;
|
|
170
|
+
};
|
|
152
171
|
/**
|
|
153
172
|
* A webhook trigger, `webhook(name, { description, signature, headers })`: the ontology service
|
|
154
173
|
* starts the workflow for each genuine delivery to `/api/webhooks/<name>`, with the delivery as its
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.130.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",
|