@cumulus/api-client 15.0.4 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/executions.d.ts +4 -4
- package/executions.d.ts.map +1 -1
- package/executions.js.map +1 -1
- package/granules.d.ts +35 -6
- package/granules.d.ts.map +1 -1
- package/granules.js +95 -24
- package/granules.js.map +1 -1
- package/package.json +5 -5
- package/src/executions.ts +4 -4
- package/src/granules.ts +135 -22
- package/tsconfig.tsbuildinfo +1 -1
- package/migrationCounts.d.ts +0 -20
- package/migrationCounts.d.ts.map +0 -1
- package/migrationCounts.js +0 -34
- package/migrationCounts.js.map +0 -1
- package/src/migrationCounts.ts +0 -37
package/src/granules.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import pRetry from 'p-retry';
|
|
2
2
|
|
|
3
|
-
import { ApiGranuleRecord, GranuleId, GranuleStatus } from '@cumulus/types/api/granules';
|
|
3
|
+
import { ApiGranuleRecord, ApiGranule, GranuleId, GranuleStatus } from '@cumulus/types/api/granules';
|
|
4
|
+
import { CollectionId } from '@cumulus/types/api/collections';
|
|
4
5
|
import Logger from '@cumulus/logger';
|
|
5
6
|
|
|
6
7
|
import { invokeApi } from './cumulusApiClient';
|
|
@@ -15,7 +16,7 @@ type AssociateExecutionRequest = {
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* GET raw response from /granules/{
|
|
19
|
+
* GET raw response from /granules/{granuleId} or /granules/{collectionId}/{granuleId}
|
|
19
20
|
*
|
|
20
21
|
* @param {Object} params - params
|
|
21
22
|
* @param {string} params.prefix - the prefix configured for the stack
|
|
@@ -33,6 +34,7 @@ type AssociateExecutionRequest = {
|
|
|
33
34
|
export const getGranuleResponse = async (params: {
|
|
34
35
|
prefix: string,
|
|
35
36
|
granuleId: GranuleId,
|
|
37
|
+
collectionId?: CollectionId,
|
|
36
38
|
expectedStatusCodes?: number[] | number,
|
|
37
39
|
query?: { [key: string]: string },
|
|
38
40
|
callback?: InvokeApiFunction
|
|
@@ -40,17 +42,25 @@ export const getGranuleResponse = async (params: {
|
|
|
40
42
|
const {
|
|
41
43
|
prefix,
|
|
42
44
|
granuleId,
|
|
45
|
+
collectionId,
|
|
43
46
|
query,
|
|
44
47
|
expectedStatusCodes,
|
|
45
48
|
callback = invokeApi,
|
|
46
49
|
} = params;
|
|
47
50
|
|
|
51
|
+
let path = `/granules/${collectionId}/${granuleId}`;
|
|
52
|
+
|
|
53
|
+
// Fetching a granule without a collectionId is supported but deprecated
|
|
54
|
+
if (!collectionId) {
|
|
55
|
+
path = `/granules/${granuleId}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
return await callback({
|
|
49
59
|
prefix,
|
|
50
60
|
payload: {
|
|
51
61
|
httpMethod: 'GET',
|
|
52
62
|
resource: '/{proxy+}',
|
|
53
|
-
path
|
|
63
|
+
path,
|
|
54
64
|
...(query && { queryStringParameters: query }),
|
|
55
65
|
},
|
|
56
66
|
expectedStatusCodes,
|
|
@@ -58,7 +68,7 @@ export const getGranuleResponse = async (params: {
|
|
|
58
68
|
};
|
|
59
69
|
|
|
60
70
|
/**
|
|
61
|
-
* GET granule record from /granules/{
|
|
71
|
+
* GET granule record from /granules/{granuleId} or /granules/{collectionId}/{granuleId}
|
|
62
72
|
*
|
|
63
73
|
* @param {Object} params - params
|
|
64
74
|
* @param {string} params.prefix - the prefix configured for the stack
|
|
@@ -73,6 +83,7 @@ export const getGranuleResponse = async (params: {
|
|
|
73
83
|
export const getGranule = async (params: {
|
|
74
84
|
prefix: string,
|
|
75
85
|
granuleId: GranuleId,
|
|
86
|
+
collectionId?: CollectionId,
|
|
76
87
|
query?: { [key: string]: string },
|
|
77
88
|
callback?: InvokeApiFunction
|
|
78
89
|
}): Promise<ApiGranuleRecord> => {
|
|
@@ -110,6 +121,7 @@ export const waitForGranule = async (params: {
|
|
|
110
121
|
|
|
111
122
|
await pRetry(
|
|
112
123
|
async () => {
|
|
124
|
+
// TODO update to use collectionId + granuleId
|
|
113
125
|
const apiResult = await getGranuleResponse({ prefix, granuleId, callback });
|
|
114
126
|
|
|
115
127
|
if (apiResult.statusCode === 500) {
|
|
@@ -158,20 +170,36 @@ export const waitForGranule = async (params: {
|
|
|
158
170
|
export const reingestGranule = async (params: {
|
|
159
171
|
prefix: string,
|
|
160
172
|
granuleId: GranuleId,
|
|
173
|
+
collectionId?: CollectionId,
|
|
161
174
|
workflowName?: string | undefined,
|
|
162
175
|
executionArn?: string | undefined,
|
|
163
176
|
callback?: InvokeApiFunction
|
|
164
177
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
165
|
-
const {
|
|
178
|
+
const {
|
|
179
|
+
prefix,
|
|
180
|
+
granuleId,
|
|
181
|
+
collectionId,
|
|
182
|
+
workflowName,
|
|
183
|
+
executionArn,
|
|
184
|
+
callback = invokeApi,
|
|
185
|
+
} = params;
|
|
186
|
+
|
|
187
|
+
let path = `/granules/${collectionId}/${granuleId}`;
|
|
188
|
+
|
|
189
|
+
// Fetching a granule without a collectionId is supported but deprecated
|
|
190
|
+
if (!collectionId) {
|
|
191
|
+
path = `/granules/${granuleId}`;
|
|
192
|
+
}
|
|
166
193
|
|
|
167
194
|
return await callback({
|
|
168
195
|
prefix: prefix,
|
|
169
196
|
payload: {
|
|
170
197
|
httpMethod: 'PATCH',
|
|
171
198
|
resource: '/{proxy+}',
|
|
172
|
-
path
|
|
199
|
+
path,
|
|
173
200
|
headers: {
|
|
174
201
|
'Content-Type': 'application/json',
|
|
202
|
+
'Cumulus-API-Version': '2',
|
|
175
203
|
},
|
|
176
204
|
body: JSON.stringify({
|
|
177
205
|
action: 'reingest',
|
|
@@ -198,18 +226,27 @@ export const reingestGranule = async (params: {
|
|
|
198
226
|
export const removeFromCMR = async (params: {
|
|
199
227
|
prefix: string,
|
|
200
228
|
granuleId: GranuleId,
|
|
229
|
+
collectionId?: CollectionId,
|
|
201
230
|
callback?: InvokeApiFunction
|
|
202
231
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
203
|
-
const { prefix, granuleId, callback = invokeApi } = params;
|
|
232
|
+
const { prefix, granuleId, collectionId, callback = invokeApi } = params;
|
|
233
|
+
|
|
234
|
+
let path = `/granules/${collectionId}/${granuleId}`;
|
|
235
|
+
|
|
236
|
+
// Fetching a granule without a collectionId is supported but deprecated
|
|
237
|
+
if (!collectionId) {
|
|
238
|
+
path = `/granules/${granuleId}`;
|
|
239
|
+
}
|
|
204
240
|
|
|
205
241
|
return await callback({
|
|
206
242
|
prefix: prefix,
|
|
207
243
|
payload: {
|
|
208
244
|
httpMethod: 'PATCH',
|
|
209
245
|
resource: '/{proxy+}',
|
|
210
|
-
path
|
|
246
|
+
path,
|
|
211
247
|
headers: {
|
|
212
248
|
'Content-Type': 'application/json',
|
|
249
|
+
'Cumulus-API-Version': '2',
|
|
213
250
|
},
|
|
214
251
|
body: JSON.stringify({ action: 'removeFromCmr' }),
|
|
215
252
|
},
|
|
@@ -233,6 +270,7 @@ export const removeFromCMR = async (params: {
|
|
|
233
270
|
export const applyWorkflow = async (params: {
|
|
234
271
|
prefix: string,
|
|
235
272
|
granuleId: GranuleId,
|
|
273
|
+
collectionId?: CollectionId,
|
|
236
274
|
workflow: string,
|
|
237
275
|
meta?: object,
|
|
238
276
|
callback?: InvokeApiFunction
|
|
@@ -240,11 +278,19 @@ export const applyWorkflow = async (params: {
|
|
|
240
278
|
const {
|
|
241
279
|
prefix,
|
|
242
280
|
granuleId,
|
|
281
|
+
collectionId,
|
|
243
282
|
workflow,
|
|
244
283
|
meta,
|
|
245
284
|
callback = invokeApi,
|
|
246
285
|
} = params;
|
|
247
286
|
|
|
287
|
+
let path = `/granules/${collectionId}/${granuleId}`;
|
|
288
|
+
|
|
289
|
+
// Fetching a granule without a collectionId is supported but deprecated
|
|
290
|
+
if (!collectionId) {
|
|
291
|
+
path = `/granules/${granuleId}`;
|
|
292
|
+
}
|
|
293
|
+
|
|
248
294
|
return await callback({
|
|
249
295
|
prefix: prefix,
|
|
250
296
|
payload: {
|
|
@@ -252,8 +298,9 @@ export const applyWorkflow = async (params: {
|
|
|
252
298
|
resource: '/{proxy+}',
|
|
253
299
|
headers: {
|
|
254
300
|
'Content-Type': 'application/json',
|
|
301
|
+
'Cumulus-API-Version': '2',
|
|
255
302
|
},
|
|
256
|
-
path
|
|
303
|
+
path,
|
|
257
304
|
body: JSON.stringify({ action: 'applyWorkflow', workflow, meta }),
|
|
258
305
|
},
|
|
259
306
|
});
|
|
@@ -276,6 +323,7 @@ export const applyWorkflow = async (params: {
|
|
|
276
323
|
export const deleteGranule = async (params: {
|
|
277
324
|
prefix: string,
|
|
278
325
|
granuleId: GranuleId,
|
|
326
|
+
collectionId?: CollectionId,
|
|
279
327
|
pRetryOptions?: pRetry.Options,
|
|
280
328
|
callback?: InvokeApiFunction
|
|
281
329
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
@@ -283,14 +331,23 @@ export const deleteGranule = async (params: {
|
|
|
283
331
|
pRetryOptions,
|
|
284
332
|
prefix,
|
|
285
333
|
granuleId,
|
|
334
|
+
collectionId,
|
|
286
335
|
callback = invokeApi,
|
|
287
336
|
} = params;
|
|
337
|
+
|
|
338
|
+
let path = `/granules/${collectionId}/${granuleId}`;
|
|
339
|
+
|
|
340
|
+
// Fetching a granule without a collectionId is supported but deprecated
|
|
341
|
+
if (!collectionId) {
|
|
342
|
+
path = `/granules/${granuleId}`;
|
|
343
|
+
}
|
|
344
|
+
|
|
288
345
|
return await callback({
|
|
289
346
|
prefix: prefix,
|
|
290
347
|
payload: {
|
|
291
348
|
httpMethod: 'DELETE',
|
|
292
349
|
resource: '/{proxy+}',
|
|
293
|
-
path
|
|
350
|
+
path,
|
|
294
351
|
},
|
|
295
352
|
pRetryOptions,
|
|
296
353
|
});
|
|
@@ -313,16 +370,25 @@ export const deleteGranule = async (params: {
|
|
|
313
370
|
export const moveGranule = async (params: {
|
|
314
371
|
prefix: string,
|
|
315
372
|
granuleId: GranuleId,
|
|
373
|
+
collectionId?: CollectionId,
|
|
316
374
|
destinations: unknown[],
|
|
317
375
|
callback?: InvokeApiFunction
|
|
318
376
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
319
377
|
const {
|
|
320
378
|
prefix,
|
|
321
379
|
granuleId,
|
|
380
|
+
collectionId,
|
|
322
381
|
destinations,
|
|
323
382
|
callback = invokeApi,
|
|
324
383
|
} = params;
|
|
325
384
|
|
|
385
|
+
let path = `/granules/${collectionId}/${granuleId}`;
|
|
386
|
+
|
|
387
|
+
// Fetching a granule without a collectionId is supported but deprecated
|
|
388
|
+
if (!collectionId) {
|
|
389
|
+
path = `/granules/${granuleId}`;
|
|
390
|
+
}
|
|
391
|
+
|
|
326
392
|
return await callback({
|
|
327
393
|
prefix: prefix,
|
|
328
394
|
payload: {
|
|
@@ -330,8 +396,9 @@ export const moveGranule = async (params: {
|
|
|
330
396
|
resource: '/{proxy+}',
|
|
331
397
|
headers: {
|
|
332
398
|
'Content-Type': 'application/json',
|
|
399
|
+
'Cumulus-API-Version': '2',
|
|
333
400
|
},
|
|
334
|
-
path
|
|
401
|
+
path,
|
|
335
402
|
body: JSON.stringify({ action: 'move', destinations }),
|
|
336
403
|
},
|
|
337
404
|
});
|
|
@@ -352,13 +419,14 @@ export const moveGranule = async (params: {
|
|
|
352
419
|
export const removePublishedGranule = async (params: {
|
|
353
420
|
prefix: string,
|
|
354
421
|
granuleId: GranuleId,
|
|
422
|
+
collectionId?: CollectionId,
|
|
355
423
|
callback?: InvokeApiFunction
|
|
356
424
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
357
|
-
const { prefix, granuleId, callback = invokeApi } = params;
|
|
425
|
+
const { prefix, granuleId, collectionId, callback = invokeApi } = params;
|
|
358
426
|
|
|
359
427
|
// pre-delete: Remove the granule from CMR
|
|
360
|
-
await removeFromCMR({ prefix, granuleId, callback });
|
|
361
|
-
return deleteGranule({ prefix, granuleId, callback });
|
|
428
|
+
await removeFromCMR({ prefix, granuleId, collectionId, callback });
|
|
429
|
+
return deleteGranule({ prefix, granuleId, collectionId, callback });
|
|
362
430
|
};
|
|
363
431
|
|
|
364
432
|
/**
|
|
@@ -423,6 +491,42 @@ export const createGranule = async (params: {
|
|
|
423
491
|
});
|
|
424
492
|
};
|
|
425
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Update/create granule in cumulus via PUT request. Existing values will
|
|
496
|
+
* be removed if not specified and in some cases replaced with defaults.
|
|
497
|
+
* Granule execution association history will be retained.
|
|
498
|
+
* PUT /granules/{collectionId}/{granuleId}
|
|
499
|
+
* @param {Object} params - params
|
|
500
|
+
* @param {Object} [params.body] - granule to pass the API lambda
|
|
501
|
+
* @param {Function} params.callback - async function to invoke the api lambda
|
|
502
|
+
* that takes a prefix / user payload. Defaults
|
|
503
|
+
* to cumulusApiClient.invokeApifunction to invoke the
|
|
504
|
+
* api lambda
|
|
505
|
+
* @returns {Promise<Object>} - the response from the callback
|
|
506
|
+
*/
|
|
507
|
+
export const replaceGranule = async (params: {
|
|
508
|
+
prefix: string,
|
|
509
|
+
body: ApiGranuleRecord,
|
|
510
|
+
callback?: InvokeApiFunction
|
|
511
|
+
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
512
|
+
const { prefix, body, callback = invokeApi } = params;
|
|
513
|
+
|
|
514
|
+
return await callback({
|
|
515
|
+
prefix,
|
|
516
|
+
payload: {
|
|
517
|
+
httpMethod: 'PUT',
|
|
518
|
+
resource: '/{proxy+}',
|
|
519
|
+
path: `/granules/${body.collectionId}/${body.granuleId}`,
|
|
520
|
+
headers: {
|
|
521
|
+
'Content-Type': 'application/json',
|
|
522
|
+
'Cumulus-API-Version': '2',
|
|
523
|
+
},
|
|
524
|
+
body: JSON.stringify(body),
|
|
525
|
+
},
|
|
526
|
+
expectedStatusCodes: [200, 201],
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
|
|
426
530
|
/**
|
|
427
531
|
* Update granule in cumulus via PATCH request. Existing values will
|
|
428
532
|
* not be overwritten if not specified, null values will be removed and in
|
|
@@ -439,17 +543,26 @@ export const createGranule = async (params: {
|
|
|
439
543
|
export const updateGranule = async (params: {
|
|
440
544
|
prefix: string,
|
|
441
545
|
body: ApiGranuleRecord,
|
|
546
|
+
granuleId: GranuleId,
|
|
547
|
+
collectionId?: CollectionId,
|
|
442
548
|
callback?: InvokeApiFunction
|
|
443
549
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
444
|
-
const { prefix, body, callback = invokeApi } = params;
|
|
550
|
+
const { prefix, granuleId, collectionId, body, callback = invokeApi } = params;
|
|
551
|
+
|
|
552
|
+
let path = `/granules/${collectionId}/${granuleId}`;
|
|
553
|
+
|
|
554
|
+
// Fetching a granule without a collectionId is supported but deprecated
|
|
555
|
+
if (!collectionId) {
|
|
556
|
+
path = `/granules/${granuleId}`;
|
|
557
|
+
}
|
|
445
558
|
|
|
446
559
|
return await callback({
|
|
447
560
|
prefix,
|
|
448
561
|
payload: {
|
|
449
562
|
httpMethod: 'PATCH',
|
|
450
563
|
resource: '/{proxy+}',
|
|
451
|
-
path
|
|
452
|
-
headers: { 'Content-Type': 'application/json' },
|
|
564
|
+
path,
|
|
565
|
+
headers: { 'Content-Type': 'application/json', 'Cumulus-API-Version': '2' },
|
|
453
566
|
body: JSON.stringify(body),
|
|
454
567
|
},
|
|
455
568
|
expectedStatusCodes: [200, 201],
|
|
@@ -499,7 +612,7 @@ export const associateExecutionWithGranule = async (params: {
|
|
|
499
612
|
*/
|
|
500
613
|
export const bulkGranules = async (params: {
|
|
501
614
|
prefix: string,
|
|
502
|
-
body:
|
|
615
|
+
body: unknown,
|
|
503
616
|
callback?: InvokeApiFunction
|
|
504
617
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
505
618
|
const { prefix, body, callback = invokeApi } = params;
|
|
@@ -580,7 +693,7 @@ export const bulkReingestGranules = async (params: {
|
|
|
580
693
|
*
|
|
581
694
|
* @param {Object} params - params
|
|
582
695
|
* @param {string} params.prefix - the prefix configured for the stack
|
|
583
|
-
* @param {Array<
|
|
696
|
+
* @param {Array<ApiGranuleRecord>} params.granules - the granules to have bulk operation on
|
|
584
697
|
* @param {string} params.workflowName - workflowName for the bulk operation execution
|
|
585
698
|
* @param {Function} params.callback - async function to invoke the api lambda
|
|
586
699
|
* that takes a prefix / user payload. Defaults
|
|
@@ -590,11 +703,11 @@ export const bulkReingestGranules = async (params: {
|
|
|
590
703
|
*/
|
|
591
704
|
export const bulkOperation = async (params: {
|
|
592
705
|
prefix: string,
|
|
593
|
-
|
|
706
|
+
granules: ApiGranule[],
|
|
594
707
|
workflowName: string,
|
|
595
708
|
callback?: InvokeApiFunction
|
|
596
709
|
}): Promise<ApiGatewayLambdaHttpProxyResponse> => {
|
|
597
|
-
const { prefix,
|
|
710
|
+
const { prefix, granules, workflowName, callback = invokeApi } = params;
|
|
598
711
|
return await callback({
|
|
599
712
|
prefix: prefix,
|
|
600
713
|
payload: {
|
|
@@ -604,7 +717,7 @@ export const bulkOperation = async (params: {
|
|
|
604
717
|
headers: {
|
|
605
718
|
'Content-Type': 'application/json',
|
|
606
719
|
},
|
|
607
|
-
body: JSON.stringify({
|
|
720
|
+
body: JSON.stringify({ granules, workflowName }),
|
|
608
721
|
},
|
|
609
722
|
expectedStatusCodes: 202,
|
|
610
723
|
});
|