@pulsebyshiga/collect-react-native 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shiga Digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @pulsebyshiga/collect-react-native
2
+
3
+ React Native bindings for Pulse Collect — renders the same Pulse-hosted embed used on the
4
+ web inside a WebView, with events delivered through the native message bridge.
5
+
6
+ > **Status: pre-release (0.1.0).** Validate on physical devices before shipping — see
7
+ > [docs/rn-validation.md](../../docs/rn-validation.md) for the Expo recipe.
8
+
9
+ ## Requirements
10
+
11
+ - React ≥ 18 and `react-native-webview` ≥ 13 (peer dependencies)
12
+ - A session token (`cs_*`) minted by your backend with [`@pulsebyshiga/node`](../node-sdk)
13
+
14
+ ## Installation
15
+
16
+ ```sh
17
+ npm install @pulsebyshiga/collect-react-native react-native-webview
18
+ # then: cd ios && pod install (bare RN) — Expo projects need no extra step
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```tsx
24
+ import { PulseCollectPayment } from '@pulsebyshiga/collect-react-native';
25
+
26
+ export function FundScreen({ sessionToken }: { sessionToken: string }) {
27
+ return (
28
+ <PulseCollectPayment
29
+ sessionToken={sessionToken}
30
+ theme={{ primaryColor: '#083a9a' }}
31
+ onSuccess={(orderId) => showFunded(orderId)} // UX only — credit off the webhook
32
+ onError={(code, message) => report(code, message)}
33
+ />
34
+ );
35
+ }
36
+ ```
37
+
38
+ ## Props
39
+
40
+ | Prop | Type | Description |
41
+ | --------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------ |
42
+ | `sessionToken` | `string` (required) | Single-order session token from your backend. |
43
+ | `flow` | `"select" \| "direct"` | Selection flow (default) or pinned asset/network. |
44
+ | `networks` / `assets` | `string[]` | Narrow the selectable sets for this mount (narrowing only — see `@pulsebyshiga/collect-js`). |
45
+ | `theme` / `strings` | `EmbedTheme` / `EmbedStrings` | Same tokens and placeholders as the web loader. |
46
+ | `style` | WebView style | When omitted, the WebView height follows the embed content. |
47
+ | `embedUrl` / `apiUrl` | `string` | Origin overrides for local development. |
48
+ | callbacks | — | `onReady`, `onStatusChange`, `onSuccess`, `onQuoteExpired`, `onQuoteRefreshed`, `onError`, `onResize`. |
49
+
50
+ ## Platform notes
51
+
52
+ - **Configuration travels in the URL.** Theme and copy are applied via URL params at load —
53
+ there is no message-in channel on React Native, so changing `theme`/`strings` props
54
+ reloads the WebView (the memoized source changes).
55
+ - **Height** — the embed reports its content height; the wrapper tracks it automatically
56
+ unless you pass `style`. `onResize(height)` exposes the raw signal.
57
+ - **Events** — all embed events arrive through `onMessage` on the WebView; the wrapper
58
+ validates and dispatches them to your typed callbacks (`dispatchEmbedMessage` is exported
59
+ for custom WebView setups).
60
+
61
+ ## Security model
62
+
63
+ Identical to the web: your `sk_*` key and user PII stay on your backend; the app receives
64
+ only the single-order `cs_*` token, and the payment surface renders inside Pulse-hosted
65
+ content. Credit users exclusively from the signed `disbursement.completed` webhook.
66
+
67
+ ## License
68
+
69
+ [MIT](../../LICENSE) © Shiga Digital
@@ -0,0 +1,10 @@
1
+ import { type MountOptions } from '@pulsebyshiga/collect-js';
2
+ export type EmbedCallbacks = Pick<MountOptions, 'onReady' | 'onStatusChange' | 'onSuccess' | 'onQuoteExpired' | 'onQuoteRefreshed' | 'onError'> & {
3
+ onResize?: (height: number) => void;
4
+ };
5
+ /**
6
+ * Dispatch a WebView onMessage payload (JSON string posted by the embed via
7
+ * window.ReactNativeWebView) to the partner's callbacks. Non-JSON and
8
+ * unrelated messages are ignored.
9
+ */
10
+ export declare function dispatchEmbedMessage(data: string, callbacks: EmbedCallbacks): void;
@@ -0,0 +1,40 @@
1
+ import { isEmbedToHostMessage } from '@pulsebyshiga/collect-js';
2
+ /**
3
+ * Dispatch a WebView onMessage payload (JSON string posted by the embed via
4
+ * window.ReactNativeWebView) to the partner's callbacks. Non-JSON and
5
+ * unrelated messages are ignored.
6
+ */
7
+ export function dispatchEmbedMessage(data, callbacks) {
8
+ let parsed;
9
+ try {
10
+ parsed = JSON.parse(data);
11
+ }
12
+ catch {
13
+ return;
14
+ }
15
+ if (!isEmbedToHostMessage(parsed))
16
+ return;
17
+ switch (parsed.type) {
18
+ case 'ready':
19
+ callbacks.onReady?.();
20
+ break;
21
+ case 'resize':
22
+ callbacks.onResize?.(parsed.height);
23
+ break;
24
+ case 'status_change':
25
+ callbacks.onStatusChange?.(parsed.status, parsed.orderId);
26
+ break;
27
+ case 'quote_expired':
28
+ callbacks.onQuoteExpired?.();
29
+ break;
30
+ case 'quote_refreshed':
31
+ callbacks.onQuoteRefreshed?.(parsed.lockedUntil);
32
+ break;
33
+ case 'success':
34
+ callbacks.onSuccess?.(parsed.orderId);
35
+ break;
36
+ case 'error':
37
+ callbacks.onError?.(parsed.code, parsed.message);
38
+ break;
39
+ }
40
+ }
@@ -0,0 +1,28 @@
1
+ import { type EmbedStrings, type EmbedTheme } from '@pulsebyshiga/collect-js';
2
+ import { type ReactElement } from 'react';
3
+ import { type EmbedCallbacks } from './handleMessage.js';
4
+ export type PulseCollectPaymentProps = EmbedCallbacks & {
5
+ /** Single-order session token from the partner backend. */
6
+ sessionToken: string;
7
+ embedUrl?: string;
8
+ apiUrl?: string;
9
+ /** "select" (default): in-embed asset/network selection; "direct": pinned. */
10
+ flow?: 'select' | 'direct';
11
+ /** Narrow selectable networks (intersected with the partner config; never widens). */
12
+ networks?: string[];
13
+ /** Narrow payable assets (same narrowing rules as `networks`). */
14
+ assets?: string[];
15
+ theme?: EmbedTheme;
16
+ /** Copy overrides travel via URL params on React Native. */
17
+ strings?: EmbedStrings;
18
+ /** WebView style. When omitted, height follows the embed content. */
19
+ style?: unknown;
20
+ };
21
+ /**
22
+ * Payment component for React Native. Renders the same Pulse-controlled embed
23
+ * used on the web inside a WebView; theme and copy arrive via URL params, and
24
+ * embed events arrive through the WebView message bridge.
25
+ */
26
+ export declare function PulseCollectPayment(props: PulseCollectPaymentProps): ReactElement;
27
+ export { dispatchEmbedMessage, type EmbedCallbacks } from './handleMessage.js';
28
+ export type { EmbedStatus, EmbedStrings, EmbedTheme } from '@pulsebyshiga/collect-js';
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { buildEmbedSrc } from '@pulsebyshiga/collect-js';
3
+ import { useMemo, useState } from 'react';
4
+ import { WebView } from 'react-native-webview';
5
+ import { dispatchEmbedMessage } from './handleMessage.js';
6
+ /**
7
+ * Payment component for React Native. Renders the same Pulse-controlled embed
8
+ * used on the web inside a WebView; theme and copy arrive via URL params, and
9
+ * embed events arrive through the WebView message bridge.
10
+ */
11
+ export function PulseCollectPayment(props) {
12
+ const { sessionToken, embedUrl, apiUrl, flow, networks, assets, theme, strings, style, ...callbacks } = props;
13
+ const [height, setHeight] = useState(420);
14
+ const src = useMemo(() => buildEmbedSrc({ sessionToken, embedUrl, apiUrl, flow, networks, assets, theme, strings }).src, [sessionToken, embedUrl, apiUrl, flow, networks, assets, theme, strings]);
15
+ return (_jsx(WebView, { source: { uri: src }, javaScriptEnabled: true, originWhitelist: ['https://*', 'http://*'], style: style ?? { height }, onMessage: (event) => dispatchEmbedMessage(event.nativeEvent.data, {
16
+ ...callbacks,
17
+ onResize: (nextHeight) => {
18
+ callbacks.onResize?.(nextHeight);
19
+ setHeight(nextHeight);
20
+ },
21
+ }) }));
22
+ }
23
+ export { dispatchEmbedMessage } from './handleMessage.js';
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@pulsebyshiga/collect-react-native",
3
+ "version": "0.2.0",
4
+ "description": "React Native bindings for Pulse Collect — <PulseCollectPayment /> rendering the same Pulse-controlled embed in a WebView",
5
+ "license": "MIT",
6
+ "author": "Shiga Digital",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Pulse-Digital/pulse-collect.git",
10
+ "directory": "packages/collect-react-native"
11
+ },
12
+ "sideEffects": false,
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "peerDependencies": {
26
+ "react": ">=18",
27
+ "react-native-webview": ">=13"
28
+ },
29
+ "dependencies": {
30
+ "@pulsebyshiga/collect-js": "0.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/react": "^18.3.12",
34
+ "react": "^18.3.1",
35
+ "typescript": "^5.6.3",
36
+ "vitest": "^3.0.0"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.build.json",
40
+ "typecheck": "tsc -p tsconfig.json --noEmit",
41
+ "test": "vitest run"
42
+ }
43
+ }