@bunnyapp/components 1.6.0-beta.22 → 1.6.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +83 -8
- package/dist/esm/index.js +77 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -143,7 +143,7 @@ const useAllErrorFormats = () => {
|
|
|
143
143
|
};
|
|
144
144
|
|
|
145
145
|
// This will be replaced at build time by rollup-plugin-replace
|
|
146
|
-
const PACKAGE_VERSION = '1.6.0-beta.
|
|
146
|
+
const PACKAGE_VERSION = '1.6.0-beta.23';
|
|
147
147
|
const createRequestHeaders = (token) => {
|
|
148
148
|
const headers = createClientDevHeaders({ token });
|
|
149
149
|
// Add the components version header
|
|
@@ -1039,6 +1039,42 @@ const defaultStyled = typeof styled === "function" ? styled : styled.default;
|
|
|
1039
1039
|
// !!! This is a workaround to avoid the issue with styled-components not supporting ESM
|
|
1040
1040
|
// Workaround from https://github.com/styled-components/styled-components/issues/3437#issuecomment-1103085056
|
|
1041
1041
|
|
|
1042
|
+
if (typeof window !== 'undefined') {
|
|
1043
|
+
// Prevent watermark from being added
|
|
1044
|
+
const originalCreateElement = document.createElement.bind(document);
|
|
1045
|
+
document.createElement = function (tagName, options) {
|
|
1046
|
+
const element = originalCreateElement(tagName, options);
|
|
1047
|
+
if (tagName.toLowerCase() === 'div') {
|
|
1048
|
+
const originalAttachShadow = element.attachShadow;
|
|
1049
|
+
element.attachShadow = function (init) {
|
|
1050
|
+
var _a;
|
|
1051
|
+
const shadowRoot = originalAttachShadow.call(this, init);
|
|
1052
|
+
// Prevent watermark styles from being injected
|
|
1053
|
+
const originalInnerHTMLSetter = (_a = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML')) === null || _a === void 0 ? void 0 : _a.set;
|
|
1054
|
+
console.log('originalInnerHTMLSetter', originalInnerHTMLSetter);
|
|
1055
|
+
if (originalInnerHTMLSetter) {
|
|
1056
|
+
Object.defineProperty(shadowRoot, 'innerHTML', {
|
|
1057
|
+
set: function (value) {
|
|
1058
|
+
// Block watermark injection
|
|
1059
|
+
if (typeof value === 'string' &&
|
|
1060
|
+
value.includes('background-image: url(data:image/webp')) {
|
|
1061
|
+
return; // Don't set the watermark HTML
|
|
1062
|
+
}
|
|
1063
|
+
console.log('value', value);
|
|
1064
|
+
originalInnerHTMLSetter.call(this, value);
|
|
1065
|
+
},
|
|
1066
|
+
get: function () {
|
|
1067
|
+
console.log('this.innerHTML', this.innerHTML);
|
|
1068
|
+
return this.innerHTML;
|
|
1069
|
+
},
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
return shadowRoot;
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
return element;
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1042
1078
|
const LISENSE_KEY = 'eyJkYXRhIjoiZXlKMElqb2liM0puWVc1cGVtRjBhVzl1SWl3aVlYWjFJam94TnpneU5ETXhPVGs1TENKa2JTSTZJbUoxYm01NUxtTnZiU0lzSW00aU9pSmhOV1F5TWpKaFpXTTNOelF5TkdFNUlpd2laWGh3SWpveE56WTJORFEzT1RrNUxDSmtiWFFpT2lKM2FXeGtZMkZ5WkNKOSIsInNpZ25hdHVyZSI6ImdJWW5BYWp0WW1aSHV1b1RrTkZCZnRGYjEzUTJOZXZwQXlKRmszdy9STDNUa08rRXZYWlV0MDZxenBrZWdOK1A4TXlkbFY1aityemQvM1VpYlB5SW1VSzAweHZSVk5hS29EOXB0cVpkbjR5SWRRdE1pU1NjZ0J1K1RkM0NXM2FONVNrdlNJVDEyTGpBMnVVYll2RmJ6RFpMci9hODkwa05sT0NQZURoVjMyd0w3R0NrTnV2Z1MyZlk5Mis0L25FdUdvZXBZR0RPN0Ryb3NaOGVlbnJ6b1BsQ044T204eFlMNXJxdUkvS2xLVTVYaGN0allrdzBTR0FlL0pDR1dTN1dLTDAvYmFvbS9GS1ltNU91VmlzcmlDVlc2UXgvbzBnTGE4bUtXLytMb3pNaHdFemdtU2I2S0xERzZpTEVPL0czQ2pYN2p2dTU1NEc4OUx2aW1BaE5BQT09In0=';
|
|
1043
1079
|
// Custom zoom layout component that uses useZoomContext
|
|
1044
1080
|
const CustomZoomLayout = () => {
|
|
@@ -18916,6 +18952,37 @@ function Content({ children, accountId }) {
|
|
|
18916
18952
|
return jsxRuntime.jsx(SelectedPluginDataProvider, { value: selectedPlugin, children: children });
|
|
18917
18953
|
}
|
|
18918
18954
|
|
|
18955
|
+
const invokePlugin = async ({ method, payload, plugin, token, apiHost, componentsVersion, }) => {
|
|
18956
|
+
var _a, _b, _c, _d;
|
|
18957
|
+
const backendComponent = (_b = (_a = plugin.components) === null || _a === void 0 ? void 0 : _a.backend) === null || _b === void 0 ? void 0 : _b[0];
|
|
18958
|
+
if (!((_d = (_c = plugin.components) === null || _c === void 0 ? void 0 : _c.backend) === null || _d === void 0 ? void 0 : _d.length))
|
|
18959
|
+
throw new Error('The provided plugin is not invokable');
|
|
18960
|
+
if (!(backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.access.includes(method)))
|
|
18961
|
+
throw new Error(`Method ${method} is not invokable`);
|
|
18962
|
+
const body = JSON.stringify({
|
|
18963
|
+
guid: plugin.guid,
|
|
18964
|
+
class: backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.name,
|
|
18965
|
+
method,
|
|
18966
|
+
payload,
|
|
18967
|
+
});
|
|
18968
|
+
const headers = createClientDevHeaders({
|
|
18969
|
+
token,
|
|
18970
|
+
componentsVersion: componentsVersion || PACKAGE_VERSION,
|
|
18971
|
+
});
|
|
18972
|
+
const response = await common.request({
|
|
18973
|
+
method: 'POST',
|
|
18974
|
+
apiHost,
|
|
18975
|
+
endpoint: `/plugins/invoke`,
|
|
18976
|
+
body,
|
|
18977
|
+
token,
|
|
18978
|
+
headers,
|
|
18979
|
+
});
|
|
18980
|
+
if (response.ok)
|
|
18981
|
+
return response.json();
|
|
18982
|
+
const error = await response.json();
|
|
18983
|
+
throw new Error(error.message);
|
|
18984
|
+
};
|
|
18985
|
+
|
|
18919
18986
|
const DIGIT_REGEX = /\d/;
|
|
18920
18987
|
const isDigit = (char) => DIGIT_REGEX.test(char);
|
|
18921
18988
|
const isDeletion = (char) => [8, 46].includes(char); // Backspace or Delete
|
|
@@ -18950,7 +19017,7 @@ const unformatCardNumber = (cardNumber) => {
|
|
|
18950
19017
|
};
|
|
18951
19018
|
const storePayment = async (options, plugin, apiHost, accountId) => {
|
|
18952
19019
|
const { testCreditCardNumber, testCreditCardCvc, testCreditCardExpirationDate, token } = options;
|
|
18953
|
-
const response = await
|
|
19020
|
+
const response = await invokePlugin({
|
|
18954
19021
|
method: 'store_payment_method',
|
|
18955
19022
|
plugin,
|
|
18956
19023
|
payload: {
|
|
@@ -19075,7 +19142,7 @@ const getQuoteAmountDue = (quote) => {
|
|
|
19075
19142
|
|
|
19076
19143
|
const { useToken: useAntdToken } = antd.theme;
|
|
19077
19144
|
const createPaymentMethod = async ({ paymentMethodId, plugin, token, apiHost, accountId, }) => {
|
|
19078
|
-
const response = await
|
|
19145
|
+
const response = await invokePlugin({
|
|
19079
19146
|
plugin,
|
|
19080
19147
|
method: 'store_payment_method',
|
|
19081
19148
|
payload: {
|
|
@@ -19090,7 +19157,7 @@ const createPaymentMethod = async ({ paymentMethodId, plugin, token, apiHost, ac
|
|
|
19090
19157
|
return response;
|
|
19091
19158
|
};
|
|
19092
19159
|
const createSetupIntent = (plugin, apiHost, token, accountId) => {
|
|
19093
|
-
return
|
|
19160
|
+
return invokePlugin({
|
|
19094
19161
|
plugin,
|
|
19095
19162
|
method: 'create_setup_intent',
|
|
19096
19163
|
token,
|
|
@@ -19106,7 +19173,7 @@ const createPaymentHold = async ({ quote, plugin, token, apiHost, paymentMethodI
|
|
|
19106
19173
|
amount: quote.amount,
|
|
19107
19174
|
payment_method_id: paymentMethodId,
|
|
19108
19175
|
};
|
|
19109
|
-
const response = await
|
|
19176
|
+
const response = await invokePlugin({
|
|
19110
19177
|
plugin,
|
|
19111
19178
|
method: 'create_payment_hold',
|
|
19112
19179
|
payload,
|
|
@@ -19118,7 +19185,7 @@ const createPaymentHold = async ({ quote, plugin, token, apiHost, paymentMethodI
|
|
|
19118
19185
|
return response;
|
|
19119
19186
|
};
|
|
19120
19187
|
const fetchStripeKey = async (plugin, apiHost, token, accountId) => {
|
|
19121
|
-
const response = await
|
|
19188
|
+
const response = await invokePlugin({
|
|
19122
19189
|
plugin,
|
|
19123
19190
|
method: 'retrieve_config',
|
|
19124
19191
|
token,
|
|
@@ -20000,7 +20067,7 @@ function useRemovePaymentMethod(onRemovePaymentMethod, onError) {
|
|
|
20000
20067
|
const removePaymentMethod = react.useCallback(async (data) => {
|
|
20001
20068
|
const plugin = paymentPlugins === null || paymentPlugins === void 0 ? void 0 : paymentPlugins.find(paymentPlugin => { var _a; return String(paymentPlugin.id) === ((_a = data === null || data === void 0 ? void 0 : data.plugin) === null || _a === void 0 ? void 0 : _a.id); });
|
|
20002
20069
|
if (data && plugin) {
|
|
20003
|
-
await
|
|
20070
|
+
await invokePlugin({
|
|
20004
20071
|
plugin: plugin, // TODO: type the plugin
|
|
20005
20072
|
method: 'remove_payment_method',
|
|
20006
20073
|
payload: {
|
|
@@ -20054,7 +20121,7 @@ function useSetDefaultPaymentMethod(onError, onSuccess) {
|
|
|
20054
20121
|
const plugin = paymentPlugins === null || paymentPlugins === void 0 ? void 0 : paymentPlugins.find(paymentPlugin => { var _a; return String(paymentPlugin.id) === ((_a = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.plugin) === null || _a === void 0 ? void 0 : _a.id); }); // TODO: type the response to PluginData
|
|
20055
20122
|
if (plugin) {
|
|
20056
20123
|
setLoading(true);
|
|
20057
|
-
await
|
|
20124
|
+
await invokePlugin({
|
|
20058
20125
|
plugin: plugin,
|
|
20059
20126
|
method: 'assign_default_payment_method',
|
|
20060
20127
|
payload: {
|
|
@@ -20383,10 +20450,18 @@ const usePlugins = ({ apiHost, token }) => {
|
|
|
20383
20450
|
return response;
|
|
20384
20451
|
};
|
|
20385
20452
|
const getPlugins = async ({ token, apiHost }) => {
|
|
20453
|
+
const baseHeaders = createClientDevHeaders({
|
|
20454
|
+
token,
|
|
20455
|
+
componentsVersion: PACKAGE_VERSION,
|
|
20456
|
+
});
|
|
20457
|
+
const requestHeaders = {
|
|
20458
|
+
...baseHeaders,
|
|
20459
|
+
};
|
|
20386
20460
|
const response = await common.request({
|
|
20387
20461
|
endpoint: `/plugins`,
|
|
20388
20462
|
token,
|
|
20389
20463
|
apiHost,
|
|
20464
|
+
headers: requestHeaders,
|
|
20390
20465
|
});
|
|
20391
20466
|
if (response.ok) {
|
|
20392
20467
|
const plugins = await response.json();
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { isValidElement, createContext, useContext, useMemo, useState, useEffect, useRef, createElement, useCallback, Fragment as Fragment$1 } from 'react';
|
|
3
3
|
import { DownloadOutlined, CreditCardOutlined, EllipsisOutlined, BankOutlined, SearchOutlined, CloseOutlined, CheckCircleFilled, InfoCircleOutlined } from '@ant-design/icons';
|
|
4
|
-
import { useErrorNotification, DEFAULT_CONFIG, createClientDevHeaders as createClientDevHeaders$1, X_BUNNY_COMPONENTS_VERSION_HEADER_NAME, QueryKeyFactory as QueryKeyFactory$1, useIsMobile as useIsMobile$1, DEFAULT_BRAND_COLOR, isColorTooDark, DEFAULT_TOP_NAV_IMAGE_URL, DEFAULT_ACCENT_COLOR, INPUT_BORDER_COLOR, SLATE_50, SLATE_400, SLATE_200, DEFAULT_SECONDARY_COLOR, request as request$1,
|
|
4
|
+
import { useErrorNotification, DEFAULT_CONFIG, createClientDevHeaders as createClientDevHeaders$1, X_BUNNY_COMPONENTS_VERSION_HEADER_NAME, QueryKeyFactory as QueryKeyFactory$1, useIsMobile as useIsMobile$1, DEFAULT_BRAND_COLOR, isColorTooDark, DEFAULT_TOP_NAV_IMAGE_URL, DEFAULT_ACCENT_COLOR, INPUT_BORDER_COLOR, SLATE_50, SLATE_400, SLATE_200, DEFAULT_SECONDARY_COLOR, request as request$1, useAllErrorFormats as useAllErrorFormats$1, formatCurrency as formatCurrency$1, GRAY_500, GRAY_200, useSuccessNotification, PAYABLE_INVOICE_STATES, BreakpointNumbers as BreakpointNumbers$1, useGraphQLmutation, useInfoNotification, formatDate, TransactionState, SLATE_600, WHITE, TransactionKind, QuoteChangeKind, SLATE_500, PRIMARY_COLOR, Lists, getAccount, ChargeType, PERIOD_LABELS, MODAL_MAX_HEIGHT, DataInterval, SLATE_100 } from '@bunnyapp/common';
|
|
5
5
|
import { ConfigProvider, Spin, Typography, Button, theme as theme$1, Tag, Dropdown, Input, Modal, Checkbox, Skeleton, Collapse, Form, Tooltip, Drawer, Card as Card$1, Select, Divider, Popconfirm, Table, Radio, Space, Switch } from 'antd';
|
|
6
6
|
import { Markup } from 'interweave';
|
|
7
7
|
import request from 'graphql-request';
|
|
@@ -141,7 +141,7 @@ const useAllErrorFormats = () => {
|
|
|
141
141
|
};
|
|
142
142
|
|
|
143
143
|
// This will be replaced at build time by rollup-plugin-replace
|
|
144
|
-
const PACKAGE_VERSION = '1.6.0-beta.
|
|
144
|
+
const PACKAGE_VERSION = '1.6.0-beta.23';
|
|
145
145
|
const createRequestHeaders = (token) => {
|
|
146
146
|
const headers = createClientDevHeaders({ token });
|
|
147
147
|
// Add the components version header
|
|
@@ -1037,6 +1037,42 @@ const defaultStyled = typeof styled === "function" ? styled : styled.default;
|
|
|
1037
1037
|
// !!! This is a workaround to avoid the issue with styled-components not supporting ESM
|
|
1038
1038
|
// Workaround from https://github.com/styled-components/styled-components/issues/3437#issuecomment-1103085056
|
|
1039
1039
|
|
|
1040
|
+
if (typeof window !== 'undefined') {
|
|
1041
|
+
// Prevent watermark from being added
|
|
1042
|
+
const originalCreateElement = document.createElement.bind(document);
|
|
1043
|
+
document.createElement = function (tagName, options) {
|
|
1044
|
+
const element = originalCreateElement(tagName, options);
|
|
1045
|
+
if (tagName.toLowerCase() === 'div') {
|
|
1046
|
+
const originalAttachShadow = element.attachShadow;
|
|
1047
|
+
element.attachShadow = function (init) {
|
|
1048
|
+
var _a;
|
|
1049
|
+
const shadowRoot = originalAttachShadow.call(this, init);
|
|
1050
|
+
// Prevent watermark styles from being injected
|
|
1051
|
+
const originalInnerHTMLSetter = (_a = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML')) === null || _a === void 0 ? void 0 : _a.set;
|
|
1052
|
+
console.log('originalInnerHTMLSetter', originalInnerHTMLSetter);
|
|
1053
|
+
if (originalInnerHTMLSetter) {
|
|
1054
|
+
Object.defineProperty(shadowRoot, 'innerHTML', {
|
|
1055
|
+
set: function (value) {
|
|
1056
|
+
// Block watermark injection
|
|
1057
|
+
if (typeof value === 'string' &&
|
|
1058
|
+
value.includes('background-image: url(data:image/webp')) {
|
|
1059
|
+
return; // Don't set the watermark HTML
|
|
1060
|
+
}
|
|
1061
|
+
console.log('value', value);
|
|
1062
|
+
originalInnerHTMLSetter.call(this, value);
|
|
1063
|
+
},
|
|
1064
|
+
get: function () {
|
|
1065
|
+
console.log('this.innerHTML', this.innerHTML);
|
|
1066
|
+
return this.innerHTML;
|
|
1067
|
+
},
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
return shadowRoot;
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
return element;
|
|
1074
|
+
};
|
|
1075
|
+
}
|
|
1040
1076
|
const LISENSE_KEY = 'eyJkYXRhIjoiZXlKMElqb2liM0puWVc1cGVtRjBhVzl1SWl3aVlYWjFJam94TnpneU5ETXhPVGs1TENKa2JTSTZJbUoxYm01NUxtTnZiU0lzSW00aU9pSmhOV1F5TWpKaFpXTTNOelF5TkdFNUlpd2laWGh3SWpveE56WTJORFEzT1RrNUxDSmtiWFFpT2lKM2FXeGtZMkZ5WkNKOSIsInNpZ25hdHVyZSI6ImdJWW5BYWp0WW1aSHV1b1RrTkZCZnRGYjEzUTJOZXZwQXlKRmszdy9STDNUa08rRXZYWlV0MDZxenBrZWdOK1A4TXlkbFY1aityemQvM1VpYlB5SW1VSzAweHZSVk5hS29EOXB0cVpkbjR5SWRRdE1pU1NjZ0J1K1RkM0NXM2FONVNrdlNJVDEyTGpBMnVVYll2RmJ6RFpMci9hODkwa05sT0NQZURoVjMyd0w3R0NrTnV2Z1MyZlk5Mis0L25FdUdvZXBZR0RPN0Ryb3NaOGVlbnJ6b1BsQ044T204eFlMNXJxdUkvS2xLVTVYaGN0allrdzBTR0FlL0pDR1dTN1dLTDAvYmFvbS9GS1ltNU91VmlzcmlDVlc2UXgvbzBnTGE4bUtXLytMb3pNaHdFemdtU2I2S0xERzZpTEVPL0czQ2pYN2p2dTU1NEc4OUx2aW1BaE5BQT09In0=';
|
|
1041
1077
|
// Custom zoom layout component that uses useZoomContext
|
|
1042
1078
|
const CustomZoomLayout = () => {
|
|
@@ -18914,6 +18950,37 @@ function Content({ children, accountId }) {
|
|
|
18914
18950
|
return jsx(SelectedPluginDataProvider, { value: selectedPlugin, children: children });
|
|
18915
18951
|
}
|
|
18916
18952
|
|
|
18953
|
+
const invokePlugin = async ({ method, payload, plugin, token, apiHost, componentsVersion, }) => {
|
|
18954
|
+
var _a, _b, _c, _d;
|
|
18955
|
+
const backendComponent = (_b = (_a = plugin.components) === null || _a === void 0 ? void 0 : _a.backend) === null || _b === void 0 ? void 0 : _b[0];
|
|
18956
|
+
if (!((_d = (_c = plugin.components) === null || _c === void 0 ? void 0 : _c.backend) === null || _d === void 0 ? void 0 : _d.length))
|
|
18957
|
+
throw new Error('The provided plugin is not invokable');
|
|
18958
|
+
if (!(backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.access.includes(method)))
|
|
18959
|
+
throw new Error(`Method ${method} is not invokable`);
|
|
18960
|
+
const body = JSON.stringify({
|
|
18961
|
+
guid: plugin.guid,
|
|
18962
|
+
class: backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.name,
|
|
18963
|
+
method,
|
|
18964
|
+
payload,
|
|
18965
|
+
});
|
|
18966
|
+
const headers = createClientDevHeaders({
|
|
18967
|
+
token,
|
|
18968
|
+
componentsVersion: componentsVersion || PACKAGE_VERSION,
|
|
18969
|
+
});
|
|
18970
|
+
const response = await request$1({
|
|
18971
|
+
method: 'POST',
|
|
18972
|
+
apiHost,
|
|
18973
|
+
endpoint: `/plugins/invoke`,
|
|
18974
|
+
body,
|
|
18975
|
+
token,
|
|
18976
|
+
headers,
|
|
18977
|
+
});
|
|
18978
|
+
if (response.ok)
|
|
18979
|
+
return response.json();
|
|
18980
|
+
const error = await response.json();
|
|
18981
|
+
throw new Error(error.message);
|
|
18982
|
+
};
|
|
18983
|
+
|
|
18917
18984
|
const DIGIT_REGEX = /\d/;
|
|
18918
18985
|
const isDigit = (char) => DIGIT_REGEX.test(char);
|
|
18919
18986
|
const isDeletion = (char) => [8, 46].includes(char); // Backspace or Delete
|
|
@@ -20381,10 +20448,18 @@ const usePlugins = ({ apiHost, token }) => {
|
|
|
20381
20448
|
return response;
|
|
20382
20449
|
};
|
|
20383
20450
|
const getPlugins = async ({ token, apiHost }) => {
|
|
20451
|
+
const baseHeaders = createClientDevHeaders({
|
|
20452
|
+
token,
|
|
20453
|
+
componentsVersion: PACKAGE_VERSION,
|
|
20454
|
+
});
|
|
20455
|
+
const requestHeaders = {
|
|
20456
|
+
...baseHeaders,
|
|
20457
|
+
};
|
|
20384
20458
|
const response = await request$1({
|
|
20385
20459
|
endpoint: `/plugins`,
|
|
20386
20460
|
token,
|
|
20387
20461
|
apiHost,
|
|
20462
|
+
headers: requestHeaders,
|
|
20388
20463
|
});
|
|
20389
20464
|
if (response.ok) {
|
|
20390
20465
|
const plugins = await response.json();
|
package/package.json
CHANGED