@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,152 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { cancelConnectAsync, completeConnectAsync, disconnectConnectionAsync, discoverAuthorizedTargetsAsync, evaluateAuthorizationHealth, reconcileRevocationAsync, refreshConnectionAsync, retryConnectAsync, startConnectAsync, } from '@ankhorage/connection';
|
|
3
|
+
import { isSocialManagerConnectionHealth, projectSocialManagerConnection, socialManagerConnectionForbidden as forbiddenResponse, socialManagerConnectionInvalid as invalidResponse, socialManagerConnectionMissing as missingResponse, socialManagerConnectionSuccess as successResponse, socialManagerConnectionUnavailable as unavailableResponse, } from '../adapters/projectSocialManagerConnection.js';
|
|
4
|
+
import { readSocialManagerConnectionCallback, readSocialManagerConnectRequest, readSocialManagerDiscoveryRequirement, readSocialManagerTargetId, socialManagerReconnectInput, } from '../domain/readSocialManagerConnectionRequest.js';
|
|
5
|
+
import { isSocialManagerConnectionOwner, socialManagerRevocationOperation, } from '../domain/socialManagerConnectionIdentity.js';
|
|
6
|
+
/*** Bind released Connection use cases to verified caller identity and redacted HTTP projections. */
|
|
7
|
+
export function createSocialManagerConnectionOperations(input, callerOf) {
|
|
8
|
+
const authorization = {
|
|
9
|
+
repository: input.store.delegatedAuthorizationRepository,
|
|
10
|
+
adapter: input.authorization,
|
|
11
|
+
now: input.now,
|
|
12
|
+
};
|
|
13
|
+
const revocation = {
|
|
14
|
+
...input.revocation,
|
|
15
|
+
repository: input.store.revocationRepository,
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
...createConnectionStartOperations(input.store, authorization, callerOf),
|
|
19
|
+
...createConnectionLifecycleOperations(input.store, authorization, callerOf),
|
|
20
|
+
...createConnectionReadOperations(input, callerOf),
|
|
21
|
+
...createConnectionRevocationOperations(input.store, revocation, callerOf),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function createConnectionStartOperations(store, authorization, callerOf) {
|
|
25
|
+
return {
|
|
26
|
+
'projects.social.connections.list': readOperation(async (request) => {
|
|
27
|
+
const caller = callerOf(request);
|
|
28
|
+
return caller ? listConnectionsAsync(store, caller) : forbiddenResponse();
|
|
29
|
+
}),
|
|
30
|
+
'projects.social.connections.connect': createOperation(async (request) => {
|
|
31
|
+
const caller = callerOf(request);
|
|
32
|
+
const start = caller && readSocialManagerConnectRequest(request.body, caller, randomUUID());
|
|
33
|
+
return start
|
|
34
|
+
? successResponse(201, await startConnectAsync(authorization, start))
|
|
35
|
+
: invalidResponse();
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function createConnectionLifecycleOperations(store, authorization, callerOf) {
|
|
40
|
+
return {
|
|
41
|
+
'projects.social.connections.complete': createOperation(async (request) => completeConnectionAsync(store, authorization, callerOf(request), request.body)),
|
|
42
|
+
'projects.social.connections.cancel': deleteOperation(async (request) => cancelConnectionAsync(store, authorization, callerOf(request), request.params.attemptId)),
|
|
43
|
+
'projects.social.connections.reconnect': createOperation(async (request) => reconnectConnectionAsync(store, authorization, callerOf(request), request.params.connectionId)),
|
|
44
|
+
'projects.social.connections.refresh': createOperation(async (request) => refreshCallerConnectionAsync(store, authorization, callerOf(request), request.params.connectionId)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function createConnectionReadOperations(input, callerOf) {
|
|
48
|
+
return {
|
|
49
|
+
'projects.social.connections.health': readOperation(async (request) => readConnectionHealthAsync(input, callerOf(request), request.params.connectionId)),
|
|
50
|
+
'projects.social.connections.destinations.list': readOperation(async (request) => discoverDestinationsAsync(input.store, callerOf(request), request.params.connectionId, request.query)),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function createConnectionRevocationOperations(store, revocation, callerOf) {
|
|
54
|
+
return {
|
|
55
|
+
'projects.social.connections.disconnect': deleteOperation(async (request) => revokeConnectionAsync(store, revocation, callerOf(request), request.params.connectionId, request.body, disconnectConnectionAsync)),
|
|
56
|
+
'projects.social.connections.revocation.reconcile': createOperation(async (request) => revokeConnectionAsync(store, revocation, callerOf(request), request.params.connectionId, request.body, reconcileRevocationAsync)),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/*** Complete only an attempt whose immutable binding belongs to the authenticated caller. */
|
|
60
|
+
async function completeConnectionAsync(store, authorization, caller, body) {
|
|
61
|
+
const callback = readSocialManagerConnectionCallback(body);
|
|
62
|
+
if (!caller || !callback)
|
|
63
|
+
return invalidResponse();
|
|
64
|
+
const attempt = await store.delegatedAuthorizationRepository.loadAttemptAsync(callback.attemptId);
|
|
65
|
+
if (!attempt || !isSocialManagerConnectionOwner(attempt, caller))
|
|
66
|
+
return missingResponse('connection_not_found');
|
|
67
|
+
return successResponse(200, await completeConnectAsync(authorization, callback));
|
|
68
|
+
}
|
|
69
|
+
/*** Cancel only a pending authorization attempt owned by the authenticated caller. */
|
|
70
|
+
async function cancelConnectionAsync(store, authorization, caller, attemptId) {
|
|
71
|
+
if (!caller || !attemptId)
|
|
72
|
+
return invalidResponse();
|
|
73
|
+
const attempt = await store.delegatedAuthorizationRepository.loadAttemptAsync(attemptId);
|
|
74
|
+
if (!attempt || !isSocialManagerConnectionOwner(attempt, caller))
|
|
75
|
+
return missingResponse('connection_not_found');
|
|
76
|
+
return successResponse(200, await cancelConnectAsync(authorization, attemptId));
|
|
77
|
+
}
|
|
78
|
+
/*** Reconnect only a durable connection bound to the authenticated caller. */
|
|
79
|
+
async function reconnectConnectionAsync(store, authorization, caller, connectionId) {
|
|
80
|
+
const connection = caller && (await loadConnectionAsync(store, caller, connectionId));
|
|
81
|
+
return connection
|
|
82
|
+
? successResponse(201, await retryConnectAsync(authorization, socialManagerReconnectInput(connection)))
|
|
83
|
+
: missingResponse('connection_not_found');
|
|
84
|
+
}
|
|
85
|
+
/*** Refresh only a durable connection bound to the authenticated caller. */
|
|
86
|
+
async function refreshCallerConnectionAsync(store, authorization, caller, connectionId) {
|
|
87
|
+
const connection = caller && (await loadConnectionAsync(store, caller, connectionId));
|
|
88
|
+
return connection
|
|
89
|
+
? successResponse(200, await refreshConnectionAsync(authorization, connection.connectionId))
|
|
90
|
+
: missingResponse('connection_not_found');
|
|
91
|
+
}
|
|
92
|
+
/*** Return health only after the injected provider adapter confirms the same authorization binding. */
|
|
93
|
+
async function readConnectionHealthAsync(input, caller, connectionId) {
|
|
94
|
+
const connection = caller && (await loadConnectionAsync(input.store, caller, connectionId));
|
|
95
|
+
if (!connection)
|
|
96
|
+
return missingResponse('connection_not_found');
|
|
97
|
+
const health = await input.healthAsync(connection);
|
|
98
|
+
return isSocialManagerConnectionHealth(connection, health)
|
|
99
|
+
? successResponse(200, evaluateAuthorizationHealth(health, connection.grantedScopes))
|
|
100
|
+
: unavailableResponse();
|
|
101
|
+
}
|
|
102
|
+
/*** Discover only targets below the caller's current durable connection. */
|
|
103
|
+
async function discoverDestinationsAsync(store, caller, connectionId, query) {
|
|
104
|
+
const connection = caller && (await loadConnectionAsync(store, caller, connectionId));
|
|
105
|
+
const requirement = connection && readSocialManagerDiscoveryRequirement(query, connection);
|
|
106
|
+
return connection && requirement
|
|
107
|
+
? successResponse(200, await discoverAuthorizedTargetsAsync(store.targetDiscovery, requirement))
|
|
108
|
+
: invalidResponse();
|
|
109
|
+
}
|
|
110
|
+
/*** Execute one released revocation use case for a caller-owned connection and target. */
|
|
111
|
+
async function revokeConnectionAsync(store, dependencies, caller, connectionId, body, executeAsync) {
|
|
112
|
+
const connection = caller && (await loadConnectionAsync(store, caller, connectionId));
|
|
113
|
+
const targetId = readSocialManagerTargetId(body);
|
|
114
|
+
const target = connection?.targets.find((candidate) => candidate.targetId === targetId);
|
|
115
|
+
return connection && target && targetId
|
|
116
|
+
? successResponse(200, await executeAsync(dependencies, socialManagerRevocationOperation(connection, targetId)))
|
|
117
|
+
: missingResponse('connection_not_found');
|
|
118
|
+
}
|
|
119
|
+
/*** Wrap a read operation so invalid provider state remains a stable redacted service failure. */
|
|
120
|
+
function readOperation(handler) {
|
|
121
|
+
return { intent: 'read', method: 'GET', handler: safeHandler(handler) };
|
|
122
|
+
}
|
|
123
|
+
/*** Wrap a create operation so Connection lifecycle effects retain their declared HTTP method. */
|
|
124
|
+
function createOperation(handler) {
|
|
125
|
+
return { intent: 'create', method: 'POST', handler: safeHandler(handler) };
|
|
126
|
+
}
|
|
127
|
+
/*** Wrap a delete operation so revocation effects retain their declared HTTP method. */
|
|
128
|
+
function deleteOperation(handler) {
|
|
129
|
+
return { intent: 'delete', method: 'DELETE', handler: safeHandler(handler) };
|
|
130
|
+
}
|
|
131
|
+
/*** Convert released use-case failures into credential-safe host responses. */
|
|
132
|
+
function safeHandler(handler) {
|
|
133
|
+
return async (request, context) => {
|
|
134
|
+
try {
|
|
135
|
+
return await handler(request, context);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return unavailableResponse();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/*** List only the authenticated caller's account projections without authorization references. */
|
|
143
|
+
async function listConnectionsAsync(store, caller) {
|
|
144
|
+
const connections = await store.listConnectionsAsync(caller);
|
|
145
|
+
return successResponse(200, connections.map(projectSocialManagerConnection));
|
|
146
|
+
}
|
|
147
|
+
/*** Load a connection only when it belongs to the caller selected by authenticated request handling. */
|
|
148
|
+
async function loadConnectionAsync(store, caller, connectionId) {
|
|
149
|
+
if (!connectionId)
|
|
150
|
+
return undefined;
|
|
151
|
+
return (await store.listConnectionsAsync(caller)).find((connection) => connection.connectionId === connectionId);
|
|
152
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AuthorizationHealthSnapshot, ManagedConnection, TrustedCredentialRemovalPort, TrustedDelegatedAuthorizationAdapter, TrustedProviderRevocationPort } from '@ankhorage/connection';
|
|
2
|
+
import type { SocialAnalyticsAdapter, SocialProviderPort } from '@ankhorage/social';
|
|
3
|
+
import type { SocialOperationStores } from '../adapters/createSocialOperationStoresAsync.js';
|
|
4
|
+
export type SocialManagerLocalProviderFixtures = Readonly<{
|
|
5
|
+
authorization: TrustedDelegatedAuthorizationAdapter;
|
|
6
|
+
healthAsync: (connection: ManagedConnection) => Promise<AuthorizationHealthSnapshot>;
|
|
7
|
+
revocation: Readonly<{
|
|
8
|
+
provider: TrustedProviderRevocationPort;
|
|
9
|
+
credentials: TrustedCredentialRemovalPort;
|
|
10
|
+
}>;
|
|
11
|
+
providers: Readonly<Record<'facebook' | 'instagram' | 'linkedin' | 'pinterest', SocialProviderPort>>;
|
|
12
|
+
analytics: Readonly<Record<'facebook' | 'instagram' | 'linkedin' | 'pinterest', SocialAnalyticsAdapter>>;
|
|
13
|
+
}>;
|
|
14
|
+
/***
|
|
15
|
+
* Compose deterministic local protocol boundaries for explicitly selected development fixtures.
|
|
16
|
+
* This factory never receives credentials or network endpoints; production hosts must inject their
|
|
17
|
+
* own provider boundaries instead.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSocialManagerLocalProviderFixtures(input: Readonly<{
|
|
20
|
+
operations: SocialOperationStores;
|
|
21
|
+
now: () => string;
|
|
22
|
+
}>): SocialManagerLocalProviderFixtures;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { createSocialManagerProvider } from './createSocialManagerProvider.js';
|
|
2
|
+
/***
|
|
3
|
+
* Compose deterministic local protocol boundaries for explicitly selected development fixtures.
|
|
4
|
+
* This factory never receives credentials or network endpoints; production hosts must inject their
|
|
5
|
+
* own provider boundaries instead.
|
|
6
|
+
*/
|
|
7
|
+
export function createSocialManagerLocalProviderFixtures(input) {
|
|
8
|
+
const providers = createProviders(input);
|
|
9
|
+
return {
|
|
10
|
+
authorization: createAuthorizationFixture(input.now),
|
|
11
|
+
healthAsync: (connection) => Promise.resolve({
|
|
12
|
+
tenantId: connection.tenantId,
|
|
13
|
+
projectId: connection.projectId,
|
|
14
|
+
environmentId: connection.environmentId,
|
|
15
|
+
actorId: connection.actorId,
|
|
16
|
+
provider: connection.provider,
|
|
17
|
+
connectionId: connection.connectionId,
|
|
18
|
+
accountId: connection.accountId,
|
|
19
|
+
targetId: connection.targets[0]?.targetId ?? 'local-target',
|
|
20
|
+
authorizationId: connection.authorizationId,
|
|
21
|
+
confirmed: connection.status === 'connected',
|
|
22
|
+
providerStatus: connection.status === 'connected' ? 'active' : 'reconnect-required',
|
|
23
|
+
grantedScopes: connection.grantedScopes,
|
|
24
|
+
}),
|
|
25
|
+
revocation: {
|
|
26
|
+
provider: createRevocationProvider(),
|
|
27
|
+
credentials: { removeExactCredentialAsync: () => Promise.resolve('removed') },
|
|
28
|
+
},
|
|
29
|
+
providers: {
|
|
30
|
+
facebook: providers.facebook.provider,
|
|
31
|
+
instagram: providers.instagram.provider,
|
|
32
|
+
linkedin: providers.linkedin.provider,
|
|
33
|
+
pinterest: providers.pinterest.provider,
|
|
34
|
+
},
|
|
35
|
+
analytics: {
|
|
36
|
+
facebook: providers.facebook.analytics,
|
|
37
|
+
instagram: providers.instagram.analytics,
|
|
38
|
+
linkedin: providers.linkedin.analytics,
|
|
39
|
+
pinterest: providers.pinterest.analytics,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/*** Construct each published provider adapter over an explicit local-only protocol response boundary. */
|
|
44
|
+
function createProviders(input) {
|
|
45
|
+
return {
|
|
46
|
+
facebook: createFacebookProvider(input.operations),
|
|
47
|
+
instagram: createInstagramProvider(input.operations),
|
|
48
|
+
linkedin: createLinkedinProvider(input.operations),
|
|
49
|
+
pinterest: createPinterestProvider(input.operations, input.now),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/*** Bind the published Facebook Pages adapter to deterministic Graph responses and durable operations. */
|
|
53
|
+
function createFacebookProvider(operations) {
|
|
54
|
+
return createSocialManagerProvider({
|
|
55
|
+
provider: 'facebook',
|
|
56
|
+
input: {
|
|
57
|
+
operations: operations.facebookPages,
|
|
58
|
+
transport: {
|
|
59
|
+
requestAsync: facebookResponse,
|
|
60
|
+
uploadMediaAsync: (request) => Promise.resolve({ status: 200, body: { id: `media:${request.mediaId}` } }),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/*** Bind the published Instagram adapter to deterministic account, media, and protocol responses. */
|
|
66
|
+
function createInstagramProvider(operations) {
|
|
67
|
+
return createSocialManagerProvider({
|
|
68
|
+
provider: 'instagram',
|
|
69
|
+
input: {
|
|
70
|
+
account: { getAccountAsync: (target) => Promise.resolve(instagramAccount(target)) },
|
|
71
|
+
mediaSource: {
|
|
72
|
+
resolveAsync: (_command, _authorizationRef, media) => Promise.resolve(media.map((item) => ({
|
|
73
|
+
mediaId: item.mediaId,
|
|
74
|
+
url: `https://social-manager.local/media/${encodeURIComponent(item.mediaId)}`,
|
|
75
|
+
}))),
|
|
76
|
+
},
|
|
77
|
+
operations: operations.instagramProfessional,
|
|
78
|
+
transport: { requestAsync: instagramResponse },
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/*** Resolve only a matching local Instagram professional account without storing a credential. */
|
|
83
|
+
function instagramAccount(target) {
|
|
84
|
+
if (target.provider !== 'instagram' || target.accountId !== target.destinationId)
|
|
85
|
+
return null;
|
|
86
|
+
if (target.accountType === 'business')
|
|
87
|
+
return socialInstagramAccount(target.accountId, 'business');
|
|
88
|
+
if (target.accountType === 'creator')
|
|
89
|
+
return socialInstagramAccount(target.accountId, 'creator');
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
/*** Construct one narrowed local Instagram account from an authenticated target identity. */
|
|
93
|
+
function socialInstagramAccount(accountId, accountType) {
|
|
94
|
+
return {
|
|
95
|
+
authorizationMode: 'instagram-login',
|
|
96
|
+
accountType,
|
|
97
|
+
instagramAccountId: accountId,
|
|
98
|
+
carouselEnabled: true,
|
|
99
|
+
carouselVideoEnabled: true,
|
|
100
|
+
commentsEnabled: true,
|
|
101
|
+
insightsEnabled: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/*** Bind the published LinkedIn adapter to deterministic authenticated transport and media source ports. */
|
|
105
|
+
function createLinkedinProvider(operations) {
|
|
106
|
+
return createSocialManagerProvider({
|
|
107
|
+
provider: 'linkedin',
|
|
108
|
+
input: {
|
|
109
|
+
apiVersion: '202601',
|
|
110
|
+
identity: { kind: 'member', author: 'urn:li:person:local-social-manager' },
|
|
111
|
+
access: { communityManagement: 'confirmed', commentsAndReactions: true, analytics: true },
|
|
112
|
+
mediaSource: {
|
|
113
|
+
loadAsync: () => Promise.resolve({ owner: 'urn:li:person:local-social-manager', bytes: new Uint8Array() }),
|
|
114
|
+
},
|
|
115
|
+
operations: operations.linkedin,
|
|
116
|
+
transport: { requestAsync: linkedinResponse },
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/*** Bind the published Pinterest adapter to deterministic public-board and media resolver ports. */
|
|
121
|
+
function createPinterestProvider(operations, now) {
|
|
122
|
+
return createSocialManagerProvider({
|
|
123
|
+
provider: 'pinterest',
|
|
124
|
+
input: {
|
|
125
|
+
accessTier: 'standard',
|
|
126
|
+
mediaResolver: { resolveAsync: (media) => Promise.resolve(pinterestMedia(media)) },
|
|
127
|
+
now,
|
|
128
|
+
operations: operations.pinterest,
|
|
129
|
+
transport: { requestAsync: (request) => pinterestResponse(request.path) },
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/*** Resolve a local opaque Social media reference to its deterministic Pinterest source shape. */
|
|
134
|
+
function pinterestMedia(media) {
|
|
135
|
+
const path = `https://social-manager.local/media/${encodeURIComponent(media.mediaId)}`;
|
|
136
|
+
return media.kind === 'image'
|
|
137
|
+
? { kind: 'image', url: path }
|
|
138
|
+
: { kind: 'video', mediaId: `media:${media.mediaId}`, coverImageUrl: `${path}/cover` };
|
|
139
|
+
}
|
|
140
|
+
/*** Build deterministic credential-free delegated authorization fixtures for local development only. */
|
|
141
|
+
function createAuthorizationFixture(now) {
|
|
142
|
+
return {
|
|
143
|
+
startAsync: (attempt) => Promise.resolve({
|
|
144
|
+
attemptId: attempt.attemptId,
|
|
145
|
+
authorizationUrl: `local-fixture://social-manager/authorize/${attempt.provider}/${attempt.attemptId}`,
|
|
146
|
+
expiresAt: attempt.expiresAt,
|
|
147
|
+
}),
|
|
148
|
+
completeAsync: (attempt, callback) => Promise.resolve(callback.payload === localCallbackPayload(attempt.provider)
|
|
149
|
+
? completedAuthorization(attempt, now())
|
|
150
|
+
: { kind: 'cancelled' }),
|
|
151
|
+
cancelAsync: () => Promise.resolve(),
|
|
152
|
+
refreshAsync: (connection) => Promise.resolve({
|
|
153
|
+
kind: 'refreshed',
|
|
154
|
+
authorizationRef: `${connection.authorizationRef}:refreshed`,
|
|
155
|
+
grantedScopes: connection.grantedScopes,
|
|
156
|
+
authorizationRevision: `local:${now()}`,
|
|
157
|
+
}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/*** Return an explicit fixture callback payload so local authorization cannot be mistaken for OAuth. */
|
|
161
|
+
function localCallbackPayload(provider) {
|
|
162
|
+
return `local-fixture:${provider}:authorized`;
|
|
163
|
+
}
|
|
164
|
+
/*** Construct one complete provider-confirmed local connection without representing a credential. */
|
|
165
|
+
function completedAuthorization(attempt, now) {
|
|
166
|
+
const target = fixtureTarget(attempt.provider, attempt);
|
|
167
|
+
return {
|
|
168
|
+
tenantId: attempt.tenantId,
|
|
169
|
+
projectId: attempt.projectId,
|
|
170
|
+
environmentId: attempt.environmentId,
|
|
171
|
+
actorId: attempt.actorId,
|
|
172
|
+
connectionId: attempt.connectionId,
|
|
173
|
+
provider: attempt.provider,
|
|
174
|
+
requestedScopes: attempt.requestedScopes,
|
|
175
|
+
authorizationId: `local:${attempt.connectionId}`,
|
|
176
|
+
authorizationRef: `local:${attempt.connectionId}:${attempt.provider}`,
|
|
177
|
+
accountId: target.accountId,
|
|
178
|
+
grantedScopes: fixtureScopes(attempt.provider),
|
|
179
|
+
targets: [target],
|
|
180
|
+
authorizationRevision: `local:${now}`,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/*** Derive a stable local target descriptor for the selected provider protocol. */
|
|
184
|
+
function fixtureTarget(provider, attempt) {
|
|
185
|
+
const accountId = provider === 'linkedin' ? 'urn:li:person:local-social-manager' : 'local-account';
|
|
186
|
+
const targetId = provider === 'pinterest' ? 'local-board' : accountId;
|
|
187
|
+
return {
|
|
188
|
+
tenantId: attempt.tenantId,
|
|
189
|
+
projectId: attempt.projectId,
|
|
190
|
+
environmentId: attempt.environmentId,
|
|
191
|
+
actorId: attempt.actorId,
|
|
192
|
+
provider,
|
|
193
|
+
connectionId: attempt.connectionId,
|
|
194
|
+
accountId,
|
|
195
|
+
targetId,
|
|
196
|
+
connectionStatus: 'connected',
|
|
197
|
+
roles: provider === 'linkedin' ? ['ADMINISTRATOR'] : ['CREATE_CONTENT'],
|
|
198
|
+
scopes: fixtureScopes(provider),
|
|
199
|
+
capabilities: [{ operation: 'publish', status: 'confirmed' }],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/*** Declare the provider scopes represented by the deliberately local fixture protocol. */
|
|
203
|
+
function fixtureScopes(provider) {
|
|
204
|
+
switch (provider) {
|
|
205
|
+
case 'facebook-login':
|
|
206
|
+
return ['pages_show_list', 'pages_read_engagement', 'pages_manage_posts'];
|
|
207
|
+
case 'instagram-login':
|
|
208
|
+
return ['instagram_business_basic', 'instagram_business_content_publishing'];
|
|
209
|
+
case 'linkedin':
|
|
210
|
+
return ['w_member_social'];
|
|
211
|
+
case 'pinterest':
|
|
212
|
+
return ['boards:read', 'pins:write', 'pins:read'];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/*** Supply deterministic verified revocation evidence bound to the exact durable revocation operation. */
|
|
216
|
+
function createRevocationProvider() {
|
|
217
|
+
return {
|
|
218
|
+
findVerifiedEvidenceAsync: () => Promise.resolve(null),
|
|
219
|
+
revokeAsync: (operation) => Promise.resolve({
|
|
220
|
+
kind: 'revoked',
|
|
221
|
+
evidence: { evidenceId: `local-revocation:${operation.effectId}`, operation },
|
|
222
|
+
}),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/*** Respond to only the Facebook Graph shapes exercised by the published Pages adapter. */
|
|
226
|
+
function facebookResponse(request) {
|
|
227
|
+
if (request.method === 'GET' && request.path === '/me/accounts')
|
|
228
|
+
return Promise.resolve({
|
|
229
|
+
status: 200,
|
|
230
|
+
body: { data: [{ id: 'local-account', name: 'Local Page', tasks: ['CREATE_CONTENT'] }] },
|
|
231
|
+
});
|
|
232
|
+
return Promise.resolve({
|
|
233
|
+
status: 200,
|
|
234
|
+
body: { id: `facebook:${request.path.replaceAll('/', ':')}` },
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/*** Return completed local Instagram container and publication records without external transport. */
|
|
238
|
+
function instagramResponse(request) {
|
|
239
|
+
return Promise.resolve(request.method === 'GET'
|
|
240
|
+
? { status: 200, body: { status_code: 'FINISHED' } }
|
|
241
|
+
: { status: 200, body: { id: `instagram:${request.path.replaceAll('/', ':')}` } });
|
|
242
|
+
}
|
|
243
|
+
/*** Return the exact headers and initialization body expected by the published LinkedIn adapter. */
|
|
244
|
+
function linkedinResponse(request) {
|
|
245
|
+
if (request.method === 'POST' && request.url.includes('initializeUpload'))
|
|
246
|
+
return Promise.resolve({
|
|
247
|
+
status: 200,
|
|
248
|
+
headers: {},
|
|
249
|
+
body: {
|
|
250
|
+
value: {
|
|
251
|
+
uploadUrl: 'https://social-manager.local/linkedin/upload',
|
|
252
|
+
image: 'urn:li:image:local',
|
|
253
|
+
video: 'urn:li:video:local',
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
return Promise.resolve({ status: 201, headers: { 'x-restli-id': 'local-linkedin-resource' } });
|
|
258
|
+
}
|
|
259
|
+
/*** Return public local Pinterest boards and deterministic Pin records for published adapter paths. */
|
|
260
|
+
function pinterestResponse(path) {
|
|
261
|
+
if (path === '/v5/boards')
|
|
262
|
+
return Promise.resolve({
|
|
263
|
+
status: 200,
|
|
264
|
+
body: { items: [{ id: 'local-board', privacy: 'public' }] },
|
|
265
|
+
});
|
|
266
|
+
if (path.includes('/sections'))
|
|
267
|
+
return Promise.resolve({ status: 200, body: { items: [] } });
|
|
268
|
+
if (path === '/v5/boards/local-board')
|
|
269
|
+
return Promise.resolve({ status: 200, body: { id: 'local-board', privacy: 'public' } });
|
|
270
|
+
return Promise.resolve({ status: 201, body: { id: 'local-pin' } });
|
|
271
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ApiHandler } from '@ankhorage/api';
|
|
2
|
+
import type { SocialManagerCaller, SocialManagerMediaStore } from '../../../types/socialManager.js';
|
|
3
|
+
type MediaOperation = Readonly<{
|
|
4
|
+
intent: 'create' | 'delete' | 'read';
|
|
5
|
+
method: 'DELETE' | 'GET' | 'POST';
|
|
6
|
+
handler: ApiHandler;
|
|
7
|
+
}>;
|
|
8
|
+
export type SocialManagerMediaHostDependencies = Readonly<{
|
|
9
|
+
store: SocialManagerMediaStore;
|
|
10
|
+
isReferencedAsync: (caller: SocialManagerCaller, mediaId: string) => Promise<boolean>;
|
|
11
|
+
}>;
|
|
12
|
+
/*** Bind immutable caller-owned media operations to authenticated HTTP delivery. */
|
|
13
|
+
export declare function createSocialManagerMediaOperations(input: SocialManagerMediaHostDependencies, callerOf: (request: Parameters<ApiHandler>[0]) => SocialManagerCaller | undefined): Readonly<Record<string, MediaOperation>>;
|
|
14
|
+
export {};
|
package/dist/features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
3
|
+
/*** Bind immutable caller-owned media operations to authenticated HTTP delivery. */
|
|
4
|
+
export function createSocialManagerMediaOperations(input, callerOf) {
|
|
5
|
+
return {
|
|
6
|
+
'projects.social.media.upload': createOperation((request) => uploadMediaAsync(input, callerOf(request), request.body)),
|
|
7
|
+
'projects.social.media.list': readOperation((request) => listMediaAsync(input, callerOf(request))),
|
|
8
|
+
'projects.social.media.read': readOperation((request) => readMediaAsync(input, callerOf(request), request.params.mediaId)),
|
|
9
|
+
'projects.social.media.remove': deleteOperation((request) => removeMediaAsync(input, callerOf(request), request.params.mediaId)),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/*** Persist a bounded base64 upload without accepting client-supplied media identity. */
|
|
13
|
+
async function uploadMediaAsync(input, caller, value) {
|
|
14
|
+
const upload = readUpload(value);
|
|
15
|
+
if (!caller || !upload)
|
|
16
|
+
return invalidResponse();
|
|
17
|
+
try {
|
|
18
|
+
return { status: 201, body: await input.store.uploadAsync(caller, upload) };
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return invalidResponse();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/*** List redaction-safe immutable media metadata for the authenticated caller. */
|
|
25
|
+
async function listMediaAsync(input, caller) {
|
|
26
|
+
return caller ? { body: await input.store.listAsync(caller) } : missingResponse();
|
|
27
|
+
}
|
|
28
|
+
/*** Resolve exactly one immutable media metadata record in the caller's scope. */
|
|
29
|
+
async function readMediaAsync(input, caller, mediaId) {
|
|
30
|
+
const media = caller && mediaId ? await input.store.readAsync(caller, mediaId) : undefined;
|
|
31
|
+
return media ? { body: media } : missingResponse();
|
|
32
|
+
}
|
|
33
|
+
/*** Remove media only when no immutable draft or retained publication reference requires it. */
|
|
34
|
+
async function removeMediaAsync(input, caller, mediaId) {
|
|
35
|
+
if (!caller || !mediaId)
|
|
36
|
+
return missingResponse();
|
|
37
|
+
const result = await input.store.removeAsync(caller, mediaId, (media) => input.isReferencedAsync(caller, media.mediaId));
|
|
38
|
+
return result === 'removed'
|
|
39
|
+
? { status: 204 }
|
|
40
|
+
: result === 'referenced'
|
|
41
|
+
? { status: 409, body: { error: { code: 'social_media_referenced' } } }
|
|
42
|
+
: missingResponse();
|
|
43
|
+
}
|
|
44
|
+
/*** Decode only canonical nonempty base64 JSON input before durable media validation. */
|
|
45
|
+
function readUpload(value) {
|
|
46
|
+
if (!isRecord(value) || typeof value.contentType !== 'string' || typeof value.base64 !== 'string')
|
|
47
|
+
return undefined;
|
|
48
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value.base64))
|
|
49
|
+
return undefined;
|
|
50
|
+
const bytes = new Uint8Array(Buffer.from(value.base64, 'base64'));
|
|
51
|
+
return bytes.byteLength > 0 ? { contentType: value.contentType, bytes } : undefined;
|
|
52
|
+
}
|
|
53
|
+
/*** Declare a canonical immutable-media read operation. */
|
|
54
|
+
function readOperation(handler) {
|
|
55
|
+
return { intent: 'read', method: 'GET', handler };
|
|
56
|
+
}
|
|
57
|
+
/*** Declare a canonical immutable-media upload operation. */
|
|
58
|
+
function createOperation(handler) {
|
|
59
|
+
return { intent: 'create', method: 'POST', handler };
|
|
60
|
+
}
|
|
61
|
+
/*** Declare a canonical immutable-media removal operation. */
|
|
62
|
+
function deleteOperation(handler) {
|
|
63
|
+
return { intent: 'delete', method: 'DELETE', handler };
|
|
64
|
+
}
|
|
65
|
+
/*** Return a stable request validation response without echoing untrusted media data. */
|
|
66
|
+
function invalidResponse() {
|
|
67
|
+
return { status: 400, body: { error: { code: 'invalid_social_media' } } };
|
|
68
|
+
}
|
|
69
|
+
/*** Hide media existence outside the authenticated caller scope. */
|
|
70
|
+
function missingResponse() {
|
|
71
|
+
return { status: 404, body: { error: { code: 'social_media_not_found' } } };
|
|
72
|
+
}
|
package/dist/features/trusted-social-manager-host/composition/createSocialManagerProvider.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SocialAnalyticsAdapter, SocialProviderPort } from '@ankhorage/social';
|
|
2
|
+
import { createFacebookPagesProvider, createInstagramProfessionalProvider, createLinkedinProviderAdapter, createPinterestProvider } from '@ankhorage/social';
|
|
3
|
+
export type SocialManagerProviderConfiguration = {
|
|
4
|
+
readonly provider: 'facebook';
|
|
5
|
+
readonly input: Parameters<typeof createFacebookPagesProvider>[0];
|
|
6
|
+
} | {
|
|
7
|
+
readonly provider: 'instagram';
|
|
8
|
+
readonly input: Parameters<typeof createInstagramProfessionalProvider>[0];
|
|
9
|
+
} | {
|
|
10
|
+
readonly provider: 'linkedin';
|
|
11
|
+
readonly input: Parameters<typeof createLinkedinProviderAdapter>[0];
|
|
12
|
+
} | {
|
|
13
|
+
readonly provider: 'pinterest';
|
|
14
|
+
readonly input: Parameters<typeof createPinterestProvider>[0];
|
|
15
|
+
};
|
|
16
|
+
/*** Construct a provider bound to one trusted authorization, never from browser-supplied transport options. */
|
|
17
|
+
export declare function createSocialManagerProvider(configuration: SocialManagerProviderConfiguration): {
|
|
18
|
+
readonly provider: SocialProviderPort;
|
|
19
|
+
readonly analytics: SocialAnalyticsAdapter;
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createFacebookPagesProvider, createInstagramProfessionalProvider, createLinkedinProviderAdapter, createPinterestProvider, } from '@ankhorage/social';
|
|
2
|
+
/*** Construct a provider bound to one trusted authorization, never from browser-supplied transport options. */
|
|
3
|
+
export function createSocialManagerProvider(configuration) {
|
|
4
|
+
switch (configuration.provider) {
|
|
5
|
+
case 'facebook':
|
|
6
|
+
return createFacebookPagesProvider(configuration.input);
|
|
7
|
+
case 'instagram': {
|
|
8
|
+
const provider = createInstagramProfessionalProvider(configuration.input);
|
|
9
|
+
return { provider, analytics: provider };
|
|
10
|
+
}
|
|
11
|
+
case 'linkedin': {
|
|
12
|
+
const provider = createLinkedinProviderAdapter(configuration.input);
|
|
13
|
+
return { provider, analytics: provider };
|
|
14
|
+
}
|
|
15
|
+
case 'pinterest': {
|
|
16
|
+
const provider = createPinterestProvider(configuration.input);
|
|
17
|
+
return { provider, analytics: provider };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ApiHandler } from '@ankhorage/api';
|
|
2
|
+
import type { SocialManagerCaller } from '../../../types/socialManager.js';
|
|
3
|
+
import type { createSocialManagerPublicationRuntime } from '../application/createSocialManagerPublicationRuntime.js';
|
|
4
|
+
type PublicationRuntime = ReturnType<typeof createSocialManagerPublicationRuntime>;
|
|
5
|
+
type PublicationOperation = Readonly<{
|
|
6
|
+
intent: 'create' | 'delete' | 'read' | 'update';
|
|
7
|
+
method: 'DELETE' | 'GET' | 'POST';
|
|
8
|
+
handler: ApiHandler;
|
|
9
|
+
}>;
|
|
10
|
+
export type SocialManagerPublicationHostDependencies = Readonly<{
|
|
11
|
+
runtime: PublicationRuntime;
|
|
12
|
+
}>;
|
|
13
|
+
/*** Bind protected Flow publication lifecycle operations to the authenticated caller. */
|
|
14
|
+
export declare function createSocialManagerPublicationOperations(input: SocialManagerPublicationHostDependencies, callerOf: (request: Parameters<ApiHandler>[0]) => SocialManagerCaller | undefined): Readonly<Record<string, PublicationOperation>>;
|
|
15
|
+
export {};
|