@supertokens-plugins/rownd-nodejs 0.3.0-beta.2 → 0.3.0-beta.4

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
@@ -1492,7 +1492,7 @@ function buildRowndSessionClaimPayload(input) {
1492
1492
  const verifiedData = originalRowndUser?.verified_data;
1493
1493
  const authLevel = getEffectiveAuthLevel(
1494
1494
  input.user,
1495
- originalRowndUser?.auth_level,
1495
+ typeof currentPayload.auth_level === "string" ? currentPayload.auth_level : originalRowndUser?.auth_level,
1496
1496
  verifiedData
1497
1497
  );
1498
1498
  const appUserId = getRowndAppUserId(
@@ -1501,7 +1501,7 @@ function buildRowndSessionClaimPayload(input) {
1501
1501
  currentPayload,
1502
1502
  input.metadata
1503
1503
  );
1504
- const isAnonymous = authLevel === GUEST_AUTH_METHOD_ID;
1504
+ const isAnonymous = currentPayload.is_anonymous === true || authLevel === GUEST_AUTH_METHOD_ID || authLevel === ANONYMOUS_AUTH_METHOD_ID;
1505
1505
  const anonymousId = getAnonymousId(input.userId, input.user, input.metadata);
1506
1506
  const isVerifiedUser = authLevel !== "unverified";
1507
1507
  const audience = buildRowndAudience(currentPayload, input.appVariantId);
@@ -1617,6 +1617,9 @@ function hasVerifiedRealLoginMethod(user) {
1617
1617
  });
1618
1618
  }
1619
1619
  function getEffectiveAuthLevel(user, originalAuthLevel, verifiedData) {
1620
+ if (originalAuthLevel === ANONYMOUS_AUTH_METHOD_ID) {
1621
+ return ANONYMOUS_AUTH_METHOD_ID;
1622
+ }
1620
1623
  if (hasVerifiedRealLoginMethod(user)) {
1621
1624
  return "verified";
1622
1625
  }
@@ -1648,13 +1651,9 @@ async function validateRowndToken(token) {
1648
1651
  const tokenInfo = await client.validateToken(token);
1649
1652
  return tokenInfo.user_id;
1650
1653
  }
1651
- async function fetchRowndUserInfo(userId) {
1654
+ async function fetchOptionalRowndUserInfo(userId) {
1652
1655
  const client = getRowndClient();
1653
- const rowndUser = await client.fetchUserInfo({ user_id: userId });
1654
- if (!rowndUser) {
1655
- throw new RowndPluginError("ROWND_USER_NOT_FOUND");
1656
- }
1657
- return rowndUser;
1656
+ return client.fetchUserInfo({ user_id: userId });
1658
1657
  }
1659
1658
 
1660
1659
  // src/supertokens-repository.ts
@@ -2119,6 +2118,7 @@ function handleGuestLogin(deps) {
2119
2118
  assertRowndAppVariantIsConfigured(appVariantId);
2120
2119
  const thirdPartyId = body.authLevel === ANONYMOUS_AUTH_METHOD_ID ? ANONYMOUS_AUTH_METHOD_ID : GUEST_AUTH_METHOD_ID;
2121
2120
  const thirdPartyUserId = thirdPartyId === ANONYMOUS_AUTH_METHOD_ID ? `anon_${(0, import_crypto.randomUUID)()}` : guestId;
2121
+ const authLevel = thirdPartyId === ANONYMOUS_AUTH_METHOD_ID ? ANONYMOUS_AUTH_METHOD_ID : GUEST_AUTH_METHOD_ID;
2122
2122
  const response = await import_thirdparty.default.manuallyCreateOrUpdateUser(
2123
2123
  PUBLIC_TENANT_ID,
2124
2124
  thirdPartyId,
@@ -2140,7 +2140,7 @@ function handleGuestLogin(deps) {
2140
2140
  response.recipeUserId,
2141
2141
  {
2142
2142
  ...buildRowndAudience({}, appVariantId),
2143
- auth_level: GUEST_AUTH_METHOD_ID,
2143
+ auth_level: authLevel,
2144
2144
  is_anonymous: true,
2145
2145
  app_user_id: response.user.id
2146
2146
  },
@@ -2188,9 +2188,15 @@ function handleMigrate(deps) {
2188
2188
  const appVariantId = getRequestedAppVariantIdFromRequest(req);
2189
2189
  assertRowndAppVariantIsConfigured(appVariantId);
2190
2190
  rowndUserId = await validateRowndToken(parsed.token);
2191
+ const rowndUser = await fetchOptionalRowndUserInfo(rowndUserId);
2192
+ if (!rowndUser) {
2193
+ logDebugMessage(
2194
+ `Skipping migration because user does not exist in Rownd. tenantId: ${PUBLIC_TENANT_ID}, rowndUserId: ${rowndUserId}`
2195
+ );
2196
+ return { status: "OK" };
2197
+ }
2191
2198
  user = await import_supertokens_node3.default.getUser(rowndUserId, userContext);
2192
2199
  if (!user) {
2193
- const rowndUser = await fetchRowndUserInfo(rowndUserId);
2194
2200
  const stUserImport = mapRowndUserToSuperTokens(rowndUser);
2195
2201
  try {
2196
2202
  const importedUser = await importUser(
package/dist/index.mjs CHANGED
@@ -1469,7 +1469,7 @@ function buildRowndSessionClaimPayload(input) {
1469
1469
  const verifiedData = originalRowndUser?.verified_data;
1470
1470
  const authLevel = getEffectiveAuthLevel(
1471
1471
  input.user,
1472
- originalRowndUser?.auth_level,
1472
+ typeof currentPayload.auth_level === "string" ? currentPayload.auth_level : originalRowndUser?.auth_level,
1473
1473
  verifiedData
1474
1474
  );
1475
1475
  const appUserId = getRowndAppUserId(
@@ -1478,7 +1478,7 @@ function buildRowndSessionClaimPayload(input) {
1478
1478
  currentPayload,
1479
1479
  input.metadata
1480
1480
  );
1481
- const isAnonymous = authLevel === GUEST_AUTH_METHOD_ID;
1481
+ const isAnonymous = currentPayload.is_anonymous === true || authLevel === GUEST_AUTH_METHOD_ID || authLevel === ANONYMOUS_AUTH_METHOD_ID;
1482
1482
  const anonymousId = getAnonymousId(input.userId, input.user, input.metadata);
1483
1483
  const isVerifiedUser = authLevel !== "unverified";
1484
1484
  const audience = buildRowndAudience(currentPayload, input.appVariantId);
@@ -1594,6 +1594,9 @@ function hasVerifiedRealLoginMethod(user) {
1594
1594
  });
1595
1595
  }
1596
1596
  function getEffectiveAuthLevel(user, originalAuthLevel, verifiedData) {
1597
+ if (originalAuthLevel === ANONYMOUS_AUTH_METHOD_ID) {
1598
+ return ANONYMOUS_AUTH_METHOD_ID;
1599
+ }
1597
1600
  if (hasVerifiedRealLoginMethod(user)) {
1598
1601
  return "verified";
1599
1602
  }
@@ -1625,13 +1628,9 @@ async function validateRowndToken(token) {
1625
1628
  const tokenInfo = await client.validateToken(token);
1626
1629
  return tokenInfo.user_id;
1627
1630
  }
1628
- async function fetchRowndUserInfo(userId) {
1631
+ async function fetchOptionalRowndUserInfo(userId) {
1629
1632
  const client = getRowndClient();
1630
- const rowndUser = await client.fetchUserInfo({ user_id: userId });
1631
- if (!rowndUser) {
1632
- throw new RowndPluginError("ROWND_USER_NOT_FOUND");
1633
- }
1634
- return rowndUser;
1633
+ return client.fetchUserInfo({ user_id: userId });
1635
1634
  }
1636
1635
 
1637
1636
  // src/supertokens-repository.ts
@@ -2096,6 +2095,7 @@ function handleGuestLogin(deps) {
2096
2095
  assertRowndAppVariantIsConfigured(appVariantId);
2097
2096
  const thirdPartyId = body.authLevel === ANONYMOUS_AUTH_METHOD_ID ? ANONYMOUS_AUTH_METHOD_ID : GUEST_AUTH_METHOD_ID;
2098
2097
  const thirdPartyUserId = thirdPartyId === ANONYMOUS_AUTH_METHOD_ID ? `anon_${randomUUID()}` : guestId;
2098
+ const authLevel = thirdPartyId === ANONYMOUS_AUTH_METHOD_ID ? ANONYMOUS_AUTH_METHOD_ID : GUEST_AUTH_METHOD_ID;
2099
2099
  const response = await ThirdParty.manuallyCreateOrUpdateUser(
2100
2100
  PUBLIC_TENANT_ID,
2101
2101
  thirdPartyId,
@@ -2117,7 +2117,7 @@ function handleGuestLogin(deps) {
2117
2117
  response.recipeUserId,
2118
2118
  {
2119
2119
  ...buildRowndAudience({}, appVariantId),
2120
- auth_level: GUEST_AUTH_METHOD_ID,
2120
+ auth_level: authLevel,
2121
2121
  is_anonymous: true,
2122
2122
  app_user_id: response.user.id
2123
2123
  },
@@ -2165,9 +2165,15 @@ function handleMigrate(deps) {
2165
2165
  const appVariantId = getRequestedAppVariantIdFromRequest(req);
2166
2166
  assertRowndAppVariantIsConfigured(appVariantId);
2167
2167
  rowndUserId = await validateRowndToken(parsed.token);
2168
+ const rowndUser = await fetchOptionalRowndUserInfo(rowndUserId);
2169
+ if (!rowndUser) {
2170
+ logDebugMessage(
2171
+ `Skipping migration because user does not exist in Rownd. tenantId: ${PUBLIC_TENANT_ID}, rowndUserId: ${rowndUserId}`
2172
+ );
2173
+ return { status: "OK" };
2174
+ }
2168
2175
  user = await SuperTokens3.getUser(rowndUserId, userContext);
2169
2176
  if (!user) {
2170
- const rowndUser = await fetchRowndUserInfo(rowndUserId);
2171
2177
  const stUserImport = mapRowndUserToSuperTokens(rowndUser);
2172
2178
  try {
2173
2179
  const importedUser = await importUser(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supertokens-plugins/rownd-nodejs",
3
- "version": "0.3.0-beta.2",
3
+ "version": "0.3.0-beta.4",
4
4
  "description": "Rownd User Migration Plugin for SuperTokens",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",