@lowdefy/api 6.1.0 → 7.0.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 (195) hide show
  1. package/dist/context/applySystemTrust.js +45 -0
  2. package/dist/context/createApiContext.js +18 -3
  3. package/dist/context/createAuthorizeOutcome.js +91 -0
  4. package/dist/context/createBoundSystemContext.js +33 -0
  5. package/dist/context/createEvaluateOperators.js +8 -3
  6. package/dist/context/createRequestSignal.js +47 -0
  7. package/dist/context/createSystemContext.js +80 -0
  8. package/dist/context/getCanonicalUrl.js +27 -0
  9. package/dist/context/isSameOriginRequest.js +85 -0
  10. package/dist/context/isWebSocketOriginAllowed.js +63 -0
  11. package/dist/context/normalizeInjectedCaller.js +58 -0
  12. package/dist/context/parseRequestBody.js +32 -0
  13. package/dist/context/readMemberships.js +71 -0
  14. package/dist/context/resolveAuthentication.js +758 -0
  15. package/dist/context/resolveStrategyCaller.js +7 -3
  16. package/dist/csp/addNonceToElements.js +23 -0
  17. package/dist/csp/createContentSecurityPolicy.js +45 -0
  18. package/dist/csp/getWebSocketSources.js +36 -0
  19. package/dist/email/renderAuthEmail.js +99 -0
  20. package/dist/index.js +21 -5
  21. package/dist/response/formatErrorForAgent.js +35 -0
  22. package/dist/response/redactResponse.js +8 -1
  23. package/dist/routes/agent/authorizeAgent.js +17 -5
  24. package/dist/routes/agent/callAgent.js +12 -2
  25. package/dist/routes/agent/collectChatFiles.js +39 -0
  26. package/dist/routes/agent/prepareAgent.js +23 -4
  27. package/dist/routes/auth/buildAdminPlugin.js +33 -0
  28. package/dist/routes/auth/buildCaptchaPlugin.js +61 -0
  29. package/dist/routes/auth/buildMcpTokenPlugin.js +77 -0
  30. package/dist/routes/auth/buildOauthPostLogin.js +73 -0
  31. package/dist/routes/auth/buildPhoneNumberPlugin.js +57 -0
  32. package/dist/routes/auth/buildProviders.js +61 -0
  33. package/dist/routes/auth/createAsMetadataHandler.js +27 -0
  34. package/dist/routes/auth/createAuthLogger.js +31 -0
  35. package/dist/routes/auth/createMcpAccessTokenClaims.js +52 -0
  36. package/dist/routes/auth/createOnAPIError.js +41 -0
  37. package/dist/routes/auth/createSendEmail.js +54 -0
  38. package/dist/routes/auth/ensureMcpTokenIndexes.js +48 -0
  39. package/dist/routes/auth/getAuthEnforcement.js +41 -0
  40. package/dist/routes/auth/getBetterAuth.js +107 -0
  41. package/dist/routes/auth/getBetterAuthConfig.js +767 -0
  42. package/dist/routes/auth/handleAuthRequest.js +43 -0
  43. package/dist/routes/auth/hooks/authHookPoints.js +204 -0
  44. package/dist/routes/auth/hooks/buildEngineHooks.js +68 -0
  45. package/dist/routes/auth/hooks/buildHooks.js +112 -0
  46. package/dist/routes/auth/{callbacks/addUserFieldsToSession.js → hooks/composeAfterSlot.js} +11 -13
  47. package/dist/routes/auth/hooks/composeBeforeSlot.js +41 -0
  48. package/dist/routes/auth/hooks/createHookDispatch.js +59 -0
  49. package/dist/routes/auth/hooks/createUserAfterHook.js +36 -0
  50. package/dist/routes/auth/hooks/createUserBeforeHook.js +50 -0
  51. package/dist/routes/auth/hooks/findHookUser.js +27 -0
  52. package/dist/routes/auth/modelNames.js +30 -0
  53. package/dist/routes/auth/organizations/OrganizationKeyError.js +28 -0
  54. package/dist/routes/auth/organizations/authorizeRole.js +27 -0
  55. package/dist/routes/auth/organizations/buildOrganizationPlugin.js +178 -0
  56. package/dist/routes/auth/organizations/createAcceptActiveOrgGuardHook.js +57 -0
  57. package/dist/routes/auth/organizations/createAcceptExistingMemberHook.js +120 -0
  58. package/dist/routes/auth/organizations/createActiveOrgPolicyHook.js +403 -0
  59. package/dist/routes/auth/organizations/createAdmissionGateHook.js +50 -0
  60. package/dist/routes/auth/organizations/createAfterAcceptInvitationHook.js +90 -0
  61. package/dist/routes/auth/organizations/createAutoJoinHook.js +68 -0
  62. package/dist/routes/auth/organizations/createEmailSendGate.js +59 -0
  63. package/dist/routes/auth/organizations/createExpiredInvitationGate.js +76 -0
  64. package/dist/routes/auth/organizations/ensureAuthIndexes.js +122 -0
  65. package/dist/routes/auth/organizations/ensureOrganization.js +132 -0
  66. package/dist/routes/auth/organizations/findPendingInvitation.js +43 -0
  67. package/dist/routes/auth/organizations/getHookRequestHeaders.js +24 -0
  68. package/dist/routes/auth/organizations/getOrganizationBinding.js +65 -0
  69. package/dist/routes/auth/organizations/isEmailAdmitted.js +89 -0
  70. package/dist/routes/auth/organizations/organizationAccessControl.js +94 -0
  71. package/dist/routes/auth/organizations/resolvePinnedOrganization.js +62 -0
  72. package/dist/routes/auth/requestHooks/beginTwoFactorChallenge.js +145 -0
  73. package/dist/routes/auth/requestHooks/buildRequestHooks.js +288 -0
  74. package/dist/routes/auth/requestHooks/createOauthPostLoginHook.js +43 -0
  75. package/dist/routes/auth/requestHooks/createTwoFactorChallengeHook.js +59 -0
  76. package/dist/routes/auth/requestHooks/dispatchRequestHooks.js +47 -0
  77. package/dist/routes/auth/requestHooks/redirectToChallenge.js +79 -0
  78. package/dist/routes/auth/requestHooks/resolveTwoFactorPageUrl.js +31 -0
  79. package/dist/routes/auth/resolveCookiePrefix.js +30 -0
  80. package/dist/routes/auth/sanitizeSessionResponse.js +27 -0
  81. package/dist/routes/auth/strategies/getAuthStrategies.js +1 -1
  82. package/dist/routes/connections/checkUnwalledReach.js +37 -0
  83. package/dist/routes/connections/getConnectionConfig.js +6 -1
  84. package/dist/routes/connections/resolveTenantPreflight.js +226 -0
  85. package/dist/routes/connections/resolveUnwalledReach.js +144 -0
  86. package/dist/routes/endpoints/acceptDetachedEndpoint.js +50 -0
  87. package/dist/routes/endpoints/authorizeApiEndpoint.js +13 -4
  88. package/dist/routes/endpoints/callEndpoint.js +22 -7
  89. package/dist/routes/endpoints/control/controlParallelFor.js +61 -22
  90. package/dist/routes/endpoints/control/controlReject.js +23 -1
  91. package/dist/routes/endpoints/control/controlReturn.js +29 -1
  92. package/dist/routes/endpoints/control/controlThrow.js +3 -2
  93. package/dist/routes/endpoints/control/controlTry.js +10 -1
  94. package/dist/routes/endpoints/control/controlWhile.js +55 -0
  95. package/dist/routes/endpoints/control/handleControl.js +3 -1
  96. package/dist/routes/endpoints/createWebhookAnswer.js +78 -0
  97. package/dist/routes/endpoints/evaluateRoutineOperators.js +2 -1
  98. package/dist/routes/endpoints/forwardScheduledEndpoint.js +3 -2
  99. package/dist/routes/endpoints/getEndpointConfig.js +18 -8
  100. package/dist/routes/endpoints/getSchemaValidator.js +39 -0
  101. package/dist/routes/endpoints/handleAgentCall.js +21 -2
  102. package/dist/routes/endpoints/handleAuthStep.js +214 -0
  103. package/dist/routes/endpoints/handleDescribeDynamicPolicy.js +64 -0
  104. package/dist/routes/endpoints/handleEndpointCall.js +43 -6
  105. package/dist/routes/endpoints/handleRenderNotification.js +14 -4
  106. package/dist/routes/endpoints/handleRequest.js +12 -1
  107. package/dist/routes/endpoints/handleValidateDynamic.js +106 -0
  108. package/dist/routes/endpoints/handleValidateSchema.js +13 -15
  109. package/dist/routes/endpoints/invokeEndpoint.js +26 -3
  110. package/dist/routes/endpoints/operatorScope.js +2 -1
  111. package/dist/routes/{auth/callbacks/createCallbackPlugins.js → endpoints/parseWebhookBody.js} +10 -6
  112. package/dist/routes/endpoints/resolveCallBinding.js +91 -0
  113. package/dist/routes/endpoints/resolveStepOrganizationId.js +64 -0
  114. package/dist/routes/endpoints/runDetachedEndpoint.js +63 -18
  115. package/dist/routes/endpoints/runRoutine.js +64 -5
  116. package/dist/routes/endpoints/runScheduledEndpoint.js +18 -11
  117. package/dist/routes/endpoints/runWebhookEndpoint.js +69 -23
  118. package/dist/routes/endpoints/runWebhookVerify.js +129 -0
  119. package/dist/routes/endpoints/scheduleBackground.js +10 -0
  120. package/dist/routes/endpoints/test/runTest.js +31 -9
  121. package/dist/routes/endpoints/validatePayload.js +144 -0
  122. package/dist/routes/log/logClientError.js +7 -4
  123. package/dist/routes/mcp/createMcpServer.js +143 -82
  124. package/dist/routes/mcp/getMcpJwks.js +93 -0
  125. package/dist/routes/mcp/getMcpResourceBinding.js +41 -0
  126. package/dist/routes/mcp/getMcpUri.js +69 -0
  127. package/dist/routes/mcp/oauthResourceLifecycle.js +122 -0
  128. package/dist/routes/mcp/runAfterToolCall.js +50 -0
  129. package/dist/routes/notifications/resolveNotificationLinks.js +39 -11
  130. package/dist/routes/page/dynamic/checkDynamicContent.js +81 -0
  131. package/dist/routes/page/dynamic/checkLiteralContent.js +242 -0
  132. package/dist/routes/page/dynamic/createContentError.js +34 -0
  133. package/dist/routes/page/dynamic/flagIconsOutsidePage.js +39 -0
  134. package/dist/routes/page/dynamic/flagTypesOutsidePage.js +44 -0
  135. package/dist/routes/page/dynamic/getPropertiesSchemaErrors.js +35 -0
  136. package/dist/routes/page/dynamic/loadDynamicArtifacts.js +52 -0
  137. package/dist/routes/page/dynamic/policy/checkAction.js +204 -0
  138. package/dist/routes/page/dynamic/policy/checkEvents.js +163 -0
  139. package/dist/routes/page/dynamic/policy/checkPolicy.js +313 -0
  140. package/dist/routes/page/dynamic/policy/checkValue.js +214 -0
  141. package/dist/routes/page/dynamic/policy/collectUrlKinds.js +117 -0
  142. package/dist/routes/page/dynamic/policy/findEmbeddedUrls.js +54 -0
  143. package/dist/routes/page/dynamic/policy/findSerializerKeys.js +50 -0
  144. package/dist/routes/page/dynamic/policy/isAllowedUrl.js +53 -0
  145. package/dist/routes/{auth/createAdapter.js → page/dynamic/policy/isUnderState.js} +5 -9
  146. package/dist/routes/page/dynamic/policy/normalizeUrlText.js +25 -0
  147. package/dist/routes/page/dynamic/resolveDynamicContent.js +89 -37
  148. package/dist/routes/page/dynamic/unescapeOperators.js +21 -4
  149. package/dist/routes/page/dynamic/validateFragment.js +17 -58
  150. package/dist/routes/page/getPageConfig.js +76 -6
  151. package/dist/routes/request/authorizeRequest.js +21 -6
  152. package/dist/routes/request/callRequest.js +22 -10
  153. package/dist/routes/request/callRequestResolver.js +49 -6
  154. package/dist/routes/request/checkConnectionRead.js +1 -1
  155. package/dist/routes/request/checkConnectionWrite.js +1 -1
  156. package/dist/routes/request/createWalledResolver.js +75 -0
  157. package/dist/routes/request/getRequestConfig.js +19 -3
  158. package/dist/routes/request/maskCredentialProperties.js +34 -0
  159. package/dist/routes/request/resolveTenancy.js +223 -0
  160. package/dist/routes/request/validateSchemas.js +7 -6
  161. package/dist/routes/{auth/events/createEventPlugins.js → rootConfig/getAppEvents.js} +7 -6
  162. package/dist/routes/rootConfig/getHomeAndMenus.js +23 -16
  163. package/dist/routes/{auth/events/createSessionEvent.js → rootConfig/getPagePaths.js} +16 -18
  164. package/dist/routes/rootConfig/getRootConfig.js +9 -3
  165. package/dist/routes/rootConfig/menus/filterMenuList.js +5 -2
  166. package/dist/routes/websocket/authorizeWebsocket.js +19 -4
  167. package/dist/routes/websocket/createChannelRegistry.js +20 -9
  168. package/dist/routes/websocket/createWebSocketConnection.js +150 -28
  169. package/dist/routes/websocket/getCallerFingerprint.js +31 -0
  170. package/dist/routes/websocket/prepareChannel.js +29 -1
  171. package/dist/routes/websocket/resolveWebsocketCaller.js +40 -0
  172. package/dist/test/testContext.js +13 -10
  173. package/package.json +28 -12
  174. package/dist/context/createAuthorize.js +0 -45
  175. package/dist/routes/auth/callbacks/addUserFieldsToToken.js +0 -30
  176. package/dist/routes/auth/callbacks/createCallbacks.js +0 -46
  177. package/dist/routes/auth/callbacks/createJWTCallback.js +0 -77
  178. package/dist/routes/auth/callbacks/createRedirectCallback.js +0 -41
  179. package/dist/routes/auth/callbacks/createSessionCallback.js +0 -81
  180. package/dist/routes/auth/callbacks/createSignInCallback.js +0 -40
  181. package/dist/routes/auth/callbacks/validateSessionRoles.js +0 -33
  182. package/dist/routes/auth/createLogger.js +0 -35
  183. package/dist/routes/auth/createPrefixedCookies.js +0 -52
  184. package/dist/routes/auth/createProviders.js +0 -25
  185. package/dist/routes/auth/defaultAuthUrl.js +0 -31
  186. package/dist/routes/auth/events/createCreateUserEvent.js +0 -41
  187. package/dist/routes/auth/events/createEvents.js +0 -56
  188. package/dist/routes/auth/events/createLinkAccountEvent.js +0 -43
  189. package/dist/routes/auth/events/createSignInEvent.js +0 -46
  190. package/dist/routes/auth/events/createSignOutEvent.js +0 -43
  191. package/dist/routes/auth/events/createUpdateUserEvent.js +0 -41
  192. package/dist/routes/auth/getAuthConfig.js +0 -90
  193. package/dist/routes/auth/resolveCookies.js +0 -37
  194. package/dist/routes/log/formatValidationError.js +0 -31
  195. /package/dist/{routes/notifications → email}/resolveThemeLogo.js +0 -0
@@ -12,18 +12,31 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { serializer, type, urlQuery } from '@lowdefy/helpers';
16
- function resolveLinkValue({ link, option, serverUrl, basePath, landingPage, recordId }) {
15
+ */ import { buildPagePath, serializer, type, urlQuery } from '@lowdefy/helpers';
16
+ function pagePathFor({ pageId, pathParams, routes }) {
17
+ const route = routes.find((candidate)=>candidate.pageId === pageId);
18
+ return buildPagePath({
19
+ pageId,
20
+ path: route?.path,
21
+ pathParams
22
+ });
23
+ }
24
+ function resolveLinkValue({ link, option, serverUrl, basePath, landingPath, recordId, routes }) {
17
25
  // Absolute URLs pass through — links into other apps or external destinations.
18
26
  // They skip any landing page, so they carry no mark-as-read.
19
27
  if (type.isString(link)) {
20
28
  return link;
21
29
  }
22
30
  if (type.isObject(link) && !type.isNone(link.pageId)) {
23
- if (type.isNone(landingPage)) {
31
+ if (type.isNone(landingPath)) {
24
32
  // No landing page configured — link straight to the target page.
33
+ const pagePath = pagePathFor({
34
+ pageId: link.pageId,
35
+ pathParams: link.pathParams,
36
+ routes
37
+ });
25
38
  const query = urlQuery.stringify(link.urlQuery ?? {});
26
- return `${serverUrl}${basePath}/${link.pageId}${query ? `?${query}` : ''}`;
39
+ return `${serverUrl}${basePath}/${pagePath}${query ? `?${query}` : ''}`;
27
40
  }
28
41
  // The option query param is the dot-path of the link inside the record's
29
42
  // data — the landing page reads the original target back with
@@ -32,25 +45,39 @@ function resolveLinkValue({ link, option, serverUrl, basePath, landingPage, reco
32
45
  _id: recordId,
33
46
  option
34
47
  });
35
- return `${serverUrl}${basePath}${landingPage}?${query}`;
48
+ return `${serverUrl}${basePath}/${landingPath}?${query}`;
36
49
  }
37
50
  return link;
38
51
  }
39
52
  // Resolves link values in a copy of the data item to URLs; the stored record
40
- // keeps the original { pageId, urlQuery } objects for in-app navigation.
53
+ // keeps the original { pageId, urlQuery, pathParams } objects for in-app navigation.
41
54
  // data.links is the framework convention; link fields inside arrays are
42
55
  // resolved for the data keys the template declares (Template.dataKeys), so
43
56
  // custom templates get the same treatment as the built-in ones.
44
- function resolveNotificationLinks({ item, dataKeys, serverUrl, basePath, landingPage, recordId }) {
57
+ // routes is the build's routes.json; a link's page path is its pattern there.
58
+ // landingPage is a page id, or { pageId, pathParams }; its path is built from the same table.
59
+ function resolveNotificationLinks({ item, dataKeys, serverUrl, basePath, landingPage, recordId, routes }) {
45
60
  const resolved = serializer.copy(item);
61
+ let landingPath;
62
+ if (!type.isNone(landingPage)) {
63
+ const landing = type.isString(landingPage) ? {
64
+ pageId: landingPage
65
+ } : landingPage;
66
+ landingPath = pagePathFor({
67
+ pageId: landing.pageId,
68
+ pathParams: landing.pathParams,
69
+ routes
70
+ });
71
+ }
46
72
  Object.keys(resolved.links ?? {}).forEach((key)=>{
47
73
  resolved.links[key] = resolveLinkValue({
48
74
  link: resolved.links[key],
49
75
  option: `links.${key}`,
50
76
  serverUrl,
51
77
  basePath,
52
- landingPage,
53
- recordId
78
+ landingPath,
79
+ recordId,
80
+ routes
54
81
  });
55
82
  });
56
83
  (dataKeys ?? []).forEach((arrayKey)=>{
@@ -62,8 +89,9 @@ function resolveNotificationLinks({ item, dataKeys, serverUrl, basePath, landing
62
89
  option: `${arrayKey}.${index}.link`,
63
90
  serverUrl,
64
91
  basePath,
65
- landingPage,
66
- recordId
92
+ landingPath,
93
+ recordId,
94
+ routes
67
95
  });
68
96
  });
69
97
  });
@@ -0,0 +1,81 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
+ import checkPolicy from './policy/checkPolicy.js';
17
+ import validateFragment from './validateFragment.js';
18
+ // The one checker behind both the ValidateDynamic step and page get. Policy
19
+ // rules run first on the content as submitted and collect every violation;
20
+ // when they pass, the content goes through the same block build and fragment
21
+ // validation every Dynamic block gets. Returns { errors } on failure, or the
22
+ // built fragment. buildBlock mutates the content, so callers pass their own copy.
23
+ async function checkDynamicContent(context, { artifacts, blocks, dynamicBlockId, idPrefix, pageId, pageRequests, policy, usedTypes }) {
24
+ if (policy) {
25
+ const errors = checkPolicy({
26
+ blocks,
27
+ policy,
28
+ blockMetas: artifacts.blockMetas,
29
+ blockSchemas: artifacts.blockSchemas,
30
+ clientOperators: artifacts.clientOperators,
31
+ routes: artifacts.routes
32
+ });
33
+ if (errors.length > 0) {
34
+ return {
35
+ errors
36
+ };
37
+ }
38
+ }
39
+ try {
40
+ const built = artifacts.buildDynamicBlocks({
41
+ blocks,
42
+ pageId,
43
+ dynamicBlockId,
44
+ idPrefix,
45
+ types: artifacts.types,
46
+ blockMetas: artifacts.blockMetas,
47
+ clientOperators: artifacts.clientOperators,
48
+ dynamicPolicies: artifacts.dynamicPolicies,
49
+ policy,
50
+ usedTypes
51
+ });
52
+ await validateFragment(context, {
53
+ blocks: built.blocks,
54
+ blockSchemas: artifacts.blockSchemas,
55
+ callApiActionRefs: built.callApiActionRefs,
56
+ dynamicBlockId,
57
+ pageId,
58
+ pageRequests,
59
+ requestActionRefs: built.requestActionRefs
60
+ });
61
+ return {
62
+ errors: [],
63
+ ...built
64
+ };
65
+ } catch (error) {
66
+ if (!(error instanceof ConfigError)) {
67
+ throw error;
68
+ }
69
+ return {
70
+ errors: [
71
+ {
72
+ path: 'blocks',
73
+ rule: 'build',
74
+ message: error.message,
75
+ cause: error
76
+ }
77
+ ]
78
+ };
79
+ }
80
+ }
81
+ export default checkDynamicContent;
@@ -0,0 +1,242 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
+ import { type } from '@lowdefy/helpers';
17
+ import { findDataOrigin, getPossibleOperators } from '@lowdefy/operators';
18
+ function joinPath(path, key) {
19
+ return `${path}.${key}`;
20
+ }
21
+ // An object the client would run as an operator must have been written as one.
22
+ // The per-result scan refuses operators in data as it is returned; data merged
23
+ // with config afterwards (_object.assign, a key set to undefined) can still end
24
+ // up with an operator key alone, so the finished content is checked here.
25
+ function findDataOperator({ blocks, literalData }) {
26
+ const pending = [
27
+ {
28
+ node: blocks,
29
+ path: 'blocks'
30
+ }
31
+ ];
32
+ while(pending.length > 0){
33
+ const { node, path } = pending.pop();
34
+ if (type.isObject(node)) {
35
+ const [possible] = getPossibleOperators({
36
+ value: node,
37
+ operators: literalData.clientOperators
38
+ });
39
+ const origin = possible ? findDataOrigin({
40
+ literalData,
41
+ value: node
42
+ }) : null;
43
+ if (origin !== null) {
44
+ return {
45
+ operator: possible.operator,
46
+ origin,
47
+ path
48
+ };
49
+ }
50
+ }
51
+ if (type.isObject(node) || type.isArray(node)) {
52
+ const keys = Object.keys(node);
53
+ for(let index = keys.length - 1; index >= 0; index -= 1){
54
+ pending.push({
55
+ node: node[keys[index]],
56
+ path: joinPath(path, keys[index])
57
+ });
58
+ }
59
+ }
60
+ }
61
+ return null;
62
+ }
63
+ // The items a block, an event map, an action list or an action holds, in the
64
+ // order they are checked: a block's events, skeleton (rendered through
65
+ // LoadingBlock, like content) and child block lists; control branches (:if,
66
+ // :switch) of an action list. A :return item holds no action.
67
+ function getStructureChildren({ kind, node, path }) {
68
+ if (kind === 'block') {
69
+ const children = [
70
+ {
71
+ kind: 'events',
72
+ node: node.events,
73
+ path: `${path}.events`
74
+ },
75
+ {
76
+ kind: 'block',
77
+ node: node.skeleton,
78
+ path: `${path}.skeleton`
79
+ }
80
+ ];
81
+ if (type.isArray(node.blocks)) {
82
+ children.push({
83
+ kind: 'blocks',
84
+ node: node.blocks,
85
+ path: `${path}.blocks`
86
+ });
87
+ }
88
+ [
89
+ 'areas',
90
+ 'slots'
91
+ ].forEach((containerKey)=>{
92
+ if (!type.isObject(node[containerKey])) return;
93
+ Object.keys(node[containerKey]).forEach((name)=>{
94
+ children.push({
95
+ kind: 'blocks',
96
+ node: node[containerKey][name]?.blocks,
97
+ path: `${path}.${containerKey}.${name}.blocks`
98
+ });
99
+ });
100
+ });
101
+ return children;
102
+ }
103
+ if (kind === 'events') {
104
+ return Object.keys(node).flatMap((eventName)=>{
105
+ const event = node[eventName];
106
+ const eventPath = joinPath(path, eventName);
107
+ if (type.isArray(event)) {
108
+ return [
109
+ {
110
+ kind: 'actions',
111
+ node: event,
112
+ path: eventPath
113
+ }
114
+ ];
115
+ }
116
+ return [
117
+ {
118
+ kind: 'actions',
119
+ node: event?.try,
120
+ path: `${eventPath}.try`
121
+ },
122
+ {
123
+ kind: 'actions',
124
+ node: event?.catch,
125
+ path: `${eventPath}.catch`
126
+ }
127
+ ];
128
+ });
129
+ }
130
+ if (kind === 'blocks' || kind === 'actions') {
131
+ const itemKind = kind === 'blocks' ? 'block' : 'action';
132
+ return node.map((item, index)=>({
133
+ kind: itemKind,
134
+ node: item,
135
+ path: joinPath(path, index)
136
+ }));
137
+ }
138
+ if (':if' in node) {
139
+ return [
140
+ {
141
+ kind: 'actions',
142
+ node: node[':then'],
143
+ path: `${path}.:then`
144
+ },
145
+ {
146
+ kind: 'actions',
147
+ node: node[':else'],
148
+ path: `${path}.:else`
149
+ }
150
+ ];
151
+ }
152
+ if (':switch' in node) {
153
+ const cases = type.isArray(node[':switch']) ? node[':switch'] : [];
154
+ return [
155
+ ...cases.map((caseObject, caseIndex)=>({
156
+ kind: 'actions',
157
+ node: caseObject?.[':then'],
158
+ path: `${path}.:switch.${caseIndex}.:then`
159
+ })),
160
+ {
161
+ kind: 'actions',
162
+ node: node[':default'],
163
+ path: `${path}.:default`
164
+ }
165
+ ];
166
+ }
167
+ return [];
168
+ }
169
+ function isStructureNode({ kind, node }) {
170
+ if (kind === 'blocks' || kind === 'actions') {
171
+ return type.isArray(node);
172
+ }
173
+ return type.isObject(node);
174
+ }
175
+ // The first block or action in the content that is data, walked with an
176
+ // explicit stack.
177
+ function findDataStructure({ blocks, literalData }) {
178
+ const pending = [
179
+ {
180
+ kind: 'blocks',
181
+ node: blocks,
182
+ path: 'blocks'
183
+ }
184
+ ];
185
+ while(pending.length > 0){
186
+ const item = pending.pop();
187
+ if (isStructureNode(item)) {
188
+ const isAction = item.kind === 'action' && !(':if' in item.node) && !(':switch' in item.node) && !(':return' in item.node);
189
+ if (item.kind === 'block' || isAction) {
190
+ const origin = findDataOrigin({
191
+ literalData,
192
+ value: item.node
193
+ });
194
+ if (origin !== null) {
195
+ return {
196
+ what: item.kind === 'block' ? 'Block' : 'Action',
197
+ path: item.path,
198
+ origin
199
+ };
200
+ }
201
+ }
202
+ const children = getStructureChildren(item);
203
+ for(let index = children.length - 1; index >= 0; index -= 1){
204
+ pending.push(children[index]);
205
+ }
206
+ }
207
+ }
208
+ return null;
209
+ }
210
+ // Checks the content a Dynamic block's endpoint returns, as :return built it.
211
+ // Data may fill values inside the blocks the :return writes, but without a
212
+ // dynamic blocks policy it may not be a block or an action itself: a block or
213
+ // action that is data an operator returned, or a copy a copying read made of
214
+ // it, is refused. Config is never matched by content. With a policy the policy
215
+ // checks every block and action at page get instead. Under both, data may not
216
+ // become an operator.
217
+ function checkLiteralContent({ blocks, configKey, literalData }) {
218
+ if (!type.isArray(blocks)) {
219
+ return;
220
+ }
221
+ if (type.isNone(literalData.policyId)) {
222
+ const structure = findDataStructure({
223
+ blocks,
224
+ literalData
225
+ });
226
+ if (structure) {
227
+ throw new ConfigError(`${structure.what} at "${structure.path}" is data returned by "${structure.origin}". A Dynamic block without a dynamic blocks policy renders only blocks and actions written in its endpoint's :return config. Map data into blocks inside :return, or check stored blocks with a ValidateDynamic step under a policy.`, {
228
+ configKey
229
+ });
230
+ }
231
+ }
232
+ const operator = findDataOperator({
233
+ blocks,
234
+ literalData
235
+ });
236
+ if (operator) {
237
+ throw new ConfigError(`Data returned by "${operator.origin}" can run as the operator "${operator.operator}" at "${operator.path}" once it is merged with other config. Operators in endpoint data do not run in Dynamic block content.`, {
238
+ configKey
239
+ });
240
+ }
241
+ }
242
+ export default checkLiteralContent;
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
+ // Content without a policy fails on the build or fragment check's own error,
17
+ // which already names the Dynamic block. Policy violations are listed with the
18
+ // path and rule of each, and kept on the error for logging.
19
+ function createContentError({ block, errors, pageId, policy }) {
20
+ if (policy === null) {
21
+ return errors[0].cause;
22
+ }
23
+ const lines = errors.map((error)=>` - ${error.path}: ${error.message} [${error.rule}]`);
24
+ const contentError = new ConfigError(`Dynamic block "${block.blockId}" on page "${pageId}" resolved content violates dynamic blocks policy "${policy.id}":\n${lines.join('\n')}`, {
25
+ configKey: block['~k']
26
+ });
27
+ contentError.policyErrors = errors.map(({ path, rule, message })=>({
28
+ path,
29
+ rule,
30
+ message
31
+ }));
32
+ return contentError;
33
+ }
34
+ export default createContentError;
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ // The production client loads each page's own icons. Dynamic content can name
16
+ // any icon the app bundles (iconImports), so when the resolved page names one
17
+ // its page set lacks, the client loads the app-wide icons before the first
18
+ // render instead of drawing a placeholder until they arrive. The scan is the
19
+ // build's own discovery scan; the static part of the page adds nothing, since
20
+ // its icons are in the page set already. Unlike types, icons outside the page
21
+ // are expected here - content is only known at runtime - so there is no warning.
22
+ function flagIconsOutsidePage({ collectIconNames, iconImports, pageConfig, pageTypeSets }) {
23
+ // Dev builds write null: the dev client bundles every icon the app names.
24
+ if (pageTypeSets === null) {
25
+ return;
26
+ }
27
+ const pageIcons = new Set(pageTypeSets[pageConfig.pageId].icons);
28
+ const appIcons = new Set(iconImports);
29
+ const names = collectIconNames({
30
+ text: JSON.stringify(pageConfig)
31
+ });
32
+ for (const name of names){
33
+ if (appIcons.has(name) && !pageIcons.has(name)) {
34
+ pageConfig.loadAllIcons = true;
35
+ return;
36
+ }
37
+ }
38
+ }
39
+ export default flagIconsOutsidePage;
@@ -0,0 +1,44 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ // The production client loads each page's own client types. A fragment may use
16
+ // any type the app bundles (buildDynamicBlocks checks app-wide membership), so a
17
+ // fragment that reaches outside its page's types asks the client for the full
18
+ // set, and the warning names what the Dynamic block should declare.
19
+ function flagTypesOutsidePage(context, { pageConfig, pageTypeSets, usedTypes }) {
20
+ // Dev builds write null: the dev client bundles every installed type.
21
+ if (pageTypeSets === null) {
22
+ return;
23
+ }
24
+ const pageTypeSet = pageTypeSets[pageConfig.pageId];
25
+ const outside = [];
26
+ Object.entries(usedTypes).forEach(([category, used])=>{
27
+ const pageTypes = new Set(pageTypeSet[category]);
28
+ used.forEach((typeName)=>{
29
+ if (!pageTypes.has(typeName)) {
30
+ outside.push(typeName);
31
+ }
32
+ });
33
+ });
34
+ if (outside.length === 0) {
35
+ return;
36
+ }
37
+ pageConfig.loadAllTypes = true;
38
+ context.logger.warn({
39
+ event: 'dynamic_types_outside_page',
40
+ pageId: pageConfig.pageId,
41
+ types: outside
42
+ }, `Dynamic content on page "${pageConfig.pageId}" uses types not declared in its Dynamic blocks' properties.types: ${outside.join(', ')}. The page loads the full client type set.`);
43
+ }
44
+ export default flagTypesOutsidePage;
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { getConfigSchemaErrors } from '@lowdefy/ajv';
16
+ import { type } from '@lowdefy/helpers';
17
+ // Returns "properties/... message" strings for a block's schema violations,
18
+ // judged as the build judges config: see getConfigSchemaErrors.
19
+ function getPropertiesSchemaErrors({ block, blockSchemas }) {
20
+ const properties = block.properties;
21
+ if (!type.isObject(properties)) {
22
+ return [];
23
+ }
24
+ // Block schemas validate the whole pre-build block shape; the plugin's
25
+ // properties schema sits at schema.properties.properties.
26
+ const propertiesSchema = blockSchemas[block.type]?.properties?.properties;
27
+ if (type.isNone(propertiesSchema)) {
28
+ return [];
29
+ }
30
+ return getConfigSchemaErrors({
31
+ schema: propertiesSchema,
32
+ data: properties
33
+ }).map((error)=>`properties${error.instancePath || ''} ${error.message}`);
34
+ }
35
+ export default getPropertiesSchemaErrors;
@@ -0,0 +1,52 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ // Build artifacts every Dynamic content check reads. readConfigFile caches
16
+ // files per server lifetime, and the build package loads only when a page or
17
+ // routine first needs it.
18
+ // readConfigFile returns the same cached array per server lifetime, so the set
19
+ // is built once.
20
+ const clientOperatorSets = new WeakMap();
21
+ function getClientOperatorSet(names) {
22
+ if (names === null) {
23
+ return null;
24
+ }
25
+ if (!clientOperatorSets.has(names)) {
26
+ clientOperatorSets.set(names, new Set(names));
27
+ }
28
+ return clientOperatorSets.get(names);
29
+ }
30
+ async function loadDynamicArtifacts(context) {
31
+ const [{ default: buildDynamicBlocks }, types, blockMetas, blockSchemas, clientOperators, dynamicPolicies, routes] = await Promise.all([
32
+ import('@lowdefy/build/dynamic'),
33
+ context.readConfigFile('types.json'),
34
+ context.readConfigFile('plugins/blockMetas.json'),
35
+ context.readConfigFile('plugins/blockSchemas.json'),
36
+ context.readConfigFile('plugins/clientOperators.json'),
37
+ context.readConfigFile('dynamicPolicies.json'),
38
+ context.readConfigFile('routes.json')
39
+ ]);
40
+ return {
41
+ blockMetas: blockMetas ?? {},
42
+ blockSchemas: blockSchemas ?? {},
43
+ buildDynamicBlocks,
44
+ // Every client operator name the app knows, so only keys the client would
45
+ // run count as operators. Without the list every operator-shaped key counts.
46
+ clientOperators: getClientOperatorSet(clientOperators),
47
+ dynamicPolicies: dynamicPolicies ?? {},
48
+ routes,
49
+ types: types ?? {}
50
+ };
51
+ }
52
+ export default loadDynamicArtifacts;