@open-wa/schema 5.0.0-alpha.2 → 5.0.0-alpha.4
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/dist/generated/index.cjs +598 -0
- package/dist/generated/index.cjs.map +1 -0
- package/dist/generated/index.d.cts +3674 -0
- package/dist/generated/index.d.cts.map +1 -0
- package/dist/generated/index.d.mts +3674 -0
- package/dist/generated/index.d.mts.map +1 -0
- package/dist/generated/index.mjs +595 -0
- package/dist/generated/index.mjs.map +1 -0
- package/dist/http-manifest-BQIxNSNP.d.mts +177 -0
- package/dist/http-manifest-BQIxNSNP.d.mts.map +1 -0
- package/dist/http-manifest-Cgp405eE.d.cts +177 -0
- package/dist/http-manifest-Cgp405eE.d.cts.map +1 -0
- package/dist/http-manifest.cjs +59 -0
- package/dist/http-manifest.cjs.map +1 -0
- package/dist/http-manifest.d.cts +2 -0
- package/dist/http-manifest.d.mts +2 -0
- package/dist/http-manifest.mjs +58 -0
- package/dist/http-manifest.mjs.map +1 -0
- package/dist/implementor-DIBNbQXA.d.cts +8 -0
- package/dist/implementor-DIBNbQXA.d.cts.map +1 -0
- package/dist/implementor-DoN9ga7C.d.mts +8 -0
- package/dist/implementor-DoN9ga7C.d.mts.map +1 -0
- package/dist/implementor.cjs +50 -0
- package/dist/implementor.cjs.map +1 -0
- package/dist/implementor.d.cts +2 -0
- package/dist/implementor.d.mts +2 -0
- package/dist/implementor.mjs +48 -0
- package/dist/implementor.mjs.map +1 -0
- package/dist/index-BpnIT_UN.d.mts +1323 -0
- package/dist/index-BpnIT_UN.d.mts.map +1 -0
- package/dist/index-BsqJbJE4.d.cts +1323 -0
- package/dist/index-BsqJbJE4.d.cts.map +1 -0
- package/dist/index.cjs +649 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +299 -0
- package/dist/index.mjs.map +1 -0
- package/dist/methods/index.cjs +125 -0
- package/dist/methods/index.d.cts +2 -0
- package/dist/methods/index.d.mts +2 -0
- package/dist/methods/index.mjs +2 -0
- package/dist/methods-BXZrkKjP.mjs +2633 -0
- package/dist/methods-BXZrkKjP.mjs.map +1 -0
- package/dist/methods-CuiwUO7-.cjs +3802 -0
- package/dist/methods-CuiwUO7-.cjs.map +1 -0
- package/dist/registry-CsyR8i6y.mjs +284 -0
- package/dist/registry-CsyR8i6y.mjs.map +1 -0
- package/dist/registry-TbMVoiw5.cjs +355 -0
- package/dist/registry-TbMVoiw5.cjs.map +1 -0
- package/package.json +6 -3
- package/CHANGELOG.md +0 -31
- package/client_migration_doc.md +0 -467
- package/codecs_and_params_plan.md +0 -936
- package/migration_plan_doc.md +0 -223
- package/scripts/gen-client-implementation.ts +0 -129
- package/scripts/gen-client-reference-docs.ts +0 -621
- package/scripts/gen-openapi.ts +0 -96
- package/scripts/gen-types.ts +0 -43
- package/scripts/verify-v5-pipeline.ts +0 -85
- package/src/__tests__/generators.contract.test.ts +0 -181
- package/src/__tests__/registry.contract.test.ts +0 -81
- package/src/client-config.ts +0 -30
- package/src/codecs.test.ts +0 -41
- package/src/codecs.ts +0 -191
- package/src/common-types.ts +0 -280
- package/src/config.ts +0 -47
- package/src/enums.ts +0 -63
- package/src/events/groups.ts +0 -33
- package/src/events/index.ts +0 -4
- package/src/events/messaging.ts +0 -72
- package/src/events/registry.ts +0 -114
- package/src/events/state.ts +0 -59
- package/src/generated/AliasMap.ts +0 -214
- package/src/generated/BaseClient.ts +0 -868
- package/src/generated/BaseNamespacedClient.ts +0 -212
- package/src/generated/index.ts +0 -5
- package/src/generated/openapi.json +0 -7799
- package/src/generated/types.ts +0 -377
- package/src/http-manifest.ts +0 -97
- package/src/implementor.test.ts +0 -88
- package/src/implementor.ts +0 -75
- package/src/index.ts +0 -43
- package/src/methods/business.ts +0 -51
- package/src/methods/chats.ts +0 -263
- package/src/methods/communities.ts +0 -119
- package/src/methods/contacts.ts +0 -158
- package/src/methods/groups.ts +0 -376
- package/src/methods/index.ts +0 -33
- package/src/methods/labels.ts +0 -86
- package/src/methods/media.ts +0 -36
- package/src/methods/messaging.ts +0 -828
- package/src/methods/session.ts +0 -261
- package/src/methods/status.ts +0 -120
- package/src/open-wa-utils.d.ts +0 -4
- package/src/parameters.ts +0 -237
- package/src/registry.test.ts +0 -30
- package/src/registry.ts +0 -601
- package/tsconfig.generated.json +0 -11
- package/tsconfig.json +0 -15
- package/tsdown.config.ts +0 -16
- package/vitest.config.ts +0 -10
package/src/codecs.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { assertFile, getDUrl } from '@open-wa/utils';
|
|
3
|
-
|
|
4
|
-
const chatIdPattern = /^\d+(-\d+)?@(c|g)\.us$|^\d+@lid$/;
|
|
5
|
-
const contactIdPattern = /^\d+@c\.us$/;
|
|
6
|
-
const groupIdPattern = /^\d+(-\d+)?@g\.us$/;
|
|
7
|
-
const messageIdPattern = /^(true|false)_.+_.+$/;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Chat ID Codec
|
|
11
|
-
* Intelligently converts phone numbers to proper WhatsApp chat IDs.
|
|
12
|
-
*/
|
|
13
|
-
export const chatIdCodec = {
|
|
14
|
-
decode: (input: string): string => {
|
|
15
|
-
if (input.includes('@')) {
|
|
16
|
-
return input;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const digits = input.replace(/\D/g, '');
|
|
20
|
-
const digitCount = digits.length;
|
|
21
|
-
|
|
22
|
-
if (digitCount === 18) {
|
|
23
|
-
return `${digits}@g.us`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (digitCount === 14 && !digits.startsWith('62')) {
|
|
27
|
-
return `${digits}@lid`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return `${digits}@c.us`;
|
|
31
|
-
},
|
|
32
|
-
encode: (chatId: string): string => chatId,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Contact ID Codec - always formats as @c.us
|
|
37
|
-
*/
|
|
38
|
-
export const contactIdCodec = {
|
|
39
|
-
decode: (input: string): string => {
|
|
40
|
-
if (input.endsWith('@c.us')) {
|
|
41
|
-
return input;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return `${input.replace(/\D/g, '')}@c.us`;
|
|
45
|
-
},
|
|
46
|
-
encode: (contactId: string): string => contactId,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Group ID Codec - always formats as @g.us
|
|
51
|
-
*/
|
|
52
|
-
export const groupIdCodec = {
|
|
53
|
-
decode: (input: string): string => {
|
|
54
|
-
if (input.endsWith('@g.us')) {
|
|
55
|
-
return input;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return `${input.replace(/\D/g, '')}@g.us`;
|
|
59
|
-
},
|
|
60
|
-
encode: (groupId: string): string => groupId,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Message ID Codec - validates format only
|
|
65
|
-
*/
|
|
66
|
-
export const messageIdCodec = {
|
|
67
|
-
decode: (input: string): string => input,
|
|
68
|
-
encode: (messageId: string): string => messageId,
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* File Codec Factory
|
|
73
|
-
*/
|
|
74
|
-
export const createFileCodec = (outputType: string) => ({
|
|
75
|
-
decode: async (input: unknown): Promise<unknown> => assertFile(input, outputType),
|
|
76
|
-
encode: (output: unknown) => output,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
export const fileToDataUrlCodec = createFileCodec('DATA_URL');
|
|
80
|
-
export const fileToBase64Codec = createFileCodec('BASE_64');
|
|
81
|
-
export const fileToBufferCodec = createFileCodec('BUFFER');
|
|
82
|
-
export const fileToTempPathCodec = createFileCodec('TEMP_FILE_PATH');
|
|
83
|
-
export const fileToStreamCodec = createFileCodec('READ_STREAM');
|
|
84
|
-
|
|
85
|
-
export const base64ToDataUrlCodec = {
|
|
86
|
-
decode: (base64: string): string => {
|
|
87
|
-
if (base64.startsWith('data:')) {
|
|
88
|
-
return base64;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return `data:application/octet-stream;base64,${base64}`;
|
|
92
|
-
},
|
|
93
|
-
encode: (dataUrl: string): string => dataUrl.split(',')[1] || dataUrl,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const urlToDataUrlCodec = {
|
|
97
|
-
decode: async (url: string): Promise<string> => getDUrl(url),
|
|
98
|
-
encode: (_dataUrl: string): string => {
|
|
99
|
-
throw new Error('Cannot encode DataURL back to URL');
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const isoDatetimeToDate = {
|
|
104
|
-
decode: (isoString: string): Date => new Date(isoString),
|
|
105
|
-
encode: (date: Date): string => date.toISOString(),
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export const unixSecondsToDate = {
|
|
109
|
-
decode: (seconds: number): Date => new Date(seconds * 1000),
|
|
110
|
-
encode: (date: Date): number => Math.floor(date.getTime() / 1000),
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export const unixMillisToDate = {
|
|
114
|
-
decode: (millis: number): Date => new Date(millis),
|
|
115
|
-
encode: (date: Date): number => date.getTime(),
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export const hexColorCodec = {
|
|
119
|
-
decode: (input: string): string => input.replace('#', '').toUpperCase(),
|
|
120
|
-
encode: (hex: string): string => `#${hex}`,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export const jsonStringCodec = <T>(schema: z.ZodType<T>) =>
|
|
124
|
-
z.codec(z.string(), schema, {
|
|
125
|
-
decode: (jsonString: string): T => schema.parse(JSON.parse(jsonString)),
|
|
126
|
-
encode: (value: T): string => JSON.stringify(value),
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
export const ChatIdSchema = z.codec(
|
|
130
|
-
z.string(),
|
|
131
|
-
z.string().regex(chatIdPattern).brand('ChatId'),
|
|
132
|
-
chatIdCodec
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
export const ContactIdSchema = z.codec(
|
|
136
|
-
z.string(),
|
|
137
|
-
z.string().regex(contactIdPattern).brand('ContactId'),
|
|
138
|
-
contactIdCodec
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
export const GroupIdSchema = z.codec(
|
|
142
|
-
z.string(),
|
|
143
|
-
z.string().regex(groupIdPattern).brand('GroupChatId'),
|
|
144
|
-
groupIdCodec
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
export const MessageIdSchema = z.codec(
|
|
148
|
-
z.string(),
|
|
149
|
-
z.string().regex(messageIdPattern).brand('MessageId'),
|
|
150
|
-
messageIdCodec
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
export const ChatIdCodecSchema = ChatIdSchema;
|
|
154
|
-
export const ContactIdCodecSchema = ContactIdSchema;
|
|
155
|
-
export const GroupIdCodecSchema = GroupIdSchema;
|
|
156
|
-
export const MessageIdCodecSchema = MessageIdSchema;
|
|
157
|
-
|
|
158
|
-
export const FileToDataUrlSchema = z
|
|
159
|
-
.union([z.string(), z.instanceof(Buffer)])
|
|
160
|
-
.transform(async (input) => fileToDataUrlCodec.decode(input))
|
|
161
|
-
.pipe(z.string().regex(/^data:.+;base64,.+$/).brand('DataURL'));
|
|
162
|
-
|
|
163
|
-
export const Base64ToDataUrlSchema = z.codec(
|
|
164
|
-
z.string(),
|
|
165
|
-
z.string().regex(/^data:.+;base64,.+$/).brand('DataURL'),
|
|
166
|
-
base64ToDataUrlCodec
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
export const HexColorSchema = z.codec(
|
|
170
|
-
z.string(),
|
|
171
|
-
z.string().regex(/^[0-9A-F]+$/),
|
|
172
|
-
hexColorCodec
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
export const IsoDatetimeToDateSchema = z.codec(
|
|
176
|
-
z.iso.datetime(),
|
|
177
|
-
z.date(),
|
|
178
|
-
isoDatetimeToDate
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
export const UnixSecondsToDateSchema = z.codec(
|
|
182
|
-
z.number().int().min(0),
|
|
183
|
-
z.date(),
|
|
184
|
-
unixSecondsToDate
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
export const UnixMillisToDateSchema = z.codec(
|
|
188
|
-
z.number().int().min(0),
|
|
189
|
-
z.date(),
|
|
190
|
-
unixMillisToDate
|
|
191
|
-
);
|
package/src/common-types.ts
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
// Aliases
|
|
4
|
-
export const ContactIdSchema = z.string().brand('ContactId');
|
|
5
|
-
export type ContactId = z.infer<typeof ContactIdSchema>;
|
|
6
|
-
|
|
7
|
-
export const ChatIdSchema = z.string().brand('ChatId');
|
|
8
|
-
export type ChatId = z.infer<typeof ChatIdSchema>;
|
|
9
|
-
|
|
10
|
-
export const MessageIdSchema = z.string().brand('MessageId');
|
|
11
|
-
export type MessageId = z.infer<typeof MessageIdSchema>;
|
|
12
|
-
|
|
13
|
-
export const GroupChatIdSchema = z.string().brand('GroupChatId');
|
|
14
|
-
export type GroupChatId = z.infer<typeof GroupChatIdSchema>;
|
|
15
|
-
|
|
16
|
-
export const GroupIdSchema = z.string().brand('GroupId');
|
|
17
|
-
export type GroupId = z.infer<typeof GroupIdSchema>;
|
|
18
|
-
|
|
19
|
-
export type DataURL = `data:${string};base64,${string}`;
|
|
20
|
-
export type Base64 = string;
|
|
21
|
-
export type Content = string | DataURL | Base64 | Buffer;
|
|
22
|
-
|
|
23
|
-
export const GroupMetadataSchema = z.object({
|
|
24
|
-
id: GroupIdSchema,
|
|
25
|
-
subject: z.string(),
|
|
26
|
-
creation: z.number(),
|
|
27
|
-
owner: ContactIdSchema.optional(),
|
|
28
|
-
desc: z.string().optional(),
|
|
29
|
-
descTime: z.number().optional(),
|
|
30
|
-
descOwner: ContactIdSchema.optional(),
|
|
31
|
-
restrict: z.boolean().optional(),
|
|
32
|
-
announce: z.boolean().optional(),
|
|
33
|
-
participants: z.array(z.object({
|
|
34
|
-
id: ContactIdSchema,
|
|
35
|
-
isAdmin: z.boolean(),
|
|
36
|
-
isSuperAdmin: z.boolean().optional(),
|
|
37
|
-
})),
|
|
38
|
-
}).passthrough();
|
|
39
|
-
export type GroupMetadata = z.infer<typeof GroupMetadataSchema>;
|
|
40
|
-
|
|
41
|
-
// Id
|
|
42
|
-
export const IdSchema = z.object({
|
|
43
|
-
server: z.string(),
|
|
44
|
-
user: z.string(),
|
|
45
|
-
_serialized: z.string(),
|
|
46
|
-
});
|
|
47
|
-
export type Id = z.infer<typeof IdSchema>;
|
|
48
|
-
|
|
49
|
-
// Enums
|
|
50
|
-
export enum MessageTypes {
|
|
51
|
-
TEXT = 'chat',
|
|
52
|
-
AUDIO = 'audio',
|
|
53
|
-
VOICE = 'ptt',
|
|
54
|
-
IMAGE = 'image',
|
|
55
|
-
VIDEO = 'video',
|
|
56
|
-
DOCUMENT = 'document',
|
|
57
|
-
STICKER = 'sticker',
|
|
58
|
-
LOCATION = 'location',
|
|
59
|
-
CONTACT_CARD = 'vcard',
|
|
60
|
-
CONTACT_CARD_MULTI = 'multi_vcard',
|
|
61
|
-
REVOKED = 'revoked',
|
|
62
|
-
ORDER = 'order',
|
|
63
|
-
BUTTONS_RESPONSE = 'buttons_response',
|
|
64
|
-
LIST_RESPONSE = "list_response",
|
|
65
|
-
UNKNOWN = 'unknown'
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export enum MessageAck {
|
|
69
|
-
ACK_ERROR = -1,
|
|
70
|
-
ACK_PENDING = 0,
|
|
71
|
-
ACK_SERVER = 1,
|
|
72
|
-
ACK_DEVICE = 2,
|
|
73
|
-
ACK_READ = 3,
|
|
74
|
-
ACK_PLAYED = 4,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* An enum of all the "simple listeners". A simple listener is a listener that just takes one parameter which is the callback function to handle the event.
|
|
79
|
-
*/
|
|
80
|
-
export enum SimpleListener {
|
|
81
|
-
/**
|
|
82
|
-
* Represents [[onMessage]]
|
|
83
|
-
*/
|
|
84
|
-
Message = 'onMessage',
|
|
85
|
-
/**
|
|
86
|
-
* Represents [[onAnyMessage]]
|
|
87
|
-
*/
|
|
88
|
-
AnyMessage = 'onAnyMessage',
|
|
89
|
-
/**
|
|
90
|
-
* Represents [[onMessageDeleted]]
|
|
91
|
-
*/
|
|
92
|
-
MessageDeleted = 'onMessageDeleted',
|
|
93
|
-
/**
|
|
94
|
-
* Represents [[onAck]]
|
|
95
|
-
*/
|
|
96
|
-
Ack = 'onAck',
|
|
97
|
-
/**
|
|
98
|
-
* Represents [[onAddedToGroup]]
|
|
99
|
-
*/
|
|
100
|
-
AddedToGroup = 'onAddedToGroup',
|
|
101
|
-
/**
|
|
102
|
-
* Represents [[onChatDeleted]]
|
|
103
|
-
*/
|
|
104
|
-
ChatDeleted = 'onChatDeleted',
|
|
105
|
-
/**
|
|
106
|
-
* Represents [[onBattery]]
|
|
107
|
-
*/
|
|
108
|
-
Battery = 'onBattery',
|
|
109
|
-
/**
|
|
110
|
-
* Represents [[onChatOpened]]
|
|
111
|
-
*/
|
|
112
|
-
ChatOpened = 'onChatOpened',
|
|
113
|
-
/**
|
|
114
|
-
* Represents [[onIncomingCall]]
|
|
115
|
-
*/
|
|
116
|
-
IncomingCall = 'onIncomingCall',
|
|
117
|
-
/**
|
|
118
|
-
* Represents [[onGlobalParticipantsChanged]]
|
|
119
|
-
*/
|
|
120
|
-
GlobalParticipantsChanged = 'onGlobalParticipantsChanged',
|
|
121
|
-
/**
|
|
122
|
-
* Represents [[onChatState]]
|
|
123
|
-
*/
|
|
124
|
-
ChatState = 'onChatState',
|
|
125
|
-
/**
|
|
126
|
-
* Represents [[onLogout]]
|
|
127
|
-
*/
|
|
128
|
-
Logout = 'onLogout',
|
|
129
|
-
/**
|
|
130
|
-
* Represents [[onPlugged]]
|
|
131
|
-
*/
|
|
132
|
-
Plugged = 'onPlugged',
|
|
133
|
-
/**
|
|
134
|
-
* Represents [[onStateChanged]]
|
|
135
|
-
*/
|
|
136
|
-
StateChanged = 'onStateChanged',
|
|
137
|
-
/**
|
|
138
|
-
* Represents [[onButton]]
|
|
139
|
-
*/
|
|
140
|
-
Button = 'onButton',
|
|
141
|
-
/**
|
|
142
|
-
* Requires licence
|
|
143
|
-
* Represents [[onStory]]
|
|
144
|
-
*/
|
|
145
|
-
Story = 'onStory',
|
|
146
|
-
/**
|
|
147
|
-
* Requires licence
|
|
148
|
-
* Represents [[onRemovedFromGroup]]
|
|
149
|
-
*/
|
|
150
|
-
RemovedFromGroup = 'onRemovedFromGroup',
|
|
151
|
-
/**
|
|
152
|
-
* Requires licence
|
|
153
|
-
* Represents [[onContactAdded]]
|
|
154
|
-
*/
|
|
155
|
-
ContactAdded = 'onContactAdded',
|
|
156
|
-
/**
|
|
157
|
-
* Represents [[onOrder]]
|
|
158
|
-
*/
|
|
159
|
-
Order = 'onOrder',
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Forward declarations
|
|
163
|
-
const MessageSchemaBase = z.object({
|
|
164
|
-
id: MessageIdSchema,
|
|
165
|
-
body: z.string(),
|
|
166
|
-
type: z.nativeEnum(MessageTypes),
|
|
167
|
-
t: z.number(),
|
|
168
|
-
notifyName: z.string().optional(),
|
|
169
|
-
from: ChatIdSchema,
|
|
170
|
-
to: ChatIdSchema,
|
|
171
|
-
self: z.enum(['in', 'out']),
|
|
172
|
-
ack: z.nativeEnum(MessageAck),
|
|
173
|
-
invis: z.boolean().optional(),
|
|
174
|
-
isNewMsg: z.boolean().optional(),
|
|
175
|
-
star: z.boolean().optional(),
|
|
176
|
-
recvFresh: z.boolean().optional(),
|
|
177
|
-
broadcast: z.boolean().optional(),
|
|
178
|
-
isForwarded: z.boolean().optional(),
|
|
179
|
-
labels: z.array(z.string()).optional(),
|
|
180
|
-
mentionedJidList: z.array(ContactIdSchema).optional(),
|
|
181
|
-
caption: z.string().optional(),
|
|
182
|
-
sender: z.any(), // Circular reference handled later/lazy
|
|
183
|
-
timestamp: z.number(),
|
|
184
|
-
content: z.string(),
|
|
185
|
-
isGroupMsg: z.boolean(),
|
|
186
|
-
isMMS: z.boolean().optional(),
|
|
187
|
-
isMedia: z.boolean(),
|
|
188
|
-
isNotification: z.boolean(),
|
|
189
|
-
isPSA: z.boolean().optional(),
|
|
190
|
-
fromMe: z.boolean(),
|
|
191
|
-
chat: z.any(), // Circular reference handled later/lazy
|
|
192
|
-
chatId: ChatIdSchema,
|
|
193
|
-
author: z.string().optional(),
|
|
194
|
-
clientUrl: z.string().optional(),
|
|
195
|
-
deprecatedMms3Url: z.string().optional(),
|
|
196
|
-
isQuotedMsgAvailable: z.boolean(),
|
|
197
|
-
quotedMsg: z.any().optional(), // z.lazy(() => MessageSchema.optional()),
|
|
198
|
-
quotedMsgObj: z.any().optional(), // z.lazy(() => MessageSchema.optional()),
|
|
199
|
-
senderId: z.string().optional(),
|
|
200
|
-
}).passthrough();
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// Contact
|
|
204
|
-
export const ContactSchema = z.object({
|
|
205
|
-
id: ContactIdSchema,
|
|
206
|
-
name: z.string().optional(),
|
|
207
|
-
shortName: z.string().optional(),
|
|
208
|
-
pushname: z.string().optional(),
|
|
209
|
-
formattedName: z.string().optional(),
|
|
210
|
-
isBusiness: z.boolean().optional(),
|
|
211
|
-
isEnterprise: z.boolean().optional(),
|
|
212
|
-
isMe: z.boolean().optional(),
|
|
213
|
-
isMyContact: z.boolean().optional(),
|
|
214
|
-
isPSA: z.boolean().optional(),
|
|
215
|
-
isUser: z.boolean().optional(),
|
|
216
|
-
isWAContact: z.boolean().optional(),
|
|
217
|
-
labels: z.array(z.string()).optional(),
|
|
218
|
-
msgs: z.array(z.any()).optional(), // Avoid infinite recursion
|
|
219
|
-
profilePicThumbObj: z.object({
|
|
220
|
-
eurl: z.string().optional(),
|
|
221
|
-
id: IdSchema.optional(),
|
|
222
|
-
img: z.string().optional(),
|
|
223
|
-
imgFull: z.string().optional(),
|
|
224
|
-
tag: z.string().optional(),
|
|
225
|
-
}).optional(),
|
|
226
|
-
statusMute: z.boolean().optional(),
|
|
227
|
-
type: z.string().optional(),
|
|
228
|
-
verifiedLevel: z.number().optional(),
|
|
229
|
-
verifiedName: z.string().optional(),
|
|
230
|
-
isOnline: z.boolean().optional(),
|
|
231
|
-
lastSeen: z.number().optional(),
|
|
232
|
-
}).passthrough();
|
|
233
|
-
|
|
234
|
-
export type Contact = z.infer<typeof ContactSchema>;
|
|
235
|
-
|
|
236
|
-
// Location
|
|
237
|
-
export const LocationSchema = z.object({
|
|
238
|
-
lat: z.number().describe('Latitude coordinate'),
|
|
239
|
-
lng: z.number().describe('Longitude coordinate'),
|
|
240
|
-
name: z.string().optional().describe('Location name'),
|
|
241
|
-
address: z.string().optional().describe('Formatted address'),
|
|
242
|
-
url: z.string().optional().describe('WhatsApp location URL'),
|
|
243
|
-
}).passthrough();
|
|
244
|
-
|
|
245
|
-
export type Location = z.infer<typeof LocationSchema>;
|
|
246
|
-
|
|
247
|
-
// Chat
|
|
248
|
-
export const ChatSchema = z.object({
|
|
249
|
-
id: ContactIdSchema.or(GroupChatIdSchema),
|
|
250
|
-
name: z.string().optional(),
|
|
251
|
-
formattedTitle: z.string().optional(),
|
|
252
|
-
isGroup: z.boolean(),
|
|
253
|
-
contact: ContactSchema,
|
|
254
|
-
groupMetadata: z.any().optional(), // Metadata
|
|
255
|
-
presence: z.any().optional(),
|
|
256
|
-
t: z.number().optional(),
|
|
257
|
-
unreadCount: z.number().optional(),
|
|
258
|
-
lastReceivedKey: z.any().optional(),
|
|
259
|
-
msgs: z.array(z.any()).optional(), // Avoid infinite recursion
|
|
260
|
-
isReadOnly: z.boolean().optional(),
|
|
261
|
-
muteExpiration: z.number().optional(),
|
|
262
|
-
notSpam: z.boolean().optional(),
|
|
263
|
-
pin: z.number().optional(),
|
|
264
|
-
ack: z.any().optional(),
|
|
265
|
-
}).passthrough();
|
|
266
|
-
|
|
267
|
-
export type Chat = z.infer<typeof ChatSchema>;
|
|
268
|
-
|
|
269
|
-
// Full Message Schema with implementations
|
|
270
|
-
export const MessageSchema = MessageSchemaBase.extend({
|
|
271
|
-
sender: ContactSchema,
|
|
272
|
-
chat: ChatSchema,
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
export type Message = z.infer<typeof MessageSchema>;
|
|
276
|
-
|
|
277
|
-
// Additional return types
|
|
278
|
-
export const MessageIdReturnSchema = z.object({
|
|
279
|
-
_serialized: z.string(),
|
|
280
|
-
}).passthrough();
|
package/src/config.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration schema and types - re-exported from @open-wa/config
|
|
3
|
-
*
|
|
4
|
-
* This file provides backward compatibility for code that imports from @open-wa/schema.
|
|
5
|
-
* New code should import directly from @open-wa/config.
|
|
6
|
-
*
|
|
7
|
-
* @deprecated Import from '@open-wa/config' instead
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// Re-export everything from @open-wa/config
|
|
11
|
-
export {
|
|
12
|
-
// Enums
|
|
13
|
-
QRFormat,
|
|
14
|
-
CLOUD_PROVIDERS,
|
|
15
|
-
DIRECTORY_STRATEGY,
|
|
16
|
-
NotificationLanguage,
|
|
17
|
-
OnError,
|
|
18
|
-
LicenseType,
|
|
19
|
-
// Sub-schemas
|
|
20
|
-
SessionDataSchema,
|
|
21
|
-
DevToolsSchema,
|
|
22
|
-
ProxyServerCredentialsSchema,
|
|
23
|
-
CloudUploadOptionsSchema,
|
|
24
|
-
ViewportSchema,
|
|
25
|
-
S3SyncSchema,
|
|
26
|
-
LoggingTransportSchema,
|
|
27
|
-
// Main schema
|
|
28
|
-
ConfigSchema,
|
|
29
|
-
PartialConfigSchema,
|
|
30
|
-
StrictConfigSchema,
|
|
31
|
-
// Types
|
|
32
|
-
type Config,
|
|
33
|
-
type PartialConfig,
|
|
34
|
-
type DeepPartialConfig,
|
|
35
|
-
type StrictConfig,
|
|
36
|
-
type SessionData,
|
|
37
|
-
type DevTools,
|
|
38
|
-
type ProxyServerCredentials,
|
|
39
|
-
type CloudUploadOptions,
|
|
40
|
-
type Viewport,
|
|
41
|
-
type S3Sync,
|
|
42
|
-
type LoggingTransport,
|
|
43
|
-
// Validation helpers
|
|
44
|
-
validateConfig,
|
|
45
|
-
parseConfig,
|
|
46
|
-
getDefaultConfig,
|
|
47
|
-
} from '@open-wa/config';
|
package/src/enums.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Action types for RBAC permissions
|
|
5
|
-
* - read: Retrieve data (e.g., get contact, chat object)
|
|
6
|
-
* - send: Create/send new content (e.g., send message, image, story)
|
|
7
|
-
* - update: Modify existing data (e.g., update message, chat metadata, promote admin)
|
|
8
|
-
* - delete: Remove data (e.g., delete chat, story, remove contact, demote admin)
|
|
9
|
-
*/
|
|
10
|
-
export const ActionEnum = z.enum([
|
|
11
|
-
'read',
|
|
12
|
-
'send',
|
|
13
|
-
'update',
|
|
14
|
-
'delete'
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
export type ActionType = z.infer<typeof ActionEnum>;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* License tiers for feature gating
|
|
21
|
-
* - none: Available to all users
|
|
22
|
-
* - insiders: Requires insiders license
|
|
23
|
-
* - restricted: Requires special/restricted license
|
|
24
|
-
*/
|
|
25
|
-
export const LicenseEnum = z.enum([
|
|
26
|
-
'none',
|
|
27
|
-
'insiders',
|
|
28
|
-
'restricted'
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
export type LicenseTier = z.infer<typeof LicenseEnum>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Functionality scope for WhatsApp account types
|
|
35
|
-
* - both: Works on both business and personal accounts
|
|
36
|
-
* - business-only: Only works on business accounts
|
|
37
|
-
* - personal-only: Only works on personal accounts
|
|
38
|
-
*/
|
|
39
|
-
export const FunctionalityEnum = z.enum([
|
|
40
|
-
'both',
|
|
41
|
-
'business-only',
|
|
42
|
-
'personal-only'
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
export type FunctionalityScope = z.infer<typeof FunctionalityEnum>;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* HTTP methods for API mapping
|
|
49
|
-
* - AUTO: Automatically inferred from action type or defaults to POST
|
|
50
|
-
* - GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD: Standard HTTP methods
|
|
51
|
-
*/
|
|
52
|
-
export const HttpMethodEnum = z.enum([
|
|
53
|
-
'AUTO',
|
|
54
|
-
'GET',
|
|
55
|
-
'POST',
|
|
56
|
-
'PUT',
|
|
57
|
-
'DELETE',
|
|
58
|
-
'PATCH',
|
|
59
|
-
'OPTIONS',
|
|
60
|
-
'HEAD'
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
|
-
export type HttpMethod = z.infer<typeof HttpMethodEnum>;
|
package/src/events/groups.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { defineListenerV2 } from './registry';
|
|
3
|
-
|
|
4
|
-
export const participantsChangedEvent = defineListenerV2('participantsChanged', {
|
|
5
|
-
legacyName: 'onParticipantsChanged',
|
|
6
|
-
meta: {
|
|
7
|
-
description: 'Fired when group participants change',
|
|
8
|
-
namespace: 'groups',
|
|
9
|
-
status: 'stable',
|
|
10
|
-
license: 'none',
|
|
11
|
-
},
|
|
12
|
-
payload: z.object({
|
|
13
|
-
groupId: z.string(),
|
|
14
|
-
action: z.enum(['add', 'remove', 'promote', 'demote']),
|
|
15
|
-
participantIds: z.array(z.string()),
|
|
16
|
-
by: z.string().optional(),
|
|
17
|
-
}),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export const addedToGroupEvent = defineListenerV2('addedToGroup', {
|
|
21
|
-
legacyName: 'onAddedToGroup',
|
|
22
|
-
meta: {
|
|
23
|
-
description: 'Fired when you are added to a group',
|
|
24
|
-
namespace: 'groups',
|
|
25
|
-
status: 'stable',
|
|
26
|
-
license: 'none',
|
|
27
|
-
},
|
|
28
|
-
payload: z.object({
|
|
29
|
-
groupId: z.string(),
|
|
30
|
-
groupName: z.string(),
|
|
31
|
-
addedBy: z.string().optional(),
|
|
32
|
-
}),
|
|
33
|
-
});
|
package/src/events/index.ts
DELETED
package/src/events/messaging.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { defineListenerV2 } from './registry';
|
|
3
|
-
import { MessageSchema, MessageAck } from '../common-types';
|
|
4
|
-
|
|
5
|
-
const AckSchema = z.object({
|
|
6
|
-
id: z.string(),
|
|
7
|
-
chatId: z.string(),
|
|
8
|
-
ack: z.nativeEnum(MessageAck),
|
|
9
|
-
timestamp: z.number().optional(),
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export const messageEvent = defineListenerV2('message', {
|
|
13
|
-
legacyName: 'onMessage',
|
|
14
|
-
meta: {
|
|
15
|
-
description: 'Fired when a new message is received (excluding own messages)',
|
|
16
|
-
namespace: 'messages',
|
|
17
|
-
status: 'stable',
|
|
18
|
-
license: 'none',
|
|
19
|
-
},
|
|
20
|
-
payload: MessageSchema,
|
|
21
|
-
defaultQueueOptions: { concurrency: 1 },
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export const anyMessageEvent = defineListenerV2('anyMessage', {
|
|
25
|
-
legacyName: 'onAnyMessage',
|
|
26
|
-
meta: {
|
|
27
|
-
description: 'Fired for any message including own messages',
|
|
28
|
-
namespace: 'messages',
|
|
29
|
-
status: 'stable',
|
|
30
|
-
license: 'none',
|
|
31
|
-
},
|
|
32
|
-
payload: MessageSchema,
|
|
33
|
-
defaultQueueOptions: { concurrency: 1 },
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
export const messageDeletedEvent = defineListenerV2('messageDeleted', {
|
|
37
|
-
legacyName: 'onMessageDeleted',
|
|
38
|
-
meta: {
|
|
39
|
-
description: 'Fired when a message is deleted',
|
|
40
|
-
namespace: 'messages',
|
|
41
|
-
status: 'stable',
|
|
42
|
-
license: 'none',
|
|
43
|
-
},
|
|
44
|
-
payload: MessageSchema,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export const ackEvent = defineListenerV2('ack', {
|
|
48
|
-
legacyName: 'onAck',
|
|
49
|
-
meta: {
|
|
50
|
-
description: 'Fired when a message acknowledgment is received',
|
|
51
|
-
namespace: 'messages',
|
|
52
|
-
status: 'stable',
|
|
53
|
-
license: 'none',
|
|
54
|
-
},
|
|
55
|
-
payload: AckSchema,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export const reactionEvent = defineListenerV2('reaction', {
|
|
59
|
-
legacyName: 'onReaction',
|
|
60
|
-
meta: {
|
|
61
|
-
description: 'Fired when a reaction is added to a message',
|
|
62
|
-
namespace: 'messages',
|
|
63
|
-
status: 'stable',
|
|
64
|
-
license: 'none',
|
|
65
|
-
},
|
|
66
|
-
payload: z.object({
|
|
67
|
-
messageId: z.string(),
|
|
68
|
-
reaction: z.string(),
|
|
69
|
-
senderId: z.string(),
|
|
70
|
-
timestamp: z.number(),
|
|
71
|
-
}),
|
|
72
|
-
});
|