@@ -16,13 +16,14 @@ import {
1616import { type HttpAuthMiddleware , Video } from "@cap/web-domain" ;
1717import {
1818 FetchHttpClient ,
19+ Headers ,
1920 type HttpApi ,
2021 HttpApiBuilder ,
2122 HttpApiClient ,
2223 HttpMiddleware ,
2324 HttpServer ,
2425} from "@effect/platform" ;
25- import { RpcClient } from "@effect/rpc" ;
26+ import { RpcClient , RpcMessage , RpcMiddleware } from "@effect/rpc" ;
2627import {
2728 Cause ,
2829 Config ,
@@ -31,6 +32,7 @@ import {
3132 Layer ,
3233 ManagedRuntime ,
3334 Option ,
35+ Redacted ,
3436} from "effect" ;
3537import { cookies } from "next/headers" ;
3638
@@ -50,11 +52,21 @@ const CookiePasswordAttachmentLive = Layer.effect(
5052 } ) ,
5153) ;
5254
55+ class WorkflowRpcSecret extends Effect . Service < WorkflowRpcSecret > ( ) (
56+ "WorkflowRpcSecret" ,
57+ {
58+ effect : Effect . map (
59+ Config . redacted ( Config . string ( "WORKFLOWS_RPC_SECRET" ) ) ,
60+ ( v ) => ( { authSecret : v } ) ,
61+ ) ,
62+ } ,
63+ ) { }
64+
5365const WorkflowRpcLive = Layer . scoped (
5466 Workflows . RpcClient ,
5567 Effect . gen ( function * ( ) {
5668 const url = Option . getOrElse (
57- yield * Config . option ( Config . string ( "REMOTE_WORKFLOW_URL " ) ) ,
69+ yield * Config . option ( Config . string ( "WORKFLOWS_RPC_URL " ) ) ,
5870 ( ) => "http://127.0.0.1:42169" ,
5971 ) ;
6072
@@ -66,6 +78,22 @@ const WorkflowRpcLive = Layer.scoped(
6678 ) ,
6779 ) ;
6880 } ) ,
81+ ) . pipe (
82+ Layer . provide (
83+ RpcMiddleware . layerClient ( Workflows . SecretAuthMiddleware , ( { request } ) =>
84+ Effect . gen ( function * ( ) {
85+ const { authSecret } = yield * WorkflowRpcSecret ;
86+ return {
87+ ...request ,
88+ headers : Headers . set (
89+ request . headers ,
90+ "authorization" ,
91+ Redacted . value ( authSecret ) ,
92+ ) ,
93+ } ;
94+ } ) ,
95+ ) ,
96+ ) ,
6997) ;
7098
7199export const Dependencies = Layer . mergeAll (
@@ -79,7 +107,13 @@ export const Dependencies = Layer.mergeAll(
79107 WorkflowRpcLive ,
80108 layerTracer ,
81109) . pipe (
82- Layer . provideMerge ( Layer . mergeAll ( Database . Default , FetchHttpClient . layer ) ) ,
110+ Layer . provideMerge (
111+ Layer . mergeAll (
112+ Database . Default ,
113+ FetchHttpClient . layer ,
114+ WorkflowRpcSecret . Default ,
115+ ) ,
116+ ) ,
83117) ;
84118
85119// purposefully not exposed
@@ -132,6 +166,7 @@ export const apiToHandler = (
132166 Layer . provide (
133167 HttpApiBuilder . middleware ( Effect . provide ( CookiePasswordAttachmentLive ) ) ,
134168 ) ,
169+ Layer . provide ( layerTracer ) ,
135170 Layer . provideMerge ( Dependencies ) ,
136171 HttpApiBuilder . toWebHandler ,
137172 ( v ) => ( req : Request ) => v . handler ( req ) ,
0 commit comments