@explorins/pers-sdk 2.0.7 → 2.0.10

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
@@ -107,84 +107,106 @@ npm install @explorins/pers-shared ethers@^6.15.0
107
107
 
108
108
  ### Direct Dependencies
109
109
 
110
- | Package | Purpose |
111
- |---------|---------|
112
- | `@explorins/web3-ts` | Internal Web3 chain utilities |
110
+ The SDK has **zero** direct runtime dependencies. All peer dependencies are optional:
111
+
112
+ | Package | Type | Purpose |
113
+ |---------|------|---------|
114
+ | `@explorins/pers-shared` | Peer (required) | Shared types, interfaces, and DTOs |
115
+ | `@explorins/web3-ts` | Peer (optional) | Web3/blockchain utilities (only needed for `sdk.web3.*` methods) |
116
+ | `ethers` | Peer (optional) | Blockchain operations (only needed for `sdk.web3.*` methods) |
113
117
 
114
118
  ---
115
119
 
116
120
  ## Installation
117
121
 
118
122
  ```bash
119
- # Core SDK
123
+ # Core SDK (lightweight - ~200KB)
120
124
  npm install @explorins/pers-sdk
121
125
 
122
- # Required peer dependencies
123
- npm install @explorins/pers-shared ethers@^6.15.0
126
+ # Required peer dependency
127
+ npm install @explorins/pers-shared
128
+
129
+ # Optional: Only if using Web3/blockchain features (sdk.web3.*)
130
+ npm install @explorins/web3-ts ethers@^6.15.0
124
131
 
125
132
  # Optional: For Angular applications only
126
133
  npm install rxjs
127
134
  ```
128
135
 
136
+ **Package Size:**
137
+ - Installed: ~1.9 MB (node_modules - both ESM/CJS + types + maps)
138
+ - Your bundle: ~450 KB (bundler includes only ESM or CJS, not both)
139
+ - With Web3: +1.5 MB (optional peer dependencies)
140
+ - For smaller bundles: Import from `@explorins/pers-sdk/campaign` etc.
141
+
129
142
  ---
130
143
 
131
144
  ## Quick Start
132
145
 
133
- ### Minimum Viable Example
146
+ ### Browser / React / Vue
134
147
 
135
148
  ```typescript
136
- import { PersSDK } from '@explorins/pers-sdk';
149
+ import { createPersSDK } from '@explorins/pers-sdk';
137
150
  import { BrowserFetchClientAdapter } from '@explorins/pers-sdk/platform-adapters';
138
151
 
139
- // 1. Initialize SDK (required: adapter + project key)
140
- const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
141
- apiProjectKey: 'your-project-key' // Get from PERS dashboard
152
+ // Initialize SDK
153
+ const sdk = createPersSDK(new BrowserFetchClientAdapter(), {
154
+ apiProjectKey: 'your-project-key'
142
155
  });
143
156
 
144
- // 2. Authenticate with external JWT (Firebase, Auth0, Cognito, etc.)
145
- const externalJWT = await yourAuthProvider.getIdToken(); // Your JWT
157
+ // Authenticate with external JWT (Firebase, Auth0, Cognito, etc.)
158
+ const externalJWT = await yourAuthProvider.getIdToken();
146
159
  const authResult = await sdk.auth.loginWithToken(externalJWT, 'user');
147
- console.log('Authenticated user:', authResult.user.id);
148
160
 
149
- // 3. Use SDK managers
161
+ // Use SDK managers
150
162
  const campaigns = await sdk.campaigns.getActiveCampaigns();
151
- const tokens = await sdk.tokens.getTokens();
152
163
  ```
153
164
 
154
- ### Complete Example
165
+ ### Node.js (Convenience Function)
155
166
 
156
167
  ```typescript
157
- import { PersSDK } from '@explorins/pers-sdk';
158
- import { BrowserFetchClientAdapter } from '@explorins/pers-sdk/platform-adapters';
168
+ import { createNodeSDK } from '@explorins/pers-sdk/node';
159
169
 
160
- // Initialize SDK with browser fetch adapter
161
- const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
162
- environment: 'production',
163
- apiProjectKey: 'your-project-key'
170
+ // One-liner setup with static JWT
171
+ const sdk = createNodeSDK({
172
+ jwt: 'your-system-jwt',
173
+ projectKey: 'your-project-key',
174
+ environment: 'production'
164
175
  });
165
176
 
166
- // Authentication - login with external JWT (Firebase, Auth0, etc.)
167
- const authResult = await sdk.auth.loginWithToken(firebaseJWT, 'user');
168
- const user = await sdk.auth.getCurrentUser();
177
+ // Ready to use - no additional auth needed
178
+ const campaigns = await sdk.campaigns.getCampaigns();
179
+ const userClaims = await sdk.campaigns.getCampaignClaims({ userId: 'user-123' });
180
+ ```
169
181
 
170
- // Business operations
171
- const businesses = await sdk.businesses.getActiveBusinesses();
172
- const business = await sdk.businesses.getBusinessById('business-123');
182
+ ### Complete Example (Node.js Server-Side)
173
183
 
174
- // Campaign management
175
- const campaigns = await sdk.campaigns.getActiveCampaigns();
176
- const claim = await sdk.campaigns.claimCampaign({
184
+ ```typescript
185
+ import { createNodeSDK } from '@explorins/pers-sdk/node';
186
+
187
+ // Initialize with static JWT (tenant/business system token)
188
+ const sdk = createNodeSDK({
189
+ jwt: process.env.PERS_JWT_TOKEN,
190
+ projectKey: process.env.PERS_PROJECT_KEY,
191
+ environment: 'production'
192
+ });
193
+
194
+ // Campaign operations (admin/system access)
195
+ const campaigns = await sdk.campaigns.getCampaigns();
196
+ const campaign = await sdk.campaigns.getCampaignById('campaign-123');
197
+
198
+ // Claim campaign for a user (system operation)
199
+ const claim = await sdk.campaigns.claimCampaign({
177
200
  campaignId: 'campaign-123',
178
- businessId: 'business-456'
201
+ userIdentifier: 'external-user-id'
179
202
  });
180
203
 
181
- // Token operations
182
- const tokens = await sdk.tokens.getTokens();
183
- const creditToken = await sdk.tokens.getActiveCreditToken();
184
- const rewardTokens = await sdk.tokens.getRewardTokens();
204
+ // Get user's claim history
205
+ const userId = claim.user?.id;
206
+ const userClaims = await sdk.campaigns.getCampaignClaims({ userId });
185
207
 
186
- // User claims history
187
- const userClaims = await sdk.campaigns.getUserClaims();
208
+ // Business operations
209
+ const businesses = await sdk.businesses.getActiveBusinesses();
188
210
  ```
189
211
 
190
212
  ---
@@ -196,10 +218,10 @@ const userClaims = await sdk.campaigns.getUserClaims();
196
218
  **No additional dependencies required.**
197
219
 
198
220
  ```typescript
199
- import { PersSDK } from '@explorins/pers-sdk';
221
+ import { createPersSDK } from '@explorins/pers-sdk';
200
222
  import { BrowserFetchClientAdapter } from '@explorins/pers-sdk/platform-adapters';
201
223
 
202
- const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
224
+ const sdk = createPersSDK(new BrowserFetchClientAdapter(), {
203
225
  environment: 'production',
204
226
  apiProjectKey: 'your-project-key'
205
227
  });
@@ -256,19 +278,23 @@ export class PersSDKService {
256
278
 
257
279
  ### Node.js
258
280
 
259
- **No additional dependencies required.**
281
+ **No additional dependencies required.** Use the dedicated Node.js entry point:
260
282
 
261
283
  ```typescript
262
- import { PersSDK } from '@explorins/pers-sdk';
263
- import { NodeHttpClientAdapter } from '@explorins/pers-sdk/platform-adapters';
284
+ import { createNodeSDK } from '@explorins/pers-sdk/node';
264
285
 
265
- const sdk = new PersSDK(new NodeHttpClientAdapter(), {
266
- environment: 'production',
267
- apiProjectKey: 'your-project-key'
286
+ // Convenience function for Node.js - auto-configures adapter
287
+ const sdk = createNodeSDK({
288
+ jwt: 'your-jwt-token',
289
+ projectKey: 'your-project-key',
290
+ environment: 'production'
268
291
  });
269
292
 
270
- // Server-side operations
271
- const businesses = await sdk.businesses.getActiveBusinesses();
293
+ // Ready to use
294
+ const campaigns = await sdk.campaigns.getActiveCampaigns();
295
+ const userClaims = await sdk.campaigns.getCampaignClaims({
296
+ userId: 'user-123'
297
+ });
272
298
  ```
273
299
 
274
300
  ### React Native
@@ -853,11 +879,11 @@ const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
853
879
  For better security and performance, use IndexedDB instead of LocalStorage:
854
880
 
855
881
  ```typescript
856
- import { PersSDK } from '@explorins/pers-sdk';
882
+ import { createPersSDK } from '@explorins/pers-sdk';
857
883
  import { IndexedDBTokenStorage } from '@explorins/pers-sdk/core';
858
884
  import { BrowserFetchClientAdapter } from '@explorins/pers-sdk/platform-adapters';
859
885
 
860
- const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
886
+ const sdk = createPersSDK(new BrowserFetchClientAdapter(), {
861
887
  environment: 'production',
862
888
  apiProjectKey: 'your-key',
863
889
  authStorage: new IndexedDBTokenStorage() // Secure, async storage
@@ -952,10 +978,18 @@ const retryable = ErrorUtils.isRetryable(error); // Check if retryable
952
978
 
953
979
  ## Bundle Size
954
980
 
955
- - **Core SDK**: ~85 KB (minified)
956
- - **Tree-shaking**: Fully supported - import only what you need
957
- - **Zero runtime dependencies**: No RxJS, no heavy libraries in core
958
- - **Native APIs**: Uses browser-native `fetch`, `crypto`, `IndexedDB`
981
+ - **Installed to node_modules**: ~1.9 MB unpacked (includes both ESM + CJS builds, TypeScript definitions, source maps)
982
+ - **What your bundler actually includes**:
983
+ - ESM build: ~450 KB (Vite, Rollup, modern Webpack)
984
+ - CJS build: ~470 KB (legacy Node.js/Webpack)
985
+ - Your bundler only includes ONE of these, not both
986
+ - **TypeScript definitions**: ~510 KB (used by IDE/compiler, not bundled into your app)
987
+ - **Source maps**: ~440 KB (used for debugging, typically excluded from production)
988
+ - **With Web3 Features**: +1.5 MB additional when installing optional `@explorins/web3-ts` + `ethers` peer dependencies
989
+ - **Tree-shaking**: The main `PersSDK` class includes all managers. For smaller bundles, import from domain-specific entry points (e.g., `@explorins/pers-sdk/campaign`)
990
+ - **Zero bundled dependencies**: All dependencies are peer dependencies
991
+
992
+ **Bottom line:** Your production bundle gets ~450 KB from this SDK (ESM), not 1.9 MB. The larger size is what's stored in `node_modules`, which includes both module formats, type definitions, and development tools.
959
993
 
960
994
  ---
961
995
 
@@ -1023,16 +1057,17 @@ import type {
1023
1057
  ### Usage Example
1024
1058
 
1025
1059
  ```typescript
1026
- import { PersSDK } from '@explorins/pers-sdk';
1060
+ import { createPersSDK } from '@explorins/pers-sdk';
1027
1061
  import { BrowserFetchClientAdapter } from '@explorins/pers-sdk/platform-adapters';
1028
1062
  import type { CampaignDTO, CampaignClaimRequestDTO } from '@explorins/pers-shared';
1029
1063
 
1030
- const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
1064
+ const sdk = createPersSDK(new BrowserFetchClientAdapter(), {
1031
1065
  apiProjectKey: 'your-key'
1032
1066
  });
1033
1067
 
1034
1068
  // Type-safe campaign operations
1035
- const campaigns: CampaignDTO[] = await sdk.campaigns.getActiveCampaigns();
1069
+ const response = await sdk.campaigns.getActiveCampaigns();
1070
+ const campaigns: CampaignDTO[] = response.data;
1036
1071
 
1037
1072
  const claimRequest: CampaignClaimRequestDTO = {
1038
1073
  campaignId: campaigns[0].id,
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk",
3
- "version": "2.0.7",
3
+ "version": "2.0.10",
4
4
  "description": "Platform-agnostic SDK for PERS (Phygital Experience Rewards System) - Core business logic and API integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -127,9 +127,7 @@
127
127
  "publish-version": "npm run clean && npm run build && npm version patch && npm publish",
128
128
  "publish-with-docs": "npm run clean && npm run build && npm run docs && npm version patch && npm publish"
129
129
  },
130
- "dependencies": {
131
- "@explorins/web3-ts": "^0.3.77"
132
- },
130
+ "dependencies": {},
133
131
  "devDependencies": {
134
132
  "@explorins/pers-shared": "^2.1.72",
135
133
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -148,9 +146,17 @@
148
146
  },
149
147
  "peerDependencies": {
150
148
  "@explorins/pers-shared": "*",
149
+ "@explorins/web3-ts": "^0.3.77",
151
150
  "ethers": "^6.15.0"
152
151
  },
153
- "peerDependenciesMeta": {},
152
+ "peerDependenciesMeta": {
153
+ "@explorins/web3-ts": {
154
+ "optional": true
155
+ },
156
+ "ethers": {
157
+ "optional": true
158
+ }
159
+ },
154
160
  "publishConfig": {
155
161
  "access": "public",
156
162
  "registry": "https://registry.npmjs.org/"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk",
3
- "version": "2.0.7",
3
+ "version": "2.0.10",
4
4
  "description": "Platform-agnostic SDK for PERS (Phygital Experience Rewards System) - Core business logic and API integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -127,9 +127,7 @@
127
127
  "publish-version": "npm run clean && npm run build && npm version patch && npm publish",
128
128
  "publish-with-docs": "npm run clean && npm run build && npm run docs && npm version patch && npm publish"
129
129
  },
130
- "dependencies": {
131
- "@explorins/web3-ts": "^0.3.77"
132
- },
130
+ "dependencies": {},
133
131
  "devDependencies": {
134
132
  "@explorins/pers-shared": "^2.1.72",
135
133
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -148,9 +146,17 @@
148
146
  },
149
147
  "peerDependencies": {
150
148
  "@explorins/pers-shared": "*",
149
+ "@explorins/web3-ts": "^0.3.77",
151
150
  "ethers": "^6.15.0"
152
151
  },
153
- "peerDependenciesMeta": {},
152
+ "peerDependenciesMeta": {
153
+ "@explorins/web3-ts": {
154
+ "optional": true
155
+ },
156
+ "ethers": {
157
+ "optional": true
158
+ }
159
+ },
154
160
  "publishConfig": {
155
161
  "access": "public",
156
162
  "registry": "https://registry.npmjs.org/"