@archlast/client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +60 -0
- package/dist/admin/index.cjs +93 -0
- package/dist/admin/index.cjs.map +1 -0
- package/dist/admin/index.d.cts +51 -0
- package/dist/admin/index.d.ts +51 -0
- package/dist/admin/index.js +59 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/auth/index.cjs +174 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +128 -0
- package/dist/auth/index.d.ts +128 -0
- package/dist/auth/index.js +141 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/client.cjs +677 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +84 -0
- package/dist/client.d.ts +84 -0
- package/dist/client.js +642 -0
- package/dist/client.js.map +1 -0
- package/dist/function-reference.cjs +50 -0
- package/dist/function-reference.cjs.map +1 -0
- package/dist/function-reference.d.cts +22 -0
- package/dist/function-reference.d.ts +22 -0
- package/dist/function-reference.js +24 -0
- package/dist/function-reference.js.map +1 -0
- package/dist/index.cjs +1163 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1111 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +455 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +137 -0
- package/dist/react.d.ts +137 -0
- package/dist/react.js +410 -0
- package/dist/react.js.map +1 -0
- package/dist/storage/index.cjs +150 -0
- package/dist/storage/index.cjs.map +1 -0
- package/dist/storage/index.d.cts +59 -0
- package/dist/storage/index.d.ts +59 -0
- package/dist/storage/index.js +117 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/trpc.cjs +66 -0
- package/dist/trpc.cjs.map +1 -0
- package/dist/trpc.d.cts +59 -0
- package/dist/trpc.d.ts +59 -0
- package/dist/trpc.js +41 -0
- package/dist/trpc.js.map +1 -0
- package/package.json +90 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Archlast Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @archlast/client
|
|
2
|
+
|
|
3
|
+
Archlast client SDK for React hooks, auth helpers, storage utilities, and tRPC client access.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @archlast/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies (install in your app):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install react react-dom @tanstack/react-query
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { ArchlastClient, ArchlastProvider, useQuery } from "@archlast/client";
|
|
21
|
+
import { api } from "./_generated/api";
|
|
22
|
+
|
|
23
|
+
const client = new ArchlastClient({ baseUrl: "http://localhost:4000" });
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
return (
|
|
27
|
+
<ArchlastProvider client={client}>
|
|
28
|
+
<TodoList />
|
|
29
|
+
</ArchlastProvider>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function TodoList() {
|
|
34
|
+
const tasks = useQuery(api.tasks.list, {});
|
|
35
|
+
return <pre>{JSON.stringify(tasks, null, 2)}</pre>;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Subpath exports
|
|
40
|
+
|
|
41
|
+
- `@archlast/client/react`
|
|
42
|
+
- `@archlast/client/trpc`
|
|
43
|
+
- `@archlast/client/auth`
|
|
44
|
+
- `@archlast/client/storage`
|
|
45
|
+
- `@archlast/client/admin`
|
|
46
|
+
|
|
47
|
+
## tRPC client
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { createArchlastTRPCClient } from "@archlast/client/trpc";
|
|
51
|
+
import type { AppRouter } from "./_generated/rpc";
|
|
52
|
+
|
|
53
|
+
const trpc = createArchlastTRPCClient<AppRouter>({
|
|
54
|
+
baseUrl: "http://localhost:4000",
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Publishing (maintainers)
|
|
59
|
+
|
|
60
|
+
See `docs/npm-publishing.md` for release and publish steps.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
|
+
|
|
32
|
+
// src/admin/index.ts
|
|
33
|
+
var admin_exports = {};
|
|
34
|
+
__export(admin_exports, {
|
|
35
|
+
AdminAuthClient: () => AdminAuthClient,
|
|
36
|
+
AdminClient: () => AdminClient
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(admin_exports);
|
|
39
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
40
|
+
var AdminAuthClient = class {
|
|
41
|
+
constructor(baseUrl, options) {
|
|
42
|
+
__publicField(this, "axios");
|
|
43
|
+
this.axios = import_axios.default.create({
|
|
44
|
+
baseURL: baseUrl,
|
|
45
|
+
withCredentials: !options?.apiKey,
|
|
46
|
+
headers: {
|
|
47
|
+
...options?.apiKey ? { "x-api-key": options.apiKey } : {}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async signIn(email, password) {
|
|
52
|
+
const response = await this.axios.post("/_archlast/admin/auth/sign-in", {
|
|
53
|
+
email,
|
|
54
|
+
password
|
|
55
|
+
});
|
|
56
|
+
return response.data;
|
|
57
|
+
}
|
|
58
|
+
async signOut() {
|
|
59
|
+
const response = await this.axios.post("/_archlast/admin/auth/sign-out");
|
|
60
|
+
return response.data;
|
|
61
|
+
}
|
|
62
|
+
async getProfile() {
|
|
63
|
+
const response = await this.axios.get("/_archlast/admin/auth/me");
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
async getSessions() {
|
|
67
|
+
const response = await this.axios.get("/_archlast/admin/auth/sessions");
|
|
68
|
+
return response.data;
|
|
69
|
+
}
|
|
70
|
+
async revokeSession(sessionId) {
|
|
71
|
+
const response = await this.axios.post("/_archlast/admin/auth/revoke-session", {
|
|
72
|
+
sessionId
|
|
73
|
+
});
|
|
74
|
+
return response.data;
|
|
75
|
+
}
|
|
76
|
+
async signOutAll() {
|
|
77
|
+
const response = await this.axios.post("/_archlast/admin/auth/sign-out-all");
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var AdminClient = class {
|
|
82
|
+
// Add other admin clients here (users, tenants, etc.)
|
|
83
|
+
constructor(baseUrl, options) {
|
|
84
|
+
__publicField(this, "auth");
|
|
85
|
+
this.auth = new AdminAuthClient(baseUrl, options);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
AdminAuthClient,
|
|
91
|
+
AdminClient
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/index.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nexport type AdminSession = {\n id: string;\n userId: string;\n createdAt: number;\n lastAccess: number;\n userAgent: string | null;\n ipAddress: string | null;\n current: boolean;\n};\n\nexport type AdminProfile = {\n id: string;\n email: string;\n is_super_admin: boolean;\n created_at: number;\n};\n\nexport type AdminClientOptions = {\n /**\n * Better-Auth API key for authentication\n * When provided, uses x-api-key header instead of cookies\n */\n apiKey?: string;\n};\n\nexport class AdminAuthClient {\n private readonly axios: AxiosInstance;\n\n constructor(baseUrl: string, options?: AdminClientOptions) {\n this.axios = axios.create({\n baseURL: baseUrl,\n withCredentials: !options?.apiKey,\n headers: {\n ...(options?.apiKey ? { \"x-api-key\": options.apiKey } : {}),\n },\n });\n }\n\n async signIn(\n email: string,\n password: string\n ): Promise<{ success: boolean; user: AdminProfile }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-in\", {\n email,\n password,\n });\n return response.data;\n }\n\n async signOut(): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-out\");\n return response.data;\n }\n\n async getProfile(): Promise<{ user: AdminProfile }> {\n const response = await this.axios.get(\"/_archlast/admin/auth/me\");\n return response.data;\n }\n\n async getSessions(): Promise<{ sessions: AdminSession[] }> {\n const response = await this.axios.get(\"/_archlast/admin/auth/sessions\");\n return response.data;\n }\n\n async revokeSession(sessionId: string): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/revoke-session\", {\n sessionId,\n });\n return response.data;\n }\n\n async signOutAll(): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-out-all\");\n return response.data;\n }\n}\n\nexport class AdminClient {\n public auth: AdminAuthClient;\n // Add other admin clients here (users, tenants, etc.)\n\n constructor(baseUrl: string, options?: AdminClientOptions) {\n this.auth = new AdminAuthClient(baseUrl, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AA2B9B,IAAM,kBAAN,MAAsB;AAAA,EAGzB,YAAY,SAAiB,SAA8B;AAF3D,wBAAiB;AAGb,SAAK,QAAQ,aAAAA,QAAM,OAAO;AAAA,MACtB,SAAS;AAAA,MACT,iBAAiB,CAAC,SAAS;AAAA,MAC3B,SAAS;AAAA,QACL,GAAI,SAAS,SAAS,EAAE,aAAa,QAAQ,OAAO,IAAI,CAAC;AAAA,MAC7D;AAAA,IACJ,CAAC;AAAA,EACL;AAAA,EAEA,MAAM,OACF,OACA,UACiD;AACjD,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,iCAAiC;AAAA,MACpE;AAAA,MACA;AAAA,IACJ,CAAC;AACD,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,UAAyC;AAC3C,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,gCAAgC;AACvE,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,aAA8C;AAChD,UAAM,WAAW,MAAM,KAAK,MAAM,IAAI,0BAA0B;AAChE,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,cAAqD;AACvD,UAAM,WAAW,MAAM,KAAK,MAAM,IAAI,gCAAgC;AACtE,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,cAAc,WAAkD;AAClE,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,wCAAwC;AAAA,MAC3E;AAAA,IACJ,CAAC;AACD,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,aAA4C;AAC9C,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,oCAAoC;AAC3E,WAAO,SAAS;AAAA,EACpB;AACJ;AAEO,IAAM,cAAN,MAAkB;AAAA;AAAA,EAIrB,YAAY,SAAiB,SAA8B;AAH3D,wBAAO;AAIH,SAAK,OAAO,IAAI,gBAAgB,SAAS,OAAO;AAAA,EACpD;AACJ;","names":["axios"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type AdminSession = {
|
|
2
|
+
id: string;
|
|
3
|
+
userId: string;
|
|
4
|
+
createdAt: number;
|
|
5
|
+
lastAccess: number;
|
|
6
|
+
userAgent: string | null;
|
|
7
|
+
ipAddress: string | null;
|
|
8
|
+
current: boolean;
|
|
9
|
+
};
|
|
10
|
+
type AdminProfile = {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
is_super_admin: boolean;
|
|
14
|
+
created_at: number;
|
|
15
|
+
};
|
|
16
|
+
type AdminClientOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Better-Auth API key for authentication
|
|
19
|
+
* When provided, uses x-api-key header instead of cookies
|
|
20
|
+
*/
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
};
|
|
23
|
+
declare class AdminAuthClient {
|
|
24
|
+
private readonly axios;
|
|
25
|
+
constructor(baseUrl: string, options?: AdminClientOptions);
|
|
26
|
+
signIn(email: string, password: string): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
user: AdminProfile;
|
|
29
|
+
}>;
|
|
30
|
+
signOut(): Promise<{
|
|
31
|
+
success: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
getProfile(): Promise<{
|
|
34
|
+
user: AdminProfile;
|
|
35
|
+
}>;
|
|
36
|
+
getSessions(): Promise<{
|
|
37
|
+
sessions: AdminSession[];
|
|
38
|
+
}>;
|
|
39
|
+
revokeSession(sessionId: string): Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
signOutAll(): Promise<{
|
|
43
|
+
success: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
declare class AdminClient {
|
|
47
|
+
auth: AdminAuthClient;
|
|
48
|
+
constructor(baseUrl: string, options?: AdminClientOptions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { AdminAuthClient, AdminClient, type AdminClientOptions, type AdminProfile, type AdminSession };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type AdminSession = {
|
|
2
|
+
id: string;
|
|
3
|
+
userId: string;
|
|
4
|
+
createdAt: number;
|
|
5
|
+
lastAccess: number;
|
|
6
|
+
userAgent: string | null;
|
|
7
|
+
ipAddress: string | null;
|
|
8
|
+
current: boolean;
|
|
9
|
+
};
|
|
10
|
+
type AdminProfile = {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
is_super_admin: boolean;
|
|
14
|
+
created_at: number;
|
|
15
|
+
};
|
|
16
|
+
type AdminClientOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Better-Auth API key for authentication
|
|
19
|
+
* When provided, uses x-api-key header instead of cookies
|
|
20
|
+
*/
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
};
|
|
23
|
+
declare class AdminAuthClient {
|
|
24
|
+
private readonly axios;
|
|
25
|
+
constructor(baseUrl: string, options?: AdminClientOptions);
|
|
26
|
+
signIn(email: string, password: string): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
user: AdminProfile;
|
|
29
|
+
}>;
|
|
30
|
+
signOut(): Promise<{
|
|
31
|
+
success: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
getProfile(): Promise<{
|
|
34
|
+
user: AdminProfile;
|
|
35
|
+
}>;
|
|
36
|
+
getSessions(): Promise<{
|
|
37
|
+
sessions: AdminSession[];
|
|
38
|
+
}>;
|
|
39
|
+
revokeSession(sessionId: string): Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
signOutAll(): Promise<{
|
|
43
|
+
success: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
declare class AdminClient {
|
|
47
|
+
auth: AdminAuthClient;
|
|
48
|
+
constructor(baseUrl: string, options?: AdminClientOptions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { AdminAuthClient, AdminClient, type AdminClientOptions, type AdminProfile, type AdminSession };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/admin/index.ts
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
var AdminAuthClient = class {
|
|
8
|
+
constructor(baseUrl, options) {
|
|
9
|
+
__publicField(this, "axios");
|
|
10
|
+
this.axios = axios.create({
|
|
11
|
+
baseURL: baseUrl,
|
|
12
|
+
withCredentials: !options?.apiKey,
|
|
13
|
+
headers: {
|
|
14
|
+
...options?.apiKey ? { "x-api-key": options.apiKey } : {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async signIn(email, password) {
|
|
19
|
+
const response = await this.axios.post("/_archlast/admin/auth/sign-in", {
|
|
20
|
+
email,
|
|
21
|
+
password
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
async signOut() {
|
|
26
|
+
const response = await this.axios.post("/_archlast/admin/auth/sign-out");
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
29
|
+
async getProfile() {
|
|
30
|
+
const response = await this.axios.get("/_archlast/admin/auth/me");
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
|
33
|
+
async getSessions() {
|
|
34
|
+
const response = await this.axios.get("/_archlast/admin/auth/sessions");
|
|
35
|
+
return response.data;
|
|
36
|
+
}
|
|
37
|
+
async revokeSession(sessionId) {
|
|
38
|
+
const response = await this.axios.post("/_archlast/admin/auth/revoke-session", {
|
|
39
|
+
sessionId
|
|
40
|
+
});
|
|
41
|
+
return response.data;
|
|
42
|
+
}
|
|
43
|
+
async signOutAll() {
|
|
44
|
+
const response = await this.axios.post("/_archlast/admin/auth/sign-out-all");
|
|
45
|
+
return response.data;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var AdminClient = class {
|
|
49
|
+
// Add other admin clients here (users, tenants, etc.)
|
|
50
|
+
constructor(baseUrl, options) {
|
|
51
|
+
__publicField(this, "auth");
|
|
52
|
+
this.auth = new AdminAuthClient(baseUrl, options);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
AdminAuthClient,
|
|
57
|
+
AdminClient
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/index.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nexport type AdminSession = {\n id: string;\n userId: string;\n createdAt: number;\n lastAccess: number;\n userAgent: string | null;\n ipAddress: string | null;\n current: boolean;\n};\n\nexport type AdminProfile = {\n id: string;\n email: string;\n is_super_admin: boolean;\n created_at: number;\n};\n\nexport type AdminClientOptions = {\n /**\n * Better-Auth API key for authentication\n * When provided, uses x-api-key header instead of cookies\n */\n apiKey?: string;\n};\n\nexport class AdminAuthClient {\n private readonly axios: AxiosInstance;\n\n constructor(baseUrl: string, options?: AdminClientOptions) {\n this.axios = axios.create({\n baseURL: baseUrl,\n withCredentials: !options?.apiKey,\n headers: {\n ...(options?.apiKey ? { \"x-api-key\": options.apiKey } : {}),\n },\n });\n }\n\n async signIn(\n email: string,\n password: string\n ): Promise<{ success: boolean; user: AdminProfile }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-in\", {\n email,\n password,\n });\n return response.data;\n }\n\n async signOut(): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-out\");\n return response.data;\n }\n\n async getProfile(): Promise<{ user: AdminProfile }> {\n const response = await this.axios.get(\"/_archlast/admin/auth/me\");\n return response.data;\n }\n\n async getSessions(): Promise<{ sessions: AdminSession[] }> {\n const response = await this.axios.get(\"/_archlast/admin/auth/sessions\");\n return response.data;\n }\n\n async revokeSession(sessionId: string): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/revoke-session\", {\n sessionId,\n });\n return response.data;\n }\n\n async signOutAll(): Promise<{ success: boolean }> {\n const response = await this.axios.post(\"/_archlast/admin/auth/sign-out-all\");\n return response.data;\n }\n}\n\nexport class AdminClient {\n public auth: AdminAuthClient;\n // Add other admin clients here (users, tenants, etc.)\n\n constructor(baseUrl: string, options?: AdminClientOptions) {\n this.auth = new AdminAuthClient(baseUrl, options);\n }\n}\n"],"mappings":";;;;;AAAA,OAAO,WAA8B;AA2B9B,IAAM,kBAAN,MAAsB;AAAA,EAGzB,YAAY,SAAiB,SAA8B;AAF3D,wBAAiB;AAGb,SAAK,QAAQ,MAAM,OAAO;AAAA,MACtB,SAAS;AAAA,MACT,iBAAiB,CAAC,SAAS;AAAA,MAC3B,SAAS;AAAA,QACL,GAAI,SAAS,SAAS,EAAE,aAAa,QAAQ,OAAO,IAAI,CAAC;AAAA,MAC7D;AAAA,IACJ,CAAC;AAAA,EACL;AAAA,EAEA,MAAM,OACF,OACA,UACiD;AACjD,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,iCAAiC;AAAA,MACpE;AAAA,MACA;AAAA,IACJ,CAAC;AACD,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,UAAyC;AAC3C,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,gCAAgC;AACvE,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,aAA8C;AAChD,UAAM,WAAW,MAAM,KAAK,MAAM,IAAI,0BAA0B;AAChE,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,cAAqD;AACvD,UAAM,WAAW,MAAM,KAAK,MAAM,IAAI,gCAAgC;AACtE,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,cAAc,WAAkD;AAClE,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,wCAAwC;AAAA,MAC3E;AAAA,IACJ,CAAC;AACD,WAAO,SAAS;AAAA,EACpB;AAAA,EAEA,MAAM,aAA4C;AAC9C,UAAM,WAAW,MAAM,KAAK,MAAM,KAAK,oCAAoC;AAC3E,WAAO,SAAS;AAAA,EACpB;AACJ;AAEO,IAAM,cAAN,MAAkB;AAAA;AAAA,EAIrB,YAAY,SAAiB,SAA8B;AAH3D,wBAAO;AAIH,SAAK,OAAO,IAAI,gBAAgB,SAAS,OAAO;AAAA,EACpD;AACJ;","names":[]}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
|
+
|
|
32
|
+
// src/auth/index.ts
|
|
33
|
+
var auth_exports = {};
|
|
34
|
+
__export(auth_exports, {
|
|
35
|
+
ArchlastAuthClient: () => ArchlastAuthClient,
|
|
36
|
+
default: () => auth_default
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(auth_exports);
|
|
39
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
40
|
+
function resolveBaseUrl(explicit) {
|
|
41
|
+
if (explicit && explicit.trim()) return explicit.replace(/\/+$/, "");
|
|
42
|
+
if (typeof window !== "undefined" && window.location?.origin) return window.location.origin;
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
var ArchlastAuthClient = class {
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
__publicField(this, "baseUrl");
|
|
48
|
+
__publicField(this, "axios");
|
|
49
|
+
__publicField(this, "appId");
|
|
50
|
+
__publicField(this, "apiKey");
|
|
51
|
+
this.baseUrl = resolveBaseUrl(options.baseUrl);
|
|
52
|
+
this.appId = options.appId;
|
|
53
|
+
this.apiKey = options.apiKey;
|
|
54
|
+
this.axios = import_axios.default.create({
|
|
55
|
+
baseURL: this.baseUrl,
|
|
56
|
+
withCredentials: !options.apiKey,
|
|
57
|
+
// Only use cookies if no API key
|
|
58
|
+
headers: {
|
|
59
|
+
"content-type": "application/json",
|
|
60
|
+
...this.appId ? { "x-archlast-app-id": this.appId } : {},
|
|
61
|
+
...options.apiKey ? { "x-api-key": options.apiKey } : {}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get current authentication state
|
|
67
|
+
* Uses Better-Auth's getSession endpoint
|
|
68
|
+
*/
|
|
69
|
+
async getState() {
|
|
70
|
+
try {
|
|
71
|
+
const response = await this.axios.get("/api/auth/get-session");
|
|
72
|
+
const { user, session } = response.data;
|
|
73
|
+
return {
|
|
74
|
+
user,
|
|
75
|
+
session,
|
|
76
|
+
isAuthenticated: !!user
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
user: null,
|
|
81
|
+
session: null,
|
|
82
|
+
isAuthenticated: false
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sign up new user
|
|
88
|
+
* Uses Better-Auth's email signUp endpoint
|
|
89
|
+
*/
|
|
90
|
+
async signUp(input) {
|
|
91
|
+
const response = await this.axios.post("/api/auth/sign-up/email", {
|
|
92
|
+
email: input.email,
|
|
93
|
+
password: input.password,
|
|
94
|
+
name: input.name,
|
|
95
|
+
username: input.username
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
user: response.data.user,
|
|
99
|
+
session: null,
|
|
100
|
+
// Session is managed via cookies
|
|
101
|
+
isAuthenticated: !!response.data.user
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sign in with email/username and password
|
|
106
|
+
* Uses Better-Auth's credential sign-in endpoint
|
|
107
|
+
*/
|
|
108
|
+
async signIn(input) {
|
|
109
|
+
if (!input.email && !input.username) {
|
|
110
|
+
throw new Error("Either email or username is required");
|
|
111
|
+
}
|
|
112
|
+
const response = await this.axios.post("/api/auth/sign-in/email", {
|
|
113
|
+
email: input.email,
|
|
114
|
+
username: input.username,
|
|
115
|
+
password: input.password
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
user: response.data.user,
|
|
119
|
+
session: null,
|
|
120
|
+
// Session is managed via cookies
|
|
121
|
+
isAuthenticated: !!response.data.user
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sign out and revoke session
|
|
126
|
+
* Uses Better-Auth's sign-out endpoint
|
|
127
|
+
*/
|
|
128
|
+
async signOut() {
|
|
129
|
+
const response = await this.axios.post(
|
|
130
|
+
"/api/auth/sign-out",
|
|
131
|
+
{},
|
|
132
|
+
{ withCredentials: true }
|
|
133
|
+
);
|
|
134
|
+
return response.data;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Request password reset email
|
|
138
|
+
* Uses Better-Auth's password reset flow
|
|
139
|
+
*/
|
|
140
|
+
async requestPasswordReset(email, callbackURL) {
|
|
141
|
+
const response = await this.axios.post("/api/auth/forgot-password", {
|
|
142
|
+
email,
|
|
143
|
+
redirectTo: callbackURL
|
|
144
|
+
});
|
|
145
|
+
return response.data;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Reset password with token
|
|
149
|
+
* Uses Better-Auth's reset password endpoint
|
|
150
|
+
*/
|
|
151
|
+
async resetPassword(token, password) {
|
|
152
|
+
const response = await this.axios.post("/api/auth/reset-password", {
|
|
153
|
+
token,
|
|
154
|
+
password
|
|
155
|
+
});
|
|
156
|
+
return response.data;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Verify email with token
|
|
160
|
+
* Uses Better-Auth's email verification endpoint
|
|
161
|
+
*/
|
|
162
|
+
async verifyEmail(token) {
|
|
163
|
+
const response = await this.axios.post("/api/auth/verify-email", {
|
|
164
|
+
token
|
|
165
|
+
});
|
|
166
|
+
return response.data;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var auth_default = ArchlastAuthClient;
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
ArchlastAuthClient
|
|
173
|
+
});
|
|
174
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/index.ts"],"sourcesContent":["/**\n * Client-side auth API wrapper for Archlast.\n *\n * This now uses Better-Auth endpoints via the proxy:\n * - GET /api/auth/get-session\n * - POST /api/auth/sign-up\n * - POST /api/auth/sign-in\n * - POST /api/auth/sign-out\n *\n * Migration from legacy /_auth/* endpoints:\n * - /_auth/state → /api/auth/get-session\n * - /_auth/sign-up → /api/auth/sign-up (email)\n * - /_auth/sign-in → /api/auth/sign-in (email)\n * - /_auth/sign-out → /api/auth/sign-out\n *\n * Notes:\n * - Uses cookie-based sessions by default (credentials: \"include\").\n * - For programmatic access, use Better-Auth API keys (arch_* prefix) via x-api-key header.\n * - Better-Auth supports username, OAuth, magic link, and more.\n */\n\nimport axios, { type AxiosInstance } from \"axios\";\n\nexport type AuthUser = {\n id: string;\n email: string;\n emailVerified: boolean;\n name?: string;\n image?: string;\n createdAt?: Date;\n updatedAt?: Date;\n role?: string;\n banned?: boolean;\n};\n\nexport type AuthSession = {\n token: string;\n expiresAt: Date;\n userId: string;\n ipAddress?: string;\n userAgent?: string;\n};\n\nexport type AuthState = {\n user: AuthUser | null;\n session: AuthSession | null;\n isAuthenticated: boolean;\n};\n\nexport type SignUpInput = {\n email: string;\n password: string;\n name?: string;\n username?: string;\n};\n\nexport type SignInInput = {\n email?: string;\n username?: string;\n password: string;\n};\n\nexport type ArchlastAuthClientOptions = {\n /**\n * Base URL for the Archlast server.\n * Example: \"http://localhost:4000\"\n *\n * If omitted, it will default to:\n * - window.location.origin in the browser\n * - \"\" in non-browser contexts\n */\n baseUrl?: string;\n\n /**\n * App ID for session isolation (e.g. \"web\", \"admin\").\n * When set, adds x-archlast-app-id header.\n */\n appId?: string;\n\n /**\n * Better-Auth API key for authentication.\n * When provided, uses x-api-key header instead of cookies.\n */\n apiKey?: string;\n};\n\nfunction resolveBaseUrl(explicit?: string): string {\n if (explicit && explicit.trim()) return explicit.replace(/\\/+$/, \"\");\n if (typeof window !== \"undefined\" && window.location?.origin) return window.location.origin;\n return \"\";\n}\n\nexport class ArchlastAuthClient {\n private readonly baseUrl: string;\n private readonly axios: AxiosInstance;\n private readonly appId?: string;\n private readonly apiKey?: string;\n\n constructor(options: ArchlastAuthClientOptions = {}) {\n this.baseUrl = resolveBaseUrl(options.baseUrl);\n this.appId = options.appId;\n this.apiKey = options.apiKey;\n this.axios = axios.create({\n baseURL: this.baseUrl,\n withCredentials: !options.apiKey, // Only use cookies if no API key\n headers: {\n \"content-type\": \"application/json\",\n ...(this.appId ? { \"x-archlast-app-id\": this.appId } : {}),\n ...(options.apiKey ? { \"x-api-key\": options.apiKey } : {}),\n },\n });\n }\n\n /**\n * Get current authentication state\n * Uses Better-Auth's getSession endpoint\n */\n async getState(): Promise<AuthState> {\n try {\n const response = await this.axios.get<{\n user: AuthUser | null;\n session: AuthSession | null;\n }>(\"/api/auth/get-session\");\n\n const { user, session } = response.data;\n\n return {\n user,\n session,\n isAuthenticated: !!user,\n };\n } catch (error) {\n // Return unauthenticated state on error\n return {\n user: null,\n session: null,\n isAuthenticated: false,\n };\n }\n }\n\n /**\n * Sign up new user\n * Uses Better-Auth's email signUp endpoint\n */\n async signUp(input: SignUpInput): Promise<AuthState> {\n const response = await this.axios.post<{ user: AuthUser }>(\"/api/auth/sign-up/email\", {\n email: input.email,\n password: input.password,\n name: input.name,\n username: input.username,\n });\n\n return {\n user: response.data.user,\n session: null, // Session is managed via cookies\n isAuthenticated: !!response.data.user,\n };\n }\n\n /**\n * Sign in with email/username and password\n * Uses Better-Auth's credential sign-in endpoint\n */\n async signIn(input: SignInInput): Promise<AuthState> {\n // Support email or username sign-in\n if (!input.email && !input.username) {\n throw new Error(\"Either email or username is required\");\n }\n\n const response = await this.axios.post<{ user: AuthUser }>(\"/api/auth/sign-in/email\", {\n email: input.email,\n username: input.username,\n password: input.password,\n });\n\n return {\n user: response.data.user,\n session: null, // Session is managed via cookies\n isAuthenticated: !!response.data.user,\n };\n }\n\n /**\n * Sign out and revoke session\n * Uses Better-Auth's sign-out endpoint\n */\n async signOut(): Promise<{ success: boolean }> {\n const response = await this.axios.post<{ success: boolean }>(\n \"/api/auth/sign-out\",\n {},\n { withCredentials: true }\n );\n\n return response.data;\n }\n\n /**\n * Request password reset email\n * Uses Better-Auth's password reset flow\n */\n async requestPasswordReset(email: string, callbackURL?: string): Promise<{ success: boolean }> {\n const response = await this.axios.post<{ success: boolean }>(\"/api/auth/forgot-password\", {\n email,\n redirectTo: callbackURL,\n });\n\n return response.data;\n }\n\n /**\n * Reset password with token\n * Uses Better-Auth's reset password endpoint\n */\n async resetPassword(token: string, password: string): Promise<{ success: boolean }> {\n const response = await this.axios.post<{ success: boolean }>(\"/api/auth/reset-password\", {\n token,\n password,\n });\n\n return response.data;\n }\n\n /**\n * Verify email with token\n * Uses Better-Auth's email verification endpoint\n */\n async verifyEmail(token: string): Promise<{ success: boolean; user?: AuthUser }> {\n const response = await this.axios.post<{ success: boolean; user?: AuthUser }>(\"/api/auth/verify-email\", {\n token,\n });\n\n return response.data;\n }\n}\n\n/**\n * Default export for backward compatibility\n */\nexport default ArchlastAuthClient;\n"],"mappings":"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","names":["axios"]}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side auth API wrapper for Archlast.
|
|
3
|
+
*
|
|
4
|
+
* This now uses Better-Auth endpoints via the proxy:
|
|
5
|
+
* - GET /api/auth/get-session
|
|
6
|
+
* - POST /api/auth/sign-up
|
|
7
|
+
* - POST /api/auth/sign-in
|
|
8
|
+
* - POST /api/auth/sign-out
|
|
9
|
+
*
|
|
10
|
+
* Migration from legacy /_auth/* endpoints:
|
|
11
|
+
* - /_auth/state → /api/auth/get-session
|
|
12
|
+
* - /_auth/sign-up → /api/auth/sign-up (email)
|
|
13
|
+
* - /_auth/sign-in → /api/auth/sign-in (email)
|
|
14
|
+
* - /_auth/sign-out → /api/auth/sign-out
|
|
15
|
+
*
|
|
16
|
+
* Notes:
|
|
17
|
+
* - Uses cookie-based sessions by default (credentials: "include").
|
|
18
|
+
* - For programmatic access, use Better-Auth API keys (arch_* prefix) via x-api-key header.
|
|
19
|
+
* - Better-Auth supports username, OAuth, magic link, and more.
|
|
20
|
+
*/
|
|
21
|
+
type AuthUser = {
|
|
22
|
+
id: string;
|
|
23
|
+
email: string;
|
|
24
|
+
emailVerified: boolean;
|
|
25
|
+
name?: string;
|
|
26
|
+
image?: string;
|
|
27
|
+
createdAt?: Date;
|
|
28
|
+
updatedAt?: Date;
|
|
29
|
+
role?: string;
|
|
30
|
+
banned?: boolean;
|
|
31
|
+
};
|
|
32
|
+
type AuthSession = {
|
|
33
|
+
token: string;
|
|
34
|
+
expiresAt: Date;
|
|
35
|
+
userId: string;
|
|
36
|
+
ipAddress?: string;
|
|
37
|
+
userAgent?: string;
|
|
38
|
+
};
|
|
39
|
+
type AuthState = {
|
|
40
|
+
user: AuthUser | null;
|
|
41
|
+
session: AuthSession | null;
|
|
42
|
+
isAuthenticated: boolean;
|
|
43
|
+
};
|
|
44
|
+
type SignUpInput = {
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
name?: string;
|
|
48
|
+
username?: string;
|
|
49
|
+
};
|
|
50
|
+
type SignInInput = {
|
|
51
|
+
email?: string;
|
|
52
|
+
username?: string;
|
|
53
|
+
password: string;
|
|
54
|
+
};
|
|
55
|
+
type ArchlastAuthClientOptions = {
|
|
56
|
+
/**
|
|
57
|
+
* Base URL for the Archlast server.
|
|
58
|
+
* Example: "http://localhost:4000"
|
|
59
|
+
*
|
|
60
|
+
* If omitted, it will default to:
|
|
61
|
+
* - window.location.origin in the browser
|
|
62
|
+
* - "" in non-browser contexts
|
|
63
|
+
*/
|
|
64
|
+
baseUrl?: string;
|
|
65
|
+
/**
|
|
66
|
+
* App ID for session isolation (e.g. "web", "admin").
|
|
67
|
+
* When set, adds x-archlast-app-id header.
|
|
68
|
+
*/
|
|
69
|
+
appId?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Better-Auth API key for authentication.
|
|
72
|
+
* When provided, uses x-api-key header instead of cookies.
|
|
73
|
+
*/
|
|
74
|
+
apiKey?: string;
|
|
75
|
+
};
|
|
76
|
+
declare class ArchlastAuthClient {
|
|
77
|
+
private readonly baseUrl;
|
|
78
|
+
private readonly axios;
|
|
79
|
+
private readonly appId?;
|
|
80
|
+
private readonly apiKey?;
|
|
81
|
+
constructor(options?: ArchlastAuthClientOptions);
|
|
82
|
+
/**
|
|
83
|
+
* Get current authentication state
|
|
84
|
+
* Uses Better-Auth's getSession endpoint
|
|
85
|
+
*/
|
|
86
|
+
getState(): Promise<AuthState>;
|
|
87
|
+
/**
|
|
88
|
+
* Sign up new user
|
|
89
|
+
* Uses Better-Auth's email signUp endpoint
|
|
90
|
+
*/
|
|
91
|
+
signUp(input: SignUpInput): Promise<AuthState>;
|
|
92
|
+
/**
|
|
93
|
+
* Sign in with email/username and password
|
|
94
|
+
* Uses Better-Auth's credential sign-in endpoint
|
|
95
|
+
*/
|
|
96
|
+
signIn(input: SignInInput): Promise<AuthState>;
|
|
97
|
+
/**
|
|
98
|
+
* Sign out and revoke session
|
|
99
|
+
* Uses Better-Auth's sign-out endpoint
|
|
100
|
+
*/
|
|
101
|
+
signOut(): Promise<{
|
|
102
|
+
success: boolean;
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Request password reset email
|
|
106
|
+
* Uses Better-Auth's password reset flow
|
|
107
|
+
*/
|
|
108
|
+
requestPasswordReset(email: string, callbackURL?: string): Promise<{
|
|
109
|
+
success: boolean;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Reset password with token
|
|
113
|
+
* Uses Better-Auth's reset password endpoint
|
|
114
|
+
*/
|
|
115
|
+
resetPassword(token: string, password: string): Promise<{
|
|
116
|
+
success: boolean;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Verify email with token
|
|
120
|
+
* Uses Better-Auth's email verification endpoint
|
|
121
|
+
*/
|
|
122
|
+
verifyEmail(token: string): Promise<{
|
|
123
|
+
success: boolean;
|
|
124
|
+
user?: AuthUser;
|
|
125
|
+
}>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { ArchlastAuthClient, type ArchlastAuthClientOptions, type AuthSession, type AuthState, type AuthUser, type SignInInput, type SignUpInput, ArchlastAuthClient as default };
|