@nhost/nhost-js 3.2.8 → 5.0.0-beta.2

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.
Files changed (120) hide show
  1. package/README.md +73 -37
  2. package/dist/nhost-js/auth.cjs.js +2 -0
  3. package/dist/nhost-js/auth.cjs.js.map +1 -0
  4. package/dist/nhost-js/auth.es.js +589 -0
  5. package/dist/nhost-js/auth.es.js.map +1 -0
  6. package/dist/nhost-js/fetch.cjs.js +2 -0
  7. package/dist/nhost-js/fetch.cjs.js.map +1 -0
  8. package/dist/nhost-js/fetch.es.js +10 -0
  9. package/dist/nhost-js/fetch.es.js.map +1 -0
  10. package/dist/nhost-js/functions.cjs.js +2 -0
  11. package/dist/nhost-js/functions.cjs.js.map +1 -0
  12. package/dist/nhost-js/functions.es.js +31 -0
  13. package/dist/nhost-js/functions.es.js.map +1 -0
  14. package/dist/nhost-js/graphql.cjs.js +2 -0
  15. package/dist/nhost-js/graphql.cjs.js.map +1 -0
  16. package/dist/nhost-js/graphql.es.js +35 -0
  17. package/dist/nhost-js/graphql.es.js.map +1 -0
  18. package/dist/nhost-js/storage.cjs.js +2 -0
  19. package/dist/nhost-js/storage.cjs.js.map +1 -0
  20. package/dist/nhost-js/storage.es.js +205 -0
  21. package/dist/nhost-js/storage.es.js.map +1 -0
  22. package/dist/nhost-js.cjs.js +2 -0
  23. package/dist/nhost-js.cjs.js.map +1 -0
  24. package/dist/nhost-js.es.js +497 -0
  25. package/dist/nhost-js.es.js.map +1 -0
  26. package/dist/nhost-js.umd.js +2 -0
  27. package/dist/nhost-js.umd.js.map +1 -0
  28. package/dist/src/auth/client.d.ts +430 -0
  29. package/dist/src/auth/client.d.ts.map +1 -0
  30. package/dist/src/auth/client.js +727 -0
  31. package/dist/src/auth/client.js.map +1 -0
  32. package/dist/src/auth/index.d.ts +11 -0
  33. package/dist/src/auth/index.d.ts.map +1 -0
  34. package/dist/src/auth/index.js +11 -0
  35. package/dist/src/auth/index.js.map +1 -0
  36. package/dist/src/auth/interface.d.ts +142 -0
  37. package/dist/src/auth/interface.d.ts.map +1 -0
  38. package/dist/src/auth/interface.js +2 -0
  39. package/dist/src/auth/interface.js.map +1 -0
  40. package/dist/src/fetch/index.d.ts +53 -0
  41. package/dist/src/fetch/index.d.ts.map +1 -0
  42. package/dist/src/fetch/index.js +40 -0
  43. package/dist/src/fetch/index.js.map +1 -0
  44. package/dist/src/functions/client.d.ts +47 -0
  45. package/dist/src/functions/client.d.ts.map +1 -0
  46. package/dist/src/functions/client.js +62 -0
  47. package/dist/src/functions/client.js.map +1 -0
  48. package/dist/src/functions/index.d.ts +10 -0
  49. package/dist/src/functions/index.d.ts.map +1 -0
  50. package/dist/src/functions/index.js +10 -0
  51. package/dist/src/functions/index.js.map +1 -0
  52. package/dist/src/graphql/client.d.ts +89 -0
  53. package/dist/src/graphql/client.d.ts.map +1 -0
  54. package/dist/src/graphql/client.js +49 -0
  55. package/dist/src/graphql/client.js.map +1 -0
  56. package/dist/src/graphql/index.d.ts +10 -0
  57. package/dist/src/graphql/index.d.ts.map +1 -0
  58. package/dist/src/graphql/index.js +10 -0
  59. package/dist/src/graphql/index.js.map +1 -0
  60. package/dist/src/index.d.ts +184 -0
  61. package/dist/src/index.d.ts.map +1 -0
  62. package/dist/src/index.js +251 -0
  63. package/dist/src/index.js.map +1 -0
  64. package/dist/src/middlewareAttachToken.d.ts +24 -0
  65. package/dist/src/middlewareAttachToken.d.ts.map +1 -0
  66. package/dist/src/middlewareAttachToken.js +60 -0
  67. package/dist/src/middlewareAttachToken.js.map +1 -0
  68. package/dist/src/middlewareRefreshSession.d.ts +43 -0
  69. package/dist/src/middlewareRefreshSession.d.ts.map +1 -0
  70. package/dist/src/middlewareRefreshSession.js +190 -0
  71. package/dist/src/middlewareRefreshSession.js.map +1 -0
  72. package/dist/src/middlewareResponseSession.d.ts +26 -0
  73. package/dist/src/middlewareResponseSession.d.ts.map +1 -0
  74. package/dist/src/middlewareResponseSession.js +83 -0
  75. package/dist/src/middlewareResponseSession.js.map +1 -0
  76. package/dist/src/sessionStorage.d.ts +123 -0
  77. package/dist/src/sessionStorage.d.ts.map +1 -0
  78. package/dist/src/sessionStorage.js +165 -0
  79. package/dist/src/sessionStorage.js.map +1 -0
  80. package/dist/src/storage/client.d.ts +184 -0
  81. package/dist/src/storage/client.d.ts.map +1 -0
  82. package/dist/src/storage/client.js +249 -0
  83. package/dist/src/storage/client.js.map +1 -0
  84. package/dist/src/storage/index.d.ts +11 -0
  85. package/dist/src/storage/index.d.ts.map +1 -0
  86. package/dist/src/storage/index.js +11 -0
  87. package/dist/src/storage/index.js.map +1 -0
  88. package/dist/src/storage/interface.d.ts +52 -0
  89. package/dist/src/storage/interface.d.ts.map +1 -0
  90. package/dist/src/storage/interface.js +2 -0
  91. package/dist/src/storage/interface.js.map +1 -0
  92. package/dist/tsconfig.tsbuildinfo +1 -0
  93. package/package.json +109 -63
  94. package/LICENSE +0 -21
  95. package/dist/clients/auth.d.ts +0 -8
  96. package/dist/clients/auth.d.ts.map +0 -1
  97. package/dist/clients/functions/index.d.ts +0 -107
  98. package/dist/clients/functions/index.d.ts.map +0 -1
  99. package/dist/clients/functions/types.d.ts +0 -28
  100. package/dist/clients/functions/types.d.ts.map +0 -1
  101. package/dist/clients/graphql.d.ts +0 -8
  102. package/dist/clients/graphql.d.ts.map +0 -1
  103. package/dist/clients/index.d.ts +0 -6
  104. package/dist/clients/index.d.ts.map +0 -1
  105. package/dist/clients/nhost.d.ts +0 -83
  106. package/dist/clients/nhost.d.ts.map +0 -1
  107. package/dist/clients/storage.d.ts +0 -8
  108. package/dist/clients/storage.d.ts.map +0 -1
  109. package/dist/index.cjs.js +0 -2
  110. package/dist/index.cjs.js.map +0 -1
  111. package/dist/index.d.ts +0 -6
  112. package/dist/index.d.ts.map +0 -1
  113. package/dist/index.esm.js +0 -344
  114. package/dist/index.esm.js.map +0 -1
  115. package/dist/utils/helpers.d.ts +0 -20
  116. package/dist/utils/helpers.d.ts.map +0 -1
  117. package/dist/utils/types.d.ts +0 -57
  118. package/dist/utils/types.d.ts.map +0 -1
  119. package/umd/nhost-js.umd.js +0 -22
  120. package/umd/nhost-js.umd.js.map +0 -1
package/dist/index.cjs.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@nhost/hasura-auth-js"),p=require("@nhost/hasura-storage-js"),C=require("isomorphic-unfetch"),k=require("@nhost/graphql-js"),q=/^((?<protocol>http[s]?):\/\/)?(?<host>(localhost|local))(:(?<port>(\d+|__\w+__)))?$/;function d(t,e){const{subdomain:r,region:n}=t;if(!r)throw new Error("A `subdomain` must be set.");const u=r.match(q);if(u!=null&&u.groups){const{protocol:l,host:a,port:c}=u.groups,s=U(e);return s||(a==="localhost"?(console.warn('The `subdomain` is set to "localhost". Support for this will be removed in a future release. Please use "local" instead.'),`${l||"http"}://localhost:${c||1337}/v1/${e}`):c?`${l||"https"}://local.${e}.local.nhost.run:${c}/v1`:`${l||"https"}://local.${e}.local.nhost.run/v1`)}if(!n)throw new Error('`region` must be set when using a `subdomain` other than "local".');return`https://${r}.${e}.${n}.nhost.run/v1`}function y(){return typeof window!="undefined"}function H(){return typeof process!="undefined"&&process.env}function U(t){return y()||!H()?null:process.env[`NHOST_${t.toUpperCase()}_URL`]}function $(t,e){const n=e.startsWith("/")?e:`/${e}`;return t+n}function b(t){const e="subdomain"in t?d(t,"auth"):t.authUrl,{subdomain:r,region:n}=t;if(!e)throw new Error("Please provide `subdomain` or `authUrl`.");return new g.HasuraAuthClient({url:e,broadcastKey:`${r}${n!=null?n:"local"}`,...t})}function T(t){const e="subdomain"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){this.headers={};const{url:r,adminSecret:n}=e;this.url=r,this.accessToken=null,this.adminSecret=n}async call(e,r,n){var a,c;const u={"Content-Type":"application/json",...this.generateAccessTokenHeaders(),...n==null?void 0:n.headers,...this.headers},l=$(this.url,e);try{const s=await C(l,{body:r?JSON.stringify(r):null,headers:u,method:"POST"});if(!s.ok){let i;return(a=s.headers.get("content-type"))!=null&&a.includes("application/json")?i=await s.json():i=await s.text(),{res:null,error:{message:i,error:s.statusText,status:s.status}}}let o;return(c=s.headers.get("content-type"))!=null&&c.includes("application/json")?o=await s.json():o=await s.text(),{res:{data:o,status:s.status,statusText:s.statusText},error:null}}catch(s){const o=s;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}getHeaders(){return this.headers}setHeaders(e){e&&(this.headers={...this.headers,...e})}unsetHeaders(){const e=this.headers["x-hasura-role"];this.headers=e?{"x-hasura-role":e}:{}}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}function m(t){const e="subdomain"in t?d(t,"graphql"):t.graphqlUrl;if(!e)throw new Error("Please provide `subdomain` or `graphqlUrl`.");return new k.NhostGraphqlClient({url:e,...t})}function A(t){const e="subdomain"in t?d(t,"storage"):t.storageUrl;if(!e)throw new Error("Please provide `subdomain` or `storageUrl`.");return new p.HasuraStorageClient({url:e,...t})}const v=t=>new S(t);class S{constructor({refreshIntervalTime:e,clientStorage:r,clientStorageType:n,autoRefreshToken:u,autoSignIn:l,adminSecret:a,devTools:c,start:s=!0,...o}){this.auth=b({refreshIntervalTime:e,clientStorage:r,clientStorageType:n,autoRefreshToken:u,autoSignIn:l,start:s,...o}),this.storage=A({adminSecret:a,...o}),this.functions=T({adminSecret:a,...o}),this.graphql=m({adminSecret:a,...o}),this.auth.onAuthStateChanged((i,h)=>{if(i==="SIGNED_OUT"){this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0);return}const f=h==null?void 0:h.accessToken;this.storage.setAccessToken(f),this.functions.setAccessToken(f),this.graphql.setAccessToken(f)}),this.auth.onTokenChanged(i=>{const h=i==null?void 0:i.accessToken;this.storage.setAccessToken(h),this.functions.setAccessToken(h),this.graphql.setAccessToken(h)}),this._adminSecret=a,this.devTools=c}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}setRole(e){this.graphql.setHeaders({"x-hasura-role":e}),this.storage.setHeaders({"x-hasura-role":e}),this.functions.setHeaders({"x-hasura-role":e})}unsetRole(){this.graphql.setHeaders((({"x-hasura-role":e,...r})=>r)(this.graphql.getHeaders())),this.storage.setHeaders((({"x-hasura-role":e,...r})=>r)(this.storage.getHeaders())),this.functions.setHeaders((({"x-hasura-role":e,...r})=>r)(this.functions.getHeaders()))}}exports.NhostClient=S;exports.NhostFunctionsClient=w;exports.createAuthClient=b;exports.createFunctionsClient=T;exports.createGraphqlClient=m;exports.createNhostClient=v;exports.createStorageClient=A;exports.urlFromSubdomain=d;Object.keys(g).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>g[t]})});Object.keys(p).forEach(t=>{t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>p[t]})});
2
- //# sourceMappingURL=index.cjs.js.map
@@ -1 +0,0 @@
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__\"\nexport const LOCALHOST_REGEX =\n /^((?<protocol>http[s]?):\\/\\/)?(?<host>(localhost|local))(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * \\`subdomain\\` and `region` should be used when running the Nhost platform\n *\n * @param subdomainAndRegion\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n subdomainAndRegion: Pick<NhostClientConstructorParams, 'region' | 'subdomain'>,\n service: string\n): string {\n const { subdomain, region } = subdomainAndRegion\n\n if (!subdomain) {\n throw new Error('A `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port] or [http[s]://]local[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol, host, port } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n\n if (host === 'localhost') {\n console.warn(\n 'The `subdomain` is set to \"localhost\". Support for this will be removed in a future release. Please use \"local\" instead.'\n )\n\n return `${protocol || 'http'}://localhost:${port || 1337}/v1/${service}`\n }\n\n return port\n ? `${protocol || 'https'}://local.${service}.local.nhost.run:${port}/v1`\n : `${protocol || 'https'}://local.${service}.local.nhost.run/v1`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"local\".')\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\n/**\n * Combines a base URL and a path into a single URL string.\n *\n * @param baseUrl - The base URL to use.\n * @param path - The path to append to the base URL.\n * @returns The combined URL string.\n */\nexport function buildUrl(baseUrl: string, path: string) {\n const hasLeadingSlash = path.startsWith('/')\n const urlPath = hasLeadingSlash ? path : `/${path}`\n return baseUrl + urlPath\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 = 'subdomain' in params ? urlFromSubdomain(params, 'auth') : params.authUrl\n\n const { subdomain, region } = params\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({\n url: authUrl,\n broadcastKey: `${subdomain}${region ?? 'local'}`,\n ...params\n })\n}\n","import fetch from 'isomorphic-unfetch'\nimport { buildUrl, 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 ? urlFromSubdomain(params, 'functions') : 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 private headers: Record<string, 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 /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic\n * types to specify the expected response data, request body and error message.\n *\n * @example\n * ### Without generic types\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @example\n * ### Using generic types\n * ```ts\n * type Data = {\n * message: string\n * }\n *\n * type Body = {\n * email: string\n * name: string\n * }\n *\n * type ErrorMessage = {\n * details: string\n * }\n *\n * // The function will only accept a body of type `Body`\n * const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>(\n * 'send-welcome-email',\n * { email: 'joe@example.com', name: 'Joe Doe' }\n * )\n *\n * // Now the response data is typed as `Data`\n * console.log(res?.data.message)\n *\n * // Now the error message is typed as `ErrorMessage`\n * console.log(error?.message.details)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<TData = unknown, TBody = any, TErrorMessage = any>(\n url: string,\n body?: TBody | null,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<TData, TErrorMessage>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers,\n ...this.headers // nhost functions client headers to be sent with all calls\n }\n\n const fullUrl = buildUrl(this.url, url)\n\n try {\n const result = await fetch(fullUrl, {\n body: body ? JSON.stringify(body) : null,\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n let message: TErrorMessage\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n message = await result.json()\n } else {\n message = (await result.text()) as unknown as TErrorMessage\n }\n\n return {\n res: null,\n error: {\n message,\n error: result.statusText,\n status: result.status\n }\n }\n }\n\n let data: TData\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as TData\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 as unknown as TErrorMessage,\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 /**\n * Use `nhost.functions.getHeaders` to get the global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.getHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/get-headers\n */\n getHeaders(): Record<string, string> {\n return this.headers\n }\n\n /**\n * Use `nhost.functions.setHeaders` to a set global headers to be sent in all subsequent functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.setHeaders({\n * 'x-hasura-role': 'admin'\n * })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-headers\n */\n setHeaders(headers?: Record<string, string>) {\n if (!headers) {\n return\n }\n\n this.headers = {\n ...this.headers,\n ...headers\n }\n }\n\n /**\n * Use `nhost.functions.unsetHeaders` to a unset global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.unsetHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/unset-headers\n */\n unsetHeaders() {\n const userRole = this.headers['x-hasura-role']\n\n // preserve the user role header to avoid invalidating preceding 'setRole' call.\n this.headers = userRole ? { 'x-hasura-role': userRole } : {}\n }\n\n 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 = 'subdomain' in params ? urlFromSubdomain(params, 'graphql') : 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) {\n const storageUrl = 'subdomain' in params ? urlFromSubdomain(params, 'storage') : 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 *\n * @example\n * ```ts\n * // Create a new Nhost client from subdomain and region.\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc).\n * const nhost = new NhostClient({\n * authUrl: \"my-auth-service-url\",\n * storageUrl: \"my-storage-service-url\",\n * graphqlUrl: \"my-graphql-service-url\",\n * functionsUrl: \"my-functions-service-url\",\n * });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client for local development.\n * const nhost = new NhostClient({ subdomain: \"local\" });\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 return\n }\n\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\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 /**\n * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls.\n * Underneath, this method sets the `x-hasura-role` header on the graphql, storage,\n * and functions clients.\n *\n * ```ts\n * nhost.graphql.setHeaders({ 'x-hasura-role': role })\n * nhost.storage.setHeaders({ 'x-hasura-role': role })\n * nhost.functions.setHeaders({ 'x-hasura-role': role })\n * ```\n *\n * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.setRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role\n */\n setRole(role: string) {\n this.graphql.setHeaders({ 'x-hasura-role': role })\n this.storage.setHeaders({ 'x-hasura-role': role })\n this.functions.setHeaders({ 'x-hasura-role': role })\n }\n\n /**\n * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls.\n * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients.\n *\n * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.unsetRole()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role\n */\n unsetRole() {\n this.graphql.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.graphql.getHeaders()))\n this.storage.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.storage.getHeaders()))\n this.functions.setHeaders(\n (({ 'x-hasura-role': _, ...rest }) => rest)(this.functions.getHeaders())\n )\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","subdomainAndRegion","service","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","buildUrl","baseUrl","path","urlPath","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","fullUrl","result","fetch","message","_a","data","_b","e","error","accessToken","userRole","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","event","session","newValue","role","_","rest"],"mappings":"8NAGaA,EACX,sFASc,SAAAC,EACdC,EACAC,EACQ,CACF,KAAA,CAAE,UAAAC,EAAW,OAAAC,CAAA,EAAWH,EAE9B,GAAI,CAACE,EACG,MAAA,IAAI,MAAM,4BAA4B,EAIxC,MAAAE,EAA0BF,EAAU,MAAMJ,CAAe,EAC/D,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CAiBrD,WAAY,CACV,KAAK,QAAQ,YAAY,CAAC,CAAE,gBAAiBC,EAAG,GAAGC,CAAK,IAAMA,GAAM,KAAK,QAAQ,WAAY,CAAA,CAAC,EAC9F,KAAK,QAAQ,YAAY,CAAC,CAAE,gBAAiBD,EAAG,GAAGC,CAAK,IAAMA,GAAM,KAAK,QAAQ,WAAY,CAAA,CAAC,EAC9F,KAAK,UAAU,YACZ,CAAC,CAAE,gBAAiBD,EAAG,GAAGC,CAAK,IAAMA,GAAM,KAAK,UAAU,WAAY,CAAA,CACzE,CAAA,CAEJ"}
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from '@nhost/hasura-auth-js';
2
- export * from '@nhost/hasura-storage-js';
3
- export * from './clients';
4
- export { urlFromSubdomain } from './utils/helpers';
5
- export * from './utils/types';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,WAAW,CAAA;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,cAAc,eAAe,CAAA"}
package/dist/index.esm.js DELETED
@@ -1,344 +0,0 @@
1
- import { HasuraAuthClient as g } from "@nhost/hasura-auth-js";
2
- export * from "@nhost/hasura-auth-js";
3
- import { HasuraStorageClient as p } from "@nhost/hasura-storage-js";
4
- export * from "@nhost/hasura-storage-js";
5
- import T from "isomorphic-unfetch";
6
- import { NhostGraphqlClient as m } from "@nhost/graphql-js";
7
- const w = /^((?<protocol>http[s]?):\/\/)?(?<host>(localhost|local))(:(?<port>(\d+|__\w+__)))?$/;
8
- function d(e, t) {
9
- const { subdomain: s, region: o } = e;
10
- if (!s)
11
- throw new Error("A `subdomain` must be set.");
12
- const h = s.match(w);
13
- if (h != null && h.groups) {
14
- const { protocol: c, host: a, port: u } = h.groups, r = A(t);
15
- return r || (a === "localhost" ? (console.warn(
16
- 'The `subdomain` is set to "localhost". Support for this will be removed in a future release. Please use "local" instead.'
17
- ), `${c || "http"}://localhost:${u || 1337}/v1/${t}`) : u ? `${c || "https"}://local.${t}.local.nhost.run:${u}/v1` : `${c || "https"}://local.${t}.local.nhost.run/v1`);
18
- }
19
- if (!o)
20
- throw new Error('`region` must be set when using a `subdomain` other than "local".');
21
- return `https://${s}.${t}.${o}.nhost.run/v1`;
22
- }
23
- function k() {
24
- return typeof window != "undefined";
25
- }
26
- function b() {
27
- return typeof process != "undefined" && process.env;
28
- }
29
- function A(e) {
30
- return k() || !b() ? null : process.env[`NHOST_${e.toUpperCase()}_URL`];
31
- }
32
- function S(e, t) {
33
- const o = t.startsWith("/") ? t : `/${t}`;
34
- return e + o;
35
- }
36
- function H(e) {
37
- const t = "subdomain" in e ? d(e, "auth") : e.authUrl, { subdomain: s, region: o } = e;
38
- if (!t)
39
- throw new Error("Please provide `subdomain` or `authUrl`.");
40
- return new g({
41
- url: t,
42
- broadcastKey: `${s}${o != null ? o : "local"}`,
43
- ...e
44
- });
45
- }
46
- function x(e) {
47
- const t = "subdomain" in e ? d(e, "functions") : e.functionsUrl;
48
- if (!t)
49
- throw new Error("Please provide `subdomain` or `functionsUrl`.");
50
- return new U({ url: t, ...e });
51
- }
52
- class U {
53
- constructor(t) {
54
- this.headers = {};
55
- const { url: s, adminSecret: o } = t;
56
- this.url = s, this.accessToken = null, this.adminSecret = o;
57
- }
58
- /**
59
- * Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic
60
- * types to specify the expected response data, request body and error message.
61
- *
62
- * @example
63
- * ### Without generic types
64
- * ```ts
65
- * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })
66
- * ```
67
- *
68
- * @example
69
- * ### Using generic types
70
- * ```ts
71
- * type Data = {
72
- * message: string
73
- * }
74
- *
75
- * type Body = {
76
- * email: string
77
- * name: string
78
- * }
79
- *
80
- * type ErrorMessage = {
81
- * details: string
82
- * }
83
- *
84
- * // The function will only accept a body of type `Body`
85
- * const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>(
86
- * 'send-welcome-email',
87
- * { email: 'joe@example.com', name: 'Joe Doe' }
88
- * )
89
- *
90
- * // Now the response data is typed as `Data`
91
- * console.log(res?.data.message)
92
- *
93
- * // Now the error message is typed as `ErrorMessage`
94
- * console.log(error?.message.details)
95
- * ```
96
- *
97
- * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call
98
- */
99
- async call(t, s, o) {
100
- var a, u;
101
- const h = {
102
- "Content-Type": "application/json",
103
- ...this.generateAccessTokenHeaders(),
104
- ...o == null ? void 0 : o.headers,
105
- ...this.headers
106
- // nhost functions client headers to be sent with all calls
107
- }, c = S(this.url, t);
108
- try {
109
- const r = await T(c, {
110
- body: s ? JSON.stringify(s) : null,
111
- headers: h,
112
- method: "POST"
113
- });
114
- if (!r.ok) {
115
- let i;
116
- return (a = r.headers.get("content-type")) != null && a.includes("application/json") ? i = await r.json() : i = await r.text(), {
117
- res: null,
118
- error: {
119
- message: i,
120
- error: r.statusText,
121
- status: r.status
122
- }
123
- };
124
- }
125
- let n;
126
- return (u = r.headers.get("content-type")) != null && u.includes("application/json") ? n = await r.json() : n = await r.text(), {
127
- res: { data: n, status: r.status, statusText: r.statusText },
128
- error: null
129
- };
130
- } catch (r) {
131
- const n = r;
132
- return {
133
- res: null,
134
- error: {
135
- message: n.message,
136
- status: n.name === "AbortError" ? 0 : 500,
137
- error: n.name === "AbortError" ? "abort-error" : "unknown"
138
- }
139
- };
140
- }
141
- }
142
- /**
143
- * 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.
144
- *
145
- * @example
146
- * ```ts
147
- * nhost.functions.setAccessToken('some-access-token')
148
- * ```
149
- *
150
- * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token
151
- */
152
- setAccessToken(t) {
153
- if (!t) {
154
- this.accessToken = null;
155
- return;
156
- }
157
- this.accessToken = t;
158
- }
159
- /**
160
- * Use `nhost.functions.getHeaders` to get the global headers sent with all functions requests.
161
- *
162
- * @example
163
- * ```ts
164
- * nhost.functions.getHeaders()
165
- * ```
166
- *
167
- * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/get-headers
168
- */
169
- getHeaders() {
170
- return this.headers;
171
- }
172
- /**
173
- * Use `nhost.functions.setHeaders` to a set global headers to be sent in all subsequent functions requests.
174
- *
175
- * @example
176
- * ```ts
177
- * nhost.functions.setHeaders({
178
- * 'x-hasura-role': 'admin'
179
- * })
180
- * ```
181
- *
182
- * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-headers
183
- */
184
- setHeaders(t) {
185
- t && (this.headers = {
186
- ...this.headers,
187
- ...t
188
- });
189
- }
190
- /**
191
- * Use `nhost.functions.unsetHeaders` to a unset global headers sent with all functions requests.
192
- *
193
- * @example
194
- * ```ts
195
- * nhost.functions.unsetHeaders()
196
- * ```
197
- *
198
- * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/unset-headers
199
- */
200
- unsetHeaders() {
201
- const t = this.headers["x-hasura-role"];
202
- this.headers = t ? { "x-hasura-role": t } : {};
203
- }
204
- generateAccessTokenHeaders() {
205
- return this.adminSecret ? {
206
- "x-hasura-admin-secret": this.adminSecret
207
- } : this.accessToken ? {
208
- Authorization: `Bearer ${this.accessToken}`
209
- } : {};
210
- }
211
- }
212
- function $(e) {
213
- const t = "subdomain" in e ? d(e, "graphql") : e.graphqlUrl;
214
- if (!t)
215
- throw new Error("Please provide `subdomain` or `graphqlUrl`.");
216
- return new m({ url: t, ...e });
217
- }
218
- function v(e) {
219
- const t = "subdomain" in e ? d(e, "storage") : e.storageUrl;
220
- if (!t)
221
- throw new Error("Please provide `subdomain` or `storageUrl`.");
222
- return new p({ url: t, ...e });
223
- }
224
- const N = (e) => new C(e);
225
- class C {
226
- /**
227
- *
228
- * @example
229
- * ```ts
230
- * // Create a new Nhost client from subdomain and region.
231
- * const nhost = new NhostClient({ subdomain, region });
232
- * ```
233
- *
234
- *
235
- * ```ts
236
- * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc).
237
- * const nhost = new NhostClient({
238
- * authUrl: "my-auth-service-url",
239
- * storageUrl: "my-storage-service-url",
240
- * graphqlUrl: "my-graphql-service-url",
241
- * functionsUrl: "my-functions-service-url",
242
- * });
243
- * ```
244
- *
245
- *
246
- * ```ts
247
- * // Create a new Nhost client for local development.
248
- * const nhost = new NhostClient({ subdomain: "local" });
249
- * ```
250
- *
251
- * @docs https://docs.nhost.io/reference/javascript
252
- */
253
- constructor({
254
- refreshIntervalTime: t,
255
- clientStorage: s,
256
- clientStorageType: o,
257
- autoRefreshToken: h,
258
- autoSignIn: c,
259
- adminSecret: a,
260
- devTools: u,
261
- start: r = !0,
262
- ...n
263
- }) {
264
- this.auth = H({
265
- refreshIntervalTime: t,
266
- clientStorage: s,
267
- clientStorageType: o,
268
- autoRefreshToken: h,
269
- autoSignIn: c,
270
- start: r,
271
- ...n
272
- }), this.storage = v({ adminSecret: a, ...n }), this.functions = x({ adminSecret: a, ...n }), this.graphql = $({ adminSecret: a, ...n }), this.auth.onAuthStateChanged((i, l) => {
273
- if (i === "SIGNED_OUT") {
274
- this.storage.setAccessToken(void 0), this.functions.setAccessToken(void 0), this.graphql.setAccessToken(void 0);
275
- return;
276
- }
277
- const f = l == null ? void 0 : l.accessToken;
278
- this.storage.setAccessToken(f), this.functions.setAccessToken(f), this.graphql.setAccessToken(f);
279
- }), this.auth.onTokenChanged((i) => {
280
- const l = i == null ? void 0 : i.accessToken;
281
- this.storage.setAccessToken(l), this.functions.setAccessToken(l), this.graphql.setAccessToken(l);
282
- }), this._adminSecret = a, this.devTools = u;
283
- }
284
- get adminSecret() {
285
- return this._adminSecret;
286
- }
287
- set adminSecret(t) {
288
- this._adminSecret = t, this.storage.setAdminSecret(t);
289
- }
290
- /**
291
- * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls.
292
- * Underneath, this method sets the `x-hasura-role` header on the graphql, storage,
293
- * and functions clients.
294
- *
295
- * ```ts
296
- * nhost.graphql.setHeaders({ 'x-hasura-role': role })
297
- * nhost.storage.setHeaders({ 'x-hasura-role': role })
298
- * nhost.functions.setHeaders({ 'x-hasura-role': role })
299
- * ```
300
- *
301
- * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the
302
- * `x-hasura-role` header, as the last call will override any previous ones.
303
- *
304
- * @example
305
- * ```ts
306
- * nhost.setRole('admin')
307
- * ```
308
- *
309
- * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role
310
- */
311
- setRole(t) {
312
- this.graphql.setHeaders({ "x-hasura-role": t }), this.storage.setHeaders({ "x-hasura-role": t }), this.functions.setHeaders({ "x-hasura-role": t });
313
- }
314
- /**
315
- * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls.
316
- * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients.
317
- *
318
- * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the
319
- * `x-hasura-role` header, as the last call will override any previous ones.
320
- *
321
- * @example
322
- * ```ts
323
- * nhost.unsetRole()
324
- * ```
325
- *
326
- * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role
327
- */
328
- unsetRole() {
329
- this.graphql.setHeaders((({ "x-hasura-role": t, ...s }) => s)(this.graphql.getHeaders())), this.storage.setHeaders((({ "x-hasura-role": t, ...s }) => s)(this.storage.getHeaders())), this.functions.setHeaders(
330
- (({ "x-hasura-role": t, ...s }) => s)(this.functions.getHeaders())
331
- );
332
- }
333
- }
334
- export {
335
- C as NhostClient,
336
- U as NhostFunctionsClient,
337
- H as createAuthClient,
338
- x as createFunctionsClient,
339
- $ as createGraphqlClient,
340
- N as createNhostClient,
341
- v as createStorageClient,
342
- d as urlFromSubdomain
343
- };
344
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
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__\"\nexport const LOCALHOST_REGEX =\n /^((?<protocol>http[s]?):\\/\\/)?(?<host>(localhost|local))(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * \\`subdomain\\` and `region` should be used when running the Nhost platform\n *\n * @param subdomainAndRegion\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n subdomainAndRegion: Pick<NhostClientConstructorParams, 'region' | 'subdomain'>,\n service: string\n): string {\n const { subdomain, region } = subdomainAndRegion\n\n if (!subdomain) {\n throw new Error('A `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port] or [http[s]://]local[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol, host, port } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n\n if (host === 'localhost') {\n console.warn(\n 'The `subdomain` is set to \"localhost\". Support for this will be removed in a future release. Please use \"local\" instead.'\n )\n\n return `${protocol || 'http'}://localhost:${port || 1337}/v1/${service}`\n }\n\n return port\n ? `${protocol || 'https'}://local.${service}.local.nhost.run:${port}/v1`\n : `${protocol || 'https'}://local.${service}.local.nhost.run/v1`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"local\".')\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\n/**\n * Combines a base URL and a path into a single URL string.\n *\n * @param baseUrl - The base URL to use.\n * @param path - The path to append to the base URL.\n * @returns The combined URL string.\n */\nexport function buildUrl(baseUrl: string, path: string) {\n const hasLeadingSlash = path.startsWith('/')\n const urlPath = hasLeadingSlash ? path : `/${path}`\n return baseUrl + urlPath\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 = 'subdomain' in params ? urlFromSubdomain(params, 'auth') : params.authUrl\n\n const { subdomain, region } = params\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({\n url: authUrl,\n broadcastKey: `${subdomain}${region ?? 'local'}`,\n ...params\n })\n}\n","import fetch from 'isomorphic-unfetch'\nimport { buildUrl, 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 ? urlFromSubdomain(params, 'functions') : 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 private headers: Record<string, 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 /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic\n * types to specify the expected response data, request body and error message.\n *\n * @example\n * ### Without generic types\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @example\n * ### Using generic types\n * ```ts\n * type Data = {\n * message: string\n * }\n *\n * type Body = {\n * email: string\n * name: string\n * }\n *\n * type ErrorMessage = {\n * details: string\n * }\n *\n * // The function will only accept a body of type `Body`\n * const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>(\n * 'send-welcome-email',\n * { email: 'joe@example.com', name: 'Joe Doe' }\n * )\n *\n * // Now the response data is typed as `Data`\n * console.log(res?.data.message)\n *\n * // Now the error message is typed as `ErrorMessage`\n * console.log(error?.message.details)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<TData = unknown, TBody = any, TErrorMessage = any>(\n url: string,\n body?: TBody | null,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<TData, TErrorMessage>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers,\n ...this.headers // nhost functions client headers to be sent with all calls\n }\n\n const fullUrl = buildUrl(this.url, url)\n\n try {\n const result = await fetch(fullUrl, {\n body: body ? JSON.stringify(body) : null,\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n let message: TErrorMessage\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n message = await result.json()\n } else {\n message = (await result.text()) as unknown as TErrorMessage\n }\n\n return {\n res: null,\n error: {\n message,\n error: result.statusText,\n status: result.status\n }\n }\n }\n\n let data: TData\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as TData\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 as unknown as TErrorMessage,\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 /**\n * Use `nhost.functions.getHeaders` to get the global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.getHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/get-headers\n */\n getHeaders(): Record<string, string> {\n return this.headers\n }\n\n /**\n * Use `nhost.functions.setHeaders` to a set global headers to be sent in all subsequent functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.setHeaders({\n * 'x-hasura-role': 'admin'\n * })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-headers\n */\n setHeaders(headers?: Record<string, string>) {\n if (!headers) {\n return\n }\n\n this.headers = {\n ...this.headers,\n ...headers\n }\n }\n\n /**\n * Use `nhost.functions.unsetHeaders` to a unset global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.unsetHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/unset-headers\n */\n unsetHeaders() {\n const userRole = this.headers['x-hasura-role']\n\n // preserve the user role header to avoid invalidating preceding 'setRole' call.\n this.headers = userRole ? { 'x-hasura-role': userRole } : {}\n }\n\n 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 = 'subdomain' in params ? urlFromSubdomain(params, 'graphql') : 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) {\n const storageUrl = 'subdomain' in params ? urlFromSubdomain(params, 'storage') : 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 *\n * @example\n * ```ts\n * // Create a new Nhost client from subdomain and region.\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc).\n * const nhost = new NhostClient({\n * authUrl: \"my-auth-service-url\",\n * storageUrl: \"my-storage-service-url\",\n * graphqlUrl: \"my-graphql-service-url\",\n * functionsUrl: \"my-functions-service-url\",\n * });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client for local development.\n * const nhost = new NhostClient({ subdomain: \"local\" });\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 return\n }\n\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\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 /**\n * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls.\n * Underneath, this method sets the `x-hasura-role` header on the graphql, storage,\n * and functions clients.\n *\n * ```ts\n * nhost.graphql.setHeaders({ 'x-hasura-role': role })\n * nhost.storage.setHeaders({ 'x-hasura-role': role })\n * nhost.functions.setHeaders({ 'x-hasura-role': role })\n * ```\n *\n * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.setRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role\n */\n setRole(role: string) {\n this.graphql.setHeaders({ 'x-hasura-role': role })\n this.storage.setHeaders({ 'x-hasura-role': role })\n this.functions.setHeaders({ 'x-hasura-role': role })\n }\n\n /**\n * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls.\n * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients.\n *\n * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.unsetRole()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role\n */\n unsetRole() {\n this.graphql.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.graphql.getHeaders()))\n this.storage.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.storage.getHeaders()))\n this.functions.setHeaders(\n (({ 'x-hasura-role': _, ...rest }) => rest)(this.functions.getHeaders())\n )\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","subdomainAndRegion","service","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","buildUrl","baseUrl","path","urlPath","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","fullUrl","result","fetch","message","_a","data","_b","e","error","accessToken","userRole","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","event","session","newValue","role","_","rest"],"mappings":";;;;;;AAGO,MAAMA,IACX;AASc,SAAAC,EACdC,GACAC,GACQ;AACF,QAAA,EAAE,WAAAC,GAAW,QAAAC,EAAA,IAAWH;AAE9B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,4BAA4B;AAIxC,QAAAE,IAA0BF,EAAU,MAAMJ,CAAe;AAC/D,MAAIM,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,GAAU,MAAAC,GAAM,MAAAC,MAASH,EAAwB,QAEnDI,IAAaC,EAAgBR,CAAO;AAC1C,WAAIO,MAIAF,MAAS,eACH,QAAA;AAAA,MACN;AAAA,IACF,GAEO,GAAGD,KAAY,MAAM,gBAAgBE,KAAQ,IAAI,OAAON,CAAO,MAGjEM,IACH,GAAGF,KAAY,OAAO,YAAYJ,CAAO,oBAAoBM,CAAI,QACjE,GAAGF,KAAY,OAAO,YAAYJ,CAAO;AAAA,EAAA;AAG/C,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,mEAAmE;AAGrF,SAAO,WAAWD,CAAS,IAAID,CAAO,IAAIE,CAAM;AAClD;AAMA,SAASO,IAAqB;AAC5B,SAAO,OAAO,UAAW;AAC3B;AAMA,SAASC,IAAyB;AACzB,SAAA,OAAO,WAAY,eAAe,QAAQ;AACnD;AAQA,SAASF,EAAgBR,GAAiB;AACxC,SAAIS,EAAU,KAAK,CAACC,MACX,OAGF,QAAQ,IAAI,SAASV,EAAQ,YAAA,CAAa,MAAM;AACzD;AASgB,SAAAW,EAASC,GAAiBC,GAAc;AAEtD,QAAMC,IADkBD,EAAK,WAAW,GAAG,IACTA,IAAO,IAAIA,CAAI;AACjD,SAAOD,IAAUE;AACnB;ACtFO,SAASC,EAA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,EAAA;AAAA,EAGlB,IAAI,cAAkC;AACpC,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,IAAI,YAAYK,GAA8B;AAC5C,SAAK,eAAeA,GACf,KAAA,QAAQ,eAAeA,CAAQ;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BtC,QAAQC,GAAc;AACpB,SAAK,QAAQ,WAAW,EAAE,iBAAiBA,GAAM,GACjD,KAAK,QAAQ,WAAW,EAAE,iBAAiBA,GAAM,GACjD,KAAK,UAAU,WAAW,EAAE,iBAAiBA,GAAM;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBrD,YAAY;AACV,SAAK,QAAQ,YAAY,CAAC,EAAE,iBAAiBC,GAAG,GAAGC,EAAK,MAAMA,GAAM,KAAK,QAAQ,WAAY,CAAA,CAAC,GAC9F,KAAK,QAAQ,YAAY,CAAC,EAAE,iBAAiBD,GAAG,GAAGC,EAAK,MAAMA,GAAM,KAAK,QAAQ,WAAY,CAAA,CAAC,GAC9F,KAAK,UAAU;AAAA,OACZ,CAAC,EAAE,iBAAiBD,GAAG,GAAGC,EAAK,MAAMA,GAAM,KAAK,UAAU,WAAY,CAAA;AAAA,IACzE;AAAA,EAAA;AAEJ;"}
@@ -1,20 +0,0 @@
1
- import { NhostClientConstructorParams } from './types';
2
-
3
- export declare const LOCALHOST_REGEX: RegExp;
4
- /**
5
- * \`subdomain\` and `region` should be used when running the Nhost platform
6
- *
7
- * @param subdomainAndRegion
8
- * @param service
9
- * @returns
10
- */
11
- export declare function urlFromSubdomain(subdomainAndRegion: Pick<NhostClientConstructorParams, 'region' | 'subdomain'>, service: string): string;
12
- /**
13
- * Combines a base URL and a path into a single URL string.
14
- *
15
- * @param baseUrl - The base URL to use.
16
- * @param path - The path to append to the base URL.
17
- * @returns The combined URL string.
18
- */
19
- export declare function buildUrl(baseUrl: string, path: string): string;
20
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAGtD,eAAO,MAAM,eAAe,QAC2D,CAAA;AAEvF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,kBAAkB,EAAE,IAAI,CAAC,4BAA4B,EAAE,QAAQ,GAAG,WAAW,CAAC,EAC9E,OAAO,EAAE,MAAM,GACd,MAAM,CAmCR;AAgCD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAIrD"}
@@ -1,57 +0,0 @@
1
- import { NhostAuthConstructorParams } from '@nhost/hasura-auth-js';
2
-
3
- export interface ErrorPayload<TMessage = any> {
4
- error: string;
5
- status: number;
6
- message: TMessage;
7
- }
8
- export interface ActionErrorState {
9
- /**
10
- * @return `true` if an error occurred
11
- * @depreacted use `!isSuccess` or `!!error` instead
12
- * */
13
- isError: boolean;
14
- /** Provides details about the error */
15
- error: ErrorPayload | null;
16
- }
17
- export interface ActionLoadingState {
18
- /**
19
- * @return `true` when the action is executing, `false` when it finished its execution.
20
- */
21
- isLoading: boolean;
22
- }
23
- export interface ActionSuccessState {
24
- /** Returns `true` if the action is successful. */
25
- isSuccess: boolean;
26
- }
27
- export type Subdomain = {
28
- /**
29
- * Project subdomain (e.g. `ieingiwnginwnfnegqwvdqwdwq`)
30
- * Use `localhost` during local development
31
- */
32
- subdomain: string;
33
- /**
34
- * Project region (e.g. `eu-central-1`)
35
- * Project region is not required during local development (when `subdomain` is `localhost`)
36
- */
37
- region?: string;
38
- /**
39
- * When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
40
- * for all requests to GraphQL, Storage, and Serverless Functions.
41
- */
42
- adminSecret?: string;
43
- };
44
- export type ServiceUrls = {
45
- authUrl?: string;
46
- graphqlUrl?: string;
47
- storageUrl?: string;
48
- functionsUrl?: string;
49
- };
50
- export interface NhostClientConstructorParams extends Partial<Subdomain>, Partial<ServiceUrls>, Omit<NhostAuthConstructorParams, 'url' | 'broadcastKey'> {
51
- /**
52
- * When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
53
- * for all requests to GraphQL, Storage, and Serverless Functions.
54
- */
55
- adminSecret?: string;
56
- }
57
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAGlE,MAAM,WAAW,YAAY,CAAC,QAAQ,GAAG,GAAG;IAC1C,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,QAAQ,CAAA;CAClB;AAGD,MAAM,WAAW,gBAAgB;IAC/B;;;SAGK;IACL,OAAO,EAAE,OAAO,CAAA;IAChB,uCAAuC;IACvC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;CAC3B;AAGD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,SAAS,EAAE,OAAO,CAAA;CACnB;AAGD,MAAM,WAAW,kBAAkB;IACjC,kDAAkD;IAClD,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,MAAM,SAAS,GAAG;IACtB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,WAAW,4BACf,SAAQ,OAAO,CAAC,SAAS,CAAC,EACxB,OAAO,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,0BAA0B,EAAE,KAAK,GAAG,cAAc,CAAC;IAC1D;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}