| ... | ... | @@ -192,11 +192,8 @@ export class ManagedEndpointTunnelClient extends Context.Service< |
| 192 | 192 | } |
| 193 | 193 | >()("t3code-relay/environments/ManagedEndpointProvider/ManagedEndpointTunnelClient") {} |
| 194 | 194 | |
| 195 | | export const makeTunnelClient = (client: ManagedEndpointTunnelClient["Service"]) => |
| 196 | | ManagedEndpointTunnelClient.of(client); |
| 197 | | |
| 198 | 195 | export const layerTunnelClient = (client: ManagedEndpointTunnelClient["Service"]) => |
| 199 | | Layer.succeed(ManagedEndpointTunnelClient, makeTunnelClient(client)); |
| 196 | Layer.succeed(ManagedEndpointTunnelClient, client); |
| 200 | 197 | |
| 201 | 198 | interface ManagedEndpointCnameRecordInput { |
| 202 | 199 | readonly type: "CNAME"; |
| ... | ... | @@ -247,11 +244,8 @@ export class ManagedEndpointDnsClient extends Context.Service< |
| 247 | 244 | } |
| 248 | 245 | >()("t3code-relay/environments/ManagedEndpointProvider/ManagedEndpointDnsClient") {} |
| 249 | 246 | |
| 250 | | export const makeDnsClient = (client: ManagedEndpointDnsClient["Service"]) => |
| 251 | | ManagedEndpointDnsClient.of(client); |
| 252 | | |
| 253 | 247 | export const layerDnsClient = (client: ManagedEndpointDnsClient["Service"]) => |
| 254 | | Layer.succeed(ManagedEndpointDnsClient, makeDnsClient(client)); |
| 248 | Layer.succeed(ManagedEndpointDnsClient, client); |
| 255 | 249 | |
| 256 | 250 | const requireCloudflareSettings = Effect.fnUntraced(function* ( |
| 257 | 251 | settings: RelayConfiguration.RelayConfiguration["Service"], |
| ... | ... | @@ -331,7 +325,7 @@ const ignoreNotFound = <A>( |
| 331 | 325 | }), |
| 332 | 326 | ); |
| 333 | 327 | |
| 334 | | const make = Effect.gen(function* () { |
| 328 | export const make = Effect.gen(function* () { |
| 335 | 329 | const config = yield* RelayConfiguration.RelayConfiguration; |
| 336 | 330 | const crypto = yield* Crypto.Crypto; |
| 337 | 331 | const tunnels = yield* ManagedEndpointTunnelClient; |
| ... | ... | @@ -366,7 +360,10 @@ const make = Effect.gen(function* () { |
| 366 | 360 | .updateRecord(preferredDnsRecordId, dnsRecord) |
| 367 | 361 | .pipe( |
| 368 | 362 | Effect.as(true), |
| 369 | | Effect.orElseSucceed(() => false), |
| 363 | Effect.catchTags({ |
| 364 | ManagedEndpointDnsClientError: (error) => |
| 365 | isNotFoundCause(error.cause) ? Effect.succeed(false) : Effect.fail(error), |
| 366 | }), |
| 370 | 367 | ); |
| 371 | 368 | if (checkpointedRecordUpdated) { |
| 372 | 369 | return preferredDnsRecordId; |
| ... | ... | @@ -550,7 +547,7 @@ const make = Effect.gen(function* () { |
| 550 | 547 | }), |
| 551 | 548 | ), |
| 552 | 549 | ); |
| 553 | | if (!tunnelResponse.id || !tunnelResponse.name) { |
| 550 | if (!tunnelResponse.id || tunnelResponse.name !== tunnelName) { |
| 554 | 551 | return yield* new ManagedEndpointProvisioningFailed({ |
| 555 | 552 | userId: input.userId, |
| 556 | 553 | environmentId: input.environmentId, |
| ... | ... | @@ -712,131 +709,127 @@ export const layerCloudflareBindings = ( |
| 712 | 709 | layer.pipe( |
| 713 | 710 | Layer.provide( |
| 714 | 711 | Layer.mergeAll( |
| 715 | | layerTunnelClient( |
| 716 | | ManagedEndpointTunnelClient.of({ |
| 717 | | list: (request) => |
| 718 | | tunnelClient.list(request).pipe( |
| 719 | | Effect.mapError( |
| 720 | | (cause) => |
| 721 | | new ManagedEndpointTunnelClientError({ |
| 722 | | operation: "list", |
| 723 | | tunnelName: request.name, |
| 724 | | cause, |
| 725 | | }), |
| 726 | | ), |
| 727 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 712 | layerTunnelClient({ |
| 713 | list: (request) => |
| 714 | tunnelClient.list(request).pipe( |
| 715 | Effect.mapError( |
| 716 | (cause) => |
| 717 | new ManagedEndpointTunnelClientError({ |
| 718 | operation: "list", |
| 719 | tunnelName: request.name, |
| 720 | cause, |
| 721 | }), |
| 728 | 722 | ), |
| 729 | | create: (request) => |
| 730 | | tunnelClient.create(request).pipe( |
| 731 | | Effect.mapError( |
| 732 | | (cause) => |
| 733 | | new ManagedEndpointTunnelClientError({ |
| 734 | | operation: "create", |
| 735 | | tunnelName: request.name, |
| 736 | | cause, |
| 737 | | }), |
| 738 | | ), |
| 739 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 723 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 724 | ), |
| 725 | create: (request) => |
| 726 | tunnelClient.create(request).pipe( |
| 727 | Effect.mapError( |
| 728 | (cause) => |
| 729 | new ManagedEndpointTunnelClientError({ |
| 730 | operation: "create", |
| 731 | tunnelName: request.name, |
| 732 | cause, |
| 733 | }), |
| 740 | 734 | ), |
| 741 | | putConfiguration: (tunnelId, config) => |
| 742 | | tunnelClient.putConfiguration(tunnelId, config).pipe( |
| 743 | | Effect.mapError( |
| 744 | | (cause) => |
| 745 | | new ManagedEndpointTunnelClientError({ |
| 746 | | operation: "put-configuration", |
| 747 | | tunnelId, |
| 748 | | cause, |
| 749 | | }), |
| 750 | | ), |
| 751 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 735 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 736 | ), |
| 737 | putConfiguration: (tunnelId, config) => |
| 738 | tunnelClient.putConfiguration(tunnelId, config).pipe( |
| 739 | Effect.mapError( |
| 740 | (cause) => |
| 741 | new ManagedEndpointTunnelClientError({ |
| 742 | operation: "put-configuration", |
| 743 | tunnelId, |
| 744 | cause, |
| 745 | }), |
| 752 | 746 | ), |
| 753 | | getToken: (tunnelId) => |
| 754 | | tunnelClient.getToken(tunnelId).pipe( |
| 755 | | Effect.mapError( |
| 756 | | (cause) => |
| 757 | | new ManagedEndpointTunnelClientError({ |
| 758 | | operation: "get-token", |
| 759 | | tunnelId, |
| 760 | | cause, |
| 761 | | }), |
| 762 | | ), |
| 763 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 747 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 748 | ), |
| 749 | getToken: (tunnelId) => |
| 750 | tunnelClient.getToken(tunnelId).pipe( |
| 751 | Effect.mapError( |
| 752 | (cause) => |
| 753 | new ManagedEndpointTunnelClientError({ |
| 754 | operation: "get-token", |
| 755 | tunnelId, |
| 756 | cause, |
| 757 | }), |
| 764 | 758 | ), |
| 765 | | delete: (tunnelId) => |
| 766 | | tunnelClient.delete(tunnelId).pipe( |
| 767 | | Effect.mapError( |
| 768 | | (cause) => |
| 769 | | new ManagedEndpointTunnelClientError({ |
| 770 | | operation: "delete", |
| 771 | | tunnelId, |
| 772 | | cause, |
| 773 | | }), |
| 774 | | ), |
| 775 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 759 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 760 | ), |
| 761 | delete: (tunnelId) => |
| 762 | tunnelClient.delete(tunnelId).pipe( |
| 763 | Effect.mapError( |
| 764 | (cause) => |
| 765 | new ManagedEndpointTunnelClientError({ |
| 766 | operation: "delete", |
| 767 | tunnelId, |
| 768 | cause, |
| 769 | }), |
| 776 | 770 | ), |
| 777 | | }), |
| 778 | | ), |
| 779 | | layerDnsClient( |
| 780 | | ManagedEndpointDnsClient.of({ |
| 781 | | listRecords: (hostname) => |
| 782 | | dnsClient.listDnsRecords({ search: hostname }).pipe( |
| 783 | | Effect.map((response) => |
| 784 | | response.result.filter( |
| 785 | | (record): record is typeof record & { readonly id: string } => |
| 786 | | typeof record.id === "string" && |
| 787 | | normalizeHostname(record.name) === normalizeHostname(hostname), |
| 788 | | ), |
| 789 | | ), |
| 790 | | Effect.mapError( |
| 791 | | (cause) => |
| 792 | | new ManagedEndpointDnsClientError({ |
| 793 | | operation: "list-records", |
| 794 | | hostname, |
| 795 | | cause, |
| 796 | | }), |
| 771 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 772 | ), |
| 773 | }), |
| 774 | layerDnsClient({ |
| 775 | listRecords: (hostname) => |
| 776 | dnsClient.listDnsRecords({ search: hostname }).pipe( |
| 777 | Effect.map((response) => |
| 778 | response.result.filter( |
| 779 | (record): record is typeof record & { readonly id: string } => |
| 780 | typeof record.id === "string" && |
| 781 | normalizeHostname(record.name) === normalizeHostname(hostname), |
| 797 | 782 | ), |
| 798 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 799 | 783 | ), |
| 800 | | createRecord: (request) => |
| 801 | | dnsClient.createDnsRecord(request).pipe( |
| 802 | | Effect.map((response) => ({ id: response.id })), |
| 803 | | Effect.mapError( |
| 804 | | (cause) => |
| 805 | | new ManagedEndpointDnsClientError({ |
| 806 | | operation: "create-record", |
| 807 | | hostname: request.name, |
| 808 | | cause, |
| 809 | | }), |
| 810 | | ), |
| 811 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 784 | Effect.mapError( |
| 785 | (cause) => |
| 786 | new ManagedEndpointDnsClientError({ |
| 787 | operation: "list-records", |
| 788 | hostname, |
| 789 | cause, |
| 790 | }), |
| 812 | 791 | ), |
| 813 | | updateRecord: (dnsRecordId, request) => |
| 814 | | dnsClient.updateDnsRecord(dnsRecordId, request).pipe( |
| 815 | | Effect.mapError( |
| 816 | | (cause) => |
| 817 | | new ManagedEndpointDnsClientError({ |
| 818 | | operation: "update-record", |
| 819 | | hostname: request.name, |
| 820 | | dnsRecordId, |
| 821 | | cause, |
| 822 | | }), |
| 823 | | ), |
| 824 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 792 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 793 | ), |
| 794 | createRecord: (request) => |
| 795 | dnsClient.createDnsRecord(request).pipe( |
| 796 | Effect.map((response) => ({ id: response.id })), |
| 797 | Effect.mapError( |
| 798 | (cause) => |
| 799 | new ManagedEndpointDnsClientError({ |
| 800 | operation: "create-record", |
| 801 | hostname: request.name, |
| 802 | cause, |
| 803 | }), |
| 825 | 804 | ), |
| 826 | | deleteRecord: (dnsRecordId) => |
| 827 | | dnsClient.deleteDnsRecord(dnsRecordId).pipe( |
| 828 | | Effect.mapError( |
| 829 | | (cause) => |
| 830 | | new ManagedEndpointDnsClientError({ |
| 831 | | operation: "delete-record", |
| 832 | | dnsRecordId, |
| 833 | | cause, |
| 834 | | }), |
| 835 | | ), |
| 836 | | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 805 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 806 | ), |
| 807 | updateRecord: (dnsRecordId, request) => |
| 808 | dnsClient.updateDnsRecord(dnsRecordId, request).pipe( |
| 809 | Effect.mapError( |
| 810 | (cause) => |
| 811 | new ManagedEndpointDnsClientError({ |
| 812 | operation: "update-record", |
| 813 | hostname: request.name, |
| 814 | dnsRecordId, |
| 815 | cause, |
| 816 | }), |
| 837 | 817 | ), |
| 838 | | }), |
| 839 | | ), |
| 818 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 819 | ), |
| 820 | deleteRecord: (dnsRecordId) => |
| 821 | dnsClient.deleteDnsRecord(dnsRecordId).pipe( |
| 822 | Effect.mapError( |
| 823 | (cause) => |
| 824 | new ManagedEndpointDnsClientError({ |
| 825 | operation: "delete-record", |
| 826 | dnsRecordId, |
| 827 | cause, |
| 828 | }), |
| 829 | ), |
| 830 | Effect.provideService(Alchemy.RuntimeContext, alchemyRuntimeContext), |
| 831 | ), |
| 832 | }), |
| 840 | 833 | ), |
| 841 | 834 | ), |
| 842 | 835 | ); |