@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/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 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.
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
- return signature.generated === true
71
- ? { scheme: signature.scheme, secret: "generated", generated: true }
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 and a workspace secret's name, and for `hmac` a complete
86
- * format. Empty when the declaration is valid.
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, secret }, or omitted for a provider that signs nothing.");
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 (generated !== undefined) {
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; name the ` +
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.");
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 ? { generated: true } : { secret: signature.secret };
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
  }
@@ -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 the workspace secret
126
- * that holds its signing secret. Without one, the webhook's URL ends in a token. `stripe` and `meta`
127
- * name published formats; `hmac` declares any other HMAC format with the trigger.
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: 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.
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 workspace secret's name, such as `stripe-webhook-signing-secret`. */
141
- readonly secret: string;
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
- /** Meta's registration handshake; the verify token is a workspace secret, separate from the app secret. */
148
- export interface WebhookVerification {
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.128.1",
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",