domainkit 0.1.1 → 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/README.md +87 -83
- package/dist/{client-BnD7QLRF.mjs → auth-6-KRy1gN.mjs} +235 -131
- package/dist/auth-6-KRy1gN.mjs.map +1 -0
- package/dist/{auth-B0owkrpk.mjs → auth-B4jq3yk3.mjs} +212 -20
- package/dist/auth-B4jq3yk3.mjs.map +1 -0
- package/dist/authorization-CQSKKMrW.mjs +255 -0
- package/dist/authorization-CQSKKMrW.mjs.map +1 -0
- package/dist/canonical-json-CpvqGMcr.mjs +57 -0
- package/dist/canonical-json-CpvqGMcr.mjs.map +1 -0
- package/dist/{cloudflare-D0-J2MfP.mjs → cloudflare-Bg_p-M2c.mjs} +26 -3
- package/dist/cloudflare-Bg_p-M2c.mjs.map +1 -0
- package/dist/cloudflare-FDl5q7Dm.d.mts +32 -0
- package/dist/cloudflare.d.mts +3 -3
- package/dist/cloudflare.mjs +2 -2
- package/dist/connection-BXoSrhZs.mjs +58 -0
- package/dist/connection-BXoSrhZs.mjs.map +1 -0
- package/dist/connection-CEqadXSm.d.mts +182 -0
- package/dist/connection-X3rZhrBZ.mjs +186 -0
- package/dist/connection-X3rZhrBZ.mjs.map +1 -0
- package/dist/connection-api-DftK7eHo.d.mts +7 -0
- package/dist/{dns-record-C_KwGPLf.mjs → dns-record-BLeqo56C.mjs} +23 -3
- package/dist/dns-record-BLeqo56C.mjs.map +1 -0
- package/dist/effect-cloudflare.d.mts +2 -2
- package/dist/effect-cloudflare.mjs +2 -2
- package/dist/effect-vercel.d.mts +2 -2
- package/dist/effect-vercel.mjs +2 -2
- package/dist/effect.d.mts +9 -46
- package/dist/effect.mjs +29 -7
- package/dist/effect.mjs.map +1 -1
- package/dist/{index-D2howbNz.d.mts → index-B1opsgls.d.mts} +53 -6
- package/dist/{index-CEzk2gbZ.d.mts → index-Ewc__bQu.d.mts} +58 -7
- package/dist/index.d.mts +169 -113
- package/dist/index.mjs +201 -139
- package/dist/index.mjs.map +1 -1
- package/dist/{resolver-BHPsADzE.d.mts → resolver-BbVzTbCX.d.mts} +630 -273
- package/dist/resolver-CxE-VDw4.mjs +598 -0
- package/dist/resolver-CxE-VDw4.mjs.map +1 -0
- package/dist/testing.d.mts +53 -44
- package/dist/testing.mjs +379 -107
- package/dist/testing.mjs.map +1 -1
- package/dist/{vercel-DD89DCqH.mjs → vercel-BIFpZRPu.mjs} +23 -3
- package/dist/vercel-BIFpZRPu.mjs.map +1 -0
- package/dist/vercel-DgJaUX9D.d.mts +31 -0
- package/dist/vercel.d.mts +3 -3
- package/dist/vercel.mjs +2 -2
- package/dist/verify-7_EbKbFM.d.mts +805 -0
- package/dist/verify-Q5RYpnuw.mjs +642 -0
- package/dist/verify-Q5RYpnuw.mjs.map +1 -0
- package/dist/zone-discovery-BA5I24vu.d.mts +1390 -0
- package/dist/zones-DKHTpX9C.mjs +19 -0
- package/dist/zones-DKHTpX9C.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/auth-B0owkrpk.mjs.map +0 -1
- package/dist/client-BnD7QLRF.mjs.map +0 -1
- package/dist/cloudflare-CprjjXfm.d.mts +0 -23
- package/dist/cloudflare-D0-J2MfP.mjs.map +0 -1
- package/dist/dns-record-C_KwGPLf.mjs.map +0 -1
- package/dist/manifest-CP85ePFn.d.mts +0 -583
- package/dist/receipt-CGSnfZQ6.mjs +0 -28
- package/dist/receipt-CGSnfZQ6.mjs.map +0 -1
- package/dist/resolver-tEXpKxmH.mjs +0 -200
- package/dist/resolver-tEXpKxmH.mjs.map +0 -1
- package/dist/vercel-D-E2aqb1.d.mts +0 -22
- package/dist/vercel-DD89DCqH.mjs.map +0 -1
- package/dist/verify-B80xCBh2.d.mts +0 -1407
- package/dist/verify-BXOvXE20.mjs +0 -1388
- package/dist/verify-BXOvXE20.mjs.map +0 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { M as Service, k as Error$2 } from "./dns-record-BLeqo56C.mjs";
|
|
3
|
+
import { Clock, Crypto, Data, Effect, Schema } from "effect";
|
|
4
|
+
//#region src/auth/connect.ts
|
|
5
|
+
const Method = Data.taggedEnum();
|
|
6
|
+
const StartResult = Data.taggedEnum();
|
|
7
|
+
var Error$1 = class extends Schema.TaggedError()("ConnectionError", {
|
|
8
|
+
category: Schema.Literals([
|
|
9
|
+
"authorization",
|
|
10
|
+
"provider",
|
|
11
|
+
"validation"
|
|
12
|
+
]),
|
|
13
|
+
message: Schema.String,
|
|
14
|
+
operation: Schema.String,
|
|
15
|
+
retry: Schema.Literals([
|
|
16
|
+
"never",
|
|
17
|
+
"after-user-action",
|
|
18
|
+
"safe",
|
|
19
|
+
"unknown"
|
|
20
|
+
])
|
|
21
|
+
}) {};
|
|
22
|
+
const mergeGrant = (current, requested) => {
|
|
23
|
+
if (current === void 0) return requested;
|
|
24
|
+
if (current._tag === "account" || requested._tag === "account") return { _tag: "account" };
|
|
25
|
+
return {
|
|
26
|
+
_tag: "domains",
|
|
27
|
+
domains: [.../* @__PURE__ */ new Set([...current.domains, ...requested.domains])]
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const persist = Effect.fn("Connection.persist")(function* (input) {
|
|
31
|
+
const repository = yield* Service;
|
|
32
|
+
const crypto = yield* Crypto.Crypto;
|
|
33
|
+
const now = new Date(yield* Clock.currentTimeMillis);
|
|
34
|
+
const missingCapability = input.requiredCapabilities.find((capability) => !input.authentication.capabilityEvidence.some((item) => item.capability === capability));
|
|
35
|
+
if (missingCapability !== void 0) return yield* new Error$1({
|
|
36
|
+
category: "authorization",
|
|
37
|
+
message: `Provider authorization lacks evidence for ${missingCapability}`,
|
|
38
|
+
operation: "Connection.persist",
|
|
39
|
+
retry: "after-user-action"
|
|
40
|
+
});
|
|
41
|
+
const existing = yield* repository.findByProviderAccount(input.providerId, input.authentication.providerAccountId);
|
|
42
|
+
const authorizationId = existing?.authorization.id ?? (yield* crypto.randomUUIDv4.pipe(Effect.mapError((cause) => new Error$1({
|
|
43
|
+
category: "validation",
|
|
44
|
+
message: cause.message,
|
|
45
|
+
operation: "Connection.persist",
|
|
46
|
+
retry: "safe"
|
|
47
|
+
}))));
|
|
48
|
+
const existingBinding = existing?.bindings.find((binding) => binding.ownerId === input.ownerId);
|
|
49
|
+
const binding = {
|
|
50
|
+
authorizationId,
|
|
51
|
+
createdAt: existingBinding?.createdAt ?? now,
|
|
52
|
+
grant: mergeGrant(existingBinding?.grant, input.grant),
|
|
53
|
+
id: existingBinding?.id ?? (yield* crypto.randomUUIDv4.pipe(Effect.mapError((cause) => new Error$1({
|
|
54
|
+
category: "validation",
|
|
55
|
+
message: cause.message,
|
|
56
|
+
operation: "Connection.persist",
|
|
57
|
+
retry: "safe"
|
|
58
|
+
})))),
|
|
59
|
+
ownerId: input.ownerId
|
|
60
|
+
};
|
|
61
|
+
const aggregate = {
|
|
62
|
+
authorization: {
|
|
63
|
+
authorizedById: input.authorizedById,
|
|
64
|
+
capabilityEvidence: [...input.authentication.capabilityEvidence],
|
|
65
|
+
createdAt: existing?.authorization.createdAt ?? now,
|
|
66
|
+
expiresAt: input.authentication.expiresAt,
|
|
67
|
+
id: authorizationId,
|
|
68
|
+
method: input.method,
|
|
69
|
+
providerAccountId: input.authentication.providerAccountId,
|
|
70
|
+
providerContext: input.authentication.providerContext,
|
|
71
|
+
providerId: input.providerId,
|
|
72
|
+
requiredCapabilities: [...input.requiredCapabilities],
|
|
73
|
+
revocation: { _tag: "Active" },
|
|
74
|
+
scopes: [...input.authentication.scopes]
|
|
75
|
+
},
|
|
76
|
+
bindings: [...existing?.bindings.filter((candidate) => candidate.id !== binding.id) ?? [], binding],
|
|
77
|
+
credential: input.authentication.credential
|
|
78
|
+
};
|
|
79
|
+
return yield* repository.connect(aggregate);
|
|
80
|
+
});
|
|
81
|
+
const start = Effect.fn("Connection.start")(function* (input) {
|
|
82
|
+
if (input.method._tag === "Interactive") {
|
|
83
|
+
const crypto = yield* Crypto.Crypto;
|
|
84
|
+
const now = yield* Clock.currentTimeMillis;
|
|
85
|
+
const continuationId = yield* crypto.randomUUIDv4.pipe(Effect.mapError((cause) => new Error$1({
|
|
86
|
+
category: "validation",
|
|
87
|
+
message: cause.message,
|
|
88
|
+
operation: "Connection.start",
|
|
89
|
+
retry: "safe"
|
|
90
|
+
})));
|
|
91
|
+
const started = yield* input.method.flow.start(continuationId);
|
|
92
|
+
yield* input.method.continuations.put({
|
|
93
|
+
authorizedById: input.authorizedById,
|
|
94
|
+
expiresAt: new Date(now + (input.method.ttlMs ?? 6e5)),
|
|
95
|
+
grant: input.grant,
|
|
96
|
+
id: continuationId,
|
|
97
|
+
method: input.method.flow.method,
|
|
98
|
+
ownerId: input.ownerId,
|
|
99
|
+
payload: started.payload,
|
|
100
|
+
providerId: input.method.flow.providerId,
|
|
101
|
+
requiredCapabilities: [...input.method.flow.requiredCapabilities]
|
|
102
|
+
});
|
|
103
|
+
return StartResult.Redirect({
|
|
104
|
+
authorizationUrl: started.authorizationUrl,
|
|
105
|
+
continuationId
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const authentication = yield* input.method.authenticate(input.method.token);
|
|
109
|
+
const aggregate = yield* persist({
|
|
110
|
+
authentication,
|
|
111
|
+
authorizedById: input.authorizedById,
|
|
112
|
+
grant: input.grant,
|
|
113
|
+
method: "token",
|
|
114
|
+
ownerId: input.ownerId,
|
|
115
|
+
providerId: input.method.providerId,
|
|
116
|
+
requiredCapabilities: input.method.requiredCapabilities
|
|
117
|
+
});
|
|
118
|
+
return StartResult.Connected({ aggregate });
|
|
119
|
+
});
|
|
120
|
+
const complete = Effect.fn("Connection.complete")(function* (input) {
|
|
121
|
+
const continuation = yield* input.continuations.consume(input.continuationId, new Date(yield* Clock.currentTimeMillis));
|
|
122
|
+
if (continuation === null) return yield* new Error$1({
|
|
123
|
+
category: "authorization",
|
|
124
|
+
message: "Connection continuation is expired, unknown, or already consumed",
|
|
125
|
+
operation: "Connection.complete",
|
|
126
|
+
retry: "after-user-action"
|
|
127
|
+
});
|
|
128
|
+
if (continuation.providerId !== input.flow.providerId || continuation.method !== input.flow.method) return yield* new Error$1({
|
|
129
|
+
category: "authorization",
|
|
130
|
+
message: "Connection continuation does not match the provider flow",
|
|
131
|
+
operation: "Connection.complete",
|
|
132
|
+
retry: "never"
|
|
133
|
+
});
|
|
134
|
+
const authentication = yield* input.flow.complete(continuation.payload, input.callbackUrl);
|
|
135
|
+
return yield* persist({
|
|
136
|
+
authentication,
|
|
137
|
+
authorizedById: continuation.authorizedById,
|
|
138
|
+
grant: continuation.grant,
|
|
139
|
+
method: continuation.method,
|
|
140
|
+
ownerId: continuation.ownerId,
|
|
141
|
+
providerId: continuation.providerId,
|
|
142
|
+
requiredCapabilities: continuation.requiredCapabilities
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/auth/secret.ts
|
|
147
|
+
var secret_exports = /* @__PURE__ */ __exportAll({
|
|
148
|
+
Value: () => Value,
|
|
149
|
+
make: () => make
|
|
150
|
+
});
|
|
151
|
+
/** A deliberately non-serializable credential value. */
|
|
152
|
+
var Value = class Value {
|
|
153
|
+
#value;
|
|
154
|
+
constructor(value) {
|
|
155
|
+
this.#value = value;
|
|
156
|
+
}
|
|
157
|
+
static from(value) {
|
|
158
|
+
if (value.length === 0) throw new Error("Secret values cannot be empty");
|
|
159
|
+
return new Value(value);
|
|
160
|
+
}
|
|
161
|
+
expose() {
|
|
162
|
+
return this.#value;
|
|
163
|
+
}
|
|
164
|
+
toJSON() {
|
|
165
|
+
return "[REDACTED]";
|
|
166
|
+
}
|
|
167
|
+
toString() {
|
|
168
|
+
return "[REDACTED]";
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const make = Value.from;
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/auth/provider-context.ts
|
|
174
|
+
var provider_context_exports = /* @__PURE__ */ __exportAll({
|
|
175
|
+
Envelope: () => Envelope,
|
|
176
|
+
codec: () => codec,
|
|
177
|
+
decode: () => decode$1,
|
|
178
|
+
encode: () => encode$1
|
|
179
|
+
});
|
|
180
|
+
/** A provider-owned, versioned, non-secret context value persisted by the host. */
|
|
181
|
+
const Envelope = Schema.Struct({
|
|
182
|
+
value: Schema.Json,
|
|
183
|
+
version: Schema.String
|
|
184
|
+
});
|
|
185
|
+
/** Build an adapter-owned context codec from a schema and stable version identifier. */
|
|
186
|
+
function codec(version, schema) {
|
|
187
|
+
return {
|
|
188
|
+
decode: Effect.fn("ProviderContext.decode")((envelope) => envelope.version !== version ? Effect.fail(new Error$2({ message: `Unsupported provider context version: ${envelope.version}` })) : Schema.decodeUnknownEffect(schema)(envelope.value).pipe(Effect.mapError((cause) => new Error$2({ message: cause.message })))),
|
|
189
|
+
encode: Effect.fn("ProviderContext.encode")((value) => Schema.encodeEffect(schema)(value).pipe(Effect.flatMap((encoded) => Schema.decodeUnknownEffect(Schema.Json)(encoded)), Effect.map((encoded) => ({
|
|
190
|
+
value: encoded,
|
|
191
|
+
version
|
|
192
|
+
})), Effect.mapError((cause) => new Error$2({ message: cause.message })))),
|
|
193
|
+
version
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const decode$1 = Effect.fn("ProviderContext.Envelope.decode")((input) => Schema.decodeUnknownEffect(Envelope)(input).pipe(Effect.mapError((cause) => new Error$2({ message: cause.message }))));
|
|
197
|
+
const encode$1 = Schema.encodeSync(Envelope);
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/auth/authorization.ts
|
|
200
|
+
var authorization_exports = /* @__PURE__ */ __exportAll({
|
|
201
|
+
Capability: () => Capability,
|
|
202
|
+
CapabilityEvidence: () => CapabilityEvidence,
|
|
203
|
+
Evidence: () => Evidence,
|
|
204
|
+
EvidenceSchema: () => EvidenceSchema,
|
|
205
|
+
Revocation: () => Revocation,
|
|
206
|
+
Schema: () => Schema$1,
|
|
207
|
+
decode: () => decode,
|
|
208
|
+
encode: () => encode,
|
|
209
|
+
evidenceFor: () => evidenceFor,
|
|
210
|
+
validate: () => validate
|
|
211
|
+
});
|
|
212
|
+
const Capability = Schema.Literals(["dns:read", "dns:write"]);
|
|
213
|
+
const Evidence = Data.taggedEnum();
|
|
214
|
+
const EvidenceSchema = Schema.TaggedUnion({
|
|
215
|
+
Declared: {},
|
|
216
|
+
Exercised: { observedAt: Schema.DateFromString },
|
|
217
|
+
Introspected: { observedAt: Schema.DateFromString }
|
|
218
|
+
});
|
|
219
|
+
const CapabilityEvidence = Schema.Struct({
|
|
220
|
+
capability: Capability,
|
|
221
|
+
evidence: EvidenceSchema
|
|
222
|
+
});
|
|
223
|
+
const Revocation = Schema.TaggedUnion({
|
|
224
|
+
Active: {},
|
|
225
|
+
Pending: { requestedAt: Schema.DateFromString }
|
|
226
|
+
});
|
|
227
|
+
/** A provider credential authorization shared by one or more owner connections. */
|
|
228
|
+
const Schema$1 = Schema.Struct({
|
|
229
|
+
authorizedById: Schema.String,
|
|
230
|
+
capabilityEvidence: Schema.Array(CapabilityEvidence),
|
|
231
|
+
createdAt: Schema.DateFromString,
|
|
232
|
+
expiresAt: Schema.NullOr(Schema.DateFromString),
|
|
233
|
+
id: Schema.String,
|
|
234
|
+
method: Schema.Literals([
|
|
235
|
+
"integration",
|
|
236
|
+
"oauth2",
|
|
237
|
+
"token"
|
|
238
|
+
]),
|
|
239
|
+
providerAccountId: Schema.String,
|
|
240
|
+
providerContext: Envelope,
|
|
241
|
+
providerId: Schema.String,
|
|
242
|
+
requiredCapabilities: Schema.Array(Capability),
|
|
243
|
+
revocation: Revocation,
|
|
244
|
+
scopes: Schema.Array(Schema.String)
|
|
245
|
+
});
|
|
246
|
+
const decode = Effect.fn("ProviderAuthorization.decode")((input) => Schema.decodeUnknownEffect(Schema$1)(input).pipe(Effect.mapError((cause) => new Error$2({ message: cause.message }))));
|
|
247
|
+
const validate = Effect.fn("ProviderAuthorization.validate")((input) => Schema.decodeUnknownEffect(Schema.toType(Schema$1))(input).pipe(Effect.mapError((cause) => new Error$2({ message: cause.message }))));
|
|
248
|
+
const encode = Schema.encodeSync(Schema$1);
|
|
249
|
+
function evidenceFor(authorization, capability) {
|
|
250
|
+
return authorization.capabilityEvidence.find((item) => item.capability === capability)?.evidence;
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
export { StartResult as _, Schema$1 as a, encode as c, provider_context_exports as d, Value as f, Method as g, Error$1 as h, EvidenceSchema as i, evidenceFor as l, secret_exports as m, CapabilityEvidence as n, authorization_exports as o, make as p, Evidence as r, decode as s, Capability as t, codec as u, complete as v, start as y };
|
|
254
|
+
|
|
255
|
+
//# sourceMappingURL=authorization-CQSKKMrW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-CQSKKMrW.mjs","names":["Error","Repository.Service","InvalidInputError","decode","encode","S","Schema","ProviderContext.Envelope","InvalidInputError"],"sources":["../src/auth/connect.ts","../src/auth/secret.ts","../src/auth/provider-context.ts","../src/auth/authorization.ts"],"sourcesContent":["import { Clock, Crypto, Data, Effect, Schema } from \"effect\";\n\nimport { CryptoError } from \"../plan/canonical-json.ts\";\nimport type { Error as InvalidInputError } from \"../invalid-input.ts\";\nimport type * as DnsProvider from \"../provider/provider.ts\";\nimport * as ProviderAuthorization from \"./authorization.ts\";\nimport type * as Binding from \"./connection.ts\";\nimport * as Repository from \"./lifecycle-repository.ts\";\nimport type * as ProviderContext from \"./provider-context.ts\";\nimport type * as Secret from \"./secret.ts\";\n\nexport interface Authentication {\n readonly capabilityEvidence: ReadonlyArray<ProviderAuthorization.CapabilityEvidence>;\n readonly credential: Binding.StoredCredential;\n readonly expiresAt: Date | null;\n readonly providerAccountId: string;\n readonly providerContext: ProviderContext.Envelope;\n readonly scopes: ReadonlyArray<string>;\n}\n\nexport type AuthenticationFailure = Error | InvalidInputError | DnsProvider.Error;\n\nexport interface InteractiveStart {\n readonly authorizationUrl: URL;\n readonly payload: Secret.Value;\n}\n\nexport interface Continuation extends BaseInput {\n readonly expiresAt: Date;\n readonly id: string;\n readonly method: \"integration\" | \"oauth2\";\n readonly payload: Secret.Value;\n readonly providerId: string;\n readonly requiredCapabilities: ReadonlyArray<ProviderAuthorization.Capability>;\n}\n\nexport interface ContinuationStore {\n readonly consume: (id: string, now: Date) => Effect.Effect<Continuation | null, Error>;\n readonly put: (continuation: Continuation) => Effect.Effect<void, Error>;\n}\n\nexport interface InteractiveFlow {\n readonly complete: (\n payload: Secret.Value,\n callbackUrl: URL,\n ) => Effect.Effect<Authentication, AuthenticationFailure>;\n readonly method: \"integration\" | \"oauth2\";\n readonly providerId: string;\n readonly requiredCapabilities: ReadonlyArray<ProviderAuthorization.Capability>;\n readonly start: (\n continuationId: string,\n ) => Effect.Effect<InteractiveStart, AuthenticationFailure, Crypto.Crypto>;\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: (\n token: Secret.Value,\n ) => Effect.Effect<Authentication, AuthenticationFailure>;\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 type StartResult = Data.TaggedEnum<{\n Connected: { readonly aggregate: Repository.Aggregate };\n Redirect: { readonly authorizationUrl: URL; readonly continuationId: string };\n}>;\nexport const StartResult = Data.taggedEnum<StartResult>();\n\nexport class Error extends Schema.TaggedError<Error>()(\"ConnectionError\", {\n category: Schema.Literals([\"authorization\", \"provider\", \"validation\"]),\n message: Schema.String,\n operation: Schema.String,\n retry: Schema.Literals([\"never\", \"after-user-action\", \"safe\", \"unknown\"]),\n}) {}\n\nexport interface BaseInput {\n readonly authorizedById: string;\n readonly grant: Binding.Grant;\n readonly ownerId: string;\n}\n\nexport interface CompleteInput {\n readonly callbackUrl: URL;\n readonly continuationId: string;\n readonly continuations: ContinuationStore;\n readonly flow: InteractiveFlow;\n}\n\nconst mergeGrant = (\n current: Binding.Grant | undefined,\n requested: Binding.Grant,\n): Binding.Grant => {\n if (current === undefined) return requested;\n if (current._tag === \"account\" || requested._tag === \"account\") return { _tag: \"account\" };\n return {\n _tag: \"domains\",\n domains: [...new Set([...current.domains, ...requested.domains])],\n };\n};\n\nconst persist = Effect.fn(\"Connection.persist\")(function* (\n input: BaseInput & {\n readonly authentication: Authentication;\n readonly method: \"integration\" | \"oauth2\" | \"token\";\n readonly providerId: string;\n readonly requiredCapabilities: ReadonlyArray<ProviderAuthorization.Capability>;\n },\n) {\n const repository = yield* Repository.Service;\n const crypto = yield* Crypto.Crypto;\n const now = new Date(yield* Clock.currentTimeMillis);\n const missingCapability = input.requiredCapabilities.find(\n (capability) =>\n !input.authentication.capabilityEvidence.some((item) => item.capability === capability),\n );\n if (missingCapability !== undefined) {\n return yield* new Error({\n category: \"authorization\",\n message: `Provider authorization lacks evidence for ${missingCapability}`,\n operation: \"Connection.persist\",\n retry: \"after-user-action\",\n });\n }\n const existing = yield* repository.findByProviderAccount(\n input.providerId,\n input.authentication.providerAccountId,\n );\n const authorizationId =\n existing?.authorization.id ??\n (yield* crypto.randomUUIDv4.pipe(\n Effect.mapError(\n (cause) =>\n new Error({\n category: \"validation\",\n message: cause.message,\n operation: \"Connection.persist\",\n retry: \"safe\",\n }),\n ),\n ));\n const existingBinding = existing?.bindings.find((binding) => binding.ownerId === input.ownerId);\n const binding: Binding.Connection = {\n authorizationId,\n createdAt: existingBinding?.createdAt ?? now,\n grant: mergeGrant(existingBinding?.grant, input.grant),\n id:\n existingBinding?.id ??\n (yield* crypto.randomUUIDv4.pipe(\n Effect.mapError(\n (cause) =>\n new Error({\n category: \"validation\",\n message: cause.message,\n operation: \"Connection.persist\",\n retry: \"safe\",\n }),\n ),\n )),\n ownerId: input.ownerId,\n };\n const aggregate: Repository.Aggregate = {\n authorization: {\n authorizedById: input.authorizedById,\n capabilityEvidence: [...input.authentication.capabilityEvidence],\n createdAt: existing?.authorization.createdAt ?? now,\n expiresAt: input.authentication.expiresAt,\n id: authorizationId,\n method: input.method,\n providerAccountId: input.authentication.providerAccountId,\n providerContext: input.authentication.providerContext,\n providerId: input.providerId,\n requiredCapabilities: [...input.requiredCapabilities],\n revocation: { _tag: \"Active\" },\n scopes: [...input.authentication.scopes],\n },\n bindings: [\n ...(existing?.bindings.filter((candidate) => candidate.id !== binding.id) ?? []),\n binding,\n ],\n credential: input.authentication.credential,\n };\n return yield* repository.connect(aggregate);\n});\n\nexport const start = Effect.fn(\"Connection.start\")(function* (\n input: BaseInput & { readonly method: Method },\n) {\n if (input.method._tag === \"Interactive\") {\n const crypto = yield* Crypto.Crypto;\n const now = yield* Clock.currentTimeMillis;\n const continuationId = yield* crypto.randomUUIDv4.pipe(\n Effect.mapError(\n (cause) =>\n new Error({\n category: \"validation\",\n message: cause.message,\n operation: \"Connection.start\",\n retry: \"safe\",\n }),\n ),\n );\n const started = yield* input.method.flow.start(continuationId);\n yield* input.method.continuations.put({\n authorizedById: input.authorizedById,\n expiresAt: new Date(now + (input.method.ttlMs ?? 10 * 60_000)),\n grant: input.grant,\n id: continuationId,\n method: input.method.flow.method,\n ownerId: input.ownerId,\n payload: started.payload,\n providerId: input.method.flow.providerId,\n requiredCapabilities: [...input.method.flow.requiredCapabilities],\n });\n return StartResult.Redirect({\n authorizationUrl: started.authorizationUrl,\n continuationId,\n });\n }\n const authentication = yield* input.method.authenticate(input.method.token);\n const aggregate = yield* persist({\n authentication,\n authorizedById: input.authorizedById,\n grant: input.grant,\n method: \"token\",\n ownerId: input.ownerId,\n providerId: input.method.providerId,\n requiredCapabilities: input.method.requiredCapabilities,\n });\n return StartResult.Connected({ aggregate });\n});\n\nexport const complete = Effect.fn(\"Connection.complete\")(function* (input: CompleteInput) {\n const continuation = yield* input.continuations.consume(\n input.continuationId,\n new Date(yield* Clock.currentTimeMillis),\n );\n if (continuation === null) {\n return yield* new Error({\n category: \"authorization\",\n message: \"Connection continuation is expired, unknown, or already consumed\",\n operation: \"Connection.complete\",\n retry: \"after-user-action\",\n });\n }\n if (\n continuation.providerId !== input.flow.providerId ||\n continuation.method !== input.flow.method\n ) {\n return yield* new Error({\n category: \"authorization\",\n message: \"Connection continuation does not match the provider flow\",\n operation: \"Connection.complete\",\n retry: \"never\",\n });\n }\n const authentication = yield* input.flow.complete(continuation.payload, input.callbackUrl);\n return yield* persist({\n authentication,\n authorizedById: continuation.authorizedById,\n grant: continuation.grant,\n method: continuation.method,\n ownerId: continuation.ownerId,\n providerId: continuation.providerId,\n requiredCapabilities: continuation.requiredCapabilities,\n });\n});\n\nexport type Requirements = Repository.Service | Crypto.Crypto;\nexport type Failure = AuthenticationFailure | Repository.Error | CryptoError;\n","/** A deliberately non-serializable credential value. */\nexport class Value {\n readonly #value: string;\n\n private constructor(value: string) {\n this.#value = value;\n }\n\n static from(value: string): Value {\n if (value.length === 0) throw new Error(\"Secret values cannot be empty\");\n return new Value(value);\n }\n\n expose(): string {\n return this.#value;\n }\n\n toJSON(): string {\n return \"[REDACTED]\";\n }\n\n toString(): string {\n return \"[REDACTED]\";\n }\n}\n\nexport const make = Value.from;\n","import { Effect, Schema } from \"effect\";\n\nimport { Error as InvalidInputError } from \"../invalid-input.ts\";\n\n/** A provider-owned, versioned, non-secret context value persisted by the host. */\nexport const Envelope = Schema.Struct({\n value: Schema.Json,\n version: Schema.String,\n});\nexport interface Envelope extends Schema.Schema.Type<typeof Envelope> {}\n\nexport interface Codec<A> {\n readonly decode: (envelope: Envelope) => Effect.Effect<A, InvalidInputError>;\n readonly encode: (value: A) => Effect.Effect<Envelope, InvalidInputError>;\n readonly version: string;\n}\n\n/** Build an adapter-owned context codec from a schema and stable version identifier. */\nexport function codec<A, I>(version: string, schema: Schema.Codec<A, I>): Codec<A> {\n return {\n decode: Effect.fn(\"ProviderContext.decode\")((envelope) =>\n envelope.version !== version\n ? Effect.fail(\n new InvalidInputError({\n message: `Unsupported provider context version: ${envelope.version}`,\n }),\n )\n : Schema.decodeUnknownEffect(schema)(envelope.value).pipe(\n Effect.mapError((cause) => new InvalidInputError({ message: cause.message })),\n ),\n ),\n encode: Effect.fn(\"ProviderContext.encode\")((value) =>\n Schema.encodeEffect(schema)(value).pipe(\n Effect.flatMap((encoded) => Schema.decodeUnknownEffect(Schema.Json)(encoded)),\n Effect.map((encoded) => ({ value: encoded, version })),\n Effect.mapError((cause) => new InvalidInputError({ message: cause.message })),\n ),\n ),\n version,\n };\n}\n\nexport const decode = Effect.fn(\"ProviderContext.Envelope.decode\")((input: unknown) =>\n Schema.decodeUnknownEffect(Envelope)(input).pipe(\n Effect.mapError((cause) => new InvalidInputError({ message: cause.message })),\n ),\n);\n\nexport const encode = Schema.encodeSync(Envelope);\n","import { Data, Effect, Schema as S } from \"effect\";\n\nimport { Error as InvalidInputError } from \"../invalid-input.ts\";\nimport * as ProviderContext from \"./provider-context.ts\";\n\nexport const Capability = S.Literals([\"dns:read\", \"dns:write\"]);\nexport type Capability = typeof Capability.Type;\n\nexport type Evidence = Data.TaggedEnum<{\n Declared: {};\n Exercised: { readonly observedAt: Date };\n Introspected: { readonly observedAt: Date };\n}>;\nexport const Evidence = Data.taggedEnum<Evidence>();\n\nexport const EvidenceSchema = S.TaggedUnion({\n Declared: {},\n Exercised: { observedAt: S.DateFromString },\n Introspected: { observedAt: S.DateFromString },\n});\n\nexport const CapabilityEvidence = S.Struct({\n capability: Capability,\n evidence: EvidenceSchema,\n});\nexport interface CapabilityEvidence extends S.Schema.Type<typeof CapabilityEvidence> {}\n\nexport const Revocation = S.TaggedUnion({\n Active: {},\n Pending: { requestedAt: S.DateFromString },\n});\nexport type Revocation = typeof Revocation.Type;\n\n/** A provider credential authorization shared by one or more owner connections. */\nexport const Schema = S.Struct({\n authorizedById: S.String,\n capabilityEvidence: S.Array(CapabilityEvidence),\n createdAt: S.DateFromString,\n expiresAt: S.NullOr(S.DateFromString),\n id: S.String,\n method: S.Literals([\"integration\", \"oauth2\", \"token\"]),\n providerAccountId: S.String,\n providerContext: ProviderContext.Envelope,\n providerId: S.String,\n requiredCapabilities: S.Array(Capability),\n revocation: Revocation,\n scopes: S.Array(S.String),\n});\nexport interface ProviderAuthorization extends S.Schema.Type<typeof Schema> {}\n\nexport const decode = Effect.fn(\"ProviderAuthorization.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(\"ProviderAuthorization.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 function evidenceFor(\n authorization: ProviderAuthorization,\n capability: Capability,\n): Evidence | undefined {\n return authorization.capabilityEvidence.find((item) => item.capability === capability)?.evidence;\n}\n"],"mappings":";;;;AAqEA,MAAa,SAAS,KAAK,WAAmB;AAM9C,MAAa,cAAc,KAAK,WAAwB;AAExD,IAAaA,UAAb,cAA2B,OAAO,YAAmB,CAAC,CAAC,mBAAmB;CACxE,UAAU,OAAO,SAAS;EAAC;EAAiB;EAAY;CAAY,CAAC;CACrE,SAAS,OAAO;CAChB,WAAW,OAAO;CAClB,OAAO,OAAO,SAAS;EAAC;EAAS;EAAqB;EAAQ;CAAS,CAAC;AAC1E,CAAC,CAAC,CAAC,CAAC;AAeJ,MAAM,cACJ,SACA,cACkB;CAClB,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,IAAI,QAAQ,SAAS,aAAa,UAAU,SAAS,WAAW,OAAO,EAAE,MAAM,UAAU;CACzF,OAAO;EACL,MAAM;EACN,SAAS,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,QAAQ,SAAS,GAAG,UAAU,OAAO,CAAC,CAAC;CAClE;AACF;AAEA,MAAM,UAAU,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAC9C,OAMA;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,OAAE,MAAM,kBAAkB;CAC9C,WAAWA,OAAE;CACb,WAAWA,OAAE,OAAOA,OAAE,cAAc;CACpC,IAAIA,OAAE;CACN,QAAQA,OAAE,SAAS;EAAC;EAAe;EAAU;CAAO,CAAC;CACrD,mBAAmBA,OAAE;CACrB,iBAAiBE;CACjB,YAAYF,OAAE;CACd,sBAAsBA,OAAE,MAAM,UAAU;CACxC,YAAY;CACZ,QAAQA,OAAE,MAAMA,OAAE,MAAM;AAC1B,CAAC;AAGD,MAAa,SAAS,OAAO,GAAG,8BAA8B,CAAC,EAAE,UAC/DA,OAAE,oBAAoBC,QAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KACnC,OAAO,UAAU,UAAU,IAAIE,QAAkB,EAAE,SAAS,MAAM,QAAQ,CAAC,CAAC,CAC9E,CACF;AAEA,MAAa,WAAW,OAAO,GAAG,gCAAgC,CAAC,EAAE,UACnEH,OAAE,oBAAoBA,OAAE,OAAOC,QAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAC7C,OAAO,UAAU,UAAU,IAAIE,QAAkB,EAAE,SAAS,MAAM,QAAQ,CAAC,CAAC,CAC9E,CACF;AAEA,MAAa,SAASH,OAAE,WAAWC,QAAM;AAEzC,SAAgB,YACd,eACA,YACsB;CACtB,OAAO,cAAc,mBAAmB,MAAM,SAAS,KAAK,eAAe,UAAU,CAAC,EAAE;AAC1F"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { Crypto, Effect, Layer, PlatformError, Schema } from "effect";
|
|
3
|
+
//#region src/plan/canonical-json.ts
|
|
4
|
+
var canonical_json_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
CryptoError: () => CryptoError,
|
|
6
|
+
sha256Encoded: () => sha256Encoded,
|
|
7
|
+
sha256Json: () => sha256Json,
|
|
8
|
+
sha256Text: () => sha256Text,
|
|
9
|
+
stringify: () => stringify,
|
|
10
|
+
webCryptoLayer: () => webCryptoLayer
|
|
11
|
+
});
|
|
12
|
+
var CryptoError = class extends Schema.TaggedError()("CryptoError", { message: Schema.String }) {};
|
|
13
|
+
/** Deterministic JSON serialization for already schema-encoded protocol values. */
|
|
14
|
+
function stringify(value) {
|
|
15
|
+
if (value === null || typeof value !== "object") {
|
|
16
|
+
const encoded = JSON.stringify(value);
|
|
17
|
+
if (encoded === void 0) throw new TypeError("Value is not representable as JSON");
|
|
18
|
+
return encoded;
|
|
19
|
+
}
|
|
20
|
+
if (isJsonArray(value)) return `[${value.map(stringify).join(",")}]`;
|
|
21
|
+
return `{${Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entry]) => `${JSON.stringify(key)}:${stringify(entry)}`).join(",")}}`;
|
|
22
|
+
}
|
|
23
|
+
function isJsonArray(value) {
|
|
24
|
+
return Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
const sha256Text = Effect.fn("Digest.sha256Text")(function* (value) {
|
|
27
|
+
return [...yield* (yield* Crypto.Crypto).digest("SHA-256", new TextEncoder().encode(value)).pipe(Effect.mapError((cause) => new CryptoError({ message: cause.message })))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
28
|
+
});
|
|
29
|
+
const sha256Json = Effect.fn("Digest.sha256Json")((value) => Effect.try({
|
|
30
|
+
try: () => stringify(value),
|
|
31
|
+
catch: (cause) => new CryptoError({ message: cause instanceof Error ? cause.message : String(cause) })
|
|
32
|
+
}).pipe(Effect.flatMap(sha256Text)));
|
|
33
|
+
function sha256EncodedProgram(schema, value) {
|
|
34
|
+
return Schema.encodeEffect(schema)(value).pipe(Effect.mapError((cause) => new CryptoError({ message: cause.message })), Effect.flatMap(Schema.decodeUnknownEffect(Schema.Json)), Effect.mapError((cause) => new CryptoError({ message: cause.message })), Effect.flatMap(sha256Json));
|
|
35
|
+
}
|
|
36
|
+
const sha256Encoded = Effect.fn("Digest.sha256Encoded")(sha256EncodedProgram);
|
|
37
|
+
/** Portable Web Crypto implementation for hosts that want a ready-made Layer. */
|
|
38
|
+
const webCryptoLayer = Layer.succeed(Crypto.Crypto, Crypto.make({
|
|
39
|
+
randomBytes: (size) => crypto.getRandomValues(new Uint8Array(size)),
|
|
40
|
+
digest: (algorithm, data) => Effect.tryPromise({
|
|
41
|
+
try: async () => {
|
|
42
|
+
const bytes = new Uint8Array(data.byteLength);
|
|
43
|
+
bytes.set(data);
|
|
44
|
+
return new Uint8Array(await crypto.subtle.digest(algorithm, bytes.buffer));
|
|
45
|
+
},
|
|
46
|
+
catch: (cause) => PlatformError.systemError({
|
|
47
|
+
_tag: "Unknown",
|
|
48
|
+
module: "WebCrypto",
|
|
49
|
+
method: "digest",
|
|
50
|
+
cause
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
}));
|
|
54
|
+
//#endregion
|
|
55
|
+
export { webCryptoLayer as i, sha256Encoded as n, stringify as r, canonical_json_exports as t };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=canonical-json-CpvqGMcr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-json-CpvqGMcr.mjs","names":[],"sources":["../src/plan/canonical-json.ts"],"sourcesContent":["import { Crypto, Effect, Layer, PlatformError, Schema } from \"effect\";\n\nexport class CryptoError extends Schema.TaggedError<CryptoError>()(\"CryptoError\", {\n message: Schema.String,\n}) {}\n\nexport type Json =\n | null\n | boolean\n | number\n | string\n | ReadonlyArray<Json>\n | { readonly [key: string]: Json };\n\n/** Deterministic JSON serialization for already schema-encoded protocol values. */\nexport function stringify(value: Json): string {\n if (value === null || typeof value !== \"object\") {\n const encoded = JSON.stringify(value);\n if (encoded === undefined) throw new TypeError(\"Value is not representable as JSON\");\n return encoded;\n }\n if (isJsonArray(value)) return `[${value.map(stringify).join(\",\")}]`;\n return `{${Object.entries(value)\n .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))\n .map(([key, entry]) => `${JSON.stringify(key)}:${stringify(entry)}`)\n .join(\",\")}}`;\n}\n\nfunction isJsonArray(value: Json): value is ReadonlyArray<Json> {\n return Array.isArray(value);\n}\n\nexport const sha256Text = Effect.fn(\"Digest.sha256Text\")(function* (value: string) {\n const cryptoService = yield* Crypto.Crypto;\n const digest = yield* cryptoService\n .digest(\"SHA-256\", new TextEncoder().encode(value))\n .pipe(Effect.mapError((cause) => new CryptoError({ message: cause.message })));\n return [...digest].map((byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n});\n\nexport const sha256Json = Effect.fn(\"Digest.sha256Json\")((value: Json) =>\n Effect.try({\n try: () => stringify(value),\n catch: (cause) =>\n new CryptoError({ message: cause instanceof Error ? cause.message : String(cause) }),\n }).pipe(Effect.flatMap(sha256Text)),\n);\n\nfunction sha256EncodedProgram<S extends Schema.Constraint>(\n schema: S,\n value: S[\"Type\"],\n): Effect.Effect<string, CryptoError, Crypto.Crypto | S[\"EncodingServices\"]> {\n return Schema.encodeEffect(schema)(value).pipe(\n Effect.mapError((cause) => new CryptoError({ message: cause.message })),\n Effect.flatMap(Schema.decodeUnknownEffect(Schema.Json)),\n Effect.mapError((cause) => new CryptoError({ message: cause.message })),\n Effect.flatMap(sha256Json),\n );\n}\n\nexport const sha256Encoded = Effect.fn(\"Digest.sha256Encoded\")(sha256EncodedProgram);\n\n/** Portable Web Crypto implementation for hosts that want a ready-made Layer. */\nexport const webCryptoLayer: Layer.Layer<Crypto.Crypto> = Layer.succeed(\n Crypto.Crypto,\n Crypto.make({\n randomBytes: (size) => crypto.getRandomValues(new Uint8Array(size)),\n digest: (algorithm, data) =>\n Effect.tryPromise({\n try: async () => {\n const bytes = new Uint8Array(data.byteLength);\n bytes.set(data);\n return new Uint8Array(await crypto.subtle.digest(algorithm, bytes.buffer));\n },\n catch: (cause) =>\n PlatformError.systemError({\n _tag: \"Unknown\",\n module: \"WebCrypto\",\n method: \"digest\",\n cause,\n }),\n }),\n }),\n);\n"],"mappings":";;;;;;;;;;;AAEA,IAAa,c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,KAAK,EAAE,CAAC;AACvF,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,UAAU,CAAC,CACpC;AAEA,SAAS,qBACP,QACA,OAC2E;CAC3E,OAAO,OAAO,aAAa,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KACxC,OAAO,UAAU,UAAU,IAAI,YAAY,EAAE,SAAS,MAAM,QAAQ,CAAC,CAAC,GACtE,OAAO,QAAQ,OAAO,oBAAoB,OAAO,IAAI,CAAC,GACtD,OAAO,UAAU,UAAU,IAAI,YAAY,EAAE,SAAS,MAAM,QAAQ,CAAC,CAAC,GACtE,OAAO,QAAQ,UAAU,CAC3B;AACF;AAEA,MAAa,gBAAgB,OAAO,GAAG,sBAAsB,CAAC,CAAC,oBAAoB;;AAGnF,MAAa,iBAA6C,MAAM,QAC9D,OAAO,QACP,OAAO,KAAK;CACV,cAAc,SAAS,OAAO,gBAAgB,IAAI,WAAW,IAAI,CAAC;CAClE,SAAS,WAAW,SAClB,OAAO,WAAW;EAChB,KAAK,YAAY;GACf,MAAM,QAAQ,IAAI,WAAW,KAAK,UAAU;GAC5C,MAAM,IAAI,IAAI;GACd,OAAO,IAAI,WAAW,MAAM,OAAO,OAAO,OAAO,WAAW,MAAM,MAAM,CAAC;EAC3E;EACA,QAAQ,UACN,cAAc,YAAY;GACxB,MAAM;GACN,QAAQ;GACR,QAAQ;GACR;EACF,CAAC;CACL,CAAC;AACL,CAAC,CACH"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as subjectResolver$1, c as tokenValidator$1, d as make$1, i as oauthMethod$1, n as manifest$1, o as tokenConnectionMethod$1, r as oauthFlow$1, s as tokenMethod$1 } from "./auth-B4jq3yk3.mjs";
|
|
3
|
+
import { n as fromEffectFlow, r as fromEffectTokenMethod } from "./connection-X3rZhrBZ.mjs";
|
|
3
4
|
import { Effect } from "effect";
|
|
4
5
|
//#region src/promise/cloudflare-auth.ts
|
|
5
6
|
var cloudflare_auth_exports = /* @__PURE__ */ __exportAll({
|
|
6
7
|
manifest: () => manifest,
|
|
8
|
+
oauthFlow: () => oauthFlow,
|
|
7
9
|
oauthMethod: () => oauthMethod,
|
|
8
10
|
subjectResolver: () => subjectResolver,
|
|
11
|
+
tokenConnectionMethod: () => tokenConnectionMethod,
|
|
9
12
|
tokenMethod: () => tokenMethod,
|
|
10
13
|
tokenValidator: () => tokenValidator
|
|
11
14
|
});
|
|
@@ -16,6 +19,14 @@ function subjectResolver(options) {
|
|
|
16
19
|
const resolve = subjectResolver$1(options);
|
|
17
20
|
return (tokens, accessToken) => Effect.runPromise(resolve(tokens, accessToken));
|
|
18
21
|
}
|
|
22
|
+
/** Creates Cloudflare's OAuth implementation for the Promise connection facade. */
|
|
23
|
+
function oauthFlow(options) {
|
|
24
|
+
return fromEffectFlow(oauthFlow$1(options));
|
|
25
|
+
}
|
|
26
|
+
/** Creates a Cloudflare token method for the Promise connection facade. */
|
|
27
|
+
function tokenConnectionMethod(options) {
|
|
28
|
+
return fromEffectTokenMethod(tokenConnectionMethod$1(options));
|
|
29
|
+
}
|
|
19
30
|
function tokenValidator(options) {
|
|
20
31
|
const validate = tokenValidator$1(options);
|
|
21
32
|
return (token) => Effect.runPromise(validate(token));
|
|
@@ -24,6 +35,7 @@ function tokenValidator(options) {
|
|
|
24
35
|
//#region src/promise/cloudflare.ts
|
|
25
36
|
var cloudflare_exports = /* @__PURE__ */ __exportAll({
|
|
26
37
|
Auth: () => cloudflare_auth_exports,
|
|
38
|
+
discovery: () => discovery,
|
|
27
39
|
make: () => make
|
|
28
40
|
});
|
|
29
41
|
/** Creates a Promise-compatible facade over the Effect-native Cloudflare client. */
|
|
@@ -40,7 +52,18 @@ function make(options) {
|
|
|
40
52
|
validateToken: () => Effect.runPromise(client.validateToken())
|
|
41
53
|
};
|
|
42
54
|
}
|
|
55
|
+
/** Creates the optional Cloudflare discovery source for Promise consumers. */
|
|
56
|
+
function discovery(options) {
|
|
57
|
+
const client = make(options);
|
|
58
|
+
return {
|
|
59
|
+
listZones: async (name) => (await client.listZones({ name })).map((zone) => ({
|
|
60
|
+
...zone,
|
|
61
|
+
status: zone.status === "active" || zone.status === "pending" ? zone.status : "unknown"
|
|
62
|
+
})),
|
|
63
|
+
provider: client
|
|
64
|
+
};
|
|
65
|
+
}
|
|
43
66
|
//#endregion
|
|
44
|
-
export {
|
|
67
|
+
export { cloudflare_auth_exports as i, discovery as n, make as r, cloudflare_exports as t };
|
|
45
68
|
|
|
46
|
-
//# sourceMappingURL=cloudflare-
|
|
69
|
+
//# sourceMappingURL=cloudflare-Bg_p-M2c.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare-Bg_p-M2c.mjs","names":["EffectAuth.manifest","EffectAuth.oauthMethod","EffectAuth.tokenMethod","EffectAuth.subjectResolver","Connection.fromEffectFlow","EffectAuth.oauthFlow","Connection.fromEffectTokenMethod","EffectAuth.tokenConnectionMethod","EffectAuth.tokenValidator","Cloudflare.make"],"sources":["../src/promise/cloudflare-auth.ts","../src/promise/cloudflare.ts"],"sourcesContent":["import type * as oauth from \"oauth4webapi\";\nimport { Effect } from \"effect\";\n\nimport type * as ProviderAuth from \"../auth/manifest.ts\";\nimport type * as Secret from \"../auth/secret.ts\";\nimport * as EffectAuth from \"../providers/cloudflare/auth.ts\";\nimport * as Connection from \"./connection.ts\";\n\nexport const manifest = EffectAuth.manifest;\nexport const oauthMethod = EffectAuth.oauthMethod;\nexport const tokenMethod = EffectAuth.tokenMethod;\nexport type {\n CredentialTarget,\n OAuthFlowOptions,\n OAuthMethodOptions,\n SubjectResolverOptions,\n TokenValidatorOptions,\n} from \"../providers/cloudflare/auth.ts\";\n\nexport function subjectResolver(\n options: EffectAuth.SubjectResolverOptions,\n): ProviderAuth.AsyncOAuthSubjectResolver {\n const resolve = EffectAuth.subjectResolver(options);\n return (tokens: oauth.TokenEndpointResponse, accessToken: Secret.Value) =>\n Effect.runPromise(resolve(tokens, accessToken));\n}\n\n/** Creates Cloudflare's OAuth implementation for the Promise connection facade. */\nexport function oauthFlow(options: EffectAuth.OAuthFlowOptions): Connection.InteractiveFlow {\n return Connection.fromEffectFlow(EffectAuth.oauthFlow(options));\n}\n\n/** Creates a Cloudflare token method for the Promise connection facade. */\nexport function tokenConnectionMethod(\n options: EffectAuth.TokenConnectionOptions,\n): Extract<Connection.Method, { readonly _tag: \"Token\" }> {\n return Connection.fromEffectTokenMethod(EffectAuth.tokenConnectionMethod(options));\n}\n\nexport function tokenValidator(\n options: EffectAuth.TokenValidatorOptions,\n): (token: Secret.Value) => Promise<ProviderAuth.TokenValidation> {\n const validate = EffectAuth.tokenValidator(options);\n return (token) => Effect.runPromise(validate(token));\n}\n","import { Effect } from \"effect\";\n\nimport type * as ProviderAuth from \"../auth/manifest.ts\";\nimport type * as DnsProvider from \"../provider/provider.ts\";\nimport * as Cloudflare from \"../providers/cloudflare/index.ts\";\nimport type * as ZoneDiscovery from \"./zone-discovery.ts\";\n\nexport * as Auth from \"./cloudflare-auth.ts\";\nexport type {\n Account,\n Fetch,\n ListZonesInput,\n Options,\n Zone,\n} from \"../providers/cloudflare/client.ts\";\n\nexport interface Interface extends DnsProvider.AsyncInterface {\n readonly listAccounts: () => Promise<ReadonlyArray<Cloudflare.Account>>;\n readonly listZones: (\n input?: Cloudflare.Client.ListZonesInput,\n ) => Promise<ReadonlyArray<Cloudflare.Zone>>;\n readonly validateToken: () => Promise<ProviderAuth.TokenValidation>;\n}\n\n/** Creates a Promise-compatible facade over the Effect-native Cloudflare client. */\nexport function make(options: Cloudflare.Client.Options): Interface {\n const client = Cloudflare.make(options);\n return {\n id: client.id,\n createRecord: (zone, record) => Effect.runPromise(client.createRecord(zone, record)),\n deleteRecord: (zone, providerRecordId) =>\n Effect.runPromise(client.deleteRecord(zone, providerRecordId)),\n getRecord: (zone, providerRecordId) =>\n Effect.runPromise(client.getRecord(zone, providerRecordId)),\n listAccounts: () => Effect.runPromise(client.listAccounts()),\n listRecords: (zone) => Effect.runPromise(client.listRecords(zone)),\n listZones: (input) => Effect.runPromise(client.listZones(input)),\n validateToken: () => Effect.runPromise(client.validateToken()),\n };\n}\n\n/** Creates the optional Cloudflare discovery source for Promise consumers. */\nexport function discovery(options: Cloudflare.Client.Options): ZoneDiscovery.Source {\n const client = make(options);\n return {\n listZones: async (name) =>\n (await client.listZones({ name })).map((zone) => ({\n ...zone,\n status: zone.status === \"active\" || zone.status === \"pending\" ? zone.status : \"unknown\",\n })),\n provider: client,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAQA,MAAa,WAAWA;AACxB,MAAa,cAAcC;AAC3B,MAAa,cAAcC;AAS3B,SAAgB,gBACd,SACwC;CACxC,MAAM,UAAUC,kBAA2B,OAAO;CAClD,QAAQ,QAAqC,gBAC3C,OAAO,WAAW,QAAQ,QAAQ,WAAW,CAAC;AAClD;;AAGA,SAAgB,UAAU,SAAkE;CAC1F,OAAOC,eAA0BC,YAAqB,OAAO,CAAC;AAChE;;AAGA,SAAgB,sBACd,SACwD;CACxD,OAAOC,sBAAiCC,wBAAiC,OAAO,CAAC;AACnF;AAEA,SAAgB,eACd,SACgE;CAChE,MAAM,WAAWC,iBAA0B,OAAO;CAClD,QAAQ,UAAU,OAAO,WAAW,SAAS,KAAK,CAAC;AACrD;;;;;;;;;ACnBA,SAAgB,KAAK,SAA+C;CAClE,MAAM,SAASC,OAAgB,OAAO;CACtC,OAAO;EACL,IAAI,OAAO;EACX,eAAe,MAAM,WAAW,OAAO,WAAW,OAAO,aAAa,MAAM,MAAM,CAAC;EACnF,eAAe,MAAM,qBACnB,OAAO,WAAW,OAAO,aAAa,MAAM,gBAAgB,CAAC;EAC/D,YAAY,MAAM,qBAChB,OAAO,WAAW,OAAO,UAAU,MAAM,gBAAgB,CAAC;EAC5D,oBAAoB,OAAO,WAAW,OAAO,aAAa,CAAC;EAC3D,cAAc,SAAS,OAAO,WAAW,OAAO,YAAY,IAAI,CAAC;EACjE,YAAY,UAAU,OAAO,WAAW,OAAO,UAAU,KAAK,CAAC;EAC/D,qBAAqB,OAAO,WAAW,OAAO,cAAc,CAAC;CAC/D;AACF;;AAGA,SAAgB,UAAU,SAA0D;CAClF,MAAM,SAAS,KAAK,OAAO;CAC3B,OAAO;EACL,WAAW,OAAO,UACf,MAAM,OAAO,UAAU,EAAE,KAAK,CAAC,EAAA,CAAG,KAAK,UAAU;GAChD,GAAG;GACH,QAAQ,KAAK,WAAW,YAAY,KAAK,WAAW,YAAY,KAAK,SAAS;EAChF,EAAE;EACJ,UAAU;CACZ;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export { type Account, cloudflare_auth_d_exports as Auth, type Fetch, Interface, type ListZonesInput, type Options, type Zone, make };
|
|
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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
export { cloudflare_auth_exports as Auth, make };
|
|
1
|
+
import { i as cloudflare_auth_exports, n as discovery, r as make } from "./cloudflare-Bg_p-M2c.mjs";
|
|
2
|
+
export { cloudflare_auth_exports as Auth, discovery, make };
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,SAAS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