domainkit 0.2.1 → 0.3.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 +31 -26
- package/dist/index.d.mts +639 -187
- package/dist/index.mjs +301 -300
- package/dist/index.mjs.map +1 -1
- package/dist/promise.d.mts +464 -0
- package/dist/promise.mjs +636 -0
- package/dist/promise.mjs.map +1 -0
- package/dist/{resolver-CxE-VDw4.mjs → resolver-CvK7JoJM.mjs} +401 -54
- package/dist/resolver-CvK7JoJM.mjs.map +1 -0
- package/dist/{resolver-BbVzTbCX.d.mts → resolver-uqe1h5Vz.d.mts} +1513 -25
- package/dist/testing.d.mts +4 -5
- package/dist/testing.mjs +17 -3
- package/dist/testing.mjs.map +1 -1
- package/dist/verify-B00c81-n.mjs +2420 -0
- package/dist/verify-B00c81-n.mjs.map +1 -0
- package/dist/{verify-7_EbKbFM.d.mts → verify-CkgVrwyl.d.mts} +318 -21
- package/package.json +6 -30
- package/dist/auth-6-KRy1gN.mjs +0 -671
- package/dist/auth-6-KRy1gN.mjs.map +0 -1
- package/dist/auth-B4jq3yk3.mjs +0 -738
- package/dist/auth-B4jq3yk3.mjs.map +0 -1
- package/dist/authorization-CQSKKMrW.mjs +0 -255
- package/dist/authorization-CQSKKMrW.mjs.map +0 -1
- package/dist/canonical-json-CpvqGMcr.mjs +0 -57
- package/dist/canonical-json-CpvqGMcr.mjs.map +0 -1
- package/dist/cloudflare-Bg_p-M2c.mjs +0 -69
- package/dist/cloudflare-Bg_p-M2c.mjs.map +0 -1
- package/dist/cloudflare-FDl5q7Dm.d.mts +0 -32
- package/dist/cloudflare.d.mts +0 -3
- package/dist/cloudflare.mjs +0 -2
- package/dist/connection-BXoSrhZs.mjs +0 -58
- package/dist/connection-BXoSrhZs.mjs.map +0 -1
- package/dist/connection-CEqadXSm.d.mts +0 -182
- package/dist/connection-X3rZhrBZ.mjs +0 -186
- package/dist/connection-X3rZhrBZ.mjs.map +0 -1
- package/dist/connection-api-DftK7eHo.d.mts +0 -7
- package/dist/dns-record-BLeqo56C.mjs +0 -289
- package/dist/dns-record-BLeqo56C.mjs.map +0 -1
- package/dist/effect-cloudflare.d.mts +0 -2
- package/dist/effect-cloudflare.mjs +0 -2
- package/dist/effect-vercel.d.mts +0 -2
- package/dist/effect-vercel.mjs +0 -2
- package/dist/effect.d.mts +0 -36
- package/dist/effect.mjs +0 -50
- package/dist/effect.mjs.map +0 -1
- package/dist/index-B1opsgls.d.mts +0 -159
- package/dist/index-Ewc__bQu.d.mts +0 -145
- package/dist/resolver-CxE-VDw4.mjs.map +0 -1
- package/dist/vercel-BIFpZRPu.mjs +0 -60
- package/dist/vercel-BIFpZRPu.mjs.map +0 -1
- package/dist/vercel-DgJaUX9D.d.mts +0 -31
- package/dist/vercel.d.mts +0 -3
- package/dist/vercel.mjs +0 -2
- package/dist/verify-Q5RYpnuw.mjs +0 -642
- package/dist/verify-Q5RYpnuw.mjs.map +0 -1
- package/dist/zone-discovery-BA5I24vu.d.mts +0 -1390
- package/dist/zones-DKHTpX9C.mjs +0 -19
- package/dist/zones-DKHTpX9C.mjs.map +0 -1
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { X as AsyncOAuthSubjectResolver, ct as AsyncInterface, it as TokenValidation, ot as Value } from "./zone-discovery-BA5I24vu.mjs";
|
|
2
|
-
import { _ as Zone, a as SubjectResolverOptions, d as tokenMethod$1, f as Account, g as Options, h as ListZonesInput, i as OAuthMethodOptions, l as manifest$1, n as CredentialTarget, o as TokenConnectionOptions, p as Fetch, r as OAuthFlowOptions, s as TokenValidatorOptions, u as oauthMethod$1 } from "./index-B1opsgls.mjs";
|
|
3
|
-
import { a as Source, n as Method, t as InteractiveFlow } from "./connection-CEqadXSm.mjs";
|
|
4
|
-
declare namespace cloudflare_auth_d_exports {
|
|
5
|
-
export { CredentialTarget, OAuthFlowOptions, OAuthMethodOptions, SubjectResolverOptions, TokenValidatorOptions, manifest, oauthFlow, oauthMethod, subjectResolver, tokenConnectionMethod, tokenMethod, tokenValidator };
|
|
6
|
-
}
|
|
7
|
-
declare const manifest: typeof manifest$1;
|
|
8
|
-
declare const oauthMethod: typeof oauthMethod$1;
|
|
9
|
-
declare const tokenMethod: typeof tokenMethod$1;
|
|
10
|
-
declare function subjectResolver(options: SubjectResolverOptions): AsyncOAuthSubjectResolver;
|
|
11
|
-
/** Creates Cloudflare's OAuth implementation for the Promise connection facade. */
|
|
12
|
-
declare function oauthFlow(options: OAuthFlowOptions): InteractiveFlow;
|
|
13
|
-
/** Creates a Cloudflare token method for the Promise connection facade. */
|
|
14
|
-
declare function tokenConnectionMethod(options: TokenConnectionOptions): Extract<Method, {
|
|
15
|
-
readonly _tag: "Token";
|
|
16
|
-
}>;
|
|
17
|
-
declare function tokenValidator(options: TokenValidatorOptions): (token: Value) => Promise<TokenValidation>;
|
|
18
|
-
declare namespace cloudflare_d_exports {
|
|
19
|
-
export { Account, cloudflare_auth_d_exports as Auth, Fetch, Interface, ListZonesInput, Options, Zone, discovery, make };
|
|
20
|
-
}
|
|
21
|
-
interface Interface extends AsyncInterface {
|
|
22
|
-
readonly listAccounts: () => Promise<ReadonlyArray<Account>>;
|
|
23
|
-
readonly listZones: (input?: ListZonesInput) => Promise<ReadonlyArray<Zone>>;
|
|
24
|
-
readonly validateToken: () => Promise<TokenValidation>;
|
|
25
|
-
}
|
|
26
|
-
/** Creates a Promise-compatible facade over the Effect-native Cloudflare client. */
|
|
27
|
-
declare function make(options: Options): Interface;
|
|
28
|
-
/** Creates the optional Cloudflare discovery source for Promise consumers. */
|
|
29
|
-
declare function discovery(options: Options): Source;
|
|
30
|
-
//#endregion
|
|
31
|
-
export { cloudflare_auth_d_exports as a, make as i, cloudflare_d_exports as n, discovery as r, Interface as t };
|
|
32
|
-
//# sourceMappingURL=cloudflare-FDl5q7Dm.d.mts.map
|
package/dist/cloudflare.d.mts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { _ as Zone, f as Account, g as Options, h as ListZonesInput, p as Fetch } from "./index-B1opsgls.mjs";
|
|
2
|
-
import { a as cloudflare_auth_d_exports, i as make, r as discovery, t as Interface } from "./cloudflare-FDl5q7Dm.mjs";
|
|
3
|
-
export { type Account, cloudflare_auth_d_exports as Auth, type Fetch, Interface, type ListZonesInput, type Options, type Zone, discovery, make };
|
package/dist/cloudflare.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { O as parse, T as Schema$2, k as Error$1 } from "./dns-record-BLeqo56C.mjs";
|
|
2
|
-
import { l as evidenceFor } from "./authorization-CQSKKMrW.mjs";
|
|
3
|
-
import { Effect, Schema } from "effect";
|
|
4
|
-
//#region src/auth/connection.ts
|
|
5
|
-
const Grant = Schema.TaggedUnion({
|
|
6
|
-
account: {},
|
|
7
|
-
domains: { domains: Schema.Array(Schema$2) }
|
|
8
|
-
});
|
|
9
|
-
/** An owner-scoped grant bound to one provider authorization. */
|
|
10
|
-
const Schema$1 = Schema.Struct({
|
|
11
|
-
authorizationId: Schema.String,
|
|
12
|
-
createdAt: Schema.DateFromString,
|
|
13
|
-
grant: Grant,
|
|
14
|
-
id: Schema.String,
|
|
15
|
-
ownerId: Schema.String
|
|
16
|
-
});
|
|
17
|
-
const decode = Effect.fn("Connection.decode")((input) => Schema.decodeUnknownEffect(Schema$1)(input).pipe(Effect.mapError((cause) => new Error$1({ message: cause.message }))));
|
|
18
|
-
const validate = Effect.fn("Connection.validate")((input) => Schema.decodeUnknownEffect(Schema.toType(Schema$1))(input).pipe(Effect.mapError((cause) => new Error$1({ message: cause.message }))));
|
|
19
|
-
const encode = Schema.encodeSync(Schema$1);
|
|
20
|
-
var AuthorizationError = class extends Schema.TaggedError()("AuthorizationError", {
|
|
21
|
-
category: Schema.Literal("authorization"),
|
|
22
|
-
message: Schema.String,
|
|
23
|
-
operation: Schema.String,
|
|
24
|
-
retry: Schema.Literals([
|
|
25
|
-
"never",
|
|
26
|
-
"after-user-action",
|
|
27
|
-
"safe",
|
|
28
|
-
"unknown"
|
|
29
|
-
])
|
|
30
|
-
}) {};
|
|
31
|
-
const authorizationError = (message, operation) => new AuthorizationError({
|
|
32
|
-
category: "authorization",
|
|
33
|
-
message,
|
|
34
|
-
operation,
|
|
35
|
-
retry: "after-user-action"
|
|
36
|
-
});
|
|
37
|
-
function assertGrant(connection, authorization, request) {
|
|
38
|
-
if (connection.authorizationId !== authorization.id || authorization.providerId !== request.providerId || authorization.revocation._tag !== "Active") throw authorizationError("Connection does not grant this provider account", "Connection.assertGrant");
|
|
39
|
-
if (authorization.expiresAt !== null) {
|
|
40
|
-
if (Number.isNaN(authorization.expiresAt.getTime())) throw authorizationError("Connection expiration is invalid", "Connection.assertGrant");
|
|
41
|
-
if (authorization.expiresAt <= (request.now ?? /* @__PURE__ */ new Date())) throw authorizationError("Connection has expired", "Connection.assertGrant");
|
|
42
|
-
}
|
|
43
|
-
if (!authorization.requiredCapabilities.includes(request.capability)) throw authorizationError(`Connection lacks the ${request.capability} capability`, "Connection.assertGrant");
|
|
44
|
-
if (evidenceFor(authorization, request.capability) === void 0) throw authorizationError(`Connection has no evidence for the ${request.capability} capability`, "Connection.assertGrant");
|
|
45
|
-
let domain;
|
|
46
|
-
try {
|
|
47
|
-
domain = parse(request.domain);
|
|
48
|
-
} catch (cause) {
|
|
49
|
-
if (cause instanceof Error$1) throw cause;
|
|
50
|
-
throw new Error$1({ message: cause instanceof Error ? cause.message : String(cause) });
|
|
51
|
-
}
|
|
52
|
-
if (connection.grant._tag === "domains" && !connection.grant.domains.includes(domain)) throw authorizationError("Connection does not grant this domain", "Connection.assertGrant");
|
|
53
|
-
return domain;
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
export { authorizationError as a, validate as c, assertGrant as i, Grant as n, decode as o, Schema$1 as r, encode as s, AuthorizationError as t };
|
|
57
|
-
|
|
58
|
-
//# sourceMappingURL=connection-BXoSrhZs.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-BXoSrhZs.mjs","names":["S","DomainName.Schema","Schema","InvalidInputError","ProviderAuthorization.evidenceFor","DomainName.parse"],"sources":["../src/auth/connection.ts"],"sourcesContent":["import { Effect, Schema as S } from \"effect\";\n\nimport * as DomainName from \"../domain/domain-name.ts\";\nimport { Error as InvalidInputError } from \"../invalid-input.ts\";\nimport type { Value as Secret } from \"./secret.ts\";\nimport type { OAuthMethod } from \"./manifest.ts\";\nimport * as ProviderAuthorization from \"./authorization.ts\";\n\nexport const Grant = S.TaggedUnion({\n account: {},\n domains: { domains: S.Array(DomainName.Schema) },\n});\nexport type Grant = typeof Grant.Type;\n\n/** An owner-scoped grant bound to one provider authorization. */\nexport const Schema = S.Struct({\n authorizationId: S.String,\n createdAt: S.DateFromString,\n grant: Grant,\n id: S.String,\n ownerId: S.String,\n});\nexport interface Connection extends S.Schema.Type<typeof Schema> {}\n\nexport const decode = Effect.fn(\"Connection.decode\")((input: unknown) =>\n S.decodeUnknownEffect(Schema)(input).pipe(\n Effect.mapError((cause) => new InvalidInputError({ message: cause.message })),\n ),\n);\n\nexport const validate = Effect.fn(\"Connection.validate\")((input: unknown) =>\n S.decodeUnknownEffect(S.toType(Schema))(input).pipe(\n Effect.mapError((cause) => new InvalidInputError({ message: cause.message })),\n ),\n);\n\nexport const encode = S.encodeSync(Schema);\n\nexport interface OAuthContinuation {\n readonly clientId: string;\n readonly codeVerifier: Secret;\n readonly expiresAt: Date;\n readonly grant: Grant;\n readonly method: OAuthMethod;\n readonly ownerId: string;\n readonly redirectUri: string;\n readonly stateHash: string;\n readonly authorizedById: string;\n}\n\nexport interface StoredCredential {\n readonly accessToken: Secret;\n readonly refreshToken: Secret | null;\n readonly tokenType: string;\n}\n\nexport class AuthorizationError extends S.TaggedError<AuthorizationError>()(\"AuthorizationError\", {\n category: S.Literal(\"authorization\"),\n message: S.String,\n operation: S.String,\n retry: S.Literals([\"never\", \"after-user-action\", \"safe\", \"unknown\"]),\n}) {}\n\nexport const authorizationError = (message: string, operation: string): AuthorizationError =>\n new AuthorizationError({\n category: \"authorization\",\n message,\n operation,\n retry: \"after-user-action\",\n });\n\nexport function assertGrant(\n connection: Connection,\n authorization: ProviderAuthorization.ProviderAuthorization,\n request: {\n readonly capability: ProviderAuthorization.Capability;\n readonly domain: string;\n readonly now?: Date;\n readonly providerId: string;\n },\n): DomainName.DomainName {\n if (\n connection.authorizationId !== authorization.id ||\n authorization.providerId !== request.providerId ||\n authorization.revocation._tag !== \"Active\"\n ) {\n throw authorizationError(\n \"Connection does not grant this provider account\",\n \"Connection.assertGrant\",\n );\n }\n if (authorization.expiresAt !== null) {\n if (Number.isNaN(authorization.expiresAt.getTime())) {\n throw authorizationError(\"Connection expiration is invalid\", \"Connection.assertGrant\");\n }\n if (authorization.expiresAt <= (request.now ?? new Date())) {\n throw authorizationError(\"Connection has expired\", \"Connection.assertGrant\");\n }\n }\n if (!authorization.requiredCapabilities.includes(request.capability)) {\n throw authorizationError(\n `Connection lacks the ${request.capability} capability`,\n \"Connection.assertGrant\",\n );\n }\n if (ProviderAuthorization.evidenceFor(authorization, request.capability) === undefined) {\n throw authorizationError(\n `Connection has no evidence for the ${request.capability} capability`,\n \"Connection.assertGrant\",\n );\n }\n let domain: DomainName.DomainName;\n try {\n domain = DomainName.parse(request.domain);\n } catch (cause) {\n if (cause instanceof InvalidInputError) throw cause;\n throw new InvalidInputError({\n message: cause instanceof Error ? cause.message : String(cause),\n });\n }\n if (connection.grant._tag === \"domains\" && !connection.grant.domains.includes(domain)) {\n throw authorizationError(\"Connection does not grant this domain\", \"Connection.assertGrant\");\n }\n return domain;\n}\n"],"mappings":";;;;AAQA,MAAa,QAAQA,OAAE,YAAY;CACjC,SAAS,CAAC;CACV,SAAS,EAAE,SAASA,OAAE,MAAMC,QAAiB,EAAE;AACjD,CAAC;;AAID,MAAaC,WAASF,OAAE,OAAO;CAC7B,iBAAiBA,OAAE;CACnB,WAAWA,OAAE;CACb,OAAO;CACP,IAAIA,OAAE;CACN,SAASA,OAA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AW,cAC3C,wBACF;CAEF,IAAII,YAAkC,eAAe,QAAQ,UAAU,MAAM,KAAA,GAC3E,MAAM,mBACJ,sCAAsC,QAAQ,WAAW,cACzD,wBACF;CAEF,IAAI;CACJ,IAAI;EACF,SAASC,MAAiB,QAAQ,MAAM;CAC1C,SAAS,OAAO;EACd,IAAI,iBAAiBF,SAAmB,MAAM;EAC9C,MAAM,IAAIA,QAAkB,EAC1B,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAChE,CAAC;CACH;CACA,IAAI,WAAW,MAAM,SAAS,aAAa,CAAC,WAAW,MAAM,QAAQ,SAAS,MAAM,GAClF,MAAM,mBAAmB,yCAAyC,wBAAwB;CAE5F,OAAO;AACT"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { A as Connection, B as Capability, C as Aggregate, D as Service, E as Interface, F as assertGrant, M as OAuthContinuation, N as Schema$1, Nt as DomainName, P as StoredCredential, R as encode, T as Error, V as CapabilityEvidence, _ as StartResult, a as Authentication, ct as AsyncInterface, d as Error$1, h as Method$1, j as Grant, k as AuthorizationError, l as Continuation, m as InteractiveStart, ot as Value, p as InteractiveFlow$1, r as Source$1, s as BaseInput, t as Candidate, u as ContinuationStore$1, w as DetachResult } from "./zone-discovery-BA5I24vu.mjs";
|
|
2
|
-
import "./connection-api-DftK7eHo.mjs";
|
|
3
|
-
import { Data, Layer } from "effect";
|
|
4
|
-
declare namespace zone_discovery_d_exports {
|
|
5
|
-
export { Candidate, Outcome, Source, discover, toEffectSource };
|
|
6
|
-
}
|
|
7
|
-
interface Source {
|
|
8
|
-
readonly listZones: (name: DomainName) => Promise<ReadonlyArray<Omit<Candidate, "providerId">>>;
|
|
9
|
-
readonly provider: AsyncInterface;
|
|
10
|
-
}
|
|
11
|
-
type Outcome = {
|
|
12
|
-
readonly _tag: "NotFound";
|
|
13
|
-
readonly domain: DomainName;
|
|
14
|
-
} | {
|
|
15
|
-
readonly _tag: "Resolved";
|
|
16
|
-
readonly candidate: Candidate;
|
|
17
|
-
} | {
|
|
18
|
-
readonly _tag: "SelectionRequired";
|
|
19
|
-
readonly candidates: ReadonlyArray<Candidate>;
|
|
20
|
-
};
|
|
21
|
-
declare function discover(input: {
|
|
22
|
-
readonly domain: DomainName;
|
|
23
|
-
readonly sources: ReadonlyArray<Source>;
|
|
24
|
-
}): Promise<Outcome>;
|
|
25
|
-
declare function toEffectSource(source: Source): Source$1;
|
|
26
|
-
declare namespace authorization_lifecycle_d_exports {
|
|
27
|
-
export { Aggregate, DetachResult, Error, Repository, from, layerFrom, toAsync };
|
|
28
|
-
}
|
|
29
|
-
interface Repository {
|
|
30
|
-
readonly bind: (authorizationId: string, binding: Connection) => Promise<Aggregate>;
|
|
31
|
-
readonly connect: (aggregate: Aggregate) => Promise<Aggregate>;
|
|
32
|
-
readonly detach: (input: {
|
|
33
|
-
readonly connectionId: string;
|
|
34
|
-
readonly revoke: (aggregate: Aggregate) => Promise<void>;
|
|
35
|
-
}) => Promise<DetachResult>;
|
|
36
|
-
readonly findByProviderAccount: (providerId: string, providerAccountId: string) => Promise<Aggregate | null>;
|
|
37
|
-
readonly get: (authorizationId: string) => Promise<Aggregate | null>;
|
|
38
|
-
readonly getByConnectionId: (connectionId: string) => Promise<Aggregate | null>;
|
|
39
|
-
readonly promoteEvidence: (authorizationId: string, evidence: ReadonlyArray<CapabilityEvidence>) => Promise<Aggregate>;
|
|
40
|
-
readonly recover: (input: {
|
|
41
|
-
readonly authorizationId: string;
|
|
42
|
-
readonly revoke: (aggregate: Aggregate) => Promise<void>;
|
|
43
|
-
}) => Promise<DetachResult>;
|
|
44
|
-
readonly rotate: (authorizationId: string, credential: StoredCredential, expiresAt: Date | null) => Promise<Aggregate>;
|
|
45
|
-
}
|
|
46
|
-
declare const layerFrom: (repository: Repository) => Layer.Layer<Service>;
|
|
47
|
-
declare const toAsync: (repository: Interface) => Repository;
|
|
48
|
-
declare const from: (repository: Repository) => Repository;
|
|
49
|
-
declare namespace connection_d_exports {
|
|
50
|
-
export { Authentication, AuthorizationError, Connection, StartResult as ConnectionStartResult, ContinuationStore, Error$1 as Error, Grant, InteractiveFlow, Method, OAuthContinuation, Schema$1 as Schema, StartResult, StoredCredential, assertGrant, complete, decode, encode, fromEffectFlow, fromEffectTokenMethod, start, toAsyncContinuations };
|
|
51
|
-
}
|
|
52
|
-
declare function decode(input: unknown): Promise<Connection>;
|
|
53
|
-
type Method = Data.TaggedEnum<{
|
|
54
|
-
Interactive: {
|
|
55
|
-
readonly continuations: ContinuationStore;
|
|
56
|
-
readonly flow: InteractiveFlow;
|
|
57
|
-
readonly ttlMs?: number;
|
|
58
|
-
};
|
|
59
|
-
Token: {
|
|
60
|
-
readonly authenticate: (token: Value) => Promise<Authentication>;
|
|
61
|
-
readonly providerId: string;
|
|
62
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
63
|
-
readonly token: Value;
|
|
64
|
-
};
|
|
65
|
-
}>;
|
|
66
|
-
declare const Method: {
|
|
67
|
-
readonly $is: <Tag extends "Interactive" | "Token">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
68
|
-
readonly _tag: "Interactive";
|
|
69
|
-
readonly continuations: ContinuationStore;
|
|
70
|
-
readonly flow: InteractiveFlow;
|
|
71
|
-
readonly ttlMs?: number;
|
|
72
|
-
}, {
|
|
73
|
-
readonly _tag: Tag;
|
|
74
|
-
}> | Extract<{
|
|
75
|
-
readonly _tag: "Token";
|
|
76
|
-
readonly authenticate: (token: Value) => Promise<Authentication>;
|
|
77
|
-
readonly providerId: string;
|
|
78
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
79
|
-
readonly token: Value;
|
|
80
|
-
}, {
|
|
81
|
-
readonly _tag: Tag;
|
|
82
|
-
}>;
|
|
83
|
-
readonly $match: {
|
|
84
|
-
<Cases extends { readonly [Tag in "Interactive" | "Token"]: (args: Extract<{
|
|
85
|
-
readonly _tag: "Interactive";
|
|
86
|
-
readonly continuations: ContinuationStore;
|
|
87
|
-
readonly flow: InteractiveFlow;
|
|
88
|
-
readonly ttlMs?: number;
|
|
89
|
-
} | {
|
|
90
|
-
readonly _tag: "Token";
|
|
91
|
-
readonly authenticate: (token: Value) => Promise<Authentication>;
|
|
92
|
-
readonly providerId: string;
|
|
93
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
94
|
-
readonly token: Value;
|
|
95
|
-
}, {
|
|
96
|
-
readonly _tag: Tag;
|
|
97
|
-
}>) => any; }>(cases: Cases): (value: {
|
|
98
|
-
readonly _tag: "Interactive";
|
|
99
|
-
readonly continuations: ContinuationStore;
|
|
100
|
-
readonly flow: InteractiveFlow;
|
|
101
|
-
readonly ttlMs?: number;
|
|
102
|
-
} | {
|
|
103
|
-
readonly _tag: "Token";
|
|
104
|
-
readonly authenticate: (token: Value) => Promise<Authentication>;
|
|
105
|
-
readonly providerId: string;
|
|
106
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
107
|
-
readonly token: Value;
|
|
108
|
-
}) => import("effect/Unify").Unify<ReturnType<Cases["Interactive" | "Token"]>>;
|
|
109
|
-
<Cases extends { readonly [Tag in "Interactive" | "Token"]: (args: Extract<{
|
|
110
|
-
readonly _tag: "Interactive";
|
|
111
|
-
readonly continuations: ContinuationStore;
|
|
112
|
-
readonly flow: InteractiveFlow;
|
|
113
|
-
readonly ttlMs?: number;
|
|
114
|
-
} | {
|
|
115
|
-
readonly _tag: "Token";
|
|
116
|
-
readonly authenticate: (token: Value) => Promise<Authentication>;
|
|
117
|
-
readonly providerId: string;
|
|
118
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
119
|
-
readonly token: Value;
|
|
120
|
-
}, {
|
|
121
|
-
readonly _tag: Tag;
|
|
122
|
-
}>) => any; }>(value: {
|
|
123
|
-
readonly _tag: "Interactive";
|
|
124
|
-
readonly continuations: ContinuationStore;
|
|
125
|
-
readonly flow: InteractiveFlow;
|
|
126
|
-
readonly ttlMs?: number;
|
|
127
|
-
} | {
|
|
128
|
-
readonly _tag: "Token";
|
|
129
|
-
readonly authenticate: (token: Value) => Promise<Authentication>;
|
|
130
|
-
readonly providerId: string;
|
|
131
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
132
|
-
readonly token: Value;
|
|
133
|
-
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Interactive" | "Token"]>>;
|
|
134
|
-
};
|
|
135
|
-
readonly Interactive: Data.TaggedEnum.ConstructorFrom<{
|
|
136
|
-
readonly _tag: "Interactive";
|
|
137
|
-
readonly continuations: ContinuationStore;
|
|
138
|
-
readonly flow: InteractiveFlow;
|
|
139
|
-
readonly ttlMs?: number;
|
|
140
|
-
}, "_tag">;
|
|
141
|
-
readonly Token: Data.TaggedEnum.ConstructorFrom<{
|
|
142
|
-
readonly _tag: "Token";
|
|
143
|
-
readonly authenticate: (token: Value) => Promise<Authentication>;
|
|
144
|
-
readonly providerId: string;
|
|
145
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
146
|
-
readonly token: Value;
|
|
147
|
-
}, "_tag">;
|
|
148
|
-
};
|
|
149
|
-
interface ContinuationStore {
|
|
150
|
-
readonly consume: (id: string, now: Date) => Promise<Continuation | null>;
|
|
151
|
-
readonly put: (continuation: Continuation) => Promise<void>;
|
|
152
|
-
}
|
|
153
|
-
interface InteractiveFlow {
|
|
154
|
-
readonly complete: (payload: Value, callbackUrl: URL) => Promise<Authentication>;
|
|
155
|
-
readonly method: "integration" | "oauth2";
|
|
156
|
-
readonly providerId: string;
|
|
157
|
-
readonly requiredCapabilities: ReadonlyArray<Capability>;
|
|
158
|
-
readonly start: (continuationId: string) => Promise<InteractiveStart>;
|
|
159
|
-
}
|
|
160
|
-
declare const toAsyncContinuations: (store: ContinuationStore$1) => ContinuationStore;
|
|
161
|
-
/** Adapts an Effect-native provider flow to the Promise facade. */
|
|
162
|
-
declare const fromEffectFlow: (flow: InteractiveFlow$1) => InteractiveFlow;
|
|
163
|
-
/** Adapts an Effect-native token method to the Promise facade. */
|
|
164
|
-
declare function fromEffectTokenMethod(method: Extract<Method$1, {
|
|
165
|
-
readonly _tag: "Token";
|
|
166
|
-
}>): Extract<Method, {
|
|
167
|
-
readonly _tag: "Token";
|
|
168
|
-
}>;
|
|
169
|
-
declare function start(input: BaseInput & {
|
|
170
|
-
readonly method: Method;
|
|
171
|
-
readonly repository: Repository;
|
|
172
|
-
}): Promise<StartResult>;
|
|
173
|
-
declare function complete(input: {
|
|
174
|
-
readonly callbackUrl: URL;
|
|
175
|
-
readonly continuationId: string;
|
|
176
|
-
readonly continuations: ContinuationStore;
|
|
177
|
-
readonly flow: InteractiveFlow;
|
|
178
|
-
readonly repository: Repository;
|
|
179
|
-
}): Promise<Aggregate>;
|
|
180
|
-
//#endregion
|
|
181
|
-
export { Source as a, authorization_lifecycle_d_exports as i, Method as n, zone_discovery_d_exports as o, connection_d_exports as r, InteractiveFlow as t };
|
|
182
|
-
//# sourceMappingURL=connection-CEqadXSm.d.mts.map
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { M as Service, j as Error } from "./dns-record-BLeqo56C.mjs";
|
|
3
|
-
import { _ as StartResult, g as Method$1, h as Error$1, v as complete$1, y as start$1 } from "./authorization-CQSKKMrW.mjs";
|
|
4
|
-
import { i as assertGrant, n as Grant, o as decode$1, r as Schema$1, s as encode, t as AuthorizationError } from "./connection-BXoSrhZs.mjs";
|
|
5
|
-
import { i as webCryptoLayer } from "./canonical-json-CpvqGMcr.mjs";
|
|
6
|
-
import { Data, Effect, Layer } from "effect";
|
|
7
|
-
//#region src/promise/authorization-lifecycle.ts
|
|
8
|
-
var authorization_lifecycle_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
-
Error: () => Error,
|
|
10
|
-
from: () => from,
|
|
11
|
-
layerFrom: () => layerFrom,
|
|
12
|
-
toAsync: () => toAsync
|
|
13
|
-
});
|
|
14
|
-
const failure = (operation, cause) => cause instanceof Error ? cause : new Error({
|
|
15
|
-
category: "storage",
|
|
16
|
-
message: cause instanceof globalThis.Error ? cause.message : String(cause),
|
|
17
|
-
operation,
|
|
18
|
-
retry: "safe"
|
|
19
|
-
});
|
|
20
|
-
const layerFrom = (repository) => Layer.succeed(Service, {
|
|
21
|
-
bind: Effect.fn("AuthorizationLifecycleRepository.bind")((authorizationId, binding) => Effect.tryPromise({
|
|
22
|
-
try: () => repository.bind(authorizationId, binding),
|
|
23
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.bind", cause)
|
|
24
|
-
})),
|
|
25
|
-
connect: Effect.fn("AuthorizationLifecycleRepository.connect")((aggregate) => Effect.tryPromise({
|
|
26
|
-
try: () => repository.connect(aggregate),
|
|
27
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.connect", cause)
|
|
28
|
-
})),
|
|
29
|
-
detach: ({ connectionId, revoke }) => Effect.tryPromise({
|
|
30
|
-
try: () => repository.detach({
|
|
31
|
-
connectionId,
|
|
32
|
-
revoke: (aggregate) => Effect.runPromise(revoke(aggregate))
|
|
33
|
-
}),
|
|
34
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.detach", cause)
|
|
35
|
-
}),
|
|
36
|
-
findByProviderAccount: Effect.fn("AuthorizationLifecycleRepository.findByProviderAccount")((providerId, providerAccountId) => Effect.tryPromise({
|
|
37
|
-
try: () => repository.findByProviderAccount(providerId, providerAccountId),
|
|
38
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.findByProviderAccount", cause)
|
|
39
|
-
})),
|
|
40
|
-
get: Effect.fn("AuthorizationLifecycleRepository.get")((authorizationId) => Effect.tryPromise({
|
|
41
|
-
try: () => repository.get(authorizationId),
|
|
42
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.get", cause)
|
|
43
|
-
})),
|
|
44
|
-
getByConnectionId: Effect.fn("AuthorizationLifecycleRepository.getByConnectionId")((connectionId) => Effect.tryPromise({
|
|
45
|
-
try: () => repository.getByConnectionId(connectionId),
|
|
46
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.getByConnectionId", cause)
|
|
47
|
-
})),
|
|
48
|
-
promoteEvidence: Effect.fn("AuthorizationLifecycleRepository.promoteEvidence")((authorizationId, evidence) => Effect.tryPromise({
|
|
49
|
-
try: () => repository.promoteEvidence(authorizationId, evidence),
|
|
50
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.promoteEvidence", cause)
|
|
51
|
-
})),
|
|
52
|
-
recover: ({ authorizationId, revoke }) => Effect.tryPromise({
|
|
53
|
-
try: () => repository.recover({
|
|
54
|
-
authorizationId,
|
|
55
|
-
revoke: (aggregate) => Effect.runPromise(revoke(aggregate))
|
|
56
|
-
}),
|
|
57
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.recover", cause)
|
|
58
|
-
}),
|
|
59
|
-
rotate: Effect.fn("AuthorizationLifecycleRepository.rotate")((authorizationId, credential, expiresAt) => Effect.tryPromise({
|
|
60
|
-
try: () => repository.rotate(authorizationId, credential, expiresAt),
|
|
61
|
-
catch: (cause) => failure("AuthorizationLifecycleRepository.rotate", cause)
|
|
62
|
-
}))
|
|
63
|
-
});
|
|
64
|
-
const toAsync = (repository) => ({
|
|
65
|
-
bind: (authorizationId, binding) => Effect.runPromise(repository.bind(authorizationId, binding)),
|
|
66
|
-
connect: (aggregate) => Effect.runPromise(repository.connect(aggregate)),
|
|
67
|
-
detach: ({ connectionId, revoke }) => Effect.runPromise(repository.detach({
|
|
68
|
-
connectionId,
|
|
69
|
-
revoke: (aggregate) => Effect.tryPromise(() => revoke(aggregate))
|
|
70
|
-
})),
|
|
71
|
-
findByProviderAccount: (providerId, providerAccountId) => Effect.runPromise(repository.findByProviderAccount(providerId, providerAccountId)),
|
|
72
|
-
get: (authorizationId) => Effect.runPromise(repository.get(authorizationId)),
|
|
73
|
-
getByConnectionId: (connectionId) => Effect.runPromise(repository.getByConnectionId(connectionId)),
|
|
74
|
-
promoteEvidence: (authorizationId, evidence) => Effect.runPromise(repository.promoteEvidence(authorizationId, evidence)),
|
|
75
|
-
recover: ({ authorizationId, revoke }) => Effect.runPromise(repository.recover({
|
|
76
|
-
authorizationId,
|
|
77
|
-
revoke: (aggregate) => Effect.tryPromise(() => revoke(aggregate))
|
|
78
|
-
})),
|
|
79
|
-
rotate: (authorizationId, credential, expiresAt) => Effect.runPromise(repository.rotate(authorizationId, credential, expiresAt))
|
|
80
|
-
});
|
|
81
|
-
const from = (repository) => repository;
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/promise/connection.ts
|
|
84
|
-
var connection_exports = /* @__PURE__ */ __exportAll({
|
|
85
|
-
AuthorizationError: () => AuthorizationError,
|
|
86
|
-
Error: () => Error$1,
|
|
87
|
-
Grant: () => Grant,
|
|
88
|
-
Method: () => Method,
|
|
89
|
-
Schema: () => Schema$1,
|
|
90
|
-
StartResult: () => StartResult,
|
|
91
|
-
assertGrant: () => assertGrant,
|
|
92
|
-
complete: () => complete,
|
|
93
|
-
decode: () => decode,
|
|
94
|
-
encode: () => encode,
|
|
95
|
-
fromEffectFlow: () => fromEffectFlow,
|
|
96
|
-
fromEffectTokenMethod: () => fromEffectTokenMethod,
|
|
97
|
-
start: () => start,
|
|
98
|
-
toAsyncContinuations: () => toAsyncContinuations
|
|
99
|
-
});
|
|
100
|
-
function decode(input) {
|
|
101
|
-
return Effect.runPromise(decode$1(input));
|
|
102
|
-
}
|
|
103
|
-
const Method = Data.taggedEnum();
|
|
104
|
-
const connectionFailure = (operation, cause) => cause instanceof Error$1 ? cause : new Error$1({
|
|
105
|
-
category: "provider",
|
|
106
|
-
message: cause instanceof globalThis.Error ? cause.message : String(cause),
|
|
107
|
-
operation,
|
|
108
|
-
retry: "unknown"
|
|
109
|
-
});
|
|
110
|
-
const effectMethod = (method) => method._tag === "Interactive" ? Method$1.Interactive({
|
|
111
|
-
continuations: effectContinuations(method.continuations),
|
|
112
|
-
flow: effectFlow(method.flow),
|
|
113
|
-
...method.ttlMs === void 0 ? {} : { ttlMs: method.ttlMs }
|
|
114
|
-
}) : Method$1.Token({
|
|
115
|
-
authenticate: (token) => Effect.tryPromise({
|
|
116
|
-
try: () => method.authenticate(token),
|
|
117
|
-
catch: (cause) => connectionFailure("Connection.start", cause)
|
|
118
|
-
}),
|
|
119
|
-
providerId: method.providerId,
|
|
120
|
-
requiredCapabilities: method.requiredCapabilities,
|
|
121
|
-
token: method.token
|
|
122
|
-
});
|
|
123
|
-
const effectContinuations = (store) => ({
|
|
124
|
-
consume: (id, now) => Effect.tryPromise({
|
|
125
|
-
try: () => store.consume(id, now),
|
|
126
|
-
catch: (cause) => connectionFailure("ConnectionContinuations.consume", cause)
|
|
127
|
-
}),
|
|
128
|
-
put: (continuation) => Effect.tryPromise({
|
|
129
|
-
try: () => store.put(continuation),
|
|
130
|
-
catch: (cause) => connectionFailure("ConnectionContinuations.put", cause)
|
|
131
|
-
})
|
|
132
|
-
});
|
|
133
|
-
const toAsyncContinuations = (store) => ({
|
|
134
|
-
consume: (id, now) => Effect.runPromise(store.consume(id, now)),
|
|
135
|
-
put: (continuation) => Effect.runPromise(store.put(continuation))
|
|
136
|
-
});
|
|
137
|
-
const effectFlow = (flow) => ({
|
|
138
|
-
complete: (payload, callbackUrl) => Effect.tryPromise({
|
|
139
|
-
try: () => flow.complete(payload, callbackUrl),
|
|
140
|
-
catch: (cause) => connectionFailure("Connection.complete", cause)
|
|
141
|
-
}),
|
|
142
|
-
method: flow.method,
|
|
143
|
-
providerId: flow.providerId,
|
|
144
|
-
requiredCapabilities: flow.requiredCapabilities,
|
|
145
|
-
start: (continuationId) => Effect.tryPromise({
|
|
146
|
-
try: () => flow.start(continuationId),
|
|
147
|
-
catch: (cause) => connectionFailure("Connection.start", cause)
|
|
148
|
-
})
|
|
149
|
-
});
|
|
150
|
-
/** Adapts an Effect-native provider flow to the Promise facade. */
|
|
151
|
-
const fromEffectFlow = (flow) => ({
|
|
152
|
-
complete: (payload, callbackUrl) => Effect.runPromise(flow.complete(payload, callbackUrl)),
|
|
153
|
-
method: flow.method,
|
|
154
|
-
providerId: flow.providerId,
|
|
155
|
-
requiredCapabilities: flow.requiredCapabilities,
|
|
156
|
-
start: (continuationId) => Effect.runPromise(flow.start(continuationId).pipe(Effect.provide(webCryptoLayer)))
|
|
157
|
-
});
|
|
158
|
-
/** Adapts an Effect-native token method to the Promise facade. */
|
|
159
|
-
function fromEffectTokenMethod(method) {
|
|
160
|
-
return Method.Token({
|
|
161
|
-
authenticate: (token) => Effect.runPromise(method.authenticate(token)),
|
|
162
|
-
providerId: method.providerId,
|
|
163
|
-
requiredCapabilities: method.requiredCapabilities,
|
|
164
|
-
token: method.token
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
async function start(input) {
|
|
168
|
-
return Effect.runPromise(start$1({
|
|
169
|
-
authorizedById: input.authorizedById,
|
|
170
|
-
grant: input.grant,
|
|
171
|
-
method: effectMethod(input.method),
|
|
172
|
-
ownerId: input.ownerId
|
|
173
|
-
}).pipe(Effect.provide(Layer.merge(layerFrom(input.repository), webCryptoLayer))));
|
|
174
|
-
}
|
|
175
|
-
async function complete(input) {
|
|
176
|
-
return Effect.runPromise(complete$1({
|
|
177
|
-
callbackUrl: input.callbackUrl,
|
|
178
|
-
continuationId: input.continuationId,
|
|
179
|
-
continuations: effectContinuations(input.continuations),
|
|
180
|
-
flow: effectFlow(input.flow)
|
|
181
|
-
}).pipe(Effect.provide(Layer.merge(layerFrom(input.repository), webCryptoLayer))));
|
|
182
|
-
}
|
|
183
|
-
//#endregion
|
|
184
|
-
export { authorization_lifecycle_exports as i, fromEffectFlow as n, fromEffectTokenMethod as r, connection_exports as t };
|
|
185
|
-
|
|
186
|
-
//# sourceMappingURL=connection-X3rZhrBZ.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-X3rZhrBZ.mjs","names":["Lifecycle.Error","Lifecycle.Service","Connection.decode","Connect.Error","Connect.start","LifecycleRepository.layerFrom","Connect.complete"],"sources":["../src/promise/authorization-lifecycle.ts","../src/promise/connection.ts"],"sourcesContent":["import { Effect, Layer } from \"effect\";\n\nimport type * as ProviderAuthorization from \"../auth/authorization.ts\";\nimport type * as Connection from \"../auth/connection.ts\";\nimport * as Lifecycle from \"../auth/lifecycle-repository.ts\";\n\nexport interface Repository {\n readonly bind: (\n authorizationId: string,\n binding: Connection.Connection,\n ) => Promise<Lifecycle.Aggregate>;\n readonly connect: (aggregate: Lifecycle.Aggregate) => Promise<Lifecycle.Aggregate>;\n readonly detach: (input: {\n readonly connectionId: string;\n readonly revoke: (aggregate: Lifecycle.Aggregate) => Promise<void>;\n }) => Promise<Lifecycle.DetachResult>;\n readonly findByProviderAccount: (\n providerId: string,\n providerAccountId: string,\n ) => Promise<Lifecycle.Aggregate | null>;\n readonly get: (authorizationId: string) => Promise<Lifecycle.Aggregate | null>;\n readonly getByConnectionId: (connectionId: string) => Promise<Lifecycle.Aggregate | null>;\n readonly promoteEvidence: (\n authorizationId: string,\n evidence: ReadonlyArray<ProviderAuthorization.CapabilityEvidence>,\n ) => Promise<Lifecycle.Aggregate>;\n readonly recover: (input: {\n readonly authorizationId: string;\n readonly revoke: (aggregate: Lifecycle.Aggregate) => Promise<void>;\n }) => Promise<Lifecycle.DetachResult>;\n readonly rotate: (\n authorizationId: string,\n credential: Connection.StoredCredential,\n expiresAt: Date | null,\n ) => Promise<Lifecycle.Aggregate>;\n}\n\nconst failure = (operation: string, cause: unknown): Lifecycle.Error =>\n cause instanceof Lifecycle.Error\n ? cause\n : new Lifecycle.Error({\n category: \"storage\",\n message: cause instanceof globalThis.Error ? cause.message : String(cause),\n operation,\n retry: \"safe\",\n });\n\nexport const layerFrom = (repository: Repository): Layer.Layer<Lifecycle.Service> =>\n Layer.succeed(Lifecycle.Service, {\n bind: Effect.fn(\"AuthorizationLifecycleRepository.bind\")((authorizationId, binding) =>\n Effect.tryPromise({\n try: () => repository.bind(authorizationId, binding),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.bind\", cause),\n }),\n ),\n connect: Effect.fn(\"AuthorizationLifecycleRepository.connect\")((aggregate) =>\n Effect.tryPromise({\n try: () => repository.connect(aggregate),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.connect\", cause),\n }),\n ),\n detach: ({ connectionId, revoke }) =>\n Effect.tryPromise({\n try: () =>\n repository.detach({\n connectionId,\n revoke: (aggregate) => Effect.runPromise(revoke(aggregate)),\n }),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.detach\", cause),\n }),\n findByProviderAccount: Effect.fn(\"AuthorizationLifecycleRepository.findByProviderAccount\")(\n (providerId, providerAccountId) =>\n Effect.tryPromise({\n try: () => repository.findByProviderAccount(providerId, providerAccountId),\n catch: (cause) =>\n failure(\"AuthorizationLifecycleRepository.findByProviderAccount\", cause),\n }),\n ),\n get: Effect.fn(\"AuthorizationLifecycleRepository.get\")((authorizationId) =>\n Effect.tryPromise({\n try: () => repository.get(authorizationId),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.get\", cause),\n }),\n ),\n getByConnectionId: Effect.fn(\"AuthorizationLifecycleRepository.getByConnectionId\")(\n (connectionId) =>\n Effect.tryPromise({\n try: () => repository.getByConnectionId(connectionId),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.getByConnectionId\", cause),\n }),\n ),\n promoteEvidence: Effect.fn(\"AuthorizationLifecycleRepository.promoteEvidence\")(\n (authorizationId, evidence) =>\n Effect.tryPromise({\n try: () => repository.promoteEvidence(authorizationId, evidence),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.promoteEvidence\", cause),\n }),\n ),\n recover: ({ authorizationId, revoke }) =>\n Effect.tryPromise({\n try: () =>\n repository.recover({\n authorizationId,\n revoke: (aggregate) => Effect.runPromise(revoke(aggregate)),\n }),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.recover\", cause),\n }),\n rotate: Effect.fn(\"AuthorizationLifecycleRepository.rotate\")(\n (authorizationId, credential, expiresAt) =>\n Effect.tryPromise({\n try: () => repository.rotate(authorizationId, credential, expiresAt),\n catch: (cause) => failure(\"AuthorizationLifecycleRepository.rotate\", cause),\n }),\n ),\n });\n\nexport const toAsync = (repository: Lifecycle.Interface): Repository => ({\n bind: (authorizationId, binding) => Effect.runPromise(repository.bind(authorizationId, binding)),\n connect: (aggregate) => Effect.runPromise(repository.connect(aggregate)),\n detach: ({ connectionId, revoke }) =>\n Effect.runPromise(\n repository.detach({\n connectionId,\n revoke: (aggregate) => Effect.tryPromise(() => revoke(aggregate)),\n }),\n ),\n findByProviderAccount: (providerId, providerAccountId) =>\n Effect.runPromise(repository.findByProviderAccount(providerId, providerAccountId)),\n get: (authorizationId) => Effect.runPromise(repository.get(authorizationId)),\n getByConnectionId: (connectionId) =>\n Effect.runPromise(repository.getByConnectionId(connectionId)),\n promoteEvidence: (authorizationId, evidence) =>\n Effect.runPromise(repository.promoteEvidence(authorizationId, evidence)),\n recover: ({ authorizationId, revoke }) =>\n Effect.runPromise(\n repository.recover({\n authorizationId,\n revoke: (aggregate) => Effect.tryPromise(() => revoke(aggregate)),\n }),\n ),\n rotate: (authorizationId, credential, expiresAt) =>\n Effect.runPromise(repository.rotate(authorizationId, credential, expiresAt)),\n});\n\nexport const from = (repository: Repository): Repository => repository;\n\nexport { Error } from \"../auth/lifecycle-repository.ts\";\nexport type { Aggregate, DetachResult } from \"../auth/lifecycle-repository.ts\";\n","import { Data, Effect, Layer } from \"effect\";\n\nimport * as Connection from \"../auth/connection.ts\";\nimport * as Connect from \"../auth/connect.ts\";\nimport type * as Repository from \"./authorization-lifecycle.ts\";\nimport type * as ProviderAuthorization from \"../auth/authorization.ts\";\nimport { webCryptoLayer } from \"../plan/canonical-json.ts\";\nimport * as LifecycleRepository from \"./authorization-lifecycle.ts\";\nimport type * as Secret from \"../auth/secret.ts\";\n\nexport { assertGrant, AuthorizationError, encode, Grant, Schema } from \"../auth/connection.ts\";\nexport type { Connection, OAuthContinuation, StoredCredential } from \"../auth/connection.ts\";\n\nexport function decode(input: unknown): Promise<Connection.Connection> {\n return Effect.runPromise(Connection.decode(input));\n}\n\nexport type Method = Data.TaggedEnum<{\n Interactive: {\n readonly continuations: ContinuationStore;\n readonly flow: InteractiveFlow;\n readonly ttlMs?: number;\n };\n Token: {\n readonly authenticate: (token: Secret.Value) => Promise<Connect.Authentication>;\n readonly providerId: string;\n readonly requiredCapabilities: ReadonlyArray<ProviderAuthorization.Capability>;\n readonly token: Secret.Value;\n };\n}>;\nexport const Method = Data.taggedEnum<Method>();\n\nexport interface ContinuationStore {\n readonly consume: (id: string, now: Date) => Promise<Connect.Continuation | null>;\n readonly put: (continuation: Connect.Continuation) => Promise<void>;\n}\n\nexport interface InteractiveFlow {\n readonly complete: (payload: Secret.Value, callbackUrl: URL) => Promise<Connect.Authentication>;\n readonly method: \"integration\" | \"oauth2\";\n readonly providerId: string;\n readonly requiredCapabilities: ReadonlyArray<ProviderAuthorization.Capability>;\n readonly start: (continuationId: string) => Promise<Connect.InteractiveStart>;\n}\n\nconst connectionFailure = (operation: string, cause: unknown): Connect.Error =>\n cause instanceof Connect.Error\n ? cause\n : new Connect.Error({\n category: \"provider\",\n message: cause instanceof globalThis.Error ? cause.message : String(cause),\n operation,\n retry: \"unknown\",\n });\n\nconst effectMethod = (method: Method): Connect.Method =>\n method._tag === \"Interactive\"\n ? Connect.Method.Interactive({\n continuations: effectContinuations(method.continuations),\n flow: effectFlow(method.flow),\n ...(method.ttlMs === undefined ? {} : { ttlMs: method.ttlMs }),\n })\n : Connect.Method.Token({\n authenticate: (token) =>\n Effect.tryPromise({\n try: () => method.authenticate(token),\n catch: (cause) => connectionFailure(\"Connection.start\", cause),\n }),\n providerId: method.providerId,\n requiredCapabilities: method.requiredCapabilities,\n token: method.token,\n });\n\nconst effectContinuations = (store: ContinuationStore): Connect.ContinuationStore => ({\n consume: (id, now) =>\n Effect.tryPromise({\n try: () => store.consume(id, now),\n catch: (cause) => connectionFailure(\"ConnectionContinuations.consume\", cause),\n }),\n put: (continuation) =>\n Effect.tryPromise({\n try: () => store.put(continuation),\n catch: (cause) => connectionFailure(\"ConnectionContinuations.put\", cause),\n }),\n});\n\nexport const toAsyncContinuations = (store: Connect.ContinuationStore): ContinuationStore => ({\n consume: (id, now) => Effect.runPromise(store.consume(id, now)),\n put: (continuation) => Effect.runPromise(store.put(continuation)),\n});\n\nconst effectFlow = (flow: InteractiveFlow): Connect.InteractiveFlow => ({\n complete: (payload, callbackUrl) =>\n Effect.tryPromise({\n try: () => flow.complete(payload, callbackUrl),\n catch: (cause) => connectionFailure(\"Connection.complete\", cause),\n }),\n method: flow.method,\n providerId: flow.providerId,\n requiredCapabilities: flow.requiredCapabilities,\n start: (continuationId) =>\n Effect.tryPromise({\n try: () => flow.start(continuationId),\n catch: (cause) => connectionFailure(\"Connection.start\", cause),\n }),\n});\n\n/** Adapts an Effect-native provider flow to the Promise facade. */\nexport const fromEffectFlow = (flow: Connect.InteractiveFlow): InteractiveFlow => ({\n complete: (payload, callbackUrl) => Effect.runPromise(flow.complete(payload, callbackUrl)),\n method: flow.method,\n providerId: flow.providerId,\n requiredCapabilities: flow.requiredCapabilities,\n start: (continuationId) =>\n Effect.runPromise(flow.start(continuationId).pipe(Effect.provide(webCryptoLayer))),\n});\n\n/** Adapts an Effect-native token method to the Promise facade. */\nexport function fromEffectTokenMethod(\n method: Extract<Connect.Method, { readonly _tag: \"Token\" }>,\n): Extract<Method, { readonly _tag: \"Token\" }> {\n return Method.Token({\n authenticate: (token) => Effect.runPromise(method.authenticate(token)),\n providerId: method.providerId,\n requiredCapabilities: method.requiredCapabilities,\n token: method.token,\n });\n}\n\nexport async function start(\n input: Connect.BaseInput & {\n readonly method: Method;\n readonly repository: Repository.Repository;\n },\n): Promise<Connect.StartResult> {\n return Effect.runPromise(\n Connect.start({\n authorizedById: input.authorizedById,\n grant: input.grant,\n method: effectMethod(input.method),\n ownerId: input.ownerId,\n }).pipe(\n Effect.provide(Layer.merge(LifecycleRepository.layerFrom(input.repository), webCryptoLayer)),\n ),\n );\n}\n\nexport async function complete(input: {\n readonly callbackUrl: URL;\n readonly continuationId: string;\n readonly continuations: ContinuationStore;\n readonly flow: InteractiveFlow;\n readonly repository: Repository.Repository;\n}): Promise<Repository.Aggregate> {\n return Effect.runPromise(\n Connect.complete({\n callbackUrl: input.callbackUrl,\n continuationId: input.continuationId,\n continuations: effectContinuations(input.continuations),\n flow: effectFlow(input.flow),\n }).pipe(\n Effect.provide(Layer.merge(LifecycleRepository.layerFrom(input.repository), webCryptoLayer)),\n ),\n );\n}\n\nexport { Error, StartResult } from \"../auth/connect.ts\";\nexport type { Authentication, ConnectionStartResult } from \"../auth/connection-api.ts\";\n"],"mappings":";;;;;;;;;;;;;AAqCA,MAAM,WAAW,WAAmB,UAClC,iBAAiBA,QACb,QACA,IAAIA,MAAgB;CAClB,UAAU;CACV,SAAS,iBAAiB,WAAW,QAAQ,MAAM,UAAU,OAAO,KAAK;CACzE;CACA,OAAO;AACT,CAAC;AAEP,MAAa,aAAa,eACxB,MAAM,QAAQC,SAAmB;CAC/B,MAAM,OAAO,GAAG,uCAAuC,CAAC,EAAE,iBAAiB,YACzE,OAAO,WAAW;EAChB,WAAW,WAAW,KAAK,iBAAiB,OAAO;EACnD,QAAQ,UAAU,QAAQ,yCAAyC,KAAK;CAC1E,CAAC,CACH;CACA,SAAS,OAAO,GAAG,0CAA0C,CAAC,EAAE,cAC9D,OAAO,WAAW;EAChB,WAAW,WAAW,QAAQ,SAAS;EACvC,QAAQ,UAAU,QAAQ,4CAA4C,KAAK;CAC7E,CAAC,CACH;CACA,SAAS,EAAE,cAAc,aACvB,OAAO,WAAW;EAChB,WACE,WAAW,OAAO;GAChB;GACA,SAAS,cAAc,OAAO,WAAW,OAAO,SAAS,CAAC;EAC5D,CAAC;EACH,QAAQ,UAAU,QAAQ,2CAA2C,KAAK;CAC5E,CAAC;CACH,uBAAuB,OAAO,GAAG,wDAAwD,CAAC,EACvF,YAAY,sBACX,OAAO,WAAW;EAChB,WAAW,WAAW,sBAAsB,YAAY,iBA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BAAgB,MAAM;EACtB,OAAO,MAAM;EACb,QAAQ,aAAa,MAAM,MAAM;EACjC,SAAS,MAAM;CACjB,CAAC,CAAC,CAAC,KACD,OAAO,QAAQ,MAAM,MAAMC,UAA8B,MAAM,UAAU,GAAG,cAAc,CAAC,CAC7F,CACF;AACF;AAEA,eAAsB,SAAS,OAMG;CAChC,OAAO,OAAO,WACZC,WAAiB;EACf,aAAa,MAAM;EACnB,gBAAgB,MAAM;EACtB,eAAe,oBAAoB,MAAM,aAAa;EACtD,MAAM,WAAW,MAAM,IAAI;CAC7B,CAAC,CAAC,CAAC,KACD,OAAO,QAAQ,MAAM,MAAMD,UAA8B,MAAM,UAAU,GAAG,cAAc,CAAC,CAC7F,CACF;AACF"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { A as Connection, F as assertGrant, I as authorizationError, L as decode, N as Schema, P as StoredCredential, R as encode, _ as StartResult, a as Authentication, c as CompleteInput, d as Error, f as Failure, g as Requirements, h as Method, j as Grant, k as AuthorizationError, l as Continuation, m as InteractiveStart, o as AuthenticationFailure, p as InteractiveFlow, s as BaseInput, u as ContinuationStore, v as complete, y as start, z as validate } from "./zone-discovery-BA5I24vu.mjs";
|
|
2
|
-
declare namespace connection_api_d_exports {
|
|
3
|
-
export { Authentication, AuthenticationFailure, AuthorizationError, BaseInput, CompleteInput, Connection, Method as ConnectionMethod, StartResult as ConnectionStartResult, Continuation, ContinuationStore, Error, Failure, Grant, InteractiveFlow, InteractiveStart, Method, Requirements, Schema, StartResult, StoredCredential, assertGrant, authorizationError, complete, decode, encode, start, validate };
|
|
4
|
-
}
|
|
5
|
-
//#endregion
|
|
6
|
-
export { connection_api_d_exports as t };
|
|
7
|
-
//# sourceMappingURL=connection-api-DftK7eHo.d.mts.map
|