UNPKG

@solufy/evolution-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

1 lines 6.28 kB
{"version":3,"sources":["../../../../src/modules/messages/schemas/location.ts","../../../../src/types/tags.ts","../../../../src/utils/phone-numer-from-jid.ts","../../../../src/modules/messages/schemas/base.ts","../../../../src/schemas/common.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { Jid, MessageId } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\nimport { BaseMessageOptionsSchema } from \"./base\";\n\nexport const LocationMessageOptionsSchema = BaseMessageOptionsSchema.extend({\n\t/**\n\t * Location name\n\t */\n\tname: z.string(),\n\t/**\n\t * Location address\n\t */\n\taddress: z.string(),\n\t/**\n\t * Location latitude\n\t */\n\tlatitude: z.number(),\n\t/**\n\t * Location longitude\n\t */\n\tlongitude: z.number(),\n});\n\nexport const LocationMessageBodySchema = LocationMessageOptionsSchema;\n\nexport const LocationMessageResponseSchema = z\n\t.object({\n\t\tkey: z.object({\n\t\t\tremoteJid: z.string(),\n\t\t\tid: z.string(),\n\t\t}),\n\t\tmessage: z.object({\n\t\t\tlocationMessage: z.object({\n\t\t\t\tdegreesLatitude: z.number(),\n\t\t\t\tdegreesLongitude: z.number(),\n\t\t\t\tname: z.string(),\n\t\t\t\taddress: z.string(),\n\t\t\t}),\n\t\t}),\n\t\tmessageTimestamp: z.coerce.date(),\n\t})\n\t.transform((data) => ({\n\t\treceiver: {\n\t\t\tphoneNumber: phoneNumberFromJid(data.key.remoteJid),\n\t\t\tjid: Jid(data.key.remoteJid),\n\t\t},\n\t\tlocation: {\n\t\t\tlatitude: data.message.locationMessage.degreesLatitude,\n\t\t\tlongitude: data.message.locationMessage.degreesLongitude,\n\t\t\tname: data.message.locationMessage.name,\n\t\t\taddress: data.message.locationMessage.address,\n\t\t},\n\t\tid: MessageId(data.key.id),\n\t\ttimestamp: data.messageTimestamp,\n\t}));\n\nexport type LocationMessageOptions = z.infer<\n\ttypeof LocationMessageOptionsSchema\n>;\nexport type LocationMessageResponse = z.infer<\n\ttypeof LocationMessageResponseSchema\n>;\n\nexport {\n\tLocationMessageBodySchema as BodySchema,\n\tLocationMessageOptionsSchema as OptionsSchema,\n\tLocationMessageResponseSchema as ResponseSchema,\n};\n","export type Jid = `${string}@s.whatsapp.net`;\nexport const Jid = (jid: string) => jid as Jid;\n\nexport type GroupJid = `${string}@g.us`;\nexport const GroupJid = (jid: string) => jid as GroupJid;\n\nexport type GroupInviteCode = string & { __tag: \"GroupInviteCode\" };\nexport const GroupInviteCode = (code: string) => code as GroupInviteCode;\n\nexport type MessageId = string & { __tag: \"MessageId\" };\nexport const MessageId = (id: string) => id as MessageId;\n\nexport type ChatId = string & { __tag: \"ChatId\" };\nexport const ChatId = (id: string) => id as ChatId;\n","import { parsePhoneNumber } from \"libphonenumber-js\";\n\n/**\n * Get phone number from JID\n * @param jid - JID (remote JID)\n */\nexport function phoneNumberFromJid(jid: string) {\n\treturn parsePhoneNumber(`+${jid.split(\"@\")[0]}`).number;\n}\n","import { z } from \"zod\";\n\nimport { ApiNumberSchema } from \"@/schemas/common\";\n\nexport const BaseMessageOptionsSchema = z.object({\n\t/**\n\t * Number (with country code) or JID to receive the message\n\t */\n\tnumber: ApiNumberSchema,\n\t/**\n\t * Time in milliseconds before sending message\n\t */\n\tdelay: z.number().optional(),\n});\n\nexport type BaseMessageOptions = z.infer<typeof BaseMessageOptionsSchema>;\n","import { isValidPhoneNumber, parsePhoneNumber } from \"libphonenumber-js\";\nimport { z } from \"zod\";\n\nimport type { GroupInviteCode, GroupJid, Jid } from \"@/types/tags\";\n\nexport const PhoneNumberSchema = z\n\t.custom<string>((value) => isValidPhoneNumber(value), \"Invalid phone number\")\n\t.transform<string>((phoneNumber) => parsePhoneNumber(phoneNumber).number);\n\nexport const JidSchema = z\n\t.string()\n\t.endsWith(\n\t\t\"@s.whatsapp.net\",\n\t\t\"Invalid remote JID, should end with @s.whatsapp.net\",\n\t) as z.ZodType<Jid>;\n\nexport const GroupJidSchema = z\n\t.string()\n\t.endsWith(\n\t\t\"@g.us\",\n\t\t\"Invalid group JID, should end with @g.us\",\n\t) as z.ZodType<GroupJid>;\n\nexport const GroupInviteCodeSchema = z\n\t.string()\n\t.length(22)\n\t.regex(\n\t\t/^[a-zA-Z0-9]{22}$/,\n\t\t\"Invalid group invite code\",\n\t) as unknown as z.ZodType<GroupInviteCode>;\n\nexport const ApiNumberSchema = z.union([\n\tPhoneNumberSchema,\n\tJidSchema,\n\tGroupJidSchema,\n]);\n\nexport const mediaSchema = z.union([z.string().url(), z.string().base64()]);\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACCX,IAAM,MAAM,CAAC,QAAgB;AAS7B,IAAM,YAAY,CAAC,OAAe;;;ACVzC,SAAS,wBAAwB;AAM1B,SAAS,mBAAmB,KAAa;AAC/C,SAAO,iBAAiB,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;AAClD;;;ACRA,SAAS,KAAAC,UAAS;;;ACAlB,SAAS,oBAAoB,oBAAAC,yBAAwB;AACrD,SAAS,SAAS;AAIX,IAAM,oBAAoB,EAC/B,OAAe,CAAC,UAAU,mBAAmB,KAAK,GAAG,sBAAsB,EAC3E,UAAkB,CAAC,gBAAgBA,kBAAiB,WAAW,EAAE,MAAM;AAElE,IAAM,YAAY,EACvB,OAAO,EACP;AAAA,EACA;AAAA,EACA;AACD;AAEM,IAAM,iBAAiB,EAC5B,OAAO,EACP;AAAA,EACA;AAAA,EACA;AACD;AAEM,IAAM,wBAAwB,EACnC,OAAO,EACP,OAAO,EAAE,EACT;AAAA,EACA;AAAA,EACA;AACD;AAEM,IAAM,kBAAkB,EAAE,MAAM;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACD,CAAC;AAEM,IAAM,cAAc,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;;;ADjCnE,IAAM,2BAA2BC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