@teleporthq/teleport-plugin-common 0.45.3-alpha.0 → 0.45.13

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 (200) hide show
  1. package/__tests__/builders/html-builders.ts +9 -2
  2. package/__tests__/builders/style-builders.ts +135 -1
  3. package/__tests__/node-handlers/node-to-html/index.ts +2 -0
  4. package/__tests__/node-handlers/node-to-jsx/attribute-value-mapper.ts +77 -0
  5. package/__tests__/node-handlers/node-to-jsx/calendar-events-reviver.ts +176 -0
  6. package/__tests__/node-handlers/node-to-jsx/chart-data-guard.ts +101 -0
  7. package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-ecommerce-source.ts +79 -0
  8. package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-loading.ts +122 -0
  9. package/__tests__/node-handlers/node-to-jsx/index.ts +719 -3
  10. package/__tests__/node-handlers/node-to-jsx/url-search-params-expression.ts +59 -0
  11. package/__tests__/node-handlers/node-to-jsx/utils.ts +635 -3
  12. package/__tests__/utils/ast-utils.ts +188 -0
  13. package/__tests__/utils/content-property-sanitiser.ts +156 -0
  14. package/__tests__/utils/page-seeds-state-from-data-source.ts +70 -0
  15. package/__tests__/utils/parse-string-with-template-expressions.ts +82 -0
  16. package/__tests__/utils/resource-auth-scheme.ts +55 -0
  17. package/__tests__/utils/route-utils.ts +118 -0
  18. package/__tests__/utils/style-utils.ts +59 -0
  19. package/__tests__/utils/template-expression-balance.ts +83 -0
  20. package/__tests__/utils/url-query-writer.ts +239 -0
  21. package/__tests__/utils/url-search-param-sync.ts +138 -0
  22. package/__tests__/utils/url-search-params.ts +48 -0
  23. package/dist/cjs/builders/ast-builders.d.ts +2 -0
  24. package/dist/cjs/builders/ast-builders.d.ts.map +1 -1
  25. package/dist/cjs/builders/ast-builders.js +41 -3
  26. package/dist/cjs/builders/ast-builders.js.map +1 -1
  27. package/dist/cjs/builders/hast-builders.d.ts +1 -0
  28. package/dist/cjs/builders/hast-builders.d.ts.map +1 -1
  29. package/dist/cjs/builders/hast-builders.js +11 -1
  30. package/dist/cjs/builders/hast-builders.js.map +1 -1
  31. package/dist/cjs/builders/style-builders.d.ts +8 -2
  32. package/dist/cjs/builders/style-builders.d.ts.map +1 -1
  33. package/dist/cjs/builders/style-builders.js +80 -33
  34. package/dist/cjs/builders/style-builders.js.map +1 -1
  35. package/dist/cjs/index.d.ts +5 -1
  36. package/dist/cjs/index.d.ts.map +1 -1
  37. package/dist/cjs/index.js +10 -1
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/node-handlers/node-to-html/constants.d.ts.map +1 -1
  40. package/dist/cjs/node-handlers/node-to-html/constants.js +2 -0
  41. package/dist/cjs/node-handlers/node-to-html/constants.js.map +1 -1
  42. package/dist/cjs/node-handlers/node-to-html/index.d.ts.map +1 -1
  43. package/dist/cjs/node-handlers/node-to-html/index.js +69 -1
  44. package/dist/cjs/node-handlers/node-to-html/index.js.map +1 -1
  45. package/dist/cjs/node-handlers/node-to-html/types.d.ts +5 -1
  46. package/dist/cjs/node-handlers/node-to-html/types.d.ts.map +1 -1
  47. package/dist/cjs/node-handlers/node-to-html/utils.d.ts +2 -1
  48. package/dist/cjs/node-handlers/node-to-html/utils.d.ts.map +1 -1
  49. package/dist/cjs/node-handlers/node-to-html/utils.js +174 -13
  50. package/dist/cjs/node-handlers/node-to-html/utils.js.map +1 -1
  51. package/dist/cjs/node-handlers/node-to-jsx/index.d.ts.map +1 -1
  52. package/dist/cjs/node-handlers/node-to-jsx/index.js +1443 -45
  53. package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
  54. package/dist/cjs/node-handlers/node-to-jsx/types.d.ts +60 -6
  55. package/dist/cjs/node-handlers/node-to-jsx/types.d.ts.map +1 -1
  56. package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts +80 -7
  57. package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
  58. package/dist/cjs/node-handlers/node-to-jsx/utils.js +883 -72
  59. package/dist/cjs/node-handlers/node-to-jsx/utils.js.map +1 -1
  60. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  61. package/dist/cjs/utils/ast-utils.d.ts +163 -11
  62. package/dist/cjs/utils/ast-utils.d.ts.map +1 -1
  63. package/dist/cjs/utils/ast-utils.js +1013 -75
  64. package/dist/cjs/utils/ast-utils.js.map +1 -1
  65. package/dist/cjs/utils/hast-utils.d.ts +8 -6
  66. package/dist/cjs/utils/hast-utils.d.ts.map +1 -1
  67. package/dist/cjs/utils/hast-utils.js +28 -4
  68. package/dist/cjs/utils/hast-utils.js.map +1 -1
  69. package/dist/cjs/utils/nested-selector-commas.d.ts +2 -0
  70. package/dist/cjs/utils/nested-selector-commas.d.ts.map +1 -0
  71. package/dist/cjs/utils/nested-selector-commas.js +81 -0
  72. package/dist/cjs/utils/nested-selector-commas.js.map +1 -0
  73. package/dist/cjs/utils/route-utils.d.ts +117 -0
  74. package/dist/cjs/utils/route-utils.d.ts.map +1 -0
  75. package/dist/cjs/utils/route-utils.js +212 -0
  76. package/dist/cjs/utils/route-utils.js.map +1 -0
  77. package/dist/cjs/utils/style-utils.d.ts +1 -0
  78. package/dist/cjs/utils/style-utils.d.ts.map +1 -1
  79. package/dist/cjs/utils/style-utils.js +181 -2
  80. package/dist/cjs/utils/style-utils.js.map +1 -1
  81. package/dist/cjs/utils/template-expression-balance.d.ts +58 -0
  82. package/dist/cjs/utils/template-expression-balance.d.ts.map +1 -0
  83. package/dist/cjs/utils/template-expression-balance.js +181 -0
  84. package/dist/cjs/utils/template-expression-balance.js.map +1 -0
  85. package/dist/cjs/utils/types.d.ts +3 -0
  86. package/dist/cjs/utils/types.d.ts.map +1 -0
  87. package/dist/cjs/utils/types.js +3 -0
  88. package/dist/cjs/utils/types.js.map +1 -0
  89. package/dist/cjs/utils/url-query-writer.d.ts +123 -0
  90. package/dist/cjs/utils/url-query-writer.d.ts.map +1 -0
  91. package/dist/cjs/utils/url-query-writer.js +260 -0
  92. package/dist/cjs/utils/url-query-writer.js.map +1 -0
  93. package/dist/cjs/utils/url-search-param-sync.d.ts +4 -0
  94. package/dist/cjs/utils/url-search-param-sync.d.ts.map +1 -0
  95. package/dist/cjs/utils/url-search-param-sync.js +241 -0
  96. package/dist/cjs/utils/url-search-param-sync.js.map +1 -0
  97. package/dist/cjs/utils/url-search-params.d.ts +48 -0
  98. package/dist/cjs/utils/url-search-params.d.ts.map +1 -0
  99. package/dist/cjs/utils/url-search-params.js +109 -0
  100. package/dist/cjs/utils/url-search-params.js.map +1 -0
  101. package/dist/esm/builders/ast-builders.d.ts +2 -0
  102. package/dist/esm/builders/ast-builders.d.ts.map +1 -1
  103. package/dist/esm/builders/ast-builders.js +40 -4
  104. package/dist/esm/builders/ast-builders.js.map +1 -1
  105. package/dist/esm/builders/hast-builders.d.ts +1 -0
  106. package/dist/esm/builders/hast-builders.d.ts.map +1 -1
  107. package/dist/esm/builders/hast-builders.js +9 -0
  108. package/dist/esm/builders/hast-builders.js.map +1 -1
  109. package/dist/esm/builders/style-builders.d.ts +8 -2
  110. package/dist/esm/builders/style-builders.d.ts.map +1 -1
  111. package/dist/esm/builders/style-builders.js +78 -32
  112. package/dist/esm/builders/style-builders.js.map +1 -1
  113. package/dist/esm/index.d.ts +5 -1
  114. package/dist/esm/index.d.ts.map +1 -1
  115. package/dist/esm/index.js +5 -1
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/node-handlers/node-to-html/constants.d.ts.map +1 -1
  118. package/dist/esm/node-handlers/node-to-html/constants.js +2 -0
  119. package/dist/esm/node-handlers/node-to-html/constants.js.map +1 -1
  120. package/dist/esm/node-handlers/node-to-html/index.d.ts.map +1 -1
  121. package/dist/esm/node-handlers/node-to-html/index.js +71 -3
  122. package/dist/esm/node-handlers/node-to-html/index.js.map +1 -1
  123. package/dist/esm/node-handlers/node-to-html/types.d.ts +5 -1
  124. package/dist/esm/node-handlers/node-to-html/types.d.ts.map +1 -1
  125. package/dist/esm/node-handlers/node-to-html/utils.d.ts +2 -1
  126. package/dist/esm/node-handlers/node-to-html/utils.d.ts.map +1 -1
  127. package/dist/esm/node-handlers/node-to-html/utils.js +170 -13
  128. package/dist/esm/node-handlers/node-to-html/utils.js.map +1 -1
  129. package/dist/esm/node-handlers/node-to-jsx/index.d.ts.map +1 -1
  130. package/dist/esm/node-handlers/node-to-jsx/index.js +1442 -47
  131. package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
  132. package/dist/esm/node-handlers/node-to-jsx/types.d.ts +60 -6
  133. package/dist/esm/node-handlers/node-to-jsx/types.d.ts.map +1 -1
  134. package/dist/esm/node-handlers/node-to-jsx/utils.d.ts +80 -7
  135. package/dist/esm/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
  136. package/dist/esm/node-handlers/node-to-jsx/utils.js +875 -70
  137. package/dist/esm/node-handlers/node-to-jsx/utils.js.map +1 -1
  138. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  139. package/dist/esm/utils/ast-utils.d.ts +163 -11
  140. package/dist/esm/utils/ast-utils.d.ts.map +1 -1
  141. package/dist/esm/utils/ast-utils.js +989 -75
  142. package/dist/esm/utils/ast-utils.js.map +1 -1
  143. package/dist/esm/utils/hast-utils.d.ts +8 -6
  144. package/dist/esm/utils/hast-utils.d.ts.map +1 -1
  145. package/dist/esm/utils/hast-utils.js +26 -3
  146. package/dist/esm/utils/hast-utils.js.map +1 -1
  147. package/dist/esm/utils/nested-selector-commas.d.ts +2 -0
  148. package/dist/esm/utils/nested-selector-commas.d.ts.map +1 -0
  149. package/dist/esm/utils/nested-selector-commas.js +77 -0
  150. package/dist/esm/utils/nested-selector-commas.js.map +1 -0
  151. package/dist/esm/utils/route-utils.d.ts +117 -0
  152. package/dist/esm/utils/route-utils.d.ts.map +1 -0
  153. package/dist/esm/utils/route-utils.js +179 -0
  154. package/dist/esm/utils/route-utils.js.map +1 -0
  155. package/dist/esm/utils/style-utils.d.ts +1 -0
  156. package/dist/esm/utils/style-utils.d.ts.map +1 -1
  157. package/dist/esm/utils/style-utils.js +179 -1
  158. package/dist/esm/utils/style-utils.js.map +1 -1
  159. package/dist/esm/utils/template-expression-balance.d.ts +58 -0
  160. package/dist/esm/utils/template-expression-balance.d.ts.map +1 -0
  161. package/dist/esm/utils/template-expression-balance.js +174 -0
  162. package/dist/esm/utils/template-expression-balance.js.map +1 -0
  163. package/dist/esm/utils/types.d.ts +3 -0
  164. package/dist/esm/utils/types.d.ts.map +1 -0
  165. package/dist/esm/utils/types.js +2 -0
  166. package/dist/esm/utils/types.js.map +1 -0
  167. package/dist/esm/utils/url-query-writer.d.ts +123 -0
  168. package/dist/esm/utils/url-query-writer.d.ts.map +1 -0
  169. package/dist/esm/utils/url-query-writer.js +229 -0
  170. package/dist/esm/utils/url-query-writer.js.map +1 -0
  171. package/dist/esm/utils/url-search-param-sync.d.ts +4 -0
  172. package/dist/esm/utils/url-search-param-sync.d.ts.map +1 -0
  173. package/dist/esm/utils/url-search-param-sync.js +213 -0
  174. package/dist/esm/utils/url-search-param-sync.js.map +1 -0
  175. package/dist/esm/utils/url-search-params.d.ts +48 -0
  176. package/dist/esm/utils/url-search-params.d.ts.map +1 -0
  177. package/dist/esm/utils/url-search-params.js +81 -0
  178. package/dist/esm/utils/url-search-params.js.map +1 -0
  179. package/package.json +4 -4
  180. package/src/builders/ast-builders.ts +80 -3
  181. package/src/builders/hast-builders.ts +11 -0
  182. package/src/builders/style-builders.ts +121 -43
  183. package/src/index.ts +22 -1
  184. package/src/node-handlers/node-to-html/constants.ts +2 -0
  185. package/src/node-handlers/node-to-html/index.ts +126 -6
  186. package/src/node-handlers/node-to-html/types.ts +6 -0
  187. package/src/node-handlers/node-to-html/utils.ts +228 -14
  188. package/src/node-handlers/node-to-jsx/index.ts +2135 -62
  189. package/src/node-handlers/node-to-jsx/types.ts +75 -32
  190. package/src/node-handlers/node-to-jsx/utils.ts +1173 -84
  191. package/src/utils/ast-utils.ts +1316 -127
  192. package/src/utils/hast-utils.ts +37 -9
  193. package/src/utils/nested-selector-commas.ts +88 -0
  194. package/src/utils/route-utils.ts +214 -0
  195. package/src/utils/style-utils.ts +183 -1
  196. package/src/utils/template-expression-balance.ts +196 -0
  197. package/src/utils/types.ts +25 -0
  198. package/src/utils/url-query-writer.ts +318 -0
  199. package/src/utils/url-search-param-sync.ts +303 -0
  200. package/src/utils/url-search-params.ts +122 -0
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.pageDataReadArguments = exports.pageDataReadsAsStore = exports.pageSeedsStateFromDataSource = exports.stateQueryHasTemplatePlaceholder = exports.pageReadsProtectedTable = exports.pageHasSameTableMutationWorkflow = exports.parseDynamicPathSegments = exports.pathHasDynamicSegment = exports.isDynamicRoute = void 0;
36
+ var types = __importStar(require("@babel/types"));
37
+ var teleport_shared_1 = require("@teleporthq/teleport-shared");
38
+ /**
39
+ * True when this UIDL component's output route contains a Next.js dynamic
40
+ * segment (`[id]`, `[slug]`, ...) anywhere in its folder path or file name.
41
+ */
42
+ var isDynamicRoute = function (uidl) {
43
+ var _a = uidl.outputOptions || {}, _b = _a.folderPath, folderPath = _b === void 0 ? [] : _b, _c = _a.fileName, fileName = _c === void 0 ? '' : _c;
44
+ return __spreadArray(__spreadArray([], folderPath, true), [fileName], false).some(function (segment) { return segment.startsWith('[') && segment.endsWith(']'); });
45
+ };
46
+ exports.isDynamicRoute = isDynamicRoute;
47
+ /**
48
+ * Reading a route TEMPLATE (`/event-details/[id]`) rather than a URL. Defined in
49
+ * teleport-shared because the navlink resolver needs the same two functions and
50
+ * lives in a package that does not depend on this one; re-exported here so
51
+ * `RouteUtils` stays the single import for route questions in the plugins.
52
+ */
53
+ exports.pathHasDynamicSegment = teleport_shared_1.RoutePaths.pathHasDynamicSegment, exports.parseDynamicPathSegments = teleport_shared_1.RoutePaths.parseDynamicPathSegments;
54
+ var MUTATION_NODE_TYPES = new Set(['data-create-item', 'data-update-item']);
55
+ /**
56
+ * True when this page both reads one specific database row via its own
57
+ * getStaticProps (`detailsPageInfo.tableName` — present on every details
58
+ * page, feature/admin/generic alike, regardless of the project's visual nav
59
+ * layout) AND has a workflow scoped to this page/an element on it that
60
+ * writes to that SAME table. That combination is the actual ISR hazard: a
61
+ * form on this page can just have written the exact row this page's own
62
+ * getStaticProps reads, and ISR would keep serving the pre-write snapshot
63
+ * for up to `cache.revalidate` seconds — a real, successful save silently
64
+ * looking "unsaved" on reload (the "Edit Press Item" bug). This is a
65
+ * data-correctness signal tied to what the page actually does, not a proxy
66
+ * for it — unlike a project-wide "dashboard vs standard" nav-layout choice,
67
+ * which has no bearing on whether any single page both reads and writes the
68
+ * same row (a `standard`-layout marketplace's "Edit Listing" page carries
69
+ * the identical risk; a `dashboard`-layout read-only report page carries
70
+ * none of it).
71
+ *
72
+ * Shared by `teleport-plugin-next-static-props` (decides getStaticProps vs
73
+ * getServerSideProps) and `teleport-plugin-next-static-paths` (decides
74
+ * whether to skip getStaticPaths) — both plugins must reach the exact same
75
+ * verdict for a given page, so the check lives here once instead of as two
76
+ * independently-maintained copies.
77
+ */
78
+ var pageHasSameTableMutationWorkflow = function (uidl, workflows) {
79
+ var _a, _b, _c, _d;
80
+ var tableName = (_b = (_a = uidl.outputOptions) === null || _a === void 0 ? void 0 : _a.detailsPageInfo) === null || _b === void 0 ? void 0 : _b.tableName;
81
+ if (!tableName || !(workflows === null || workflows === void 0 ? void 0 : workflows.workflows)) {
82
+ return false;
83
+ }
84
+ var pageId = ((_c = uidl.outputOptions) === null || _c === void 0 ? void 0 : _c.pageId) || ((_d = uidl.outputOptions) === null || _d === void 0 ? void 0 : _d.fileName) || uidl.name || '';
85
+ return Object.values(workflows.workflows).some(function (wf) {
86
+ var _a, _b;
87
+ var trigger = wf.trigger;
88
+ if (!trigger || (trigger.scope !== 'page' && trigger.scope !== 'element')) {
89
+ return false;
90
+ }
91
+ // Same page-matching semantics the runtime workflow plugin already uses
92
+ // (workflow-component-plugin.ts's getRelevantWorkflows): an empty/absent
93
+ // `selectedPages` means the trigger fires on every page it's attached to,
94
+ // a non-empty one restricts it to those pages.
95
+ var triggerPageId = (_a = trigger.config) === null || _a === void 0 ? void 0 : _a.pageId;
96
+ var selectedPages = (_b = trigger.config) === null || _b === void 0 ? void 0 : _b.selectedPages;
97
+ var isScopedToThisPage = trigger.scope === 'page'
98
+ ? !triggerPageId || triggerPageId === pageId
99
+ : !selectedPages || selectedPages.length === 0 || selectedPages.some(function (p) { return p.id === pageId; });
100
+ if (!isScopedToThisPage) {
101
+ return false;
102
+ }
103
+ return wf.nodes.some(function (node) { var _a; return MUTATION_NODE_TYPES.has(node.type) && ((_a = node.config) === null || _a === void 0 ? void 0 : _a.tableName) === tableName; });
104
+ });
105
+ };
106
+ exports.pageHasSameTableMutationWorkflow = pageHasSameTableMutationWorkflow;
107
+ var collectResourceTables = function (value, tables, seen) {
108
+ if (!value || typeof value !== 'object' || seen.has(value)) {
109
+ return;
110
+ }
111
+ seen.add(value);
112
+ if (Array.isArray(value)) {
113
+ value.forEach(function (item) { return collectResourceTables(item, tables, seen); });
114
+ return;
115
+ }
116
+ var record = value;
117
+ var definition = record.resourceDefinition;
118
+ if (definition && typeof definition.tableName === 'string') {
119
+ tables.add(definition.tableName.trim().toLowerCase());
120
+ }
121
+ Object.keys(record).forEach(function (key) { return collectResourceTables(record[key], tables, seen); });
122
+ };
123
+ /**
124
+ * True when anything on this page reads a table that holds money, the keys
125
+ * to it, or the customers' own records (`TableAccess.PROTECTED_TABLES`: gift
126
+ * cards, vouchers, their ledgers, orders, accounts). Such a page renders per
127
+ * request. A statically generated one bakes codes, balances and addresses
128
+ * into the build output and keeps serving a balance the checkout has already
129
+ * spent until the next revalidation.
130
+ *
131
+ * Shared by the static-props and static-paths plugins and the page pipeline's
132
+ * getServerSideProps finalizer, which must all reach the same verdict.
133
+ */
134
+ var pageReadsProtectedTable = function (uidl) {
135
+ var _a, _b;
136
+ var tables = new Set();
137
+ var detailsTable = (_b = (_a = uidl.outputOptions) === null || _a === void 0 ? void 0 : _a.detailsPageInfo) === null || _b === void 0 ? void 0 : _b.tableName;
138
+ if (typeof detailsTable === 'string') {
139
+ tables.add(detailsTable.trim().toLowerCase());
140
+ }
141
+ collectResourceTables(uidl.node, tables, new Set());
142
+ return teleport_shared_1.TableAccess.PROTECTED_TABLES.some(function (table) { return tables.has(table); });
143
+ };
144
+ exports.pageReadsProtectedTable = pageReadsProtectedTable;
145
+ /**
146
+ * Any `{{…}}` template placeholder (`{{Current User.id}}`, `{{urlDifferentiator}}`).
147
+ * A state query carrying one can only be resolved in the browser, so the page's
148
+ * server data function never runs it — sending the literal placeholder to the
149
+ * database fails (`invalid input syntax for type uuid: "{{Current User.id}}"`).
150
+ */
151
+ var TEMPLATE_PLACEHOLDER = /\{\{[^}]+\}\}/;
152
+ var stateQueryHasTemplatePlaceholder = function (definition) {
153
+ return typeof definition.query === 'string' && TEMPLATE_PLACEHOLDER.test(definition.query);
154
+ };
155
+ exports.stateQueryHasTemplatePlaceholder = stateQueryHasTemplatePlaceholder;
156
+ /**
157
+ * True when the page's own data function seeds a state from one of the
158
+ * project's data sources — a state bound to a table or a raw query that has no
159
+ * `{{…}}` placeholder. Such a page renders per request: those values have to be
160
+ * computed every time a visitor arrives, and a statically generated page hands a
161
+ * client-side navigation the copy Next.js cached in the browser (prefetched
162
+ * links included) or the one ISR rendered before the last write.
163
+ *
164
+ * Shared by the static-paths plugin and the page pipeline's getServerSideProps
165
+ * finalizer, which must reach the same verdict. The state data-source plugin
166
+ * splits states with the same `stateQueryHasTemplatePlaceholder` test.
167
+ */
168
+ var pageSeedsStateFromDataSource = function (uidl, dataSources) {
169
+ return Object.values(uidl.stateDefinitions || {}).some(function (definition) {
170
+ return !!definition.dataSourceBinding &&
171
+ !!(dataSources === null || dataSources === void 0 ? void 0 : dataSources[definition.dataSourceBinding.dataSourceId]) &&
172
+ !(0, exports.stateQueryHasTemplatePlaceholder)(definition);
173
+ });
174
+ };
175
+ exports.pageSeedsStateFromDataSource = pageSeedsStateFromDataSource;
176
+ /**
177
+ * The path a page is served at, from where its file lands: `/admin/orders`
178
+ * for `pages/admin/orders.js`, `/` for the home page.
179
+ */
180
+ var pageRouteOf = function (outputOptions) {
181
+ var _a = outputOptions || {}, _b = _a.folderPath, folderPath = _b === void 0 ? [] : _b, _c = _a.fileName, fileName = _c === void 0 ? '' : _c;
182
+ var segments = __spreadArray(__spreadArray([], folderPath, true), [fileName], false).filter(function (segment, index, all) { return segment !== '' && !(segment === 'index' && index === all.length - 1); });
183
+ return "/".concat(segments.join('/'));
184
+ };
185
+ /**
186
+ * Whether a page's own data may be read as the store — only an admin panel
187
+ * page that nobody but the store's trusted readers may open
188
+ * (`TableAccess.pageReadsAsStore`). Every other page renders what a visitor
189
+ * is served of the store's tables.
190
+ */
191
+ var pageDataReadsAsStore = function (uidl, auth) {
192
+ var _a;
193
+ return teleport_shared_1.TableAccess.pageReadsAsStore({ route: pageRouteOf(uidl.outputOptions), pageId: (_a = uidl.outputOptions) === null || _a === void 0 ? void 0 : _a.pageId }, auth);
194
+ };
195
+ exports.pageDataReadsAsStore = pageDataReadsAsStore;
196
+ /**
197
+ * The arguments a page's data read hands a data-source module after its
198
+ * params: `{ as: 'visitor' }` — read what a visitor is served (the route's row
199
+ * policy, hidden columns and refused tables) — or none on a page that reads as
200
+ * the store (`pageDataReadsAsStore`).
201
+ */
202
+ var pageDataReadArguments = function (uidl, auth) {
203
+ return (0, exports.pageDataReadsAsStore)(uidl, auth)
204
+ ? []
205
+ : [
206
+ types.objectExpression([
207
+ types.objectProperty(types.identifier('as'), types.stringLiteral('visitor')),
208
+ ]),
209
+ ];
210
+ };
211
+ exports.pageDataReadArguments = pageDataReadArguments;
212
+ //# sourceMappingURL=route-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-utils.js","sourceRoot":"","sources":["../../../src/utils/route-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAqC;AAErC,+DAAqE;AAErE;;;GAGG;AACI,IAAM,cAAc,GAAG,UAAC,IAE9B;IACO,IAAA,KAAqC,IAAI,CAAC,aAAa,IAAI,EAAE,EAA3D,kBAAe,EAAf,UAAU,mBAAG,EAAE,KAAA,EAAE,gBAAa,EAAb,QAAQ,mBAAG,EAAE,KAA6B,CAAA;IACnE,OAAO,gCAAI,UAAU,UAAE,QAAQ,UAAE,IAAI,CACnC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,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IAAI,EAAE,IAAI,CAAC;QAC9B,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC;YACE,KAAK,CAAC,gBAAgB,CAAC;gBACrB,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;aAC7E,CAAC;SACH;AANL,CAMK,CAAA;AAVM,QAAA,qBAAqB,yBAU3B"}
@@ -1,4 +1,5 @@
1
1
  import { UIDLStaticValue, UIDLStyleDefinitions } from '@teleporthq/teleport-types';
2
+ export declare const sanitizeContentValue: (raw: string) => string;
2
3
  export declare const getContentOfStyleObject: (styleObject: UIDLStyleDefinitions) => Record<string, unknown>;
3
4
  export declare const getTokensContentFromTokensObject: (tokens: Record<string, UIDLStaticValue>) => Record<string, string | number>;
4
5
  export declare const getCSSVariablesContentFromTokenStyles: (styleObject: UIDLStyleDefinitions) => Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"style-utils.d.ts","sourceRoot":"","sources":["../../../src/utils/style-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAkB,MAAM,4BAA4B,CAAA;AAelG,eAAO,MAAM,uBAAuB,gBAAiB,oBAAoB,4BAKxE,CAAA;AAED,eAAO,MAAM,gCAAgC,WAAY,OAAO,MAAM,EAAE,eAAe,CAAC,oCAKvF,CAAA;AAED,eAAO,MAAM,qCAAqC,gBAAiB,oBAAoB,2BAQtF,CAAA"}
1
+ {"version":3,"file":"style-utils.d.ts","sourceRoot":"","sources":["../../../src/utils/style-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAkB,MAAM,4BAA4B,CAAA;AA6ElG,eAAO,MAAM,oBAAoB,QAAS,MAAM,KAAG,MAyBlD,CAAA;AAgFD,eAAO,MAAM,uBAAuB,gBAAiB,oBAAoB,4BAoBxE,CAAA;AAED,eAAO,MAAM,gCAAgC,WAAY,OAAO,MAAM,EAAE,eAAe,CAAC,oCAKvF,CAAA;AAED,eAAO,MAAM,qCAAqC,gBAAiB,oBAAoB,2BAQtF,CAAA"}
@@ -1,7 +1,169 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCSSVariablesContentFromTokenStyles = exports.getTokensContentFromTokensObject = exports.getContentOfStyleObject = void 0;
3
+ exports.getCSSVariablesContentFromTokenStyles = exports.getTokensContentFromTokensObject = exports.getContentOfStyleObject = exports.sanitizeContentValue = void 0;
4
4
  var teleport_shared_1 = require("@teleporthq/teleport-shared");
5
+ var CSS_FUNCTIONS = [
6
+ 'radial-gradient',
7
+ 'linear-gradient',
8
+ 'conic-gradient',
9
+ 'repeating-linear-gradient',
10
+ 'repeating-radial-gradient',
11
+ 'repeating-conic-gradient',
12
+ ];
13
+ // CSS `content` property has the strictest value grammar of any
14
+ // property the AI emits: it must be either a quoted string, one of
15
+ // a fixed set of keywords, or a recognised function call. The AI
16
+ // occasionally produces garbage here (e.g. the raw fragment `';`
17
+ // straight out of a hallucinated declaration), and the
18
+ // downstream JSS serializer happily concatenates that into
19
+ // `content: ';;` — a CSS parse error that breaks the entire
20
+ // stylesheet on Next.js dev (the browser stops applying any rule
21
+ // after the malformed one). When we can't recognise the value as
22
+ // valid, we fall back to an empty string literal — losing the
23
+ // decoration but keeping the stylesheet parseable.
24
+ var CONTENT_KEYWORDS = new Set([
25
+ 'none',
26
+ 'normal',
27
+ 'open-quote',
28
+ 'close-quote',
29
+ 'no-open-quote',
30
+ 'no-close-quote',
31
+ 'inherit',
32
+ 'initial',
33
+ 'unset',
34
+ 'revert',
35
+ 'revert-layer',
36
+ ]);
37
+ var CONTENT_FUNCTION_PREFIXES = [
38
+ 'attr(',
39
+ 'counter(',
40
+ 'counters(',
41
+ 'var(',
42
+ 'url(',
43
+ 'image(',
44
+ 'image-set(',
45
+ 'linear-gradient(',
46
+ 'radial-gradient(',
47
+ 'conic-gradient(',
48
+ ];
49
+ var isProperlyQuotedString = function (value) {
50
+ if (value.length < 2) {
51
+ return false;
52
+ }
53
+ var first = value.charAt(0);
54
+ var last = value.charAt(value.length - 1);
55
+ if (first !== last) {
56
+ return false;
57
+ }
58
+ if (first !== '"' && first !== "'") {
59
+ return false;
60
+ }
61
+ // Walk the interior and reject unescaped occurrences of the same
62
+ // quote character — those would close the string early and leak
63
+ // arbitrary CSS into the surrounding stylesheet.
64
+ for (var i = 1; i < value.length - 1; i++) {
65
+ var ch = value.charAt(i);
66
+ if (ch === '\\') {
67
+ i++; // skip the escaped character
68
+ continue;
69
+ }
70
+ if (ch === first) {
71
+ return false;
72
+ }
73
+ }
74
+ return true;
75
+ };
76
+ var sanitizeContentValue = function (raw) {
77
+ var trimmed = raw.trim();
78
+ if (trimmed === '') {
79
+ return "''";
80
+ }
81
+ if (CONTENT_KEYWORDS.has(trimmed)) {
82
+ return trimmed;
83
+ }
84
+ for (var _i = 0, CONTENT_FUNCTION_PREFIXES_1 = CONTENT_FUNCTION_PREFIXES; _i < CONTENT_FUNCTION_PREFIXES_1.length; _i++) {
85
+ var prefix = CONTENT_FUNCTION_PREFIXES_1[_i];
86
+ if (trimmed.startsWith(prefix) && trimmed.endsWith(')')) {
87
+ return trimmed;
88
+ }
89
+ }
90
+ if (isProperlyQuotedString(trimmed)) {
91
+ return trimmed;
92
+ }
93
+ // Last-resort repair: strip every quote and semicolon (the two
94
+ // characters that break the surrounding rule) and wrap the
95
+ // remainder in single quotes. If nothing legible survives, fall
96
+ // through to an empty string. We deliberately do NOT try to
97
+ // preserve "almost a quoted string" inputs — the AI's malformed
98
+ // emissions don't have a clear repair path and silently keeping
99
+ // them risks injecting CSS the user didn't author.
100
+ var stripped = trimmed.replace(/['";]/g, '').trim();
101
+ return "'" + stripped + "'";
102
+ };
103
+ exports.sanitizeContentValue = sanitizeContentValue;
104
+ var isValidCSSValue = function (value, key) {
105
+ if (typeof value === 'number') {
106
+ return true;
107
+ }
108
+ // Check for CSS functions that are missing their parentheses (e.g. "radial-gradientfoo")
109
+ for (var _i = 0, CSS_FUNCTIONS_1 = CSS_FUNCTIONS; _i < CSS_FUNCTIONS_1.length; _i++) {
110
+ var fn = CSS_FUNCTIONS_1[_i];
111
+ if (value.includes(fn) && !value.includes("".concat(fn, "("))) {
112
+ return false;
113
+ }
114
+ }
115
+ // The `content` property is treated separately by
116
+ // `sanitizeContentValue` — it has its own grammar (quoted string
117
+ // OR keyword OR function call) that the general colon/paren
118
+ // check below would mis-evaluate for a legitimate quoted string
119
+ // that happens to contain a `:`.
120
+ if (key === 'content') {
121
+ return true;
122
+ }
123
+ // Check for values that contain embedded CSS declarations (e.g. "valueproperty-name: other")
124
+ // A colon in a CSS value normally only appears inside url() or var() or similar functions.
125
+ // If a colon appears outside of parentheses, the value is likely corrupted.
126
+ //
127
+ // Parentheses and colons inside a quoted string (e.g. a `url("data:...(...)")`
128
+ // data-URI or a `font-family: "Foo (Bold)"`) are literal text, not syntax, so
129
+ // the scan tracks the active quote and ignores everything inside it.
130
+ var parenDepth = 0;
131
+ var quote = '';
132
+ for (var i = 0; i < value.length; i++) {
133
+ var char = value[i];
134
+ if (quote) {
135
+ if (char === quote && value[i - 1] !== '\\') {
136
+ quote = '';
137
+ }
138
+ continue;
139
+ }
140
+ if (char === "'" || char === '"') {
141
+ quote = char;
142
+ }
143
+ else if (char === '(') {
144
+ parenDepth++;
145
+ }
146
+ else if (char === ')') {
147
+ parenDepth--;
148
+ // A closing paren with no matching opener means the value is corrupted.
149
+ if (parenDepth < 0) {
150
+ return false;
151
+ }
152
+ }
153
+ else if (char === ':' && parenDepth === 0) {
154
+ // Colons outside parentheses in a CSS value indicate a corrupted/merged declaration
155
+ return false;
156
+ }
157
+ }
158
+ // Unbalanced parentheses leave an unclosed CSS function — e.g. a stream that
159
+ // was truncated mid-value (`color-mix(in srgb, var(--color-surface) 50%,`).
160
+ // Emitting it produces `color: color-mix(...50%,;` which fails the CSS parser
161
+ // and breaks the whole stylesheet (and the Next.js production build).
162
+ if (parenDepth !== 0) {
163
+ return false;
164
+ }
165
+ return true;
166
+ };
5
167
  var getContentOfStyleKey = function (styleValue) {
6
168
  if (styleValue.type === 'static') {
7
169
  return styleValue.content;
@@ -10,7 +172,24 @@ var getContentOfStyleKey = function (styleValue) {
10
172
  };
11
173
  var getContentOfStyleObject = function (styleObject) {
12
174
  return Object.keys(styleObject).reduce(function (acc, key) {
13
- acc[key] = getContentOfStyleKey(styleObject[key]);
175
+ var value = getContentOfStyleKey(styleObject[key]);
176
+ if (typeof value === 'string' || typeof value === 'number') {
177
+ if (isValidCSSValue(value, key)) {
178
+ // The `content` CSS property is the only one in the AI's
179
+ // typical output that consistently arrives malformed — the
180
+ // sanitiser repairs or empty-strings it so the surrounding
181
+ // rule stays parseable.
182
+ if (key === 'content' && typeof value === 'string') {
183
+ acc[key] = (0, exports.sanitizeContentValue)(value);
184
+ }
185
+ else {
186
+ acc[key] = value;
187
+ }
188
+ }
189
+ }
190
+ else {
191
+ acc[key] = value;
192
+ }
14
193
  return acc;
15
194
  }, {});
16
195
  };
@@ -1 +1 @@
1
- {"version":3,"file":"style-utils.js","sourceRoot":"","sources":["../../../src/utils/style-utils.ts"],"names":[],"mappings":";;;AAAA,+DAAyD;AAGzD,IAAM,oBAAoB,GAAG,UAAC,UAA0B;IACtD,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ,EAAE;QAChC,OAAO,UAAU,CAAC,OAAO,CAAA;KAC1B;IACD,MAAM,IAAI,KAAK,CACb,oDAA6C,IAAI,CAAC,SAAS,CACzD,UAAU,EACV,IAAI,EACJ,CAAC,CACF,8BAA2B,CAC7B,CAAA;AACH,CAAC,CAAA;AAEM,IAAM,uBAAuB,GAAG,UAAC,WAAiC;IACvE,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,UAAC,GAA4B,EAAE,GAAG;QACvE,GAAG,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC,WAAW,CAAC,GAAG,CAA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,CAAC,CAAC,MAAM,CAAC,UAAC,GAAoC,EAAE,GAAG;QAChF,GAAG,CAAC,6BAAW,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,OAAiB,CAAA;QAC7E,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AALY,QAAA,gCAAgC,oCAK5C;AAEM,IAAM,qCAAqC,GAAG,UAAC,WAAiC;IACrF,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,UAAC,GAA2B,EAAE,GAAG;QAC5E,IAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;QAC9B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,KAAK,OAAO,EAAE;YACvE,GAAG,CAAC,GAAG,CAAC,GAAG,cAAO,6BAAW,CAAC,uBAAuB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,MAAG,CAAA;SAC3E;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AARY,QAAA,qCAAqC,yCAQjD"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Delimiter balancing for `{{ … }}` binding expressions.
3
+ *
4
+ * THE DEFECT THIS EXISTS FOR. `parseStringWithTemplateExpressions` converted a
5
+ * UIDL string into a template literal and then handed the result straight to
6
+ * Babel. When the binding inside was unbalanced the produced source did not
7
+ * parse, `parse()` threw, and — because the inline-style caller has no
8
+ * try/catch — the SyntaxError escaped all the way out and killed the ENTIRE
9
+ * project build:
10
+ *
11
+ * const x = `translateX(${-(cameraX || ''}px) }px)`
12
+ * ^ Unexpected token, expected ","
13
+ *
14
+ * Two separate faults produced that line. The interpolated expression
15
+ * `-(cameraX || ''` was missing its closing paren, and the "re-close the CSS
16
+ * function" step counted parentheses across the WHOLE string — including the
17
+ * ones inside `${…}` — decided one was missing, and appended `px)` to the end,
18
+ * which could never help because the imbalance was inside the interpolation.
19
+ *
20
+ * One bad binding in one style property must never cost a project its build.
21
+ * These helpers make the imbalance repairable where it actually is, and let the
22
+ * caller degrade a single value instead of aborting.
23
+ */
24
+ export interface ExpressionScan {
25
+ /** Openers still waiting for their closer, outermost first. */
26
+ unclosed: string[];
27
+ /** Closers that never had a matching opener. */
28
+ strayCloserCount: number;
29
+ /** The quote character still open at the end of the scan, if any. */
30
+ unterminatedQuote: string | null;
31
+ }
32
+ /**
33
+ * Single left-to-right pass over an expression, quote and escape aware.
34
+ * Characters inside a string literal never affect nesting.
35
+ */
36
+ export declare const scanExpression: (expression: string) => ExpressionScan;
37
+ /** True when every quote and bracket closes and no closer is stray. */
38
+ export declare const isBalancedExpression: (expression: string) => boolean;
39
+ /**
40
+ * Close an expression that ends mid-quote or mid-bracket:
41
+ * `-(cameraX || ''` → `-(cameraX || '')`.
42
+ *
43
+ * Returns the expression unchanged when it is already balanced, and when the
44
+ * imbalance is a STRAY CLOSER — appending cannot fix a missing opener, and
45
+ * inventing one would be a guess.
46
+ */
47
+ export declare const balanceExpression: (expression: string) => string;
48
+ /**
49
+ * Parenthesis balance of the STATIC parts of a template string — everything
50
+ * outside `${…}`.
51
+ *
52
+ * This is the number the "re-close the CSS function" step needs. Counting over
53
+ * the whole string mixes in the expressions' own parentheses, so an imbalance
54
+ * INSIDE an interpolation reads as a missing close on the CSS function and the
55
+ * step appends a unit and a `)` that belong nowhere.
56
+ */
57
+ export declare const countUnclosedStaticParens: (templateStr: string) => number;
58
+ //# sourceMappingURL=template-expression-balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-expression-balance.d.ts","sourceRoot":"","sources":["../../../src/utils/template-expression-balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAYH,MAAM,WAAW,cAAc;IAC7B,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAA;IACxB,qEAAqE;IACrE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;CACjC;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,eAAgB,MAAM,KAAG,cAyCnD,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,eAAgB,MAAM,KAAG,OAKzD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,MAYtD,CAAA;AAQD;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,gBAAiB,MAAM,KAAG,MAkB/D,CAAA"}