@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.
- package/README.md +20 -12
- package/dist/capabilities/index.d.ts +330 -0
- package/dist/capabilities/index.js +194 -0
- package/dist/capabilities/socialManagerMediaAnalytics.d.ts +92 -0
- package/dist/capabilities/socialManagerMediaAnalytics.js +75 -0
- package/dist/features/projects/composition/composeGeneratedRuntimeMaterialization.d.ts +1 -0
- package/dist/features/projects/composition/composeGeneratedRuntimeMaterialization.js +13 -5
- package/dist/features/projects/composition/createExpoProjectMaterializer.d.ts +4 -6
- package/dist/features/projects/composition/createExpoProjectMaterializer.js +29 -36
- package/dist/features/projects/composition/createNavigatorMaterializationFiles.d.ts +14 -0
- package/dist/features/projects/composition/createNavigatorMaterializationFiles.js +19 -0
- package/dist/features/projects/composition/createRootNavigatorGenerationOptions.d.ts +9 -0
- package/dist/features/projects/composition/createRootNavigatorGenerationOptions.js +10 -0
- package/dist/features/projects/composition/createSocialManagerServerFiles.d.ts +6 -0
- package/dist/features/projects/composition/createSocialManagerServerFiles.js +16 -0
- package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemRepositories.d.ts +16 -0
- package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemRepositories.js +201 -0
- package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemStoreAsync.d.ts +25 -0
- package/dist/features/trusted-social-manager-host/adapters/createConnectionFileSystemStoreAsync.js +72 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerDraftStoreAsync.d.ts +7 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerDraftStoreAsync.js +160 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerFlowSecurityAsync.d.ts +19 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerFlowSecurityAsync.js +176 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaPreflight.d.ts +4 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaPreflight.js +37 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.d.ts +7 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.js +242 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialOperationStoresAsync.d.ts +13 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialOperationStoresAsync.js +244 -0
- package/dist/features/trusted-social-manager-host/adapters/projectSocialManagerConnection.d.ts +53 -0
- package/dist/features/trusted-social-manager-host/adapters/projectSocialManagerConnection.js +42 -0
- package/dist/features/trusted-social-manager-host/application/createSocialManagerPublicationRuntime.d.ts +10 -0
- package/dist/features/trusted-social-manager-host/application/createSocialManagerPublicationRuntime.js +240 -0
- package/dist/features/trusted-social-manager-host/application/resolveSocialManagerPublication.d.ts +22 -0
- package/dist/features/trusted-social-manager-host/application/resolveSocialManagerPublication.js +97 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerCapabilityOperations.d.ts +22 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerCapabilityOperations.js +224 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerConnectionOperations.d.ts +20 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerConnectionOperations.js +152 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerLocalProviderFixtures.d.ts +22 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerLocalProviderFixtures.js +271 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.d.ts +14 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.js +72 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerProvider.d.ts +20 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerProvider.js +20 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerPublicationOperations.d.ts +15 -0
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerPublicationOperations.js +185 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerFileSystemPersistenceAsync.d.ts +14 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerFileSystemPersistenceAsync.js +17 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.d.ts +51 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.js +188 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalHostAsync.d.ts +18 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalHostAsync.js +177 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalServerAsync.d.ts +26 -0
- package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerLocalServerAsync.js +66 -0
- package/dist/features/trusted-social-manager-host/domain/publicationConfig.d.ts +18 -0
- package/dist/features/trusted-social-manager-host/domain/publicationConfig.js +77 -0
- package/dist/features/trusted-social-manager-host/domain/readSocialManagerConnectionRequest.d.ts +54 -0
- package/dist/features/trusted-social-manager-host/domain/readSocialManagerConnectionRequest.js +77 -0
- package/dist/features/trusted-social-manager-host/domain/readSocialManagerDraftContent.d.ts +3 -0
- package/dist/features/trusted-social-manager-host/domain/readSocialManagerDraftContent.js +47 -0
- package/dist/features/trusted-social-manager-host/domain/socialManagerConnectionIdentity.d.ts +17 -0
- package/dist/features/trusted-social-manager-host/domain/socialManagerConnectionIdentity.js +17 -0
- package/dist/features/trusted-zefix-host/composition/createTrustedZefixHost.d.ts +1 -2
- package/dist/features/trusted-zefix-host/composition/createTrustedZefixHost.js +3 -59
- package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.d.ts +36 -0
- package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerEntry.js +105 -0
- package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.d.ts +35 -0
- package/dist/features/trusted-zefix-host/composition/createTrustedZefixWorkerHandler.js +92 -0
- package/dist/features/trusted-zefix-host/composition/zefixOperations.d.ts +20 -0
- package/dist/features/trusted-zefix-host/composition/zefixOperations.js +57 -0
- package/dist/features/worker-materialization/composition/composeWorkerMaterialization.d.ts +13 -0
- package/dist/features/worker-materialization/composition/composeWorkerMaterialization.js +90 -0
- package/dist/features/worker-materialization/composition/createWorkerMaterializationFile.d.ts +13 -0
- package/dist/features/worker-materialization/composition/createWorkerMaterializationFile.js +48 -0
- package/dist/features/worker-materialization/constants/worker.d.ts +6 -0
- package/dist/features/worker-materialization/constants/worker.js +6 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +16 -0
- package/dist/types/socialManager.d.ts +77 -0
- package/dist/types/socialManager.js +1 -0
- package/dist/types/socialManagerPublication.d.ts +27 -0
- package/dist/types/socialManagerPublication.js +1 -0
- package/dist/worker/index.d.ts +3 -0
- package/dist/worker/index.js +3 -0
- package/package.json +511 -9
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
import { readPublicationConfig } from '../domain/publicationConfig.js';
|
|
3
|
+
/*** Bind protected Flow publication lifecycle operations to the authenticated caller. */
|
|
4
|
+
export function createSocialManagerPublicationOperations(input, callerOf) {
|
|
5
|
+
return {
|
|
6
|
+
'projects.social.publications.prepare': createOperation((request) => schedulePublicationAsync(input.runtime, callerOf(request), request.body, true)),
|
|
7
|
+
'projects.social.publications.publish': createOperation((request) => schedulePublicationAsync(input.runtime, callerOf(request), request.body, false)),
|
|
8
|
+
'projects.social.publications.schedule': createOperation((request) => schedulePublicationAsync(input.runtime, callerOf(request), request.body, true)),
|
|
9
|
+
'projects.social.publications.cancel': deleteOperation((request) => cancelPublicationAsync(input.runtime, callerOf(request), request.params.runId)),
|
|
10
|
+
'projects.social.publications.execution.status': readOperation((request) => readPublicationAsync(input.runtime, callerOf(request), request.params.runId)),
|
|
11
|
+
'projects.social.publications.approval.status': readOperation((request) => readApprovalAsync(input.runtime, callerOf(request), request.params.runId)),
|
|
12
|
+
'projects.social.publications.approval.resolve': updateOperation((request) => resolveApprovalAsync(input.runtime, callerOf(request), request.params.runId, request.body)),
|
|
13
|
+
'projects.social.publications.scheduled.list': readOperation((request) => listPublicationsAsync(input.runtime, callerOf(request), true)),
|
|
14
|
+
'projects.social.publications.history.list': readOperation((request) => listPublicationsAsync(input.runtime, callerOf(request), false)),
|
|
15
|
+
'projects.social.publications.receipts.list': readOperation((request) => listReceiptsAsync(input.runtime, callerOf(request))),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/*** Prepare a server-owned Flow run and its exact approval without trusting caller identity JSON. */
|
|
19
|
+
async function schedulePublicationAsync(runtime, caller, body, scheduled) {
|
|
20
|
+
const request = caller && readPublicationRequest(body, caller, scheduled);
|
|
21
|
+
if (!request)
|
|
22
|
+
return invalidResponse();
|
|
23
|
+
try {
|
|
24
|
+
return { status: 202, body: await runtime.scheduleAsync(request) };
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return invalidResponse();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/*** Cancel only a nonterminal Social publication run in the authenticated caller scope. */
|
|
31
|
+
async function cancelPublicationAsync(runtime, caller, runId) {
|
|
32
|
+
const run = caller && runId ? await readCallerPublicationAsync(runtime, caller, runId) : undefined;
|
|
33
|
+
if (!caller || !run)
|
|
34
|
+
return missingResponse();
|
|
35
|
+
const cancelled = await runtime.runtime.cancelRunAsync(scopeOf(caller), run.id);
|
|
36
|
+
return cancelled ? { body: projectRun(cancelled) } : missingResponse();
|
|
37
|
+
}
|
|
38
|
+
/*** Project one caller-owned Social publication execution without exposing Flow node configuration. */
|
|
39
|
+
async function readPublicationAsync(runtime, caller, runId) {
|
|
40
|
+
const run = caller && runId ? await readCallerPublicationAsync(runtime, caller, runId) : undefined;
|
|
41
|
+
return run ? { body: projectRun(run) } : missingResponse();
|
|
42
|
+
}
|
|
43
|
+
/*** Read approval availability only after resolving the caller-owned durable publication run. */
|
|
44
|
+
async function readApprovalAsync(runtime, caller, runId) {
|
|
45
|
+
const run = caller && runId ? await readCallerPublicationAsync(runtime, caller, runId) : undefined;
|
|
46
|
+
if (!caller || !run)
|
|
47
|
+
return missingResponse();
|
|
48
|
+
const approval = await runtime.runtime.getApprovalAvailabilityAsync({
|
|
49
|
+
scope: scopeOf(caller),
|
|
50
|
+
flowId: run.flow.id,
|
|
51
|
+
flowVersion: run.flow.version,
|
|
52
|
+
runId: run.id,
|
|
53
|
+
approvalId: `social-approval:${run.id}`,
|
|
54
|
+
});
|
|
55
|
+
return approval ? { body: approval } : missingResponse();
|
|
56
|
+
}
|
|
57
|
+
/*** Resolve the exact pending approval as the authenticated actor, never an actor supplied by JSON. */
|
|
58
|
+
async function resolveApprovalAsync(runtime, caller, runId, body) {
|
|
59
|
+
const run = caller && runId ? await readCallerPublicationAsync(runtime, caller, runId) : undefined;
|
|
60
|
+
const approved = isRecord(body) && typeof body.approved === 'boolean' ? body.approved : undefined;
|
|
61
|
+
if (!caller || !run || approved === undefined)
|
|
62
|
+
return missingResponse();
|
|
63
|
+
const approval = await runtime.runtime.resolveApprovalAsync({
|
|
64
|
+
scope: scopeOf(caller),
|
|
65
|
+
actorId: caller.actorId,
|
|
66
|
+
approvalId: `social-approval:${run.id}`,
|
|
67
|
+
approved,
|
|
68
|
+
});
|
|
69
|
+
return approval ? { body: approval } : missingResponse();
|
|
70
|
+
}
|
|
71
|
+
/*** List only the caller's Social runs, partitioned into active queue and completed history. */
|
|
72
|
+
async function listPublicationsAsync(runtime, caller, scheduled) {
|
|
73
|
+
if (!caller)
|
|
74
|
+
return { body: [] };
|
|
75
|
+
const runs = await listCallerPublicationRunsAsync(runtime, caller);
|
|
76
|
+
const publications = runs;
|
|
77
|
+
return { body: publications.filter((run) => isActive(run) === scheduled).map(projectRun) };
|
|
78
|
+
}
|
|
79
|
+
/*** Project redacted Social receipts from terminal or active publication run outputs. */
|
|
80
|
+
async function listReceiptsAsync(runtime, caller) {
|
|
81
|
+
if (!caller)
|
|
82
|
+
return { body: [] };
|
|
83
|
+
const runs = await listCallerPublicationRunsAsync(runtime, caller);
|
|
84
|
+
return {
|
|
85
|
+
body: runs.flatMap((run) => receiptOf(run) ?? []),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/*** Parse only the serializable request fields whose ownership begins at the authenticated caller. */
|
|
89
|
+
function readPublicationRequest(body, caller, scheduled) {
|
|
90
|
+
if (!isRecord(body) || typeof body.draftId !== 'string' || !body.draftId.trim())
|
|
91
|
+
return undefined;
|
|
92
|
+
const { revision, destinationIndex, runAt } = body;
|
|
93
|
+
if (typeof revision !== 'number' ||
|
|
94
|
+
typeof destinationIndex !== 'number' ||
|
|
95
|
+
!Number.isSafeInteger(revision) ||
|
|
96
|
+
!Number.isSafeInteger(destinationIndex))
|
|
97
|
+
return undefined;
|
|
98
|
+
if (scheduled && typeof runAt !== 'string')
|
|
99
|
+
return undefined;
|
|
100
|
+
if (!scheduled && runAt !== undefined)
|
|
101
|
+
return undefined;
|
|
102
|
+
return {
|
|
103
|
+
caller,
|
|
104
|
+
draftId: body.draftId,
|
|
105
|
+
revision,
|
|
106
|
+
destinationIndex,
|
|
107
|
+
...(typeof runAt === 'string' ? { runAt } : {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/*** Load a caller-scoped publication and reject unrelated Flow runs from this host projection. */
|
|
111
|
+
async function readCallerPublicationAsync(runtime, caller, runId) {
|
|
112
|
+
const run = await runtime.runtime.getRunAsync(scopeOf(caller), runId);
|
|
113
|
+
return run && (await isCallerPublicationRunAsync(runtime, caller, run)) ? run : undefined;
|
|
114
|
+
}
|
|
115
|
+
/*** List only runs whose immutable config matches the current environment and authorized project. */
|
|
116
|
+
async function listCallerPublicationRunsAsync(runtime, caller) {
|
|
117
|
+
const runs = await runtime.runtime.listRunsAsync(scopeOf(caller));
|
|
118
|
+
const matches = await Promise.all(runs.map(async (run) => (await isCallerPublicationRunAsync(runtime, caller, run)) ? run : undefined));
|
|
119
|
+
return matches.filter((run) => run !== undefined);
|
|
120
|
+
}
|
|
121
|
+
/*** Bind a Flow run to the configured environment; host authorization retains collaborator access. */
|
|
122
|
+
async function isCallerPublicationRunAsync(runtime, caller, run) {
|
|
123
|
+
if (!run.flow.id.startsWith('social-'))
|
|
124
|
+
return false;
|
|
125
|
+
const workflow = await runtime.runtime.getWorkflowAsync(scopeOf(caller), run.flow.id, run.flow.version);
|
|
126
|
+
const node = workflow?.definition.nodes.find((candidate) => candidate.id === 'publication');
|
|
127
|
+
if (!node)
|
|
128
|
+
return false;
|
|
129
|
+
try {
|
|
130
|
+
const config = readPublicationConfig(node, caller);
|
|
131
|
+
return (config.caller.tenantId === caller.tenantId &&
|
|
132
|
+
config.caller.projectId === caller.projectId &&
|
|
133
|
+
config.caller.environmentId === caller.environmentId);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/*** Identify Flow statuses whose durable work is still eligible for future execution. */
|
|
140
|
+
function isActive(run) {
|
|
141
|
+
return !['cancelled', 'failed', 'succeeded', 'timed_out'].includes(run.status);
|
|
142
|
+
}
|
|
143
|
+
/*** Project only redaction-safe execution status from the canonical Flow run snapshot. */
|
|
144
|
+
function projectRun(run) {
|
|
145
|
+
return {
|
|
146
|
+
id: run.id,
|
|
147
|
+
status: run.status,
|
|
148
|
+
createdAt: run.createdAt,
|
|
149
|
+
...(run.startedAt === undefined ? {} : { startedAt: run.startedAt }),
|
|
150
|
+
...(run.completedAt === undefined ? {} : { completedAt: run.completedAt }),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/*** Extract the existing redacted publication receipt output without surfacing arbitrary step values. */
|
|
154
|
+
function receiptOf(run) {
|
|
155
|
+
const value = run.steps.find((step) => step.nodeId === 'publication')?.output?.receipt;
|
|
156
|
+
return value?.kind === 'inline' && isRecord(value.value) ? [value.value] : undefined;
|
|
157
|
+
}
|
|
158
|
+
/*** Derive the server-authoritative Flow resource scope from the authenticated caller. */
|
|
159
|
+
function scopeOf(caller) {
|
|
160
|
+
return { tenantId: caller.tenantId, projectId: caller.projectId };
|
|
161
|
+
}
|
|
162
|
+
/*** Declare one read operation using the canonical HTTP method and data intent. */
|
|
163
|
+
function readOperation(handler) {
|
|
164
|
+
return { intent: 'read', method: 'GET', handler };
|
|
165
|
+
}
|
|
166
|
+
/*** Declare one creation operation using the canonical HTTP method and data intent. */
|
|
167
|
+
function createOperation(handler) {
|
|
168
|
+
return { intent: 'create', method: 'POST', handler };
|
|
169
|
+
}
|
|
170
|
+
/*** Declare one resolution operation using the canonical update intent. */
|
|
171
|
+
function updateOperation(handler) {
|
|
172
|
+
return { intent: 'update', method: 'POST', handler };
|
|
173
|
+
}
|
|
174
|
+
/*** Declare one cancellation operation using the canonical delete method and intent. */
|
|
175
|
+
function deleteOperation(handler) {
|
|
176
|
+
return { intent: 'delete', method: 'DELETE', handler };
|
|
177
|
+
}
|
|
178
|
+
/*** Return a stable validation error without reflecting untrusted publication input. */
|
|
179
|
+
function invalidResponse() {
|
|
180
|
+
return { status: 400, body: { error: { code: 'invalid_publication_request' } } };
|
|
181
|
+
}
|
|
182
|
+
/*** Hide caller ownership and publication existence behind one stable response. */
|
|
183
|
+
function missingResponse() {
|
|
184
|
+
return { status: 404, body: { error: { code: 'publication_not_found' } } };
|
|
185
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SocialManagerDraftStore, SocialManagerMediaStore } from '../../../types/socialManager.js';
|
|
2
|
+
import { type ConnectionFileSystemStore } from '../adapters/createConnectionFileSystemStoreAsync.js';
|
|
3
|
+
import { type SocialOperationStores } from '../adapters/createSocialOperationStoresAsync.js';
|
|
4
|
+
export type TrustedSocialManagerFileSystemPersistence = Readonly<{
|
|
5
|
+
drafts: SocialManagerDraftStore;
|
|
6
|
+
media: SocialManagerMediaStore;
|
|
7
|
+
connection: ConnectionFileSystemStore;
|
|
8
|
+
operations: SocialOperationStores;
|
|
9
|
+
}>;
|
|
10
|
+
/***
|
|
11
|
+
* Compose the private, single-writer local stores required by a trusted Social Manager host.
|
|
12
|
+
* Credentials remain behind the injected trusted authorization and provider boundaries.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createTrustedSocialManagerFileSystemPersistenceAsync(directory: string): Promise<TrustedSocialManagerFileSystemPersistence>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createConnectionFileSystemStoreAsync, } from '../adapters/createConnectionFileSystemStoreAsync.js';
|
|
2
|
+
import { createSocialManagerDraftStoreAsync } from '../adapters/createSocialManagerDraftStoreAsync.js';
|
|
3
|
+
import { createSocialManagerMediaStoreAsync } from '../adapters/createSocialManagerMediaStoreAsync.js';
|
|
4
|
+
import { createSocialOperationStoresAsync, } from '../adapters/createSocialOperationStoresAsync.js';
|
|
5
|
+
/***
|
|
6
|
+
* Compose the private, single-writer local stores required by a trusted Social Manager host.
|
|
7
|
+
* Credentials remain behind the injected trusted authorization and provider boundaries.
|
|
8
|
+
*/
|
|
9
|
+
export async function createTrustedSocialManagerFileSystemPersistenceAsync(directory) {
|
|
10
|
+
const [drafts, media, connection, operations] = await Promise.all([
|
|
11
|
+
createSocialManagerDraftStoreAsync(directory),
|
|
12
|
+
createSocialManagerMediaStoreAsync(directory),
|
|
13
|
+
createConnectionFileSystemStoreAsync(directory),
|
|
14
|
+
createSocialOperationStoresAsync(directory),
|
|
15
|
+
]);
|
|
16
|
+
return { drafts, media, connection, operations };
|
|
17
|
+
}
|
package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ApiRequest, ComposeAuthorizedApiRuntimeOptions } from '@ankhorage/api';
|
|
2
|
+
import { type FastifyInstance, type RegisterFastifyApiOptions } from '@ankhorage/api-fastify';
|
|
3
|
+
import type { InternalRestApiDefinition } from '@ankhorage/contracts/data';
|
|
4
|
+
import type { SocialManagerCaller, SocialManagerDraftStore, SocialManagerScope } from '../../../types/socialManager.js';
|
|
5
|
+
import type { SocialManagerPublicationDependencies } from '../../../types/socialManagerPublication.js';
|
|
6
|
+
import { type CreateSocialManagerFlowSecurityInput } from '../adapters/createSocialManagerFlowSecurityAsync.js';
|
|
7
|
+
import { type SocialManagerCapabilityHostDependencies } from './createSocialManagerCapabilityOperations.js';
|
|
8
|
+
import { type SocialManagerConnectionHostDependencies } from './createSocialManagerConnectionOperations.js';
|
|
9
|
+
import { type SocialManagerMediaHostDependencies } from './createSocialManagerMediaOperations.js';
|
|
10
|
+
import { type SocialManagerPublicationHostDependencies } from './createSocialManagerPublicationOperations.js';
|
|
11
|
+
export type CreateTrustedSocialManagerHostInput = Readonly<{
|
|
12
|
+
appId: string;
|
|
13
|
+
scope: SocialManagerScope;
|
|
14
|
+
definition: InternalRestApiDefinition;
|
|
15
|
+
drafts: SocialManagerDraftStore;
|
|
16
|
+
connection?: SocialManagerConnectionHostDependencies;
|
|
17
|
+
media?: SocialManagerMediaHostDependencies;
|
|
18
|
+
capabilities?: SocialManagerCapabilityHostDependencies;
|
|
19
|
+
publication?: SocialManagerPublicationHostDependencies;
|
|
20
|
+
authenticateCallerAsync: (request: ApiRequest) => Promise<SocialManagerCaller | undefined>;
|
|
21
|
+
authorizeCallerAsync: (input: Readonly<{
|
|
22
|
+
caller: SocialManagerCaller;
|
|
23
|
+
appId: string;
|
|
24
|
+
operationId: string;
|
|
25
|
+
}>) => Promise<boolean>;
|
|
26
|
+
}>;
|
|
27
|
+
export type CreateTrustedSocialManagerHostAsyncInput = Omit<CreateTrustedSocialManagerHostInput, 'publication'> & Readonly<{
|
|
28
|
+
publication: Omit<SocialManagerPublicationDependencies, 'flow'> & {
|
|
29
|
+
readonly flow: Omit<SocialManagerPublicationDependencies['flow'], 'security'>;
|
|
30
|
+
readonly security: Omit<CreateSocialManagerFlowSecurityInput, 'scope' | 'store'> & {
|
|
31
|
+
readonly directory: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
export type TrustedSocialManagerHost = Readonly<{
|
|
36
|
+
composition: ComposeAuthorizedApiRuntimeOptions;
|
|
37
|
+
registerFastifyAsync: (server: FastifyInstance, options?: RegisterFastifyApiOptions) => Promise<unknown>;
|
|
38
|
+
startWorkerAsync?: () => Readonly<{
|
|
39
|
+
stop: () => Promise<void>;
|
|
40
|
+
}>;
|
|
41
|
+
}>;
|
|
42
|
+
/***
|
|
43
|
+
* Compose the Social Manager draft operations with authenticated, scoped API delivery.
|
|
44
|
+
* Unimplemented provider or execution operations are not registered or simulated.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createTrustedSocialManagerHost(input: CreateTrustedSocialManagerHostInput): TrustedSocialManagerHost;
|
|
47
|
+
/***
|
|
48
|
+
* Compose the canonical durable Flow security port and publication runtime before HTTP delivery.
|
|
49
|
+
* The embedding host supplies its durable store, audit, grant, rate-limit, and secret boundaries.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createTrustedSocialManagerHostAsync(input: CreateTrustedSocialManagerHostAsyncInput): Promise<TrustedSocialManagerHost>;
|
package/dist/features/trusted-social-manager-host/composition/createTrustedSocialManagerHost.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { registerAuthorizedFastifyApiAsync, } from '@ankhorage/api-fastify';
|
|
2
|
+
import { startFlowWorkerAsync } from '@ankhorage/flow/server';
|
|
3
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
4
|
+
import { CAPABILITIES } from '../../../capabilities/index.js';
|
|
5
|
+
import { createSocialManagerFlowSecurityAsync, } from '../adapters/createSocialManagerFlowSecurityAsync.js';
|
|
6
|
+
import { createSocialManagerPublicationRuntime } from '../application/createSocialManagerPublicationRuntime.js';
|
|
7
|
+
import { readSocialManagerDraftContent } from '../domain/readSocialManagerDraftContent.js';
|
|
8
|
+
import { createSocialManagerCapabilityOperations, } from './createSocialManagerCapabilityOperations.js';
|
|
9
|
+
import { createSocialManagerConnectionOperations, } from './createSocialManagerConnectionOperations.js';
|
|
10
|
+
import { createSocialManagerMediaOperations, } from './createSocialManagerMediaOperations.js';
|
|
11
|
+
import { createSocialManagerPublicationOperations, } from './createSocialManagerPublicationOperations.js';
|
|
12
|
+
/***
|
|
13
|
+
* Compose the Social Manager draft operations with authenticated, scoped API delivery.
|
|
14
|
+
* Unimplemented provider or execution operations are not registered or simulated.
|
|
15
|
+
*/
|
|
16
|
+
export function createTrustedSocialManagerHost(input) {
|
|
17
|
+
const scope = Object.freeze({ ...input.scope });
|
|
18
|
+
assertHostIdentity(input.appId, scope);
|
|
19
|
+
const callers = new WeakMap();
|
|
20
|
+
const operations = {
|
|
21
|
+
...createDraftOperations(input.drafts, scope),
|
|
22
|
+
...(input.connection === undefined
|
|
23
|
+
? {}
|
|
24
|
+
: createSocialManagerConnectionOperations(input.connection, (request) => callers.get(request))),
|
|
25
|
+
...(input.media === undefined
|
|
26
|
+
? {}
|
|
27
|
+
: createSocialManagerMediaOperations(input.media, (request) => callers.get(request))),
|
|
28
|
+
...(input.capabilities === undefined
|
|
29
|
+
? {}
|
|
30
|
+
: createSocialManagerCapabilityOperations(input.capabilities, (request) => callers.get(request))),
|
|
31
|
+
...(input.publication === undefined
|
|
32
|
+
? {}
|
|
33
|
+
: createSocialManagerPublicationOperations(input.publication, (request) => callers.get(request))),
|
|
34
|
+
};
|
|
35
|
+
const composition = createHostComposition(input, scope, operations, callers);
|
|
36
|
+
return {
|
|
37
|
+
composition,
|
|
38
|
+
registerFastifyAsync: (server, options) => registerAuthorizedFastifyApiAsync(server, composition, options),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/***
|
|
42
|
+
* Compose the canonical durable Flow security port and publication runtime before HTTP delivery.
|
|
43
|
+
* The embedding host supplies its durable store, audit, grant, rate-limit, and secret boundaries.
|
|
44
|
+
*/
|
|
45
|
+
export async function createTrustedSocialManagerHostAsync(input) {
|
|
46
|
+
const { publication } = input;
|
|
47
|
+
const security = await createSocialManagerFlowSecurityAsync(publication.security.directory, {
|
|
48
|
+
...publication.security,
|
|
49
|
+
scope: input.scope,
|
|
50
|
+
store: publication.flow.store,
|
|
51
|
+
});
|
|
52
|
+
const runtime = createSocialManagerPublicationRuntime({
|
|
53
|
+
...publication,
|
|
54
|
+
flow: { ...publication.flow, security },
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
...createTrustedSocialManagerHost({ ...input, publication: { runtime } }),
|
|
58
|
+
// The worker is deliberately created from this exact runtime; a second scheduler would
|
|
59
|
+
// break durable publication and approval ownership across the HTTP and worker boundaries.
|
|
60
|
+
startWorkerAsync: () => startFlowWorkerAsync({ runtime: runtime.runtime }),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/*** Bind declared API operations to the verified caller and canonical capability catalog. */
|
|
64
|
+
function createHostComposition(input, scope, operations, callers) {
|
|
65
|
+
return {
|
|
66
|
+
definition: input.definition,
|
|
67
|
+
context: { appId: input.appId, projectId: scope.projectId },
|
|
68
|
+
authorizeAsync: async ({ binding, request }) => authorizeAsync(input, scope, binding.operationId, request, callers),
|
|
69
|
+
resolveHandler: ({ binding, declaration, context }) => {
|
|
70
|
+
const capability = CAPABILITIES.find((candidate) => candidate.id === declaration.capability);
|
|
71
|
+
const operation = Object.hasOwn(operations, binding.operationId)
|
|
72
|
+
? operations[binding.operationId]
|
|
73
|
+
: undefined;
|
|
74
|
+
if (!capability ||
|
|
75
|
+
!operation ||
|
|
76
|
+
binding.operationId !== capability.id ||
|
|
77
|
+
binding.operation.intent !== operation.intent ||
|
|
78
|
+
binding.method !== operation.method) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
capability,
|
|
83
|
+
approval: {
|
|
84
|
+
operationId: binding.operationId,
|
|
85
|
+
intent: operation.intent,
|
|
86
|
+
method: operation.method,
|
|
87
|
+
capabilityId: capability.id,
|
|
88
|
+
owner: capability.owner,
|
|
89
|
+
scope: context,
|
|
90
|
+
},
|
|
91
|
+
handler: operation.handler,
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/*** Reject incomplete server-owned identity before exposing operations. */
|
|
97
|
+
function assertHostIdentity(appId, scope) {
|
|
98
|
+
if (!appId.trim() ||
|
|
99
|
+
!scope.tenantId.trim() ||
|
|
100
|
+
!scope.projectId.trim() ||
|
|
101
|
+
!scope.environmentId.trim()) {
|
|
102
|
+
throw new Error('Social Manager host identity is incomplete.');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/*** Authorize the real caller before exposing any draft state or mutation. */
|
|
106
|
+
async function authorizeAsync(input, scope, operationId, request, callers) {
|
|
107
|
+
try {
|
|
108
|
+
const caller = await input.authenticateCallerAsync(request);
|
|
109
|
+
const authorized = caller !== undefined &&
|
|
110
|
+
typeof caller.actorId === 'string' &&
|
|
111
|
+
caller.actorId.trim().length > 0 &&
|
|
112
|
+
caller.tenantId === scope.tenantId &&
|
|
113
|
+
caller.projectId === scope.projectId &&
|
|
114
|
+
caller.environmentId === scope.environmentId &&
|
|
115
|
+
(await input.authorizeCallerAsync({ caller, appId: input.appId, operationId }));
|
|
116
|
+
if (authorized)
|
|
117
|
+
callers.set(request, caller);
|
|
118
|
+
return authorized;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/*** Bind only the implemented draft operations to the trusted project scope. */
|
|
125
|
+
function createDraftOperations(drafts, scope) {
|
|
126
|
+
return {
|
|
127
|
+
'projects.social.drafts.create': {
|
|
128
|
+
intent: 'create',
|
|
129
|
+
method: 'POST',
|
|
130
|
+
handler: async (request) => {
|
|
131
|
+
const content = readSocialManagerDraftContent(request.body);
|
|
132
|
+
return content
|
|
133
|
+
? { status: 201, body: await drafts.createAsync(scope, content) }
|
|
134
|
+
: invalidResponse();
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
'projects.social.drafts.list': {
|
|
138
|
+
intent: 'read',
|
|
139
|
+
method: 'GET',
|
|
140
|
+
handler: async () => ({ body: await drafts.listAsync(scope) }),
|
|
141
|
+
},
|
|
142
|
+
'projects.social.drafts.read': {
|
|
143
|
+
intent: 'read',
|
|
144
|
+
method: 'GET',
|
|
145
|
+
handler: async (request) => {
|
|
146
|
+
const id = request.params.draftId;
|
|
147
|
+
if (!id)
|
|
148
|
+
return invalidResponse();
|
|
149
|
+
const draft = await drafts.readAsync(scope, id);
|
|
150
|
+
return draft ? { body: draft } : missingResponse();
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
'projects.social.drafts.update': {
|
|
154
|
+
intent: 'update',
|
|
155
|
+
method: 'PATCH',
|
|
156
|
+
handler: async (request) => updateDraftAsync(drafts, scope, request),
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/*** Apply an optimistic revision check; edits never mutate already approved content revisions. */
|
|
161
|
+
async function updateDraftAsync(drafts, scope, request) {
|
|
162
|
+
const id = request.params.draftId;
|
|
163
|
+
const { body } = request;
|
|
164
|
+
if (!id ||
|
|
165
|
+
!isRecord(body) ||
|
|
166
|
+
typeof body.expectedRevision !== 'number' ||
|
|
167
|
+
!Number.isSafeInteger(body.expectedRevision) ||
|
|
168
|
+
body.expectedRevision < 1) {
|
|
169
|
+
return invalidResponse();
|
|
170
|
+
}
|
|
171
|
+
const content = readSocialManagerDraftContent(body.content);
|
|
172
|
+
if (!content)
|
|
173
|
+
return invalidResponse();
|
|
174
|
+
const result = await drafts.updateAsync(scope, id, body.expectedRevision, content);
|
|
175
|
+
if (result.status === 'updated')
|
|
176
|
+
return { body: result.draft };
|
|
177
|
+
return result.status === 'not-found'
|
|
178
|
+
? missingResponse()
|
|
179
|
+
: { status: 409, body: { error: { code: 'draft_revision_conflict' } } };
|
|
180
|
+
}
|
|
181
|
+
/*** Return a stable validation error without echoing untrusted input. */
|
|
182
|
+
function invalidResponse() {
|
|
183
|
+
return { status: 400, body: { error: { code: 'invalid_draft' } } };
|
|
184
|
+
}
|
|
185
|
+
/*** Do not distinguish an absent draft from one outside the authorized scope. */
|
|
186
|
+
function missingResponse() {
|
|
187
|
+
return { status: 404, body: { error: { code: 'draft_not_found' } } };
|
|
188
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { createSocialManagerLocalProviderFixtures } from './createSocialManagerLocalProviderFixtures.js';
|
|
2
|
+
import type { createTrustedSocialManagerFileSystemPersistenceAsync } from './createTrustedSocialManagerFileSystemPersistenceAsync.js';
|
|
3
|
+
import type { CreateTrustedSocialManagerLocalServerAsyncInput } from './createTrustedSocialManagerLocalServerAsync.js';
|
|
4
|
+
type LocalHostInput = Readonly<{
|
|
5
|
+
input: CreateTrustedSocialManagerLocalServerAsyncInput;
|
|
6
|
+
persistence: Awaited<ReturnType<typeof createTrustedSocialManagerFileSystemPersistenceAsync>>;
|
|
7
|
+
fixtures: ReturnType<typeof createSocialManagerLocalProviderFixtures>;
|
|
8
|
+
now: () => string;
|
|
9
|
+
}>;
|
|
10
|
+
/*** Compose a local host from the durable stores and deterministic provider fixtures selected by the loopback server. */
|
|
11
|
+
export declare function createTrustedSocialManagerLocalHostAsync({ input, persistence, fixtures, now, }: LocalHostInput): Promise<Readonly<{
|
|
12
|
+
composition: import("@ankhorage/api").ComposeAuthorizedApiRuntimeOptions;
|
|
13
|
+
registerFastifyAsync: (server: import("fastify").FastifyInstance, options?: import("@ankhorage/api-fastify").RegisterFastifyApiOptions) => Promise<unknown>;
|
|
14
|
+
startWorkerAsync?: () => Readonly<{
|
|
15
|
+
stop: () => Promise<void>;
|
|
16
|
+
}>;
|
|
17
|
+
}>>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { FileFlowPersistenceAdapter, FileFlowRuntimeStore } from '@ankhorage/flow';
|
|
3
|
+
import { createSocialManagerMediaPreflight } from '../adapters/createSocialManagerMediaPreflight.js';
|
|
4
|
+
import { createTrustedSocialManagerHostAsync } from './createTrustedSocialManagerHost.js';
|
|
5
|
+
/*** Compose a local host from the durable stores and deterministic provider fixtures selected by the loopback server. */
|
|
6
|
+
export async function createTrustedSocialManagerLocalHostAsync({ input, persistence, fixtures, now, }) {
|
|
7
|
+
const resolveBindingAsync = createBindingResolver(persistence.connection, fixtures, input.caller);
|
|
8
|
+
const resolveMediaAsync = createMediaResolver(persistence.media);
|
|
9
|
+
return createTrustedSocialManagerHostAsync({
|
|
10
|
+
appId: input.appId,
|
|
11
|
+
scope: input.scope,
|
|
12
|
+
definition: input.definition,
|
|
13
|
+
drafts: persistence.drafts,
|
|
14
|
+
connection: createConnectionDependencies(persistence, fixtures, now),
|
|
15
|
+
media: {
|
|
16
|
+
store: persistence.media,
|
|
17
|
+
isReferencedAsync: (caller, mediaId) => persistence.drafts.isMediaReferencedAsync(caller, mediaId),
|
|
18
|
+
},
|
|
19
|
+
capabilities: createCapabilityDependencies(persistence, fixtures, resolveBindingAsync, resolveMediaAsync, now),
|
|
20
|
+
publication: createPublicationDependencies(input, persistence, fixtures, resolveBindingAsync, resolveMediaAsync),
|
|
21
|
+
authenticateCallerAsync: (request) => Promise.resolve(request.headers.authorization === `Bearer ${input.development.token}`
|
|
22
|
+
? input.caller
|
|
23
|
+
: undefined),
|
|
24
|
+
authorizeCallerAsync: () => Promise.resolve(true),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/*** Bind the released Connection lifecycle implementation to its durable local store and deterministic fixture ports. */
|
|
28
|
+
function createConnectionDependencies(persistence, fixtures, now) {
|
|
29
|
+
return {
|
|
30
|
+
store: persistence.connection,
|
|
31
|
+
authorization: fixtures.authorization,
|
|
32
|
+
now,
|
|
33
|
+
healthAsync: fixtures.healthAsync,
|
|
34
|
+
revocation: fixtures.revocation,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/*** Bind capability queries to the same server-resolved target and immutable media paths as publication. */
|
|
38
|
+
function createCapabilityDependencies(persistence, fixtures, resolveBindingAsync, resolveMediaAsync, now) {
|
|
39
|
+
return {
|
|
40
|
+
drafts: persistence.drafts,
|
|
41
|
+
resolveBindingAsync,
|
|
42
|
+
resolveAnalyticsBindingAsync: async (caller, destination) => {
|
|
43
|
+
const binding = await resolveBindingAsync(caller, destination);
|
|
44
|
+
return binding === undefined
|
|
45
|
+
? undefined
|
|
46
|
+
: { ...binding, analytics: analyticsFor(fixtures, binding.target) };
|
|
47
|
+
},
|
|
48
|
+
resolveMediaAsync,
|
|
49
|
+
now,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/*** Bind one durable Flow runtime to publication, security, provider discovery, and fixture-only media validation. */
|
|
53
|
+
function createPublicationDependencies(input, persistence, fixtures, resolveBindingAsync, resolveMediaAsync) {
|
|
54
|
+
return {
|
|
55
|
+
scope: input.scope,
|
|
56
|
+
drafts: persistence.drafts,
|
|
57
|
+
flow: {
|
|
58
|
+
store: FileFlowRuntimeStore(join(input.dataDirectory, 'social-flow-runtime.json')),
|
|
59
|
+
persistence: FileFlowPersistenceAdapter(join(input.dataDirectory, 'social-flow-worker.json')),
|
|
60
|
+
},
|
|
61
|
+
security: {
|
|
62
|
+
directory: input.dataDirectory,
|
|
63
|
+
grants: [
|
|
64
|
+
{
|
|
65
|
+
actorId: input.caller.actorId,
|
|
66
|
+
capability: 'projects.social.publication.execute',
|
|
67
|
+
tenantId: input.scope.tenantId,
|
|
68
|
+
projectId: input.scope.projectId,
|
|
69
|
+
environment: input.scope.environmentId,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
audit: { writeAsync: () => Promise.resolve(undefined) },
|
|
73
|
+
rateLimit: { acquireAsync: () => Promise.resolve(true) },
|
|
74
|
+
secretStore: createDevelopmentSecretStore(),
|
|
75
|
+
},
|
|
76
|
+
discovery: persistence.connection.targetDiscovery,
|
|
77
|
+
resolveBindingAsync,
|
|
78
|
+
resolveMediaAsync,
|
|
79
|
+
mediaPreflight: createSocialManagerMediaPreflight(persistence.media, (command) => providerFor(fixtures, command.target).getCapabilityAsync(command.target)),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/*** Resolve a caller-owned durable connection and provider-specific target without accepting target details from HTTP. */
|
|
83
|
+
function createBindingResolver(store, fixtures, configuredCaller) {
|
|
84
|
+
return async (caller, destination) => {
|
|
85
|
+
if (!sameCaller(caller, configuredCaller))
|
|
86
|
+
return undefined;
|
|
87
|
+
const connection = await store.delegatedAuthorizationRepository.loadConnectionAsync(destination.connectionId);
|
|
88
|
+
const target = connection && targetForConnection(connection, destination.targetId);
|
|
89
|
+
return connection && target
|
|
90
|
+
? { connection, target, provider: providerFor(fixtures, target) }
|
|
91
|
+
: undefined;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/*** Load immutable caller-owned media and retain the exact order requested by the stored draft. */
|
|
95
|
+
function createMediaResolver(media) {
|
|
96
|
+
return async (caller, mediaIds) => {
|
|
97
|
+
const items = await Promise.all(mediaIds.map((mediaId) => media.loadAsync(caller, mediaId)));
|
|
98
|
+
return items.flatMap((item) => (item === undefined ? [] : [item.media]));
|
|
99
|
+
};
|
|
100
|
+
}
|
|
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
|
+
/*** Select exactly one local provider fixture from the server-resolved target provider. */
|
|
124
|
+
function providerFor(fixtures, target) {
|
|
125
|
+
switch (target.provider) {
|
|
126
|
+
case 'facebook':
|
|
127
|
+
return fixtures.providers.facebook;
|
|
128
|
+
case 'instagram':
|
|
129
|
+
return fixtures.providers.instagram;
|
|
130
|
+
case 'linkedin':
|
|
131
|
+
return fixtures.providers.linkedin;
|
|
132
|
+
case 'pinterest':
|
|
133
|
+
return fixtures.providers.pinterest;
|
|
134
|
+
default:
|
|
135
|
+
throw new Error('Social Manager provider is unsupported.');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/*** Select analytics from the same server-resolved provider as publication. */
|
|
139
|
+
function analyticsFor(fixtures, target) {
|
|
140
|
+
switch (target.provider) {
|
|
141
|
+
case 'facebook':
|
|
142
|
+
return fixtures.analytics.facebook;
|
|
143
|
+
case 'instagram':
|
|
144
|
+
return fixtures.analytics.instagram;
|
|
145
|
+
case 'linkedin':
|
|
146
|
+
return fixtures.analytics.linkedin;
|
|
147
|
+
case 'pinterest':
|
|
148
|
+
return fixtures.analytics.pinterest;
|
|
149
|
+
default:
|
|
150
|
+
throw new Error('Social Manager analytics provider is unsupported.');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/*** Compare every server-owned scope and actor field before reusing a configured development caller. */
|
|
154
|
+
function sameCaller(left, right) {
|
|
155
|
+
return (left.tenantId === right.tenantId &&
|
|
156
|
+
left.projectId === right.projectId &&
|
|
157
|
+
left.environmentId === right.environmentId &&
|
|
158
|
+
left.actorId === right.actorId);
|
|
159
|
+
}
|
|
160
|
+
/*** Provide the fixture-only empty secret boundary; local providers never request credentials. */
|
|
161
|
+
function createDevelopmentSecretStore() {
|
|
162
|
+
const unavailable = () => Promise.resolve({
|
|
163
|
+
ok: false,
|
|
164
|
+
error: {
|
|
165
|
+
code: 'not_found',
|
|
166
|
+
message: 'Development fixtures do not store credentials.',
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
list: unavailable,
|
|
171
|
+
getMetadata: unavailable,
|
|
172
|
+
create: unavailable,
|
|
173
|
+
replace: unavailable,
|
|
174
|
+
remove: unavailable,
|
|
175
|
+
resolve: unavailable,
|
|
176
|
+
};
|
|
177
|
+
}
|