@superpanel-sdk/runtime 0.0.1-internal.1

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 (169) hide show
  1. package/README.md +35 -0
  2. package/bin/superpanel-sdk-runtime.mjs +22 -0
  3. package/dist/builder/codegen/emit.d.ts +17 -0
  4. package/dist/builder/codegen/emit.js +143 -0
  5. package/dist/builder/codegen/generate.d.ts +21 -0
  6. package/dist/builder/codegen/generate.js +90 -0
  7. package/dist/builder/compile/compile-agenda.d.ts +15 -0
  8. package/dist/builder/compile/compile-agenda.js +59 -0
  9. package/dist/builder/compile/compile-sequence.d.ts +24 -0
  10. package/dist/builder/compile/compile-sequence.js +121 -0
  11. package/dist/builder/compile/function-code.d.ts +6 -0
  12. package/dist/builder/compile/function-code.js +30 -0
  13. package/dist/builder/compile/registry.d.ts +13 -0
  14. package/dist/builder/compile/registry.js +42 -0
  15. package/dist/builder/load.d.ts +22 -0
  16. package/dist/builder/load.js +169 -0
  17. package/dist/builder/merge.d.ts +4 -0
  18. package/dist/builder/merge.js +19 -0
  19. package/dist/builder/paths.d.ts +10 -0
  20. package/dist/builder/paths.js +22 -0
  21. package/dist/builder/types.d.ts +31 -0
  22. package/dist/builder/types.js +2 -0
  23. package/dist/cli/compile/index.d.ts +4 -0
  24. package/dist/cli/compile/index.js +11 -0
  25. package/dist/cli/index.d.ts +3 -0
  26. package/dist/cli/index.js +64 -0
  27. package/dist/cli/serve/index.d.ts +9 -0
  28. package/dist/cli/serve/index.js +340 -0
  29. package/dist/cli/type-gen/index.d.ts +5 -0
  30. package/dist/cli/type-gen/index.js +90 -0
  31. package/dist/compute-host/compute-host.d.ts +38 -0
  32. package/dist/compute-host/compute-host.js +45 -0
  33. package/dist/compute-host/index.d.ts +5 -0
  34. package/dist/compute-host/index.js +3 -0
  35. package/dist/compute-host/source-compute-host.d.ts +29 -0
  36. package/dist/compute-host/source-compute-host.js +72 -0
  37. package/dist/core/context/account-fields.d.ts +12 -0
  38. package/dist/core/context/account-fields.js +2 -0
  39. package/dist/core/context/contact.d.ts +60 -0
  40. package/dist/core/context/contact.js +34 -0
  41. package/dist/core/context/db.d.ts +69 -0
  42. package/dist/core/context/db.js +44 -0
  43. package/dist/core/context/docusign.d.ts +134 -0
  44. package/dist/core/context/docusign.js +108 -0
  45. package/dist/core/context/env.d.ts +9 -0
  46. package/dist/core/context/env.js +19 -0
  47. package/dist/core/context/filevine.d.ts +323 -0
  48. package/dist/core/context/filevine.js +254 -0
  49. package/dist/core/context/http.d.ts +9 -0
  50. package/dist/core/context/http.js +4 -0
  51. package/dist/core/context/hubspot.d.ts +250 -0
  52. package/dist/core/context/hubspot.js +191 -0
  53. package/dist/core/context/platform-registry.d.ts +67 -0
  54. package/dist/core/context/platform-registry.js +11 -0
  55. package/dist/core/context/platform.d.ts +33 -0
  56. package/dist/core/context/platform.js +2 -0
  57. package/dist/core/context/twilio.d.ts +50 -0
  58. package/dist/core/context/twilio.js +42 -0
  59. package/dist/core/context/types.d.ts +87 -0
  60. package/dist/core/context/types.js +9 -0
  61. package/dist/core/functions/define/case-context.d.ts +14 -0
  62. package/dist/core/functions/define/case-context.js +15 -0
  63. package/dist/core/functions/define/compute.d.ts +7 -0
  64. package/dist/core/functions/define/compute.js +17 -0
  65. package/dist/core/functions/define/custom.d.ts +4 -0
  66. package/dist/core/functions/define/custom.js +8 -0
  67. package/dist/core/functions/define/system.d.ts +7 -0
  68. package/dist/core/functions/define/system.js +12 -0
  69. package/dist/core/functions/func-ref.d.ts +16 -0
  70. package/dist/core/functions/func-ref.js +20 -0
  71. package/dist/core/functions/types.d.ts +78 -0
  72. package/dist/core/functions/types.js +5 -0
  73. package/dist/core/slot/compile-schema.d.ts +24 -0
  74. package/dist/core/slot/compile-schema.js +336 -0
  75. package/dist/core/slot/deps.d.ts +15 -0
  76. package/dist/core/slot/deps.js +88 -0
  77. package/dist/core/slot/derived.d.ts +32 -0
  78. package/dist/core/slot/derived.js +115 -0
  79. package/dist/core/slot/field.d.ts +36 -0
  80. package/dist/core/slot/field.js +97 -0
  81. package/dist/core/slot/id-ref.d.ts +4 -0
  82. package/dist/core/slot/id-ref.js +15 -0
  83. package/dist/core/slot/index.d.ts +15 -0
  84. package/dist/core/slot/index.js +14 -0
  85. package/dist/core/slot/path.d.ts +18 -0
  86. package/dist/core/slot/path.js +22 -0
  87. package/dist/core/slot/row.d.ts +22 -0
  88. package/dist/core/slot/row.js +54 -0
  89. package/dist/core/slot/schema.d.ts +102 -0
  90. package/dist/core/slot/schema.js +17 -0
  91. package/dist/core/slot/sf-schema.d.ts +23 -0
  92. package/dist/core/slot/sf-schema.js +125 -0
  93. package/dist/core/slot/sf-validate.d.ts +14 -0
  94. package/dist/core/slot/sf-validate.js +132 -0
  95. package/dist/core/slot/snapshot.d.ts +18 -0
  96. package/dist/core/slot/snapshot.js +138 -0
  97. package/dist/core/slot/types.d.ts +144 -0
  98. package/dist/core/slot/types.js +2 -0
  99. package/dist/core/slot/value.d.ts +9 -0
  100. package/dist/core/slot/value.js +97 -0
  101. package/dist/core/slot/write.d.ts +41 -0
  102. package/dist/core/slot/write.js +319 -0
  103. package/dist/core/stage/builders.d.ts +36 -0
  104. package/dist/core/stage/builders.js +28 -0
  105. package/dist/core/stage/condition.d.ts +17 -0
  106. package/dist/core/stage/condition.js +198 -0
  107. package/dist/core/stage/drive.d.ts +43 -0
  108. package/dist/core/stage/drive.js +77 -0
  109. package/dist/core/stage/finish-when.d.ts +20 -0
  110. package/dist/core/stage/finish-when.js +82 -0
  111. package/dist/core/stage/flatten.d.ts +27 -0
  112. package/dist/core/stage/flatten.js +464 -0
  113. package/dist/core/stage/index.d.ts +11 -0
  114. package/dist/core/stage/index.js +10 -0
  115. package/dist/core/stage/simulate.d.ts +24 -0
  116. package/dist/core/stage/simulate.js +33 -0
  117. package/dist/core/stage/transfer-fields.d.ts +14 -0
  118. package/dist/core/stage/transfer-fields.js +88 -0
  119. package/dist/core/stage/types.d.ts +177 -0
  120. package/dist/core/stage/types.js +2 -0
  121. package/dist/core/stage/validate.d.ts +11 -0
  122. package/dist/core/stage/validate.js +226 -0
  123. package/dist/core/stage/walk.d.ts +34 -0
  124. package/dist/core/stage/walk.js +96 -0
  125. package/dist/dev-overlay/protocol.d.ts +53 -0
  126. package/dist/dev-overlay/protocol.js +21 -0
  127. package/dist/fn-context/build-context.d.ts +11 -0
  128. package/dist/fn-context/build-context.js +21 -0
  129. package/dist/fn-context/fake/empty-api.d.ts +9 -0
  130. package/dist/fn-context/fake/empty-api.js +50 -0
  131. package/dist/fn-context/fake/index.d.ts +12 -0
  132. package/dist/fn-context/fake/index.js +22 -0
  133. package/dist/fn-context/index.d.ts +9 -0
  134. package/dist/fn-context/index.js +8 -0
  135. package/dist/fn-context/log.d.ts +8 -0
  136. package/dist/fn-context/log.js +29 -0
  137. package/dist/fn-context/make-ctx.d.ts +9 -0
  138. package/dist/fn-context/make-ctx.js +51 -0
  139. package/dist/fn-context/rpc/errors.d.ts +25 -0
  140. package/dist/fn-context/rpc/errors.js +23 -0
  141. package/dist/fn-context/rpc/index.d.ts +10 -0
  142. package/dist/fn-context/rpc/index.js +9 -0
  143. package/dist/fn-context/rpc/integration/index.d.ts +51 -0
  144. package/dist/fn-context/rpc/integration/index.js +19 -0
  145. package/dist/fn-context/rpc/integration/list-bindings.d.ts +21 -0
  146. package/dist/fn-context/rpc/integration/list-bindings.js +18 -0
  147. package/dist/fn-context/rpc/log.d.ts +36 -0
  148. package/dist/fn-context/rpc/log.js +16 -0
  149. package/dist/fn-context/rpc/platform.d.ts +28 -0
  150. package/dist/fn-context/rpc/platform.js +15 -0
  151. package/dist/fn-context/rpc/request-id.d.ts +5 -0
  152. package/dist/fn-context/rpc/request-id.js +13 -0
  153. package/dist/fn-context/rpc/trpc-client.d.ts +7 -0
  154. package/dist/fn-context/rpc/trpc-client.js +109 -0
  155. package/dist/fn-context/rpc/trpc-init.d.ts +17 -0
  156. package/dist/fn-context/rpc/trpc-init.js +17 -0
  157. package/dist/fn-context/rpc/trpc-router-factory.d.ts +84 -0
  158. package/dist/fn-context/rpc/trpc-router-factory.js +9 -0
  159. package/dist/fn-context/types.d.ts +17 -0
  160. package/dist/fn-context/types.js +2 -0
  161. package/dist/index.d.ts +47 -0
  162. package/dist/index.js +34 -0
  163. package/dist/voice-service/actions.d.ts +20 -0
  164. package/dist/voice-service/actions.js +2 -0
  165. package/dist/voice-service/index.d.ts +3 -0
  166. package/dist/voice-service/index.js +3 -0
  167. package/dist/voice-service/types.d.ts +1010 -0
  168. package/dist/voice-service/types.js +16 -0
  169. package/package.json +55 -0
@@ -0,0 +1,50 @@
1
+ import { platformSurfaces } from '../../core/context/platform-registry.js';
2
+ import { docusignMockService } from '../../core/context/docusign.js';
3
+ import { envMockService } from '../../core/context/env.js';
4
+ import { filevineMockService } from '../../core/context/filevine.js';
5
+ import { hubspotMockService } from '../../core/context/hubspot.js';
6
+ import { twilioMockService } from '../../core/context/twilio.js';
7
+ const MOCK_HUBSPOT_TARGET = { kind: 'account', id: 'mock-hubspot-main' };
8
+ const MOCK_TWILIO_TARGET = { kind: 'account', id: 'mock-twilio-main' };
9
+ const MOCK_FILEVINE_TARGET = { kind: 'account', id: 'mock-filevine-main' };
10
+ const MOCK_DOCUSIGN_TARGET = { kind: 'account', id: 'mock-docusign-main' };
11
+ const MOCK_ENV_TARGET = { kind: 'account', id: 'mock-env-main' };
12
+ function mockAccount(target, name) {
13
+ return { target, name, credentials: {}, config: {} };
14
+ }
15
+ const hubspotStub = {
16
+ ...mockAccount(MOCK_HUBSPOT_TARGET, 'main'),
17
+ ...hubspotMockService,
18
+ };
19
+ const twilioStub = {
20
+ ...mockAccount(MOCK_TWILIO_TARGET, 'main'),
21
+ ...twilioMockService,
22
+ };
23
+ const filevineStub = {
24
+ ...mockAccount(MOCK_FILEVINE_TARGET, 'main'),
25
+ ...filevineMockService,
26
+ };
27
+ const docusignStub = {
28
+ ...mockAccount(MOCK_DOCUSIGN_TARGET, 'main'),
29
+ ...docusignMockService,
30
+ };
31
+ const envStub = {
32
+ ...mockAccount(MOCK_ENV_TARGET, 'main'),
33
+ ...envMockService,
34
+ };
35
+ export const emptyIntegration = () => ({
36
+ hubspots: [hubspotStub],
37
+ twilios: [twilioStub],
38
+ filevines: [filevineStub],
39
+ docusigns: [docusignStub],
40
+ envs: [envStub],
41
+ });
42
+ /** Each registered surface backed by its mock, with per-method overrides applied on top. */
43
+ export const defaultPlatformApis = (overrides = {}) => {
44
+ const entries = Object.entries(platformSurfaces).map(([key, surface]) => [
45
+ key,
46
+ { ...surface.mock, ...overrides[key] },
47
+ ]);
48
+ return Object.fromEntries(entries);
49
+ };
50
+ //# sourceMappingURL=empty-api.js.map
@@ -0,0 +1,12 @@
1
+ import type { IntegrationApi, Logger } from '../../core/context/types.js';
2
+ import { type HttpApi } from '../../core/context/http.js';
3
+ import type { ApiHost } from '../types.js';
4
+ import { type PlatformApiOverrides } from './empty-api.js';
5
+ export type FakeApiHostOptions = PlatformApiOverrides & {
6
+ integration?: Partial<IntegrationApi>;
7
+ log?: Logger;
8
+ http?: Partial<HttpApi>;
9
+ };
10
+ /** In-process ApiHost for local unit tests (`makeCtx` uses this). */
11
+ export declare function createFakeApiHost(options?: FakeApiHostOptions): ApiHost;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { defaultHttpApi } from '../../core/context/http.js';
2
+ import { noopLog } from '../log.js';
3
+ import { defaultPlatformApis, emptyIntegration } from './empty-api.js';
4
+ /** In-process ApiHost for local unit tests (`makeCtx` uses this). */
5
+ export function createFakeApiHost(options = {}) {
6
+ const integration = {
7
+ ...emptyIntegration(),
8
+ ...options.integration,
9
+ };
10
+ const api = {
11
+ ...defaultPlatformApis(options),
12
+ integration,
13
+ log: options.log ?? noopLog,
14
+ http: { ...defaultHttpApi(), ...options.http },
15
+ };
16
+ return {
17
+ async buildApi() {
18
+ return api;
19
+ },
20
+ };
21
+ }
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ export type { ActionContext, ActionDataSlice, ApiHost, RunScope } from './types.js';
2
+ export { buildActionContext, type BuildActionContextOptions } from './build-context.js';
3
+ export { createFakeApiHost, type FakeApiHostOptions } from './fake/index.js';
4
+ export { defaultPlatformApis, emptyIntegration, type PlatformApiOverrides } from './fake/empty-api.js';
5
+ export { createRpcApiHost, REQUEST_ID_HEADER, readRequestIdHeader } from './rpc/index.js';
6
+ export { bindLogMeta, noopLog } from './log.js';
7
+ export { makeCtx, makeCtxAsync } from './make-ctx.js';
8
+ export { defaultHttpApi } from '../core/context/http.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,8 @@
1
+ export { buildActionContext } from './build-context.js';
2
+ export { createFakeApiHost } from './fake/index.js';
3
+ export { defaultPlatformApis, emptyIntegration } from './fake/empty-api.js';
4
+ export { createRpcApiHost, REQUEST_ID_HEADER, readRequestIdHeader } from './rpc/index.js';
5
+ export { bindLogMeta, noopLog } from './log.js';
6
+ export { makeCtx, makeCtxAsync } from './make-ctx.js';
7
+ export { defaultHttpApi } from '../core/context/http.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ import type { Logger, SystemContext } from '../core/context/types.js';
2
+ export declare const noopLog: Logger;
3
+ /**
4
+ * Stamp every `ctx.api.log` call with SystemContext.meta. First-class ids stay
5
+ * on extra so RpcApiHost can send them; the backend lifts them into LogContext.
6
+ */
7
+ export declare function bindLogMeta(log: Logger, meta: SystemContext['meta']): Logger;
8
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1,29 @@
1
+ export const noopLog = {
2
+ info: () => { },
3
+ warn: () => { },
4
+ error: () => { },
5
+ };
6
+ /** Identity fields that LogContext already stores first-class (mars ctx). */
7
+ const CONTEXT_KEYS = ['companyId', 'sequenceId', 'contactId'];
8
+ /** Remaining SystemContext.meta fields; carried on log extra. */
9
+ const EXTRA_META_KEYS = ['environmentId', 'entry', 'caseId'];
10
+ /**
11
+ * Stamp every `ctx.api.log` call with SystemContext.meta. First-class ids stay
12
+ * on extra so RpcApiHost can send them; the backend lifts them into LogContext.
13
+ */
14
+ export function bindLogMeta(log, meta) {
15
+ const bind = (extra) => {
16
+ const stamped = {};
17
+ for (const key of CONTEXT_KEYS)
18
+ stamped[key] = meta[key];
19
+ for (const key of EXTRA_META_KEYS)
20
+ stamped[key] = meta[key];
21
+ return { ...stamped, ...extra };
22
+ };
23
+ return {
24
+ info: (message, extra) => log.info(message, bind(extra)),
25
+ warn: (message, extra) => log.warn(message, bind(extra)),
26
+ error: (message, extra) => log.error(message, bind(extra)),
27
+ };
28
+ }
29
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1,9 @@
1
+ import type { MakeCtxOverrides, SystemContext } from '../core/context/types.js';
2
+ /**
3
+ * Build a fake SystemContext for local unit tests.
4
+ * Uses {@link createFakeApiHost}; sync because FakeApiHost has no I/O.
5
+ */
6
+ export declare function makeCtx(overrides?: MakeCtxOverrides): SystemContext;
7
+ /** Async makeCtx via {@link buildActionContext} + FakeApiHost (same result as {@link makeCtx}). */
8
+ export declare function makeCtxAsync(overrides?: MakeCtxOverrides): Promise<SystemContext>;
9
+ //# sourceMappingURL=make-ctx.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { defaultHttpApi } from '../core/context/http.js';
2
+ import { buildActionContext } from './build-context.js';
3
+ import { createFakeApiHost } from './fake/index.js';
4
+ import { defaultPlatformApis, emptyIntegration } from './fake/empty-api.js';
5
+ import { bindLogMeta, noopLog } from './log.js';
6
+ function toDataSlice(overrides) {
7
+ const timezone = overrides.timezone ?? 'UTC';
8
+ const today = overrides.today ?? '1970-01-01';
9
+ const now = overrides.now ?? Date.parse(`${today}T00:00:00.000Z`);
10
+ return {
11
+ time: { now, timezone, today },
12
+ meta: {
13
+ companyId: 'company',
14
+ environmentId: 'sandbox',
15
+ sequenceId: 'sequence',
16
+ entry: 'test',
17
+ contactId: 'contact',
18
+ caseId: 'case',
19
+ ...overrides.meta,
20
+ },
21
+ config: {
22
+ frontendUrl: 'http://localhost:3000',
23
+ backendUrl: 'http://localhost:4000',
24
+ ...overrides.config,
25
+ },
26
+ };
27
+ }
28
+ /**
29
+ * Build a fake SystemContext for local unit tests.
30
+ * Uses {@link createFakeApiHost}; sync because FakeApiHost has no I/O.
31
+ */
32
+ export function makeCtx(overrides = {}) {
33
+ const data = toDataSlice(overrides);
34
+ const api = {
35
+ ...defaultPlatformApis(overrides.api),
36
+ integration: { ...emptyIntegration(), ...overrides.api?.integration },
37
+ log: bindLogMeta(overrides.api?.log ?? noopLog, data.meta),
38
+ http: { ...defaultHttpApi(), ...overrides.api?.http },
39
+ };
40
+ return { ...data, api };
41
+ }
42
+ /** Async makeCtx via {@link buildActionContext} + FakeApiHost (same result as {@link makeCtx}). */
43
+ export async function makeCtxAsync(overrides = {}) {
44
+ return buildActionContext(toDataSlice(overrides), createFakeApiHost({
45
+ ...overrides.api,
46
+ integration: overrides.api?.integration,
47
+ log: overrides.api?.log,
48
+ http: overrides.api?.http,
49
+ }));
50
+ }
51
+ //# sourceMappingURL=make-ctx.js.map
@@ -0,0 +1,25 @@
1
+ import { TRPCError } from '@trpc/server';
2
+ import type { z } from 'zod';
3
+ export type RpcErrorCode = ConstructorParameters<typeof TRPCError>[0]['code'];
4
+ /**
5
+ * tRPC reports any non-TRPCError as INTERNAL_SERVER_ERROR, which would file caller mistakes and
6
+ * denied access under "server fault" — noisy in monitoring and wrongly retriable. A domain error
7
+ * opts out by declaring the status it deserves; everything else stays a 500 on purpose.
8
+ */
9
+ export type RpcCodedError = Error & {
10
+ readonly rpcCode: RpcErrorCode;
11
+ };
12
+ export declare function isRpcCodedError(error: unknown): error is RpcCodedError;
13
+ /**
14
+ * Raised when a caller passes params that fail a method's schema. Distinct from a bare ZodError
15
+ * because surfaces also validate their *responses* with zod, and "you sent bad params" must not
16
+ * be confused with "we produced a bad response".
17
+ */
18
+ export declare class ScriptInputError extends Error implements RpcCodedError {
19
+ readonly rpcCode = "BAD_REQUEST";
20
+ constructor(message: string, options?: {
21
+ cause?: unknown;
22
+ });
23
+ }
24
+ export declare function parseScriptInput<S extends z.ZodType>(schema: S, input: unknown): z.infer<S>;
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,23 @@
1
+ export function isRpcCodedError(error) {
2
+ return error instanceof Error && typeof error.rpcCode === 'string';
3
+ }
4
+ /**
5
+ * Raised when a caller passes params that fail a method's schema. Distinct from a bare ZodError
6
+ * because surfaces also validate their *responses* with zod, and "you sent bad params" must not
7
+ * be confused with "we produced a bad response".
8
+ */
9
+ export class ScriptInputError extends Error {
10
+ rpcCode = 'BAD_REQUEST';
11
+ constructor(message, options) {
12
+ super(message, options);
13
+ this.name = 'ScriptInputError';
14
+ }
15
+ }
16
+ export function parseScriptInput(schema, input) {
17
+ const parsed = schema.safeParse(input);
18
+ if (!parsed.success) {
19
+ throw new ScriptInputError(parsed.error.message, { cause: parsed.error });
20
+ }
21
+ return parsed.data;
22
+ }
23
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,10 @@
1
+ export { createAppRouter, type AppRouter } from './trpc-router-factory.js';
2
+ export type { RpcContext } from './trpc-init.js';
3
+ export { ScriptInputError, isRpcCodedError, parseScriptInput, type RpcCodedError, type RpcErrorCode, } from './errors.js';
4
+ export { createIntegrationRouter, type IntegrationInvokeHandler } from './integration/index.js';
5
+ export { createListBindingsProcedure } from './integration/list-bindings.js';
6
+ export { createPlatformRouter, type PlatformInvokeHandler } from './platform.js';
7
+ export { createLogRouter, type LogEmitHandler } from './log.js';
8
+ export { createRpcApiHost } from './trpc-client.js';
9
+ export { REQUEST_ID_HEADER, readRequestIdHeader } from './request-id.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ export { createAppRouter } from './trpc-router-factory.js';
2
+ export { ScriptInputError, isRpcCodedError, parseScriptInput, } from './errors.js';
3
+ export { createIntegrationRouter } from './integration/index.js';
4
+ export { createListBindingsProcedure } from './integration/list-bindings.js';
5
+ export { createPlatformRouter } from './platform.js';
6
+ export { createLogRouter } from './log.js';
7
+ export { createRpcApiHost } from './trpc-client.js';
8
+ export { REQUEST_ID_HEADER, readRequestIdHeader } from './request-id.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,51 @@
1
+ import type { IntegrationTarget } from '../../../core/context/types.js';
2
+ import { type RpcContext } from '../trpc-init.js';
3
+ import { createListBindingsProcedure } from './list-bindings.js';
4
+ /**
5
+ * Provider-agnostic entry point for script surfaces: the target's provider decides
6
+ * which methods exist, so adding one never touches the RPC layer.
7
+ */
8
+ export type IntegrationInvokeHandler = (input: {
9
+ target: IntegrationTarget;
10
+ method: string;
11
+ params: Record<string, unknown>;
12
+ ctx: RpcContext;
13
+ }) => Promise<unknown>;
14
+ export declare function createIntegrationRouter(modules: {
15
+ listBindings: ReturnType<typeof createListBindingsProcedure>;
16
+ invoke: IntegrationInvokeHandler;
17
+ }): import("@trpc/server").TRPCBuiltRouter<{
18
+ ctx: RpcContext;
19
+ meta: object;
20
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
21
+ transformer: false;
22
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
23
+ listBindings: import("@trpc/server").TRPCQueryProcedure<{
24
+ input: void;
25
+ output: {
26
+ surfaceKey: "docusigns" | "envs" | "filevines" | "hubspots" | "twilios";
27
+ target: {
28
+ kind: "account" | "resource";
29
+ id: string;
30
+ };
31
+ name: string;
32
+ methods: string[];
33
+ credentials: Record<string, unknown>;
34
+ config: Record<string, unknown>;
35
+ }[];
36
+ meta: object;
37
+ }>;
38
+ invoke: import("@trpc/server").TRPCMutationProcedure<{
39
+ input: {
40
+ target: {
41
+ kind: "account" | "resource";
42
+ id: string;
43
+ };
44
+ method: string;
45
+ params?: Record<string, unknown> | undefined;
46
+ };
47
+ output: unknown;
48
+ meta: object;
49
+ }>;
50
+ }>>;
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { publicProcedure, router } from '../trpc-init.js';
3
+ const integrationInvokeInput = z.object({
4
+ target: z.object({
5
+ kind: z.enum(['account', 'resource']),
6
+ id: z.string(),
7
+ }),
8
+ method: z.string(),
9
+ params: z.record(z.string(), z.unknown()).optional(),
10
+ });
11
+ export function createIntegrationRouter(modules) {
12
+ return router({
13
+ listBindings: modules.listBindings,
14
+ invoke: publicProcedure
15
+ .input(integrationInvokeInput)
16
+ .mutation(async ({ ctx, input }) => modules.invoke({ target: input.target, method: input.method, params: input.params ?? {}, ctx })),
17
+ });
18
+ }
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ import { type BoundIntegrationMeta } from '../../../core/context/types.js';
2
+ import { type RpcContext } from '../trpc-init.js';
3
+ export type ListBindingsHandler = (opts: {
4
+ ctx: RpcContext;
5
+ }) => Promise<BoundIntegrationMeta[]>;
6
+ export declare function createListBindingsProcedure(handler: ListBindingsHandler): import("@trpc/server").TRPCQueryProcedure<{
7
+ input: void;
8
+ output: {
9
+ surfaceKey: "docusigns" | "envs" | "filevines" | "hubspots" | "twilios";
10
+ target: {
11
+ kind: "account" | "resource";
12
+ id: string;
13
+ };
14
+ name: string;
15
+ methods: string[];
16
+ credentials: Record<string, unknown>;
17
+ config: Record<string, unknown>;
18
+ }[];
19
+ meta: object;
20
+ }>;
21
+ //# sourceMappingURL=list-bindings.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ import { integrationSurfaceKeys } from '../../../core/context/types.js';
3
+ import { publicProcedure } from '../trpc-init.js';
4
+ const boundIntegrationMeta = z.object({
5
+ surfaceKey: z.enum(integrationSurfaceKeys),
6
+ target: z.object({
7
+ kind: z.enum(['account', 'resource']),
8
+ id: z.string(),
9
+ }),
10
+ name: z.string(),
11
+ methods: z.array(z.string()),
12
+ credentials: z.record(z.string(), z.unknown()),
13
+ config: z.record(z.string(), z.unknown()),
14
+ });
15
+ export function createListBindingsProcedure(handler) {
16
+ return publicProcedure.output(z.array(boundIntegrationMeta)).query(async (opts) => handler(opts));
17
+ }
18
+ //# sourceMappingURL=list-bindings.js.map
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ import { type RpcContext } from './trpc-init.js';
3
+ export declare const logEmitInput: z.ZodObject<{
4
+ level: z.ZodEnum<{
5
+ error: "error";
6
+ info: "info";
7
+ warn: "warn";
8
+ }>;
9
+ message: z.ZodString;
10
+ extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
11
+ }, z.core.$strip>;
12
+ export type LogEmitHandler = (input: {
13
+ level: 'info' | 'warn' | 'error';
14
+ message: string;
15
+ extra?: Record<string, unknown>;
16
+ ctx: RpcContext;
17
+ }) => Promise<void>;
18
+ export declare function createLogRouter(emit: LogEmitHandler): import("@trpc/server").TRPCBuiltRouter<{
19
+ ctx: RpcContext;
20
+ meta: object;
21
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
22
+ transformer: false;
23
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
24
+ emit: import("@trpc/server").TRPCMutationProcedure<{
25
+ input: {
26
+ level: "error" | "info" | "warn";
27
+ message: string;
28
+ extra?: Record<string, unknown> | undefined;
29
+ };
30
+ output: {
31
+ ok: true;
32
+ };
33
+ meta: object;
34
+ }>;
35
+ }>>;
36
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ import { publicProcedure, router } from './trpc-init.js';
3
+ export const logEmitInput = z.object({
4
+ level: z.enum(['info', 'warn', 'error']),
5
+ message: z.string(),
6
+ extra: z.record(z.string(), z.unknown()).optional(),
7
+ });
8
+ export function createLogRouter(emit) {
9
+ return router({
10
+ emit: publicProcedure.input(logEmitInput).mutation(async ({ ctx, input }) => {
11
+ await emit({ level: input.level, message: input.message, extra: input.extra, ctx });
12
+ return { ok: true };
13
+ }),
14
+ });
15
+ }
16
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1,28 @@
1
+ import { type RpcContext } from './trpc-init.js';
2
+ /**
3
+ * Single entry point for every platform surface. The handler validates against the surface's
4
+ * declared schemas, so adding a method never touches this file.
5
+ */
6
+ export type PlatformInvokeHandler = (input: {
7
+ surface: string;
8
+ method: string;
9
+ params: Record<string, unknown>;
10
+ ctx: RpcContext;
11
+ }) => Promise<unknown>;
12
+ export declare function createPlatformRouter(invoke: PlatformInvokeHandler): import("@trpc/server").TRPCBuiltRouter<{
13
+ ctx: RpcContext;
14
+ meta: object;
15
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
16
+ transformer: false;
17
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
18
+ invoke: import("@trpc/server").TRPCMutationProcedure<{
19
+ input: {
20
+ surface: string;
21
+ method: string;
22
+ params?: Record<string, unknown> | undefined;
23
+ };
24
+ output: unknown;
25
+ meta: object;
26
+ }>;
27
+ }>>;
28
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ import { publicProcedure, router } from './trpc-init.js';
3
+ const platformInvokeInput = z.object({
4
+ surface: z.string(),
5
+ method: z.string(),
6
+ params: z.record(z.string(), z.unknown()).optional(),
7
+ });
8
+ export function createPlatformRouter(invoke) {
9
+ return router({
10
+ invoke: publicProcedure
11
+ .input(platformInvokeInput)
12
+ .mutation(async ({ ctx, input }) => invoke({ surface: input.surface, method: input.method, params: input.params ?? {}, ctx })),
13
+ });
14
+ }
15
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1,5 @@
1
+ export declare const REQUEST_ID_HEADER = "x-request-id";
2
+ export declare function readRequestIdHeader(headers: {
3
+ get(name: string): string | null;
4
+ } | Record<string, string | string[] | undefined>): string | undefined;
5
+ //# sourceMappingURL=request-id.d.ts.map
@@ -0,0 +1,13 @@
1
+ export const REQUEST_ID_HEADER = 'x-request-id';
2
+ function firstString(value) {
3
+ const raw = Array.isArray(value) ? value[0] : value;
4
+ return typeof raw === 'string' && raw.length > 0 ? raw : undefined;
5
+ }
6
+ export function readRequestIdHeader(headers) {
7
+ if (typeof headers.get === 'function') {
8
+ return firstString(headers.get(REQUEST_ID_HEADER));
9
+ }
10
+ const record = headers;
11
+ return firstString(record[REQUEST_ID_HEADER]);
12
+ }
13
+ //# sourceMappingURL=request-id.js.map
@@ -0,0 +1,7 @@
1
+ import type { ApiHost } from '../types.js';
2
+ export declare function createRpcApiHost(options: {
3
+ baseUrl: string;
4
+ getToken: () => string | Promise<string>;
5
+ getRequestId?: () => string | undefined;
6
+ }): ApiHost;
7
+ //# sourceMappingURL=trpc-client.d.ts.map
@@ -0,0 +1,109 @@
1
+ import { createTRPCClient, httpLink } from '@trpc/client';
2
+ import { platformSurfaces } from '../../core/context/platform-registry.js';
3
+ import { defaultHttpApi } from '../../core/context/http.js';
4
+ import { integrationSurfaceKeys, } from '../../core/context/types.js';
5
+ import { bindEnvService } from '../../core/context/env.js';
6
+ import { REQUEST_ID_HEADER } from './request-id.js';
7
+ function rpcLogger(c) {
8
+ const emit = (level, message, extra) => {
9
+ void c.log.emit.mutate({ level, message, extra }).catch(() => { });
10
+ };
11
+ return {
12
+ info: (message, extra) => emit('info', message, extra),
13
+ warn: (message, extra) => emit('warn', message, extra),
14
+ error: (message, extra) => emit('error', message, extra),
15
+ };
16
+ }
17
+ function rpcSafe(promise) {
18
+ return promise.catch((err) => {
19
+ if (err instanceof Error && err.constructor?.name === 'TRPCClientError') {
20
+ throw new Error(`RPC call failed: ${err.message}`);
21
+ }
22
+ throw err;
23
+ });
24
+ }
25
+ /**
26
+ * Builds the object a script sees at `ctx.api.integration.<surface>[i]`. The provider decides
27
+ * which methods exist and ships them in `meta.methods`, so this stays provider-agnostic; the
28
+ * declared surface type is what gives callers their static signatures.
29
+ */
30
+ function stubSurface(c, meta) {
31
+ const methods = meta.methods.map((method) => [
32
+ method,
33
+ (params = {}) => rpcSafe(c.integration.invoke.mutate({ target: meta.target, method, params })),
34
+ ]);
35
+ const stub = {
36
+ target: meta.target,
37
+ name: meta.name,
38
+ credentials: meta.credentials,
39
+ config: meta.config,
40
+ ...Object.fromEntries(methods),
41
+ };
42
+ if (meta.surfaceKey === 'envs') {
43
+ return bindEnvService(stub);
44
+ }
45
+ return stub;
46
+ }
47
+ function buildSurfaces(c, metas) {
48
+ const surfaces = Object.fromEntries(integrationSurfaceKeys.map((key) => [key, []]));
49
+ for (const meta of metas) {
50
+ surfaces[meta.surfaceKey]?.push(stubSurface(c, meta));
51
+ }
52
+ // Both the key set and the element shapes come from IntegrationApi, but TS cannot follow
53
+ // that through the dynamic construction above.
54
+ return surfaces;
55
+ }
56
+ /**
57
+ * Every platform surface routes through one procedure, so the whole set is built from the
58
+ * registry's method tables rather than hand-wired call by call.
59
+ */
60
+ function buildPlatformApis(c) {
61
+ const surfaces = Object.entries(platformSurfaces).map(([surface, spec]) => [
62
+ surface,
63
+ Object.fromEntries(Object.keys(spec.methods).map((method) => [
64
+ method,
65
+ (params = {}) => rpcSafe(c.platform.invoke.mutate({ surface, method, params })),
66
+ ])),
67
+ ]);
68
+ // The registry is what guarantees the shape; TS cannot follow it through Object.fromEntries.
69
+ return Object.fromEntries(surfaces);
70
+ }
71
+ export function createRpcApiHost(options) {
72
+ let client;
73
+ let lastBaseUrl;
74
+ function getClient(baseUrl) {
75
+ if (!client || lastBaseUrl !== baseUrl) {
76
+ client = createTRPCClient({
77
+ links: [
78
+ httpLink({
79
+ url: baseUrl,
80
+ headers: async () => {
81
+ const headers = {
82
+ authorization: `Bearer ${await options.getToken()}`,
83
+ };
84
+ const requestId = options.getRequestId?.();
85
+ if (requestId)
86
+ headers[REQUEST_ID_HEADER] = requestId;
87
+ return headers;
88
+ },
89
+ }),
90
+ ],
91
+ });
92
+ lastBaseUrl = baseUrl;
93
+ }
94
+ return client;
95
+ }
96
+ return {
97
+ async buildApi(_run) {
98
+ const c = getClient(options.baseUrl);
99
+ const metas = await rpcSafe(c.integration.listBindings.query());
100
+ return {
101
+ ...buildPlatformApis(c),
102
+ integration: buildSurfaces(c, metas),
103
+ log: rpcLogger(c),
104
+ http: defaultHttpApi(),
105
+ };
106
+ },
107
+ };
108
+ }
109
+ //# sourceMappingURL=trpc-client.js.map
@@ -0,0 +1,17 @@
1
+ import type { RunScope } from '../types.js';
2
+ export type RpcContext = {
3
+ run: RunScope;
4
+ requestId?: string;
5
+ };
6
+ export declare const router: import("@trpc/server").TRPCRouterBuilder<{
7
+ ctx: RpcContext;
8
+ meta: object;
9
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
10
+ transformer: false;
11
+ }>;
12
+ /**
13
+ * Applied to every procedure so domain errors reach the caller with the status they declared,
14
+ * without each dispatcher wrapping its own body in try/catch.
15
+ */
16
+ export declare const publicProcedure: import("@trpc/server").TRPCProcedureBuilder<RpcContext, object, {}, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, import("@trpc/server").TRPCUnsetMarker, false>;
17
+ //# sourceMappingURL=trpc-init.d.ts.map