@modainteract/moda-interact-shared 0.11.2 → 0.12.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.
@@ -0,0 +1,67 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const WHATSAPP_INBOUND_MESSAGE_SCHEMA_VERSION: 1;
4
+ declare const WhatsAppInboundContentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
+ type: z.ZodLiteral<"text">;
6
+ text: z.ZodString;
7
+ }, z.core.$strict>, z.ZodObject<{
8
+ type: z.ZodLiteral<"audio">;
9
+ mediaId: z.ZodString;
10
+ mimeType: z.ZodNullable<z.ZodString>;
11
+ sha256: z.ZodNullable<z.ZodString>;
12
+ voice: z.ZodNullable<z.ZodBoolean>;
13
+ }, z.core.$strict>, z.ZodObject<{
14
+ type: z.ZodLiteral<"unsupported">;
15
+ providerType: z.ZodString;
16
+ }, z.core.$strict>], "type">;
17
+ declare const NormalizedWhatsAppInboundMessageSchema: z.ZodObject<{
18
+ schemaVersion: z.ZodLiteral<1>;
19
+ provider: z.ZodLiteral<"whatsapp">;
20
+ providerAccountId: z.ZodString;
21
+ providerPhoneNumberId: z.ZodString;
22
+ providerMessageId: z.ZodString;
23
+ customerPhone: z.ZodString;
24
+ contextMessageId: z.ZodNullable<z.ZodString>;
25
+ occurredAt: z.ZodISODateTime;
26
+ content: z.ZodDiscriminatedUnion<[z.ZodObject<{
27
+ type: z.ZodLiteral<"text">;
28
+ text: z.ZodString;
29
+ }, z.core.$strict>, z.ZodObject<{
30
+ type: z.ZodLiteral<"audio">;
31
+ mediaId: z.ZodString;
32
+ mimeType: z.ZodNullable<z.ZodString>;
33
+ sha256: z.ZodNullable<z.ZodString>;
34
+ voice: z.ZodNullable<z.ZodBoolean>;
35
+ }, z.core.$strict>, z.ZodObject<{
36
+ type: z.ZodLiteral<"unsupported">;
37
+ providerType: z.ZodString;
38
+ }, z.core.$strict>], "type">;
39
+ }, z.core.$strict>;
40
+ type WhatsAppInboundContent = z.infer<typeof WhatsAppInboundContentSchema>;
41
+ type NormalizedWhatsAppInboundMessage = z.infer<typeof NormalizedWhatsAppInboundMessageSchema>;
42
+ declare function parseNormalizedWhatsAppInboundMessage(input: unknown): NormalizedWhatsAppInboundMessage;
43
+ declare function safeParseNormalizedWhatsAppInboundMessage(input: unknown): z.ZodSafeParseResult<{
44
+ schemaVersion: 1;
45
+ provider: "whatsapp";
46
+ providerAccountId: string;
47
+ providerPhoneNumberId: string;
48
+ providerMessageId: string;
49
+ customerPhone: string;
50
+ contextMessageId: string | null;
51
+ occurredAt: string;
52
+ content: {
53
+ type: "text";
54
+ text: string;
55
+ } | {
56
+ type: "audio";
57
+ mediaId: string;
58
+ mimeType: string | null;
59
+ sha256: string | null;
60
+ voice: boolean | null;
61
+ } | {
62
+ type: "unsupported";
63
+ providerType: string;
64
+ };
65
+ }>;
66
+
67
+ export { type NormalizedWhatsAppInboundMessage, NormalizedWhatsAppInboundMessageSchema, WHATSAPP_INBOUND_MESSAGE_SCHEMA_VERSION, type WhatsAppInboundContent, WhatsAppInboundContentSchema, parseNormalizedWhatsAppInboundMessage, safeParseNormalizedWhatsAppInboundMessage };
@@ -0,0 +1,52 @@
1
+ // src/whatsapp.ts
2
+ import { z } from "zod";
3
+ var WHATSAPP_INBOUND_MESSAGE_SCHEMA_VERSION = 1;
4
+ var MAX_IDENTIFIER_LENGTH = 256;
5
+ var MAX_CUSTOMER_PHONE_LENGTH = 64;
6
+ var MAX_TEXT_LENGTH = 4096;
7
+ var boundedIdentifier = (max = MAX_IDENTIFIER_LENGTH) => z.string().trim().min(1).max(max);
8
+ var textContentSchema = z.object({
9
+ type: z.literal("text"),
10
+ text: z.string().trim().min(1).max(MAX_TEXT_LENGTH)
11
+ }).strict();
12
+ var audioContentSchema = z.object({
13
+ type: z.literal("audio"),
14
+ mediaId: boundedIdentifier(),
15
+ mimeType: z.string().trim().min(1).max(MAX_IDENTIFIER_LENGTH).nullable(),
16
+ sha256: z.string().trim().min(1).max(MAX_IDENTIFIER_LENGTH).nullable(),
17
+ voice: z.boolean().nullable()
18
+ }).strict();
19
+ var unsupportedContentSchema = z.object({
20
+ type: z.literal("unsupported"),
21
+ providerType: boundedIdentifier()
22
+ }).strict();
23
+ var WhatsAppInboundContentSchema = z.discriminatedUnion("type", [
24
+ textContentSchema,
25
+ audioContentSchema,
26
+ unsupportedContentSchema
27
+ ]);
28
+ var NormalizedWhatsAppInboundMessageSchema = z.object({
29
+ schemaVersion: z.literal(WHATSAPP_INBOUND_MESSAGE_SCHEMA_VERSION),
30
+ provider: z.literal("whatsapp"),
31
+ providerAccountId: boundedIdentifier(),
32
+ providerPhoneNumberId: boundedIdentifier(),
33
+ providerMessageId: boundedIdentifier(),
34
+ customerPhone: boundedIdentifier(MAX_CUSTOMER_PHONE_LENGTH),
35
+ contextMessageId: boundedIdentifier().nullable(),
36
+ occurredAt: z.iso.datetime({ offset: true }),
37
+ content: WhatsAppInboundContentSchema
38
+ }).strict();
39
+ function parseNormalizedWhatsAppInboundMessage(input) {
40
+ return NormalizedWhatsAppInboundMessageSchema.parse(input);
41
+ }
42
+ function safeParseNormalizedWhatsAppInboundMessage(input) {
43
+ return NormalizedWhatsAppInboundMessageSchema.safeParse(input);
44
+ }
45
+ export {
46
+ NormalizedWhatsAppInboundMessageSchema,
47
+ WHATSAPP_INBOUND_MESSAGE_SCHEMA_VERSION,
48
+ WhatsAppInboundContentSchema,
49
+ parseNormalizedWhatsAppInboundMessage,
50
+ safeParseNormalizedWhatsAppInboundMessage
51
+ };
52
+ //# sourceMappingURL=whatsapp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/whatsapp.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const WHATSAPP_INBOUND_MESSAGE_SCHEMA_VERSION = 1 as const;\n\nconst MAX_IDENTIFIER_LENGTH = 256;\nconst MAX_CUSTOMER_PHONE_LENGTH = 64;\nconst MAX_TEXT_LENGTH = 4096;\n\nconst boundedIdentifier = (max: number = MAX_IDENTIFIER_LENGTH) =>\n z.string().trim().min(1).max(max);\n\nconst textContentSchema = z\n .object({\n type: z.literal(\"text\"),\n text: z.string().trim().min(1).max(MAX_TEXT_LENGTH),\n })\n .strict();\n\nconst audioContentSchema = z\n .object({\n type: z.literal(\"audio\"),\n mediaId: boundedIdentifier(),\n mimeType: z.string().trim().min(1).max(MAX_IDENTIFIER_LENGTH).nullable(),\n sha256: z.string().trim().min(1).max(MAX_IDENTIFIER_LENGTH).nullable(),\n voice: z.boolean().nullable(),\n })\n .strict();\n\nconst unsupportedContentSchema = z\n .object({\n type: z.literal(\"unsupported\"),\n providerType: boundedIdentifier(),\n })\n .strict();\n\nexport const WhatsAppInboundContentSchema = z.discriminatedUnion(\"type\", [\n textContentSchema,\n audioContentSchema,\n unsupportedContentSchema,\n]);\n\nexport const NormalizedWhatsAppInboundMessageSchema = z\n .object({\n schemaVersion: z.literal(WHATSAPP_INBOUND_MESSAGE_SCHEMA_VERSION),\n provider: z.literal(\"whatsapp\"),\n providerAccountId: boundedIdentifier(),\n providerPhoneNumberId: boundedIdentifier(),\n providerMessageId: boundedIdentifier(),\n customerPhone: boundedIdentifier(MAX_CUSTOMER_PHONE_LENGTH),\n contextMessageId: boundedIdentifier().nullable(),\n occurredAt: z.iso.datetime({ offset: true }),\n content: WhatsAppInboundContentSchema,\n })\n .strict();\n\nexport type WhatsAppInboundContent = z.infer<typeof WhatsAppInboundContentSchema>;\nexport type NormalizedWhatsAppInboundMessage = z.infer<\n typeof NormalizedWhatsAppInboundMessageSchema\n>;\n\nexport function parseNormalizedWhatsAppInboundMessage(\n input: unknown,\n): NormalizedWhatsAppInboundMessage {\n return NormalizedWhatsAppInboundMessageSchema.parse(input);\n}\n\nexport function safeParseNormalizedWhatsAppInboundMessage(input: unknown) {\n return NormalizedWhatsAppInboundMessageSchema.safeParse(input);\n}"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,0CAA0C;AAEvD,IAAM,wBAAwB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AC,EACA,OAAO;AAOH,SAAS,sCACd,OACkC;AAClC,SAAO,uCAAuC,MAAM,KAAK;AAC3D;AAEO,SAAS,0CAA0C,OAAgB;AACxE,SAAO,uCAAuC,UAAU,KAAK;AAC/D;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modainteract/moda-interact-shared",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,6 +20,10 @@
20
20
  "types": "./dist/billing.d.ts",
21
21
  "import": "./dist/billing.js"
22
22
  },
23
+ "./whatsapp": {
24
+ "types": "./dist/whatsapp.d.ts",
25
+ "import": "./dist/whatsapp.js"
26
+ },
23
27
  "./merchant-communications": {
24
28
  "types": "./dist/merchant-communications.d.ts",
25
29
  "import": "./dist/merchant-communications.js"