micropaywall-embed-react 0.1.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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # micropaywall-embed-react
2
+
3
+ Lightweight **React iframe embed** for Micropaywall checkout. Keeps Solana/EVM wallet code on the hosted app; your site only renders an iframe.
4
+
5
+ **Note:** The scoped name `@micropaywall/embed-react` requires an npm org named `micropaywall`. This package uses an unscoped name so you can publish without creating that org. To use a scope, create the org at [npmjs.com/org/create](https://www.npmjs.com/org/create) and change the `name` in `package.json`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install micropaywall-embed-react
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { MicropaywallEmbed } from 'micropaywall-embed-react';
17
+
18
+ export function Checkout() {
19
+ return (
20
+ <MicropaywallEmbed
21
+ merchantId="your-merchant-uuid"
22
+ slug="your-content-slug"
23
+ baseUrl="https://micropaywall.app"
24
+ />
25
+ );
26
+ }
27
+ ```
28
+
29
+ ## Publish
30
+
31
+ From this directory:
32
+
33
+ ```bash
34
+ npm run build
35
+ npm publish --access public
36
+ ```
37
+
38
+ Unscoped packages are public by default; `--access public` is optional. Add a `repository` field to `package.json` when you have a Git URL (optional for npm).
39
+
40
+ ## Full checkout component
41
+
42
+ For a drop-in widget with wallets inside **your** app, depend on the main app’s `PaymentWidget` (or copy it) and list `wagmi`, `@solana/wallet-adapter-*`, etc. as peer dependencies—that is a heavier package; this embed is the recommended default for third-party sites.
@@ -0,0 +1,18 @@
1
+ import { type CSSProperties } from 'react';
2
+ export interface MicropaywallEmbedProps {
3
+ merchantId: string;
4
+ slug: string;
5
+ /** Hosted app origin, default production */
6
+ baseUrl?: string;
7
+ /** Initial iframe min-height in px */
8
+ minHeight?: number;
9
+ className?: string;
10
+ style?: CSSProperties;
11
+ title?: string;
12
+ }
13
+ /**
14
+ * Embeds the hosted Micropaywall content checkout in an iframe.
15
+ * Listens for `micropaywall:resize` postMessage to adjust height (same protocol as `public/micropaywall-embed.js`).
16
+ */
17
+ export declare function MicropaywallEmbed({ merchantId, slug, baseUrl, minHeight, className, style, title, }: MicropaywallEmbedProps): import("react/jsx-runtime").JSX.Element;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4C,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAErF,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,UAAU,EACV,IAAI,EACJ,OAAoC,EACpC,SAAe,EACf,SAAS,EACT,KAAK,EACL,KAA+B,GAChC,EAAE,sBAAsB,2CAuCxB"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ /**
4
+ * Embeds the hosted Micropaywall content checkout in an iframe.
5
+ * Listens for `micropaywall:resize` postMessage to adjust height (same protocol as `public/micropaywall-embed.js`).
6
+ */
7
+ export function MicropaywallEmbed({ merchantId, slug, baseUrl = 'https://micropaywall.app', minHeight = 520, className, style, title = 'Micropaywall checkout', }) {
8
+ const iframeRef = useRef(null);
9
+ const [height, setHeight] = useState(minHeight);
10
+ const src = `${baseUrl.replace(/\/$/, '')}/marketplace/content/?merchantId=${encodeURIComponent(merchantId)}&slug=${encodeURIComponent(slug)}`;
11
+ const onMessage = useCallback((ev) => {
12
+ const data = ev.data;
13
+ if (!data || data.type !== 'micropaywall:resize')
14
+ return;
15
+ if (typeof data.height === 'number' && data.height > 200) {
16
+ setHeight(Math.min(data.height + 32, 3200));
17
+ }
18
+ }, []);
19
+ useEffect(() => {
20
+ window.addEventListener('message', onMessage);
21
+ return () => window.removeEventListener('message', onMessage);
22
+ }, [onMessage]);
23
+ return (_jsx("iframe", { ref: iframeRef, src: src, title: title, className: className, style: {
24
+ width: '100%',
25
+ border: 0,
26
+ minHeight,
27
+ height,
28
+ ...style,
29
+ }, loading: "lazy", referrerPolicy: "strict-origin-when-cross-origin" }));
30
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "micropaywall-embed-react",
3
+ "version": "0.1.0",
4
+ "description": "React iframe embed for Micropaywall checkout pages (no wallet deps in your app)",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "sideEffects": false,
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.build.json",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "peerDependencies": {
25
+ "react": "^18.0.0 || ^19.0.0",
26
+ "react-dom": "^18.0.0 || ^19.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/react": "^18.3.0",
30
+ "typescript": "^5.3.3"
31
+ },
32
+ "keywords": [
33
+ "micropaywall",
34
+ "paywall",
35
+ "crypto",
36
+ "react",
37
+ "embed"
38
+ ]
39
+ }