@aws-amplify/rtn-web-browser 1.0.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 (51) hide show
  1. package/AmplifyRTNWebBrowser.podspec +35 -0
  2. package/LICENSE +201 -0
  3. package/android/build.gradle +84 -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/hasPackageName/AndroidManifest.xml +9 -0
  10. package/android/src/main/AndroidManifest.xml +8 -0
  11. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/CustomTabsHelper.kt +54 -0
  12. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/WebBrowserModule.kt +74 -0
  13. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/WebBrowserPackage.kt +22 -0
  14. package/android/src/main/kotlin/com/amazonaws/amplify/rtnwebbrowser/WebBrowserServiceConnection.kt +50 -0
  15. package/ios/AmplifyRTNWebBrowser-Bridging-Header.h +6 -0
  16. package/ios/AmplifyRTNWebBrowser.m +14 -0
  17. package/ios/AmplifyRTNWebBrowser.swift +71 -0
  18. package/ios/AmplifyRTNWebBrowser.xcodeproj/project.pbxproj +170 -0
  19. package/ios/AmplifyRTNWebBrowser.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  20. package/ios/AmplifyRTNWebBrowser.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  21. package/ios/AmplifyRTNWebBrowser.xcworkspace/contents.xcworkspacedata +7 -0
  22. package/ios/AmplifyRTNWebBrowser.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  23. package/lib/apis/openAuthSessionAsync.d.ts +1 -0
  24. package/lib/apis/openAuthSessionAsync.js +68 -0
  25. package/lib/apis/openAuthSessionAsync.js.map +1 -0
  26. package/lib/index.d.ts +4 -0
  27. package/lib/index.js +13 -0
  28. package/lib/index.js.map +1 -0
  29. package/lib/nativeModule.d.ts +2 -0
  30. package/lib/nativeModule.js +18 -0
  31. package/lib/nativeModule.js.map +1 -0
  32. package/lib/types.d.ts +3 -0
  33. package/lib/types.js +5 -0
  34. package/lib/types.js.map +1 -0
  35. package/lib-esm/apis/openAuthSessionAsync.d.ts +1 -0
  36. package/lib-esm/apis/openAuthSessionAsync.js +64 -0
  37. package/lib-esm/apis/openAuthSessionAsync.js.map +1 -0
  38. package/lib-esm/index.d.ts +4 -0
  39. package/lib-esm/index.js +10 -0
  40. package/lib-esm/index.js.map +1 -0
  41. package/lib-esm/nativeModule.d.ts +2 -0
  42. package/lib-esm/nativeModule.js +15 -0
  43. package/lib-esm/nativeModule.js.map +1 -0
  44. package/lib-esm/types.d.ts +3 -0
  45. package/lib-esm/types.js +4 -0
  46. package/lib-esm/types.js.map +1 -0
  47. package/package.json +53 -0
  48. package/src/apis/openAuthSessionAsync.ts +91 -0
  49. package/src/index.ts +12 -0
  50. package/src/nativeModule.ts +23 -0
  51. package/src/types.ts +10 -0
@@ -0,0 +1 @@
1
+ export declare const openAuthSessionAsync: (url: string, redirectUrls: string[], prefersEphemeralSession?: boolean) => Promise<string | null | undefined>;
@@ -0,0 +1,64 @@
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 { nativeModule } from '../nativeModule';
5
+ let appStateListener;
6
+ let redirectListener;
7
+ export const openAuthSessionAsync = async (url, redirectUrls, prefersEphemeralSession) => {
8
+ // enforce HTTPS
9
+ const httpsUrl = url.replace('http://', 'https://');
10
+ if (Platform.OS === 'ios') {
11
+ return openAuthSessionIOS(httpsUrl, redirectUrls, prefersEphemeralSession);
12
+ }
13
+ if (Platform.OS === 'android') {
14
+ return openAuthSessionAndroid(httpsUrl, redirectUrls);
15
+ }
16
+ };
17
+ const openAuthSessionIOS = async (url, redirectUrls, prefersEphemeralSession = false) => {
18
+ const redirectUrl = redirectUrls.find(
19
+ // take the first non-web url as the deeplink
20
+ item => !item.startsWith('https://') && !item.startsWith('http://'));
21
+ return nativeModule.openAuthSessionAsync(url, redirectUrl, prefersEphemeralSession);
22
+ };
23
+ const openAuthSessionAndroid = async (url, redirectUrls) => {
24
+ try {
25
+ const [redirectUrl] = await Promise.all([
26
+ Promise.race([
27
+ // wait for app to redirect, resulting in a redirectUrl
28
+ getRedirectPromise(redirectUrls),
29
+ // wait for app to return some other way, resulting in null
30
+ getAppStatePromise(),
31
+ ]),
32
+ // open chrome tab
33
+ nativeModule.openAuthSessionAsync(url),
34
+ ]);
35
+ return redirectUrl;
36
+ }
37
+ finally {
38
+ appStateListener?.remove();
39
+ redirectListener?.remove();
40
+ appStateListener = undefined;
41
+ redirectListener = undefined;
42
+ }
43
+ };
44
+ const getAppStatePromise = () => new Promise(resolve => {
45
+ appStateListener = AppState.addEventListener('change', nextAppState => {
46
+ // if current state is null, the change is from initialization
47
+ if (AppState.currentState === null) {
48
+ return;
49
+ }
50
+ if (nextAppState === 'active') {
51
+ appStateListener?.remove();
52
+ appStateListener = undefined;
53
+ resolve(null);
54
+ }
55
+ });
56
+ });
57
+ const getRedirectPromise = (redirectUrls) => new Promise(resolve => {
58
+ redirectListener = Linking.addEventListener('url', event => {
59
+ if (redirectUrls.some(url => event.url.startsWith(url))) {
60
+ resolve(event.url);
61
+ }
62
+ });
63
+ });
64
+ //# 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,YAAY,EAAE,MAAM,iB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,CAAC,CAAC;QACH,OAAO,WAAW,CAAC;KACnB;YAAS;QACT,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAC3B,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAC3B,gBAAgB,GAAG,SAAS,CAAC;QAC7B,gBAAgB,GAAG,SAAS,CAAC;KAC7B;AACF,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,GAAkB,EAAE,CAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;IACrB,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE;QACrE,8DAA8D;QAC9D,IAAI,QAAQ,CAAC,YAAY,KAAK,IAAI,EAAE;YACnC,OAAO;SACP;QAED,IAAI,YAAY,KAAK,QAAQ,EAAE;YAC9B,gBAAgB,EAAE,MAAM,EAAE,CAAC;YAC3B,gBAAgB,GAAG,SAAS,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;SACd;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEJ,MAAM,kBAAkB,GAAG,CAAC,YAAsB,EAAmB,EAAE,CACtE,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;IACrB,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE;QAC1D,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE;YACxD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACnB;IACF,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const mergedModule: {
2
+ openAuthSessionAsync: (url: string, redirectUrls: string[], prefersEphemeralSession?: boolean | undefined) => 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 { nativeModule } from './nativeModule';
5
+ const mergedModule = {
6
+ ...nativeModule,
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,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,YAAY,GAAG;IACpB,GAAG,YAAY;IACf,oBAAoB;CACpB,CAAC;AAEF,OAAO,EAAE,YAAY,IAAI,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { WebBrowserNativeModule } from './types';
2
+ export declare const nativeModule: 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 nativeModule = NativeModules.AmplifyRTNWebBrowser
9
+ ? NativeModules.AmplifyRTNWebBrowser
10
+ : new Proxy({}, {
11
+ get() {
12
+ throw new Error(LINKING_ERROR);
13
+ },
14
+ });
15
+ //# sourceMappingURL=nativeModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeModule.js","sourceRoot":"","sources":["../src/nativeModule.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,YAAY,GACxB,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,3 @@
1
+ export type WebBrowserNativeModule = {
2
+ openAuthSessionAsync: (url: string, redirectUrl?: string, prefersEphemeralSession?: boolean) => 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.0",
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": "d505105326d7f6214f6bd1e06eb20be3a3651377"
53
+ }
@@ -0,0 +1,91 @@
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 { nativeModule } from '../nativeModule';
11
+
12
+ let appStateListener: NativeEventSubscription | undefined;
13
+ let redirectListener: NativeEventSubscription | undefined;
14
+
15
+ export const openAuthSessionAsync = async (
16
+ url: string,
17
+ redirectUrls: string[],
18
+ prefersEphemeralSession?: boolean
19
+ ) => {
20
+ // enforce HTTPS
21
+ const httpsUrl = url.replace('http://', 'https://');
22
+ if (Platform.OS === 'ios') {
23
+ return openAuthSessionIOS(httpsUrl, redirectUrls, prefersEphemeralSession);
24
+ }
25
+
26
+ if (Platform.OS === 'android') {
27
+ return openAuthSessionAndroid(httpsUrl, redirectUrls);
28
+ }
29
+ };
30
+
31
+ const openAuthSessionIOS = async (
32
+ url: string,
33
+ redirectUrls: string[],
34
+ prefersEphemeralSession: boolean = false
35
+ ) => {
36
+ const redirectUrl = redirectUrls.find(
37
+ // take the first non-web url as the deeplink
38
+ item => !item.startsWith('https://') && !item.startsWith('http://')
39
+ );
40
+ return nativeModule.openAuthSessionAsync(
41
+ url,
42
+ redirectUrl,
43
+ prefersEphemeralSession
44
+ );
45
+ };
46
+
47
+ const openAuthSessionAndroid = async (url: string, redirectUrls: string[]) => {
48
+ try {
49
+ const [redirectUrl] = await Promise.all([
50
+ Promise.race([
51
+ // wait for app to redirect, resulting in a redirectUrl
52
+ getRedirectPromise(redirectUrls),
53
+ // wait for app to return some other way, resulting in null
54
+ getAppStatePromise(),
55
+ ]),
56
+ // open chrome tab
57
+ nativeModule.openAuthSessionAsync(url),
58
+ ]);
59
+ return redirectUrl;
60
+ } finally {
61
+ appStateListener?.remove();
62
+ redirectListener?.remove();
63
+ appStateListener = undefined;
64
+ redirectListener = undefined;
65
+ }
66
+ };
67
+
68
+ const getAppStatePromise = (): Promise<null> =>
69
+ new Promise(resolve => {
70
+ appStateListener = AppState.addEventListener('change', nextAppState => {
71
+ // if current state is null, the change is from initialization
72
+ if (AppState.currentState === null) {
73
+ return;
74
+ }
75
+
76
+ if (nextAppState === 'active') {
77
+ appStateListener?.remove();
78
+ appStateListener = undefined;
79
+ resolve(null);
80
+ }
81
+ });
82
+ });
83
+
84
+ const getRedirectPromise = (redirectUrls: string[]): Promise<string> =>
85
+ new Promise(resolve => {
86
+ redirectListener = Linking.addEventListener('url', event => {
87
+ if (redirectUrls.some(url => event.url.startsWith(url))) {
88
+ resolve(event.url);
89
+ }
90
+ });
91
+ });
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 { nativeModule } from './nativeModule';
6
+
7
+ const mergedModule = {
8
+ ...nativeModule,
9
+ openAuthSessionAsync,
10
+ };
11
+
12
+ export { mergedModule as AmplifyRTNWebBrowser };
@@ -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 nativeModule: 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/types.ts ADDED
@@ -0,0 +1,10 @@
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: (
6
+ url: string,
7
+ redirectUrl?: string,
8
+ prefersEphemeralSession?: boolean
9
+ ) => Promise<string | null>;
10
+ };