@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.
Files changed (147) hide show
  1. package/README.md +67 -32
  2. package/dist/fetch-2PHmQBIJ.mjs +61 -0
  3. package/dist/fetch-2PHmQBIJ.mjs.map +1 -0
  4. package/dist/fetch-DWXwEnoe.js +2 -0
  5. package/dist/fetch-DWXwEnoe.js.map +1 -0
  6. package/dist/nhost-js/auth.cjs.js +2 -0
  7. package/dist/nhost-js/auth.cjs.js.map +1 -0
  8. package/dist/nhost-js/auth.es.js +917 -0
  9. package/dist/nhost-js/auth.es.js.map +1 -0
  10. package/dist/nhost-js/fetch.cjs.js +2 -0
  11. package/dist/nhost-js/fetch.cjs.js.map +1 -0
  12. package/dist/nhost-js/fetch.es.js +90 -0
  13. package/dist/nhost-js/fetch.es.js.map +1 -0
  14. package/dist/nhost-js/functions.cjs.js +2 -0
  15. package/dist/nhost-js/functions.cjs.js.map +1 -0
  16. package/dist/nhost-js/functions.es.js +45 -0
  17. package/dist/nhost-js/functions.es.js.map +1 -0
  18. package/dist/nhost-js/graphql.cjs.js +2 -0
  19. package/dist/nhost-js/graphql.cjs.js.map +1 -0
  20. package/dist/nhost-js/graphql.es.js +48 -0
  21. package/dist/nhost-js/graphql.es.js.map +1 -0
  22. package/dist/nhost-js/session.cjs.js +2 -0
  23. package/dist/nhost-js/session.cjs.js.map +1 -0
  24. package/dist/nhost-js/session.es.js +234 -0
  25. package/dist/nhost-js/session.es.js.map +1 -0
  26. package/dist/nhost-js/storage.cjs.js +2 -0
  27. package/dist/nhost-js/storage.cjs.js.map +1 -0
  28. package/dist/nhost-js/storage.es.js +324 -0
  29. package/dist/nhost-js/storage.es.js.map +1 -0
  30. package/dist/nhost-js.cjs.js +2 -0
  31. package/dist/nhost-js.cjs.js.map +1 -0
  32. package/dist/nhost-js.es.js +228 -0
  33. package/dist/nhost-js.es.js.map +1 -0
  34. package/dist/nhost-js.umd.js +2 -0
  35. package/dist/nhost-js.umd.js.map +1 -0
  36. package/dist/refreshSession-Bw715ZmX.js +2 -0
  37. package/dist/refreshSession-Bw715ZmX.js.map +1 -0
  38. package/dist/refreshSession-WwGlzgtM.mjs +95 -0
  39. package/dist/refreshSession-WwGlzgtM.mjs.map +1 -0
  40. package/dist/src/auth/client.d.ts +1763 -0
  41. package/dist/src/auth/client.d.ts.map +1 -0
  42. package/dist/src/auth/client.js +1043 -0
  43. package/dist/src/auth/client.js.map +1 -0
  44. package/dist/src/auth/index.d.ts +35 -0
  45. package/dist/src/auth/index.d.ts.map +1 -0
  46. package/dist/src/auth/index.js +35 -0
  47. package/dist/src/auth/index.js.map +1 -0
  48. package/dist/src/fetch/fetch.d.ts +88 -0
  49. package/dist/src/fetch/fetch.d.ts.map +1 -0
  50. package/dist/src/fetch/fetch.js +98 -0
  51. package/dist/src/fetch/fetch.js.map +1 -0
  52. package/dist/src/fetch/index.d.ts +38 -0
  53. package/dist/src/fetch/index.d.ts.map +1 -0
  54. package/dist/src/fetch/index.js +38 -0
  55. package/dist/src/fetch/index.js.map +1 -0
  56. package/dist/src/fetch/middlewareAttachAccessToken.d.ts +24 -0
  57. package/dist/src/fetch/middlewareAttachAccessToken.d.ts.map +1 -0
  58. package/dist/src/fetch/middlewareAttachAccessToken.js +54 -0
  59. package/dist/src/fetch/middlewareAttachAccessToken.js.map +1 -0
  60. package/dist/src/fetch/middlewareSessionRefresh.d.ts +30 -0
  61. package/dist/src/fetch/middlewareSessionRefresh.d.ts.map +1 -0
  62. package/dist/src/fetch/middlewareSessionRefresh.js +61 -0
  63. package/dist/src/fetch/middlewareSessionRefresh.js.map +1 -0
  64. package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts +26 -0
  65. package/dist/src/fetch/middlewareUpdateSessionFromResponse.d.ts.map +1 -0
  66. package/dist/src/fetch/middlewareUpdateSessionFromResponse.js +79 -0
  67. package/dist/src/fetch/middlewareUpdateSessionFromResponse.js.map +1 -0
  68. package/dist/src/functions/client.d.ts +52 -0
  69. package/dist/src/functions/client.d.ts.map +1 -0
  70. package/dist/src/functions/client.js +89 -0
  71. package/dist/src/functions/client.js.map +1 -0
  72. package/dist/src/functions/index.d.ts +43 -0
  73. package/dist/src/functions/index.d.ts.map +1 -0
  74. package/dist/src/functions/index.js +43 -0
  75. package/dist/src/functions/index.js.map +1 -0
  76. package/dist/src/graphql/client.d.ts +93 -0
  77. package/dist/src/graphql/client.d.ts.map +1 -0
  78. package/dist/src/graphql/client.js +66 -0
  79. package/dist/src/graphql/client.js.map +1 -0
  80. package/dist/src/graphql/index.d.ts +65 -0
  81. package/dist/src/graphql/index.d.ts.map +1 -0
  82. package/dist/src/graphql/index.js +65 -0
  83. package/dist/src/graphql/index.js.map +1 -0
  84. package/dist/src/index.d.ts +35 -0
  85. package/dist/src/index.d.ts.map +1 -0
  86. package/dist/src/index.js +45 -0
  87. package/dist/src/index.js.map +1 -0
  88. package/dist/src/nhost.d.ts +301 -0
  89. package/dist/src/nhost.d.ts.map +1 -0
  90. package/dist/src/nhost.js +323 -0
  91. package/dist/src/nhost.js.map +1 -0
  92. package/dist/src/session/index.d.ts +20 -0
  93. package/dist/src/session/index.d.ts.map +1 -0
  94. package/dist/src/session/index.js +19 -0
  95. package/dist/src/session/index.js.map +1 -0
  96. package/dist/src/session/refreshSession.d.ts +17 -0
  97. package/dist/src/session/refreshSession.d.ts.map +1 -0
  98. package/dist/src/session/refreshSession.js +120 -0
  99. package/dist/src/session/refreshSession.js.map +1 -0
  100. package/dist/src/session/session.d.ts +24 -0
  101. package/dist/src/session/session.d.ts.map +1 -0
  102. package/dist/src/session/session.js +48 -0
  103. package/dist/src/session/session.js.map +1 -0
  104. package/dist/src/session/storage.d.ts +62 -0
  105. package/dist/src/session/storage.d.ts.map +1 -0
  106. package/dist/src/session/storage.js +91 -0
  107. package/dist/src/session/storage.js.map +1 -0
  108. package/dist/src/session/storageBackend.d.ts +122 -0
  109. package/dist/src/session/storageBackend.d.ts.map +1 -0
  110. package/dist/src/session/storageBackend.js +145 -0
  111. package/dist/src/session/storageBackend.js.map +1 -0
  112. package/dist/src/storage/client.d.ts +546 -0
  113. package/dist/src/storage/client.d.ts.map +1 -0
  114. package/dist/src/storage/client.js +368 -0
  115. package/dist/src/storage/client.js.map +1 -0
  116. package/dist/src/storage/index.d.ts +37 -0
  117. package/dist/src/storage/index.d.ts.map +1 -0
  118. package/dist/src/storage/index.js +37 -0
  119. package/dist/src/storage/index.js.map +1 -0
  120. package/dist/tsconfig.tsbuildinfo +1 -0
  121. package/package.json +103 -59
  122. package/dist/clients/auth.d.ts +0 -8
  123. package/dist/clients/auth.d.ts.map +0 -1
  124. package/dist/clients/functions/index.d.ts +0 -107
  125. package/dist/clients/functions/index.d.ts.map +0 -1
  126. package/dist/clients/functions/types.d.ts +0 -28
  127. package/dist/clients/functions/types.d.ts.map +0 -1
  128. package/dist/clients/graphql.d.ts +0 -8
  129. package/dist/clients/graphql.d.ts.map +0 -1
  130. package/dist/clients/index.d.ts +0 -6
  131. package/dist/clients/index.d.ts.map +0 -1
  132. package/dist/clients/nhost.d.ts +0 -83
  133. package/dist/clients/nhost.d.ts.map +0 -1
  134. package/dist/clients/storage.d.ts +0 -8
  135. package/dist/clients/storage.d.ts.map +0 -1
  136. package/dist/index.cjs.js +0 -2
  137. package/dist/index.cjs.js.map +0 -1
  138. package/dist/index.d.ts +0 -6
  139. package/dist/index.d.ts.map +0 -1
  140. package/dist/index.esm.js +0 -356
  141. package/dist/index.esm.js.map +0 -1
  142. package/dist/utils/helpers.d.ts +0 -20
  143. package/dist/utils/helpers.d.ts.map +0 -1
  144. package/dist/utils/types.d.ts +0 -57
  145. package/dist/utils/types.d.ts.map +0 -1
  146. package/umd/nhost-js.umd.js +0 -22
  147. package/umd/nhost-js.umd.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/graphql/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAEH,cAAc,UAAU,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Main entry point for the Nhost JavaScript SDK.
3
+ *
4
+ * This package provides a unified client for interacting with Nhost services:
5
+ * - Authentication
6
+ * - Storage
7
+ * - GraphQL
8
+ * - Functions
9
+ *
10
+ * ## Import
11
+ *
12
+ * ```ts
13
+ * import { createClient } from "@nhost/nhost-js";
14
+ * ```
15
+ *
16
+ * ## Usage
17
+ *
18
+ * Create a client instance to interact with Nhost services:
19
+ *
20
+ * {@includeCode ./__tests__/docstrings.test.ts:11-115}
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ export { createClient, createServerClient, type NhostClient, type NhostClientOptions, type NhostServerClientOptions, } from "./nhost";
25
+ /**
26
+ * Generates a base URL for a Nhost service based on configuration
27
+ *
28
+ * @param serviceType - Type of service (auth, storage, graphql, functions)
29
+ * @param subdomain - Nhost project subdomain
30
+ * @param region - Nhost region
31
+ * @param customUrl - Custom URL override if provided
32
+ * @returns The base URL for the service
33
+ */
34
+ export declare const generateServiceUrl: (serviceType: "auth" | "storage" | "graphql" | "functions", subdomain?: string, region?: string, customUrl?: string) => string;
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,GAC9B,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"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Main entry point for the Nhost JavaScript SDK.
3
+ *
4
+ * This package provides a unified client for interacting with Nhost services:
5
+ * - Authentication
6
+ * - Storage
7
+ * - GraphQL
8
+ * - Functions
9
+ *
10
+ * ## Import
11
+ *
12
+ * ```ts
13
+ * import { createClient } from "@nhost/nhost-js";
14
+ * ```
15
+ *
16
+ * ## Usage
17
+ *
18
+ * Create a client instance to interact with Nhost services:
19
+ *
20
+ * {@includeCode ./__tests__/docstrings.test.ts:11-115}
21
+ *
22
+ * @packageDocumentation
23
+ */
24
+ export { createClient, createServerClient, } from "./nhost";
25
+ /**
26
+ * Generates a base URL for a Nhost service based on configuration
27
+ *
28
+ * @param serviceType - Type of service (auth, storage, graphql, functions)
29
+ * @param subdomain - Nhost project subdomain
30
+ * @param region - Nhost region
31
+ * @param customUrl - Custom URL override if provided
32
+ * @returns The base URL for the service
33
+ */
34
+ export const generateServiceUrl = (serviceType, subdomain, region, customUrl) => {
35
+ if (customUrl) {
36
+ return customUrl;
37
+ }
38
+ else if (subdomain && region) {
39
+ return `https://${subdomain}.${serviceType}.${region}.nhost.run/v1`;
40
+ }
41
+ else {
42
+ return `https://local.${serviceType}.local.nhost.run/v1`;
43
+ }
44
+ };
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,YAAY,EACZ,kBAAkB,GAInB,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"}
@@ -0,0 +1,301 @@
1
+ import { type Client as AuthClient } from "./auth";
2
+ import { type Client as FunctionsClient } from "./functions";
3
+ import { type Client as GraphQLClient } from "./graphql";
4
+ import { type Session, SessionStorage, type SessionStorageBackend } from "./session/";
5
+ import { type Client as StorageClient } from "./storage";
6
+ /**
7
+ * Main client class that provides unified access to all Nhost services.
8
+ * This class serves as the central interface for interacting with Nhost's
9
+ * authentication, storage, GraphQL, and serverless functions capabilities.
10
+ */
11
+ export declare class NhostClient {
12
+ /**
13
+ * Authentication client providing methods for user sign-in, sign-up, and session management.
14
+ * Use this client to handle all authentication-related operations.
15
+ */
16
+ auth: AuthClient;
17
+ /**
18
+ * Storage client providing methods for file operations (upload, download, delete).
19
+ * Use this client to manage files in your Nhost storage.
20
+ */
21
+ storage: StorageClient;
22
+ /**
23
+ * GraphQL client providing methods for executing GraphQL operations against your Hasura backend.
24
+ * Use this client to query and mutate data in your database through GraphQL.
25
+ */
26
+ graphql: GraphQLClient;
27
+ /**
28
+ * Functions client providing methods for invoking serverless functions.
29
+ * Use this client to call your custom serverless functions deployed to Nhost.
30
+ */
31
+ functions: FunctionsClient;
32
+ /**
33
+ * Storage implementation used for persisting session information.
34
+ * This handles saving, retrieving, and managing authentication sessions across requests.
35
+ */
36
+ sessionStorage: SessionStorage;
37
+ /**
38
+ * Create a new Nhost client. This constructor is reserved for advanced use cases.
39
+ * For typical usage, use [createClient](#createclient) or [createServerClient](#createserverclient) instead.
40
+ *
41
+ * @param auth - Authentication client instance
42
+ * @param storage - Storage client instance
43
+ * @param graphql - GraphQL client instance
44
+ * @param functions - Functions client instance
45
+ * @param sessionStorage - Storage implementation for session persistence
46
+ */
47
+ constructor(auth: AuthClient, storage: StorageClient, graphql: GraphQLClient, functions: FunctionsClient, sessionStorage: SessionStorage);
48
+ /**
49
+ * Get the current session from storage.
50
+ * This method retrieves the authenticated user's session information if one exists.
51
+ *
52
+ * @returns The current session or null if no session exists
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const session = nhost.getUserSession();
57
+ * if (session) {
58
+ * console.log('User is authenticated:', session.user.id);
59
+ * } else {
60
+ * console.log('No active session');
61
+ * }
62
+ * ```
63
+ */
64
+ getUserSession(): Session | null;
65
+ /**
66
+ * Refresh the session using the current refresh token
67
+ * in the storage and update the storage with the new session.
68
+ *
69
+ * This method can be used to proactively refresh tokens before they expire
70
+ * or to force a refresh when needed.
71
+ *
72
+ * @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.
73
+ *
74
+ * @returns The new session or null if there is currently no session or if refresh fails
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * // Refresh token if it's about to expire in the next 5 minutes
79
+ * const refreshedSession = await nhost.refreshSession(300);
80
+ *
81
+ * // Force refresh regardless of current token expiration
82
+ * const forcedRefresh = await nhost.refreshSession(0);
83
+ * ```
84
+ */
85
+ refreshSession(marginSeconds?: number): Promise<Session | null>;
86
+ /**
87
+ * Clear the session from storage.
88
+ *
89
+ * This method removes the current authentication session, effectively logging out the user.
90
+ * Note that this is a client-side operation and doesn't invalidate the refresh token on
91
+ * the server, which can be done with `nhost.auth.signOut({refreshToken: session.refreshTokenId})`.
92
+ * If the middle `updateSessionFromResponseMiddleware` is used, the session will be removed
93
+ * from the storage automatically and calling this method is not necessary.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * // Log out the user
98
+ * nhost.clearSession();
99
+ * ```
100
+ */
101
+ clearSession(): void;
102
+ }
103
+ /**
104
+ * Configuration options for creating an Nhost client
105
+ */
106
+ export interface NhostClientOptions {
107
+ /**
108
+ * Nhost project subdomain (e.g., 'abcdefgh'). Used to construct the base URL for services for the Nhost cloud.
109
+ */
110
+ subdomain?: string;
111
+ /**
112
+ * Nhost region (e.g., 'eu-central-1'). Used to construct the base URL for services for the Nhost cloud.
113
+ */
114
+ region?: string;
115
+ /**
116
+ * Complete base URL for the auth service (overrides subdomain/region)
117
+ */
118
+ authUrl?: string;
119
+ /**
120
+ * Complete base URL for the storage service (overrides subdomain/region)
121
+ */
122
+ storageUrl?: string;
123
+ /**
124
+ * Complete base URL for the GraphQL service (overrides subdomain/region)
125
+ */
126
+ graphqlUrl?: string;
127
+ /**
128
+ * Complete base URL for the functions service (overrides subdomain/region)
129
+ */
130
+ functionsUrl?: string;
131
+ /**
132
+ * Storage backend to use for session persistence. If not provided, the SDK will
133
+ * default to localStorage in the browser or memory in other environments.
134
+ */
135
+ storage?: SessionStorageBackend;
136
+ }
137
+ /**
138
+ * Creates and configures a new Nhost client instance optimized for client-side usage.
139
+ *
140
+ * This helper method instantiates a fully configured Nhost client by:
141
+ * - Instantiating the various service clients (auth, storage, functions and graphql)
142
+ * - Auto-detecting and configuring an appropriate session storage (localStorage in browsers, memory otherwise)
143
+ * - Setting up a sophisticated middleware chain for seamless authentication management:
144
+ * - Automatically refreshing tokens before they expire
145
+ * - Attaching authorization tokens to all service requests
146
+ * - Updating the session storage when new tokens are received
147
+ *
148
+ * This method includes automatic session refresh middleware, making it ideal for
149
+ * client-side applications where long-lived sessions are expected.
150
+ *
151
+ * @param options - Configuration options for the client
152
+ * @returns A configured Nhost client
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * // Create client using Nhost cloud default URLs
157
+ * const nhost = createClient({
158
+ * subdomain: 'abcdefgh',
159
+ * region: 'eu-central-1'
160
+ * });
161
+ *
162
+ * // Create client with custom service URLs
163
+ * const customNhost = createClient({
164
+ * authUrl: 'https://auth.example.com',
165
+ * storageUrl: 'https://storage.example.com',
166
+ * graphqlUrl: 'https://graphql.example.com',
167
+ * functionsUrl: 'https://functions.example.com'
168
+ * });
169
+ *
170
+ * // Create client using cookies for storing the session
171
+ * import { CookieStorage } from "@nhost/nhost-js/session";
172
+ *
173
+ * const nhost = createClient({
174
+ * subdomain: 'abcdefgh',
175
+ * region: 'eu-central-1',
176
+ * storage: new CookieStorage({
177
+ * secure: import.meta.env.ENVIRONMENT === 'production',
178
+ * })
179
+ * });
180
+ * ```
181
+ */
182
+ export declare function createClient(options?: NhostClientOptions): NhostClient;
183
+ export interface NhostServerClientOptions extends NhostClientOptions {
184
+ /**
185
+ * Storage backend to use for session persistence in server environments.
186
+ * Unlike the base options, this field is required for server-side usage
187
+ * as the SDK cannot auto-detect an appropriate storage mechanism.
188
+ */
189
+ storage: SessionStorageBackend;
190
+ }
191
+ /**
192
+ * Creates and configures a new Nhost client instance optimized for server-side usage.
193
+ *
194
+ * This helper method instantiates a fully configured Nhost client specifically designed for:
195
+ * - Server components (in frameworks like Next.js or Remix)
196
+ * - API routes and middleware
197
+ * - Backend services and server-side rendering contexts
198
+ *
199
+ * Key differences from the standard client:
200
+ * - Requires explicit storage implementation (must be provided)
201
+ * - Disables automatic session refresh middleware (to prevent race conditions in server contexts)
202
+ * - Still attaches authorization tokens and updates session storage from responses
203
+ *
204
+ * The server client is ideal for short-lived request contexts where session tokens
205
+ * are passed in (like cookie-based authentication flows) and automatic refresh
206
+ * mechanisms could cause issues with concurrent requests.
207
+ *
208
+ * @param options - Configuration options for the server client (requires storage implementation)
209
+ * @returns A configured Nhost client optimized for server-side usage
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * // Example with cookie storage for Next.js API route or server component
214
+ * import { cookies } from 'next/headers';
215
+ *
216
+ * const nhost = createServerClient({
217
+ * region: process.env["NHOST_REGION"] || "local",
218
+ * subdomain: process.env["NHOST_SUBDOMAIN"] || "local",
219
+ * storage: {
220
+ * // storage compatible with Next.js server components
221
+ * get: (): Session | null => {
222
+ * const s = cookieStore.get(key)?.value || null;
223
+ * if (!s) {
224
+ * return null;
225
+ * }
226
+ * const session = JSON.parse(s) as Session;
227
+ * return session;
228
+ * },
229
+ * set: (value: Session) => {
230
+ * cookieStore.set(key, JSON.stringify(value));
231
+ * },
232
+ * remove: () => {
233
+ * cookieStore.delete(key);
234
+ * },
235
+ * },
236
+ * });
237
+ *
238
+ * // Example with cookie storage for Next.js middleware
239
+ * const nhost = createServerClient({
240
+ * region: process.env["NHOST_REGION"] || "local",
241
+ * subdomain: process.env["NHOST_SUBDOMAIN"] || "local",
242
+ * storage: {
243
+ * // storage compatible with Next.js middleware
244
+ * get: (): Session | null => {
245
+ * const raw = request.cookies.get(key)?.value || null;
246
+ * if (!raw) {
247
+ * return null;
248
+ * }
249
+ * const session = JSON.parse(raw) as Session;
250
+ * return session;
251
+ * },
252
+ * set: (value: Session) => {
253
+ * response.cookies.set({
254
+ * name: key,
255
+ * value: JSON.stringify(value),
256
+ * path: "/",
257
+ * httpOnly: false, //if set to true we can't access it in the client
258
+ * secure: process.env.NODE_ENV === "production",
259
+ * sameSite: "lax",
260
+ * maxAge: 60 * 60 * 24 * 30, // 30 days in seconds
261
+ * });
262
+ * },
263
+ * remove: () => {
264
+ * response.cookies.delete(key);
265
+ * },
266
+ * },
267
+ * });
268
+ *
269
+ * // Example for express reading session from a cookie
270
+ *
271
+ * import express, { Request, Response } from "express";
272
+ * import cookieParser from "cookie-parser";
273
+ *
274
+ * app.use(cookieParser());
275
+ *
276
+ * const nhostClientFromCookies = (req: Request) => {
277
+ * return createServerClient({
278
+ * subdomain: "local",
279
+ * region: "local",
280
+ * storage: {
281
+ * get: (): Session | null => {
282
+ * const s = req.cookies.nhostSession || null;
283
+ * if (!s) {
284
+ * return null;
285
+ * }
286
+ * const session = JSON.parse(s) as Session;
287
+ * return session;
288
+ * },
289
+ * set: (_value: Session) => {
290
+ * throw new Error("It is easier to handle the session in the client");
291
+ * },
292
+ * remove: () => {
293
+ * throw new Error("It is easier to handle the session in the client");
294
+ * },
295
+ * },
296
+ * });
297
+ * };
298
+ * ```
299
+ */
300
+ export declare function createServerClient(options: NhostServerClientOptions): NhostClient;
301
+ //# sourceMappingURL=nhost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"n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