@aws-amplify/core 6.0.1-console-preview.5a31ca1.0 → 6.0.1-console-preview.8f82e46.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/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/ServiceWorker/ServiceWorker.js +69 -17
- package/lib/ServiceWorker/index.d.ts +0 -12
- package/lib/ServiceWorker/index.js +0 -12
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -1
- package/lib/libraryUtils.d.ts +0 -1
- package/lib/libraryUtils.js +2 -5
- package/lib/providers/pinpoint/types/pinpoint.d.ts +1 -1
- package/lib/singleton/Auth/types.d.ts +2 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/ServiceWorker/ServiceWorker.js +69 -17
- package/lib-esm/ServiceWorker/index.d.ts +0 -12
- package/lib-esm/ServiceWorker/index.js +0 -12
- package/lib-esm/index.d.ts +1 -0
- package/lib-esm/index.js +2 -0
- package/lib-esm/libraryUtils.d.ts +0 -1
- package/lib-esm/libraryUtils.js +0 -2
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +1 -1
- package/lib-esm/singleton/Auth/types.d.ts +2 -2
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Platform/version.ts +1 -1
- package/src/ServiceWorker/ServiceWorker.ts +20 -17
- package/src/ServiceWorker/index.ts +0 -12
- package/src/index.ts +3 -0
- package/src/libraryUtils.ts +0 -3
- package/src/providers/pinpoint/types/pinpoint.ts +1 -0
- package/src/singleton/Auth/types.ts +2 -2
- package/lib/Amplify.d.ts +0 -29
- package/lib/Amplify.js +0 -118
- package/lib-esm/Amplify.d.ts +0 -29
- package/lib-esm/Amplify.js +0 -115
- package/src/Amplify.ts +0 -106
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/core",
|
|
3
|
-
"version": "6.0.1-console-preview.
|
|
3
|
+
"version": "6.0.1-console-preview.8f82e46.0+8f82e46",
|
|
4
4
|
"description": "Core category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"uuid": "^9.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@aws-amplify/react-native": "1.0.1-console-preview.
|
|
67
|
+
"@aws-amplify/react-native": "1.0.1-console-preview.8f82e46.0+8f82e46",
|
|
68
68
|
"@types/js-cookie": "3.0.2",
|
|
69
69
|
"@types/uuid": "^9.0.0",
|
|
70
70
|
"find": "^0.2.7",
|
|
@@ -169,5 +169,5 @@
|
|
|
169
169
|
"lib-esm"
|
|
170
170
|
]
|
|
171
171
|
},
|
|
172
|
-
"gitHead": "
|
|
172
|
+
"gitHead": "8f82e460c4cdb9e52e0ba7ed8aea90f627a27693"
|
|
173
173
|
}
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '6.0.1-console-preview.
|
|
2
|
+
export const version = '6.0.1-console-preview.8f82e46.0+8f82e46';
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { ConsoleLogger as Logger } from '../Logger';
|
|
5
5
|
import { isBrowser } from '../utils';
|
|
6
|
-
import { Amplify } from '../Amplify';
|
|
7
6
|
import { AmplifyError } from '../errors';
|
|
8
7
|
import { assert, ServiceWorkerErrorCode } from './errorHelpers';
|
|
8
|
+
import { record } from '../providers/pinpoint';
|
|
9
|
+
import { Amplify, fetchAuthSession } from '../singleton';
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* Provides a means to registering a service worker in the browser
|
|
11
13
|
* and communicating with it via postMessage events.
|
|
@@ -205,15 +207,25 @@ export class ServiceWorkerClass {
|
|
|
205
207
|
* https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/state
|
|
206
208
|
**/
|
|
207
209
|
_setupListeners() {
|
|
208
|
-
this.serviceWorker.addEventListener('statechange', event => {
|
|
210
|
+
this.serviceWorker.addEventListener('statechange', async event => {
|
|
209
211
|
const currentState = this.serviceWorker.state;
|
|
210
212
|
this._logger.debug(`ServiceWorker statechange: ${currentState}`);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
|
|
214
|
+
const { appId, region } = Amplify.getConfig().Analytics?.Pinpoint ?? {};
|
|
215
|
+
const { credentials } = await fetchAuthSession();
|
|
216
|
+
|
|
217
|
+
if (appId && region && credentials) {
|
|
218
|
+
// Pinpoint is configured, record an event
|
|
219
|
+
record({
|
|
220
|
+
appId,
|
|
221
|
+
region,
|
|
222
|
+
category: 'Core',
|
|
223
|
+
credentials,
|
|
224
|
+
event: {
|
|
225
|
+
name: 'ServiceWorker',
|
|
226
|
+
attributes: {
|
|
227
|
+
state: currentState,
|
|
228
|
+
},
|
|
217
229
|
},
|
|
218
230
|
});
|
|
219
231
|
}
|
|
@@ -223,12 +235,3 @@ export class ServiceWorkerClass {
|
|
|
223
235
|
});
|
|
224
236
|
}
|
|
225
237
|
}
|
|
226
|
-
|
|
227
|
-
type AmplifyWithAnalytics = {
|
|
228
|
-
Analytics: {
|
|
229
|
-
record: Function;
|
|
230
|
-
};
|
|
231
|
-
};
|
|
232
|
-
function isAmplifyWithAnalytics(amplify: any): amplify is AmplifyWithAnalytics {
|
|
233
|
-
return amplify.Analytics && typeof amplify.Analytics.record === 'function';
|
|
234
|
-
}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
7
|
-
* the License. A copy of the License is located at
|
|
8
|
-
*
|
|
9
|
-
* http://aws.amazon.com/apache2.0/
|
|
10
|
-
*
|
|
11
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
12
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
13
|
-
* and limitations under the License.
|
|
14
|
-
*/
|
|
15
3
|
|
|
16
4
|
export { ServiceWorkerClass as ServiceWorker } from './ServiceWorker';
|
package/src/index.ts
CHANGED
package/src/libraryUtils.ts
CHANGED
|
@@ -71,9 +71,6 @@ export {
|
|
|
71
71
|
} from './Platform/types';
|
|
72
72
|
export { setCustomUserAgent } from './Platform/customUserAgent';
|
|
73
73
|
|
|
74
|
-
// Service worker
|
|
75
|
-
export { ServiceWorker } from './ServiceWorker';
|
|
76
|
-
|
|
77
74
|
// Other utilities & constants
|
|
78
75
|
export { BackgroundProcessManager } from './BackgroundProcessManager';
|
|
79
76
|
export { Mutex } from './Mutex';
|
|
@@ -113,12 +113,12 @@ export type AuthIdentityPoolConfig = {
|
|
|
113
113
|
Cognito: CognitoIdentityPoolConfig & {
|
|
114
114
|
userPoolClientId?: never;
|
|
115
115
|
userPoolId?: never;
|
|
116
|
+
userPoolEndpoint?: never;
|
|
116
117
|
loginWith?: never;
|
|
117
118
|
signUpVerificationMethod?: never;
|
|
118
119
|
userAttributes?: never;
|
|
119
120
|
mfa?: never;
|
|
120
121
|
passwordFormat?: never;
|
|
121
|
-
endpoint?: never;
|
|
122
122
|
};
|
|
123
123
|
};
|
|
124
124
|
|
|
@@ -137,6 +137,7 @@ export type AuthUserPoolConfig = {
|
|
|
137
137
|
export type CognitoUserPoolConfig = {
|
|
138
138
|
userPoolClientId: string;
|
|
139
139
|
userPoolId: string;
|
|
140
|
+
userPoolEndpoint?: string;
|
|
140
141
|
signUpVerificationMethod?: 'code' | 'link';
|
|
141
142
|
loginWith?: {
|
|
142
143
|
oauth?: OAuthConfig;
|
|
@@ -157,7 +158,6 @@ export type CognitoUserPoolConfig = {
|
|
|
157
158
|
requireNumbers?: boolean;
|
|
158
159
|
requireSpecialCharacters?: boolean;
|
|
159
160
|
};
|
|
160
|
-
endpoint?: string;
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
export type OAuthConfig = {
|
package/lib/Amplify.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ConsoleLogger as LoggerClass } from './Logger';
|
|
2
|
-
export declare class AmplifyClass {
|
|
3
|
-
private _components;
|
|
4
|
-
private _config;
|
|
5
|
-
private _modules;
|
|
6
|
-
Auth: null;
|
|
7
|
-
Analytics: null;
|
|
8
|
-
API: null;
|
|
9
|
-
Credentials: null;
|
|
10
|
-
Storage: null;
|
|
11
|
-
I18n: null;
|
|
12
|
-
Cache: null;
|
|
13
|
-
PubSub: null;
|
|
14
|
-
Interactions: null;
|
|
15
|
-
Pushnotification: null;
|
|
16
|
-
UI: null;
|
|
17
|
-
XR: null;
|
|
18
|
-
Predictions: null;
|
|
19
|
-
DataStore: null;
|
|
20
|
-
Geo: null;
|
|
21
|
-
Notifications: null;
|
|
22
|
-
Logger: typeof LoggerClass;
|
|
23
|
-
ServiceWorker: null;
|
|
24
|
-
get config(): any;
|
|
25
|
-
register(comp: any): void;
|
|
26
|
-
configure(config?: any): {};
|
|
27
|
-
addPluggable(pluggable: any): void;
|
|
28
|
-
}
|
|
29
|
-
export declare const Amplify: AmplifyClass;
|
package/lib/Amplify.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.Amplify = exports.AmplifyClass = void 0;
|
|
20
|
-
// @ts-nocheck
|
|
21
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
22
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
23
|
-
var Logger_1 = require("./Logger");
|
|
24
|
-
var logger = new Logger_1.ConsoleLogger('Amplify');
|
|
25
|
-
var AmplifyClass = /** @class */ (function () {
|
|
26
|
-
function AmplifyClass() {
|
|
27
|
-
// Everything that is `register`ed is tracked here
|
|
28
|
-
this._components = [];
|
|
29
|
-
this._config = {};
|
|
30
|
-
// All modules (with `getModuleName()`) are stored here for dependency injection
|
|
31
|
-
this._modules = {};
|
|
32
|
-
// for backward compatibility to avoid breaking change
|
|
33
|
-
// if someone is using like Amplify.Auth
|
|
34
|
-
this.Auth = null;
|
|
35
|
-
this.Analytics = null;
|
|
36
|
-
this.API = null;
|
|
37
|
-
this.Credentials = null;
|
|
38
|
-
this.Storage = null;
|
|
39
|
-
this.I18n = null;
|
|
40
|
-
this.Cache = null;
|
|
41
|
-
this.PubSub = null;
|
|
42
|
-
this.Interactions = null;
|
|
43
|
-
this.Pushnotification = null;
|
|
44
|
-
this.UI = null;
|
|
45
|
-
this.XR = null;
|
|
46
|
-
this.Predictions = null;
|
|
47
|
-
this.DataStore = null;
|
|
48
|
-
this.Geo = null;
|
|
49
|
-
this.Notifications = null;
|
|
50
|
-
this.Logger = Logger_1.ConsoleLogger;
|
|
51
|
-
this.ServiceWorker = null;
|
|
52
|
-
}
|
|
53
|
-
Object.defineProperty(AmplifyClass.prototype, "config", {
|
|
54
|
-
// TODO: update "any" when types are determined
|
|
55
|
-
get: function () {
|
|
56
|
-
return Object.assign({}, this._config);
|
|
57
|
-
},
|
|
58
|
-
enumerable: false,
|
|
59
|
-
configurable: true
|
|
60
|
-
});
|
|
61
|
-
AmplifyClass.prototype.register = function (comp) {
|
|
62
|
-
logger.debug('component registered in amplify', comp);
|
|
63
|
-
this._components.push(comp);
|
|
64
|
-
if (typeof comp.getModuleName === 'function') {
|
|
65
|
-
this._modules[comp.getModuleName()] = comp;
|
|
66
|
-
this[comp.getModuleName()] = comp;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
logger.debug('no getModuleName method for component', comp);
|
|
70
|
-
}
|
|
71
|
-
// Finally configure this new component(category) loaded
|
|
72
|
-
// With the new modularization changes in Amplify V3, all the Amplify
|
|
73
|
-
// component are not loaded/registered right away but when they are
|
|
74
|
-
// imported (and hence instantiated) in the client's app. This ensures
|
|
75
|
-
// that all new components imported get correctly configured with the
|
|
76
|
-
// configuration that Amplify.configure() was called with.
|
|
77
|
-
comp.configure(this._config);
|
|
78
|
-
};
|
|
79
|
-
AmplifyClass.prototype.configure = function (config) {
|
|
80
|
-
var _this = this;
|
|
81
|
-
if (!config)
|
|
82
|
-
return this._config;
|
|
83
|
-
this._config = Object.assign(this._config, config);
|
|
84
|
-
logger.debug('amplify config', this._config);
|
|
85
|
-
// Dependency Injection via property-setting.
|
|
86
|
-
// This avoids introducing a public method/interface/setter that's difficult to remove later.
|
|
87
|
-
// Plus, it reduces `if` statements within the `constructor` and `configure` of each module
|
|
88
|
-
Object.entries(this._modules).forEach(function (_a) {
|
|
89
|
-
var _b = __read(_a, 2), Name = _b[0], comp = _b[1];
|
|
90
|
-
// e.g. Auth.*
|
|
91
|
-
Object.keys(comp).forEach(function (property) {
|
|
92
|
-
// e.g. Auth["Credentials"] = this._modules["Credentials"] when set
|
|
93
|
-
if (_this._modules[property]) {
|
|
94
|
-
comp[property] = _this._modules[property];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
this._components.map(function (comp) {
|
|
99
|
-
comp.configure(_this._config);
|
|
100
|
-
});
|
|
101
|
-
return this._config;
|
|
102
|
-
};
|
|
103
|
-
AmplifyClass.prototype.addPluggable = function (pluggable) {
|
|
104
|
-
if (pluggable &&
|
|
105
|
-
pluggable['getCategory'] &&
|
|
106
|
-
typeof pluggable['getCategory'] === 'function') {
|
|
107
|
-
this._components.map(function (comp) {
|
|
108
|
-
if (comp['addPluggable'] &&
|
|
109
|
-
typeof comp['addPluggable'] === 'function') {
|
|
110
|
-
comp.addPluggable(pluggable);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
return AmplifyClass;
|
|
116
|
-
}());
|
|
117
|
-
exports.AmplifyClass = AmplifyClass;
|
|
118
|
-
exports.Amplify = new AmplifyClass();
|
package/lib-esm/Amplify.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ConsoleLogger as LoggerClass } from './Logger';
|
|
2
|
-
export declare class AmplifyClass {
|
|
3
|
-
private _components;
|
|
4
|
-
private _config;
|
|
5
|
-
private _modules;
|
|
6
|
-
Auth: null;
|
|
7
|
-
Analytics: null;
|
|
8
|
-
API: null;
|
|
9
|
-
Credentials: null;
|
|
10
|
-
Storage: null;
|
|
11
|
-
I18n: null;
|
|
12
|
-
Cache: null;
|
|
13
|
-
PubSub: null;
|
|
14
|
-
Interactions: null;
|
|
15
|
-
Pushnotification: null;
|
|
16
|
-
UI: null;
|
|
17
|
-
XR: null;
|
|
18
|
-
Predictions: null;
|
|
19
|
-
DataStore: null;
|
|
20
|
-
Geo: null;
|
|
21
|
-
Notifications: null;
|
|
22
|
-
Logger: typeof LoggerClass;
|
|
23
|
-
ServiceWorker: null;
|
|
24
|
-
get config(): any;
|
|
25
|
-
register(comp: any): void;
|
|
26
|
-
configure(config?: any): {};
|
|
27
|
-
addPluggable(pluggable: any): void;
|
|
28
|
-
}
|
|
29
|
-
export declare const Amplify: AmplifyClass;
|
package/lib-esm/Amplify.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
// @ts-nocheck
|
|
18
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
19
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
-
import { ConsoleLogger as LoggerClass } from './Logger';
|
|
21
|
-
var logger = new LoggerClass('Amplify');
|
|
22
|
-
var AmplifyClass = /** @class */ (function () {
|
|
23
|
-
function AmplifyClass() {
|
|
24
|
-
// Everything that is `register`ed is tracked here
|
|
25
|
-
this._components = [];
|
|
26
|
-
this._config = {};
|
|
27
|
-
// All modules (with `getModuleName()`) are stored here for dependency injection
|
|
28
|
-
this._modules = {};
|
|
29
|
-
// for backward compatibility to avoid breaking change
|
|
30
|
-
// if someone is using like Amplify.Auth
|
|
31
|
-
this.Auth = null;
|
|
32
|
-
this.Analytics = null;
|
|
33
|
-
this.API = null;
|
|
34
|
-
this.Credentials = null;
|
|
35
|
-
this.Storage = null;
|
|
36
|
-
this.I18n = null;
|
|
37
|
-
this.Cache = null;
|
|
38
|
-
this.PubSub = null;
|
|
39
|
-
this.Interactions = null;
|
|
40
|
-
this.Pushnotification = null;
|
|
41
|
-
this.UI = null;
|
|
42
|
-
this.XR = null;
|
|
43
|
-
this.Predictions = null;
|
|
44
|
-
this.DataStore = null;
|
|
45
|
-
this.Geo = null;
|
|
46
|
-
this.Notifications = null;
|
|
47
|
-
this.Logger = LoggerClass;
|
|
48
|
-
this.ServiceWorker = null;
|
|
49
|
-
}
|
|
50
|
-
Object.defineProperty(AmplifyClass.prototype, "config", {
|
|
51
|
-
// TODO: update "any" when types are determined
|
|
52
|
-
get: function () {
|
|
53
|
-
return Object.assign({}, this._config);
|
|
54
|
-
},
|
|
55
|
-
enumerable: false,
|
|
56
|
-
configurable: true
|
|
57
|
-
});
|
|
58
|
-
AmplifyClass.prototype.register = function (comp) {
|
|
59
|
-
logger.debug('component registered in amplify', comp);
|
|
60
|
-
this._components.push(comp);
|
|
61
|
-
if (typeof comp.getModuleName === 'function') {
|
|
62
|
-
this._modules[comp.getModuleName()] = comp;
|
|
63
|
-
this[comp.getModuleName()] = comp;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
logger.debug('no getModuleName method for component', comp);
|
|
67
|
-
}
|
|
68
|
-
// Finally configure this new component(category) loaded
|
|
69
|
-
// With the new modularization changes in Amplify V3, all the Amplify
|
|
70
|
-
// component are not loaded/registered right away but when they are
|
|
71
|
-
// imported (and hence instantiated) in the client's app. This ensures
|
|
72
|
-
// that all new components imported get correctly configured with the
|
|
73
|
-
// configuration that Amplify.configure() was called with.
|
|
74
|
-
comp.configure(this._config);
|
|
75
|
-
};
|
|
76
|
-
AmplifyClass.prototype.configure = function (config) {
|
|
77
|
-
var _this = this;
|
|
78
|
-
if (!config)
|
|
79
|
-
return this._config;
|
|
80
|
-
this._config = Object.assign(this._config, config);
|
|
81
|
-
logger.debug('amplify config', this._config);
|
|
82
|
-
// Dependency Injection via property-setting.
|
|
83
|
-
// This avoids introducing a public method/interface/setter that's difficult to remove later.
|
|
84
|
-
// Plus, it reduces `if` statements within the `constructor` and `configure` of each module
|
|
85
|
-
Object.entries(this._modules).forEach(function (_a) {
|
|
86
|
-
var _b = __read(_a, 2), Name = _b[0], comp = _b[1];
|
|
87
|
-
// e.g. Auth.*
|
|
88
|
-
Object.keys(comp).forEach(function (property) {
|
|
89
|
-
// e.g. Auth["Credentials"] = this._modules["Credentials"] when set
|
|
90
|
-
if (_this._modules[property]) {
|
|
91
|
-
comp[property] = _this._modules[property];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
this._components.map(function (comp) {
|
|
96
|
-
comp.configure(_this._config);
|
|
97
|
-
});
|
|
98
|
-
return this._config;
|
|
99
|
-
};
|
|
100
|
-
AmplifyClass.prototype.addPluggable = function (pluggable) {
|
|
101
|
-
if (pluggable &&
|
|
102
|
-
pluggable['getCategory'] &&
|
|
103
|
-
typeof pluggable['getCategory'] === 'function') {
|
|
104
|
-
this._components.map(function (comp) {
|
|
105
|
-
if (comp['addPluggable'] &&
|
|
106
|
-
typeof comp['addPluggable'] === 'function') {
|
|
107
|
-
comp.addPluggable(pluggable);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
return AmplifyClass;
|
|
113
|
-
}());
|
|
114
|
-
export { AmplifyClass };
|
|
115
|
-
export var Amplify = new AmplifyClass();
|
package/src/Amplify.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { ConsoleLogger as LoggerClass } from './Logger';
|
|
5
|
-
|
|
6
|
-
const logger = new LoggerClass('Amplify');
|
|
7
|
-
|
|
8
|
-
export class AmplifyClass {
|
|
9
|
-
// Everything that is `register`ed is tracked here
|
|
10
|
-
private _components:any[] = [];
|
|
11
|
-
private _config = {};
|
|
12
|
-
|
|
13
|
-
// All modules (with `getModuleName()`) are stored here for dependency injection
|
|
14
|
-
private _modules = {};
|
|
15
|
-
|
|
16
|
-
// for backward compatibility to avoid breaking change
|
|
17
|
-
// if someone is using like Amplify.Auth
|
|
18
|
-
Auth = null;
|
|
19
|
-
Analytics = null;
|
|
20
|
-
API = null;
|
|
21
|
-
Credentials = null;
|
|
22
|
-
Storage = null;
|
|
23
|
-
I18n = null;
|
|
24
|
-
Cache = null;
|
|
25
|
-
PubSub = null;
|
|
26
|
-
Interactions = null;
|
|
27
|
-
Pushnotification = null;
|
|
28
|
-
UI = null;
|
|
29
|
-
XR = null;
|
|
30
|
-
Predictions = null;
|
|
31
|
-
DataStore = null;
|
|
32
|
-
Geo = null;
|
|
33
|
-
Notifications = null;
|
|
34
|
-
|
|
35
|
-
Logger = LoggerClass;
|
|
36
|
-
ServiceWorker = null;
|
|
37
|
-
|
|
38
|
-
// TODO: update "any" when types are determined
|
|
39
|
-
public get config(): any {
|
|
40
|
-
return Object.assign({}, this._config);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
register(comp:any) {
|
|
44
|
-
logger.debug('component registered in amplify', comp);
|
|
45
|
-
this._components.push(comp);
|
|
46
|
-
if (typeof comp.getModuleName === 'function') {
|
|
47
|
-
this._modules[comp.getModuleName()] = comp;
|
|
48
|
-
this[comp.getModuleName()] = comp;
|
|
49
|
-
} else {
|
|
50
|
-
logger.debug('no getModuleName method for component', comp);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Finally configure this new component(category) loaded
|
|
54
|
-
// With the new modularization changes in Amplify V3, all the Amplify
|
|
55
|
-
// component are not loaded/registered right away but when they are
|
|
56
|
-
// imported (and hence instantiated) in the client's app. This ensures
|
|
57
|
-
// that all new components imported get correctly configured with the
|
|
58
|
-
// configuration that Amplify.configure() was called with.
|
|
59
|
-
comp.configure(this._config);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
configure(config?) {
|
|
63
|
-
if (!config) return this._config;
|
|
64
|
-
|
|
65
|
-
this._config = Object.assign(this._config, config);
|
|
66
|
-
logger.debug('amplify config', this._config);
|
|
67
|
-
|
|
68
|
-
// Dependency Injection via property-setting.
|
|
69
|
-
// This avoids introducing a public method/interface/setter that's difficult to remove later.
|
|
70
|
-
// Plus, it reduces `if` statements within the `constructor` and `configure` of each module
|
|
71
|
-
Object.entries(this._modules).forEach(([Name, comp]:[any, any]) => {
|
|
72
|
-
// e.g. Auth.*
|
|
73
|
-
Object.keys(comp).forEach(property => {
|
|
74
|
-
// e.g. Auth["Credentials"] = this._modules["Credentials"] when set
|
|
75
|
-
if (this._modules[property]) {
|
|
76
|
-
comp[property] = this._modules[property];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
this._components.map(comp => {
|
|
82
|
-
comp.configure(this._config);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return this._config;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
addPluggable(pluggable) {
|
|
89
|
-
if (
|
|
90
|
-
pluggable &&
|
|
91
|
-
pluggable['getCategory'] &&
|
|
92
|
-
typeof pluggable['getCategory'] === 'function'
|
|
93
|
-
) {
|
|
94
|
-
this._components.map(comp => {
|
|
95
|
-
if (
|
|
96
|
-
comp['addPluggable'] &&
|
|
97
|
-
typeof comp['addPluggable'] === 'function'
|
|
98
|
-
) {
|
|
99
|
-
comp.addPluggable(pluggable);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const Amplify = new AmplifyClass();
|