spectrum-ts 1.8.0 → 1.9.1
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.
|
@@ -578,8 +578,6 @@ var MessageCache = class {
|
|
|
578
578
|
var PollCache = class {
|
|
579
579
|
map = /* @__PURE__ */ new Map();
|
|
580
580
|
max;
|
|
581
|
-
selectionEventTimesByPoll = /* @__PURE__ */ new Map();
|
|
582
|
-
selectionsByPoll = /* @__PURE__ */ new Map();
|
|
583
581
|
constructor(max = DEFAULT_MAX) {
|
|
584
582
|
this.max = max;
|
|
585
583
|
}
|
|
@@ -595,61 +593,11 @@ var PollCache = class {
|
|
|
595
593
|
const first = this.map.keys().next().value;
|
|
596
594
|
if (first !== void 0) {
|
|
597
595
|
this.map.delete(first);
|
|
598
|
-
this.selectionEventTimesByPoll.delete(first);
|
|
599
|
-
this.selectionsByPoll.delete(first);
|
|
600
596
|
}
|
|
601
597
|
}
|
|
602
598
|
}
|
|
603
599
|
clear() {
|
|
604
600
|
this.map.clear();
|
|
605
|
-
this.selectionEventTimesByPoll.clear();
|
|
606
|
-
this.selectionsByPoll.clear();
|
|
607
|
-
}
|
|
608
|
-
actorSelectionDeltas(pollId, actorId, optionIds) {
|
|
609
|
-
const previous = this.selectionsByPoll.get(pollId)?.get(actorId);
|
|
610
|
-
if (!previous) {
|
|
611
|
-
return optionIds.map((optionId) => ({ optionId, selected: true }));
|
|
612
|
-
}
|
|
613
|
-
const current = new Set(optionIds);
|
|
614
|
-
const selected = optionIds.filter((optionId) => !previous.has(optionId)).map((optionId) => ({ optionId, selected: true }));
|
|
615
|
-
const deselected = [...previous].filter((optionId) => !current.has(optionId)).map((optionId) => ({ optionId, selected: false }));
|
|
616
|
-
return [...selected, ...deselected];
|
|
617
|
-
}
|
|
618
|
-
clearedActorSelectionDeltas(pollId, actorId) {
|
|
619
|
-
const previous = this.selectionsByPoll.get(pollId)?.get(actorId);
|
|
620
|
-
if (!previous) {
|
|
621
|
-
return [];
|
|
622
|
-
}
|
|
623
|
-
return [...previous].map((optionId) => ({ optionId, selected: false }));
|
|
624
|
-
}
|
|
625
|
-
actorSelection(pollId, actorId) {
|
|
626
|
-
const selection = this.selectionsByPoll.get(pollId)?.get(actorId);
|
|
627
|
-
return selection ? [...selection] : void 0;
|
|
628
|
-
}
|
|
629
|
-
commitActorSelection(pollId, actorId, optionIds, at) {
|
|
630
|
-
let selections = this.selectionsByPoll.get(pollId);
|
|
631
|
-
if (!selections) {
|
|
632
|
-
selections = /* @__PURE__ */ new Map();
|
|
633
|
-
this.selectionsByPoll.set(pollId, selections);
|
|
634
|
-
}
|
|
635
|
-
selections.set(actorId, new Set(optionIds));
|
|
636
|
-
if (!at) {
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
let eventTimes = this.selectionEventTimesByPoll.get(pollId);
|
|
640
|
-
if (!eventTimes) {
|
|
641
|
-
eventTimes = /* @__PURE__ */ new Map();
|
|
642
|
-
this.selectionEventTimesByPoll.set(pollId, eventTimes);
|
|
643
|
-
}
|
|
644
|
-
const eventTime = at.getTime();
|
|
645
|
-
const previousTime = eventTimes.get(actorId);
|
|
646
|
-
if (previousTime === void 0 || eventTime >= previousTime) {
|
|
647
|
-
eventTimes.set(actorId, eventTime);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
isStaleActorSelectionEvent(pollId, actorId, at) {
|
|
651
|
-
const previousTime = this.selectionEventTimesByPoll.get(pollId)?.get(actorId);
|
|
652
|
-
return previousTime !== void 0 && at.getTime() < previousTime;
|
|
653
601
|
}
|
|
654
602
|
};
|
|
655
603
|
var messageCaches = /* @__PURE__ */ new WeakMap();
|
|
@@ -1711,8 +1659,7 @@ var fetchPollInfo = async (client, cache, event) => {
|
|
|
1711
1659
|
}
|
|
1712
1660
|
};
|
|
1713
1661
|
var resolvePoll = async (client, cache, event) => {
|
|
1714
|
-
const
|
|
1715
|
-
const cached = cache.get(pollId);
|
|
1662
|
+
const cached = cache.get(event.pollMessageGuid);
|
|
1716
1663
|
if (cached) {
|
|
1717
1664
|
return cached;
|
|
1718
1665
|
}
|
|
@@ -1747,25 +1694,6 @@ var buildPollOptionMessage = (input) => {
|
|
|
1747
1694
|
})
|
|
1748
1695
|
};
|
|
1749
1696
|
};
|
|
1750
|
-
var buildPollOptionMessages = (input) => {
|
|
1751
|
-
const messages5 = [];
|
|
1752
|
-
for (const delta of input.deltas) {
|
|
1753
|
-
const message = buildPollOptionMessage({
|
|
1754
|
-
cached: input.cached,
|
|
1755
|
-
chatGuid: input.chatGuid,
|
|
1756
|
-
event: input.event,
|
|
1757
|
-
optionId: delta.optionId,
|
|
1758
|
-
phone: input.phone,
|
|
1759
|
-
selected: delta.selected,
|
|
1760
|
-
senderAddress: input.senderAddress
|
|
1761
|
-
});
|
|
1762
|
-
if (message) {
|
|
1763
|
-
messages5.push(message);
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
return messages5;
|
|
1767
|
-
};
|
|
1768
|
-
var allOptionIdsKnown = (cached, optionIds) => optionIds.every((optionId) => cached.optionsByIdentifier.has(optionId));
|
|
1769
1697
|
var refreshPollMetadata = async (client, pollCache, event) => {
|
|
1770
1698
|
const info = await fetchPollInfo(client, pollCache, event);
|
|
1771
1699
|
if (!info) {
|
|
@@ -1773,94 +1701,39 @@ var refreshPollMetadata = async (client, pollCache, event) => {
|
|
|
1773
1701
|
}
|
|
1774
1702
|
return pollCache.get(info.pollMessageGuid);
|
|
1775
1703
|
};
|
|
1776
|
-
var
|
|
1704
|
+
var toPollOptionMessage = async (client, pollCache, event, phone) => {
|
|
1777
1705
|
const senderAddress = event.actor?.address;
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
}
|
|
1781
|
-
const pollId = event.pollMessageGuid;
|
|
1782
|
-
if (pollCache.isStaleActorSelectionEvent(
|
|
1783
|
-
pollId,
|
|
1784
|
-
senderAddress,
|
|
1785
|
-
event.occurredAt
|
|
1786
|
-
)) {
|
|
1706
|
+
const optionId = event.delta.optionIdentifier;
|
|
1707
|
+
if (!(senderAddress && optionId)) {
|
|
1787
1708
|
return [];
|
|
1788
1709
|
}
|
|
1789
|
-
|
|
1710
|
+
let cached = await resolvePoll(client, pollCache, event);
|
|
1790
1711
|
if (!cached) {
|
|
1791
1712
|
return [];
|
|
1792
1713
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
(optionId) => !resolvedPoll.optionsByIdentifier.has(optionId)
|
|
1798
|
-
)) {
|
|
1799
|
-
const snapshot = await refreshPollMetadata(client, pollCache, event);
|
|
1800
|
-
if (snapshot) {
|
|
1801
|
-
resolvedPoll = snapshot;
|
|
1714
|
+
if (!cached.optionsByIdentifier.has(optionId)) {
|
|
1715
|
+
const refreshed = await refreshPollMetadata(client, pollCache, event);
|
|
1716
|
+
if (refreshed) {
|
|
1717
|
+
cached = refreshed;
|
|
1802
1718
|
}
|
|
1803
1719
|
}
|
|
1804
|
-
|
|
1805
|
-
return [];
|
|
1806
|
-
}
|
|
1807
|
-
const deltas = pollCache.actorSelectionDeltas(
|
|
1808
|
-
pollId,
|
|
1809
|
-
senderAddress,
|
|
1810
|
-
currentOptionIds
|
|
1811
|
-
);
|
|
1812
|
-
const messages5 = buildPollOptionMessages({
|
|
1813
|
-
cached: resolvedPoll,
|
|
1814
|
-
chatGuid: chatGuidStr,
|
|
1815
|
-
deltas,
|
|
1816
|
-
event,
|
|
1817
|
-
phone,
|
|
1818
|
-
senderAddress
|
|
1819
|
-
});
|
|
1820
|
-
pollCache.commitActorSelection(
|
|
1821
|
-
pollId,
|
|
1822
|
-
senderAddress,
|
|
1823
|
-
currentOptionIds,
|
|
1824
|
-
event.occurredAt
|
|
1825
|
-
);
|
|
1826
|
-
return messages5;
|
|
1827
|
-
};
|
|
1828
|
-
var toPollUnvoteMessages = async (client, pollCache, event, phone) => {
|
|
1829
|
-
const senderAddress = event.actor?.address;
|
|
1830
|
-
if (!senderAddress) {
|
|
1831
|
-
return [];
|
|
1832
|
-
}
|
|
1833
|
-
const pollId = event.pollMessageGuid;
|
|
1834
|
-
if (pollCache.isStaleActorSelectionEvent(
|
|
1835
|
-
pollId,
|
|
1836
|
-
senderAddress,
|
|
1837
|
-
event.occurredAt
|
|
1838
|
-
)) {
|
|
1839
|
-
return [];
|
|
1840
|
-
}
|
|
1841
|
-
const cached = await resolvePoll(client, pollCache, event);
|
|
1842
|
-
if (!cached) {
|
|
1843
|
-
return [];
|
|
1844
|
-
}
|
|
1845
|
-
const chatGuidStr = event.chatGuid;
|
|
1846
|
-
const deltas = pollCache.clearedActorSelectionDeltas(pollId, senderAddress);
|
|
1847
|
-
const messages5 = buildPollOptionMessages({
|
|
1720
|
+
const message = buildPollOptionMessage({
|
|
1848
1721
|
cached,
|
|
1849
|
-
chatGuid:
|
|
1850
|
-
deltas,
|
|
1722
|
+
chatGuid: event.chatGuid,
|
|
1851
1723
|
event,
|
|
1724
|
+
optionId,
|
|
1852
1725
|
phone,
|
|
1726
|
+
selected: event.delta.type === "voted",
|
|
1853
1727
|
senderAddress
|
|
1854
1728
|
});
|
|
1855
|
-
|
|
1856
|
-
return messages5;
|
|
1729
|
+
return message ? [message] : [];
|
|
1857
1730
|
};
|
|
1858
1731
|
var toPollDeltaMessages = async (client, pollCache, event, phone) => {
|
|
1859
1732
|
if (isVotedPollEvent(event)) {
|
|
1860
|
-
return
|
|
1733
|
+
return toPollOptionMessage(client, pollCache, event, phone);
|
|
1861
1734
|
}
|
|
1862
1735
|
if (isUnvotedPollEvent(event)) {
|
|
1863
|
-
return
|
|
1736
|
+
return toPollOptionMessage(client, pollCache, event, phone);
|
|
1864
1737
|
}
|
|
1865
1738
|
return [];
|
|
1866
1739
|
};
|
|
@@ -1875,7 +1748,7 @@ var isRetryableIMessageStreamError = (error) => {
|
|
|
1875
1748
|
}
|
|
1876
1749
|
return false;
|
|
1877
1750
|
};
|
|
1878
|
-
var isEventFromCurrentAccount = (event, phone) => phone !== SHARED_PHONE && event.actor?.address !== void 0 && event.actor.address === phone;
|
|
1751
|
+
var isEventFromCurrentAccount = (event, phone) => event.isFromMe || phone !== SHARED_PHONE && event.actor?.address !== void 0 && event.actor.address === phone;
|
|
1879
1752
|
var toMessageItem = async (client, event, phone, cursor) => {
|
|
1880
1753
|
if (event.type === "message.received") {
|
|
1881
1754
|
if (event.message.isFromMe) {
|
package/dist/index.js
CHANGED
|
@@ -1971,6 +1971,10 @@ import {
|
|
|
1971
1971
|
} from "@photon-ai/otel";
|
|
1972
1972
|
import z from "zod";
|
|
1973
1973
|
|
|
1974
|
+
// src/build-env.ts
|
|
1975
|
+
var SPECTRUM_SDK_VERSION = "local";
|
|
1976
|
+
var SPECTRUM_BUILD_ENV = "development";
|
|
1977
|
+
|
|
1974
1978
|
// src/utils/store.ts
|
|
1975
1979
|
var isRecordObject = (value) => {
|
|
1976
1980
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
@@ -2026,9 +2030,6 @@ function createStore() {
|
|
|
2026
2030
|
};
|
|
2027
2031
|
}
|
|
2028
2032
|
|
|
2029
|
-
// src/version.ts
|
|
2030
|
-
var SPECTRUM_SDK_VERSION = "1.8.0";
|
|
2031
|
-
|
|
2032
2033
|
// src/spectrum.ts
|
|
2033
2034
|
var PHOTON_OTEL_ENDPOINT = "https://otlp.photon.codes";
|
|
2034
2035
|
var lifecycleLog = createLogger("spectrum.lifecycle");
|
|
@@ -2058,7 +2059,9 @@ function bootstrapTelemetry(opts) {
|
|
|
2058
2059
|
const credential = `${opts.projectId}:${opts.projectSecret}`;
|
|
2059
2060
|
headers.Authorization = `Basic ${btoa(credential)}`;
|
|
2060
2061
|
}
|
|
2061
|
-
const resourceAttributes = {
|
|
2062
|
+
const resourceAttributes = {
|
|
2063
|
+
"deployment.environment": process.env.DEPLOYMENT_ENV ?? SPECTRUM_BUILD_ENV
|
|
2064
|
+
};
|
|
2062
2065
|
if (opts.projectId) {
|
|
2063
2066
|
resourceAttributes["spectrum.project_id"] = opts.projectId;
|
|
2064
2067
|
}
|
package/dist/providers/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spectrum-ts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@photon-ai/advanced-imessage": "^0.7.
|
|
26
|
+
"@photon-ai/advanced-imessage": "^0.7.2",
|
|
27
27
|
"@photon-ai/imessage-kit": "^3.0.0",
|
|
28
28
|
"@photon-ai/otel": "^0.1.1",
|
|
29
29
|
"@photon-ai/whatsapp-business": "^0.1.1",
|