primitive-admin 1.2.0-alpha.9 → 1.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (546) hide show
  1. package/README.md +258 -186
  2. package/assets/skill/skills/primitive-platform/SKILL.md +93 -27
  3. package/dist/bin/primitive.js +15 -89
  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.d.ts +129 -0
  8. package/dist/src/commands/agent-sessions.js +532 -20
  9. package/dist/src/commands/agent-sessions.js.map +1 -1
  10. package/dist/src/commands/analytics.js +207 -155
  11. package/dist/src/commands/analytics.js.map +1 -1
  12. package/dist/src/commands/apps-children.js +3 -0
  13. package/dist/src/commands/apps-children.js.map +1 -1
  14. package/dist/src/commands/apps-transitions.d.ts +39 -0
  15. package/dist/src/commands/apps-transitions.js +198 -0
  16. package/dist/src/commands/apps-transitions.js.map +1 -0
  17. package/dist/src/commands/apps.d.ts +17 -0
  18. package/dist/src/commands/apps.js +108 -3
  19. package/dist/src/commands/apps.js.map +1 -1
  20. package/dist/src/commands/auth-sessions.js +2 -0
  21. package/dist/src/commands/auth-sessions.js.map +1 -1
  22. package/dist/src/commands/auth.js +138 -44
  23. package/dist/src/commands/auth.js.map +1 -1
  24. package/dist/src/commands/blob-buckets.js +2 -0
  25. package/dist/src/commands/blob-buckets.js.map +1 -1
  26. package/dist/src/commands/collections.js +318 -256
  27. package/dist/src/commands/collections.js.map +1 -1
  28. package/dist/src/commands/comparisons.js +2 -0
  29. package/dist/src/commands/comparisons.js.map +1 -1
  30. package/dist/src/commands/config.d.ts +2 -2
  31. package/dist/src/commands/config.js +59 -33
  32. package/dist/src/commands/config.js.map +1 -1
  33. package/dist/src/commands/connections.js +2 -0
  34. package/dist/src/commands/connections.js.map +1 -1
  35. package/dist/src/commands/database-type-configs.js +5 -3
  36. package/dist/src/commands/database-type-configs.js.map +1 -1
  37. package/dist/src/commands/databases.js +6 -4
  38. package/dist/src/commands/databases.js.map +1 -1
  39. package/dist/src/commands/db3-types.d.ts +15 -0
  40. package/dist/src/commands/db3-types.js +159 -0
  41. package/dist/src/commands/db3-types.js.map +1 -0
  42. package/dist/src/commands/db3.d.ts +24 -0
  43. package/dist/src/commands/db3.js +1444 -0
  44. package/dist/src/commands/db3.js.map +1 -0
  45. package/dist/src/commands/documents.d.ts +110 -10
  46. package/dist/src/commands/documents.js +1012 -748
  47. package/dist/src/commands/documents.js.map +1 -1
  48. package/dist/src/commands/email-templates.js +74 -0
  49. package/dist/src/commands/email-templates.js.map +1 -1
  50. package/dist/src/commands/env.js +8 -4
  51. package/dist/src/commands/env.js.map +1 -1
  52. package/dist/src/commands/function-trigger-commands.d.ts +28 -0
  53. package/dist/src/commands/function-trigger-commands.js +341 -0
  54. package/dist/src/commands/function-trigger-commands.js.map +1 -0
  55. package/dist/src/commands/functions.js +376 -30
  56. package/dist/src/commands/functions.js.map +1 -1
  57. package/dist/src/commands/groups.js +168 -50
  58. package/dist/src/commands/groups.js.map +1 -1
  59. package/dist/src/commands/guides.js +7 -5
  60. package/dist/src/commands/guides.js.map +1 -1
  61. package/dist/src/commands/hosting.d.ts +8 -0
  62. package/dist/src/commands/hosting.js +346 -0
  63. package/dist/src/commands/hosting.js.map +1 -0
  64. package/dist/src/commands/init.js +129 -38
  65. package/dist/src/commands/init.js.map +1 -1
  66. package/dist/src/commands/integrations.js +82 -53
  67. package/dist/src/commands/integrations.js.map +1 -1
  68. package/dist/src/commands/locks.d.ts +5 -3
  69. package/dist/src/commands/locks.js +19 -61
  70. package/dist/src/commands/locks.js.map +1 -1
  71. package/dist/src/commands/metadata-category-configs.d.ts +2 -2
  72. package/dist/src/commands/metadata-category-configs.js +4 -2
  73. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  74. package/dist/src/commands/metadata.js +41 -0
  75. package/dist/src/commands/metadata.js.map +1 -1
  76. package/dist/src/commands/prompts.js +75 -52
  77. package/dist/src/commands/prompts.js.map +1 -1
  78. package/dist/src/commands/rate-counters.d.ts +19 -0
  79. package/dist/src/commands/rate-counters.js +104 -0
  80. package/dist/src/commands/rate-counters.js.map +1 -0
  81. package/dist/src/commands/rule-sets.d.ts +1 -1
  82. package/dist/src/commands/rule-sets.js +2 -1
  83. package/dist/src/commands/rule-sets.js.map +1 -1
  84. package/dist/src/commands/schemas.d.ts +15 -0
  85. package/dist/src/commands/schemas.js +122 -0
  86. package/dist/src/commands/schemas.js.map +1 -0
  87. package/dist/src/commands/scripts.d.ts +9 -17
  88. package/dist/src/commands/scripts.js +24 -479
  89. package/dist/src/commands/scripts.js.map +1 -1
  90. package/dist/src/commands/secrets.js +47 -3
  91. package/dist/src/commands/secrets.js.map +1 -1
  92. package/dist/src/commands/sessions.js +2 -0
  93. package/dist/src/commands/sessions.js.map +1 -1
  94. package/dist/src/commands/skill.js +2 -0
  95. package/dist/src/commands/skill.js.map +1 -1
  96. package/dist/src/commands/sync-schemas.d.ts +202 -0
  97. package/dist/src/commands/sync-schemas.js +629 -0
  98. package/dist/src/commands/sync-schemas.js.map +1 -0
  99. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  100. package/dist/src/commands/sync-user-properties.js +276 -0
  101. package/dist/src/commands/sync-user-properties.js.map +1 -0
  102. package/dist/src/commands/sync.d.ts +518 -546
  103. package/dist/src/commands/sync.js +3010 -4877
  104. package/dist/src/commands/sync.js.map +1 -1
  105. package/dist/src/commands/tokens.js +5 -3
  106. package/dist/src/commands/tokens.js.map +1 -1
  107. package/dist/src/commands/transitions.d.ts +54 -0
  108. package/dist/src/commands/transitions.js +418 -0
  109. package/dist/src/commands/transitions.js.map +1 -0
  110. package/dist/src/commands/usage.d.ts +18 -0
  111. package/dist/src/commands/usage.js +343 -0
  112. package/dist/src/commands/usage.js.map +1 -0
  113. package/dist/src/commands/user-properties.d.ts +14 -0
  114. package/dist/src/commands/user-properties.js +79 -0
  115. package/dist/src/commands/user-properties.js.map +1 -0
  116. package/dist/src/commands/users.js +911 -18
  117. package/dist/src/commands/users.js.map +1 -1
  118. package/dist/src/commands/vars.js +2 -0
  119. package/dist/src/commands/vars.js.map +1 -1
  120. package/dist/src/commands/waitlist.js +39 -4
  121. package/dist/src/commands/waitlist.js.map +1 -1
  122. package/dist/src/commands/workflows.d.ts +5 -83
  123. package/dist/src/commands/workflows.js +57 -2282
  124. package/dist/src/commands/workflows.js.map +1 -1
  125. package/dist/src/lib/analytics-query.d.ts +58 -0
  126. package/dist/src/lib/analytics-query.js +134 -0
  127. package/dist/src/lib/analytics-query.js.map +1 -0
  128. package/dist/src/lib/api-client.d.ts +1818 -438
  129. package/dist/src/lib/api-client.js +965 -544
  130. package/dist/src/lib/api-client.js.map +1 -1
  131. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  132. package/dist/src/lib/app-settings-descriptor.js +6 -0
  133. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  134. package/dist/src/lib/auth-fixtures.d.ts +44 -0
  135. package/dist/src/lib/auth-fixtures.js +61 -0
  136. package/dist/src/lib/auth-fixtures.js.map +1 -0
  137. package/dist/src/lib/auth-flow.d.ts +34 -1
  138. package/dist/src/lib/auth-flow.js +429 -13
  139. package/dist/src/lib/auth-flow.js.map +1 -1
  140. package/dist/src/lib/block-layout.d.ts +12 -23
  141. package/dist/src/lib/block-layout.js +26 -92
  142. package/dist/src/lib/block-layout.js.map +1 -1
  143. package/dist/src/lib/block-selector.d.ts +8 -14
  144. package/dist/src/lib/block-selector.js +8 -19
  145. package/dist/src/lib/block-selector.js.map +1 -1
  146. package/dist/src/lib/child-apps-local.d.ts +3 -1
  147. package/dist/src/lib/child-apps-local.js +9 -1
  148. package/dist/src/lib/child-apps-local.js.map +1 -1
  149. package/dist/src/lib/cli-manifest.d.ts +9 -0
  150. package/dist/src/lib/cli-manifest.js +10 -1
  151. package/dist/src/lib/cli-manifest.js.map +1 -1
  152. package/dist/src/lib/cli-version.d.ts +14 -0
  153. package/dist/src/lib/cli-version.js +38 -0
  154. package/dist/src/lib/cli-version.js.map +1 -0
  155. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  156. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  157. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  158. package/dist/src/lib/collection-export.d.ts +76 -15
  159. package/dist/src/lib/collection-export.js +116 -23
  160. package/dist/src/lib/collection-export.js.map +1 -1
  161. package/dist/src/lib/collection-principal.d.ts +22 -0
  162. package/dist/src/lib/collection-principal.js +35 -0
  163. package/dist/src/lib/collection-principal.js.map +1 -0
  164. package/dist/src/lib/command-groups.d.ts +30 -0
  165. package/dist/src/lib/command-groups.js +109 -0
  166. package/dist/src/lib/command-groups.js.map +1 -0
  167. package/dist/src/lib/command-status.d.ts +147 -0
  168. package/dist/src/lib/command-status.js +266 -0
  169. package/dist/src/lib/command-status.js.map +1 -0
  170. package/dist/src/lib/config-object-descriptor.d.ts +9 -22
  171. package/dist/src/lib/config-object-descriptor.js +107 -276
  172. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  173. package/dist/src/lib/config-surface.d.ts +3 -7
  174. package/dist/src/lib/config-surface.js +9 -13
  175. package/dist/src/lib/config-surface.js.map +1 -1
  176. package/dist/src/lib/config-toml.d.ts +11 -2
  177. package/dist/src/lib/config-toml.js +25 -2
  178. package/dist/src/lib/config-toml.js.map +1 -1
  179. package/dist/src/lib/credentials-home.d.ts +7 -0
  180. package/dist/src/lib/credentials-home.js +45 -10
  181. package/dist/src/lib/credentials-home.js.map +1 -1
  182. package/dist/src/lib/credentials-lock.d.ts +14 -6
  183. package/dist/src/lib/credentials-lock.js +90 -10
  184. package/dist/src/lib/credentials-lock.js.map +1 -1
  185. package/dist/src/lib/credentials-store.d.ts +123 -70
  186. package/dist/src/lib/credentials-store.js +358 -113
  187. package/dist/src/lib/credentials-store.js.map +1 -1
  188. package/dist/src/lib/custodian.d.ts +8 -0
  189. package/dist/src/lib/custodian.js +18 -0
  190. package/dist/src/lib/custodian.js.map +1 -0
  191. package/dist/src/lib/data-input.d.ts +1 -1
  192. package/dist/src/lib/data-input.js +1 -1
  193. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  194. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  195. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  196. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +38 -1
  197. package/dist/src/lib/db-codegen/dbTypeIR.js +29 -7
  198. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  199. package/dist/src/lib/db-type-records.d.ts +106 -0
  200. package/dist/src/lib/db-type-records.js +224 -0
  201. package/dist/src/lib/db-type-records.js.map +1 -0
  202. package/dist/src/lib/db3-export.d.ts +287 -0
  203. package/dist/src/lib/db3-export.js +647 -0
  204. package/dist/src/lib/db3-export.js.map +1 -0
  205. package/dist/src/lib/db3-index-output.d.ts +116 -0
  206. package/dist/src/lib/db3-index-output.js +223 -0
  207. package/dist/src/lib/db3-index-output.js.map +1 -0
  208. package/dist/src/lib/db3-type-models.d.ts +134 -0
  209. package/dist/src/lib/db3-type-models.js +452 -0
  210. package/dist/src/lib/db3-type-models.js.map +1 -0
  211. package/dist/src/lib/deprecation.d.ts +2 -2
  212. package/dist/src/lib/deprecation.js +2 -2
  213. package/dist/src/lib/document-ingest-artifact.d.ts +13 -0
  214. package/dist/src/lib/document-ingest-artifact.js +36 -6
  215. package/dist/src/lib/document-ingest-artifact.js.map +1 -1
  216. package/dist/src/lib/document-ingest-format2.d.ts +36 -0
  217. package/dist/src/lib/document-ingest-format2.js +78 -0
  218. package/dist/src/lib/document-ingest-format2.js.map +1 -0
  219. package/dist/src/lib/document-ingest-input.d.ts +9 -0
  220. package/dist/src/lib/document-ingest-input.js +28 -1
  221. package/dist/src/lib/document-ingest-input.js.map +1 -1
  222. package/dist/src/lib/document-ingest.d.ts +11 -1
  223. package/dist/src/lib/document-ingest.js +16 -0
  224. package/dist/src/lib/document-ingest.js.map +1 -1
  225. package/dist/src/lib/document-schema-rows.d.ts +42 -0
  226. package/dist/src/lib/document-schema-rows.js +53 -0
  227. package/dist/src/lib/document-schema-rows.js.map +1 -0
  228. package/dist/src/lib/experimental-apis.d.ts +36 -0
  229. package/dist/src/lib/experimental-apis.js +46 -0
  230. package/dist/src/lib/experimental-apis.js.map +1 -0
  231. package/dist/src/lib/file-attachment.d.ts +24 -0
  232. package/dist/src/lib/file-attachment.js +31 -0
  233. package/dist/src/lib/file-attachment.js.map +1 -0
  234. package/dist/src/lib/function-authorize-check.d.ts +142 -0
  235. package/dist/src/lib/function-authorize-check.js +311 -0
  236. package/dist/src/lib/function-authorize-check.js.map +1 -0
  237. package/dist/src/lib/function-authorize-view.d.ts +27 -0
  238. package/dist/src/lib/function-authorize-view.js +88 -0
  239. package/dist/src/lib/function-authorize-view.js.map +1 -0
  240. package/dist/src/lib/function-bundle.d.ts +27 -5
  241. package/dist/src/lib/function-bundle.js +142 -7
  242. package/dist/src/lib/function-bundle.js.map +1 -1
  243. package/dist/src/lib/function-collect.d.ts +90 -12
  244. package/dist/src/lib/function-collect.js +482 -12
  245. package/dist/src/lib/function-collect.js.map +1 -1
  246. package/dist/src/lib/function-db-types.d.ts +65 -11
  247. package/dist/src/lib/function-db-types.js +297 -157
  248. package/dist/src/lib/function-db-types.js.map +1 -1
  249. package/dist/src/lib/function-document-types.d.ts +19 -7
  250. package/dist/src/lib/function-document-types.js +24 -12
  251. package/dist/src/lib/function-document-types.js.map +1 -1
  252. package/dist/src/lib/function-lint.d.ts +57 -0
  253. package/dist/src/lib/function-lint.js +234 -0
  254. package/dist/src/lib/function-lint.js.map +1 -0
  255. package/dist/src/lib/function-log-row.js +21 -2
  256. package/dist/src/lib/function-log-row.js.map +1 -1
  257. package/dist/src/lib/function-run.d.ts +13 -21
  258. package/dist/src/lib/function-run.js +14 -27
  259. package/dist/src/lib/function-run.js.map +1 -1
  260. package/dist/src/lib/function-schema-codegen.d.ts +86 -22
  261. package/dist/src/lib/function-schema-codegen.js +194 -88
  262. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  263. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  264. package/dist/src/lib/function-schema-refs.js +177 -0
  265. package/dist/src/lib/function-schema-refs.js.map +1 -0
  266. package/dist/src/lib/function-sync.d.ts +109 -6
  267. package/dist/src/lib/function-sync.js +179 -26
  268. package/dist/src/lib/function-sync.js.map +1 -1
  269. package/dist/src/lib/function-trigger-listing.d.ts +11 -6
  270. package/dist/src/lib/function-trigger-listing.js +32 -11
  271. package/dist/src/lib/function-trigger-listing.js.map +1 -1
  272. package/dist/src/lib/function-typecheck.d.ts +52 -0
  273. package/dist/src/lib/function-typecheck.js +174 -54
  274. package/dist/src/lib/function-typecheck.js.map +1 -1
  275. package/dist/src/lib/function-versions.d.ts +2 -0
  276. package/dist/src/lib/function-versions.js +1 -0
  277. package/dist/src/lib/function-versions.js.map +1 -1
  278. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  279. package/dist/src/lib/generated-build-flags.js +14 -0
  280. package/dist/src/lib/generated-build-flags.js.map +1 -0
  281. package/dist/src/lib/generated-command-status.d.ts +6 -0
  282. package/dist/src/lib/generated-command-status.js +469 -0
  283. package/dist/src/lib/generated-command-status.js.map +1 -0
  284. package/dist/src/lib/generated-config-surfaces.d.ts +538 -141
  285. package/dist/src/lib/generated-config-surfaces.js +1772 -1854
  286. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  287. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  288. package/dist/src/lib/generated-sdk-types.js +1 -1
  289. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  290. package/dist/src/lib/hosting-build.d.ts +97 -0
  291. package/dist/src/lib/hosting-build.js +204 -0
  292. package/dist/src/lib/hosting-build.js.map +1 -0
  293. package/dist/src/lib/hosting-client.d.ts +167 -0
  294. package/dist/src/lib/hosting-client.js +340 -0
  295. package/dist/src/lib/hosting-client.js.map +1 -0
  296. package/dist/src/lib/hosting-environments.d.ts +32 -0
  297. package/dist/src/lib/hosting-environments.js +74 -0
  298. package/dist/src/lib/hosting-environments.js.map +1 -0
  299. package/dist/src/lib/hosting-errors.d.ts +30 -0
  300. package/dist/src/lib/hosting-errors.js +43 -0
  301. package/dist/src/lib/hosting-errors.js.map +1 -0
  302. package/dist/src/lib/hosting-token.d.ts +46 -0
  303. package/dist/src/lib/hosting-token.js +60 -0
  304. package/dist/src/lib/hosting-token.js.map +1 -0
  305. package/dist/src/lib/hosting-wait.d.ts +42 -0
  306. package/dist/src/lib/hosting-wait.js +84 -0
  307. package/dist/src/lib/hosting-wait.js.map +1 -0
  308. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  309. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  310. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  311. package/dist/src/lib/init-assets.d.ts +2 -6
  312. package/dist/src/lib/init-assets.js +11 -27
  313. package/dist/src/lib/init-assets.js.map +1 -1
  314. package/dist/src/lib/init-ios-links.d.ts +11 -7
  315. package/dist/src/lib/init-ios-links.js +28 -22
  316. package/dist/src/lib/init-ios-links.js.map +1 -1
  317. package/dist/src/lib/init-login-note.d.ts +13 -0
  318. package/dist/src/lib/init-login-note.js +22 -0
  319. package/dist/src/lib/init-login-note.js.map +1 -0
  320. package/dist/src/lib/init-schema.d.ts +15 -0
  321. package/dist/src/lib/init-schema.js +54 -0
  322. package/dist/src/lib/init-schema.js.map +1 -1
  323. package/dist/src/lib/integration-test-request.d.ts +54 -0
  324. package/dist/src/lib/integration-test-request.js +207 -0
  325. package/dist/src/lib/integration-test-request.js.map +1 -0
  326. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  327. package/dist/src/lib/invoker-shared-enums.js +98 -0
  328. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  329. package/dist/src/lib/json-value.d.ts +6 -0
  330. package/dist/src/lib/json-value.js +13 -0
  331. package/dist/src/lib/json-value.js.map +1 -0
  332. package/dist/src/lib/load-routes.d.ts +33 -0
  333. package/dist/src/lib/load-routes.js +35 -0
  334. package/dist/src/lib/load-routes.js.map +1 -0
  335. package/dist/src/lib/log-inspection.d.ts +23 -4
  336. package/dist/src/lib/log-inspection.js +14 -5
  337. package/dist/src/lib/log-inspection.js.map +1 -1
  338. package/dist/src/lib/login-exchange-check.d.ts +18 -0
  339. package/dist/src/lib/login-exchange-check.js +27 -0
  340. package/dist/src/lib/login-exchange-check.js.map +1 -0
  341. package/dist/src/lib/login-scope-lines.d.ts +17 -7
  342. package/dist/src/lib/login-scope-lines.js +33 -10
  343. package/dist/src/lib/login-scope-lines.js.map +1 -1
  344. package/dist/src/lib/metadata-report.d.ts +85 -0
  345. package/dist/src/lib/metadata-report.js +81 -0
  346. package/dist/src/lib/metadata-report.js.map +1 -0
  347. package/dist/src/lib/object-status-filter.d.ts +9 -1
  348. package/dist/src/lib/object-status-filter.js +9 -1
  349. package/dist/src/lib/object-status-filter.js.map +1 -1
  350. package/dist/src/lib/output.d.ts +1 -1
  351. package/dist/src/lib/output.js +3 -1
  352. package/dist/src/lib/output.js.map +1 -1
  353. package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
  354. package/dist/src/lib/pin-refusal-hint.js +35 -0
  355. package/dist/src/lib/pin-refusal-hint.js.map +1 -0
  356. package/dist/src/lib/platform-owned.js +5 -0
  357. package/dist/src/lib/platform-owned.js.map +1 -1
  358. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  359. package/dist/src/lib/primitive-declaration-names.js +22 -0
  360. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  361. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  362. package/dist/src/lib/primitive-declaration.js +792 -0
  363. package/dist/src/lib/primitive-declaration.js.map +1 -0
  364. package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
  365. package/dist/src/lib/primitive-env-plugin.js +408 -0
  366. package/dist/src/lib/primitive-env-plugin.js.map +1 -0
  367. package/dist/src/lib/project-login-apps.d.ts +8 -0
  368. package/dist/src/lib/project-login-apps.js +27 -0
  369. package/dist/src/lib/project-login-apps.js.map +1 -0
  370. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  371. package/dist/src/lib/prompt-schema-codegen.js +96 -100
  372. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  373. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  374. package/dist/src/lib/prompt-schema-document.js +92 -0
  375. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  376. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  377. package/dist/src/lib/prompt-schema-refs.js +478 -0
  378. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  379. package/dist/src/lib/records-verbs.d.ts +79 -0
  380. package/dist/src/lib/records-verbs.js +45 -0
  381. package/dist/src/lib/records-verbs.js.map +1 -0
  382. package/dist/src/lib/register-commands.d.ts +36 -0
  383. package/dist/src/lib/register-commands.js +37 -0
  384. package/dist/src/lib/register-commands.js.map +1 -0
  385. package/dist/src/lib/retired-imports.d.ts +53 -0
  386. package/dist/src/lib/retired-imports.js +120 -0
  387. package/dist/src/lib/retired-imports.js.map +1 -0
  388. package/dist/src/lib/run-status.d.ts +1 -1
  389. package/dist/src/lib/run-status.generated.d.ts +2 -2
  390. package/dist/src/lib/run-status.generated.js +3 -1
  391. package/dist/src/lib/run-status.generated.js.map +1 -1
  392. package/dist/src/lib/run-status.js +1 -1
  393. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  394. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  395. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  396. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  397. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  398. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  399. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  400. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  401. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  402. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
  403. package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
  404. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  405. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  406. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  407. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  408. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  409. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  410. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  411. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +258 -0
  412. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +422 -0
  413. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
  414. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  415. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  416. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  417. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  418. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  419. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  420. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  421. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  422. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  423. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  424. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  425. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  426. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  427. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  428. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  429. package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
  430. package/dist/src/lib/schema-codegen/naming.js +83 -0
  431. package/dist/src/lib/schema-codegen/naming.js.map +1 -0
  432. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  433. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  434. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  435. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  436. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  437. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  438. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  439. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  440. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  441. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +109 -0
  442. package/dist/src/lib/schema-codegen/schemaToTs.js +269 -0
  443. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
  444. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  445. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  446. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  447. package/dist/src/lib/schema-family-index.d.ts +228 -0
  448. package/dist/src/lib/schema-family-index.js +813 -0
  449. package/dist/src/lib/schema-family-index.js.map +1 -0
  450. package/dist/src/lib/schema-pins.d.ts +82 -0
  451. package/dist/src/lib/schema-pins.js +198 -0
  452. package/dist/src/lib/schema-pins.js.map +1 -0
  453. package/dist/src/lib/schema-preview.d.ts +244 -0
  454. package/dist/src/lib/schema-preview.js +498 -0
  455. package/dist/src/lib/schema-preview.js.map +1 -0
  456. package/dist/src/lib/scope-request.d.ts +23 -11
  457. package/dist/src/lib/scope-request.js +69 -31
  458. package/dist/src/lib/scope-request.js.map +1 -1
  459. package/dist/src/lib/session-scope.d.ts +26 -0
  460. package/dist/src/lib/session-scope.js +58 -0
  461. package/dist/src/lib/session-scope.js.map +1 -0
  462. package/dist/src/lib/skill-installer.d.ts +2 -2
  463. package/dist/src/lib/skill-installer.js +2 -21
  464. package/dist/src/lib/skill-installer.js.map +1 -1
  465. package/dist/src/lib/step-run-table.d.ts +1 -2
  466. package/dist/src/lib/step-run-table.js +1 -2
  467. package/dist/src/lib/step-run-table.js.map +1 -1
  468. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  469. package/dist/src/lib/swift-codegen/agentGenerator.js +25 -23
  470. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  471. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  472. package/dist/src/lib/swift-codegen/banners.js +12 -0
  473. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  474. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  475. package/dist/src/lib/swift-codegen/functionGenerator.js +169 -51
  476. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  477. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +33 -9
  478. package/dist/src/lib/swift-codegen/schemaToSwift.js +215 -179
  479. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  480. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  481. package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
  482. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  483. package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
  484. package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
  485. package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
  486. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  487. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  488. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  489. package/dist/src/lib/sync-resource-types.d.ts +117 -31
  490. package/dist/src/lib/sync-resource-types.js +197 -189
  491. package/dist/src/lib/sync-resource-types.js.map +1 -1
  492. package/dist/src/lib/sync-selectors.d.ts +7 -0
  493. package/dist/src/lib/sync-selectors.js +22 -2
  494. package/dist/src/lib/sync-selectors.js.map +1 -1
  495. package/dist/src/lib/template.d.ts +39 -3
  496. package/dist/src/lib/template.js +103 -14
  497. package/dist/src/lib/template.js.map +1 -1
  498. package/dist/src/lib/test-case-file-names.d.ts +3 -5
  499. package/dist/src/lib/test-case-file-names.js +3 -5
  500. package/dist/src/lib/test-case-file-names.js.map +1 -1
  501. package/dist/src/lib/test-runs.d.ts +45 -0
  502. package/dist/src/lib/test-runs.js +150 -0
  503. package/dist/src/lib/test-runs.js.map +1 -0
  504. package/dist/src/lib/test-users.d.ts +25 -0
  505. package/dist/src/lib/test-users.js +36 -0
  506. package/dist/src/lib/test-users.js.map +1 -0
  507. package/dist/src/lib/toml-database-config.d.ts +4 -2
  508. package/dist/src/lib/toml-database-config.js +11 -6
  509. package/dist/src/lib/toml-database-config.js.map +1 -1
  510. package/dist/src/lib/toml-scalar-edit.js +6 -4
  511. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  512. package/dist/src/lib/transition-warnings.d.ts +21 -0
  513. package/dist/src/lib/transition-warnings.js +49 -0
  514. package/dist/src/lib/transition-warnings.js.map +1 -0
  515. package/dist/src/lib/user-index.d.ts +80 -0
  516. package/dist/src/lib/user-index.js +166 -0
  517. package/dist/src/lib/user-index.js.map +1 -0
  518. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  519. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  520. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  521. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  522. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  523. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  524. package/dist/src/lib/user-walk.d.ts +31 -0
  525. package/dist/src/lib/user-walk.js +102 -0
  526. package/dist/src/lib/user-walk.js.map +1 -0
  527. package/dist/src/lib/webhook-capture.d.ts +43 -0
  528. package/dist/src/lib/webhook-capture.js +91 -0
  529. package/dist/src/lib/webhook-capture.js.map +1 -0
  530. package/dist/src/lib/webhook-deliver.d.ts +18 -20
  531. package/dist/src/lib/webhook-deliver.js +34 -89
  532. package/dist/src/lib/webhook-deliver.js.map +1 -1
  533. package/dist/src/lib/webhook-test-run.d.ts +32 -0
  534. package/dist/src/lib/webhook-test-run.js +108 -0
  535. package/dist/src/lib/webhook-test-run.js.map +1 -0
  536. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  537. package/dist/src/lib/worker-perf-format.js +27 -0
  538. package/dist/src/lib/worker-perf-format.js.map +1 -0
  539. package/dist/src/types/index.d.ts +20 -65
  540. package/dist/src/validators.d.ts +7 -55
  541. package/dist/src/validators.js +7 -53
  542. package/dist/src/validators.js.map +1 -1
  543. package/dist/src/vite.d.ts +17 -0
  544. package/dist/src/vite.js +18 -0
  545. package/dist/src/vite.js.map +1 -0
  546. package/package.json +20 -9
@@ -0,0 +1,340 @@
1
+ /**
2
+ * The hosting control Worker's client for `primitive hosting`: one method
3
+ * per control route, each request sent with the token the provider hands
4
+ * out (a derived `write`-only token, or a CI token as it is), and every
5
+ * refusal turned into a {@link HostingError} carrying the service's code.
6
+ *
7
+ * Requests go out over `node:http`/`node:https`. A host under `localhost`
8
+ * (`hosting-api.localhost:8788`, `<slug>.localhost:8788`) is connected on
9
+ * loopback with its `Host` header kept, because macOS does not resolve
10
+ * subdomains of `localhost`.
11
+ */
12
+ import { createReadStream } from "fs";
13
+ import { request as httpRequest } from "http";
14
+ import { request as httpsRequest } from "https";
15
+ import { HostingError } from "./hosting-errors.js";
16
+ import { DEPLOY_HEADER } from "./hosting-wait.js";
17
+ /** How long one control request may take. */
18
+ const REQUEST_TIMEOUT_MS = 60_000;
19
+ /** How long one origin probe may take. */
20
+ const PROBE_TIMEOUT_MS = 10_000;
21
+ /** Files uploaded at once. */
22
+ export const UPLOAD_CONCURRENCY = 6;
23
+ /** Retries of one upload after a network failure or a 5xx. */
24
+ export const UPLOAD_RETRIES = 3;
25
+ /** Attempts of a create the service answers `create_busy`. */
26
+ export const CREATE_ATTEMPTS = 3;
27
+ /** Attempts of an activation the service answers `activation_in_progress`. */
28
+ export const ACTIVATE_ATTEMPTS = 3;
29
+ /** The header the serve probe sends: a `wfp` origin then answers only once the deployment's own version serves here. */
30
+ export const PROBE_HEADER = "x-primitive-hosting-probe";
31
+ /** The headers of the serve probe (`HEAD <origin>/`). */
32
+ export const PROBE_REQUEST_HEADERS = Object.freeze({ [PROBE_HEADER]: "1" });
33
+ /**
34
+ * Whether an activation that failed with `err` on attempt `attempt` (from 1)
35
+ * is tried again, and after how many milliseconds: only for
36
+ * `activation_in_progress`, after its `retry-after` (5 s when absent or not a
37
+ * number), {@link ACTIVATE_ATTEMPTS} attempts in all; null to give up.
38
+ */
39
+ export function activationRetryDelayMs(err, attempt) {
40
+ if (!(err instanceof HostingError) || err.code !== "activation_in_progress" || attempt >= ACTIVATE_ATTEMPTS)
41
+ return null;
42
+ const after = Number(err.details.retryAfter ?? 5);
43
+ return (Number.isFinite(after) && after >= 0 ? after : 5) * 1000;
44
+ }
45
+ /**
46
+ * One HTTP request. A `*.localhost` host is reached on 127.0.0.1 with its
47
+ * `Host` header kept; one connection per request.
48
+ *
49
+ * @param url The full URL.
50
+ * @param init The method, headers, body and timeout.
51
+ * @returns The answer.
52
+ * @throws The transport's error on a network failure or a timeout.
53
+ */
54
+ export function hostingFetch(url, init) {
55
+ const target = new URL(url);
56
+ const local = target.hostname === "localhost" || target.hostname.endsWith(".localhost");
57
+ const send = target.protocol === "https:" ? httpsRequest : httpRequest;
58
+ const body = init.body;
59
+ const length = body === undefined ? undefined : Buffer.isBuffer(body) ? body.length : body.size;
60
+ const headers = {
61
+ ...(init.headers ?? {}),
62
+ Host: target.host,
63
+ ...(length !== undefined ? { "Content-Length": String(length) } : {}),
64
+ };
65
+ return new Promise((resolve, reject) => {
66
+ let deadline;
67
+ let onAbort;
68
+ const settle = () => {
69
+ if (deadline !== undefined)
70
+ clearTimeout(deadline);
71
+ if (onAbort)
72
+ init.signal?.removeEventListener("abort", onAbort);
73
+ };
74
+ const done = (res) => {
75
+ settle();
76
+ resolve(res);
77
+ };
78
+ const fail = (err) => {
79
+ settle();
80
+ reject(err);
81
+ };
82
+ const req = send({
83
+ host: local ? "127.0.0.1" : target.hostname,
84
+ port: target.port || (target.protocol === "https:" ? 443 : 80),
85
+ path: `${target.pathname}${target.search}`,
86
+ method: init.method,
87
+ headers,
88
+ agent: false,
89
+ ...(target.protocol === "https:" ? { servername: target.hostname } : {}),
90
+ }, (res) => {
91
+ const chunks = [];
92
+ res.on("data", (chunk) => chunks.push(chunk));
93
+ res.on("end", () => done({ status: res.statusCode ?? 0, headers: res.headers, text: Buffer.concat(chunks).toString("utf-8") }));
94
+ res.on("error", fail);
95
+ res.on("aborted", () => fail(new Error("the answer was cut off")));
96
+ });
97
+ const timeoutMs = init.timeoutMs ?? REQUEST_TIMEOUT_MS;
98
+ req.setTimeout(timeoutMs, () => req.destroy(new Error(`no answer within ${timeoutMs / 1000} s`)));
99
+ req.on("error", fail);
100
+ if (init.deadlineMs !== undefined) {
101
+ const deadlineMs = init.deadlineMs;
102
+ deadline = setTimeout(() => req.destroy(new Error(`no answer within ${deadlineMs / 1000} s`)), deadlineMs);
103
+ }
104
+ if (init.signal) {
105
+ if (init.signal.aborted) {
106
+ req.destroy(new Error("aborted"));
107
+ }
108
+ else {
109
+ onAbort = () => req.destroy(new Error("aborted"));
110
+ init.signal.addEventListener("abort", onAbort, { once: true });
111
+ }
112
+ }
113
+ if (body === undefined || Buffer.isBuffer(body)) {
114
+ req.end(body);
115
+ }
116
+ else if (body.size === 0) {
117
+ req.end();
118
+ }
119
+ else {
120
+ const stream = createReadStream(body.file);
121
+ stream.on("error", (err) => req.destroy(err));
122
+ stream.pipe(req);
123
+ }
124
+ });
125
+ }
126
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
127
+ /** The client of one hosting control Worker. */
128
+ export class HostingClient {
129
+ baseUrl;
130
+ tokens;
131
+ canStepUp;
132
+ /**
133
+ * @param baseUrl The control Worker, without a trailing slash.
134
+ * @param tokens Hands out the bearer of each request.
135
+ * @param canStepUp Whether an unexpired step-up that may reach the app is stored.
136
+ */
137
+ constructor(baseUrl, tokens, canStepUp) {
138
+ this.baseUrl = baseUrl;
139
+ this.tokens = tokens;
140
+ this.canStepUp = canStepUp;
141
+ }
142
+ async send(method, path, body, headers = {}) {
143
+ const token = await this.tokens.token();
144
+ try {
145
+ return await hostingFetch(`${this.baseUrl}${path}`, {
146
+ method,
147
+ headers: { Accept: "application/json", Authorization: `Bearer ${token}`, ...headers },
148
+ body: body?.(),
149
+ });
150
+ }
151
+ catch (err) {
152
+ throw new HostingError("hosting_unreachable", `Could not reach the hosting service at ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`);
153
+ }
154
+ }
155
+ parse(response) {
156
+ let body;
157
+ try {
158
+ body = response.text ? JSON.parse(response.text) : {};
159
+ }
160
+ catch {
161
+ body = undefined;
162
+ }
163
+ if (body === undefined || body === null || typeof body !== "object") {
164
+ throw new HostingError("hosting_unreachable", `The hosting service at ${this.baseUrl} answered ${response.status} with a body that is not JSON (a proxy's error page, or not the hosting service).`, response.status);
165
+ }
166
+ if (response.status >= 400) {
167
+ const { error: code, message, ...rest } = body;
168
+ throw new HostingError(typeof code === "string" ? code : "hosting_error", typeof message === "string" ? message : `The hosting service answered ${response.status}.`, response.status, { ...rest, ...(response.headers["retry-after"] ? { retryAfter: response.headers["retry-after"] } : {}) });
169
+ }
170
+ return body;
171
+ }
172
+ /**
173
+ * One control request, answered as JSON. A protected app's refusal of a
174
+ * token derived from the login is retried once with one derived from the
175
+ * stored step-up; when that cannot be derived, the refusal stands.
176
+ */
177
+ async call(method, path, options = {}) {
178
+ const body = options.body ?? (options.json === undefined ? undefined : () => Buffer.from(JSON.stringify(options.json)));
179
+ const headers = { ...(options.json === undefined ? {} : { "Content-Type": "application/json" }), ...(options.headers ?? {}) };
180
+ try {
181
+ return this.parse(await this.send(method, path, body, headers));
182
+ }
183
+ catch (err) {
184
+ if (!(err instanceof HostingError) ||
185
+ err.status !== 403 ||
186
+ err.apiCode !== "PROTECTED_APP_STEP_UP_REQUIRED" ||
187
+ !this.canStepUp ||
188
+ this.tokens.source !== "login") {
189
+ throw err;
190
+ }
191
+ this.tokens.useStepUp();
192
+ try {
193
+ await this.tokens.token();
194
+ }
195
+ catch {
196
+ throw err;
197
+ }
198
+ return this.parse(await this.send(method, path, body, headers));
199
+ }
200
+ }
201
+ /** `GET /apps/:appId`: the app's view, or null when it has no slug. */
202
+ async appView(appId) {
203
+ try {
204
+ return await this.call("GET", `/apps/${encodeURIComponent(appId)}`);
205
+ }
206
+ catch (err) {
207
+ if (err instanceof HostingError && err.code === "no_slug")
208
+ return null;
209
+ throw err;
210
+ }
211
+ }
212
+ /** `POST /apps/:appId/<action>`: a state change, answered with the app's view. */
213
+ change(appId, action, json) {
214
+ return this.call("POST", `/apps/${encodeURIComponent(appId)}/${action}`, json === undefined ? {} : { json });
215
+ }
216
+ /** `GET /apps/:appId/deployments`, newest first. */
217
+ async deployments(appId) {
218
+ const { items } = await this.call("GET", `/apps/${encodeURIComponent(appId)}/deployments`);
219
+ return items
220
+ .map((d) => ({
221
+ deployId: d.deployId,
222
+ createdAt: d.createdAt,
223
+ routingMode: d.routingMode,
224
+ fileCount: d.fileCount,
225
+ totalBytes: d.totalBytes,
226
+ active: d.active,
227
+ supersededAt: d.supersededAt ?? null,
228
+ }))
229
+ .sort((a, b) => (a.createdAt === b.createdAt ? (a.deployId < b.deployId ? 1 : -1) : a.createdAt < b.createdAt ? 1 : -1));
230
+ }
231
+ /**
232
+ * `POST /apps/:appId/deployments`: creates a deployment from the manifest
233
+ * body, retried after `retry-after` while the service answers `create_busy`.
234
+ */
235
+ async createDeployment(appId, body, wait = sleep) {
236
+ for (let attempt = 1;; attempt++) {
237
+ try {
238
+ return await this.call("POST", `/apps/${encodeURIComponent(appId)}/deployments`, {
239
+ body: () => body,
240
+ headers: { "Content-Type": "application/json" },
241
+ });
242
+ }
243
+ catch (err) {
244
+ if (!(err instanceof HostingError) || err.code !== "create_busy" || attempt >= CREATE_ATTEMPTS)
245
+ throw err;
246
+ const after = Number(err.details.retryAfter ?? 30);
247
+ await wait((Number.isFinite(after) && after > 0 ? after : 30) * 1000);
248
+ }
249
+ }
250
+ }
251
+ /**
252
+ * `PUT /apps/:appId/files/:sha256?size=<n>`, streamed from disk, retried
253
+ * up to {@link UPLOAD_RETRIES} times after a network failure or a 5xx.
254
+ */
255
+ async upload(appId, file) {
256
+ let last = null;
257
+ for (let attempt = 0; attempt <= UPLOAD_RETRIES; attempt++) {
258
+ if (attempt > 0)
259
+ await sleep(250 * attempt);
260
+ try {
261
+ await this.call("PUT", `/apps/${encodeURIComponent(appId)}/files/${file.sha256}?size=${file.size}`, {
262
+ body: () => ({ file: file.absolutePath, size: file.size }),
263
+ headers: { "Content-Type": "application/octet-stream" },
264
+ });
265
+ return;
266
+ }
267
+ catch (err) {
268
+ if (!(err instanceof HostingError))
269
+ throw err;
270
+ const retryable = err.code === "hosting_unreachable" || (err.status !== undefined && err.status >= 500);
271
+ if (!retryable)
272
+ throw err;
273
+ last = err;
274
+ }
275
+ }
276
+ throw new HostingError("upload_failed", `Could not upload ${file.path} after ${UPLOAD_RETRIES} retries: ${last.message} Nothing was activated; run the deploy again to upload what is still missing.`, last.status);
277
+ }
278
+ /**
279
+ * `POST /apps/:appId/deployments/:deployId/activate` with no body, answered
280
+ * with the app's view; retried after `retry-after` while another
281
+ * activation of the app is in progress, {@link ACTIVATE_ATTEMPTS} attempts in all.
282
+ */
283
+ async activate(appId, deployId, wait = sleep) {
284
+ for (let attempt = 1;; attempt++) {
285
+ try {
286
+ return await this.call("POST", `/apps/${encodeURIComponent(appId)}/deployments/${encodeURIComponent(deployId)}/activate`);
287
+ }
288
+ catch (err) {
289
+ const delay = activationRetryDelayMs(err, attempt);
290
+ if (delay === null)
291
+ throw err;
292
+ await wait(delay);
293
+ }
294
+ }
295
+ }
296
+ /** `HEAD <origin>/` with the probe header: its status and the deployment id it carried; at most 10 s, or until `signal`. */
297
+ async probe(origin, signal) {
298
+ const res = await hostingFetch(`${origin}/`, { method: "HEAD", headers: { ...PROBE_REQUEST_HEADERS }, deadlineMs: PROBE_TIMEOUT_MS, signal });
299
+ const header = res.headers[DEPLOY_HEADER];
300
+ return { status: res.status, deployId: typeof header === "string" ? header : null };
301
+ }
302
+ }
303
+ /** How long `apps delete` waits on the hosting service. */
304
+ const DELETION_MARK_TIMEOUT_MS = 10_000;
305
+ /**
306
+ * `POST /apps/:appId/deleted`, sent with no token once the API deleted the
307
+ * app: the control Worker checks the API itself and marks the app's
308
+ * hostnames gone, so they answer 410 at once. Never throws.
309
+ *
310
+ * @param hostingUrl The control Worker, without a trailing slash.
311
+ * @param appId The deleted app.
312
+ * @param deadlineMs How long the whole call may take, from before it opens; 10 s by default.
313
+ * @returns `marked`, `no_slug` for an app that never held a slug, or `failed` with why.
314
+ */
315
+ export async function reportAppDeleted(hostingUrl, appId, deadlineMs = DELETION_MARK_TIMEOUT_MS) {
316
+ try {
317
+ const res = await hostingFetch(`${hostingUrl}/apps/${encodeURIComponent(appId)}/deleted`, {
318
+ method: "POST",
319
+ headers: { Accept: "application/json" },
320
+ timeoutMs: deadlineMs,
321
+ deadlineMs,
322
+ });
323
+ if (res.status === 200)
324
+ return { outcome: "marked" };
325
+ let code;
326
+ try {
327
+ code = JSON.parse(res.text)?.error;
328
+ }
329
+ catch {
330
+ code = undefined;
331
+ }
332
+ if (res.status === 404 && code === "no_slug")
333
+ return { outcome: "no_slug" };
334
+ return { outcome: "failed", reason: typeof code === "string" ? `${res.status} ${code}` : `answered ${res.status}` };
335
+ }
336
+ catch (err) {
337
+ return { outcome: "failed", reason: err instanceof Error ? err.message : String(err) };
338
+ }
339
+ }
340
+ //# sourceMappingURL=hosting-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosting-client.js","sourceRoot":"","sources":["../../../src/lib/hosting-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,WAAW,EAA4B,MAAM,MAAM,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAoB,MAAM,mBAAmB,CAAC;AAapE,6CAA6C;AAC7C,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,0CAA0C;AAC1C,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,8BAA8B;AAC9B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,wHAAwH;AACxH,MAAM,CAAC,MAAM,YAAY,GAAG,2BAA2B,CAAC;AAExD,yDAAyD;AACzD,MAAM,CAAC,MAAM,qBAAqB,GAAqC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;AAE9G;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAY,EAAE,OAAe;IAClE,IAAI,CAAC,CAAC,GAAG,YAAY,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,wBAAwB,IAAI,OAAO,IAAI,iBAAiB;QAAE,OAAO,IAAI,CAAC;IACzH,MAAM,KAAK,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C;IACtH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACzF,CAAC;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ /** The variable that names the hosting control Worker directly. */
2
+ export declare const HOSTING_URL_VAR = "PRIMITIVE_HOSTING_URL";
3
+ /**
4
+ * The deployed environments with hosting: each API origin and its control
5
+ * Worker, `https://hosting-api.<domain>`. Kept equal to the deployed rows of
6
+ * `packages/hosting/environments.json` by a unit test.
7
+ */
8
+ export declare const HOSTING_ENVIRONMENTS: ReadonlyArray<{
9
+ readonly apiUrl: string;
10
+ readonly hostingUrl: string;
11
+ }>;
12
+ /**
13
+ * The control Worker's base URL for the API at `apiUrl`, without a trailing
14
+ * slash: `PRIMITIVE_HOSTING_URL` when it is set and not blank, else the
15
+ * deployed environment whose API origin matches, else null (no hosting).
16
+ *
17
+ * @param apiUrl The API the command talks to.
18
+ * @param env The process environment to read `PRIMITIVE_HOSTING_URL` from.
19
+ * @returns The control Worker's URL, or null when this environment has no hosting.
20
+ * @throws HostingError `hosting_url_invalid` when the variable is not an http(s) URL.
21
+ */
22
+ export declare function hostingApiUrl(apiUrl: string, env?: Record<string, string | undefined>): string | null;
23
+ /**
24
+ * The control Worker's URL for `apiUrl`, or the `hosting_not_available`
25
+ * refusal every `hosting` command stops with before any request.
26
+ *
27
+ * @param apiUrl The API the command talks to.
28
+ * @param env The process environment.
29
+ * @returns The control Worker's URL.
30
+ * @throws HostingError `hosting_not_available`, or as {@link hostingApiUrl}.
31
+ */
32
+ export declare function requireHostingApiUrl(apiUrl: string, env?: Record<string, string | undefined>): string;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Where `primitive hosting` finds the hosting control Worker for the API the
3
+ * current environment talks to. Hosting runs in production and on agent;
4
+ * every other environment has none. `PRIMITIVE_HOSTING_URL` names the
5
+ * control Worker instead, which is how a developer reaches a local
6
+ * `wrangler dev` (`http://hosting-api.localhost:<port>`).
7
+ */
8
+ import { HostingError } from "./hosting-errors.js";
9
+ /** The variable that names the hosting control Worker directly. */
10
+ export const HOSTING_URL_VAR = "PRIMITIVE_HOSTING_URL";
11
+ /**
12
+ * The deployed environments with hosting: each API origin and its control
13
+ * Worker, `https://hosting-api.<domain>`. Kept equal to the deployed rows of
14
+ * `packages/hosting/environments.json` by a unit test.
15
+ */
16
+ export const HOSTING_ENVIRONMENTS = [
17
+ { apiUrl: "https://primitiveapi.com", hostingUrl: "https://hosting-api.primitive.app" },
18
+ {
19
+ apiUrl: "https://js-bao-wss-agent.primitive-labs-agents.workers.dev",
20
+ hostingUrl: "https://hosting-api.primitive-agent.app",
21
+ },
22
+ ];
23
+ function origin(url) {
24
+ try {
25
+ return new URL(url).origin;
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
31
+ /**
32
+ * The control Worker's base URL for the API at `apiUrl`, without a trailing
33
+ * slash: `PRIMITIVE_HOSTING_URL` when it is set and not blank, else the
34
+ * deployed environment whose API origin matches, else null (no hosting).
35
+ *
36
+ * @param apiUrl The API the command talks to.
37
+ * @param env The process environment to read `PRIMITIVE_HOSTING_URL` from.
38
+ * @returns The control Worker's URL, or null when this environment has no hosting.
39
+ * @throws HostingError `hosting_url_invalid` when the variable is not an http(s) URL.
40
+ */
41
+ export function hostingApiUrl(apiUrl, env = process.env) {
42
+ const named = env[HOSTING_URL_VAR]?.trim();
43
+ if (named) {
44
+ let parsed = null;
45
+ try {
46
+ parsed = new URL(named);
47
+ }
48
+ catch {
49
+ parsed = null;
50
+ }
51
+ if (!parsed || (parsed.protocol !== "http:" && parsed.protocol !== "https:")) {
52
+ throw new HostingError("hosting_url_invalid", `${HOSTING_URL_VAR} must be an http(s) URL such as http://hosting-api.localhost:8788 (got "${named}").`);
53
+ }
54
+ return named.replace(/\/+$/, "");
55
+ }
56
+ const api = origin(apiUrl);
57
+ return HOSTING_ENVIRONMENTS.find((e) => origin(e.apiUrl) === api)?.hostingUrl ?? null;
58
+ }
59
+ /**
60
+ * The control Worker's URL for `apiUrl`, or the `hosting_not_available`
61
+ * refusal every `hosting` command stops with before any request.
62
+ *
63
+ * @param apiUrl The API the command talks to.
64
+ * @param env The process environment.
65
+ * @returns The control Worker's URL.
66
+ * @throws HostingError `hosting_not_available`, or as {@link hostingApiUrl}.
67
+ */
68
+ export function requireHostingApiUrl(apiUrl, env = process.env) {
69
+ const url = hostingApiUrl(apiUrl, env);
70
+ if (url)
71
+ return url;
72
+ throw new HostingError("hosting_not_available", `hosting is not available in this environment (${apiUrl}). Hosting runs in production and on agent; set ${HOSTING_URL_VAR} to reach another hosting service.`);
73
+ }
74
+ //# sourceMappingURL=hosting-environments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosting-environments.js","sourceRoot":"","sources":["../../../src/lib/hosting-environments.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,mEAAmE;AACnE,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA4E;IAC3G,EAAE,MAAM,EAAE,0BAA0B,EAAE,UAAU,EAAE,mCAAmC,EAAE;IACvF;QACE,MAAM,EAAE,4DAA4D;QACpE,UAAU,EAAE,yCAAyC;KACtD;CACF,CAAC;AAEF,SAAS,MAAM,CAAC,GAAW;IACzB,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,MAA0C,OAAO,CAAC,GAAG;IACjG,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,MAAM,GAAe,IAAI,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,EAAE,CAAC;YAC7E,MAAM,IAAI,YAAY,CACpB,qBAAqB,EACrB,GAAG,eAAe,2EAA2E,KAAK,KAAK,CACxG,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3B,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,UAAU,IAAI,IAAI,CAAC;AACxF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,MAA0C,OAAO,CAAC,GAAG;IACxG,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvC,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IACpB,MAAM,IAAI,YAAY,CACpB,uBAAuB,EACvB,iDAAiD,MAAM,mDAAmD,eAAe,oCAAoC,CAC9J,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The error every `primitive hosting` step throws: a snake_case `code` in the
3
+ * hosting service's own vocabulary, the HTTP status when the service or the
4
+ * API answered one, and the fields a caller may want to print or assert.
5
+ */
6
+ export declare class HostingError extends Error {
7
+ readonly code: string;
8
+ readonly status?: number;
9
+ readonly details: Record<string, unknown>;
10
+ /**
11
+ * @param code The refusal's code: the service's `error` (`no_slug`,
12
+ * `slug_taken`) or one of the CLI's own (`slug_required`,
13
+ * `activation_timeout`).
14
+ * @param message What happened and what to do, never a token.
15
+ * @param status The HTTP status that carried the refusal, when there was one.
16
+ * @param details The answer's other fields: the API's `code` when the
17
+ * service passed one through, the last probe answer of a wait.
18
+ */
19
+ constructor(code: string, message: string, status?: number, details?: Record<string, unknown>);
20
+ /** The API's own code the service passed through (`PROTECTED_APP_STEP_UP_REQUIRED`), when there was one. */
21
+ get apiCode(): string | undefined;
22
+ }
23
+ /**
24
+ * A refusal as the CLI prints it: the message, then the code in parentheses,
25
+ * and the API's own code beside it when the service passed one through.
26
+ *
27
+ * @param err The refusal.
28
+ * @returns One line for stderr.
29
+ */
30
+ export declare function describeHostingError(err: HostingError): string;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The error every `primitive hosting` step throws: a snake_case `code` in the
3
+ * hosting service's own vocabulary, the HTTP status when the service or the
4
+ * API answered one, and the fields a caller may want to print or assert.
5
+ */
6
+ export class HostingError extends Error {
7
+ code;
8
+ status;
9
+ details;
10
+ /**
11
+ * @param code The refusal's code: the service's `error` (`no_slug`,
12
+ * `slug_taken`) or one of the CLI's own (`slug_required`,
13
+ * `activation_timeout`).
14
+ * @param message What happened and what to do, never a token.
15
+ * @param status The HTTP status that carried the refusal, when there was one.
16
+ * @param details The answer's other fields: the API's `code` when the
17
+ * service passed one through, the last probe answer of a wait.
18
+ */
19
+ constructor(code, message, status, details = {}) {
20
+ super(message);
21
+ this.code = code;
22
+ this.status = status;
23
+ this.details = details;
24
+ this.name = "HostingError";
25
+ }
26
+ /** The API's own code the service passed through (`PROTECTED_APP_STEP_UP_REQUIRED`), when there was one. */
27
+ get apiCode() {
28
+ const code = this.details.code;
29
+ return typeof code === "string" ? code : undefined;
30
+ }
31
+ }
32
+ /**
33
+ * A refusal as the CLI prints it: the message, then the code in parentheses,
34
+ * and the API's own code beside it when the service passed one through.
35
+ *
36
+ * @param err The refusal.
37
+ * @returns One line for stderr.
38
+ */
39
+ export function describeHostingError(err) {
40
+ const codes = [err.code, err.apiCode].filter((c, i, all) => Boolean(c) && all.indexOf(c) === i);
41
+ return `${err.message} (${codes.join(", ")})`;
42
+ }
43
+ //# sourceMappingURL=hosting-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosting-errors.js","sourceRoot":"","sources":["../../../src/lib/hosting-errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAW1B;IAEA;IACA;IAbX;;;;;;;;OAQG;IACH,YACW,IAAY,EACrB,OAAe,EACN,MAAe,EACf,UAAmC,EAAE;QAE9C,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAS;QACf,YAAO,GAAP,OAAO,CAA8B;QAG9C,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;IAED,4GAA4G;IAC5G,IAAI,OAAO;QACT,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QAC/B,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAiB;IACpD,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAe,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7G,OAAO,GAAG,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAChD,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The token `primitive hosting` sends to the hosting service. A login is
3
+ * never sent: the provider derives a short-lived `write`-only token from it
4
+ * (or, on a protected app, from the stored step-up) and derives again before
5
+ * that one runs out. A CI token cannot derive, so it is sent as it is.
6
+ */
7
+ /** Derive again once less than this much of a token's life remains. */
8
+ export declare const REDERIVE_MARGIN_MS: number;
9
+ /** Where a derived token comes from: the login, or the stored step-up. */
10
+ export type TokenSource = "login" | "step-up";
11
+ /** A derived token and when it expires (ISO 8601). */
12
+ export interface DerivedToken {
13
+ accessToken: string;
14
+ expiresAt: string;
15
+ }
16
+ /** What {@link HostingTokenProvider} needs. */
17
+ export interface TokenProviderOptions {
18
+ /** Derives a `write`-only token from the login or the step-up. */
19
+ derive: (from: TokenSource) => Promise<DerivedToken>;
20
+ /** A CI token to send unchanged instead of deriving. */
21
+ ciToken?: string | null;
22
+ /** The clock; `Date.now` by default. */
23
+ now?: () => number;
24
+ }
25
+ /** Hands out the bearer for each hosting request. */
26
+ export declare class HostingTokenProvider {
27
+ private readonly options;
28
+ private current;
29
+ private pending;
30
+ private from;
31
+ private readonly now;
32
+ /** @param options How to derive, the CI token if any, and the clock. */
33
+ constructor(options: TokenProviderOptions);
34
+ /** `ci` for a CI token, else where the next derived token comes from. */
35
+ get source(): "ci" | TokenSource;
36
+ /**
37
+ * The bearer for the next request: the CI token, or a derived token with
38
+ * more than {@link REDERIVE_MARGIN_MS} of life left, derived now if needed.
39
+ *
40
+ * @returns The token, without the `Bearer ` prefix.
41
+ * @throws Whatever the derivation throws (the API's refusal).
42
+ */
43
+ token(): Promise<string>;
44
+ /** Derive from the stored step-up from now on, dropping the login's token. */
45
+ useStepUp(): void;
46
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The token `primitive hosting` sends to the hosting service. A login is
3
+ * never sent: the provider derives a short-lived `write`-only token from it
4
+ * (or, on a protected app, from the stored step-up) and derives again before
5
+ * that one runs out. A CI token cannot derive, so it is sent as it is.
6
+ */
7
+ /** Derive again once less than this much of a token's life remains. */
8
+ export const REDERIVE_MARGIN_MS = 2 * 60_000;
9
+ /** Hands out the bearer for each hosting request. */
10
+ export class HostingTokenProvider {
11
+ options;
12
+ current = null;
13
+ pending = null;
14
+ from = "login";
15
+ now;
16
+ /** @param options How to derive, the CI token if any, and the clock. */
17
+ constructor(options) {
18
+ this.options = options;
19
+ this.now = options.now ?? Date.now;
20
+ }
21
+ /** `ci` for a CI token, else where the next derived token comes from. */
22
+ get source() {
23
+ return this.options.ciToken ? "ci" : this.from;
24
+ }
25
+ /**
26
+ * The bearer for the next request: the CI token, or a derived token with
27
+ * more than {@link REDERIVE_MARGIN_MS} of life left, derived now if needed.
28
+ *
29
+ * @returns The token, without the `Bearer ` prefix.
30
+ * @throws Whatever the derivation throws (the API's refusal).
31
+ */
32
+ async token() {
33
+ if (this.options.ciToken)
34
+ return this.options.ciToken;
35
+ if (this.current && new Date(this.current.expiresAt).getTime() - this.now() >= REDERIVE_MARGIN_MS) {
36
+ return this.current.accessToken;
37
+ }
38
+ if (!this.pending) {
39
+ const from = this.from;
40
+ this.pending = this.options
41
+ .derive(from)
42
+ .then((derived) => {
43
+ if (this.from === from)
44
+ this.current = derived;
45
+ return derived;
46
+ })
47
+ .finally(() => {
48
+ this.pending = null;
49
+ });
50
+ }
51
+ return (await this.pending).accessToken;
52
+ }
53
+ /** Derive from the stored step-up from now on, dropping the login's token. */
54
+ useStepUp() {
55
+ this.from = "step-up";
56
+ this.current = null;
57
+ this.pending = null;
58
+ }
59
+ }
60
+ //# sourceMappingURL=hosting-token.js.map