@open-wa/schema 5.0.0-alpha.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 (54) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.md +67 -0
  3. package/README.md +19 -0
  4. package/client_migration_doc.md +467 -0
  5. package/codecs_and_params_plan.md +936 -0
  6. package/migration_plan_doc.md +223 -0
  7. package/package.json +90 -0
  8. package/scripts/gen-client-implementation.ts +129 -0
  9. package/scripts/gen-client-reference-docs.ts +621 -0
  10. package/scripts/gen-openapi.ts +96 -0
  11. package/scripts/gen-types.ts +43 -0
  12. package/scripts/verify-v5-pipeline.ts +85 -0
  13. package/src/__tests__/generators.contract.test.ts +181 -0
  14. package/src/__tests__/registry.contract.test.ts +81 -0
  15. package/src/client-config.ts +30 -0
  16. package/src/codecs.test.ts +41 -0
  17. package/src/codecs.ts +191 -0
  18. package/src/common-types.ts +280 -0
  19. package/src/config.ts +47 -0
  20. package/src/enums.ts +63 -0
  21. package/src/events/groups.ts +33 -0
  22. package/src/events/index.ts +4 -0
  23. package/src/events/messaging.ts +72 -0
  24. package/src/events/registry.ts +114 -0
  25. package/src/events/state.ts +59 -0
  26. package/src/generated/AliasMap.ts +214 -0
  27. package/src/generated/BaseClient.ts +868 -0
  28. package/src/generated/BaseNamespacedClient.ts +212 -0
  29. package/src/generated/index.ts +5 -0
  30. package/src/generated/openapi.json +7799 -0
  31. package/src/generated/types.ts +377 -0
  32. package/src/http-manifest.ts +97 -0
  33. package/src/implementor.test.ts +88 -0
  34. package/src/implementor.ts +75 -0
  35. package/src/index.ts +43 -0
  36. package/src/methods/business.ts +51 -0
  37. package/src/methods/chats.ts +263 -0
  38. package/src/methods/communities.ts +119 -0
  39. package/src/methods/contacts.ts +158 -0
  40. package/src/methods/groups.ts +376 -0
  41. package/src/methods/index.ts +33 -0
  42. package/src/methods/labels.ts +86 -0
  43. package/src/methods/media.ts +36 -0
  44. package/src/methods/messaging.ts +828 -0
  45. package/src/methods/session.ts +261 -0
  46. package/src/methods/status.ts +120 -0
  47. package/src/open-wa-utils.d.ts +4 -0
  48. package/src/parameters.ts +237 -0
  49. package/src/registry.test.ts +30 -0
  50. package/src/registry.ts +601 -0
  51. package/tsconfig.generated.json +11 -0
  52. package/tsconfig.json +15 -0
  53. package/tsdown.config.ts +16 -0
  54. package/vitest.config.ts +10 -0
@@ -0,0 +1,114 @@
1
+ import { z } from 'zod';
2
+ import { Options as PQueueOptions, DefaultAddOptions } from 'p-queue';
3
+ import PriorityQueue from 'p-queue/dist/priority-queue';
4
+ import { LicenseTier } from '../enums';
5
+
6
+ export type EventStatus = 'stable' | 'beta' | 'deprecated' | 'experimental';
7
+
8
+ export interface EventMetadata {
9
+ eventName: string;
10
+ legacyName: string;
11
+ description?: string;
12
+ namespace?: string;
13
+ status?: EventStatus;
14
+ deprecated?: string;
15
+ license?: LicenseTier;
16
+ since?: string;
17
+ payloadSchema: z.ZodTypeAny;
18
+ defaultQueueOptions?: PQueueOptions<PriorityQueue, DefaultAddOptions>;
19
+ }
20
+
21
+ export interface EventDefinition {
22
+ callbackSchema: z.ZodFunction<any, any>;
23
+ meta: EventMetadata;
24
+ }
25
+
26
+ const eventsByName = new Map<string, EventDefinition>();
27
+ const nameByCallback = new WeakMap<z.ZodFunction<any, any>, string>();
28
+
29
+ export const eventRegistry = {
30
+ register(def: EventDefinition): z.ZodFunction<any, any> {
31
+ const name = def.meta.eventName;
32
+
33
+ if (eventsByName.has(name)) {
34
+ throw new Error(`Event "${name}" already registered`);
35
+ }
36
+
37
+ eventsByName.set(name, def);
38
+ nameByCallback.set(def.callbackSchema, name);
39
+
40
+ return def.callbackSchema;
41
+ },
42
+
43
+ get(name: string): EventDefinition | undefined {
44
+ return eventsByName.get(name);
45
+ },
46
+
47
+ getByLegacyName(legacyName: string): EventDefinition | undefined {
48
+ for (const def of eventsByName.values()) {
49
+ if (def.meta.legacyName === legacyName) return def;
50
+ }
51
+ return undefined;
52
+ },
53
+
54
+ has(name: string): boolean {
55
+ return eventsByName.has(name);
56
+ },
57
+
58
+ getAll(): EventDefinition[] {
59
+ return Array.from(eventsByName.values());
60
+ },
61
+
62
+ getByNamespace(namespace: string): EventDefinition[] {
63
+ return this.getAll().filter(def => def.meta.namespace === namespace);
64
+ },
65
+
66
+ clear(): void {
67
+ eventsByName.clear();
68
+ }
69
+ };
70
+
71
+ export const QueueOptionsSchema = z.object({
72
+ concurrency: z.number().positive().optional(),
73
+ intervalCap: z.number().positive().optional(),
74
+ interval: z.number().positive().optional(),
75
+ timeout: z.number().positive().optional(),
76
+ priority: z.number().optional(),
77
+ }).optional();
78
+
79
+ export type QueueOptions = z.infer<typeof QueueOptionsSchema>;
80
+
81
+ export function defineListenerV2<T extends z.ZodTypeAny>(
82
+ name: string,
83
+ params: {
84
+ legacyName?: string;
85
+ meta: Omit<EventMetadata, 'eventName' | 'legacyName' | 'payloadSchema'>;
86
+ payload: T;
87
+ defaultQueueOptions?: PQueueOptions<PriorityQueue, DefaultAddOptions>;
88
+ }
89
+ ): z.ZodFunction<any, any> {
90
+
91
+ const legacyName = params.legacyName || `on${name.charAt(0).toUpperCase()}${name.slice(1)}`;
92
+
93
+ const callbackSchema = z.function({
94
+ input: z.tuple([params.payload, QueueOptionsSchema]),
95
+ output: z.union([
96
+ z.boolean(),
97
+ z.promise(z.boolean()),
98
+ z.function({ input: z.tuple([]), output: z.void() }),
99
+ ])
100
+ });
101
+
102
+ eventRegistry.register({
103
+ callbackSchema,
104
+ meta: {
105
+ eventName: name,
106
+ legacyName,
107
+ payloadSchema: params.payload,
108
+ defaultQueueOptions: params.defaultQueueOptions,
109
+ ...params.meta
110
+ }
111
+ });
112
+
113
+ return callbackSchema as any;
114
+ }
@@ -0,0 +1,59 @@
1
+ import { z } from 'zod';
2
+ import { defineListenerV2 } from './registry';
3
+
4
+ export const StateEnum = z.enum([
5
+ 'STARTING',
6
+ 'AUTHENTICATING',
7
+ 'READY',
8
+ 'STOPPED',
9
+ 'CONNECTED',
10
+ 'DISCONNECTED',
11
+ 'SYNCING',
12
+ 'CONFLICT',
13
+ 'UNLAUNCHED',
14
+ 'PAIRING',
15
+ 'TIMEOUT',
16
+ ]);
17
+
18
+ export const stateChangedEvent = defineListenerV2('stateChanged', {
19
+ legacyName: 'onStateChanged',
20
+ meta: {
21
+ description: 'Fired when connection state changes',
22
+ namespace: 'state',
23
+ status: 'stable',
24
+ license: 'none',
25
+ },
26
+ payload: z.object({
27
+ state: StateEnum,
28
+ previousState: StateEnum.optional(),
29
+ }),
30
+ });
31
+
32
+ export const chatStateEvent = defineListenerV2('chatState', {
33
+ legacyName: 'onChatState',
34
+ meta: {
35
+ description: 'Fired when someone is typing or recording',
36
+ namespace: 'state',
37
+ status: 'stable',
38
+ license: 'none',
39
+ },
40
+ payload: z.object({
41
+ chatId: z.string(),
42
+ state: z.enum(['typing', 'recording', 'paused']),
43
+ senderId: z.string(),
44
+ }),
45
+ });
46
+
47
+ export const logoutEvent = defineListenerV2('logout', {
48
+ legacyName: 'onLogout',
49
+ meta: {
50
+ description: 'Fired when the session is logged out',
51
+ namespace: 'state',
52
+ status: 'stable',
53
+ license: 'none',
54
+ },
55
+ payload: z.object({
56
+ reason: z.string().optional(),
57
+ timestamp: z.number(),
58
+ }),
59
+ });
@@ -0,0 +1,214 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * This file was automatically generated by packages/schema/scripts/gen-client-implementation.ts
4
+ * Do not edit this file manually.
5
+ */
6
+ export const clientMethodAliasMap = {
7
+ "messages.sendText": "sendText",
8
+ "messages.sendTextWithMentions": "sendTextWithMentions",
9
+ "messages.sendReplyWithMentions": "sendReplyWithMentions",
10
+ "messages.sendPaymentRequest": "sendPaymentRequest",
11
+ "messages.sendImage": "sendImage",
12
+ "messages.sendFile": "sendFile",
13
+ "messages.sendAudio": "sendAudio",
14
+ "sendVoiceNote": "sendPtt",
15
+ "messages.sendPtt": "sendPtt",
16
+ "messages.sendVoiceNote": "sendPtt",
17
+ "messages.sendVideoAsGif": "sendVideoAsGif",
18
+ "messages.sendLocation": "sendLocation",
19
+ "messages.sendVCard": "sendVCard",
20
+ "messages.sendContact": "sendContact",
21
+ "sendContacts": "sendMultipleContacts",
22
+ "messages.sendContacts": "sendMultipleContacts",
23
+ "messages.sendMultipleContacts": "sendMultipleContacts",
24
+ "messages.sendButtons": "sendButtons",
25
+ "messages.sendAdvancedButtons": "sendAdvancedButtons",
26
+ "sendList": "sendListMessage",
27
+ "messages.sendList": "sendListMessage",
28
+ "messages.sendPoll": "sendPoll",
29
+ "messages.sendBanner": "sendBanner",
30
+ "sendYoutubeLink": "sendYouTubeLink",
31
+ "messages.sendYouTubeLink": "sendYouTubeLink",
32
+ "messages.sendYoutubeLink": "sendYouTubeLink",
33
+ "sendLink": "sendLinkWithAutoPreview",
34
+ "messages.sendLinkWithAutoPreview": "sendLinkWithAutoPreview",
35
+ "messages.sendLink": "sendLinkWithAutoPreview",
36
+ "sendLinkWithThumbnail": "sendMessageWithThumb",
37
+ "messages.sendLinkWithThumbnail": "sendMessageWithThumb",
38
+ "messages.sendWithThumb": "sendMessageWithThumb",
39
+ "messages.forward": "forwardMessages",
40
+ "messages.delete": "deleteMessage",
41
+ "getMessage": "getMessageById",
42
+ "messages.get": "getMessageById",
43
+ "messages.getById": "getMessageById",
44
+ "listMessages": "getAllMessages",
45
+ "messages.getAll": "getAllMessages",
46
+ "messages.all": "getAllMessages",
47
+ "messages.list": "getAllMessages",
48
+ "messages.getMyLast": "getMyLastMessage",
49
+ "messages.getStarred": "getStarredMessages",
50
+ "messages.getUnsent": "getUnsentMessages",
51
+ "messages.getInfo": "getMessageInfo",
52
+ "messages.getVCards": "getVCards",
53
+ "getGptArray": "getMessagesForLLM",
54
+ "messages.getForLLM": "getMessagesForLLM",
55
+ "messages.getGptArray": "getMessagesForLLM",
56
+ "messages.star": "starMessage",
57
+ "messages.unstar": "unstarMessage",
58
+ "messages.react": "react",
59
+ "messages.sendSeen": "sendSeen",
60
+ "loadOlderMessages": "loadEarlierMessages",
61
+ "messages.loadEarlier": "loadEarlierMessages",
62
+ "messages.loadOlder": "loadEarlierMessages",
63
+ "messages.sendFileFromUrl": "sendFileFromUrl",
64
+ "listChats": "getAllChats",
65
+ "chats.getAll": "getAllChats",
66
+ "chats.all": "getAllChats",
67
+ "chats.list": "getAllChats",
68
+ "chats.ids": "getAllChatIds",
69
+ "listChatIds": "getAllChatIds",
70
+ "chatIds.getAll": "getAllChatIds",
71
+ "chatIds.all": "getAllChatIds",
72
+ "chatIds.list": "getAllChatIds",
73
+ "getChatById": "getChat",
74
+ "chats.get": "getChat",
75
+ "chats.getById": "getChat",
76
+ "chats.getWithNonContacts": "getChatWithNonContacts",
77
+ "chats.archive": "archiveChat",
78
+ "chats.unarchive": "unarchiveChat",
79
+ "chats.clear": "clearChat",
80
+ "chats.delete": "deleteChat",
81
+ "chats.pin": "pinChat",
82
+ "chats.unpin": "unpinChat",
83
+ "chats.mute": "muteChat",
84
+ "chats.unmute": "unmuteChat",
85
+ "chats.markAsRead": "markAsRead",
86
+ "chats.markAsUnread": "markAsUnread",
87
+ "chats.setEphemeral": "setChatEphemeral",
88
+ "chats.isOnline": "isChatOnline",
89
+ "listContacts": "getAllContacts",
90
+ "contacts.getAll": "getAllContacts",
91
+ "contacts.all": "getAllContacts",
92
+ "contacts.list": "getAllContacts",
93
+ "contacts.get": "getContact",
94
+ "contacts.getCommonGroups": "getCommonGroups",
95
+ "contacts.getNumberProfile": "getNumberProfile",
96
+ "contacts.getBlockedIds": "getBlockedIds",
97
+ "contactBlock": "blockContact",
98
+ "contacts.block": "blockContact",
99
+ "contacts.contactBlock": "blockContact",
100
+ "contactUnblock": "unblockContact",
101
+ "contacts.unblock": "unblockContact",
102
+ "contacts.contactUnblock": "unblockContact",
103
+ "getReadReceipts": "checkReadReceipts",
104
+ "contacts.checkReadReceipts": "checkReadReceipts",
105
+ "contacts.getReadReceipts": "checkReadReceipts",
106
+ "contacts.checkNumberStatus": "checkNumberStatus",
107
+ "getProfilePicFromServer": "getProfilePicture",
108
+ "contacts.getProfilePicture": "getProfilePicture",
109
+ "contacts.getProfilePicFromServer": "getProfilePicture",
110
+ "groups.getMembers": "getGroupMembers",
111
+ "listGroups": "getAllGroups",
112
+ "groups.getAll": "getAllGroups",
113
+ "groups.all": "getAllGroups",
114
+ "groups.list": "getAllGroups",
115
+ "getGroupMemberIds": "getGroupMembersId",
116
+ "groups.getMemberIds": "getGroupMembersId",
117
+ "groups.getMembersId": "getGroupMembersId",
118
+ "groups.getInfo": "getGroupInfo",
119
+ "groups.getAdmins": "getGroupAdmins",
120
+ "groups.getKicked": "getKickedGroups",
121
+ "groups.getInviteLink": "getGroupInviteLink",
122
+ "groups.create": "createGroup",
123
+ "groups.leave": "leaveGroup",
124
+ "joinGroup": "joinGroupViaLink",
125
+ "groups.join": "joinGroupViaLink",
126
+ "groups.joinViaLink": "joinGroupViaLink",
127
+ "groups.revokeInviteLink": "revokeGroupInviteLink",
128
+ "groups.setTitle": "setGroupTitle",
129
+ "groups.setDescription": "setGroupDescription",
130
+ "groups.setIcon": "setGroupIcon",
131
+ "groups.setAdminsOnly": "setGroupToAdminsOnly",
132
+ "groups.setToAdminsOnly": "setGroupToAdminsOnly",
133
+ "groups.setEditAdminsOnly": "setGroupEditToAdminsOnly",
134
+ "groups.setEditToAdminsOnly": "setGroupEditToAdminsOnly",
135
+ "addGroupParticipant": "addParticipant",
136
+ "groups.addParticipant": "addParticipant",
137
+ "removeGroupParticipant": "removeParticipant",
138
+ "groups.removeParticipant": "removeParticipant",
139
+ "promoteGroupParticipant": "promoteParticipant",
140
+ "groups.promoteParticipant": "promoteParticipant",
141
+ "demoteGroupParticipant": "demoteParticipant",
142
+ "groups.demoteParticipant": "demoteParticipant",
143
+ "groups.approveJoinRequest": "approveGroupJoinRequest",
144
+ "groups.rejectJoinRequest": "rejectGroupJoinRequest",
145
+ "listCommunities": "getAllCommunities",
146
+ "communities.getAll": "getAllCommunities",
147
+ "communities.all": "getAllCommunities",
148
+ "communities.list": "getAllCommunities",
149
+ "communities.getInfo": "getCommunityInfo",
150
+ "communities.getParticipantIds": "getCommunityParticipantIds",
151
+ "communities.getAdminIds": "getCommunityAdminIds",
152
+ "communities.getParticipants": "getCommunityParticipants",
153
+ "communities.getAdmins": "getCommunityAdmins",
154
+ "status.postText": "postTextStatus",
155
+ "status.postImage": "postImageStatus",
156
+ "status.postVideo": "postVideoStatus",
157
+ "getStatuses": "getStories",
158
+ "status.getAll": "getStories",
159
+ "status.getStories": "getStories",
160
+ "status.get": "getStories",
161
+ "mystatus.getStatus": "getStatus",
162
+ "status.delete": "deleteStatus",
163
+ "deleteAllStatuses": "deleteAllStatus",
164
+ "status.deleteAll": "deleteAllStatus",
165
+ "listLabels": "getAllLabels",
166
+ "labels.getAll": "getAllLabels",
167
+ "labels.all": "getAllLabels",
168
+ "labels.list": "getAllLabels",
169
+ "labels.getChats": "getChatsByLabel",
170
+ "labels.getChatsBy": "getChatsByLabel",
171
+ "labels.add": "addLabel",
172
+ "labels.remove": "removeLabel",
173
+ "business.getProfile": "getBusinessProfile",
174
+ "getBusinessProfilesProducts": "getBusinessProducts",
175
+ "business.getProducts": "getBusinessProducts",
176
+ "business.getProfilesProducts": "getBusinessProducts",
177
+ "business.getOrder": "getOrder",
178
+ "session.getMe": "getMe",
179
+ "session.getHostNumber": "getHostNumber",
180
+ "session.getConnectionState": "getConnectionState",
181
+ "getWhatsAppVersion": "getWAVersion",
182
+ "session.getWAVersion": "getWAVersion",
183
+ "session.getWhatsAppVersion": "getWAVersion",
184
+ "session.getBatteryLevel": "getBatteryLevel",
185
+ "getIsPlugged": "isPlugged",
186
+ "session.isPlugged": "isPlugged",
187
+ "session.getIsPlugged": "isPlugged",
188
+ "session.getFeatures": "getFeatures",
189
+ "session.getLicenseType": "getLicenseType",
190
+ "getGeneratedUserAgent": "getUserAgent",
191
+ "session.getUserAgent": "getUserAgent",
192
+ "session.getGeneratedUserAgent": "getUserAgent",
193
+ "session.getProcessStats": "getProcessStats",
194
+ "getAmountOfLoadedMessages": "getLoadedMessageCount",
195
+ "session.getLoadedMessageCount": "getLoadedMessageCount",
196
+ "session.getAmountOfLoadedMessages": "getLoadedMessageCount",
197
+ "takeScreenshot": "getSnapshot",
198
+ "session.getSnapshot": "getSnapshot",
199
+ "session.takeScreenshot": "getSnapshot",
200
+ "session.healthCheck": "healthCheck",
201
+ "setDisplayName": "setMyName",
202
+ "session.setName": "setMyName",
203
+ "session.setMyName": "setMyName",
204
+ "session.setDisplayName": "setMyName",
205
+ "setStatusText": "setMyStatus",
206
+ "session.setStatus": "setMyStatus",
207
+ "session.setMyStatus": "setMyStatus",
208
+ "session.setStatusText": "setMyStatus",
209
+ "setProfilePic": "setProfilePicture",
210
+ "session.setProfilePicture": "setProfilePicture",
211
+ "session.setProfilePic": "setProfilePicture",
212
+ "media.decrypt": "decryptMedia",
213
+ "media.download": "downloadMedia"
214
+ } as const;