@gymspace/evolution 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +1273 -0
  2. package/dist/index.d.mts +1790 -0
  3. package/dist/index.d.ts +1790 -0
  4. package/dist/index.js +1091 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +1077 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +63 -0
  9. package/src/api/errors.ts +220 -0
  10. package/src/api/routes.ts +76 -0
  11. package/src/api/service.ts +141 -0
  12. package/src/index.ts +89 -0
  13. package/src/modules/chats/index.ts +253 -0
  14. package/src/modules/chats/schemas/archive.ts +15 -0
  15. package/src/modules/chats/schemas/check.ts +20 -0
  16. package/src/modules/chats/schemas/delete-message.ts +16 -0
  17. package/src/modules/chats/schemas/fetch-profile-picture.ts +13 -0
  18. package/src/modules/chats/schemas/find-all.ts +49 -0
  19. package/src/modules/chats/schemas/find-contacts.ts +17 -0
  20. package/src/modules/chats/schemas/find-messages.ts +55 -0
  21. package/src/modules/chats/schemas/find-status-message.ts +11 -0
  22. package/src/modules/chats/schemas/get-base64-from-media-message.ts +20 -0
  23. package/src/modules/chats/schemas/index.ts +33 -0
  24. package/src/modules/chats/schemas/mark-as-read.ts +20 -0
  25. package/src/modules/chats/schemas/mark-as-unread.ts +17 -0
  26. package/src/modules/chats/schemas/presence.ts +41 -0
  27. package/src/modules/chats/schemas/update-message.ts +16 -0
  28. package/src/modules/groups/index.ts +246 -0
  29. package/src/modules/groups/schemas/accept-invite-code.ts +14 -0
  30. package/src/modules/groups/schemas/common.ts +89 -0
  31. package/src/modules/groups/schemas/create.ts +15 -0
  32. package/src/modules/groups/schemas/fetch-invite-code.ts +13 -0
  33. package/src/modules/groups/schemas/find-all.ts +26 -0
  34. package/src/modules/groups/schemas/find-by-invite-code.ts +39 -0
  35. package/src/modules/groups/schemas/find-by-jid.ts +14 -0
  36. package/src/modules/groups/schemas/find-members.ts +16 -0
  37. package/src/modules/groups/schemas/index.ts +24 -0
  38. package/src/modules/groups/schemas/leave.ts +14 -0
  39. package/src/modules/groups/schemas/revoke-invite-code.ts +14 -0
  40. package/src/modules/groups/schemas/send-group-invite.ts +15 -0
  41. package/src/modules/groups/schemas/toggle-ephemeral.ts +15 -0
  42. package/src/modules/groups/schemas/update-description.ts +15 -0
  43. package/src/modules/groups/schemas/update-members.ts +18 -0
  44. package/src/modules/groups/schemas/update-picture.ts +15 -0
  45. package/src/modules/groups/schemas/update-setting.ts +16 -0
  46. package/src/modules/groups/schemas/update-subject.ts +15 -0
  47. package/src/modules/index.ts +7 -0
  48. package/src/modules/instance/index.ts +126 -0
  49. package/src/modules/instance/schemas/connect.ts +14 -0
  50. package/src/modules/instance/schemas/connection-state.ts +16 -0
  51. package/src/modules/instance/schemas/create.ts +99 -0
  52. package/src/modules/instance/schemas/delete.ts +21 -0
  53. package/src/modules/instance/schemas/fetch-all.ts +57 -0
  54. package/src/modules/instance/schemas/index.ts +8 -0
  55. package/src/modules/instance/schemas/logout.ts +22 -0
  56. package/src/modules/instance/schemas/restart.ts +13 -0
  57. package/src/modules/instance/schemas/set-presence.ts +20 -0
  58. package/src/modules/messages/index.ts +246 -0
  59. package/src/modules/messages/schemas/audio.ts +12 -0
  60. package/src/modules/messages/schemas/base.ts +11 -0
  61. package/src/modules/messages/schemas/contact.ts +70 -0
  62. package/src/modules/messages/schemas/document.ts +12 -0
  63. package/src/modules/messages/schemas/image.ts +12 -0
  64. package/src/modules/messages/schemas/index.ts +31 -0
  65. package/src/modules/messages/schemas/list.ts +36 -0
  66. package/src/modules/messages/schemas/location.ts +76 -0
  67. package/src/modules/messages/schemas/media.ts +51 -0
  68. package/src/modules/messages/schemas/poll.ts +87 -0
  69. package/src/modules/messages/schemas/reaction.ts +21 -0
  70. package/src/modules/messages/schemas/status.ts +18 -0
  71. package/src/modules/messages/schemas/sticker.ts +77 -0
  72. package/src/modules/messages/schemas/template.ts +39 -0
  73. package/src/modules/messages/schemas/text.ts +88 -0
  74. package/src/modules/messages/schemas/video.ts +12 -0
  75. package/src/modules/messages/schemas/voice.ts +94 -0
  76. package/src/modules/profile/index.ts +110 -0
  77. package/src/modules/profile/schemas/fetch-business-profile.ts +29 -0
  78. package/src/modules/profile/schemas/fetch-privacy-settings.ts +11 -0
  79. package/src/modules/profile/schemas/fetch-profile.ts +23 -0
  80. package/src/modules/profile/schemas/index.ts +8 -0
  81. package/src/modules/profile/schemas/remove-picture.ts +4 -0
  82. package/src/modules/profile/schemas/update-name.ts +11 -0
  83. package/src/modules/profile/schemas/update-picture.ts +11 -0
  84. package/src/modules/profile/schemas/update-privacy-settings.ts +18 -0
  85. package/src/modules/profile/schemas/update-status.ts +11 -0
  86. package/src/modules/settings/index.ts +28 -0
  87. package/src/modules/settings/schemas/find.ts +11 -0
  88. package/src/modules/settings/schemas/index.ts +2 -0
  89. package/src/modules/settings/schemas/set.ts +18 -0
  90. package/src/modules/webhook/index.ts +28 -0
  91. package/src/modules/webhook/schemas/find.ts +7 -0
  92. package/src/modules/webhook/schemas/index.ts +2 -0
  93. package/src/modules/webhook/schemas/set.ts +16 -0
  94. package/src/schemas/client.ts +23 -0
  95. package/src/schemas/common.ts +44 -0
  96. package/src/types/api.ts +17 -0
  97. package/src/types/events.ts +53 -0
  98. package/src/types/messages.ts +5 -0
  99. package/src/types/tags.ts +14 -0
  100. package/src/types/webhooks.ts +255 -0
  101. package/src/utils/phone-numer-from-jid.ts +9 -0
@@ -0,0 +1,15 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import type { GroupJid, Jid } from "@/types/tags";
3
+
4
+ export interface SendGroupInviteRequest {
5
+ groupJid: GroupJid;
6
+ participantJid: Jid;
7
+ }
8
+
9
+ export interface SendGroupInviteResponse {
10
+ status: string;
11
+ message: string;
12
+ }
13
+
14
+ // Backward compatibility aliases
15
+ export type SendGroupInviteOptions = SendGroupInviteRequest;
@@ -0,0 +1,15 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import type { GroupJid } from "@/types/tags";
3
+
4
+ export interface ToggleEphemeralRequest {
5
+ groupJid: GroupJid;
6
+ duration: number;
7
+ }
8
+
9
+ export interface ToggleEphemeralResponse {
10
+ status: string;
11
+ message: string;
12
+ }
13
+
14
+ // Backward compatibility aliases
15
+ export type ToggleEphemeralOptions = ToggleEphemeralRequest;
@@ -0,0 +1,15 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import type { GroupJid } from "@/types/tags";
3
+
4
+ export interface UpdateDescriptionRequest {
5
+ groupJid: GroupJid;
6
+ description: string;
7
+ }
8
+
9
+ export interface UpdateDescriptionResponse {
10
+ status: string;
11
+ message: string;
12
+ }
13
+
14
+ // Backward compatibility aliases
15
+ export type UpdateDescriptionOptions = UpdateDescriptionRequest;
@@ -0,0 +1,18 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import type { GroupJid, Jid } from "@/types/tags";
3
+
4
+ export interface UpdateMembersRequest {
5
+ groupJid: GroupJid;
6
+ participants: Jid[];
7
+ action: "add" | "remove" | "promote" | "demote";
8
+ }
9
+
10
+ export interface Participant {
11
+ id: Jid;
12
+ status: string;
13
+ }
14
+
15
+ export type UpdateMembersResponse = Participant[];
16
+
17
+ // Backward compatibility aliases
18
+ export type UpdateMembersOptions = UpdateMembersRequest;
@@ -0,0 +1,15 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import type { GroupJid } from "@/types/tags";
3
+
4
+ export interface UpdatePictureRequest {
5
+ groupJid: GroupJid;
6
+ url: string;
7
+ }
8
+
9
+ export interface UpdatePictureResponse {
10
+ status: string;
11
+ message: string;
12
+ }
13
+
14
+ // Backward compatibility aliases
15
+ export type UpdatePictureOptions = UpdatePictureRequest;
@@ -0,0 +1,16 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import type { GroupJid } from "@/types/tags";
3
+
4
+ export interface UpdateSettingRequest {
5
+ groupJid: GroupJid;
6
+ setting: "announcement" | "locked";
7
+ value: boolean;
8
+ }
9
+
10
+ export interface UpdateSettingResponse {
11
+ status: string;
12
+ message: string;
13
+ }
14
+
15
+ // Backward compatibility aliases
16
+ export type UpdateSettingOptions = UpdateSettingRequest;
@@ -0,0 +1,15 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import type { GroupJid } from "@/types/tags";
3
+
4
+ export interface UpdateSubjectRequest {
5
+ groupJid: GroupJid;
6
+ subject: string;
7
+ }
8
+
9
+ export interface UpdateSubjectResponse {
10
+ status: string;
11
+ message: string;
12
+ }
13
+
14
+ // Backward compatibility aliases
15
+ export type UpdateSubjectOptions = UpdateSubjectRequest;
@@ -0,0 +1,7 @@
1
+ export * from "./chats";
2
+ export * from "./groups";
3
+ export * from "./instance";
4
+ export * from "./messages";
5
+ export * from "./profile";
6
+ export * from "./settings";
7
+ export * from "./webhook";
@@ -0,0 +1,126 @@
1
+ import { Routes } from "@/api/routes";
2
+ import type { ApiService } from "@/api/service";
3
+
4
+ import type * as Connect from "./schemas/connect";
5
+ import type * as ConnectionState from "./schemas/connection-state";
6
+ import type * as Create from "./schemas/create";
7
+ import type * as Delete from "./schemas/delete";
8
+ import type * as FetchAll from "./schemas/fetch-all";
9
+ import type * as Logout from "./schemas/logout";
10
+ import type * as Restart from "./schemas/restart";
11
+ import type * as SetPresence from "./schemas/set-presence";
12
+
13
+ import type { MethodOptions } from "@/types/api";
14
+
15
+ export class InstanceModule {
16
+ constructor(private readonly api: ApiService) {}
17
+
18
+ async create(
19
+ options: Create.CreateInstanceRequest
20
+ ): Promise<Create.CreateInstanceResponse> {
21
+ const response = await this.api.post(Routes.Instance.Create, {
22
+ body: options,
23
+ isInstanceUrl: false,
24
+ });
25
+ return response as Create.CreateInstanceResponse;
26
+ }
27
+
28
+ async connect(
29
+ options: Connect.ConnectRequest,
30
+ methodOptions?: MethodOptions
31
+ ): Promise<Connect.ConnectResponse> {
32
+ const { instanceName } = options;
33
+ const instance = methodOptions?.instance ?? instanceName;
34
+ if (!instance) {
35
+ throw new Error("Instance name is required");
36
+ }
37
+ const response = await this.api.get(Routes.Instance.Connect, {
38
+ instance,
39
+ isInstanceUrl: true,
40
+ });
41
+ return response as Connect.ConnectResponse;
42
+ }
43
+
44
+ async connectionState(
45
+ options: ConnectionState.ConnectionStateRequest,
46
+ methodOptions?: MethodOptions
47
+ ): Promise<ConnectionState.ConnectionStateResponse> {
48
+ const { instanceName } = options;
49
+ const instance = methodOptions?.instance ?? instanceName;
50
+ if (!instance) {
51
+ throw new Error("Instance name is required");
52
+ }
53
+ const response = await this.api.get(Routes.Instance.ConnectionState, {
54
+ instance,
55
+ isInstanceUrl: true,
56
+ });
57
+ return response as ConnectionState.ConnectionStateResponse;
58
+ }
59
+
60
+ async logout(
61
+ options: Logout.LogoutRequest,
62
+ methodOptions?: MethodOptions
63
+ ): Promise<Logout.LogoutResponse> {
64
+ const { instanceName } = options;
65
+ const instance = methodOptions?.instance ?? instanceName;
66
+ if (!instance) {
67
+ throw new Error("Instance name is required");
68
+ }
69
+ const response = await this.api.delete(Routes.Instance.Logout, {
70
+ instance,
71
+ isInstanceUrl: true,
72
+ });
73
+ return response as Logout.LogoutResponse;
74
+ }
75
+
76
+ async delete(options: Delete.DeleteRequest): Promise<Delete.DeleteResponse> {
77
+ const response = await this.api.delete(Routes.Instance.Delete, {
78
+ instance: options.instanceName,
79
+ isInstanceUrl: true,
80
+ });
81
+ return response as Delete.DeleteResponse;
82
+ }
83
+
84
+ async restart(
85
+ options: Restart.RestartRequest,
86
+ methodOptions?: MethodOptions
87
+ ): Promise<Restart.RestartResponse> {
88
+ const { instanceName } = options;
89
+ const instance = methodOptions?.instance ?? instanceName;
90
+ if (!instance) {
91
+ throw new Error("Instance name is required");
92
+ }
93
+ const response = await this.api.post(Routes.Instance.Restart, {
94
+ instance,
95
+ isInstanceUrl: true,
96
+ });
97
+ return response as Restart.RestartResponse;
98
+ }
99
+
100
+ async fetchAll(
101
+ options?: FetchAll.FetchAllRequest
102
+ ): Promise<FetchAll.FetchAllResponse> {
103
+ const response = await this.api.get(Routes.Instance.FetchAll, {
104
+ params: options,
105
+ isInstanceUrl: false,
106
+ });
107
+ return response as FetchAll.FetchAllResponse;
108
+ }
109
+
110
+ async setPresence(
111
+ options: SetPresence.SetPresenceRequest,
112
+ methodOptions?: MethodOptions
113
+ ): Promise<SetPresence.SetPresenceResponse> {
114
+ const { instanceName, ...rest } = options;
115
+ const instance = methodOptions?.instance ?? instanceName;
116
+ if (!instance) {
117
+ throw new Error("Instance name is required");
118
+ }
119
+ const response = await this.api.post(Routes.Instance.SetPresence, {
120
+ body: rest,
121
+ instance,
122
+ isInstanceUrl: true,
123
+ });
124
+ return response as SetPresence.SetPresenceResponse;
125
+ }
126
+ }
@@ -0,0 +1,14 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ export interface ConnectRequest {
3
+ instanceName: string;
4
+ }
5
+
6
+ export interface ConnectResponse {
7
+ pairingCode: string | null;
8
+ code: string;
9
+ base64: string;
10
+ count: number;
11
+ }
12
+
13
+ // Backward compatibility aliases
14
+ export type ConnectOptions = ConnectRequest;
@@ -0,0 +1,16 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+ import { ConnectionState } from "@/types/webhooks";
3
+
4
+ export interface ConnectionStateRequest {
5
+ instanceName: string;
6
+ }
7
+
8
+ export interface ConnectionStateResponse {
9
+ instance: {
10
+ instanceName: string;
11
+ state: ConnectionState;
12
+ };
13
+ }
14
+
15
+ // Backward compatibility aliases
16
+ export type ConnectionStateOptions = ConnectionStateRequest;
@@ -0,0 +1,99 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+
3
+ export interface WebhookConfig {
4
+ url?: string;
5
+ byEvents?: boolean;
6
+ base64?: boolean;
7
+ headers?: Record<string, string>;
8
+ events?: string[];
9
+ }
10
+
11
+ export interface RabbitMQConfig {
12
+ enabled?: boolean;
13
+ events?: string[];
14
+ }
15
+
16
+ export interface SQSConfig {
17
+ enabled?: boolean;
18
+ events?: string[];
19
+ }
20
+
21
+ export interface CreateInstanceRequest {
22
+ instanceName: string;
23
+ token?: string;
24
+ qrcode?: boolean;
25
+ number?: string;
26
+ integration?: string;
27
+
28
+ // Call settings
29
+ rejectCall?: boolean;
30
+ msgCall?: string;
31
+
32
+ // Group and status settings
33
+ groupsIgnore?: boolean;
34
+ alwaysOnline?: boolean;
35
+ readMessages?: boolean;
36
+ readStatus?: boolean;
37
+ syncFullHistory?: boolean;
38
+
39
+ // Proxy settings (flat fields)
40
+ proxyHost?: string;
41
+ proxyPort?: string;
42
+ proxyProtocol?: "http" | "https";
43
+ proxyUsername?: string;
44
+ proxyPassword?: string;
45
+
46
+ // Webhook settings (nested object)
47
+ webhook?: WebhookConfig;
48
+
49
+ // RabbitMQ settings (nested object)
50
+ rabbitmq?: RabbitMQConfig;
51
+
52
+ // SQS settings (nested object)
53
+ sqs?: SQSConfig;
54
+
55
+ // Chatwoot settings
56
+ chatwootAccountId?: number;
57
+ chatwootToken?: string;
58
+ chatwootUrl?: string;
59
+ chatwootSignMsg?: boolean;
60
+ chatwootReopenConversation?: boolean;
61
+ chatwootConversationPending?: boolean;
62
+ chatwootImportContacts?: boolean;
63
+ chatwootNameInbox?: string;
64
+ chatwootMergeBrazilContacts?: boolean;
65
+ chatwootImportMessages?: boolean;
66
+ chatwootDaysLimitImportMessages?: number;
67
+ chatwootOrganization?: string;
68
+ chatwootLogo?: string;
69
+ }
70
+
71
+ export interface InstanceInfo {
72
+ instanceName: string;
73
+ instanceId: string;
74
+ webhook_wa_business?: string | null;
75
+ access_token_wa_business?: string;
76
+ status: string;
77
+ }
78
+
79
+ export interface InstanceSettings {
80
+ rejectCall?: boolean;
81
+ msgCall?: string;
82
+ groupsIgnore?: boolean;
83
+ alwaysOnline?: boolean;
84
+ readMessages?: boolean;
85
+ readStatus?: boolean;
86
+ syncFullHistory?: boolean;
87
+ }
88
+
89
+ export interface QRCodeInfo {
90
+ code: string;
91
+ base64: string;
92
+ }
93
+
94
+ export interface CreateInstanceResponse {
95
+ instance: InstanceInfo;
96
+ hash: string; // API returns a string, not an object
97
+ settings?: InstanceSettings; // Settings might not always be present
98
+ qrcode?: QRCodeInfo;
99
+ }
@@ -0,0 +1,21 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+
3
+ export interface DeleteRequest {
4
+ instanceName: string;
5
+ }
6
+
7
+ export interface DeleteInstanceInfo {
8
+ instanceName: string;
9
+ status: string;
10
+ }
11
+
12
+ export interface DeleteResponse {
13
+ status: "SUCCESS" | "ERROR";
14
+ error: boolean;
15
+ response: {
16
+ message: string;
17
+ };
18
+ }
19
+
20
+ // Backward compatibility aliases
21
+ export type DeleteOptions = DeleteRequest;
@@ -0,0 +1,57 @@
1
+ import { Jid } from "@/types/tags";
2
+ import { ConnectionState } from "@/types/webhooks";
3
+
4
+ export interface Setting {
5
+ id: string;
6
+ rejectCall: boolean;
7
+ msgCall: string;
8
+ groupsIgnore: boolean;
9
+ alwaysOnline: boolean;
10
+ readMessages: boolean;
11
+ readStatus: boolean;
12
+ syncFullHistory: boolean;
13
+ wavoipToken: string;
14
+ createdAt: string;
15
+ updatedAt: string;
16
+ instanceId: string;
17
+ }
18
+
19
+ export interface Count {
20
+ Message: number;
21
+ Contact: number;
22
+ Chat: number;
23
+ }
24
+
25
+ export interface InstanceDetails {
26
+ id: string;
27
+ name: string;
28
+ connectionStatus: ConnectionState;
29
+ ownerJid: Jid;
30
+ profileName: string;
31
+ profilePicUrl: string | null;
32
+ profileStatus?: string;
33
+ integration: string;
34
+ number: string | null;
35
+ businessId: string | null;
36
+ token: string;
37
+ clientName: string;
38
+ disconnectionReasonCode: string | number | null;
39
+ disconnectionObject: unknown | null;
40
+ disconnectionAt: string | null;
41
+ createdAt: string;
42
+ updatedAt: string;
43
+ Chatwoot: unknown | null;
44
+ Proxy: unknown | null;
45
+ Rabbitmq: unknown | null;
46
+ Nats: unknown | null;
47
+ Sqs: unknown | null;
48
+ Websocket: unknown | null;
49
+ Setting: Setting | null;
50
+ _count: Count;
51
+ }
52
+
53
+ export type FetchAllResponse = InstanceDetails[];
54
+
55
+ export interface FetchAllRequest {
56
+ instanceName?: string;
57
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./connect";
2
+ export * from "./connection-state";
3
+ export * from "./create";
4
+ export * from "./delete";
5
+ export * from "./fetch-all";
6
+ export * from "./logout";
7
+ export * from "./restart";
8
+ export * from "./set-presence";
@@ -0,0 +1,22 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+
3
+ export interface LogoutRequest {
4
+ instanceName: string;
5
+ }
6
+
7
+ export interface LogoutInstanceInfo {
8
+ instanceName: string;
9
+ status: string;
10
+ }
11
+
12
+ export interface LogoutResponse {
13
+ status: "SUCCESS" | "ERROR";
14
+ error: boolean;
15
+ response: {
16
+ message: string;
17
+ };
18
+ instance: LogoutInstanceInfo;
19
+ }
20
+
21
+ // Backward compatibility aliases
22
+ export type LogoutOptions = LogoutRequest;
@@ -0,0 +1,13 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+
3
+ export interface RestartRequest {
4
+ instanceName: string;
5
+ }
6
+
7
+ export interface RestartResponse {
8
+ success: boolean;
9
+ message: string;
10
+ }
11
+
12
+ // Backward compatibility aliases
13
+ export type RestartOptions = RestartRequest;
@@ -0,0 +1,20 @@
1
+ // Pure TypeScript interfaces for better IDE support and performance
2
+
3
+ export interface SetPresenceRequest {
4
+ instanceName?: string;
5
+ presence: "unavailable" | "available";
6
+ }
7
+
8
+ export interface SetPresenceData {
9
+ instance: string;
10
+ presence: string;
11
+ }
12
+
13
+ export interface SetPresenceResponse {
14
+ error: boolean;
15
+ message: string;
16
+ data: SetPresenceData;
17
+ }
18
+
19
+ // Backward compatibility aliases
20
+ export type SetPresenceOptions = SetPresenceRequest;