torta-js 1.1.0 → 1.2.0

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.
Files changed (2) hide show
  1. package/index.js +12 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3,14 +3,20 @@
3
3
  *
4
4
  * Usage:
5
5
  * import { createClient } from 'torta-js';
6
- * const client = createClient('http://localhost:8000', 'your-api-key');
6
+ *
7
+ * const client = createClient(
8
+ * 'http://localhost:8000/SHORT_KEY', // base URL with short public key
9
+ * 'pk_PUBLISHABLE_KEY' // publishable key — sent as X-Publishable-Key header
10
+ * );
7
11
  *
8
12
  * After publish, from CDN:
9
13
  * import { createClient } from 'https://cdn.jsdelivr.net/npm/torta-js/+esm';
10
14
  */
11
15
 
12
- export function createClient(baseUrl, apiKey) {
13
- const base = `${baseUrl}/${apiKey}`;
16
+ export function createClient(baseUrl, publishableKey) {
17
+ // baseUrl already contains the short public key in the path,
18
+ // e.g. "http://localhost:8000/0c39355b5b6b5ac05bbc"
19
+ const base = baseUrl.replace(/\/$/, '');
14
20
 
15
21
  // ─── User cache ───────────────────────────────────────────────────────────
16
22
  let _user = undefined; // undefined = never fetched, null = not logged in
@@ -21,7 +27,9 @@ export function createClient(baseUrl, apiKey) {
21
27
  const options = {
22
28
  method,
23
29
  credentials: "include",
24
- headers: {},
30
+ headers: {
31
+ "X-Publishable-Key": publishableKey,
32
+ },
25
33
  };
26
34
  if (body !== undefined) {
27
35
  options.headers["Content-Type"] = "application/json";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "torta-js",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "JavaScript client SDK for Torta CRM — connect your storefront to the API in one line",
5
5
  "type": "module",
6
6
  "main": "index.js",