@coinflowlabs/react 4.1.3 → 4.2.2

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 (44) hide show
  1. package/build/cjs/card-form/CoinflowCardForm.d.ts +138 -0
  2. package/build/cjs/card-form/CoinflowCardForm.js +177 -0
  3. package/build/cjs/card-form/CoinflowCardForm.js.map +1 -0
  4. package/build/cjs/card-form/TokenEx.d.ts +106 -0
  5. package/build/cjs/card-form/TokenEx.js +4 -0
  6. package/build/cjs/card-form/TokenEx.js.map +1 -0
  7. package/build/cjs/card-form/useCardFormIframe.d.ts +99 -0
  8. package/build/cjs/card-form/useCardFormIframe.js +191 -0
  9. package/build/cjs/card-form/useCardFormIframe.js.map +1 -0
  10. package/build/cjs/common/CoinflowTypes.d.ts +25 -1
  11. package/build/cjs/common/CoinflowTypes.js +8 -1
  12. package/build/cjs/common/CoinflowTypes.js.map +1 -1
  13. package/build/cjs/common/CoinflowUtils.d.ts +1 -1
  14. package/build/cjs/common/CoinflowUtils.js +3 -1
  15. package/build/cjs/common/CoinflowUtils.js.map +1 -1
  16. package/build/cjs/index.d.ts +1 -1
  17. package/build/cjs/index.js +1 -1
  18. package/build/cjs/index.js.map +1 -1
  19. package/build/esm/card-form/CoinflowCardForm.d.ts +138 -0
  20. package/build/esm/card-form/CoinflowCardForm.js +173 -0
  21. package/build/esm/card-form/CoinflowCardForm.js.map +1 -0
  22. package/build/esm/card-form/TokenEx.d.ts +106 -0
  23. package/build/esm/card-form/TokenEx.js +3 -0
  24. package/build/esm/card-form/TokenEx.js.map +1 -0
  25. package/build/esm/card-form/useCardFormIframe.d.ts +99 -0
  26. package/build/esm/card-form/useCardFormIframe.js +187 -0
  27. package/build/esm/card-form/useCardFormIframe.js.map +1 -0
  28. package/build/esm/common/CoinflowTypes.d.ts +25 -1
  29. package/build/esm/common/CoinflowTypes.js +7 -0
  30. package/build/esm/common/CoinflowTypes.js.map +1 -1
  31. package/build/esm/common/CoinflowUtils.d.ts +1 -1
  32. package/build/esm/common/CoinflowUtils.js +3 -1
  33. package/build/esm/common/CoinflowUtils.js.map +1 -1
  34. package/build/esm/index.d.ts +1 -1
  35. package/build/esm/index.js +1 -1
  36. package/build/esm/index.js.map +1 -1
  37. package/build/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +1 -1
  39. package/build/cjs/CoinflowCardForm.d.ts +0 -39
  40. package/build/cjs/CoinflowCardForm.js +0 -100
  41. package/build/cjs/CoinflowCardForm.js.map +0 -1
  42. package/build/esm/CoinflowCardForm.d.ts +0 -39
  43. package/build/esm/CoinflowCardForm.js +0 -97
  44. package/build/esm/CoinflowCardForm.js.map +0 -1
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoinflowCardForm = void 0;
4
- var tslib_1 = require("tslib");
5
- var react_1 = tslib_1.__importStar(require("react"));
6
- var CoinflowIFrame_1 = require("./CoinflowIFrame");
7
- /**
8
- * Allows merchants to collect card information from their customers in a PCI-compliant way and receive a token for use with the `/api/checkout/token` endpoint.
9
- *
10
- * Usage:
11
- * ```tsx
12
- * const ref = useRef<{getToken(): Promise<{token: string}>}>();
13
- *
14
- * <CoinflowCardForm
15
- * ref={coinflowCardFormRef}
16
- * ...
17
- * />
18
- *
19
- * <button onClick={() => {
20
- * ref.current?.getToken()
21
- * .then(({token}) => console.log(token))
22
- * .catch(e => console.error('GET TOKEN ERROR', e))
23
- * }}>Get Token</button>
24
- *
25
- * ```
26
- */
27
- exports.CoinflowCardForm = (0, react_1.forwardRef)(function (props, ref) {
28
- var iframeRef = (0, react_1.useRef)();
29
- (0, react_1.useImperativeHandle)(ref, function () { return ({
30
- getToken: function () {
31
- return tslib_1.__awaiter(this, void 0, void 0, function () {
32
- var methodName, isValid, response;
33
- return tslib_1.__generator(this, function (_a) {
34
- switch (_a.label) {
35
- case 0:
36
- methodName = 'getToken';
37
- if (!iframeRef.current)
38
- throw new Error('Unable to get token');
39
- isValid = function (data) {
40
- try {
41
- var res = JSON.parse(data);
42
- return 'method' in res && res.method === methodName;
43
- }
44
- catch (e) {
45
- return false;
46
- }
47
- };
48
- return [4 /*yield*/, iframeRef.current.sendAndReceiveMessage(methodName, isValid)];
49
- case 1:
50
- response = _a.sent();
51
- return [2 /*return*/, JSON.parse(response).data];
52
- }
53
- });
54
- });
55
- },
56
- }); });
57
- var merchantCss = (0, react_1.useMemo)(function () {
58
- if (!props.customCss)
59
- return undefined;
60
- var cssStr = Object.entries(props.customCss).reduce(function (acc, _a) {
61
- var key = _a[0], value = _a[1];
62
- return acc + "".concat(key, " {").concat(CSSPropertiesToComponent(value), "}\n");
63
- }, '');
64
- return Buffer.from(cssStr).toString('base64');
65
- }, [props.customCss]);
66
- var iframeProps = (0, react_1.useMemo)(function () {
67
- return tslib_1.__assign(tslib_1.__assign({}, props), { walletPubkey: props.walletPubkey, route: "/checkout-form/".concat(props.merchantId), routePrefix: 'form', merchantCss: merchantCss, transaction: undefined });
68
- }, [merchantCss, props]);
69
- var messageHandlers = (0, react_1.useMemo)(function () {
70
- return {
71
- handleSendTransaction: function () {
72
- throw new Error('Not Supported');
73
- },
74
- handleHeightChange: props.handleHeightChange,
75
- onSuccess: undefined,
76
- };
77
- }, [props]);
78
- return (react_1.default.createElement(CoinflowIFrame_1.CoinflowIFrame, tslib_1.__assign({ ref: iframeRef }, iframeProps, messageHandlers)));
79
- });
80
- function CSSPropertiesToComponent(dict) {
81
- var str = '';
82
- var _loop_1 = function (key, value) {
83
- var clo = '';
84
- key.split('').forEach(function (lt) {
85
- if (lt.toUpperCase() === lt) {
86
- clo += '-' + lt.toLowerCase();
87
- }
88
- else {
89
- clo += lt;
90
- }
91
- });
92
- str += clo + ':' + value + ';';
93
- };
94
- for (var _i = 0, _a = Object.entries(dict); _i < _a.length; _i++) {
95
- var _b = _a[_i], key = _b[0], value = _b[1];
96
- _loop_1(key, value);
97
- }
98
- return str;
99
- }
100
- //# sourceMappingURL=CoinflowCardForm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AAG,IAAI,GAAG,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,GAAG,IAAI,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;QACH,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC;;IATjC,KAA2B,UAAoB,EAApB,KAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAApB,cAAoB,EAApB,IAAoB;QAApC,IAAA,WAAY,EAAX,GAAG,QAAA,EAAE,KAAK,QAAA;gBAAV,GAAG,EAAE,KAAK;KAUrB;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,39 +0,0 @@
1
- import React, { CSSProperties } from 'react';
2
- import { CoinflowBlockchain, CoinflowEnvs } from './common';
3
- export type CoinflowCardTokenResponse = {
4
- last4: string;
5
- type: 'VISA' | 'MSTR' | 'AMEX' | 'DISC';
6
- token: string;
7
- };
8
- export interface CoinflowCardFormProps {
9
- merchantId: string;
10
- walletPubkey?: string;
11
- handleHeightChange?: (height: string) => void;
12
- env: CoinflowEnvs;
13
- inputCss?: CSSProperties;
14
- customCss?: {
15
- [key: string]: CSSProperties;
16
- };
17
- blockchain: CoinflowBlockchain;
18
- }
19
- /**
20
- * Allows merchants to collect card information from their customers in a PCI-compliant way and receive a token for use with the `/api/checkout/token` endpoint.
21
- *
22
- * Usage:
23
- * ```tsx
24
- * const ref = useRef<{getToken(): Promise<{token: string}>}>();
25
- *
26
- * <CoinflowCardForm
27
- * ref={coinflowCardFormRef}
28
- * ...
29
- * />
30
- *
31
- * <button onClick={() => {
32
- * ref.current?.getToken()
33
- * .then(({token}) => console.log(token))
34
- * .catch(e => console.error('GET TOKEN ERROR', e))
35
- * }}>Get Token</button>
36
- *
37
- * ```
38
- */
39
- export declare const CoinflowCardForm: React.ForwardRefExoticComponent<CoinflowCardFormProps & React.RefAttributes<unknown>>;
@@ -1,97 +0,0 @@
1
- import { __assign, __awaiter, __generator } from "tslib";
2
- import React, { forwardRef, useImperativeHandle, useMemo, useRef, } from 'react';
3
- import { CoinflowIFrame } from './CoinflowIFrame';
4
- /**
5
- * Allows merchants to collect card information from their customers in a PCI-compliant way and receive a token for use with the `/api/checkout/token` endpoint.
6
- *
7
- * Usage:
8
- * ```tsx
9
- * const ref = useRef<{getToken(): Promise<{token: string}>}>();
10
- *
11
- * <CoinflowCardForm
12
- * ref={coinflowCardFormRef}
13
- * ...
14
- * />
15
- *
16
- * <button onClick={() => {
17
- * ref.current?.getToken()
18
- * .then(({token}) => console.log(token))
19
- * .catch(e => console.error('GET TOKEN ERROR', e))
20
- * }}>Get Token</button>
21
- *
22
- * ```
23
- */
24
- export var CoinflowCardForm = forwardRef(function (props, ref) {
25
- var iframeRef = useRef();
26
- useImperativeHandle(ref, function () { return ({
27
- getToken: function () {
28
- return __awaiter(this, void 0, void 0, function () {
29
- var methodName, isValid, response;
30
- return __generator(this, function (_a) {
31
- switch (_a.label) {
32
- case 0:
33
- methodName = 'getToken';
34
- if (!iframeRef.current)
35
- throw new Error('Unable to get token');
36
- isValid = function (data) {
37
- try {
38
- var res = JSON.parse(data);
39
- return 'method' in res && res.method === methodName;
40
- }
41
- catch (e) {
42
- return false;
43
- }
44
- };
45
- return [4 /*yield*/, iframeRef.current.sendAndReceiveMessage(methodName, isValid)];
46
- case 1:
47
- response = _a.sent();
48
- return [2 /*return*/, JSON.parse(response).data];
49
- }
50
- });
51
- });
52
- },
53
- }); });
54
- var merchantCss = useMemo(function () {
55
- if (!props.customCss)
56
- return undefined;
57
- var cssStr = Object.entries(props.customCss).reduce(function (acc, _a) {
58
- var key = _a[0], value = _a[1];
59
- return acc + "".concat(key, " {").concat(CSSPropertiesToComponent(value), "}\n");
60
- }, '');
61
- return Buffer.from(cssStr).toString('base64');
62
- }, [props.customCss]);
63
- var iframeProps = useMemo(function () {
64
- return __assign(__assign({}, props), { walletPubkey: props.walletPubkey, route: "/checkout-form/".concat(props.merchantId), routePrefix: 'form', merchantCss: merchantCss, transaction: undefined });
65
- }, [merchantCss, props]);
66
- var messageHandlers = useMemo(function () {
67
- return {
68
- handleSendTransaction: function () {
69
- throw new Error('Not Supported');
70
- },
71
- handleHeightChange: props.handleHeightChange,
72
- onSuccess: undefined,
73
- };
74
- }, [props]);
75
- return (React.createElement(CoinflowIFrame, __assign({ ref: iframeRef }, iframeProps, messageHandlers)));
76
- });
77
- function CSSPropertiesToComponent(dict) {
78
- var str = '';
79
- var _loop_1 = function (key, value) {
80
- var clo = '';
81
- key.split('').forEach(function (lt) {
82
- if (lt.toUpperCase() === lt) {
83
- clo += '-' + lt.toLowerCase();
84
- }
85
- else {
86
- clo += lt;
87
- }
88
- });
89
- str += clo + ':' + value + ';';
90
- };
91
- for (var _i = 0, _a = Object.entries(dict); _i < _a.length; _i++) {
92
- var _b = _a[_i], key = _b[0], value = _b[1];
93
- _loop_1(key, value);
94
- }
95
- return str;
96
- }
97
- //# sourceMappingURL=CoinflowCardForm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CoinflowCardForm.js","sourceRoot":"","sources":["../../src/CoinflowCardForm.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAEZ,UAAU,EACV,mBAAmB,EACnB,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,cAAc,EAAiC,MAAM,kBAAkB,CAAC;AAwBhF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAU,CACxC,UAAC,KAA4B,EAAE,GAAG;IAChC,IAAM,SAAS,GAAG,MAAM,EAAkC,CAAC;IAC3D,mBAAmB,CAAC,GAAG,EAAE,cAAM,OAAA,CAAC;QACxB,QAAQ;;;;;;4BACN,UAAU,GAAG,UAAU,CAAC;4BAC9B,IAAI,CAAC,SAAS,CAAC,OAAO;gCAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;4BACzD,OAAO,GAAG,UA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