@nhost/nhost-js 4.0.1 → 4.1.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/middlewareWithAdminSession-BtFo6WUj.js +2 -0
- package/dist/middlewareWithAdminSession-BtFo6WUj.js.map +1 -0
- package/dist/middlewareWithAdminSession-w7fkl0J9.mjs +106 -0
- package/dist/middlewareWithAdminSession-w7fkl0J9.mjs.map +1 -0
- package/dist/nhost-js/auth.cjs.js +1 -1
- package/dist/nhost-js/auth.cjs.js.map +1 -1
- package/dist/nhost-js/auth.es.js +48 -0
- package/dist/nhost-js/auth.es.js.map +1 -1
- package/dist/nhost-js/fetch.cjs.js +1 -1
- package/dist/nhost-js/fetch.cjs.js.map +1 -1
- package/dist/nhost-js/fetch.es.js +19 -79
- package/dist/nhost-js/fetch.es.js.map +1 -1
- package/dist/nhost-js/functions.cjs.js +1 -1
- package/dist/nhost-js/functions.cjs.js.map +1 -1
- package/dist/nhost-js/functions.es.js +7 -2
- package/dist/nhost-js/functions.es.js.map +1 -1
- package/dist/nhost-js/graphql.cjs.js +1 -1
- package/dist/nhost-js/graphql.cjs.js.map +1 -1
- package/dist/nhost-js/graphql.es.js +7 -2
- package/dist/nhost-js/graphql.es.js.map +1 -1
- package/dist/nhost-js/session.es.js +1 -1
- package/dist/nhost-js/storage.cjs.js.map +1 -1
- package/dist/nhost-js/storage.es.js.map +1 -1
- package/dist/nhost-js.cjs.js +1 -1
- package/dist/nhost-js.cjs.js.map +1 -1
- package/dist/nhost-js.es.js +78 -65
- package/dist/nhost-js.es.js.map +1 -1
- package/dist/nhost-js.umd.js +1 -1
- package/dist/nhost-js.umd.js.map +1 -1
- package/dist/refreshSession-Bw715ZmX.js.map +1 -1
- package/dist/{refreshSession-WwGlzgtM.mjs → refreshSession-CG8GIEun.mjs} +5 -2
- package/dist/refreshSession-CG8GIEun.mjs.map +1 -0
- package/dist/src/auth/client.d.ts +72 -1
- package/dist/src/auth/client.d.ts.map +1 -1
- package/dist/src/auth/client.js +56 -0
- package/dist/src/auth/client.js.map +1 -1
- package/dist/src/fetch/index.d.ts +15 -0
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +15 -0
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js +1 -1
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js.map +1 -1
- package/dist/src/fetch/middlewareWithAdminSession.d.ts +87 -0
- package/dist/src/fetch/middlewareWithAdminSession.d.ts.map +1 -0
- package/dist/src/fetch/middlewareWithAdminSession.js +79 -0
- package/dist/src/fetch/middlewareWithAdminSession.js.map +1 -0
- package/dist/src/fetch/middlewareWithHeaders.d.ts +23 -0
- package/dist/src/fetch/middlewareWithHeaders.d.ts.map +1 -0
- package/dist/src/fetch/middlewareWithHeaders.js +31 -0
- package/dist/src/fetch/middlewareWithHeaders.js.map +1 -0
- package/dist/src/fetch/middlewareWithRole.d.ts +44 -0
- package/dist/src/fetch/middlewareWithRole.d.ts.map +1 -0
- package/dist/src/fetch/middlewareWithRole.js +50 -0
- package/dist/src/fetch/middlewareWithRole.js.map +1 -0
- package/dist/src/functions/client.d.ts +6 -1
- package/dist/src/functions/client.d.ts.map +1 -1
- package/dist/src/functions/client.js +6 -1
- package/dist/src/functions/client.js.map +1 -1
- package/dist/src/graphql/client.d.ts +4 -0
- package/dist/src/graphql/client.d.ts.map +1 -1
- package/dist/src/graphql/client.js +6 -1
- package/dist/src/graphql/client.js.map +1 -1
- package/dist/src/index.d.ts +12 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/nhost.d.ts +109 -0
- package/dist/src/nhost.d.ts.map +1 -1
- package/dist/src/nhost.js +167 -49
- package/dist/src/nhost.js.map +1 -1
- package/dist/src/session/refreshSession.d.ts.map +1 -1
- package/dist/src/session/refreshSession.js +3 -1
- package/dist/src/session/refreshSession.js.map +1 -1
- package/dist/src/storage/client.d.ts +3 -0
- package/dist/src/storage/client.d.ts.map +1 -1
- package/dist/src/storage/client.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/refreshSession-WwGlzgtM.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewareUpdateSessionFromResponse.js","sourceRoot":"","sources":["../../../src/fetch/middlewareUpdateSessionFromResponse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,OAAuB,EACR,EAAE;IACjB;;;;;OAKG;IACH,MAAM,gBAAgB,GAAG,CACvB,IAAuC,EACvB,EAAE;QAClB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,iBAAiB;YACjB,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;QAC9B,CAAC;QAED,IAAI,aAAa,IAAI,IAAI,IAAI,cAAc,IAAI,IAAI,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"middlewareUpdateSessionFromResponse.js","sourceRoot":"","sources":["../../../src/fetch/middlewareUpdateSessionFromResponse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,OAAuB,EACR,EAAE;IACjB;;;;;OAKG;IACH,MAAM,gBAAgB,GAAG,CACvB,IAAuC,EACvB,EAAE;QAClB,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,iBAAiB;YACjB,OAAO,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;QAC9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CAAC;YACf,OAAO,CAAC,IAAI,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;QAC/D,CAAC;QAED,+BAA+B;QAC/B,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin session middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically attach
|
|
5
|
+
* Hasura admin secret for admin permissions in requests.
|
|
6
|
+
*/
|
|
7
|
+
import type { ChainFunction } from "./fetch";
|
|
8
|
+
/**
|
|
9
|
+
* Configuration options for admin session middleware
|
|
10
|
+
*/
|
|
11
|
+
export interface AdminSessionOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Hasura admin secret for elevated permissions (sets x-hasura-admin-secret header)
|
|
14
|
+
*/
|
|
15
|
+
adminSecret: string;
|
|
16
|
+
/**
|
|
17
|
+
* Hasura role to use for the request (sets x-hasura-role header)
|
|
18
|
+
*/
|
|
19
|
+
role?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Additional Hasura session variables to attach to requests.
|
|
22
|
+
* Keys will be automatically prefixed with 'x-hasura-' if not already present.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* {
|
|
27
|
+
* 'user-id': '123',
|
|
28
|
+
* 'org-id': '456'
|
|
29
|
+
* }
|
|
30
|
+
* // Results in headers:
|
|
31
|
+
* // x-hasura-user-id: 123
|
|
32
|
+
* // x-hasura-org-id: 456
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
sessionVariables?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a fetch middleware that attaches the Hasura admin secret and optional session variables to requests.
|
|
39
|
+
*
|
|
40
|
+
* This middleware:
|
|
41
|
+
* 1. Sets the x-hasura-admin-secret header, which grants full admin access to Hasura
|
|
42
|
+
* 2. Optionally sets the x-hasura-role header if a role is provided
|
|
43
|
+
* 3. Optionally sets additional x-hasura-* headers for custom session variables
|
|
44
|
+
*
|
|
45
|
+
* **Security Warning**: Never use this middleware in client-side code or expose
|
|
46
|
+
* the admin secret to end users. Admin secrets grant unrestricted access to your
|
|
47
|
+
* entire database. This should only be used in trusted server-side environments.
|
|
48
|
+
*
|
|
49
|
+
* The middleware preserves request-specific headers when they conflict with the
|
|
50
|
+
* admin session configuration.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Admin session options including admin secret, role, and session variables
|
|
53
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* // Create middleware with admin secret only
|
|
58
|
+
* const adminMiddleware = withAdminSessionMiddleware({
|
|
59
|
+
* adminSecret: process.env.NHOST_ADMIN_SECRET
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Create middleware with admin secret and role
|
|
63
|
+
* const adminUserMiddleware = withAdminSessionMiddleware({
|
|
64
|
+
* adminSecret: process.env.NHOST_ADMIN_SECRET,
|
|
65
|
+
* role: 'user'
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // Create middleware with admin secret, role, and custom session variables
|
|
69
|
+
* const fullMiddleware = withAdminSessionMiddleware({
|
|
70
|
+
* adminSecret: process.env.NHOST_ADMIN_SECRET,
|
|
71
|
+
* role: 'user',
|
|
72
|
+
* sessionVariables: {
|
|
73
|
+
* 'user-id': '123',
|
|
74
|
+
* 'org-id': '456'
|
|
75
|
+
* }
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // Use with createCustomClient for an admin client
|
|
79
|
+
* const adminClient = createCustomClient({
|
|
80
|
+
* subdomain: 'myproject',
|
|
81
|
+
* region: 'eu-central-1',
|
|
82
|
+
* chainFunctions: [adminMiddleware]
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare const withAdminSessionMiddleware: (options: AdminSessionOptions) => ChainFunction;
|
|
87
|
+
//# sourceMappingURL=middlewareWithAdminSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareWithAdminSession.d.ts","sourceRoot":"","sources":["../../../src/fetch/middlewareWithAdminSession.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,SAAS,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;;;;;OAcG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,0BAA0B,GACpC,SAAS,mBAAmB,KAAG,aA6B/B,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin session middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically attach
|
|
5
|
+
* Hasura admin secret for admin permissions in requests.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates a fetch middleware that attaches the Hasura admin secret and optional session variables to requests.
|
|
9
|
+
*
|
|
10
|
+
* This middleware:
|
|
11
|
+
* 1. Sets the x-hasura-admin-secret header, which grants full admin access to Hasura
|
|
12
|
+
* 2. Optionally sets the x-hasura-role header if a role is provided
|
|
13
|
+
* 3. Optionally sets additional x-hasura-* headers for custom session variables
|
|
14
|
+
*
|
|
15
|
+
* **Security Warning**: Never use this middleware in client-side code or expose
|
|
16
|
+
* the admin secret to end users. Admin secrets grant unrestricted access to your
|
|
17
|
+
* entire database. This should only be used in trusted server-side environments.
|
|
18
|
+
*
|
|
19
|
+
* The middleware preserves request-specific headers when they conflict with the
|
|
20
|
+
* admin session configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Admin session options including admin secret, role, and session variables
|
|
23
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Create middleware with admin secret only
|
|
28
|
+
* const adminMiddleware = withAdminSessionMiddleware({
|
|
29
|
+
* adminSecret: process.env.NHOST_ADMIN_SECRET
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Create middleware with admin secret and role
|
|
33
|
+
* const adminUserMiddleware = withAdminSessionMiddleware({
|
|
34
|
+
* adminSecret: process.env.NHOST_ADMIN_SECRET,
|
|
35
|
+
* role: 'user'
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Create middleware with admin secret, role, and custom session variables
|
|
39
|
+
* const fullMiddleware = withAdminSessionMiddleware({
|
|
40
|
+
* adminSecret: process.env.NHOST_ADMIN_SECRET,
|
|
41
|
+
* role: 'user',
|
|
42
|
+
* sessionVariables: {
|
|
43
|
+
* 'user-id': '123',
|
|
44
|
+
* 'org-id': '456'
|
|
45
|
+
* }
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Use with createCustomClient for an admin client
|
|
49
|
+
* const adminClient = createCustomClient({
|
|
50
|
+
* subdomain: 'myproject',
|
|
51
|
+
* region: 'eu-central-1',
|
|
52
|
+
* chainFunctions: [adminMiddleware]
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const withAdminSessionMiddleware = (options) => (next) => async (url, requestOptions = {}) => {
|
|
57
|
+
const headers = new Headers(requestOptions.headers || {});
|
|
58
|
+
// Set x-hasura-admin-secret if not already present
|
|
59
|
+
if (!headers.has("x-hasura-admin-secret")) {
|
|
60
|
+
headers.set("x-hasura-admin-secret", options.adminSecret);
|
|
61
|
+
}
|
|
62
|
+
// Set x-hasura-role if provided and not already present
|
|
63
|
+
if (options.role && !headers.has("x-hasura-role")) {
|
|
64
|
+
headers.set("x-hasura-role", options.role);
|
|
65
|
+
}
|
|
66
|
+
// Set custom session variables
|
|
67
|
+
if (options.sessionVariables) {
|
|
68
|
+
for (const [key, value] of Object.entries(options.sessionVariables)) {
|
|
69
|
+
// Ensure the key has the x-hasura- prefix
|
|
70
|
+
const headerKey = key.startsWith("x-hasura-") ? key : `x-hasura-${key}`;
|
|
71
|
+
// Only set if not already present in the request
|
|
72
|
+
if (!headers.has(headerKey)) {
|
|
73
|
+
headers.set(headerKey, value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return next(url, { ...requestOptions, headers });
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=middlewareWithAdminSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareWithAdminSession.js","sourceRoot":"","sources":["../../../src/fetch/middlewareWithAdminSession.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoCH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,CAAC,MAAM,0BAA0B,GACrC,CAAC,OAA4B,EAAiB,EAAE,CAChD,CAAC,IAAmB,EAAiB,EAAE,CACvC,KAAK,EAAE,GAAW,EAAE,iBAA8B,EAAE,EAAqB,EAAE;IACzE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE1D,mDAAmD;IACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5D,CAAC;IAED,wDAAwD;IACxD,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,+BAA+B;IAC/B,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACpE,0CAA0C;YAC1C,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,GAAG,EAAE,CAAC;YAExE,iDAAiD;YACjD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headers middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically attach
|
|
5
|
+
* default headers to all outgoing requests, while allowing request-specific
|
|
6
|
+
* headers to take precedence.
|
|
7
|
+
*/
|
|
8
|
+
import type { ChainFunction } from "./fetch";
|
|
9
|
+
/**
|
|
10
|
+
* Creates a fetch middleware that attaches default headers to requests.
|
|
11
|
+
*
|
|
12
|
+
* This middleware:
|
|
13
|
+
* 1. Merges default headers with request-specific headers
|
|
14
|
+
* 2. Preserves request-specific headers when they conflict with defaults
|
|
15
|
+
*
|
|
16
|
+
* The middleware ensures consistent headers across requests while allowing
|
|
17
|
+
* individual requests to override defaults as needed.
|
|
18
|
+
*
|
|
19
|
+
* @param defaultHeaders - Default headers to attach to all requests
|
|
20
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
21
|
+
*/
|
|
22
|
+
export declare const withHeadersMiddleware: (defaultHeaders: HeadersInit) => ChainFunction;
|
|
23
|
+
//# sourceMappingURL=middlewareWithHeaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareWithHeaders.d.ts","sourceRoot":"","sources":["../../../src/fetch/middlewareWithHeaders.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,SAAS,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GAC/B,gBAAgB,WAAW,KAAG,aAa9B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headers middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically attach
|
|
5
|
+
* default headers to all outgoing requests, while allowing request-specific
|
|
6
|
+
* headers to take precedence.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a fetch middleware that attaches default headers to requests.
|
|
10
|
+
*
|
|
11
|
+
* This middleware:
|
|
12
|
+
* 1. Merges default headers with request-specific headers
|
|
13
|
+
* 2. Preserves request-specific headers when they conflict with defaults
|
|
14
|
+
*
|
|
15
|
+
* The middleware ensures consistent headers across requests while allowing
|
|
16
|
+
* individual requests to override defaults as needed.
|
|
17
|
+
*
|
|
18
|
+
* @param defaultHeaders - Default headers to attach to all requests
|
|
19
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
20
|
+
*/
|
|
21
|
+
export const withHeadersMiddleware = (defaultHeaders) => (next) => async (url, options = {}) => {
|
|
22
|
+
const headers = new Headers(options.headers || {});
|
|
23
|
+
const defaults = new Headers(defaultHeaders);
|
|
24
|
+
defaults.forEach((value, key) => {
|
|
25
|
+
if (!headers.has(key)) {
|
|
26
|
+
headers.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return next(url, { ...options, headers });
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=middlewareWithHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareWithHeaders.js","sourceRoot":"","sources":["../../../src/fetch/middlewareWithHeaders.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAChC,CAAC,cAA2B,EAAiB,EAAE,CAC/C,CAAC,IAAmB,EAAiB,EAAE,CACvC,KAAK,EAAE,GAAW,EAAE,UAAuB,EAAE,EAAqB,EAAE;IAClE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC;IAE7C,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically set
|
|
5
|
+
* the Hasura role for all requests. This is useful when you want to
|
|
6
|
+
* make requests as a specific role without using the admin secret.
|
|
7
|
+
*/
|
|
8
|
+
import type { ChainFunction } from "./fetch";
|
|
9
|
+
/**
|
|
10
|
+
* Creates a fetch middleware that sets the Hasura role header.
|
|
11
|
+
*
|
|
12
|
+
* This middleware sets the x-hasura-role header for all requests, allowing
|
|
13
|
+
* you to specify which role's permissions should be used. This works with
|
|
14
|
+
* authenticated sessions where the user has access to the specified role.
|
|
15
|
+
*
|
|
16
|
+
* Unlike `withAdminSessionMiddleware`, this does not bypass permission rules
|
|
17
|
+
* but instead uses the permission rules defined for the specified role.
|
|
18
|
+
*
|
|
19
|
+
* The middleware preserves request-specific headers when they conflict with
|
|
20
|
+
* the role configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param role - The Hasura role to use for requests
|
|
23
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Use with createClient to default all requests to a specific role
|
|
28
|
+
* const nhost = createClient({
|
|
29
|
+
* subdomain: 'myproject',
|
|
30
|
+
* region: 'eu-central-1',
|
|
31
|
+
* chainFunctions: [withRoleMiddleware('moderator')]
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Use with createServerClient for server-side requests
|
|
35
|
+
* const serverNhost = createServerClient({
|
|
36
|
+
* subdomain: 'myproject',
|
|
37
|
+
* region: 'eu-central-1',
|
|
38
|
+
* storage: myServerStorage,
|
|
39
|
+
* chainFunctions: [withRoleMiddleware('moderator')]
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const withRoleMiddleware: (role: string) => ChainFunction;
|
|
44
|
+
//# sourceMappingURL=middlewareWithRole.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareWithRole.d.ts","sourceRoot":"","sources":["../../../src/fetch/middlewareWithRole.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,SAAS,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,kBAAkB,GAC5B,MAAM,MAAM,KAAG,aAWf,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role middleware for the Nhost SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides middleware functionality to automatically set
|
|
5
|
+
* the Hasura role for all requests. This is useful when you want to
|
|
6
|
+
* make requests as a specific role without using the admin secret.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a fetch middleware that sets the Hasura role header.
|
|
10
|
+
*
|
|
11
|
+
* This middleware sets the x-hasura-role header for all requests, allowing
|
|
12
|
+
* you to specify which role's permissions should be used. This works with
|
|
13
|
+
* authenticated sessions where the user has access to the specified role.
|
|
14
|
+
*
|
|
15
|
+
* Unlike `withAdminSessionMiddleware`, this does not bypass permission rules
|
|
16
|
+
* but instead uses the permission rules defined for the specified role.
|
|
17
|
+
*
|
|
18
|
+
* The middleware preserves request-specific headers when they conflict with
|
|
19
|
+
* the role configuration.
|
|
20
|
+
*
|
|
21
|
+
* @param role - The Hasura role to use for requests
|
|
22
|
+
* @returns A middleware function that can be used in the fetch chain
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Use with createClient to default all requests to a specific role
|
|
27
|
+
* const nhost = createClient({
|
|
28
|
+
* subdomain: 'myproject',
|
|
29
|
+
* region: 'eu-central-1',
|
|
30
|
+
* chainFunctions: [withRoleMiddleware('moderator')]
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Use with createServerClient for server-side requests
|
|
34
|
+
* const serverNhost = createServerClient({
|
|
35
|
+
* subdomain: 'myproject',
|
|
36
|
+
* region: 'eu-central-1',
|
|
37
|
+
* storage: myServerStorage,
|
|
38
|
+
* chainFunctions: [withRoleMiddleware('moderator')]
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export const withRoleMiddleware = (role) => (next) => async (url, requestOptions = {}) => {
|
|
43
|
+
const headers = new Headers(requestOptions.headers || {});
|
|
44
|
+
// Set x-hasura-role if not already present
|
|
45
|
+
if (!headers.has("x-hasura-role")) {
|
|
46
|
+
headers.set("x-hasura-role", role);
|
|
47
|
+
}
|
|
48
|
+
return next(url, { ...requestOptions, headers });
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=middlewareWithRole.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewareWithRole.js","sourceRoot":"","sources":["../../../src/fetch/middlewareWithRole.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAC,IAAY,EAAiB,EAAE,CAChC,CAAC,IAAmB,EAAiB,EAAE,CACvC,KAAK,EAAE,GAAW,EAAE,iBAA8B,EAAE,EAAqB,EAAE;IACzE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE1D,2CAA2C;IAC3C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -10,6 +10,10 @@ import { type ChainFunction, type FetchResponse } from "../fetch";
|
|
|
10
10
|
*/
|
|
11
11
|
export interface Client {
|
|
12
12
|
baseURL: string;
|
|
13
|
+
/** Add a middleware function to the fetch chain
|
|
14
|
+
* @param chainFunction - The middleware function to add
|
|
15
|
+
*/
|
|
16
|
+
pushChainFunction(chainFunction: ChainFunction): void;
|
|
13
17
|
/**
|
|
14
18
|
* Execute a request to a serverless function
|
|
15
19
|
* The response body will be automatically parsed based on the content type into the following types:
|
|
@@ -19,7 +23,8 @@ export interface Client {
|
|
|
19
23
|
*
|
|
20
24
|
* @param path - The path to the serverless function
|
|
21
25
|
* @param options - Additional fetch options to apply to the request
|
|
22
|
-
* @returns Promise with the function response and metadata.
|
|
26
|
+
* @returns Promise with the function response and metadata.
|
|
27
|
+
*/
|
|
23
28
|
fetch<T = unknown>(path: string, options?: RequestInit): Promise<FetchResponse<T>>;
|
|
24
29
|
/**
|
|
25
30
|
* Executes a POST request to a serverless function with a JSON body
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/functions/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAEhB
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/functions/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,iBAAiB,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;IAEtD;;;;;;;;;;OAUG;IACH,KAAK,CAAC,CAAC,GAAG,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7B;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,iBAAgB,aAAa,EAAO,KACnC,MAuFF,CAAC"}
|
|
@@ -17,7 +17,11 @@ import { createEnhancedFetch, FetchError, } from "../fetch";
|
|
|
17
17
|
* @returns Functions client with fetch method
|
|
18
18
|
*/
|
|
19
19
|
export const createAPIClient = (baseURL, chainFunctions = []) => {
|
|
20
|
-
|
|
20
|
+
let enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
21
|
+
const pushChainFunction = (chainFunction) => {
|
|
22
|
+
chainFunctions.push(chainFunction);
|
|
23
|
+
enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
24
|
+
};
|
|
21
25
|
/**
|
|
22
26
|
* Executes a request to a serverless function and processes the response
|
|
23
27
|
*
|
|
@@ -84,6 +88,7 @@ export const createAPIClient = (baseURL, chainFunctions = []) => {
|
|
|
84
88
|
baseURL,
|
|
85
89
|
fetch,
|
|
86
90
|
post,
|
|
91
|
+
pushChainFunction,
|
|
87
92
|
};
|
|
88
93
|
};
|
|
89
94
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/functions/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,mBAAmB,EACnB,UAAU,GAEX,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/functions/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,mBAAmB,EACnB,UAAU,GAEX,MAAM,UAAU,CAAC;AAkDlB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAe,EACf,iBAAkC,EAAE,EAC5B,EAAE;IACV,IAAI,aAAa,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAExD,MAAM,iBAAiB,GAAG,CAAC,aAA4B,EAAE,EAAE;QACzD,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CA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gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO,CAAC,OAAO;aACnB;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;QAEF,OAAO,KAAK,CAAI,IAAI,EAAE,cAAc,CAAC,CAAC;IACxC,CAAC,CAAC;IAEF,6CAA6C;IAC7C,OAAO;QACL,OAAO;QACP,KAAK;QACL,IAAI;QACJ,iBAAiB;KACR,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -77,6 +77,10 @@ export interface Client {
|
|
|
77
77
|
* URL for the GraphQL endpoint.
|
|
78
78
|
*/
|
|
79
79
|
url: string;
|
|
80
|
+
/** Add a middleware function to the fetch chain
|
|
81
|
+
* @param chainFunction - The middleware function to add
|
|
82
|
+
*/
|
|
83
|
+
pushChainFunction(chainFunction: ChainFunction): void;
|
|
80
84
|
}
|
|
81
85
|
/**
|
|
82
86
|
* Creates a GraphQL API client for interacting with a GraphQL endpoint.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/graphql/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EACL,KAAK,aAAa,EAGlB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,UAAU,GAAG,gBAAgB;IAC3D,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;C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E1D;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa,EAAE,UAAU,GAAG,gBAAgB,EAClD,QAAQ,EAAE,iBAAiB,CAAC,aAAa,EAAE,UAAU,CAAC,EACtD,SAAS,CAAC,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAE1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,iBAAiB,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;CACvD;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,MAAM,EACX,iBAAgB,aAAa,EAAO,KACnC,MAmFF,CAAC"}
|
|
@@ -17,7 +17,11 @@ import { createEnhancedFetch, FetchError, } from "../fetch";
|
|
|
17
17
|
* @returns GraphQL client with query and mutation methods
|
|
18
18
|
*/
|
|
19
19
|
export const createAPIClient = (url, chainFunctions = []) => {
|
|
20
|
-
|
|
20
|
+
let enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
21
|
+
const pushChainFunction = (chainFunction) => {
|
|
22
|
+
chainFunctions.push(chainFunction);
|
|
23
|
+
enhancedFetch = createEnhancedFetch(chainFunctions);
|
|
24
|
+
};
|
|
21
25
|
const executeOperation = async (request, options) => {
|
|
22
26
|
const response = await enhancedFetch(`${url}`, {
|
|
23
27
|
method: "POST",
|
|
@@ -61,6 +65,7 @@ export const createAPIClient = (url, chainFunctions = []) => {
|
|
|
61
65
|
return {
|
|
62
66
|
request,
|
|
63
67
|
url,
|
|
68
|
+
pushChainFunction,
|
|
64
69
|
};
|
|
65
70
|
};
|
|
66
71
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/graphql/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAEL,mBAAmB,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E,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAWF,SAAS,OAAO,CACd,iBAEgD,EAChD,kBAA6C,EAC7C,OAAqB;QAErB,IAAI,OAAO,iBAAiB,KAAK,QAAQ,IAAI,MAAM,IAAI,iBAAiB,EAAE,CAAC;YACzE,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAEpD,MAAM,OAAO,GAA+B;gBAC1C,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;gBAC/C,SAAS,EAAE,kBAAgC;gBAC3C,aAAa,EACX,UAAU,IAAI,MAAM,IAAI,UAAU;oBAChC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK;oBACxB,CAAC,CAAC,SAAS;aAChB,CAAC;YACF,OAAO,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,wBAAwB;YACxB,MAAM,OAAO,GAAG,iBAAiB,CAAC;YAClC,MAAM,cAAc,GAAG,kBAAiC,CAAC;YACzD,OAAO,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,GAAG;QACH,iBAAiB;KACR,CAAC;AACd,CAAC,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -17,11 +17,21 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Create a client instance to interact with Nhost services:
|
|
19
19
|
*
|
|
20
|
-
* {@includeCode ./__tests__/docstrings.test.ts:
|
|
20
|
+
* {@includeCode ./__tests__/docstrings.test.ts:15-119}
|
|
21
|
+
*
|
|
22
|
+
* ### Creating an admin client
|
|
23
|
+
*
|
|
24
|
+
* You can also create an admin client if needed. This client will have admin access to the database
|
|
25
|
+
* and will bypass permissions. Additionally, it can impersonate users and set any role or session
|
|
26
|
+
* variable.
|
|
27
|
+
*
|
|
28
|
+
* IMPORTANT!!! Keep your admin secret safe and never expose it in client-side code.
|
|
29
|
+
*
|
|
30
|
+
* {@includeCode ./__tests__/docstrings.test.ts:142-201}
|
|
21
31
|
*
|
|
22
32
|
* @packageDocumentation
|
|
23
33
|
*/
|
|
24
|
-
export { createClient, createServerClient, type NhostClient, type NhostClientOptions, type NhostServerClientOptions, } from "./nhost";
|
|
34
|
+
export { type ClientConfigurationFn, createClient, createNhostClient, createServerClient, type NhostClient, type NhostClientOptions, type NhostServerClientOptions, withAdminSession, withClientSideSessionMiddleware, withServerSideSessionMiddleware, } from "./nhost";
|
|
25
35
|
/**
|
|
26
36
|
* Generates a base URL for a Nhost service based on configuration
|
|
27
37
|
*
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EACL,KAAK,qBAAqB,EAC1B,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,gBAAgB,EAChB,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC7B,aAAa,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,EACzD,YAAY,MAAM,EAClB,SAAS,MAAM,EACf,YAAY,MAAM,KACjB,MAQF,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -17,11 +17,21 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Create a client instance to interact with Nhost services:
|
|
19
19
|
*
|
|
20
|
-
* {@includeCode ./__tests__/docstrings.test.ts:
|
|
20
|
+
* {@includeCode ./__tests__/docstrings.test.ts:15-119}
|
|
21
|
+
*
|
|
22
|
+
* ### Creating an admin client
|
|
23
|
+
*
|
|
24
|
+
* You can also create an admin client if needed. This client will have admin access to the database
|
|
25
|
+
* and will bypass permissions. Additionally, it can impersonate users and set any role or session
|
|
26
|
+
* variable.
|
|
27
|
+
*
|
|
28
|
+
* IMPORTANT!!! Keep your admin secret safe and never expose it in client-side code.
|
|
29
|
+
*
|
|
30
|
+
* {@includeCode ./__tests__/docstrings.test.ts:142-201}
|
|
21
31
|
*
|
|
22
32
|
* @packageDocumentation
|
|
23
33
|
*/
|
|
24
|
-
export { createClient, createServerClient, } from "./nhost";
|
|
34
|
+
export { createClient, createNhostClient, createServerClient, withAdminSession, withClientSideSessionMiddleware, withServerSideSessionMiddleware, } from "./nhost";
|
|
25
35
|
/**
|
|
26
36
|
* Generates a base URL for a Nhost service based on configuration
|
|
27
37
|
*
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAEL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAIlB,gBAAgB,EAChB,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,WAAyD,EACzD,SAAkB,EAClB,MAAe,EACf,SAAkB,EACV,EAAE;IACV,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;SAAM,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QAC/B,OAAO,WAAW,SAAS,IAAI,WAAW,IAAI,MAAM,eAAe,CAAC;IACtE,CAAC;SAAM,CAAC;QACN,OAAO,iBAAiB,WAAW,qBAAqB,CAAC;IAC3D,CAAC;AACH,CAAC,CAAC"}
|