@layers/amba-web 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.
@@ -0,0 +1,814 @@
1
+ import { AmbaCoreWasm } from "@layers/amba-core-wasm";
2
+
3
+ //#region src/types.d.ts
4
+
5
+ /**
6
+ * Public type surface for `@layers/amba-web`.
7
+ *
8
+ * Mirrors the Rust core's `serde` definitions. Field names match the
9
+ * wire format (snake_case) where it would cause confusion to translate;
10
+ * idiomatic camelCase is reserved for the SDK's own option objects.
11
+ */
12
+ interface AmbaConfig {
13
+ /** Tenant API key from the developer console (`amba_pk_…`). */
14
+ apiKey: string;
15
+ /** Override the base URL for non-prod environments. */
16
+ baseUrl?: string;
17
+ /**
18
+ * If `true`, blocks all telemetry until `setConsent(granted)` is called.
19
+ * Required for SOC2 / GDPR strict modes.
20
+ */
21
+ consentRequired?: boolean;
22
+ /** Verbose `tracing::Level::DEBUG` logging. */
23
+ debug?: boolean;
24
+ /** Override the localStorage key prefix. Defaults to `"amba"`. */
25
+ storagePrefix?: string;
26
+ }
27
+ type SocialProvider = "apple" | "google";
28
+ type PushPlatform = "apns" | "fcm" | "web";
29
+ interface User {
30
+ id: string;
31
+ email?: string | null;
32
+ display_name?: string | null;
33
+ avatar_url?: string | null;
34
+ external_id?: string | null;
35
+ anonymous_id?: string | null;
36
+ auth_providers: string[];
37
+ properties: Record<string, unknown>;
38
+ first_seen_at?: string;
39
+ last_seen_at?: string;
40
+ created_at?: string;
41
+ updated_at?: string;
42
+ }
43
+ interface AuthResult {
44
+ session_token: string;
45
+ refresh_token: string;
46
+ user: User;
47
+ anonymous_id?: string | null;
48
+ expires_at?: string | null;
49
+ }
50
+ /**
51
+ * Snapshot of the current session as visible to the SDK consumer.
52
+ *
53
+ * `sessionToken` / `refreshToken` / `expiresAt` are SDK-managed and not
54
+ * read-back-able from the WASM core (held internally for the auto-refresh
55
+ * dance), so they're empty strings on the consumer side — present for
56
+ * shape-compatibility with the prior `@layers/amba-client` `Session`
57
+ * type. Callers who need to introspect should branch on `user` /
58
+ * `Amba.isAuthenticated`.
59
+ */
60
+ interface Session {
61
+ sessionToken: string;
62
+ refreshToken: string;
63
+ user: User;
64
+ expiresAt: string;
65
+ }
66
+ type FilterValue = string | number | boolean | null | unknown[];
67
+ interface ConditionFilter {
68
+ column: string;
69
+ op: string;
70
+ value?: FilterValue;
71
+ }
72
+ interface AndFilter {
73
+ and: Filter[];
74
+ }
75
+ interface OrFilter {
76
+ or: Filter[];
77
+ }
78
+ interface NotFilter {
79
+ not: Filter;
80
+ }
81
+ type Filter = ConditionFilter | AndFilter | OrFilter | NotFilter;
82
+ interface OrderBy {
83
+ column: string;
84
+ direction: "asc" | "desc";
85
+ }
86
+ interface FindOptions {
87
+ filter?: Filter;
88
+ order?: OrderBy[];
89
+ limit?: number;
90
+ cursor?: string;
91
+ select?: string[];
92
+ include_deleted?: boolean;
93
+ }
94
+ interface FindResponse<T> {
95
+ data: T[];
96
+ next_cursor?: string | null;
97
+ has_more: boolean;
98
+ }
99
+ interface MediaAsset {
100
+ id: string;
101
+ bucket: string;
102
+ key: string;
103
+ url: string;
104
+ mime_type: string;
105
+ size_bytes: number;
106
+ width?: number | null;
107
+ height?: number | null;
108
+ retention_days?: number | null;
109
+ created_at: string;
110
+ }
111
+ interface PresignData {
112
+ upload_id: string;
113
+ upload_url: string;
114
+ upload_headers: Array<[string, string]>;
115
+ asset_id: string;
116
+ }
117
+ interface PushToken {
118
+ id: string;
119
+ token: string;
120
+ platform: PushPlatform;
121
+ bundle_id?: string | null;
122
+ created_at: string;
123
+ }
124
+ type EntitlementSource = "revenue_cat" | "app_store" | "play_store" | "stripe" | "promo_code" | "manual";
125
+ interface UserEntitlement {
126
+ id: string;
127
+ name: string;
128
+ is_active: boolean;
129
+ source: EntitlementSource;
130
+ expires_at?: string | null;
131
+ granted_at?: string | null;
132
+ metadata: Record<string, unknown>;
133
+ }
134
+ interface AiMessage {
135
+ role: string;
136
+ content: unknown;
137
+ }
138
+ interface AiMessageRequest {
139
+ prompt_slug: string;
140
+ variables?: Record<string, unknown>;
141
+ messages?: AiMessage[];
142
+ max_tokens?: number;
143
+ temperature?: number;
144
+ enable_prompt_cache?: boolean;
145
+ }
146
+ interface AiUsage {
147
+ input_tokens: number;
148
+ output_tokens: number;
149
+ cache_creation_input_tokens?: number;
150
+ cache_read_input_tokens?: number;
151
+ }
152
+ interface AiMessageResponse {
153
+ content: unknown[];
154
+ usage: AiUsage;
155
+ stop_reason?: string | null;
156
+ model: string;
157
+ }
158
+ /**
159
+ * Resolved remote config returned by `config.fetch()`.
160
+ *
161
+ * Server: `GET /v1/client/config` returns body `{ "data": { key → value, ... } }`
162
+ * plus an `ETag` response header carrying the version stamp. The Rust core
163
+ * lifts the `data` map into `values` and parses the ETag prefix into
164
+ * `version` (see `core/src/config.rs::parse_etag_version`).
165
+ *
166
+ * `version` is `null` when the server didn't send an ETag (e.g. local
167
+ * dev with an empty `config_versions` row).
168
+ */
169
+ interface ConfigBundle {
170
+ version: string | null;
171
+ values: Record<string, unknown>;
172
+ }
173
+ interface FlagAssignment {
174
+ name: string;
175
+ enabled: boolean;
176
+ variant?: string | null;
177
+ payload?: unknown;
178
+ }
179
+ interface Achievement {
180
+ id: string;
181
+ key: string;
182
+ name: string;
183
+ description?: string | null;
184
+ icon_url?: string | null;
185
+ points: number;
186
+ criteria: unknown;
187
+ }
188
+ interface AchievementProgress {
189
+ achievement_id: string;
190
+ key: string;
191
+ progress: number;
192
+ unlocked: boolean;
193
+ unlocked_at?: string | null;
194
+ }
195
+ interface Challenge {
196
+ id: string;
197
+ key: string;
198
+ name: string;
199
+ description?: string | null;
200
+ starts_at: string;
201
+ ends_at: string;
202
+ criteria: unknown;
203
+ reward: unknown;
204
+ }
205
+ interface ChallengeProgress {
206
+ challenge_id: string;
207
+ progress: number;
208
+ completed: boolean;
209
+ claimed: boolean;
210
+ completed_at?: string | null;
211
+ claimed_at?: string | null;
212
+ }
213
+ interface CurrencyBalance {
214
+ currency_id: string;
215
+ key: string;
216
+ balance: number;
217
+ updated_at: string;
218
+ }
219
+ interface CurrencyTransaction {
220
+ id: string;
221
+ currency_id: string;
222
+ delta: number;
223
+ balance_after: number;
224
+ reason?: string | null;
225
+ created_at: string;
226
+ }
227
+ interface InventoryItem {
228
+ id: string;
229
+ catalog_item_id: string;
230
+ sku: string;
231
+ quantity: number;
232
+ acquired_at: string;
233
+ metadata: unknown;
234
+ }
235
+ interface PurchaseRequest {
236
+ sku: string;
237
+ quantity?: number;
238
+ currency_key?: string;
239
+ }
240
+ interface ConsumeRequest {
241
+ item_id: string;
242
+ quantity: number;
243
+ }
244
+ interface Leaderboard {
245
+ id: string;
246
+ key: string;
247
+ name: string;
248
+ period: string;
249
+ direction: string;
250
+ starts_at?: string | null;
251
+ ends_at?: string | null;
252
+ }
253
+ interface LeaderboardEntry {
254
+ rank: number;
255
+ user_id: string;
256
+ display_name?: string | null;
257
+ avatar_url?: string | null;
258
+ score: number;
259
+ }
260
+ interface Store {
261
+ id: string;
262
+ key: string;
263
+ name: string;
264
+ }
265
+ interface PurchaseOption {
266
+ id: string;
267
+ store_id: string;
268
+ sku: string;
269
+ name: string;
270
+ price_cents: number;
271
+ currency: string;
272
+ period?: string | null;
273
+ metadata: unknown;
274
+ }
275
+ interface PurchaseResult {
276
+ id: string;
277
+ user_id: string;
278
+ purchase_option_id: string;
279
+ status: string;
280
+ purchased_at: string;
281
+ receipt: unknown;
282
+ }
283
+ interface XpBalance {
284
+ user_id: string;
285
+ total_xp: number;
286
+ current_level: number;
287
+ xp_into_level: number;
288
+ xp_to_next_level: number;
289
+ updated_at: string;
290
+ /**
291
+ * XP earned in the current rolling window. The window is server-defined
292
+ * via the project's XP rules; the value comes straight from
293
+ * `user_xp.xp_this_period` on the tenant DB. Older servers that don't
294
+ * populate it decode as `0` (Rust core uses `#[serde(default)]`).
295
+ */
296
+ xp_this_period: number;
297
+ }
298
+ interface XpTransaction {
299
+ id: string;
300
+ delta: number;
301
+ reason?: string | null;
302
+ source?: string | null;
303
+ created_at: string;
304
+ }
305
+ interface Streak {
306
+ id: string;
307
+ key: string;
308
+ name: string;
309
+ current_length: number;
310
+ longest_length: number;
311
+ last_qualified_on?: string | null;
312
+ updated_at: string;
313
+ /**
314
+ * Server-computed lifecycle state.
315
+ * - `"active"` — streak is alive and current period not yet qualified
316
+ * - `"qualified_today"` — user already qualified for the current period
317
+ * - `"broken"` — user missed a period; current_length reset to 0
318
+ * - `"frozen"` — a freeze (shield) is protecting the streak from a miss
319
+ *
320
+ * Empty string when decoded against an older server that didn't emit it.
321
+ */
322
+ status: string;
323
+ /**
324
+ * Unused streak-freeze count. Auto-granted by the server every
325
+ * `streak_definitions.freezes_per_n_events` qualifying events, capped
326
+ * at `streak_definitions.max_freezes`.
327
+ */
328
+ freezes_remaining: number;
329
+ }
330
+ interface FeedItem {
331
+ id: string;
332
+ actor_id: string;
333
+ verb: string;
334
+ object_type: string;
335
+ object_id: string;
336
+ target_type?: string | null;
337
+ target_id?: string | null;
338
+ data: unknown;
339
+ created_at: string;
340
+ }
341
+ interface FeedResponse {
342
+ data: FeedItem[];
343
+ next_cursor?: string | null;
344
+ }
345
+ type FriendshipState = "pending" | "accepted" | "blocked" | "declined";
346
+ interface Friendship {
347
+ id: string;
348
+ user_id: string;
349
+ friend_id: string;
350
+ state: FriendshipState;
351
+ created_at: string;
352
+ }
353
+ interface Group {
354
+ id: string;
355
+ name: string;
356
+ description?: string | null;
357
+ avatar_url?: string | null;
358
+ created_by: string;
359
+ member_count: number;
360
+ created_at: string;
361
+ updated_at: string;
362
+ metadata: unknown;
363
+ }
364
+ interface GroupMember {
365
+ group_id: string;
366
+ user_id: string;
367
+ role: string;
368
+ joined_at: string;
369
+ }
370
+ interface GroupCreate {
371
+ name: string;
372
+ description?: string;
373
+ avatar_url?: string;
374
+ metadata?: unknown;
375
+ }
376
+ interface GroupUpdate {
377
+ name?: string;
378
+ description?: string;
379
+ avatar_url?: string;
380
+ metadata?: unknown;
381
+ }
382
+ interface Message {
383
+ id: string;
384
+ conversation_id: string;
385
+ sender_id: string;
386
+ body: string;
387
+ metadata: unknown;
388
+ created_at: string;
389
+ }
390
+ interface Conversation {
391
+ id: string;
392
+ participants: string[];
393
+ last_message?: Message | null;
394
+ created_at: string;
395
+ updated_at: string;
396
+ }
397
+ interface SendMessageRequest {
398
+ conversation_id?: string | null;
399
+ to_user_id?: string | null;
400
+ body: string;
401
+ metadata?: unknown;
402
+ }
403
+ interface Report {
404
+ id: string;
405
+ reporter_id: string;
406
+ target_type: string;
407
+ target_id: string;
408
+ reason: string;
409
+ status: string;
410
+ notes?: string | null;
411
+ created_at: string;
412
+ resolved_at?: string | null;
413
+ }
414
+ interface ReportRequest {
415
+ target_id: string;
416
+ reason: string;
417
+ notes?: string;
418
+ }
419
+ interface ReferralCode {
420
+ id: string;
421
+ code: string;
422
+ owner_id: string;
423
+ uses_count: number;
424
+ max_uses?: number | null;
425
+ expires_at?: string | null;
426
+ created_at: string;
427
+ }
428
+ interface ReferralClaim {
429
+ id: string;
430
+ code_id: string;
431
+ referrer_id: string;
432
+ referee_id: string;
433
+ reward: unknown;
434
+ claimed_at: string;
435
+ }
436
+ interface Review {
437
+ id: string;
438
+ author_id: string;
439
+ target_type: string;
440
+ target_id: string;
441
+ rating: number;
442
+ title?: string | null;
443
+ body?: string | null;
444
+ created_at: string;
445
+ updated_at: string;
446
+ }
447
+ interface ReviewCreate {
448
+ target_type: string;
449
+ target_id: string;
450
+ rating: number;
451
+ title?: string;
452
+ body?: string;
453
+ }
454
+ interface ReviewUpdate {
455
+ rating?: number;
456
+ title?: string;
457
+ body?: string;
458
+ }
459
+ interface Role {
460
+ id: string;
461
+ key: string;
462
+ name: string;
463
+ permissions: string[];
464
+ }
465
+ interface CatalogItem {
466
+ id: string;
467
+ sku: string;
468
+ name: string;
469
+ description?: string | null;
470
+ price_cents?: number | null;
471
+ currency?: string | null;
472
+ metadata: unknown;
473
+ }
474
+ interface ContentItem {
475
+ id: string;
476
+ channel: string;
477
+ title?: string | null;
478
+ body?: string | null;
479
+ data: unknown;
480
+ published_at: string;
481
+ user_state: unknown;
482
+ }
483
+ interface DeepLink {
484
+ id: string;
485
+ url: string;
486
+ short_code: string;
487
+ target_path?: string | null;
488
+ metadata: unknown;
489
+ created_at: string;
490
+ }
491
+ interface DeepLinkCreate {
492
+ target_path: string;
493
+ metadata?: unknown;
494
+ short_code?: string;
495
+ }
496
+ interface OnboardingStatus {
497
+ current_step: string | null;
498
+ completed_steps: string[];
499
+ remaining_steps: string[];
500
+ completed: boolean;
501
+ completed_at?: string | null;
502
+ }
503
+ //#endregion
504
+ //#region src/error.d.ts
505
+ /**
506
+ * Typed error class for the amba SDK + helper that converts arbitrary
507
+ * thrown values (WASM JsError, native Error, plain objects) into a
508
+ * stable `AmbaApiError` instance.
509
+ *
510
+ * Callers can `instanceof`-narrow safely, branch on `.code`, and pull
511
+ * extra payload from `.details` (raw HTTP body, validation field paths,
512
+ * etc.). The wrapper methods on `Amba` wrap every async call in
513
+ * `toAmbaApiError`, so consumers see one error shape regardless of
514
+ * which layer (network, FFI, validation) failed.
515
+ */
516
+ /**
517
+ * Stable error codes surfaced by the SDK. Strings rather than an enum
518
+ * so customers can extend with custom codes by simply throwing
519
+ * `new AmbaApiError("MY_CODE", "...")` without coordinating with this
520
+ * package's TypeScript types.
521
+ */
522
+ type AmbaApiErrorCode = "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "CONFLICT" | "RATE_LIMITED" | "VALIDATION_ERROR" | "NETWORK_ERROR" | "HTTP_ERROR" | "CIRCUIT_OPEN" | "CONSENT_NOT_GRANTED" | "NOT_INITIALIZED" | "INVALID_CONFIG" | "INVALID_ARGUMENT" | "PUSH_PERMISSION_DENIED" | "PUSH_REGISTRATION_FAILED" | "UNKNOWN_ERROR" | (string & {});
523
+ declare class AmbaApiError extends Error {
524
+ readonly code: AmbaApiErrorCode;
525
+ readonly details?: unknown;
526
+ constructor(code: AmbaApiErrorCode, message: string, details?: unknown);
527
+ }
528
+ //#endregion
529
+ //#region src/index.d.ts
530
+ /**
531
+ * Top-level SDK namespace.
532
+ *
533
+ * Stateless from the JS side — all state lives in the WASM core. Calling
534
+ * `Amba.configure()` multiple times replaces the previous instance.
535
+ */
536
+ declare const Amba: {
537
+ /**
538
+ * Initialize the SDK. Must be called once at app start.
539
+ *
540
+ * Internally:
541
+ * 1. Loads the WASM binary (one-time per page).
542
+ * 2. Constructs an AmbaCoreWasm with a bound `fetch`.
543
+ * 3. Seeds an `anonymous_id` from localStorage (if present) or fresh.
544
+ */
545
+ configure: (config: AmbaConfig) => Promise<void>;
546
+ /** Anonymous id — stable per browser. */
547
+ readonly anonymousId: string;
548
+ /** Authenticated user id, if a session is live. */
549
+ readonly appUserId: string | undefined;
550
+ /** Whether a session token is currently held. */
551
+ readonly isAuthenticated: boolean;
552
+ /** Toggle verbose logging at runtime. */
553
+ setDebug: (enabled: boolean) => void;
554
+ /** Track engagement events. */
555
+ events: {
556
+ track: (event: string, properties?: Record<string, unknown>) => Promise<void>;
557
+ };
558
+ /** Authentication flows. */
559
+ auth: {
560
+ signInAnonymously: () => Promise<AuthResult>;
561
+ signInWithEmail: (email: string, password: string) => Promise<AuthResult>;
562
+ signUpWithEmail: (email: string, password: string) => Promise<AuthResult>;
563
+ signInWithSocial: (provider: SocialProvider, idToken: string) => Promise<AuthResult>;
564
+ signOut: (rotateAnonymousId?: boolean) => Promise<void>;
565
+ refresh: () => Promise<AuthResult>;
566
+ me: () => Promise<User>;
567
+ /**
568
+ * Snapshot the current session, or `null` if no session is live.
569
+ * sessionToken/refreshToken/expiresAt come back as empty strings —
570
+ * they're SDK-managed and not read-back-able from the core. Use
571
+ * `Amba.isAuthenticated` if you only need the boolean.
572
+ */
573
+ getSession: () => Promise<Session | null>;
574
+ /**
575
+ * Stable anonymous identifier (synchronous read; the WASM core
576
+ * keeps it in memory). Sync today, async for parity with the
577
+ * RN/native shape where the platform may need to await a
578
+ * persistence read.
579
+ */
580
+ getAnonymousId: () => Promise<string>;
581
+ /**
582
+ * Subscribe to session changes. Fires after every `signIn*`,
583
+ * `signUp*`, `refresh`, and `signOut` call. Returns an
584
+ * unsubscribe function — call it to remove the callback.
585
+ *
586
+ * Does NOT fire an initial snapshot when subscribed; call
587
+ * `getSession()` once after subscribing if you need the
588
+ * current state up front.
589
+ */
590
+ onAuthStateChange: (cb: (session: Session | null) => void) => (() => void);
591
+ };
592
+ /** Typed Postgres CRUD with auto-RLS. */
593
+ collections: {
594
+ find: <T = unknown>(name: string, options?: FindOptions) => Promise<FindResponse<T>>;
595
+ findOne: <T = unknown>(name: string, id: string) => Promise<T>;
596
+ insert: <T = unknown>(name: string, row: Record<string, unknown>) => Promise<T>;
597
+ update: <T = unknown>(name: string, id: string, set: Record<string, unknown>) => Promise<T>;
598
+ delete: (name: string, id: string) => Promise<{
599
+ data: {
600
+ deleted: boolean;
601
+ };
602
+ }>;
603
+ /** Filter DSL helpers — pass into `find({ filter: f })`. */
604
+ where: {
605
+ eq: (column: string, value: FilterValue) => Filter;
606
+ ne: (column: string, value: FilterValue) => Filter;
607
+ gt: (column: string, value: FilterValue) => Filter;
608
+ gte: (column: string, value: FilterValue) => Filter;
609
+ lt: (column: string, value: FilterValue) => Filter;
610
+ lte: (column: string, value: FilterValue) => Filter;
611
+ in: (column: string, values: FilterValue[]) => Filter;
612
+ notIn: (column: string, values: FilterValue[]) => Filter;
613
+ like: (column: string, pattern: string) => Filter;
614
+ ilike: (column: string, pattern: string) => Filter;
615
+ isNull: (column: string) => Filter;
616
+ isNotNull: (column: string) => Filter;
617
+ and: (...filters: Filter[]) => Filter;
618
+ or: (...filters: Filter[]) => Filter;
619
+ not: (filter: Filter) => Filter;
620
+ };
621
+ };
622
+ /** Media uploads + CDN URL helpers. */
623
+ storage: {
624
+ presign: (params: {
625
+ bucket: string;
626
+ filename: string;
627
+ mimeType: string;
628
+ sizeBytes: number;
629
+ retentionDays?: number;
630
+ }) => Promise<PresignData>;
631
+ /**
632
+ * Complete-flow upload: presign → PUT to R2 → commit.
633
+ * Returns the finalized MediaAsset.
634
+ */
635
+ upload: (params: {
636
+ bucket: string;
637
+ file: File | Blob;
638
+ filename?: string;
639
+ retentionDays?: number;
640
+ }) => Promise<MediaAsset>;
641
+ };
642
+ /** Push notifications. */
643
+ push: {
644
+ register: (token: string, platform: PushPlatform, bundleId?: string) => Promise<PushToken>;
645
+ unregister: (token: string) => Promise<void>;
646
+ getTokens: () => Promise<PushToken[]>;
647
+ subscribe: (topic: string) => Promise<void>;
648
+ unsubscribe: (topic: string) => Promise<void>;
649
+ };
650
+ /** RevenueCat/App Store/Stripe entitlements. */
651
+ entitlements: {
652
+ list: () => Promise<UserEntitlement[]>;
653
+ has: (name: string) => Promise<boolean>;
654
+ };
655
+ /** LLM proxy. */
656
+ ai: {
657
+ anthropic: {
658
+ messages: {
659
+ create: (request: AiMessageRequest) => Promise<AiMessageResponse>;
660
+ };
661
+ };
662
+ };
663
+ /** Remote config bundle. */
664
+ config: {
665
+ fetch: () => Promise<ConfigBundle>;
666
+ };
667
+ /** Server-evaluated feature flags. */
668
+ flags: {
669
+ fetch: () => Promise<FlagAssignment[]>;
670
+ };
671
+ /** Achievement definitions + per-user progress. */
672
+ achievements: {
673
+ getAll: () => Promise<Achievement[]>;
674
+ getProgress: () => Promise<AchievementProgress[]>;
675
+ };
676
+ /** Time-bounded challenges with rewards. */
677
+ challenges: {
678
+ getActive: () => Promise<Challenge[]>;
679
+ get: (id: string) => Promise<Challenge>;
680
+ getProgress: (id: string) => Promise<ChallengeProgress>;
681
+ claim: (id: string) => Promise<ChallengeProgress>;
682
+ };
683
+ /** Virtual currency balances + ledger. */
684
+ currencies: {
685
+ getBalance: () => Promise<CurrencyBalance[]>;
686
+ getTransactions: (currencyKey: string) => Promise<CurrencyTransaction[]>;
687
+ };
688
+ /** User inventory items + purchase/consume. */
689
+ inventory: {
690
+ getItems: () => Promise<InventoryItem[]>;
691
+ getItem: (id: string) => Promise<InventoryItem>;
692
+ purchase: (request: PurchaseRequest) => Promise<InventoryItem>;
693
+ consume: (request: ConsumeRequest) => Promise<InventoryItem>;
694
+ };
695
+ /** Score rankings. */
696
+ leaderboards: {
697
+ get: (key: string) => Promise<Leaderboard>;
698
+ getEntries: (key: string, limit?: number) => Promise<LeaderboardEntry[]>;
699
+ getMyRank: (key: string) => Promise<LeaderboardEntry>;
700
+ };
701
+ /** Purchase storefronts. */
702
+ stores: {
703
+ list: () => Promise<Store[]>;
704
+ getPurchaseOptions: (storeKey: string) => Promise<PurchaseOption[]>;
705
+ purchase: (storeKey: string, purchaseOptionId: string, receipt: unknown) => Promise<PurchaseResult>;
706
+ };
707
+ /** Experience points + level system. */
708
+ xp: {
709
+ getBalance: () => Promise<XpBalance>;
710
+ getHistory: (limit?: number) => Promise<XpTransaction[]>;
711
+ claim: (grantKey: string) => Promise<XpTransaction>;
712
+ };
713
+ /** Daily-engagement streaks. */
714
+ streaks: {
715
+ getAll: () => Promise<Streak[]>;
716
+ qualify: (streakKey: string) => Promise<Streak>;
717
+ };
718
+ /** Activity feeds. */
719
+ feeds: {
720
+ getActivity: (feed?: string, cursor?: string) => Promise<FeedResponse>;
721
+ };
722
+ /** Friend graph + block list. */
723
+ friends: {
724
+ getList: () => Promise<Friendship[]>;
725
+ getFriends: () => Promise<Friendship[]>;
726
+ blockUser: (userId: string) => Promise<Friendship>;
727
+ unblockUser: (userId: string) => Promise<void>;
728
+ removeBlock: (friendshipId: string) => Promise<void>;
729
+ };
730
+ /** Multi-user groups. */
731
+ groups: {
732
+ create: (params: GroupCreate) => Promise<Group>;
733
+ get: (id: string) => Promise<Group>;
734
+ update: (id: string, patch: GroupUpdate) => Promise<Group>;
735
+ delete: (id: string) => Promise<void>;
736
+ getMembers: (id: string) => Promise<GroupMember[]>;
737
+ join: (id: string) => Promise<GroupMember>;
738
+ leave: (id: string) => Promise<void>;
739
+ invite: (id: string, userId: string) => Promise<GroupMember>;
740
+ };
741
+ /** User-to-user direct messaging. */
742
+ messaging: {
743
+ getConversations: () => Promise<Conversation[]>;
744
+ getMessage: (id: string) => Promise<Message>;
745
+ sendMessage: (request: SendMessageRequest) => Promise<Message>;
746
+ };
747
+ /** Report users / content for moderation. */
748
+ moderation: {
749
+ reportUser: (request: ReportRequest) => Promise<Report>;
750
+ reportContent: (request: ReportRequest) => Promise<Report>;
751
+ getReportStatus: (id: string) => Promise<Report>;
752
+ };
753
+ /** User reviews of catalog items or other users. */
754
+ reviews: {
755
+ list: (targetType: string, targetId: string) => Promise<Review[]>;
756
+ create: (params: ReviewCreate) => Promise<Review>;
757
+ update: (id: string, patch: ReviewUpdate) => Promise<Review>;
758
+ delete: (id: string) => Promise<void>;
759
+ };
760
+ /** RBAC roles + permission checks. */
761
+ roles: {
762
+ getMyRoles: () => Promise<Role[]>;
763
+ hasPermission: (permission: string) => Promise<boolean>;
764
+ };
765
+ /** Referral codes + claim flow. */
766
+ referrals: {
767
+ getReferralCode: () => Promise<ReferralCode>;
768
+ claimReferral: (code: string) => Promise<ReferralClaim>;
769
+ create: (code?: string, maxUses?: number) => Promise<ReferralCode>;
770
+ };
771
+ /** Read-only product catalog. */
772
+ catalog: {
773
+ list: () => Promise<CatalogItem[]>;
774
+ };
775
+ /** Developer-defined content items (daily quotes, lessons, etc.). */
776
+ content: {
777
+ /**
778
+ * Get today's published item for `channel`. Defaults to `"default"`
779
+ * so single-channel apps can call `Amba.content.getToday()` bare.
780
+ */
781
+ getToday: (channel?: string) => Promise<ContentItem | null>;
782
+ /**
783
+ * Paginated library list for `channel`. `options.limit` caps page size
784
+ * (server default applies when omitted); `options.cursor` is the
785
+ * opaque token returned by a prior response's `next_cursor`.
786
+ */
787
+ getLibrary: (channel?: string, options?: {
788
+ limit?: number;
789
+ cursor?: string;
790
+ }) => Promise<ContentItem[]>;
791
+ getItem: (id: string) => Promise<ContentItem>;
792
+ updateItem: (id: string, state: unknown) => Promise<ContentItem>;
793
+ createItem: (channel: string, item: unknown) => Promise<ContentItem>;
794
+ };
795
+ /** Server-managed deep link records. */
796
+ deepLinks: {
797
+ get: (shortCode: string) => Promise<DeepLink>;
798
+ create: (params: DeepLinkCreate) => Promise<DeepLink>;
799
+ };
800
+ /** Step-by-step user onboarding flow. */
801
+ onboarding: {
802
+ getStatus: () => Promise<OnboardingStatus>;
803
+ nextStep: (payload: unknown) => Promise<OnboardingStatus>;
804
+ skipStep: () => Promise<OnboardingStatus>;
805
+ complete: () => Promise<OnboardingStatus>;
806
+ };
807
+ };
808
+ /** Escape hatch — the raw WASM handle, for namespaces not yet wrapped. */
809
+ declare function getCoreWasm(): AmbaCoreWasm;
810
+ /** Package version stamped at build time. */
811
+ declare const SDK_VERSION = "0.1.0";
812
+ //#endregion
813
+ export { Achievement, AchievementProgress, AiMessage, AiMessageRequest, AiMessageResponse, AiUsage, Amba, AmbaApiError, type AmbaApiErrorCode, AmbaConfig, AndFilter, AuthResult, CatalogItem, Challenge, ChallengeProgress, ConditionFilter, ConfigBundle, ConsumeRequest, ContentItem, Conversation, CurrencyBalance, CurrencyTransaction, DeepLink, DeepLinkCreate, EntitlementSource, FeedItem, FeedResponse, Filter, FilterValue, FindOptions, FindResponse, FlagAssignment, Friendship, FriendshipState, Group, GroupCreate, GroupMember, GroupUpdate, InventoryItem, Leaderboard, LeaderboardEntry, MediaAsset, Message, NotFilter, OnboardingStatus, OrFilter, OrderBy, PresignData, PurchaseOption, PurchaseRequest, PurchaseResult, PushPlatform, PushToken, ReferralClaim, ReferralCode, Report, ReportRequest, Review, ReviewCreate, ReviewUpdate, Role, SDK_VERSION, SendMessageRequest, Session, SocialProvider, Store, Streak, User, UserEntitlement, XpBalance, XpTransaction, getCoreWasm };
814
+ //# sourceMappingURL=index.d.ts.map