@pinwheel/react-native-pinwheel 2.3.1 → 2.3.5

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 ADDED
@@ -0,0 +1,25 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## 2.3.x Releases
6
+
7
+ - `2.3.x` Releases - [2.3.4](#234)
8
+
9
+ ---
10
+
11
+ ### [2.3.4](https://github.com/underdog-tech/react-native-pinwheel/releases/tag/2.3.4)
12
+
13
+ #### Added
14
+
15
+ - Export `EventPayload` type.
16
+ - Export `PinwheelError` type.
17
+ - Export `PinwheelErrorType` type.
18
+ - Export `EmptyPayloadObject` type as `Record<string, never>`.
19
+
20
+ ##### Updated
21
+
22
+ - `EventPayload` is no longer a union containing `{}`. It now contains `Record<string, never>` instead due to [this behavior](https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-all-types-assignable-to-empty-interfaces).
23
+ - Mark exported `Error` type as **@deprecated** because it collides with the built-in javascript `Error` object. Replaced with `PinwheelError`.
24
+ - Mark exported `ErrorType` type as **@deprecated** because the new naming convention is prefixing with "`PinwheelError`". Replaced with `PinwheelErrorType`.
25
+ - Update `onExit` type to be `(error: PinwheelError | Record<string, never>)` to be accurate with current functionality.
@@ -0,0 +1,27 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinwheel/react-native-pinwheel",
3
- "version": "2.3.1",
3
+ "version": "2.3.5",
4
4
  "type": "module",
5
5
  "description": "Pinwheel React Native SDK",
6
6
  "main": "lib/index.js",
@@ -9,7 +9,8 @@
9
9
  "lib/**/*"
10
10
  ],
11
11
  "scripts": {
12
- "build": "tsc"
12
+ "build": "tsc",
13
+ "pinwheel-publish": "./scripts/publish.sh"
13
14
  },
14
15
  "author": "Pinwheel",
15
16
  "license": "MIT",
package/lib/index.d.ts DELETED
@@ -1,51 +0,0 @@
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
- job: string;
12
- params: {
13
- amount?: {
14
- value: number;
15
- unit: '%' | '$';
16
- };
17
- };
18
- };
19
- export declare type ErrorType = 'clientError' | 'systemError' | 'userActionRequired' | 'platformError' | 'invalidAccountsConfiguration' | 'invalidUserInput' | 'invalidLinkToken';
20
- export declare type Error = {
21
- type: ErrorType;
22
- code: string;
23
- message: string;
24
- pendingRetry: boolean;
25
- };
26
- declare type EventPayload = {
27
- selectedEmployerId: string;
28
- selectedEmployerName: string;
29
- } | {
30
- selectedPlatformId: string;
31
- selectedPlatformName: string;
32
- } | {
33
- value: number;
34
- unit: '%' | '$';
35
- } | LinkResult | {
36
- accountId: string;
37
- platformId: string;
38
- } | Error | {} | undefined;
39
- declare type PinwheelProps = {
40
- linkToken: string;
41
- onLogin?: (result: {
42
- accountId: string;
43
- platformId: string;
44
- }) => void;
45
- onSuccess?: (result: LinkResult) => void;
46
- onError?: (error: Error) => void;
47
- onExit?: (error?: Error) => void;
48
- onEvent?: (eventName: string, payload: EventPayload) => void;
49
- };
50
- declare const _default: ({ linkToken, onLogin, onSuccess, onError, onExit, onEvent }: PinwheelProps) => JSX.Element;
51
- export default _default;
package/lib/index.js DELETED
@@ -1,120 +0,0 @@
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.0';
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, 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
- console.error(error);
31
- onExit && onExit(error);
32
- onError && onError(error);
33
- onEvent && onEvent('error', error);
34
- return;
35
- }
36
- const { type, eventName, payload } = eventData;
37
- if (type === 'PINWHEEL_EVENT') {
38
- onEvent && onEvent(eventName, payload);
39
- switch (eventName) {
40
- case 'exit':
41
- onExit && onExit(payload);
42
- break;
43
- case 'success':
44
- onSuccess && onSuccess(payload);
45
- break;
46
- case 'login':
47
- onLogin && onLogin(payload);
48
- break;
49
- case 'error':
50
- onError && onError(payload);
51
- break;
52
- default:
53
- }
54
- }
55
- };
56
- const now = Date.now();
57
- const [major, minor, patch] = version.split('.').map(x => Number(x));
58
- const runFirst = `
59
- const uuidKey = 'pinwheel-uuid';
60
- const localStorage = window.localStorage;
61
- let uuid = localStorage.getItem(uuidKey);
62
- if(!uuid) {
63
- uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
64
- var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
65
- return v.toString(16);
66
- });
67
- localStorage.setItem(uuidKey, uuid);
68
- }
69
- try {
70
- window.addEventListener('message', event => {
71
- window.ReactNativeWebView.postMessage(JSON.stringify(event.data))
72
- });
73
- window.postMessage(
74
- {
75
- type: 'PINWHEEL_INIT',
76
- payload: {
77
- platform: "${Platform.OS}",
78
- sdk: 'react native',
79
- version: {
80
- major: ${major},
81
- minor: ${minor},
82
- patch: ${patch}
83
- },
84
- initializationOptions: {
85
- hasOnSuccess: ${!!onSuccess},
86
- hasOnEvent: ${!!onEvent},
87
- hasOnExit: ${!!onExit},
88
- hasOnError: ${!!onError},
89
- hasOnLogin: ${!!onLogin},
90
- },
91
- linkToken: '${linkToken}',
92
- uniqueUserId: uuid,
93
- initializationTimestamp: ${now}
94
- }
95
- }
96
- );
97
- } catch (err) {
98
- console.error(err);
99
- }
100
- true;
101
- `;
102
- return (<SafeAreaView style={styles.container}>
103
- <WebView source={{ uri: LINK_PAGE_URL }} onMessage={handleEvent} injectedJavaScript={runFirst} onShouldStartLoadWithRequest={(request) => {
104
- const targetURL = request.url;
105
- const isLinkPage = targetURL.includes(PINWHEEL_DOMAIN);
106
- if (!isLinkPage) {
107
- Linking.canOpenURL(targetURL).then(supported => {
108
- if (supported) {
109
- Linking.openURL(targetURL).then(() => { });
110
- }
111
- else {
112
- console.warn('Don\'t know how to open URL: ' + targetURL);
113
- }
114
- return false;
115
- }).catch(err => console.error('An error occurred ', err));
116
- }
117
- return isLinkPage;
118
- }}/>
119
- </SafeAreaView>);
120
- };