@spinajs/configuration-http 2.0.481 → 2.0.482

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 (54) hide show
  1. package/README.md +30 -7
  2. package/lib/cjs/bootstrap.d.ts +20 -0
  3. package/lib/cjs/bootstrap.d.ts.map +1 -0
  4. package/lib/cjs/bootstrap.js +40 -0
  5. package/lib/cjs/bootstrap.js.map +1 -0
  6. package/lib/cjs/config/configuration-http.d.ts +34 -0
  7. package/lib/cjs/config/configuration-http.d.ts.map +1 -0
  8. package/lib/cjs/config/configuration-http.js +41 -0
  9. package/lib/cjs/config/configuration-http.js.map +1 -0
  10. package/lib/cjs/controllers/Configuration.d.ts +66 -0
  11. package/lib/cjs/controllers/Configuration.d.ts.map +1 -0
  12. package/lib/cjs/controllers/Configuration.js +170 -0
  13. package/lib/cjs/controllers/Configuration.js.map +1 -0
  14. package/lib/cjs/dto/update-config-dto.d.ts +14 -0
  15. package/lib/cjs/dto/update-config-dto.d.ts.map +1 -0
  16. package/lib/cjs/dto/update-config-dto.js +42 -0
  17. package/lib/cjs/dto/update-config-dto.js.map +1 -0
  18. package/lib/cjs/index.d.ts +5 -0
  19. package/lib/cjs/index.d.ts.map +1 -0
  20. package/lib/cjs/index.js +21 -0
  21. package/lib/cjs/index.js.map +1 -0
  22. package/lib/cjs/package.json +1 -0
  23. package/lib/cjs/validation.d.ts +29 -0
  24. package/lib/cjs/validation.d.ts.map +1 -0
  25. package/lib/cjs/validation.js +72 -0
  26. package/lib/cjs/validation.js.map +1 -0
  27. package/lib/mjs/bootstrap.d.ts +20 -0
  28. package/lib/mjs/bootstrap.d.ts.map +1 -0
  29. package/lib/mjs/bootstrap.js +37 -0
  30. package/lib/mjs/bootstrap.js.map +1 -0
  31. package/lib/mjs/config/configuration-http.d.ts +34 -0
  32. package/lib/mjs/config/configuration-http.d.ts.map +1 -0
  33. package/lib/mjs/config/configuration-http.js +39 -0
  34. package/lib/mjs/config/configuration-http.js.map +1 -0
  35. package/lib/mjs/controllers/Configuration.d.ts +66 -0
  36. package/lib/mjs/controllers/Configuration.d.ts.map +1 -0
  37. package/lib/mjs/controllers/Configuration.js +167 -0
  38. package/lib/mjs/controllers/Configuration.js.map +1 -0
  39. package/lib/mjs/dto/update-config-dto.d.ts +14 -0
  40. package/lib/mjs/dto/update-config-dto.d.ts.map +1 -0
  41. package/lib/mjs/dto/update-config-dto.js +39 -0
  42. package/lib/mjs/dto/update-config-dto.js.map +1 -0
  43. package/lib/mjs/index.d.ts +5 -0
  44. package/lib/mjs/index.d.ts.map +1 -0
  45. package/lib/mjs/index.js +5 -0
  46. package/lib/mjs/index.js.map +1 -0
  47. package/lib/mjs/package.json +1 -0
  48. package/lib/mjs/validation.d.ts +29 -0
  49. package/lib/mjs/validation.d.ts.map +1 -0
  50. package/lib/mjs/validation.js +68 -0
  51. package/lib/mjs/validation.js.map +1 -0
  52. package/lib/tsconfig.cjs.tsbuildinfo +1 -0
  53. package/lib/tsconfig.mjs.tsbuildinfo +1 -0
  54. package/package.json +30 -7
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VALUE_SCHEMAS = void 0;
4
+ exports.valueSchema = valueSchema;
5
+ /**
6
+ * Base JSON Schema per configuration `Type`. These shapes are constant - the
7
+ * per-entry `Meta` ( bounds / allowed values ) is folded on top at request time
8
+ * by {@link valueSchema}.
9
+ *
10
+ * Validation only - it asserts the incoming value is acceptable. Coercion into
11
+ * the typed / canonical stored form is the converter's job ( see
12
+ * DbConfigValueConverter ), so eg. a `date` is just a `format: date` string
13
+ * here, not a luxon DateTime.
14
+ */
15
+ exports.VALUE_SCHEMAS = {
16
+ string: { type: 'string' },
17
+ file: { type: 'string' },
18
+ oneOf: { type: 'string' },
19
+ manyOf: { type: 'array', uniqueItems: true, items: { type: 'string' } },
20
+ number: { type: 'integer' },
21
+ float: { type: 'number' },
22
+ range: { type: 'number' },
23
+ // a real boolean or the canonical / numeric string forms the converter understands
24
+ boolean: { anyOf: [{ type: 'boolean' }, { type: 'string', enum: ['0', '1', 'true', 'false'] }] },
25
+ date: { type: 'string', format: 'date' },
26
+ time: { type: 'string', format: 'time' },
27
+ datetime: { type: 'string', format: 'date-time' },
28
+ 'date-range': { type: 'array', items: { type: 'string', format: 'date' } },
29
+ 'time-range': { type: 'array', items: { type: 'string', format: 'time' } },
30
+ 'datetime-range': { type: 'array', items: { type: 'string', format: 'date-time' } },
31
+ json: {},
32
+ };
33
+ /**
34
+ * Resolves the value schema for an entry: the constant base schema for its
35
+ * `Type` with the entry `Meta` constraints applied.
36
+ *
37
+ * The constraints target the schema "leaf" - the `items` schema for array types
38
+ * ( manyOf / *-range ), otherwise the schema itself - so allowed values and
39
+ * bounds land on the element being validated regardless of arity.
40
+ *
41
+ * Fed to `DataValidator` ( ajv ) in the controller, after the entry - and so its
42
+ * Type / Meta - has been loaded from the db. It can't live on the request DTO
43
+ * schema, which is validated before that lookup when the type is still unknown.
44
+ */
45
+ function valueSchema(type, meta) {
46
+ const schema = structuredClone(exports.VALUE_SCHEMAS[type]);
47
+ if (!meta) {
48
+ return schema;
49
+ }
50
+ const leaf = schema.items ?? schema;
51
+ // oneOf / manyOf both restrict the string element to an allowed set
52
+ const allowed = meta.oneOf ?? meta.manyOf;
53
+ if (allowed) {
54
+ leaf.enum = allowed;
55
+ }
56
+ if (meta.min !== undefined) {
57
+ leaf.minimum = meta.min;
58
+ }
59
+ if (meta.max !== undefined) {
60
+ leaf.maximum = meta.max;
61
+ }
62
+ // minDate / maxDate are ISO strings in the JSON Meta; ajv-formats
63
+ // formatMinimum / formatMaximum compare date / time / date-time formats
64
+ if (meta.minDate !== undefined) {
65
+ leaf.formatMinimum = meta.minDate;
66
+ }
67
+ if (meta.maxDate !== undefined) {
68
+ leaf.formatMaximum = meta.maxDate;
69
+ }
70
+ return schema;
71
+ }
72
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":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4
+ *
5
+ * `DbConfig` lives in the persistence-only `@spinajs/configuration-db-source`
6
+ * package, which intentionally does not depend on rbac. Its `@Model('configuration')`
7
+ * only names the database table - that is NOT the RBAC resource. Set the model's
8
+ * `RbacResource` here ( this http package already depends on rbac ) so the
9
+ * `RbacModelPermissionMiddleware` enforces `configuration` grants on every
10
+ * DbConfig query, matching the route-level `@Resource('configuration')` on the
11
+ * controller.
12
+ *
13
+ * Without this the model descriptor has no `RbacResource`, so model-level
14
+ * permission checks are silently skipped ( the middleware's table-name fallback
15
+ * is disabled ) and only the route-level policy would guard the data.
16
+ */
17
+ export declare class ConfigurationHttpBootstrapper extends Bootstrapper {
18
+ bootstrap(): void;
19
+ }
20
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAKvD;;;;;;;;;;;;;;GAcG;AACH,qBACa,6BAA8B,SAAQ,YAAY;IACtD,SAAS,IAAI,IAAI;CAMzB"}
@@ -0,0 +1,37 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Bootstrapper, Injectable } from '@spinajs/di';
8
+ import { extractModelDescriptor } from '@spinajs/orm';
9
+ import { DbConfig } from '@spinajs/configuration-db-source';
10
+ /**
11
+ * Ties the `DbConfig` model to the `configuration` RBAC resource.
12
+ *
13
+ * `DbConfig` lives in the persistence-only `@spinajs/configuration-db-source`
14
+ * package, which intentionally does not depend on rbac. Its `@Model('configuration')`
15
+ * only names the database table - that is NOT the RBAC resource. Set the model's
16
+ * `RbacResource` here ( this http package already depends on rbac ) so the
17
+ * `RbacModelPermissionMiddleware` enforces `configuration` grants on every
18
+ * DbConfig query, matching the route-level `@Resource('configuration')` on the
19
+ * controller.
20
+ *
21
+ * Without this the model descriptor has no `RbacResource`, so model-level
22
+ * permission checks are silently skipped ( the middleware's table-name fallback
23
+ * is disabled ) and only the route-level policy would guard the data.
24
+ */
25
+ let ConfigurationHttpBootstrapper = class ConfigurationHttpBootstrapper extends Bootstrapper {
26
+ bootstrap() {
27
+ const descriptor = extractModelDescriptor(DbConfig);
28
+ if (descriptor) {
29
+ descriptor.RbacResource = 'configuration';
30
+ }
31
+ }
32
+ };
33
+ ConfigurationHttpBootstrapper = __decorate([
34
+ Injectable(Bootstrapper)
35
+ ], ConfigurationHttpBootstrapper);
36
+ export { ConfigurationHttpBootstrapper };
37
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAG5D;;;;;;;;;;;;;;GAcG;AAEI,IAAM,6BAA6B,GAAnC,MAAM,6BAA8B,SAAQ,YAAY;IACtD,SAAS;QACd,MAAM,UAAU,GAAG,sBAAsB,CAAC,QAAQ,CAAyB,CAAC;QAC5E,IAAI,UAAU,EAAE,CAAC;YACf,UAAU,CAAC,YAAY,GAAG,eAAe,CAAC;QAC5C,CAAC;IACH,CAAC;CACF,CAAA;AAPY,6BAA6B;IADzC,UAAU,CAAC,YAAY,CAAC;GACZ,6BAA6B,CAOzC"}
@@ -0,0 +1,34 @@
1
+ declare const configurationHttp: {
2
+ system: {
3
+ dirs: {
4
+ controllers: string[];
5
+ };
6
+ };
7
+ rbac: {
8
+ grants: {
9
+ /**
10
+ * Dedicated admin sub-role granting full management over configuration
11
+ * entries. Mirrors the `admin.users` sub-role in @spinajs/rbac: only the
12
+ * `admin` role ( and `system`, which extends admin ) inherits it below, so
13
+ * the configuration HTTP api is an admin-only capability. The resource
14
+ * itself is named `configuration` ( see @Resource in the controller ).
15
+ */
16
+ 'admin.configuration': {
17
+ configuration: {
18
+ 'read:any': string[];
19
+ 'update:any': string[];
20
+ };
21
+ };
22
+ /**
23
+ * Admin inherits configuration management. The config merge concatenates
24
+ * `$extend` arrays, so this is additive - it does not overwrite the base
25
+ * admin grants ( eg. `admin.users` ).
26
+ */
27
+ admin: {
28
+ $extend: string[];
29
+ };
30
+ };
31
+ };
32
+ };
33
+ export default configurationHttp;
34
+ //# sourceMappingURL=configuration-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration-http.d.ts","sourceRoot":"","sources":["../../../src/config/configuration-http.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,iBAAiB;;;;;;;;YAQjB;;;;;;eAMG;;;;;;;YAQH;;;;eAIG;;;;;;CAMR,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { join, normalize, resolve } from 'path';
2
+ function dir(path) {
3
+ const inCommonJs = typeof module !== 'undefined';
4
+ return resolve(normalize(join(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), 'node_modules', '@spinajs', 'configuration-http', 'lib', inCommonJs ? 'cjs' : 'mjs', path)));
5
+ }
6
+ const configurationHttp = {
7
+ system: {
8
+ dirs: {
9
+ controllers: [dir('controllers')],
10
+ },
11
+ },
12
+ rbac: {
13
+ grants: {
14
+ /**
15
+ * Dedicated admin sub-role granting full management over configuration
16
+ * entries. Mirrors the `admin.users` sub-role in @spinajs/rbac: only the
17
+ * `admin` role ( and `system`, which extends admin ) inherits it below, so
18
+ * the configuration HTTP api is an admin-only capability. The resource
19
+ * itself is named `configuration` ( see @Resource in the controller ).
20
+ */
21
+ 'admin.configuration': {
22
+ configuration: {
23
+ 'read:any': ['*'],
24
+ 'update:any': ['*'],
25
+ },
26
+ },
27
+ /**
28
+ * Admin inherits configuration management. The config merge concatenates
29
+ * `$extend` arrays, so this is additive - it does not overwrite the base
30
+ * admin grants ( eg. `admin.users` ).
31
+ */
32
+ admin: {
33
+ $extend: ['admin.configuration'],
34
+ },
35
+ },
36
+ },
37
+ };
38
+ export default configurationHttp;
39
+ //# sourceMappingURL=configuration-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration-http.js","sourceRoot":"","sources":["../../../src/config/configuration-http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACjD,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/K,CAAC;AAED,MAAM,iBAAiB,GAAG;IACxB,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,WAAW,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;SAClC;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE;YACN;;;;;;eAMG;YACH,qBAAqB,EAAE;gBACrB,aAAa,EAAE;oBACb,UAAU,EAAE,CAAC,GAAG,CAAC;oBACjB,YAAY,EAAE,CAAC,GAAG,CAAC;iBACpB;aACF;YAED;;;;eAIG;YACH,KAAK,EAAE;gBACL,OAAO,EAAE,CAAC,qBAAqB,CAAC;aACjC;SACF;KACF;CACF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { BadRequestResponse, BaseController, Ok } from '@spinajs/http';
2
+ import { DataValidator } from '@spinajs/validation';
3
+ import { DbConfig } from '@spinajs/configuration-db-source';
4
+ import { UpdateConfigDto } from '../dto/update-config-dto.js';
5
+ /**
6
+ * HTTP api for database stored configuration values.
7
+ *
8
+ * Exposes read and update operations over the `configuration` table managed by
9
+ * `@spinajs/configuration-db-source`. Entries themselves are created by code
10
+ * that exposes config options ( `expose: true` ), so this api intentionally does
11
+ * NOT allow creating or deleting arbitrary entries - only tuning their values.
12
+ *
13
+ * Writes are persisted to the database only. The running application picks up
14
+ * the change through the db-source watch poll, and only for entries with
15
+ * `Watch = true`.
16
+ *
17
+ * @tags Configuration
18
+ */
19
+ export declare class ConfigurationController extends BaseController {
20
+ protected Validator: DataValidator;
21
+ /**
22
+ * List configuration entries
23
+ * Returns all database stored configuration entries, optionally filtered by group.
24
+ * @security cookieAuth
25
+ * @param group Optional group name to filter entries by
26
+ * @response 200 List of configuration entries
27
+ * @response 401 Unauthorized — valid session required
28
+ * @response 403 Forbidden — readAny permission required on configuration resource
29
+ */
30
+ list(group?: string): Promise<Ok<Record<string, unknown>[]>>;
31
+ /**
32
+ * Get configuration entry
33
+ * Returns a single configuration entry identified by its slug.
34
+ * @security cookieAuth
35
+ * @param slug Unique configuration entry slug
36
+ * @response 200 Configuration entry
37
+ * @response 401 Unauthorized — valid session required
38
+ * @response 403 Forbidden — readAny permission required on configuration resource
39
+ * @response 404 Configuration entry not found
40
+ */
41
+ get(entry: DbConfig): Promise<Ok<Record<string, unknown>>>;
42
+ /**
43
+ * Update configuration entry value
44
+ * Updates the value ( and optionally default/watch flag ) of an existing entry.
45
+ * The incoming value is validated against the entry `Type` and `Meta` constraints.
46
+ * Structural fields ( slug, group, type ) cannot be changed through this api.
47
+ * @security cookieAuth
48
+ * @param slug Unique configuration entry slug
49
+ * @response 200 Updated configuration entry
50
+ * @response 400 Invalid value for the entry type or constraints
51
+ * @response 401 Unauthorized — valid session required
52
+ * @response 403 Forbidden — updateAny permission required on configuration resource
53
+ * @response 404 Configuration entry not found
54
+ */
55
+ update(entry: DbConfig, data: UpdateConfigDto): Promise<Ok<Record<string, unknown>> | BadRequestResponse<any>>;
56
+ /**
57
+ * Validates a single value against the entry value schema, returning a 400
58
+ * response on failure or `null` when it passes.
59
+ *
60
+ * The value is wrapped in an object ( `{ [field]: value }` ) so it is always a
61
+ * non-null object for the validator - a bare `null` / scalar would otherwise
62
+ * confuse `tryValidate`'s schema-vs-data overload resolution.
63
+ */
64
+ private validateValue;
65
+ }
66
+ //# sourceMappingURL=Configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Configuration.d.ts","sourceRoot":"","sources":["../../../src/controllers/Configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAuB,EAAE,EAAwB,MAAM,eAAe,CAAC;AAGlH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAgB9D;;;;;;;;;;;;;GAaG;AACH,qBAGa,uBAAwB,SAAQ,cAAc;IAEzD,SAAS,CAAC,SAAS,EAAG,aAAa,CAAC;IAEpC;;;;;;;;OAQG;IAGU,IAAI,CAAU,KAAK,CAAC,EAAE,MAAM;IAKzC;;;;;;;;;OASG;IAGU,GAAG,CAAwD,KAAK,EAAE,QAAQ;IAIvF;;;;;;;;;;;;OAYG;IAGU,MAAM,CAAwD,KAAK,EAAE,QAAQ,EAAU,IAAI,EAAE,eAAe;IAmCzH;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa;CActB"}
@@ -0,0 +1,167 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { BadRequestResponse, BaseController, BasePath, Body, Get, Ok, Patch, Policy, Query } from '@spinajs/http';
14
+ import { AuthorizedPolicy, Permission, Resource } from '@spinajs/rbac-http';
15
+ import { Autoinject } from '@spinajs/di';
16
+ import { DataValidator } from '@spinajs/validation';
17
+ import { FromModel } from '@spinajs/orm-http';
18
+ import { DbConfig } from '@spinajs/configuration-db-source';
19
+ import { UpdateConfigDto } from '../dto/update-config-dto.js';
20
+ import { valueSchema } from '../validation.js';
21
+ /**
22
+ * Serializes an entry for the api. `DbConfig.dehydrate()` emits only the declared
23
+ * columns with Value / Default in their canonical stored form ( numbers as "10",
24
+ * booleans as "true"/"false", dates / times as ISO 8601 etc. ) produced by the
25
+ * DbConfigValueConverter, and Meta already parsed into an object by its @Json
26
+ * converter - the same representation they round-trip through on update.
27
+ */
28
+ function present(entry) {
29
+ const out = entry.dehydrate();
30
+ out.Meta = entry.Meta ?? null;
31
+ return out;
32
+ }
33
+ /**
34
+ * HTTP api for database stored configuration values.
35
+ *
36
+ * Exposes read and update operations over the `configuration` table managed by
37
+ * `@spinajs/configuration-db-source`. Entries themselves are created by code
38
+ * that exposes config options ( `expose: true` ), so this api intentionally does
39
+ * NOT allow creating or deleting arbitrary entries - only tuning their values.
40
+ *
41
+ * Writes are persisted to the database only. The running application picks up
42
+ * the change through the db-source watch poll, and only for entries with
43
+ * `Watch = true`.
44
+ *
45
+ * @tags Configuration
46
+ */
47
+ let ConfigurationController = class ConfigurationController extends BaseController {
48
+ /**
49
+ * List configuration entries
50
+ * Returns all database stored configuration entries, optionally filtered by group.
51
+ * @security cookieAuth
52
+ * @param group Optional group name to filter entries by
53
+ * @response 200 List of configuration entries
54
+ * @response 401 Unauthorized — valid session required
55
+ * @response 403 Forbidden — readAny permission required on configuration resource
56
+ */
57
+ async list(group) {
58
+ const entries = await (group ? DbConfig.where('Group', group) : DbConfig.all());
59
+ return new Ok(entries.map((e) => present(e)));
60
+ }
61
+ /**
62
+ * Get configuration entry
63
+ * Returns a single configuration entry identified by its slug.
64
+ * @security cookieAuth
65
+ * @param slug Unique configuration entry slug
66
+ * @response 200 Configuration entry
67
+ * @response 401 Unauthorized — valid session required
68
+ * @response 403 Forbidden — readAny permission required on configuration resource
69
+ * @response 404 Configuration entry not found
70
+ */
71
+ async get(entry) {
72
+ return new Ok(present(entry));
73
+ }
74
+ /**
75
+ * Update configuration entry value
76
+ * Updates the value ( and optionally default/watch flag ) of an existing entry.
77
+ * The incoming value is validated against the entry `Type` and `Meta` constraints.
78
+ * Structural fields ( slug, group, type ) cannot be changed through this api.
79
+ * @security cookieAuth
80
+ * @param slug Unique configuration entry slug
81
+ * @response 200 Updated configuration entry
82
+ * @response 400 Invalid value for the entry type or constraints
83
+ * @response 401 Unauthorized — valid session required
84
+ * @response 403 Forbidden — updateAny permission required on configuration resource
85
+ * @response 404 Configuration entry not found
86
+ */
87
+ async update(entry, data) {
88
+ // Build the value schema from the entry Type + Meta ( entry.Meta is already an
89
+ // object here, parsed by its @Json converter on load ) and validate the
90
+ // incoming value(s) against it. Validation can only happen here - not on the
91
+ // request DTO - because the entry Type isn't known until after this lookup.
92
+ const schema = valueSchema(entry.Type, entry.Meta);
93
+ const valueError = this.validateValue(schema, 'Value', data.Value);
94
+ if (valueError) {
95
+ return valueError;
96
+ }
97
+ if (data.Default !== undefined) {
98
+ const defaultError = this.validateValue(schema, 'Default', data.Default);
99
+ if (defaultError) {
100
+ return defaultError;
101
+ }
102
+ }
103
+ // Assign the raw, validated value(s). The DbConfigValueConverter does all the
104
+ // type-based coercion into the canonical stored form on update().
105
+ entry.Value = data.Value;
106
+ if (data.Default !== undefined) {
107
+ entry.Default = data.Default;
108
+ }
109
+ if (data.Watch !== undefined) {
110
+ entry.Watch = data.Watch;
111
+ }
112
+ await entry.update();
113
+ return new Ok(present(entry));
114
+ }
115
+ /**
116
+ * Validates a single value against the entry value schema, returning a 400
117
+ * response on failure or `null` when it passes.
118
+ *
119
+ * The value is wrapped in an object ( `{ [field]: value }` ) so it is always a
120
+ * non-null object for the validator - a bare `null` / scalar would otherwise
121
+ * confuse `tryValidate`'s schema-vs-data overload resolution.
122
+ */
123
+ validateValue(valueSchema, field, value) {
124
+ const [isValid, errors] = this.Validator.tryValidate({ type: 'object', properties: { [field]: valueSchema }, required: [field] }, { [field]: value });
125
+ if (isValid) {
126
+ return null;
127
+ }
128
+ const message = (errors ?? []).map((e) => `${field}${e.instancePath ? e.instancePath.replace(`/${field}`, '') : ''} ${e.message ?? 'is invalid'}`.trim()).join('; ') || `invalid value for ${field}`;
129
+ return new BadRequestResponse({ error: { message } });
130
+ }
131
+ };
132
+ __decorate([
133
+ Autoinject(),
134
+ __metadata("design:type", DataValidator)
135
+ ], ConfigurationController.prototype, "Validator", void 0);
136
+ __decorate([
137
+ Get('/'),
138
+ Permission(['readAny']),
139
+ __param(0, Query()),
140
+ __metadata("design:type", Function),
141
+ __metadata("design:paramtypes", [String]),
142
+ __metadata("design:returntype", Promise)
143
+ ], ConfigurationController.prototype, "list", null);
144
+ __decorate([
145
+ Get(':slug'),
146
+ Permission(['readAny']),
147
+ __param(0, FromModel({ paramField: 'slug', queryField: 'Slug' })),
148
+ __metadata("design:type", Function),
149
+ __metadata("design:paramtypes", [DbConfig]),
150
+ __metadata("design:returntype", Promise)
151
+ ], ConfigurationController.prototype, "get", null);
152
+ __decorate([
153
+ Patch(':slug'),
154
+ Permission(['updateAny']),
155
+ __param(0, FromModel({ paramField: 'slug', queryField: 'Slug' })),
156
+ __param(1, Body()),
157
+ __metadata("design:type", Function),
158
+ __metadata("design:paramtypes", [DbConfig, UpdateConfigDto]),
159
+ __metadata("design:returntype", Promise)
160
+ ], ConfigurationController.prototype, "update", null);
161
+ ConfigurationController = __decorate([
162
+ BasePath('configuration'),
163
+ Policy(AuthorizedPolicy),
164
+ Resource('configuration')
165
+ ], ConfigurationController);
166
+ export { ConfigurationController };
167
+ //# sourceMappingURL=Configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/controllers/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;GAMG;AACH,SAAS,OAAO,CAAC,KAAe;IAC9B,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,EAA6B,CAAC;IACzD,GAAG,CAAC,IAAI,GAAG,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C,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,qBAAqB,KAAK,EAAE,CAAC;QAErM,OAAO,IAAI,kBAAkB,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IACxD,CAAC;CACF,CAAA;AA1GW;IADT,UAAU,EAAE;8BACS,aAAa;0DAAC;AAavB;IAFZ,GAAG,CAAC,GAAG,CAAC;IACR,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC;IACL,WAAA,KAAK,EAAE,CAAA;;;;mDAGzB;AAcY;IAFZ,GAAG,CAAC,OAAO,CAAC;IACZ,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC;IACN,WAAA,SAAS,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAA;;qCAAQ,QAAQ;;kDAEtF;AAiBY;IAFZ,KAAK,CAAC,OAAO,CAAC;IACd,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC;IACL,WAAA,SAAS,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAA;IAAmB,WAAA,IAAI,EAAE,CAAA;;qCAAjB,QAAQ,EAAgB,eAAe;;qDAiCxH;AApFU,uBAAuB;IAHnC,QAAQ,CAAC,eAAe,CAAC;IACzB,MAAM,CAAC,gBAAgB,CAAC;IACxB,QAAQ,CAAC,eAAe,CAAC;GACb,uBAAuB,CA4GnC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Body payload for updating a configuration entry value.
3
+ *
4
+ * Only the operationally meaningful fields are editable. Structural fields
5
+ * ( `Slug`, `Group`, `Type` ) are owned by code that exposes the option and
6
+ * cannot be changed through this api.
7
+ */
8
+ export declare class UpdateConfigDto {
9
+ Value: any;
10
+ Default?: any;
11
+ Watch?: boolean;
12
+ constructor(data: Partial<UpdateConfigDto>);
13
+ }
14
+ //# sourceMappingURL=update-config-dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-config-dto.d.ts","sourceRoot":"","sources":["../../../src/dto/update-config-dto.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,qBAYa,eAAe;IAEnB,KAAK,EAAE,GAAG,CAAC;IAGX,OAAO,CAAC,EAAE,GAAG,CAAC;IAEd,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEX,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC;CAG3C"}
@@ -0,0 +1,39 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Schema } from '@spinajs/validation';
11
+ /**
12
+ * Body payload for updating a configuration entry value.
13
+ *
14
+ * Only the operationally meaningful fields are editable. Structural fields
15
+ * ( `Slug`, `Group`, `Type` ) are owned by code that exposes the option and
16
+ * cannot be changed through this api.
17
+ */
18
+ let UpdateConfigDto = class UpdateConfigDto {
19
+ constructor(data) {
20
+ Object.assign(this, data);
21
+ }
22
+ };
23
+ UpdateConfigDto = __decorate([
24
+ Schema({
25
+ type: 'object',
26
+ $id: 'configuration.http.updateConfigDTO',
27
+ properties: {
28
+ // value type varies with the entry `Type`, real validation happens against
29
+ // Type/Meta in the controller, so the schema only requires its presence
30
+ Value: {},
31
+ Default: {},
32
+ Watch: { type: 'boolean' },
33
+ },
34
+ required: ['Value'],
35
+ }),
36
+ __metadata("design:paramtypes", [Object])
37
+ ], UpdateConfigDto);
38
+ export { UpdateConfigDto };
39
+ //# sourceMappingURL=update-config-dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-config-dto.js","sourceRoot":"","sources":["../../../src/dto/update-config-dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C;;;;;;GAMG;AAaI,IAAM,eAAe,GAArB,MAAM,eAAe;IAS1B,YAAY,IAA8B;QACxC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AAZY,eAAe;IAZ3B,MAAM,CAAC;QACN,IAAI,EAAE,QAAQ;QACd,GAAG,EAAE,oCAAoC;QACzC,UAAU,EAAE;YACV,2EAA2E;YAC3E,wEAAwE;YACxE,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,EAAE;YACX,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;SAC3B;QACD,QAAQ,EAAE,CAAC,OAAO,CAAC;KACpB,CAAC;;GACW,eAAe,CAY3B"}
@@ -0,0 +1,5 @@
1
+ export * from './controllers/Configuration.js';
2
+ export * from './dto/update-config-dto.js';
3
+ export * from './validation.js';
4
+ export * from './bootstrap.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './controllers/Configuration.js';
2
+ export * from './dto/update-config-dto.js';
3
+ export * from './validation.js';
4
+ export * from './bootstrap.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,29 @@
1
+ import { ConfigurationEntryType, IConfigurationEntryMeta } from '@spinajs/configuration-db-source';
2
+ /** A plain JSON Schema fragment. */
3
+ type JsonSchema = Record<string, unknown>;
4
+ /**
5
+ * Base JSON Schema per configuration `Type`. These shapes are constant - the
6
+ * per-entry `Meta` ( bounds / allowed values ) is folded on top at request time
7
+ * by {@link valueSchema}.
8
+ *
9
+ * Validation only - it asserts the incoming value is acceptable. Coercion into
10
+ * the typed / canonical stored form is the converter's job ( see
11
+ * DbConfigValueConverter ), so eg. a `date` is just a `format: date` string
12
+ * here, not a luxon DateTime.
13
+ */
14
+ export declare const VALUE_SCHEMAS: Record<ConfigurationEntryType, JsonSchema>;
15
+ /**
16
+ * Resolves the value schema for an entry: the constant base schema for its
17
+ * `Type` with the entry `Meta` constraints applied.
18
+ *
19
+ * The constraints target the schema "leaf" - the `items` schema for array types
20
+ * ( manyOf / *-range ), otherwise the schema itself - so allowed values and
21
+ * bounds land on the element being validated regardless of arity.
22
+ *
23
+ * Fed to `DataValidator` ( ajv ) in the controller, after the entry - and so its
24
+ * Type / Meta - has been loaded from the db. It can't live on the request DTO
25
+ * schema, which is validated before that lookup when the type is still unknown.
26
+ */
27
+ export declare function valueSchema(type: ConfigurationEntryType, meta?: IConfigurationEntryMeta): JsonSchema;
28
+ export {};
29
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAEnG,oCAAoC;AACpC,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,UAAU,CAiBpE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,sBAAsB,EAAE,IAAI,CAAC,EAAE,uBAAuB,GAAG,UAAU,CA8BpG"}