@murumets-ee/settings 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,33 +1,28 @@
1
1
  {
2
2
  "name": "@murumets-ee/settings",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
- "import": "./dist/index.js",
10
- "require": "./dist/index.cjs"
9
+ "import": "./dist/index.js"
11
10
  },
12
11
  "./schema": {
13
12
  "types": "./dist/schema.d.ts",
14
- "import": "./dist/schema.js",
15
- "require": "./dist/schema.cjs"
13
+ "import": "./dist/schema.js"
16
14
  },
17
15
  "./view-state": {
18
16
  "types": "./dist/view-state.d.ts",
19
- "import": "./dist/view-state.js",
20
- "require": "./dist/view-state.cjs"
17
+ "import": "./dist/view-state.js"
21
18
  },
22
19
  "./plugin": {
23
20
  "types": "./dist/plugin.d.ts",
24
- "import": "./dist/plugin.js",
25
- "require": "./dist/plugin.cjs"
21
+ "import": "./dist/plugin.js"
26
22
  },
27
23
  "./admin": {
28
24
  "types": "./dist/admin.d.ts",
29
- "import": "./dist/admin.js",
30
- "require": "./dist/admin.cjs"
25
+ "import": "./dist/admin.js"
31
26
  }
32
27
  },
33
28
  "files": [
@@ -37,9 +32,9 @@
37
32
  "drizzle-orm": "^0.45.1",
38
33
  "zod": "^3.24.1",
39
34
  "server-only": "^0.0.1",
40
- "@murumets-ee/core": "0.1.2",
41
- "@murumets-ee/db": "0.1.1",
42
- "@murumets-ee/logging": "0.1.2"
35
+ "@murumets-ee/logging": "0.1.3",
36
+ "@murumets-ee/db": "0.1.2",
37
+ "@murumets-ee/core": "0.1.3"
43
38
  },
44
39
  "devDependencies": {
45
40
  "@types/node": "^22.10.5",
package/dist/admin.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var P=Object.create;var y=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var S=(t,e)=>()=>(t&&(e=t(t=0)),e);var C=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0})},b=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of j(e))!B.call(t,s)&&s!==n&&y(t,s,{get:()=>e[s],enumerable:!(o=K(e,s))||o.enumerable});return t};var z=(t,e,n)=>(n=t!=null?P(N(t)):{},b(e||!t||!t.__esModule?y(n,"default",{value:t,enumerable:!0}):n,t)),V=t=>b(y({},"__esModule",{value:!0}),t);var r,i,q,v=S(()=>{"use strict";r=require("drizzle-orm/pg-core"),i=(0,r.pgTable)("toolkit_settings",{id:(0,r.uuid)("id").primaryKey().defaultRandom(),namespace:(0,r.varchar)("namespace",{length:100}).notNull(),scope:(0,r.varchar)("scope",{length:20}).notNull().default("global"),scopeId:(0,r.varchar)("scope_id",{length:100}).notNull().default("__global__"),key:(0,r.varchar)("key",{length:255}).notNull(),locale:(0,r.varchar)("locale",{length:10}).notNull().default("_default"),value:(0,r.jsonb)("value"),updatedAt:(0,r.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow(),updatedBy:(0,r.uuid)("updated_by")},t=>({uniqueSetting:(0,r.unique)().on(t.namespace,t.scope,t.scopeId,t.key,t.locale)})),q=(0,r.pgTable)("toolkit_view_state",{id:(0,r.uuid)("id").primaryKey().defaultRandom(),userId:(0,r.uuid)("user_id").notNull(),viewKey:(0,r.varchar)("view_key",{length:255}).notNull(),state:(0,r.jsonb)("state").notNull(),expiresAt:(0,r.timestamp)("expires_at",{withTimezone:!0}),updatedAt:(0,r.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow()},t=>({uniqueUserView:(0,r.unique)().on(t.userId,t.viewKey)}))});var k,p,I=S(()=>{"use strict";k="__global__",p="_default"});function E(t){switch(t.type){case"text":{let e=f.z.string();return t.maxLength&&(e=e.max(t.maxLength)),t.minLength&&(e=e.min(t.minLength)),t.pattern&&(e=e.regex(t.pattern)),e}case"number":{let e=f.z.number();return t.integer&&(e=e.int()),t.min!==void 0&&(e=e.min(t.min)),t.max!==void 0&&(e=e.max(t.max)),e}case"boolean":return f.z.boolean();case"select":return f.z.enum(t.options);case"json":return t.schema??f.z.unknown();case"media":return f.z.string().uuid();default:return f.z.unknown()}}function L(t){let e={};for(let[n,o]of Object.entries(t.schema)){let s=E(o);"default"in o&&o.default!==void 0||(s=s.nullable()),e[n]=s}return e}var f,T=S(()=>{"use strict";f=require("zod")});var c,w,A=S(()=>{"use strict";c=require("drizzle-orm");v();I();T();w=class{definition;db;logger;scope;scopeId;validators;constructor(e,n){if(typeof window<"u")throw new Error("SettingsClient cannot be used in browser code.");if(this.definition=e,this.db=n.db,this.logger=n.logger,this.scope=n.scope??e.scope,this.scopeId=n.scopeId??k,(this.scope==="team"||this.scope==="user")&&!n.scopeId)throw new Error(`scopeId is required for ${this.scope}-scoped settings (namespace: ${e.namespace})`);this.validators=L(e)}async get(e,n){let o=this.definition.schema[e],s=o?.translatable&&n?.locale?n.locale:null;if(this.logger?.debug({namespace:this.definition.namespace,key:e,locale:s},"Getting setting"),s){let a=await this.db.select({locale:i.locale,value:i.value}).from(i).where((0,c.and)(...this.baseWhere(),(0,c.eq)(i.key,e),(0,c.or)((0,c.eq)(i.locale,s),(0,c.eq)(i.locale,p)))),l=a.find(d=>d.locale===s),g=a.find(d=>d.locale===p),u=l??g;if(u&&u.value!==void 0&&u.value!==null)return u.value}else{let a=await this.db.select({value:i.value}).from(i).where(this.whereClause(e)).limit(1);if(a.length>0&&a[0].value!==void 0&&a[0].value!==null)return a[0].value}return o&&"default"in o&&o.default!==void 0?o.default:null}async getAll(e){let n=e?.locale??null;this.logger?.debug({namespace:this.definition.namespace,locale:n},"Getting all settings");let o;n?o=await this.db.select({key:i.key,locale:i.locale,value:i.value}).from(i).where((0,c.and)(...this.baseWhere(),(0,c.or)((0,c.eq)(i.locale,p),(0,c.eq)(i.locale,n)))):o=await this.db.select({key:i.key,locale:i.locale,value:i.value}).from(i).where((0,c.and)(...this.baseWhere(),(0,c.eq)(i.locale,p)));let s=new Map;for(let l of o){let g=s.get(l.key)??{};l.locale===p?g.default=l.value:g.locale=l.value,s.set(l.key,g)}let a={};for(let[l,g]of Object.entries(this.definition.schema)){let u=s.get(l),d;g.translatable&&n&&u?.locale!==void 0&&u?.locale!==null?d=u.locale:u?.default!==void 0&&u?.default!==null&&(d=u.default),d!==void 0?a[l]=d:"default"in g&&g.default!==void 0?a[l]=g.default:a[l]=null}return a}async set(e,n,o){let s=this.resolveLocale(e,o);if(this.logger?.info({namespace:this.definition.namespace,key:e,locale:s},"Setting value"),!(e in this.definition.schema))throw new Error(`Unknown setting key '${e}' in namespace '${this.definition.namespace}'`);let a=this.validators[e];a&&a.parse(n),await this.upsert(e,n,s)}async setMany(e,n){this.logger?.info({namespace:this.definition.namespace,keys:Object.keys(e),locale:n?.locale},"Setting multiple values");for(let[o,s]of Object.entries(e)){if(!(o in this.definition.schema))throw new Error(`Unknown setting key '${o}' in namespace '${this.definition.namespace}'`);let a=this.validators[o];a&&s!==void 0&&a.parse(s)}await this.db.transaction(async o=>{for(let[s,a]of Object.entries(e)){if(a===void 0)continue;let l=this.resolveLocale(s,n);await o.insert(i).values({namespace:this.definition.namespace,scope:this.scope,scopeId:this.scopeId,key:s,locale:l,value:a,updatedAt:new Date}).onConflictDoUpdate({target:[i.namespace,i.scope,i.scopeId,i.key,i.locale],set:{value:a,updatedAt:new Date}})}})}async delete(e,n){let o=this.resolveLocale(e,n);this.logger?.info({namespace:this.definition.namespace,key:e,locale:o},"Deleting setting"),await this.db.delete(i).where(this.whereClause(e,o))}async has(e,n){let o=this.resolveLocale(e,n);return(await this.db.select({key:i.key}).from(i).where(this.whereClause(e,o)).limit(1)).length>0}resolveLocale(e,n){return this.definition.schema[e]?.translatable&&n?.locale?n.locale:p}baseWhere(){return[(0,c.eq)(i.namespace,this.definition.namespace),(0,c.eq)(i.scope,this.scope),(0,c.eq)(i.scopeId,this.scopeId)]}whereClause(e,n=p){return(0,c.and)(...this.baseWhere(),(0,c.eq)(i.key,e),(0,c.eq)(i.locale,n))}async upsert(e,n,o){await this.db.insert(i).values({namespace:this.definition.namespace,scope:this.scope,scopeId:this.scopeId,key:e,locale:o,value:n,updatedAt:new Date}).onConflictDoUpdate({target:[i.namespace,i.scope,i.scopeId,i.key,i.locale],set:{value:n,updatedAt:new Date}})}}});var R={};C(R,{createSettingsClient:()=>M});function M(t,e){let n=e?.app??(0,O.getApp)();return new w(t,{db:n.db.readWrite,logger:n.logger.child({settings:t.namespace}),scope:e?.scope,scopeId:e?.scopeId})}var O,_=S(()=>{"use strict";O=require("@murumets-ee/core");A()});var Z={};C(Z,{settingsRoutes:()=>D});module.exports=V(Z);function x(t,e=200){return new Response(JSON.stringify(t),{status:e,headers:{"Content-Type":"application/json"}})}function U(t,e){return x({error:t},e)}function D(t){let e=null;function n(){return e||(e=(async()=>{let{getApp:a}=await import("@murumets-ee/core"),{createSettingsClient:l}=await Promise.resolve().then(()=>(_(),R)),g=a();return l(t,{app:g})})()),e}async function o(a,l){let g=await n(),d=new URL(a.url).searchParams.get("locale")??void 0,m=await g.getAll(d?{locale:d}:void 0);return x(m)}async function s(a,{user:l,audit:g}){let u=await n(),d=await a.json(),{values:m,locale:h}=d;return!m||typeof m!="object"?U('Body must contain "values" object',400):(await u.setMany(m,h?{locale:h}:void 0),g?.({action:"settings.update",entityType:"settings",userId:l.id,userName:l.name,changes:{fields:m},metadata:{namespace:t.namespace,...h?{locale:h}:{}}}),x({success:!0}))}return{prefix:"settings",resource:"settings",actions:["view","update"],handlers:{GET:o,PATCH:s}}}0&&(module.exports={settingsRoutes});
package/dist/admin.d.cts DELETED
@@ -1,100 +0,0 @@
1
- import { AdminRoute } from '@murumets-ee/core';
2
- import { ZodType } from 'zod';
3
-
4
- /**
5
- * Setting configuration types and compile-time type inference.
6
- *
7
- * Design mirrors the entity field system:
8
- * - Config interfaces define what each setting type accepts
9
- * - SettingToTS maps a single config to its TypeScript type
10
- * - InferSettingValue adds null awareness based on `default` presence
11
- * - InferSettingsMap maps an entire schema to a typed record
12
- */
13
-
14
- interface BaseSettingConfig {
15
- /** Human-readable label for admin UI */
16
- label?: string;
17
- /** Description / help text */
18
- description?: string;
19
- /** If true, this setting can have per-locale values (mirrors entity translatable pattern) */
20
- translatable?: boolean;
21
- }
22
- interface TextSettingConfig extends BaseSettingConfig {
23
- type: 'text';
24
- default?: string;
25
- maxLength?: number;
26
- minLength?: number;
27
- pattern?: RegExp;
28
- }
29
- interface NumberSettingConfig extends BaseSettingConfig {
30
- type: 'number';
31
- default?: number;
32
- min?: number;
33
- max?: number;
34
- integer?: boolean;
35
- }
36
- interface BooleanSettingConfig extends BaseSettingConfig {
37
- type: 'boolean';
38
- default?: boolean;
39
- }
40
- interface SelectSettingConfig<O extends readonly string[] = readonly string[]> extends BaseSettingConfig {
41
- type: 'select';
42
- options: O;
43
- default?: O[number];
44
- }
45
- interface JsonSettingConfig<T = unknown> extends BaseSettingConfig {
46
- type: 'json';
47
- default?: T;
48
- /** Optional Zod schema for validation. If provided, values are validated on set. */
49
- schema?: ZodType<T>;
50
- }
51
- interface MediaSettingConfig extends BaseSettingConfig {
52
- type: 'media';
53
- accept?: string[];
54
- }
55
- type SettingConfig = TextSettingConfig | NumberSettingConfig | BooleanSettingConfig | SelectSettingConfig | JsonSettingConfig | MediaSettingConfig;
56
- type SettingScope = 'global' | 'team' | 'user';
57
- interface SettingsDefinition<S extends Record<string, SettingConfig> = Record<string, SettingConfig>> {
58
- /** Unique namespace for this settings group */
59
- namespace: string;
60
- /** Default scope for these settings */
61
- scope: SettingScope;
62
- /** Setting schema (the shape) */
63
- schema: S;
64
- /** Human-readable label for admin UI */
65
- label?: string;
66
- }
67
-
68
- /**
69
- * Settings admin routes for the centralized admin API handler.
70
- *
71
- * Provides get/update operations for typed settings.
72
- * All auth, CSRF, and role checks are handled by the parent handler.
73
- * Settings mutations require admin role (not editor).
74
- *
75
- * @example
76
- * ```typescript
77
- * import { createAdminApiHandler } from '@murumets-ee/admin-ui/server'
78
- * import { settingsRoutes } from '@murumets-ee/settings/admin'
79
- * import { siteSettings } from '@/settings/site'
80
- *
81
- * const handler = createAdminApiHandler({
82
- * authenticate: async (req) => { ... },
83
- * entities: [Article],
84
- * routes: [settingsRoutes(siteSettings)],
85
- * })
86
- * ```
87
- */
88
-
89
- /**
90
- * Create admin API routes for settings management.
91
- *
92
- * Routes:
93
- * - `GET /api/admin/settings` — Get all settings (query: `?locale=`)
94
- * - `PATCH /api/admin/settings` — Update settings (JSON body: `{ values, locale? }`)
95
- *
96
- * @param definition - The settings definition (created by defineSettings)
97
- */
98
- declare function settingsRoutes<S extends Record<string, SettingConfig>>(definition: SettingsDefinition<S>): AdminRoute;
99
-
100
- export { settingsRoutes };
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var C=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var T=(t,e)=>{for(var n in e)C(t,n,{get:e[n],enumerable:!0})},I=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!O.call(t,s)&&s!==n&&C(t,s,{get:()=>e[s],enumerable:!(o=v(e,s))||o.enumerable});return t};var L=t=>I(C({},"__esModule",{value:!0}),t);var _={};T(_,{DEFAULT_LOCALE:()=>f,GLOBAL_SCOPE_ID:()=>m,SettingsClient:()=>S,createSettingsClient:()=>w,defineSettings:()=>b,setting:()=>h});module.exports=L(_);var U=require("server-only");var h={text:t=>({type:"text",...t}),number:t=>({type:"number",...t}),boolean:t=>({type:"boolean",...t}),select:t=>({type:"select",...t}),json:t=>({type:"json",...t}),media:t=>({type:"media",...t})};var l=require("drizzle-orm");var a=require("drizzle-orm/pg-core"),i=(0,a.pgTable)("toolkit_settings",{id:(0,a.uuid)("id").primaryKey().defaultRandom(),namespace:(0,a.varchar)("namespace",{length:100}).notNull(),scope:(0,a.varchar)("scope",{length:20}).notNull().default("global"),scopeId:(0,a.varchar)("scope_id",{length:100}).notNull().default("__global__"),key:(0,a.varchar)("key",{length:255}).notNull(),locale:(0,a.varchar)("locale",{length:10}).notNull().default("_default"),value:(0,a.jsonb)("value"),updatedAt:(0,a.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow(),updatedBy:(0,a.uuid)("updated_by")},t=>({uniqueSetting:(0,a.unique)().on(t.namespace,t.scope,t.scopeId,t.key,t.locale)})),A=(0,a.pgTable)("toolkit_view_state",{id:(0,a.uuid)("id").primaryKey().defaultRandom(),userId:(0,a.uuid)("user_id").notNull(),viewKey:(0,a.varchar)("view_key",{length:255}).notNull(),state:(0,a.jsonb)("state").notNull(),expiresAt:(0,a.timestamp)("expires_at",{withTimezone:!0}),updatedAt:(0,a.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow()},t=>({uniqueUserView:(0,a.unique)().on(t.userId,t.viewKey)}));var m="__global__",f="_default";var u=require("zod");function D(t){switch(t.type){case"text":{let e=u.z.string();return t.maxLength&&(e=e.max(t.maxLength)),t.minLength&&(e=e.min(t.minLength)),t.pattern&&(e=e.regex(t.pattern)),e}case"number":{let e=u.z.number();return t.integer&&(e=e.int()),t.min!==void 0&&(e=e.min(t.min)),t.max!==void 0&&(e=e.max(t.max)),e}case"boolean":return u.z.boolean();case"select":return u.z.enum(t.options);case"json":return t.schema??u.z.unknown();case"media":return u.z.string().uuid();default:return u.z.unknown()}}function y(t){let e={};for(let[n,o]of Object.entries(t.schema)){let s=D(o);"default"in o&&o.default!==void 0||(s=s.nullable()),e[n]=s}return e}var S=class{definition;db;logger;scope;scopeId;validators;constructor(e,n){if(typeof window<"u")throw new Error("SettingsClient cannot be used in browser code.");if(this.definition=e,this.db=n.db,this.logger=n.logger,this.scope=n.scope??e.scope,this.scopeId=n.scopeId??m,(this.scope==="team"||this.scope==="user")&&!n.scopeId)throw new Error(`scopeId is required for ${this.scope}-scoped settings (namespace: ${e.namespace})`);this.validators=y(e)}async get(e,n){let o=this.definition.schema[e],s=o?.translatable&&n?.locale?n.locale:null;if(this.logger?.debug({namespace:this.definition.namespace,key:e,locale:s},"Getting setting"),s){let r=await this.db.select({locale:i.locale,value:i.value}).from(i).where((0,l.and)(...this.baseWhere(),(0,l.eq)(i.key,e),(0,l.or)((0,l.eq)(i.locale,s),(0,l.eq)(i.locale,f)))),g=r.find(d=>d.locale===s),p=r.find(d=>d.locale===f),c=g??p;if(c&&c.value!==void 0&&c.value!==null)return c.value}else{let r=await this.db.select({value:i.value}).from(i).where(this.whereClause(e)).limit(1);if(r.length>0&&r[0].value!==void 0&&r[0].value!==null)return r[0].value}return o&&"default"in o&&o.default!==void 0?o.default:null}async getAll(e){let n=e?.locale??null;this.logger?.debug({namespace:this.definition.namespace,locale:n},"Getting all settings");let o;n?o=await this.db.select({key:i.key,locale:i.locale,value:i.value}).from(i).where((0,l.and)(...this.baseWhere(),(0,l.or)((0,l.eq)(i.locale,f),(0,l.eq)(i.locale,n)))):o=await this.db.select({key:i.key,locale:i.locale,value:i.value}).from(i).where((0,l.and)(...this.baseWhere(),(0,l.eq)(i.locale,f)));let s=new Map;for(let g of o){let p=s.get(g.key)??{};g.locale===f?p.default=g.value:p.locale=g.value,s.set(g.key,p)}let r={};for(let[g,p]of Object.entries(this.definition.schema)){let c=s.get(g),d;p.translatable&&n&&c?.locale!==void 0&&c?.locale!==null?d=c.locale:c?.default!==void 0&&c?.default!==null&&(d=c.default),d!==void 0?r[g]=d:"default"in p&&p.default!==void 0?r[g]=p.default:r[g]=null}return r}async set(e,n,o){let s=this.resolveLocale(e,o);if(this.logger?.info({namespace:this.definition.namespace,key:e,locale:s},"Setting value"),!(e in this.definition.schema))throw new Error(`Unknown setting key '${e}' in namespace '${this.definition.namespace}'`);let r=this.validators[e];r&&r.parse(n),await this.upsert(e,n,s)}async setMany(e,n){this.logger?.info({namespace:this.definition.namespace,keys:Object.keys(e),locale:n?.locale},"Setting multiple values");for(let[o,s]of Object.entries(e)){if(!(o in this.definition.schema))throw new Error(`Unknown setting key '${o}' in namespace '${this.definition.namespace}'`);let r=this.validators[o];r&&s!==void 0&&r.parse(s)}await this.db.transaction(async o=>{for(let[s,r]of Object.entries(e)){if(r===void 0)continue;let g=this.resolveLocale(s,n);await o.insert(i).values({namespace:this.definition.namespace,scope:this.scope,scopeId:this.scopeId,key:s,locale:g,value:r,updatedAt:new Date}).onConflictDoUpdate({target:[i.namespace,i.scope,i.scopeId,i.key,i.locale],set:{value:r,updatedAt:new Date}})}})}async delete(e,n){let o=this.resolveLocale(e,n);this.logger?.info({namespace:this.definition.namespace,key:e,locale:o},"Deleting setting"),await this.db.delete(i).where(this.whereClause(e,o))}async has(e,n){let o=this.resolveLocale(e,n);return(await this.db.select({key:i.key}).from(i).where(this.whereClause(e,o)).limit(1)).length>0}resolveLocale(e,n){return this.definition.schema[e]?.translatable&&n?.locale?n.locale:f}baseWhere(){return[(0,l.eq)(i.namespace,this.definition.namespace),(0,l.eq)(i.scope,this.scope),(0,l.eq)(i.scopeId,this.scopeId)]}whereClause(e,n=f){return(0,l.and)(...this.baseWhere(),(0,l.eq)(i.key,e),(0,l.eq)(i.locale,n))}async upsert(e,n,o){await this.db.insert(i).values({namespace:this.definition.namespace,scope:this.scope,scopeId:this.scopeId,key:e,locale:o,value:n,updatedAt:new Date}).onConflictDoUpdate({target:[i.namespace,i.scope,i.scopeId,i.key,i.locale],set:{value:n,updatedAt:new Date}})}};var x=require("@murumets-ee/core");function w(t,e){let n=e?.app??(0,x.getApp)();return new S(t,{db:n.db.readWrite,logger:n.logger.child({settings:t.namespace}),scope:e?.scope,scopeId:e?.scopeId})}function b(t){if(!t.namespace)throw new Error("Settings namespace is required");if(!t.schema||Object.keys(t.schema).length===0)throw new Error("Settings schema must have at least one setting");return t}0&&(module.exports={DEFAULT_LOCALE,GLOBAL_SCOPE_ID,SettingsClient,createSettingsClient,defineSettings,setting});
package/dist/plugin.cjs DELETED
@@ -1,24 +0,0 @@
1
- "use strict";var c=Object.create;var n=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var w=(e,a)=>()=>(e&&(a=e(e=0)),a);var u=(e,a)=>{for(var o in a)n(e,o,{get:a[o],enumerable:!0})},s=(e,a,o,i)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of g(a))!h.call(e,l)&&l!==o&&n(e,l,{get:()=>a[l],enumerable:!(i=m(a,l))||i.enumerable});return e};var y=(e,a,o)=>(o=e!=null?c(_(e)):{},s(a||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),f=e=>s(n({},"__esModule",{value:!0}),e);var r={};u(r,{toolkitSettings:()=>N,toolkitViewState:()=>k});var t,N,k,p=w(()=>{"use strict";t=require("drizzle-orm/pg-core"),N=(0,t.pgTable)("toolkit_settings",{id:(0,t.uuid)("id").primaryKey().defaultRandom(),namespace:(0,t.varchar)("namespace",{length:100}).notNull(),scope:(0,t.varchar)("scope",{length:20}).notNull().default("global"),scopeId:(0,t.varchar)("scope_id",{length:100}).notNull().default("__global__"),key:(0,t.varchar)("key",{length:255}).notNull(),locale:(0,t.varchar)("locale",{length:10}).notNull().default("_default"),value:(0,t.jsonb)("value"),updatedAt:(0,t.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow(),updatedBy:(0,t.uuid)("updated_by")},e=>({uniqueSetting:(0,t.unique)().on(e.namespace,e.scope,e.scopeId,e.key,e.locale)})),k=(0,t.pgTable)("toolkit_view_state",{id:(0,t.uuid)("id").primaryKey().defaultRandom(),userId:(0,t.uuid)("user_id").notNull(),viewKey:(0,t.varchar)("view_key",{length:255}).notNull(),state:(0,t.jsonb)("state").notNull(),expiresAt:(0,t.timestamp)("expires_at",{withTimezone:!0}),updatedAt:(0,t.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow()},e=>({uniqueUserView:(0,t.unique)().on(e.userId,e.viewKey)}))});var b={};u(b,{settings:()=>v});module.exports=f(b);function d(){return`export const toolkitSettings = pgTable('toolkit_settings', {
2
- id: uuid('id').primaryKey().defaultRandom(),
3
- namespace: varchar('namespace', { length: 100 }).notNull(),
4
- scope: varchar('scope', { length: 20 }).notNull().default('global'),
5
- scopeId: varchar('scope_id', { length: 100 }).notNull().default('__global__'),
6
- key: varchar('key', { length: 255 }).notNull(),
7
- locale: varchar('locale', { length: 10 }).notNull().default('_default'),
8
- value: jsonb('value'),
9
- updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
10
- updatedBy: uuid('updated_by'),
11
- }, (table) => ({
12
- uniqueSetting: unique().on(table.namespace, table.scope, table.scopeId, table.key, table.locale),
13
- }))
14
-
15
- export const toolkitViewState = pgTable('toolkit_view_state', {
16
- id: uuid('id').primaryKey().defaultRandom(),
17
- userId: uuid('user_id').notNull(),
18
- viewKey: varchar('view_key', { length: 255 }).notNull(),
19
- state: jsonb('state').notNull(),
20
- expiresAt: timestamp('expires_at', { withTimezone: true }),
21
- updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
22
- }, (table) => ({
23
- uniqueUserView: unique().on(table.userId, table.viewKey),
24
- }))`}function v(){return{name:"@murumets-ee/settings",schemaCode:d(),init:async e=>{let{schemaRegistry:a}=await import("@murumets-ee/db"),{toolkitSettings:o,toolkitViewState:i}=await Promise.resolve().then(()=>(p(),r));a.has("toolkit_settings")||a.register("toolkit_settings",o),a.has("toolkit_view_state")||a.register("toolkit_view_state",i),e.logger.info("Settings plugin initialized")}}}0&&(module.exports={settings});
package/dist/schema.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var a=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var p=(t,l)=>{for(var u in l)a(t,u,{get:l[u],enumerable:!0})},r=(t,l,u,i)=>{if(l&&typeof l=="object"||typeof l=="function")for(let o of d(l))!s.call(t,o)&&o!==u&&a(t,o,{get:()=>l[o],enumerable:!(i=n(l,o))||i.enumerable});return t};var c=t=>r(a({},"__esModule",{value:!0}),t);var g={};p(g,{toolkitSettings:()=>_,toolkitViewState:()=>m});module.exports=c(g);var e=require("drizzle-orm/pg-core"),_=(0,e.pgTable)("toolkit_settings",{id:(0,e.uuid)("id").primaryKey().defaultRandom(),namespace:(0,e.varchar)("namespace",{length:100}).notNull(),scope:(0,e.varchar)("scope",{length:20}).notNull().default("global"),scopeId:(0,e.varchar)("scope_id",{length:100}).notNull().default("__global__"),key:(0,e.varchar)("key",{length:255}).notNull(),locale:(0,e.varchar)("locale",{length:10}).notNull().default("_default"),value:(0,e.jsonb)("value"),updatedAt:(0,e.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow(),updatedBy:(0,e.uuid)("updated_by")},t=>({uniqueSetting:(0,e.unique)().on(t.namespace,t.scope,t.scopeId,t.key,t.locale)})),m=(0,e.pgTable)("toolkit_view_state",{id:(0,e.uuid)("id").primaryKey().defaultRandom(),userId:(0,e.uuid)("user_id").notNull(),viewKey:(0,e.varchar)("view_key",{length:255}).notNull(),state:(0,e.jsonb)("state").notNull(),expiresAt:(0,e.timestamp)("expires_at",{withTimezone:!0}),updatedAt:(0,e.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow()},t=>({uniqueUserView:(0,e.unique)().on(t.userId,t.viewKey)}));0&&(module.exports={toolkitSettings,toolkitViewState});
@@ -1 +0,0 @@
1
- "use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var c=(r,e)=>{for(var i in e)d(r,i,{get:e[i],enumerable:!0})},h=(r,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of p(e))!w.call(r,a)&&a!==i&&d(r,a,{get:()=>e[a],enumerable:!(o=g(e,a))||o.enumerable});return r};var m=r=>h(d({},"__esModule",{value:!0}),r);var b={};c(b,{ViewStateClient:()=>l,createViewStateClient:()=>I});module.exports=m(b);var n=require("drizzle-orm");var t=require("drizzle-orm/pg-core"),x=(0,t.pgTable)("toolkit_settings",{id:(0,t.uuid)("id").primaryKey().defaultRandom(),namespace:(0,t.varchar)("namespace",{length:100}).notNull(),scope:(0,t.varchar)("scope",{length:20}).notNull().default("global"),scopeId:(0,t.varchar)("scope_id",{length:100}).notNull().default("__global__"),key:(0,t.varchar)("key",{length:255}).notNull(),locale:(0,t.varchar)("locale",{length:10}).notNull().default("_default"),value:(0,t.jsonb)("value"),updatedAt:(0,t.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow(),updatedBy:(0,t.uuid)("updated_by")},r=>({uniqueSetting:(0,t.unique)().on(r.namespace,r.scope,r.scopeId,r.key,r.locale)})),s=(0,t.pgTable)("toolkit_view_state",{id:(0,t.uuid)("id").primaryKey().defaultRandom(),userId:(0,t.uuid)("user_id").notNull(),viewKey:(0,t.varchar)("view_key",{length:255}).notNull(),state:(0,t.jsonb)("state").notNull(),expiresAt:(0,t.timestamp)("expires_at",{withTimezone:!0}),updatedAt:(0,t.timestamp)("updated_at",{withTimezone:!0}).notNull().defaultNow()},r=>({uniqueUserView:(0,t.unique)().on(r.userId,r.viewKey)}));var f=720*60*60,l=class{db;userId;logger;defaultTtl;constructor(e){if(typeof window<"u")throw new Error("ViewStateClient cannot be used in browser code.");this.db=e.db,this.userId=e.userId,this.logger=e.logger,this.defaultTtl=e.defaultTtl??f}async save(e,i,o){this.logger?.debug({userId:this.userId,viewKey:e},"Saving view state");let a=o?.ttl??this.defaultTtl,u=new Date(Date.now()+a*1e3);await this.db.insert(s).values({userId:this.userId,viewKey:e,state:i,expiresAt:u,updatedAt:new Date}).onConflictDoUpdate({target:[s.userId,s.viewKey],set:{state:i,expiresAt:u,updatedAt:new Date}})}async load(e){this.logger?.debug({userId:this.userId,viewKey:e},"Loading view state");let i=await this.db.select({state:s.state,expiresAt:s.expiresAt}).from(s).where((0,n.and)((0,n.eq)(s.userId,this.userId),(0,n.eq)(s.viewKey,e))).limit(1);if(i.length===0)return null;let o=i[0];return o.expiresAt&&o.expiresAt<new Date?(await this.clear(e),null):o.state}async clear(e){this.logger?.debug({userId:this.userId,viewKey:e},"Clearing view state"),await this.db.delete(s).where((0,n.and)((0,n.eq)(s.userId,this.userId),(0,n.eq)(s.viewKey,e)))}async clearExpired(){this.logger?.info("Clearing expired view state entries");let i=(await this.db.delete(s).where((0,n.lt)(s.expiresAt,new Date)).returning({id:s.id})).length;return this.logger?.info({count:i},"Expired view state entries cleared"),i}};function I(r){return new l(r)}0&&(module.exports={ViewStateClient,createViewStateClient});