Repository navigation
Getting Started
This page shows how to add Selldone Core to a project, which meta tags it needs, what SelldoneCore.Setup() does, and how to import models, enums and helpers. If you use the Storefront SDK or the Backoffice SDK, Core is installed as a dependency and you can jump to Import paths.
- A browser application. Core reads
<meta>tags fromdocument.headand useswindow,localStorageand cookies. - A bundler that compiles TypeScript from
node_modulesand handles image imports, such as Vite. The package entry point (main) isindex.ts, and some enums import.svg/.pngassets.types/assets.d.tsdeclares these modules for TypeScript.
npm install @selldone/core-js
# or
yarn add @selldone/core-jsRuntime dependencies (axios, lodash-es, chroma-js, print-js, html-to-image, register-service-worker) are installed with it.
SelldoneCore.Setup() builds API and CDN URLs from meta tags in <head>:
<!-- 🪁 Service Origin -->
<meta content="https://selldone.com" name="service-url">
<!-- 🎯 APIs -->
<meta content="https://gapi.selldone.com" name="selldone-gapi">
<meta content="https://xapi.selldone.com" name="selldone-xapi">
<meta content="https://iframe.selldone.com" name="selldone-iframe">
<meta content="https://capi.selldone.com" name="selldone-capi">
<!-- 🌍 CDNs -->
<meta content="https://selldone.com/cdn-shop-images-1" name="selldone-cdn-images">
<meta content="https://selldone.com/cdn-shop-jsons-1" name="selldone-cdn-jsons">
<meta content="https://selldone.com/cdn-videos" name="selldone-cdn-videos">
<meta content="https://selldone.com/cdn-shop-temp-files" name="selldone-cdn-temp-files">
<meta content="https://selldone.com/cdn-ar" name="selldone-cdn-ar">
<meta content="https://selldone.com/cdn-id" name="selldone-cdn-id">
<meta content="true" name="storage-redirect">
<meta content="https://cdn.selldone.com" name="storage-redirect-host">
<meta content="true" name="storage-redirect-thumbnails">| Tag | Needed by | If missing |
|---|---|---|
service-url |
SetupService.MainServiceUrl(), CDN, URLS, axios headers |
Setup() throws The service url is not defined in [service-url] meta tag!
|
selldone-iframe |
URLS |
Throws. |
selldone-cdn-images, selldone-cdn-jsons, selldone-cdn-ar
|
CDN |
Throws. |
selldone-cdn-videos, selldone-cdn-temp-files, selldone-cdn-id
|
CDN |
Console warning only. |
selldone-gapi |
GAPI / window.$selldone.gapi
|
GAPI URLs are invalid. |
selldone-xapi, selldone-capi
|
Storefront SDK, Community SDK | Not used by Core itself. |
csrf-token |
X-CSRF-TOKEN header |
Console warning CSRF token not found!
|
When no <meta> tag exists, SetupService.GetMetaValue() falls back to window.selldone_config[name], which is handy for embedded widgets. Storefronts deployed on Selldone (Layouts) receive these tags automatically.
import { SelldoneCore } from "@selldone/core-js";
SelldoneCore.Setup();Setup() accepts one optional argument, { i18n }. Pass your i18n instance (an object with a t(key, values) method, such as i18n.global from vue-i18n) so helpers like GlobalRules and MapHelper can translate their messages:
import { createI18n } from "vue-i18n";
const i18n = createI18n({ /* … */ });
SelldoneCore.Setup({ i18n: i18n.global });- Logs
Selldone® Core: V…to the console. - Stores the i18n instance as
window.$i18n_global(when provided). - Sets
window.axioswith defaultAccess-Control-Allow-Origin/Access-Control-Allow-Headersheaders and, if acsrf-tokenmeta tag exists,X-CSRF-TOKEN. - Creates
window.CDN(media URLs),window.URLS(service URLs) andwindow.GAPI(general API URL builder). - Creates
window.$selldone = { gapi: new Gapi() }. - Registers the cookie helper as
window.$cookies.
Importing SelldoneCore also installs console.style() for styled console messages.
The package root re-exports SelldoneCore and everything in helper/, models/, server/, utils/ and prototypes/:
import { SelldoneCore, APIAbstract, SetupService, PriceHelper, DateConverter } from "@selldone/core-js";
import type { Shop, Product, ProductVariant, Basket, Customer } from "@selldone/core-js";Import enums, gapi/, timeserie/, types/ and default exports by their file path:
import { Currency, type ICurrency } from "@selldone/core-js/enums/payment/Currency";
import { Language } from "@selldone/core-js/enums/language/Language";
import { ProductType } from "@selldone/core-js/enums/product/ProductType";
import { StorefrontRoutesName } from "@selldone/core-js/enums/route/StorefrontRoutesName";
import { TimeSeries } from "@selldone/core-js/timeserie/TimeSeries";
import GlobalRules from "@selldone/core-js/helper/rules/GlobalRules";
import type { IReturn } from "@selldone/core-js/types/route/return.type";Deep imports are also the pattern used inside the Selldone SDKs, for example @selldone/core-js/models/shop/product/product.model.
Note
Importing the package root has side effects: it installs prototype extensions such as Array.prototype.limit(), Array.prototype.uniqueByKey() and Date.prototype.addDays(). See Helpers and Utilities.
import { SelldoneCore, CurrencyHelper, DateConverter } from "@selldone/core-js";
import { Currency } from "@selldone/core-js/enums/payment/Currency";
import { Language } from "@selldone/core-js/enums/language/Language";
SelldoneCore.Setup();
console.log(Currency.USD.name, Currency.USD.unicode, Currency.USD.floats); // "global.currency.USD" "$" 2
console.log(Language.de.title, Language.de.dir, Language.de.full_locale); // "Deutsch" "ltr" "de-DE"
console.log(CurrencyHelper.ConvertToString(1999.9, "USD")); // "$1,999.90"
console.log(DateConverter.getFromNowString(new Date(Date.now() - 3600e3), "en-US")); // "1 hour ago"
window.$selldone.gapi.fetchCountries().then((countries) => {
// [{ name, alpha2, alpha3, numeric, currency: string[] }, …]
});