@nhost/nhost-js 5.0.0-beta.9 → 5.0.0-beta10
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/LICENSE +1 -1
- package/README.md +20 -20
- package/dist/fetch-2PHmQBIJ.mjs.map +1 -1
- package/dist/fetch-DWXwEnoe.js.map +1 -1
- 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 +38 -38
- 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 +3 -3
- package/dist/nhost-js/fetch.es.js.map +1 -1
- package/dist/nhost-js/functions.cjs.js.map +1 -1
- package/dist/nhost-js/functions.es.js.map +1 -1
- package/dist/nhost-js/graphql.cjs.js.map +1 -1
- package/dist/nhost-js/graphql.es.js.map +1 -1
- package/dist/nhost-js/session.cjs.js +1 -1
- package/dist/nhost-js/session.cjs.js.map +1 -1
- package/dist/nhost-js/session.es.js +1 -1
- package/dist/nhost-js/session.es.js.map +1 -1
- package/dist/nhost-js/storage.cjs.js +1 -1
- package/dist/nhost-js/storage.cjs.js.map +1 -1
- package/dist/nhost-js/storage.es.js +19 -17
- 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 +4 -4
- 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 +2 -0
- package/dist/refreshSession-Bw715ZmX.js.map +1 -0
- package/dist/{refreshSession-cGdPdFoG.mjs → refreshSession-WwGlzgtM.mjs} +9 -5
- package/dist/refreshSession-WwGlzgtM.mjs.map +1 -0
- package/dist/src/auth/client.d.ts.map +1 -1
- package/dist/src/auth/client.js +41 -41
- package/dist/src/auth/client.js.map +1 -1
- package/dist/src/fetch/fetch.d.ts +1 -1
- package/dist/src/fetch/fetch.d.ts.map +1 -1
- package/dist/src/fetch/fetch.js +0 -1
- package/dist/src/fetch/fetch.js.map +1 -1
- package/dist/src/fetch/index.d.ts +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +1 -1
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/fetch/middlewareSessionRefresh.d.ts +1 -1
- package/dist/src/fetch/middlewareSessionRefresh.d.ts.map +1 -1
- package/dist/src/fetch/middlewareSessionRefresh.js.map +1 -1
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js +2 -2
- package/dist/src/fetch/middlewareUpdateSessionFromResponse.js.map +1 -1
- package/dist/src/functions/client.d.ts +2 -2
- package/dist/src/functions/client.d.ts.map +1 -1
- package/dist/src/functions/client.js +0 -2
- package/dist/src/functions/client.js.map +1 -1
- package/dist/src/graphql/client.d.ts +4 -4
- package/dist/src/graphql/client.d.ts.map +1 -1
- package/dist/src/graphql/client.js.map +1 -1
- package/dist/src/graphql/index.d.ts +13 -5
- package/dist/src/graphql/index.d.ts.map +1 -1
- package/dist/src/graphql/index.js +13 -5
- package/dist/src/graphql/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/nhost.d.ts +3 -3
- package/dist/src/nhost.d.ts.map +1 -1
- package/dist/src/nhost.js +5 -5
- package/dist/src/nhost.js.map +1 -1
- package/dist/src/session/index.d.ts +3 -3
- package/dist/src/session/index.d.ts.map +1 -1
- package/dist/src/session/index.js +2 -2
- package/dist/src/session/index.js.map +1 -1
- package/dist/src/session/refreshSession.d.ts +4 -4
- package/dist/src/session/refreshSession.d.ts.map +1 -1
- package/dist/src/session/refreshSession.js +10 -11
- package/dist/src/session/refreshSession.js.map +1 -1
- package/dist/src/session/storage.d.ts +2 -2
- package/dist/src/session/storage.d.ts.map +1 -1
- package/dist/src/session/storage.js +1 -1
- package/dist/src/session/storage.js.map +1 -1
- package/dist/src/session/storageBackend.d.ts.map +1 -1
- package/dist/src/session/storageBackend.js +2 -0
- package/dist/src/session/storageBackend.js.map +1 -1
- package/dist/src/storage/client.d.ts.map +1 -1
- package/dist/src/storage/client.js +21 -17
- package/dist/src/storage/client.js.map +1 -1
- package/dist/src/storage/index.d.ts +2 -2
- package/dist/src/storage/index.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/dist/refreshSession-bgb-tiu4.js +0 -2
- package/dist/refreshSession-bgb-tiu4.js.map +0 -1
- package/dist/refreshSession-cGdPdFoG.mjs.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -18,22 +18,22 @@ pnpm add @nhost/nhost-js@beta
|
|
|
18
18
|
## Quick Start
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import { createClient } from
|
|
21
|
+
import { createClient } from '@nhost/nhost-js'
|
|
22
22
|
|
|
23
23
|
// Initialize the Nhost client
|
|
24
24
|
const nhost = createClient({
|
|
25
|
-
subdomain:
|
|
26
|
-
region:
|
|
27
|
-
})
|
|
25
|
+
subdomain: 'your-project',
|
|
26
|
+
region: 'eu-central-1'
|
|
27
|
+
})
|
|
28
28
|
|
|
29
29
|
// Use authentication features
|
|
30
30
|
const response = await nhost.auth.signInEmailPassword({
|
|
31
|
-
email:
|
|
32
|
-
password:
|
|
33
|
-
})
|
|
31
|
+
email: 'user@example.com',
|
|
32
|
+
password: 'password123'
|
|
33
|
+
})
|
|
34
34
|
|
|
35
35
|
if (response.body.session) {
|
|
36
|
-
console.log(
|
|
36
|
+
console.log('Signed in successfully!')
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Use GraphQL features
|
|
@@ -46,28 +46,28 @@ const response = await nhost.graphql.request({
|
|
|
46
46
|
email
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
})
|
|
49
|
+
`
|
|
50
|
+
})
|
|
51
51
|
|
|
52
|
-
return response.body.data.users
|
|
52
|
+
return response.body.data.users
|
|
53
53
|
|
|
54
54
|
// Use storage features
|
|
55
55
|
const response = await nhost.storage.uploadFiles({
|
|
56
|
-
|
|
57
|
-
})
|
|
56
|
+
'file[]': [file]
|
|
57
|
+
})
|
|
58
58
|
|
|
59
|
-
return response.body.processedFiles[0]
|
|
59
|
+
return response.body.processedFiles[0]
|
|
60
60
|
|
|
61
61
|
// call a serverless function
|
|
62
|
-
const response = await nhost.functions.fetch(
|
|
63
|
-
method:
|
|
62
|
+
const response = await nhost.functions.fetch('/echo', {
|
|
63
|
+
method: 'POST',
|
|
64
64
|
body: JSON.stringify({
|
|
65
|
-
message:
|
|
65
|
+
message: 'Hello, world!'
|
|
66
66
|
}),
|
|
67
67
|
headers: {
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
})
|
|
68
|
+
'Content-Type': 'application/json'
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
## Modules
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-2PHmQBIJ.mjs","sources":["../src/fetch/fetch.ts"],"sourcesContent":["/**\n * Type definition for a fetch-like function.\n * Takes the same parameters as fetch and returns the same type.\n * This allows middleware to intercept and modify requests and responses.\n */\nexport type FetchFunction = (\n url: string,\n options?: RequestInit,\n) => Promise<Response>;\n\n/**\n * Type definition for a chain function (middleware).\n * Takes a fetch-like function and returns another fetch-like function.\n *\n * Chain functions can be used to implement:\n * - Authentication token handling\n * - Error handling and retry logic\n * - Request and response transformations\n * - Logging and metrics\n */\nexport type ChainFunction = (next: FetchFunction) => FetchFunction;\n\n/**\n * Creates an enhanced fetch function using a chain of middleware functions.\n *\n * The fetch chain executes in the order of the array, with each middleware\n * wrapping the next one in the chain. This allows each middleware to\n * intercept both the request (before calling next) and the response\n * (after calling next).\n *\n * @example\n * ```typescript\n * // Simple logging middleware\n * const loggingMiddleware: ChainFunction = (next) => {\n * return async (url, options) => {\n * console.log(`Request to ${url}`);\n * const response = await next(url, options);\n * console.log(`Response from ${url}: ${response.status}`);\n * return response;\n * };\n * };\n *\n * const enhancedFetch = createEnhancedFetch([loggingMiddleware]);\n * const response = await enhancedFetch('https://api.example.com/data');\n * ```\n *\n * @param chainFunctions - Array of chain functions to apply in order\n * @returns Enhanced fetch function with all middleware applied\n */\nexport function createEnhancedFetch(\n chainFunctions: ChainFunction[] = [],\n): FetchFunction {\n // Build the chain starting with vanilla fetch, but apply functions in reverse\n // to achieve the desired execution order\n return chainFunctions.reduceRight(\n (nextInChain, chainFunction) => chainFunction(nextInChain),\n fetch as FetchFunction,\n );\n}\n\n/**\n * Interface representing a structured API response.\n *\n * This interface provides a consistent structure for responses across the SDK,\n * offering access to the parsed response body along with status and headers.\n *\n * @template T - The type of the response body\n */\nexport interface FetchResponse<T> {\n /** The parsed response body */\n body: T;\n /** HTTP status code of the response */\n status: number;\n /** Response headers */\n headers: Headers;\n}\n\nfunction extractMessage(body: unknown): string {\n if (body && typeof body === \"string\") {\n return body;\n }\n\n if (body && typeof body === \"object\") {\n const typedBody = body as Record<string, unknown>;\n\n if (\"message\" in typedBody && typeof typedBody[\"message\"] === \"string\") {\n return typedBody[\"message\"];\n }\n\n if (\"error\" in typedBody && typeof typedBody[\"error\"] === \"string\") {\n return typedBody[\"error\"];\n }\n\n if (\n \"error\" in typedBody &&\n typedBody[\"error\"] &&\n typeof typedBody[\"error\"] === \"object\"\n ) {\n const error = typedBody[\"error\"] as Record<string, unknown>;\n if (\"message\" in error && typeof error[\"message\"] === \"string\") {\n return error[\"message\"];\n }\n }\n\n if (\"errors\" in typedBody && Array.isArray(typedBody[\"errors\"])) {\n const messages = (typedBody[\"errors\"] as unknown[])\n .filter(\n (error): error is { message: string } =>\n typeof error === \"object\" &&\n error !== null &&\n \"message\" in error &&\n typeof (error as { message: unknown })[\"message\"] === \"string\",\n )\n .map((error) => error[\"message\"]);\n\n if (messages.length > 0) {\n return messages.join(\", \");\n }\n }\n }\n\n return \"An unexpected error occurred\";\n}\n\n/**\n * Error class for representing fetch operation failures.\n *\n * This class extends the standard Error to include additional\n * information about failed requests, including the response body,\n * status code, and headers. The error message is automatically\n * extracted from common error response formats.\n *\n * @template T - The type of the response body\n */\
|
|
1
|
+
{"version":3,"file":"fetch-2PHmQBIJ.mjs","sources":["../src/fetch/fetch.ts"],"sourcesContent":["/**\n * Type definition for a fetch-like function.\n * Takes the same parameters as fetch and returns the same type.\n * This allows middleware to intercept and modify requests and responses.\n */\nexport type FetchFunction = (\n url: string,\n options?: RequestInit,\n) => Promise<Response>;\n\n/**\n * Type definition for a chain function (middleware).\n * Takes a fetch-like function and returns another fetch-like function.\n *\n * Chain functions can be used to implement:\n * - Authentication token handling\n * - Error handling and retry logic\n * - Request and response transformations\n * - Logging and metrics\n */\nexport type ChainFunction = (next: FetchFunction) => FetchFunction;\n\n/**\n * Creates an enhanced fetch function using a chain of middleware functions.\n *\n * The fetch chain executes in the order of the array, with each middleware\n * wrapping the next one in the chain. This allows each middleware to\n * intercept both the request (before calling next) and the response\n * (after calling next).\n *\n * @example\n * ```typescript\n * // Simple logging middleware\n * const loggingMiddleware: ChainFunction = (next) => {\n * return async (url, options) => {\n * console.log(`Request to ${url}`);\n * const response = await next(url, options);\n * console.log(`Response from ${url}: ${response.status}`);\n * return response;\n * };\n * };\n *\n * const enhancedFetch = createEnhancedFetch([loggingMiddleware]);\n * const response = await enhancedFetch('https://api.example.com/data');\n * ```\n *\n * @param chainFunctions - Array of chain functions to apply in order\n * @returns Enhanced fetch function with all middleware applied\n */\nexport function createEnhancedFetch(\n chainFunctions: ChainFunction[] = [],\n): FetchFunction {\n // Build the chain starting with vanilla fetch, but apply functions in reverse\n // to achieve the desired execution order\n return chainFunctions.reduceRight(\n (nextInChain, chainFunction) => chainFunction(nextInChain),\n fetch as FetchFunction,\n );\n}\n\n/**\n * Interface representing a structured API response.\n *\n * This interface provides a consistent structure for responses across the SDK,\n * offering access to the parsed response body along with status and headers.\n *\n * @template T - The type of the response body\n */\nexport interface FetchResponse<T> {\n /** The parsed response body */\n body: T;\n /** HTTP status code of the response */\n status: number;\n /** Response headers */\n headers: Headers;\n}\n\nfunction extractMessage(body: unknown): string {\n if (body && typeof body === \"string\") {\n return body;\n }\n\n if (body && typeof body === \"object\") {\n const typedBody = body as Record<string, unknown>;\n\n if (\"message\" in typedBody && typeof typedBody[\"message\"] === \"string\") {\n return typedBody[\"message\"];\n }\n\n if (\"error\" in typedBody && typeof typedBody[\"error\"] === \"string\") {\n return typedBody[\"error\"];\n }\n\n if (\n \"error\" in typedBody &&\n typedBody[\"error\"] &&\n typeof typedBody[\"error\"] === \"object\"\n ) {\n const error = typedBody[\"error\"] as Record<string, unknown>;\n if (\"message\" in error && typeof error[\"message\"] === \"string\") {\n return error[\"message\"];\n }\n }\n\n if (\"errors\" in typedBody && Array.isArray(typedBody[\"errors\"])) {\n const messages = (typedBody[\"errors\"] as unknown[])\n .filter(\n (error): error is { message: string } =>\n typeof error === \"object\" &&\n error !== null &&\n \"message\" in error &&\n typeof (error as { message: unknown })[\"message\"] === \"string\",\n )\n .map((error) => error[\"message\"]);\n\n if (messages.length > 0) {\n return messages.join(\", \");\n }\n }\n }\n\n return \"An unexpected error occurred\";\n}\n\n/**\n * Error class for representing fetch operation failures.\n *\n * This class extends the standard Error to include additional\n * information about failed requests, including the response body,\n * status code, and headers. The error message is automatically\n * extracted from common error response formats.\n *\n * @template T - The type of the response body\n */\nexport class FetchError<T = unknown> extends Error {\n /** The original response body */\n body: T;\n /** HTTP status code of the failed response */\n status: number;\n /** Response headers */\n headers: Headers;\n\n /**\n * Creates a new FetchError instance\n *\n * @param body - The response body from the failed request\n * @param status - The HTTP status code\n * @param headers - The response headers\n */\n constructor(body: T, status: number, headers: Headers) {\n super(extractMessage(body));\n this.body = body;\n this.status = status;\n this.headers = headers;\n }\n}\n"],"names":[],"mappings":"AAiDO,SAAS,oBACd,iBAAkC,IACnB;AAGf,SAAO,eAAe;AAAA,IACpB,CAAC,aAAa,kBAAkB,cAAc,WAAW;AAAA,IACzD;AAAA,EAAA;AAEJ;AAmBA,SAAS,eAAe,MAAuB;AAC7C,MAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,UAAM,YAAY;AAElB,QAAI,aAAa,aAAa,OAAO,UAAU,SAAS,MAAM,UAAU;AACtE,aAAO,UAAU,SAAS;AAAA,IAC5B;AAEA,QAAI,WAAW,aAAa,OAAO,UAAU,OAAO,MAAM,UAAU;AAClE,aAAO,UAAU,OAAO;AAAA,IAC1B;AAEA,QACE,WAAW,aACX,UAAU,OAAO,KACjB,OAAO,UAAU,OAAO,MAAM,UAC9B;AACA,YAAM,QAAQ,UAAU,OAAO;AAC/B,UAAI,aAAa,SAAS,OAAO,MAAM,SAAS,MAAM,UAAU;AAC9D,eAAO,MAAM,SAAS;AAAA,MACxB;AAAA,IACF;AAEA,QAAI,YAAY,aAAa,MAAM,QAAQ,UAAU,QAAQ,CAAC,GAAG;AAC/D,YAAM,WAAY,UAAU,QAAQ,EACjC;AAAA,QACC,CAAC,UACC,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,OAAQ,MAA+B,SAAS,MAAM;AAAA,MAAA,EAEzD,IAAI,CAAC,UAAU,MAAM,SAAS,CAAC;AAElC,UAAI,SAAS,SAAS,GAAG;AACvB,eAAO,SAAS,KAAK,IAAI;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAYO,MAAM,mBAAgC,MAAM;AAAA;AAAA,EAEjD;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAAY,MAAS,QAAgB,SAAkB;AACrD,UAAM,eAAe,IAAI,CAAC;AAC1B,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-DWXwEnoe.js","sources":["../src/fetch/fetch.ts"],"sourcesContent":["/**\n * Type definition for a fetch-like function.\n * Takes the same parameters as fetch and returns the same type.\n * This allows middleware to intercept and modify requests and responses.\n */\nexport type FetchFunction = (\n url: string,\n options?: RequestInit,\n) => Promise<Response>;\n\n/**\n * Type definition for a chain function (middleware).\n * Takes a fetch-like function and returns another fetch-like function.\n *\n * Chain functions can be used to implement:\n * - Authentication token handling\n * - Error handling and retry logic\n * - Request and response transformations\n * - Logging and metrics\n */\nexport type ChainFunction = (next: FetchFunction) => FetchFunction;\n\n/**\n * Creates an enhanced fetch function using a chain of middleware functions.\n *\n * The fetch chain executes in the order of the array, with each middleware\n * wrapping the next one in the chain. This allows each middleware to\n * intercept both the request (before calling next) and the response\n * (after calling next).\n *\n * @example\n * ```typescript\n * // Simple logging middleware\n * const loggingMiddleware: ChainFunction = (next) => {\n * return async (url, options) => {\n * console.log(`Request to ${url}`);\n * const response = await next(url, options);\n * console.log(`Response from ${url}: ${response.status}`);\n * return response;\n * };\n * };\n *\n * const enhancedFetch = createEnhancedFetch([loggingMiddleware]);\n * const response = await enhancedFetch('https://api.example.com/data');\n * ```\n *\n * @param chainFunctions - Array of chain functions to apply in order\n * @returns Enhanced fetch function with all middleware applied\n */\nexport function createEnhancedFetch(\n chainFunctions: ChainFunction[] = [],\n): FetchFunction {\n // Build the chain starting with vanilla fetch, but apply functions in reverse\n // to achieve the desired execution order\n return chainFunctions.reduceRight(\n (nextInChain, chainFunction) => chainFunction(nextInChain),\n fetch as FetchFunction,\n );\n}\n\n/**\n * Interface representing a structured API response.\n *\n * This interface provides a consistent structure for responses across the SDK,\n * offering access to the parsed response body along with status and headers.\n *\n * @template T - The type of the response body\n */\nexport interface FetchResponse<T> {\n /** The parsed response body */\n body: T;\n /** HTTP status code of the response */\n status: number;\n /** Response headers */\n headers: Headers;\n}\n\nfunction extractMessage(body: unknown): string {\n if (body && typeof body === \"string\") {\n return body;\n }\n\n if (body && typeof body === \"object\") {\n const typedBody = body as Record<string, unknown>;\n\n if (\"message\" in typedBody && typeof typedBody[\"message\"] === \"string\") {\n return typedBody[\"message\"];\n }\n\n if (\"error\" in typedBody && typeof typedBody[\"error\"] === \"string\") {\n return typedBody[\"error\"];\n }\n\n if (\n \"error\" in typedBody &&\n typedBody[\"error\"] &&\n typeof typedBody[\"error\"] === \"object\"\n ) {\n const error = typedBody[\"error\"] as Record<string, unknown>;\n if (\"message\" in error && typeof error[\"message\"] === \"string\") {\n return error[\"message\"];\n }\n }\n\n if (\"errors\" in typedBody && Array.isArray(typedBody[\"errors\"])) {\n const messages = (typedBody[\"errors\"] as unknown[])\n .filter(\n (error): error is { message: string } =>\n typeof error === \"object\" &&\n error !== null &&\n \"message\" in error &&\n typeof (error as { message: unknown })[\"message\"] === \"string\",\n )\n .map((error) => error[\"message\"]);\n\n if (messages.length > 0) {\n return messages.join(\", \");\n }\n }\n }\n\n return \"An unexpected error occurred\";\n}\n\n/**\n * Error class for representing fetch operation failures.\n *\n * This class extends the standard Error to include additional\n * information about failed requests, including the response body,\n * status code, and headers. The error message is automatically\n * extracted from common error response formats.\n *\n * @template T - The type of the response body\n */\
|
|
1
|
+
{"version":3,"file":"fetch-DWXwEnoe.js","sources":["../src/fetch/fetch.ts"],"sourcesContent":["/**\n * Type definition for a fetch-like function.\n * Takes the same parameters as fetch and returns the same type.\n * This allows middleware to intercept and modify requests and responses.\n */\nexport type FetchFunction = (\n url: string,\n options?: RequestInit,\n) => Promise<Response>;\n\n/**\n * Type definition for a chain function (middleware).\n * Takes a fetch-like function and returns another fetch-like function.\n *\n * Chain functions can be used to implement:\n * - Authentication token handling\n * - Error handling and retry logic\n * - Request and response transformations\n * - Logging and metrics\n */\nexport type ChainFunction = (next: FetchFunction) => FetchFunction;\n\n/**\n * Creates an enhanced fetch function using a chain of middleware functions.\n *\n * The fetch chain executes in the order of the array, with each middleware\n * wrapping the next one in the chain. This allows each middleware to\n * intercept both the request (before calling next) and the response\n * (after calling next).\n *\n * @example\n * ```typescript\n * // Simple logging middleware\n * const loggingMiddleware: ChainFunction = (next) => {\n * return async (url, options) => {\n * console.log(`Request to ${url}`);\n * const response = await next(url, options);\n * console.log(`Response from ${url}: ${response.status}`);\n * return response;\n * };\n * };\n *\n * const enhancedFetch = createEnhancedFetch([loggingMiddleware]);\n * const response = await enhancedFetch('https://api.example.com/data');\n * ```\n *\n * @param chainFunctions - Array of chain functions to apply in order\n * @returns Enhanced fetch function with all middleware applied\n */\nexport function createEnhancedFetch(\n chainFunctions: ChainFunction[] = [],\n): FetchFunction {\n // Build the chain starting with vanilla fetch, but apply functions in reverse\n // to achieve the desired execution order\n return chainFunctions.reduceRight(\n (nextInChain, chainFunction) => chainFunction(nextInChain),\n fetch as FetchFunction,\n );\n}\n\n/**\n * Interface representing a structured API response.\n *\n * This interface provides a consistent structure for responses across the SDK,\n * offering access to the parsed response body along with status and headers.\n *\n * @template T - The type of the response body\n */\nexport interface FetchResponse<T> {\n /** The parsed response body */\n body: T;\n /** HTTP status code of the response */\n status: number;\n /** Response headers */\n headers: Headers;\n}\n\nfunction extractMessage(body: unknown): string {\n if (body && typeof body === \"string\") {\n return body;\n }\n\n if (body && typeof body === \"object\") {\n const typedBody = body as Record<string, unknown>;\n\n if (\"message\" in typedBody && typeof typedBody[\"message\"] === \"string\") {\n return typedBody[\"message\"];\n }\n\n if (\"error\" in typedBody && typeof typedBody[\"error\"] === \"string\") {\n return typedBody[\"error\"];\n }\n\n if (\n \"error\" in typedBody &&\n typedBody[\"error\"] &&\n typeof typedBody[\"error\"] === \"object\"\n ) {\n const error = typedBody[\"error\"] as Record<string, unknown>;\n if (\"message\" in error && typeof error[\"message\"] === \"string\") {\n return error[\"message\"];\n }\n }\n\n if (\"errors\" in typedBody && Array.isArray(typedBody[\"errors\"])) {\n const messages = (typedBody[\"errors\"] as unknown[])\n .filter(\n (error): error is { message: string } =>\n typeof error === \"object\" &&\n error !== null &&\n \"message\" in error &&\n typeof (error as { message: unknown })[\"message\"] === \"string\",\n )\n .map((error) => error[\"message\"]);\n\n if (messages.length > 0) {\n return messages.join(\", \");\n }\n }\n }\n\n return \"An unexpected error occurred\";\n}\n\n/**\n * Error class for representing fetch operation failures.\n *\n * This class extends the standard Error to include additional\n * information about failed requests, including the response body,\n * status code, and headers. The error message is automatically\n * extracted from common error response formats.\n *\n * @template T - The type of the response body\n */\nexport class FetchError<T = unknown> extends Error {\n /** The original response body */\n body: T;\n /** HTTP status code of the failed response */\n status: number;\n /** Response headers */\n headers: Headers;\n\n /**\n * Creates a new FetchError instance\n *\n * @param body - The response body from the failed request\n * @param status - The HTTP status code\n * @param headers - The response headers\n */\n constructor(body: T, status: number, headers: Headers) {\n super(extractMessage(body));\n this.body = body;\n this.status = status;\n this.headers = headers;\n }\n}\n"],"names":["FetchError","Error","body","status","headers","constructor","super","typedBody","error","Array","isArray","messages","filter","map","length","join","extractMessage","this","chainFunctions","reduceRight","nextInChain","chainFunction","fetch"],"mappings":"aAsIO,MAAMA,UAAgCC,MAE3CC,KAEAC,OAEAC,QASA,WAAAC,CAAYH,EAASC,EAAgBC,GACnCE,MAzEJ,SAAwBJ,GACtB,GAAIA,GAAwB,iBAATA,EACjB,OAAOA,EAGT,GAAIA,GAAwB,iBAATA,EAAmB,CACpC,MAAMK,EAAYL,EAElB,GAAI,YAAaK,GAA6C,iBAAzBA,EAAmB,QACtD,OAAOA,EAAmB,QAG5B,GAAI,UAAWA,GAA2C,iBAAvBA,EAAiB,MAClD,OAAOA,EAAiB,MAG1B,GACE,UAAWA,GACXA,EAAiB,OACa,iBAAvBA,EAAiB,MACxB,CACA,MAAMC,EAAQD,EAAiB,MAC/B,GAAI,YAAaC,GAAqC,iBAArBA,EAAe,QAC9C,OAAOA,EAAe,OAE1B,CAEA,GAAI,WAAYD,GAAaE,MAAMC,QAAQH,EAAkB,QAAI,CAC/D,MAAMI,EAAYJ,EAAkB,OACjCK,QACEJ,GACkB,iBAAVA,GACG,OAAVA,GACA,YAAaA,GACyC,iBAA9CA,EAAwC,UAEnDK,KAAKL,GAAUA,EAAe,UAEjC,GAAIG,EAASG,OAAS,EACpB,OAAOH,EAASI,KAAK,KAEzB,CACF,CAEA,MAAO,8BACT,CA4BUC,CAAed,IACrBe,KAAKf,KAAOA,EACZe,KAAKd,OAASA,EACdc,KAAKb,QAAUA,CACjB,mDAzGK,SACLc,EAAkC,IAIlC,OAAOA,EAAeC,aACpB,CAACC,EAAaC,IAAkBA,EAAcD,IAC9CE,MAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../fetch-DWXwEnoe.js");exports.createAPIClient=(s,e=[])=>{let a=t.createEnhancedFetch(e);return{baseURL:s,pushChainFunction:s=>{e.push(s),a=t.createEnhancedFetch(e)},getJWKs:async e=>{const n=s+"/.well-known/jwks.json",r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},elevateWebauthn:async e=>{const n=s+"/elevate/webauthn",r=await a(n,{...e,method:"POST",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},verifyElevateWebauthn:async(e,n)=>{const r=s+"/elevate/webauthn/verify",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},healthCheckGet:async e=>{const n=s+"/healthz",r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},healthCheckHead:async e=>{const n=s+"/healthz",r=await a(n,{...e,method:"HEAD",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}return{body:void 0,status:r.status,headers:r.headers}},linkIdToken:async(e,n)=>{const r=s+"/link/idtoken",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},changeUserMfa:async e=>{const n=s+"/mfa/totp/generate",r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},createPAT:async(e,n)=>{const r=s+"/pat",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInAnonymous:async(e,n)=>{const r=s+"/signin/anonymous",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInEmailPassword:async(e,n)=>{const r=s+"/signin/email-password",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInIdToken:async(e,n)=>{const r=s+"/signin/idtoken",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInMfaTotp:async(e,n)=>{const r=s+"/signin/mfa/totp",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInOTPEmail:async(e,n)=>{const r=s+"/signin/otp/email",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInOTPEmail:async(e,n)=>{const r=s+"/signin/otp/email/verify",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInPasswordlessEmail:async(e,n)=>{const r=s+"/signin/passwordless/email",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInPasswordlessSms:async(e,n)=>{const r=s+"/signin/passwordless/sms",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInPasswordlessSms:async(e,n)=>{const r=s+"/signin/passwordless/sms/otp",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInPAT:async(e,n)=>{const r=s+"/signin/pat",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInProviderURL:(t,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?s+`/signin/provider/${t}?${a}`:s+`/signin/provider/${t}`},signInWebauthn:async(e,n)=>{const r=s+"/signin/webauthn",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInWebauthn:async(e,n)=>{const r=s+"/signin/webauthn/verify",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signOut:async(e,n)=>{const r=s+"/signout",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signUpEmailPassword:async(e,n)=>{const r=s+"/signup/email-password",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signUpWebauthn:async(e,n)=>{const r=s+"/signup/webauthn",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignUpWebauthn:async(e,n)=>{const r=s+"/signup/webauthn/verify",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},refreshToken:async(e,n)=>{const r=s+"/token",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifyToken:async(e,n)=>{const r=s+"/token/verify",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},getUser:async e=>{const n=s+"/user",r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},deanonymizeUser:async(e,n)=>{const r=s+"/user/deanonymize",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},changeUserEmail:async(e,n)=>{const r=s+"/user/email/change",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},sendVerificationEmail:async(e,n)=>{const r=s+"/user/email/send-verification-email",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifyChangeUserMfa:async(e,n)=>{const r=s+"/user/mfa",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},changeUserPassword:async(e,n)=>{const r=s+"/user/password",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},sendPasswordResetEmail:async(e,n)=>{const r=s+"/user/password/reset",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},addSecurityKey:async e=>{const n=s+"/user/webauthn/add",r=await a(n,{...e,method:"POST",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},verifyAddSecurityKey:async(e,n)=>{const r=s+"/user/webauthn/verify",i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifyTicketURL:t=>{const e=t&&Object.entries(t).map((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s?JSON.stringify(s):s;return`${t}=${encodeURIComponent(e)}`})).join("&");return e?s+`/verify?${e}`:s+"/verify"},getVersion:async e=>{const n=s+"/version",r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}}}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../fetch-DWXwEnoe.js");exports.createAPIClient=(s,e=[])=>{let a=t.createEnhancedFetch(e);return{baseURL:s,pushChainFunction:s=>{e.push(s),a=t.createEnhancedFetch(e)},getJWKs:async e=>{const n=`${s}/.well-known/jwks.json`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},elevateWebauthn:async e=>{const n=`${s}/elevate/webauthn`,r=await a(n,{...e,method:"POST",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},verifyElevateWebauthn:async(e,n)=>{const r=`${s}/elevate/webauthn/verify`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},healthCheckGet:async e=>{const n=`${s}/healthz`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},healthCheckHead:async e=>{const n=`${s}/healthz`,r=await a(n,{...e,method:"HEAD",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}return{body:void 0,status:r.status,headers:r.headers}},linkIdToken:async(e,n)=>{const r=`${s}/link/idtoken`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},changeUserMfa:async e=>{const n=`${s}/mfa/totp/generate`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},createPAT:async(e,n)=>{const r=`${s}/pat`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInAnonymous:async(e,n)=>{const r=`${s}/signin/anonymous`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInEmailPassword:async(e,n)=>{const r=`${s}/signin/email-password`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInIdToken:async(e,n)=>{const r=`${s}/signin/idtoken`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInMfaTotp:async(e,n)=>{const r=`${s}/signin/mfa/totp`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInOTPEmail:async(e,n)=>{const r=`${s}/signin/otp/email`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInOTPEmail:async(e,n)=>{const r=`${s}/signin/otp/email/verify`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInPasswordlessEmail:async(e,n)=>{const r=`${s}/signin/passwordless/email`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInPasswordlessSms:async(e,n)=>{const r=`${s}/signin/passwordless/sms`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInPasswordlessSms:async(e,n)=>{const r=`${s}/signin/passwordless/sms/otp`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInPAT:async(e,n)=>{const r=`${s}/signin/pat`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signInProviderURL:(t,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?`${s}/signin/provider/${t}?${a}`:`${s}/signin/provider/${t}`},signInWebauthn:async(e,n)=>{const r=`${s}/signin/webauthn`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignInWebauthn:async(e,n)=>{const r=`${s}/signin/webauthn/verify`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signOut:async(e,n)=>{const r=`${s}/signout`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signUpEmailPassword:async(e,n)=>{const r=`${s}/signup/email-password`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},signUpWebauthn:async(e,n)=>{const r=`${s}/signup/webauthn`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifySignUpWebauthn:async(e,n)=>{const r=`${s}/signup/webauthn/verify`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},refreshToken:async(e,n)=>{const r=`${s}/token`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifyToken:async(e,n)=>{const r=`${s}/token/verify`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},getUser:async e=>{const n=`${s}/user`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},deanonymizeUser:async(e,n)=>{const r=`${s}/user/deanonymize`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},changeUserEmail:async(e,n)=>{const r=`${s}/user/email/change`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},sendVerificationEmail:async(e,n)=>{const r=`${s}/user/email/send-verification-email`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifyChangeUserMfa:async(e,n)=>{const r=`${s}/user/mfa`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},changeUserPassword:async(e,n)=>{const r=`${s}/user/password`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},sendPasswordResetEmail:async(e,n)=>{const r=`${s}/user/password/reset`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},addSecurityKey:async e=>{const n=`${s}/user/webauthn/add`,r=await a(n,{...e,method:"POST",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},verifyAddSecurityKey:async(e,n)=>{const r=`${s}/user/webauthn/verify`,i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifyTicketURL:t=>{const e=t&&Object.entries(t).map((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s?JSON.stringify(s):s;return`${t}=${encodeURIComponent(e)}`})).join("&");return e?`${s}/verify?${e}`:`${s}/verify`},getVersion:async e=>{const n=`${s}/version`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text(),e=s?JSON.parse(s):{};throw new t.FetchError(e,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}}}};
|
|
2
2
|
//# sourceMappingURL=auth.cjs.js.map
|