prividium 0.1.7 → 0.1.8

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 CHANGED
@@ -54,7 +54,7 @@ const prividium = createPrividiumChain({
54
54
  chain: prividiumChain,
55
55
  rpcUrl: 'https://rpc.prividium.io',
56
56
  authBaseUrl: 'https://auth.prividium.io',
57
- permissionsApiBaseUrl: 'https://permissions.prividium.io/api',
57
+ prividiumApiBaseUrl: 'https://permissions.prividium.io/api',
58
58
  redirectUrl: window.location.origin + '/auth/callback',
59
59
  onAuthExpiry: () => {
60
60
  console.log('Authentication expired - please reconnect');
@@ -231,7 +231,7 @@ const prividium = createPrividiumChain({
231
231
  chain: prividiumChain,
232
232
  rpcUrl: 'https://rpc.prividium.io',
233
233
  authBaseUrl: 'https://auth.prividium.io',
234
- permissionsApiBaseUrl: 'https://permissions.prividium.io/api',
234
+ prividiumApiBaseUrl: 'https://permissions.prividium.io/api',
235
235
  redirectUrl: window.location.origin + '/auth/callback',
236
236
  onAuthExpiry: () => {
237
237
  console.log('Authentication expired');
@@ -263,9 +263,8 @@ Creates a new Prividium™ SDK instance.
263
263
  interface PrividiumConfig {
264
264
  clientId: string; // OAuth client ID
265
265
  chain: Chain; // Viem chain configuration (without rpcUrls)
266
- rpcUrl: string; // Private RPC endpoint URL
267
266
  authBaseUrl: string; // Authorization service base URL
268
- permissionsApiBaseUrl: string; // Permissions API service base URL
267
+ prividiumApiBaseUrl: string; // Permissions API service base URL
269
268
  redirectUrl: string; // OAuth redirect URL
270
269
  storage?: Storage; // Custom storage implementation (optional)
271
270
  onAuthExpiry?: () => void; // Called when authentication expires (optional)
@@ -397,7 +396,7 @@ const testnetPrividium = createPrividiumChain({
397
396
  chain: testnetChain,
398
397
  rpcUrl: 'https://testnet-rpc.prividium.io',
399
398
  authBaseUrl: 'https://testnet-auth.prividium.io',
400
- permissionsApiBaseUrl: 'https://testnet-permissions.prividium.io/api',
399
+ prividiumApiBaseUrl: 'https://testnet-permissions.prividium.io/api',
401
400
  redirectUrl: window.location.origin + '/auth/callback'
402
401
  });
403
402
 
@@ -406,7 +405,7 @@ const mainnetPrividium = createPrividiumChain({
406
405
  chain: mainnetChain,
407
406
  rpcUrl: 'https://mainnet-rpc.prividium.io',
408
407
  authBaseUrl: 'https://mainnet-auth.prividium.io',
409
- permissionsApiBaseUrl: 'https://mainnet-permissions.prividium.io/api',
408
+ prividiumApiBaseUrl: 'https://mainnet-permissions.prividium.io/api',
410
409
  redirectUrl: window.location.origin + '/auth/callback'
411
410
  });
412
411
  ```
@@ -3,7 +3,16 @@ import { mainnet } from 'viem/chains';
3
3
  import { LocalStorage, TokenManager } from './storage.js';
4
4
  import { PopupAuth } from './popup-auth.js';
5
5
  import { hasPrividiumUnauthorizedError } from './error-utils.js';
6
+ function rpcUrl(apiUrl) {
7
+ return new URL('/rpc', apiUrl).toString();
8
+ }
9
+ function walletRpcUrl(apiUrl, token) {
10
+ return new URL(`/rpc/wallet/${token}`, apiUrl).toString();
11
+ }
6
12
  export function createPrividiumChain(config) {
13
+ if (config.permissionsApiBaseUrl !== undefined) {
14
+ throw new Error('"permissionsApiBaseUrl" was deprecated. Please use "prividiumApiBaseUrl" instead.');
15
+ }
7
16
  const storage = config.storage || new LocalStorage();
8
17
  const tokenManager = new TokenManager(storage, config.chain.id);
9
18
  const popupAuth = new PopupAuth({
@@ -23,7 +32,7 @@ export function createPrividiumChain(config) {
23
32
  return null;
24
33
  };
25
34
  // Create transport with auth integration using viem callbacks
26
- const transport = http(config.rpcUrl, {
35
+ const transport = http(rpcUrl(config.prividiumApiBaseUrl), {
27
36
  batch: false,
28
37
  fetchOptions: {
29
38
  headers: getAuthHeaders() || {}
@@ -51,7 +60,7 @@ export function createPrividiumChain(config) {
51
60
  ...config.chain.contracts,
52
61
  multicall3: undefined // Prividium™ doesn't support multicall yet
53
62
  },
54
- rpcUrls: { default: { http: [config.rpcUrl] } },
63
+ rpcUrls: { default: { http: [rpcUrl(config.prividiumApiBaseUrl)] } },
55
64
  blockExplorers: config.chain.blockExplorers
56
65
  },
57
66
  transport,
@@ -70,7 +79,7 @@ export function createPrividiumChain(config) {
70
79
  if (!headers) {
71
80
  throw new Error('Authentication required. Please call authorize() first.');
72
81
  }
73
- const response = await fetch(`${config.permissionsApiBaseUrl}/api/profiles/me`, {
82
+ const response = await fetch(`${config.prividiumApiBaseUrl}/api/profiles/me`, {
74
83
  method: 'GET',
75
84
  headers: {
76
85
  'Content-Type': 'application/json',
@@ -100,7 +109,7 @@ export function createPrividiumChain(config) {
100
109
  if (!headers) {
101
110
  throw new Error('Authentication required. Please call authorize() first.');
102
111
  }
103
- const response = await fetch(`${config.permissionsApiBaseUrl}/api/wallet/personal-rpc-token`, {
112
+ const response = await fetch(`${config.prividiumApiBaseUrl}/api/wallet/personal-rpc-token`, {
104
113
  method: 'GET',
105
114
  headers: {
106
115
  'Content-Type': 'application/json',
@@ -120,16 +129,14 @@ export function createPrividiumChain(config) {
120
129
  },
121
130
  async getWalletRpcUrl() {
122
131
  const walletToken = await this.getWalletToken();
123
- // Extract base URL without /api path
124
- const baseUrl = config.rpcUrl.replace(/\/rpc.*$/, '');
125
- return `${baseUrl}/wallet/${walletToken}`;
132
+ return walletRpcUrl(config.prividiumApiBaseUrl, walletToken);
126
133
  },
127
134
  async invalidateWalletToken() {
128
135
  const headers = getAuthHeaders();
129
136
  if (!headers) {
130
137
  throw new Error('Authentication required. Please call authorize() first.');
131
138
  }
132
- const response = await fetch(`${config.permissionsApiBaseUrl}/api/wallet/invalidate`, {
139
+ const response = await fetch(`${config.prividiumApiBaseUrl}/api/wallet/invalidate`, {
133
140
  method: 'POST',
134
141
  headers: {
135
142
  'Content-Type': 'application/json',
@@ -147,7 +154,7 @@ export function createPrividiumChain(config) {
147
154
  if (!headers) {
148
155
  throw new Error('Authentication required. Please call authorize() first.');
149
156
  }
150
- const response = await fetch(`${config.permissionsApiBaseUrl}/api/wallet/transaction-authorization`, {
157
+ const response = await fetch(`${config.prividiumApiBaseUrl}/api/wallet/transaction-authorization`, {
151
158
  method: 'POST',
152
159
  headers: {
153
160
  'Content-Type': 'application/json',
@@ -8,10 +8,13 @@ export interface Storage {
8
8
  export interface PrividiumConfig {
9
9
  clientId: string;
10
10
  chain: Omit<Chain, 'rpcUrls'>;
11
- rpcUrl: string;
12
11
  authBaseUrl: string;
13
12
  redirectUrl: string;
14
- permissionsApiBaseUrl: string;
13
+ /**
14
+ * @deprecated use the `prividiumApiBaseUrl` field instead
15
+ */
16
+ permissionsApiBaseUrl?: string;
17
+ prividiumApiBaseUrl: string;
15
18
  storage?: Storage;
16
19
  onAuthExpiry?: () => void;
17
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prividium",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "bin": {
5
5
  "prividium": "./bin/cli.js"
6
6
  },
@@ -48,6 +48,7 @@
48
48
  "@repo/eslint-config": "workspace:*",
49
49
  "@types/node": "^22.8.6",
50
50
  "@types/yargs": "^17.0.34",
51
+ "@vitest/coverage-v8": "3.2.4",
51
52
  "eslint": "^8",
52
53
  "jsdom": "^25.0.0",
53
54
  "tsx": "^4.20.6",