wa-multi-mongodb 3.10.3 → 3.10.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.
@@ -102,4 +102,163 @@ export declare const getGroupMetadata: (sessionId: string, jid: string, forceFet
102
102
  export declare const clearGroupMetadataCache: (sessionId: string, jid: string) => Promise<void>;
103
103
  export declare const clearSessionGroupMetadataCache: (sessionId: string) => Promise<void>;
104
104
  export declare const clearAllGroupMetadataCache: () => void;
105
+ /**
106
+ * Result type for LID to PN conversion
107
+ */
108
+ export interface LIDConversionResult {
109
+ success: boolean;
110
+ lid: string;
111
+ pn: string | null;
112
+ error?: string;
113
+ }
114
+ /**
115
+ * Result type for PN to LID conversion
116
+ */
117
+ export interface PNConversionResult {
118
+ success: boolean;
119
+ pn: string;
120
+ lid: string | null;
121
+ error?: string;
122
+ }
123
+ /**
124
+ * LID Mapping entry type
125
+ */
126
+ export interface LIDMappingEntry {
127
+ lid: string;
128
+ pn: string;
129
+ }
130
+ /**
131
+ * Convert LID (Linked ID) to Phone Number (PN/JID)
132
+ *
133
+ * This function uses Baileys' internal signalRepository.lidMapping to retrieve
134
+ * the phone number associated with a given LID.
135
+ *
136
+ * @param sessionId - Session ID to use for conversion
137
+ * @param lid - The LID to convert (e.g., "1524746986546@lid")
138
+ * @returns Promise<LIDConversionResult> - Result object with the phone number or null if not found
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const result = await whatsapp.getPNForLID("mysession", "1524746986546@lid");
143
+ * if (result.success && result.pn) {
144
+ * console.log(`Phone number: ${result.pn}`);
145
+ * } else {
146
+ * console.log("Phone number not found for this LID");
147
+ * }
148
+ * ```
149
+ *
150
+ * @note This function may return null for new contacts or when WhatsApp
151
+ * hasn't provided the LID-PN mapping yet. Not all LIDs have known phone numbers.
152
+ */
153
+ export declare const getPNForLID: (sessionId: string, lid: string) => Promise<LIDConversionResult>;
154
+ /**
155
+ * Convert Phone Number (PN/JID) to LID (Linked ID)
156
+ *
157
+ * This function uses Baileys' internal signalRepository.lidMapping to retrieve
158
+ * the LID associated with a given phone number.
159
+ *
160
+ * @param sessionId - Session ID to use for conversion
161
+ * @param pn - The phone number/JID to convert (e.g., "6281234567890" or "6281234567890@s.whatsapp.net")
162
+ * @returns Promise<PNConversionResult> - Result object with the LID or null if not found
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const result = await whatsapp.getLIDForPN("mysession", "6281234567890");
167
+ * if (result.success && result.lid) {
168
+ * console.log(`LID: ${result.lid}`);
169
+ * } else {
170
+ * console.log("LID not found for this phone number");
171
+ * }
172
+ * ```
173
+ *
174
+ * @note This function may return null for contacts that haven't been encountered
175
+ * with their LID mapping yet.
176
+ */
177
+ export declare const getLIDForPN: (sessionId: string, pn: string) => Promise<PNConversionResult>;
178
+ /**
179
+ * Get all known LID-PN mappings for a session
180
+ *
181
+ * This function retrieves all LID to phone number mappings that are currently
182
+ * stored in the session's signal repository.
183
+ *
184
+ * @param sessionId - Session ID to get mappings from
185
+ * @returns Promise<LIDMappingEntry[]> - Array of LID-PN mapping entries
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const mappings = await whatsapp.getAllLIDMappings("mysession");
190
+ * for (const mapping of mappings) {
191
+ * console.log(`${mapping.lid} => ${mapping.pn}`);
192
+ * }
193
+ * ```
194
+ *
195
+ * @note This may return an empty array if no mappings are available yet.
196
+ */
197
+ export declare const getAllLIDMappings: (sessionId: string) => Promise<LIDMappingEntry[]>;
198
+ /**
199
+ * Check if a JID is in LID format
200
+ *
201
+ * @param jid - The JID to check
202
+ * @returns boolean - True if the JID is in LID format
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * if (whatsapp.isLIDFormat("1524746986546@lid")) {
207
+ * console.log("This is an LID");
208
+ * }
209
+ * ```
210
+ */
211
+ export declare const isLIDFormat: (jid: string) => boolean;
212
+ /**
213
+ * Check if a JID is in Phone Number format (@s.whatsapp.net)
214
+ *
215
+ * @param jid - The JID to check
216
+ * @returns boolean - True if the JID is in PN format
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * if (whatsapp.isPNFormat("6281234567890@s.whatsapp.net")) {
221
+ * console.log("This is a phone number JID");
222
+ * }
223
+ * ```
224
+ */
225
+ export declare const isPNFormat: (jid: string) => boolean;
226
+ /**
227
+ * Smart convert any JID to phone number
228
+ *
229
+ * Automatically detects if the input is an LID and converts it to PN,
230
+ * or returns the PN if already in PN format.
231
+ *
232
+ * @param sessionId - Session ID to use for conversion
233
+ * @param jid - Any JID (LID or PN format)
234
+ * @returns Promise<string | null> - Phone number or null if conversion failed
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * const pn = await whatsapp.toPhoneNumber("mysession", jid);
239
+ * if (pn) {
240
+ * console.log(`Phone number: ${pn}`);
241
+ * }
242
+ * ```
243
+ */
244
+ export declare const toPhoneNumber: (sessionId: string, jid: string) => Promise<string | null>;
245
+ /**
246
+ * Smart convert any JID to LID
247
+ *
248
+ * Automatically detects if the input is a PN and converts it to LID,
249
+ * or returns the LID if already in LID format.
250
+ *
251
+ * @param sessionId - Session ID to use for conversion
252
+ * @param jid - Any JID (LID or PN format)
253
+ * @returns Promise<string | null> - LID or null if conversion failed
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const lid = await whatsapp.toLID("mysession", "6281234567890@s.whatsapp.net");
258
+ * if (lid) {
259
+ * console.log(`LID: ${lid}`);
260
+ * }
261
+ * ```
262
+ */
263
+ export declare const toLID: (sessionId: string, jid: string) => Promise<string | null>;
105
264
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Socket/index.ts"],"names":[],"mappings":"AAAA,OAAqB,EAInB,QAAQ,EACT,MAAM,SAAS,CAAC;AAMjB,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,kBAAkB,EAEnB,MAAM,UAAU,CAAC;AAiClB;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,kBAkB5C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C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAwBzF,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,KAAK,GAAU,WAAW,MAAM,EAAE,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAkBjF,CAAC"}
@@ -21,6 +21,32 @@ import { MongoClient } from "mongodb";
21
21
  import { useMongoAuthState } from "../Utils/mongo-auth-state.js";
22
22
  import { createDelay } from "../Utils/create-delay.js";
23
23
  const sessions = new Map();
24
+ /**
25
+ * Helper function to generate browser configuration based on type and name
26
+ * @param browserType - Browser type (ubuntu, macOS, windows, appropriate)
27
+ * @param browserName - Custom browser/app name
28
+ * @returns Browser configuration tuple for Baileys
29
+ */
30
+ const getBrowserConfig = (browserType = "ubuntu", browserName = "Chrome") => {
31
+ let browserTuple;
32
+ switch (browserType) {
33
+ case "macOS":
34
+ browserTuple = Browsers.macOS(browserName);
35
+ break;
36
+ case "windows":
37
+ browserTuple = Browsers.windows(browserName);
38
+ break;
39
+ case "appropriate":
40
+ browserTuple = Browsers.appropriate(browserName);
41
+ break;
42
+ case "ubuntu":
43
+ default:
44
+ browserTuple = Browsers.ubuntu(browserName);
45
+ break;
46
+ }
47
+ // Convert readonly tuple to mutable tuple for Baileys compatibility
48
+ return [...browserTuple];
49
+ };
24
50
  const callback = new Map();
25
51
  const retryCount = new Map();
26
52
  // Tambahkan Map untuk melacak session yang menggunakan pairing code
@@ -85,7 +111,7 @@ export const startSession = (...args_1) => __awaiter(void 0, [...args_1], void 0
85
111
  auth: state,
86
112
  logger: P,
87
113
  markOnlineOnConnect: false,
88
- browser: Browsers.ubuntu("Chrome"),
114
+ browser: getBrowserConfig(options.browserType, options.browserName),
89
115
  // Configure caching group metadata using our hybrid implementation with session ID
90
116
  cachedGroupMetadata: (jid) => __awaiter(void 0, void 0, void 0, function* () {
91
117
  return yield groupCache.get(sessionId, jid);
@@ -244,7 +270,7 @@ export const startSessionWithPairingCode = (sessionId_1, phoneNumber_1, ...args_
244
270
  auth: state,
245
271
  logger: P,
246
272
  markOnlineOnConnect: false,
247
- browser: Browsers.ubuntu("Chrome"),
273
+ browser: getBrowserConfig(options.browserType, options.browserName),
248
274
  // Opsi tambahan untuk meningkatkan kompatibilitas
249
275
  linkPreviewImageThumbnailWidth: 300,
250
276
  generateHighQualityLinkPreview: true,
@@ -806,3 +832,305 @@ export const clearSessionGroupMetadataCache = (sessionId) => __awaiter(void 0, v
806
832
  export const clearAllGroupMetadataCache = () => {
807
833
  groupCache.flush();
808
834
  };
835
+ /**
836
+ * Convert LID (Linked ID) to Phone Number (PN/JID)
837
+ *
838
+ * This function uses Baileys' internal signalRepository.lidMapping to retrieve
839
+ * the phone number associated with a given LID.
840
+ *
841
+ * @param sessionId - Session ID to use for conversion
842
+ * @param lid - The LID to convert (e.g., "1524746986546@lid")
843
+ * @returns Promise<LIDConversionResult> - Result object with the phone number or null if not found
844
+ *
845
+ * @example
846
+ * ```typescript
847
+ * const result = await whatsapp.getPNForLID("mysession", "1524746986546@lid");
848
+ * if (result.success && result.pn) {
849
+ * console.log(`Phone number: ${result.pn}`);
850
+ * } else {
851
+ * console.log("Phone number not found for this LID");
852
+ * }
853
+ * ```
854
+ *
855
+ * @note This function may return null for new contacts or when WhatsApp
856
+ * hasn't provided the LID-PN mapping yet. Not all LIDs have known phone numbers.
857
+ */
858
+ export const getPNForLID = (sessionId, lid) => __awaiter(void 0, void 0, void 0, function* () {
859
+ var _a, _b;
860
+ const session = getSession(sessionId);
861
+ if (!session) {
862
+ return {
863
+ success: false,
864
+ lid,
865
+ pn: null,
866
+ error: Messages.sessionNotFound(sessionId)
867
+ };
868
+ }
869
+ try {
870
+ // Normalize LID format
871
+ let normalizedLid = lid;
872
+ if (!lid.includes('@lid')) {
873
+ normalizedLid = `${lid}@lid`;
874
+ }
875
+ // Access the signalRepository.lidMapping to get PN for LID
876
+ const signalRepo = session.signalRepository;
877
+ if (!signalRepo || !signalRepo.lidMapping) {
878
+ return {
879
+ success: false,
880
+ lid: normalizedLid,
881
+ pn: null,
882
+ error: "LID mapping not available in this session"
883
+ };
884
+ }
885
+ // Try to get the phone number for the LID
886
+ const pn = ((_b = (_a = signalRepo.lidMapping).getPNForLID) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedLid)) || null;
887
+ return {
888
+ success: pn !== null,
889
+ lid: normalizedLid,
890
+ pn
891
+ };
892
+ }
893
+ catch (error) {
894
+ return {
895
+ success: false,
896
+ lid,
897
+ pn: null,
898
+ error: `Failed to convert LID to PN: ${error.message || String(error)}`
899
+ };
900
+ }
901
+ });
902
+ /**
903
+ * Convert Phone Number (PN/JID) to LID (Linked ID)
904
+ *
905
+ * This function uses Baileys' internal signalRepository.lidMapping to retrieve
906
+ * the LID associated with a given phone number.
907
+ *
908
+ * @param sessionId - Session ID to use for conversion
909
+ * @param pn - The phone number/JID to convert (e.g., "6281234567890" or "6281234567890@s.whatsapp.net")
910
+ * @returns Promise<PNConversionResult> - Result object with the LID or null if not found
911
+ *
912
+ * @example
913
+ * ```typescript
914
+ * const result = await whatsapp.getLIDForPN("mysession", "6281234567890");
915
+ * if (result.success && result.lid) {
916
+ * console.log(`LID: ${result.lid}`);
917
+ * } else {
918
+ * console.log("LID not found for this phone number");
919
+ * }
920
+ * ```
921
+ *
922
+ * @note This function may return null for contacts that haven't been encountered
923
+ * with their LID mapping yet.
924
+ */
925
+ export const getLIDForPN = (sessionId, pn) => __awaiter(void 0, void 0, void 0, function* () {
926
+ var _a, _b;
927
+ const session = getSession(sessionId);
928
+ if (!session) {
929
+ return {
930
+ success: false,
931
+ pn,
932
+ lid: null,
933
+ error: Messages.sessionNotFound(sessionId)
934
+ };
935
+ }
936
+ try {
937
+ // Normalize PN format
938
+ let normalizedPn = pn.replace(/\D/g, ''); // Remove non-digits
939
+ if (!pn.includes('@s.whatsapp.net')) {
940
+ normalizedPn = `${normalizedPn}@s.whatsapp.net`;
941
+ }
942
+ else {
943
+ normalizedPn = pn;
944
+ }
945
+ // Access the signalRepository.lidMapping to get LID for PN
946
+ const signalRepo = session.signalRepository;
947
+ if (!signalRepo || !signalRepo.lidMapping) {
948
+ return {
949
+ success: false,
950
+ pn: normalizedPn,
951
+ lid: null,
952
+ error: "LID mapping not available in this session"
953
+ };
954
+ }
955
+ // Try to get the LID for the phone number
956
+ const lid = ((_b = (_a = signalRepo.lidMapping).getLIDForPN) === null || _b === void 0 ? void 0 : _b.call(_a, normalizedPn)) || null;
957
+ return {
958
+ success: lid !== null,
959
+ pn: normalizedPn,
960
+ lid
961
+ };
962
+ }
963
+ catch (error) {
964
+ return {
965
+ success: false,
966
+ pn,
967
+ lid: null,
968
+ error: `Failed to convert PN to LID: ${error.message || String(error)}`
969
+ };
970
+ }
971
+ });
972
+ /**
973
+ * Get all known LID-PN mappings for a session
974
+ *
975
+ * This function retrieves all LID to phone number mappings that are currently
976
+ * stored in the session's signal repository.
977
+ *
978
+ * @param sessionId - Session ID to get mappings from
979
+ * @returns Promise<LIDMappingEntry[]> - Array of LID-PN mapping entries
980
+ *
981
+ * @example
982
+ * ```typescript
983
+ * const mappings = await whatsapp.getAllLIDMappings("mysession");
984
+ * for (const mapping of mappings) {
985
+ * console.log(`${mapping.lid} => ${mapping.pn}`);
986
+ * }
987
+ * ```
988
+ *
989
+ * @note This may return an empty array if no mappings are available yet.
990
+ */
991
+ export const getAllLIDMappings = (sessionId) => __awaiter(void 0, void 0, void 0, function* () {
992
+ const session = getSession(sessionId);
993
+ if (!session) {
994
+ throw new WhatsappError(Messages.sessionNotFound(sessionId));
995
+ }
996
+ try {
997
+ const signalRepo = session.signalRepository;
998
+ if (!signalRepo || !signalRepo.lidMapping) {
999
+ return [];
1000
+ }
1001
+ // Try to get all mappings if available
1002
+ const getAllMappings = signalRepo.lidMapping.getAll || signalRepo.lidMapping.getAllMappings;
1003
+ if (typeof getAllMappings === 'function') {
1004
+ const mappings = getAllMappings();
1005
+ if (Array.isArray(mappings)) {
1006
+ return mappings;
1007
+ }
1008
+ // If it's a Map or Object, convert to array
1009
+ if (mappings instanceof Map) {
1010
+ return Array.from(mappings.entries()).map(([lid, pn]) => ({ lid, pn: pn }));
1011
+ }
1012
+ if (typeof mappings === 'object') {
1013
+ return Object.entries(mappings).map(([lid, pn]) => ({ lid, pn: pn }));
1014
+ }
1015
+ }
1016
+ // Alternative: Try to access internal store directly
1017
+ const store = signalRepo.lidMapping.store || signalRepo.lidMapping._store;
1018
+ if (store) {
1019
+ if (store instanceof Map) {
1020
+ return Array.from(store.entries()).map(([lid, pn]) => ({ lid, pn: pn }));
1021
+ }
1022
+ if (typeof store === 'object') {
1023
+ return Object.entries(store).map(([lid, pn]) => ({ lid, pn: pn }));
1024
+ }
1025
+ }
1026
+ return [];
1027
+ }
1028
+ catch (error) {
1029
+ throw new WhatsappError(`Failed to get LID mappings: ${error.message || String(error)}`);
1030
+ }
1031
+ });
1032
+ /**
1033
+ * Check if a JID is in LID format
1034
+ *
1035
+ * @param jid - The JID to check
1036
+ * @returns boolean - True if the JID is in LID format
1037
+ *
1038
+ * @example
1039
+ * ```typescript
1040
+ * if (whatsapp.isLIDFormat("1524746986546@lid")) {
1041
+ * console.log("This is an LID");
1042
+ * }
1043
+ * ```
1044
+ */
1045
+ export const isLIDFormat = (jid) => {
1046
+ return jid.includes('@lid');
1047
+ };
1048
+ /**
1049
+ * Check if a JID is in Phone Number format (@s.whatsapp.net)
1050
+ *
1051
+ * @param jid - The JID to check
1052
+ * @returns boolean - True if the JID is in PN format
1053
+ *
1054
+ * @example
1055
+ * ```typescript
1056
+ * if (whatsapp.isPNFormat("6281234567890@s.whatsapp.net")) {
1057
+ * console.log("This is a phone number JID");
1058
+ * }
1059
+ * ```
1060
+ */
1061
+ export const isPNFormat = (jid) => {
1062
+ return jid.includes('@s.whatsapp.net');
1063
+ };
1064
+ /**
1065
+ * Smart convert any JID to phone number
1066
+ *
1067
+ * Automatically detects if the input is an LID and converts it to PN,
1068
+ * or returns the PN if already in PN format.
1069
+ *
1070
+ * @param sessionId - Session ID to use for conversion
1071
+ * @param jid - Any JID (LID or PN format)
1072
+ * @returns Promise<string | null> - Phone number or null if conversion failed
1073
+ *
1074
+ * @example
1075
+ * ```typescript
1076
+ * const pn = await whatsapp.toPhoneNumber("mysession", jid);
1077
+ * if (pn) {
1078
+ * console.log(`Phone number: ${pn}`);
1079
+ * }
1080
+ * ```
1081
+ */
1082
+ export const toPhoneNumber = (sessionId, jid) => __awaiter(void 0, void 0, void 0, function* () {
1083
+ // If already in PN format, return as-is
1084
+ if (isPNFormat(jid)) {
1085
+ return jid;
1086
+ }
1087
+ // If it's an LID, try to convert
1088
+ if (isLIDFormat(jid)) {
1089
+ const result = yield getPNForLID(sessionId, jid);
1090
+ return result.pn;
1091
+ }
1092
+ // If it's a group or broadcast, return null
1093
+ if (jid.includes('@g.us') || jid.includes('@broadcast')) {
1094
+ return null;
1095
+ }
1096
+ // If it's just a number, format it as PN
1097
+ const phoneNumber = jid.replace(/\D/g, '');
1098
+ if (phoneNumber.length >= 10) {
1099
+ return `${phoneNumber}@s.whatsapp.net`;
1100
+ }
1101
+ return null;
1102
+ });
1103
+ /**
1104
+ * Smart convert any JID to LID
1105
+ *
1106
+ * Automatically detects if the input is a PN and converts it to LID,
1107
+ * or returns the LID if already in LID format.
1108
+ *
1109
+ * @param sessionId - Session ID to use for conversion
1110
+ * @param jid - Any JID (LID or PN format)
1111
+ * @returns Promise<string | null> - LID or null if conversion failed
1112
+ *
1113
+ * @example
1114
+ * ```typescript
1115
+ * const lid = await whatsapp.toLID("mysession", "6281234567890@s.whatsapp.net");
1116
+ * if (lid) {
1117
+ * console.log(`LID: ${lid}`);
1118
+ * }
1119
+ * ```
1120
+ */
1121
+ export const toLID = (sessionId, jid) => __awaiter(void 0, void 0, void 0, function* () {
1122
+ // If already in LID format, return as-is
1123
+ if (isLIDFormat(jid)) {
1124
+ return jid;
1125
+ }
1126
+ // If it's a PN, try to convert
1127
+ if (isPNFormat(jid) || /^\d+$/.test(jid.replace(/\D/g, ''))) {
1128
+ const result = yield getLIDForPN(sessionId, jid);
1129
+ return result.lid;
1130
+ }
1131
+ // If it's a group or broadcast, return null
1132
+ if (jid.includes('@g.us') || jid.includes('@broadcast')) {
1133
+ return null;
1134
+ }
1135
+ return null;
1136
+ });
@@ -1,4 +1,12 @@
1
1
  import { WAMessageUpdate, proto } from "baileys";
2
+ /**
3
+ * Supported browser types for WhatsApp connection
4
+ * - ubuntu: Uses Ubuntu browser agent (default)
5
+ * - macOS: Uses macOS browser agent
6
+ * - windows: Uses Windows browser agent
7
+ * - appropriate: Uses appropriate browser based on platform
8
+ */
9
+ export type BrowserType = "ubuntu" | "macOS" | "windows" | "appropriate";
2
10
  export interface SendMessageTypes {
3
11
  to: string | number;
4
12
  text?: string;
@@ -53,6 +61,19 @@ export interface StartSessionParams {
53
61
  * Print QR Code into Terminal
54
62
  */
55
63
  printQR?: boolean;
64
+ /**
65
+ * Browser type for WhatsApp connection
66
+ * Options: "ubuntu" (default), "macOS", "windows", "appropriate"
67
+ * @default "ubuntu"
68
+ */
69
+ browserType?: BrowserType;
70
+ /**
71
+ * Custom browser/app name displayed in WhatsApp
72
+ * This name will appear in "Linked Devices" on your phone
73
+ * @default "Chrome"
74
+ * @example "My Bot App"
75
+ */
76
+ browserName?: string;
56
77
  onQRUpdated?: (qr: string) => void;
57
78
  onConnected?: () => void;
58
79
  onConnecting?: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CA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