@layers/amba-react-native 4.0.4 → 4.0.5

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.js CHANGED
@@ -830,6 +830,18 @@ const notifications = {
830
830
  //#region src/realtime.ts
831
831
  const INITIAL_BACKOFF_MS = 500;
832
832
  const MAX_BACKOFF_MS = 15e3;
833
+ const DEFAULT_API_URL = "https://api.amba.dev";
834
+ const DEFAULT_REALTIME_URL = "https://realtime.amba.host";
835
+ /**
836
+ * Resolve the base URL for live-update connections. Long-lived streams are
837
+ * served from a dedicated realtime host (no request-duration ceiling), so
838
+ * when the SDK points at the default production API the stream connects
839
+ * there instead. Any custom `apiUrl` (dev, staging, self-hosted, proxy)
840
+ * keeps live updates on that same origin — override semantics unchanged.
841
+ */
842
+ function resolveRealtimeBaseUrl(baseUrl) {
843
+ return baseUrl.replace(/\/+$/, "") === DEFAULT_API_URL ? DEFAULT_REALTIME_URL : baseUrl;
844
+ }
833
845
  /**
834
846
  * Builder returned by `Amba.collection(name)`. Chain `.where(...)` to
835
847
  * narrow, then `.subscribe(cb)` to start streaming.
@@ -853,7 +865,7 @@ var CollectionSubscription = class {
853
865
  if (!this.ctx.authHeaders()) throw new Error("Amba.collection().subscribe() requires an authenticated session — call Amba.auth.signIn* first.");
854
866
  const qs = Object.keys(this.filters).length > 0 ? `?where=${encodeURIComponent(JSON.stringify(this.filters))}` : "";
855
867
  return openStream({
856
- url: `${this.ctx.baseUrl}/v1/client/realtime/collections/${encodeURIComponent(this.name)}${qs}`,
868
+ url: `${resolveRealtimeBaseUrl(this.ctx.baseUrl)}/v1/client/realtime/collections/${encodeURIComponent(this.name)}${qs}`,
857
869
  authHeaders: this.ctx.authHeaders,
858
870
  onChange: cb,
859
871
  options,
@@ -877,7 +889,7 @@ var ConversationSubscription = class {
877
889
  subscribe(cb, options = {}) {
878
890
  if (!this.ctx.authHeaders()) throw new Error("Amba.messaging.conversation().subscribe() requires an authenticated session — call Amba.auth.signIn* first.");
879
891
  return openStream({
880
- url: `${this.ctx.baseUrl}/v1/client/realtime/conversations/${encodeURIComponent(this.conversationId)}`,
892
+ url: `${resolveRealtimeBaseUrl(this.ctx.baseUrl)}/v1/client/realtime/conversations/${encodeURIComponent(this.conversationId)}`,
881
893
  authHeaders: this.ctx.authHeaders,
882
894
  onChange: cb,
883
895
  options,
@@ -901,7 +913,7 @@ var GamificationSubscription = class {
901
913
  subscribe(cb, options = {}) {
902
914
  if (!this.ctx.authHeaders()) throw new Error("Amba.gamification.subscribe() requires an authenticated session — call Amba.auth.signIn* first.");
903
915
  return openStream({
904
- url: `${this.ctx.baseUrl}/v1/client/realtime/gamification`,
916
+ url: `${resolveRealtimeBaseUrl(this.ctx.baseUrl)}/v1/client/realtime/gamification`,
905
917
  authHeaders: this.ctx.authHeaders,
906
918
  onChange: cb,
907
919
  options,
@@ -1137,7 +1149,7 @@ function delay(ms) {
1137
1149
  //#endregion
1138
1150
  //#region src/index.ts
1139
1151
  /** SDK semver — burned in at build time. Bump alongside package.json. */
1140
- const SDK_VERSION = "4.0.4";
1152
+ const SDK_VERSION = "4.0.5";
1141
1153
  /**
1142
1154
  * Default host that serves deployed functions. `Amba.functions.invoke(name)`
1143
1155
  * targets `https://<projectId>.<DEFAULT_FUNCTIONS_HOST>/<name>` unless a
@@ -1297,6 +1309,8 @@ const P = {
1297
1309
  pushSubscribe: "/v1/client/push/subscribe",
1298
1310
  pushUnsubscribe: "/v1/client/push/unsubscribe",
1299
1311
  entitlements: "/v1/client/entitlements",
1312
+ entitlementsRestore: "/v1/client/entitlements/restore",
1313
+ offerings: "/v1/client/offerings",
1300
1314
  aiAnthropic: "/v1/client/ai/anthropic/messages",
1301
1315
  config: "/v1/client/config",
1302
1316
  flags: "/v1/client/flags",
@@ -1959,8 +1973,14 @@ const Amba = {
1959
1973
  },
1960
1974
  has: async (entitlementId) => {
1961
1975
  return (await getState().http.get(P.entitlements, { active_only: "true" })).data.some((e) => e.entitlement_id === entitlementId && e.is_active);
1976
+ },
1977
+ restore: async () => {
1978
+ return (await getState().http.post(P.entitlementsRestore, {})).data;
1962
1979
  }
1963
1980
  },
1981
+ offerings: async (offeringId) => {
1982
+ return (await getState().http.get(P.offerings, offeringId ? { offering_id: offeringId } : void 0)).data;
1983
+ },
1964
1984
  ai: { anthropic: { messages: { create: async (request) => {
1965
1985
  const env = await getState().http.post(P.aiAnthropic, request);
1966
1986
  if (!env || typeof env !== "object" || env.data === void 0) throw new AmbaApiError("MALFORMED_RESPONSE", "AI response was not wrapped in the expected { data } envelope", env);