@lightspeed/online-payments-sdk 1.1.4 → 1.1.6

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/dist/cjs/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LightspeedPayments = void 0;
3
+ exports.LightspeedPayments = exports.THEME_COLORS = void 0;
4
4
  var v1_1 = require("./v1");
5
+ var v1_2 = require("./v1");
6
+ Object.defineProperty(exports, "THEME_COLORS", { enumerable: true, get: function () { return v1_2.THEME_COLORS; } });
5
7
  exports.LightspeedPayments = {
6
8
  v1: v1_1.v1,
7
9
  };
@@ -6,13 +6,15 @@
6
6
  * Don't use * for exports. Be specific to prevent leaking internal APIs.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.v1 = exports.ProcessingError = exports.InvalidSessionError = exports.InvalidSessionPayloadError = exports.UnsupportedLocationError = void 0;
9
+ exports.v1 = exports.THEME_COLORS = exports.ProcessingError = exports.InvalidSessionError = exports.InvalidSessionPayloadError = exports.UnsupportedLocationError = void 0;
10
10
  var widget_1 = require("./widget");
11
11
  var error_1 = require("./error");
12
12
  Object.defineProperty(exports, "UnsupportedLocationError", { enumerable: true, get: function () { return error_1.UnsupportedLocationError; } });
13
13
  Object.defineProperty(exports, "InvalidSessionPayloadError", { enumerable: true, get: function () { return error_1.InvalidSessionPayloadError; } });
14
14
  Object.defineProperty(exports, "InvalidSessionError", { enumerable: true, get: function () { return error_1.InvalidSessionError; } });
15
15
  Object.defineProperty(exports, "ProcessingError", { enumerable: true, get: function () { return error_1.ProcessingError; } });
16
+ var themes_1 = require("./stripe/themes");
17
+ Object.defineProperty(exports, "THEME_COLORS", { enumerable: true, get: function () { return themes_1.THEME_COLORS; } });
16
18
  exports.v1 = {
17
19
  mountPaymentWidget: widget_1.mountPaymentWidget,
18
20
  };
@@ -1,6 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.THEME_COLORS = void 0;
4
+ exports.applyThemeClass = applyThemeClass;
5
+ exports.removeThemeClass = removeThemeClass;
3
6
  exports.getThemeConfig = getThemeConfig;
7
+ /**
8
+ * Theme color constants for styling containers
9
+ * Use these to match the SDK's dark theme colors in your application
10
+ */
11
+ exports.THEME_COLORS = {
12
+ DARK: {
13
+ BACKGROUND: '#1a1a1a',
14
+ TEXT: '#ffffff',
15
+ },
16
+ };
17
+ /**
18
+ * ID for the injected theme stylesheet element
19
+ */
20
+ var THEME_STYLESHEET_ID = 'lsp-theme-styles';
21
+ /**
22
+ * Apply theme class to an element
23
+ */
24
+ function applyThemeClass(element, theme) {
25
+ element.classList.add("lsp-theme-".concat(theme));
26
+ }
27
+ /**
28
+ * Remove theme class from an element
29
+ */
30
+ function removeThemeClass(element, theme) {
31
+ if (theme) {
32
+ element.classList.remove("lsp-theme-".concat(theme));
33
+ }
34
+ }
35
+ /**
36
+ * Inject theme stylesheets into the document head
37
+ * Each theme can define its own container styling
38
+ */
39
+ function ensureThemeStylesheet() {
40
+ if (document.getElementById(THEME_STYLESHEET_ID)) {
41
+ return;
42
+ }
43
+ var styleElement = document.createElement('style');
44
+ styleElement.id = THEME_STYLESHEET_ID;
45
+ styleElement.textContent = "\n /* Dark theme styles for the mount element */\n .lsp-theme-dark {\n background-color: ".concat(exports.THEME_COLORS.DARK.BACKGROUND, " !important;\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n /* Dark theme styles for Stripe custom terms elements */\n .lsp-theme-dark .stripe-terms-triangle {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-custom-terms-text {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-expandable-terms-content p {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n ");
46
+ document.head.appendChild(styleElement);
47
+ }
4
48
  /**
5
49
  * Get theme configuration based on theme name
6
50
  */
@@ -37,6 +81,18 @@ function getThemeConfig(theme) {
37
81
  type: 'tabs',
38
82
  },
39
83
  };
84
+ case 'dark':
85
+ // Ensure theme stylesheet is injected
86
+ ensureThemeStylesheet();
87
+ return {
88
+ appearance: {
89
+ theme: 'night',
90
+ },
91
+ fonts: [],
92
+ layout: {
93
+ type: 'tabs',
94
+ },
95
+ };
40
96
  default:
41
97
  return undefined;
42
98
  }
@@ -40,27 +40,57 @@ exports.StripeWidget = void 0;
40
40
  exports.mount = mount;
41
41
  var payment_1 = require("./widgets/payment");
42
42
  var moto_1 = require("./widgets/moto");
43
+ var themes_1 = require("./themes");
43
44
  /**
44
45
  * Main mount function that delegates to appropriate widget based on session type
45
46
  */
46
47
  function mount(mountElement, session, eventBroadcaster, defaultValues, theme) {
47
48
  return __awaiter(this, void 0, void 0, function () {
48
- var sessionType;
49
- return __generator(this, function (_a) {
50
- sessionType = session.metadata.sessionType;
51
- // Route to appropriate widget based on session type
52
- switch (sessionType) {
53
- case 'payment':
54
- case 'payment-with-save':
55
- return [2 /*return*/, (0, payment_1.mountPaymentWidget)(mountElement, session, eventBroadcaster, defaultValues, theme)];
56
- case 'moto':
57
- case 'moto-with-save':
58
- case 'save':
59
- return [2 /*return*/, (0, moto_1.mountMotoWidget)(mountElement, session, eventBroadcaster, defaultValues, theme)];
60
- default:
61
- throw new Error("Unsupported session type: ".concat(sessionType));
49
+ var sessionType, widgetController, _a, originalUnmount_1, error_1;
50
+ return __generator(this, function (_b) {
51
+ switch (_b.label) {
52
+ case 0:
53
+ // Apply theme class to mount element
54
+ if (theme) {
55
+ (0, themes_1.applyThemeClass)(mountElement, theme);
56
+ }
57
+ sessionType = session.metadata.sessionType;
58
+ _b.label = 1;
59
+ case 1:
60
+ _b.trys.push([1, 8, , 9]);
61
+ widgetController = void 0;
62
+ _a = sessionType;
63
+ switch (_a) {
64
+ case 'payment': return [3 /*break*/, 2];
65
+ case 'payment-with-save': return [3 /*break*/, 2];
66
+ case 'moto': return [3 /*break*/, 4];
67
+ case 'moto-with-save': return [3 /*break*/, 4];
68
+ case 'save': return [3 /*break*/, 4];
69
+ }
70
+ return [3 /*break*/, 6];
71
+ case 2: return [4 /*yield*/, (0, payment_1.mountPaymentWidget)(mountElement, session, eventBroadcaster, defaultValues, theme)];
72
+ case 3:
73
+ widgetController = _b.sent();
74
+ return [3 /*break*/, 7];
75
+ case 4: return [4 /*yield*/, (0, moto_1.mountMotoWidget)(mountElement, session, eventBroadcaster, defaultValues, theme)];
76
+ case 5:
77
+ widgetController = _b.sent();
78
+ return [3 /*break*/, 7];
79
+ case 6: throw new Error("Unsupported session type: ".concat(sessionType));
80
+ case 7:
81
+ originalUnmount_1 = widgetController.unmount;
82
+ widgetController.unmount = function () {
83
+ (0, themes_1.removeThemeClass)(mountElement, theme);
84
+ originalUnmount_1();
85
+ };
86
+ return [2 /*return*/, widgetController];
87
+ case 8:
88
+ error_1 = _b.sent();
89
+ // Clean up theme class if mounting fails
90
+ (0, themes_1.removeThemeClass)(mountElement, theme);
91
+ throw error_1;
92
+ case 9: return [2 /*return*/];
62
93
  }
63
- return [2 /*return*/];
64
94
  });
65
95
  });
66
96
  }
@@ -46,7 +46,7 @@ var common_1 = require("./logging/common");
46
46
  var EventBroadcaster_1 = require("./EventBroadcaster");
47
47
  function mountPaymentWidget(session, config) {
48
48
  return __awaiter(this, void 0, void 0, function () {
49
- var eventBroadcaster, decodedSession, logger_2, widgetController, _a, error_2;
49
+ var eventBroadcaster, decodedSession, logger_2, configSummary, widgetController, _a, error_2;
50
50
  return __generator(this, function (_b) {
51
51
  switch (_b.label) {
52
52
  case 0:
@@ -62,7 +62,12 @@ function mountPaymentWidget(session, config) {
62
62
  logger_2.log('info', event.status, { event: event });
63
63
  return event;
64
64
  });
65
- logger_2.log('info', 'Mount');
65
+ configSummary = {
66
+ theme: config.theme || 'none',
67
+ listeners: config.listeners ? Object.keys(config.listeners) : [],
68
+ defaultValues: config.defaultValues ? Object.keys(config.defaultValues) : undefined,
69
+ };
70
+ logger_2.log('info', 'Mount', { configuration: configSummary });
66
71
  widgetController = void 0;
67
72
  _a = decodedSession.psp;
68
73
  switch (_a) {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type * from './v1';
2
+ export { THEME_COLORS } from './v1';
2
3
  export declare const LightspeedPayments: {
3
4
  v1: import("./v1").LightspeedPaymentsV1;
4
5
  };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { v1 } from './v1';
2
+ export { THEME_COLORS } from './v1';
2
3
  export var LightspeedPayments = {
3
4
  v1: v1,
4
5
  };
@@ -10,6 +10,7 @@ export type { WidgetController, SessionType, DefaultValues } from './common';
10
10
  export type { Event } from './EventBroadcaster';
11
11
  export { UnsupportedLocationError, InvalidSessionPayloadError, InvalidSessionError, ProcessingError, } from './error';
12
12
  export type { PaymentWidgetConfiguration, PaymentWidgetTheme } from './widget';
13
+ export { THEME_COLORS } from './stripe/themes';
13
14
  export type LightspeedPaymentsV1 = {
14
15
  /**
15
16
  * Mounts the payment widget to the specified mount point.
package/dist/v1/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { mountPaymentWidget } from './widget';
8
8
  export { UnsupportedLocationError, InvalidSessionPayloadError, InvalidSessionError, ProcessingError, } from './error';
9
+ export { THEME_COLORS } from './stripe/themes';
9
10
  export var v1 = {
10
11
  mountPaymentWidget: mountPaymentWidget,
11
12
  };
@@ -1,5 +1,23 @@
1
1
  import type { Appearance } from '@stripe/stripe-js';
2
2
  import { PaymentWidgetTheme } from '../widget';
3
+ /**
4
+ * Theme color constants for styling containers
5
+ * Use these to match the SDK's dark theme colors in your application
6
+ */
7
+ export declare const THEME_COLORS: {
8
+ readonly DARK: {
9
+ readonly BACKGROUND: "#1a1a1a";
10
+ readonly TEXT: "#ffffff";
11
+ };
12
+ };
13
+ /**
14
+ * Apply theme class to an element
15
+ */
16
+ export declare function applyThemeClass(element: HTMLElement, theme: PaymentWidgetTheme): void;
17
+ /**
18
+ * Remove theme class from an element
19
+ */
20
+ export declare function removeThemeClass(element: HTMLElement, theme?: PaymentWidgetTheme): void;
3
21
  /**
4
22
  * Theme configuration for Stripe Elements appearance
5
23
  */
@@ -1,3 +1,44 @@
1
+ /**
2
+ * Theme color constants for styling containers
3
+ * Use these to match the SDK's dark theme colors in your application
4
+ */
5
+ export var THEME_COLORS = {
6
+ DARK: {
7
+ BACKGROUND: '#1a1a1a',
8
+ TEXT: '#ffffff',
9
+ },
10
+ };
11
+ /**
12
+ * ID for the injected theme stylesheet element
13
+ */
14
+ var THEME_STYLESHEET_ID = 'lsp-theme-styles';
15
+ /**
16
+ * Apply theme class to an element
17
+ */
18
+ export function applyThemeClass(element, theme) {
19
+ element.classList.add("lsp-theme-".concat(theme));
20
+ }
21
+ /**
22
+ * Remove theme class from an element
23
+ */
24
+ export function removeThemeClass(element, theme) {
25
+ if (theme) {
26
+ element.classList.remove("lsp-theme-".concat(theme));
27
+ }
28
+ }
29
+ /**
30
+ * Inject theme stylesheets into the document head
31
+ * Each theme can define its own container styling
32
+ */
33
+ function ensureThemeStylesheet() {
34
+ if (document.getElementById(THEME_STYLESHEET_ID)) {
35
+ return;
36
+ }
37
+ var styleElement = document.createElement('style');
38
+ styleElement.id = THEME_STYLESHEET_ID;
39
+ styleElement.textContent = "\n /* Dark theme styles for the mount element */\n .lsp-theme-dark {\n background-color: ".concat(THEME_COLORS.DARK.BACKGROUND, " !important;\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n /* Dark theme styles for Stripe custom terms elements */\n .lsp-theme-dark .stripe-terms-triangle {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-custom-terms-text {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-expandable-terms-content p {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n ");
40
+ document.head.appendChild(styleElement);
41
+ }
1
42
  /**
2
43
  * Get theme configuration based on theme name
3
44
  */
@@ -34,6 +75,18 @@ export function getThemeConfig(theme) {
34
75
  type: 'tabs',
35
76
  },
36
77
  };
78
+ case 'dark':
79
+ // Ensure theme stylesheet is injected
80
+ ensureThemeStylesheet();
81
+ return {
82
+ appearance: {
83
+ theme: 'night',
84
+ },
85
+ fonts: [],
86
+ layout: {
87
+ type: 'tabs',
88
+ },
89
+ };
37
90
  default:
38
91
  return undefined;
39
92
  }
@@ -36,27 +36,57 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { mountPaymentWidget } from './widgets/payment';
38
38
  import { mountMotoWidget } from './widgets/moto';
39
+ import { applyThemeClass, removeThemeClass } from './themes';
39
40
  /**
40
41
  * Main mount function that delegates to appropriate widget based on session type
41
42
  */
42
43
  export function mount(mountElement, session, eventBroadcaster, defaultValues, theme) {
43
44
  return __awaiter(this, void 0, void 0, function () {
44
- var sessionType;
45
- return __generator(this, function (_a) {
46
- sessionType = session.metadata.sessionType;
47
- // Route to appropriate widget based on session type
48
- switch (sessionType) {
49
- case 'payment':
50
- case 'payment-with-save':
51
- return [2 /*return*/, mountPaymentWidget(mountElement, session, eventBroadcaster, defaultValues, theme)];
52
- case 'moto':
53
- case 'moto-with-save':
54
- case 'save':
55
- return [2 /*return*/, mountMotoWidget(mountElement, session, eventBroadcaster, defaultValues, theme)];
56
- default:
57
- throw new Error("Unsupported session type: ".concat(sessionType));
45
+ var sessionType, widgetController, _a, originalUnmount_1, error_1;
46
+ return __generator(this, function (_b) {
47
+ switch (_b.label) {
48
+ case 0:
49
+ // Apply theme class to mount element
50
+ if (theme) {
51
+ applyThemeClass(mountElement, theme);
52
+ }
53
+ sessionType = session.metadata.sessionType;
54
+ _b.label = 1;
55
+ case 1:
56
+ _b.trys.push([1, 8, , 9]);
57
+ widgetController = void 0;
58
+ _a = sessionType;
59
+ switch (_a) {
60
+ case 'payment': return [3 /*break*/, 2];
61
+ case 'payment-with-save': return [3 /*break*/, 2];
62
+ case 'moto': return [3 /*break*/, 4];
63
+ case 'moto-with-save': return [3 /*break*/, 4];
64
+ case 'save': return [3 /*break*/, 4];
65
+ }
66
+ return [3 /*break*/, 6];
67
+ case 2: return [4 /*yield*/, mountPaymentWidget(mountElement, session, eventBroadcaster, defaultValues, theme)];
68
+ case 3:
69
+ widgetController = _b.sent();
70
+ return [3 /*break*/, 7];
71
+ case 4: return [4 /*yield*/, mountMotoWidget(mountElement, session, eventBroadcaster, defaultValues, theme)];
72
+ case 5:
73
+ widgetController = _b.sent();
74
+ return [3 /*break*/, 7];
75
+ case 6: throw new Error("Unsupported session type: ".concat(sessionType));
76
+ case 7:
77
+ originalUnmount_1 = widgetController.unmount;
78
+ widgetController.unmount = function () {
79
+ removeThemeClass(mountElement, theme);
80
+ originalUnmount_1();
81
+ };
82
+ return [2 /*return*/, widgetController];
83
+ case 8:
84
+ error_1 = _b.sent();
85
+ // Clean up theme class if mounting fails
86
+ removeThemeClass(mountElement, theme);
87
+ throw error_1;
88
+ case 9: return [2 /*return*/];
58
89
  }
59
- return [2 /*return*/];
60
90
  });
61
91
  });
62
92
  }
@@ -1,6 +1,6 @@
1
1
  import { WidgetController, DefaultValues } from './common';
2
2
  import { EventListeners } from './EventBroadcaster';
3
- export type PaymentWidgetTheme = 'invoicing';
3
+ export type PaymentWidgetTheme = 'invoicing' | 'dark';
4
4
  export type PaymentWidgetConfiguration = {
5
5
  mountPoint: HTMLElement;
6
6
  defaultValues?: DefaultValues;
package/dist/v1/widget.js CHANGED
@@ -43,7 +43,7 @@ import { withLogging } from './logging/common';
43
43
  import { EventBroadcaster } from './EventBroadcaster';
44
44
  export function mountPaymentWidget(session, config) {
45
45
  return __awaiter(this, void 0, void 0, function () {
46
- var eventBroadcaster, decodedSession, logger_1, widgetController, _a, error_1;
46
+ var eventBroadcaster, decodedSession, logger_1, configSummary, widgetController, _a, error_1;
47
47
  return __generator(this, function (_b) {
48
48
  switch (_b.label) {
49
49
  case 0:
@@ -59,7 +59,12 @@ export function mountPaymentWidget(session, config) {
59
59
  logger_1.log('info', event.status, { event: event });
60
60
  return event;
61
61
  });
62
- logger_1.log('info', 'Mount');
62
+ configSummary = {
63
+ theme: config.theme || 'none',
64
+ listeners: config.listeners ? Object.keys(config.listeners) : [],
65
+ defaultValues: config.defaultValues ? Object.keys(config.defaultValues) : undefined,
66
+ };
67
+ logger_1.log('info', 'Mount', { configuration: configSummary });
63
68
  widgetController = void 0;
64
69
  _a = decodedSession.psp;
65
70
  switch (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed/online-payments-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Process online-payments with Lightspeed Payments",
5
5
  "author": "Lightspeed Commerce Inc.",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -20,10 +20,6 @@
20
20
  text-decoration: underline;
21
21
  }
22
22
 
23
- .stripe-custom-terms-text a:hover {
24
- color: #0a2540;
25
- }
26
-
27
23
  /* Expandable terms toggle */
28
24
  .stripe-expandable-terms-toggle {
29
25
  color: #635bff;
@@ -31,10 +27,6 @@
31
27
  text-decoration: underline;
32
28
  }
33
29
 
34
- .stripe-expandable-terms-toggle:hover {
35
- color: #0a2540;
36
- }
37
-
38
30
  .stripe-terms-triangle {
39
31
  display: inline-block;
40
32
  font-size: 10px;