@aws-amplify/core 6.0.1-console-preview.814dea6.0 → 6.0.1-preview-testing.64b45b1.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/AwsClients/CognitoIdentity/base.d.ts +12 -4
- package/lib/AwsClients/CognitoIdentity/base.js +1 -0
- package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
- package/lib/AwsClients/CognitoIdentity/getId.d.ts +15 -3
- package/lib/AwsClients/Pinpoint/base.d.ts +10 -2
- package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
- package/lib/AwsClients/Pinpoint/putEvents.d.ts +17 -3
- package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/RNComponents/index.js +2 -2
- package/lib/ServiceWorker/ServiceWorker.js +1 -1
- package/lib/Util/JS.d.ts +1 -4
- package/lib/Util/JS.js +4 -11
- package/lib/Util/Reachability.js +0 -3
- package/lib/clients/handlers/authenticated.d.ts +1 -1
- package/lib/clients/handlers/fetch.d.ts +0 -1
- package/lib/clients/handlers/fetch.js +2 -2
- package/lib/clients/handlers/unauthenticated.d.ts +1 -1
- package/lib/clients/internal/composeServiceApi.d.ts +5 -3
- package/lib/clients/types/aws.d.ts +0 -4
- package/lib/clients/types/http.d.ts +8 -0
- package/lib/clients/types/index.d.ts +1 -1
- package/lib/libraryUtils.d.ts +1 -2
- package/lib/libraryUtils.js +3 -6
- package/lib/providers/pinpoint/apis/record.d.ts +2 -2
- package/lib/providers/pinpoint/apis/record.js +3 -3
- package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
- package/lib/providers/pinpoint/types/buffer.d.ts +1 -1
- package/lib/providers/pinpoint/types/pinpoint.d.ts +3 -3
- package/lib/singleton/Storage/types.d.ts +5 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +12 -4
- package/lib-esm/AwsClients/CognitoIdentity/base.js +1 -0
- package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
- package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +15 -3
- package/lib-esm/AwsClients/Pinpoint/base.d.ts +10 -2
- package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
- package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +17 -3
- package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/RNComponents/index.js +3 -3
- package/lib-esm/ServiceWorker/ServiceWorker.js +2 -2
- package/lib-esm/Util/JS.d.ts +1 -4
- package/lib-esm/Util/JS.js +2 -9
- package/lib-esm/Util/Reachability.js +1 -4
- package/lib-esm/clients/handlers/authenticated.d.ts +1 -1
- package/lib-esm/clients/handlers/fetch.d.ts +0 -1
- package/lib-esm/clients/handlers/fetch.js +2 -2
- package/lib-esm/clients/handlers/unauthenticated.d.ts +1 -1
- package/lib-esm/clients/internal/composeServiceApi.d.ts +5 -3
- package/lib-esm/clients/types/aws.d.ts +0 -4
- package/lib-esm/clients/types/http.d.ts +8 -0
- package/lib-esm/clients/types/index.d.ts +1 -1
- package/lib-esm/libraryUtils.d.ts +1 -2
- package/lib-esm/libraryUtils.js +1 -2
- package/lib-esm/providers/pinpoint/apis/record.d.ts +2 -2
- package/lib-esm/providers/pinpoint/apis/record.js +3 -3
- package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
- package/lib-esm/providers/pinpoint/types/buffer.d.ts +1 -1
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +3 -3
- package/lib-esm/singleton/Storage/types.d.ts +5 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -4
- package/src/AwsClients/CognitoIdentity/base.ts +2 -2
- package/src/AwsClients/Pinpoint/base.ts +2 -6
- package/src/Platform/version.ts +1 -1
- package/src/RNComponents/index.ts +3 -3
- package/src/ServiceWorker/ServiceWorker.ts +2 -2
- package/src/Util/JS.ts +2 -13
- package/src/Util/Reachability.ts +1 -5
- package/src/clients/handlers/authenticated.ts +2 -1
- package/src/clients/handlers/fetch.ts +2 -2
- package/src/clients/handlers/unauthenticated.ts +2 -1
- package/src/clients/internal/composeServiceApi.ts +10 -3
- package/src/clients/types/aws.ts +0 -10
- package/src/clients/types/http.ts +8 -0
- package/src/clients/types/index.ts +0 -1
- package/src/libraryUtils.ts +1 -2
- package/src/providers/pinpoint/apis/record.ts +8 -8
- package/src/providers/pinpoint/apis/updateEndpoint.ts +2 -2
- package/src/providers/pinpoint/types/buffer.ts +1 -1
- package/src/providers/pinpoint/types/pinpoint.ts +8 -7
- package/src/singleton/Storage/types.ts +6 -2
- package/lib/OAuthHelper/FacebookOAuth.d.ts +0 -6
- package/lib/OAuthHelper/FacebookOAuth.js +0 -124
- package/lib/OAuthHelper/GoogleOAuth.d.ts +0 -6
- package/lib/OAuthHelper/GoogleOAuth.js +0 -134
- package/lib/OAuthHelper/index.d.ts +0 -4
- package/lib/OAuthHelper/index.js +0 -9
- package/lib-esm/OAuthHelper/FacebookOAuth.d.ts +0 -6
- package/lib-esm/OAuthHelper/FacebookOAuth.js +0 -121
- package/lib-esm/OAuthHelper/GoogleOAuth.d.ts +0 -6
- package/lib-esm/OAuthHelper/GoogleOAuth.js +0 -131
- package/lib-esm/OAuthHelper/index.d.ts +0 -4
- package/lib-esm/OAuthHelper/index.js +0 -6
- package/src/OAuthHelper/FacebookOAuth.ts +0 -83
- package/src/OAuthHelper/GoogleOAuth.ts +0 -97
- package/src/OAuthHelper/index.ts +0 -7
|
@@ -29,7 +29,7 @@ export const composeServiceApi = <
|
|
|
29
29
|
ServiceClientOptions &
|
|
30
30
|
Partial<DefaultConfig> &
|
|
31
31
|
InferEndpointResolverOptionType<DefaultConfig>,
|
|
32
|
-
|
|
32
|
+
DefaultConfig
|
|
33
33
|
>,
|
|
34
34
|
input: Input
|
|
35
35
|
) => {
|
|
@@ -54,8 +54,15 @@ export const composeServiceApi = <
|
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
type OptionalizeKey<
|
|
58
|
-
[
|
|
57
|
+
type OptionalizeKey<InputType, InputDefaultsType> = {
|
|
58
|
+
[KeyWithDefaultValue in keyof InputDefaultsType]?: KeyWithDefaultValue extends keyof InputType
|
|
59
|
+
? InputType[KeyWithDefaultValue]
|
|
60
|
+
: never;
|
|
61
|
+
} & {
|
|
62
|
+
[KeyWithoutDefaultValue in keyof Omit<
|
|
63
|
+
InputType,
|
|
64
|
+
keyof InputDefaultsType
|
|
65
|
+
>]: InputType[KeyWithoutDefaultValue];
|
|
59
66
|
};
|
|
60
67
|
|
|
61
68
|
type InferEndpointResolverOptionType<T> = T extends {
|
package/src/clients/types/aws.ts
CHANGED
|
@@ -26,13 +26,3 @@ export interface ServiceClientOptions {
|
|
|
26
26
|
export type ErrorParser = (
|
|
27
27
|
response?: HttpResponse
|
|
28
28
|
) => Promise<(Error & MetadataBearer) | undefined>;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Default config options for the `composeServiceApi`.
|
|
32
|
-
*/
|
|
33
|
-
export type DefaultConfigOptions<
|
|
34
|
-
TransferHandlerOptions extends Record<string, unknown> = Record<
|
|
35
|
-
string,
|
|
36
|
-
unknown
|
|
37
|
-
>
|
|
38
|
-
> = Partial<TransferHandlerOptions & ServiceClientOptions>;
|
|
@@ -34,6 +34,14 @@ export interface HttpResponse extends Response {
|
|
|
34
34
|
|
|
35
35
|
export interface HttpTransferOptions {
|
|
36
36
|
abortSignal?: AbortSignal;
|
|
37
|
+
/**
|
|
38
|
+
* Cache mode for the request. Note that this is only effective when the underlying HTTP handler is fetch.
|
|
39
|
+
* For XHR handler, or Node.js `"http(s)"` module or running on React Native, this option is ignored.
|
|
40
|
+
* Instead, you can configure the `Cache-Control` headers to achieve similar effects.
|
|
41
|
+
* @default 'default'
|
|
42
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/cache}
|
|
43
|
+
*/
|
|
44
|
+
cache?: RequestCache;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
export type HttpTransferHandler = TransferHandler<
|
package/src/libraryUtils.ts
CHANGED
|
@@ -7,7 +7,7 @@ utils for use throughout the library.
|
|
|
7
7
|
*/
|
|
8
8
|
// JS utilities
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
isBrowser,
|
|
11
11
|
filenameToContentType,
|
|
12
12
|
generateRandomString,
|
|
13
13
|
isEmpty,
|
|
@@ -96,7 +96,6 @@ export {
|
|
|
96
96
|
AmplifyError,
|
|
97
97
|
AmplifyErrorString,
|
|
98
98
|
} from './Util/Errors';
|
|
99
|
-
export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
|
|
100
99
|
export { AppState, AsyncStorage, Linking } from './RNComponents';
|
|
101
100
|
export { ErrorParams, AmplifyErrorMap, ServiceError } from './types';
|
|
102
101
|
export {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { v4 as uuid } from 'uuid';
|
|
5
|
-
import {
|
|
5
|
+
import { PinpointRecordInput, PinpointSession } from '../types';
|
|
6
6
|
import { getEndpointId } from '../utils';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
8
|
BUFFER_SIZE,
|
|
9
9
|
FLUSH_INTERVAL,
|
|
10
10
|
FLUSH_SIZE,
|
|
@@ -28,11 +28,11 @@ export const record = async ({
|
|
|
28
28
|
identityId,
|
|
29
29
|
region,
|
|
30
30
|
userAgentValue,
|
|
31
|
-
}:
|
|
31
|
+
}: PinpointRecordInput): Promise<void> => {
|
|
32
32
|
const timestampISOString = new Date().toISOString();
|
|
33
33
|
const eventId = uuid();
|
|
34
34
|
let endpointId = await getEndpointId(appId, category);
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
// Prepare event buffer if required
|
|
37
37
|
const buffer = getEventBuffer({
|
|
38
38
|
appId,
|
|
@@ -43,7 +43,7 @@ export const record = async ({
|
|
|
43
43
|
identityId,
|
|
44
44
|
region,
|
|
45
45
|
resendLimit: RESEND_LIMIT,
|
|
46
|
-
userAgentValue
|
|
46
|
+
userAgentValue,
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
// Prepare a Pinpoint endpoint via updateEndpoint if one does not already exist, which will generate and cache an
|
|
@@ -64,7 +64,7 @@ export const record = async ({
|
|
|
64
64
|
if (!endpointId) {
|
|
65
65
|
throw new AmplifyError({
|
|
66
66
|
name: 'ENDPOINT_NOT_CREATED',
|
|
67
|
-
message: 'Endpoint was not created.'
|
|
67
|
+
message: 'Endpoint was not created.',
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -77,7 +77,7 @@ export const record = async ({
|
|
|
77
77
|
StartTimestamp: timestampISOString,
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
// Push event to buffer
|
|
82
82
|
buffer.push({
|
|
83
83
|
eventId,
|
|
@@ -85,6 +85,6 @@ export const record = async ({
|
|
|
85
85
|
event,
|
|
86
86
|
session,
|
|
87
87
|
timestamp: timestampISOString,
|
|
88
|
-
resendLimit: RESEND_LIMIT
|
|
88
|
+
resendLimit: RESEND_LIMIT,
|
|
89
89
|
});
|
|
90
90
|
};
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
updateEndpoint as clientUpdateEndpoint,
|
|
8
8
|
UpdateEndpointInput,
|
|
9
9
|
} from '../../../AwsClients/Pinpoint';
|
|
10
|
-
import {
|
|
10
|
+
import { PinpointUpdateEndpointInput } from '../types';
|
|
11
11
|
import { cacheEndpointId, getEndpointId } from '../utils';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -25,7 +25,7 @@ export const updateEndpoint = async ({
|
|
|
25
25
|
userId,
|
|
26
26
|
userProfile,
|
|
27
27
|
userAgentValue,
|
|
28
|
-
}:
|
|
28
|
+
}: PinpointUpdateEndpointInput): Promise<void> => {
|
|
29
29
|
const endpointId = await getEndpointId(appId, category);
|
|
30
30
|
// only generate a new endpoint id if one was not found in cache
|
|
31
31
|
const createdEndpointId = !endpointId ? uuidv4() : undefined;
|
|
@@ -7,7 +7,7 @@ import { PinpointAnalyticsEvent, PinpointSession } from './pinpoint';
|
|
|
7
7
|
export type EventBufferConfig = {
|
|
8
8
|
appId: string;
|
|
9
9
|
bufferSize: number;
|
|
10
|
-
credentials: AuthSession['credentials'];
|
|
10
|
+
credentials: Required<AuthSession>['credentials'];
|
|
11
11
|
identityId: AuthSession['identityId'];
|
|
12
12
|
flushInterval: number;
|
|
13
13
|
flushSize: number;
|
|
@@ -38,18 +38,19 @@ export type PinpointAnalyticsEvent = {
|
|
|
38
38
|
type PinpointCommonParameters = {
|
|
39
39
|
appId: string;
|
|
40
40
|
category: SupportedCategory;
|
|
41
|
-
credentials: AuthSession['credentials'];
|
|
41
|
+
credentials: Required<AuthSession>['credentials'];
|
|
42
42
|
identityId?: AuthSession['identityId'];
|
|
43
43
|
region: string;
|
|
44
44
|
userAgentValue?: string;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
export type
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
export type PinpointUpdateEndpointInput = PinpointCommonParameters &
|
|
48
|
+
PinpointServiceOptions & {
|
|
49
|
+
channelType?: SupportedChannelType;
|
|
50
|
+
userId?: string;
|
|
51
|
+
userProfile?: UserProfile;
|
|
52
|
+
};
|
|
52
53
|
|
|
53
|
-
export type
|
|
54
|
+
export type PinpointRecordInput = PinpointCommonParameters & {
|
|
54
55
|
event: PinpointAnalyticsEvent;
|
|
55
56
|
};
|
|
@@ -7,8 +7,13 @@ export interface StorageConfig {
|
|
|
7
7
|
S3: {
|
|
8
8
|
bucket?: string;
|
|
9
9
|
region?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Internal-only configuration for testing purpose. You should not use this.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
10
15
|
dangerouslyConnectToHttpEndpointForTesting?: string;
|
|
11
|
-
}
|
|
16
|
+
};
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
type StoragePrefixResolver = (params: {
|
|
@@ -16,7 +21,6 @@ type StoragePrefixResolver = (params: {
|
|
|
16
21
|
targetIdentityId?: string;
|
|
17
22
|
}) => Promise<string>;
|
|
18
23
|
|
|
19
|
-
// TODO[AllanZhengYP]: need to finalize the decision whether to move defaultAccessLevel to StorageConfig
|
|
20
24
|
export interface LibraryStorageOptions {
|
|
21
25
|
S3: {
|
|
22
26
|
prefixResolver?: StoragePrefixResolver;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.FacebookOAuth = void 0;
|
|
40
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
41
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
42
|
-
var Logger_1 = require("../Logger");
|
|
43
|
-
var JS_1 = require("../Util/JS");
|
|
44
|
-
var Util_1 = require("../Util");
|
|
45
|
-
var logger = new Logger_1.ConsoleLogger('CognitoCredentials');
|
|
46
|
-
var waitForInit = new Promise(function (res, rej) {
|
|
47
|
-
if (!(0, JS_1.browserOrNode)().isBrowser) {
|
|
48
|
-
logger.debug('not in the browser, directly resolved');
|
|
49
|
-
return res();
|
|
50
|
-
}
|
|
51
|
-
var fb = window['FB'];
|
|
52
|
-
if (fb) {
|
|
53
|
-
logger.debug('FB SDK already loaded');
|
|
54
|
-
return res();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
setTimeout(function () {
|
|
58
|
-
return res();
|
|
59
|
-
}, 2000);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
var FacebookOAuth = /** @class */ (function () {
|
|
63
|
-
function FacebookOAuth() {
|
|
64
|
-
this.initialized = false;
|
|
65
|
-
this.refreshFacebookToken = this.refreshFacebookToken.bind(this);
|
|
66
|
-
this._refreshFacebookTokenImpl = this._refreshFacebookTokenImpl.bind(this);
|
|
67
|
-
}
|
|
68
|
-
FacebookOAuth.prototype.refreshFacebookToken = function () {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0:
|
|
73
|
-
if (!!this.initialized) return [3 /*break*/, 2];
|
|
74
|
-
logger.debug('need to wait for the Facebook SDK loaded');
|
|
75
|
-
return [4 /*yield*/, waitForInit];
|
|
76
|
-
case 1:
|
|
77
|
-
_a.sent();
|
|
78
|
-
this.initialized = true;
|
|
79
|
-
logger.debug('finish waiting');
|
|
80
|
-
_a.label = 2;
|
|
81
|
-
case 2: return [2 /*return*/, this._refreshFacebookTokenImpl()];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
FacebookOAuth.prototype._refreshFacebookTokenImpl = function () {
|
|
87
|
-
var fb = null;
|
|
88
|
-
if ((0, JS_1.browserOrNode)().isBrowser)
|
|
89
|
-
fb = window['FB'];
|
|
90
|
-
if (!fb) {
|
|
91
|
-
var errorMessage = 'no fb sdk available';
|
|
92
|
-
logger.debug(errorMessage);
|
|
93
|
-
return Promise.reject(new Util_1.NonRetryableError(errorMessage));
|
|
94
|
-
}
|
|
95
|
-
return new Promise(function (res, rej) {
|
|
96
|
-
fb.getLoginStatus(function (fbResponse) {
|
|
97
|
-
if (!fbResponse || !fbResponse.authResponse) {
|
|
98
|
-
var errorMessage = 'no response from facebook when refreshing the jwt token';
|
|
99
|
-
logger.debug(errorMessage);
|
|
100
|
-
// There is no definitive indication for a network error in
|
|
101
|
-
// fbResponse, so we are treating it as an invalid token.
|
|
102
|
-
rej(new Util_1.NonRetryableError(errorMessage));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
var response = fbResponse.authResponse;
|
|
106
|
-
var accessToken = response.accessToken, expiresIn = response.expiresIn;
|
|
107
|
-
var date = new Date();
|
|
108
|
-
var expires_at = expiresIn * 1000 + date.getTime();
|
|
109
|
-
if (!accessToken) {
|
|
110
|
-
var errorMessage = 'the jwtToken is undefined';
|
|
111
|
-
logger.debug(errorMessage);
|
|
112
|
-
rej(new Util_1.NonRetryableError(errorMessage));
|
|
113
|
-
}
|
|
114
|
-
res({
|
|
115
|
-
token: accessToken,
|
|
116
|
-
expires_at: expires_at,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}, { scope: 'public_profile,email' });
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
return FacebookOAuth;
|
|
123
|
-
}());
|
|
124
|
-
exports.FacebookOAuth = FacebookOAuth;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.GoogleOAuth = void 0;
|
|
40
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
41
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
42
|
-
var Logger_1 = require("../Logger");
|
|
43
|
-
var JS_1 = require("../Util/JS");
|
|
44
|
-
var Util_1 = require("../Util");
|
|
45
|
-
var logger = new Logger_1.ConsoleLogger('CognitoCredentials');
|
|
46
|
-
var waitForInit = new Promise(function (res, rej) {
|
|
47
|
-
if (!(0, JS_1.browserOrNode)().isBrowser) {
|
|
48
|
-
logger.debug('not in the browser, directly resolved');
|
|
49
|
-
return res();
|
|
50
|
-
}
|
|
51
|
-
var ga = window['gapi'] && window['gapi'].auth2 ? window['gapi'].auth2 : null;
|
|
52
|
-
if (ga) {
|
|
53
|
-
logger.debug('google api already loaded');
|
|
54
|
-
return res();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
setTimeout(function () {
|
|
58
|
-
return res();
|
|
59
|
-
}, 2000);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
var GoogleOAuth = /** @class */ (function () {
|
|
63
|
-
function GoogleOAuth() {
|
|
64
|
-
this.initialized = false;
|
|
65
|
-
this.refreshGoogleToken = this.refreshGoogleToken.bind(this);
|
|
66
|
-
this._refreshGoogleTokenImpl = this._refreshGoogleTokenImpl.bind(this);
|
|
67
|
-
}
|
|
68
|
-
GoogleOAuth.prototype.refreshGoogleToken = function () {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
return __generator(this, function (_a) {
|
|
71
|
-
switch (_a.label) {
|
|
72
|
-
case 0:
|
|
73
|
-
if (!!this.initialized) return [3 /*break*/, 2];
|
|
74
|
-
logger.debug('need to wait for the Google SDK loaded');
|
|
75
|
-
return [4 /*yield*/, waitForInit];
|
|
76
|
-
case 1:
|
|
77
|
-
_a.sent();
|
|
78
|
-
this.initialized = true;
|
|
79
|
-
logger.debug('finish waiting');
|
|
80
|
-
_a.label = 2;
|
|
81
|
-
case 2: return [2 /*return*/, this._refreshGoogleTokenImpl()];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
GoogleOAuth.prototype._refreshGoogleTokenImpl = function () {
|
|
87
|
-
var ga = null;
|
|
88
|
-
if ((0, JS_1.browserOrNode)().isBrowser)
|
|
89
|
-
ga = window['gapi'] && window['gapi'].auth2 ? window['gapi'].auth2 : null;
|
|
90
|
-
if (!ga) {
|
|
91
|
-
logger.debug('no gapi auth2 available');
|
|
92
|
-
return Promise.reject('no gapi auth2 available');
|
|
93
|
-
}
|
|
94
|
-
return new Promise(function (res, rej) {
|
|
95
|
-
ga.getAuthInstance()
|
|
96
|
-
.then(function (googleAuth) {
|
|
97
|
-
if (!googleAuth) {
|
|
98
|
-
logger.debug('google Auth undefined');
|
|
99
|
-
rej(new Util_1.NonRetryableError('google Auth undefined'));
|
|
100
|
-
}
|
|
101
|
-
var googleUser = googleAuth.currentUser.get();
|
|
102
|
-
// refresh the token
|
|
103
|
-
if (googleUser.isSignedIn()) {
|
|
104
|
-
logger.debug('refreshing the google access token');
|
|
105
|
-
googleUser
|
|
106
|
-
.reloadAuthResponse()
|
|
107
|
-
.then(function (authResponse) {
|
|
108
|
-
var id_token = authResponse.id_token, expires_at = authResponse.expires_at;
|
|
109
|
-
res({ token: id_token, expires_at: expires_at });
|
|
110
|
-
})
|
|
111
|
-
.catch(function (err) {
|
|
112
|
-
if (err &&
|
|
113
|
-
err.error === 'network_error') {
|
|
114
|
-
// Not using NonRetryableError so handler will be retried
|
|
115
|
-
rej('Network error reloading google auth response');
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
rej(new Util_1.NonRetryableError('Failed to reload google auth response'));
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
rej(new Util_1.NonRetryableError('User is not signed in with Google'));
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
.catch(function (err) {
|
|
127
|
-
logger.debug('Failed to refresh google token', err);
|
|
128
|
-
rej(new Util_1.NonRetryableError('Failed to refresh google token'));
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
return GoogleOAuth;
|
|
133
|
-
}());
|
|
134
|
-
exports.GoogleOAuth = GoogleOAuth;
|
package/lib/OAuthHelper/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FacebookOAuth = exports.GoogleOAuth = void 0;
|
|
4
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
var GoogleOAuth_1 = require("./GoogleOAuth");
|
|
7
|
-
var FacebookOAuth_1 = require("./FacebookOAuth");
|
|
8
|
-
exports.GoogleOAuth = new GoogleOAuth_1.GoogleOAuth();
|
|
9
|
-
exports.FacebookOAuth = new FacebookOAuth_1.FacebookOAuth();
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
38
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
39
|
-
import { ConsoleLogger as Logger } from '../Logger';
|
|
40
|
-
import { browserOrNode } from '../Util/JS';
|
|
41
|
-
import { NonRetryableError } from '../Util';
|
|
42
|
-
var logger = new Logger('CognitoCredentials');
|
|
43
|
-
var waitForInit = new Promise(function (res, rej) {
|
|
44
|
-
if (!browserOrNode().isBrowser) {
|
|
45
|
-
logger.debug('not in the browser, directly resolved');
|
|
46
|
-
return res();
|
|
47
|
-
}
|
|
48
|
-
var fb = window['FB'];
|
|
49
|
-
if (fb) {
|
|
50
|
-
logger.debug('FB SDK already loaded');
|
|
51
|
-
return res();
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
setTimeout(function () {
|
|
55
|
-
return res();
|
|
56
|
-
}, 2000);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
var FacebookOAuth = /** @class */ (function () {
|
|
60
|
-
function FacebookOAuth() {
|
|
61
|
-
this.initialized = false;
|
|
62
|
-
this.refreshFacebookToken = this.refreshFacebookToken.bind(this);
|
|
63
|
-
this._refreshFacebookTokenImpl = this._refreshFacebookTokenImpl.bind(this);
|
|
64
|
-
}
|
|
65
|
-
FacebookOAuth.prototype.refreshFacebookToken = function () {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
return __generator(this, function (_a) {
|
|
68
|
-
switch (_a.label) {
|
|
69
|
-
case 0:
|
|
70
|
-
if (!!this.initialized) return [3 /*break*/, 2];
|
|
71
|
-
logger.debug('need to wait for the Facebook SDK loaded');
|
|
72
|
-
return [4 /*yield*/, waitForInit];
|
|
73
|
-
case 1:
|
|
74
|
-
_a.sent();
|
|
75
|
-
this.initialized = true;
|
|
76
|
-
logger.debug('finish waiting');
|
|
77
|
-
_a.label = 2;
|
|
78
|
-
case 2: return [2 /*return*/, this._refreshFacebookTokenImpl()];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
FacebookOAuth.prototype._refreshFacebookTokenImpl = function () {
|
|
84
|
-
var fb = null;
|
|
85
|
-
if (browserOrNode().isBrowser)
|
|
86
|
-
fb = window['FB'];
|
|
87
|
-
if (!fb) {
|
|
88
|
-
var errorMessage = 'no fb sdk available';
|
|
89
|
-
logger.debug(errorMessage);
|
|
90
|
-
return Promise.reject(new NonRetryableError(errorMessage));
|
|
91
|
-
}
|
|
92
|
-
return new Promise(function (res, rej) {
|
|
93
|
-
fb.getLoginStatus(function (fbResponse) {
|
|
94
|
-
if (!fbResponse || !fbResponse.authResponse) {
|
|
95
|
-
var errorMessage = 'no response from facebook when refreshing the jwt token';
|
|
96
|
-
logger.debug(errorMessage);
|
|
97
|
-
// There is no definitive indication for a network error in
|
|
98
|
-
// fbResponse, so we are treating it as an invalid token.
|
|
99
|
-
rej(new NonRetryableError(errorMessage));
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
var response = fbResponse.authResponse;
|
|
103
|
-
var accessToken = response.accessToken, expiresIn = response.expiresIn;
|
|
104
|
-
var date = new Date();
|
|
105
|
-
var expires_at = expiresIn * 1000 + date.getTime();
|
|
106
|
-
if (!accessToken) {
|
|
107
|
-
var errorMessage = 'the jwtToken is undefined';
|
|
108
|
-
logger.debug(errorMessage);
|
|
109
|
-
rej(new NonRetryableError(errorMessage));
|
|
110
|
-
}
|
|
111
|
-
res({
|
|
112
|
-
token: accessToken,
|
|
113
|
-
expires_at: expires_at,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}, { scope: 'public_profile,email' });
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
return FacebookOAuth;
|
|
120
|
-
}());
|
|
121
|
-
export { FacebookOAuth };
|