@nhost/nhost-js 3.3.1 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -32
- package/dist/fetch-2PHmQBIJ.mjs +61 -0
- package/dist/fetch-2PHmQBIJ.mjs.map +1 -0
- package/dist/fetch-DWXwEnoe.js +2 -0
- package/dist/fetch-DWXwEnoe.js.map +1 -0
- package/dist/nhost-js/auth.cjs.js +2 -0
- package/dist/nhost-js/auth.cjs.js.map +1 -0
- package/dist/nhost-js/auth.es.js +917 -0
- package/dist/nhost-js/auth.es.js.map +1 -0
- package/dist/nhost-js/fetch.cjs.js +2 -0
- package/dist/nhost-js/fetch.cjs.js.map +1 -0
- package/dist/nhost-js/fetch.es.js +90 -0
- package/dist/nhost-js/fetch.es.js.map +1 -0
- package/dist/nhost-js/functions.cjs.js +2 -0
- package/dist/nhost-js/functions.cjs.js.map +1 -0
- package/dist/nhost-js/functions.es.js +45 -0
- package/dist/nhost-js/functions.es.js.map +1 -0
- package/dist/nhost-js/graphql.cjs.js +2 -0
- package/dist/nhost-js/graphql.cjs.js.map +1 -0
- package/dist/nhost-js/graphql.es.js +48 -0
- package/dist/nhost-js/graphql.es.js.map +1 -0
- package/dist/nhost-js/session.cjs.js +2 -0
- package/dist/nhost-js/session.cjs.js.map +1 -0
- package/dist/nhost-js/session.es.js +234 -0
- package/dist/nhost-js/session.es.js.map +1 -0
- package/dist/nhost-js/storage.cjs.js +2 -0
- package/dist/nhost-js/storage.cjs.js.map +1 -0
- package/dist/nhost-js/storage.es.js +324 -0
- package/dist/nhost-js/storage.es.js.map +1 -0
- package/dist/nhost-js.cjs.js +2 -0
- package/dist/nhost-js.cjs.js.map +1 -0
- package/dist/nhost-js.es.js +228 -0
- package/dist/nhost-js.es.js.map +1 -0
- package/dist/nhost-js.umd.js +2 -0
- package/dist/nhost-js.umd.js.map +1 -0
- package/dist/refreshSession-Bw715ZmX.js +2 -0
- package/dist/refreshSession-Bw715ZmX.js.map +1 -0
- package/dist/refreshSession-WwGlzgtM.mjs +95 -0
- package/dist/refreshSession-WwGlzgtM.mjs.map +1 -0
- package/dist/src/auth/client.d.ts +1763 -0
- package/dist/src/auth/client.d.ts.map +1 -0
- package/dist/src/auth/client.js +1043 -0
- package/dist/src/auth/client.js.map +1 -0
- package/dist/src/auth/index.d.ts +35 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +35 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/fetch/fetch.d.ts +88 -0
- package/dist/src/fetch/fetch.d.ts.map +1 -0
- package/dist/src/fetch/fetch.js +98 -0
- package/dist/src/fetch/fetch.js.map +1 -0
- package/dist/src/fetch/index.d.ts +38 -0
- package/dist/src/fetch/index.d.ts.map +1 -0
- package/dist/src/fetch/index.js +38 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/fetch/middlewareAttachAccessToken.d.ts +24 -0
- package/dist/src/fetch/middlewareAttachAccessToken.d.ts.map +1 -0
- package/dist/src/fetch/middlewareAttachAccessToken.js +54 -0
- package/dist/src/fetch/middlewareAttachAccessToken.js.map +1 -0
- package/dist/src/fetch/middlewareSessionRefresh.d.ts +30 -0
- package/dist/src/fetch/middlewareSessionRefresh.d.ts.map +1 -0
- package/dist/src/fetch/middlewareSessionRefresh.js +61 -0
- package/dist/src/fetch/middlewareSessionRefresh.js.map +1 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts +26 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts.map +1 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js +79 -0
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js.map +1 -0
- package/dist/src/functions/client.d.ts +52 -0
- package/dist/src/functions/client.d.ts.map +1 -0
- package/dist/src/functions/client.js +89 -0
- package/dist/src/functions/client.js.map +1 -0
- package/dist/src/functions/index.d.ts +43 -0
- package/dist/src/functions/index.d.ts.map +1 -0
- package/dist/src/functions/index.js +43 -0
- package/dist/src/functions/index.js.map +1 -0
- package/dist/src/graphql/client.d.ts +93 -0
- package/dist/src/graphql/client.d.ts.map +1 -0
- package/dist/src/graphql/client.js +66 -0
- package/dist/src/graphql/client.js.map +1 -0
- package/dist/src/graphql/index.d.ts +65 -0
- package/dist/src/graphql/index.d.ts.map +1 -0
- package/dist/src/graphql/index.js +65 -0
- package/dist/src/graphql/index.js.map +1 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/nhost.d.ts +301 -0
- package/dist/src/nhost.d.ts.map +1 -0
- package/dist/src/nhost.js +323 -0
- package/dist/src/nhost.js.map +1 -0
- package/dist/src/session/index.d.ts +20 -0
- package/dist/src/session/index.d.ts.map +1 -0
- package/dist/src/session/index.js +19 -0
- package/dist/src/session/index.js.map +1 -0
- package/dist/src/session/refreshSession.d.ts +17 -0
- package/dist/src/session/refreshSession.d.ts.map +1 -0
- package/dist/src/session/refreshSession.js +120 -0
- package/dist/src/session/refreshSession.js.map +1 -0
- package/dist/src/session/session.d.ts +24 -0
- package/dist/src/session/session.d.ts.map +1 -0
- package/dist/src/session/session.js +48 -0
- package/dist/src/session/session.js.map +1 -0
- package/dist/src/session/storage.d.ts +62 -0
- package/dist/src/session/storage.d.ts.map +1 -0
- package/dist/src/session/storage.js +91 -0
- package/dist/src/session/storage.js.map +1 -0
- package/dist/src/session/storageBackend.d.ts +122 -0
- package/dist/src/session/storageBackend.d.ts.map +1 -0
- package/dist/src/session/storageBackend.js +145 -0
- package/dist/src/session/storageBackend.js.map +1 -0
- package/dist/src/storage/client.d.ts +546 -0
- package/dist/src/storage/client.d.ts.map +1 -0
- package/dist/src/storage/client.js +368 -0
- package/dist/src/storage/client.js.map +1 -0
- package/dist/src/storage/index.d.ts +37 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +37 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +103 -59
- package/dist/clients/auth.d.ts +0 -8
- package/dist/clients/auth.d.ts.map +0 -1
- package/dist/clients/functions/index.d.ts +0 -107
- package/dist/clients/functions/index.d.ts.map +0 -1
- package/dist/clients/functions/types.d.ts +0 -28
- package/dist/clients/functions/types.d.ts.map +0 -1
- package/dist/clients/graphql.d.ts +0 -8
- package/dist/clients/graphql.d.ts.map +0 -1
- package/dist/clients/index.d.ts +0 -6
- package/dist/clients/index.d.ts.map +0 -1
- package/dist/clients/nhost.d.ts +0 -83
- package/dist/clients/nhost.d.ts.map +0 -1
- package/dist/clients/storage.d.ts +0 -8
- package/dist/clients/storage.d.ts.map +0 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -356
- package/dist/index.esm.js.map +0 -1
- package/dist/utils/helpers.d.ts +0 -20
- package/dist/utils/helpers.d.ts.map +0 -1
- package/dist/utils/types.d.ts +0 -57
- package/dist/utils/types.d.ts.map +0 -1
- package/umd/nhost-js.umd.js +0 -22
- package/umd/nhost-js.umd.js.map +0 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { createAPIClient } from "./nhost-js/auth.es.js";
|
|
2
|
+
import { updateSessionFromResponseMiddleware, attachAccessTokenMiddleware, sessionRefreshMiddleware } from "./nhost-js/fetch.es.js";
|
|
3
|
+
import { createAPIClient as createAPIClient$3 } from "./nhost-js/functions.es.js";
|
|
4
|
+
import { createAPIClient as createAPIClient$2 } from "./nhost-js/graphql.es.js";
|
|
5
|
+
import { r as refreshSession } from "./refreshSession-WwGlzgtM.mjs";
|
|
6
|
+
import { detectStorage, SessionStorage } from "./nhost-js/session.es.js";
|
|
7
|
+
import { createAPIClient as createAPIClient$1 } from "./nhost-js/storage.es.js";
|
|
8
|
+
class NhostClient {
|
|
9
|
+
/**
|
|
10
|
+
* Authentication client providing methods for user sign-in, sign-up, and session management.
|
|
11
|
+
* Use this client to handle all authentication-related operations.
|
|
12
|
+
*/
|
|
13
|
+
auth;
|
|
14
|
+
/**
|
|
15
|
+
* Storage client providing methods for file operations (upload, download, delete).
|
|
16
|
+
* Use this client to manage files in your Nhost storage.
|
|
17
|
+
*/
|
|
18
|
+
storage;
|
|
19
|
+
/**
|
|
20
|
+
* GraphQL client providing methods for executing GraphQL operations against your Hasura backend.
|
|
21
|
+
* Use this client to query and mutate data in your database through GraphQL.
|
|
22
|
+
*/
|
|
23
|
+
graphql;
|
|
24
|
+
/**
|
|
25
|
+
* Functions client providing methods for invoking serverless functions.
|
|
26
|
+
* Use this client to call your custom serverless functions deployed to Nhost.
|
|
27
|
+
*/
|
|
28
|
+
functions;
|
|
29
|
+
/**
|
|
30
|
+
* Storage implementation used for persisting session information.
|
|
31
|
+
* This handles saving, retrieving, and managing authentication sessions across requests.
|
|
32
|
+
*/
|
|
33
|
+
sessionStorage;
|
|
34
|
+
/**
|
|
35
|
+
* Create a new Nhost client. This constructor is reserved for advanced use cases.
|
|
36
|
+
* For typical usage, use [createClient](#createclient) or [createServerClient](#createserverclient) instead.
|
|
37
|
+
*
|
|
38
|
+
* @param auth - Authentication client instance
|
|
39
|
+
* @param storage - Storage client instance
|
|
40
|
+
* @param graphql - GraphQL client instance
|
|
41
|
+
* @param functions - Functions client instance
|
|
42
|
+
* @param sessionStorage - Storage implementation for session persistence
|
|
43
|
+
*/
|
|
44
|
+
constructor(auth, storage, graphql, functions, sessionStorage) {
|
|
45
|
+
this.auth = auth;
|
|
46
|
+
this.storage = storage;
|
|
47
|
+
this.graphql = graphql;
|
|
48
|
+
this.functions = functions;
|
|
49
|
+
this.sessionStorage = sessionStorage;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the current session from storage.
|
|
53
|
+
* This method retrieves the authenticated user's session information if one exists.
|
|
54
|
+
*
|
|
55
|
+
* @returns The current session or null if no session exists
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const session = nhost.getUserSession();
|
|
60
|
+
* if (session) {
|
|
61
|
+
* console.log('User is authenticated:', session.user.id);
|
|
62
|
+
* } else {
|
|
63
|
+
* console.log('No active session');
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
getUserSession() {
|
|
68
|
+
return this.sessionStorage.get();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Refresh the session using the current refresh token
|
|
72
|
+
* in the storage and update the storage with the new session.
|
|
73
|
+
*
|
|
74
|
+
* This method can be used to proactively refresh tokens before they expire
|
|
75
|
+
* or to force a refresh when needed.
|
|
76
|
+
*
|
|
77
|
+
* @param marginSeconds - The number of seconds before the token expiration to refresh the session. If the token is still valid for this duration, it will not be refreshed. Set to 0 to force the refresh.
|
|
78
|
+
*
|
|
79
|
+
* @returns The new session or null if there is currently no session or if refresh fails
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* // Refresh token if it's about to expire in the next 5 minutes
|
|
84
|
+
* const refreshedSession = await nhost.refreshSession(300);
|
|
85
|
+
*
|
|
86
|
+
* // Force refresh regardless of current token expiration
|
|
87
|
+
* const forcedRefresh = await nhost.refreshSession(0);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
async refreshSession(marginSeconds = 60) {
|
|
91
|
+
return refreshSession(this.auth, this.sessionStorage, marginSeconds);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Clear the session from storage.
|
|
95
|
+
*
|
|
96
|
+
* This method removes the current authentication session, effectively logging out the user.
|
|
97
|
+
* Note that this is a client-side operation and doesn't invalidate the refresh token on
|
|
98
|
+
* the server, which can be done with `nhost.auth.signOut({refreshToken: session.refreshTokenId})`.
|
|
99
|
+
* If the middle `updateSessionFromResponseMiddleware` is used, the session will be removed
|
|
100
|
+
* from the storage automatically and calling this method is not necessary.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // Log out the user
|
|
105
|
+
* nhost.clearSession();
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
clearSession() {
|
|
109
|
+
this.sessionStorage.remove();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function createClient(options = {}) {
|
|
113
|
+
const {
|
|
114
|
+
subdomain,
|
|
115
|
+
region,
|
|
116
|
+
authUrl,
|
|
117
|
+
storageUrl,
|
|
118
|
+
graphqlUrl,
|
|
119
|
+
functionsUrl,
|
|
120
|
+
storage = detectStorage()
|
|
121
|
+
} = options;
|
|
122
|
+
const sessionStorage = new SessionStorage(storage);
|
|
123
|
+
const authBaseUrl = generateServiceUrl("auth", subdomain, region, authUrl);
|
|
124
|
+
const storageBaseUrl = generateServiceUrl(
|
|
125
|
+
"storage",
|
|
126
|
+
subdomain,
|
|
127
|
+
region,
|
|
128
|
+
storageUrl
|
|
129
|
+
);
|
|
130
|
+
const graphqlBaseUrl = generateServiceUrl(
|
|
131
|
+
"graphql",
|
|
132
|
+
subdomain,
|
|
133
|
+
region,
|
|
134
|
+
graphqlUrl
|
|
135
|
+
);
|
|
136
|
+
const functionsBaseUrl = generateServiceUrl(
|
|
137
|
+
"functions",
|
|
138
|
+
subdomain,
|
|
139
|
+
region,
|
|
140
|
+
functionsUrl
|
|
141
|
+
);
|
|
142
|
+
const auth = createAPIClient(authBaseUrl);
|
|
143
|
+
const mwChain = getMiddlewareChain(auth, sessionStorage, true);
|
|
144
|
+
for (const mw of mwChain) {
|
|
145
|
+
auth.pushChainFunction(mw);
|
|
146
|
+
}
|
|
147
|
+
const storageClient = createAPIClient$1(storageBaseUrl, mwChain);
|
|
148
|
+
const graphqlClient = createAPIClient$2(graphqlBaseUrl, mwChain);
|
|
149
|
+
const functionsClient = createAPIClient$3(functionsBaseUrl, mwChain);
|
|
150
|
+
return new NhostClient(
|
|
151
|
+
auth,
|
|
152
|
+
storageClient,
|
|
153
|
+
graphqlClient,
|
|
154
|
+
functionsClient,
|
|
155
|
+
sessionStorage
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
function createServerClient(options) {
|
|
159
|
+
const {
|
|
160
|
+
subdomain,
|
|
161
|
+
region,
|
|
162
|
+
authUrl,
|
|
163
|
+
storageUrl,
|
|
164
|
+
graphqlUrl,
|
|
165
|
+
functionsUrl,
|
|
166
|
+
storage
|
|
167
|
+
} = options;
|
|
168
|
+
const sessionStorage = new SessionStorage(storage);
|
|
169
|
+
const authBaseUrl = generateServiceUrl("auth", subdomain, region, authUrl);
|
|
170
|
+
const storageBaseUrl = generateServiceUrl(
|
|
171
|
+
"storage",
|
|
172
|
+
subdomain,
|
|
173
|
+
region,
|
|
174
|
+
storageUrl
|
|
175
|
+
);
|
|
176
|
+
const graphqlBaseUrl = generateServiceUrl(
|
|
177
|
+
"graphql",
|
|
178
|
+
subdomain,
|
|
179
|
+
region,
|
|
180
|
+
graphqlUrl
|
|
181
|
+
);
|
|
182
|
+
const functionsBaseUrl = generateServiceUrl(
|
|
183
|
+
"functions",
|
|
184
|
+
subdomain,
|
|
185
|
+
region,
|
|
186
|
+
functionsUrl
|
|
187
|
+
);
|
|
188
|
+
const auth = createAPIClient(authBaseUrl);
|
|
189
|
+
const mwChain = getMiddlewareChain(auth, sessionStorage, false);
|
|
190
|
+
for (const mw of mwChain) {
|
|
191
|
+
auth.pushChainFunction(mw);
|
|
192
|
+
}
|
|
193
|
+
const storageClient = createAPIClient$1(storageBaseUrl, mwChain);
|
|
194
|
+
const graphqlClient = createAPIClient$2(graphqlBaseUrl, mwChain);
|
|
195
|
+
const functionsClient = createAPIClient$3(functionsBaseUrl, mwChain);
|
|
196
|
+
return new NhostClient(
|
|
197
|
+
auth,
|
|
198
|
+
storageClient,
|
|
199
|
+
graphqlClient,
|
|
200
|
+
functionsClient,
|
|
201
|
+
sessionStorage
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
function getMiddlewareChain(auth, storage, autoRefresh) {
|
|
205
|
+
const mwChain = [
|
|
206
|
+
updateSessionFromResponseMiddleware(storage),
|
|
207
|
+
attachAccessTokenMiddleware(storage)
|
|
208
|
+
];
|
|
209
|
+
if (autoRefresh) {
|
|
210
|
+
mwChain.unshift(sessionRefreshMiddleware(auth, storage));
|
|
211
|
+
}
|
|
212
|
+
return mwChain;
|
|
213
|
+
}
|
|
214
|
+
const generateServiceUrl = (serviceType, subdomain, region, customUrl) => {
|
|
215
|
+
if (customUrl) {
|
|
216
|
+
return customUrl;
|
|
217
|
+
} else if (subdomain && region) {
|
|
218
|
+
return `https://${subdomain}.${serviceType}.${region}.nhost.run/v1`;
|
|
219
|
+
} else {
|
|
220
|
+
return `https://local.${serviceType}.local.nhost.run/v1`;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
export {
|
|
224
|
+
createClient,
|
|
225
|
+
createServerClient,
|
|
226
|
+
generateServiceUrl
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=nhost-js.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nhost-js.es.js","sources":["../src/nhost.ts","../src/index.ts"],"sourcesContent":["import { generateServiceUrl } from \"./\";\nimport {\n type Client as AuthClient,\n createAPIClient as createAuthClient,\n} from \"./auth\";\nimport {\n attachAccessTokenMiddleware,\n type ChainFunction,\n sessionRefreshMiddleware,\n updateSessionFromResponseMiddleware,\n} from \"./fetch\";\nimport {\n createAPIClient as createFunctionsClient,\n type Client as FunctionsClient,\n} from \"./functions\";\nimport {\n createAPIClient as createGraphQLClient,\n type Client as GraphQLClient,\n} from \"./graphql\";\nimport {\n detectStorage,\n refreshSession,\n type Session,\n SessionStorage,\n type SessionStorageBackend,\n} from \"./session/\";\nimport {\n createAPIClient as createStorageClient,\n type Client as StorageClient,\n} from \"./storage\";\n\n/**\n * Main client class that provides unified access to all Nhost services.\n * This class serves as the central interface for interacting with Nhost's\n * authentication, storage, GraphQL, and serverless functions capabilities.\n */\nexport class NhostClient {\n /**\n * Authentication client providing methods for user sign-in, sign-up, and session management.\n * Use this client to handle all authentication-related operations.\n */\n auth: AuthClient;\n\n /**\n * Storage client providing methods for file operations (upload, download, delete).\n * Use this client to manage files in your Nhost storage.\n */\n storage: StorageClient;\n\n /**\n * GraphQL client providing methods for executing GraphQL operations against your Hasura backend.\n * Use this client to query and mutate data in your database through GraphQL.\n */\n graphql: GraphQLClient;\n\n /**\n * Functions client providing methods for invoking serverless functions.\n * Use this client to call your custom serverless functions deployed to Nhost.\n */\n functions: FunctionsClient;\n\n /**\n * Storage implementation used for persisting session information.\n * This handles saving, retrieving, and managing authentication sessions across requests.\n */\n sessionStorage: SessionStorage;\n\n /**\n * Create a new Nhost client. This constructor is reserved for advanced use cases.\n * For typical usage, use [createClient](#createclient) or [createServerClient](#createserverclient) instead.\n *\n * @param auth - Authentication client instance\n * @param storage - Storage client instance\n * @param graphql - GraphQL client instance\n * @param functions - Functions client instance\n * @param sessionStorage - Storage implementation for session persistence\n */\n constructor(\n auth: AuthClient,\n storage: StorageClient,\n graphql: GraphQLClient,\n functions: FunctionsClient,\n sessionStorage: SessionStorage,\n ) {\n this.auth = auth;\n this.storage = storage;\n this.graphql = graphql;\n this.functions = functions;\n this.sessionStorage = sessionStorage;\n }\n\n /**\n * Get the current session from storage.\n * This method retrieves the authenticated user's session information if one exists.\n *\n * @returns The current session or null if no session exists\n *\n * @example\n * ```ts\n * const session = nhost.getUserSession();\n * if (session) {\n * console.log('User is authenticated:', session.user.id);\n * } else {\n * console.log('No active session');\n * }\n * ```\n */\n getUserSession(): Session | null {\n return this.sessionStorage.get();\n }\n\n /**\n * Refresh the session using the current refresh token\n * in the storage and update the storage with the new session.\n *\n * This method can be used to proactively refresh tokens before they expire\n * or to force a refresh when needed.\n *\n * @param marginSeconds - The number of seconds before the token expiration to refresh the session. If the token is still valid for this duration, it will not be refreshed. Set to 0 to force the refresh.\n *\n * @returns The new session or null if there is currently no session or if refresh fails\n *\n * @example\n * ```ts\n * // Refresh token if it's about to expire in the next 5 minutes\n * const refreshedSession = await nhost.refreshSession(300);\n *\n * // Force refresh regardless of current token expiration\n * const forcedRefresh = await nhost.refreshSession(0);\n * ```\n */\n async refreshSession(marginSeconds = 60): Promise<Session | null> {\n return refreshSession(this.auth, this.sessionStorage, marginSeconds);\n }\n\n /**\n * Clear the session from storage.\n *\n * This method removes the current authentication session, effectively logging out the user.\n * Note that this is a client-side operation and doesn't invalidate the refresh token on\n * the server, which can be done with `nhost.auth.signOut({refreshToken: session.refreshTokenId})`.\n * If the middle `updateSessionFromResponseMiddleware` is used, the session will be removed\n * from the storage automatically and calling this method is not necessary.\n *\n * @example\n * ```ts\n * // Log out the user\n * nhost.clearSession();\n * ```\n */\n clearSession(): void {\n this.sessionStorage.remove();\n }\n}\n\n/**\n * Configuration options for creating an Nhost client\n */\nexport interface NhostClientOptions {\n /**\n * Nhost project subdomain (e.g., 'abcdefgh'). Used to construct the base URL for services for the Nhost cloud.\n */\n subdomain?: string;\n\n /**\n * Nhost region (e.g., 'eu-central-1'). Used to construct the base URL for services for the Nhost cloud.\n */\n region?: string;\n\n /**\n * Complete base URL for the auth service (overrides subdomain/region)\n */\n authUrl?: string;\n\n /**\n * Complete base URL for the storage service (overrides subdomain/region)\n */\n storageUrl?: string;\n\n /**\n * Complete base URL for the GraphQL service (overrides subdomain/region)\n */\n graphqlUrl?: string;\n\n /**\n * Complete base URL for the functions service (overrides subdomain/region)\n */\n functionsUrl?: string;\n\n /**\n * Storage backend to use for session persistence. If not provided, the SDK will\n * default to localStorage in the browser or memory in other environments.\n */\n storage?: SessionStorageBackend;\n}\n\n/**\n * Creates and configures a new Nhost client instance optimized for client-side usage.\n *\n * This helper method instantiates a fully configured Nhost client by:\n * - Instantiating the various service clients (auth, storage, functions and graphql)\n * - Auto-detecting and configuring an appropriate session storage (localStorage in browsers, memory otherwise)\n * - Setting up a sophisticated middleware chain for seamless authentication management:\n * - Automatically refreshing tokens before they expire\n * - Attaching authorization tokens to all service requests\n * - Updating the session storage when new tokens are received\n *\n * This method includes automatic session refresh middleware, making it ideal for\n * client-side applications where long-lived sessions are expected.\n *\n * @param options - Configuration options for the client\n * @returns A configured Nhost client\n *\n * @example\n * ```ts\n * // Create client using Nhost cloud default URLs\n * const nhost = createClient({\n * subdomain: 'abcdefgh',\n * region: 'eu-central-1'\n * });\n *\n * // Create client with custom service URLs\n * const customNhost = createClient({\n * authUrl: 'https://auth.example.com',\n * storageUrl: 'https://storage.example.com',\n * graphqlUrl: 'https://graphql.example.com',\n * functionsUrl: 'https://functions.example.com'\n * });\n *\n * // Create client using cookies for storing the session\n * import { CookieStorage } from \"@nhost/nhost-js/session\";\n *\n * const nhost = createClient({\n * subdomain: 'abcdefgh',\n * region: 'eu-central-1',\n * storage: new CookieStorage({\n * secure: import.meta.env.ENVIRONMENT === 'production',\n * })\n * });\n * ```\n */\nexport function createClient(options: NhostClientOptions = {}): NhostClient {\n const {\n subdomain,\n region,\n authUrl,\n storageUrl,\n graphqlUrl,\n functionsUrl,\n storage = detectStorage(),\n } = options;\n\n const sessionStorage = new SessionStorage(storage);\n\n // Determine base URLs for each service\n const authBaseUrl = generateServiceUrl(\"auth\", subdomain, region, authUrl);\n const storageBaseUrl = generateServiceUrl(\n \"storage\",\n subdomain,\n region,\n storageUrl,\n );\n const graphqlBaseUrl = generateServiceUrl(\n \"graphql\",\n subdomain,\n region,\n graphqlUrl,\n );\n\n const functionsBaseUrl = generateServiceUrl(\n \"functions\",\n subdomain,\n region,\n functionsUrl,\n );\n\n // Create auth client\n const auth = createAuthClient(authBaseUrl);\n\n const mwChain = getMiddlewareChain(auth, sessionStorage, true);\n\n for (const mw of mwChain) {\n auth.pushChainFunction(mw);\n }\n\n // Create storage and graphql clients with the refresh and attach token middlewares\n const storageClient = createStorageClient(storageBaseUrl, mwChain);\n const graphqlClient = createGraphQLClient(graphqlBaseUrl, mwChain);\n const functionsClient = createFunctionsClient(functionsBaseUrl, mwChain);\n\n // Return an initialized NhostClient\n return new NhostClient(\n auth,\n storageClient,\n graphqlClient,\n functionsClient,\n sessionStorage,\n );\n}\n\nexport interface NhostServerClientOptions extends NhostClientOptions {\n /**\n * Storage backend to use for session persistence in server environments.\n * Unlike the base options, this field is required for server-side usage\n * as the SDK cannot auto-detect an appropriate storage mechanism.\n */\n storage: SessionStorageBackend;\n}\n\n/**\n * Creates and configures a new Nhost client instance optimized for server-side usage.\n *\n * This helper method instantiates a fully configured Nhost client specifically designed for:\n * - Server components (in frameworks like Next.js or Remix)\n * - API routes and middleware\n * - Backend services and server-side rendering contexts\n *\n * Key differences from the standard client:\n * - Requires explicit storage implementation (must be provided)\n * - Disables automatic session refresh middleware (to prevent race conditions in server contexts)\n * - Still attaches authorization tokens and updates session storage from responses\n *\n * The server client is ideal for short-lived request contexts where session tokens\n * are passed in (like cookie-based authentication flows) and automatic refresh\n * mechanisms could cause issues with concurrent requests.\n *\n * @param options - Configuration options for the server client (requires storage implementation)\n * @returns A configured Nhost client optimized for server-side usage\n *\n * @example\n * ```ts\n * // Example with cookie storage for Next.js API route or server component\n * import { cookies } from 'next/headers';\n *\n * const nhost = createServerClient({\n * region: process.env[\"NHOST_REGION\"] || \"local\",\n * subdomain: process.env[\"NHOST_SUBDOMAIN\"] || \"local\",\n * storage: {\n * // storage compatible with Next.js server components\n * get: (): Session | null => {\n * const s = cookieStore.get(key)?.value || null;\n * if (!s) {\n * return null;\n * }\n * const session = JSON.parse(s) as Session;\n * return session;\n * },\n * set: (value: Session) => {\n * cookieStore.set(key, JSON.stringify(value));\n * },\n * remove: () => {\n * cookieStore.delete(key);\n * },\n * },\n * });\n *\n * // Example with cookie storage for Next.js middleware\n * const nhost = createServerClient({\n * region: process.env[\"NHOST_REGION\"] || \"local\",\n * subdomain: process.env[\"NHOST_SUBDOMAIN\"] || \"local\",\n * storage: {\n * // storage compatible with Next.js middleware\n * get: (): Session | null => {\n * const raw = request.cookies.get(key)?.value || null;\n * if (!raw) {\n * return null;\n * }\n * const session = JSON.parse(raw) as Session;\n * return session;\n * },\n * set: (value: Session) => {\n * response.cookies.set({\n * name: key,\n * value: JSON.stringify(value),\n * path: \"/\",\n * httpOnly: false, //if set to true we can't access it in the client\n * secure: process.env.NODE_ENV === \"production\",\n * sameSite: \"lax\",\n * maxAge: 60 * 60 * 24 * 30, // 30 days in seconds\n * });\n * },\n * remove: () => {\n * response.cookies.delete(key);\n * },\n * },\n * });\n *\n * // Example for express reading session from a cookie\n *\n * import express, { Request, Response } from \"express\";\n * import cookieParser from \"cookie-parser\";\n *\n * app.use(cookieParser());\n *\n * const nhostClientFromCookies = (req: Request) => {\n * return createServerClient({\n * subdomain: \"local\",\n * region: \"local\",\n * storage: {\n * get: (): Session | null => {\n * const s = req.cookies.nhostSession || null;\n * if (!s) {\n * return null;\n * }\n * const session = JSON.parse(s) as Session;\n * return session;\n * },\n * set: (_value: Session) => {\n * throw new Error(\"It is easier to handle the session in the client\");\n * },\n * remove: () => {\n * throw new Error(\"It is easier to handle the session in the client\");\n * },\n * },\n * });\n * };\n * ```\n */\nexport function createServerClient(\n options: NhostServerClientOptions,\n): NhostClient {\n const {\n subdomain,\n region,\n authUrl,\n storageUrl,\n graphqlUrl,\n functionsUrl,\n storage,\n } = options;\n const sessionStorage = new SessionStorage(storage);\n\n // Determine base URLs for each service\n const authBaseUrl = generateServiceUrl(\"auth\", subdomain, region, authUrl);\n const storageBaseUrl = generateServiceUrl(\n \"storage\",\n subdomain,\n region,\n storageUrl,\n );\n const graphqlBaseUrl = generateServiceUrl(\n \"graphql\",\n subdomain,\n region,\n graphqlUrl,\n );\n\n const functionsBaseUrl = generateServiceUrl(\n \"functions\",\n subdomain,\n region,\n functionsUrl,\n );\n\n // Create auth client\n const auth = createAuthClient(authBaseUrl);\n\n const mwChain = getMiddlewareChain(auth, sessionStorage, false);\n\n for (const mw of mwChain) {\n auth.pushChainFunction(mw);\n }\n\n // Create storage and graphql clients with the refresh and attach token middlewares\n const storageClient = createStorageClient(storageBaseUrl, mwChain);\n const graphqlClient = createGraphQLClient(graphqlBaseUrl, mwChain);\n const functionsClient = createFunctionsClient(functionsBaseUrl, mwChain);\n\n // Return an initialized NhostClient\n return new NhostClient(\n auth,\n storageClient,\n graphqlClient,\n functionsClient,\n sessionStorage,\n );\n}\n\nfunction getMiddlewareChain(\n auth: AuthClient,\n storage: SessionStorage,\n autoRefresh: boolean,\n): ChainFunction[] {\n const mwChain = [\n updateSessionFromResponseMiddleware(storage),\n attachAccessTokenMiddleware(storage),\n ];\n\n if (autoRefresh) {\n mwChain.unshift(sessionRefreshMiddleware(auth, storage));\n }\n\n return mwChain;\n}\n","/**\n * Main entry point for the Nhost JavaScript SDK.\n *\n * This package provides a unified client for interacting with Nhost services:\n * - Authentication\n * - Storage\n * - GraphQL\n * - Functions\n *\n * ## Import\n *\n * ```ts\n * import { createClient } from \"@nhost/nhost-js\";\n * ```\n *\n * ## Usage\n *\n * Create a client instance to interact with Nhost services:\n *\n * {@includeCode ./__tests__/docstrings.test.ts:11-115}\n *\n * @packageDocumentation\n */\n\nexport {\n createClient,\n createServerClient,\n type NhostClient,\n type NhostClientOptions,\n type NhostServerClientOptions,\n} from \"./nhost\";\n\n/**\n * Generates a base URL for a Nhost service based on configuration\n *\n * @param serviceType - Type of service (auth, storage, graphql, functions)\n * @param subdomain - Nhost project subdomain\n * @param region - Nhost region\n * @param customUrl - Custom URL override if provided\n * @returns The base URL for the service\n */\nexport const generateServiceUrl = (\n serviceType: \"auth\" | \"storage\" | \"graphql\" | \"functions\",\n subdomain?: string,\n region?: string,\n customUrl?: string,\n): string => {\n if (customUrl) {\n return customUrl;\n } else if (subdomain && region) {\n return `https://${subdomain}.${serviceType}.${region}.nhost.run/v1`;\n } else {\n return `https://local.${serviceType}.local.nhost.run/v1`;\n }\n};\n"],"names":["createAuthClient","createStorageClient","createGraphQLClient","createFunctionsClient"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).NhostJs={})}(this,(function(t){"use strict";function s(t=[]){return t.reduceRight(((t,s)=>s(t)),fetch)}class e extends Error{body;status;headers;constructor(t,s,e){super(function(t){if(t&&"string"==typeof t)return t;if(t&&"object"==typeof t){const s=t;if("message"in s&&"string"==typeof s.message)return s.message;if("error"in s&&"string"==typeof s.error)return s.error;if("error"in s&&s.error&&"object"==typeof s.error){const t=s.error;if("message"in t&&"string"==typeof t.message)return t.message}if("errors"in s&&Array.isArray(s.errors)){const t=s.errors.filter((t=>"object"==typeof t&&null!==t&&"message"in t&&"string"==typeof t.message)).map((t=>t.message));if(t.length>0)return t.join(", ")}}return"An unexpected error occurred"}(t)),this.body=t,this.status=s,this.headers=e}}const a=t=>s=>async(e,a={})=>{const r=new Headers(a.headers||{});if(r.has("Authorization"))return s(e,a);const o=t.get();if(o?.accessToken){const t={...a,headers:n(r,o)};return s(e,t)}return s(e,a)};function n(t,s){return s.accessToken&&t.set("Authorization",`Bearer ${s.accessToken}`),t}const r="undefined"!=typeof navigator&&navigator.locks?navigator.locks:new class{async request(t,s,e){return e()}},o=async(t,s,e=60)=>{try{return await i(t,s,e)}catch(a){try{return console.warn("error refreshing session, retrying:",a),await i(t,s,e)}catch(n){const t=n;return 401===t?.status&&(console.error("session probably expired"),s.remove()),null}}},i=async(t,s,e=60)=>{const{session:a,needsRefresh:n}=await r.request("nhostSessionLock",{mode:"shared"},(async()=>u(s,e)));if(!a)return null;if(!n)return a;return await r.request("nhostSessionLock",{mode:"exclusive"},(async()=>{const{session:a,needsRefresh:n,sessionExpired:r}=u(s,e);if(!a)return null;if(!n)return a;try{const e=await t.refreshToken({refreshToken:a.refreshToken});return s.set(e.body),e.body}catch(o){if(!r)return a;throw o}}))},u=(t,s=60)=>{const e=t.get();if(!e)return{session:null,needsRefresh:!1,sessionExpired:!1};if(!e.decodedToken||!e.decodedToken.exp)return{session:e,needsRefresh:!0,sessionExpired:!0};if(0===s)return{session:e,needsRefresh:!0,sessionExpired:!1};const a=Date.now();return e.decodedToken.exp-a>1e3*s?{session:e,needsRefresh:!1,sessionExpired:!1}:{session:e,needsRefresh:!0,sessionExpired:e.decodedToken.exp<a}},d=(t,s,e)=>{const{marginSeconds:a=60}={};return e=>async(n,r={})=>{if(function(t,s){const e=new Headers(s.headers||{});if(e.has("Authorization"))return!0;if(t.endsWith("/v1/token"))return!0;return!1}(n,r))return e(n,r);try{await o(t,s,a)}catch{}return e(n,r)}};const c=t=>s=>async(e,a)=>{const n=await s(e,a);try{if(e.endsWith("/signout"))return t.remove(),n;if(e.endsWith("/token")||e.includes("/signin/")||e.includes("/signup/")){const s=n.clone(),e=await s.json().catch((()=>null));if(e){const s=(t=>"string"==typeof t?null:"session"in t?t.session||null:"accessToken"in t&&"refreshToken"in t?t:null)(e);s?.accessToken&&s.refreshToken&&t.set(s)}}}catch(r){console.warn("Error in session response middleware:",r)}return n},h=(t,a=[])=>{let n=s(a);return{baseURL:t,pushChainFunction:t=>{a.push(t),n=s(a)},getJWKs:async s=>{const a=`${t}/.well-known/jwks.json`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},elevateWebauthn:async s=>{const a=`${t}/elevate/webauthn`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},verifyElevateWebauthn:async(s,a)=>{const r=`${t}/elevate/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},healthCheckGet:async s=>{const a=`${t}/healthz`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},healthCheckHead:async s=>{const a=`${t}/healthz`,r=await n(a,{...s,method:"HEAD",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}return{body:void 0,status:r.status,headers:r.headers}},linkIdToken:async(s,a)=>{const r=`${t}/link/idtoken`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},changeUserMfa:async s=>{const a=`${t}/mfa/totp/generate`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},createPAT:async(s,a)=>{const r=`${t}/pat`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInAnonymous:async(s,a)=>{const r=`${t}/signin/anonymous`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInEmailPassword:async(s,a)=>{const r=`${t}/signin/email-password`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInIdToken:async(s,a)=>{const r=`${t}/signin/idtoken`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInMfaTotp:async(s,a)=>{const r=`${t}/signin/mfa/totp`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInOTPEmail:async(s,a)=>{const r=`${t}/signin/otp/email`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInOTPEmail:async(s,a)=>{const r=`${t}/signin/otp/email/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInPasswordlessEmail:async(s,a)=>{const r=`${t}/signin/passwordless/email`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInPasswordlessSms:async(s,a)=>{const r=`${t}/signin/passwordless/sms`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInPasswordlessSms:async(s,a)=>{const r=`${t}/signin/passwordless/sms/otp`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInPAT:async(s,a)=>{const r=`${t}/signin/pat`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInProviderURL:(s,e)=>{const a=e&&Object.entries(e).map((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s?JSON.stringify(s):s;return`${t}=${encodeURIComponent(e)}`})).join("&");return a?`${t}/signin/provider/${s}?${a}`:`${t}/signin/provider/${s}`},signInWebauthn:async(s,a)=>{const r=`${t}/signin/webauthn`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInWebauthn:async(s,a)=>{const r=`${t}/signin/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signOut:async(s,a)=>{const r=`${t}/signout`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpEmailPassword:async(s,a)=>{const r=`${t}/signup/email-password`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpWebauthn:async(s,a)=>{const r=`${t}/signup/webauthn`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignUpWebauthn:async(s,a)=>{const r=`${t}/signup/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},refreshToken:async(s,a)=>{const r=`${t}/token`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifyToken:async(s,a)=>{const r=`${t}/token/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},getUser:async s=>{const a=`${t}/user`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},deanonymizeUser:async(s,a)=>{const r=`${t}/user/deanonymize`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},changeUserEmail:async(s,a)=>{const r=`${t}/user/email/change`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},sendVerificationEmail:async(s,a)=>{const r=`${t}/user/email/send-verification-email`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifyChangeUserMfa:async(s,a)=>{const r=`${t}/user/mfa`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},changeUserPassword:async(s,a)=>{const r=`${t}/user/password`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},sendPasswordResetEmail:async(s,a)=>{const r=`${t}/user/password/reset`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},addSecurityKey:async s=>{const a=`${t}/user/webauthn/add`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},verifyAddSecurityKey:async(s,a)=>{const r=`${t}/user/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifyTicketURL:s=>{const e=s&&Object.entries(s).map((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s?JSON.stringify(s):s;return`${t}=${encodeURIComponent(e)}`})).join("&");return e?`${t}/verify?${e}`:`${t}/verify`},getVersion:async s=>{const a=`${t}/version`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}}}},l=(t,a=[])=>{const n=s(a),r=async(s,a)=>{const r=await n(`${t}${s}`,a);let o;if(o=r.headers.get("content-type")?.includes("application/json")?await r.json():r.headers.get("content-type")?.startsWith("text/")?await r.text():await r.blob(),!r.ok)throw new e(o,r.status,r.headers);return{status:r.status,body:o,headers:r.headers}};return{baseURL:t,fetch:r,post:async(t,s,e={})=>{const a={...e,method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...e.headers},body:s?JSON.stringify(s):void 0};return r(t,a)}}},p=(t,a=[])=>{const n=s(a),r=async(s,a)=>{const r=await n(`${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),...a}),o=await r.text(),i=o?JSON.parse(o):{},u={body:i,status:r.status,headers:r.headers};if(i.errors)throw new e(i,r.status,r.headers);return u};return{request:function(t,s,e){if("object"==typeof t&&"kind"in t){const a=t.definitions[0],n={query:t.loc?.source.body||"",variables:s,operationName:a&&"name"in a?a.name?.value:void 0};return r(n,e)}return r(t,s)},url:t}},w=t=>t.startsWith("{")&&t.endsWith("}"),y=t=>t&&"{}"!==t?t.slice(1,-1).split(",").map((t=>t.trim().replace(/^"(.*)"$/,"$1"))):[];class f{storageKey;constructor(t){this.storageKey=t?.storageKey||"nhostSession"}get(){try{const t=window.localStorage.getItem(this.storageKey);return t?JSON.parse(t):null}catch{return this.remove(),null}}set(t){window.localStorage.setItem(this.storageKey,JSON.stringify(t))}remove(){window.localStorage.removeItem(this.storageKey)}}class S{session=null;get(){return this.session}set(t){this.session=t}remove(){this.session=null}}class O{storage;subscribers=new Set;constructor(t){this.storage=t}get(){return this.storage.get()}set(t){const s=(t=>{const s=t.split(".");if(3!==s.length||!s[1])throw new Error("Invalid access token format");const e=JSON.parse("undefined"!=typeof atob?atob(s[1]):Buffer.from(s[1],"base64").toString("utf-8")),a="number"==typeof e.iat?1e3*e.iat:void 0,n="number"==typeof e.exp?1e3*e.exp:void 0,r=e["https://hasura.io/jwt/claims"],o=r?Object.entries(r).reduce(((t,[s,e])=>("string"==typeof e&&w(e)?t[s]=y(e):t[s]=e,t)),{}):void 0;return{...e,iat:a,exp:n,"https://hasura.io/jwt/claims":o}})(t.accessToken),e={...t,decodedToken:s};this.storage.set(e),this.notifySubscribers(e)}remove(){this.storage.remove(),this.notifySubscribers(null)}onChange(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}notifySubscribers(t){for(const e of this.subscribers)try{e(t)}catch(s){console.error("Error notifying subscriber:",s)}}}const g=()=>"undefined"!=typeof window?new f:new S,b=(t,a=[])=>{let n=s(a);return{baseURL:t,pushChainFunction:t=>{a.push(t),n=s(a)},uploadFiles:async(s,a)=>{const r=`${t}/files`,o=new FormData;void 0!==s["bucket-id"]&&o.append("bucket-id",s["bucket-id"]),void 0!==s["metadata[]"]&&s["metadata[]"].forEach((t=>{o.append("metadata[]",new Blob([JSON.stringify(t)],{type:"application/json"}),"")})),void 0!==s["file[]"]&&s["file[]"].forEach((t=>{o.append("file[]",t)}));const i=await n(r,{...a,method:"POST",body:o});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,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,a)=>{const r=`${t}/files/${s}`,o=await n(r,{...a,method:"DELETE",headers:{...a?.headers}});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}return{body:void 0,status:o.status,headers:o.headers}},getFile:async(s,a,r)=>{const o=a&&Object.entries(a).map((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s?JSON.stringify(s):s;return`${t}=${encodeURIComponent(e)}`})).join("&"),i=o?`${t}/files/${s}?${o}`:`${t}/files/${s}`,u=await n(i,{...r,method:"GET",headers:{...r?.headers}});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}return{body:await u.blob(),status:u.status,headers:u.headers}},getFileMetadataHeaders:async(s,a,r)=>{const o=a&&Object.entries(a).map((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s?JSON.stringify(s):s;return`${t}=${encodeURIComponent(e)}`})).join("&"),i=o?`${t}/files/${s}?${o}`:`${t}/files/${s}`,u=await n(i,{...r,method:"HEAD",headers:{...r?.headers}});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}return{body:void 0,status:u.status,headers:u.headers}},replaceFile:async(s,a,r)=>{const o=`${t}/files/${s}`,i=new FormData;void 0!==a.metadata&&i.append("metadata",new Blob([JSON.stringify(a.metadata)],{type:"application/json"}),""),void 0!==a.file&&i.append("file",a.file);const u=await n(o,{...r,method:"PUT",body:i});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}const d=[204,205,304].includes(u.status)?null:await u.text();return{body:d?JSON.parse(d):{},status:u.status,headers:u.headers}},getFilePresignedURL:async(s,a)=>{const r=`${t}/files/${s}/presignedurl`,o=await n(r,{...a,method:"GET",headers:{...a?.headers}});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},deleteBrokenMetadata:async s=>{const a=`${t}/ops/delete-broken-metadata`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},deleteOrphanedFiles:async s=>{const a=`${t}/ops/delete-orphans`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},listBrokenMetadata:async s=>{const a=`${t}/ops/list-broken-metadata`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},listFilesNotUploaded:async s=>{const a=`${t}/ops/list-not-uploaded`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},listOrphanedFiles:async s=>{const a=`${t}/ops/list-orphans`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},getVersion:async s=>{const a=`${t}/version`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}}}};class m{auth;storage;graphql;functions;sessionStorage;constructor(t,s,e,a,n){this.auth=t,this.storage=s,this.graphql=e,this.functions=a,this.sessionStorage=n}getUserSession(){return this.sessionStorage.get()}async refreshSession(t=60){return o(this.auth,this.sessionStorage,t)}clearSession(){this.sessionStorage.remove()}}function N(t,s,e){const n=[c(s),a(s)];return e&&n.unshift(d(t,s)),n}const J=(t,s,e,a)=>a||(s&&e?`https://${s}.${t}.${e}.nhost.run/v1`:`https://local.${t}.local.nhost.run/v1`);t.createClient=function(t={}){const{subdomain:s,region:e,authUrl:a,storageUrl:n,graphqlUrl:r,functionsUrl:o,storage:i=g()}=t,u=new O(i),d=J("auth",s,e,a),c=J("storage",s,e,n),w=J("graphql",s,e,r),y=J("functions",s,e,o),f=h(d),S=N(f,u,!0);for(const h of S)f.pushChainFunction(h);const x=b(c,S),T=p(w,S),$=l(y,S);return new m(f,x,T,$,u)},t.createServerClient=function(t){const{subdomain:s,region:e,authUrl:a,storageUrl:n,graphqlUrl:r,functionsUrl:o,storage:i}=t,u=new O(i),d=J("auth",s,e,a),c=J("storage",s,e,n),w=J("graphql",s,e,r),y=J("functions",s,e,o),f=h(d),S=N(f,u,!1);for(const h of S)f.pushChainFunction(h);const g=b(c,S),x=p(w,S),T=l(y,S);return new m(f,g,x,T,u)},t.generateServiceUrl=J,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
2
|
+
//# sourceMappingURL=nhost-js.umd.js.map
|