@nhost/nhost-js 2.0.2 → 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;
|
|
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"),
|
|
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
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -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,EAE1C,GAAIE,EACF,MAAO,GAAGA,QAAiBD,IAG7B,GAAI,CAACE,EACG,MAAA,IAAI,MAAM,iDAAiD,EAI7D,MAAAE,EAA0BF,EAAU,MAAML,CAAe,EAC/D,GAAIO,GAAA,MAAAA,EAAyB,OAAQ,CACnC,KAAM,CAAE,SAAAC,EAAW,OAAQ,KAAAC,EAAM,KAAAC,EAAO,MAASH,EAAwB,OAEnEI,EAAaC,EAAgBT,CAAO,EAC1C,OAAIQ,GAGG,GAAGH,OAAcC,KAAQC,QAAWP,GAC7C,CAEA,GAAI,CAACG,EACG,MAAA,IAAI,MAAM,uEAAuE,EAGlF,MAAA,WAAWD,KAAaF,KAAWG,gBAC5C,CAMA,SAASO,GAAqB,CAC5B,OAAO,OAAO,OAAW,GAC3B,CAMA,SAASC,GAAyB,CACzB,OAAA,OAAO,QAAY,KAAe,QAAQ,GACnD,CAQA,SAASF,EAAgBT,EAAiB,CACxC,OAAIU,EAAU,GAAK,CAACC,IACX,KAGF,QAAQ,IAAI,SAASX,EAAQ,YAAY,QAClD,CClEO,SAASY,EAAiBC,EAAsC,CAC/D,MAAAC,EACJ,cAAeD,GAAU,eAAgBA,EACrCf,EAAiBe,EAAQ,MAAM,EAC/BA,EAAO,QAEb,GAAI,CAACC,EACG,MAAA,IAAI,MAAM,0CAA0C,EAG5D,OAAO,IAAIC,EAAiB,iBAAA,CAAE,IAAKD,EAAS,GAAGD,EAAQ,CACzD,CCRO,SAASG,EAAsBH,EAAsC,CACpE,MAAAI,EACJ,cAAeJ,GAAU,eAAgBA,EACrCf,EAAiBe,EAAQ,WAAW,EACpCA,EAAO,aAEb,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B,CAAW,EAClC,KAAA,UAAU,eAAeA,CAAW,EACpC,KAAA,QAAQ,eAAeA,CAAW,CAAA,CACxC,EAED,KAAK,aAAeT,EACpB,KAAK,SAAWuB,CAClB,CAEA,IAAI,aAAkC,CACpC,OAAO,KAAK,YACd,CAEA,IAAI,YAAYK,EAA8B,CAC5C,KAAK,aAAeA,EACf,KAAA,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","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AA,YAAAA,EAAS,YACxB,KAAA,QAAQ,eAAelB,CAAW,EAClC,KAAA,UAAU,eAAeA,CAAW,EACpC,KAAA,QAAQ,eAAeA,CAAW,CAAA,CACxC,EAED,KAAK,aAAeV,EACpB,KAAK,SAAWwB,CAClB,CAEA,IAAI,aAAkC,CACpC,OAAO,KAAK,YACd,CAEA,IAAI,YAAYK,EAA8B,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
|
|
6
|
+
import { NhostGraphqlClient as p } from "@nhost/graphql-js";
|
|
7
7
|
const b = /^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/;
|
|
8
|
-
function
|
|
9
|
-
const { backendUrl: s, subdomain:
|
|
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 (!
|
|
12
|
+
if (!n)
|
|
13
13
|
throw new Error("Either `backendUrl` or `subdomain` must be set.");
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
const { protocol:
|
|
17
|
-
return
|
|
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 (!
|
|
19
|
+
if (!a)
|
|
20
20
|
throw new Error('`region` must be set when using a `subdomain` other than "localhost".');
|
|
21
|
-
return `https://${
|
|
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
|
|
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
|
-
|
|
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 ?
|
|
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:
|
|
47
|
-
this.url = s, this.accessToken = null, this.adminSecret =
|
|
46
|
+
const { url: s, adminSecret: n } = e;
|
|
47
|
+
this.url = s, this.accessToken = null, this.adminSecret = n;
|
|
48
48
|
}
|
|
49
|
-
async call(e, s,
|
|
50
|
-
const
|
|
49
|
+
async call(e, s, n) {
|
|
50
|
+
const a = {
|
|
51
51
|
"Content-Type": "application/json",
|
|
52
52
|
...this.generateAccessTokenHeaders(),
|
|
53
|
-
...
|
|
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(
|
|
56
|
+
const r = await w(`${i}/${c}`, {
|
|
57
57
|
body: JSON.stringify(s),
|
|
58
|
-
headers:
|
|
58
|
+
headers: a,
|
|
59
59
|
method: "POST"
|
|
60
60
|
});
|
|
61
61
|
if (!r.ok)
|
|
62
62
|
throw new Error(r.statusText);
|
|
63
|
-
let
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
69
|
+
const o = r;
|
|
75
70
|
return {
|
|
76
71
|
res: null,
|
|
77
72
|
error: {
|
|
78
|
-
message:
|
|
79
|
-
status:
|
|
80
|
-
error:
|
|
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 ?
|
|
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
|
|
99
|
+
return new p({ url: e, ...t });
|
|
105
100
|
}
|
|
106
101
|
function E(t) {
|
|
107
|
-
const e = "subdomain" in t || "backendUrl" in t ?
|
|
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
|
|
113
|
-
class
|
|
107
|
+
const y = (t) => new $(t);
|
|
108
|
+
class $ {
|
|
114
109
|
constructor({
|
|
115
110
|
refreshIntervalTime: e,
|
|
116
111
|
clientStorage: s,
|
|
117
|
-
clientStorageType:
|
|
118
|
-
autoRefreshToken:
|
|
119
|
-
autoSignIn:
|
|
120
|
-
adminSecret:
|
|
121
|
-
devTools:
|
|
122
|
-
start:
|
|
123
|
-
...
|
|
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 =
|
|
120
|
+
this.auth = m({
|
|
126
121
|
refreshIntervalTime: e,
|
|
127
122
|
clientStorage: s,
|
|
128
|
-
clientStorageType:
|
|
129
|
-
autoRefreshToken:
|
|
130
|
-
autoSignIn:
|
|
131
|
-
start:
|
|
132
|
-
...
|
|
133
|
-
}), this.storage = E({ adminSecret:
|
|
134
|
-
|
|
135
|
-
}), this.auth.onTokenChanged((
|
|
136
|
-
const
|
|
137
|
-
this.storage.setAccessToken(
|
|
138
|
-
}), this._adminSecret =
|
|
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
|
-
|
|
143
|
+
$ as NhostClient,
|
|
149
144
|
S as NhostFunctionsClient,
|
|
150
|
-
|
|
145
|
+
m as createAuthClient,
|
|
151
146
|
A as createFunctionsClient,
|
|
152
147
|
C as createGraphqlClient,
|
|
153
148
|
y as createNhostClient,
|
package/dist/index.esm.js.map
CHANGED
|
@@ -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,MACX,OAGF,QAAQ,IAAI,SAASX,EAAQ,YAAY;AAClD;AClEO,SAASY,EAAiBC,GAAsC;AAC/D,QAAAC,IACJ,eAAeD,KAAU,gBAAgBA,IACrCf,EAAiBe,GAAQ,MAAM,IAC/BA,EAAO;AAEb,MAAI,CAACC;AACG,UAAA,IAAI,MAAM,0CAA0C;AAG5D,SAAO,IAAIC,EAAiB,EAAE,KAAKD,GAAS,GAAGD,GAAQ;AACzD;ACR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AAUZ,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,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,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ost-js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Nhost JavaScript SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"cross-fetch": "^3.1.5",
|
|
47
47
|
"@nhost/hasura-auth-js": "2.0.0",
|
|
48
|
-
"@nhost/hasura-storage-js": "2.0.
|
|
48
|
+
"@nhost/hasura-storage-js": "2.0.1",
|
|
49
49
|
"@nhost/graphql-js": "0.0.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|