{"version":3,"sources":["../../../src/api/routes.ts","../../../src/schemas/common.ts","../../../src/modules/chats/index.ts"],"sourcesContent":["export const Routes = {\n  Message: {\n    SendText: \"message/sendText\",\n    SendMedia: \"message/sendMedia\",\n    SendVoice: \"message/sendWhatsAppAudio\",\n    SendSticker: \"message/sendSticker\",\n    SendLocation: \"message/sendLocation\",\n    SendContact: \"message/sendContact\",\n    SendPoll: \"message/sendPoll\",\n    SendReaction: \"message/sendReaction\",\n    SendTemplate: \"message/sendTemplate\",\n    SendStatus: \"message/sendStatus\",\n    SendList: \"message/sendList\",\n  },\n  Chats: {\n    Check: \"chat/whatsappNumbers\",\n    FindAll: \"chat/findChats\",\n    SendPresence: \"chat/sendPresence\",\n    MarkAsRead: \"chat/markMessageAsRead\",\n    MarkAsUnread: \"chat/markChatUnread\",\n    Archive: \"chat/archive\",\n    DeleteMessage: \"chat/deleteMessageForEveryone\",\n    FetchProfilePicture: \"chat/fetchProfilePictureUrl\",\n    FindContacts: \"chat/findContacts\",\n    FindMessages: \"chat/findMessages\",\n    FindStatusMessage: \"chat/findStatusMessage\",\n    UpdateMessage: \"chat/updateMessage\",\n    GetBase64FromMediaMessage: \"chat/getBase64FromMediaMessage\",\n  },\n  Groups: {\n    FindAll: \"group/fetchAllGroups\",\n    FindByJid: \"group/findGroupInfos\",\n    FindByInviteCode: \"group/inviteInfo\",\n    Create: \"group/create\",\n    UpdatePicture: \"group/updateGroupPicture\",\n    UpdateSubject: \"group/updateGroupSubject\",\n    UpdateDescription: \"group/updateGroupDescription\",\n    FetchInviteCode: \"group/fetchInviteCode\",\n    AcceptInviteCode: \"group/acceptInviteCode\",\n    RevokeInviteCode: \"group/revokeInviteCode\",\n    SendGroupInvite: \"group/sendGroupInvite\",\n    FindMembers: \"group/findGroupMembers\",\n    UpdateMembers: \"group/updateGroupMembers\",\n    UpdateSetting: \"group/updateGroupSetting\",\n    ToggleEphemeral: \"group/toggleEphemeral\",\n    Leave: \"group/leaveGroup\",\n  },\n  Profile: {\n    FetchBusinessProfile: \"chat/fetchBusinessProfile\",\n    FetchProfile: \"chat/fetchProfile\",\n    UpdateName: \"chat/updateProfileName\",\n    UpdateStatus: \"chat/updateProfileStatus\",\n    UpdatePicture: \"chat/updateProfilePicture\",\n    RemovePicture: \"chat/removeProfilePicture\",\n    FetchPrivacySettings: \"chat/fetchPrivacySettings\",\n    UpdatePrivacySettings: \"chat/updatePrivacySettings\",\n  },\n  Webhook: {\n    Set: \"webhook/set\",\n    Find: \"webhook/find\",\n  },\n  Settings: {\n    Set: \"settings/set\",\n    Find: \"settings/find\",\n  },\n  Instance: {\n    Create: \"instance/create\",\n    FetchAll: \"instance/fetchInstances\",\n    Connect: \"instance/connect\",\n    Restart: \"instance/restart\",\n    ConnectionState: \"instance/connectionState\",\n    Logout: \"instance/logout\",\n    Delete: \"instance/delete\",\n    SetPresence: \"instance/setPresence\",\n  },\n};\n","// 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","import { Routes } from \"@/api/routes\";\nimport type { ApiService } from \"@/api/service\";\nimport { validateGroupJid, validateJid } from \"@/schemas/common\";\nimport type { MethodOptions } from \"@/types/api\";\n\nimport type * as Archive from \"./schemas/archive\";\nimport type * as Check from \"./schemas/check\";\nimport type * as DeleteMessage from \"./schemas/delete-message\";\nimport type * as FetchProfilePicture from \"./schemas/fetch-profile-picture\";\nimport type * as FindAll from \"./schemas/find-all\";\nimport type * as FindContacts from \"./schemas/find-contacts\";\nimport type * as FindMessages from \"./schemas/find-messages\";\nimport type * as FindStatusMessage from \"./schemas/find-status-message\";\nimport type * as GetBase64FromMediaMessage from \"./schemas/get-base64-from-media-message\";\nimport type * as MarkAsRead from \"./schemas/mark-as-read\";\nimport type * as MarkAsUnread from \"./schemas/mark-as-unread\";\nimport type * as Presence from \"./schemas/presence\";\nimport type * as UpdateMessage from \"./schemas/update-message\";\n\nexport class ChatsModule {\n  constructor(private readonly api: ApiService) {}\n\n  /**\n   * Checks if phone numbers are registered on WhatsApp\n   * @param numbers - Array of phone numbers to check\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async check(\n    numbers: Check.CheckOptions,\n    methodOptions?: MethodOptions\n  ): Promise<Check.CheckResponse> {\n    const body = {\n      numbers: Array.isArray(numbers) ? numbers : [numbers],\n    };\n    const response = await this.api.post(Routes.Chats.Check, {\n      body,\n      ...methodOptions,\n    });\n\n    return response as Check.CheckResponse;\n  }\n\n  /**\n   * Gets all chats\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async findAll(\n    methodOptions?: MethodOptions\n  ): Promise<FindAll.FindAllChatsResponse> {\n    const response = await this.api.post(Routes.Chats.FindAll, {\n      body: {},\n      ...methodOptions,\n    });\n\n    return response as FindAll.FindAllChatsResponse;\n  }\n\n  /**\n   * Updates presence status\n   * @param params - Presence parameters\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async updatePresence(\n    options: Presence.PresenceOptions,\n    methodOptions?: MethodOptions\n  ): Promise<void> {\n    if (!options.number) {\n      throw new Error(\"Number is required\");\n    }\n\n    if (!validateJid(options.number) && !validateGroupJid(options.number)) {\n      options.number = `${options.number}@s.whatsapp.net`;\n    }\n\n    await this.api.post(Routes.Chats.SendPresence, {\n      body: options,\n      ...methodOptions,\n    });\n  }\n\n  /**\n   * Marks messages as read\n   * @param options - Mark as read options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async markAsRead(\n    options: MarkAsRead.MarkAsReadRequest,\n    methodOptions?: MethodOptions\n  ): Promise<MarkAsRead.MarkAsReadResponse> {\n    const response = await this.api.post(Routes.Chats.MarkAsRead, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as MarkAsRead.MarkAsReadResponse;\n  }\n\n  /**\n   * Marks messages as unread\n   * @param options - Mark as unread options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async markAsUnread(\n    options: MarkAsUnread.MarkAsUnreadRequest,\n    methodOptions?: MethodOptions\n  ): Promise<MarkAsUnread.MarkAsUnreadResponse> {\n    const response = await this.api.post(Routes.Chats.MarkAsUnread, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as MarkAsUnread.MarkAsUnreadResponse;\n  }\n\n  /**\n   * Archives a chat\n   * @param options - Archive options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async archive(\n    options: Archive.ArchiveRequest,\n    methodOptions?: MethodOptions\n  ): Promise<Archive.ArchiveResponse> {\n    const response = await this.api.post(Routes.Chats.Archive, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as Archive.ArchiveResponse;\n  }\n\n  /**\n   * Deletes a message\n   * @param options - Delete message options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async deleteMessage(\n    options: DeleteMessage.DeleteMessageRequest,\n    methodOptions?: MethodOptions\n  ): Promise<DeleteMessage.DeleteMessageResponse> {\n    const response = await this.api.delete(Routes.Chats.DeleteMessage, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as DeleteMessage.DeleteMessageResponse;\n  }\n\n  /**\n   * Fetches profile picture\n   * @param options - Fetch profile picture options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async fetchProfilePicture(\n    options: FetchProfilePicture.FetchProfilePictureRequest,\n    methodOptions?: MethodOptions\n  ): Promise<FetchProfilePicture.FetchProfilePictureResponse> {\n    const response = await this.api.post(Routes.Chats.FetchProfilePicture, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as FetchProfilePicture.FetchProfilePictureResponse;\n  }\n\n  /**\n   * Finds contacts\n   * @param options - Find contacts options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async findContacts(\n    options: FindContacts.FindContactsRequest,\n    methodOptions?: MethodOptions\n  ): Promise<FindContacts.FindContactsResponse> {\n    const response = await this.api.post(Routes.Chats.FindContacts, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as FindContacts.FindContactsResponse;\n  }\n\n  /**\n   * Finds messages\n   * @param options - Find messages options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async findMessages(\n    options: FindMessages.FindMessagesRequest,\n    methodOptions?: MethodOptions\n  ): Promise<FindMessages.FindMessagesResponse> {\n    const response = await this.api.post(Routes.Chats.FindMessages, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as FindMessages.FindMessagesResponse;\n  }\n\n  /**\n   * Finds status messages\n   * @param options - Find status message options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async findStatusMessage(\n    options: FindStatusMessage.FindStatusMessageRequest,\n    methodOptions?: MethodOptions\n  ): Promise<FindStatusMessage.FindStatusMessageResponse> {\n    const response = await this.api.post(Routes.Chats.FindStatusMessage, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as FindStatusMessage.FindStatusMessageResponse;\n  }\n\n  /**\n   * Updates a message\n   * @param options - Update message options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async updateMessage(\n    options: UpdateMessage.UpdateMessageRequest,\n    methodOptions?: MethodOptions\n  ): Promise<UpdateMessage.UpdateMessageResponse> {\n    const response = await this.api.put(Routes.Chats.UpdateMessage, {\n      body: options,\n      ...methodOptions,\n    });\n\n    return response as UpdateMessage.UpdateMessageResponse;\n  }\n\n  /**\n   * Gets base64 representation of media from a message\n   * @param options - Get base64 from media message options\n   * @param methodOptions - Method-specific options (instance override)\n   */\n  async getBase64FromMediaMessage(\n    options: GetBase64FromMediaMessage.GetBase64FromMediaMessageRequest,\n    methodOptions?: MethodOptions\n  ): Promise<GetBase64FromMediaMessage.GetBase64FromMediaMessageResponse> {\n    const response = await this.api.post(\n      Routes.Chats.GetBase64FromMediaMessage,\n      {\n        body: options,\n        ...methodOptions,\n      }\n    );\n\n    return response as GetBase64FromMediaMessage.GetBase64FromMediaMessageResponse;\n  }\n}\n"],"mappings":";AAAO,IAAM,SAAS;AAAA,EACpB,SAAS;AAAA,IACP,UAAU;AAAA,IACV,WAAW;AAAA,IACX,WAAW;AAAA,IACX,aAAa;AAAA,IACb,cAAc;AAAA,IACd,aAAa;AAAA,IACb,UAAU;AAAA,IACV,cAAc;AAAA,IACd,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,SAAS;AAAA,IACT,eAAe;AAAA,IACf,qBAAqB;AAAA,IACrB,cAAc;AAAA,IACd,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,2BAA2B;AAAA,EAC7B;AAAA,EACA,QAAQ;AAAA,IACN,SAAS;AAAA,IACT,WAAW;AAAA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