@metrifox/react-sdk 0.0.1
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 +21 -0
- package/README.md +166 -0
- package/dist/index.cjs +45 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.js +45 -0
- package/dist/styles.css +3 -0
- package/package.json +104 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Metrifox
|
|
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,166 @@
|
|
|
1
|
+
# MetriFox React SDK
|
|
2
|
+
|
|
3
|
+
A fully-configurable **React SDK** providing ready-to-use widgets for SaaS and billing platforms including customer portals, billing sections, and more.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# using npm
|
|
11
|
+
npm install @metrifox/react-sdk
|
|
12
|
+
|
|
13
|
+
# or pnpm
|
|
14
|
+
pnpm add @metrifox/react-sdk
|
|
15
|
+
|
|
16
|
+
# or yarn
|
|
17
|
+
yarn add @metrifox/react-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
Before using any SDK components, initialize it once with your API key (and optional base URL).
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { metrifoxInit } from "@metrifox/react-sdk"
|
|
28
|
+
|
|
29
|
+
metrifoxInit({
|
|
30
|
+
apiKey:
|
|
31
|
+
process.env.NEXT_PUBLIC_METRIFOX_API_KEY ||
|
|
32
|
+
process.env.REACT_APP_METRIFOX_API_KEY ||
|
|
33
|
+
import.meta.env?.VITE_METRIFOX_API_KEY ||
|
|
34
|
+
"your-api-key",
|
|
35
|
+
// baseUrl: "https://api.example.com" // Optional (defaults to Metrifox Cloud)
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
> Works with **React**, **Next.js**, and other frameworks using React 18+.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Core Widget: `CustomerPortal`
|
|
44
|
+
|
|
45
|
+
Displays a customizable customer dashboard with plans, subscriptions, billing, credits, and more.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { CustomerPortal } from "@metrifox/react-sdk"
|
|
49
|
+
|
|
50
|
+
const MyCustomPlan = ({ foo }) => <div>Custom Plan! Foo: {foo}</div>
|
|
51
|
+
|
|
52
|
+
export default function MyPortalPage() {
|
|
53
|
+
return (
|
|
54
|
+
<CustomerPortal
|
|
55
|
+
customerKey="your-customer-key"
|
|
56
|
+
sectionsConfig={[
|
|
57
|
+
{ key: "subscription" },
|
|
58
|
+
{ key: "plan", component: MyCustomPlan, props: { foo: "bar" } },
|
|
59
|
+
{ key: "billingHistory", hidden: true },
|
|
60
|
+
]}
|
|
61
|
+
/>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Section Configuration
|
|
69
|
+
|
|
70
|
+
The `sectionsConfig` prop controls what appears in the portal.
|
|
71
|
+
|
|
72
|
+
| Property | Type | Description |
|
|
73
|
+
| ----------- | ------------------------- | --------------------------------------------------- |
|
|
74
|
+
| `key` | `SectionKey` | Unique key of the section (see list below) |
|
|
75
|
+
| `hidden` | `boolean` | Hide this section when `true` |
|
|
76
|
+
| `component` | `React.ComponentType` | Replace the default section with your own component |
|
|
77
|
+
| `props` | `Record<string, unknown>` | Extra props passed to the custom or default section |
|
|
78
|
+
|
|
79
|
+
### Built-in Section Keys
|
|
80
|
+
|
|
81
|
+
| Key | Description |
|
|
82
|
+
| ------------------ | ----------------------------- |
|
|
83
|
+
| `upcomingInvoice` | Displays next invoice details |
|
|
84
|
+
| `subscription` | Active subscription overview |
|
|
85
|
+
| `walletBalance` | Shows user wallet balance |
|
|
86
|
+
| `entitlementUsage` | Displays resource usage |
|
|
87
|
+
| `paymentOverview` | Payment summary and methods |
|
|
88
|
+
| `billingHistory` | List of past transactions |
|
|
89
|
+
| `plan` | Current plan details |
|
|
90
|
+
|
|
91
|
+
### Section Anchors
|
|
92
|
+
|
|
93
|
+
Each portal section now renders inside a `<section id="...">` wrapper so you can link directly to segments of a customer portal view. The default anchor IDs are:
|
|
94
|
+
|
|
95
|
+
| Anchor ID | Section Key |
|
|
96
|
+
| ------------------ | ------------------ |
|
|
97
|
+
| `#upcoming-invoice` | `upcomingInvoice` |
|
|
98
|
+
| `#subscription` | `subscription` |
|
|
99
|
+
| `#credit-balance` | `creditBalance` |
|
|
100
|
+
| `#entitlement-usage`| `entitlementUsage`|
|
|
101
|
+
| `#payment-overview` | `paymentOverview` |
|
|
102
|
+
| `#billing-history` | `billingHistory` |
|
|
103
|
+
| `#plan` | `plan` |
|
|
104
|
+
|
|
105
|
+
Use these anchors when embedding the SDK or sharing deep links (e.g., `https://app.example.com/portal#billing-history`).
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Styling
|
|
110
|
+
|
|
111
|
+
Import the SDK’s global styles into your app entry (e.g., `src/index.tsx` or `_app.tsx`):
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import "@metrifox/react-sdk/dist/styles.css"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
> This is required for proper styling of all widgets.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Local Development
|
|
122
|
+
|
|
123
|
+
### Using [yalc](https://github.com/wclr/yalc)
|
|
124
|
+
|
|
125
|
+
For local SDK testing:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# In SDK project
|
|
129
|
+
pnpm build
|
|
130
|
+
npx yalc publish
|
|
131
|
+
|
|
132
|
+
# In consuming app
|
|
133
|
+
npx yalc add @metrifox/react-sdk
|
|
134
|
+
pnpm install
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Auto-update during development
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# In SDK project
|
|
141
|
+
pnpm dev:build # watch & rebuild
|
|
142
|
+
pnpm dev:link # re-publish build to yalc
|
|
143
|
+
|
|
144
|
+
# In consuming project
|
|
145
|
+
npx yalc update @metrifox/react-sdk
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Clean up
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx yalc remove @metrifox/react-sdk
|
|
152
|
+
pnpm install
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Support
|
|
158
|
+
|
|
159
|
+
📘 **Full Documentation:**
|
|
160
|
+
For detailed guides, API references, and live examples, visit [docs.metrifox.com](https://docs.metrifox.com).
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 📄 License
|
|
165
|
+
|
|
166
|
+
MIT © [MetriFox](https://metrifox.com)
|