Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 108 additions & 18 deletions dist/tebex.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@
* @internal
*/
const isString = (value) => typeof value === "string";
/**
* @internal
*/
const isNonEmptyString = (value) => typeof value === "string" && value !== "";
/**
* @internal
*/
const isBoolean = (value) => typeof value === "boolean";
/**
* @internal
*/
Expand Down Expand Up @@ -12498,7 +12506,7 @@
return html;
};

var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_resolveLocale, _Checkout_resolveTheme, _Checkout_resolveColors, _Checkout_resolvePopupOnMobile, _Checkout_resolveEndpoint, _Checkout_resolveCloseOnClickOutside, _Checkout_resolveCloseOnEsc, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
const DEFAULT_WIDTH = "800px";
const DEFAULT_HEIGHT = "760px";
const THEME_NAMES = [
Expand Down Expand Up @@ -12547,20 +12555,15 @@
* Configure the Tebex checkout settings.
*/
init(options) {
assert(options.ident && isString(options.ident), "ident option is required, and must be a string");
this.ident = options.ident;
this.locale = options.locale ?? null;
this.theme = options.theme ?? this.theme;
this.colors = options.colors ?? this.colors;
this.closeOnClickOutside = options.closeOnClickOutside ?? this.closeOnClickOutside;
this.closeOnEsc = options.closeOnEsc ?? this.closeOnEsc;
this.popupOnMobile = options.popupOnMobile ?? this.popupOnMobile;
this.endpoint = options.endpoint ?? this.endpoint;
assert(!isNullOrUndefined(this.ident), "ident option is required");
assert(THEME_NAMES.includes(this.theme), `invalid theme option "${this.theme}"`);
for (let { color, name } of this.colors) {
assert(COLOR_NAMES.includes(name), `invalid color name "${name}"`);
assert(!color.includes("var("), `invalid ${name} color: colors cannot include CSS variables`);
}
this.locale = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveLocale).call(this, options) ?? this.locale;
this.theme = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveTheme).call(this, options) ?? this.theme;
this.colors = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveColors).call(this, options) ?? this.colors;
this.popupOnMobile = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolvePopupOnMobile).call(this, options) ?? this.popupOnMobile;
this.endpoint = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveEndpoint).call(this, options) ?? this.endpoint;
this.closeOnClickOutside = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnClickOutside).call(this, options) ?? this.closeOnClickOutside;
this.closeOnEsc = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnEsc).call(this, options) ?? this.closeOnEsc;
}
/**
* Subscribe to Tebex checkout events, such as when the embed is closed or when a payment is completed.
Expand All @@ -12573,7 +12576,10 @@
// @ts-ignore - handles legacy event name
if (event === "payment_error")
event = "payment:error";
assert(EVENT_NAMES.includes(event), `invalid event name "${event}"`);
if (!EVENT_NAMES.includes(event)) {
warn(`invalid event name "${event}"`);
return () => { };
}
return this.emitter.on(event, callback);
}
/**
Expand Down Expand Up @@ -12639,7 +12645,91 @@
});
}
}
_Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checkout_onRequestLightboxClose = new WeakMap(), _Checkout_instances = new WeakSet(), _Checkout_showLightbox = async function _Checkout_showLightbox() {
_Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checkout_onRequestLightboxClose = new WeakMap(), _Checkout_instances = new WeakSet(), _Checkout_resolveLocale = function _Checkout_resolveLocale(options) {
if (isNullOrUndefined(options.locale))
return null;
if (!isNonEmptyString(options.locale)) {
warn(`invalid locale option "${options.locale}" - must be a non-empty string`);
return null;
}
return options.locale;
}, _Checkout_resolveTheme = function _Checkout_resolveTheme(options) {
if (isNullOrUndefined(options.theme))
return null;
if (!THEME_NAMES.includes(options.theme)) {
const list = THEME_NAMES.map(n => `"${n}"`).join(", ");
warn(`invalid theme option "${options.theme}" - must be one of ${list}`);
return null;
}
return options.theme;
}, _Checkout_resolveColors = function _Checkout_resolveColors(options) {
if (isNullOrUndefined(options.colors))
return null;
if (!isArray$1(options.colors)) {
warn(`invalid colors option "${options.colors}" - must be an array`);
return null;
}
for (let entry of options.colors) {
if (!isObject(entry)) {
warn(`invalid colors option item ${entry} - must be an object`);
return null;
}
if (!entry.hasOwnProperty("name")) {
warn(`invalid colors option item - missing 'name' field`);
return null;
}
if (!entry.hasOwnProperty("color")) {
warn(`invalid colors option item - missing 'color' field`);
return null;
}
if (!COLOR_NAMES.includes(entry.name)) {
const list = COLOR_NAMES.map(n => `"${n}"`).join(", ");
warn(`invalid color name "${entry.name}" - must be one of ${list}`);
return null;
}
if (!isNonEmptyString(entry.color)) {
warn(`invalid color value "${entry.color}" - must be a non-empty string`);
return null;
}
if (entry.color.includes("var(")) {
warn(`invalid color value "${entry.color}" - cannot include CSS variables`);
return null;
}
}
return options.colors;
}, _Checkout_resolvePopupOnMobile = function _Checkout_resolvePopupOnMobile(options) {
if (isNullOrUndefined(options.popupOnMobile))
return null;
if (!isBoolean(options.popupOnMobile)) {
warn(`invalid popupOnMobile option "${options.popupOnMobile}" - must be a boolean`);
return null;
}
return options.popupOnMobile;
}, _Checkout_resolveEndpoint = function _Checkout_resolveEndpoint(options) {
if (isNullOrUndefined(options.endpoint))
return null;
if (!isNonEmptyString(options.endpoint)) {
warn(`invalid endpoint option "${options.endpoint}" - must be a non-empty string`);
return null;
}
return options.endpoint;
}, _Checkout_resolveCloseOnClickOutside = function _Checkout_resolveCloseOnClickOutside(options) {
if (isNullOrUndefined(options.closeOnClickOutside))
return null;
if (!isBoolean(options.closeOnClickOutside)) {
warn(`invalid closeOnClickOutside option "${options.closeOnClickOutside}" - must be a boolean`);
return null;
}
return options.closeOnClickOutside;
}, _Checkout_resolveCloseOnEsc = function _Checkout_resolveCloseOnEsc(options) {
if (isNullOrUndefined(options.closeOnEsc))
return null;
if (!isBoolean(options.closeOnEsc)) {
warn(`invalid closeOnEsc option "${options.closeOnEsc}" - must be a boolean`);
return null;
}
return options.closeOnEsc;
}, _Checkout_showLightbox = async function _Checkout_showLightbox() {
if (!this.lightbox)
this.lightbox = new Lightbox();
if (this.closeOnClickOutside)
Expand Down Expand Up @@ -12701,7 +12791,7 @@
origin: url.origin,
path: url.pathname,
params: url.search,
version: "1.5.0",
version: "1.6.0",
});
await this.zoid.renderTo(window, container, popup ? "popup" : "iframe");
__classPrivateFieldSet(this, _Checkout_didRender, true, "f");
Expand Down Expand Up @@ -12906,7 +12996,7 @@
/**
* Current Tebex.js package version
*/
const version = "1.5.0";
const version = "1.6.0";
/**
* Tebex checkout API
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/tebex.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tebex.min.js.map

Large diffs are not rendered by default.

126 changes: 108 additions & 18 deletions dist/tebex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ const isNullOrUndefined = (value) => value === undefined || value == null;
* @internal
*/
const isString = (value) => typeof value === "string";
/**
* @internal
*/
const isNonEmptyString = (value) => typeof value === "string" && value !== "";
/**
* @internal
*/
const isBoolean = (value) => typeof value === "boolean";
/**
* @internal
*/
Expand Down Expand Up @@ -12492,7 +12500,7 @@ const spinnerRender = ({ doc, props }) => {
return html;
};

var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_resolveLocale, _Checkout_resolveTheme, _Checkout_resolveColors, _Checkout_resolvePopupOnMobile, _Checkout_resolveEndpoint, _Checkout_resolveCloseOnClickOutside, _Checkout_resolveCloseOnEsc, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
const DEFAULT_WIDTH = "800px";
const DEFAULT_HEIGHT = "760px";
const THEME_NAMES = [
Expand Down Expand Up @@ -12541,20 +12549,15 @@ class Checkout {
* Configure the Tebex checkout settings.
*/
init(options) {
assert(options.ident && isString(options.ident), "ident option is required, and must be a string");
this.ident = options.ident;
this.locale = options.locale ?? null;
this.theme = options.theme ?? this.theme;
this.colors = options.colors ?? this.colors;
this.closeOnClickOutside = options.closeOnClickOutside ?? this.closeOnClickOutside;
this.closeOnEsc = options.closeOnEsc ?? this.closeOnEsc;
this.popupOnMobile = options.popupOnMobile ?? this.popupOnMobile;
this.endpoint = options.endpoint ?? this.endpoint;
assert(!isNullOrUndefined(this.ident), "ident option is required");
assert(THEME_NAMES.includes(this.theme), `invalid theme option "${this.theme}"`);
for (let { color, name } of this.colors) {
assert(COLOR_NAMES.includes(name), `invalid color name "${name}"`);
assert(!color.includes("var("), `invalid ${name} color: colors cannot include CSS variables`);
}
this.locale = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveLocale).call(this, options) ?? this.locale;
this.theme = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveTheme).call(this, options) ?? this.theme;
this.colors = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveColors).call(this, options) ?? this.colors;
this.popupOnMobile = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolvePopupOnMobile).call(this, options) ?? this.popupOnMobile;
this.endpoint = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveEndpoint).call(this, options) ?? this.endpoint;
this.closeOnClickOutside = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnClickOutside).call(this, options) ?? this.closeOnClickOutside;
this.closeOnEsc = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnEsc).call(this, options) ?? this.closeOnEsc;
}
/**
* Subscribe to Tebex checkout events, such as when the embed is closed or when a payment is completed.
Expand All @@ -12567,7 +12570,10 @@ class Checkout {
// @ts-ignore - handles legacy event name
if (event === "payment_error")
event = "payment:error";
assert(EVENT_NAMES.includes(event), `invalid event name "${event}"`);
if (!EVENT_NAMES.includes(event)) {
warn(`invalid event name "${event}"`);
return () => { };
}
return this.emitter.on(event, callback);
}
/**
Expand Down Expand Up @@ -12633,7 +12639,91 @@ class Checkout {
});
}
}
_Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checkout_onRequestLightboxClose = new WeakMap(), _Checkout_instances = new WeakSet(), _Checkout_showLightbox = async function _Checkout_showLightbox() {
_Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checkout_onRequestLightboxClose = new WeakMap(), _Checkout_instances = new WeakSet(), _Checkout_resolveLocale = function _Checkout_resolveLocale(options) {
if (isNullOrUndefined(options.locale))
return null;
if (!isNonEmptyString(options.locale)) {
warn(`invalid locale option "${options.locale}" - must be a non-empty string`);
return null;
}
return options.locale;
}, _Checkout_resolveTheme = function _Checkout_resolveTheme(options) {
if (isNullOrUndefined(options.theme))
return null;
if (!THEME_NAMES.includes(options.theme)) {
const list = THEME_NAMES.map(n => `"${n}"`).join(", ");
warn(`invalid theme option "${options.theme}" - must be one of ${list}`);
return null;
}
return options.theme;
}, _Checkout_resolveColors = function _Checkout_resolveColors(options) {
if (isNullOrUndefined(options.colors))
return null;
if (!isArray$1(options.colors)) {
warn(`invalid colors option "${options.colors}" - must be an array`);
return null;
}
for (let entry of options.colors) {
if (!isObject(entry)) {
warn(`invalid colors option item ${entry} - must be an object`);
return null;
}
if (!entry.hasOwnProperty("name")) {
warn(`invalid colors option item - missing 'name' field`);
return null;
}
if (!entry.hasOwnProperty("color")) {
warn(`invalid colors option item - missing 'color' field`);
return null;
}
if (!COLOR_NAMES.includes(entry.name)) {
const list = COLOR_NAMES.map(n => `"${n}"`).join(", ");
warn(`invalid color name "${entry.name}" - must be one of ${list}`);
return null;
}
if (!isNonEmptyString(entry.color)) {
warn(`invalid color value "${entry.color}" - must be a non-empty string`);
return null;
}
if (entry.color.includes("var(")) {
warn(`invalid color value "${entry.color}" - cannot include CSS variables`);
return null;
}
}
return options.colors;
}, _Checkout_resolvePopupOnMobile = function _Checkout_resolvePopupOnMobile(options) {
if (isNullOrUndefined(options.popupOnMobile))
return null;
if (!isBoolean(options.popupOnMobile)) {
warn(`invalid popupOnMobile option "${options.popupOnMobile}" - must be a boolean`);
return null;
}
return options.popupOnMobile;
}, _Checkout_resolveEndpoint = function _Checkout_resolveEndpoint(options) {
if (isNullOrUndefined(options.endpoint))
return null;
if (!isNonEmptyString(options.endpoint)) {
warn(`invalid endpoint option "${options.endpoint}" - must be a non-empty string`);
return null;
}
return options.endpoint;
}, _Checkout_resolveCloseOnClickOutside = function _Checkout_resolveCloseOnClickOutside(options) {
if (isNullOrUndefined(options.closeOnClickOutside))
return null;
if (!isBoolean(options.closeOnClickOutside)) {
warn(`invalid closeOnClickOutside option "${options.closeOnClickOutside}" - must be a boolean`);
return null;
}
return options.closeOnClickOutside;
}, _Checkout_resolveCloseOnEsc = function _Checkout_resolveCloseOnEsc(options) {
if (isNullOrUndefined(options.closeOnEsc))
return null;
if (!isBoolean(options.closeOnEsc)) {
warn(`invalid closeOnEsc option "${options.closeOnEsc}" - must be a boolean`);
return null;
}
return options.closeOnEsc;
}, _Checkout_showLightbox = async function _Checkout_showLightbox() {
if (!this.lightbox)
this.lightbox = new Lightbox();
if (this.closeOnClickOutside)
Expand Down Expand Up @@ -12695,7 +12785,7 @@ _Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checko
origin: url.origin,
path: url.pathname,
params: url.search,
version: "1.5.0",
version: "1.6.0",
});
await this.zoid.renderTo(window, container, popup ? "popup" : "iframe");
__classPrivateFieldSet(this, _Checkout_didRender, true, "f");
Expand Down Expand Up @@ -12900,7 +12990,7 @@ if (isEnvBrowser())
/**
* Current Tebex.js package version
*/
const version = "1.5.0";
const version = "1.6.0";
/**
* Tebex checkout API
*/
Expand Down
3 changes: 2 additions & 1 deletion dist/types/checkout.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Unsubscribe } from "nanoevents";
import { Lightbox } from "./lightbox";
import { type CssDimension, type Implements } from "./utils";
export declare const THEME_NAMES: readonly ["auto", "default", "light", "dark"];
Expand Down Expand Up @@ -104,7 +105,7 @@ export default class Checkout {
* Subscribe to Tebex checkout events, such as when the embed is closed or when a payment is completed.
* NOTE: None of these events should not be used to confirm actual receipt of payment - you should use Webhooks for that.
*/
on<T extends CheckoutEvent>(event: T, callback: CheckoutEventMap[T]): import("nanoevents").Unsubscribe;
on<T extends CheckoutEvent>(event: T, callback: CheckoutEventMap[T]): Unsubscribe;
/**
* Launch the Tebex checkout panel.
* On desktop, the panel will launch in a "lightbox" mode that covers the screen. On mobile, it will be opened as a new page.
Expand Down
4 changes: 4 additions & 0 deletions dist/types/utils/is.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export declare const isNullOrUndefined: (value: unknown) => value is null;
* @internal
*/
export declare const isString: (value: unknown) => value is string;
/**
* @internal
*/
export declare const isNonEmptyString: (value: unknown) => value is string;
/**
* @internal
*/
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tebexio/tebex.js",
"version": "1.5.0",
"version": "1.6.0",
"description": "Integrate Tebex Checkout directly into your own website or game using our embedded checkout experience.",
"type": "module",
"main": "dist/tebex.cjs",
Expand Down
Loading