@lightspeed/online-payments-sdk 0.1.0

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.md ADDED
@@ -0,0 +1 @@
1
+ # Process payments with Lightspeed Payments
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@lightspeed/online-payments-sdk"]={})}(this,(function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(s,i){function a(e){try{r(o.next(e))}catch(e){i(e)}}function d(e){try{r(o.throw(e))}catch(e){i(e)}}function r(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,d)}r((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=(e,t,n)=>({publishMessage:(e,o)=>t.contentWindow?(t.contentWindow.postMessage({type:e,payload:o},n),{success:!0}):{success:!1,message:"Failed to send event"},awaitMessage:t=>new Promise((o=>{const s=i=>{i.origin===n&&function(e,t){var n,o,s,i;const a=t;if(a.type!==e)return!1;switch(e){case"READY":return!0;case"COMPLETE":{const e=a;return void 0!==(null===(o=null===(n=null==e?void 0:e.payload)||void 0===n?void 0:n.data)||void 0===o?void 0:o.paymentId)}case"ERROR":return void 0!==(null===(i=null===(s=a.payload)||void 0===s?void 0:s.data)||void 0===i?void 0:i.code);default:return!1}}(t,i.data)&&(e.removeEventListener("message",s),o(i.data))};e.addEventListener("message",s)}))});e.mountLightspeedPayments=function(e){return t(this,void 0,void 0,(function*(){const o=null!==(i=null!==(s=process.env.OVERRIDE_IFRAME_CONTENT_HOSTNAME)&&void 0!==s?s:"$ONLINE_PAYMENT_WIDGETS_PROD")&&void 0!==i?i:"";var s,i;const a=window.document.createElement("iframe");if(a.height="800px",a.width="700px",a.src=o,!e)throw Error("HtmlElement to mount checkout to is required. Received undefined");const d=n(window,a,o),r=d.awaitMessage("READY");return e.appendChild(a),r.then((()=>function(e){return{collectPaymentMethod:n=>t(this,void 0,void 0,(function*(){const t=Promise.race([e.awaitMessage("COMPLETE"),e.awaitMessage("ERROR")]);e.publishMessage("SET_PAYMENT_SESSION_V1",{paymentSessionId:n});const o=yield t;if("COMPLETE"===o.type)return{success:!0,paymentId:o.payload.data.paymentId};throw Error(o.payload.data.message)}))}}(d)))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -0,0 +1,41 @@
1
+ type PublishableMessagePayloadMapping = {
2
+ SET_PAYMENT_SESSION_V1: {
3
+ paymentSessionId: string;
4
+ };
5
+ };
6
+ type PublishableMessage = keyof PublishableMessagePayloadMapping;
7
+ type MessageEventData<K extends AwaitableMessage, T> = {
8
+ type: K;
9
+ payload: T;
10
+ };
11
+ export type AwaitableMessagePayloadMap = {
12
+ READY: MessageEventData<'READY', undefined>;
13
+ ERROR: MessageEventData<'ERROR', {
14
+ version: string;
15
+ data: {
16
+ code: string;
17
+ message: string;
18
+ };
19
+ }>;
20
+ COMPLETE: MessageEventData<'COMPLETE', {
21
+ version: string;
22
+ data: {
23
+ paymentId: string;
24
+ };
25
+ }>;
26
+ };
27
+ export type AwaitableMessage = keyof AwaitableMessagePayloadMap;
28
+ type PublishMessageResult = {
29
+ success: true;
30
+ } | {
31
+ success: false;
32
+ message: string;
33
+ };
34
+ export type FrameMessenger = {
35
+ awaitMessage<T extends AwaitableMessage>(eventType: T): Promise<AwaitableMessagePayloadMap[T]>;
36
+ publishMessage<T extends PublishableMessage>(eventType: T, payload: PublishableMessagePayloadMapping[T]): PublishMessageResult;
37
+ };
38
+ export declare const FrameMessenger: {
39
+ createFrameMessenger: (hostWindow: Window, contentIframe: HTMLIFrameElement, contentOrigin: string) => FrameMessenger;
40
+ };
41
+ export {};
@@ -0,0 +1,11 @@
1
+ export type Configuration = {
2
+ payment_session: string;
3
+ };
4
+ export type CollectPaymentMethodResponse = {
5
+ success: true;
6
+ paymentId: string;
7
+ };
8
+ export type OnlinePaymentsInterface = {
9
+ collectPaymentMethod(paymentSessionId: string): Promise<CollectPaymentMethodResponse>;
10
+ };
11
+ export declare function mountLightspeedPayments(mountPoint: HTMLElement): Promise<OnlinePaymentsInterface>;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@lightspeed/online-payments-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Process online-payments with Lightspeed Payments",
5
+ "main": "dist/bundle.js",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "scripts": {
10
+ "bundle": "rollup -c",
11
+ "test": "jest --no-cache --detectOpenHandles",
12
+ "lint": "gts lint",
13
+ "clean": "gts clean",
14
+ "typecheck": "tsc --noEmit",
15
+ "release": "npm run clean && npm run bundle && npm publish",
16
+ "preversion": "npm run lint && npm run typecheck && npm run unit-test",
17
+ "create-release": "./create-release.sh",
18
+ "check-package-content": "npm pack --dry-run"
19
+ },
20
+ "author": "Lightspeed",
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "devDependencies": {
26
+ "@rollup/plugin-inject": "^5.0.5",
27
+ "@rollup/plugin-node-resolve": "^15.3.0",
28
+ "@rollup/plugin-replace": "^6.0.1",
29
+ "@rollup/plugin-terser": "^0.4.4",
30
+ "@rollup/plugin-typescript": "^11.1.6",
31
+ "@rollup/plugin-url": "^8.0.2",
32
+ "@types/jest": "^29.5.13",
33
+ "gts": "^5.3.1",
34
+ "jest": "^29.7.0",
35
+ "jest-environment-jsdom": "^29.7.0",
36
+ "jest-junit": "^16.0.0",
37
+ "rollup": "^2.79.1",
38
+ "ts-jest": "^29.2.5",
39
+ "tslib": "^2.7.0",
40
+ "typescript": "^5.1.5"
41
+ }
42
+ }