@axium/core 0.1.0 → 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/dist/api.d.ts ADDED
@@ -0,0 +1,104 @@
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, 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
+ }
12
+ export interface Verification {
13
+ userId: string;
14
+ expires: Date;
15
+ }
16
+ export interface Passkey {
17
+ id: string;
18
+ name?: string | null;
19
+ createdAt: Date;
20
+ userId: string;
21
+ deviceType: CredentialDeviceType;
22
+ backedUp: boolean;
23
+ transports: AuthenticatorTransportFuture[];
24
+ }
25
+ export interface NewSessionResponse {
26
+ userId: string;
27
+ token: string;
28
+ }
29
+ /**
30
+ * Types for all API endpoints
31
+ * @internal
32
+ */
33
+ export interface _apiTypes {
34
+ metadata: {
35
+ GET: {
36
+ version: string;
37
+ routes: Record<string, {
38
+ params: Record<string, string | null>;
39
+ methods: string[];
40
+ }>;
41
+ plugins: Record<string, string>;
42
+ };
43
+ };
44
+ session: {
45
+ GET: Session & {
46
+ user: User;
47
+ };
48
+ DELETE: Session;
49
+ };
50
+ register: {
51
+ OPTIONS: {
52
+ userId: string;
53
+ options: PublicKeyCredentialCreationOptionsJSON;
54
+ };
55
+ POST: [z.input<typeof APIUserRegistration>, NewSessionResponse];
56
+ };
57
+ 'users/:id': {
58
+ GET: UserPublic & Partial<User>;
59
+ PATCH: [z.input<typeof UserChangeable>, User];
60
+ DELETE: User;
61
+ };
62
+ 'users/:id/full': {
63
+ GET: User & {
64
+ sessions: Session[];
65
+ };
66
+ };
67
+ 'users/:id/auth': {
68
+ OPTIONS: [z.input<typeof UserAuthOptions>, PublicKeyCredentialRequestOptionsJSON];
69
+ POST: [z.input<typeof PasskeyAuthenticationResponse>, NewSessionResponse];
70
+ };
71
+ 'users/:id/sessions': {
72
+ GET: Session[];
73
+ DELETE: [string, Session[]];
74
+ };
75
+ 'users/:id/passkeys': {
76
+ OPTIONS: PublicKeyCredentialCreationOptionsJSON;
77
+ GET: Passkey[];
78
+ PUT: [z.input<typeof PasskeyRegistration>, Passkey];
79
+ };
80
+ 'users/:id/verify_email': {
81
+ GET: Verification;
82
+ POST: [{
83
+ token: string;
84
+ }, {}];
85
+ };
86
+ 'passkeys/:id': {
87
+ GET: Passkey;
88
+ PATCH: [z.input<typeof PasskeyChangeable>, Passkey];
89
+ DELETE: Passkey;
90
+ };
91
+ user_id: {
92
+ POST: [{
93
+ using: 'email' | 'handle';
94
+ value: string;
95
+ }, {
96
+ id: string;
97
+ }];
98
+ };
99
+ }
100
+ export type Endpoint = keyof _apiTypes;
101
+ 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;
102
+ export type RequestBody<Method extends RequestMethod, E extends Endpoint> = Method extends keyof _apiTypes[E] ? _apiTypes[E][Method] extends [infer Body, unknown] ? Body : any : unknown;
103
+ 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>;
104
+ 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
@@ -1,2 +1,4 @@
1
- export * as schemas from './schemas.js';
1
+ export * from './api.js';
2
+ export * from './requests.js';
3
+ export * from './schemas.js';
2
4
  export * from './user.js';
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- export * as schemas from './schemas.js';
1
+ export * from './api.js';
2
+ export * from './requests.js';
3
+ export * from './schemas.js';
2
4
  export * from './user.js';
@@ -0,0 +1,2 @@
1
+ export declare const requestMethods: readonly ["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"];
2
+ export type RequestMethod = (typeof requestMethods)[number];
@@ -0,0 +1 @@
1
+ export const requestMethods = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH'];
package/dist/schemas.d.ts CHANGED
@@ -1,44 +1,78 @@
1
- import * as z from 'zod';
2
- export declare const User: z.ZodObject<{
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
- email: z.ZodString;
5
- name: z.ZodString;
6
- image: z.ZodString;
7
- }, "strip", z.ZodTypeAny, {
8
- name: string;
9
- email: string;
10
- id: string;
11
- image: string;
12
- }, {
13
- name: string;
14
- email: string;
15
- id: string;
16
- image: string;
17
- }>;
18
- export type User = z.infer<typeof User>;
19
- export declare const Login: z.ZodObject<{
20
- email: z.ZodString;
21
- password: z.ZodOptional<z.ZodString>;
22
- }, "strip", z.ZodTypeAny, {
23
- email: string;
24
- password?: string | undefined;
25
- }, {
26
- email: string;
27
- password?: string | undefined;
28
- }>;
29
- export type Login = z.infer<typeof Login>;
30
- export declare const Registration: z.ZodObject<z.objectUtil.extendShape<{
31
- email: z.ZodString;
32
- password: z.ZodOptional<z.ZodString>;
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
- }>, "strip", z.ZodTypeAny, {
36
- name: string;
37
- email: string;
38
- password?: string | undefined;
39
- }, {
40
- name: string;
41
- email: string;
42
- password?: string | undefined;
43
- }>;
44
- export type Registration = z.infer<typeof Registration>;
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<"action" | "login">;
77
+ }, z.core.$strip>;
78
+ export type UserAuthOptions = z.infer<typeof UserAuthOptions>;
package/dist/schemas.js CHANGED
@@ -1,14 +1,48 @@
1
- import * as z from 'zod';
2
- export const User = z.object({
3
- id: z.string().uuid(),
4
- email: z.string().email(),
5
- name: z.string().min(1, 'Name is required').max(255, 'Name is too long'),
6
- image: z.string().url(),
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'),
7
24
  });
8
- export const Login = z.object({
9
- email: z.string({ required_error: 'Email is required' }).min(1, 'Email is required').max(255, 'Email is too long').email('Invalid email'),
10
- password: z.string().max(255, 'Password must be less than 255 characters').optional(),
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'),
11
40
  });
12
- export const Registration = Login.extend({
13
- name: z.string({ required_error: 'Name is required' }),
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,
14
46
  });
47
+ export const PasskeyChangeable = z.object({ name: z.string() }).partial();
48
+ export const UserAuthOptions = z.object({ type: z.literal(['login', 'action']) });
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
+ name: z.ZodOptional<z.ZodString>;
25
+ image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
26
+ email: z.ZodOptional<z.ZodEmail>;
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.1.0",
3
+ "version": "0.2.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
- "./schemas": "./dist/schemas.js"
22
+ "./*": "./dist/*.js"
23
23
  },
24
24
  "files": [
25
25
  "dist"
@@ -28,6 +28,7 @@
28
28
  "build": "tsc"
29
29
  },
30
30
  "dependencies": {
31
- "zod": "^3.24.2"
31
+ "@simplewebauthn/types": "^12.0.0",
32
+ "zod": "^3.25.61"
32
33
  }
33
34
  }