@block-auth.io/core 0.12.0 → 0.13.1
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 +75 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -1
- package/dist/index.d.ts +38 -1
- package/dist/index.js +73 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
|
2959
|
-
const
|
|
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";
|
|
@@ -3762,6 +3811,13 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3762
3811
|
);
|
|
3763
3812
|
});
|
|
3764
3813
|
};
|
|
3814
|
+
const onSocketReconnect = () => {
|
|
3815
|
+
if (stopped || hookState.isLoggingOut || !hookState.isSigned) return;
|
|
3816
|
+
const externalService = browserBase.getExternalService();
|
|
3817
|
+
const did = externalService.service && externalService.service !== "blockauth" ? externalService.did : browserBase.getSession().did;
|
|
3818
|
+
if (!did) return;
|
|
3819
|
+
emitSdkSign(wsc().accessToken, did);
|
|
3820
|
+
};
|
|
3765
3821
|
const onSdkUserRolesChanged = async (data) => {
|
|
3766
3822
|
const { success, message } = data || {};
|
|
3767
3823
|
if (!success || !message?.address) return;
|
|
@@ -3871,6 +3927,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3871
3927
|
wsc().on("sdk:user:roles:changed", onSdkUserRolesChanged);
|
|
3872
3928
|
wsc().on("sdk:restore", onSdkRestore);
|
|
3873
3929
|
wsc().ws?.onAny(onAnyServerEvent);
|
|
3930
|
+
wsc().ws?.on("connect", onSocketReconnect);
|
|
3874
3931
|
if (typeof window !== "undefined") {
|
|
3875
3932
|
window.addEventListener("storage", onStorageLogout);
|
|
3876
3933
|
}
|
|
@@ -3920,6 +3977,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3920
3977
|
w.off("sdk:user:roles:changed", onSdkUserRolesChanged);
|
|
3921
3978
|
w.off("sdk:restore", onSdkRestore);
|
|
3922
3979
|
w.ws?.offAny(onAnyServerEvent);
|
|
3980
|
+
w.ws?.off("connect", onSocketReconnect);
|
|
3923
3981
|
}
|
|
3924
3982
|
if (typeof window !== "undefined") {
|
|
3925
3983
|
window.removeEventListener("storage", onStorageLogout);
|
|
@@ -4078,6 +4136,15 @@ var TEXTS = {
|
|
|
4078
4136
|
},
|
|
4079
4137
|
shareData: { es: "Ceder", en: "Share" },
|
|
4080
4138
|
saveData: { es: "Guardar", en: "Save" },
|
|
4139
|
+
emailUnverified: { es: "no verificado", en: "not verified" },
|
|
4140
|
+
emailNoneVerified: {
|
|
4141
|
+
es: "Ning\xFAn correo verificado",
|
|
4142
|
+
en: "No verified email"
|
|
4143
|
+
},
|
|
4144
|
+
emailsManage: {
|
|
4145
|
+
es: "A\xF1adir o gestionar correos en Identity",
|
|
4146
|
+
en: "Add or manage emails in Identity"
|
|
4147
|
+
},
|
|
4081
4148
|
undoChange: { es: "Deshacer", en: "Undo" },
|
|
4082
4149
|
savedToProfileHint: {
|
|
4083
4150
|
es: "Se guardar\xE1 en tu perfil al aceptar",
|
|
@@ -4226,6 +4293,7 @@ exports.fetchUserProfile = fetchUserProfile;
|
|
|
4226
4293
|
exports.finalizeAfterRestorationExpired = finalizeAfterRestorationExpired;
|
|
4227
4294
|
exports.formatParamValue = formatParamValue;
|
|
4228
4295
|
exports.formatPhoneForDisplay = formatPhoneForDisplay;
|
|
4296
|
+
exports.formatSolicitedEmailOption = formatSolicitedEmailOption;
|
|
4229
4297
|
exports.getDefaultPhoneCountry = getDefaultPhoneCountry;
|
|
4230
4298
|
exports.getExtensionStoreUrl = getExtensionStoreUrl;
|
|
4231
4299
|
exports.getPhoneCountries = getPhoneCountries;
|
|
@@ -4253,6 +4321,7 @@ exports.isRestorationExpiredMessage = isRestorationExpiredMessage;
|
|
|
4253
4321
|
exports.isSdkPage = isSdkPage;
|
|
4254
4322
|
exports.isShowSignin = isShowSignin;
|
|
4255
4323
|
exports.isSolicitedDataComplete = isSolicitedDataComplete;
|
|
4324
|
+
exports.isSolicitedEmailSelectable = isSolicitedEmailSelectable;
|
|
4256
4325
|
exports.isSolicitedHintSuccess = isSolicitedHintSuccess;
|
|
4257
4326
|
exports.isValidParamValue = isValidParamValue;
|
|
4258
4327
|
exports.isValidPhoneValue = isValidPhoneValue;
|
|
@@ -4313,6 +4382,7 @@ exports.setServiceIcon = setServiceIcon;
|
|
|
4313
4382
|
exports.setServiceName = setServiceName;
|
|
4314
4383
|
exports.setSignature = setSignature;
|
|
4315
4384
|
exports.setSignedBy = setSignedBy;
|
|
4385
|
+
exports.setSolicitedEmailChoice = setSolicitedEmailChoice;
|
|
4316
4386
|
exports.setSolicitedShared = setSolicitedShared;
|
|
4317
4387
|
exports.setSolicitedValue = setSolicitedValue;
|
|
4318
4388
|
exports.setToken = setToken;
|