@deffa5556/bail 1.0.6 → 1.0.7
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/cjs/WAProto/index.cjs +106053 -0
- package/cjs/deffa/config.cjs +14 -0
- package/cjs/deffa/plugins/ai/deepseekr1.cjs +35 -0
- package/cjs/deffa/plugins/ai/gita.cjs +26 -0
- package/cjs/deffa/plugins/ai/glm47flash.cjs +35 -0
- package/cjs/deffa/plugins/ai/gptoss120b.cjs +35 -0
- package/cjs/deffa/plugins/ai/qwq32b.cjs +35 -0
- package/cjs/deffa/plugins/berita/antara.cjs +25 -0
- package/cjs/deffa/plugins/berita/cnbcindonesia.cjs +25 -0
- package/cjs/deffa/plugins/berita/cnn.cjs +25 -0
- package/cjs/deffa/plugins/berita/kompas.cjs +25 -0
- package/cjs/deffa/plugins/berita/liputan6.cjs +25 -0
- package/cjs/deffa/plugins/berita/merdeka.cjs +25 -0
- package/cjs/deffa/plugins/berita/sindonews.cjs +25 -0
- package/cjs/deffa/plugins/berita/tribunnews.cjs +25 -0
- package/cjs/deffa/plugins/downloader/douyin.cjs +30 -0
- package/cjs/deffa/plugins/downloader/facebook.cjs +30 -0
- package/cjs/deffa/plugins/downloader/github.cjs +35 -0
- package/cjs/deffa/plugins/downloader/lahelu.cjs +30 -0
- package/cjs/deffa/plugins/downloader/snackvideo.cjs +30 -0
- package/cjs/deffa/plugins/downloader/soundcloud.cjs +30 -0
- package/cjs/deffa/plugins/downloader/tiktok.cjs +30 -0
- package/cjs/deffa/plugins/downloader/tiktokhd.cjs +30 -0
- package/cjs/deffa/plugins/downloader/twitter.cjs +30 -0
- package/cjs/deffa/plugins/downloader/ummy.cjs +36 -0
- package/cjs/deffa/plugins/index.cjs +213 -0
- package/cjs/deffa/plugins/info/bmkg.cjs +34 -0
- package/cjs/deffa/plugins/info/cuaca.cjs +31 -0
- package/cjs/deffa/plugins/info/jadwaltv.cjs +29 -0
- package/cjs/deffa/plugins/maker/brat.cjs +45 -0
- package/cjs/deffa/plugins/maker/bratvid.cjs +52 -0
- package/cjs/deffa/plugins/search/8font.cjs +28 -0
- package/cjs/deffa/plugins/search/applemusic.cjs +28 -0
- package/cjs/deffa/plugins/search/bimg.cjs +30 -0
- package/cjs/deffa/plugins/search/brave.cjs +34 -0
- package/cjs/deffa/plugins/search/duckduckgo.cjs +28 -0
- package/cjs/deffa/plugins/search/lahelu.cjs +28 -0
- package/cjs/deffa/plugins/search/mangatoon.cjs +28 -0
- package/cjs/deffa/plugins/search/mcpedl.cjs +28 -0
- package/cjs/deffa/plugins/search/myinstants.cjs +28 -0
- package/cjs/deffa/plugins/search/otakotaku.cjs +28 -0
- package/cjs/deffa/plugins/search/pinterest.cjs +30 -0
- package/cjs/deffa/plugins/search/resep.cjs +28 -0
- package/cjs/deffa/plugins/search/seegore.cjs +30 -0
- package/cjs/deffa/plugins/search/soundcloud.cjs +28 -0
- package/cjs/deffa/plugins/search/youtube.cjs +28 -0
- package/cjs/deffa/plugins/stalk/github.cjs +38 -0
- package/cjs/deffa/plugins/stalk/pinterest.cjs +37 -0
- package/cjs/deffa/plugins/stalk/threads.cjs +34 -0
- package/cjs/deffa/plugins/stalk/tiktok.cjs +37 -0
- package/cjs/deffa/plugins/stalk/twitter.cjs +37 -0
- package/cjs/deffa/plugins/stalk/youtube.cjs +37 -0
- package/cjs/lib/Defaults/index.cjs +158 -0
- package/cjs/lib/Discord/Client.cjs +263 -0
- package/cjs/lib/Discord/Constants.cjs +1842 -0
- package/cjs/lib/Discord/connect-dc.cjs +11 -0
- package/cjs/lib/Discord/esm-bridge.cjs +136 -0
- package/cjs/lib/Discord/gateway/Dispatcher.cjs +93 -0
- package/cjs/lib/Discord/gateway/Shard.cjs +695 -0
- package/cjs/lib/Discord/gateway/ShardManager.cjs +344 -0
- package/cjs/lib/Discord/gateway/compression/base.cjs +13 -0
- package/cjs/lib/Discord/gateway/compression/config.cjs +47 -0
- package/cjs/lib/Discord/gateway/compression/pako.cjs +44 -0
- package/cjs/lib/Discord/gateway/compression/zlib-native.cjs +47 -0
- package/cjs/lib/Discord/gateway/compression/zlib-sync.cjs +31 -0
- package/cjs/lib/Discord/gateway/compression/zstd-napi.cjs +80 -0
- package/cjs/lib/Discord/gateway/compression/zstd-native.cjs +46 -0
- package/cjs/lib/Discord/gateway/events.cjs +956 -0
- package/cjs/lib/Discord/index.cjs +238 -0
- package/cjs/lib/Discord/rest/Bucket.cjs +69 -0
- package/cjs/lib/Discord/rest/DiscordHTTPError.cjs +63 -0
- package/cjs/lib/Discord/rest/DiscordRESTError.cjs +84 -0
- package/cjs/lib/Discord/rest/OAuthHelper.cjs +226 -0
- package/cjs/lib/Discord/rest/RESTManager.cjs +116 -0
- package/cjs/lib/Discord/rest/RequestHandler.cjs +320 -0
- package/cjs/lib/Discord/rest/SequentialBucket.cjs +69 -0
- package/cjs/lib/Discord/routes/Applications.cjs +625 -0
- package/cjs/lib/Discord/routes/Channels.cjs +1199 -0
- package/cjs/lib/Discord/routes/Guilds.cjs +1792 -0
- package/cjs/lib/Discord/routes/Interactions.cjs +212 -0
- package/cjs/lib/Discord/routes/Lobbies.cjs +197 -0
- package/cjs/lib/Discord/routes/Miscellaneous.cjs +120 -0
- package/cjs/lib/Discord/routes/OAuth.cjs +350 -0
- package/cjs/lib/Discord/routes/Users.cjs +107 -0
- package/cjs/lib/Discord/routes/Webhooks.cjs +308 -0
- package/cjs/lib/Discord/structures/AnnouncementChannel.cjs +46 -0
- package/cjs/lib/Discord/structures/AnnouncementThreadChannel.cjs +28 -0
- package/cjs/lib/Discord/structures/Application.cjs +345 -0
- package/cjs/lib/Discord/structures/ApplicationCommand.cjs +109 -0
- package/cjs/lib/Discord/structures/Attachment.cjs +46 -0
- package/cjs/lib/Discord/structures/AuditLogEntry.cjs +41 -0
- package/cjs/lib/Discord/structures/AutoModerationRule.cjs +117 -0
- package/cjs/lib/Discord/structures/AutocompleteInteraction.cjs +90 -0
- package/cjs/lib/Discord/structures/Base.cjs +56 -0
- package/cjs/lib/Discord/structures/BaseEntitlement.cjs +40 -0
- package/cjs/lib/Discord/structures/CategoryChannel.cjs +102 -0
- package/cjs/lib/Discord/structures/Channel.cjs +89 -0
- package/cjs/lib/Discord/structures/ClientApplication.cjs +269 -0
- package/cjs/lib/Discord/structures/CommandInteraction.cjs +294 -0
- package/cjs/lib/Discord/structures/ComponentInteraction.cjs +306 -0
- package/cjs/lib/Discord/structures/Entitlement.cjs +24 -0
- package/cjs/lib/Discord/structures/ExtendedUser.cjs +48 -0
- package/cjs/lib/Discord/structures/ForumChannel.cjs +20 -0
- package/cjs/lib/Discord/structures/GroupChannel.cjs +160 -0
- package/cjs/lib/Discord/structures/Guild.cjs +1289 -0
- package/cjs/lib/Discord/structures/GuildChannel.cjs +82 -0
- package/cjs/lib/Discord/structures/GuildPreview.cjs +141 -0
- package/cjs/lib/Discord/structures/GuildScheduledEvent.cjs +166 -0
- package/cjs/lib/Discord/structures/GuildTemplate.cjs +96 -0
- package/cjs/lib/Discord/structures/Integration.cjs +123 -0
- package/cjs/lib/Discord/structures/Interaction.cjs +78 -0
- package/cjs/lib/Discord/structures/InteractionResolvedChannel.cjs +36 -0
- package/cjs/lib/Discord/structures/Invite.cjs +196 -0
- package/cjs/lib/Discord/structures/InviteGuild.cjs +117 -0
- package/cjs/lib/Discord/structures/InviteRole.cjs +88 -0
- package/cjs/lib/Discord/structures/Lobby.cjs +84 -0
- package/cjs/lib/Discord/structures/LobbyMember.cjs +30 -0
- package/cjs/lib/Discord/structures/MediaChannel.cjs +20 -0
- package/cjs/lib/Discord/structures/Member.cjs +300 -0
- package/cjs/lib/Discord/structures/Message.cjs +553 -0
- package/cjs/lib/Discord/structures/ModalSubmitInteraction.cjs +263 -0
- package/cjs/lib/Discord/structures/OAuthApplication.cjs +203 -0
- package/cjs/lib/Discord/structures/OAuthGuild.cjs +98 -0
- package/cjs/lib/Discord/structures/PartialApplication.cjs +97 -0
- package/cjs/lib/Discord/structures/Permission.cjs +61 -0
- package/cjs/lib/Discord/structures/PermissionOverwrite.cjs +46 -0
- package/cjs/lib/Discord/structures/PingInteraction.cjs +27 -0
- package/cjs/lib/Discord/structures/Poll.cjs +69 -0
- package/cjs/lib/Discord/structures/PrimaryGuild.cjs +93 -0
- package/cjs/lib/Discord/structures/PrivateChannel.cjs +131 -0
- package/cjs/lib/Discord/structures/PrivateThreadChannel.cjs +28 -0
- package/cjs/lib/Discord/structures/PublicThreadChannel.cjs +36 -0
- package/cjs/lib/Discord/structures/Role.cjs +126 -0
- package/cjs/lib/Discord/structures/SKU.cjs +58 -0
- package/cjs/lib/Discord/structures/Soundboard.cjs +58 -0
- package/cjs/lib/Discord/structures/StageChannel.cjs +45 -0
- package/cjs/lib/Discord/structures/StageInstance.cjs +80 -0
- package/cjs/lib/Discord/structures/Subscription.cjs +21 -0
- package/cjs/lib/Discord/structures/Team.cjs +70 -0
- package/cjs/lib/Discord/structures/TestEntitlement.cjs +22 -0
- package/cjs/lib/Discord/structures/TextChannel.cjs +48 -0
- package/cjs/lib/Discord/structures/TextableChannel.cjs +265 -0
- package/cjs/lib/Discord/structures/TextableVoiceChannel.cjs +70 -0
- package/cjs/lib/Discord/structures/ThreadChannel.cjs +276 -0
- package/cjs/lib/Discord/structures/ThreadOnlyChannel.cjs +205 -0
- package/cjs/lib/Discord/structures/ThreadableChannel.cjs +57 -0
- package/cjs/lib/Discord/structures/UnavailableGuild.cjs +21 -0
- package/cjs/lib/Discord/structures/User.cjs +223 -0
- package/cjs/lib/Discord/structures/VoiceChannel.cjs +34 -0
- package/cjs/lib/Discord/structures/VoiceState.cjs +113 -0
- package/cjs/lib/Discord/structures/Webhook.cjs +224 -0
- package/cjs/lib/Discord/util/Collection.cjs +77 -0
- package/cjs/lib/Discord/util/Errors.cjs +81 -0
- package/cjs/lib/Discord/util/QueryBuilder.cjs +20 -0
- package/cjs/lib/Discord/util/Routes.cjs +293 -0
- package/cjs/lib/Discord/util/SimpleCollection.cjs +78 -0
- package/cjs/lib/Discord/util/Time.cjs +92 -0
- package/cjs/lib/Discord/util/TypedCollection.cjs +78 -0
- package/cjs/lib/Discord/util/TypedEmitter.cjs +20 -0
- package/cjs/lib/Discord/util/Util.cjs +906 -0
- package/cjs/lib/Discord/util/interactions/InteractionOptionsWrapper.cjs +207 -0
- package/cjs/lib/Discord/util/interactions/MessageInteractionResponse.cjs +26 -0
- package/cjs/lib/Discord/util/interactions/ModalSubmitInteractionComponentsWrapper.cjs +98 -0
- package/cjs/lib/Discord/util/interactions/SelectMenuValuesWrapper.cjs +77 -0
- package/cjs/lib/Discord/util/interactions/shared.cjs +20 -0
- package/cjs/lib/Discord/util/warning.cjs +34 -0
- package/cjs/lib/Signal/Group/ciphertext-message.cjs +16 -0
- package/cjs/lib/Signal/Group/group-session-builder.cjs +67 -0
- package/cjs/lib/Signal/Group/group_cipher.cjs +86 -0
- package/cjs/lib/Signal/Group/index.cjs +58 -0
- package/cjs/lib/Signal/Group/keyhelper.cjs +56 -0
- package/cjs/lib/Signal/Group/sender-chain-key.cjs +30 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.cjs +67 -0
- package/cjs/lib/Signal/Group/sender-key-message.cjs +70 -0
- package/cjs/lib/Signal/Group/sender-key-name.cjs +52 -0
- package/cjs/lib/Signal/Group/sender-key-record.cjs +45 -0
- package/cjs/lib/Signal/Group/sender-key-state.cjs +88 -0
- package/cjs/lib/Signal/Group/sender-message-key.cjs +30 -0
- package/cjs/lib/Signal/libsignal.cjs +467 -0
- package/cjs/lib/Signal/lid-mapping.cjs +281 -0
- package/cjs/lib/Socket/Client/index.cjs +19 -0
- package/cjs/lib/Socket/Client/types.cjs +15 -0
- package/cjs/lib/Socket/Client/websocket.cjs +61 -0
- package/cjs/lib/Socket/business.cjs +384 -0
- package/cjs/lib/Socket/chats.cjs +1221 -0
- package/cjs/lib/Socket/communities.cjs +440 -0
- package/cjs/lib/Socket/groups.cjs +353 -0
- package/cjs/lib/Socket/index.cjs +14 -0
- package/cjs/lib/Socket/messages-recv.cjs +1772 -0
- package/cjs/lib/Socket/messages-send.cjs +1376 -0
- package/cjs/lib/Socket/mex.cjs +46 -0
- package/cjs/lib/Socket/newsletter.cjs +230 -0
- package/cjs/lib/Socket/socket.cjs +976 -0
- package/cjs/lib/Store/index.cjs +20 -0
- package/cjs/lib/Store/make-in-memory-store.cjs +470 -0
- package/cjs/lib/Store/make-ordered-dictionary.cjs +82 -0
- package/cjs/lib/Store/object-repository.cjs +28 -0
- package/cjs/lib/Telegram/button.cjs +147 -0
- package/cjs/lib/Telegram/composer.cjs +582 -0
- package/cjs/lib/Telegram/context.cjs +853 -0
- package/cjs/lib/Telegram/core/helpers/args.cjs +57 -0
- package/cjs/lib/Telegram/core/helpers/check.cjs +55 -0
- package/cjs/lib/Telegram/core/helpers/compact.cjs +16 -0
- package/cjs/lib/Telegram/core/helpers/deunionize.cjs +12 -0
- package/cjs/lib/Telegram/core/helpers/formatting.cjs +91 -0
- package/cjs/lib/Telegram/core/helpers/util.cjs +50 -0
- package/cjs/lib/Telegram/core/network/client.cjs +338 -0
- package/cjs/lib/Telegram/core/network/error.cjs +21 -0
- package/cjs/lib/Telegram/core/network/multipart-stream.cjs +79 -0
- package/cjs/lib/Telegram/core/network/polling.cjs +87 -0
- package/cjs/lib/Telegram/core/network/webhook.cjs +54 -0
- package/cjs/lib/Telegram/core/types/typegram.cjs +31 -0
- package/cjs/lib/Telegram/deffa-telegraf.cjs +264 -0
- package/cjs/lib/Telegram/esm-bridge.cjs +20 -0
- package/cjs/lib/Telegram/filters.cjs +69 -0
- package/cjs/lib/Telegram/format.cjs +58 -0
- package/cjs/lib/Telegram/future.cjs +140 -0
- package/cjs/lib/Telegram/index.cjs +67 -0
- package/cjs/lib/Telegram/input.cjs +61 -0
- package/cjs/lib/Telegram/markup.cjs +129 -0
- package/cjs/lib/Telegram/middleware.cjs +2 -0
- package/cjs/lib/Telegram/reactions.cjs +84 -0
- package/cjs/lib/Telegram/router.cjs +46 -0
- package/cjs/lib/Telegram/scenes/base.cjs +39 -0
- package/cjs/lib/Telegram/scenes/context.cjs +104 -0
- package/cjs/lib/Telegram/scenes/index.cjs +21 -0
- package/cjs/lib/Telegram/scenes/stage.cjs +49 -0
- package/cjs/lib/Telegram/scenes/wizard/context.cjs +31 -0
- package/cjs/lib/Telegram/scenes/wizard/index.cjs +45 -0
- package/cjs/lib/Telegram/scenes.cjs +21 -0
- package/cjs/lib/Telegram/session.cjs +166 -0
- package/cjs/lib/Telegram/telegram-types.cjs +6 -0
- package/cjs/lib/Telegram/telegram.cjs +945 -0
- package/cjs/lib/Telegram/types.cjs +2 -0
- package/cjs/lib/Telegram/utils.cjs +5 -0
- package/cjs/lib/Types/Auth.cjs +3 -0
- package/cjs/lib/Types/Bussines.cjs +3 -0
- package/cjs/lib/Types/Call.cjs +3 -0
- package/cjs/lib/Types/Chat.cjs +11 -0
- package/cjs/lib/Types/Contact.cjs +3 -0
- package/cjs/lib/Types/Events.cjs +4 -0
- package/cjs/lib/Types/GroupMetadata.cjs +3 -0
- package/cjs/lib/Types/Label.cjs +26 -0
- package/cjs/lib/Types/LabelAssociation.cjs +8 -0
- package/cjs/lib/Types/Message.cjs +19 -0
- package/cjs/lib/Types/Mex.cjs +40 -0
- package/cjs/lib/Types/Product.cjs +3 -0
- package/cjs/lib/Types/RichType.cjs +24 -0
- package/cjs/lib/Types/Signal.cjs +4 -0
- package/cjs/lib/Types/Socket.cjs +4 -0
- package/cjs/lib/Types/State.cjs +54 -0
- package/cjs/lib/Types/USync.cjs +4 -0
- package/cjs/lib/Types/index.cjs +42 -0
- package/cjs/lib/Utils/auth-utils.cjs +312 -0
- package/cjs/lib/Utils/browser-utils.cjs +39 -0
- package/cjs/lib/Utils/business.cjs +241 -0
- package/cjs/lib/Utils/chat-utils.cjs +890 -0
- package/cjs/lib/Utils/companion-reg-client-utils.cjs +51 -0
- package/cjs/lib/Utils/crypto.cjs +170 -0
- package/cjs/lib/Utils/decode-wa-message.cjs +330 -0
- package/cjs/lib/Utils/event-buffer.cjs +629 -0
- package/cjs/lib/Utils/generics.cjs +427 -0
- package/cjs/lib/Utils/history.cjs +141 -0
- package/cjs/lib/Utils/identity-change-handler.cjs +56 -0
- package/cjs/lib/Utils/index.cjs +43 -0
- package/cjs/lib/Utils/link-preview.cjs +122 -0
- package/cjs/lib/Utils/logger.cjs +8 -0
- package/cjs/lib/Utils/lt-hash.cjs +11 -0
- package/cjs/lib/Utils/make-mutex.cjs +38 -0
- package/cjs/lib/Utils/message-retry-manager.cjs +267 -0
- package/cjs/lib/Utils/messages-media.cjs +906 -0
- package/cjs/lib/Utils/messages.cjs +1909 -0
- package/cjs/lib/Utils/noise-handler.cjs +205 -0
- package/cjs/lib/Utils/offline-node-processor.cjs +43 -0
- package/cjs/lib/Utils/pre-key-manager.cjs +113 -0
- package/cjs/lib/Utils/process-message.cjs +755 -0
- package/cjs/lib/Utils/reporting-utils.cjs +263 -0
- package/cjs/lib/Utils/rich-message-utils.cjs +434 -0
- package/cjs/lib/Utils/session-guard.cjs +163 -0
- package/cjs/lib/Utils/signal.cjs +214 -0
- package/cjs/lib/Utils/stanza-ack.cjs +41 -0
- package/cjs/lib/Utils/sync-action-utils.cjs +54 -0
- package/cjs/lib/Utils/tc-token-utils.cjs +174 -0
- package/cjs/lib/Utils/text-sticker.cjs +174 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.cjs +125 -0
- package/cjs/lib/Utils/use-single-file-auth-state.cjs +113 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.cjs +145 -0
- package/cjs/lib/Utils/validate-connection.cjs +210 -0
- package/cjs/lib/WABinary/constants.cjs +1470 -0
- package/cjs/lib/WABinary/decode.cjs +301 -0
- package/cjs/lib/WABinary/encode.cjs +257 -0
- package/cjs/lib/WABinary/generic-utils.cjs +240 -0
- package/cjs/lib/WABinary/index.cjs +22 -0
- package/cjs/lib/WABinary/jid-utils.cjs +114 -0
- package/cjs/lib/WABinary/types.cjs +37 -0
- package/cjs/lib/WAM/BinaryInfo.cjs +14 -0
- package/cjs/lib/WAM/constants.cjs +22856 -0
- package/cjs/lib/WAM/encode.cjs +154 -0
- package/cjs/lib/WAM/index.cjs +20 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.cjs +56 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.cjs +58 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.cjs +31 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.cjs +42 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.cjs +29 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.cjs +55 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.cjs +33 -0
- package/cjs/lib/WAUSync/Protocols/index.cjs +22 -0
- package/cjs/lib/WAUSync/USyncQuery.cjs +102 -0
- package/cjs/lib/WAUSync/USyncUser.cjs +35 -0
- package/cjs/lib/WAUSync/index.cjs +20 -0
- package/cjs/lib/index.cjs +372 -0
- package/cjs/lib/plugins/loader.cjs +117 -0
- package/lib/Defaults/index.js +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.renderTextSticker = renderTextSticker;
|
|
37
|
+
/**
|
|
38
|
+
* deffa@Changes --- Text Sticker generator.
|
|
39
|
+
*
|
|
40
|
+
* Implements WA's "Text Stickers" feature, announced officially on
|
|
41
|
+
* blog.whatsapp.com (Jan 7 2026, "Level Up Your WhatsApp Group Chats With
|
|
42
|
+
* New Member Tags, Text Stickers, and More"):
|
|
43
|
+
* "you can now turn any word into a sticker by typing your text into
|
|
44
|
+
* Sticker Search."
|
|
45
|
+
*
|
|
46
|
+
* IMPORTANT — protocol note: WA's "Sticker Search" is a client-side / app
|
|
47
|
+
* UI feature (local rendering + Meta's closed sticker search index). There
|
|
48
|
+
* is no dedicated wire-protocol message type for it — the result a user
|
|
49
|
+
* sends is just a normal stickerMessage (image/webp), identical to what
|
|
50
|
+
* Baileys already sends via the sticker pack pipeline in messages.js.
|
|
51
|
+
*
|
|
52
|
+
* This util renders the *client-side* part ourselves (text -> styled
|
|
53
|
+
* image -> webp), so deffa-baileys can produce the same end result
|
|
54
|
+
* (a valid stickerMessage) without depending on WA's internal sticker
|
|
55
|
+
* search service, which isn't reachable over the protocol Baileys speaks.
|
|
56
|
+
*
|
|
57
|
+
* Output of `renderTextSticker()` is a webp Buffer ready to be passed as
|
|
58
|
+
* the `sticker` field of `sock.sendMessage(jid, { sticker: buffer })`,
|
|
59
|
+
* exactly like any other sticker in this library.
|
|
60
|
+
*/
|
|
61
|
+
const boom_1 = require("@hapi/boom");
|
|
62
|
+
const messages_media_js_1 = require("./messages-media.cjs");
|
|
63
|
+
const MAX_TEXT_LENGTH = 60;
|
|
64
|
+
const STICKER_SIZE = 512;
|
|
65
|
+
const DEFAULT_STYLE = {
|
|
66
|
+
backgroundColor: '#FFFFFF',
|
|
67
|
+
textColor: '#000000',
|
|
68
|
+
fontFamily: 'sans-serif',
|
|
69
|
+
fontWeight: 'bold',
|
|
70
|
+
padding: 48,
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Renders a single word/phrase into a square WhatsApp-compatible sticker (webp).
|
|
74
|
+
*
|
|
75
|
+
* @param {string} text - The text to render (e.g. a word typed into "Sticker Search").
|
|
76
|
+
* @param {object} [options]
|
|
77
|
+
* @param {string} [options.backgroundColor='#FFFFFF'] - CSS color for the sticker background.
|
|
78
|
+
* @param {string} [options.textColor='#000000'] - CSS color for the text.
|
|
79
|
+
* @param {string} [options.fontFamily='sans-serif'] - Font family available on the system/canvas.
|
|
80
|
+
* @param {string} [options.fontWeight='bold'] - CSS font-weight.
|
|
81
|
+
* @returns {Promise<Buffer>} webp-encoded sticker buffer, ready for sock.sendMessage(jid, { sticker: buffer }).
|
|
82
|
+
*/
|
|
83
|
+
async function renderTextSticker(text, options = {}) {
|
|
84
|
+
if (typeof text !== 'string' || !text.trim()) {
|
|
85
|
+
throw new boom_1.Boom('text is required to render a text sticker', { statusCode: 400 });
|
|
86
|
+
}
|
|
87
|
+
const trimmed = text.trim();
|
|
88
|
+
if (trimmed.length > MAX_TEXT_LENGTH) {
|
|
89
|
+
throw new boom_1.Boom(`text exceeds max length of ${MAX_TEXT_LENGTH} characters`, { statusCode: 400 });
|
|
90
|
+
}
|
|
91
|
+
const style = { ...DEFAULT_STYLE, ...options };
|
|
92
|
+
// canvas is an existing dependency of this package (see package.json).
|
|
93
|
+
let canvasLib;
|
|
94
|
+
try {
|
|
95
|
+
canvasLib = await Promise.resolve().then(() => __importStar(require('canvas')));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
throw new boom_1.Boom('The "canvas" package is required to render text stickers but is not installed.', { statusCode: 500 });
|
|
99
|
+
}
|
|
100
|
+
const { createCanvas } = canvasLib;
|
|
101
|
+
const canvas = createCanvas(STICKER_SIZE, STICKER_SIZE);
|
|
102
|
+
const ctx = canvas.getContext('2d');
|
|
103
|
+
// Background
|
|
104
|
+
ctx.fillStyle = style.backgroundColor;
|
|
105
|
+
ctx.fillRect(0, 0, STICKER_SIZE, STICKER_SIZE);
|
|
106
|
+
// Auto-fit font size so the text (possibly multi-line) fits within the
|
|
107
|
+
// sticker bounds, shrinking from a large starting size.
|
|
108
|
+
const maxWidth = STICKER_SIZE - style.padding * 2;
|
|
109
|
+
const maxHeight = STICKER_SIZE - style.padding * 2;
|
|
110
|
+
let fontSize = 160;
|
|
111
|
+
let lines = [trimmed];
|
|
112
|
+
const wrapText = (size) => {
|
|
113
|
+
ctx.font = `${style.fontWeight} ${size}px ${style.fontFamily}`;
|
|
114
|
+
const words = trimmed.split(/\s+/);
|
|
115
|
+
const wrapped = [];
|
|
116
|
+
let current = '';
|
|
117
|
+
for (const word of words) {
|
|
118
|
+
const test = current ? `${current} ${word}` : word;
|
|
119
|
+
if (ctx.measureText(test).width <= maxWidth || !current) {
|
|
120
|
+
current = test;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
wrapped.push(current);
|
|
124
|
+
current = word;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (current)
|
|
128
|
+
wrapped.push(current);
|
|
129
|
+
return wrapped;
|
|
130
|
+
};
|
|
131
|
+
while (fontSize > 24) {
|
|
132
|
+
lines = wrapText(fontSize);
|
|
133
|
+
const lineHeight = fontSize * 1.15;
|
|
134
|
+
const totalHeight = lineHeight * lines.length;
|
|
135
|
+
const widestLine = Math.max(...lines.map(l => ctx.measureText(l).width));
|
|
136
|
+
if (totalHeight <= maxHeight && widestLine <= maxWidth) {
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
fontSize -= 4;
|
|
140
|
+
}
|
|
141
|
+
ctx.font = `${style.fontWeight} ${fontSize}px ${style.fontFamily}`;
|
|
142
|
+
ctx.fillStyle = style.textColor;
|
|
143
|
+
ctx.textAlign = 'center';
|
|
144
|
+
ctx.textBaseline = 'middle';
|
|
145
|
+
const lineHeight = fontSize * 1.15;
|
|
146
|
+
const startY = STICKER_SIZE / 2 - (lineHeight * (lines.length - 1)) / 2;
|
|
147
|
+
lines.forEach((line, i) => {
|
|
148
|
+
ctx.fillText(line, STICKER_SIZE / 2, startY + i * lineHeight);
|
|
149
|
+
});
|
|
150
|
+
const pngBuffer = canvas.toBuffer('image/png');
|
|
151
|
+
// Convert PNG -> WebP using the same image-processing pipeline the rest
|
|
152
|
+
// of the library already relies on (sharp / @napi-rs/image), so output
|
|
153
|
+
// is guaranteed to be a valid WA sticker (webp, <=1MB, 512x512).
|
|
154
|
+
const lib = await (0, messages_media_js_1.getImageProcessingLibrary)();
|
|
155
|
+
let webpBuffer;
|
|
156
|
+
if ('sharp' in lib && lib.sharp?.default) {
|
|
157
|
+
webpBuffer = await lib.sharp.default(pngBuffer)
|
|
158
|
+
.resize(STICKER_SIZE, STICKER_SIZE, { fit: 'inside' })
|
|
159
|
+
.webp({ quality: 90 })
|
|
160
|
+
.toBuffer();
|
|
161
|
+
}
|
|
162
|
+
else if ('image' in lib && lib.image?.Transformer) {
|
|
163
|
+
webpBuffer = await new lib.image.Transformer(pngBuffer)
|
|
164
|
+
.resize(STICKER_SIZE, STICKER_SIZE)
|
|
165
|
+
.webp(90);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
throw new boom_1.Boom('No image processing library (sharp or @napi-rs/image) available to encode the sticker as WebP.', { statusCode: 500 });
|
|
169
|
+
}
|
|
170
|
+
if (webpBuffer.length > 1024 * 1024) {
|
|
171
|
+
throw new boom_1.Boom('Generated text sticker exceeds the 1MB WhatsApp sticker size limit.', { statusCode: 400 });
|
|
172
|
+
}
|
|
173
|
+
return webpBuffer;
|
|
174
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require("async-mutex");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const index_js_1 = require("../../WAProto/index.cjs");
|
|
8
|
+
const auth_utils_js_1 = require("./auth-utils.cjs");
|
|
9
|
+
const generics_js_1 = require("./generics.cjs");
|
|
10
|
+
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
11
|
+
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
12
|
+
// https://github.com/nodejs/node/issues/26338
|
|
13
|
+
// Use a Map to store mutexes for each file path
|
|
14
|
+
const fileLocks = new Map();
|
|
15
|
+
// Get or create a mutex for a specific file path
|
|
16
|
+
const getFileLock = (path) => {
|
|
17
|
+
let mutex = fileLocks.get(path);
|
|
18
|
+
if (!mutex) {
|
|
19
|
+
mutex = new async_mutex_1.Mutex();
|
|
20
|
+
fileLocks.set(path, mutex);
|
|
21
|
+
}
|
|
22
|
+
return mutex;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* stores the full authentication state in a single folder.
|
|
26
|
+
* Far more efficient than singlefileauthstate
|
|
27
|
+
*
|
|
28
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
29
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
30
|
+
* */
|
|
31
|
+
const useMultiFileAuthState = async (folder) => {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
const writeData = async (data, file) => {
|
|
34
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
35
|
+
const mutex = getFileLock(filePath);
|
|
36
|
+
return mutex.acquire().then(async (release) => {
|
|
37
|
+
try {
|
|
38
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_js_1.BufferJSON.replacer));
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
release();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const readData = async (file) => {
|
|
46
|
+
try {
|
|
47
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
48
|
+
const mutex = getFileLock(filePath);
|
|
49
|
+
return await mutex.acquire().then(async (release) => {
|
|
50
|
+
try {
|
|
51
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
52
|
+
return JSON.parse(data, generics_js_1.BufferJSON.reviver);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
release();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const removeData = async (file) => {
|
|
64
|
+
try {
|
|
65
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
66
|
+
const mutex = getFileLock(filePath);
|
|
67
|
+
return mutex.acquire().then(async (release) => {
|
|
68
|
+
try {
|
|
69
|
+
await (0, promises_1.unlink)(filePath);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
release();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch { }
|
|
79
|
+
};
|
|
80
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
81
|
+
if (folderInfo) {
|
|
82
|
+
if (!folderInfo.isDirectory()) {
|
|
83
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
const fixFileName = (file) => file?.replace(/\//g, '__')?.replace(/:/g, '-');
|
|
90
|
+
const creds = (await readData('creds.json')) || (0, auth_utils_js_1.initAuthCreds)();
|
|
91
|
+
return {
|
|
92
|
+
state: {
|
|
93
|
+
creds,
|
|
94
|
+
keys: {
|
|
95
|
+
get: async (type, ids) => {
|
|
96
|
+
const data = {};
|
|
97
|
+
await Promise.all(ids.map(async (id) => {
|
|
98
|
+
let value = await readData(`${type}-${id}.json`);
|
|
99
|
+
if (type === 'app-state-sync-key' && value) {
|
|
100
|
+
value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
101
|
+
}
|
|
102
|
+
data[id] = value;
|
|
103
|
+
}));
|
|
104
|
+
return data;
|
|
105
|
+
},
|
|
106
|
+
set: async (data) => {
|
|
107
|
+
const tasks = [];
|
|
108
|
+
for (const category in data) {
|
|
109
|
+
for (const id in data[category]) {
|
|
110
|
+
const value = data[category][id];
|
|
111
|
+
const file = `${category}-${id}.json`;
|
|
112
|
+
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await Promise.all(tasks);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
saveCreds: async () => {
|
|
120
|
+
return writeData(creds, 'creds.json');
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
125
|
+
//# sourceMappingURL=use-multi-file-auth-state.js.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSingleFileAuthState = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const index_js_1 = require("../Defaults/index.cjs");
|
|
6
|
+
const index_js_2 = require("../../WAProto/index.cjs");
|
|
7
|
+
const auth_utils_js_1 = require("./auth-utils.cjs");
|
|
8
|
+
const generics_js_1 = require("./generics.cjs");
|
|
9
|
+
const lru_cache_1 = require("lru-cache");
|
|
10
|
+
const async_mutex_1 = require("async-mutex");
|
|
11
|
+
// Lia@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
|
|
12
|
+
const FLUSH_TIMEOUT_MS = 3000;
|
|
13
|
+
// Lia@Changes 22-04-26 --- Enhanced useSingleFileAuthState with LRUCache
|
|
14
|
+
const useSingleFileAuthState = async (fileName) => {
|
|
15
|
+
const cache = new lru_cache_1.LRUCache({
|
|
16
|
+
max: 20000,
|
|
17
|
+
ttl: 1000 * index_js_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
18
|
+
updateAgeOnGet: false,
|
|
19
|
+
updateAgeOnHas: false,
|
|
20
|
+
ttlAutopurge: true
|
|
21
|
+
});
|
|
22
|
+
// Lia@Changes 26-04-26 --- Add mutex for prevent race condition
|
|
23
|
+
const mutex = new async_mutex_1.Mutex();
|
|
24
|
+
let fileData = {};
|
|
25
|
+
let isLoaded = false;
|
|
26
|
+
let flushTimeout = null;
|
|
27
|
+
const loadKey = async () => {
|
|
28
|
+
return await mutex.runExclusive(async () => {
|
|
29
|
+
if (isLoaded)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
const data = JSON.parse(await (0, promises_1.readFile)(fileName, 'utf-8'), generics_js_1.BufferJSON.reviver);
|
|
33
|
+
fileData = data || {};
|
|
34
|
+
for (const [keyName, value] of Object.entries(fileData)) {
|
|
35
|
+
cache.set(keyName, value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
fileData = {};
|
|
40
|
+
}
|
|
41
|
+
isLoaded = true;
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const flushKey = () => {
|
|
45
|
+
if (flushTimeout)
|
|
46
|
+
return;
|
|
47
|
+
flushTimeout = setTimeout(async () => {
|
|
48
|
+
flushTimeout = null;
|
|
49
|
+
await mutex.runExclusive(async () => {
|
|
50
|
+
try {
|
|
51
|
+
const tempFile = fileName + '.temp';
|
|
52
|
+
await (0, promises_1.writeFile)(tempFile, JSON.stringify(fileData, generics_js_1.BufferJSON.replacer));
|
|
53
|
+
await (0, promises_1.rename)(tempFile, fileName);
|
|
54
|
+
}
|
|
55
|
+
catch { }
|
|
56
|
+
});
|
|
57
|
+
}, FLUSH_TIMEOUT_MS);
|
|
58
|
+
};
|
|
59
|
+
const writeKey = (keyName, value) => {
|
|
60
|
+
cache.set(keyName, value);
|
|
61
|
+
fileData[keyName] = value;
|
|
62
|
+
flushKey();
|
|
63
|
+
};
|
|
64
|
+
const removeKey = (keyName) => {
|
|
65
|
+
cache.delete(keyName);
|
|
66
|
+
delete fileData[keyName];
|
|
67
|
+
flushKey();
|
|
68
|
+
};
|
|
69
|
+
const fileInfo = await (0, promises_1.stat)(fileName).catch(() => null);
|
|
70
|
+
if (!fileInfo) {
|
|
71
|
+
await (0, promises_1.writeFile)(fileName, '{}');
|
|
72
|
+
}
|
|
73
|
+
else if (!fileInfo.isFile()) {
|
|
74
|
+
throw new Error(`found something that is not a file at ${fileName}, either delete it or specify a different location`);
|
|
75
|
+
}
|
|
76
|
+
await loadKey();
|
|
77
|
+
const creds = fileData['creds'] || (0, auth_utils_js_1.initAuthCreds)();
|
|
78
|
+
return {
|
|
79
|
+
state: {
|
|
80
|
+
creds,
|
|
81
|
+
keys: {
|
|
82
|
+
get: (type, ids) => {
|
|
83
|
+
const data = {};
|
|
84
|
+
for (const id of ids) {
|
|
85
|
+
const keyName = type + id;
|
|
86
|
+
let value = cache.get(keyName);
|
|
87
|
+
if (value === undefined && fileData[keyName] !== undefined) {
|
|
88
|
+
value = fileData[keyName];
|
|
89
|
+
cache.set(keyName, value);
|
|
90
|
+
}
|
|
91
|
+
if (type === 'app-state-sync-key' && value) {
|
|
92
|
+
value = index_js_2.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
93
|
+
}
|
|
94
|
+
data[id] = value;
|
|
95
|
+
}
|
|
96
|
+
return data;
|
|
97
|
+
},
|
|
98
|
+
set: (data) => {
|
|
99
|
+
for (const category in data) {
|
|
100
|
+
for (const id in data[category]) {
|
|
101
|
+
const keyName = category + id;
|
|
102
|
+
const value = data[category][id];
|
|
103
|
+
value ? writeKey(keyName, value) : removeKey(keyName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
saveCreds: () => writeKey('creds', creds)
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
exports.useSingleFileAuthState = useSingleFileAuthState;
|
|
113
|
+
//# sourceMappingURL=use-single-file-auth-state.js.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.useSqliteAuthState = useSqliteAuthState;
|
|
37
|
+
const promises_1 = require("fs/promises");
|
|
38
|
+
const path_1 = require("path");
|
|
39
|
+
const index_js_1 = require("../../WAProto/index.cjs");
|
|
40
|
+
const auth_utils_js_1 = require("./auth-utils.cjs");
|
|
41
|
+
const generics_js_1 = require("./generics.cjs");
|
|
42
|
+
async function loadBetterSqlite3() {
|
|
43
|
+
try {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
const mod = (await Promise.resolve().then(() => __importStar(require('better-sqlite3'))));
|
|
46
|
+
return mod.default ?? mod;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
const helpful = new Error('`better-sqlite3` is required for `useSqliteAuthState`. Install it as a peer dependency: `npm install better-sqlite3` (or `yarn add better-sqlite3`).');
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
helpful.cause = err;
|
|
52
|
+
throw helpful;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const CREDS_ROW_KEY = '__creds__';
|
|
56
|
+
const CREATE_SCHEMA_SQL = `
|
|
57
|
+
CREATE TABLE IF NOT EXISTS creds (
|
|
58
|
+
key TEXT PRIMARY KEY,
|
|
59
|
+
value TEXT NOT NULL
|
|
60
|
+
);
|
|
61
|
+
CREATE TABLE IF NOT EXISTS signal_keys (
|
|
62
|
+
type TEXT NOT NULL,
|
|
63
|
+
id TEXT NOT NULL,
|
|
64
|
+
value TEXT NOT NULL,
|
|
65
|
+
PRIMARY KEY (type, id)
|
|
66
|
+
);
|
|
67
|
+
CREATE INDEX IF NOT EXISTS signal_keys_type_idx ON signal_keys(type);
|
|
68
|
+
`;
|
|
69
|
+
async function useSqliteAuthState(opts) {
|
|
70
|
+
let db;
|
|
71
|
+
if (opts.database) {
|
|
72
|
+
db = opts.database;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const Database = await loadBetterSqlite3();
|
|
76
|
+
db = new Database(opts.dbPath);
|
|
77
|
+
}
|
|
78
|
+
// WAL mode allows concurrent reads alongside a single writer; matches
|
|
79
|
+
// what SQLite recommends for read-heavy workloads with sporadic writes.
|
|
80
|
+
db.pragma('journal_mode = WAL');
|
|
81
|
+
db.pragma('synchronous = NORMAL');
|
|
82
|
+
db.exec(CREATE_SCHEMA_SQL);
|
|
83
|
+
const stmts = {
|
|
84
|
+
credsSelect: db.prepare('SELECT value FROM creds WHERE key = ?'),
|
|
85
|
+
credsUpsert: db.prepare('INSERT INTO creds (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'),
|
|
86
|
+
keySelect: db.prepare('SELECT value FROM signal_keys WHERE type = ? AND id = ?'),
|
|
87
|
+
keyUpsert: db.prepare('INSERT INTO signal_keys (type, id, value) VALUES (?, ?, ?) ON CONFLICT(type, id) DO UPDATE SET value = excluded.value'),
|
|
88
|
+
keyDelete: db.prepare('DELETE FROM signal_keys WHERE type = ? AND id = ?'),
|
|
89
|
+
keyListIds: db.prepare('SELECT id FROM signal_keys WHERE type = ?'),
|
|
90
|
+
keyList: db.prepare('SELECT id, value FROM signal_keys WHERE type = ?'),
|
|
91
|
+
clearKeys: db.prepare('DELETE FROM signal_keys')
|
|
92
|
+
};
|
|
93
|
+
const loadCreds = () => {
|
|
94
|
+
const row = stmts.credsSelect.get(CREDS_ROW_KEY);
|
|
95
|
+
if (!row)
|
|
96
|
+
return (0, auth_utils_js_1.initAuthCreds)();
|
|
97
|
+
return JSON.parse(row.value, generics_js_1.BufferJSON.reviver);
|
|
98
|
+
};
|
|
99
|
+
const persistCreds = (creds) => {
|
|
100
|
+
stmts.credsUpsert.run(CREDS_ROW_KEY, JSON.stringify(creds, generics_js_1.BufferJSON.replacer));
|
|
101
|
+
};
|
|
102
|
+
const creds = loadCreds();
|
|
103
|
+
return {
|
|
104
|
+
state: {
|
|
105
|
+
creds,
|
|
106
|
+
keys: {
|
|
107
|
+
get: async (type, ids) => {
|
|
108
|
+
const data = {};
|
|
109
|
+
for (const id of ids) {
|
|
110
|
+
const row = stmts.keySelect.get(type, id);
|
|
111
|
+
if (row) {
|
|
112
|
+
let value = JSON.parse(row.value, generics_js_1.BufferJSON.reviver);
|
|
113
|
+
if (type === 'app-state-sync-key' && value) {
|
|
114
|
+
value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
115
|
+
}
|
|
116
|
+
data[id] = value;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return data;
|
|
120
|
+
},
|
|
121
|
+
set: async (data) => {
|
|
122
|
+
const writeTx = db.transaction(() => {
|
|
123
|
+
for (const category in data) {
|
|
124
|
+
for (const id in data[category]) {
|
|
125
|
+
const value = data[category][id];
|
|
126
|
+
if (value) {
|
|
127
|
+
const stringified = JSON.stringify(value, generics_js_1.BufferJSON.replacer);
|
|
128
|
+
stmts.keyUpsert.run(category, id, stringified);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
stmts.keyDelete.run(category, id);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
writeTx();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
saveCreds: async () => {
|
|
141
|
+
persistCreds(creds);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=use-sqlite-auth-state.js.map
|