@noaignite/react-centra-checkout
Version:
React components and helpers for Centra checkout api
65 lines (64 loc) • 1.99 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/ApiClient.ts
var ApiClient_exports = {};
__export(ApiClient_exports, {
ApiClient: () => ApiClient
});
module.exports = __toCommonJS(ApiClient_exports);
var ApiClient = class _ApiClient {
baseUrl;
headers;
options;
static _default;
constructor(baseUrl = "", options = {}) {
this.baseUrl = baseUrl;
this.options = options;
this.headers = new Headers({
Accept: "application/json",
"Content-Type": "application/json",
...this.options.headers
});
}
request = async (method, endpoint, data = {}) => {
const response = await fetch(`${this.baseUrl}/${endpoint}`, {
...this.options,
headers: this.headers,
mode: "cors",
method,
body: ["POST", "PUT"].includes(method) ? JSON.stringify(data) : void 0
});
const json = await response.json();
return json;
};
static get default() {
if (!_ApiClient._default) {
_ApiClient._default = new _ApiClient();
}
return _ApiClient._default;
}
get default() {
return _ApiClient.default;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ApiClient
});
//# sourceMappingURL=ApiClient.cjs.map