@open-wa/schema 5.0.0-alpha.8 → 5.1.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.
- package/LICENSE.md +2 -2
- package/README.md +1 -1
- package/dist/generated/index.cjs +8 -2
- package/dist/generated/index.cjs.map +1 -1
- package/dist/generated/index.d.cts +1164 -452
- package/dist/generated/index.d.cts.map +1 -1
- package/dist/generated/index.d.mts +1164 -452
- package/dist/generated/index.d.mts.map +1 -1
- package/dist/generated/index.mjs +8 -2
- package/dist/generated/index.mjs.map +1 -1
- package/dist/{http-manifest-BlJWPKsp.d.mts → http-manifest-CqjUoaDB.d.cts} +12 -13
- package/dist/http-manifest-CqjUoaDB.d.cts.map +1 -0
- package/dist/{http-manifest-DCOVY9QZ.d.cts → http-manifest-CqjUoaDB.d.mts} +12 -13
- package/dist/http-manifest-CqjUoaDB.d.mts.map +1 -0
- package/dist/http-manifest.cjs +1 -1
- package/dist/http-manifest.cjs.map +1 -1
- package/dist/http-manifest.d.cts +1 -1
- package/dist/http-manifest.d.mts +1 -1
- package/dist/http-manifest.mjs +1 -1
- package/dist/http-manifest.mjs.map +1 -1
- package/dist/{implementor-DIBNbQXA.d.cts → implementor-ACLHTHby.d.cts} +1 -2
- package/dist/implementor-ACLHTHby.d.cts.map +1 -0
- package/dist/{implementor-DoN9ga7C.d.mts → implementor-ACLHTHby.d.mts} +1 -2
- package/dist/implementor-ACLHTHby.d.mts.map +1 -0
- package/dist/implementor.cjs +1 -1
- package/dist/implementor.cjs.map +1 -1
- package/dist/implementor.d.cts +1 -1
- package/dist/implementor.d.mts +1 -1
- package/dist/implementor.mjs +1 -1
- package/dist/implementor.mjs.map +1 -1
- package/dist/{index-BB9uyLe8.d.cts → index-DTztyYhw.d.cts} +935 -103
- package/dist/index-DTztyYhw.d.cts.map +1 -0
- package/dist/{index-D77q1gPk.d.mts → index-nVKR0RmZ.d.mts} +935 -103
- package/dist/index-nVKR0RmZ.d.mts.map +1 -0
- package/dist/index.cjs +58 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +31 -7
- package/dist/index.mjs.map +1 -1
- package/dist/methods/index.cjs +5 -1
- package/dist/methods/index.d.cts +2 -2
- package/dist/methods/index.d.mts +2 -2
- package/dist/methods/index.mjs +2 -2
- package/dist/{methods-BXZrkKjP.mjs → methods-BSv5O3bS.mjs} +318 -3
- package/dist/methods-BSv5O3bS.mjs.map +1 -0
- package/dist/{methods-CuiwUO7-.cjs → methods-DO0JONvB.cjs} +473 -2
- package/dist/methods-DO0JONvB.cjs.map +1 -0
- package/dist/{registry-CsyR8i6y.mjs → registry-BIddXpin.mjs} +26 -1
- package/dist/{registry-CsyR8i6y.mjs.map → registry-BIddXpin.mjs.map} +1 -1
- package/dist/{registry-TbMVoiw5.cjs → registry-_s9a7_jl.cjs} +26 -1
- package/dist/{registry-TbMVoiw5.cjs.map → registry-_s9a7_jl.cjs.map} +1 -1
- package/package.json +12 -10
- package/src/__tests__/generators.contract.test.ts +181 -0
- package/src/__tests__/registry.contract.test.ts +81 -0
- package/src/client-config.ts +30 -0
- package/src/codecs.test.ts +41 -0
- package/src/codecs.ts +191 -0
- package/src/common-types.ts +280 -0
- package/src/config.ts +47 -0
- package/src/enums.ts +63 -0
- package/src/events/groups.ts +33 -0
- package/src/events/index.ts +4 -0
- package/src/events/messaging.ts +86 -0
- package/src/events/registry.ts +124 -0
- package/src/events/state.ts +59 -0
- package/src/generated/AliasMap.ts +216 -0
- package/src/generated/BaseClient.ts +878 -0
- package/src/generated/BaseNamespacedClient.ts +214 -0
- package/src/generated/index.ts +5 -0
- package/src/generated/openapi.json +8949 -0
- package/src/generated/types.ts +383 -0
- package/src/http-manifest.ts +97 -0
- package/src/implementor.test.ts +88 -0
- package/src/implementor.ts +75 -0
- package/src/index.ts +44 -0
- package/src/interactive.ts +151 -0
- package/src/methods/business.ts +51 -0
- package/src/methods/chats.ts +263 -0
- package/src/methods/communities.ts +119 -0
- package/src/methods/contacts.ts +158 -0
- package/src/methods/groups.ts +376 -0
- package/src/methods/index.ts +34 -0
- package/src/methods/interactive.ts +21 -0
- package/src/methods/labels.ts +86 -0
- package/src/methods/media.ts +36 -0
- package/src/methods/messaging.ts +828 -0
- package/src/methods/session.ts +261 -0
- package/src/methods/status.ts +120 -0
- package/src/parameters.ts +237 -0
- package/src/registry.test.ts +30 -0
- package/src/registry.ts +601 -0
- package/dist/http-manifest-BlJWPKsp.d.mts.map +0 -1
- package/dist/http-manifest-DCOVY9QZ.d.cts.map +0 -1
- package/dist/implementor-DIBNbQXA.d.cts.map +0 -1
- package/dist/implementor-DoN9ga7C.d.mts.map +0 -1
- package/dist/index-BB9uyLe8.d.cts.map +0 -1
- package/dist/index-D77q1gPk.d.mts.map +0 -1
- package/dist/methods-BXZrkKjP.mjs.map +0 -1
- package/dist/methods-CuiwUO7-.cjs.map +0 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* This file was automatically generated by packages/schema/scripts/gen-types.ts
|
|
4
|
+
* Do not edit this file manually.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type * as Zod from 'zod';
|
|
8
|
+
import type * as Methods from '../methods';
|
|
9
|
+
|
|
10
|
+
export type SendTextInput = Zod.input<typeof Methods.sendText.openWAInput>;
|
|
11
|
+
export type SendTextOutput = Zod.output<typeof Methods.sendText.openWAOutput>;
|
|
12
|
+
|
|
13
|
+
export type SendTextWithMentionsInput = Zod.input<typeof Methods.sendTextWithMentions.openWAInput>;
|
|
14
|
+
export type SendTextWithMentionsOutput = Zod.output<typeof Methods.sendTextWithMentions.openWAOutput>;
|
|
15
|
+
|
|
16
|
+
export type SendReplyWithMentionsInput = Zod.input<typeof Methods.sendReplyWithMentions.openWAInput>;
|
|
17
|
+
export type SendReplyWithMentionsOutput = Zod.output<typeof Methods.sendReplyWithMentions.openWAOutput>;
|
|
18
|
+
|
|
19
|
+
export type SendPaymentRequestInput = Zod.input<typeof Methods.sendPaymentRequest.openWAInput>;
|
|
20
|
+
export type SendPaymentRequestOutput = Zod.output<typeof Methods.sendPaymentRequest.openWAOutput>;
|
|
21
|
+
|
|
22
|
+
export type SendImageInput = Zod.input<typeof Methods.sendImage.openWAInput>;
|
|
23
|
+
export type SendImageOutput = Zod.output<typeof Methods.sendImage.openWAOutput>;
|
|
24
|
+
|
|
25
|
+
export type SendFileInput = Zod.input<typeof Methods.sendFile.openWAInput>;
|
|
26
|
+
export type SendFileOutput = Zod.output<typeof Methods.sendFile.openWAOutput>;
|
|
27
|
+
|
|
28
|
+
export type SendAudioInput = Zod.input<typeof Methods.sendAudio.openWAInput>;
|
|
29
|
+
export type SendAudioOutput = Zod.output<typeof Methods.sendAudio.openWAOutput>;
|
|
30
|
+
|
|
31
|
+
export type SendPttInput = Zod.input<typeof Methods.sendPtt.openWAInput>;
|
|
32
|
+
export type SendPttOutput = Zod.output<typeof Methods.sendPtt.openWAOutput>;
|
|
33
|
+
|
|
34
|
+
export type SendVideoAsGifInput = Zod.input<typeof Methods.sendVideoAsGif.openWAInput>;
|
|
35
|
+
export type SendVideoAsGifOutput = Zod.output<typeof Methods.sendVideoAsGif.openWAOutput>;
|
|
36
|
+
|
|
37
|
+
export type SendLocationInput = Zod.input<typeof Methods.sendLocation.openWAInput>;
|
|
38
|
+
export type SendLocationOutput = Zod.output<typeof Methods.sendLocation.openWAOutput>;
|
|
39
|
+
|
|
40
|
+
export type SendVCardInput = Zod.input<typeof Methods.sendVCard.openWAInput>;
|
|
41
|
+
export type SendVCardOutput = Zod.output<typeof Methods.sendVCard.openWAOutput>;
|
|
42
|
+
|
|
43
|
+
export type SendContactInput = Zod.input<typeof Methods.sendContact.openWAInput>;
|
|
44
|
+
export type SendContactOutput = Zod.output<typeof Methods.sendContact.openWAOutput>;
|
|
45
|
+
|
|
46
|
+
export type SendMultipleContactsInput = Zod.input<typeof Methods.sendMultipleContacts.openWAInput>;
|
|
47
|
+
export type SendMultipleContactsOutput = Zod.output<typeof Methods.sendMultipleContacts.openWAOutput>;
|
|
48
|
+
|
|
49
|
+
export type SendButtonsInput = Zod.input<typeof Methods.sendButtons.openWAInput>;
|
|
50
|
+
export type SendButtonsOutput = Zod.output<typeof Methods.sendButtons.openWAOutput>;
|
|
51
|
+
|
|
52
|
+
export type SendAdvancedButtonsInput = Zod.input<typeof Methods.sendAdvancedButtons.openWAInput>;
|
|
53
|
+
export type SendAdvancedButtonsOutput = Zod.output<typeof Methods.sendAdvancedButtons.openWAOutput>;
|
|
54
|
+
|
|
55
|
+
export type SendListMessageInput = Zod.input<typeof Methods.sendListMessage.openWAInput>;
|
|
56
|
+
export type SendListMessageOutput = Zod.output<typeof Methods.sendListMessage.openWAOutput>;
|
|
57
|
+
|
|
58
|
+
export type SendPollInput = Zod.input<typeof Methods.sendPoll.openWAInput>;
|
|
59
|
+
export type SendPollOutput = Zod.output<typeof Methods.sendPoll.openWAOutput>;
|
|
60
|
+
|
|
61
|
+
export type SendBannerInput = Zod.input<typeof Methods.sendBanner.openWAInput>;
|
|
62
|
+
export type SendBannerOutput = Zod.output<typeof Methods.sendBanner.openWAOutput>;
|
|
63
|
+
|
|
64
|
+
export type SendYouTubeLinkInput = Zod.input<typeof Methods.sendYouTubeLink.openWAInput>;
|
|
65
|
+
export type SendYouTubeLinkOutput = Zod.output<typeof Methods.sendYouTubeLink.openWAOutput>;
|
|
66
|
+
|
|
67
|
+
export type SendLinkWithAutoPreviewInput = Zod.input<typeof Methods.sendLinkWithAutoPreview.openWAInput>;
|
|
68
|
+
export type SendLinkWithAutoPreviewOutput = Zod.output<typeof Methods.sendLinkWithAutoPreview.openWAOutput>;
|
|
69
|
+
|
|
70
|
+
export type SendMessageWithThumbInput = Zod.input<typeof Methods.sendMessageWithThumb.openWAInput>;
|
|
71
|
+
export type SendMessageWithThumbOutput = Zod.output<typeof Methods.sendMessageWithThumb.openWAOutput>;
|
|
72
|
+
|
|
73
|
+
export type ForwardMessagesInput = Zod.input<typeof Methods.forwardMessages.openWAInput>;
|
|
74
|
+
export type ForwardMessagesOutput = Zod.output<typeof Methods.forwardMessages.openWAOutput>;
|
|
75
|
+
|
|
76
|
+
export type DeleteMessageInput = Zod.input<typeof Methods.deleteMessage.openWAInput>;
|
|
77
|
+
export type DeleteMessageOutput = Zod.output<typeof Methods.deleteMessage.openWAOutput>;
|
|
78
|
+
|
|
79
|
+
export type GetMessageByIdInput = Zod.input<typeof Methods.getMessageById.openWAInput>;
|
|
80
|
+
export type GetMessageByIdOutput = Zod.output<typeof Methods.getMessageById.openWAOutput>;
|
|
81
|
+
|
|
82
|
+
export type GetAllMessagesInput = Zod.input<typeof Methods.getAllMessages.openWAInput>;
|
|
83
|
+
export type GetAllMessagesOutput = Zod.output<typeof Methods.getAllMessages.openWAOutput>;
|
|
84
|
+
|
|
85
|
+
export type GetMyLastMessageInput = Zod.input<typeof Methods.getMyLastMessage.openWAInput>;
|
|
86
|
+
export type GetMyLastMessageOutput = Zod.output<typeof Methods.getMyLastMessage.openWAOutput>;
|
|
87
|
+
|
|
88
|
+
export type GetStarredMessagesInput = Zod.input<typeof Methods.getStarredMessages.openWAInput>;
|
|
89
|
+
export type GetStarredMessagesOutput = Zod.output<typeof Methods.getStarredMessages.openWAOutput>;
|
|
90
|
+
|
|
91
|
+
export type GetUnsentMessagesInput = Zod.input<typeof Methods.getUnsentMessages.openWAInput>;
|
|
92
|
+
export type GetUnsentMessagesOutput = Zod.output<typeof Methods.getUnsentMessages.openWAOutput>;
|
|
93
|
+
|
|
94
|
+
export type GetMessageInfoInput = Zod.input<typeof Methods.getMessageInfo.openWAInput>;
|
|
95
|
+
export type GetMessageInfoOutput = Zod.output<typeof Methods.getMessageInfo.openWAOutput>;
|
|
96
|
+
|
|
97
|
+
export type GetVCardsInput = Zod.input<typeof Methods.getVCards.openWAInput>;
|
|
98
|
+
export type GetVCardsOutput = Zod.output<typeof Methods.getVCards.openWAOutput>;
|
|
99
|
+
|
|
100
|
+
export type GetMessagesForLLMInput = Zod.input<typeof Methods.getMessagesForLLM.openWAInput>;
|
|
101
|
+
export type GetMessagesForLLMOutput = Zod.output<typeof Methods.getMessagesForLLM.openWAOutput>;
|
|
102
|
+
|
|
103
|
+
export type StarMessageInput = Zod.input<typeof Methods.starMessage.openWAInput>;
|
|
104
|
+
export type StarMessageOutput = Zod.output<typeof Methods.starMessage.openWAOutput>;
|
|
105
|
+
|
|
106
|
+
export type UnstarMessageInput = Zod.input<typeof Methods.unstarMessage.openWAInput>;
|
|
107
|
+
export type UnstarMessageOutput = Zod.output<typeof Methods.unstarMessage.openWAOutput>;
|
|
108
|
+
|
|
109
|
+
export type ReactInput = Zod.input<typeof Methods.react.openWAInput>;
|
|
110
|
+
export type ReactOutput = Zod.output<typeof Methods.react.openWAOutput>;
|
|
111
|
+
|
|
112
|
+
export type SendSeenInput = Zod.input<typeof Methods.sendSeen.openWAInput>;
|
|
113
|
+
export type SendSeenOutput = Zod.output<typeof Methods.sendSeen.openWAOutput>;
|
|
114
|
+
|
|
115
|
+
export type LoadEarlierMessagesInput = Zod.input<typeof Methods.loadEarlierMessages.openWAInput>;
|
|
116
|
+
export type LoadEarlierMessagesOutput = Zod.output<typeof Methods.loadEarlierMessages.openWAOutput>;
|
|
117
|
+
|
|
118
|
+
export type SendFileFromUrlInput = Zod.input<typeof Methods.sendFileFromUrl.openWAInput>;
|
|
119
|
+
export type SendFileFromUrlOutput = Zod.output<typeof Methods.sendFileFromUrl.openWAOutput>;
|
|
120
|
+
|
|
121
|
+
export type GetAllChatsInput = Zod.input<typeof Methods.getAllChats.openWAInput>;
|
|
122
|
+
export type GetAllChatsOutput = Zod.output<typeof Methods.getAllChats.openWAOutput>;
|
|
123
|
+
|
|
124
|
+
export type GetAllChatIdsInput = Zod.input<typeof Methods.getAllChatIds.openWAInput>;
|
|
125
|
+
export type GetAllChatIdsOutput = Zod.output<typeof Methods.getAllChatIds.openWAOutput>;
|
|
126
|
+
|
|
127
|
+
export type GetChatInput = Zod.input<typeof Methods.getChat.openWAInput>;
|
|
128
|
+
export type GetChatOutput = Zod.output<typeof Methods.getChat.openWAOutput>;
|
|
129
|
+
|
|
130
|
+
export type GetChatWithNonContactsInput = Zod.input<typeof Methods.getChatWithNonContacts.openWAInput>;
|
|
131
|
+
export type GetChatWithNonContactsOutput = Zod.output<typeof Methods.getChatWithNonContacts.openWAOutput>;
|
|
132
|
+
|
|
133
|
+
export type ArchiveChatInput = Zod.input<typeof Methods.archiveChat.openWAInput>;
|
|
134
|
+
export type ArchiveChatOutput = Zod.output<typeof Methods.archiveChat.openWAOutput>;
|
|
135
|
+
|
|
136
|
+
export type UnarchiveChatInput = Zod.input<typeof Methods.unarchiveChat.openWAInput>;
|
|
137
|
+
export type UnarchiveChatOutput = Zod.output<typeof Methods.unarchiveChat.openWAOutput>;
|
|
138
|
+
|
|
139
|
+
export type ClearChatInput = Zod.input<typeof Methods.clearChat.openWAInput>;
|
|
140
|
+
export type ClearChatOutput = Zod.output<typeof Methods.clearChat.openWAOutput>;
|
|
141
|
+
|
|
142
|
+
export type DeleteChatInput = Zod.input<typeof Methods.deleteChat.openWAInput>;
|
|
143
|
+
export type DeleteChatOutput = Zod.output<typeof Methods.deleteChat.openWAOutput>;
|
|
144
|
+
|
|
145
|
+
export type PinChatInput = Zod.input<typeof Methods.pinChat.openWAInput>;
|
|
146
|
+
export type PinChatOutput = Zod.output<typeof Methods.pinChat.openWAOutput>;
|
|
147
|
+
|
|
148
|
+
export type UnpinChatInput = Zod.input<typeof Methods.unpinChat.openWAInput>;
|
|
149
|
+
export type UnpinChatOutput = Zod.output<typeof Methods.unpinChat.openWAOutput>;
|
|
150
|
+
|
|
151
|
+
export type MuteChatInput = Zod.input<typeof Methods.muteChat.openWAInput>;
|
|
152
|
+
export type MuteChatOutput = Zod.output<typeof Methods.muteChat.openWAOutput>;
|
|
153
|
+
|
|
154
|
+
export type UnmuteChatInput = Zod.input<typeof Methods.unmuteChat.openWAInput>;
|
|
155
|
+
export type UnmuteChatOutput = Zod.output<typeof Methods.unmuteChat.openWAOutput>;
|
|
156
|
+
|
|
157
|
+
export type MarkAsReadInput = Zod.input<typeof Methods.markAsRead.openWAInput>;
|
|
158
|
+
export type MarkAsReadOutput = Zod.output<typeof Methods.markAsRead.openWAOutput>;
|
|
159
|
+
|
|
160
|
+
export type MarkAsUnreadInput = Zod.input<typeof Methods.markAsUnread.openWAInput>;
|
|
161
|
+
export type MarkAsUnreadOutput = Zod.output<typeof Methods.markAsUnread.openWAOutput>;
|
|
162
|
+
|
|
163
|
+
export type SetChatEphemeralInput = Zod.input<typeof Methods.setChatEphemeral.openWAInput>;
|
|
164
|
+
export type SetChatEphemeralOutput = Zod.output<typeof Methods.setChatEphemeral.openWAOutput>;
|
|
165
|
+
|
|
166
|
+
export type IsChatOnlineInput = Zod.input<typeof Methods.isChatOnline.openWAInput>;
|
|
167
|
+
export type IsChatOnlineOutput = Zod.output<typeof Methods.isChatOnline.openWAOutput>;
|
|
168
|
+
|
|
169
|
+
export type GetAllContactsInput = Zod.input<typeof Methods.getAllContacts.openWAInput>;
|
|
170
|
+
export type GetAllContactsOutput = Zod.output<typeof Methods.getAllContacts.openWAOutput>;
|
|
171
|
+
|
|
172
|
+
export type GetContactInput = Zod.input<typeof Methods.getContact.openWAInput>;
|
|
173
|
+
export type GetContactOutput = Zod.output<typeof Methods.getContact.openWAOutput>;
|
|
174
|
+
|
|
175
|
+
export type GetCommonGroupsInput = Zod.input<typeof Methods.getCommonGroups.openWAInput>;
|
|
176
|
+
export type GetCommonGroupsOutput = Zod.output<typeof Methods.getCommonGroups.openWAOutput>;
|
|
177
|
+
|
|
178
|
+
export type GetNumberProfileInput = Zod.input<typeof Methods.getNumberProfile.openWAInput>;
|
|
179
|
+
export type GetNumberProfileOutput = Zod.output<typeof Methods.getNumberProfile.openWAOutput>;
|
|
180
|
+
|
|
181
|
+
export type GetBlockedIdsInput = Zod.input<typeof Methods.getBlockedIds.openWAInput>;
|
|
182
|
+
export type GetBlockedIdsOutput = Zod.output<typeof Methods.getBlockedIds.openWAOutput>;
|
|
183
|
+
|
|
184
|
+
export type BlockContactInput = Zod.input<typeof Methods.blockContact.openWAInput>;
|
|
185
|
+
export type BlockContactOutput = Zod.output<typeof Methods.blockContact.openWAOutput>;
|
|
186
|
+
|
|
187
|
+
export type UnblockContactInput = Zod.input<typeof Methods.unblockContact.openWAInput>;
|
|
188
|
+
export type UnblockContactOutput = Zod.output<typeof Methods.unblockContact.openWAOutput>;
|
|
189
|
+
|
|
190
|
+
export type CheckReadReceiptsInput = Zod.input<typeof Methods.checkReadReceipts.openWAInput>;
|
|
191
|
+
export type CheckReadReceiptsOutput = Zod.output<typeof Methods.checkReadReceipts.openWAOutput>;
|
|
192
|
+
|
|
193
|
+
export type CheckNumberStatusInput = Zod.input<typeof Methods.checkNumberStatus.openWAInput>;
|
|
194
|
+
export type CheckNumberStatusOutput = Zod.output<typeof Methods.checkNumberStatus.openWAOutput>;
|
|
195
|
+
|
|
196
|
+
export type GetProfilePictureInput = Zod.input<typeof Methods.getProfilePicture.openWAInput>;
|
|
197
|
+
export type GetProfilePictureOutput = Zod.output<typeof Methods.getProfilePicture.openWAOutput>;
|
|
198
|
+
|
|
199
|
+
export type GetGroupMembersInput = Zod.input<typeof Methods.getGroupMembers.openWAInput>;
|
|
200
|
+
export type GetGroupMembersOutput = Zod.output<typeof Methods.getGroupMembers.openWAOutput>;
|
|
201
|
+
|
|
202
|
+
export type GetAllGroupsInput = Zod.input<typeof Methods.getAllGroups.openWAInput>;
|
|
203
|
+
export type GetAllGroupsOutput = Zod.output<typeof Methods.getAllGroups.openWAOutput>;
|
|
204
|
+
|
|
205
|
+
export type GetGroupMembersIdInput = Zod.input<typeof Methods.getGroupMembersId.openWAInput>;
|
|
206
|
+
export type GetGroupMembersIdOutput = Zod.output<typeof Methods.getGroupMembersId.openWAOutput>;
|
|
207
|
+
|
|
208
|
+
export type GetGroupInfoInput = Zod.input<typeof Methods.getGroupInfo.openWAInput>;
|
|
209
|
+
export type GetGroupInfoOutput = Zod.output<typeof Methods.getGroupInfo.openWAOutput>;
|
|
210
|
+
|
|
211
|
+
export type GetGroupAdminsInput = Zod.input<typeof Methods.getGroupAdmins.openWAInput>;
|
|
212
|
+
export type GetGroupAdminsOutput = Zod.output<typeof Methods.getGroupAdmins.openWAOutput>;
|
|
213
|
+
|
|
214
|
+
export type GetKickedGroupsInput = Zod.input<typeof Methods.getKickedGroups.openWAInput>;
|
|
215
|
+
export type GetKickedGroupsOutput = Zod.output<typeof Methods.getKickedGroups.openWAOutput>;
|
|
216
|
+
|
|
217
|
+
export type GetGroupInviteLinkInput = Zod.input<typeof Methods.getGroupInviteLink.openWAInput>;
|
|
218
|
+
export type GetGroupInviteLinkOutput = Zod.output<typeof Methods.getGroupInviteLink.openWAOutput>;
|
|
219
|
+
|
|
220
|
+
export type CreateGroupInput = Zod.input<typeof Methods.createGroup.openWAInput>;
|
|
221
|
+
export type CreateGroupOutput = Zod.output<typeof Methods.createGroup.openWAOutput>;
|
|
222
|
+
|
|
223
|
+
export type LeaveGroupInput = Zod.input<typeof Methods.leaveGroup.openWAInput>;
|
|
224
|
+
export type LeaveGroupOutput = Zod.output<typeof Methods.leaveGroup.openWAOutput>;
|
|
225
|
+
|
|
226
|
+
export type JoinGroupViaLinkInput = Zod.input<typeof Methods.joinGroupViaLink.openWAInput>;
|
|
227
|
+
export type JoinGroupViaLinkOutput = Zod.output<typeof Methods.joinGroupViaLink.openWAOutput>;
|
|
228
|
+
|
|
229
|
+
export type RevokeGroupInviteLinkInput = Zod.input<typeof Methods.revokeGroupInviteLink.openWAInput>;
|
|
230
|
+
export type RevokeGroupInviteLinkOutput = Zod.output<typeof Methods.revokeGroupInviteLink.openWAOutput>;
|
|
231
|
+
|
|
232
|
+
export type SetGroupTitleInput = Zod.input<typeof Methods.setGroupTitle.openWAInput>;
|
|
233
|
+
export type SetGroupTitleOutput = Zod.output<typeof Methods.setGroupTitle.openWAOutput>;
|
|
234
|
+
|
|
235
|
+
export type SetGroupDescriptionInput = Zod.input<typeof Methods.setGroupDescription.openWAInput>;
|
|
236
|
+
export type SetGroupDescriptionOutput = Zod.output<typeof Methods.setGroupDescription.openWAOutput>;
|
|
237
|
+
|
|
238
|
+
export type SetGroupIconInput = Zod.input<typeof Methods.setGroupIcon.openWAInput>;
|
|
239
|
+
export type SetGroupIconOutput = Zod.output<typeof Methods.setGroupIcon.openWAOutput>;
|
|
240
|
+
|
|
241
|
+
export type SetGroupToAdminsOnlyInput = Zod.input<typeof Methods.setGroupToAdminsOnly.openWAInput>;
|
|
242
|
+
export type SetGroupToAdminsOnlyOutput = Zod.output<typeof Methods.setGroupToAdminsOnly.openWAOutput>;
|
|
243
|
+
|
|
244
|
+
export type SetGroupEditToAdminsOnlyInput = Zod.input<typeof Methods.setGroupEditToAdminsOnly.openWAInput>;
|
|
245
|
+
export type SetGroupEditToAdminsOnlyOutput = Zod.output<typeof Methods.setGroupEditToAdminsOnly.openWAOutput>;
|
|
246
|
+
|
|
247
|
+
export type AddParticipantInput = Zod.input<typeof Methods.addParticipant.openWAInput>;
|
|
248
|
+
export type AddParticipantOutput = Zod.output<typeof Methods.addParticipant.openWAOutput>;
|
|
249
|
+
|
|
250
|
+
export type RemoveParticipantInput = Zod.input<typeof Methods.removeParticipant.openWAInput>;
|
|
251
|
+
export type RemoveParticipantOutput = Zod.output<typeof Methods.removeParticipant.openWAOutput>;
|
|
252
|
+
|
|
253
|
+
export type PromoteParticipantInput = Zod.input<typeof Methods.promoteParticipant.openWAInput>;
|
|
254
|
+
export type PromoteParticipantOutput = Zod.output<typeof Methods.promoteParticipant.openWAOutput>;
|
|
255
|
+
|
|
256
|
+
export type DemoteParticipantInput = Zod.input<typeof Methods.demoteParticipant.openWAInput>;
|
|
257
|
+
export type DemoteParticipantOutput = Zod.output<typeof Methods.demoteParticipant.openWAOutput>;
|
|
258
|
+
|
|
259
|
+
export type ApproveGroupJoinRequestInput = Zod.input<typeof Methods.approveGroupJoinRequest.openWAInput>;
|
|
260
|
+
export type ApproveGroupJoinRequestOutput = Zod.output<typeof Methods.approveGroupJoinRequest.openWAOutput>;
|
|
261
|
+
|
|
262
|
+
export type RejectGroupJoinRequestInput = Zod.input<typeof Methods.rejectGroupJoinRequest.openWAInput>;
|
|
263
|
+
export type RejectGroupJoinRequestOutput = Zod.output<typeof Methods.rejectGroupJoinRequest.openWAOutput>;
|
|
264
|
+
|
|
265
|
+
export type GetAllCommunitiesInput = Zod.input<typeof Methods.getAllCommunities.openWAInput>;
|
|
266
|
+
export type GetAllCommunitiesOutput = Zod.output<typeof Methods.getAllCommunities.openWAOutput>;
|
|
267
|
+
|
|
268
|
+
export type GetCommunityInfoInput = Zod.input<typeof Methods.getCommunityInfo.openWAInput>;
|
|
269
|
+
export type GetCommunityInfoOutput = Zod.output<typeof Methods.getCommunityInfo.openWAOutput>;
|
|
270
|
+
|
|
271
|
+
export type GetCommunityParticipantIdsInput = Zod.input<typeof Methods.getCommunityParticipantIds.openWAInput>;
|
|
272
|
+
export type GetCommunityParticipantIdsOutput = Zod.output<typeof Methods.getCommunityParticipantIds.openWAOutput>;
|
|
273
|
+
|
|
274
|
+
export type GetCommunityAdminIdsInput = Zod.input<typeof Methods.getCommunityAdminIds.openWAInput>;
|
|
275
|
+
export type GetCommunityAdminIdsOutput = Zod.output<typeof Methods.getCommunityAdminIds.openWAOutput>;
|
|
276
|
+
|
|
277
|
+
export type GetCommunityParticipantsInput = Zod.input<typeof Methods.getCommunityParticipants.openWAInput>;
|
|
278
|
+
export type GetCommunityParticipantsOutput = Zod.output<typeof Methods.getCommunityParticipants.openWAOutput>;
|
|
279
|
+
|
|
280
|
+
export type GetCommunityAdminsInput = Zod.input<typeof Methods.getCommunityAdmins.openWAInput>;
|
|
281
|
+
export type GetCommunityAdminsOutput = Zod.output<typeof Methods.getCommunityAdmins.openWAOutput>;
|
|
282
|
+
|
|
283
|
+
export type PostTextStatusInput = Zod.input<typeof Methods.postTextStatus.openWAInput>;
|
|
284
|
+
export type PostTextStatusOutput = Zod.output<typeof Methods.postTextStatus.openWAOutput>;
|
|
285
|
+
|
|
286
|
+
export type PostImageStatusInput = Zod.input<typeof Methods.postImageStatus.openWAInput>;
|
|
287
|
+
export type PostImageStatusOutput = Zod.output<typeof Methods.postImageStatus.openWAOutput>;
|
|
288
|
+
|
|
289
|
+
export type PostVideoStatusInput = Zod.input<typeof Methods.postVideoStatus.openWAInput>;
|
|
290
|
+
export type PostVideoStatusOutput = Zod.output<typeof Methods.postVideoStatus.openWAOutput>;
|
|
291
|
+
|
|
292
|
+
export type GetStoriesInput = Zod.input<typeof Methods.getStories.openWAInput>;
|
|
293
|
+
export type GetStoriesOutput = Zod.output<typeof Methods.getStories.openWAOutput>;
|
|
294
|
+
|
|
295
|
+
export type GetStatusInput = Zod.input<typeof Methods.getStatus.openWAInput>;
|
|
296
|
+
export type GetStatusOutput = Zod.output<typeof Methods.getStatus.openWAOutput>;
|
|
297
|
+
|
|
298
|
+
export type DeleteStatusInput = Zod.input<typeof Methods.deleteStatus.openWAInput>;
|
|
299
|
+
export type DeleteStatusOutput = Zod.output<typeof Methods.deleteStatus.openWAOutput>;
|
|
300
|
+
|
|
301
|
+
export type DeleteAllStatusInput = Zod.input<typeof Methods.deleteAllStatus.openWAInput>;
|
|
302
|
+
export type DeleteAllStatusOutput = Zod.output<typeof Methods.deleteAllStatus.openWAOutput>;
|
|
303
|
+
|
|
304
|
+
export type GetAllLabelsInput = Zod.input<typeof Methods.getAllLabels.openWAInput>;
|
|
305
|
+
export type GetAllLabelsOutput = Zod.output<typeof Methods.getAllLabels.openWAOutput>;
|
|
306
|
+
|
|
307
|
+
export type GetChatsByLabelInput = Zod.input<typeof Methods.getChatsByLabel.openWAInput>;
|
|
308
|
+
export type GetChatsByLabelOutput = Zod.output<typeof Methods.getChatsByLabel.openWAOutput>;
|
|
309
|
+
|
|
310
|
+
export type AddLabelInput = Zod.input<typeof Methods.addLabel.openWAInput>;
|
|
311
|
+
export type AddLabelOutput = Zod.output<typeof Methods.addLabel.openWAOutput>;
|
|
312
|
+
|
|
313
|
+
export type RemoveLabelInput = Zod.input<typeof Methods.removeLabel.openWAInput>;
|
|
314
|
+
export type RemoveLabelOutput = Zod.output<typeof Methods.removeLabel.openWAOutput>;
|
|
315
|
+
|
|
316
|
+
export type GetBusinessProfileInput = Zod.input<typeof Methods.getBusinessProfile.openWAInput>;
|
|
317
|
+
export type GetBusinessProfileOutput = Zod.output<typeof Methods.getBusinessProfile.openWAOutput>;
|
|
318
|
+
|
|
319
|
+
export type GetBusinessProductsInput = Zod.input<typeof Methods.getBusinessProducts.openWAInput>;
|
|
320
|
+
export type GetBusinessProductsOutput = Zod.output<typeof Methods.getBusinessProducts.openWAOutput>;
|
|
321
|
+
|
|
322
|
+
export type GetOrderInput = Zod.input<typeof Methods.getOrder.openWAInput>;
|
|
323
|
+
export type GetOrderOutput = Zod.output<typeof Methods.getOrder.openWAOutput>;
|
|
324
|
+
|
|
325
|
+
export type GetMeInput = Zod.input<typeof Methods.getMe.openWAInput>;
|
|
326
|
+
export type GetMeOutput = Zod.output<typeof Methods.getMe.openWAOutput>;
|
|
327
|
+
|
|
328
|
+
export type GetHostNumberInput = Zod.input<typeof Methods.getHostNumber.openWAInput>;
|
|
329
|
+
export type GetHostNumberOutput = Zod.output<typeof Methods.getHostNumber.openWAOutput>;
|
|
330
|
+
|
|
331
|
+
export type GetConnectionStateInput = Zod.input<typeof Methods.getConnectionState.openWAInput>;
|
|
332
|
+
export type GetConnectionStateOutput = Zod.output<typeof Methods.getConnectionState.openWAOutput>;
|
|
333
|
+
|
|
334
|
+
export type GetWAVersionInput = Zod.input<typeof Methods.getWAVersion.openWAInput>;
|
|
335
|
+
export type GetWAVersionOutput = Zod.output<typeof Methods.getWAVersion.openWAOutput>;
|
|
336
|
+
|
|
337
|
+
export type GetBatteryLevelInput = Zod.input<typeof Methods.getBatteryLevel.openWAInput>;
|
|
338
|
+
export type GetBatteryLevelOutput = Zod.output<typeof Methods.getBatteryLevel.openWAOutput>;
|
|
339
|
+
|
|
340
|
+
export type IsPluggedInput = Zod.input<typeof Methods.isPlugged.openWAInput>;
|
|
341
|
+
export type IsPluggedOutput = Zod.output<typeof Methods.isPlugged.openWAOutput>;
|
|
342
|
+
|
|
343
|
+
export type GetFeaturesInput = Zod.input<typeof Methods.getFeatures.openWAInput>;
|
|
344
|
+
export type GetFeaturesOutput = Zod.output<typeof Methods.getFeatures.openWAOutput>;
|
|
345
|
+
|
|
346
|
+
export type GetLicenseTypeInput = Zod.input<typeof Methods.getLicenseType.openWAInput>;
|
|
347
|
+
export type GetLicenseTypeOutput = Zod.output<typeof Methods.getLicenseType.openWAOutput>;
|
|
348
|
+
|
|
349
|
+
export type GetUserAgentInput = Zod.input<typeof Methods.getUserAgent.openWAInput>;
|
|
350
|
+
export type GetUserAgentOutput = Zod.output<typeof Methods.getUserAgent.openWAOutput>;
|
|
351
|
+
|
|
352
|
+
export type GetProcessStatsInput = Zod.input<typeof Methods.getProcessStats.openWAInput>;
|
|
353
|
+
export type GetProcessStatsOutput = Zod.output<typeof Methods.getProcessStats.openWAOutput>;
|
|
354
|
+
|
|
355
|
+
export type GetLoadedMessageCountInput = Zod.input<typeof Methods.getLoadedMessageCount.openWAInput>;
|
|
356
|
+
export type GetLoadedMessageCountOutput = Zod.output<typeof Methods.getLoadedMessageCount.openWAOutput>;
|
|
357
|
+
|
|
358
|
+
export type GetSnapshotInput = Zod.input<typeof Methods.getSnapshot.openWAInput>;
|
|
359
|
+
export type GetSnapshotOutput = Zod.output<typeof Methods.getSnapshot.openWAOutput>;
|
|
360
|
+
|
|
361
|
+
export type HealthCheckInput = Zod.input<typeof Methods.healthCheck.openWAInput>;
|
|
362
|
+
export type HealthCheckOutput = Zod.output<typeof Methods.healthCheck.openWAOutput>;
|
|
363
|
+
|
|
364
|
+
export type SetMyNameInput = Zod.input<typeof Methods.setMyName.openWAInput>;
|
|
365
|
+
export type SetMyNameOutput = Zod.output<typeof Methods.setMyName.openWAOutput>;
|
|
366
|
+
|
|
367
|
+
export type SetMyStatusInput = Zod.input<typeof Methods.setMyStatus.openWAInput>;
|
|
368
|
+
export type SetMyStatusOutput = Zod.output<typeof Methods.setMyStatus.openWAOutput>;
|
|
369
|
+
|
|
370
|
+
export type SetProfilePictureInput = Zod.input<typeof Methods.setProfilePicture.openWAInput>;
|
|
371
|
+
export type SetProfilePictureOutput = Zod.output<typeof Methods.setProfilePicture.openWAOutput>;
|
|
372
|
+
|
|
373
|
+
export type DecryptMediaInput = Zod.input<typeof Methods.decryptMedia.openWAInput>;
|
|
374
|
+
export type DecryptMediaOutput = Zod.output<typeof Methods.decryptMedia.openWAOutput>;
|
|
375
|
+
|
|
376
|
+
export type DownloadMediaInput = Zod.input<typeof Methods.downloadMedia.openWAInput>;
|
|
377
|
+
export type DownloadMediaOutput = Zod.output<typeof Methods.downloadMedia.openWAOutput>;
|
|
378
|
+
|
|
379
|
+
export type SendInteractiveInput = Zod.input<typeof Methods.sendInteractive.openWAInput>;
|
|
380
|
+
export type SendInteractiveOutput = Zod.output<typeof Methods.sendInteractive.openWAOutput>;
|
|
381
|
+
|
|
382
|
+
export type SendRawMessageInput = Zod.input<typeof Methods.sendRawMessage.openWAInput>;
|
|
383
|
+
export type SendRawMessageOutput = Zod.output<typeof Methods.sendRawMessage.openWAOutput>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { buildKeyAliasMap, clientRegistry, MethodDefinition } from './registry';
|
|
2
|
+
|
|
3
|
+
export interface HttpRouteAlias {
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
deprecated: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface HttpMethodDefinition {
|
|
10
|
+
functionName: string;
|
|
11
|
+
namespacedName: string;
|
|
12
|
+
path: string;
|
|
13
|
+
namespace: string;
|
|
14
|
+
description: string;
|
|
15
|
+
httpMethod: string;
|
|
16
|
+
inputSchema: MethodDefinition['meta']['inputSchema'];
|
|
17
|
+
outputSchema: MethodDefinition['meta']['outputSchema'];
|
|
18
|
+
parameterOrder: string[];
|
|
19
|
+
aliases: string[];
|
|
20
|
+
deprecatedAliases: string[];
|
|
21
|
+
aliasRoutes: HttpRouteAlias[];
|
|
22
|
+
routeSignatures: string[];
|
|
23
|
+
invocationNames: string[];
|
|
24
|
+
keyAliasMap: Record<string, string>;
|
|
25
|
+
wapiOverride?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function joinPath(...parts: string[]): string {
|
|
29
|
+
const normalized = parts
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((part, index) =>
|
|
32
|
+
index === 0 ? part.replace(/\/+$/, '') : part.replace(/^\/+/, '').replace(/\/+$/, '')
|
|
33
|
+
)
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join('/');
|
|
36
|
+
|
|
37
|
+
return normalized.startsWith('/') ? normalized : `/${normalized}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function routePathForMethodName(basePath: string, fallbackNamespace: string, methodName: string): string {
|
|
41
|
+
if (methodName.includes('.')) {
|
|
42
|
+
const [namespace, ...rest] = methodName.split('.');
|
|
43
|
+
return joinPath(basePath, namespace, rest.join('/'));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return joinPath(basePath, methodName || fallbackNamespace);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function uniqueStrings(values: string[]): string[] {
|
|
50
|
+
return Array.from(new Set(values.filter(Boolean)));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getHttpMethodDefinitions(basePath = '/api'): HttpMethodDefinition[] {
|
|
54
|
+
return clientRegistry.getAll().map((def) => {
|
|
55
|
+
const namespace = def.meta.namespace || 'core';
|
|
56
|
+
const namespacedName = def.meta.namespacedName || def.meta.functionName;
|
|
57
|
+
const path = joinPath(basePath, namespace, namespacedName);
|
|
58
|
+
const aliases = uniqueStrings(def.meta.allAliases ?? []);
|
|
59
|
+
const deprecatedAliases = uniqueStrings(def.meta.deprecatedAliases ?? []);
|
|
60
|
+
const aliasNames = uniqueStrings([def.meta.functionName, ...aliases]).filter(
|
|
61
|
+
(alias) => alias !== `${namespace}.${namespacedName}`
|
|
62
|
+
);
|
|
63
|
+
const aliasRoutes = aliasNames.map((name) => ({
|
|
64
|
+
name,
|
|
65
|
+
path: routePathForMethodName(basePath, namespace, name),
|
|
66
|
+
deprecated: deprecatedAliases.includes(name),
|
|
67
|
+
}));
|
|
68
|
+
const httpMethod = def.meta.httpMethod || 'POST';
|
|
69
|
+
const routeSignatures = [
|
|
70
|
+
`${httpMethod} ${path}`,
|
|
71
|
+
...aliasRoutes.map((alias) => `${httpMethod} ${alias.path}`),
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
functionName: def.meta.functionName,
|
|
76
|
+
namespacedName,
|
|
77
|
+
path,
|
|
78
|
+
namespace,
|
|
79
|
+
description: def.meta.description || def.meta.functionName,
|
|
80
|
+
httpMethod,
|
|
81
|
+
inputSchema: def.meta.inputSchema,
|
|
82
|
+
outputSchema: def.meta.outputSchema,
|
|
83
|
+
parameterOrder: def.meta.parameterOrder,
|
|
84
|
+
aliases,
|
|
85
|
+
deprecatedAliases,
|
|
86
|
+
aliasRoutes,
|
|
87
|
+
routeSignatures,
|
|
88
|
+
invocationNames: uniqueStrings([
|
|
89
|
+
def.meta.functionName,
|
|
90
|
+
def.meta.wapiOverride || '',
|
|
91
|
+
...aliases,
|
|
92
|
+
]),
|
|
93
|
+
keyAliasMap: buildKeyAliasMap(def.meta.inputSchema.shape),
|
|
94
|
+
wapiOverride: def.meta.wapiOverride,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineMethodV2 } from './registry';
|
|
3
|
+
import { implementMethod } from './implementor';
|
|
4
|
+
|
|
5
|
+
describe('implementor.ts', () => {
|
|
6
|
+
const testSchema = defineMethodV2('testFunc', {
|
|
7
|
+
meta: {
|
|
8
|
+
description: 'A test function',
|
|
9
|
+
},
|
|
10
|
+
input: z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
count: z.number(),
|
|
13
|
+
}),
|
|
14
|
+
parameterOrder: ['id', 'count'],
|
|
15
|
+
output: z.string(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should correctly normalize positional arguments', async () => {
|
|
19
|
+
interface TestParams { id: string; count: number; }
|
|
20
|
+
let receivedParams: TestParams | null = null;
|
|
21
|
+
const mockClient = {
|
|
22
|
+
testFunc: implementMethod(testSchema, async function (params: TestParams) {
|
|
23
|
+
receivedParams = params;
|
|
24
|
+
return 'ok';
|
|
25
|
+
})
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
await mockClient.testFunc('user-1', 42);
|
|
29
|
+
expect(receivedParams).toEqual({ id: 'user-1', count: 42 } as TestParams);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should correctly normalize named object arguments', async () => {
|
|
33
|
+
let receivedParams: any = null;
|
|
34
|
+
const mockClient = {
|
|
35
|
+
testFunc: implementMethod(testSchema, async function (params) {
|
|
36
|
+
receivedParams = params;
|
|
37
|
+
return 'ok';
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
await mockClient.testFunc({ id: 'user-2', count: 100 });
|
|
42
|
+
expect(receivedParams).toEqual({ id: 'user-2', count: 100 });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should throw ZodError for invalid positional inputs', async () => {
|
|
46
|
+
const mockClient = {
|
|
47
|
+
testFunc: implementMethod(testSchema, async () => 'ok')
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Wrong type for count
|
|
51
|
+
await expect(mockClient.testFunc('user-1', 'not-a-number' as any))
|
|
52
|
+
.rejects.toThrow();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should throw ZodError for invalid named inputs', async () => {
|
|
56
|
+
const mockClient = {
|
|
57
|
+
testFunc: implementMethod(testSchema, async () => 'ok')
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Missing required field 'count'
|
|
61
|
+
await expect(mockClient.testFunc({ id: 'user-3' } as any))
|
|
62
|
+
.rejects.toThrow();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should preserve this context', async () => {
|
|
66
|
+
class Client {
|
|
67
|
+
name = 'test-client';
|
|
68
|
+
testFunc = implementMethod(testSchema, async function (this: Client, params) {
|
|
69
|
+
return `${this.name}-${params.id}`;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const client = new Client();
|
|
74
|
+
const result = await client.testFunc('xyz', 1);
|
|
75
|
+
expect(result).toBe('test-client-xyz');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should bridge to pup by default', async () => {
|
|
79
|
+
const mockClient = {
|
|
80
|
+
pup: jest.fn().mockResolvedValue('pup-result'),
|
|
81
|
+
testFunc: implementMethod(testSchema)
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const result = await mockClient.testFunc('user-4', 10);
|
|
85
|
+
expect(result).toBe('pup-result');
|
|
86
|
+
expect(mockClient.pup).toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { buildKeyAliasMap, clientRegistry, normalizeParameterKeys } from './registry';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a runtime method from a Zod Function Schema.
|
|
6
|
+
* Handles argument normalization (Positional -> Object) automatically.
|
|
7
|
+
*
|
|
8
|
+
* This function versions the schema definition to the actual runtime implementation,
|
|
9
|
+
* leveraging native Zod function capabilities for built-in validation.
|
|
10
|
+
*
|
|
11
|
+
* @param schema - The Zod function schema created by defineMethodV2
|
|
12
|
+
* @param implementation - Optional custom implementation. If omitted, defaults to generic WAPI call via this.pup
|
|
13
|
+
* @returns A validated async function that can be called with either positional or named arguments
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Default implementation (auto-bridges to WAPI)
|
|
17
|
+
* class Client {
|
|
18
|
+
* sendText = implementMethod(sendTextSchema);
|
|
19
|
+
* async pup(func: Function, args: any) { ... }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export function implementMethod<
|
|
23
|
+
Schema extends z.ZodFunction<any, any>
|
|
24
|
+
>(
|
|
25
|
+
schema: Schema,
|
|
26
|
+
implementation?: (this: any, params: any) => Promise<ReturnType<z.infer<Schema>>>
|
|
27
|
+
): (...args: Parameters<z.infer<Schema>>) => Promise<ReturnType<z.infer<Schema>>> {
|
|
28
|
+
const def = clientRegistry.getBySchema(schema as any);
|
|
29
|
+
if (!def) {
|
|
30
|
+
throw new Error('Schema is not registered in clientRegistry');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const meta = def.meta;
|
|
34
|
+
const keyAliasMap = buildKeyAliasMap(meta.inputSchema.shape);
|
|
35
|
+
|
|
36
|
+
return (async function (this: any, ...args: any[]) {
|
|
37
|
+
let resolvedParams: any = {};
|
|
38
|
+
|
|
39
|
+
if (args.length === 1 && typeof args[0] === 'object' && !Array.isArray(args[0])) {
|
|
40
|
+
resolvedParams = args[0];
|
|
41
|
+
} else {
|
|
42
|
+
resolvedParams = (meta.parameterOrder || []).reduce((acc: any, key: string, index: number) => {
|
|
43
|
+
if (index < args.length) {
|
|
44
|
+
acc[key] = args[index];
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
}, {} as any);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const normalizedParams = normalizeParameterKeys(resolvedParams, keyAliasMap);
|
|
51
|
+
const validatedParams = await meta.inputSchema.parseAsync(normalizedParams);
|
|
52
|
+
|
|
53
|
+
if (implementation) {
|
|
54
|
+
return await implementation.call(this, validatedParams);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this && typeof this.execute === 'function') {
|
|
58
|
+
return await this.execute(meta.wapiOverride || meta.functionName, validatedParams);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!this || typeof this.pup !== 'function') {
|
|
62
|
+
throw new Error(`Method ${meta.functionName} requires this.pup() for default implementation`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return await this.pup(
|
|
66
|
+
(params: any) => (window as any).WAPI[meta.wapiOverride || meta.functionName](params),
|
|
67
|
+
validatedParams
|
|
68
|
+
);
|
|
69
|
+
}) as (...args: Parameters<z.infer<Schema>>) => Promise<ReturnType<z.infer<Schema>>>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Alias for implementMethod
|
|
74
|
+
*/
|
|
75
|
+
export const implementMethodAsync = implementMethod;
|