@axium/core 0.16.0 → 0.17.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/dist/access.d.ts +22 -7
- package/dist/access.js +8 -0
- package/dist/api.d.ts +611 -130
- package/dist/api.js +106 -1
- package/dist/audit.d.ts +26 -18
- package/dist/audit.js +20 -0
- package/dist/auth.d.ts +20 -6
- package/dist/auth.js +13 -0
- package/dist/format.js +1 -1
- package/dist/node/packages.d.ts +8 -0
- package/dist/node/packages.js +51 -0
- package/dist/node/plugins.js +1 -1
- package/dist/packages.d.ts +7 -11
- package/dist/packages.js +6 -51
- package/dist/passkeys.d.ts +64 -20
- package/dist/passkeys.js +85 -3
- package/dist/plugins.d.ts +77 -33
- package/dist/plugins.js +20 -6
- package/dist/user.d.ts +18 -21
- package/dist/user.js +19 -9
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -1 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { AccessControl, AccessMap } from './access.js';
|
|
3
|
+
import { App } from './apps.js';
|
|
4
|
+
import { AuditEvent, AuditFilter, Severity } from './audit.js';
|
|
5
|
+
import { NewSessionResponse, Session, Verification, VerificationInternal } from './auth.js';
|
|
6
|
+
import { PackageVersionInfo } from './packages.js';
|
|
7
|
+
import { Passkey, PasskeyAuthOptions, PasskeyAuthResponse, PasskeyChangeable, PasskeyCreationOptions, PasskeyRegistration, } from './passkeys.js';
|
|
8
|
+
import { PluginInternal } from './plugins.js';
|
|
9
|
+
import { LogoutSessions, User, UserAuthOptions, UserChangeable, UserPublic, UserRegistration, UserRegistrationInit } from './user.js';
|
|
10
|
+
export const AdminSummary = z.object({
|
|
11
|
+
users: z.number(),
|
|
12
|
+
passkeys: z.number(),
|
|
13
|
+
sessions: z.number(),
|
|
14
|
+
auditEvents: z.tuple(Array(Severity.Debug + 1).fill(z.number())),
|
|
15
|
+
configFiles: z.number(),
|
|
16
|
+
plugins: z.number(),
|
|
17
|
+
versions: z.record(z.literal(['core', 'server', 'client']), PackageVersionInfo),
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Schemas for all API endpoints
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
const _API = {
|
|
24
|
+
metadata: {
|
|
25
|
+
GET: z.object({
|
|
26
|
+
versions: PackageVersionInfo.array(),
|
|
27
|
+
routes: z.record(z.string(), z.object({ params: z.record(z.string(), z.string().nullable()), methods: z.string().array() })),
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
apps: {
|
|
31
|
+
GET: App.array(),
|
|
32
|
+
},
|
|
33
|
+
session: {
|
|
34
|
+
GET: z.object({ ...Session.shape, user: User }),
|
|
35
|
+
DELETE: Session,
|
|
36
|
+
},
|
|
37
|
+
register: {
|
|
38
|
+
OPTIONS: [UserRegistrationInit, z.object({ userId: z.uuid(), options: PasskeyCreationOptions })],
|
|
39
|
+
POST: [UserRegistration, NewSessionResponse],
|
|
40
|
+
},
|
|
41
|
+
'users/:id': {
|
|
42
|
+
GET: UserPublic,
|
|
43
|
+
PATCH: [UserChangeable, User],
|
|
44
|
+
DELETE: User,
|
|
45
|
+
},
|
|
46
|
+
'users/:id/full': {
|
|
47
|
+
GET: z.object({ ...User.shape, sessions: Session.array() }),
|
|
48
|
+
},
|
|
49
|
+
'users/:id/auth': {
|
|
50
|
+
OPTIONS: [UserAuthOptions, PasskeyAuthOptions],
|
|
51
|
+
POST: [PasskeyAuthResponse, NewSessionResponse],
|
|
52
|
+
},
|
|
53
|
+
'users/:id/sessions': {
|
|
54
|
+
GET: Session.array(),
|
|
55
|
+
DELETE: [LogoutSessions, Session.array()],
|
|
56
|
+
},
|
|
57
|
+
'users/:id/passkeys': {
|
|
58
|
+
OPTIONS: PasskeyCreationOptions,
|
|
59
|
+
GET: Passkey.array(),
|
|
60
|
+
PUT: [PasskeyRegistration, Passkey],
|
|
61
|
+
},
|
|
62
|
+
'users/:id/verify/email': {
|
|
63
|
+
OPTIONS: z.object({ enabled: z.boolean() }),
|
|
64
|
+
GET: Verification,
|
|
65
|
+
POST: [z.object({ token: z.string() }), z.object({})],
|
|
66
|
+
},
|
|
67
|
+
'users/:id/verify/login': {
|
|
68
|
+
POST: [z.object({ token: z.string() }), NewSessionResponse],
|
|
69
|
+
},
|
|
70
|
+
'passkeys/:id': {
|
|
71
|
+
GET: Passkey,
|
|
72
|
+
PATCH: [PasskeyChangeable, Passkey],
|
|
73
|
+
DELETE: Passkey,
|
|
74
|
+
},
|
|
75
|
+
user_id: {
|
|
76
|
+
POST: [z.object({ using: z.literal(['email', 'handle']), value: z.string() }), z.object({ id: z.uuid() })],
|
|
77
|
+
},
|
|
78
|
+
'acl/:itemType/:itemId': {
|
|
79
|
+
GET: AccessControl.array(),
|
|
80
|
+
POST: [AccessMap, AccessControl.array()],
|
|
81
|
+
},
|
|
82
|
+
'admin/summary': {
|
|
83
|
+
GET: AdminSummary,
|
|
84
|
+
},
|
|
85
|
+
'admin/users': {
|
|
86
|
+
GET: User.array(),
|
|
87
|
+
PUT: [z.object({ name: z.string(), email: z.email() }), z.object({ user: User, verification: VerificationInternal })],
|
|
88
|
+
},
|
|
89
|
+
'admin/config': {
|
|
90
|
+
GET: z.object({
|
|
91
|
+
files: z.record(z.string(), z.any()),
|
|
92
|
+
config: z.record(z.string(), z.unknown()),
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
'admin/plugins': {
|
|
96
|
+
GET: z.object({ ...PluginInternal.omit({ _hooks: true, _client: true }).shape, ...PackageVersionInfo.shape }).array(),
|
|
97
|
+
},
|
|
98
|
+
'admin/audit/events': {
|
|
99
|
+
OPTIONS: z.object({ name: z.string().array(), source: z.string().array(), tags: z.string().array() }).or(z.literal(false)),
|
|
100
|
+
GET: [AuditFilter, AuditEvent.array()],
|
|
101
|
+
},
|
|
102
|
+
'admin/audit/:eventId': {
|
|
103
|
+
GET: AuditEvent,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
export const $API = _API;
|
package/dist/audit.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
import type { User } from './user.js';
|
|
3
2
|
export declare enum Severity {
|
|
4
3
|
Emergency = 0,
|
|
5
4
|
Alert = 1,
|
|
@@ -11,23 +10,32 @@ export declare enum Severity {
|
|
|
11
10
|
Debug = 7
|
|
12
11
|
}
|
|
13
12
|
export declare const severityNames: Lowercase<keyof typeof Severity>[];
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
export declare const AuditEvent: z.ZodObject<{
|
|
14
|
+
id: z.ZodUUID;
|
|
15
|
+
userId: z.ZodNullable<z.ZodUUID>;
|
|
16
|
+
user: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
17
|
+
id: z.ZodNonOptional<z.ZodOptional<z.ZodUUID>>;
|
|
18
|
+
name: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
|
|
19
|
+
email: z.ZodOptional<z.ZodEmail>;
|
|
20
|
+
emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
|
|
21
|
+
image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
22
|
+
preferences: z.ZodOptional<z.ZodLazy<z.ZodObject<{
|
|
23
|
+
debug: z.ZodDefault<z.ZodBoolean>;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
+
registeredAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
28
|
+
isAdmin: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
isSuspended: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
}, z.core.$strip>>>;
|
|
31
|
+
timestamp: z.ZodCoercedDate<unknown>;
|
|
32
|
+
severity: z.ZodEnum<typeof Severity>;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
source: z.ZodString;
|
|
35
|
+
tags: z.ZodArray<z.ZodString>;
|
|
36
|
+
extra: z.ZodRecord<z.ZodAny, z.ZodUnknown>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export interface AuditEvent<T extends Record<string, unknown> = Record<string, unknown>> extends z.infer<typeof AuditEvent> {
|
|
31
39
|
extra: T;
|
|
32
40
|
}
|
|
33
41
|
export declare const AuditFilter: z.ZodObject<{
|
package/dist/audit.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { capitalize, uncapitalize } from 'utilium/string.js';
|
|
2
2
|
import * as z from 'zod';
|
|
3
|
+
import { User } from './user.js';
|
|
3
4
|
export var Severity;
|
|
4
5
|
(function (Severity) {
|
|
5
6
|
Severity[Severity["Emergency"] = 0] = "Emergency";
|
|
@@ -14,6 +15,25 @@ export var Severity;
|
|
|
14
15
|
export const severityNames = Object.keys(Severity)
|
|
15
16
|
.filter(k => isNaN(Number(k)))
|
|
16
17
|
.map(uncapitalize);
|
|
18
|
+
export const AuditEvent = z.object({
|
|
19
|
+
/** UUID of the event */
|
|
20
|
+
id: z.uuid(),
|
|
21
|
+
/** UUID of the user that triggered the event. `null` for events triggered via the server CLI */
|
|
22
|
+
userId: z.uuid().nullable(),
|
|
23
|
+
user: User.partial().required({ id: true, name: true }).nullish(),
|
|
24
|
+
/** When the event happened */
|
|
25
|
+
timestamp: z.coerce.date(),
|
|
26
|
+
/** How severe the event is */
|
|
27
|
+
severity: z.enum(Severity),
|
|
28
|
+
/** Snake case name for the event */
|
|
29
|
+
name: z.string(),
|
|
30
|
+
/** The source of the event. This should be a package name */
|
|
31
|
+
source: z.string(),
|
|
32
|
+
/** Tags for the event. For example, `auth` for authentication events */
|
|
33
|
+
tags: z.string().array(),
|
|
34
|
+
/** Additional event specific data. */
|
|
35
|
+
extra: z.record(z.any(), z.unknown()),
|
|
36
|
+
});
|
|
17
37
|
export const AuditFilter = z.object({
|
|
18
38
|
since: z.coerce.date().optional(),
|
|
19
39
|
until: z.coerce.date().optional(),
|
package/dist/auth.d.ts
CHANGED
|
@@ -8,11 +8,25 @@ export declare const Session: z.ZodObject<{
|
|
|
8
8
|
}, z.core.$strip>;
|
|
9
9
|
export interface Session extends z.infer<typeof Session> {
|
|
10
10
|
}
|
|
11
|
-
export
|
|
12
|
-
userId:
|
|
13
|
-
expires:
|
|
11
|
+
export declare const Verification: z.ZodObject<{
|
|
12
|
+
userId: z.ZodUUID;
|
|
13
|
+
expires: z.ZodCoercedDate<unknown>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export interface Verification extends z.infer<typeof Verification> {
|
|
14
16
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
export declare const VerificationRole: z.ZodLiteral<"email" | "login">;
|
|
18
|
+
export type VerificationRole = z.infer<typeof VerificationRole>;
|
|
19
|
+
export declare const VerificationInternal: z.ZodObject<{
|
|
20
|
+
userId: z.ZodUUID;
|
|
21
|
+
expires: z.ZodCoercedDate<unknown>;
|
|
22
|
+
token: z.ZodString;
|
|
23
|
+
role: z.ZodLiteral<"email" | "login">;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
export interface VerificationInternal extends z.infer<typeof VerificationInternal> {
|
|
26
|
+
}
|
|
27
|
+
export declare const NewSessionResponse: z.ZodObject<{
|
|
28
|
+
userId: z.ZodUUID;
|
|
29
|
+
token: z.ZodString;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export interface NewSessionResponse extends z.infer<typeof NewSessionResponse> {
|
|
18
32
|
}
|
package/dist/auth.js
CHANGED
|
@@ -6,3 +6,16 @@ export const Session = z.object({
|
|
|
6
6
|
created: z.coerce.date(),
|
|
7
7
|
elevated: z.boolean(),
|
|
8
8
|
});
|
|
9
|
+
export const Verification = z.object({
|
|
10
|
+
userId: z.uuid(),
|
|
11
|
+
expires: z.coerce.date(),
|
|
12
|
+
});
|
|
13
|
+
export const VerificationRole = z.literal(['email', 'login']);
|
|
14
|
+
export const VerificationInternal = Verification.extend({
|
|
15
|
+
token: z.string(),
|
|
16
|
+
role: VerificationRole,
|
|
17
|
+
});
|
|
18
|
+
export const NewSessionResponse = z.object({
|
|
19
|
+
userId: z.uuid(),
|
|
20
|
+
token: z.string(),
|
|
21
|
+
});
|
package/dist/format.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function formatDateRange(date) {
|
|
2
2
|
const rawDays = (date.getTime() - Date.now()) / (24 * 3600_000);
|
|
3
3
|
const daysCount = Math.abs(rawDays);
|
|
4
|
-
const daysText =
|
|
4
|
+
const daysText = Math.round(daysCount);
|
|
5
5
|
const plural = daysCount == 1 ? '' : 's';
|
|
6
6
|
return `${date.toLocaleString()} (${rawDays >= 0 ? `in ${daysText} day${plural}` : `${daysText} day${plural} ago`})`;
|
|
7
7
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PackageVersionInfo } from '../packages.js';
|
|
2
|
+
export declare function locatePackage(specifier: string, loadedBy: string): string;
|
|
3
|
+
export declare function setPackageCacheTTL(seconds: number): void;
|
|
4
|
+
/**
|
|
5
|
+
* @param name Package name
|
|
6
|
+
* @param version The current/installed version
|
|
7
|
+
*/
|
|
8
|
+
export declare function getVersionInfo(specifier: string, from?: string): Promise<PackageVersionInfo>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path/posix';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { lt as ltVersion } from 'semver';
|
|
5
|
+
import { warn } from '../io.js';
|
|
6
|
+
function isRelative(specifier) {
|
|
7
|
+
return specifier[0] == '/' || ['.', '..'].includes(specifier.split('/')[0]);
|
|
8
|
+
}
|
|
9
|
+
export function locatePackage(specifier, loadedBy) {
|
|
10
|
+
if (isRelative(specifier)) {
|
|
11
|
+
const path = resolve(dirname(loadedBy), specifier);
|
|
12
|
+
const stats = fs.statSync(path);
|
|
13
|
+
if (stats.isFile())
|
|
14
|
+
return path;
|
|
15
|
+
if (!stats.isDirectory())
|
|
16
|
+
throw new Error('Can not resolve package path: ' + path);
|
|
17
|
+
return join(path, 'package.json');
|
|
18
|
+
}
|
|
19
|
+
let packageDir = dirname(fileURLToPath(import.meta.resolve(specifier)));
|
|
20
|
+
for (; !fs.existsSync(join(packageDir, 'package.json')); packageDir = dirname(packageDir))
|
|
21
|
+
;
|
|
22
|
+
return join(packageDir, 'package.json');
|
|
23
|
+
}
|
|
24
|
+
let cacheTTL = 1000 * 60 * 60;
|
|
25
|
+
export function setPackageCacheTTL(seconds) {
|
|
26
|
+
cacheTTL = seconds * 1000;
|
|
27
|
+
}
|
|
28
|
+
const cache = new Map();
|
|
29
|
+
/**
|
|
30
|
+
* @param name Package name
|
|
31
|
+
* @param version The current/installed version
|
|
32
|
+
*/
|
|
33
|
+
export async function getVersionInfo(specifier, from = import.meta.filename) {
|
|
34
|
+
const path = locatePackage(specifier, from);
|
|
35
|
+
const { version, name } = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
36
|
+
const info = { name, version, latest: null };
|
|
37
|
+
if (isRelative(specifier))
|
|
38
|
+
return info;
|
|
39
|
+
const cached = cache.get(specifier);
|
|
40
|
+
const useCache = cached && Date.now() - cached.timestamp < cacheTTL;
|
|
41
|
+
try {
|
|
42
|
+
const pkg = useCache ? cached.data : await fetch('https://registry.npmjs.org/' + specifier).then(res => res.json());
|
|
43
|
+
if (!useCache)
|
|
44
|
+
cache.set(specifier, { timestamp: Date.now(), data: pkg });
|
|
45
|
+
info.latest = pkg['dist-tags']?.latest || Object.keys(pkg.versions).sort((a, b) => (ltVersion(a, b) ? 1 : -1))[0];
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
warn(`Failed to fetch version info for package ${name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
49
|
+
}
|
|
50
|
+
return info;
|
|
51
|
+
}
|
package/dist/node/plugins.js
CHANGED
|
@@ -5,7 +5,7 @@ import { dirname, resolve } from 'node:path/posix';
|
|
|
5
5
|
import { styleText } from 'node:util';
|
|
6
6
|
import { _throw } from 'utilium';
|
|
7
7
|
import { apps } from '../apps.js';
|
|
8
|
-
import { locatePackage } from '
|
|
8
|
+
import { locatePackage } from './packages.js';
|
|
9
9
|
export function* pluginText(plugin) {
|
|
10
10
|
yield styleText('whiteBright', plugin.name);
|
|
11
11
|
yield `Version: ${plugin.version}`;
|
package/dist/packages.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
name:
|
|
4
|
-
version:
|
|
5
|
-
latest:
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export declare const PackageVersionInfo: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
version: z.ZodString;
|
|
5
|
+
latest: z.ZodNullable<z.ZodString>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export interface PackageVersionInfo extends z.infer<typeof PackageVersionInfo> {
|
|
6
8
|
}
|
|
7
|
-
export declare function setPackageCacheTTL(seconds: number): void;
|
|
8
|
-
/**
|
|
9
|
-
* @param name Package name
|
|
10
|
-
* @param version The current/installed version
|
|
11
|
-
*/
|
|
12
|
-
export declare function getVersionInfo(specifier: string, from?: string): Promise<PackageVersionInfo>;
|
package/dist/packages.js
CHANGED
|
@@ -1,51 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return specifier[0] == '/' || ['.', '..'].includes(specifier.split('/')[0]);
|
|
8
|
-
}
|
|
9
|
-
export function locatePackage(specifier, loadedBy) {
|
|
10
|
-
if (isRelative(specifier)) {
|
|
11
|
-
const path = resolve(dirname(loadedBy), specifier);
|
|
12
|
-
const stats = fs.statSync(path);
|
|
13
|
-
if (stats.isFile())
|
|
14
|
-
return path;
|
|
15
|
-
if (!stats.isDirectory())
|
|
16
|
-
throw new Error('Can not resolve package path: ' + path);
|
|
17
|
-
return join(path, 'package.json');
|
|
18
|
-
}
|
|
19
|
-
let packageDir = dirname(fileURLToPath(import.meta.resolve(specifier)));
|
|
20
|
-
for (; !fs.existsSync(join(packageDir, 'package.json')); packageDir = dirname(packageDir))
|
|
21
|
-
;
|
|
22
|
-
return join(packageDir, 'package.json');
|
|
23
|
-
}
|
|
24
|
-
let cacheTTL = 1000 * 60 * 60;
|
|
25
|
-
export function setPackageCacheTTL(seconds) {
|
|
26
|
-
cacheTTL = seconds * 1000;
|
|
27
|
-
}
|
|
28
|
-
const cache = new Map();
|
|
29
|
-
/**
|
|
30
|
-
* @param name Package name
|
|
31
|
-
* @param version The current/installed version
|
|
32
|
-
*/
|
|
33
|
-
export async function getVersionInfo(specifier, from = import.meta.filename) {
|
|
34
|
-
const path = locatePackage(specifier, from);
|
|
35
|
-
const { version, name } = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
36
|
-
const info = { name, version, latest: null };
|
|
37
|
-
if (isRelative(specifier))
|
|
38
|
-
return info;
|
|
39
|
-
const cached = cache.get(specifier);
|
|
40
|
-
const useCache = cached && Date.now() - cached.timestamp < cacheTTL;
|
|
41
|
-
try {
|
|
42
|
-
const pkg = useCache ? cached.data : await fetch('https://registry.npmjs.org/' + specifier).then(res => res.json());
|
|
43
|
-
if (!useCache)
|
|
44
|
-
cache.set(specifier, { timestamp: Date.now(), data: pkg });
|
|
45
|
-
info.latest = pkg['dist-tags']?.latest || Object.keys(pkg.versions).sort((a, b) => (ltVersion(a, b) ? 1 : -1))[0];
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
warn(`Failed to fetch version info for package ${name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
49
|
-
}
|
|
50
|
-
return info;
|
|
51
|
-
}
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
export const PackageVersionInfo = z.object({
|
|
3
|
+
name: z.string(),
|
|
4
|
+
version: z.string(),
|
|
5
|
+
latest: z.string().nullable(),
|
|
6
|
+
});
|
package/dist/passkeys.d.ts
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
|
-
import type { AuthenticatorTransportFuture } from '@simplewebauthn/server';
|
|
2
|
-
import type { CredentialDeviceType } from '@simplewebauthn/types';
|
|
3
1
|
import * as z from 'zod';
|
|
4
2
|
export declare const authenticatorAttachment: z.ZodOptional<z.ZodLiteral<"cross-platform" | "platform">>;
|
|
3
|
+
/**
|
|
4
|
+
* ak/a/ `PublicKeyCredentialRequestOptionsJSON`
|
|
5
|
+
*/
|
|
6
|
+
export declare const PasskeyAuthOptions: z.ZodObject<{
|
|
7
|
+
challenge: z.ZodBase64URL;
|
|
8
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
rpId: z.ZodOptional<z.ZodString>;
|
|
10
|
+
allowCredentials: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
11
|
+
id: z.ZodBase64URL;
|
|
12
|
+
type: z.ZodLiteral<"public-key">;
|
|
13
|
+
transports: z.ZodOptional<z.ZodArray<z.ZodLiteral<"ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb">>>;
|
|
14
|
+
}, z.core.$strip>>>;
|
|
15
|
+
userVerification: z.ZodOptional<z.ZodLiteral<"required" | "preferred" | "discouraged">>;
|
|
16
|
+
extensions: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
appid: z.ZodOptional<z.ZodString>;
|
|
18
|
+
credProps: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
hmacCreateSecret: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
minPinLength: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
/**
|
|
24
|
+
* a/k/a `PublicKeyCredentialCreationOptionsJSON`
|
|
25
|
+
*/
|
|
26
|
+
export declare const PasskeyCreationOptions: z.ZodObject<{
|
|
27
|
+
rp: z.ZodObject<{
|
|
28
|
+
id: z.ZodOptional<z.ZodString>;
|
|
29
|
+
name: z.ZodString;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
user: z.ZodObject<{
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
displayName: z.ZodString;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
challenge: z.ZodBase64URL;
|
|
37
|
+
pubKeyCredParams: z.ZodArray<z.ZodObject<{
|
|
38
|
+
alg: z.ZodNumber;
|
|
39
|
+
type: z.ZodLiteral<"public-key">;
|
|
40
|
+
}, z.core.$strip>>;
|
|
41
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
excludeCredentials: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
43
|
+
id: z.ZodBase64URL;
|
|
44
|
+
type: z.ZodLiteral<"public-key">;
|
|
45
|
+
transports: z.ZodOptional<z.ZodArray<z.ZodLiteral<"ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb">>>;
|
|
46
|
+
}, z.core.$strip>>>;
|
|
47
|
+
authenticatorSelection: z.ZodOptional<z.ZodObject<{
|
|
48
|
+
authenticatorAttachment: z.ZodOptional<z.ZodOptional<z.ZodLiteral<"cross-platform" | "platform">>>;
|
|
49
|
+
requireResidentKey: z.ZodOptional<z.ZodBoolean>;
|
|
50
|
+
residentKey: z.ZodOptional<z.ZodLiteral<"required" | "preferred" | "discouraged">>;
|
|
51
|
+
userVerification: z.ZodOptional<z.ZodLiteral<"required" | "preferred" | "discouraged">>;
|
|
52
|
+
}, z.core.$strip>>;
|
|
53
|
+
attestation: z.ZodOptional<z.ZodLiteral<"none" | "indirect" | "direct" | "enterprise">>;
|
|
54
|
+
}, z.core.$strip>;
|
|
5
55
|
export declare const PasskeyRegistration: z.ZodObject<{
|
|
6
56
|
id: z.ZodString;
|
|
7
57
|
rawId: z.ZodString;
|
|
@@ -9,15 +59,7 @@ export declare const PasskeyRegistration: z.ZodObject<{
|
|
|
9
59
|
clientDataJSON: z.ZodString;
|
|
10
60
|
attestationObject: z.ZodString;
|
|
11
61
|
authenticatorData: z.ZodOptional<z.ZodString>;
|
|
12
|
-
transports: z.ZodOptional<z.ZodArray<z.
|
|
13
|
-
ble: "ble";
|
|
14
|
-
cable: "cable";
|
|
15
|
-
hybrid: "hybrid";
|
|
16
|
-
internal: "internal";
|
|
17
|
-
nfc: "nfc";
|
|
18
|
-
"smart-card": "smart-card";
|
|
19
|
-
usb: "usb";
|
|
20
|
-
}>>>;
|
|
62
|
+
transports: z.ZodOptional<z.ZodArray<z.ZodLiteral<"ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb">>>;
|
|
21
63
|
publicKeyAlgorithm: z.ZodOptional<z.ZodNumber>;
|
|
22
64
|
publicKey: z.ZodOptional<z.ZodString>;
|
|
23
65
|
}, z.core.$strip>;
|
|
@@ -28,7 +70,7 @@ export declare const PasskeyRegistration: z.ZodObject<{
|
|
|
28
70
|
/**
|
|
29
71
|
* POSTed to the `/users/:id/login` endpoint.
|
|
30
72
|
*/
|
|
31
|
-
export declare const
|
|
73
|
+
export declare const PasskeyAuthResponse: z.ZodObject<{
|
|
32
74
|
id: z.ZodString;
|
|
33
75
|
rawId: z.ZodString;
|
|
34
76
|
response: z.ZodObject<{
|
|
@@ -44,12 +86,14 @@ export declare const PasskeyAuthenticationResponse: z.ZodObject<{
|
|
|
44
86
|
export declare const PasskeyChangeable: z.ZodObject<{
|
|
45
87
|
name: z.ZodOptional<z.ZodString>;
|
|
46
88
|
}, z.core.$strip>;
|
|
47
|
-
export
|
|
48
|
-
id:
|
|
49
|
-
name
|
|
50
|
-
createdAt:
|
|
51
|
-
userId:
|
|
52
|
-
deviceType:
|
|
53
|
-
backedUp:
|
|
54
|
-
transports:
|
|
89
|
+
export declare const Passkey: z.ZodObject<{
|
|
90
|
+
id: z.ZodString;
|
|
91
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
92
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
93
|
+
userId: z.ZodUUID;
|
|
94
|
+
deviceType: z.ZodLiteral<"singleDevice" | "multiDevice">;
|
|
95
|
+
backedUp: z.ZodBoolean;
|
|
96
|
+
transports: z.ZodArray<z.ZodLiteral<"ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb">>;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
export interface Passkey extends z.infer<typeof Passkey> {
|
|
55
99
|
}
|
package/dist/passkeys.js
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
const
|
|
2
|
+
const PasskeyTransport = z.literal([
|
|
3
|
+
'ble',
|
|
4
|
+
'cable',
|
|
5
|
+
'hybrid',
|
|
6
|
+
'internal',
|
|
7
|
+
'nfc',
|
|
8
|
+
'smart-card',
|
|
9
|
+
'usb',
|
|
10
|
+
]);
|
|
3
11
|
export const authenticatorAttachment = z.literal(['platform', 'cross-platform']).optional();
|
|
12
|
+
const PublicKeyCredentialType = z.literal(['public-key']);
|
|
13
|
+
/**
|
|
14
|
+
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson
|
|
15
|
+
*/
|
|
16
|
+
const PublicKeyCredentialUserEntity = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
name: z.string(),
|
|
19
|
+
displayName: z.string(),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson
|
|
23
|
+
*/
|
|
24
|
+
const PublicKeyCredentialDescriptor = z.object({
|
|
25
|
+
id: z.base64url(),
|
|
26
|
+
type: PublicKeyCredentialType,
|
|
27
|
+
transports: PasskeyTransport.array().optional(),
|
|
28
|
+
});
|
|
29
|
+
const UserVerificationRequirement = z.literal(['required', 'preferred', 'discouraged']);
|
|
30
|
+
const AuthenticationExtensionsClientInputs = z.object({
|
|
31
|
+
appid: z.string().optional(),
|
|
32
|
+
credProps: z.boolean().optional(),
|
|
33
|
+
hmacCreateSecret: z.boolean().optional(),
|
|
34
|
+
minPinLength: z.boolean().optional(),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* ak/a/ `PublicKeyCredentialRequestOptionsJSON`
|
|
38
|
+
*/
|
|
39
|
+
export const PasskeyAuthOptions = z.object({
|
|
40
|
+
challenge: z.base64url(),
|
|
41
|
+
timeout: z.number().optional(),
|
|
42
|
+
rpId: z.string().optional(),
|
|
43
|
+
allowCredentials: PublicKeyCredentialDescriptor.array().optional(),
|
|
44
|
+
userVerification: UserVerificationRequirement.optional(),
|
|
45
|
+
extensions: AuthenticationExtensionsClientInputs.optional(),
|
|
46
|
+
});
|
|
47
|
+
const PublicKeyCredentialRpEntity = z.object({
|
|
48
|
+
id: z.string().optional(),
|
|
49
|
+
name: z.string(),
|
|
50
|
+
});
|
|
51
|
+
const COSEAlgorithmIdentifier = z.number();
|
|
52
|
+
const PublicKeyCredentialParameters = z.object({
|
|
53
|
+
alg: COSEAlgorithmIdentifier,
|
|
54
|
+
type: PublicKeyCredentialType,
|
|
55
|
+
});
|
|
56
|
+
const ResidentKeyRequirement = z.literal(['required', 'preferred', 'discouraged']);
|
|
57
|
+
const AuthenticatorSelectionCriteria = z.object({
|
|
58
|
+
authenticatorAttachment: authenticatorAttachment.optional(),
|
|
59
|
+
requireResidentKey: z.boolean().optional(),
|
|
60
|
+
residentKey: ResidentKeyRequirement.optional(),
|
|
61
|
+
userVerification: UserVerificationRequirement.optional(),
|
|
62
|
+
});
|
|
63
|
+
const AttestationConveyancePreference = z.literal(['none', 'indirect', 'direct', 'enterprise']);
|
|
64
|
+
/**
|
|
65
|
+
* a/k/a `PublicKeyCredentialCreationOptionsJSON`
|
|
66
|
+
*/
|
|
67
|
+
export const PasskeyCreationOptions = z.object({
|
|
68
|
+
rp: PublicKeyCredentialRpEntity,
|
|
69
|
+
user: PublicKeyCredentialUserEntity,
|
|
70
|
+
challenge: z.base64url(),
|
|
71
|
+
pubKeyCredParams: PublicKeyCredentialParameters.array(),
|
|
72
|
+
timeout: z.number().optional(),
|
|
73
|
+
excludeCredentials: PublicKeyCredentialDescriptor.array().optional(),
|
|
74
|
+
authenticatorSelection: AuthenticatorSelectionCriteria.optional(),
|
|
75
|
+
attestation: AttestationConveyancePreference.optional(),
|
|
76
|
+
});
|
|
4
77
|
export const PasskeyRegistration = z.object({
|
|
5
78
|
id: z.string(),
|
|
6
79
|
rawId: z.string(),
|
|
@@ -8,7 +81,7 @@ export const PasskeyRegistration = z.object({
|
|
|
8
81
|
clientDataJSON: z.string(),
|
|
9
82
|
attestationObject: z.string(),
|
|
10
83
|
authenticatorData: z.string().optional(),
|
|
11
|
-
transports:
|
|
84
|
+
transports: PasskeyTransport.array().optional(),
|
|
12
85
|
publicKeyAlgorithm: z.number().optional(),
|
|
13
86
|
publicKey: z.string().optional(),
|
|
14
87
|
}),
|
|
@@ -19,7 +92,7 @@ export const PasskeyRegistration = z.object({
|
|
|
19
92
|
/**
|
|
20
93
|
* POSTed to the `/users/:id/login` endpoint.
|
|
21
94
|
*/
|
|
22
|
-
export const
|
|
95
|
+
export const PasskeyAuthResponse = z.object({
|
|
23
96
|
id: z.string(),
|
|
24
97
|
rawId: z.string(),
|
|
25
98
|
response: z.object({
|
|
@@ -33,3 +106,12 @@ export const PasskeyAuthenticationResponse = z.object({
|
|
|
33
106
|
type: z.literal('public-key'),
|
|
34
107
|
});
|
|
35
108
|
export const PasskeyChangeable = z.object({ name: z.string() }).partial();
|
|
109
|
+
export const Passkey = z.object({
|
|
110
|
+
id: z.string(),
|
|
111
|
+
name: z.string().nullish(),
|
|
112
|
+
createdAt: z.coerce.date(),
|
|
113
|
+
userId: z.uuid(),
|
|
114
|
+
deviceType: z.literal(['singleDevice', 'multiDevice']),
|
|
115
|
+
backedUp: z.boolean(),
|
|
116
|
+
transports: z.literal(['ble', 'cable', 'hybrid', 'internal', 'nfc', 'smart-card', 'usb']).array(),
|
|
117
|
+
});
|