@krak-stack/registry 0.1.59 → 0.1.60

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/dist/components/ui/data-table.d.ts +2 -0
  3. package/dist/components/ui/data-table.js +6 -2
  4. package/dist/components/ui/item.d.ts +22 -0
  5. package/dist/components/ui/trace.d.ts +18 -0
  6. package/dist/services/agent/client/index.js +584 -434
  7. package/dist/services/agent/client/widget.d.ts +1 -0
  8. package/dist/services/events/browser.js +29 -3
  9. package/dist/services/events/client/audit-log-table.js +6 -2
  10. package/dist/services/events/client/tracking-notice.js +2 -1
  11. package/dist/services/events/index.d.ts +26 -56
  12. package/dist/services/events/index.js +118 -7
  13. package/dist/services/events/schema.d.ts +66 -24
  14. package/dist/services/events/schema.js +34 -3
  15. package/dist/services/opentelemetry/api.js +2 -1
  16. package/dist/services/opentelemetry/browser.d.ts +1 -1
  17. package/dist/services/opentelemetry/browser.js +2 -1
  18. package/dist/services/opentelemetry/events.d.ts +1 -1
  19. package/dist/services/opentelemetry/index.d.ts +1 -1
  20. package/dist/services/opentelemetry/index.js +2 -1
  21. package/dist/services/opentelemetry/schema.d.ts +3 -1
  22. package/dist/services/opentelemetry/web-vitals.js +2 -1
  23. package/dist/services/webhooks/http-client.d.ts +7 -0
  24. package/dist/services/webhooks/http-client.js +57 -0
  25. package/dist/services/webhooks/index.d.ts +341 -0
  26. package/dist/services/webhooks/index.js +737 -0
  27. package/dist/services/webhooks/migrations.d.ts +5 -0
  28. package/dist/services/webhooks/migrations.js +44 -0
  29. package/dist/services/webhooks/schema.d.ts +243 -0
  30. package/dist/services/webhooks/schema.js +333 -0
  31. package/dist/services/webhooks/url.d.ts +3 -0
  32. package/dist/services/webhooks/url.js +32 -0
  33. package/package.json +25 -1
  34. package/dist/components/ui/marker.d.ts +0 -10
@@ -0,0 +1,5 @@
1
+ import { Effect, Layer } from "effect";
2
+ import { Migrator, SqlClient } from "effect/sql";
3
+ export declare const webhookMigrations: Migrator.Loader<never>;
4
+ export declare const migrateWebhooks: Effect.Effect<readonly (readonly [id: number, name: string])[], Migrator.MigrationError | import("effect/sql/SqlError").SqlError, SqlClient.SqlClient>;
5
+ export declare const webhookMigrationsLayer: Layer.Layer<never, Migrator.MigrationError | import("effect/sql/SqlError").SqlError, SqlClient.SqlClient>;
@@ -0,0 +1,44 @@
1
+ // ../../src/services/webhooks/migrations.ts
2
+ import { Effect, Layer } from "effect";
3
+ import { Migrator, SqlClient } from "effect/sql";
4
+ var webhookMigrations = Migrator.fromRecord({
5
+ "1_webhooks_initial": Effect.gen(function* () {
6
+ const sql = yield* SqlClient.SqlClient;
7
+ yield* sql`CREATE TABLE IF NOT EXISTS webhooks (
8
+ id text PRIMARY KEY, organization_id text NOT NULL, url text NOT NULL,
9
+ description text, headers jsonb, events jsonb, secret text NOT NULL,
10
+ enabled boolean NOT NULL DEFAULT true,
11
+ created_at timestamp NOT NULL DEFAULT now(), updated_at timestamp NOT NULL DEFAULT now()
12
+ )`;
13
+ yield* sql`CREATE TABLE IF NOT EXISTS webhook_deliveries (
14
+ id text PRIMARY KEY, webhook_id text NOT NULL REFERENCES webhooks(id) ON DELETE CASCADE,
15
+ event text NOT NULL, data jsonb NOT NULL DEFAULT '{}', status text NOT NULL DEFAULT 'pending',
16
+ completed_at timestamp, retry_at timestamp NOT NULL DEFAULT now(), retries integer NOT NULL DEFAULT 0,
17
+ created_at timestamp NOT NULL DEFAULT now(), updated_at timestamp NOT NULL DEFAULT now()
18
+ )`;
19
+ yield* sql`ALTER TABLE webhook_deliveries ADD COLUMN IF NOT EXISTS event_id text`;
20
+ yield* sql`CREATE UNIQUE INDEX IF NOT EXISTS krakstack_webhook_event_endpoint ON webhook_deliveries (webhook_id, event_id) WHERE event_id IS NOT NULL`;
21
+ yield* sql`CREATE INDEX IF NOT EXISTS krakstack_webhook_pending ON webhook_deliveries (retry_at) WHERE status = 'pending'`;
22
+ yield* sql`CREATE INDEX IF NOT EXISTS krakstack_webhook_organization ON webhooks (organization_id)`;
23
+ yield* sql`CREATE TABLE IF NOT EXISTS webhook_publications (
24
+ organization_id text NOT NULL, event_id text NOT NULL, event text NOT NULL, data jsonb NOT NULL,
25
+ PRIMARY KEY (organization_id, event_id)
26
+ )`;
27
+ }),
28
+ "2_webhook_names": Effect.gen(function* () {
29
+ const sql = yield* SqlClient.SqlClient;
30
+ yield* sql`ALTER TABLE webhooks ADD COLUMN name text`;
31
+ yield* sql`UPDATE webhooks SET name = url WHERE name IS NULL`;
32
+ yield* sql`ALTER TABLE webhook_deliveries ADD COLUMN error text`;
33
+ })
34
+ });
35
+ var migrateWebhooks = Migrator.make({})({
36
+ loader: webhookMigrations,
37
+ table: "krakstack_webhook_migrations"
38
+ });
39
+ var webhookMigrationsLayer = Layer.effectDiscard(migrateWebhooks);
40
+ export {
41
+ migrateWebhooks,
42
+ webhookMigrations,
43
+ webhookMigrationsLayer
44
+ };
@@ -0,0 +1,243 @@
1
+ import { Schema } from "effect";
2
+ export declare const webhookColumns = "id, organization_id AS \"organizationId\", COALESCE(name, url) AS name, url, description, headers, events, secret, enabled, created_at AS \"createdAt\", updated_at AS \"updatedAt\"";
3
+ export declare const deliveryColumns = "d.id, d.webhook_id AS \"webhookId\", d.event, d.data, d.status, d.error, d.completed_at AS \"completedAt\", d.retry_at AS \"retryAt\", d.retries, d.created_at AS \"createdAt\", d.updated_at AS \"updatedAt\"";
4
+ export declare const WebhookScope: Schema.Struct<{
5
+ readonly organizationId: Schema.NonEmptyString;
6
+ }>;
7
+ export declare const WebhookRequest: Schema.Struct<{
8
+ readonly organizationId: Schema.NonEmptyString;
9
+ readonly id: Schema.NonEmptyString;
10
+ }>;
11
+ export declare const WebhookStatisticsInterval: Schema.Literals<readonly ["hour", "day"]>;
12
+ export type WebhookStatisticsInterval = typeof WebhookStatisticsInterval.Type;
13
+ export declare const WebhookStatisticsRequest: Schema.Struct<{
14
+ readonly organizationId: Schema.NonEmptyString;
15
+ readonly id: Schema.NonEmptyString;
16
+ readonly interval: Schema.Literals<readonly ["hour", "day"]>;
17
+ }>;
18
+ export declare const WebhookDeliveryCounts: Schema.Struct<{
19
+ readonly total: Schema.Int;
20
+ readonly success: Schema.Int;
21
+ readonly failed: Schema.Int;
22
+ }>;
23
+ export declare const WebhookEventCount: Schema.Struct<{
24
+ readonly event: Schema.String;
25
+ readonly total: Schema.Int;
26
+ }>;
27
+ export declare const WebhookDeliveryBucket: Schema.Struct<{
28
+ readonly total: Schema.Int;
29
+ readonly success: Schema.Int;
30
+ readonly failed: Schema.Int;
31
+ readonly bucket: Schema.Date;
32
+ readonly events: Schema.$Array<Schema.Struct<{
33
+ readonly event: Schema.String;
34
+ readonly total: Schema.Int;
35
+ }>>;
36
+ }>;
37
+ export declare const WebhookStatistics: Schema.Struct<{
38
+ readonly total: Schema.Int;
39
+ readonly success: Schema.Int;
40
+ readonly failed: Schema.Int;
41
+ readonly buckets: Schema.$Array<Schema.Struct<{
42
+ readonly total: Schema.Int;
43
+ readonly success: Schema.Int;
44
+ readonly failed: Schema.Int;
45
+ readonly bucket: Schema.Date;
46
+ readonly events: Schema.$Array<Schema.Struct<{
47
+ readonly event: Schema.String;
48
+ readonly total: Schema.Int;
49
+ }>>;
50
+ }>>;
51
+ }>;
52
+ export declare const WebhookName: Schema.Trim;
53
+ export declare const WebhookPayload: Schema.Struct<{
54
+ readonly name: Schema.optional<Schema.Trim>;
55
+ readonly url: Schema.String;
56
+ readonly description: Schema.NullOr<Schema.String>;
57
+ readonly enabled: Schema.Boolean;
58
+ readonly events: Schema.NullOr<Schema.$Array<Schema.NonEmptyString>>;
59
+ readonly customHeaders: Schema.NullOr<Schema.$Record<Schema.String, Schema.String>>;
60
+ }>;
61
+ export declare const Webhook: Schema.Struct<{
62
+ readonly id: Schema.String;
63
+ readonly name: Schema.String;
64
+ readonly organizationId: Schema.String;
65
+ readonly url: Schema.String;
66
+ readonly description: Schema.NullOr<Schema.String>;
67
+ readonly headers: Schema.NullOr<Schema.$Record<Schema.String, Schema.String>>;
68
+ readonly events: Schema.NullOr<Schema.$Array<Schema.String>>;
69
+ readonly secret: Schema.String;
70
+ readonly enabled: Schema.Boolean;
71
+ readonly createdAt: Schema.Date;
72
+ readonly updatedAt: Schema.Date;
73
+ }>;
74
+ export declare const WebhookDelivery: Schema.Struct<{
75
+ readonly id: Schema.String;
76
+ readonly webhookId: Schema.String;
77
+ readonly event: Schema.String;
78
+ readonly data: Schema.Codec<Schema.Json, Schema.Json, never, never>;
79
+ readonly status: Schema.Literals<readonly ["pending", "success", "failed"]>;
80
+ readonly error: Schema.NullOr<Schema.String>;
81
+ readonly completedAt: Schema.NullOr<Schema.Date>;
82
+ readonly retryAt: Schema.Date;
83
+ readonly retries: Schema.Int;
84
+ readonly createdAt: Schema.Date;
85
+ readonly updatedAt: Schema.Date;
86
+ }>;
87
+ export declare const WebhookDeliverySortId: Schema.Literals<readonly ["id", "event", "status", "createdAt", "completedAt"]>;
88
+ export declare const WebhookDeliveriesQuery: Schema.Struct<{
89
+ readonly page: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
90
+ readonly pageSize: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
91
+ readonly globalFilter: Schema.optional<Schema.String>;
92
+ readonly filters: Schema.optional<Schema.declare<readonly ({
93
+ readonly id: string;
94
+ readonly kind: "number";
95
+ readonly min?: number | undefined;
96
+ readonly max?: number | undefined;
97
+ } | {
98
+ readonly id: string;
99
+ readonly kind: "date";
100
+ readonly from?: string | undefined;
101
+ readonly to?: string | undefined;
102
+ } | {
103
+ readonly id: string;
104
+ readonly kind: "text";
105
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
106
+ readonly value: string;
107
+ } | {
108
+ readonly id: string;
109
+ readonly kind: "boolean";
110
+ readonly value: boolean;
111
+ } | {
112
+ readonly id: string;
113
+ readonly kind: "values";
114
+ readonly values: readonly [string, ...string[]];
115
+ })[], readonly ({
116
+ readonly id: string;
117
+ readonly kind: "number";
118
+ readonly min?: number | undefined;
119
+ readonly max?: number | undefined;
120
+ } | {
121
+ readonly id: string;
122
+ readonly kind: "date";
123
+ readonly from?: string | undefined;
124
+ readonly to?: string | undefined;
125
+ } | {
126
+ readonly id: string;
127
+ readonly kind: "text";
128
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
129
+ readonly value: string;
130
+ } | {
131
+ readonly id: string;
132
+ readonly kind: "boolean";
133
+ readonly value: boolean;
134
+ } | {
135
+ readonly id: string;
136
+ readonly kind: "values";
137
+ readonly values: readonly [string, ...string[]];
138
+ })[]>>;
139
+ readonly sort: Schema.optional<Schema.declare<readonly {
140
+ readonly id: string;
141
+ readonly direction: "asc" | "desc";
142
+ }[], readonly {
143
+ readonly id: string;
144
+ readonly direction: "asc" | "desc";
145
+ }[]>>;
146
+ }>;
147
+ export declare const ListWebhookDeliveries: Schema.Struct<{
148
+ readonly page: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
149
+ readonly pageSize: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
150
+ readonly globalFilter: Schema.optional<Schema.String>;
151
+ readonly organizationId: Schema.NonEmptyString;
152
+ readonly id: Schema.NonEmptyString;
153
+ readonly filters: Schema.optional<Schema.declare<readonly ({
154
+ readonly id: string;
155
+ readonly kind: "number";
156
+ readonly min?: number | undefined;
157
+ readonly max?: number | undefined;
158
+ } | {
159
+ readonly id: string;
160
+ readonly kind: "date";
161
+ readonly from?: string | undefined;
162
+ readonly to?: string | undefined;
163
+ } | {
164
+ readonly id: string;
165
+ readonly kind: "text";
166
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
167
+ readonly value: string;
168
+ } | {
169
+ readonly id: string;
170
+ readonly kind: "boolean";
171
+ readonly value: boolean;
172
+ } | {
173
+ readonly id: string;
174
+ readonly kind: "values";
175
+ readonly values: readonly [string, ...string[]];
176
+ })[], readonly ({
177
+ readonly id: string;
178
+ readonly kind: "number";
179
+ readonly min?: number | undefined;
180
+ readonly max?: number | undefined;
181
+ } | {
182
+ readonly id: string;
183
+ readonly kind: "date";
184
+ readonly from?: string | undefined;
185
+ readonly to?: string | undefined;
186
+ } | {
187
+ readonly id: string;
188
+ readonly kind: "text";
189
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
190
+ readonly value: string;
191
+ } | {
192
+ readonly id: string;
193
+ readonly kind: "boolean";
194
+ readonly value: boolean;
195
+ } | {
196
+ readonly id: string;
197
+ readonly kind: "values";
198
+ readonly values: readonly [string, ...string[]];
199
+ })[]>>;
200
+ readonly sort: Schema.optional<Schema.declare<readonly {
201
+ readonly id: string;
202
+ readonly direction: "asc" | "desc";
203
+ }[], readonly {
204
+ readonly id: string;
205
+ readonly direction: "asc" | "desc";
206
+ }[]>>;
207
+ }>;
208
+ export declare const WebhookDeliveries: Schema.Struct<{
209
+ readonly data: Schema.$Array<Schema.Struct<{
210
+ readonly id: Schema.String;
211
+ readonly webhookId: Schema.String;
212
+ readonly event: Schema.String;
213
+ readonly data: Schema.Codec<Schema.Json, Schema.Json, never, never>;
214
+ readonly status: Schema.Literals<readonly ["pending", "success", "failed"]>;
215
+ readonly error: Schema.NullOr<Schema.String>;
216
+ readonly completedAt: Schema.NullOr<Schema.Date>;
217
+ readonly retryAt: Schema.Date;
218
+ readonly retries: Schema.Int;
219
+ readonly createdAt: Schema.Date;
220
+ readonly updatedAt: Schema.Date;
221
+ }>>;
222
+ readonly meta: Schema.Struct<{
223
+ readonly page: Schema.Int;
224
+ readonly pageSize: Schema.Int;
225
+ readonly total: Schema.Int;
226
+ readonly pageCount: Schema.Int;
227
+ }>;
228
+ }>;
229
+ export declare const PublishWebhook: Schema.Struct<{
230
+ readonly organizationId: Schema.NonEmptyString;
231
+ readonly eventId: Schema.NonEmptyString;
232
+ readonly event: Schema.NonEmptyString;
233
+ readonly data: Schema.Codec<Schema.Json, Schema.Json, never, never>;
234
+ }>;
235
+ declare const WebhookError_base: Schema.Class<WebhookError, Schema.TaggedStruct<"WebhookError", {
236
+ readonly message: Schema.String;
237
+ }>, import("effect/Cause").YieldableError>;
238
+ export declare class WebhookError extends WebhookError_base {
239
+ }
240
+ export type Webhook = typeof Webhook.Type;
241
+ export type WebhookDelivery = typeof WebhookDelivery.Type;
242
+ export type WebhookPayload = typeof WebhookPayload.Type;
243
+ export {};
@@ -0,0 +1,333 @@
1
+ // ../../src/services/webhooks/schema.ts
2
+ import { Schema as Schema2 } from "effect";
3
+
4
+ // ../../src/services/webhooks/url.ts
5
+ var hostname = (value) => value.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
6
+ var isPublicIpAddress = (value) => {
7
+ const address = hostname(value);
8
+ const octets = address.split(".");
9
+ if (octets.length === 4 && octets.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255)) {
10
+ const [a = 0, b = 0, c = 0] = octets.map(Number);
11
+ return !(a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && (b === 0 || b === 168 || b === 88 && c === 99) || a === 198 && (b === 18 || b === 19 || b === 51) || a === 203 && b === 0 || a >= 224);
12
+ }
13
+ const first = Number.parseInt(address.split(":")[0] ?? "", 16);
14
+ return address.includes(":") && first >= 8192 && first <= 16383 && !address.startsWith("2001:") && !address.startsWith("2002:") && !address.startsWith("3fff:");
15
+ };
16
+ var isPublicWebhookUrl = (url) => {
17
+ if (!["https:", "http:"].includes(url.protocol) || url.username || url.password)
18
+ return false;
19
+ const host = hostname(url.hostname);
20
+ if (!host || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local"))
21
+ return false;
22
+ return !(host.includes(":") || /^\d+(?:\.\d+){3}$/.test(host)) || isPublicIpAddress(host);
23
+ };
24
+ var isPublicWebhookUrlString = (value) => {
25
+ try {
26
+ return isPublicWebhookUrl(new URL(value));
27
+ } catch {
28
+ return false;
29
+ }
30
+ };
31
+
32
+ // ../../src/lib/query.ts
33
+ import {
34
+ DateTime,
35
+ Effect,
36
+ Option,
37
+ Schema,
38
+ SchemaGetter,
39
+ SchemaIssue,
40
+ SchemaTransformation
41
+ } from "effect";
42
+ var parseSortParam = (sort) => {
43
+ const id = sort.startsWith("-") ? sort.slice(1) : sort;
44
+ if (!id || id.includes(",") || id.includes(":")) {
45
+ return null;
46
+ }
47
+ return { id, direction: sort.startsWith("-") ? "desc" : "asc" };
48
+ };
49
+ var SortDirection = Schema.Union([
50
+ Schema.Literal("asc"),
51
+ Schema.Literal("desc")
52
+ ]).pipe(Schema.annotate({
53
+ identifier: "SortDirection",
54
+ title: "Sort Direction",
55
+ description: "Sort direction for list query results.",
56
+ examples: ["asc", "desc"]
57
+ }));
58
+ var SortParam = Schema.Struct({
59
+ id: Schema.NonEmptyString,
60
+ direction: SortDirection
61
+ }).pipe(Schema.annotate({
62
+ identifier: "SortParam",
63
+ title: "Sort Parameter",
64
+ description: "Decoded sort parameter with a field id and direction.",
65
+ examples: [{ id: "publicName", direction: "asc" }]
66
+ }));
67
+ var SortParamFromString = Schema.String.pipe(Schema.decodeTo(SortParam, SchemaTransformation.transformEffect({
68
+ decode: (sort) => {
69
+ const sortParam = parseSortParam(sort);
70
+ if (!sortParam) {
71
+ return Effect.fail(new SchemaIssue.InvalidValue({ message: 'Expected sort in the format "field" or "-field"' }, sort));
72
+ }
73
+ return Effect.succeed(sortParam);
74
+ },
75
+ encode: (sort) => Effect.succeed(sort.direction === "desc" ? `-${sort.id}` : sort.id)
76
+ })), Schema.annotate({
77
+ identifier: "SortParamFromString",
78
+ title: "Sort Parameter From String",
79
+ description: 'URL encoded single sort parameter where descending fields are prefixed with "-".',
80
+ examples: [{ id: "publicName", direction: "asc" }]
81
+ }));
82
+ var SortParamsFromString = Schema.String.pipe(Schema.decodeTo(Schema.Array(SortParam), SchemaTransformation.transformEffect({
83
+ decode: (sort) => {
84
+ if (sort === "")
85
+ return Effect.succeed([]);
86
+ const parts = sort.split(",");
87
+ const sortParams = [];
88
+ for (const part of parts) {
89
+ const sortParam = parseSortParam(part);
90
+ if (!sortParam) {
91
+ return Effect.fail(new SchemaIssue.InvalidValue({ message: 'Expected sort in the format "field,-otherField"' }, sort));
92
+ }
93
+ sortParams.push(sortParam);
94
+ }
95
+ return Effect.succeed(sortParams);
96
+ },
97
+ encode: (sort) => Effect.succeed(sort.map((part) => Schema.encodeSync(SortParamFromString)(part)).join(","))
98
+ })), Schema.annotate({
99
+ identifier: "SortParamsFromString",
100
+ title: "Sort Parameters From String",
101
+ description: 'URL encoded sort parameters where descending fields are prefixed with "-" and multiple fields are comma-separated.',
102
+ examples: [
103
+ [
104
+ { id: "name", direction: "desc" },
105
+ { id: "age", direction: "asc" }
106
+ ]
107
+ ]
108
+ }));
109
+ var SortParamsArray = Schema.Array(SortParam);
110
+ var SortParams = Schema.declare(Schema.is(SortParamsArray), {
111
+ identifier: "SortParams",
112
+ toCodec: () => Schema.link()(SortParamsArray, SchemaTransformation.passthrough()),
113
+ toCodecStringTree: () => Schema.link()(SortParamsFromString, SchemaTransformation.passthrough())
114
+ });
115
+ var TextFilterOperator = Schema.Literals([
116
+ "contains",
117
+ "equals",
118
+ "startsWith",
119
+ "endsWith"
120
+ ]).annotate({ identifier: "TextFilterOperator" });
121
+ var FilterCalendarDate = Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}$/), Schema.makeFilter((value) => Option.exists(DateTime.make(value), (date) => DateTime.formatIsoDateUtc(date) === value))).annotate({ identifier: "FilterCalendarDate" });
122
+ var ColumnFilter = Schema.Union([
123
+ Schema.Struct({
124
+ id: Schema.NonEmptyString,
125
+ kind: Schema.Literal("text"),
126
+ operator: TextFilterOperator,
127
+ value: Schema.NonEmptyString
128
+ }),
129
+ Schema.Struct({
130
+ id: Schema.NonEmptyString,
131
+ kind: Schema.Literal("number"),
132
+ min: Schema.optional(Schema.Finite),
133
+ max: Schema.optional(Schema.Finite)
134
+ }).check(Schema.makeFilter((range) => (range.min !== undefined || range.max !== undefined) && (range.min === undefined || range.max === undefined || range.min <= range.max))),
135
+ Schema.Struct({
136
+ id: Schema.NonEmptyString,
137
+ kind: Schema.Literal("date"),
138
+ from: Schema.optional(FilterCalendarDate),
139
+ to: Schema.optional(FilterCalendarDate)
140
+ }).check(Schema.makeFilter((range) => (range.from !== undefined || range.to !== undefined) && (range.from === undefined || range.to === undefined || range.from <= range.to))),
141
+ Schema.Struct({
142
+ id: Schema.NonEmptyString,
143
+ kind: Schema.Literal("boolean"),
144
+ value: Schema.Boolean
145
+ }),
146
+ Schema.Struct({
147
+ id: Schema.NonEmptyString,
148
+ kind: Schema.Literal("values"),
149
+ values: Schema.NonEmptyArray(Schema.String)
150
+ })
151
+ ]).annotate({ identifier: "ColumnFilter" });
152
+ var ColumnFiltersArray = Schema.Array(ColumnFilter);
153
+ var ColumnFilters = Schema.declare(Schema.is(ColumnFiltersArray), {
154
+ identifier: "ColumnFilters",
155
+ toCodec: () => Schema.link()(ColumnFiltersArray, SchemaTransformation.passthrough()),
156
+ toCodecStringTree: () => Schema.link()(Schema.fromJsonString(ColumnFiltersArray), SchemaTransformation.passthrough())
157
+ });
158
+ var Query = Schema.Struct({
159
+ page: Schema.optional(Schema.Union([Schema.Number, Schema.NumberFromString]).check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))).pipe(Schema.decodeTo(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)), {
160
+ decode: SchemaGetter.withDefault(Effect.succeed(0)),
161
+ encode: SchemaGetter.transformOptional(Option.filter((page) => page !== 0))
162
+ })),
163
+ pageSize: Schema.optional(Schema.Union([Schema.Number, Schema.NumberFromString]).check(Schema.isInt(), Schema.isBetween({ minimum: 1, maximum: 100 }))).pipe(Schema.decodeTo(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 })), {
164
+ decode: SchemaGetter.withDefault(Effect.succeed(20)),
165
+ encode: SchemaGetter.transformOptional(Option.filter((pageSize) => pageSize !== 20))
166
+ })),
167
+ globalFilter: Schema.optional(Schema.String),
168
+ sort: Schema.optional(SortParams),
169
+ filters: Schema.optional(ColumnFilters)
170
+ }).annotate({
171
+ identifier: "Query",
172
+ title: "Query",
173
+ description: "Zero-based page request parameters with optional filtering and sorting for list endpoints.",
174
+ examples: [
175
+ {
176
+ page: 0,
177
+ pageSize: 20,
178
+ globalFilter: "housing",
179
+ sort: [
180
+ { id: "publicName", direction: "desc" },
181
+ { id: "createdAt", direction: "asc" }
182
+ ]
183
+ }
184
+ ]
185
+ });
186
+ var QueryStandard = Schema.toStandardSchemaV1(Query);
187
+ var PaginationMeta = Schema.Struct({
188
+ page: Schema.Int,
189
+ pageSize: Schema.Int,
190
+ total: Schema.Int,
191
+ pageCount: Schema.Int
192
+ }).pipe(Schema.annotate({
193
+ identifier: "PaginationMeta",
194
+ title: "Pagination Metadata",
195
+ description: "Pagination metadata returned with a paginated list response.",
196
+ examples: [{ page: 0, pageSize: 20, total: 125, pageCount: 7 }]
197
+ }));
198
+ var PaginatedResponse = (items) => Schema.Struct({
199
+ data: Schema.Array(items),
200
+ meta: PaginationMeta
201
+ });
202
+
203
+ // ../../src/services/webhooks/schema.ts
204
+ var webhookColumns = 'id, organization_id AS "organizationId", COALESCE(name, url) AS name, url, description, headers, events, secret, enabled, created_at AS "createdAt", updated_at AS "updatedAt"';
205
+ var deliveryColumns = 'd.id, d.webhook_id AS "webhookId", d.event, d.data, d.status, d.error, d.completed_at AS "completedAt", d.retry_at AS "retryAt", d.retries, d.created_at AS "createdAt", d.updated_at AS "updatedAt"';
206
+ var WebhookScope = Schema2.Struct({
207
+ organizationId: Schema2.NonEmptyString
208
+ }).annotate({ identifier: "WebhookScope" });
209
+ var WebhookRequest = Schema2.Struct({
210
+ organizationId: Schema2.NonEmptyString,
211
+ id: Schema2.NonEmptyString
212
+ }).annotate({ identifier: "WebhookRequest" });
213
+ var WebhookStatisticsInterval = Schema2.Literals([
214
+ "hour",
215
+ "day"
216
+ ]).annotate({ identifier: "WebhookStatisticsInterval" });
217
+ var WebhookStatisticsRequest = Schema2.Struct({
218
+ ...WebhookRequest.fields,
219
+ interval: WebhookStatisticsInterval
220
+ }).annotate({ identifier: "WebhookStatisticsRequest" });
221
+ var WebhookDeliveryCounts = Schema2.Struct({
222
+ total: Schema2.Int,
223
+ success: Schema2.Int,
224
+ failed: Schema2.Int
225
+ }).annotate({ identifier: "WebhookDeliveryCounts" });
226
+ var WebhookEventCount = Schema2.Struct({
227
+ event: Schema2.String,
228
+ total: Schema2.Int
229
+ }).annotate({ identifier: "WebhookEventCount" });
230
+ var WebhookDeliveryBucket = Schema2.Struct({
231
+ ...WebhookDeliveryCounts.fields,
232
+ bucket: Schema2.Date,
233
+ events: Schema2.Array(WebhookEventCount)
234
+ }).annotate({ identifier: "WebhookDeliveryBucket" });
235
+ var WebhookStatistics = Schema2.Struct({
236
+ ...WebhookDeliveryCounts.fields,
237
+ buckets: Schema2.Array(WebhookDeliveryBucket)
238
+ }).annotate({ identifier: "WebhookStatistics" });
239
+ var WebhookName = Schema2.Trim.check(Schema2.isMinLength(1), Schema2.isMaxLength(200)).annotate({ identifier: "WebhookName" });
240
+ var WebhookPayload = Schema2.Struct({
241
+ name: Schema2.optional(WebhookName),
242
+ url: Schema2.String.check(Schema2.makeFilter(isPublicWebhookUrlString, {
243
+ expected: "a public HTTP or HTTPS URL without credentials"
244
+ })),
245
+ description: Schema2.NullOr(Schema2.String),
246
+ enabled: Schema2.Boolean,
247
+ events: Schema2.NullOr(Schema2.Array(Schema2.NonEmptyString)),
248
+ customHeaders: Schema2.NullOr(Schema2.Record(Schema2.String, Schema2.String)).check(Schema2.makeFilter((headers) => Object.keys(headers ?? {}).every((name) => ![
249
+ "content-type",
250
+ "webhook-id",
251
+ "webhook-timestamp",
252
+ "webhook-signature"
253
+ ].includes(name.toLowerCase())), { expected: "headers that do not override webhook protocol headers" }))
254
+ }).annotate({ identifier: "WebhookPayload" });
255
+ var Webhook = Schema2.Struct({
256
+ id: Schema2.String,
257
+ name: Schema2.String,
258
+ organizationId: Schema2.String,
259
+ url: Schema2.String,
260
+ description: Schema2.NullOr(Schema2.String),
261
+ headers: Schema2.NullOr(Schema2.Record(Schema2.String, Schema2.String)),
262
+ events: Schema2.NullOr(Schema2.Array(Schema2.String)),
263
+ secret: Schema2.String,
264
+ enabled: Schema2.Boolean,
265
+ createdAt: Schema2.Date,
266
+ updatedAt: Schema2.Date
267
+ }).annotate({ identifier: "Webhook" });
268
+ var WebhookDelivery = Schema2.Struct({
269
+ id: Schema2.String,
270
+ webhookId: Schema2.String,
271
+ event: Schema2.String,
272
+ data: Schema2.Json,
273
+ status: Schema2.Literals(["pending", "success", "failed"]),
274
+ error: Schema2.NullOr(Schema2.String),
275
+ completedAt: Schema2.NullOr(Schema2.Date),
276
+ retryAt: Schema2.Date,
277
+ retries: Schema2.Int,
278
+ createdAt: Schema2.Date,
279
+ updatedAt: Schema2.Date
280
+ }).annotate({ identifier: "WebhookDelivery" });
281
+ var WebhookDeliverySortId = Schema2.Literals([
282
+ "id",
283
+ "event",
284
+ "status",
285
+ "createdAt",
286
+ "completedAt"
287
+ ]).annotate({ identifier: "WebhookDeliverySortId" });
288
+ var DeliveryFilter = ColumnFilter.check(Schema2.makeFilter((filter) => filter.id === "id" ? filter.kind === "text" : filter.id === "event" ? filter.kind === "values" : filter.id === "status" ? filter.kind === "values" && filter.values.every((value) => ["pending", "success", "failed"].includes(value)) : ["createdAt", "completedAt"].includes(filter.id) && filter.kind === "date")).annotate({ identifier: "WebhookDeliveryFilter" });
289
+ var WebhookDeliveriesQuery = Schema2.Struct({
290
+ ...Query.fields,
291
+ filters: Schema2.optional(ColumnFilters.check(Schema2.makeFilter((filters) => filters.every(Schema2.is(DeliveryFilter))))),
292
+ sort: Schema2.optional(SortParams.check(Schema2.makeFilter((sort) => sort.every((part) => Schema2.is(WebhookDeliverySortId)(part.id)))))
293
+ }).annotate({ identifier: "WebhookDeliveriesQuery" });
294
+ var ListWebhookDeliveries = Schema2.Struct({
295
+ ...WebhookRequest.fields,
296
+ ...WebhookDeliveriesQuery.fields
297
+ }).annotate({ identifier: "ListWebhookDeliveries" });
298
+ var WebhookDeliveries = PaginatedResponse(WebhookDelivery).annotate({
299
+ identifier: "WebhookDeliveries"
300
+ });
301
+ var PublishWebhook = Schema2.Struct({
302
+ organizationId: Schema2.NonEmptyString,
303
+ eventId: Schema2.NonEmptyString,
304
+ event: Schema2.NonEmptyString,
305
+ data: Schema2.Json
306
+ }).annotate({ identifier: "PublishWebhook" });
307
+
308
+ class WebhookError extends Schema2.TaggedError()("WebhookError", {
309
+ message: Schema2.String
310
+ }) {
311
+ }
312
+ export {
313
+ ListWebhookDeliveries,
314
+ PublishWebhook,
315
+ Webhook,
316
+ WebhookDeliveries,
317
+ WebhookDeliveriesQuery,
318
+ WebhookDelivery,
319
+ WebhookDeliveryBucket,
320
+ WebhookDeliveryCounts,
321
+ WebhookDeliverySortId,
322
+ WebhookError,
323
+ WebhookEventCount,
324
+ WebhookName,
325
+ WebhookPayload,
326
+ WebhookRequest,
327
+ WebhookScope,
328
+ WebhookStatistics,
329
+ WebhookStatisticsInterval,
330
+ WebhookStatisticsRequest,
331
+ deliveryColumns,
332
+ webhookColumns
333
+ };
@@ -0,0 +1,3 @@
1
+ export declare const isPublicIpAddress: (value: string) => boolean;
2
+ export declare const isPublicWebhookUrl: (url: URL) => boolean;
3
+ export declare const isPublicWebhookUrlString: (value: string) => boolean;
@@ -0,0 +1,32 @@
1
+ // ../../src/services/webhooks/url.ts
2
+ var hostname = (value) => value.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
3
+ var isPublicIpAddress = (value) => {
4
+ const address = hostname(value);
5
+ const octets = address.split(".");
6
+ if (octets.length === 4 && octets.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255)) {
7
+ const [a = 0, b = 0, c = 0] = octets.map(Number);
8
+ return !(a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && (b === 0 || b === 168 || b === 88 && c === 99) || a === 198 && (b === 18 || b === 19 || b === 51) || a === 203 && b === 0 || a >= 224);
9
+ }
10
+ const first = Number.parseInt(address.split(":")[0] ?? "", 16);
11
+ return address.includes(":") && first >= 8192 && first <= 16383 && !address.startsWith("2001:") && !address.startsWith("2002:") && !address.startsWith("3fff:");
12
+ };
13
+ var isPublicWebhookUrl = (url) => {
14
+ if (!["https:", "http:"].includes(url.protocol) || url.username || url.password)
15
+ return false;
16
+ const host = hostname(url.hostname);
17
+ if (!host || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local"))
18
+ return false;
19
+ return !(host.includes(":") || /^\d+(?:\.\d+){3}$/.test(host)) || isPublicIpAddress(host);
20
+ };
21
+ var isPublicWebhookUrlString = (value) => {
22
+ try {
23
+ return isPublicWebhookUrl(new URL(value));
24
+ } catch {
25
+ return false;
26
+ }
27
+ };
28
+ export {
29
+ isPublicIpAddress,
30
+ isPublicWebhookUrl,
31
+ isPublicWebhookUrlString
32
+ };