@xube/kit-aws-hooks 0.0.22

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 @@
1
+ export declare const WEBHOOK_TABLE_NAME_ENV_VAR = "WEBHOOK_TABLE_NAME";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WEBHOOK_TABLE_NAME_ENV_VAR = void 0;
4
+ exports.WEBHOOK_TABLE_NAME_ENV_VAR = "WEBHOOK_TABLE_NAME";
@@ -0,0 +1,4 @@
1
+ import { CreateWebhookForAccountRequest, CreateWebhookForAccountResponse } from "./schemas/create";
2
+ import { XubeResponse } from "@xube/kit-request";
3
+ import { XubeLog } from "@xube/kit-log";
4
+ export declare const createWebhookForAccount: (request: CreateWebhookForAccountRequest, tableName: string, log?: XubeLog) => Promise<XubeResponse<CreateWebhookForAccountResponse>>;
package/dist/create.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWebhookForAccount = void 0;
4
+ const create_1 = require("./schemas/create");
5
+ const kit_request_1 = require("@xube/kit-request");
6
+ const kit_constants_1 = require("@xube/kit-constants");
7
+ const generate_1 = require("./generate");
8
+ const kit_aws_1 = require("@xube/kit-aws");
9
+ const kit_log_1 = require("@xube/kit-log");
10
+ const createWebhookForAccount = async (request, tableName, log = kit_log_1.XubeLog.getInstance()) => {
11
+ if (!(0, create_1.isCreateWebhookForAccountRequest)(request)) {
12
+ return new kit_request_1.XubeResponse({
13
+ statusCode: kit_constants_1.StatusCode.BadRequest,
14
+ error: `Webhook creation request did not have the expected structure.`,
15
+ });
16
+ }
17
+ const newWebhooks = (0, generate_1.generateWebhookItems)(request);
18
+ const putWebhookItems = [];
19
+ for (const webhook of newWebhooks) {
20
+ putWebhookItems.push((0, kit_aws_1.putItemInTable)(tableName, webhook));
21
+ }
22
+ const putItemResponses = await Promise.all(putWebhookItems);
23
+ const failedWebhooks = [];
24
+ const failedResponses = putItemResponses.filter((response, idx) => {
25
+ failedWebhooks.push(newWebhooks[idx]);
26
+ return response.hasFailed();
27
+ });
28
+ if (failedResponses.length) {
29
+ log.error(`Failed to save ${failedResponses} out or ${newWebhooks.length} to ddb.`);
30
+ log.info(`Failed webhooks: ${JSON.stringify(failedWebhooks, null, 2)}`);
31
+ return new kit_request_1.XubeResponse({
32
+ statusCode: failedResponses.length === newWebhooks.length
33
+ ? kit_constants_1.StatusCode.InternalError
34
+ : kit_constants_1.StatusCode.PartialSuccess,
35
+ error: `Failed to save the following webhooks to ddb:\n${JSON.stringify(failedWebhooks, null, 2)}`,
36
+ });
37
+ }
38
+ return new kit_request_1.XubeResponse({
39
+ statusCode: kit_constants_1.StatusCode.OK,
40
+ data: {
41
+ success: true,
42
+ },
43
+ });
44
+ };
45
+ exports.createWebhookForAccount = createWebhookForAccount;
File without changes
package/dist/delete.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,3 @@
1
+ import { CreateWebhookForAccountRequest } from "./schemas/create";
2
+ import { WebhookEndpointItem } from "./schemas/webhook";
3
+ export declare const generateWebhookItems: (request: CreateWebhookForAccountRequest) => WebhookEndpointItem[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateWebhookItems = void 0;
4
+ const keys_1 = require("./keys");
5
+ const types_1 = require("./types");
6
+ const generateWebhookItems = (request) => {
7
+ const webhookItems = [];
8
+ for (const endpoint of request.endpoints) {
9
+ for (const id of request.ids) {
10
+ webhookItems.push({
11
+ account: request.account,
12
+ ...endpoint,
13
+ id,
14
+ PK: (0, keys_1.getWebhookPartitionKey)(request.account),
15
+ SK: (0, keys_1.getWebhookSortKey)(id, request.type ?? types_1.WebhookTypes.data),
16
+ });
17
+ }
18
+ }
19
+ return webhookItems;
20
+ };
21
+ exports.generateWebhookItems = generateWebhookItems;
package/dist/get.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const getWebhooks: () => void;
package/dist/get.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWebhooks = void 0;
4
+ const getWebhooks = () => {
5
+ };
6
+ exports.getWebhooks = getWebhooks;
@@ -0,0 +1,9 @@
1
+ export * from "./schemas/create";
2
+ export * from "./schemas/endpoint";
3
+ export * from "./schemas/webhook";
4
+ export * from "./constants";
5
+ export * from "./create";
6
+ export * from "./generate";
7
+ export * from "./get";
8
+ export * from "./keys";
9
+ export * from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schemas/create"), exports);
18
+ __exportStar(require("./schemas/endpoint"), exports);
19
+ __exportStar(require("./schemas/webhook"), exports);
20
+ __exportStar(require("./constants"), exports);
21
+ __exportStar(require("./create"), exports);
22
+ // export * from "./delete";
23
+ __exportStar(require("./generate"), exports);
24
+ __exportStar(require("./get"), exports);
25
+ __exportStar(require("./keys"), exports);
26
+ __exportStar(require("./types"), exports);
package/dist/keys.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const getWebhookPartitionKey: (account: string) => string;
2
+ export declare const getWebhookSortKey: (id: string, type: string) => string;
package/dist/keys.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWebhookSortKey = exports.getWebhookPartitionKey = void 0;
4
+ const getWebhookPartitionKey = (account) => {
5
+ return `ACCOUNT#${account}`;
6
+ };
7
+ exports.getWebhookPartitionKey = getWebhookPartitionKey;
8
+ const getWebhookSortKey = (id, type) => {
9
+ return `HOOK#${id}#${type}`;
10
+ };
11
+ exports.getWebhookSortKey = getWebhookSortKey;
@@ -0,0 +1,93 @@
1
+ import { z } from "zod";
2
+ export declare const CreateWebhookForAccountRequestSchema: z.ZodObject<{
3
+ account: z.ZodString;
4
+ ids: z.ZodArray<z.ZodString, "many">;
5
+ endpoints: z.ZodArray<z.ZodObject<{
6
+ url: z.ZodString;
7
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ url: string;
10
+ headers: Record<string, string>;
11
+ }, {
12
+ url: string;
13
+ headers: Record<string, string>;
14
+ }>, "many">;
15
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
16
+ type: z.ZodOptional<z.ZodNativeEnum<{
17
+ readonly data: "data";
18
+ readonly event: "event";
19
+ }>>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ headers: Record<string, string>;
22
+ account: string;
23
+ ids: string[];
24
+ endpoints: {
25
+ url: string;
26
+ headers: Record<string, string>;
27
+ }[];
28
+ type?: "data" | "event" | undefined;
29
+ }, {
30
+ headers: Record<string, string>;
31
+ account: string;
32
+ ids: string[];
33
+ endpoints: {
34
+ url: string;
35
+ headers: Record<string, string>;
36
+ }[];
37
+ type?: "data" | "event" | undefined;
38
+ }>;
39
+ export type CreateWebhookForAccountRequest = z.infer<typeof CreateWebhookForAccountRequestSchema>;
40
+ export declare const isCreateWebhookForAccountRequest: (obj: unknown) => obj is {
41
+ headers: Record<string, string>;
42
+ account: string;
43
+ ids: string[];
44
+ endpoints: {
45
+ url: string;
46
+ headers: Record<string, string>;
47
+ }[];
48
+ type?: "data" | "event" | undefined;
49
+ };
50
+ export declare const CreateWebhookForAccountResponseSchema: z.ZodObject<{
51
+ success: z.ZodBoolean;
52
+ }, "strip", z.ZodTypeAny, {
53
+ success: boolean;
54
+ }, {
55
+ success: boolean;
56
+ }>;
57
+ export type CreateWebhookForAccountResponse = z.infer<typeof CreateWebhookForAccountResponseSchema>;
58
+ export declare const CreateWebhookRequestSchema: z.ZodObject<{
59
+ ids: z.ZodString;
60
+ endpoints: z.ZodArray<z.ZodObject<{
61
+ url: z.ZodString;
62
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
63
+ }, "strip", z.ZodTypeAny, {
64
+ url: string;
65
+ headers: Record<string, string>;
66
+ }, {
67
+ url: string;
68
+ headers: Record<string, string>;
69
+ }>, "many">;
70
+ headers: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>, "many">;
71
+ }, "strip", z.ZodTypeAny, {
72
+ headers: Record<string, string>[];
73
+ ids: string;
74
+ endpoints: {
75
+ url: string;
76
+ headers: Record<string, string>;
77
+ }[];
78
+ }, {
79
+ headers: Record<string, string>[];
80
+ ids: string;
81
+ endpoints: {
82
+ url: string;
83
+ headers: Record<string, string>;
84
+ }[];
85
+ }>;
86
+ export declare const CreateWebhookResponseSchema: z.ZodObject<{
87
+ success: z.ZodBoolean;
88
+ }, "strip", z.ZodTypeAny, {
89
+ success: boolean;
90
+ }, {
91
+ success: boolean;
92
+ }>;
93
+ export type CreateWebhookResponse = z.infer<typeof CreateWebhookResponseSchema>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateWebhookResponseSchema = exports.CreateWebhookRequestSchema = exports.CreateWebhookForAccountResponseSchema = exports.isCreateWebhookForAccountRequest = exports.CreateWebhookForAccountRequestSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const endpoint_1 = require("./endpoint");
6
+ const types_1 = require("../types");
7
+ exports.CreateWebhookForAccountRequestSchema = zod_1.z.object({
8
+ account: zod_1.z.string(),
9
+ ids: zod_1.z.array(zod_1.z.string()),
10
+ endpoints: zod_1.z.array(endpoint_1.HookEndpointSchema),
11
+ headers: endpoint_1.HookEndpointHeaderSchema,
12
+ type: types_1.WebhookTypesSchema.optional(),
13
+ });
14
+ const isCreateWebhookForAccountRequest = (obj) => {
15
+ exports.CreateWebhookForAccountRequestSchema.parse(obj);
16
+ return true;
17
+ };
18
+ exports.isCreateWebhookForAccountRequest = isCreateWebhookForAccountRequest;
19
+ exports.CreateWebhookForAccountResponseSchema = zod_1.z.object({
20
+ success: zod_1.z.boolean(),
21
+ });
22
+ exports.CreateWebhookRequestSchema = zod_1.z.object({
23
+ ids: zod_1.z.string(),
24
+ endpoints: zod_1.z.array(endpoint_1.HookEndpointSchema),
25
+ headers: zod_1.z.array(endpoint_1.HookEndpointHeaderSchema),
26
+ });
27
+ exports.CreateWebhookResponseSchema = exports.CreateWebhookForAccountResponseSchema;
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ export declare const HookEndpointHeaderSchema: z.ZodRecord<z.ZodString, z.ZodString>;
3
+ export type HookEndpointHeader = z.infer<typeof HookEndpointHeaderSchema>;
4
+ export declare const HookEndpointSchema: z.ZodObject<{
5
+ url: z.ZodString;
6
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ url: string;
9
+ headers: Record<string, string>;
10
+ }, {
11
+ url: string;
12
+ headers: Record<string, string>;
13
+ }>;
14
+ export type HookEndpoint = z.infer<typeof HookEndpointSchema>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HookEndpointSchema = exports.HookEndpointHeaderSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.HookEndpointHeaderSchema = zod_1.z.record(zod_1.z.string());
6
+ exports.HookEndpointSchema = zod_1.z.object({
7
+ url: zod_1.z.string().url(),
8
+ headers: exports.HookEndpointHeaderSchema,
9
+ });
@@ -0,0 +1,55 @@
1
+ import { z } from "zod";
2
+ export declare const WebhookEndpointSchema: z.ZodObject<{
3
+ url: z.ZodString;
4
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
5
+ id: z.ZodString;
6
+ account: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ url: string;
9
+ headers: Record<string, string>;
10
+ account: string;
11
+ id: string;
12
+ }, {
13
+ url: string;
14
+ headers: Record<string, string>;
15
+ account: string;
16
+ id: string;
17
+ }>;
18
+ export type WebhookEndpoint = z.infer<typeof WebhookEndpointSchema>;
19
+ export declare const isWebhookEndpoint: (obj: unknown) => obj is {
20
+ url: string;
21
+ headers: Record<string, string>;
22
+ account: string;
23
+ id: string;
24
+ };
25
+ export declare const WebhookEndpointItemSchema: z.ZodObject<{
26
+ url: z.ZodString;
27
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
28
+ account: z.ZodString;
29
+ PK: z.ZodString;
30
+ SK: z.ZodString;
31
+ id: z.ZodString;
32
+ }, "strip", z.ZodTypeAny, {
33
+ url: string;
34
+ headers: Record<string, string>;
35
+ account: string;
36
+ id: string;
37
+ PK: string;
38
+ SK: string;
39
+ }, {
40
+ url: string;
41
+ headers: Record<string, string>;
42
+ account: string;
43
+ id: string;
44
+ PK: string;
45
+ SK: string;
46
+ }>;
47
+ export type WebhookEndpointItem = z.infer<typeof WebhookEndpointItemSchema>;
48
+ export declare const isWebhookEndpointItem: (obj: unknown) => obj is {
49
+ url: string;
50
+ headers: Record<string, string>;
51
+ account: string;
52
+ id: string;
53
+ PK: string;
54
+ SK: string;
55
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWebhookEndpointItem = exports.WebhookEndpointItemSchema = exports.isWebhookEndpoint = exports.WebhookEndpointSchema = void 0;
4
+ const kit_aws_1 = require("@xube/kit-aws");
5
+ const zod_1 = require("zod");
6
+ const endpoint_1 = require("./endpoint");
7
+ exports.WebhookEndpointSchema = zod_1.z.object({
8
+ url: zod_1.z.string(),
9
+ headers: endpoint_1.HookEndpointHeaderSchema,
10
+ id: zod_1.z.string(),
11
+ account: zod_1.z.string(),
12
+ });
13
+ const isWebhookEndpoint = (obj) => exports.WebhookEndpointSchema.safeParse(obj).success;
14
+ exports.isWebhookEndpoint = isWebhookEndpoint;
15
+ exports.WebhookEndpointItemSchema = exports.WebhookEndpointSchema.merge(kit_aws_1.TableItemSchema);
16
+ const isWebhookEndpointItem = (obj) => exports.WebhookEndpointItemSchema.safeParse(obj).success;
17
+ exports.isWebhookEndpointItem = isWebhookEndpointItem;
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ export declare const WebhookTypes: {
3
+ readonly data: "data";
4
+ readonly event: "event";
5
+ };
6
+ export declare const WebhookTypesSchema: z.ZodNativeEnum<{
7
+ readonly data: "data";
8
+ readonly event: "event";
9
+ }>;
10
+ export type WebhookType = z.infer<typeof WebhookTypesSchema>;
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookTypesSchema = exports.WebhookTypes = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.WebhookTypes = {
6
+ data: "data",
7
+ event: "event",
8
+ };
9
+ exports.WebhookTypesSchema = zod_1.z.nativeEnum(exports.WebhookTypes);
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@xube/kit-aws-hooks",
3
+ "version": "0.0.22",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@github.com/XubeLtd/dev-kit.git"
12
+ },
13
+ "author": "Xube Pty Ltd",
14
+ "license": "MIT",
15
+ "bugs": {
16
+ "url": "https://github.com/XubeLtd/dev-kit/issues"
17
+ },
18
+ "homepage": "https://github.com/XubeLtd/dev-kit#readme",
19
+ "devDependencies": {
20
+ "@xube/kit-build": "^0.0.22"
21
+ },
22
+ "dependencies": {
23
+ "@xube/kit-aws": "^0.0.22",
24
+ "@xube/kit-log": "^0.0.22",
25
+ "@xube/kit-request": "^0.0.22",
26
+ "zod": "^3.22.4"
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ export const WEBHOOK_TABLE_NAME_ENV_VAR = "WEBHOOK_TABLE_NAME";
package/src/create.ts ADDED
@@ -0,0 +1,64 @@
1
+ import {
2
+ CreateWebhookForAccountRequest,
3
+ CreateWebhookForAccountResponse,
4
+ isCreateWebhookForAccountRequest,
5
+ } from "./schemas/create";
6
+ import { XubeResponse } from "@xube/kit-request";
7
+ import { StatusCode } from "@xube/kit-constants";
8
+ import { generateWebhookItems } from "./generate";
9
+ import { putItemInTable } from "@xube/kit-aws";
10
+ import { XubeLog } from "@xube/kit-log";
11
+ import { WebhookEndpointItem } from "./schemas/webhook";
12
+
13
+ export const createWebhookForAccount = async (
14
+ request: CreateWebhookForAccountRequest,
15
+ tableName: string,
16
+ log: XubeLog = XubeLog.getInstance()
17
+ ): Promise<XubeResponse<CreateWebhookForAccountResponse>> => {
18
+ if (!isCreateWebhookForAccountRequest(request)) {
19
+ return new XubeResponse({
20
+ statusCode: StatusCode.BadRequest,
21
+ error: `Webhook creation request did not have the expected structure.`,
22
+ });
23
+ }
24
+
25
+ const newWebhooks: WebhookEndpointItem[] = generateWebhookItems(request);
26
+
27
+ const putWebhookItems: Promise<XubeResponse<boolean>>[] = [];
28
+ for (const webhook of newWebhooks) {
29
+ putWebhookItems.push(putItemInTable(tableName, webhook));
30
+ }
31
+ const putItemResponses = await Promise.all(putWebhookItems);
32
+
33
+ const failedWebhooks: WebhookEndpointItem[] = [];
34
+
35
+ const failedResponses = putItemResponses.filter((response, idx) => {
36
+ failedWebhooks.push(newWebhooks[idx]);
37
+ return response.hasFailed();
38
+ });
39
+
40
+ if (failedResponses.length) {
41
+ log.error(
42
+ `Failed to save ${failedResponses} out or ${newWebhooks.length} to ddb.`
43
+ );
44
+ log.info(`Failed webhooks: ${JSON.stringify(failedWebhooks, null, 2)}`);
45
+ return new XubeResponse({
46
+ statusCode:
47
+ failedResponses.length === newWebhooks.length
48
+ ? StatusCode.InternalError
49
+ : StatusCode.PartialSuccess,
50
+ error: `Failed to save the following webhooks to ddb:\n${JSON.stringify(
51
+ failedWebhooks,
52
+ null,
53
+ 2
54
+ )}`,
55
+ });
56
+ }
57
+
58
+ return new XubeResponse({
59
+ statusCode: StatusCode.OK,
60
+ data: {
61
+ success: true,
62
+ },
63
+ });
64
+ };
package/src/delete.ts ADDED
File without changes
@@ -0,0 +1,24 @@
1
+ import { getWebhookPartitionKey, getWebhookSortKey } from "./keys";
2
+ import { CreateWebhookForAccountRequest } from "./schemas/create";
3
+ import { WebhookEndpoint, WebhookEndpointItem } from "./schemas/webhook";
4
+ import { WebhookTypes } from "./types";
5
+
6
+ export const generateWebhookItems = (
7
+ request: CreateWebhookForAccountRequest
8
+ ): WebhookEndpointItem[] => {
9
+ const webhookItems: WebhookEndpointItem[] = [];
10
+
11
+ for (const endpoint of request.endpoints) {
12
+ for (const id of request.ids) {
13
+ webhookItems.push({
14
+ account: request.account,
15
+ ...endpoint,
16
+ id,
17
+ PK: getWebhookPartitionKey(request.account),
18
+ SK: getWebhookSortKey(id, request.type ?? WebhookTypes.data),
19
+ });
20
+ }
21
+ }
22
+
23
+ return webhookItems;
24
+ };
package/src/get.ts ADDED
@@ -0,0 +1,3 @@
1
+ export const getWebhooks = () => {
2
+
3
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./schemas/create"
2
+ export * from "./schemas/endpoint"
3
+ export * from "./schemas/webhook"
4
+ export * from "./constants";
5
+ export * from "./create";
6
+ // export * from "./delete";
7
+ export * from "./generate";
8
+ export * from "./get";
9
+ export * from "./keys";
10
+ export * from "./types";
package/src/keys.ts ADDED
@@ -0,0 +1,7 @@
1
+ export const getWebhookPartitionKey = (account: string) => {
2
+ return `ACCOUNT#${account}`;
3
+ }
4
+
5
+ export const getWebhookSortKey = (id: string, type: string) => {
6
+ return `HOOK#${id}#${type}`;
7
+ }
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ import { HookEndpointHeaderSchema, HookEndpointSchema } from "./endpoint";
3
+ import { WebhookTypesSchema } from "../types";
4
+
5
+ export const CreateWebhookForAccountRequestSchema = z.object({
6
+ account: z.string(),
7
+ ids: z.array(z.string()),
8
+ endpoints: z.array(HookEndpointSchema),
9
+ headers: HookEndpointHeaderSchema,
10
+ type: WebhookTypesSchema.optional(),
11
+ });
12
+ export type CreateWebhookForAccountRequest = z.infer<
13
+ typeof CreateWebhookForAccountRequestSchema
14
+ >;
15
+ export const isCreateWebhookForAccountRequest = (
16
+ obj: unknown
17
+ ): obj is CreateWebhookForAccountRequest => {
18
+ CreateWebhookForAccountRequestSchema.parse(obj);
19
+ return true;
20
+ };
21
+
22
+ export const CreateWebhookForAccountResponseSchema = z.object({
23
+ success: z.boolean(),
24
+ });
25
+ export type CreateWebhookForAccountResponse = z.infer<
26
+ typeof CreateWebhookForAccountResponseSchema
27
+ >;
28
+
29
+ export const CreateWebhookRequestSchema = z.object({
30
+ ids: z.string(),
31
+ endpoints: z.array(HookEndpointSchema),
32
+ headers: z.array(HookEndpointHeaderSchema),
33
+ });
34
+
35
+ export const CreateWebhookResponseSchema =
36
+ CreateWebhookForAccountResponseSchema;
37
+ export type CreateWebhookResponse = z.infer<typeof CreateWebhookResponseSchema>;
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+
3
+ export const HookEndpointHeaderSchema = z.record(z.string());
4
+ export type HookEndpointHeader = z.infer<typeof HookEndpointHeaderSchema>;
5
+
6
+ export const HookEndpointSchema = z.object({
7
+ url: z.string().url(),
8
+ headers: HookEndpointHeaderSchema,
9
+ });
10
+ export type HookEndpoint = z.infer<typeof HookEndpointSchema>;
@@ -0,0 +1,21 @@
1
+ import { TableItemSchema } from "@xube/kit-aws";
2
+ import { z } from "zod";
3
+ import { HookEndpointHeaderSchema } from "./endpoint";
4
+
5
+ export const WebhookEndpointSchema = z.object({
6
+ url: z.string(),
7
+ headers: HookEndpointHeaderSchema,
8
+ id: z.string(),
9
+ account: z.string(),
10
+ });
11
+ export type WebhookEndpoint = z.infer<typeof WebhookEndpointSchema>;
12
+ export const isWebhookEndpoint = (obj: unknown): obj is WebhookEndpoint =>
13
+ WebhookEndpointSchema.safeParse(obj).success;
14
+
15
+ export const WebhookEndpointItemSchema =
16
+ WebhookEndpointSchema.merge(TableItemSchema);
17
+ export type WebhookEndpointItem = z.infer<typeof WebhookEndpointItemSchema>;
18
+ export const isWebhookEndpointItem = (
19
+ obj: unknown
20
+ ): obj is WebhookEndpointItem =>
21
+ WebhookEndpointItemSchema.safeParse(obj).success;
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+
3
+ export const WebhookTypes = {
4
+ data: "data",
5
+ event: "event",
6
+ } as const;
7
+
8
+
9
+ export const WebhookTypesSchema = z.nativeEnum(WebhookTypes);
10
+ export type WebhookType = z.infer<typeof WebhookTypesSchema>;
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../kit-build/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist"
6
+ },
7
+ "exclude": ["**/*.test.ts", "**/*.mock.ts", "dist"],
8
+ "references": [
9
+ {
10
+ "path": "../kit-constants"
11
+ },
12
+ {
13
+ "path": "../kit-log"
14
+ },
15
+ {
16
+ "path": "../kit-request"
17
+ },
18
+ {
19
+ "path": "../kit-aws"
20
+ }
21
+ ]
22
+ }