@spectrum-ts/imessage 12.2.0 → 12.3.0

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -6
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { NotFoundError, ValidationError, createGrpcClient } from "@photon-ai/advanced-imessage/grpc";
1
+ import { ErrorCode, NotFoundError, ValidationError, createGrpcClient } from "@photon-ai/advanced-imessage/grpc";
2
2
  import { sanitizePhone, withSpan } from "@photon-ai/otel";
3
3
  import { UnsupportedError, appLayoutSchema, cloud, definePlatform, fromVCard, mergeStreams, read, text, toVCard } from "@spectrum-ts/core";
4
4
  import { addMemberSchema, asAttachment, asContact, asCustom, asGroup, asPoll, asPollOption, asReply, asText, asVoice, avatarSchema, buildPhotoAction, createLogger, createTokenRenewal, ensureM4a, errorAttrs, groupSchema, leaveSpaceSchema, messageEffectSchema, photoActionSchema, reactionSchema, removeMemberSchema, renameSchema, resumableOrderedStream, sanitizeErrorMessage } from "@spectrum-ts/core/authoring";
@@ -1506,6 +1506,7 @@ const randomPhone = (clients) => {
1506
1506
  const log$2 = createLogger("spectrum.imessage.contact");
1507
1507
  const SHARE_TTL_MS = 1440 * 60 * 1e3;
1508
1508
  const MAX_TRACKED_CHATS = 1e4;
1509
+ const isPreconditionFailure = (error) => typeof error === "object" && error !== null && "code" in error && error.code === ErrorCode.preconditionFailed;
1509
1510
  /**
1510
1511
  * Tracks which chats this bot's line has already proactively pushed its contact
1511
1512
  * card to, so `im.chats.shareContactInfo` is fired at most once per chat per
@@ -1530,10 +1531,12 @@ var ContactShareTracker = class {
1530
1531
  }
1531
1532
  /**
1532
1533
  * Best-effort share. The cache is set eagerly so that a burst of inbound
1533
- * messages for the same chat coalesces to a single API call. On failure the
1534
- * entry is evicted so the next inbound retries — transient errors don't
1535
- * permanently mute the feature for a chat. Never awaits and never throws:
1536
- * the receive stream must not crash on share failures.
1534
+ * messages for the same chat coalesces to a single API call. A
1535
+ * `preconditionFailed` response remains cached for the normal 24-hour TTL,
1536
+ * avoiding repeated attempts when the account cannot currently share its
1537
+ * profile. Other failures evict the entry so the next inbound retries.
1538
+ * Never awaits and never throws: the receive stream must not crash on share
1539
+ * failures.
1537
1540
  */
1538
1541
  maybeShare(chatGuid) {
1539
1542
  if (this.cache.has(chatGuid)) return;
@@ -1542,7 +1545,7 @@ var ContactShareTracker = class {
1542
1545
  this.client.chats.shareContactInfo(chatGuid).then(() => {
1543
1546
  log$2.info("shared contact card", { "spectrum.imessage.contact.chat": safeChatGuid });
1544
1547
  }).catch((error) => {
1545
- this.cache.delete(chatGuid);
1548
+ if (!isPreconditionFailure(error)) this.cache.delete(chatGuid);
1546
1549
  log$2.warn("failed to share contact card", {
1547
1550
  "spectrum.imessage.contact.chat": safeChatGuid,
1548
1551
  ...errorAttrs(error)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-ts/imessage",
3
- "version": "12.2.0",
3
+ "version": "12.3.0",
4
4
  "description": "iMessage provider for spectrum-ts.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@grpc/grpc-js": "^1.14.4",
35
35
  "@photon-ai/advanced-imessage": "^2.0.2",
36
- "@photon-ai/otel": "^3.1.0",
36
+ "@photon-ai/otel": "^3.3.0",
37
37
  "lru-cache": "^11.0.0",
38
38
  "marked": "^18.0.5",
39
39
  "nice-grpc": "^2.1.16",