1
/*
2
 * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
 * the License. A copy of the License is located at
6
 *
7
 *     http://aws.amazon.com/apache2.0/
8
 *
9
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
 * and limitations under the License.
12
 */
13

14 1
import { Storage as StorageClass } from './Storage';
15

16 1
import { Amplify, ConsoleLogger as Logger } from '@aws-amplify/core';
17

18 1
const logger = new Logger('Storage');
19

20 1
let _instance: StorageClass = null;
21

22 1
const getInstance = () => {
23 1
	if (_instance) {
24 0
		return _instance;
25
	}
26 1
	logger.debug('Create Storage Instance, debug');
27 1
	_instance = new StorageClass();
28 1
	_instance.vault = new StorageClass();
29

30 1
	const old_configure = _instance.configure;
31 1
	_instance.configure = options => {
32 1
		logger.debug('storage configure called');
33 1
		const vaultConfig = { ...old_configure.call(_instance, options) };
34

35
		// set level private for each provider for the vault
36 1
		Object.keys(vaultConfig).forEach(providerName => {
37 1
			if (typeof vaultConfig[providerName] !== 'string') {
38 1
				vaultConfig[providerName] = {
39
					...vaultConfig[providerName],
40
					level: 'private',
41
				};
42
			}
43
		});
44 1
		logger.debug('storage vault configure called');
45 1
		_instance.vault.configure(vaultConfig);
46
	};
47 1
	return _instance;
48
};
49

50 1
export const Storage: StorageClass = getInstance();
51 1
Amplify.register(Storage);
52

53
/**
54
 * @deprecated use named import
55
 */
56 1
export default Storage;
57

58 1
export { StorageClass };
59 1
export * from './providers';
60
export * from './types';

Read our documentation on viewing source code .

Loading