@spectrum-ts/imessage 5.1.0 → 6.0.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.
- package/dist/index.d.ts +10 -1
- package/dist/index.js +32 -17
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -199,7 +199,16 @@ declare const imessage: import("@spectrum-ts/core").Platform<import("@spectrum-t
|
|
|
199
199
|
token: import("zod").ZodString;
|
|
200
200
|
phone: import("zod").ZodString;
|
|
201
201
|
}, import("zod/v4/core").$strip>>]>>;
|
|
202
|
-
}, import("zod/v4/core").$strip>]>, import("zod").
|
|
202
|
+
}, import("zod/v4/core").$strip>]>, import("zod").ZodObject<{
|
|
203
|
+
address: import("zod").ZodOptional<import("zod").ZodString>;
|
|
204
|
+
country: import("zod").ZodOptional<import("zod").ZodString>;
|
|
205
|
+
service: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
206
|
+
iMessage: "iMessage";
|
|
207
|
+
unknown: "unknown";
|
|
208
|
+
SMS: "SMS";
|
|
209
|
+
RCS: "RCS";
|
|
210
|
+
}>>;
|
|
211
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
203
212
|
id: import("zod").ZodString;
|
|
204
213
|
type: import("zod").ZodEnum<{
|
|
205
214
|
dm: "dm";
|
package/dist/index.js
CHANGED
|
@@ -186,7 +186,7 @@ const configSchema = z.union([z.object({ local: z.literal(true) }), z.object({
|
|
|
186
186
|
local: z.literal(false).optional().default(false),
|
|
187
187
|
clients: clientEntry.or(z.array(clientEntry)).optional()
|
|
188
188
|
})]);
|
|
189
|
-
z.object({
|
|
189
|
+
const userSchema = z.object({
|
|
190
190
|
address: z.string().optional(),
|
|
191
191
|
country: z.string().optional(),
|
|
192
192
|
service: z.enum([
|
|
@@ -1508,9 +1508,12 @@ const log$1 = createLogger("spectrum.imessage.contact");
|
|
|
1508
1508
|
const SHARE_TTL_MS = 1440 * 60 * 1e3;
|
|
1509
1509
|
const MAX_TRACKED_CHATS = 1e4;
|
|
1510
1510
|
/**
|
|
1511
|
-
* Tracks which chats this bot has already proactively pushed its contact
|
|
1512
|
-
* to, so `im.chats.shareContactInfo` is fired at most once per chat per
|
|
1513
|
-
* per
|
|
1511
|
+
* Tracks which chats this bot's line has already proactively pushed its contact
|
|
1512
|
+
* card to, so `im.chats.shareContactInfo` is fired at most once per chat per
|
|
1513
|
+
* line per 24h. One tracker is created per `AdvancedIMessage` client (see
|
|
1514
|
+
* `getContactShareTracker`), so the dedupe is naturally scoped to the line: a
|
|
1515
|
+
* DM `chatGuid` encodes the peer, not the receiving bot line, so the same guid
|
|
1516
|
+
* arriving on a different line shares independently.
|
|
1514
1517
|
*
|
|
1515
1518
|
* Backed by `lru-cache` for TTL + bounded memory. `ttlAutopurge: false`
|
|
1516
1519
|
* keeps eviction lazy (on access) — there is no background timer to leak
|
|
@@ -1522,6 +1525,10 @@ var ContactShareTracker = class {
|
|
|
1522
1525
|
ttl: SHARE_TTL_MS,
|
|
1523
1526
|
ttlAutopurge: false
|
|
1524
1527
|
});
|
|
1528
|
+
client;
|
|
1529
|
+
constructor(client) {
|
|
1530
|
+
this.client = client;
|
|
1531
|
+
}
|
|
1525
1532
|
/**
|
|
1526
1533
|
* Best-effort share. The cache is set eagerly so that a burst of inbound
|
|
1527
1534
|
* messages for the same chat coalesces to a single API call. On failure the
|
|
@@ -1529,11 +1536,11 @@ var ContactShareTracker = class {
|
|
|
1529
1536
|
* permanently mute the feature for a chat. Never awaits and never throws:
|
|
1530
1537
|
* the receive stream must not crash on share failures.
|
|
1531
1538
|
*/
|
|
1532
|
-
maybeShare(
|
|
1539
|
+
maybeShare(chatGuid) {
|
|
1533
1540
|
if (this.cache.has(chatGuid)) return;
|
|
1534
1541
|
this.cache.set(chatGuid, true);
|
|
1535
1542
|
const safeChatGuid = sanitizeErrorMessage(chatGuid);
|
|
1536
|
-
client.chats.shareContactInfo(chatGuid).then(() => {
|
|
1543
|
+
this.client.chats.shareContactInfo(chatGuid).then(() => {
|
|
1537
1544
|
log$1.info("shared contact card", { "spectrum.imessage.contact.chat": safeChatGuid });
|
|
1538
1545
|
}).catch((error) => {
|
|
1539
1546
|
this.cache.delete(chatGuid);
|
|
@@ -1546,16 +1553,18 @@ var ContactShareTracker = class {
|
|
|
1546
1553
|
};
|
|
1547
1554
|
const trackers = /* @__PURE__ */ new WeakMap();
|
|
1548
1555
|
/**
|
|
1549
|
-
* Returns a per-
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
1556
|
+
* Returns a per-line tracker. Mirrors `getMessageCache` in ../cache.ts — keyed
|
|
1557
|
+
* by the individual `AdvancedIMessage` client, so each line has its own dedupe
|
|
1558
|
+
* state and multiple lines/providers don't share state accidentally. The
|
|
1559
|
+
* WeakMap holds the client weakly, so a torn-down line's tracker is collected
|
|
1560
|
+
* with its client (the tracker's own reference back to the client doesn't pin
|
|
1561
|
+
* it — the entry is a collectible cycle).
|
|
1553
1562
|
*/
|
|
1554
|
-
const getContactShareTracker = (
|
|
1555
|
-
let tracker = trackers.get(
|
|
1563
|
+
const getContactShareTracker = (client) => {
|
|
1564
|
+
let tracker = trackers.get(client);
|
|
1556
1565
|
if (!tracker) {
|
|
1557
|
-
tracker = new ContactShareTracker();
|
|
1558
|
-
trackers.set(
|
|
1566
|
+
tracker = new ContactShareTracker(client);
|
|
1567
|
+
trackers.set(client, tracker);
|
|
1559
1568
|
}
|
|
1560
1569
|
return tracker;
|
|
1561
1570
|
};
|
|
@@ -1786,8 +1795,11 @@ const pollStream = (client, pollCache, phone) => resumableOrderedStream({
|
|
|
1786
1795
|
const clientStream = (client, pollCache, phone, onInbound) => mergeStreams([messageStream(client, phone, onInbound), pollStream(client, pollCache, phone)]);
|
|
1787
1796
|
const messages$1 = (clients, projectConfig) => {
|
|
1788
1797
|
const pollCache = getPollCache(clients);
|
|
1789
|
-
const
|
|
1790
|
-
return mergeStreams(clients.map((entry) =>
|
|
1798
|
+
const shareEnabled = projectConfig?.profile?.imessageSynced === true;
|
|
1799
|
+
return mergeStreams(clients.map((entry) => {
|
|
1800
|
+
const tracker = shareEnabled ? getContactShareTracker(entry.client) : void 0;
|
|
1801
|
+
return clientStream(entry.client, pollCache, entry.phone, tracker ? (chatGuid) => tracker.maybeShare(chatGuid) : void 0);
|
|
1802
|
+
}));
|
|
1791
1803
|
};
|
|
1792
1804
|
//#endregion
|
|
1793
1805
|
//#region src/remote/stream-text.ts
|
|
@@ -2060,7 +2072,10 @@ const imessage = definePlatform("iMessage", {
|
|
|
2060
2072
|
await Promise.all(client.map((entry) => entry.client.close()));
|
|
2061
2073
|
}
|
|
2062
2074
|
},
|
|
2063
|
-
user: {
|
|
2075
|
+
user: {
|
|
2076
|
+
schema: userSchema,
|
|
2077
|
+
resolve: async ({ input }) => ({ id: input.userID })
|
|
2078
|
+
},
|
|
2064
2079
|
space: {
|
|
2065
2080
|
schema: spaceSchema,
|
|
2066
2081
|
params: spaceParamsSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-ts/imessage",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "iMessage provider for spectrum-ts — local and remote (advanced) modes.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"zod": "^4.2.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@spectrum-ts/core": "^
|
|
42
|
+
"@spectrum-ts/core": "^6.0.0",
|
|
43
43
|
"typescript": "^5 || ^6.0.0"
|
|
44
44
|
},
|
|
45
45
|
"license": "MIT"
|