@axium/core 0.1.1 → 0.3.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/dist/api.d.ts +108 -0
- package/dist/api.js +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/requests.d.ts +2 -0
- package/dist/requests.js +1 -0
- package/dist/schemas.d.ts +80 -42
- package/dist/schemas.js +51 -13
- package/dist/user.d.ts +29 -0
- package/dist/user.js +15 -0
- package/package.json +6 -3
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { AuthenticatorTransportFuture, CredentialDeviceType, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';
|
|
2
|
+
import type z from 'zod/v4';
|
|
3
|
+
import type { RequestMethod } from './requests.js';
|
|
4
|
+
import type { APIUserRegistration, LogoutSessions, PasskeyAuthenticationResponse, PasskeyChangeable, PasskeyRegistration, UserAuthOptions } from './schemas.js';
|
|
5
|
+
import type { User, UserChangeable, UserPublic } from './user.js';
|
|
6
|
+
export interface Session {
|
|
7
|
+
id: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
expires: Date;
|
|
10
|
+
created: Date;
|
|
11
|
+
elevated: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface Verification {
|
|
14
|
+
userId: string;
|
|
15
|
+
expires: Date;
|
|
16
|
+
}
|
|
17
|
+
export interface Passkey {
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string | null;
|
|
20
|
+
createdAt: Date;
|
|
21
|
+
userId: string;
|
|
22
|
+
deviceType: CredentialDeviceType;
|
|
23
|
+
backedUp: boolean;
|
|
24
|
+
transports: AuthenticatorTransportFuture[];
|
|
25
|
+
}
|
|
26
|
+
export interface NewSessionResponse {
|
|
27
|
+
userId: string;
|
|
28
|
+
token: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Types for all API endpoints
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export interface _apiTypes {
|
|
35
|
+
metadata: {
|
|
36
|
+
GET: {
|
|
37
|
+
version: string;
|
|
38
|
+
routes: Record<string, {
|
|
39
|
+
params: Record<string, string | null>;
|
|
40
|
+
methods: string[];
|
|
41
|
+
}>;
|
|
42
|
+
plugins: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
session: {
|
|
46
|
+
GET: Session & {
|
|
47
|
+
user: User;
|
|
48
|
+
};
|
|
49
|
+
DELETE: Session;
|
|
50
|
+
};
|
|
51
|
+
register: {
|
|
52
|
+
OPTIONS: {
|
|
53
|
+
userId: string;
|
|
54
|
+
options: PublicKeyCredentialCreationOptionsJSON;
|
|
55
|
+
};
|
|
56
|
+
POST: [z.input<typeof APIUserRegistration>, NewSessionResponse];
|
|
57
|
+
};
|
|
58
|
+
'users/:id': {
|
|
59
|
+
GET: UserPublic & Partial<User>;
|
|
60
|
+
PATCH: [z.input<typeof UserChangeable>, User];
|
|
61
|
+
DELETE: User;
|
|
62
|
+
};
|
|
63
|
+
'users/:id/full': {
|
|
64
|
+
GET: User & {
|
|
65
|
+
sessions: Session[];
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
'users/:id/auth': {
|
|
69
|
+
OPTIONS: [z.input<typeof UserAuthOptions>, PublicKeyCredentialRequestOptionsJSON];
|
|
70
|
+
POST: [z.input<typeof PasskeyAuthenticationResponse>, NewSessionResponse];
|
|
71
|
+
};
|
|
72
|
+
'users/:id/sessions': {
|
|
73
|
+
GET: Session[];
|
|
74
|
+
DELETE: [z.input<typeof LogoutSessions>, Session[]];
|
|
75
|
+
};
|
|
76
|
+
'users/:id/passkeys': {
|
|
77
|
+
OPTIONS: PublicKeyCredentialCreationOptionsJSON;
|
|
78
|
+
GET: Passkey[];
|
|
79
|
+
PUT: [z.input<typeof PasskeyRegistration>, Passkey];
|
|
80
|
+
};
|
|
81
|
+
'users/:id/verify_email': {
|
|
82
|
+
OPTIONS: {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
};
|
|
85
|
+
GET: Verification;
|
|
86
|
+
POST: [{
|
|
87
|
+
token: string;
|
|
88
|
+
}, {}];
|
|
89
|
+
};
|
|
90
|
+
'passkeys/:id': {
|
|
91
|
+
GET: Passkey;
|
|
92
|
+
PATCH: [z.input<typeof PasskeyChangeable>, Passkey];
|
|
93
|
+
DELETE: Passkey;
|
|
94
|
+
};
|
|
95
|
+
user_id: {
|
|
96
|
+
POST: [{
|
|
97
|
+
using: 'email' | 'handle';
|
|
98
|
+
value: string;
|
|
99
|
+
}, {
|
|
100
|
+
id: string;
|
|
101
|
+
}];
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export type Endpoint = keyof _apiTypes;
|
|
105
|
+
export type APIFunction<Method extends RequestMethod, E extends Endpoint> = Method extends keyof _apiTypes[E] ? _apiTypes[E][Method] extends [infer Body, infer Result] ? (body: Body) => Promise<Result> : () => _apiTypes[E][Method] : unknown;
|
|
106
|
+
export type RequestBody<Method extends RequestMethod, E extends Endpoint> = Method extends keyof _apiTypes[E] ? _apiTypes[E][Method] extends [infer Body, unknown] ? Body : any : unknown;
|
|
107
|
+
export type Result<Method extends RequestMethod, E extends Endpoint> = Promise<Method extends keyof _apiTypes[E] ? (_apiTypes[E][Method] extends [unknown, infer R] ? R : _apiTypes[E][Method]) : unknown>;
|
|
108
|
+
export type APIParameters<S extends string> = S extends `${string}/:${infer Right}` ? [string, ...APIParameters<Right>] : [];
|
package/dist/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/requests.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const requestMethods = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH'];
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,44 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare
|
|
1
|
+
import z from 'zod/v4';
|
|
2
|
+
export declare function zFunction<T extends z.core.$ZodFunction>(schema: T): z.ZodCustom<Parameters<T["implement"]>[0], Parameters<T["implement"]>[0]>;
|
|
3
|
+
export declare function zAsyncFunction<T extends z.core.$ZodFunction>(schema: T): z.ZodCustom<Parameters<T["implementAsync"]>[0], Parameters<T["implementAsync"]>[0]>;
|
|
4
|
+
export declare const authenticatorAttachment: z.ZodOptional<z.ZodLiteral<"cross-platform" | "platform">>;
|
|
5
|
+
export declare const PasskeyRegistration: z.ZodObject<{
|
|
3
6
|
id: z.ZodString;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
rawId: z.ZodString;
|
|
8
|
+
response: z.ZodObject<{
|
|
9
|
+
clientDataJSON: z.ZodString;
|
|
10
|
+
attestationObject: z.ZodString;
|
|
11
|
+
authenticatorData: z.ZodOptional<z.ZodString>;
|
|
12
|
+
transports: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
13
|
+
ble: "ble";
|
|
14
|
+
hybrid: "hybrid";
|
|
15
|
+
internal: "internal";
|
|
16
|
+
nfc: "nfc";
|
|
17
|
+
usb: "usb";
|
|
18
|
+
cable: "cable";
|
|
19
|
+
"smart-card": "smart-card";
|
|
20
|
+
}>>>;
|
|
21
|
+
publicKeyAlgorithm: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
publicKey: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
authenticatorAttachment: z.ZodOptional<z.ZodLiteral<"cross-platform" | "platform">>;
|
|
25
|
+
clientExtensionResults: z.ZodRecord<z.ZodAny, z.ZodAny>;
|
|
26
|
+
type: z.ZodLiteral<"public-key">;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
/**
|
|
29
|
+
* POSTed to the `/users/:id/login` endpoint.
|
|
30
|
+
*/
|
|
31
|
+
export declare const PasskeyAuthenticationResponse: z.ZodObject<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
rawId: z.ZodString;
|
|
34
|
+
response: z.ZodObject<{
|
|
35
|
+
clientDataJSON: z.ZodString;
|
|
36
|
+
authenticatorData: z.ZodString;
|
|
37
|
+
signature: z.ZodString;
|
|
38
|
+
userHandle: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
authenticatorAttachment: z.ZodOptional<z.ZodLiteral<"cross-platform" | "platform">>;
|
|
41
|
+
clientExtensionResults: z.ZodRecord<z.ZodAny, z.ZodAny>;
|
|
42
|
+
type: z.ZodLiteral<"public-key">;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export declare const APIUserRegistration: z.ZodObject<{
|
|
34
45
|
name: z.ZodString;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
email: z.ZodEmail;
|
|
47
|
+
userId: z.ZodUUID;
|
|
48
|
+
response: z.ZodObject<{
|
|
49
|
+
id: z.ZodString;
|
|
50
|
+
rawId: z.ZodString;
|
|
51
|
+
response: z.ZodObject<{
|
|
52
|
+
clientDataJSON: z.ZodString;
|
|
53
|
+
attestationObject: z.ZodString;
|
|
54
|
+
authenticatorData: z.ZodOptional<z.ZodString>;
|
|
55
|
+
transports: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
56
|
+
ble: "ble";
|
|
57
|
+
hybrid: "hybrid";
|
|
58
|
+
internal: "internal";
|
|
59
|
+
nfc: "nfc";
|
|
60
|
+
usb: "usb";
|
|
61
|
+
cable: "cable";
|
|
62
|
+
"smart-card": "smart-card";
|
|
63
|
+
}>>>;
|
|
64
|
+
publicKeyAlgorithm: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
publicKey: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
authenticatorAttachment: z.ZodOptional<z.ZodLiteral<"cross-platform" | "platform">>;
|
|
68
|
+
clientExtensionResults: z.ZodRecord<z.ZodAny, z.ZodAny>;
|
|
69
|
+
type: z.ZodLiteral<"public-key">;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export declare const PasskeyChangeable: z.ZodObject<{
|
|
73
|
+
name: z.ZodOptional<z.ZodString>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export declare const UserAuthOptions: z.ZodObject<{
|
|
76
|
+
type: z.ZodLiteral<"login" | "action">;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
export type UserAuthOptions = z.infer<typeof UserAuthOptions>;
|
|
79
|
+
export declare const LogoutSessions: z.ZodObject<{
|
|
80
|
+
id: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
81
|
+
confirm_all: z.ZodOptional<z.ZodBoolean>;
|
|
82
|
+
}, z.core.$strip>;
|
package/dist/schemas.js
CHANGED
|
@@ -1,14 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import z from 'zod/v4';
|
|
2
|
+
export function zFunction(schema) {
|
|
3
|
+
return z.custom((fn) => schema.implement(fn));
|
|
4
|
+
}
|
|
5
|
+
export function zAsyncFunction(schema) {
|
|
6
|
+
return z.custom((fn) => schema.implementAsync(fn));
|
|
7
|
+
}
|
|
8
|
+
const transports = ['ble', 'cable', 'hybrid', 'internal', 'nfc', 'smart-card', 'usb'];
|
|
9
|
+
export const authenticatorAttachment = z.literal(['platform', 'cross-platform']).optional();
|
|
10
|
+
export const PasskeyRegistration = z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
rawId: z.string(),
|
|
13
|
+
response: z.object({
|
|
14
|
+
clientDataJSON: z.string(),
|
|
15
|
+
attestationObject: z.string(),
|
|
16
|
+
authenticatorData: z.string().optional(),
|
|
17
|
+
transports: z.array(z.enum(transports)).optional(),
|
|
18
|
+
publicKeyAlgorithm: z.number().optional(),
|
|
19
|
+
publicKey: z.string().optional(),
|
|
20
|
+
}),
|
|
21
|
+
authenticatorAttachment,
|
|
22
|
+
clientExtensionResults: z.record(z.any(), z.any()),
|
|
23
|
+
type: z.literal('public-key'),
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* POSTed to the `/users/:id/login` endpoint.
|
|
27
|
+
*/
|
|
28
|
+
export const PasskeyAuthenticationResponse = z.object({
|
|
29
|
+
id: z.string(),
|
|
30
|
+
rawId: z.string(),
|
|
31
|
+
response: z.object({
|
|
32
|
+
clientDataJSON: z.string(),
|
|
33
|
+
authenticatorData: z.string(),
|
|
34
|
+
signature: z.string(),
|
|
35
|
+
userHandle: z.string().optional(),
|
|
36
|
+
}),
|
|
37
|
+
authenticatorAttachment,
|
|
38
|
+
clientExtensionResults: z.record(z.any(), z.any()),
|
|
39
|
+
type: z.literal('public-key'),
|
|
40
|
+
});
|
|
41
|
+
export const APIUserRegistration = z.object({
|
|
42
|
+
name: z.string().min(1).max(100),
|
|
43
|
+
email: z.email(),
|
|
44
|
+
userId: z.uuid(),
|
|
45
|
+
response: PasskeyRegistration,
|
|
46
|
+
});
|
|
47
|
+
export const PasskeyChangeable = z.object({ name: z.string() }).partial();
|
|
48
|
+
export const UserAuthOptions = z.object({ type: z.literal(['login', 'action']) });
|
|
49
|
+
export const LogoutSessions = z.object({
|
|
50
|
+
id: z.array(z.uuid()).optional(),
|
|
51
|
+
confirm_all: z.boolean().optional(),
|
|
14
52
|
});
|
package/dist/user.d.ts
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
|
+
import z from 'zod/v4';
|
|
2
|
+
/**
|
|
3
|
+
* User preferences.
|
|
4
|
+
* Modify with `declare module ...`
|
|
5
|
+
*/
|
|
6
|
+
export interface Preferences {
|
|
7
|
+
}
|
|
8
|
+
export declare const User: z.ZodObject<{
|
|
9
|
+
id: z.ZodUUID;
|
|
10
|
+
name: z.ZodString;
|
|
11
|
+
email: z.ZodEmail;
|
|
12
|
+
emailVerified: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
13
|
+
image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export interface User extends z.infer<typeof User> {
|
|
16
|
+
preferences?: Preferences;
|
|
17
|
+
}
|
|
18
|
+
export declare const userPublicFields: ["id", "image", "name"];
|
|
19
|
+
type UserPublicField = (typeof userPublicFields)[number];
|
|
20
|
+
export interface UserPublic extends Pick<User, UserPublicField> {
|
|
21
|
+
}
|
|
22
|
+
export declare const userProtectedFields: ["email", "emailVerified", "preferences"];
|
|
23
|
+
export declare const UserChangeable: z.ZodObject<{
|
|
24
|
+
email: z.ZodOptional<z.ZodEmail>;
|
|
25
|
+
name: z.ZodOptional<z.ZodString>;
|
|
26
|
+
image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type UserChangeable = z.infer<typeof UserChangeable>;
|
|
1
29
|
export declare function getUserImage(user: {
|
|
2
30
|
name?: string;
|
|
3
31
|
image?: string;
|
|
4
32
|
}): string;
|
|
33
|
+
export {};
|
package/dist/user.js
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
import z from 'zod/v4';
|
|
2
|
+
export const User = z.object({
|
|
3
|
+
id: z.uuid(),
|
|
4
|
+
name: z.string().min(1, 'Name is required').max(255, 'Name is too long'),
|
|
5
|
+
email: z.email(),
|
|
6
|
+
emailVerified: z.date().nullable().optional(),
|
|
7
|
+
image: z.url().nullable().optional(),
|
|
8
|
+
});
|
|
9
|
+
export const userPublicFields = ['id', 'image', 'name'];
|
|
10
|
+
export const userProtectedFields = ['email', 'emailVerified', 'preferences'];
|
|
11
|
+
export const UserChangeable = User.pick({
|
|
12
|
+
name: true,
|
|
13
|
+
email: true,
|
|
14
|
+
image: true,
|
|
15
|
+
}).partial();
|
|
1
16
|
export function getUserImage(user) {
|
|
2
17
|
if (user.image)
|
|
3
18
|
return user.image;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
20
|
"exports": {
|
|
21
21
|
".": "./dist/index.js",
|
|
22
|
-
"
|
|
22
|
+
"./*": "./dist/*.js"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist"
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsc"
|
|
29
29
|
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"zod": "^3.25.61"
|
|
32
|
+
},
|
|
30
33
|
"dependencies": {
|
|
31
|
-
"
|
|
34
|
+
"@simplewebauthn/types": "^12.0.0"
|
|
32
35
|
}
|
|
33
36
|
}
|