@squidcloud/local-backend 1.0.65 → 1.0.67

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 (182) hide show
  1. package/dist/common/src/ai-assistant.context.d.ts +13 -13
  2. package/dist/common/src/ai-assistant.context.js +19 -19
  3. package/dist/common/src/ai-assistant.schemas.d.ts +243 -243
  4. package/dist/common/src/ai-assistant.schemas.js +210 -210
  5. package/dist/common/src/ai-assistant.types.d.ts +90 -90
  6. package/dist/common/src/ai-assistant.types.js +11 -11
  7. package/dist/common/src/api-call.context.d.ts +13 -13
  8. package/dist/common/src/api-call.context.js +16 -16
  9. package/dist/common/src/api.types.d.ts +23 -23
  10. package/dist/common/src/api.types.js +2 -2
  11. package/dist/common/src/application.schemas.d.ts +1312 -1312
  12. package/dist/common/src/application.schemas.js +860 -860
  13. package/dist/common/src/application.types.d.ts +186 -186
  14. package/dist/common/src/application.types.js +89 -89
  15. package/dist/common/src/backend-function.schemas.d.ts +3 -3
  16. package/dist/common/src/backend-function.schemas.js +12 -12
  17. package/dist/common/src/backend-function.types.d.ts +6 -6
  18. package/dist/common/src/backend-function.types.js +2 -2
  19. package/dist/common/src/backend-run.types.d.ts +54 -54
  20. package/dist/common/src/backend-run.types.js +96 -96
  21. package/dist/common/src/bundle-api.types.d.ts +63 -63
  22. package/dist/common/src/bundle-api.types.js +2 -2
  23. package/dist/common/src/bundle-data.types.d.ts +59 -59
  24. package/dist/common/src/bundle-data.types.js +2 -2
  25. package/dist/common/src/communication.types.d.ts +18 -18
  26. package/dist/common/src/communication.types.js +40 -40
  27. package/dist/common/src/context.types.d.ts +24 -24
  28. package/dist/common/src/context.types.js +2 -2
  29. package/dist/common/src/distributed-lock.context.d.ts +5 -5
  30. package/dist/common/src/distributed-lock.context.js +10 -10
  31. package/dist/common/src/document.types.d.ts +32 -32
  32. package/dist/common/src/document.types.js +50 -50
  33. package/dist/common/src/graphql.context.d.ts +14 -14
  34. package/dist/common/src/graphql.context.js +12 -12
  35. package/dist/common/src/graphql.types.d.ts +11 -11
  36. package/dist/common/src/graphql.types.js +34 -34
  37. package/dist/common/src/heartbeat.types.d.ts +4 -4
  38. package/dist/common/src/heartbeat.types.js +16 -16
  39. package/dist/common/src/http-status.enum.d.ts +50 -50
  40. package/dist/common/src/http-status.enum.js +54 -54
  41. package/dist/common/src/index.d.ts +55 -55
  42. package/dist/common/src/index.js +71 -71
  43. package/dist/common/src/integrations/ai_assistant.types.d.ts +24 -24
  44. package/dist/common/src/integrations/ai_assistant.types.js +2 -2
  45. package/dist/common/src/integrations/api.types.d.ts +80 -80
  46. package/dist/common/src/integrations/api.types.js +2 -2
  47. package/dist/common/src/integrations/auth.types.d.ts +39 -39
  48. package/dist/common/src/integrations/auth.types.js +2 -2
  49. package/dist/common/src/integrations/database.types.d.ts +231 -231
  50. package/dist/common/src/integrations/database.types.js +2 -2
  51. package/dist/common/src/integrations/index.d.ts +124 -124
  52. package/dist/common/src/integrations/index.js +111 -111
  53. package/dist/common/src/integrations/observability.types.d.ts +23 -23
  54. package/dist/common/src/integrations/observability.types.js +23 -23
  55. package/dist/common/src/logger.types.d.ts +21 -21
  56. package/dist/common/src/logger.types.js +11 -11
  57. package/dist/common/src/metrics.types.d.ts +73 -73
  58. package/dist/common/src/metrics.types.js +11 -11
  59. package/dist/common/src/mutation.context.d.ts +13 -13
  60. package/dist/common/src/mutation.context.js +26 -26
  61. package/dist/common/src/mutation.schemas.d.ts +5 -5
  62. package/dist/common/src/mutation.schemas.js +114 -114
  63. package/dist/common/src/mutation.types.d.ts +63 -63
  64. package/dist/common/src/mutation.types.js +142 -142
  65. package/dist/common/src/named-query.context.d.ts +4 -4
  66. package/dist/common/src/named-query.context.js +9 -9
  67. package/dist/common/src/named-query.schemas.d.ts +3 -3
  68. package/dist/common/src/named-query.schemas.js +13 -13
  69. package/dist/common/src/named-query.types.d.ts +8 -8
  70. package/dist/common/src/named-query.types.js +2 -2
  71. package/dist/common/src/query/base-query-builder.d.ts +37 -37
  72. package/dist/common/src/query/base-query-builder.js +36 -36
  73. package/dist/common/src/query/index.d.ts +4 -4
  74. package/dist/common/src/query/index.js +20 -20
  75. package/dist/common/src/query/pagination.d.ts +42 -42
  76. package/dist/common/src/query/pagination.js +164 -164
  77. package/dist/common/src/query/query-context.d.ts +47 -47
  78. package/dist/common/src/query/query-context.js +159 -159
  79. package/dist/common/src/query/serialized-query.types.d.ts +24 -24
  80. package/dist/common/src/query/serialized-query.types.js +2 -2
  81. package/dist/common/src/query.types.d.ts +86 -86
  82. package/dist/common/src/query.types.js +153 -153
  83. package/dist/common/src/regions.d.ts +21 -21
  84. package/dist/common/src/regions.js +46 -46
  85. package/dist/common/src/schema/schema.types.d.ts +30 -30
  86. package/dist/common/src/schema/schema.types.js +172 -172
  87. package/dist/common/src/secret.schemas.d.ts +6 -6
  88. package/dist/common/src/secret.schemas.js +38 -32
  89. package/dist/common/src/secret.schemas.js.map +1 -1
  90. package/dist/common/src/secret.types.d.ts +49 -49
  91. package/dist/common/src/secret.types.js +5 -5
  92. package/dist/common/src/security.types.d.ts +3 -3
  93. package/dist/common/src/security.types.js +2 -2
  94. package/dist/common/src/socket.schemas.d.ts +3 -3
  95. package/dist/common/src/socket.schemas.js +58 -58
  96. package/dist/common/src/socket.types.d.ts +112 -112
  97. package/dist/common/src/socket.types.js +2 -2
  98. package/dist/common/src/time-units.d.ts +5 -5
  99. package/dist/common/src/time-units.js +8 -8
  100. package/dist/common/src/trigger.types.d.ts +15 -15
  101. package/dist/common/src/trigger.types.js +2 -2
  102. package/dist/common/src/types.d.ts +21 -21
  103. package/dist/common/src/types.js +2 -2
  104. package/dist/common/src/utils/array.d.ts +8 -8
  105. package/dist/common/src/utils/array.js +54 -54
  106. package/dist/common/src/utils/assert.d.ts +8 -8
  107. package/dist/common/src/utils/assert.js +49 -49
  108. package/dist/common/src/utils/error.d.ts +4 -4
  109. package/dist/common/src/utils/error.js +10 -10
  110. package/dist/common/src/utils/global.utils.d.ts +10 -10
  111. package/dist/common/src/utils/global.utils.js +46 -46
  112. package/dist/common/src/utils/http.d.ts +2 -2
  113. package/dist/common/src/utils/http.js +41 -40
  114. package/dist/common/src/utils/http.js.map +1 -1
  115. package/dist/common/src/utils/id.d.ts +2 -2
  116. package/dist/common/src/utils/id.js +21 -21
  117. package/dist/common/src/utils/lock.manager.d.ts +9 -9
  118. package/dist/common/src/utils/lock.manager.js +39 -39
  119. package/dist/common/src/utils/nullish.d.ts +2 -2
  120. package/dist/common/src/utils/nullish.js +11 -11
  121. package/dist/common/src/utils/object.d.ts +5 -5
  122. package/dist/common/src/utils/object.js +75 -75
  123. package/dist/common/src/utils/serialization.d.ts +6 -6
  124. package/dist/common/src/utils/serialization.js +77 -77
  125. package/dist/common/src/utils/transforms.d.ts +18 -18
  126. package/dist/common/src/utils/transforms.js +92 -92
  127. package/dist/common/src/utils/url.d.ts +1 -1
  128. package/dist/common/src/utils/url.js +15 -15
  129. package/dist/common/src/utils/validation.d.ts +17 -17
  130. package/dist/common/src/utils/validation.js +209 -209
  131. package/dist/common/src/webhook-response.d.ts +6 -6
  132. package/dist/common/src/webhook-response.js +2 -2
  133. package/dist/common/src/websocket.impl.d.ts +21 -21
  134. package/dist/common/src/websocket.impl.js +76 -76
  135. package/dist/internal-common/src/async-queue.d.ts +4 -4
  136. package/dist/internal-common/src/async-queue.js +17 -17
  137. package/dist/internal-common/src/code-executor.types.d.ts +13 -13
  138. package/dist/internal-common/src/code-executor.types.js +2 -2
  139. package/dist/internal-common/src/dao.types.d.ts +46 -46
  140. package/dist/internal-common/src/dao.types.js +2 -2
  141. package/dist/internal-common/src/environment/environment.types.d.ts +74 -74
  142. package/dist/internal-common/src/environment/environment.types.js +2 -2
  143. package/dist/internal-common/src/environment/index.d.ts +6 -6
  144. package/dist/internal-common/src/environment/index.js +27 -27
  145. package/dist/internal-common/src/environment/local.environment.d.ts +2 -2
  146. package/dist/internal-common/src/environment/local.environment.js +62 -62
  147. package/dist/internal-common/src/filters/custom-exception.filter.d.ts +6 -6
  148. package/dist/internal-common/src/filters/custom-exception.filter.js +44 -44
  149. package/dist/internal-common/src/index.d.ts +14 -14
  150. package/dist/internal-common/src/index.js +32 -32
  151. package/dist/internal-common/src/interceptors/body.interceptor.d.ts +5 -5
  152. package/dist/internal-common/src/interceptors/body.interceptor.js +24 -24
  153. package/dist/internal-common/src/kafka/kafka.manager.d.ts +22 -22
  154. package/dist/internal-common/src/kafka/kafka.manager.js +129 -129
  155. package/dist/internal-common/src/kafka/kafka.types.d.ts +17 -17
  156. package/dist/internal-common/src/kafka/kafka.types.js +2 -2
  157. package/dist/internal-common/src/kafka-observability-publisher.d.ts +11 -11
  158. package/dist/internal-common/src/kafka-observability-publisher.js +20 -20
  159. package/dist/internal-common/src/local-dev.types.d.ts +35 -35
  160. package/dist/internal-common/src/local-dev.types.js +2 -2
  161. package/dist/internal-common/src/observability-publisher.d.ts +9 -9
  162. package/dist/internal-common/src/observability-publisher.js +58 -58
  163. package/dist/internal-common/src/observability.types.d.ts +17 -17
  164. package/dist/internal-common/src/observability.types.js +2 -2
  165. package/dist/internal-common/src/shutdown.manager.d.ts +20 -20
  166. package/dist/internal-common/src/shutdown.manager.js +75 -75
  167. package/dist/internal-common/src/utils.d.ts +5 -5
  168. package/dist/internal-common/src/utils.js +29 -29
  169. package/dist/local-backend/src/index.d.ts +4 -4
  170. package/dist/local-backend/src/index.js +20 -20
  171. package/dist/local-backend/src/local-backend-socket.service.d.ts +19 -19
  172. package/dist/local-backend/src/local-backend-socket.service.js +110 -110
  173. package/dist/local-backend/src/local-backend.app.d.ts +2 -2
  174. package/dist/local-backend/src/local-backend.app.js +19 -19
  175. package/dist/local-backend/src/local-backend.controller.d.ts +8 -8
  176. package/dist/local-backend/src/local-backend.controller.js +49 -49
  177. package/dist/local-backend/src/local-backend.module.d.ts +8 -8
  178. package/dist/local-backend/src/local-backend.module.js +53 -53
  179. package/dist/local-backend/src/local-backend.service.d.ts +15 -15
  180. package/dist/local-backend/src/local-backend.service.js +165 -165
  181. package/dist/tsconfig.build.tsbuildinfo +1 -1
  182. package/package.json +1 -1
@@ -1,173 +1,173 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findMatchingPropertiesForKey = exports.validateSchema = exports.compileSchema = exports.SUPPORTED_FIELD_TYPES_ARRAY = void 0;
4
- const ajv_1 = require("ajv");
5
- const ajv_formats_1 = require("ajv-formats");
6
- const deep_diff_1 = require("deep-diff");
7
- const http_status_enum_1 = require("../http-status.enum");
8
- const assert_1 = require("../utils/assert");
9
- const validation_1 = require("../utils/validation");
10
- const ajv = new ajv_1.default({ allErrors: true, allowUnionTypes: false, useDefaults: false });
11
- (0, ajv_formats_1.default)(ajv);
12
- ajv.addKeyword({
13
- keyword: 'isDate',
14
- type: 'object',
15
- validate: (isDate, value) => {
16
- return isDate === value instanceof Date;
17
- },
18
- });
19
- ajv.addKeyword({
20
- keyword: 'isJSON',
21
- type: 'object',
22
- validate: (isJSON, value) => {
23
- try {
24
- const jsonString = JSON.stringify(value);
25
- JSON.parse(jsonString);
26
- return true;
27
- }
28
- catch (_a) {
29
- return false;
30
- }
31
- },
32
- });
33
- ajv.addKeyword({
34
- keyword: 'isComputed',
35
- validate: (isComputed, value) => {
36
- return isComputed ? value !== null : true;
37
- },
38
- });
39
- ajv.addKeyword({
40
- keyword: 'isDefaultComputed',
41
- validate: (isDefaultComputed, value) => {
42
- return isDefaultComputed ? value !== null : true;
43
- },
44
- });
45
- ajv.addKeyword({
46
- keyword: 'primaryKey',
47
- validate: (isPrimaryKey, value) => {
48
- return isPrimaryKey ? value !== null : true;
49
- },
50
- });
51
- ajv.addKeyword({
52
- keyword: 'insertable',
53
- validate: (insertable, value) => {
54
- return insertable ? value !== null : true;
55
- },
56
- });
57
- ajv.addKeyword({
58
- keyword: 'deletable',
59
- validate: (deletable, value) => {
60
- return deletable ? value !== null : true;
61
- },
62
- });
63
- ajv.addKeyword({
64
- keyword: 'applyDefaultValueOn',
65
- validate: (applyDefaultValueOn, value) => {
66
- return applyDefaultValueOn ? ['always', 'empty', 'updateOrEmpty'].includes(applyDefaultValueOn) : true;
67
- },
68
- });
69
- ajv.addKeyword({
70
- keyword: 'dataType',
71
- validate: (dataType, value) => {
72
- return true;
73
- },
74
- });
75
- exports.SUPPORTED_FIELD_TYPES_ARRAY = [
76
- 'string',
77
- 'integer',
78
- 'number',
79
- 'date',
80
- 'boolean',
81
- 'map',
82
- 'array',
83
- 'any',
84
- ];
85
- function compileSchema(schema) {
86
- return ajv.compile(schema);
87
- }
88
- exports.compileSchema = compileSchema;
89
- function validateSchema(schema, data, updatedPaths = [], dataBefore = {}) {
90
- const validator = compileSchema(schema);
91
- const isValid = validator(data);
92
- if (!updatedPaths.length && !isValid) {
93
- throw new validation_1.ValidationError(`The data does not conform with the collection schema.`, http_status_enum_1.HttpStatus.BAD_REQUEST, {
94
- errors: validator.errors,
95
- });
96
- }
97
- if (!isValid && updatedPaths.length) {
98
- for (const schemaError of (0, assert_1.truthy)(validator.errors)) {
99
- let fieldPath = schemaError.instancePath;
100
- if (schemaError.params['missingProperty']) {
101
- fieldPath = `${fieldPath}/${schemaError.params['missingProperty']}`;
102
- }
103
- fieldPath = fieldPath.slice(1).replace(/\//g, '.') + '.';
104
- if (updatedPaths.some((updatedPath) => fieldPath.startsWith(updatedPath + '.'))) {
105
- throw new validation_1.ValidationError(`${fieldPath} does not conform with the collection schema.`, http_status_enum_1.HttpStatus.BAD_REQUEST);
106
- }
107
- }
108
- }
109
- const diff = (0, assert_1.truthy)((0, deep_diff_1.default)(dataBefore, data));
110
- validateRestrictedFieldsForDiff(diff, schema, !!updatedPaths.length);
111
- }
112
- exports.validateSchema = validateSchema;
113
- function validateRestrictedFieldsForDiff(diffs, schema, isUpdateMutation) {
114
- if ((isUpdateMutation && schema.readOnly) || (schema.insertable === false && !isUpdateMutation)) {
115
- throw new validation_1.ValidationError(`The schema does not allow this action`, http_status_enum_1.HttpStatus.BAD_REQUEST);
116
- }
117
- for (const diff of diffs) {
118
- const path = (0, assert_1.truthy)(diff.path).join('.');
119
- const relevantProperties = getMatchingProperties((0, assert_1.truthy)(diff.path), schema);
120
- for (const property of relevantProperties.exactMatch) {
121
- if (property.readOnly && diff.kind === 'E') {
122
- throw new validation_1.ValidationError(`${path} is readonly`, http_status_enum_1.HttpStatus.BAD_REQUEST);
123
- }
124
- if (isUpdateMutation && property.deletable === false && diff.kind === 'D') {
125
- throw new validation_1.ValidationError(`${path} is not deletable`, http_status_enum_1.HttpStatus.BAD_REQUEST);
126
- }
127
- if (property.insertable === false && diff.kind === 'N') {
128
- throw new validation_1.ValidationError(`${path} is not insertable`, http_status_enum_1.HttpStatus.BAD_REQUEST);
129
- }
130
- }
131
- for (const property of relevantProperties.parentsMatch) {
132
- if (isUpdateMutation && property.readOnly) {
133
- throw new validation_1.ValidationError(`${path} is readonly`, http_status_enum_1.HttpStatus.BAD_REQUEST);
134
- }
135
- }
136
- }
137
- }
138
- function getMatchingProperties(path, schema) {
139
- const result = {
140
- exactMatch: [],
141
- parentsMatch: [],
142
- };
143
- if (!path.length) {
144
- result.exactMatch.push(schema);
145
- return result;
146
- }
147
- result.parentsMatch.push(schema);
148
- const pathToUse = [...path];
149
- while (pathToUse.length) {
150
- const key = (0, assert_1.notNullish)(pathToUse.shift());
151
- const matchingPropertiesForKey = findMatchingPropertiesForKey(schema, key);
152
- for (const property of matchingPropertiesForKey) {
153
- const subMatchingProperties = getMatchingProperties(pathToUse, property);
154
- result.parentsMatch.push(...subMatchingProperties.parentsMatch);
155
- result.exactMatch.push(...subMatchingProperties.exactMatch);
156
- }
157
- }
158
- return result;
159
- }
160
- function findMatchingPropertiesForKey(schema, key) {
161
- var _a, _b;
162
- const matchingProperties = ((_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key]) ? [(_b = schema.properties) === null || _b === void 0 ? void 0 : _b[key]] : [];
163
- if (schema.patternProperties) {
164
- matchingProperties.push(...Object.entries(schema.patternProperties)
165
- .filter(([pattern]) => {
166
- return new RegExp(pattern).test(key);
167
- })
168
- .map(([_, matchedProperty]) => matchedProperty));
169
- }
170
- return matchingProperties;
171
- }
172
- exports.findMatchingPropertiesForKey = findMatchingPropertiesForKey;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findMatchingPropertiesForKey = exports.validateSchema = exports.compileSchema = exports.SUPPORTED_FIELD_TYPES_ARRAY = void 0;
4
+ const ajv_1 = require("ajv");
5
+ const ajv_formats_1 = require("ajv-formats");
6
+ const deep_diff_1 = require("deep-diff");
7
+ const http_status_enum_1 = require("../http-status.enum");
8
+ const assert_1 = require("../utils/assert");
9
+ const validation_1 = require("../utils/validation");
10
+ const ajv = new ajv_1.default({ allErrors: true, allowUnionTypes: false, useDefaults: false });
11
+ (0, ajv_formats_1.default)(ajv);
12
+ ajv.addKeyword({
13
+ keyword: 'isDate',
14
+ type: 'object',
15
+ validate: (isDate, value) => {
16
+ return isDate === value instanceof Date;
17
+ },
18
+ });
19
+ ajv.addKeyword({
20
+ keyword: 'isJSON',
21
+ type: 'object',
22
+ validate: (isJSON, value) => {
23
+ try {
24
+ const jsonString = JSON.stringify(value);
25
+ JSON.parse(jsonString);
26
+ return true;
27
+ }
28
+ catch (_a) {
29
+ return false;
30
+ }
31
+ },
32
+ });
33
+ ajv.addKeyword({
34
+ keyword: 'isComputed',
35
+ validate: (isComputed, value) => {
36
+ return isComputed ? value !== null : true;
37
+ },
38
+ });
39
+ ajv.addKeyword({
40
+ keyword: 'isDefaultComputed',
41
+ validate: (isDefaultComputed, value) => {
42
+ return isDefaultComputed ? value !== null : true;
43
+ },
44
+ });
45
+ ajv.addKeyword({
46
+ keyword: 'primaryKey',
47
+ validate: (isPrimaryKey, value) => {
48
+ return isPrimaryKey ? value !== null : true;
49
+ },
50
+ });
51
+ ajv.addKeyword({
52
+ keyword: 'insertable',
53
+ validate: (insertable, value) => {
54
+ return insertable ? value !== null : true;
55
+ },
56
+ });
57
+ ajv.addKeyword({
58
+ keyword: 'deletable',
59
+ validate: (deletable, value) => {
60
+ return deletable ? value !== null : true;
61
+ },
62
+ });
63
+ ajv.addKeyword({
64
+ keyword: 'applyDefaultValueOn',
65
+ validate: (applyDefaultValueOn, value) => {
66
+ return applyDefaultValueOn ? ['always', 'empty', 'updateOrEmpty'].includes(applyDefaultValueOn) : true;
67
+ },
68
+ });
69
+ ajv.addKeyword({
70
+ keyword: 'dataType',
71
+ validate: (dataType, value) => {
72
+ return true;
73
+ },
74
+ });
75
+ exports.SUPPORTED_FIELD_TYPES_ARRAY = [
76
+ 'string',
77
+ 'integer',
78
+ 'number',
79
+ 'date',
80
+ 'boolean',
81
+ 'map',
82
+ 'array',
83
+ 'any',
84
+ ];
85
+ function compileSchema(schema) {
86
+ return ajv.compile(schema);
87
+ }
88
+ exports.compileSchema = compileSchema;
89
+ function validateSchema(schema, data, updatedPaths = [], dataBefore = {}) {
90
+ const validator = compileSchema(schema);
91
+ const isValid = validator(data);
92
+ if (!updatedPaths.length && !isValid) {
93
+ throw new validation_1.ValidationError(`The data does not conform with the collection schema.`, http_status_enum_1.HttpStatus.BAD_REQUEST, {
94
+ errors: validator.errors,
95
+ });
96
+ }
97
+ if (!isValid && updatedPaths.length) {
98
+ for (const schemaError of (0, assert_1.truthy)(validator.errors)) {
99
+ let fieldPath = schemaError.instancePath;
100
+ if (schemaError.params['missingProperty']) {
101
+ fieldPath = `${fieldPath}/${schemaError.params['missingProperty']}`;
102
+ }
103
+ fieldPath = fieldPath.slice(1).replace(/\//g, '.') + '.';
104
+ if (updatedPaths.some((updatedPath) => fieldPath.startsWith(updatedPath + '.'))) {
105
+ throw new validation_1.ValidationError(`${fieldPath} does not conform with the collection schema.`, http_status_enum_1.HttpStatus.BAD_REQUEST);
106
+ }
107
+ }
108
+ }
109
+ const diff = (0, assert_1.truthy)((0, deep_diff_1.default)(dataBefore, data));
110
+ validateRestrictedFieldsForDiff(diff, schema, !!updatedPaths.length);
111
+ }
112
+ exports.validateSchema = validateSchema;
113
+ function validateRestrictedFieldsForDiff(diffs, schema, isUpdateMutation) {
114
+ if ((isUpdateMutation && schema.readOnly) || (schema.insertable === false && !isUpdateMutation)) {
115
+ throw new validation_1.ValidationError(`The schema does not allow this action`, http_status_enum_1.HttpStatus.BAD_REQUEST);
116
+ }
117
+ for (const diff of diffs) {
118
+ const path = (0, assert_1.truthy)(diff.path).join('.');
119
+ const relevantProperties = getMatchingProperties((0, assert_1.truthy)(diff.path), schema);
120
+ for (const property of relevantProperties.exactMatch) {
121
+ if (property.readOnly && diff.kind === 'E') {
122
+ throw new validation_1.ValidationError(`${path} is readonly`, http_status_enum_1.HttpStatus.BAD_REQUEST);
123
+ }
124
+ if (isUpdateMutation && property.deletable === false && diff.kind === 'D') {
125
+ throw new validation_1.ValidationError(`${path} is not deletable`, http_status_enum_1.HttpStatus.BAD_REQUEST);
126
+ }
127
+ if (property.insertable === false && diff.kind === 'N') {
128
+ throw new validation_1.ValidationError(`${path} is not insertable`, http_status_enum_1.HttpStatus.BAD_REQUEST);
129
+ }
130
+ }
131
+ for (const property of relevantProperties.parentsMatch) {
132
+ if (isUpdateMutation && property.readOnly) {
133
+ throw new validation_1.ValidationError(`${path} is readonly`, http_status_enum_1.HttpStatus.BAD_REQUEST);
134
+ }
135
+ }
136
+ }
137
+ }
138
+ function getMatchingProperties(path, schema) {
139
+ const result = {
140
+ exactMatch: [],
141
+ parentsMatch: [],
142
+ };
143
+ if (!path.length) {
144
+ result.exactMatch.push(schema);
145
+ return result;
146
+ }
147
+ result.parentsMatch.push(schema);
148
+ const pathToUse = [...path];
149
+ while (pathToUse.length) {
150
+ const key = (0, assert_1.notNullish)(pathToUse.shift());
151
+ const matchingPropertiesForKey = findMatchingPropertiesForKey(schema, key);
152
+ for (const property of matchingPropertiesForKey) {
153
+ const subMatchingProperties = getMatchingProperties(pathToUse, property);
154
+ result.parentsMatch.push(...subMatchingProperties.parentsMatch);
155
+ result.exactMatch.push(...subMatchingProperties.exactMatch);
156
+ }
157
+ }
158
+ return result;
159
+ }
160
+ function findMatchingPropertiesForKey(schema, key) {
161
+ var _a, _b;
162
+ const matchingProperties = ((_a = schema.properties) === null || _a === void 0 ? void 0 : _a[key]) ? [(_b = schema.properties) === null || _b === void 0 ? void 0 : _b[key]] : [];
163
+ if (schema.patternProperties) {
164
+ matchingProperties.push(...Object.entries(schema.patternProperties)
165
+ .filter(([pattern]) => {
166
+ return new RegExp(pattern).test(key);
167
+ })
168
+ .map(([_, matchedProperty]) => matchedProperty));
169
+ }
170
+ return matchingProperties;
171
+ }
172
+ exports.findMatchingPropertiesForKey = findMatchingPropertiesForKey;
173
173
  //# sourceMappingURL=schema.types.js.map
@@ -1,6 +1,6 @@
1
- import { JSONSchemaType } from 'ajv';
2
- import { DeleteApiKeyRequest, DeleteCustomSecretRequest, GenerateNewApiKeyRequest, SetCustomSecretRequest } from './secret.types';
3
- export declare const SetCustomSecretRequestSchema: JSONSchemaType<SetCustomSecretRequest>;
4
- export declare const DeleteCustomSecretRequestSchema: JSONSchemaType<DeleteCustomSecretRequest>;
5
- export declare const DeleteApiKeyRequestSchema: JSONSchemaType<DeleteApiKeyRequest>;
6
- export declare const GenerateNewApiKeyRequestSchema: JSONSchemaType<GenerateNewApiKeyRequest>;
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { DeleteApiKeyRequest, DeleteSecretRequest, GenerateNewApiKeyRequest, SetSecretRequest } from './secret.types';
3
+ export declare const SetSecretRequestSchema: JSONSchemaType<SetSecretRequest>;
4
+ export declare const DeleteSecretRequestSchema: JSONSchemaType<DeleteSecretRequest>;
5
+ export declare const DeleteApiKeyRequestSchema: JSONSchemaType<DeleteApiKeyRequest>;
6
+ export declare const GenerateNewApiKeyRequestSchema: JSONSchemaType<GenerateNewApiKeyRequest>;
@@ -1,33 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GenerateNewApiKeyRequestSchema = exports.DeleteApiKeyRequestSchema = exports.DeleteCustomSecretRequestSchema = exports.SetCustomSecretRequestSchema = void 0;
4
- exports.SetCustomSecretRequestSchema = {
5
- type: 'object',
6
- required: ['key', 'value'],
7
- properties: {
8
- key: { type: 'string', pattern: '[a-zA-Z0-9-_+]', nullable: false },
9
- value: { type: 'string', nullable: false },
10
- },
11
- };
12
- exports.DeleteCustomSecretRequestSchema = {
13
- type: 'object',
14
- required: ['key'],
15
- properties: {
16
- key: { type: 'string', pattern: '[a-zA-Z0-9-_]+', nullable: false, isSecret: {} },
17
- },
18
- };
19
- exports.DeleteApiKeyRequestSchema = {
20
- type: 'object',
21
- required: ['key'],
22
- properties: {
23
- key: { type: 'string', pattern: '[a-zA-Z0-9-_]+', nullable: false, isSecret: { collection: 'apiKeys' } },
24
- },
25
- };
26
- exports.GenerateNewApiKeyRequestSchema = {
27
- type: 'object',
28
- required: ['key'],
29
- properties: {
30
- key: { type: 'string', pattern: '[a-zA-Z0-9-_]+', nullable: false, isSecret: {} },
31
- },
32
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenerateNewApiKeyRequestSchema = exports.DeleteApiKeyRequestSchema = exports.DeleteSecretRequestSchema = exports.SetSecretRequestSchema = void 0;
4
+ exports.SetSecretRequestSchema = {
5
+ type: 'object',
6
+ required: ['key', 'value'],
7
+ properties: {
8
+ key: { type: 'string', pattern: '[a-zA-Z0-9-_+]', nullable: false },
9
+ value: {
10
+ anyOf: [
11
+ { type: 'string', nullable: false },
12
+ { type: 'number', nullable: false },
13
+ { type: 'boolean', nullable: false },
14
+ ],
15
+ },
16
+ },
17
+ };
18
+ exports.DeleteSecretRequestSchema = {
19
+ type: 'object',
20
+ required: ['key'],
21
+ properties: {
22
+ key: { type: 'string', pattern: '[a-zA-Z0-9-_]+', nullable: false, isSecret: {} },
23
+ },
24
+ };
25
+ exports.DeleteApiKeyRequestSchema = {
26
+ type: 'object',
27
+ required: ['key'],
28
+ properties: {
29
+ key: { type: 'string', pattern: '[a-zA-Z0-9-_]+', nullable: false, isSecret: { collection: 'apiKeys' } },
30
+ },
31
+ };
32
+ exports.GenerateNewApiKeyRequestSchema = {
33
+ type: 'object',
34
+ required: ['key'],
35
+ properties: {
36
+ key: { type: 'string', pattern: '[a-zA-Z0-9-_]+', nullable: false, isSecret: {} },
37
+ },
38
+ };
33
39
  //# sourceMappingURL=secret.schemas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"secret.schemas.js","sourceRoot":"","sources":["../../../../common/src/secret.schemas.ts"],"names":[],"mappings":";;;AASa,QAAA,4BAA4B,GAA2C;IAClF,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE;QACnE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC3C;CACF,CAAC;AAGW,QAAA,+BAA+B,GAA8C;IACxF,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,CAAC;IACjB,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;KAClF;CACF,CAAC;AAGW,QAAA,yBAAyB,GAAwC;IAC5E,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,CAAC;IACjB,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE;KACzG;CACF,CAAC;AAGW,QAAA,8BAA8B,GAA6C;IACtF,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,CAAC;IACjB,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;KAClF;CACF,CAAC"}
1
+ {"version":3,"file":"secret.schemas.js","sourceRoot":"","sources":["../../../../common/src/secret.schemas.ts"],"names":[],"mappings":";;;AAIa,QAAA,sBAAsB,GAAqC;IACtE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE;QACnE,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACnC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACnC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE;aACrC;SACF;KACF;CACF,CAAC;AAGW,QAAA,yBAAyB,GAAwC;IAC5E,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,CAAC;IACjB,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;KAClF;CACF,CAAC;AAGW,QAAA,yBAAyB,GAAwC;IAC5E,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,CAAC;IACjB,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE;KACzG;CACF,CAAC;AAGW,QAAA,8BAA8B,GAA6C;IACtF,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,KAAK,CAAC;IACjB,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;KAClF;CACF,CAAC"}
@@ -1,49 +1,49 @@
1
- export type SecretKey = string;
2
- export type SecretValue = string | number | boolean;
3
- export type SecretTimestamp = number;
4
- export type ApiKeyName = string;
5
- export type ApiKey = string;
6
- export declare const BACKEND_API_KEY = "_BACKEND_API_KEY";
7
- export declare const APP_API_KEY = "APP_API_KEY";
8
- export interface ApplicationSecrets {
9
- custom: Record<SecretKey, SecretEntry>;
10
- apiKeys: Record<SecretKey, SecretEntry>;
11
- }
12
- export interface SystemSecrets {
13
- sharedMongo: {
14
- password: string;
15
- };
16
- datadog: {
17
- appKey: string;
18
- apiKey: string;
19
- };
20
- openai: {
21
- apiKey: string;
22
- };
23
- pinecone: {
24
- apiKey: string;
25
- };
26
- }
27
- export interface SecretMetadata {
28
- key: SecretKey;
29
- lastUpdated: SecretTimestamp;
30
- }
31
- export interface SecretEntry extends SecretMetadata {
32
- value: SecretValue;
33
- }
34
- export type SetCustomSecretRequest = Omit<SecretEntry, 'lastUpdated'>;
35
- export interface DeleteCustomSecretRequest {
36
- key: SecretKey;
37
- }
38
- export interface GetApiKeyResponse {
39
- apiKey: string | undefined;
40
- }
41
- export type DeleteApiKeyRequest = Pick<SecretMetadata, 'key'>;
42
- export interface ListApplicationSecretMetadataResponse {
43
- custom: SecretMetadata[];
44
- apiKeys: SecretMetadata[];
45
- }
46
- export type GenerateNewApiKeyRequest = Pick<SecretMetadata, 'key'>;
47
- export interface GenerateNewApiKeyResponse {
48
- apiKey: string;
49
- }
1
+ export type SecretKey = string;
2
+ export type SecretValue = string | number | boolean;
3
+ export type SecretTimestamp = number;
4
+ export type ApiKeyName = string;
5
+ export type ApiKey = string;
6
+ export declare const BACKEND_API_KEY = "_BACKEND_API_KEY";
7
+ export declare const APP_API_KEY = "APP_API_KEY";
8
+ export interface ApplicationSecrets {
9
+ custom: Record<SecretKey, SecretEntry>;
10
+ apiKeys: Record<SecretKey, ApiKeyEntry>;
11
+ }
12
+ export interface SystemSecrets {
13
+ sharedMongo: {
14
+ password: string;
15
+ };
16
+ datadog: {
17
+ appKey: string;
18
+ apiKey: string;
19
+ };
20
+ openai: {
21
+ apiKey: string;
22
+ };
23
+ pinecone: {
24
+ apiKey: string;
25
+ };
26
+ }
27
+ export interface SecretMetadata {
28
+ key: SecretKey;
29
+ lastUpdated: SecretTimestamp;
30
+ }
31
+ export interface SecretEntry<T extends SecretValue = SecretValue> extends SecretMetadata {
32
+ value: T;
33
+ }
34
+ export interface ApiKeyEntry extends SecretMetadata {
35
+ value: string;
36
+ }
37
+ export type SetSecretRequest = Omit<SecretEntry<SecretValue>, 'lastUpdated'>;
38
+ export interface DeleteSecretRequest {
39
+ key: SecretKey;
40
+ }
41
+ export type DeleteApiKeyRequest = Pick<SecretMetadata, 'key'>;
42
+ export interface ListApplicationSecretMetadataResponse {
43
+ custom: SecretMetadata[];
44
+ apiKeys: SecretMetadata[];
45
+ }
46
+ export type GenerateNewApiKeyRequest = Pick<SecretMetadata, 'key'>;
47
+ export interface GenerateNewApiKeyResponse {
48
+ apiKey: string;
49
+ }
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.APP_API_KEY = exports.BACKEND_API_KEY = void 0;
4
- exports.BACKEND_API_KEY = '_BACKEND_API_KEY';
5
- exports.APP_API_KEY = 'APP_API_KEY';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APP_API_KEY = exports.BACKEND_API_KEY = void 0;
4
+ exports.BACKEND_API_KEY = '_BACKEND_API_KEY';
5
+ exports.APP_API_KEY = 'APP_API_KEY';
6
6
  //# sourceMappingURL=secret.types.js.map
@@ -1,3 +1,3 @@
1
- export interface SecureNamedQueryRequest {
2
- params: Record<string, any>;
3
- }
1
+ export interface SecureNamedQueryRequest {
2
+ params: Record<string, any>;
3
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=security.types.js.map
@@ -1,3 +1,3 @@
1
- import { JSONSchemaType } from 'ajv';
2
- import { MessageFromClient } from './socket.types';
3
- export declare const MessageFromClientSchema: JSONSchemaType<MessageFromClient>;
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { MessageFromClient } from './socket.types';
3
+ export declare const MessageFromClientSchema: JSONSchemaType<MessageFromClient>;