@payyo/ptp-js 0.2.0 → 0.2.1
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/README.doc.md +20 -8
- package/package.json +1 -1
- package/dist/form/v1.js +0 -2
- package/dist/form/v1.js.map +0 -1
package/README.doc.md
CHANGED
|
@@ -68,15 +68,27 @@ as well as other integrators.
|
|
|
68
68
|
## NPM package publishing
|
|
69
69
|
|
|
70
70
|
To make the library available to the public and used in other Payyo projects and other user you need to publish it to NPM.
|
|
71
|
-
We have the NPM account registered to `developers@payyo.ch` email and organization `payyo` defined there.
|
|
72
|
-
package to NPM you need to execute the following commands:
|
|
71
|
+
We have the NPM account registered to `developers@payyo.ch` email and organization `payyo` defined there.
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
2. npm publish --access public
|
|
73
|
+
### Init the package
|
|
76
74
|
|
|
75
|
+
This needs to be run once when package is created or renamed:
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
```shell
|
|
78
|
+
npm init --scope=<your_org_name>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For example:
|
|
82
|
+
|
|
83
|
+
```shell
|
|
84
|
+
npm init --scope=payyo
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The command will create a `package.json` file with the provided package details.
|
|
88
|
+
|
|
89
|
+
### Publish NPM package
|
|
90
|
+
|
|
91
|
+
Run the following commands to publish the package to NPM and make it public:
|
|
82
92
|
|
|
93
|
+
1. `make npmlogin` and provide your credentials
|
|
94
|
+
2. `make publish` to publish the package
|
package/package.json
CHANGED
package/dist/form/v1.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
(()=>{var e={415:e=>{e.exports=function(e){const t={},r={},n=[],o={},s=i();let a=null;function i(){return Math.random().toString(36).substr(2,9)}function l(){if(e.debug&&window.console){const e=Array.prototype.slice.call(arguments);e.unshift("[PTP FORM]"),console.log.apply(console,e)}}function d(t){const r=t.container,o=t.iFrameName,a={id:o,name:o,class:o,src:e.iframeUri+"?"+new URLSearchParams({form_id:s,field_name:t.fieldName,field_names:n,placeholder:t.placeholder,input_type:t.inputType,debug:e.debug?"1":"0"}).toString(),frameborder:"0",scrolling:"no",style:"width: 100%; height: 100%"},i=document.createElement("iframe");for(Object.keys(a).forEach((function(e){i.setAttribute(e,a[e])}));r.hasChildNodes();)r.removeChild(r.lastChild);r.appendChild(i),t.iframe=i[0]}function c(e,t={}){const n={params:t,type:e,formId:s,messageId:null};return new Promise((t=>{const s=e+":"+i();o[s]=t,n.messageId=s,l("send message",n),window.frames[r[a].iFrameName].postMessage(n,"*")}))}t.init=function(e){for(let t in e){if(!e.hasOwnProperty(t))return;let o=e[t],a=o.container;"string"==typeof a&&(a=document.getElementById(a)),r[t]={fieldName:t,iFrameName:"ptp-field-iframe-"+s+"-"+t,container:a,placeholder:o.placeholder||"",inputType:o.inputType||"text",isReady:!1},n.push(t)}a=n[0];for(let e=0;e<n.length;e++)d(r[n[e]])};const f={};function m(e){const n=e.data;if(s!==n.formId)return;l(`message received of type "${n.type}"`,n);const a={fieldReady:e=>{if(void 0===r[e.fieldName])return;r[e.fieldName].isReady=!0;Object.keys(r).map((e=>r[e].isReady)).reduce(((e,t)=>e&&t),!0)&&u("ready")},fieldChanged:function(e){u("change",e)}},i=n.messageId,d=o[i];if(void 0!==d)delete o[i],d.apply(t,[n.response]);else{const e=a[n.type];e&&e.apply(t,[n.response])}}function u(){const e=Array.prototype.slice.call(arguments),t=e.shift(),r=f[t];r?(l(`emit event "${t}"`,e),r.apply(null,e)):l(`no handler for event "${t}"`,e)}function p(){for(let[,e]of Object.entries(r)){const t=window.frames[e.iFrameName];t.postMessage({type:"checkFocus"},"*")}}return t.onChange=function(e){f.change=e},t.onReady=function(e){f.ready=e},t.validate=function(){return c("validateRequest")},t.submit=function(e){return c("submitRequest",{params:e||{},browserDetails:{browserUserAgent:navigator.userAgent,browserJavaEnabled:navigator.javaEnabled(),browserLanguage:navigator.language,browserColorDepth:screen.colorDepth,browserScreenHeight:screen.height,browserScreenWidth:screen.width,browserTZ:(new Date).getTimezoneOffset()}}).then((e=>e.success?Promise.resolve(e.result):Promise.reject({error:e.error,error_details:e.error_details})))},t.focus=function(e){const t=r[e]||null;t&&window.frames[t.iFrameName].focus()},t.setStyle=function(e,t,n){r[e]&&window.frames[r[e].iFrameName].postMessage({type:"setStyle",params:{selector:t,rules:n}},"*")},window.addEventListener("message",m,!1),t.destroy=function(){window.removeEventListener("message",m,!1),window.addEventListener("touchend",p,!0);for(let e in r){let t=document.getElementById(r[e].iFrameName);t&&t.parentNode.removeChild(t)}},t}}},t={};(function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports})(415)})();
|
|
2
|
-
//# sourceMappingURL=v1.js.map
|
package/dist/form/v1.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v1.js","mappings":"qBAAAA,EAAOC,QAAU,SAAUC,GACvB,MAAMC,EAAO,GACTC,EAAS,GACTC,EAAa,GACbC,EAAY,GACZC,EAASC,IAKb,IAAIC,EAAY,KAEhB,SAASD,IACL,OAAOE,KAAKC,SAASC,SAAS,IAAIC,OAAO,EAAG,GAGhD,SAASC,IACL,GAAIZ,EAAOa,OAASC,OAAOC,QAAS,CAChC,MAAMC,EAAOC,MAAMC,UAAUC,MAAMC,KAAKC,WACxCL,EAAKM,QAAQ,cACbP,QAAQH,IAAIW,MAAMR,QAASC,IAoCnC,SAASQ,EAAaC,GAClB,MAAMC,EAAcD,EAAME,UACtBC,EAAaH,EAAMG,WACnBC,EAAa,CACTC,GAAIF,EACJG,KAAMH,EACNI,MAAOJ,EACPK,IAAKjC,EAAOkC,UAAY,IAAM,IAAKC,gBAAgB,CAC/CC,QAAS/B,EACTgC,WAAYZ,EAAMa,UAClBC,YAAapC,EACbuB,YAAaD,EAAMC,YACnBc,WAAYf,EAAMg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cAC9BC,gBAAiBJ,UAAUK,SAC3BC,kBAAmBC,OAAOC,WAC1BC,oBAAqBF,OAAOG,OAC5BC,mBAAoBJ,OAAOK,MAC3BC,WAAW,IAAKC,MAAQC,uBAE7BC,MAAMC,GACDA,EAAIC,QACGxD,QAAQC,QAAQsD,EAAIE,QAGxBzD,QAAQ0D,OAAO,CAClBC,MAAOJ,EAAII,MACXC,cAAeL,EAAIK,mBAK/BzH,EAAK0H,MAAQ,SAAUlG,GACnB,MAAMmG,EAAI1H,EAAOuB,IAAU,KACvBmG,GACA9G,OAAOkD,OAAO4D,EAAEhG,YAAY+F,SAIpC1H,EAAK4H,SAAW,SAAUvF,EAAWwF,EAAUC,GACtC7H,EAAOoC,IAIZxB,OAAOkD,OAAO9D,EAAOoC,GAAWV,YAAY6B,YAAY,CACpDC,KAAM,WACNC,OAAQ,CACJmE,SAAUA,EACVE,MAAOD,IAEZ,MAwDPjH,OAAOmH,iBAAiB,UAAWtD,GAAgB,GAenD1E,EAAKiI,QAAU,WACXpH,OAAOqH,oBAAoB,UAAWxD,GAAgB,GACtD7D,OAAOmH,iBAAiB,WAAYrC,GAAY,GAChD,IAAK,IAAItD,KAAapC,EAAQ,CAC1B,IAAI2C,EAASC,SAASuB,eAAenE,EAAOoC,GAAWV,YACnDiB,GACAA,EAAOuF,WAAW9E,YAAYT,KAKnC5C,KC9OPoI,EAA2B,IAG/B,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBvD,IAAjBwD,EACH,OAAOA,EAAazI,QAGrB,IAAID,EAASuI,EAAyBE,GAAY,CAGjDxI,QAAS,IAOV,OAHA0I,EAAoBF,GAAUzI,EAAQA,EAAOC,QAASuI,GAG/CxI,EAAOC,SClBWuI,CAAoB,M","sources":["webpack://@payyoag/ptp-js/./src/form/index.js","webpack://@payyoag/ptp-js/webpack/bootstrap","webpack://@payyoag/ptp-js/webpack/startup"],"sourcesContent":["module.exports = function (config) {\n const form = {},\n fields = {},\n fieldNames = [],\n callbacks = {},\n formId = generateRandomId();\n\n const EVENT_ON_CHANGE = 'change';\n const EVENT_ON_READY = 'ready';\n\n let mainField = null;\n\n function generateRandomId() {\n return Math.random().toString(36).substr(2, 9);\n }\n\n function log() {\n if (config.debug && window.console) {\n const args = Array.prototype.slice.call(arguments);\n args.unshift('[PTP FORM]');\n console.log.apply(console, args);\n }\n }\n\n form.init = function (fieldsMap) {\n for (let fieldName in fieldsMap) {\n if (!fieldsMap.hasOwnProperty(fieldName)) {\n return;\n }\n\n let field = fieldsMap[fieldName];\n let fieldContainer = field.container;\n\n if (typeof fieldContainer === 'string') {\n fieldContainer = document.getElementById(fieldContainer);\n }\n\n fields[fieldName] = {\n fieldName: fieldName,\n iFrameName: 'ptp-field-iframe-' + formId + '-' + fieldName,\n container: fieldContainer,\n placeholder: field.placeholder || '',\n inputType: field.inputType || 'text',\n isReady: false\n };\n\n fieldNames.push(fieldName);\n }\n\n mainField = fieldNames[0];\n\n for (let i = 0; i < fieldNames.length; i++) {\n createIframe(fields[fieldNames[i]]);\n }\n };\n\n function createIframe(field) {\n const placeholder = field.container,\n iFrameName = field.iFrameName,\n attributes = {\n id: iFrameName,\n name: iFrameName,\n class: iFrameName,\n src: config.iframeUri + '?' + (new URLSearchParams({\n form_id: formId,\n field_name: field.fieldName,\n field_names: fieldNames,\n placeholder: field.placeholder,\n input_type: field.inputType,\n debug: config.debug ? '1' : '0',\n })).toString(),\n frameborder: \"0\",\n scrolling: \"no\",\n style: 'width: 100%; height: 100%',\n },\n iframe = document.createElement('iframe');\n\n Object.keys(attributes).forEach(function (key) {\n iframe.setAttribute(key, attributes[key]);\n });\n\n while (placeholder.hasChildNodes()) {\n placeholder.removeChild(placeholder.lastChild);\n }\n placeholder.appendChild(iframe);\n\n field.iframe = iframe[0];\n }\n\n function postMessage(type, params = {}) {\n const message = {params: params, type: type, formId: formId, messageId: null};\n\n return new Promise((resolve) => {\n const messageId = type + \":\" + generateRandomId();\n callbacks[messageId] = resolve;\n message.messageId = messageId;\n\n log('send message', message);\n window.frames[fields[mainField].iFrameName].postMessage(message, '*');\n });\n }\n\n const handlers = {};\n form.onChange = function (handler) {\n handlers[EVENT_ON_CHANGE] = handler;\n }\n\n form.onReady = function (handler) {\n handlers[EVENT_ON_READY] = handler;\n }\n\n form.validate = function () {\n return postMessage('validateRequest');\n }\n\n form.submit = function (params) {\n return postMessage('submitRequest', {\n params: params || {},\n browserDetails: {\n browserUserAgent: navigator.userAgent,\n browserJavaEnabled: navigator.javaEnabled(),\n browserLanguage: navigator.language,\n browserColorDepth: screen.colorDepth,\n browserScreenHeight: screen.height,\n browserScreenWidth: screen.width,\n browserTZ: (new Date()).getTimezoneOffset()\n }\n }).then((res) => {\n if (res.success) {\n return Promise.resolve(res.result);\n }\n\n return Promise.reject({\n error: res.error,\n error_details: res.error_details,\n });\n });\n }\n\n form.focus = function (field) {\n const f = fields[field] || null;\n if (f) {\n window.frames[f.iFrameName].focus();\n }\n };\n\n form.setStyle = function (fieldName, selector, cssRules) {\n if (!fields[fieldName]) {\n return;\n }\n\n window.frames[fields[fieldName].iFrameName].postMessage({\n type: 'setStyle',\n params: {\n selector: selector,\n rules: cssRules,\n }\n }, '*');\n };\n\n function receiveMessage(message) {\n const event = message.data;\n if (formId !== event.formId) {\n return;\n }\n\n log(`message received of type \"${event.type}\"`, event);\n\n const handlers = {\n fieldReady: (r) => {\n if (fields[r.fieldName] === undefined) {\n return;\n }\n fields[r.fieldName].isReady = true;\n const ready = Object.keys(fields)\n .map((key) => fields[key].isReady)\n .reduce((a, b) => a && b, true);\n\n if (ready) {\n emitEvent('ready');\n }\n },\n fieldChanged: function (response) {\n emitEvent('change', response);\n },\n };\n\n const messageId = event.messageId,\n callback = callbacks[messageId];\n\n if (callback !== undefined) {\n delete callbacks[messageId];\n callback.apply(form, [event.response]);\n } else {\n const handler = handlers[event.type];\n if (handler) {\n handler.apply(form, [event.response]);\n }\n }\n }\n\n function emitEvent() {\n const args = Array.prototype.slice.call(arguments);\n const eventName = args.shift();\n const handler = handlers[eventName];\n if (handler) {\n log(`emit event \"${eventName}\"`, args);\n handler.apply(null, args);\n } else {\n log(`no handler for event \"${eventName}\"`, args);\n }\n }\n\n window.addEventListener('message', receiveMessage, false);\n\n function addOnTouchedEventListener() {\n window.addEventListener('touchend', checkFocus, true);\n }\n\n function checkFocus() {\n for (let [, field] of Object.entries(fields)) {\n const iframe = window.frames[field.iFrameName];\n if (typeof iframe) {\n iframe.postMessage({'type': 'checkFocus'}, '*');\n }\n }\n }\n\n form.destroy = function () {\n window.removeEventListener('message', receiveMessage, false);\n window.addEventListener('touchend', checkFocus, true);\n for (let fieldName in fields) {\n let iframe = document.getElementById(fields[fieldName].iFrameName);\n if (iframe) {\n iframe.parentNode.removeChild(iframe);\n }\n }\n }\n\n return form;\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(415);\n"],"names":["module","exports","config","form","fields","fieldNames","callbacks","formId","generateRandomId","mainField","Math","random","toString","substr","log","debug","window","console","args","Array","prototype","slice","call","arguments","unshift","apply","createIframe","field","placeholder","container","iFrameName","attributes","id","name","class","src","iframeUri","URLSearchParams","form_id","field_name","fieldName","field_names","input_type","inputType","frameborder","scrolling","style","iframe","document","createElement","Object","keys","forEach","key","setAttribute","hasChildNodes","removeChild","lastChild","appendChild","postMessage","type","params","message","messageId","Promise","resolve","frames","init","fieldsMap","hasOwnProperty","fieldContainer","getElementById","isReady","push","i","length","handlers","receiveMessage","event","data","fieldReady","r","undefined","map","reduce","a","b","emitEvent","fieldChanged","response","callback","handler","eventName","shift","checkFocus","entries","onChange","onReady","validate","submit","browserDetails","browserUserAgent","navigator","userAgent","browserJavaEnabled","javaEnabled","browserLanguage","language","browserColorDepth","screen","colorDepth","browserScreenHeight","height","browserScreenWidth","width","browserTZ","Date","getTimezoneOffset","then","res","success","result","reject","error","error_details","focus","f","setStyle","selector","cssRules","rules","addEventListener","destroy","removeEventListener","parentNode","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
|