@streamoid/settings 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 +99 -0
- package/dist/index.d.mts +691 -0
- package/dist/index.d.ts +691 -0
- package/dist/index.js +7904 -0
- package/dist/index.mjs +7942 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @streamoid/settings
|
|
2
|
+
|
|
3
|
+
Shared Settings module (Account, Workspace, Team, Billing, API Keys, Referral).
|
|
4
|
+
The host application provides auth, workspace, API, navigation, toast, and
|
|
5
|
+
image-upload implementations through a single **adapter** object — the package
|
|
6
|
+
contains no host-specific code.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @streamoid/settings @streamoid/ui @streamoid/icons
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`react`, `react-dom`, `@streamoid/ui`, and `@streamoid/icons` are peer deps.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { SettingsContent, type SettingsAdapters } from "@streamoid/settings";
|
|
20
|
+
|
|
21
|
+
function MySettingsPage() {
|
|
22
|
+
const adapters: SettingsAdapters = {
|
|
23
|
+
auth: {
|
|
24
|
+
user: currentUser,
|
|
25
|
+
refreshProfile: async () => { /* ... */ },
|
|
26
|
+
updateProfile: async (patch) => { /* PATCH /profile */ },
|
|
27
|
+
clearAuth: () => { /* clear local auth state */ },
|
|
28
|
+
logout: async () => { /* POST /logout */ },
|
|
29
|
+
},
|
|
30
|
+
workspace: {
|
|
31
|
+
current: { id: currentWorkspaceId, name, role },
|
|
32
|
+
list: async () => fetchWorkspaceList(),
|
|
33
|
+
create: async ({ name, imageUrl }) => { /* POST /workspace */ },
|
|
34
|
+
update: async (id, patch) => { /* PATCH /workspace/:id */ },
|
|
35
|
+
switch: async (id) => { /* set active workspace */ },
|
|
36
|
+
leave: async (id) => { /* DELETE /workspace/:id/leave */ },
|
|
37
|
+
delete: async (id) => { /* DELETE /workspace/:id */ },
|
|
38
|
+
},
|
|
39
|
+
api: {
|
|
40
|
+
fetchPlans: () => fetch("/billing/plans").then(r => r.json()),
|
|
41
|
+
fetchCurrentPlan: () => fetch("/billing/subscription").then(r => r.json()),
|
|
42
|
+
fetchCreditsUsage: async () => ({ used: 120, total: 500 }),
|
|
43
|
+
fetchInvoices: () => fetch("/billing/invoices").then(r => r.json()),
|
|
44
|
+
fetchUsageLogs: () => fetch("/billing/usage").then(r => r.json()),
|
|
45
|
+
downloadInvoice: (id) => fetch(`/billing/invoices/${id}`).then(r => r.json()),
|
|
46
|
+
exportAllInvoices: () => fetch(`/billing/invoices/export`).then(r => r.json()),
|
|
47
|
+
buyCredits: ({ quantity }) => fetch("/billing/credits", { method: "POST", body: JSON.stringify({ quantity }) }),
|
|
48
|
+
upgradePlan: (planId) => fetch(`/billing/upgrade/${planId}`, { method: "POST" }),
|
|
49
|
+
fetchMembers: () => fetch("/team/members").then(r => r.json()),
|
|
50
|
+
fetchPendingInvites: () => fetch("/team/invites").then(r => r.json()),
|
|
51
|
+
inviteMember: ({ email, role }) => fetch("/team/invites", { method: "POST", body: JSON.stringify({ email, role }) }),
|
|
52
|
+
updateMemberRole: (id, role) => fetch(`/team/members/${id}`, { method: "PATCH", body: JSON.stringify({ role }) }),
|
|
53
|
+
removeMember: (id) => fetch(`/team/members/${id}`, { method: "DELETE" }).then(() => undefined),
|
|
54
|
+
cancelInvite: (id) => fetch(`/team/invites/${id}`, { method: "DELETE" }).then(() => undefined),
|
|
55
|
+
resendInvite: (id) => fetch(`/team/invites/${id}/resend`, { method: "POST" }).then(() => undefined),
|
|
56
|
+
fetchTokens: () => fetch("/tokens").then(r => r.json()),
|
|
57
|
+
createToken: ({ name, scopes, expiresAt }) => fetch("/tokens", { method: "POST", body: JSON.stringify({ name, scopes, expiresAt }) }).then(r => r.json()),
|
|
58
|
+
revokeToken: (id) => fetch(`/tokens/${id}`, { method: "DELETE" }).then(() => undefined),
|
|
59
|
+
},
|
|
60
|
+
navigation: {
|
|
61
|
+
navigateToTab: (tab) => router.push(`/settings/${TAB_TO_URL[tab]}`),
|
|
62
|
+
openExternal: (url) => window.open(url, "_blank", "noopener"),
|
|
63
|
+
},
|
|
64
|
+
toast: {
|
|
65
|
+
success: (msg) => toast.success(msg),
|
|
66
|
+
error: (msg) => toast.error(msg),
|
|
67
|
+
info: (msg) => toast(msg),
|
|
68
|
+
},
|
|
69
|
+
imageUpload: {
|
|
70
|
+
upload: (file) => uploadToR2(file),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<SettingsContent
|
|
76
|
+
activeTab={resolveSettingsTabFromPath(location.pathname)}
|
|
77
|
+
adapters={adapters}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Adapter surface
|
|
84
|
+
|
|
85
|
+
| Adapter | Purpose |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `auth` | Current user + profile mutations + logout |
|
|
88
|
+
| `workspace` | Current workspace + workspace CRUD + switch |
|
|
89
|
+
| `api` | Billing, team management, and API token endpoints |
|
|
90
|
+
| `navigation` | Imperative navigation between tabs and to external URLs |
|
|
91
|
+
| `toast` | User-facing success / error / info notifications |
|
|
92
|
+
| `imageUpload` | Single `upload(file)` for avatar / workspace image uploads |
|
|
93
|
+
|
|
94
|
+
See [`src/adapters.ts`](src/adapters.ts) for full type definitions.
|
|
95
|
+
|
|
96
|
+
## Status
|
|
97
|
+
|
|
98
|
+
- **0.1.0** — Adapter surface and package scaffold. Tab content lands in
|
|
99
|
+
subsequent releases as files migrate from `cxo-dashboard` into the package.
|