@layers/amba-web 4.0.5 → 4.0.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.
@@ -38,6 +38,17 @@ interface AmbaConfig {
38
38
  debug?: boolean;
39
39
  /** Override the localStorage key prefix. Defaults to `"amba"`. */
40
40
  storagePrefix?: string;
41
+ /**
42
+ * Advanced: explicit URL or RequestInfo for the @layers/amba-core WASM file.
43
+ * Browser bundlers should not need this; the browser entry supplies a
44
+ * bundler-safe core runtime automatically.
45
+ */
46
+ wasmUrl?: RequestInfo | URL;
47
+ /**
48
+ * Advanced: explicit compiled module, response, or bytes for the WASM core.
49
+ * Mutually exclusive with `wasmUrl`.
50
+ */
51
+ wasmModule?: Response | BufferSource | WebAssembly.Module;
41
52
  }
42
53
  type SocialProvider = "apple" | "google";
43
54
  type PushPlatform = "apns" | "fcm" | "web";
@@ -116,7 +127,7 @@ interface OrderBy {
116
127
  }
117
128
  /**
118
129
  * Eager-load related rows from another collection in the same `find` call,
119
- * avoiding an N+1 round-trip per base row. Single-level (MVP).
130
+ * avoiding an N+1 round-trip per base row.
120
131
  *
121
132
  * belongs-to — each base row's `localKey` column points at the related row:
122
133
  * { collection: "novels", localKey: "novel_id", as: "novel", single: true }
@@ -145,6 +156,24 @@ interface IncludeClause {
145
156
  single?: boolean;
146
157
  /** has-many only: cap related rows per base row (default 100, max 1000). */
147
158
  limit?: number;
159
+ /**
160
+ * Filtered include — an extra predicate on the related rows, in the
161
+ * server's where-DSL shape (`{ status: "published" }`,
162
+ * `{ score: { gte: 10 } }`). The target collection's own read policy +
163
+ * soft-delete still apply.
164
+ */
165
+ where?: Record<string, unknown>;
166
+ /**
167
+ * Projection on the included rows — only these columns are returned
168
+ * (join keys are handled internally).
169
+ */
170
+ select?: string[];
171
+ /**
172
+ * Nested include — eager-load relations OF the included rows
173
+ * (e.g. novels → chapters → comments). Max depth 3; max 10 clauses
174
+ * total per find.
175
+ */
176
+ include?: IncludeClause[];
148
177
  }
149
178
  interface FindOptions {
150
179
  filter?: Filter;
@@ -2402,7 +2431,7 @@ declare function getCoreWasm(): AmbaCoreWasm;
2402
2431
  * `verify-sdk-version-coherence` GH action gates every publish on the
2403
2432
  * pair agreeing (and matching the `web-v<X.Y.Z>` tag when tag-triggered).
2404
2433
  */
2405
- declare const SDK_VERSION = "4.0.5";
2434
+ declare const SDK_VERSION = "4.0.7";
2406
2435
  //#endregion
2407
2436
  export { Achievement, AchievementProgress, AiContentBlock, AiImageInput, AiMessage, AiMessageRequest, AiMessageResponse, type AiStreamDelta, type AiStreamDone, type AiStreamEvent, type AiStreamOptions, AiUsage, Amba, AmbaApiError, type AmbaApiErrorCode, AmbaConfig, AndFilter, AppSession, AuthResult, CatalogItem, Challenge, ChallengeProgress, CollectionSubscription, ConditionFilter, ConfigBundle, ConsumeRequest, ContentItem, Conversation, ConversationParticipant, ConversationSubscription, ConversationType, CreateConversationRequest, CurrencyBalance, CurrencyTransaction, DeepLink, DeepLinkCreate, DeleteManyResult, DiagnosticsEnvironment, EntitlementPeriodType, EntitlementStore, EventExplainResult, ExplainMatchedRule, FeedItem, FeedResponse, Filter, FilterValue, FindOptions, FindResponse, FlagAssignment, type FlushResult, Friendship, FriendshipState, type GamificationChange, type GamificationKind, GamificationSubscription, Group, GroupCreate, GroupMember, GroupUpdate, IncludeClause, InventoryItem, InvokeOptions, type KvStore, Leaderboard, LeaderboardEntry, LeagueCohort, LeagueCohortMember, LeagueCohortView, LeagueMembership, LeagueTier, LinkedIdentifier, ListMessagesOptions, LocalNotificationHandle, LocalNotificationTrigger, type LocalNotificationsNamespace, MarkReadResult, MediaAsset, MediaCatalog, MediaCatalogItem, MediaListResponse, Message, type MessageChange, MessageType, NearestOptions, NearestResponse, NotFilter, Offering, OfferingPackage, OfferingProduct, OfferingsResult, OnboardingStatus, OrFilter, OrderBy, type OutboxOp, type OutboxOpKind, PingResult, PresignData, PullChangesCursor, PullChangesResult, PurchaseOption, PurchaseRequest, PurchaseResult, PushChangesResult, PushPlatform, PushToken, type RealtimeChange, ReferralClaim, ReferralCode, Report, ReportRequest, RestoreResult, Review, ReviewCreate, ReviewUpdate, Role, type RowChangeOp, SDK_VERSION, ScheduleLocalNotificationInput, ScheduledLocalNotification, SendMessageRequest, Session, SocialProvider, Store, Streak, type SubscribeOptions, SyncChange, SyncConflict, TransactionOp, TransactionOpResult, type Unsubscribe, UpsertOptions, User, UserEntitlement, XpBalance, XpTransaction, getCoreWasm, withOptimistic };
2408
2437
  //# sourceMappingURL=index.d.ts.map
package/dist-rn/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import init, { AmbaCoreWasm } from "@layers/amba-core";
2
-
3
1
  //#region src/storage-adapter.ts
4
2
  /**
5
3
  * Browser localStorage adapter for SDK identity persistence.
@@ -131,14 +129,13 @@ var AmbaApiError = class extends Error {
131
129
  }
132
130
  };
133
131
  /**
134
- * Best-effort: pull a stable error code out of a Rust `AmbaError`
135
- * Display string. Used by `toAmbaApiError` when the underlying thrown
136
- * value is a generic `Error` produced by `wasm-bindgen`'s `JsError::new`.
132
+ * Best-effort: pull a stable error code out of an `AmbaError` display
133
+ * string. Used by `toAmbaApiError` when the underlying thrown value is a
134
+ * generic `Error` produced by the SDK core.
137
135
  *
138
- * Keep in sync with `sdks/core/src/error.rs::AmbaError`'s `#[error]`
139
- * format strings — but the parser falls back to UNKNOWN_ERROR for any
140
- * pattern it doesn't recognize, so a stale match list isn't a footgun,
141
- * just a quality-of-life regression.
136
+ * Keep in sync with the SDK core's `AmbaError` format strings — but the
137
+ * parser falls back to UNKNOWN_ERROR for any pattern it doesn't recognize,
138
+ * so a stale match list isn't a footgun, just a quality-of-life regression.
142
139
  */
143
140
  function codeFromMessage(message) {
144
141
  if (message.startsWith("Unauthorized")) return "UNAUTHORIZED";
@@ -181,6 +178,18 @@ function toAmbaApiError(err) {
181
178
  //#region src/realtime.ts
182
179
  const INITIAL_BACKOFF_MS = 500;
183
180
  const MAX_BACKOFF_MS = 15e3;
181
+ const DEFAULT_API_URL$1 = "https://api.amba.dev";
182
+ const DEFAULT_REALTIME_URL = "https://realtime.amba.host";
183
+ /**
184
+ * Resolve the base URL for live-update connections. Long-lived streams are
185
+ * served from a dedicated realtime host (no request-duration ceiling), so
186
+ * when the SDK points at the default production API the stream connects
187
+ * there instead. Any custom `apiUrl` (dev, staging, self-hosted, proxy)
188
+ * keeps live updates on that same origin — override semantics unchanged.
189
+ */
190
+ function resolveRealtimeBaseUrl(baseUrl) {
191
+ return baseUrl.replace(/\/+$/, "") === DEFAULT_API_URL$1 ? DEFAULT_REALTIME_URL : baseUrl;
192
+ }
184
193
  /**
185
194
  * Builder returned by `Amba.collection(name)`. Chain `.where(...)` to
186
195
  * narrow, then `.subscribe(cb)` to start streaming.
@@ -204,7 +213,7 @@ var CollectionSubscription = class {
204
213
  if (!this.ctx.authHeaders()) throw new Error("Amba.collection().subscribe() requires an authenticated session — call Amba.auth.signIn*/verify* first.");
205
214
  const qs = Object.keys(this.filters).length > 0 ? `?where=${encodeURIComponent(JSON.stringify(this.filters))}` : "";
206
215
  return openStream({
207
- url: `${this.ctx.baseUrl}/v1/client/realtime/collections/${encodeURIComponent(this.name)}${qs}`,
216
+ url: `${resolveRealtimeBaseUrl(this.ctx.baseUrl)}/v1/client/realtime/collections/${encodeURIComponent(this.name)}${qs}`,
208
217
  authHeaders: this.ctx.authHeaders,
209
218
  onChange: cb,
210
219
  options
@@ -325,7 +334,7 @@ var ConversationSubscription = class {
325
334
  subscribe(cb, options = {}) {
326
335
  if (!this.ctx.authHeaders()) throw new Error("Amba.messaging.conversation().subscribe() requires an authenticated session — call Amba.auth.signIn*/verify* first.");
327
336
  return openStream({
328
- url: `${this.ctx.baseUrl}/v1/client/realtime/conversations/${encodeURIComponent(this.conversationId)}`,
337
+ url: `${resolveRealtimeBaseUrl(this.ctx.baseUrl)}/v1/client/realtime/conversations/${encodeURIComponent(this.conversationId)}`,
329
338
  authHeaders: this.ctx.authHeaders,
330
339
  onChange: cb,
331
340
  options
@@ -354,7 +363,7 @@ var GamificationSubscription = class {
354
363
  subscribe(cb, options = {}) {
355
364
  if (!this.ctx.authHeaders()) throw new Error("Amba.gamification.subscribe() requires an authenticated session — call Amba.auth.signIn*/verify* first.");
356
365
  return openGamificationStream({
357
- url: `${this.ctx.baseUrl}/v1/client/realtime/gamification`,
366
+ url: `${resolveRealtimeBaseUrl(this.ctx.baseUrl)}/v1/client/realtime/gamification`,
358
367
  authHeaders: this.ctx.authHeaders,
359
368
  onChange: cb,
360
369
  options
@@ -1305,6 +1314,26 @@ const notifications = {
1305
1314
  }
1306
1315
  };
1307
1316
 
1317
+ //#endregion
1318
+ //#region src/wasm-loader.ts
1319
+ let coreInit;
1320
+ let coreWasmClass;
1321
+ function setCoreRuntime(init, wasmClass) {
1322
+ coreInit = init;
1323
+ coreWasmClass = wasmClass;
1324
+ }
1325
+ async function getCoreRuntime() {
1326
+ if (coreInit === void 0 || coreWasmClass === void 0) {
1327
+ const core = await import("@layers/amba-core");
1328
+ setCoreRuntime(core.default, core.AmbaCoreWasm);
1329
+ }
1330
+ if (coreInit === void 0 || coreWasmClass === void 0) throw new Error("Amba.configure: core WASM runtime failed to load");
1331
+ return {
1332
+ initCore: coreInit,
1333
+ wasmClass: coreWasmClass
1334
+ };
1335
+ }
1336
+
1308
1337
  //#endregion
1309
1338
  //#region src/index.ts
1310
1339
  const DEFAULT_API_URL = "https://api.amba.dev";
@@ -1622,12 +1651,19 @@ const Amba = {
1622
1651
  configure: async (config) => {
1623
1652
  if (!config.projectId || config.projectId.trim() === "") throw new Error("Amba.configure: projectId is required");
1624
1653
  if (!config.clientKey || config.clientKey.trim() === "") throw new Error("Amba.configure: clientKey is required");
1625
- await init(); // Hermes-stripped Node-init block (DX-15) — see scripts/build-rn.mjs
1654
+ if (config.wasmUrl !== void 0 && config.wasmModule !== void 0) throw new Error("Amba.configure: pass only one of wasmUrl or wasmModule");
1655
+ else {
1656
+ const { initCore } = await getCoreRuntime();
1657
+ const explicitWasmInput = config.wasmModule ?? config.wasmUrl;
1658
+ if (explicitWasmInput !== void 0) await initCore({ module_or_path: explicitWasmInput });
1659
+ else await initCore(); // Hermes-stripped Node-init block (DX-15) — see scripts/build-rn.mjs
1660
+ }
1626
1661
  const persistence = new LocalStoragePersistence(config.storagePrefix ?? "amba");
1627
1662
  persistence.hydrate();
1628
1663
  let nextCore;
1629
1664
  try {
1630
- nextCore = AmbaCoreWasm.init(encodeJson({
1665
+ const { wasmClass } = await getCoreRuntime();
1666
+ nextCore = wasmClass.init(encodeJson({
1631
1667
  api_key: config.clientKey,
1632
1668
  base_url: config.apiUrl,
1633
1669
  project_id: config.projectId,
@@ -2391,7 +2427,7 @@ function getCoreWasm() {
2391
2427
  * `verify-sdk-version-coherence` GH action gates every publish on the
2392
2428
  * pair agreeing (and matching the `web-v<X.Y.Z>` tag when tag-triggered).
2393
2429
  */
2394
- const SDK_VERSION = "4.0.5";
2430
+ const SDK_VERSION = "4.0.7";
2395
2431
 
2396
2432
  //#endregion
2397
2433
  export { Amba, AmbaApiError, CollectionSubscription, ConversationSubscription, GamificationSubscription, SDK_VERSION, getCoreWasm, withOptimistic };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layers/amba-web",
3
- "version": "4.0.5",
3
+ "version": "4.0.7",
4
4
  "description": "amba SDK for browser apps — full SDK 4.0 surface (34 modules: auth + magic link, users, sessions, sync, collections + vector search, storage + list/delete/download, push, entitlements, flags, config, deep links, onboarding, content, messaging, friends, groups, feeds, reviews, moderation, roles, referrals, achievements, xp, streaks, challenges, leaderboards, leagues, currencies, inventory, stores, catalog, ai, diagnostics).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -10,7 +10,7 @@
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "react-native": "./dist-rn/index.js",
13
- "browser": "./dist/index.js",
13
+ "browser": "./dist/index.browser.js",
14
14
  "import": "./dist/index.js",
15
15
  "default": "./dist/index.js"
16
16
  }
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "sideEffects": false,
34
34
  "dependencies": {
35
- "@layers/amba-core": "^4.0.5"
35
+ "@layers/amba-core": "^4.0.7"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^22.13.14",