@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 ADDED
@@ -0,0 +1,147 @@
1
+ # @omen.dog/sdk
2
+
3
+ Official server-side TypeScript SDK for the [Omen](https://omen.dog) platform.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @omen.dog/sdk
9
+ ```
10
+
11
+ Requires Node.js 18+ (uses native `fetch`). Zero dependencies.
12
+
13
+ ## Quick Start
14
+
15
+ ```ts
16
+ import { OmenClient } from '@omen.dog/sdk';
17
+
18
+ const omen = new OmenClient({
19
+ token: process.env.OMEN_TOKEN!, // dev_yourorg_abc123...
20
+ appId: 'your-app-id', // from the Developer Portal
21
+ });
22
+ ```
23
+
24
+ ## Namespaces
25
+
26
+ ### Users
27
+
28
+ ```ts
29
+ const profile = await omen.users.get('pistolphoenix');
30
+ const { friends, onlineCount } = await omen.users.friends('pistolphoenix', {
31
+ status: 'online',
32
+ limit: 10,
33
+ });
34
+ ```
35
+
36
+ ### Storage
37
+
38
+ Per-user key-value storage scoped to your app.
39
+
40
+ ```ts
41
+ const { data } = await omen.storage.get();
42
+ await omen.storage.set({ highScore: 100, level: 5 });
43
+ await omen.storage.merge({ highScore: 200 }); // keeps 'level' intact
44
+ ```
45
+
46
+ ### Items
47
+
48
+ Issue achievements, collectibles, and in-game items to users.
49
+
50
+ ```ts
51
+ const item = await omen.items.issue({
52
+ userId: 'cmm0tzco8...',
53
+ name: 'Dragon Slayer',
54
+ type: 'achievement',
55
+ rarity: 'legendary',
56
+ });
57
+
58
+ // Batch issue (up to 100)
59
+ const { items } = await omen.items.issueBatch([
60
+ { userId: 'user1', name: 'Gold Medal', type: 'achievement' },
61
+ { userId: 'user2', name: 'Silver Medal', type: 'achievement' },
62
+ ]);
63
+
64
+ // Revoke
65
+ await omen.items.revoke(item.id, 'Violated terms');
66
+ ```
67
+
68
+ ### Collections
69
+
70
+ Structured data storage — like a simple document database.
71
+
72
+ ```ts
73
+ // Create a collection with schema
74
+ await omen.collections.create({
75
+ name: 'player_stats',
76
+ schema: { score: 'number', level: 'number', name: 'string' },
77
+ indexedFields: ['score'],
78
+ });
79
+
80
+ // Insert documents
81
+ const doc = await omen.collections.insert('player_stats', {
82
+ score: 1500, level: 12, name: 'PistolPhoenix',
83
+ });
84
+
85
+ // Query with filters
86
+ const { documents } = await omen.collections.query('player_stats', {
87
+ where: { level: { $gte: 10 } },
88
+ sort: { score: -1 },
89
+ limit: 20,
90
+ });
91
+
92
+ // Atomic transactions (Pro+ tier)
93
+ const { results } = await omen.collections.transaction('game_state', [
94
+ { type: 'get', id: 'player_1' },
95
+ { type: 'update', id: 'player_1', data: { health: 50 } },
96
+ ]);
97
+ ```
98
+
99
+ ### Webhooks
100
+
101
+ ```ts
102
+ // Register (secret is only returned once!)
103
+ const webhook = await omen.webhooks.create({
104
+ url: 'https://myapp.com/webhooks/omen',
105
+ events: ['item.issued', 'friend.added'],
106
+ });
107
+ console.log(webhook.secret); // save this!
108
+
109
+ // Verify incoming webhooks
110
+ const valid = await omen.webhooks.verify(rawBody, signature, secret);
111
+ ```
112
+
113
+ ## Creation Runtime Types
114
+
115
+ For creation developers — get autocomplete for the `omen.*` global:
116
+
117
+ ```ts
118
+ /// <reference types="@omen.dog/sdk/creation" />
119
+
120
+ const save = await omen.load();
121
+ omen.score(100);
122
+ ```
123
+
124
+ ## Error Handling
125
+
126
+ ```ts
127
+ import { OmenClient, OmenNotFoundError, OmenRateLimitError } from '@omen.dog/sdk';
128
+
129
+ try {
130
+ await omen.users.get('nonexistent');
131
+ } catch (err) {
132
+ if (err instanceof OmenNotFoundError) {
133
+ console.log('User not found');
134
+ }
135
+ if (err instanceof OmenRateLimitError) {
136
+ console.log(`Rate limited. Retry after ${err.retryAfter}s`);
137
+ }
138
+ }
139
+ ```
140
+
141
+ ## API Reference
142
+
143
+ Full documentation at [omen.dog/docs](https://omen.dog/docs).
144
+
145
+ ## License
146
+
147
+ MIT
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Type definitions for the Omen Creation Runtime SDK.
3
+ *
4
+ * Add to your creation's tsconfig.json or use a triple-slash directive:
5
+ * ```ts
6
+ * /// <reference types="@omen.dog/sdk/creation" />
7
+ * ```
8
+ *
9
+ * This provides autocomplete for the `omen.*` global available inside creations.
10
+ * Zero runtime cost — types only.
11
+ */
12
+
13
+ interface OmenStorageAPI {
14
+ /** Load the user's saved data for this creation. */
15
+ load(): Promise<Record<string, unknown> | null>;
16
+ /** Save data for the current user. */
17
+ save(data: Record<string, unknown>): Promise<void>;
18
+ /** Delete the user's saved data. */
19
+ delete(): Promise<void>;
20
+ }
21
+
22
+ interface OmenCollectionsAPI {
23
+ /** Insert a document into a collection. */
24
+ insert(collection: string, data: Record<string, unknown>): Promise<{ id: string }>;
25
+ /** Find documents in a collection. */
26
+ find(collection: string, query?: {
27
+ where?: Record<string, unknown>;
28
+ sort?: Record<string, 1 | -1>;
29
+ limit?: number;
30
+ offset?: number;
31
+ }): Promise<{ documents: Array<{ id: string; data: Record<string, unknown> }> }>;
32
+ /** Update a document. */
33
+ update(collection: string, docId: string, data: Record<string, unknown>): Promise<void>;
34
+ /** Delete a document. */
35
+ delete(collection: string, docId: string): Promise<void>;
36
+ }
37
+
38
+ interface OmenInputAPI {
39
+ /** True while the key/button is held. */
40
+ isDown(action: 'action' | 'secondary' | 'up' | 'down' | 'left' | 'right'): boolean;
41
+ /** True for one frame on press. */
42
+ pressed(action: 'action' | 'secondary' | 'up' | 'down' | 'left' | 'right'): boolean;
43
+ /** True for one frame on release. */
44
+ released(action: 'action' | 'secondary' | 'up' | 'down' | 'left' | 'right'): boolean;
45
+ /** Register a callback on press. */
46
+ on(action: string, fn: () => void): void;
47
+ /** Pointer state (normalized 0-1 coordinates). */
48
+ pointer: { x: number; y: number; down: boolean };
49
+ /** Show the virtual joystick on mobile. */
50
+ joystick(): void;
51
+ /** Virtual joystick position (-1 to 1). */
52
+ stick: { x: number; y: number };
53
+ }
54
+
55
+ interface OmenDeviceAPI {
56
+ type: 'mobile' | 'tablet' | 'desktop';
57
+ touch: boolean;
58
+ keyboard: boolean;
59
+ width: number;
60
+ height: number;
61
+ orientation: 'portrait' | 'landscape';
62
+ on(event: 'resize', fn: () => void): void;
63
+ }
64
+
65
+ interface OmenSDK {
66
+ /** Current user info. */
67
+ me: { id: string; username: string; avatar: string | null };
68
+
69
+ // Storage
70
+ load(): Promise<Record<string, unknown> | null>;
71
+ save(data: Record<string, unknown>): Promise<void>;
72
+
73
+ // Collections
74
+ collections: OmenCollectionsAPI;
75
+
76
+ // Economy
77
+ buy(productId: string): Promise<{ success: boolean; item?: unknown; newBalance?: number }>;
78
+ owns(itemId: string): boolean;
79
+ inventory(): Promise<Array<{ id: string; name: string; type: string }>>;
80
+
81
+ // Items & Badges
82
+ hasItem(itemId: string): boolean;
83
+ hasBadge(badgeId: string): boolean;
84
+
85
+ // Social
86
+ friends(): Promise<Array<{ id: string; username: string; avatar: string | null; status: string }>>;
87
+ invite(friendId: string): Promise<void>;
88
+ presence(text: string | null): void;
89
+
90
+ // Companion
91
+ companion(): Promise<{ name: string; mood: string; traits: string[] } | null>;
92
+
93
+ // Input
94
+ input: OmenInputAPI;
95
+
96
+ // Device
97
+ device: OmenDeviceAPI;
98
+
99
+ // Moderation
100
+ filter(text: string, options?: { context?: 'username' | 'content'; mode?: 'check' }): Promise<string | { allowed: boolean; reason?: string }>;
101
+ isChild(): boolean;
102
+ report(userId: string, reason: string): Promise<void>;
103
+
104
+ // Leaderboards
105
+ score(value: number, options?: { board?: string; metadata?: Record<string, unknown> }): Promise<{ rank: number; score: number; isNewBest: boolean; previousRank: number | null }>;
106
+ leaderboard(options?: { board?: string; friends?: boolean; period?: 'all' | 'week' | 'month' }): Promise<{ entries: Array<{ rank: number; userId: string; username: string; score: number }>; board: string; userRank: number | null }>;
107
+ showLeaderboard(board?: string): void;
108
+
109
+ // Haptics
110
+ vibrate(type: 'light' | 'medium' | 'heavy' | 'success' | 'error'): void;
111
+
112
+ // Feature detection
113
+ has(feature: 'storage' | 'collections' | 'economy' | 'identity' | 'input' | 'social' | 'companion' | 'moderation' | 'leaderboard'): boolean;
114
+ }
115
+
116
+ declare const omen: OmenSDK;