@plitzi/sdk-server 0.38.24 → 0.39.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 (233) hide show
  1. package/CHANGELOG.md +152 -1
  2. package/README.md +55 -9
  3. package/dist/actions.d.ts +4 -1
  4. package/dist/actions.js +3 -2
  5. package/dist/auth.d.ts +2 -2
  6. package/dist/auth.js +5 -4
  7. package/dist/core/auth/api/accounts.d.ts +11 -0
  8. package/dist/core/auth/api/accounts.js +175 -0
  9. package/dist/core/auth/api/admin.d.ts +41 -0
  10. package/dist/core/auth/api/admin.js +146 -0
  11. package/dist/core/auth/api/context.d.ts +119 -0
  12. package/dist/core/auth/api/context.js +262 -0
  13. package/dist/core/auth/api/factors.d.ts +31 -0
  14. package/dist/core/auth/api/factors.js +209 -0
  15. package/dist/core/auth/api/index.d.ts +94 -0
  16. package/dist/core/auth/api/index.js +43 -0
  17. package/dist/core/auth/api/profile.d.ts +43 -0
  18. package/dist/core/auth/api/profile.js +243 -0
  19. package/dist/core/auth/api/session.d.ts +62 -0
  20. package/dist/core/auth/api/session.js +312 -0
  21. package/dist/core/auth/{api.d.ts → api/types.d.ts} +41 -195
  22. package/dist/core/auth/api/values.d.ts +67 -0
  23. package/dist/core/auth/api/values.js +90 -0
  24. package/dist/core/auth/createAuth.d.ts +49 -39
  25. package/dist/core/auth/createAuth.js +21 -1
  26. package/dist/core/auth/oauth/client.d.ts +2 -2
  27. package/dist/core/auth/oauth/client.js +6 -1
  28. package/dist/core/auth/oauth/index.d.ts +30 -7
  29. package/dist/core/auth/oauth/index.js +33 -14
  30. package/dist/core/auth/oauth/providers/github.js +1 -1
  31. package/dist/core/auth/oauth/providers/google.js +1 -1
  32. package/dist/core/auth/oauth/providers/oidc.d.ts +40 -0
  33. package/dist/core/auth/oauth/providers/oidc.js +197 -0
  34. package/dist/core/auth/oauth/state.d.ts +2 -0
  35. package/dist/core/auth/oauth/state.js +2 -0
  36. package/dist/core/auth/oauth/types.d.ts +21 -3
  37. package/dist/core/auth/oauth/types.js +4 -1
  38. package/dist/core/auth/routes.js +1 -1
  39. package/dist/core/auth/tokens.d.ts +3 -1
  40. package/dist/core/auth/tokens.js +2 -1
  41. package/dist/core/configSeam.d.ts +0 -4
  42. package/dist/core/configSeam.js +12 -1
  43. package/dist/core/createServer.js +16 -4
  44. package/dist/core/freePort.d.ts +10 -0
  45. package/dist/core/freePort.js +39 -1
  46. package/dist/core/handlers/socialRouteHandlers.d.ts +9 -1
  47. package/dist/core/handlers/socialRouteHandlers.js +46 -12
  48. package/dist/core/health.d.ts +1 -0
  49. package/dist/core/health.js +2 -1
  50. package/dist/core/http/stages/authRoutes.d.ts +6 -0
  51. package/dist/core/http/stages/authRoutes.js +42 -1
  52. package/dist/core/http/stages/images.js +5 -3
  53. package/dist/core/http/stages/livePages.js +1 -1
  54. package/dist/core/server/fleet/relay.js +9 -1
  55. package/dist/core/server/fleet/stores.d.ts +7 -0
  56. package/dist/core/server/fleet/stores.js +15 -2
  57. package/dist/core/server/pageServer.js +5 -1
  58. package/dist/core/services/realtime.js +4 -2
  59. package/dist/core/services/registry.js +7 -1
  60. package/dist/core/services/robotsTxt.d.ts +16 -0
  61. package/dist/core/services/robotsTxt.js +50 -0
  62. package/dist/core/services/servedSpace.d.ts +8 -0
  63. package/dist/core/services/servedSpace.js +16 -0
  64. package/dist/core/services/sitemapXml.d.ts +7 -0
  65. package/dist/core/services/sitemapXml.js +37 -0
  66. package/dist/functions-api.d.ts +69 -2
  67. package/dist/helpers/fileStore.d.ts +60 -0
  68. package/dist/helpers/fileStore.js +127 -0
  69. package/dist/helpers/outboundGuard.d.ts +32 -3
  70. package/dist/helpers/outboundGuard.js +50 -5
  71. package/dist/hosts/project/agentRuns.d.ts +24 -0
  72. package/dist/hosts/project/agentRuns.js +107 -0
  73. package/dist/hosts/project/laterAsks.d.ts +41 -0
  74. package/dist/hosts/project/laterAsks.js +117 -0
  75. package/dist/hosts/project/plugins.js +11 -4
  76. package/dist/hosts/project/serveProject.d.ts +8 -1
  77. package/dist/hosts/project/serveProject.js +81 -24
  78. package/dist/hosts/project/spaceFailure.d.ts +4 -0
  79. package/dist/hosts/project/spaceFailure.js +10 -0
  80. package/dist/hosts/project/watchSpace.d.ts +5 -5
  81. package/dist/hosts/project/watchSpace.js +15 -6
  82. package/dist/index.js +2 -2
  83. package/dist/kernel.js +1 -1
  84. package/dist/modules/actions/connectorWrite.js +3 -1
  85. package/dist/modules/actions/index.js +1 -1
  86. package/dist/modules/actions/jobs/fileQueue.d.ts +34 -0
  87. package/dist/modules/actions/jobs/fileQueue.js +72 -0
  88. package/dist/modules/actions/jobs/index.js +3 -3
  89. package/dist/modules/actions/jobs/memoryQueue.js +6 -215
  90. package/dist/modules/actions/jobs/queueDocument.d.ts +14 -0
  91. package/dist/modules/actions/jobs/queueDocument.js +22 -0
  92. package/dist/modules/actions/jobs/queueRules.d.ts +39 -0
  93. package/dist/modules/actions/jobs/queueRules.js +270 -0
  94. package/dist/modules/actions/moduleFor.js +2 -0
  95. package/dist/modules/actions/runtime/fileKv.d.ts +3 -1
  96. package/dist/modules/actions/runtime/fileKv.js +12 -98
  97. package/dist/modules/actions/runtime/guards.d.ts +19 -1
  98. package/dist/modules/actions/runtime/guards.js +10 -1
  99. package/dist/modules/actions/runtime/kvChange.d.ts +40 -0
  100. package/dist/modules/actions/runtime/kvChange.js +23 -1
  101. package/dist/modules/actions/runtime/kvList.d.ts +4 -0
  102. package/dist/modules/actions/runtime/kvList.js +5 -1
  103. package/dist/modules/actions/runtime/kvStore.js +15 -1
  104. package/dist/modules/actions/runtime/namespaceKv.js +2 -0
  105. package/dist/modules/actions/runtime/renderResolver.js +31 -5
  106. package/dist/modules/actions/runtime/runAction.js +16 -6
  107. package/dist/modules/actions/runtime/scope.js +11 -0
  108. package/dist/modules/actions/runtime/taskContext.js +11 -32
  109. package/dist/modules/actions/tasks/auth.js +2 -0
  110. package/dist/modules/actions/tasks/connector.js +6 -2
  111. package/dist/modules/actions/tasks/flow.js +5 -0
  112. package/dist/modules/actions/tasks/http.js +2 -1
  113. package/dist/modules/actions/tasks/kv.js +5 -0
  114. package/dist/modules/actions/tasks/list.js +11 -2
  115. package/dist/modules/actions/tasks/transform.js +2 -0
  116. package/dist/modules/actions/transport/callHandler.js +25 -4
  117. package/dist/modules/actions/types.d.ts +46 -1
  118. package/dist/modules/connectors/engine.d.ts +7 -2
  119. package/dist/modules/connectors/engine.js +4 -4
  120. package/dist/modules/connectors/resolver.d.ts +2 -1
  121. package/dist/modules/connectors/resolver.js +3 -2
  122. package/dist/modules/functions/build.d.ts +7 -2
  123. package/dist/modules/functions/build.js +90 -6
  124. package/dist/modules/functions/capabilities.js +16 -0
  125. package/dist/modules/functions/context.js +6 -2
  126. package/dist/modules/functions/contract.d.ts +39 -1
  127. package/dist/modules/functions/driver.d.ts +2 -1
  128. package/dist/modules/functions/driver.js +35 -0
  129. package/dist/modules/functions/load.d.ts +1 -1
  130. package/dist/modules/functions/load.js +2 -2
  131. package/dist/modules/functions/manifest.js +7 -1
  132. package/dist/modules/functions/oauth.d.ts +1 -1
  133. package/dist/modules/functions/oauth.js +4 -4
  134. package/dist/modules/functions/protocol.d.ts +6 -0
  135. package/dist/modules/functions/sandbox/guest/bytes.d.ts +27 -0
  136. package/dist/modules/functions/sandbox/guest/bytes.js +108 -0
  137. package/dist/modules/functions/sandbox/guest/crypto.d.ts +47 -0
  138. package/dist/modules/functions/sandbox/guest/crypto.js +144 -0
  139. package/dist/modules/functions/sandbox/guest/events.d.ts +152 -0
  140. package/dist/modules/functions/sandbox/guest/events.js +143 -0
  141. package/dist/modules/functions/sandbox/guest/fetch.d.ts +305 -0
  142. package/dist/modules/functions/sandbox/guest/fetch.js +237 -0
  143. package/dist/modules/functions/sandbox/guest/index.d.ts +28 -0
  144. package/dist/modules/functions/sandbox/guest/index.js +130 -0
  145. package/dist/modules/functions/sandbox/{guest.d.ts → guest/types.d.ts} +5 -12
  146. package/dist/modules/functions/sandbox/isolate.js +20 -6
  147. package/dist/modules/functions/space.js +2 -8
  148. package/dist/modules/images/imageProxy.d.ts +3 -2
  149. package/dist/modules/images/imageProxy.js +2 -2
  150. package/dist/modules/mongo/jobQueue.js +0 -19
  151. package/dist/modules/mysql/accounts.js +12 -5
  152. package/dist/modules/mysql/jobs/index.d.ts +1 -1
  153. package/dist/modules/mysql/jobs/schema.d.ts +0 -6
  154. package/dist/modules/mysql/jobs/schema.js +2 -46
  155. package/dist/modules/mysql/schema.js +26 -1
  156. package/dist/modules/mysql/sessions.js +2 -1
  157. package/dist/modules/realtime/handlers.d.ts +9 -4
  158. package/dist/modules/realtime/handlers.js +20 -3
  159. package/dist/modules/realtime/hub.d.ts +4 -2
  160. package/dist/modules/realtime/hub.js +36 -4
  161. package/dist/modules/realtime/index.d.ts +14 -0
  162. package/dist/modules/realtime/index.js +14 -1
  163. package/dist/modules/realtime/presence.d.ts +33 -0
  164. package/dist/modules/realtime/presence.js +56 -0
  165. package/dist/modules/realtime/socket.d.ts +3 -1
  166. package/dist/modules/realtime/socket.js +2 -2
  167. package/dist/modules/rsc/connectorRscData.d.ts +6 -1
  168. package/dist/modules/rsc/connectorRscData.js +27 -6
  169. package/dist/modules/rsc/externalQueryReader.d.ts +28 -0
  170. package/dist/modules/rsc/externalQueryReader.js +43 -0
  171. package/dist/modules/rsc/handler.js +1 -1
  172. package/dist/modules/rsc/resolveRscData.d.ts +11 -1
  173. package/dist/modules/rsc/resolveRscData.js +86 -16
  174. package/dist/modules/runtime/inside.js +1 -1
  175. package/dist/modules/runtime/runner.js +2 -1
  176. package/dist/modules/sqlite/jobQueue.d.ts +35 -0
  177. package/dist/modules/sqlite/jobQueue.js +56 -0
  178. package/dist/modules/sqlite/kv.d.ts +1 -1
  179. package/dist/modules/sqlite/kv.js +2 -10
  180. package/dist/modules/sqlite/open.d.ts +3 -0
  181. package/dist/modules/sqlite/open.js +13 -0
  182. package/dist/modules/ssr/Component.d.ts +5 -1
  183. package/dist/modules/ssr/Component.js +3 -1
  184. package/dist/modules/ssr/applySSRResult.d.ts +8 -1
  185. package/dist/modules/ssr/applySSRResult.js +23 -3
  186. package/dist/modules/ssr/handler.js +30 -5
  187. package/dist/modules/ssr/prepareRender.js +27 -5
  188. package/dist/modules/ssr/preview.d.ts +2 -0
  189. package/dist/modules/ssr/preview.js +6 -3
  190. package/dist/modules/ssr/registerExternalPlugins.d.ts +2 -6
  191. package/dist/modules/ssr/registerExternalPlugins.js +2 -2
  192. package/dist/modules/ssr/resolvePageSeo.d.ts +11 -0
  193. package/dist/modules/ssr/resolvePageSeo.js +13 -2
  194. package/dist/modules/ssr/streamBody.js +2 -2
  195. package/dist/modules/ssr/views/template.ejs +21 -17
  196. package/dist/mysql.d.ts +1 -1
  197. package/dist/mysql.js +2 -2
  198. package/dist/plugins/manager.d.ts +5 -0
  199. package/dist/plugins/manager.js +9 -0
  200. package/dist/sqlite.d.ts +8 -1
  201. package/dist/sqlite.js +3 -1
  202. package/package.json +5 -5
  203. package/skills/plitzi-authoring/CHEATSHEET.md +6 -6
  204. package/skills/plitzi-authoring/SKILL.md +4 -2
  205. package/skills/plitzi-authoring/recipes/accordion.ts +2 -1
  206. package/skills/plitzi-authoring/recipes/carousel.ts +24 -3
  207. package/skills/plitzi-authoring/recipes/detail-page.ts +0 -1
  208. package/skills/plitzi-authoring/recipes/embed-and-svg.ts +3 -1
  209. package/skills/plitzi-authoring/recipes/filter-a-list.ts +0 -1
  210. package/skills/plitzi-authoring/recipes/show-data.ts +0 -1
  211. package/skills/plitzi-authoring/recipes/typed-data.ts +0 -1
  212. package/skills/plitzi-authoring/reference/accessibility.md +7 -2
  213. package/skills/plitzi-authoring/reference/auth.md +15 -4
  214. package/skills/plitzi-authoring/reference/authoring-errors.md +51 -10
  215. package/skills/plitzi-authoring/reference/colours-and-motion.md +7 -1
  216. package/skills/plitzi-authoring/reference/components.md +4 -1
  217. package/skills/plitzi-authoring/reference/data-and-visibility.md +31 -22
  218. package/skills/plitzi-authoring/reference/efficiency.md +2 -1
  219. package/skills/plitzi-authoring/reference/elements-and-styles.md +16 -15
  220. package/skills/plitzi-authoring/reference/flows.md +20 -8
  221. package/skills/plitzi-authoring/reference/kept-state.md +8 -0
  222. package/skills/plitzi-authoring/reference/layouts.md +18 -2
  223. package/skills/plitzi-authoring/reference/lists.md +20 -4
  224. package/skills/plitzi-authoring/reference/plugin-reach.md +12 -0
  225. package/skills/plitzi-authoring/reference/plugins.md +13 -2
  226. package/skills/plitzi-authoring/reference/realtime.md +8 -5
  227. package/skills/plitzi-authoring/reference/structure.md +17 -1
  228. package/skills/plitzi-authoring/reference/templates.md +11 -3
  229. package/skills/plitzi-authoring/reference/testing.md +82 -5
  230. package/skills/plitzi-authoring/reference/typed-sources.md +6 -0
  231. package/skills/plitzi-authoring/reference/validation.md +1 -1
  232. package/dist/core/auth/api.js +0 -1323
  233. package/dist/modules/functions/sandbox/guest.js +0 -662
@@ -29,6 +29,7 @@ var connectorTasks = [{
29
29
  namespace: "connector",
30
30
  action: "read",
31
31
  title: "Connector Read",
32
+ description: "Reads a resource through one of the space's connectors — a page of it, filtered; answers `records` and `pageInfo`.",
32
33
  params: {
33
34
  connector: {
34
35
  type: "text",
@@ -80,7 +81,8 @@ var connectorTasks = [{
80
81
  offset: toNumber(params.offset),
81
82
  filters: parseFilters(params.filters)
82
83
  },
83
- fetchImpl: ctx.fetch
84
+ fetchImpl: ctx.fetch,
85
+ outbound: ctx.outbound
84
86
  });
85
87
  return {
86
88
  records: result.records,
@@ -91,6 +93,7 @@ var connectorTasks = [{
91
93
  namespace: "connector",
92
94
  action: "write",
93
95
  title: "Connector Write",
96
+ description: "Creates, updates or deletes a record through one of the space's connectors (`endpoint`); answers the `record` written.",
94
97
  params: {
95
98
  connector: {
96
99
  type: "text",
@@ -133,7 +136,8 @@ var connectorTasks = [{
133
136
  resource: params.resource || void 0,
134
137
  recordId: params.recordId || void 0,
135
138
  values: parseValues(params.values),
136
- fetchImpl: ctx.fetch
139
+ fetchImpl: ctx.fetch,
140
+ outbound: ctx.outbound
137
141
  }) ?? null };
138
142
  }
139
143
  }];
@@ -13,6 +13,7 @@ var delay = {
13
13
  namespace: "flow",
14
14
  action: "delay",
15
15
  title: "Delay",
16
+ description: "Waits so many milliseconds before the next step, capped by the run's time budget; answers `waited`.",
16
17
  params: { milliseconds: {
17
18
  type: "text",
18
19
  canBind: true,
@@ -40,6 +41,7 @@ var fail = {
40
41
  namespace: "flow",
41
42
  action: "fail",
42
43
  title: "Fail",
44
+ description: "Ends the run as failed, with its message. `tellCaller` hands the message to whoever called — a form's refusal; otherwise the caller hears only that it failed.",
43
45
  params: {
44
46
  message: {
45
47
  type: "text",
@@ -95,6 +97,7 @@ var output = {
95
97
  namespace: "flow",
96
98
  action: "output",
97
99
  title: "Output",
100
+ description: "What the run answers its caller: the values, a JSON object built from the steps before (`{{ step.value|json_encode }}`).",
98
101
  params: { values: {
99
102
  type: "codemirror-json",
100
103
  canBind: true,
@@ -120,6 +123,7 @@ var emit = {
120
123
  namespace: "stream",
121
124
  action: "emit",
122
125
  title: "Report Progress",
126
+ description: "Sends a chunk of progress to the caller while the run goes on — what a streaming answer is made of; answers `emitted`.",
123
127
  params: { chunk: {
124
128
  type: "codemirror-text",
125
129
  canBind: true,
@@ -143,6 +147,7 @@ var rateLimit = {
143
147
  namespace: "flow",
144
148
  action: "rateLimit",
145
149
  title: "Rate Limit",
150
+ description: "Lets a caller through at most `limit` times every `windowSeconds`, counted for each person or for everyone together; past it, the run fails with the refusal as its message. First in a public action that writes. Answers `count` and `remaining`.",
146
151
  params: {
147
152
  bucket: {
148
153
  type: "text",
@@ -17,6 +17,7 @@ var httpTasks = [{
17
17
  namespace: "http",
18
18
  action: "request",
19
19
  title: "HTTP Request",
20
+ description: "Calls a URL — with one of the space's credentials when named, never written in the step — and answers `status`, `ok` and `data` (the body, read as JSON when it is).",
20
21
  rawParams: true,
21
22
  params: {
22
23
  credential: {
@@ -93,7 +94,7 @@ var httpTasks = [{
93
94
  headers,
94
95
  body: hasBody ? JSON.stringify(parseJsonParam(params.body, "Body")) : void 0,
95
96
  signal: ctx.signal
96
- });
97
+ }, ctx.outbound);
97
98
  const text = await response.text();
98
99
  let data = text;
99
100
  try {
@@ -9,6 +9,7 @@ var kvTasks = [
9
9
  namespace: "kv",
10
10
  action: "get",
11
11
  title: "Read Value",
12
+ description: "Reads a value the space's actions keep (its kv) by key; answers `value`, null when there is none.",
12
13
  params: { key: {
13
14
  type: "text",
14
15
  canBind: true,
@@ -21,6 +22,7 @@ var kvTasks = [
21
22
  namespace: "kv",
22
23
  action: "set",
23
24
  title: "Write Value",
25
+ description: "Keeps a value under a key, for a while when `ttlSeconds` is given; answers `stored`.",
24
26
  params: {
25
27
  key: {
26
28
  type: "text",
@@ -54,6 +56,7 @@ var kvTasks = [
54
56
  namespace: "kv",
55
57
  action: "setIf",
56
58
  title: "Write Value If Unchanged",
59
+ description: "Writes a value only if the key still holds what was read before — or nothing, when `expected` is empty — so two runs at once cannot both write it; answers `written` and the `value` it holds.",
57
60
  params: {
58
61
  key: {
59
62
  type: "text",
@@ -93,6 +96,7 @@ var kvTasks = [
93
96
  namespace: "kv",
94
97
  action: "increment",
95
98
  title: "Increment Counter",
99
+ description: "Adds to a counter under a key, from 0 when there is none; answers the new `value`.",
96
100
  params: {
97
101
  key: {
98
102
  type: "text",
@@ -122,6 +126,7 @@ var kvTasks = [
122
126
  namespace: "kv",
123
127
  action: "delete",
124
128
  title: "Delete Value",
129
+ description: "Drops a key of the space's kv; answers `deleted`.",
125
130
  params: { key: {
126
131
  type: "text",
127
132
  canBind: true,
@@ -5,13 +5,19 @@ var toNumber = (value, fallback) => {
5
5
  const parsed = typeof value === "number" ? value : Number(value);
6
6
  return Number.isFinite(parsed) ? parsed : fallback;
7
7
  };
8
- /** What a typed value means: JSON when it reads as JSON, the text itself when it does not. A bound value as it is. */
8
+ /**
9
+ * What a typed value means: JSON when it reads as JSON, the text itself when it does not. A bound value as it is. A
10
+ * value written as an object or a list that does not read — a quote in a field put in by a template without
11
+ * `json_encode` — is refused, never kept as a string the readers of the list would then fail on.
12
+ */
9
13
  var valueOf = (value) => {
10
14
  if (typeof value !== "string") return value ?? null;
11
15
  if (value === "") return null;
12
16
  try {
13
17
  return JSON.parse(value);
14
- } catch {
18
+ } catch (error) {
19
+ const start = value.trimStart()[0];
20
+ if (start === "{" || start === "[") throw new Error(`The value is written as JSON but does not read as JSON (${error instanceof Error ? error.message : String(error)}): a value put in by a template outside quotes — a number, a list, one that may be empty — is written with |json_encode ("amount": {{ input.amount|json_encode }}); inside quotes it is escaped already`, { cause: error });
15
21
  return value;
16
22
  }
17
23
  };
@@ -26,6 +32,7 @@ var listTasks = [
26
32
  namespace: "list",
27
33
  action: "put",
28
34
  title: "Add To List",
35
+ description: "Adds an entry to a list the space's actions keep — by id, with a score the list is ordered by and a value (a JSON document) — replacing the entry of the same id; `keep` drops the lowest beyond it. Answers `stored` and the ids `dropped`.",
29
36
  params: {
30
37
  list: nameParam,
31
38
  id: {
@@ -82,6 +89,7 @@ var listTasks = [
82
89
  namespace: "list",
83
90
  action: "range",
84
91
  title: "Read List",
92
+ description: "Reads a window of a list, by score: answers `entries`, each `id`, `score` and `value`.",
85
93
  params: {
86
94
  list: nameParam,
87
95
  offset: {
@@ -125,6 +133,7 @@ var listTasks = [
125
133
  namespace: "list",
126
134
  action: "remove",
127
135
  title: "Remove From List",
136
+ description: "Takes an entry out of a list by its id; answers `removed`.",
128
137
  params: {
129
138
  list: nameParam,
130
139
  id: {
@@ -3,6 +3,7 @@ var transformTasks = [{
3
3
  namespace: "transform",
4
4
  action: "template",
5
5
  title: "Template",
6
+ description: "A template rendered against the run's input and the steps before it; answers `value` — text, or the JSON document it writes.",
6
7
  rawParams: true,
7
8
  params: { template: {
8
9
  type: "codemirror-text",
@@ -15,6 +16,7 @@ var transformTasks = [{
15
16
  namespace: "transform",
16
17
  action: "json",
17
18
  title: "Parse JSON",
19
+ description: "Reads a JSON text into a value; answers `value`. A text that is not JSON fails the step.",
18
20
  params: { value: {
19
21
  type: "codemirror-text",
20
22
  canBind: true,
@@ -83,6 +83,11 @@ var handleActionCall = async (deps) => {
83
83
  fail(res, "invalid_input", "Expected { actionId, input }");
84
84
  return;
85
85
  }
86
+ if (body.trigger === "render" && config.devMode !== true) {
87
+ fail(res, "forbidden", "A render is run from the command line on a development server alone (devMode)");
88
+ return;
89
+ }
90
+ const trigger = body.trigger === "render" ? "render" : "call";
86
91
  /**
87
92
  * A call that never became a run, told to whoever keeps the deployment's records.
88
93
  *
@@ -94,7 +99,7 @@ var handleActionCall = async (deps) => {
94
99
  actionId: body.actionId,
95
100
  spaceId,
96
101
  environment,
97
- trigger: "call",
102
+ trigger,
98
103
  reason,
99
104
  callerId,
100
105
  ...detail === void 0 ? {} : { detail }
@@ -138,7 +143,7 @@ var handleActionCall = async (deps) => {
138
143
  let entryPoint;
139
144
  try {
140
145
  entryPoint = precheckRun(entry, {
141
- trigger: "call",
146
+ trigger,
142
147
  input,
143
148
  user: req.ctx.user,
144
149
  lineage
@@ -146,6 +151,20 @@ var handleActionCall = async (deps) => {
146
151
  run = await module.guards.begin(begin);
147
152
  } catch (error) {
148
153
  const reason = error instanceof ActionRunError ? error.reason : "failed";
154
+ const joined = reason === "duplicate" ? module.guards.join(begin) : void 0;
155
+ if (joined) {
156
+ const answer = await joined;
157
+ res.setHeader("X-Plitzi-Joined", "true");
158
+ if (answer) send(res, 200, {
159
+ runId: answer.runId,
160
+ status: answer.status,
161
+ output: answer.output,
162
+ ...answer.error === void 0 ? {} : { error: answer.error },
163
+ joined: true
164
+ }, answer.runId);
165
+ else fail(res, "failed", "The same call was already running, and it ended with no answer");
166
+ return;
167
+ }
149
168
  await reject(reason, error instanceof Error ? error.message : void 0);
150
169
  fail(res, reason, error instanceof Error ? error.message : "Action refused");
151
170
  return;
@@ -192,7 +211,7 @@ var handleActionCall = async (deps) => {
192
211
  input,
193
212
  spaceId,
194
213
  environment,
195
- trigger: "call",
214
+ trigger,
196
215
  user: req.ctx.user,
197
216
  callerId,
198
217
  ...origin ? { origin } : {},
@@ -228,6 +247,7 @@ var handleActionCall = async (deps) => {
228
247
  status: result.status,
229
248
  output: result.output,
230
249
  ...result.error === void 0 ? {} : { error: result.error },
250
+ ...result.code === void 0 ? {} : { code: result.code },
231
251
  ...outline ? { steps: result.steps } : {}
232
252
  }
233
253
  });
@@ -238,7 +258,8 @@ var handleActionCall = async (deps) => {
238
258
  runId: result.runId,
239
259
  status: result.status,
240
260
  output: result.output,
241
- ...result.error === void 0 ? {} : { error: result.error }
261
+ ...result.error === void 0 ? {} : { error: result.error },
262
+ ...result.code === void 0 ? {} : { code: result.code }
242
263
  };
243
264
  if (outline) payload.steps = result.steps;
244
265
  if (fullTrace) payload.trace = result.trace;
@@ -1,7 +1,8 @@
1
1
  import { LaterAnswer, LaterRequest } from './jobs/later';
2
2
  import { ActionEmailSender } from './runtime/email';
3
+ import { OutboundOptions } from '../../helpers/outboundGuard';
3
4
  import { FunctionsConfig } from '../functions/config';
4
- import { FunctionJobs } from '../functions/contract';
5
+ import { FunctionJobs, FunctionPresence, FunctionVisitor } from '../functions/contract';
5
6
  import { SpaceFunctions } from '../functions/protocol';
6
7
  import { KvChangeLifetime } from './runtime/kvChange';
7
8
  import { KvListEntry, KvListPut, KvListPutOptions, KvListRange } from './runtime/kvList';
@@ -88,6 +89,24 @@ export type ActionKvStore = {
88
89
  listRange: (list: string, range?: KvListRange) => Promise<KvListEntry[]>;
89
90
  /** Takes the entry with `id` out of the list, and answers whether it was there. */
90
91
  listRemove: (list: string, id: string) => Promise<boolean>;
92
+ /**
93
+ * Writes the list's entry `id` as `next` — or takes it out, `next` null — only if it is still `expected`, the entry
94
+ * `listRange` answered (or, `expected` undefined, only if there is none). Answers whether it wrote: `swap`, for one
95
+ * entry of a list.
96
+ */
97
+ listSwap: (list: string, id: string, expected: KvListEntry | undefined, next: KvListEntry | null) => Promise<boolean>;
98
+ /**
99
+ * Reads the list's entry `id`, hands it to `change` and writes back what that answers — `{ score, value }`, or `null`
100
+ * to take it out — reading and asking again when somebody wrote in between. `undefined` writes nothing. A vote that
101
+ * re-scores an entry while the track it is starts was the race (a run's queue): the entry gone, nothing is put back.
102
+ */
103
+ listChange: (list: string, id: string, change: (current: KvListEntry | undefined) => {
104
+ score: number;
105
+ value: unknown;
106
+ } | null | undefined | Promise<{
107
+ score: number;
108
+ value: unknown;
109
+ } | null | undefined>) => Promise<KvListEntry | null | undefined>;
91
110
  /**
92
111
  * Reads the key, hands its value to `change` and writes back what that answers — reading and asking again when
93
112
  * somebody wrote in between, so no writer undoes another. `change` answering `undefined` writes nothing. Answers what
@@ -135,6 +154,12 @@ export type ActionLookups = {
135
154
  * self-hosted server derives from its own when it is given none. Absent, neither reads anything here.
136
155
  */
137
156
  getData?: (spaceId: number, at?: SpaceRevision) => Promise<Record<string, string> | undefined>;
157
+ /**
158
+ * One person of the space, by username or id — public fields alone (`FunctionVisitor`), and only of someone who
159
+ * belongs to it: what a function's `ctx.visitors.get` reads. Absent, a server with an `auth` of its own answers its
160
+ * accounts; else nobody is read.
161
+ */
162
+ getVisitor?: (spaceId: number, environment: string, who: string | number) => Promise<FunctionVisitor | undefined>;
138
163
  /**
139
164
  * The feature flags the space declares as of that revision, for a flow that reads `{{ flags.<name> }}`. Only asked
140
165
  * for a run whose document names `flags` at all. Absent, such a flow sees no flags — and the server says so.
@@ -174,6 +199,11 @@ export type ActionTaskContext = {
174
199
  credential: (identifier: string) => Promise<ActionCredential | undefined>;
175
200
  connector: (connectorId: string) => Promise<ResolvedConnector | undefined>;
176
201
  fetch: typeof fetch;
202
+ /**
203
+ * What an authored request may reach from here, handed to `fetchOutbound` with every one: the deployment's own
204
+ * origins on its network (`outbound.privateOrigins`) and nothing else private. Absent, nothing private.
205
+ */
206
+ outbound?: OutboundOptions;
177
207
  /** Key/value storage, namespaced to this space by the runner — a key one space writes is a key only it reads. */
178
208
  kv: ActionKvStore;
179
209
  /** The database engines this deployment registered, for the `db.query` task. */
@@ -192,6 +222,10 @@ export type ActionTaskContext = {
192
222
  * the `realtime.publish` task sends through.
193
223
  */
194
224
  publish?: (topic: string, type: string, data: unknown) => Promise<void>;
225
+ /** Who is on a topic of a `presence: true` channel of this space, on every replica — `undefined` with no channels. */
226
+ presence?: (topic: string) => Promise<FunctionPresence>;
227
+ /** One person of the space, public fields alone — `undefined` when the server tells no visitor apart. */
228
+ visitor?: (who: string | number) => Promise<FunctionVisitor | undefined>;
195
229
  /**
196
230
  * A grant for one topic of a `grant: true` channel of this space — what `realtime.grant` hands the page, once the
197
231
  * flow has decided the visitor may be there. `undefined` when the server has no realtime channels.
@@ -245,6 +279,10 @@ export type ActionRealtime = {
245
279
  spaceId: number;
246
280
  environment: string;
247
281
  }, topic: string, grant?: string) => Promise<void>;
282
+ presence?: (space: {
283
+ spaceId: number;
284
+ environment: string;
285
+ }, topic: string) => Promise<FunctionPresence>;
248
286
  /** Says a job of the space's functions as it is now, on its own topic (`$job:<id>`), kept for a page that joins. */
249
287
  publishJob?: (space: {
250
288
  spaceId: number;
@@ -319,6 +357,8 @@ export type ActionsConfig = {
319
357
  rateLimit?: {
320
358
  webhookPerMinute?: number;
321
359
  };
360
+ /** The deployment's own origins on its network a flow's request may reach (`outbound.privateOrigins`), validated. */
361
+ outbound?: OutboundOptions;
322
362
  /** Database engines this deployment lets a flow reach. Empty → the `db.query` task is not offered at all. */
323
363
  dbDrivers?: ActionDbDriver[];
324
364
  /** The limits on `email.send`: messages per space per day, and whether an SMTP host may be on a private network. */
@@ -472,4 +512,9 @@ export type ActionRunResult = {
472
512
  steps: ActionRunStep[];
473
513
  /** Why the run failed, when a step said so for the caller (`ActionRefusal`). Absent for every other failure. */
474
514
  error?: string;
515
+ /**
516
+ * The refusal's code, when its step gave one (`refuse('banned', …)`): what a page tells refusals apart by — a run's
517
+ * specs could only read their words.
518
+ */
519
+ code?: string;
475
520
  };
@@ -1,4 +1,5 @@
1
1
  import { ConnectorCredential, ConnectorManifest, ConnectorQuery, ConnectorRecord, ConnectorResult } from './types';
2
+ import { OutboundOptions } from '../../helpers/outboundGuard';
2
3
  export type FetchConnectorOptions = {
3
4
  manifest: ConnectorManifest;
4
5
  /** Which read endpoint to execute. Defaults to `list`, the one an element addresses when it names none. */
@@ -7,6 +8,8 @@ export type FetchConnectorOptions = {
7
8
  query?: ConnectorQuery;
8
9
  /** Injected so tests — and a future edge runtime — can supply their own transport. */
9
10
  fetchImpl?: typeof fetch;
11
+ /** The deployment's own origins on its network a manifest may name (`outbound.privateOrigins`). */
12
+ outbound?: OutboundOptions;
10
13
  };
11
14
  export type WriteConnectorOptions = {
12
15
  manifest: ConnectorManifest;
@@ -17,6 +20,8 @@ export type WriteConnectorOptions = {
17
20
  recordId?: string;
18
21
  values?: Record<string, unknown>;
19
22
  fetchImpl?: typeof fetch;
23
+ /** The deployment's own origins on its network a manifest may name (`outbound.privateOrigins`). */
24
+ outbound?: OutboundOptions;
20
25
  };
21
26
  /**
22
27
  * Rebases the relative media paths a CMS returns (`/uploads/cover.jpg`) onto the manifest's media host.
@@ -32,11 +37,11 @@ export declare const rebaseMedia: (value: unknown, baseUrl: string) => unknown;
32
37
  * Everything provider-specific — the endpoint, the auth header, where the array lives, how paging is expressed —
33
38
  * comes from the manifest, so a new CMS is configuration rather than code.
34
39
  */
35
- export declare const fetchConnectorRecords: ({ manifest, endpoint, credential, query, fetchImpl }: FetchConnectorOptions) => Promise<ConnectorResult>;
40
+ export declare const fetchConnectorRecords: ({ manifest, endpoint, credential, query, fetchImpl, outbound }: FetchConnectorOptions) => Promise<ConnectorResult>;
36
41
  /**
37
42
  * Executes one connector write.
38
43
  *
39
44
  * An action the manifest does not declare is refused rather than inferred: a connector is read-only until its
40
45
  * owner says otherwise, so a form can never reach a provider that was never meant to be written to.
41
46
  */
42
- export declare const writeConnectorRecord: ({ manifest, credential, action, resource, recordId, values, fetchImpl }: WriteConnectorOptions) => Promise<ConnectorRecord | undefined>;
47
+ export declare const writeConnectorRecord: ({ manifest, credential, action, resource, recordId, values, fetchImpl, outbound }: WriteConnectorOptions) => Promise<ConnectorRecord | undefined>;
@@ -123,7 +123,7 @@ var toRecords = (items, mapping) => items.reduce((acum, item, index) => {
123
123
  * Everything provider-specific — the endpoint, the auth header, where the array lives, how paging is expressed —
124
124
  * comes from the manifest, so a new CMS is configuration rather than code.
125
125
  */
126
- var fetchConnectorRecords = async ({ manifest, endpoint = DEFAULT_READ_ENDPOINT, credential = {}, query = {}, fetchImpl = fetch }) => {
126
+ var fetchConnectorRecords = async ({ manifest, endpoint = DEFAULT_READ_ENDPOINT, credential = {}, query = {}, fetchImpl = fetch, outbound }) => {
127
127
  const { endpoints, ...connection } = manifest;
128
128
  const read = Object.hasOwn(endpoints.read, endpoint) ? endpoints.read[endpoint] : void 0;
129
129
  if (!read) throw new Error(`Connector ${connection.id} has no read endpoint named "${endpoint}"`);
@@ -161,7 +161,7 @@ var fetchConnectorRecords = async ({ manifest, endpoint = DEFAULT_READ_ENDPOINT,
161
161
  method,
162
162
  headers,
163
163
  body: sendsBody ? JSON.stringify(renderEntries(read.body ?? {}, variables)) : void 0
164
- });
164
+ }, outbound);
165
165
  if (!response.ok) throw new Error(`Connector ${connection.id} responded ${response.status} for ${url.pathname}`);
166
166
  const payload = await response.json();
167
167
  const rawItems = getByPath(payload, read.itemsPath);
@@ -189,7 +189,7 @@ var wrapBody = (values, bodyPath) => {
189
189
  * An action the manifest does not declare is refused rather than inferred: a connector is read-only until its
190
190
  * owner says otherwise, so a form can never reach a provider that was never meant to be written to.
191
191
  */
192
- var writeConnectorRecord = async ({ manifest, credential = {}, action, resource, recordId, values = {}, fetchImpl = fetch }) => {
192
+ var writeConnectorRecord = async ({ manifest, credential = {}, action, resource, recordId, values = {}, fetchImpl = fetch, outbound }) => {
193
193
  const { endpoints, ...connection } = manifest;
194
194
  const operation = endpoints.write?.[action];
195
195
  if (!operation) throw new Error(`Connector ${connection.id} does not allow "${action}"`);
@@ -210,7 +210,7 @@ var writeConnectorRecord = async ({ manifest, credential = {}, action, resource,
210
210
  method: operation.method,
211
211
  headers,
212
212
  body: BODYLESS_METHODS.includes(operation.method) ? void 0 : JSON.stringify(wrapBody(values, operation.bodyPath))
213
- });
213
+ }, outbound);
214
214
  if (!response.ok) throw new Error(`Connector ${connection.id} responded ${response.status} for ${action} on ${url.pathname}`);
215
215
  if (EMPTY_RESPONSE_METHODS.includes(operation.method) || response.status === 204) return;
216
216
  const mapping = operation.response ?? {};
@@ -1,4 +1,5 @@
1
1
  import { ConnectorCredential, ConnectorManifest } from './types';
2
+ import { OutboundOptions } from '../../helpers/outboundGuard';
2
3
  import { RscElementResolver } from '../rsc/resolveRscData';
3
4
  import { SpaceRevision } from '@plitzi/sdk-shared';
4
5
  export type ConnectorLookups = {
@@ -23,4 +24,4 @@ export type ProviderPagination = 'none' | 'url' | 'append';
23
24
  * An element without a connector resolves to nothing rather than failing — an unconfigured provider on a page is a
24
25
  * draft, not an error.
25
26
  */
26
- export declare const createConnectorResolver: ({ getConnector, getCredential, fetchImpl }: ConnectorLookups) => RscElementResolver;
27
+ export declare const createConnectorResolver: ({ getConnector, getCredential, fetchImpl }: ConnectorLookups, outbound?: OutboundOptions) => RscElementResolver;
@@ -28,7 +28,7 @@ var toPage = (queryParams, attributes) => {
28
28
  * An element without a connector resolves to nothing rather than failing — an unconfigured provider on a page is a
29
29
  * draft, not an error.
30
30
  */
31
- var createConnectorResolver = ({ getConnector, getCredential, fetchImpl }) => async ({ element, flat, routeParams, queryParams, spaceId, environment, req }) => {
31
+ var createConnectorResolver = ({ getConnector, getCredential, fetchImpl }, outbound) => async ({ element, flat, routeParams, queryParams, spaceId, environment, req }) => {
32
32
  const deployment = req.ctx.spaceDeployment;
33
33
  const at = {
34
34
  environment: deployment?.environment ?? environment,
@@ -57,7 +57,8 @@ var createConnectorResolver = ({ getConnector, getCredential, fetchImpl }) => as
57
57
  routeParams,
58
58
  queryParams
59
59
  },
60
- fetchImpl
60
+ fetchImpl,
61
+ outbound
61
62
  });
62
63
  const slice = {
63
64
  ...singleRecord ? { record: records[0] } : { records },
@@ -1,3 +1,4 @@
1
+ import { FunctionsDefinition } from './contract';
1
2
  import { FunctionsProblem } from '@plitzi/sdk-shared';
2
3
  /** A space's functions source: its files under `functions/`, by path (`index.ts`, `lib/feed.ts`). */
3
4
  export type FunctionsSource = Record<string, string>;
@@ -10,8 +11,12 @@ export declare class FunctionsBuildError extends Error {
10
11
  readonly problems: FunctionsProblem[];
11
12
  constructor(problems: FunctionsProblem[]);
12
13
  }
13
- /** The file a space's functions start from. */
14
- export declare const FUNCTIONS_ENTRY = "index.ts";
14
+ /**
15
+ * The definitions of `files`, merged into one — what a bundle exports by default. Printed into the bundle from itself,
16
+ * so it uses nothing outside: two tasks of one id or two routes of one path are refused, naming both files; the hosts
17
+ * code may reach are every file's together; a file whose default export is not a definition is no definition.
18
+ */
19
+ export declare const mergeFunctions: (files: [string, unknown][]) => FunctionsDefinition;
15
20
  /** The most a bundle may weigh: well under the smallest provider a runner may be (Workers take 3 MB compressed). */
16
21
  export declare const MAX_FUNCTIONS_BYTES = 1000000;
17
22
  /**
@@ -1,6 +1,6 @@
1
1
  import { ActionRefusal } from "../actions/runtime/errors.js";
2
2
  import { defineFunctions } from "./contract.js";
3
- import { isFunctionsSourcePath } from "@plitzi/sdk-shared/actions";
3
+ import { exportsByDefault, isFunctionsDefinitionFile, isFunctionsSourcePath } from "@plitzi/sdk-shared/actions";
4
4
  import path from "node:path";
5
5
  import esbuild from "esbuild";
6
6
  //#region src/modules/functions/build.ts
@@ -12,8 +12,78 @@ var FunctionsBuildError = class extends Error {
12
12
  this.problems = problems;
13
13
  }
14
14
  };
15
- /** The file a space's functions start from. */
16
- var FUNCTIONS_ENTRY = "index.ts";
15
+ /**
16
+ * The definitions of `files`, merged into one — what a bundle exports by default. Printed into the bundle from itself,
17
+ * so it uses nothing outside: two tasks of one id or two routes of one path are refused, naming both files; the hosts
18
+ * code may reach are every file's together; a file whose default export is not a definition is no definition.
19
+ */
20
+ var mergeFunctions = (files) => {
21
+ const isDefinition = (value) => typeof value === "object" && value !== null && [
22
+ "tasks",
23
+ "routes",
24
+ "allow",
25
+ "limits",
26
+ "oauth",
27
+ "jobs"
28
+ ].some((key) => key in value) && !Array.isArray(value);
29
+ const tasks = [];
30
+ const routes = {};
31
+ const oauth = {};
32
+ const jobs = {};
33
+ const hosts = /* @__PURE__ */ new Set();
34
+ const from = /* @__PURE__ */ new Map();
35
+ let limits;
36
+ let found = 0;
37
+ const once = (kind, name, file) => {
38
+ const before = from.get(`${kind} ${name}`);
39
+ if (before !== void 0) throw new Error(`The ${kind} ${name} is defined twice: in ${before} and in ${file} — one file defines it`);
40
+ from.set(`${kind} ${name}`, file);
41
+ };
42
+ for (const [file, value] of files) {
43
+ if (!isDefinition(value)) continue;
44
+ found += 1;
45
+ for (const task of value.tasks ?? []) {
46
+ once("task", `${task.namespace}.${task.action}`, file);
47
+ tasks.push(task);
48
+ }
49
+ for (const [route, handler] of Object.entries(value.routes ?? {})) {
50
+ once("route", route, file);
51
+ routes[route] = handler;
52
+ }
53
+ for (const [name, connection] of Object.entries(value.oauth ?? {})) {
54
+ once("OAuth connection", name, file);
55
+ oauth[name] = connection;
56
+ }
57
+ for (const [name, job] of Object.entries(value.jobs ?? {})) {
58
+ once("job", name, file);
59
+ jobs[name] = job;
60
+ }
61
+ if (value.limits !== void 0) {
62
+ if (limits !== void 0) throw new Error(`The functions' limits are said twice: in ${limits.file} and in ${file} — they are every task's, said once`);
63
+ limits = {
64
+ file,
65
+ value: value.limits
66
+ };
67
+ }
68
+ for (const host of value.allow?.hosts ?? []) hosts.add(host);
69
+ }
70
+ if (found === 0) throw new Error("No file at the top of functions/ exports a definition by default: export default defineFunctions({ tasks: [ … ] }) in each domain's file");
71
+ return {
72
+ tasks,
73
+ ...Object.keys(routes).length > 0 ? { routes } : {},
74
+ ...Object.keys(oauth).length > 0 ? { oauth } : {},
75
+ ...Object.keys(jobs).length > 0 ? { jobs } : {},
76
+ ...limits ? { limits: limits.value } : {},
77
+ ...hosts.size > 0 ? { allow: { hosts: [...hosts] } } : {}
78
+ };
79
+ };
80
+ /** The module a bundle starts from: each definition file imported, their definitions merged (`mergeFunctions`). */
81
+ var ENTRY = "\0functions-entry";
82
+ var entryModule = (files) => [
83
+ ...files.map((file, index) => `import * as file${String(index)} from './${file}';`),
84
+ `const merge = ${mergeFunctions.toString()};`,
85
+ `export default merge([${files.map((file, index) => `[${JSON.stringify(file)}, file${String(index)}.default]`).join(", ")}]);`
86
+ ].join("\n");
17
87
  /** The most a bundle may weigh: well under the smallest provider a runner may be (Workers take 3 MB compressed). */
18
88
  var MAX_FUNCTIONS_BYTES = 1e6;
19
89
  /** The one package a space's code may import: the contract, which is all it needs of the platform. */
@@ -24,13 +94,15 @@ var CONTRACT_SPECIFIER = "@plitzi/sdk-server/functions";
24
94
  */
25
95
  var CONTRACT_MODULE = [`export const defineFunctions = ${defineFunctions.toString()};`, `export const ActionRefusal = ${ActionRefusal.toString()};`].join("\n");
26
96
  var normalize = (file) => path.posix.normalize(file).replace(/^\.\//, "");
97
+ /** A file the bundle starts from: one at the top of `functions/` whose text exports its definition by default. */
98
+ var isDefinition = (file, text) => isFunctionsDefinitionFile(file) && exportsByDefault(text);
27
99
  var sourceProblems = (source) => {
28
100
  const problems = [];
29
101
  for (const file of Object.keys(source)) if (!isFunctionsSourcePath(file)) problems.push({
30
102
  file,
31
103
  message: "A file is a relative path under functions/, ending in .ts, .js, .mjs or .json"
32
104
  });
33
- if (!("index.ts" in source)) problems.push({ message: `Functions start from ${FUNCTIONS_ENTRY}, which exports the definition by default` });
105
+ if (!Object.entries(source).some(([file, text]) => isDefinition(normalize(file), text))) problems.push({ message: "Functions are the files at the top of functions/, each exporting its definition by default: export default defineFunctions({ tasks: [ … ] })" });
34
106
  return problems;
35
107
  };
36
108
  var loaderOf = (file) => {
@@ -55,6 +127,10 @@ var sourcePlugin = (files) => ({
55
127
  path: CONTRACT_SPECIFIER,
56
128
  namespace: "contract"
57
129
  };
130
+ if (args.kind === "entry-point" && args.path === ENTRY) return {
131
+ path: ENTRY,
132
+ namespace: "entry"
133
+ };
58
134
  if (args.kind !== "entry-point" && !args.path.startsWith(".")) return { errors: [{ text: `"${args.path}" cannot be imported: functions import their own files and ${CONTRACT_SPECIFIER}, nothing else — a package of web APIs is bundled in as one of their files with \`plitzi functions add ${args.path.startsWith("node:") ? "<package>" : args.path}\`` }] };
59
135
  const base = args.kind === "entry-point" ? "." : path.posix.dirname(args.importer);
60
136
  const wanted = normalize(path.posix.join(base, args.path));
@@ -77,6 +153,14 @@ var sourcePlugin = (files) => ({
77
153
  contents: CONTRACT_MODULE,
78
154
  loader: "js"
79
155
  }));
156
+ build.onLoad({
157
+ filter: /.*/,
158
+ namespace: "entry"
159
+ }, () => ({
160
+ contents: entryModule([...files].filter(([file, text]) => isDefinition(file, text)).map(([file]) => file).sort()),
161
+ loader: "js",
162
+ resolveDir: "."
163
+ }));
80
164
  build.onLoad({
81
165
  filter: /.*/,
82
166
  namespace: "functions"
@@ -107,7 +191,7 @@ var buildFunctions = async (source) => {
107
191
  let result;
108
192
  try {
109
193
  result = await esbuild.build({
110
- entryPoints: [FUNCTIONS_ENTRY],
194
+ entryPoints: [ENTRY],
111
195
  bundle: true,
112
196
  write: false,
113
197
  format: "esm",
@@ -129,4 +213,4 @@ var buildFunctions = async (source) => {
129
213
  };
130
214
  };
131
215
  //#endregion
132
- export { FUNCTIONS_ENTRY, FunctionsBuildError, MAX_FUNCTIONS_BYTES, buildFunctions };
216
+ export { FunctionsBuildError, MAX_FUNCTIONS_BYTES, buildFunctions, mergeFunctions };