@meet-sudo/sdk 0.1.6 → 0.1.7
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 +118 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,28 @@ meetsudo.identify('user-123', {
|
|
|
57
57
|
</script>
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
### Server SDK (Node.js)
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import { MeetSudoServer } from '@meet-sudo/sdk';
|
|
64
|
+
|
|
65
|
+
const ms = new MeetSudoServer({
|
|
66
|
+
apiKey: process.env.MEETSUDO_API_KEY, // for identify/track/customer APIs
|
|
67
|
+
secretKey: process.env.MEETSUDO_SECRET_KEY // for logs APIs, must start with sk_
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await ms.identify('user-123', {
|
|
71
|
+
email: 'user@example.com',
|
|
72
|
+
name: 'John Doe',
|
|
73
|
+
plan: 'pro'
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await ms.track('user-123', 'invoice_paid', {
|
|
77
|
+
amount: 120,
|
|
78
|
+
currency: 'USD'
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
60
82
|
## API Reference
|
|
61
83
|
|
|
62
84
|
### `init(config)`
|
|
@@ -141,6 +163,96 @@ meetsudo.changelog('open');
|
|
|
141
163
|
meetsudo.changelog('close');
|
|
142
164
|
```
|
|
143
165
|
|
|
166
|
+
## Server API Reference
|
|
167
|
+
|
|
168
|
+
### `new MeetSudoServer(config)`
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
interface MeetSudoServerConfig {
|
|
172
|
+
apiKey?: string;
|
|
173
|
+
secretKey?: string;
|
|
174
|
+
apiUrl?: string;
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
- Provide `apiKey` for customer/event APIs.
|
|
179
|
+
- Provide `secretKey` for log ingest/query APIs.
|
|
180
|
+
|
|
181
|
+
### `identify(userId, traits?)`
|
|
182
|
+
|
|
183
|
+
Create or update a user from backend code.
|
|
184
|
+
|
|
185
|
+
### `track(userId, eventName, properties?)`
|
|
186
|
+
|
|
187
|
+
Track one backend event for a user.
|
|
188
|
+
|
|
189
|
+
### `trackBatch(userId, events[])`
|
|
190
|
+
|
|
191
|
+
Track multiple backend events in one call.
|
|
192
|
+
|
|
193
|
+
### `getCustomer(customerId)`
|
|
194
|
+
|
|
195
|
+
Fetch customer details.
|
|
196
|
+
|
|
197
|
+
### `getCustomerTimeline(customerId, limit?)`
|
|
198
|
+
|
|
199
|
+
Fetch customer timeline (events, messages, sessions).
|
|
200
|
+
|
|
201
|
+
## Logging API (Server)
|
|
202
|
+
|
|
203
|
+
### `log(entry)`
|
|
204
|
+
|
|
205
|
+
Ingest a single backend log line.
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
await ms.log({
|
|
209
|
+
level: 'error',
|
|
210
|
+
source: 'backend',
|
|
211
|
+
service: 'api',
|
|
212
|
+
event: 'checkout_failed',
|
|
213
|
+
message: 'Stripe returned 402',
|
|
214
|
+
user_id: 'user-123',
|
|
215
|
+
props: { duration_ms: 742, amount: 99 }
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### `logBatch(entries[])`
|
|
220
|
+
|
|
221
|
+
Ingest multiple logs in one request.
|
|
222
|
+
|
|
223
|
+
```javascript
|
|
224
|
+
await ms.logBatch([
|
|
225
|
+
{ level: 'info', source: 'backend', service: 'api', message: 'request started' },
|
|
226
|
+
{ level: 'warn', source: 'backend', service: 'api', message: 'retrying payment' }
|
|
227
|
+
]);
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### `queryLogs({ query, from, to, limit })`
|
|
231
|
+
|
|
232
|
+
Run Splunk-like queries.
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
const r1 = await ms.queryLogs({ query: 'count' });
|
|
236
|
+
const r2 = await ms.queryLogs({ query: 'stats count by service' });
|
|
237
|
+
const r3 = await ms.queryLogs({ query: 'stats p95(prop.duration_ms) by service' });
|
|
238
|
+
const r4 = await ms.queryLogs({ query: 'timechart span=1h' });
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### `assistLogQuery(prompt)`
|
|
242
|
+
|
|
243
|
+
Generate a valid logs query from English text.
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
const assist = await ms.assistLogQuery(
|
|
247
|
+
'show p99 checkout latency by service in last 24 hours'
|
|
248
|
+
);
|
|
249
|
+
// assist.query => stats p99(prop.duration_ms) by service
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### `getLogSchemaHints()`
|
|
253
|
+
|
|
254
|
+
Get observed workspace fields (services, events, prop keys, levels, sources).
|
|
255
|
+
|
|
144
256
|
### Helper Methods
|
|
145
257
|
|
|
146
258
|
```javascript
|
|
@@ -193,7 +305,12 @@ import type {
|
|
|
193
305
|
EventProperties,
|
|
194
306
|
PageProperties,
|
|
195
307
|
ChatAction,
|
|
196
|
-
ChangelogAction
|
|
308
|
+
ChangelogAction,
|
|
309
|
+
MeetSudoServerConfig,
|
|
310
|
+
LogEntry,
|
|
311
|
+
LogQueryRequest,
|
|
312
|
+
LogAssistResponse,
|
|
313
|
+
LogSchemaHintsResponse
|
|
197
314
|
} from '@meet-sudo/sdk';
|
|
198
315
|
```
|
|
199
316
|
|