@paydock/client-sdk 1.144.0-beta → 1.145.0-beta
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/README.md +422 -31
- package/bundles/index.cjs +2476 -988
- package/bundles/index.cjs.d.ts +627 -431
- package/bundles/index.mjs +2476 -988
- package/bundles/index.mjs.d.ts +627 -431
- package/bundles/types/api/api-base.d.ts +15 -2
- package/bundles/types/api/api-base.d.ts.map +1 -1
- package/bundles/types/helper/browser.d.ts.map +1 -1
- package/bundles/types/helper/element-id.d.ts +3 -1
- package/bundles/types/helper/element-id.d.ts.map +1 -1
- package/bundles/types/helper/uuid.d.ts.map +1 -1
- package/bundles/types/open-wallets/apple-pay-open-wallet-button.d.ts +41 -0
- package/bundles/types/open-wallets/apple-pay-open-wallet-button.d.ts.map +1 -1
- package/bundles/types/open-wallets/base/open-wallet-buttons.d.ts +10 -0
- package/bundles/types/open-wallets/base/open-wallet-buttons.d.ts.map +1 -1
- package/bundles/types/open-wallets/base/service-config-cache.d.ts +23 -0
- package/bundles/types/open-wallets/base/service-config-cache.d.ts.map +1 -0
- package/bundles/types/open-wallets/google-pay-open-wallet-button.d.ts +33 -1
- package/bundles/types/open-wallets/google-pay-open-wallet-button.d.ts.map +1 -1
- package/bundles/types/open-wallets/index.d.ts +82 -1
- package/bundles/types/open-wallets/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/apple-pay/apple-pay-availability.interface.d.ts +41 -0
- package/bundles/types/open-wallets/interfaces/apple-pay/apple-pay-availability.interface.d.ts.map +1 -0
- package/bundles/types/open-wallets/interfaces/apple-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/interfaces/apple-pay/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/google-pay/google-pay-availability.interface.d.ts +25 -0
- package/bundles/types/open-wallets/interfaces/google-pay/google-pay-availability.interface.d.ts.map +1 -0
- package/bundles/types/open-wallets/interfaces/google-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/interfaces/google-pay/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/index.d.ts +3 -0
- package/bundles/types/open-wallets/interfaces/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/interfaces/open-wallet-availability.interface.d.ts +31 -0
- package/bundles/types/open-wallets/interfaces/open-wallet-availability.interface.d.ts.map +1 -0
- package/bundles/types/open-wallets/services/apple-pay/apple-pay-availability.d.ts +58 -0
- package/bundles/types/open-wallets/services/apple-pay/apple-pay-availability.d.ts.map +1 -0
- package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts +8 -10
- package/bundles/types/open-wallets/services/apple-pay/apple-pay.open-wallet.service.d.ts.map +1 -1
- package/bundles/types/open-wallets/services/apple-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/services/apple-pay/index.d.ts.map +1 -1
- package/bundles/types/open-wallets/services/google-pay/google-pay-availability.d.ts +53 -0
- package/bundles/types/open-wallets/services/google-pay/google-pay-availability.d.ts.map +1 -0
- package/bundles/types/open-wallets/services/google-pay/google-pay.open-wallet.service.d.ts.map +1 -1
- package/bundles/types/open-wallets/services/google-pay/index.d.ts +1 -0
- package/bundles/types/open-wallets/services/google-pay/index.d.ts.map +1 -1
- package/bundles/types/secure-remote-commerce/secure-remote-commerce.d.ts.map +1 -1
- package/bundles/widget.umd.js +2476 -988
- package/bundles/widget.umd.js.d.ts +627 -431
- package/bundles/widget.umd.js.min.d.ts +627 -431
- package/bundles/widget.umd.min.js +1 -1
- package/docs/open-wallet-buttons-examples.md +170 -2
- package/docs/open-wallet-buttons.md +252 -29
- package/package.json +15 -8
- package/slate.md +170 -2
package/bundles/widget.umd.js
CHANGED
|
@@ -834,16 +834,28 @@
|
|
|
834
834
|
value: function getBrowserName() {
|
|
835
835
|
var sUsrAg = navigator.userAgent;
|
|
836
836
|
// "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
|
|
837
|
-
if (sUsrAg.indexOf('Firefox') > -1)
|
|
838
|
-
|
|
837
|
+
if (sUsrAg.indexOf('Firefox') > -1) {
|
|
838
|
+
return 'Mozilla Firefox';
|
|
839
|
+
}
|
|
840
|
+
if (sUsrAg.indexOf('Opera') > -1) {
|
|
841
|
+
return 'Opera';
|
|
842
|
+
}
|
|
839
843
|
// "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; Zoom 3.6.0; wbx 1.0.0; rv:11.0) like Gecko"
|
|
840
|
-
if (sUsrAg.indexOf('Trident') > -1)
|
|
844
|
+
if (sUsrAg.indexOf('Trident') > -1) {
|
|
845
|
+
return 'Microsoft Internet Explorer';
|
|
846
|
+
}
|
|
841
847
|
// "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"
|
|
842
|
-
if (sUsrAg.indexOf('Edge') > -1)
|
|
848
|
+
if (sUsrAg.indexOf('Edge') > -1) {
|
|
849
|
+
return 'Microsoft Edge';
|
|
850
|
+
}
|
|
843
851
|
// "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36"
|
|
844
|
-
if (sUsrAg.indexOf('Chrome') > -1)
|
|
852
|
+
if (sUsrAg.indexOf('Chrome') > -1) {
|
|
853
|
+
return 'Google Chrome or Chromium';
|
|
854
|
+
}
|
|
845
855
|
// "Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1 980x1306"
|
|
846
|
-
if (sUsrAg.indexOf('Safari') > -1)
|
|
856
|
+
if (sUsrAg.indexOf('Safari') > -1) {
|
|
857
|
+
return 'Apple Safari';
|
|
858
|
+
}
|
|
847
859
|
return 'unknown';
|
|
848
860
|
}
|
|
849
861
|
}, {
|
|
@@ -874,11 +886,13 @@
|
|
|
874
886
|
}, {
|
|
875
887
|
key: "getBrowserInfo",
|
|
876
888
|
value: function getBrowserInfo() {
|
|
877
|
-
|
|
889
|
+
// Bound the user-agent length before running any regex to avoid
|
|
890
|
+
// pathological backtracking (ReDoS) on maliciously long inputs.
|
|
891
|
+
var ua = (navigator.userAgent || '').slice(0, 256);
|
|
878
892
|
var M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
879
|
-
var tem;
|
|
880
|
-
if (/trident/i.test(M[1])) {
|
|
881
|
-
tem = /\brv[ :](\d+)
|
|
893
|
+
var tem = null;
|
|
894
|
+
if (/trident/i.test(M[1] || '')) {
|
|
895
|
+
tem = ua.match(/\brv[ :](\d+)/) || [];
|
|
882
896
|
return {
|
|
883
897
|
name: 'IE',
|
|
884
898
|
version: tem[1] || ''
|
|
@@ -894,8 +908,8 @@
|
|
|
894
908
|
}
|
|
895
909
|
}
|
|
896
910
|
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
|
|
897
|
-
|
|
898
|
-
if (
|
|
911
|
+
tem = ua.match(/version\/(\d+)/i);
|
|
912
|
+
if (tem != null) {
|
|
899
913
|
M.splice(1, 1, tem[1]);
|
|
900
914
|
}
|
|
901
915
|
return {
|
|
@@ -960,246 +974,6 @@
|
|
|
960
974
|
}]);
|
|
961
975
|
}();
|
|
962
976
|
|
|
963
|
-
var ENV = {
|
|
964
|
-
SANDBOX: 'sandbox',
|
|
965
|
-
SANDBOX_KOVENA: 'sandbox-kovena',
|
|
966
|
-
SANDBOX_DEMO: 'sandbox-demo',
|
|
967
|
-
SANDBOX_DEMO_KOVENA: 'sandbox-demo-kovena',
|
|
968
|
-
PROD: 'production',
|
|
969
|
-
STAGING: 'staging',
|
|
970
|
-
STAGING_1: 'staging_1',
|
|
971
|
-
STAGING_2: 'staging_2',
|
|
972
|
-
STAGING_3: 'staging_3',
|
|
973
|
-
STAGING_4: 'staging_4',
|
|
974
|
-
STAGING_5: 'staging_5',
|
|
975
|
-
STAGING_6: 'staging_6',
|
|
976
|
-
STAGING_7: 'staging_7',
|
|
977
|
-
STAGING_8: 'staging_8',
|
|
978
|
-
STAGING_9: 'staging_9',
|
|
979
|
-
STAGING_10: 'staging_10',
|
|
980
|
-
STAGING_11: 'staging_11',
|
|
981
|
-
STAGING_12: 'staging_12',
|
|
982
|
-
STAGING_13: 'staging_13',
|
|
983
|
-
STAGING_14: 'staging_14',
|
|
984
|
-
STAGING_15: 'staging_15'
|
|
985
|
-
};
|
|
986
|
-
var WIDGET_URL = [{
|
|
987
|
-
env: ENV.SANDBOX,
|
|
988
|
-
url: 'https://widget-sandbox.'
|
|
989
|
-
}, {
|
|
990
|
-
env: ENV.SANDBOX_KOVENA,
|
|
991
|
-
url: 'https://widget-sandbox.'
|
|
992
|
-
}, {
|
|
993
|
-
env: ENV.SANDBOX_DEMO,
|
|
994
|
-
url: 'https://widget-sandbox-demo.'
|
|
995
|
-
}, {
|
|
996
|
-
env: ENV.SANDBOX_DEMO_KOVENA,
|
|
997
|
-
url: 'https://widget-sandbox-demo.'
|
|
998
|
-
}, {
|
|
999
|
-
env: ENV.PROD,
|
|
1000
|
-
url: 'https://widget.'
|
|
1001
|
-
}, {
|
|
1002
|
-
env: ENV.STAGING,
|
|
1003
|
-
url: 'https://widsta.'
|
|
1004
|
-
}, {
|
|
1005
|
-
env: ENV.STAGING_1,
|
|
1006
|
-
url: 'https://widsta-1.'
|
|
1007
|
-
}, {
|
|
1008
|
-
env: ENV.STAGING_2,
|
|
1009
|
-
url: 'https://widsta-2.'
|
|
1010
|
-
}, {
|
|
1011
|
-
env: ENV.STAGING_3,
|
|
1012
|
-
url: 'https://widsta-3.'
|
|
1013
|
-
}, {
|
|
1014
|
-
env: ENV.STAGING_4,
|
|
1015
|
-
url: 'https://widsta-4.'
|
|
1016
|
-
}, {
|
|
1017
|
-
env: ENV.STAGING_5,
|
|
1018
|
-
url: 'https://widsta-5.'
|
|
1019
|
-
}, {
|
|
1020
|
-
env: ENV.STAGING_6,
|
|
1021
|
-
url: 'https://widsta-6.'
|
|
1022
|
-
}, {
|
|
1023
|
-
env: ENV.STAGING_7,
|
|
1024
|
-
url: 'https://widsta-7.'
|
|
1025
|
-
}, {
|
|
1026
|
-
env: ENV.STAGING_8,
|
|
1027
|
-
url: 'https://widsta-8.'
|
|
1028
|
-
}, {
|
|
1029
|
-
env: ENV.STAGING_9,
|
|
1030
|
-
url: 'https://widsta-9.'
|
|
1031
|
-
}, {
|
|
1032
|
-
env: ENV.STAGING_10,
|
|
1033
|
-
url: 'https://widsta-10.'
|
|
1034
|
-
}, {
|
|
1035
|
-
env: ENV.STAGING_11,
|
|
1036
|
-
url: 'https://widsta-11.'
|
|
1037
|
-
}, {
|
|
1038
|
-
env: ENV.STAGING_12,
|
|
1039
|
-
url: 'https://widsta-12.'
|
|
1040
|
-
}, {
|
|
1041
|
-
env: ENV.STAGING_13,
|
|
1042
|
-
url: 'https://widsta-13.'
|
|
1043
|
-
}, {
|
|
1044
|
-
env: ENV.STAGING_14,
|
|
1045
|
-
url: 'https://widsta-14.'
|
|
1046
|
-
}, {
|
|
1047
|
-
env: ENV.STAGING_15,
|
|
1048
|
-
url: 'https://widsta-15.'
|
|
1049
|
-
}];
|
|
1050
|
-
var API_URL = [{
|
|
1051
|
-
env: ENV.SANDBOX,
|
|
1052
|
-
url: 'https://api-sandbox.'
|
|
1053
|
-
}, {
|
|
1054
|
-
env: ENV.PROD,
|
|
1055
|
-
url: 'https://api.'
|
|
1056
|
-
}, {
|
|
1057
|
-
env: ENV.STAGING,
|
|
1058
|
-
url: 'https://apista.'
|
|
1059
|
-
}, {
|
|
1060
|
-
env: ENV.STAGING_1,
|
|
1061
|
-
url: 'https://apista-1.'
|
|
1062
|
-
}, {
|
|
1063
|
-
env: ENV.STAGING_2,
|
|
1064
|
-
url: 'https://apista-2.'
|
|
1065
|
-
}, {
|
|
1066
|
-
env: ENV.STAGING_3,
|
|
1067
|
-
url: 'https://apista-3.'
|
|
1068
|
-
}, {
|
|
1069
|
-
env: ENV.STAGING_4,
|
|
1070
|
-
url: 'https://apista-4.'
|
|
1071
|
-
}, {
|
|
1072
|
-
env: ENV.STAGING_5,
|
|
1073
|
-
url: 'https://apista-5.'
|
|
1074
|
-
}, {
|
|
1075
|
-
env: ENV.STAGING_6,
|
|
1076
|
-
url: 'https://apista-6.'
|
|
1077
|
-
}, {
|
|
1078
|
-
env: ENV.STAGING_7,
|
|
1079
|
-
url: 'https://apista-7.'
|
|
1080
|
-
}, {
|
|
1081
|
-
env: ENV.STAGING_8,
|
|
1082
|
-
url: 'https://apista-8.'
|
|
1083
|
-
}, {
|
|
1084
|
-
env: ENV.STAGING_9,
|
|
1085
|
-
url: 'https://apista-9.'
|
|
1086
|
-
}, {
|
|
1087
|
-
env: ENV.STAGING_10,
|
|
1088
|
-
url: 'https://apista-10.'
|
|
1089
|
-
}, {
|
|
1090
|
-
env: ENV.STAGING_11,
|
|
1091
|
-
url: 'https://apista-11.'
|
|
1092
|
-
}, {
|
|
1093
|
-
env: ENV.STAGING_12,
|
|
1094
|
-
url: 'https://apista-12.'
|
|
1095
|
-
}, {
|
|
1096
|
-
env: ENV.STAGING_13,
|
|
1097
|
-
url: 'https://apista-13.'
|
|
1098
|
-
}, {
|
|
1099
|
-
env: ENV.STAGING_14,
|
|
1100
|
-
url: 'https://apista-14.'
|
|
1101
|
-
}, {
|
|
1102
|
-
env: ENV.STAGING_15,
|
|
1103
|
-
url: 'https://apista-15.'
|
|
1104
|
-
}];
|
|
1105
|
-
var ADDITIONAL_ENV = [ENV.SANDBOX_KOVENA, ENV.SANDBOX_DEMO_KOVENA];
|
|
1106
|
-
var REGEX_ALIAS = '^([a-zA-Z0-9](?:(?:[a-zA-Z0-9-.]*(?!-)\\.(?![-.]))*[a-zA-Z0-9]+)?)$';
|
|
1107
|
-
var DEFAULT_ENV = ENV.SANDBOX;
|
|
1108
|
-
var DEFAULT_ALIAS = {
|
|
1109
|
-
PAYDOCK: 'paydock.com',
|
|
1110
|
-
KOVENA: 'kovena.com'
|
|
1111
|
-
};
|
|
1112
|
-
// TODO @ingeniousraccoons we should take advantage of TypeScript mechanism for static environmentId checking and simplified runtime validation
|
|
1113
|
-
// TODO @ingeniousraccoons unify `environment.paydock.ts` and `environment.cba.ts` making them configuration driven
|
|
1114
|
-
var Env = /*#__PURE__*/function () {
|
|
1115
|
-
function Env(configs) {
|
|
1116
|
-
var defaultEnv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_ENV;
|
|
1117
|
-
_classCallCheck(this, Env);
|
|
1118
|
-
this.environmentConfigurations = configs;
|
|
1119
|
-
this.setEnv(defaultEnv);
|
|
1120
|
-
}
|
|
1121
|
-
return _createClass(Env, [{
|
|
1122
|
-
key: "setEnv",
|
|
1123
|
-
value: function setEnv(environmentId, alias) {
|
|
1124
|
-
this.validateAlias(alias);
|
|
1125
|
-
this.validateEnvironmentId(environmentId);
|
|
1126
|
-
this.environmentId = environmentId;
|
|
1127
|
-
if (alias) {
|
|
1128
|
-
this.alias = alias;
|
|
1129
|
-
} else if (ADDITIONAL_ENV.includes(this.environmentId)) {
|
|
1130
|
-
this.alias = DEFAULT_ALIAS.KOVENA;
|
|
1131
|
-
} else {
|
|
1132
|
-
this.alias = DEFAULT_ALIAS.PAYDOCK;
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
}, {
|
|
1136
|
-
key: "getEnv",
|
|
1137
|
-
value: function getEnv() {
|
|
1138
|
-
return this.environmentId;
|
|
1139
|
-
}
|
|
1140
|
-
}, {
|
|
1141
|
-
key: "getConf",
|
|
1142
|
-
value: function getConf() {
|
|
1143
|
-
for (var index in this.environmentConfigurations) {
|
|
1144
|
-
if (!Object.hasOwn(this.environmentConfigurations, index)) {
|
|
1145
|
-
continue;
|
|
1146
|
-
}
|
|
1147
|
-
if (this.environmentConfigurations[index].env === this.getEnv()) {
|
|
1148
|
-
return {
|
|
1149
|
-
url: this.environmentConfigurations[index].url.indexOf('localhost') !== -1 ? this.environmentConfigurations[index].url : this.environmentConfigurations[index].url + this.alias,
|
|
1150
|
-
env: this.environmentConfigurations[index].env
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
throw new Error('Env could not obtain configuration. Unknown environmentId.');
|
|
1155
|
-
}
|
|
1156
|
-
}, {
|
|
1157
|
-
key: "validateAlias",
|
|
1158
|
-
value: function validateAlias(alias) {
|
|
1159
|
-
if (typeof alias === 'undefined') {
|
|
1160
|
-
return;
|
|
1161
|
-
}
|
|
1162
|
-
if (typeof alias !== 'string') {
|
|
1163
|
-
throw new TypeError("Env expects parameter 'alias' to be of type 'string' or 'undefined'.");
|
|
1164
|
-
}
|
|
1165
|
-
if (!alias.match(REGEX_ALIAS)) {
|
|
1166
|
-
throw new Error("Env received malformed alias: ".concat(alias, ". Ensure it satisfies the regex: '").concat(REGEX_ALIAS, "'."));
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
}, {
|
|
1170
|
-
key: "validateEnvironmentId",
|
|
1171
|
-
value: function validateEnvironmentId(environmentId) {
|
|
1172
|
-
for (var index in this.environmentConfigurations) {
|
|
1173
|
-
if (!Object.hasOwn(this.environmentConfigurations, index)) {
|
|
1174
|
-
continue;
|
|
1175
|
-
}
|
|
1176
|
-
if (this.environmentConfigurations[index].env === environmentId) {
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
throw new TypeError("Env received unknown environmentId: ".concat(environmentId));
|
|
1181
|
-
}
|
|
1182
|
-
}]);
|
|
1183
|
-
}();
|
|
1184
|
-
|
|
1185
|
-
var SDK = /*#__PURE__*/function () {
|
|
1186
|
-
function SDK() {
|
|
1187
|
-
_classCallCheck(this, SDK);
|
|
1188
|
-
}
|
|
1189
|
-
return _createClass(SDK, null, [{
|
|
1190
|
-
key: "version",
|
|
1191
|
-
get: function get() {
|
|
1192
|
-
return SDK._version.trim() || null;
|
|
1193
|
-
}
|
|
1194
|
-
}]);
|
|
1195
|
-
}();
|
|
1196
|
-
SDK.type = 'client';
|
|
1197
|
-
SDK.headerKeys = Object.freeze({
|
|
1198
|
-
version: 'x-sdk-version',
|
|
1199
|
-
type: 'x-sdk-type'
|
|
1200
|
-
});
|
|
1201
|
-
SDK._version = 'v1.144.0-beta';
|
|
1202
|
-
|
|
1203
977
|
function isFunction(value) {
|
|
1204
978
|
return typeof value === 'function';
|
|
1205
979
|
}
|
|
@@ -1857,17 +1631,257 @@
|
|
|
1857
1631
|
return BehaviorSubject;
|
|
1858
1632
|
}(Subject));
|
|
1859
1633
|
|
|
1860
|
-
var
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1634
|
+
var ENV = {
|
|
1635
|
+
SANDBOX: 'sandbox',
|
|
1636
|
+
SANDBOX_KOVENA: 'sandbox-kovena',
|
|
1637
|
+
SANDBOX_DEMO: 'sandbox-demo',
|
|
1638
|
+
SANDBOX_DEMO_KOVENA: 'sandbox-demo-kovena',
|
|
1639
|
+
PROD: 'production',
|
|
1640
|
+
STAGING: 'staging',
|
|
1641
|
+
STAGING_1: 'staging_1',
|
|
1642
|
+
STAGING_2: 'staging_2',
|
|
1643
|
+
STAGING_3: 'staging_3',
|
|
1644
|
+
STAGING_4: 'staging_4',
|
|
1645
|
+
STAGING_5: 'staging_5',
|
|
1646
|
+
STAGING_6: 'staging_6',
|
|
1647
|
+
STAGING_7: 'staging_7',
|
|
1648
|
+
STAGING_8: 'staging_8',
|
|
1649
|
+
STAGING_9: 'staging_9',
|
|
1650
|
+
STAGING_10: 'staging_10',
|
|
1651
|
+
STAGING_11: 'staging_11',
|
|
1652
|
+
STAGING_12: 'staging_12',
|
|
1653
|
+
STAGING_13: 'staging_13',
|
|
1654
|
+
STAGING_14: 'staging_14',
|
|
1655
|
+
STAGING_15: 'staging_15'
|
|
1656
|
+
};
|
|
1657
|
+
var WIDGET_URL = [{
|
|
1658
|
+
env: ENV.SANDBOX,
|
|
1659
|
+
url: 'https://widget-sandbox.'
|
|
1660
|
+
}, {
|
|
1661
|
+
env: ENV.SANDBOX_KOVENA,
|
|
1662
|
+
url: 'https://widget-sandbox.'
|
|
1663
|
+
}, {
|
|
1664
|
+
env: ENV.SANDBOX_DEMO,
|
|
1665
|
+
url: 'https://widget-sandbox-demo.'
|
|
1666
|
+
}, {
|
|
1667
|
+
env: ENV.SANDBOX_DEMO_KOVENA,
|
|
1668
|
+
url: 'https://widget-sandbox-demo.'
|
|
1669
|
+
}, {
|
|
1670
|
+
env: ENV.PROD,
|
|
1671
|
+
url: 'https://widget.'
|
|
1672
|
+
}, {
|
|
1673
|
+
env: ENV.STAGING,
|
|
1674
|
+
url: 'https://widsta.'
|
|
1675
|
+
}, {
|
|
1676
|
+
env: ENV.STAGING_1,
|
|
1677
|
+
url: 'https://widsta-1.'
|
|
1678
|
+
}, {
|
|
1679
|
+
env: ENV.STAGING_2,
|
|
1680
|
+
url: 'https://widsta-2.'
|
|
1681
|
+
}, {
|
|
1682
|
+
env: ENV.STAGING_3,
|
|
1683
|
+
url: 'https://widsta-3.'
|
|
1684
|
+
}, {
|
|
1685
|
+
env: ENV.STAGING_4,
|
|
1686
|
+
url: 'https://widsta-4.'
|
|
1687
|
+
}, {
|
|
1688
|
+
env: ENV.STAGING_5,
|
|
1689
|
+
url: 'https://widsta-5.'
|
|
1690
|
+
}, {
|
|
1691
|
+
env: ENV.STAGING_6,
|
|
1692
|
+
url: 'https://widsta-6.'
|
|
1693
|
+
}, {
|
|
1694
|
+
env: ENV.STAGING_7,
|
|
1695
|
+
url: 'https://widsta-7.'
|
|
1696
|
+
}, {
|
|
1697
|
+
env: ENV.STAGING_8,
|
|
1698
|
+
url: 'https://widsta-8.'
|
|
1699
|
+
}, {
|
|
1700
|
+
env: ENV.STAGING_9,
|
|
1701
|
+
url: 'https://widsta-9.'
|
|
1702
|
+
}, {
|
|
1703
|
+
env: ENV.STAGING_10,
|
|
1704
|
+
url: 'https://widsta-10.'
|
|
1705
|
+
}, {
|
|
1706
|
+
env: ENV.STAGING_11,
|
|
1707
|
+
url: 'https://widsta-11.'
|
|
1708
|
+
}, {
|
|
1709
|
+
env: ENV.STAGING_12,
|
|
1710
|
+
url: 'https://widsta-12.'
|
|
1711
|
+
}, {
|
|
1712
|
+
env: ENV.STAGING_13,
|
|
1713
|
+
url: 'https://widsta-13.'
|
|
1714
|
+
}, {
|
|
1715
|
+
env: ENV.STAGING_14,
|
|
1716
|
+
url: 'https://widsta-14.'
|
|
1717
|
+
}, {
|
|
1718
|
+
env: ENV.STAGING_15,
|
|
1719
|
+
url: 'https://widsta-15.'
|
|
1720
|
+
}];
|
|
1721
|
+
var API_URL = [{
|
|
1722
|
+
env: ENV.SANDBOX,
|
|
1723
|
+
url: 'https://api-sandbox.'
|
|
1724
|
+
}, {
|
|
1725
|
+
env: ENV.PROD,
|
|
1726
|
+
url: 'https://api.'
|
|
1727
|
+
}, {
|
|
1728
|
+
env: ENV.STAGING,
|
|
1729
|
+
url: 'https://apista.'
|
|
1730
|
+
}, {
|
|
1731
|
+
env: ENV.STAGING_1,
|
|
1732
|
+
url: 'https://apista-1.'
|
|
1733
|
+
}, {
|
|
1734
|
+
env: ENV.STAGING_2,
|
|
1735
|
+
url: 'https://apista-2.'
|
|
1736
|
+
}, {
|
|
1737
|
+
env: ENV.STAGING_3,
|
|
1738
|
+
url: 'https://apista-3.'
|
|
1739
|
+
}, {
|
|
1740
|
+
env: ENV.STAGING_4,
|
|
1741
|
+
url: 'https://apista-4.'
|
|
1742
|
+
}, {
|
|
1743
|
+
env: ENV.STAGING_5,
|
|
1744
|
+
url: 'https://apista-5.'
|
|
1745
|
+
}, {
|
|
1746
|
+
env: ENV.STAGING_6,
|
|
1747
|
+
url: 'https://apista-6.'
|
|
1748
|
+
}, {
|
|
1749
|
+
env: ENV.STAGING_7,
|
|
1750
|
+
url: 'https://apista-7.'
|
|
1751
|
+
}, {
|
|
1752
|
+
env: ENV.STAGING_8,
|
|
1753
|
+
url: 'https://apista-8.'
|
|
1754
|
+
}, {
|
|
1755
|
+
env: ENV.STAGING_9,
|
|
1756
|
+
url: 'https://apista-9.'
|
|
1757
|
+
}, {
|
|
1758
|
+
env: ENV.STAGING_10,
|
|
1759
|
+
url: 'https://apista-10.'
|
|
1760
|
+
}, {
|
|
1761
|
+
env: ENV.STAGING_11,
|
|
1762
|
+
url: 'https://apista-11.'
|
|
1763
|
+
}, {
|
|
1764
|
+
env: ENV.STAGING_12,
|
|
1765
|
+
url: 'https://apista-12.'
|
|
1766
|
+
}, {
|
|
1767
|
+
env: ENV.STAGING_13,
|
|
1768
|
+
url: 'https://apista-13.'
|
|
1769
|
+
}, {
|
|
1770
|
+
env: ENV.STAGING_14,
|
|
1771
|
+
url: 'https://apista-14.'
|
|
1772
|
+
}, {
|
|
1773
|
+
env: ENV.STAGING_15,
|
|
1774
|
+
url: 'https://apista-15.'
|
|
1775
|
+
}];
|
|
1776
|
+
var ADDITIONAL_ENV = [ENV.SANDBOX_KOVENA, ENV.SANDBOX_DEMO_KOVENA];
|
|
1777
|
+
var REGEX_ALIAS = '^([a-zA-Z0-9](?:(?:[a-zA-Z0-9-.]*(?!-)\\.(?![-.]))*[a-zA-Z0-9]+)?)$';
|
|
1778
|
+
var DEFAULT_ENV = ENV.SANDBOX;
|
|
1779
|
+
var DEFAULT_ALIAS = {
|
|
1780
|
+
PAYDOCK: 'paydock.com',
|
|
1781
|
+
KOVENA: 'kovena.com'
|
|
1782
|
+
};
|
|
1783
|
+
// TODO @ingeniousraccoons we should take advantage of TypeScript mechanism for static environmentId checking and simplified runtime validation
|
|
1784
|
+
// TODO @ingeniousraccoons unify `environment.paydock.ts` and `environment.cba.ts` making them configuration driven
|
|
1785
|
+
var Env = /*#__PURE__*/function () {
|
|
1786
|
+
function Env(configs) {
|
|
1787
|
+
var defaultEnv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_ENV;
|
|
1788
|
+
_classCallCheck(this, Env);
|
|
1789
|
+
this.environmentConfigurations = configs;
|
|
1790
|
+
this.setEnv(defaultEnv);
|
|
1791
|
+
}
|
|
1792
|
+
return _createClass(Env, [{
|
|
1793
|
+
key: "setEnv",
|
|
1794
|
+
value: function setEnv(environmentId, alias) {
|
|
1795
|
+
this.validateAlias(alias);
|
|
1796
|
+
this.validateEnvironmentId(environmentId);
|
|
1797
|
+
this.environmentId = environmentId;
|
|
1798
|
+
if (alias) {
|
|
1799
|
+
this.alias = alias;
|
|
1800
|
+
} else if (ADDITIONAL_ENV.includes(this.environmentId)) {
|
|
1801
|
+
this.alias = DEFAULT_ALIAS.KOVENA;
|
|
1802
|
+
} else {
|
|
1803
|
+
this.alias = DEFAULT_ALIAS.PAYDOCK;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}, {
|
|
1807
|
+
key: "getEnv",
|
|
1808
|
+
value: function getEnv() {
|
|
1809
|
+
return this.environmentId;
|
|
1810
|
+
}
|
|
1811
|
+
}, {
|
|
1812
|
+
key: "getConf",
|
|
1813
|
+
value: function getConf() {
|
|
1814
|
+
for (var index in this.environmentConfigurations) {
|
|
1815
|
+
if (!Object.hasOwn(this.environmentConfigurations, index)) {
|
|
1816
|
+
continue;
|
|
1817
|
+
}
|
|
1818
|
+
if (this.environmentConfigurations[index].env === this.getEnv()) {
|
|
1819
|
+
return {
|
|
1820
|
+
url: this.environmentConfigurations[index].url.indexOf('localhost') !== -1 ? this.environmentConfigurations[index].url : this.environmentConfigurations[index].url + this.alias,
|
|
1821
|
+
env: this.environmentConfigurations[index].env
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
throw new Error('Env could not obtain configuration. Unknown environmentId.');
|
|
1826
|
+
}
|
|
1827
|
+
}, {
|
|
1828
|
+
key: "validateAlias",
|
|
1829
|
+
value: function validateAlias(alias) {
|
|
1830
|
+
if (typeof alias === 'undefined') {
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
if (typeof alias !== 'string') {
|
|
1834
|
+
throw new TypeError("Env expects parameter 'alias' to be of type 'string' or 'undefined'.");
|
|
1835
|
+
}
|
|
1836
|
+
if (!alias.match(REGEX_ALIAS)) {
|
|
1837
|
+
throw new Error("Env received malformed alias: ".concat(alias, ". Ensure it satisfies the regex: '").concat(REGEX_ALIAS, "'."));
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
}, {
|
|
1841
|
+
key: "validateEnvironmentId",
|
|
1842
|
+
value: function validateEnvironmentId(environmentId) {
|
|
1843
|
+
for (var index in this.environmentConfigurations) {
|
|
1844
|
+
if (!Object.hasOwn(this.environmentConfigurations, index)) {
|
|
1845
|
+
continue;
|
|
1846
|
+
}
|
|
1847
|
+
if (this.environmentConfigurations[index].env === environmentId) {
|
|
1848
|
+
return;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
throw new TypeError("Env received unknown environmentId: ".concat(environmentId));
|
|
1852
|
+
}
|
|
1853
|
+
}]);
|
|
1854
|
+
}();
|
|
1855
|
+
|
|
1856
|
+
var SDK = /*#__PURE__*/function () {
|
|
1857
|
+
function SDK() {
|
|
1858
|
+
_classCallCheck(this, SDK);
|
|
1859
|
+
}
|
|
1860
|
+
return _createClass(SDK, null, [{
|
|
1861
|
+
key: "version",
|
|
1862
|
+
get: function get() {
|
|
1863
|
+
return SDK._version.trim() || null;
|
|
1864
|
+
}
|
|
1865
|
+
}]);
|
|
1866
|
+
}();
|
|
1867
|
+
SDK.type = 'client';
|
|
1868
|
+
SDK.headerKeys = Object.freeze({
|
|
1869
|
+
version: 'x-sdk-version',
|
|
1870
|
+
type: 'x-sdk-type'
|
|
1871
|
+
});
|
|
1872
|
+
SDK._version = 'v1.145.0-beta';
|
|
1873
|
+
|
|
1874
|
+
var ACCESS_HEADER_NAME = {
|
|
1875
|
+
accessToken: 'x-access-token',
|
|
1876
|
+
publicKey: 'x-user-public-key'
|
|
1877
|
+
};
|
|
1878
|
+
var AccessToken = /*#__PURE__*/function () {
|
|
1879
|
+
function AccessToken() {
|
|
1880
|
+
_classCallCheck(this, AccessToken);
|
|
1881
|
+
}
|
|
1882
|
+
return _createClass(AccessToken, null, [{
|
|
1883
|
+
key: "validateJWT",
|
|
1884
|
+
value: function validateJWT(jwt) {
|
|
1871
1885
|
if (!jwt) return null;
|
|
1872
1886
|
var _jwt$split = jwt.split("."),
|
|
1873
1887
|
_jwt$split2 = _slicedToArray(_jwt$split, 3),
|
|
@@ -1945,7 +1959,140 @@
|
|
|
1945
1959
|
return jwtPattern.test(value);
|
|
1946
1960
|
}
|
|
1947
1961
|
}]);
|
|
1948
|
-
}();
|
|
1962
|
+
}();
|
|
1963
|
+
|
|
1964
|
+
/**
|
|
1965
|
+
* Top-level classification of an error. Used by the SDK to route errors to the
|
|
1966
|
+
* right category in instrumentation and to give consumers a coarse-grained
|
|
1967
|
+
* tag for grouping/filtering. See {@link getErrorCategory} for the mapping
|
|
1968
|
+
* between {@link ERROR_CAUSE} and {@link ERROR_CATEGORY}.
|
|
1969
|
+
*/
|
|
1970
|
+
var ERROR_CATEGORY = {
|
|
1971
|
+
/** SDK was misconfigured (missing keys, invalid options, etc.). */
|
|
1972
|
+
CONFIGURATION: 'configuration',
|
|
1973
|
+
/** Authentication or authorization failure. */
|
|
1974
|
+
IDENTITY: 'identity_access_management',
|
|
1975
|
+
/** SDK internal failure or upstream service problem. */
|
|
1976
|
+
INTERNAL: 'internal',
|
|
1977
|
+
/** Flow lifecycle event (user cancelled, aborted, etc.) — not a real fault. */
|
|
1978
|
+
PROCESS: 'process',
|
|
1979
|
+
/** Resource lookup failed or was rate-limited. */
|
|
1980
|
+
RESOURCE: 'resource',
|
|
1981
|
+
/** Invalid input or business-rule validation failure. */
|
|
1982
|
+
VALIDATION: 'validation'
|
|
1983
|
+
};
|
|
1984
|
+
/**
|
|
1985
|
+
* Concrete cause of an error. More specific than {@link ERROR_CATEGORY} —
|
|
1986
|
+
* useful for deciding programmatic responses (e.g. show a retry button only
|
|
1987
|
+
* when `cause` is `'service_unreachable'` or `'server_busy'`).
|
|
1988
|
+
*/
|
|
1989
|
+
var ERROR_CAUSE = {
|
|
1990
|
+
/** Operation was aborted programmatically. */
|
|
1991
|
+
ABORTED: 'aborted',
|
|
1992
|
+
/** Caller has insufficient permissions for the operation. */
|
|
1993
|
+
ACCESS_FORBIDDEN: 'access_forbidden',
|
|
1994
|
+
/** Resource already exists when create was expected. */
|
|
1995
|
+
ALREADY_EXISTS: 'already_exists',
|
|
1996
|
+
/** User cancelled the flow (e.g. closed the wallet sheet). */
|
|
1997
|
+
CANCELED: 'canceled',
|
|
1998
|
+
/** SDK was instantiated or invoked with invalid configuration. */
|
|
1999
|
+
INVALID_CONFIGURATION: 'invalid_configuration',
|
|
2000
|
+
/** Input failed structural or business-rule validation. */
|
|
2001
|
+
INVALID_INPUT: 'invalid_input',
|
|
2002
|
+
/** Resource was not found by the backend. */
|
|
2003
|
+
NOT_FOUND: 'not_found',
|
|
2004
|
+
/** Operation is not supported in the current context or version. */
|
|
2005
|
+
NOT_IMPLEMENTED: 'not_implemented',
|
|
2006
|
+
/** Caller exceeded the allowed request rate. */
|
|
2007
|
+
RATE_LIMITED: 'rate_limited',
|
|
2008
|
+
/** Backend is healthy but currently overloaded — typically retryable. */
|
|
2009
|
+
SERVER_BUSY: 'server_busy',
|
|
2010
|
+
/** Backend or third-party service could not be reached — typically retryable. */
|
|
2011
|
+
SERVICE_UNREACHABLE: 'service_unreachable',
|
|
2012
|
+
/** Caller is not authenticated. */
|
|
2013
|
+
UNAUTHORIZED: 'unauthorized',
|
|
2014
|
+
/** Catch-all when no other cause applies. */
|
|
2015
|
+
UNKNOWN: 'unknown_error',
|
|
2016
|
+
/** Request was syntactically valid but semantically rejected. */
|
|
2017
|
+
UNPROCESSABLE_ENTITY: 'unprocessable_entity'
|
|
2018
|
+
};
|
|
2019
|
+
var EventError = /*#__PURE__*/function (_Error) {
|
|
2020
|
+
function EventError(cause, category, retryable, details) {
|
|
2021
|
+
var _this;
|
|
2022
|
+
_classCallCheck(this, EventError);
|
|
2023
|
+
_this = _callSuper(this, EventError, [details.message]);
|
|
2024
|
+
_this.cause = cause;
|
|
2025
|
+
_this.category = category;
|
|
2026
|
+
_this.retryable = retryable;
|
|
2027
|
+
_this.details = details;
|
|
2028
|
+
Object.setPrototypeOf(_this, EventError.prototype);
|
|
2029
|
+
_this.name = EventError.name;
|
|
2030
|
+
return _this;
|
|
2031
|
+
}
|
|
2032
|
+
_inherits(EventError, _Error);
|
|
2033
|
+
return _createClass(EventError, [{
|
|
2034
|
+
key: "toJSON",
|
|
2035
|
+
value: function toJSON() {
|
|
2036
|
+
return {
|
|
2037
|
+
error: {
|
|
2038
|
+
category: this.category,
|
|
2039
|
+
cause: this.cause,
|
|
2040
|
+
details: this.details,
|
|
2041
|
+
retryable: this.retryable
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
}, {
|
|
2046
|
+
key: "setContextId",
|
|
2047
|
+
value: function setContextId(contextId) {
|
|
2048
|
+
this.details.contextId = contextId;
|
|
2049
|
+
}
|
|
2050
|
+
}, {
|
|
2051
|
+
key: "setPurpose",
|
|
2052
|
+
value: function setPurpose(purpose) {
|
|
2053
|
+
this.purpose = purpose;
|
|
2054
|
+
}
|
|
2055
|
+
}], [{
|
|
2056
|
+
key: "create",
|
|
2057
|
+
value: function create(cause, message) {
|
|
2058
|
+
var contextId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
2059
|
+
var retryable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
2060
|
+
var details = {
|
|
2061
|
+
cause: cause,
|
|
2062
|
+
contextId: contextId,
|
|
2063
|
+
message: message,
|
|
2064
|
+
timestamp: new Date().toISOString()
|
|
2065
|
+
};
|
|
2066
|
+
var category = getErrorCategory(cause);
|
|
2067
|
+
return new EventError(cause, category, retryable, details);
|
|
2068
|
+
}
|
|
2069
|
+
}]);
|
|
2070
|
+
}(/*#__PURE__*/_wrapNativeSuper(Error));
|
|
2071
|
+
function getErrorCategory(cause) {
|
|
2072
|
+
switch (cause) {
|
|
2073
|
+
case ERROR_CAUSE.INVALID_CONFIGURATION:
|
|
2074
|
+
return ERROR_CATEGORY.CONFIGURATION;
|
|
2075
|
+
case ERROR_CAUSE.ACCESS_FORBIDDEN:
|
|
2076
|
+
case ERROR_CAUSE.UNAUTHORIZED:
|
|
2077
|
+
return ERROR_CATEGORY.IDENTITY;
|
|
2078
|
+
case ERROR_CAUSE.SERVICE_UNREACHABLE:
|
|
2079
|
+
case ERROR_CAUSE.NOT_IMPLEMENTED:
|
|
2080
|
+
case ERROR_CAUSE.SERVER_BUSY:
|
|
2081
|
+
return ERROR_CATEGORY.INTERNAL;
|
|
2082
|
+
case ERROR_CAUSE.ABORTED:
|
|
2083
|
+
case ERROR_CAUSE.CANCELED:
|
|
2084
|
+
return ERROR_CATEGORY.PROCESS;
|
|
2085
|
+
case ERROR_CAUSE.NOT_FOUND:
|
|
2086
|
+
case ERROR_CAUSE.RATE_LIMITED:
|
|
2087
|
+
return ERROR_CATEGORY.RESOURCE;
|
|
2088
|
+
case ERROR_CAUSE.ALREADY_EXISTS:
|
|
2089
|
+
case ERROR_CAUSE.INVALID_INPUT:
|
|
2090
|
+
case ERROR_CAUSE.UNPROCESSABLE_ENTITY:
|
|
2091
|
+
return ERROR_CATEGORY.VALIDATION;
|
|
2092
|
+
default:
|
|
2093
|
+
return ERROR_CATEGORY.INTERNAL;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
1949
2096
|
|
|
1950
2097
|
var HttpRequest = /*#__PURE__*/function () {
|
|
1951
2098
|
function HttpRequest(request) {
|
|
@@ -4641,18 +4788,23 @@
|
|
|
4641
4788
|
var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (data) {
|
|
4642
4789
|
return undefined;
|
|
4643
4790
|
};
|
|
4791
|
+
var onError = function onError(err) {
|
|
4792
|
+
_this4.reportError(errorRepository, err, _extends(_extends({}, _this4.ctx), {
|
|
4793
|
+
classMethod: 'getClient',
|
|
4794
|
+
description: 'Send unsuccessful.'
|
|
4795
|
+
}));
|
|
4796
|
+
errorCb(err);
|
|
4797
|
+
};
|
|
4644
4798
|
request.onload = function () {
|
|
4645
4799
|
return _this4.parser({
|
|
4646
4800
|
text: request.responseText,
|
|
4647
4801
|
status: request.status
|
|
4648
|
-
}, cb,
|
|
4649
|
-
_this4.reportError(errorRepository, err, _extends(_extends({}, _this4.ctx), {
|
|
4650
|
-
classMethod: 'getClient',
|
|
4651
|
-
description: 'Send unsuccessful.'
|
|
4652
|
-
}));
|
|
4653
|
-
errorCb(err);
|
|
4654
|
-
});
|
|
4802
|
+
}, cb, onError);
|
|
4655
4803
|
};
|
|
4804
|
+
// Transport-level failures (dropped connection, failed CORS
|
|
4805
|
+
// preflight, HTTP/2 protocol error, timeout) never fire `onload`,
|
|
4806
|
+
// so without these handlers the request would fail silently.
|
|
4807
|
+
_this4.attachFailureHandlers(request, onError);
|
|
4656
4808
|
request.send(JSON.stringify(body));
|
|
4657
4809
|
}
|
|
4658
4810
|
};
|
|
@@ -4665,13 +4817,18 @@
|
|
|
4665
4817
|
return {
|
|
4666
4818
|
config: request,
|
|
4667
4819
|
send: function send(body) {
|
|
4668
|
-
return new Promise(function (resolve,
|
|
4820
|
+
return new Promise(function (resolve, reject) {
|
|
4669
4821
|
request.onload = function () {
|
|
4670
4822
|
return resolve({
|
|
4671
4823
|
text: request.responseText,
|
|
4672
4824
|
status: request.status
|
|
4673
4825
|
});
|
|
4674
4826
|
};
|
|
4827
|
+
// Transport-level failures (dropped connection, failed CORS
|
|
4828
|
+
// preflight, HTTP/2 protocol error, timeout) never fire
|
|
4829
|
+
// `onload`, so without these handlers the promise would never
|
|
4830
|
+
// settle and the caller would hang silently.
|
|
4831
|
+
_this5.attachFailureHandlers(request, reject);
|
|
4675
4832
|
request.send(JSON.stringify(body));
|
|
4676
4833
|
}).then(function (value) {
|
|
4677
4834
|
return _this5.parserPromise(value);
|
|
@@ -4723,6 +4880,36 @@
|
|
|
4723
4880
|
return Promise.reject(err);
|
|
4724
4881
|
}
|
|
4725
4882
|
}
|
|
4883
|
+
/**
|
|
4884
|
+
* Wires the XHR failure events that `onload` does not cover. `onload` only
|
|
4885
|
+
* fires when an HTTP response is received (any status, including 4xx/5xx);
|
|
4886
|
+
* transport-level failures — a dropped connection, a failed CORS preflight,
|
|
4887
|
+
* an HTTP/2 protocol error, or a timeout — fire `onerror`/`ontimeout`/
|
|
4888
|
+
* `onabort` instead. Without these the request never settles and fails
|
|
4889
|
+
* silently (e.g. `onUnavailable` is never invoked for wallet callbacks).
|
|
4890
|
+
*/
|
|
4891
|
+
}, {
|
|
4892
|
+
key: "attachFailureHandlers",
|
|
4893
|
+
value: function attachFailureHandlers(request, onFailure) {
|
|
4894
|
+
request.onerror = function () {
|
|
4895
|
+
return onFailure({
|
|
4896
|
+
message: 'Network request failed: the service could not be reached.',
|
|
4897
|
+
code: ERROR_CAUSE.SERVICE_UNREACHABLE
|
|
4898
|
+
});
|
|
4899
|
+
};
|
|
4900
|
+
request.ontimeout = function () {
|
|
4901
|
+
return onFailure({
|
|
4902
|
+
message: 'Network request timed out: the service could not be reached.',
|
|
4903
|
+
code: ERROR_CAUSE.SERVICE_UNREACHABLE
|
|
4904
|
+
});
|
|
4905
|
+
};
|
|
4906
|
+
request.onabort = function () {
|
|
4907
|
+
return onFailure({
|
|
4908
|
+
message: 'Network request was aborted.',
|
|
4909
|
+
code: ERROR_CAUSE.ABORTED
|
|
4910
|
+
});
|
|
4911
|
+
};
|
|
4912
|
+
}
|
|
4726
4913
|
}, {
|
|
4727
4914
|
key: "newApiRequest",
|
|
4728
4915
|
value: function newApiRequest(method, link) {
|
|
@@ -5481,12 +5668,12 @@
|
|
|
5481
5668
|
return _createClass(Uuid, null, [{
|
|
5482
5669
|
key: "generate",
|
|
5483
5670
|
value: function generate() {
|
|
5484
|
-
if (typeof window !==
|
|
5671
|
+
if (typeof window !== 'undefined' && typeof window.crypto !== 'undefined' && typeof window.crypto.getRandomValues !== 'undefined') {
|
|
5485
5672
|
var buf = new Uint16Array(8);
|
|
5486
5673
|
window.crypto.getRandomValues(buf);
|
|
5487
|
-
return
|
|
5674
|
+
return Uuid.hash(buf[0]) + Uuid.hash(buf[1]) + '-' + Uuid.hash(buf[2]) + '-' + Uuid.hash(buf[3]) + '-' + Uuid.hash(buf[4]) + '-' + Uuid.hash(buf[5]) + Uuid.hash(buf[6]) + Uuid.hash(buf[7]);
|
|
5488
5675
|
} else {
|
|
5489
|
-
return
|
|
5676
|
+
return Uuid.random() + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + '-' + Uuid.random() + Uuid.random() + Uuid.random();
|
|
5490
5677
|
}
|
|
5491
5678
|
}
|
|
5492
5679
|
}, {
|
|
@@ -5494,14 +5681,22 @@
|
|
|
5494
5681
|
value: function hash(number) {
|
|
5495
5682
|
var hash = number.toString(16);
|
|
5496
5683
|
while (hash.length < 4) {
|
|
5497
|
-
hash =
|
|
5684
|
+
hash = '0' + hash;
|
|
5498
5685
|
}
|
|
5499
5686
|
return hash;
|
|
5500
5687
|
}
|
|
5501
5688
|
}, {
|
|
5502
5689
|
key: "random",
|
|
5503
5690
|
value: function random() {
|
|
5504
|
-
|
|
5691
|
+
var value;
|
|
5692
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
5693
|
+
var buf = new Uint16Array(1);
|
|
5694
|
+
crypto.getRandomValues(buf);
|
|
5695
|
+
value = buf[0] / 0x10000;
|
|
5696
|
+
} else {
|
|
5697
|
+
value = Math.random();
|
|
5698
|
+
}
|
|
5699
|
+
return Math.floor((1 + value) * 0x10000).toString(16).substring(1);
|
|
5505
5700
|
}
|
|
5506
5701
|
}]);
|
|
5507
5702
|
}();
|
|
@@ -8176,7 +8371,7 @@
|
|
|
8176
8371
|
}]);
|
|
8177
8372
|
}(WalletService);
|
|
8178
8373
|
|
|
8179
|
-
/*! @license DOMPurify 3.4.
|
|
8374
|
+
/*! @license DOMPurify 3.4.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.11/LICENSE */
|
|
8180
8375
|
|
|
8181
8376
|
var purify_cjs;
|
|
8182
8377
|
var hasRequiredPurify_cjs;
|
|
@@ -8185,22 +8380,63 @@
|
|
|
8185
8380
|
if (hasRequiredPurify_cjs) return purify_cjs;
|
|
8186
8381
|
hasRequiredPurify_cjs = 1;
|
|
8187
8382
|
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8383
|
+
function _arrayLikeToArray(r, a) {
|
|
8384
|
+
(null == a || a > r.length) && (a = r.length);
|
|
8385
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8386
|
+
return n;
|
|
8387
|
+
}
|
|
8388
|
+
function _arrayWithHoles(r) {
|
|
8389
|
+
if (Array.isArray(r)) return r;
|
|
8390
|
+
}
|
|
8391
|
+
function _iterableToArrayLimit(r, l) {
|
|
8392
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
8393
|
+
if (null != t) {
|
|
8394
|
+
var e,
|
|
8395
|
+
n,
|
|
8396
|
+
i,
|
|
8397
|
+
u,
|
|
8398
|
+
a = [],
|
|
8399
|
+
f = true,
|
|
8400
|
+
o = false;
|
|
8401
|
+
try {
|
|
8402
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
8403
|
+
} catch (r) {
|
|
8404
|
+
o = true, n = r;
|
|
8405
|
+
} finally {
|
|
8406
|
+
try {
|
|
8407
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
8408
|
+
} finally {
|
|
8409
|
+
if (o) throw n;
|
|
8410
|
+
}
|
|
8411
|
+
}
|
|
8412
|
+
return a;
|
|
8413
|
+
}
|
|
8414
|
+
}
|
|
8415
|
+
function _nonIterableRest() {
|
|
8416
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
8417
|
+
}
|
|
8418
|
+
function _slicedToArray(r, e) {
|
|
8419
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
8420
|
+
}
|
|
8421
|
+
function _unsupportedIterableToArray(r, a) {
|
|
8422
|
+
if (r) {
|
|
8423
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
8424
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
8425
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
8426
|
+
}
|
|
8427
|
+
}
|
|
8428
|
+
|
|
8429
|
+
const entries = Object.entries,
|
|
8430
|
+
setPrototypeOf = Object.setPrototypeOf,
|
|
8431
|
+
isFrozen = Object.isFrozen,
|
|
8432
|
+
getPrototypeOf = Object.getPrototypeOf,
|
|
8433
|
+
getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
8434
|
+
let freeze = Object.freeze,
|
|
8435
|
+
seal = Object.seal,
|
|
8436
|
+
create = Object.create; // eslint-disable-line import/no-mutable-exports
|
|
8437
|
+
let _ref = typeof Reflect !== 'undefined' && Reflect,
|
|
8438
|
+
apply = _ref.apply,
|
|
8439
|
+
construct = _ref.construct;
|
|
8204
8440
|
if (!freeze) {
|
|
8205
8441
|
freeze = function freeze(x) {
|
|
8206
8442
|
return x;
|
|
@@ -8232,13 +8468,19 @@
|
|
|
8232
8468
|
const arrayPop = unapply(Array.prototype.pop);
|
|
8233
8469
|
const arrayPush = unapply(Array.prototype.push);
|
|
8234
8470
|
const arraySplice = unapply(Array.prototype.splice);
|
|
8471
|
+
const arrayIsArray = Array.isArray;
|
|
8235
8472
|
const stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
8236
8473
|
const stringToString = unapply(String.prototype.toString);
|
|
8237
8474
|
const stringMatch = unapply(String.prototype.match);
|
|
8238
8475
|
const stringReplace = unapply(String.prototype.replace);
|
|
8239
8476
|
const stringIndexOf = unapply(String.prototype.indexOf);
|
|
8240
8477
|
const stringTrim = unapply(String.prototype.trim);
|
|
8478
|
+
const numberToString = unapply(Number.prototype.toString);
|
|
8479
|
+
const booleanToString = unapply(Boolean.prototype.toString);
|
|
8480
|
+
const bigintToString = typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);
|
|
8481
|
+
const symbolToString = typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);
|
|
8241
8482
|
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
8483
|
+
const objectToString = unapply(Object.prototype.toString);
|
|
8242
8484
|
const regExpTest = unapply(RegExp.prototype.test);
|
|
8243
8485
|
const typeErrorCreate = unconstruct(TypeError);
|
|
8244
8486
|
/**
|
|
@@ -8288,6 +8530,9 @@
|
|
|
8288
8530
|
// Prevent prototype setters from intercepting set as a this value.
|
|
8289
8531
|
setPrototypeOf(set, null);
|
|
8290
8532
|
}
|
|
8533
|
+
if (!arrayIsArray(array)) {
|
|
8534
|
+
return set;
|
|
8535
|
+
}
|
|
8291
8536
|
let l = array.length;
|
|
8292
8537
|
while (l--) {
|
|
8293
8538
|
let element = array[l];
|
|
@@ -8328,10 +8573,13 @@
|
|
|
8328
8573
|
*/
|
|
8329
8574
|
function clone(object) {
|
|
8330
8575
|
const newObject = create(null);
|
|
8331
|
-
for (const
|
|
8576
|
+
for (const _ref2 of entries(object)) {
|
|
8577
|
+
var _ref3 = _slicedToArray(_ref2, 2);
|
|
8578
|
+
const property = _ref3[0];
|
|
8579
|
+
const value = _ref3[1];
|
|
8332
8580
|
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
8333
8581
|
if (isPropertyExist) {
|
|
8334
|
-
if (
|
|
8582
|
+
if (arrayIsArray(value)) {
|
|
8335
8583
|
newObject[property] = cleanArray(value);
|
|
8336
8584
|
} else if (value && typeof value === 'object' && value.constructor === Object) {
|
|
8337
8585
|
newObject[property] = clone(value);
|
|
@@ -8342,6 +8590,58 @@
|
|
|
8342
8590
|
}
|
|
8343
8591
|
return newObject;
|
|
8344
8592
|
}
|
|
8593
|
+
/**
|
|
8594
|
+
* Convert non-node values into strings without depending on direct property access.
|
|
8595
|
+
*
|
|
8596
|
+
* @param value - The value to stringify.
|
|
8597
|
+
* @returns A string representation of the provided value.
|
|
8598
|
+
*/
|
|
8599
|
+
function stringifyValue(value) {
|
|
8600
|
+
switch (typeof value) {
|
|
8601
|
+
case 'string':
|
|
8602
|
+
{
|
|
8603
|
+
return value;
|
|
8604
|
+
}
|
|
8605
|
+
case 'number':
|
|
8606
|
+
{
|
|
8607
|
+
return numberToString(value);
|
|
8608
|
+
}
|
|
8609
|
+
case 'boolean':
|
|
8610
|
+
{
|
|
8611
|
+
return booleanToString(value);
|
|
8612
|
+
}
|
|
8613
|
+
case 'bigint':
|
|
8614
|
+
{
|
|
8615
|
+
return bigintToString ? bigintToString(value) : '0';
|
|
8616
|
+
}
|
|
8617
|
+
case 'symbol':
|
|
8618
|
+
{
|
|
8619
|
+
return symbolToString ? symbolToString(value) : 'Symbol()';
|
|
8620
|
+
}
|
|
8621
|
+
case 'undefined':
|
|
8622
|
+
{
|
|
8623
|
+
return objectToString(value);
|
|
8624
|
+
}
|
|
8625
|
+
case 'function':
|
|
8626
|
+
case 'object':
|
|
8627
|
+
{
|
|
8628
|
+
if (value === null) {
|
|
8629
|
+
return objectToString(value);
|
|
8630
|
+
}
|
|
8631
|
+
const valueAsRecord = value;
|
|
8632
|
+
const valueToString = lookupGetter(valueAsRecord, 'toString');
|
|
8633
|
+
if (typeof valueToString === 'function') {
|
|
8634
|
+
const stringified = valueToString(valueAsRecord);
|
|
8635
|
+
return typeof stringified === 'string' ? stringified : objectToString(stringified);
|
|
8636
|
+
}
|
|
8637
|
+
return objectToString(value);
|
|
8638
|
+
}
|
|
8639
|
+
default:
|
|
8640
|
+
{
|
|
8641
|
+
return objectToString(value);
|
|
8642
|
+
}
|
|
8643
|
+
}
|
|
8644
|
+
}
|
|
8345
8645
|
/**
|
|
8346
8646
|
* This method automatically checks if the prop is function or getter and behaves accordingly.
|
|
8347
8647
|
*
|
|
@@ -8367,6 +8667,14 @@
|
|
|
8367
8667
|
}
|
|
8368
8668
|
return fallbackValue;
|
|
8369
8669
|
}
|
|
8670
|
+
function isRegex(value) {
|
|
8671
|
+
try {
|
|
8672
|
+
regExpTest(value, '');
|
|
8673
|
+
return true;
|
|
8674
|
+
} catch (_unused) {
|
|
8675
|
+
return false;
|
|
8676
|
+
}
|
|
8677
|
+
}
|
|
8370
8678
|
|
|
8371
8679
|
const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
|
|
8372
8680
|
const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
|
|
@@ -8382,15 +8690,14 @@
|
|
|
8382
8690
|
const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
|
|
8383
8691
|
const text = freeze(['#text']);
|
|
8384
8692
|
|
|
8385
|
-
const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns'
|
|
8693
|
+
const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'command', 'commandfor', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns']);
|
|
8386
8694
|
const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
|
|
8387
8695
|
const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lquote', 'lspace', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
|
|
8388
8696
|
const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
|
|
8389
8697
|
|
|
8390
|
-
|
|
8391
|
-
const
|
|
8392
|
-
const
|
|
8393
|
-
const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
|
|
8698
|
+
const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
|
|
8699
|
+
const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
|
|
8700
|
+
const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
|
|
8394
8701
|
const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
|
|
8395
8702
|
const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
|
|
8396
8703
|
const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
|
|
@@ -8400,30 +8707,31 @@
|
|
|
8400
8707
|
);
|
|
8401
8708
|
const DOCTYPE_NAME = seal(/^html$/i);
|
|
8402
8709
|
const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
8710
|
+
// Markup-significant character probes used by _sanitizeElements.
|
|
8711
|
+
// Shared module-level instances are safe despite the sticky /g flags:
|
|
8712
|
+
// unapply() resets lastIndex for RegExp receivers before every call.
|
|
8713
|
+
const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
|
|
8714
|
+
const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
|
|
8715
|
+
const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
|
|
8716
|
+
const SELF_CLOSING_TAG = seal(/\/>/i);
|
|
8403
8717
|
|
|
8404
|
-
var EXPRESSIONS = /*#__PURE__*/Object.freeze({
|
|
8405
|
-
__proto__: null,
|
|
8406
|
-
ARIA_ATTR: ARIA_ATTR,
|
|
8407
|
-
ATTR_WHITESPACE: ATTR_WHITESPACE,
|
|
8408
|
-
CUSTOM_ELEMENT: CUSTOM_ELEMENT,
|
|
8409
|
-
DATA_ATTR: DATA_ATTR,
|
|
8410
|
-
DOCTYPE_NAME: DOCTYPE_NAME,
|
|
8411
|
-
ERB_EXPR: ERB_EXPR,
|
|
8412
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI,
|
|
8413
|
-
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
|
|
8414
|
-
MUSTACHE_EXPR: MUSTACHE_EXPR,
|
|
8415
|
-
TMPLIT_EXPR: TMPLIT_EXPR
|
|
8416
|
-
});
|
|
8417
|
-
|
|
8418
|
-
/* eslint-disable @typescript-eslint/indent */
|
|
8419
8718
|
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
|
|
8420
8719
|
const NODE_TYPE = {
|
|
8421
8720
|
element: 1,
|
|
8721
|
+
attribute: 2,
|
|
8422
8722
|
text: 3,
|
|
8723
|
+
cdataSection: 4,
|
|
8724
|
+
entityReference: 5,
|
|
8423
8725
|
// Deprecated
|
|
8424
|
-
|
|
8726
|
+
entityNode: 6,
|
|
8727
|
+
// Deprecated
|
|
8728
|
+
processingInstruction: 7,
|
|
8425
8729
|
comment: 8,
|
|
8426
|
-
document: 9
|
|
8730
|
+
document: 9,
|
|
8731
|
+
documentType: 10,
|
|
8732
|
+
documentFragment: 11,
|
|
8733
|
+
notation: 12 // Deprecated
|
|
8734
|
+
};
|
|
8427
8735
|
const getGlobal = function getGlobal() {
|
|
8428
8736
|
return typeof window === 'undefined' ? null : window;
|
|
8429
8737
|
};
|
|
@@ -8478,10 +8786,25 @@
|
|
|
8478
8786
|
uponSanitizeShadowNode: []
|
|
8479
8787
|
};
|
|
8480
8788
|
};
|
|
8789
|
+
/**
|
|
8790
|
+
* Resolve a set-valued configuration option: a fresh set built from
|
|
8791
|
+
* cfg[key] when it is an own array property (seeded with a clone of
|
|
8792
|
+
* options.base when given, case-normalized via options.transform),
|
|
8793
|
+
* the fallback set otherwise.
|
|
8794
|
+
*
|
|
8795
|
+
* @param cfg the cloned, prototype-free configuration object
|
|
8796
|
+
* @param key the configuration property to read
|
|
8797
|
+
* @param fallback the set to use when the option is absent or not an array
|
|
8798
|
+
* @param options transform and optional base set to merge into
|
|
8799
|
+
* @returns the resolved set
|
|
8800
|
+
*/
|
|
8801
|
+
const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
|
|
8802
|
+
return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
|
|
8803
|
+
};
|
|
8481
8804
|
function createDOMPurify() {
|
|
8482
8805
|
let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
|
|
8483
8806
|
const DOMPurify = root => createDOMPurify(root);
|
|
8484
|
-
DOMPurify.version = '3.4.
|
|
8807
|
+
DOMPurify.version = '3.4.11';
|
|
8485
8808
|
DOMPurify.removed = [];
|
|
8486
8809
|
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
|
|
8487
8810
|
// Not running in a browser, provide a factory function
|
|
@@ -8489,28 +8812,29 @@
|
|
|
8489
8812
|
DOMPurify.isSupported = false;
|
|
8490
8813
|
return DOMPurify;
|
|
8491
8814
|
}
|
|
8492
|
-
let
|
|
8493
|
-
document
|
|
8494
|
-
} = window;
|
|
8815
|
+
let document = window.document;
|
|
8495
8816
|
const originalDocument = document;
|
|
8496
8817
|
const currentScript = originalDocument.currentScript;
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
|
|
8503
|
-
NamedNodeMap
|
|
8504
|
-
HTMLFormElement
|
|
8505
|
-
DOMParser,
|
|
8506
|
-
trustedTypes
|
|
8507
|
-
} = window;
|
|
8818
|
+
window.DocumentFragment;
|
|
8819
|
+
const HTMLTemplateElement = window.HTMLTemplateElement,
|
|
8820
|
+
Node = window.Node,
|
|
8821
|
+
Element = window.Element,
|
|
8822
|
+
NodeFilter = window.NodeFilter,
|
|
8823
|
+
_window$NamedNodeMap = window.NamedNodeMap;
|
|
8824
|
+
_window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap;
|
|
8825
|
+
window.HTMLFormElement;
|
|
8826
|
+
const DOMParser = window.DOMParser,
|
|
8827
|
+
trustedTypes = window.trustedTypes;
|
|
8508
8828
|
const ElementPrototype = Element.prototype;
|
|
8509
8829
|
const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
|
|
8510
8830
|
const remove = lookupGetter(ElementPrototype, 'remove');
|
|
8511
8831
|
const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
|
|
8512
8832
|
const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
|
|
8513
8833
|
const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
|
|
8834
|
+
const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');
|
|
8835
|
+
const getAttributes = lookupGetter(ElementPrototype, 'attributes');
|
|
8836
|
+
const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;
|
|
8837
|
+
const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;
|
|
8514
8838
|
// As per issue #47, the web-components registry is inherited by a
|
|
8515
8839
|
// new document created via createHTMLDocument. As per the spec
|
|
8516
8840
|
// (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
|
|
@@ -8525,33 +8849,74 @@
|
|
|
8525
8849
|
}
|
|
8526
8850
|
let trustedTypesPolicy;
|
|
8527
8851
|
let emptyHTML = '';
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8852
|
+
// The instance's own internal Trusted Types policy. Unlike a caller-supplied
|
|
8853
|
+
// `TRUSTED_TYPES_POLICY`, this is created at most once — Trusted Types throws
|
|
8854
|
+
// on duplicate policy names — and is the only policy allowed to persist
|
|
8855
|
+
// across configurations and survive `clearConfig()`.
|
|
8856
|
+
let defaultTrustedTypesPolicy;
|
|
8857
|
+
let defaultTrustedTypesPolicyResolved = false;
|
|
8858
|
+
// Tracks whether we are already inside a call to the configured Trusted Types
|
|
8859
|
+
// policy (`createHTML` or `createScriptURL`). If a supplied policy callback
|
|
8860
|
+
// itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would
|
|
8861
|
+
// re-enter the policy and recurse until the stack overflows. We detect that
|
|
8862
|
+
// re-entry and throw a clear, actionable error instead. The guard is shared
|
|
8863
|
+
// across both callbacks, because either one re-entering `sanitize` triggers
|
|
8864
|
+
// the same unbounded recursion.
|
|
8865
|
+
let IN_TRUSTED_TYPES_POLICY = 0;
|
|
8866
|
+
const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy() {
|
|
8867
|
+
if (IN_TRUSTED_TYPES_POLICY > 0) {
|
|
8868
|
+
throw typeErrorCreate('A configured TRUSTED_TYPES_POLICY callback (createHTML or ' + 'createScriptURL) must not call DOMPurify.sanitize, as that causes ' + 'infinite recursion. Do not pass a policy whose callbacks wrap ' + 'DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted ' + 'Types" section of the README.');
|
|
8869
|
+
}
|
|
8870
|
+
};
|
|
8871
|
+
const _createTrustedHTML = function _createTrustedHTML(html) {
|
|
8872
|
+
_assertNotInTrustedTypesPolicy();
|
|
8873
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
8874
|
+
try {
|
|
8875
|
+
return trustedTypesPolicy.createHTML(html);
|
|
8876
|
+
} finally {
|
|
8877
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
8878
|
+
}
|
|
8879
|
+
};
|
|
8880
|
+
const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
|
|
8881
|
+
_assertNotInTrustedTypesPolicy();
|
|
8882
|
+
IN_TRUSTED_TYPES_POLICY++;
|
|
8883
|
+
try {
|
|
8884
|
+
return trustedTypesPolicy.createScriptURL(scriptUrl);
|
|
8885
|
+
} finally {
|
|
8886
|
+
IN_TRUSTED_TYPES_POLICY--;
|
|
8887
|
+
}
|
|
8888
|
+
};
|
|
8889
|
+
// Lazily resolve (and cache) the instance's internal default policy.
|
|
8890
|
+
// Resolution is attempted at most once: a successful `createPolicy` cannot be
|
|
8891
|
+
// repeated (Trusted Types throws on duplicate names), and a failed or
|
|
8892
|
+
// unsupported attempt must not be retried on every parse.
|
|
8893
|
+
const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy() {
|
|
8894
|
+
if (!defaultTrustedTypesPolicyResolved) {
|
|
8895
|
+
defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
8896
|
+
defaultTrustedTypesPolicyResolved = true;
|
|
8897
|
+
}
|
|
8898
|
+
return defaultTrustedTypesPolicy;
|
|
8899
|
+
};
|
|
8900
|
+
const _document = document,
|
|
8901
|
+
implementation = _document.implementation,
|
|
8902
|
+
createNodeIterator = _document.createNodeIterator,
|
|
8903
|
+
createDocumentFragment = _document.createDocumentFragment,
|
|
8904
|
+
getElementsByTagName = _document.getElementsByTagName;
|
|
8905
|
+
const importNode = originalDocument.importNode;
|
|
8537
8906
|
let hooks = _createHooksMap();
|
|
8538
8907
|
/**
|
|
8539
8908
|
* Expose whether this browser supports running the full DOMPurify.
|
|
8540
8909
|
*/
|
|
8541
8910
|
DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
|
|
8542
|
-
const
|
|
8543
|
-
|
|
8544
|
-
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
} = EXPRESSIONS;
|
|
8552
|
-
let {
|
|
8553
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
8554
|
-
} = EXPRESSIONS;
|
|
8911
|
+
const MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
|
|
8912
|
+
ERB_EXPR$1 = ERB_EXPR,
|
|
8913
|
+
TMPLIT_EXPR$1 = TMPLIT_EXPR,
|
|
8914
|
+
DATA_ATTR$1 = DATA_ATTR,
|
|
8915
|
+
ARIA_ATTR$1 = ARIA_ATTR,
|
|
8916
|
+
IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
|
|
8917
|
+
ATTR_WHITESPACE$1 = ATTR_WHITESPACE,
|
|
8918
|
+
CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
|
|
8919
|
+
let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
|
|
8555
8920
|
/**
|
|
8556
8921
|
* We consider the elements and attributes below to be safe. Ideally
|
|
8557
8922
|
* don't add any new ones but feel free to remove unwanted ones.
|
|
@@ -8628,6 +8993,13 @@
|
|
|
8628
8993
|
let WHOLE_DOCUMENT = false;
|
|
8629
8994
|
/* Track whether config is already set on this instance of DOMPurify. */
|
|
8630
8995
|
let SET_CONFIG = false;
|
|
8996
|
+
/* Pristine allowlist bindings captured at setConfig() time. On the
|
|
8997
|
+
* persistent-config path sanitize() restores the sets from these before
|
|
8998
|
+
* the per-walk hook clone-guard, so a hook's in-call widening cannot
|
|
8999
|
+
* carry across calls. Null until setConfig() is called; reset by
|
|
9000
|
+
* clearConfig(). */
|
|
9001
|
+
let SET_CONFIG_ALLOWED_TAGS = null;
|
|
9002
|
+
let SET_CONFIG_ALLOWED_ATTR = null;
|
|
8631
9003
|
/* Decide if all elements (e.g. style, script) must be children of
|
|
8632
9004
|
* document.body. By default, browsers might move them to document.head */
|
|
8633
9005
|
let FORCE_BODY = false;
|
|
@@ -8670,7 +9042,17 @@
|
|
|
8670
9042
|
let USE_PROFILES = {};
|
|
8671
9043
|
/* Tags to ignore content of when KEEP_CONTENT is true */
|
|
8672
9044
|
let FORBID_CONTENTS = null;
|
|
8673
|
-
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
9045
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script',
|
|
9046
|
+
// <selectedcontent> mirrors the selected <option>'s subtree, cloned by
|
|
9047
|
+
// the UA (customizable <select>) — including any on* handlers — and the
|
|
9048
|
+
// engine re-mirrors synchronously whenever a removal changes which
|
|
9049
|
+
// option/selectedcontent is current, even inside DOMPurify's inert
|
|
9050
|
+
// DOMParser document. Hoisting its children on removal re-inserts a fresh
|
|
9051
|
+
// mirror target ahead of the walk, which the engine refills, looping
|
|
9052
|
+
// forever (DoS) and amplifying output. Dropping its content on removal
|
|
9053
|
+
// (rather than hoisting) breaks that cascade; the content is a duplicate
|
|
9054
|
+
// of the option, which is sanitized on its own. See campaign-3 F1/F6.
|
|
9055
|
+
'selectedcontent', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
|
|
8674
9056
|
/* Tags that are safe for data: URIs */
|
|
8675
9057
|
let DATA_URI_TAGS = null;
|
|
8676
9058
|
const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
|
|
@@ -8686,8 +9068,10 @@
|
|
|
8686
9068
|
/* Allowed XHTML+XML namespaces */
|
|
8687
9069
|
let ALLOWED_NAMESPACES = null;
|
|
8688
9070
|
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
8689
|
-
|
|
8690
|
-
let
|
|
9071
|
+
const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(['mi', 'mo', 'mn', 'ms', 'mtext']);
|
|
9072
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
|
|
9073
|
+
const DEFAULT_HTML_INTEGRATION_POINTS = freeze(['annotation-xml']);
|
|
9074
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
|
|
8691
9075
|
// Certain elements are allowed in both SVG and HTML
|
|
8692
9076
|
// namespace. We need to specify them explicitly
|
|
8693
9077
|
// so that they don't get erroneously deleted from
|
|
@@ -8729,15 +9113,33 @@
|
|
|
8729
9113
|
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
|
|
8730
9114
|
transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
|
|
8731
9115
|
/* Set configuration parameters */
|
|
8732
|
-
ALLOWED_TAGS =
|
|
8733
|
-
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
9116
|
+
ALLOWED_TAGS = _resolveSetOption(cfg, 'ALLOWED_TAGS', DEFAULT_ALLOWED_TAGS, {
|
|
9117
|
+
transform: transformCaseFunc
|
|
9118
|
+
});
|
|
9119
|
+
ALLOWED_ATTR = _resolveSetOption(cfg, 'ALLOWED_ATTR', DEFAULT_ALLOWED_ATTR, {
|
|
9120
|
+
transform: transformCaseFunc
|
|
9121
|
+
});
|
|
9122
|
+
ALLOWED_NAMESPACES = _resolveSetOption(cfg, 'ALLOWED_NAMESPACES', DEFAULT_ALLOWED_NAMESPACES, {
|
|
9123
|
+
transform: stringToString
|
|
9124
|
+
});
|
|
9125
|
+
URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, 'ADD_URI_SAFE_ATTR', DEFAULT_URI_SAFE_ATTRIBUTES, {
|
|
9126
|
+
transform: transformCaseFunc,
|
|
9127
|
+
base: DEFAULT_URI_SAFE_ATTRIBUTES
|
|
9128
|
+
});
|
|
9129
|
+
DATA_URI_TAGS = _resolveSetOption(cfg, 'ADD_DATA_URI_TAGS', DEFAULT_DATA_URI_TAGS, {
|
|
9130
|
+
transform: transformCaseFunc,
|
|
9131
|
+
base: DEFAULT_DATA_URI_TAGS
|
|
9132
|
+
});
|
|
9133
|
+
FORBID_CONTENTS = _resolveSetOption(cfg, 'FORBID_CONTENTS', DEFAULT_FORBID_CONTENTS, {
|
|
9134
|
+
transform: transformCaseFunc
|
|
9135
|
+
});
|
|
9136
|
+
FORBID_TAGS = _resolveSetOption(cfg, 'FORBID_TAGS', clone({}), {
|
|
9137
|
+
transform: transformCaseFunc
|
|
9138
|
+
});
|
|
9139
|
+
FORBID_ATTR = _resolveSetOption(cfg, 'FORBID_ATTR', clone({}), {
|
|
9140
|
+
transform: transformCaseFunc
|
|
9141
|
+
});
|
|
9142
|
+
USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === 'object' ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
|
|
8741
9143
|
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
|
|
8742
9144
|
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
|
|
8743
9145
|
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
|
|
@@ -8753,20 +9155,22 @@
|
|
|
8753
9155
|
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
|
|
8754
9156
|
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
|
|
8755
9157
|
IN_PLACE = cfg.IN_PLACE || false; // Default false
|
|
8756
|
-
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP
|
|
8757
|
-
NAMESPACE = cfg.NAMESPACE
|
|
8758
|
-
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS
|
|
8759
|
-
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
9158
|
+
IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI; // Default regexp
|
|
9159
|
+
NAMESPACE = typeof cfg.NAMESPACE === 'string' ? cfg.NAMESPACE : HTML_NAMESPACE; // Default HTML namespace
|
|
9160
|
+
MATHML_TEXT_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'MATHML_TEXT_INTEGRATION_POINTS') && cfg.MATHML_TEXT_INTEGRATION_POINTS && typeof cfg.MATHML_TEXT_INTEGRATION_POINTS === 'object' ? clone(cfg.MATHML_TEXT_INTEGRATION_POINTS) : addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS); // Default built-in map
|
|
9161
|
+
HTML_INTEGRATION_POINTS = objectHasOwnProperty(cfg, 'HTML_INTEGRATION_POINTS') && cfg.HTML_INTEGRATION_POINTS && typeof cfg.HTML_INTEGRATION_POINTS === 'object' ? clone(cfg.HTML_INTEGRATION_POINTS) : addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS); // Default built-in map
|
|
9162
|
+
const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOM_ELEMENT_HANDLING') && cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING === 'object' ? clone(cfg.CUSTOM_ELEMENT_HANDLING) : create(null);
|
|
9163
|
+
CUSTOM_ELEMENT_HANDLING = create(null);
|
|
9164
|
+
if (objectHasOwnProperty(customElementHandling, 'tagNameCheck') && isRegexOrFunction(customElementHandling.tagNameCheck)) {
|
|
9165
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck; // Default undefined
|
|
8763
9166
|
}
|
|
8764
|
-
if (
|
|
8765
|
-
CUSTOM_ELEMENT_HANDLING.attributeNameCheck =
|
|
9167
|
+
if (objectHasOwnProperty(customElementHandling, 'attributeNameCheck') && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
|
|
9168
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck; // Default undefined
|
|
8766
9169
|
}
|
|
8767
|
-
if (
|
|
8768
|
-
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements =
|
|
9170
|
+
if (objectHasOwnProperty(customElementHandling, 'allowCustomizedBuiltInElements') && typeof customElementHandling.allowCustomizedBuiltInElements === 'boolean') {
|
|
9171
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements; // Default undefined
|
|
8769
9172
|
}
|
|
9173
|
+
seal(CUSTOM_ELEMENT_HANDLING);
|
|
8770
9174
|
if (SAFE_FOR_TEMPLATES) {
|
|
8771
9175
|
ALLOW_DATA_ATTR = false;
|
|
8772
9176
|
}
|
|
@@ -8802,36 +9206,36 @@
|
|
|
8802
9206
|
EXTRA_ELEMENT_HANDLING.tagCheck = null;
|
|
8803
9207
|
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
|
|
8804
9208
|
/* Merge configuration parameters */
|
|
8805
|
-
if (cfg
|
|
9209
|
+
if (objectHasOwnProperty(cfg, 'ADD_TAGS')) {
|
|
8806
9210
|
if (typeof cfg.ADD_TAGS === 'function') {
|
|
8807
9211
|
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
8808
|
-
} else {
|
|
9212
|
+
} else if (arrayIsArray(cfg.ADD_TAGS)) {
|
|
8809
9213
|
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
8810
9214
|
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
8811
9215
|
}
|
|
8812
9216
|
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
8813
9217
|
}
|
|
8814
9218
|
}
|
|
8815
|
-
if (cfg
|
|
9219
|
+
if (objectHasOwnProperty(cfg, 'ADD_ATTR')) {
|
|
8816
9220
|
if (typeof cfg.ADD_ATTR === 'function') {
|
|
8817
9221
|
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
8818
|
-
} else {
|
|
9222
|
+
} else if (arrayIsArray(cfg.ADD_ATTR)) {
|
|
8819
9223
|
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
8820
9224
|
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
8821
9225
|
}
|
|
8822
9226
|
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
8823
9227
|
}
|
|
8824
9228
|
}
|
|
8825
|
-
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
9229
|
+
if (objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') && arrayIsArray(cfg.ADD_URI_SAFE_ATTR)) {
|
|
8826
9230
|
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
8827
9231
|
}
|
|
8828
|
-
if (cfg.FORBID_CONTENTS) {
|
|
9232
|
+
if (objectHasOwnProperty(cfg, 'FORBID_CONTENTS') && arrayIsArray(cfg.FORBID_CONTENTS)) {
|
|
8829
9233
|
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
8830
9234
|
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
8831
9235
|
}
|
|
8832
9236
|
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
8833
9237
|
}
|
|
8834
|
-
if (cfg.ADD_FORBID_CONTENTS) {
|
|
9238
|
+
if (objectHasOwnProperty(cfg, 'ADD_FORBID_CONTENTS') && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
|
|
8835
9239
|
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
8836
9240
|
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
8837
9241
|
}
|
|
@@ -8850,6 +9254,13 @@
|
|
|
8850
9254
|
addToSet(ALLOWED_TAGS, ['tbody']);
|
|
8851
9255
|
delete FORBID_TAGS.tbody;
|
|
8852
9256
|
}
|
|
9257
|
+
// Re-derive the active Trusted Types policy from this configuration on
|
|
9258
|
+
// every parse. The active policy must never be sticky closure state that
|
|
9259
|
+
// outlives the config that set it: a caller-supplied policy left in place
|
|
9260
|
+
// after `clearConfig()` — or after a later call that supplied none, or
|
|
9261
|
+
// `TRUSTED_TYPES_POLICY: null` — could sign a subsequent "default"
|
|
9262
|
+
// `RETURN_TRUSTED_TYPE` result with a foreign, possibly unsafe policy.
|
|
9263
|
+
// See GHSA-vxr8-fq34-vvx9.
|
|
8853
9264
|
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
8854
9265
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
|
|
8855
9266
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
@@ -8857,18 +9268,45 @@
|
|
|
8857
9268
|
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
|
|
8858
9269
|
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
8859
9270
|
}
|
|
8860
|
-
//
|
|
9271
|
+
// A caller-supplied policy applies to this configuration only.
|
|
9272
|
+
const previousTrustedTypesPolicy = trustedTypesPolicy;
|
|
8861
9273
|
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
8862
|
-
// Sign local variables required by `sanitize`.
|
|
8863
|
-
|
|
9274
|
+
// Sign local variables required by `sanitize`. If the supplied policy's
|
|
9275
|
+
// `createHTML` is circular (i.e. it calls `DOMPurify.sanitize`), this
|
|
9276
|
+
// throws via the re-entrancy guard. Restore the previous policy first so
|
|
9277
|
+
// the instance is not left in a poisoned state. See #1422.
|
|
9278
|
+
try {
|
|
9279
|
+
emptyHTML = _createTrustedHTML('');
|
|
9280
|
+
} catch (error) {
|
|
9281
|
+
trustedTypesPolicy = previousTrustedTypesPolicy;
|
|
9282
|
+
throw error;
|
|
9283
|
+
}
|
|
9284
|
+
} else if (cfg.TRUSTED_TYPES_POLICY === null) {
|
|
9285
|
+
// Explicit opt-out for this call: perform no Trusted Types signing and
|
|
9286
|
+
// create nothing (so a strict `trusted-types` CSP that disallows a
|
|
9287
|
+
// `dompurify` policy can still call `sanitize` from inside its own
|
|
9288
|
+
// policy — see #1422). Resetting to `undefined` rather than a sticky
|
|
9289
|
+
// `null` also drops any previously retained caller policy, so it cannot
|
|
9290
|
+
// resurface on a later call, while still allowing the next config-less
|
|
9291
|
+
// call to restore the internal default policy. See GHSA-vxr8-fq34-vvx9.
|
|
9292
|
+
trustedTypesPolicy = undefined;
|
|
9293
|
+
emptyHTML = '';
|
|
8864
9294
|
} else {
|
|
8865
|
-
//
|
|
9295
|
+
// No policy supplied: keep the currently active policy if one is set — a
|
|
9296
|
+
// previously supplied policy is intentionally sticky across config-less
|
|
9297
|
+
// calls — otherwise fall back to the instance's own internal policy,
|
|
9298
|
+
// created at most once. (A policy supplied for a *single* call still
|
|
9299
|
+
// lingers by design; what must not linger is a policy whose configuration
|
|
9300
|
+
// has been torn down via `clearConfig()`, which restores the default.)
|
|
8866
9301
|
if (trustedTypesPolicy === undefined) {
|
|
8867
|
-
trustedTypesPolicy =
|
|
9302
|
+
trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
|
|
8868
9303
|
}
|
|
8869
|
-
//
|
|
8870
|
-
|
|
8871
|
-
|
|
9304
|
+
// Sign internal variables only when a policy is active. A falsy policy
|
|
9305
|
+
// (Trusted Types unsupported, creation failed, or an explicit opt-out)
|
|
9306
|
+
// leaves `emptyHTML` as a plain string, so we never call `.createHTML` on
|
|
9307
|
+
// a non-policy and throw. See #1422.
|
|
9308
|
+
if (trustedTypesPolicy && typeof emptyHTML === 'string') {
|
|
9309
|
+
emptyHTML = _createTrustedHTML('');
|
|
8872
9310
|
}
|
|
8873
9311
|
}
|
|
8874
9312
|
// Prevent further manipulation of configuration.
|
|
@@ -8883,6 +9321,77 @@
|
|
|
8883
9321
|
* correctly. */
|
|
8884
9322
|
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
8885
9323
|
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
9324
|
+
/**
|
|
9325
|
+
* Namespace rules for an element in the SVG namespace.
|
|
9326
|
+
*
|
|
9327
|
+
* @param tagName the element's lowercase tag name
|
|
9328
|
+
* @param parent the (possibly simulated) parent node
|
|
9329
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9330
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9331
|
+
*/
|
|
9332
|
+
const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
|
|
9333
|
+
// The only way to switch from HTML namespace to SVG
|
|
9334
|
+
// is via <svg>. If it happens via any other tag, then
|
|
9335
|
+
// it should be killed.
|
|
9336
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9337
|
+
return tagName === 'svg';
|
|
9338
|
+
}
|
|
9339
|
+
// The only way to switch from MathML to SVG is via <svg>
|
|
9340
|
+
// if the parent is either <annotation-xml> or a MathML
|
|
9341
|
+
// text integration point.
|
|
9342
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
9343
|
+
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
9344
|
+
}
|
|
9345
|
+
// We only allow elements that are defined in SVG
|
|
9346
|
+
// spec. All others are disallowed in SVG namespace.
|
|
9347
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
9348
|
+
};
|
|
9349
|
+
/**
|
|
9350
|
+
* Namespace rules for an element in the MathML namespace.
|
|
9351
|
+
*
|
|
9352
|
+
* @param tagName the element's lowercase tag name
|
|
9353
|
+
* @param parent the (possibly simulated) parent node
|
|
9354
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9355
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9356
|
+
*/
|
|
9357
|
+
const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
|
|
9358
|
+
// The only way to switch from HTML namespace to MathML
|
|
9359
|
+
// is via <math>. If it happens via any other tag, then
|
|
9360
|
+
// it should be killed.
|
|
9361
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
9362
|
+
return tagName === 'math';
|
|
9363
|
+
}
|
|
9364
|
+
// The only way to switch from SVG to MathML is via
|
|
9365
|
+
// <math> and HTML integration points
|
|
9366
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
9367
|
+
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
9368
|
+
}
|
|
9369
|
+
// We only allow elements that are defined in MathML
|
|
9370
|
+
// spec. All others are disallowed in MathML namespace.
|
|
9371
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
9372
|
+
};
|
|
9373
|
+
/**
|
|
9374
|
+
* Namespace rules for an element in the HTML namespace.
|
|
9375
|
+
*
|
|
9376
|
+
* @param tagName the element's lowercase tag name
|
|
9377
|
+
* @param parent the (possibly simulated) parent node
|
|
9378
|
+
* @param parentTagName the parent's lowercase tag name
|
|
9379
|
+
* @returns true if a spec-compliant parser could produce this element
|
|
9380
|
+
*/
|
|
9381
|
+
const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
|
|
9382
|
+
// The only way to switch from SVG to HTML is via
|
|
9383
|
+
// HTML integration points, and from MathML to HTML
|
|
9384
|
+
// is via MathML text integration points
|
|
9385
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
9386
|
+
return false;
|
|
9387
|
+
}
|
|
9388
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
9389
|
+
return false;
|
|
9390
|
+
}
|
|
9391
|
+
// We disallow tags that are specific for MathML
|
|
9392
|
+
// or SVG and should never appear in HTML namespace
|
|
9393
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
9394
|
+
};
|
|
8886
9395
|
/**
|
|
8887
9396
|
* @param element a DOM element whose namespace is being checked
|
|
8888
9397
|
* @returns Return false if the element has a
|
|
@@ -8905,51 +9414,13 @@
|
|
|
8905
9414
|
return false;
|
|
8906
9415
|
}
|
|
8907
9416
|
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
8908
|
-
|
|
8909
|
-
// is via <svg>. If it happens via any other tag, then
|
|
8910
|
-
// it should be killed.
|
|
8911
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
8912
|
-
return tagName === 'svg';
|
|
8913
|
-
}
|
|
8914
|
-
// The only way to switch from MathML to SVG is via`
|
|
8915
|
-
// svg if parent is either <annotation-xml> or MathML
|
|
8916
|
-
// text integration points.
|
|
8917
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
8918
|
-
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
8919
|
-
}
|
|
8920
|
-
// We only allow elements that are defined in SVG
|
|
8921
|
-
// spec. All others are disallowed in SVG namespace.
|
|
8922
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
9417
|
+
return _checkSvgNamespace(tagName, parent, parentTagName);
|
|
8923
9418
|
}
|
|
8924
9419
|
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
8925
|
-
|
|
8926
|
-
// is via <math>. If it happens via any other tag, then
|
|
8927
|
-
// it should be killed.
|
|
8928
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
8929
|
-
return tagName === 'math';
|
|
8930
|
-
}
|
|
8931
|
-
// The only way to switch from SVG to MathML is via
|
|
8932
|
-
// <math> and HTML integration points
|
|
8933
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
8934
|
-
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
8935
|
-
}
|
|
8936
|
-
// We only allow elements that are defined in MathML
|
|
8937
|
-
// spec. All others are disallowed in MathML namespace.
|
|
8938
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
9420
|
+
return _checkMathMlNamespace(tagName, parent, parentTagName);
|
|
8939
9421
|
}
|
|
8940
9422
|
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
8941
|
-
|
|
8942
|
-
// HTML integration points, and from MathML to HTML
|
|
8943
|
-
// is via MathML text integration points
|
|
8944
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
8945
|
-
return false;
|
|
8946
|
-
}
|
|
8947
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
8948
|
-
return false;
|
|
8949
|
-
}
|
|
8950
|
-
// We disallow tags that are specific for MathML
|
|
8951
|
-
// or SVG and should never appear in HTML namespace
|
|
8952
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
9423
|
+
return _checkHtmlNamespace(tagName, parent, parentTagName);
|
|
8953
9424
|
}
|
|
8954
9425
|
// For XHTML and XML documents that support custom namespaces
|
|
8955
9426
|
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
@@ -8974,7 +9445,74 @@
|
|
|
8974
9445
|
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
8975
9446
|
getParentNode(node).removeChild(node);
|
|
8976
9447
|
} catch (_) {
|
|
9448
|
+
/* The normal detach failed — this is reached for a parentless node
|
|
9449
|
+
(getParentNode() is null, so .removeChild throws). Element.prototype
|
|
9450
|
+
.remove() is itself a spec no-op on a parentless node, so a recorded
|
|
9451
|
+
"removal" would otherwise hand the caller back an intact,
|
|
9452
|
+
payload-bearing node (e.g. a detached IN_PLACE root the mXSS canary or
|
|
9453
|
+
the style-with-element-child rule decided to kill). Fail closed by
|
|
9454
|
+
throwing — exactly as a clobbered root does at the IN_PLACE entry —
|
|
9455
|
+
rather than trying to "neutralize" the node via its own methods.
|
|
9456
|
+
Neutralizing would mean calling getAttributeNames()/removeAttribute()
|
|
9457
|
+
on the node, both of which a <form> root can clobber via a named child
|
|
9458
|
+
(and _isClobbered does not even probe getAttributeNames), so the
|
|
9459
|
+
neutralize step could itself be silently defeated, leaving the payload
|
|
9460
|
+
intact. A throw touches only the cached, clobber-safe remove() and
|
|
9461
|
+
getParentNode(). Generalizes GHSA-r47g-fvhr-h676 (clobbered-form root)
|
|
9462
|
+
to every root-kill reason. REPORT-3.
|
|
9463
|
+
This lives inside the catch, so it never fires for a normally-removed
|
|
9464
|
+
in-tree node: those have a parent, removeChild() succeeds, and the
|
|
9465
|
+
catch is not entered. Only a kept (parentless) root reaches here. */
|
|
8977
9466
|
remove(node);
|
|
9467
|
+
if (!getParentNode(node)) {
|
|
9468
|
+
throw typeErrorCreate('a node selected for removal could not be detached from its tree ' + 'and cannot be safely returned; refusing to sanitize in place');
|
|
9469
|
+
}
|
|
9470
|
+
}
|
|
9471
|
+
};
|
|
9472
|
+
/**
|
|
9473
|
+
* _neutralizeRoot
|
|
9474
|
+
*
|
|
9475
|
+
* Fail-closed teardown of an in-place root after the sanitize walk aborts
|
|
9476
|
+
* (campaign-3 F2). An internal throw mid-walk — e.g. a page-registered
|
|
9477
|
+
* custom element's reaction detaches a node so `_forceRemove`'s deliberate
|
|
9478
|
+
* parentless guard throws, or any other re-entrant engine mutation — would
|
|
9479
|
+
* otherwise leave the caller's *live* tree half-sanitized, with everything
|
|
9480
|
+
* after the abort point still carrying its handlers. There is no safe way
|
|
9481
|
+
* to resume the walk (the tree mutated under us), so we strip the root bare:
|
|
9482
|
+
* remove every child and every attribute, then let the caller's catch see
|
|
9483
|
+
* the original error. Clobber-safe (cached `remove`/`childNodes`/`attributes`
|
|
9484
|
+
* getters; the root was already clobber-pre-flighted at the IN_PLACE entry).
|
|
9485
|
+
*
|
|
9486
|
+
* @param root the in-place root to empty
|
|
9487
|
+
*/
|
|
9488
|
+
const _neutralizeRoot = function _neutralizeRoot(root) {
|
|
9489
|
+
const childNodes = getChildNodes(root);
|
|
9490
|
+
if (childNodes) {
|
|
9491
|
+
const snapshot = [];
|
|
9492
|
+
arrayForEach(childNodes, child => {
|
|
9493
|
+
arrayPush(snapshot, child);
|
|
9494
|
+
});
|
|
9495
|
+
arrayForEach(snapshot, child => {
|
|
9496
|
+
try {
|
|
9497
|
+
remove(child);
|
|
9498
|
+
} catch (_) {
|
|
9499
|
+
/* Best-effort teardown; a still-attached child is handled below */
|
|
9500
|
+
}
|
|
9501
|
+
});
|
|
9502
|
+
}
|
|
9503
|
+
const attributes = getAttributes(root);
|
|
9504
|
+
if (attributes) {
|
|
9505
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
9506
|
+
const attribute = attributes[i];
|
|
9507
|
+
const name = attribute && attribute.name;
|
|
9508
|
+
if (typeof name === 'string') {
|
|
9509
|
+
try {
|
|
9510
|
+
root.removeAttribute(name);
|
|
9511
|
+
} catch (_) {
|
|
9512
|
+
/* Clobbered removeAttribute — ignore (fail-closed best effort) */
|
|
9513
|
+
}
|
|
9514
|
+
}
|
|
9515
|
+
}
|
|
8978
9516
|
}
|
|
8979
9517
|
};
|
|
8980
9518
|
/**
|
|
@@ -9009,6 +9547,72 @@
|
|
|
9009
9547
|
}
|
|
9010
9548
|
}
|
|
9011
9549
|
};
|
|
9550
|
+
/**
|
|
9551
|
+
* _stripDisallowedAttributes
|
|
9552
|
+
*
|
|
9553
|
+
* Removes every attribute the active configuration does not allow from a
|
|
9554
|
+
* single element, using the same allowlist as the main attribute pass (so
|
|
9555
|
+
* `on*` handlers go, but no `/^on/` blocklist is introduced). Used only to
|
|
9556
|
+
* neutralise nodes that are being discarded from an in-place tree.
|
|
9557
|
+
*
|
|
9558
|
+
* @param element the element to strip
|
|
9559
|
+
*/
|
|
9560
|
+
const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
|
|
9561
|
+
const attributes = getAttributes(element);
|
|
9562
|
+
if (!attributes) {
|
|
9563
|
+
return;
|
|
9564
|
+
}
|
|
9565
|
+
for (let i = attributes.length - 1; i >= 0; --i) {
|
|
9566
|
+
const attribute = attributes[i];
|
|
9567
|
+
const name = attribute && attribute.name;
|
|
9568
|
+
if (typeof name !== 'string' || ALLOWED_ATTR[transformCaseFunc(name)]) {
|
|
9569
|
+
continue;
|
|
9570
|
+
}
|
|
9571
|
+
try {
|
|
9572
|
+
element.removeAttribute(name);
|
|
9573
|
+
} catch (_) {
|
|
9574
|
+
/* Clobbered removeAttribute on a doomed node — ignore */
|
|
9575
|
+
}
|
|
9576
|
+
}
|
|
9577
|
+
};
|
|
9578
|
+
/**
|
|
9579
|
+
* _neutralizeSubtree
|
|
9580
|
+
*
|
|
9581
|
+
* Completes the audit-5 F1 fix across every removal path. The KEEP_CONTENT
|
|
9582
|
+
* move-hoist neutralises only disallowed-tag removals; clobber, mXSS-canary,
|
|
9583
|
+
* namespace, comment, processing-instruction and KEEP_CONTENT:false removals
|
|
9584
|
+
* all drop their subtree wholesale via `_forceRemove`. On the IN_PLACE path
|
|
9585
|
+
* those dropped nodes are detached from the caller's LIVE tree but a
|
|
9586
|
+
* handler-bearing original among them (an `<img onerror>`/`<video>` that was
|
|
9587
|
+
* loading) keeps its queued resource event, which fires in page scope after
|
|
9588
|
+
* sanitize returns. This walks a removed subtree and strips every attribute
|
|
9589
|
+
* the active configuration does not allow — so `on*` handlers are cancelled
|
|
9590
|
+
* through the SAME allowlist that governs kept nodes, not a separate `/^on/`
|
|
9591
|
+
* blocklist. Run synchronously before sanitize returns, i.e. before any
|
|
9592
|
+
* queued event can fire. Hook-free by design: these nodes leave the output,
|
|
9593
|
+
* so firing attribute hooks for them would be surprising. Clobber-safe reads;
|
|
9594
|
+
* a doomed clobbered node may shadow `removeAttribute` (its own attributes are
|
|
9595
|
+
* irrelevant — it is discarded — while its non-clobbered descendants, e.g.
|
|
9596
|
+
* the `<img>`, are reached and scrubbed).
|
|
9597
|
+
*
|
|
9598
|
+
* @param root the root of a removed subtree to neutralise
|
|
9599
|
+
*/
|
|
9600
|
+
const _neutralizeSubtree = function _neutralizeSubtree(root) {
|
|
9601
|
+
const stack = [root];
|
|
9602
|
+
while (stack.length > 0) {
|
|
9603
|
+
const node = stack.pop();
|
|
9604
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
9605
|
+
if (nodeType === NODE_TYPE.element) {
|
|
9606
|
+
_stripDisallowedAttributes(node);
|
|
9607
|
+
}
|
|
9608
|
+
const childNodes = getChildNodes(node);
|
|
9609
|
+
if (childNodes) {
|
|
9610
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
9611
|
+
stack.push(childNodes[i]);
|
|
9612
|
+
}
|
|
9613
|
+
}
|
|
9614
|
+
}
|
|
9615
|
+
};
|
|
9012
9616
|
/**
|
|
9013
9617
|
* _initDocument
|
|
9014
9618
|
*
|
|
@@ -9030,7 +9634,7 @@
|
|
|
9030
9634
|
// Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
|
|
9031
9635
|
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
|
|
9032
9636
|
}
|
|
9033
|
-
const dirtyPayload = trustedTypesPolicy ?
|
|
9637
|
+
const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
|
|
9034
9638
|
/*
|
|
9035
9639
|
* Use the DOMParser API by default, fallback later if needs be
|
|
9036
9640
|
* DOMParser not work for svg when has multiple root element.
|
|
@@ -9070,29 +9674,254 @@
|
|
|
9070
9674
|
// eslint-disable-next-line no-bitwise
|
|
9071
9675
|
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
9072
9676
|
};
|
|
9677
|
+
/**
|
|
9678
|
+
* Replace template expression syntax (mustache, ERB, template
|
|
9679
|
+
* literal) with a space; shared by all SAFE_FOR_TEMPLATES scrub
|
|
9680
|
+
* sites. Order matters: mustache, then ERB, then template literal.
|
|
9681
|
+
*
|
|
9682
|
+
* @param value the string to scrub
|
|
9683
|
+
* @returns the scrubbed string
|
|
9684
|
+
*/
|
|
9685
|
+
const _stripTemplateExpressions = function _stripTemplateExpressions(value) {
|
|
9686
|
+
value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
|
|
9687
|
+
value = stringReplace(value, ERB_EXPR$1, ' ');
|
|
9688
|
+
value = stringReplace(value, TMPLIT_EXPR$1, ' ');
|
|
9689
|
+
return value;
|
|
9690
|
+
};
|
|
9691
|
+
/**
|
|
9692
|
+
* Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
|
|
9693
|
+
* character data of an element subtree. Used as the final safety net for
|
|
9694
|
+
* SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
|
|
9695
|
+
* which only form after text-node normalization (e.g. fragments split across
|
|
9696
|
+
* stripped elements) cannot survive into a template-evaluating framework.
|
|
9697
|
+
*
|
|
9698
|
+
* Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
|
|
9699
|
+
* in place rather than round-tripping through innerHTML. This preserves
|
|
9700
|
+
* descendant node references (important for IN_PLACE callers), avoids a
|
|
9701
|
+
* serialize/reparse cycle, and reads literal character data — which means
|
|
9702
|
+
* `<%...%>` in text content matches the ERB regex against its real bytes
|
|
9703
|
+
* instead of the HTML-entity-escaped form innerHTML would produce.
|
|
9704
|
+
*
|
|
9705
|
+
* Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
|
|
9706
|
+
* attributes is performed during the per-node `_sanitizeAttributes` pass.
|
|
9707
|
+
*
|
|
9708
|
+
* @param node The root element whose character data should be scrubbed.
|
|
9709
|
+
*/
|
|
9710
|
+
const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
|
|
9711
|
+
var _node$querySelectorAl;
|
|
9712
|
+
node.normalize();
|
|
9713
|
+
const walker = createNodeIterator.call(node.ownerDocument || node, node,
|
|
9714
|
+
// eslint-disable-next-line no-bitwise
|
|
9715
|
+
NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
|
|
9716
|
+
let currentNode = walker.nextNode();
|
|
9717
|
+
while (currentNode) {
|
|
9718
|
+
currentNode.data = _stripTemplateExpressions(currentNode.data);
|
|
9719
|
+
currentNode = walker.nextNode();
|
|
9720
|
+
}
|
|
9721
|
+
// NodeIterator does not descend into <template>.content per the DOM spec,
|
|
9722
|
+
// so we must explicitly recurse into each template's content fragment,
|
|
9723
|
+
// mirroring the approach used by _sanitizeShadowDOM.
|
|
9724
|
+
const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, 'template');
|
|
9725
|
+
if (templates) {
|
|
9726
|
+
arrayForEach(templates, tmpl => {
|
|
9727
|
+
if (_isDocumentFragment(tmpl.content)) {
|
|
9728
|
+
_scrubTemplateExpressions2(tmpl.content);
|
|
9729
|
+
}
|
|
9730
|
+
});
|
|
9731
|
+
}
|
|
9732
|
+
};
|
|
9073
9733
|
/**
|
|
9074
9734
|
* _isClobbered
|
|
9075
9735
|
*
|
|
9736
|
+
* Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
|
|
9737
|
+
* interface with [LegacyOverrideBuiltIns]; a descendant element with a
|
|
9738
|
+
* `name` attribute matching a prototype property shadows that property
|
|
9739
|
+
* on direct reads. We use this check at the IN_PLACE entry-point and
|
|
9740
|
+
* during attribute sanitization to refuse clobbered forms.
|
|
9741
|
+
*
|
|
9076
9742
|
* @param element element to check for clobbering attacks
|
|
9077
9743
|
* @return true if clobbered, false if safe
|
|
9078
9744
|
*/
|
|
9079
9745
|
const _isClobbered = function _isClobbered(element) {
|
|
9080
|
-
|
|
9746
|
+
// Realm-independent tag-name probe. If we can't determine the tag
|
|
9747
|
+
// name at all, we can't reason about clobbering — return false
|
|
9748
|
+
// (the caller's other defences still apply).
|
|
9749
|
+
const realTagName = getNodeName ? getNodeName(element) : null;
|
|
9750
|
+
if (typeof realTagName !== 'string') {
|
|
9751
|
+
return false;
|
|
9752
|
+
}
|
|
9753
|
+
if (transformCaseFunc(realTagName) !== 'form') {
|
|
9754
|
+
return false;
|
|
9755
|
+
}
|
|
9756
|
+
return typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' ||
|
|
9757
|
+
// Realm-safe NamedNodeMap detection: equality against the cached
|
|
9758
|
+
// prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
|
|
9759
|
+
// makes the direct read diverge from the cached read; a clean form
|
|
9760
|
+
// (same-realm OR foreign-realm) has both reads pointing at the same
|
|
9761
|
+
// canonical NamedNodeMap.
|
|
9762
|
+
element.attributes !== getAttributes(element) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function' ||
|
|
9763
|
+
// NodeType clobbering probe. Cached Node.prototype.nodeType getter
|
|
9764
|
+
// returns the integer 1 for any Element regardless of realm; direct
|
|
9765
|
+
// read on a clobbered form (e.g. <input name="nodeType">) returns
|
|
9766
|
+
// the named child element. Cheap addition — nodeType is read from
|
|
9767
|
+
// an internal slot, no serialization cost — and removes a residual
|
|
9768
|
+
// clobbering surface used by several mXSS / PI / comment branches
|
|
9769
|
+
// in _sanitizeElements that compare currentNode.nodeType directly.
|
|
9770
|
+
element.nodeType !== getNodeType(element) ||
|
|
9771
|
+
// HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
|
|
9772
|
+
// "childNodes" shadows the prototype getter. Direct reads of
|
|
9773
|
+
// form.childNodes from a clobbered form return the named child
|
|
9774
|
+
// instead of the real NodeList, so any walk that reads it directly
|
|
9775
|
+
// skips the form's real children. Compare the direct read to the
|
|
9776
|
+
// cached Node.prototype getter — when the form's named-property
|
|
9777
|
+
// getter intercepts the read, the two values differ and we flag
|
|
9778
|
+
// the form. This catches every clobbering child type (input,
|
|
9779
|
+
// select, etc.) regardless of whether the named child happens to
|
|
9780
|
+
// carry a numeric .length, which a typeof-based probe would miss
|
|
9781
|
+
// (e.g. HTMLSelectElement.length is a defined unsigned-long).
|
|
9782
|
+
element.childNodes !== getChildNodes(element);
|
|
9081
9783
|
};
|
|
9082
9784
|
/**
|
|
9083
|
-
* Checks whether the given
|
|
9785
|
+
* Checks whether the given value is a DocumentFragment from any realm.
|
|
9786
|
+
*
|
|
9787
|
+
* The realm-independent replacement reads `nodeType` through the cached
|
|
9788
|
+
* Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
|
|
9789
|
+
* constant (11). nodeType is a numeric value resolved from the node's
|
|
9790
|
+
* internal slot, identical across realms for the same kind of node.
|
|
9791
|
+
*
|
|
9792
|
+
* @param value object to check
|
|
9793
|
+
* @return true if value is a DocumentFragment-shaped node from any realm
|
|
9794
|
+
*/
|
|
9795
|
+
const _isDocumentFragment = function _isDocumentFragment(value) {
|
|
9796
|
+
if (!getNodeType || typeof value !== 'object' || value === null) {
|
|
9797
|
+
return false;
|
|
9798
|
+
}
|
|
9799
|
+
try {
|
|
9800
|
+
return getNodeType(value) === NODE_TYPE.documentFragment;
|
|
9801
|
+
} catch (_) {
|
|
9802
|
+
return false;
|
|
9803
|
+
}
|
|
9804
|
+
};
|
|
9805
|
+
/**
|
|
9806
|
+
* Checks whether the given object is a DOM node, including nodes that
|
|
9807
|
+
* originate from a different window/realm (e.g. an iframe's
|
|
9808
|
+
* contentDocument). The previous `value instanceof Node` check was
|
|
9809
|
+
* realm-bound: nodes from a different window failed it, causing
|
|
9810
|
+
* sanitize() to silently stringify them and reset IN_PLACE to false,
|
|
9811
|
+
* returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
|
|
9084
9812
|
*
|
|
9085
9813
|
* @param value object to check whether it's a DOM node
|
|
9086
|
-
* @return true
|
|
9814
|
+
* @return true if value is a DOM node from any realm
|
|
9087
9815
|
*/
|
|
9088
9816
|
const _isNode = function _isNode(value) {
|
|
9089
|
-
|
|
9817
|
+
if (!getNodeType || typeof value !== 'object' || value === null) {
|
|
9818
|
+
return false;
|
|
9819
|
+
}
|
|
9820
|
+
try {
|
|
9821
|
+
return typeof getNodeType(value) === 'number';
|
|
9822
|
+
} catch (_) {
|
|
9823
|
+
return false;
|
|
9824
|
+
}
|
|
9090
9825
|
};
|
|
9091
9826
|
function _executeHooks(hooks, currentNode, data) {
|
|
9827
|
+
if (hooks.length === 0) {
|
|
9828
|
+
return;
|
|
9829
|
+
}
|
|
9092
9830
|
arrayForEach(hooks, hook => {
|
|
9093
9831
|
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
9094
9832
|
});
|
|
9095
9833
|
}
|
|
9834
|
+
/**
|
|
9835
|
+
* Structural-threat checks that condemn a node regardless of the
|
|
9836
|
+
* allowlists: mXSS via namespace confusion, risky CSS construction,
|
|
9837
|
+
* processing instructions, markup-bearing comments. Pure predicate;
|
|
9838
|
+
* the caller removes. Check order is load-bearing.
|
|
9839
|
+
*
|
|
9840
|
+
* @param currentNode the node to inspect
|
|
9841
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
9842
|
+
* @return true if the node must be removed
|
|
9843
|
+
*/
|
|
9844
|
+
const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
|
|
9845
|
+
/* Detect mXSS attempts abusing namespace confusion */
|
|
9846
|
+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
|
|
9847
|
+
return true;
|
|
9848
|
+
}
|
|
9849
|
+
/* Remove risky CSS construction leading to mXSS */
|
|
9850
|
+
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
|
|
9851
|
+
return true;
|
|
9852
|
+
}
|
|
9853
|
+
/* Remove any occurrence of processing instructions */
|
|
9854
|
+
if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
|
|
9855
|
+
return true;
|
|
9856
|
+
}
|
|
9857
|
+
/* Remove any kind of possibly harmful comments */
|
|
9858
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
|
|
9859
|
+
return true;
|
|
9860
|
+
}
|
|
9861
|
+
return false;
|
|
9862
|
+
};
|
|
9863
|
+
/**
|
|
9864
|
+
* Handle a node whose tag is forbidden or not allowlisted: keep
|
|
9865
|
+
* allowed custom elements (false return exits _sanitizeElements
|
|
9866
|
+
* early - namespace/fallback checks and the afterSanitizeElements
|
|
9867
|
+
* hook are intentionally skipped for kept custom elements), else
|
|
9868
|
+
* hoist content per KEEP_CONTENT and remove.
|
|
9869
|
+
*
|
|
9870
|
+
* @param currentNode the disallowed node
|
|
9871
|
+
* @param tagName the node's transformCaseFunc'd tag name
|
|
9872
|
+
* @return true if the node was removed, false if kept
|
|
9873
|
+
*/
|
|
9874
|
+
const _sanitizeDisallowedNode = function _sanitizeDisallowedNode(currentNode, tagName) {
|
|
9875
|
+
/* Check if we have a custom element to handle */
|
|
9876
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
9877
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
9878
|
+
return false;
|
|
9879
|
+
}
|
|
9880
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
9881
|
+
return false;
|
|
9882
|
+
}
|
|
9883
|
+
}
|
|
9884
|
+
/* Keep content except for bad-listed elements.
|
|
9885
|
+
Use the cached prototype getters exclusively — the previous code
|
|
9886
|
+
had `|| currentNode.parentNode` / `|| currentNode.childNodes`
|
|
9887
|
+
fallbacks, but the cached getters always return the canonical
|
|
9888
|
+
value (or null for a real parent-less node), so the fallback
|
|
9889
|
+
path was dead in safe cases and a clobbering surface in unsafe
|
|
9890
|
+
ones. Falsy cached results stay falsy; the `if (childNodes &&
|
|
9891
|
+
parentNode)` check already gates correctly. */
|
|
9892
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
9893
|
+
const parentNode = getParentNode(currentNode);
|
|
9894
|
+
const childNodes = getChildNodes(currentNode);
|
|
9895
|
+
if (childNodes && parentNode) {
|
|
9896
|
+
const childCount = childNodes.length;
|
|
9897
|
+
/* In-place: hoist the *original* children so the iterator visits
|
|
9898
|
+
and sanitises them through the same allowlist pass as every other
|
|
9899
|
+
node. The caller built the tree in the live document, so the
|
|
9900
|
+
originals carry already-queued resource events (`<img onerror>`,
|
|
9901
|
+
`<video>`/`<audio>` error, lazy/`onload`, …); cloning would leave
|
|
9902
|
+
those originals detached but still armed, firing in page scope
|
|
9903
|
+
while the returned tree looked clean. Moving is safe in-place: the
|
|
9904
|
+
root is pre-validated as an allowed tag and so is never the node
|
|
9905
|
+
being removed, which keeps `parentNode` inside the iterator root
|
|
9906
|
+
and the relocated child inside the serialised tree.
|
|
9907
|
+
Otherwise (string / DOM-copy paths): clone. The iterator is rooted
|
|
9908
|
+
at — and the result serialised from — `body`, so a restrictive
|
|
9909
|
+
ALLOWED_TAGS that removes `body` itself must leave its content in
|
|
9910
|
+
place, which only cloning does; and those paths parse into an
|
|
9911
|
+
inert document, so their discarded originals never had a queued
|
|
9912
|
+
event to neutralise.
|
|
9913
|
+
`childNodes` is live; a tail-to-head walk keeps `childNodes[i]`
|
|
9914
|
+
valid whether we move (drops the trailing entry) or clone (leaves
|
|
9915
|
+
the list intact). */
|
|
9916
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
9917
|
+
const hoisted = IN_PLACE ? childNodes[i] : cloneNode(childNodes[i], true);
|
|
9918
|
+
parentNode.insertBefore(hoisted, getNextSibling(currentNode));
|
|
9919
|
+
}
|
|
9920
|
+
}
|
|
9921
|
+
}
|
|
9922
|
+
_forceRemove(currentNode);
|
|
9923
|
+
return true;
|
|
9924
|
+
};
|
|
9096
9925
|
/**
|
|
9097
9926
|
* _sanitizeElements
|
|
9098
9927
|
*
|
|
@@ -9103,7 +9932,6 @@
|
|
|
9103
9932
|
* @return true if node was killed, false if left alive
|
|
9104
9933
|
*/
|
|
9105
9934
|
const _sanitizeElements = function _sanitizeElements(currentNode) {
|
|
9106
|
-
let content = null;
|
|
9107
9935
|
/* Execute a hook if present */
|
|
9108
9936
|
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
9109
9937
|
/* Check if element is clobbered or can clobber */
|
|
@@ -9112,76 +9940,41 @@
|
|
|
9112
9940
|
return true;
|
|
9113
9941
|
}
|
|
9114
9942
|
/* Now let's check the element's type and name */
|
|
9115
|
-
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
9943
|
+
const tagName = transformCaseFunc(getNodeName ? getNodeName(currentNode) : currentNode.nodeName);
|
|
9116
9944
|
/* Execute a hook if present */
|
|
9117
9945
|
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
9118
9946
|
tagName,
|
|
9119
9947
|
allowedTags: ALLOWED_TAGS
|
|
9120
9948
|
});
|
|
9121
|
-
/*
|
|
9122
|
-
if (
|
|
9123
|
-
_forceRemove(currentNode);
|
|
9124
|
-
return true;
|
|
9125
|
-
}
|
|
9126
|
-
/* Remove risky CSS construction leading to mXSS */
|
|
9127
|
-
if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
|
|
9128
|
-
_forceRemove(currentNode);
|
|
9129
|
-
return true;
|
|
9130
|
-
}
|
|
9131
|
-
/* Remove any occurrence of processing instructions */
|
|
9132
|
-
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
9133
|
-
_forceRemove(currentNode);
|
|
9134
|
-
return true;
|
|
9135
|
-
}
|
|
9136
|
-
/* Remove any kind of possibly harmful comments */
|
|
9137
|
-
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
9949
|
+
/* Remove mXSS vectors, processing instructions and risky comments */
|
|
9950
|
+
if (_isUnsafeNode(currentNode, tagName)) {
|
|
9138
9951
|
_forceRemove(currentNode);
|
|
9139
9952
|
return true;
|
|
9140
9953
|
}
|
|
9141
9954
|
/* Remove element if anything forbids its presence */
|
|
9142
9955
|
if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
|
|
9143
|
-
|
|
9144
|
-
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
9145
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
9146
|
-
return false;
|
|
9147
|
-
}
|
|
9148
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
9149
|
-
return false;
|
|
9150
|
-
}
|
|
9151
|
-
}
|
|
9152
|
-
/* Keep content except for bad-listed elements */
|
|
9153
|
-
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
9154
|
-
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
9155
|
-
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
9156
|
-
if (childNodes && parentNode) {
|
|
9157
|
-
const childCount = childNodes.length;
|
|
9158
|
-
for (let i = childCount - 1; i >= 0; --i) {
|
|
9159
|
-
const childClone = cloneNode(childNodes[i], true);
|
|
9160
|
-
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
9161
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
9162
|
-
}
|
|
9163
|
-
}
|
|
9164
|
-
}
|
|
9165
|
-
_forceRemove(currentNode);
|
|
9166
|
-
return true;
|
|
9956
|
+
return _sanitizeDisallowedNode(currentNode, tagName);
|
|
9167
9957
|
}
|
|
9168
|
-
/* Check whether element has a valid namespace
|
|
9169
|
-
|
|
9958
|
+
/* Check whether element has a valid namespace.
|
|
9959
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype
|
|
9960
|
+
nodeType getter rather than `instanceof Element`, which is realm-
|
|
9961
|
+
bound and short-circuits to false for any node minted in a different
|
|
9962
|
+
realm — letting a foreign-realm element with a forbidden namespace
|
|
9963
|
+
slip past the namespace check entirely. */
|
|
9964
|
+
const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType;
|
|
9965
|
+
if (nt === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
|
|
9170
9966
|
_forceRemove(currentNode);
|
|
9171
9967
|
return true;
|
|
9172
9968
|
}
|
|
9173
9969
|
/* Make sure that older browsers don't get fallback-tag mXSS */
|
|
9174
|
-
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(
|
|
9970
|
+
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
|
|
9175
9971
|
_forceRemove(currentNode);
|
|
9176
9972
|
return true;
|
|
9177
9973
|
}
|
|
9178
9974
|
/* Sanitize element content to be template-safe */
|
|
9179
9975
|
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
9180
9976
|
/* Get the element's text content */
|
|
9181
|
-
content = currentNode.textContent;
|
|
9182
|
-
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
9183
|
-
content = stringReplace(content, expr, ' ');
|
|
9184
|
-
});
|
|
9977
|
+
const content = _stripTemplateExpressions(currentNode.textContent);
|
|
9185
9978
|
if (currentNode.textContent !== content) {
|
|
9186
9979
|
arrayPush(DOMPurify.removed, {
|
|
9187
9980
|
element: currentNode.cloneNode()
|
|
@@ -9211,11 +10004,12 @@
|
|
|
9211
10004
|
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
|
9212
10005
|
return false;
|
|
9213
10006
|
}
|
|
10007
|
+
const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
|
|
9214
10008
|
/* Allow valid data-* attributes: At least one character after "-"
|
|
9215
10009
|
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
|
9216
10010
|
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
|
9217
10011
|
We don't need to check the value; it's always URI safe. */
|
|
9218
|
-
if (ALLOW_DATA_ATTR &&
|
|
10012
|
+
if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!nameIsPermitted) {
|
|
9219
10013
|
if (
|
|
9220
10014
|
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
9221
10015
|
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
@@ -9227,11 +10021,15 @@
|
|
|
9227
10021
|
return false;
|
|
9228
10022
|
}
|
|
9229
10023
|
/* Check value is safe. First, is attr inert? If so, is safe */
|
|
9230
|
-
} else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
|
|
10024
|
+
} else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if (value) {
|
|
9231
10025
|
return false;
|
|
9232
10026
|
} else ;
|
|
9233
10027
|
return true;
|
|
9234
10028
|
};
|
|
10029
|
+
/* Names the HTML spec reserves from valid-custom-element-name; these must
|
|
10030
|
+
* never be treated as basic custom elements even when a permissive
|
|
10031
|
+
* CUSTOM_ELEMENT_HANDLING.tagNameCheck is configured. */
|
|
10032
|
+
const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, ['annotation-xml', 'color-profile', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'missing-glyph']);
|
|
9235
10033
|
/**
|
|
9236
10034
|
* _isBasicCustomElement
|
|
9237
10035
|
* checks if at least one dash is included in tagName, and it's not the first char
|
|
@@ -9241,7 +10039,64 @@
|
|
|
9241
10039
|
* @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
|
|
9242
10040
|
*/
|
|
9243
10041
|
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
9244
|
-
return tagName
|
|
10042
|
+
return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
|
|
10043
|
+
};
|
|
10044
|
+
/**
|
|
10045
|
+
* Wrap an attribute value in the matching Trusted Types object when
|
|
10046
|
+
* the active policy requires it. Namespaced attributes pass through
|
|
10047
|
+
* unchanged (no TT support yet, see
|
|
10048
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1305293).
|
|
10049
|
+
*
|
|
10050
|
+
* @param lcTag lowercase tag name of the containing element
|
|
10051
|
+
* @param lcName lowercase attribute name
|
|
10052
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
10053
|
+
* @param value the attribute value to wrap
|
|
10054
|
+
* @return the value, wrapped when Trusted Types demand it
|
|
10055
|
+
*/
|
|
10056
|
+
const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value) {
|
|
10057
|
+
if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function' && !namespaceURI) {
|
|
10058
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
10059
|
+
case 'TrustedHTML':
|
|
10060
|
+
{
|
|
10061
|
+
return _createTrustedHTML(value);
|
|
10062
|
+
}
|
|
10063
|
+
case 'TrustedScriptURL':
|
|
10064
|
+
{
|
|
10065
|
+
return _createTrustedScriptURL(value);
|
|
10066
|
+
}
|
|
10067
|
+
}
|
|
10068
|
+
}
|
|
10069
|
+
return value;
|
|
10070
|
+
};
|
|
10071
|
+
/**
|
|
10072
|
+
* Write a modified attribute value back onto the element. On
|
|
10073
|
+
* success, re-probe for clobbering introduced by the new value and
|
|
10074
|
+
* remove the element when found; otherwise pop the removal entry
|
|
10075
|
+
* recorded by the earlier _removeAttribute (long-standing pairing
|
|
10076
|
+
* with the SANITIZE_NAMED_PROPS path - do not "fix" casually). On
|
|
10077
|
+
* failure, remove the attribute instead.
|
|
10078
|
+
*
|
|
10079
|
+
* @param currentNode the element carrying the attribute
|
|
10080
|
+
* @param name the attribute name as present on the element
|
|
10081
|
+
* @param namespaceURI the attribute's namespace, if any
|
|
10082
|
+
* @param value the new attribute value
|
|
10083
|
+
*/
|
|
10084
|
+
const _setAttributeValue = function _setAttributeValue(currentNode, name, namespaceURI, value) {
|
|
10085
|
+
try {
|
|
10086
|
+
if (namespaceURI) {
|
|
10087
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
10088
|
+
} else {
|
|
10089
|
+
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
10090
|
+
currentNode.setAttribute(name, value);
|
|
10091
|
+
}
|
|
10092
|
+
if (_isClobbered(currentNode)) {
|
|
10093
|
+
_forceRemove(currentNode);
|
|
10094
|
+
} else {
|
|
10095
|
+
arrayPop(DOMPurify.removed);
|
|
10096
|
+
}
|
|
10097
|
+
} catch (_) {
|
|
10098
|
+
_removeAttribute(name, currentNode);
|
|
10099
|
+
}
|
|
9245
10100
|
};
|
|
9246
10101
|
/**
|
|
9247
10102
|
* _sanitizeAttributes
|
|
@@ -9256,9 +10111,7 @@
|
|
|
9256
10111
|
const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
9257
10112
|
/* Execute a hook if present */
|
|
9258
10113
|
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
9259
|
-
const
|
|
9260
|
-
attributes
|
|
9261
|
-
} = currentNode;
|
|
10114
|
+
const attributes = currentNode.attributes;
|
|
9262
10115
|
/* Check if we have attributes; if not we might have a text node */
|
|
9263
10116
|
if (!attributes || _isClobbered(currentNode)) {
|
|
9264
10117
|
return;
|
|
@@ -9271,14 +10124,13 @@
|
|
|
9271
10124
|
forceKeepAttr: undefined
|
|
9272
10125
|
};
|
|
9273
10126
|
let l = attributes.length;
|
|
10127
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
9274
10128
|
/* Go backwards over all attributes; safely remove bad ones */
|
|
9275
10129
|
while (l--) {
|
|
9276
10130
|
const attr = attributes[l];
|
|
9277
|
-
const
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
value: attrValue
|
|
9281
|
-
} = attr;
|
|
10131
|
+
const name = attr.name,
|
|
10132
|
+
namespaceURI = attr.namespaceURI,
|
|
10133
|
+
attrValue = attr.value;
|
|
9282
10134
|
const lcName = transformCaseFunc(name);
|
|
9283
10135
|
const initValue = attrValue;
|
|
9284
10136
|
let value = name === 'value' ? initValue : stringTrim(initValue);
|
|
@@ -9292,12 +10144,14 @@
|
|
|
9292
10144
|
/* Full DOM Clobbering protection via namespace isolation,
|
|
9293
10145
|
* Prefix id and name attributes with `user-content-`
|
|
9294
10146
|
*/
|
|
9295
|
-
if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
|
|
10147
|
+
if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name') && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
|
|
9296
10148
|
// Remove the attribute with this value
|
|
9297
10149
|
_removeAttribute(name, currentNode);
|
|
9298
10150
|
// Prefix the value and later re-create the attribute with the sanitized value
|
|
9299
10151
|
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
9300
10152
|
}
|
|
10153
|
+
// Else: already prefixed, leave the attribute alone — the prefix is
|
|
10154
|
+
// itself the clobbering protection, and re-applying it is incorrect.
|
|
9301
10155
|
/* Work around a security issue with comments inside attributes */
|
|
9302
10156
|
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
|
|
9303
10157
|
_removeAttribute(name, currentNode);
|
|
@@ -9308,7 +10162,7 @@
|
|
|
9308
10162
|
_removeAttribute(name, currentNode);
|
|
9309
10163
|
continue;
|
|
9310
10164
|
}
|
|
9311
|
-
/* Did the hooks
|
|
10165
|
+
/* Did the hooks force-keep the attribute? */
|
|
9312
10166
|
if (hookEvent.forceKeepAttr) {
|
|
9313
10167
|
continue;
|
|
9314
10168
|
}
|
|
@@ -9318,56 +10172,24 @@
|
|
|
9318
10172
|
continue;
|
|
9319
10173
|
}
|
|
9320
10174
|
/* Work around a security issue in jQuery 3.0 */
|
|
9321
|
-
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(
|
|
10175
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
|
|
9322
10176
|
_removeAttribute(name, currentNode);
|
|
9323
10177
|
continue;
|
|
9324
10178
|
}
|
|
9325
10179
|
/* Sanitize attribute content to be template-safe */
|
|
9326
10180
|
if (SAFE_FOR_TEMPLATES) {
|
|
9327
|
-
|
|
9328
|
-
value = stringReplace(value, expr, ' ');
|
|
9329
|
-
});
|
|
10181
|
+
value = _stripTemplateExpressions(value);
|
|
9330
10182
|
}
|
|
9331
10183
|
/* Is `value` valid for this attribute? */
|
|
9332
|
-
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
9333
10184
|
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
9334
10185
|
_removeAttribute(name, currentNode);
|
|
9335
10186
|
continue;
|
|
9336
10187
|
}
|
|
9337
10188
|
/* Handle attributes that require Trusted Types */
|
|
9338
|
-
|
|
9339
|
-
if (namespaceURI) ; else {
|
|
9340
|
-
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
9341
|
-
case 'TrustedHTML':
|
|
9342
|
-
{
|
|
9343
|
-
value = trustedTypesPolicy.createHTML(value);
|
|
9344
|
-
break;
|
|
9345
|
-
}
|
|
9346
|
-
case 'TrustedScriptURL':
|
|
9347
|
-
{
|
|
9348
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
|
9349
|
-
break;
|
|
9350
|
-
}
|
|
9351
|
-
}
|
|
9352
|
-
}
|
|
9353
|
-
}
|
|
10189
|
+
value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
|
|
9354
10190
|
/* Handle invalid data-* attribute set by try-catching it */
|
|
9355
10191
|
if (value !== initValue) {
|
|
9356
|
-
|
|
9357
|
-
if (namespaceURI) {
|
|
9358
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
9359
|
-
} else {
|
|
9360
|
-
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
9361
|
-
currentNode.setAttribute(name, value);
|
|
9362
|
-
}
|
|
9363
|
-
if (_isClobbered(currentNode)) {
|
|
9364
|
-
_forceRemove(currentNode);
|
|
9365
|
-
} else {
|
|
9366
|
-
arrayPop(DOMPurify.removed);
|
|
9367
|
-
}
|
|
9368
|
-
} catch (_) {
|
|
9369
|
-
_removeAttribute(name, currentNode);
|
|
9370
|
-
}
|
|
10192
|
+
_setAttributeValue(currentNode, name, namespaceURI, value);
|
|
9371
10193
|
}
|
|
9372
10194
|
}
|
|
9373
10195
|
/* Execute a hook if present */
|
|
@@ -9390,14 +10212,133 @@
|
|
|
9390
10212
|
_sanitizeElements(shadowNode);
|
|
9391
10213
|
/* Check attributes next */
|
|
9392
10214
|
_sanitizeAttributes(shadowNode);
|
|
9393
|
-
/* Deep shadow DOM detected
|
|
9394
|
-
|
|
10215
|
+
/* Deep shadow DOM detected.
|
|
10216
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): use nodeType against the
|
|
10217
|
+
DOCUMENT_FRAGMENT_NODE constant rather than instanceof, so we
|
|
10218
|
+
recurse into <template>.content from foreign realms too. */
|
|
10219
|
+
if (_isDocumentFragment(shadowNode.content)) {
|
|
9395
10220
|
_sanitizeShadowDOM2(shadowNode.content);
|
|
9396
10221
|
}
|
|
10222
|
+
/* An element iterated here may itself host an attached
|
|
10223
|
+
shadow root. The default NodeIterator does not enter shadow
|
|
10224
|
+
trees, so a shadow root nested inside template.content was
|
|
10225
|
+
previously reached by no walk at all (the pre-pass at
|
|
10226
|
+
_sanitizeAttachedShadowRoots descends via childNodes, which
|
|
10227
|
+
doesn't enter template.content; the template-content recursion
|
|
10228
|
+
above iterates the content but never inspected shadowRoot).
|
|
10229
|
+
Walk it explicitly. The nodeType guard avoids reading
|
|
10230
|
+
shadowRoot off text / comment / CDATA / PI nodes that the
|
|
10231
|
+
iterator also surfaces. */
|
|
10232
|
+
const shadowNodeType = getNodeType ? getNodeType(shadowNode) : shadowNode.nodeType;
|
|
10233
|
+
if (shadowNodeType === NODE_TYPE.element) {
|
|
10234
|
+
const innerSr = getShadowRoot(shadowNode);
|
|
10235
|
+
if (_isDocumentFragment(innerSr)) {
|
|
10236
|
+
_sanitizeAttachedShadowRoots(innerSr);
|
|
10237
|
+
_sanitizeShadowDOM2(innerSr);
|
|
10238
|
+
}
|
|
10239
|
+
}
|
|
9397
10240
|
}
|
|
9398
10241
|
/* Execute a hook if present */
|
|
9399
10242
|
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
9400
10243
|
};
|
|
10244
|
+
/**
|
|
10245
|
+
* _sanitizeAttachedShadowRoots
|
|
10246
|
+
*
|
|
10247
|
+
* Walks `root` and feeds every attached shadow root we encounter into
|
|
10248
|
+
* the existing _sanitizeShadowDOM pipeline. The default node iterator
|
|
10249
|
+
* does not descend into shadow trees, so nodes inside an attached
|
|
10250
|
+
* shadow root would otherwise be skipped entirely.
|
|
10251
|
+
*
|
|
10252
|
+
* Two real input paths put attached shadow roots in front of us:
|
|
10253
|
+
* 1. IN_PLACE on a DOM node that already has shadow roots attached.
|
|
10254
|
+
* 2. DOM-node input where importNode(dirty, true) deep-clones the
|
|
10255
|
+
* shadow root because it was created with `clonable: true`.
|
|
10256
|
+
*
|
|
10257
|
+
* This pass runs once, up front, so the main iteration loop (and the
|
|
10258
|
+
* existing _sanitizeShadowDOM template-content recursion) stay
|
|
10259
|
+
* untouched — string-input paths are not affected.
|
|
10260
|
+
*
|
|
10261
|
+
* @param root the subtree root to walk for attached shadow roots
|
|
10262
|
+
*/
|
|
10263
|
+
const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots(root) {
|
|
10264
|
+
/* Iterative (explicit stack) rather than per-child recursion. DOM APIs
|
|
10265
|
+
impose no depth cap, so an attacker-shaped tree (JSON/CRDT/editor data
|
|
10266
|
+
built straight into the DOM — the IN_PLACE surface) deeper than the JS
|
|
10267
|
+
call-stack budget would otherwise overflow native recursion here and
|
|
10268
|
+
throw at the IN_PLACE entry pre-pass, before a single node is
|
|
10269
|
+
sanitized, leaving the caller's live tree untouched (fail-open). See
|
|
10270
|
+
campaign-3 F4. A heap stack keeps depth off the call stack.
|
|
10271
|
+
Each work item is either a node to descend into, or a deferred
|
|
10272
|
+
`_sanitizeShadowDOM` for an already-walked shadow root. The deferred
|
|
10273
|
+
form preserves the original post-order discipline: a shadow root's
|
|
10274
|
+
nested shadow roots are discovered before the outer shadow is
|
|
10275
|
+
sanitized (which may remove hosts). Pushes are in reverse of the
|
|
10276
|
+
desired processing order (LIFO): template content, then children, then
|
|
10277
|
+
the shadow-sanitize, then the shadow walk — so the order matches the
|
|
10278
|
+
previous recursion exactly. */
|
|
10279
|
+
const stack = [{
|
|
10280
|
+
node: root,
|
|
10281
|
+
shadow: null
|
|
10282
|
+
}];
|
|
10283
|
+
while (stack.length > 0) {
|
|
10284
|
+
const item = stack.pop();
|
|
10285
|
+
/* Deferred shadow-DOM sanitisation: runs after its subtree was walked. */
|
|
10286
|
+
if (item.shadow) {
|
|
10287
|
+
_sanitizeShadowDOM2(item.shadow);
|
|
10288
|
+
continue;
|
|
10289
|
+
}
|
|
10290
|
+
const node = item.node;
|
|
10291
|
+
const nodeType = getNodeType ? getNodeType(node) : node.nodeType;
|
|
10292
|
+
const isElement = nodeType === NODE_TYPE.element;
|
|
10293
|
+
/* (pushed last → processed first) Children, snapshotted in reverse so
|
|
10294
|
+
the first child is processed first. Snapshotting matters because a
|
|
10295
|
+
hook may detach siblings mid-walk. */
|
|
10296
|
+
const childNodes = getChildNodes(node);
|
|
10297
|
+
if (childNodes) {
|
|
10298
|
+
for (let i = childNodes.length - 1; i >= 0; --i) {
|
|
10299
|
+
stack.push({
|
|
10300
|
+
node: childNodes[i],
|
|
10301
|
+
shadow: null
|
|
10302
|
+
});
|
|
10303
|
+
}
|
|
10304
|
+
}
|
|
10305
|
+
/* (pushed before children → processed after them, matching the old
|
|
10306
|
+
"template content last" order) When the node is a <template>,
|
|
10307
|
+
descend into its content. */
|
|
10308
|
+
if (isElement) {
|
|
10309
|
+
const rootName = getNodeName ? getNodeName(node) : null;
|
|
10310
|
+
if (typeof rootName === 'string' && transformCaseFunc(rootName) === 'template') {
|
|
10311
|
+
const content = node.content;
|
|
10312
|
+
if (_isDocumentFragment(content)) {
|
|
10313
|
+
stack.push({
|
|
10314
|
+
node: content,
|
|
10315
|
+
shadow: null
|
|
10316
|
+
});
|
|
10317
|
+
}
|
|
10318
|
+
}
|
|
10319
|
+
}
|
|
10320
|
+
/* Shadow root (processed first): walk its subtree, then sanitise it.
|
|
10321
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
10322
|
+
rather than `instanceof DocumentFragment`, which is realm-bound and
|
|
10323
|
+
silently skipped foreign-realm shadow roots (e.g.
|
|
10324
|
+
iframe.contentDocument attachShadow). */
|
|
10325
|
+
if (isElement) {
|
|
10326
|
+
const sr = getShadowRoot(node);
|
|
10327
|
+
if (_isDocumentFragment(sr)) {
|
|
10328
|
+
/* Push the deferred sanitise first so it pops after the shadow
|
|
10329
|
+
walk we push next, i.e. nested shadow roots are discovered
|
|
10330
|
+
before this one is sanitised. */
|
|
10331
|
+
stack.push({
|
|
10332
|
+
node: null,
|
|
10333
|
+
shadow: sr
|
|
10334
|
+
}, {
|
|
10335
|
+
node: sr,
|
|
10336
|
+
shadow: null
|
|
10337
|
+
});
|
|
10338
|
+
}
|
|
10339
|
+
}
|
|
10340
|
+
}
|
|
10341
|
+
};
|
|
9401
10342
|
// eslint-disable-next-line complexity
|
|
9402
10343
|
DOMPurify.sanitize = function (dirty) {
|
|
9403
10344
|
let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -9414,13 +10355,9 @@
|
|
|
9414
10355
|
}
|
|
9415
10356
|
/* Stringify, in case dirty is an object */
|
|
9416
10357
|
if (typeof dirty !== 'string' && !_isNode(dirty)) {
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
throw typeErrorCreate('dirty is not a string, aborting');
|
|
9421
|
-
}
|
|
9422
|
-
} else {
|
|
9423
|
-
throw typeErrorCreate('toString is not a function');
|
|
10358
|
+
dirty = stringifyValue(dirty);
|
|
10359
|
+
if (typeof dirty !== 'string') {
|
|
10360
|
+
throw typeErrorCreate('dirty is not a string, aborting');
|
|
9424
10361
|
}
|
|
9425
10362
|
}
|
|
9426
10363
|
/* Return dirty HTML if DOMPurify cannot run */
|
|
@@ -9428,24 +10365,78 @@
|
|
|
9428
10365
|
return dirty;
|
|
9429
10366
|
}
|
|
9430
10367
|
/* Assign config vars */
|
|
9431
|
-
if (
|
|
10368
|
+
if (SET_CONFIG) {
|
|
10369
|
+
/* Persistent setConfig() path: _parseConfig is skipped, so the sets are
|
|
10370
|
+
* not re-derived per call. Restore them from the pristine bindings
|
|
10371
|
+
* captured at setConfig() time so a previous call's hook clone (mutated
|
|
10372
|
+
* below) does not carry over. */
|
|
10373
|
+
ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
|
|
10374
|
+
ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
|
|
10375
|
+
} else {
|
|
9432
10376
|
_parseConfig(cfg);
|
|
9433
10377
|
}
|
|
10378
|
+
/* Clone the hook-mutable allowlists before the walk whenever an
|
|
10379
|
+
* uponSanitize* hook is registered. The hook event exposes ALLOWED_TAGS
|
|
10380
|
+
* and ALLOWED_ATTR by reference (as allowedTags / allowedAttributes), so
|
|
10381
|
+
* a hook that widens them would otherwise mutate the shared set
|
|
10382
|
+
* permanently: across later calls and across every element. Cloning per
|
|
10383
|
+
* walk keeps documented in-call widening working while scoping it to the
|
|
10384
|
+
* call. A single guard for both config paths - the per-call path rebinds
|
|
10385
|
+
* the sets in _parseConfig each call, the persistent path restores them
|
|
10386
|
+
* from the captured bindings just above - so the two cannot diverge. */
|
|
10387
|
+
if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
|
|
10388
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
10389
|
+
}
|
|
10390
|
+
if (hooks.uponSanitizeAttribute.length > 0) {
|
|
10391
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
10392
|
+
}
|
|
9434
10393
|
/* Clean up removed elements */
|
|
9435
10394
|
DOMPurify.removed = [];
|
|
9436
|
-
/*
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
|
|
9440
|
-
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
10395
|
+
/* Resolve IN_PLACE for this call without mutating persistent config.
|
|
10396
|
+
Writing the IN_PLACE closure variable here leaks under setConfig(),
|
|
10397
|
+
where _parseConfig is skipped on later calls: a single string call would
|
|
10398
|
+
disable in-place mode for every subsequent node call, returning a
|
|
10399
|
+
sanitized copy while leaving the caller's node — which in-place callers
|
|
10400
|
+
keep using and whose return value they ignore — unsanitized. REPORT-2. */
|
|
10401
|
+
const inPlace = IN_PLACE && typeof dirty !== 'string' && _isNode(dirty);
|
|
10402
|
+
if (inPlace) {
|
|
10403
|
+
/* Do some early pre-sanitization to avoid unsafe root nodes.
|
|
10404
|
+
Read nodeName through the cached prototype getter — a clobbering
|
|
10405
|
+
child named "nodeName" on the form root would otherwise shadow
|
|
10406
|
+
the property and let this check skip the root-allowlist
|
|
10407
|
+
validation entirely. */
|
|
10408
|
+
const nn = getNodeName ? getNodeName(dirty) : dirty.nodeName;
|
|
10409
|
+
if (typeof nn === 'string') {
|
|
10410
|
+
const tagName = transformCaseFunc(nn);
|
|
9444
10411
|
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
9445
10412
|
throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
|
|
9446
10413
|
}
|
|
9447
10414
|
}
|
|
9448
|
-
|
|
10415
|
+
/* Pre-flight the root through _isClobbered. The iterator-driven
|
|
10416
|
+
removal path can not detach a parent-less root: _forceRemove
|
|
10417
|
+
falls through to Element.prototype.remove(), which per spec
|
|
10418
|
+
is a no-op on a node with no parent. A clobbered root would
|
|
10419
|
+
then survive the main loop with its attributes uninspected,
|
|
10420
|
+
because _sanitizeAttributes early-returns on _isClobbered. The
|
|
10421
|
+
result would be an attacker-controlled form, complete with any
|
|
10422
|
+
event-handler attributes the caller passed in, handed back to
|
|
10423
|
+
the application unsanitized. Refuse to sanitize such a root
|
|
10424
|
+
the same way we refuse a forbidden tag. GHSA-r47g-fvhr-h676. */
|
|
10425
|
+
if (_isClobbered(dirty)) {
|
|
10426
|
+
throw typeErrorCreate('root node is clobbered and cannot be sanitized in-place');
|
|
10427
|
+
}
|
|
10428
|
+
/* Sanitize attached shadow roots before the main iterator runs.
|
|
10429
|
+
The iterator does not descend into shadow trees. Same fail-closed
|
|
10430
|
+
barrier as the main walk (campaign-3 F2): a custom-element reaction
|
|
10431
|
+
inside a shadow root could abort this pre-pass before the walk runs,
|
|
10432
|
+
which would otherwise leave the entire live tree unsanitized. */
|
|
10433
|
+
try {
|
|
10434
|
+
_sanitizeAttachedShadowRoots(dirty);
|
|
10435
|
+
} catch (error) {
|
|
10436
|
+
_neutralizeRoot(dirty);
|
|
10437
|
+
throw error;
|
|
10438
|
+
}
|
|
10439
|
+
} else if (_isNode(dirty)) {
|
|
9449
10440
|
/* If dirty is a DOM element, append to an empty document to avoid
|
|
9450
10441
|
elements being stripped by the parser */
|
|
9451
10442
|
body = _initDocument('<!---->');
|
|
@@ -9459,12 +10450,18 @@
|
|
|
9459
10450
|
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
9460
10451
|
body.appendChild(importedNode);
|
|
9461
10452
|
}
|
|
10453
|
+
/* Clonable shadow roots are deep-cloned by importNode(); sanitize
|
|
10454
|
+
them before the main iterator runs, since the iterator does not
|
|
10455
|
+
descend into shadow trees. The walk routes every read through a
|
|
10456
|
+
cached prototype getter so clobbering descendants on a form root
|
|
10457
|
+
cannot hide a shadow host from this pass. */
|
|
10458
|
+
_sanitizeAttachedShadowRoots(importedNode);
|
|
9462
10459
|
} else {
|
|
9463
10460
|
/* Exit directly if we have nothing to do */
|
|
9464
10461
|
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
|
|
9465
10462
|
// eslint-disable-next-line unicorn/prefer-includes
|
|
9466
10463
|
dirty.indexOf('<') === -1) {
|
|
9467
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
10464
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
|
|
9468
10465
|
}
|
|
9469
10466
|
/* Initialize the document to work on */
|
|
9470
10467
|
body = _initDocument(dirty);
|
|
@@ -9478,31 +10475,59 @@
|
|
|
9478
10475
|
_forceRemove(body.firstChild);
|
|
9479
10476
|
}
|
|
9480
10477
|
/* Get node iterator */
|
|
9481
|
-
const nodeIterator = _createNodeIterator(
|
|
9482
|
-
/* Now start iterating over the created document
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
10478
|
+
const nodeIterator = _createNodeIterator(inPlace ? dirty : body);
|
|
10479
|
+
/* Now start iterating over the created document.
|
|
10480
|
+
The walk runs inside an exception barrier (campaign-3 F2): a re-entrant
|
|
10481
|
+
engine/custom-element mutation can detach a node mid-walk so
|
|
10482
|
+
`_forceRemove`'s parentless guard throws, aborting the loop. Without the
|
|
10483
|
+
barrier the caller's in-place tree would be left half-sanitized with the
|
|
10484
|
+
unvisited tail still armed. On any throw we fail closed — strip the
|
|
10485
|
+
in-place root bare — then rethrow so the existing throw contract is
|
|
10486
|
+
preserved. (String/DOM-copy paths never return the partial body, so the
|
|
10487
|
+
propagating throw is already fail-closed there.) */
|
|
10488
|
+
try {
|
|
10489
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
10490
|
+
/* Sanitize tags and elements */
|
|
10491
|
+
_sanitizeElements(currentNode);
|
|
10492
|
+
/* Check attributes next */
|
|
10493
|
+
_sanitizeAttributes(currentNode);
|
|
10494
|
+
/* Shadow DOM detected, sanitize it.
|
|
10495
|
+
Realm-safe check (GHSA-hpcv-96wg-7vj8): nodeType-based detection
|
|
10496
|
+
instead of instanceof, so foreign-realm <template>.content is
|
|
10497
|
+
walked correctly. */
|
|
10498
|
+
if (_isDocumentFragment(currentNode.content)) {
|
|
10499
|
+
_sanitizeShadowDOM2(currentNode.content);
|
|
10500
|
+
}
|
|
9491
10501
|
}
|
|
10502
|
+
} catch (error) {
|
|
10503
|
+
if (inPlace) {
|
|
10504
|
+
_neutralizeRoot(dirty);
|
|
10505
|
+
}
|
|
10506
|
+
throw error;
|
|
9492
10507
|
}
|
|
9493
10508
|
/* If we sanitized `dirty` in-place, return it. */
|
|
9494
|
-
if (
|
|
10509
|
+
if (inPlace) {
|
|
10510
|
+
/* Fail-closed completion of the audit-5 F1 fix: every node removed from
|
|
10511
|
+
the caller's live tree is detached but may still hold a queued
|
|
10512
|
+
resource-event handler that fires in page scope after we return. The
|
|
10513
|
+
move-hoist covers only disallowed-tag KEEP_CONTENT removals; strip the
|
|
10514
|
+
non-allow-listed attributes off every other removed subtree (clobber,
|
|
10515
|
+
mXSS, namespace, comments, KEEP_CONTENT:false, …) so those handlers are
|
|
10516
|
+
cancelled before any event can fire. Runs synchronously, pre-return. */
|
|
10517
|
+
arrayForEach(DOMPurify.removed, entry => {
|
|
10518
|
+
if (entry.element) {
|
|
10519
|
+
_neutralizeSubtree(entry.element);
|
|
10520
|
+
}
|
|
10521
|
+
});
|
|
10522
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
10523
|
+
_scrubTemplateExpressions2(dirty);
|
|
10524
|
+
}
|
|
9495
10525
|
return dirty;
|
|
9496
10526
|
}
|
|
9497
10527
|
/* Return sanitized string or DOM */
|
|
9498
10528
|
if (RETURN_DOM) {
|
|
9499
10529
|
if (SAFE_FOR_TEMPLATES) {
|
|
9500
|
-
body
|
|
9501
|
-
let html = body.innerHTML;
|
|
9502
|
-
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
9503
|
-
html = stringReplace(html, expr, ' ');
|
|
9504
|
-
});
|
|
9505
|
-
body.innerHTML = html;
|
|
10530
|
+
_scrubTemplateExpressions2(body);
|
|
9506
10531
|
}
|
|
9507
10532
|
if (RETURN_DOM_FRAGMENT) {
|
|
9508
10533
|
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
@@ -9532,20 +10557,28 @@
|
|
|
9532
10557
|
}
|
|
9533
10558
|
/* Sanitize final string template-safe */
|
|
9534
10559
|
if (SAFE_FOR_TEMPLATES) {
|
|
9535
|
-
|
|
9536
|
-
serializedHTML = stringReplace(serializedHTML, expr, ' ');
|
|
9537
|
-
});
|
|
10560
|
+
serializedHTML = _stripTemplateExpressions(serializedHTML);
|
|
9538
10561
|
}
|
|
9539
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ?
|
|
10562
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
|
|
9540
10563
|
};
|
|
9541
10564
|
DOMPurify.setConfig = function () {
|
|
9542
10565
|
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
9543
10566
|
_parseConfig(cfg);
|
|
9544
10567
|
SET_CONFIG = true;
|
|
10568
|
+
SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
|
|
10569
|
+
SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
|
|
9545
10570
|
};
|
|
9546
10571
|
DOMPurify.clearConfig = function () {
|
|
9547
10572
|
CONFIG = null;
|
|
9548
10573
|
SET_CONFIG = false;
|
|
10574
|
+
SET_CONFIG_ALLOWED_TAGS = null;
|
|
10575
|
+
SET_CONFIG_ALLOWED_ATTR = null;
|
|
10576
|
+
// Drop any caller-supplied Trusted Types policy so it cannot poison later
|
|
10577
|
+
// `RETURN_TRUSTED_TYPE` output. The internal default policy (cached, and
|
|
10578
|
+
// never recreated — Trusted Types throws on duplicate names) is restored by
|
|
10579
|
+
// the next `_parseConfig`. See GHSA-vxr8-fq34-vvx9.
|
|
10580
|
+
trustedTypesPolicy = defaultTrustedTypesPolicy;
|
|
10581
|
+
emptyHTML = '';
|
|
9549
10582
|
};
|
|
9550
10583
|
DOMPurify.isValidAttribute = function (tag, attr, value) {
|
|
9551
10584
|
/* Initialize shared config vars if necessary. */
|
|
@@ -9560,9 +10593,19 @@
|
|
|
9560
10593
|
if (typeof hookFunction !== 'function') {
|
|
9561
10594
|
return;
|
|
9562
10595
|
}
|
|
10596
|
+
/* Reject unknown entry points. Without this, a non-hook key (e.g.
|
|
10597
|
+
* '__proto__') indexes off the prototype chain rather than a real
|
|
10598
|
+
* hook array, and arrayPush then writes to Object.prototype. Guard
|
|
10599
|
+
* with an own-property check against the known hook names. */
|
|
10600
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
10601
|
+
return;
|
|
10602
|
+
}
|
|
9563
10603
|
arrayPush(hooks[entryPoint], hookFunction);
|
|
9564
10604
|
};
|
|
9565
10605
|
DOMPurify.removeHook = function (entryPoint, hookFunction) {
|
|
10606
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
10607
|
+
return undefined;
|
|
10608
|
+
}
|
|
9566
10609
|
if (hookFunction !== undefined) {
|
|
9567
10610
|
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
9568
10611
|
return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
@@ -9570,6 +10613,9 @@
|
|
|
9570
10613
|
return arrayPop(hooks[entryPoint]);
|
|
9571
10614
|
};
|
|
9572
10615
|
DOMPurify.removeHooks = function (entryPoint) {
|
|
10616
|
+
if (!objectHasOwnProperty(hooks, entryPoint)) {
|
|
10617
|
+
return;
|
|
10618
|
+
}
|
|
9573
10619
|
hooks[entryPoint] = [];
|
|
9574
10620
|
};
|
|
9575
10621
|
DOMPurify.removeAllHooks = function () {
|
|
@@ -9830,10 +10876,26 @@
|
|
|
9830
10876
|
}(Background);
|
|
9831
10877
|
|
|
9832
10878
|
/**
|
|
9833
|
-
* Generate a unique id compatible with HTML element id
|
|
10879
|
+
* Generate a unique id compatible with HTML element id.
|
|
10880
|
+
* Uses the Web Crypto API for cryptographically strong randomness, with a
|
|
10881
|
+
* deterministic fallback only when crypto is unavailable.
|
|
9834
10882
|
*/
|
|
9835
10883
|
function getUniqueId() {
|
|
9836
|
-
|
|
10884
|
+
var letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
10885
|
+
var length = 10;
|
|
10886
|
+
var bytes = new Uint8Array(length);
|
|
10887
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
10888
|
+
crypto.getRandomValues(bytes);
|
|
10889
|
+
} else {
|
|
10890
|
+
for (var i = 0; i < length; i++) {
|
|
10891
|
+
bytes[i] = (i * 31 + 7) % 256;
|
|
10892
|
+
}
|
|
10893
|
+
}
|
|
10894
|
+
var id = '';
|
|
10895
|
+
for (var _i = 0; _i < length; _i++) {
|
|
10896
|
+
id += letters[bytes[_i] % letters.length];
|
|
10897
|
+
}
|
|
10898
|
+
return id;
|
|
9837
10899
|
}
|
|
9838
10900
|
|
|
9839
10901
|
function getFlypayV2Button(widgetId) {
|
|
@@ -12799,208 +13861,75 @@
|
|
|
12799
13861
|
function getDefinedFormFields(configuration) {
|
|
12800
13862
|
return getBaseFormFields(configuration).map(function (field) {
|
|
12801
13863
|
var _a, _b;
|
|
12802
|
-
if ((_a = configuration.defined_form_fields) === null || _a === void 0 ? void 0 : _a.includes(field)) {
|
|
12803
|
-
return field;
|
|
12804
|
-
}
|
|
12805
|
-
if ((_b = configuration.defined_form_fields) === null || _b === void 0 ? void 0 : _b.includes("".concat(field, "*"))) {
|
|
12806
|
-
return "".concat(field, "*");
|
|
12807
|
-
}
|
|
12808
|
-
}).filter(Boolean);
|
|
12809
|
-
}
|
|
12810
|
-
function getDynamicFormFields(configuration) {
|
|
12811
|
-
var _a;
|
|
12812
|
-
var baseFormFields = getBaseFormFields(configuration);
|
|
12813
|
-
return (_a = configuration.defined_form_fields) === null || _a === void 0 ? void 0 : _a.map(function (field) {
|
|
12814
|
-
var sanitizedField = field.replace('*', '');
|
|
12815
|
-
if (baseFormFields.includes(sanitizedField)) {
|
|
12816
|
-
return field;
|
|
12817
|
-
}
|
|
12818
|
-
}).filter(Boolean);
|
|
12819
|
-
}
|
|
12820
|
-
function getMetaFields(configuration) {
|
|
12821
|
-
return Object.values(META_FIELDS).reduce(function (accumulator, metaField) {
|
|
12822
|
-
var _a;
|
|
12823
|
-
var configurationMetaFieldValue = (_a = configuration.meta) === null || _a === void 0 ? void 0 : _a[metaField];
|
|
12824
|
-
if (!configurationMetaFieldValue) {
|
|
12825
|
-
return accumulator;
|
|
12826
|
-
}
|
|
12827
|
-
return _extends({}, accumulator, _defineProperty({}, metaField, configuration.meta[metaField]));
|
|
12828
|
-
}, {});
|
|
12829
|
-
}
|
|
12830
|
-
function getPredefinedFields(configuration) {
|
|
12831
|
-
var gatewayId = configuration.predefined_fields.gateway_id === 'not_configured' ? '' : configuration.predefined_fields.gateway_id;
|
|
12832
|
-
return _extends({}, configuration.predefined_fields, {
|
|
12833
|
-
gateway_id: gatewayId
|
|
12834
|
-
});
|
|
12835
|
-
}
|
|
12836
|
-
function getWrongPredefinedFields(configuration) {
|
|
12837
|
-
var erroringFields = getBasePredefinedFields(configuration).map(function (field) {
|
|
12838
|
-
return !configuration.predefined_fields[field] ? field : '';
|
|
12839
|
-
}).filter(Boolean);
|
|
12840
|
-
if (erroringFields.length) {
|
|
12841
|
-
return erroringFields.join(', ').concat(" ".concat(erroringFields.length > 1 ? 'are' : 'is', " cannot be empty"));
|
|
12842
|
-
}
|
|
12843
|
-
}
|
|
12844
|
-
function getBasePredefinedFields(configuration) {
|
|
12845
|
-
var basePredefinedFields = [PREDEFINED_FIELDS.GATEWAY_ID, PREDEFINED_FIELDS.TYPE];
|
|
12846
|
-
switch (configuration.predefined_fields.type) {
|
|
12847
|
-
case PAYMENT_SOURCE_TYPE.GIFT_CARD:
|
|
12848
|
-
{
|
|
12849
|
-
return basePredefinedFields.concat([PREDEFINED_FIELDS.CARD_SCHEME, PREDEFINED_FIELDS.CARD_PROCESSING_NETWORK]);
|
|
12850
|
-
}
|
|
12851
|
-
default:
|
|
12852
|
-
{
|
|
12853
|
-
return basePredefinedFields;
|
|
12854
|
-
}
|
|
12855
|
-
}
|
|
12856
|
-
}
|
|
12857
|
-
function getHandleCvv(configuration) {
|
|
12858
|
-
switch (configuration.purpose) {
|
|
12859
|
-
case PURPOSE.CARD_PAYMENT_SOURCE_WITH_CVV:
|
|
12860
|
-
{
|
|
12861
|
-
return true;
|
|
12862
|
-
}
|
|
12863
|
-
case PURPOSE.CARD_PAYMENT_SOURCE_WITHOUT_CVV:
|
|
12864
|
-
{
|
|
12865
|
-
return false;
|
|
12866
|
-
}
|
|
12867
|
-
default:
|
|
12868
|
-
{
|
|
12869
|
-
return undefined;
|
|
12870
|
-
}
|
|
12871
|
-
}
|
|
12872
|
-
}
|
|
12873
|
-
|
|
12874
|
-
/**
|
|
12875
|
-
* Top-level classification of an error. Used by the SDK to route errors to the
|
|
12876
|
-
* right category in instrumentation and to give consumers a coarse-grained
|
|
12877
|
-
* tag for grouping/filtering. See {@link getErrorCategory} for the mapping
|
|
12878
|
-
* between {@link ERROR_CAUSE} and {@link ERROR_CATEGORY}.
|
|
12879
|
-
*/
|
|
12880
|
-
var ERROR_CATEGORY = {
|
|
12881
|
-
/** SDK was misconfigured (missing keys, invalid options, etc.). */
|
|
12882
|
-
CONFIGURATION: 'configuration',
|
|
12883
|
-
/** Authentication or authorization failure. */
|
|
12884
|
-
IDENTITY: 'identity_access_management',
|
|
12885
|
-
/** SDK internal failure or upstream service problem. */
|
|
12886
|
-
INTERNAL: 'internal',
|
|
12887
|
-
/** Flow lifecycle event (user cancelled, aborted, etc.) — not a real fault. */
|
|
12888
|
-
PROCESS: 'process',
|
|
12889
|
-
/** Resource lookup failed or was rate-limited. */
|
|
12890
|
-
RESOURCE: 'resource',
|
|
12891
|
-
/** Invalid input or business-rule validation failure. */
|
|
12892
|
-
VALIDATION: 'validation'
|
|
12893
|
-
};
|
|
12894
|
-
/**
|
|
12895
|
-
* Concrete cause of an error. More specific than {@link ERROR_CATEGORY} —
|
|
12896
|
-
* useful for deciding programmatic responses (e.g. show a retry button only
|
|
12897
|
-
* when `cause` is `'service_unreachable'` or `'server_busy'`).
|
|
12898
|
-
*/
|
|
12899
|
-
var ERROR_CAUSE = {
|
|
12900
|
-
/** Operation was aborted programmatically. */
|
|
12901
|
-
ABORTED: 'aborted',
|
|
12902
|
-
/** Caller has insufficient permissions for the operation. */
|
|
12903
|
-
ACCESS_FORBIDDEN: 'access_forbidden',
|
|
12904
|
-
/** Resource already exists when create was expected. */
|
|
12905
|
-
ALREADY_EXISTS: 'already_exists',
|
|
12906
|
-
/** User cancelled the flow (e.g. closed the wallet sheet). */
|
|
12907
|
-
CANCELED: 'canceled',
|
|
12908
|
-
/** SDK was instantiated or invoked with invalid configuration. */
|
|
12909
|
-
INVALID_CONFIGURATION: 'invalid_configuration',
|
|
12910
|
-
/** Input failed structural or business-rule validation. */
|
|
12911
|
-
INVALID_INPUT: 'invalid_input',
|
|
12912
|
-
/** Resource was not found by the backend. */
|
|
12913
|
-
NOT_FOUND: 'not_found',
|
|
12914
|
-
/** Operation is not supported in the current context or version. */
|
|
12915
|
-
NOT_IMPLEMENTED: 'not_implemented',
|
|
12916
|
-
/** Caller exceeded the allowed request rate. */
|
|
12917
|
-
RATE_LIMITED: 'rate_limited',
|
|
12918
|
-
/** Backend is healthy but currently overloaded — typically retryable. */
|
|
12919
|
-
SERVER_BUSY: 'server_busy',
|
|
12920
|
-
/** Backend or third-party service could not be reached — typically retryable. */
|
|
12921
|
-
SERVICE_UNREACHABLE: 'service_unreachable',
|
|
12922
|
-
/** Caller is not authenticated. */
|
|
12923
|
-
UNAUTHORIZED: 'unauthorized',
|
|
12924
|
-
/** Catch-all when no other cause applies. */
|
|
12925
|
-
UNKNOWN: 'unknown_error',
|
|
12926
|
-
/** Request was syntactically valid but semantically rejected. */
|
|
12927
|
-
UNPROCESSABLE_ENTITY: 'unprocessable_entity'
|
|
12928
|
-
};
|
|
12929
|
-
var EventError = /*#__PURE__*/function (_Error) {
|
|
12930
|
-
function EventError(cause, category, retryable, details) {
|
|
12931
|
-
var _this;
|
|
12932
|
-
_classCallCheck(this, EventError);
|
|
12933
|
-
_this = _callSuper(this, EventError, [details.message]);
|
|
12934
|
-
_this.cause = cause;
|
|
12935
|
-
_this.category = category;
|
|
12936
|
-
_this.retryable = retryable;
|
|
12937
|
-
_this.details = details;
|
|
12938
|
-
Object.setPrototypeOf(_this, EventError.prototype);
|
|
12939
|
-
_this.name = EventError.name;
|
|
12940
|
-
return _this;
|
|
12941
|
-
}
|
|
12942
|
-
_inherits(EventError, _Error);
|
|
12943
|
-
return _createClass(EventError, [{
|
|
12944
|
-
key: "toJSON",
|
|
12945
|
-
value: function toJSON() {
|
|
12946
|
-
return {
|
|
12947
|
-
error: {
|
|
12948
|
-
category: this.category,
|
|
12949
|
-
cause: this.cause,
|
|
12950
|
-
details: this.details,
|
|
12951
|
-
retryable: this.retryable
|
|
12952
|
-
}
|
|
12953
|
-
};
|
|
13864
|
+
if ((_a = configuration.defined_form_fields) === null || _a === void 0 ? void 0 : _a.includes(field)) {
|
|
13865
|
+
return field;
|
|
12954
13866
|
}
|
|
12955
|
-
|
|
12956
|
-
|
|
12957
|
-
value: function setContextId(contextId) {
|
|
12958
|
-
this.details.contextId = contextId;
|
|
13867
|
+
if ((_b = configuration.defined_form_fields) === null || _b === void 0 ? void 0 : _b.includes("".concat(field, "*"))) {
|
|
13868
|
+
return "".concat(field, "*");
|
|
12959
13869
|
}
|
|
12960
|
-
}
|
|
12961
|
-
|
|
12962
|
-
|
|
12963
|
-
|
|
13870
|
+
}).filter(Boolean);
|
|
13871
|
+
}
|
|
13872
|
+
function getDynamicFormFields(configuration) {
|
|
13873
|
+
var _a;
|
|
13874
|
+
var baseFormFields = getBaseFormFields(configuration);
|
|
13875
|
+
return (_a = configuration.defined_form_fields) === null || _a === void 0 ? void 0 : _a.map(function (field) {
|
|
13876
|
+
var sanitizedField = field.replace('*', '');
|
|
13877
|
+
if (baseFormFields.includes(sanitizedField)) {
|
|
13878
|
+
return field;
|
|
12964
13879
|
}
|
|
12965
|
-
}
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
message: message,
|
|
12974
|
-
timestamp: new Date().toISOString()
|
|
12975
|
-
};
|
|
12976
|
-
var category = getErrorCategory(cause);
|
|
12977
|
-
return new EventError(cause, category, retryable, details);
|
|
13880
|
+
}).filter(Boolean);
|
|
13881
|
+
}
|
|
13882
|
+
function getMetaFields(configuration) {
|
|
13883
|
+
return Object.values(META_FIELDS).reduce(function (accumulator, metaField) {
|
|
13884
|
+
var _a;
|
|
13885
|
+
var configurationMetaFieldValue = (_a = configuration.meta) === null || _a === void 0 ? void 0 : _a[metaField];
|
|
13886
|
+
if (!configurationMetaFieldValue) {
|
|
13887
|
+
return accumulator;
|
|
12978
13888
|
}
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
|
|
12999
|
-
case
|
|
13000
|
-
|
|
13001
|
-
|
|
13889
|
+
return _extends({}, accumulator, _defineProperty({}, metaField, configuration.meta[metaField]));
|
|
13890
|
+
}, {});
|
|
13891
|
+
}
|
|
13892
|
+
function getPredefinedFields(configuration) {
|
|
13893
|
+
var gatewayId = configuration.predefined_fields.gateway_id === 'not_configured' ? '' : configuration.predefined_fields.gateway_id;
|
|
13894
|
+
return _extends({}, configuration.predefined_fields, {
|
|
13895
|
+
gateway_id: gatewayId
|
|
13896
|
+
});
|
|
13897
|
+
}
|
|
13898
|
+
function getWrongPredefinedFields(configuration) {
|
|
13899
|
+
var erroringFields = getBasePredefinedFields(configuration).map(function (field) {
|
|
13900
|
+
return !configuration.predefined_fields[field] ? field : '';
|
|
13901
|
+
}).filter(Boolean);
|
|
13902
|
+
if (erroringFields.length) {
|
|
13903
|
+
return erroringFields.join(', ').concat(" ".concat(erroringFields.length > 1 ? 'are' : 'is', " cannot be empty"));
|
|
13904
|
+
}
|
|
13905
|
+
}
|
|
13906
|
+
function getBasePredefinedFields(configuration) {
|
|
13907
|
+
var basePredefinedFields = [PREDEFINED_FIELDS.GATEWAY_ID, PREDEFINED_FIELDS.TYPE];
|
|
13908
|
+
switch (configuration.predefined_fields.type) {
|
|
13909
|
+
case PAYMENT_SOURCE_TYPE.GIFT_CARD:
|
|
13910
|
+
{
|
|
13911
|
+
return basePredefinedFields.concat([PREDEFINED_FIELDS.CARD_SCHEME, PREDEFINED_FIELDS.CARD_PROCESSING_NETWORK]);
|
|
13912
|
+
}
|
|
13002
13913
|
default:
|
|
13003
|
-
|
|
13914
|
+
{
|
|
13915
|
+
return basePredefinedFields;
|
|
13916
|
+
}
|
|
13917
|
+
}
|
|
13918
|
+
}
|
|
13919
|
+
function getHandleCvv(configuration) {
|
|
13920
|
+
switch (configuration.purpose) {
|
|
13921
|
+
case PURPOSE.CARD_PAYMENT_SOURCE_WITH_CVV:
|
|
13922
|
+
{
|
|
13923
|
+
return true;
|
|
13924
|
+
}
|
|
13925
|
+
case PURPOSE.CARD_PAYMENT_SOURCE_WITHOUT_CVV:
|
|
13926
|
+
{
|
|
13927
|
+
return false;
|
|
13928
|
+
}
|
|
13929
|
+
default:
|
|
13930
|
+
{
|
|
13931
|
+
return undefined;
|
|
13932
|
+
}
|
|
13004
13933
|
}
|
|
13005
13934
|
}
|
|
13006
13935
|
|
|
@@ -19098,6 +20027,90 @@
|
|
|
19098
20027
|
EVENT["ON_SHIPPING_OPTIONS_CHANGE"] = "onShippingOptionsChange";
|
|
19099
20028
|
})(EVENT$1 || (EVENT$1 = {}));
|
|
19100
20029
|
|
|
20030
|
+
/** TTL for a cached service configuration: 1 day, in milliseconds. */
|
|
20031
|
+
var CACHE_TTL_MS = 86400000;
|
|
20032
|
+
/** Builds the `localStorage` key used to cache a service's configuration. */
|
|
20033
|
+
function serviceConfigStorageKey(serviceId) {
|
|
20034
|
+
return "paydock-serviceConfig-".concat(serviceId);
|
|
20035
|
+
}
|
|
20036
|
+
/**
|
|
20037
|
+
* Removes the cached service configuration for the given service ID, forcing the next
|
|
20038
|
+
* fetch to go to the network. Called on error / unavailable flows so a potentially
|
|
20039
|
+
* stale cached config is not reused after something changed server-side. No-throw when
|
|
20040
|
+
* `localStorage` is unavailable.
|
|
20041
|
+
*
|
|
20042
|
+
* @param serviceId - The service ID whose cached configuration should be cleared.
|
|
20043
|
+
*/
|
|
20044
|
+
function clearServiceConfigCache(serviceId) {
|
|
20045
|
+
try {
|
|
20046
|
+
localStorage.removeItem(serviceConfigStorageKey(serviceId));
|
|
20047
|
+
} catch (_error) {
|
|
20048
|
+
// localStorage may be unavailable; nothing to clear
|
|
20049
|
+
}
|
|
20050
|
+
}
|
|
20051
|
+
/**
|
|
20052
|
+
* Fetches the wallet service configuration, backed by a 1-day `localStorage` cache
|
|
20053
|
+
* keyed on the service ID. Falls back gracefully (no caching) when `localStorage`
|
|
20054
|
+
* is unavailable (e.g. private browsing). Shared by the instance `load()` flow and
|
|
20055
|
+
* the static availability checks so both reuse the same cached fetch.
|
|
20056
|
+
*
|
|
20057
|
+
* @param api - The configured API client (env must already be set).
|
|
20058
|
+
* @param serviceId - The service ID to fetch the configuration for.
|
|
20059
|
+
* @returns The service configuration response.
|
|
20060
|
+
*/
|
|
20061
|
+
function getServiceConfigCached(api, serviceId) {
|
|
20062
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
20063
|
+
var storageKey, cachedData, _JSON$parse, data, timestamp, serviceConfigResponse, encodedData;
|
|
20064
|
+
return _regenerator().w(function (_context) {
|
|
20065
|
+
while (1) switch (_context.p = _context.n) {
|
|
20066
|
+
case 0:
|
|
20067
|
+
storageKey = serviceConfigStorageKey(serviceId);
|
|
20068
|
+
_context.p = 1;
|
|
20069
|
+
cachedData = localStorage.getItem(storageKey);
|
|
20070
|
+
if (!cachedData) {
|
|
20071
|
+
_context.n = 5;
|
|
20072
|
+
break;
|
|
20073
|
+
}
|
|
20074
|
+
_context.p = 2;
|
|
20075
|
+
_JSON$parse = JSON.parse(atob(cachedData)), data = _JSON$parse.data, timestamp = _JSON$parse.timestamp;
|
|
20076
|
+
if (!(Date.now() - timestamp < CACHE_TTL_MS)) {
|
|
20077
|
+
_context.n = 3;
|
|
20078
|
+
break;
|
|
20079
|
+
}
|
|
20080
|
+
return _context.a(2, JSON.parse(data));
|
|
20081
|
+
case 3:
|
|
20082
|
+
_context.n = 5;
|
|
20083
|
+
break;
|
|
20084
|
+
case 4:
|
|
20085
|
+
_context.p = 4;
|
|
20086
|
+
_context.v;
|
|
20087
|
+
localStorage.removeItem(storageKey);
|
|
20088
|
+
case 5:
|
|
20089
|
+
_context.n = 7;
|
|
20090
|
+
break;
|
|
20091
|
+
case 6:
|
|
20092
|
+
_context.p = 6;
|
|
20093
|
+
_context.v;
|
|
20094
|
+
case 7:
|
|
20095
|
+
_context.n = 8;
|
|
20096
|
+
return api.service().getConfig(serviceId);
|
|
20097
|
+
case 8:
|
|
20098
|
+
serviceConfigResponse = _context.v;
|
|
20099
|
+
try {
|
|
20100
|
+
encodedData = btoa(JSON.stringify({
|
|
20101
|
+
data: JSON.stringify(serviceConfigResponse),
|
|
20102
|
+
timestamp: Date.now()
|
|
20103
|
+
}));
|
|
20104
|
+
localStorage.setItem(storageKey, encodedData);
|
|
20105
|
+
} catch (_error) {
|
|
20106
|
+
// localStorage may be unavailable; proceed without caching
|
|
20107
|
+
}
|
|
20108
|
+
return _context.a(2, serviceConfigResponse);
|
|
20109
|
+
}
|
|
20110
|
+
}, _callee, null, [[2, 4], [1, 6]]);
|
|
20111
|
+
}));
|
|
20112
|
+
}
|
|
20113
|
+
|
|
19101
20114
|
/**
|
|
19102
20115
|
* @classdesc Abstract base class for Open Wallet buttons. **Do not instantiate directly.**
|
|
19103
20116
|
* Use {@link ApplePayOpenWalletButton} or {@link GooglePayOpenWalletButton} instead.
|
|
@@ -19131,10 +20144,30 @@
|
|
|
19131
20144
|
this.api = new ApiInternal(publicKeyOrAccessToken, this.getApiAuthType(publicKeyOrAccessToken));
|
|
19132
20145
|
this.serviceId = serviceId;
|
|
19133
20146
|
this.meta = meta;
|
|
20147
|
+
this.registerCacheInvalidationOnError();
|
|
19134
20148
|
this.validateBaseMeta();
|
|
19135
20149
|
this.validateWalletMeta();
|
|
19136
20150
|
}
|
|
20151
|
+
/**
|
|
20152
|
+
* Invalidates the cached service configuration whenever an error or unavailable
|
|
20153
|
+
* event fires, so the next `load()` re-fetches a fresh config. The cache is keyed
|
|
20154
|
+
* on the service ID with a 1-day TTL; clearing it on failure means a config that
|
|
20155
|
+
* changed server-side (and caused the failure) is not reused until the TTL expires.
|
|
20156
|
+
* Registered once per button, independently of any merchant-registered handlers.
|
|
20157
|
+
*
|
|
20158
|
+
* @private
|
|
20159
|
+
*/
|
|
19137
20160
|
return _createClass(OpenWalletButtons, [{
|
|
20161
|
+
key: "registerCacheInvalidationOnError",
|
|
20162
|
+
value: function registerCacheInvalidationOnError() {
|
|
20163
|
+
var _this = this;
|
|
20164
|
+
var invalidate = function invalidate() {
|
|
20165
|
+
return clearServiceConfigCache(_this.serviceId);
|
|
20166
|
+
};
|
|
20167
|
+
this.eventEmitter.subscribe(EVENT$1.ERROR, invalidate);
|
|
20168
|
+
this.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, invalidate);
|
|
20169
|
+
}
|
|
20170
|
+
}, {
|
|
19138
20171
|
key: "getApiAuthType",
|
|
19139
20172
|
value: function getApiAuthType(publicKeyOrAccessToken) {
|
|
19140
20173
|
if (AccessToken.validateJWT(publicKeyOrAccessToken)) {
|
|
@@ -19168,57 +20201,7 @@
|
|
|
19168
20201
|
}, {
|
|
19169
20202
|
key: "getOpenWalletServiceConfig",
|
|
19170
20203
|
value: function getOpenWalletServiceConfig() {
|
|
19171
|
-
return
|
|
19172
|
-
var storageKey, cachedData, _JSON$parse, data, timestamp, oneDay, serviceConfigResponse, encodedData;
|
|
19173
|
-
return _regenerator().w(function (_context) {
|
|
19174
|
-
while (1) switch (_context.p = _context.n) {
|
|
19175
|
-
case 0:
|
|
19176
|
-
storageKey = "serviceConfig-".concat(this.serviceId);
|
|
19177
|
-
_context.p = 1;
|
|
19178
|
-
cachedData = localStorage.getItem(storageKey);
|
|
19179
|
-
if (!cachedData) {
|
|
19180
|
-
_context.n = 5;
|
|
19181
|
-
break;
|
|
19182
|
-
}
|
|
19183
|
-
_context.p = 2;
|
|
19184
|
-
_JSON$parse = JSON.parse(atob(cachedData)), data = _JSON$parse.data, timestamp = _JSON$parse.timestamp;
|
|
19185
|
-
oneDay = 86400000;
|
|
19186
|
-
if (!(Date.now() - timestamp < oneDay)) {
|
|
19187
|
-
_context.n = 3;
|
|
19188
|
-
break;
|
|
19189
|
-
}
|
|
19190
|
-
return _context.a(2, JSON.parse(data));
|
|
19191
|
-
case 3:
|
|
19192
|
-
_context.n = 5;
|
|
19193
|
-
break;
|
|
19194
|
-
case 4:
|
|
19195
|
-
_context.p = 4;
|
|
19196
|
-
_context.v;
|
|
19197
|
-
localStorage.removeItem(storageKey);
|
|
19198
|
-
case 5:
|
|
19199
|
-
_context.n = 7;
|
|
19200
|
-
break;
|
|
19201
|
-
case 6:
|
|
19202
|
-
_context.p = 6;
|
|
19203
|
-
_context.v;
|
|
19204
|
-
case 7:
|
|
19205
|
-
_context.n = 8;
|
|
19206
|
-
return this.api.service().getConfig(this.serviceId);
|
|
19207
|
-
case 8:
|
|
19208
|
-
serviceConfigResponse = _context.v;
|
|
19209
|
-
try {
|
|
19210
|
-
encodedData = btoa(JSON.stringify({
|
|
19211
|
-
data: JSON.stringify(serviceConfigResponse),
|
|
19212
|
-
timestamp: Date.now()
|
|
19213
|
-
}));
|
|
19214
|
-
localStorage.setItem(storageKey, encodedData);
|
|
19215
|
-
} catch (_error) {
|
|
19216
|
-
// localStorage may be unavailable; proceed without caching
|
|
19217
|
-
}
|
|
19218
|
-
return _context.a(2, serviceConfigResponse);
|
|
19219
|
-
}
|
|
19220
|
-
}, _callee, this, [[2, 4], [1, 6]]);
|
|
19221
|
-
}));
|
|
20204
|
+
return getServiceConfigCached(this.api, this.serviceId);
|
|
19222
20205
|
}
|
|
19223
20206
|
}, {
|
|
19224
20207
|
key: "handleOnError",
|
|
@@ -19253,13 +20236,13 @@
|
|
|
19253
20236
|
}, {
|
|
19254
20237
|
key: "load",
|
|
19255
20238
|
value: function load() {
|
|
19256
|
-
var
|
|
20239
|
+
var _this2 = this;
|
|
19257
20240
|
this.getOpenWalletServiceConfig().then(function (serviceConfig) {
|
|
19258
|
-
|
|
19259
|
-
|
|
19260
|
-
|
|
20241
|
+
_this2.validateServiceType(serviceConfig);
|
|
20242
|
+
_this2.walletService = _this2.createWalletService(serviceConfig);
|
|
20243
|
+
_this2.walletService.load();
|
|
19261
20244
|
})["catch"](function (error) {
|
|
19262
|
-
|
|
20245
|
+
_this2.handleOnError(error instanceof Error ? error : new Error(String(error)), exports.ERROR_OPERATION.CONFIGURATION);
|
|
19263
20246
|
});
|
|
19264
20247
|
}
|
|
19265
20248
|
/**
|
|
@@ -19457,28 +20440,28 @@
|
|
|
19457
20440
|
}, {
|
|
19458
20441
|
key: "onSuccess",
|
|
19459
20442
|
value: function onSuccess(handler) {
|
|
19460
|
-
var
|
|
20443
|
+
var _this3 = this;
|
|
19461
20444
|
if (typeof handler === 'function') {
|
|
19462
20445
|
this.eventEmitter.subscribe(EVENT$1.SUCCESS, function (data) {
|
|
19463
|
-
return __awaiter(
|
|
19464
|
-
var
|
|
19465
|
-
return _regenerator().w(function (
|
|
19466
|
-
while (1) switch (
|
|
20446
|
+
return __awaiter(_this3, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
20447
|
+
var _t;
|
|
20448
|
+
return _regenerator().w(function (_context) {
|
|
20449
|
+
while (1) switch (_context.p = _context.n) {
|
|
19467
20450
|
case 0:
|
|
19468
|
-
|
|
19469
|
-
|
|
20451
|
+
_context.p = 0;
|
|
20452
|
+
_context.n = 1;
|
|
19470
20453
|
return handler(data);
|
|
19471
20454
|
case 1:
|
|
19472
|
-
|
|
20455
|
+
_context.n = 3;
|
|
19473
20456
|
break;
|
|
19474
20457
|
case 2:
|
|
19475
|
-
|
|
19476
|
-
|
|
19477
|
-
console.warn('Merchant onSuccess handler threw (swallowed):',
|
|
20458
|
+
_context.p = 2;
|
|
20459
|
+
_t = _context.v;
|
|
20460
|
+
console.warn('Merchant onSuccess handler threw (swallowed):', _t);
|
|
19478
20461
|
case 3:
|
|
19479
|
-
return
|
|
20462
|
+
return _context.a(2);
|
|
19480
20463
|
}
|
|
19481
|
-
},
|
|
20464
|
+
}, _callee, null, [[0, 2]]);
|
|
19482
20465
|
}));
|
|
19483
20466
|
});
|
|
19484
20467
|
return;
|
|
@@ -19509,28 +20492,28 @@
|
|
|
19509
20492
|
}, {
|
|
19510
20493
|
key: "onUnavailable",
|
|
19511
20494
|
value: function onUnavailable(handler) {
|
|
19512
|
-
var
|
|
20495
|
+
var _this4 = this;
|
|
19513
20496
|
if (typeof handler === 'function') {
|
|
19514
20497
|
this.eventEmitter.subscribe(EVENT$1.UNAVAILABLE, function (data) {
|
|
19515
|
-
return __awaiter(
|
|
19516
|
-
var
|
|
19517
|
-
return _regenerator().w(function (
|
|
19518
|
-
while (1) switch (
|
|
20498
|
+
return __awaiter(_this4, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
20499
|
+
var _t2;
|
|
20500
|
+
return _regenerator().w(function (_context2) {
|
|
20501
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
19519
20502
|
case 0:
|
|
19520
|
-
|
|
19521
|
-
|
|
20503
|
+
_context2.p = 0;
|
|
20504
|
+
_context2.n = 1;
|
|
19522
20505
|
return handler(data);
|
|
19523
20506
|
case 1:
|
|
19524
|
-
|
|
20507
|
+
_context2.n = 3;
|
|
19525
20508
|
break;
|
|
19526
20509
|
case 2:
|
|
19527
|
-
|
|
19528
|
-
|
|
19529
|
-
console.warn('Merchant onUnavailable handler threw (swallowed):',
|
|
20510
|
+
_context2.p = 2;
|
|
20511
|
+
_t2 = _context2.v;
|
|
20512
|
+
console.warn('Merchant onUnavailable handler threw (swallowed):', _t2);
|
|
19530
20513
|
case 3:
|
|
19531
|
-
return
|
|
20514
|
+
return _context2.a(2);
|
|
19532
20515
|
}
|
|
19533
|
-
},
|
|
20516
|
+
}, _callee2, null, [[0, 2]]);
|
|
19534
20517
|
}));
|
|
19535
20518
|
});
|
|
19536
20519
|
return;
|
|
@@ -19562,28 +20545,28 @@
|
|
|
19562
20545
|
}, {
|
|
19563
20546
|
key: "onError",
|
|
19564
20547
|
value: function onError(handler) {
|
|
19565
|
-
var
|
|
20548
|
+
var _this5 = this;
|
|
19566
20549
|
if (typeof handler === 'function') {
|
|
19567
20550
|
this.eventEmitter.subscribe(EVENT$1.ERROR, function (data) {
|
|
19568
|
-
return __awaiter(
|
|
19569
|
-
var
|
|
19570
|
-
return _regenerator().w(function (
|
|
19571
|
-
while (1) switch (
|
|
20551
|
+
return __awaiter(_this5, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
|
|
20552
|
+
var _t3;
|
|
20553
|
+
return _regenerator().w(function (_context3) {
|
|
20554
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
19572
20555
|
case 0:
|
|
19573
|
-
|
|
19574
|
-
|
|
20556
|
+
_context3.p = 0;
|
|
20557
|
+
_context3.n = 1;
|
|
19575
20558
|
return handler(data);
|
|
19576
20559
|
case 1:
|
|
19577
|
-
|
|
20560
|
+
_context3.n = 3;
|
|
19578
20561
|
break;
|
|
19579
20562
|
case 2:
|
|
19580
|
-
|
|
19581
|
-
|
|
19582
|
-
console.warn('Merchant onError handler threw (swallowed):',
|
|
20563
|
+
_context3.p = 2;
|
|
20564
|
+
_t3 = _context3.v;
|
|
20565
|
+
console.warn('Merchant onError handler threw (swallowed):', _t3);
|
|
19583
20566
|
case 3:
|
|
19584
|
-
return
|
|
20567
|
+
return _context3.a(2);
|
|
19585
20568
|
}
|
|
19586
|
-
},
|
|
20569
|
+
}, _callee3, null, [[0, 2]]);
|
|
19587
20570
|
}));
|
|
19588
20571
|
});
|
|
19589
20572
|
return;
|
|
@@ -19614,28 +20597,28 @@
|
|
|
19614
20597
|
}, {
|
|
19615
20598
|
key: "onCancel",
|
|
19616
20599
|
value: function onCancel(handler) {
|
|
19617
|
-
var
|
|
20600
|
+
var _this6 = this;
|
|
19618
20601
|
if (typeof handler === 'function') {
|
|
19619
20602
|
this.eventEmitter.subscribe(EVENT$1.CHECKOUT_CLOSE, function (data) {
|
|
19620
|
-
return __awaiter(
|
|
19621
|
-
var
|
|
19622
|
-
return _regenerator().w(function (
|
|
19623
|
-
while (1) switch (
|
|
20603
|
+
return __awaiter(_this6, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
|
|
20604
|
+
var _t4;
|
|
20605
|
+
return _regenerator().w(function (_context4) {
|
|
20606
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
19624
20607
|
case 0:
|
|
19625
|
-
|
|
19626
|
-
|
|
20608
|
+
_context4.p = 0;
|
|
20609
|
+
_context4.n = 1;
|
|
19627
20610
|
return handler(data);
|
|
19628
20611
|
case 1:
|
|
19629
|
-
|
|
20612
|
+
_context4.n = 3;
|
|
19630
20613
|
break;
|
|
19631
20614
|
case 2:
|
|
19632
|
-
|
|
19633
|
-
|
|
19634
|
-
console.warn('Merchant onCancel handler threw (swallowed):',
|
|
20615
|
+
_context4.p = 2;
|
|
20616
|
+
_t4 = _context4.v;
|
|
20617
|
+
console.warn('Merchant onCancel handler threw (swallowed):', _t4);
|
|
19635
20618
|
case 3:
|
|
19636
|
-
return
|
|
20619
|
+
return _context4.a(2);
|
|
19637
20620
|
}
|
|
19638
|
-
},
|
|
20621
|
+
}, _callee4, null, [[0, 2]]);
|
|
19639
20622
|
}));
|
|
19640
20623
|
});
|
|
19641
20624
|
return;
|
|
@@ -19659,28 +20642,28 @@
|
|
|
19659
20642
|
}, {
|
|
19660
20643
|
key: "onLoaded",
|
|
19661
20644
|
value: function onLoaded(handler) {
|
|
19662
|
-
var
|
|
20645
|
+
var _this7 = this;
|
|
19663
20646
|
if (typeof handler === 'function') {
|
|
19664
20647
|
this.eventEmitter.subscribe(EVENT$1.LOADED, function (data) {
|
|
19665
|
-
return __awaiter(
|
|
19666
|
-
var
|
|
19667
|
-
return _regenerator().w(function (
|
|
19668
|
-
while (1) switch (
|
|
20648
|
+
return __awaiter(_this7, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
|
|
20649
|
+
var _t5;
|
|
20650
|
+
return _regenerator().w(function (_context5) {
|
|
20651
|
+
while (1) switch (_context5.p = _context5.n) {
|
|
19669
20652
|
case 0:
|
|
19670
|
-
|
|
19671
|
-
|
|
20653
|
+
_context5.p = 0;
|
|
20654
|
+
_context5.n = 1;
|
|
19672
20655
|
return handler(data);
|
|
19673
20656
|
case 1:
|
|
19674
|
-
|
|
20657
|
+
_context5.n = 3;
|
|
19675
20658
|
break;
|
|
19676
20659
|
case 2:
|
|
19677
|
-
|
|
19678
|
-
|
|
19679
|
-
console.warn('Merchant onLoaded handler threw (swallowed):',
|
|
20660
|
+
_context5.p = 2;
|
|
20661
|
+
_t5 = _context5.v;
|
|
20662
|
+
console.warn('Merchant onLoaded handler threw (swallowed):', _t5);
|
|
19680
20663
|
case 3:
|
|
19681
|
-
return
|
|
20664
|
+
return _context5.a(2);
|
|
19682
20665
|
}
|
|
19683
|
-
},
|
|
20666
|
+
}, _callee5, null, [[0, 2]]);
|
|
19684
20667
|
}));
|
|
19685
20668
|
});
|
|
19686
20669
|
return;
|
|
@@ -20028,7 +21011,143 @@
|
|
|
20028
21011
|
WALLET_TYPES["GOOGLE_PAY"] = "google";
|
|
20029
21012
|
})(exports.WALLET_TYPES || (exports.WALLET_TYPES = {}));
|
|
20030
21013
|
|
|
20031
|
-
|
|
21014
|
+
/** CDN location of Apple's web SDK (provides the `<apple-pay-button>` web component). */
|
|
21015
|
+
var APPLE_PAY_SDK_URL = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
|
|
21016
|
+
/**
|
|
21017
|
+
* Statuses that count as available when the merchant does not override them.
|
|
21018
|
+
* Includes `paymentCredentialStatusUnknown` so the button is shown in third-party /
|
|
21019
|
+
* cross-device (QR) browsers, per Apple's guidance.
|
|
21020
|
+
*/
|
|
21021
|
+
var DEFAULT_APPLE_PAY_CAPABILITIES$1 = ['paymentCredentialsAvailable', 'paymentCredentialStatusUnknown'];
|
|
21022
|
+
/**
|
|
21023
|
+
* Maps the SDK's friendly capability tokens to Apple's `PaymentCredentialStatus` values.
|
|
21024
|
+
* Unknown tokens are passed through unchanged.
|
|
21025
|
+
*/
|
|
21026
|
+
function formatCapabilities(capabilities) {
|
|
21027
|
+
var fieldMap = {
|
|
21028
|
+
credentials_available: 'paymentCredentialsAvailable',
|
|
21029
|
+
credentials_status_unknown: 'paymentCredentialStatusUnknown',
|
|
21030
|
+
credentials_unavailable: 'paymentCredentialsUnavailable'
|
|
21031
|
+
};
|
|
21032
|
+
return capabilities.map(function (capability) {
|
|
21033
|
+
return fieldMap[capability] || capability;
|
|
21034
|
+
});
|
|
21035
|
+
}
|
|
21036
|
+
/**
|
|
21037
|
+
* Synchronous, network-free check for a **native, same-device** Apple Pay session
|
|
21038
|
+
* (`window.ApplePaySession` exists and `canMakePayments()` is `true`). Safe to call in
|
|
21039
|
+
* any environment (never throws).
|
|
21040
|
+
*
|
|
21041
|
+
* Note: this is a legacy/Safari-oriented signal. It is **not** authoritative for
|
|
21042
|
+
* cross-browser / cross-device (QR) availability — in Chrome/Edge/Firefox
|
|
21043
|
+
* `window.ApplePaySession` is supplied by the CDN SDK and may be absent until it loads,
|
|
21044
|
+
* and the cross-device flow is reflected by `applePayCapabilities()`, not this call.
|
|
21045
|
+
* Use {@link evaluateApplePayAvailability} for the authoritative, cross-browser answer.
|
|
21046
|
+
*/
|
|
21047
|
+
function hasNativeApplePaySession() {
|
|
21048
|
+
try {
|
|
21049
|
+
return typeof window !== 'undefined' && !!window.ApplePaySession && typeof ApplePaySession !== 'undefined' && ApplePaySession.canMakePayments();
|
|
21050
|
+
} catch (_a) {
|
|
21051
|
+
return false;
|
|
21052
|
+
}
|
|
21053
|
+
}
|
|
21054
|
+
var sdkLoadPromise = null;
|
|
21055
|
+
/**
|
|
21056
|
+
* Idempotently loads Apple's web SDK from the CDN.
|
|
21057
|
+
* Resolves immediately if the `<apple-pay-button>` custom element is already
|
|
21058
|
+
* registered, and de-duplicates concurrent loads. Rejects if the script fails to load.
|
|
21059
|
+
*/
|
|
21060
|
+
function loadApplePaySdk() {
|
|
21061
|
+
if (typeof customElements !== 'undefined' && customElements.get('apple-pay-button')) {
|
|
21062
|
+
return Promise.resolve();
|
|
21063
|
+
}
|
|
21064
|
+
if (sdkLoadPromise) {
|
|
21065
|
+
return sdkLoadPromise;
|
|
21066
|
+
}
|
|
21067
|
+
sdkLoadPromise = new Promise(function (resolve, reject) {
|
|
21068
|
+
var script = document.createElement('script');
|
|
21069
|
+
script.src = APPLE_PAY_SDK_URL;
|
|
21070
|
+
script.type = 'text/javascript';
|
|
21071
|
+
script.crossOrigin = 'anonymous';
|
|
21072
|
+
script.onload = function () {
|
|
21073
|
+
return resolve();
|
|
21074
|
+
};
|
|
21075
|
+
script.onerror = function () {
|
|
21076
|
+
// Allow a future retry after a transient failure.
|
|
21077
|
+
sdkLoadPromise = null;
|
|
21078
|
+
reject(new Error('Failed to load Apple Pay script'));
|
|
21079
|
+
};
|
|
21080
|
+
document.head.appendChild(script);
|
|
21081
|
+
});
|
|
21082
|
+
return sdkLoadPromise;
|
|
21083
|
+
}
|
|
21084
|
+
/**
|
|
21085
|
+
* Core Apple Pay availability evaluation, shared by the instance flow
|
|
21086
|
+
* (`ApplePayOpenWalletService`) and the static `ApplePayOpenWalletButton.checkAvailability`.
|
|
21087
|
+
*
|
|
21088
|
+
* Assumes the Apple Pay SDK is already loaded (call {@link loadApplePaySdk} first).
|
|
21089
|
+
*/
|
|
21090
|
+
function evaluateApplePayAvailability(params) {
|
|
21091
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
21092
|
+
var _a, hasNativeSession, allowed, capabilities, paymentCredentialStatus, available;
|
|
21093
|
+
return _regenerator().w(function (_context) {
|
|
21094
|
+
while (1) switch (_context.p = _context.n) {
|
|
21095
|
+
case 0:
|
|
21096
|
+
if (!(typeof window === 'undefined' || !window.ApplePaySession)) {
|
|
21097
|
+
_context.n = 1;
|
|
21098
|
+
break;
|
|
21099
|
+
}
|
|
21100
|
+
return _context.a(2, {
|
|
21101
|
+
available: false,
|
|
21102
|
+
supported: false,
|
|
21103
|
+
has_native_session: false,
|
|
21104
|
+
reason: 'unsupported_browser'
|
|
21105
|
+
});
|
|
21106
|
+
case 1:
|
|
21107
|
+
hasNativeSession = hasNativeApplePaySession();
|
|
21108
|
+
allowed = ((_a = params.apple_pay_capabilities) === null || _a === void 0 ? void 0 : _a.length) ? formatCapabilities(params.apple_pay_capabilities) : DEFAULT_APPLE_PAY_CAPABILITIES$1;
|
|
21109
|
+
_context.p = 2;
|
|
21110
|
+
_context.n = 3;
|
|
21111
|
+
return ApplePaySession.applePayCapabilities(params.merchantId);
|
|
21112
|
+
case 3:
|
|
21113
|
+
capabilities = _context.v;
|
|
21114
|
+
paymentCredentialStatus = capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus; // `applePayCapabilities` is authoritative: trust an explicit `applePayUnsupported`
|
|
21115
|
+
// (e.g. an unregistered/misconfigured merchant) rather than overriding it with the
|
|
21116
|
+
// coarse `canMakePayments()` signal.
|
|
21117
|
+
if (!(paymentCredentialStatus === 'applePayUnsupported')) {
|
|
21118
|
+
_context.n = 4;
|
|
21119
|
+
break;
|
|
21120
|
+
}
|
|
21121
|
+
return _context.a(2, {
|
|
21122
|
+
available: false,
|
|
21123
|
+
supported: false,
|
|
21124
|
+
has_native_session: hasNativeSession,
|
|
21125
|
+
payment_credential_status: paymentCredentialStatus,
|
|
21126
|
+
reason: 'unsupported_browser'
|
|
21127
|
+
});
|
|
21128
|
+
case 4:
|
|
21129
|
+
available = allowed.includes(paymentCredentialStatus);
|
|
21130
|
+
return _context.a(2, {
|
|
21131
|
+
available: available,
|
|
21132
|
+
supported: true,
|
|
21133
|
+
has_native_session: hasNativeSession,
|
|
21134
|
+
payment_credential_status: paymentCredentialStatus,
|
|
21135
|
+
reason: available ? undefined : 'no_credentials'
|
|
21136
|
+
});
|
|
21137
|
+
case 5:
|
|
21138
|
+
_context.p = 5;
|
|
21139
|
+
_context.v;
|
|
21140
|
+
return _context.a(2, {
|
|
21141
|
+
available: false,
|
|
21142
|
+
supported: hasNativeSession,
|
|
21143
|
+
has_native_session: hasNativeSession,
|
|
21144
|
+
reason: 'query_failed'
|
|
21145
|
+
});
|
|
21146
|
+
}
|
|
21147
|
+
}, _callee, null, [[2, 5]]);
|
|
21148
|
+
}));
|
|
21149
|
+
}
|
|
21150
|
+
|
|
20032
21151
|
/**
|
|
20033
21152
|
* Apple Pay implementation of the OpenWallet service.
|
|
20034
21153
|
*
|
|
@@ -20304,7 +21423,6 @@
|
|
|
20304
21423
|
value: function load() {
|
|
20305
21424
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
|
|
20306
21425
|
var _this4 = this;
|
|
20307
|
-
var applePayScript;
|
|
20308
21426
|
return _regenerator().w(function (_context3) {
|
|
20309
21427
|
while (1) switch (_context3.n) {
|
|
20310
21428
|
case 0:
|
|
@@ -20315,26 +21433,12 @@
|
|
|
20315
21433
|
this.handleOnUnavailable('Promises not supported');
|
|
20316
21434
|
return _context3.a(2);
|
|
20317
21435
|
case 1:
|
|
20318
|
-
|
|
20319
|
-
_context3.n = 2;
|
|
20320
|
-
break;
|
|
20321
|
-
}
|
|
20322
|
-
this.onScriptLoaded();
|
|
20323
|
-
return _context3.a(2);
|
|
20324
|
-
case 2:
|
|
20325
|
-
applePayScript = document.createElement('script');
|
|
20326
|
-
applePayScript.src = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js';
|
|
20327
|
-
applePayScript.type = 'text/javascript';
|
|
20328
|
-
applePayScript.crossOrigin = 'anonymous';
|
|
20329
|
-
applePayScript.onload = function () {
|
|
21436
|
+
loadApplePaySdk().then(function () {
|
|
20330
21437
|
_this4.onScriptLoaded();
|
|
20331
|
-
}
|
|
20332
|
-
applePayScript.onerror = function () {
|
|
21438
|
+
})["catch"](function () {
|
|
20333
21439
|
_this4.handleOnUnavailable('Failed to load Apple Pay script');
|
|
20334
|
-
|
|
20335
|
-
|
|
20336
|
-
document.head.appendChild(applePayScript);
|
|
20337
|
-
case 3:
|
|
21440
|
+
});
|
|
21441
|
+
case 2:
|
|
20338
21442
|
return _context3.a(2);
|
|
20339
21443
|
}
|
|
20340
21444
|
}, _callee3, this);
|
|
@@ -20362,26 +21466,22 @@
|
|
|
20362
21466
|
}, {
|
|
20363
21467
|
key: "checkAvailability",
|
|
20364
21468
|
value: function checkAvailability() {
|
|
20365
|
-
|
|
20366
|
-
|
|
20367
|
-
|
|
20368
|
-
|
|
20369
|
-
|
|
20370
|
-
|
|
20371
|
-
|
|
20372
|
-
|
|
20373
|
-
|
|
20374
|
-
|
|
20375
|
-
|
|
20376
|
-
|
|
20377
|
-
|
|
21469
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
|
|
21470
|
+
var result;
|
|
21471
|
+
return _regenerator().w(function (_context4) {
|
|
21472
|
+
while (1) switch (_context4.n) {
|
|
21473
|
+
case 0:
|
|
21474
|
+
_context4.n = 1;
|
|
21475
|
+
return evaluateApplePayAvailability({
|
|
21476
|
+
merchantId: this.getMerchantId(),
|
|
21477
|
+
apple_pay_capabilities: this.meta.apple_pay_capabilities
|
|
21478
|
+
});
|
|
21479
|
+
case 1:
|
|
21480
|
+
result = _context4.v;
|
|
21481
|
+
return _context4.a(2, result.available);
|
|
20378
21482
|
}
|
|
20379
|
-
|
|
20380
|
-
|
|
20381
|
-
})["catch"](function () {
|
|
20382
|
-
resolve(false);
|
|
20383
|
-
});
|
|
20384
|
-
});
|
|
21483
|
+
}, _callee4, this);
|
|
21484
|
+
}));
|
|
20385
21485
|
}
|
|
20386
21486
|
}, {
|
|
20387
21487
|
key: "mount",
|
|
@@ -20407,7 +21507,7 @@
|
|
|
20407
21507
|
}, {
|
|
20408
21508
|
key: "onApplePayButtonClicked",
|
|
20409
21509
|
value: function onApplePayButtonClicked() {
|
|
20410
|
-
var
|
|
21510
|
+
var _this6 = this;
|
|
20411
21511
|
if (this.isButtonDisabled()) {
|
|
20412
21512
|
return;
|
|
20413
21513
|
}
|
|
@@ -20426,26 +21526,27 @@
|
|
|
20426
21526
|
// As part of PAYCA-2065 we detect that the paymentSession.onvalidatemerchant is not
|
|
20427
21527
|
// executed if the browser is not safari. In that case, we handle it outside the
|
|
20428
21528
|
// actual merchant validation function.
|
|
20429
|
-
var
|
|
20430
|
-
var
|
|
21529
|
+
var userAgent = navigator.userAgent || '';
|
|
21530
|
+
var isIOS = userAgent.includes('iPhone') || userAgent.includes('iPad') || userAgent.includes('iPod');
|
|
21531
|
+
var isDesktopRequestIOS = navigator.maxTouchPoints > 1 && userAgent.includes('Macintosh');
|
|
20431
21532
|
if (!window.safari && !isIOS && !isDesktopRequestIOS) {
|
|
20432
21533
|
this.handleMerchantOnButtonClickEvent()["catch"](function (err) {
|
|
20433
21534
|
console.error('Error while processing merchant callback', err);
|
|
20434
|
-
|
|
21535
|
+
_this6.paymentSession.abort();
|
|
20435
21536
|
});
|
|
20436
21537
|
}
|
|
20437
21538
|
}
|
|
20438
21539
|
}, {
|
|
20439
21540
|
key: "getMerchantSession",
|
|
20440
21541
|
value: function getMerchantSession() {
|
|
20441
|
-
var
|
|
21542
|
+
var _this7 = this;
|
|
20442
21543
|
return new Promise(function (resolve, reject) {
|
|
20443
|
-
return
|
|
20444
|
-
service_id:
|
|
21544
|
+
return _this7.api.paymentSource().createSession(_extends({
|
|
21545
|
+
service_id: _this7.serviceId,
|
|
20445
21546
|
session_id: window.location.hostname,
|
|
20446
|
-
store_name:
|
|
20447
|
-
},
|
|
20448
|
-
request_shipping:
|
|
21547
|
+
store_name: _this7.meta.store_name
|
|
21548
|
+
}, _this7.isShippingRequired() && {
|
|
21549
|
+
request_shipping: _this7.meta.request_shipping
|
|
20449
21550
|
})).then(function (res) {
|
|
20450
21551
|
resolve(res);
|
|
20451
21552
|
})["catch"](function (err) {
|
|
@@ -20456,42 +21557,30 @@
|
|
|
20456
21557
|
}, {
|
|
20457
21558
|
key: "handleMerchantOnButtonClickEvent",
|
|
20458
21559
|
value: function handleMerchantOnButtonClickEvent() {
|
|
20459
|
-
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function
|
|
21560
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
|
|
20460
21561
|
var results;
|
|
20461
|
-
return _regenerator().w(function (
|
|
20462
|
-
while (1) switch (
|
|
21562
|
+
return _regenerator().w(function (_context5) {
|
|
21563
|
+
while (1) switch (_context5.n) {
|
|
20463
21564
|
case 0:
|
|
20464
|
-
|
|
21565
|
+
_context5.n = 1;
|
|
20465
21566
|
return this.eventEmitter.emitWithResult(EVENT$1.ON_CLICK, {
|
|
20466
21567
|
event: EVENT$1.ON_CLICK
|
|
20467
21568
|
});
|
|
20468
21569
|
case 1:
|
|
20469
|
-
results =
|
|
21570
|
+
results = _context5.v;
|
|
20470
21571
|
if (!results.some(function (r) {
|
|
20471
21572
|
return r === false;
|
|
20472
21573
|
})) {
|
|
20473
|
-
|
|
21574
|
+
_context5.n = 2;
|
|
20474
21575
|
break;
|
|
20475
21576
|
}
|
|
20476
21577
|
throw new Error('onClick handler aborted the payment flow');
|
|
20477
21578
|
case 2:
|
|
20478
|
-
return
|
|
21579
|
+
return _context5.a(2);
|
|
20479
21580
|
}
|
|
20480
|
-
},
|
|
21581
|
+
}, _callee5, this);
|
|
20481
21582
|
}));
|
|
20482
21583
|
}
|
|
20483
|
-
}, {
|
|
20484
|
-
key: "formatCapabilities",
|
|
20485
|
-
value: function formatCapabilities(capabilities) {
|
|
20486
|
-
var fieldMap = {
|
|
20487
|
-
credentials_available: 'paymentCredentialsAvailable',
|
|
20488
|
-
credentials_status_unknown: 'paymentCredentialStatusUnknown',
|
|
20489
|
-
credentials_unavailable: 'paymentCredentialsUnavailable'
|
|
20490
|
-
};
|
|
20491
|
-
return capabilities.map(function (capability) {
|
|
20492
|
-
return fieldMap[capability] || capability;
|
|
20493
|
-
});
|
|
20494
|
-
}
|
|
20495
21584
|
}, {
|
|
20496
21585
|
key: "formatErrorFields",
|
|
20497
21586
|
value: function formatErrorFields(error) {
|
|
@@ -20658,11 +21747,6 @@
|
|
|
20658
21747
|
applePayLaterAvailability: this.meta.apple_pay_later_availability
|
|
20659
21748
|
});
|
|
20660
21749
|
}
|
|
20661
|
-
}, {
|
|
20662
|
-
key: "isUnsuportedBrowser",
|
|
20663
|
-
value: function isUnsuportedBrowser(capabilities) {
|
|
20664
|
-
return (capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus) === 'applePayUnsupported';
|
|
20665
|
-
}
|
|
20666
21750
|
}]);
|
|
20667
21751
|
}(OpenWalletService);
|
|
20668
21752
|
|
|
@@ -20711,17 +21795,57 @@
|
|
|
20711
21795
|
return _this;
|
|
20712
21796
|
}
|
|
20713
21797
|
/**
|
|
20714
|
-
*
|
|
20715
|
-
*
|
|
21798
|
+
* Checks Apple Pay availability **without instantiating the button** — the single,
|
|
21799
|
+
* authoritative, cross-browser-aware availability entry point.
|
|
20716
21800
|
*
|
|
20717
|
-
*
|
|
20718
|
-
*
|
|
20719
|
-
*
|
|
21801
|
+
* Resolves the merchant identifier (either supplied directly or fetched from the
|
|
21802
|
+
* service configuration), loads Apple's web SDK if needed, then queries
|
|
21803
|
+
* `ApplePaySession.applePayCapabilities()`. Returns a convenience `available` verdict
|
|
21804
|
+
* (computed against `apple_pay_capabilities`), the raw device-reported
|
|
21805
|
+
* `payment_credential_status`, and `has_native_session` so callers can infer the transport:
|
|
21806
|
+
* `available && has_native_session` ⇒ native sheet likely; `available && !has_native_session`
|
|
21807
|
+
* ⇒ cross-device / QR handoff likely.
|
|
21808
|
+
*
|
|
21809
|
+
* Pass `{ sync: true }` for a cheap, network-free native same-device pre-check that
|
|
21810
|
+
* resolves immediately (see {@link ApplePayAvailabilityOptions.sync}).
|
|
21811
|
+
*
|
|
21812
|
+
* @param {ApplePayAvailabilityOptions} [options] - Merchant context, allowed capabilities, and mode.
|
|
21813
|
+
* @returns {Promise<ApplePayAvailabilityResult>} The availability result.
|
|
21814
|
+
*
|
|
21815
|
+
* @example
|
|
21816
|
+
* // Lightest path — no network, when you already know the merchant identifier:
|
|
21817
|
+
* const result = await ApplePayOpenWalletButton.checkAvailability({ merchant_id });
|
|
21818
|
+
*
|
|
21819
|
+
* @example
|
|
21820
|
+
* // Resolve the merchant identifier from the service configuration:
|
|
21821
|
+
* const result = await ApplePayOpenWalletButton.checkAvailability({
|
|
21822
|
+
* public_key_or_access_token,
|
|
21823
|
+
* service_id,
|
|
21824
|
+
* env: 'sandbox',
|
|
21825
|
+
* });
|
|
21826
|
+
* if (result.available) {
|
|
21827
|
+
* // Render the Apple Pay button (native sheet or cross-device QR, per has_native_session).
|
|
21828
|
+
* } else {
|
|
21829
|
+
* console.log('Unavailable:', result.reason, result.payment_credential_status);
|
|
21830
|
+
* }
|
|
21831
|
+
*
|
|
21832
|
+
* @example
|
|
21833
|
+
* // Synchronous native-only fast check (no network / SDK load):
|
|
21834
|
+
* const { has_native_session } = await ApplePayOpenWalletButton.checkAvailability({ sync: true });
|
|
20720
21835
|
*/
|
|
20721
21836
|
_inherits(ApplePayOpenWalletButton, _OpenWalletButtons);
|
|
20722
21837
|
return _createClass(ApplePayOpenWalletButton, [{
|
|
20723
21838
|
key: "validateWalletMeta",
|
|
20724
|
-
value:
|
|
21839
|
+
value:
|
|
21840
|
+
/**
|
|
21841
|
+
* Validates Apple Pay-specific required metadata fields.
|
|
21842
|
+
* Apple Pay requires `amount_label` and `store_name` to be present and strings.
|
|
21843
|
+
*
|
|
21844
|
+
* @private
|
|
21845
|
+
* @throws {Error} If `amount_label` is missing or not a string.
|
|
21846
|
+
* @throws {Error} If `store_name` is missing or not a string.
|
|
21847
|
+
*/
|
|
21848
|
+
function validateWalletMeta() {
|
|
20725
21849
|
if (typeof this.meta.amount_label !== 'string' || this.meta.amount_label.trim() === '') {
|
|
20726
21850
|
throw new Error("meta.amount_label is required for Apple Pay and must be a non-empty string (e.g. 'TOTAL').");
|
|
20727
21851
|
}
|
|
@@ -20755,6 +21879,114 @@
|
|
|
20755
21879
|
value: function createWalletService(serviceConfig) {
|
|
20756
21880
|
return new ApplePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
|
|
20757
21881
|
}
|
|
21882
|
+
}], [{
|
|
21883
|
+
key: "checkAvailability",
|
|
21884
|
+
value: function checkAvailability() {
|
|
21885
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
21886
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
21887
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
21888
|
+
var hasNativeSession, merchantId, authType, api, serviceConfig;
|
|
21889
|
+
return _regenerator().w(function (_context) {
|
|
21890
|
+
while (1) switch (_context.p = _context.n) {
|
|
21891
|
+
case 0:
|
|
21892
|
+
hasNativeSession = hasNativeApplePaySession();
|
|
21893
|
+
if (!options.sync) {
|
|
21894
|
+
_context.n = 1;
|
|
21895
|
+
break;
|
|
21896
|
+
}
|
|
21897
|
+
return _context.a(2, {
|
|
21898
|
+
available: hasNativeSession,
|
|
21899
|
+
supported: hasNativeSession,
|
|
21900
|
+
has_native_session: hasNativeSession,
|
|
21901
|
+
reason: hasNativeSession ? undefined : 'no_native_session'
|
|
21902
|
+
});
|
|
21903
|
+
case 1:
|
|
21904
|
+
merchantId = options.merchant_id;
|
|
21905
|
+
if (merchantId) {
|
|
21906
|
+
_context.n = 6;
|
|
21907
|
+
break;
|
|
21908
|
+
}
|
|
21909
|
+
if (!(!options.public_key_or_access_token || !options.service_id)) {
|
|
21910
|
+
_context.n = 2;
|
|
21911
|
+
break;
|
|
21912
|
+
}
|
|
21913
|
+
return _context.a(2, {
|
|
21914
|
+
available: false,
|
|
21915
|
+
supported: hasNativeSession,
|
|
21916
|
+
has_native_session: hasNativeSession,
|
|
21917
|
+
reason: 'missing_merchant_id'
|
|
21918
|
+
});
|
|
21919
|
+
case 2:
|
|
21920
|
+
_context.p = 2;
|
|
21921
|
+
authType = AccessToken.validateJWT(options.public_key_or_access_token) ? API_AUTH_TYPE.TOKEN : API_AUTH_TYPE.PUBLIC_KEY;
|
|
21922
|
+
api = new ApiInternal(options.public_key_or_access_token, authType);
|
|
21923
|
+
if (options.env) {
|
|
21924
|
+
api.setEnv(options.env);
|
|
21925
|
+
}
|
|
21926
|
+
_context.n = 3;
|
|
21927
|
+
return getServiceConfigCached(api, options.service_id);
|
|
21928
|
+
case 3:
|
|
21929
|
+
serviceConfig = _context.v;
|
|
21930
|
+
if (!(serviceConfig.type !== SERVICE_TYPES.APPLE_PAY)) {
|
|
21931
|
+
_context.n = 4;
|
|
21932
|
+
break;
|
|
21933
|
+
}
|
|
21934
|
+
return _context.a(2, {
|
|
21935
|
+
available: false,
|
|
21936
|
+
supported: hasNativeSession,
|
|
21937
|
+
has_native_session: hasNativeSession,
|
|
21938
|
+
reason: 'service_type_mismatch'
|
|
21939
|
+
});
|
|
21940
|
+
case 4:
|
|
21941
|
+
merchantId = serviceConfig.merchant;
|
|
21942
|
+
_context.n = 6;
|
|
21943
|
+
break;
|
|
21944
|
+
case 5:
|
|
21945
|
+
_context.p = 5;
|
|
21946
|
+
_context.v;
|
|
21947
|
+
return _context.a(2, {
|
|
21948
|
+
available: false,
|
|
21949
|
+
supported: hasNativeSession,
|
|
21950
|
+
has_native_session: hasNativeSession,
|
|
21951
|
+
reason: 'config_fetch_failed'
|
|
21952
|
+
});
|
|
21953
|
+
case 6:
|
|
21954
|
+
if (merchantId) {
|
|
21955
|
+
_context.n = 7;
|
|
21956
|
+
break;
|
|
21957
|
+
}
|
|
21958
|
+
return _context.a(2, {
|
|
21959
|
+
available: false,
|
|
21960
|
+
supported: hasNativeSession,
|
|
21961
|
+
has_native_session: hasNativeSession,
|
|
21962
|
+
reason: 'missing_merchant_id'
|
|
21963
|
+
});
|
|
21964
|
+
case 7:
|
|
21965
|
+
_context.p = 7;
|
|
21966
|
+
_context.n = 8;
|
|
21967
|
+
return loadApplePaySdk();
|
|
21968
|
+
case 8:
|
|
21969
|
+
_context.n = 10;
|
|
21970
|
+
break;
|
|
21971
|
+
case 9:
|
|
21972
|
+
_context.p = 9;
|
|
21973
|
+
_context.v;
|
|
21974
|
+
return _context.a(2, {
|
|
21975
|
+
available: false,
|
|
21976
|
+
supported: hasNativeSession,
|
|
21977
|
+
has_native_session: hasNativeSession,
|
|
21978
|
+
reason: 'sdk_load_failed'
|
|
21979
|
+
});
|
|
21980
|
+
case 10:
|
|
21981
|
+
return _context.a(2, evaluateApplePayAvailability({
|
|
21982
|
+
merchantId: merchantId,
|
|
21983
|
+
apple_pay_capabilities: options.apple_pay_capabilities
|
|
21984
|
+
}));
|
|
21985
|
+
}
|
|
21986
|
+
}, _callee, null, [[7, 9], [2, 5]]);
|
|
21987
|
+
})();
|
|
21988
|
+
});
|
|
21989
|
+
}
|
|
20758
21990
|
}]);
|
|
20759
21991
|
}(OpenWalletButtons);
|
|
20760
21992
|
|
|
@@ -20791,6 +22023,137 @@
|
|
|
20791
22023
|
SHIPPING_OPTION: EVENT$1.ON_SHIPPING_OPTIONS_CHANGE
|
|
20792
22024
|
});
|
|
20793
22025
|
|
|
22026
|
+
/**
|
|
22027
|
+
* Synchronous, network-free check for whether the Google Pay JS API is already present
|
|
22028
|
+
* in the page (`window.google.payments.api.PaymentsClient`). Safe to call in any
|
|
22029
|
+
* environment (never throws).
|
|
22030
|
+
*
|
|
22031
|
+
* Note: Google Pay has no synchronous device/card capability API — this only reports
|
|
22032
|
+
* whether the SDK script has loaded. The authoritative readiness signal comes from
|
|
22033
|
+
* {@link evaluateGooglePayAvailability} (which runs `isReadyToPay`).
|
|
22034
|
+
*/
|
|
22035
|
+
function isGooglePayApiPresent() {
|
|
22036
|
+
var _a, _b, _c;
|
|
22037
|
+
try {
|
|
22038
|
+
return typeof window !== 'undefined' && !!((_c = (_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.payments) === null || _b === void 0 ? void 0 : _b.api) === null || _c === void 0 ? void 0 : _c.PaymentsClient);
|
|
22039
|
+
} catch (_d) {
|
|
22040
|
+
return false;
|
|
22041
|
+
}
|
|
22042
|
+
}
|
|
22043
|
+
var scriptLoadPromise = null;
|
|
22044
|
+
/**
|
|
22045
|
+
* Idempotently loads the Google Pay JS SDK from the CDN.
|
|
22046
|
+
* Resolves immediately if the API is already present, de-duplicates concurrent loads,
|
|
22047
|
+
* and rejects if the script fails to load.
|
|
22048
|
+
*/
|
|
22049
|
+
function loadGooglePayScript() {
|
|
22050
|
+
if (isGooglePayApiPresent()) {
|
|
22051
|
+
return Promise.resolve();
|
|
22052
|
+
}
|
|
22053
|
+
if (scriptLoadPromise) {
|
|
22054
|
+
return scriptLoadPromise;
|
|
22055
|
+
}
|
|
22056
|
+
scriptLoadPromise = new Promise(function (resolve, reject) {
|
|
22057
|
+
var script = document.createElement('script');
|
|
22058
|
+
script.type = 'text/javascript';
|
|
22059
|
+
script.src = GOOGLE_PAY_SCRIPT_URL;
|
|
22060
|
+
script.async = true;
|
|
22061
|
+
script.onload = function () {
|
|
22062
|
+
if (!isGooglePayApiPresent()) {
|
|
22063
|
+
scriptLoadPromise = null;
|
|
22064
|
+
reject(new Error('Google Pay not available'));
|
|
22065
|
+
return;
|
|
22066
|
+
}
|
|
22067
|
+
resolve();
|
|
22068
|
+
};
|
|
22069
|
+
script.onerror = function () {
|
|
22070
|
+
// Allow a future retry after a transient failure.
|
|
22071
|
+
scriptLoadPromise = null;
|
|
22072
|
+
reject(new Error('Failed to load Google Pay script'));
|
|
22073
|
+
};
|
|
22074
|
+
document.head.appendChild(script);
|
|
22075
|
+
});
|
|
22076
|
+
return scriptLoadPromise;
|
|
22077
|
+
}
|
|
22078
|
+
/**
|
|
22079
|
+
* Builds the base `isReadyToPay` request using the default card configuration
|
|
22080
|
+
* (standard auth methods + card networks). Mirrors the instance service's request:
|
|
22081
|
+
* `existingPaymentMethodRequired` is `false` on Safari (where Google Pay surfaces a
|
|
22082
|
+
* different flow) and `true` elsewhere.
|
|
22083
|
+
*/
|
|
22084
|
+
function buildIsReadyToPayRequest() {
|
|
22085
|
+
var isSafariBrowser = Browser.getBrowserName() === 'Apple Safari';
|
|
22086
|
+
return _extends(_extends({}, GOOGLE_PAY_API_CONFIG), {
|
|
22087
|
+
allowedPaymentMethods: [{
|
|
22088
|
+
type: 'CARD',
|
|
22089
|
+
parameters: {
|
|
22090
|
+
allowedAuthMethods: GOOGLE_PAY_AUTH_METHODS,
|
|
22091
|
+
allowedCardNetworks: GOOGLE_PAY_CARD_NETWORKS
|
|
22092
|
+
}
|
|
22093
|
+
}],
|
|
22094
|
+
existingPaymentMethodRequired: !isSafariBrowser
|
|
22095
|
+
});
|
|
22096
|
+
}
|
|
22097
|
+
/**
|
|
22098
|
+
* Core Google Pay availability evaluation, shared by the instance flow
|
|
22099
|
+
* (`GooglePayOpenWalletService`) and the static `GooglePayOpenWalletButton.checkAvailability`.
|
|
22100
|
+
*
|
|
22101
|
+
* The static check passes no `request`, so it uses the **default** card configuration
|
|
22102
|
+
* (a button instance with a custom `card_config` may produce a different result). The
|
|
22103
|
+
* instance flow passes its own `paymentsClient` and `request` so the readiness check
|
|
22104
|
+
* honours the merchant's `card_config` and runs against the same client it pays with.
|
|
22105
|
+
*
|
|
22106
|
+
* Assumes the Google Pay SDK is already loaded (call {@link loadGooglePayScript} first).
|
|
22107
|
+
*/
|
|
22108
|
+
function evaluateGooglePayAvailability() {
|
|
22109
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
22110
|
+
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22111
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
22112
|
+
var _a, _b, paymentsClient, response, available;
|
|
22113
|
+
return _regenerator().w(function (_context) {
|
|
22114
|
+
while (1) switch (_context.p = _context.n) {
|
|
22115
|
+
case 0:
|
|
22116
|
+
if (isGooglePayApiPresent()) {
|
|
22117
|
+
_context.n = 1;
|
|
22118
|
+
break;
|
|
22119
|
+
}
|
|
22120
|
+
return _context.a(2, {
|
|
22121
|
+
available: false,
|
|
22122
|
+
supported: false,
|
|
22123
|
+
reason: 'unsupported_browser'
|
|
22124
|
+
});
|
|
22125
|
+
case 1:
|
|
22126
|
+
_context.p = 1;
|
|
22127
|
+
paymentsClient = (_a = params.paymentsClient) !== null && _a !== void 0 ? _a : new google.payments.api.PaymentsClient({
|
|
22128
|
+
merchantInfo: {
|
|
22129
|
+
merchantId: params.merchantId || ''
|
|
22130
|
+
}
|
|
22131
|
+
});
|
|
22132
|
+
_context.n = 2;
|
|
22133
|
+
return paymentsClient.isReadyToPay((_b = params.request) !== null && _b !== void 0 ? _b : buildIsReadyToPayRequest());
|
|
22134
|
+
case 2:
|
|
22135
|
+
response = _context.v;
|
|
22136
|
+
available = !!response.result;
|
|
22137
|
+
return _context.a(2, {
|
|
22138
|
+
available: available,
|
|
22139
|
+
supported: true,
|
|
22140
|
+
payment_method_present: response.paymentMethodPresent,
|
|
22141
|
+
reason: available ? undefined : 'no_payment_method'
|
|
22142
|
+
});
|
|
22143
|
+
case 3:
|
|
22144
|
+
_context.p = 3;
|
|
22145
|
+
_context.v;
|
|
22146
|
+
return _context.a(2, {
|
|
22147
|
+
available: false,
|
|
22148
|
+
supported: isGooglePayApiPresent(),
|
|
22149
|
+
reason: 'query_failed'
|
|
22150
|
+
});
|
|
22151
|
+
}
|
|
22152
|
+
}, _callee, null, [[1, 3]]);
|
|
22153
|
+
})();
|
|
22154
|
+
});
|
|
22155
|
+
}
|
|
22156
|
+
|
|
20794
22157
|
/**
|
|
20795
22158
|
* Parses intermediate payment data from Google Pay into a normalized format
|
|
20796
22159
|
* for use in shipping address/option change events.
|
|
@@ -21126,14 +22489,18 @@
|
|
|
21126
22489
|
key: "checkAvailability",
|
|
21127
22490
|
value: function checkAvailability() {
|
|
21128
22491
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
|
|
22492
|
+
var result;
|
|
21129
22493
|
return _regenerator().w(function (_context2) {
|
|
21130
22494
|
while (1) switch (_context2.n) {
|
|
21131
22495
|
case 0:
|
|
21132
|
-
|
|
21133
|
-
|
|
21134
|
-
|
|
21135
|
-
|
|
21136
|
-
})
|
|
22496
|
+
_context2.n = 1;
|
|
22497
|
+
return evaluateGooglePayAvailability({
|
|
22498
|
+
paymentsClient: this.paymentsClient,
|
|
22499
|
+
request: this.createRequest()
|
|
22500
|
+
});
|
|
22501
|
+
case 1:
|
|
22502
|
+
result = _context2.v;
|
|
22503
|
+
return _context2.a(2, result.available);
|
|
21137
22504
|
}
|
|
21138
22505
|
}, _callee2, this);
|
|
21139
22506
|
}));
|
|
@@ -21591,14 +22958,46 @@
|
|
|
21591
22958
|
return _this;
|
|
21592
22959
|
}
|
|
21593
22960
|
/**
|
|
21594
|
-
*
|
|
21595
|
-
*
|
|
21596
|
-
*
|
|
22961
|
+
* Checks Google Pay availability **without instantiating the button** — the static
|
|
22962
|
+
* availability entry point.
|
|
22963
|
+
*
|
|
22964
|
+
* Loads the Google Pay JS SDK if needed, then runs `PaymentsClient.isReadyToPay()` using
|
|
22965
|
+
* the **default** card configuration (a button instance with a custom `card_config` may
|
|
22966
|
+
* produce a different result). All options are optional — unlike Apple Pay, Google Pay's
|
|
22967
|
+
* readiness check does not require a merchant identifier; supplying `service_id` +
|
|
22968
|
+
* `public_key_or_access_token` additionally validates that the service is a Google Pay service.
|
|
22969
|
+
*
|
|
22970
|
+
* Pass `{ sync: true }` for a cheap, network-free check that only reports whether the
|
|
22971
|
+
* Google Pay JS API is already present (see {@link GooglePayAvailabilityOptions.sync}).
|
|
22972
|
+
*
|
|
22973
|
+
* @param {GooglePayAvailabilityOptions} [options] - Optional merchant context and mode.
|
|
22974
|
+
* @returns {Promise<GooglePayAvailabilityResult>} The availability result.
|
|
22975
|
+
*
|
|
22976
|
+
* @example
|
|
22977
|
+
* // Simplest form — no merchant context needed:
|
|
22978
|
+
* const result = await GooglePayOpenWalletButton.checkAvailability();
|
|
22979
|
+
* if (result.available) {
|
|
22980
|
+
* // Render the Google Pay button.
|
|
22981
|
+
* }
|
|
22982
|
+
*
|
|
22983
|
+
* @example
|
|
22984
|
+
* // Validate the service is a Google Pay service while checking:
|
|
22985
|
+
* const result = await GooglePayOpenWalletButton.checkAvailability({
|
|
22986
|
+
* public_key_or_access_token,
|
|
22987
|
+
* service_id,
|
|
22988
|
+
* env: 'sandbox',
|
|
22989
|
+
* });
|
|
21597
22990
|
*/
|
|
21598
22991
|
_inherits(GooglePayOpenWalletButton, _OpenWalletButtons);
|
|
21599
22992
|
return _createClass(GooglePayOpenWalletButton, [{
|
|
21600
22993
|
key: "validateWalletMeta",
|
|
21601
|
-
value:
|
|
22994
|
+
value:
|
|
22995
|
+
/**
|
|
22996
|
+
* Validates Google Pay-specific required metadata fields.
|
|
22997
|
+
* Google Pay has no additional required fields beyond the base (amount, currency, country).
|
|
22998
|
+
* @private
|
|
22999
|
+
*/
|
|
23000
|
+
function validateWalletMeta() {
|
|
21602
23001
|
// Google Pay has no additional required meta fields beyond the base.
|
|
21603
23002
|
// Optional fields (merchant_name, card_config, etc.) are validated
|
|
21604
23003
|
// at runtime by the Google Pay SDK.
|
|
@@ -21629,6 +23028,87 @@
|
|
|
21629
23028
|
value: function createWalletService(serviceConfig) {
|
|
21630
23029
|
return new GooglePayOpenWalletService(this.api, this.eventEmitter, this.serviceId, this.container, this.meta, serviceConfig);
|
|
21631
23030
|
}
|
|
23031
|
+
}], [{
|
|
23032
|
+
key: "checkAvailability",
|
|
23033
|
+
value: function checkAvailability() {
|
|
23034
|
+
return __awaiter(this, arguments, void 0, function () {
|
|
23035
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
23036
|
+
return /*#__PURE__*/_regenerator().m(function _callee() {
|
|
23037
|
+
var present, merchantId, authType, api, serviceConfig;
|
|
23038
|
+
return _regenerator().w(function (_context) {
|
|
23039
|
+
while (1) switch (_context.p = _context.n) {
|
|
23040
|
+
case 0:
|
|
23041
|
+
if (!options.sync) {
|
|
23042
|
+
_context.n = 1;
|
|
23043
|
+
break;
|
|
23044
|
+
}
|
|
23045
|
+
present = isGooglePayApiPresent();
|
|
23046
|
+
return _context.a(2, {
|
|
23047
|
+
available: present,
|
|
23048
|
+
supported: present,
|
|
23049
|
+
reason: present ? undefined : 'api_not_loaded'
|
|
23050
|
+
});
|
|
23051
|
+
case 1:
|
|
23052
|
+
merchantId = options.merchant_id;
|
|
23053
|
+
if (!(!merchantId && options.public_key_or_access_token && options.service_id)) {
|
|
23054
|
+
_context.n = 6;
|
|
23055
|
+
break;
|
|
23056
|
+
}
|
|
23057
|
+
_context.p = 2;
|
|
23058
|
+
authType = AccessToken.validateJWT(options.public_key_or_access_token) ? API_AUTH_TYPE.TOKEN : API_AUTH_TYPE.PUBLIC_KEY;
|
|
23059
|
+
api = new ApiInternal(options.public_key_or_access_token, authType);
|
|
23060
|
+
if (options.env) {
|
|
23061
|
+
api.setEnv(options.env);
|
|
23062
|
+
}
|
|
23063
|
+
_context.n = 3;
|
|
23064
|
+
return getServiceConfigCached(api, options.service_id);
|
|
23065
|
+
case 3:
|
|
23066
|
+
serviceConfig = _context.v;
|
|
23067
|
+
if (!(serviceConfig.type !== SERVICE_TYPES.GOOGLE_PAY)) {
|
|
23068
|
+
_context.n = 4;
|
|
23069
|
+
break;
|
|
23070
|
+
}
|
|
23071
|
+
return _context.a(2, {
|
|
23072
|
+
available: false,
|
|
23073
|
+
supported: isGooglePayApiPresent(),
|
|
23074
|
+
reason: 'service_type_mismatch'
|
|
23075
|
+
});
|
|
23076
|
+
case 4:
|
|
23077
|
+
merchantId = serviceConfig.merchant;
|
|
23078
|
+
_context.n = 6;
|
|
23079
|
+
break;
|
|
23080
|
+
case 5:
|
|
23081
|
+
_context.p = 5;
|
|
23082
|
+
_context.v;
|
|
23083
|
+
return _context.a(2, {
|
|
23084
|
+
available: false,
|
|
23085
|
+
supported: isGooglePayApiPresent(),
|
|
23086
|
+
reason: 'config_fetch_failed'
|
|
23087
|
+
});
|
|
23088
|
+
case 6:
|
|
23089
|
+
_context.p = 6;
|
|
23090
|
+
_context.n = 7;
|
|
23091
|
+
return loadGooglePayScript();
|
|
23092
|
+
case 7:
|
|
23093
|
+
_context.n = 9;
|
|
23094
|
+
break;
|
|
23095
|
+
case 8:
|
|
23096
|
+
_context.p = 8;
|
|
23097
|
+
_context.v;
|
|
23098
|
+
return _context.a(2, {
|
|
23099
|
+
available: false,
|
|
23100
|
+
supported: isGooglePayApiPresent(),
|
|
23101
|
+
reason: 'sdk_load_failed'
|
|
23102
|
+
});
|
|
23103
|
+
case 9:
|
|
23104
|
+
return _context.a(2, evaluateGooglePayAvailability({
|
|
23105
|
+
merchantId: merchantId
|
|
23106
|
+
}));
|
|
23107
|
+
}
|
|
23108
|
+
}, _callee, null, [[6, 8], [2, 5]]);
|
|
23109
|
+
})();
|
|
23110
|
+
});
|
|
23111
|
+
}
|
|
21632
23112
|
}]);
|
|
21633
23113
|
}(OpenWalletButtons);
|
|
21634
23114
|
|
|
@@ -22901,6 +24381,14 @@
|
|
|
22901
24381
|
if (_this.provider) {
|
|
22902
24382
|
_this.provider.load();
|
|
22903
24383
|
}
|
|
24384
|
+
})["catch"](function (error) {
|
|
24385
|
+
var _a;
|
|
24386
|
+
// Surface config-load failures (including transport-level ones now
|
|
24387
|
+
// rejected by ApiBase) instead of leaving the widget hung silently.
|
|
24388
|
+
_this.eventEmitter.emit(EVENT.CHECKOUT_ERROR, {
|
|
24389
|
+
type: EVENT_DATA_TYPE.CRITICAL_ERROR,
|
|
24390
|
+
data: (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : 'Failed to load Click to Pay configuration.'
|
|
24391
|
+
});
|
|
22904
24392
|
});
|
|
22905
24393
|
}
|
|
22906
24394
|
/**
|