@aws-amplify/rtn-web-browser 1.0.1-console-preview.431c340.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 (50) hide show
  1. package/AmplifyRTNWebBrowser.podspec +35 -0
  2. package/LICENSE +201 -0
  3. package/android/build.gradle +68 -0
  4. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  6. package/android/gradle.properties +23 -0
  7. package/android/gradlew +234 -0
  8. package/android/gradlew.bat +89 -0
  9. package/android/src/main/AndroidManifest.xml +10 -0
  10. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/CustomTabsHelper.kt +54 -0
  11. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/WebBrowserModule.kt +75 -0
  12. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/WebBrowserPackage.kt +22 -0
  13. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/WebBrowserServiceConnection.kt +50 -0
  14. package/ios/AmplifyRTNWebBrowser-Bridging-Header.h +6 -0
  15. package/ios/AmplifyRTNWebBrowser.m +12 -0
  16. package/ios/AmplifyRTNWebBrowser.swift +64 -0
  17. package/ios/AmplifyRTNWebBrowser.xcodeproj/project.pbxproj +170 -0
  18. package/ios/AmplifyRTNWebBrowser.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  19. package/ios/AmplifyRTNWebBrowser.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  20. package/ios/AmplifyRTNWebBrowser.xcworkspace/contents.xcworkspacedata +7 -0
  21. package/ios/AmplifyRTNWebBrowser.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  22. package/lib/apis/openAuthSessionAsync.d.ts +1 -0
  23. package/lib/apis/openAuthSessionAsync.js +62 -0
  24. package/lib/apis/openAuthSessionAsync.js.map +1 -0
  25. package/lib/apis/webBrowserNativeModule.d.ts +2 -0
  26. package/lib/apis/webBrowserNativeModule.js +18 -0
  27. package/lib/apis/webBrowserNativeModule.js.map +1 -0
  28. package/lib/index.d.ts +4 -0
  29. package/lib/index.js +13 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/types.d.ts +3 -0
  32. package/lib/types.js +5 -0
  33. package/lib/types.js.map +1 -0
  34. package/lib-esm/apis/openAuthSessionAsync.d.ts +1 -0
  35. package/lib-esm/apis/openAuthSessionAsync.js +58 -0
  36. package/lib-esm/apis/openAuthSessionAsync.js.map +1 -0
  37. package/lib-esm/apis/webBrowserNativeModule.d.ts +2 -0
  38. package/lib-esm/apis/webBrowserNativeModule.js +15 -0
  39. package/lib-esm/apis/webBrowserNativeModule.js.map +1 -0
  40. package/lib-esm/index.d.ts +4 -0
  41. package/lib-esm/index.js +10 -0
  42. package/lib-esm/index.js.map +1 -0
  43. package/lib-esm/types.d.ts +3 -0
  44. package/lib-esm/types.js +4 -0
  45. package/lib-esm/types.js.map +1 -0
  46. package/package.json +53 -0
  47. package/src/apis/openAuthSessionAsync.ts +77 -0
  48. package/src/apis/webBrowserNativeModule.ts +23 -0
  49. package/src/index.ts +12 -0
  50. package/src/types.ts +6 -0
@@ -0,0 +1,58 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { AppState, Linking, Platform, } from 'react-native';
4
+ import { webBrowserNativeModule } from './webBrowserNativeModule';
5
+ let appStateListener;
6
+ let redirectListener;
7
+ export const openAuthSessionAsync = async (url, redirectSchemes) => {
8
+ // enforce HTTPS
9
+ const httpsUrl = url.replace('http://', 'https://');
10
+ if (Platform.OS === 'ios') {
11
+ return webBrowserNativeModule.openAuthSessionAsync(httpsUrl);
12
+ }
13
+ if (Platform.OS === 'android') {
14
+ return openAuthSessionAndroid(httpsUrl, redirectSchemes);
15
+ }
16
+ };
17
+ const openAuthSessionAndroid = async (url, redirectSchemes) => {
18
+ try {
19
+ const [redirectUrl] = await Promise.all([
20
+ Promise.race([
21
+ // wait for app to redirect, resulting in a redirectUrl
22
+ getRedirectPromise(redirectSchemes),
23
+ // wait for app to return some other way, resulting in null
24
+ getAppStatePromise(),
25
+ ]),
26
+ // open chrome tab
27
+ webBrowserNativeModule.openAuthSessionAsync(url),
28
+ ]);
29
+ return redirectUrl;
30
+ }
31
+ finally {
32
+ appStateListener?.remove();
33
+ redirectListener?.remove();
34
+ appStateListener = undefined;
35
+ redirectListener = undefined;
36
+ }
37
+ };
38
+ const getAppStatePromise = () => new Promise(resolve => {
39
+ appStateListener = AppState.addEventListener('change', nextAppState => {
40
+ // if current state is null, the change is from initialization
41
+ if (AppState.currentState === null) {
42
+ return;
43
+ }
44
+ if (nextAppState === 'active') {
45
+ appStateListener?.remove();
46
+ appStateListener = undefined;
47
+ resolve(null);
48
+ }
49
+ });
50
+ });
51
+ const getRedirectPromise = (redirectSchemes) => new Promise(resolve => {
52
+ redirectListener = Linking.addEventListener('url', event => {
53
+ if (redirectSchemes.some(scheme => event.url.startsWith(scheme))) {
54
+ resolve(event.url);
55
+ }
56
+ });
57
+ });
58
+ //# sourceMappingURL=openAuthSessionAsync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openAuthSessionAsync.js","sourceRoot":"","sources":["../../src/apis/openAuthSessionAsync.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EACN,QAAQ,EACR,OAAO,EAEP,QAAQ,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,IAAI,gBAAqD,CAAC;AAC1D,IAAI,gBAAqD,CAAC;AAE1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACxC,GAAW,EACX,eAAyB,EACxB,EAAE;IACH,gBAAgB;IAChB,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;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C,CAAC,CAAC;AAEJ,MAAM,kBAAkB,GAAG,CAAC,eAAyB,EAAmB,EAAE,CACzE,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;IACrB,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE;QAC1D,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;YACjE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACnB;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { WebBrowserNativeModule } from '../types';
2
+ export declare const webBrowserNativeModule: WebBrowserNativeModule;
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { NativeModules, Platform } from 'react-native';
4
+ const LINKING_ERROR = `The package '@aws-amplify/rtn-web-browser' doesn't seem to be linked. Make sure: \n\n` +
5
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
+ '- You rebuilt the app after installing the package\n' +
7
+ '- You are not using Expo Go\n';
8
+ export const webBrowserNativeModule = NativeModules.AmplifyRTNWebBrowser
9
+ ? NativeModules.AmplifyRTNWebBrowser
10
+ : new Proxy({}, {
11
+ get() {
12
+ throw new Error(LINKING_ERROR);
13
+ },
14
+ });
15
+ //# sourceMappingURL=webBrowserNativeModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webBrowserNativeModule.js","sourceRoot":"","sources":["../../src/apis/webBrowserNativeModule.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGvD,MAAM,aAAa,GAClB,uFAAuF;IACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,gCAAgC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACvE,sDAAsD;IACtD,+BAA+B,CAAC;AAEjC,MAAM,CAAC,MAAM,sBAAsB,GAClC,aAAa,CAAC,oBAAoB;IACjC,CAAC,CAAC,aAAa,CAAC,oBAAoB;IACpC,CAAC,CAAC,IAAI,KAAK,CACT,EAAE,EACF;QACC,GAAG;YACF,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QAChC,CAAC;KACD,CACA,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const mergedModule: {
2
+ openAuthSessionAsync: (url: string, redirectSchemes: string[]) => Promise<string | null | undefined>;
3
+ };
4
+ export { mergedModule as AmplifyRTNWebBrowser };
@@ -0,0 +1,10 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { openAuthSessionAsync } from './apis/openAuthSessionAsync';
4
+ import { webBrowserNativeModule } from './apis/webBrowserNativeModule';
5
+ const mergedModule = {
6
+ ...webBrowserNativeModule,
7
+ openAuthSessionAsync,
8
+ };
9
+ export { mergedModule as AmplifyRTNWebBrowser };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,MAAM,YAAY,GAAG;IACpB,GAAG,sBAAsB;IACzB,oBAAoB;CACpB,CAAC;AAEF,OAAO,EAAE,YAAY,IAAI,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type WebBrowserNativeModule = {
2
+ openAuthSessionAsync: (url: string) => Promise<string | null>;
3
+ };
@@ -0,0 +1,4 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export {};
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@aws-amplify/rtn-web-browser",
3
+ "version": "1.0.1-console-preview.431c340.0+431c340",
4
+ "description": "React Native module for aws-amplify web browser",
5
+ "main": "./lib/index.js",
6
+ "module": "./lib-esm/index.js",
7
+ "typings": "./lib-esm/index.d.ts",
8
+ "sideEffects": false,
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "scripts": {
13
+ "test": "tslint 'src/**/*.ts'",
14
+ "test:android": "./android/gradlew test -p ./android",
15
+ "build-with-test": "npm run clean && npm test && tsc",
16
+ "build:cjs": "rimraf lib && tsc -m commonjs --outDir lib",
17
+ "build:esm": "rimraf lib-esm && tsc -m esnext --outDir lib-esm",
18
+ "build:cjs:watch": "rimraf lib && tsc -m commonjs --outDir lib --watch",
19
+ "build:esm:watch": "rimraf lib-esm && tsc -m esnext --outDir lib-esm --watch",
20
+ "build": "npm run clean && npm run build:esm && npm run build:cjs",
21
+ "clean": "rimraf lib-esm lib dist",
22
+ "format": "echo \"Not implemented\"",
23
+ "lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
24
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.21"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react-native": "0.70.0",
28
+ "react-native": "0.72.3",
29
+ "typescript": "5.1.6"
30
+ },
31
+ "react-native": {
32
+ "./lib/index": "./lib-esm/index.js"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/aws-amplify/amplify-js.git"
37
+ },
38
+ "author": "Amazon Web Services",
39
+ "license": "Apache-2.0",
40
+ "bugs": {
41
+ "url": "https://github.com/aws/aws-amplify/issues"
42
+ },
43
+ "homepage": "https://docs.amplify.aws/",
44
+ "files": [
45
+ "Amplify*.podspec",
46
+ "android",
47
+ "ios",
48
+ "lib",
49
+ "lib-esm",
50
+ "src"
51
+ ],
52
+ "gitHead": "431c340469e40ebed677872def2feb216ce151fe"
53
+ }
@@ -0,0 +1,77 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ AppState,
6
+ Linking,
7
+ NativeEventSubscription,
8
+ Platform,
9
+ } from 'react-native';
10
+ import { webBrowserNativeModule } from './webBrowserNativeModule';
11
+
12
+ let appStateListener: NativeEventSubscription | undefined;
13
+ let redirectListener: NativeEventSubscription | undefined;
14
+
15
+ export const openAuthSessionAsync = async (
16
+ url: string,
17
+ redirectSchemes: string[]
18
+ ) => {
19
+ // enforce HTTPS
20
+ const httpsUrl = url.replace('http://', 'https://');
21
+ if (Platform.OS === 'ios') {
22
+ return webBrowserNativeModule.openAuthSessionAsync(httpsUrl);
23
+ }
24
+
25
+ if (Platform.OS === 'android') {
26
+ return openAuthSessionAndroid(httpsUrl, redirectSchemes);
27
+ }
28
+ };
29
+
30
+ const openAuthSessionAndroid = async (
31
+ url: string,
32
+ redirectSchemes: string[]
33
+ ) => {
34
+ try {
35
+ const [redirectUrl] = await Promise.all([
36
+ Promise.race([
37
+ // wait for app to redirect, resulting in a redirectUrl
38
+ getRedirectPromise(redirectSchemes),
39
+ // wait for app to return some other way, resulting in null
40
+ getAppStatePromise(),
41
+ ]),
42
+ // open chrome tab
43
+ webBrowserNativeModule.openAuthSessionAsync(url),
44
+ ]);
45
+ return redirectUrl;
46
+ } finally {
47
+ appStateListener?.remove();
48
+ redirectListener?.remove();
49
+ appStateListener = undefined;
50
+ redirectListener = undefined;
51
+ }
52
+ };
53
+
54
+ const getAppStatePromise = (): Promise<null> =>
55
+ new Promise(resolve => {
56
+ appStateListener = AppState.addEventListener('change', nextAppState => {
57
+ // if current state is null, the change is from initialization
58
+ if (AppState.currentState === null) {
59
+ return;
60
+ }
61
+
62
+ if (nextAppState === 'active') {
63
+ appStateListener?.remove();
64
+ appStateListener = undefined;
65
+ resolve(null);
66
+ }
67
+ });
68
+ });
69
+
70
+ const getRedirectPromise = (redirectSchemes: string[]): Promise<string> =>
71
+ new Promise(resolve => {
72
+ redirectListener = Linking.addEventListener('url', event => {
73
+ if (redirectSchemes.some(scheme => event.url.startsWith(scheme))) {
74
+ resolve(event.url);
75
+ }
76
+ });
77
+ });
@@ -0,0 +1,23 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { NativeModules, Platform } from 'react-native';
5
+ import { WebBrowserNativeModule } from '../types';
6
+
7
+ const LINKING_ERROR =
8
+ `The package '@aws-amplify/rtn-web-browser' doesn't seem to be linked. Make sure: \n\n` +
9
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
10
+ '- You rebuilt the app after installing the package\n' +
11
+ '- You are not using Expo Go\n';
12
+
13
+ export const webBrowserNativeModule: WebBrowserNativeModule =
14
+ NativeModules.AmplifyRTNWebBrowser
15
+ ? NativeModules.AmplifyRTNWebBrowser
16
+ : new Proxy(
17
+ {},
18
+ {
19
+ get() {
20
+ throw new Error(LINKING_ERROR);
21
+ },
22
+ }
23
+ );
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { openAuthSessionAsync } from './apis/openAuthSessionAsync';
5
+ import { webBrowserNativeModule } from './apis/webBrowserNativeModule';
6
+
7
+ const mergedModule = {
8
+ ...webBrowserNativeModule,
9
+ openAuthSessionAsync,
10
+ };
11
+
12
+ export { mergedModule as AmplifyRTNWebBrowser };
package/src/types.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export type WebBrowserNativeModule = {
5
+ openAuthSessionAsync: (url: string) => Promise<string | null>;
6
+ };