@superpanel-sdk/runtime 0.2.2 → 0.5.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 (274) hide show
  1. package/README.md +28 -8
  2. package/dist/builder/codegen/emit.d.ts +29 -11
  3. package/dist/builder/codegen/emit.js +328 -61
  4. package/dist/builder/codegen/generate.d.ts +21 -0
  5. package/dist/builder/codegen/generate.js +152 -20
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +24 -0
  9. package/dist/builder/company-imports.js +114 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +59 -8
  11. package/dist/builder/compile/compile-sequence.js +279 -77
  12. package/dist/builder/compile/function-code.d.ts +12 -2
  13. package/dist/builder/compile/function-code.js +87 -39
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +24 -23
  16. package/dist/builder/load.d.ts +70 -10
  17. package/dist/builder/load.js +250 -61
  18. package/dist/builder/paths.d.ts +3 -0
  19. package/dist/builder/paths.js +16 -0
  20. package/dist/builder/schedules.d.ts +23 -0
  21. package/dist/builder/schedules.js +102 -0
  22. package/dist/builder/slot-schema-validation.d.ts +4 -0
  23. package/dist/builder/slot-schema-validation.js +10 -0
  24. package/dist/builder/typecheck.d.ts +8 -0
  25. package/dist/builder/typecheck.js +105 -0
  26. package/dist/builder/types.d.ts +91 -19
  27. package/dist/builder/types.js +2 -1
  28. package/dist/cli/auth/auth.d.ts +37 -0
  29. package/dist/cli/auth/auth.js +211 -0
  30. package/dist/cli/auth/backend-url.d.ts +5 -0
  31. package/dist/cli/auth/backend-url.js +25 -0
  32. package/dist/cli/auth/clipboard.d.ts +9 -0
  33. package/dist/cli/auth/clipboard.js +38 -0
  34. package/dist/cli/auth/http.d.ts +20 -0
  35. package/dist/cli/auth/http.js +27 -0
  36. package/dist/cli/auth/index.d.ts +10 -0
  37. package/dist/cli/auth/index.js +27 -0
  38. package/dist/cli/auth/progress.d.ts +12 -0
  39. package/dist/cli/auth/progress.js +15 -0
  40. package/dist/cli/auth/serve-login.d.ts +8 -0
  41. package/dist/cli/auth/serve-login.js +24 -0
  42. package/dist/cli/compile/index.js +3 -0
  43. package/dist/cli/config.d.ts +10 -0
  44. package/dist/cli/config.js +52 -0
  45. package/dist/cli/index.js +28 -8
  46. package/dist/cli/serve/index.d.ts +73 -3
  47. package/dist/cli/serve/index.js +410 -113
  48. package/dist/cli/type-gen/index.js +9 -8
  49. package/dist/compiler.d.ts +7 -0
  50. package/dist/compiler.js +7 -0
  51. package/dist/compute-host/compute-host.d.ts +15 -23
  52. package/dist/compute-host/compute-host.js +25 -28
  53. package/dist/compute-host/index.d.ts +2 -2
  54. package/dist/compute-host/index.js +1 -1
  55. package/dist/compute-host/source-compute-host.d.ts +11 -9
  56. package/dist/compute-host/source-compute-host.js +50 -31
  57. package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
  58. package/dist/core/case-orchestrator/contact-hours.js +108 -0
  59. package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
  60. package/dist/core/case-orchestrator/follow-ups.js +103 -0
  61. package/dist/core/case-orchestrator/index.d.ts +6 -0
  62. package/dist/core/case-orchestrator/index.js +6 -0
  63. package/dist/core/case-orchestrator/render.d.ts +75 -0
  64. package/dist/core/case-orchestrator/render.js +239 -0
  65. package/dist/core/case-orchestrator/time.d.ts +11 -0
  66. package/dist/core/case-orchestrator/time.js +29 -0
  67. package/dist/core/case-orchestrator/tools.d.ts +29 -0
  68. package/dist/core/case-orchestrator/tools.js +31 -0
  69. package/dist/core/case-orchestrator/types.d.ts +753 -0
  70. package/dist/core/case-orchestrator/types.js +46 -0
  71. package/dist/core/case-orchestrator/validate.d.ts +11 -0
  72. package/dist/core/case-orchestrator/validate.js +63 -0
  73. package/dist/core/context/call.d.ts +291 -0
  74. package/dist/core/context/call.js +94 -0
  75. package/dist/core/context/channels.d.ts +60 -0
  76. package/dist/core/context/channels.js +35 -0
  77. package/dist/core/context/contact.d.ts +96 -6
  78. package/dist/core/context/contact.js +48 -2
  79. package/dist/core/context/email-message.d.ts +159 -0
  80. package/dist/core/context/email-message.js +59 -0
  81. package/dist/core/context/email.d.ts +97 -0
  82. package/dist/core/context/email.js +91 -0
  83. package/dist/core/context/exchanges.d.ts +142 -0
  84. package/dist/core/context/exchanges.js +63 -0
  85. package/dist/core/context/instances.d.ts +278 -0
  86. package/dist/core/context/instances.js +123 -0
  87. package/dist/core/context/kv.d.ts +113 -0
  88. package/dist/core/context/kv.js +60 -0
  89. package/dist/core/context/platform-registry.d.ts +509 -4
  90. package/dist/core/context/platform-registry.js +14 -2
  91. package/dist/core/context/platform.d.ts +2 -1
  92. package/dist/core/context/sms.d.ts +147 -0
  93. package/dist/core/context/sms.js +57 -0
  94. package/dist/core/context/types.d.ts +51 -30
  95. package/dist/core/context/types.js +1 -7
  96. package/dist/core/conversation/index.d.ts +31 -0
  97. package/dist/core/conversation/index.js +14 -0
  98. package/dist/core/functions/define/bind.d.ts +25 -0
  99. package/dist/core/functions/define/bind.js +14 -0
  100. package/dist/core/functions/define/case.d.ts +9 -0
  101. package/dist/core/functions/define/case.js +13 -0
  102. package/dist/core/functions/define/events.d.ts +20 -0
  103. package/dist/core/functions/define/events.js +21 -0
  104. package/dist/core/functions/define/no-case.d.ts +4 -0
  105. package/dist/core/functions/define/no-case.js +9 -0
  106. package/dist/core/functions/events.d.ts +247 -0
  107. package/dist/core/functions/events.js +32 -0
  108. package/dist/core/functions/func-ref.d.ts +11 -2
  109. package/dist/core/functions/schedules.d.ts +51 -0
  110. package/dist/core/functions/schedules.js +20 -0
  111. package/dist/core/functions/types.d.ts +62 -51
  112. package/dist/core/functions/types.js +6 -1
  113. package/dist/core/office-hours/index.d.ts +39 -0
  114. package/dist/core/office-hours/index.js +187 -0
  115. package/dist/core/page/define.d.ts +834 -0
  116. package/dist/core/page/define.js +477 -0
  117. package/dist/core/page/ops.d.ts +58 -0
  118. package/dist/core/page/ops.js +220 -0
  119. package/dist/core/page/render.d.ts +253 -0
  120. package/dist/core/page/render.js +840 -0
  121. package/dist/core/page/time-format.d.ts +19 -0
  122. package/dist/core/page/time-format.js +41 -0
  123. package/dist/core/page/timeline.d.ts +40 -0
  124. package/dist/core/page/timeline.js +2 -0
  125. package/dist/core/page/typed.d.ts +642 -0
  126. package/dist/core/page/typed.js +2 -0
  127. package/dist/core/page/workspace.d.ts +33 -0
  128. package/dist/core/page/workspace.js +231 -0
  129. package/dist/core/party/index.d.ts +3 -0
  130. package/dist/core/party/index.js +3 -0
  131. package/dist/core/party/schema.d.ts +137 -0
  132. package/dist/core/party/schema.js +80 -0
  133. package/dist/core/party/types.d.ts +40 -0
  134. package/dist/core/party/types.js +15 -0
  135. package/dist/core/sequence/define.d.ts +57 -0
  136. package/dist/core/sequence/define.js +10 -0
  137. package/dist/core/sequence/index.d.ts +63 -0
  138. package/dist/core/sequence/index.js +231 -0
  139. package/dist/core/slot/binding.d.ts +40 -0
  140. package/dist/core/slot/binding.js +2 -0
  141. package/dist/core/slot/company-metadata.d.ts +113 -0
  142. package/dist/core/slot/company-metadata.js +563 -0
  143. package/dist/core/slot/compile-schema.d.ts +19 -13
  144. package/dist/core/slot/compile-schema.js +51 -248
  145. package/dist/core/slot/contact-timezone.d.ts +110 -0
  146. package/dist/core/slot/contact-timezone.js +186 -0
  147. package/dist/core/slot/field.d.ts +2 -24
  148. package/dist/core/slot/field.js +0 -69
  149. package/dist/core/slot/id-ref.d.ts +17 -2
  150. package/dist/core/slot/id-ref.js +16 -8
  151. package/dist/core/slot/index.d.ts +12 -13
  152. package/dist/core/slot/index.js +11 -12
  153. package/dist/core/slot/naming.d.ts +15 -0
  154. package/dist/core/slot/naming.js +96 -0
  155. package/dist/core/slot/platform-fields.d.ts +119 -0
  156. package/dist/core/slot/platform-fields.js +121 -0
  157. package/dist/core/slot/ref.d.ts +16 -0
  158. package/dist/core/slot/ref.js +14 -0
  159. package/dist/core/slot/row.d.ts +2 -9
  160. package/dist/core/slot/row.js +13 -23
  161. package/dist/core/slot/schema-compat.d.ts +16 -0
  162. package/dist/core/slot/schema-compat.js +112 -0
  163. package/dist/core/slot/schema.d.ts +409 -76
  164. package/dist/core/slot/schema.js +178 -10
  165. package/dist/core/slot/types.d.ts +27 -92
  166. package/dist/core/slot/value.d.ts +26 -3
  167. package/dist/core/slot/value.js +89 -57
  168. package/dist/dev-overlay/protocol.d.ts +41 -8
  169. package/dist/fn-context/build-context.d.ts +3 -1
  170. package/dist/fn-context/build-context.js +20 -10
  171. package/dist/fn-context/fake/empty-api.js +9 -28
  172. package/dist/fn-context/fake/index.d.ts +11 -4
  173. package/dist/fn-context/fake/index.js +27 -2
  174. package/dist/fn-context/fn-params.d.ts +6 -0
  175. package/dist/fn-context/fn-params.js +13 -0
  176. package/dist/fn-context/index.d.ts +5 -5
  177. package/dist/fn-context/index.js +4 -4
  178. package/dist/fn-context/log.js +2 -2
  179. package/dist/fn-context/make-ctx.d.ts +11 -0
  180. package/dist/fn-context/make-ctx.js +18 -8
  181. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
  182. package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
  183. package/dist/fn-context/rpc/index.d.ts +3 -1
  184. package/dist/fn-context/rpc/index.js +3 -1
  185. package/dist/fn-context/rpc/integration/index.d.ts +4 -4
  186. package/dist/fn-context/rpc/integration/index.js +1 -1
  187. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  188. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  189. package/dist/fn-context/rpc/platform.d.ts +2 -2
  190. package/dist/fn-context/rpc/platform.js +1 -1
  191. package/dist/fn-context/rpc/records.d.ts +78 -0
  192. package/dist/fn-context/rpc/records.js +26 -0
  193. package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
  194. package/dist/fn-context/rpc/trpc-client.js +89 -5
  195. package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
  196. package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
  197. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  198. package/dist/fn-context/run-scope.d.ts +4 -0
  199. package/dist/fn-context/run-scope.js +9 -0
  200. package/dist/fn-context/types.d.ts +36 -3
  201. package/dist/index.d.ts +37 -46
  202. package/dist/index.js +33 -33
  203. package/dist/logger.d.ts +7 -0
  204. package/dist/logger.js +41 -0
  205. package/dist/platform.d.ts +76 -0
  206. package/dist/platform.js +56 -0
  207. package/dist/voice-service/actions.d.ts +71 -4
  208. package/dist/voice-service/types.d.ts +42 -2
  209. package/dist/worker.d.ts +10 -0
  210. package/dist/worker.js +10 -0
  211. package/package.json +38 -19
  212. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  213. package/dist/builder/compile/compile-agenda.js +0 -59
  214. package/dist/builder/merge.d.ts +0 -4
  215. package/dist/builder/merge.js +0 -19
  216. package/dist/core/context/db.d.ts +0 -69
  217. package/dist/core/context/db.js +0 -44
  218. package/dist/core/context/docusign.d.ts +0 -134
  219. package/dist/core/context/docusign.js +0 -108
  220. package/dist/core/context/filevine.d.ts +0 -323
  221. package/dist/core/context/filevine.js +0 -254
  222. package/dist/core/context/http.d.ts +0 -9
  223. package/dist/core/context/http.js +0 -4
  224. package/dist/core/context/hubspot.d.ts +0 -250
  225. package/dist/core/context/hubspot.js +0 -191
  226. package/dist/core/context/twilio.d.ts +0 -50
  227. package/dist/core/context/twilio.js +0 -42
  228. package/dist/core/functions/define/case-context.d.ts +0 -14
  229. package/dist/core/functions/define/case-context.js +0 -15
  230. package/dist/core/functions/define/compute.d.ts +0 -7
  231. package/dist/core/functions/define/compute.js +0 -17
  232. package/dist/core/functions/define/custom.d.ts +0 -4
  233. package/dist/core/functions/define/custom.js +0 -8
  234. package/dist/core/functions/define/system.d.ts +0 -7
  235. package/dist/core/functions/define/system.js +0 -12
  236. package/dist/core/slot/deps.d.ts +0 -15
  237. package/dist/core/slot/deps.js +0 -88
  238. package/dist/core/slot/derived.d.ts +0 -32
  239. package/dist/core/slot/derived.js +0 -115
  240. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  241. package/dist/core/slot/platform-session-fields.js +0 -48
  242. package/dist/core/slot/sf-schema.d.ts +0 -23
  243. package/dist/core/slot/sf-schema.js +0 -125
  244. package/dist/core/slot/sf-validate.d.ts +0 -14
  245. package/dist/core/slot/sf-validate.js +0 -132
  246. package/dist/core/slot/snapshot.d.ts +0 -18
  247. package/dist/core/slot/snapshot.js +0 -138
  248. package/dist/core/slot/write.d.ts +0 -41
  249. package/dist/core/slot/write.js +0 -319
  250. package/dist/core/stage/builders.d.ts +0 -36
  251. package/dist/core/stage/builders.js +0 -28
  252. package/dist/core/stage/condition.d.ts +0 -17
  253. package/dist/core/stage/condition.js +0 -198
  254. package/dist/core/stage/drive.d.ts +0 -43
  255. package/dist/core/stage/drive.js +0 -77
  256. package/dist/core/stage/finish-when.d.ts +0 -20
  257. package/dist/core/stage/finish-when.js +0 -82
  258. package/dist/core/stage/flatten.d.ts +0 -27
  259. package/dist/core/stage/flatten.js +0 -464
  260. package/dist/core/stage/index.d.ts +0 -11
  261. package/dist/core/stage/index.js +0 -10
  262. package/dist/core/stage/simulate.d.ts +0 -24
  263. package/dist/core/stage/simulate.js +0 -33
  264. package/dist/core/stage/transfer-fields.d.ts +0 -14
  265. package/dist/core/stage/transfer-fields.js +0 -88
  266. package/dist/core/stage/types.d.ts +0 -177
  267. package/dist/core/stage/types.js +0 -2
  268. package/dist/core/stage/validate.d.ts +0 -11
  269. package/dist/core/stage/validate.js +0 -226
  270. package/dist/core/stage/walk.d.ts +0 -34
  271. package/dist/core/stage/walk.js +0 -96
  272. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  273. package/dist/fn-context/system-args.d.ts +0 -6
  274. package/dist/fn-context/system-args.js +0 -14
@@ -0,0 +1,38 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ /** Native clipboard commands, in preference order for the current platform. */
3
+ export function clipboardCommands(platform) {
4
+ switch (platform) {
5
+ case 'darwin':
6
+ return [{ file: 'pbcopy', args: [] }];
7
+ case 'win32':
8
+ return [{ file: 'clip.exe', args: [] }];
9
+ case 'linux':
10
+ return [
11
+ { file: 'wl-copy', args: [] },
12
+ { file: 'xclip', args: ['-selection', 'clipboard'] },
13
+ { file: 'xsel', args: ['--clipboard', '--input'] },
14
+ ];
15
+ default:
16
+ return [];
17
+ }
18
+ }
19
+ /** Copy text without invoking a shell, so an authorization URL is always treated as plain input. */
20
+ export function copyToClipboard(text, platform = process.platform) {
21
+ const commands = clipboardCommands(platform);
22
+ if (commands.length === 0)
23
+ throw new Error(`clipboard copy is not supported on ${platform}`);
24
+ const failures = [];
25
+ for (const command of commands) {
26
+ const result = spawnSync(command.file, command.args, {
27
+ input: text,
28
+ encoding: 'utf8',
29
+ stdio: ['pipe', 'ignore', 'pipe'],
30
+ });
31
+ if (!result.error && result.status === 0)
32
+ return;
33
+ const detail = result.error?.message ?? (result.stderr.trim() || `exit ${result.status}`);
34
+ failures.push(`${command.file}: ${detail}`);
35
+ }
36
+ throw new Error(failures.join('; '));
37
+ }
38
+ //# sourceMappingURL=clipboard.js.map
@@ -0,0 +1,20 @@
1
+ export declare function apiUrl(backendUrl: string, path: string): string;
2
+ export declare function requestJson<T>(url: string, init: RequestInit): Promise<{
3
+ response: Response;
4
+ payload: T & {
5
+ error?: string;
6
+ };
7
+ }>;
8
+ export declare function postJson<T>(url: string, body: unknown): Promise<{
9
+ response: Response;
10
+ payload: T & {
11
+ error?: string;
12
+ };
13
+ }>;
14
+ export declare function getJson<T>(url: string, token: string): Promise<{
15
+ response: Response;
16
+ payload: T & {
17
+ error?: string;
18
+ };
19
+ }>;
20
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { toHttpUrl } from './backend-url.js';
2
+ export function apiUrl(backendUrl, path) {
3
+ const url = toHttpUrl(backendUrl);
4
+ url.pathname = `/api/${path.replace(/^\//, '')}`;
5
+ url.search = '';
6
+ url.hash = '';
7
+ return url.toString();
8
+ }
9
+ export async function requestJson(url, init) {
10
+ const response = await fetch(url, { ...init, signal: AbortSignal.timeout(15_000) });
11
+ const payload = (await response.json().catch(() => ({})));
12
+ return { response, payload };
13
+ }
14
+ export async function postJson(url, body) {
15
+ return requestJson(url, {
16
+ method: 'POST',
17
+ headers: { 'Content-Type': 'application/json' },
18
+ body: JSON.stringify(body),
19
+ });
20
+ }
21
+ export async function getJson(url, token) {
22
+ return requestJson(url, {
23
+ method: 'GET',
24
+ headers: { Authorization: `Bearer ${token}` },
25
+ });
26
+ }
27
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1,10 @@
1
+ export declare function runLogin(repoRoot: string, options: {
2
+ url?: string;
3
+ }): Promise<void>;
4
+ export declare function runLogout(repoRoot: string, options: {
5
+ url?: string;
6
+ }): Promise<void>;
7
+ export declare function runWhoami(repoRoot: string, options: {
8
+ url?: string;
9
+ }): Promise<void>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { authorizeServe, cacheServeAuthorization, readServeAuthorizationStatus, removeCachedServeAuthorization, resolveBackendUrl, } from './auth.js';
2
+ export async function runLogin(repoRoot, options) {
3
+ const backendUrl = resolveBackendUrl(repoRoot, options.url);
4
+ const authorization = await authorizeServe(backendUrl);
5
+ await cacheServeAuthorization(backendUrl, authorization);
6
+ console.log(`Logged in as ${authorization.user.email}`);
7
+ }
8
+ export async function runLogout(repoRoot, options) {
9
+ const backendUrl = resolveBackendUrl(repoRoot, options.url);
10
+ const removed = await removeCachedServeAuthorization(backendUrl);
11
+ console.log(removed ? `Logged out of ${backendUrl}` : `Not logged in to ${backendUrl}`);
12
+ }
13
+ export async function runWhoami(repoRoot, options) {
14
+ const backendUrl = resolveBackendUrl(repoRoot, options.url);
15
+ const status = await readServeAuthorizationStatus(backendUrl);
16
+ if (!status.loggedIn) {
17
+ console.log(`Not logged in to ${backendUrl}`);
18
+ return;
19
+ }
20
+ console.log(`Backend: ${backendUrl}`);
21
+ console.log(`User: ${status.authorization.user.email}`);
22
+ console.log(`Company: ${status.authorization.companyId}`);
23
+ console.log(status.expired
24
+ ? `Session: expired at ${new Date(status.expiresAt).toISOString()} (run "login" again)`
25
+ : `Session: valid until ${new Date(status.expiresAt).toISOString()}`);
26
+ }
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ export type ProgressIndicator = {
2
+ start(message: string): void;
3
+ stop(message: string): void;
4
+ error(message: string): void;
5
+ };
6
+ /**
7
+ * A spinner on an interactive terminal; a single echoed start message otherwise. `stop`/`error`
8
+ * are spinner-only cosmetic detail — dropped silently when there's no spinner, since the CLI's
9
+ * top-level handler already prints failures for non-interactive runs.
10
+ */
11
+ export declare function progressIndicator(): ProgressIndicator;
12
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { spinner } from '@clack/prompts';
2
+ /**
3
+ * A spinner on an interactive terminal; a single echoed start message otherwise. `stop`/`error`
4
+ * are spinner-only cosmetic detail — dropped silently when there's no spinner, since the CLI's
5
+ * top-level handler already prints failures for non-interactive runs.
6
+ */
7
+ export function progressIndicator() {
8
+ const s = process.stdout.isTTY === true ? spinner() : null;
9
+ return {
10
+ start: (message) => (s ? s.start(message) : console.log(message)),
11
+ stop: (message) => s?.stop(message),
12
+ error: (message) => s?.error(message),
13
+ };
14
+ }
15
+ //# sourceMappingURL=progress.js.map
@@ -0,0 +1,8 @@
1
+ import { type ServeAuthorization } from './auth.js';
2
+ /** A fresh browser login, cached for the next run (a cache write failure only warns). */
3
+ export declare function loginServe(backendUrl: string, options?: {
4
+ openBrowser?: boolean;
5
+ }): Promise<ServeAuthorization>;
6
+ /** Drops a token the backend rejected from the cache, so the next run logs in again. */
7
+ export declare function forgetServeAuthorization(backendUrl: string, authorization: ServeAuthorization): Promise<void>;
8
+ //# sourceMappingURL=serve-login.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { getLogger } from '../../logger.js';
2
+ import { authorizeServe, cacheServeAuthorization, clearCachedServeAuthorization, } from './auth.js';
3
+ const logger = getLogger(['runtime', 'auth']);
4
+ /** A fresh browser login, cached for the next run (a cache write failure only warns). */
5
+ export async function loginServe(backendUrl, options = {}) {
6
+ const authorization = await authorizeServe(backendUrl, options);
7
+ try {
8
+ await cacheServeAuthorization(backendUrl, authorization);
9
+ }
10
+ catch (error) {
11
+ logger.warn('could not cache serve authorization', error);
12
+ }
13
+ return authorization;
14
+ }
15
+ /** Drops a token the backend rejected from the cache, so the next run logs in again. */
16
+ export async function forgetServeAuthorization(backendUrl, authorization) {
17
+ try {
18
+ await clearCachedServeAuthorization(backendUrl, authorization.token);
19
+ }
20
+ catch (error) {
21
+ logger.warn('could not clear cached serve authorization', error);
22
+ }
23
+ }
24
+ //# sourceMappingURL=serve-login.js.map
@@ -1,6 +1,9 @@
1
1
  import path from 'node:path';
2
2
  import { compileAll } from '../../builder/compile/compile-sequence.js';
3
+ import { typecheckRepo } from '../../builder/typecheck.js';
3
4
  export async function runCompile(repoRoot, options = {}) {
5
+ // The same type check as a release, before any build is written: a type error blocks both.
6
+ await typecheckRepo(repoRoot, (text) => console.log(text));
4
7
  const results = await compileAll(repoRoot, {
5
8
  sequenceIds: options.sequenceId ? [options.sequenceId] : undefined,
6
9
  });
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod';
2
+ export declare const COMPANY_REPO_CONFIG_PATH = ".superpanel/config.json";
3
+ declare const companyRepoConfigSchema: z.ZodObject<{
4
+ version: z.ZodLiteral<1>;
5
+ backendUrl: z.ZodString;
6
+ }, z.core.$strict>;
7
+ export type CompanyRepoConfig = z.infer<typeof companyRepoConfigSchema>;
8
+ export declare function readCompanyRepoConfig(repoRoot: string): CompanyRepoConfig | undefined;
9
+ export {};
10
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { z } from 'zod';
4
+ import { toHttpUrl } from './auth/backend-url.js';
5
+ export const COMPANY_REPO_CONFIG_PATH = '.superpanel/config.json';
6
+ const companyRepoConfigSchema = z
7
+ .object({
8
+ version: z.literal(1),
9
+ backendUrl: z
10
+ .string()
11
+ .trim()
12
+ .min(1)
13
+ .refine((value) => {
14
+ try {
15
+ toHttpUrl(value);
16
+ return true;
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ }, 'must be a valid HTTP or HTTPS URL'),
22
+ })
23
+ .strict();
24
+ export function readCompanyRepoConfig(repoRoot) {
25
+ const file = path.join(repoRoot, COMPANY_REPO_CONFIG_PATH);
26
+ let raw;
27
+ try {
28
+ raw = readFileSync(file, 'utf8');
29
+ }
30
+ catch (error) {
31
+ const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
32
+ if (code === 'ENOENT')
33
+ return undefined;
34
+ throw error;
35
+ }
36
+ let value;
37
+ try {
38
+ value = JSON.parse(raw);
39
+ }
40
+ catch {
41
+ throw new Error(`${COMPANY_REPO_CONFIG_PATH} is not valid JSON`);
42
+ }
43
+ const result = companyRepoConfigSchema.safeParse(value);
44
+ if (!result.success) {
45
+ const details = result.error.issues
46
+ .map((issue) => `${issue.path.join('.') || 'config'}: ${issue.message}`)
47
+ .join('; ');
48
+ throw new Error(`${COMPANY_REPO_CONFIG_PATH} has an invalid Superpanel configuration (${details})`);
49
+ }
50
+ return result.data;
51
+ }
52
+ //# sourceMappingURL=config.js.map
package/dist/cli/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { existsSync } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { Command } from 'commander';
5
+ import { runLogin, runLogout, runWhoami } from './auth/index.js';
5
6
  import { runCompile } from './compile/index.js';
6
7
  import { runServe } from './serve/index.js';
7
8
  import { runTypeGen } from './type-gen/index.js';
@@ -35,19 +36,38 @@ program
35
36
  .action(async (options) => {
36
37
  await runCompile(process.cwd(), { sequenceId: options.sequence });
37
38
  });
39
+ program
40
+ .command('login')
41
+ .description('Authorize Local Serve and cache the credential')
42
+ .option('--url <url>', 'Backend host URL')
43
+ .action(async (options) => {
44
+ await runLogin(process.cwd(), options);
45
+ });
46
+ program
47
+ .command('logout')
48
+ .description('Clear the cached Local Serve credential')
49
+ .option('--url <url>', 'Backend host URL')
50
+ .action(async (options) => {
51
+ await runLogout(process.cwd(), options);
52
+ });
53
+ program
54
+ .command('whoami')
55
+ .description('Show the cached Local Serve login')
56
+ .option('--url <url>', 'Backend host URL')
57
+ .action(async (options) => {
58
+ await runWhoami(process.cwd(), options);
59
+ });
38
60
  program
39
61
  .command('serve')
40
- .description('Watch local sequences and overlay them onto a backend over WebSocket')
41
- .option('--url <url>', 'Backend host or overlay WebSocket URL (env SUPERPANEL_SDK_BACKEND_URL)')
42
- .option('--api-key <key>', 'Company API key (env SUPERPANEL_SDK_API_KEY)')
43
- .option('--company <id>', 'Company id (env SUPERPANEL_SDK_COMPANY_ID)')
44
- .option('--sequence <id>', 'Serve a single sequence (default: all with slots)')
62
+ .description('Watch the whole repository and serve it in place of an environment\'s live release, over WebSocket')
63
+ .option('--url <url>', 'Backend host URL (env SUPERPANEL_SDK_BACKEND_URL)')
64
+ .option('--no-open', 'Copy the authorization URL to the clipboard instead of opening a browser')
65
+ .option('--environment <id>', 'Target non-production environment id (prompts in a terminal if omitted)')
45
66
  .action(async (options) => {
46
67
  await runServe(process.cwd(), {
47
68
  url: options.url,
48
- apiKey: options.apiKey,
49
- companyId: options.company,
50
- sequenceIds: options.sequence ? [options.sequence] : undefined,
69
+ openBrowser: options.open,
70
+ environment: options.environment,
51
71
  });
52
72
  });
53
73
  async function main() {
@@ -1,9 +1,79 @@
1
+ import type { AnyEventHandlers } from '../../core/functions/events.js';
2
+ import type { FuncMap } from '../../core/functions/types.js';
3
+ import { type CompanyPart, type SequenceBuild } from '../../builder/types.js';
4
+ import type { CompiledCompanyMetadata } from '../../core/slot/schema.js';
5
+ import { type OverlayAuthErrorMessage } from '../../dev-overlay/protocol.js';
1
6
  export type ServeOptions = {
2
7
  url?: string;
3
- apiKey?: string;
4
- companyId?: string;
5
- sequenceIds?: string[];
8
+ environment?: string;
9
+ openBrowser?: boolean;
10
+ };
11
+ type LoadedSequence = {
12
+ build: SequenceBuild;
13
+ functions: FuncMap;
14
+ events: AnyEventHandlers;
15
+ generation: number;
16
+ };
17
+ /** The company-level functions (22 §5), compiled without code, and their implementations. */
18
+ type LoadedCompany = {
19
+ part: CompanyPart;
20
+ /** From `schema/`, apart from any sequence: a repository with no sequence still pushes it. */
21
+ companyMetadata: CompiledCompanyMetadata;
22
+ functions: FuncMap;
6
23
  };
7
24
  export declare function overlayWebSocketUrl(raw: string): string;
25
+ /** Not the repository's code: dependencies, git, and what compiling writes. */
26
+ export declare function isIgnoredServePath(repoRoot: string, file: string): boolean;
27
+ /**
28
+ * What a changed file recompiles (22-sequence-as-business-unit §6): a file of one sequence, that
29
+ * sequence; anything else (`schema/`, `resolve.ts`, shared code) can reach every sequence, so all.
30
+ */
31
+ export declare function reloadScopeForPath(repoRoot: string, file: string): 'all' | {
32
+ sequenceId: string;
33
+ } | null;
34
+ export declare function loadCompany(repoRoot: string): Promise<LoadedCompany>;
35
+ /** What a reload recompiles: the whole repository, or these sequences. */
36
+ export type ReloadJob = {
37
+ all: boolean;
38
+ ids: Set<string>;
39
+ };
40
+ /**
41
+ * The changes waiting to be reloaded. A reload that fails keeps its scope (`fail`) for the next one,
42
+ * which a new file change starts (no retry on its own: the failure is in the code until it is
43
+ * edited); it is cleared only once a reload of it loads.
44
+ */
45
+ export declare class ReloadQueue {
46
+ private pending;
47
+ private failed;
48
+ add(scope: 'all' | {
49
+ sequenceId: string;
50
+ }): void;
51
+ /** Something changed since the last reload. */
52
+ hasChanges(): boolean;
53
+ /** The next reload: the new changes plus what failed before. */
54
+ take(): ReloadJob;
55
+ fail(job: ReloadJob): void;
56
+ }
57
+ /** What a serve runs and pushes: the company's code and every loaded sequence. */
58
+ export type ServeState = {
59
+ company: LoadedCompany;
60
+ sequences: Map<string, LoadedSequence>;
61
+ };
62
+ /**
63
+ * The state after a reload (`all`: the whole repository; else the sequences `ids` names), built
64
+ * aside: if any part fails to load it throws and the current state stays whole, never new company
65
+ * code with old sequences.
66
+ */
67
+ export declare function reloadServeState(repoRoot: string, current: ServeState, job: {
68
+ all: boolean;
69
+ ids: Iterable<string>;
70
+ }, generation: number): Promise<ServeState>;
71
+ /**
72
+ * Push the local company build: the company's functions and every loaded sequence, as one overlay.
73
+ * With no sequence left it is still pushed, so the environment drops the ones it had (22 §11).
74
+ */
75
+ export declare function pushOverlay(ws: Pick<WebSocket, 'send'>, company: LoadedCompany, sequences: Map<string, LoadedSequence>, generation: number): void;
76
+ export declare function toOverlayError(message: OverlayAuthErrorMessage): Error;
8
77
  export declare function runServe(repoRoot: string, options?: ServeOptions): Promise<void>;
78
+ export {};
9
79
  //# sourceMappingURL=index.d.ts.map