@block-auth.io/core 0.12.0 → 0.13.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.
package/dist/index.cjs CHANGED
@@ -1574,13 +1574,27 @@ var toTxnDataParam = (raw) => {
1574
1574
  if (!raw || typeof raw.slug !== "string") return null;
1575
1575
  if (!TXN_DATA_MODES.includes(raw.mode)) return null;
1576
1576
  if (!TXN_DATA_STATUSES.includes(raw.status)) return null;
1577
- return {
1577
+ const param = {
1578
1578
  slug: raw.slug,
1579
1579
  mode: raw.mode,
1580
1580
  status: raw.status,
1581
1581
  value: typeof raw.value === "string" ? raw.value : null
1582
1582
  };
1583
+ if (Array.isArray(raw.emails)) {
1584
+ param.emails = raw.emails.filter(isTxnDataEmail).map((email) => ({
1585
+ id: email.id,
1586
+ label: typeof email.label === "string" ? email.label : "",
1587
+ email: email.email,
1588
+ isDefault: email.isDefault === true,
1589
+ ...typeof email.verified === "boolean" && { verified: email.verified }
1590
+ }));
1591
+ param.selectedEmailId = typeof raw.selectedEmailId === "number" ? raw.selectedEmailId : null;
1592
+ param.emailsMax = typeof raw.emailsMax === "number" ? raw.emailsMax : 0;
1593
+ param.emailsManageUrl = typeof raw.emailsManageUrl === "string" && /^https?:\/\//i.test(raw.emailsManageUrl) ? raw.emailsManageUrl : null;
1594
+ }
1595
+ return param;
1583
1596
  };
1597
+ var isTxnDataEmail = (raw) => !!raw && typeof raw.id === "number" && typeof raw.email === "string";
1584
1598
  function requestSignin(args) {
1585
1599
  const { wsc, token, url, service, apiKey, sessionId } = args;
1586
1600
  wsc.emit("user:txns:create", { token, url, service, apiKey, sessionId });
@@ -1600,6 +1614,7 @@ function acceptTxn(args) {
1600
1614
  userParams,
1601
1615
  grantedParams,
1602
1616
  revokedParams,
1617
+ sharedEmailId,
1603
1618
  sessionId
1604
1619
  } = args;
1605
1620
  wsc.emit("provider:signin", {
@@ -1610,6 +1625,7 @@ function acceptTxn(args) {
1610
1625
  userParams: userParams ?? {},
1611
1626
  grantedParams: grantedParams ?? [],
1612
1627
  revokedParams: revokedParams ?? [],
1628
+ sharedEmailId,
1613
1629
  sessionId
1614
1630
  });
1615
1631
  }
@@ -2635,6 +2651,7 @@ function createBlockAuthClient(config3) {
2635
2651
  userParams: opts.userParams,
2636
2652
  grantedParams: opts.grantedParams,
2637
2653
  revokedParams: opts.revokedParams,
2654
+ sharedEmailId: opts.sharedEmailId,
2638
2655
  sessionId: browserBase.getDeviceSessionId()
2639
2656
  }),
2640
2657
  dataRequest: (txnId) => requestTxnData({
@@ -2920,6 +2937,21 @@ var EMPTY_SOLICITED_DATA_FORM = {
2920
2937
  shared: {},
2921
2938
  saved: {}
2922
2939
  };
2940
+ var EMAIL_SLUG = "users-email";
2941
+ var isSolicitedEmailSelectable = (email) => email.verified !== false;
2942
+ function emailChoiceOf(item, form) {
2943
+ if (item.slug !== EMAIL_SLUG || !item.emails) return void 0;
2944
+ if (form.emailChoice !== void 0) return form.emailChoice;
2945
+ const selectable = item.emails.filter(isSolicitedEmailSelectable);
2946
+ const selected = selectable.find(
2947
+ (email) => email.id === item.selectedEmailId
2948
+ );
2949
+ return selected?.id ?? selectable.find((email) => email.isDefault)?.id ?? selectable[0]?.id ?? null;
2950
+ }
2951
+ var formatSolicitedEmailOption = (email, unverifiedText = "") => {
2952
+ const text = email.label ? `${email.label} \xB7 ${email.email}` : email.email;
2953
+ return email.verified === false && unverifiedText ? `${text} (${unverifiedText})` : text;
2954
+ };
2923
2955
  var omitKey = (record, key) => Object.fromEntries(
2924
2956
  Object.entries(record).filter(([entryKey]) => entryKey !== key)
2925
2957
  );
@@ -2955,14 +2987,18 @@ function getSolicitedParams({
2955
2987
  }
2956
2988
  function getSolicitedFields(items, form = EMPTY_SOLICITED_DATA_FORM, withConsent = true) {
2957
2989
  return items.map((item) => {
2958
- const profileValue = item.value ?? "";
2959
- const inputValue = form.values[item.slug] ?? profileValue;
2990
+ const emailChoice = emailChoiceOf(item, form);
2991
+ const chosenEmail = typeof emailChoice === "number" ? item.emails?.find((email) => email.id === emailChoice)?.email : void 0;
2992
+ const emailFields = emailChoice !== void 0 ? { emailChoice } : {};
2993
+ const profileValue = chosenEmail ?? (emailChoice === null ? "" : item.value ?? "");
2994
+ const inputValue = chosenEmail ?? form.values[item.slug] ?? profileValue;
2960
2995
  const trimmed = inputValue.trim();
2961
2996
  const isEmpty = !trimmed;
2962
2997
  const isValid = isValidParamValue(item.slug, inputValue);
2963
2998
  if (!withConsent) {
2964
2999
  return {
2965
3000
  ...item,
3001
+ ...emailFields,
2966
3002
  profileValue,
2967
3003
  inputValue,
2968
3004
  isEmpty,
@@ -2980,6 +3016,7 @@ function getSolicitedFields(items, form = EMPTY_SOLICITED_DATA_FORM, withConsent
2980
3016
  const isComplete = isShared ? isValid && (!isChanged || isSaved) : item.mode !== "required";
2981
3017
  return {
2982
3018
  ...item,
3019
+ ...emailFields,
2983
3020
  profileValue,
2984
3021
  inputValue,
2985
3022
  isEmpty,
@@ -3002,6 +3039,7 @@ function getSolicitedAcceptParams(fields) {
3002
3039
  const userParams = {};
3003
3040
  const grantedParams = [];
3004
3041
  const revokedParams = [];
3042
+ const email = {};
3005
3043
  fields.forEach((field) => {
3006
3044
  if (!field.isShared) {
3007
3045
  if ((field.status === "granted" || field.status === "shared") && field.mode === "optional")
@@ -3010,17 +3048,20 @@ function getSolicitedAcceptParams(fields) {
3010
3048
  }
3011
3049
  if (!field.isValid) return;
3012
3050
  if (field.isChanged) {
3013
- if (field.isSaved)
3051
+ if (field.isSaved) {
3014
3052
  userParams[field.slug] = normalizeParamValue(
3015
3053
  field.slug,
3016
3054
  field.inputValue
3017
3055
  );
3056
+ }
3018
3057
  return;
3019
3058
  }
3059
+ if (typeof field.emailChoice === "number")
3060
+ email.sharedEmailId = field.emailChoice;
3020
3061
  if (field.status === "consent" || field.status === "granted")
3021
3062
  grantedParams.push(field.slug);
3022
3063
  });
3023
- return { userParams, grantedParams, revokedParams };
3064
+ return { userParams, grantedParams, revokedParams, ...email };
3024
3065
  }
3025
3066
  var setSolicitedValue = (form, item, value) => ({
3026
3067
  ...form,
@@ -3039,10 +3080,18 @@ var saveSolicitedValue = (form, slug) => {
3039
3080
  };
3040
3081
  };
3041
3082
  var undoSolicitedValue = (form, item) => ({
3083
+ ...form,
3042
3084
  values: omitKey(form.values, item.slug),
3043
3085
  saved: omitKey(form.saved, item.slug),
3044
3086
  shared: (item.value ?? "").trim() ? form.shared : omitKey(form.shared, item.slug)
3045
3087
  });
3088
+ var setSolicitedEmailChoice = (form, emailChoice) => ({
3089
+ ...form,
3090
+ emailChoice,
3091
+ values: omitKey(form.values, EMAIL_SLUG),
3092
+ saved: omitKey(form.saved, EMAIL_SLUG),
3093
+ shared: omitKey(form.shared, EMAIL_SLUG)
3094
+ });
3046
3095
 
3047
3096
  // src/auth/redirectPopup.ts
3048
3097
  var AUTH_CODE_MESSAGE2 = "blockauth:auth-code";
@@ -4078,6 +4127,15 @@ var TEXTS = {
4078
4127
  },
4079
4128
  shareData: { es: "Ceder", en: "Share" },
4080
4129
  saveData: { es: "Guardar", en: "Save" },
4130
+ emailUnverified: { es: "no verificado", en: "not verified" },
4131
+ emailNoneVerified: {
4132
+ es: "Ning\xFAn correo verificado",
4133
+ en: "No verified email"
4134
+ },
4135
+ emailsManage: {
4136
+ es: "A\xF1adir o gestionar correos en Identity",
4137
+ en: "Add or manage emails in Identity"
4138
+ },
4081
4139
  undoChange: { es: "Deshacer", en: "Undo" },
4082
4140
  savedToProfileHint: {
4083
4141
  es: "Se guardar\xE1 en tu perfil al aceptar",
@@ -4226,6 +4284,7 @@ exports.fetchUserProfile = fetchUserProfile;
4226
4284
  exports.finalizeAfterRestorationExpired = finalizeAfterRestorationExpired;
4227
4285
  exports.formatParamValue = formatParamValue;
4228
4286
  exports.formatPhoneForDisplay = formatPhoneForDisplay;
4287
+ exports.formatSolicitedEmailOption = formatSolicitedEmailOption;
4229
4288
  exports.getDefaultPhoneCountry = getDefaultPhoneCountry;
4230
4289
  exports.getExtensionStoreUrl = getExtensionStoreUrl;
4231
4290
  exports.getPhoneCountries = getPhoneCountries;
@@ -4253,6 +4312,7 @@ exports.isRestorationExpiredMessage = isRestorationExpiredMessage;
4253
4312
  exports.isSdkPage = isSdkPage;
4254
4313
  exports.isShowSignin = isShowSignin;
4255
4314
  exports.isSolicitedDataComplete = isSolicitedDataComplete;
4315
+ exports.isSolicitedEmailSelectable = isSolicitedEmailSelectable;
4256
4316
  exports.isSolicitedHintSuccess = isSolicitedHintSuccess;
4257
4317
  exports.isValidParamValue = isValidParamValue;
4258
4318
  exports.isValidPhoneValue = isValidPhoneValue;
@@ -4313,6 +4373,7 @@ exports.setServiceIcon = setServiceIcon;
4313
4373
  exports.setServiceName = setServiceName;
4314
4374
  exports.setSignature = setSignature;
4315
4375
  exports.setSignedBy = setSignedBy;
4376
+ exports.setSolicitedEmailChoice = setSolicitedEmailChoice;
4316
4377
  exports.setSolicitedShared = setSolicitedShared;
4317
4378
  exports.setSolicitedValue = setSolicitedValue;
4318
4379
  exports.setToken = setToken;