@knocklabs/client 0.10.13 → 0.10.15

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 26166e3: fix: update preference set types
8
+ - Updated dependencies [26166e3]
9
+ - @knocklabs/types@0.1.5
10
+
11
+ ## 0.10.14
12
+
13
+ ### Patch Changes
14
+
15
+ - 7510909: fix: ensure axios is always imported correctly
16
+
3
17
  ## 0.10.13
4
18
 
5
19
  ### Patch Changes
package/dist/cjs/api.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var a=(s,e,t)=>e in s?o(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var r=(s,e,t)=>a(s,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("axios"),i=require("axios-retry"),u=require("phoenix");class c{constructor(e){r(this,"host");r(this,"apiKey");r(this,"userToken");r(this,"axiosClient");r(this,"socket");this.host=e.host,this.apiKey=e.apiKey,this.userToken=e.userToken||null,this.axiosClient=n.create({baseURL:this.host,headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`,"X-Knock-User-Token":this.userToken}}),typeof window<"u"&&(this.socket=new u.Socket(`${this.host.replace("http","ws")}/ws/v1`,{params:{user_token:this.userToken,api_key:this.apiKey}})),i(this.axiosClient,{retries:3,retryCondition:this.canRetryRequest,retryDelay:i.exponentialDelay})}async makeRequest(e){try{const t=await this.axiosClient(e);return{statusCode:t.status<300?"ok":"error",body:t.data,error:void 0,status:t.status}}catch(t){return console.error(t),{statusCode:"error",status:500,body:void 0,error:t}}}canRetryRequest(e){return i.isNetworkError(e)?!0:e.response?e.response.status>=500&&e.response.status<=599||e.response.status===429:!1}}exports.default=c;
1
+ "use strict";var a=Object.defineProperty;var n=(s,e,t)=>e in s?a(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var r=(s,e,t)=>n(s,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("axios"),o=require("axios-retry"),u=require("phoenix");class c{constructor(e){r(this,"host");r(this,"apiKey");r(this,"userToken");r(this,"axiosClient");r(this,"socket");this.host=e.host,this.apiKey=e.apiKey,this.userToken=e.userToken||null;const t=i.default?i.default:i;this.axiosClient=t.create({baseURL:this.host,headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`,"X-Knock-User-Token":this.userToken}}),typeof window<"u"&&(this.socket=new u.Socket(`${this.host.replace("http","ws")}/ws/v1`,{params:{user_token:this.userToken,api_key:this.apiKey}})),o(this.axiosClient,{retries:3,retryCondition:this.canRetryRequest,retryDelay:o.exponentialDelay})}async makeRequest(e){try{const t=await this.axiosClient(e);return{statusCode:t.status<300?"ok":"error",body:t.data,error:void 0,status:t.status}}catch(t){return console.error(t),{statusCode:"error",status:500,body:void 0,error:t}}}canRetryRequest(e){return o.isNetworkError(e)?!0:e.response?e.response.status>=500&&e.response.status<=599||e.response.status===429:!1}}exports.default=c;
2
2
  //# sourceMappingURL=api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sources":["../../src/api.ts"],"sourcesContent":["import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from \"axios\";\nimport axiosRetry from \"axios-retry\";\nimport { Socket } from \"phoenix\";\n\ntype ApiClientOptions = {\n host: string;\n apiKey: string;\n userToken: string | undefined;\n};\n\nexport interface ApiResponse {\n // eslint-disable-next-line\n error?: any;\n // eslint-disable-next-line\n body?: any;\n statusCode: \"ok\" | \"error\";\n status: number;\n}\n\nclass ApiClient {\n private host: string;\n private apiKey: string;\n private userToken: string | null;\n private axiosClient: AxiosInstance;\n\n public socket: Socket | undefined;\n\n constructor(options: ApiClientOptions) {\n this.host = options.host;\n this.apiKey = options.apiKey;\n this.userToken = options.userToken || null;\n\n // Create a retryable axios client\n this.axiosClient = axios.create({\n baseURL: this.host,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n \"X-Knock-User-Token\": this.userToken,\n },\n });\n\n if (typeof window !== \"undefined\") {\n this.socket = new Socket(`${this.host.replace(\"http\", \"ws\")}/ws/v1`, {\n params: {\n user_token: this.userToken,\n api_key: this.apiKey,\n },\n });\n }\n\n axiosRetry(this.axiosClient, {\n retries: 3,\n retryCondition: this.canRetryRequest,\n retryDelay: axiosRetry.exponentialDelay,\n });\n }\n\n async makeRequest(req: AxiosRequestConfig): Promise<ApiResponse> {\n try {\n const result = await this.axiosClient(req);\n\n return {\n statusCode: result.status < 300 ? \"ok\" : \"error\",\n body: result.data,\n error: undefined,\n status: result.status,\n };\n\n // eslint:disable-next-line\n } catch (e: unknown) {\n console.error(e);\n\n return {\n statusCode: \"error\",\n status: 500,\n body: undefined,\n error: e,\n };\n }\n }\n\n private canRetryRequest(error: AxiosError) {\n // Retry Network Errors.\n if (axiosRetry.isNetworkError(error)) {\n return true;\n }\n\n if (!error.response) {\n // Cannot determine if the request can be retried\n return false;\n }\n\n // Retry Server Errors (5xx).\n if (error.response.status >= 500 && error.response.status <= 599) {\n return true;\n }\n\n // Retry if rate limited.\n if (error.response.status === 429) {\n return true;\n }\n\n return false;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","axios","Socket","axiosRetry","req","result","e","error"],"mappings":"uVAmBA,MAAMA,CAAU,CAQd,YAAYC,EAA2B,CAP/BC,EAAA,aACAA,EAAA,eACAA,EAAA,kBACAA,EAAA,oBAEDA,EAAA,eAGL,KAAK,KAAOD,EAAQ,KACpB,KAAK,OAASA,EAAQ,OACjB,KAAA,UAAYA,EAAQ,WAAa,KAGjC,KAAA,YAAcE,EAAM,OAAO,CAC9B,QAAS,KAAK,KACd,QAAS,CACP,OAAQ,mBACR,eAAgB,mBAChB,cAAe,UAAU,KAAK,MAAM,GACpC,qBAAsB,KAAK,SAC7B,CAAA,CACD,EAEG,OAAO,OAAW,MACf,KAAA,OAAS,IAAIC,EAAA,OAAO,GAAG,KAAK,KAAK,QAAQ,OAAQ,IAAI,CAAC,SAAU,CACnE,OAAQ,CACN,WAAY,KAAK,UACjB,QAAS,KAAK,MAChB,CAAA,CACD,GAGHC,EAAW,KAAK,YAAa,CAC3B,QAAS,EACT,eAAgB,KAAK,gBACrB,WAAYA,EAAW,gBAAA,CACxB,CACH,CAEA,MAAM,YAAYC,EAA+C,CAC3D,GAAA,CACF,MAAMC,EAAS,MAAM,KAAK,YAAYD,CAAG,EAElC,MAAA,CACL,WAAYC,EAAO,OAAS,IAAM,KAAO,QACzC,KAAMA,EAAO,KACb,MAAO,OACP,OAAQA,EAAO,MAAA,QAIVC,EAAY,CACnB,eAAQ,MAAMA,CAAC,EAER,CACL,WAAY,QACZ,OAAQ,IACR,KAAM,OACN,MAAOA,CAAA,CAEX,CACF,CAEQ,gBAAgBC,EAAmB,CAErC,OAAAJ,EAAW,eAAeI,CAAK,EAC1B,GAGJA,EAAM,SAMPA,EAAM,SAAS,QAAU,KAAOA,EAAM,SAAS,QAAU,KAKzDA,EAAM,SAAS,SAAW,IATrB,EAcX,CACF"}
1
+ {"version":3,"file":"api.js","sources":["../../src/api.ts"],"sourcesContent":["import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from \"axios\";\nimport axiosRetry from \"axios-retry\";\nimport { Socket } from \"phoenix\";\n\ntype ApiClientOptions = {\n host: string;\n apiKey: string;\n userToken: string | undefined;\n};\n\nexport interface ApiResponse {\n // eslint-disable-next-line\n error?: any;\n // eslint-disable-next-line\n body?: any;\n statusCode: \"ok\" | \"error\";\n status: number;\n}\n\nclass ApiClient {\n private host: string;\n private apiKey: string;\n private userToken: string | null;\n private axiosClient: AxiosInstance;\n\n public socket: Socket | undefined;\n\n constructor(options: ApiClientOptions) {\n this.host = options.host;\n this.apiKey = options.apiKey;\n this.userToken = options.userToken || null;\n\n // Create a retryable axios client, but account for issues where the axios export is not\n // the default in certain bundlers (Webpack).\n //\n // NOTE: This is a temporary fix that exists because of this issue:\n // https://github.com/axios/axios/issues/6591\n const axiosInstance = // @ts-expect-error Fixing the issue described above\n (axios.default ? axios.default : axios) as AxiosStatic;\n\n this.axiosClient = axiosInstance.create({\n baseURL: this.host,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n \"X-Knock-User-Token\": this.userToken,\n },\n });\n\n if (typeof window !== \"undefined\") {\n this.socket = new Socket(`${this.host.replace(\"http\", \"ws\")}/ws/v1`, {\n params: {\n user_token: this.userToken,\n api_key: this.apiKey,\n },\n });\n }\n\n axiosRetry(this.axiosClient, {\n retries: 3,\n retryCondition: this.canRetryRequest,\n retryDelay: axiosRetry.exponentialDelay,\n });\n }\n\n async makeRequest(req: AxiosRequestConfig): Promise<ApiResponse> {\n try {\n const result = await this.axiosClient(req);\n\n return {\n statusCode: result.status < 300 ? \"ok\" : \"error\",\n body: result.data,\n error: undefined,\n status: result.status,\n };\n\n // eslint:disable-next-line\n } catch (e: unknown) {\n console.error(e);\n\n return {\n statusCode: \"error\",\n status: 500,\n body: undefined,\n error: e,\n };\n }\n }\n\n private canRetryRequest(error: AxiosError) {\n // Retry Network Errors.\n if (axiosRetry.isNetworkError(error)) {\n return true;\n }\n\n if (!error.response) {\n // Cannot determine if the request can be retried\n return false;\n }\n\n // Retry Server Errors (5xx).\n if (error.response.status >= 500 && error.response.status <= 599) {\n return true;\n }\n\n // Retry if rate limited.\n if (error.response.status === 429) {\n return true;\n }\n\n return false;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","axiosInstance","axios","Socket","axiosRetry","req","result","e","error"],"mappings":"uVAmBA,MAAMA,CAAU,CAQd,YAAYC,EAA2B,CAP/BC,EAAA,aACAA,EAAA,eACAA,EAAA,kBACAA,EAAA,oBAEDA,EAAA,eAGL,KAAK,KAAOD,EAAQ,KACpB,KAAK,OAASA,EAAQ,OACjB,KAAA,UAAYA,EAAQ,WAAa,KAOhC,MAAAE,EACHC,EAAM,QAAUA,EAAM,QAAUA,EAE9B,KAAA,YAAcD,EAAc,OAAO,CACtC,QAAS,KAAK,KACd,QAAS,CACP,OAAQ,mBACR,eAAgB,mBAChB,cAAe,UAAU,KAAK,MAAM,GACpC,qBAAsB,KAAK,SAC7B,CAAA,CACD,EAEG,OAAO,OAAW,MACf,KAAA,OAAS,IAAIE,EAAA,OAAO,GAAG,KAAK,KAAK,QAAQ,OAAQ,IAAI,CAAC,SAAU,CACnE,OAAQ,CACN,WAAY,KAAK,UACjB,QAAS,KAAK,MAChB,CAAA,CACD,GAGHC,EAAW,KAAK,YAAa,CAC3B,QAAS,EACT,eAAgB,KAAK,gBACrB,WAAYA,EAAW,gBAAA,CACxB,CACH,CAEA,MAAM,YAAYC,EAA+C,CAC3D,GAAA,CACF,MAAMC,EAAS,MAAM,KAAK,YAAYD,CAAG,EAElC,MAAA,CACL,WAAYC,EAAO,OAAS,IAAM,KAAO,QACzC,KAAMA,EAAO,KACb,MAAO,OACP,OAAQA,EAAO,MAAA,QAIVC,EAAY,CACnB,eAAQ,MAAMA,CAAC,EAER,CACL,WAAY,QACZ,OAAQ,IACR,KAAM,OACN,MAAOA,CAAA,CAEX,CACF,CAEQ,gBAAgBC,EAAmB,CAErC,OAAAJ,EAAW,eAAeI,CAAK,EAC1B,GAGJA,EAAM,SAMPA,EAAM,SAAS,QAAU,KAAOA,EAAM,SAAS,QAAU,KAKzDA,EAAM,SAAS,SAAW,IATrB,EAcX,CACF"}
package/dist/esm/api.mjs CHANGED
@@ -1,8 +1,8 @@
1
- var i = Object.defineProperty;
2
- var a = (s, e, t) => e in s ? i(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var r = (s, e, t) => a(s, typeof e != "symbol" ? e + "" : e, t);
4
- import n from "axios";
5
- import o from "axios-retry";
1
+ var a = Object.defineProperty;
2
+ var n = (s, e, t) => e in s ? a(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var r = (s, e, t) => n(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import o from "axios";
5
+ import i from "axios-retry";
6
6
  import { Socket as u } from "phoenix";
7
7
  class y {
8
8
  constructor(e) {
@@ -11,7 +11,12 @@ class y {
11
11
  r(this, "userToken");
12
12
  r(this, "axiosClient");
13
13
  r(this, "socket");
14
- this.host = e.host, this.apiKey = e.apiKey, this.userToken = e.userToken || null, this.axiosClient = n.create({
14
+ this.host = e.host, this.apiKey = e.apiKey, this.userToken = e.userToken || null;
15
+ const t = (
16
+ // @ts-expect-error Fixing the issue described above
17
+ o.default ? o.default : o
18
+ );
19
+ this.axiosClient = t.create({
15
20
  baseURL: this.host,
16
21
  headers: {
17
22
  Accept: "application/json",
@@ -24,10 +29,10 @@ class y {
24
29
  user_token: this.userToken,
25
30
  api_key: this.apiKey
26
31
  }
27
- })), o(this.axiosClient, {
32
+ })), i(this.axiosClient, {
28
33
  retries: 3,
29
34
  retryCondition: this.canRetryRequest,
30
- retryDelay: o.exponentialDelay
35
+ retryDelay: i.exponentialDelay
31
36
  });
32
37
  }
33
38
  async makeRequest(e) {
@@ -49,7 +54,7 @@ class y {
49
54
  }
50
55
  }
51
56
  canRetryRequest(e) {
52
- return o.isNetworkError(e) ? !0 : e.response ? e.response.status >= 500 && e.response.status <= 599 || e.response.status === 429 : !1;
57
+ return i.isNetworkError(e) ? !0 : e.response ? e.response.status >= 500 && e.response.status <= 599 || e.response.status === 429 : !1;
53
58
  }
54
59
  }
55
60
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"api.mjs","sources":["../../src/api.ts"],"sourcesContent":["import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from \"axios\";\nimport axiosRetry from \"axios-retry\";\nimport { Socket } from \"phoenix\";\n\ntype ApiClientOptions = {\n host: string;\n apiKey: string;\n userToken: string | undefined;\n};\n\nexport interface ApiResponse {\n // eslint-disable-next-line\n error?: any;\n // eslint-disable-next-line\n body?: any;\n statusCode: \"ok\" | \"error\";\n status: number;\n}\n\nclass ApiClient {\n private host: string;\n private apiKey: string;\n private userToken: string | null;\n private axiosClient: AxiosInstance;\n\n public socket: Socket | undefined;\n\n constructor(options: ApiClientOptions) {\n this.host = options.host;\n this.apiKey = options.apiKey;\n this.userToken = options.userToken || null;\n\n // Create a retryable axios client\n this.axiosClient = axios.create({\n baseURL: this.host,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n \"X-Knock-User-Token\": this.userToken,\n },\n });\n\n if (typeof window !== \"undefined\") {\n this.socket = new Socket(`${this.host.replace(\"http\", \"ws\")}/ws/v1`, {\n params: {\n user_token: this.userToken,\n api_key: this.apiKey,\n },\n });\n }\n\n axiosRetry(this.axiosClient, {\n retries: 3,\n retryCondition: this.canRetryRequest,\n retryDelay: axiosRetry.exponentialDelay,\n });\n }\n\n async makeRequest(req: AxiosRequestConfig): Promise<ApiResponse> {\n try {\n const result = await this.axiosClient(req);\n\n return {\n statusCode: result.status < 300 ? \"ok\" : \"error\",\n body: result.data,\n error: undefined,\n status: result.status,\n };\n\n // eslint:disable-next-line\n } catch (e: unknown) {\n console.error(e);\n\n return {\n statusCode: \"error\",\n status: 500,\n body: undefined,\n error: e,\n };\n }\n }\n\n private canRetryRequest(error: AxiosError) {\n // Retry Network Errors.\n if (axiosRetry.isNetworkError(error)) {\n return true;\n }\n\n if (!error.response) {\n // Cannot determine if the request can be retried\n return false;\n }\n\n // Retry Server Errors (5xx).\n if (error.response.status >= 500 && error.response.status <= 599) {\n return true;\n }\n\n // Retry if rate limited.\n if (error.response.status === 429) {\n return true;\n }\n\n return false;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","axios","Socket","axiosRetry","req","result","e","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,EAAM,SAAS,UAAU,OAAOA,EAAM,SAAS,UAAU,OAKzDA,EAAM,SAAS,WAAW,MATrB;AAAA,EAcX;AACF;"}
1
+ {"version":3,"file":"api.mjs","sources":["../../src/api.ts"],"sourcesContent":["import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from \"axios\";\nimport axiosRetry from \"axios-retry\";\nimport { Socket } from \"phoenix\";\n\ntype ApiClientOptions = {\n host: string;\n apiKey: string;\n userToken: string | undefined;\n};\n\nexport interface ApiResponse {\n // eslint-disable-next-line\n error?: any;\n // eslint-disable-next-line\n body?: any;\n statusCode: \"ok\" | \"error\";\n status: number;\n}\n\nclass ApiClient {\n private host: string;\n private apiKey: string;\n private userToken: string | null;\n private axiosClient: AxiosInstance;\n\n public socket: Socket | undefined;\n\n constructor(options: ApiClientOptions) {\n this.host = options.host;\n this.apiKey = options.apiKey;\n this.userToken = options.userToken || null;\n\n // Create a retryable axios client, but account for issues where the axios export is not\n // the default in certain bundlers (Webpack).\n //\n // NOTE: This is a temporary fix that exists because of this issue:\n // https://github.com/axios/axios/issues/6591\n const axiosInstance = // @ts-expect-error Fixing the issue described above\n (axios.default ? axios.default : axios) as AxiosStatic;\n\n this.axiosClient = axiosInstance.create({\n baseURL: this.host,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n \"X-Knock-User-Token\": this.userToken,\n },\n });\n\n if (typeof window !== \"undefined\") {\n this.socket = new Socket(`${this.host.replace(\"http\", \"ws\")}/ws/v1`, {\n params: {\n user_token: this.userToken,\n api_key: this.apiKey,\n },\n });\n }\n\n axiosRetry(this.axiosClient, {\n retries: 3,\n retryCondition: this.canRetryRequest,\n retryDelay: axiosRetry.exponentialDelay,\n });\n }\n\n async makeRequest(req: AxiosRequestConfig): Promise<ApiResponse> {\n try {\n const result = await this.axiosClient(req);\n\n return {\n statusCode: result.status < 300 ? \"ok\" : \"error\",\n body: result.data,\n error: undefined,\n status: result.status,\n };\n\n // eslint:disable-next-line\n } catch (e: unknown) {\n console.error(e);\n\n return {\n statusCode: \"error\",\n status: 500,\n body: undefined,\n error: e,\n };\n }\n }\n\n private canRetryRequest(error: AxiosError) {\n // Retry Network Errors.\n if (axiosRetry.isNetworkError(error)) {\n return true;\n }\n\n if (!error.response) {\n // Cannot determine if the request can be retried\n return false;\n }\n\n // Retry Server Errors (5xx).\n if (error.response.status >= 500 && error.response.status <= 599) {\n return true;\n }\n\n // Retry if rate limited.\n if (error.response.status === 429) {\n return true;\n }\n\n return false;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","axiosInstance","axios","Socket","axiosRetry","req","result","e","error"],"mappings":";;;;;;AAmBA,MAAMA,EAAU;AAAA,EAQd,YAAYC,GAA2B;AAP/B,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAED,IAAAA,EAAA;AAGL,SAAK,OAAOD,EAAQ,MACpB,KAAK,SAASA,EAAQ,QACjB,KAAA,YAAYA,EAAQ,aAAa;AAOhC,UAAAE;AAAA;AAAA,MACHC,EAAM,UAAUA,EAAM,UAAUA;AAAA;AAE9B,SAAA,cAAcD,EAAc,OAAO;AAAA,MACtC,SAAS,KAAK;AAAA,MACd,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,gBAAgB;AAAA,QAChB,eAAe,UAAU,KAAK,MAAM;AAAA,QACpC,sBAAsB,KAAK;AAAA,MAC7B;AAAA,IAAA,CACD,GAEG,OAAO,SAAW,QACf,KAAA,SAAS,IAAIE,EAAO,GAAG,KAAK,KAAK,QAAQ,QAAQ,IAAI,CAAC,UAAU;AAAA,MACnE,QAAQ;AAAA,QACN,YAAY,KAAK;AAAA,QACjB,SAAS,KAAK;AAAA,MAChB;AAAA,IAAA,CACD,IAGHC,EAAW,KAAK,aAAa;AAAA,MAC3B,SAAS;AAAA,MACT,gBAAgB,KAAK;AAAA,MACrB,YAAYA,EAAW;AAAA,IAAA,CACxB;A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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"}
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;IAuC/B,WAAW,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBhE,OAAO,CAAC,eAAe;CAuBxB;AAED,eAAe,SAAS,CAAC"}
@@ -1,11 +1,14 @@
1
- import { ChannelType } from '@knocklabs/types';
1
+ import { ChannelType, Condition } from '@knocklabs/types';
2
2
 
3
+ export type ConditionalPreferenceSettings = {
4
+ conditions: Condition[];
5
+ };
3
6
  export type ChannelTypePreferences = {
4
- [K in ChannelType]?: boolean;
7
+ [_K in ChannelType]?: boolean | ConditionalPreferenceSettings;
5
8
  };
6
9
  export type WorkflowPreferenceSetting = boolean | {
7
10
  channel_types: ChannelTypePreferences;
8
- };
11
+ } | ConditionalPreferenceSettings;
9
12
  export type WorkflowPreferences = Partial<Record<string, WorkflowPreferenceSetting>>;
10
13
  export interface SetPreferencesProperties {
11
14
  workflows: WorkflowPreferences;
@@ -14,9 +17,9 @@ export interface SetPreferencesProperties {
14
17
  }
15
18
  export interface PreferenceSet {
16
19
  id: string;
17
- categories: WorkflowPreferences;
18
- workflows: WorkflowPreferences;
19
- channel_types: ChannelTypePreferences;
20
+ categories: WorkflowPreferences | null;
21
+ workflows: WorkflowPreferences | null;
22
+ channel_types: ChannelTypePreferences | null;
20
23
  }
21
24
  export interface PreferenceOptions {
22
25
  preferenceSet?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/clients/preferences/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,MAAM,sBAAsB,GAAG;KAClC,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,OAAO;CAC7B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,OAAO,GACP;IAAE,aAAa,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAC1C,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,UAAU,EAAE,mBAAmB,CAAC;IAChC,aAAa,EAAE,sBAAsB,CAAC;CACvC;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,mBAAmB,CAAC;IAChC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,aAAa,EAAE,sBAAsB,CAAC;CACvC;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/clients/preferences/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,MAAM,6BAA6B,GAAG;IAC1C,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;KAClC,EAAE,IAAI,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,6BAA6B;CAC9D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,OAAO,GACP;IAAE,aAAa,EAAE,sBAAsB,CAAA;CAAE,GACzC,6BAA6B,CAAC;AAElC,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAC1C,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,UAAU,EAAE,mBAAmB,CAAC;IAChC,aAAa,EAAE,sBAAsB,CAAC;CACvC;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACvC,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,aAAa,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/client",
3
- "version": "0.10.13",
3
+ "version": "0.10.15",
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,33 +47,33 @@
47
47
  "prepublishOnly": "npm run build"
48
48
  },
49
49
  "devDependencies": {
50
- "@babel/cli": "^7.25.6",
51
- "@babel/core": "^7.20.0",
50
+ "@babel/cli": "^7.25.7",
51
+ "@babel/core": "^7.26.0",
52
52
  "@babel/plugin-proposal-class-properties": "^7.16.7",
53
53
  "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
54
- "@babel/plugin-transform-runtime": "^7.16.7",
54
+ "@babel/plugin-transform-runtime": "^7.25.4",
55
55
  "@babel/preset-env": "^7.16.7",
56
56
  "@babel/preset-typescript": "^7.16.7",
57
57
  "@types/jsonwebtoken": "^9.0.5",
58
58
  "@typescript-eslint/eslint-plugin": "^6.20.0",
59
- "@typescript-eslint/parser": "^6.20.0",
59
+ "@typescript-eslint/parser": "^8.8.1",
60
60
  "cross-env": "^7.0.3",
61
61
  "crypto": "^1.0.1",
62
62
  "eslint": "^8.56.0",
63
63
  "jsonwebtoken": "^9.0.2",
64
64
  "prettier": "^3.1.0",
65
65
  "rimraf": "^6.0.1",
66
- "rollup": "^4.21.0",
67
- "typescript": "^5.5.4",
66
+ "rollup": "^4.24.2",
67
+ "typescript": "^5.6.3",
68
68
  "vite": "^5.0.0",
69
- "vitest": "^2.0.5"
69
+ "vitest": "^2.1.4"
70
70
  },
71
71
  "dependencies": {
72
72
  "@babel/runtime": "^7.25.6",
73
- "@knocklabs/types": "^0.1.4",
73
+ "@knocklabs/types": "^0.1.5",
74
74
  "@types/phoenix": "^1.5.4",
75
75
  "axios": "^1.7.4",
76
- "axios-retry": "^3.1.9",
76
+ "axios-retry": "^4.5.0",
77
77
  "eventemitter2": "^6.4.5",
78
78
  "jwt-decode": "^4.0.0",
79
79
  "phoenix": "1.6.16",
package/src/api.ts CHANGED
@@ -30,8 +30,15 @@ class ApiClient {
30
30
  this.apiKey = options.apiKey;
31
31
  this.userToken = options.userToken || null;
32
32
 
33
- // Create a retryable axios client
34
- this.axiosClient = axios.create({
33
+ // Create a retryable axios client, but account for issues where the axios export is not
34
+ // the default in certain bundlers (Webpack).
35
+ //
36
+ // NOTE: This is a temporary fix that exists because of this issue:
37
+ // https://github.com/axios/axios/issues/6591
38
+ const axiosInstance = // @ts-expect-error Fixing the issue described above
39
+ (axios.default ? axios.default : axios) as AxiosStatic;
40
+
41
+ this.axiosClient = axiosInstance.create({
35
42
  baseURL: this.host,
36
43
  headers: {
37
44
  Accept: "application/json",
@@ -1,12 +1,17 @@
1
- import { ChannelType } from "@knocklabs/types";
1
+ import { ChannelType, Condition } from "@knocklabs/types";
2
+
3
+ export type ConditionalPreferenceSettings = {
4
+ conditions: Condition[];
5
+ };
2
6
 
3
7
  export type ChannelTypePreferences = {
4
- [K in ChannelType]?: boolean;
8
+ [_K in ChannelType]?: boolean | ConditionalPreferenceSettings;
5
9
  };
6
10
 
7
11
  export type WorkflowPreferenceSetting =
8
12
  | boolean
9
- | { channel_types: ChannelTypePreferences };
13
+ | { channel_types: ChannelTypePreferences }
14
+ | ConditionalPreferenceSettings;
10
15
 
11
16
  export type WorkflowPreferences = Partial<
12
17
  Record<string, WorkflowPreferenceSetting>
@@ -20,9 +25,9 @@ export interface SetPreferencesProperties {
20
25
 
21
26
  export interface PreferenceSet {
22
27
  id: string;
23
- categories: WorkflowPreferences;
24
- workflows: WorkflowPreferences;
25
- channel_types: ChannelTypePreferences;
28
+ categories: WorkflowPreferences | null;
29
+ workflows: WorkflowPreferences | null;
30
+ channel_types: ChannelTypePreferences | null;
26
31
  }
27
32
 
28
33
  export interface PreferenceOptions {