domainkit 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +213 -41
  2. package/dist/Approval.mjs +34 -0
  3. package/dist/Approval.mjs.map +1 -0
  4. package/dist/Cleanup.mjs +97 -0
  5. package/dist/Cleanup.mjs.map +1 -0
  6. package/dist/Cloudflare.mjs +225 -0
  7. package/dist/Cloudflare.mjs.map +1 -0
  8. package/dist/Connect.mjs +463 -0
  9. package/dist/Connect.mjs.map +1 -0
  10. package/dist/Custody.mjs +64 -0
  11. package/dist/Custody.mjs.map +1 -0
  12. package/dist/DnsRecord.mjs +213 -0
  13. package/dist/DnsRecord.mjs.map +1 -0
  14. package/dist/DomainKit.mjs +34 -0
  15. package/dist/DomainKit.mjs.map +1 -0
  16. package/dist/DomainName.mjs +100 -0
  17. package/dist/DomainName.mjs.map +1 -0
  18. package/dist/Plan.mjs +102 -0
  19. package/dist/Plan.mjs.map +1 -0
  20. package/dist/Principal.mjs +23 -0
  21. package/dist/Principal.mjs.map +1 -0
  22. package/dist/Provider.mjs +130 -0
  23. package/dist/Provider.mjs.map +1 -0
  24. package/dist/Providers.mjs +40 -0
  25. package/dist/Providers.mjs.map +1 -0
  26. package/dist/Provision.mjs +93 -0
  27. package/dist/Provision.mjs.map +1 -0
  28. package/dist/Reason.mjs +162 -0
  29. package/dist/Reason.mjs.map +1 -0
  30. package/dist/Receipt.mjs +71 -0
  31. package/dist/Receipt.mjs.map +1 -0
  32. package/dist/Resolver.mjs +75 -0
  33. package/dist/Resolver.mjs.map +1 -0
  34. package/dist/Server.mjs +516 -0
  35. package/dist/Server.mjs.map +1 -0
  36. package/dist/Storage.mjs +236 -0
  37. package/dist/Storage.mjs.map +1 -0
  38. package/dist/Testing.mjs +226 -0
  39. package/dist/Testing.mjs.map +1 -0
  40. package/dist/Transport.mjs +187 -0
  41. package/dist/Transport.mjs.map +1 -0
  42. package/dist/Vercel.mjs +116 -0
  43. package/dist/Vercel.mjs.map +1 -0
  44. package/dist/Verify.mjs +292 -0
  45. package/dist/Verify.mjs.map +1 -0
  46. package/dist/{rolldown-runtime-D7D4PA-g.mjs → _virtual/_rolldown/runtime.mjs} +1 -1
  47. package/dist/entry/client.mjs +2 -0
  48. package/dist/entry/server.mjs +2 -0
  49. package/dist/entry/testing.mjs +3 -0
  50. package/dist/index.mjs +33 -462
  51. package/dist/index.mjs.map +1 -1
  52. package/dist/internal/aes.mjs +61 -0
  53. package/dist/internal/aes.mjs.map +1 -0
  54. package/dist/internal/attempts.mjs +284 -0
  55. package/dist/internal/attempts.mjs.map +1 -0
  56. package/dist/internal/cloudflare/client.mjs +100 -0
  57. package/dist/internal/cloudflare/client.mjs.map +1 -0
  58. package/dist/internal/cloudflare/protocol.mjs +59 -0
  59. package/dist/internal/cloudflare/protocol.mjs.map +1 -0
  60. package/dist/internal/cloudflare/records.mjs +156 -0
  61. package/dist/internal/cloudflare/records.mjs.map +1 -0
  62. package/dist/internal/config.mjs +13 -0
  63. package/dist/internal/config.mjs.map +1 -0
  64. package/dist/internal/conformance/provider.mjs +207 -0
  65. package/dist/internal/conformance/provider.mjs.map +1 -0
  66. package/dist/internal/conformance/storage.mjs +428 -0
  67. package/dist/internal/conformance/storage.mjs.map +1 -0
  68. package/dist/internal/digest.mjs +25 -0
  69. package/dist/internal/digest.mjs.map +1 -0
  70. package/dist/internal/doh.mjs +152 -0
  71. package/dist/internal/doh.mjs.map +1 -0
  72. package/dist/internal/error.mjs +69 -0
  73. package/dist/internal/error.mjs.map +1 -0
  74. package/dist/internal/http.mjs +89 -0
  75. package/dist/internal/http.mjs.map +1 -0
  76. package/dist/internal/ids.mjs +8 -0
  77. package/dist/internal/ids.mjs.map +1 -0
  78. package/dist/internal/oauth.mjs +113 -0
  79. package/dist/internal/oauth.mjs.map +1 -0
  80. package/dist/internal/planner.mjs +88 -0
  81. package/dist/internal/planner.mjs.map +1 -0
  82. package/dist/internal/provider-async.mjs +83 -0
  83. package/dist/internal/provider-async.mjs.map +1 -0
  84. package/dist/internal/storage-memory.mjs +302 -0
  85. package/dist/internal/storage-memory.mjs.map +1 -0
  86. package/dist/internal/vercel/client.mjs +122 -0
  87. package/dist/internal/vercel/client.mjs.map +1 -0
  88. package/dist/internal/vercel/protocol.mjs +80 -0
  89. package/dist/internal/vercel/protocol.mjs.map +1 -0
  90. package/dist/internal/vercel/records.mjs +151 -0
  91. package/dist/internal/vercel/records.mjs.map +1 -0
  92. package/dist/package.mjs +6 -0
  93. package/dist/package.mjs.map +1 -0
  94. package/dist/types/Approval.d.ts +26 -0
  95. package/dist/types/Cleanup.d.ts +41 -0
  96. package/dist/types/Cloudflare.d.ts +36 -0
  97. package/dist/types/Connect.d.ts +506 -0
  98. package/dist/types/Custody.d.ts +38 -0
  99. package/dist/types/DnsRecord.d.ts +158 -0
  100. package/dist/types/DomainKit.d.ts +31 -0
  101. package/dist/types/DomainName.d.ts +27 -0
  102. package/dist/types/Plan.d.ts +76 -0
  103. package/dist/types/Principal.d.ts +18 -0
  104. package/dist/types/Provider.d.ts +248 -0
  105. package/dist/types/Providers.d.ts +16 -0
  106. package/dist/types/Provision.d.ts +75 -0
  107. package/dist/types/Reason.d.ts +118 -0
  108. package/dist/types/Receipt.d.ts +55 -0
  109. package/dist/types/Resolver.d.ts +135 -0
  110. package/dist/types/Server.d.ts +6523 -0
  111. package/dist/types/Storage.d.ts +314 -0
  112. package/dist/types/Testing.d.ts +84 -0
  113. package/dist/types/Transport.d.ts +124 -0
  114. package/dist/types/Vercel.d.ts +25 -0
  115. package/dist/types/Verify.d.ts +109 -0
  116. package/dist/types/entry/client.d.ts +2 -0
  117. package/dist/types/entry/server.d.ts +2 -0
  118. package/dist/types/entry/testing.d.ts +3 -0
  119. package/dist/types/index.d.ts +21 -0
  120. package/dist/types/internal/aes.d.ts +8 -0
  121. package/dist/types/internal/attempts.d.ts +40 -0
  122. package/dist/types/internal/cloudflare/client.d.ts +23 -0
  123. package/dist/types/internal/cloudflare/protocol.d.ts +71 -0
  124. package/dist/types/internal/cloudflare/records.d.ts +8 -0
  125. package/dist/types/internal/config.d.ts +4 -0
  126. package/dist/types/internal/conformance/provider.d.ts +12 -0
  127. package/dist/types/internal/conformance/storage.d.ts +14 -0
  128. package/dist/types/internal/digest.d.ts +10 -0
  129. package/dist/types/internal/doh.d.ts +19 -0
  130. package/dist/types/internal/error.d.ts +24 -0
  131. package/dist/types/internal/http.d.ts +27 -0
  132. package/dist/types/internal/ids.d.ts +3 -0
  133. package/dist/types/internal/oauth.d.ts +58 -0
  134. package/dist/types/internal/planner.d.ts +22 -0
  135. package/dist/types/internal/provider-async.d.ts +78 -0
  136. package/dist/types/internal/storage-memory.d.ts +2 -0
  137. package/dist/types/internal/vercel/client.d.ts +29 -0
  138. package/dist/types/internal/vercel/protocol.d.ts +124 -0
  139. package/dist/types/internal/vercel/records.d.ts +7 -0
  140. package/package.json +88 -12
  141. package/dist/canonical-json-CQYKsZw7.mjs +0 -310
  142. package/dist/canonical-json-CQYKsZw7.mjs.map +0 -1
  143. package/dist/connect-D-X8T9W8.d.mts +0 -1597
  144. package/dist/connect-oI8hcMxc.mjs +0 -185
  145. package/dist/connect-oI8hcMxc.mjs.map +0 -1
  146. package/dist/connection-Dp6ZdSo8.d.mts +0 -186
  147. package/dist/connection-api-lqG1nBtD.d.mts +0 -26
  148. package/dist/index.d.mts +0 -1551
  149. package/dist/managed-dns-connections-C3A_GBaz.mjs +0 -99
  150. package/dist/managed-dns-connections-C3A_GBaz.mjs.map +0 -1
  151. package/dist/promise.d.mts +0 -378
  152. package/dist/promise.mjs +0 -598
  153. package/dist/promise.mjs.map +0 -1
  154. package/dist/resolver-BeGz1ukw.mjs +0 -921
  155. package/dist/resolver-BeGz1ukw.mjs.map +0 -1
  156. package/dist/resolver-xoSwyXDJ.d.mts +0 -3734
  157. package/dist/server.d.mts +0 -128
  158. package/dist/server.mjs +0 -319
  159. package/dist/server.mjs.map +0 -1
  160. package/dist/testing.d.mts +0 -62
  161. package/dist/testing.mjs +0 -507
  162. package/dist/testing.mjs.map +0 -1
  163. package/dist/verify-DvGPb5C9.mjs +0 -2402
  164. package/dist/verify-DvGPb5C9.mjs.map +0 -1
  165. package/dist/verify-FpunAcM7.d.mts +0 -1335
@@ -0,0 +1,506 @@
1
+ /**
2
+ * Connect a provider, attach domains to it, and keep the credential alive. Interactive methods
3
+ * (OAuth, integration) return a redirect and complete on callback; token methods connect in one
4
+ * call. Reuse of an existing connection for a new domain is `attach`.
5
+ */
6
+ import { Context, Data, Effect, Layer, Redacted } from "effect";
7
+ import * as Custody from "./Custody.ts";
8
+ import * as Errors from "./internal/error.ts";
9
+ import * as Principal from "./Principal.ts";
10
+ import * as Provider from "./Provider.ts";
11
+ import * as Providers from "./Providers.ts";
12
+ import * as Resolver from "./Resolver.ts";
13
+ import * as Storage from "./Storage.ts";
14
+ type Fx<A> = Effect.Effect<A, Errors.DomainKitError, Principal.Service>;
15
+ export type Method = Data.TaggedEnum<{
16
+ /** Values keyed by the provider's declared `auth.token.fields`. */
17
+ Token: {
18
+ readonly values: Provider.TokenValues;
19
+ };
20
+ OAuth: {
21
+ readonly returnTo?: string;
22
+ };
23
+ Integration: {
24
+ readonly returnTo?: string;
25
+ };
26
+ }>;
27
+ /** `token` accepts a lone string (`{ token }`) or a record; every value is wrapped in `Redacted`. */
28
+ export declare const Method: {
29
+ readonly $is: <Tag extends "Integration" | "OAuth" | "Token">(tag: Tag) => (u: unknown) => u is Extract<{
30
+ readonly _tag: "Integration";
31
+ readonly returnTo?: string;
32
+ }, {
33
+ readonly _tag: Tag;
34
+ }> | Extract<{
35
+ readonly _tag: "OAuth";
36
+ readonly returnTo?: string;
37
+ }, {
38
+ readonly _tag: Tag;
39
+ }> | Extract<{
40
+ readonly _tag: "Token";
41
+ readonly values: Provider.TokenValues;
42
+ }, {
43
+ readonly _tag: Tag;
44
+ }>;
45
+ readonly $match: {
46
+ <Cases extends { readonly [Tag in "Integration" | "OAuth" | "Token"]: (args: Extract<{
47
+ readonly _tag: "Integration";
48
+ readonly returnTo?: string;
49
+ } | {
50
+ readonly _tag: "OAuth";
51
+ readonly returnTo?: string;
52
+ } | {
53
+ readonly _tag: "Token";
54
+ readonly values: Provider.TokenValues;
55
+ }, {
56
+ readonly _tag: Tag;
57
+ }>) => any; }>(cases: Cases): (value: {
58
+ readonly _tag: "Integration";
59
+ readonly returnTo?: string;
60
+ } | {
61
+ readonly _tag: "OAuth";
62
+ readonly returnTo?: string;
63
+ } | {
64
+ readonly _tag: "Token";
65
+ readonly values: Provider.TokenValues;
66
+ }) => import("effect/Unify").Unify<ReturnType<Cases["Integration" | "OAuth" | "Token"]>>;
67
+ <Cases extends { readonly [Tag in "Integration" | "OAuth" | "Token"]: (args: Extract<{
68
+ readonly _tag: "Integration";
69
+ readonly returnTo?: string;
70
+ } | {
71
+ readonly _tag: "OAuth";
72
+ readonly returnTo?: string;
73
+ } | {
74
+ readonly _tag: "Token";
75
+ readonly values: Provider.TokenValues;
76
+ }, {
77
+ readonly _tag: Tag;
78
+ }>) => any; }>(value: {
79
+ readonly _tag: "Integration";
80
+ readonly returnTo?: string;
81
+ } | {
82
+ readonly _tag: "OAuth";
83
+ readonly returnTo?: string;
84
+ } | {
85
+ readonly _tag: "Token";
86
+ readonly values: Provider.TokenValues;
87
+ }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Integration" | "OAuth" | "Token"]>>;
88
+ };
89
+ readonly token: (values: string | Readonly<Record<string, Redacted.Redacted<string> | string | undefined>>) => Method;
90
+ readonly oauth: (options?: {
91
+ readonly returnTo?: string;
92
+ }) => Method;
93
+ readonly integration: (options?: {
94
+ readonly returnTo?: string;
95
+ }) => Method;
96
+ readonly Integration: Data.TaggedEnum.ConstructorFrom<{
97
+ readonly _tag: "Integration";
98
+ readonly returnTo?: string;
99
+ }, "_tag">;
100
+ readonly OAuth: Data.TaggedEnum.ConstructorFrom<{
101
+ readonly _tag: "OAuth";
102
+ readonly returnTo?: string;
103
+ }, "_tag">;
104
+ readonly Token: Data.TaggedEnum.ConstructorFrom<{
105
+ readonly _tag: "Token";
106
+ readonly values: Provider.TokenValues;
107
+ }, "_tag">;
108
+ };
109
+ /** Everything the UI needs about a domain's provider state. */
110
+ export interface Snapshot {
111
+ readonly domain: string;
112
+ readonly attachment: Storage.Attachment | null;
113
+ readonly connection: Storage.Connection | null;
114
+ readonly authorization: Pick<Storage.Authorization, "id" | "provider" | "method" | "capabilities" | "revocation"> | null;
115
+ readonly lastReceiptId: string | null;
116
+ /** Other connections of this owner that could serve this domain. */
117
+ readonly reusable: ReadonlyArray<{
118
+ readonly connection: Storage.Connection;
119
+ readonly provider: string;
120
+ readonly method: Storage.AuthMethod;
121
+ }>;
122
+ readonly providers: ReadonlyArray<{
123
+ readonly id: string;
124
+ readonly name: string;
125
+ readonly methods: ReadonlyArray<Provider.MethodDescriptor>;
126
+ }>;
127
+ }
128
+ export type Started = Data.TaggedEnum<{
129
+ Connected: {
130
+ readonly connection: Storage.Connection;
131
+ readonly attachment: Storage.Attachment | null;
132
+ };
133
+ Redirect: {
134
+ readonly authorizationUrl: string;
135
+ readonly continuationId: string;
136
+ };
137
+ SelectionRequired: {
138
+ readonly connection: Storage.Connection;
139
+ readonly candidates: ReadonlyArray<Provider.Target>;
140
+ };
141
+ }>;
142
+ export declare const Started: {
143
+ readonly $is: <Tag extends "Connected" | "Redirect" | "SelectionRequired">(tag: Tag) => (u: unknown) => u is Extract<{
144
+ readonly _tag: "Connected";
145
+ readonly connection: Storage.Connection;
146
+ readonly attachment: Storage.Attachment | null;
147
+ }, {
148
+ readonly _tag: Tag;
149
+ }> | Extract<{
150
+ readonly _tag: "Redirect";
151
+ readonly authorizationUrl: string;
152
+ readonly continuationId: string;
153
+ }, {
154
+ readonly _tag: Tag;
155
+ }> | Extract<{
156
+ readonly _tag: "SelectionRequired";
157
+ readonly connection: Storage.Connection;
158
+ readonly candidates: ReadonlyArray<Provider.Target>;
159
+ }, {
160
+ readonly _tag: Tag;
161
+ }>;
162
+ readonly $match: {
163
+ <Cases extends { readonly [Tag in "Connected" | "Redirect" | "SelectionRequired"]: (args: Extract<{
164
+ readonly _tag: "Connected";
165
+ readonly connection: Storage.Connection;
166
+ readonly attachment: Storage.Attachment | null;
167
+ } | {
168
+ readonly _tag: "Redirect";
169
+ readonly authorizationUrl: string;
170
+ readonly continuationId: string;
171
+ } | {
172
+ readonly _tag: "SelectionRequired";
173
+ readonly connection: Storage.Connection;
174
+ readonly candidates: ReadonlyArray<Provider.Target>;
175
+ }, {
176
+ readonly _tag: Tag;
177
+ }>) => any; }>(cases: Cases): (value: {
178
+ readonly _tag: "Connected";
179
+ readonly connection: Storage.Connection;
180
+ readonly attachment: Storage.Attachment | null;
181
+ } | {
182
+ readonly _tag: "Redirect";
183
+ readonly authorizationUrl: string;
184
+ readonly continuationId: string;
185
+ } | {
186
+ readonly _tag: "SelectionRequired";
187
+ readonly connection: Storage.Connection;
188
+ readonly candidates: ReadonlyArray<Provider.Target>;
189
+ }) => import("effect/Unify").Unify<ReturnType<Cases["Connected" | "Redirect" | "SelectionRequired"]>>;
190
+ <Cases extends { readonly [Tag in "Connected" | "Redirect" | "SelectionRequired"]: (args: Extract<{
191
+ readonly _tag: "Connected";
192
+ readonly connection: Storage.Connection;
193
+ readonly attachment: Storage.Attachment | null;
194
+ } | {
195
+ readonly _tag: "Redirect";
196
+ readonly authorizationUrl: string;
197
+ readonly continuationId: string;
198
+ } | {
199
+ readonly _tag: "SelectionRequired";
200
+ readonly connection: Storage.Connection;
201
+ readonly candidates: ReadonlyArray<Provider.Target>;
202
+ }, {
203
+ readonly _tag: Tag;
204
+ }>) => any; }>(value: {
205
+ readonly _tag: "Connected";
206
+ readonly connection: Storage.Connection;
207
+ readonly attachment: Storage.Attachment | null;
208
+ } | {
209
+ readonly _tag: "Redirect";
210
+ readonly authorizationUrl: string;
211
+ readonly continuationId: string;
212
+ } | {
213
+ readonly _tag: "SelectionRequired";
214
+ readonly connection: Storage.Connection;
215
+ readonly candidates: ReadonlyArray<Provider.Target>;
216
+ }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Connected" | "Redirect" | "SelectionRequired"]>>;
217
+ };
218
+ readonly Connected: Data.TaggedEnum.ConstructorFrom<{
219
+ readonly _tag: "Connected";
220
+ readonly connection: Storage.Connection;
221
+ readonly attachment: Storage.Attachment | null;
222
+ }, "_tag">;
223
+ readonly Redirect: Data.TaggedEnum.ConstructorFrom<{
224
+ readonly _tag: "Redirect";
225
+ readonly authorizationUrl: string;
226
+ readonly continuationId: string;
227
+ }, "_tag">;
228
+ readonly SelectionRequired: Data.TaggedEnum.ConstructorFrom<{
229
+ readonly _tag: "SelectionRequired";
230
+ readonly connection: Storage.Connection;
231
+ readonly candidates: ReadonlyArray<Provider.Target>;
232
+ }, "_tag">;
233
+ };
234
+ /** `attach` either attached the domain or needs the caller to pick a zone. */
235
+ export type Selection = Data.TaggedEnum<{
236
+ SelectionRequired: {
237
+ readonly candidates: ReadonlyArray<Provider.Target>;
238
+ };
239
+ }>;
240
+ export declare const Selection: {
241
+ readonly $is: <Tag extends "SelectionRequired">(tag: Tag) => (u: unknown) => u is Extract<{
242
+ readonly _tag: "SelectionRequired";
243
+ readonly candidates: ReadonlyArray<Provider.Target>;
244
+ }, {
245
+ readonly _tag: Tag;
246
+ }>;
247
+ readonly $match: {
248
+ <Cases extends { readonly [Tag in "SelectionRequired"]: (args: Extract<{
249
+ readonly _tag: "SelectionRequired";
250
+ readonly candidates: ReadonlyArray<Provider.Target>;
251
+ }, {
252
+ readonly _tag: Tag;
253
+ }>) => any; }>(cases: Cases): (value: {
254
+ readonly _tag: "SelectionRequired";
255
+ readonly candidates: ReadonlyArray<Provider.Target>;
256
+ }) => import("effect/Unify").Unify<ReturnType<Cases["SelectionRequired"]>>;
257
+ <Cases extends { readonly [Tag in "SelectionRequired"]: (args: Extract<{
258
+ readonly _tag: "SelectionRequired";
259
+ readonly candidates: ReadonlyArray<Provider.Target>;
260
+ }, {
261
+ readonly _tag: Tag;
262
+ }>) => any; }>(value: {
263
+ readonly _tag: "SelectionRequired";
264
+ readonly candidates: ReadonlyArray<Provider.Target>;
265
+ }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["SelectionRequired"]>>;
266
+ };
267
+ readonly SelectionRequired: Data.TaggedEnum.ConstructorFrom<{
268
+ readonly _tag: "SelectionRequired";
269
+ readonly candidates: ReadonlyArray<Provider.Target>;
270
+ }, "_tag">;
271
+ };
272
+ export type Attached = Storage.Attachment | Selection;
273
+ export type Refreshed = "current" | "refreshed" | "reconnect";
274
+ /** Which of the principal's connections serves a domain, from nameserver evidence and zone lists. */
275
+ export type Discovery = Data.TaggedEnum<{
276
+ Resolved: {
277
+ readonly connectionId: string;
278
+ readonly target: Provider.Target;
279
+ };
280
+ SelectionRequired: {
281
+ readonly candidates: ReadonlyArray<{
282
+ readonly connectionId: string;
283
+ readonly target: Provider.Target;
284
+ }>;
285
+ };
286
+ NotFound: {
287
+ readonly nameservers: ReadonlyArray<string>;
288
+ };
289
+ }>;
290
+ export declare const Discovery: {
291
+ readonly $is: <Tag extends "NotFound" | "Resolved" | "SelectionRequired">(tag: Tag) => (u: unknown) => u is Extract<{
292
+ readonly _tag: "NotFound";
293
+ readonly nameservers: ReadonlyArray<string>;
294
+ }, {
295
+ readonly _tag: Tag;
296
+ }> | Extract<{
297
+ readonly _tag: "Resolved";
298
+ readonly connectionId: string;
299
+ readonly target: Provider.Target;
300
+ }, {
301
+ readonly _tag: Tag;
302
+ }> | Extract<{
303
+ readonly _tag: "SelectionRequired";
304
+ readonly candidates: ReadonlyArray<{
305
+ readonly connectionId: string;
306
+ readonly target: Provider.Target;
307
+ }>;
308
+ }, {
309
+ readonly _tag: Tag;
310
+ }>;
311
+ readonly $match: {
312
+ <Cases extends { readonly [Tag in "NotFound" | "Resolved" | "SelectionRequired"]: (args: Extract<{
313
+ readonly _tag: "NotFound";
314
+ readonly nameservers: ReadonlyArray<string>;
315
+ } | {
316
+ readonly _tag: "Resolved";
317
+ readonly connectionId: string;
318
+ readonly target: Provider.Target;
319
+ } | {
320
+ readonly _tag: "SelectionRequired";
321
+ readonly candidates: ReadonlyArray<{
322
+ readonly connectionId: string;
323
+ readonly target: Provider.Target;
324
+ }>;
325
+ }, {
326
+ readonly _tag: Tag;
327
+ }>) => any; }>(cases: Cases): (value: {
328
+ readonly _tag: "NotFound";
329
+ readonly nameservers: ReadonlyArray<string>;
330
+ } | {
331
+ readonly _tag: "Resolved";
332
+ readonly connectionId: string;
333
+ readonly target: Provider.Target;
334
+ } | {
335
+ readonly _tag: "SelectionRequired";
336
+ readonly candidates: ReadonlyArray<{
337
+ readonly connectionId: string;
338
+ readonly target: Provider.Target;
339
+ }>;
340
+ }) => import("effect/Unify").Unify<ReturnType<Cases["NotFound" | "Resolved" | "SelectionRequired"]>>;
341
+ <Cases extends { readonly [Tag in "NotFound" | "Resolved" | "SelectionRequired"]: (args: Extract<{
342
+ readonly _tag: "NotFound";
343
+ readonly nameservers: ReadonlyArray<string>;
344
+ } | {
345
+ readonly _tag: "Resolved";
346
+ readonly connectionId: string;
347
+ readonly target: Provider.Target;
348
+ } | {
349
+ readonly _tag: "SelectionRequired";
350
+ readonly candidates: ReadonlyArray<{
351
+ readonly connectionId: string;
352
+ readonly target: Provider.Target;
353
+ }>;
354
+ }, {
355
+ readonly _tag: Tag;
356
+ }>) => any; }>(value: {
357
+ readonly _tag: "NotFound";
358
+ readonly nameservers: ReadonlyArray<string>;
359
+ } | {
360
+ readonly _tag: "Resolved";
361
+ readonly connectionId: string;
362
+ readonly target: Provider.Target;
363
+ } | {
364
+ readonly _tag: "SelectionRequired";
365
+ readonly candidates: ReadonlyArray<{
366
+ readonly connectionId: string;
367
+ readonly target: Provider.Target;
368
+ }>;
369
+ }, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["NotFound" | "Resolved" | "SelectionRequired"]>>;
370
+ };
371
+ readonly NotFound: Data.TaggedEnum.ConstructorFrom<{
372
+ readonly _tag: "NotFound";
373
+ readonly nameservers: ReadonlyArray<string>;
374
+ }, "_tag">;
375
+ readonly Resolved: Data.TaggedEnum.ConstructorFrom<{
376
+ readonly _tag: "Resolved";
377
+ readonly connectionId: string;
378
+ readonly target: Provider.Target;
379
+ }, "_tag">;
380
+ readonly SelectionRequired: Data.TaggedEnum.ConstructorFrom<{
381
+ readonly _tag: "SelectionRequired";
382
+ readonly candidates: ReadonlyArray<{
383
+ readonly connectionId: string;
384
+ readonly target: Provider.Target;
385
+ }>;
386
+ }, "_tag">;
387
+ };
388
+ export interface Interface {
389
+ readonly inspect: (domain: string) => Fx<Snapshot>;
390
+ /**
391
+ * Resolve the domain's authoritative nameservers, then match them against the zones each of
392
+ * the principal's connections can reach: the closest zone wins, a decisive nameserver match
393
+ * breaks ties, and anything else needs a selection.
394
+ */
395
+ readonly discover: (domain: string) => Fx<Discovery>;
396
+ /** Connect a provider and, when `domain` is given, attach it. Token methods finish here. */
397
+ readonly start: (input: {
398
+ readonly provider: string;
399
+ readonly method: Method;
400
+ readonly domain?: string;
401
+ readonly callbackUrl?: string;
402
+ }) => Fx<Started>;
403
+ /** Finish an interactive connection from the provider callback (the full callback URL). */
404
+ readonly complete: (input: {
405
+ readonly continuationId: string;
406
+ readonly callbackUrl: string;
407
+ }) => Fx<Started>;
408
+ readonly attach: (input: {
409
+ readonly connectionId: string;
410
+ readonly domain: string;
411
+ readonly target?: Provider.Target;
412
+ }) => Fx<Attached>;
413
+ /** Records stay in DNS; DomainKit forgets the domain. Use `Cleanup` first to remove records. */
414
+ readonly detach: (attachmentId: string) => Fx<void>;
415
+ /** Detach every domain and revoke the credential at the provider when the method supports it. */
416
+ readonly disconnect: (connectionId: string) => Fx<void>;
417
+ /** Refresh a near-expiry credential, single-flighted. Called automatically before provider use. */
418
+ readonly refresh: (connectionId: string) => Fx<Refreshed>;
419
+ /** Live provider session for an attachment; used by Provision, Cleanup, Verify. */
420
+ readonly session: (attachmentId: string) => Fx<{
421
+ readonly session: Provider.Session;
422
+ readonly target: Provider.Target;
423
+ }>;
424
+ }
425
+ declare const Service_base: Context.ServiceClass<Service, "@domainkit/Connect", Interface>;
426
+ export declare class Service extends Service_base {
427
+ }
428
+ /** Which owner-scoped reuse is allowed. Default: any connection of the same owner may serve any of its domains. */
429
+ export interface PolicyShape {
430
+ readonly allowReuse: (input: {
431
+ readonly connection: Storage.Connection;
432
+ readonly domain: string;
433
+ }) => Effect.Effect<boolean, never, Principal.Service>;
434
+ /** Refresh this long before expiry. Default 10 minutes. */
435
+ readonly refreshBeforeMs: number;
436
+ /** Continuation lifetime. Default 15 minutes. */
437
+ readonly continuationTtlMs: number;
438
+ }
439
+ export declare const defaults: PolicyShape;
440
+ declare const Policy_base: Context.Reference<PolicyShape>;
441
+ export declare class Policy extends Policy_base {
442
+ }
443
+ export declare const make: Effect.Effect<Interface, never, Storage.Service | Custody.Service | Providers.Service | Resolver.Service>;
444
+ export declare const layer: Layer.Layer<Service, never, Storage.Service | Custody.Service | Providers.Service | Resolver.Service>;
445
+ export declare const inspect: (domain: string) => Effect.Effect<Snapshot, Errors.DomainKitError, Principal.Service | Service>;
446
+ export declare const discover: (domain: string) => Effect.Effect<{
447
+ readonly _tag: "NotFound";
448
+ readonly nameservers: ReadonlyArray<string>;
449
+ } | {
450
+ readonly _tag: "Resolved";
451
+ readonly connectionId: string;
452
+ readonly target: Provider.Target;
453
+ } | {
454
+ readonly _tag: "SelectionRequired";
455
+ readonly candidates: ReadonlyArray<{
456
+ readonly connectionId: string;
457
+ readonly target: Provider.Target;
458
+ }>;
459
+ }, Errors.DomainKitError, Principal.Service | Service>;
460
+ export declare const start: (input: {
461
+ readonly provider: string;
462
+ readonly method: Method;
463
+ readonly domain?: string;
464
+ readonly callbackUrl?: string;
465
+ }) => Effect.Effect<{
466
+ readonly _tag: "Connected";
467
+ readonly connection: Storage.Connection;
468
+ readonly attachment: Storage.Attachment | null;
469
+ } | {
470
+ readonly _tag: "Redirect";
471
+ readonly authorizationUrl: string;
472
+ readonly continuationId: string;
473
+ } | {
474
+ readonly _tag: "SelectionRequired";
475
+ readonly connection: Storage.Connection;
476
+ readonly candidates: ReadonlyArray<Provider.Target>;
477
+ }, Errors.DomainKitError, Principal.Service | Service>;
478
+ export declare const complete: (input: {
479
+ readonly continuationId: string;
480
+ readonly callbackUrl: string;
481
+ }) => Effect.Effect<{
482
+ readonly _tag: "Connected";
483
+ readonly connection: Storage.Connection;
484
+ readonly attachment: Storage.Attachment | null;
485
+ } | {
486
+ readonly _tag: "Redirect";
487
+ readonly authorizationUrl: string;
488
+ readonly continuationId: string;
489
+ } | {
490
+ readonly _tag: "SelectionRequired";
491
+ readonly connection: Storage.Connection;
492
+ readonly candidates: ReadonlyArray<Provider.Target>;
493
+ }, Errors.DomainKitError, Principal.Service | Service>;
494
+ export declare const attach: (input: {
495
+ readonly connectionId: string;
496
+ readonly domain: string;
497
+ readonly target?: Provider.Target;
498
+ }) => Effect.Effect<Attached, Errors.DomainKitError, Principal.Service | Service>;
499
+ export declare const detach: (attachmentId: string) => Effect.Effect<void, Errors.DomainKitError, Principal.Service | Service>;
500
+ export declare const disconnect: (connectionId: string) => Effect.Effect<void, Errors.DomainKitError, Principal.Service | Service>;
501
+ export declare const refresh: (connectionId: string) => Effect.Effect<Refreshed, Errors.DomainKitError, Principal.Service | Service>;
502
+ export declare const session: (attachmentId: string) => Effect.Effect<{
503
+ readonly session: Provider.Session;
504
+ readonly target: Provider.Target;
505
+ }, Errors.DomainKitError, Principal.Service | Service>;
506
+ export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Seals provider credentials before Storage writes them. The default is AES-256-GCM through
3
+ * WebCrypto from one configured key; hosts with a KMS provide their own. There is no plaintext
4
+ * mode.
5
+ *
6
+ * Envelope format: `v1.<iv>.<ciphertext>` with base64url segments and a 12-byte IV. Rotating
7
+ * the key requires re-sealing stored credentials; `open` fails with `CryptoFailed` on a mismatch.
8
+ */
9
+ import { Config, Context, Effect, Layer, Redacted } from "effect";
10
+ import * as Errors from "./internal/error.ts";
11
+ import * as Aes from "./internal/aes.ts";
12
+ export interface Interface {
13
+ readonly seal: (plaintext: Redacted.Redacted<string>) => Effect.Effect<string, Errors.DomainKitError>;
14
+ readonly open: (ciphertext: string) => Effect.Effect<Redacted.Redacted<string>, Errors.DomainKitError>;
15
+ }
16
+ declare const Service_base: Context.ServiceClass<Service, "@domainkit/Custody", Interface>;
17
+ export declare class Service extends Service_base {
18
+ }
19
+ export interface Options {
20
+ /** 32 bytes, base64 or hex. Rotating it requires re-sealing stored credentials. */
21
+ readonly key: Redacted.Redacted<string>;
22
+ }
23
+ export declare const make: (options: Options) => Effect.Effect<Interface, Errors.DomainKitError>;
24
+ export declare const layer: (options: Options) => Layer.Layer<Service, Errors.DomainKitError>;
25
+ /** Same options, each field a `Config`. Defaults to `DOMAINKIT_CUSTODY_KEY`. */
26
+ export declare const layerConfig: (options?: {
27
+ readonly key?: Config.Config<Redacted.Redacted<string>>;
28
+ }) => Layer.Layer<Service, Errors.DomainKitError>;
29
+ /** A fresh random key in the accepted encoding; for tests, playgrounds, and first-time setup. */
30
+ export declare const generateKey: typeof Aes.generateKey;
31
+ export interface AsyncInterface {
32
+ readonly seal: (plaintext: string) => Promise<string>;
33
+ readonly open: (ciphertext: string) => Promise<string>;
34
+ }
35
+ /** Wrap a Promise-shaped KMS client; rejections become `CryptoFailed`. */
36
+ export declare const fromAsync: (service: AsyncInterface) => Interface;
37
+ export declare const layerFromAsync: (service: AsyncInterface) => Layer.Layer<Service>;
38
+ export {};