UNPKG

evolution-api-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

1 lines 2.28 kB
{"version":3,"sources":["../../src/schemas/common.ts"],"sourcesContent":["// Pure TypeScript types and utility functions for better IDE support and performance\nimport { isValidPhoneNumber, parsePhoneNumber } from \"libphonenumber-js\";\nimport type { GroupInviteCode, GroupJid, Jid } from \"@/types/tags\";\n\n// Type definitions\nexport type PhoneNumber = string;\nexport type MessageId = string;\nexport type ChatId = PhoneNumber | Jid | GroupJid;\nexport type ApiNumber = PhoneNumber | Jid | GroupJid;\nexport type Media = string; // URL or base64 string\n\n// Utility functions\nexport const validatePhoneNumber = (value: string): boolean => isValidPhoneNumber(value);\nexport const parsePhoneNumberUtil = (phoneNumber: string): string => parsePhoneNumber(phoneNumber).number;\n\nexport const validateJid = (value: string): boolean => value.endsWith(\"@s.whatsapp.net\");\nexport const validateGroupJid = (value: string): boolean => value.endsWith(\"@g.us\");\nexport const validateGroupInviteCode = (value: string): boolean => \n value.length === 22 && /^[a-zA-Z0-9]{22}$/.test(value);\n\nexport const validateMedia = (value: string): boolean => {\n // Check if it's a URL or base64 string\n try {\n new URL(value);\n return true;\n } catch {\n // Check if it's a valid base64 string\n try {\n return btoa(atob(value)) === value;\n } catch {\n return false;\n }\n }\n};\n\n// Backward compatibility - keeping the schema names but as type aliases\nexport type PhoneNumberSchema = PhoneNumber;\nexport type JidSchema = Jid;\nexport type GroupJidSchema = GroupJid;\nexport type GroupInviteCodeSchema = GroupInviteCode;\nexport type MessageIdSchema = MessageId;\nexport type ChatIdSchema = ChatId;\nexport type ApiNumberSchema = ApiNumber;\nexport type mediaSchema = Media;\n"],"mappings":";AACA,SAAS,oBAAoB,wBAAwB;AAW9C,IAAM,sBAAsB,CAAC,UAA2B,mBAAmB,KAAK;AAChF,IAAM,uBAAuB,CAAC,gBAAgC,iBAAiB,WAAW,EAAE;AAE5F,IAAM,cAAc,CAAC,UAA2B,MAAM,SAAS,iBAAiB;AAChF,IAAM,mBAAmB,CAAC,UAA2B,MAAM,SAAS,OAAO;AAC3E,IAAM,0BAA0B,CAAC,UACtC,MAAM,WAAW,MAAM,oBAAoB,KAAK,KAAK;AAEhD,IAAM,gBAAgB,CAAC,UAA2B;AAEvD,MAAI;AACF,QAAI,IAAI,KAAK;AACb,WAAO;AAAA,EACT,QAAQ;AAEN,QAAI;AACF,aAAO,KAAK,KAAK,KAAK,CAAC,MAAM;AAAA,IAC/B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}