@objectstack/platform-objects 4.0.5 → 4.1.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.
Files changed (57) hide show
  1. package/dist/apps/index.d.mts +16 -48
  2. package/dist/apps/index.d.ts +16 -48
  3. package/dist/apps/index.js +139 -217
  4. package/dist/apps/index.js.map +1 -1
  5. package/dist/apps/index.mjs +140 -212
  6. package/dist/apps/index.mjs.map +1 -1
  7. package/dist/audit/index.d.mts +38990 -51
  8. package/dist/audit/index.d.ts +38990 -51
  9. package/dist/audit/index.js +1428 -0
  10. package/dist/audit/index.js.map +1 -1
  11. package/dist/audit/index.mjs +1417 -1
  12. package/dist/audit/index.mjs.map +1 -1
  13. package/dist/identity/index.d.mts +14869 -2802
  14. package/dist/identity/index.d.ts +14869 -2802
  15. package/dist/identity/index.js +1090 -6
  16. package/dist/identity/index.js.map +1 -1
  17. package/dist/identity/index.mjs +1089 -7
  18. package/dist/identity/index.mjs.map +1 -1
  19. package/dist/index.d.mts +8 -7
  20. package/dist/index.d.ts +8 -7
  21. package/dist/index.js +3652 -1482
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +3633 -1465
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/integration/index.d.mts +2905 -0
  26. package/dist/integration/index.d.ts +2905 -0
  27. package/dist/integration/index.js +140 -0
  28. package/dist/integration/index.js.map +1 -0
  29. package/dist/integration/index.mjs +138 -0
  30. package/dist/integration/index.mjs.map +1 -0
  31. package/dist/metadata/index.d.mts +577 -21181
  32. package/dist/metadata/index.d.ts +577 -21181
  33. package/dist/metadata/index.js +29 -619
  34. package/dist/metadata/index.js.map +1 -1
  35. package/dist/metadata/index.mjs +30 -615
  36. package/dist/metadata/index.mjs.map +1 -1
  37. package/dist/security/index.d.mts +7278 -46
  38. package/dist/security/index.d.ts +7278 -46
  39. package/dist/security/index.js +540 -0
  40. package/dist/security/index.js.map +1 -1
  41. package/dist/security/index.mjs +539 -1
  42. package/dist/security/index.mjs.map +1 -1
  43. package/dist/system/index.d.mts +8409 -0
  44. package/dist/system/index.d.ts +8409 -0
  45. package/dist/system/index.js +395 -0
  46. package/dist/system/index.js.map +1 -0
  47. package/dist/system/index.mjs +391 -0
  48. package/dist/system/index.mjs.map +1 -0
  49. package/package.json +13 -8
  50. package/dist/tenant/index.d.mts +0 -18464
  51. package/dist/tenant/index.d.ts +0 -18464
  52. package/dist/tenant/index.js +0 -741
  53. package/dist/tenant/index.js.map +0 -1
  54. package/dist/tenant/index.mjs +0 -733
  55. package/dist/tenant/index.mjs.map +0 -1
  56. /package/dist/{state-machine.zod-BFg-VE0M.d-Ek3_yo9P.d.mts → state-machine.zod-BNanU03M.d-Ek3_yo9P.d.mts} +0 -0
  57. /package/dist/{state-machine.zod-BFg-VE0M.d-Ek3_yo9P.d.ts → state-machine.zod-BNanU03M.d-Ek3_yo9P.d.ts} +0 -0
@@ -0,0 +1,391 @@
1
+ import { ObjectSchema, Field } from '@objectstack/spec/data';
2
+
3
+ // src/system/sys-setting.object.ts
4
+ var SysSetting = ObjectSchema.create({
5
+ name: "sys_setting",
6
+ label: "Setting",
7
+ pluralLabel: "Settings",
8
+ icon: "sliders",
9
+ isSystem: true,
10
+ managedBy: "system",
11
+ description: "Generic K/V store backing the SettingsManifest contract.",
12
+ displayNameField: "key",
13
+ titleFormat: "{namespace}.{key}",
14
+ compactLayout: ["namespace", "key", "scope", "updated_at"],
15
+ listViews: {
16
+ by_namespace: {
17
+ type: "grid",
18
+ name: "by_namespace",
19
+ label: "By Namespace",
20
+ data: { provider: "object", object: "sys_setting" },
21
+ columns: ["namespace", "key", "scope", "encrypted", "updated_by", "updated_at"],
22
+ sort: [{ field: "namespace", order: "asc" }, { field: "key", order: "asc" }],
23
+ grouping: { fields: [{ field: "namespace", order: "asc", collapsed: false }] },
24
+ pagination: { pageSize: 200 }
25
+ },
26
+ tenant_only: {
27
+ type: "grid",
28
+ name: "tenant_only",
29
+ label: "Tenant",
30
+ data: { provider: "object", object: "sys_setting" },
31
+ columns: ["namespace", "key", "encrypted", "updated_by", "updated_at"],
32
+ filter: [{ field: "scope", operator: "equals", value: "tenant" }],
33
+ sort: [{ field: "namespace", order: "asc" }, { field: "key", order: "asc" }],
34
+ pagination: { pageSize: 200 }
35
+ },
36
+ user_only: {
37
+ type: "grid",
38
+ name: "user_only",
39
+ label: "User",
40
+ data: { provider: "object", object: "sys_setting" },
41
+ columns: ["user_id", "namespace", "key", "updated_at"],
42
+ filter: [{ field: "scope", operator: "equals", value: "user" }],
43
+ sort: [{ field: "user_id", order: "asc" }, { field: "namespace", order: "asc" }],
44
+ pagination: { pageSize: 200 }
45
+ },
46
+ all_settings: {
47
+ type: "grid",
48
+ name: "all_settings",
49
+ label: "All",
50
+ data: { provider: "object", object: "sys_setting" },
51
+ columns: ["namespace", "key", "scope", "user_id", "encrypted", "updated_at"],
52
+ sort: [{ field: "updated_at", order: "desc" }],
53
+ pagination: { pageSize: 100 }
54
+ }
55
+ },
56
+ fields: {
57
+ id: Field.text({
58
+ label: "Setting ID",
59
+ required: true,
60
+ readonly: true
61
+ }),
62
+ created_at: Field.datetime({
63
+ label: "Created At",
64
+ defaultValue: "NOW()",
65
+ readonly: true
66
+ }),
67
+ updated_at: Field.datetime({
68
+ label: "Updated At",
69
+ defaultValue: "NOW()",
70
+ readonly: true
71
+ }),
72
+ namespace: Field.text({
73
+ label: "Namespace",
74
+ required: true,
75
+ maxLength: 64,
76
+ description: "Manifest namespace (e.g. mail, branding, feature_flags)."
77
+ }),
78
+ key: Field.text({
79
+ label: "Key",
80
+ required: true,
81
+ maxLength: 128,
82
+ description: "Specifier key inside the namespace (snake_case)."
83
+ }),
84
+ scope: Field.select(
85
+ [
86
+ { label: "Global", value: "global" },
87
+ { label: "Tenant", value: "tenant" },
88
+ { label: "User", value: "user" },
89
+ { label: "Runtime", value: "runtime" }
90
+ ],
91
+ {
92
+ label: "Scope",
93
+ required: true,
94
+ defaultValue: "tenant",
95
+ description: "Which layer of the config-resolution hierarchy this row belongs to."
96
+ }
97
+ ),
98
+ user_id: Field.lookup("sys_user", {
99
+ label: "User",
100
+ description: "Owning user when scope=user; null otherwise."
101
+ }),
102
+ value: Field.json({
103
+ label: "Value",
104
+ description: "JSON-encoded value. Null when encrypted=true (see value_enc)."
105
+ }),
106
+ encrypted: Field.boolean({
107
+ label: "Encrypted",
108
+ defaultValue: false,
109
+ description: "When true, the value is stored encrypted-at-rest in value_enc; value column is null."
110
+ }),
111
+ locked: Field.boolean({
112
+ label: "Locked",
113
+ defaultValue: false,
114
+ description: "When true, lower-scope rows cannot override this value; writes against lower scopes return 409. Used by platform administrators to pin a global value for all tenants (Phase 2 cascade)."
115
+ }),
116
+ locked_reason: Field.text({
117
+ label: "Lock Reason",
118
+ description: "Human-readable explanation surfaced in the UI tooltip when locked=true."
119
+ }),
120
+ value_enc: Field.text({
121
+ label: "Encrypted Value",
122
+ readonly: true,
123
+ description: "Ciphertext payload (KMS-wrapped). Set only when encrypted=true."
124
+ }),
125
+ updated_by: Field.lookup("sys_user", {
126
+ label: "Updated By",
127
+ readonly: true,
128
+ description: "Last actor who wrote this row via SettingsService.set()."
129
+ })
130
+ },
131
+ indexes: [
132
+ // Primary lookup path: (namespace, key, scope, user_id?) is what
133
+ // SettingsService.get hits on every resolve. The composite UNIQUE
134
+ // covers both the row-identity constraint and the read path.
135
+ { fields: ["namespace", "key", "scope", "user_id"], unique: true },
136
+ // Common range read: full namespace dump for SettingsService.getNamespace.
137
+ { fields: ["namespace", "scope"], unique: false },
138
+ // Per-user listing on the user-prefs scope.
139
+ { fields: ["user_id", "namespace"], unique: false }
140
+ ],
141
+ enable: {
142
+ // History on settings is opt-in per namespace (handled at service
143
+ // layer when needed) to avoid bloating sys_history with churn from
144
+ // feature flags and similar high-frequency toggles.
145
+ trackHistory: false,
146
+ searchable: false,
147
+ apiEnabled: true,
148
+ // Direct data API exposed for the admin grid view, but writes from
149
+ // the UI MUST go through /api/settings/:namespace so the resolver
150
+ // and audit hooks fire. The grid is diagnostic-only.
151
+ apiMethods: ["get", "list"],
152
+ trash: false,
153
+ mru: false
154
+ }
155
+ });
156
+ var SysSecret = ObjectSchema.create({
157
+ name: "sys_secret",
158
+ label: "Secret",
159
+ pluralLabel: "Secrets",
160
+ icon: "key",
161
+ isSystem: true,
162
+ managedBy: "system",
163
+ description: "Cipher store referenced by sys_setting handles. Never holds plaintext.",
164
+ scope: "tenant",
165
+ compactLayout: ["namespace", "key", "kms_key_id", "version", "rotated_at"],
166
+ defaultViewName: "all",
167
+ views: {
168
+ all: {
169
+ type: "list",
170
+ name: "all",
171
+ label: "All Secrets",
172
+ columns: ["namespace", "key", "kms_key_id", "version", "rotated_at", "created_at"]
173
+ }
174
+ },
175
+ fields: {
176
+ id: Field.text({
177
+ label: "ID",
178
+ readonly: true,
179
+ description: "Opaque handle referenced by `sys_setting.value_enc`."
180
+ }),
181
+ created_at: Field.datetime({
182
+ label: "Created At",
183
+ readonly: true,
184
+ description: "When the cipher was first written."
185
+ }),
186
+ rotated_at: Field.datetime({
187
+ label: "Rotated At",
188
+ readonly: true,
189
+ description: "When the cipher was last re-wrapped under a new KMS key."
190
+ }),
191
+ /**
192
+ * Namespace/key duplicated from `sys_setting` for forensic
193
+ * convenience — lets operators answer "which secret backs
194
+ * mail.api_key right now?" without joining the K/V table.
195
+ * The authoritative link is `sys_setting.value_enc → sys_secret.id`.
196
+ */
197
+ namespace: Field.text({
198
+ label: "Namespace",
199
+ required: true,
200
+ maxLength: 128,
201
+ description: "Settings namespace this secret belongs to."
202
+ }),
203
+ key: Field.text({
204
+ label: "Key",
205
+ required: true,
206
+ maxLength: 128,
207
+ description: "Specifier key within the namespace."
208
+ }),
209
+ /** Identifier of the KMS key used to wrap `ciphertext`. */
210
+ kms_key_id: Field.text({
211
+ label: "KMS Key ID",
212
+ required: true,
213
+ maxLength: 256,
214
+ description: "External KMS handle (ARN, GCP resource id, or `local`)."
215
+ }),
216
+ /** Algorithm tag (e.g. `aes-256-gcm`). Used by the provider on decrypt. */
217
+ alg: Field.text({
218
+ label: "Algorithm",
219
+ required: true,
220
+ defaultValue: "aes-256-gcm",
221
+ maxLength: 64,
222
+ description: "Cipher/AEAD algorithm tag."
223
+ }),
224
+ /** Wrapping version — bumps on every rotate(). */
225
+ version: Field.number({
226
+ label: "Version",
227
+ required: true,
228
+ defaultValue: 1,
229
+ description: "Bumps each time rotateKey() re-wraps this row."
230
+ }),
231
+ ciphertext: Field.text({
232
+ label: "Ciphertext",
233
+ required: true,
234
+ readonly: true,
235
+ description: "Provider-encoded ciphertext blob (base64 / JSON). Implementation-defined; only the matching ICryptoProvider can read it."
236
+ })
237
+ },
238
+ indexes: [
239
+ // Operators frequently look up by (namespace, key) to inspect or rotate.
240
+ { fields: ["namespace", "key"], unique: false },
241
+ { fields: ["kms_key_id"], unique: false }
242
+ ],
243
+ enable: {
244
+ trackHistory: false,
245
+ // rotation events are recorded by sys_setting_audit
246
+ audit: true
247
+ }
248
+ });
249
+ var SysSettingAudit = ObjectSchema.create({
250
+ name: "sys_setting_audit",
251
+ label: "Setting Audit Entry",
252
+ pluralLabel: "Setting Audit",
253
+ icon: "history",
254
+ isSystem: true,
255
+ managedBy: "system",
256
+ description: "Append-only audit trail for SettingsService mutations.",
257
+ scope: "tenant",
258
+ compactLayout: ["namespace", "key", "scope", "action", "actor_id", "created_at"],
259
+ defaultViewName: "recent",
260
+ views: {
261
+ recent: {
262
+ type: "list",
263
+ name: "recent",
264
+ label: "Recent",
265
+ columns: ["created_at", "namespace", "key", "scope", "action", "actor_id", "source"],
266
+ sort: [{ field: "created_at", order: "desc" }]
267
+ }
268
+ },
269
+ fields: {
270
+ id: Field.text({
271
+ label: "ID",
272
+ readonly: true
273
+ }),
274
+ created_at: Field.datetime({
275
+ label: "Created At",
276
+ readonly: true,
277
+ description: "When the mutation was recorded."
278
+ }),
279
+ namespace: Field.text({
280
+ label: "Namespace",
281
+ required: true,
282
+ maxLength: 128
283
+ }),
284
+ key: Field.text({
285
+ label: "Key",
286
+ required: true,
287
+ maxLength: 128
288
+ }),
289
+ scope: Field.select(
290
+ [
291
+ { label: "Global", value: "global" },
292
+ { label: "Tenant", value: "tenant" },
293
+ { label: "User", value: "user" }
294
+ ],
295
+ {
296
+ label: "Scope",
297
+ required: true,
298
+ description: "Cascade layer the row was written to."
299
+ }
300
+ ),
301
+ action: Field.select(
302
+ [
303
+ { label: "Set", value: "set" },
304
+ { label: "Reset", value: "reset" },
305
+ { label: "Lock", value: "lock" },
306
+ { label: "Unlock", value: "unlock" },
307
+ { label: "Rotate", value: "rotate" }
308
+ ],
309
+ {
310
+ label: "Action",
311
+ required: true,
312
+ description: "Mutation kind."
313
+ }
314
+ ),
315
+ actor_id: Field.lookup("sys_user", {
316
+ label: "Actor",
317
+ description: "User who performed the mutation; null for system jobs."
318
+ }),
319
+ /**
320
+ * Where the write originated. Lets operators distinguish admin UI
321
+ * activity from migration jobs and bulk imports during incident
322
+ * analysis.
323
+ */
324
+ source: Field.select(
325
+ [
326
+ { label: "UI", value: "ui" },
327
+ { label: "API", value: "api" },
328
+ { label: "Migration", value: "migration" },
329
+ { label: "Import", value: "import" },
330
+ { label: "System", value: "system" }
331
+ ],
332
+ {
333
+ label: "Source",
334
+ required: true,
335
+ defaultValue: "api",
336
+ description: "Mutation entry-point."
337
+ }
338
+ ),
339
+ /** Optional free-text reason (Phase 3+ change-management hook). */
340
+ reason: Field.text({
341
+ label: "Reason",
342
+ description: "Free-text justification provided by the actor (optional)."
343
+ }),
344
+ /**
345
+ * Content digest of the previous value. Never the plaintext —
346
+ * lets operators detect duplicate writes without leaking secrets.
347
+ * Format: hex SHA-256 of the canonicalised JSON, or null when
348
+ * the previous value was unset.
349
+ */
350
+ old_hash: Field.text({
351
+ label: "Old Hash",
352
+ readonly: true,
353
+ maxLength: 128,
354
+ description: "SHA-256 of the previous value (canonicalised). Null when previously unset."
355
+ }),
356
+ /** Content digest of the new value. Null on `reset`. */
357
+ new_hash: Field.text({
358
+ label: "New Hash",
359
+ readonly: true,
360
+ maxLength: 128,
361
+ description: "SHA-256 of the new value (canonicalised). Null on reset."
362
+ }),
363
+ /** True when the field is encrypted — flags secret rotation events. */
364
+ encrypted: Field.boolean({
365
+ label: "Encrypted",
366
+ defaultValue: false,
367
+ description: "True when the field carries secret material (rotation is interesting)."
368
+ }),
369
+ /** Request id from the originating HTTP/CLI invocation. */
370
+ request_id: Field.text({
371
+ label: "Request ID",
372
+ maxLength: 128,
373
+ description: "Correlates with sys_audit_log / tracing."
374
+ })
375
+ },
376
+ indexes: [
377
+ // Most common query: "what changed for namespace X in the last 7 days?"
378
+ { fields: ["namespace", "created_at"], unique: false },
379
+ // Per-actor lookup for compliance reviews.
380
+ { fields: ["actor_id", "created_at"], unique: false }
381
+ ],
382
+ enable: {
383
+ trackHistory: false,
384
+ audit: false
385
+ // this IS the audit; no recursion
386
+ }
387
+ });
388
+
389
+ export { SysSecret, SysSetting, SysSettingAudit };
390
+ //# sourceMappingURL=index.mjs.map
391
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/system/sys-setting.object.ts","../../src/system/sys-secret.object.ts","../../src/system/sys-setting-audit.object.ts"],"names":["ObjectSchema","Field"],"mappings":";;;AAiCO,IAAM,UAAA,GAAa,aAAa,MAAA,CAAO;AAAA,EAC5C,IAAA,EAAM,aAAA;AAAA,EACN,KAAA,EAAO,SAAA;AAAA,EACP,WAAA,EAAa,UAAA;AAAA,EACb,IAAA,EAAM,SAAA;AAAA,EACN,QAAA,EAAU,IAAA;AAAA,EACV,SAAA,EAAW,QAAA;AAAA,EACX,WAAA,EAAa,0DAAA;AAAA,EACb,gBAAA,EAAkB,KAAA;AAAA,EAClB,WAAA,EAAa,mBAAA;AAAA,EACb,aAAA,EAAe,CAAC,WAAA,EAAa,KAAA,EAAO,SAAS,YAAY,CAAA;AAAA,EAEzD,SAAA,EAAW;AAAA,IACT,YAAA,EAAc;AAAA,MACZ,IAAA,EAAM,MAA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M;AAAA;AAAA,IAErD,EAAE,MAAA,EAAQ,CAAC,YAAY,YAAY,CAAA,EAAG,QAAQ,KAAA;AAAM,GACtD;AAAA,EAEA,MAAA,EAAQ;AAAA,IACN,YAAA,EAAc,KAAA;AAAA,IACd,KAAA,EAAO;AAAA;AAAA;AAEX,CAAC","file":"index.mjs","sourcesContent":["// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { ObjectSchema, Field } from '@objectstack/spec/data';\n\n/**\n * sys_setting — Generic K/V store backing the SettingsManifest contract\n *\n * Single physical table that holds *every* value for *every* settings\n * namespace declared by a `SettingsManifest`. Plugins MUST NOT define\n * per-namespace tables (e.g. `sys_mail_config`); they declare a manifest\n * and the value persists here.\n *\n * Row identity: (namespace, key, scope, user_id?).\n *\n * Resolution order (handled by `SettingsService.get`):\n * 1. process.env override (source='env', locked=true)\n * 2. sys_setting WHERE scope='global' (source='global')\n * 3. sys_setting WHERE scope='tenant' (source='tenant')\n * 4. sys_setting WHERE scope='user' (source='user')\n * 5. manifest specifier.default (source='default')\n *\n * Encryption: rows with `encrypted=true` store ciphertext in `value_enc`\n * and leave `value` null. The plain value is never written to audit log\n * or history snapshots — only an `'<encrypted>'` placeholder + a digest.\n *\n * managedBy: 'system' — the admin grid in Setup is a diagnostic surface\n * only; all writes flow through `SettingsService.set()` so the resolver\n * stays the single source of truth.\n *\n * See ADR-0007 (Settings Manifest + K/V Store + Resolver).\n *\n * @namespace sys\n */\nexport const SysSetting = ObjectSchema.create({\n name: 'sys_setting',\n label: 'Setting',\n pluralLabel: 'Settings',\n icon: 'sliders',\n isSystem: true,\n managedBy: 'system',\n description: 'Generic K/V store backing the SettingsManifest contract.',\n displayNameField: 'key',\n titleFormat: '{namespace}.{key}',\n compactLayout: ['namespace', 'key', 'scope', 'updated_at'],\n\n listViews: {\n by_namespace: {\n type: 'grid',\n name: 'by_namespace',\n label: 'By Namespace',\n data: { provider: 'object', object: 'sys_setting' },\n columns: ['namespace', 'key', 'scope', 'encrypted', 'updated_by', 'updated_at'],\n sort: [{ field: 'namespace', order: 'asc' }, { field: 'key', order: 'asc' }],\n grouping: { fields: [{ field: 'namespace', order: 'asc', collapsed: false }] },\n pagination: { pageSize: 200 },\n },\n tenant_only: {\n type: 'grid',\n name: 'tenant_only',\n label: 'Tenant',\n data: { provider: 'object', object: 'sys_setting' },\n columns: ['namespace', 'key', 'encrypted', 'updated_by', 'updated_at'],\n filter: [{ field: 'scope', operator: 'equals', value: 'tenant' }],\n sort: [{ field: 'namespace', order: 'asc' }, { field: 'key', order: 'asc' }],\n pagination: { pageSize: 200 },\n },\n user_only: {\n type: 'grid',\n name: 'user_only',\n label: 'User',\n data: { provider: 'object', object: 'sys_setting' },\n columns: ['user_id', 'namespace', 'key', 'updated_at'],\n filter: [{ field: 'scope', operator: 'equals', value: 'user' }],\n sort: [{ field: 'user_id', order: 'asc' }, { field: 'namespace', order: 'asc' }],\n pagination: { pageSize: 200 },\n },\n all_settings: {\n type: 'grid',\n name: 'all_settings',\n label: 'All',\n data: { provider: 'object', object: 'sys_setting' },\n columns: ['namespace', 'key', 'scope', 'user_id', 'encrypted', 'updated_at'],\n sort: [{ field: 'updated_at', order: 'desc' }],\n pagination: { pageSize: 100 },\n },\n },\n\n fields: {\n id: Field.text({\n label: 'Setting ID',\n required: true,\n readonly: true,\n }),\n\n created_at: Field.datetime({\n label: 'Created At',\n defaultValue: 'NOW()',\n readonly: true,\n }),\n\n updated_at: Field.datetime({\n label: 'Updated At',\n defaultValue: 'NOW()',\n readonly: true,\n }),\n\n namespace: Field.text({\n label: 'Namespace',\n required: true,\n maxLength: 64,\n description: 'Manifest namespace (e.g. mail, branding, feature_flags).',\n }),\n\n key: Field.text({\n label: 'Key',\n required: true,\n maxLength: 128,\n description: 'Specifier key inside the namespace (snake_case).',\n }),\n\n scope: Field.select(\n [\n { label: 'Global', value: 'global' },\n { label: 'Tenant', value: 'tenant' },\n { label: 'User', value: 'user' },\n { label: 'Runtime',value: 'runtime' },\n ],\n {\n label: 'Scope',\n required: true,\n defaultValue: 'tenant',\n description: 'Which layer of the config-resolution hierarchy this row belongs to.',\n },\n ),\n\n user_id: Field.lookup('sys_user', {\n label: 'User',\n description: 'Owning user when scope=user; null otherwise.',\n }),\n\n value: Field.json({\n label: 'Value',\n description: 'JSON-encoded value. Null when encrypted=true (see value_enc).',\n }),\n\n encrypted: Field.boolean({\n label: 'Encrypted',\n defaultValue: false,\n description: 'When true, the value is stored encrypted-at-rest in value_enc; value column is null.',\n }),\n\n locked: Field.boolean({\n label: 'Locked',\n defaultValue: false,\n description:\n 'When true, lower-scope rows cannot override this value; writes against lower scopes return 409. ' +\n 'Used by platform administrators to pin a global value for all tenants (Phase 2 cascade).',\n }),\n\n locked_reason: Field.text({\n label: 'Lock Reason',\n description: 'Human-readable explanation surfaced in the UI tooltip when locked=true.',\n }),\n\n value_enc: Field.text({\n label: 'Encrypted Value',\n readonly: true,\n description: 'Ciphertext payload (KMS-wrapped). Set only when encrypted=true.',\n }),\n\n updated_by: Field.lookup('sys_user', {\n label: 'Updated By',\n readonly: true,\n description: 'Last actor who wrote this row via SettingsService.set().',\n }),\n },\n\n indexes: [\n // Primary lookup path: (namespace, key, scope, user_id?) is what\n // SettingsService.get hits on every resolve. The composite UNIQUE\n // covers both the row-identity constraint and the read path.\n { fields: ['namespace', 'key', 'scope', 'user_id'], unique: true },\n // Common range read: full namespace dump for SettingsService.getNamespace.\n { fields: ['namespace', 'scope'], unique: false },\n // Per-user listing on the user-prefs scope.\n { fields: ['user_id', 'namespace'], unique: false },\n ],\n\n enable: {\n // History on settings is opt-in per namespace (handled at service\n // layer when needed) to avoid bloating sys_history with churn from\n // feature flags and similar high-frequency toggles.\n trackHistory: false,\n searchable: false,\n apiEnabled: true,\n // Direct data API exposed for the admin grid view, but writes from\n // the UI MUST go through /api/settings/:namespace so the resolver\n // and audit hooks fire. The grid is diagnostic-only.\n apiMethods: ['get', 'list'],\n trash: false,\n mru: false,\n },\n});\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { ObjectSchema, Field } from '@objectstack/spec/data';\n\n/**\n * sys_secret — Separated cipher store for sensitive settings values.\n *\n * Phase 3 of the settings roadmap splits secret material out of\n * `sys_setting` so they can carry their own retention/rotation/KMS\n * policies without bloating the regular settings audit trail. The\n * value column in `sys_setting` for an encrypted specifier holds a\n * *handle* (the `id` of a row here), never the ciphertext itself —\n * the resolver dereferences on read.\n *\n * Why split:\n * 1. **Key rotation.** KMS adapters (AWS/GCP) rotate keys on a\n * different cadence than user-visible settings; tracking\n * `kms_key_id` + `version` per cipher lets us re-wrap without\n * touching the value lifecycle.\n * 2. **Backup hygiene.** Operators can replicate `sys_setting` to\n * analytics/lower environments while keeping `sys_secret` pinned\n * to the primary KMS region.\n * 3. **Audit symmetry.** Every secret read can record an access row\n * (Phase 4) without polluting `sys_setting_audit` with plaintext\n * reads of e.g. feature flags.\n *\n * managedBy: 'system' — never edited from a generic Object grid. All\n * writes flow through `SettingsService` and an `ICryptoProvider`.\n *\n * @namespace sys\n */\nexport const SysSecret = ObjectSchema.create({\n name: 'sys_secret',\n label: 'Secret',\n pluralLabel: 'Secrets',\n icon: 'key',\n isSystem: true,\n managedBy: 'system',\n description: 'Cipher store referenced by sys_setting handles. Never holds plaintext.',\n scope: 'tenant',\n compactLayout: ['namespace', 'key', 'kms_key_id', 'version', 'rotated_at'],\n defaultViewName: 'all',\n views: {\n all: {\n type: 'list',\n name: 'all',\n label: 'All Secrets',\n columns: ['namespace', 'key', 'kms_key_id', 'version', 'rotated_at', 'created_at'],\n },\n },\n\n fields: {\n id: Field.text({\n label: 'ID',\n readonly: true,\n description: 'Opaque handle referenced by `sys_setting.value_enc`.',\n }),\n\n created_at: Field.datetime({\n label: 'Created At',\n readonly: true,\n description: 'When the cipher was first written.',\n }),\n\n rotated_at: Field.datetime({\n label: 'Rotated At',\n readonly: true,\n description: 'When the cipher was last re-wrapped under a new KMS key.',\n }),\n\n /**\n * Namespace/key duplicated from `sys_setting` for forensic\n * convenience — lets operators answer \"which secret backs\n * mail.api_key right now?\" without joining the K/V table.\n * The authoritative link is `sys_setting.value_enc → sys_secret.id`.\n */\n namespace: Field.text({\n label: 'Namespace',\n required: true,\n maxLength: 128,\n description: 'Settings namespace this secret belongs to.',\n }),\n\n key: Field.text({\n label: 'Key',\n required: true,\n maxLength: 128,\n description: 'Specifier key within the namespace.',\n }),\n\n /** Identifier of the KMS key used to wrap `ciphertext`. */\n kms_key_id: Field.text({\n label: 'KMS Key ID',\n required: true,\n maxLength: 256,\n description: 'External KMS handle (ARN, GCP resource id, or `local`).',\n }),\n\n /** Algorithm tag (e.g. `aes-256-gcm`). Used by the provider on decrypt. */\n alg: Field.text({\n label: 'Algorithm',\n required: true,\n defaultValue: 'aes-256-gcm',\n maxLength: 64,\n description: 'Cipher/AEAD algorithm tag.',\n }),\n\n /** Wrapping version — bumps on every rotate(). */\n version: Field.number({\n label: 'Version',\n required: true,\n defaultValue: 1,\n description: 'Bumps each time rotateKey() re-wraps this row.',\n }),\n\n ciphertext: Field.text({\n label: 'Ciphertext',\n required: true,\n readonly: true,\n description:\n 'Provider-encoded ciphertext blob (base64 / JSON). Implementation-defined; only the matching ICryptoProvider can read it.',\n }),\n },\n\n indexes: [\n // Operators frequently look up by (namespace, key) to inspect or rotate.\n { fields: ['namespace', 'key'], unique: false },\n { fields: ['kms_key_id'], unique: false },\n ],\n\n enable: {\n trackHistory: false, // rotation events are recorded by sys_setting_audit\n audit: true,\n },\n});\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { ObjectSchema, Field } from '@objectstack/spec/data';\n\n/**\n * sys_setting_audit — Append-only audit trail for every settings mutation.\n *\n * Phase 3 of the settings roadmap. Each call to `SettingsService.set()`\n * (and any other mutation hook) writes a row here BEFORE returning to\n * the caller. The row records who, when, where (scope), and what\n * changed — but never the plaintext value of an encrypted field; only\n * a content digest is stored so an operator can verify \"this is the\n * same value as last week\" without exposing the secret.\n *\n * Why separate from `sys_audit_log`:\n * - The generic audit log is a high-traffic firehose (every CRUD\n * on every business object). Settings rows are low-traffic and\n * operationally critical, so they deserve dedicated retention and\n * indexing.\n * - The schema here carries settings-specific fields (`scope`,\n * `cascade_source`) that don't make sense on a generic row.\n *\n * Append-only contract: enforced at the application layer (the only\n * writer is SettingsService). Operators MUST NOT delete rows; instead\n * use lifecycle policies to archive cold rows to a separate bucket.\n *\n * @namespace sys\n */\nexport const SysSettingAudit = ObjectSchema.create({\n name: 'sys_setting_audit',\n label: 'Setting Audit Entry',\n pluralLabel: 'Setting Audit',\n icon: 'history',\n isSystem: true,\n managedBy: 'system',\n description: 'Append-only audit trail for SettingsService mutations.',\n scope: 'tenant',\n compactLayout: ['namespace', 'key', 'scope', 'action', 'actor_id', 'created_at'],\n defaultViewName: 'recent',\n views: {\n recent: {\n type: 'list',\n name: 'recent',\n label: 'Recent',\n columns: ['created_at', 'namespace', 'key', 'scope', 'action', 'actor_id', 'source'],\n sort: [{ field: 'created_at', order: 'desc' }],\n },\n },\n\n fields: {\n id: Field.text({\n label: 'ID',\n readonly: true,\n }),\n\n created_at: Field.datetime({\n label: 'Created At',\n readonly: true,\n description: 'When the mutation was recorded.',\n }),\n\n namespace: Field.text({\n label: 'Namespace',\n required: true,\n maxLength: 128,\n }),\n\n key: Field.text({\n label: 'Key',\n required: true,\n maxLength: 128,\n }),\n\n scope: Field.select(\n [\n { label: 'Global', value: 'global' },\n { label: 'Tenant', value: 'tenant' },\n { label: 'User', value: 'user' },\n ],\n {\n label: 'Scope',\n required: true,\n description: 'Cascade layer the row was written to.',\n },\n ),\n\n action: Field.select(\n [\n { label: 'Set', value: 'set' },\n { label: 'Reset', value: 'reset' },\n { label: 'Lock', value: 'lock' },\n { label: 'Unlock', value: 'unlock' },\n { label: 'Rotate', value: 'rotate' },\n ],\n {\n label: 'Action',\n required: true,\n description: 'Mutation kind.',\n },\n ),\n\n actor_id: Field.lookup('sys_user', {\n label: 'Actor',\n description: 'User who performed the mutation; null for system jobs.',\n }),\n\n /**\n * Where the write originated. Lets operators distinguish admin UI\n * activity from migration jobs and bulk imports during incident\n * analysis.\n */\n source: Field.select(\n [\n { label: 'UI', value: 'ui' },\n { label: 'API', value: 'api' },\n { label: 'Migration', value: 'migration' },\n { label: 'Import', value: 'import' },\n { label: 'System', value: 'system' },\n ],\n {\n label: 'Source',\n required: true,\n defaultValue: 'api',\n description: 'Mutation entry-point.',\n },\n ),\n\n /** Optional free-text reason (Phase 3+ change-management hook). */\n reason: Field.text({\n label: 'Reason',\n description: 'Free-text justification provided by the actor (optional).',\n }),\n\n /**\n * Content digest of the previous value. Never the plaintext —\n * lets operators detect duplicate writes without leaking secrets.\n * Format: hex SHA-256 of the canonicalised JSON, or null when\n * the previous value was unset.\n */\n old_hash: Field.text({\n label: 'Old Hash',\n readonly: true,\n maxLength: 128,\n description: 'SHA-256 of the previous value (canonicalised). Null when previously unset.',\n }),\n\n /** Content digest of the new value. Null on `reset`. */\n new_hash: Field.text({\n label: 'New Hash',\n readonly: true,\n maxLength: 128,\n description: 'SHA-256 of the new value (canonicalised). Null on reset.',\n }),\n\n /** True when the field is encrypted — flags secret rotation events. */\n encrypted: Field.boolean({\n label: 'Encrypted',\n defaultValue: false,\n description: 'True when the field carries secret material (rotation is interesting).',\n }),\n\n /** Request id from the originating HTTP/CLI invocation. */\n request_id: Field.text({\n label: 'Request ID',\n maxLength: 128,\n description: 'Correlates with sys_audit_log / tracing.',\n }),\n },\n\n indexes: [\n // Most common query: \"what changed for namespace X in the last 7 days?\"\n { fields: ['namespace', 'created_at'], unique: false },\n // Per-actor lookup for compliance reviews.\n { fields: ['actor_id', 'created_at'], unique: false },\n ],\n\n enable: {\n trackHistory: false,\n audit: false, // this IS the audit; no recursion\n },\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/platform-objects",
3
- "version": "4.0.5",
3
+ "version": "4.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Core platform object schemas for ObjectStack — identity, security, audit, tenant, and metadata objects",
6
6
  "main": "dist/index.js",
@@ -26,16 +26,21 @@
26
26
  "import": "./dist/audit/index.mjs",
27
27
  "require": "./dist/audit/index.js"
28
28
  },
29
- "./tenant": {
30
- "types": "./dist/tenant/index.d.ts",
31
- "import": "./dist/tenant/index.mjs",
32
- "require": "./dist/tenant/index.js"
29
+ "./integration": {
30
+ "types": "./dist/integration/index.d.ts",
31
+ "import": "./dist/integration/index.mjs",
32
+ "require": "./dist/integration/index.js"
33
33
  },
34
34
  "./metadata": {
35
35
  "types": "./dist/metadata/index.d.ts",
36
36
  "import": "./dist/metadata/index.mjs",
37
37
  "require": "./dist/metadata/index.js"
38
38
  },
39
+ "./system": {
40
+ "types": "./dist/system/index.d.ts",
41
+ "import": "./dist/system/index.mjs",
42
+ "require": "./dist/system/index.js"
43
+ },
39
44
  "./apps": {
40
45
  "types": "./dist/apps/index.d.ts",
41
46
  "import": "./dist/apps/index.mjs",
@@ -43,13 +48,13 @@
43
48
  }
44
49
  },
45
50
  "dependencies": {
46
- "@objectstack/spec": "4.0.5"
51
+ "@objectstack/spec": "4.1.0"
47
52
  },
48
53
  "devDependencies": {
49
- "@types/node": "^25.6.2",
54
+ "@types/node": "^25.9.1",
50
55
  "tsup": "^8.5.1",
51
56
  "typescript": "^6.0.3",
52
- "vitest": "^4.1.5"
57
+ "vitest": "^4.1.7"
53
58
  },
54
59
  "keywords": [
55
60
  "objectstack",