@whanext/core 0.19.11 → 0.19.13

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,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.19.13
4
+
5
+ - Group edits now preserve the original message author's participant identities instead of replacing them with identities carried by the edit-addon envelope.
6
+ - Archived mutation recovery now prefers the original stored participant and `fromMe` values over fallback mutation metadata.
7
+ - Fixed external edits being incorrectly classified as owner edits in multi-account/group sessions.
8
+
9
+ ## 0.19.12
10
+
11
+ - Added end-to-end AntiEdit diagnostics for encrypted addons, protocol events, direct edit envelopes, normalization, previous-message recovery, and final `messageEdited` emission.
12
+ - Missing parent secrets during Zapo edit-addon decryption now surface as a dedicated `decrypt_failed_missing_parent_secret` warning.
13
+ - Diagnostics contain message identifiers and processing stages, but never message text or encrypted payload bytes.
14
+
3
15
  ## 0.19.11
4
16
 
5
17
  - 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,24 +3389,39 @@ 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;
3335
3404
  const participant = protocolKey.participant ?? event.key.participant;
3336
3405
  const participantAlt = protocolKey.participantAlt ?? event.key.participantAlt;
3337
- const target = {
3406
+ let target = {
3338
3407
  ...protocolKey,
3339
3408
  ...remoteJid !== void 0 ? { remoteJid } : {},
3340
3409
  ...participant !== void 0 ? { participant } : {},
3341
3410
  ...participantAlt !== void 0 ? { participantAlt } : {}
3342
3411
  };
3343
3412
  const stored = await this.#findStoredMessage(target);
3413
+ if (stored) target = this.#targetKeyFromStoredMessage(target, stored.key);
3344
3414
  if (!target.remoteJid && stored?.key.remoteJid) target.remoteJid = stored.key.remoteJid;
3345
- if (!target.remoteJid) return;
3415
+ if (!target.remoteJid) {
3416
+ if (protocol.type === proto.Message.ProtocolMessage.Type.MESSAGE_EDIT) {
3417
+ this.#logEditDiagnostic("dropped_edit_without_chat", {
3418
+ eventMessageId: event.key.id ?? void 0,
3419
+ targetMessageId: target.id ?? void 0,
3420
+ previousRecovered: stored !== void 0
3421
+ }, "warn");
3422
+ }
3423
+ return;
3424
+ }
3346
3425
  const type = protocol.type;
3347
3426
  const mutationKey = this.#protocolDeliveryKey(event, target, type);
3348
3427
  if (mutationKey && this.#handledProtocolStore.has(mutationKey)) {
@@ -3373,7 +3452,13 @@ var ZapoProvider = class {
3373
3452
  return;
3374
3453
  }
3375
3454
  const editedContent = protocol.editedMessage ? this.#unwrapEditedContent(protocol.editedMessage) : void 0;
3376
- if (!editedContent) return;
3455
+ if (!editedContent) {
3456
+ this.#logEditDiagnostic("dropped_edit_without_content", {
3457
+ eventMessageId: event.key.id ?? void 0,
3458
+ targetMessageId: target.id ?? void 0
3459
+ }, "warn");
3460
+ return;
3461
+ }
3377
3462
  const pushName = event.pushName ?? stored?.pushName;
3378
3463
  const edited = {
3379
3464
  ...stored ?? {},
@@ -3386,18 +3471,31 @@ var ZapoProvider = class {
3386
3471
  ...pushName !== void 0 ? { pushName } : {}
3387
3472
  };
3388
3473
  const message = normalizeZapoMessage(edited);
3389
- if (!message) return;
3474
+ if (!message) {
3475
+ this.#logEditDiagnostic("dropped_edit_normalization_failed", {
3476
+ eventMessageId: event.key.id ?? void 0,
3477
+ targetMessageId: target.id ?? void 0,
3478
+ previousRecovered: stored !== void 0
3479
+ }, "warn");
3480
+ return;
3481
+ }
3390
3482
  const previous = stored ? normalizeZapoMessage(stored) : void 0;
3391
3483
  if (mutationKey) this.#rememberHandledProtocol(mutationKey);
3392
3484
  this.#remember(edited);
3393
3485
  const editedByMe = event.key.fromMe === true;
3394
3486
  const editedById = event.key.participant ?? event.key.participantAlt ?? (editedByMe ? this.getCurrentUserIds()[0] : event.key.remoteJid ?? void 0);
3395
3487
  if (!previous) {
3396
- this.#logger.debug("Zapo edit target was not present in the recent message cache.", {
3488
+ this.#logEditDiagnostic("emitting_without_previous_message", {
3397
3489
  targetMessageId: target.id ?? void 0,
3398
3490
  chatId: target.remoteJid ?? void 0
3399
- });
3491
+ }, "warn");
3400
3492
  }
3493
+ this.#logEditDiagnostic("emitting_message_edited", {
3494
+ eventMessageId: event.key.id ?? void 0,
3495
+ targetMessageId: target.id ?? void 0,
3496
+ previousRecovered: previous !== void 0,
3497
+ editedByMe
3498
+ });
3401
3499
  void this.#events.emit("messageEdited", {
3402
3500
  key: message.keys,
3403
3501
  ...previous ? { previous } : {},
@@ -3411,6 +3509,20 @@ var ZapoProvider = class {
3411
3509
  const wrapper = message.editedMessage;
3412
3510
  return wrapper?.message ?? message;
3413
3511
  }
3512
+ #targetKeyFromStoredMessage(fallback, stored) {
3513
+ const id = stored.id ?? fallback.id;
3514
+ const remoteJid = stored.remoteJid ?? fallback.remoteJid;
3515
+ const fromMe = stored.fromMe ?? fallback.fromMe;
3516
+ return {
3517
+ ...id !== void 0 ? { id } : {},
3518
+ ...remoteJid !== void 0 ? { remoteJid } : {},
3519
+ ...stored.remoteJidAlt !== void 0 ? { remoteJidAlt: stored.remoteJidAlt } : {},
3520
+ ...fromMe !== void 0 ? { fromMe } : {},
3521
+ ...stored.participant !== void 0 ? { participant: stored.participant } : {},
3522
+ ...stored.participantAlt !== void 0 ? { participantAlt: stored.participantAlt } : {},
3523
+ ...stored.senderUsername !== void 0 ? { senderUsername: stored.senderUsername } : {}
3524
+ };
3525
+ }
3414
3526
  #handleGroupEvent(event) {
3415
3527
  const groupId = event.groupJid;
3416
3528
  if (!groupId) return;
@@ -3959,10 +4071,10 @@ var ZapoProvider = class {
3959
4071
  const archivedChatId = stringValue(archived.chat_id);
3960
4072
  const remoteJid = key.remoteJid ?? archivedChatId;
3961
4073
  if (!remoteJid) return void 0;
3962
- const participant = key.participant ?? key.participantAlt ?? stringValue(archived.participant_id);
4074
+ const participant = stringValue(archived.participant_id) ?? key.participant ?? key.participantAlt;
3963
4075
  const archivedFromMe = booleanValue(archived.from_me);
3964
4076
  const timestampSeconds = numberValue(archived.timestamp_seconds);
3965
- const fromMe = key.fromMe ?? archivedFromMe;
4077
+ const fromMe = archivedFromMe ?? key.fromMe;
3966
4078
  const restored = {
3967
4079
  key: {
3968
4080
  ...key,
@@ -4479,6 +4591,14 @@ var WhaNextZapoLogger = class _WhaNextZapoLogger {
4479
4591
  this.#logger.info(message, this.#merge(context));
4480
4592
  }
4481
4593
  warn(message, context) {
4594
+ if (message.startsWith("addon parent message secret not found") && context?.kind === "message_edit") {
4595
+ this.#logger.warn("AntiEdit diagnostic", {
4596
+ diagnostic: "antiedit",
4597
+ stage: "decrypt_failed_missing_parent_secret",
4598
+ ...this.#merge(context)
4599
+ });
4600
+ return;
4601
+ }
4482
4602
  this.#logger.warn(message, this.#merge(context));
4483
4603
  }
4484
4604
  error(message, context) {