@coinflowlabs/react 4.1.2 → 4.2.0

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 +101 -0
  2. package/build/cjs/card-form/CoinflowCardForm.js +129 -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 +77 -0
  8. package/build/cjs/card-form/useCardFormIframe.js +160 -0
  9. package/build/cjs/card-form/useCardFormIframe.js.map +1 -0
  10. package/build/cjs/common/CoinflowLibMessageHandlers.d.ts +13 -3
  11. package/build/cjs/common/CoinflowLibMessageHandlers.js +19 -11
  12. package/build/cjs/common/CoinflowLibMessageHandlers.js.map +1 -1
  13. package/build/cjs/common/CoinflowTypes.d.ts +10 -1
  14. package/build/cjs/common/CoinflowTypes.js +8 -1
  15. package/build/cjs/common/CoinflowTypes.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 +101 -0
  20. package/build/esm/card-form/CoinflowCardForm.js +125 -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 +77 -0
  26. package/build/esm/card-form/useCardFormIframe.js +156 -0
  27. package/build/esm/card-form/useCardFormIframe.js.map +1 -0
  28. package/build/esm/common/CoinflowLibMessageHandlers.d.ts +13 -3
  29. package/build/esm/common/CoinflowLibMessageHandlers.js +19 -11
  30. package/build/esm/common/CoinflowLibMessageHandlers.js.map +1 -1
  31. package/build/esm/common/CoinflowTypes.d.ts +10 -1
  32. package/build/esm/common/CoinflowTypes.js +7 -0
  33. package/build/esm/common/CoinflowTypes.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 -97
  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 -94
  44. package/build/esm/CoinflowCardForm.js.map +0 -1
@@ -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,94 +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 () { throw new Error('Not Supported'); },
69
- handleHeightChange: props.handleHeightChange
70
- };
71
- }, [props]);
72
- return React.createElement(CoinflowIFrame, __assign({ ref: iframeRef }, iframeProps, messageHandlers));
73
- });
74
- function CSSPropertiesToComponent(dict) {
75
- var str = '';
76
- var _loop_1 = function (key, value) {
77
- var clo = '';
78
- key.split('').forEach(function (lt) {
79
- if (lt.toUpperCase() === lt) {
80
- clo += '-' + lt.toLowerCase();
81
- }
82
- else {
83
- clo += lt;
84
- }
85
- });
86
- str += clo + ':' + value + ';';
87
- };
88
- for (var _i = 0, _a = Object.entries(dict); _i < _a.length; _i++) {
89
- var _b = _a[_i], key = _b[0], value = _b[1];
90
- _loop_1(key, value);
91
- }
92
- return str;
93
- }
94
- //# sourceMappingURL=CoinflowCardForm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CoinflowCardForm.js","sourceRoot":"","sources":["../../src/CoinflowCardForm.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAiB,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/F,OAAO,EAAE,cAAc,EAAkC,MAAM,kBAAkB,CAAC;AAmBlF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAU,CAAC,UAAC,KAA4B,EAAE,GAAG;IAC3E,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;4BACz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