@nvisy/sdk 0.53.0 → 0.55.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/dist/datatypes/index.d.ts +2 -2
  3. package/dist/{errors-aOivXE8A.d.ts → errors-DShmkdjS.d.ts} +2 -2
  4. package/dist/{errors-aOivXE8A.d.ts.map → errors-DShmkdjS.d.ts.map} +1 -1
  5. package/dist/guest/index.d.ts +35 -0
  6. package/dist/guest/index.d.ts.map +1 -0
  7. package/dist/guest/index.js +59 -0
  8. package/dist/guest/index.js.map +1 -0
  9. package/dist/http-BRaKBzAA.js +128 -0
  10. package/dist/http-BRaKBzAA.js.map +1 -0
  11. package/dist/{client-DywPcOzJ.d.ts → index-CuKzO8Ly.d.ts} +357 -216
  12. package/dist/index-CuKzO8Ly.d.ts.map +1 -0
  13. package/dist/{index-rc5Y8RNG.d.ts → index-DzEtj1r2.d.ts} +109 -51
  14. package/dist/index-DzEtj1r2.d.ts.map +1 -0
  15. package/dist/index.d.ts +4 -5
  16. package/dist/index.js +34 -120
  17. package/dist/index.js.map +1 -1
  18. package/dist/services/index.d.ts +2 -2
  19. package/dist/services/index.js +2 -2
  20. package/dist/{services-DFJfjW1b.js → services-BMmcawiT.js} +117 -60
  21. package/dist/services-BMmcawiT.js.map +1 -0
  22. package/dist/webhooks/index.d.ts +2 -2
  23. package/package.json +4 -4
  24. package/dist/client-DywPcOzJ.d.ts.map +0 -1
  25. package/dist/config-BdAgnJlh.d.ts +0 -103
  26. package/dist/config-BdAgnJlh.d.ts.map +0 -1
  27. package/dist/error-D_h2zq6T.js +0 -47
  28. package/dist/error-D_h2zq6T.js.map +0 -1
  29. package/dist/index-rc5Y8RNG.d.ts.map +0 -1
  30. package/dist/services-DFJfjW1b.js.map +0 -1
  31. package/dist/standalone/index.d.ts +0 -117
  32. package/dist/standalone/index.d.ts.map +0 -1
  33. package/dist/standalone/index.js +0 -153
  34. package/dist/standalone/index.js.map +0 -1
@@ -1,153 +0,0 @@
1
- import { n as DEFAULTS, t as errorMiddleware } from "../error-D_h2zq6T.js";
2
- import createClient from "openapi-fetch";
3
-
4
- //#region src/standalone/http.ts
5
- /**
6
- * @fileoverview Shared openapi-fetch client factory for the SDK's standalone
7
- * operations (auth, health) that run before a {@link Nvisy} client exists.
8
- *
9
- * @module http
10
- * @internal
11
- */
12
- /**
13
- * Build an unauthenticated openapi-fetch client from a {@link PublicConfig}.
14
- *
15
- * Applies the shared base URL / user-agent / header / fetch resolution used by
16
- * both the auth helpers and the health check.
17
- */
18
- function createPublicClient(config, { json = false, errorHandling = true } = {}) {
19
- const headers = {
20
- "User-Agent": config?.userAgent ?? DEFAULTS.USER_AGENT,
21
- ...json ? { "Content-Type": "application/json" } : {},
22
- ...config?.headers
23
- };
24
- const client = createClient({
25
- baseUrl: config?.baseUrl ?? DEFAULTS.BASE_URL,
26
- headers,
27
- fetch: config?.fetch,
28
- ...config?.credentials ? { credentials: config.credentials } : {}
29
- });
30
- if (errorHandling) client.use(errorMiddleware);
31
- return client;
32
- }
33
-
34
- //#endregion
35
- //#region src/standalone/auth.ts
36
- /**
37
- * Creates an unauthenticated API client for auth operations.
38
- *
39
- * @param config - Optional configuration options
40
- * @returns A configured openapi-fetch client without authentication
41
- * @internal
42
- */
43
- function createAuthClient(config) {
44
- return createPublicClient(config, { json: true });
45
- }
46
- /**
47
- * Login with email and password, starting a browser session.
48
- *
49
- * A standalone function that needs no existing {@link Client}. Sets HttpOnly
50
- * session and CSRF cookies; returns no body. For a programmatic client, create
51
- * an API token instead and pass it as `apiToken` when constructing the client.
52
- *
53
- * @param credentials - Login credentials (identifier and password)
54
- * @param config - Optional configuration (baseUrl, credentials, headers,
55
- * userAgent, fetch); pass `credentials: "include"` for a cross-origin session
56
- * @returns Promise that resolves once the session is started
57
- * @throws {ApiError} If the credentials are invalid or the request fails
58
- *
59
- * @example
60
- * ```typescript
61
- * import { login } from "@nvisy/sdk/standalone";
62
- *
63
- * await login(
64
- * { identifier: "user@example.com", password: "your-password" },
65
- * { credentials: "include" },
66
- * );
67
- * ```
68
- */
69
- async function login(credentials, config) {
70
- await createAuthClient(config).POST("/auth/login", { body: credentials });
71
- }
72
- /**
73
- * Sign up a new account, starting a browser session.
74
- *
75
- * A standalone function that needs no existing {@link Client}. Sets HttpOnly
76
- * session and CSRF cookies; returns no body. For a programmatic client, create
77
- * an API token instead and pass it as `apiToken` when constructing the client.
78
- *
79
- * @param details - Signup details (username, emailAddress, password, etc.)
80
- * @param config - Optional configuration (baseUrl, credentials, headers,
81
- * userAgent, fetch); pass `credentials: "include"` for a cross-origin session
82
- * @returns Promise that resolves once the session is started
83
- * @throws {ApiError} If the signup fails (e.g., email already exists)
84
- *
85
- * @example
86
- * ```typescript
87
- * import { signup } from "@nvisy/sdk/standalone";
88
- *
89
- * await signup(
90
- * {
91
- * username: "johndoe",
92
- * emailAddress: "john@example.com",
93
- * password: "secure-password",
94
- * },
95
- * { credentials: "include" },
96
- * );
97
- * ```
98
- */
99
- async function signup(details, config) {
100
- await createAuthClient(config).POST("/auth/signup", { body: details });
101
- }
102
- /**
103
- * Begin an OpenID Connect sign-in with a provider.
104
- *
105
- * A standalone function that needs no existing {@link Client}. Returns the
106
- * provider authorize URL to redirect the user to; on consent the provider
107
- * redirects to the callback, which signs the user in.
108
- *
109
- * @param provider - The identity provider to sign in with
110
- * @param query - Optional frontend URL to return to once done
111
- * @param config - Optional configuration (baseUrl, headers, userAgent, fetch)
112
- * @returns Promise that resolves with the provider authorize URL
113
- * @throws {ApiError} If the request fails
114
- *
115
- * @example
116
- * ```typescript
117
- * import { startOidcSignIn } from "@nvisy/sdk/standalone";
118
- *
119
- * const { authorizeUrl } = await startOidcSignIn("google", {
120
- * redirectUri: "https://app.example.com/after-login",
121
- * });
122
- * window.location.href = authorizeUrl;
123
- * ```
124
- */
125
- async function startOidcSignIn(provider, query, config) {
126
- const { data } = await createAuthClient(config).GET("/auth/{provider}/start", { params: {
127
- path: { provider },
128
- query
129
- } });
130
- return data;
131
- }
132
-
133
- //#endregion
134
- //#region src/standalone/health.ts
135
- /**
136
- * Check the health status of the API, without an API token or a client.
137
- *
138
- * The health endpoint is public: an unauthenticated request returns a cached
139
- * status, an authenticated one performs a real-time check. This function sends
140
- * no token; pass one via `config.headers` if a real-time check is desired.
141
- *
142
- * @param config - Optional configuration (baseUrl, headers, userAgent, fetch)
143
- * @returns Promise that resolves with the API health status (for both the
144
- * healthy `200` and degraded `503` responses)
145
- */
146
- async function checkHealth(config) {
147
- const { data, error } = await createPublicClient(config, { errorHandling: false }).GET("/health");
148
- return data ?? error;
149
- }
150
-
151
- //#endregion
152
- export { checkHealth, login, signup, startOidcSignIn };
153
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/standalone/http.ts","../../src/standalone/auth.ts","../../src/standalone/health.ts"],"sourcesContent":["/**\n * @fileoverview Shared openapi-fetch client factory for the SDK's standalone\n * operations (auth, health) that run before a {@link Nvisy} client exists.\n *\n * @module http\n * @internal\n */\n\nimport createClient from \"openapi-fetch\";\nimport type { ClientConfig } from \"@/config.js\";\nimport { DEFAULTS } from \"@/config.js\";\nimport { errorMiddleware } from \"@/middleware/index.js\";\nimport type { paths } from \"@/schema/api.js\";\n\n/** Config accepted by a standalone (unauthenticated) client. */\nexport type PublicConfig = Omit<ClientConfig, \"apiToken\">;\n\ninterface PublicClientOptions {\n\t/** Send a JSON `Content-Type` header (for requests with a body). */\n\tjson?: boolean;\n\t/**\n\t * Throw {@link NvisyApiError} / {@link NvisyError} on non-2xx responses and\n\t * network failures. Off for endpoints where a non-2xx body is a valid\n\t * result (e.g. health `503`).\n\t *\n\t * @default true\n\t */\n\terrorHandling?: boolean;\n}\n\n/**\n * Build an unauthenticated openapi-fetch client from a {@link PublicConfig}.\n *\n * Applies the shared base URL / user-agent / header / fetch resolution used by\n * both the auth helpers and the health check.\n */\nexport function createPublicClient(\n\tconfig?: PublicConfig,\n\t{ json = false, errorHandling = true }: PublicClientOptions = {},\n) {\n\tconst headers: Record<string, string> = {\n\t\t\"User-Agent\": config?.userAgent ?? DEFAULTS.USER_AGENT,\n\t\t...(json ? { \"Content-Type\": \"application/json\" } : {}),\n\t\t...config?.headers,\n\t};\n\n\tconst client = createClient<paths>({\n\t\tbaseUrl: config?.baseUrl ?? DEFAULTS.BASE_URL,\n\t\theaders,\n\t\t// `undefined` falls back to the global fetch inside openapi-fetch.\n\t\tfetch: config?.fetch,\n\t\t// Forward `credentials` so login/signup can establish a cross-origin\n\t\t// cookie session (the browser stores Set-Cookie only with \"include\").\n\t\t...(config?.credentials ? { credentials: config.credentials } : {}),\n\t});\n\n\tif (errorHandling) client.use(errorMiddleware);\n\treturn client;\n}\n","/**\n * @fileoverview Standalone authentication functions.\n *\n * These functions start a browser session without an existing client: login\n * and signup set HttpOnly session and CSRF cookies (they return no body), and\n * `startOidcSignIn` returns a provider authorize URL to redirect to.\n *\n * For a programmatic (non-browser) client, do not use these to obtain a\n * credential — a cookie session is not replayed across SDK calls. Instead\n * create an API token (via the account's api-tokens endpoint) and pass it as\n * `apiToken` when constructing a {@link Client}.\n *\n * @module standalone/auth\n *\n * @example\n * ```typescript\n * import { login } from \"@nvisy/sdk/standalone\";\n *\n * // Browser: start a cookie session\n * await login(\n * { identifier: \"user@example.com\", password: \"...\" },\n * { credentials: \"include\" },\n * );\n * ```\n */\n\nimport type {\n\tIdentityProvider,\n\tLogin,\n\tOidcStartResponse,\n\tSignup,\n} from \"@/datatypes/index.js\";\nimport type { AuthConfig } from \"@/standalone/config.js\";\nimport { createPublicClient } from \"@/standalone/http.js\";\n\n/**\n * Creates an unauthenticated API client for auth operations.\n *\n * @param config - Optional configuration options\n * @returns A configured openapi-fetch client without authentication\n * @internal\n */\nfunction createAuthClient(config?: AuthConfig) {\n\treturn createPublicClient(config, { json: true });\n}\n\n/**\n * Login with email and password, starting a browser session.\n *\n * A standalone function that needs no existing {@link Client}. Sets HttpOnly\n * session and CSRF cookies; returns no body. For a programmatic client, create\n * an API token instead and pass it as `apiToken` when constructing the client.\n *\n * @param credentials - Login credentials (identifier and password)\n * @param config - Optional configuration (baseUrl, credentials, headers,\n * userAgent, fetch); pass `credentials: \"include\"` for a cross-origin session\n * @returns Promise that resolves once the session is started\n * @throws {ApiError} If the credentials are invalid or the request fails\n *\n * @example\n * ```typescript\n * import { login } from \"@nvisy/sdk/standalone\";\n *\n * await login(\n * { identifier: \"user@example.com\", password: \"your-password\" },\n * { credentials: \"include\" },\n * );\n * ```\n */\nexport async function login(\n\tcredentials: Login,\n\tconfig?: AuthConfig,\n): Promise<void> {\n\tconst client = createAuthClient(config);\n\tawait client.POST(\"/auth/login\", {\n\t\tbody: credentials,\n\t});\n}\n\n/**\n * Sign up a new account, starting a browser session.\n *\n * A standalone function that needs no existing {@link Client}. Sets HttpOnly\n * session and CSRF cookies; returns no body. For a programmatic client, create\n * an API token instead and pass it as `apiToken` when constructing the client.\n *\n * @param details - Signup details (username, emailAddress, password, etc.)\n * @param config - Optional configuration (baseUrl, credentials, headers,\n * userAgent, fetch); pass `credentials: \"include\"` for a cross-origin session\n * @returns Promise that resolves once the session is started\n * @throws {ApiError} If the signup fails (e.g., email already exists)\n *\n * @example\n * ```typescript\n * import { signup } from \"@nvisy/sdk/standalone\";\n *\n * await signup(\n * {\n * username: \"johndoe\",\n * emailAddress: \"john@example.com\",\n * password: \"secure-password\",\n * },\n * { credentials: \"include\" },\n * );\n * ```\n */\nexport async function signup(\n\tdetails: Signup,\n\tconfig?: AuthConfig,\n): Promise<void> {\n\tconst client = createAuthClient(config);\n\tawait client.POST(\"/auth/signup\", {\n\t\tbody: details,\n\t});\n}\n\n/**\n * Begin an OpenID Connect sign-in with a provider.\n *\n * A standalone function that needs no existing {@link Client}. Returns the\n * provider authorize URL to redirect the user to; on consent the provider\n * redirects to the callback, which signs the user in.\n *\n * @param provider - The identity provider to sign in with\n * @param query - Optional frontend URL to return to once done\n * @param config - Optional configuration (baseUrl, headers, userAgent, fetch)\n * @returns Promise that resolves with the provider authorize URL\n * @throws {ApiError} If the request fails\n *\n * @example\n * ```typescript\n * import { startOidcSignIn } from \"@nvisy/sdk/standalone\";\n *\n * const { authorizeUrl } = await startOidcSignIn(\"google\", {\n * redirectUri: \"https://app.example.com/after-login\",\n * });\n * window.location.href = authorizeUrl;\n * ```\n */\nexport async function startOidcSignIn(\n\tprovider: IdentityProvider,\n\tquery?: { redirectUri?: string },\n\tconfig?: AuthConfig,\n): Promise<OidcStartResponse> {\n\tconst client = createAuthClient(config);\n\tconst { data } = await client.GET(\"/auth/{provider}/start\", {\n\t\tparams: { path: { provider }, query },\n\t});\n\treturn data!;\n}\n","/**\n * @fileoverview Standalone API health check.\n *\n * This module provides a `checkHealth` function that does not require an API\n * token or a {@link Nvisy} client. Use it as a pre-auth liveness probe.\n *\n * @module standalone/health\n *\n * @example\n * ```typescript\n * import { checkHealth } from \"@nvisy/sdk/standalone\";\n *\n * const health = await checkHealth();\n * if (health.status !== \"healthy\") {\n * // back off, retry, alert, ...\n * }\n * ```\n */\n\nimport type { Health } from \"@/datatypes/index.js\";\nimport type { HealthConfig } from \"@/standalone/config.js\";\nimport { createPublicClient } from \"@/standalone/http.js\";\n\n/**\n * Check the health status of the API, without an API token or a client.\n *\n * The health endpoint is public: an unauthenticated request returns a cached\n * status, an authenticated one performs a real-time check. This function sends\n * no token; pass one via `config.headers` if a real-time check is desired.\n *\n * @param config - Optional configuration (baseUrl, headers, userAgent, fetch)\n * @returns Promise that resolves with the API health status (for both the\n * healthy `200` and degraded `503` responses)\n */\nexport async function checkHealth(config?: HealthConfig): Promise<Health> {\n\t// `errorHandling: false` — the health endpoint returns a `Health` body on\n\t// both `200` (healthy) and `503` (degraded); a degraded status is a valid\n\t// result to return, not an error to throw.\n\tconst client = createPublicClient(config, { errorHandling: false });\n\n\tconst { data, error } = await client.GET(\"/health\");\n\t// `data` on 200, `error` on 503 — both carry a `Health`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