@scality/data-browser-library 1.1.8 → 1.1.10
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/dist/components/__tests__/BucketLifecycleFormPage.test.js +106 -0
- package/dist/components/buckets/BucketLifecycleFormPage.js +19 -37
- package/dist/components/buckets/BucketLifecycleList.js +8 -4
- package/dist/components/buckets/BucketReplicationList.js +12 -9
- package/dist/components/providers/DataBrowserProvider.d.ts +1 -1
- package/dist/components/providers/DataBrowserProvider.js +4 -2
- package/dist/hooks/useS3Client.js +4 -5
- package/dist/test/utils/errorHandling.test.js +34 -1
- package/dist/types/index.d.ts +9 -4
- package/dist/utils/errorHandling.d.ts +2 -1
- package/dist/utils/errorHandling.js +11 -1
- package/dist/utils/s3Client.d.ts +3 -9
- package/dist/utils/s3ConfigIdentifier.js +10 -7
- package/package.json +2 -2
|
@@ -598,6 +598,112 @@ describe('BucketLifecycleFormPage', ()=>{
|
|
|
598
598
|
expect(transitionToggle).toBeChecked();
|
|
599
599
|
});
|
|
600
600
|
});
|
|
601
|
+
it('does not add extra transition rows when loading a rule with existing transitions', async ()=>{
|
|
602
|
+
const rule = {
|
|
603
|
+
ID: 'transition-rule',
|
|
604
|
+
Status: 'Enabled',
|
|
605
|
+
Filter: {},
|
|
606
|
+
Transitions: [
|
|
607
|
+
{
|
|
608
|
+
Days: 60,
|
|
609
|
+
StorageClass: 'STANDARD_IA'
|
|
610
|
+
}
|
|
611
|
+
]
|
|
612
|
+
};
|
|
613
|
+
mockUseGetBucketLifecycle.mockReturnValue({
|
|
614
|
+
data: {
|
|
615
|
+
Rules: [
|
|
616
|
+
rule
|
|
617
|
+
]
|
|
618
|
+
},
|
|
619
|
+
status: 'success'
|
|
620
|
+
});
|
|
621
|
+
renderBucketLifecycleFormPage('test-bucket', 'transition-rule');
|
|
622
|
+
await waitFor(()=>{
|
|
623
|
+
const transitionToggle = findToggleByLabel('Transition current version');
|
|
624
|
+
expect(transitionToggle).toBeChecked();
|
|
625
|
+
expect(screen.getByDisplayValue('60')).toBeInTheDocument();
|
|
626
|
+
});
|
|
627
|
+
expect(document.getElementById('transition-days-1')).not.toBeInTheDocument();
|
|
628
|
+
});
|
|
629
|
+
it('auto-adds a transition row when enabling transitions in edit mode on a rule without transitions', async ()=>{
|
|
630
|
+
const rule = {
|
|
631
|
+
ID: 'delete-marker-rule',
|
|
632
|
+
Status: 'Enabled',
|
|
633
|
+
Filter: {},
|
|
634
|
+
Expiration: {
|
|
635
|
+
ExpiredObjectDeleteMarker: true
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
mockUseGetBucketLifecycle.mockReturnValue({
|
|
639
|
+
data: {
|
|
640
|
+
Rules: [
|
|
641
|
+
rule
|
|
642
|
+
]
|
|
643
|
+
},
|
|
644
|
+
status: 'success'
|
|
645
|
+
});
|
|
646
|
+
renderBucketLifecycleFormPage('test-bucket', 'delete-marker-rule');
|
|
647
|
+
await waitFor(()=>{
|
|
648
|
+
expect(screen.getByText('Edit Lifecycle Rule')).toBeInTheDocument();
|
|
649
|
+
});
|
|
650
|
+
const transitionToggle = findToggleByLabel('Transition current version');
|
|
651
|
+
fireEvent.click(transitionToggle);
|
|
652
|
+
await waitFor(()=>{
|
|
653
|
+
expect(screen.getByText('Time Type')).toBeInTheDocument();
|
|
654
|
+
expect(screen.getByText('Storage Class')).toBeInTheDocument();
|
|
655
|
+
expect(screen.getByDisplayValue('30')).toBeInTheDocument();
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
it('auto-adds a noncurrent transition row when enabling noncurrent transitions in edit mode', async ()=>{
|
|
659
|
+
const rule = {
|
|
660
|
+
ID: 'expiration-only-rule',
|
|
661
|
+
Status: 'Enabled',
|
|
662
|
+
Filter: {},
|
|
663
|
+
Expiration: {
|
|
664
|
+
Days: 30
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
mockUseGetBucketLifecycle.mockReturnValue({
|
|
668
|
+
data: {
|
|
669
|
+
Rules: [
|
|
670
|
+
rule
|
|
671
|
+
]
|
|
672
|
+
},
|
|
673
|
+
status: 'success'
|
|
674
|
+
});
|
|
675
|
+
renderBucketLifecycleFormPage('test-bucket', 'expiration-only-rule');
|
|
676
|
+
await waitFor(()=>{
|
|
677
|
+
expect(screen.getByText('Edit Lifecycle Rule')).toBeInTheDocument();
|
|
678
|
+
});
|
|
679
|
+
const noncurrentToggle = findToggleByLabel('Transition noncurrent version');
|
|
680
|
+
fireEvent.click(noncurrentToggle);
|
|
681
|
+
await waitFor(()=>{
|
|
682
|
+
expect(screen.getByText('Noncurrent Days')).toBeInTheDocument();
|
|
683
|
+
expect(document.getElementById('noncurrent-transition-days-0')).toBeInTheDocument();
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
describe('Transition Auto-Add in Create Mode', ()=>{
|
|
688
|
+
it('auto-adds a transition row when enabling transitions', async ()=>{
|
|
689
|
+
renderBucketLifecycleFormPage();
|
|
690
|
+
const transitionToggle = findToggleByLabel('Transition current version');
|
|
691
|
+
fireEvent.click(transitionToggle);
|
|
692
|
+
await waitFor(()=>{
|
|
693
|
+
expect(screen.getByText('Time Type')).toBeInTheDocument();
|
|
694
|
+
expect(screen.getByText('Storage Class')).toBeInTheDocument();
|
|
695
|
+
expect(screen.getByDisplayValue('30')).toBeInTheDocument();
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
it('auto-adds a noncurrent transition row when enabling noncurrent transitions', async ()=>{
|
|
699
|
+
renderBucketLifecycleFormPage();
|
|
700
|
+
const noncurrentToggle = findToggleByLabel('Transition noncurrent version');
|
|
701
|
+
fireEvent.click(noncurrentToggle);
|
|
702
|
+
await waitFor(()=>{
|
|
703
|
+
expect(screen.getByText('Noncurrent Days')).toBeInTheDocument();
|
|
704
|
+
expect(document.getElementById('noncurrent-transition-days-0')).toBeInTheDocument();
|
|
705
|
+
});
|
|
706
|
+
});
|
|
601
707
|
});
|
|
602
708
|
describe('Navigation', ()=>{
|
|
603
709
|
it('navigates back to bucket lifecycle tab when cancel is clicked', ()=>{
|
|
@@ -9,8 +9,8 @@ import { Controller, FormProvider, useFieldArray, useForm } from "react-hook-for
|
|
|
9
9
|
import { useParams } from "react-router";
|
|
10
10
|
import { useDataBrowserUICustomization } from "../../contexts/DataBrowserUICustomizationContext.js";
|
|
11
11
|
import { useGetBucketLifecycle, useSetBucketLifecycle } from "../../hooks/bucketConfiguration.js";
|
|
12
|
-
import { useISVBucketStatus } from "../../hooks/useISVBucketDetection.js";
|
|
13
12
|
import { useDataBrowserNavigate } from "../../hooks/useDataBrowserNavigate.js";
|
|
13
|
+
import { useISVBucketStatus } from "../../hooks/useISVBucketDetection.js";
|
|
14
14
|
import { AWS_RULE_LIMITS, STATUS_OPTIONS, buildS3Filter } from "../../utils/s3RuleUtils.js";
|
|
15
15
|
import { ArrayFieldActions } from "../ui/ArrayFieldActions.js";
|
|
16
16
|
import { FilterFormSection, createFilterValidationSchema } from "../ui/FilterFormSection.js";
|
|
@@ -405,39 +405,6 @@ function BucketLifecycleFormPage() {
|
|
|
405
405
|
isISVManaged,
|
|
406
406
|
methods
|
|
407
407
|
]);
|
|
408
|
-
const prevTransitionsEnabledRef = useRef(null);
|
|
409
|
-
const prevNoncurrentTransitionsEnabledRef = useRef(null);
|
|
410
|
-
useEffect(()=>{
|
|
411
|
-
const prevValue = prevTransitionsEnabledRef.current;
|
|
412
|
-
prevTransitionsEnabledRef.current = transitionsEnabled;
|
|
413
|
-
if (!isEditMode && null !== prevValue && !prevValue && transitionsEnabled && 0 === transitionFields.length) appendTransition({
|
|
414
|
-
timeType: 'days',
|
|
415
|
-
days: 30,
|
|
416
|
-
date: '',
|
|
417
|
-
storageClass: hasCustomSelector ? '' : 'STANDARD_IA'
|
|
418
|
-
});
|
|
419
|
-
}, [
|
|
420
|
-
isEditMode,
|
|
421
|
-
transitionsEnabled,
|
|
422
|
-
transitionFields.length,
|
|
423
|
-
appendTransition,
|
|
424
|
-
hasCustomSelector
|
|
425
|
-
]);
|
|
426
|
-
useEffect(()=>{
|
|
427
|
-
const prevValue = prevNoncurrentTransitionsEnabledRef.current;
|
|
428
|
-
prevNoncurrentTransitionsEnabledRef.current = noncurrentTransitionsEnabled;
|
|
429
|
-
if (!isEditMode && null !== prevValue && !prevValue && noncurrentTransitionsEnabled && 0 === noncurrentTransitionFields.length) appendNoncurrentTransition({
|
|
430
|
-
noncurrentDays: 30,
|
|
431
|
-
storageClass: hasCustomSelector ? '' : 'GLACIER',
|
|
432
|
-
newerNoncurrentVersions: 0
|
|
433
|
-
});
|
|
434
|
-
}, [
|
|
435
|
-
isEditMode,
|
|
436
|
-
noncurrentTransitionsEnabled,
|
|
437
|
-
noncurrentTransitionFields.length,
|
|
438
|
-
appendNoncurrentTransition,
|
|
439
|
-
hasCustomSelector
|
|
440
|
-
]);
|
|
441
408
|
const prevFilterTypeRef = useRef();
|
|
442
409
|
useEffect(()=>{
|
|
443
410
|
const prevFilterType = prevFilterTypeRef.current;
|
|
@@ -693,7 +660,15 @@ function BucketLifecycleFormPage() {
|
|
|
693
660
|
control: control,
|
|
694
661
|
render: ({ field })=>/*#__PURE__*/ jsx(Toggle, {
|
|
695
662
|
toggle: field.value,
|
|
696
|
-
onChange:
|
|
663
|
+
onChange: (e)=>{
|
|
664
|
+
field.onChange(e);
|
|
665
|
+
if (e.target.checked && 0 === transitionFields.length) appendTransition({
|
|
666
|
+
timeType: 'days',
|
|
667
|
+
days: 30,
|
|
668
|
+
date: '',
|
|
669
|
+
storageClass: hasCustomSelector ? '' : 'STANDARD_IA'
|
|
670
|
+
});
|
|
671
|
+
},
|
|
697
672
|
label: field.value ? 'Enabled' : 'Disabled'
|
|
698
673
|
})
|
|
699
674
|
})
|
|
@@ -964,13 +939,20 @@ function BucketLifecycleFormPage() {
|
|
|
964
939
|
label: "Transition noncurrent version",
|
|
965
940
|
id: "noncurrentTransitionsEnabled",
|
|
966
941
|
direction: "horizontal",
|
|
967
|
-
labelHelpTooltip: noncurrentTransitionsHelpText ||
|
|
942
|
+
labelHelpTooltip: noncurrentTransitionsHelpText || 'Transition noncurrent object versions to a different storage class after a specified number of days',
|
|
968
943
|
content: /*#__PURE__*/ jsx(Controller, {
|
|
969
944
|
name: "noncurrentTransitionsEnabled",
|
|
970
945
|
control: control,
|
|
971
946
|
render: ({ field })=>/*#__PURE__*/ jsx(Toggle, {
|
|
972
947
|
toggle: field.value,
|
|
973
|
-
onChange:
|
|
948
|
+
onChange: (e)=>{
|
|
949
|
+
field.onChange(e);
|
|
950
|
+
if (e.target.checked && 0 === noncurrentTransitionFields.length) appendNoncurrentTransition({
|
|
951
|
+
noncurrentDays: 30,
|
|
952
|
+
storageClass: hasCustomSelector ? '' : 'GLACIER',
|
|
953
|
+
newerNoncurrentVersions: 0
|
|
954
|
+
});
|
|
955
|
+
},
|
|
974
956
|
label: field.value ? 'Enabled' : 'Disabled'
|
|
975
957
|
})
|
|
976
958
|
})
|
|
@@ -77,7 +77,8 @@ function BucketLifecycleList({ bucketName, lifecycleRules, lifecycleStatus, onCr
|
|
|
77
77
|
}),
|
|
78
78
|
cellStyle: {
|
|
79
79
|
flex: '1',
|
|
80
|
-
width: 'unset'
|
|
80
|
+
width: 'unset',
|
|
81
|
+
minWidth: 0
|
|
81
82
|
}
|
|
82
83
|
},
|
|
83
84
|
{
|
|
@@ -92,7 +93,8 @@ function BucketLifecycleList({ bucketName, lifecycleRules, lifecycleStatus, onCr
|
|
|
92
93
|
},
|
|
93
94
|
cellStyle: {
|
|
94
95
|
width: 'unset',
|
|
95
|
-
flex: '0.5'
|
|
96
|
+
flex: '0.5',
|
|
97
|
+
minWidth: 0
|
|
96
98
|
}
|
|
97
99
|
},
|
|
98
100
|
{
|
|
@@ -165,7 +167,8 @@ function BucketLifecycleList({ bucketName, lifecycleRules, lifecycleStatus, onCr
|
|
|
165
167
|
},
|
|
166
168
|
cellStyle: {
|
|
167
169
|
width: 'unset',
|
|
168
|
-
flex: '1.5'
|
|
170
|
+
flex: '1.5',
|
|
171
|
+
minWidth: 0
|
|
169
172
|
}
|
|
170
173
|
},
|
|
171
174
|
{
|
|
@@ -176,7 +179,8 @@ function BucketLifecycleList({ bucketName, lifecycleRules, lifecycleStatus, onCr
|
|
|
176
179
|
flex: '0.5',
|
|
177
180
|
textAlign: 'right',
|
|
178
181
|
paddingRight: spacing.r16,
|
|
179
|
-
width: 'unset'
|
|
182
|
+
width: 'unset',
|
|
183
|
+
minWidth: 0
|
|
180
184
|
},
|
|
181
185
|
Cell: ({ value })=>/*#__PURE__*/ jsxs(Box, {
|
|
182
186
|
display: "flex",
|
|
@@ -19,7 +19,8 @@ function BucketReplicationList({ bucketName, replicationRules, replicationRole,
|
|
|
19
19
|
}),
|
|
20
20
|
cellStyle: {
|
|
21
21
|
flex: '1',
|
|
22
|
-
width: 'unset'
|
|
22
|
+
width: 'unset',
|
|
23
|
+
minWidth: 0
|
|
23
24
|
}
|
|
24
25
|
},
|
|
25
26
|
{
|
|
@@ -34,7 +35,8 @@ function BucketReplicationList({ bucketName, replicationRules, replicationRole,
|
|
|
34
35
|
},
|
|
35
36
|
cellStyle: {
|
|
36
37
|
width: 'unset',
|
|
37
|
-
flex: '0.
|
|
38
|
+
flex: '0.6',
|
|
39
|
+
minWidth: 0
|
|
38
40
|
}
|
|
39
41
|
},
|
|
40
42
|
{
|
|
@@ -46,9 +48,8 @@ function BucketReplicationList({ bucketName, replicationRules, replicationRole,
|
|
|
46
48
|
}),
|
|
47
49
|
cellStyle: {
|
|
48
50
|
width: 'unset',
|
|
49
|
-
flex: '0.
|
|
50
|
-
|
|
51
|
-
paddingRight: spacing.r16
|
|
51
|
+
flex: '0.8',
|
|
52
|
+
minWidth: 0
|
|
52
53
|
}
|
|
53
54
|
},
|
|
54
55
|
{
|
|
@@ -84,7 +85,8 @@ function BucketReplicationList({ bucketName, replicationRules, replicationRole,
|
|
|
84
85
|
},
|
|
85
86
|
cellStyle: {
|
|
86
87
|
width: 'unset',
|
|
87
|
-
flex: '1.
|
|
88
|
+
flex: '1.2',
|
|
89
|
+
minWidth: 0
|
|
88
90
|
}
|
|
89
91
|
},
|
|
90
92
|
{
|
|
@@ -92,10 +94,11 @@ function BucketReplicationList({ bucketName, replicationRules, replicationRole,
|
|
|
92
94
|
accessor: 'ID',
|
|
93
95
|
id: 'operations',
|
|
94
96
|
cellStyle: {
|
|
95
|
-
flex: '0.
|
|
97
|
+
flex: '0.8',
|
|
98
|
+
width: 'unset',
|
|
99
|
+
minWidth: 0,
|
|
96
100
|
textAlign: 'right',
|
|
97
|
-
paddingRight: spacing.r16
|
|
98
|
-
width: 'unset'
|
|
101
|
+
paddingRight: spacing.r16
|
|
99
102
|
},
|
|
100
103
|
Cell: ({ value })=>/*#__PURE__*/ jsxs(Box, {
|
|
101
104
|
display: "flex",
|
|
@@ -17,7 +17,7 @@ export interface DataBrowserProviderProps {
|
|
|
17
17
|
}
|
|
18
18
|
export declare const DataBrowserProvider: React.FC<DataBrowserProviderProps>;
|
|
19
19
|
export declare const useDataBrowserConfig: () => import("../../types").S3BrowserConfig & {
|
|
20
|
-
credentials: import("../../types").S3Credentials;
|
|
20
|
+
credentials: import("../../types").S3Credentials | import("../../types").S3CredentialProvider;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* Hook to invalidate queries with automatic S3 config identifier prefixing.
|
|
@@ -13,10 +13,12 @@ const DataBrowserContext = /*#__PURE__*/ createContext(DEFAULT_CONTEXT_VALUE);
|
|
|
13
13
|
const useDataBrowserContext = ()=>useContext(DataBrowserContext);
|
|
14
14
|
const DataBrowserProvider = ({ children, queryClient, theme, enableDevtools, getS3Config })=>{
|
|
15
15
|
const currentConfig = getS3Config?.();
|
|
16
|
+
const currentCredentials = currentConfig?.credentials;
|
|
17
|
+
const staticCredentials = 'function' == typeof currentCredentials ? void 0 : currentCredentials;
|
|
16
18
|
const s3ConfigIdentifier = useMemo(()=>currentConfig ? computeS3ConfigIdentifier(currentConfig) : ANONYMOUS_S3_CONFIG_IDENTIFIER, [
|
|
17
19
|
currentConfig?.cacheKey,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
staticCredentials?.accessKeyId,
|
|
21
|
+
staticCredentials?.sessionToken,
|
|
20
22
|
currentConfig?.region,
|
|
21
23
|
currentConfig?.endpoint
|
|
22
24
|
]);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
1
|
+
import { useMemo, useRef } from "react";
|
|
2
2
|
import { useDataBrowserContext } from "../components/providers/DataBrowserProvider.js";
|
|
3
3
|
import { createS3Client } from "../utils/s3Client.js";
|
|
4
4
|
const useS3Client = ()=>{
|
|
5
5
|
const { s3ConfigIdentifier, getS3Config } = useDataBrowserContext();
|
|
6
6
|
if (!getS3Config) throw new Error('useS3Client: S3 config not available. Ensure DataBrowserProvider has getS3Config prop set.');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}, [
|
|
7
|
+
const getS3ConfigRef = useRef(getS3Config);
|
|
8
|
+
getS3ConfigRef.current = getS3Config;
|
|
9
|
+
return useMemo(()=>createS3Client(getS3ConfigRef.current()), [
|
|
11
10
|
s3ConfigIdentifier
|
|
12
11
|
]);
|
|
13
12
|
};
|
|
@@ -36,6 +36,9 @@ const TestErrors = {
|
|
|
36
36
|
accessDenied: ()=>createMockAWSError('AccessDenied', TEST_CONSTANTS.MESSAGES.ACCESS_DENIED, 403),
|
|
37
37
|
internalError: ()=>createMockAWSError('InternalError', TEST_CONSTANTS.MESSAGES.INTERNAL_ERROR, 500),
|
|
38
38
|
serviceUnavailable: ()=>createMockAWSError('ServiceUnavailable', TEST_CONSTANTS.MESSAGES.SERVICE_UNAVAILABLE, 503),
|
|
39
|
+
expiredToken: ()=>createMockAWSError('ExpiredToken', 'The provided token has expired.', 400),
|
|
40
|
+
expiredTokenException: ()=>createMockAWSError('ExpiredTokenException', 'The security token included in the request is expired', 400),
|
|
41
|
+
tokenRefreshRequired: ()=>createMockAWSError('TokenRefreshRequired', 'Token refresh is required', 400),
|
|
39
42
|
abortError: ()=>{
|
|
40
43
|
const error = new Error('Operation aborted');
|
|
41
44
|
Object.defineProperty(error, 'name', {
|
|
@@ -61,7 +64,8 @@ const TestEnhancedErrors = {
|
|
|
61
64
|
auth: ()=>new EnhancedS3Error('Auth error', 'AuthError', ErrorCategory.AUTHORIZATION, new Error()),
|
|
62
65
|
notFound: ()=>new EnhancedS3Error('Not found', 'NotFoundError', ErrorCategory.NOT_FOUND, new Error()),
|
|
63
66
|
cancelled: ()=>new EnhancedS3Error('Cancelled', 'CancelError', ErrorCategory.CANCELLATION, new Error()),
|
|
64
|
-
unknown: ()=>new EnhancedS3Error('Unknown', 'UnknownError', ErrorCategory.UNKNOWN, new Error())
|
|
67
|
+
unknown: ()=>new EnhancedS3Error('Unknown', 'UnknownError', ErrorCategory.UNKNOWN, new Error()),
|
|
68
|
+
expiredCredentials: ()=>new EnhancedS3Error('Token expired', 'ExpiredToken', ErrorCategory.EXPIRED_CREDENTIALS, new Error())
|
|
65
69
|
};
|
|
66
70
|
describe('ErrorCategory', ()=>{
|
|
67
71
|
test('contains all expected categories', ()=>{
|
|
@@ -71,6 +75,7 @@ describe('ErrorCategory', ()=>{
|
|
|
71
75
|
expect(ErrorCategory.CANCELLATION).toBe('CANCELLATION');
|
|
72
76
|
expect(ErrorCategory.AUTHORIZATION).toBe('AUTHORIZATION');
|
|
73
77
|
expect(ErrorCategory.NOT_FOUND).toBe('NOT_FOUND');
|
|
78
|
+
expect(ErrorCategory.EXPIRED_CREDENTIALS).toBe('EXPIRED_CREDENTIALS');
|
|
74
79
|
expect(ErrorCategory.UNKNOWN).toBe('UNKNOWN');
|
|
75
80
|
});
|
|
76
81
|
});
|
|
@@ -102,6 +107,7 @@ describe('EnhancedS3Error', ()=>{
|
|
|
102
107
|
test('returns true for retryable categories', ()=>{
|
|
103
108
|
expect(TestEnhancedErrors.server().shouldRetry()).toBe(true);
|
|
104
109
|
expect(TestEnhancedErrors.network().shouldRetry()).toBe(true);
|
|
110
|
+
expect(TestEnhancedErrors.expiredCredentials().shouldRetry()).toBe(true);
|
|
105
111
|
});
|
|
106
112
|
test('returns false for non-retryable categories', ()=>{
|
|
107
113
|
expect(TestEnhancedErrors.client().shouldRetry()).toBe(false);
|
|
@@ -192,6 +198,29 @@ describe('createS3Error', ()=>{
|
|
|
192
198
|
expect(result.category).toBe(expectedCategory);
|
|
193
199
|
});
|
|
194
200
|
});
|
|
201
|
+
test('handles expired credential errors as retryable', ()=>{
|
|
202
|
+
const testCases = [
|
|
203
|
+
{
|
|
204
|
+
error: TestErrors.expiredToken(),
|
|
205
|
+
expectedName: 'ExpiredToken'
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
error: TestErrors.expiredTokenException(),
|
|
209
|
+
expectedName: 'ExpiredTokenException'
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
error: TestErrors.tokenRefreshRequired(),
|
|
213
|
+
expectedName: 'TokenRefreshRequired'
|
|
214
|
+
}
|
|
215
|
+
];
|
|
216
|
+
testCases.forEach(({ error, expectedName })=>{
|
|
217
|
+
const result = createS3Error(error);
|
|
218
|
+
expect(result.category).toBe(ErrorCategory.EXPIRED_CREDENTIALS);
|
|
219
|
+
expect(result.name).toBe(expectedName);
|
|
220
|
+
expect(result.statusCode).toBe(400);
|
|
221
|
+
expect(result.shouldRetry()).toBe(true);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
195
224
|
test('handles network errors', ()=>{
|
|
196
225
|
const testCases = [
|
|
197
226
|
TestErrors.networkError(),
|
|
@@ -325,6 +354,10 @@ describe('shouldRetryError', ()=>{
|
|
|
325
354
|
error: TestErrors.internalError(),
|
|
326
355
|
shouldRetry: true
|
|
327
356
|
},
|
|
357
|
+
{
|
|
358
|
+
error: TestErrors.expiredToken(),
|
|
359
|
+
shouldRetry: true
|
|
360
|
+
},
|
|
328
361
|
{
|
|
329
362
|
error: TestErrors.invalidRequest(),
|
|
330
363
|
shouldRetry: false
|
package/dist/types/index.d.ts
CHANGED
|
@@ -50,15 +50,20 @@ export interface S3BrowserConfig extends Omit<S3ClientConfig, 'credentials'> {
|
|
|
50
50
|
*/
|
|
51
51
|
export interface S3Credentials extends AwsCredentialIdentity {
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Async credential provider function.
|
|
55
|
+
* The AWS SDK calls this before each request to resolve credentials.
|
|
56
|
+
*/
|
|
57
|
+
export type S3CredentialProvider = () => Promise<S3Credentials>;
|
|
53
58
|
/**
|
|
54
59
|
* Function type that returns the current S3 configuration with credentials.
|
|
55
60
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
61
|
+
* Credentials can be either a static object or an async provider function.
|
|
62
|
+
* When a provider is used, the AWS SDK calls it before each request,
|
|
63
|
+
* allowing transparent credential refresh.
|
|
59
64
|
*/
|
|
60
65
|
export type GetConfigFunction = () => S3BrowserConfig & {
|
|
61
|
-
credentials: S3Credentials;
|
|
66
|
+
credentials: S3Credentials | S3CredentialProvider;
|
|
62
67
|
};
|
|
63
68
|
export type S3ErrorCode = 'AccessDenied' | 'NoSuchBucket' | 'NoSuchKey' | 'InvalidBucketName' | 'BucketNotFound' | 'NetworkError' | 'UnknownError';
|
|
64
69
|
export interface S3Error extends Error {
|
|
@@ -10,6 +10,7 @@ export declare enum ErrorCategory {
|
|
|
10
10
|
CANCELLATION = "CANCELLATION",// User cancelled - don't retry
|
|
11
11
|
AUTHORIZATION = "AUTHORIZATION",// Permission issues - don't retry
|
|
12
12
|
NOT_FOUND = "NOT_FOUND",// Resource doesn't exist - don't retry
|
|
13
|
+
EXPIRED_CREDENTIALS = "EXPIRED_CREDENTIALS",// Temporary credentials expired - can retry
|
|
13
14
|
UNKNOWN = "UNKNOWN"
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
@@ -25,7 +26,7 @@ export declare class EnhancedS3Error extends Error {
|
|
|
25
26
|
constructor(message: string, name: string, category: ErrorCategory, originalError: Error, statusCode?: number, metadata?: S3ServiceException['$metadata'], context?: Record<string, unknown>);
|
|
26
27
|
/**
|
|
27
28
|
* Determines if this error should be retried based on its category.
|
|
28
|
-
*
|
|
29
|
+
* Server errors, network issues, and expired credentials are retryable.
|
|
29
30
|
*/
|
|
30
31
|
shouldRetry(): boolean;
|
|
31
32
|
}
|
|
@@ -6,6 +6,7 @@ var errorHandling_ErrorCategory = /*#__PURE__*/ function(ErrorCategory) {
|
|
|
6
6
|
ErrorCategory["CANCELLATION"] = "CANCELLATION";
|
|
7
7
|
ErrorCategory["AUTHORIZATION"] = "AUTHORIZATION";
|
|
8
8
|
ErrorCategory["NOT_FOUND"] = "NOT_FOUND";
|
|
9
|
+
ErrorCategory["EXPIRED_CREDENTIALS"] = "EXPIRED_CREDENTIALS";
|
|
9
10
|
ErrorCategory["UNKNOWN"] = "UNKNOWN";
|
|
10
11
|
return ErrorCategory;
|
|
11
12
|
}({});
|
|
@@ -26,9 +27,17 @@ class EnhancedS3Error extends Error {
|
|
|
26
27
|
Object.setPrototypeOf(this, EnhancedS3Error.prototype);
|
|
27
28
|
}
|
|
28
29
|
shouldRetry() {
|
|
29
|
-
return "SERVER_ERROR" === this.category || "NETWORK_ERROR" === this.category;
|
|
30
|
+
return "SERVER_ERROR" === this.category || "NETWORK_ERROR" === this.category || "EXPIRED_CREDENTIALS" === this.category;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
33
|
+
const EXPIRED_CREDENTIAL_ERROR_NAMES = new Set([
|
|
34
|
+
'ExpiredToken',
|
|
35
|
+
'ExpiredTokenException',
|
|
36
|
+
'TokenRefreshRequired'
|
|
37
|
+
]);
|
|
38
|
+
function isExpiredCredentialError(errorName) {
|
|
39
|
+
return EXPIRED_CREDENTIAL_ERROR_NAMES.has(errorName);
|
|
40
|
+
}
|
|
32
41
|
function classifyByStatusCode(statusCode) {
|
|
33
42
|
if (statusCode >= 400 && statusCode < 500) {
|
|
34
43
|
if (401 === statusCode || 403 === statusCode) return "AUTHORIZATION";
|
|
@@ -47,6 +56,7 @@ function createS3Error(error, context) {
|
|
|
47
56
|
if (error instanceof Error && 'AbortError' === error.name) return new EnhancedS3Error('Operation was cancelled', 'AbortError', "CANCELLATION", error, void 0, void 0, context);
|
|
48
57
|
if (error instanceof NoSuchBucket || error instanceof NoSuchKey || error instanceof NoSuchUpload) return new EnhancedS3Error(error.message, error.name, "NOT_FOUND", error, error.$metadata?.httpStatusCode, error.$metadata, context);
|
|
49
58
|
if (error instanceof InvalidRequest || error instanceof InvalidObjectState || error instanceof InvalidWriteOffset || error instanceof ObjectAlreadyInActiveTierError || error instanceof ObjectNotInActiveTierError) return new EnhancedS3Error(error.message, error.name, "CLIENT_ERROR", error, error.$metadata?.httpStatusCode, error.$metadata, context);
|
|
59
|
+
if (isS3ServiceException(error) && isExpiredCredentialError(error.name)) return new EnhancedS3Error(error.message, error.name, "EXPIRED_CREDENTIALS", error, error.$metadata?.httpStatusCode, error.$metadata, context);
|
|
50
60
|
if (isS3ServiceException(error)) {
|
|
51
61
|
const category = error.$metadata?.httpStatusCode ? classifyByStatusCode(error.$metadata.httpStatusCode) : "UNKNOWN";
|
|
52
62
|
return new EnhancedS3Error(error.message, error.name, category, error, error.$metadata?.httpStatusCode, error.$metadata, context);
|
package/dist/utils/s3Client.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
* S3Client configuration with credentials
|
|
5
|
-
*/
|
|
6
|
-
export interface S3ClientConfigWithProxy extends S3BrowserConfig {
|
|
7
|
-
credentials: S3Credentials;
|
|
8
|
-
}
|
|
2
|
+
import type { GetConfigFunction } from '../types';
|
|
9
3
|
/**
|
|
10
4
|
* Create S3 client with optional proxy middleware
|
|
11
5
|
*
|
|
12
|
-
* @param config - S3 configuration with credentials and optional proxy config
|
|
6
|
+
* @param config - S3 configuration with credentials (static or provider) and optional proxy config
|
|
13
7
|
* @returns Configured S3Client instance
|
|
14
8
|
*/
|
|
15
|
-
export declare const createS3Client: (config:
|
|
9
|
+
export declare const createS3Client: (config: ReturnType<GetConfigFunction>) => S3Client;
|
|
@@ -38,13 +38,16 @@ const computeS3ConfigIdentifier = (config, fallbackIdentifier = ANONYMOUS_S3_CON
|
|
|
38
38
|
const cacheKey = config?.cacheKey?.trim();
|
|
39
39
|
if (cacheKey) parts.push(cacheKey);
|
|
40
40
|
else {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
41
|
+
const credentials = config?.credentials;
|
|
42
|
+
if ('object' == typeof credentials && null !== credentials) {
|
|
43
|
+
const accessKeyId = credentials.accessKeyId?.trim();
|
|
44
|
+
if (accessKeyId) {
|
|
45
|
+
parts.push(accessKeyId);
|
|
46
|
+
const sessionToken = credentials.sessionToken?.trim();
|
|
47
|
+
if (sessionToken) {
|
|
48
|
+
const hash = hashSessionToken(sessionToken);
|
|
49
|
+
parts.push(`session:${hash}`);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scality/data-browser-library",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "A modular React component library for browsing S3 buckets and objects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"jest": "^30.0.5",
|
|
62
62
|
"jest-environment-jsdom": "^30.0.5",
|
|
63
63
|
"msw": "^2.12.3",
|
|
64
|
-
"ts-jest": "^29.4.
|
|
64
|
+
"ts-jest": "^29.4.6"
|
|
65
65
|
},
|
|
66
66
|
"repository": {
|
|
67
67
|
"type": "git",
|