@@ -23,6 +23,10 @@ import { createUcantoServer } from '../service.js'
23
23
import { Config } from 'sst/node/config'
24
24
import { CAR , Legacy , Codec } from '@ucanto/transport'
25
25
import { Email } from '../email.js'
26
+ import { createTasksStorage } from '../stores/tasks.js'
27
+ import { createReceiptsStorage } from '../stores/receipts.js'
28
+ import { createAllocationsStorage } from '../stores/allocations.js'
29
+ import { createBlobsStorage , composeblobStoragesWithOrderedHas } from '../stores/blobs.js'
26
30
import { useProvisionStore } from '../stores/provisions.js'
27
31
import { useSubscriptionsStore } from '../stores/subscriptions.js'
28
32
import { createDelegationsTable } from '../tables/delegations.js'
@@ -39,6 +43,7 @@ import { createSpaceDiffStore } from '@web3-storage/w3infra-billing/tables/space
39
43
import { createSpaceSnapshotStore } from '@web3-storage/w3infra-billing/tables/space-snapshot.js'
40
44
import { useUsageStore } from '../stores/usage.js'
41
45
import { createStripeBillingProvider } from '../billing.js'
46
+ import { createTasksScheduler } from '../scheduler.js'
42
47
43
48
Sentry . AWSLambda . init ( {
44
49
environment : process . env . SST_STAGE ,
@@ -99,6 +104,7 @@ export async function ucanInvocationRouter(request) {
99
104
storeTableName,
100
105
storeBucketName,
101
106
uploadTableName,
107
+ allocationTableName,
102
108
consumerTableName,
103
109
customerTableName,
104
110
subscriptionTableName,
@@ -122,6 +128,7 @@ export async function ucanInvocationRouter(request) {
122
128
aggregatorDid,
123
129
dealTrackerDid,
124
130
dealTrackerUrl,
131
+ uploadServiceURL,
125
132
pieceOfferQueueUrl,
126
133
filecoinSubmitQueueUrl,
127
134
requirePaymentPlan,
@@ -144,6 +151,22 @@ export async function ucanInvocationRouter(request) {
144
151
const { PRIVATE_KEY , STRIPE_SECRET_KEY } = Config
145
152
const serviceSigner = getServiceSigner ( { did : UPLOAD_API_DID , privateKey : PRIVATE_KEY } )
146
153
154
+ const tasksStorage = createTasksStorage ( AWS_REGION , invocationBucketName , workflowBucketName )
155
+ const receiptsStorage = createReceiptsStorage ( AWS_REGION , taskBucketName , invocationBucketName , workflowBucketName )
156
+ const allocationsStorage = createAllocationsStorage ( AWS_REGION , allocationTableName , {
157
+ endpoint : dbEndpoint ,
158
+ } )
159
+ const blobsStorage = composeblobStoragesWithOrderedHas (
160
+ createBlobsStorage ( R2_REGION , carparkBucketName , {
161
+ endpoint : carparkBucketEndpoint ,
162
+ credentials : {
163
+ accessKeyId : carparkBucketAccessKeyId ,
164
+ secretAccessKey : carparkBucketSecretAccessKey ,
165
+ } ,
166
+ } ) ,
167
+ createBlobsStorage ( AWS_REGION , storeBucketName ) ,
168
+ )
169
+
147
170
const invocationBucket = createInvocationStore (
148
171
AWS_REGION ,
149
172
invocationBucketName
@@ -172,16 +195,29 @@ export async function ucanInvocationRouter(request) {
172
195
const spaceSnapshotStore = createSpaceSnapshotStore ( { region : AWS_REGION } , { tableName : spaceSnapshotTableName } )
173
196
const usageStorage = useUsageStore ( { spaceDiffStore, spaceSnapshotStore } )
174
197
175
- const connection = getServiceConnection ( {
198
+ const dealTrackerConnection = getServiceConnection ( {
176
199
did : dealTrackerDid ,
177
200
url : dealTrackerUrl
178
201
} )
202
+ const selfConnection = getServiceConnection ( {
203
+ did : serviceSigner . did ( ) ,
204
+ url : uploadServiceURL
205
+ } )
206
+ const tasksScheduler = createTasksScheduler ( ( ) => selfConnection )
179
207
180
208
const server = createUcantoServer ( serviceSigner , {
181
209
codec,
210
+ allocationsStorage,
211
+ blobsStorage,
212
+ tasksStorage,
213
+ receiptsStorage,
214
+ tasksScheduler,
215
+ getServiceConnection : ( ) => selfConnection ,
216
+ // TODO: to be deprecated with `store/*` protocol
182
217
storeTable : createStoreTable ( AWS_REGION , storeTableName , {
183
218
endpoint : dbEndpoint ,
184
219
} ) ,
220
+ // TODO: to be deprecated with `store/*` protocol
185
221
carStoreBucket : composeCarStoresWithOrderedHas (
186
222
createCarStore ( AWS_REGION , storeBucketName ) ,
187
223
createCarStore ( R2_REGION , carparkBucketName , {
@@ -192,6 +228,7 @@ export async function ucanInvocationRouter(request) {
192
228
} ,
193
229
} ) ,
194
230
) ,
231
+ // TODO: to be deprecated with `store/*` protocol
195
232
dudewhereBucket : createDudewhereStore ( R2_REGION , R2_DUDEWHERE_BUCKET_NAME , {
196
233
endpoint : R2_ENDPOINT ,
197
234
credentials : {
@@ -218,10 +255,10 @@ export async function ucanInvocationRouter(request) {
218
255
pieceOfferQueue : createPieceOfferQueueClient ( { region : AWS_REGION } , { queueUrl : pieceOfferQueueUrl } ) ,
219
256
filecoinSubmitQueue : createFilecoinSubmitQueueClient ( { region : AWS_REGION } , { queueUrl : filecoinSubmitQueueUrl } ) ,
220
257
dealTrackerService : {
221
- connection,
258
+ connection : dealTrackerConnection ,
222
259
invocationConfig : {
223
260
issuer : serviceSigner ,
224
- audience : connection . id ,
261
+ audience : dealTrackerConnection . id ,
225
262
with : serviceSigner . did ( )
226
263
}
227
264
} ,
@@ -316,6 +353,7 @@ function getLambdaEnv () {
316
353
storeTableName : mustGetEnv ( 'STORE_TABLE_NAME' ) ,
317
354
storeBucketName : mustGetEnv ( 'STORE_BUCKET_NAME' ) ,
318
355
uploadTableName : mustGetEnv ( 'UPLOAD_TABLE_NAME' ) ,
356
+ allocationTableName : mustGetEnv ( 'ALLOCATION_TABLE_NAME' ) ,
319
357
consumerTableName : mustGetEnv ( 'CONSUMER_TABLE_NAME' ) ,
320
358
customerTableName : mustGetEnv ( 'CUSTOMER_TABLE_NAME' ) ,
321
359
subscriptionTableName : mustGetEnv ( 'SUBSCRIPTION_TABLE_NAME' ) ,
@@ -339,6 +377,7 @@ function getLambdaEnv () {
339
377
postmarkToken : mustGetEnv ( 'POSTMARK_TOKEN' ) ,
340
378
providers : mustGetEnv ( 'PROVIDERS' ) ,
341
379
accessServiceURL : mustGetEnv ( 'ACCESS_SERVICE_URL' ) ,
380
+ uploadServiceURL : mustGetEnv ( 'UPLOAD_SERVICE_URL' ) ,
342
381
aggregatorDid : mustGetEnv ( 'AGGREGATOR_DID' ) ,
343
382
requirePaymentPlan : ( process . env . REQUIRE_PAYMENT_PLAN === 'true' ) ,
344
383
dealTrackerDid : mustGetEnv ( 'DEAL_TRACKER_DID' ) ,
0 commit comments