@party-stack/connect 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -2
- package/lib/ServiceConnector.d.ts +68 -0
- package/lib/ServiceConnector.d.ts.map +1 -0
- package/lib/ServiceConnector.js +1 -0
- package/lib/acquireConfiguredConnection.d.ts +32 -0
- package/lib/acquireConfiguredConnection.d.ts.map +1 -0
- package/lib/acquireConfiguredConnection.js +54 -0
- package/lib/acquireConfiguredConnection.js.map +1 -0
- package/lib/authentication.d.ts +76 -0
- package/lib/authentication.d.ts.map +1 -0
- package/lib/authentication.js +95 -0
- package/lib/authentication.js.map +1 -0
- package/lib/authorization.d.ts +43 -0
- package/lib/authorization.d.ts.map +1 -0
- package/lib/authorization.js +175 -0
- package/lib/authorization.js.map +1 -0
- package/lib/core/accessToken.d.ts +10 -0
- package/lib/core/accessToken.d.ts.map +1 -0
- package/lib/core/accessToken.js +87 -0
- package/lib/core/accessToken.js.map +1 -0
- package/lib/core/backend.d.ts +33 -0
- package/lib/core/backend.d.ts.map +1 -0
- package/lib/core/backend.js +249 -0
- package/lib/core/backend.js.map +1 -0
- package/lib/core/errors.d.ts +13 -0
- package/lib/core/errors.d.ts.map +1 -0
- package/lib/core/errors.js +26 -0
- package/lib/core/errors.js.map +1 -0
- package/lib/core/maintenance.d.ts +11 -0
- package/lib/core/maintenance.d.ts.map +1 -0
- package/lib/core/maintenance.js +21 -0
- package/lib/core/maintenance.js.map +1 -0
- package/lib/core/migrate.d.ts +18 -0
- package/lib/core/migrate.d.ts.map +1 -0
- package/lib/core/migrate.js +71 -0
- package/lib/core/migrate.js.map +1 -0
- package/lib/core/oauth.d.ts +27 -0
- package/lib/core/oauth.d.ts.map +1 -0
- package/lib/core/oauth.js +82 -0
- package/lib/core/oauth.js.map +1 -0
- package/lib/core/oauthAuthority.d.ts +90 -0
- package/lib/core/oauthAuthority.d.ts.map +1 -0
- package/lib/core/oauthAuthority.js +382 -0
- package/lib/core/oauthAuthority.js.map +1 -0
- package/lib/core/store.d.ts +48 -0
- package/lib/core/store.d.ts.map +1 -0
- package/lib/core/store.js +92 -0
- package/lib/core/store.js.map +1 -0
- package/lib/createDefaultConnectionEgressHandlers.d.ts +5 -0
- package/lib/createDefaultConnectionEgressHandlers.d.ts.map +1 -0
- package/lib/createDefaultConnectionEgressHandlers.js +20 -0
- package/lib/createDefaultConnectionEgressHandlers.js.map +1 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +17 -0
- package/lib/makeConnectManager.d.ts +90 -0
- package/lib/makeConnectManager.d.ts.map +1 -0
- package/lib/makeConnectManager.js +91 -0
- package/lib/makeConnectManager.js.map +1 -0
- package/lib/oauth/storage.d.ts +9 -0
- package/lib/oauth/storage.d.ts.map +1 -0
- package/lib/oauth/storage.js +16 -0
- package/lib/oauth/storage.js.map +1 -0
- package/lib/publicOntology.d.ts +17 -0
- package/lib/publicOntology.d.ts.map +1 -0
- package/lib/publicOntology.js +86 -0
- package/lib/publicOntology.js.map +1 -0
- package/lib/server/index.d.ts +33 -0
- package/lib/server/index.d.ts.map +1 -0
- package/lib/server/index.js +119 -0
- package/lib/server/index.js.map +1 -0
- package/lib/serverClient.d.ts +28 -0
- package/lib/serverClient.d.ts.map +1 -0
- package/lib/serverClient.js +67 -0
- package/lib/serverClient.js.map +1 -0
- package/lib/serviceConnections.d.ts +39 -0
- package/lib/serviceConnections.d.ts.map +1 -0
- package/lib/serviceConnections.js +277 -0
- package/lib/serviceConnections.js.map +1 -0
- package/lib/spec/index.d.ts +958 -0
- package/lib/spec/index.d.ts.map +1 -0
- package/lib/spec/index.js +565 -0
- package/lib/spec/index.js.map +1 -0
- package/lib/toWebEgress.d.ts +12 -0
- package/lib/toWebEgress.d.ts.map +1 -0
- package/lib/toWebEgress.js +28 -0
- package/lib/toWebEgress.js.map +1 -0
- package/lib/types.d.ts +44 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +25 -0
- package/lib/types.js.map +1 -0
- package/lib/withHttpAuthenticationErrors.d.ts +5 -0
- package/lib/withHttpAuthenticationErrors.d.ts.map +1 -0
- package/lib/withHttpAuthenticationErrors.js +20 -0
- package/lib/withHttpAuthenticationErrors.js.map +1 -0
- package/package.json +34 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","names":[],"sources":["../../src/core/store.ts"],"sourcesContent":["import { makeOwnedBackend } from \"@party-stack/ontology-backend/owned\";\nimport { compileEffectSchemas } from \"@party-stack/ontology-spec/effect\";\nimport { field } from \"@party-stack/ontology-storage\";\nimport { Context, Effect } from \"effect\";\nimport { connectOntology } from \"../spec/index.js\";\nimport { connectError, type ConnectError } from \"./errors.js\";\nimport { migrateConnectCredentials } from \"./migrate.js\";\nimport type {\n OAuthConnectionRecord,\n OAuthApplicationRecord,\n ServiceInstanceRecord,\n OAuthAuthorizationAttemptRecord,\n ApiKeyConnectionRecord,\n ExternalSessionConnectionRecord,\n} from \"../spec/index.js\";\nimport type { OwnedReadTransaction, OwnedStorageTransaction } from \"@party-stack/ontology-backend/owned\";\nimport type { OntologyIR } from \"@party-stack/ontology-spec\";\nimport type { Query } from \"@party-stack/ontology-storage\";\nimport type { TablesService } from \"@party-stack/ontology-storage/tables\";\n\ntype Records = {\n ServiceInstance: ServiceInstanceRecord;\n OAuthApplication: OAuthApplicationRecord;\n OAuthConnection: OAuthConnectionRecord;\n OAuthAuthorizationAttempt: OAuthAuthorizationAttemptRecord;\n ApiKeyConnection: ApiKeyConnectionRecord;\n ExternalSessionConnection: ExternalSessionConnectionRecord;\n};\n/** Remote implementations may implement this boundary with trusted ontology actions.\n * transaction must atomically enforce the read/write decisions in its body.\n */\nexport interface ConnectStore {\n get<N extends keyof Records>(name: N, id: string): Effect.Effect<Records[N] | undefined, ConnectError>;\n put<N extends keyof Records>(name: N, value: Records[N]): Effect.Effect<void, ConnectError>;\n delete<N extends keyof Records>(name: N, id: string): Effect.Effect<void, ConnectError>;\n load<N extends keyof Records>(name: N, query: Query): Effect.Effect<Records[N][], ConnectError>;\n transaction<A, E, R>(body: Effect.Effect<A, E, R>): Effect.Effect<A, E | ConnectError, R>;\n}\n\n/** Additional application properties are validated and preserved by the compiled ontology. */\nexport const makeConnectPersistence = Effect.fn(\"Connect.persistence\")(function* (options: {\n tables: TablesService;\n namespace: string;\n ir?: OntologyIR;\n maintenance?: false | { readonly intervalMs?: number };\n}) {\n const ir = options.ir ?? connectOntology;\n const protect = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.mapError(() => connectError(\"Storage\", \"Connect storage operation failed.\", true))\n );\n // Compile application extensions, then check that every standard property remains compatible.\n yield* Effect.try({\n try: () => {\n for (const base of connectOntology.objectTypes) {\n const definition = ir.objectTypes.find((candidate) => candidate.name === base.name);\n if (!definition || definition.primaryKey !== base.primaryKey) throw new Error();\n for (const property of base.properties) {\n const actual = definition.properties.find(\n (candidate) => candidate.name === property.name\n );\n if (!actual || JSON.stringify(actual.type) !== JSON.stringify(property.type))\n throw new Error();\n }\n }\n compileEffectSchemas(ir);\n },\n catch: () =>\n connectError(\n \"Configuration\",\n \"Connect definitions must retain their standard properties and primary keys.\"\n ),\n });\n const backend = yield* makeOwnedBackend({\n ...options,\n // Version 3 adds per-application OAuth scopes. Import v2 records below;\n // credential encryption uses options.namespace, so handles retain their AAD.\n namespace: JSON.stringify([options.namespace, \"connect\", 3]),\n ir,\n mutators: {},\n });\n // Each persistence instance has its own transaction binding. Nested calls compose;\n // concurrent effects and different Connect authorities never share a transaction.\n const CurrentTransaction = Context.Service<OwnedStorageTransaction>(\n `Connect.transaction:${crypto.randomUUID()}`\n );\n const inTransaction = <A, E, R>(body: (tx: OwnedStorageTransaction) => Effect.Effect<A, E, R>) =>\n Effect.serviceOption(CurrentTransaction).pipe(\n Effect.flatMap((current) =>\n current._tag === \"Some\" ? body(current.value) : backend.storage.transaction(body)\n )\n );\n const read = <A, E, R>(body: (tx: OwnedReadTransaction) => Effect.Effect<A, E, R>) =>\n Effect.serviceOption(CurrentTransaction).pipe(\n Effect.flatMap((current) =>\n current._tag === \"Some\" ? body(current.value) : backend.storage.read(body)\n )\n );\n const store: ConnectStore = {\n get: (name, id) =>\n protect(read((tx) => tx.get(name, id))).pipe(\n Effect.map((value) => value as Records[typeof name] | undefined)\n ),\n put: (name, value) => protect(inTransaction((tx) => tx.put(name, value))),\n delete: (name, id) => protect(inTransaction((tx) => tx.delete(name, id))),\n load: (name, query) =>\n protect(read((tx) => tx.loadSubset(name, query))).pipe(\n Effect.map((rows) => rows.map((row) => row.value as Records[typeof name]))\n ),\n transaction: (body) =>\n inTransaction((tx) => body.pipe(Effect.provideService(CurrentTransaction, tx))).pipe(\n Effect.catchTag(\"BackendError\", () =>\n Effect.fail(connectError(\"Storage\", \"Connect transaction failed.\", true))\n )\n ),\n };\n for (const [name, fields] of Object.entries({\n OAuthApplication: [\"serviceInstance\", \"connection\"],\n OAuthConnection: [\n \"application\",\n \"userId\",\n \"accessTokenExpiresAt\",\n \"refreshTokenExpiresAt\",\n \"operationExpiresAt\",\n ],\n OAuthAuthorizationAttempt: [\"expiresAt\", \"application\", \"connectionId\"],\n ApiKeyConnection: [\"serviceInstance\", \"userId\", \"expiresAt\"],\n ExternalSessionConnection: [\"serviceInstance\", \"userId\", \"sessionId\", \"expiresAt\"],\n }))\n for (const property of fields)\n yield* protect(\n backend.storage.transaction((tx) =>\n tx.ensureIndex(name, { name: property, field: field(property) })\n )\n );\n yield* protect(migrateConnectCredentials({ ...options, ir, store }));\n return { store, backend };\n});\n\nexport const makeConnectStore = Effect.fn(\"Connect.store\")(function* (\n options: Parameters<typeof makeConnectPersistence>[0]\n) {\n return (yield* makeConnectPersistence(options)).store;\n});\n"],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ConnectionEgressHandlers } from "./types.js";
|
|
2
|
+
//#region src/createDefaultConnectionEgressHandlers.d.ts
|
|
3
|
+
export declare function createDefaultConnectionEgressHandlers(): ConnectionEgressHandlers;
|
|
4
|
+
//#endregion
|
|
5
|
+
//# sourceMappingURL=createDefaultConnectionEgressHandlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDefaultConnectionEgressHandlers.d.ts","names":[],"sources":["../src/createDefaultConnectionEgressHandlers.ts"],"mappings":";;wBAEgB,yCAAyC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { classifyBackendFailure } from "@party-stack/ontology-backend";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
//#region src/createDefaultConnectionEgressHandlers.ts
|
|
4
|
+
function createDefaultConnectionEgressHandlers() {
|
|
5
|
+
const fetchImpl = globalThis.fetch.bind(globalThis);
|
|
6
|
+
return {
|
|
7
|
+
fetch: (request) => Effect.tryPromise({
|
|
8
|
+
try: (signal) => fetchImpl(new Request(request, { signal: AbortSignal.any([request.signal, signal]) })),
|
|
9
|
+
catch: (cause) => classifyBackendFailure("connect.egress.fetch", cause)
|
|
10
|
+
}),
|
|
11
|
+
createWebSocket: (url, protocols) => Effect.try({
|
|
12
|
+
try: () => new WebSocket(url, protocols),
|
|
13
|
+
catch: (cause) => classifyBackendFailure("connect.egress.webSocket", cause)
|
|
14
|
+
})
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createDefaultConnectionEgressHandlers };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=createDefaultConnectionEgressHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDefaultConnectionEgressHandlers.js","names":[],"sources":["../src/createDefaultConnectionEgressHandlers.ts"],"sourcesContent":["import type { ConnectionEgressHandlers } from \"./types.js\";\n\nexport function createDefaultConnectionEgressHandlers(): ConnectionEgressHandlers {\n const fetchImpl = globalThis.fetch.bind(globalThis);\n return {\n fetch: (request) =>\n Effect.tryPromise({\n try: (signal) =>\n fetchImpl(\n new Request(request, {\n signal: AbortSignal.any([request.signal, signal]),\n })\n ),\n catch: (cause) => classifyBackendFailure(\"connect.egress.fetch\", cause),\n }),\n createWebSocket: (url, protocols) =>\n Effect.try({\n try: () => new WebSocket(url, protocols),\n catch: (cause) => classifyBackendFailure(\"connect.egress.webSocket\", cause),\n }),\n };\n}\nimport { classifyBackendFailure } from \"@party-stack/ontology-backend\";\nimport { Effect } from \"effect\";\n"],"mappings":";;;AAEA,SAAgB,wCAAkE;CAC9E,MAAM,YAAY,WAAW,MAAM,KAAK,UAAU;CAClD,OAAO;EACH,QAAQ,YACJ,OAAO,WAAW;GACd,MAAM,WACF,UACI,IAAI,QAAQ,SAAS,EACjB,QAAQ,YAAY,IAAI,CAAC,QAAQ,QAAQ,MAAM,CAAC,EACpD,CAAC,CACL;GACJ,QAAQ,UAAU,uBAAuB,wBAAwB,KAAK;EAC1E,CAAC;EACL,kBAAkB,KAAK,cACnB,OAAO,IAAI;GACP,WAAW,IAAI,UAAU,KAAK,SAAS;GACvC,QAAQ,UAAU,uBAAuB,4BAA4B,KAAK;EAC9E,CAAC;CACT;AACJ"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConnectError } from "./core/errors.js";
|
|
2
|
+
import { ConnectStore, makeConnectStore } from "./core/store.js";
|
|
3
|
+
import { BeginAuthorization, ConnectCredentialValues, ConnectOAuthService, OAuthTokens } from "./core/oauthAuthority.js";
|
|
4
|
+
import { Connection, ConnectionEgress, ConnectionEgressHandlers, ConnectionMonitor, ConnectionState, ConnectionStateSchema, ConnectionStatus } from "./types.js";
|
|
5
|
+
import { ConnectionRef, SavedConnection, ServiceConnector, VerifiedServiceIdentity } from "./ServiceConnector.js";
|
|
6
|
+
import { createDefaultConnectionEgressHandlers } from "./createDefaultConnectionEgressHandlers.js";
|
|
7
|
+
import { withHttpAuthenticationErrors } from "./withHttpAuthenticationErrors.js";
|
|
8
|
+
import { OAuthServiceOptions, makeOAuthService } from "./core/oauth.js";
|
|
9
|
+
import { makeServerConnectClient } from "./serverClient.js";
|
|
10
|
+
import { ConnectActionHandler, makeConnectBackend } from "./core/backend.js";
|
|
11
|
+
import { connectionAccessToken } from "./core/accessToken.js";
|
|
12
|
+
import { OAuthAuthorizationClient, OAuthAuthorizationSource, bindOAuthAuthorizationBackend, makeOAuthAuthorizationClient, oauthAuthorizationOntology } from "./authorization.js";
|
|
13
|
+
import { runtimeCredentialValues } from "./oauth/storage.js";
|
|
14
|
+
import { connectDeviceRoute, connectPublicOntologyIR } from "./publicOntology.js";
|
|
15
|
+
import { AccountRef, AccountSummary, AuthenticationClient, makeAuthenticationClient } from "./authentication.js";
|
|
16
|
+
import { ConnectionAccess } from "./serviceConnections.js";
|
|
17
|
+
import { toWebEgress } from "./toWebEgress.js";
|
|
18
|
+
import { ConnectInstanceConfiguration, ConnectManager, ConnectManagerOptions, ConnectManagerService, ConnectOAuthApplicationConfiguration, ConnectServiceConfiguration, makeConnectManager } from "./makeConnectManager.js";
|
|
19
|
+
import { acquireConfiguredConnection } from "./acquireConfiguredConnection.js";
|
|
20
|
+
export { type AccountRef, type AccountSummary, type AuthenticationClient, type BeginAuthorization, type ConnectActionHandler, type ConnectCredentialValues, ConnectError, type ConnectInstanceConfiguration, ConnectManager, type ConnectManagerOptions, type ConnectManagerService, type ConnectOAuthApplicationConfiguration, type ConnectOAuthService, type ConnectServiceConfiguration, type ConnectStore, type Connection, type ConnectionAccess, type ConnectionEgress, type ConnectionEgressHandlers, type ConnectionMonitor, type ConnectionRef, type ConnectionState, ConnectionStateSchema, type ConnectionStatus, type OAuthAuthorizationClient, type OAuthAuthorizationSource, type OAuthServiceOptions, type OAuthTokens, type SavedConnection, type ServiceConnector, type VerifiedServiceIdentity, acquireConfiguredConnection, bindOAuthAuthorizationBackend, connectDeviceRoute, connectPublicOntologyIR, connectionAccessToken, createDefaultConnectionEgressHandlers, makeAuthenticationClient, makeConnectBackend, makeConnectManager, makeConnectStore, makeOAuthAuthorizationClient, makeOAuthService, makeServerConnectClient, oauthAuthorizationOntology, runtimeCredentialValues, toWebEgress, withHttpAuthenticationErrors };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { bindOAuthAuthorizationBackend, makeOAuthAuthorizationClient, oauthAuthorizationOntology } from "./authorization.js";
|
|
2
|
+
import { makeAuthenticationClient } from "./authentication.js";
|
|
3
|
+
import { ConnectError } from "./core/errors.js";
|
|
4
|
+
import { makeConnectStore } from "./core/store.js";
|
|
5
|
+
import { makeConnectBackend } from "./core/backend.js";
|
|
6
|
+
import { acquireConfiguredConnection } from "./acquireConfiguredConnection.js";
|
|
7
|
+
import { createDefaultConnectionEgressHandlers } from "./createDefaultConnectionEgressHandlers.js";
|
|
8
|
+
import { ConnectionStateSchema } from "./types.js";
|
|
9
|
+
import { withHttpAuthenticationErrors } from "./withHttpAuthenticationErrors.js";
|
|
10
|
+
import { runtimeCredentialValues } from "./oauth/storage.js";
|
|
11
|
+
import { connectionAccessToken } from "./core/accessToken.js";
|
|
12
|
+
import { ConnectManager, makeConnectManager } from "./makeConnectManager.js";
|
|
13
|
+
import { makeOAuthService } from "./core/oauth.js";
|
|
14
|
+
import { makeServerConnectClient } from "./serverClient.js";
|
|
15
|
+
import { connectDeviceRoute, connectPublicOntologyIR } from "./publicOntology.js";
|
|
16
|
+
import { toWebEgress } from "./toWebEgress.js";
|
|
17
|
+
export { ConnectError, ConnectManager, ConnectionStateSchema, acquireConfiguredConnection, bindOAuthAuthorizationBackend, connectDeviceRoute, connectPublicOntologyIR, connectionAccessToken, createDefaultConnectionEgressHandlers, makeAuthenticationClient, makeConnectBackend, makeConnectManager, makeConnectStore, makeOAuthAuthorizationClient, makeOAuthService, makeServerConnectClient, oauthAuthorizationOntology, runtimeCredentialValues, toWebEgress, withHttpAuthenticationErrors };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { OAuthApplicationRecord, ServiceInstanceRecord } from "./spec/index.js";
|
|
2
|
+
import { ConnectStore } from "./core/store.js";
|
|
3
|
+
import { ConnectCredentialValues, OAuthAuthorityService } from "./core/oauthAuthority.js";
|
|
4
|
+
import { ConnectionEgress, ConnectionMonitor } from "./types.js";
|
|
5
|
+
import { ConnectionRef, ServiceConnector } from "./ServiceConnector.js";
|
|
6
|
+
import { ConnectActionHandler } from "./core/backend.js";
|
|
7
|
+
import "./index.js";
|
|
8
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
9
|
+
import { Context, Effect, Layer } from "effect";
|
|
10
|
+
import { OntologyIR } from "@party-stack/ontology-spec";
|
|
11
|
+
import { Runtime } from "@party-stack/runtime";
|
|
12
|
+
//#region src/makeConnectManager.d.ts
|
|
13
|
+
/** A device/server credential owner. Runtime supplies Tables and key storage;
|
|
14
|
+
* service integrations supply authentication/egress, and the ontology stores inventory.
|
|
15
|
+
* Expose backend through a policy-bound ordinary ontology server.
|
|
16
|
+
*/
|
|
17
|
+
export interface ConnectOAuthApplicationConfiguration extends Omit<OAuthApplicationRecord, "serviceInstance" | "id" | "title" | "flow"> {
|
|
18
|
+
readonly id?: string;
|
|
19
|
+
readonly title?: string;
|
|
20
|
+
readonly flow?: OAuthApplicationRecord["flow"];
|
|
21
|
+
}
|
|
22
|
+
export interface ConnectInstanceConfiguration extends Omit<ServiceInstanceRecord, "service" | "id" | "title"> {
|
|
23
|
+
readonly id?: string;
|
|
24
|
+
readonly title?: string;
|
|
25
|
+
readonly OAuthApplications?: readonly ConnectOAuthApplicationConfiguration[];
|
|
26
|
+
}
|
|
27
|
+
export interface ConnectServiceConfiguration {
|
|
28
|
+
readonly connector: ServiceConnector;
|
|
29
|
+
readonly instances?: readonly ConnectInstanceConfiguration[];
|
|
30
|
+
}
|
|
31
|
+
export interface ConnectManagerOptions {
|
|
32
|
+
readonly ir?: OntologyIR;
|
|
33
|
+
readonly actionHandlers?: Readonly<Record<string, ConnectActionHandler>>;
|
|
34
|
+
readonly namespace?: string;
|
|
35
|
+
readonly services: readonly ConnectServiceConfiguration[];
|
|
36
|
+
/** Start the scoped periodic sweep. Alarms/jobs call maintenance.run themselves. */
|
|
37
|
+
readonly startMaintenance?: boolean;
|
|
38
|
+
readonly maintenance?: {
|
|
39
|
+
readonly intervalMs?: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export declare const makeConnectManager: (options: ConnectManagerOptions) => Effect.Effect<{
|
|
43
|
+
backend: import("@party-stack/ontology-backend").OntologyBackendService;
|
|
44
|
+
connect: OAuthAuthorityService;
|
|
45
|
+
store: ConnectStore;
|
|
46
|
+
values: ConnectCredentialValues;
|
|
47
|
+
connections: {
|
|
48
|
+
acquire: (connection: ConnectionRef) => Effect.Effect<{
|
|
49
|
+
connection: {
|
|
50
|
+
readonly objectType: "ApiKeyConnection" | "ExternalSessionConnection" | "OAuthConnection";
|
|
51
|
+
readonly id: string;
|
|
52
|
+
};
|
|
53
|
+
userId: string;
|
|
54
|
+
serviceInstance: ServiceInstanceRecord;
|
|
55
|
+
egress: ConnectionEgress;
|
|
56
|
+
authentication: ConnectionMonitor;
|
|
57
|
+
}, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, import("effect/Scope").Scope>;
|
|
58
|
+
};
|
|
59
|
+
maintenance: {
|
|
60
|
+
run: Effect.Effect<void, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
|
|
61
|
+
};
|
|
62
|
+
}, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, Runtime | import("effect/Scope").Scope>;
|
|
63
|
+
export type ConnectManagerService = Effect.Success<ReturnType<typeof makeConnectManager>>;
|
|
64
|
+
declare const ConnectManager_base: Context.ServiceClass<ConnectManager, "@party-stack/connect/ConnectManager", {
|
|
65
|
+
backend: import("@party-stack/ontology-backend").OntologyBackendService;
|
|
66
|
+
connect: OAuthAuthorityService;
|
|
67
|
+
store: ConnectStore;
|
|
68
|
+
values: ConnectCredentialValues;
|
|
69
|
+
connections: {
|
|
70
|
+
acquire: (connection: ConnectionRef) => Effect.Effect<{
|
|
71
|
+
connection: {
|
|
72
|
+
readonly objectType: "ApiKeyConnection" | "ExternalSessionConnection" | "OAuthConnection";
|
|
73
|
+
readonly id: string;
|
|
74
|
+
};
|
|
75
|
+
userId: string;
|
|
76
|
+
serviceInstance: ServiceInstanceRecord;
|
|
77
|
+
egress: ConnectionEgress;
|
|
78
|
+
authentication: ConnectionMonitor;
|
|
79
|
+
}, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, import("effect/Scope").Scope>;
|
|
80
|
+
};
|
|
81
|
+
maintenance: {
|
|
82
|
+
run: Effect.Effect<void, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, never>;
|
|
83
|
+
};
|
|
84
|
+
}>;
|
|
85
|
+
export declare class ConnectManager extends ConnectManager_base {
|
|
86
|
+
static readonly layer: (options: ConnectManagerOptions) => Layer.Layer<ConnectManager, BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, Runtime>;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=makeConnectManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeConnectManager.d.ts","names":["_$__core_oauthAuthority_js0.OAuthAuthorityService","_$__index_js0.ConnectStore","_$__index_js0.ConnectCredentialValues","_$__ServiceConnector_js0.ConnectionRef","_$__types_js0.ConnectionEgress","_$__types_js0.ConnectionMonitor"],"sources":["../src/makeConnectManager.ts"],"mappings":";;;;;;;;;;;;;;;;iBAeiB,6CAA6C,KAC1D;WAGS;WACA;WACA,OAAO;;iBAEH,qCAAqC,KAClD;WAGS;WACA;WACA,6BAA6B;;iBAEzB;WACJ,WAAW;WACX,qBAAqB;;iBAEjB;WACJ,KAAK;WACL,iBAAiB,SAAS,eAAe;WACzC;WACA,mBAAmB;;WAEnB;WACA;aAAyB;;;qBAEzB,qBAAkB,SAAA,0BAAA,OAAA;;WAAAA;;;;;;;;;;;;;;;;IA2EgC,KAAG,OAAA,aAAA;;GAChE,iWAAA,iCAAA;YAEU,wBAAwB,OAAO,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;IAHN,KAAG,OAAA,aAAA;;;qBAIrD,uBAAuB;kBAGhB,QAAK,SAAa,0BAAqB,MAAA,MAAA,gBAAA,iWAAA"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { connectBackendError, makeConnectBackend } from "./core/backend.js";
|
|
2
|
+
import { runtimeCredentialValues } from "./oauth/storage.js";
|
|
3
|
+
import { makeServiceConnections } from "./serviceConnections.js";
|
|
4
|
+
import { BackendError } from "@party-stack/ontology-backend";
|
|
5
|
+
import { Context, Effect, Layer } from "effect";
|
|
6
|
+
import { Runtime } from "@party-stack/runtime";
|
|
7
|
+
//#region src/makeConnectManager.ts
|
|
8
|
+
const makeConnectManager = Effect.fn("ConnectManager.make")(function* (options) {
|
|
9
|
+
const runtime = yield* Runtime;
|
|
10
|
+
const namespace = options.namespace ?? runtime.namespace;
|
|
11
|
+
const values = yield* runtimeCredentialValues(runtime, namespace).pipe(Effect.mapError(connectBackendError));
|
|
12
|
+
const instances = [];
|
|
13
|
+
const applications = [];
|
|
14
|
+
for (const configured of options.services) {
|
|
15
|
+
const { connector } = configured;
|
|
16
|
+
for (const { OAuthApplications, ...instance } of configured.instances ?? []) {
|
|
17
|
+
const canonicalUrl = yield* Effect.try({
|
|
18
|
+
try: () => new URL(instance.instanceUrl).href.replace(/\/+$/, ""),
|
|
19
|
+
catch: () => new BackendError({
|
|
20
|
+
operation: "connect.configure",
|
|
21
|
+
kind: "InvalidConfiguration",
|
|
22
|
+
retryable: false,
|
|
23
|
+
message: "A service instance must have an absolute URL."
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
const id = instance.id ?? JSON.stringify([connector.service, canonicalUrl]);
|
|
27
|
+
const title = instance.title ?? connector.displayName ?? connector.service;
|
|
28
|
+
instances.push({
|
|
29
|
+
...instance,
|
|
30
|
+
id,
|
|
31
|
+
title,
|
|
32
|
+
service: connector.service
|
|
33
|
+
});
|
|
34
|
+
for (const application of OAuthApplications ?? []) {
|
|
35
|
+
const scopes = application.scopes ?? connector.defaultOAuthScopes;
|
|
36
|
+
applications.push({
|
|
37
|
+
...application,
|
|
38
|
+
id: application.id ?? JSON.stringify([id, application.clientId]),
|
|
39
|
+
title: application.title ?? title,
|
|
40
|
+
flow: application.flow ?? "authorization-code",
|
|
41
|
+
scopes: scopes === void 0 ? void 0 : [...scopes],
|
|
42
|
+
serviceInstance: id
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (new Set(instances.map((row) => row.id)).size !== instances.length || new Set(applications.map((row) => row.id)).size !== applications.length) return yield* new BackendError({
|
|
48
|
+
operation: "connect.configure",
|
|
49
|
+
kind: "InvalidConfiguration",
|
|
50
|
+
retryable: false,
|
|
51
|
+
message: "Service instance and OAuth application IDs must be unique."
|
|
52
|
+
});
|
|
53
|
+
const authority = yield* makeConnectBackend({
|
|
54
|
+
ir: options.ir,
|
|
55
|
+
actionHandlers: options.actionHandlers,
|
|
56
|
+
tables: runtime.tables,
|
|
57
|
+
namespace,
|
|
58
|
+
values,
|
|
59
|
+
services: options.services.map((entry) => entry.connector),
|
|
60
|
+
maintenance: options.startMaintenance === false ? false : options.maintenance
|
|
61
|
+
});
|
|
62
|
+
yield* authority.store.transaction(Effect.gen(function* () {
|
|
63
|
+
for (const instance of instances) yield* authority.store.put("ServiceInstance", instance);
|
|
64
|
+
for (const application of applications) {
|
|
65
|
+
const previous = yield* authority.store.get("OAuthApplication", application.id);
|
|
66
|
+
yield* authority.store.put("OAuthApplication", {
|
|
67
|
+
...previous,
|
|
68
|
+
...application
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
})).pipe(Effect.mapError(connectBackendError));
|
|
72
|
+
yield* authority.connect.collectExpired().pipe(Effect.mapError(connectBackendError));
|
|
73
|
+
const connections = yield* makeServiceConnections({
|
|
74
|
+
backend: authority.backend,
|
|
75
|
+
store: authority.store,
|
|
76
|
+
services: options.services.map((entry) => entry.connector)
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
...authority,
|
|
80
|
+
values,
|
|
81
|
+
connections,
|
|
82
|
+
maintenance: { run: authority.backend.maintenance }
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
var ConnectManager = class ConnectManager extends Context.Service()("@party-stack/connect/ConnectManager") {
|
|
86
|
+
static layer = (options) => Layer.effect(ConnectManager, makeConnectManager(options));
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
export { ConnectManager, makeConnectManager };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=makeConnectManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeConnectManager.js","names":[],"sources":["../src/makeConnectManager.ts"],"sourcesContent":["import { BackendError } from \"@party-stack/ontology-backend\";\nimport { Runtime } from \"@party-stack/runtime\";\nimport { Context, Effect, Layer } from \"effect\";\nimport { makeConnectBackend, connectBackendError } from \"./core/backend.js\";\nimport { runtimeCredentialValues } from \"./oauth/storage.js\";\nimport { makeServiceConnections } from \"./serviceConnections.js\";\nimport type { ConnectActionHandler } from \"./core/backend.js\";\nimport type { ServiceConnector } from \"./ServiceConnector.js\";\nimport type { OAuthApplicationRecord, ServiceInstanceRecord } from \"./spec/index.js\";\nimport type { OntologyIR } from \"@party-stack/ontology-spec\";\n\n/** A device/server credential owner. Runtime supplies Tables and key storage;\n * service integrations supply authentication/egress, and the ontology stores inventory.\n * Expose backend through a policy-bound ordinary ontology server.\n */\nexport interface ConnectOAuthApplicationConfiguration extends Omit<\n OAuthApplicationRecord,\n \"serviceInstance\" | \"id\" | \"title\" | \"flow\"\n> {\n readonly id?: string;\n readonly title?: string;\n readonly flow?: OAuthApplicationRecord[\"flow\"];\n}\nexport interface ConnectInstanceConfiguration extends Omit<\n ServiceInstanceRecord,\n \"service\" | \"id\" | \"title\"\n> {\n readonly id?: string;\n readonly title?: string;\n readonly OAuthApplications?: readonly ConnectOAuthApplicationConfiguration[];\n}\nexport interface ConnectServiceConfiguration {\n readonly connector: ServiceConnector;\n readonly instances?: readonly ConnectInstanceConfiguration[];\n}\nexport interface ConnectManagerOptions {\n readonly ir?: OntologyIR;\n readonly actionHandlers?: Readonly<Record<string, ConnectActionHandler>>;\n readonly namespace?: string;\n readonly services: readonly ConnectServiceConfiguration[];\n /** Start the scoped periodic sweep. Alarms/jobs call maintenance.run themselves. */\n readonly startMaintenance?: boolean;\n readonly maintenance?: { readonly intervalMs?: number };\n}\nexport const makeConnectManager = Effect.fn(\"ConnectManager.make\")(function* (\n options: ConnectManagerOptions\n) {\n const runtime = yield* Runtime;\n const namespace = options.namespace ?? runtime.namespace;\n const values = yield* runtimeCredentialValues(runtime, namespace).pipe(\n Effect.mapError(connectBackendError)\n );\n const instances: ServiceInstanceRecord[] = [];\n const applications: OAuthApplicationRecord[] = [];\n for (const configured of options.services) {\n const { connector } = configured;\n for (const { OAuthApplications, ...instance } of configured.instances ?? []) {\n const canonicalUrl = yield* Effect.try({\n try: () => new URL(instance.instanceUrl).href.replace(/\\/+$/, \"\"),\n catch: () =>\n new BackendError({\n operation: \"connect.configure\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"A service instance must have an absolute URL.\",\n }),\n });\n const id = instance.id ?? JSON.stringify([connector.service, canonicalUrl]);\n const title = instance.title ?? connector.displayName ?? connector.service;\n instances.push({ ...instance, id, title, service: connector.service });\n for (const application of OAuthApplications ?? []) {\n const scopes = application.scopes ?? connector.defaultOAuthScopes;\n applications.push({\n ...application,\n id: application.id ?? JSON.stringify([id, application.clientId]),\n title: application.title ?? title,\n flow: application.flow ?? \"authorization-code\",\n scopes: scopes === undefined ? undefined : [...scopes],\n serviceInstance: id,\n });\n }\n }\n }\n if (\n new Set(instances.map((row) => row.id)).size !== instances.length ||\n new Set(applications.map((row) => row.id)).size !== applications.length\n )\n return yield* new BackendError({\n operation: \"connect.configure\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"Service instance and OAuth application IDs must be unique.\",\n });\n const authority = yield* makeConnectBackend({\n ir: options.ir,\n actionHandlers: options.actionHandlers,\n tables: runtime.tables,\n namespace,\n values,\n services: options.services.map((entry) => entry.connector),\n maintenance: options.startMaintenance === false ? false : options.maintenance,\n });\n yield* authority.store\n .transaction(\n Effect.gen(function* () {\n for (const instance of instances) yield* authority.store.put(\"ServiceInstance\", instance);\n for (const application of applications) {\n const previous = yield* authority.store.get(\"OAuthApplication\", application.id);\n yield* authority.store.put(\"OAuthApplication\", { ...previous, ...application });\n }\n })\n )\n .pipe(Effect.mapError(connectBackendError));\n yield* authority.connect.collectExpired().pipe(Effect.mapError(connectBackendError));\n const connections = yield* makeServiceConnections({\n backend: authority.backend,\n store: authority.store,\n services: options.services.map((entry) => entry.connector),\n });\n return { ...authority, values, connections, maintenance: { run: authority.backend.maintenance! } };\n});\n\nexport type ConnectManagerService = Effect.Success<ReturnType<typeof makeConnectManager>>;\nexport class ConnectManager extends Context.Service<ConnectManager, ConnectManagerService>()(\n \"@party-stack/connect/ConnectManager\"\n) {\n static readonly layer = (options: ConnectManagerOptions) =>\n Layer.effect(ConnectManager, makeConnectManager(options));\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConnectError } from "../core/errors.js";
|
|
2
|
+
import { ConnectCredentialValues } from "../core/oauthAuthority.js";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { RuntimeService } from "@party-stack/runtime";
|
|
5
|
+
//#region src/oauth/storage.d.ts
|
|
6
|
+
/** Credentials use embedded ciphertext in Tables; only the keyring owns encryption keys. */
|
|
7
|
+
export declare function runtimeCredentialValues(runtime: RuntimeService, namespace: string): Effect.Effect<ConnectCredentialValues, ConnectError>;
|
|
8
|
+
//#endregion
|
|
9
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","names":[],"sources":["../../src/oauth/storage.ts"],"mappings":";;;;;;wBAQgB,wBACZ,SAAS,gBACT,oBACD,OAAO,OAAO,yBAAyB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { connectError } from "../core/errors.js";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { makeEncryptedValues } from "@party-stack/ontology-storage/encrypted";
|
|
4
|
+
//#region src/oauth/storage.ts
|
|
5
|
+
/** Credentials use embedded ciphertext in Tables; only the keyring owns encryption keys. */
|
|
6
|
+
function runtimeCredentialValues(runtime, namespace) {
|
|
7
|
+
if (!runtime.encryptionKeyring) return Effect.fail(connectError("Configuration", "OAuth requires an encryption keyring. Configure platform key storage; persistent browser runtimes must explicitly opt into persistEncryptionKeys."));
|
|
8
|
+
return Effect.succeed({
|
|
9
|
+
...makeEncryptedValues(namespace, runtime.encryptionKeyring),
|
|
10
|
+
evict: () => Effect.void
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { runtimeCredentialValues };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","names":[],"sources":["../../src/oauth/storage.ts"],"sourcesContent":["import { makeEncryptedValues } from \"@party-stack/ontology-storage/encrypted\";\nimport { Effect } from \"effect\";\nimport { connectError } from \"../core/errors.js\";\nimport type { ConnectError } from \"../core/errors.js\";\nimport type { ConnectCredentialValues } from \"../core/oauthAuthority.js\";\nimport type { RuntimeService } from \"@party-stack/runtime\";\n\n/** Credentials use embedded ciphertext in Tables; only the keyring owns encryption keys. */\nexport function runtimeCredentialValues(\n runtime: RuntimeService,\n namespace: string\n): Effect.Effect<ConnectCredentialValues, ConnectError> {\n if (!runtime.encryptionKeyring)\n return Effect.fail(\n connectError(\n \"Configuration\",\n \"OAuth requires an encryption keyring. Configure platform key storage; persistent browser runtimes must explicitly opt into persistEncryptionKeys.\"\n )\n );\n return Effect.succeed({\n ...makeEncryptedValues(namespace, runtime.encryptionKeyring),\n evict: () => Effect.void,\n });\n}\n"],"mappings":";;;;;AAQA,SAAgB,wBACZ,SACA,WACoD;CACpD,IAAI,CAAC,QAAQ,mBACT,OAAO,OAAO,KACV,aACI,iBACA,mJACJ,CACJ;CACJ,OAAO,OAAO,QAAQ;EAClB,GAAG,oBAAoB,WAAW,QAAQ,iBAAiB;EAC3D,aAAa,OAAO;CACxB,CAAC;AACL"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConnectManagerService } from "./makeConnectManager.js";
|
|
2
|
+
import { OntologyIR } from "@party-stack/ontology-spec";
|
|
3
|
+
//#region src/publicOntology.d.ts
|
|
4
|
+
export declare const connectPublicOntologyIR: OntologyIR;
|
|
5
|
+
/** Private device ports share an account inventory. A public server must instead
|
|
6
|
+
* bind a caller-specific policy/context; this policy hides secrets but not accounts.
|
|
7
|
+
* Keep the current generic executor behind this composition until owned workflows
|
|
8
|
+
* provide its multi-transaction action lifecycle.
|
|
9
|
+
*/
|
|
10
|
+
export declare function connectDeviceRoute(manager: Pick<ConnectManagerService, "backend">): {
|
|
11
|
+
kind: "proxy";
|
|
12
|
+
backend: import("@party-stack/ontology-backend").OntologyBackendService;
|
|
13
|
+
ir: OntologyIR;
|
|
14
|
+
context: {};
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=publicOntology.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicOntology.d.ts","names":[],"sources":["../src/publicOntology.ts"],"mappings":";;;qBAuCa,yBAAyB;;;;;;wBAyBtB,mBAAmB,SAAS,KAAK;EAEzC;EACA,iDAAO;EACP,IAAE;EACF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { connectOntology } from "./spec/index.js";
|
|
2
|
+
import * as q from "@party-stack/ontology-spec/query";
|
|
3
|
+
//#region src/publicOntology.ts
|
|
4
|
+
/** Device-local public view. It exposes inventory and authentication actions while
|
|
5
|
+
* retaining token ciphertext and PKCE records at the credential owner. Public servers
|
|
6
|
+
* must additionally scope instances/connections to their authenticated caller.
|
|
7
|
+
*/
|
|
8
|
+
const read = { select: [
|
|
9
|
+
q.sub("services", {
|
|
10
|
+
from: {
|
|
11
|
+
source: { objectType: "ServiceInstance" },
|
|
12
|
+
binding: "s"
|
|
13
|
+
},
|
|
14
|
+
select: [
|
|
15
|
+
"id",
|
|
16
|
+
"title",
|
|
17
|
+
"service",
|
|
18
|
+
"instanceUrl"
|
|
19
|
+
].map((name) => q.selectField(name, q.field("s", name)))
|
|
20
|
+
}),
|
|
21
|
+
q.sub("applications", {
|
|
22
|
+
from: {
|
|
23
|
+
source: { objectType: "OAuthApplication" },
|
|
24
|
+
binding: "app"
|
|
25
|
+
},
|
|
26
|
+
select: [
|
|
27
|
+
"id",
|
|
28
|
+
"title",
|
|
29
|
+
"serviceInstance",
|
|
30
|
+
"flow",
|
|
31
|
+
"clientId",
|
|
32
|
+
"redirectUrl",
|
|
33
|
+
"scopes"
|
|
34
|
+
].map((name) => q.selectField(name, q.field("app", name)))
|
|
35
|
+
}),
|
|
36
|
+
...[
|
|
37
|
+
"OAuthConnection",
|
|
38
|
+
"ApiKeyConnection",
|
|
39
|
+
"ExternalSessionConnection"
|
|
40
|
+
].map((objectType) => q.sub(objectType, {
|
|
41
|
+
from: {
|
|
42
|
+
source: { objectType },
|
|
43
|
+
binding: "c"
|
|
44
|
+
},
|
|
45
|
+
select: [
|
|
46
|
+
"id",
|
|
47
|
+
"title",
|
|
48
|
+
"userId",
|
|
49
|
+
"status",
|
|
50
|
+
...objectType === "OAuthConnection" ? ["application", "accessTokenExpiresAt"] : ["serviceInstance", "expiresAt"]
|
|
51
|
+
].map((name) => q.selectField(name, q.field("c", name)))
|
|
52
|
+
}))
|
|
53
|
+
] };
|
|
54
|
+
const connectPublicOntologyIR = {
|
|
55
|
+
...connectOntology,
|
|
56
|
+
policy: {
|
|
57
|
+
objects: read,
|
|
58
|
+
actions: connectOntology.actionTypes.map((action) => ({
|
|
59
|
+
actionType: action.name,
|
|
60
|
+
check: action.name === "beginAuthorization" ? q.exists({
|
|
61
|
+
from: {
|
|
62
|
+
source: { objectType: "OAuthApplication" },
|
|
63
|
+
binding: "app"
|
|
64
|
+
},
|
|
65
|
+
where: q.and(q.eq(q.field("app", "id"), q.input("applicationId")), q.eq(q.field("app", "redirectUrl"), q.input("redirectUrl")))
|
|
66
|
+
}) : q.literal(true)
|
|
67
|
+
}))
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/** Private device ports share an account inventory. A public server must instead
|
|
71
|
+
* bind a caller-specific policy/context; this policy hides secrets but not accounts.
|
|
72
|
+
* Keep the current generic executor behind this composition until owned workflows
|
|
73
|
+
* provide its multi-transaction action lifecycle.
|
|
74
|
+
*/
|
|
75
|
+
function connectDeviceRoute(manager) {
|
|
76
|
+
return {
|
|
77
|
+
kind: "proxy",
|
|
78
|
+
backend: manager.backend,
|
|
79
|
+
ir: connectPublicOntologyIR,
|
|
80
|
+
context: {}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { connectDeviceRoute, connectPublicOntologyIR };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=publicOntology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicOntology.js","names":[],"sources":["../src/publicOntology.ts"],"sourcesContent":["import * as q from \"@party-stack/ontology-spec/query\";\nimport { connectOntology } from \"./spec/index.js\";\nimport type { ConnectManagerService } from \"./makeConnectManager.js\";\nimport type { OntologyIR } from \"@party-stack/ontology-spec\";\n\n/** Device-local public view. It exposes inventory and authentication actions while\n * retaining token ciphertext and PKCE records at the credential owner. Public servers\n * must additionally scope instances/connections to their authenticated caller.\n */\nconst read = {\n select: [\n q.sub(\"services\", {\n from: { source: { objectType: \"ServiceInstance\" }, binding: \"s\" },\n select: [\"id\", \"title\", \"service\", \"instanceUrl\"].map((name) =>\n q.selectField(name, q.field(\"s\", name))\n ),\n }),\n q.sub(\"applications\", {\n from: { source: { objectType: \"OAuthApplication\" }, binding: \"app\" },\n select: [\"id\", \"title\", \"serviceInstance\", \"flow\", \"clientId\", \"redirectUrl\", \"scopes\"].map(\n (name) => q.selectField(name, q.field(\"app\", name))\n ),\n }),\n ...([\"OAuthConnection\", \"ApiKeyConnection\", \"ExternalSessionConnection\"] as const).map((objectType) =>\n q.sub(objectType, {\n from: { source: { objectType }, binding: \"c\" },\n select: [\n \"id\",\n \"title\",\n \"userId\",\n \"status\",\n ...(objectType === \"OAuthConnection\"\n ? [\"application\", \"accessTokenExpiresAt\"]\n : [\"serviceInstance\", \"expiresAt\"]),\n ].map((name) => q.selectField(name, q.field(\"c\", name))),\n })\n ),\n ],\n};\nexport const connectPublicOntologyIR: OntologyIR = {\n ...connectOntology,\n policy: {\n objects: read,\n actions: connectOntology.actionTypes.map((action) => ({\n actionType: action.name,\n check:\n action.name === \"beginAuthorization\"\n ? q.exists({\n from: { source: { objectType: \"OAuthApplication\" }, binding: \"app\" },\n where: q.and(\n q.eq(q.field(\"app\", \"id\"), q.input(\"applicationId\")),\n q.eq(q.field(\"app\", \"redirectUrl\"), q.input(\"redirectUrl\"))\n ),\n })\n : q.literal(true),\n })),\n },\n};\n\n/** Private device ports share an account inventory. A public server must instead\n * bind a caller-specific policy/context; this policy hides secrets but not accounts.\n * Keep the current generic executor behind this composition until owned workflows\n * provide its multi-transaction action lifecycle.\n */\nexport function connectDeviceRoute(manager: Pick<ConnectManagerService, \"backend\">) {\n return {\n kind: \"proxy\" as const,\n backend: manager.backend,\n ir: connectPublicOntologyIR,\n context: {},\n };\n}\n"],"mappings":";;;;;;;AASA,MAAM,OAAO,EACT,QAAQ;CACJ,EAAE,IAAI,YAAY;EACd,MAAM;GAAE,QAAQ,EAAE,YAAY,kBAAkB;GAAG,SAAS;EAAI;EAChE,QAAQ;GAAC;GAAM;GAAS;GAAW;EAAa,CAAC,CAAC,KAAK,SACnD,EAAE,YAAY,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,CAC1C;CACJ,CAAC;CACD,EAAE,IAAI,gBAAgB;EAClB,MAAM;GAAE,QAAQ,EAAE,YAAY,mBAAmB;GAAG,SAAS;EAAM;EACnE,QAAQ;GAAC;GAAM;GAAS;GAAmB;GAAQ;GAAY;GAAe;EAAQ,CAAC,CAAC,KACnF,SAAS,EAAE,YAAY,MAAM,EAAE,MAAM,OAAO,IAAI,CAAC,CACtD;CACJ,CAAC;CACD,GAAI;EAAC;EAAmB;EAAoB;CAA2B,CAAC,CAAW,KAAK,eACpF,EAAE,IAAI,YAAY;EACd,MAAM;GAAE,QAAQ,EAAE,WAAW;GAAG,SAAS;EAAI;EAC7C,QAAQ;GACJ;GACA;GACA;GACA;GACA,GAAI,eAAe,oBACb,CAAC,eAAe,sBAAsB,IACtC,CAAC,mBAAmB,WAAW;EACzC,CAAC,CAAC,KAAK,SAAS,EAAE,YAAY,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;CAC3D,CAAC,CACL;AACJ,EACJ;AACA,MAAa,0BAAsC;CAC/C,GAAG;CACH,QAAQ;EACJ,SAAS;EACT,SAAS,gBAAgB,YAAY,KAAK,YAAY;GAClD,YAAY,OAAO;GACnB,OACI,OAAO,SAAS,uBACV,EAAE,OAAO;IACL,MAAM;KAAE,QAAQ,EAAE,YAAY,mBAAmB;KAAG,SAAS;IAAM;IACnE,OAAO,EAAE,IACL,EAAE,GAAG,EAAE,MAAM,OAAO,IAAI,GAAG,EAAE,MAAM,eAAe,CAAC,GACnD,EAAE,GAAG,EAAE,MAAM,OAAO,aAAa,GAAG,EAAE,MAAM,aAAa,CAAC,CAC9D;GACJ,CAAC,IACD,EAAE,QAAQ,IAAI;EAC5B,EAAE;CACN;AACJ;;;;;;AAOA,SAAgB,mBAAmB,SAAiD;CAChF,OAAO;EACH,MAAM;EACN,SAAS,QAAQ;EACjB,IAAI;EACJ,SAAS,CAAC;CACd;AACJ"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ConnectError } from "../core/errors.js";
|
|
2
|
+
import { OAuthAuthorizationAttemptRecord } from "../spec/index.js";
|
|
3
|
+
import { ConnectStore } from "../core/store.js";
|
|
4
|
+
import { OAuthAuthorityService } from "../core/oauthAuthority.js";
|
|
5
|
+
import { Effect } from "effect";
|
|
6
|
+
//#region src/server/index.d.ts
|
|
7
|
+
export interface ConnectPrincipal {
|
|
8
|
+
id: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ConnectServerOptions {
|
|
12
|
+
connect: OAuthAuthorityService;
|
|
13
|
+
store: ConnectStore;
|
|
14
|
+
/** Fixed, provider-registered URL. Never accepted from a browser request. */
|
|
15
|
+
callbackUrl: string;
|
|
16
|
+
appOrigin: string;
|
|
17
|
+
authenticate(request: Request): Effect.Effect<ConnectPrincipal, ConnectError>;
|
|
18
|
+
/** Check project/org permissions again on completion; return trusted extra attempt properties on begin. */
|
|
19
|
+
authorize(input: {
|
|
20
|
+
operation: "begin" | "complete" | "inspect";
|
|
21
|
+
principal: ConnectPrincipal;
|
|
22
|
+
applicationId: string;
|
|
23
|
+
connectionId?: string;
|
|
24
|
+
context?: unknown;
|
|
25
|
+
attempt?: OAuthAuthorizationAttemptRecord;
|
|
26
|
+
}): Effect.Effect<Record<string, unknown> | void, ConnectError>;
|
|
27
|
+
}
|
|
28
|
+
/** Mount /begin (POST), /callback (GET), /result (GET) beneath one application route.
|
|
29
|
+
* Promise conversion belongs to the hosting framework; all work here stays Effectful.
|
|
30
|
+
*/
|
|
31
|
+
export declare function makeConnectServer(options: ConnectServerOptions): (request: Request) => Effect.Effect<Response, never, never>;
|
|
32
|
+
//#endregion
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$___spec_index_js0.OAuthAuthorizationAttemptRecord"],"sources":["../../src/server/index.ts"],"mappings":";;;;;;iBAKiB;EACb;EACA;;iBAEa;EACb,SAAS;EACT,OAAO;;EAEP;EACA;EACA,aAAa,SAAS,UAAU,OAAO,OAAO,kBAAkB;;EAEhE,UAAU;IACN;IACA,WAAW;IACX;IACA;IACA;IACA,UAJWA;MAKX,OAAO,OAAO,gCAAgC;;;;;wBAetC,kBAAkB,SAAS,wBAAoB,SAAA,YAAA,OAAA,OAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { connectError } from "../core/errors.js";
|
|
2
|
+
import { Clock, Effect, Schema } from "effect";
|
|
3
|
+
//#region src/server/index.ts
|
|
4
|
+
const Start = Schema.Struct({
|
|
5
|
+
applicationId: Schema.NonEmptyString,
|
|
6
|
+
connectionId: Schema.optional(Schema.NonEmptyString),
|
|
7
|
+
returnUrl: Schema.NonEmptyString,
|
|
8
|
+
context: Schema.optional(Schema.Unknown)
|
|
9
|
+
});
|
|
10
|
+
const principalKey = (principal) => JSON.stringify([principal.id, principal.sessionId]);
|
|
11
|
+
const headers = {
|
|
12
|
+
"Cache-Control": "no-store",
|
|
13
|
+
"Referrer-Policy": "no-referrer"
|
|
14
|
+
};
|
|
15
|
+
const response = (value, status = 200) => Response.json(value, {
|
|
16
|
+
status,
|
|
17
|
+
headers
|
|
18
|
+
});
|
|
19
|
+
/** Mount /begin (POST), /callback (GET), /result (GET) beneath one application route.
|
|
20
|
+
* Promise conversion belongs to the hosting framework; all work here stays Effectful.
|
|
21
|
+
*/
|
|
22
|
+
function makeConnectServer(options) {
|
|
23
|
+
return Effect.fn("Connect.http")(function* (request) {
|
|
24
|
+
return yield* Effect.gen(function* () {
|
|
25
|
+
const url = new URL(request.url);
|
|
26
|
+
const principal = yield* options.authenticate(request);
|
|
27
|
+
if (request.method === "POST" && url.pathname.endsWith("/begin")) {
|
|
28
|
+
if (request.headers.get("origin") !== new URL(options.appOrigin).origin) return yield* connectError("Forbidden", "Authorization must start from the application origin.");
|
|
29
|
+
const body = yield* Effect.tryPromise({
|
|
30
|
+
try: () => request.json(),
|
|
31
|
+
catch: () => connectError("Configuration", "Invalid authorization request.")
|
|
32
|
+
});
|
|
33
|
+
const input = yield* Schema.decodeUnknownEffect(Start)(body).pipe(Effect.mapError(() => connectError("Configuration", "Invalid authorization request.")));
|
|
34
|
+
const returnUrl = yield* Effect.try({
|
|
35
|
+
try: () => new URL(input.returnUrl, options.appOrigin),
|
|
36
|
+
catch: () => connectError("Configuration", "Invalid return URL.")
|
|
37
|
+
});
|
|
38
|
+
if (returnUrl.origin !== new URL(options.appOrigin).origin || returnUrl.username || returnUrl.password) return yield* connectError("Forbidden", "Return URL must belong to the application.");
|
|
39
|
+
const properties = yield* options.authorize({
|
|
40
|
+
operation: "begin",
|
|
41
|
+
principal,
|
|
42
|
+
applicationId: input.applicationId,
|
|
43
|
+
connectionId: input.connectionId,
|
|
44
|
+
context: input.context
|
|
45
|
+
});
|
|
46
|
+
const selected = input.connectionId ?? (yield* options.connect.connectionForApplication(input.applicationId))?.id;
|
|
47
|
+
const started = yield* options.connect.begin({
|
|
48
|
+
applicationId: input.applicationId,
|
|
49
|
+
connectionId: selected,
|
|
50
|
+
principalId: principalKey(principal),
|
|
51
|
+
redirectUrl: options.callbackUrl,
|
|
52
|
+
returnUrl: returnUrl.href,
|
|
53
|
+
properties: properties ?? void 0
|
|
54
|
+
});
|
|
55
|
+
return response(started);
|
|
56
|
+
}
|
|
57
|
+
if (request.method === "GET" && url.pathname.endsWith("/status")) {
|
|
58
|
+
const applicationId = url.searchParams.get("applicationId");
|
|
59
|
+
if (!applicationId) return yield* connectError("Configuration", "Connector ID is required.");
|
|
60
|
+
yield* options.authorize({
|
|
61
|
+
operation: "inspect",
|
|
62
|
+
principal,
|
|
63
|
+
applicationId
|
|
64
|
+
});
|
|
65
|
+
const connection = yield* options.connect.connectionForApplication(applicationId);
|
|
66
|
+
return response({
|
|
67
|
+
applicationId,
|
|
68
|
+
connectionId: connection?.id,
|
|
69
|
+
status: connection?.status ?? "unconnected"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (request.method !== "GET" || !(url.pathname.endsWith("/callback") || url.pathname.endsWith("/result"))) return response({ error: "NotFound" }, 404);
|
|
73
|
+
const state = url.searchParams.get("state");
|
|
74
|
+
const attempt = state ? yield* options.store.get("OAuthAuthorizationAttempt", state) : void 0;
|
|
75
|
+
if (!attempt || attempt.principalId !== principalKey(principal) || attempt.expiresAt.epochMilliseconds <= (yield* Clock.currentTimeMillis)) return yield* connectError("InvalidAttempt", "Authorization attempt is unavailable.");
|
|
76
|
+
yield* options.authorize({
|
|
77
|
+
operation: "complete",
|
|
78
|
+
principal,
|
|
79
|
+
applicationId: attempt.application,
|
|
80
|
+
connectionId: attempt.connectionId,
|
|
81
|
+
attempt
|
|
82
|
+
});
|
|
83
|
+
if (url.pathname.endsWith("/result")) {
|
|
84
|
+
if (attempt.status !== "completed") return response({ status: attempt.status });
|
|
85
|
+
if (!attempt.connectionId) return yield* connectError("InvalidAttempt", "Completed authorization has no connection.");
|
|
86
|
+
const connection = yield* options.store.get("OAuthConnection", attempt.connectionId);
|
|
87
|
+
return response({
|
|
88
|
+
status: "completed",
|
|
89
|
+
connectionId: connection?.id
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const completed = yield* options.connect.complete({
|
|
93
|
+
callbackUrl: url.href,
|
|
94
|
+
principalId: principalKey(principal)
|
|
95
|
+
});
|
|
96
|
+
if (!attempt.returnUrl) return response({
|
|
97
|
+
status: "completed",
|
|
98
|
+
connectionId: completed.id
|
|
99
|
+
});
|
|
100
|
+
const target = new URL(attempt.returnUrl);
|
|
101
|
+
target.searchParams.set("connectAttempt", attempt.id);
|
|
102
|
+
target.searchParams.set("state", attempt.id);
|
|
103
|
+
return new Response(null, {
|
|
104
|
+
status: 303,
|
|
105
|
+
headers: {
|
|
106
|
+
...headers,
|
|
107
|
+
Location: target.href
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}).pipe(Effect.catch((error) => Effect.succeed(response({
|
|
111
|
+
error: error.kind,
|
|
112
|
+
message: error.message
|
|
113
|
+
}, error.kind === "Forbidden" ? 403 : error.kind === "NotFound" ? 404 : error.kind === "Busy" ? 409 : error.kind === "Provider" || error.kind === "Storage" ? 503 : 400))));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { makeConnectServer };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=index.js.map
|