primitive-admin 1.2.0-alpha.14 → 1.2.0-alpha.16

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 (400) hide show
  1. package/README.md +181 -73
  2. package/assets/skill/skills/primitive-platform/SKILL.md +87 -23
  3. package/dist/bin/primitive.js +11 -82
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/admins.js +80 -17
  6. package/dist/src/commands/admins.js.map +1 -1
  7. package/dist/src/commands/agent-sessions.js +2 -0
  8. package/dist/src/commands/agent-sessions.js.map +1 -1
  9. package/dist/src/commands/analytics.js +181 -12
  10. package/dist/src/commands/analytics.js.map +1 -1
  11. package/dist/src/commands/apps-children.js +2 -0
  12. package/dist/src/commands/apps-children.js.map +1 -1
  13. package/dist/src/commands/apps-transitions.d.ts +39 -0
  14. package/dist/src/commands/apps-transitions.js +198 -0
  15. package/dist/src/commands/apps-transitions.js.map +1 -0
  16. package/dist/src/commands/apps.d.ts +11 -0
  17. package/dist/src/commands/apps.js +65 -3
  18. package/dist/src/commands/apps.js.map +1 -1
  19. package/dist/src/commands/auth-sessions.js +2 -0
  20. package/dist/src/commands/auth-sessions.js.map +1 -1
  21. package/dist/src/commands/auth.js +16 -1
  22. package/dist/src/commands/auth.js.map +1 -1
  23. package/dist/src/commands/blob-buckets.js +2 -0
  24. package/dist/src/commands/blob-buckets.js.map +1 -1
  25. package/dist/src/commands/collections.js +2 -0
  26. package/dist/src/commands/collections.js.map +1 -1
  27. package/dist/src/commands/comparisons.js +2 -0
  28. package/dist/src/commands/comparisons.js.map +1 -1
  29. package/dist/src/commands/config.d.ts +1 -1
  30. package/dist/src/commands/config.js +42 -9
  31. package/dist/src/commands/config.js.map +1 -1
  32. package/dist/src/commands/connections.js +2 -0
  33. package/dist/src/commands/connections.js.map +1 -1
  34. package/dist/src/commands/database-type-configs.js +5 -3
  35. package/dist/src/commands/database-type-configs.js.map +1 -1
  36. package/dist/src/commands/databases.js +6 -4
  37. package/dist/src/commands/databases.js.map +1 -1
  38. package/dist/src/commands/db3-types.js +2 -0
  39. package/dist/src/commands/db3-types.js.map +1 -1
  40. package/dist/src/commands/db3.d.ts +12 -0
  41. package/dist/src/commands/db3.js +408 -31
  42. package/dist/src/commands/db3.js.map +1 -1
  43. package/dist/src/commands/documents.d.ts +52 -12
  44. package/dist/src/commands/documents.js +120 -29
  45. package/dist/src/commands/documents.js.map +1 -1
  46. package/dist/src/commands/email-templates.js +74 -0
  47. package/dist/src/commands/email-templates.js.map +1 -1
  48. package/dist/src/commands/env.js +2 -0
  49. package/dist/src/commands/env.js.map +1 -1
  50. package/dist/src/commands/functions.js +90 -11
  51. package/dist/src/commands/functions.js.map +1 -1
  52. package/dist/src/commands/groups.js +20 -3
  53. package/dist/src/commands/groups.js.map +1 -1
  54. package/dist/src/commands/guides.js +2 -0
  55. package/dist/src/commands/guides.js.map +1 -1
  56. package/dist/src/commands/hosting.d.ts +8 -0
  57. package/dist/src/commands/hosting.js +346 -0
  58. package/dist/src/commands/hosting.js.map +1 -0
  59. package/dist/src/commands/init.js +9 -1
  60. package/dist/src/commands/init.js.map +1 -1
  61. package/dist/src/commands/integrations.js +82 -47
  62. package/dist/src/commands/integrations.js.map +1 -1
  63. package/dist/src/commands/locks.js +2 -0
  64. package/dist/src/commands/locks.js.map +1 -1
  65. package/dist/src/commands/metadata-category-configs.js +2 -0
  66. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  67. package/dist/src/commands/metadata.js +41 -0
  68. package/dist/src/commands/metadata.js.map +1 -1
  69. package/dist/src/commands/prompts.js +75 -47
  70. package/dist/src/commands/prompts.js.map +1 -1
  71. package/dist/src/commands/rate-counters.d.ts +19 -0
  72. package/dist/src/commands/rate-counters.js +104 -0
  73. package/dist/src/commands/rate-counters.js.map +1 -0
  74. package/dist/src/commands/rule-sets.js +2 -0
  75. package/dist/src/commands/rule-sets.js.map +1 -1
  76. package/dist/src/commands/schemas.d.ts +15 -0
  77. package/dist/src/commands/schemas.js +122 -0
  78. package/dist/src/commands/schemas.js.map +1 -0
  79. package/dist/src/commands/secrets.js +47 -3
  80. package/dist/src/commands/secrets.js.map +1 -1
  81. package/dist/src/commands/sessions.js +2 -0
  82. package/dist/src/commands/sessions.js.map +1 -1
  83. package/dist/src/commands/skill.js +2 -0
  84. package/dist/src/commands/skill.js.map +1 -1
  85. package/dist/src/commands/sync-schemas.d.ts +202 -0
  86. package/dist/src/commands/sync-schemas.js +629 -0
  87. package/dist/src/commands/sync-schemas.js.map +1 -0
  88. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  89. package/dist/src/commands/sync-user-properties.js +276 -0
  90. package/dist/src/commands/sync-user-properties.js.map +1 -0
  91. package/dist/src/commands/sync.d.ts +344 -14
  92. package/dist/src/commands/sync.js +1834 -345
  93. package/dist/src/commands/sync.js.map +1 -1
  94. package/dist/src/commands/tokens.js +2 -0
  95. package/dist/src/commands/tokens.js.map +1 -1
  96. package/dist/src/commands/transitions.d.ts +54 -0
  97. package/dist/src/commands/transitions.js +418 -0
  98. package/dist/src/commands/transitions.js.map +1 -0
  99. package/dist/src/commands/usage.d.ts +18 -0
  100. package/dist/src/commands/usage.js +343 -0
  101. package/dist/src/commands/usage.js.map +1 -0
  102. package/dist/src/commands/user-properties.d.ts +14 -0
  103. package/dist/src/commands/user-properties.js +79 -0
  104. package/dist/src/commands/user-properties.js.map +1 -0
  105. package/dist/src/commands/users.js +878 -16
  106. package/dist/src/commands/users.js.map +1 -1
  107. package/dist/src/commands/vars.js +2 -0
  108. package/dist/src/commands/vars.js.map +1 -1
  109. package/dist/src/commands/waitlist.js +39 -4
  110. package/dist/src/commands/waitlist.js.map +1 -1
  111. package/dist/src/lib/analytics-query.d.ts +58 -0
  112. package/dist/src/lib/analytics-query.js +134 -0
  113. package/dist/src/lib/analytics-query.js.map +1 -0
  114. package/dist/src/lib/api-client.d.ts +1354 -97
  115. package/dist/src/lib/api-client.js +513 -164
  116. package/dist/src/lib/api-client.js.map +1 -1
  117. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  118. package/dist/src/lib/app-settings-descriptor.js +6 -0
  119. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  120. package/dist/src/lib/auth-flow.d.ts +33 -0
  121. package/dist/src/lib/auth-flow.js +404 -13
  122. package/dist/src/lib/auth-flow.js.map +1 -1
  123. package/dist/src/lib/block-selector.d.ts +9 -15
  124. package/dist/src/lib/block-selector.js +9 -20
  125. package/dist/src/lib/block-selector.js.map +1 -1
  126. package/dist/src/lib/cli-manifest.d.ts +9 -0
  127. package/dist/src/lib/cli-manifest.js +10 -1
  128. package/dist/src/lib/cli-manifest.js.map +1 -1
  129. package/dist/src/lib/cli-version.d.ts +14 -0
  130. package/dist/src/lib/cli-version.js +38 -0
  131. package/dist/src/lib/cli-version.js.map +1 -0
  132. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  133. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  134. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  135. package/dist/src/lib/command-groups.d.ts +30 -0
  136. package/dist/src/lib/command-groups.js +109 -0
  137. package/dist/src/lib/command-groups.js.map +1 -0
  138. package/dist/src/lib/command-status.d.ts +147 -0
  139. package/dist/src/lib/command-status.js +266 -0
  140. package/dist/src/lib/command-status.js.map +1 -0
  141. package/dist/src/lib/config-object-descriptor.d.ts +6 -0
  142. package/dist/src/lib/config-object-descriptor.js +71 -1
  143. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  144. package/dist/src/lib/config-toml.d.ts +11 -2
  145. package/dist/src/lib/config-toml.js +25 -2
  146. package/dist/src/lib/config-toml.js.map +1 -1
  147. package/dist/src/lib/data-input.d.ts +1 -1
  148. package/dist/src/lib/data-input.js +1 -1
  149. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  150. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  151. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  152. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +18 -1
  153. package/dist/src/lib/db-codegen/dbTypeIR.js +14 -5
  154. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  155. package/dist/src/lib/db-type-records.d.ts +106 -0
  156. package/dist/src/lib/db-type-records.js +224 -0
  157. package/dist/src/lib/db-type-records.js.map +1 -0
  158. package/dist/src/lib/db3-export.d.ts +51 -14
  159. package/dist/src/lib/db3-export.js +136 -28
  160. package/dist/src/lib/db3-export.js.map +1 -1
  161. package/dist/src/lib/db3-index-output.d.ts +92 -4
  162. package/dist/src/lib/db3-index-output.js +183 -11
  163. package/dist/src/lib/db3-index-output.js.map +1 -1
  164. package/dist/src/lib/db3-type-models.d.ts +49 -7
  165. package/dist/src/lib/db3-type-models.js +159 -28
  166. package/dist/src/lib/db3-type-models.js.map +1 -1
  167. package/dist/src/lib/deprecation.d.ts +2 -2
  168. package/dist/src/lib/deprecation.js +2 -2
  169. package/dist/src/lib/experimental-apis.d.ts +36 -0
  170. package/dist/src/lib/experimental-apis.js +46 -0
  171. package/dist/src/lib/experimental-apis.js.map +1 -0
  172. package/dist/src/lib/file-attachment.d.ts +24 -0
  173. package/dist/src/lib/file-attachment.js +31 -0
  174. package/dist/src/lib/file-attachment.js.map +1 -0
  175. package/dist/src/lib/function-authorize-check.d.ts +1 -1
  176. package/dist/src/lib/function-authorize-check.js +2 -1
  177. package/dist/src/lib/function-authorize-check.js.map +1 -1
  178. package/dist/src/lib/function-authorize-view.d.ts +12 -0
  179. package/dist/src/lib/function-authorize-view.js +38 -0
  180. package/dist/src/lib/function-authorize-view.js.map +1 -1
  181. package/dist/src/lib/function-bundle.d.ts +27 -5
  182. package/dist/src/lib/function-bundle.js +106 -7
  183. package/dist/src/lib/function-bundle.js.map +1 -1
  184. package/dist/src/lib/function-collect.d.ts +15 -0
  185. package/dist/src/lib/function-collect.js +73 -14
  186. package/dist/src/lib/function-collect.js.map +1 -1
  187. package/dist/src/lib/function-db-types.d.ts +63 -40
  188. package/dist/src/lib/function-db-types.js +289 -293
  189. package/dist/src/lib/function-db-types.js.map +1 -1
  190. package/dist/src/lib/function-document-types.d.ts +19 -7
  191. package/dist/src/lib/function-document-types.js +24 -12
  192. package/dist/src/lib/function-document-types.js.map +1 -1
  193. package/dist/src/lib/function-lint.d.ts +24 -1
  194. package/dist/src/lib/function-lint.js +123 -1
  195. package/dist/src/lib/function-lint.js.map +1 -1
  196. package/dist/src/lib/function-run.d.ts +1 -1
  197. package/dist/src/lib/function-run.js +1 -1
  198. package/dist/src/lib/function-run.js.map +1 -1
  199. package/dist/src/lib/function-schema-codegen.d.ts +85 -21
  200. package/dist/src/lib/function-schema-codegen.js +191 -85
  201. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  202. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  203. package/dist/src/lib/function-schema-refs.js +177 -0
  204. package/dist/src/lib/function-schema-refs.js.map +1 -0
  205. package/dist/src/lib/function-sync.d.ts +38 -4
  206. package/dist/src/lib/function-sync.js +91 -14
  207. package/dist/src/lib/function-sync.js.map +1 -1
  208. package/dist/src/lib/function-typecheck.d.ts +52 -0
  209. package/dist/src/lib/function-typecheck.js +171 -54
  210. package/dist/src/lib/function-typecheck.js.map +1 -1
  211. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  212. package/dist/src/lib/generated-build-flags.js +14 -0
  213. package/dist/src/lib/generated-build-flags.js.map +1 -0
  214. package/dist/src/lib/generated-command-status.d.ts +6 -0
  215. package/dist/src/lib/generated-command-status.js +469 -0
  216. package/dist/src/lib/generated-command-status.js.map +1 -0
  217. package/dist/src/lib/generated-config-surfaces.d.ts +239 -14
  218. package/dist/src/lib/generated-config-surfaces.js +670 -85
  219. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  220. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  221. package/dist/src/lib/generated-sdk-types.js +1 -1
  222. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  223. package/dist/src/lib/hosting-build.d.ts +97 -0
  224. package/dist/src/lib/hosting-build.js +204 -0
  225. package/dist/src/lib/hosting-build.js.map +1 -0
  226. package/dist/src/lib/hosting-client.d.ts +167 -0
  227. package/dist/src/lib/hosting-client.js +340 -0
  228. package/dist/src/lib/hosting-client.js.map +1 -0
  229. package/dist/src/lib/hosting-environments.d.ts +32 -0
  230. package/dist/src/lib/hosting-environments.js +74 -0
  231. package/dist/src/lib/hosting-environments.js.map +1 -0
  232. package/dist/src/lib/hosting-errors.d.ts +30 -0
  233. package/dist/src/lib/hosting-errors.js +43 -0
  234. package/dist/src/lib/hosting-errors.js.map +1 -0
  235. package/dist/src/lib/hosting-token.d.ts +46 -0
  236. package/dist/src/lib/hosting-token.js +60 -0
  237. package/dist/src/lib/hosting-token.js.map +1 -0
  238. package/dist/src/lib/hosting-wait.d.ts +42 -0
  239. package/dist/src/lib/hosting-wait.js +84 -0
  240. package/dist/src/lib/hosting-wait.js.map +1 -0
  241. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  242. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  243. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  244. package/dist/src/lib/integration-test-request.d.ts +54 -0
  245. package/dist/src/lib/integration-test-request.js +207 -0
  246. package/dist/src/lib/integration-test-request.js.map +1 -0
  247. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  248. package/dist/src/lib/invoker-shared-enums.js +98 -0
  249. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  250. package/dist/src/lib/log-inspection.d.ts +4 -1
  251. package/dist/src/lib/log-inspection.js.map +1 -1
  252. package/dist/src/lib/metadata-report.d.ts +85 -0
  253. package/dist/src/lib/metadata-report.js +81 -0
  254. package/dist/src/lib/metadata-report.js.map +1 -0
  255. package/dist/src/lib/output.d.ts +1 -1
  256. package/dist/src/lib/output.js +1 -1
  257. package/dist/src/lib/platform-owned.js +5 -0
  258. package/dist/src/lib/platform-owned.js.map +1 -1
  259. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  260. package/dist/src/lib/primitive-declaration-names.js +22 -0
  261. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  262. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  263. package/dist/src/lib/primitive-declaration.js +792 -0
  264. package/dist/src/lib/primitive-declaration.js.map +1 -0
  265. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  266. package/dist/src/lib/prompt-schema-codegen.js +94 -98
  267. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  268. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  269. package/dist/src/lib/prompt-schema-document.js +92 -0
  270. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  271. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  272. package/dist/src/lib/prompt-schema-refs.js +478 -0
  273. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  274. package/dist/src/lib/records-verbs.d.ts +12 -2
  275. package/dist/src/lib/records-verbs.js +7 -2
  276. package/dist/src/lib/records-verbs.js.map +1 -1
  277. package/dist/src/lib/register-commands.d.ts +36 -0
  278. package/dist/src/lib/register-commands.js +37 -0
  279. package/dist/src/lib/register-commands.js.map +1 -0
  280. package/dist/src/lib/retired-imports.d.ts +53 -0
  281. package/dist/src/lib/retired-imports.js +120 -0
  282. package/dist/src/lib/retired-imports.js.map +1 -0
  283. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  284. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  285. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  286. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  287. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  288. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  289. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  290. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  291. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  292. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
  293. package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
  294. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  295. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  296. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  297. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  298. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  299. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  300. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  301. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
  302. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +154 -1
  303. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -1
  304. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  305. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  306. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  307. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  308. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  309. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  310. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  311. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  312. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  313. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  314. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  315. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  316. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  317. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  318. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  319. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  320. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  321. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  322. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  323. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  324. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  325. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  326. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  327. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  328. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +40 -13
  329. package/dist/src/lib/schema-codegen/schemaToTs.js +124 -160
  330. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
  331. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  332. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  333. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  334. package/dist/src/lib/schema-family-index.d.ts +228 -0
  335. package/dist/src/lib/schema-family-index.js +813 -0
  336. package/dist/src/lib/schema-family-index.js.map +1 -0
  337. package/dist/src/lib/schema-pins.d.ts +82 -0
  338. package/dist/src/lib/schema-pins.js +198 -0
  339. package/dist/src/lib/schema-pins.js.map +1 -0
  340. package/dist/src/lib/schema-preview.d.ts +244 -0
  341. package/dist/src/lib/schema-preview.js +498 -0
  342. package/dist/src/lib/schema-preview.js.map +1 -0
  343. package/dist/src/lib/skill-installer.d.ts +2 -2
  344. package/dist/src/lib/skill-installer.js +2 -21
  345. package/dist/src/lib/skill-installer.js.map +1 -1
  346. package/dist/src/lib/step-run-table.d.ts +1 -2
  347. package/dist/src/lib/step-run-table.js +1 -2
  348. package/dist/src/lib/step-run-table.js.map +1 -1
  349. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  350. package/dist/src/lib/swift-codegen/agentGenerator.js +24 -22
  351. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  352. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  353. package/dist/src/lib/swift-codegen/banners.js +12 -0
  354. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  355. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  356. package/dist/src/lib/swift-codegen/functionGenerator.js +168 -50
  357. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  358. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +31 -7
  359. package/dist/src/lib/swift-codegen/schemaToSwift.js +213 -177
  360. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  361. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  362. package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
  363. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  364. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  365. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  366. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  367. package/dist/src/lib/sync-resource-types.d.ts +37 -5
  368. package/dist/src/lib/sync-resource-types.js +50 -5
  369. package/dist/src/lib/sync-resource-types.js.map +1 -1
  370. package/dist/src/lib/sync-selectors.d.ts +7 -0
  371. package/dist/src/lib/sync-selectors.js +22 -2
  372. package/dist/src/lib/sync-selectors.js.map +1 -1
  373. package/dist/src/lib/test-runs.d.ts +45 -0
  374. package/dist/src/lib/test-runs.js +150 -0
  375. package/dist/src/lib/test-runs.js.map +1 -0
  376. package/dist/src/lib/toml-database-config.d.ts +2 -1
  377. package/dist/src/lib/toml-database-config.js +7 -4
  378. package/dist/src/lib/toml-database-config.js.map +1 -1
  379. package/dist/src/lib/toml-scalar-edit.js +6 -4
  380. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  381. package/dist/src/lib/transition-warnings.d.ts +21 -0
  382. package/dist/src/lib/transition-warnings.js +49 -0
  383. package/dist/src/lib/transition-warnings.js.map +1 -0
  384. package/dist/src/lib/user-index.d.ts +80 -0
  385. package/dist/src/lib/user-index.js +166 -0
  386. package/dist/src/lib/user-index.js.map +1 -0
  387. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  388. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  389. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  390. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  391. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  392. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  393. package/dist/src/lib/user-walk.d.ts +31 -0
  394. package/dist/src/lib/user-walk.js +102 -0
  395. package/dist/src/lib/user-walk.js.map +1 -0
  396. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  397. package/dist/src/lib/worker-perf-format.js +27 -0
  398. package/dist/src/lib/worker-perf-format.js.map +1 -0
  399. package/dist/src/types/index.d.ts +13 -34
  400. package/package.json +5 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosting-token.js","sourceRoot":"","sources":["../../../src/lib/hosting-token.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,MAAM,CAAC;AAqB7C,qDAAqD;AACrD,MAAM,OAAO,oBAAoB;IAOF;IANrB,OAAO,GAAwB,IAAI,CAAC;IACpC,OAAO,GAAiC,IAAI,CAAC;IAC7C,IAAI,GAAgB,OAAO,CAAC;IACnB,GAAG,CAAe;IAEnC,wEAAwE;IACxE,YAA6B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;QACxD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACrC,CAAC;IAED,yEAAyE;IACzE,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACtD,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,kBAAkB,EAAE,CAAC;YAClG,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;QAClC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO;iBACxB,MAAM,CAAC,IAAI,CAAC;iBACZ,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;gBAChB,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;oBAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;gBAC/C,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACtB,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC;IAC1C,CAAC;IAED,8EAA8E;IAC9E,SAAS;QACP,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;CACF"}
@@ -0,0 +1,42 @@
1
+ /** The header every answer produced from an active deployment carries. */
2
+ export declare const DEPLOY_HEADER = "x-primitive-hosting-deploy";
3
+ /** How long a command waits for the origin to serve a deployment. */
4
+ export declare const SERVE_TIMEOUT_MS = 120000;
5
+ /** Time between two probes of the origin. */
6
+ export declare const SERVE_INTERVAL_MS = 1000;
7
+ /** One probe's answer: its status and the deployment id it carried, if any. */
8
+ export interface ProbeAnswer {
9
+ status: number;
10
+ deployId: string | null;
11
+ }
12
+ /** What {@link waitUntilServed} needs. */
13
+ export interface WaitOptions {
14
+ /** The origin being probed, for the timeout's message. */
15
+ origin: string;
16
+ /** The deployment the origin must serve. */
17
+ deployId: string;
18
+ /**
19
+ * One `HEAD <origin>/`; a thrown error counts as no answer. The signal is
20
+ * aborted when the wait's deadline passes while the probe is in flight.
21
+ */
22
+ probe: (signal: AbortSignal) => Promise<ProbeAnswer>;
23
+ /** How long to wait in all; 120 s by default. */
24
+ timeoutMs?: number;
25
+ /** Time between probes; 1 s by default. */
26
+ intervalMs?: number;
27
+ /** The clock; `Date.now` by default. */
28
+ now?: () => number;
29
+ /** Waits `ms`; a timer by default. */
30
+ sleep?: (ms: number) => Promise<void>;
31
+ }
32
+ /**
33
+ * Polls until the origin serves `deployId`. Each probe is bounded by the
34
+ * time left before `timeoutMs`, and an answer that arrives after the
35
+ * deadline is not accepted, so the wait never succeeds or runs past it.
36
+ *
37
+ * @param options The origin, the deployment, the probe and the clock.
38
+ * @returns The answer that showed the deployment served.
39
+ * @throws HostingError `activation_timeout` once `timeoutMs` have passed,
40
+ * carrying the last answer in `details`.
41
+ */
42
+ export declare function waitUntilServed(options: WaitOptions): Promise<ProbeAnswer>;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * How `primitive hosting deploy` and `activate` know the origin serves a
3
+ * deployment: they poll `HEAD <origin>/` until an answer carries the
4
+ * deployment's id in `x-primitive-hosting-deploy` with a status below 500.
5
+ * A 5xx carrying the id (the dispatcher's storage-unavailable 503) is not
6
+ * served.
7
+ */
8
+ import { HostingError } from "./hosting-errors.js";
9
+ /** The header every answer produced from an active deployment carries. */
10
+ export const DEPLOY_HEADER = "x-primitive-hosting-deploy";
11
+ /** How long a command waits for the origin to serve a deployment. */
12
+ export const SERVE_TIMEOUT_MS = 120_000;
13
+ /** Time between two probes of the origin. */
14
+ export const SERVE_INTERVAL_MS = 1_000;
15
+ function seconds(ms) {
16
+ return `${Math.round(ms / 100) / 10} s`;
17
+ }
18
+ /** A probe cut off by the wait's deadline: not an answer, so the last real answer stands. */
19
+ class DeadlinePassed extends Error {
20
+ }
21
+ /**
22
+ * Runs one probe, bounded by what is left of the wait: when `remainingMs`
23
+ * pass first, the probe's signal is aborted and the probe counts as no answer.
24
+ */
25
+ async function boundedProbe(probe, remainingMs) {
26
+ const controller = new AbortController();
27
+ let timer;
28
+ const expired = new Promise((_, reject) => {
29
+ timer = setTimeout(() => {
30
+ controller.abort();
31
+ reject(new DeadlinePassed("no answer before the wait's deadline"));
32
+ }, Math.max(0, remainingMs));
33
+ });
34
+ const probing = probe(controller.signal);
35
+ // A probe that settles after the deadline won must not surface as an unhandled rejection.
36
+ probing.catch(() => undefined);
37
+ try {
38
+ return await Promise.race([probing, expired]);
39
+ }
40
+ finally {
41
+ clearTimeout(timer);
42
+ }
43
+ }
44
+ /**
45
+ * Polls until the origin serves `deployId`. Each probe is bounded by the
46
+ * time left before `timeoutMs`, and an answer that arrives after the
47
+ * deadline is not accepted, so the wait never succeeds or runs past it.
48
+ *
49
+ * @param options The origin, the deployment, the probe and the clock.
50
+ * @returns The answer that showed the deployment served.
51
+ * @throws HostingError `activation_timeout` once `timeoutMs` have passed,
52
+ * carrying the last answer in `details`.
53
+ */
54
+ export async function waitUntilServed(options) {
55
+ const { origin, deployId, probe, timeoutMs = SERVE_TIMEOUT_MS, intervalMs = SERVE_INTERVAL_MS, now = Date.now, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), } = options;
56
+ const started = now();
57
+ let last = null;
58
+ let lastError = null;
59
+ for (;;) {
60
+ try {
61
+ const answer = await boundedProbe(probe, timeoutMs - (now() - started));
62
+ last = answer;
63
+ lastError = null;
64
+ const servedInTime = now() - started <= timeoutMs;
65
+ if (servedInTime && answer.deployId === deployId && answer.status < 500)
66
+ return answer;
67
+ }
68
+ catch (err) {
69
+ if (!(err instanceof DeadlinePassed && (last || lastError))) {
70
+ last = null;
71
+ lastError = err instanceof Error ? err.message : String(err);
72
+ }
73
+ }
74
+ const elapsed = now() - started;
75
+ if (elapsed >= timeoutMs)
76
+ break;
77
+ await sleep(Math.min(intervalMs, timeoutMs - elapsed));
78
+ }
79
+ const lastAnswer = last
80
+ ? `${last.status} ${last.deployId ? `from deployment ${last.deployId}` : "with no deployment id"}`
81
+ : `no answer (${lastError ?? "unknown error"})`;
82
+ throw new HostingError("activation_timeout", `Deployment ${deployId} is active in the registry, but ${origin} did not serve it within ${seconds(timeoutMs)}; it last answered ${lastAnswer}. Check it with 'primitive hosting get'.`, undefined, { deployId, origin, lastStatus: last?.status ?? null, lastDeployId: last?.deployId ?? null });
83
+ }
84
+ //# sourceMappingURL=hosting-wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosting-wait.js","sourceRoot":"","sources":["../../../src/lib/hosting-wait.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,aAAa,GAAG,4BAA4B,CAAC;AAE1D,qEAAqE;AACrE,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AA6BvC,SAAS,OAAO,CAAC,EAAU;IACzB,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC;AAC1C,CAAC;AAED,6FAA6F;AAC7F,MAAM,cAAe,SAAQ,KAAK;CAAG;AAErC;;;GAGG;AACH,KAAK,UAAU,YAAY,CAAC,KAAoD,EAAE,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AC,sBAAsB,UAAU,0CAA0C,EACvL,SAAS,EACT,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,IAAI,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI,EAAE,CAC7F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,86 @@
1
+ import type { BuildFile } from "./hosting-build.js";
2
+ /** A file the hosting service uploads beside the build's (its version marker). */
3
+ export interface PlatformFile {
4
+ /** The file's 32-hex hash, as the buckets name it. */
5
+ hash: string;
6
+ contentType: string;
7
+ /** The file's bytes, base64. */
8
+ base64: string;
9
+ }
10
+ /** A create's `upload` answer on `wfp`. */
11
+ export interface UploadSession {
12
+ url: string;
13
+ token: string;
14
+ /** Groups of 32-hex hashes, each uploaded in one request. */
15
+ buckets: string[][];
16
+ platformFiles: PlatformFile[];
17
+ }
18
+ /** Buckets uploaded at once. */
19
+ export declare const BUCKET_CONCURRENCY = 3;
20
+ /** Retries of one bucket after a network failure or a 5xx. */
21
+ export declare const BUCKET_RETRIES = 3;
22
+ /**
23
+ * Refuses an upload URL that is not Cloudflare's API, before any byte or the
24
+ * session token is sent.
25
+ *
26
+ * @param url The create answer's `upload.url`.
27
+ * @throws HostingError `upload_target_invalid`.
28
+ */
29
+ export declare function checkUploadTarget(url: string): void;
30
+ /**
31
+ * Whether a failed bucket upload is tried again: after a network failure or
32
+ * a 5xx, never after a 4xx.
33
+ *
34
+ * @param failure The answer's status, or that there was none.
35
+ * @returns True to retry.
36
+ */
37
+ export declare function shouldRetryUpload(failure: {
38
+ status: number;
39
+ } | {
40
+ network: true;
41
+ }): boolean;
42
+ /** One field of a bucket: a build file read from disk, or a platform file's bytes. */
43
+ export type BucketPart = {
44
+ name: string;
45
+ contentType: string;
46
+ file: BuildFile;
47
+ } | {
48
+ name: string;
49
+ contentType: string;
50
+ base64: string;
51
+ };
52
+ /**
53
+ * The fields of one bucket, one per hash: the build file holding it, else
54
+ * the platform file the session listed. The same bytes at two paths are one
55
+ * field.
56
+ *
57
+ * @param bucket The bucket's 32-hex hashes.
58
+ * @param files The build's files.
59
+ * @param platformFiles The session's platform files.
60
+ * @returns The bucket's fields, in the bucket's order.
61
+ * @throws HostingError `hosting_error` when a hash matches neither.
62
+ */
63
+ export declare function bucketParts(bucket: readonly string[], files: readonly BuildFile[], platformFiles: readonly PlatformFile[]): BucketPart[];
64
+ /**
65
+ * One bucket as Cloudflare's upload takes it: a field per hash, named by
66
+ * the hash, holding the file's base64 with its content type.
67
+ *
68
+ * @param parts The bucket's fields ({@link bucketParts}).
69
+ * @returns The multipart form.
70
+ */
71
+ export declare function bucketForm(parts: readonly BucketPart[]): Promise<FormData>;
72
+ /**
73
+ * Uploads every bucket of the session, {@link BUCKET_CONCURRENCY} at a time.
74
+ * Every bucket is checked against the build before the first is sent.
75
+ *
76
+ * @param session The create's `upload` answer; its URL is not checked here ({@link checkUploadTarget}).
77
+ * @param files The build's files.
78
+ * @param options `sleep` replaces the pause between retries.
79
+ * @returns How many files were uploaded.
80
+ * @throws HostingError `upload_session_expired`, `upload_refused`, `upload_failed` or `hosting_error`.
81
+ */
82
+ export declare function uploadBuckets(session: UploadSession, files: readonly BuildFile[], options?: {
83
+ sleep?: (ms: number) => Promise<void>;
84
+ }): Promise<{
85
+ uploaded: number;
86
+ }>;
@@ -0,0 +1,149 @@
1
+ /**
2
+ * How `primitive hosting deploy` uploads a build on the `wfp` backend: the
3
+ * create answers an `upload` session (Cloudflare's upload URL, a session
4
+ * token valid one hour, and the buckets of files the app's user Worker
5
+ * lacks), and the CLI sends each bucket straight to Cloudflare as base64
6
+ * multipart, three buckets at a time. The session token is sent only to
7
+ * `https://api.cloudflare.com` and never printed.
8
+ */
9
+ import { readFile } from "fs/promises";
10
+ import { hostingFetch } from "./hosting-client.js";
11
+ import { HostingError } from "./hosting-errors.js";
12
+ /** Buckets uploaded at once. */
13
+ export const BUCKET_CONCURRENCY = 3;
14
+ /** Retries of one bucket after a network failure or a 5xx. */
15
+ export const BUCKET_RETRIES = 3;
16
+ /** How long one bucket upload may take. */
17
+ const BUCKET_TIMEOUT_MS = 120_000;
18
+ /**
19
+ * Refuses an upload URL that is not Cloudflare's API, before any byte or the
20
+ * session token is sent.
21
+ *
22
+ * @param url The create answer's `upload.url`.
23
+ * @throws HostingError `upload_target_invalid`.
24
+ */
25
+ export function checkUploadTarget(url) {
26
+ let target;
27
+ try {
28
+ target = new URL(url);
29
+ }
30
+ catch {
31
+ target = null;
32
+ }
33
+ const ok = target !== null && target.protocol === "https:" && target.host === "api.cloudflare.com" && !target.username && !target.password;
34
+ if (!ok) {
35
+ throw new HostingError("upload_target_invalid", "The hosting service named an upload target that is not https://api.cloudflare.com, so nothing was uploaded. Check that PRIMITIVE_HOSTING_URL points at a Primitive hosting service.");
36
+ }
37
+ }
38
+ /**
39
+ * Whether a failed bucket upload is tried again: after a network failure or
40
+ * a 5xx, never after a 4xx.
41
+ *
42
+ * @param failure The answer's status, or that there was none.
43
+ * @returns True to retry.
44
+ */
45
+ export function shouldRetryUpload(failure) {
46
+ return "network" in failure || failure.status >= 500;
47
+ }
48
+ /**
49
+ * The fields of one bucket, one per hash: the build file holding it, else
50
+ * the platform file the session listed. The same bytes at two paths are one
51
+ * field.
52
+ *
53
+ * @param bucket The bucket's 32-hex hashes.
54
+ * @param files The build's files.
55
+ * @param platformFiles The session's platform files.
56
+ * @returns The bucket's fields, in the bucket's order.
57
+ * @throws HostingError `hosting_error` when a hash matches neither.
58
+ */
59
+ export function bucketParts(bucket, files, platformFiles) {
60
+ const byHash = new Map();
61
+ for (const file of files)
62
+ if (!byHash.has(file.sha256.slice(0, 32)))
63
+ byHash.set(file.sha256.slice(0, 32), file);
64
+ return bucket.map((hash) => {
65
+ const file = byHash.get(hash);
66
+ if (file)
67
+ return { name: hash, contentType: file.contentType, file };
68
+ const platform = platformFiles.find((p) => p.hash === hash);
69
+ if (platform)
70
+ return { name: hash, contentType: platform.contentType, base64: platform.base64 };
71
+ throw new HostingError("hosting_error", `The hosting service asked for a file the build does not hold (${hash}).`);
72
+ });
73
+ }
74
+ /**
75
+ * One bucket as Cloudflare's upload takes it: a field per hash, named by
76
+ * the hash, holding the file's base64 with its content type.
77
+ *
78
+ * @param parts The bucket's fields ({@link bucketParts}).
79
+ * @returns The multipart form.
80
+ */
81
+ export async function bucketForm(parts) {
82
+ const form = new FormData();
83
+ for (const part of parts) {
84
+ const base64 = "file" in part ? (await readFile(part.file.absolutePath)).toString("base64") : part.base64;
85
+ form.append(part.name, new Blob([base64], { type: part.contentType }), part.name);
86
+ }
87
+ return form;
88
+ }
89
+ /** Waits `ms`. */
90
+ const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
91
+ /** Uploads one bucket, retried as {@link shouldRetryUpload} says. */
92
+ async function uploadBucket(session, parts, sleep) {
93
+ const form = await bucketForm(parts);
94
+ const encoded = new Response(form);
95
+ const contentType = encoded.headers.get("content-type");
96
+ const body = Buffer.from(await encoded.arrayBuffer());
97
+ let last = "";
98
+ let attempts = 0;
99
+ for (let attempt = 0; attempt <= BUCKET_RETRIES; attempt++) {
100
+ if (attempt > 0)
101
+ await sleep(250 * attempt);
102
+ attempts++;
103
+ let status;
104
+ try {
105
+ status = (await hostingFetch(session.url, {
106
+ method: "POST",
107
+ headers: { Authorization: `Bearer ${session.token}`, "Content-Type": contentType },
108
+ body,
109
+ timeoutMs: BUCKET_TIMEOUT_MS,
110
+ })).status;
111
+ }
112
+ catch (err) {
113
+ last = `a network error (${err instanceof Error ? err.message : String(err)})`;
114
+ continue;
115
+ }
116
+ if (status >= 200 && status < 300)
117
+ return;
118
+ if (status === 401 || status === 403) {
119
+ throw new HostingError("upload_session_expired", "The upload session expired or was not accepted. Run the deploy again: it opens a new session and uploads what is still missing.", status);
120
+ }
121
+ if (!shouldRetryUpload({ status })) {
122
+ throw new HostingError("upload_refused", `The hosting backend refused an upload with ${status}. Nothing was activated; run the deploy again.`, status);
123
+ }
124
+ last = `${status}`;
125
+ }
126
+ throw new HostingError("upload_failed", `Could not upload ${parts.length} file(s) after ${BUCKET_RETRIES} retries: the last attempt ended with ${last}. Nothing was activated; run the deploy again to upload what is still missing.`, undefined, { attempts });
127
+ }
128
+ /**
129
+ * Uploads every bucket of the session, {@link BUCKET_CONCURRENCY} at a time.
130
+ * Every bucket is checked against the build before the first is sent.
131
+ *
132
+ * @param session The create's `upload` answer; its URL is not checked here ({@link checkUploadTarget}).
133
+ * @param files The build's files.
134
+ * @param options `sleep` replaces the pause between retries.
135
+ * @returns How many files were uploaded.
136
+ * @throws HostingError `upload_session_expired`, `upload_refused`, `upload_failed` or `hosting_error`.
137
+ */
138
+ export async function uploadBuckets(session, files, options = {}) {
139
+ const queue = session.buckets.map((bucket) => bucketParts(bucket, files, session.platformFiles ?? []));
140
+ const sleep = options.sleep ?? pause;
141
+ let next = 0;
142
+ const worker = async () => {
143
+ while (next < queue.length)
144
+ await uploadBucket(session, queue[next++], sleep);
145
+ };
146
+ await Promise.all(Array.from({ length: Math.min(BUCKET_CONCURRENCY, queue.length) }, worker));
147
+ return { uploaded: queue.reduce((n, parts) => n + parts.length, 0) };
148
+ }
149
+ //# sourceMappingURL=hosting-wfp-upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosting-wfp-upload.js","sourceRoot":"","sources":["../../../src/lib/hosting-wfp-upload.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAoBnD,gCAAgC;AAChC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAEpC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,2CAA2C;AAC3C,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC;;;;;;GAMG;AACH,MAA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EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;AACvE,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { IntegrationTestPayload } from "./api-client.js";
2
+ /**
3
+ * The longest base64 attachment the integration test route accepts. The
4
+ * server's `normalizeProxyPayload` (`src/services/integration-utils.ts`)
5
+ * refuses anything longer as over its 10 MB limit, which admits files of at
6
+ * most 9,999,999 bytes. The CLI checks the encoded length, the same quantity
7
+ * the server checks, so the two limits cannot disagree.
8
+ */
9
+ export declare const MAX_ATTACHMENT_BASE64_CHARS = 13333333;
10
+ /** The `integrations test` option values the request is built from. */
11
+ export interface IntegrationTestRequestFlags {
12
+ method?: string;
13
+ path?: string;
14
+ /** `--query`, as JSON text. */
15
+ query?: string;
16
+ /** `--body`, as JSON text. */
17
+ body?: string;
18
+ /** `--header 'Name: value'`, repeatable. */
19
+ header?: string[];
20
+ /** `--form name=value`, repeatable. */
21
+ form?: string[];
22
+ /** `--field name=value`, repeatable. */
23
+ field?: string[];
24
+ /** `--file field=@path`, repeatable. */
25
+ file?: string[];
26
+ /** `--raw-body <path|->`. */
27
+ rawBody?: string;
28
+ /** `--content-type <type>`, the raw body's type. */
29
+ contentType?: string;
30
+ }
31
+ /** The request builder's answer: the payload to send, or why nothing is sent. */
32
+ export type IntegrationTestRequestResult = {
33
+ ok: true;
34
+ payload: IntegrationTestPayload;
35
+ } | {
36
+ ok: false;
37
+ message: string;
38
+ };
39
+ /** What the builder reads from outside the flags. */
40
+ export interface IntegrationTestRequestDeps {
41
+ /** Read all of stdin, for `--raw-body -`. */
42
+ readStdin?: () => Promise<Buffer>;
43
+ }
44
+ /**
45
+ * Build the body of `POST …/integrations/{id}/test` from the command's
46
+ * options, or say why the request would be refused or misread by the
47
+ * integration proxy. Nothing here sends a request.
48
+ *
49
+ * Each option maps to one field the route accepts: `--header` to `headers`,
50
+ * `--form` to the url-encoded `form` table, `--field` and `--file` to
51
+ * multipart `multipartFields` and `attachments`, and `--raw-body` to a raw
52
+ * body sent from its one attachment.
53
+ */
54
+ export declare function buildIntegrationTestRequest(flags: IntegrationTestRequestFlags, deps?: IntegrationTestRequestDeps): Promise<IntegrationTestRequestResult>;
@@ -0,0 +1,207 @@
1
+ import { attachmentFromBytes, readFileAttachment } from "./file-attachment.js";
2
+ /**
3
+ * The longest base64 attachment the integration test route accepts. The
4
+ * server's `normalizeProxyPayload` (`src/services/integration-utils.ts`)
5
+ * refuses anything longer as over its 10 MB limit, which admits files of at
6
+ * most 9,999,999 bytes. The CLI checks the encoded length, the same quantity
7
+ * the server checks, so the two limits cannot disagree.
8
+ */
9
+ export const MAX_ATTACHMENT_BASE64_CHARS = 13_333_333;
10
+ async function readProcessStdin() {
11
+ const chunks = [];
12
+ for await (const chunk of process.stdin) {
13
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
14
+ }
15
+ return Buffer.concat(chunks);
16
+ }
17
+ /** Split `name<sep>value` at the first separator; null when there is no name. */
18
+ function splitPair(entry, separator) {
19
+ const at = entry.indexOf(separator);
20
+ if (at <= 0)
21
+ return null;
22
+ const name = entry.slice(0, at).trim();
23
+ if (!name)
24
+ return null;
25
+ return [name, entry.slice(at + 1)];
26
+ }
27
+ function oversize(label, attachment) {
28
+ if (attachment.data.length <= MAX_ATTACHMENT_BASE64_CHARS)
29
+ return null;
30
+ return `Attachment '${label}' exceeds the 10 MB size limit for an integration test.`;
31
+ }
32
+ /**
33
+ * Build the body of `POST …/integrations/{id}/test` from the command's
34
+ * options, or say why the request would be refused or misread by the
35
+ * integration proxy. Nothing here sends a request.
36
+ *
37
+ * Each option maps to one field the route accepts: `--header` to `headers`,
38
+ * `--form` to the url-encoded `form` table, `--field` and `--file` to
39
+ * multipart `multipartFields` and `attachments`, and `--raw-body` to a raw
40
+ * body sent from its one attachment.
41
+ */
42
+ export async function buildIntegrationTestRequest(flags, deps = {}) {
43
+ const headerFlags = flags.header ?? [];
44
+ const formFlags = flags.form ?? [];
45
+ const fieldFlags = flags.field ?? [];
46
+ const fileFlags = flags.file ?? [];
47
+ // Empty --query/--body text is ignored, as it always was.
48
+ const hasBody = Boolean(flags.body);
49
+ const hasRaw = flags.rawBody !== undefined;
50
+ const payload = { method: flags.method, path: flags.path };
51
+ if (flags.query) {
52
+ try {
53
+ payload.query = JSON.parse(flags.query);
54
+ }
55
+ catch {
56
+ return { ok: false, message: "Invalid JSON in --query" };
57
+ }
58
+ }
59
+ if (hasBody) {
60
+ try {
61
+ payload.body = JSON.parse(flags.body);
62
+ }
63
+ catch {
64
+ return { ok: false, message: "Invalid JSON in --body" };
65
+ }
66
+ }
67
+ // The proxy refuses `form` alongside another body (REQUEST_BODY_CONFLICT),
68
+ // sends only the attachment in raw mode, and ignores `body` once multipart
69
+ // fields are given, so each mix is refused here instead.
70
+ const given = (pairs) => pairs.filter(([on]) => on).map(([, flag]) => flag);
71
+ if (hasRaw) {
72
+ const others = given([
73
+ [hasBody, "--body"],
74
+ [formFlags.length > 0, "--form"],
75
+ [fieldFlags.length > 0, "--field"],
76
+ [fileFlags.length > 0, "--file"],
77
+ ]);
78
+ if (others.length > 0) {
79
+ return { ok: false, message: `--raw-body sends the whole body; it cannot be combined with ${others.join(", ")}.` };
80
+ }
81
+ }
82
+ if (formFlags.length > 0) {
83
+ const others = given([
84
+ [hasBody, "--body"],
85
+ [fieldFlags.length > 0, "--field"],
86
+ [fileFlags.length > 0, "--file"],
87
+ ]);
88
+ if (others.length > 0) {
89
+ return { ok: false, message: `--form sends a url-encoded body; it cannot be combined with ${others.join(", ")}.` };
90
+ }
91
+ }
92
+ if (hasBody && (fieldFlags.length > 0 || fileFlags.length > 0)) {
93
+ const others = given([
94
+ [fieldFlags.length > 0, "--field"],
95
+ [fileFlags.length > 0, "--file"],
96
+ ]);
97
+ return {
98
+ ok: false,
99
+ message: `--body cannot be combined with ${others.join(", ")}: a multipart body ignores it. Send text parts with --field.`,
100
+ };
101
+ }
102
+ if (flags.contentType !== undefined && !hasRaw) {
103
+ return {
104
+ ok: false,
105
+ message: "--content-type sets the type of --raw-body; pass --raw-body, or set the header with --header 'Content-Type: <type>'.",
106
+ };
107
+ }
108
+ if (headerFlags.length > 0) {
109
+ // Null-prototype maps so names like `__proto__` or `constructor` are kept as given.
110
+ const headers = Object.create(null);
111
+ for (const entry of headerFlags) {
112
+ const pair = splitPair(entry, ":");
113
+ if (!pair)
114
+ return { ok: false, message: `Invalid --header '${entry}'. Use 'Name: value'.` };
115
+ headers[pair[0]] = pair[1].trim();
116
+ }
117
+ payload.headers = headers;
118
+ }
119
+ if (formFlags.length > 0) {
120
+ const form = Object.create(null);
121
+ for (const entry of formFlags) {
122
+ const pair = splitPair(entry, "=");
123
+ if (!pair)
124
+ return { ok: false, message: `Invalid --form '${entry}'. Use name=value.` };
125
+ const [name, value] = pair;
126
+ const existing = form[name];
127
+ form[name] = existing === undefined ? value : [...(Array.isArray(existing) ? existing : [existing]), value];
128
+ }
129
+ payload.form = form;
130
+ }
131
+ if (fieldFlags.length > 0 || fileFlags.length > 0) {
132
+ const fields = [];
133
+ const filePaths = [];
134
+ const seen = new Set();
135
+ const claim = (name) => {
136
+ if (seen.has(name)) {
137
+ return `Multipart field '${name}' is given more than once across --field and --file.`;
138
+ }
139
+ seen.add(name);
140
+ return null;
141
+ };
142
+ for (const entry of fieldFlags) {
143
+ const pair = splitPair(entry, "=");
144
+ if (!pair)
145
+ return { ok: false, message: `Invalid --field '${entry}'. Use name=value.` };
146
+ const duplicate = claim(pair[0]);
147
+ if (duplicate)
148
+ return { ok: false, message: duplicate };
149
+ fields.push({ fieldName: pair[0], type: "value", value: pair[1] });
150
+ }
151
+ for (const entry of fileFlags) {
152
+ const pair = splitPair(entry, "=");
153
+ if (!pair || !pair[1].startsWith("@") || pair[1].length === 1) {
154
+ return {
155
+ ok: false,
156
+ message: `Invalid --file '${entry}'. Use field=@path; to send a text value, use --field name=value.`,
157
+ };
158
+ }
159
+ const duplicate = claim(pair[0]);
160
+ if (duplicate)
161
+ return { ok: false, message: duplicate };
162
+ fields.push({ fieldName: pair[0], type: "attachment", attachmentIndex: filePaths.length });
163
+ filePaths.push(pair[1].slice(1));
164
+ }
165
+ const attachments = [];
166
+ for (const filePath of filePaths) {
167
+ let attachment;
168
+ try {
169
+ attachment = readFileAttachment(filePath);
170
+ }
171
+ catch (err) {
172
+ return { ok: false, message: `--file: ${err.message}` };
173
+ }
174
+ const tooBig = oversize(filePath, attachment);
175
+ if (tooBig)
176
+ return { ok: false, message: tooBig };
177
+ attachments.push(attachment);
178
+ }
179
+ payload.bodyMode = "multipart";
180
+ if (attachments.length > 0)
181
+ payload.attachments = attachments;
182
+ payload.multipartFields = fields;
183
+ }
184
+ if (hasRaw) {
185
+ const source = flags.rawBody;
186
+ let attachment;
187
+ if (source === "-") {
188
+ const bytes = await (deps.readStdin ?? readProcessStdin)();
189
+ attachment = attachmentFromBytes("stdin", bytes, flags.contentType);
190
+ }
191
+ else {
192
+ try {
193
+ attachment = readFileAttachment(source, flags.contentType);
194
+ }
195
+ catch (err) {
196
+ return { ok: false, message: `--raw-body: ${err.message}` };
197
+ }
198
+ }
199
+ const tooBig = oversize(source === "-" ? "stdin" : source, attachment);
200
+ if (tooBig)
201
+ return { ok: false, message: tooBig };
202
+ payload.bodyMode = "raw";
203
+ payload.attachments = [attachment];
204
+ }
205
+ return { ok: true, payload };
206
+ }
207
+ //# sourceMappingURL=integration-test-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-test-request.js","sourceRoot":"","sources":["../../../src/lib/integration-test-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAuB,MAAM,sBAAsB,CAAC;AAEpG;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC;AAmCtD,KAAK,UAAU,gBAAgB;IAC7B,MAAM,M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