@nhost/nhost-js 2.0.3 → 2.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,+BAA+B,EAChC,MAAM,SAAS,CAAA;AAChB;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,4BAA4B,wBAWzE;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAEhB,MAAM,EAAE,+BAA+B;IAQ7C,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,GAAG,EAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,uBAAuB,GAC/B,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC;IAuDxC;;;;;;;;;OASG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAanC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,+BAA+B,EAChC,MAAM,SAAS,CAAA;AAChB;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,4BAA4B,wBAWzE;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAEhB,MAAM,EAAE,+BAA+B;IAQ7C,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,GAAG,EAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,uBAAuB,GAC/B,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC;IA8DxC;;;;;;;;;OASG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAanC"}
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@nhost/hasura-auth-js"),g=require("@nhost/hasura-storage-js"),U=require("cross-fetch"),A=require("@nhost/graphql-js"),S=/^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/;function l(t,e){const{backendUrl:s,subdomain:o,region:c}=t;if(s)return`${s}/v1/${e}`;if(!o)throw new Error("Either `backendUrl` or `subdomain` must be set.");const r=o.match(S);if(r!=null&&r.groups){const{protocol:n="http",host:h,port:d=1337}=r.groups,i=q(e);return i||`${n}://${h}:${d}/v1/${e}`}if(!c)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${o}.${e}.${c}.nhost.run/v1`}function y(){return typeof window<"u"}function m(){return typeof process<"u"&&process.env}function q(t){return y()||!m()?null:process.env[`NHOST_${t.toUpperCase()}_URL`]}function b(t){const e="subdomain"in t||"backendUrl"in t?l(t,"auth"):t.authUrl;if(!e)throw new Error("Please provide `subdomain` or `authUrl`.");return new f.HasuraAuthClient({url:e,...t})}function w(t){const e="subdomain"in t||"backendUrl"in t?l(t,"functions"):t.functionsUrl;if(!e)throw new Error("Please provide `subdomain` or `functionsUrl`.");return new p({url:e,...t})}class p{constructor(e){const{url:s,adminSecret:o}=e;this.url=s,this.accessToken=null,this.adminSecret=o}async call(e,s,o){const c={"Content-Type":"application/json",...this.generateAccessTokenHeaders(),...o==null?void 0:o.headers};try{const r=await U(e,{body:JSON.stringify(s),headers:c,method:"POST"});if(!r.ok)throw new Error(r.statusText);let n;try{n=await r.json()}catch{n=await r.text()}return{res:{data:n,status:r.status,statusText:r.statusText},error:null}}catch(r){const n=r;return{res:null,error:{message:n.message,status:n.name==="AbortError"?0:500,error:n.name==="AbortError"?"abort-error":"unknown"}}}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}function k(t){const e="subdomain"in t||"backendUrl"in t?l(t,"graphql"):t.graphqlUrl;if(!e)throw new Error("Please provide `subdomain` or `graphqlUrl`.");return new A.NhostGraphqlClient({url:e,...t})}function T(t){const e="subdomain"in t||"backendUrl"in t?l(t,"storage"):t.storageUrl;if(!e)throw new Error("Please provide `subdomain` or `storageUrl`.");return new g.HasuraStorageClient({url:e,...t})}const v=t=>new C(t);class C{constructor({refreshIntervalTime:e,clientStorage:s,clientStorageType:o,autoRefreshToken:c,autoSignIn:r,adminSecret:n,devTools:h,start:d=!0,...i}){this.auth=b({refreshIntervalTime:e,clientStorage:s,clientStorageType:o,autoRefreshToken:c,autoSignIn:r,start:d,...i}),this.storage=T({adminSecret:n,...i}),this.functions=w({adminSecret:n,...i}),this.graphql=k({adminSecret:n,...i}),this.auth.onAuthStateChanged((u,a)=>{u==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(u=>{const a=u==null?void 0:u.accessToken;this.storage.setAccessToken(a),this.functions.setAccessToken(a),this.graphql.setAccessToken(a)}),this._adminSecret=n,this.devTools=h}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}exports.NhostClient=C;exports.NhostFunctionsClient=p;exports.createAuthClient=b;exports.createFunctionsClient=w;exports.createGraphqlClient=k;exports.createNhostClient=v;exports.createStorageClient=T;for(const t in f)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>f[t]});for(const t in g)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>g[t]});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@nhost/hasura-auth-js"),g=require("@nhost/hasura-storage-js"),C=require("cross-fetch"),A=require("@nhost/graphql-js"),S=/^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/;function d(t,e){const{backendUrl:s,subdomain:n,region:a}=t;if(s)return`${s}/v1/${e}`;if(!n)throw new Error("Either `backendUrl` or `subdomain` must be set.");const i=n.match(S);if(i!=null&&i.groups){const{protocol:c="http",host:r,port:o=1337}=i.groups,u=q(e);return u||`${c}://${r}:${o}/v1/${e}`}if(!a)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${n}.${e}.${a}.nhost.run/v1`}function y(){return typeof window<"u"}function m(){return typeof process<"u"&&process.env}function q(t){return y()||!m()?null:process.env[`NHOST_${t.toUpperCase()}_URL`]}function b(t){const e="subdomain"in t||"backendUrl"in t?d(t,"auth"):t.authUrl;if(!e)throw new Error("Please provide `subdomain` or `authUrl`.");return new f.HasuraAuthClient({url:e,...t})}function p(t){const e="subdomain"in t||"backendUrl"in t?d(t,"functions"):t.functionsUrl;if(!e)throw new Error("Please provide `subdomain` or `functionsUrl`.");return new w({url:e,...t})}class w{constructor(e){const{url:s,adminSecret:n}=e;this.url=s,this.accessToken=null,this.adminSecret=n}async call(e,s,n){const a={"Content-Type":"application/json",...this.generateAccessTokenHeaders(),...n==null?void 0:n.headers},i=this.url,c=e.startsWith("/")?e:`/${e}`;try{const r=await C(`${i}/${c}`,{body:JSON.stringify(s),headers:a,method:"POST"});if(!r.ok)throw new Error(r.statusText);let o;return r.headers.get("content-type")==="application/json"?o=await r.json():o=await r.text(),{res:{data:o,status:r.status,statusText:r.statusText},error:null}}catch(r){const o=r;return{res:null,error:{message:o.message,status:o.name==="AbortError"?0:500,error:o.name==="AbortError"?"abort-error":"unknown"}}}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}function k(t){const e="subdomain"in t||"backendUrl"in t?d(t,"graphql"):t.graphqlUrl;if(!e)throw new Error("Please provide `subdomain` or `graphqlUrl`.");return new A.NhostGraphqlClient({url:e,...t})}function T(t){const e="subdomain"in t||"backendUrl"in t?d(t,"storage"):t.storageUrl;if(!e)throw new Error("Please provide `subdomain` or `storageUrl`.");return new g.HasuraStorageClient({url:e,...t})}const v=t=>new U(t);class U{constructor({refreshIntervalTime:e,clientStorage:s,clientStorageType:n,autoRefreshToken:a,autoSignIn:i,adminSecret:c,devTools:r,start:o=!0,...u}){this.auth=b({refreshIntervalTime:e,clientStorage:s,clientStorageType:n,autoRefreshToken:a,autoSignIn:i,start:o,...u}),this.storage=T({adminSecret:c,...u}),this.functions=p({adminSecret:c,...u}),this.graphql=k({adminSecret:c,...u}),this.auth.onAuthStateChanged((l,h)=>{l==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(l=>{const h=l==null?void 0:l.accessToken;this.storage.setAccessToken(h),this.functions.setAccessToken(h),this.graphql.setAccessToken(h)}),this._adminSecret=c,this.devTools=r}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}exports.NhostClient=U;exports.NhostFunctionsClient=w;exports.createAuthClient=b;exports.createFunctionsClient=p;exports.createGraphqlClient=k;exports.createNhostClient=v;exports.createStorageClient=T;for(const t in f)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>f[t]});for(const t in g)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>g[t]});
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/utils/helpers.ts","../src/clients/auth.ts","../src/clients/functions/index.ts","../src/clients/graphql.ts","../src/clients/storage.ts","../src/clients/nhost.ts"],"sourcesContent":["import { NhostClientConstructorParams } from './types'\n\n// a port can be a number or a placeholder string with leading and trailing double underscores, f.e. \"8080\" or \"__PLACEHOLDER_NAME__\"\nconst LOCALHOST_REGEX = /^((?<protocol>http[s]?):\\/\\/)?(?<host>localhost)(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n): string {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n if (!subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol = 'http', host, port = 1337 } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n return `${protocol}://${host}:${port}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n\n/**\n *\n * @returns whether the code is running in a browser\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\n/**\n *\n * @returns whether the code is running in a Node.js environment\n */\nfunction environmentIsAvailable() {\n return typeof process !== 'undefined' && process.env\n}\n\n/**\n *\n * @param service auth | storage | graphql | functions\n * @returns the service's url if the corresponding env var is set\n * NHOST_${service}_URL\n */\nfunction getValueFromEnv(service: string) {\n if (isBrowser() || !environmentIsAvailable()) {\n return null\n }\n\n return process.env[`NHOST_${service.toUpperCase()}_URL`]\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Auth from either a subdomain or a URL\n */\nexport function createAuthClient(params: NhostClientConstructorParams) {\n const authUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'auth')\n : params.authUrl\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({ url: authUrl, ...params })\n}\n","import fetch from 'cross-fetch'\nimport { urlFromSubdomain } from '../../utils/helpers'\nimport { NhostClientConstructorParams } from '../../utils/types'\nimport {\n NhostFunctionCallConfig,\n NhostFunctionCallResponse,\n NhostFunctionsConstructorParams\n} from './types'\n/**\n * Creates a client for Functions from either a subdomain or a URL\n */\nexport function createFunctionsClient(params: NhostClientConstructorParams) {\n const functionsUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'functions')\n : params.functionsUrl\n\n if (!functionsUrl) {\n throw new Error('Please provide `subdomain` or `functionsUrl`.')\n }\n\n return new NhostFunctionsClient({ url: functionsUrl, ...params })\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n readonly url: string\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n }\n\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>>\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n body: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const result = await fetch(url, {\n body: JSON.stringify(body),\n headers,\n method: 'POST'\n })\n if (!result.ok) {\n throw new Error(result.statusText)\n }\n let data: T\n try {\n data = await result.json()\n } catch {\n data = (await result.text()) as unknown as T\n }\n return {\n res: { data, status: result.status, statusText: result.statusText },\n error: null\n }\n } catch (e) {\n const error = e as Error\n return {\n res: null,\n error: {\n message: error.message,\n status: error.name === 'AbortError' ? 0 : 500,\n error: error.name === 'AbortError' ? 'abort-error' : 'unknown'\n }\n }\n }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): NhostFunctionCallConfig['headers'] {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for GraphQL from either a subdomain or a URL\n */\nexport function createGraphqlClient(params: NhostClientConstructorParams) {\n const graphqlUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'graphql')\n : params.graphqlUrl\n\n if (!graphqlUrl) {\n throw new Error('Please provide `subdomain` or `graphqlUrl`.')\n }\n\n return new NhostGraphqlClient({ url: graphqlUrl, ...params })\n}\n","import { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Storage from either a subdomain or a URL\n */\nexport function createStorageClient(params: NhostClientConstructorParams<undefined>) {\n const storageUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'storage')\n : params.storageUrl\n\n if (!storageUrl) {\n throw new Error('Please provide `subdomain` or `storageUrl`.')\n }\n\n return new HasuraStorageClient({ url: storageUrl, ...params })\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\nimport { NhostClientConstructorParams } from '../utils/types'\nimport { createAuthClient } from './auth'\nimport { createFunctionsClient, NhostFunctionsClient } from './functions'\nimport { createGraphqlClient } from './graphql'\nimport { createStorageClient } from './storage'\n\nexport const createNhostClient = (params: NhostClientConstructorParams) => new NhostClient(params)\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n // * Set clients for all services\n this.auth = createAuthClient({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start,\n ...urlParams\n })\n this.storage = createStorageClient({ adminSecret, ...urlParams })\n this.functions = createFunctionsClient({ adminSecret, ...urlParams })\n this.graphql = createGraphqlClient({ adminSecret, ...urlParams })\n\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\n })\n\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","result","fetch","data","e","error","accessToken","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","_event","session","newValue"],"mappings":"uNAGMA,EAAkB,8EAUR,SAAAC,EACdC,EACAC,EACQ,CACR,KAAM,CAAE,WAAAC,EAAY,UAAAC,EAAW,OAAAC,CAAA,EAAWJ,EAE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AA,QAAQ,eAAeA,CAAQ,CAItC,CACF"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/utils/helpers.ts","../src/clients/auth.ts","../src/clients/functions/index.ts","../src/clients/graphql.ts","../src/clients/storage.ts","../src/clients/nhost.ts"],"sourcesContent":["import { NhostClientConstructorParams } from './types'\n\n// a port can be a number or a placeholder string with leading and trailing double underscores, f.e. \"8080\" or \"__PLACEHOLDER_NAME__\"\nconst LOCALHOST_REGEX = /^((?<protocol>http[s]?):\\/\\/)?(?<host>localhost)(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n): string {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n if (!subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol = 'http', host, port = 1337 } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n return `${protocol}://${host}:${port}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n\n/**\n *\n * @returns whether the code is running in a browser\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\n/**\n *\n * @returns whether the code is running in a Node.js environment\n */\nfunction environmentIsAvailable() {\n return typeof process !== 'undefined' && process.env\n}\n\n/**\n *\n * @param service auth | storage | graphql | functions\n * @returns the service's url if the corresponding env var is set\n * NHOST_${service}_URL\n */\nfunction getValueFromEnv(service: string) {\n if (isBrowser() || !environmentIsAvailable()) {\n return null\n }\n\n return process.env[`NHOST_${service.toUpperCase()}_URL`]\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Auth from either a subdomain or a URL\n */\nexport function createAuthClient(params: NhostClientConstructorParams) {\n const authUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'auth')\n : params.authUrl\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({ url: authUrl, ...params })\n}\n","import fetch from 'cross-fetch'\nimport { urlFromSubdomain } from '../../utils/helpers'\nimport { NhostClientConstructorParams } from '../../utils/types'\nimport {\n NhostFunctionCallConfig,\n NhostFunctionCallResponse,\n NhostFunctionsConstructorParams\n} from './types'\n/**\n * Creates a client for Functions from either a subdomain or a URL\n */\nexport function createFunctionsClient(params: NhostClientConstructorParams) {\n const functionsUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'functions')\n : params.functionsUrl\n\n if (!functionsUrl) {\n throw new Error('Please provide `subdomain` or `functionsUrl`.')\n }\n\n return new NhostFunctionsClient({ url: functionsUrl, ...params })\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n readonly url: string\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n }\n\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>>\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n body: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n const backendUrl = this.url\n const functionUrl = url.startsWith('/') ? url : `/${url}`\n\n try {\n const result = await fetch(`${backendUrl}/${functionUrl}`, {\n body: JSON.stringify(body),\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n throw new Error(result.statusText)\n }\n\n let data: T\n\n if (result.headers.get('content-type') === 'application/json') {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as T\n }\n\n return {\n res: { data, status: result.status, statusText: result.statusText },\n error: null\n }\n } catch (e) {\n const error = e as Error\n return {\n res: null,\n error: {\n message: error.message,\n status: error.name === 'AbortError' ? 0 : 500,\n error: error.name === 'AbortError' ? 'abort-error' : 'unknown'\n }\n }\n }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): NhostFunctionCallConfig['headers'] {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for GraphQL from either a subdomain or a URL\n */\nexport function createGraphqlClient(params: NhostClientConstructorParams) {\n const graphqlUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'graphql')\n : params.graphqlUrl\n\n if (!graphqlUrl) {\n throw new Error('Please provide `subdomain` or `graphqlUrl`.')\n }\n\n return new NhostGraphqlClient({ url: graphqlUrl, ...params })\n}\n","import { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Storage from either a subdomain or a URL\n */\nexport function createStorageClient(params: NhostClientConstructorParams<undefined>) {\n const storageUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'storage')\n : params.storageUrl\n\n if (!storageUrl) {\n throw new Error('Please provide `subdomain` or `storageUrl`.')\n }\n\n return new HasuraStorageClient({ url: storageUrl, ...params })\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\nimport { NhostClientConstructorParams } from '../utils/types'\nimport { createAuthClient } from './auth'\nimport { createFunctionsClient, NhostFunctionsClient } from './functions'\nimport { createGraphqlClient } from './graphql'\nimport { createStorageClient } from './storage'\n\nexport const createNhostClient = (params: NhostClientConstructorParams) => new NhostClient(params)\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n // * Set clients for all services\n this.auth = createAuthClient({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start,\n ...urlParams\n })\n this.storage = createStorageClient({ adminSecret, ...urlParams })\n this.functions = createFunctionsClient({ adminSecret, ...urlParams })\n this.graphql = createGraphqlClient({ adminSecret, ...urlParams })\n\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\n })\n\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","functionUrl","result","fetch","data","e","error","accessToken","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","_event","session","newValue"],"mappings":"uNAGMA,EAAkB,8EAUR,SAAAC,EACdC,EACAC,EACQ,CACR,KAAM,CAAE,WAAAC,EAAY,UAAAC,EAAW,OAAAC,CAAA,EAAWJ,EAE1C,GAAIE,EACF,MAAO,GAAGA,QAAiBD,IAG7B,GAAI,CAACE,EACG,MAAA,IAAI,M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AA8B,CAC5C,KAAK,aAAeA,EACf,KAAA,QAAQ,eAAeA,CAAQ,CAItC,CACF"}
package/dist/index.esm.js CHANGED
@@ -3,81 +3,76 @@ export * from "@nhost/hasura-auth-js";
3
3
  import { HasuraStorageClient as g } from "@nhost/hasura-storage-js";
4
4
  export * from "@nhost/hasura-storage-js";
5
5
  import w from "cross-fetch";
6
- import { NhostGraphqlClient as T } from "@nhost/graphql-js";
6
+ import { NhostGraphqlClient as p } from "@nhost/graphql-js";
7
7
  const b = /^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/;
8
- function a(t, e) {
9
- const { backendUrl: s, subdomain: o, region: c } = t;
8
+ function d(t, e) {
9
+ const { backendUrl: s, subdomain: n, region: a } = t;
10
10
  if (s)
11
11
  return `${s}/v1/${e}`;
12
- if (!o)
12
+ if (!n)
13
13
  throw new Error("Either `backendUrl` or `subdomain` must be set.");
14
- const r = o.match(b);
15
- if (r != null && r.groups) {
16
- const { protocol: n = "http", host: l, port: d = 1337 } = r.groups, i = m(e);
17
- return i || `${n}://${l}:${d}/v1/${e}`;
14
+ const i = n.match(b);
15
+ if (i != null && i.groups) {
16
+ const { protocol: c = "http", host: r, port: o = 1337 } = i.groups, u = U(e);
17
+ return u || `${c}://${r}:${o}/v1/${e}`;
18
18
  }
19
- if (!c)
19
+ if (!a)
20
20
  throw new Error('`region` must be set when using a `subdomain` other than "localhost".');
21
- return `https://${o}.${e}.${c}.nhost.run/v1`;
21
+ return `https://${n}.${e}.${a}.nhost.run/v1`;
22
22
  }
23
23
  function k() {
24
24
  return typeof window < "u";
25
25
  }
26
- function p() {
26
+ function T() {
27
27
  return typeof process < "u" && process.env;
28
28
  }
29
- function m(t) {
30
- return k() || !p() ? null : process.env[`NHOST_${t.toUpperCase()}_URL`];
31
- }
32
29
  function U(t) {
33
- const e = "subdomain" in t || "backendUrl" in t ? a(t, "auth") : t.authUrl;
30
+ return k() || !T() ? null : process.env[`NHOST_${t.toUpperCase()}_URL`];
31
+ }
32
+ function m(t) {
33
+ const e = "subdomain" in t || "backendUrl" in t ? d(t, "auth") : t.authUrl;
34
34
  if (!e)
35
35
  throw new Error("Please provide `subdomain` or `authUrl`.");
36
36
  return new f({ url: e, ...t });
37
37
  }
38
38
  function A(t) {
39
- const e = "subdomain" in t || "backendUrl" in t ? a(t, "functions") : t.functionsUrl;
39
+ const e = "subdomain" in t || "backendUrl" in t ? d(t, "functions") : t.functionsUrl;
40
40
  if (!e)
41
41
  throw new Error("Please provide `subdomain` or `functionsUrl`.");
42
42
  return new S({ url: e, ...t });
43
43
  }
44
44
  class S {
45
45
  constructor(e) {
46
- const { url: s, adminSecret: o } = e;
47
- this.url = s, this.accessToken = null, this.adminSecret = o;
46
+ const { url: s, adminSecret: n } = e;
47
+ this.url = s, this.accessToken = null, this.adminSecret = n;
48
48
  }
49
- async call(e, s, o) {
50
- const c = {
49
+ async call(e, s, n) {
50
+ const a = {
51
51
  "Content-Type": "application/json",
52
52
  ...this.generateAccessTokenHeaders(),
53
- ...o == null ? void 0 : o.headers
54
- };
53
+ ...n == null ? void 0 : n.headers
54
+ }, i = this.url, c = e.startsWith("/") ? e : `/${e}`;
55
55
  try {
56
- const r = await w(e, {
56
+ const r = await w(`${i}/${c}`, {
57
57
  body: JSON.stringify(s),
58
- headers: c,
58
+ headers: a,
59
59
  method: "POST"
60
60
  });
61
61
  if (!r.ok)
62
62
  throw new Error(r.statusText);
63
- let n;
64
- try {
65
- n = await r.json();
66
- } catch {
67
- n = await r.text();
68
- }
69
- return {
70
- res: { data: n, status: r.status, statusText: r.statusText },
63
+ let o;
64
+ return r.headers.get("content-type") === "application/json" ? o = await r.json() : o = await r.text(), {
65
+ res: { data: o, status: r.status, statusText: r.statusText },
71
66
  error: null
72
67
  };
73
68
  } catch (r) {
74
- const n = r;
69
+ const o = r;
75
70
  return {
76
71
  res: null,
77
72
  error: {
78
- message: n.message,
79
- status: n.name === "AbortError" ? 0 : 500,
80
- error: n.name === "AbortError" ? "abort-error" : "unknown"
73
+ message: o.message,
74
+ status: o.name === "AbortError" ? 0 : 500,
75
+ error: o.name === "AbortError" ? "abort-error" : "unknown"
81
76
  }
82
77
  };
83
78
  }
@@ -98,44 +93,44 @@ class S {
98
93
  }
99
94
  }
100
95
  function C(t) {
101
- const e = "subdomain" in t || "backendUrl" in t ? a(t, "graphql") : t.graphqlUrl;
96
+ const e = "subdomain" in t || "backendUrl" in t ? d(t, "graphql") : t.graphqlUrl;
102
97
  if (!e)
103
98
  throw new Error("Please provide `subdomain` or `graphqlUrl`.");
104
- return new T({ url: e, ...t });
99
+ return new p({ url: e, ...t });
105
100
  }
106
101
  function E(t) {
107
- const e = "subdomain" in t || "backendUrl" in t ? a(t, "storage") : t.storageUrl;
102
+ const e = "subdomain" in t || "backendUrl" in t ? d(t, "storage") : t.storageUrl;
108
103
  if (!e)
109
104
  throw new Error("Please provide `subdomain` or `storageUrl`.");
110
105
  return new g({ url: e, ...t });
111
106
  }
112
- const y = (t) => new v(t);
113
- class v {
107
+ const y = (t) => new $(t);
108
+ class $ {
114
109
  constructor({
115
110
  refreshIntervalTime: e,
116
111
  clientStorage: s,
117
- clientStorageType: o,
118
- autoRefreshToken: c,
119
- autoSignIn: r,
120
- adminSecret: n,
121
- devTools: l,
122
- start: d = !0,
123
- ...i
112
+ clientStorageType: n,
113
+ autoRefreshToken: a,
114
+ autoSignIn: i,
115
+ adminSecret: c,
116
+ devTools: r,
117
+ start: o = !0,
118
+ ...u
124
119
  }) {
125
- this.auth = U({
120
+ this.auth = m({
126
121
  refreshIntervalTime: e,
127
122
  clientStorage: s,
128
- clientStorageType: o,
129
- autoRefreshToken: c,
130
- autoSignIn: r,
131
- start: d,
132
- ...i
133
- }), this.storage = E({ adminSecret: n, ...i }), this.functions = A({ adminSecret: n, ...i }), this.graphql = C({ adminSecret: n, ...i }), this.auth.onAuthStateChanged((u, h) => {
134
- u === "SIGNED_OUT" && (this.storage.setAccessToken(void 0), this.functions.setAccessToken(void 0), this.graphql.setAccessToken(void 0));
135
- }), this.auth.onTokenChanged((u) => {
136
- const h = u == null ? void 0 : u.accessToken;
137
- this.storage.setAccessToken(h), this.functions.setAccessToken(h), this.graphql.setAccessToken(h);
138
- }), this._adminSecret = n, this.devTools = l;
123
+ clientStorageType: n,
124
+ autoRefreshToken: a,
125
+ autoSignIn: i,
126
+ start: o,
127
+ ...u
128
+ }), this.storage = E({ adminSecret: c, ...u }), this.functions = A({ adminSecret: c, ...u }), this.graphql = C({ adminSecret: c, ...u }), this.auth.onAuthStateChanged((h, l) => {
129
+ h === "SIGNED_OUT" && (this.storage.setAccessToken(void 0), this.functions.setAccessToken(void 0), this.graphql.setAccessToken(void 0));
130
+ }), this.auth.onTokenChanged((h) => {
131
+ const l = h == null ? void 0 : h.accessToken;
132
+ this.storage.setAccessToken(l), this.functions.setAccessToken(l), this.graphql.setAccessToken(l);
133
+ }), this._adminSecret = c, this.devTools = r;
139
134
  }
140
135
  get adminSecret() {
141
136
  return this._adminSecret;
@@ -145,9 +140,9 @@ class v {
145
140
  }
146
141
  }
147
142
  export {
148
- v as NhostClient,
143
+ $ as NhostClient,
149
144
  S as NhostFunctionsClient,
150
- U as createAuthClient,
145
+ m as createAuthClient,
151
146
  A as createFunctionsClient,
152
147
  C as createGraphqlClient,
153
148
  y as createNhostClient,
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/utils/helpers.ts","../src/clients/auth.ts","../src/clients/functions/index.ts","../src/clients/graphql.ts","../src/clients/storage.ts","../src/clients/nhost.ts"],"sourcesContent":["import { NhostClientConstructorParams } from './types'\n\n// a port can be a number or a placeholder string with leading and trailing double underscores, f.e. \"8080\" or \"__PLACEHOLDER_NAME__\"\nconst LOCALHOST_REGEX = /^((?<protocol>http[s]?):\\/\\/)?(?<host>localhost)(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n): string {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n if (!subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol = 'http', host, port = 1337 } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n return `${protocol}://${host}:${port}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n\n/**\n *\n * @returns whether the code is running in a browser\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\n/**\n *\n * @returns whether the code is running in a Node.js environment\n */\nfunction environmentIsAvailable() {\n return typeof process !== 'undefined' && process.env\n}\n\n/**\n *\n * @param service auth | storage | graphql | functions\n * @returns the service's url if the corresponding env var is set\n * NHOST_${service}_URL\n */\nfunction getValueFromEnv(service: string) {\n if (isBrowser() || !environmentIsAvailable()) {\n return null\n }\n\n return process.env[`NHOST_${service.toUpperCase()}_URL`]\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Auth from either a subdomain or a URL\n */\nexport function createAuthClient(params: NhostClientConstructorParams) {\n const authUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'auth')\n : params.authUrl\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({ url: authUrl, ...params })\n}\n","import fetch from 'cross-fetch'\nimport { urlFromSubdomain } from '../../utils/helpers'\nimport { NhostClientConstructorParams } from '../../utils/types'\nimport {\n NhostFunctionCallConfig,\n NhostFunctionCallResponse,\n NhostFunctionsConstructorParams\n} from './types'\n/**\n * Creates a client for Functions from either a subdomain or a URL\n */\nexport function createFunctionsClient(params: NhostClientConstructorParams) {\n const functionsUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'functions')\n : params.functionsUrl\n\n if (!functionsUrl) {\n throw new Error('Please provide `subdomain` or `functionsUrl`.')\n }\n\n return new NhostFunctionsClient({ url: functionsUrl, ...params })\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n readonly url: string\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n }\n\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>>\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n body: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const result = await fetch(url, {\n body: JSON.stringify(body),\n headers,\n method: 'POST'\n })\n if (!result.ok) {\n throw new Error(result.statusText)\n }\n let data: T\n try {\n data = await result.json()\n } catch {\n data = (await result.text()) as unknown as T\n }\n return {\n res: { data, status: result.status, statusText: result.statusText },\n error: null\n }\n } catch (e) {\n const error = e as Error\n return {\n res: null,\n error: {\n message: error.message,\n status: error.name === 'AbortError' ? 0 : 500,\n error: error.name === 'AbortError' ? 'abort-error' : 'unknown'\n }\n }\n }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): NhostFunctionCallConfig['headers'] {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for GraphQL from either a subdomain or a URL\n */\nexport function createGraphqlClient(params: NhostClientConstructorParams) {\n const graphqlUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'graphql')\n : params.graphqlUrl\n\n if (!graphqlUrl) {\n throw new Error('Please provide `subdomain` or `graphqlUrl`.')\n }\n\n return new NhostGraphqlClient({ url: graphqlUrl, ...params })\n}\n","import { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Storage from either a subdomain or a URL\n */\nexport function createStorageClient(params: NhostClientConstructorParams<undefined>) {\n const storageUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'storage')\n : params.storageUrl\n\n if (!storageUrl) {\n throw new Error('Please provide `subdomain` or `storageUrl`.')\n }\n\n return new HasuraStorageClient({ url: storageUrl, ...params })\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\nimport { NhostClientConstructorParams } from '../utils/types'\nimport { createAuthClient } from './auth'\nimport { createFunctionsClient, NhostFunctionsClient } from './functions'\nimport { createGraphqlClient } from './graphql'\nimport { createStorageClient } from './storage'\n\nexport const createNhostClient = (params: NhostClientConstructorParams) => new NhostClient(params)\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n // * Set clients for all services\n this.auth = createAuthClient({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start,\n ...urlParams\n })\n this.storage = createStorageClient({ adminSecret, ...urlParams })\n this.functions = createFunctionsClient({ adminSecret, ...urlParams })\n this.graphql = createGraphqlClient({ adminSecret, ...urlParams })\n\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\n })\n\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","result","fetch","data","e","error","accessToken","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","_event","session","newValue"],"mappings":";;;;;;AAGA,MAAMA,IAAkB;AAUR,SAAAC,EACdC,GACAC,GACQ;AACR,QAAM,EAAE,YAAAC,GAAY,WAAAC,GAAW,QAAAC,EAAA,IAAWJ;AAE1C,MAAIE;AACF,WAAO,GAAGA,QAAiBD;AAG7B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,iDAAiD;AAI7D,QAAAE,IAA0BF,EAAU,MAAML,CAAe;AAC/D,MAAIO,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,IAAW,QAAQ,MAAAC,GAAM,MAAAC,IAAO,SAASH,EAAwB,QAEnEI,IAAaC,EAAgBT,CAAO;AAC1C,WAAIQ,KAGG,GAAGH,OAAcC,KAAQC,QAAWP;AAAA,EAC7C;AAEA,MAAI,CAACG;AACG,UAAA,IAAI,MAAM,uEAAuE;AAGlF,SAAA,WAAWD,KAAaF,KAAWG;AAC5C;AAMA,SAASO,IAAqB;AAC5B,SAAO,OAAO,SAAW;AAC3B;AAMA,SAASC,IAAyB;AACzB,SAAA,OAAO,UAAY,OAAe,QAAQ;AACnD;AAQA,SAASF,EAAgBT,GAAiB;AACxC,SAAIU,EAAU,KAAK,CAACC,MAC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IACA,aAAAtB;AAAA,IACA,UAAAuB;AAAA,IACA,OAAAC,IAAQ;AAAA,OACLC;AAAA,EAAA,GAC4B;AAE/B,SAAK,OAAOjC,EAAiB;AAAA,MAC3B,qBAAA0B;AAAA,MACA,eAAAC;AAAA,MACA,mBAAAC;AAAA,MACA,kBAAAC;AAAA,MACA,YAAAC;AAAA,MACA,OAAAE;AAAA,MACA,GAAGC;AAAA,IAAA,CACJ,GACD,KAAK,UAAUZ,EAAoB,EAAE,aAAAb,GAAa,GAAGyB,GAAW,GAChE,KAAK,YAAY7B,EAAsB,EAAE,aAAAI,GAAa,GAAGyB,GAAW,GACpE,KAAK,UAAUf,EAAoB,EAAE,aAAAV,GAAa,GAAGyB,GAAW,GAEhE,KAAK,KAAK,mBAAmB,CAACC,GAAQC,MAAY;AAChD,MAAID,MAAW,iBACR,KAAA,QAAQ,eAAe,MAAS,GAChC,KAAA,UAAU,eAAe,MAAS,GAClC,KAAA,QAAQ,eAAe,MAAS;AAAA,IACvC,CACD,GAGI,KAAA,KAAK,eAAe,CAACC,MAAY;AACpC,YAAMlB,IAAckB,KAAA,gBAAAA,EAAS;AACxB,WAAA,QAAQ,eAAelB,CAAW,GAClC,KAAA,UAAU,eAAeA,CAAW,GACpC,KAAA,QAAQ,eAAeA,CAAW;AAAA,IAAA,CACxC,GAED,KAAK,eAAeT,GACpB,KAAK,WAAWuB;AAAA,EAClB;AAAA,EAEA,IAAI,cAAkC;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAYK,GAA8B;AAC5C,SAAK,eAAeA,GACf,KAAA,QAAQ,eAAeA,CAAQ;AAAA,EAItC;AACF;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/utils/helpers.ts","../src/clients/auth.ts","../src/clients/functions/index.ts","../src/clients/graphql.ts","../src/clients/storage.ts","../src/clients/nhost.ts"],"sourcesContent":["import { NhostClientConstructorParams } from './types'\n\n// a port can be a number or a placeholder string with leading and trailing double underscores, f.e. \"8080\" or \"__PLACEHOLDER_NAME__\"\nconst LOCALHOST_REGEX = /^((?<protocol>http[s]?):\\/\\/)?(?<host>localhost)(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n): string {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n if (!subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol = 'http', host, port = 1337 } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n return `${protocol}://${host}:${port}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n\n/**\n *\n * @returns whether the code is running in a browser\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\n/**\n *\n * @returns whether the code is running in a Node.js environment\n */\nfunction environmentIsAvailable() {\n return typeof process !== 'undefined' && process.env\n}\n\n/**\n *\n * @param service auth | storage | graphql | functions\n * @returns the service's url if the corresponding env var is set\n * NHOST_${service}_URL\n */\nfunction getValueFromEnv(service: string) {\n if (isBrowser() || !environmentIsAvailable()) {\n return null\n }\n\n return process.env[`NHOST_${service.toUpperCase()}_URL`]\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Auth from either a subdomain or a URL\n */\nexport function createAuthClient(params: NhostClientConstructorParams) {\n const authUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'auth')\n : params.authUrl\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({ url: authUrl, ...params })\n}\n","import fetch from 'cross-fetch'\nimport { urlFromSubdomain } from '../../utils/helpers'\nimport { NhostClientConstructorParams } from '../../utils/types'\nimport {\n NhostFunctionCallConfig,\n NhostFunctionCallResponse,\n NhostFunctionsConstructorParams\n} from './types'\n/**\n * Creates a client for Functions from either a subdomain or a URL\n */\nexport function createFunctionsClient(params: NhostClientConstructorParams) {\n const functionsUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'functions')\n : params.functionsUrl\n\n if (!functionsUrl) {\n throw new Error('Please provide `subdomain` or `functionsUrl`.')\n }\n\n return new NhostFunctionsClient({ url: functionsUrl, ...params })\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n readonly url: string\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n }\n\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>>\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n body: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n const backendUrl = this.url\n const functionUrl = url.startsWith('/') ? url : `/${url}`\n\n try {\n const result = await fetch(`${backendUrl}/${functionUrl}`, {\n body: JSON.stringify(body),\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n throw new Error(result.statusText)\n }\n\n let data: T\n\n if (result.headers.get('content-type') === 'application/json') {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as T\n }\n\n return {\n res: { data, status: result.status, statusText: result.statusText },\n error: null\n }\n } catch (e) {\n const error = e as Error\n return {\n res: null,\n error: {\n message: error.message,\n status: error.name === 'AbortError' ? 0 : 500,\n error: error.name === 'AbortError' ? 'abort-error' : 'unknown'\n }\n }\n }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): NhostFunctionCallConfig['headers'] {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for GraphQL from either a subdomain or a URL\n */\nexport function createGraphqlClient(params: NhostClientConstructorParams) {\n const graphqlUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'graphql')\n : params.graphqlUrl\n\n if (!graphqlUrl) {\n throw new Error('Please provide `subdomain` or `graphqlUrl`.')\n }\n\n return new NhostGraphqlClient({ url: graphqlUrl, ...params })\n}\n","import { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Storage from either a subdomain or a URL\n */\nexport function createStorageClient(params: NhostClientConstructorParams<undefined>) {\n const storageUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'storage')\n : params.storageUrl\n\n if (!storageUrl) {\n throw new Error('Please provide `subdomain` or `storageUrl`.')\n }\n\n return new HasuraStorageClient({ url: storageUrl, ...params })\n}\n","import { NhostGraphqlClient } from '@nhost/graphql-js'\nimport { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\nimport { NhostClientConstructorParams } from '../utils/types'\nimport { createAuthClient } from './auth'\nimport { createFunctionsClient, NhostFunctionsClient } from './functions'\nimport { createGraphqlClient } from './graphql'\nimport { createStorageClient } from './storage'\n\nexport const createNhostClient = (params: NhostClientConstructorParams) => new NhostClient(params)\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n // * Set clients for all services\n this.auth = createAuthClient({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start,\n ...urlParams\n })\n this.storage = createStorageClient({ adminSecret, ...urlParams })\n this.functions = createFunctionsClient({ adminSecret, ...urlParams })\n this.graphql = createGraphqlClient({ adminSecret, ...urlParams })\n\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\n })\n\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","functionUrl","result","fetch","data","e","error","accessToken","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","_event","session","newValue"],"mappings":";;;;;;AAGA,MAAMA,IAAkB;AAUR,SAAAC,EACdC,GACAC,GACQ;AACR,QAAM,EAAE,YAAAC,GAAY,WAAAC,GAAW,QAAAC,EAAA,IAAWJ;AAE1C,MAAIE;AACF,WAAO,GAAGA,QAAiBD;AAG7B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,iDAAiD;AAI7D,QAAAE,IAA0BF,EAAU,MAAML,CAAe;AAC/D,MAAIO,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,IAAW,QAAQ,MAAAC,GAAM,MAAAC,IAAO,SAASH,EAAwB,QAEnEI,IAAaC,EAAgBT,CAAO;AAC1C,WAAIQ,KAGG,GAAGH,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,GACpB,KAAK,WAAWwB;AAAA,EAClB;AAAA,EAEA,IAAI,cAAkC;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAYK,GAA8B;AAC5C,SAAK,eAAeA,GACf,KAAA,QAAQ,eAAeA,CAAQ;AAAA,EAItC;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhost/nhost-js",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Nhost JavaScript SDK",
5
5
  "license": "MIT",
6
6
  "keywords": [