authula 0.2.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.
- package/LICENSE +201 -0
- package/README.md +627 -0
- package/dist/fetch-B4O1awi2.js +124 -0
- package/dist/fetch-B4O1awi2.js.map +1 -0
- package/dist/fetch-q98rEoAp.cjs +159 -0
- package/dist/fetch-q98rEoAp.cjs.map +1 -0
- package/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/index.cjs +388 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +417 -0
- package/dist/plugins/index.d.ts +417 -0
- package/dist/plugins/index.js +377 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/sdk-BWoai6MP.d.ts +163 -0
- package/dist/sdk-DV73pbRH.d.cts +163 -0
- package/package.json +52 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/types/http.d.ts
|
|
4
|
+
type FetchContext = {
|
|
5
|
+
url: string;
|
|
6
|
+
init: RequestInit; /** internal metadata for plugins */
|
|
7
|
+
meta: {
|
|
8
|
+
retry?: boolean;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
type BeforeFetchHook = (ctx: FetchContext) => Promise<void> | void;
|
|
12
|
+
type AfterFetchHook = (ctx: FetchContext, res: Response) => Promise<"retry" | void> | "retry" | void;
|
|
13
|
+
/**
|
|
14
|
+
* Fetch options for internal API calls
|
|
15
|
+
*/
|
|
16
|
+
type FetchRequestOptions = {
|
|
17
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
body?: Record<string, unknown>;
|
|
20
|
+
callbackUrl?: string;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/types/schemas.d.ts
|
|
24
|
+
declare const userSchema: z.ZodObject<{
|
|
25
|
+
id: z.ZodUUID;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
email: z.ZodEmail;
|
|
28
|
+
emailVerified: z.ZodBoolean;
|
|
29
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
31
|
+
createdAt: z.ZodISODateTime;
|
|
32
|
+
updatedAt: z.ZodISODateTime;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
type User = z.infer<typeof userSchema>;
|
|
35
|
+
declare const accountSchema: z.ZodObject<{
|
|
36
|
+
id: z.ZodUUID;
|
|
37
|
+
userId: z.ZodString;
|
|
38
|
+
accountId: z.ZodString;
|
|
39
|
+
providerId: z.ZodString;
|
|
40
|
+
accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
42
|
+
idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
|
|
44
|
+
refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
|
|
45
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
46
|
+
password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
createdAt: z.ZodISODateTime;
|
|
48
|
+
updatedAt: z.ZodISODateTime;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
type Account = z.infer<typeof accountSchema>;
|
|
51
|
+
declare const sessionSchema: z.ZodObject<{
|
|
52
|
+
id: z.ZodUUID;
|
|
53
|
+
userId: z.ZodString;
|
|
54
|
+
token: z.ZodString;
|
|
55
|
+
expiresAt: z.ZodISODateTime;
|
|
56
|
+
ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
58
|
+
createdAt: z.ZodISODateTime;
|
|
59
|
+
updatedAt: z.ZodISODateTime;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
type Session = z.infer<typeof sessionSchema>;
|
|
62
|
+
declare const verificationTypeSchema: z.ZodEnum<{
|
|
63
|
+
email_verification: "email_verification";
|
|
64
|
+
password_reset_request: "password_reset_request";
|
|
65
|
+
email_reset_request: "email_reset_request";
|
|
66
|
+
}>;
|
|
67
|
+
type VerificationType = z.infer<typeof verificationTypeSchema>;
|
|
68
|
+
declare const verificationSchema: z.ZodObject<{
|
|
69
|
+
id: z.ZodUUID;
|
|
70
|
+
userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
71
|
+
identifier: z.ZodString;
|
|
72
|
+
token: z.ZodString;
|
|
73
|
+
type: z.ZodEnum<{
|
|
74
|
+
email_verification: "email_verification";
|
|
75
|
+
password_reset_request: "password_reset_request";
|
|
76
|
+
email_reset_request: "email_reset_request";
|
|
77
|
+
}>;
|
|
78
|
+
expiresAt: z.ZodISODateTime;
|
|
79
|
+
createdAt: z.ZodISODateTime;
|
|
80
|
+
updatedAt: z.ZodISODateTime;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
type Verification = z.infer<typeof verificationSchema>;
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/types/cookies.d.ts
|
|
85
|
+
type CookieStore = {
|
|
86
|
+
getAll(): {
|
|
87
|
+
name: string;
|
|
88
|
+
value: string;
|
|
89
|
+
}[];
|
|
90
|
+
set(name: string, value: string, options?: Record<string, any>): void;
|
|
91
|
+
delete?(name: string): void;
|
|
92
|
+
};
|
|
93
|
+
type CookieProvider = (() => Promise<CookieStore>) | (() => CookieStore);
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/client.d.ts
|
|
96
|
+
declare class AuthulaClient {
|
|
97
|
+
readonly config: AuthulaClientConfig;
|
|
98
|
+
private readonly plugins;
|
|
99
|
+
private readonly beforeFetchHooks;
|
|
100
|
+
private readonly afterFetchHooks;
|
|
101
|
+
constructor(options: AuthulaClientOptions);
|
|
102
|
+
registerBeforeFetch(hook: BeforeFetchHook): void;
|
|
103
|
+
registerAfterFetch(hook: AfterFetchHook): void;
|
|
104
|
+
runBeforeFetch(ctx: FetchContext): Promise<void>;
|
|
105
|
+
runAfterFetch(ctx: FetchContext, res: Response): Promise<"retry" | undefined>;
|
|
106
|
+
getMe<T = unknown>(): Promise<T>;
|
|
107
|
+
signOut(data: SignOutRequest): Promise<SignOutResponse>;
|
|
108
|
+
getPlugin<T extends Plugin>(id: string): T | undefined;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/types/plugins.d.ts
|
|
112
|
+
interface Plugin {
|
|
113
|
+
readonly id: string;
|
|
114
|
+
init(client: AuthulaClient): any;
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/types/config.d.ts
|
|
118
|
+
type FetchOptions = {
|
|
119
|
+
/**
|
|
120
|
+
* The abort timeout in seconds
|
|
121
|
+
*/
|
|
122
|
+
abortTimeout?: number;
|
|
123
|
+
};
|
|
124
|
+
type AuthulaClientConfig = {
|
|
125
|
+
/**
|
|
126
|
+
* The URL of your Authula server
|
|
127
|
+
* @example 'http://localhost:8080/auth'
|
|
128
|
+
*/
|
|
129
|
+
url: string;
|
|
130
|
+
fetchOptions?: FetchOptions;
|
|
131
|
+
cookies?: CookieProvider;
|
|
132
|
+
};
|
|
133
|
+
type AuthulaClientOptions = AuthulaClientConfig & {
|
|
134
|
+
/**
|
|
135
|
+
* The list of plugins to use
|
|
136
|
+
*/
|
|
137
|
+
plugins: Array<Plugin>;
|
|
138
|
+
};
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/types/methods.d.ts
|
|
141
|
+
type GetMeResponse = {
|
|
142
|
+
user: User;
|
|
143
|
+
session: Session;
|
|
144
|
+
};
|
|
145
|
+
type SignOutRequest = {
|
|
146
|
+
sessionId?: string;
|
|
147
|
+
signOutAll?: boolean;
|
|
148
|
+
};
|
|
149
|
+
type SignOutResponse = {
|
|
150
|
+
message: string;
|
|
151
|
+
};
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/sdk.d.ts
|
|
154
|
+
type InferPluginMethods<P> = P extends {
|
|
155
|
+
init: (client: any) => infer M;
|
|
156
|
+
} ? M : never;
|
|
157
|
+
type ClientWithPlugins<T extends readonly Plugin[]> = AuthulaClient & { [P in T[number] as P["id"]]: InferPluginMethods<P> };
|
|
158
|
+
declare function createClient<const T extends readonly Plugin[]>(options: Omit<AuthulaClientOptions, "plugins"> & {
|
|
159
|
+
plugins: T;
|
|
160
|
+
}): ClientWithPlugins<T>;
|
|
161
|
+
//#endregion
|
|
162
|
+
export { AfterFetchHook as C, FetchRequestOptions as E, verificationTypeSchema as S, FetchContext as T, VerificationType as _, SignOutResponse as a, userSchema as b, FetchOptions as c, CookieProvider as d, CookieStore as f, Verification as g, User as h, SignOutRequest as i, Plugin as l, Session as m, createClient as n, AuthulaClientConfig as o, Account as p, GetMeResponse as r, AuthulaClientOptions as s, ClientWithPlugins as t, AuthulaClient as u, accountSchema as v, BeforeFetchHook as w, verificationSchema as x, sessionSchema as y };
|
|
163
|
+
//# sourceMappingURL=sdk-DV73pbRH.d.cts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "authula",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"description": "Official SDK for Authula.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"homepage": "https://github.com/Authula/authula-node-sdk#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Authula/authula-node-sdk.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Authula/authula-node-sdk/issues"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./plugins": {
|
|
21
|
+
"import": "./dist/plugins/index.js",
|
|
22
|
+
"require": "./dist/plugins/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.cjs",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.cts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsdown",
|
|
34
|
+
"dev": "tsdown --watch",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:watch": "vitest --watch",
|
|
38
|
+
"prepublishOnly": "pnpm run build"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"cookie": "^1.1.1",
|
|
42
|
+
"es-toolkit": "^1.45.1",
|
|
43
|
+
"zod": "^4.3.6"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^25.5.0",
|
|
47
|
+
"bumpp": "^11.0.1",
|
|
48
|
+
"tsdown": "^0.21.4",
|
|
49
|
+
"typescript": "^5.9.3",
|
|
50
|
+
"vitest": "^4.1.0"
|
|
51
|
+
}
|
|
52
|
+
}
|