Skip to content

Commit

Permalink
feat(lib): added distribution webpack for lib use case (#10)
Browse files Browse the repository at this point in the history
* 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
RatnadeepSimhadri and Ratnadeep Simhadri committed Aug 15, 2022
1 parent 605367e commit c82c2fb
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 8 deletions.
2 changes: 2 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/index.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/index.min.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions dist/module/babel.config.js
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'
};
54 changes: 54 additions & 0 deletions dist/module/component.js
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'
};
32 changes: 32 additions & 0 deletions dist/module/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions dist/module/index.js
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];
});
1 change: 1 addition & 0 deletions dist/module/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";
66 changes: 66 additions & 0 deletions dist/module/util/index.js
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;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"lint": "eslint src/ test/ *.js",
"test": "npm run lint && npm run flow && npm run karma",
"karma": "cross-env NODE_ENV=test babel-node $(npm bin)/karma start",
"babel": "babel src/ --out-dir dist/module",
"webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress",
"build": "npm run test && npm run babel && npm run webpack",
"prepare": "husky install",
"release": "standard-version",
"postrelease": "git push && git push --follow-tags && npm publish"
Expand Down
4 changes: 2 additions & 2 deletions src/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* @flow */

export * from './component';
export * from './util';
15 changes: 9 additions & 6 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ import { getLocale } from '@paypal/sdk-client/src';
import type { ContentConfig } from '../types';
import * as LegalConstants from '../constants';

export function getBuyerCountryFromFundingSource(fundingSource : string) : string {

const buyerCountry = LegalConstants[fundingSource]?.BUYER_COUNTRY || '';
return buyerCountry;
}

export function buildContent(options : ContentConfig) : string {
let content = '';
const paypalPolicyLink = `https://www.paypal.com/${ options.buyerCountry }/webapps/mpp/ua/privacy-full?locale.x=${ options.legalLocale }`;
const buyerCountry = options.buyerCountry || getBuyerCountryFromFundingSource(options.fundingSource);
const legalLocale = options.legalLocale || LegalConstants[options.fundingSource]?.DEFAULT_LOCALE;

const paypalPolicyLink = `https://www.paypal.com/${ buyerCountry }/webapps/mpp/ua/privacy-full?locale.x=${ legalLocale }`;
if (options.errorCode) {
content =
LegalConstants[options.fundingSource]?.ERROR_MESSAGES?.[options.errorCode]?.[
Expand All @@ -34,11 +42,6 @@ export function buildContent(options : ContentConfig) : string {
return content || '';
}

export function getBuyerCountryFromFundingSource(fundingSource : string) : string {

const buyerCountry = LegalConstants[fundingSource]?.BUYER_COUNTRY || '';
return buyerCountry;
}

/**
* This function defaults the legal text language locale based on
Expand Down
27 changes: 27 additions & 0 deletions webpack.config.js
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

0 comments on commit c82c2fb

Please sign in to comment.