@@ -8,23 +8,32 @@ import {
8
8
WithinRangeInteger ,
9
9
} from '@pagopa/ts-commons/lib/numbers' ;
10
10
11
+ type OnOrOff = 'on' | 'off' ;
12
+
13
+ interface ActiveConsumer {
14
+ readonly consumer : Extract < OnOrOff , 'on' > ;
15
+ readonly connectionString : string ;
16
+ }
17
+ interface InactiveConsumer {
18
+ readonly consumer : Extract < OnOrOff , 'off' > ;
19
+ }
20
+ type Consumer = ActiveConsumer | InactiveConsumer ;
21
+
22
+ const OnOrOffCodec = t . keyof < {
23
+ readonly [ K in OnOrOff ] : unknown ;
24
+ } > ( {
25
+ on : null ,
26
+ off : null ,
27
+ } ) ;
28
+
11
29
export interface Config {
12
- readonly subscriptionHistory : {
13
- readonly consumer : 'on' | 'off' ;
14
- } ;
15
- readonly subscriptionRequest : {
16
- readonly consumer : 'on' | 'off' ;
17
- } ;
18
- readonly activations : {
19
- readonly consumer : 'on' | 'off' ;
20
- readonly maxFetchSize : number ;
21
- } ;
30
+ readonly subscriptionHistory : Consumer ;
31
+ readonly subscriptionRequest : Consumer ;
32
+ readonly activations : Consumer & { readonly maxFetchSize : number } ;
22
33
readonly events : {
23
- readonly producer : 'on' | 'off' ;
24
- } ;
25
- readonly trials : {
26
- readonly consumer : 'on' | 'off' ;
34
+ readonly producer : OnOrOff ;
27
35
} ;
36
+ readonly trials : Consumer ;
28
37
readonly servicebus : {
29
38
readonly namespace : string ;
30
39
readonly names : {
@@ -54,12 +63,7 @@ export interface Config {
54
63
} ;
55
64
}
56
65
57
- const OnOrOffCodec = t . keyof ( {
58
- on : null ,
59
- off : null ,
60
- } ) ;
61
-
62
- const EnvsCodec = t . strict ( {
66
+ const EnvsCodec = t . type ( {
63
67
COSMOSDB_ENDPOINT : NonEmptyString ,
64
68
COSMOSDB_DATABASE_NAME : NonEmptyString ,
65
69
EVENTHUB_NAMESPACE : NonEmptyString ,
@@ -79,6 +83,14 @@ const EnvsCodec = t.strict({
79
83
SUBSCRIPTION_ID : NonEmptyString ,
80
84
SERVICE_BUS_RESOURCE_GROUP_NAME : NonEmptyString ,
81
85
SERVICE_BUS_LOCATION : NonEmptyString ,
86
+ SubscriptionHistoryCosmosConnection : t . union ( [ NonEmptyString , t . undefined ] ) ,
87
+ SubscriptionHistoryCosmosConnection__accountName : NonEmptyString ,
88
+ ActivationConsumerCosmosDBConnection : t . union ( [ NonEmptyString , t . undefined ] ) ,
89
+ ActivationConsumerCosmosDBConnection__accountEndpoint : NonEmptyString ,
90
+ SubscriptionRequestEventHubConnection : t . union ( [ NonEmptyString , t . undefined ] ) ,
91
+ SubscriptionRequestEventHubConnection__accountName : NonEmptyString ,
92
+ TrialsCosmosConnection : t . union ( [ NonEmptyString , t . undefined ] ) ,
93
+ TrialsCosmosConnection__accountEndpoint : NonEmptyString ,
82
94
} ) ;
83
95
84
96
export const parseConfig = (
@@ -91,19 +103,31 @@ export const parseConfig = (
91
103
( envs ) => ( {
92
104
subscriptionHistory : {
93
105
consumer : envs . SUBSCRIPTION_HISTORY_CONSUMER ,
106
+ connectionString :
107
+ envs . SubscriptionHistoryCosmosConnection ||
108
+ envs . SubscriptionHistoryCosmosConnection__accountName ,
94
109
} ,
95
110
subscriptionRequest : {
96
- consumer : envs . SUBSCRIPTION_REQUEST_CONSUMER ,
111
+ consumer : envs . SUBSCRIPTION_HISTORY_CONSUMER ,
112
+ connectionString :
113
+ envs . SubscriptionRequestEventHubConnection ||
114
+ envs . SubscriptionRequestEventHubConnection__accountName ,
97
115
} ,
98
116
activations : {
99
- consumer : envs . ACTIVATION_CONSUMER ,
117
+ consumer : envs . SUBSCRIPTION_HISTORY_CONSUMER ,
118
+ connectionString :
119
+ envs . ActivationConsumerCosmosDBConnection ||
120
+ envs . ActivationConsumerCosmosDBConnection__accountEndpoint ,
100
121
maxFetchSize : envs . ACTIVATION_MAX_FETCH_SIZE ,
101
122
} ,
102
123
events : {
103
124
producer : envs . EVENTS_PRODUCER ,
104
125
} ,
105
126
trials : {
106
- consumer : envs . TRIAL_CONSUMER ,
127
+ consumer : envs . SUBSCRIPTION_HISTORY_CONSUMER ,
128
+ connectionString :
129
+ envs . TrialsCosmosConnection ||
130
+ envs . TrialsCosmosConnection__accountEndpoint ,
107
131
} ,
108
132
servicebus : {
109
133
namespace : envs . SERVICEBUS_NAMESPACE ,
0 commit comments