@coffer-org/sdk 1.2.4 → 1.3.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.
@@ -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 {};
@@ -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
- return z.preprocess((v) => (v === '' || v === null ? undefined : v), req ? schema : schema.optional());
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
@@ -201,8 +201,7 @@ export declare function isJsonStored(field: FieldMeta | FieldClient): boolean;
201
201
  export { LANGUAGES, SEX_OPTIONS, WEEKDAY_OPTIONS } from './fields/constants.ts';
202
202
  export { parseUrl, buildUrl, hrefOf, type UrlValue } from './fields/url.ts';
203
203
  export declare function applyMultiple(base: FieldMeta, multiple: boolean): FieldMeta;
204
- export interface StringOpts extends FieldCoreOpts {
205
- }
204
+ export type StringOpts = FieldCoreOpts;
206
205
  export declare function string(o: StringOpts & {
207
206
  key: string;
208
207
  }): FieldItem;
@@ -214,10 +213,8 @@ export declare function string(o: StringOpts & {
214
213
  key?: undefined;
215
214
  value?: undefined;
216
215
  }): FieldMeta;
217
- export interface LocalPathOpts extends FieldCoreOpts {
218
- }
219
- export interface LocalFileOpts extends LocalPathOpts {
220
- }
216
+ export type LocalPathOpts = FieldCoreOpts;
217
+ export type LocalFileOpts = LocalPathOpts;
221
218
  export declare function localDir(o: LocalPathOpts & {
222
219
  key: string;
223
220
  }): FieldItem;
@@ -240,8 +237,7 @@ export declare function localFile(o: LocalFileOpts & {
240
237
  key?: undefined;
241
238
  value?: undefined;
242
239
  }): FieldMeta;
243
- export interface TextOpts extends FieldCoreOpts {
244
- }
240
+ export type TextOpts = FieldCoreOpts;
245
241
  export declare function text(o: TextOpts & {
246
242
  key: string;
247
243
  }): FieldItem;
@@ -275,8 +271,7 @@ export declare function smallText(o: TextOpts & {
275
271
  key?: undefined;
276
272
  value?: undefined;
277
273
  }): FieldMeta;
278
- export interface RealOpts extends FieldCoreOpts {
279
- }
274
+ export type RealOpts = FieldCoreOpts;
280
275
  export declare function real(o: RealOpts & {
281
276
  key: string;
282
277
  }): FieldItem;
@@ -288,8 +283,7 @@ export declare function real(o: RealOpts & {
288
283
  key?: undefined;
289
284
  value?: undefined;
290
285
  }): FieldMeta;
291
- export interface IntOpts extends FieldCoreOpts {
292
- }
286
+ export type IntOpts = FieldCoreOpts;
293
287
  export declare function int(o: IntOpts & {
294
288
  key: string;
295
289
  }): FieldItem;
@@ -301,8 +295,7 @@ export declare function int(o: IntOpts & {
301
295
  key?: undefined;
302
296
  value?: undefined;
303
297
  }): FieldMeta;
304
- export interface DateOpts extends FieldCoreOpts {
305
- }
298
+ export type DateOpts = FieldCoreOpts;
306
299
  export declare function date(o: DateOpts & {
307
300
  key: string;
308
301
  }): FieldItem;
@@ -314,8 +307,7 @@ export declare function date(o: DateOpts & {
314
307
  key?: undefined;
315
308
  value?: undefined;
316
309
  }): FieldMeta;
317
- export interface TimeOpts extends FieldCoreOpts {
318
- }
310
+ export type TimeOpts = FieldCoreOpts;
319
311
  export declare function time(o: TimeOpts & {
320
312
  key: string;
321
313
  }): FieldItem;
@@ -327,8 +319,7 @@ export declare function time(o: TimeOpts & {
327
319
  key?: undefined;
328
320
  value?: undefined;
329
321
  }): FieldMeta;
330
- export interface DateTimeOpts extends FieldCoreOpts {
331
- }
322
+ export type DateTimeOpts = FieldCoreOpts;
332
323
  export declare function datetime(o: DateTimeOpts & {
333
324
  key: string;
334
325
  }): FieldItem;
@@ -340,8 +331,7 @@ export declare function datetime(o: DateTimeOpts & {
340
331
  key?: undefined;
341
332
  value?: undefined;
342
333
  }): FieldMeta;
343
- export interface BooleanOpts extends FieldCoreOpts {
344
- }
334
+ export type BooleanOpts = FieldCoreOpts;
345
335
  export declare function boolean(o: BooleanOpts & {
346
336
  key: string;
347
337
  }): FieldItem;
@@ -353,8 +343,7 @@ export declare function boolean(o: BooleanOpts & {
353
343
  key?: undefined;
354
344
  value?: undefined;
355
345
  }): FieldMeta;
356
- export interface TriStateOpts extends FieldCoreOpts {
357
- }
346
+ export type TriStateOpts = FieldCoreOpts;
358
347
  export declare function triState(o: TriStateOpts & {
359
348
  key: string;
360
349
  }): FieldItem;
@@ -398,8 +387,7 @@ export declare function relation(o: RelationOpts & {
398
387
  value?: undefined;
399
388
  }): FieldMeta;
400
389
  export declare function bindSelectSourceZod(field: FieldMeta, values: string[]): void;
401
- export interface JsonOpts extends FieldCoreOpts {
402
- }
390
+ export type JsonOpts = FieldCoreOpts;
403
391
  export declare function json(o: JsonOpts & {
404
392
  key: string;
405
393
  }): FieldItem;
@@ -439,8 +427,7 @@ export declare function measured(o: MeasuredOpts & {
439
427
  key?: undefined;
440
428
  value?: undefined;
441
429
  }): FieldMeta;
442
- export interface MoneyOpts extends FieldCoreOpts {
443
- }
430
+ export type MoneyOpts = FieldCoreOpts;
444
431
  export declare function money(o: MoneyOpts & {
445
432
  key: string;
446
433
  }): FieldItem;
@@ -452,8 +439,7 @@ export declare function money(o: MoneyOpts & {
452
439
  key?: undefined;
453
440
  value?: undefined;
454
441
  }): FieldMeta;
455
- export interface CodeFieldOpts extends FieldCoreOpts {
456
- }
442
+ export type CodeFieldOpts = FieldCoreOpts;
457
443
  export declare function code(o: CodeFieldOpts & {
458
444
  key: string;
459
445
  }): FieldItem;
@@ -465,8 +451,7 @@ export declare function code(o: CodeFieldOpts & {
465
451
  key?: undefined;
466
452
  value?: undefined;
467
453
  }): FieldMeta;
468
- export interface GeoOpts extends FieldCoreOpts {
469
- }
454
+ export type GeoOpts = FieldCoreOpts;
470
455
  export declare function geo(o: GeoOpts & {
471
456
  key: string;
472
457
  }): FieldItem;
@@ -518,8 +503,7 @@ export declare function period(o: PeriodOpts & {
518
503
  key?: undefined;
519
504
  value?: undefined;
520
505
  }): FieldMeta;
521
- export interface FileOpts extends FieldCoreOpts {
522
- }
506
+ export type FileOpts = FieldCoreOpts;
523
507
  export type ImageOpts = FileOpts;
524
508
  export declare function file(o: FileOpts & {
525
509
  key: string;
@@ -609,6 +593,17 @@ export declare function cover(o: FileOpts & {
609
593
  key?: undefined;
610
594
  value?: undefined;
611
595
  }): FieldMeta;
596
+ export declare function poster(o: FileOpts & {
597
+ key: string;
598
+ }): FieldItem;
599
+ export declare function poster(o: FileOpts & {
600
+ value: unknown;
601
+ key?: undefined;
602
+ }): StaticEl;
603
+ export declare function poster(o: FileOpts & {
604
+ key?: undefined;
605
+ value?: undefined;
606
+ }): FieldMeta;
612
607
  export interface KeyValueOpts extends FieldCoreOpts {
613
608
  option?: FieldMeta;
614
609
  keyLabel?: string;
@@ -618,8 +613,7 @@ export interface KeyValueOpts extends FieldCoreOpts {
618
613
  export declare function keyValue(raw: KeyValueOpts & {
619
614
  key: string;
620
615
  }): GroupEl;
621
- export interface RangeOpts extends FieldCoreOpts {
622
- }
616
+ export type RangeOpts = FieldCoreOpts;
623
617
  export declare function numberRange(o: RangeOpts & {
624
618
  key: string;
625
619
  }): FieldItem;
@@ -642,8 +636,7 @@ export declare function realRange(o: RangeOpts & {
642
636
  key?: undefined;
643
637
  value?: undefined;
644
638
  }): FieldMeta;
645
- export interface EmbedOpts extends FieldCoreOpts {
646
- }
639
+ export type EmbedOpts = FieldCoreOpts;
647
640
  export declare function embed(o: EmbedOpts & {
648
641
  key: string;
649
642
  }): FieldItem;
@@ -688,6 +681,7 @@ declare const PRIMITIVES: {
688
681
  media: typeof media;
689
682
  avatar: typeof avatar;
690
683
  cover: typeof cover;
684
+ poster: typeof poster;
691
685
  embed: typeof embed;
692
686
  keyValue: typeof keyValue;
693
687
  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 = [string({ key: 'text', label: 'core.fields.text' })];
506
- slots.forEach((label, i) => fields.push(boolean({ key: `check${i}`, label: label || 'core.fields.check' })));
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().optional(),
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffer-org/sdk",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"