@layers/amba-react-native 4.0.5 → 4.0.6

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.cjs CHANGED
@@ -1150,7 +1150,7 @@ function delay(ms) {
1150
1150
  //#endregion
1151
1151
  //#region src/index.ts
1152
1152
  /** SDK semver — burned in at build time. Bump alongside package.json. */
1153
- const SDK_VERSION = "4.0.5";
1153
+ const SDK_VERSION = "4.0.6";
1154
1154
  /**
1155
1155
  * Default host that serves deployed functions. `Amba.functions.invoke(name)`
1156
1156
  * targets `https://<projectId>.<DEFAULT_FUNCTIONS_HOST>/<name>` unless a
@@ -1202,6 +1202,58 @@ function notifyAuthSubscribers(session) {
1202
1202
  if (typeof console !== "undefined") console.error("[amba] onAuthStateChange callback threw", err);
1203
1203
  }
1204
1204
  }
1205
+ function normalizeAuthProviderNames(value) {
1206
+ let normalized = value;
1207
+ if (typeof normalized === "string") {
1208
+ const trimmed = normalized.trim();
1209
+ if (trimmed === "") return [];
1210
+ try {
1211
+ normalized = JSON.parse(trimmed);
1212
+ } catch {
1213
+ return [normalized];
1214
+ }
1215
+ }
1216
+ if (!Array.isArray(normalized)) {
1217
+ if (normalized && typeof normalized === "object") {
1218
+ const provider = normalized.provider;
1219
+ return typeof provider === "string" ? [provider] : [];
1220
+ }
1221
+ return [];
1222
+ }
1223
+ return normalized.map((entry) => {
1224
+ if (typeof entry === "string") {
1225
+ const trimmed = entry.trim();
1226
+ if (trimmed === "") return null;
1227
+ try {
1228
+ const parsed = JSON.parse(trimmed);
1229
+ if (parsed && typeof parsed === "object") {
1230
+ const provider = parsed.provider;
1231
+ return typeof provider === "string" ? provider : null;
1232
+ }
1233
+ } catch {
1234
+ return entry;
1235
+ }
1236
+ return entry;
1237
+ }
1238
+ if (entry && typeof entry === "object") {
1239
+ const provider = entry.provider;
1240
+ return typeof provider === "string" ? provider : null;
1241
+ }
1242
+ return null;
1243
+ }).filter((provider) => provider !== null);
1244
+ }
1245
+ function normalizeUserAuthProviders(user) {
1246
+ return {
1247
+ ...user,
1248
+ auth_providers: normalizeAuthProviderNames(user.auth_providers)
1249
+ };
1250
+ }
1251
+ function normalizeAuthResult(result) {
1252
+ return {
1253
+ ...result,
1254
+ user: normalizeUserAuthProviders(result.user)
1255
+ };
1256
+ }
1205
1257
  async function notifyFromAuthResult(result) {
1206
1258
  notifyAuthSubscribers(snapshotSession(result.user));
1207
1259
  }
@@ -1218,7 +1270,7 @@ async function persistAuthResult(state_, result) {
1218
1270
  });
1219
1271
  }
1220
1272
  async function postAuth(state_, path, body) {
1221
- const result = (await state_.http.post(path, body)).data;
1273
+ const result = normalizeAuthResult((await state_.http.post(path, body)).data);
1222
1274
  await persistAuthResult(state_, result);
1223
1275
  await notifyFromAuthResult(result);
1224
1276
  return result;
@@ -1250,7 +1302,7 @@ async function ensureAnonymousSession(state_) {
1250
1302
  * Existing session tokens stay untouched.
1251
1303
  */
1252
1304
  async function postUserNoRotate(state_, path, body) {
1253
- return (await state_.http.post(path, body)).data.user;
1305
+ return normalizeUserAuthProviders((await state_.http.post(path, body)).data.user);
1254
1306
  }
1255
1307
  async function unlinkProvider(provider) {
1256
1308
  const s = getState();
@@ -1666,12 +1718,12 @@ const Amba = {
1666
1718
  me: async () => {
1667
1719
  const s = getState();
1668
1720
  if (!s.identity.getSessionToken()) throw new AmbaApiError("UNAUTHORIZED", "no active session — call signIn* first");
1669
- return (await s.http.get(P.authMe)).data;
1721
+ return normalizeUserAuthProviders((await s.http.get(P.authMe)).data);
1670
1722
  },
1671
1723
  getSession: async () => {
1672
1724
  const s = getState();
1673
1725
  if (!s.identity.isAuthenticated()) return null;
1674
- return snapshotSession((await s.http.get(P.authMe)).data);
1726
+ return snapshotSession(normalizeUserAuthProviders((await s.http.get(P.authMe)).data));
1675
1727
  },
1676
1728
  getAnonymousId: async () => {
1677
1729
  return getState().identity.getAnonymousId();
@@ -1688,7 +1740,7 @@ const Amba = {
1688
1740
  const s = getState();
1689
1741
  if (!s.identity.getSessionToken()) throw new AmbaApiError("UNAUTHORIZED", "no active session — call signIn* first");
1690
1742
  const path = userId === void 0 || userId === null || userId === "" ? P.usersMe : `${P.users}/${encodePathSegment(userId)}`;
1691
- return (await s.http.get(path)).data;
1743
+ return normalizeUserAuthProviders((await s.http.get(path)).data);
1692
1744
  },
1693
1745
  update: ((arg1, arg2) => {
1694
1746
  const s = getState();
@@ -1696,7 +1748,7 @@ const Amba = {
1696
1748
  const isById = typeof arg1 === "string";
1697
1749
  const patch = isById ? arg2 ?? {} : arg1;
1698
1750
  const path = isById ? `${P.users}/${encodePathSegment(arg1)}` : `${P.users}/me`;
1699
- return s.http.patch(path, patch).then((env) => env.data);
1751
+ return s.http.patch(path, patch).then((env) => normalizeUserAuthProviders(env.data));
1700
1752
  })
1701
1753
  },
1702
1754
  sessions: {