spaps 0.2.2 → 0.2.3
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/client.js +46 -1
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -5,7 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
try {
|
|
7
7
|
// Try to load spaps-sdk if it's installed
|
|
8
|
-
|
|
8
|
+
const sdk = require('spaps-sdk');
|
|
9
|
+
|
|
10
|
+
// Support both default export and named export
|
|
11
|
+
const SPAPSClient = sdk.SPAPSClient || sdk.default || sdk;
|
|
12
|
+
|
|
13
|
+
module.exports = SPAPSClient;
|
|
14
|
+
module.exports.SPAPSClient = SPAPSClient;
|
|
15
|
+
module.exports.default = SPAPSClient;
|
|
16
|
+
module.exports.SPAPS = SPAPSClient;
|
|
17
|
+
module.exports.SweetPotatoSDK = SPAPSClient;
|
|
9
18
|
} catch (error) {
|
|
10
19
|
// Fallback to a simple client implementation for local development
|
|
11
20
|
const axios = require('axios');
|
|
@@ -94,9 +103,45 @@ try {
|
|
|
94
103
|
isLocalMode() {
|
|
95
104
|
return this.isLocalMode;
|
|
96
105
|
}
|
|
106
|
+
|
|
107
|
+
async health() {
|
|
108
|
+
return this.client.get('/health');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async logout() {
|
|
112
|
+
await this.client.post('/api/auth/logout', {}, {
|
|
113
|
+
headers: { Authorization: `Bearer ${this.accessToken}` }
|
|
114
|
+
});
|
|
115
|
+
this.accessToken = null;
|
|
116
|
+
this.refreshToken = null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async refresh(refreshToken) {
|
|
120
|
+
const response = await this.client.post('/api/auth/refresh', {
|
|
121
|
+
refresh_token: refreshToken || this.refreshToken
|
|
122
|
+
});
|
|
123
|
+
this.accessToken = response.data.access_token;
|
|
124
|
+
this.refreshToken = response.data.refresh_token;
|
|
125
|
+
return response;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async recordUsage(feature, amount) {
|
|
129
|
+
return this.client.post('/api/usage/record',
|
|
130
|
+
{ feature, amount },
|
|
131
|
+
{ headers: { Authorization: `Bearer ${this.accessToken}` } }
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async cancelSubscription() {
|
|
136
|
+
return this.client.delete('/api/stripe/subscription', {
|
|
137
|
+
headers: { Authorization: `Bearer ${this.accessToken}` }
|
|
138
|
+
});
|
|
139
|
+
}
|
|
97
140
|
}
|
|
98
141
|
|
|
99
142
|
module.exports = SPAPSClient;
|
|
100
143
|
module.exports.SPAPSClient = SPAPSClient;
|
|
101
144
|
module.exports.default = SPAPSClient;
|
|
145
|
+
module.exports.SPAPS = SPAPSClient;
|
|
146
|
+
module.exports.SweetPotatoSDK = SPAPSClient;
|
|
102
147
|
}
|