@aws-amplify/core 6.0.1-console-preview.047a1dd.0 → 6.0.1-next.054df96.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.
Files changed (122) hide show
  1. package/lib/Cache/Utils/CacheUtils.js +4 -2
  2. package/lib/Platform/version.d.ts +1 -1
  3. package/lib/Platform/version.js +1 -1
  4. package/lib/RNComponents/index.d.ts +6 -0
  5. package/lib/RNComponents/index.js +16 -0
  6. package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.js +4 -1
  7. package/lib/RNComponents/reactnative.d.ts +3 -0
  8. package/lib/RNComponents/reactnative.js +14 -0
  9. package/lib/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
  10. package/lib/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +83 -35
  11. package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
  12. package/lib/StorageHelper/inMemoryStorage.js +82 -0
  13. package/lib/StorageHelper/index.d.ts +45 -0
  14. package/lib/StorageHelper/index.js +83 -0
  15. package/lib/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  16. package/lib/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +15 -13
  17. package/lib/StorageHelper/reactnative.d.ts +83 -0
  18. package/lib/StorageHelper/reactnative.js +250 -0
  19. package/lib/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  20. package/lib/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +43 -46
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.js +8 -6
  23. package/lib/libraryUtils.d.ts +1 -0
  24. package/lib/libraryUtils.js +5 -1
  25. package/lib/parseAWSExports.js +1 -20
  26. package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
  27. package/lib/singleton/types.d.ts +1 -4
  28. package/lib/tsconfig.tsbuildinfo +1 -1
  29. package/lib/types/storage.d.ts +0 -3
  30. package/lib-esm/Cache/Utils/CacheUtils.js +4 -2
  31. package/lib-esm/Platform/version.d.ts +1 -1
  32. package/lib-esm/Platform/version.js +1 -1
  33. package/lib-esm/RNComponents/index.d.ts +6 -0
  34. package/lib-esm/RNComponents/index.js +13 -0
  35. package/lib-esm/RNComponents/isAppInForeground.js +6 -0
  36. package/lib-esm/RNComponents/reactnative.d.ts +3 -0
  37. package/lib-esm/RNComponents/reactnative.js +6 -0
  38. package/lib-esm/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
  39. package/lib-esm/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +61 -36
  40. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
  41. package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
  42. package/lib-esm/StorageHelper/index.d.ts +45 -0
  43. package/lib-esm/StorageHelper/index.js +76 -0
  44. package/lib-esm/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  45. package/lib-esm/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +14 -12
  46. package/lib-esm/StorageHelper/reactnative.d.ts +83 -0
  47. package/lib-esm/StorageHelper/reactnative.js +244 -0
  48. package/lib-esm/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  49. package/lib-esm/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +42 -45
  50. package/lib-esm/index.d.ts +1 -1
  51. package/lib-esm/index.js +1 -1
  52. package/lib-esm/libraryUtils.d.ts +1 -0
  53. package/lib-esm/libraryUtils.js +1 -0
  54. package/lib-esm/parseAWSExports.js +1 -20
  55. package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
  56. package/lib-esm/singleton/types.d.ts +1 -4
  57. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  58. package/lib-esm/types/storage.d.ts +0 -3
  59. package/package.json +4 -3
  60. package/src/Cache/Utils/CacheUtils.ts +4 -2
  61. package/src/Platform/version.ts +1 -1
  62. package/src/RNComponents/index.ts +16 -0
  63. package/src/RNComponents/isAppInForeground.ts +8 -0
  64. package/src/RNComponents/reactnative.ts +6 -0
  65. package/src/StorageHelper/cookieStorage.ts +99 -0
  66. package/src/StorageHelper/inMemoryStorage.ts +32 -0
  67. package/src/StorageHelper/index.ts +78 -0
  68. package/src/StorageHelper/localStorage.ts +60 -0
  69. package/src/StorageHelper/reactnative.ts +182 -0
  70. package/src/{storage/KeyValueStorage.ts → StorageHelper/sessionStorage.ts} +13 -10
  71. package/src/index.ts +6 -4
  72. package/src/libraryUtils.ts +1 -0
  73. package/src/parseAWSExports.ts +0 -26
  74. package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +12 -16
  75. package/src/singleton/types.ts +1 -4
  76. package/src/types/storage.ts +0 -4
  77. package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
  78. package/lib/providers/pinpoint/utils/isAppInForeground.native.js +0 -9
  79. package/lib/singleton/API/types.d.ts +0 -34
  80. package/lib/singleton/API/types.js +0 -2
  81. package/lib/storage/CookieStorage.native.d.ts +0 -7
  82. package/lib/storage/CookieStorage.native.js +0 -32
  83. package/lib/storage/DefaultStorage.d.ts +0 -7
  84. package/lib/storage/DefaultStorage.js +0 -33
  85. package/lib/storage/InMemoryStorage.d.ts +0 -12
  86. package/lib/storage/InMemoryStorage.js +0 -41
  87. package/lib/storage/SessionStorage.d.ts +0 -7
  88. package/lib/storage/SessionStorage.js +0 -33
  89. package/lib/storage/index.d.ts +0 -7
  90. package/lib/storage/index.js +0 -14
  91. package/lib/storage/utils.d.ts +0 -10
  92. package/lib/storage/utils.js +0 -26
  93. package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +0 -3
  94. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
  95. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +0 -5
  96. package/lib-esm/singleton/API/types.d.ts +0 -34
  97. package/lib-esm/singleton/API/types.js +0 -1
  98. package/lib-esm/storage/CookieStorage.native.d.ts +0 -7
  99. package/lib-esm/storage/CookieStorage.native.js +0 -29
  100. package/lib-esm/storage/DefaultStorage.d.ts +0 -7
  101. package/lib-esm/storage/DefaultStorage.js +0 -30
  102. package/lib-esm/storage/InMemoryStorage.d.ts +0 -12
  103. package/lib-esm/storage/InMemoryStorage.js +0 -38
  104. package/lib-esm/storage/SessionStorage.d.ts +0 -7
  105. package/lib-esm/storage/SessionStorage.js +0 -30
  106. package/lib-esm/storage/index.d.ts +0 -7
  107. package/lib-esm/storage/index.js +0 -10
  108. package/lib-esm/storage/utils.d.ts +0 -10
  109. package/lib-esm/storage/utils.js +0 -21
  110. package/src/providers/pinpoint/utils/isAppInForeground.native.ts +0 -7
  111. package/src/providers/pinpoint/utils/isAppInForeground.ts +0 -4
  112. package/src/singleton/API/types.ts +0 -31
  113. package/src/storage/CookieStorage.native.ts +0 -13
  114. package/src/storage/CookieStorage.ts +0 -72
  115. package/src/storage/DefaultStorage.native.ts +0 -78
  116. package/src/storage/DefaultStorage.ts +0 -14
  117. package/src/storage/InMemoryStorage.ts +0 -36
  118. package/src/storage/SessionStorage.ts +0 -14
  119. package/src/storage/index.ts +0 -13
  120. package/src/storage/utils.ts +0 -22
  121. /package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
  122. /package/lib-esm/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
@@ -1,31 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export type LibraryAPIOptions = {
4
- AppSync: {
5
- query: string;
6
- variables?: object;
7
- authMode?: any;
8
- authToken?: string;
9
- /**
10
- * @deprecated This property should not be used
11
- */
12
- userAgentSuffix?: string;
13
- };
14
- customHeaders: Function;
15
- };
16
-
17
- export type APIConfig = {
18
- AppSync?: {
19
- defaultAuthMode?: GraphQLAuthMode;
20
- region?: string;
21
- endpoint?: string;
22
- modelIntrospectionSchema?: any;
23
- };
24
- };
25
-
26
- export type GraphQLAuthMode =
27
- | { type: 'apiKey'; apiKey: string }
28
- | { type: 'jwt'; token: 'id' | 'access' }
29
- | { type: 'iam' }
30
- | { type: 'lambda' }
31
- | { type: 'custom' };
@@ -1,13 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { KeyValueStorage } from './KeyValueStorage';
5
-
6
- /**
7
- * @internal
8
- */
9
- export class CookieStorage extends KeyValueStorage {
10
- constructor() {
11
- super();
12
- }
13
- }
@@ -1,72 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import {
5
- get as getJsCookie,
6
- remove as removeJsCookie,
7
- set as setJsCookie,
8
- } from 'js-cookie';
9
- import {
10
- CookieStorageData,
11
- KeyValueStorageInterface,
12
- SameSite,
13
- } from '../types';
14
-
15
- export class CookieStorage implements KeyValueStorageInterface {
16
- path: string;
17
- domain?: string;
18
- expires?: number;
19
- sameSite?: SameSite;
20
- secure?: boolean;
21
-
22
- constructor(data: CookieStorageData = {}) {
23
- const { path, domain, expires, sameSite, secure } = data;
24
- this.domain = domain;
25
- this.path = path ? path : '/';
26
- this.expires = data.hasOwnProperty('expires') ? expires : 365;
27
- this.secure = data.hasOwnProperty('secure') ? secure : true;
28
-
29
- if (data.hasOwnProperty('sameSite')) {
30
- if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
31
- throw new Error(
32
- 'The sameSite value of cookieStorage must be "lax", "strict" or "none".'
33
- );
34
- }
35
- if (sameSite === 'none' && !this.secure) {
36
- throw new Error(
37
- 'sameSite = None requires the Secure attribute in latest browser versions.'
38
- );
39
- }
40
- this.sameSite = sameSite;
41
- }
42
- }
43
-
44
- async setItem(key: string, value: string) {
45
- setJsCookie(key, value, this.getData());
46
- }
47
-
48
- async getItem(key: string) {
49
- const item = getJsCookie(key);
50
- return item ?? null;
51
- }
52
-
53
- async removeItem(key: string) {
54
- removeJsCookie(key, this.getData());
55
- }
56
-
57
- async clear() {
58
- const cookie = getJsCookie();
59
- const promises = Object.keys(cookie).map(key => this.removeItem(key));
60
- await Promise.all(promises);
61
- }
62
-
63
- private getData(): CookieStorageData {
64
- return {
65
- path: this.path,
66
- expires: this.expires,
67
- domain: this.domain,
68
- secure: this.secure,
69
- ...(this.sameSite && { sameSite: this.sameSite }),
70
- };
71
- }
72
- }
@@ -1,78 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
5
- import { AmplifyError } from '../libraryUtils';
6
- import { KeyValueStorageInterface } from '../types';
7
-
8
- const ASYNC_STORAGE_MODULE = '@react-native-async-storage/async-storage';
9
- const MEMORY_KEY_PREFIX = '@MemoryStorage:';
10
-
11
- /**
12
- * @internal
13
- */
14
- export class DefaultStorage implements KeyValueStorageInterface {
15
- private asyncStorage?: AsyncStorageStatic;
16
-
17
- /**
18
- * This is used to set a specific item in storage
19
- * @param {string} key - the key for the item
20
- * @param {object} value - the value
21
- * @returns {string} value that was set
22
- */
23
- setItem(key: string, value: string) {
24
- this.assertModule(this.asyncStorage);
25
- return this.asyncStorage.setItem(`${MEMORY_KEY_PREFIX}${key}`, value);
26
- }
27
-
28
- /**
29
- * This is used to get a specific key from storage
30
- * @param {string} key - the key for the item
31
- * This is used to clear the storage
32
- * @returns {string} the data item
33
- */
34
- getItem(key: string) {
35
- this.assertModule(this.asyncStorage);
36
- return this.asyncStorage.getItem(`${MEMORY_KEY_PREFIX}${key}`);
37
- }
38
-
39
- /**
40
- * This is used to remove an item from storage
41
- * @param {string} key - the key being set
42
- * @returns {string} value - value that was deleted
43
- */
44
- removeItem(key: string): Promise<void> {
45
- this.assertModule(this.asyncStorage);
46
- return this.asyncStorage.removeItem(`${MEMORY_KEY_PREFIX}${key}`);
47
- }
48
-
49
- /**
50
- * This is used to clear the storage
51
- * @returns {string} nothing
52
- */
53
- async clear(): Promise<void> {
54
- this.assertModule(this.asyncStorage);
55
- const allKeys = await this.asyncStorage.getAllKeys();
56
- return this.asyncStorage.multiRemove(
57
- allKeys.filter(key => key.startsWith(MEMORY_KEY_PREFIX))
58
- );
59
- }
60
-
61
- private assertModule(
62
- asyncStorage?: AsyncStorageStatic
63
- ): asserts asyncStorage {
64
- if (!!asyncStorage) {
65
- return;
66
- }
67
- try {
68
- this.asyncStorage = require(ASYNC_STORAGE_MODULE)
69
- .default as AsyncStorageStatic;
70
- } catch (err) {
71
- throw new AmplifyError({
72
- name: 'NativeModuleException',
73
- message: `Unable to find ${ASYNC_STORAGE_MODULE}`,
74
- recoverySuggestion: `Make sure to install ${ASYNC_STORAGE_MODULE}`,
75
- });
76
- }
77
- }
78
- }
@@ -1,14 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { KeyValueStorage } from './KeyValueStorage';
5
- import { getDefaultStorageWithFallback } from './utils';
6
-
7
- /**
8
- * @internal
9
- */
10
- export class DefaultStorage extends KeyValueStorage {
11
- constructor() {
12
- super(getDefaultStorageWithFallback());
13
- }
14
- }
@@ -1,36 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /**
5
- * @internal
6
- */
7
- export class InMemoryStorage implements Storage {
8
- storage = new Map<string, string>();
9
-
10
- get length() {
11
- return this.storage.size;
12
- }
13
-
14
- key(index: number) {
15
- if (index > this.length - 1) {
16
- return null;
17
- }
18
- return Array.from(this.storage.keys())[index];
19
- }
20
-
21
- setItem(key: string, value: string) {
22
- this.storage.set(key, value);
23
- }
24
-
25
- getItem(key: string) {
26
- return this.storage.get(key) ?? null;
27
- }
28
-
29
- removeItem(key: string) {
30
- this.storage.delete(key);
31
- }
32
-
33
- clear() {
34
- this.storage.clear();
35
- }
36
- }
@@ -1,14 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { KeyValueStorage } from './KeyValueStorage';
5
- import { getSessionStorageWithFallback } from './utils';
6
-
7
- /**
8
- * @internal
9
- */
10
- export class SessionStorage extends KeyValueStorage {
11
- constructor() {
12
- super(getSessionStorageWithFallback());
13
- }
14
- }
@@ -1,13 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { DefaultStorage } from './DefaultStorage';
5
- import { InMemoryStorage } from './InMemoryStorage';
6
- import { KeyValueStorage } from './KeyValueStorage';
7
- import { SessionStorage } from './SessionStorage';
8
-
9
- export { CookieStorage } from './CookieStorage';
10
-
11
- export const defaultStorage = new DefaultStorage();
12
- export const sessionStorage = new SessionStorage();
13
- export const sharedInMemoryStorage = new KeyValueStorage(new InMemoryStorage());
@@ -1,22 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { InMemoryStorage } from './InMemoryStorage';
5
-
6
- /**
7
- * @internal
8
- * @returns Either a reference to window.localStorage or an in-memory storage as fallback
9
- */
10
- export const getDefaultStorageWithFallback = (): Storage =>
11
- typeof window !== 'undefined' && window.localStorage
12
- ? window.localStorage
13
- : new InMemoryStorage();
14
-
15
- /**
16
- * @internal
17
- * @returns Either a reference to window.sessionStorage or an in-memory storage as fallback
18
- */
19
- export const getSessionStorageWithFallback = (): Storage =>
20
- typeof window !== 'undefined' && window.sessionStorage
21
- ? window.sessionStorage
22
- : new InMemoryStorage();