@coffer-org/sdk 1.2.3 → 1.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/field-presets.d.ts +6 -1
- package/dist/field-presets.js +17 -1
- package/dist/fields/validation.js +8 -1
- package/dist/fields.d.ts +12 -0
- package/dist/fields.js +14 -4
- package/dist/users-module.d.ts +1 -0
- package/dist/users-module.js +22 -0
- package/package.json +1 -1
package/dist/field-presets.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FieldMeta, type FieldItem, type StaticEl, type FieldCoreOpts } from './fields.ts';
|
|
1
|
+
import { type FieldMeta, type FieldItem, type StaticEl, type FieldCoreOpts, type GroupEl } from './fields.ts';
|
|
2
2
|
export interface TextPresetOpts extends FieldCoreOpts {
|
|
3
3
|
label?: string;
|
|
4
4
|
}
|
|
@@ -35,6 +35,10 @@ export declare function password(o: TextPresetOpts & {
|
|
|
35
35
|
key?: undefined;
|
|
36
36
|
value?: undefined;
|
|
37
37
|
}): FieldMeta;
|
|
38
|
+
export declare function internalApiToken(o: {
|
|
39
|
+
key: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
}): GroupEl;
|
|
38
42
|
export declare function slug(o: TextPresetOpts & {
|
|
39
43
|
key: string;
|
|
40
44
|
}): FieldItem;
|
|
@@ -242,5 +246,6 @@ export declare const presets: {
|
|
|
242
246
|
weight: typeof weight;
|
|
243
247
|
dimensions: typeof dimensions;
|
|
244
248
|
country: typeof country;
|
|
249
|
+
internalApiToken: typeof internalApiToken;
|
|
245
250
|
};
|
|
246
251
|
export {};
|
package/dist/field-presets.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { real, int, text, date, select, vmsg, jsonRefined, typeErr, optionalize, applyMultiple, wrapKey, normalizeOpts, } from "./fields.js";
|
|
2
|
+
import { real, int, text, date, select, string, group, vmsg, jsonRefined, typeErr, optionalize, applyMultiple, wrapKey, normalizeOpts, } from "./fields.js";
|
|
3
3
|
export function email(raw) {
|
|
4
4
|
const o = normalizeOpts(raw);
|
|
5
5
|
const required = o.required ?? false;
|
|
@@ -50,6 +50,21 @@ export function password(raw) {
|
|
|
50
50
|
};
|
|
51
51
|
return wrapKey(o, base);
|
|
52
52
|
}
|
|
53
|
+
export function internalApiToken(o) {
|
|
54
|
+
return group({
|
|
55
|
+
key: o.key,
|
|
56
|
+
label: o.label ?? o.key,
|
|
57
|
+
multiple: true,
|
|
58
|
+
rules: { unique: ['name'] },
|
|
59
|
+
view: { kind: 'internalApiToken' },
|
|
60
|
+
fields: [
|
|
61
|
+
string({ key: 'name' }),
|
|
62
|
+
password({ key: 'token' }),
|
|
63
|
+
string({ key: 'createdAt' }),
|
|
64
|
+
string({ key: 'lastUsedAt' }),
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
53
68
|
const SLUG_RE = /^[a-z0-9-]+$/;
|
|
54
69
|
export function slug(raw) {
|
|
55
70
|
const o = normalizeOpts(raw);
|
|
@@ -308,4 +323,5 @@ export const presets = {
|
|
|
308
323
|
weight,
|
|
309
324
|
dimensions,
|
|
310
325
|
country,
|
|
326
|
+
internalApiToken,
|
|
311
327
|
};
|
|
@@ -37,7 +37,14 @@ export function jsonRefined(inner, code) {
|
|
|
37
37
|
}
|
|
38
38
|
export function optionalize(schema, required) {
|
|
39
39
|
const req = required === true;
|
|
40
|
-
|
|
40
|
+
const pre = (v) => (v === '' || v === null ? undefined : v);
|
|
41
|
+
if (!req)
|
|
42
|
+
return z.preprocess(pre, schema.optional());
|
|
43
|
+
const guard = z.unknown().superRefine((v, ctx) => {
|
|
44
|
+
if (v === undefined)
|
|
45
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: vmsg('required') });
|
|
46
|
+
});
|
|
47
|
+
return z.preprocess(pre, guard.pipe(schema));
|
|
41
48
|
}
|
|
42
49
|
export function decodeVmsg(message) {
|
|
43
50
|
try {
|
package/dist/fields.d.ts
CHANGED
|
@@ -609,6 +609,17 @@ export declare function cover(o: FileOpts & {
|
|
|
609
609
|
key?: undefined;
|
|
610
610
|
value?: undefined;
|
|
611
611
|
}): FieldMeta;
|
|
612
|
+
export declare function poster(o: FileOpts & {
|
|
613
|
+
key: string;
|
|
614
|
+
}): FieldItem;
|
|
615
|
+
export declare function poster(o: FileOpts & {
|
|
616
|
+
value: unknown;
|
|
617
|
+
key?: undefined;
|
|
618
|
+
}): StaticEl;
|
|
619
|
+
export declare function poster(o: FileOpts & {
|
|
620
|
+
key?: undefined;
|
|
621
|
+
value?: undefined;
|
|
622
|
+
}): FieldMeta;
|
|
612
623
|
export interface KeyValueOpts extends FieldCoreOpts {
|
|
613
624
|
option?: FieldMeta;
|
|
614
625
|
keyLabel?: string;
|
|
@@ -688,6 +699,7 @@ declare const PRIMITIVES: {
|
|
|
688
699
|
media: typeof media;
|
|
689
700
|
avatar: typeof avatar;
|
|
690
701
|
cover: typeof cover;
|
|
702
|
+
poster: typeof poster;
|
|
691
703
|
embed: typeof embed;
|
|
692
704
|
keyValue: typeof keyValue;
|
|
693
705
|
numberRange: typeof numberRange;
|
package/dist/fields.js
CHANGED
|
@@ -502,9 +502,9 @@ export function check(raw) {
|
|
|
502
502
|
const multiple = o.multiple ?? false;
|
|
503
503
|
const slots = o.slots && o.slots.length > 0 ? o.slots : [''];
|
|
504
504
|
if (multiple) {
|
|
505
|
-
const fields =
|
|
506
|
-
|
|
507
|
-
return group({ key: o.key, label: o.label ?? o.key, multiple: true, required: required, fields });
|
|
505
|
+
const fields = slots.map((label, i) => boolean({ key: `check${i}`, label: label || 'core.fields.check' }));
|
|
506
|
+
fields.push(string({ key: 'text', label: 'core.fields.text' }));
|
|
507
|
+
return group({ key: o.key, label: o.label ?? o.key, multiple: true, required: required, fields, view: { kind: 'checklist' } });
|
|
508
508
|
}
|
|
509
509
|
const shape = { text: z.string() };
|
|
510
510
|
const columns = { text: 'text' };
|
|
@@ -661,10 +661,16 @@ export function geo(raw) {
|
|
|
661
661
|
const rowSchema = z.object({
|
|
662
662
|
lat: z.number().min(-90).max(90),
|
|
663
663
|
lng: z.number().min(-180).max(180),
|
|
664
|
-
label: z.string().
|
|
664
|
+
label: z.string().nullish(),
|
|
665
665
|
});
|
|
666
666
|
const s = z.unknown().superRefine((raw, ctx) => {
|
|
667
667
|
const parsed = jsonValue(raw);
|
|
668
|
+
const p = parsed;
|
|
669
|
+
if (p == null || (typeof p === 'object' && p.lat == null && p.lng == null)) {
|
|
670
|
+
if (required)
|
|
671
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: vmsg('required') });
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
668
674
|
if (typeof parsed === 'string') {
|
|
669
675
|
ctx.addIssue({ code: z.ZodIssueCode.custom, message: vmsg('json') });
|
|
670
676
|
return;
|
|
@@ -837,6 +843,9 @@ export function avatar(o) {
|
|
|
837
843
|
export function cover(o) {
|
|
838
844
|
return makeFile('cover', o);
|
|
839
845
|
}
|
|
846
|
+
export function poster(o) {
|
|
847
|
+
return makeFile('poster', o);
|
|
848
|
+
}
|
|
840
849
|
export function keyValue(raw) {
|
|
841
850
|
const o = normalizeOpts(raw);
|
|
842
851
|
const valueType = { ...(o.option ?? string({ label: '' })), label: o.valueLabel ?? '' };
|
|
@@ -962,6 +971,7 @@ const PRIMITIVES = {
|
|
|
962
971
|
media,
|
|
963
972
|
avatar,
|
|
964
973
|
cover,
|
|
974
|
+
poster,
|
|
965
975
|
embed,
|
|
966
976
|
keyValue,
|
|
967
977
|
numberRange,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const USERS_MODULE: import("./module.ts").ModuleDef;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineModule } from "./module.js";
|
|
2
|
+
import { field } from "./fields.js";
|
|
3
|
+
export const USERS_MODULE = defineModule({
|
|
4
|
+
module: 'users',
|
|
5
|
+
vault: '',
|
|
6
|
+
label: 'auth.usersTitle',
|
|
7
|
+
icon: 'lucide:users',
|
|
8
|
+
views: { table: ['login', 'displayName', 'role', 'disabled'] },
|
|
9
|
+
fields: [
|
|
10
|
+
field.string({ key: 'login', label: 'auth.fieldLogin' }),
|
|
11
|
+
field.string({ key: 'displayName', label: 'auth.fieldDisplayName' }),
|
|
12
|
+
field.select({
|
|
13
|
+
key: 'role',
|
|
14
|
+
label: 'auth.fieldRole',
|
|
15
|
+
options: [
|
|
16
|
+
{ value: 'admin', title: 'auth.roleAdmin' },
|
|
17
|
+
{ value: 'member', title: 'auth.roleMember' },
|
|
18
|
+
],
|
|
19
|
+
}),
|
|
20
|
+
field.boolean({ key: 'disabled', label: 'auth.fieldDisabled' }),
|
|
21
|
+
],
|
|
22
|
+
});
|