@knocklabs/client 0.8.20 → 0.8.21

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 (84) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/api.js +1 -1
  3. package/dist/cjs/api.js.map +1 -1
  4. package/dist/cjs/clients/feed/feed.js +1 -1
  5. package/dist/cjs/clients/feed/feed.js.map +1 -1
  6. package/dist/cjs/clients/feed/store.js +1 -1
  7. package/dist/cjs/clients/feed/store.js.map +1 -1
  8. package/dist/esm/{api.js → api.mjs} +1 -1
  9. package/dist/esm/api.mjs.map +1 -0
  10. package/dist/esm/clients/feed/{feed.js → feed.mjs} +4 -4
  11. package/dist/esm/clients/feed/feed.mjs.map +1 -0
  12. package/dist/esm/clients/feed/{index.js → index.mjs} +2 -2
  13. package/dist/esm/clients/feed/index.mjs.map +1 -0
  14. package/dist/esm/clients/feed/{store.js → store.mjs} +3 -3
  15. package/dist/esm/clients/feed/store.mjs.map +1 -0
  16. package/dist/esm/clients/feed/{utils.js → utils.mjs} +1 -1
  17. package/dist/esm/clients/feed/utils.mjs.map +1 -0
  18. package/dist/esm/clients/preferences/{index.js → index.mjs} +1 -1
  19. package/dist/esm/clients/preferences/index.mjs.map +1 -0
  20. package/dist/esm/clients/users/{index.js → index.mjs} +1 -1
  21. package/dist/esm/clients/users/index.mjs.map +1 -0
  22. package/dist/esm/index.mjs +12 -0
  23. package/dist/esm/index.mjs.map +1 -0
  24. package/dist/esm/{knock.js → knock.mjs} +5 -5
  25. package/dist/esm/knock.mjs.map +1 -0
  26. package/dist/esm/{networkStatus.js → networkStatus.mjs} +1 -1
  27. package/dist/esm/networkStatus.mjs.map +1 -0
  28. package/package.json +6 -5
  29. package/dist/api.d.ts +0 -25
  30. package/dist/api.d.ts.map +0 -1
  31. package/dist/api.js +0 -84
  32. package/dist/clients/feed/feed.d.ts +0 -64
  33. package/dist/clients/feed/feed.d.ts.map +0 -1
  34. package/dist/clients/feed/feed.js +0 -572
  35. package/dist/clients/feed/index.d.ts +0 -15
  36. package/dist/clients/feed/index.d.ts.map +0 -1
  37. package/dist/clients/feed/index.js +0 -34
  38. package/dist/clients/feed/interfaces.d.ts +0 -60
  39. package/dist/clients/feed/interfaces.d.ts.map +0 -1
  40. package/dist/clients/feed/interfaces.js +0 -2
  41. package/dist/clients/feed/store.d.ts +0 -3
  42. package/dist/clients/feed/store.d.ts.map +0 -1
  43. package/dist/clients/feed/store.js +0 -72
  44. package/dist/clients/feed/types.d.ts +0 -34
  45. package/dist/clients/feed/types.d.ts.map +0 -1
  46. package/dist/clients/feed/types.js +0 -2
  47. package/dist/clients/feed/utils.d.ts +0 -4
  48. package/dist/clients/feed/utils.d.ts.map +0 -1
  49. package/dist/clients/feed/utils.js +0 -21
  50. package/dist/clients/preferences/index.d.ts +0 -46
  51. package/dist/clients/preferences/index.d.ts.map +0 -1
  52. package/dist/clients/preferences/index.js +0 -129
  53. package/dist/clients/preferences/interfaces.d.ts +0 -26
  54. package/dist/clients/preferences/interfaces.d.ts.map +0 -1
  55. package/dist/clients/preferences/interfaces.js +0 -2
  56. package/dist/clients/users/index.d.ts +0 -16
  57. package/dist/clients/users/index.d.ts.map +0 -1
  58. package/dist/clients/users/index.js +0 -56
  59. package/dist/clients/users/interfaces.d.ts +0 -8
  60. package/dist/clients/users/interfaces.d.ts.map +0 -1
  61. package/dist/clients/users/interfaces.js +0 -2
  62. package/dist/esm/api.js.map +0 -1
  63. package/dist/esm/clients/feed/feed.js.map +0 -1
  64. package/dist/esm/clients/feed/index.js.map +0 -1
  65. package/dist/esm/clients/feed/store.js.map +0 -1
  66. package/dist/esm/clients/feed/utils.js.map +0 -1
  67. package/dist/esm/clients/preferences/index.js.map +0 -1
  68. package/dist/esm/clients/users/index.js.map +0 -1
  69. package/dist/esm/index.js +0 -12
  70. package/dist/esm/index.js.map +0 -1
  71. package/dist/esm/knock.js.map +0 -1
  72. package/dist/esm/networkStatus.js.map +0 -1
  73. package/dist/index.d.ts +0 -11
  74. package/dist/index.d.ts.map +0 -1
  75. package/dist/index.js +0 -43
  76. package/dist/interfaces.d.ts +0 -41
  77. package/dist/interfaces.d.ts.map +0 -1
  78. package/dist/interfaces.js +0 -2
  79. package/dist/knock.d.ts +0 -30
  80. package/dist/knock.d.ts.map +0 -1
  81. package/dist/knock.js +0 -135
  82. package/dist/networkStatus.d.ts +0 -8
  83. package/dist/networkStatus.d.ts.map +0 -1
  84. package/dist/networkStatus.js +0 -18
@@ -2,10 +2,10 @@ var c = Object.defineProperty;
2
2
  var l = (s, e, t) => e in s ? c(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
3
  var i = (s, e, t) => (l(s, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import { jwtDecode as u } from "jwt-decode";
5
- import p from "./api.js";
6
- import k from "./clients/feed/index.js";
7
- import d from "./clients/preferences/index.js";
8
- import f from "./clients/users/index.js";
5
+ import p from "./api.mjs";
6
+ import k from "./clients/feed/index.mjs";
7
+ import d from "./clients/preferences/index.mjs";
8
+ import f from "./clients/users/index.mjs";
9
9
  const T = "https://api.knock.app";
10
10
  class x {
11
11
  constructor(e, t = {}) {
@@ -87,4 +87,4 @@ class x {
87
87
  export {
88
88
  x as default
89
89
  };
90
- //# sourceMappingURL=knock.js.map
90
+ //# sourceMappingURL=knock.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knock.mjs","sources":["../../src/knock.ts"],"sourcesContent":["import { jwtDecode } from \"jwt-decode\";\n\nimport ApiClient from \"./api\";\nimport FeedClient from \"./clients/feed\";\nimport Preferences from \"./clients/preferences\";\nimport UserClient from \"./clients/users\";\nimport {\n AuthenticateOptions,\n KnockOptions,\n LogLevel,\n UserTokenExpiringCallback,\n} from \"./interfaces\";\n\nconst DEFAULT_HOST = \"https://api.knock.app\";\n\nclass Knock {\n private host: string;\n private apiClient: ApiClient | null = null;\n public userId: string | undefined;\n public userToken?: string;\n public logLevel?: LogLevel;\n private tokenExpirationTimer: ReturnType<typeof setTimeout> | null = null;\n readonly feeds = new FeedClient(this);\n readonly preferences = new Preferences(this);\n readonly user = new UserClient(this);\n\n constructor(\n readonly apiKey: string,\n options: KnockOptions = {},\n ) {\n this.host = options.host || DEFAULT_HOST;\n this.logLevel = options.logLevel;\n\n this.log(\"Initialized Knock instance\");\n\n // Fail loudly if we're using the wrong API key\n if (this.apiKey && this.apiKey.startsWith(\"sk_\")) {\n throw new Error(\n \"[Knock] You are using your secret API key on the client. Please use the public key.\",\n );\n }\n }\n\n client() {\n if (!this.userId) {\n console.warn(\n `[Knock] You must call authenticate(userId, userToken) first before trying to make a request.\n Typically you'll see this message when you're creating a feed instance before having called\n authenticate with a user Id and token. That means we won't know who to issue the request\n to Knock on behalf of.\n `,\n );\n }\n\n // Initiate a new API client if we don't have one yet\n if (!this.apiClient) {\n this.apiClient = this.createApiClient();\n }\n\n return this.apiClient;\n }\n\n /*\n Authenticates the current user. In non-sandbox environments\n the userToken must be specified.\n */\n authenticate(\n userId: string,\n userToken?: string,\n options?: AuthenticateOptions,\n ) {\n let reinitializeApi = false;\n const currentApiClient = this.apiClient;\n\n // If we've previously been initialized and the values have now changed, then we\n // need to reinitialize any stateful connections we have\n if (\n currentApiClient &&\n (this.userId !== userId || this.userToken !== userToken)\n ) {\n this.log(\"userId or userToken changed; reinitializing connections\");\n this.feeds.teardownInstances();\n this.teardown();\n reinitializeApi = true;\n }\n\n this.userId = userId;\n this.userToken = userToken;\n\n this.log(`Authenticated with userId ${userId}`);\n\n if (this.userToken && options?.onUserTokenExpiring instanceof Function) {\n this.maybeScheduleUserTokenExpiration(\n options.onUserTokenExpiring,\n options.timeBeforeExpirationInMs,\n );\n }\n\n // If we get the signal to reinitialize the api client, then we want to create a new client\n // and the reinitialize any existing feed real-time connections we have so everything continues\n // to work with the new credentials we've been given\n if (reinitializeApi) {\n this.apiClient = this.createApiClient();\n this.feeds.reinitializeInstances();\n this.log(\"Reinitialized real-time connections\");\n }\n\n return;\n }\n\n /*\n Returns whether or this Knock instance is authenticated. Passing `true` will check the presence\n of the userToken as well.\n */\n isAuthenticated(checkUserToken = false) {\n return checkUserToken ? !!(this.userId && this.userToken) : !!this.userId;\n }\n\n // Used to teardown any connected instances\n teardown() {\n if (this.tokenExpirationTimer) {\n clearTimeout(this.tokenExpirationTimer);\n }\n if (this.apiClient?.socket && this.apiClient.socket.isConnected()) {\n this.apiClient.socket.disconnect();\n }\n }\n\n log(message: string) {\n if (this.logLevel === \"debug\") {\n console.log(`[Knock] ${message}`);\n }\n }\n\n /**\n * Initiates an API client\n */\n private createApiClient() {\n return new ApiClient({\n apiKey: this.apiKey,\n host: this.host,\n userToken: this.userToken,\n });\n }\n\n private async maybeScheduleUserTokenExpiration(\n callbackFn: UserTokenExpiringCallback,\n timeBeforeExpirationInMs: number = 30_000,\n ) {\n if (!this.userToken) return;\n\n const decoded = jwtDecode(this.userToken);\n const expiresAtMs = (decoded.exp ?? 0) * 1000;\n const nowMs = Date.now();\n\n // Expiration is in the future\n if (expiresAtMs && expiresAtMs > nowMs) {\n // Check how long until the token should be regenerated\n // | ----------------- | ----------------------- |\n // ^ now ^ expiration offset ^ expires at\n const msInFuture = expiresAtMs - timeBeforeExpirationInMs - nowMs;\n\n this.tokenExpirationTimer = setTimeout(async () => {\n const newToken = await callbackFn(this.userToken as string, decoded);\n\n // Reauthenticate which will handle reinitializing sockets\n if (typeof newToken === \"string\") {\n this.authenticate(this.userId!, newToken, {\n onUserTokenExpiring: callbackFn,\n timeBeforeExpirationInMs: timeBeforeExpirationInMs,\n });\n }\n }, msInFuture);\n }\n }\n}\n\nexport default Knock;\n"],"names":["DEFAULT_HOST","Knock","apiKey","options","__publicField","FeedClient","Preferences","UserClient","userId","userToken","reinitializeApi","checkUserToken","_a","message","ApiClient","callbackFn","timeBeforeExpirationInMs","decoded","jwtDecode","expiresAtMs","nowMs","msInFuture","newToken"],"mappings":";;;;;;;;AAaA,MAAMA,IAAe;AAErB,MAAMC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,WAAAA,IAAiB,CAAC,EAAE,KAAK,UAAU,KAAK,aAAa,CAAC,CAAC,KAAK;AAAA,EACrE;AAAA;AAAA,EAGA,WAAW;;AACT,IAAI,KAAK,wBACP,aAAa,KAAK,oBAAoB,IAEpCC,IAAA,KAAK,cAAL,QAAAA,EAAgB,UAAU,KAAK,UAAU,OAAO,iBAC7C,KAAA,UAAU,OAAO;EAE1B;AAAA,EAEA,IAAIC,GAAiB;AACf,IAAA,KAAK,aAAa,WACZ,QAAA,IAAI,WAAWA,CAAO,EAAE;AAAA,EAEpC;AAAA;AAAA;AAAA;AAAA,EAKQ,kBAAkB;AACxB,WAAO,IAAIC,EAAU;AAAA,MACnB,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK;AAAA,MACX,WAAW,KAAK;AAAA,IAAA,CACjB;AAAA,EACH;AAAA,EAEA,MAAc,iCACZC,GACAC,IAAmC,KACnC;AACA,QAAI,CAAC,KAAK;AAAW;AAEf,UAAAC,IAAUC,EAAU,KAAK,SAAS,GAClCC,KAAeF,EAAQ,OAAO,KAAK,KACnCG,IAAQ,KAAK;AAGf,QAAAD,KAAeA,IAAcC,GAAO;AAIhC,YAAAC,IAAaF,IAAcH,IAA2BI;AAEvD,WAAA,uBAAuB,WAAW,YAAY;AACjD,cAAME,IAAW,MAAMP,EAAW,KAAK,WAAqBE,CAAO;AAG/D,QAAA,OAAOK,KAAa,YACjB,KAAA,aAAa,KAAK,QAASA,GAAU;AAAA,UACxC,qBAAqBP;AAAA,UACrB,0BAAAC;AAAA,QAAA,CACD;AAAA,SAEFK,CAAU;AAAA,IACf;AAAA,EACF;AACF;"}
@@ -12,4 +12,4 @@ export {
12
12
  e as NetworkStatus,
13
13
  n as isRequestInFlight
14
14
  };
15
- //# sourceMappingURL=networkStatus.js.map
15
+ //# sourceMappingURL=networkStatus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networkStatus.mjs","sources":["../../src/networkStatus.ts"],"sourcesContent":["export enum NetworkStatus {\n // Performing a top level loading operation\n loading = \"loading\",\n\n // Performing a fetch more on some already loaded data\n fetchMore = \"fetchMore\",\n\n // No operation is currently in progress\n ready = \"ready\",\n\n // The last operation failed with an error\n error = \"error\",\n}\n\nexport function isRequestInFlight(networkStatus: NetworkStatus): boolean {\n return [NetworkStatus.loading, NetworkStatus.fetchMore].includes(\n networkStatus,\n );\n}\n"],"names":["NetworkStatus","isRequestInFlight","networkStatus"],"mappings":"AAAY,IAAAA,sBAAAA,OAEVA,EAAA,UAAU,WAGVA,EAAA,YAAY,aAGZA,EAAA,QAAQ,SAGRA,EAAA,QAAQ,SAXEA,IAAAA,KAAA,CAAA,CAAA;AAcL,SAASC,EAAkBC,GAAuC;AAChE,SAAA;AAAA,IAAC;AAAA,IAAuB;AAAA;AAAA,EAAA,EAAyB;AAAA,IACtDA;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@knocklabs/client",
3
- "version": "0.8.20",
3
+ "version": "0.8.21",
4
4
  "description": "The clientside library for interacting with Knock",
5
5
  "homepage": "https://github.com/knocklabs/javascript/tree/main/packages/client",
6
6
  "author": "@knocklabs",
7
7
  "license": "MIT",
8
8
  "main": "dist/cjs/index.js",
9
- "module": "dist/esm/index.js",
9
+ "module": "dist/esm/index.mjs",
10
10
  "types": "dist/types/index.d.ts",
11
11
  "typings": "dist/types/index.d.ts",
12
12
  "exports": {
13
13
  ".": {
14
14
  "require": "./dist/cjs/index.js",
15
+ "import": "./dist/esm/index.mjs",
15
16
  "types": "./dist/types/index.d.ts",
16
- "default": "./dist/esm/index.js"
17
+ "default": "./dist/esm/index.mjs"
17
18
  }
18
19
  },
19
20
  "files": [
@@ -39,8 +40,8 @@
39
40
  "type-check": "tsc --noEmit",
40
41
  "type-check:watch": "npm run type-check -- --watch",
41
42
  "build": "yarn clean && yarn build:cjs && yarn build:esm",
42
- "build:esm": "BUILD_TARGET=esm; tsc && vite build",
43
- "build:cjs": "BUILD_TARGET=cjs; tsc && vite build",
43
+ "build:esm": "BUILD_TARGET=esm; vite build",
44
+ "build:cjs": "BUILD_TARGET=cjs; vite build",
44
45
  "prepublishOnly": "npm run build"
45
46
  },
46
47
  "devDependencies": {
package/dist/api.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { AxiosRequestConfig } from "axios";
2
- import { Socket } from "phoenix";
3
- type ApiClientOptions = {
4
- host: string;
5
- apiKey: string;
6
- userToken: string | undefined;
7
- };
8
- export interface ApiResponse {
9
- error?: any;
10
- body?: any;
11
- statusCode: "ok" | "error";
12
- status: number;
13
- }
14
- declare class ApiClient {
15
- private host;
16
- private apiKey;
17
- private userToken;
18
- private axiosClient;
19
- socket: Socket | undefined;
20
- constructor(options: ApiClientOptions);
21
- makeRequest(req: AxiosRequestConfig): Promise<ApiResponse>;
22
- private canRetryRequest;
23
- }
24
- export default ApiClient;
25
- //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAc,EAA6B,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE7E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,MAAM,WAAW,WAAW;IAE1B,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,UAAU,EAAE,IAAI,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,cAAM,SAAS;IACb,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,WAAW,CAAgB;IAE5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEtB,OAAO,EAAE,gBAAgB;IAgC/B,WAAW,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBhE,OAAO,CAAC,eAAe;CAuBxB;AAED,eAAe,SAAS,CAAC"}
package/dist/api.js DELETED
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const axios_1 = __importDefault(require("axios"));
7
- const axios_retry_1 = __importDefault(require("axios-retry"));
8
- const phoenix_1 = require("phoenix");
9
- class ApiClient {
10
- host;
11
- apiKey;
12
- userToken;
13
- axiosClient;
14
- socket;
15
- constructor(options) {
16
- this.host = options.host;
17
- this.apiKey = options.apiKey;
18
- this.userToken = options.userToken || null;
19
- // Create a retryable axios client
20
- this.axiosClient = axios_1.default.create({
21
- baseURL: this.host,
22
- headers: {
23
- Accept: "application/json",
24
- "Content-Type": "application/json",
25
- Authorization: `Bearer ${this.apiKey}`,
26
- "X-Knock-User-Token": this.userToken,
27
- },
28
- });
29
- if (typeof window !== "undefined") {
30
- this.socket = new phoenix_1.Socket(`${this.host.replace("http", "ws")}/ws/v1`, {
31
- params: {
32
- user_token: this.userToken,
33
- api_key: this.apiKey,
34
- },
35
- });
36
- }
37
- (0, axios_retry_1.default)(this.axiosClient, {
38
- retries: 3,
39
- retryCondition: this.canRetryRequest,
40
- retryDelay: axios_retry_1.default.exponentialDelay,
41
- });
42
- }
43
- async makeRequest(req) {
44
- try {
45
- const result = await this.axiosClient(req);
46
- return {
47
- statusCode: result.status < 300 ? "ok" : "error",
48
- body: result.data,
49
- error: undefined,
50
- status: result.status,
51
- };
52
- // eslint:disable-next-line
53
- }
54
- catch (e) {
55
- console.error(e);
56
- return {
57
- statusCode: "error",
58
- status: 500,
59
- body: undefined,
60
- error: e,
61
- };
62
- }
63
- }
64
- canRetryRequest(error) {
65
- // Retry Network Errors.
66
- if (axios_retry_1.default.isNetworkError(error)) {
67
- return true;
68
- }
69
- if (!error.response) {
70
- // Cannot determine if the request can be retried
71
- return false;
72
- }
73
- // Retry Server Errors (5xx).
74
- if (error.response.status >= 500 && error.response.status <= 599) {
75
- return true;
76
- }
77
- // Retry if rate limited.
78
- if (error.response.status === 429) {
79
- return true;
80
- }
81
- return false;
82
- }
83
- }
84
- exports.default = ApiClient;
@@ -1,64 +0,0 @@
1
- import { StoreApi } from "zustand";
2
- import Knock from "../../knock";
3
- import { FeedClientOptions, FetchFeedOptions } from "./interfaces";
4
- import { BindableFeedEvent, FeedEventCallback, FeedItemOrItems, FeedRealTimeCallback, FeedStoreState } from "./types";
5
- export type Status = "seen" | "read" | "interacted" | "archived" | "unseen" | "unread" | "unarchived";
6
- declare class Feed {
7
- readonly knock: Knock;
8
- readonly feedId: string;
9
- private userFeedId;
10
- private channel?;
11
- private broadcaster;
12
- private defaultOptions;
13
- private broadcastChannel;
14
- private disconnectTimer;
15
- private hasSubscribedToRealTimeUpdates;
16
- store: StoreApi<FeedStoreState>;
17
- constructor(knock: Knock, feedId: string, options: FeedClientOptions);
18
- /**
19
- * Used to reinitialize a current feed instance, which is useful when reauthenticating users
20
- */
21
- reinitialize(): void;
22
- /**
23
- * Cleans up a feed instance by destroying the store and disconnecting
24
- * an open socket connection.
25
- */
26
- teardown(): void;
27
- /** Tears down an instance and removes it entirely from the feed manager */
28
- dispose(): void;
29
- listenForUpdates(): void;
30
- on(eventName: BindableFeedEvent, callback: FeedEventCallback | FeedRealTimeCallback): void;
31
- off(eventName: BindableFeedEvent, callback: FeedEventCallback | FeedRealTimeCallback): void;
32
- getState(): FeedStoreState;
33
- markAsSeen(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>;
34
- markAllAsSeen(): Promise<import("../../api").ApiResponse>;
35
- markAsUnseen(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>;
36
- markAsRead(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>;
37
- markAllAsRead(): Promise<import("../../api").ApiResponse>;
38
- markAsUnread(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>;
39
- markAsInteracted(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>;
40
- markAsArchived(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>;
41
- markAllAsArchived(): Promise<import("../../api").ApiResponse>;
42
- markAsUnarchived(itemOrItems: FeedItemOrItems): Promise<import("../../api").ApiResponse>;
43
- fetch(options?: FetchFeedOptions): Promise<{
44
- status: "ok" | "error";
45
- data: any;
46
- } | undefined>;
47
- fetchNextPage(): Promise<void>;
48
- private broadcast;
49
- private onNewMessageReceived;
50
- private buildUserFeedId;
51
- private optimisticallyPerformStatusUpdate;
52
- private makeStatusUpdate;
53
- private makeBulkStatusUpdate;
54
- private setupBroadcastChannel;
55
- private broadcastOverChannel;
56
- private initializeRealtimeConnection;
57
- /**
58
- * Listen for changes to document visibility and automatically disconnect
59
- * or reconnect the socket after a delay
60
- */
61
- private setupAutoSocketManager;
62
- }
63
- export default Feed;
64
- //# sourceMappingURL=feed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../../../src/clients/feed/feed.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,MAAM,aAAa,CAAC;AAGhC,OAAO,EACL,iBAAiB,EAIjB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,iBAAiB,EAEjB,iBAAiB,EAEjB,eAAe,EAEf,oBAAoB,EACpB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,MAAM,GACd,MAAM,GACN,MAAM,GACN,YAAY,GACZ,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,YAAY,CAAC;AASjB,cAAM,IAAI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