evolution-api-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
1 lines • 5.38 kB
Source Map (JSON)
{"version":3,"sources":["../../../../src/types/tags.ts","../../../../src/utils/phone-numer-from-jid.ts","../../../../src/modules/groups/schemas/common.ts","../../../../src/modules/groups/schemas/find-all.ts"],"sourcesContent":["export type Jid = `${string}@s.whatsapp.net` | string;\nexport const Jid = (jid: string) => jid as Jid;\n\nexport type GroupJid = `${string}@g.us` | string;\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","// Pure TypeScript interfaces for better IDE support and performance\nimport { GroupJid, Jid } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\n\n// Raw response interfaces from API\nexport interface GroupResponseRaw {\n\tid: string;\n\tsubject: string;\n\tsubjectOwner: string;\n\tsubjectTime: string | Date;\n\tpictureUrl?: string | null;\n\tsize: number;\n\tcreation: string | Date;\n\towner: string;\n\trestrict: boolean;\n\tannounce: boolean;\n}\n\nexport interface ParticipantResponseRaw {\n\tid: string;\n\tadmin?: \"admin\" | \"superadmin\" | null;\n}\n\nexport interface GroupWithParticipantsResponseRaw extends GroupResponseRaw {\n\tparticipants: ParticipantResponseRaw[];\n}\n\n// Transformed response interfaces\nexport interface GroupResponse {\n\tjid: GroupJid;\n\tname: string;\n\tpictureUrl?: string;\n\tsize: number;\n\tsubject: {\n\t\towner: Jid;\n\t\ttime: Date;\n\t};\n\towner: {\n\t\tjid: Jid;\n\t\tphoneNumber: string;\n\t};\n\tcreatedAt: Date;\n\trestrict: boolean;\n\tannounce: boolean;\n}\n\nexport interface ParticipantResponse {\n\tid: string;\n\trole: \"admin\" | \"superadmin\" | \"member\";\n}\n\nexport interface GroupWithParticipantsResponse extends GroupResponse {\n\tparticipants: ParticipantResponse[];\n}\n\n// Transform functions\nexport const GroupResponseSchemaTransform = (\n\tgroup: GroupResponseRaw,\n): GroupResponse => ({\n\tjid: GroupJid(group.id),\n\tname: group.subject,\n\tpictureUrl: group.pictureUrl || undefined,\n\tsize: group.size,\n\tsubject: {\n\t\towner: Jid(group.subjectOwner),\n\t\ttime: new Date(group.subjectTime),\n\t},\n\towner: {\n\t\tjid: Jid(group.owner),\n\t\tphoneNumber: phoneNumberFromJid(group.owner),\n\t},\n\tcreatedAt: new Date(group.creation),\n\trestrict: group.restrict,\n\tannounce: group.announce,\n});\n\nexport const ParticipantResponseSchemaTransform = (\n\tparticipant: ParticipantResponseRaw,\n): ParticipantResponse => ({\n\tid: participant.id,\n\trole: participant.admin || (\"member\" as const),\n});\n\nexport const GroupWithParticipantsResponseSchemaTransform = (\n\tgroup: GroupWithParticipantsResponseRaw,\n): GroupWithParticipantsResponse => ({\n\t...GroupResponseSchemaTransform(group),\n\tparticipants: group.participants.map(ParticipantResponseSchemaTransform),\n});\n","// Pure TypeScript interfaces for better IDE support and performance\nimport {\n\tGroupResponseRaw,\n\tGroupResponseSchemaTransform,\n\tGroupWithParticipantsResponseRaw,\n\tGroupWithParticipantsResponseSchemaTransform,\n\tGroupResponse,\n\tGroupWithParticipantsResponse,\n} from \"./common\";\n\n// Transform functions\nexport const FindAllGroupsResponseTransform = (\n\tgroups: GroupResponseRaw[],\n): GroupResponse[] => groups.map(GroupResponseSchemaTransform);\n\nexport const FindAllGroupsWithParticipantsResponseTransform = (\n\tgroups: GroupWithParticipantsResponseRaw[],\n): GroupWithParticipantsResponse[] => groups.map(GroupWithParticipantsResponseSchemaTransform);\n\n// Response types\nexport type FindAllGroupsResponse = GroupResponse[];\nexport type FindAllGroupsWithParticipantsResponse = GroupWithParticipantsResponse[];\n\n// Backward compatibility aliases\nexport const ResponseSchema = { parse: FindAllGroupsResponseTransform };\nexport const ResponseWithParticipantsSchema = { parse: FindAllGroupsWithParticipantsResponseTransform };\n"],"mappings":";AACO,IAAM,MAAM,CAAC,QAAgB;AAG7B,IAAM,WAAW,CAAC,QAAgB;;;ACJzC,SAAS,wBAAwB;AAM1B,SAAS,mBAAmB,KAAa;AAC/C,SAAO,iBAAiB,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;AAClD;;;ACgDO,IAAM,+BAA+B,CAC3C,WACoB;AAAA,EACpB,KAAK,SAAS,MAAM,EAAE;AAAA,EACtB,MAAM,MAAM;AAAA,EACZ,YAAY,MAAM,cAAc;AAAA,EAChC,MAAM,MAAM;AAAA,EACZ,SAAS;AAAA,IACR,OAAO,IAAI,MAAM,YAAY;AAAA,IAC7B,MAAM,IAAI,KAAK,MAAM,WAAW;AAAA,EACjC;AAAA,EACA,OAAO;AAAA,IACN,KAAK,IAAI,MAAM,KAAK;AAAA,IACpB,aAAa,mBAAmB,MAAM,KAAK;AAAA,EAC5C;AAAA,EACA,WAAW,IAAI,KAAK,MAAM,QAAQ;AAAA,EAClC,UAAU,MAAM;AAAA,EAChB,UAAU,MAAM;AACjB;AAEO,IAAM,qCAAqC,CACjD,iBAC0B;AAAA,EAC1B,IAAI,YAAY;AAAA,EAChB,MAAM,YAAY,SAAU;AAC7B;AAEO,IAAM,+CAA+C,CAC3D,WACoC;AAAA,EACpC,GAAG,6BAA6B,KAAK;AAAA,EACrC,cAAc,MAAM,aAAa,IAAI,kCAAkC;AACxE;;;AC7EO,IAAM,iCAAiC,CAC7C,WACqB,OAAO,IAAI,4BAA4B;AAEtD,IAAM,iDAAiD,CAC7D,WACqC,OAAO,IAAI,4CAA4C;AAOtF,IAAM,iBAAiB,EAAE,OAAO,+BAA+B;AAC/D,IAAM,iCAAiC,EAAE,OAAO,+CAA+C;","names":[]}