@ankhorage/projects 0.7.3 → 0.9.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 (86) hide show
  1. package/README.md +20 -12
  2. package/dist/capabilities/index.d.ts +330 -0
  3. package/dist/capabilities/index.js +194 -0
  4. package/dist/capabilities/socialManagerMediaAnalytics.d.ts +92 -0
  5. package/dist/capabilities/socialManagerMediaAnalytics.js +75 -0
  6. package/dist/features/projects/composition/composeGeneratedRuntimeMaterialization.d.ts +1 -0
  7. package/dist/features/projects/composition/composeGeneratedRuntimeMaterialization.js +13 -5
  8. package/dist/features/projects/composition/createExpoProjectMaterializer.d.ts +4 -6
  9. package/dist/features/projects/composition/createExpoProjectMaterializer.js +29 -36
  10. package/dist/features/projects/composition/createNavigatorMaterializationFiles.d.ts +14 -0
  11. package/dist/features/projects/composition/createNavigatorMaterializationFiles.js +19 -0
  12. package/dist/features/projects/composition/createRootNavigatorGenerationOptions.d.ts +9 -0
  13. package/dist/features/projects/composition/createRootNavigatorGenerationOptions.js +10 -0
  14. package/dist/features/projects/composition/createSocialManagerServerFiles.d.ts +6 -0
  15. package/dist/features/projects/composition/createSocialManagerServerFiles.js +16 -0
  16. package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemRepositories.d.ts +16 -0
  17. package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemRepositories.js +201 -0
  18. package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemStoreAsync.d.ts +25 -0
  19. package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemStoreAsync.js +72 -0
  20. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerDraftStoreAsync.d.ts +7 -0
  21. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerDraftStoreAsync.js +160 -0
  22. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerFlowSecurityAsync.d.ts +19 -0
  23. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerFlowSecurityAsync.js +176 -0
  24. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaPreflight.d.ts +4 -0
  25. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaPreflight.js +37 -0
  26. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.d.ts +7 -0
  27. package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.js +242 -0
  28. package/dist/features/trusted-social-manager-host/adapters/createSocialOperationStoresAsync.d.ts +13 -0
  29. package/dist/features/trusted-social-manager-host/adapters/createSocialOperationStoresAsync.js +244 -0
  30. package/dist/features/trusted-social-manager-host/adapters/projectSocialManagerConnection.d.ts +53 -0
  31. package/dist/features/trusted-social-manager-host/adapters/projectSocialManagerConnection.js +42 -0
  32. package/dist/features/trusted-social-manager-host/application/createSocialManagerPublicationRuntime.d.ts +10 -0
  33. package/dist/features/trusted-social-manager-host/application/createSocialManagerPublicationRuntime.js +240 -0
  34. package/dist/features/trusted-social-manager-host/application/resolveSocialManagerPublication.d.ts +22 -0
  35. package/dist/features/trusted-social-manager-host/application/resolveSocialManagerPublication.js +97 -0
  36. package/dist/features/trusted-social-manager-host/composition/createSocialManagerCapabilityOperations.d.ts +22 -0
  37. package/dist/features/trusted-social-manager-host/composition/createSocialManagerCapabilityOperations.js +224 -0
  38. package/dist/features/trusted-social-manager-host/composition/createSocialManagerConnectionOperations.d.ts +20 -0
  39. package/dist/features/trusted-social-manager-host/composition/createSocialManagerConnectionOperations.js +152 -0
  40. package/dist/features/trusted-social-manager-host/composition/createSocialManagerLocalProviderFixtures.d.ts +22 -0
  41. package/dist/features/trusted-social-manager-host/composition/createSocialManagerLocalProviderFixtures.js +271 -0
  42. package/dist/features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.d.ts +14 -0
  43. package/dist/features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.js +72 -0
  44. package/dist/features/trusted-social-manager-host/composition/createSocialManagerProvider.d.ts +20 -0
  45. package/dist/features/trusted-social-manager-host/composition/createSocialManagerProvider.js +20 -0
  46. package/dist/features/trusted-social-manager-host/composition/createSocialManagerPublicationOperations.d.ts +15 -0
  47. package/dist/features/trusted-social-manager-host/composition/createSocialManagerPublicationOperations.js +185 -0
  48. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerFileSystemPersistenceAsync.d.ts +14 -0
  49. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerFileSystemPersistenceAsync.js +17 -0
  50. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.d.ts +51 -0
  51. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.js +188 -0
  52. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalHostAsync.d.ts +18 -0
  53. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalHostAsync.js +177 -0
  54. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalServerAsync.d.ts +26 -0
  55. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalServerAsync.js +66 -0
  56. package/dist/features/trusted-social-manager-host/domain/publicationConfig.d.ts +18 -0
  57. package/dist/features/trusted-social-manager-host/domain/publicationConfig.js +77 -0
  58. package/dist/features/trusted-social-manager-host/domain/readSocialManagerConnectionRequest.d.ts +54 -0
  59. package/dist/features/trusted-social-manager-host/domain/readSocialManagerConnectionRequest.js +77 -0
  60. package/dist/features/trusted-social-manager-host/domain/readSocialManagerDraftContent.d.ts +3 -0
  61. package/dist/features/trusted-social-manager-host/domain/readSocialManagerDraftContent.js +47 -0
  62. package/dist/features/trusted-social-manager-host/domain/socialManagerConnectionIdentity.d.ts +17 -0
  63. package/dist/features/trusted-social-manager-host/domain/socialManagerConnectionIdentity.js +17 -0
  64. package/dist/features/trusted-zefix-host/composition/createTrustedZefixHost.d.ts +1 -2
  65. package/dist/features/trusted-zefix-host/composition/createTrustedZefixHost.js +3 -59
  66. package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.d.ts +36 -0
  67. package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.js +105 -0
  68. package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.d.ts +35 -0
  69. package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.js +92 -0
  70. package/dist/features/trusted-zefix-host/composition/zefixOperations.d.ts +20 -0
  71. package/dist/features/trusted-zefix-host/composition/zefixOperations.js +57 -0
  72. package/dist/features/worker-materialization/composition/composeWorkerMaterialization.d.ts +13 -0
  73. package/dist/features/worker-materialization/composition/composeWorkerMaterialization.js +90 -0
  74. package/dist/features/worker-materialization/composition/createWorkerMaterializationFile.d.ts +13 -0
  75. package/dist/features/worker-materialization/composition/createWorkerMaterializationFile.js +48 -0
  76. package/dist/features/worker-materialization/constants/worker.d.ts +6 -0
  77. package/dist/features/worker-materialization/constants/worker.js +6 -0
  78. package/dist/index.d.ts +18 -0
  79. package/dist/index.js +16 -0
  80. package/dist/types/socialManager.d.ts +77 -0
  81. package/dist/types/socialManager.js +1 -0
  82. package/dist/types/socialManagerPublication.d.ts +27 -0
  83. package/dist/types/socialManagerPublication.js +1 -0
  84. package/dist/worker/index.d.ts +3 -0
  85. package/dist/worker/index.js +3 -0
  86. package/package.json +511 -9
@@ -0,0 +1,35 @@
1
+ import { type PersistentExternalRequestBudgetPort } from '@ankhorage/api';
2
+ import { type EndpointTestFetch, type EndpointTestFetchInit } from '@ankhorage/data-sources';
3
+ import { type TrustedZefixOperation } from './zefixOperations.js';
4
+ /*** Basic credentials resolved by the trusted host, for example from a Worker secret binding. */
5
+ export type TrustedZefixWorkerCredentials = Readonly<{
6
+ username: string;
7
+ password: string;
8
+ }>;
9
+ /*** Outbound transport that receives the reservation's abort signal and must not follow redirects. */
10
+ export type TrustedZefixWorkerFetch = (url: string, init: EndpointTestFetchInit & Readonly<{
11
+ signal?: AbortSignal;
12
+ redirect: 'error';
13
+ }>) => ReturnType<EndpointTestFetch>;
14
+ export type CreateTrustedZefixWorkerHandlerInput = Readonly<{
15
+ appId: string;
16
+ projectId: string;
17
+ environment: string;
18
+ /** The application allowlist: broker operation ids permitted to reach each Zefix operation. */
19
+ operations: Readonly<Record<string, TrustedZefixOperation>>;
20
+ /** Verify the caller session, for example with Neon Auth; never trust caller-supplied identity. */
21
+ authenticateCallerAsync: (request: Request) => Promise<unknown>;
22
+ authorizeCallerAsync: (input: Readonly<{
23
+ caller: unknown;
24
+ appId: string;
25
+ projectId: string;
26
+ environment: string;
27
+ operationId: string;
28
+ }>) => Promise<boolean>;
29
+ /** Durable atomic admission, for example the PostgreSQL request budget. */
30
+ requestBudget: PersistentExternalRequestBudgetPort;
31
+ resolveCredentialsAsync: () => Promise<TrustedZefixWorkerCredentials | undefined>;
32
+ fetch?: TrustedZefixWorkerFetch;
33
+ }>;
34
+ /*** Compose the Fetch-standard Zefix Worker handler from injected, provider-neutral host ports. */
35
+ export declare function createTrustedZefixWorkerHandler(input: CreateTrustedZefixWorkerHandlerInput): (request: Request) => Promise<Response>;
@@ -0,0 +1,92 @@
1
+ import { createWorkerTrustedApiHandler, } from '@ankhorage/api';
2
+ import { createZefixPublicRestApi, } from '@ankhorage/data-sources';
3
+ import { createRuntimeApiCapabilityExecutor } from '@ankhorage/runtime/api-capabilities';
4
+ import { executeZefixOperationAsync, isHostBindingRecord, } from './zefixOperations.js';
5
+ /*** Compose the Fetch-standard Zefix Worker handler from injected, provider-neutral host ports. */
6
+ export function createTrustedZefixWorkerHandler(input) {
7
+ if (!input.appId.trim() || !input.projectId.trim() || !input.environment.trim())
8
+ throw new Error('Trusted Zefix host requires immutable app, project, and environment identities.');
9
+ const operations = new Map(Object.entries(input.operations));
10
+ const fetchImpl = input.fetch ?? defaultFetchAsync;
11
+ return createWorkerTrustedApiHandler({
12
+ scope: { appId: input.appId, projectId: input.projectId, environment: input.environment },
13
+ authenticateCallerAsync: input.authenticateCallerAsync,
14
+ broker: {
15
+ requestBudget: input.requestBudget,
16
+ authorizeAsync: async ({ context, request }) => input
17
+ .authorizeCallerAsync({
18
+ caller: context.caller,
19
+ ...context.scope,
20
+ operationId: request.operationId,
21
+ })
22
+ .catch(() => false),
23
+ resolveOperationAsync: ({ request }) => resolveOperation(operations, request),
24
+ validateInputAsync: ({ input: value }) => {
25
+ if (!isHostBindingRecord(value))
26
+ throw new TypeError('Invalid operation input.');
27
+ return value;
28
+ },
29
+ resolveCredentialsAsync: async () => {
30
+ const credentials = await input.resolveCredentialsAsync();
31
+ return credentials === undefined ? undefined : { values: { ...credentials } };
32
+ },
33
+ executeOperationAsync: (execution) => executeBrokerOperationAsync(fetchImpl, execution),
34
+ },
35
+ });
36
+ }
37
+ /*** Admit only allowlisted operation ids bound to their one canonical Zefix endpoint. */
38
+ function resolveOperation(operations, request) {
39
+ const zefix = operations.get(request.operationId);
40
+ return zefix !== undefined &&
41
+ request.apiId === 'zefix' &&
42
+ request.endpointId === canonicalEndpointId(zefix)
43
+ ? {
44
+ apiId: 'zefix',
45
+ endpointId: request.endpointId,
46
+ operationId: request.operationId,
47
+ credentialsRequired: true,
48
+ zefix,
49
+ }
50
+ : undefined;
51
+ }
52
+ /*** Bind each Zefix operation to its one canonical endpoint id. */
53
+ function canonicalEndpointId(operation) {
54
+ return operation === 'company.search' ? 'company-search' : 'company-uid';
55
+ }
56
+ /*** Execute one admitted operation with abort-aware transport and server-side Basic credentials. */
57
+ async function executeBrokerOperationAsync(fetchImpl, execution) {
58
+ const { credentials, signal } = execution;
59
+ const executor = createRuntimeApiCapabilityExecutor({
60
+ apis: { zefix: createZefixPublicRestApi() },
61
+ credentialResolver: () => Promise.resolve(credentials === undefined
62
+ ? undefined
63
+ : {
64
+ headers: {
65
+ authorization: `Basic ${btoa(`${credentials.values.username}:${credentials.values.password}`)}`,
66
+ },
67
+ }),
68
+ // Every admitted execution is abortable and issues at most the one Zefix request.
69
+ fetch: createSingleRequestFetch(fetchImpl, signal),
70
+ });
71
+ const result = await executeZefixOperationAsync(executor, execution.operation.zefix, execution.input);
72
+ return { status: 'status' in result ? result.status : 200, publicBody: result.body };
73
+ }
74
+ /*** Allow exactly one upstream request per reservation: no second call, redirect or retry. */
75
+ function createSingleRequestFetch(fetchImpl, signal) {
76
+ const state = { used: false };
77
+ return (url, init) => {
78
+ if (state.used)
79
+ return Promise.reject(new Error('Only one upstream request is permitted.'));
80
+ state.used = true;
81
+ return fetchImpl(url, {
82
+ ...init,
83
+ redirect: 'error',
84
+ ...(signal === undefined ? {} : { signal }),
85
+ });
86
+ };
87
+ }
88
+ /*** Use the platform fetch and expose only the response surface the runtime executor reads. */
89
+ async function defaultFetchAsync(url, init) {
90
+ const response = await fetch(url, init);
91
+ return { status: response.status, text: () => response.text() };
92
+ }
@@ -0,0 +1,20 @@
1
+ import type { createRuntimeApiCapabilityExecutor } from '@ankhorage/runtime/api-capabilities';
2
+ export type TrustedZefixOperation = 'company.search' | 'company.get-by-uid';
3
+ /*** Execute only an approved Zefix operation and return the curated company projection. */
4
+ export declare function executeZefixOperationAsync(executor: ReturnType<typeof createRuntimeApiCapabilityExecutor>, operation: TrustedZefixOperation, input: unknown): Promise<{
5
+ status: number;
6
+ body: {
7
+ error: {
8
+ code: string;
9
+ };
10
+ };
11
+ } | {
12
+ body: import("@ankhorage/data-sources").ZefixCompanyResultCompany[];
13
+ }>;
14
+ type HostBindingValue = string | number | boolean | null | readonly HostBindingValue[] | HostBindingRecord;
15
+ interface HostBindingRecord {
16
+ readonly [key: string]: HostBindingValue;
17
+ }
18
+ /*** Admit only serializable operation input before passing it to Runtime's binding executor. */
19
+ export declare function isHostBindingRecord(value: unknown): value is HostBindingRecord;
20
+ export {};
@@ -0,0 +1,57 @@
1
+ import { mapZefixCompanyResult } from '@ankhorage/data-sources';
2
+ import { isRecord } from '@ankhorage/utility/object';
3
+ /*** Execute only an approved Zefix operation and return the curated company projection. */
4
+ export async function executeZefixOperationAsync(executor, operation, input) {
5
+ const values = isHostBindingRecord(input) ? input : undefined;
6
+ const result = await executor({
7
+ capability: `api.zefix.${operation}`,
8
+ ...(values === undefined ? {} : { input: values }),
9
+ });
10
+ if (!result.ok)
11
+ return zefixUnavailableResponse();
12
+ const companies = curateZefixResult(result.data);
13
+ return companies === undefined ? zefixUnavailableResponse() : { body: companies };
14
+ }
15
+ /*** Strip provider wire payloads before any Zefix result crosses the trusted host boundary. */
16
+ function curateZefixResult(value) {
17
+ if (!Array.isArray(value))
18
+ return undefined;
19
+ const mapped = value.map((candidate) => {
20
+ const company = asZefixCompany(candidate);
21
+ return company ? mapZefixCompanyResult(company) : undefined;
22
+ });
23
+ return mapped.every((result) => result !== undefined)
24
+ ? mapped.map((result) => result.company)
25
+ : undefined;
26
+ }
27
+ /*** Return the one credential-safe failure representation for Vault or provider failures. */
28
+ function zefixUnavailableResponse() {
29
+ return { status: 502, body: { error: { code: 'zefix_unavailable' } } };
30
+ }
31
+ /*** Narrow unknown endpoint data to the optional-field Zefix short-company DTO. */
32
+ function asZefixCompany(value) {
33
+ return isRecord(value) &&
34
+ optionalString(value.name) &&
35
+ optionalString(value.uid) &&
36
+ optionalString(value.chid) &&
37
+ optionalString(value.legalSeat)
38
+ ? value
39
+ : undefined;
40
+ }
41
+ /*** Accept missing or string wire fields while rejecting non-serializable provider data. */
42
+ function optionalString(value) {
43
+ return value === undefined || typeof value === 'string';
44
+ }
45
+ /*** Admit only serializable operation input before passing it to Runtime's binding executor. */
46
+ export function isHostBindingRecord(value) {
47
+ return isRecord(value) && Object.values(value).every(isHostBindingValue);
48
+ }
49
+ /*** Recursively reject host objects and functions from untrusted request input. */
50
+ function isHostBindingValue(value) {
51
+ return (value === null ||
52
+ typeof value === 'string' ||
53
+ typeof value === 'number' ||
54
+ typeof value === 'boolean' ||
55
+ (Array.isArray(value) && value.every(isHostBindingValue)) ||
56
+ (isRecord(value) && Object.values(value).every(isHostBindingValue)));
57
+ }
@@ -0,0 +1,13 @@
1
+ import { type AppManifest } from '@ankhorage/contracts';
2
+ /*** One generated file emitted by the Worker generator. */
3
+ interface WorkerMaterializationFile {
4
+ readonly relativePath: string;
5
+ readonly source: string;
6
+ }
7
+ /*** Add the Worker entry and build scripts to a generated package when the target environment runs on Workers. */
8
+ export declare function applyWorkerMaterialization(manifest: AppManifest, projectId: string, packageSource: string, targetEnvironment: string | undefined): Readonly<{
9
+ packageSource: string;
10
+ files: readonly WorkerMaterializationFile[];
11
+ }>;
12
+ export {};
13
+ /*** Render the thin Worker module: bindings are resolved server-side by the shared host. */
@@ -0,0 +1,90 @@
1
+ import { APP_ENVIRONMENT_IDS } from '@ankhorage/contracts';
2
+ import { WORKER_BUILT_ENTRY, WORKER_ENTRY_SOURCE_PATH, WORKER_WEB_DIRECTORY, } from '../constants/worker.js';
3
+ import { createWorkerMaterializationFile } from './createWorkerMaterializationFile.js';
4
+ const WORKER_DEPENDENCIES = {
5
+ '@ankhorage/auth': '^0.3.0',
6
+ '@ankhorage/auth-neon': '^0.2.0',
7
+ '@ankhorage/db-postgres': '^0.2.0',
8
+ '@ankhorage/projects': '^0.9.0',
9
+ };
10
+ const WORKER_SCRIPTS = {
11
+ 'build:web': `expo export --platform web --output-dir ${WORKER_WEB_DIRECTORY}`,
12
+ 'build:worker': `bun build ${WORKER_ENTRY_SOURCE_PATH} --outfile ${WORKER_BUILT_ENTRY} --target browser --format esm`,
13
+ build: 'bun run build:web && bun run build:worker',
14
+ };
15
+ const ZEFIX_OPERATIONS = ['company.search', 'company.get-by-uid'];
16
+ /*** Add the Worker entry and build scripts to a generated package when the target environment runs on Workers. */
17
+ export function applyWorkerMaterialization(manifest, projectId, packageSource, targetEnvironment) {
18
+ const worker = composeWorkerMaterialization(manifest, projectId, targetEnvironment);
19
+ return worker === undefined
20
+ ? { packageSource, files: [] }
21
+ : { packageSource: composeWorkerPackageSource(packageSource, worker), files: worker.files };
22
+ }
23
+ /*** Generate the Worker entry and build scripts when the target environment deploys to Cloudflare Workers. */
24
+ function composeWorkerMaterialization(manifest, projectId, targetEnvironment) {
25
+ if (targetEnvironment === undefined)
26
+ return undefined;
27
+ const target = resolveTargetEnvironment(manifest, targetEnvironment);
28
+ if (target.deployment.runtime.provider !== 'workers')
29
+ return undefined;
30
+ const scripts = createWorkerScripts(target.auth?.provider);
31
+ // The trusted Zefix handler is composed only when the manifest declares the corresponding API.
32
+ const operations = resolveZefixOperations(manifest);
33
+ return operations.length === 0
34
+ ? {
35
+ files: [createWorkerMaterializationFile()],
36
+ dependencies: {},
37
+ scripts,
38
+ }
39
+ : {
40
+ files: [
41
+ createWorkerMaterializationFile({
42
+ appId: manifest.metadata.slug,
43
+ projectId,
44
+ environment: targetEnvironment,
45
+ operations,
46
+ }),
47
+ ],
48
+ dependencies: WORKER_DEPENDENCIES,
49
+ scripts,
50
+ };
51
+ }
52
+ /** Resolve the declared target through the shared application-environment contract. */
53
+ function resolveTargetEnvironment(manifest, targetEnvironment) {
54
+ if (!isAppEnvironmentId(targetEnvironment)) {
55
+ throw new Error(`Target environment "${targetEnvironment}" is not declared in the manifest.`);
56
+ }
57
+ const target = Object.entries(manifest.infra.environments).find(([environment]) => environment === targetEnvironment)?.[1];
58
+ if (target === undefined) {
59
+ throw new Error(`Target environment "${targetEnvironment}" is not declared in the manifest.`);
60
+ }
61
+ return target;
62
+ }
63
+ /** Recognize only application environments declared by the portable contracts package. */
64
+ function isAppEnvironmentId(value) {
65
+ return APP_ENVIRONMENT_IDS.some((environment) => environment === value);
66
+ }
67
+ /*** Map the selected Neon Auth public output into Expo's public build environment only for Neon Auth builds. */
68
+ function createWorkerScripts(authProvider) {
69
+ return authProvider === 'neon'
70
+ ? {
71
+ ...WORKER_SCRIPTS,
72
+ 'build:web': `EXPO_PUBLIC_NEON_AUTH_URL="$NEON_AUTH_BASE_URL" ${WORKER_SCRIPTS['build:web']}`,
73
+ }
74
+ : WORKER_SCRIPTS;
75
+ }
76
+ /*** Add the Worker dependencies and build scripts to the generated application's package.json. */
77
+ function composeWorkerPackageSource(packageSource, worker) {
78
+ const packageJson = JSON.parse(packageSource);
79
+ return `${JSON.stringify({
80
+ ...packageJson,
81
+ dependencies: { ...packageJson.dependencies, ...worker.dependencies },
82
+ scripts: { ...packageJson.scripts, ...worker.scripts },
83
+ }, null, 2)}\n`;
84
+ }
85
+ /*** Collect the declared Zefix operations the trusted host can execute. */
86
+ function resolveZefixOperations(manifest) {
87
+ const declared = new Set(Object.values(manifest.infra.apis?.zefix?.endpoints ?? {}).flatMap((endpoint) => Object.values(endpoint.operations).map((operation) => operation.id)));
88
+ return ZEFIX_OPERATIONS.filter((operation) => declared.has(operation));
89
+ }
90
+ /*** Render the thin Worker module: bindings are resolved server-side by the shared host. */
@@ -0,0 +1,13 @@
1
+ interface WorkerMaterializationFile {
2
+ readonly relativePath: string;
3
+ readonly source: string;
4
+ }
5
+ interface WorkerEntryInput {
6
+ readonly appId: string;
7
+ readonly projectId: string;
8
+ readonly environment: string;
9
+ readonly operations: readonly string[];
10
+ }
11
+ /*** Render the generated Worker entry for either trusted API operations or a static-only application. */
12
+ export declare function createWorkerMaterializationFile(input?: WorkerEntryInput): WorkerMaterializationFile;
13
+ export {};
@@ -0,0 +1,48 @@
1
+ import { WORKER_ENTRY_SOURCE_PATH, WORKER_WEB_DIRECTORY } from '../constants/worker.js';
2
+ /** Maximum requests per budget key admitted by the generated Worker. */
3
+ const WORKER_REQUEST_LIMIT = 10;
4
+ /*** Render the generated Worker entry for either trusted API operations or a static-only application. */
5
+ export function createWorkerMaterializationFile(input) {
6
+ return {
7
+ relativePath: WORKER_ENTRY_SOURCE_PATH,
8
+ source: input === undefined ? createStaticWorkerEntrySource() : createWorkerEntrySource(input),
9
+ };
10
+ }
11
+ /*** Render the Worker module that delegates trusted API operations to the published host boundary. */
12
+ function createWorkerEntrySource(input) {
13
+ const operations = Object.fromEntries(input.operations.map((operation) => [operation, operation]));
14
+ return `import { createNeonServerCallerAuthenticationPort } from '@ankhorage/auth-neon';
15
+ import { createNeonPostgresRequestBudget } from '@ankhorage/db-postgres';
16
+ import { createTrustedZefixWorkerEntry } from '@ankhorage/projects/worker';
17
+
18
+ // Server-only: bundled to dist/worker/index.js, never into the public ${WORKER_WEB_DIRECTORY} assets.
19
+ // DATABASE_URL, ZEFIX_CREDENTIALS and ANKH_AUTH_ALLOWED_SUBJECTS are Worker secret bindings;
20
+ // NEON_AUTH_BASE_URL and NEON_AUTH_JWKS_URL are bound from the provisioned Neon Auth outputs.
21
+ export default createTrustedZefixWorkerEntry({
22
+ appId: ${JSON.stringify(input.appId)},
23
+ projectId: ${JSON.stringify(input.projectId)},
24
+ environment: ${JSON.stringify(input.environment)},
25
+ operations: ${JSON.stringify(operations)},
26
+ createCallerAuthentication: (env) =>
27
+ createNeonServerCallerAuthenticationPort({
28
+ authUrl: env.NEON_AUTH_BASE_URL ?? '',
29
+ ...(env.NEON_AUTH_JWKS_URL === undefined ? {} : { jwksUrl: env.NEON_AUTH_JWKS_URL }),
30
+ }),
31
+ createRequestBudget: (env) =>
32
+ createNeonPostgresRequestBudget({
33
+ connectionString: env.DATABASE_URL ?? '',
34
+ limit: ${WORKER_REQUEST_LIMIT},
35
+ }),
36
+ });
37
+ `;
38
+ }
39
+ /*** Render the Worker module for an application without server APIs: every Worker-routed request is unknown. */
40
+ function createStaticWorkerEntrySource() {
41
+ return `// Server-only: bundled to dist/worker/index.js, never into the public ${WORKER_WEB_DIRECTORY} assets.
42
+ // This application declares no server API, so the Worker serves none.
43
+ export default {
44
+ fetch: (): Response =>
45
+ Response.json({ error: { code: 'not_found' } }, { status: 404, headers: { 'cache-control': 'no-store' } }),
46
+ };
47
+ `;
48
+ }
@@ -0,0 +1,6 @@
1
+ /** Built Worker module uploaded by the Workers adapter; server code never lives in the asset directory. */
2
+ export declare const WORKER_ENTRY_SOURCE_PATH = "src/worker/index.ts";
3
+ /** Built Worker module consumed by the Workers deployment boundary. */
4
+ export declare const WORKER_BUILT_ENTRY = "dist/worker/index.js";
5
+ /** Public static assets uploaded beside the Worker. */
6
+ export declare const WORKER_WEB_DIRECTORY = "dist/web";
@@ -0,0 +1,6 @@
1
+ /** Built Worker module uploaded by the Workers adapter; server code never lives in the asset directory. */
2
+ export const WORKER_ENTRY_SOURCE_PATH = 'src/worker/index.ts';
3
+ /** Built Worker module consumed by the Workers deployment boundary. */
4
+ export const WORKER_BUILT_ENTRY = 'dist/worker/index.js';
5
+ /** Public static assets uploaded beside the Worker. */
6
+ export const WORKER_WEB_DIRECTORY = 'dist/web';
package/dist/index.d.ts CHANGED
@@ -3,5 +3,23 @@ export { projects } from './features/projects/application/projects.js';
3
3
  export { createExpoProjectMaterializer, type CreateExpoProjectMaterializerInput, type ExpoProjectMaterializationResult, type ExpoProjectMaterializer, } from './features/projects/composition/createExpoProjectMaterializer.js';
4
4
  export { createProjectsApiHandlerResolver } from './features/projects/composition/createProjectsApiHandlerResolver.js';
5
5
  export type { ProjectMaterializer, ProjectRepository, } from './features/projects/ports/ProjectRepository.js';
6
+ export { type ConnectionFileSystemStore, createConnectionFileSystemStoreAsync, } from './features/trusted-social-manager-host/adapters/createConnectionFileSystemStoreAsync.js';
7
+ export { createSocialManagerDraftStoreAsync } from './features/trusted-social-manager-host/adapters/createSocialManagerDraftStoreAsync.js';
8
+ export { createSocialManagerFlowSecurityAsync, type CreateSocialManagerFlowSecurityInput, } from './features/trusted-social-manager-host/adapters/createSocialManagerFlowSecurityAsync.js';
9
+ export { createSocialManagerMediaPreflight } from './features/trusted-social-manager-host/adapters/createSocialManagerMediaPreflight.js';
10
+ export { createSocialManagerMediaStoreAsync } from './features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.js';
11
+ export { createSocialOperationStoresAsync, type SocialOperationStores, } from './features/trusted-social-manager-host/adapters/createSocialOperationStoresAsync.js';
12
+ export { createSocialManagerPublicationRuntime } from './features/trusted-social-manager-host/application/createSocialManagerPublicationRuntime.js';
13
+ export { createSocialManagerCapabilityOperations, type SocialManagerCapabilityHostDependencies, } from './features/trusted-social-manager-host/composition/createSocialManagerCapabilityOperations.js';
14
+ export { createSocialManagerLocalProviderFixtures, type SocialManagerLocalProviderFixtures, } from './features/trusted-social-manager-host/composition/createSocialManagerLocalProviderFixtures.js';
15
+ export { createSocialManagerMediaOperations, type SocialManagerMediaHostDependencies, } from './features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.js';
16
+ export { createSocialManagerProvider, type SocialManagerProviderConfiguration, } from './features/trusted-social-manager-host/composition/createSocialManagerProvider.js';
17
+ export { createTrustedSocialManagerFileSystemPersistenceAsync, type TrustedSocialManagerFileSystemPersistence, } from './features/trusted-social-manager-host/composition/createTrustedSocialManagerFileSystemPersistenceAsync.js';
18
+ export { createTrustedSocialManagerHost, createTrustedSocialManagerHostAsync, type CreateTrustedSocialManagerHostAsyncInput, type CreateTrustedSocialManagerHostInput, } from './features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.js';
19
+ export { createTrustedSocialManagerLocalServerAsync, type CreateTrustedSocialManagerLocalServerAsyncInput, findTrustedSocialManagerApiDefinition, type TrustedSocialManagerLocalServer, } from './features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalServerAsync.js';
6
20
  export { createTrustedZefixHost, type CreateTrustedZefixHostInput, type TrustedZefixHost, } from './features/trusted-zefix-host/composition/createTrustedZefixHost.js';
21
+ export { createTrustedZefixWorkerEntry, type CreateTrustedZefixWorkerEntryInput, type TrustedZefixWorkerCallerAuthentication, type TrustedZefixWorkerEntry, type TrustedZefixWorkerEnvironment, type TrustedZefixWorkerRequestBudget, } from './features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.js';
22
+ export { createTrustedZefixWorkerHandler, type CreateTrustedZefixWorkerHandlerInput, type TrustedZefixWorkerCredentials, type TrustedZefixWorkerFetch, } from './features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.js';
7
23
  export type { CreateProjectInput, MaterializeProjectRevisionInput, Project, ProjectManifest, ProjectManifestDraft, ProjectManifestRevision, ReloadProjectManifestInput, SaveProjectManifestInput, UpdateProjectInput, } from './types/projects.js';
24
+ export type { SocialManagerCaller, SocialManagerDestination, SocialManagerDraft, SocialManagerDraftContent, SocialManagerDraftStore, SocialManagerDraftUpdate, SocialManagerMedia, SocialManagerMediaStore, SocialManagerMediaUpload, SocialManagerScope, } from './types/socialManager.js';
25
+ export type { SocialManagerPublicationBinding, SocialManagerPublicationDependencies, SocialManagerPublicationRequest, } from './types/socialManagerPublication.js';
package/dist/index.js CHANGED
@@ -2,4 +2,20 @@ export { createProjectRepositoryFileSystemAsync } from './features/projects/adap
2
2
  export { projects } from './features/projects/application/projects.js';
3
3
  export { createExpoProjectMaterializer, } from './features/projects/composition/createExpoProjectMaterializer.js';
4
4
  export { createProjectsApiHandlerResolver } from './features/projects/composition/createProjectsApiHandlerResolver.js';
5
+ export { createConnectionFileSystemStoreAsync, } from './features/trusted-social-manager-host/adapters/createConnectionFileSystemStoreAsync.js';
6
+ export { createSocialManagerDraftStoreAsync } from './features/trusted-social-manager-host/adapters/createSocialManagerDraftStoreAsync.js';
7
+ export { createSocialManagerFlowSecurityAsync, } from './features/trusted-social-manager-host/adapters/createSocialManagerFlowSecurityAsync.js';
8
+ export { createSocialManagerMediaPreflight } from './features/trusted-social-manager-host/adapters/createSocialManagerMediaPreflight.js';
9
+ export { createSocialManagerMediaStoreAsync } from './features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.js';
10
+ export { createSocialOperationStoresAsync, } from './features/trusted-social-manager-host/adapters/createSocialOperationStoresAsync.js';
11
+ export { createSocialManagerPublicationRuntime } from './features/trusted-social-manager-host/application/createSocialManagerPublicationRuntime.js';
12
+ export { createSocialManagerCapabilityOperations, } from './features/trusted-social-manager-host/composition/createSocialManagerCapabilityOperations.js';
13
+ export { createSocialManagerLocalProviderFixtures, } from './features/trusted-social-manager-host/composition/createSocialManagerLocalProviderFixtures.js';
14
+ export { createSocialManagerMediaOperations, } from './features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.js';
15
+ export { createSocialManagerProvider, } from './features/trusted-social-manager-host/composition/createSocialManagerProvider.js';
16
+ export { createTrustedSocialManagerFileSystemPersistenceAsync, } from './features/trusted-social-manager-host/composition/createTrustedSocialManagerFileSystemPersistenceAsync.js';
17
+ export { createTrustedSocialManagerHost, createTrustedSocialManagerHostAsync, } from './features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.js';
18
+ export { createTrustedSocialManagerLocalServerAsync, findTrustedSocialManagerApiDefinition, } from './features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalServerAsync.js';
5
19
  export { createTrustedZefixHost, } from './features/trusted-zefix-host/composition/createTrustedZefixHost.js';
20
+ export { createTrustedZefixWorkerEntry, } from './features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.js';
21
+ export { createTrustedZefixWorkerHandler, } from './features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.js';
@@ -0,0 +1,77 @@
1
+ /*** The server-resolved boundary within which collaborators may access drafts. */
2
+ export interface SocialManagerScope {
3
+ readonly tenantId: string;
4
+ readonly projectId: string;
5
+ readonly environmentId: string;
6
+ }
7
+ /*** An untrusted selection, not an authorization grant. Resolve it before provider execution. */
8
+ export interface SocialManagerDestination {
9
+ readonly connectionId: string;
10
+ readonly targetId: string;
11
+ readonly text: string;
12
+ readonly mediaIds: readonly string[];
13
+ readonly link?: string;
14
+ }
15
+ /*** Editable content contains opaque destination and media references, never credentials. */
16
+ export interface SocialManagerDraftContent {
17
+ readonly title: string;
18
+ readonly text: string;
19
+ readonly mediaIds: readonly string[];
20
+ readonly link?: string;
21
+ readonly destinations: readonly SocialManagerDestination[];
22
+ }
23
+ /*** An immutable draft revision suitable for binding subsequent approval to exact content. */
24
+ export interface SocialManagerDraft {
25
+ readonly id: string;
26
+ readonly revision: number;
27
+ readonly createdAt: string;
28
+ readonly updatedAt: string;
29
+ readonly content: SocialManagerDraftContent;
30
+ }
31
+ export type SocialManagerDraftUpdate = {
32
+ readonly status: 'updated';
33
+ readonly draft: SocialManagerDraft;
34
+ } | {
35
+ readonly status: 'not-found' | 'conflict';
36
+ };
37
+ /*** Durable host-owned draft persistence; scope is supplied by the trusted server, never the body. */
38
+ export interface SocialManagerDraftStore {
39
+ readonly createAsync: (scope: SocialManagerScope, content: SocialManagerDraftContent) => Promise<SocialManagerDraft>;
40
+ readonly listAsync: (scope: SocialManagerScope) => Promise<readonly SocialManagerDraft[]>;
41
+ readonly readAsync: (scope: SocialManagerScope, id: string, revision?: number) => Promise<SocialManagerDraft | undefined>;
42
+ readonly updateAsync: (scope: SocialManagerScope, id: string, expectedRevision: number, content: SocialManagerDraftContent) => Promise<SocialManagerDraftUpdate>;
43
+ readonly isMediaReferencedAsync: (scope: SocialManagerScope, mediaId: string) => Promise<boolean>;
44
+ }
45
+ /*** Identity obtained from a trusted authenticator, not from operation input. */
46
+ export interface SocialManagerCaller extends SocialManagerScope {
47
+ readonly actorId: string;
48
+ }
49
+ /*** Immutable metadata for host-owned media selected by a Social Manager draft. */
50
+ export interface SocialManagerMedia {
51
+ readonly mediaId: string;
52
+ readonly kind: 'image' | 'video';
53
+ readonly contentType: string;
54
+ readonly byteLength: number;
55
+ readonly createdAt: string;
56
+ }
57
+ /*** Raw upload content accepted only at the trusted Social Manager host boundary. */
58
+ export interface SocialManagerMediaUpload {
59
+ readonly contentType: string;
60
+ readonly bytes: Uint8Array;
61
+ }
62
+ /*** Durable caller-scoped media persistence with immutable content references. */
63
+ export interface SocialManagerMediaStore {
64
+ readonly uploadAsync: (caller: SocialManagerCaller, upload: SocialManagerMediaUpload) => Promise<SocialManagerMedia>;
65
+ readonly listAsync: (caller: SocialManagerCaller) => Promise<readonly SocialManagerMedia[]>;
66
+ readonly readAsync: (caller: SocialManagerCaller, mediaId: string) => Promise<SocialManagerMedia | undefined>;
67
+ readonly loadAsync: (caller: SocialManagerCaller, mediaId: string) => Promise<Readonly<{
68
+ media: SocialManagerMedia;
69
+ bytes: Uint8Array;
70
+ }> | undefined>;
71
+ readonly readForPublicationAsync: (input: Readonly<{
72
+ tenantId: string;
73
+ actorId: string;
74
+ mediaId: string;
75
+ }>) => Promise<SocialManagerMedia | undefined>;
76
+ readonly removeAsync: (caller: SocialManagerCaller, mediaId: string, isReferencedAsync: (media: SocialManagerMedia) => Promise<boolean>) => Promise<'removed' | 'not-found' | 'referenced'>;
77
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { ConnectionTargetDiscoveryPort, ManagedConnection } from '@ankhorage/connection';
2
+ import type { FlowRuntimeDependencies, FlowSecurityPort } from '@ankhorage/flow';
3
+ import type { SocialMediaPreflightPort, SocialMediaRef, SocialProviderPort, SocialTargetRef } from '@ankhorage/social';
4
+ import type { SocialManagerCaller, SocialManagerDestination, SocialManagerDraftStore, SocialManagerScope } from './socialManager.js';
5
+ export interface SocialManagerPublicationBinding {
6
+ readonly connection: ManagedConnection;
7
+ readonly target: SocialTargetRef;
8
+ readonly provider: SocialProviderPort;
9
+ }
10
+ export interface SocialManagerPublicationDependencies {
11
+ readonly scope: SocialManagerScope;
12
+ readonly drafts: SocialManagerDraftStore;
13
+ readonly flow: Omit<FlowRuntimeDependencies, 'nodeRegistry' | 'security'> & {
14
+ readonly security: FlowSecurityPort;
15
+ };
16
+ readonly discovery: ConnectionTargetDiscoveryPort;
17
+ readonly resolveBindingAsync: (caller: SocialManagerCaller, destination: SocialManagerDestination) => Promise<SocialManagerPublicationBinding | undefined>;
18
+ readonly resolveMediaAsync: (caller: SocialManagerCaller, mediaIds: readonly string[]) => Promise<readonly SocialMediaRef[]>;
19
+ readonly mediaPreflight: SocialMediaPreflightPort;
20
+ }
21
+ export interface SocialManagerPublicationRequest {
22
+ readonly caller: SocialManagerCaller;
23
+ readonly draftId: string;
24
+ readonly revision: number;
25
+ readonly destinationIndex: number;
26
+ readonly runAt?: string;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ /** Worker-safe entrypoint: only Fetch-standard trusted host composition, no filesystem or Node APIs. */
2
+ export { createTrustedZefixWorkerEntry, type CreateTrustedZefixWorkerEntryInput, type TrustedZefixWorkerCallerAuthentication, type TrustedZefixWorkerEntry, type TrustedZefixWorkerEnvironment, type TrustedZefixWorkerRequestBudget, } from '../features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.js';
3
+ export { createTrustedZefixWorkerHandler, type CreateTrustedZefixWorkerHandlerInput, type TrustedZefixWorkerCredentials, type TrustedZefixWorkerFetch, } from '../features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.js';
@@ -0,0 +1,3 @@
1
+ /** Worker-safe entrypoint: only Fetch-standard trusted host composition, no filesystem or Node APIs. */
2
+ export { createTrustedZefixWorkerEntry, } from '../features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.js';
3
+ export { createTrustedZefixWorkerHandler, } from '../features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.js';