@bigbinary/neeto-payments-frontend 1.4.17 → 1.4.19

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.
Files changed (154) hide show
  1. package/README.md +4 -0
  2. package/dist/AccountsDashboard.js +472 -0
  3. package/dist/AccountsDashboard.js.map +1 -0
  4. package/dist/Dashboard.js +597 -0
  5. package/dist/Dashboard.js.map +1 -0
  6. package/dist/ExportModal-a00544db.js +643 -0
  7. package/dist/ExportModal-a00544db.js.map +1 -0
  8. package/dist/IdentifierButton-73cadb18.js +20 -0
  9. package/dist/IdentifierButton-73cadb18.js.map +1 -0
  10. package/dist/PaymentKindRestrictionAlert.js +34 -0
  11. package/dist/PaymentKindRestrictionAlert.js.map +1 -0
  12. package/dist/PayoutsDashboard.js +502 -0
  13. package/dist/PayoutsDashboard.js.map +1 -0
  14. package/dist/PayoutsPage.js +184 -0
  15. package/dist/PayoutsPage.js.map +1 -0
  16. package/dist/RazorpayDashboard.js +246 -0
  17. package/dist/RazorpayDashboard.js.map +1 -0
  18. package/dist/RazorpayPaymentButton.js +108 -0
  19. package/dist/RazorpayPaymentButton.js.map +1 -0
  20. package/dist/SquareCard.js +65 -0
  21. package/dist/SquareCard.js.map +1 -0
  22. package/dist/SquareDashboard.js +294 -0
  23. package/dist/SquareDashboard.js.map +1 -0
  24. package/dist/StripeConnect.js +2067 -0
  25. package/dist/StripeConnect.js.map +1 -0
  26. package/dist/UpiConnect.js +148 -0
  27. package/dist/UpiConnect.js.map +1 -0
  28. package/dist/UpiMarkAsPaidButton.js +39 -0
  29. package/dist/UpiMarkAsPaidButton.js.map +1 -0
  30. package/dist/UpiPayment.js +91 -0
  31. package/dist/UpiPayment.js.map +1 -0
  32. package/dist/V2PaymentsDashboard.js +298 -0
  33. package/dist/V2PaymentsDashboard.js.map +1 -0
  34. package/dist/buildStripeTransactionLink.js +6 -0
  35. package/dist/buildStripeTransactionLink.js.map +1 -0
  36. package/dist/cjs/AccountsDashboard.js +489 -0
  37. package/dist/cjs/AccountsDashboard.js.map +1 -0
  38. package/dist/cjs/Dashboard.js +612 -0
  39. package/dist/cjs/Dashboard.js.map +1 -0
  40. package/dist/cjs/ExportModal-408e0ed8.js +667 -0
  41. package/dist/cjs/ExportModal-408e0ed8.js.map +1 -0
  42. package/dist/cjs/IdentifierButton-40b5459d.js +27 -0
  43. package/dist/cjs/IdentifierButton-40b5459d.js.map +1 -0
  44. package/dist/cjs/PaymentKindRestrictionAlert.js +41 -0
  45. package/dist/cjs/PaymentKindRestrictionAlert.js.map +1 -0
  46. package/dist/cjs/PayoutsDashboard.js +518 -0
  47. package/dist/cjs/PayoutsDashboard.js.map +1 -0
  48. package/dist/cjs/PayoutsPage.js +193 -0
  49. package/dist/cjs/PayoutsPage.js.map +1 -0
  50. package/dist/cjs/RazorpayDashboard.js +257 -0
  51. package/dist/cjs/RazorpayDashboard.js.map +1 -0
  52. package/dist/cjs/RazorpayPaymentButton.js +115 -0
  53. package/dist/cjs/RazorpayPaymentButton.js.map +1 -0
  54. package/dist/cjs/SquareCard.js +73 -0
  55. package/dist/cjs/SquareCard.js.map +1 -0
  56. package/dist/cjs/SquareDashboard.js +305 -0
  57. package/dist/cjs/SquareDashboard.js.map +1 -0
  58. package/dist/cjs/StripeConnect.js +2102 -0
  59. package/dist/cjs/StripeConnect.js.map +1 -0
  60. package/dist/cjs/UpiConnect.js +181 -0
  61. package/dist/cjs/UpiConnect.js.map +1 -0
  62. package/dist/cjs/UpiMarkAsPaidButton.js +46 -0
  63. package/dist/cjs/UpiMarkAsPaidButton.js.map +1 -0
  64. package/dist/cjs/UpiPayment.js +121 -0
  65. package/dist/cjs/UpiPayment.js.map +1 -0
  66. package/dist/cjs/V2PaymentsDashboard.js +309 -0
  67. package/dist/cjs/V2PaymentsDashboard.js.map +1 -0
  68. package/dist/cjs/buildStripeTransactionLink.js +11 -0
  69. package/dist/cjs/buildStripeTransactionLink.js.map +1 -0
  70. package/dist/cjs/constants.js +495 -0
  71. package/dist/cjs/constants.js.map +1 -0
  72. package/dist/cjs/exportChannel-e4cc2bb1.js +37 -0
  73. package/dist/cjs/exportChannel-e4cc2bb1.js.map +1 -0
  74. package/dist/cjs/extends-1b35a664.js +19 -0
  75. package/dist/cjs/extends-1b35a664.js.map +1 -0
  76. package/dist/cjs/index-042b6907.js.map +1 -0
  77. package/dist/cjs/index-b097dce8.js +41 -0
  78. package/dist/cjs/index-b097dce8.js.map +1 -0
  79. package/dist/cjs/index-b7badf96.js +88 -0
  80. package/dist/cjs/index-b7badf96.js.map +1 -0
  81. package/dist/cjs/index.js +106 -0
  82. package/dist/cjs/index.js.map +1 -0
  83. package/dist/cjs/queryConstants-a6a3c360.js +26 -0
  84. package/dist/cjs/queryConstants-a6a3c360.js.map +1 -0
  85. package/dist/cjs/renderFunctions-5e706b7a.js +168 -0
  86. package/dist/cjs/renderFunctions-5e706b7a.js.map +1 -0
  87. package/dist/cjs/stripe.esm-4218a1e9.js.map +1 -0
  88. package/dist/cjs/useConnectApi-b8770f71.js +2170 -0
  89. package/dist/cjs/useConnectApi-b8770f71.js.map +1 -0
  90. package/dist/cjs/useFiltersAndPagination-a5f10d80.js +410 -0
  91. package/dist/cjs/useFiltersAndPagination-a5f10d80.js.map +1 -0
  92. package/dist/cjs/usePaymentApi-a0b4ea86.js +41 -0
  93. package/dist/cjs/usePaymentApi-a0b4ea86.js.map +1 -0
  94. package/dist/cjs/usePaymentsApi-5eba9184.js +30 -0
  95. package/dist/cjs/usePaymentsApi-5eba9184.js.map +1 -0
  96. package/dist/cjs/usePlatformApi-c77f6fdd.js +89 -0
  97. package/dist/cjs/usePlatformApi-c77f6fdd.js.map +1 -0
  98. package/dist/cjs/useRazorpayPayment.js +87 -0
  99. package/dist/cjs/useRazorpayPayment.js.map +1 -0
  100. package/dist/cjs/useSquareCard.js +32 -0
  101. package/dist/cjs/useSquareCard.js.map +1 -0
  102. package/dist/cjs/useStripePromise.js +27 -0
  103. package/dist/cjs/useStripePromise.js.map +1 -0
  104. package/dist/constants.js +480 -0
  105. package/dist/constants.js.map +1 -0
  106. package/dist/exportChannel-e0822151.js +30 -0
  107. package/dist/exportChannel-e0822151.js.map +1 -0
  108. package/dist/extends-093996c9.js +17 -0
  109. package/dist/extends-093996c9.js.map +1 -0
  110. package/dist/index-1aedc364.js +80 -0
  111. package/dist/index-1aedc364.js.map +1 -0
  112. package/dist/index-48f8b281.js +32 -0
  113. package/dist/index-48f8b281.js.map +1 -0
  114. package/dist/index.js +80 -10090
  115. package/dist/index.js.map +1 -1
  116. package/dist/queryConstants-9b7fe0cf.js +24 -0
  117. package/dist/queryConstants-9b7fe0cf.js.map +1 -0
  118. package/dist/renderFunctions-5f829290.js +147 -0
  119. package/dist/renderFunctions-5f829290.js.map +1 -0
  120. package/dist/useConnectApi-185a67ad.js +2155 -0
  121. package/dist/useConnectApi-185a67ad.js.map +1 -0
  122. package/dist/useFiltersAndPagination-e5dc4b96.js +392 -0
  123. package/dist/useFiltersAndPagination-e5dc4b96.js.map +1 -0
  124. package/dist/usePaymentApi-8b68e636.js +34 -0
  125. package/dist/usePaymentApi-8b68e636.js.map +1 -0
  126. package/dist/usePaymentsApi-c1c0e6ab.js +23 -0
  127. package/dist/usePaymentsApi-c1c0e6ab.js.map +1 -0
  128. package/dist/usePlatformApi-5dba6b28.js +77 -0
  129. package/dist/usePlatformApi-5dba6b28.js.map +1 -0
  130. package/dist/useRazorpayPayment.js +85 -0
  131. package/dist/useRazorpayPayment.js.map +1 -0
  132. package/dist/useSquareCard.js +30 -0
  133. package/dist/useSquareCard.js.map +1 -0
  134. package/dist/useStripePromise.js +25 -0
  135. package/dist/useStripePromise.js.map +1 -0
  136. package/package.json +17 -8
  137. package/types/AccountsDashboard.d.ts +3 -0
  138. package/types/Dashboard.d.ts +15 -0
  139. package/types/PaymentKindRestrictionAlert.d.ts +11 -0
  140. package/types/PayoutsDashboard.d.ts +10 -0
  141. package/types/PayoutsPage.d.ts +11 -0
  142. package/types/SquareCard.d.ts +14 -0
  143. package/types/SquareDashboard.d.ts +13 -0
  144. package/types/StripeConnect.d.ts +13 -0
  145. package/types/buildStripeTransactionLink.d.ts +6 -0
  146. package/types/useSquareCard.d.ts +9 -0
  147. package/types/useStripePromise.d.ts +5 -0
  148. package/types.d.ts +11 -75
  149. package/dist/index-042b6907.js.map +0 -1
  150. package/dist/index.cjs.js +0 -10166
  151. package/dist/index.cjs.js.map +0 -1
  152. package/dist/stripe.esm-4218a1e9.js.map +0 -1
  153. /package/dist/{index-042b6907.js → cjs/index-042b6907.js} +0 -0
  154. /package/dist/{stripe.esm-4218a1e9.js → cjs/stripe.esm-4218a1e9.js} +0 -0
@@ -0,0 +1,2102 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var neetoCist = require('@bigbinary/neeto-cist');
5
+ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
6
+ var neetointegrations = require('neetointegrations');
7
+ var useConnectApi = require('./useConnectApi-b8770f71.js');
8
+ var Label = require('@bigbinary/neetoui/Label');
9
+ var Typography = require('@bigbinary/neetoui/Typography');
10
+ var reactI18next = require('react-i18next');
11
+ var PageLoader = require('@bigbinary/neeto-molecules/PageLoader');
12
+ var Select = require('@bigbinary/neetoui/formik/Select');
13
+ var Form = require('@bigbinary/neetoui/formik/Form');
14
+ var ActionBlock = require('@bigbinary/neetoui/formik/ActionBlock');
15
+ var reactRouterDom = require('react-router-dom');
16
+ var reactQuery = require('react-query');
17
+ var axios = require('axios');
18
+ var constants = require('./constants.js');
19
+ var queryConstants = require('./queryConstants-a6a3c360.js');
20
+ var i18next = require('i18next');
21
+ var yup = require('yup');
22
+ require('ramda');
23
+ var Alert = require('@bigbinary/neetoui/Alert');
24
+ var Button = require('@bigbinary/neetoui/Button');
25
+ var Radio = require('@bigbinary/neetoui/Radio');
26
+ var utils = require('@bigbinary/neeto-commons-frontend/utils');
27
+ require('util');
28
+ require('@bigbinary/neeto-commons-frontend/constants');
29
+
30
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
31
+
32
+ function _interopNamespace(e) {
33
+ if (e && e.__esModule) return e;
34
+ var n = Object.create(null);
35
+ if (e) {
36
+ Object.keys(e).forEach(function (k) {
37
+ if (k !== 'default') {
38
+ var d = Object.getOwnPropertyDescriptor(e, k);
39
+ Object.defineProperty(n, k, d.get ? d : {
40
+ enumerable: true,
41
+ get: function () { return e[k]; }
42
+ });
43
+ }
44
+ });
45
+ }
46
+ n["default"] = e;
47
+ return Object.freeze(n);
48
+ }
49
+
50
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
51
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
52
+ var Label__default = /*#__PURE__*/_interopDefaultLegacy(Label);
53
+ var Typography__default = /*#__PURE__*/_interopDefaultLegacy(Typography);
54
+ var PageLoader__default = /*#__PURE__*/_interopDefaultLegacy(PageLoader);
55
+ var Select__default = /*#__PURE__*/_interopDefaultLegacy(Select);
56
+ var Form__default = /*#__PURE__*/_interopDefaultLegacy(Form);
57
+ var ActionBlock__default = /*#__PURE__*/_interopDefaultLegacy(ActionBlock);
58
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
59
+ var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
60
+ var Alert__default = /*#__PURE__*/_interopDefaultLegacy(Alert);
61
+ var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);
62
+ var Radio__default = /*#__PURE__*/_interopDefaultLegacy(Radio);
63
+
64
+ var _path, _path2, _path3;
65
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
66
+ const SvgStripe = props => /*#__PURE__*/React__namespace.createElement("svg", _extends({
67
+ xmlns: "http://www.w3.org/2000/svg",
68
+ width: 54,
69
+ height: 54,
70
+ fill: "#6772e5",
71
+ viewBox: "0 0 32 32"
72
+ }, props), _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
73
+ fillRule: "evenodd",
74
+ d: "M111.328 15.602c0-4.97-2.415-8.9-7.013-8.9s-7.423 3.924-7.423 8.863c0 5.85 3.32 8.8 8.036 8.8 2.318 0 4.06-.528 5.377-1.26V19.22a10.246 10.246 0 0 1-4.764 1.075c-1.9 0-3.556-.67-3.774-2.943h9.497a39.64 39.64 0 0 0 .063-1.748zm-9.606-1.835c0-2.186 1.35-3.1 2.56-3.1s2.454.906 2.454 3.1zM89.4 6.712a5.434 5.434 0 0 0-3.801 1.509l-.254-1.208h-4.27v22.64l4.85-1.032v-5.488a5.434 5.434 0 0 0 3.444 1.265c3.472 0 6.64-2.792 6.64-8.957.003-5.66-3.206-8.73-6.614-8.73zM88.23 20.1a2.898 2.898 0 0 1-2.288-.906l-.03-7.2a2.928 2.928 0 0 1 2.315-.96c1.775 0 2.998 2 2.998 4.528.003 2.593-1.198 4.546-2.995 4.546zM79.25.57l-4.87 1.035v3.95l4.87-1.032z"
75
+ })), _path2 || (_path2 = /*#__PURE__*/React__namespace.createElement("path", {
76
+ d: "M74.38 7.035h4.87V24.04h-4.87z"
77
+ })), _path3 || (_path3 = /*#__PURE__*/React__namespace.createElement("path", {
78
+ fillRule: "evenodd",
79
+ d: "m69.164 8.47-.302-1.434h-4.196V24.04h4.848V12.5c1.147-1.5 3.082-1.208 3.698-1.017V7.038c-.646-.232-2.913-.658-4.048 1.43zm-9.73-5.646L54.698 3.83l-.02 15.562c0 2.87 2.158 4.993 5.038 4.993 1.585 0 2.756-.302 3.405-.643v-3.95c-.622.248-3.683 1.138-3.683-1.72v-6.9h3.683V7.035h-3.683zM46.3 11.97c0-.758.63-1.05 1.648-1.05a10.868 10.868 0 0 1 4.83 1.25V7.6a12.815 12.815 0 0 0-4.83-.888c-3.924 0-6.557 2.056-6.557 5.488 0 5.37 7.375 4.498 7.375 6.813 0 .906-.78 1.186-1.863 1.186-1.606 0-3.68-.664-5.307-1.55v4.63a13.461 13.461 0 0 0 5.307 1.117c4.033 0 6.813-1.992 6.813-5.485 0-5.796-7.417-4.76-7.417-6.943zM13.88 9.515c0-1.37 1.14-1.9 2.982-1.9A19.661 19.661 0 0 1 25.6 9.876v-8.27A23.184 23.184 0 0 0 16.862.001C9.762.001 5 3.72 5 9.93c0 9.716 13.342 8.138 13.342 12.326 0 1.638-1.4 2.146-3.37 2.146-2.905 0-6.657-1.202-9.6-2.802v8.378A24.353 24.353 0 0 0 14.973 32C22.27 32 27.3 28.395 27.3 22.077c0-10.486-13.42-8.613-13.42-12.56z"
80
+ })));
81
+
82
+ const fetchCountries = () => axios__default["default"].get(`${constants.BASE_URL}/api/v1/stripe/countries`);
83
+ const countriesApi = {
84
+ fetchCountries
85
+ };
86
+
87
+ const useFetchStripeCountries = () => reactQuery.useQuery(queryConstants.QUERY_KEYS.STRIPE_COUNTRIES, () => countriesApi.fetchCountries());
88
+
89
+ const POLLING_INTERVAL = 5000;
90
+ const MAX_POLLING_TIME = 30000;
91
+ const INITIAL_VALUES = {
92
+ country: "",
93
+ return_url: ""
94
+ };
95
+ const VALIDATION_SCHEMA = yup__namespace.object().shape({
96
+ country: yup__namespace.object().required(i18next.t("neetoPayments.validations.countryRequired")),
97
+ returnUrl: yup__namespace.string().url(i18next.t("neetoPayments.validations.invalidUrl"))
98
+ });
99
+
100
+ const STEPS = {
101
+ connect: "connect",
102
+ configure: "configure",
103
+ finish: "finish",
104
+ demo: "demo"
105
+ };
106
+ const INTEGRATION_STEPS = [{
107
+ step: "1",
108
+ label: i18next.t("neetoPayments.common.connect"),
109
+ isActive: false,
110
+ isCompleted: false
111
+ }, {
112
+ step: "2",
113
+ label: i18next.t("neetoPayments.common.configure"),
114
+ isActive: false,
115
+ isCompleted: false
116
+ }, {
117
+ step: "3",
118
+ label: i18next.t("neetoPayments.common.finish"),
119
+ isActive: false,
120
+ isCompleted: true
121
+ }
122
+ // { step: "4", label: "demo", isActive: false, isCompleted: false },
123
+ ];
124
+
125
+ const INTEGRATION_METHOD = {
126
+ useExistingAccount: "use_existing_account",
127
+ createNewAccount: "create_new_account"
128
+ };
129
+ const STRIPE_CONNECT_URL = `/${constants.BASE_URL}/api/v1/integrations/connect/stripe`;
130
+
131
+ const buildRefreshUrl = (accountId, returnUrl) => `/payments/api/v1/stripe/callbacks/${accountId}/refresh?return_url=${returnUrl}`;
132
+ const buildCountryOptions = countries => Object.entries(countries)?.map(country => ({
133
+ label: neetoCist.humanize(country[0]),
134
+ value: country[1]
135
+ }));
136
+
137
+ const AccountForm = _ref => {
138
+ let {
139
+ holdableId,
140
+ returnUrl
141
+ } = _ref;
142
+ const {
143
+ t
144
+ } = reactI18next.useTranslation();
145
+ const history = reactRouterDom.useHistory();
146
+ const [isPolling, setIsPolling] = React.useState(false);
147
+ const submitButtonLabel = isPolling ? t("neetoPayments.integrationModal.creating") : t("neetoPayments.common.connect");
148
+ const refetchInterval = function () {
149
+ let {
150
+ jobStatus,
151
+ onboarding
152
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
153
+ if (jobStatus === "complete") {
154
+ window.open(onboarding?.url, "_self");
155
+ return false;
156
+ }
157
+ return POLLING_INTERVAL;
158
+ };
159
+ const {
160
+ isLoading: isCreating,
161
+ data: {
162
+ jobId
163
+ } = {},
164
+ mutate: createStripeAccount
165
+ } = useConnectApi.useCreateStripeAccount({
166
+ onSuccess: () => setIsPolling(true)
167
+ });
168
+ useConnectApi.usePollingStripeAccountCreationStatus(jobId, {
169
+ refetchInterval,
170
+ enabled: neetoCist.isPresent(jobId)
171
+ });
172
+ const {
173
+ isLoading,
174
+ data: {
175
+ countries = {}
176
+ } = {}
177
+ } = useFetchStripeCountries();
178
+ const handleSubmit = _ref2 => {
179
+ let {
180
+ country
181
+ } = _ref2;
182
+ const payload = {
183
+ returnUrl,
184
+ country: country.value,
185
+ holdableId
186
+ };
187
+ createStripeAccount(payload);
188
+ };
189
+ if (isLoading) {
190
+ return /*#__PURE__*/React__default["default"].createElement(PageLoader__default["default"], null);
191
+ }
192
+ return /*#__PURE__*/React__default["default"].createElement(Form__default["default"], {
193
+ formikProps: {
194
+ enableReinitialize: true,
195
+ initialValues: INITIAL_VALUES,
196
+ validationSchema: VALIDATION_SCHEMA,
197
+ onSubmit: handleSubmit
198
+ }
199
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
200
+ className: "space-y-3"
201
+ }, /*#__PURE__*/React__default["default"].createElement(Select__default["default"], {
202
+ required: true,
203
+ helpText: t("neetoPayments.integrationModal.form.helpText"),
204
+ label: t("neetoPayments.integrationModal.form.label"),
205
+ name: "country",
206
+ options: buildCountryOptions(countries),
207
+ placeholder: t("neetoPayments.integrationModal.form.placeholder")
208
+ }), /*#__PURE__*/React__default["default"].createElement(ActionBlock__default["default"], {
209
+ cancelButtonProps: {
210
+ onClick: () => history.goBack()
211
+ },
212
+ isSubmitting: isCreating || isPolling,
213
+ submitButtonProps: {
214
+ label: submitButtonLabel
215
+ }
216
+ })));
217
+ };
218
+
219
+ const AccountDetails = _ref => {
220
+ let {
221
+ holdableId
222
+ } = _ref;
223
+ const {
224
+ data: {
225
+ account: stripeAccount
226
+ } = {}
227
+ } = useConnectApi.useFetchConnectedStripeAccount(holdableId);
228
+ const {
229
+ t
230
+ } = reactI18next.useTranslation();
231
+ return /*#__PURE__*/React__default["default"].createElement("div", {
232
+ className: "mb-6 space-y-3"
233
+ }, /*#__PURE__*/React__default["default"].createElement(Typography__default["default"], {
234
+ style: "h5",
235
+ weight: "medium"
236
+ }, t("neetoPayments.integrationModal.account.title")), /*#__PURE__*/React__default["default"].createElement("div", {
237
+ className: "grid grid-cols-4 gap-y-3"
238
+ }, /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
239
+ className: "neeto-ui-text-gray-800"
240
+ }, t("neetoPayments.common.id")), /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
241
+ className: "neeto-ui-text-gray-800 col-span-3"
242
+ }, stripeAccount?.identifier), /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
243
+ className: "neeto-ui-text-gray-800"
244
+ }, t("neetoPayments.common.email")), /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
245
+ className: "neeto-ui-text-gray-800 col-span-3"
246
+ }, stripeAccount?.email), /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
247
+ className: "neeto-ui-text-gray-800"
248
+ }, t("neetoPayments.common.country")), /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
249
+ className: "neeto-ui-text-gray-800 col-span-3"
250
+ }, stripeAccount?.country)));
251
+ };
252
+
253
+ const AccountProcessing = _ref => {
254
+ let {
255
+ holdableId,
256
+ returnUrl
257
+ } = _ref;
258
+ const {
259
+ app
260
+ } = reactUtils.useQueryParams();
261
+ const [isAlertOpen, setIsAlertOpen] = React.useState(false);
262
+ const [isPolling, setIsPolling] = React.useState(false);
263
+ const {
264
+ t
265
+ } = reactI18next.useTranslation();
266
+ const isStripeCallback = app === "stripe";
267
+ React.useEffect(() => {
268
+ if (!isStripeCallback) return;
269
+ setIsPolling(true);
270
+ setInterval(() => {
271
+ setIsPolling(false);
272
+ }, MAX_POLLING_TIME);
273
+ }, [isStripeCallback]);
274
+ const {
275
+ data: {
276
+ account: stripeAccount
277
+ } = {}
278
+ } = useConnectApi.useFetchConnectedStripeAccount(holdableId);
279
+ const {
280
+ isLoading: isStripeAccountDestroying,
281
+ mutate: destroyStripeAccount
282
+ } = useConnectApi.useDestroyStripeAccount({
283
+ onSuccess: () => setIsAlertOpen(false),
284
+ holdableId
285
+ });
286
+ const refetchInterval = function () {
287
+ let {
288
+ account
289
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
290
+ if (isStripeCallback && !account?.isConnected && isPolling) {
291
+ return POLLING_INTERVAL;
292
+ }
293
+ if (account?.isConnected) {
294
+ setIsPolling(false);
295
+ }
296
+ return false;
297
+ };
298
+ useConnectApi.usePollingStripeAccount(holdableId, {
299
+ refetchInterval
300
+ });
301
+ const isAccountProcessingFailed = isStripeCallback && !isPolling && !stripeAccount?.isConnected;
302
+ const buttonLabel = () => {
303
+ if (isPolling) {
304
+ return t("neetoPayments.integrationModal.creating");
305
+ }
306
+ if (isAccountProcessingFailed) {
307
+ return t("neetoPayments.integrationModal.failedButton");
308
+ }
309
+ return t("neetoPayments.common.continue");
310
+ };
311
+ const handleUseAnotherStripeAccount = () => {
312
+ destroyStripeAccount(stripeAccount?.id);
313
+ };
314
+ return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(AccountDetails, null), /*#__PURE__*/React__default["default"].createElement("div", {
315
+ className: "flex flex-col items-start space-y-2"
316
+ }, /*#__PURE__*/React__default["default"].createElement(Button__default["default"], {
317
+ disabled: isPolling,
318
+ href: buildRefreshUrl(stripeAccount?.id, returnUrl),
319
+ label: buttonLabel(),
320
+ loading: isPolling,
321
+ size: "small"
322
+ }), !isPolling && !isAccountProcessingFailed && /*#__PURE__*/React__default["default"].createElement(Button__default["default"], {
323
+ disabled: isStripeAccountDestroying || isPolling,
324
+ label: t("neetoPayments.integrationModal.anotherAccount"),
325
+ size: "small",
326
+ style: "link",
327
+ onClick: () => setIsAlertOpen(true)
328
+ })), /*#__PURE__*/React__default["default"].createElement(Alert__default["default"], {
329
+ isOpen: isAlertOpen,
330
+ title: t("neetoPayments.integrationModal.alert.changeTitle"),
331
+ message: /*#__PURE__*/React__default["default"].createElement(reactI18next.Trans, {
332
+ i18nKey: "neetoPayments.integrationModal.alert.changeMessage",
333
+ values: {
334
+ account: stripeAccount?.email
335
+ }
336
+ }),
337
+ onClose: () => setIsAlertOpen(false),
338
+ onSubmit: handleUseAnotherStripeAccount
339
+ }));
340
+ };
341
+
342
+ const Configure = _ref => {
343
+ let {
344
+ holdableId,
345
+ returnUrl
346
+ } = _ref;
347
+ const {
348
+ t
349
+ } = reactI18next.useTranslation();
350
+ const {
351
+ data: {
352
+ account: stripeAccount
353
+ } = {}
354
+ } = useConnectApi.useFetchConnectedStripeAccount(holdableId);
355
+ const handleStripeAccountCreated = _ref2 => {
356
+ let {
357
+ onboarding
358
+ } = _ref2;
359
+ window.open(onboarding?.url, "_self");
360
+ };
361
+ const connectDescription = neetoCist.isPresent(stripeAccount) ? t("neetoPayments.integrationModal.linkedDescription") : t("neetoPayments.integrationModal.subtitle");
362
+ return /*#__PURE__*/React__default["default"].createElement("div", {
363
+ className: "mx-auto w-full max-w-lg space-y-8"
364
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
365
+ className: "space-y-2"
366
+ }, /*#__PURE__*/React__default["default"].createElement(SvgStripe, null), /*#__PURE__*/React__default["default"].createElement(Typography__default["default"], {
367
+ "data-cy": "configure-payment-title",
368
+ style: "h2",
369
+ weight: "semibold"
370
+ }, t("neetoPayments.integrationModal.title")), /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
371
+ className: "leading-snug"
372
+ }, connectDescription)), neetoCist.isPresent(stripeAccount) ? /*#__PURE__*/React__default["default"].createElement(AccountProcessing, {
373
+ onAccountCreated: handleStripeAccountCreated,
374
+ holdableId,
375
+ returnUrl
376
+ }) : /*#__PURE__*/React__default["default"].createElement(AccountForm, {
377
+ holdableId,
378
+ returnUrl,
379
+ onAccountCreated: handleStripeAccountCreated
380
+ }));
381
+ };
382
+
383
+ /*! @license DOMPurify 3.0.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.2/LICENSE */
384
+
385
+ const {
386
+ entries,
387
+ setPrototypeOf,
388
+ isFrozen,
389
+ getPrototypeOf,
390
+ getOwnPropertyDescriptor
391
+ } = Object;
392
+ let {
393
+ freeze,
394
+ seal,
395
+ create
396
+ } = Object; // eslint-disable-line import/no-mutable-exports
397
+
398
+ let {
399
+ apply,
400
+ construct
401
+ } = typeof Reflect !== 'undefined' && Reflect;
402
+
403
+ if (!apply) {
404
+ apply = function apply(fun, thisValue, args) {
405
+ return fun.apply(thisValue, args);
406
+ };
407
+ }
408
+
409
+ if (!freeze) {
410
+ freeze = function freeze(x) {
411
+ return x;
412
+ };
413
+ }
414
+
415
+ if (!seal) {
416
+ seal = function seal(x) {
417
+ return x;
418
+ };
419
+ }
420
+
421
+ if (!construct) {
422
+ construct = function construct(Func, args) {
423
+ return new Func(...args);
424
+ };
425
+ }
426
+
427
+ const arrayForEach = unapply(Array.prototype.forEach);
428
+ const arrayPop = unapply(Array.prototype.pop);
429
+ const arrayPush = unapply(Array.prototype.push);
430
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
431
+ const stringToString = unapply(String.prototype.toString);
432
+ const stringMatch = unapply(String.prototype.match);
433
+ const stringReplace = unapply(String.prototype.replace);
434
+ const stringIndexOf = unapply(String.prototype.indexOf);
435
+ const stringTrim = unapply(String.prototype.trim);
436
+ const regExpTest = unapply(RegExp.prototype.test);
437
+ const typeErrorCreate = unconstruct(TypeError);
438
+ function unapply(func) {
439
+ return function (thisArg) {
440
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
441
+ args[_key - 1] = arguments[_key];
442
+ }
443
+
444
+ return apply(func, thisArg, args);
445
+ };
446
+ }
447
+ function unconstruct(func) {
448
+ return function () {
449
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
450
+ args[_key2] = arguments[_key2];
451
+ }
452
+
453
+ return construct(func, args);
454
+ };
455
+ }
456
+ /* Add properties to a lookup table */
457
+
458
+ function addToSet(set, array, transformCaseFunc) {
459
+ transformCaseFunc = transformCaseFunc ? transformCaseFunc : stringToLowerCase;
460
+
461
+ if (setPrototypeOf) {
462
+ // Make 'in' and truthy checks like Boolean(set.constructor)
463
+ // independent of any properties defined on Object.prototype.
464
+ // Prevent prototype setters from intercepting set as a this value.
465
+ setPrototypeOf(set, null);
466
+ }
467
+
468
+ let l = array.length;
469
+
470
+ while (l--) {
471
+ let element = array[l];
472
+
473
+ if (typeof element === 'string') {
474
+ const lcElement = transformCaseFunc(element);
475
+
476
+ if (lcElement !== element) {
477
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
478
+ if (!isFrozen(array)) {
479
+ array[l] = lcElement;
480
+ }
481
+
482
+ element = lcElement;
483
+ }
484
+ }
485
+
486
+ set[element] = true;
487
+ }
488
+
489
+ return set;
490
+ }
491
+ /* Shallow clone an object */
492
+
493
+ function clone(object) {
494
+ const newObject = create(null);
495
+
496
+ for (const [property, value] of entries(object)) {
497
+ newObject[property] = value;
498
+ }
499
+
500
+ return newObject;
501
+ }
502
+ /* This method automatically checks if the prop is function
503
+ * or getter and behaves accordingly. */
504
+
505
+ function lookupGetter(object, prop) {
506
+ while (object !== null) {
507
+ const desc = getOwnPropertyDescriptor(object, prop);
508
+
509
+ if (desc) {
510
+ if (desc.get) {
511
+ return unapply(desc.get);
512
+ }
513
+
514
+ if (typeof desc.value === 'function') {
515
+ return unapply(desc.value);
516
+ }
517
+ }
518
+
519
+ object = getPrototypeOf(object);
520
+ }
521
+
522
+ function fallbackValue(element) {
523
+ console.warn('fallback value for', element);
524
+ return null;
525
+ }
526
+
527
+ return fallbackValue;
528
+ }
529
+
530
+ 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', 'section', 'select', 'shadow', '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']); // SVG
531
+
532
+ const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
533
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']); // List of SVG elements that are disallowed by default.
534
+ // We still need to know them so that we can do namespace
535
+ // checks properly in case one wants to add them to
536
+ // allow-list.
537
+
538
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'fedropshadow', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
539
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']); // Similarly to SVG, we want to know all MathML elements,
540
+ // even those that we disallow by default.
541
+
542
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
543
+ const text = freeze(['#text']);
544
+
545
+ 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', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', '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', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns', 'slot']);
546
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', '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', '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', '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', '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', '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', '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']);
547
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', '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']);
548
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
549
+
550
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
551
+
552
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
553
+ const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
554
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
555
+
556
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
557
+
558
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
559
+ );
560
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
561
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
562
+ );
563
+ const DOCTYPE_NAME = seal(/^html$/i);
564
+
565
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
566
+ __proto__: null,
567
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
568
+ ERB_EXPR: ERB_EXPR,
569
+ TMPLIT_EXPR: TMPLIT_EXPR,
570
+ DATA_ATTR: DATA_ATTR,
571
+ ARIA_ATTR: ARIA_ATTR,
572
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
573
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
574
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
575
+ DOCTYPE_NAME: DOCTYPE_NAME
576
+ });
577
+
578
+ const getGlobal = () => typeof window === 'undefined' ? null : window;
579
+ /**
580
+ * Creates a no-op policy for internal use only.
581
+ * Don't export this function outside this module!
582
+ * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
583
+ * @param {Document} document The document object (to determine policy name suffix)
584
+ * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
585
+ * are not supported).
586
+ */
587
+
588
+
589
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
590
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
591
+ return null;
592
+ } // Allow the callers to control the unique policy name
593
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
594
+ // Policy creation with duplicate names throws in Trusted Types.
595
+
596
+
597
+ let suffix = null;
598
+ const ATTR_NAME = 'data-tt-policy-suffix';
599
+
600
+ if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
601
+ suffix = document.currentScript.getAttribute(ATTR_NAME);
602
+ }
603
+
604
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
605
+
606
+ try {
607
+ return trustedTypes.createPolicy(policyName, {
608
+ createHTML(html) {
609
+ return html;
610
+ },
611
+
612
+ createScriptURL(scriptUrl) {
613
+ return scriptUrl;
614
+ }
615
+
616
+ });
617
+ } catch (_) {
618
+ // Policy creation failed (most likely another DOMPurify script has
619
+ // already run). Skip creating the policy, as this will only cause errors
620
+ // if TT are enforced.
621
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
622
+ return null;
623
+ }
624
+ };
625
+
626
+ function createDOMPurify() {
627
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
628
+
629
+ const DOMPurify = root => createDOMPurify(root);
630
+ /**
631
+ * Version label, exposed for easier checks
632
+ * if DOMPurify is up to date or not
633
+ */
634
+
635
+
636
+ DOMPurify.version = '3.0.2';
637
+ /**
638
+ * Array of elements that DOMPurify removed during sanitation.
639
+ * Empty if nothing was removed.
640
+ */
641
+
642
+ DOMPurify.removed = [];
643
+
644
+ if (!window || !window.document || window.document.nodeType !== 9) {
645
+ // Not running in a browser, provide a factory function
646
+ // so that you can pass your own Window
647
+ DOMPurify.isSupported = false;
648
+ return DOMPurify;
649
+ }
650
+
651
+ const originalDocument = window.document;
652
+ let {
653
+ document
654
+ } = window;
655
+ const {
656
+ DocumentFragment,
657
+ HTMLTemplateElement,
658
+ Node,
659
+ Element,
660
+ NodeFilter,
661
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
662
+ HTMLFormElement,
663
+ DOMParser,
664
+ trustedTypes
665
+ } = window;
666
+ const ElementPrototype = Element.prototype;
667
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
668
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
669
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
670
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); // As per issue #47, the web-components registry is inherited by a
671
+ // new document created via createHTMLDocument. As per the spec
672
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
673
+ // a new empty registry is used when creating a template contents owner
674
+ // document, so we use that as our parent document to ensure nothing
675
+ // is inherited.
676
+
677
+ if (typeof HTMLTemplateElement === 'function') {
678
+ const template = document.createElement('template');
679
+
680
+ if (template.content && template.content.ownerDocument) {
681
+ document = template.content.ownerDocument;
682
+ }
683
+ }
684
+
685
+ const trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
686
+
687
+ const emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML('') : '';
688
+ const {
689
+ implementation,
690
+ createNodeIterator,
691
+ createDocumentFragment,
692
+ getElementsByTagName
693
+ } = document;
694
+ const {
695
+ importNode
696
+ } = originalDocument;
697
+ let hooks = {};
698
+ /**
699
+ * Expose whether this browser supports running the full DOMPurify.
700
+ */
701
+
702
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined';
703
+ const {
704
+ MUSTACHE_EXPR,
705
+ ERB_EXPR,
706
+ TMPLIT_EXPR,
707
+ DATA_ATTR,
708
+ ARIA_ATTR,
709
+ IS_SCRIPT_OR_DATA,
710
+ ATTR_WHITESPACE
711
+ } = EXPRESSIONS;
712
+ let {
713
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
714
+ } = EXPRESSIONS;
715
+ /**
716
+ * We consider the elements and attributes below to be safe. Ideally
717
+ * don't add any new ones but feel free to remove unwanted ones.
718
+ */
719
+
720
+ /* allowed element names */
721
+
722
+ let ALLOWED_TAGS = null;
723
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
724
+ /* Allowed attribute names */
725
+
726
+ let ALLOWED_ATTR = null;
727
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
728
+ /*
729
+ * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
730
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
731
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
732
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
733
+ */
734
+
735
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
736
+ tagNameCheck: {
737
+ writable: true,
738
+ configurable: false,
739
+ enumerable: true,
740
+ value: null
741
+ },
742
+ attributeNameCheck: {
743
+ writable: true,
744
+ configurable: false,
745
+ enumerable: true,
746
+ value: null
747
+ },
748
+ allowCustomizedBuiltInElements: {
749
+ writable: true,
750
+ configurable: false,
751
+ enumerable: true,
752
+ value: false
753
+ }
754
+ }));
755
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
756
+
757
+ let FORBID_TAGS = null;
758
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
759
+
760
+ let FORBID_ATTR = null;
761
+ /* Decide if ARIA attributes are okay */
762
+
763
+ let ALLOW_ARIA_ATTR = true;
764
+ /* Decide if custom data attributes are okay */
765
+
766
+ let ALLOW_DATA_ATTR = true;
767
+ /* Decide if unknown protocols are okay */
768
+
769
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
770
+ /* Decide if self-closing tags in attributes are allowed.
771
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
772
+
773
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
774
+ /* Output should be safe for common template engines.
775
+ * This means, DOMPurify removes data attributes, mustaches and ERB
776
+ */
777
+
778
+ let SAFE_FOR_TEMPLATES = false;
779
+ /* Decide if document with <html>... should be returned */
780
+
781
+ let WHOLE_DOCUMENT = false;
782
+ /* Track whether config is already set on this instance of DOMPurify. */
783
+
784
+ let SET_CONFIG = false;
785
+ /* Decide if all elements (e.g. style, script) must be children of
786
+ * document.body. By default, browsers might move them to document.head */
787
+
788
+ let FORCE_BODY = false;
789
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
790
+ * string (or a TrustedHTML object if Trusted Types are supported).
791
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
792
+ */
793
+
794
+ let RETURN_DOM = false;
795
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
796
+ * string (or a TrustedHTML object if Trusted Types are supported) */
797
+
798
+ let RETURN_DOM_FRAGMENT = false;
799
+ /* Try to return a Trusted Type object instead of a string, return a string in
800
+ * case Trusted Types are not supported */
801
+
802
+ let RETURN_TRUSTED_TYPE = false;
803
+ /* Output should be free from DOM clobbering attacks?
804
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
805
+ */
806
+
807
+ let SANITIZE_DOM = true;
808
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
809
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
810
+ *
811
+ * HTML/DOM spec rules that enable DOM Clobbering:
812
+ * - Named Access on Window (§7.3.3)
813
+ * - DOM Tree Accessors (§3.1.5)
814
+ * - Form Element Parent-Child Relations (§4.10.3)
815
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
816
+ * - HTMLCollection (§4.2.10.2)
817
+ *
818
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
819
+ * with a constant string, i.e., `user-content-`
820
+ */
821
+
822
+ let SANITIZE_NAMED_PROPS = false;
823
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
824
+ /* Keep element content when removing element? */
825
+
826
+ let KEEP_CONTENT = true;
827
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
828
+ * of importing it into a new Document and returning a sanitized copy */
829
+
830
+ let IN_PLACE = false;
831
+ /* Allow usage of profiles like html, svg and mathMl */
832
+
833
+ let USE_PROFILES = {};
834
+ /* Tags to ignore content of when KEEP_CONTENT is true */
835
+
836
+ let FORBID_CONTENTS = null;
837
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
838
+ /* Tags that are safe for data: URIs */
839
+
840
+ let DATA_URI_TAGS = null;
841
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
842
+ /* Attributes safe for values like "javascript:" */
843
+
844
+ let URI_SAFE_ATTRIBUTES = null;
845
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
846
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
847
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
848
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
849
+ /* Document namespace */
850
+
851
+ let NAMESPACE = HTML_NAMESPACE;
852
+ let IS_EMPTY_INPUT = false;
853
+ /* Allowed XHTML+XML namespaces */
854
+
855
+ let ALLOWED_NAMESPACES = null;
856
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
857
+ /* Parsing of strict XHTML documents */
858
+
859
+ let PARSER_MEDIA_TYPE;
860
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
861
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
862
+ let transformCaseFunc;
863
+ /* Keep a reference to config to pass to hooks */
864
+
865
+ let CONFIG = null;
866
+ /* Ideally, do not touch anything below this line */
867
+
868
+ /* ______________________________________________ */
869
+
870
+ const formElement = document.createElement('form');
871
+
872
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
873
+ return testValue instanceof RegExp || testValue instanceof Function;
874
+ };
875
+ /**
876
+ * _parseConfig
877
+ *
878
+ * @param {Object} cfg optional config literal
879
+ */
880
+ // eslint-disable-next-line complexity
881
+
882
+
883
+ const _parseConfig = function _parseConfig(cfg) {
884
+ if (CONFIG && CONFIG === cfg) {
885
+ return;
886
+ }
887
+ /* Shield configuration object from tampering */
888
+
889
+
890
+ if (!cfg || typeof cfg !== 'object') {
891
+ cfg = {};
892
+ }
893
+ /* Shield configuration object from prototype pollution */
894
+
895
+
896
+ cfg = clone(cfg);
897
+ PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
898
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE; // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
899
+
900
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
901
+ /* Set configuration parameters */
902
+
903
+ ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
904
+ ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
905
+ ALLOWED_NAMESPACES = 'ALLOWED_NAMESPACES' in cfg ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
906
+ URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
907
+ cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
908
+ transformCaseFunc // eslint-disable-line indent
909
+ ) // eslint-disable-line indent
910
+ : DEFAULT_URI_SAFE_ATTRIBUTES;
911
+ DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent
912
+ cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent
913
+ transformCaseFunc // eslint-disable-line indent
914
+ ) // eslint-disable-line indent
915
+ : DEFAULT_DATA_URI_TAGS;
916
+ FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
917
+ FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
918
+ FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
919
+ USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
920
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
921
+
922
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
923
+
924
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
925
+
926
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
927
+
928
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
929
+
930
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
931
+
932
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
933
+
934
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
935
+
936
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
937
+
938
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
939
+
940
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
941
+
942
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
943
+
944
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
945
+
946
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
947
+
948
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
949
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
950
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
951
+
952
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
953
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
954
+ }
955
+
956
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
957
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
958
+ }
959
+
960
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
961
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
962
+ }
963
+
964
+ if (SAFE_FOR_TEMPLATES) {
965
+ ALLOW_DATA_ATTR = false;
966
+ }
967
+
968
+ if (RETURN_DOM_FRAGMENT) {
969
+ RETURN_DOM = true;
970
+ }
971
+ /* Parse profile info */
972
+
973
+
974
+ if (USE_PROFILES) {
975
+ ALLOWED_TAGS = addToSet({}, [...text]);
976
+ ALLOWED_ATTR = [];
977
+
978
+ if (USE_PROFILES.html === true) {
979
+ addToSet(ALLOWED_TAGS, html$1);
980
+ addToSet(ALLOWED_ATTR, html);
981
+ }
982
+
983
+ if (USE_PROFILES.svg === true) {
984
+ addToSet(ALLOWED_TAGS, svg$1);
985
+ addToSet(ALLOWED_ATTR, svg);
986
+ addToSet(ALLOWED_ATTR, xml);
987
+ }
988
+
989
+ if (USE_PROFILES.svgFilters === true) {
990
+ addToSet(ALLOWED_TAGS, svgFilters);
991
+ addToSet(ALLOWED_ATTR, svg);
992
+ addToSet(ALLOWED_ATTR, xml);
993
+ }
994
+
995
+ if (USE_PROFILES.mathMl === true) {
996
+ addToSet(ALLOWED_TAGS, mathMl$1);
997
+ addToSet(ALLOWED_ATTR, mathMl);
998
+ addToSet(ALLOWED_ATTR, xml);
999
+ }
1000
+ }
1001
+ /* Merge configuration parameters */
1002
+
1003
+
1004
+ if (cfg.ADD_TAGS) {
1005
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
1006
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
1007
+ }
1008
+
1009
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
1010
+ }
1011
+
1012
+ if (cfg.ADD_ATTR) {
1013
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
1014
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
1015
+ }
1016
+
1017
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
1018
+ }
1019
+
1020
+ if (cfg.ADD_URI_SAFE_ATTR) {
1021
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
1022
+ }
1023
+
1024
+ if (cfg.FORBID_CONTENTS) {
1025
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
1026
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
1027
+ }
1028
+
1029
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
1030
+ }
1031
+ /* Add #text in case KEEP_CONTENT is set to true */
1032
+
1033
+
1034
+ if (KEEP_CONTENT) {
1035
+ ALLOWED_TAGS['#text'] = true;
1036
+ }
1037
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
1038
+
1039
+
1040
+ if (WHOLE_DOCUMENT) {
1041
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
1042
+ }
1043
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
1044
+
1045
+
1046
+ if (ALLOWED_TAGS.table) {
1047
+ addToSet(ALLOWED_TAGS, ['tbody']);
1048
+ delete FORBID_TAGS.tbody;
1049
+ } // Prevent further manipulation of configuration.
1050
+ // Not available in IE8, Safari 5, etc.
1051
+
1052
+
1053
+ if (freeze) {
1054
+ freeze(cfg);
1055
+ }
1056
+
1057
+ CONFIG = cfg;
1058
+ };
1059
+
1060
+ const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
1061
+ const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']); // Certain elements are allowed in both SVG and HTML
1062
+ // namespace. We need to specify them explicitly
1063
+ // so that they don't get erroneously deleted from
1064
+ // HTML namespace.
1065
+
1066
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
1067
+ /* Keep track of all possible SVG and MathML tags
1068
+ * so that we can perform the namespace checks
1069
+ * correctly. */
1070
+
1071
+ const ALL_SVG_TAGS = addToSet({}, svg$1);
1072
+ addToSet(ALL_SVG_TAGS, svgFilters);
1073
+ addToSet(ALL_SVG_TAGS, svgDisallowed);
1074
+ const ALL_MATHML_TAGS = addToSet({}, mathMl$1);
1075
+ addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
1076
+ /**
1077
+ *
1078
+ *
1079
+ * @param {Element} element a DOM element whose namespace is being checked
1080
+ * @returns {boolean} Return false if the element has a
1081
+ * namespace that a spec-compliant parser would never
1082
+ * return. Return true otherwise.
1083
+ */
1084
+
1085
+ const _checkValidNamespace = function _checkValidNamespace(element) {
1086
+ let parent = getParentNode(element); // In JSDOM, if we're inside shadow DOM, then parentNode
1087
+ // can be null. We just simulate parent in this case.
1088
+
1089
+ if (!parent || !parent.tagName) {
1090
+ parent = {
1091
+ namespaceURI: NAMESPACE,
1092
+ tagName: 'template'
1093
+ };
1094
+ }
1095
+
1096
+ const tagName = stringToLowerCase(element.tagName);
1097
+ const parentTagName = stringToLowerCase(parent.tagName);
1098
+
1099
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
1100
+ return false;
1101
+ }
1102
+
1103
+ if (element.namespaceURI === SVG_NAMESPACE) {
1104
+ // The only way to switch from HTML namespace to SVG
1105
+ // is via <svg>. If it happens via any other tag, then
1106
+ // it should be killed.
1107
+ if (parent.namespaceURI === HTML_NAMESPACE) {
1108
+ return tagName === 'svg';
1109
+ } // The only way to switch from MathML to SVG is via`
1110
+ // svg if parent is either <annotation-xml> or MathML
1111
+ // text integration points.
1112
+
1113
+
1114
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
1115
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1116
+ } // We only allow elements that are defined in SVG
1117
+ // spec. All others are disallowed in SVG namespace.
1118
+
1119
+
1120
+ return Boolean(ALL_SVG_TAGS[tagName]);
1121
+ }
1122
+
1123
+ if (element.namespaceURI === MATHML_NAMESPACE) {
1124
+ // The only way to switch from HTML namespace to MathML
1125
+ // is via <math>. If it happens via any other tag, then
1126
+ // it should be killed.
1127
+ if (parent.namespaceURI === HTML_NAMESPACE) {
1128
+ return tagName === 'math';
1129
+ } // The only way to switch from SVG to MathML is via
1130
+ // <math> and HTML integration points
1131
+
1132
+
1133
+ if (parent.namespaceURI === SVG_NAMESPACE) {
1134
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
1135
+ } // We only allow elements that are defined in MathML
1136
+ // spec. All others are disallowed in MathML namespace.
1137
+
1138
+
1139
+ return Boolean(ALL_MATHML_TAGS[tagName]);
1140
+ }
1141
+
1142
+ if (element.namespaceURI === HTML_NAMESPACE) {
1143
+ // The only way to switch from SVG to HTML is via
1144
+ // HTML integration points, and from MathML to HTML
1145
+ // is via MathML text integration points
1146
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
1147
+ return false;
1148
+ }
1149
+
1150
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
1151
+ return false;
1152
+ } // We disallow tags that are specific for MathML
1153
+ // or SVG and should never appear in HTML namespace
1154
+
1155
+
1156
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1157
+ } // For XHTML and XML documents that support custom namespaces
1158
+
1159
+
1160
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
1161
+ return true;
1162
+ } // The code should never reach this place (this means
1163
+ // that the element somehow got namespace that is not
1164
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
1165
+ // Return false just in case.
1166
+
1167
+
1168
+ return false;
1169
+ };
1170
+ /**
1171
+ * _forceRemove
1172
+ *
1173
+ * @param {Node} node a DOM node
1174
+ */
1175
+
1176
+
1177
+ const _forceRemove = function _forceRemove(node) {
1178
+ arrayPush(DOMPurify.removed, {
1179
+ element: node
1180
+ });
1181
+
1182
+ try {
1183
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
1184
+ node.parentNode.removeChild(node);
1185
+ } catch (_) {
1186
+ node.remove();
1187
+ }
1188
+ };
1189
+ /**
1190
+ * _removeAttribute
1191
+ *
1192
+ * @param {String} name an Attribute name
1193
+ * @param {Node} node a DOM node
1194
+ */
1195
+
1196
+
1197
+ const _removeAttribute = function _removeAttribute(name, node) {
1198
+ try {
1199
+ arrayPush(DOMPurify.removed, {
1200
+ attribute: node.getAttributeNode(name),
1201
+ from: node
1202
+ });
1203
+ } catch (_) {
1204
+ arrayPush(DOMPurify.removed, {
1205
+ attribute: null,
1206
+ from: node
1207
+ });
1208
+ }
1209
+
1210
+ node.removeAttribute(name); // We void attribute values for unremovable "is"" attributes
1211
+
1212
+ if (name === 'is' && !ALLOWED_ATTR[name]) {
1213
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
1214
+ try {
1215
+ _forceRemove(node);
1216
+ } catch (_) {}
1217
+ } else {
1218
+ try {
1219
+ node.setAttribute(name, '');
1220
+ } catch (_) {}
1221
+ }
1222
+ }
1223
+ };
1224
+ /**
1225
+ * _initDocument
1226
+ *
1227
+ * @param {String} dirty a string of dirty markup
1228
+ * @return {Document} a DOM, filled with the dirty markup
1229
+ */
1230
+
1231
+
1232
+ const _initDocument = function _initDocument(dirty) {
1233
+ /* Create a HTML document */
1234
+ let doc;
1235
+ let leadingWhitespace;
1236
+
1237
+ if (FORCE_BODY) {
1238
+ dirty = '<remove></remove>' + dirty;
1239
+ } else {
1240
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
1241
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1242
+ leadingWhitespace = matches && matches[0];
1243
+ }
1244
+
1245
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
1246
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
1247
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
1248
+ }
1249
+
1250
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
1251
+ /*
1252
+ * Use the DOMParser API by default, fallback later if needs be
1253
+ * DOMParser not work for svg when has multiple root element.
1254
+ */
1255
+
1256
+ if (NAMESPACE === HTML_NAMESPACE) {
1257
+ try {
1258
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1259
+ } catch (_) {}
1260
+ }
1261
+ /* Use createHTMLDocument in case DOMParser is not available */
1262
+
1263
+
1264
+ if (!doc || !doc.documentElement) {
1265
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
1266
+
1267
+ try {
1268
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1269
+ } catch (_) {// Syntax error if dirtyPayload is invalid xml
1270
+ }
1271
+ }
1272
+
1273
+ const body = doc.body || doc.documentElement;
1274
+
1275
+ if (dirty && leadingWhitespace) {
1276
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1277
+ }
1278
+ /* Work on whole document or just its body */
1279
+
1280
+
1281
+ if (NAMESPACE === HTML_NAMESPACE) {
1282
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
1283
+ }
1284
+
1285
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
1286
+ };
1287
+ /**
1288
+ * _createIterator
1289
+ *
1290
+ * @param {Document} root document/fragment to create iterator for
1291
+ * @return {Iterator} iterator instance
1292
+ */
1293
+
1294
+
1295
+ const _createIterator = function _createIterator(root) {
1296
+ return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
1297
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
1298
+ };
1299
+ /**
1300
+ * _isClobbered
1301
+ *
1302
+ * @param {Node} elm element to check for clobbering attacks
1303
+ * @return {Boolean} true if clobbered, false if safe
1304
+ */
1305
+
1306
+
1307
+ const _isClobbered = function _isClobbered(elm) {
1308
+ return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
1309
+ };
1310
+ /**
1311
+ * _isNode
1312
+ *
1313
+ * @param {Node} obj object to check whether it's a DOM node
1314
+ * @return {Boolean} true is object is a DOM node
1315
+ */
1316
+
1317
+
1318
+ const _isNode = function _isNode(object) {
1319
+ return typeof Node === 'object' ? object instanceof Node : object && typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
1320
+ };
1321
+ /**
1322
+ * _executeHook
1323
+ * Execute user configurable hooks
1324
+ *
1325
+ * @param {String} entryPoint Name of the hook's entry point
1326
+ * @param {Node} currentNode node to work on with the hook
1327
+ * @param {Object} data additional hook parameters
1328
+ */
1329
+
1330
+
1331
+ const _executeHook = function _executeHook(entryPoint, currentNode, data) {
1332
+ if (!hooks[entryPoint]) {
1333
+ return;
1334
+ }
1335
+
1336
+ arrayForEach(hooks[entryPoint], hook => {
1337
+ hook.call(DOMPurify, currentNode, data, CONFIG);
1338
+ });
1339
+ };
1340
+ /**
1341
+ * _sanitizeElements
1342
+ *
1343
+ * @protect nodeName
1344
+ * @protect textContent
1345
+ * @protect removeChild
1346
+ *
1347
+ * @param {Node} currentNode to check for permission to exist
1348
+ * @return {Boolean} true if node was killed, false if left alive
1349
+ */
1350
+
1351
+
1352
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
1353
+ let content;
1354
+ /* Execute a hook if present */
1355
+
1356
+ _executeHook('beforeSanitizeElements', currentNode, null);
1357
+ /* Check if element is clobbered or can clobber */
1358
+
1359
+
1360
+ if (_isClobbered(currentNode)) {
1361
+ _forceRemove(currentNode);
1362
+
1363
+ return true;
1364
+ }
1365
+ /* Now let's check the element's type and name */
1366
+
1367
+
1368
+ const tagName = transformCaseFunc(currentNode.nodeName);
1369
+ /* Execute a hook if present */
1370
+
1371
+ _executeHook('uponSanitizeElement', currentNode, {
1372
+ tagName,
1373
+ allowedTags: ALLOWED_TAGS
1374
+ });
1375
+ /* Detect mXSS attempts abusing namespace confusion */
1376
+
1377
+
1378
+ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
1379
+ _forceRemove(currentNode);
1380
+
1381
+ return true;
1382
+ }
1383
+ /* Remove element if anything forbids its presence */
1384
+
1385
+
1386
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1387
+ /* Check if we have a custom element to handle */
1388
+ if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
1389
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
1390
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
1391
+ }
1392
+ /* Keep content except for bad-listed elements */
1393
+
1394
+
1395
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1396
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
1397
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1398
+
1399
+ if (childNodes && parentNode) {
1400
+ const childCount = childNodes.length;
1401
+
1402
+ for (let i = childCount - 1; i >= 0; --i) {
1403
+ parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1404
+ }
1405
+ }
1406
+ }
1407
+
1408
+ _forceRemove(currentNode);
1409
+
1410
+ return true;
1411
+ }
1412
+ /* Check whether element has a valid namespace */
1413
+
1414
+
1415
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1416
+ _forceRemove(currentNode);
1417
+
1418
+ return true;
1419
+ }
1420
+ /* Make sure that older browsers don't get noscript mXSS */
1421
+
1422
+
1423
+ if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1424
+ _forceRemove(currentNode);
1425
+
1426
+ return true;
1427
+ }
1428
+ /* Sanitize element content to be template-safe */
1429
+
1430
+
1431
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
1432
+ /* Get the element's text content */
1433
+ content = currentNode.textContent;
1434
+ content = stringReplace(content, MUSTACHE_EXPR, ' ');
1435
+ content = stringReplace(content, ERB_EXPR, ' ');
1436
+ content = stringReplace(content, TMPLIT_EXPR, ' ');
1437
+
1438
+ if (currentNode.textContent !== content) {
1439
+ arrayPush(DOMPurify.removed, {
1440
+ element: currentNode.cloneNode()
1441
+ });
1442
+ currentNode.textContent = content;
1443
+ }
1444
+ }
1445
+ /* Execute a hook if present */
1446
+
1447
+
1448
+ _executeHook('afterSanitizeElements', currentNode, null);
1449
+
1450
+ return false;
1451
+ };
1452
+ /**
1453
+ * _isValidAttribute
1454
+ *
1455
+ * @param {string} lcTag Lowercase tag name of containing element.
1456
+ * @param {string} lcName Lowercase attribute name.
1457
+ * @param {string} value Attribute value.
1458
+ * @return {Boolean} Returns true if `value` is valid, otherwise false.
1459
+ */
1460
+ // eslint-disable-next-line complexity
1461
+
1462
+
1463
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1464
+ /* Make sure attribute cannot clobber */
1465
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1466
+ return false;
1467
+ }
1468
+ /* Allow valid data-* attributes: At least one character after "-"
1469
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1470
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1471
+ We don't need to check the value; it's always URI safe. */
1472
+
1473
+
1474
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1475
+ if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1476
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1477
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1478
+ _basicCustomElementTest(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
1479
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1480
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1481
+ return false;
1482
+ }
1483
+ /* Check value is safe. First, is attr inert? If so, is safe */
1484
+
1485
+ } 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) ; else {
1486
+ return false;
1487
+ }
1488
+
1489
+ return true;
1490
+ };
1491
+ /**
1492
+ * _basicCustomElementCheck
1493
+ * checks if at least one dash is included in tagName, and it's not the first char
1494
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1495
+ * @param {string} tagName name of the tag of the node to sanitize
1496
+ */
1497
+
1498
+
1499
+ const _basicCustomElementTest = function _basicCustomElementTest(tagName) {
1500
+ return tagName.indexOf('-') > 0;
1501
+ };
1502
+ /**
1503
+ * _sanitizeAttributes
1504
+ *
1505
+ * @protect attributes
1506
+ * @protect nodeName
1507
+ * @protect removeAttribute
1508
+ * @protect setAttribute
1509
+ *
1510
+ * @param {Node} currentNode to sanitize
1511
+ */
1512
+
1513
+
1514
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1515
+ let attr;
1516
+ let value;
1517
+ let lcName;
1518
+ let l;
1519
+ /* Execute a hook if present */
1520
+
1521
+ _executeHook('beforeSanitizeAttributes', currentNode, null);
1522
+
1523
+ const {
1524
+ attributes
1525
+ } = currentNode;
1526
+ /* Check if we have attributes; if not we might have a text node */
1527
+
1528
+ if (!attributes) {
1529
+ return;
1530
+ }
1531
+
1532
+ const hookEvent = {
1533
+ attrName: '',
1534
+ attrValue: '',
1535
+ keepAttr: true,
1536
+ allowedAttributes: ALLOWED_ATTR
1537
+ };
1538
+ l = attributes.length;
1539
+ /* Go backwards over all attributes; safely remove bad ones */
1540
+
1541
+ while (l--) {
1542
+ attr = attributes[l];
1543
+ const {
1544
+ name,
1545
+ namespaceURI
1546
+ } = attr;
1547
+ value = name === 'value' ? attr.value : stringTrim(attr.value);
1548
+ lcName = transformCaseFunc(name);
1549
+ /* Execute a hook if present */
1550
+
1551
+ hookEvent.attrName = lcName;
1552
+ hookEvent.attrValue = value;
1553
+ hookEvent.keepAttr = true;
1554
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1555
+
1556
+ _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1557
+
1558
+ value = hookEvent.attrValue;
1559
+ /* Did the hooks approve of the attribute? */
1560
+
1561
+ if (hookEvent.forceKeepAttr) {
1562
+ continue;
1563
+ }
1564
+ /* Remove attribute */
1565
+
1566
+
1567
+ _removeAttribute(name, currentNode);
1568
+ /* Did the hooks approve of the attribute? */
1569
+
1570
+
1571
+ if (!hookEvent.keepAttr) {
1572
+ continue;
1573
+ }
1574
+ /* Work around a security issue in jQuery 3.0 */
1575
+
1576
+
1577
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1578
+ _removeAttribute(name, currentNode);
1579
+
1580
+ continue;
1581
+ }
1582
+ /* Sanitize attribute content to be template-safe */
1583
+
1584
+
1585
+ if (SAFE_FOR_TEMPLATES) {
1586
+ value = stringReplace(value, MUSTACHE_EXPR, ' ');
1587
+ value = stringReplace(value, ERB_EXPR, ' ');
1588
+ value = stringReplace(value, TMPLIT_EXPR, ' ');
1589
+ }
1590
+ /* Is `value` valid for this attribute? */
1591
+
1592
+
1593
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1594
+
1595
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1596
+ continue;
1597
+ }
1598
+ /* Full DOM Clobbering protection via namespace isolation,
1599
+ * Prefix id and name attributes with `user-content-`
1600
+ */
1601
+
1602
+
1603
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1604
+ // Remove the attribute with this value
1605
+ _removeAttribute(name, currentNode); // Prefix the value and later re-create the attribute with the sanitized value
1606
+
1607
+
1608
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1609
+ }
1610
+ /* Handle attributes that require Trusted Types */
1611
+
1612
+
1613
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1614
+ if (namespaceURI) ; else {
1615
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1616
+ case 'TrustedHTML':
1617
+ value = trustedTypesPolicy.createHTML(value);
1618
+ break;
1619
+
1620
+ case 'TrustedScriptURL':
1621
+ value = trustedTypesPolicy.createScriptURL(value);
1622
+ break;
1623
+ }
1624
+ }
1625
+ }
1626
+ /* Handle invalid data-* attribute set by try-catching it */
1627
+
1628
+
1629
+ try {
1630
+ if (namespaceURI) {
1631
+ currentNode.setAttributeNS(namespaceURI, name, value);
1632
+ } else {
1633
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1634
+ currentNode.setAttribute(name, value);
1635
+ }
1636
+
1637
+ arrayPop(DOMPurify.removed);
1638
+ } catch (_) {}
1639
+ }
1640
+ /* Execute a hook if present */
1641
+
1642
+
1643
+ _executeHook('afterSanitizeAttributes', currentNode, null);
1644
+ };
1645
+ /**
1646
+ * _sanitizeShadowDOM
1647
+ *
1648
+ * @param {DocumentFragment} fragment to iterate over recursively
1649
+ */
1650
+
1651
+
1652
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1653
+ let shadowNode;
1654
+
1655
+ const shadowIterator = _createIterator(fragment);
1656
+ /* Execute a hook if present */
1657
+
1658
+
1659
+ _executeHook('beforeSanitizeShadowDOM', fragment, null);
1660
+
1661
+ while (shadowNode = shadowIterator.nextNode()) {
1662
+ /* Execute a hook if present */
1663
+ _executeHook('uponSanitizeShadowNode', shadowNode, null);
1664
+ /* Sanitize tags and elements */
1665
+
1666
+
1667
+ if (_sanitizeElements(shadowNode)) {
1668
+ continue;
1669
+ }
1670
+ /* Deep shadow DOM detected */
1671
+
1672
+
1673
+ if (shadowNode.content instanceof DocumentFragment) {
1674
+ _sanitizeShadowDOM(shadowNode.content);
1675
+ }
1676
+ /* Check attributes, sanitize if necessary */
1677
+
1678
+
1679
+ _sanitizeAttributes(shadowNode);
1680
+ }
1681
+ /* Execute a hook if present */
1682
+
1683
+
1684
+ _executeHook('afterSanitizeShadowDOM', fragment, null);
1685
+ };
1686
+ /**
1687
+ * Sanitize
1688
+ * Public method providing core sanitation functionality
1689
+ *
1690
+ * @param {String|Node} dirty string or DOM node
1691
+ * @param {Object} configuration object
1692
+ */
1693
+ // eslint-disable-next-line complexity
1694
+
1695
+
1696
+ DOMPurify.sanitize = function (dirty) {
1697
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1698
+ let body;
1699
+ let importedNode;
1700
+ let currentNode;
1701
+ let returnNode;
1702
+ /* Make sure we have a string to sanitize.
1703
+ DO NOT return early, as this will return the wrong type if
1704
+ the user has requested a DOM object rather than a string */
1705
+
1706
+ IS_EMPTY_INPUT = !dirty;
1707
+
1708
+ if (IS_EMPTY_INPUT) {
1709
+ dirty = '<!-->';
1710
+ }
1711
+ /* Stringify, in case dirty is an object */
1712
+
1713
+
1714
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1715
+ // eslint-disable-next-line no-negated-condition
1716
+ if (typeof dirty.toString !== 'function') {
1717
+ throw typeErrorCreate('toString is not a function');
1718
+ } else {
1719
+ dirty = dirty.toString();
1720
+
1721
+ if (typeof dirty !== 'string') {
1722
+ throw typeErrorCreate('dirty is not a string, aborting');
1723
+ }
1724
+ }
1725
+ }
1726
+ /* Return dirty HTML if DOMPurify cannot run */
1727
+
1728
+
1729
+ if (!DOMPurify.isSupported) {
1730
+ return dirty;
1731
+ }
1732
+ /* Assign config vars */
1733
+
1734
+
1735
+ if (!SET_CONFIG) {
1736
+ _parseConfig(cfg);
1737
+ }
1738
+ /* Clean up removed elements */
1739
+
1740
+
1741
+ DOMPurify.removed = [];
1742
+ /* Check if dirty is correctly typed for IN_PLACE */
1743
+
1744
+ if (typeof dirty === 'string') {
1745
+ IN_PLACE = false;
1746
+ }
1747
+
1748
+ if (IN_PLACE) {
1749
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1750
+ if (dirty.nodeName) {
1751
+ const tagName = transformCaseFunc(dirty.nodeName);
1752
+
1753
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1754
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1755
+ }
1756
+ }
1757
+ } else if (dirty instanceof Node) {
1758
+ /* If dirty is a DOM element, append to an empty document to avoid
1759
+ elements being stripped by the parser */
1760
+ body = _initDocument('<!---->');
1761
+ importedNode = body.ownerDocument.importNode(dirty, true);
1762
+
1763
+ if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
1764
+ /* Node is already a body, use as is */
1765
+ body = importedNode;
1766
+ } else if (importedNode.nodeName === 'HTML') {
1767
+ body = importedNode;
1768
+ } else {
1769
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1770
+ body.appendChild(importedNode);
1771
+ }
1772
+ } else {
1773
+ /* Exit directly if we have nothing to do */
1774
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1775
+ dirty.indexOf('<') === -1) {
1776
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1777
+ }
1778
+ /* Initialize the document to work on */
1779
+
1780
+
1781
+ body = _initDocument(dirty);
1782
+ /* Check we have a DOM node from the data */
1783
+
1784
+ if (!body) {
1785
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1786
+ }
1787
+ }
1788
+ /* Remove first element node (ours) if FORCE_BODY is set */
1789
+
1790
+
1791
+ if (body && FORCE_BODY) {
1792
+ _forceRemove(body.firstChild);
1793
+ }
1794
+ /* Get node iterator */
1795
+
1796
+
1797
+ const nodeIterator = _createIterator(IN_PLACE ? dirty : body);
1798
+ /* Now start iterating over the created document */
1799
+
1800
+
1801
+ while (currentNode = nodeIterator.nextNode()) {
1802
+ /* Sanitize tags and elements */
1803
+ if (_sanitizeElements(currentNode)) {
1804
+ continue;
1805
+ }
1806
+ /* Shadow DOM detected, sanitize it */
1807
+
1808
+
1809
+ if (currentNode.content instanceof DocumentFragment) {
1810
+ _sanitizeShadowDOM(currentNode.content);
1811
+ }
1812
+ /* Check attributes, sanitize if necessary */
1813
+
1814
+
1815
+ _sanitizeAttributes(currentNode);
1816
+ }
1817
+ /* If we sanitized `dirty` in-place, return it. */
1818
+
1819
+
1820
+ if (IN_PLACE) {
1821
+ return dirty;
1822
+ }
1823
+ /* Return sanitized string or DOM */
1824
+
1825
+
1826
+ if (RETURN_DOM) {
1827
+ if (RETURN_DOM_FRAGMENT) {
1828
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1829
+
1830
+ while (body.firstChild) {
1831
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1832
+ returnNode.appendChild(body.firstChild);
1833
+ }
1834
+ } else {
1835
+ returnNode = body;
1836
+ }
1837
+
1838
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmod) {
1839
+ /*
1840
+ AdoptNode() is not used because internal state is not reset
1841
+ (e.g. the past names map of a HTMLFormElement), this is safe
1842
+ in theory but we would rather not risk another attack vector.
1843
+ The state that is cloned by importNode() is explicitly defined
1844
+ by the specs.
1845
+ */
1846
+ returnNode = importNode.call(originalDocument, returnNode, true);
1847
+ }
1848
+
1849
+ return returnNode;
1850
+ }
1851
+
1852
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1853
+ /* Serialize doctype if allowed */
1854
+
1855
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1856
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1857
+ }
1858
+ /* Sanitize final string template-safe */
1859
+
1860
+
1861
+ if (SAFE_FOR_TEMPLATES) {
1862
+ serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR, ' ');
1863
+ serializedHTML = stringReplace(serializedHTML, ERB_EXPR, ' ');
1864
+ serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR, ' ');
1865
+ }
1866
+
1867
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1868
+ };
1869
+ /**
1870
+ * Public method to set the configuration once
1871
+ * setConfig
1872
+ *
1873
+ * @param {Object} cfg configuration object
1874
+ */
1875
+
1876
+
1877
+ DOMPurify.setConfig = function (cfg) {
1878
+ _parseConfig(cfg);
1879
+
1880
+ SET_CONFIG = true;
1881
+ };
1882
+ /**
1883
+ * Public method to remove the configuration
1884
+ * clearConfig
1885
+ *
1886
+ */
1887
+
1888
+
1889
+ DOMPurify.clearConfig = function () {
1890
+ CONFIG = null;
1891
+ SET_CONFIG = false;
1892
+ };
1893
+ /**
1894
+ * Public method to check if an attribute value is valid.
1895
+ * Uses last set config, if any. Otherwise, uses config defaults.
1896
+ * isValidAttribute
1897
+ *
1898
+ * @param {string} tag Tag name of containing element.
1899
+ * @param {string} attr Attribute name.
1900
+ * @param {string} value Attribute value.
1901
+ * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1902
+ */
1903
+
1904
+
1905
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1906
+ /* Initialize shared config vars if necessary. */
1907
+ if (!CONFIG) {
1908
+ _parseConfig({});
1909
+ }
1910
+
1911
+ const lcTag = transformCaseFunc(tag);
1912
+ const lcName = transformCaseFunc(attr);
1913
+ return _isValidAttribute(lcTag, lcName, value);
1914
+ };
1915
+ /**
1916
+ * AddHook
1917
+ * Public method to add DOMPurify hooks
1918
+ *
1919
+ * @param {String} entryPoint entry point for the hook to add
1920
+ * @param {Function} hookFunction function to execute
1921
+ */
1922
+
1923
+
1924
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1925
+ if (typeof hookFunction !== 'function') {
1926
+ return;
1927
+ }
1928
+
1929
+ hooks[entryPoint] = hooks[entryPoint] || [];
1930
+ arrayPush(hooks[entryPoint], hookFunction);
1931
+ };
1932
+ /**
1933
+ * RemoveHook
1934
+ * Public method to remove a DOMPurify hook at a given entryPoint
1935
+ * (pops it from the stack of hooks if more are present)
1936
+ *
1937
+ * @param {String} entryPoint entry point for the hook to remove
1938
+ * @return {Function} removed(popped) hook
1939
+ */
1940
+
1941
+
1942
+ DOMPurify.removeHook = function (entryPoint) {
1943
+ if (hooks[entryPoint]) {
1944
+ return arrayPop(hooks[entryPoint]);
1945
+ }
1946
+ };
1947
+ /**
1948
+ * RemoveHooks
1949
+ * Public method to remove all DOMPurify hooks at a given entryPoint
1950
+ *
1951
+ * @param {String} entryPoint entry point for the hooks to remove
1952
+ */
1953
+
1954
+
1955
+ DOMPurify.removeHooks = function (entryPoint) {
1956
+ if (hooks[entryPoint]) {
1957
+ hooks[entryPoint] = [];
1958
+ }
1959
+ };
1960
+ /**
1961
+ * RemoveAllHooks
1962
+ * Public method to remove all DOMPurify hooks
1963
+ *
1964
+ */
1965
+
1966
+
1967
+ DOMPurify.removeAllHooks = function () {
1968
+ hooks = {};
1969
+ };
1970
+
1971
+ return DOMPurify;
1972
+ }
1973
+
1974
+ var purify = createDOMPurify();
1975
+
1976
+ const getInitialTab = stripeAccount => {
1977
+ if (stripeAccount?.isConnected) {
1978
+ return STEPS.finish;
1979
+ }
1980
+ if (neetoCist.isPresent(stripeAccount)) {
1981
+ return STEPS.configure;
1982
+ }
1983
+ return STEPS.connect;
1984
+ };
1985
+ const buildStripeConnectUrl = (holdableId, returnUrl) => utils.buildUrl(STRIPE_CONNECT_URL, {
1986
+ holdable_id: holdableId,
1987
+ return_url: returnUrl
1988
+ });
1989
+
1990
+ const Connect = _ref => {
1991
+ let {
1992
+ setActiveTab,
1993
+ holdableId,
1994
+ returnUrl
1995
+ } = _ref;
1996
+ const {
1997
+ t
1998
+ } = reactI18next.useTranslation();
1999
+ const [selectedOption, setSelectedOption] = React.useState(INTEGRATION_METHOD.createNewAccount);
2000
+ const stripeConnectUrl = buildStripeConnectUrl(holdableId, returnUrl);
2001
+ const handleSubmit = () => {
2002
+ if (selectedOption !== INTEGRATION_METHOD.useExistingAccount) {
2003
+ setActiveTab(STEPS.configure);
2004
+ return;
2005
+ }
2006
+ window.location.href = purify.sanitize(stripeConnectUrl);
2007
+ };
2008
+ return /*#__PURE__*/React__default["default"].createElement("div", {
2009
+ className: "mx-auto w-full max-w-lg space-y-8"
2010
+ }, /*#__PURE__*/React__default["default"].createElement("div", {
2011
+ className: "space-y-2"
2012
+ }, /*#__PURE__*/React__default["default"].createElement(SvgStripe, null), /*#__PURE__*/React__default["default"].createElement(Typography__default["default"], {
2013
+ "data-cy": "configure-payment-title",
2014
+ style: "h2",
2015
+ weight: "semibold"
2016
+ }, t("neetoPayments.integrationModal.title")), /*#__PURE__*/React__default["default"].createElement(Label__default["default"], {
2017
+ className: "leading-snug"
2018
+ }, t("neetoPayments.integrationModal.subtitle"))), /*#__PURE__*/React__default["default"].createElement(Radio__default["default"], {
2019
+ stacked: true,
2020
+ value: selectedOption,
2021
+ onChange: event => setSelectedOption(event.target.value)
2022
+ }, /*#__PURE__*/React__default["default"].createElement(Radio__default["default"].Item, {
2023
+ className: "neeto-ui-border-black w-96 py-2",
2024
+ label: t("neetoPayments.integrationModal.createAccount"),
2025
+ name: "accountMethod",
2026
+ value: INTEGRATION_METHOD.createNewAccount
2027
+ }), /*#__PURE__*/React__default["default"].createElement(Radio__default["default"].Item, {
2028
+ className: "neeto-ui-border-black w-96 py-2",
2029
+ label: t("neetoPayments.integrationModal.connectAccount"),
2030
+ name: "accountMethod",
2031
+ value: INTEGRATION_METHOD.useExistingAccount
2032
+ })), /*#__PURE__*/React__default["default"].createElement(Button__default["default"], {
2033
+ label: t("neetoPayments.common.continue"),
2034
+ onClick: handleSubmit
2035
+ }));
2036
+ };
2037
+
2038
+ const Finish = reactUtils.withT(_ref => {
2039
+ let {
2040
+ t,
2041
+ onSuccess
2042
+ } = _ref;
2043
+ return /*#__PURE__*/React__default["default"].createElement(neetointegrations.Finish, {
2044
+ title: t("v2.payment.finishTitle"),
2045
+ onClick: onSuccess
2046
+ }, /*#__PURE__*/React__default["default"].createElement(AccountDetails, null));
2047
+ });
2048
+
2049
+ const StripeConnect = _ref => {
2050
+ let {
2051
+ holdableId = null,
2052
+ isOpen,
2053
+ onClose,
2054
+ isPlatform = false,
2055
+ returnUrl
2056
+ } = _ref;
2057
+ const {
2058
+ data: {
2059
+ account: stripeAccount
2060
+ } = {}
2061
+ } = useConnectApi.useFetchConnectedStripeAccount(holdableId);
2062
+ const [activeTab, setActiveTab] = reactUtils.useStateWithDependency(getInitialTab(stripeAccount), [stripeAccount]);
2063
+ const steps = React.useMemo(() => {
2064
+ const [connect, configure, finish, demo] = INTEGRATION_STEPS;
2065
+ return [{
2066
+ ...connect,
2067
+ isActive: activeTab === STEPS.connect,
2068
+ isCompleted: neetoCist.isPresent(stripeAccount) || activeTab === STEPS.configure || isPlatform
2069
+ }, {
2070
+ ...configure,
2071
+ isActive: activeTab === STEPS.configure,
2072
+ isCompleted: !!stripeAccount?.isConnected
2073
+ }, {
2074
+ ...finish,
2075
+ isActive: activeTab === STEPS.finish,
2076
+ isCompleted: activeTab === STEPS.finish || activeTab === STEPS.demo
2077
+ }, {
2078
+ ...demo,
2079
+ isActive: activeTab === STEPS.demo,
2080
+ isCompleted: activeTab === STEPS.demo
2081
+ }];
2082
+ }, [activeTab, stripeAccount]);
2083
+ return /*#__PURE__*/React__default["default"].createElement(neetointegrations.Modal, {
2084
+ isOpen,
2085
+ onClose,
2086
+ steps
2087
+ }, activeTab === STEPS.connect && /*#__PURE__*/React__default["default"].createElement(Connect, {
2088
+ holdableId,
2089
+ returnUrl,
2090
+ setActiveTab
2091
+ }), activeTab === STEPS.configure && /*#__PURE__*/React__default["default"].createElement(Configure, {
2092
+ holdableId,
2093
+ returnUrl
2094
+ }), activeTab === STEPS.finish && /*#__PURE__*/React__default["default"].createElement(Finish, {
2095
+ onSuccess: onClose
2096
+ }), activeTab === STEPS.demo && /*#__PURE__*/React__default["default"].createElement(neetointegrations.Demo, {
2097
+ onClose
2098
+ }));
2099
+ };
2100
+
2101
+ module.exports = StripeConnect;
2102
+ //# sourceMappingURL=StripeConnect.js.map