@lightspeed/online-payments-sdk 0.1.0 → 0.1.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/package.json +13 -20
- package/dist/index.js +0 -1
- package/dist/src/frameMessenger.d.ts +0 -41
- package/dist/src/index.d.ts +0 -11
package/package.json
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightspeed/online-payments-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Process online-payments with Lightspeed Payments",
|
|
5
|
-
"main": "dist/bundle.js",
|
|
6
5
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
6
|
+
"author": "Lightspeed Commerce Inc.",
|
|
7
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
8
|
+
"main": "dist/cjs/index.js",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"publishConfig": { "access": "public" },
|
|
12
|
+
"files": ["dist"],
|
|
13
|
+
"sideEffects": false,
|
|
9
14
|
"scripts": {
|
|
10
|
-
"bundle": "rollup -c",
|
|
11
15
|
"test": "jest --no-cache --detectOpenHandles",
|
|
12
16
|
"lint": "gts lint",
|
|
13
17
|
"clean": "gts clean",
|
|
14
18
|
"typecheck": "tsc --noEmit",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
+
"check-package-content": "npm pack --dry-run",
|
|
20
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
21
|
+
"build:esm": "tsc --module esnext --target es5 --outDir dist --downlevelIteration",
|
|
22
|
+
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs --downlevelIteration --declaration false"
|
|
19
23
|
},
|
|
20
|
-
"author": "Lightspeed",
|
|
21
|
-
"files": [
|
|
22
|
-
"dist",
|
|
23
|
-
"README.md"
|
|
24
|
-
],
|
|
25
24
|
"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
25
|
"@types/jest": "^29.5.13",
|
|
33
26
|
"gts": "^5.3.1",
|
|
34
27
|
"jest": "^29.7.0",
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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})}));
|
|
@@ -1,41 +0,0 @@
|
|
|
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 {};
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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>;
|