@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/plugins.d.ts CHANGED
@@ -1,4 +1,24 @@
1
1
  import * as z from 'zod';
2
+ export declare const PluginServerHooks: z.ZodObject<{
3
+ statusText: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>>>;
4
+ remove: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
5
+ clean: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
6
+ }, z.core.$strip>;
7
+ interface _InitOptions {
8
+ force?: boolean;
9
+ skip: boolean;
10
+ check: boolean;
11
+ }
12
+ export interface ServerHooks {
13
+ statusText?(): string | Promise<string>;
14
+ remove?: (opt: {
15
+ force?: boolean;
16
+ }) => void | Promise<void>;
17
+ clean?: (opt: Partial<_InitOptions>) => void | Promise<void>;
18
+ }
19
+ export interface ClientHooks {
20
+ run(): void | Promise<void>;
21
+ }
2
22
  export declare const Plugin: z.ZodObject<{
3
23
  name: z.ZodString;
4
24
  version: z.ZodString;
@@ -25,20 +45,64 @@ export declare const Plugin: z.ZodObject<{
25
45
  /** If set Axium can check the npm registry for updates */
26
46
  update_checks: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
27
47
  }, z.core.$loose>;
28
- export type Plugin = z.infer<typeof Plugin>;
29
- export interface PluginInfo {
30
- path: string;
31
- dirname: string;
32
- specifier: string;
33
- loadedBy: string;
34
- cli?: string;
35
- /** @internal */
36
- _hooks?: ServerHooks;
37
- /** @internal */
38
- _client?: ClientHooks;
39
- isServer: boolean;
40
- _db?: any;
48
+ export interface Plugin extends z.infer<typeof Plugin> {
49
+ }
50
+ export declare const PluginInfo: z.ZodObject<{
51
+ path: z.ZodString;
52
+ dirname: z.ZodString;
53
+ specifier: z.ZodString;
54
+ loadedBy: z.ZodString;
55
+ cli: z.ZodOptional<z.ZodString>;
56
+ _hooks: z.ZodOptional<z.ZodObject<{
57
+ statusText: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>>>;
58
+ remove: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
59
+ clean: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
60
+ }, z.core.$strip>>;
61
+ _client: z.ZodOptional<z.ZodAny>;
62
+ isServer: z.ZodBoolean;
63
+ _db: z.ZodOptional<z.ZodAny>;
64
+ }, z.core.$strip>;
65
+ export interface PluginInfo extends z.infer<typeof PluginInfo> {
41
66
  }
67
+ export declare const PluginInternal: z.ZodObject<{
68
+ path: z.ZodString;
69
+ dirname: z.ZodString;
70
+ specifier: z.ZodString;
71
+ loadedBy: z.ZodString;
72
+ cli: z.ZodOptional<z.ZodString>;
73
+ _hooks: z.ZodOptional<z.ZodObject<{
74
+ statusText: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>>>;
75
+ remove: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
76
+ clean: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
77
+ }, z.core.$strip>>;
78
+ _client: z.ZodOptional<z.ZodAny>;
79
+ isServer: z.ZodBoolean;
80
+ _db: z.ZodOptional<z.ZodAny>;
81
+ name: z.ZodString;
82
+ version: z.ZodString;
83
+ description: z.ZodOptional<z.ZodString>;
84
+ apps: z.ZodOptional<z.ZodArray<z.ZodObject<{
85
+ id: z.ZodString;
86
+ name: z.ZodOptional<z.ZodString>;
87
+ image: z.ZodOptional<z.ZodString>;
88
+ icon: z.ZodOptional<z.ZodString>;
89
+ }, z.core.$strip>>>;
90
+ client: z.ZodOptional<z.ZodObject<{
91
+ cli: z.ZodOptional<z.ZodString>;
92
+ hooks: z.ZodOptional<z.ZodString>;
93
+ integrations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
94
+ }, z.core.$strip>>;
95
+ server: z.ZodOptional<z.ZodObject<{
96
+ cli: z.ZodOptional<z.ZodString>;
97
+ hooks: z.ZodOptional<z.ZodString>;
98
+ integrations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
99
+ http_handler: z.ZodOptional<z.ZodString>;
100
+ routes: z.ZodOptional<z.ZodString>;
101
+ db: z.ZodOptional<z.ZodString>;
102
+ }, z.core.$strip>>;
103
+ /** If set Axium can check the npm registry for updates */
104
+ update_checks: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
105
+ }, z.core.$loose>;
42
106
  export interface PluginInternal extends Plugin, Readonly<PluginInfo> {
43
107
  }
44
108
  export declare const plugins: Map<string, PluginInternal>;
@@ -46,25 +110,5 @@ export declare const plugins: Map<string, PluginInternal>;
46
110
  * @internal
47
111
  */
48
112
  export declare function _findPlugin(search: string): PluginInternal;
49
- export declare const PluginServerHooks: z.ZodObject<{
50
- statusText: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<readonly [], null>, z.ZodString>>>;
51
- remove: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
52
- clean: z.ZodOptional<z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>;
53
- }, z.core.$strip>;
54
- interface _InitOptions {
55
- force?: boolean;
56
- skip: boolean;
57
- check: boolean;
58
- }
59
- export interface ServerHooks {
60
- statusText?(): string | Promise<string>;
61
- remove?: (opt: {
62
- force?: boolean;
63
- }) => void | Promise<void>;
64
- clean?: (opt: Partial<_InitOptions>) => void | Promise<void>;
65
- }
66
- export interface ClientHooks {
67
- run(): void | Promise<void>;
68
- }
69
113
  export declare function runIntegrations(): Promise<void>;
70
114
  export {};
package/dist/plugins.js CHANGED
@@ -2,6 +2,12 @@ import * as z from 'zod';
2
2
  import { App } from './apps.js';
3
3
  import { debug, warn } from './io.js';
4
4
  import { zAsyncFunction } from './schemas.js';
5
+ const fn = z.custom(data => typeof data === 'function');
6
+ export const PluginServerHooks = z.object({
7
+ statusText: zAsyncFunction(z.function({ input: [], output: z.string() })).optional(),
8
+ remove: fn.optional(),
9
+ clean: fn.optional(),
10
+ });
5
11
  const PluginCommon = z.object({
6
12
  /** CLI mixin path */
7
13
  cli: z.string().optional(),
@@ -25,6 +31,20 @@ export const Plugin = z.looseObject({
25
31
  /** If set Axium can check the npm registry for updates */
26
32
  update_checks: z.boolean().nullish(),
27
33
  });
34
+ export const PluginInfo = z.object({
35
+ path: z.string(),
36
+ dirname: z.string(),
37
+ specifier: z.string(),
38
+ loadedBy: z.string(),
39
+ cli: z.string().optional(),
40
+ /** @internal */
41
+ _hooks: PluginServerHooks.optional(),
42
+ /** @internal */
43
+ _client: z.any().optional(),
44
+ isServer: z.boolean(),
45
+ _db: z.any().optional(),
46
+ });
47
+ export const PluginInternal = z.looseObject({ ...Plugin.shape, ...PluginInfo.shape });
28
48
  export const plugins = new Map();
29
49
  /**
30
50
  * @internal
@@ -35,12 +55,6 @@ export function _findPlugin(search) {
35
55
  throw `Can't find a plugin matching "${search}"`;
36
56
  return plugin;
37
57
  }
38
- const fn = z.custom(data => typeof data === 'function');
39
- export const PluginServerHooks = z.object({
40
- statusText: zAsyncFunction(z.function({ input: [], output: z.string() })).optional(),
41
- remove: fn.optional(),
42
- clean: fn.optional(),
43
- });
44
58
  export async function runIntegrations() {
45
59
  for (const [pluginName, plugin] of plugins) {
46
60
  const { integrations } = plugin[plugin.isServer ? 'server' : 'client'];
package/dist/user.d.ts CHANGED
@@ -4,44 +4,45 @@ export declare const User: z.ZodObject<{
4
4
  id: z.ZodUUID;
5
5
  name: z.ZodString;
6
6
  email: z.ZodEmail;
7
- emailVerified: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
7
+ emailVerified: z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>;
8
8
  image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
9
- preferences: z.ZodObject<{
9
+ preferences: z.ZodLazy<z.ZodObject<{
10
10
  debug: z.ZodDefault<z.ZodBoolean>;
11
- }, z.core.$strip>;
11
+ }, z.core.$strip>>;
12
12
  roles: z.ZodArray<z.ZodString>;
13
+ tags: z.ZodArray<z.ZodString>;
13
14
  registeredAt: z.ZodCoercedDate<unknown>;
14
15
  isAdmin: z.ZodBoolean;
16
+ isSuspended: z.ZodBoolean;
15
17
  }, z.core.$strip>;
16
18
  export interface User extends z.infer<typeof User> {
17
19
  preferences: Preferences;
18
20
  }
19
21
  export interface UserInternal extends User {
20
- isSuspended: boolean;
21
- /** Tags are internal, roles are public */
22
- tags: string[];
23
22
  }
24
23
  export declare const userPublicFields: ["id", "image", "name", "registeredAt", "roles"];
25
24
  export declare const UserPublic: z.ZodObject<{
26
25
  id: z.ZodUUID;
27
26
  name: z.ZodString;
28
27
  email: z.ZodOptional<z.ZodEmail>;
29
- emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodDate>>>;
28
+ emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
30
29
  image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
31
- preferences: z.ZodOptional<z.ZodObject<{
30
+ preferences: z.ZodOptional<z.ZodLazy<z.ZodObject<{
32
31
  debug: z.ZodDefault<z.ZodBoolean>;
33
- }, z.core.$strip>>;
32
+ }, z.core.$strip>>>;
34
33
  roles: z.ZodArray<z.ZodString>;
34
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
35
35
  registeredAt: z.ZodCoercedDate<unknown>;
36
36
  isAdmin: z.ZodOptional<z.ZodBoolean>;
37
+ isSuspended: z.ZodOptional<z.ZodBoolean>;
37
38
  }, z.core.$strip>;
38
39
  export interface UserPublic extends z.infer<typeof UserPublic> {
39
40
  }
40
- export declare const userProtectedFields: ["email", "emailVerified", "preferences", "isAdmin"];
41
+ export declare const userProtectedFields: ["email", "emailVerified", "preferences", "isAdmin", "isSuspended", "tags"];
41
42
  export declare const UserChangeable: z.ZodObject<{
42
- preferences: z.ZodOptional<z.ZodObject<{
43
+ preferences: z.ZodOptional<z.ZodLazy<z.ZodObject<{
43
44
  debug: z.ZodDefault<z.ZodBoolean>;
44
- }, z.core.$strip>>;
45
+ }, z.core.$strip>>>;
45
46
  email: z.ZodOptional<z.ZodEmail>;
46
47
  name: z.ZodOptional<z.ZodString>;
47
48
  image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
@@ -50,6 +51,10 @@ export interface UserChangeable extends z.infer<typeof UserChangeable> {
50
51
  preferences?: Preferences;
51
52
  }
52
53
  export declare function getUserImage(user: Partial<User>): string;
54
+ export declare const UserRegistrationInit: z.ZodObject<{
55
+ name: z.ZodOptional<z.ZodString>;
56
+ email: z.ZodOptional<z.ZodEmail>;
57
+ }, z.core.$strip>;
53
58
  export declare const UserRegistration: z.ZodObject<{
54
59
  name: z.ZodString;
55
60
  email: z.ZodEmail;
@@ -61,15 +66,7 @@ export declare const UserRegistration: z.ZodObject<{
61
66
  clientDataJSON: z.ZodString;
62
67
  attestationObject: z.ZodString;
63
68
  authenticatorData: z.ZodOptional<z.ZodString>;
64
- transports: z.ZodOptional<z.ZodArray<z.ZodEnum<{
65
- ble: "ble";
66
- cable: "cable";
67
- hybrid: "hybrid";
68
- internal: "internal";
69
- nfc: "nfc";
70
- "smart-card": "smart-card";
71
- usb: "usb";
72
- }>>>;
69
+ transports: z.ZodOptional<z.ZodArray<z.ZodLiteral<"ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb">>>;
73
70
  publicKeyAlgorithm: z.ZodOptional<z.ZodNumber>;
74
71
  publicKey: z.ZodOptional<z.ZodString>;
75
72
  }, z.core.$strip>;
package/dist/user.js CHANGED
@@ -7,26 +7,32 @@ export const User = z.object({
7
7
  id: z.uuid(),
8
8
  name: z.string().min(1, 'Name is required').max(255, 'Name is too long'),
9
9
  email: z.email(),
10
- emailVerified: z.date().nullish(),
10
+ emailVerified: z.coerce.date().nullish(),
11
11
  image: z.url().nullish(),
12
- get preferences() {
13
- return Preferences;
14
- },
15
- roles: z.array(z.string()),
12
+ preferences: z.lazy(() => Preferences),
13
+ roles: z.string().array(),
14
+ /** Tags are internal, roles are public */
15
+ tags: z.string().array(),
16
16
  registeredAt: z.coerce.date(),
17
17
  isAdmin: z.boolean(),
18
+ isSuspended: z.boolean(),
18
19
  });
19
20
  export const userPublicFields = ['id', 'image', 'name', 'registeredAt', 'roles'];
20
21
  export const UserPublic = User.partial(Object.fromEntries(Object.keys(User.shape)
21
22
  .filter((key) => !userPublicFields.includes(key))
22
23
  .map(key => [key, true])));
23
- export const userProtectedFields = ['email', 'emailVerified', 'preferences', 'isAdmin'];
24
+ export const userProtectedFields = [
25
+ 'email',
26
+ 'emailVerified',
27
+ 'preferences',
28
+ 'isAdmin',
29
+ 'isSuspended',
30
+ 'tags',
31
+ ];
24
32
  export const UserChangeable = z
25
33
  .object({
26
34
  ...pick(User.shape, 'name', 'email', 'image'),
27
- get preferences() {
28
- return Preferences;
29
- },
35
+ preferences: z.lazy(() => Preferences),
30
36
  })
31
37
  .partial();
32
38
  export function getUserImage(user) {
@@ -37,6 +43,10 @@ export function getUserImage(user) {
37
43
  <text x="23" y="28" style="font-family:sans-serif;font-weight:bold;" fill="white">${(user.name ?? '?').replaceAll(/\W/g, '')[0]}</text>
38
44
  </svg>`.replaceAll(/[\t\n]/g, '');
39
45
  }
46
+ export const UserRegistrationInit = z.object({
47
+ name: z.string().min(1).max(100).optional(),
48
+ email: z.email().optional(),
49
+ });
40
50
  export const UserRegistration = z.object({
41
51
  name: z.string().min(1).max(100),
42
52
  email: z.email(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",