@paypal/checkout-components 5.0.218 → 5.0.221
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/CHANGELOG.md +18 -0
- package/__sdk__.js +1 -0
- package/dist/button.js +1 -1
- package/package.json +7 -7
- package/src/funding/config.js +1 -0
- package/src/lib/index.js +1 -0
- package/src/lib/perceived-latency-instrumentation.js +61 -0
- package/src/zoid/buttons/component.jsx +33 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paypal/checkout-components",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.221",
|
|
4
4
|
"description": "PayPal Checkout components, for integrating checkout products.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -86,17 +86,17 @@
|
|
|
86
86
|
"serve": "^13.0.0"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@paypal/common-components": "^1.0.27",
|
|
90
|
-
"@paypal/funding-components": "^1.0.27",
|
|
91
|
-
"@paypal/sdk-client": "^4.0.166",
|
|
92
|
-
"@paypal/sdk-constants": "^1.0.107",
|
|
93
|
-
"@paypal/sdk-logos": "^1.0.45",
|
|
94
89
|
"@krakenjs/belter": "^2.0.0",
|
|
95
90
|
"@krakenjs/cross-domain-utils": "^3.0.0",
|
|
96
91
|
"@krakenjs/jsx-pragmatic": "^3",
|
|
97
92
|
"@krakenjs/post-robot": "^11.0.0",
|
|
98
93
|
"@krakenjs/zalgo-promise": "^2.0.0",
|
|
99
|
-
"@krakenjs/zoid": "^10.0.0"
|
|
94
|
+
"@krakenjs/zoid": "^10.0.0",
|
|
95
|
+
"@paypal/common-components": "^1.0.27",
|
|
96
|
+
"@paypal/funding-components": "^1.0.27",
|
|
97
|
+
"@paypal/sdk-client": "^4.0.166",
|
|
98
|
+
"@paypal/sdk-constants": "^1.0.119",
|
|
99
|
+
"@paypal/sdk-logos": "^1.0.45"
|
|
100
100
|
},
|
|
101
101
|
"lint-staged": {
|
|
102
102
|
"*.sh": "prettier --write"
|
package/src/funding/config.js
CHANGED
|
@@ -57,6 +57,7 @@ export function getFundingConfig() : { [$Values<typeof FUNDING>] : ?FundingSourc
|
|
|
57
57
|
[ FUNDING.WECHATPAY ]: (!__TREE_SHAKE__ || (typeof __FUNDING_ELIGIBILITY__.wechatpay !== 'undefined' && __FUNDING_ELIGIBILITY__.wechatpay.eligible)) ? getWechatpayConfig() : null,
|
|
58
58
|
[ FUNDING.OXXO ]: (!__TREE_SHAKE__ || (typeof __FUNDING_ELIGIBILITY__.oxxo !== 'undefined' && __FUNDING_ELIGIBILITY__.oxxo.eligible)) ? getOxxoConfig() : null,
|
|
59
59
|
[ FUNDING.BOLETO ]: (!__TREE_SHAKE__ || (typeof __FUNDING_ELIGIBILITY__.boleto !== 'undefined' && __FUNDING_ELIGIBILITY__.boleto.eligible)) ? getBoletoConfig() : null,
|
|
60
|
+
[ FUNDING.BOLETOBANCARIO ]: (!__TREE_SHAKE__ || (typeof __FUNDING_ELIGIBILITY__.boletobancario !== 'undefined' && __FUNDING_ELIGIBILITY__.boletobancario.eligible)) ? getBoletoConfig() : null,
|
|
60
61
|
[ FUNDING.MAXIMA ]: (!__TREE_SHAKE__ || (typeof __FUNDING_ELIGIBILITY__.maxima !== 'undefined' && __FUNDING_ELIGIBILITY__.maxima.eligible)) ? getMaximaConfig() : null,
|
|
61
62
|
[ FUNDING.MERCADOPAGO ]: (!__TREE_SHAKE__ || (typeof __FUNDING_ELIGIBILITY__.mercadopago !== 'undefined' && __FUNDING_ELIGIBILITY__.mercadopago.eligible)) ? getMercadopagoConfig() : null,
|
|
62
63
|
[ FUNDING.MULTIBANCO ]: (!__TREE_SHAKE__ || (typeof __FUNDING_ELIGIBILITY__.multibanco !== 'undefined' && __FUNDING_ELIGIBILITY__.multibanco.eligible)) ? getMultibancoConfig() : null
|
package/src/lib/index.js
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
type LogLatencyInstrumentationPhaseParams = {|
|
|
4
|
+
buttonSessionID : string,
|
|
5
|
+
phase : string
|
|
6
|
+
|};
|
|
7
|
+
|
|
8
|
+
type InstrumentationPayload = {|
|
|
9
|
+
comp? : Object,
|
|
10
|
+
chunk? : Object,
|
|
11
|
+
query? : Object
|
|
12
|
+
|};
|
|
13
|
+
|
|
14
|
+
function getNavigationTimeOrigin() : number {
|
|
15
|
+
if (window.performance) {
|
|
16
|
+
const hrSyncPoint = performance.now();
|
|
17
|
+
const unixSyncPoint = new Date().getTime();
|
|
18
|
+
return window.performance.timeOrigin || window.performance.timing.navigationStart || (unixSyncPoint - hrSyncPoint);
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error('window.performance not supported');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getStartTimeFromMark({ buttonSessionID, phase } : LogLatencyInstrumentationPhaseParams) : number {
|
|
25
|
+
if (window.performance) {
|
|
26
|
+
return performance.getEntriesByName(`${ buttonSessionID }_${ phase }`).pop().startTime;
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error('window.performance not supported');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* To Track time spent in each phase(cdn download, chunks download, etc)
|
|
33
|
+
logLatencyInstrumentationPhase({
|
|
34
|
+
buttonID: buttonId,
|
|
35
|
+
phase: 'html_body'
|
|
36
|
+
})
|
|
37
|
+
logLatencyInstrumentationPhase({
|
|
38
|
+
buttonID: buttonId,
|
|
39
|
+
phase: 'html_body'
|
|
40
|
+
})
|
|
41
|
+
*/
|
|
42
|
+
export const logLatencyInstrumentationPhase = ({ buttonSessionID, phase } : LogLatencyInstrumentationPhaseParams) => {
|
|
43
|
+
if (window.performance && window.performance.mark) {
|
|
44
|
+
window.performance.mark(`${ buttonSessionID }_${ phase }`);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const prepareInstrumentationPayload = (buttonSessionID : string) : InstrumentationPayload => {
|
|
49
|
+
const timeOrigin = getNavigationTimeOrigin();
|
|
50
|
+
const renderStartTime = getStartTimeFromMark({ buttonSessionID, phase: 'buttons-first-render' });
|
|
51
|
+
const renderEndTime = getStartTimeFromMark({ buttonSessionID, phase: 'buttons-first-render-end' });
|
|
52
|
+
return {
|
|
53
|
+
comp: {
|
|
54
|
+
'first-render': {
|
|
55
|
+
start: timeOrigin + renderStartTime,
|
|
56
|
+
tt: renderEndTime - renderStartTime
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
@@ -8,12 +8,18 @@ import { getLogger, getLocale, getClientID, getEnv, getIntent, getCommit, getVau
|
|
|
8
8
|
getUserIDToken, getClientMetadataID, getAmount, getEnableFunding, getStorageID, getUserExperienceFlow, getMerchantRequestedPopupsDisabled, getVersion } from '@paypal/sdk-client/src';
|
|
9
9
|
import { rememberFunding, getRememberedFunding, getRefinedFundingEligibility } from '@paypal/funding-components/src';
|
|
10
10
|
import { ZalgoPromise } from '@krakenjs/zalgo-promise/src';
|
|
11
|
-
import { create, type ZoidComponent } from '@krakenjs/zoid/src';
|
|
11
|
+
import { create, EVENT, type ZoidComponent } from '@krakenjs/zoid/src';
|
|
12
12
|
import { uniqueID, memoize, isApplePaySupported, supportsPopups as userAgentSupportsPopups, noop, isLocalStorageEnabled } from '@krakenjs/belter/src';
|
|
13
13
|
import { FUNDING, FUNDING_BRAND_LABEL, QUERY_BOOL, ENV, FPTI_KEY } from '@paypal/sdk-constants/src';
|
|
14
14
|
import { node, dom } from '@krakenjs/jsx-pragmatic/src';
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
getSessionID,
|
|
18
|
+
storageState,
|
|
19
|
+
sessionState,
|
|
20
|
+
logLatencyInstrumentationPhase,
|
|
21
|
+
prepareInstrumentationPayload
|
|
22
|
+
} from '../../lib';
|
|
17
23
|
import { normalizeButtonStyle, type ButtonProps } from '../../ui/buttons/props';
|
|
18
24
|
import { isFundingEligible } from '../../funding';
|
|
19
25
|
import { EXPERIENCE } from '../../constants';
|
|
@@ -44,7 +50,7 @@ export const getButtonsComponent : () => ButtonsComponent = memoize(() => {
|
|
|
44
50
|
|
|
45
51
|
logger: getLogger(),
|
|
46
52
|
|
|
47
|
-
prerenderTemplate: ({ state, props, doc }) => {
|
|
53
|
+
prerenderTemplate: ({ state, props, doc, event }) => {
|
|
48
54
|
const { buttonSessionID } = props;
|
|
49
55
|
|
|
50
56
|
if (!isLocalStorageEnabled()) {
|
|
@@ -56,6 +62,28 @@ export const getButtonsComponent : () => ButtonsComponent = memoize(() => {
|
|
|
56
62
|
});
|
|
57
63
|
}
|
|
58
64
|
|
|
65
|
+
event.on(EVENT.PRERENDERED, () => {
|
|
66
|
+
// CPL stands for Consumer Perceived Latency
|
|
67
|
+
logLatencyInstrumentationPhase({ buttonSessionID, phase: 'buttons-first-render-end' });
|
|
68
|
+
try {
|
|
69
|
+
const cplPhases = prepareInstrumentationPayload(buttonSessionID);
|
|
70
|
+
const cplLatencyMetrics = {
|
|
71
|
+
[FPTI_KEY.STATE]: 'CPL_LATENCY_METRICS',
|
|
72
|
+
[FPTI_KEY.TRANSITION]: 'process_client_metrics',
|
|
73
|
+
[FPTI_KEY.CONTEXT_ID]: buttonSessionID,
|
|
74
|
+
[FPTI_KEY.PAGE]: 'main:xo:paypal-components:smart-payment-buttons',
|
|
75
|
+
[FPTI_KEY.CPL_COMP_METRICS]: JSON.stringify(cplPhases?.comp || {})
|
|
76
|
+
};
|
|
77
|
+
getLogger().info('CPL_LATENCY_METRICS_FIRST_RENDER').track(cplLatencyMetrics);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
getLogger().info('button_render_CPL_instrumentation_log_error').track({
|
|
80
|
+
err: err.message || 'CPL_LOG_PHASE_ERROR',
|
|
81
|
+
details: err.details,
|
|
82
|
+
stack: JSON.stringify(err.stack || err)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
59
87
|
return (
|
|
60
88
|
<PrerenderedButtons
|
|
61
89
|
nonce={ props.nonce }
|
|
@@ -275,6 +303,8 @@ export const getButtonsComponent : () => ButtonsComponent = memoize(() => {
|
|
|
275
303
|
required: false,
|
|
276
304
|
default: () => noop,
|
|
277
305
|
decorate: ({ props, value = noop }) => {
|
|
306
|
+
logLatencyInstrumentationPhase({ buttonSessionID: props.buttonSessionID, phase: 'buttons-first-render' });
|
|
307
|
+
|
|
278
308
|
return (...args) => {
|
|
279
309
|
const { fundingSource } = props;
|
|
280
310
|
const venmoExperiment = createVenmoExperiment();
|