UNPKG

@solufy/evolution-sdk

Version:

Unofficial SDK for the Evolution Whatsapp API v2

1 lines 3.14 kB
{"version":3,"sources":["../../../../src/modules/chats/schemas/find-all.ts","../../../../src/types/tags.ts","../../../../src/utils/phone-numer-from-jid.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { ChatId, GroupJid, Jid } from \"@/types/tags\";\nimport { phoneNumberFromJid } from \"@/utils/phone-numer-from-jid\";\n\nexport const FindAllChatsResponseSchema = z\n\t.array(\n\t\tz.object({\n\t\t\tid: z.string(),\n\t\t\tremoteJid: z.string(),\n\t\t\tname: z.string().nullish(),\n\t\t\tlabels: z.array(z.string()).nullish(),\n\t\t\tcreatedAt: z.coerce.date(),\n\t\t\tupdatedAt: z.coerce.date(),\n\t\t\tpushName: z.string().nullish(),\n\t\t\tprofilePicUrl: z.string().url().nullish(),\n\t\t}),\n\t)\n\t.transform((chats) =>\n\t\tchats.map((chat) => ({\n\t\t\tid: ChatId(chat.id),\n\t\t\tjid: chat.remoteJid.endsWith(\"@g.us\")\n\t\t\t\t? GroupJid(chat.remoteJid)\n\t\t\t\t: Jid(chat.remoteJid),\n\t\t\tphoneNumber: phoneNumberFromJid(chat.remoteJid),\n\t\t\tname: chat.name || undefined,\n\t\t\tlabels: chat.labels || undefined,\n\t\t\tcreatedAt: chat.createdAt,\n\t\t\tupdatedAt: chat.updatedAt,\n\t\t\tpushName: chat.pushName || undefined,\n\t\t\tpictureUrl: chat.profilePicUrl || undefined,\n\t\t})),\n\t);\n\nexport type FindAllChatsResponse = z.infer<typeof FindAllChatsResponseSchema>;\n\nexport { FindAllChatsResponseSchema as ResponseSchema };\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"],"mappings":";AAAA,SAAS,SAAS;;;ACCX,IAAM,MAAM,CAAC,QAAgB;AAG7B,IAAM,WAAW,CAAC,QAAgB;AASlC,IAAM,SAAS,CAAC,OAAe;;;ACbtC,SAAS,wBAAwB;AAM1B,SAAS,mBAAmB,KAAa;AAC/C,SAAO,iBAAiB,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;AAClD;;;AFHO,IAAM,6BAA6B,EACxC;AAAA,EACA,EAAE,OAAO;AAAA,IACR,IAAI,EAAE,OAAO;AAAA,IACb,WAAW,EAAE,OAAO;AAAA,IACpB,MAAM,EAAE,OAAO,EAAE,QAAQ;AAAA,IACzB,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ;AAAA,IACpC,WAAW,EAAE,OAAO,KAAK;AAAA,IACzB,WAAW,EAAE,OAAO,KAAK;AAAA,IACzB,UAAU,EAAE,OAAO,EAAE,QAAQ;AAAA,IAC7B,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ;AAAA,EACzC,CAAC;AACF,EACC;AAAA,EAAU,CAAC,UACX,MAAM,IAAI,CAAC,UAAU;AAAA,IACpB,IAAI,OAAO,KAAK,EAAE;AAAA,IAClB,KAAK,KAAK,UAAU,SAAS,OAAO,IACjC,SAAS,KAAK,SAAS,IACvB,IAAI,KAAK,SAAS;AAAA,IACrB,aAAa,mBAAmB,KAAK,SAAS;AAAA,IAC9C,MAAM,KAAK,QAAQ;AAAA,IACnB,QAAQ,KAAK,UAAU;AAAA,IACvB,WAAW,KAAK;AAAA,IAChB,WAAW,KAAK;AAAA,IAChB,UAAU,KAAK,YAAY;AAAA,IAC3B,YAAY,KAAK,iBAAiB;AAAA,EACnC,EAAE;AACH;","names":[]}