@knocklabs/client 0.18.3 → 0.18.5
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 +13 -0
- package/dist/cjs/api.js +1 -1
- package/dist/cjs/clients/guide/client.js +1 -1
- package/dist/cjs/clients/guide/client.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 +2 -1
- package/dist/cjs/knock.js.map +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/clients/guide/client.mjs +125 -65
- package/dist/esm/clients/guide/client.mjs.map +1 -1
- package/dist/esm/clients/users/index.mjs +1 -1
- package/dist/esm/clients/users/index.mjs.map +1 -1
- package/dist/esm/knock.mjs +33 -27
- package/dist/esm/knock.mjs.map +1 -1
- package/dist/types/clients/guide/client.d.ts +1 -0
- package/dist/types/clients/guide/client.d.ts.map +1 -1
- package/dist/types/clients/guide/types.d.ts +0 -2
- package/dist/types/clients/guide/types.d.ts.map +1 -1
- package/dist/types/knock.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/guide/client.ts +97 -5
- package/src/clients/guide/types.ts +0 -2
- package/src/clients/users/index.ts +1 -1
- package/src/knock.ts +8 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/clients/users/index.ts"],"sourcesContent":["import { GenericData } from \"@knocklabs/types\";\n\nimport { ApiResponse } from \"../../api\";\nimport { ChannelData, User } from \"../../interfaces\";\nimport Knock from \"../../knock\";\nimport { guidesApiRootPath } from \"../guide/client\";\nimport { GuideEngagementEventBaseParams } from \"../guide/types\";\nimport {\n GetPreferencesOptions,\n PreferenceOptions,\n PreferenceSet,\n SetPreferencesProperties,\n} from \"../preferences/interfaces\";\n\nimport { GetChannelDataInput, SetChannelDataInput } from \"./interfaces\";\n\nconst DEFAULT_PREFERENCE_SET_ID = \"default\";\n\nclass UserClient {\n private instance: Knock;\n\n constructor(instance: Knock) {\n this.instance = instance;\n }\n\n async get() {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}`,\n });\n\n return this.handleResponse<User>(result);\n }\n\n async identify(props: GenericData = {}) {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}`,\n data: props,\n });\n\n return this.handleResponse<User>(result);\n }\n\n async getAllPreferences() {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences`,\n });\n\n return this.handleResponse<PreferenceSet[]>(result);\n }\n\n async getPreferences(\n options: GetPreferencesOptions = {},\n ): Promise<PreferenceSet> {\n this.instance.failIfNotAuthenticated();\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n params: { tenant: options.tenant },\n });\n\n return this.handleResponse<PreferenceSet>(result);\n }\n\n async setPreferences(\n preferenceSet: SetPreferencesProperties,\n options: PreferenceOptions = {},\n ): Promise<PreferenceSet> {\n this.instance.failIfNotAuthenticated();\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n data: preferenceSet,\n });\n\n return this.handleResponse<PreferenceSet>(result);\n }\n\n async getChannelData<T = GenericData>(params: GetChannelDataInput) {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/channel_data/${params.channelId}`,\n });\n\n return this.handleResponse<ChannelData<T>>(result);\n }\n\n async setChannelData<T = GenericData>({\n channelId,\n channelData,\n }: SetChannelDataInput) {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/channel_data/${channelId}`,\n data: { data: channelData },\n });\n\n return this.handleResponse<ChannelData<T>>(result);\n }\n\n async getGuides<P, R>(channelId: string, params: P) {\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `${guidesApiRootPath(this.instance.userId)}/${channelId}`,\n params,\n });\n\n return this.handleResponse<R>(result);\n }\n\n async markGuideStepAs<P extends GuideEngagementEventBaseParams, R>(\n status: \"seen\" | \"interacted\" | \"archived\",\n params: P,\n ) {\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `${guidesApiRootPath(this.instance.userId)}/messages/${
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/clients/users/index.ts"],"sourcesContent":["import { GenericData } from \"@knocklabs/types\";\n\nimport { ApiResponse } from \"../../api\";\nimport { ChannelData, User } from \"../../interfaces\";\nimport Knock from \"../../knock\";\nimport { guidesApiRootPath } from \"../guide/client\";\nimport { GuideEngagementEventBaseParams } from \"../guide/types\";\nimport {\n GetPreferencesOptions,\n PreferenceOptions,\n PreferenceSet,\n SetPreferencesProperties,\n} from \"../preferences/interfaces\";\n\nimport { GetChannelDataInput, SetChannelDataInput } from \"./interfaces\";\n\nconst DEFAULT_PREFERENCE_SET_ID = \"default\";\n\nclass UserClient {\n private instance: Knock;\n\n constructor(instance: Knock) {\n this.instance = instance;\n }\n\n async get() {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}`,\n });\n\n return this.handleResponse<User>(result);\n }\n\n async identify(props: GenericData = {}) {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}`,\n data: props,\n });\n\n return this.handleResponse<User>(result);\n }\n\n async getAllPreferences() {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences`,\n });\n\n return this.handleResponse<PreferenceSet[]>(result);\n }\n\n async getPreferences(\n options: GetPreferencesOptions = {},\n ): Promise<PreferenceSet> {\n this.instance.failIfNotAuthenticated();\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n params: { tenant: options.tenant },\n });\n\n return this.handleResponse<PreferenceSet>(result);\n }\n\n async setPreferences(\n preferenceSet: SetPreferencesProperties,\n options: PreferenceOptions = {},\n ): Promise<PreferenceSet> {\n this.instance.failIfNotAuthenticated();\n const preferenceSetId = options.preferenceSet || DEFAULT_PREFERENCE_SET_ID;\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/preferences/${preferenceSetId}`,\n data: preferenceSet,\n });\n\n return this.handleResponse<PreferenceSet>(result);\n }\n\n async getChannelData<T = GenericData>(params: GetChannelDataInput) {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `/v1/users/${this.instance.userId}/channel_data/${params.channelId}`,\n });\n\n return this.handleResponse<ChannelData<T>>(result);\n }\n\n async setChannelData<T = GenericData>({\n channelId,\n channelData,\n }: SetChannelDataInput) {\n this.instance.failIfNotAuthenticated();\n\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `/v1/users/${this.instance.userId}/channel_data/${channelId}`,\n data: { data: channelData },\n });\n\n return this.handleResponse<ChannelData<T>>(result);\n }\n\n async getGuides<P, R>(channelId: string, params: P) {\n const result = await this.instance.client().makeRequest({\n method: \"GET\",\n url: `${guidesApiRootPath(this.instance.userId)}/${channelId}`,\n params,\n });\n\n return this.handleResponse<R>(result);\n }\n\n async markGuideStepAs<P extends GuideEngagementEventBaseParams, R>(\n status: \"seen\" | \"interacted\" | \"archived\",\n params: P,\n ) {\n const result = await this.instance.client().makeRequest({\n method: \"PUT\",\n url: `${guidesApiRootPath(this.instance.userId)}/messages/${status}`,\n data: params,\n });\n\n return this.handleResponse<R>(result);\n }\n\n private handleResponse<T>(response: ApiResponse) {\n if (response.statusCode === \"error\") {\n throw new Error(response.error || response.body);\n }\n\n return response.body as T;\n }\n}\n\nexport default UserClient;\n"],"names":["DEFAULT_PREFERENCE_SET_ID","UserClient","instance","__publicField","result","props","options","preferenceSetId","preferenceSet","params","channelId","channelData","guidesApiRootPath","status","response"],"mappings":";;;;AAgBA,MAAMA,IAA4B;AAElC,MAAMC,EAAW;AAAA,EAGf,YAAYC,GAAiB;AAFrB,IAAAC,EAAA;AAGN,SAAK,WAAWD;AAAA,EAAA;AAAA,EAGlB,MAAM,MAAM;AACV,SAAK,SAAS,uBAAuB;AAErC,UAAME,IAAS,MAAM,KAAK,SAAS,OAAA,EAAS,YAAY;AAAA,MACtD,QAAQ;AAAA,MACR,KAAK,aAAa,KAAK,SAAS,MAAM;AAAA,IAAA,CACvC;AAEM,WAAA,KAAK,eAAqBA,CAAM;AAAA,EAAA;AAAA,EAGzC,MAAM,SAASC,IAAqB,IAAI;AACtC,SAAK,SAAS,uBAAuB;AAErC,UAAMD,IAAS,MAAM,KAAK,SAAS,OAAA,EAAS,YAAY;AAAA,MACtD,QAAQ;AAAA,MACR,KAAK,aAAa,KAAK,SAAS,MAAM;AAAA,MACtC,MAAMC;AAAA,IAAA,CACP;AAEM,WAAA,KAAK,eAAqBD,CAAM;AAAA,EAAA;AAAA,EAGzC,MAAM,oBAAoB;AACxB,SAAK,SAAS,uBAAuB;AAErC,UAAMA,IAAS,MAAM,KAAK,SAAS,OAAA,EAAS,YAAY;AAAA,MACtD,QAAQ;AAAA,MACR,KAAK,aAAa,KAAK,SAAS,MAAM;AAAA,IAAA,CACvC;AAEM,WAAA,KAAK,eAAgCA,CAAM;AAAA,EAAA;AAAA,EAGpD,MAAM,eACJE,IAAiC,IACT;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MAAM,UAAgBM,GAAmBD,GAAW;AAClD,UAAML,IAAS,MAAM,KAAK,SAAS,OAAA,EAAS,YAAY;AAAA,MACtD,QAAQ;AAAA,MACR,KAAK,GAAGQ,EAAkB,KAAK,SAAS,MAAM,CAAC,IAAIF,CAAS;AAAA,MAC5D,QAAAD;AAAA,IAAA,CACD;AAEM,WAAA,KAAK,eAAkBL,CAAM;AAAA,EAAA;AAAA,EAGtC,MAAM,gBACJS,GACAJ,GACA;AACA,UAAML,IAAS,MAAM,KAAK,SAAS,OAAA,EAAS,YAAY;AAAA,MACtD,QAAQ;AAAA,MACR,KAAK,GAAGQ,EAAkB,KAAK,SAAS,MAAM,CAAC,aAAaC,CAAM;AAAA,MAClE,MAAMJ;AAAA,IAAA,CACP;AAEM,WAAA,KAAK,eAAkBL,CAAM;AAAA,EAAA;AAAA,EAG9B,eAAkBU,GAAuB;AAC3C,QAAAA,EAAS,eAAe;AAC1B,YAAM,IAAI,MAAMA,EAAS,SAASA,EAAS,IAAI;AAGjD,WAAOA,EAAS;AAAA,EAAA;AAEpB;"}
|
package/dist/esm/knock.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var t = (s, i, e) =>
|
|
4
|
-
import { jwtDecode as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
const
|
|
14
|
-
class
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var k = (s, i, e) => i in s ? u(s, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[i] = e;
|
|
3
|
+
var t = (s, i, e) => k(s, typeof i != "symbol" ? i + "" : i, e);
|
|
4
|
+
import { jwtDecode as m } from "jwt-decode";
|
|
5
|
+
import g from "./api.mjs";
|
|
6
|
+
import d from "./clients/feed/index.mjs";
|
|
7
|
+
import p from "./clients/messages/index.mjs";
|
|
8
|
+
import T from "./clients/ms-teams/index.mjs";
|
|
9
|
+
import w from "./clients/objects/index.mjs";
|
|
10
|
+
import y from "./clients/preferences/index.mjs";
|
|
11
|
+
import C from "./clients/slack/index.mjs";
|
|
12
|
+
import E from "./clients/users/index.mjs";
|
|
13
|
+
const A = "https://api.knock.app";
|
|
14
|
+
class F {
|
|
15
15
|
constructor(i, e = {}) {
|
|
16
16
|
t(this, "host");
|
|
17
17
|
t(this, "apiClient", null);
|
|
@@ -19,14 +19,14 @@ class D {
|
|
|
19
19
|
t(this, "userToken");
|
|
20
20
|
t(this, "logLevel");
|
|
21
21
|
t(this, "tokenExpirationTimer", null);
|
|
22
|
-
t(this, "feeds", new
|
|
23
|
-
t(this, "objects", new
|
|
24
|
-
t(this, "preferences", new
|
|
25
|
-
t(this, "slack", new
|
|
26
|
-
t(this, "msTeams", new
|
|
27
|
-
t(this, "user", new
|
|
28
|
-
t(this, "messages", new
|
|
29
|
-
if (this.apiKey = i, this.host = e.host ||
|
|
22
|
+
t(this, "feeds", new d(this));
|
|
23
|
+
t(this, "objects", new w(this));
|
|
24
|
+
t(this, "preferences", new y(this));
|
|
25
|
+
t(this, "slack", new C(this));
|
|
26
|
+
t(this, "msTeams", new T(this));
|
|
27
|
+
t(this, "user", new E(this));
|
|
28
|
+
t(this, "messages", new p(this));
|
|
29
|
+
if (this.apiKey = i, this.host = e.host || A, this.logLevel = e.logLevel, this.log("Initialized Knock instance"), this.apiKey && this.apiKey.startsWith("sk_"))
|
|
30
30
|
throw new Error(
|
|
31
31
|
"[Knock] You are using your secret API key on the client. Please use the public key."
|
|
32
32
|
);
|
|
@@ -46,8 +46,14 @@ class D {
|
|
|
46
46
|
}
|
|
47
47
|
if (c === "inline" && typeof i == "object" && (i != null && i.id)) {
|
|
48
48
|
this.log(`Identifying user ${i.id} inline`);
|
|
49
|
-
const { id:
|
|
50
|
-
this.user.identify(h)
|
|
49
|
+
const { id: x, ...r } = i;
|
|
50
|
+
this.user.identify(r).catch((h) => {
|
|
51
|
+
const f = h instanceof Error ? h.message : "Unknown error";
|
|
52
|
+
this.log(
|
|
53
|
+
`Error identifying user ${i.id} inline:
|
|
54
|
+
${f}`
|
|
55
|
+
);
|
|
56
|
+
});
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
failIfNotAuthenticated() {
|
|
@@ -73,7 +79,7 @@ class D {
|
|
|
73
79
|
* Initiates an API client
|
|
74
80
|
*/
|
|
75
81
|
createApiClient() {
|
|
76
|
-
return new
|
|
82
|
+
return new g({
|
|
77
83
|
apiKey: this.apiKey,
|
|
78
84
|
host: this.host,
|
|
79
85
|
userToken: this.userToken
|
|
@@ -81,7 +87,7 @@ class D {
|
|
|
81
87
|
}
|
|
82
88
|
async maybeScheduleUserTokenExpiration(i, e = 3e4) {
|
|
83
89
|
if (!this.userToken) return;
|
|
84
|
-
const n =
|
|
90
|
+
const n = m(this.userToken), o = (n.exp ?? 0) * 1e3, l = Date.now();
|
|
85
91
|
if (o && o > l) {
|
|
86
92
|
const a = o - e - l;
|
|
87
93
|
this.tokenExpirationTimer = setTimeout(async () => {
|
|
@@ -108,6 +114,6 @@ class D {
|
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
export {
|
|
111
|
-
|
|
117
|
+
F as default
|
|
112
118
|
};
|
|
113
119
|
//# sourceMappingURL=knock.mjs.map
|
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 MsTeamsClient from \"./clients/ms-teams\";\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 UserId,\n UserIdOrUserWithProperties,\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 | null;\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 msTeams = new MsTeamsClient(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 // 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 * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * knock.authenticate({ id: \"user_123\" });\n * ```\n */\n authenticate(\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticateOptions,\n ): never;\n authenticate(\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticateOptions,\n ): void;\n authenticate(\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticateOptions,\n ) {\n let reinitializeApi = false;\n const currentApiClient = this.apiClient;\n const userId = this.getUserId(userIdOrUserWithProperties);\n const identificationStrategy = options?.identificationStrategy || \"inline\";\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 // We explicitly skip the inline identification if the strategy is set to \"skip\"\n if (identificationStrategy === \"skip\") {\n this.log(\"Skipping inline user identification\");\n return;\n }\n\n // Inline identify the user if we've been given an object with an id\n // and the strategy is set to \"inline\".\n if (\n identificationStrategy === \"inline\" &&\n typeof userIdOrUserWithProperties === \"object\" &&\n userIdOrUserWithProperties?.id\n ) {\n this.log(`Identifying user ${userIdOrUserWithProperties.id} inline`);\n const { id, ...properties } = userIdOrUserWithProperties;\n this.user.identify(properties);\n }\n\n return;\n }\n\n failIfNotAuthenticated() {\n if (!this.isAuthenticated()) {\n throw new Error(\"Not authenticated. Please call `authenticate` first.\");\n }\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, force = false) {\n if (this.logLevel === \"debug\" || force) {\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 /**\n * Returns the user id from the given userIdOrUserWithProperties\n * @param userIdOrUserWithProperties - The user id or user object\n * @returns The user id\n * @throws {Error} If the user object does not contain an `id` property\n */\n private getUserId(userIdOrUserWithProperties: UserIdOrUserWithProperties) {\n if (\n typeof userIdOrUserWithProperties === \"string\" ||\n !userIdOrUserWithProperties\n ) {\n return userIdOrUserWithProperties;\n }\n\n if (userIdOrUserWithProperties?.id) {\n return userIdOrUserWithProperties.id;\n }\n\n throw new Error(\"`user` object must contain an `id` property\");\n }\n}\n\nexport default Knock;\n"],"names":["DEFAULT_HOST","Knock","apiKey","options","__publicField","FeedClient","ObjectClient","Preferences","SlackClient","MsTeamsClient","UserClient","MessageClient","userIdOrUserWithProperties","userToken","reinitializeApi","currentApiClient","userId","identificationStrategy","id","properties","checkUserToken","_a","message","force","ApiClient","callbackFn","timeBeforeExpirationInMs","decoded","jwtDecode","expiresAtMs","nowMs","msInFuture","newToken"],"mappings":";;;;;;;;;;;;A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CAAC,KAAK,UAAW;AAEf,UAAAC,IAAUC,EAAU,KAAK,SAAS,GAClCC,KAAeF,EAAQ,OAAO,KAAK,KACnCG,IAAQ,KAAK,IAAI;AAGnB,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,IAAA;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASM,UAAUnB,GAAwD;AACxE,QACE,OAAOA,KAA+B,YACtC,CAACA;AAEM,aAAAA;AAGT,QAAIA,KAAA,QAAAA,EAA4B;AAC9B,aAAOA,EAA2B;AAG9B,UAAA,IAAI,MAAM,6CAA6C;AAAA,EAAA;AAEjE;"}
|
|
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 MsTeamsClient from \"./clients/ms-teams\";\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 UserId,\n UserIdOrUserWithProperties,\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 | null;\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 msTeams = new MsTeamsClient(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 // 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 * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * knock.authenticate({ id: \"user_123\" });\n * ```\n */\n authenticate(\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticateOptions,\n ): never;\n authenticate(\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticateOptions,\n ): void;\n authenticate(\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticateOptions,\n ) {\n let reinitializeApi = false;\n const currentApiClient = this.apiClient;\n const userId = this.getUserId(userIdOrUserWithProperties);\n const identificationStrategy = options?.identificationStrategy || \"inline\";\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 // We explicitly skip the inline identification if the strategy is set to \"skip\"\n if (identificationStrategy === \"skip\") {\n this.log(\"Skipping inline user identification\");\n return;\n }\n\n // Inline identify the user if we've been given an object with an id\n // and the strategy is set to \"inline\".\n if (\n identificationStrategy === \"inline\" &&\n typeof userIdOrUserWithProperties === \"object\" &&\n userIdOrUserWithProperties?.id\n ) {\n this.log(`Identifying user ${userIdOrUserWithProperties.id} inline`);\n const { id, ...properties } = userIdOrUserWithProperties;\n this.user.identify(properties).catch((err) => {\n const errorMessage =\n err instanceof Error ? err.message : \"Unknown error\";\n\n this.log(\n `Error identifying user ${userIdOrUserWithProperties.id} inline:\\n${errorMessage}`,\n );\n });\n }\n\n return;\n }\n\n failIfNotAuthenticated() {\n if (!this.isAuthenticated()) {\n throw new Error(\"Not authenticated. Please call `authenticate` first.\");\n }\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, force = false) {\n if (this.logLevel === \"debug\" || force) {\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 /**\n * Returns the user id from the given userIdOrUserWithProperties\n * @param userIdOrUserWithProperties - The user id or user object\n * @returns The user id\n * @throws {Error} If the user object does not contain an `id` property\n */\n private getUserId(userIdOrUserWithProperties: UserIdOrUserWithProperties) {\n if (\n typeof userIdOrUserWithProperties === \"string\" ||\n !userIdOrUserWithProperties\n ) {\n return userIdOrUserWithProperties;\n }\n\n if (userIdOrUserWithProperties?.id) {\n return userIdOrUserWithProperties.id;\n }\n\n throw new Error(\"`user` object must contain an `id` property\");\n }\n}\n\nexport default Knock;\n"],"names":["DEFAULT_HOST","Knock","apiKey","options","__publicField","FeedClient","ObjectClient","Preferences","SlackClient","MsTeamsClient","UserClient","MessageClient","userIdOrUserWithProperties","userToken","reinitializeApi","currentApiClient","userId","identificationStrategy","id","properties","err","errorMessage","checkUserToken","_a","message","force","ApiClient","callbackFn","timeBeforeExpirationInMs","decoded","jwtDecode","expiresAtMs","nowMs","msInFuture","newToken"],"mappings":";;;;;;;;;;;;AAmBA,MAAMA,IAAe;AAErB,MAAMC,EAAM;AAAA,EAeV,YACWC,GACTC,IAAwB,IACxB;AAjBK,IAAAC,EAAA;AACC,IAAAA,E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AAAA,EAGH,MAAc,iCACZC,GACAC,IAAmC,KACnC;AACI,QAAA,CAAC,KAAK,UAAW;AAEf,UAAAC,IAAUC,EAAU,KAAK,SAAS,GAClCC,KAAeF,EAAQ,OAAO,KAAK,KACnCG,IAAQ,KAAK,IAAI;AAGnB,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,IAAA;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASM,UAAUrB,GAAwD;AACxE,QACE,OAAOA,KAA+B,YACtC,CAACA;AAEM,aAAAA;AAGT,QAAIA,KAAA,QAAAA,EAA4B;AAC9B,aAAOA,EAA2B;AAG9B,UAAA,IAAI,MAAM,6CAA6C;AAAA,EAAA;AAEjE;"}
|
|
@@ -35,6 +35,7 @@ export declare class KnockGuideClient {
|
|
|
35
35
|
unsubscribe(): void;
|
|
36
36
|
private handleSocketEvent;
|
|
37
37
|
setLocation(href: string, additionalParams?: Partial<StoreState>): void;
|
|
38
|
+
exitDebugMode(): void;
|
|
38
39
|
selectGuides<C = Any>(state: StoreState, filters?: SelectFilterParams): KnockGuide<C>[];
|
|
39
40
|
selectGuide<C = Any>(state: StoreState, filters?: SelectFilterParams): KnockGuide<C> | undefined;
|
|
40
41
|
private openGroupStage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/clients/guide/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAA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AC,SAAS;IA4DjB,OAAO,CAAC,gBAAgB;IA4BxB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,mBAAmB;IA+C3B,OAAO,CAAC,8BAA8B;IAYtC,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,sBAAsB;IAiC9B,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,oBAAoB,CA4B1B;IAIF,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,kCAAkC;IAyC1C,OAAO,CAAC,oBAAoB;CAgB7B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GenericData } from '@knocklabs/types';
|
|
2
2
|
export type Any = any;
|
|
3
3
|
export interface StepMessageState {
|
|
4
|
-
id: string;
|
|
5
4
|
seen_at: string | null;
|
|
6
5
|
read_at: string | null;
|
|
7
6
|
interacted_at: string | null;
|
|
@@ -63,7 +62,6 @@ export type GetGuidesResponse = {
|
|
|
63
62
|
guide_group_display_logs: Record<GuideGroupData["key"], string>;
|
|
64
63
|
};
|
|
65
64
|
export type GuideEngagementEventBaseParams = {
|
|
66
|
-
message_id: string;
|
|
67
65
|
channel_id: string;
|
|
68
66
|
guide_key: string;
|
|
69
67
|
guide_id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/clients/guide/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAC/B,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/clients/guide/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAC/B,OAAO,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mBAAmB,GAC5B,IAAI;IAwEP,sBAAsB;IAUtB,eAAe,CAAC,cAAc,UAAQ;IAKtC,QAAQ;IASR,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,UAAQ;IAMlC;;OAEG;IACH,OAAO,CAAC,eAAe;YAQT,gCAAgC;IA+B9C;;;;;OAKG;IACH,OAAO,CAAC,SAAS;CAclB;AAED,eAAe,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/client",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.5",
|
|
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",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"react-native": "./src/index.ts",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"require": "./dist/cjs/index.js",
|
|
16
|
-
"import": "./dist/esm/index.mjs",
|
|
17
15
|
"types": "./dist/types/index.d.ts",
|
|
18
16
|
"react-native": "./src/index.ts",
|
|
17
|
+
"import": "./dist/esm/index.mjs",
|
|
18
|
+
"require": "./dist/cjs/index.js",
|
|
19
19
|
"default": "./dist/esm/index.mjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
@@ -66,6 +66,8 @@ export const DEBUG_QUERY_PARAMS = {
|
|
|
66
66
|
PREVIEW_SESSION_ID: "knock_preview_session_id",
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
const DEBUG_STORAGE_KEY = "knock_guide_debug";
|
|
70
|
+
|
|
69
71
|
// Return the global window object if defined, so to safely guard against SSR.
|
|
70
72
|
const checkForWindow = () => {
|
|
71
73
|
if (typeof window !== "undefined") {
|
|
@@ -76,7 +78,7 @@ const checkForWindow = () => {
|
|
|
76
78
|
export const guidesApiRootPath = (userId: string | undefined | null) =>
|
|
77
79
|
`/v1/users/${userId}/guides`;
|
|
78
80
|
|
|
79
|
-
// Detect debug params
|
|
81
|
+
// Detect debug params from URL or local storage
|
|
80
82
|
const detectDebugParams = (): DebugState => {
|
|
81
83
|
const win = checkForWindow();
|
|
82
84
|
if (!win) {
|
|
@@ -84,10 +86,66 @@ const detectDebugParams = (): DebugState => {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
const urlParams = new URLSearchParams(win.location.search);
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
+
const urlGuideKey = urlParams.get(DEBUG_QUERY_PARAMS.GUIDE_KEY);
|
|
90
|
+
const urlPreviewSessionId = urlParams.get(
|
|
91
|
+
DEBUG_QUERY_PARAMS.PREVIEW_SESSION_ID,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// If URL params exist, persist them to localStorage and return them
|
|
95
|
+
if (urlGuideKey || urlPreviewSessionId) {
|
|
96
|
+
if (win.localStorage) {
|
|
97
|
+
try {
|
|
98
|
+
const debugState = {
|
|
99
|
+
forcedGuideKey: urlGuideKey,
|
|
100
|
+
previewSessionId: urlPreviewSessionId,
|
|
101
|
+
};
|
|
102
|
+
win.localStorage.setItem(DEBUG_STORAGE_KEY, JSON.stringify(debugState));
|
|
103
|
+
} catch {
|
|
104
|
+
// Silently fail in privacy mode
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
forcedGuideKey: urlGuideKey,
|
|
109
|
+
previewSessionId: urlPreviewSessionId,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
89
112
|
|
|
90
|
-
|
|
113
|
+
// Check local storage if no URL params
|
|
114
|
+
let storedGuideKey = null;
|
|
115
|
+
let storedPreviewSessionId = null;
|
|
116
|
+
|
|
117
|
+
if (win.localStorage) {
|
|
118
|
+
try {
|
|
119
|
+
const storedDebugState = win.localStorage.getItem(DEBUG_STORAGE_KEY);
|
|
120
|
+
if (storedDebugState) {
|
|
121
|
+
const parsedDebugState = safeJsonParseDebugParams(storedDebugState);
|
|
122
|
+
storedGuideKey = parsedDebugState.forcedGuideKey;
|
|
123
|
+
storedPreviewSessionId = parsedDebugState.previewSessionId;
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
// Silently fail in privacy mode
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
forcedGuideKey: storedGuideKey,
|
|
132
|
+
previewSessionId: storedPreviewSessionId,
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const safeJsonParseDebugParams = (value: string): DebugState => {
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(value);
|
|
139
|
+
return {
|
|
140
|
+
forcedGuideKey: parsed?.forcedGuideKey ?? null,
|
|
141
|
+
previewSessionId: parsed?.previewSessionId ?? null,
|
|
142
|
+
};
|
|
143
|
+
} catch {
|
|
144
|
+
return {
|
|
145
|
+
forcedGuideKey: null,
|
|
146
|
+
previewSessionId: null,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
91
149
|
};
|
|
92
150
|
|
|
93
151
|
const select = (state: StoreState, filters: SelectFilterParams = {}) => {
|
|
@@ -470,6 +528,41 @@ export class KnockGuideClient {
|
|
|
470
528
|
});
|
|
471
529
|
}
|
|
472
530
|
|
|
531
|
+
exitDebugMode() {
|
|
532
|
+
this.knock.log("[Guide] Exiting debug mode");
|
|
533
|
+
|
|
534
|
+
// Clear localStorage debug params
|
|
535
|
+
const win = checkForWindow();
|
|
536
|
+
if (win?.localStorage) {
|
|
537
|
+
try {
|
|
538
|
+
win.localStorage.removeItem(DEBUG_STORAGE_KEY);
|
|
539
|
+
} catch {
|
|
540
|
+
// Silently fail in privacy mode
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// Clear debug state from store
|
|
545
|
+
this.store.setState((state) => ({
|
|
546
|
+
...state,
|
|
547
|
+
debug: { forcedGuideKey: null, previewSessionId: null },
|
|
548
|
+
previewGuides: {}, // Clear preview guides when exiting debug mode
|
|
549
|
+
}));
|
|
550
|
+
|
|
551
|
+
// Remove URL query params if present
|
|
552
|
+
// Only update the URL if params need to be cleared to avoid unnecessary navigations
|
|
553
|
+
if (win) {
|
|
554
|
+
const url = new URL(win.location.href);
|
|
555
|
+
if (
|
|
556
|
+
url.searchParams.has(DEBUG_QUERY_PARAMS.GUIDE_KEY) ||
|
|
557
|
+
url.searchParams.has(DEBUG_QUERY_PARAMS.PREVIEW_SESSION_ID)
|
|
558
|
+
) {
|
|
559
|
+
url.searchParams.delete(DEBUG_QUERY_PARAMS.GUIDE_KEY);
|
|
560
|
+
url.searchParams.delete(DEBUG_QUERY_PARAMS.PREVIEW_SESSION_ID);
|
|
561
|
+
win.location.href = url.toString();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
473
566
|
//
|
|
474
567
|
// Store selector
|
|
475
568
|
//
|
|
@@ -978,7 +1071,6 @@ export class KnockGuideClient {
|
|
|
978
1071
|
step: GuideStepData,
|
|
979
1072
|
) {
|
|
980
1073
|
return {
|
|
981
|
-
message_id: step.message.id,
|
|
982
1074
|
channel_id: guide.channel_id,
|
|
983
1075
|
guide_key: guide.key,
|
|
984
1076
|
guide_id: guide.id,
|
|
@@ -8,7 +8,6 @@ import { GenericData } from "@knocklabs/types";
|
|
|
8
8
|
export type Any = any;
|
|
9
9
|
|
|
10
10
|
export interface StepMessageState {
|
|
11
|
-
id: string;
|
|
12
11
|
seen_at: string | null;
|
|
13
12
|
read_at: string | null;
|
|
14
13
|
interacted_at: string | null;
|
|
@@ -83,7 +82,6 @@ export type GetGuidesResponse = {
|
|
|
83
82
|
|
|
84
83
|
export type GuideEngagementEventBaseParams = {
|
|
85
84
|
// Base params required for all engagement update events
|
|
86
|
-
message_id: string;
|
|
87
85
|
channel_id: string;
|
|
88
86
|
guide_key: string;
|
|
89
87
|
guide_id: string;
|
|
@@ -130,7 +130,7 @@ class UserClient {
|
|
|
130
130
|
) {
|
|
131
131
|
const result = await this.instance.client().makeRequest({
|
|
132
132
|
method: "PUT",
|
|
133
|
-
url: `${guidesApiRootPath(this.instance.userId)}/messages/${
|
|
133
|
+
url: `${guidesApiRootPath(this.instance.userId)}/messages/${status}`,
|
|
134
134
|
data: params,
|
|
135
135
|
});
|
|
136
136
|
|
package/src/knock.ts
CHANGED
|
@@ -136,7 +136,14 @@ class Knock {
|
|
|
136
136
|
) {
|
|
137
137
|
this.log(`Identifying user ${userIdOrUserWithProperties.id} inline`);
|
|
138
138
|
const { id, ...properties } = userIdOrUserWithProperties;
|
|
139
|
-
this.user.identify(properties)
|
|
139
|
+
this.user.identify(properties).catch((err) => {
|
|
140
|
+
const errorMessage =
|
|
141
|
+
err instanceof Error ? err.message : "Unknown error";
|
|
142
|
+
|
|
143
|
+
this.log(
|
|
144
|
+
`Error identifying user ${userIdOrUserWithProperties.id} inline:\n${errorMessage}`,
|
|
145
|
+
);
|
|
146
|
+
});
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
return;
|