@pinwheel/react-native-pinwheel 2.3.5 → 2.3.8
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/CHANGELOG.md +9 -1
- package/lib/index.d.ts +66 -0
- package/lib/index.js +124 -0
- package/package.json +1 -1
- package/lib/package.json +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -4,10 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## 2.3.x Releases
|
|
6
6
|
|
|
7
|
-
- `2.3.x` Releases - [2.3.4](#234)
|
|
7
|
+
- `2.3.x` Releases - [2.3.4](#234) [2.3.5](#235) [2.3.6](#236)
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
+
### [2.3.6](https://github.com/underdog-tech/react-native-pinwheel/releases/tag/2.3.6)
|
|
12
|
+
|
|
13
|
+
N/A
|
|
14
|
+
|
|
15
|
+
### [2.3.5](https://github.com/underdog-tech/react-native-pinwheel/releases/tag/2.3.5)
|
|
16
|
+
|
|
17
|
+
N/A
|
|
18
|
+
|
|
11
19
|
### [2.3.4](https://github.com/underdog-tech/react-native-pinwheel/releases/tag/2.3.4)
|
|
12
20
|
|
|
13
21
|
#### Added
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const PINWHEEL_MESSAGE_TYPES: {
|
|
3
|
+
PINWHEEL_EXIT: string;
|
|
4
|
+
PINWHEEL_MODAL_CLOSE: string;
|
|
5
|
+
PINWHEEL_LOAD_COMPLETE: string;
|
|
6
|
+
PINWHEEL_SUCCESS: string;
|
|
7
|
+
PINWHEEL_EVENT: string;
|
|
8
|
+
};
|
|
9
|
+
export declare type LinkResult = {
|
|
10
|
+
accountId: string;
|
|
11
|
+
platformId: string;
|
|
12
|
+
job: string;
|
|
13
|
+
params: {
|
|
14
|
+
amount?: {
|
|
15
|
+
value: number;
|
|
16
|
+
unit: '%' | '$';
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated This type will be removed in version 2.4. Use the renamed type `PinwheelErrorType`
|
|
22
|
+
* instead.
|
|
23
|
+
*/
|
|
24
|
+
export declare type ErrorType = 'clientError' | 'systemError' | 'userActionRequired' | 'platformError' | 'invalidAccountsConfiguration' | 'invalidUserInput' | 'invalidLinkToken';
|
|
25
|
+
export declare type PinwheelErrorType = ErrorType;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated The type should not be used as it clashes with the native JS `Error` object.
|
|
28
|
+
* You should use `PinwheelError` instead. `Error` will be removed in version 2.4
|
|
29
|
+
*/
|
|
30
|
+
export declare type Error = {
|
|
31
|
+
type: PinwheelErrorType;
|
|
32
|
+
code: string;
|
|
33
|
+
message: string;
|
|
34
|
+
pendingRetry: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare type PinwheelError = Error;
|
|
37
|
+
export declare type EmptyPayloadObject = Record<string, never>;
|
|
38
|
+
export declare type EventPayload = {
|
|
39
|
+
selectedEmployerId: string;
|
|
40
|
+
selectedEmployerName: string;
|
|
41
|
+
} | {
|
|
42
|
+
selectedPlatformId: string;
|
|
43
|
+
selectedPlatformName: string;
|
|
44
|
+
} | {
|
|
45
|
+
value: number;
|
|
46
|
+
unit: '%' | '$';
|
|
47
|
+
} | LinkResult | {
|
|
48
|
+
accountId: string;
|
|
49
|
+
platformId: string;
|
|
50
|
+
} | PinwheelError | EmptyPayloadObject | undefined;
|
|
51
|
+
declare type PinwheelProps = {
|
|
52
|
+
linkToken: string;
|
|
53
|
+
onLogin?: (result: {
|
|
54
|
+
accountId: string;
|
|
55
|
+
platformId: string;
|
|
56
|
+
}) => void;
|
|
57
|
+
onLoginAttempt?: (result: {
|
|
58
|
+
platformId: string;
|
|
59
|
+
}) => void;
|
|
60
|
+
onSuccess?: (result: LinkResult) => void;
|
|
61
|
+
onError?: (error: PinwheelError) => void;
|
|
62
|
+
onExit?: (error: PinwheelError | EmptyPayloadObject) => void;
|
|
63
|
+
onEvent?: (eventName: string, payload: EventPayload) => void;
|
|
64
|
+
};
|
|
65
|
+
declare const _default: ({ linkToken, onLogin, onLoginAttempt, onSuccess, onError, onExit, onEvent }: PinwheelProps) => JSX.Element;
|
|
66
|
+
export default _default;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { WebView } from 'react-native-webview';
|
|
3
|
+
import { Linking, Platform, SafeAreaView, StyleSheet } from 'react-native';
|
|
4
|
+
const version = '2.3.8';
|
|
5
|
+
const styles = StyleSheet.create({
|
|
6
|
+
container: {
|
|
7
|
+
flex: 1,
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
export const PINWHEEL_MESSAGE_TYPES = {
|
|
11
|
+
PINWHEEL_EXIT: 'PINWHEEL_EXIT',
|
|
12
|
+
PINWHEEL_MODAL_CLOSE: 'PINWHEEL_MODAL_CLOSE',
|
|
13
|
+
PINWHEEL_LOAD_COMPLETE: 'PINWHEEL_LOAD_COMPLETE',
|
|
14
|
+
PINWHEEL_SUCCESS: 'PINWHEEL_SUCCESS',
|
|
15
|
+
PINWHEEL_EVENT: 'PINWHEEL_EVENT',
|
|
16
|
+
};
|
|
17
|
+
const LINK_PAGE_URL = 'https://cdn.getpinwheel.com/link-v2.3.0.html';
|
|
18
|
+
const PINWHEEL_DOMAIN = 'getpinwheel.com';
|
|
19
|
+
export default ({ linkToken, onLogin, onLoginAttempt, onSuccess, onError, onExit, onEvent }) => {
|
|
20
|
+
const handleEvent = (event) => {
|
|
21
|
+
if (!event) {
|
|
22
|
+
// first event is always an empty string
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let eventData;
|
|
26
|
+
try {
|
|
27
|
+
eventData = JSON.parse(event.nativeEvent.data);
|
|
28
|
+
}
|
|
29
|
+
catch (_error) {
|
|
30
|
+
let error = _error;
|
|
31
|
+
console.error(error);
|
|
32
|
+
onExit && onExit(error);
|
|
33
|
+
onError && onError(error);
|
|
34
|
+
onEvent && onEvent('error', error);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const { type, eventName, payload } = eventData;
|
|
38
|
+
if (type === 'PINWHEEL_EVENT') {
|
|
39
|
+
onEvent && onEvent(eventName, payload);
|
|
40
|
+
switch (eventName) {
|
|
41
|
+
case 'exit':
|
|
42
|
+
onExit && onExit(payload);
|
|
43
|
+
break;
|
|
44
|
+
case 'success':
|
|
45
|
+
onSuccess && onSuccess(payload);
|
|
46
|
+
break;
|
|
47
|
+
case 'login':
|
|
48
|
+
onLogin && onLogin(payload);
|
|
49
|
+
break;
|
|
50
|
+
case 'login_attempt':
|
|
51
|
+
onLoginAttempt && onLoginAttempt(payload);
|
|
52
|
+
break;
|
|
53
|
+
case 'error':
|
|
54
|
+
onError && onError(payload);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
const [major, minor, patch] = version.split('.').map(x => Number(x));
|
|
62
|
+
const runFirst = `
|
|
63
|
+
const uuidKey = 'pinwheel-uuid';
|
|
64
|
+
const localStorage = window.localStorage;
|
|
65
|
+
let uuid = localStorage.getItem(uuidKey);
|
|
66
|
+
if(!uuid) {
|
|
67
|
+
uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
68
|
+
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
69
|
+
return v.toString(16);
|
|
70
|
+
});
|
|
71
|
+
localStorage.setItem(uuidKey, uuid);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
window.addEventListener('message', event => {
|
|
75
|
+
window.ReactNativeWebView.postMessage(JSON.stringify(event.data))
|
|
76
|
+
});
|
|
77
|
+
window.postMessage(
|
|
78
|
+
{
|
|
79
|
+
type: 'PINWHEEL_INIT',
|
|
80
|
+
payload: {
|
|
81
|
+
platform: "${Platform.OS}",
|
|
82
|
+
sdk: 'react native',
|
|
83
|
+
version: {
|
|
84
|
+
major: ${major},
|
|
85
|
+
minor: ${minor},
|
|
86
|
+
patch: ${patch}
|
|
87
|
+
},
|
|
88
|
+
initializationOptions: {
|
|
89
|
+
hasOnSuccess: ${!!onSuccess},
|
|
90
|
+
hasOnEvent: ${!!onEvent},
|
|
91
|
+
hasOnExit: ${!!onExit},
|
|
92
|
+
hasOnError: ${!!onError},
|
|
93
|
+
hasOnLogin: ${!!onLogin},
|
|
94
|
+
},
|
|
95
|
+
linkToken: '${linkToken}',
|
|
96
|
+
uniqueUserId: uuid,
|
|
97
|
+
initializationTimestamp: ${now}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error(err);
|
|
103
|
+
}
|
|
104
|
+
true;
|
|
105
|
+
`;
|
|
106
|
+
return (<SafeAreaView style={styles.container}>
|
|
107
|
+
<WebView source={{ uri: LINK_PAGE_URL }} onMessage={handleEvent} injectedJavaScript={runFirst} onShouldStartLoadWithRequest={(request) => {
|
|
108
|
+
const targetURL = request.url;
|
|
109
|
+
const isLinkPage = targetURL.includes(PINWHEEL_DOMAIN);
|
|
110
|
+
if (!isLinkPage) {
|
|
111
|
+
Linking.canOpenURL(targetURL).then(supported => {
|
|
112
|
+
if (supported) {
|
|
113
|
+
Linking.openURL(targetURL).then(() => { });
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.warn('Don\'t know how to open URL: ' + targetURL);
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}).catch(err => console.error('An error occurred ', err));
|
|
120
|
+
}
|
|
121
|
+
return isLinkPage;
|
|
122
|
+
}}/>
|
|
123
|
+
</SafeAreaView>);
|
|
124
|
+
};
|
package/package.json
CHANGED
package/lib/package.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pinwheel/react-native-pinwheel",
|
|
3
|
-
"version": "2.3.5",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Pinwheel React Native SDK",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"types": "lib/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"lib/**/*"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"pinwheel-publish": "./scripts/publish.sh"
|
|
14
|
-
},
|
|
15
|
-
"author": "Pinwheel",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"peerDependencies": {
|
|
18
|
-
"react": "16.13.1",
|
|
19
|
-
"react-native": "0.63.3",
|
|
20
|
-
"react-native-webview": "^10.10.0"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/react-native": "^0.63.29",
|
|
24
|
-
"react-native-webview": "^10.9.2",
|
|
25
|
-
"typescript": "^4.0.3"
|
|
26
|
-
}
|
|
27
|
-
}
|