@spectrum-ts/imessage 11.0.0 → 11.1.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 +27 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1807,6 +1807,25 @@ const toPollDeltaMessages = async (client, pollCache, event, phone) => {
1807
1807
  const isCursorRejectedIMessageError = (error) => error instanceof ValidationError;
1808
1808
  const streamLabel = (kind, phone) => `imessage.${kind}:${phone === "shared" ? phone : sanitizePhone(phone)}`;
1809
1809
  const isEventFromCurrentAccount = (event, phone) => event.isFromMe || phone !== "shared" && event.actor?.address !== void 0 && event.actor.address === phone;
1810
+ const streamLog = createLogger("spectrum.imessage.stream");
1811
+ const isRetryableMappingError = (error) => typeof error === "object" && error !== null && error.retryable === true;
1812
+ const skipUnmappable = async (label, cursor, map) => {
1813
+ try {
1814
+ return await map();
1815
+ } catch (error) {
1816
+ if (isRetryableMappingError(error)) throw error;
1817
+ streamLog.warn("skipping unmappable imessage event", {
1818
+ "spectrum.imessage.stream": label,
1819
+ "spectrum.imessage.cursor": cursor,
1820
+ ...errorAttrs(error)
1821
+ }, error instanceof Error ? error : void 0);
1822
+ return {
1823
+ cursor,
1824
+ id: `unmappable:${cursor}`,
1825
+ values: []
1826
+ };
1827
+ }
1828
+ };
1810
1829
  const toMessageItem = async (client, event, phone, cursor, onInbound) => {
1811
1830
  if (event.type === "message.received") {
1812
1831
  if (event.message.isFromMe) return {
@@ -1814,13 +1833,13 @@ const toMessageItem = async (client, event, phone, cursor, onInbound) => {
1814
1833
  id: event.message.guid,
1815
1834
  values: []
1816
1835
  };
1836
+ const values = await toInboundMessages(client, getMessageCache(client), event, phone);
1817
1837
  const inboundChatGuid = event.message.chatGuids?.[0];
1818
1838
  if (inboundChatGuid) onInbound?.(inboundChatGuid);
1819
- const cache = getMessageCache(client);
1820
1839
  return {
1821
1840
  cursor,
1822
1841
  id: event.message.guid,
1823
- values: await toInboundMessages(client, cache, event, phone)
1842
+ values
1824
1843
  };
1825
1844
  }
1826
1845
  if (event.type === "message.reactionAdded") {
@@ -1914,8 +1933,8 @@ const messageStream = (client, phone, onInbound, recover) => resumableOrderedStr
1914
1933
  isCursorRejectedError: isCursorRejectedIMessageError,
1915
1934
  label: streamLabel("messages", phone),
1916
1935
  recover,
1917
- processLive: (event) => toMessageItem(client, event, phone, String(event.sequence), onInbound),
1918
- processMissed: (event) => event.type === "catchup.complete" ? Promise.resolve(toCatchUpCompleteItem(event)) : toMessageItem(client, event, phone, String(event.sequence), onInbound),
1936
+ processLive: (event) => skipUnmappable(streamLabel("messages", phone), String(event.sequence), () => toMessageItem(client, event, phone, String(event.sequence), onInbound)),
1937
+ processMissed: (event) => event.type === "catchup.complete" ? Promise.resolve(toCatchUpCompleteItem(event)) : skipUnmappable(streamLabel("messages", phone), String(event.sequence), () => toMessageItem(client, event, phone, String(event.sequence), onInbound)),
1919
1938
  subscribeLive: (cursor) => withClose(client.messages.subscribeEvents(), cursor)
1920
1939
  });
1921
1940
  const pollStream = (client, pollCache, phone, recover) => resumableOrderedStream({
@@ -1923,8 +1942,8 @@ const pollStream = (client, pollCache, phone, recover) => resumableOrderedStream
1923
1942
  isCursorRejectedError: isCursorRejectedIMessageError,
1924
1943
  label: streamLabel("polls", phone),
1925
1944
  recover,
1926
- processLive: (event) => toPollItem(client, pollCache, event, phone, String(event.sequence)),
1927
- processMissed: (event) => event.type === "catchup.complete" ? Promise.resolve(toCatchUpCompleteItem(event)) : toPollItem(client, pollCache, event, phone, String(event.sequence)),
1945
+ processLive: (event) => skipUnmappable(streamLabel("polls", phone), String(event.sequence), () => toPollItem(client, pollCache, event, phone, String(event.sequence))),
1946
+ processMissed: (event) => event.type === "catchup.complete" ? Promise.resolve(toCatchUpCompleteItem(event)) : skipUnmappable(streamLabel("polls", phone), String(event.sequence), () => toPollItem(client, pollCache, event, phone, String(event.sequence))),
1928
1947
  subscribeLive: (cursor) => withClose(client.polls.subscribeEvents(), cursor)
1929
1948
  });
1930
1949
  const groupStream = (client, phone, recover) => resumableOrderedStream({
@@ -1932,8 +1951,8 @@ const groupStream = (client, phone, recover) => resumableOrderedStream({
1932
1951
  isCursorRejectedError: isCursorRejectedIMessageError,
1933
1952
  label: streamLabel("groups", phone),
1934
1953
  recover,
1935
- processLive: (event) => toGroupItem(client, event, phone, String(event.sequence)),
1936
- processMissed: (event) => event.type === "catchup.complete" ? Promise.resolve(toCatchUpCompleteItem(event)) : toGroupItem(client, event, phone, String(event.sequence)),
1954
+ processLive: (event) => skipUnmappable(streamLabel("groups", phone), String(event.sequence), () => toGroupItem(client, event, phone, String(event.sequence))),
1955
+ processMissed: (event) => event.type === "catchup.complete" ? Promise.resolve(toCatchUpCompleteItem(event)) : skipUnmappable(streamLabel("groups", phone), String(event.sequence), () => toGroupItem(client, event, phone, String(event.sequence))),
1937
1956
  subscribeLive: (cursor) => withClose(client.groups.subscribeEvents(), cursor)
1938
1957
  });
1939
1958
  const clientStream = (client, pollCache, phone, includeGroupEvents, onInbound, recover) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-ts/imessage",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "iMessage provider for spectrum-ts.",
5
5
  "repository": {
6
6
  "type": "git",