@bunnyapp/components 1.6.0-beta.22 → 1.6.0-beta.23

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 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.21';
146
+ const PACKAGE_VERSION = '1.6.0-beta.22';
147
147
  const createRequestHeaders = (token) => {
148
148
  const headers = createClientDevHeaders({ token });
149
149
  // Add the components version header
@@ -18916,6 +18916,37 @@ function Content({ children, accountId }) {
18916
18916
  return jsxRuntime.jsx(SelectedPluginDataProvider, { value: selectedPlugin, children: children });
18917
18917
  }
18918
18918
 
18919
+ const invokePlugin = async ({ method, payload, plugin, token, apiHost, componentsVersion, }) => {
18920
+ var _a, _b, _c, _d;
18921
+ const backendComponent = (_b = (_a = plugin.components) === null || _a === void 0 ? void 0 : _a.backend) === null || _b === void 0 ? void 0 : _b[0];
18922
+ if (!((_d = (_c = plugin.components) === null || _c === void 0 ? void 0 : _c.backend) === null || _d === void 0 ? void 0 : _d.length))
18923
+ throw new Error('The provided plugin is not invokable');
18924
+ if (!(backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.access.includes(method)))
18925
+ throw new Error(`Method ${method} is not invokable`);
18926
+ const body = JSON.stringify({
18927
+ guid: plugin.guid,
18928
+ class: backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.name,
18929
+ method,
18930
+ payload,
18931
+ });
18932
+ const headers = createClientDevHeaders({
18933
+ token,
18934
+ componentsVersion: componentsVersion || PACKAGE_VERSION,
18935
+ });
18936
+ const response = await common.request({
18937
+ method: 'POST',
18938
+ apiHost,
18939
+ endpoint: `/plugins/invoke`,
18940
+ body,
18941
+ token,
18942
+ headers,
18943
+ });
18944
+ if (response.ok)
18945
+ return response.json();
18946
+ const error = await response.json();
18947
+ throw new Error(error.message);
18948
+ };
18949
+
18919
18950
  const DIGIT_REGEX = /\d/;
18920
18951
  const isDigit = (char) => DIGIT_REGEX.test(char);
18921
18952
  const isDeletion = (char) => [8, 46].includes(char); // Backspace or Delete
@@ -18950,7 +18981,7 @@ const unformatCardNumber = (cardNumber) => {
18950
18981
  };
18951
18982
  const storePayment = async (options, plugin, apiHost, accountId) => {
18952
18983
  const { testCreditCardNumber, testCreditCardCvc, testCreditCardExpirationDate, token } = options;
18953
- const response = await common.invokePlugin({
18984
+ const response = await invokePlugin({
18954
18985
  method: 'store_payment_method',
18955
18986
  plugin,
18956
18987
  payload: {
@@ -19075,7 +19106,7 @@ const getQuoteAmountDue = (quote) => {
19075
19106
 
19076
19107
  const { useToken: useAntdToken } = antd.theme;
19077
19108
  const createPaymentMethod = async ({ paymentMethodId, plugin, token, apiHost, accountId, }) => {
19078
- const response = await common.invokePlugin({
19109
+ const response = await invokePlugin({
19079
19110
  plugin,
19080
19111
  method: 'store_payment_method',
19081
19112
  payload: {
@@ -19090,7 +19121,7 @@ const createPaymentMethod = async ({ paymentMethodId, plugin, token, apiHost, ac
19090
19121
  return response;
19091
19122
  };
19092
19123
  const createSetupIntent = (plugin, apiHost, token, accountId) => {
19093
- return common.invokePlugin({
19124
+ return invokePlugin({
19094
19125
  plugin,
19095
19126
  method: 'create_setup_intent',
19096
19127
  token,
@@ -19106,7 +19137,7 @@ const createPaymentHold = async ({ quote, plugin, token, apiHost, paymentMethodI
19106
19137
  amount: quote.amount,
19107
19138
  payment_method_id: paymentMethodId,
19108
19139
  };
19109
- const response = await common.invokePlugin({
19140
+ const response = await invokePlugin({
19110
19141
  plugin,
19111
19142
  method: 'create_payment_hold',
19112
19143
  payload,
@@ -19118,7 +19149,7 @@ const createPaymentHold = async ({ quote, plugin, token, apiHost, paymentMethodI
19118
19149
  return response;
19119
19150
  };
19120
19151
  const fetchStripeKey = async (plugin, apiHost, token, accountId) => {
19121
- const response = await common.invokePlugin({
19152
+ const response = await invokePlugin({
19122
19153
  plugin,
19123
19154
  method: 'retrieve_config',
19124
19155
  token,
@@ -20000,7 +20031,7 @@ function useRemovePaymentMethod(onRemovePaymentMethod, onError) {
20000
20031
  const removePaymentMethod = react.useCallback(async (data) => {
20001
20032
  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
20033
  if (data && plugin) {
20003
- await common.invokePlugin({
20034
+ await invokePlugin({
20004
20035
  plugin: plugin, // TODO: type the plugin
20005
20036
  method: 'remove_payment_method',
20006
20037
  payload: {
@@ -20054,7 +20085,7 @@ function useSetDefaultPaymentMethod(onError, onSuccess) {
20054
20085
  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
20086
  if (plugin) {
20056
20087
  setLoading(true);
20057
- await common.invokePlugin({
20088
+ await invokePlugin({
20058
20089
  plugin: plugin,
20059
20090
  method: 'assign_default_payment_method',
20060
20091
  payload: {
@@ -20383,10 +20414,18 @@ const usePlugins = ({ apiHost, token }) => {
20383
20414
  return response;
20384
20415
  };
20385
20416
  const getPlugins = async ({ token, apiHost }) => {
20417
+ const baseHeaders = createClientDevHeaders({
20418
+ token,
20419
+ componentsVersion: PACKAGE_VERSION,
20420
+ });
20421
+ const requestHeaders = {
20422
+ ...baseHeaders,
20423
+ };
20386
20424
  const response = await common.request({
20387
20425
  endpoint: `/plugins`,
20388
20426
  token,
20389
20427
  apiHost,
20428
+ headers: requestHeaders,
20390
20429
  });
20391
20430
  if (response.ok) {
20392
20431
  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, invokePlugin, 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';
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.21';
144
+ const PACKAGE_VERSION = '1.6.0-beta.22';
145
145
  const createRequestHeaders = (token) => {
146
146
  const headers = createClientDevHeaders({ token });
147
147
  // Add the components version header
@@ -18914,6 +18914,37 @@ function Content({ children, accountId }) {
18914
18914
  return jsx(SelectedPluginDataProvider, { value: selectedPlugin, children: children });
18915
18915
  }
18916
18916
 
18917
+ const invokePlugin = async ({ method, payload, plugin, token, apiHost, componentsVersion, }) => {
18918
+ var _a, _b, _c, _d;
18919
+ const backendComponent = (_b = (_a = plugin.components) === null || _a === void 0 ? void 0 : _a.backend) === null || _b === void 0 ? void 0 : _b[0];
18920
+ if (!((_d = (_c = plugin.components) === null || _c === void 0 ? void 0 : _c.backend) === null || _d === void 0 ? void 0 : _d.length))
18921
+ throw new Error('The provided plugin is not invokable');
18922
+ if (!(backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.access.includes(method)))
18923
+ throw new Error(`Method ${method} is not invokable`);
18924
+ const body = JSON.stringify({
18925
+ guid: plugin.guid,
18926
+ class: backendComponent === null || backendComponent === void 0 ? void 0 : backendComponent.name,
18927
+ method,
18928
+ payload,
18929
+ });
18930
+ const headers = createClientDevHeaders({
18931
+ token,
18932
+ componentsVersion: componentsVersion || PACKAGE_VERSION,
18933
+ });
18934
+ const response = await request$1({
18935
+ method: 'POST',
18936
+ apiHost,
18937
+ endpoint: `/plugins/invoke`,
18938
+ body,
18939
+ token,
18940
+ headers,
18941
+ });
18942
+ if (response.ok)
18943
+ return response.json();
18944
+ const error = await response.json();
18945
+ throw new Error(error.message);
18946
+ };
18947
+
18917
18948
  const DIGIT_REGEX = /\d/;
18918
18949
  const isDigit = (char) => DIGIT_REGEX.test(char);
18919
18950
  const isDeletion = (char) => [8, 46].includes(char); // Backspace or Delete
@@ -20381,10 +20412,18 @@ const usePlugins = ({ apiHost, token }) => {
20381
20412
  return response;
20382
20413
  };
20383
20414
  const getPlugins = async ({ token, apiHost }) => {
20415
+ const baseHeaders = createClientDevHeaders({
20416
+ token,
20417
+ componentsVersion: PACKAGE_VERSION,
20418
+ });
20419
+ const requestHeaders = {
20420
+ ...baseHeaders,
20421
+ };
20384
20422
  const response = await request$1({
20385
20423
  endpoint: `/plugins`,
20386
20424
  token,
20387
20425
  apiHost,
20426
+ headers: requestHeaders,
20388
20427
  });
20389
20428
  if (response.ok) {
20390
20429
  const plugins = await response.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunnyapp/components",
3
- "version": "1.6.0-beta.22",
3
+ "version": "1.6.0-beta.23",
4
4
  "description": "Components from the Bunny portal to embed Bunny UI functionality into your application.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",