@@ -5,13 +5,18 @@ import { Service, Worker_Binding } from "../../runtime";
55import {
66getUserBindingServiceName ,
77Plugin ,
8+ remoteProxyClientWorker ,
9+ RemoteProxyConnectionString ,
810WORKER_BINDING_SERVICE_LOOPBACK ,
911} from "../shared" ;
1012
1113// Define the mutually exclusive schema
1214const EmailBindingOptionsSchema = z
1315. object ( {
1416name : z . string ( ) ,
17+ remoteProxyConnectionString : z
18+ . custom < RemoteProxyConnectionString > ( )
19+ . optional ( ) ,
1520} )
1621. and (
1722z . union ( [
@@ -53,10 +58,12 @@ export const EMAIL_PLUGIN: Plugin<typeof EmailOptionsSchema> = {
5358
5459const sendEmailBindings = options . email . send_email ;
5560
56- return sendEmailBindings . map ( ( { name } ) => ( {
61+ return sendEmailBindings . map ( ( { name, remoteProxyConnectionString } ) => ( {
5762name,
5863service : {
59- entrypoint : "SendEmailBinding" ,
64+ entrypoint : remoteProxyConnectionString
65+ ? undefined
66+ : "SendEmailBinding" ,
6067name : getUserBindingServiceName ( SERVICE_SEND_EMAIL_WORKER_PREFIX , name ) ,
6168} ,
6269} ) ) ;
@@ -67,22 +74,25 @@ export const EMAIL_PLUGIN: Plugin<typeof EmailOptionsSchema> = {
6774async getServices ( args ) {
6875const services : Service [ ] = [ ] ;
6976
70- for ( const { name, ...config } of args . options . email ?. send_email ?? [ ] ) {
77+ for ( const { name, remoteProxyConnectionString, ...config } of args . options
78+ . email ?. send_email ?? [ ] ) {
7179services . push ( {
7280name : getUserBindingServiceName ( SERVICE_SEND_EMAIL_WORKER_PREFIX , name ) ,
73- worker : {
74- compatibilityDate : "2025-03-17" ,
75- modules : [
76- {
77- name : "send_email.mjs" ,
78- esModule : SEND_EMAIL_BINDING ( ) ,
81+ worker : remoteProxyConnectionString
82+ ? remoteProxyClientWorker ( remoteProxyConnectionString , name )
83+ : {
84+ compatibilityDate : "2025-03-17" ,
85+ modules : [
86+ {
87+ name : "send_email.mjs" ,
88+ esModule : SEND_EMAIL_BINDING ( ) ,
89+ } ,
90+ ] ,
91+ bindings : [
92+ ...buildJsonBindings ( config ) ,
93+ WORKER_BINDING_SERVICE_LOOPBACK ,
94+ ] ,
7995} ,
80- ] ,
81- bindings : [
82- ...buildJsonBindings ( config ) ,
83- WORKER_BINDING_SERVICE_LOOPBACK ,
84- ] ,
85- } ,
8696} ) ;
8797}
8898
0 commit comments