From edaba44ff0a89e5ef8aa9602bf929b94914655ab Mon Sep 17 00:00:00 2001 From: Christopher Rogers Date: Wed, 3 Jan 2024 08:57:26 -0700 Subject: [PATCH] Adds compilation artifacts --- .gitignore | 1 - lib-dist/element/card-cvv.js | 28 +++++ lib-dist/element/card-month.js | 28 +++++ lib-dist/element/card-number.js | 28 +++++ lib-dist/element/card-year.js | 28 +++++ lib-dist/element/card.js | 28 +++++ lib-dist/element/element.js | 161 ++++++++++++++++++++++++++++ lib-dist/element/index.js | 10 ++ lib-dist/elements.js | 63 +++++++++++ lib-dist/index.js | 83 +++++++++++++++ lib-dist/provider.js | 134 +++++++++++++++++++++++ lib-dist/risk-data-collector.js | 114 ++++++++++++++++++++ lib-dist/three-d-secure-action.js | 108 +++++++++++++++++++ lib-dist/use-checkout-pricing.js | 171 ++++++++++++++++++++++++++++++ lib-dist/use-recurly.js | 34 ++++++ 15 files changed, 1018 insertions(+), 1 deletion(-) create mode 100644 lib-dist/element/card-cvv.js create mode 100644 lib-dist/element/card-month.js create mode 100644 lib-dist/element/card-number.js create mode 100644 lib-dist/element/card-year.js create mode 100644 lib-dist/element/card.js create mode 100644 lib-dist/element/element.js create mode 100644 lib-dist/element/index.js create mode 100644 lib-dist/elements.js create mode 100644 lib-dist/index.js create mode 100644 lib-dist/provider.js create mode 100644 lib-dist/risk-data-collector.js create mode 100644 lib-dist/three-d-secure-action.js create mode 100644 lib-dist/use-checkout-pricing.js create mode 100644 lib-dist/use-recurly.js diff --git a/.gitignore b/.gitignore index 5a75083..818ebef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .DS_Store build -lib-dist node_modules npm-debug.log diff --git a/lib-dist/element/card-cvv.js b/lib-dist/element/card-cvv.js new file mode 100644 index 0000000..0f269c4 --- /dev/null +++ b/lib-dist/element/card-cvv.js @@ -0,0 +1,28 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _element = _interopRequireDefault(require("./element")); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var CardCvvElement = /*#__PURE__*/function (_Element) { + (0, _inherits2["default"])(CardCvvElement, _Element); + var _super = _createSuper(CardCvvElement); + function CardCvvElement() { + (0, _classCallCheck2["default"])(this, CardCvvElement); + return _super.apply(this, arguments); + } + return (0, _createClass2["default"])(CardCvvElement); +}(_element["default"]); +exports["default"] = CardCvvElement; +(0, _defineProperty2["default"])(CardCvvElement, "elementClassName", 'CardCvvElement'); +; \ No newline at end of file diff --git a/lib-dist/element/card-month.js b/lib-dist/element/card-month.js new file mode 100644 index 0000000..f2b7fb1 --- /dev/null +++ b/lib-dist/element/card-month.js @@ -0,0 +1,28 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _element = _interopRequireDefault(require("./element")); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var CardMonthElement = /*#__PURE__*/function (_Element) { + (0, _inherits2["default"])(CardMonthElement, _Element); + var _super = _createSuper(CardMonthElement); + function CardMonthElement() { + (0, _classCallCheck2["default"])(this, CardMonthElement); + return _super.apply(this, arguments); + } + return (0, _createClass2["default"])(CardMonthElement); +}(_element["default"]); +exports["default"] = CardMonthElement; +(0, _defineProperty2["default"])(CardMonthElement, "elementClassName", 'CardMonthElement'); +; \ No newline at end of file diff --git a/lib-dist/element/card-number.js b/lib-dist/element/card-number.js new file mode 100644 index 0000000..6ec5ca2 --- /dev/null +++ b/lib-dist/element/card-number.js @@ -0,0 +1,28 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _element = _interopRequireDefault(require("./element")); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var CardNumberElement = /*#__PURE__*/function (_Element) { + (0, _inherits2["default"])(CardNumberElement, _Element); + var _super = _createSuper(CardNumberElement); + function CardNumberElement() { + (0, _classCallCheck2["default"])(this, CardNumberElement); + return _super.apply(this, arguments); + } + return (0, _createClass2["default"])(CardNumberElement); +}(_element["default"]); +exports["default"] = CardNumberElement; +(0, _defineProperty2["default"])(CardNumberElement, "elementClassName", 'CardNumberElement'); +; \ No newline at end of file diff --git a/lib-dist/element/card-year.js b/lib-dist/element/card-year.js new file mode 100644 index 0000000..ab00163 --- /dev/null +++ b/lib-dist/element/card-year.js @@ -0,0 +1,28 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _element = _interopRequireDefault(require("./element")); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var CardYearElement = /*#__PURE__*/function (_Element) { + (0, _inherits2["default"])(CardYearElement, _Element); + var _super = _createSuper(CardYearElement); + function CardYearElement() { + (0, _classCallCheck2["default"])(this, CardYearElement); + return _super.apply(this, arguments); + } + return (0, _createClass2["default"])(CardYearElement); +}(_element["default"]); +exports["default"] = CardYearElement; +(0, _defineProperty2["default"])(CardYearElement, "elementClassName", 'CardYearElement'); +; \ No newline at end of file diff --git a/lib-dist/element/card.js b/lib-dist/element/card.js new file mode 100644 index 0000000..382e7a3 --- /dev/null +++ b/lib-dist/element/card.js @@ -0,0 +1,28 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _element = _interopRequireDefault(require("./element")); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var CardElement = /*#__PURE__*/function (_Element) { + (0, _inherits2["default"])(CardElement, _Element); + var _super = _createSuper(CardElement); + function CardElement() { + (0, _classCallCheck2["default"])(this, CardElement); + return _super.apply(this, arguments); + } + return (0, _createClass2["default"])(CardElement); +}(_element["default"]); +exports["default"] = CardElement; +(0, _defineProperty2["default"])(CardElement, "elementClassName", 'CardElement'); +; \ No newline at end of file diff --git a/lib-dist/element/element.js b/lib-dist/element/element.js new file mode 100644 index 0000000..7221c9f --- /dev/null +++ b/lib-dist/element/element.js @@ -0,0 +1,161 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); +var _react = _interopRequireDefault(require("react")); +var _propTypes = _interopRequireDefault(require("prop-types")); +var _memoizeOne = _interopRequireDefault(require("memoize-one")); +var _elements = require("../elements"); +var _excluded = ["id", "className", "onChange", "onBlur", "onFocus", "onReady", "onSubmit"]; +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var noop = function noop() {}; +var extractOptions = function extractOptions(props) { + var id = props.id, + className = props.className, + onChange = props.onChange, + onBlur = props.onBlur, + onFocus = props.onFocus, + onReady = props.onReady, + onSubmit = props.onSubmit, + options = (0, _objectWithoutProperties2["default"])(props, _excluded); + return options; +}; + +/** + * An [Element](https://developers.recurly.com/reference/recurly-js/#elements) + * component which wraps its Recurly.js analogue, passing configuration props to the underlying + * Recurly.js Element and allowing event binding using props. + */ +var Element = /*#__PURE__*/function (_React$PureComponent) { + (0, _inherits2["default"])(Element, _React$PureComponent); + var _super = _createSuper(Element); + function Element(props, context) { + var _this; + (0, _classCallCheck2["default"])(this, Element); + _this = _super.call(this, props, context); + (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "configureElement", (0, _memoizeOne["default"])(function (element, options) { + return element && Object.keys(options).length > 0 && element.configure(options); + })); + var elementClassName = _this.constructor.elementClassName; + if (!context || !context.elements) { + throw new Error("<".concat(elementClassName, "> must be within an tree.")); + } + _this._container = /*#__PURE__*/_react["default"].createRef(); + return _this; + } + (0, _createClass2["default"])(Element, [{ + key: "componentDidMount", + value: function componentDidMount() { + var _this2 = this; + var elementClassName = this.constructor.elementClassName; + var options = extractOptions(this.props); + var element = this._element = this.context.elements[elementClassName](options); + element.on('attach', function () { + var _this2$props; + return (_this2$props = _this2.props).onReady.apply(_this2$props, arguments); + }); + element.on('change', function () { + var _this2$props2; + return (_this2$props2 = _this2.props).onChange.apply(_this2$props2, arguments); + }); + element.on('blur', function () { + var _this2$props3; + return (_this2$props3 = _this2.props).onBlur.apply(_this2$props3, arguments); + }); + element.on('focus', function () { + var _this2$props4; + return (_this2$props4 = _this2.props).onFocus.apply(_this2$props4, arguments); + }); + element.on('submit', function () { + var _this2$props5; + return (_this2$props5 = _this2.props).onSubmit.apply(_this2$props5, arguments); + }); + this._element.attach(this._container.current); + } + }, { + key: "componentWillUnmount", + value: function componentWillUnmount() { + this._element.destroy(); + } + }, { + key: "render", + value: function render() { + var element = this._element, + props = this.props; + this.configureElement(element, extractOptions(props)); + return /*#__PURE__*/_react["default"].createElement("div", { + id: props.id, + className: props.className, + ref: this._container + }); + } + }]); + return Element; +}(_react["default"].PureComponent); +exports["default"] = Element; +(0, _defineProperty2["default"])(Element, "propTypes", { + /** + * Applied to the container. + */ + id: _propTypes["default"].string, + /** + * Applied to the container. + */ + className: _propTypes["default"].string, + /** + * Called when the state of the Element changes. + */ + onChange: _propTypes["default"].func, + /** + * Called when a user blurs from the Element. + */ + onBlur: _propTypes["default"].func, + /** + * Called when a user focuses on the Element. + */ + onFocus: _propTypes["default"].func, + /** + * Called when the Element has finished initializing. + */ + onReady: _propTypes["default"].func, + /** + * Called when a user presses the enter key while focused on the Element. + */ + onSubmit: _propTypes["default"].func, + /** + * Set style attributes for the Element. + * See [Styling Elements](https://developers.recurly.com/reference/recurly-js/#styling-elements) + * for available options. + */ + style: _propTypes["default"].object, + /** + * [tabindex](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex) + * property to be applied to the outer iframe. + */ + tabIndex: _propTypes["default"].string +}); +(0, _defineProperty2["default"])(Element, "defaultProps", { + id: undefined, + className: undefined, + onChange: function onChange(state) {}, + onBlur: noop, + onFocus: noop, + onReady: noop, + onSubmit: noop, + style: {}, + tabIndex: undefined +}); +(0, _defineProperty2["default"])(Element, "contextType", _elements.RecurlyElementsContext); +; \ No newline at end of file diff --git a/lib-dist/element/index.js b/lib-dist/element/index.js new file mode 100644 index 0000000..2d02b73 --- /dev/null +++ b/lib-dist/element/index.js @@ -0,0 +1,10 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _element = _interopRequireDefault(require("./element")); +var _default = _element["default"]; +exports["default"] = _default; \ No newline at end of file diff --git a/lib-dist/elements.js b/lib-dist/elements.js new file mode 100644 index 0000000..59dafcc --- /dev/null +++ b/lib-dist/elements.js @@ -0,0 +1,63 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = exports.RecurlyElementsContext = void 0; +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _react = _interopRequireDefault(require("react")); +var _propTypes = _interopRequireDefault(require("prop-types")); +var _provider = require("./provider"); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var RecurlyElementsContext = /*#__PURE__*/_react["default"].createContext(); +exports.RecurlyElementsContext = RecurlyElementsContext; +var Provider = RecurlyElementsContext.Provider; +var Elements = /*#__PURE__*/function (_React$Component) { + (0, _inherits2["default"])(Elements, _React$Component); + var _super = _createSuper(Elements); + function Elements(props, context) { + var _this; + (0, _classCallCheck2["default"])(this, Elements); + _this = _super.call(this, props, context); + if (!context || !context.recurly) { + throw new Error(' must be within a tree.'); + } + _this._elements = _this.context.recurly.Elements(); + _this._elements.on('submit', function (el) { + return _this.props.onSubmit(el); + }); + return _this; + } + (0, _createClass2["default"])(Elements, [{ + key: "render", + value: function render() { + var elements = this._elements; + return /*#__PURE__*/_react["default"].createElement(Provider, { + value: { + elements: elements + } + }, this.props.children); + } + }]); + return Elements; +}(_react["default"].Component); +exports["default"] = Elements; +(0, _defineProperty2["default"])(Elements, "propTypes", { + /** + * Called when a user presses the enter key while + * focused on any descendant `*Element`. + */ + onSubmit: _propTypes["default"].func +}); +(0, _defineProperty2["default"])(Elements, "defaultProps", { + onSubmit: function onSubmit() {} +}); +(0, _defineProperty2["default"])(Elements, "contextType", _provider.RecurlyContext); +; \ No newline at end of file diff --git a/lib-dist/index.js b/lib-dist/index.js new file mode 100644 index 0000000..b87d6cf --- /dev/null +++ b/lib-dist/index.js @@ -0,0 +1,83 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "CardCvvElement", { + enumerable: true, + get: function get() { + return _cardCvv["default"]; + } +}); +Object.defineProperty(exports, "CardElement", { + enumerable: true, + get: function get() { + return _card["default"]; + } +}); +Object.defineProperty(exports, "CardMonthElement", { + enumerable: true, + get: function get() { + return _cardMonth["default"]; + } +}); +Object.defineProperty(exports, "CardNumberElement", { + enumerable: true, + get: function get() { + return _cardNumber["default"]; + } +}); +Object.defineProperty(exports, "CardYearElement", { + enumerable: true, + get: function get() { + return _cardYear["default"]; + } +}); +Object.defineProperty(exports, "Elements", { + enumerable: true, + get: function get() { + return _elements["default"]; + } +}); +Object.defineProperty(exports, "RecurlyProvider", { + enumerable: true, + get: function get() { + return _provider["default"]; + } +}); +Object.defineProperty(exports, "RiskDataCollector", { + enumerable: true, + get: function get() { + return _riskDataCollector["default"]; + } +}); +Object.defineProperty(exports, "ThreeDSecureAction", { + enumerable: true, + get: function get() { + return _threeDSecureAction["default"]; + } +}); +Object.defineProperty(exports, "useCheckoutPricing", { + enumerable: true, + get: function get() { + return _useCheckoutPricing["default"]; + } +}); +Object.defineProperty(exports, "useRecurly", { + enumerable: true, + get: function get() { + return _useRecurly["default"]; + } +}); +var _provider = _interopRequireDefault(require("./provider")); +var _useRecurly = _interopRequireDefault(require("./use-recurly")); +var _elements = _interopRequireDefault(require("./elements")); +var _card = _interopRequireDefault(require("./element/card")); +var _cardNumber = _interopRequireDefault(require("./element/card-number")); +var _cardMonth = _interopRequireDefault(require("./element/card-month")); +var _cardYear = _interopRequireDefault(require("./element/card-year")); +var _cardCvv = _interopRequireDefault(require("./element/card-cvv")); +var _riskDataCollector = _interopRequireDefault(require("./risk-data-collector")); +var _threeDSecureAction = _interopRequireDefault(require("./three-d-secure-action")); +var _useCheckoutPricing = _interopRequireDefault(require("./use-checkout-pricing")); \ No newline at end of file diff --git a/lib-dist/provider.js b/lib-dist/provider.js new file mode 100644 index 0000000..ae7e6a6 --- /dev/null +++ b/lib-dist/provider.js @@ -0,0 +1,134 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = exports.RecurlyContext = void 0; +var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _react = _interopRequireDefault(require("react")); +var _propTypes = _interopRequireDefault(require("prop-types")); +var _package = require("../package.json"); +var _excluded = ["children"]; +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var RecurlyContext = /*#__PURE__*/_react["default"].createContext({ + recurly: null +}); +exports.RecurlyContext = RecurlyContext; +var Provider = RecurlyContext.Provider; + +/** + * This is the top-level component for `react-recurly`, and must wrap any other + * `react-recurly` component you will use. It is responsible for creating a `Recurly.js` + * instance for any descendant components to interact with. + * + * This component accepts your `publicKey` and other configuration options for Recurly.js as props. + */ +var RecurlyProvider = /*#__PURE__*/function (_React$Component) { + (0, _inherits2["default"])(RecurlyProvider, _React$Component); + var _super = _createSuper(RecurlyProvider); + function RecurlyProvider(props) { + var _this; + (0, _classCallCheck2["default"])(this, RecurlyProvider); + _this = _super.call(this, props); + if (!(_this.props.publicKey || _this.props.hostname)) { + throw new Error("\n Please pass your 'publicKey' value to this RecurlyProvider.\n Example: \n "); + } + + // TODO: ensure proper shape? + if (!window.recurly || !window.recurly.Recurly) { + throw new Error("\n Please load Recurly.js (https://js.recurly.com/v4/recurly.js) on this page prior to\n loading your React application.\n "); + } + var _this$props = _this.props, + children = _this$props.children, + options = (0, _objectWithoutProperties2["default"])(_this$props, _excluded); + _this._recurly = fetchRecurlyInstance(options); + if (!RecurlyProvider.hasReportedInitialization && _this._recurly.report) { + _this._recurly.ready(function () { + _this._recurly.report('react-recurly', { + version: _package.version + }); + }); + RecurlyProvider.hasReportedInitialization = true; + } + return _this; + } + (0, _createClass2["default"])(RecurlyProvider, [{ + key: "render", + value: function render() { + return /*#__PURE__*/_react["default"].createElement(Provider, { + value: { + recurly: this._recurly + } + }, this.props.children); + } + }]); + return RecurlyProvider; +}(_react["default"].Component); +exports["default"] = RecurlyProvider; +(0, _defineProperty2["default"])(RecurlyProvider, "propTypes", { + /** + * Your Recurly public key. See + * [API Access](https://app.recurly.com/go/developer/api_access). + */ + publicKey: _propTypes["default"].string, + /** + * Register the current hostname + */ + hostname: _propTypes["default"].string, + /** + * Sets a default currency + */ + currency: _propTypes["default"].string, + /** + * Adds additional field requirements for tokenization. ex: ['cvv'] + */ + required: _propTypes["default"].arrayOf(_propTypes["default"].string), + /** + * API request timeout in ms + */ + timeout: _propTypes["default"].number, + /** + * Fraud configuration. See the + * [Recurly-js docs on fraud configuration](https://developers.recurly.com/reference/recurly-js/index.html#fraud) + */ + fraud: _propTypes["default"].shape({ + kount: _propTypes["default"].shape({ + dataCollector: _propTypes["default"].bool + }), + braintree: _propTypes["default"].shape({ + deviceData: _propTypes["default"].string + }), + litle: _propTypes["default"].shape({ + sessionId: _propTypes["default"].string + }) + }) +}); +(0, _defineProperty2["default"])(RecurlyProvider, "defaultProps", { + publicKey: '' +}); +; + +/** + * Retrieves a recurly instance from a cache on the Recurly class, or creates one + * if none found on the cache key. This is used when the Provider is being + * regularly re-instantiated + * + * @param {object} options instance instantiation options + * @return {Recurly} + */ +function fetchRecurlyInstance(options) { + var cache = window.recurly.Recurly.__instanceCache = window.recurly.Recurly.__instanceCache || {}; + var key = JSON.stringify(options); + var recurly = cache[key] || new window.recurly.Recurly(); + recurly.configure(options); + cache[key] = recurly; + return recurly; +} \ No newline at end of file diff --git a/lib-dist/risk-data-collector.js b/lib-dist/risk-data-collector.js new file mode 100644 index 0000000..24f7fdf --- /dev/null +++ b/lib-dist/risk-data-collector.js @@ -0,0 +1,114 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = exports.RISK_STRATEGIES = void 0; +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _react = _interopRequireDefault(require("react")); +var _propTypes = _interopRequireDefault(require("prop-types")); +var _provider = require("./provider"); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var RISK_STRATEGIES = ['kount']; + +/** + * Injects risk data collection point in your checkout. + * + * + */ +exports.RISK_STRATEGIES = RISK_STRATEGIES; +var RiskDataCollector = /*#__PURE__*/function (_React$Component) { + (0, _inherits2["default"])(RiskDataCollector, _React$Component); + var _super = _createSuper(RiskDataCollector); + function RiskDataCollector(props, context) { + var _this; + (0, _classCallCheck2["default"])(this, RiskDataCollector); + _this = _super.call(this, props, context); + if (!context || !context.recurly) { + throw new Error(' must be within a tree.'); + } + + /** + * TODO + * Once recurly.Fraud is decommissioned in favor of recurly.Risk.FraudConcern, + * this will change to consume a RiskProvider. + */ + _this._container = /*#__PURE__*/_react["default"].createRef(); + _this._recurly = _this.context.recurly; + return _this; + } + (0, _createClass2["default"])(RiskDataCollector, [{ + key: "componentDidMount", + value: function componentDidMount() { + var container = this._container, + recurly = this._recurly; + var _this$props = this.props, + strategy = _this$props.strategy, + onError = _this$props.onError; + recurly.configure({ + fraud: (0, _defineProperty2["default"])({}, strategy, { + dataCollector: true, + form: container.current + }) + }); + var fraud = this._fraud = recurly.fraud; + fraud.on('error', function () { + return onError.apply(void 0, arguments); + }); + } + }, { + key: "render", + value: function render() { + return /*#__PURE__*/_react["default"].createElement("div", { + id: this.props.id, + className: this.props.className, + ref: this._container + }); + } + }]); + return RiskDataCollector; +}(_react["default"].Component); +exports["default"] = RiskDataCollector; +(0, _defineProperty2["default"])(RiskDataCollector, "propTypes", { + /** + * Applied to the container. + */ + id: _propTypes["default"].string, + /** + * Applied to the container. + */ + className: _propTypes["default"].string, + /** + * Risk data collection strategy. + * + * Possible values: 'kount' + */ + strategy: _propTypes["default"].oneOf(RISK_STRATEGIES), + /** + * Called when an error is encountered + * @type {FraudDataCollector~onError} + */ + + /** + * @callback FraudDataCollector~onError + * @param {RecurlyError} + */ + onError: _propTypes["default"].func +}); +(0, _defineProperty2["default"])(RiskDataCollector, "defaultProps", { + id: undefined, + className: undefined, + strategy: RISK_STRATEGIES[0], + onError: function onError(e) { + throw e; + } +}); +(0, _defineProperty2["default"])(RiskDataCollector, "contextType", _provider.RecurlyContext); +; \ No newline at end of file diff --git a/lib-dist/three-d-secure-action.js b/lib-dist/three-d-secure-action.js new file mode 100644 index 0000000..8a9e4e2 --- /dev/null +++ b/lib-dist/three-d-secure-action.js @@ -0,0 +1,108 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = void 0; +var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); +var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); +var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _react = _interopRequireDefault(require("react")); +var _propTypes = _interopRequireDefault(require("prop-types")); +var _provider = require("./provider"); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } +var ThreeDSecureAction = /*#__PURE__*/function (_React$PureComponent) { + (0, _inherits2["default"])(ThreeDSecureAction, _React$PureComponent); + var _super = _createSuper(ThreeDSecureAction); + function ThreeDSecureAction(props, context) { + var _this; + (0, _classCallCheck2["default"])(this, ThreeDSecureAction); + _this = _super.call(this, props, context); + if (!context || !context.recurly) { + throw new Error(' must be within a tree.'); + } + var actionTokenId = props.actionTokenId; + _this._container = /*#__PURE__*/_react["default"].createRef(); + _this._risk = _this.context.recurly.Risk(); + _this._threeDSecure = _this._risk.ThreeDSecure({ + actionTokenId: actionTokenId + }); + _this._threeDSecure.on('token', function () { + var _this$props; + return (_this$props = _this.props).onToken.apply(_this$props, arguments); + }); + _this._threeDSecure.on('error', function () { + var _this$props2; + return (_this$props2 = _this.props).onError.apply(_this$props2, arguments); + }); + return _this; + } + (0, _createClass2["default"])(ThreeDSecureAction, [{ + key: "componentDidMount", + value: function componentDidMount() { + this._threeDSecure.attach(this._container.current); + } + }, { + key: "render", + value: function render() { + return /*#__PURE__*/_react["default"].createElement("div", { + id: this.props.id, + className: this.props.className, + ref: this._container + }); + } + }]); + return ThreeDSecureAction; +}(_react["default"].PureComponent); +exports["default"] = ThreeDSecureAction; +(0, _defineProperty2["default"])(ThreeDSecureAction, "propTypes", { + /** + * Applied to the container. + */ + id: _propTypes["default"].string, + /** + * Applied to the container. + */ + className: _propTypes["default"].string, + /** + * `three_d_secure_action_token_id` returned by the Recurly API when 3-D Secure + * authentication is required for a transaction. + */ + actionTokenId: _propTypes["default"].string, + /** + * Called when the user has completed the 3D Secure flow + * @type {ThreeDSecureAction~onToken} + */ + + /** + * @callback ThreeDSecureAction~onToken + * @param {ThreeDSecureActionResultToken} + */ + onToken: _propTypes["default"].func, + /** + * Called when an error is encountered + * @type {ThreeDSecureAction~onError} + */ + + /** + * @callback ThreeDSecureAction~onError + * @param {RecurlyError} + */ + onError: _propTypes["default"].func +}); +(0, _defineProperty2["default"])(ThreeDSecureAction, "defaultProps", { + id: undefined, + className: undefined, + actionTokenId: '', + onToken: function onToken() {}, + onError: function onError(e) { + throw e; + } +}); +(0, _defineProperty2["default"])(ThreeDSecureAction, "contextType", _provider.RecurlyContext); +; \ No newline at end of file diff --git a/lib-dist/use-checkout-pricing.js b/lib-dist/use-checkout-pricing.js new file mode 100644 index 0000000..ee63f48 --- /dev/null +++ b/lib-dist/use-checkout-pricing.js @@ -0,0 +1,171 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = useCheckoutPricing; +exports.throwError = throwError; +var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); +var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); +var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); +var _react = require("react"); +var _useRecurly = _interopRequireDefault(require("./use-recurly")); +var _excluded = ["subscriptions", "adjustments"]; +/** + * @typedef {Object} address + * @property {String} country + * @property {String} postalCode + * @property {String} vatNumber + */ + +/** + * useCheckoutPricing interface + * @typedef {Object} useCheckoutPricingInterface + * @property {Array} subscriptions + * @property {Array} adjustments + * @property {String} currency + * @property {address} address + * @property {address} shippingAddress + * @property {String} coupon + * @property {String} giftCard + * @property {Object} tax + */ +/** + * A custom hook for interfacing with recurly.js' checkoutPricing API meant to mimic the call signature, return + * type, and behavior of `react.useState`. + * + * Accepts an `initialInputs` param (same as useState) and an error handling function. + * + * Returns a tuple with an output object and an update function similar to useState. + * + * @typedef {Object} output + * @property {Object} price + * @property {Object} pricing + * @property {Boolean} loading + * + * @typedef {Function} setPricing + * @typedef {[output, setPricing]} useCheckoutPricingInstance + * + * @param {PricingInput} useCheckoutPricingInterface + * @param {function} handleError + * @returns {useCheckoutPricingInstance} useCheckoutPricingInstance + */ +function useCheckoutPricing(initialInputs) { + var handleError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : throwError; + var recurly = (0, _useRecurly["default"])(); + var _useState = (0, _react.useState)(true), + _useState2 = (0, _slicedToArray2["default"])(_useState, 2), + loading = _useState2[0], + setLoading = _useState2[1]; + var _useState3 = (0, _react.useState)(initialInputs || {}), + _useState4 = (0, _slicedToArray2["default"])(_useState3, 2), + input = _useState4[0], + setInput = _useState4[1]; + var _useState5 = (0, _react.useState)(recurly.Pricing.Checkout()), + _useState6 = (0, _slicedToArray2["default"])(_useState5, 2), + pricing = _useState6[0], + setPricing = _useState6[1]; + (0, _react.useEffect)(function () { + setLoading(true); + var _input$subscriptions = input.subscriptions, + subscriptions = _input$subscriptions === void 0 ? [] : _input$subscriptions, + _input$adjustments = input.adjustments, + adjustments = _input$adjustments === void 0 ? [] : _input$adjustments, + restInputs = (0, _objectWithoutProperties2["default"])(input, _excluded); + var checkoutPricing = recurly.Pricing.Checkout(); + addSubscriptions(subscriptions, checkoutPricing).then(function () { + checkoutPricing = addAdjustments(adjustments, checkoutPricing); + checkoutPricing = addRestInputs(restInputs, checkoutPricing); + checkoutPricing = checkoutPricing.reprice().done(function () { + setPricing(checkoutPricing); + setLoading(false); + }); + }); + function addAdjustments(adjustments, checkoutPricing) { + if (!adjustments.length) return checkoutPricing.reprice(); + return adjustments.reduce(function (checkoutPricing, adjustment) { + return checkoutPricing.adjustment(adjustment)["catch"](handleError); + }, checkoutPricing); + } + ; + function addRestInputs(restInputs, checkoutPricing) { + var restInputsEntries = Object.entries(restInputs); + if (!restInputsEntries.length) return checkoutPricing.reprice(); + var PRICING_METHODS = checkoutPricing.pricing.PRICING_METHODS; + var exclude = ['reset', 'remove', 'reprice', 'subscription', 'adjustment', 'addon', 'plan']; + var permittedInputs = PRICING_METHODS.filter(function (method) { + return !exclude.includes(method); + }); + return restInputsEntries.reduce(function (acc, input) { + var _input = (0, _slicedToArray2["default"])(input, 2), + method = _input[0], + value = _input[1]; + var shouldCallPricingMethod = value && permittedInputs.includes(method); + return shouldCallPricingMethod ? acc[method](value)["catch"](handleError) : acc; + }, checkoutPricing); + } + ; + function addSubscriptions(subscriptions, checkoutPricing) { + var _subscriptions$reduce = subscriptions.reduce(function (_ref, _ref2) { + var checkoutPricing = _ref.checkoutPricing, + subscriptionPricings = _ref.subscriptionPricings; + var id = _ref2.id, + plan = _ref2.plan, + tax = _ref2.tax, + _ref2$addons = _ref2.addons, + addons = _ref2$addons === void 0 ? [] : _ref2$addons, + quantity = _ref2.quantity; + var subscriptionPricing = recurly.Pricing.Subscription(); + if (id) { + subscriptionPricing.id = id; + } + if (restInputs.currency) { + subscriptionPricing = subscriptionPricing.currency(restInputs.currency); + } + subscriptionPricing = subscriptionPricing.plan(plan, { + quantity: quantity + }); + if (addons.length) { + subscriptionPricing = addAddons(addons, subscriptionPricing); + } + if (tax) { + subscriptionPricing = subscriptionPricing.tax(tax); + } + subscriptionPricing = subscriptionPricing["catch"](handleError); + return { + checkoutPricing: checkoutPricing.subscription(subscriptionPricing.done())["catch"](handleError), + subscriptionPricings: [].concat((0, _toConsumableArray2["default"])(subscriptionPricings), [subscriptionPricing]) + }; + }, { + checkoutPricing: checkoutPricing, + subscriptionPricings: [] + }), + subscriptionPricings = _subscriptions$reduce.subscriptionPricings; + return Promise.all(subscriptionPricings); + } + ; + function addAddons() { + var addons = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + var subscriptionPricing = arguments.length > 1 ? arguments[1] : undefined; + return addons.reduce(function (subscriptionPricing, _ref3) { + var code = _ref3.code, + quantity = _ref3.quantity; + return subscriptionPricing.addon(code, { + quantity: quantity + }); + }, subscriptionPricing)["catch"](handleError); + } + ; + }, [input, handleError, recurly.Pricing]); + var pricingState = { + price: pricing && structuredClone(pricing.price) || {}, + loading: loading + }; + return [pricingState, setInput, pricing]; +} +; +function throwError(err) { + throw err; +} +; \ No newline at end of file diff --git a/lib-dist/use-recurly.js b/lib-dist/use-recurly.js new file mode 100644 index 0000000..6c10122 --- /dev/null +++ b/lib-dist/use-recurly.js @@ -0,0 +1,34 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports["default"] = useRecurly; +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); +var _react = require("react"); +var _elements = require("./elements"); +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } +/** + * Provides a recurly instance bound to the provider tree + */ +function useRecurly() { + var elementsContext = (0, _react.useContext)(_elements.RecurlyElementsContext); + if (!elementsContext || !elementsContext.elements) { + throw new Error("It looks like you are trying to use Recurly outside of an Elements context.\n Please be sure the component that calls 'useRecurly' is within an component."); + } + var elements = elementsContext.elements; + var recurly = _objectSpread(_objectSpread({}, elements.recurly), {}, { + // Provide a curried token method to bind the elements from the closest context + token: function token() { + var _elements$recurly; + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + return (_elements$recurly = elements.recurly).token.apply(_elements$recurly, [elements].concat(args)); + } + }); + Object.setPrototypeOf(recurly, elements.recurly); + return recurly; +} \ No newline at end of file