@omen.dog/sdk 1.0.0
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 +147 -0
- package/dist/creation.d.ts +116 -0
- package/dist/index.d.mts +559 -0
- package/dist/index.d.ts +559 -0
- package/dist/index.js +542 -0
- package/dist/index.mjs +510 -0
- package/package.json +44 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var OmenError = class extends Error {
|
|
3
|
+
/** HTTP status code from the API. */
|
|
4
|
+
status;
|
|
5
|
+
/** Machine-readable error code (e.g. "RATE_LIMITED", "NOT_FOUND"). */
|
|
6
|
+
code;
|
|
7
|
+
constructor(message, status, code) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "OmenError";
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var OmenNotFoundError = class extends OmenError {
|
|
15
|
+
constructor(message = "Resource not found") {
|
|
16
|
+
super(message, 404, "NOT_FOUND");
|
|
17
|
+
this.name = "OmenNotFoundError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var OmenAuthError = class extends OmenError {
|
|
21
|
+
constructor(message = "Authentication failed") {
|
|
22
|
+
super(message, 401, "AUTH_FAILED");
|
|
23
|
+
this.name = "OmenAuthError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var OmenValidationError = class extends OmenError {
|
|
27
|
+
/** Field-level validation errors, if available. */
|
|
28
|
+
errors;
|
|
29
|
+
constructor(message, errors) {
|
|
30
|
+
super(message, 422, "VALIDATION_ERROR");
|
|
31
|
+
this.name = "OmenValidationError";
|
|
32
|
+
this.errors = errors;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var OmenRateLimitError = class extends OmenError {
|
|
36
|
+
/** Seconds until the rate limit resets. */
|
|
37
|
+
retryAfter;
|
|
38
|
+
/** Remaining requests in the current window. */
|
|
39
|
+
remaining;
|
|
40
|
+
constructor(message = "Rate limit exceeded", retryAfter, remaining) {
|
|
41
|
+
super(message, 429, "RATE_LIMITED");
|
|
42
|
+
this.name = "OmenRateLimitError";
|
|
43
|
+
this.retryAfter = retryAfter;
|
|
44
|
+
this.remaining = remaining;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/client.ts
|
|
49
|
+
var HttpClient = class {
|
|
50
|
+
baseUrl;
|
|
51
|
+
token;
|
|
52
|
+
constructor(token, baseUrl) {
|
|
53
|
+
this.token = token;
|
|
54
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
55
|
+
}
|
|
56
|
+
async request(path, opts = {}) {
|
|
57
|
+
const url = new URL(path, this.baseUrl);
|
|
58
|
+
if (opts.query) {
|
|
59
|
+
for (const [k, v] of Object.entries(opts.query)) {
|
|
60
|
+
if (v !== void 0) url.searchParams.set(k, String(v));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const headers = {
|
|
64
|
+
"Authorization": `Bearer ${this.token}`,
|
|
65
|
+
"Accept": "application/json",
|
|
66
|
+
...opts.headers
|
|
67
|
+
};
|
|
68
|
+
if (opts.body !== void 0) {
|
|
69
|
+
headers["Content-Type"] = "application/json";
|
|
70
|
+
}
|
|
71
|
+
const res = await fetch(url.toString(), {
|
|
72
|
+
method: opts.method ?? "GET",
|
|
73
|
+
headers,
|
|
74
|
+
body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0
|
|
75
|
+
});
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
await this.handleError(res);
|
|
78
|
+
}
|
|
79
|
+
const text = await res.text();
|
|
80
|
+
return text ? JSON.parse(text) : {};
|
|
81
|
+
}
|
|
82
|
+
async handleError(res) {
|
|
83
|
+
let body = {};
|
|
84
|
+
try {
|
|
85
|
+
body = await res.json();
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
const message = body.error || body.message || res.statusText;
|
|
89
|
+
switch (res.status) {
|
|
90
|
+
case 401:
|
|
91
|
+
case 403:
|
|
92
|
+
throw new OmenAuthError(message);
|
|
93
|
+
case 404:
|
|
94
|
+
throw new OmenNotFoundError(message);
|
|
95
|
+
case 422:
|
|
96
|
+
throw new OmenValidationError(message, body.errors);
|
|
97
|
+
case 429: {
|
|
98
|
+
const retryAfter = res.headers.get("Retry-After");
|
|
99
|
+
const remaining = res.headers.get("X-RateLimit-Remaining");
|
|
100
|
+
throw new OmenRateLimitError(
|
|
101
|
+
message,
|
|
102
|
+
retryAfter ? Number(retryAfter) : void 0,
|
|
103
|
+
remaining ? Number(remaining) : void 0
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
default:
|
|
107
|
+
throw new OmenError(message, res.status);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/namespaces/users.ts
|
|
113
|
+
var UsersNamespace = class {
|
|
114
|
+
constructor(http) {
|
|
115
|
+
this.http = http;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get a user's profile by ID or username.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const profile = await omen.users.get('pistolphoenix');
|
|
123
|
+
* console.log(profile.user.username, profile.stats.creationsCount);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
async get(userId) {
|
|
127
|
+
return this.http.request(`/api/v1/users/${encodeURIComponent(userId)}/profile`);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get a user's friend list with optional filtering and pagination.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const { friends, onlineCount } = await omen.users.friends('pistolphoenix', {
|
|
135
|
+
* status: 'online',
|
|
136
|
+
* limit: 10,
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
async friends(userId, options = {}) {
|
|
141
|
+
return this.http.request(`/api/v1/users/${encodeURIComponent(userId)}/friends`, {
|
|
142
|
+
query: {
|
|
143
|
+
status: options.status,
|
|
144
|
+
sort: options.sort,
|
|
145
|
+
search: options.search,
|
|
146
|
+
cursor: options.cursor,
|
|
147
|
+
limit: options.limit
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/namespaces/storage.ts
|
|
154
|
+
var StorageNamespace = class {
|
|
155
|
+
constructor(http) {
|
|
156
|
+
this.http = http;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the current user's stored data for your app.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* const { data } = await omen.storage.get();
|
|
164
|
+
* console.log(data.highScore);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
async get() {
|
|
168
|
+
return this.http.request("/api/appdata");
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Replace the current user's stored data entirely.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* await omen.storage.set({ highScore: 100, level: 5 });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
async set(data) {
|
|
179
|
+
return this.http.request("/api/appdata", {
|
|
180
|
+
method: "PUT",
|
|
181
|
+
body: { data }
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Shallow-merge fields into the current user's stored data.
|
|
186
|
+
* Existing fields not in the payload are preserved.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* await omen.storage.merge({ highScore: 200 }); // keeps 'level' intact
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
async merge(data) {
|
|
194
|
+
return this.http.request("/api/appdata", {
|
|
195
|
+
method: "PATCH",
|
|
196
|
+
body: { data }
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/namespaces/items.ts
|
|
202
|
+
var ItemsNamespace = class {
|
|
203
|
+
constructor(http, appId) {
|
|
204
|
+
this.http = http;
|
|
205
|
+
this.appId = appId;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Issue a single item to a user.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* const item = await omen.items.issue({
|
|
213
|
+
* userId: 'cmm0tzco8...',
|
|
214
|
+
* name: 'Dragon Slayer Badge',
|
|
215
|
+
* type: 'achievement',
|
|
216
|
+
* rarity: 'legendary',
|
|
217
|
+
* });
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
async issue(options) {
|
|
221
|
+
return this.http.request(`/api/v1/apps/${this.appId}/items/issue`, {
|
|
222
|
+
method: "POST",
|
|
223
|
+
body: options
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Issue multiple items in one request. Maximum 100 items per batch.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const { items, count } = await omen.items.issueBatch([
|
|
232
|
+
* { userId: 'user1', name: 'Gold Medal', type: 'achievement' },
|
|
233
|
+
* { userId: 'user2', name: 'Silver Medal', type: 'achievement' },
|
|
234
|
+
* ]);
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
async issueBatch(items) {
|
|
238
|
+
return this.http.request(`/api/v1/apps/${this.appId}/items/issue-batch`, {
|
|
239
|
+
method: "POST",
|
|
240
|
+
body: { items }
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Revoke an item. Idempotent — re-revoking a revoked item returns 200.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* await omen.items.revoke('item_abc123', 'Violated terms of service');
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
async revoke(itemId, reason) {
|
|
252
|
+
return this.http.request(`/api/v1/apps/${this.appId}/items/${encodeURIComponent(itemId)}/revoke`, {
|
|
253
|
+
method: "POST",
|
|
254
|
+
body: { reason }
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// src/namespaces/collections.ts
|
|
260
|
+
var CollectionsNamespace = class {
|
|
261
|
+
constructor(http, appId) {
|
|
262
|
+
this.http = http;
|
|
263
|
+
this.appId = appId;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Create a new collection.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* const col = await omen.collections.create({
|
|
271
|
+
* name: 'player_stats',
|
|
272
|
+
* schema: { score: 'number', level: 'number', name: 'string' },
|
|
273
|
+
* indexedFields: ['score'],
|
|
274
|
+
* });
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
async create(options) {
|
|
278
|
+
return this.http.request(`/api/v1/apps/${this.appId}/collections`, {
|
|
279
|
+
method: "POST",
|
|
280
|
+
body: options
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
/** List all collections for your app. */
|
|
284
|
+
async list() {
|
|
285
|
+
return this.http.request(`/api/v1/apps/${this.appId}/collections`);
|
|
286
|
+
}
|
|
287
|
+
/** Get a single collection by name. */
|
|
288
|
+
async get(name) {
|
|
289
|
+
return this.http.request(`/api/v1/apps/${this.appId}/collections/${encodeURIComponent(name)}`);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Delete a collection and all its documents. This is irreversible.
|
|
293
|
+
*/
|
|
294
|
+
async delete(name) {
|
|
295
|
+
return this.http.request(`/api/v1/apps/${this.appId}/collections/${encodeURIComponent(name)}`, {
|
|
296
|
+
method: "DELETE"
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
// ── Documents ──────────────────────────────
|
|
300
|
+
/**
|
|
301
|
+
* Insert a single document into a collection.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* const doc = await omen.collections.insert('player_stats', {
|
|
306
|
+
* score: 1500,
|
|
307
|
+
* level: 12,
|
|
308
|
+
* name: 'PistolPhoenix',
|
|
309
|
+
* });
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
async insert(collection, data) {
|
|
313
|
+
return this.http.request(this.docsPath(collection), {
|
|
314
|
+
method: "POST",
|
|
315
|
+
body: { data }
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Insert multiple documents at once. Maximum 100 per batch.
|
|
320
|
+
*/
|
|
321
|
+
async insertBatch(collection, documents) {
|
|
322
|
+
return this.http.request(this.docsPath(collection), {
|
|
323
|
+
method: "POST",
|
|
324
|
+
body: { documents }
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Query documents with optional filtering, sorting, and pagination.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* const { documents } = await omen.collections.query('player_stats', {
|
|
333
|
+
* where: { level: { $gte: 10 } },
|
|
334
|
+
* sort: { score: -1 },
|
|
335
|
+
* limit: 20,
|
|
336
|
+
* });
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
async query(collection, options = {}) {
|
|
340
|
+
return this.http.request(this.docsPath(collection), {
|
|
341
|
+
query: {
|
|
342
|
+
where: options.where ? JSON.stringify(options.where) : void 0,
|
|
343
|
+
sort: options.sort ? JSON.stringify(options.sort) : void 0,
|
|
344
|
+
limit: options.limit,
|
|
345
|
+
offset: options.offset,
|
|
346
|
+
count: options.count ? "true" : void 0
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/** Get a single document by ID. */
|
|
351
|
+
async getDocument(collection, documentId) {
|
|
352
|
+
return this.http.request(`${this.docsPath(collection)}/${encodeURIComponent(documentId)}`);
|
|
353
|
+
}
|
|
354
|
+
/** Update a document's data (shallow merge). */
|
|
355
|
+
async updateDocument(collection, documentId, data) {
|
|
356
|
+
return this.http.request(`${this.docsPath(collection)}/${encodeURIComponent(documentId)}`, {
|
|
357
|
+
method: "PATCH",
|
|
358
|
+
body: { data }
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/** Delete a single document. */
|
|
362
|
+
async deleteDocument(collection, documentId) {
|
|
363
|
+
return this.http.request(`${this.docsPath(collection)}/${encodeURIComponent(documentId)}`, {
|
|
364
|
+
method: "DELETE"
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/** Get the document count for a collection, with optional filter. */
|
|
368
|
+
async count(collection, where) {
|
|
369
|
+
return this.http.request(`/api/v1/apps/${this.appId}/collections/${encodeURIComponent(collection)}/count`, {
|
|
370
|
+
query: { where: where ? JSON.stringify(where) : void 0 }
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Execute up to 5 operations atomically (Pro+ tier).
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```ts
|
|
378
|
+
* const { results } = await omen.collections.transaction('game_state', [
|
|
379
|
+
* { type: 'get', id: 'player_1' },
|
|
380
|
+
* { type: 'update', id: 'player_1', data: { health: 50 } },
|
|
381
|
+
* ]);
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
async transaction(collection, operations) {
|
|
385
|
+
return this.http.request(
|
|
386
|
+
`/api/v1/apps/${this.appId}/collections/${encodeURIComponent(collection)}/transaction`,
|
|
387
|
+
{ method: "POST", body: { operations } }
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
docsPath(collection) {
|
|
391
|
+
return `/api/v1/apps/${this.appId}/collections/${encodeURIComponent(collection)}/documents`;
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// src/namespaces/webhooks.ts
|
|
396
|
+
var WebhooksNamespace = class {
|
|
397
|
+
constructor(http, appId) {
|
|
398
|
+
this.http = http;
|
|
399
|
+
this.appId = appId;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Register a new webhook endpoint.
|
|
403
|
+
* The `secret` field is only returned on creation — store it securely.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* const webhook = await omen.webhooks.create({
|
|
408
|
+
* url: 'https://myapp.com/webhooks/omen',
|
|
409
|
+
* events: ['item.issued', 'friend.added'],
|
|
410
|
+
* });
|
|
411
|
+
* console.log(webhook.secret); // save this!
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
async create(options) {
|
|
415
|
+
return this.http.request(`/api/v1/apps/${this.appId}/webhooks`, {
|
|
416
|
+
method: "POST",
|
|
417
|
+
body: options
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/** List all webhook endpoints for your app. Secrets are not included. */
|
|
421
|
+
async list() {
|
|
422
|
+
return this.http.request(`/api/v1/apps/${this.appId}/webhooks`);
|
|
423
|
+
}
|
|
424
|
+
/** Get a single webhook endpoint. Secret is not included. */
|
|
425
|
+
async get(endpointId) {
|
|
426
|
+
return this.http.request(`/api/v1/apps/${this.appId}/webhooks/${encodeURIComponent(endpointId)}`);
|
|
427
|
+
}
|
|
428
|
+
/** Delete a webhook endpoint. */
|
|
429
|
+
async delete(endpointId) {
|
|
430
|
+
return this.http.request(`/api/v1/apps/${this.appId}/webhooks/${encodeURIComponent(endpointId)}`, {
|
|
431
|
+
method: "DELETE"
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Verify an incoming webhook signature. Use this in your webhook handler
|
|
436
|
+
* to confirm the request came from Omen.
|
|
437
|
+
*
|
|
438
|
+
* @param payload - The raw request body string.
|
|
439
|
+
* @param signature - The `X-Omen-Signature` header value.
|
|
440
|
+
* @param secret - The webhook secret from `create()`.
|
|
441
|
+
* @returns `true` if the signature is valid.
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```ts
|
|
445
|
+
* app.post('/webhooks/omen', (req, res) => {
|
|
446
|
+
* const valid = omen.webhooks.verify(
|
|
447
|
+
* req.body, // raw string
|
|
448
|
+
* req.headers['x-omen-signature'],
|
|
449
|
+
* process.env.OMEN_WEBHOOK_SECRET,
|
|
450
|
+
* );
|
|
451
|
+
* if (!valid) return res.status(401).send('Bad signature');
|
|
452
|
+
* // handle event...
|
|
453
|
+
* });
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
async verify(payload, signature, secret) {
|
|
457
|
+
const encoder = new TextEncoder();
|
|
458
|
+
const key = await crypto.subtle.importKey(
|
|
459
|
+
"raw",
|
|
460
|
+
encoder.encode(secret),
|
|
461
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
462
|
+
false,
|
|
463
|
+
["sign"]
|
|
464
|
+
);
|
|
465
|
+
const sig = await crypto.subtle.sign("HMAC", key, encoder.encode(payload));
|
|
466
|
+
const expected = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
467
|
+
return timingSafeEqual(expected, signature);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
function timingSafeEqual(a, b) {
|
|
471
|
+
if (a.length !== b.length) return false;
|
|
472
|
+
let result = 0;
|
|
473
|
+
for (let i = 0; i < a.length; i++) {
|
|
474
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
475
|
+
}
|
|
476
|
+
return result === 0;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// src/index.ts
|
|
480
|
+
var OmenClient = class {
|
|
481
|
+
/** User profiles and friend lists. */
|
|
482
|
+
users;
|
|
483
|
+
/** Per-user key-value storage. */
|
|
484
|
+
storage;
|
|
485
|
+
/** Issue, revoke, and batch-manage items. */
|
|
486
|
+
items;
|
|
487
|
+
/** Structured data collections (document database). */
|
|
488
|
+
collections;
|
|
489
|
+
/** Webhook endpoint management and signature verification. */
|
|
490
|
+
webhooks;
|
|
491
|
+
constructor(options) {
|
|
492
|
+
if (!options.token) throw new Error("OmenClient: token is required");
|
|
493
|
+
if (!options.appId) throw new Error("OmenClient: appId is required");
|
|
494
|
+
const baseUrl = options.baseUrl ?? "https://omen.dog";
|
|
495
|
+
const http = new HttpClient(options.token, baseUrl);
|
|
496
|
+
this.users = new UsersNamespace(http);
|
|
497
|
+
this.storage = new StorageNamespace(http);
|
|
498
|
+
this.items = new ItemsNamespace(http, options.appId);
|
|
499
|
+
this.collections = new CollectionsNamespace(http, options.appId);
|
|
500
|
+
this.webhooks = new WebhooksNamespace(http, options.appId);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
export {
|
|
504
|
+
OmenAuthError,
|
|
505
|
+
OmenClient,
|
|
506
|
+
OmenError,
|
|
507
|
+
OmenNotFoundError,
|
|
508
|
+
OmenRateLimitError,
|
|
509
|
+
OmenValidationError
|
|
510
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omen.dog/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official server-side TypeScript SDK for the Omen platform",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./creation": {
|
|
16
|
+
"types": "./dist/creation.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.0.0"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean && cp src/creation.d.ts dist/creation.d.ts",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsup": "^8.0.0",
|
|
31
|
+
"typescript": "^5.4.0"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"omen",
|
|
35
|
+
"game-platform",
|
|
36
|
+
"sdk",
|
|
37
|
+
"api-client"
|
|
38
|
+
],
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/omen-dog/sdk"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://omen.dog/docs"
|
|
44
|
+
}
|