spaps-sdk 1.1.0 → 1.1.2
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 +62 -14
- package/dist/index.js +3 -0
- package/dist/index.mjs +9 -0
- package/package.json +22 -9
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# @spaps/sdk
|
|
2
2
|
|
|
3
|
+
<a href="https://www.npmjs.com/package/spaps-sdk"><img alt="npm" src="https://img.shields.io/npm/v/spaps-sdk.svg"></a>
|
|
4
|
+
<img alt="node" src="https://img.shields.io/badge/node-%3E%3D14-brightgreen">
|
|
5
|
+
<img alt="types" src="https://img.shields.io/badge/types-TypeScript-blue">
|
|
6
|
+
|
|
3
7
|
> Sweet Potato Authentication & Payment Service SDK
|
|
4
8
|
|
|
5
9
|
Zero-config client for SPAPS authentication, payments, and permission checking. Works automatically with local development mode.
|
|
@@ -71,17 +75,29 @@ See [PERMISSIONS.md](./PERMISSIONS.md) for React examples and complete documenta
|
|
|
71
75
|
## Installation
|
|
72
76
|
|
|
73
77
|
```bash
|
|
74
|
-
npm install
|
|
78
|
+
npm install spaps-sdk
|
|
79
|
+
# or
|
|
80
|
+
yarn add spaps-sdk
|
|
75
81
|
# or
|
|
76
|
-
|
|
82
|
+
pnpm add spaps-sdk
|
|
77
83
|
```
|
|
78
84
|
|
|
85
|
+
### Compatibility
|
|
86
|
+
|
|
87
|
+
- ✅ **Node.js**: Fully supported (v14+) with automatic fetch polyfill
|
|
88
|
+
- ✅ **Browser**: Works in all modern browsers
|
|
89
|
+
- ✅ **TypeScript**: Full type definitions included
|
|
90
|
+
- ✅ **Next.js**: Server and client components supported
|
|
91
|
+
- ✅ **React Native**: Compatible with proper setup
|
|
92
|
+
|
|
93
|
+
The SDK automatically includes a `cross-fetch` polyfill for Node.js environments that don't have native fetch support.
|
|
94
|
+
|
|
79
95
|
## Quick Start
|
|
80
96
|
|
|
81
97
|
```javascript
|
|
82
|
-
import { SPAPSClient } from '
|
|
98
|
+
import { SPAPSClient } from 'spaps-sdk';
|
|
83
99
|
// or
|
|
84
|
-
const { SPAPSClient } = require('
|
|
100
|
+
const { SPAPSClient } = require('spaps-sdk');
|
|
85
101
|
|
|
86
102
|
// Auto-detects local mode - no API key needed for localhost!
|
|
87
103
|
const spaps = new SPAPSClient({
|
|
@@ -99,6 +115,38 @@ if (spaps.isAuthenticated()) {
|
|
|
99
115
|
}
|
|
100
116
|
```
|
|
101
117
|
|
|
118
|
+
## Local Mode Explained
|
|
119
|
+
|
|
120
|
+
- If `apiUrl` is omitted or points to `localhost`/`127.0.0.1`, the SDK runs in local mode.
|
|
121
|
+
- Local mode integrates seamlessly with the `spaps` CLI (`npx spaps local`), defaulting to `http://localhost:3300`.
|
|
122
|
+
- No API key is required in local mode; tokens and data are managed locally for development.
|
|
123
|
+
|
|
124
|
+
You can check the mode at runtime:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
spaps.isLocalMode(); // true | false
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Environment Variables
|
|
131
|
+
|
|
132
|
+
The SDK can read configuration from environment variables (useful in Next.js and Node):
|
|
133
|
+
|
|
134
|
+
- `SPAPS_API_URL` or `NEXT_PUBLIC_SPAPS_API_URL` — API base URL
|
|
135
|
+
- `SPAPS_API_KEY` — API key for production use
|
|
136
|
+
|
|
137
|
+
Example (Node):
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
export SPAPS_API_URL=https://api.sweetpotato.dev
|
|
141
|
+
export SPAPS_API_KEY=spaps_xxx
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Example (Next.js):
|
|
145
|
+
|
|
146
|
+
```env
|
|
147
|
+
NEXT_PUBLIC_SPAPS_API_URL=https://api.sweetpotato.dev
|
|
148
|
+
```
|
|
149
|
+
|
|
102
150
|
## Features
|
|
103
151
|
|
|
104
152
|
### 🚀 Zero Configuration
|
|
@@ -149,7 +197,7 @@ await spaps.recordUsage('api-call', 1);
|
|
|
149
197
|
### Production Mode
|
|
150
198
|
```javascript
|
|
151
199
|
const spaps = new SPAPSClient({
|
|
152
|
-
apiUrl: 'https://api.sweetpotato.
|
|
200
|
+
apiUrl: 'https://api.sweetpotato.dev',
|
|
153
201
|
apiKey: 'spaps_your_api_key_here',
|
|
154
202
|
timeout: 10000 // Optional timeout in ms
|
|
155
203
|
});
|
|
@@ -164,11 +212,11 @@ const spaps = new SPAPSClient();
|
|
|
164
212
|
### Environment Variables
|
|
165
213
|
```bash
|
|
166
214
|
# .env
|
|
167
|
-
SPAPS_API_URL=https://api.sweetpotato.
|
|
215
|
+
SPAPS_API_URL=https://api.sweetpotato.dev
|
|
168
216
|
SPAPS_API_KEY=spaps_your_api_key_here
|
|
169
217
|
|
|
170
218
|
# Next.js
|
|
171
|
-
NEXT_PUBLIC_SPAPS_API_URL=https://api.sweetpotato.
|
|
219
|
+
NEXT_PUBLIC_SPAPS_API_URL=https://api.sweetpotato.dev
|
|
172
220
|
```
|
|
173
221
|
|
|
174
222
|
## Helper Methods
|
|
@@ -195,16 +243,16 @@ await spaps.health()
|
|
|
195
243
|
All these work:
|
|
196
244
|
```javascript
|
|
197
245
|
// ES6 Import
|
|
198
|
-
import { SPAPSClient } from '
|
|
199
|
-
import SPAPSClient from '
|
|
246
|
+
import { SPAPSClient } from 'spaps-sdk';
|
|
247
|
+
import SPAPSClient from 'spaps-sdk';
|
|
200
248
|
|
|
201
249
|
// CommonJS
|
|
202
|
-
const { SPAPSClient } = require('
|
|
203
|
-
const SPAPSClient = require('
|
|
250
|
+
const { SPAPSClient } = require('spaps-sdk');
|
|
251
|
+
const SPAPSClient = require('spaps-sdk');
|
|
204
252
|
|
|
205
253
|
// Alternative names
|
|
206
|
-
import { SPAPS } from '
|
|
207
|
-
import { SweetPotatoSDK } from '
|
|
254
|
+
import { SPAPS } from 'spaps-sdk';
|
|
255
|
+
import { SweetPotatoSDK } from 'spaps-sdk';
|
|
208
256
|
```
|
|
209
257
|
|
|
210
258
|
## Admin API Methods
|
|
@@ -296,4 +344,4 @@ try {
|
|
|
296
344
|
|
|
297
345
|
## License
|
|
298
346
|
|
|
299
|
-
MIT
|
|
347
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -212,6 +212,9 @@ __export(index_exports, {
|
|
|
212
212
|
module.exports = __toCommonJS(index_exports);
|
|
213
213
|
var import_axios = __toESM(require("axios"));
|
|
214
214
|
init_permissions();
|
|
215
|
+
if (typeof globalThis.fetch === "undefined") {
|
|
216
|
+
require("cross-fetch/polyfill");
|
|
217
|
+
}
|
|
215
218
|
var SPAPSClient = class {
|
|
216
219
|
client;
|
|
217
220
|
apiKey;
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,12 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
7
|
+
}) : x)(function(x) {
|
|
8
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
+
});
|
|
5
11
|
var __esm = (fn, res) => function __init() {
|
|
6
12
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
13
|
};
|
|
@@ -183,6 +189,9 @@ var init_permissions = __esm({
|
|
|
183
189
|
// src/index.ts
|
|
184
190
|
init_permissions();
|
|
185
191
|
import axios from "axios";
|
|
192
|
+
if (typeof globalThis.fetch === "undefined") {
|
|
193
|
+
__require("cross-fetch/polyfill");
|
|
194
|
+
}
|
|
186
195
|
var SPAPSClient = class {
|
|
187
196
|
client;
|
|
188
197
|
apiKey;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spaps-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Sweet Potato Authentication & Payment Service SDK - Zero-config client with built-in permission checking and role-based access control",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
21
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
20
|
+
"build": "tsup --tsconfig tsconfig.json src/index.ts --format cjs,esm --dts --clean",
|
|
21
|
+
"dev": "tsup --tsconfig tsconfig.json src/index.ts --format cjs,esm --dts --watch",
|
|
22
22
|
"test": "echo \"No tests yet\"",
|
|
23
|
-
"
|
|
23
|
+
"smoke-test": "npm run build && node smoke-test.js",
|
|
24
|
+
"prepublishOnly": "npm run build && npm run smoke-test"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
|
26
27
|
"authentication",
|
|
@@ -36,11 +37,16 @@
|
|
|
36
37
|
"license": "MIT",
|
|
37
38
|
"repository": {
|
|
38
39
|
"type": "git",
|
|
39
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/buildooor/sweet-potato",
|
|
41
|
+
"directory": "packages/sdk"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/buildooor/sweet-potato/tree/main/packages/sdk",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/buildooor/sweet-potato/issues"
|
|
40
46
|
},
|
|
41
|
-
"homepage": "https://sweetpotato.dev",
|
|
42
47
|
"dependencies": {
|
|
43
|
-
"axios": "^1.6.0"
|
|
48
|
+
"axios": "^1.6.0",
|
|
49
|
+
"cross-fetch": "^4.0.0"
|
|
44
50
|
},
|
|
45
51
|
"devDependencies": {
|
|
46
52
|
"@types/node": "^20.10.0",
|
|
@@ -58,5 +64,12 @@
|
|
|
58
64
|
"files": [
|
|
59
65
|
"dist",
|
|
60
66
|
"README.md"
|
|
61
|
-
]
|
|
62
|
-
|
|
67
|
+
],
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public",
|
|
70
|
+
"registry": "https://registry.npmjs.org/"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">=14.0.0"
|
|
74
|
+
}
|
|
75
|
+
}
|