@omen.dog/sdk 1.0.0 → 1.1.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/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ export { ASK_GROWN_UP_STATES, CHILD_LOGIN_STATES, ChildIdentity, ChildLogin, ChildLoginApprovedPayload, ChildLoginContext, ChildLoginDisplayGroup, ChildLoginOptions, ChildLoginSignal, ChildLoginState, ChildRebind, ChildTokens, DeviceStartOptions, DeviceStartResult, ENTRY_STATES, PollResult, PollUntilOptions, SealedSession, deriveInitialState, displayGroup, reduce } from './child-login.mjs';
2
+
1
3
  interface RequestOptions {
2
4
  method?: string;
3
5
  body?: unknown;
@@ -160,6 +162,149 @@ interface BatchIssueResponse {
160
162
  items: Item[];
161
163
  count: number;
162
164
  }
165
+ interface AwardSparksOptions {
166
+ userId: string;
167
+ amount: number;
168
+ reason?: string;
169
+ /** Make retries safe — the same key is credited at most once. */
170
+ idempotencyKey?: string;
171
+ }
172
+ interface AwardResult {
173
+ awarded: number;
174
+ userId: string;
175
+ userBalance: number;
176
+ poolBalance: number;
177
+ transactionId: string | null;
178
+ idempotent: boolean;
179
+ }
180
+ interface AwardBatchItem {
181
+ userId: string;
182
+ amount: number;
183
+ reason?: string;
184
+ idempotencyKey?: string;
185
+ }
186
+ interface AwardBatchResultItem {
187
+ index: number;
188
+ userId: string | null;
189
+ ok: boolean;
190
+ awarded?: number;
191
+ userBalance?: number;
192
+ idempotent?: boolean;
193
+ error?: string;
194
+ }
195
+ interface AwardBatchResponse {
196
+ results: AwardBatchResultItem[];
197
+ succeeded: number;
198
+ failed: number;
199
+ poolBalance: number;
200
+ }
201
+ interface PoolBudget {
202
+ appId: string;
203
+ balance: number;
204
+ lifetimeAllocated: number;
205
+ lifetimeAwarded: number;
206
+ }
207
+ interface PoolStatus {
208
+ balance: number;
209
+ lifetimePurchased: number;
210
+ lifetimeAwarded: number;
211
+ lowBalanceThreshold: number;
212
+ currency: string;
213
+ budgets: PoolBudget[];
214
+ }
215
+ interface DisplayTokenOptions {
216
+ userId: string;
217
+ /** Your app's OAuth client secret (backend only). */
218
+ secret: string;
219
+ /** Token lifetime in seconds. Default 600, max 3600. */
220
+ ttlSeconds?: number;
221
+ }
222
+ /** F262 — write-scoped editor token for <omen-avatar-editor>. */
223
+ interface EditorTokenOptions {
224
+ userId: string;
225
+ /** Your app's OAuth client secret (backend only). */
226
+ secret: string;
227
+ /** Token lifetime in seconds. Default 600, max 3600. */
228
+ ttlSeconds?: number;
229
+ }
230
+ interface AvatarCatalogTrait {
231
+ /** `category/file.svg` path — also a public SVG at `{baseUrl}/avatar/{id}`. */
232
+ id: string;
233
+ name: string;
234
+ rarity: string;
235
+ /** Sparks list price derived from rarity (0 = common/free). */
236
+ price: number;
237
+ /** With an editor token: whether that user still needs to unlock it. */
238
+ locked: boolean;
239
+ [key: string]: unknown;
240
+ }
241
+ interface AvatarCatalogResult {
242
+ catalog: Record<string, {
243
+ traits: AvatarCatalogTrait[];
244
+ [key: string]: unknown;
245
+ }>;
246
+ /** Sparks price per rarity tier. */
247
+ rarityPricing: Record<string, number>;
248
+ [key: string]: unknown;
249
+ }
250
+ interface SendEmailOptions {
251
+ /** Sender address. Its domain must be a verified sending domain on your org. */
252
+ from: string;
253
+ /** Display name shown next to the from address. */
254
+ fromName?: string;
255
+ /** One address or up to 10. */
256
+ to: string | string[];
257
+ subject: string;
258
+ html?: string;
259
+ text?: string;
260
+ replyTo?: string;
261
+ }
262
+ interface SendEmailResult {
263
+ sent: number;
264
+ rejected: string[];
265
+ messageId: string | null;
266
+ from: string;
267
+ dailyRemaining: number;
268
+ }
269
+ interface EmailLogEntry {
270
+ id: string;
271
+ fromEmail: string;
272
+ toEmail: string;
273
+ subject: string;
274
+ status: 'sent' | 'failed';
275
+ error: string | null;
276
+ createdAt: string;
277
+ }
278
+ interface EmailLogResponse {
279
+ messages: EmailLogEntry[];
280
+ quota: {
281
+ dailyLimit: number;
282
+ usedToday: number;
283
+ remaining: number;
284
+ };
285
+ }
286
+ type CatalogType = 'store' | 'avatar_trait';
287
+ interface AwardCatalogOptions {
288
+ userId: string;
289
+ /** 'store' = open-shop item, 'avatar_trait' = avatar-editor item. */
290
+ catalogType: CatalogType;
291
+ catalogItemId: string;
292
+ idempotencyKey?: string;
293
+ }
294
+ interface AwardCatalogResult {
295
+ userId: string;
296
+ item?: {
297
+ id: string;
298
+ name: string;
299
+ rarity?: string | null;
300
+ type?: string;
301
+ category?: string;
302
+ };
303
+ price?: number;
304
+ poolBalance?: number;
305
+ alreadyOwned?: boolean;
306
+ idempotent?: boolean;
307
+ }
163
308
  type SchemaFieldType = 'string' | 'number' | 'boolean' | 'date';
164
309
  interface CreateCollectionOptions {
165
310
  name: string;
@@ -203,6 +348,81 @@ interface TransactionResponse {
203
348
  deleted: string;
204
349
  }>;
205
350
  }
351
+ interface Product {
352
+ id: string;
353
+ appId: string;
354
+ name: string;
355
+ description: string;
356
+ type: 'one_time' | 'subscription';
357
+ priceCents: number;
358
+ currency: string;
359
+ billingInterval: 'month' | 'year' | null;
360
+ trialDays: number | null;
361
+ maxPurchasesPerUser: number | null;
362
+ templateId: string | null;
363
+ active: boolean;
364
+ stripeProductId: string | null;
365
+ stripePriceId: string | null;
366
+ createdAt: string;
367
+ updatedAt: string;
368
+ }
369
+ interface CreateProductOptions {
370
+ name: string;
371
+ type: 'one_time' | 'subscription';
372
+ priceCents: number;
373
+ currency?: string;
374
+ description?: string;
375
+ billingInterval?: 'month' | 'year';
376
+ trialDays?: number;
377
+ maxPurchasesPerUser?: number;
378
+ templateId?: string;
379
+ }
380
+ interface UpdateProductOptions {
381
+ name?: string;
382
+ description?: string;
383
+ active?: boolean;
384
+ maxPurchasesPerUser?: number;
385
+ templateId?: string;
386
+ }
387
+ interface MultiplayerConfig {
388
+ managed: boolean;
389
+ maxPlayers: number;
390
+ soloSupported: boolean;
391
+ allowSpectators: boolean;
392
+ voiceEnabled: boolean;
393
+ teamMode: 'none' | 'manual' | 'auto';
394
+ teamCount: number;
395
+ matchmaking: boolean;
396
+ }
397
+ interface UpdateMultiplayerConfigOptions {
398
+ managed?: boolean;
399
+ maxPlayers?: number;
400
+ soloSupported?: boolean;
401
+ allowSpectators?: boolean;
402
+ voiceEnabled?: boolean;
403
+ teamMode?: 'none' | 'manual' | 'auto';
404
+ teamCount?: number;
405
+ matchmaking?: boolean;
406
+ }
407
+ interface RoomLogicVersion {
408
+ version: number;
409
+ deployedAt: string;
410
+ active: boolean;
411
+ sizeBytes: number;
412
+ }
413
+ type NotificationCategory = 'general' | 'items' | 'transfers' | 'badges' | 'social' | 'app' | 'system';
414
+ interface SendNotificationOptions {
415
+ userId: string;
416
+ title: string;
417
+ body: string;
418
+ category?: NotificationCategory;
419
+ data?: Record<string, unknown>;
420
+ actionUrl?: string;
421
+ }
422
+ interface NotificationResponse {
423
+ id: string;
424
+ status: 'sent';
425
+ }
206
426
  interface CreateWebhookOptions {
207
427
  url: string;
208
428
  events: string[];
@@ -330,6 +550,20 @@ declare class ItemsNamespace {
330
550
  * ```
331
551
  */
332
552
  revoke(itemId: string, reason?: string): Promise<Item>;
553
+ /**
554
+ * Award a catalog item (open-shop cosmetic or avatar-editor trait) to a user,
555
+ * paid for from your Sparks pool at the item's list price. Custom items use
556
+ * `issue()` and are free; catalog items draw the pool down. Re-awarding an item
557
+ * the user already owns is a no-op (no charge).
558
+ *
559
+ * @example
560
+ * ```ts
561
+ * await omen.items.awardCatalog({
562
+ * userId, catalogType: 'store', catalogItemId: 'theme_lava',
563
+ * });
564
+ * ```
565
+ */
566
+ awardCatalog(options: AwardCatalogOptions): Promise<AwardCatalogResult>;
333
567
  }
334
568
 
335
569
  /**
@@ -483,6 +717,265 @@ declare class WebhooksNamespace {
483
717
  verify(payload: string, signature: string, secret: string): Promise<boolean>;
484
718
  }
485
719
 
720
+ /**
721
+ * Manage in-app products (one-time purchases and subscriptions).
722
+ *
723
+ * Products are created by developers and purchased by users via Stripe.
724
+ */
725
+ declare class ProductsNamespace {
726
+ private readonly http;
727
+ private readonly appId;
728
+ constructor(http: HttpClient, appId: string);
729
+ /**
730
+ * Create a new product.
731
+ *
732
+ * @example
733
+ * ```ts
734
+ * const product = await omen.products.create({
735
+ * name: 'Premium Sword',
736
+ * type: 'one_time',
737
+ * priceCents: 499,
738
+ * });
739
+ * ```
740
+ */
741
+ create(options: CreateProductOptions): Promise<Product>;
742
+ /**
743
+ * List all products for this app.
744
+ *
745
+ * @param activeOnly - If true, only return active products. Defaults to false.
746
+ */
747
+ list(activeOnly?: boolean): Promise<Product[]>;
748
+ /**
749
+ * Update an existing product.
750
+ *
751
+ * @param productId - The product ID to update.
752
+ * @param options - Fields to update.
753
+ */
754
+ update(productId: string, options: UpdateProductOptions): Promise<Product>;
755
+ /**
756
+ * Deactivate a product. Deactivated products cannot be purchased but existing
757
+ * purchases remain valid.
758
+ *
759
+ * @param productId - The product ID to deactivate.
760
+ */
761
+ deactivate(productId: string): Promise<void>;
762
+ }
763
+
764
+ /**
765
+ * Configure managed multiplayer and deploy authoritative room logic.
766
+ *
767
+ * Room creation/joining is handled by the platform via the SDK bridge.
768
+ * This namespace is for developer-side configuration and deployment.
769
+ */
770
+ declare class MultiplayerNamespace {
771
+ private readonly http;
772
+ private readonly appId;
773
+ constructor(http: HttpClient, appId: string);
774
+ /**
775
+ * Get the current multiplayer configuration for this app.
776
+ */
777
+ getConfig(): Promise<MultiplayerConfig | null>;
778
+ /**
779
+ * Enable or update managed multiplayer configuration.
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * await omen.multiplayer.updateConfig({
784
+ * managed: true,
785
+ * maxPlayers: 8,
786
+ * voiceEnabled: true,
787
+ * teamMode: 'manual',
788
+ * });
789
+ * ```
790
+ */
791
+ updateConfig(options: UpdateMultiplayerConfigOptions): Promise<MultiplayerConfig>;
792
+ /**
793
+ * Deploy authoritative room logic (Pro tier required).
794
+ * The bundle is a JavaScript file that exports room lifecycle hooks.
795
+ *
796
+ * @param bundle - The JavaScript source code as a string.
797
+ */
798
+ deployLogic(bundle: string): Promise<{
799
+ version: number;
800
+ deployedAt: string;
801
+ }>;
802
+ /**
803
+ * List deployed room logic versions.
804
+ */
805
+ listLogicVersions(): Promise<RoomLogicVersion[]>;
806
+ /**
807
+ * Roll back to a previous room logic version.
808
+ *
809
+ * @param version - The version number to roll back to.
810
+ */
811
+ rollbackLogic(version: number): Promise<{
812
+ version: number;
813
+ rolledBackAt: string;
814
+ }>;
815
+ }
816
+
817
+ /**
818
+ * Send notifications to users of your app.
819
+ *
820
+ * Notifications appear in the user's notification inbox on Omen.
821
+ */
822
+ declare class NotificationsNamespace {
823
+ private readonly http;
824
+ private readonly appId;
825
+ constructor(http: HttpClient, appId: string);
826
+ /**
827
+ * Send a notification to a user.
828
+ *
829
+ * @example
830
+ * ```ts
831
+ * await omen.notifications.send({
832
+ * userId: 'cmm0tzco8...',
833
+ * title: 'New high score!',
834
+ * body: 'Someone beat your record on Pixel Duel.',
835
+ * category: 'app',
836
+ * actionUrl: '/creations/pixel-duel',
837
+ * });
838
+ * ```
839
+ */
840
+ send(options: SendNotificationOptions): Promise<NotificationResponse>;
841
+ }
842
+
843
+ /**
844
+ * Award Sparks (money-backed) to your app's users from your prepaid pool, and
845
+ * mint short-lived display tokens for the embeddable UI kit.
846
+ *
847
+ * Buy and manage the pool in the Developer Portal → Sparks Pool. Awards draw the
848
+ * pool down (or an app's allocated sub-budget if one exists).
849
+ *
850
+ * NOTE: `award`, `awardBatch`, and `items.awardCatalog` require an APPROVED
851
+ * Partner App (Developer Portal → Partner Program). Unapproved apps receive
852
+ * `403 partner_required`. Funding a pool and minting display tokens do not.
853
+ */
854
+ declare class SparksNamespace {
855
+ private readonly http;
856
+ private readonly appId;
857
+ constructor(http: HttpClient, appId: string);
858
+ /**
859
+ * Award Sparks to a single user. Pass `idempotencyKey` to make retries safe.
860
+ *
861
+ * @example
862
+ * ```ts
863
+ * await omen.sparks.award({
864
+ * userId: 'cmm0tzco8...',
865
+ * amount: 250,
866
+ * reason: 'Beat level 10',
867
+ * idempotencyKey: `level10:${userId}`,
868
+ * });
869
+ * ```
870
+ */
871
+ award(options: AwardSparksOptions): Promise<AwardResult>;
872
+ /**
873
+ * Award Sparks to many users in one request (max 100). Best-effort per item:
874
+ * a single bad/underfunded entry does not fail the rest. Inspect `results`.
875
+ */
876
+ awardBatch(awards: AwardBatchItem[]): Promise<AwardBatchResponse>;
877
+ /** Current pool status: balance, lifetime stats, and per-app budgets. */
878
+ pool(): Promise<PoolStatus>;
879
+ /**
880
+ * Mint a short-lived display token for the UI kit, scoped to one user. Sign
881
+ * with your app's OAuth client SECRET (from the Developer Portal) — never ship
882
+ * the secret to the browser; call this on your backend and pass the token to
883
+ * `<omen-sparks-balance token="...">` / `<omen-inventory token="...">`.
884
+ *
885
+ * Synchronous (no network). Default TTL 10 min, max 1 hour.
886
+ *
887
+ * @example
888
+ * ```ts
889
+ * const token = omen.sparks.displayToken({ userId, secret: process.env.OMEN_CLIENT_SECRET! });
890
+ * ```
891
+ */
892
+ displayToken(options: DisplayTokenOptions): string;
893
+ }
894
+
895
+ /**
896
+ * Send transactional email from your own verified domain through Omen.
897
+ *
898
+ * Add and verify a sending domain in the Developer Portal → Email (publish the
899
+ * ownership/SPF/DKIM TXT records it gives you), then send from any address on
900
+ * that domain.
901
+ *
902
+ * NOTE: sending requires an APPROVED Partner App (Developer Portal → Partner
903
+ * Program); unapproved apps receive `403 partner_required`. Sends are capped
904
+ * per app per rolling 24h — check `dailyRemaining` / `emails.log()`.
905
+ */
906
+ declare class EmailsNamespace {
907
+ private readonly http;
908
+ private readonly appId;
909
+ constructor(http: HttpClient, appId: string);
910
+ /**
911
+ * Send one email (up to 10 recipients). No attachments; 256 KB body max.
912
+ *
913
+ * @example
914
+ * ```ts
915
+ * await omen.emails.send({
916
+ * from: 'hello@yourdomain.com',
917
+ * fromName: 'My App',
918
+ * to: player.email,
919
+ * subject: 'Your weekly recap',
920
+ * html: '<h1>Nice run!</h1>',
921
+ * });
922
+ * ```
923
+ */
924
+ send(options: SendEmailOptions): Promise<SendEmailResult>;
925
+ /** Recent sends for this app plus the rolling 24h quota. */
926
+ log(limit?: number): Promise<EmailLogResponse>;
927
+ }
928
+
929
+ /**
930
+ * F262 Embedded Avatar Kit — the shared Omen avatar inside your app.
931
+ *
932
+ * Your users keep ONE avatar across Omen and every partner app: display it
933
+ * with `<omen-avatar>` (or `renderUrl()`), and let users edit it in-place
934
+ * with `<omen-avatar-editor>` powered by an editor token minted here.
935
+ *
936
+ * NOTE: editor tokens only verify for APPROVED Partner Apps, and only for
937
+ * users who have connected your app via Omen OAuth. Theme, currency display
938
+ * and commerce flags are configured per-app via the Developer Portal →
939
+ * Embed, or PUT /api/v1/developer/apps/{appId}/embed-config.
940
+ */
941
+ declare class AvatarNamespace {
942
+ private readonly appId;
943
+ private readonly baseUrl;
944
+ constructor(appId: string, baseUrl: string);
945
+ /**
946
+ * Mint a short-lived WRITE-scoped editor token for one user (backend only —
947
+ * never expose your client secret to the browser). Pass it to
948
+ * `<omen-avatar-editor token="...">`.
949
+ *
950
+ * @example
951
+ * ```ts
952
+ * const token = omen.avatar.editorToken({ userId, secret: process.env.OMEN_CLIENT_SECRET! });
953
+ * ```
954
+ */
955
+ editorToken(options: EditorTokenOptions): string;
956
+ /**
957
+ * Public render URL for a user's shared avatar (SVG; append `&format=png`
958
+ * where supported). Pass `version` (from the `avatar:saved` event or the
959
+ * `user.avatar_updated` webhook) to bust caches after an edit.
960
+ */
961
+ renderUrl(userId: string, options?: {
962
+ version?: string;
963
+ }): string;
964
+ /**
965
+ * Enumerate the shared avatar catalog — every trait id, name, rarity and
966
+ * Sparks list price. Public, no auth. Trait ids (`category/file.svg` paths)
967
+ * are also public SVGs at `{baseUrl}/avatar/{id}` for previews, and feed
968
+ * `omen.items.awardCatalog({ catalogType: 'avatar_trait', catalogItemId })`
969
+ * for pool-funded gifts.
970
+ *
971
+ * Pass a user's editor token and each trait's `locked` flag reflects that
972
+ * user's ownership instead of the anonymous default.
973
+ */
974
+ catalog(options?: {
975
+ editorToken?: string;
976
+ }): Promise<AvatarCatalogResult>;
977
+ }
978
+
486
979
  /** Base error for all Omen SDK errors. */
487
980
  declare class OmenError extends Error {
488
981
  /** HTTP status code from the API. */
@@ -551,9 +1044,21 @@ declare class OmenClient {
551
1044
  readonly collections: CollectionsNamespace;
552
1045
  /** Webhook endpoint management and signature verification. */
553
1046
  readonly webhooks: WebhooksNamespace;
1047
+ /** In-app products (one-time purchases and subscriptions). */
1048
+ readonly products: ProductsNamespace;
1049
+ /** Managed multiplayer configuration and room logic deployment. */
1050
+ readonly multiplayer: MultiplayerNamespace;
1051
+ /** Send notifications to app users. */
1052
+ readonly notifications: NotificationsNamespace;
1053
+ /** Award Sparks from your prepaid pool + mint UI-kit display tokens. */
1054
+ readonly sparks: SparksNamespace;
1055
+ /** Send transactional email from your verified domains (Partner Apps). */
1056
+ readonly emails: EmailsNamespace;
1057
+ /** Shared Omen avatar in your app: editor tokens + render URLs (F262). */
1058
+ readonly avatar: AvatarNamespace;
554
1059
  constructor(options: OmenClientOptions & {
555
1060
  appId: string;
556
1061
  });
557
1062
  }
558
1063
 
559
- export { type AcquisitionType, type Badge, type BatchIssueResponse, type Collection, type CreateCollectionOptions, type CreateWebhookOptions, type Document, type FeaturedItem, type Friend, type FriendsListOptions, type FriendsListResponse, type IssueItemOptions, type Item, type ItemType, OmenAuthError, OmenClient, type OmenClientOptions, OmenError, OmenNotFoundError, OmenRateLimitError, OmenValidationError, type PinnedCreation, type QueryDocumentsOptions, type QueryDocumentsResponse, type SchemaFieldType, type StorageData, type TransactionOperation, type TransactionResponse, type UserProfile, type UserProfileResponse, type Webhook };
1064
+ export { type AcquisitionType, type AwardBatchItem, type AwardBatchResponse, type AwardBatchResultItem, type AwardCatalogOptions, type AwardCatalogResult, type AwardResult, type AwardSparksOptions, type Badge, type BatchIssueResponse, type CatalogType, type Collection, type CreateCollectionOptions, type CreateProductOptions, type CreateWebhookOptions, type DisplayTokenOptions, type Document, type EditorTokenOptions, type EmailLogEntry, type EmailLogResponse, type FeaturedItem, type Friend, type FriendsListOptions, type FriendsListResponse, type IssueItemOptions, type Item, type ItemType, type MultiplayerConfig, type NotificationCategory, type NotificationResponse, OmenAuthError, OmenClient, type OmenClientOptions, OmenError, OmenNotFoundError, OmenRateLimitError, OmenValidationError, type PinnedCreation, type PoolBudget, type PoolStatus, type Product, type QueryDocumentsOptions, type QueryDocumentsResponse, type RoomLogicVersion, type SchemaFieldType, type SendEmailOptions, type SendEmailResult, type SendNotificationOptions, type StorageData, type TransactionOperation, type TransactionResponse, type UpdateMultiplayerConfigOptions, type UpdateProductOptions, type UserProfile, type UserProfileResponse, type Webhook };