@halonicjs/testing 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/NOTICE +4 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  4. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  5. package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
  6. package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
  7. package/dist/adapters/http-kit/src/index.d.ts +3 -0
  8. package/dist/adapters/http-kit/src/index.js +2 -0
  9. package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
  10. package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
  11. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  12. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  13. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  14. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  15. package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
  16. package/dist/adapters/integration-kit/src/declaration.js +4 -3
  17. package/dist/adapters/integration-kit/src/host.d.ts +7 -1
  18. package/dist/adapters/integration-kit/src/host.js +1 -0
  19. package/dist/adapters/integration-kit/src/index.d.ts +5 -2
  20. package/dist/adapters/integration-kit/src/index.js +2 -0
  21. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
  22. package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
  23. package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
  24. package/dist/adapters/integration-kit/src/limited-http.js +53 -10
  25. package/dist/adapters/integration-kit/src/loader.d.ts +28 -11
  26. package/dist/adapters/integration-kit/src/loader.js +36 -21
  27. package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
  28. package/dist/adapters/integration-kit/src/own-request.js +1 -1
  29. package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
  30. package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
  31. package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
  32. package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
  33. package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
  34. package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
  35. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
  36. package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
  37. package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
  38. package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
  39. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  40. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  41. package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
  42. package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
  43. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  44. package/dist/core/events/src/blocked-sites.js +89 -0
  45. package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
  46. package/dist/core/events/src/connector-listing-failed.js +1 -0
  47. package/dist/core/events/src/home-path.d.ts +4 -1
  48. package/dist/core/events/src/home-path.js +14 -3
  49. package/dist/core/events/src/index.d.ts +8 -2
  50. package/dist/core/events/src/index.js +5 -0
  51. package/dist/core/events/src/provider-notes.d.ts +16 -0
  52. package/dist/core/events/src/provider-notes.js +24 -0
  53. package/dist/core/events/src/run-basics.d.ts +131 -10
  54. package/dist/core/events/src/run-event.d.ts +120 -11
  55. package/dist/core/events/src/run-reads.d.ts +25 -0
  56. package/dist/core/events/src/run-reads.js +44 -0
  57. package/dist/core/events/src/run-sends.d.ts +47 -0
  58. package/dist/core/events/src/run-sends.js +68 -0
  59. package/dist/core/events/src/run-summary.d.ts +11 -1
  60. package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
  61. package/dist/core/events/src/sandbox-opened-read.js +27 -2
  62. package/dist/core/events/src/sandbox-opened.d.ts +37 -4
  63. package/dist/core/events/src/sandbox-opened.js +13 -3
  64. package/dist/core/events/src/summarize.js +8 -1
  65. package/dist/core/events/src/timeline-entry.js +1 -0
  66. package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
  67. package/dist/core/events/src/tool-failure-cause.js +66 -0
  68. package/dist/core/format/src/index.d.ts +9 -6
  69. package/dist/core/format/src/index.js +7 -3
  70. package/dist/core/format/src/integration/index.d.ts +3 -2
  71. package/dist/core/format/src/integration/index.js +2 -1
  72. package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
  73. package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
  74. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
  75. package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
  76. package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
  77. package/dist/core/format/src/kinds/agent/schema.js +5 -2
  78. package/dist/core/format/src/kinds/connector/is-local.js +1 -1
  79. package/dist/core/format/src/kinds/connector/kind.js +122 -2
  80. package/dist/core/format/src/kinds/connector/schema.d.ts +38 -0
  81. package/dist/core/format/src/kinds/connector/schema.js +71 -2
  82. package/dist/core/format/src/kinds/deployments/kind.js +25 -1
  83. package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
  84. package/dist/core/format/src/kinds/deployments/schema.js +52 -0
  85. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  86. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  87. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  88. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  89. package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
  90. package/dist/core/format/src/kinds/integration/kind.js +49 -12
  91. package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
  92. package/dist/core/format/src/kinds/integration/policy.js +61 -2
  93. package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
  94. package/dist/core/format/src/kinds/integration/schema.js +133 -7
  95. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +14 -0
  96. package/dist/core/format/src/kinds/integration/sign-in-checks.js +150 -0
  97. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  98. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  99. package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
  100. package/dist/core/format/src/kinds/plugin/checks.js +24 -6
  101. package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
  102. package/dist/core/format/src/kinds/plugin/schema.js +26 -6
  103. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
  104. package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
  105. package/dist/core/format/src/kinds/provider/kind.js +40 -1
  106. package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
  107. package/dist/core/format/src/kinds/provider/types.js +22 -0
  108. package/dist/core/format/src/kinds/routine/kind.js +38 -1
  109. package/dist/core/format/src/kinds/routine/schema.d.ts +20 -5
  110. package/dist/core/format/src/kinds/routine/schema.js +42 -14
  111. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  112. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  113. package/dist/core/format/src/kinds/workflow/schema.js +1 -1
  114. package/dist/core/format/src/kinds/workspace/kind.js +1 -1
  115. package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
  116. package/dist/core/format/src/kinds/workspace/schema.js +6 -5
  117. package/dist/core/format/src/parse-file.js +3 -1
  118. package/dist/core/format/src/shared/fields.d.ts +12 -8
  119. package/dist/core/format/src/shared/fields.js +48 -19
  120. package/dist/core/format/src/shared/guard.d.ts +8 -0
  121. package/dist/core/format/src/shared/guard.js +50 -1
  122. package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
  123. package/dist/core/format/src/shared/missing-keys.js +110 -0
  124. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  125. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  126. package/dist/core/ports/src/blob-store.d.ts +12 -0
  127. package/dist/core/ports/src/blob-store.js +22 -0
  128. package/dist/core/ports/src/chat.d.ts +8 -0
  129. package/dist/core/ports/src/connector-client.d.ts +48 -4
  130. package/dist/core/ports/src/connector-client.js +17 -0
  131. package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
  132. package/dist/core/ports/src/connector-start-failure.js +32 -0
  133. package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
  134. package/dist/core/ports/src/connector-tool-error.js +40 -0
  135. package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
  136. package/dist/core/ports/src/definition-store-left-out.js +47 -0
  137. package/dist/core/ports/src/definition-store.d.ts +36 -5
  138. package/dist/core/ports/src/definition-store.js +1 -1
  139. package/dist/core/ports/src/deploy-target.d.ts +358 -0
  140. package/dist/core/ports/src/deploy-target.js +2 -0
  141. package/dist/core/ports/src/harness-bridge-server.d.ts +67 -7
  142. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  143. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  144. package/dist/core/ports/src/harness.d.ts +79 -15
  145. package/dist/core/ports/src/harness.js +1 -1
  146. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  147. package/dist/core/ports/src/host-settings-store.js +106 -0
  148. package/dist/core/ports/src/host-too-old.d.ts +23 -0
  149. package/dist/core/ports/src/host-too-old.js +27 -0
  150. package/dist/core/ports/src/index.d.ts +32 -13
  151. package/dist/core/ports/src/index.js +28 -8
  152. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  153. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  154. package/dist/core/ports/src/integration.d.ts +71 -7
  155. package/dist/core/ports/src/integration.js +22 -4
  156. package/dist/core/ports/src/llm-provider.d.ts +39 -6
  157. package/dist/core/ports/src/llm-provider.js +46 -3
  158. package/dist/core/ports/src/pairing-codes.d.ts +111 -0
  159. package/dist/core/ports/src/pairing-codes.js +336 -0
  160. package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
  161. package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
  162. package/dist/core/ports/src/password-hasher.d.ts +36 -20
  163. package/dist/core/ports/src/port-versions.d.ts +13 -6
  164. package/dist/core/ports/src/port-versions.js +14 -0
  165. package/dist/core/ports/src/program-probe.d.ts +25 -2
  166. package/dist/core/ports/src/program-probe.js +1 -1
  167. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  168. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  169. package/dist/core/ports/src/record-store.d.ts +17 -0
  170. package/dist/core/ports/src/record-store.js +70 -0
  171. package/dist/core/ports/src/remote-control.d.ts +159 -0
  172. package/dist/core/ports/src/remote-control.js +26 -0
  173. package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
  174. package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
  175. package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
  176. package/dist/core/ports/src/remote-gateway-session.js +241 -0
  177. package/dist/core/ports/src/run-executor.d.ts +44 -7
  178. package/dist/core/ports/src/run-executor.js +1 -1
  179. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  180. package/dist/core/ports/src/run-target-not-found.js +41 -0
  181. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  182. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  183. package/dist/core/ports/src/sandbox.d.ts +149 -13
  184. package/dist/core/ports/src/sandbox.js +52 -2
  185. package/dist/core/ports/src/secrets.d.ts +105 -1
  186. package/dist/core/ports/src/secrets.js +75 -2
  187. package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
  188. package/dist/core/ports/src/tool-approval-store.js +59 -0
  189. package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
  190. package/dist/core/ports/src/tunnel-provider.js +65 -0
  191. package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
  192. package/dist/core/ports/src/tunnel-resolver.js +36 -0
  193. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  194. package/dist/core/ports/src/vcs-status.js +90 -0
  195. package/dist/core/ports/src/vcs.d.ts +30 -0
  196. package/dist/core/schema-kit/src/builders.d.ts +5 -0
  197. package/dist/core/schema-kit/src/builders.js +5 -0
  198. package/dist/core/std/src/amount.d.ts +13 -0
  199. package/dist/core/std/src/amount.js +22 -0
  200. package/dist/core/std/src/hidden-characters.d.ts +28 -0
  201. package/dist/core/std/src/hidden-characters.js +72 -0
  202. package/dist/core/std/src/index.d.ts +7 -0
  203. package/dist/core/std/src/index.js +7 -0
  204. package/dist/core/std/src/path-overlap.d.ts +22 -0
  205. package/dist/core/std/src/path-overlap.js +57 -0
  206. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  207. package/dist/core/std/src/public-suffixes.generated.js +10428 -0
  208. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  209. package/dist/core/std/src/registrable-domain.js +62 -0
  210. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  211. package/dist/core/std/src/secret-variable-name.js +34 -0
  212. package/dist/core/std/src/site-name.d.ts +35 -0
  213. package/dist/core/std/src/site-name.js +111 -0
  214. package/dist/core/std/src/url-host.d.ts +35 -0
  215. package/dist/core/std/src/url-host.js +170 -0
  216. package/dist/core/std/src/word-diff.d.ts +28 -0
  217. package/dist/core/std/src/word-diff.js +77 -0
  218. package/dist/core/yaml/src/edit-data.d.ts +7 -0
  219. package/dist/core/yaml/src/edit-data.js +62 -3
  220. package/dist/core/yaml/src/edit.d.ts +7 -0
  221. package/dist/core/yaml/src/edit.js +34 -3
  222. package/dist/core/yaml/src/splice-node.d.ts +6 -0
  223. package/dist/core/yaml/src/splice-node.js +10 -0
  224. package/dist/core/yaml/src/splice.js +20 -10
  225. package/dist/testing/integration/src/checks.d.ts +5 -3
  226. package/dist/testing/integration/src/checks.js +31 -3
  227. package/dist/testing/integration/src/load.js +3 -1
  228. package/package.json +9 -2
@@ -1,3 +1,4 @@
1
+ import { checkPlacementHosts, checkPlacements, isSecretPlacement, isSignInPlacement, place, } from "./auth-placement.js";
1
2
  import { IntegrationRefusedError, IntegrationTimeoutError } from "@halonicjs/adapters/integration-kit";
2
3
  import { copyRequest } from "./own-request.js";
3
4
  import { allowedUrl } from "./policy.js";
@@ -5,7 +6,8 @@ import { bodyBytes, checkBody, requestBodyLimit, requestTooLarge, toForm, } from
5
6
  import { guardBody, untilAborted } from "./response-body.js";
6
7
  import { removeSecretsFromError, secretForms } from "./secret-filter.js";
7
8
  import { carriedForms, readDeclaredSecrets, refuseCarriedSecrets, refuseRedirectCarryingSecrets, SecretInRequestError, } from "./secret-in-request.js";
8
- import { checkPlacementHosts, checkPlacements, place, readSecrets } from "./secret-placement.js";
9
+ import { readSecrets } from "./secret-placement.js";
10
+ import { readTokens, reportRejected } from "./sign-in-placement.js";
9
11
  const redirectStatuses = new Set([301, 302, 303, 307, 308]);
10
12
  /** Headers a browser drops when a redirect leaves the origin; the kit does the same. */
11
13
  const originBoundHeaders = ["authorization", "cookie", "proxy-authorization"];
@@ -33,7 +35,7 @@ export function createLimitedHttpClient(options) {
33
35
  // Needs no secret, so a placement the sheet doesn't allow is refused before any is read.
34
36
  checkPlacements(options.policy, own.placements);
35
37
  const declared = await readDeclaredSecrets(options.policy, options.secrets);
36
- const carried = carriedForms(declared.values());
38
+ const carried = carriedForms([...declared.values(), ...signInValues(options)]);
37
39
  refuseCarriedSecrets(options.policy, carried, {
38
40
  method: own.givenMethod,
39
41
  sentMethod: own.method,
@@ -65,6 +67,10 @@ export function createLimitedHttpClient(options) {
65
67
  },
66
68
  };
67
69
  }
70
+ /** Every value the sign-ins' tokens say the filter must remove: tokens not yet expired, refresh tokens, client secrets. */
71
+ function signInValues(options) {
72
+ return options.signInTokens?.filterValues() ?? [];
73
+ }
68
74
  /** What the log shows of a request that failed before the secret check passed. */
69
75
  const unchecked = { method: "", host: "", path: "" };
70
76
  async function send(options, own, { declared, carried }) {
@@ -96,13 +102,18 @@ async function send(options, own, { declared, carried }) {
96
102
  onIdle: () => timers.stop("no data", limits.idleTimeoutMs ?? 60_000),
97
103
  done: () => clearTimeout(timers.total),
98
104
  // Every declared secret, not only the placed ones: the bridge filters the same way.
99
- secrets: secretForms([...declared].map(([secret, value]) => ({
100
- value,
101
- placements: placements.filter((placement) => placement.secret === secret),
102
- }))),
105
+ secrets: filterForms(options, placements, declared, new Map()),
103
106
  };
104
107
  try {
105
- return await followHops(options, { hop, values, carried, guard, maxBodyBytes, timers });
108
+ return await followHops(options, {
109
+ hop,
110
+ values,
111
+ declared,
112
+ carried,
113
+ guard,
114
+ maxBodyBytes,
115
+ timers,
116
+ });
106
117
  }
107
118
  catch (error) {
108
119
  clearTimeout(timers.headers);
@@ -123,14 +134,43 @@ function startTimers(policy, hop, limits, signal) {
123
134
  stop,
124
135
  };
125
136
  }
137
+ /**
138
+ * Every form of the values that must not reach the integration or leave in
139
+ * its own requests: the declared secrets (with where this request places
140
+ * them), the sign-ins' filter values, and the tokens this hop places.
141
+ */
142
+ function filterForms(options, placements, declared, tokens) {
143
+ const placedAs = (name, isPlaced) => placements.filter((placement) => isPlaced(placement) && placementName(placement) === name);
144
+ return secretForms([
145
+ ...[...declared].map(([secret, value]) => ({
146
+ value,
147
+ placements: placedAs(secret, isSecretPlacement),
148
+ })),
149
+ ...signInValues(options).map((value) => ({ value })),
150
+ ...[...tokens].map(([signIn, value]) => ({
151
+ value,
152
+ placements: placedAs(signIn, isSignInPlacement),
153
+ })),
154
+ ]);
155
+ }
156
+ /** The name of the secret or sign-in a placement is for. */
157
+ function placementName(placement) {
158
+ return isSecretPlacement(placement) ? placement.secret : placement.signIn;
159
+ }
126
160
  /** Sends the request, then each redirect hop, until an answer that isn't one. */
127
161
  async function followHops(options, context) {
128
162
  const { policy, limits = {} } = options;
129
- const { hop, values, carried, guard, maxBodyBytes, timers } = context;
163
+ const { hop, values, declared, guard, maxBodyBytes, timers } = context;
130
164
  const maxRedirects = limits.maxRedirects ?? 5;
131
165
  for (let count = 0;; count++) {
166
+ const tokens = await readTokens(policy, options.signInTokens, hop.placements.filter(isSignInPlacement), hop.url, timers.combined);
167
+ if (hop.placements.some(isSignInPlacement)) {
168
+ // A refresh may have issued a token the filter didn't know when the request started.
169
+ guard.secrets = filterForms(options, hop.placements, declared, tokens);
170
+ context.carried = carriedForms([...declared.values(), ...signInValues(options)]);
171
+ }
132
172
  const headers = new Headers(hop.headers);
133
- const placedForm = place(policy, hop.placements, values, hop.url, headers, hop.form);
173
+ const placedForm = place(policy, hop.placements, { secrets: values, tokens }, hop.url, headers, hop.form);
134
174
  const body = placedForm ?? hop.body;
135
175
  if (bodyBytes(body) > maxBodyBytes)
136
176
  throw requestTooLarge(policy, hop.url, maxBodyBytes);
@@ -141,6 +181,9 @@ async function followHops(options, context) {
141
181
  redirect: "manual",
142
182
  signal: timers.combined,
143
183
  }), timers.combined);
184
+ // Only for a token this hop placed: a 401 from any other hop says nothing about it.
185
+ if (response.status === 401)
186
+ reportRejected(options.signInTokens, tokens);
144
187
  const location = response.headers.get("location");
145
188
  if (!redirectStatuses.has(response.status) || location === null) {
146
189
  clearTimeout(timers.headers);
@@ -150,7 +193,7 @@ async function followHops(options, context) {
150
193
  if (count >= maxRedirects) {
151
194
  throw new IntegrationRefusedError("too-many-redirects", `${policy.name}: ${hop.url.host}${hop.url.pathname} redirected more than ${maxRedirects} times`);
152
195
  }
153
- refuseRedirectCarryingSecrets(policy, carried, location, hop.url);
196
+ refuseRedirectCarryingSecrets(policy, context.carried, location, hop.url);
154
197
  follow(hop, response.status, allowedUrl(policy, location, hop.url));
155
198
  }
156
199
  }
@@ -1,9 +1,12 @@
1
+ import type { AddressCheckingHttpClient } from "../../http-kit/src/index.js";
1
2
  import { type IntegrationSheet } from "../../../core/format/src/integration/index.js";
2
- import { type HttpClient, type Integration, type IntegrationHost, type ProviderConfig, type Secrets, type TokenStore } from "../../../core/ports/src/index.js";
3
+ import type { Integration, IntegrationHost, ProviderConfig, Secrets, SignInTokens, TokenStore } from "../../../core/ports/src/index.js";
3
4
  import { type Result } from "../../../core/std/src/index.js";
5
+ import { type CurrentSecretForms } from "./current-secret-forms.js";
4
6
  import type { LoadProblem } from "./load-problem.js";
5
7
  import type { RequestLog } from "./request-log.js";
6
8
  import type { SecretOnWire } from "./secret-filter.js";
9
+ import { type WorkspaceChoices } from "./workspace-choices.js";
7
10
  /** An integration and its permission sheet, as they were found. */
8
11
  export interface IntegrationSource {
9
12
  /**
@@ -20,25 +23,32 @@ export interface IntegrationSource {
20
23
  * step. The loader refuses it when the sheet has changed since.
21
24
  */
22
25
  readonly approvedSheet?: unknown;
23
- }
24
- /** What the workspace chose for one integration. */
25
- export interface WorkspaceChoices {
26
- /** Its settings, such as the URL a `{ fromSetting }` host reads. Never a secret value. */
27
- readonly settings?: Readonly<Record<string, unknown>>;
28
26
  /**
29
- * For each secret in the sheet, the workspace secret the user picked for
30
- * it. A secret left out isn't configured: an optional one is left off the
31
- * request, any other is refused when a request needs it.
27
+ * `true` for a plugin's backend, whose sheet's id is the plugin's. The
28
+ * secrets it picks are then read as that plugin's own, `plugin__<id>__<name>`,
29
+ * and only those, never as a workspace's picks, which can't name a plugin's.
30
+ * The names come from the plugin's manifest, never from a workspace.
32
31
  */
33
- readonly secretNames?: Readonly<Record<string, string>>;
32
+ readonly plugin?: boolean;
34
33
  }
35
34
  /** What {@link loadIntegration} needs: the integration and the raw ports, which the integration never sees. */
36
35
  export interface LoadIntegrationOptions {
37
36
  readonly source: IntegrationSource;
38
37
  readonly choices?: WorkspaceChoices;
39
- readonly transport: HttpClient;
38
+ /**
39
+ * What sends the requests. The sheet names hosts only, so it must check
40
+ * the addresses a name resolves to itself: the Node one from
41
+ * `createNodeHttpClient`, never a plain `fetch` wrapper.
42
+ */
43
+ readonly transport: AddressCheckingHttpClient;
40
44
  readonly secrets: Secrets;
41
45
  readonly tokens: TokenStore;
46
+ /**
47
+ * The access tokens of the sheet's sign-ins, from the host's
48
+ * `createIntegrationSignIns`. Without it a request that places a sign-in's
49
+ * token is refused as `sign-in-needed`. The integration never sees it.
50
+ */
51
+ readonly signInTokens?: SignInTokens;
42
52
  /** What this runtime offers beyond HTTP, for the sheet's `needs`, such as `process`. Default none. */
43
53
  readonly capabilities?: readonly string[];
44
54
  readonly now?: () => number;
@@ -68,6 +78,13 @@ export interface PreparedIntegration extends Omit<LoadedIntegration, "integratio
68
78
  * filtered too. Only Halonic's side ever calls it.
69
79
  */
70
80
  readonly readSecrets: () => Promise<SecretOnWire[]>;
81
+ /**
82
+ * What the runner bridge filters with: the picked secrets read now, and
83
+ * every value the sign-in tokens list, read again each time the filter is
84
+ * used, so a token a refresh issues later is removed too. Call it for each
85
+ * runner start, like {@link PreparedIntegration.readSecrets}.
86
+ */
87
+ readonly currentSecretForms: () => Promise<CurrentSecretForms>;
71
88
  }
72
89
  /**
73
90
  * Checks an integration against its permission sheet and builds its host. The
@@ -1,8 +1,10 @@
1
- import { integrationPolicy, parseIntegrationSheet, } from "../../../core/format/src/integration/index.js";
2
- import { workspaceSecrets, } from "../../../core/ports/src/index.js";
1
+ import { integrationPolicy, isPlacedSecret, parseIntegrationSheet, } from "../../../core/format/src/integration/index.js";
3
2
  import { deepEqual, err, ok } from "../../../core/std/src/index.js";
3
+ import { currentSecretForms } from "./current-secret-forms.js";
4
4
  import { declarationProblems } from "./declaration.js";
5
5
  import { createIntegrationHost } from "./host.js";
6
+ import { checkSecretLength } from "./secret-placement.js";
7
+ import { choiceSettings, chosenSecrets } from "./workspace-choices.js";
6
8
  /**
7
9
  * Checks an integration against its permission sheet and builds its host. The
8
10
  * sheet must pass its schema, the code must be exactly what the sheet
@@ -20,7 +22,7 @@ export function loadIntegration(options) {
20
22
  if (!prepared.ok) {
21
23
  return prepared;
22
24
  }
23
- const { readSecrets: _readSecrets, ...loaded } = prepared.value;
25
+ const { readSecrets: _readSecrets, currentSecretForms: _forms, ...loaded } = prepared.value;
24
26
  return ok({ ...loaded, integration });
25
27
  }
26
28
  /**
@@ -43,11 +45,12 @@ function prepare(options, codeProblems) {
43
45
  return err(parsed.error);
44
46
  }
45
47
  const sheet = parsed.value;
46
- const settings = options.choices?.settings ?? {};
48
+ const settings = choiceSettings(options.choices);
47
49
  const secretNames = options.choices?.secretNames ?? {};
48
50
  const problems = [
49
51
  ...approvalProblems(source, sheet),
50
52
  ...localTokenProblems(source, sheet),
53
+ ...localSignInProblems(source, sheet),
51
54
  ...codeProblems(sheet),
52
55
  ...needProblems(sheet, options.capabilities ?? []),
53
56
  ...secretChoiceProblems(sheet, secretNames),
@@ -59,18 +62,20 @@ function prepare(options, codeProblems) {
59
62
  if (problems.length > 0 || !resolved.ok) {
60
63
  return err(problems);
61
64
  }
62
- const secrets = chosenSecrets(options.secrets, secretNames);
65
+ const secrets = chosenSecrets(options.secrets, options.choices, source.plugin ? sheet.id : undefined);
63
66
  const { host, log } = createIntegrationHost({
64
67
  policy: resolved.value.policy,
65
68
  transport: options.transport,
66
69
  secrets,
67
70
  tokens: options.tokens,
71
+ ...(options.signInTokens ? { signInTokens: options.signInTokens } : {}),
68
72
  settings,
69
73
  ...(resolved.value.limits ? { limits: requestLimits(resolved.value.limits) } : {}),
70
74
  ...(options.now ? { now: options.now } : {}),
71
75
  });
72
76
  const readSecrets = () => secretsOnWire(sheet, secrets);
73
- return ok({ origin: source.origin, sheet, host, log, readSecrets });
77
+ const forms = async () => currentSecretForms(await readSecrets(), options.signInTokens);
78
+ return ok({ origin: source.origin, sheet, host, log, readSecrets, currentSecretForms: forms });
74
79
  }
75
80
  /**
76
81
  * Maps a workspace's provider entry onto the sheet, so the integration can
@@ -152,6 +157,23 @@ function localTokenProblems(source, sheet) {
152
157
  },
153
158
  ];
154
159
  }
160
+ /**
161
+ * A local integration can't declare `signIns` until the trust content shows
162
+ * them: the client secret leaves `secrets`, and the token, revoke and
163
+ * authorize hosts needn't be in `hosts`, so the person approving would never
164
+ * see where the code and the client secret go.
165
+ */
166
+ function localSignInProblems(source, sheet) {
167
+ if (source.origin !== "local") {
168
+ return [];
169
+ }
170
+ return Object.keys(sheet.signIns).map((name) => ({
171
+ code: "sign-ins-not-allowed",
172
+ path: ["signIns", name],
173
+ message: `${sheet.id}: an integration you build or change can't declare the sign-in ${name} yet`,
174
+ fix: "Remove signIns from its sheet and use an API key, or ask for sign-in support.",
175
+ }));
176
+ }
155
177
  function needProblems(sheet, capabilities) {
156
178
  return sheet.needs.flatMap((need, index) => capabilities.includes(need)
157
179
  ? []
@@ -179,25 +201,18 @@ function requestLimits(limits) {
179
201
  return Object.fromEntries(Object.entries(limits).filter((entry) => entry[1] !== undefined));
180
202
  }
181
203
  /**
182
- * The raw secrets seen through the user's picks: the kit asks by the sheet's
183
- * name and reads the workspace secret picked for it, or nothing. The workspace
184
- * chose those names, so they can't reach Halonic's own secrets or tokens.
204
+ * Each declared secret with a value, and its one placement, as {@link PreparedIntegration.readSecrets} gives them.
205
+ *
206
+ * @throws {IntegrationRefusedError} `secret-too-short` for a value the filter can't safely remove
185
207
  */
186
- function chosenSecrets(raw, secretNames) {
187
- const picks = new Map(Object.entries(secretNames));
188
- const workspace = workspaceSecrets(raw);
189
- return {
190
- get: async (name) => {
191
- const picked = picks.get(name);
192
- return picked === undefined ? null : await workspace.get(picked);
193
- },
194
- };
195
- }
196
- /** Each declared secret with a value, and its one placement, as {@link PreparedIntegration.readSecrets} gives them. */
197
208
  async function secretsOnWire(sheet, secrets) {
198
209
  const read = Object.entries(sheet.secrets).map(async ([name, declared]) => {
199
210
  const value = await secrets.get(name);
200
- return value === null ? [] : [{ value, placements: [placementOf(name, declared)] }];
211
+ if (value === null)
212
+ return [];
213
+ checkSecretLength(sheet.id, name, value);
214
+ // A client secret is never placed by the integration, but a server could still echo it.
215
+ return [{ value, placements: isPlacedSecret(declared) ? [placementOf(name, declared)] : [] }];
201
216
  });
202
217
  return (await Promise.all(read)).flat();
203
218
  }
@@ -1,4 +1,4 @@
1
- import type { IntegrationRequestInit, SecretPlacement } from "../../../core/ports/src/index.js";
1
+ import type { AuthPlacement, IntegrationRequestInit } from "../../../core/ports/src/index.js";
2
2
  import type { IntegrationPolicy } from "./policy.js";
3
3
  import type { Body } from "./request-body.js";
4
4
  /**
@@ -19,7 +19,7 @@ export interface OwnRequest {
19
19
  readonly headers: Headers;
20
20
  /** The body, with its bytes or form copied. A kind the kit doesn't support stays as given. */
21
21
  readonly body: Body;
22
- readonly placements: readonly SecretPlacement[];
22
+ readonly placements: readonly AuthPlacement[];
23
23
  readonly signal: AbortSignal | undefined;
24
24
  }
25
25
  /**
@@ -1,4 +1,4 @@
1
- import { copyPlacements } from "./secret-placement.js";
1
+ import { copyPlacements } from "./auth-placement.js";
2
2
  /**
3
3
  * Copies the request before the kit's first `await`, reading each option
4
4
  * once. The code keeps its own objects and could change them, or give a
@@ -2,9 +2,9 @@ import { type Plugin } from "../../../core/format/src/integration/index.js";
2
2
  import { type Integration } from "../../../core/ports/src/index.js";
3
3
  import type { LoadProblem } from "./load-problem.js";
4
4
  /**
5
- * Why a plugin that passed its own checks can't load: an `sdk` other than
6
- * this Halonic's `integrationVersion`, and, when the backend's code is
7
- * given, every way it differs from the backend, with the same rules as for
5
+ * Why a plugin that passed its own checks can't load: an `sdk` newer than
6
+ * this Halonic's `integrationVersion`, and, when the backend's code is given,
7
+ * every way it differs from the backend, with the same rules as for
8
8
  * an integration and its sheet (`declarationProblems`) and each path
9
9
  * pointing into `plugin.yaml`. Empty when the plugin can load.
10
10
  *
@@ -6,9 +6,9 @@ import { backendSheet } from "../../../core/format/src/integration/index.js";
6
6
  import { integrationVersion } from "../../../core/ports/src/index.js";
7
7
  import { declarationProblems } from "./declaration.js";
8
8
  /**
9
- * Why a plugin that passed its own checks can't load: an `sdk` other than
10
- * this Halonic's `integrationVersion`, and, when the backend's code is
11
- * given, every way it differs from the backend, with the same rules as for
9
+ * Why a plugin that passed its own checks can't load: an `sdk` newer than
10
+ * this Halonic's `integrationVersion`, and, when the backend's code is given,
11
+ * every way it differs from the backend, with the same rules as for
12
12
  * an integration and its sheet (`declarationProblems`) and each path
13
13
  * pointing into `plugin.yaml`. Empty when the plugin can load.
14
14
  *
@@ -17,11 +17,11 @@ import { declarationProblems } from "./declaration.js";
17
17
  */
18
18
  export function pluginLoadProblems(plugin, backendCode) {
19
19
  const problems = [];
20
- if (plugin.sdk !== integrationVersion) {
20
+ if (plugin.sdk > integrationVersion) {
21
21
  problems.push({
22
22
  code: "sdk-version",
23
23
  path: ["sdk"],
24
- message: `${plugin.id}: built against SDK ${plugin.sdk}, but this Halonic offers SDK ${integrationVersion}`,
24
+ message: `${plugin.id}: this plugin needs a newer version of Halonic (it is built against SDK ${plugin.sdk}, and this Halonic offers SDK ${integrationVersion})`,
25
25
  });
26
26
  }
27
27
  if (backendCode !== undefined) {
@@ -23,6 +23,12 @@ export interface IntegrationPolicy {
23
23
  * it up, instead of refusing the request.
24
24
  */
25
25
  readonly secrets: Readonly<Record<string, DeclaredSecret>>;
26
+ /**
27
+ * Each sign-in, the hosts its access token may go to, and where the sheet
28
+ * puts it. Halonic's own code runs the sign-in; the integration can only
29
+ * ask the kit to place the access token.
30
+ */
31
+ readonly signIns: Readonly<Record<string, DeclaredSignIn>>;
26
32
  /** The token names it may read and write. */
27
33
  readonly tokens: readonly string[];
28
34
  }
@@ -33,6 +39,28 @@ export interface DeclaredSecret {
33
39
  /** The only way the kit may place it; any other placement is refused. */
34
40
  readonly placement: DeclaredPlacement;
35
41
  }
42
+ /** One sign-in in the permission sheet. */
43
+ export type DeclaredSignIn = DeclaredSignInPlacement & {
44
+ /** The hosts the access token may go to. */
45
+ readonly hosts: readonly string[];
46
+ /**
47
+ * The sign-in's client secret, when it has one. The integration can't
48
+ * place it: only Halonic's sign-in code sends it, to the token and revoke
49
+ * hosts.
50
+ */
51
+ readonly clientSecret?: {
52
+ readonly name: string;
53
+ readonly hosts: readonly string[];
54
+ };
55
+ };
56
+ /** Where the sheet puts a sign-in's access token. There is no `form`. */
57
+ export type DeclaredSignInPlacement = {
58
+ readonly as: "bearer";
59
+ } | {
60
+ readonly as: "header";
61
+ readonly header: string;
62
+ readonly prefix?: string;
63
+ };
36
64
  /** Where the sheet puts a secret: a `SecretPlacement` without the secret's name. */
37
65
  export type DeclaredPlacement = {
38
66
  readonly as: "bearer";
@@ -10,8 +10,12 @@ export interface BodyGuard {
10
10
  readonly onIdle: () => void;
11
11
  /** Called once when the body is finished, failed or cancelled. */
12
12
  readonly done: () => void;
13
- /** The secrets of this request, removed from the status text, the headers, the URL, the body and its errors. */
14
- readonly secrets: SecretForms;
13
+ /**
14
+ * The secrets and tokens of this request, removed from the status text, the
15
+ * headers, the URL, the body and its errors. The kit replaces it when a hop
16
+ * brings in a token that wasn't known before.
17
+ */
18
+ secrets: SecretForms;
15
19
  }
16
20
  /**
17
21
  * Passes the body through with the request's secrets removed, failing it when it grows over the size limit, when no data comes
@@ -1,12 +1,12 @@
1
- import type { SecretPlacement } from "../../../core/ports/src/index.js";
1
+ import type { AuthPlacement } from "../../../core/ports/src/index.js";
2
2
  import { secretRemoved } from "../../../core/std/src/index.js";
3
3
  /** What a secret value is replaced with wherever the filter finds it. */
4
4
  export { secretRemoved };
5
- /** A secret value, and where the kit placed it, if it did. */
5
+ /** A secret or token value, and where the kit placed it, if it did. */
6
6
  export interface SecretOnWire {
7
7
  readonly value: string;
8
8
  /** How the kit put it in a request, so the placed forms are matched whole. */
9
- readonly placements?: readonly SecretPlacement[];
9
+ readonly placements?: readonly AuthPlacement[];
10
10
  }
11
11
  /**
12
12
  * Every form of a set of secrets the filter looks for, longest first. Build
@@ -48,10 +48,25 @@ function placed(placement, value) {
48
48
  * removeSecrets(String(error), forms)
49
49
  */
50
50
  export function removeSecrets(text, forms) {
51
- let filtered = text;
52
- for (const form of forms.texts)
53
- filtered = filtered.replaceAll(form, secretRemoved);
54
- return filtered;
51
+ if (forms.longest === 0)
52
+ return text;
53
+ // One pass over the text, the longest form first at each place, as
54
+ // SecretRemover does for bodies: a marker already written is never
55
+ // searched again, so a secret found inside it can't break it up.
56
+ let filtered = "";
57
+ let kept = 0;
58
+ let at = 0;
59
+ while (at < text.length) {
60
+ const form = forms.texts.find((candidate) => text.startsWith(candidate, at));
61
+ if (form === undefined) {
62
+ at++;
63
+ continue;
64
+ }
65
+ filtered += text.slice(kept, at) + secretRemoved;
66
+ at += form.length;
67
+ kept = at;
68
+ }
69
+ return filtered + text.slice(kept);
55
70
  }
56
71
  /**
57
72
  * The error with every form of the secrets removed from its message, its
@@ -7,6 +7,9 @@ import { type SecretForms } from "./secret-filter.js";
7
7
  * The values of every secret the integration declares and the workspace
8
8
  * has set up, whether this request places them or not. The kit refuses a
9
9
  * request that carries one of them anywhere it didn't put it.
10
+ *
11
+ * @throws {IntegrationRefusedError} `secret-too-short` when a value is under the minimum length:
12
+ * the filter would remove ordinary text for it and show where the value sits
10
13
  */
11
14
  export declare function readDeclaredSecrets(policy: IntegrationPolicy, secrets: Secrets): Promise<Map<string, string>>;
12
15
  /** The parts of a request the integration wrote, before the kit places any secret. */
@@ -1,16 +1,22 @@
1
1
  import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
2
  import { removeSecrets, SecretRemover, secretForms, secretRemoved, } from "./secret-filter.js";
3
+ import { checkSecretLength } from "./secret-placement.js";
3
4
  /**
4
5
  * The values of every secret the integration declares and the workspace
5
6
  * has set up, whether this request places them or not. The kit refuses a
6
7
  * request that carries one of them anywhere it didn't put it.
8
+ *
9
+ * @throws {IntegrationRefusedError} `secret-too-short` when a value is under the minimum length:
10
+ * the filter would remove ordinary text for it and show where the value sits
7
11
  */
8
12
  export async function readDeclaredSecrets(policy, secrets) {
9
13
  const values = new Map();
10
14
  for (const name of Object.keys(policy.secrets)) {
11
15
  const value = await secrets.get(name);
12
- if (value !== null && value !== "")
13
- values.set(name, value);
16
+ if (value === null || value === "")
17
+ continue;
18
+ checkSecretLength(policy.name, name, value);
19
+ values.set(name, value);
14
20
  }
15
21
  return values;
16
22
  }
@@ -1,36 +1,46 @@
1
- import type { SecretPlacement, Secrets } from "../../../core/ports/src/index.js";
2
- import { type IntegrationPolicy } from "./policy.js";
1
+ import type { AuthPlacement, SecretPlacement, Secrets } from "../../../core/ports/src/index.js";
2
+ import { type DeclaredPlacement, type DeclaredSignInPlacement, type IntegrationPolicy } from "./policy.js";
3
+ /** Checks that the secret is declared, isn't a client secret, and is placed as the sheet says. */
4
+ export declare function checkSecretPlacement(policy: IntegrationPolicy, placement: SecretPlacement): void;
5
+ /** Checks that the secret may go to this host, over this scheme. */
6
+ export declare function checkSecretHost(policy: IntegrationPolicy, placement: SecretPlacement, url: URL): void;
3
7
  /**
4
- * Copies the placements the integration's code gave into frozen objects of
5
- * text fields, reading each field once. The kit checks and places only
6
- * these copies: the code keeps its own objects and could change them, or
7
- * give a getter, after the check and before the secret is placed. A field
8
- * that isn't text is refused here, because an object could turn into other
9
- * text each time it is read.
8
+ * Whether the code places the secret the way the sheet says. Otherwise it
9
+ * could put a key in a field the service stores, such as a note title,
10
+ * where the integration could read it back. Header names match ignoring
11
+ * ASCII case, as HTTP does; a missing prefix and `""` send the same bytes;
12
+ * form field names are case-sensitive. The placement comes from the
13
+ * integration's code, so nothing in it is trusted to have the right type.
10
14
  */
11
- export declare function copyPlacements(policy: IntegrationPolicy, placements: readonly unknown[]): readonly SecretPlacement[];
15
+ export declare function matchesSheet(placement: AuthPlacement, sheet: DeclaredPlacement | DeclaredSignInPlacement): boolean;
16
+ /** A placement in words, for a refusal message. It never holds a value. */
17
+ export declare function describe(placement: DeclaredPlacement | DeclaredSignInPlacement | AuthPlacement): string;
12
18
  /**
13
- * Checks every placement against the sheet before a secret value is read.
14
- * Give it the copies from {@link copyPlacements}, never the code's own
15
- * objects. Where the secret may go is for {@link checkPlacementHosts}.
19
+ * Text from the integration's code, cut short and quoted, so it can't break
20
+ * the message. It is cut by characters before quoting, so the cut never
21
+ * falls inside an escape or a surrogate pair.
16
22
  */
17
- export declare function checkPlacements(policy: IntegrationPolicy, placements: readonly SecretPlacement[]): void;
18
- /**
19
- * Checks that every placed secret may go to the request's first host, once
20
- * the URL is parsed. {@link checkPlacements} has already run, so every
21
- * secret is declared.
22
- */
23
- export declare function checkPlacementHosts(policy: IntegrationPolicy, placements: readonly SecretPlacement[], url: URL): void;
23
+ export declare function quoted(text: unknown): string;
24
24
  /**
25
25
  * Reads each secret's value once. The values never leave the kit. An
26
26
  * optional secret without a value gets no entry, so `place` leaves it out.
27
27
  */
28
- export declare function readSecrets(policy: IntegrationPolicy, secrets: Secrets, placements: readonly SecretPlacement[]): Promise<Map<string, string>>;
28
+ export declare function readSecrets(policy: IntegrationPolicy, secrets: Secrets, placements: readonly AuthPlacement[]): Promise<Map<string, string>>;
29
+ /**
30
+ * The fewest UTF-8 bytes a secret value may have. The filter replaces every
31
+ * copy of a value in what the integration sees, so a shorter one would
32
+ * remove ordinary text, and where it was removed would give the value away.
33
+ */
34
+ export declare const minSecretBytes = 8;
35
+ /**
36
+ * @throws {IntegrationRefusedError} `secret-too-short` when `value` has fewer than {@link minSecretBytes} bytes
37
+ */
38
+ export declare function checkSecretLength(integration: string, secret: string, value: string): void;
29
39
  /**
30
- * Puts the secrets allowed for this hop's host into the headers and the form
31
- * body. A placement whose secret may not go to this hop is left out, which
32
- * happens after a redirect to another declared host.
40
+ * Puts one secret into the headers or the form body, when it may go to this
41
+ * hop's host. A secret that may not go to this hop is left out, which happens
42
+ * after a redirect to another declared host.
33
43
  *
34
- * @returns the form body to send, when a placement wrote into it
44
+ * @returns the form body to send, which a `form` placement writes into
35
45
  */
36
- export declare function place(policy: IntegrationPolicy, placements: readonly SecretPlacement[], values: ReadonlyMap<string, string>, url: URL, headers: Headers, form: URLSearchParams | undefined): URLSearchParams | undefined;
46
+ export declare function placeSecret(policy: IntegrationPolicy, placement: SecretPlacement, value: string | undefined, url: URL, headers: Headers, form: URLSearchParams | undefined): URLSearchParams | undefined;