@fat-zebra/sdk 2.0.1-beta.1 → 2.0.1-beta.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.
- package/dist/hpp/hpp.js +5 -0
- package/dist/logging/instrument.d.ts +8 -4
- package/dist/logging/instrument.js +14 -5
- package/dist/logging/logMethod.d.ts +4 -4
- package/dist/logging/logMethod.js +1 -0
- package/dist/react/useFatZebra.js +9 -2
- package/dist/three_d_secure/utility/device-data-collection.d.ts +1 -0
- package/dist/three_d_secure/utility/device-data-collection.js +22 -3
- package/package.json +1 -1
package/dist/hpp/hpp.js
CHANGED
|
@@ -13,6 +13,8 @@ import * as util from '../shared/util';
|
|
|
13
13
|
import { setTransactionReference } from "../logging/logger-context";
|
|
14
14
|
import { logMethod } from "../logging/logMethod";
|
|
15
15
|
import ThreeDSecure from "../three_d_secure";
|
|
16
|
+
import env from "../shared/env";
|
|
17
|
+
import { configureLogger } from "../logging/instrument";
|
|
16
18
|
const HPP_DEFAULT_OPTIONS = {
|
|
17
19
|
enableSca: false,
|
|
18
20
|
hideButton: false,
|
|
@@ -34,6 +36,9 @@ class Hpp {
|
|
|
34
36
|
channel: 'sca',
|
|
35
37
|
target: this.iframe
|
|
36
38
|
});
|
|
39
|
+
configureLogger({
|
|
40
|
+
baseUrl: env[process.env.API_ENV].payNowUrl
|
|
41
|
+
});
|
|
37
42
|
}
|
|
38
43
|
setListenersAndEmitReady() {
|
|
39
44
|
const message = {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
type LogOptions = {
|
|
2
|
-
endpoint?: string;
|
|
3
|
-
mapArgs?: (args:
|
|
1
|
+
export type LogOptions<A extends unknown[]> = {
|
|
2
|
+
endpoint?: string | ((...args: A) => string);
|
|
3
|
+
mapArgs?: (args: A) => unknown;
|
|
4
4
|
enabled?: () => boolean;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
type LoggerConfig = {
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function configureLogger(config: LoggerConfig): void;
|
|
10
|
+
export declare function instrumentFunction<A extends unknown[], R>(methodName: string, fn: (...args: A) => R, opts?: LogOptions<A>): (...args: A) => R;
|
|
7
11
|
export {};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { getLoggerUsername, getTransactionReference } from "./logger-context";
|
|
3
|
+
let loggerConfig = {};
|
|
4
|
+
export function configureLogger(config) {
|
|
5
|
+
loggerConfig = config;
|
|
6
|
+
}
|
|
3
7
|
function defaultEndpoint() {
|
|
4
|
-
return
|
|
8
|
+
return loggerConfig.baseUrl
|
|
9
|
+
? `${loggerConfig.baseUrl}/log_sdk`
|
|
10
|
+
: `${process.env.PAYNOW_BASE_URL}/log_sdk`;
|
|
5
11
|
}
|
|
6
12
|
function sendLog(endpoint, payload) {
|
|
7
13
|
try {
|
|
@@ -20,12 +26,15 @@ function sendLog(endpoint, payload) {
|
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
28
|
export function instrumentFunction(methodName, fn, opts = {}) {
|
|
23
|
-
var _a, _b
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const mapArgs = (_c = opts.mapArgs) !== null && _c !== void 0 ? _c : ((a) => a);
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const enabled = (_a = opts.enabled) !== null && _a !== void 0 ? _a : (() => true);
|
|
31
|
+
const mapArgs = (_b = opts.mapArgs) !== null && _b !== void 0 ? _b : ((a) => a);
|
|
27
32
|
return function instrumented(...args) {
|
|
33
|
+
var _a;
|
|
28
34
|
if (enabled()) {
|
|
35
|
+
const endpoint = typeof opts.endpoint === "function"
|
|
36
|
+
? opts.endpoint(...args)
|
|
37
|
+
: (_a = opts.endpoint) !== null && _a !== void 0 ? _a : defaultEndpoint();
|
|
29
38
|
const payload = {
|
|
30
39
|
username: getLoggerUsername(),
|
|
31
40
|
reference: getTransactionReference(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
type LogOptions = {
|
|
2
|
-
endpoint?: string;
|
|
3
|
-
mapArgs?: (args:
|
|
1
|
+
type LogOptions<A extends unknown[]> = {
|
|
2
|
+
endpoint?: string | ((args: A) => string);
|
|
3
|
+
mapArgs?: (args: A) => unknown;
|
|
4
4
|
enabled?: () => boolean;
|
|
5
5
|
};
|
|
6
|
-
export declare function logMethod(opts?: LogOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
6
|
+
export declare function logMethod(opts?: LogOptions<unknown[]>): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
7
7
|
export {};
|
|
@@ -35,6 +35,7 @@ export function logMethod(opts = {}) {
|
|
|
35
35
|
const original = descriptor.value;
|
|
36
36
|
if (typeof original !== "function") {
|
|
37
37
|
console.error(`@logMethod can only decorate methods (${propertyKey})`);
|
|
38
|
+
return descriptor;
|
|
38
39
|
}
|
|
39
40
|
descriptor.value = instrumentFunction(propertyKey, original, Object.assign(Object.assign({}, opts), { mapArgs: (_a = opts.mapArgs) !== null && _a !== void 0 ? _a : ((args) => args.map((a) => {
|
|
40
41
|
if (!a || typeof a !== "object")
|
|
@@ -5,8 +5,12 @@ import Sca from "../sca";
|
|
|
5
5
|
import GatewayClient from "../shared/api-gateway-client";
|
|
6
6
|
import { generateVerifyURL } from "./verifyUrl";
|
|
7
7
|
import useMessage from "./useMessage";
|
|
8
|
-
import { instrumentFunction } from "../logging/instrument";
|
|
9
|
-
|
|
8
|
+
import { configureLogger, instrumentFunction } from "../logging/instrument";
|
|
9
|
+
import env from "../shared/env";
|
|
10
|
+
const logUseFatZebra = instrumentFunction("useFatZebra", (meta) => meta, {
|
|
11
|
+
mapArgs: ([meta]) => meta,
|
|
12
|
+
endpoint: (meta) => `${env[meta.environment].payNowUrl}/log_sdk`,
|
|
13
|
+
});
|
|
10
14
|
const useFatZebra = ({ config, handlers, cardToken }) => {
|
|
11
15
|
const { options, accessToken, paymentIntent, username } = config;
|
|
12
16
|
const sca = useMemo(() => {
|
|
@@ -25,6 +29,9 @@ const useFatZebra = ({ config, handlers, cardToken }) => {
|
|
|
25
29
|
config
|
|
26
30
|
});
|
|
27
31
|
useEffect(() => {
|
|
32
|
+
configureLogger({
|
|
33
|
+
baseUrl: env[config.environment].payNowUrl
|
|
34
|
+
});
|
|
28
35
|
logUseFatZebra({
|
|
29
36
|
environment: config.environment,
|
|
30
37
|
reference: config.paymentIntent.payment.reference,
|
|
@@ -14,6 +14,7 @@ export default class DeviceDataCollection {
|
|
|
14
14
|
static listenDataCollectionResponse(environment: Environment): void;
|
|
15
15
|
private static hasEmittedProfileReady;
|
|
16
16
|
private static handleDataCollectionResponse;
|
|
17
|
+
private static handleCollectionResponse;
|
|
17
18
|
static collectDeviceData(): DeviceDataType;
|
|
18
19
|
static setIframeUrl(url: string, jwt: string): void;
|
|
19
20
|
static getForm(): HTMLFormElement | null;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
1
7
|
import { PublicEvent } from "../../shared/types";
|
|
2
8
|
import { emit } from "../../shared/event-manager";
|
|
3
9
|
import env from "../../shared/env";
|
|
10
|
+
import { logMethod } from "../../logging/logMethod";
|
|
4
11
|
class DeviceDataCollection {
|
|
5
12
|
// Create elements if they don't already exist
|
|
6
13
|
createIframe() {
|
|
@@ -45,15 +52,19 @@ class DeviceDataCollection {
|
|
|
45
52
|
return;
|
|
46
53
|
if (this.hasEmittedProfileReady)
|
|
47
54
|
return;
|
|
55
|
+
this.handleCollectionResponse(event);
|
|
56
|
+
}
|
|
57
|
+
static handleCollectionResponse(event) {
|
|
48
58
|
const response = JSON.parse(event.data);
|
|
49
59
|
if (response["MessageType"] == "profile.completed") {
|
|
60
|
+
this.hasEmittedProfileReady = true;
|
|
50
61
|
emit(PublicEvent.DEVICE_PROFILE_READY_THREE_D_SECURE_EVENT, { message: null, data: null });
|
|
51
62
|
}
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
else if (response["Status"] == false) {
|
|
64
|
+
this.hasEmittedProfileReady = true;
|
|
65
|
+
// Still proceed, even if status is false (as per recommendations from cybersource support team.
|
|
54
66
|
emit(PublicEvent.DEVICE_PROFILE_READY_THREE_D_SECURE_EVENT, { message: null, data: null });
|
|
55
67
|
}
|
|
56
|
-
this.hasEmittedProfileReady = true;
|
|
57
68
|
}
|
|
58
69
|
static collectDeviceData() {
|
|
59
70
|
var _a, _b, _c, _d;
|
|
@@ -117,3 +128,11 @@ DeviceDataCollection.FORM_ID = "cardinal_collection_form";
|
|
|
117
128
|
DeviceDataCollection.INPUT_ID = "cardinal_collection_form_input";
|
|
118
129
|
DeviceDataCollection.hasEmittedProfileReady = false;
|
|
119
130
|
export default DeviceDataCollection;
|
|
131
|
+
__decorate([
|
|
132
|
+
logMethod({
|
|
133
|
+
mapArgs: (args) => {
|
|
134
|
+
const params = args[0]; // grab the first argument.
|
|
135
|
+
return JSON.parse(params.data);
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
], DeviceDataCollection, "handleCollectionResponse", null);
|