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.
- package/index.js +12 -4
- 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
|
-
*
|
|
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,
|
|
13
|
-
|
|
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";
|