@knocklabs/client 0.10.11 → 0.10.13
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/CHANGELOG.md +12 -0
- package/dist/cjs/api.js +1 -1
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/clients/feed/feed.js +1 -1
- package/dist/cjs/clients/feed/feed.js.map +1 -1
- package/dist/cjs/clients/feed/index.js +1 -1
- package/dist/cjs/clients/feed/index.js.map +1 -1
- package/dist/cjs/clients/messages/index.js +1 -1
- package/dist/cjs/clients/messages/index.js.map +1 -1
- package/dist/cjs/clients/objects/index.js +1 -1
- package/dist/cjs/clients/objects/index.js.map +1 -1
- package/dist/cjs/clients/preferences/index.js +1 -1
- package/dist/cjs/clients/preferences/index.js.map +1 -1
- package/dist/cjs/clients/slack/index.js +1 -1
- package/dist/cjs/clients/slack/index.js.map +1 -1
- package/dist/cjs/clients/users/index.js +1 -1
- package/dist/cjs/clients/users/index.js.map +1 -1
- package/dist/cjs/knock.js +1 -1
- package/dist/cjs/knock.js.map +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/clients/feed/feed.mjs +100 -78
- package/dist/esm/clients/feed/feed.mjs.map +1 -1
- package/dist/esm/clients/feed/index.mjs +1 -1
- package/dist/esm/clients/messages/index.mjs +23 -22
- package/dist/esm/clients/messages/index.mjs.map +1 -1
- package/dist/esm/clients/objects/index.mjs +1 -1
- package/dist/esm/clients/preferences/index.mjs +1 -1
- package/dist/esm/clients/slack/index.mjs +1 -1
- package/dist/esm/clients/users/index.mjs +1 -1
- package/dist/esm/knock.mjs +2 -3
- package/dist/esm/knock.mjs.map +1 -1
- package/dist/types/api.d.ts +3 -2
- package/dist/types/clients/feed/feed.d.ts +17 -15
- package/dist/types/clients/feed/feed.d.ts.map +1 -1
- package/dist/types/clients/feed/index.d.ts +4 -3
- package/dist/types/clients/feed/interfaces.d.ts +5 -4
- package/dist/types/clients/feed/store.d.ts +3 -2
- package/dist/types/clients/feed/types.d.ts +4 -3
- package/dist/types/clients/feed/utils.d.ts +3 -2
- package/dist/types/clients/messages/index.d.ts +6 -5
- package/dist/types/clients/messages/index.d.ts.map +1 -1
- package/dist/types/clients/messages/interfaces.d.ts +6 -2
- package/dist/types/clients/messages/interfaces.d.ts.map +1 -1
- package/dist/types/clients/objects/index.d.ts +4 -3
- package/dist/types/clients/preferences/index.d.ts +4 -3
- package/dist/types/clients/preferences/interfaces.d.ts +2 -1
- package/dist/types/clients/slack/index.d.ts +3 -2
- package/dist/types/clients/users/index.d.ts +6 -5
- package/dist/types/clients/users/interfaces.d.ts +2 -1
- package/dist/types/index.d.ts +16 -15
- package/dist/types/interfaces.d.ts +3 -2
- package/dist/types/knock.d.ts +9 -8
- package/package.json +8 -8
- package/src/clients/feed/feed.ts +53 -3
- package/src/clients/messages/index.ts +15 -1
- package/src/clients/messages/interfaces.ts +4 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
2
|
var h = (r, e, t) => e in r ? d(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
-
var u = (r, e, t) =>
|
|
3
|
+
var u = (r, e, t) => h(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
const a = "default";
|
|
5
5
|
function o(r) {
|
|
6
6
|
return typeof r == "object" ? r : { subscribed: r };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var i = Object.defineProperty;
|
|
2
2
|
var l = (c, e, t) => e in c ? i(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
|
|
3
|
-
var r = (c, e, t) =>
|
|
3
|
+
var r = (c, e, t) => l(c, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
const a = "$tenants";
|
|
5
5
|
class u {
|
|
6
6
|
constructor(e) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var i = Object.defineProperty;
|
|
2
2
|
var u = (s, e, t) => e in s ? i(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
-
var a = (s, e, t) =>
|
|
3
|
+
var a = (s, e, t) => u(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
const r = "default";
|
|
5
5
|
class l {
|
|
6
6
|
constructor(e) {
|
package/dist/esm/knock.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var l = Object.defineProperty;
|
|
2
2
|
var c = (n, e, t) => e in n ? l(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
-
var i = (n, e, t) =>
|
|
3
|
+
var i = (n, e, t) => c(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { jwtDecode as u } from "jwt-decode";
|
|
5
5
|
import p from "./api.mjs";
|
|
6
6
|
import k from "./clients/feed/index.mjs";
|
|
@@ -75,8 +75,7 @@ class v {
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
async maybeScheduleUserTokenExpiration(e, t = 3e4) {
|
|
78
|
-
if (!this.userToken)
|
|
79
|
-
return;
|
|
78
|
+
if (!this.userToken) return;
|
|
80
79
|
const s = u(this.userToken), o = (s.exp ?? 0) * 1e3, r = Date.now();
|
|
81
80
|
if (o && o > r) {
|
|
82
81
|
const h = o - t - r;
|
package/dist/esm/knock.mjs.map
CHANGED
|
@@ -1 +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 MessageClient from \"./clients/messages\";\nimport ObjectClient from \"./clients/objects\";\nimport Preferences from \"./clients/preferences\";\nimport SlackClient from \"./clients/slack\";\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 public 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 objects = new ObjectClient(this);\n readonly preferences = new Preferences(this);\n readonly slack = new SlackClient(this);\n readonly user = new UserClient(this);\n readonly messages = new MessageClient(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","ObjectClient","Preferences","SlackClient","UserClient","MessageClient","userId","userToken","reinitializeApi","checkUserToken","_a","message","ApiClient","callbackFn","timeBeforeExpirationInMs","decoded","jwtDecode","expiresAtMs","nowMs","msInFuture","newToken"],"mappings":";;;;;;;;;;;AAgBA,MAAMA,IAAe;AAErB,MAAMC,EAAM;AAAA,EAcV,YACWC,GACTC,IAAwB,IACxB;AAhBK,IAAAC,EAAA;AACC,IAAAA,EAAA,mBAA8B;AAC/B,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACC,IAAAA,EAAA,8BAA6D;AAC5D,IAAAA,EAAA,eAAQ,IAAIC,EAAW,IAAI;AAC3B,IAAAD,EAAA,iBAAU,IAAIE,EAAa,IAAI;AAC/B,IAAAF,EAAA,qBAAc,IAAIG,EAAY,IAAI;AAClC,IAAAH,EAAA,eAAQ,IAAII,EAAY,IAAI;AAC5B,IAAAJ,EAAA,cAAO,IAAIK,EAAW,IAAI;AAC1B,IAAAL,EAAA,kBAAW,IAAIM,EAAc,IAAI;AAYxC,QATS,KAAA,SAAAR,GAGJ,KAAA,OAAOC,EAAQ,QAAQH,GAC5B,KAAK,WAAWG,EAAQ,UAExB,KAAK,IAAI,4BAA4B,GAGjC,KAAK,UAAU,KAAK,OAAO,WAAW,KAAK;AAC7C,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,EAGN;AAAA,EAEA,SAAS;AACH,WAAC,KAAK,UACA,QAAA;AAAA,MACN;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,GASC,KAAK,cACH,KAAA,YAAY,KAAK,oBAGjB,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aACEQ,GACAC,GACAT,GACA;AACA,QAAIU,IAAkB;AAKtB,IAJyB,KAAK,cAM3B,KAAK,WAAWF,KAAU,KAAK,cAAcC,OAE9C,KAAK,IAAI,yDAAyD,GAClE,KAAK,MAAM,qBACX,KAAK,SAAS,GACIC,IAAA,KAGpB,KAAK,SAASF,GACd,KAAK,YAAYC,GAEZ,KAAA,IAAI,6BAA6BD,CAAM,EAAE,GAE1C,KAAK,cAAaR,KAAA,gBAAAA,EAAS,gCAA+B,YACvD,KAAA;AAAA,MACHA,EAAQ;AAAA,MACRA,EAAQ;AAAA,IAAA,GAORU,MACG,KAAA,YAAY,KAAK,mBACtB,KAAK,MAAM,yBACX,KAAK,IAAI,qCAAqC;AAAA,EAIlD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgBC,IAAiB,IAAO;AAC/B,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;
|
|
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 MessageClient from \"./clients/messages\";\nimport ObjectClient from \"./clients/objects\";\nimport Preferences from \"./clients/preferences\";\nimport SlackClient from \"./clients/slack\";\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 public 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 objects = new ObjectClient(this);\n readonly preferences = new Preferences(this);\n readonly slack = new SlackClient(this);\n readonly user = new UserClient(this);\n readonly messages = new MessageClient(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","ObjectClient","Preferences","SlackClient","UserClient","MessageClient","userId","userToken","reinitializeApi","checkUserToken","_a","message","ApiClient","callbackFn","timeBeforeExpirationInMs","decoded","jwtDecode","expiresAtMs","nowMs","msInFuture","newToken"],"mappings":";;;;;;;;;;;AAgBA,MAAMA,IAAe;AAErB,MAAMC,EAAM;AAAA,EAcV,YACWC,GACTC,IAAwB,IACxB;AAhBK,IAAAC,EAAA;AACC,IAAAA,EAAA,mBAA8B;AAC/B,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACC,IAAAA,EAAA,8BAA6D;AAC5D,IAAAA,EAAA,eAAQ,IAAIC,EAAW,IAAI;AAC3B,IAAAD,EAAA,iBAAU,IAAIE,EAAa,IAAI;AAC/B,IAAAF,EAAA,qBAAc,IAAIG,EAAY,IAAI;AAClC,IAAAH,EAAA,eAAQ,IAAII,EAAY,IAAI;AAC5B,IAAAJ,EAAA,cAAO,IAAIK,EAAW,IAAI;AAC1B,IAAAL,EAAA,kBAAW,IAAIM,EAAc,IAAI;AAYxC,QATS,KAAA,SAAAR,GAGJ,KAAA,OAAOC,EAAQ,QAAQH,GAC5B,KAAK,WAAWG,EAAQ,UAExB,KAAK,IAAI,4BAA4B,GAGjC,KAAK,UAAU,KAAK,OAAO,WAAW,KAAK;AAC7C,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,EAGN;AAAA,EAEA,SAAS;AACH,WAAC,KAAK,UACA,QAAA;AAAA,MACN;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,GASC,KAAK,cACH,KAAA,YAAY,KAAK,oBAGjB,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aACEQ,GACAC,GACAT,GACA;AACA,QAAIU,IAAkB;AAKtB,IAJyB,KAAK,cAM3B,KAAK,WAAWF,KAAU,KAAK,cAAcC,OAE9C,KAAK,IAAI,yDAAyD,GAClE,KAAK,MAAM,qBACX,KAAK,SAAS,GACIC,IAAA,KAGpB,KAAK,SAASF,GACd,KAAK,YAAY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A,UACrB,0BAAAC;AAAA,QAAA,CACD;AAAA,SAEFK,CAAU;AAAA,IACf;AAAA,EACF;AACF;"}
|
package/dist/types/api.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { GenericData } from
|
|
2
|
-
import { StoreApi } from
|
|
3
|
-
import Knock from
|
|
4
|
-
import { FeedClientOptions, FetchFeedOptions } from
|
|
5
|
-
import { BindableFeedEvent, FeedEventCallback, FeedItemOrItems, FeedRealTimeCallback, FeedStoreState } from
|
|
1
|
+
import { GenericData } from '@knocklabs/types';
|
|
2
|
+
import { StoreApi } from 'zustand';
|
|
3
|
+
import { default as Knock } from '../../knock';
|
|
4
|
+
import { FeedClientOptions, FetchFeedOptions } from './interfaces';
|
|
5
|
+
import { BindableFeedEvent, FeedEventCallback, FeedItemOrItems, FeedRealTimeCallback, FeedStoreState } from './types';
|
|
6
|
+
|
|
6
7
|
declare class Feed {
|
|
7
8
|
readonly knock: Knock;
|
|
8
9
|
readonly feedId: string;
|
|
@@ -32,16 +33,17 @@ declare class Feed {
|
|
|
32
33
|
on(eventName: BindableFeedEvent, callback: FeedEventCallback | FeedRealTimeCallback): void;
|
|
33
34
|
off(eventName: BindableFeedEvent, callback: FeedEventCallback | FeedRealTimeCallback): void;
|
|
34
35
|
getState(): FeedStoreState;
|
|
35
|
-
markAsSeen(itemOrItems: FeedItemOrItems): Promise<import(
|
|
36
|
-
markAllAsSeen(): Promise<import(
|
|
37
|
-
markAsUnseen(itemOrItems: FeedItemOrItems): Promise<import(
|
|
38
|
-
markAsRead(itemOrItems: FeedItemOrItems): Promise<import(
|
|
39
|
-
markAllAsRead(): Promise<import(
|
|
40
|
-
markAsUnread(itemOrItems: FeedItemOrItems): Promise<import(
|
|
41
|
-
markAsInteracted(itemOrItems: FeedItemOrItems): Promise<import(
|
|
42
|
-
markAsArchived(itemOrItems: FeedItemOrItems): Promise<import(
|
|
43
|
-
markAllAsArchived(): Promise<import(
|
|
44
|
-
|
|
36
|
+
markAsSeen(itemOrItems: FeedItemOrItems): Promise<import('../messages/interfaces').Message<GenericData>[]>;
|
|
37
|
+
markAllAsSeen(): Promise<import('../..').BulkOperation>;
|
|
38
|
+
markAsUnseen(itemOrItems: FeedItemOrItems): Promise<import('../messages/interfaces').Message<GenericData>[]>;
|
|
39
|
+
markAsRead(itemOrItems: FeedItemOrItems): Promise<import('../messages/interfaces').Message<GenericData>[]>;
|
|
40
|
+
markAllAsRead(): Promise<import('../..').BulkOperation>;
|
|
41
|
+
markAsUnread(itemOrItems: FeedItemOrItems): Promise<import('../messages/interfaces').Message<GenericData>[]>;
|
|
42
|
+
markAsInteracted(itemOrItems: FeedItemOrItems, metadata?: Record<string, string>): Promise<import('../messages/interfaces').Message<GenericData>[]>;
|
|
43
|
+
markAsArchived(itemOrItems: FeedItemOrItems): Promise<import('../messages/interfaces').Message<GenericData>[]>;
|
|
44
|
+
markAllAsArchived(): Promise<import('../..').BulkOperation>;
|
|
45
|
+
markAllReadAsArchived(): Promise<import('../..').BulkOperation>;
|
|
46
|
+
markAsUnarchived(itemOrItems: FeedItemOrItems): Promise<import('../messages/interfaces').Message<GenericData>[]>;
|
|
45
47
|
fetch(options?: FetchFeedOptions): Promise<{
|
|
46
48
|
status: "ok" | "error";
|
|
47
49
|
data: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../../../../src/clients/feed/feed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,MAAM,aAAa,CAAC;AAOhC,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;AASjB,cAAM,IAAI;IA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EAAE,eAAe;IAuE3C,iBAAiB;IA2BjB,qBAAqB;IA0CrB,gBAAgB,CAAC,WAAW,EAAE,eAAe;IAS7C,KAAK,CAAC,OAAO,GAAE,gBAAqB;;;;IA0EpC,aAAa;IAenB,OAAO,CAAC,SAAS;YAQH,oBAAoB;IAclC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,iCAAiC;YAiD3B,gBAAgB;YAsBhB,oBAAoB;IA2BlC,OAAO,CAAC,qBAAqB;IAoC7B,OAAO,CAAC,oBAAoB;IAoB5B,OAAO,CAAC,4BAA4B;IA0BpC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,yBAAyB;IAUjC,OAAO,CAAC,SAAS;IAkBjB,OAAO,CAAC,sBAAsB;CA2B/B;AAED,eAAe,IAAI,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import Knock from
|
|
2
|
-
import Feed from
|
|
3
|
-
import { FeedClientOptions } from
|
|
1
|
+
import { default as Knock } from '../../knock';
|
|
2
|
+
import { default as Feed } from './feed';
|
|
3
|
+
import { FeedClientOptions } from './interfaces';
|
|
4
|
+
|
|
4
5
|
declare class FeedClient {
|
|
5
6
|
private instance;
|
|
6
7
|
private feedInstances;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { GenericData, PageInfo } from
|
|
2
|
-
import { Activity, Recipient } from
|
|
3
|
-
import { NetworkStatus } from
|
|
4
|
-
import { NotificationSource } from
|
|
1
|
+
import { GenericData, PageInfo } from '@knocklabs/types';
|
|
2
|
+
import { Activity, Recipient } from '../../interfaces';
|
|
3
|
+
import { NetworkStatus } from '../../networkStatus';
|
|
4
|
+
import { NotificationSource } from '../messages/interfaces';
|
|
5
|
+
|
|
5
6
|
export interface FeedClientOptions {
|
|
6
7
|
before?: string;
|
|
7
8
|
after?: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { FeedStoreState } from
|
|
2
|
-
|
|
1
|
+
import { FeedStoreState } from './types';
|
|
2
|
+
|
|
3
|
+
export default function createStore(): import('zustand/vanilla').StoreApi<FeedStoreState>;
|
|
3
4
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { GenericData, PageInfo } from
|
|
2
|
-
import { NetworkStatus } from
|
|
3
|
-
import { FeedItem, FeedMetadata, FeedResponse } from
|
|
1
|
+
import { GenericData, PageInfo } from '@knocklabs/types';
|
|
2
|
+
import { NetworkStatus } from '../../networkStatus';
|
|
3
|
+
import { FeedItem, FeedMetadata, FeedResponse } from './interfaces';
|
|
4
|
+
|
|
4
5
|
export type StoreFeedResultOptions = {
|
|
5
6
|
shouldSetPage?: boolean;
|
|
6
7
|
shouldAppend?: boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { FeedItem } from
|
|
1
|
+
import { FeedItem } from './interfaces';
|
|
2
|
+
|
|
2
3
|
export declare function deduplicateItems(items: FeedItem[]): FeedItem[];
|
|
3
|
-
export declare function sortItems(items: FeedItem[]): FeedItem<import(
|
|
4
|
+
export declare function sortItems(items: FeedItem[]): FeedItem<import('@knocklabs/types').GenericData>[];
|
|
4
5
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { BulkOperation } from
|
|
2
|
-
import Knock from
|
|
3
|
-
import { BulkUpdateMessagesInChannelProperties, Message, MessageEngagementStatus } from
|
|
1
|
+
import { BulkOperation } from '../../interfaces';
|
|
2
|
+
import { default as Knock } from '../../knock';
|
|
3
|
+
import { BulkUpdateMessagesInChannelProperties, Message, MessageEngagementStatus, UpdateMessageStatusOptions } from './interfaces';
|
|
4
|
+
|
|
4
5
|
declare class MessageClient {
|
|
5
6
|
private knock;
|
|
6
7
|
constructor(knock: Knock);
|
|
7
8
|
get(messageId: string): Promise<Message>;
|
|
8
|
-
updateStatus(messageId: string, status: MessageEngagementStatus): Promise<Message>;
|
|
9
|
+
updateStatus(messageId: string, status: MessageEngagementStatus, options?: UpdateMessageStatusOptions): Promise<Message>;
|
|
9
10
|
removeStatus(messageId: string, status: Exclude<MessageEngagementStatus, "interacted">): Promise<Message>;
|
|
10
|
-
batchUpdateStatuses(messageIds: string[], status: MessageEngagementStatus | "unseen" | "unread" | "unarchived"): Promise<Message[]>;
|
|
11
|
+
batchUpdateStatuses(messageIds: string[], status: MessageEngagementStatus | "unseen" | "unread" | "unarchived", options?: UpdateMessageStatusOptions): Promise<Message[]>;
|
|
11
12
|
bulkUpdateAllStatusesInChannel({ channelId, status, options, }: BulkUpdateMessagesInChannelProperties): Promise<BulkOperation>;
|
|
12
13
|
private handleResponse;
|
|
13
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/clients/messages/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,OAAO,EACL,qCAAqC,EACrC,OAAO,EACP,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/clients/messages/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,OAAO,EACL,qCAAqC,EACrC,OAAO,EACP,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,cAAc,CAAC;AAEtB,cAAM,aAAa;IACjB,OAAO,CAAC,KAAK,CAAQ;gBAET,KAAK,EAAE,KAAK;IAIlB,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASxC,YAAY,CAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,uBAAuB,EAC/B,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,OAAO,CAAC;IAgBb,YAAY,CAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,CAAC,uBAAuB,EAAE,YAAY,CAAC,GACrD,OAAO,CAAC,OAAO,CAAC;IASb,mBAAmB,CACvB,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,EAAE,uBAAuB,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,EACpE,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,OAAO,EAAE,CAAC;IAcf,8BAA8B,CAAC,EACnC,SAAS,EACT,MAAM,EACN,OAAO,GACR,EAAE,qCAAqC,GAAG,OAAO,CAAC,aAAa,CAAC;IAUjE,OAAO,CAAC,cAAc;CAUvB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GenericData } from
|
|
2
|
-
import { RecipientRef } from
|
|
1
|
+
import { GenericData } from '@knocklabs/types';
|
|
2
|
+
import { RecipientRef } from '../..';
|
|
3
|
+
|
|
3
4
|
export type MessageDeliveryStatus = "queued" | "sent" | "delivered" | "delivery_attempted" | "undelivered" | "not_sent";
|
|
4
5
|
export interface NotificationSource {
|
|
5
6
|
key: string;
|
|
@@ -37,4 +38,7 @@ export type BulkUpdateMessagesInChannelProperties = {
|
|
|
37
38
|
tenants?: string[];
|
|
38
39
|
};
|
|
39
40
|
};
|
|
41
|
+
export type UpdateMessageStatusOptions = {
|
|
42
|
+
metadata?: Record<string, string>;
|
|
43
|
+
};
|
|
40
44
|
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/clients/messages/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,MAAM,MAAM,qBAAqB,GAC7B,QAAQ,GACR,MAAM,GACN,WAAW,GACX,oBAAoB,GACpB,aAAa,GACb,UAAU,CAAC;AAEf,M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AM,GAAG,SAAS,CAAC;IACpC,OAAO,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;QAC1D,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;QAC1C,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { GenericData } from
|
|
2
|
-
import { ChannelData } from
|
|
3
|
-
import Knock from
|
|
1
|
+
import { GenericData } from '@knocklabs/types';
|
|
2
|
+
import { ChannelData } from '../../interfaces';
|
|
3
|
+
import { default as Knock } from '../../knock';
|
|
4
|
+
|
|
4
5
|
type GetChannelDataInput = {
|
|
5
6
|
objectId: string;
|
|
6
7
|
collection: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ChannelType } from
|
|
2
|
-
import Knock from
|
|
3
|
-
import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferenceSetting, WorkflowPreferences } from
|
|
1
|
+
import { ChannelType } from '@knocklabs/types';
|
|
2
|
+
import { default as Knock } from '../../knock';
|
|
3
|
+
import { ChannelTypePreferences, PreferenceOptions, PreferenceSet, SetPreferencesProperties, WorkflowPreferenceSetting, WorkflowPreferences } from './interfaces';
|
|
4
|
+
|
|
4
5
|
declare class Preferences {
|
|
5
6
|
private instance;
|
|
6
7
|
constructor(instance: Knock);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import Knock from
|
|
2
|
-
import { AuthCheckInput, GetSlackChannelsInput, GetSlackChannelsResponse, RevokeAccessTokenInput } from
|
|
1
|
+
import { default as Knock } from '../../knock';
|
|
2
|
+
import { AuthCheckInput, GetSlackChannelsInput, GetSlackChannelsResponse, RevokeAccessTokenInput } from './interfaces';
|
|
3
|
+
|
|
3
4
|
declare class SlackClient {
|
|
4
5
|
private instance;
|
|
5
6
|
constructor(instance: Knock);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { GenericData } from
|
|
2
|
-
import { ChannelData, User } from
|
|
3
|
-
import Knock from
|
|
4
|
-
import { GetPreferencesOptions, PreferenceOptions, PreferenceSet, SetPreferencesProperties } from
|
|
5
|
-
import { GetChannelDataInput, SetChannelDataInput } from
|
|
1
|
+
import { GenericData } from '@knocklabs/types';
|
|
2
|
+
import { ChannelData, User } from '../../interfaces';
|
|
3
|
+
import { default as Knock } from '../../knock';
|
|
4
|
+
import { GetPreferencesOptions, PreferenceOptions, PreferenceSet, SetPreferencesProperties } from '../preferences/interfaces';
|
|
5
|
+
import { GetChannelDataInput, SetChannelDataInput } from './interfaces';
|
|
6
|
+
|
|
6
7
|
declare class UserClient {
|
|
7
8
|
private instance;
|
|
8
9
|
constructor(instance: Knock);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import FeedClient,
|
|
2
|
-
import Knock from
|
|
3
|
-
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
1
|
+
import { default as FeedClient, Feed } from './clients/feed';
|
|
2
|
+
import { default as Knock } from './knock';
|
|
3
|
+
|
|
4
|
+
export * from './interfaces';
|
|
5
|
+
export * from './clients/feed/types';
|
|
6
|
+
export * from './clients/feed/interfaces';
|
|
7
|
+
export * from './clients/objects';
|
|
8
|
+
export * from './clients/objects/constants';
|
|
9
|
+
export * from './clients/preferences/interfaces';
|
|
10
|
+
export * from './clients/slack';
|
|
11
|
+
export * from './clients/slack/interfaces';
|
|
12
|
+
export * from './clients/users';
|
|
13
|
+
export * from './clients/users/interfaces';
|
|
14
|
+
export * from './clients/messages';
|
|
15
|
+
export * from './clients/messages/interfaces';
|
|
16
|
+
export * from './networkStatus';
|
|
16
17
|
export default Knock;
|
|
17
18
|
export { Feed, FeedClient };
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GenericData } from
|
|
2
|
-
import { JwtPayload } from
|
|
1
|
+
import { GenericData } from '@knocklabs/types';
|
|
2
|
+
import { JwtPayload } from 'jwt-decode';
|
|
3
|
+
|
|
3
4
|
export type LogLevel = "debug";
|
|
4
5
|
export interface KnockOptions {
|
|
5
6
|
host?: string;
|
package/dist/types/knock.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import ApiClient from
|
|
2
|
-
import FeedClient from
|
|
3
|
-
import MessageClient from
|
|
4
|
-
import ObjectClient from
|
|
5
|
-
import Preferences from
|
|
6
|
-
import SlackClient from
|
|
7
|
-
import UserClient from
|
|
8
|
-
import { AuthenticateOptions, KnockOptions, LogLevel } from
|
|
1
|
+
import { default as ApiClient } from './api';
|
|
2
|
+
import { default as FeedClient } from './clients/feed';
|
|
3
|
+
import { default as MessageClient } from './clients/messages';
|
|
4
|
+
import { default as ObjectClient } from './clients/objects';
|
|
5
|
+
import { default as Preferences } from './clients/preferences';
|
|
6
|
+
import { default as SlackClient } from './clients/slack';
|
|
7
|
+
import { default as UserClient } from './clients/users';
|
|
8
|
+
import { AuthenticateOptions, KnockOptions, LogLevel } from './interfaces';
|
|
9
|
+
|
|
9
10
|
declare class Knock {
|
|
10
11
|
readonly apiKey: string;
|
|
11
12
|
host: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/client",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
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",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"prepublishOnly": "npm run build"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/cli": "^7.
|
|
50
|
+
"@babel/cli": "^7.25.6",
|
|
51
51
|
"@babel/core": "^7.20.0",
|
|
52
52
|
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
53
53
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
|
|
@@ -62,17 +62,17 @@
|
|
|
62
62
|
"eslint": "^8.56.0",
|
|
63
63
|
"jsonwebtoken": "^9.0.2",
|
|
64
64
|
"prettier": "^3.1.0",
|
|
65
|
-
"rimraf": "^
|
|
66
|
-
"rollup": "^
|
|
67
|
-
"typescript": "^5.
|
|
65
|
+
"rimraf": "^6.0.1",
|
|
66
|
+
"rollup": "^4.21.0",
|
|
67
|
+
"typescript": "^5.5.4",
|
|
68
68
|
"vite": "^5.0.0",
|
|
69
|
-
"vitest": "^
|
|
69
|
+
"vitest": "^2.0.5"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@babel/runtime": "^7.
|
|
72
|
+
"@babel/runtime": "^7.25.6",
|
|
73
73
|
"@knocklabs/types": "^0.1.4",
|
|
74
74
|
"@types/phoenix": "^1.5.4",
|
|
75
|
-
"axios": "^1.
|
|
75
|
+
"axios": "^1.7.4",
|
|
76
76
|
"axios-retry": "^3.1.9",
|
|
77
77
|
"eventemitter2": "^6.4.5",
|
|
78
78
|
"jwt-decode": "^4.0.0",
|
package/src/clients/feed/feed.ts
CHANGED
|
@@ -286,7 +286,10 @@ class Feed {
|
|
|
286
286
|
return this.makeStatusUpdate(itemOrItems, "unread");
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
async markAsInteracted(
|
|
289
|
+
async markAsInteracted(
|
|
290
|
+
itemOrItems: FeedItemOrItems,
|
|
291
|
+
metadata?: Record<string, string>,
|
|
292
|
+
) {
|
|
290
293
|
const now = new Date().toISOString();
|
|
291
294
|
this.optimisticallyPerformStatusUpdate(
|
|
292
295
|
itemOrItems,
|
|
@@ -298,7 +301,7 @@ class Feed {
|
|
|
298
301
|
"unread_count",
|
|
299
302
|
);
|
|
300
303
|
|
|
301
|
-
return this.makeStatusUpdate(itemOrItems, "interacted");
|
|
304
|
+
return this.makeStatusUpdate(itemOrItems, "interacted", metadata);
|
|
302
305
|
}
|
|
303
306
|
|
|
304
307
|
/*
|
|
@@ -407,6 +410,48 @@ class Feed {
|
|
|
407
410
|
return result;
|
|
408
411
|
}
|
|
409
412
|
|
|
413
|
+
async markAllReadAsArchived() {
|
|
414
|
+
// Note: there is the potential for a race condition here because the bulk
|
|
415
|
+
// update is an async method, so if a new message comes in during this window before
|
|
416
|
+
// the update has been processed we'll effectively reset the `unseen_count` to be what it was.
|
|
417
|
+
const { items, ...state } = this.store.getState();
|
|
418
|
+
// Filter items to only include those that are unread
|
|
419
|
+
const unreadItems = items.filter((item) => item.read_at === null);
|
|
420
|
+
// Mark all the unread items as archived and read
|
|
421
|
+
const itemIds = unreadItems.map((i) => i.id);
|
|
422
|
+
state.setItemAttrs(itemIds, {
|
|
423
|
+
archived_at: new Date().toISOString(),
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
// Here if we're looking at a feed that excludes all of the archived items by default then we
|
|
427
|
+
// will want to optimistically remove all of the items from the feed as they are now all excluded
|
|
428
|
+
const shouldOptimisticallyRemoveItems =
|
|
429
|
+
this.defaultOptions.archived === "exclude";
|
|
430
|
+
|
|
431
|
+
if (shouldOptimisticallyRemoveItems) {
|
|
432
|
+
// Remove all the read items from the store and reset the badge count
|
|
433
|
+
const remainingItems = items.filter((item) => !itemIds.includes(item.id));
|
|
434
|
+
// Build the new metadata
|
|
435
|
+
const updatedMetadata = {
|
|
436
|
+
...state.metadata,
|
|
437
|
+
total_count: remainingItems.length,
|
|
438
|
+
unread_count: 0,
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
state.setResult({
|
|
442
|
+
entries: remainingItems,
|
|
443
|
+
meta: updatedMetadata,
|
|
444
|
+
page_info: state.pageInfo,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Issue the API request to the bulk status change API
|
|
449
|
+
const result = await this.makeBulkStatusUpdate("archive");
|
|
450
|
+
// this.emitEvent("all_archived", readItems);
|
|
451
|
+
|
|
452
|
+
return result;
|
|
453
|
+
}
|
|
454
|
+
|
|
410
455
|
async markAsUnarchived(itemOrItems: FeedItemOrItems) {
|
|
411
456
|
this.optimisticallyPerformStatusUpdate(itemOrItems, "unarchived", {
|
|
412
457
|
archived_at: null,
|
|
@@ -583,12 +628,17 @@ class Feed {
|
|
|
583
628
|
private async makeStatusUpdate(
|
|
584
629
|
itemOrItems: FeedItemOrItems,
|
|
585
630
|
type: MessageEngagementStatus | "unread" | "unseen" | "unarchived",
|
|
631
|
+
metadata?: Record<string, string>,
|
|
586
632
|
) {
|
|
587
633
|
// Always treat items as a batch to use the corresponding batch endpoint
|
|
588
634
|
const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
|
|
589
635
|
const itemIds = items.map((item) => item.id);
|
|
590
636
|
|
|
591
|
-
const result = await this.knock.messages.batchUpdateStatuses(
|
|
637
|
+
const result = await this.knock.messages.batchUpdateStatuses(
|
|
638
|
+
itemIds,
|
|
639
|
+
type,
|
|
640
|
+
{ metadata },
|
|
641
|
+
);
|
|
592
642
|
|
|
593
643
|
// Emit the event that these items had their statuses changed
|
|
594
644
|
// Note: we do this after the update to ensure that the server event actually completed
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
BulkUpdateMessagesInChannelProperties,
|
|
7
7
|
Message,
|
|
8
8
|
MessageEngagementStatus,
|
|
9
|
+
UpdateMessageStatusOptions,
|
|
9
10
|
} from "./interfaces";
|
|
10
11
|
|
|
11
12
|
class MessageClient {
|
|
@@ -27,10 +28,18 @@ class MessageClient {
|
|
|
27
28
|
async updateStatus(
|
|
28
29
|
messageId: string,
|
|
29
30
|
status: MessageEngagementStatus,
|
|
31
|
+
options?: UpdateMessageStatusOptions,
|
|
30
32
|
): Promise<Message> {
|
|
33
|
+
// Metadata is only required for the "interacted" status
|
|
34
|
+
const payload =
|
|
35
|
+
status === "interacted" && options
|
|
36
|
+
? { metadata: options.metadata }
|
|
37
|
+
: undefined;
|
|
38
|
+
|
|
31
39
|
const result = await this.knock.client().makeRequest({
|
|
32
40
|
method: "PUT",
|
|
33
41
|
url: `/v1/messages/${messageId}/${status}`,
|
|
42
|
+
data: payload,
|
|
34
43
|
});
|
|
35
44
|
|
|
36
45
|
return this.handleResponse<Message>(result);
|
|
@@ -51,11 +60,16 @@ class MessageClient {
|
|
|
51
60
|
async batchUpdateStatuses(
|
|
52
61
|
messageIds: string[],
|
|
53
62
|
status: MessageEngagementStatus | "unseen" | "unread" | "unarchived",
|
|
63
|
+
options?: UpdateMessageStatusOptions,
|
|
54
64
|
): Promise<Message[]> {
|
|
65
|
+
// Metadata is only required for the "interacted" status
|
|
66
|
+
const additionalPayload =
|
|
67
|
+
status === "interacted" && options ? { metadata: options.metadata } : {};
|
|
68
|
+
|
|
55
69
|
const result = await this.knock.client().makeRequest({
|
|
56
70
|
method: "POST",
|
|
57
71
|
url: `/v1/messages/batch/${status}`,
|
|
58
|
-
data: { message_ids: messageIds },
|
|
72
|
+
data: { message_ids: messageIds, ...additionalPayload },
|
|
59
73
|
});
|
|
60
74
|
|
|
61
75
|
return this.handleResponse<Message[]>(result);
|