@kaiz11/stack-client 0.0.14
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 +32 -0
- package/README.md +586 -0
- package/dist/accounts/accounts-client.d.ts +188 -0
- package/dist/accounts/accounts-client.d.ts.map +1 -0
- package/dist/accounts/accounts-client.js +264 -0
- package/dist/accounts/accounts-client.js.map +1 -0
- package/dist/accounts/index.d.ts +8 -0
- package/dist/accounts/index.d.ts.map +1 -0
- package/dist/accounts/index.js +8 -0
- package/dist/accounts/index.js.map +1 -0
- package/dist/accounts/mock-accounts.d.ts +90 -0
- package/dist/accounts/mock-accounts.d.ts.map +1 -0
- package/dist/accounts/mock-accounts.js +434 -0
- package/dist/accounts/mock-accounts.js.map +1 -0
- package/dist/accounts/types.d.ts +180 -0
- package/dist/accounts/types.d.ts.map +1 -0
- package/dist/accounts/types.js +59 -0
- package/dist/accounts/types.js.map +1 -0
- package/dist/auth/auth-client.d.ts +224 -0
- package/dist/auth/auth-client.d.ts.map +1 -0
- package/dist/auth/auth-client.js +230 -0
- package/dist/auth/auth-client.js.map +1 -0
- package/dist/auth/base-auth.d.ts +44 -0
- package/dist/auth/base-auth.d.ts.map +1 -0
- package/dist/auth/base-auth.js +55 -0
- package/dist/auth/base-auth.js.map +1 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +11 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/methods/admin.d.ts +59 -0
- package/dist/auth/methods/admin.d.ts.map +1 -0
- package/dist/auth/methods/admin.js +55 -0
- package/dist/auth/methods/admin.js.map +1 -0
- package/dist/auth/methods/index.d.ts +9 -0
- package/dist/auth/methods/index.d.ts.map +1 -0
- package/dist/auth/methods/index.js +8 -0
- package/dist/auth/methods/index.js.map +1 -0
- package/dist/auth/methods/magic-link.d.ts +27 -0
- package/dist/auth/methods/magic-link.d.ts.map +1 -0
- package/dist/auth/methods/magic-link.js +37 -0
- package/dist/auth/methods/magic-link.js.map +1 -0
- package/dist/auth/methods/mfa.d.ts +92 -0
- package/dist/auth/methods/mfa.d.ts.map +1 -0
- package/dist/auth/methods/mfa.js +153 -0
- package/dist/auth/methods/mfa.js.map +1 -0
- package/dist/auth/methods/oauth.d.ts +62 -0
- package/dist/auth/methods/oauth.d.ts.map +1 -0
- package/dist/auth/methods/oauth.js +165 -0
- package/dist/auth/methods/oauth.js.map +1 -0
- package/dist/auth/methods/otp.d.ts +43 -0
- package/dist/auth/methods/otp.d.ts.map +1 -0
- package/dist/auth/methods/otp.js +66 -0
- package/dist/auth/methods/otp.js.map +1 -0
- package/dist/auth/methods/password.d.ts +64 -0
- package/dist/auth/methods/password.d.ts.map +1 -0
- package/dist/auth/methods/password.js +116 -0
- package/dist/auth/methods/password.js.map +1 -0
- package/dist/auth/methods/recovery.d.ts +62 -0
- package/dist/auth/methods/recovery.d.ts.map +1 -0
- package/dist/auth/methods/recovery.js +100 -0
- package/dist/auth/methods/recovery.js.map +1 -0
- package/dist/auth/mock-auth.d.ts +135 -0
- package/dist/auth/mock-auth.d.ts.map +1 -0
- package/dist/auth/mock-auth.js +417 -0
- package/dist/auth/mock-auth.js.map +1 -0
- package/dist/auth/server/helpers.d.ts +215 -0
- package/dist/auth/server/helpers.d.ts.map +1 -0
- package/dist/auth/server/helpers.js +241 -0
- package/dist/auth/server/helpers.js.map +1 -0
- package/dist/auth/server/index.d.ts +24 -0
- package/dist/auth/server/index.d.ts.map +1 -0
- package/dist/auth/server/index.js +40 -0
- package/dist/auth/server/index.js.map +1 -0
- package/dist/auth/server/middleware.d.ts +305 -0
- package/dist/auth/server/middleware.d.ts.map +1 -0
- package/dist/auth/server/middleware.js +405 -0
- package/dist/auth/server/middleware.js.map +1 -0
- package/dist/auth/server/verify.d.ts +184 -0
- package/dist/auth/server/verify.d.ts.map +1 -0
- package/dist/auth/server/verify.js +222 -0
- package/dist/auth/server/verify.js.map +1 -0
- package/dist/auth/token-manager.d.ts +94 -0
- package/dist/auth/token-manager.d.ts.map +1 -0
- package/dist/auth/token-manager.js +231 -0
- package/dist/auth/token-manager.js.map +1 -0
- package/dist/auth/types.d.ts +412 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +66 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/user/identities.d.ts +62 -0
- package/dist/auth/user/identities.d.ts.map +1 -0
- package/dist/auth/user/identities.js +88 -0
- package/dist/auth/user/identities.js.map +1 -0
- package/dist/auth/user/index.d.ts +4 -0
- package/dist/auth/user/index.d.ts.map +1 -0
- package/dist/auth/user/index.js +4 -0
- package/dist/auth/user/index.js.map +1 -0
- package/dist/auth/user/user.d.ts +64 -0
- package/dist/auth/user/user.d.ts.map +1 -0
- package/dist/auth/user/user.js +105 -0
- package/dist/auth/user/user.js.map +1 -0
- package/dist/auth/user/verification.d.ts +49 -0
- package/dist/auth/user/verification.d.ts.map +1 -0
- package/dist/auth/user/verification.js +71 -0
- package/dist/auth/user/verification.js.map +1 -0
- package/dist/cli/browser.d.ts +11 -0
- package/dist/cli/browser.d.ts.map +1 -0
- package/dist/cli/browser.js +35 -0
- package/dist/cli/browser.js.map +1 -0
- package/dist/cli/callback-server.d.ts +30 -0
- package/dist/cli/callback-server.d.ts.map +1 -0
- package/dist/cli/callback-server.js +100 -0
- package/dist/cli/callback-server.js.map +1 -0
- package/dist/cli/file-token-store.d.ts +79 -0
- package/dist/cli/file-token-store.d.ts.map +1 -0
- package/dist/cli/file-token-store.js +138 -0
- package/dist/cli/file-token-store.js.map +1 -0
- package/dist/cli/index.d.ts +33 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +38 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/oauth.d.ts +67 -0
- package/dist/cli/oauth.d.ts.map +1 -0
- package/dist/cli/oauth.js +101 -0
- package/dist/cli/oauth.js.map +1 -0
- package/dist/cli/pkce.d.ts +35 -0
- package/dist/cli/pkce.d.ts.map +1 -0
- package/dist/cli/pkce.js +43 -0
- package/dist/cli/pkce.js.map +1 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +99 -0
- package/dist/client.js.map +1 -0
- package/dist/db/client.d.ts +9 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +19 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/errors.d.ts +19 -0
- package/dist/db/errors.d.ts.map +1 -0
- package/dist/db/errors.js +57 -0
- package/dist/db/errors.js.map +1 -0
- package/dist/db/index.d.ts +7 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +5 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/mock.d.ts +28 -0
- package/dist/db/mock.d.ts.map +1 -0
- package/dist/db/mock.js +459 -0
- package/dist/db/mock.js.map +1 -0
- package/dist/db/types.d.ts +73 -0
- package/dist/db/types.d.ts.map +1 -0
- package/dist/db/types.js +2 -0
- package/dist/db/types.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/errors.d.ts +33 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +76 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/http.d.ts +81 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/http.js +163 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/keys.d.ts +87 -0
- package/dist/lib/keys.d.ts.map +1 -0
- package/dist/lib/keys.js +147 -0
- package/dist/lib/keys.js.map +1 -0
- package/dist/lib/paths.d.ts +37 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/paths.js +49 -0
- package/dist/lib/paths.js.map +1 -0
- package/dist/lib/token-store.d.ts +42 -0
- package/dist/lib/token-store.d.ts.map +1 -0
- package/dist/lib/token-store.js +75 -0
- package/dist/lib/token-store.js.map +1 -0
- package/dist/mocks/handlers.d.ts +29 -0
- package/dist/mocks/handlers.d.ts.map +1 -0
- package/dist/mocks/handlers.js +79 -0
- package/dist/mocks/handlers.js.map +1 -0
- package/dist/mocks/index.d.ts +5 -0
- package/dist/mocks/index.d.ts.map +1 -0
- package/dist/mocks/index.js +9 -0
- package/dist/mocks/index.js.map +1 -0
- package/dist/mocks/responses.d.ts +76 -0
- package/dist/mocks/responses.d.ts.map +1 -0
- package/dist/mocks/responses.js +91 -0
- package/dist/mocks/responses.js.map +1 -0
- package/dist/mocks/server.d.ts +7 -0
- package/dist/mocks/server.d.ts.map +1 -0
- package/dist/mocks/server.js +9 -0
- package/dist/mocks/server.js.map +1 -0
- package/dist/mocks/state.d.ts +86 -0
- package/dist/mocks/state.d.ts.map +1 -0
- package/dist/mocks/state.js +77 -0
- package/dist/mocks/state.js.map +1 -0
- package/dist/storage/bucket-ref.d.ts +183 -0
- package/dist/storage/bucket-ref.d.ts.map +1 -0
- package/dist/storage/bucket-ref.js +529 -0
- package/dist/storage/bucket-ref.js.map +1 -0
- package/dist/storage/errors.d.ts +27 -0
- package/dist/storage/errors.d.ts.map +1 -0
- package/dist/storage/errors.js +89 -0
- package/dist/storage/errors.js.map +1 -0
- package/dist/storage/index.d.ts +13 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +11 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/interface.d.ts +245 -0
- package/dist/storage/interface.d.ts.map +1 -0
- package/dist/storage/interface.js +2 -0
- package/dist/storage/interface.js.map +1 -0
- package/dist/storage/mock-storage.d.ts +67 -0
- package/dist/storage/mock-storage.d.ts.map +1 -0
- package/dist/storage/mock-storage.js +478 -0
- package/dist/storage/mock-storage.js.map +1 -0
- package/dist/storage/policies-client.d.ts +77 -0
- package/dist/storage/policies-client.d.ts.map +1 -0
- package/dist/storage/policies-client.js +115 -0
- package/dist/storage/policies-client.js.map +1 -0
- package/dist/storage/policy-templates.d.ts +6 -0
- package/dist/storage/policy-templates.d.ts.map +1 -0
- package/dist/storage/policy-templates.js +290 -0
- package/dist/storage/policy-templates.js.map +1 -0
- package/dist/storage/policy-types.d.ts +98 -0
- package/dist/storage/policy-types.d.ts.map +1 -0
- package/dist/storage/policy-types.js +20 -0
- package/dist/storage/policy-types.js.map +1 -0
- package/dist/storage/storage-client.d.ts +32 -0
- package/dist/storage/storage-client.d.ts.map +1 -0
- package/dist/storage/storage-client.js +94 -0
- package/dist/storage/storage-client.js.map +1 -0
- package/dist/storage/tus-upload.d.ts +56 -0
- package/dist/storage/tus-upload.d.ts.map +1 -0
- package/dist/storage/tus-upload.js +236 -0
- package/dist/storage/tus-upload.js.map +1 -0
- package/dist/storage/types.d.ts +335 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +39 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/test/auth/helpers.d.ts +33 -0
- package/dist/test/auth/helpers.d.ts.map +1 -0
- package/dist/test/auth/helpers.js +80 -0
- package/dist/test/auth/helpers.js.map +1 -0
- package/dist/test/helpers/jwt.d.ts +61 -0
- package/dist/test/helpers/jwt.d.ts.map +1 -0
- package/dist/test/helpers/jwt.js +132 -0
- package/dist/test/helpers/jwt.js.map +1 -0
- package/dist/test/helpers/mailpit.d.ts +61 -0
- package/dist/test/helpers/mailpit.d.ts.map +1 -0
- package/dist/test/helpers/mailpit.js +107 -0
- package/dist/test/helpers/mailpit.js.map +1 -0
- package/dist/test/setup.d.ts +2 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +17 -0
- package/dist/test/setup.js.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { HttpClient } from "../../lib/http.js";
|
|
2
|
+
import type { TokenManager } from "../token-manager.js";
|
|
3
|
+
import type { User, UpdateUserOptions, Session } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* User management methods
|
|
6
|
+
*/
|
|
7
|
+
export declare class UserMethods {
|
|
8
|
+
private readonly http;
|
|
9
|
+
private readonly tokenManager;
|
|
10
|
+
private readonly tenantId;
|
|
11
|
+
constructor(http: HttpClient, tokenManager: TokenManager, tenantId: string);
|
|
12
|
+
/**
|
|
13
|
+
* Get the current user (from local session)
|
|
14
|
+
*
|
|
15
|
+
* Returns the cached user from the current session.
|
|
16
|
+
* For a fresh user from the server, use `getUser()`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const user = client.auth.user.getCurrent();
|
|
21
|
+
* if (user) {
|
|
22
|
+
* console.log("Logged in as:", user.email);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
getCurrent(): User | null;
|
|
27
|
+
/**
|
|
28
|
+
* Get the current user (fresh from server)
|
|
29
|
+
*
|
|
30
|
+
* Fetches the latest user data from the server, including
|
|
31
|
+
* any changes made elsewhere.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const user = await client.auth.user.get();
|
|
36
|
+
* console.log("Email verified:", !!user.emailConfirmedAt);
|
|
37
|
+
* console.log("Identities:", user.identities);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
get(): Promise<User>;
|
|
41
|
+
/**
|
|
42
|
+
* Update the current user
|
|
43
|
+
*
|
|
44
|
+
* Can update email, phone, password, or user metadata.
|
|
45
|
+
* Some changes (email, phone, password) may require reauthentication.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Update metadata
|
|
50
|
+
* const session = await client.auth.user.update({
|
|
51
|
+
* data: { name: "New Name", avatar: "https://..." },
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Update email (requires reauthentication)
|
|
55
|
+
* const { nonce } = await client.auth.reauthenticate();
|
|
56
|
+
* const session = await client.auth.user.update({
|
|
57
|
+
* email: "newemail@example.com",
|
|
58
|
+
* nonce,
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
update(options: UpdateUserOptions): Promise<Session>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/auth/user/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,IAAI,EACJ,iBAAiB,EACjB,OAAO,EAGR,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM;IAGnC;;;;;;;;;;;;;OAaG;IACH,UAAU,IAAI,IAAI,GAAG,IAAI;IAKzB;;;;;;;;;;;;OAYG;IACG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAM1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;CAiC3D"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { authPath } from "../../lib/paths.js";
|
|
2
|
+
import { AuthError } from "../../lib/errors.js";
|
|
3
|
+
import { normalizeUser, normalizeSession } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* User management methods
|
|
6
|
+
*/
|
|
7
|
+
export class UserMethods {
|
|
8
|
+
http;
|
|
9
|
+
tokenManager;
|
|
10
|
+
tenantId;
|
|
11
|
+
constructor(http, tokenManager, tenantId) {
|
|
12
|
+
this.http = http;
|
|
13
|
+
this.tokenManager = tokenManager;
|
|
14
|
+
this.tenantId = tenantId;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the current user (from local session)
|
|
18
|
+
*
|
|
19
|
+
* Returns the cached user from the current session.
|
|
20
|
+
* For a fresh user from the server, use `getUser()`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const user = client.auth.user.getCurrent();
|
|
25
|
+
* if (user) {
|
|
26
|
+
* console.log("Logged in as:", user.email);
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
getCurrent() {
|
|
31
|
+
const session = this.tokenManager.getSession();
|
|
32
|
+
return session?.user ?? null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the current user (fresh from server)
|
|
36
|
+
*
|
|
37
|
+
* Fetches the latest user data from the server, including
|
|
38
|
+
* any changes made elsewhere.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const user = await client.auth.user.get();
|
|
43
|
+
* console.log("Email verified:", !!user.emailConfirmedAt);
|
|
44
|
+
* console.log("Identities:", user.identities);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
async get() {
|
|
48
|
+
const path = authPath(this.tenantId, "/user");
|
|
49
|
+
const response = await this.http.get(path);
|
|
50
|
+
return normalizeUser(response);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Update the current user
|
|
54
|
+
*
|
|
55
|
+
* Can update email, phone, password, or user metadata.
|
|
56
|
+
* Some changes (email, phone, password) may require reauthentication.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Update metadata
|
|
61
|
+
* const session = await client.auth.user.update({
|
|
62
|
+
* data: { name: "New Name", avatar: "https://..." },
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Update email (requires reauthentication)
|
|
66
|
+
* const { nonce } = await client.auth.reauthenticate();
|
|
67
|
+
* const session = await client.auth.user.update({
|
|
68
|
+
* email: "newemail@example.com",
|
|
69
|
+
* nonce,
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
async update(options) {
|
|
74
|
+
const path = authPath(this.tenantId, "/user");
|
|
75
|
+
const body = {};
|
|
76
|
+
if (options.email)
|
|
77
|
+
body.email = options.email;
|
|
78
|
+
if (options.phone)
|
|
79
|
+
body.phone = options.phone;
|
|
80
|
+
if (options.password)
|
|
81
|
+
body.password = options.password;
|
|
82
|
+
if (options.data)
|
|
83
|
+
body.data = options.data;
|
|
84
|
+
if (options.nonce)
|
|
85
|
+
body.nonce = options.nonce;
|
|
86
|
+
const response = await this.http.put(path, body);
|
|
87
|
+
let session;
|
|
88
|
+
if ("user" in response && response.user) {
|
|
89
|
+
session = normalizeSession(response);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const currentSession = this.tokenManager.getSession();
|
|
93
|
+
if (!currentSession) {
|
|
94
|
+
throw AuthError.notAuthenticated();
|
|
95
|
+
}
|
|
96
|
+
session = {
|
|
97
|
+
...currentSession,
|
|
98
|
+
user: normalizeUser(response),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
this.tokenManager.setSession(session, "USER_UPDATED");
|
|
102
|
+
return session;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/auth/user/user.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAShD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,WAAW;IAEH;IACA;IACA;IAHnB,YACmB,IAAgB,EAChB,YAA0B,EAC1B,QAAgB;QAFhB,SAAI,GAAJ,IAAI,CAAY;QAChB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAQ;IAChC,CAAC;IAEJ;;;;;;;;;;;;;OAaG;IACH,UAAU;QACR,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;QAC/C,OAAO,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAa,IAAI,CAAC,CAAC;QACvD,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,MAAM,CAAC,OAA0B;QACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE9C,MAAM,IAAI,GAA4B,EAAE,CAAC;QACzC,IAAI,OAAO,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9C,IAAI,OAAO,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9C,IAAI,OAAO,CAAC,QAAQ;YAAE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACvD,IAAI,OAAO,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3C,IAAI,OAAO,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAClC,IAAI,EACJ,IAAI,CACL,CAAC;QAEF,IAAI,OAAgB,CAAC;QACrB,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,OAAO,GAAG,gBAAgB,CAAC,QAA+B,CAAC,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;YACtD,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,MAAM,SAAS,CAAC,gBAAgB,EAAE,CAAC;YACrC,CAAC;YAED,OAAO,GAAG;gBACR,GAAG,cAAc;gBACjB,IAAI,EAAE,aAAa,CAAC,QAAsB,CAAC;aAC5C,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { HttpClient } from "../../lib/http.js";
|
|
2
|
+
import type { TokenManager } from "../token-manager.js";
|
|
3
|
+
import type { VerifyOptions, ResendVerificationOptions, Session } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Email/phone verification methods
|
|
6
|
+
*/
|
|
7
|
+
export declare class VerificationMethods {
|
|
8
|
+
private readonly http;
|
|
9
|
+
private readonly tokenManager;
|
|
10
|
+
private readonly tenantId;
|
|
11
|
+
constructor(http: HttpClient, tokenManager: TokenManager, tenantId: string);
|
|
12
|
+
/**
|
|
13
|
+
* Verify email or phone with a verification token
|
|
14
|
+
*
|
|
15
|
+
* Called when user clicks a verification link or enters a code.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Handle verification link callback
|
|
20
|
+
* const params = new URLSearchParams(window.location.search);
|
|
21
|
+
* const session = await client.auth.verification.verify({
|
|
22
|
+
* token: params.get("token")!,
|
|
23
|
+
* type: "signup",
|
|
24
|
+
* email: params.get("email")!,
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
verify(options: VerifyOptions): Promise<Session>;
|
|
29
|
+
/**
|
|
30
|
+
* Resend a verification email or SMS
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Resend signup verification email
|
|
35
|
+
* await client.auth.verification.resend({
|
|
36
|
+
* email: "user@example.com",
|
|
37
|
+
* type: "signup",
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Resend email change verification
|
|
41
|
+
* await client.auth.verification.resend({
|
|
42
|
+
* email: "newemail@example.com",
|
|
43
|
+
* type: "email_change",
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
resend(options: ResendVerificationOptions): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=verification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../../src/auth/user/verification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,aAAa,EACb,yBAAyB,EACzB,OAAO,EAER,MAAM,aAAa,CAAC;AAUrB;;GAEG;AACH,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM;IAGnC;;;;;;;;;;;;;;;OAeG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBtD;;;;;;;;;;;;;;;;;OAiBG;IACG,MAAM,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;CAchE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { authPath } from "../../lib/paths.js";
|
|
2
|
+
import { normalizeSession } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Email/phone verification methods
|
|
5
|
+
*/
|
|
6
|
+
export class VerificationMethods {
|
|
7
|
+
http;
|
|
8
|
+
tokenManager;
|
|
9
|
+
tenantId;
|
|
10
|
+
constructor(http, tokenManager, tenantId) {
|
|
11
|
+
this.http = http;
|
|
12
|
+
this.tokenManager = tokenManager;
|
|
13
|
+
this.tenantId = tenantId;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Verify email or phone with a verification token
|
|
17
|
+
*
|
|
18
|
+
* Called when user clicks a verification link or enters a code.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Handle verification link callback
|
|
23
|
+
* const params = new URLSearchParams(window.location.search);
|
|
24
|
+
* const session = await client.auth.verification.verify({
|
|
25
|
+
* token: params.get("token")!,
|
|
26
|
+
* type: "signup",
|
|
27
|
+
* email: params.get("email")!,
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
async verify(options) {
|
|
32
|
+
const path = authPath(this.tenantId, "/verify");
|
|
33
|
+
const response = await this.http.post(path, {
|
|
34
|
+
token: options.token,
|
|
35
|
+
type: options.type,
|
|
36
|
+
email: options.email,
|
|
37
|
+
phone: options.phone,
|
|
38
|
+
}, { noAuth: true });
|
|
39
|
+
const session = normalizeSession(response);
|
|
40
|
+
this.tokenManager.setSession(session);
|
|
41
|
+
return session;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resend a verification email or SMS
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Resend signup verification email
|
|
49
|
+
* await client.auth.verification.resend({
|
|
50
|
+
* email: "user@example.com",
|
|
51
|
+
* type: "signup",
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Resend email change verification
|
|
55
|
+
* await client.auth.verification.resend({
|
|
56
|
+
* email: "newemail@example.com",
|
|
57
|
+
* type: "email_change",
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async resend(options) {
|
|
62
|
+
const path = authPath(this.tenantId, "/resend");
|
|
63
|
+
await this.http.post(path, {
|
|
64
|
+
email: options.email,
|
|
65
|
+
phone: options.phone,
|
|
66
|
+
type: options.type,
|
|
67
|
+
redirect_to: options.redirectTo,
|
|
68
|
+
}, { noAuth: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=verification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../../src/auth/user/verification.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQ9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS/C;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAEX;IACA;IACA;IAHnB,YACmB,IAAgB,EAChB,YAA0B,EAC1B,QAAgB;QAFhB,SAAI,GAAJ,IAAI,CAAY;QAChB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAQ;IAChC,CAAC;IAEJ;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,MAAM,CAAC,OAAsB;QACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAEhD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,IAAI,EACJ;YACE,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;QAEF,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,MAAM,CAAC,OAAkC;QAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAEhD,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAClB,IAAI,EACJ;YACE,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,UAAU;SAChC,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform browser opener for CLI OAuth flows.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Open a URL in the default browser.
|
|
6
|
+
*
|
|
7
|
+
* @param url - The URL to open
|
|
8
|
+
* @returns Promise that resolves when the browser command is executed
|
|
9
|
+
*/
|
|
10
|
+
export declare function openBrowser(url: string): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/cli/browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBtD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-platform browser opener for CLI OAuth flows.
|
|
3
|
+
*/
|
|
4
|
+
import { exec } from "node:child_process";
|
|
5
|
+
/**
|
|
6
|
+
* Open a URL in the default browser.
|
|
7
|
+
*
|
|
8
|
+
* @param url - The URL to open
|
|
9
|
+
* @returns Promise that resolves when the browser command is executed
|
|
10
|
+
*/
|
|
11
|
+
export function openBrowser(url) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const platform = process.platform;
|
|
14
|
+
let command;
|
|
15
|
+
if (platform === "darwin") {
|
|
16
|
+
command = `open "${url}"`;
|
|
17
|
+
}
|
|
18
|
+
else if (platform === "win32") {
|
|
19
|
+
command = `start "" "${url}"`;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// Linux and others
|
|
23
|
+
command = `xdg-open "${url}"`;
|
|
24
|
+
}
|
|
25
|
+
exec(command, (error) => {
|
|
26
|
+
if (error) {
|
|
27
|
+
reject(error);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
resolve();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/cli/browser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAElC,IAAI,OAAe,CAAC;QACpB,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1B,OAAO,GAAG,SAAS,GAAG,GAAG,CAAC;QAC5B,CAAC;aAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YAChC,OAAO,GAAG,aAAa,GAAG,GAAG,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,mBAAmB;YACnB,OAAO,GAAG,aAAa,GAAG,GAAG,CAAC;QAChC,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACtB,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local HTTP server for OAuth callback handling.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Result from the OAuth callback
|
|
6
|
+
*/
|
|
7
|
+
export interface CallbackResult {
|
|
8
|
+
/** Authorization code from OAuth provider */
|
|
9
|
+
code: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Options for the callback server
|
|
13
|
+
*/
|
|
14
|
+
export interface CallbackServerOptions {
|
|
15
|
+
/** Port to listen on (default: 14550) */
|
|
16
|
+
port?: number;
|
|
17
|
+
/** Timeout in milliseconds (default: 120000 = 2 minutes) */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Start a local HTTP server to receive OAuth callback.
|
|
22
|
+
*
|
|
23
|
+
* The server listens for a single request with ?code=xxx query parameter,
|
|
24
|
+
* then automatically shuts down.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Server options
|
|
27
|
+
* @returns Promise that resolves with the authorization code
|
|
28
|
+
*/
|
|
29
|
+
export declare function startCallbackServer(options?: CallbackServerOptions): Promise<CallbackResult>;
|
|
30
|
+
//# sourceMappingURL=callback-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-server.d.ts","sourceRoot":"","sources":["../../src/cli/callback-server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,cAAc,CAAC,CAkGzB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local HTTP server for OAuth callback handling.
|
|
3
|
+
*/
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
/**
|
|
6
|
+
* Start a local HTTP server to receive OAuth callback.
|
|
7
|
+
*
|
|
8
|
+
* The server listens for a single request with ?code=xxx query parameter,
|
|
9
|
+
* then automatically shuts down.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Server options
|
|
12
|
+
* @returns Promise that resolves with the authorization code
|
|
13
|
+
*/
|
|
14
|
+
export function startCallbackServer(options = {}) {
|
|
15
|
+
const { port = 14550, timeout = 120000 } = options;
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
let server = null;
|
|
18
|
+
let timeoutId = null;
|
|
19
|
+
const cleanup = () => {
|
|
20
|
+
if (timeoutId) {
|
|
21
|
+
clearTimeout(timeoutId);
|
|
22
|
+
timeoutId = null;
|
|
23
|
+
}
|
|
24
|
+
if (server) {
|
|
25
|
+
server.close();
|
|
26
|
+
server = null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// Set timeout
|
|
30
|
+
timeoutId = setTimeout(() => {
|
|
31
|
+
cleanup();
|
|
32
|
+
reject(new Error("OAuth callback timeout - no response received"));
|
|
33
|
+
}, timeout);
|
|
34
|
+
server = createServer((req, res) => {
|
|
35
|
+
const url = new URL(req.url ?? "/", `http://localhost:${port}`);
|
|
36
|
+
// Handle callback path
|
|
37
|
+
if (url.pathname === "/callback") {
|
|
38
|
+
const code = url.searchParams.get("code");
|
|
39
|
+
const error = url.searchParams.get("error");
|
|
40
|
+
const errorDescription = url.searchParams.get("error_description");
|
|
41
|
+
// Send response to browser
|
|
42
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
43
|
+
if (error) {
|
|
44
|
+
res.end(`
|
|
45
|
+
<!DOCTYPE html>
|
|
46
|
+
<html>
|
|
47
|
+
<head><title>Authentication Failed</title></head>
|
|
48
|
+
<body style="font-family: system-ui; padding: 40px; text-align: center;">
|
|
49
|
+
<h1>Authentication Failed</h1>
|
|
50
|
+
<p>${errorDescription || error}</p>
|
|
51
|
+
<p>You can close this window.</p>
|
|
52
|
+
</body>
|
|
53
|
+
</html>
|
|
54
|
+
`);
|
|
55
|
+
cleanup();
|
|
56
|
+
reject(new Error(errorDescription || error));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!code) {
|
|
60
|
+
res.end(`
|
|
61
|
+
<!DOCTYPE html>
|
|
62
|
+
<html>
|
|
63
|
+
<head><title>Authentication Failed</title></head>
|
|
64
|
+
<body style="font-family: system-ui; padding: 40px; text-align: center;">
|
|
65
|
+
<h1>Authentication Failed</h1>
|
|
66
|
+
<p>No authorization code received.</p>
|
|
67
|
+
<p>You can close this window.</p>
|
|
68
|
+
</body>
|
|
69
|
+
</html>
|
|
70
|
+
`);
|
|
71
|
+
cleanup();
|
|
72
|
+
reject(new Error("No authorization code received"));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
res.end(`
|
|
76
|
+
<!DOCTYPE html>
|
|
77
|
+
<html>
|
|
78
|
+
<head><title>Authentication Successful</title></head>
|
|
79
|
+
<body style="font-family: system-ui; padding: 40px; text-align: center;">
|
|
80
|
+
<h1>Authentication Successful</h1>
|
|
81
|
+
<p>You can close this window and return to your terminal.</p>
|
|
82
|
+
</body>
|
|
83
|
+
</html>
|
|
84
|
+
`);
|
|
85
|
+
cleanup();
|
|
86
|
+
resolve({ code });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
// Unknown path
|
|
90
|
+
res.writeHead(404);
|
|
91
|
+
res.end("Not found");
|
|
92
|
+
});
|
|
93
|
+
server.on("error", (err) => {
|
|
94
|
+
cleanup();
|
|
95
|
+
reject(err);
|
|
96
|
+
});
|
|
97
|
+
server.listen(port, "127.0.0.1");
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=callback-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-server.js","sourceRoot":"","sources":["../../src/cli/callback-server.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-based token storage (for Node.js CLI applications)
|
|
3
|
+
*
|
|
4
|
+
* This module is intentionally separate from the main token-store.ts
|
|
5
|
+
* to avoid bundlers trying to resolve Node.js modules in browser builds.
|
|
6
|
+
*/
|
|
7
|
+
import type { TokenStore } from "../lib/token-store.js";
|
|
8
|
+
/**
|
|
9
|
+
* Data structure stored in the token file.
|
|
10
|
+
*/
|
|
11
|
+
export interface FileTokenData {
|
|
12
|
+
accessToken: string;
|
|
13
|
+
refreshToken: string;
|
|
14
|
+
/** Additional metadata (expiresAt, user info, etc.) */
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* File-based token storage for CLI applications.
|
|
19
|
+
*
|
|
20
|
+
* Stores tokens in a JSON file with restricted permissions (0600).
|
|
21
|
+
* Only available from the /cli entry point to avoid breaking browser builds.
|
|
22
|
+
*
|
|
23
|
+
* Supports storing additional metadata alongside tokens via `setTokensWithData`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { FileTokenStore } from "@kaiz11/stack-client/cli";
|
|
28
|
+
*
|
|
29
|
+
* const store = new FileTokenStore("~/.myapp/tokens.json");
|
|
30
|
+
*
|
|
31
|
+
* // Basic usage
|
|
32
|
+
* store.setTokens(accessToken, refreshToken);
|
|
33
|
+
*
|
|
34
|
+
* // With metadata
|
|
35
|
+
* store.setTokensWithData(accessToken, refreshToken, {
|
|
36
|
+
* expiresAt: 1234567890,
|
|
37
|
+
* user: { id: "123", email: "user@example.com" }
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Retrieve full data
|
|
41
|
+
* const data = store.getData();
|
|
42
|
+
* console.log(data?.expiresAt, data?.user);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class FileTokenStore implements TokenStore {
|
|
46
|
+
private data;
|
|
47
|
+
private loaded;
|
|
48
|
+
/** File path - protected so subclasses can access it */
|
|
49
|
+
protected readonly filePath: string;
|
|
50
|
+
/**
|
|
51
|
+
* @param filePath - Absolute path to the token file
|
|
52
|
+
*/
|
|
53
|
+
constructor(filePath: string);
|
|
54
|
+
/**
|
|
55
|
+
* Load data from file if not already loaded.
|
|
56
|
+
*/
|
|
57
|
+
protected ensureLoaded(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Persist data to file.
|
|
60
|
+
*/
|
|
61
|
+
protected persist(): void;
|
|
62
|
+
getAccessToken(): string | null;
|
|
63
|
+
getRefreshToken(): string | null;
|
|
64
|
+
/**
|
|
65
|
+
* Get all stored data including metadata.
|
|
66
|
+
*/
|
|
67
|
+
getData(): FileTokenData | null;
|
|
68
|
+
setTokens(accessToken: string, refreshToken: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Set tokens with additional metadata.
|
|
71
|
+
*
|
|
72
|
+
* @param accessToken - The access token
|
|
73
|
+
* @param refreshToken - The refresh token
|
|
74
|
+
* @param metadata - Additional data to store (expiresAt, user, etc.)
|
|
75
|
+
*/
|
|
76
|
+
setTokensWithData(accessToken: string, refreshToken: string, metadata: Record<string, unknown>): void;
|
|
77
|
+
clearTokens(): void;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=file-token-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-token-store.d.ts","sourceRoot":"","sources":["../../src/cli/file-token-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,MAAM,CAAS;IAEvB,wDAAwD;IACxD,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAEpC;;OAEG;gBACS,QAAQ,EAAE,MAAM;IAI5B;;OAEG;IACH,SAAS,CAAC,YAAY,IAAI,IAAI;IAsB9B;;OAEG;IACH,SAAS,CAAC,OAAO,IAAI,IAAI;IAmBzB,cAAc,IAAI,MAAM,GAAG,IAAI;IAK/B,eAAe,IAAI,MAAM,GAAG,IAAI;IAKhC;;OAEG;IACH,OAAO,IAAI,aAAa,GAAG,IAAI;IAK/B,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAI1D;;;;;;OAMG;IACH,iBAAiB,CACf,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,IAAI;IAUP,WAAW,IAAI,IAAI;CAYpB"}
|