@nhost/nhost-js 4.5.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fetch-DjLYNzv8.cjs +2 -0
- package/dist/fetch-DjLYNzv8.cjs.map +1 -0
- package/dist/fetch-DsJJyobH.js +2 -0
- package/dist/fetch-DsJJyobH.js.map +1 -0
- package/dist/graphql-BEFThamT.cjs +2 -0
- package/dist/graphql-BEFThamT.cjs.map +1 -0
- package/dist/graphql-CTZ9QikM.js +2 -0
- package/dist/graphql-CTZ9QikM.js.map +1 -0
- package/dist/nhost-js/auth.cjs +2 -2
- package/dist/nhost-js/auth.cjs.map +1 -1
- package/dist/nhost-js/auth.js +2 -1279
- package/dist/nhost-js/auth.js.map +1 -1
- package/dist/nhost-js/fetch.cjs +1 -2
- package/dist/nhost-js/fetch.js +1 -30
- package/dist/nhost-js/functions.cjs +2 -2
- package/dist/nhost-js/functions.cjs.map +1 -1
- package/dist/nhost-js/functions.js +2 -50
- package/dist/nhost-js/functions.js.map +1 -1
- package/dist/nhost-js/graphql.cjs +1 -2
- package/dist/nhost-js/graphql.js +1 -53
- package/dist/nhost-js/session.cjs +1 -2
- package/dist/nhost-js/session.js +1 -242
- package/dist/nhost-js/storage.cjs +2 -2
- package/dist/nhost-js/storage.cjs.map +1 -1
- package/dist/nhost-js/storage.js +2 -342
- package/dist/nhost-js/storage.js.map +1 -1
- package/dist/nhost-js.cjs +2 -2
- package/dist/nhost-js.cjs.map +1 -1
- package/dist/nhost-js.js +2 -241
- package/dist/nhost-js.js.map +1 -1
- package/dist/nhost-js.umd.js +2 -2
- package/dist/nhost-js.umd.js.map +1 -1
- package/dist/refreshSession-BvZuC-Or.js +2 -0
- package/dist/refreshSession-BvZuC-Or.js.map +1 -0
- package/dist/refreshSession-ZW-JniXX.cjs +2 -0
- package/dist/refreshSession-ZW-JniXX.cjs.map +1 -0
- package/dist/session-oECsmiRB.js +2 -0
- package/dist/session-oECsmiRB.js.map +1 -0
- package/dist/session-r_9IPgQp.cjs +2 -0
- package/dist/session-r_9IPgQp.cjs.map +1 -0
- package/dist/src/auth/client.d.ts +352 -13
- package/dist/src/auth/client.d.ts.map +1 -1
- package/dist/src/auth/client.js +167 -0
- package/dist/src/auth/client.js.map +1 -1
- package/dist/src/auth/index.d.ts +1 -0
- package/dist/src/auth/index.d.ts.map +1 -1
- package/dist/src/auth/index.js +1 -0
- package/dist/src/auth/index.js.map +1 -1
- package/dist/src/auth/pkce.d.ts +22 -0
- package/dist/src/auth/pkce.d.ts.map +1 -0
- package/dist/src/auth/pkce.js +40 -0
- package/dist/src/auth/pkce.js.map +1 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts.map +1 -1
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js +1 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js.map +1 -1
- package/dist/src/graphql/client.d.ts +11 -0
- package/dist/src/graphql/client.d.ts.map +1 -1
- package/dist/src/graphql/client.js +31 -1
- package/dist/src/graphql/client.js.map +1 -1
- package/dist/src/graphql/index.d.ts +2 -1
- package/dist/src/graphql/index.d.ts.map +1 -1
- package/dist/src/graphql/index.js +1 -1
- package/dist/src/graphql/index.js.map +1 -1
- package/dist/src/storage/client.d.ts +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/dist/fetch-2PHmQBIJ.js +0 -61
- package/dist/fetch-2PHmQBIJ.js.map +0 -1
- package/dist/fetch-DWXwEnoe.cjs +0 -2
- package/dist/fetch-DWXwEnoe.cjs.map +0 -1
- package/dist/middlewareWithAdminSession-BeIk-9HO.js +0 -106
- package/dist/middlewareWithAdminSession-BeIk-9HO.js.map +0 -1
- package/dist/middlewareWithAdminSession-DDApoLkL.cjs +0 -2
- package/dist/middlewareWithAdminSession-DDApoLkL.cjs.map +0 -1
- package/dist/nhost-js/fetch.cjs.map +0 -1
- package/dist/nhost-js/fetch.js.map +0 -1
- package/dist/nhost-js/graphql.cjs.map +0 -1
- package/dist/nhost-js/graphql.js.map +0 -1
- package/dist/nhost-js/session.cjs.map +0 -1
- package/dist/nhost-js/session.js.map +0 -1
- package/dist/refreshSession-Bw715ZmX.cjs +0 -2
- package/dist/refreshSession-Bw715ZmX.cjs.map +0 -1
- package/dist/refreshSession-WwGlzgtM.js +0 -95
- package/dist/refreshSession-WwGlzgtM.js.map +0 -1
package/dist/nhost-js/fetch.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=fetch.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../fetch-DjLYNzv8.cjs");exports.FetchError=e.FetchError,exports.attachAccessTokenMiddleware=e.attachAccessTokenMiddleware,exports.createEnhancedFetch=e.createEnhancedFetch,exports.sessionRefreshMiddleware=e.sessionRefreshMiddleware,exports.updateSessionFromResponseMiddleware=e.updateSessionFromResponseMiddleware,exports.withAdminSessionMiddleware=e.withAdminSessionMiddleware,exports.withHeadersMiddleware=e.withHeadersMiddleware,exports.withRoleMiddleware=e.withRoleMiddleware;
|
package/dist/nhost-js/fetch.js
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { a, s, u, w } from "../middlewareWithAdminSession-BeIk-9HO.js";
|
|
3
|
-
const withHeadersMiddleware = (defaultHeaders) => (next) => async (url, options = {}) => {
|
|
4
|
-
const headers = new Headers(options.headers || {});
|
|
5
|
-
const defaults = new Headers(defaultHeaders);
|
|
6
|
-
defaults.forEach((value, key) => {
|
|
7
|
-
if (!headers.has(key)) {
|
|
8
|
-
headers.set(key, value);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
return next(url, { ...options, headers });
|
|
12
|
-
};
|
|
13
|
-
const withRoleMiddleware = (role) => (next) => async (url, requestOptions = {}) => {
|
|
14
|
-
const headers = new Headers(requestOptions.headers || {});
|
|
15
|
-
if (!headers.has("x-hasura-role")) {
|
|
16
|
-
headers.set("x-hasura-role", role);
|
|
17
|
-
}
|
|
18
|
-
return next(url, { ...requestOptions, headers });
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
F as FetchError,
|
|
22
|
-
a as attachAccessTokenMiddleware,
|
|
23
|
-
c as createEnhancedFetch,
|
|
24
|
-
s as sessionRefreshMiddleware,
|
|
25
|
-
u as updateSessionFromResponseMiddleware,
|
|
26
|
-
w as withAdminSessionMiddleware,
|
|
27
|
-
withHeadersMiddleware,
|
|
28
|
-
withRoleMiddleware
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=fetch.js.map
|
|
1
|
+
import{a as s,c as a,i as o,n as r,o as t,r as c,s as e,t as f}from"../fetch-DsJJyobH.js";export{e as FetchError,t as attachAccessTokenMiddleware,a as createEnhancedFetch,s as sessionRefreshMiddleware,o as updateSessionFromResponseMiddleware,c as withAdminSessionMiddleware,r as withHeadersMiddleware,f as withRoleMiddleware};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=functions.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../fetch-DjLYNzv8.cjs");exports.createAPIClient=(e,a=[])=>{let n=t.createEnhancedFetch(a);const s=async(a,s)=>{const o=await n(`${e}${a}`,s);let r;if(r=o.headers.get("content-type")?.includes("application/json")?await o.json():o.headers.get("content-type")?.startsWith("text/")?await o.text():await o.blob(),!o.ok)throw new t.FetchError(r,o.status,o.headers);return{status:o.status,body:r,headers:o.headers}};return{baseURL:e,fetch:s,post:async(t,e,a={})=>s(t,{...a,method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a.headers},body:e?JSON.stringify(e):void 0}),pushChainFunction:e=>{a.push(e),n=t.createEnhancedFetch(a)}}};
|
|
2
|
+
//# sourceMappingURL=functions.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.cjs","sources":["../../src/functions/client.ts"],"sourcesContent":["/**\n * Functions client for the Nhost JavaScript SDK.\n *\n * This module provides functionality for executing serverless function calls\n * against Nhost serverless functions.\n */\n\nimport {\n type ChainFunction,\n createEnhancedFetch,\n FetchError,\n type FetchResponse,\n} from '../fetch';\n\n/**\n * Functions client interface providing methods for executing serverless function calls\n */\nexport interface Client {\n baseURL: string;\n\n /** Add a middleware function to the fetch chain\n * @param chainFunction - The middleware function to add\n */\n pushChainFunction(chainFunction: ChainFunction): void;\n\n /**\n * Execute a request to a serverless function\n * The response body will be automatically parsed based on the content type into the following types:\n * - Object if the response is application/json\n * - string text string if the response is text/*\n * - Blob if the response is any other type\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata.\n */\n fetch<T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n post<T = unknown>(\n path: string,\n body?: unknown,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n}\n\n/**\n * Creates a Functions API client for interacting with serverless functions.\n *\n * This client provides methods for executing requests against serverless functions,\n * with support for middleware functions to handle authentication, error handling,\n * and other cross-cutting concerns.\n *\n * @param baseURL - Base URL for the functions endpoint\n * @param chainFunctions - Array of middleware functions for the fetch chain\n * @returns Functions client with fetch method\n */\nexport const createAPIClient = (\n baseURL: string,\n chainFunctions: ChainFunction[] = [],\n): Client => {\n let enhancedFetch = createEnhancedFetch(chainFunctions);\n\n const pushChainFunction = (chainFunction: ChainFunction) => {\n chainFunctions.push(chainFunction);\n enhancedFetch = createEnhancedFetch(chainFunctions);\n };\n\n /**\n * Executes a request to a serverless function and processes the response\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata. Body will be either\n * - JSON object if the response is application/json\n - text string if the response is text/*\n - Blob if the response is any other type\n */\n const fetch = async <T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T | string | Blob>> => {\n const resp = await enhancedFetch(`${baseURL}${path}`, options);\n\n let body: T | string | Blob;\n // Process response based on content type\n if (resp.headers.get('content-type')?.includes('application/json')) {\n body = (await resp.json()) as T;\n } else if (resp.headers.get('content-type')?.startsWith('text/')) {\n body = await resp.text();\n } else {\n body = await resp.blob();\n }\n\n // Throw error for non-OK responses\n if (!resp.ok) {\n throw new FetchError(body, resp.status, resp.headers);\n }\n\n return {\n status: resp.status,\n body,\n headers: resp.headers,\n };\n };\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n const post = async <T = unknown>(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n ): Promise<FetchResponse<T | string | Blob>> => {\n // Ensure the method is POST and set the body\n const requestOptions: RequestInit = {\n ...options,\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n };\n\n return fetch<T>(path, requestOptions);\n };\n\n // Return client object with the fetch method\n return {\n baseURL,\n fetch,\n post,\n pushChainFunction,\n } as Client;\n};\n"],"
|
|
1
|
+
{"version":3,"file":"functions.cjs","names":[],"sources":["../../src/functions/client.ts"],"sourcesContent":["/**\n * Functions client for the Nhost JavaScript SDK.\n *\n * This module provides functionality for executing serverless function calls\n * against Nhost serverless functions.\n */\n\nimport {\n type ChainFunction,\n createEnhancedFetch,\n FetchError,\n type FetchResponse,\n} from '../fetch';\n\n/**\n * Functions client interface providing methods for executing serverless function calls\n */\nexport interface Client {\n baseURL: string;\n\n /** Add a middleware function to the fetch chain\n * @param chainFunction - The middleware function to add\n */\n pushChainFunction(chainFunction: ChainFunction): void;\n\n /**\n * Execute a request to a serverless function\n * The response body will be automatically parsed based on the content type into the following types:\n * - Object if the response is application/json\n * - string text string if the response is text/*\n * - Blob if the response is any other type\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata.\n */\n fetch<T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n post<T = unknown>(\n path: string,\n body?: unknown,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n}\n\n/**\n * Creates a Functions API client for interacting with serverless functions.\n *\n * This client provides methods for executing requests against serverless functions,\n * with support for middleware functions to handle authentication, error handling,\n * and other cross-cutting concerns.\n *\n * @param baseURL - Base URL for the functions endpoint\n * @param chainFunctions - Array of middleware functions for the fetch chain\n * @returns Functions client with fetch method\n */\nexport const createAPIClient = (\n baseURL: string,\n chainFunctions: ChainFunction[] = [],\n): Client => {\n let enhancedFetch = createEnhancedFetch(chainFunctions);\n\n const pushChainFunction = (chainFunction: ChainFunction) => {\n chainFunctions.push(chainFunction);\n enhancedFetch = createEnhancedFetch(chainFunctions);\n };\n\n /**\n * Executes a request to a serverless function and processes the response\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata. Body will be either\n * - JSON object if the response is application/json\n - text string if the response is text/*\n - Blob if the response is any other type\n */\n const fetch = async <T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T | string | Blob>> => {\n const resp = await enhancedFetch(`${baseURL}${path}`, options);\n\n let body: T | string | Blob;\n // Process response based on content type\n if (resp.headers.get('content-type')?.includes('application/json')) {\n body = (await resp.json()) as T;\n } else if (resp.headers.get('content-type')?.startsWith('text/')) {\n body = await resp.text();\n } else {\n body = await resp.blob();\n }\n\n // Throw error for non-OK responses\n if (!resp.ok) {\n throw new FetchError(body, resp.status, resp.headers);\n }\n\n return {\n status: resp.status,\n body,\n headers: resp.headers,\n };\n };\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n const post = async <T = unknown>(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n ): Promise<FetchResponse<T | string | Blob>> => {\n // Ensure the method is POST and set the body\n const requestOptions: RequestInit = {\n ...options,\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n };\n\n return fetch<T>(path, requestOptions);\n };\n\n // Return client object with the fetch method\n return {\n baseURL,\n fetch,\n post,\n pushChainFunction,\n } as Client;\n};\n"],"mappings":"oIAyEa,CACX,EACA,EAAkC,MAElC,IAAI,EAAgB,EAAA,oBAAoB,GAExC,MAeM,EAAQ,MACZ,EACA,KAEA,MAAM,QAAa,EAAc,GAAG,IAAU,IAAQ,GAEtD,IAAI,EAWJ,GARE,EADE,EAAK,QAAQ,IAAI,iBAAiB,SAAS,0BAC/B,EAAK,OACV,EAAK,QAAQ,IAAI,iBAAiB,WAAW,eACzC,EAAK,aAEL,EAAK,QAIf,EAAK,GACR,MAAM,IAAI,EAAA,WAAW,EAAM,EAAK,OAAQ,EAAK,SAG/C,MAAO,CACL,OAAQ,EAAK,OACb,OACA,QAAS,EAAK,QACf,EAsCH,MAAO,CACL,UACA,QACA,KAxBW,MACX,EACA,EACA,EAAuB,CAAA,IAchB,EAAS,EAXoB,IAC/B,EACH,OAAQ,OACR,QAAS,CACP,OAAQ,mBACR,eAAgB,sBACb,EAAQ,SAEb,KAAM,EAAO,KAAK,UAAU,QAAQ,IAWtC,kBAlFyB,IACzB,EAAe,KAAK,GACpB,EAAgB,EAAA,oBAAoB,EAAe,EAiFpD"}
|
|
@@ -1,50 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
let enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
4
|
-
const pushChainFunction = (chainFunction) => {
|
|
5
|
-
chainFunctions.push(chainFunction);
|
|
6
|
-
enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
7
|
-
};
|
|
8
|
-
const fetch = async (path, options) => {
|
|
9
|
-
const resp = await enhancedFetch(`${baseURL}${path}`, options);
|
|
10
|
-
let body;
|
|
11
|
-
if (resp.headers.get("content-type")?.includes("application/json")) {
|
|
12
|
-
body = await resp.json();
|
|
13
|
-
} else if (resp.headers.get("content-type")?.startsWith("text/")) {
|
|
14
|
-
body = await resp.text();
|
|
15
|
-
} else {
|
|
16
|
-
body = await resp.blob();
|
|
17
|
-
}
|
|
18
|
-
if (!resp.ok) {
|
|
19
|
-
throw new FetchError(body, resp.status, resp.headers);
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
status: resp.status,
|
|
23
|
-
body,
|
|
24
|
-
headers: resp.headers
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const post = async (path, body, options = {}) => {
|
|
28
|
-
const requestOptions = {
|
|
29
|
-
...options,
|
|
30
|
-
method: "POST",
|
|
31
|
-
headers: {
|
|
32
|
-
Accept: "application/json",
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
...options.headers
|
|
35
|
-
},
|
|
36
|
-
body: body ? JSON.stringify(body) : void 0
|
|
37
|
-
};
|
|
38
|
-
return fetch(path, requestOptions);
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
baseURL,
|
|
42
|
-
fetch,
|
|
43
|
-
post,
|
|
44
|
-
pushChainFunction
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
export {
|
|
48
|
-
createAPIClient
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=functions.js.map
|
|
1
|
+
import{c as t,s as e}from"../fetch-DsJJyobH.js";var s=(s,a=[])=>{let n=t(a);const o=async(t,a)=>{const o=await n(`${s}${t}`,a);let i;if(i=o.headers.get("content-type")?.includes("application/json")?await o.json():o.headers.get("content-type")?.startsWith("text/")?await o.text():await o.blob(),!o.ok)throw new e(i,o.status,o.headers);return{status:o.status,body:i,headers:o.headers}};return{baseURL:s,fetch:o,post:async(t,e,s={})=>o(t,{...s,method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...s.headers},body:e?JSON.stringify(e):void 0}),pushChainFunction:e=>{a.push(e),n=t(a)}}};export{s as createAPIClient};
|
|
2
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sources":["../../src/functions/client.ts"],"sourcesContent":["/**\n * Functions client for the Nhost JavaScript SDK.\n *\n * This module provides functionality for executing serverless function calls\n * against Nhost serverless functions.\n */\n\nimport {\n type ChainFunction,\n createEnhancedFetch,\n FetchError,\n type FetchResponse,\n} from '../fetch';\n\n/**\n * Functions client interface providing methods for executing serverless function calls\n */\nexport interface Client {\n baseURL: string;\n\n /** Add a middleware function to the fetch chain\n * @param chainFunction - The middleware function to add\n */\n pushChainFunction(chainFunction: ChainFunction): void;\n\n /**\n * Execute a request to a serverless function\n * The response body will be automatically parsed based on the content type into the following types:\n * - Object if the response is application/json\n * - string text string if the response is text/*\n * - Blob if the response is any other type\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata.\n */\n fetch<T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n post<T = unknown>(\n path: string,\n body?: unknown,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n}\n\n/**\n * Creates a Functions API client for interacting with serverless functions.\n *\n * This client provides methods for executing requests against serverless functions,\n * with support for middleware functions to handle authentication, error handling,\n * and other cross-cutting concerns.\n *\n * @param baseURL - Base URL for the functions endpoint\n * @param chainFunctions - Array of middleware functions for the fetch chain\n * @returns Functions client with fetch method\n */\nexport const createAPIClient = (\n baseURL: string,\n chainFunctions: ChainFunction[] = [],\n): Client => {\n let enhancedFetch = createEnhancedFetch(chainFunctions);\n\n const pushChainFunction = (chainFunction: ChainFunction) => {\n chainFunctions.push(chainFunction);\n enhancedFetch = createEnhancedFetch(chainFunctions);\n };\n\n /**\n * Executes a request to a serverless function and processes the response\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata. Body will be either\n * - JSON object if the response is application/json\n - text string if the response is text/*\n - Blob if the response is any other type\n */\n const fetch = async <T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T | string | Blob>> => {\n const resp = await enhancedFetch(`${baseURL}${path}`, options);\n\n let body: T | string | Blob;\n // Process response based on content type\n if (resp.headers.get('content-type')?.includes('application/json')) {\n body = (await resp.json()) as T;\n } else if (resp.headers.get('content-type')?.startsWith('text/')) {\n body = await resp.text();\n } else {\n body = await resp.blob();\n }\n\n // Throw error for non-OK responses\n if (!resp.ok) {\n throw new FetchError(body, resp.status, resp.headers);\n }\n\n return {\n status: resp.status,\n body,\n headers: resp.headers,\n };\n };\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n const post = async <T = unknown>(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n ): Promise<FetchResponse<T | string | Blob>> => {\n // Ensure the method is POST and set the body\n const requestOptions: RequestInit = {\n ...options,\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n };\n\n return fetch<T>(path, requestOptions);\n };\n\n // Return client object with the fetch method\n return {\n baseURL,\n fetch,\n post,\n pushChainFunction,\n } as Client;\n};\n"],"
|
|
1
|
+
{"version":3,"file":"functions.js","names":[],"sources":["../../src/functions/client.ts"],"sourcesContent":["/**\n * Functions client for the Nhost JavaScript SDK.\n *\n * This module provides functionality for executing serverless function calls\n * against Nhost serverless functions.\n */\n\nimport {\n type ChainFunction,\n createEnhancedFetch,\n FetchError,\n type FetchResponse,\n} from '../fetch';\n\n/**\n * Functions client interface providing methods for executing serverless function calls\n */\nexport interface Client {\n baseURL: string;\n\n /** Add a middleware function to the fetch chain\n * @param chainFunction - The middleware function to add\n */\n pushChainFunction(chainFunction: ChainFunction): void;\n\n /**\n * Execute a request to a serverless function\n * The response body will be automatically parsed based on the content type into the following types:\n * - Object if the response is application/json\n * - string text string if the response is text/*\n * - Blob if the response is any other type\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata.\n */\n fetch<T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n post<T = unknown>(\n path: string,\n body?: unknown,\n options?: RequestInit,\n ): Promise<FetchResponse<T>>;\n}\n\n/**\n * Creates a Functions API client for interacting with serverless functions.\n *\n * This client provides methods for executing requests against serverless functions,\n * with support for middleware functions to handle authentication, error handling,\n * and other cross-cutting concerns.\n *\n * @param baseURL - Base URL for the functions endpoint\n * @param chainFunctions - Array of middleware functions for the fetch chain\n * @returns Functions client with fetch method\n */\nexport const createAPIClient = (\n baseURL: string,\n chainFunctions: ChainFunction[] = [],\n): Client => {\n let enhancedFetch = createEnhancedFetch(chainFunctions);\n\n const pushChainFunction = (chainFunction: ChainFunction) => {\n chainFunctions.push(chainFunction);\n enhancedFetch = createEnhancedFetch(chainFunctions);\n };\n\n /**\n * Executes a request to a serverless function and processes the response\n *\n * @param path - The path to the serverless function\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata. Body will be either\n * - JSON object if the response is application/json\n - text string if the response is text/*\n - Blob if the response is any other type\n */\n const fetch = async <T = unknown>(\n path: string,\n options?: RequestInit,\n ): Promise<FetchResponse<T | string | Blob>> => {\n const resp = await enhancedFetch(`${baseURL}${path}`, options);\n\n let body: T | string | Blob;\n // Process response based on content type\n if (resp.headers.get('content-type')?.includes('application/json')) {\n body = (await resp.json()) as T;\n } else if (resp.headers.get('content-type')?.startsWith('text/')) {\n body = await resp.text();\n } else {\n body = await resp.blob();\n }\n\n // Throw error for non-OK responses\n if (!resp.ok) {\n throw new FetchError(body, resp.status, resp.headers);\n }\n\n return {\n status: resp.status,\n body,\n headers: resp.headers,\n };\n };\n\n /**\n * Executes a POST request to a serverless function with a JSON body\n *\n * This is a convenience method assuming the request is a POST with JSON body\n * setting the `Content-Type` and 'Accept' headers to `application/json` and\n * automatically stringifying the body.\n *\n * For a more generic request, use the `fetch` method instead.\n *\n * @param path - The path to the serverless function\n * @param body - The JSON body to send in the request\n * @param options - Additional fetch options to apply to the request\n * @returns Promise with the function response and metadata\n */\n const post = async <T = unknown>(\n path: string,\n body?: unknown,\n options: RequestInit = {},\n ): Promise<FetchResponse<T | string | Blob>> => {\n // Ensure the method is POST and set the body\n const requestOptions: RequestInit = {\n ...options,\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n };\n\n return fetch<T>(path, requestOptions);\n };\n\n // Return client object with the fetch method\n return {\n baseURL,\n fetch,\n post,\n pushChainFunction,\n } as Client;\n};\n"],"mappings":"gDAyEA,IAAa,EAAA,CACX,EACA,EAAkC,MAElC,IAAI,EAAgB,EAAoB,GAExC,MAeM,EAAQ,MACZ,EACA,KAEA,MAAM,QAAa,EAAc,GAAG,IAAU,IAAQ,GAEtD,IAAI,EAWJ,GARE,EADE,EAAK,QAAQ,IAAI,iBAAiB,SAAS,0BAC/B,EAAK,OACV,EAAK,QAAQ,IAAI,iBAAiB,WAAW,eACzC,EAAK,aAEL,EAAK,QAIf,EAAK,GACR,MAAM,IAAI,EAAW,EAAM,EAAK,OAAQ,EAAK,SAG/C,MAAO,CACL,OAAQ,EAAK,OACb,OACA,QAAS,EAAK,QACf,EAsCH,MAAO,CACL,UACA,QACA,KAxBW,MACX,EACA,EACA,EAAuB,CAAA,IAchB,EAAS,EAXoB,IAC/B,EACH,OAAQ,OACR,QAAS,CACP,OAAQ,mBACR,eAAgB,sBACb,EAAQ,SAEb,KAAM,EAAO,KAAK,UAAU,QAAQ,IAWtC,kBAlFyB,IACzB,EAAe,KAAK,GACpB,EAAgB,EAAoB,EAAe,EAiFpD"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=graphql.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../graphql-BEFThamT.cjs");exports.createAPIClient=e.createAPIClient;
|
package/dist/nhost-js/graphql.js
CHANGED
|
@@ -1,53 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
const createAPIClient = (url, chainFunctions = []) => {
|
|
3
|
-
let enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
4
|
-
const pushChainFunction = (chainFunction) => {
|
|
5
|
-
chainFunctions.push(chainFunction);
|
|
6
|
-
enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
7
|
-
};
|
|
8
|
-
const executeOperation = async (request2, options) => {
|
|
9
|
-
const response = await enhancedFetch(`${url}`, {
|
|
10
|
-
method: "POST",
|
|
11
|
-
headers: {
|
|
12
|
-
"Content-Type": "application/json"
|
|
13
|
-
},
|
|
14
|
-
body: JSON.stringify(request2),
|
|
15
|
-
...options
|
|
16
|
-
});
|
|
17
|
-
const body = await response.text();
|
|
18
|
-
const data = body ? JSON.parse(body) : {};
|
|
19
|
-
const resp = {
|
|
20
|
-
body: data,
|
|
21
|
-
status: response.status,
|
|
22
|
-
headers: response.headers
|
|
23
|
-
};
|
|
24
|
-
if (data.errors) {
|
|
25
|
-
throw new FetchError(data, response.status, response.headers);
|
|
26
|
-
}
|
|
27
|
-
return resp;
|
|
28
|
-
};
|
|
29
|
-
function request(requestOrDocument, variablesOrOptions, options) {
|
|
30
|
-
if (typeof requestOrDocument === "object" && "kind" in requestOrDocument) {
|
|
31
|
-
const definition = requestOrDocument.definitions[0];
|
|
32
|
-
const request2 = {
|
|
33
|
-
query: requestOrDocument.loc?.source.body || "",
|
|
34
|
-
variables: variablesOrOptions,
|
|
35
|
-
operationName: definition && "name" in definition ? definition.name?.value : void 0
|
|
36
|
-
};
|
|
37
|
-
return executeOperation(request2, options);
|
|
38
|
-
} else {
|
|
39
|
-
const request2 = requestOrDocument;
|
|
40
|
-
const requestOptions = variablesOrOptions;
|
|
41
|
-
return executeOperation(request2, requestOptions);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
request,
|
|
46
|
-
url,
|
|
47
|
-
pushChainFunction
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
export {
|
|
51
|
-
createAPIClient
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=graphql.js.map
|
|
1
|
+
import{t as r}from"../graphql-CTZ9QikM.js";export{r as createAPIClient};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=session.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../refreshSession-ZW-JniXX.cjs"),o=require("../session-r_9IPgQp.cjs");exports.CookieStorage=o.CookieStorage,exports.DEFAULT_SESSION_KEY=o.DEFAULT_SESSION_KEY,exports.LocalStorage=o.LocalStorage,exports.MemoryStorage=o.MemoryStorage,exports.SessionStorage=o.SessionStorage,exports.detectStorage=o.detectStorage,exports.refreshSession=e.refreshSession;
|
package/dist/nhost-js/session.js
CHANGED
|
@@ -1,242 +1 @@
|
|
|
1
|
-
import { r }
|
|
2
|
-
const decodeBase64Url = (input) => {
|
|
3
|
-
let base64 = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
4
|
-
const pad = base64.length % 4;
|
|
5
|
-
if (pad) {
|
|
6
|
-
base64 += "=".repeat(4 - pad);
|
|
7
|
-
}
|
|
8
|
-
const binaryString = atob(base64);
|
|
9
|
-
const bytes = Uint8Array.from(binaryString, (c) => c.charCodeAt(0));
|
|
10
|
-
return new TextDecoder().decode(bytes);
|
|
11
|
-
};
|
|
12
|
-
const decodeUserSession = (accessToken) => {
|
|
13
|
-
const s = accessToken.split(".");
|
|
14
|
-
if (s.length !== 3 || !s[1]) {
|
|
15
|
-
throw new Error("Invalid access token format");
|
|
16
|
-
}
|
|
17
|
-
const decodedToken = JSON.parse(decodeBase64Url(s[1]));
|
|
18
|
-
const iat = typeof decodedToken["iat"] === "number" ? decodedToken["iat"] * 1e3 : void 0;
|
|
19
|
-
const exp = typeof decodedToken["exp"] === "number" ? decodedToken["exp"] * 1e3 : void 0;
|
|
20
|
-
const hasuraClaims = decodedToken["https://hasura.io/jwt/claims"];
|
|
21
|
-
const processedClaims = hasuraClaims ? Object.entries(hasuraClaims).reduce(
|
|
22
|
-
(acc, [key, value]) => {
|
|
23
|
-
if (typeof value === "string" && isPostgresArray(value)) {
|
|
24
|
-
acc[key] = parsePostgresArray(value);
|
|
25
|
-
} else {
|
|
26
|
-
acc[key] = value;
|
|
27
|
-
}
|
|
28
|
-
return acc;
|
|
29
|
-
},
|
|
30
|
-
{}
|
|
31
|
-
) : void 0;
|
|
32
|
-
return {
|
|
33
|
-
...decodedToken,
|
|
34
|
-
iat,
|
|
35
|
-
exp,
|
|
36
|
-
"https://hasura.io/jwt/claims": processedClaims
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
const isPostgresArray = (value) => {
|
|
40
|
-
return value.startsWith("{") && value.endsWith("}");
|
|
41
|
-
};
|
|
42
|
-
const parsePostgresArray = (value) => {
|
|
43
|
-
if (!value || value === "{}") return [];
|
|
44
|
-
return value.slice(1, -1).split(",").map((item) => item.trim().replace(/^"(.*)"$/, "$1"));
|
|
45
|
-
};
|
|
46
|
-
const DEFAULT_SESSION_KEY = "nhostSession";
|
|
47
|
-
class LocalStorage {
|
|
48
|
-
storageKey;
|
|
49
|
-
/**
|
|
50
|
-
* Creates a new LocalStorage instance
|
|
51
|
-
* @param options - Configuration options
|
|
52
|
-
* @param options.storageKey - The key to use in localStorage (defaults to "nhostSession")
|
|
53
|
-
*/
|
|
54
|
-
constructor(options) {
|
|
55
|
-
this.storageKey = options?.storageKey || DEFAULT_SESSION_KEY;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Gets the session from localStorage
|
|
59
|
-
* @returns The stored session or null if not found
|
|
60
|
-
*/
|
|
61
|
-
get() {
|
|
62
|
-
try {
|
|
63
|
-
const value = window.localStorage.getItem(this.storageKey);
|
|
64
|
-
return value ? JSON.parse(value) : null;
|
|
65
|
-
} catch {
|
|
66
|
-
this.remove();
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Sets the session in localStorage
|
|
72
|
-
* @param value - The session to store
|
|
73
|
-
*/
|
|
74
|
-
set(value) {
|
|
75
|
-
window.localStorage.setItem(this.storageKey, JSON.stringify(value));
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Removes the session from localStorage
|
|
79
|
-
*/
|
|
80
|
-
remove() {
|
|
81
|
-
window.localStorage.removeItem(this.storageKey);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
class MemoryStorage {
|
|
85
|
-
session = null;
|
|
86
|
-
/**
|
|
87
|
-
* Gets the session from memory
|
|
88
|
-
* @returns The stored session or null if not set
|
|
89
|
-
*/
|
|
90
|
-
get() {
|
|
91
|
-
return this.session;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Sets the session in memory
|
|
95
|
-
* @param value - The session to store
|
|
96
|
-
*/
|
|
97
|
-
set(value) {
|
|
98
|
-
this.session = value;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Clears the session from memory
|
|
102
|
-
*/
|
|
103
|
-
remove() {
|
|
104
|
-
this.session = null;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
class CookieStorage {
|
|
108
|
-
cookieName;
|
|
109
|
-
expirationDays;
|
|
110
|
-
secure;
|
|
111
|
-
sameSite;
|
|
112
|
-
/**
|
|
113
|
-
* Creates a new CookieStorage instance
|
|
114
|
-
* @param options - Configuration options
|
|
115
|
-
* @param options.cookieName - Name of the cookie to use (defaults to "nhostSession")
|
|
116
|
-
* @param options.expirationDays - Number of days until the cookie expires (defaults to 30)
|
|
117
|
-
* @param options.secure - Whether to set the Secure flag on the cookie (defaults to true)
|
|
118
|
-
* @param options.sameSite - SameSite policy for the cookie (defaults to "lax")
|
|
119
|
-
*/
|
|
120
|
-
constructor(options) {
|
|
121
|
-
this.cookieName = options?.cookieName || DEFAULT_SESSION_KEY;
|
|
122
|
-
this.expirationDays = options?.expirationDays ?? 30;
|
|
123
|
-
this.secure = options?.secure ?? true;
|
|
124
|
-
this.sameSite = options?.sameSite || "lax";
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Gets the session from cookies
|
|
128
|
-
* @returns The stored session or null if not found
|
|
129
|
-
*/
|
|
130
|
-
get() {
|
|
131
|
-
const cookies = document.cookie.split(";");
|
|
132
|
-
for (const cookie of cookies) {
|
|
133
|
-
const [name, value] = cookie.trim().split("=");
|
|
134
|
-
if (name === this.cookieName) {
|
|
135
|
-
try {
|
|
136
|
-
return JSON.parse(decodeURIComponent(value || ""));
|
|
137
|
-
} catch {
|
|
138
|
-
this.remove();
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Sets the session in a cookie
|
|
147
|
-
* @param value - The session to store
|
|
148
|
-
*/
|
|
149
|
-
set(value) {
|
|
150
|
-
const expires = /* @__PURE__ */ new Date();
|
|
151
|
-
expires.setTime(
|
|
152
|
-
expires.getTime() + this.expirationDays * 24 * 60 * 60 * 1e3
|
|
153
|
-
);
|
|
154
|
-
const cookieValue = encodeURIComponent(JSON.stringify(value));
|
|
155
|
-
const cookieString = `${this.cookieName}=${cookieValue}; expires=${expires.toUTCString()}; path=/; ${this.secure ? "secure; " : ""}SameSite=${this.sameSite}`;
|
|
156
|
-
document.cookie = cookieString;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Removes the session cookie
|
|
160
|
-
*/
|
|
161
|
-
remove() {
|
|
162
|
-
document.cookie = `${this.cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; ${this.secure ? "secure; " : ""}SameSite=${this.sameSite}`;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
class SessionStorage {
|
|
166
|
-
storage;
|
|
167
|
-
subscribers = /* @__PURE__ */ new Set();
|
|
168
|
-
/**
|
|
169
|
-
* Creates a new SessionStorage instance
|
|
170
|
-
* @param storage - The underlying storage implementation to use
|
|
171
|
-
*/
|
|
172
|
-
constructor(storage) {
|
|
173
|
-
this.storage = storage;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Gets the session from the underlying storage
|
|
177
|
-
* @returns The stored session or null if not found
|
|
178
|
-
*/
|
|
179
|
-
get() {
|
|
180
|
-
return this.storage.get();
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Sets the session in the underlying storage and notifies subscribers
|
|
184
|
-
* @param value - The session to store
|
|
185
|
-
*/
|
|
186
|
-
set(value) {
|
|
187
|
-
const decodedToken = decodeUserSession(value.accessToken);
|
|
188
|
-
const decodedSession = {
|
|
189
|
-
...value,
|
|
190
|
-
decodedToken
|
|
191
|
-
};
|
|
192
|
-
this.storage.set(decodedSession);
|
|
193
|
-
this.notifySubscribers(decodedSession);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Removes the session from the underlying storage and notifies subscribers
|
|
197
|
-
*/
|
|
198
|
-
remove() {
|
|
199
|
-
this.storage.remove();
|
|
200
|
-
this.notifySubscribers(null);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Subscribe to session changes
|
|
204
|
-
* @param callback - Function that will be called when the session changes
|
|
205
|
-
* @returns An unsubscribe function to remove this subscription
|
|
206
|
-
*/
|
|
207
|
-
onChange(callback) {
|
|
208
|
-
this.subscribers.add(callback);
|
|
209
|
-
return () => {
|
|
210
|
-
this.subscribers.delete(callback);
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Notify all subscribers of a session change
|
|
215
|
-
* @param session - The new session value or null if removed
|
|
216
|
-
*/
|
|
217
|
-
notifySubscribers(session) {
|
|
218
|
-
for (const subscriber of this.subscribers) {
|
|
219
|
-
try {
|
|
220
|
-
subscriber(session);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error("Error notifying subscriber:", error);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const detectStorage = () => {
|
|
228
|
-
if (typeof window !== "undefined") {
|
|
229
|
-
return new LocalStorage();
|
|
230
|
-
}
|
|
231
|
-
return new MemoryStorage();
|
|
232
|
-
};
|
|
233
|
-
export {
|
|
234
|
-
CookieStorage,
|
|
235
|
-
DEFAULT_SESSION_KEY,
|
|
236
|
-
LocalStorage,
|
|
237
|
-
MemoryStorage,
|
|
238
|
-
SessionStorage,
|
|
239
|
-
detectStorage,
|
|
240
|
-
r as refreshSession
|
|
241
|
-
};
|
|
242
|
-
//# sourceMappingURL=session.js.map
|
|
1
|
+
import{t as s}from"../refreshSession-BvZuC-Or.js";import{a,i as o,n as r,o as e,r as i,t}from"../session-oECsmiRB.js";export{i as CookieStorage,o as DEFAULT_SESSION_KEY,a as LocalStorage,e as MemoryStorage,t as SessionStorage,r as detectStorage,s as refreshSession};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=storage.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../fetch-DjLYNzv8.cjs");exports.createAPIClient=(e,s=[])=>{let a=t.createEnhancedFetch(s);return{baseURL:e,pushChainFunction:e=>{s.push(e),a=t.createEnhancedFetch(s)},uploadFiles:async(s,r)=>{const n=`${e}/files`,d=new FormData,o="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==s["bucket-id"]&&d.append("bucket-id",s["bucket-id"]),void 0!==s["metadata[]"]&&s["metadata[]"].forEach((t=>{o?d.append("metadata[]",{string:JSON.stringify(t),type:"application/json",name:""}):d.append("metadata[]",new Blob([JSON.stringify(t)],{type:"application/json"}),"")})),void 0!==s["file[]"]&&s["file[]"].forEach((t=>{d.append("file[]",t)}));const i=await a(n,{...r,method:"POST",body:d});if(i.status>=300){const e=[412].includes(i.status)?null:await i.text();throw new t.FetchError(e?JSON.parse(e):{},i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},deleteFile:async(s,r)=>{const n=`${e}/files/${s}`,d=await a(n,{...r,method:"DELETE",headers:{...r?.headers}});if(d.status>=300){const e=[412].includes(d.status)?null:await d.text();throw new t.FetchError(e?JSON.parse(e):{},d.status,d.headers)}return{body:void 0,status:d.status,headers:d.headers}},getFile:async(s,r,n)=>{const d=r&&Object.entries(r).flatMap((([t,e])=>{const s=Array.isArray(e)?e.join(","):"object"==typeof e&&null!==e?JSON.stringify(e):String(e);return[`${t}=${encodeURIComponent(s)}`]})).join("&"),o=d?`${e}/files/${s}?${d}`:`${e}/files/${s}`,i=await a(o,{...n,method:"GET",headers:{...n?.headers}});if(i.status>=300){const e=[412].includes(i.status)?null:await i.text();throw new t.FetchError(e?JSON.parse(e):{},i.status,i.headers)}return{body:await i.blob(),status:i.status,headers:i.headers}},getFileMetadataHeaders:async(s,r,n)=>{const d=r&&Object.entries(r).flatMap((([t,e])=>{const s=Array.isArray(e)?e.join(","):"object"==typeof e&&null!==e?JSON.stringify(e):String(e);return[`${t}=${encodeURIComponent(s)}`]})).join("&"),o=d?`${e}/files/${s}?${d}`:`${e}/files/${s}`,i=await a(o,{...n,method:"HEAD",headers:{...n?.headers}});if(i.status>=300){const e=[412].includes(i.status)?null:await i.text();throw new t.FetchError(e?JSON.parse(e):{},i.status,i.headers)}return{body:void 0,status:i.status,headers:i.headers}},replaceFile:async(s,r,n)=>{const d=`${e}/files/${s}`,o=new FormData,i="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==r.metadata&&(i?o.append("metadata",{string:JSON.stringify(r.metadata),type:"application/json",name:""}):o.append("metadata",new Blob([JSON.stringify(r.metadata)],{type:"application/json"}),"")),void 0!==r.file&&o.append("file",r.file);const u=await a(d,{...n,method:"PUT",body:o});if(u.status>=300){const e=[412].includes(u.status)?null:await u.text();throw new t.FetchError(e?JSON.parse(e):{},u.status,u.headers)}const l=[204,205,304].includes(u.status)?null:await u.text();return{body:l?JSON.parse(l):{},status:u.status,headers:u.headers}},getFilePresignedURL:async(s,r)=>{const n=`${e}/files/${s}/presignedurl`,d=await a(n,{...r,method:"GET",headers:{...r?.headers}});if(d.status>=300){const e=[412].includes(d.status)?null:await d.text();throw new t.FetchError(e?JSON.parse(e):{},d.status,d.headers)}const o=[204,205,304].includes(d.status)?null:await d.text();return{body:o?JSON.parse(o):{},status:d.status,headers:d.headers}},deleteBrokenMetadata:async s=>{const r=`${e}/ops/delete-broken-metadata`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},deleteOrphanedFiles:async s=>{const r=`${e}/ops/delete-orphans`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},listBrokenMetadata:async s=>{const r=`${e}/ops/list-broken-metadata`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},listFilesNotUploaded:async s=>{const r=`${e}/ops/list-not-uploaded`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},listOrphanedFiles:async s=>{const r=`${e}/ops/list-orphans`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},getVersion:async s=>{const r=`${e}/version`,n=await a(r,{...s,method:"GET",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}}}};
|
|
2
|
+
//# sourceMappingURL=storage.cjs.map
|