@ankhorage/projects 0.9.3 → 0.9.5

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 (17) hide show
  1. package/README.md +1 -1
  2. package/dist/features/projects/composition/createExpoProjectMaterializer.js +2 -2
  3. package/dist/features/projects/composition/createManifestSource.d.ts +3 -0
  4. package/dist/features/projects/composition/createManifestSource.js +8 -0
  5. package/dist/features/trusted-social-manager-host/application/createSocialManagerPublicationRuntime.js +5 -125
  6. package/dist/features/trusted-social-manager-host/application/scheduleSocialManagerPublicationAsync.d.ts +8 -0
  7. package/dist/features/trusted-social-manager-host/application/scheduleSocialManagerPublicationAsync.js +118 -0
  8. package/dist/features/trusted-social-manager-host/application/socialManagerPublicationIdentity.d.ts +3 -0
  9. package/dist/features/trusted-social-manager-host/application/socialManagerPublicationIdentity.js +18 -0
  10. package/dist/features/trusted-social-manager-host/composition/createSocialManagerCapabilityOperations.js +1 -1
  11. package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalHostAsync.js +1 -22
  12. package/dist/features/trusted-social-manager-host/composition/targetForConnection.d.ts +4 -0
  13. package/dist/features/trusted-social-manager-host/composition/targetForConnection.js +27 -0
  14. package/dist/features/worker-materialization/composition/createWorkerMaterializationFile.js +13 -5
  15. package/package.json +4 -4
  16. package/dist/features/projects/composition/formatTypeScriptLiteral.d.ts +0 -2
  17. package/dist/features/projects/composition/formatTypeScriptLiteral.js +0 -46
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # Ankhorage Projects
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v0.9.3](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.9.5](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
7
7
 
8
8
  Provides standalone project identity, persistence, and repository-oriented project actions.
9
9
 
@@ -5,9 +5,9 @@ import { resolveExpoRuntimePlan } from '@ankhorage/expo-runtime/planning';
5
5
  import { materializeTemplateRevision } from '@ankhorage/templates';
6
6
  import { applyWorkerMaterialization } from '../../worker-materialization/composition/composeWorkerMaterialization.js';
7
7
  import { composeGeneratedRuntimeMaterialization } from './composeGeneratedRuntimeMaterialization.js';
8
+ import { createManifestSource } from './createManifestSource.js';
8
9
  import { createNavigatorMaterializationFiles, } from './createNavigatorMaterializationFiles.js';
9
10
  import { createSocialManagerServerFiles } from './createSocialManagerServerFiles.js';
10
- import { formatTypeScriptLiteral } from './formatTypeScriptLiteral.js';
11
11
  /*** Create the public, caller-targeted Expo materializer for stored immutable project revisions. */
12
12
  export function createExpoProjectMaterializer(input) {
13
13
  return {
@@ -59,7 +59,7 @@ function createGeneratedFiles(manifest, projectId, navigatorInput, targetEnviron
59
59
  })),
60
60
  {
61
61
  relativePath: 'src/ankh.manifest.ts',
62
- source: `export default ${formatTypeScriptLiteral(manifest)} as const;\n`,
62
+ source: createManifestSource(manifest),
63
63
  },
64
64
  ...app.files,
65
65
  ...createNavigatorMaterializationFiles(manifest, navigatorInput, packageSource.navigatorBindings),
@@ -0,0 +1,3 @@
1
+ import type { AppManifest } from '@ankhorage/contracts';
2
+ /*** Serialize the immutable manifest as one JSON literal so generated source stays bounded and parser-safe. */
3
+ export declare function createManifestSource(manifest: AppManifest): string;
@@ -0,0 +1,8 @@
1
+ /*** Serialize the immutable manifest as one JSON literal so generated source stays bounded and parser-safe. */
2
+ export function createManifestSource(manifest) {
3
+ const serializedManifest = JSON.stringify(manifest)
4
+ .replaceAll('\u2028', '\\u2028')
5
+ .replaceAll('\u2029', '\\u2029');
6
+ const sourceLiteral = `'${serializedManifest.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
7
+ return `import type { AppManifest } from '@ankhorage/contracts';\n\nexport default JSON.parse(\n ${sourceLiteral},\n) as AppManifest;\n`;
8
+ }
@@ -1,9 +1,9 @@
1
- import { createHash } from 'node:crypto';
2
1
  import { createFlowNodeOperationResolver, createFlowRuntime, } from '@ankhorage/flow';
3
2
  import { executeSocialActionAsync, } from '@ankhorage/social';
4
3
  import { createKeyedAsyncMutex } from '@ankhorage/utility/concurrency';
5
- import { assertCallerScope, readPublicationConfig, sameTarget, } from '../domain/publicationConfig.js';
6
- import { readDestinationAsync, requireBindingAsync, resolveCommandAsync, } from './resolveSocialManagerPublication.js';
4
+ import { readPublicationConfig, sameTarget } from '../domain/publicationConfig.js';
5
+ import { resolveCommandAsync } from './resolveSocialManagerPublication.js';
6
+ import { scheduleSocialManagerPublicationAsync } from './scheduleSocialManagerPublicationAsync.js';
7
7
  const capabilityId = 'projects.social.publication.execute';
8
8
  const providerId = '@ankhorage/projects';
9
9
  /*** Compose the released Flow engine with one protected Social operation and immutable draft references. */
@@ -28,126 +28,7 @@ export function createSocialManagerPublicationRuntime(input) {
28
28
  });
29
29
  return {
30
30
  runtime,
31
- scheduleAsync: (request) => mutex.run(publicationId(request), () => scheduleAsync(input, runtime, request)),
32
- };
33
- }
34
- /*** Persist one exact, independently approvable destination run; Flow owns scheduling and execution. */
35
- async function scheduleAsync(input, runtime, request) {
36
- const scheduledRequest = {
37
- ...request,
38
- runAt: request.runAt ?? (input.flow.clock?.now() ?? new Date()).toISOString(),
39
- };
40
- const { caller, draftId, revision, destinationIndex, runAt } = scheduledRequest;
41
- assertCallerScope(input.scope, caller);
42
- assertScheduleInput(scheduledRequest);
43
- const destination = await readDestinationAsync(input, scheduledRequest);
44
- const binding = await requireBindingAsync(input, caller, destination);
45
- const config = {
46
- caller,
47
- draftId,
48
- revision,
49
- destinationIndex,
50
- runAt,
51
- connectionRevision: binding.connection.revision,
52
- target: binding.target,
53
- };
54
- const flow = createPublicationDefinition(config);
55
- const scope = { tenantId: caller.tenantId, projectId: caller.projectId };
56
- const existing = await runtime.getWorkflowAsync(scope, flow.id, flow.version);
57
- if (!existing)
58
- await runtime.createDraftAsync(scope, flow);
59
- else if (JSON.stringify(existing.definition) !== JSON.stringify(flow))
60
- throw new Error('Social publication configuration changed.');
61
- if (!existing?.publishedAt)
62
- await runtime.publishAsync(scope, flow.id, flow.version);
63
- const run = await runtime.triggerAsync({
64
- scope,
65
- flowId: flow.id,
66
- triggerId: 'publish',
67
- idempotencyKey: flow.id,
68
- runAt,
69
- });
70
- const approvalId = await ensureApprovalAsync(input, runtime, scheduledRequest, run.id);
71
- return { run, approvalId };
72
- }
73
- /*** Create a pending approval only once, without resetting a previously resolved decision. */
74
- async function ensureApprovalAsync(input, runtime, request, runId) {
75
- const { caller } = request;
76
- const scope = { tenantId: caller.tenantId, projectId: caller.projectId };
77
- const approvalId = `social-approval:${runId}`;
78
- if (!(await input.flow.store.getApprovalAsync(scope, approvalId)))
79
- await runtime.requestApprovalAsync({
80
- scope,
81
- approval: {
82
- id: approvalId,
83
- runId,
84
- status: 'pending',
85
- requestedBy: caller.actorId,
86
- requestedAt: (input.flow.clock?.now() ?? new Date()).toISOString(),
87
- },
88
- });
89
- return approvalId;
90
- }
91
- /*** Validate one exact destination revision and canonical UTC instant. */
92
- function assertScheduleInput(request) {
93
- const { caller, revision, destinationIndex, runAt } = request;
94
- if (!caller.actorId.trim())
95
- throw new Error('Social publication requires a caller.');
96
- if (!Number.isSafeInteger(revision) ||
97
- revision < 1 ||
98
- !Number.isSafeInteger(destinationIndex) ||
99
- destinationIndex < 0 ||
100
- (runAt !== undefined &&
101
- (!Number.isFinite(Date.parse(runAt)) || new Date(runAt).toISOString() !== runAt))) {
102
- throw new Error('Invalid Social Manager publication request.');
103
- }
104
- }
105
- /*** Derive a stable intent identity so a repeated schedule request cannot create another run. */
106
- function publicationId(request) {
107
- const { caller, draftId, revision, destinationIndex, runAt } = request;
108
- return ('social-' +
109
- createHash('sha256')
110
- .update(JSON.stringify([
111
- caller.tenantId,
112
- caller.projectId,
113
- caller.environmentId,
114
- caller.actorId,
115
- draftId,
116
- revision,
117
- destinationIndex,
118
- runAt ?? null,
119
- ]))
120
- .digest('hex'));
121
- }
122
- /*** Construct a server-owned graph that pins the approved revision and provider destination. */
123
- function createPublicationDefinition(config) {
124
- return {
125
- id: publicationId(config),
126
- version: 1,
127
- title: 'Social publication',
128
- triggers: [{ id: 'publish', kind: 'manual' }],
129
- edges: [],
130
- nodes: [
131
- {
132
- id: 'publication',
133
- capability: { providerId, capabilityId },
134
- config: {
135
- publication: {
136
- kind: 'inline',
137
- value: {
138
- caller: { ...config.caller },
139
- draftId: config.draftId,
140
- revision: config.revision,
141
- destinationIndex: config.destinationIndex,
142
- runAt: config.runAt,
143
- connectionRevision: config.connectionRevision,
144
- target: { ...config.target },
145
- },
146
- },
147
- },
148
- ports: [{ id: 'receipt', direction: 'output' }],
149
- },
150
- ],
31
+ scheduleAsync: (request) => scheduleSocialManagerPublicationAsync(input, runtime, mutex, request),
151
32
  };
152
33
  }
153
34
  /*** Register an externally effective node; no internal operation can bypass the Flow security permit. */
@@ -203,8 +84,7 @@ async function requireApprovalAsync(input, node, operationKey) {
203
84
  const scope = { tenantId: config.caller.tenantId, projectId: config.caller.projectId };
204
85
  const run = await input.flow.store.getRunAsync(scope, runId);
205
86
  const approval = await input.flow.store.getApprovalAsync(scope, 'social-approval:' + runId);
206
- if (run?.flow.id !== publicationId(config) ||
207
- run.flow.version !== 1 ||
87
+ if (run?.flow.version !== 1 ||
208
88
  approval?.runId !== runId ||
209
89
  approval.status !== 'approved' ||
210
90
  (approval.expiresAt !== undefined &&
@@ -0,0 +1,8 @@
1
+ import type { FlowRuntime } from '@ankhorage/flow';
2
+ import type { KeyedAsyncMutex } from '@ankhorage/utility/concurrency';
3
+ import type { SocialManagerPublicationDependencies, SocialManagerPublicationRequest } from '../../../types/socialManagerPublication.js';
4
+ /*** Persist one exact, independently approvable destination run; Flow owns scheduling and execution. */
5
+ export declare function scheduleSocialManagerPublicationAsync(input: SocialManagerPublicationDependencies, runtime: FlowRuntime, mutex: KeyedAsyncMutex<string>, request: SocialManagerPublicationRequest): Promise<{
6
+ readonly run: Awaited<ReturnType<FlowRuntime['triggerAsync']>>;
7
+ readonly approvalId: string;
8
+ }>;
@@ -0,0 +1,118 @@
1
+ import { assertCallerScope, readPublicationConfig, } from '../domain/publicationConfig.js';
2
+ import { readDestinationAsync, requireBindingAsync } from './resolveSocialManagerPublication.js';
3
+ import { socialManagerPublicationIdentity } from './socialManagerPublicationIdentity.js';
4
+ const capabilityId = 'projects.social.publication.execute';
5
+ const providerId = '@ankhorage/projects';
6
+ /*** Persist one exact, independently approvable destination run; Flow owns scheduling and execution. */
7
+ export async function scheduleSocialManagerPublicationAsync(input, runtime, mutex, request) {
8
+ return mutex.run(socialManagerPublicationIdentity(request), async () => {
9
+ const scope = { tenantId: request.caller.tenantId, projectId: request.caller.projectId };
10
+ const id = socialManagerPublicationIdentity(request);
11
+ const existing = await runtime.getWorkflowAsync(scope, id, 1);
12
+ const scheduledRequest = {
13
+ ...request,
14
+ runAt: request.runAt ?? existingRunAt(existing, input.scope) ?? currentTime(input),
15
+ };
16
+ const { caller, draftId, revision, destinationIndex, runAt } = scheduledRequest;
17
+ assertCallerScope(input.scope, caller);
18
+ assertScheduleInput(scheduledRequest);
19
+ const destination = await readDestinationAsync(input, scheduledRequest);
20
+ const binding = await requireBindingAsync(input, caller, destination);
21
+ const config = {
22
+ caller,
23
+ draftId,
24
+ revision,
25
+ destinationIndex,
26
+ runAt,
27
+ connectionRevision: binding.connection.revision,
28
+ target: binding.target,
29
+ };
30
+ const flow = createPublicationDefinition(config, id);
31
+ if (!existing)
32
+ await runtime.createDraftAsync(scope, flow);
33
+ else if (JSON.stringify(existing.definition) !== JSON.stringify(flow))
34
+ throw new Error('Social publication configuration changed.');
35
+ if (!existing?.publishedAt)
36
+ await runtime.publishAsync(scope, flow.id, flow.version);
37
+ const run = await runtime.triggerAsync({
38
+ scope,
39
+ flowId: flow.id,
40
+ triggerId: 'publish',
41
+ idempotencyKey: flow.id,
42
+ runAt,
43
+ });
44
+ const approvalId = await ensureApprovalAsync(input, runtime, scheduledRequest, run.id);
45
+ return { run, approvalId };
46
+ });
47
+ }
48
+ /*** Reuse the original immediate-run timestamp so an identical retry retains its immutable Flow definition. */
49
+ function existingRunAt(existing, scope) {
50
+ const node = existing?.definition.nodes.find((candidate) => candidate.id === 'publication');
51
+ return node === undefined ? undefined : readPublicationConfig(node, scope).runAt;
52
+ }
53
+ /*** Read the single clock boundary used when an immediate publication first becomes a scheduled Flow run. */
54
+ function currentTime(input) {
55
+ return (input.flow.clock?.now() ?? new Date()).toISOString();
56
+ }
57
+ /*** Create a pending approval only once, without resetting a previously resolved decision. */
58
+ async function ensureApprovalAsync(input, runtime, request, runId) {
59
+ const { caller } = request;
60
+ const scope = { tenantId: caller.tenantId, projectId: caller.projectId };
61
+ const approvalId = `social-approval:${runId}`;
62
+ if (!(await input.flow.store.getApprovalAsync(scope, approvalId)))
63
+ await runtime.requestApprovalAsync({
64
+ scope,
65
+ approval: {
66
+ id: approvalId,
67
+ runId,
68
+ status: 'pending',
69
+ requestedBy: caller.actorId,
70
+ requestedAt: currentTime(input),
71
+ },
72
+ });
73
+ return approvalId;
74
+ }
75
+ /*** Validate one exact destination revision and canonical UTC instant. */
76
+ function assertScheduleInput(request) {
77
+ const { caller, revision, destinationIndex, runAt } = request;
78
+ if (!caller.actorId.trim())
79
+ throw new Error('Social publication requires a caller.');
80
+ if (!Number.isSafeInteger(revision) ||
81
+ revision < 1 ||
82
+ !Number.isSafeInteger(destinationIndex) ||
83
+ destinationIndex < 0 ||
84
+ (runAt !== undefined &&
85
+ (!Number.isFinite(Date.parse(runAt)) || new Date(runAt).toISOString() !== runAt)))
86
+ throw new Error('Invalid Social Manager publication request.');
87
+ }
88
+ /*** Construct a server-owned graph that pins the approved revision and provider destination. */
89
+ function createPublicationDefinition(config, id) {
90
+ return {
91
+ id,
92
+ version: 1,
93
+ title: 'Social publication',
94
+ triggers: [{ id: 'publish', kind: 'manual' }],
95
+ edges: [],
96
+ nodes: [
97
+ {
98
+ id: 'publication',
99
+ capability: { providerId, capabilityId },
100
+ config: {
101
+ publication: {
102
+ kind: 'inline',
103
+ value: {
104
+ caller: { ...config.caller },
105
+ draftId: config.draftId,
106
+ revision: config.revision,
107
+ destinationIndex: config.destinationIndex,
108
+ runAt: config.runAt,
109
+ connectionRevision: config.connectionRevision,
110
+ target: { ...config.target },
111
+ },
112
+ },
113
+ },
114
+ ports: [{ id: 'receipt', direction: 'output' }],
115
+ },
116
+ ],
117
+ };
118
+ }
@@ -0,0 +1,3 @@
1
+ import type { SocialManagerPublicationRequest } from '../../../types/socialManagerPublication.js';
2
+ /*** Derive the stable Flow identity for one immutable Social publication intent. */
3
+ export declare function socialManagerPublicationIdentity(request: SocialManagerPublicationRequest): string;
@@ -0,0 +1,18 @@
1
+ import { createHash } from 'node:crypto';
2
+ /*** Derive the stable Flow identity for one immutable Social publication intent. */
3
+ export function socialManagerPublicationIdentity(request) {
4
+ const { caller, draftId, revision, destinationIndex, runAt } = request;
5
+ return ('social-' +
6
+ createHash('sha256')
7
+ .update(JSON.stringify([
8
+ caller.tenantId,
9
+ caller.projectId,
10
+ caller.environmentId,
11
+ caller.actorId,
12
+ draftId,
13
+ revision,
14
+ destinationIndex,
15
+ runAt ?? null,
16
+ ]))
17
+ .digest('hex'));
18
+ }
@@ -194,7 +194,7 @@ function validateDestination(capability, destination, media) {
194
194
  /*** Verify that the exact draft's text, link, and media content classes are enabled by this provider target. */
195
195
  function contentTypeErrors(capability, destination, media) {
196
196
  const required = [
197
- ...(destination.text.trim() ? ['text'] : []),
197
+ ...(destination.text.trim() && media.length === 0 ? ['text'] : []),
198
198
  ...(destination.link === undefined ? [] : ['link']),
199
199
  ...media.map((item) => item.kind),
200
200
  ];
@@ -2,6 +2,7 @@ import { join } from 'node:path';
2
2
  import { FileFlowPersistenceAdapter, FileFlowRuntimeStore } from '@ankhorage/flow';
3
3
  import { createSocialManagerMediaPreflight } from '../adapters/createSocialManagerMediaPreflight.js';
4
4
  import { createTrustedSocialManagerHostAsync } from './createTrustedSocialManagerHost.js';
5
+ import { targetForConnection } from './targetForConnection.js';
5
6
  /*** Compose a local host from the durable stores and deterministic provider fixtures selected by the loopback server. */
6
7
  export async function createTrustedSocialManagerLocalHostAsync({ input, persistence, fixtures, now, }) {
7
8
  const resolveBindingAsync = createBindingResolver(persistence.connection, fixtures, input.caller);
@@ -98,28 +99,6 @@ function createMediaResolver(media) {
98
99
  return items.flatMap((item) => (item === undefined ? [] : [item.media]));
99
100
  };
100
101
  }
101
- /*** Verify the durable connection owner and map its selected authorized target to the published provider vocabulary. */
102
- function targetForConnection(connection, targetId) {
103
- const target = connection.targets.find((candidate) => candidate.targetId === targetId);
104
- if (!target || connection.status !== 'connected')
105
- return undefined;
106
- const base = { accountId: connection.accountId, destinationId: target.targetId };
107
- switch (connection.provider) {
108
- case 'facebook-login':
109
- return { ...base, provider: 'facebook', accountType: 'page', destinationType: 'page' };
110
- case 'instagram-login':
111
- return {
112
- ...base,
113
- provider: 'instagram',
114
- accountType: 'business',
115
- destinationType: 'account',
116
- };
117
- case 'linkedin':
118
- return { ...base, provider: 'linkedin', accountType: 'member', destinationType: 'member' };
119
- case 'pinterest':
120
- return { ...base, provider: 'pinterest', accountType: 'business', destinationType: 'board' };
121
- }
122
- }
123
102
  /*** Select exactly one local provider fixture from the server-resolved target provider. */
124
103
  function providerFor(fixtures, target) {
125
104
  switch (target.provider) {
@@ -0,0 +1,4 @@
1
+ import type { ManagedConnection } from '@ankhorage/connection';
2
+ import type { SocialTargetRef } from '@ankhorage/social';
3
+ /*** Map one connected, provider-authorized target to the published Social provider vocabulary. */
4
+ export declare function targetForConnection(connection: ManagedConnection, targetId: string): SocialTargetRef | undefined;
@@ -0,0 +1,27 @@
1
+ /*** Map one connected, provider-authorized target to the published Social provider vocabulary. */
2
+ export function targetForConnection(connection, targetId) {
3
+ const target = connection.targets.find((candidate) => candidate.targetId === targetId);
4
+ if (!target || connection.status !== 'connected')
5
+ return undefined;
6
+ const base = { accountId: connection.accountId, destinationId: target.targetId };
7
+ switch (connection.provider) {
8
+ case 'facebook-login':
9
+ return { ...base, provider: 'facebook', accountType: 'page', destinationType: 'page' };
10
+ case 'instagram-login':
11
+ return {
12
+ ...base,
13
+ provider: 'instagram',
14
+ accountType: 'business',
15
+ destinationType: 'instagram-account',
16
+ };
17
+ case 'linkedin':
18
+ return { ...base, provider: 'linkedin', accountType: 'member', destinationType: 'member' };
19
+ case 'pinterest':
20
+ return {
21
+ ...base,
22
+ provider: 'pinterest',
23
+ accountType: 'pinterest-user',
24
+ destinationType: 'board',
25
+ };
26
+ }
27
+ }
@@ -1,3 +1,4 @@
1
+ import { quoteJavaScriptString } from '@ankhorage/utility/string';
1
2
  import { WORKER_ENTRY_SOURCE_PATH, WORKER_WEB_DIRECTORY } from '../constants/worker.js';
2
3
  /** Maximum requests per budget key admitted by the generated Worker. */
3
4
  const WORKER_REQUEST_LIMIT = 10;
@@ -10,7 +11,6 @@ export function createWorkerMaterializationFile(input) {
10
11
  }
11
12
  /*** Render the Worker module that delegates trusted API operations to the published host boundary. */
12
13
  function createWorkerEntrySource(input) {
13
- const operations = Object.fromEntries(input.operations.map((operation) => [operation, operation]));
14
14
  return `import { createNeonServerCallerAuthenticationPort } from '@ankhorage/auth-neon';
15
15
  import { createNeonPostgresRequestBudget } from '@ankhorage/db-postgres';
16
16
  import { createTrustedZefixWorkerEntry } from '@ankhorage/projects/worker';
@@ -19,10 +19,12 @@ import { createTrustedZefixWorkerEntry } from '@ankhorage/projects/worker';
19
19
  // DATABASE_URL, ZEFIX_CREDENTIALS and ANKH_AUTH_ALLOWED_SUBJECTS are Worker secret bindings;
20
20
  // NEON_AUTH_BASE_URL and NEON_AUTH_JWKS_URL are bound from the provisioned Neon Auth outputs.
21
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)},
22
+ appId: ${quoteJavaScriptString(input.appId)},
23
+ projectId: ${quoteJavaScriptString(input.projectId)},
24
+ environment: ${quoteJavaScriptString(input.environment)},
25
+ operations: {
26
+ ${renderWorkerOperations(input.operations)}
27
+ },
26
28
  createCallerAuthentication: (env) =>
27
29
  createNeonServerCallerAuthenticationPort({
28
30
  authUrl: env.NEON_AUTH_BASE_URL ?? '',
@@ -36,6 +38,12 @@ export default createTrustedZefixWorkerEntry({
36
38
  });
37
39
  `;
38
40
  }
41
+ /*** Render the declared Worker operation map in the generated application's canonical source format. */
42
+ function renderWorkerOperations(operations) {
43
+ return operations
44
+ .map((operation) => ` ${quoteJavaScriptString(operation)}: ${quoteJavaScriptString(operation)},`)
45
+ .join('\n');
46
+ }
39
47
  /*** Render the Worker module for an application without server APIs: every Worker-routed request is unknown. */
40
48
  function createStaticWorkerEntrySource() {
41
49
  return `// Server-only: bundled to dist/worker/index.js, never into the public ${WORKER_WEB_DIRECTORY} assets.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/projects",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Standalone project identity and repository actions.",
5
5
  "keywords": [
6
6
  "ankhorage",
@@ -58,7 +58,7 @@
58
58
  "version-packages": "ankhorage-changeset version"
59
59
  },
60
60
  "devDependencies": {
61
- "@ankhorage/devtools": "^2.12.19",
61
+ "@ankhorage/devtools": "^2.13.4",
62
62
  "@ankhorage/paradox": "^0.6.2",
63
63
  "@types/bun": "^1.4.5",
64
64
  "@types/node": "^26.6.11",
@@ -70,14 +70,14 @@
70
70
  "@ankhorage/connection": "^0.3.0",
71
71
  "@ankhorage/contracts": "^28.0.0",
72
72
  "@ankhorage/data-sources": "^2.4.0",
73
- "@ankhorage/expo-runtime": "^7.10.0",
73
+ "@ankhorage/expo-runtime": "^7.10.4",
74
74
  "@ankhorage/flow": "^0.12.0",
75
75
  "@ankhorage/navigator": "^3.9.0",
76
76
  "@ankhorage/permissions": "^0.2.64",
77
77
  "@ankhorage/runtime": "^5.8.1",
78
78
  "@ankhorage/secrets": "^0.3.2",
79
79
  "@ankhorage/social": "^0.7.0",
80
- "@ankhorage/templates": "^12.8.0",
80
+ "@ankhorage/templates": "^12.9.4",
81
81
  "@ankhorage/utility": "^1.11.0"
82
82
  },
83
83
  "ankh": {
@@ -1,2 +0,0 @@
1
- /*** Render serializable data as deterministic, policy-compliant TypeScript source. */
2
- export declare function formatTypeScriptLiteral(value: unknown, depth?: number): string;
@@ -1,46 +0,0 @@
1
- /*** Render serializable data as deterministic, policy-compliant TypeScript source. */
2
- export function formatTypeScriptLiteral(value, depth = 0) {
3
- if (value === null)
4
- return 'null';
5
- if (typeof value === 'string')
6
- return formatTypeScriptString(value);
7
- if (typeof value === 'number' || typeof value === 'boolean')
8
- return String(value);
9
- if (Array.isArray(value))
10
- return formatTypeScriptArray(value, depth);
11
- if (isRecord(value))
12
- return formatTypeScriptRecord(value, depth);
13
- throw new Error('Generated manifest values must be JSON-serializable.');
14
- }
15
- /*** Render a serializable array with canonical indentation and trailing commas. */
16
- function formatTypeScriptArray(values, depth) {
17
- if (values.length === 0)
18
- return '[]';
19
- const indentation = ' '.repeat(depth + 1);
20
- const closingIndentation = ' '.repeat(depth);
21
- return `[\n${values.map((value) => `${indentation}${formatTypeScriptLiteral(value, depth + 1)},`).join('\n')}\n${closingIndentation}]`;
22
- }
23
- /*** Render an object with sorted keys so equal manifests produce equal source. */
24
- function formatTypeScriptRecord(value, depth) {
25
- const entries = Object.entries(value)
26
- .filter(([, entryValue]) => entryValue !== undefined)
27
- .sort(([left], [right]) => left.localeCompare(right));
28
- if (entries.length === 0)
29
- return '{}';
30
- const indentation = ' '.repeat(depth + 1);
31
- const closingIndentation = ' '.repeat(depth);
32
- return `{\n${entries.map(([key, entryValue]) => `${indentation}${formatTypeScriptPropertyKey(key)}: ${formatTypeScriptLiteral(entryValue, depth + 1)},`).join('\n')}\n${closingIndentation}}`;
33
- }
34
- /*** Use an identifier key where TypeScript permits it and quote required property names. */
35
- function formatTypeScriptPropertyKey(key) {
36
- return /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(key) ? key : formatTypeScriptString(key);
37
- }
38
- /*** Emit a single-quoted TypeScript string without a formatter runtime dependency. */
39
- function formatTypeScriptString(value) {
40
- const jsonContent = JSON.stringify(value).slice(1, -1);
41
- return `'${jsonContent.replaceAll("'", "\\'").replaceAll('\u2028', '\\u2028').replaceAll('\u2029', '\\u2029')}'`;
42
- }
43
- /*** Narrow a JSON-compatible object for recursive rendering. */
44
- function isRecord(value) {
45
- return typeof value === 'object' && value !== null && !Array.isArray(value);
46
- }