@sonicjs-cms/core 2.2.0 → 2.3.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 (105) hide show
  1. package/README.md +75 -1
  2. package/dist/app-Db0AfT5F.d.cts +100 -0
  3. package/dist/app-Db0AfT5F.d.ts +100 -0
  4. package/dist/{chunk-R57VFNP3.js → chunk-3ZLCMOCM.js} +441 -433
  5. package/dist/chunk-3ZLCMOCM.js.map +1 -0
  6. package/dist/{chunk-ZUK55KZB.js → chunk-4C433FET.js} +5 -3
  7. package/dist/chunk-4C433FET.js.map +1 -0
  8. package/dist/{chunk-OORGXYDA.js → chunk-5TRX2JHU.js} +5 -32
  9. package/dist/chunk-5TRX2JHU.js.map +1 -0
  10. package/dist/{chunk-K4Z3IHOK.js → chunk-7CXL5K7N.js} +5 -248
  11. package/dist/chunk-7CXL5K7N.js.map +1 -0
  12. package/dist/{chunk-WBX5YMTB.cjs → chunk-7KCDFDRI.cjs} +27 -15
  13. package/dist/chunk-7KCDFDRI.cjs.map +1 -0
  14. package/dist/chunk-CAMM3MJV.js +1550 -0
  15. package/dist/chunk-CAMM3MJV.js.map +1 -0
  16. package/dist/{chunk-HKEK7UNV.js → chunk-CPXAVWCU.js} +3 -3
  17. package/dist/{chunk-HKEK7UNV.js.map → chunk-CPXAVWCU.js.map} +1 -1
  18. package/dist/{chunk-F5ESJXI2.cjs → chunk-DTLB6UIH.cjs} +3 -3
  19. package/dist/{chunk-F5ESJXI2.cjs.map → chunk-DTLB6UIH.cjs.map} +1 -1
  20. package/dist/{chunk-AINTFRTC.cjs → chunk-ES3BRZQJ.cjs} +252 -2
  21. package/dist/chunk-ES3BRZQJ.cjs.map +1 -0
  22. package/dist/chunk-HBJU3I2Y.cjs +1552 -0
  23. package/dist/chunk-HBJU3I2Y.cjs.map +1 -0
  24. package/dist/{chunk-UEYMFNBN.cjs → chunk-KP4DVEX5.cjs} +7 -36
  25. package/dist/chunk-KP4DVEX5.cjs.map +1 -0
  26. package/dist/{chunk-2DIWLDCA.cjs → chunk-MPFSSBIY.cjs} +541 -533
  27. package/dist/chunk-MPFSSBIY.cjs.map +1 -0
  28. package/dist/{chunk-HV2I6API.cjs → chunk-NAYD76QF.cjs} +4 -251
  29. package/dist/chunk-NAYD76QF.cjs.map +1 -0
  30. package/dist/{chunk-L232U757.js → chunk-Q52ZQFMB.js} +249 -3
  31. package/dist/chunk-Q52ZQFMB.js.map +1 -0
  32. package/dist/{chunk-NMVOTNSL.js → chunk-RRKXFGIO.js} +28 -16
  33. package/dist/chunk-RRKXFGIO.js.map +1 -0
  34. package/dist/{chunk-YTMFJLJZ.cjs → chunk-TT266RYM.cjs} +5 -3
  35. package/dist/chunk-TT266RYM.cjs.map +1 -0
  36. package/dist/collection-config-FLlGtsh9.d.cts +107 -0
  37. package/dist/collection-config-FLlGtsh9.d.ts +107 -0
  38. package/dist/filter-bar.template-By4jeiw_.d.cts +140 -0
  39. package/dist/filter-bar.template-By4jeiw_.d.ts +140 -0
  40. package/dist/index.cjs +146 -165
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +44 -0
  43. package/dist/index.d.ts +43 -5
  44. package/dist/index.js +19 -14
  45. package/dist/index.js.map +1 -1
  46. package/dist/middleware.cjs +24 -33
  47. package/dist/middleware.d.cts +89 -0
  48. package/dist/middleware.d.ts +89 -2
  49. package/dist/middleware.js +3 -4
  50. package/dist/migrations-B2CDNN76.js +4 -0
  51. package/dist/{migrations-IHERIQVD.js.map → migrations-B2CDNN76.js.map} +1 -1
  52. package/dist/migrations-IBKKBIKR.cjs +13 -0
  53. package/dist/{migrations-POFD5KNG.cjs.map → migrations-IBKKBIKR.cjs.map} +1 -1
  54. package/dist/plugin-bootstrap-C0E3jdz-.d.cts +8339 -0
  55. package/dist/plugin-bootstrap-CDh0JHtW.d.ts +8339 -0
  56. package/dist/plugin-manifest-BCMx9CAq.d.cts +35 -0
  57. package/dist/plugin-manifest-BCMx9CAq.d.ts +35 -0
  58. package/dist/plugin-zvZpaiP5.d.cts +357 -0
  59. package/dist/plugin-zvZpaiP5.d.ts +357 -0
  60. package/dist/plugins.cjs +7 -7
  61. package/dist/plugins.d.cts +330 -0
  62. package/dist/plugins.d.ts +330 -2
  63. package/dist/plugins.js +1 -1
  64. package/dist/routes.cjs +27 -27
  65. package/dist/routes.d.cts +224 -0
  66. package/dist/routes.d.ts +224 -2
  67. package/dist/routes.js +7 -7
  68. package/dist/services.cjs +41 -41
  69. package/dist/services.d.cts +236 -0
  70. package/dist/services.d.ts +236 -2
  71. package/dist/services.js +4 -4
  72. package/dist/telemetry-BFBIjBxK.d.cts +36 -0
  73. package/dist/telemetry-BFBIjBxK.d.ts +36 -0
  74. package/dist/templates.d.cts +133 -0
  75. package/dist/templates.d.ts +133 -2
  76. package/dist/types.d.cts +7 -0
  77. package/dist/types.d.ts +7 -2
  78. package/dist/utils.cjs +27 -27
  79. package/dist/utils.d.cts +53 -0
  80. package/dist/utils.d.ts +53 -2
  81. package/dist/utils.js +2 -2
  82. package/dist/version-vktVAxhe.d.cts +195 -0
  83. package/dist/version-vktVAxhe.d.ts +195 -0
  84. package/migrations/001_initial_schema.sql +1 -1
  85. package/package.json +3 -1
  86. package/dist/chunk-2DIWLDCA.cjs.map +0 -1
  87. package/dist/chunk-AINTFRTC.cjs.map +0 -1
  88. package/dist/chunk-HV2I6API.cjs.map +0 -1
  89. package/dist/chunk-K4Z3IHOK.js.map +0 -1
  90. package/dist/chunk-L232U757.js.map +0 -1
  91. package/dist/chunk-NMVOTNSL.js.map +0 -1
  92. package/dist/chunk-OORGXYDA.js.map +0 -1
  93. package/dist/chunk-R57VFNP3.js.map +0 -1
  94. package/dist/chunk-T7IYBGGO.cjs +0 -746
  95. package/dist/chunk-T7IYBGGO.cjs.map +0 -1
  96. package/dist/chunk-UEYMFNBN.cjs.map +0 -1
  97. package/dist/chunk-WBX5YMTB.cjs.map +0 -1
  98. package/dist/chunk-YTMFJLJZ.cjs.map +0 -1
  99. package/dist/chunk-ZPMFT2JW.js +0 -744
  100. package/dist/chunk-ZPMFT2JW.js.map +0 -1
  101. package/dist/chunk-ZUK55KZB.js.map +0 -1
  102. package/dist/migrations-IHERIQVD.js +0 -4
  103. package/dist/migrations-POFD5KNG.cjs +0 -13
  104. package/migrations/013_code_examples_plugin.sql +0 -177
  105. /package/migrations/{021_add_otp_login.sql → 026_add_otp_login.sql} +0 -0
@@ -0,0 +1,195 @@
1
+ /**
2
+ * HTML sanitization utilities for preventing XSS attacks
3
+ */
4
+ /**
5
+ * Escapes HTML special characters to prevent XSS attacks
6
+ * @param text - The text to escape
7
+ * @returns The escaped text safe for HTML output
8
+ */
9
+ declare function escapeHtml(text: string): string;
10
+ /**
11
+ * Sanitizes user input by escaping HTML special characters
12
+ * This should be used for all user-provided text fields to prevent XSS
13
+ * @param input - The input string to sanitize
14
+ * @returns The sanitized string
15
+ */
16
+ declare function sanitizeInput(input: string | null | undefined): string;
17
+ /**
18
+ * Sanitizes an object's string properties
19
+ * @param obj - Object with string properties to sanitize
20
+ * @param fields - Array of field names to sanitize
21
+ * @returns New object with sanitized fields
22
+ */
23
+ declare function sanitizeObject<T extends Record<string, any>>(obj: T, fields: (keyof T)[]): T;
24
+
25
+ interface TemplateData {
26
+ [key: string]: any;
27
+ }
28
+ declare class TemplateRenderer {
29
+ private templateCache;
30
+ constructor();
31
+ /**
32
+ * Simple Handlebars-like template engine
33
+ */
34
+ private renderTemplate;
35
+ /**
36
+ * Get nested value from object using dot notation
37
+ */
38
+ private getNestedValue;
39
+ /**
40
+ * Title case helper function
41
+ */
42
+ private titleCase;
43
+ /**
44
+ * Render a template string with data
45
+ */
46
+ render(template: string, data?: TemplateData): string;
47
+ /**
48
+ * Clear template cache (useful for development)
49
+ */
50
+ clearCache(): void;
51
+ }
52
+ declare const templateRenderer: TemplateRenderer;
53
+ declare function renderTemplate(template: string, data?: TemplateData): string;
54
+
55
+ /**
56
+ * Query Filter Builder for SonicJS AI
57
+ * Supports comprehensive filtering with AND/OR logic
58
+ * Compatible with D1 Database (SQLite)
59
+ */
60
+ type FilterOperator = 'equals' | 'not_equals' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'contains' | 'in' | 'not_in' | 'all' | 'exists' | 'near' | 'within' | 'intersects';
61
+ interface FilterCondition {
62
+ field: string;
63
+ operator: FilterOperator;
64
+ value: any;
65
+ }
66
+ interface FilterGroup {
67
+ and?: FilterCondition[];
68
+ or?: FilterCondition[];
69
+ }
70
+ interface QueryFilter {
71
+ where?: FilterGroup;
72
+ limit?: number;
73
+ offset?: number;
74
+ sort?: {
75
+ field: string;
76
+ order: 'asc' | 'desc';
77
+ }[];
78
+ }
79
+ interface QueryResult {
80
+ sql: string;
81
+ params: any[];
82
+ errors: string[];
83
+ }
84
+ /**
85
+ * Query Filter Builder
86
+ * Converts filter objects into SQL WHERE clauses with parameterized queries
87
+ */
88
+ declare class QueryFilterBuilder {
89
+ private params;
90
+ private errors;
91
+ /**
92
+ * Build a complete SQL query from filter object
93
+ */
94
+ build(baseTable: string, filter: QueryFilter): QueryResult;
95
+ /**
96
+ * Build WHERE clause from filter group
97
+ */
98
+ private buildWhereClause;
99
+ /**
100
+ * Build a single condition
101
+ */
102
+ private buildCondition;
103
+ /**
104
+ * Build equals condition
105
+ */
106
+ private buildEquals;
107
+ /**
108
+ * Build not equals condition
109
+ */
110
+ private buildNotEquals;
111
+ /**
112
+ * Build comparison condition (>, >=, <, <=)
113
+ */
114
+ private buildComparison;
115
+ /**
116
+ * Build LIKE condition (case-insensitive, all words must be present)
117
+ */
118
+ private buildLike;
119
+ /**
120
+ * Build CONTAINS condition (case-insensitive substring)
121
+ */
122
+ private buildContains;
123
+ /**
124
+ * Build IN condition
125
+ */
126
+ private buildIn;
127
+ /**
128
+ * Build NOT IN condition
129
+ */
130
+ private buildNotIn;
131
+ /**
132
+ * Build ALL condition (value must contain all items in list)
133
+ * For SQLite, we'll check if a JSON array contains all values
134
+ */
135
+ private buildAll;
136
+ /**
137
+ * Build EXISTS condition
138
+ */
139
+ private buildExists;
140
+ /**
141
+ * Sanitize field names to prevent SQL injection
142
+ */
143
+ private sanitizeFieldName;
144
+ /**
145
+ * Parse filter from query string
146
+ */
147
+ static parseFromQuery(query: Record<string, any>): QueryFilter;
148
+ }
149
+ /**
150
+ * Helper function to build query from filter
151
+ */
152
+ declare function buildQuery(table: string, filter: QueryFilter): QueryResult;
153
+
154
+ /**
155
+ * Simple in-memory metrics tracker for real-time analytics
156
+ * Tracks requests per second using a sliding window
157
+ */
158
+ declare class MetricsTracker {
159
+ private requests;
160
+ private readonly windowSize;
161
+ /**
162
+ * Record a new request
163
+ */
164
+ recordRequest(): void;
165
+ /**
166
+ * Clean up old requests outside the window
167
+ */
168
+ private cleanup;
169
+ /**
170
+ * Get current requests per second
171
+ */
172
+ getRequestsPerSecond(): number;
173
+ /**
174
+ * Get total requests in the current window
175
+ */
176
+ getTotalRequests(): number;
177
+ /**
178
+ * Get average requests per second over the window
179
+ */
180
+ getAverageRPS(): number;
181
+ }
182
+ declare const metricsTracker: MetricsTracker;
183
+
184
+ /**
185
+ * Version utility
186
+ *
187
+ * Provides the current version of @sonicjs-cms/core package
188
+ */
189
+ declare const SONICJS_VERSION: string;
190
+ /**
191
+ * Get the current SonicJS core version
192
+ */
193
+ declare function getCoreVersion(): string;
194
+
195
+ export { type FilterOperator as F, QueryFilterBuilder as Q, SONICJS_VERSION as S, TemplateRenderer as T, sanitizeObject as a, buildQuery as b, type FilterCondition as c, type FilterGroup as d, escapeHtml as e, type QueryFilter as f, getCoreVersion as g, type QueryResult as h, metricsTracker as m, renderTemplate as r, sanitizeInput as s, templateRenderer as t };
@@ -0,0 +1,195 @@
1
+ /**
2
+ * HTML sanitization utilities for preventing XSS attacks
3
+ */
4
+ /**
5
+ * Escapes HTML special characters to prevent XSS attacks
6
+ * @param text - The text to escape
7
+ * @returns The escaped text safe for HTML output
8
+ */
9
+ declare function escapeHtml(text: string): string;
10
+ /**
11
+ * Sanitizes user input by escaping HTML special characters
12
+ * This should be used for all user-provided text fields to prevent XSS
13
+ * @param input - The input string to sanitize
14
+ * @returns The sanitized string
15
+ */
16
+ declare function sanitizeInput(input: string | null | undefined): string;
17
+ /**
18
+ * Sanitizes an object's string properties
19
+ * @param obj - Object with string properties to sanitize
20
+ * @param fields - Array of field names to sanitize
21
+ * @returns New object with sanitized fields
22
+ */
23
+ declare function sanitizeObject<T extends Record<string, any>>(obj: T, fields: (keyof T)[]): T;
24
+
25
+ interface TemplateData {
26
+ [key: string]: any;
27
+ }
28
+ declare class TemplateRenderer {
29
+ private templateCache;
30
+ constructor();
31
+ /**
32
+ * Simple Handlebars-like template engine
33
+ */
34
+ private renderTemplate;
35
+ /**
36
+ * Get nested value from object using dot notation
37
+ */
38
+ private getNestedValue;
39
+ /**
40
+ * Title case helper function
41
+ */
42
+ private titleCase;
43
+ /**
44
+ * Render a template string with data
45
+ */
46
+ render(template: string, data?: TemplateData): string;
47
+ /**
48
+ * Clear template cache (useful for development)
49
+ */
50
+ clearCache(): void;
51
+ }
52
+ declare const templateRenderer: TemplateRenderer;
53
+ declare function renderTemplate(template: string, data?: TemplateData): string;
54
+
55
+ /**
56
+ * Query Filter Builder for SonicJS AI
57
+ * Supports comprehensive filtering with AND/OR logic
58
+ * Compatible with D1 Database (SQLite)
59
+ */
60
+ type FilterOperator = 'equals' | 'not_equals' | 'greater_than' | 'greater_than_equal' | 'less_than' | 'less_than_equal' | 'like' | 'contains' | 'in' | 'not_in' | 'all' | 'exists' | 'near' | 'within' | 'intersects';
61
+ interface FilterCondition {
62
+ field: string;
63
+ operator: FilterOperator;
64
+ value: any;
65
+ }
66
+ interface FilterGroup {
67
+ and?: FilterCondition[];
68
+ or?: FilterCondition[];
69
+ }
70
+ interface QueryFilter {
71
+ where?: FilterGroup;
72
+ limit?: number;
73
+ offset?: number;
74
+ sort?: {
75
+ field: string;
76
+ order: 'asc' | 'desc';
77
+ }[];
78
+ }
79
+ interface QueryResult {
80
+ sql: string;
81
+ params: any[];
82
+ errors: string[];
83
+ }
84
+ /**
85
+ * Query Filter Builder
86
+ * Converts filter objects into SQL WHERE clauses with parameterized queries
87
+ */
88
+ declare class QueryFilterBuilder {
89
+ private params;
90
+ private errors;
91
+ /**
92
+ * Build a complete SQL query from filter object
93
+ */
94
+ build(baseTable: string, filter: QueryFilter): QueryResult;
95
+ /**
96
+ * Build WHERE clause from filter group
97
+ */
98
+ private buildWhereClause;
99
+ /**
100
+ * Build a single condition
101
+ */
102
+ private buildCondition;
103
+ /**
104
+ * Build equals condition
105
+ */
106
+ private buildEquals;
107
+ /**
108
+ * Build not equals condition
109
+ */
110
+ private buildNotEquals;
111
+ /**
112
+ * Build comparison condition (>, >=, <, <=)
113
+ */
114
+ private buildComparison;
115
+ /**
116
+ * Build LIKE condition (case-insensitive, all words must be present)
117
+ */
118
+ private buildLike;
119
+ /**
120
+ * Build CONTAINS condition (case-insensitive substring)
121
+ */
122
+ private buildContains;
123
+ /**
124
+ * Build IN condition
125
+ */
126
+ private buildIn;
127
+ /**
128
+ * Build NOT IN condition
129
+ */
130
+ private buildNotIn;
131
+ /**
132
+ * Build ALL condition (value must contain all items in list)
133
+ * For SQLite, we'll check if a JSON array contains all values
134
+ */
135
+ private buildAll;
136
+ /**
137
+ * Build EXISTS condition
138
+ */
139
+ private buildExists;
140
+ /**
141
+ * Sanitize field names to prevent SQL injection
142
+ */
143
+ private sanitizeFieldName;
144
+ /**
145
+ * Parse filter from query string
146
+ */
147
+ static parseFromQuery(query: Record<string, any>): QueryFilter;
148
+ }
149
+ /**
150
+ * Helper function to build query from filter
151
+ */
152
+ declare function buildQuery(table: string, filter: QueryFilter): QueryResult;
153
+
154
+ /**
155
+ * Simple in-memory metrics tracker for real-time analytics
156
+ * Tracks requests per second using a sliding window
157
+ */
158
+ declare class MetricsTracker {
159
+ private requests;
160
+ private readonly windowSize;
161
+ /**
162
+ * Record a new request
163
+ */
164
+ recordRequest(): void;
165
+ /**
166
+ * Clean up old requests outside the window
167
+ */
168
+ private cleanup;
169
+ /**
170
+ * Get current requests per second
171
+ */
172
+ getRequestsPerSecond(): number;
173
+ /**
174
+ * Get total requests in the current window
175
+ */
176
+ getTotalRequests(): number;
177
+ /**
178
+ * Get average requests per second over the window
179
+ */
180
+ getAverageRPS(): number;
181
+ }
182
+ declare const metricsTracker: MetricsTracker;
183
+
184
+ /**
185
+ * Version utility
186
+ *
187
+ * Provides the current version of @sonicjs-cms/core package
188
+ */
189
+ declare const SONICJS_VERSION: string;
190
+ /**
191
+ * Get the current SonicJS core version
192
+ */
193
+ declare function getCoreVersion(): string;
194
+
195
+ export { type FilterOperator as F, QueryFilterBuilder as Q, SONICJS_VERSION as S, TemplateRenderer as T, sanitizeObject as a, buildQuery as b, type FilterCondition as c, type FilterGroup as d, escapeHtml as e, type QueryFilter as f, getCoreVersion as g, type QueryResult as h, metricsTracker as m, renderTemplate as r, sanitizeInput as s, templateRenderer as t };
@@ -139,7 +139,7 @@ INSERT OR IGNORE INTO users (
139
139
  'admin',
140
140
  'Admin',
141
141
  'User',
142
- 'd1c379e871838f44e21d5a55841349e50636f06df139bfef11870eec74c381db', -- SHA-256 hash of 'sonicjs!'
142
+ '9c9ec10df964f588e51acc794a63f18d5582e9b91c8366ba292ebde84d3834fd', -- SHA-256 hash of 'sonicjs!' with salt
143
143
  'admin',
144
144
  1,
145
145
  strftime('%s', 'now') * 1000,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonicjs-cms/core",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Core framework for SonicJS headless CMS - Edge-first, TypeScript-native CMS built for Cloudflare Workers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -56,6 +56,8 @@
56
56
  "LICENSE"
57
57
  ],
58
58
  "scripts": {
59
+ "generate:migrations": "npx tsx scripts/generate-migrations.ts",
60
+ "prebuild": "npm run generate:migrations",
59
61
  "build": "tsup",
60
62
  "dev": "tsup --watch",
61
63
  "type-check": "tsc --noEmit",