@krak-stack/registry 0.1.60 → 0.1.61

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.
@@ -0,0 +1,41 @@
1
+ import { Context, Effect, Layer, Redacted, Schema } from "effect";
2
+ import { SqlClient } from "effect/sql";
3
+ declare const WebhookVerificationError_base: Schema.Class<WebhookVerificationError, Schema.TaggedStruct<"WebhookVerificationError", {
4
+ readonly reason: Schema.Literals<readonly ["headers", "timestamp", "signature", "payload"]>;
5
+ }>, import("effect/Cause").YieldableError>;
6
+ export declare class WebhookVerificationError extends WebhookVerificationError_base {
7
+ }
8
+ declare const WebhookReceiptConflict_base: Schema.Class<WebhookReceiptConflict, Schema.TaggedStruct<"WebhookReceiptConflict", {}>, import("effect/Cause").YieldableError>;
9
+ export declare class WebhookReceiptConflict extends WebhookReceiptConflict_base {
10
+ }
11
+ declare const WebhooksReceiver_base: Context.ServiceClass<WebhooksReceiver, "krakstack/webhooks/WebhooksReceiver", {
12
+ receive: <S extends Schema.Top, E, R>(input: {
13
+ readonly receiver: string;
14
+ readonly secret: Redacted.Redacted<string>;
15
+ readonly headers: Readonly<Record<string, string | undefined>>;
16
+ readonly body: string;
17
+ readonly schema: S;
18
+ readonly handle: (payload: S["Type"]) => Effect.Effect<void, E, R>;
19
+ }) => Effect.Effect<{
20
+ duplicate: boolean;
21
+ }, E | import("effect/crypto/CryptoError").CryptoError | import("effect/Cause").NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError | WebhookReceiptConflict | WebhookVerificationError, R | S["DecodingServices"]>;
22
+ cleanup: () => Effect.Effect<void, import("effect/sql/SqlError").SqlError, never>;
23
+ }> & {
24
+ readonly make: Effect.Effect<{
25
+ receive: <S extends Schema.Top, E, R>(input: {
26
+ readonly receiver: string;
27
+ readonly secret: Redacted.Redacted<string>;
28
+ readonly headers: Readonly<Record<string, string | undefined>>;
29
+ readonly body: string;
30
+ readonly schema: S;
31
+ readonly handle: (payload: S["Type"]) => Effect.Effect<void, E, R>;
32
+ }) => Effect.Effect<{
33
+ duplicate: boolean;
34
+ }, E | import("effect/crypto/CryptoError").CryptoError | import("effect/Cause").NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError | WebhookReceiptConflict | WebhookVerificationError, R | S["DecodingServices"]>;
35
+ cleanup: () => Effect.Effect<void, import("effect/sql/SqlError").SqlError, never>;
36
+ }, never, SqlClient.SqlClient>;
37
+ };
38
+ export declare class WebhooksReceiver extends WebhooksReceiver_base {
39
+ static readonly layer: Layer.Layer<WebhooksReceiver, import("effect/sql/Migrator").MigrationError | import("effect/sql/SqlError").SqlError, SqlClient.SqlClient>;
40
+ }
41
+ export {};
@@ -58,6 +58,14 @@ export declare const WebhookPayload: Schema.Struct<{
58
58
  readonly events: Schema.NullOr<Schema.$Array<Schema.NonEmptyString>>;
59
59
  readonly customHeaders: Schema.NullOr<Schema.$Record<Schema.String, Schema.String>>;
60
60
  }>;
61
+ export declare const webhookPayloadSchema: (allowLoopback: boolean) => Schema.Struct<{
62
+ readonly name: Schema.optional<Schema.Trim>;
63
+ readonly description: Schema.NullOr<Schema.String>;
64
+ readonly enabled: Schema.Boolean;
65
+ readonly events: Schema.NullOr<Schema.$Array<Schema.NonEmptyString>>;
66
+ readonly customHeaders: Schema.NullOr<Schema.$Record<Schema.String, Schema.String>>;
67
+ readonly url: Schema.String;
68
+ }>;
61
69
  export declare const Webhook: Schema.Struct<{
62
70
  readonly id: Schema.String;
63
71
  readonly name: Schema.String;
@@ -2,6 +2,7 @@
2
2
  import { Schema as Schema2 } from "effect";
3
3
 
4
4
  // ../../src/services/webhooks/url.ts
5
+ import { Context } from "effect";
5
6
  var hostname = (value) => value.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
6
7
  var isPublicIpAddress = (value) => {
7
8
  const address = hostname(value);
@@ -28,6 +29,18 @@ var isPublicWebhookUrlString = (value) => {
28
29
  return false;
29
30
  }
30
31
  };
32
+ var isAllowedWebhookUrlString = (value, allowLoopback) => {
33
+ try {
34
+ const url = new URL(value);
35
+ return isPublicWebhookUrl(url) || allowLoopback && isLoopbackWebhookUrl(url);
36
+ } catch {
37
+ return false;
38
+ }
39
+ };
40
+ var WebhookAllowLoopback = Context.Reference("Webhooks/AllowLoopback", {
41
+ defaultValue: () => false
42
+ });
43
+ var isLoopbackWebhookUrl = (url) => ["http:", "https:"].includes(url.protocol) && !url.username && !url.password && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
31
44
 
32
45
  // ../../src/lib/query.ts
33
46
  import {
@@ -252,6 +265,12 @@ var WebhookPayload = Schema2.Struct({
252
265
  "webhook-signature"
253
266
  ].includes(name.toLowerCase())), { expected: "headers that do not override webhook protocol headers" }))
254
267
  }).annotate({ identifier: "WebhookPayload" });
268
+ var webhookPayloadSchema = (allowLoopback) => Schema2.Struct({
269
+ ...WebhookPayload.fields,
270
+ url: Schema2.String.check(Schema2.makeFilter((value) => isAllowedWebhookUrlString(value, allowLoopback), {
271
+ expected: "a public HTTP(S) URL, or an explicitly enabled development loopback URL"
272
+ }))
273
+ }).annotate({ identifier: "ConfiguredWebhookPayload" });
255
274
  var Webhook = Schema2.Struct({
256
275
  id: Schema2.String,
257
276
  name: Schema2.String,
@@ -329,5 +348,6 @@ export {
329
348
  WebhookStatisticsInterval,
330
349
  WebhookStatisticsRequest,
331
350
  deliveryColumns,
332
- webhookColumns
351
+ webhookColumns,
352
+ webhookPayloadSchema
333
353
  };
@@ -1,3 +1,8 @@
1
1
  export declare const isPublicIpAddress: (value: string) => boolean;
2
2
  export declare const isPublicWebhookUrl: (url: URL) => boolean;
3
3
  export declare const isPublicWebhookUrlString: (value: string) => boolean;
4
+ export declare const isAllowedWebhookUrlString: (value: string, allowLoopback: boolean) => boolean;
5
+ import { Context } from "effect";
6
+ /** Opt in only in a local development composition root, never from a request. */
7
+ export declare const WebhookAllowLoopback: Context.Reference<boolean>;
8
+ export declare const isLoopbackWebhookUrl: (url: URL) => boolean;
@@ -1,4 +1,5 @@
1
1
  // ../../src/services/webhooks/url.ts
2
+ import { Context } from "effect";
2
3
  var hostname = (value) => value.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
3
4
  var isPublicIpAddress = (value) => {
4
5
  const address = hostname(value);
@@ -25,7 +26,22 @@ var isPublicWebhookUrlString = (value) => {
25
26
  return false;
26
27
  }
27
28
  };
29
+ var isAllowedWebhookUrlString = (value, allowLoopback) => {
30
+ try {
31
+ const url = new URL(value);
32
+ return isPublicWebhookUrl(url) || allowLoopback && isLoopbackWebhookUrl(url);
33
+ } catch {
34
+ return false;
35
+ }
36
+ };
37
+ var WebhookAllowLoopback = Context.Reference("Webhooks/AllowLoopback", {
38
+ defaultValue: () => false
39
+ });
40
+ var isLoopbackWebhookUrl = (url) => ["http:", "https:"].includes(url.protocol) && !url.username && !url.password && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
28
41
  export {
42
+ WebhookAllowLoopback,
43
+ isAllowedWebhookUrlString,
44
+ isLoopbackWebhookUrl,
29
45
  isPublicIpAddress,
30
46
  isPublicWebhookUrl,
31
47
  isPublicWebhookUrlString
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.60",
3
+ "version": "0.1.61",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,6 +17,10 @@
17
17
  "type": "module",
18
18
  "sideEffects": false,
19
19
  "exports": {
20
+ "./webhooks/client": {
21
+ "types": "./dist/services/webhooks/client/delivery-table.d.ts",
22
+ "import": "./dist/services/webhooks/client/delivery-table.js"
23
+ },
20
24
  "./webhooks/http-client": {
21
25
  "types": "./dist/services/webhooks/http-client.d.ts",
22
26
  "import": "./dist/services/webhooks/http-client.js"