@axium/core 0.2.0 → 0.4.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 +6 -2
- package/dist/format.d.ts +7 -0
- package/dist/format.js +17 -0
- package/dist/schemas.d.ts +5 -1
- package/dist/schemas.js +4 -0
- package/dist/user.d.ts +8 -4
- package/dist/user.js +6 -2
- package/package.json +5 -3
package/dist/api.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { AuthenticatorTransportFuture, CredentialDeviceType, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';
|
|
2
2
|
import type z from 'zod/v4';
|
|
3
3
|
import type { RequestMethod } from './requests.js';
|
|
4
|
-
import type { APIUserRegistration, PasskeyAuthenticationResponse, PasskeyChangeable, PasskeyRegistration, UserAuthOptions } from './schemas.js';
|
|
4
|
+
import type { APIUserRegistration, LogoutSessions, PasskeyAuthenticationResponse, PasskeyChangeable, PasskeyRegistration, UserAuthOptions } from './schemas.js';
|
|
5
5
|
import type { User, UserChangeable, UserPublic } from './user.js';
|
|
6
6
|
export interface Session {
|
|
7
7
|
id: string;
|
|
8
8
|
userId: string;
|
|
9
9
|
expires: Date;
|
|
10
10
|
created: Date;
|
|
11
|
+
elevated: boolean;
|
|
11
12
|
}
|
|
12
13
|
export interface Verification {
|
|
13
14
|
userId: string;
|
|
@@ -70,7 +71,7 @@ export interface _apiTypes {
|
|
|
70
71
|
};
|
|
71
72
|
'users/:id/sessions': {
|
|
72
73
|
GET: Session[];
|
|
73
|
-
DELETE: [
|
|
74
|
+
DELETE: [z.input<typeof LogoutSessions>, Session[]];
|
|
74
75
|
};
|
|
75
76
|
'users/:id/passkeys': {
|
|
76
77
|
OPTIONS: PublicKeyCredentialCreationOptionsJSON;
|
|
@@ -78,6 +79,9 @@ export interface _apiTypes {
|
|
|
78
79
|
PUT: [z.input<typeof PasskeyRegistration>, Passkey];
|
|
79
80
|
};
|
|
80
81
|
'users/:id/verify_email': {
|
|
82
|
+
OPTIONS: {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
};
|
|
81
85
|
GET: Verification;
|
|
82
86
|
POST: [{
|
|
83
87
|
token: string;
|
package/dist/format.d.ts
ADDED
package/dist/format.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function formatDateRange(date) {
|
|
2
|
+
const rawDays = (date.getTime() - Date.now()) / (24 * 3600_000);
|
|
3
|
+
const daysCount = Math.abs(rawDays);
|
|
4
|
+
const daysText = Number.isInteger(daysCount) ? daysCount : daysCount.toFixed(1);
|
|
5
|
+
const plural = daysCount == 1 ? '' : 's';
|
|
6
|
+
return `${date.toLocaleString()} (${rawDays >= 0 ? `in ${daysText} day${plural}` : `${daysText} day${plural} ago`})`;
|
|
7
|
+
}
|
|
8
|
+
export function formatBytes(bytes) {
|
|
9
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
10
|
+
const i = bytes == 0 ? 0 : Math.floor(Math.log10(bytes) / 3);
|
|
11
|
+
const value = bytes == 0 ? 0 : bytes / Math.pow(1000, i);
|
|
12
|
+
return `${Number.isInteger(value) ? value : value.toFixed(2)} ${units[i]}`;
|
|
13
|
+
}
|
|
14
|
+
export default {
|
|
15
|
+
dateRange: formatDateRange,
|
|
16
|
+
bytes: formatBytes,
|
|
17
|
+
};
|
package/dist/schemas.d.ts
CHANGED
|
@@ -73,6 +73,10 @@ export declare const PasskeyChangeable: z.ZodObject<{
|
|
|
73
73
|
name: z.ZodOptional<z.ZodString>;
|
|
74
74
|
}, z.core.$strip>;
|
|
75
75
|
export declare const UserAuthOptions: z.ZodObject<{
|
|
76
|
-
type: z.ZodLiteral<"
|
|
76
|
+
type: z.ZodLiteral<"login" | "action">;
|
|
77
77
|
}, z.core.$strip>;
|
|
78
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
|
@@ -46,3 +46,7 @@ export const APIUserRegistration = z.object({
|
|
|
46
46
|
});
|
|
47
47
|
export const PasskeyChangeable = z.object({ name: z.string() }).partial();
|
|
48
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(),
|
|
52
|
+
});
|
package/dist/user.d.ts
CHANGED
|
@@ -11,19 +11,23 @@ export declare const User: z.ZodObject<{
|
|
|
11
11
|
email: z.ZodEmail;
|
|
12
12
|
emailVerified: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
13
13
|
image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
|
|
14
|
+
preferences: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
15
|
+
roles: z.ZodArray<z.ZodString>;
|
|
16
|
+
registeredAt: z.ZodDate;
|
|
14
17
|
}, z.core.$strip>;
|
|
15
18
|
export interface User extends z.infer<typeof User> {
|
|
16
|
-
preferences
|
|
19
|
+
preferences: Preferences;
|
|
17
20
|
}
|
|
18
|
-
export declare const userPublicFields: ["id", "image", "name"];
|
|
21
|
+
export declare const userPublicFields: ["id", "image", "name", "registeredAt"];
|
|
19
22
|
type UserPublicField = (typeof userPublicFields)[number];
|
|
20
23
|
export interface UserPublic extends Pick<User, UserPublicField> {
|
|
21
24
|
}
|
|
22
|
-
export declare const userProtectedFields: ["email", "emailVerified", "preferences"];
|
|
25
|
+
export declare const userProtectedFields: ["email", "emailVerified", "preferences", "roles"];
|
|
23
26
|
export declare const UserChangeable: z.ZodObject<{
|
|
27
|
+
email: z.ZodOptional<z.ZodEmail>;
|
|
24
28
|
name: z.ZodOptional<z.ZodString>;
|
|
25
29
|
image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
26
|
-
|
|
30
|
+
preferences: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
27
31
|
}, z.core.$strip>;
|
|
28
32
|
export type UserChangeable = z.infer<typeof UserChangeable>;
|
|
29
33
|
export declare function getUserImage(user: {
|
package/dist/user.js
CHANGED
|
@@ -5,13 +5,17 @@ export const User = z.object({
|
|
|
5
5
|
email: z.email(),
|
|
6
6
|
emailVerified: z.date().nullable().optional(),
|
|
7
7
|
image: z.url().nullable().optional(),
|
|
8
|
+
preferences: z.record(z.string(), z.any()),
|
|
9
|
+
roles: z.array(z.string()),
|
|
10
|
+
registeredAt: z.date(),
|
|
8
11
|
});
|
|
9
|
-
export const userPublicFields = ['id', 'image', 'name'];
|
|
10
|
-
export const userProtectedFields = ['email', 'emailVerified', 'preferences'];
|
|
12
|
+
export const userPublicFields = ['id', 'image', 'name', 'registeredAt'];
|
|
13
|
+
export const userProtectedFields = ['email', 'emailVerified', 'preferences', 'roles'];
|
|
11
14
|
export const UserChangeable = User.pick({
|
|
12
15
|
name: true,
|
|
13
16
|
email: true,
|
|
14
17
|
image: true,
|
|
18
|
+
preferences: true,
|
|
15
19
|
}).partial();
|
|
16
20
|
export function getUserImage(user) {
|
|
17
21
|
if (user.image)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -27,8 +27,10 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsc"
|
|
29
29
|
},
|
|
30
|
-
"
|
|
31
|
-
"@simplewebauthn/types": "^12.0.0",
|
|
30
|
+
"peerDependencies": {
|
|
32
31
|
"zod": "^3.25.61"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@simplewebauthn/types": "^12.0.0"
|
|
33
35
|
}
|
|
34
36
|
}
|