@hexabot-ai/types 3.0.0-alpha.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/LICENSE.md +120 -0
- package/README.md +172 -0
- package/dist/cjs/analytics/index.js +18 -0
- package/dist/cjs/analytics/integration-health.js +30 -0
- package/dist/cjs/analytics/stats.js +32 -0
- package/dist/cjs/attachment/attachment.js +53 -0
- package/dist/cjs/attachment/index.js +16 -0
- package/dist/cjs/audit/audit-log.js +33 -0
- package/dist/cjs/audit/index.js +11 -0
- package/dist/cjs/channel/channel-metadata.js +15 -0
- package/dist/cjs/channel/index.js +15 -0
- package/dist/cjs/channel/source-full.js +16 -0
- package/dist/cjs/channel/source.js +25 -0
- package/dist/cjs/chat/attachment.js +32 -0
- package/dist/cjs/chat/button.js +70 -0
- package/dist/cjs/chat/index.js +87 -0
- package/dist/cjs/chat/label-group.js +22 -0
- package/dist/cjs/chat/label.js +37 -0
- package/dist/cjs/chat/message-contract.js +183 -0
- package/dist/cjs/chat/message.js +107 -0
- package/dist/cjs/chat/options.js +122 -0
- package/dist/cjs/chat/quick-reply.js +35 -0
- package/dist/cjs/chat/subscriber.js +36 -0
- package/dist/cjs/chat/thread.js +36 -0
- package/dist/cjs/cms/content-type.js +17 -0
- package/dist/cjs/cms/content.js +29 -0
- package/dist/cjs/cms/index.js +21 -0
- package/dist/cjs/cms/menu.js +36 -0
- package/dist/cjs/dummy/dummy.js +18 -0
- package/dist/cjs/dummy/index.js +12 -0
- package/dist/cjs/i18n/index.js +16 -0
- package/dist/cjs/i18n/language.js +19 -0
- package/dist/cjs/i18n/translation.js +17 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/setting/index.js +18 -0
- package/dist/cjs/setting/metadata.js +17 -0
- package/dist/cjs/setting/setting.js +36 -0
- package/dist/cjs/shared/aliases.js +41 -0
- package/dist/cjs/shared/base.js +14 -0
- package/dist/cjs/shared/object.js +19 -0
- package/dist/cjs/shared/preprocess.js +13 -0
- package/dist/cjs/shared/profile.js +33 -0
- package/dist/cjs/user/credential.js +26 -0
- package/dist/cjs/user/domain.js +56 -0
- package/dist/cjs/user/index.js +39 -0
- package/dist/cjs/user/model.js +24 -0
- package/dist/cjs/user/permission.js +32 -0
- package/dist/cjs/user/role.js +24 -0
- package/dist/cjs/user/user-profile-assigned.js +38 -0
- package/dist/cjs/user/user-profile.js +12 -0
- package/dist/cjs/user/user.js +44 -0
- package/dist/cjs/workflow/domain.js +44 -0
- package/dist/cjs/workflow/helpers.js +35 -0
- package/dist/cjs/workflow/index.js +40 -0
- package/dist/cjs/workflow/mcp-server.js +33 -0
- package/dist/cjs/workflow/memory-definition.js +21 -0
- package/dist/cjs/workflow/memory-record.js +44 -0
- package/dist/cjs/workflow/workflow-run.js +100 -0
- package/dist/cjs/workflow/workflow-version.js +39 -0
- package/dist/cjs/workflow/workflow.js +98 -0
- package/dist/esm/analytics/index.js +7 -0
- package/dist/esm/analytics/integration-health.js +27 -0
- package/dist/esm/analytics/stats.js +29 -0
- package/dist/esm/attachment/attachment.js +50 -0
- package/dist/esm/attachment/index.js +6 -0
- package/dist/esm/audit/audit-log.js +30 -0
- package/dist/esm/audit/index.js +6 -0
- package/dist/esm/channel/channel-metadata.js +12 -0
- package/dist/esm/channel/index.js +8 -0
- package/dist/esm/channel/source-full.js +13 -0
- package/dist/esm/channel/source.js +22 -0
- package/dist/esm/chat/attachment.js +29 -0
- package/dist/esm/chat/button.js +67 -0
- package/dist/esm/chat/index.js +15 -0
- package/dist/esm/chat/label-group.js +19 -0
- package/dist/esm/chat/label.js +34 -0
- package/dist/esm/chat/message-contract.js +180 -0
- package/dist/esm/chat/message.js +104 -0
- package/dist/esm/chat/options.js +119 -0
- package/dist/esm/chat/quick-reply.js +32 -0
- package/dist/esm/chat/subscriber.js +33 -0
- package/dist/esm/chat/thread.js +33 -0
- package/dist/esm/cms/content-type.js +14 -0
- package/dist/esm/cms/content.js +26 -0
- package/dist/esm/cms/index.js +8 -0
- package/dist/esm/cms/menu.js +33 -0
- package/dist/esm/dummy/dummy.js +15 -0
- package/dist/esm/dummy/index.js +6 -0
- package/dist/esm/i18n/index.js +7 -0
- package/dist/esm/i18n/language.js +16 -0
- package/dist/esm/i18n/translation.js +14 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/setting/index.js +7 -0
- package/dist/esm/setting/metadata.js +14 -0
- package/dist/esm/setting/setting.js +33 -0
- package/dist/esm/shared/aliases.js +35 -0
- package/dist/esm/shared/base.js +11 -0
- package/dist/esm/shared/object.js +14 -0
- package/dist/esm/shared/preprocess.js +9 -0
- package/dist/esm/shared/profile.js +30 -0
- package/dist/esm/user/credential.js +23 -0
- package/dist/esm/user/domain.js +53 -0
- package/dist/esm/user/index.js +13 -0
- package/dist/esm/user/model.js +21 -0
- package/dist/esm/user/permission.js +29 -0
- package/dist/esm/user/role.js +21 -0
- package/dist/esm/user/user-profile-assigned.js +35 -0
- package/dist/esm/user/user-profile.js +9 -0
- package/dist/esm/user/user.js +41 -0
- package/dist/esm/workflow/domain.js +41 -0
- package/dist/esm/workflow/helpers.js +30 -0
- package/dist/esm/workflow/index.js +12 -0
- package/dist/esm/workflow/mcp-server.js +30 -0
- package/dist/esm/workflow/memory-definition.js +18 -0
- package/dist/esm/workflow/memory-record.js +41 -0
- package/dist/esm/workflow/workflow-run.js +96 -0
- package/dist/esm/workflow/workflow-version.js +36 -0
- package/dist/esm/workflow/workflow.js +94 -0
- package/dist/types/analytics/index.d.ts +3 -0
- package/dist/types/analytics/index.d.ts.map +1 -0
- package/dist/types/analytics/integration-health.d.ts +55 -0
- package/dist/types/analytics/integration-health.d.ts.map +1 -0
- package/dist/types/analytics/stats.d.ts +43 -0
- package/dist/types/analytics/stats.d.ts.map +1 -0
- package/dist/types/attachment/attachment.d.ts +212 -0
- package/dist/types/attachment/attachment.d.ts.map +1 -0
- package/dist/types/attachment/index.d.ts +2 -0
- package/dist/types/attachment/index.d.ts.map +1 -0
- package/dist/types/audit/audit-log.d.ts +58 -0
- package/dist/types/audit/audit-log.d.ts.map +1 -0
- package/dist/types/audit/index.d.ts +2 -0
- package/dist/types/audit/index.d.ts.map +1 -0
- package/dist/types/channel/channel-metadata.d.ts +7 -0
- package/dist/types/channel/channel-metadata.d.ts.map +1 -0
- package/dist/types/channel/index.d.ts +4 -0
- package/dist/types/channel/index.d.ts.map +1 -0
- package/dist/types/channel/source-full.d.ts +58 -0
- package/dist/types/channel/source-full.d.ts.map +1 -0
- package/dist/types/channel/source.d.ts +44 -0
- package/dist/types/channel/source.d.ts.map +1 -0
- package/dist/types/chat/attachment.d.ts +34 -0
- package/dist/types/chat/attachment.d.ts.map +1 -0
- package/dist/types/chat/button.d.ts +31 -0
- package/dist/types/chat/button.d.ts.map +1 -0
- package/dist/types/chat/index.d.ts +11 -0
- package/dist/types/chat/index.d.ts.map +1 -0
- package/dist/types/chat/label-group.d.ts +47 -0
- package/dist/types/chat/label-group.d.ts.map +1 -0
- package/dist/types/chat/label.d.ts +102 -0
- package/dist/types/chat/label.d.ts.map +1 -0
- package/dist/types/chat/message-contract.d.ts +883 -0
- package/dist/types/chat/message-contract.d.ts.map +1 -0
- package/dist/types/chat/message.d.ts +1132 -0
- package/dist/types/chat/message.d.ts.map +1 -0
- package/dist/types/chat/options.d.ts +64 -0
- package/dist/types/chat/options.d.ts.map +1 -0
- package/dist/types/chat/quick-reply.d.ts +32 -0
- package/dist/types/chat/quick-reply.d.ts.map +1 -0
- package/dist/types/chat/subscriber.d.ts +236 -0
- package/dist/types/chat/subscriber.d.ts.map +1 -0
- package/dist/types/chat/thread.d.ts +126 -0
- package/dist/types/chat/thread.d.ts.map +1 -0
- package/dist/types/cms/content-type.d.ts +26 -0
- package/dist/types/cms/content-type.d.ts.map +1 -0
- package/dist/types/cms/content.d.ts +49 -0
- package/dist/types/cms/content.d.ts.map +1 -0
- package/dist/types/cms/index.d.ts +4 -0
- package/dist/types/cms/index.d.ts.map +1 -0
- package/dist/types/cms/menu.d.ts +85 -0
- package/dist/types/cms/menu.d.ts.map +1 -0
- package/dist/types/dummy/dummy.d.ts +26 -0
- package/dist/types/dummy/dummy.d.ts.map +1 -0
- package/dist/types/dummy/index.d.ts +2 -0
- package/dist/types/dummy/index.d.ts.map +1 -0
- package/dist/types/i18n/index.d.ts +3 -0
- package/dist/types/i18n/index.d.ts.map +1 -0
- package/dist/types/i18n/language.d.ts +32 -0
- package/dist/types/i18n/language.d.ts.map +1 -0
- package/dist/types/i18n/translation.d.ts +26 -0
- package/dist/types/i18n/translation.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/setting/index.d.ts +3 -0
- package/dist/types/setting/index.d.ts.map +1 -0
- package/dist/types/setting/metadata.d.ts +26 -0
- package/dist/types/setting/metadata.d.ts.map +1 -0
- package/dist/types/setting/setting.d.ts +41 -0
- package/dist/types/setting/setting.d.ts.map +1 -0
- package/dist/types/shared/aliases.d.ts +4 -0
- package/dist/types/shared/aliases.d.ts.map +1 -0
- package/dist/types/shared/base.d.ts +7 -0
- package/dist/types/shared/base.d.ts.map +1 -0
- package/dist/types/shared/object.d.ts +3 -0
- package/dist/types/shared/object.d.ts.map +1 -0
- package/dist/types/shared/preprocess.d.ts +3 -0
- package/dist/types/shared/preprocess.d.ts.map +1 -0
- package/dist/types/shared/profile.d.ts +40 -0
- package/dist/types/shared/profile.d.ts.map +1 -0
- package/dist/types/user/credential.d.ts +97 -0
- package/dist/types/user/credential.d.ts.map +1 -0
- package/dist/types/user/domain.d.ts +54 -0
- package/dist/types/user/domain.d.ts.map +1 -0
- package/dist/types/user/index.d.ts +9 -0
- package/dist/types/user/index.d.ts.map +1 -0
- package/dist/types/user/model.d.ts +142 -0
- package/dist/types/user/model.d.ts.map +1 -0
- package/dist/types/user/permission.d.ts +90 -0
- package/dist/types/user/permission.d.ts.map +1 -0
- package/dist/types/user/role.d.ts +111 -0
- package/dist/types/user/role.d.ts.map +1 -0
- package/dist/types/user/user-profile-assigned.d.ts +181 -0
- package/dist/types/user/user-profile-assigned.d.ts.map +1 -0
- package/dist/types/user/user-profile.d.ts +32 -0
- package/dist/types/user/user-profile.d.ts.map +1 -0
- package/dist/types/user/user.d.ts +270 -0
- package/dist/types/user/user.d.ts.map +1 -0
- package/dist/types/workflow/domain.d.ts +32 -0
- package/dist/types/workflow/domain.d.ts.map +1 -0
- package/dist/types/workflow/helpers.d.ts +117 -0
- package/dist/types/workflow/helpers.d.ts.map +1 -0
- package/dist/types/workflow/index.d.ts +8 -0
- package/dist/types/workflow/index.d.ts.map +1 -0
- package/dist/types/workflow/mcp-server.d.ts +67 -0
- package/dist/types/workflow/mcp-server.d.ts.map +1 -0
- package/dist/types/workflow/memory-definition.d.ts +35 -0
- package/dist/types/workflow/memory-definition.d.ts.map +1 -0
- package/dist/types/workflow/memory-record.d.ts +284 -0
- package/dist/types/workflow/memory-record.d.ts.map +1 -0
- package/dist/types/workflow/workflow-run.d.ts +375 -0
- package/dist/types/workflow/workflow-run.d.ts.map +1 -0
- package/dist/types/workflow/workflow-version.d.ts +179 -0
- package/dist/types/workflow/workflow-version.d.ts.map +1 -0
- package/dist/types/workflow/workflow.d.ts +366 -0
- package/dist/types/workflow/workflow.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/analytics/index.ts +26 -0
- package/src/analytics/integration-health.ts +44 -0
- package/src/analytics/stats.ts +41 -0
- package/src/attachment/attachment.ts +75 -0
- package/src/attachment/index.ts +19 -0
- package/src/audit/audit-log.ts +42 -0
- package/src/audit/index.ts +12 -0
- package/src/channel/channel-metadata.ts +20 -0
- package/src/channel/index.ts +19 -0
- package/src/channel/source-full.ts +25 -0
- package/src/channel/source.ts +42 -0
- package/src/chat/attachment.ts +44 -0
- package/src/chat/button.ts +90 -0
- package/src/chat/index.ts +173 -0
- package/src/chat/label-group.ts +35 -0
- package/src/chat/label.ts +56 -0
- package/src/chat/message-contract.ts +370 -0
- package/src/chat/message.ts +164 -0
- package/src/chat/options.ts +130 -0
- package/src/chat/quick-reply.ts +41 -0
- package/src/chat/subscriber.ts +73 -0
- package/src/chat/thread.ts +55 -0
- package/src/cms/content-type.ts +26 -0
- package/src/cms/content.ts +48 -0
- package/src/cms/index.ts +33 -0
- package/src/cms/menu.ts +54 -0
- package/src/dummy/dummy.ts +30 -0
- package/src/dummy/index.ts +14 -0
- package/src/i18n/index.ts +23 -0
- package/src/i18n/language.ts +28 -0
- package/src/i18n/translation.ts +26 -0
- package/src/index.test.ts +1271 -0
- package/src/index.ts +27 -0
- package/src/setting/index.ts +25 -0
- package/src/setting/metadata.ts +26 -0
- package/src/setting/setting.ts +46 -0
- package/src/shared/aliases.ts +48 -0
- package/src/shared/base.ts +13 -0
- package/src/shared/object.ts +19 -0
- package/src/shared/preprocess.ts +14 -0
- package/src/shared/profile.ts +49 -0
- package/src/user/credential.ts +45 -0
- package/src/user/domain.ts +94 -0
- package/src/user/index.ts +78 -0
- package/src/user/model.ts +40 -0
- package/src/user/permission.ts +51 -0
- package/src/user/role.ts +43 -0
- package/src/user/user-profile-assigned.ts +70 -0
- package/src/user/user-profile.ts +21 -0
- package/src/user/user.ts +87 -0
- package/src/workflow/domain.ts +47 -0
- package/src/workflow/helpers.ts +40 -0
- package/src/workflow/index.ts +70 -0
- package/src/workflow/mcp-server.ts +64 -0
- package/src/workflow/memory-definition.ts +31 -0
- package/src/workflow/memory-record.ts +71 -0
- package/src/workflow/workflow-run.ts +156 -0
- package/src/workflow/workflow-version.ts +68 -0
- package/src/workflow/workflow.ts +163 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
export const integrationHealthStatusSchema = z.enum([
|
|
8
|
+
"healthy",
|
|
9
|
+
"warning",
|
|
10
|
+
"unhealthy",
|
|
11
|
+
"disabled",
|
|
12
|
+
]);
|
|
13
|
+
export const integrationHealthKindSchema = z.enum(["channel", "service"]);
|
|
14
|
+
export const integrationHealthItemSchema = z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
kind: integrationHealthKindSchema,
|
|
17
|
+
name: z.string(),
|
|
18
|
+
status: integrationHealthStatusSchema,
|
|
19
|
+
checkedAt: z.string().datetime({ offset: true }),
|
|
20
|
+
reason: z.string().optional(),
|
|
21
|
+
message: z.string().optional(),
|
|
22
|
+
details: z.record(z.string(), z.unknown()).optional(),
|
|
23
|
+
});
|
|
24
|
+
export const integrationHealthResponseSchema = z.object({
|
|
25
|
+
checkedAt: z.string().datetime({ offset: true }),
|
|
26
|
+
integrations: z.array(integrationHealthItemSchema),
|
|
27
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { baseStubSchema } from "../shared/base";
|
|
8
|
+
export var StatsType;
|
|
9
|
+
(function (StatsType) {
|
|
10
|
+
StatsType["outgoing"] = "outgoing";
|
|
11
|
+
StatsType["new_users"] = "new_users";
|
|
12
|
+
StatsType["all_messages"] = "all_messages";
|
|
13
|
+
StatsType["incoming"] = "incoming";
|
|
14
|
+
StatsType["returning_users"] = "returning_users";
|
|
15
|
+
StatsType["retention"] = "retention";
|
|
16
|
+
StatsType["echo"] = "echo";
|
|
17
|
+
StatsType["new_threads"] = "new_threads";
|
|
18
|
+
StatsType["handoffs"] = "handoffs";
|
|
19
|
+
})(StatsType || (StatsType = {}));
|
|
20
|
+
const statsTypeSchema = z.enum(StatsType);
|
|
21
|
+
const statsObjectSchema = baseStubSchema.extend({
|
|
22
|
+
type: statsTypeSchema,
|
|
23
|
+
day: z.coerce.date(),
|
|
24
|
+
value: z.coerce.number(),
|
|
25
|
+
name: z.string(),
|
|
26
|
+
});
|
|
27
|
+
export const statsStubSchema = statsObjectSchema;
|
|
28
|
+
export const statsSchema = statsObjectSchema;
|
|
29
|
+
export const statsFullSchema = statsObjectSchema;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { asId, withAliases } from "../shared/aliases";
|
|
8
|
+
import { baseStubSchema } from "../shared/base";
|
|
9
|
+
import { preprocess } from "../shared/preprocess";
|
|
10
|
+
import { userProfileAssignedSchema } from "../user/user-profile-assigned";
|
|
11
|
+
export var AttachmentCreatedByRef;
|
|
12
|
+
(function (AttachmentCreatedByRef) {
|
|
13
|
+
AttachmentCreatedByRef["User"] = "User";
|
|
14
|
+
AttachmentCreatedByRef["Subscriber"] = "Subscriber";
|
|
15
|
+
})(AttachmentCreatedByRef || (AttachmentCreatedByRef = {}));
|
|
16
|
+
export var AttachmentResourceRef;
|
|
17
|
+
(function (AttachmentResourceRef) {
|
|
18
|
+
AttachmentResourceRef["SettingAttachment"] = "Setting";
|
|
19
|
+
AttachmentResourceRef["UserAvatar"] = "User";
|
|
20
|
+
AttachmentResourceRef["SubscriberAvatar"] = "Subscriber";
|
|
21
|
+
AttachmentResourceRef["ContentAttachment"] = "Content";
|
|
22
|
+
AttachmentResourceRef["MessageAttachment"] = "Message";
|
|
23
|
+
})(AttachmentResourceRef || (AttachmentResourceRef = {}));
|
|
24
|
+
export var AttachmentAccess;
|
|
25
|
+
(function (AttachmentAccess) {
|
|
26
|
+
AttachmentAccess["Public"] = "public";
|
|
27
|
+
AttachmentAccess["Private"] = "private";
|
|
28
|
+
})(AttachmentAccess || (AttachmentAccess = {}));
|
|
29
|
+
const attachmentAliasMap = {
|
|
30
|
+
createdById: "createdBy",
|
|
31
|
+
};
|
|
32
|
+
export const attachmentOwnerSchema = userProfileAssignedSchema;
|
|
33
|
+
const attachmentStubObjectSchema = baseStubSchema.extend({
|
|
34
|
+
name: z.string(),
|
|
35
|
+
type: z.string(),
|
|
36
|
+
size: z.coerce.number(),
|
|
37
|
+
location: z.string(),
|
|
38
|
+
channel: preprocess((value) => (value == null ? undefined : value), z.record(z.string(), z.unknown()).optional()).optional(),
|
|
39
|
+
createdByRef: z.enum(AttachmentCreatedByRef).optional(),
|
|
40
|
+
resourceRef: z.enum(AttachmentResourceRef),
|
|
41
|
+
access: z.enum(AttachmentAccess),
|
|
42
|
+
url: preprocess((value) => (value == null ? "" : value), z.string()),
|
|
43
|
+
});
|
|
44
|
+
export const attachmentStubSchema = attachmentStubObjectSchema;
|
|
45
|
+
export const attachmentSchema = preprocess((value) => withAliases(value, attachmentAliasMap), attachmentStubObjectSchema.extend({
|
|
46
|
+
createdBy: preprocess((value) => (value == null ? null : asId(value)), z.string().nullable()).optional(),
|
|
47
|
+
}));
|
|
48
|
+
export const attachmentFullSchema = attachmentStubObjectSchema.extend({
|
|
49
|
+
createdBy: attachmentOwnerSchema.nullable().optional(),
|
|
50
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
export { AttachmentAccess, AttachmentCreatedByRef, AttachmentResourceRef, attachmentFullSchema, attachmentOwnerSchema, attachmentSchema, attachmentStubSchema, } from "./attachment";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { baseStubSchema } from "../shared/base";
|
|
8
|
+
import { preprocess } from "../shared/preprocess";
|
|
9
|
+
const nullableRecordSchema = preprocess((value) => (value == null ? null : value), z.unknown().nullable());
|
|
10
|
+
export const auditLogSchema = baseStubSchema.extend({
|
|
11
|
+
resourceId: z.string(),
|
|
12
|
+
resourceType: z.string(),
|
|
13
|
+
resourceLabel: z.string().nullable(),
|
|
14
|
+
operationId: z.string(),
|
|
15
|
+
operationType: z.string(),
|
|
16
|
+
operationStatus: z.enum(["UNSPECIFIED", "SUCCEEDED", "FAILED"]),
|
|
17
|
+
actorId: z.string(),
|
|
18
|
+
actorType: z.string(),
|
|
19
|
+
actorLabel: z.string().nullable(),
|
|
20
|
+
actorIp: z.string().nullable(),
|
|
21
|
+
actorAgent: z.string().nullable(),
|
|
22
|
+
requestId: z.string().nullable(),
|
|
23
|
+
requestMethod: z.string().nullable(),
|
|
24
|
+
requestPath: z.string().nullable(),
|
|
25
|
+
dataBefore: nullableRecordSchema,
|
|
26
|
+
dataAfter: nullableRecordSchema,
|
|
27
|
+
dataDiff: nullableRecordSchema,
|
|
28
|
+
raw: nullableRecordSchema,
|
|
29
|
+
});
|
|
30
|
+
export const auditLogFullSchema = auditLogSchema;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
const jsonObjectSchema = z.record(z.string(), z.unknown());
|
|
8
|
+
const channelMetadataObjectSchema = z.object({
|
|
9
|
+
name: z.string(),
|
|
10
|
+
settingsSchema: jsonObjectSchema,
|
|
11
|
+
});
|
|
12
|
+
export const channelMetadataSchema = channelMetadataObjectSchema;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
export { sourceSchema, sourceStubSchema, } from "./source";
|
|
7
|
+
export { sourceFullSchema } from "./source-full";
|
|
8
|
+
export { channelMetadataSchema, } from "./channel-metadata";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { withAliases } from "../shared/aliases";
|
|
8
|
+
import { preprocess } from "../shared/preprocess";
|
|
9
|
+
import { workflowSchema } from "../workflow/workflow";
|
|
10
|
+
import { sourceAliasMap, sourceObjectSchema } from "./source";
|
|
11
|
+
export const sourceFullSchema = preprocess((value) => withAliases(value, sourceAliasMap), sourceObjectSchema.extend({
|
|
12
|
+
defaultWorkflow: preprocess((value) => (value == null ? null : value), z.lazy(() => workflowSchema).nullable()),
|
|
13
|
+
}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { asId, withAliases } from "../shared/aliases";
|
|
8
|
+
import { baseStubSchema } from "../shared/base";
|
|
9
|
+
import { preprocess } from "../shared/preprocess";
|
|
10
|
+
export const sourceAliasMap = {
|
|
11
|
+
defaultWorkflowId: "defaultWorkflow",
|
|
12
|
+
};
|
|
13
|
+
export const sourceObjectSchema = baseStubSchema.extend({
|
|
14
|
+
name: z.string(),
|
|
15
|
+
channel: z.string(),
|
|
16
|
+
settings: preprocess((value) => value && typeof value === "object" && !Array.isArray(value) ? value : {}, z.record(z.string(), z.unknown())),
|
|
17
|
+
state: z.coerce.boolean(),
|
|
18
|
+
});
|
|
19
|
+
export const sourceStubSchema = sourceObjectSchema;
|
|
20
|
+
export const sourceSchema = preprocess((value) => withAliases(value, sourceAliasMap), sourceObjectSchema.extend({
|
|
21
|
+
defaultWorkflow: preprocess((value) => (value == null ? null : asId(value)), z.string().nullable()),
|
|
22
|
+
}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
export var FileType;
|
|
8
|
+
(function (FileType) {
|
|
9
|
+
FileType["image"] = "image";
|
|
10
|
+
FileType["video"] = "video";
|
|
11
|
+
FileType["audio"] = "audio";
|
|
12
|
+
FileType["file"] = "file";
|
|
13
|
+
FileType["unknown"] = "unknown";
|
|
14
|
+
})(FileType || (FileType = {}));
|
|
15
|
+
export const fileTypeSchema = z.enum(FileType);
|
|
16
|
+
export const attachmentRefSchema = z.union([
|
|
17
|
+
z.object({
|
|
18
|
+
id: z.string().nullable(),
|
|
19
|
+
url: z.string().optional(),
|
|
20
|
+
}),
|
|
21
|
+
z.object({
|
|
22
|
+
id: z.string().nullable().optional(),
|
|
23
|
+
url: z.string(),
|
|
24
|
+
}),
|
|
25
|
+
]);
|
|
26
|
+
export const attachmentPayloadSchema = z.object({
|
|
27
|
+
type: fileTypeSchema,
|
|
28
|
+
payload: attachmentRefSchema,
|
|
29
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
export var ButtonType;
|
|
8
|
+
(function (ButtonType) {
|
|
9
|
+
ButtonType["postback"] = "postback";
|
|
10
|
+
ButtonType["web_url"] = "web_url";
|
|
11
|
+
})(ButtonType || (ButtonType = {}));
|
|
12
|
+
export const buttonSchema = z
|
|
13
|
+
.object({
|
|
14
|
+
type: z.enum([ButtonType.postback, ButtonType.web_url]).meta({
|
|
15
|
+
title: "Type",
|
|
16
|
+
description: "The type of button.",
|
|
17
|
+
}),
|
|
18
|
+
title: z.string().meta({
|
|
19
|
+
title: "Title",
|
|
20
|
+
description: "The label shown to the user.",
|
|
21
|
+
}),
|
|
22
|
+
payload: z.string().optional().meta({
|
|
23
|
+
title: "Payload",
|
|
24
|
+
description: "The value sent back when the button is clicked.",
|
|
25
|
+
}),
|
|
26
|
+
url: z
|
|
27
|
+
.union([z.url(), z.literal("")])
|
|
28
|
+
.optional()
|
|
29
|
+
.meta({
|
|
30
|
+
title: "URL",
|
|
31
|
+
description: "The destination URL opened when the button is clicked.",
|
|
32
|
+
}),
|
|
33
|
+
messenger_extensions: z.boolean().optional().meta({
|
|
34
|
+
title: "Messenger extensions",
|
|
35
|
+
description: "Whether to enable Messenger Extensions for the webview.",
|
|
36
|
+
}),
|
|
37
|
+
webview_height_ratio: z.enum(["compact", "tall", "full"]).optional().meta({
|
|
38
|
+
title: "Webview height ratio",
|
|
39
|
+
description: "The height of the webview.",
|
|
40
|
+
}),
|
|
41
|
+
})
|
|
42
|
+
.superRefine((button, ctx) => {
|
|
43
|
+
if (button.type === ButtonType.postback && !button.payload) {
|
|
44
|
+
ctx.addIssue({
|
|
45
|
+
code: z.ZodIssueCode.custom,
|
|
46
|
+
path: ["payload"],
|
|
47
|
+
message: "Payload is required for postback buttons.",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (button.type === ButtonType.web_url && !button.url) {
|
|
51
|
+
ctx.addIssue({
|
|
52
|
+
code: z.ZodIssueCode.custom,
|
|
53
|
+
path: ["url"],
|
|
54
|
+
message: "URL is required for web_url buttons.",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
export var PayloadType;
|
|
59
|
+
(function (PayloadType) {
|
|
60
|
+
PayloadType["location"] = "location";
|
|
61
|
+
PayloadType["attachment"] = "attachment";
|
|
62
|
+
PayloadType["quickReply"] = "quickReply";
|
|
63
|
+
PayloadType["button"] = "button";
|
|
64
|
+
PayloadType["outcome"] = "outcome";
|
|
65
|
+
PayloadType["menu"] = "menu";
|
|
66
|
+
PayloadType["content"] = "content";
|
|
67
|
+
})(PayloadType || (PayloadType = {}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
export { fileTypeSchema, attachmentRefSchema, attachmentPayloadSchema, FileType, } from "./attachment";
|
|
7
|
+
export { buttonSchema, ButtonType, PayloadType, } from "./button";
|
|
8
|
+
export { contentOptionsSchema, fallbackOptionsSchema, ActionOptionsSchema, } from "./options";
|
|
9
|
+
export { coordinatesSchema, payloadSchema, stdQuickReplySchema, } from "./quick-reply";
|
|
10
|
+
export { incomingMessageType, outgoingMessageTypeSchema, payloadTypeSchema, stdOutgoingTextMessageDataSchema, stdOutgoingQuickRepliesMessageDataSchema, stdOutgoingButtonsMessageDataSchema, stdOutgoingListMessageDataSchema, stdOutgoingAttachmentMessageDataSchema, stdOutgoingSystemMessageDataSchema, stdOutgoingTextMessageSchema, stdOutgoingQuickRepliesMessageSchema, stdOutgoingButtonsMessageSchema, contentElementSchema, contentPaginationSchema, stdOutgoingListMessageSchema, stdOutgoingCarouselMessageSchema, stdOutgoingAttachmentMessageSchema, stdOutgoingSystemMessageSchema, stdOutgoingMessageSchema, stdIncomingTextMessageDataSchema, stdIncomingPayloadMessageDataSchema, stdIncomingLocationMessageDataSchema, stdIncomingAttachmentMessageDataSchema, stdIncomingTextMessageSchema, stdIncomingPostBackMessageSchema, stdIncomingQuickReplyMessageSchema, stdIncomingLocationMessageSchema, stdIncomingAttachmentMessageSchema, stdIncomingMessageSchema, stdOutgoingTextEnvelopeSchema, stdOutgoingQuickRepliesEnvelopeSchema, stdOutgoingButtonsEnvelopeSchema, stdOutgoingListEnvelopeSchema, stdOutgoingAttachmentEnvelopeSchema, stdOutgoingSystemEnvelopeSchema, stdOutgoingMessageEnvelopeSchema, stdOutgoingEnvelopeSchema, IncomingMessageType, OutgoingMessageType, StdEventType, } from "./message-contract";
|
|
11
|
+
export { labelGroupFullSchema, labelGroupSchema, labelGroupStubSchema, } from "./label-group";
|
|
12
|
+
export { labelFullSchema, labelSchema, labelStubSchema, } from "./label";
|
|
13
|
+
export { subscriberFullSchema, subscriberSchema, subscriberStubSchema, } from "./subscriber";
|
|
14
|
+
export { threadFullSchema, threadSchema, threadStubSchema, } from "./thread";
|
|
15
|
+
export { messageFullSchema, messageSchema, messageStubSchema, } from "./message";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { baseStubSchema } from "../shared/base";
|
|
8
|
+
import { preprocess } from "../shared/preprocess";
|
|
9
|
+
import { labelSchema } from "./label";
|
|
10
|
+
const labelGroupObjectSchema = baseStubSchema.extend({
|
|
11
|
+
name: z.string(),
|
|
12
|
+
});
|
|
13
|
+
export const labelGroupStubSchema = labelGroupObjectSchema;
|
|
14
|
+
export const labelGroupSchema = labelGroupObjectSchema.extend({
|
|
15
|
+
labels: preprocess(() => undefined, z.undefined().optional()).optional(),
|
|
16
|
+
});
|
|
17
|
+
export const labelGroupFullSchema = labelGroupObjectSchema.extend({
|
|
18
|
+
labels: preprocess((value) => (Array.isArray(value) ? value : []), z.array(z.lazy(() => labelSchema))).optional(),
|
|
19
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { asId, withAliases } from "../shared/aliases";
|
|
8
|
+
import { baseStubSchema } from "../shared/base";
|
|
9
|
+
import { preprocess } from "../shared/preprocess";
|
|
10
|
+
import { labelGroupSchema } from "./label-group";
|
|
11
|
+
import { subscriberSchema } from "./subscriber";
|
|
12
|
+
const nullableOptionalStringSchema = z.string().nullable().optional();
|
|
13
|
+
const labelAliasMap = {
|
|
14
|
+
groupId: "group",
|
|
15
|
+
};
|
|
16
|
+
const labelStubObjectSchema = baseStubSchema.extend({
|
|
17
|
+
title: z.string(),
|
|
18
|
+
name: z.string(),
|
|
19
|
+
label_id: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
20
|
+
description: nullableOptionalStringSchema,
|
|
21
|
+
builtin: z.coerce.boolean(),
|
|
22
|
+
});
|
|
23
|
+
export const labelStubSchema = labelStubObjectSchema;
|
|
24
|
+
export const labelSchema = preprocess((value) => withAliases(value, labelAliasMap), labelStubObjectSchema.extend({
|
|
25
|
+
group: preprocess((value) => (value == null ? null : asId(value)), z.string().nullable()).optional(),
|
|
26
|
+
users: preprocess(() => undefined, z.undefined().optional()).optional(),
|
|
27
|
+
}));
|
|
28
|
+
export const labelFullSchema = labelStubObjectSchema.extend({
|
|
29
|
+
users: preprocess((value) => (Array.isArray(value) ? value : []), z.array(z.lazy(() => subscriberSchema))).optional(),
|
|
30
|
+
group: z
|
|
31
|
+
.lazy(() => labelGroupSchema)
|
|
32
|
+
.nullable()
|
|
33
|
+
.optional(),
|
|
34
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { attachmentPayloadSchema } from "./attachment";
|
|
8
|
+
import { PayloadType, buttonSchema } from "./button";
|
|
9
|
+
import { contentOptionsSchema } from "./options";
|
|
10
|
+
import { stdQuickReplySchema } from "./quick-reply";
|
|
11
|
+
export var StdEventType;
|
|
12
|
+
(function (StdEventType) {
|
|
13
|
+
StdEventType["message"] = "message";
|
|
14
|
+
StdEventType["delivery"] = "delivery";
|
|
15
|
+
StdEventType["read"] = "read";
|
|
16
|
+
StdEventType["typing"] = "typing";
|
|
17
|
+
StdEventType["follow"] = "follow";
|
|
18
|
+
StdEventType["echo"] = "echo";
|
|
19
|
+
StdEventType["error"] = "error";
|
|
20
|
+
StdEventType["unknown"] = "";
|
|
21
|
+
})(StdEventType || (StdEventType = {}));
|
|
22
|
+
export var IncomingMessageType;
|
|
23
|
+
(function (IncomingMessageType) {
|
|
24
|
+
IncomingMessageType["text"] = "text";
|
|
25
|
+
IncomingMessageType["postback"] = "postback";
|
|
26
|
+
IncomingMessageType["quickReply"] = "quickReply";
|
|
27
|
+
IncomingMessageType["location"] = "location";
|
|
28
|
+
IncomingMessageType["attachment"] = "attachment";
|
|
29
|
+
IncomingMessageType["unknown"] = "";
|
|
30
|
+
})(IncomingMessageType || (IncomingMessageType = {}));
|
|
31
|
+
export const incomingMessageType = z.enum(IncomingMessageType);
|
|
32
|
+
export var OutgoingMessageType;
|
|
33
|
+
(function (OutgoingMessageType) {
|
|
34
|
+
OutgoingMessageType["text"] = "text";
|
|
35
|
+
OutgoingMessageType["quickReply"] = "quickReply";
|
|
36
|
+
OutgoingMessageType["buttons"] = "buttons";
|
|
37
|
+
OutgoingMessageType["attachment"] = "attachment";
|
|
38
|
+
OutgoingMessageType["list"] = "list";
|
|
39
|
+
OutgoingMessageType["carousel"] = "carousel";
|
|
40
|
+
OutgoingMessageType["system"] = "system";
|
|
41
|
+
})(OutgoingMessageType || (OutgoingMessageType = {}));
|
|
42
|
+
export const outgoingMessageTypeSchema = z.enum(OutgoingMessageType);
|
|
43
|
+
export const payloadTypeSchema = z.enum(PayloadType);
|
|
44
|
+
export const stdOutgoingTextMessageDataSchema = z.object({
|
|
45
|
+
text: z.string(),
|
|
46
|
+
});
|
|
47
|
+
export const stdOutgoingQuickRepliesMessageDataSchema = z.object({
|
|
48
|
+
text: z.string(),
|
|
49
|
+
quickReplies: z.array(stdQuickReplySchema),
|
|
50
|
+
});
|
|
51
|
+
export const stdOutgoingButtonsMessageDataSchema = z.object({
|
|
52
|
+
text: z.string(),
|
|
53
|
+
buttons: z.array(buttonSchema),
|
|
54
|
+
});
|
|
55
|
+
export const contentElementSchema = z
|
|
56
|
+
.object({
|
|
57
|
+
id: z.string(),
|
|
58
|
+
title: z.string(),
|
|
59
|
+
})
|
|
60
|
+
.catchall(z.any());
|
|
61
|
+
export const contentPaginationSchema = z.object({
|
|
62
|
+
total: z.number(),
|
|
63
|
+
skip: z.number(),
|
|
64
|
+
limit: z.number(),
|
|
65
|
+
});
|
|
66
|
+
export const stdOutgoingListMessageDataSchema = z.object({
|
|
67
|
+
options: contentOptionsSchema,
|
|
68
|
+
elements: z.array(contentElementSchema),
|
|
69
|
+
pagination: contentPaginationSchema,
|
|
70
|
+
});
|
|
71
|
+
export const stdOutgoingAttachmentMessageDataSchema = z.object({
|
|
72
|
+
attachment: attachmentPayloadSchema,
|
|
73
|
+
quickReplies: z.array(stdQuickReplySchema).optional(),
|
|
74
|
+
});
|
|
75
|
+
export const stdOutgoingSystemMessageDataSchema = z.object({
|
|
76
|
+
outcome: z.string().optional(),
|
|
77
|
+
data: z.any().optional(),
|
|
78
|
+
});
|
|
79
|
+
export const stdOutgoingTextMessageSchema = z.object({
|
|
80
|
+
type: z.literal(OutgoingMessageType.text),
|
|
81
|
+
data: stdOutgoingTextMessageDataSchema,
|
|
82
|
+
});
|
|
83
|
+
export const stdOutgoingQuickRepliesMessageSchema = z.object({
|
|
84
|
+
type: z.literal(OutgoingMessageType.quickReply),
|
|
85
|
+
data: stdOutgoingQuickRepliesMessageDataSchema,
|
|
86
|
+
});
|
|
87
|
+
export const stdOutgoingButtonsMessageSchema = z.object({
|
|
88
|
+
type: z.literal(OutgoingMessageType.buttons),
|
|
89
|
+
data: stdOutgoingButtonsMessageDataSchema,
|
|
90
|
+
});
|
|
91
|
+
export const stdOutgoingListMessageSchema = z.object({
|
|
92
|
+
type: z.literal(OutgoingMessageType.list),
|
|
93
|
+
data: stdOutgoingListMessageDataSchema,
|
|
94
|
+
});
|
|
95
|
+
export const stdOutgoingCarouselMessageSchema = z.object({
|
|
96
|
+
type: z.literal(OutgoingMessageType.carousel),
|
|
97
|
+
data: stdOutgoingListMessageDataSchema,
|
|
98
|
+
});
|
|
99
|
+
export const stdOutgoingAttachmentMessageSchema = z.object({
|
|
100
|
+
type: z.literal(OutgoingMessageType.attachment),
|
|
101
|
+
data: stdOutgoingAttachmentMessageDataSchema,
|
|
102
|
+
});
|
|
103
|
+
export const stdOutgoingMessageSchema = z.discriminatedUnion("type", [
|
|
104
|
+
stdOutgoingTextMessageSchema,
|
|
105
|
+
stdOutgoingQuickRepliesMessageSchema,
|
|
106
|
+
stdOutgoingButtonsMessageSchema,
|
|
107
|
+
stdOutgoingListMessageSchema,
|
|
108
|
+
stdOutgoingCarouselMessageSchema,
|
|
109
|
+
stdOutgoingAttachmentMessageSchema,
|
|
110
|
+
]);
|
|
111
|
+
export const stdIncomingTextMessageDataSchema = z.object({
|
|
112
|
+
text: z.string(),
|
|
113
|
+
});
|
|
114
|
+
export const stdIncomingPayloadMessageDataSchema = z.object({
|
|
115
|
+
text: z.string(),
|
|
116
|
+
payload: z.string(),
|
|
117
|
+
});
|
|
118
|
+
export const stdIncomingLocationMessageDataSchema = z.object({
|
|
119
|
+
coordinates: z.object({
|
|
120
|
+
lat: z.number(),
|
|
121
|
+
lon: z.number(),
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
export const stdIncomingAttachmentMessageDataSchema = z.object({
|
|
125
|
+
serializedText: z.string(),
|
|
126
|
+
attachment: z.union([
|
|
127
|
+
attachmentPayloadSchema,
|
|
128
|
+
z.array(attachmentPayloadSchema),
|
|
129
|
+
]),
|
|
130
|
+
});
|
|
131
|
+
export const stdIncomingTextMessageSchema = z.object({
|
|
132
|
+
type: z.literal(IncomingMessageType.text),
|
|
133
|
+
data: stdIncomingTextMessageDataSchema,
|
|
134
|
+
});
|
|
135
|
+
export const stdIncomingPostBackMessageSchema = z.object({
|
|
136
|
+
type: z.literal(IncomingMessageType.postback),
|
|
137
|
+
data: stdIncomingPayloadMessageDataSchema,
|
|
138
|
+
});
|
|
139
|
+
export const stdIncomingQuickReplyMessageSchema = z.object({
|
|
140
|
+
type: z.literal(IncomingMessageType.quickReply),
|
|
141
|
+
data: stdIncomingPayloadMessageDataSchema,
|
|
142
|
+
});
|
|
143
|
+
export const stdIncomingLocationMessageSchema = z.object({
|
|
144
|
+
type: z.literal(IncomingMessageType.location),
|
|
145
|
+
data: stdIncomingLocationMessageDataSchema,
|
|
146
|
+
});
|
|
147
|
+
export const stdIncomingAttachmentMessageSchema = z.object({
|
|
148
|
+
type: z.literal(IncomingMessageType.attachment),
|
|
149
|
+
data: stdIncomingAttachmentMessageDataSchema,
|
|
150
|
+
});
|
|
151
|
+
export const stdIncomingMessageSchema = z.discriminatedUnion("type", [
|
|
152
|
+
stdIncomingTextMessageSchema,
|
|
153
|
+
stdIncomingPostBackMessageSchema,
|
|
154
|
+
stdIncomingQuickReplyMessageSchema,
|
|
155
|
+
stdIncomingLocationMessageSchema,
|
|
156
|
+
stdIncomingAttachmentMessageSchema,
|
|
157
|
+
]);
|
|
158
|
+
export const stdOutgoingTextEnvelopeSchema = stdOutgoingTextMessageSchema;
|
|
159
|
+
export const stdOutgoingQuickRepliesEnvelopeSchema = stdOutgoingQuickRepliesMessageSchema;
|
|
160
|
+
export const stdOutgoingButtonsEnvelopeSchema = stdOutgoingButtonsMessageSchema;
|
|
161
|
+
export const stdOutgoingListEnvelopeSchema = z.discriminatedUnion("type", [
|
|
162
|
+
stdOutgoingListMessageSchema,
|
|
163
|
+
stdOutgoingCarouselMessageSchema,
|
|
164
|
+
]);
|
|
165
|
+
export const stdOutgoingAttachmentEnvelopeSchema = stdOutgoingAttachmentMessageSchema;
|
|
166
|
+
export const stdOutgoingSystemMessageSchema = z.object({
|
|
167
|
+
type: z.literal(OutgoingMessageType.system),
|
|
168
|
+
data: stdOutgoingSystemMessageDataSchema,
|
|
169
|
+
});
|
|
170
|
+
export const stdOutgoingSystemEnvelopeSchema = stdOutgoingSystemMessageSchema;
|
|
171
|
+
export const stdOutgoingMessageEnvelopeSchema = stdOutgoingMessageSchema;
|
|
172
|
+
export const stdOutgoingEnvelopeSchema = z.discriminatedUnion("type", [
|
|
173
|
+
stdOutgoingTextMessageSchema,
|
|
174
|
+
stdOutgoingQuickRepliesMessageSchema,
|
|
175
|
+
stdOutgoingButtonsMessageSchema,
|
|
176
|
+
stdOutgoingListMessageSchema,
|
|
177
|
+
stdOutgoingCarouselMessageSchema,
|
|
178
|
+
stdOutgoingAttachmentMessageSchema,
|
|
179
|
+
stdOutgoingSystemMessageSchema,
|
|
180
|
+
]);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { asId, withAliases } from "../shared/aliases";
|
|
8
|
+
import { baseStubSchema } from "../shared/base";
|
|
9
|
+
import { preprocess } from "../shared/preprocess";
|
|
10
|
+
import { userSchema } from "../user/user";
|
|
11
|
+
import { IncomingMessageType, OutgoingMessageType, stdOutgoingMessageSchema, stdIncomingMessageSchema, } from "./message-contract";
|
|
12
|
+
import { subscriberSchema } from "./subscriber";
|
|
13
|
+
import { threadSchema } from "./thread";
|
|
14
|
+
const messageAliasMap = {
|
|
15
|
+
senderId: "sender",
|
|
16
|
+
recipientId: "recipient",
|
|
17
|
+
sentById: "sentBy",
|
|
18
|
+
threadId: "thread",
|
|
19
|
+
};
|
|
20
|
+
const incomingOnlyTypes = new Set([
|
|
21
|
+
IncomingMessageType.postback,
|
|
22
|
+
IncomingMessageType.location,
|
|
23
|
+
]);
|
|
24
|
+
const outgoingOnlyTypes = new Set([
|
|
25
|
+
OutgoingMessageType.buttons,
|
|
26
|
+
OutgoingMessageType.list,
|
|
27
|
+
OutgoingMessageType.carousel,
|
|
28
|
+
OutgoingMessageType.system,
|
|
29
|
+
]);
|
|
30
|
+
const invalidDirectionMessage = {
|
|
31
|
+
type: "__invalidDirection__",
|
|
32
|
+
data: null,
|
|
33
|
+
};
|
|
34
|
+
const parseByDirection = (message, record) => {
|
|
35
|
+
const hasSender = record.sender != null;
|
|
36
|
+
const hasRecipient = record.recipient != null;
|
|
37
|
+
const hasSentBy = record.sentBy != null;
|
|
38
|
+
const shouldUseOutgoingSchema = hasRecipient || hasSentBy;
|
|
39
|
+
const shouldUseIncomingSchema = hasSender && !shouldUseOutgoingSchema;
|
|
40
|
+
if (shouldUseOutgoingSchema) {
|
|
41
|
+
const parsed = stdOutgoingMessageSchema.safeParse(message);
|
|
42
|
+
return parsed.success ? parsed.data : invalidDirectionMessage;
|
|
43
|
+
}
|
|
44
|
+
if (shouldUseIncomingSchema) {
|
|
45
|
+
const parsed = stdIncomingMessageSchema.safeParse(message);
|
|
46
|
+
return parsed.success ? parsed.data : invalidDirectionMessage;
|
|
47
|
+
}
|
|
48
|
+
const type = typeof message === "object" && message !== null
|
|
49
|
+
? message.type
|
|
50
|
+
: undefined;
|
|
51
|
+
if (typeof type !== "string") {
|
|
52
|
+
const parsed = messagePayloadSchema.safeParse(message);
|
|
53
|
+
return parsed.success ? parsed.data : message;
|
|
54
|
+
}
|
|
55
|
+
if (incomingOnlyTypes.has(type)) {
|
|
56
|
+
const parsed = stdIncomingMessageSchema.safeParse(message);
|
|
57
|
+
return parsed.success ? parsed.data : message;
|
|
58
|
+
}
|
|
59
|
+
if (outgoingOnlyTypes.has(type)) {
|
|
60
|
+
const parsed = stdOutgoingMessageSchema.safeParse(message);
|
|
61
|
+
return parsed.success ? parsed.data : message;
|
|
62
|
+
}
|
|
63
|
+
const parsed = messagePayloadSchema.safeParse(message);
|
|
64
|
+
return parsed.success ? parsed.data : message;
|
|
65
|
+
};
|
|
66
|
+
const normalizeMessageRecord = (value) => {
|
|
67
|
+
const normalized = withAliases(value, messageAliasMap);
|
|
68
|
+
if (typeof normalized !== "object" ||
|
|
69
|
+
normalized === null ||
|
|
70
|
+
!("message" in normalized)) {
|
|
71
|
+
return normalized;
|
|
72
|
+
}
|
|
73
|
+
const record = normalized;
|
|
74
|
+
record.message = parseByDirection(record.message, record);
|
|
75
|
+
return record;
|
|
76
|
+
};
|
|
77
|
+
const messagePayloadSchema = z.union([
|
|
78
|
+
stdIncomingMessageSchema,
|
|
79
|
+
stdOutgoingMessageSchema,
|
|
80
|
+
]);
|
|
81
|
+
const messageStubObjectSchema = baseStubSchema.extend({
|
|
82
|
+
mid: z.string().optional(),
|
|
83
|
+
message: messagePayloadSchema,
|
|
84
|
+
read: z.coerce.boolean(),
|
|
85
|
+
delivery: z.coerce.boolean(),
|
|
86
|
+
handover: z.coerce.boolean(),
|
|
87
|
+
});
|
|
88
|
+
export const messageStubSchema = messageStubObjectSchema;
|
|
89
|
+
export const messageSchema = preprocess(normalizeMessageRecord, messageStubObjectSchema.extend({
|
|
90
|
+
sender: preprocess((value) => (value == null ? null : asId(value)), z.string().nullable()).optional(),
|
|
91
|
+
recipient: preprocess((value) => (value == null ? null : asId(value)), z.string().nullable()).optional(),
|
|
92
|
+
sentBy: preprocess((value) => (value == null ? null : asId(value)), z.string().nullable()).optional(),
|
|
93
|
+
thread: preprocess((value) => (value == null ? null : asId(value)), z.string()),
|
|
94
|
+
}));
|
|
95
|
+
const messageFullObjectSchema = messageStubObjectSchema.extend({
|
|
96
|
+
sender: subscriberSchema.nullable().optional(),
|
|
97
|
+
recipient: subscriberSchema.nullable().optional(),
|
|
98
|
+
sentBy: z
|
|
99
|
+
.lazy(() => userSchema)
|
|
100
|
+
.nullable()
|
|
101
|
+
.optional(),
|
|
102
|
+
thread: threadSchema,
|
|
103
|
+
});
|
|
104
|
+
export const messageFullSchema = preprocess(normalizeMessageRecord, messageFullObjectSchema);
|