@spectrum-ts/imessage 12.1.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -9
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdvancedIMessage, ChatServiceType } from "@photon-ai/advanced-imessage";
|
|
1
|
+
import { AdvancedIMessage, ChatServiceType } from "@photon-ai/advanced-imessage/grpc";
|
|
2
2
|
import { Attachment, ContentBuilder, ContentInput, SchemaMessage, Space, read } from "@spectrum-ts/core";
|
|
3
3
|
import { PhotoInput } from "@spectrum-ts/core/authoring";
|
|
4
4
|
import z from "zod";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NotFoundError, ValidationError,
|
|
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";
|
|
@@ -265,7 +265,7 @@ async function createCloudClients(projectId, projectSecret) {
|
|
|
265
265
|
if (tokenData.type === "shared") {
|
|
266
266
|
const entries = [{
|
|
267
267
|
phone: SHARED_PHONE,
|
|
268
|
-
client:
|
|
268
|
+
client: createGrpcClient({
|
|
269
269
|
address: process.env.SPECTRUM_IMESSAGE_ADDRESS ?? "imessage.spectrum.photon.codes:443",
|
|
270
270
|
autoIdempotency: true,
|
|
271
271
|
retry: true,
|
|
@@ -283,7 +283,7 @@ async function createCloudClients(projectId, projectSecret) {
|
|
|
283
283
|
for (const [instanceId, token] of Object.entries(dedicated.auth)) {
|
|
284
284
|
const entry = {
|
|
285
285
|
phone: requirePhone(dedicated, instanceId),
|
|
286
|
-
client:
|
|
286
|
+
client: createGrpcClient({
|
|
287
287
|
address: `${instanceId}.imsg.photon.codes:443`,
|
|
288
288
|
autoIdempotency: true,
|
|
289
289
|
retry: true,
|
|
@@ -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.
|
|
1534
|
-
*
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
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)
|
|
@@ -2197,7 +2200,7 @@ const imessage = definePlatform(IMESSAGE_PLATFORM, {
|
|
|
2197
2200
|
createClient: async ({ config, projectId, projectSecret }) => {
|
|
2198
2201
|
if (config.clients) return (Array.isArray(config.clients) ? config.clients : [config.clients]).map((e) => ({
|
|
2199
2202
|
phone: e.phone,
|
|
2200
|
-
client:
|
|
2203
|
+
client: createGrpcClient({
|
|
2201
2204
|
address: e.address,
|
|
2202
2205
|
autoIdempotency: true,
|
|
2203
2206
|
retry: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-ts/imessage",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "iMessage provider for spectrum-ts.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,10 +31,13 @@
|
|
|
31
31
|
"label": "imessage"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@photon-ai/
|
|
34
|
+
"@grpc/grpc-js": "^1.14.4",
|
|
35
|
+
"@photon-ai/advanced-imessage": "^2.0.2",
|
|
36
|
+
"@photon-ai/otel": "^3.3.0",
|
|
36
37
|
"lru-cache": "^11.0.0",
|
|
37
38
|
"marked": "^18.0.5",
|
|
39
|
+
"nice-grpc": "^2.1.16",
|
|
40
|
+
"nice-grpc-common": "^2.0.3",
|
|
38
41
|
"zod": "^4.2.1"
|
|
39
42
|
},
|
|
40
43
|
"peerDependencies": {
|