-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): added distribution webpack for lib use case (#10)
* feat(dist): added distribution webpack for lib usecase feat(dist): added distribution webpack for lib usecase - II fix(legal): text selection logic feat(build): latest build * chore: change boleto content * chore: latest build Co-authored-by: Ratnadeep Simhadri <rsimhadri@paypal.com>
- Loading branch information
1 parent
605367e
commit c82c2fb
Showing
15 changed files
with
226 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
|
||
// eslint-disable-next-line import/no-commonjs | ||
module.exports = { | ||
extends: 'grumbler-scripts/config/.babelrc-browser' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
|
||
exports.__esModule = true; | ||
exports.Legal = Legal; | ||
|
||
var _src = require("@paypal/sdk-client/src"); | ||
|
||
var _util = require("./util"); | ||
|
||
function Legal(options) { | ||
return { | ||
render(container) { | ||
if (!options.fundingSource) { | ||
throw new Error(`Expected options.fundingSource`); | ||
} | ||
|
||
const legalLocale = (0, _util.getLegalLocale)(); | ||
const buyerCountry = (0, _util.getBuyerCountryFromFundingSource)(options.fundingSource); | ||
const contentInput = { ...options, | ||
legalLocale, | ||
buyerCountry | ||
}; | ||
const metadata = { | ||
locale: legalLocale, | ||
buyerCountry | ||
}; | ||
const el = document.querySelector(container); | ||
|
||
if (!el) { | ||
throw new Error(`Can not find element: ${container}`); | ||
} | ||
|
||
el.innerHTML = (0, _util.buildContent)(contentInput); | ||
(0, _src.getLogger)().info(JSON.stringify(metadata)); | ||
(0, _src.getLogger)().info('Legal Component Loaded').track({ | ||
[_util.FPTI_KEY.CLIENT_ID]: (0, _src.getClientID)(), | ||
[_util.FPTI_KEY.PAGE_TYPE]: options.fundingSource | ||
}); | ||
} | ||
|
||
}; | ||
} | ||
|
||
Legal.FUNDING = { | ||
PAY_UPON_INVOICE: 'PayUponInvoice', | ||
BOLETO: 'boleto', | ||
BOLETOBANCARIO: 'boletobancario' | ||
}; | ||
/* Export Constants for Referencing by the Client*/ | ||
|
||
Legal.ERROR_CODE = { | ||
PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED: 'PAYMENT_SOURCE_INFO_CANNOT_BE_VERIFIED', | ||
PAYMENT_SOURCE_DECLINED_BY_PROCESSOR: 'PAYMENT_SOURCE_DECLINED_BY_PROCESSOR' | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
|
||
exports.__esModule = true; | ||
|
||
var _component = require("./component"); | ||
|
||
Object.keys(_component).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _component[key]) return; | ||
exports[key] = _component[key]; | ||
}); | ||
|
||
var _util = require("./util"); | ||
|
||
Object.keys(_util).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _util[key]) return; | ||
exports[key] = _util[key]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"use strict"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use strict"; | ||
|
||
exports.__esModule = true; | ||
exports.FPTI_KEY = void 0; | ||
exports.buildContent = buildContent; | ||
exports.getBuyerCountryFromFundingSource = getBuyerCountryFromFundingSource; | ||
exports.getLegalLocale = getLegalLocale; | ||
|
||
var _src = require("@paypal/sdk-client/src"); | ||
|
||
var LegalConstants = _interopRequireWildcard(require("../constants")); | ||
|
||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
|
||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
|
||
/* eslint-disable eslint-comments/disable-enable-pair */ | ||
|
||
/* eslint-disable import/namespace */ | ||
|
||
/* eslint-disable import/no-namespace */ | ||
function getBuyerCountryFromFundingSource(fundingSource) { | ||
var _LegalConstants$fundi; | ||
|
||
const buyerCountry = ((_LegalConstants$fundi = LegalConstants[fundingSource]) == null ? void 0 : _LegalConstants$fundi.BUYER_COUNTRY) || ''; | ||
return buyerCountry; | ||
} | ||
|
||
function buildContent(options) { | ||
var _LegalConstants$optio; | ||
|
||
let content = ''; | ||
const buyerCountry = options.buyerCountry || getBuyerCountryFromFundingSource(options.fundingSource); | ||
const legalLocale = options.legalLocale || ((_LegalConstants$optio = LegalConstants[options.fundingSource]) == null ? void 0 : _LegalConstants$optio.DEFAULT_LOCALE); | ||
const paypalPolicyLink = `https://www.paypal.com/${buyerCountry}/webapps/mpp/ua/privacy-full?locale.x=${legalLocale}`; | ||
|
||
if (options.errorCode) { | ||
var _LegalConstants$optio2, _LegalConstants$optio3, _LegalConstants$optio4, _LegalConstants$optio5, _LegalConstants$optio6, _LegalConstants$optio7, _LegalConstants$optio8; | ||
|
||
content = ((_LegalConstants$optio2 = LegalConstants[options.fundingSource]) == null ? void 0 : (_LegalConstants$optio3 = _LegalConstants$optio2.ERROR_MESSAGES) == null ? void 0 : (_LegalConstants$optio4 = _LegalConstants$optio3[options.errorCode]) == null ? void 0 : _LegalConstants$optio4[options.legalLocale]) || ((_LegalConstants$optio5 = LegalConstants[options.fundingSource]) == null ? void 0 : (_LegalConstants$optio6 = _LegalConstants$optio5.ERROR_MESSAGES) == null ? void 0 : (_LegalConstants$optio7 = _LegalConstants$optio6[options.errorCode]) == null ? void 0 : _LegalConstants$optio7[(_LegalConstants$optio8 = LegalConstants[options.fundingSource]) == null ? void 0 : _LegalConstants$optio8.DEFAULT_LOCALE]); | ||
} else { | ||
var _LegalConstants$optio9, _LegalConstants$optio10, _LegalConstants$optio11, _LegalConstants$optio12, _LegalConstants$optio13, _LegalConstants$optio14, _LegalConstants$optio15; | ||
|
||
content = ((_LegalConstants$optio9 = LegalConstants[options.fundingSource]) == null ? void 0 : (_LegalConstants$optio10 = _LegalConstants$optio9.LEGAL_TEXT) == null ? void 0 : (_LegalConstants$optio11 = _LegalConstants$optio10[options.legalLocale]) == null ? void 0 : _LegalConstants$optio11.call(_LegalConstants$optio10, paypalPolicyLink)) || ((_LegalConstants$optio12 = LegalConstants[options.fundingSource]) == null ? void 0 : (_LegalConstants$optio13 = _LegalConstants$optio12.LEGAL_TEXT) == null ? void 0 : (_LegalConstants$optio14 = _LegalConstants$optio13[(_LegalConstants$optio15 = LegalConstants[options.fundingSource]) == null ? void 0 : _LegalConstants$optio15.DEFAULT_LOCALE]) == null ? void 0 : _LegalConstants$optio14.call(_LegalConstants$optio13, paypalPolicyLink)); | ||
} | ||
|
||
return content || ''; | ||
} | ||
/** | ||
* This function defaults the legal text language locale based on | ||
* payment option and overrides based on the user preferences | ||
* @param {*} fundingOption | ||
* @returns | ||
*/ | ||
|
||
|
||
function getLegalLocale() { | ||
const locale = (0, _src.getLocale)(); | ||
return `${locale.lang}-${locale.country}`; | ||
} | ||
|
||
const FPTI_KEY = { | ||
CLIENT_ID: 'client_id', | ||
PAGE_TYPE: 'legal_component' | ||
}; | ||
exports.FPTI_KEY = FPTI_KEY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* @flow */ | ||
|
||
export * from './component'; | ||
export * from './util'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-disable eslint-comments/disable-enable-pair */ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
|
||
/* eslint import/no-nodejs-modules: off */ | ||
|
||
|
||
import { getWebpackConfig } from '@krakenjs/grumbler-scripts/config/webpack.config'; | ||
|
||
const FILE_NAME = 'index'; | ||
const MODULE_NAME = 'paypal-legal-components'; | ||
|
||
export const WEBPACK_CONFIG = getWebpackConfig({ | ||
filename: `${ FILE_NAME }.js`, | ||
modulename: MODULE_NAME | ||
}); | ||
|
||
export const WEBPACK_CONFIG_MIN = getWebpackConfig({ | ||
filename: `${ FILE_NAME }.min.js`, | ||
modulename: MODULE_NAME, | ||
minify: true, | ||
vars: { | ||
__MIN__: true | ||
} | ||
}); | ||
|
||
|
||
export default [ WEBPACK_CONFIG, WEBPACK_CONFIG_MIN ]; // eslint-disable-line import/no-default-export |