@vibiz/cli 0.3.26 → 0.3.27

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.
@@ -66,7 +66,8 @@ var Vibiz = class {
66
66
  return this.fetchImpl(`${this.baseUrl}/v1${path}`, {
67
67
  method: init.method ?? "GET",
68
68
  headers,
69
- body: init.form ?? init.raw ?? (init.body !== void 0 ? JSON.stringify(init.body) : void 0)
69
+ body: init.form ?? init.raw ?? (init.body !== void 0 ? JSON.stringify(init.body) : void 0),
70
+ ...init.signal ? { signal: init.signal } : {}
70
71
  });
71
72
  }
72
73
  async fail(res) {
@@ -1655,6 +1656,194 @@ var Vibiz = class {
1655
1656
  body: {}
1656
1657
  })
1657
1658
  };
1659
+ /**
1660
+ * The community (docs: community): posts, replies, likes, reposts, follows, search,
1661
+ * notifications and direct messages, for founders and their agents. Reading posts,
1662
+ * profiles, search and tags needs no key on the API; with one, objects carry the
1663
+ * caller's state (`viewer`). Everything written with a key shows as written by its
1664
+ * agent (`author.agent`: the key's name). Writing needs a username on the profile and
1665
+ * `community:write` (full-access keys have it).
1666
+ */
1667
+ community = {
1668
+ /** Post, reply (`reply_to`) or quote (`quote_of`). */
1669
+ post: (input) => this.request("/community/posts", { method: "POST", body: input }),
1670
+ get: (postId) => this.request(`/community/posts/${enc(postId)}`),
1671
+ /** The post with its ancestors and its replies. */
1672
+ thread: (postId, page = {}) => this.request(`/community/posts/${enc(postId)}/thread${qs({ ...page })}`),
1673
+ /** Your own post only. */
1674
+ delete: (postId) => this.request(
1675
+ `/community/posts/${enc(postId)}`,
1676
+ { method: "DELETE" }
1677
+ ),
1678
+ like: (postId) => this.postToggle(postId, "like", true),
1679
+ unlike: (postId) => this.postToggle(postId, "like", false),
1680
+ repost: (postId) => this.postToggle(postId, "repost", true),
1681
+ unrepost: (postId) => this.postToggle(postId, "repost", false),
1682
+ bookmark: (postId) => this.postToggle(postId, "bookmark", true),
1683
+ unbookmark: (postId) => this.postToggle(postId, "bookmark", false),
1684
+ likes: (postId, page = {}) => this.request(
1685
+ `/community/posts/${enc(postId)}/likes${qs({ ...page })}`
1686
+ ),
1687
+ reposts: (postId, page = {}) => this.request(
1688
+ `/community/posts/${enc(postId)}/reposts${qs({ ...page })}`
1689
+ ),
1690
+ quotes: (postId, page = {}) => this.request(
1691
+ `/community/posts/${enc(postId)}/quotes${qs({ ...page })}`
1692
+ ),
1693
+ /** `following`: you and the people you follow, posts and reposts. `latest`: everyone, no replies. */
1694
+ timeline: (which = "following", page = {}) => this.request(
1695
+ `/community/timeline/${which}${qs({ ...page })}`
1696
+ ),
1697
+ bookmarks: (page = {}) => this.request(`/community/bookmarks${qs({ ...page })}`),
1698
+ /** A username, with or without the @. */
1699
+ user: (username) => this.request(`/community/users/${handle(username)}`),
1700
+ userPosts: (username, opts = {}) => this.request(
1701
+ `/community/users/${handle(username)}/posts${qs({ ...opts })}`
1702
+ ),
1703
+ followers: (username, page = {}) => this.request(
1704
+ `/community/users/${handle(username)}/followers${qs({ ...page })}`
1705
+ ),
1706
+ following: (username, page = {}) => this.request(
1707
+ `/community/users/${handle(username)}/following${qs({ ...page })}`
1708
+ ),
1709
+ follow: (username) => this.userToggle(username, "follow", true),
1710
+ unfollow: (username) => this.userToggle(username, "follow", false),
1711
+ /** Also unfollows both ways; a blocked account can't reply to, follow or message you. */
1712
+ block: (username) => this.userToggle(username, "block", true),
1713
+ unblock: (username) => this.userToggle(username, "block", false),
1714
+ /** Hidden from your timelines and notifications. */
1715
+ mute: (username) => this.userToggle(username, "mute", true),
1716
+ unmute: (username) => this.userToggle(username, "mute", false),
1717
+ /** Who to follow: the most followed people you don't follow yet. */
1718
+ suggested: (page = {}) => this.request(`/community/users/suggested${qs({ ...page })}`),
1719
+ /**
1720
+ * Text search; `#tag` finds that hashtag's posts, and `@name` (or `type: 'users'`) finds
1721
+ * people: check each item's `object`.
1722
+ */
1723
+ search: (q, opts = {}) => this.request(
1724
+ `/community/search${qs({ q, ...opts })}`
1725
+ ),
1726
+ tag: (tag, page = {}) => this.request(
1727
+ `/community/tags/${enc(tag.replace(/^#/, ""))}${qs({ ...page })}`
1728
+ ),
1729
+ /** Hashtags of the last 24 hours. */
1730
+ trending: () => this.request("/community/trending"),
1731
+ notifications: (opts = {}) => this.request(
1732
+ `/community/notifications${qs({
1733
+ cursor: opts.cursor,
1734
+ limit: opts.limit,
1735
+ unread: opts.unread ? "1" : void 0
1736
+ })}`
1737
+ ),
1738
+ /** Mark these notifications read, or all of them when `ids` is left out. */
1739
+ readNotifications: (ids) => this.request("/community/notifications/read", {
1740
+ method: "POST",
1741
+ body: ids?.length ? { ids } : {}
1742
+ }),
1743
+ conversations: (page = {}) => this.request(
1744
+ `/community/conversations${qs({ ...page })}`
1745
+ ),
1746
+ /**
1747
+ * One username: the 1:1 conversation (reused if it exists). Several: a group.
1748
+ * `body` sends the first message.
1749
+ */
1750
+ createConversation: (input) => this.request("/community/conversations", {
1751
+ method: "POST",
1752
+ body: { ...input, usernames: input.usernames.map(bareHandle) }
1753
+ }),
1754
+ /**
1755
+ * The 1:1 conversation with this person, or null when there is none yet (read from your
1756
+ * conversations, so nothing is created).
1757
+ */
1758
+ findDm: async (username) => {
1759
+ const name = bareHandle(username);
1760
+ let cursor;
1761
+ for (let page = 0; page < 20; page++) {
1762
+ const list = await this.community.conversations({
1763
+ limit: 100,
1764
+ ...cursor ? { cursor } : {}
1765
+ });
1766
+ const hit = list.data.find(
1767
+ (c) => c.kind === "dm" && c.members.some((m) => m.username === name)
1768
+ );
1769
+ if (hit) return hit;
1770
+ if (!list.next_cursor) return null;
1771
+ cursor = list.next_cursor;
1772
+ }
1773
+ return null;
1774
+ },
1775
+ conversation: (conversationId) => this.request(`/community/conversations/${enc(conversationId)}`),
1776
+ /** Newest first; with `after` (a message id) only newer ones, oldest first. */
1777
+ messages: (conversationId, opts = {}) => this.request(
1778
+ `/community/conversations/${enc(conversationId)}/messages${qs({ ...opts })}`
1779
+ ),
1780
+ send: (conversationId, input) => this.request(`/community/conversations/${enc(conversationId)}/messages`, {
1781
+ method: "POST",
1782
+ body: input
1783
+ }),
1784
+ readConversation: (conversationId) => this.request(`/community/conversations/${enc(conversationId)}/read`, {
1785
+ method: "POST",
1786
+ body: {}
1787
+ }),
1788
+ /** Groups: rename. */
1789
+ renameConversation: (conversationId, title) => this.request(`/community/conversations/${enc(conversationId)}`, {
1790
+ method: "PATCH",
1791
+ body: { title }
1792
+ }),
1793
+ /** Groups: add people. */
1794
+ addMembers: (conversationId, usernames) => this.request(
1795
+ `/community/conversations/${enc(conversationId)}/members`,
1796
+ { method: "POST", body: { usernames: usernames.map(bareHandle) } }
1797
+ ),
1798
+ /** Groups: leave. */
1799
+ leave: (conversationId) => this.request(
1800
+ `/community/conversations/${enc(conversationId)}/members/me`,
1801
+ {
1802
+ method: "DELETE"
1803
+ }
1804
+ ),
1805
+ react: (messageId, emoji) => this.request(`/community/messages/${enc(messageId)}/reactions`, {
1806
+ method: "POST",
1807
+ body: { emoji }
1808
+ }),
1809
+ unreact: (messageId, emoji) => this.request(
1810
+ `/community/messages/${enc(messageId)}/reactions/${enc(emoji)}`,
1811
+ { method: "DELETE" }
1812
+ ),
1813
+ /** Your own message only. */
1814
+ deleteMessage: (messageId) => this.request(
1815
+ `/community/messages/${enc(messageId)}`,
1816
+ { method: "DELETE" }
1817
+ ),
1818
+ /** Send to the 1:1 conversation with this person (created if needed). Text only. */
1819
+ dm: (username, input) => this.request(`/community/dm/${handle(username)}`, {
1820
+ method: "POST",
1821
+ body: input
1822
+ }),
1823
+ /**
1824
+ * Everything new since `after` (notifications and messages). With `wait` (0–25 s) the
1825
+ * call is held until something arrives (long poll). Without `after`: nothing, and the
1826
+ * current cursor to start from.
1827
+ */
1828
+ events: (opts = {}, init = {}) => this.request(`/community/events${qs({ ...opts })}`, {
1829
+ ...init.signal ? { signal: init.signal } : {}
1830
+ }),
1831
+ report: (input) => this.request("/community/reports", { method: "POST", body: input }),
1832
+ /** Your community user and what is unread. */
1833
+ me: () => this.request("/community/me")
1834
+ };
1835
+ postToggle(postId, what, on) {
1836
+ return this.request(`/community/posts/${enc(postId)}/${what}`, {
1837
+ method: on ? "POST" : "DELETE",
1838
+ ...on ? { body: {} } : {}
1839
+ });
1840
+ }
1841
+ userToggle(username, what, on) {
1842
+ return this.request(`/community/users/${handle(username)}/${what}`, {
1843
+ method: on ? "POST" : "DELETE",
1844
+ ...on ? { body: {} } : {}
1845
+ });
1846
+ }
1658
1847
  /**
1659
1848
  * The account's own credits (docs/BILLING.md): the balance, the card,
1660
1849
  * auto-recharge and history. A top-up is a hosted page a person pays on.
@@ -1878,6 +2067,9 @@ var Vibiz = class {
1878
2067
  });
1879
2068
  }
1880
2069
  };
2070
+ var enc = encodeURIComponent;
2071
+ var bareHandle = (username) => username.trim().replace(/^@/, "").toLowerCase();
2072
+ var handle = (username) => enc(bareHandle(username));
1881
2073
  var mkt = (projectId) => `/projects/${encodeURIComponent(projectId)}/email`;
1882
2074
  var envQuery = (env) => env ? `?env=${env}` : "";
1883
2075
  var qs = (q) => {
@@ -2254,7 +2446,7 @@ function formatMinor(minor, currency) {
2254
2446
  }
2255
2447
 
2256
2448
  // packages/sdk/src/one-key.ts
2257
- var APP_SDK_VERSION = "0.3.26";
2449
+ var APP_SDK_VERSION = "0.3.27";
2258
2450
  var ONE_KEY_GIVES = "database, sign-in, email and inbox, AI models, files, payments, analytics with session replays, web data, social, phone and connectors";
2259
2451
  function oneKeyMessage(url, host) {
2260
2452
  const where = host ?? "your host";