@knocklabs/client 0.16.0 → 0.16.1

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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.16.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 35b5445: chore(deps): bump axios from 1.10.0 to 1.11.0
8
+ - 5d758d7: fix: fixes refused to set unsafe header "User-Agent"
9
+ - d2fd092: chore(deps-dev): bump @types/jsonwebtoken from 9.0.9 to 9.0.10
10
+
3
11
  ## 0.16.0
4
12
 
5
13
  ### Minor Changes
package/dist/cjs/api.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var n=(t,e,s)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var r=(t,e,s)=>n(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("axios"),l=require("axios-retry"),c=require("phoenix"),i=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},h=i(u),o=i(l);class p{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=h.default.create({baseURL:this.host,headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`,"X-Knock-User-Token":this.userToken,"User-Agent":this.getUserAgent()}}),typeof window<"u"&&(this.socket=new c.Socket(`${this.host.replace("http","ws")}/ws/v1`,{params:{user_token:this.userToken,api_key:this.apiKey}})),o.default(this.axiosClient,{retries:3,retryCondition:this.canRetryRequest,retryDelay:o.default.exponentialDelay})}async makeRequest(e){try{const s=await this.axiosClient(e);return{statusCode:s.status<300?"ok":"error",body:s.data,error:void 0,status:s.status}}catch(s){return console.error(s),{statusCode:"error",status:500,body:void 0,error:s}}}canRetryRequest(e){return o.default.isNetworkError(e)?!0:e.response?e.response.status>=500&&e.response.status<=599||e.response.status===429:!1}getUserAgent(){return"Knock/ClientJS 0.16.0"}}exports.default=p;
1
+ "use strict";var a=Object.defineProperty;var n=(t,e,s)=>e in t?a(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var r=(t,e,s)=>n(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("axios"),l=require("axios-retry"),c=require("phoenix"),i=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},d=i(u),o=i(l);class h{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=d.default.create({baseURL:this.host,headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`,"X-Knock-User-Token":this.userToken,"X-Knock-Client":this.getKnockClientHeader()}}),typeof window<"u"&&(this.socket=new c.Socket(`${this.host.replace("http","ws")}/ws/v1`,{params:{user_token:this.userToken,api_key:this.apiKey}})),o.default(this.axiosClient,{retries:3,retryCondition:this.canRetryRequest,retryDelay:o.default.exponentialDelay})}async makeRequest(e){try{const s=await this.axiosClient(e);return{statusCode:s.status<300?"ok":"error",body:s.data,error:void 0,status:s.status}}catch(s){return console.error(s),{statusCode:"error",status:500,body:void 0,error:s}}}canRetryRequest(e){return o.default.isNetworkError(e)?!0:e.response?e.response.status>=500&&e.response.status<=599||e.response.status===429:!1}getKnockClientHeader(){return"Knock/ClientJS 0.16.1"}}exports.default=h;
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 \"User-Agent\": this.getUserAgent(),\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 private getUserAgent() {\n // Note: we're following format used in our Stainless SDKs:\n // https://github.com/knocklabs/knock-node/blob/main/src/client.ts#L335\n // If we add the env var to turbo.json, it caches it so the version\n // never actually updates.\n // eslint-disable-next-line turbo/no-undeclared-env-vars\n return `Knock/ClientJS ${process.env.CLIENT_PACKAGE_VERSION}`;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","axios","Socket","axiosRetry","req","result","e","error"],"mappings":"6ZAmBA,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,UAAM,OAAO,CAC9B,QAAS,KAAK,KACd,QAAS,CACP,OAAQ,mBACR,eAAgB,mBAChB,cAAe,UAAU,KAAK,MAAM,GACpC,qBAAsB,KAAK,UAC3B,aAAc,KAAK,aAAa,CAAA,CAClC,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,MAAA,CAChB,CACD,GAGHC,EAAA,QAAW,KAAK,YAAa,CAC3B,QAAS,EACT,eAAgB,KAAK,gBACrB,WAAYA,EAAAA,QAAW,gBAAA,CACxB,CAAA,CAGH,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,MACjB,QAGOC,EAAY,CACnB,eAAQ,MAAMA,CAAC,EAER,CACL,WAAY,QACZ,OAAQ,IACR,KAAM,OACN,MAAOA,CACT,CAAA,CACF,CAGM,gBAAgBC,EAAmB,CAErC,OAAAJ,EAAA,QAAW,eAAeI,CAAK,EAC1B,GAGJA,EAAM,SAMPA,EAAM,SAAS,QAAU,KAAOA,EAAM,SAAS,QAAU,KAKzDA,EAAM,SAAS,SAAW,IATrB,EAaF,CAGD,cAAe,CAMd,MAAA,uBAAoD,CAE/D"}
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 \"X-Knock-Client\": this.getKnockClientHeader(),\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 private getKnockClientHeader() {\n // Note: we're following format used in our Stainless SDKs:\n // https://github.com/knocklabs/knock-node/blob/main/src/client.ts#L335\n // If we add the env var to turbo.json, it caches it so the version\n // never actually updates.\n // eslint-disable-next-line turbo/no-undeclared-env-vars\n return `Knock/ClientJS ${process.env.CLIENT_PACKAGE_VERSION}`;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","axios","Socket","axiosRetry","req","result","e","error"],"mappings":"6ZAmBA,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,UAAM,OAAO,CAC9B,QAAS,KAAK,KACd,QAAS,CACP,OAAQ,mBACR,eAAgB,mBAChB,cAAe,UAAU,KAAK,MAAM,GACpC,qBAAsB,KAAK,UAC3B,iBAAkB,KAAK,qBAAqB,CAAA,CAC9C,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,MAAA,CAChB,CACD,GAGHC,EAAA,QAAW,KAAK,YAAa,CAC3B,QAAS,EACT,eAAgB,KAAK,gBACrB,WAAYA,EAAAA,QAAW,gBAAA,CACxB,CAAA,CAGH,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,MACjB,QAGOC,EAAY,CACnB,eAAQ,MAAMA,CAAC,EAER,CACL,WAAY,QACZ,OAAQ,IACR,KAAM,OACN,MAAOA,CACT,CAAA,CACF,CAGM,gBAAgBC,EAAmB,CAErC,OAAAJ,EAAA,QAAW,eAAeI,CAAK,EAC1B,GAGJA,EAAM,SAMPA,EAAM,SAAS,QAAU,KAAOA,EAAM,SAAS,QAAU,KAKzDA,EAAM,SAAS,SAAW,IATrB,EAaF,CAGD,sBAAuB,CAMtB,MAAA,uBAAoD,CAE/D"}
package/dist/esm/api.mjs CHANGED
@@ -1,24 +1,24 @@
1
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";
2
+ var n = (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) => n(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import a from "axios";
5
5
  import o from "axios-retry";
6
6
  import { Socket as u } from "phoenix";
7
- class y {
7
+ class k {
8
8
  constructor(e) {
9
9
  r(this, "host");
10
10
  r(this, "apiKey");
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, this.axiosClient = a.create({
15
15
  baseURL: this.host,
16
16
  headers: {
17
17
  Accept: "application/json",
18
18
  "Content-Type": "application/json",
19
19
  Authorization: `Bearer ${this.apiKey}`,
20
20
  "X-Knock-User-Token": this.userToken,
21
- "User-Agent": this.getUserAgent()
21
+ "X-Knock-Client": this.getKnockClientHeader()
22
22
  }
23
23
  }), typeof window < "u" && (this.socket = new u(`${this.host.replace("http", "ws")}/ws/v1`, {
24
24
  params: {
@@ -52,11 +52,11 @@ class y {
52
52
  canRetryRequest(e) {
53
53
  return o.isNetworkError(e) ? !0 : e.response ? e.response.status >= 500 && e.response.status <= 599 || e.response.status === 429 : !1;
54
54
  }
55
- getUserAgent() {
56
- return "Knock/ClientJS 0.16.0";
55
+ getKnockClientHeader() {
56
+ return "Knock/ClientJS 0.16.1";
57
57
  }
58
58
  }
59
59
  export {
60
- y as default
60
+ k as default
61
61
  };
62
62
  //# sourceMappingURL=api.mjs.map
@@ -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 \"User-Agent\": this.getUserAgent(),\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 private getUserAgent() {\n // Note: we're following format used in our Stainless SDKs:\n // https://github.com/knocklabs/knock-node/blob/main/src/client.ts#L335\n // If we add the env var to turbo.json, it caches it so the version\n // never actually updates.\n // eslint-disable-next-line turbo/no-undeclared-env-vars\n return `Knock/ClientJS ${process.env.CLIENT_PACKAGE_VERSION}`;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","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,MAGjC,KAAA,cAAcE,EAAM,OAAO;AAAA,MAC9B,SAAS,KAAK;AAAA,MACd,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,gBAAgB;AAAA,QAChB,eAAe,UAAU,KAAK,MAAM;AAAA,QACpC,sBAAsB,KAAK;AAAA,QAC3B,cAAc,KAAK,aAAa;AAAA,MAAA;AAAA,IAClC,CACD,GAEG,OAAO,SAAW,QACf,KAAA,SAAS,IAAIC,EAAO,GAAG,KAAK,KAAK,QAAQ,QAAQ,IAAI,CAAC,UAAU;AAAA,MACnE,QAAQ;AAAA,QACN,YAAY,KAAK;AAAA,QACjB,SAAS,KAAK;AAAA,MAAA;AAAA,IAChB,CACD,IAGHC,EAAW,KAAK,aAAa;AAAA,MAC3B,SAAS;AAAA,MACT,gBAAgB,KAAK;AAAA,MACrB,YAAYA,EAAW;AAAA,IAAA,CACxB;AAAA,EAAA;AAAA,EAGH,MAAM,YAAYC,GAA+C;AAC3D,QAAA;AACF,YAAMC,IAAS,MAAM,KAAK,YAAYD,CAAG;AAElC,aAAA;AAAA,QACL,YAAYC,EAAO,SAAS,MAAM,OAAO;AAAA,QACzC,MAAMA,EAAO;AAAA,QACb,OAAO;AAAA,QACP,QAAQA,EAAO;AAAA,MACjB;AAAA,aAGOC,GAAY;AACnB,qBAAQ,MAAMA,CAAC,GAER;AAAA,QACL,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAOA;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAAA,EAGM,gBAAgBC,GAAmB;AAErC,WAAAJ,EAAW,eAAeI,CAAK,IAC1B,KAGJA,EAAM,WAMPA,EAAM,SAAS,UAAU,OAAOA,EAAM,SAAS,UAAU,OAKzDA,EAAM,SAAS,WAAW,MATrB;AAAA,EAaF;AAAA,EAGD,eAAe;AAMd,WAAA;AAAA,EAAoD;AAE/D;"}
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 \"X-Knock-Client\": this.getKnockClientHeader(),\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 private getKnockClientHeader() {\n // Note: we're following format used in our Stainless SDKs:\n // https://github.com/knocklabs/knock-node/blob/main/src/client.ts#L335\n // If we add the env var to turbo.json, it caches it so the version\n // never actually updates.\n // eslint-disable-next-line turbo/no-undeclared-env-vars\n return `Knock/ClientJS ${process.env.CLIENT_PACKAGE_VERSION}`;\n }\n}\n\nexport default ApiClient;\n"],"names":["ApiClient","options","__publicField","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,MAGjC,KAAA,cAAcE,EAAM,OAAO;AAAA,MAC9B,SAAS,KAAK;AAAA,MACd,SAAS;AAAA,QACP,QAAQ;AAAA,QACR,gBAAgB;AAAA,QAChB,eAAe,UAAU,KAAK,MAAM;AAAA,QACpC,sBAAsB,KAAK;AAAA,QAC3B,kBAAkB,KAAK,qBAAqB;AAAA,MAAA;AAAA,IAC9C,CACD,GAEG,OAAO,SAAW,QACf,KAAA,SAAS,IAAIC,EAAO,GAAG,KAAK,KAAK,QAAQ,QAAQ,IAAI,CAAC,UAAU;AAAA,MACnE,QAAQ;AAAA,QACN,YAAY,KAAK;AAAA,QACjB,SAAS,KAAK;AAAA,MAAA;AAAA,IAChB,CACD,IAGHC,EAAW,KAAK,aAAa;AAAA,MAC3B,SAAS;AAAA,MACT,gBAAgB,KAAK;AAAA,MACrB,YAAYA,EAAW;AAAA,IAAA,CACxB;AAAA,EAAA;AAAA,EAGH,MAAM,YAAYC,GAA+C;AAC3D,QAAA;AACF,YAAMC,IAAS,MAAM,KAAK,YAAYD,CAAG;AAElC,aAAA;AAAA,QACL,YAAYC,EAAO,SAAS,MAAM,OAAO;AAAA,QACzC,MAAMA,EAAO;AAAA,QACb,OAAO;AAAA,QACP,QAAQA,EAAO;AAAA,MACjB;AAAA,aAGOC,GAAY;AACnB,qBAAQ,MAAMA,CAAC,GAER;AAAA,QACL,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,OAAOA;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAAA,EAGM,gBAAgBC,GAAmB;AAErC,WAAAJ,EAAW,eAAeI,CAAK,IAC1B,KAGJA,EAAM,WAMPA,EAAM,SAAS,UAAU,OAAOA,EAAM,SAAS,UAAU,OAKzDA,EAAM,SAAS,WAAW,MATrB;AAAA,EAaF;AAAA,EAGD,uBAAuB;AAMtB,WAAA;AAAA,EAAoD;AAE/D;"}
@@ -20,7 +20,7 @@ declare class ApiClient {
20
20
  constructor(options: ApiClientOptions);
21
21
  makeRequest(req: AxiosRequestConfig): Promise<ApiResponse>;
22
22
  private canRetryRequest;
23
- private getUserAgent;
23
+ private getKnockClientHeader;
24
24
  }
25
25
  export default ApiClient;
26
26
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
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;IAiC/B,WAAW,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBhE,OAAO,CAAC,eAAe;IAwBvB,OAAO,CAAC,YAAY;CAQrB;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;IAiC/B,WAAW,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBhE,OAAO,CAAC,eAAe;IAwBvB,OAAO,CAAC,oBAAoB;CAQ7B;AAED,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knocklabs/client",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
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",
@@ -53,7 +53,7 @@
53
53
  "@babel/preset-env": "^7.27.1",
54
54
  "@babel/preset-typescript": "^7.27.0",
55
55
  "@codecov/vite-plugin": "^1.9.1",
56
- "@types/jsonwebtoken": "^9.0.9",
56
+ "@types/jsonwebtoken": "^9.0.10",
57
57
  "@typescript-eslint/eslint-plugin": "^8.32.0",
58
58
  "@typescript-eslint/parser": "^8.32.1",
59
59
  "cross-env": "^7.0.3",
@@ -72,7 +72,7 @@
72
72
  "@knocklabs/types": "^0.1.5",
73
73
  "@tanstack/store": "^0.7.1",
74
74
  "@types/phoenix": "^1.6.6",
75
- "axios": "^1.10.0",
75
+ "axios": "^1.11.0",
76
76
  "axios-retry": "^4.5.0",
77
77
  "eventemitter2": "^6.4.5",
78
78
  "jwt-decode": "^4.0.0",
package/src/api.ts CHANGED
@@ -38,7 +38,7 @@ class ApiClient {
38
38
  "Content-Type": "application/json",
39
39
  Authorization: `Bearer ${this.apiKey}`,
40
40
  "X-Knock-User-Token": this.userToken,
41
- "User-Agent": this.getUserAgent(),
41
+ "X-Knock-Client": this.getKnockClientHeader(),
42
42
  },
43
43
  });
44
44
 
@@ -106,7 +106,7 @@ class ApiClient {
106
106
  return false;
107
107
  }
108
108
 
109
- private getUserAgent() {
109
+ private getKnockClientHeader() {
110
110
  // Note: we're following format used in our Stainless SDKs:
111
111
  // https://github.com/knocklabs/knock-node/blob/main/src/client.ts#L335
112
112
  // If we add the env var to turbo.json, it caches it so the version