@whanext/core 0.19.11 → 0.19.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.19.12
4
+
5
+ - Added end-to-end AntiEdit diagnostics for encrypted addons, protocol events, direct edit envelopes, normalization, previous-message recovery, and final `messageEdited` emission.
6
+ - Missing parent secrets during Zapo edit-addon decryption now surface as a dedicated `decrypt_failed_missing_parent_secret` warning.
7
+ - Diagnostics contain message identifiers and processing stages, but never message text or encrypted payload bytes.
8
+
3
9
  ## 0.19.11
4
10
 
5
11
  - Direct `editedMessage` envelopes are now translated into `messageEdited` events instead of being emitted as ordinary messages.
package/dist/index.js CHANGED
@@ -3112,6 +3112,13 @@ var ZapoProvider = class {
3112
3112
  client.on("message", (event) => {
3113
3113
  const protocol = this.#protocolMessage(event);
3114
3114
  if (protocol && this.#isMessageMutationProtocol(protocol.type)) {
3115
+ if (protocol.type === proto.Message.ProtocolMessage.Type.MESSAGE_EDIT) {
3116
+ this.#logEditDiagnostic("received_message_protocol_payload", {
3117
+ eventMessageId: event.key.id ?? void 0,
3118
+ targetMessageId: protocol.key?.id ?? void 0,
3119
+ offline: event.offline === true
3120
+ });
3121
+ }
3115
3122
  this.#enqueueProtocolEvent({
3116
3123
  ...event,
3117
3124
  protocolMessage: protocol
@@ -3120,6 +3127,11 @@ var ZapoProvider = class {
3120
3127
  }
3121
3128
  const directEdit = this.#directEditedMessage(event.message);
3122
3129
  if (directEdit && event.key.id) {
3130
+ this.#logEditDiagnostic("received_direct_edited_message", {
3131
+ eventMessageId: event.key.id,
3132
+ targetMessageId: event.key.id,
3133
+ offline: event.offline === true
3134
+ });
3123
3135
  this.#enqueueProtocolEvent({
3124
3136
  ...event,
3125
3137
  protocolMessage: {
@@ -3130,6 +3142,14 @@ var ZapoProvider = class {
3130
3142
  });
3131
3143
  return;
3132
3144
  }
3145
+ const encryptedEdit = this.#encryptedEditInfo(event.message);
3146
+ if (encryptedEdit) {
3147
+ this.#logEditDiagnostic("received_encrypted_addon", {
3148
+ eventMessageId: event.key.id ?? void 0,
3149
+ targetMessageId: encryptedEdit.targetMessageId,
3150
+ offline: event.offline === true
3151
+ });
3152
+ }
3133
3153
  this.#handleMessage(event);
3134
3154
  });
3135
3155
  client.on("message_send", (event) => {
@@ -3145,6 +3165,13 @@ var ZapoProvider = class {
3145
3165
  });
3146
3166
  });
3147
3167
  client.on("message_protocol", (event) => {
3168
+ if (event.protocolMessage.type === proto.Message.ProtocolMessage.Type.MESSAGE_EDIT) {
3169
+ this.#logEditDiagnostic("received_message_protocol_event", {
3170
+ eventMessageId: event.key.id ?? void 0,
3171
+ targetMessageId: event.protocolMessage.key?.id ?? void 0,
3172
+ offline: event.offline === true
3173
+ });
3174
+ }
3148
3175
  this.#enqueueProtocolEvent(event);
3149
3176
  });
3150
3177
  client.on("message_addon", (event) => {
@@ -3202,10 +3229,29 @@ var ZapoProvider = class {
3202
3229
  const kind = event.kind ?? this.#stringField(decrypted, "kind") ?? this.#stringField(decrypted, "type");
3203
3230
  const isEdit = kind === "message_edit" || protocol?.type === proto.Message.ProtocolMessage.Type.MESSAGE_EDIT;
3204
3231
  if (!isEdit) return;
3232
+ this.#logEditDiagnostic("received_decrypted_addon", {
3233
+ eventMessageId: event.key.id ?? void 0,
3234
+ targetMessageId: event.targetMessageId ?? this.#stringField(decrypted, "targetMessageId") ?? this.#stringField(decrypted, "targetMessageID") ?? protocol?.key?.id ?? void 0,
3235
+ addonKind: kind ?? void 0,
3236
+ offline: event.offline === true
3237
+ });
3205
3238
  const targetMessageId = event.targetMessageId ?? this.#stringField(decrypted, "targetMessageId") ?? this.#stringField(decrypted, "targetMessageID") ?? protocol?.key?.id ?? void 0;
3206
- if (!targetMessageId) return;
3239
+ if (!targetMessageId) {
3240
+ this.#logEditDiagnostic("dropped_addon_without_target", {
3241
+ eventMessageId: event.key.id ?? void 0,
3242
+ addonKind: kind ?? void 0
3243
+ }, "warn");
3244
+ return;
3245
+ }
3207
3246
  const editedMessage = protocol?.editedMessage ?? this.#addonEditedMessage(event.decrypted);
3208
- if (!editedMessage) return;
3247
+ if (!editedMessage) {
3248
+ this.#logEditDiagnostic("dropped_addon_without_edited_content", {
3249
+ eventMessageId: event.key.id ?? void 0,
3250
+ targetMessageId,
3251
+ addonKind: kind ?? void 0
3252
+ }, "warn");
3253
+ return;
3254
+ }
3209
3255
  const protocolKey = protocol?.key;
3210
3256
  const target = {
3211
3257
  ...protocolKey ?? {},
@@ -3288,6 +3334,24 @@ var ZapoProvider = class {
3288
3334
  const nested = message.ephemeralMessage?.message ?? message.deviceSentMessage?.message;
3289
3335
  return nested ? this.#directEditedMessage(nested) : void 0;
3290
3336
  }
3337
+ #encryptedEditInfo(message) {
3338
+ const content = unwrapZapoMessageContent(message);
3339
+ const encrypted = content?.secretEncryptedMessage;
3340
+ if (!encrypted) return void 0;
3341
+ if (encrypted.secretEncType !== proto.Message.SecretEncryptedMessage.SecretEncType.MESSAGE_EDIT) {
3342
+ return void 0;
3343
+ }
3344
+ return {
3345
+ ...encrypted.targetMessageKey?.id ? { targetMessageId: encrypted.targetMessageKey.id } : {}
3346
+ };
3347
+ }
3348
+ #logEditDiagnostic(stage, context, level = "info") {
3349
+ this.#logger[level]("AntiEdit diagnostic", {
3350
+ diagnostic: "antiedit",
3351
+ stage,
3352
+ ...context
3353
+ });
3354
+ }
3291
3355
  #protocolMessage(event) {
3292
3356
  if (event.protocolMessage) return event.protocolMessage;
3293
3357
  const content = unwrapZapoMessageContent(event.message);
@@ -3325,10 +3389,15 @@ var ZapoProvider = class {
3325
3389
  if (!protocol || !this.#isMessageMutationProtocol(protocol.type)) return;
3326
3390
  const protocolKey = protocol.key;
3327
3391
  if (!protocolKey?.id) {
3328
- this.#logger.debug("Ignored Zapo protocol mutation without a target message id.", {
3392
+ const context = {
3329
3393
  messageId: event.key.id ?? void 0,
3330
3394
  protocolType: protocol.type ?? void 0
3331
- });
3395
+ };
3396
+ if (protocol.type === proto.Message.ProtocolMessage.Type.MESSAGE_EDIT) {
3397
+ this.#logEditDiagnostic("dropped_protocol_without_target", context, "warn");
3398
+ } else {
3399
+ this.#logger.debug("Ignored Zapo protocol mutation without a target message id.", context);
3400
+ }
3332
3401
  return;
3333
3402
  }
3334
3403
  const remoteJid = protocolKey.remoteJid ?? event.key.remoteJid;
@@ -3342,7 +3411,16 @@ var ZapoProvider = class {
3342
3411
  };
3343
3412
  const stored = await this.#findStoredMessage(target);
3344
3413
  if (!target.remoteJid && stored?.key.remoteJid) target.remoteJid = stored.key.remoteJid;
3345
- if (!target.remoteJid) return;
3414
+ if (!target.remoteJid) {
3415
+ if (protocol.type === proto.Message.ProtocolMessage.Type.MESSAGE_EDIT) {
3416
+ this.#logEditDiagnostic("dropped_edit_without_chat", {
3417
+ eventMessageId: event.key.id ?? void 0,
3418
+ targetMessageId: target.id ?? void 0,
3419
+ previousRecovered: stored !== void 0
3420
+ }, "warn");
3421
+ }
3422
+ return;
3423
+ }
3346
3424
  const type = protocol.type;
3347
3425
  const mutationKey = this.#protocolDeliveryKey(event, target, type);
3348
3426
  if (mutationKey && this.#handledProtocolStore.has(mutationKey)) {
@@ -3373,7 +3451,13 @@ var ZapoProvider = class {
3373
3451
  return;
3374
3452
  }
3375
3453
  const editedContent = protocol.editedMessage ? this.#unwrapEditedContent(protocol.editedMessage) : void 0;
3376
- if (!editedContent) return;
3454
+ if (!editedContent) {
3455
+ this.#logEditDiagnostic("dropped_edit_without_content", {
3456
+ eventMessageId: event.key.id ?? void 0,
3457
+ targetMessageId: target.id ?? void 0
3458
+ }, "warn");
3459
+ return;
3460
+ }
3377
3461
  const pushName = event.pushName ?? stored?.pushName;
3378
3462
  const edited = {
3379
3463
  ...stored ?? {},
@@ -3386,18 +3470,31 @@ var ZapoProvider = class {
3386
3470
  ...pushName !== void 0 ? { pushName } : {}
3387
3471
  };
3388
3472
  const message = normalizeZapoMessage(edited);
3389
- if (!message) return;
3473
+ if (!message) {
3474
+ this.#logEditDiagnostic("dropped_edit_normalization_failed", {
3475
+ eventMessageId: event.key.id ?? void 0,
3476
+ targetMessageId: target.id ?? void 0,
3477
+ previousRecovered: stored !== void 0
3478
+ }, "warn");
3479
+ return;
3480
+ }
3390
3481
  const previous = stored ? normalizeZapoMessage(stored) : void 0;
3391
3482
  if (mutationKey) this.#rememberHandledProtocol(mutationKey);
3392
3483
  this.#remember(edited);
3393
3484
  const editedByMe = event.key.fromMe === true;
3394
3485
  const editedById = event.key.participant ?? event.key.participantAlt ?? (editedByMe ? this.getCurrentUserIds()[0] : event.key.remoteJid ?? void 0);
3395
3486
  if (!previous) {
3396
- this.#logger.debug("Zapo edit target was not present in the recent message cache.", {
3487
+ this.#logEditDiagnostic("emitting_without_previous_message", {
3397
3488
  targetMessageId: target.id ?? void 0,
3398
3489
  chatId: target.remoteJid ?? void 0
3399
- });
3490
+ }, "warn");
3400
3491
  }
3492
+ this.#logEditDiagnostic("emitting_message_edited", {
3493
+ eventMessageId: event.key.id ?? void 0,
3494
+ targetMessageId: target.id ?? void 0,
3495
+ previousRecovered: previous !== void 0,
3496
+ editedByMe
3497
+ });
3401
3498
  void this.#events.emit("messageEdited", {
3402
3499
  key: message.keys,
3403
3500
  ...previous ? { previous } : {},
@@ -4479,6 +4576,14 @@ var WhaNextZapoLogger = class _WhaNextZapoLogger {
4479
4576
  this.#logger.info(message, this.#merge(context));
4480
4577
  }
4481
4578
  warn(message, context) {
4579
+ if (message.startsWith("addon parent message secret not found") && context?.kind === "message_edit") {
4580
+ this.#logger.warn("AntiEdit diagnostic", {
4581
+ diagnostic: "antiedit",
4582
+ stage: "decrypt_failed_missing_parent_secret",
4583
+ ...this.#merge(context)
4584
+ });
4585
+ return;
4586
+ }
4482
4587
  this.#logger.warn(message, this.#merge(context));
4483
4588
  }
4484
4589
  error(message, context) {