@bonsae/nrg 0.6.0 → 0.6.2

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 (84) hide show
  1. package/README.md +5 -5
  2. package/package.json +14 -75
  3. package/{build/server → server}/index.cjs +1 -1
  4. package/{src/core/client → shims}/components.d.ts +2 -0
  5. package/{src/tsconfig → tsconfig}/client.json +3 -3
  6. package/types/client.d.ts +37 -0
  7. package/types/index.d.ts +211 -0
  8. package/types/server.d.ts +2293 -0
  9. package/types/vite.d.ts +12 -0
  10. package/{build/vite → vite}/index.js +95 -0
  11. package/build/vite/utils.js +0 -56
  12. package/src/core/client/app.vue +0 -185
  13. package/src/core/client/components/node-red-config-input.vue +0 -79
  14. package/src/core/client/components/node-red-editor-input.vue +0 -307
  15. package/src/core/client/components/node-red-input-label.vue +0 -53
  16. package/src/core/client/components/node-red-input.vue +0 -93
  17. package/src/core/client/components/node-red-json-schema-form.vue +0 -444
  18. package/src/core/client/components/node-red-select-input.vue +0 -108
  19. package/src/core/client/components/node-red-toggle.vue +0 -115
  20. package/src/core/client/components/node-red-typed-input.vue +0 -158
  21. package/src/core/client/index.ts +0 -500
  22. package/src/core/client/tsconfig.json +0 -18
  23. package/src/core/constants.ts +0 -18
  24. package/src/core/errors.ts +0 -9
  25. package/src/core/server/api/index.ts +0 -1
  26. package/src/core/server/api/serve-nrg-resources.ts +0 -54
  27. package/src/core/server/index.ts +0 -190
  28. package/src/core/server/nodes/config-node.ts +0 -67
  29. package/src/core/server/nodes/factories.ts +0 -133
  30. package/src/core/server/nodes/index.ts +0 -5
  31. package/src/core/server/nodes/io-node.ts +0 -179
  32. package/src/core/server/nodes/node.ts +0 -259
  33. package/src/core/server/nodes/types/config-node.ts +0 -28
  34. package/src/core/server/nodes/types/factories.ts +0 -115
  35. package/src/core/server/nodes/types/index.ts +0 -4
  36. package/src/core/server/nodes/types/io-node.ts +0 -40
  37. package/src/core/server/nodes/types/node.ts +0 -41
  38. package/src/core/server/nodes/utils.ts +0 -106
  39. package/src/core/server/schemas/base.ts +0 -66
  40. package/src/core/server/schemas/index.ts +0 -3
  41. package/src/core/server/schemas/type.ts +0 -95
  42. package/src/core/server/schemas/types/index.ts +0 -82
  43. package/src/core/server/tsconfig.json +0 -17
  44. package/src/core/server/types/index.ts +0 -220
  45. package/src/core/server/utils.ts +0 -56
  46. package/src/core/server/validator.ts +0 -36
  47. package/src/core/validator.ts +0 -222
  48. package/src/index.ts +0 -2
  49. package/src/types.ts +0 -189
  50. package/src/utils.ts +0 -20
  51. package/src/vite/async-utils.ts +0 -61
  52. package/src/vite/client/build.ts +0 -227
  53. package/src/vite/client/index.ts +0 -1
  54. package/src/vite/client/plugins/html-generator.ts +0 -75
  55. package/src/vite/client/plugins/index.ts +0 -5
  56. package/src/vite/client/plugins/locales-generator.ts +0 -126
  57. package/src/vite/client/plugins/minifier.ts +0 -23
  58. package/src/vite/client/plugins/node-definitions-inliner.ts +0 -275
  59. package/src/vite/client/plugins/static-copy.ts +0 -43
  60. package/src/vite/defaults.ts +0 -77
  61. package/src/vite/errors.ts +0 -37
  62. package/src/vite/index.ts +0 -2
  63. package/src/vite/logger.ts +0 -94
  64. package/src/vite/node-red-launcher.ts +0 -344
  65. package/src/vite/plugin.ts +0 -61
  66. package/src/vite/plugins/build.ts +0 -85
  67. package/src/vite/plugins/index.ts +0 -2
  68. package/src/vite/plugins/server.ts +0 -267
  69. package/src/vite/server/build.ts +0 -124
  70. package/src/vite/server/index.ts +0 -1
  71. package/src/vite/server/plugins/index.ts +0 -3
  72. package/src/vite/server/plugins/output-wrapper.ts +0 -109
  73. package/src/vite/server/plugins/package-json-generator.ts +0 -203
  74. package/src/vite/server/plugins/type-generator.ts +0 -285
  75. package/src/vite/types.ts +0 -174
  76. package/src/vite/utils.ts +0 -72
  77. /package/{build/index.js → index.js} +0 -0
  78. /package/{build/server → server}/resources/nrg-client.js +0 -0
  79. /package/{build/server → server}/resources/vue.esm-browser.js +0 -0
  80. /package/{build/server → server}/resources/vue.esm-browser.prod.js +0 -0
  81. /package/{src/core/client → shims}/globals.d.ts +0 -0
  82. /package/{src/core/client → shims}/shims-vue.d.ts +0 -0
  83. /package/{src/tsconfig → tsconfig}/base.json +0 -0
  84. /package/{src/tsconfig → tsconfig}/server.json +0 -0
@@ -1,222 +0,0 @@
1
- import type {
2
- Options,
3
- ErrorObject,
4
- ErrorsTextOptions,
5
- AnySchemaObject,
6
- ValidateFunction,
7
- KeywordDefinition,
8
- } from "ajv";
9
- import Ajv from "ajv";
10
- import addFormats from "ajv-formats";
11
- import addErrors from "ajv-errors";
12
-
13
- interface ValidationResult<T = unknown> {
14
- valid: boolean;
15
- data?: T;
16
- errors?: ErrorObject[];
17
- errorMessage?: string;
18
- }
19
-
20
- interface ValidatorOptions extends Options {
21
- customKeywords?: string[] | KeywordDefinition[];
22
- customFormats?: Record<string, RegExp | ((data: string) => boolean)>;
23
- }
24
-
25
- interface DetailedError {
26
- field: string;
27
- message: string;
28
- keyword: string;
29
- params: Record<string, unknown>;
30
- schemaPath: string;
31
- }
32
-
33
- interface ValidateOption {
34
- cacheKey?: string;
35
- throwOnError?: boolean;
36
- }
37
-
38
- class Validator {
39
- private readonly ajv: Ajv;
40
-
41
- public constructor(options?: ValidatorOptions) {
42
- const { customKeywords, customFormats, ...ajvOptions } = options || {};
43
-
44
- this.ajv = new Ajv({
45
- allErrors: true,
46
- code: {
47
- source: false,
48
- },
49
- coerceTypes: true,
50
- removeAdditional: false,
51
- strict: false,
52
- strictSchema: false,
53
- useDefaults: true,
54
- validateFormats: true,
55
- // NOTE: typebox handles validation via typescript
56
- // NOTE: if true, types that are not serializable JSON, like Function, would not work
57
- validateSchema: false,
58
- verbose: true,
59
- ...ajvOptions,
60
- });
61
-
62
- addFormats(this.ajv);
63
- addErrors(this.ajv);
64
-
65
- this.addCustomKeywords(customKeywords || []);
66
- this.addCustomFormats(customFormats || {});
67
- }
68
-
69
- /**
70
- * Add custom keywords to the validator
71
- */
72
- private addCustomKeywords(keywords?: string[] | KeywordDefinition[]): void {
73
- if (!keywords) return;
74
- keywords.forEach((keyword) => {
75
- this.ajv.addKeyword(keyword);
76
- });
77
- }
78
-
79
- /**
80
- * Add custom formats to the validator
81
- */
82
- private addCustomFormats(
83
- formats?: Record<string, RegExp | ((data: string) => boolean)>,
84
- ): void {
85
- if (!formats) return;
86
-
87
- Object.entries(formats).forEach(([name, validator]) => {
88
- if (validator instanceof RegExp) {
89
- this.ajv.addFormat(name, validator);
90
- } else {
91
- this.ajv.addFormat(name, { validate: validator });
92
- }
93
- });
94
- }
95
-
96
- /**
97
- * Create a validator function with caching
98
- * @param schema - JSON Schema to validate against
99
- * @param cacheKey - Optional cache key for reusing validators
100
- */
101
- public createValidator(
102
- schema: AnySchemaObject,
103
- cacheKey?: string,
104
- ): ValidateFunction {
105
- if (cacheKey && !schema.$id) {
106
- schema.$id = cacheKey;
107
- }
108
-
109
- if (schema.$id) {
110
- const cached = this.ajv.getSchema(schema.$id);
111
- if (cached) return cached;
112
- }
113
-
114
- const validator = this.ajv.compile(schema);
115
-
116
- return validator;
117
- }
118
-
119
- /**
120
- * Validate data against a schema and return a structured result
121
- */
122
- public validate<T = unknown>(
123
- data: unknown,
124
- schema: AnySchemaObject,
125
- options?: ValidateOption,
126
- ): ValidationResult<T> {
127
- const validator = this.createValidator(schema, options?.cacheKey);
128
- const valid = validator(data);
129
-
130
- if (!valid) {
131
- const errorMessage = this.formatErrors(validator.errors);
132
-
133
- if (options?.throwOnError) {
134
- throw new ValidationError(errorMessage, validator.errors || []);
135
- }
136
-
137
- return {
138
- valid: false,
139
- errors: validator.errors || undefined,
140
- errorMessage,
141
- };
142
- }
143
-
144
- return {
145
- valid: true,
146
- data: data as T,
147
- };
148
- }
149
-
150
- /**
151
- * Format errors into a human-readable string
152
- */
153
- public formatErrors(
154
- errors?: ErrorObject[] | null,
155
- options?: ErrorsTextOptions,
156
- ): string {
157
- if (!errors || errors.length === 0) {
158
- return "No errors";
159
- }
160
-
161
- return this.ajv.errorsText(errors, {
162
- separator: "; ",
163
- dataVar: "data",
164
- ...options,
165
- });
166
- }
167
-
168
- /**
169
- * Get detailed error information
170
- */
171
- public getDetailedErrors(errors?: ErrorObject[] | null): DetailedError[] {
172
- if (!errors || errors.length === 0) return [];
173
-
174
- return errors.map((error) => ({
175
- field: error.instancePath || "/",
176
- message: error.message || "Validation failed",
177
- keyword: error.keyword,
178
- params: error.params,
179
- schemaPath: error.schemaPath,
180
- }));
181
- }
182
-
183
- /**
184
- * Add a schema to the validator for reference
185
- */
186
- public addSchema(schema: AnySchemaObject, key?: string): this {
187
- this.ajv.addSchema(schema, key);
188
- return this;
189
- }
190
-
191
- /**
192
- * Remove a schema from the validator
193
- */
194
- public removeSchema(key: string): this {
195
- this.ajv.removeSchema(key);
196
- return this;
197
- }
198
- }
199
-
200
- /**
201
- * Custom error class for validation errors
202
- */
203
- class ValidationError extends Error {
204
- constructor(
205
- message: string,
206
- public readonly errors: ErrorObject[],
207
- ) {
208
- super(message);
209
- this.name = "ValidationError";
210
- Object.setPrototypeOf(this, ValidationError.prototype);
211
- }
212
- }
213
-
214
- const validator = new Validator();
215
-
216
- export { Validator, ValidationError, validator };
217
- export type {
218
- ValidationResult,
219
- ValidatorOptions,
220
- ValidateOption,
221
- DetailedError,
222
- };
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { defineRuntimeSettings } from "./utils";
2
- export type { NodeRedRuntimeSettings } from "./types";
package/src/types.ts DELETED
@@ -1,189 +0,0 @@
1
- import type { Http2ServerRequest } from "http2";
2
-
3
- export interface NodeRedRuntimeSettings {
4
- userDir?: string;
5
- nodesDir?: string | string[];
6
- flowFile?: string;
7
- flowFilePretty?: boolean;
8
- credentialSecret?: string | false;
9
- requireHttps?: boolean;
10
- https?:
11
- | { key: string; cert: string }
12
- | (() =>
13
- | Promise<{ key: string; cert: string }>
14
- | { key: string; cert: string });
15
- httpsRefreshInterval?: number;
16
- httpAdminRoot?: string;
17
- httpNodeRoot?: string;
18
- httpNodeCors?: { origin: string; methods: string };
19
- httpStatic?: string | { path: string; root: string }[];
20
- httpStaticRoot?: string;
21
- httpAdminMiddleware?: (req: unknown, res: unknown, next: () => void) => void;
22
- httpNodeMiddleware?: (req: unknown, res: unknown, next: () => void) => void;
23
- httpServerOptions?: Record<string, unknown>;
24
- adminAuth?: {
25
- type?: "credentials" | "strategy";
26
- users?: {
27
- username: string;
28
- password: string;
29
- permissions?: string | string[];
30
- }[];
31
- default?: {
32
- permissions?: string | string[];
33
- };
34
- tokens?: (
35
- token: string,
36
- ) => Promise<{ user: string; permissions: string | string[] } | null>;
37
- tokenHeader: "string";
38
- sessionExpiryTime?: number;
39
- [key: string]: unknown;
40
- };
41
- httpNodeAuth?: {
42
- user?: string;
43
- pass?: string;
44
- };
45
- httpStaticAuth?: {
46
- user?: string;
47
- pass?: string;
48
- };
49
- lang?:
50
- | "en-US"
51
- | "de"
52
- | "es-ES"
53
- | "fr"
54
- | "ko"
55
- | "pt-BR"
56
- | "ru"
57
- | "ja"
58
- | "zh-CN"
59
- | "zh-TW";
60
- diagnostics?: {
61
- enabled?: boolean;
62
- ui?: boolean;
63
- };
64
- runtimeState?: {
65
- enabled?: boolean;
66
- ui?: boolean;
67
- };
68
- disableEditor?: boolean;
69
- editorTheme?: {
70
- page?: {
71
- title?: string;
72
- favicon?: string;
73
- css?: string | string[];
74
- scripts?: string | string[];
75
- };
76
- header?: {
77
- title?: string;
78
- image?: string;
79
- url?: string;
80
- };
81
- deployButton?: {
82
- type?: "simple" | "default";
83
- label?: string;
84
- icon?: string;
85
- };
86
- menu?: {
87
- "menu-item-import-library"?: boolean;
88
- "menu-item-export-library"?: boolean;
89
- "menu-item-keyboard-shortcuts"?: boolean;
90
- "menu-item-help"?: {
91
- label?: string;
92
- url?: string;
93
- };
94
- [menuItem: string]:
95
- | boolean
96
- | { label?: string; url?: string }
97
- | undefined;
98
- };
99
- userMenu?: boolean;
100
- login?: {
101
- image?: string;
102
- };
103
- logout?: {
104
- redirect?: string;
105
- };
106
- palette?: {
107
- catalogues?: string[];
108
- categories?: string[];
109
- theme?: { category: string; type: string; color: string }[];
110
- };
111
- projects?: {
112
- enabled?: boolean;
113
- workflow?: {
114
- mode: "manual" | "auto";
115
- };
116
- };
117
- codeEditor?: {
118
- lib?: "monaco" | "ace";
119
- options?: Record<string, unknown>;
120
- };
121
- mermaid?: {
122
- theme?: string;
123
- };
124
- tours?: boolean;
125
- theme?: string;
126
- [key: string]: unknown;
127
- };
128
- contextStorage?: {
129
- default?: {
130
- module?: "memory" | "localfilesystem" | object;
131
- config?: Record<string, unknown>;
132
- };
133
- [store: string]:
134
- | {
135
- module?: "memory" | "localfilesystem" | object;
136
- config?: Record<string, unknown>;
137
- }
138
- | undefined;
139
- };
140
- exportGlobalContextKeys?: boolean;
141
- logging?: {
142
- console?: {
143
- level?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "off";
144
- metrics?: boolean;
145
- audit?: boolean;
146
- };
147
- };
148
- fileWorkingDirectory?: string;
149
- functionExternalModules?: boolean;
150
- functionGlobalContext?: Record<string, unknown>;
151
- nodeMessageBufferMaxLength?: number;
152
- functionTimeout?: number;
153
- externalModules?: {
154
- autoInstall?: boolean;
155
- autoInstallRetry?: number;
156
- palette?: {
157
- allowInstall?: boolean;
158
- allowUpdate?: boolean;
159
- allowUpload?: boolean;
160
- allowList?: string[];
161
- denyList?: string[];
162
- allowUpdateList?: string[];
163
- denyUpdateList?: string[];
164
- };
165
- modules?: {
166
- allowInstall?: boolean;
167
- allowList?: string[];
168
- denyList?: string[];
169
- };
170
- };
171
- execMaxBufferSize?: number;
172
- debugMaxLength?: number;
173
- debugUseColors?: boolean;
174
- httpRequestTimeout?: number;
175
- mqttReconnectTime?: number;
176
- serialReconnectTime?: number;
177
- socketReconnectTime?: number;
178
- socketTimeout?: number;
179
- tcpMsgQueueSize?: number;
180
- inboundWebSocketTimeout?: number;
181
- tlsConfigDisableLocalFiles?: boolean;
182
- webSocketNodeVerifyClient?: (info: {
183
- origin: string;
184
- req: Http2ServerRequest;
185
- secure: boolean;
186
- }) => boolean;
187
- apiMaxLength?: string;
188
- [key: string]: unknown;
189
- }
package/src/utils.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { NodeRedRuntimeSettings } from "./types";
2
-
3
- /**
4
- * Type-safe helper for defining Node-RED runtime settings.
5
- *
6
- * @example
7
- * ```typescript
8
- * import { defineRuntimeSettings } from "@bonsae/nrg";
9
- *
10
- * export default defineRuntimeSettings({
11
- * flowFile: "flows.json",
12
- * flowFilePretty: true,
13
- * });
14
- * ```
15
- */
16
- export function defineRuntimeSettings(
17
- settings: NodeRedRuntimeSettings,
18
- ): NodeRedRuntimeSettings {
19
- return settings;
20
- }
@@ -1,61 +0,0 @@
1
- function debounce<T extends (...args: any[]) => any>(
2
- fn: T,
3
- delay: number,
4
- ): (...args: Parameters<T>) => void {
5
- let timeout: NodeJS.Timeout | null = null;
6
-
7
- return (...args: Parameters<T>) => {
8
- if (timeout) clearTimeout(timeout);
9
- timeout = setTimeout(() => fn(...args), delay);
10
- };
11
- }
12
-
13
- function withTimeout<T>(
14
- promise: Promise<T>,
15
- ms: number,
16
- fallback?: T,
17
- ): Promise<T> {
18
- return new Promise((resolve, reject) => {
19
- const timeout = setTimeout(() => {
20
- if (fallback !== undefined) {
21
- resolve(fallback);
22
- } else {
23
- reject(new Error(`Timeout after ${ms}ms`));
24
- }
25
- }, ms);
26
-
27
- promise
28
- .then((result) => {
29
- clearTimeout(timeout);
30
- resolve(result);
31
- })
32
- .catch((error) => {
33
- clearTimeout(timeout);
34
- reject(error);
35
- });
36
- });
37
- }
38
-
39
- async function retry<T>(
40
- fn: () => Promise<T>,
41
- options: { attempts?: number; delay?: number } = {},
42
- ): Promise<T> {
43
- const { attempts = 3, delay = 1000 } = options;
44
-
45
- let lastError: Error | undefined;
46
-
47
- for (let i = 0; i < attempts; i++) {
48
- try {
49
- return await fn();
50
- } catch (error) {
51
- lastError = error as Error;
52
- if (i < attempts - 1) {
53
- await new Promise((resolve) => setTimeout(resolve, delay));
54
- }
55
- }
56
- }
57
-
58
- throw lastError;
59
- }
60
-
61
- export { debounce, withTimeout, retry };