flowlink-auth 2.6.9

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/dist/api.js ADDED
@@ -0,0 +1,55 @@
1
+ // src/init.js
2
+ var CONFIG = null;
3
+ function getConfigSafe() {
4
+ return CONFIG;
5
+ }
6
+ function getCSRFToken() {
7
+ return CONFIG?.csrfToken || null;
8
+ }
9
+
10
+ // src/api.js
11
+ var makeApi = () => {
12
+ const cfg = getConfigSafe();
13
+ return {
14
+ call: async (path, opts = {}) => {
15
+ if (!cfg) {
16
+ return { status: 400, body: { error: "flowlink-auth: SDK not initialized (publishable key missing)" } };
17
+ }
18
+ if (!path || typeof path !== "string") {
19
+ return { status: 400, body: { error: "Invalid API path" } };
20
+ }
21
+ if (path.startsWith("//") || path.startsWith("http")) {
22
+ return { status: 400, body: { error: "Invalid API path" } };
23
+ }
24
+ const headers = {
25
+ "Content-Type": "application/json",
26
+ "x-publishable-key": cfg.publishableKey,
27
+ ...opts.headers || {}
28
+ };
29
+ const csrfToken = getCSRFToken();
30
+ if (csrfToken && opts.method && opts.method.toUpperCase() !== "GET") {
31
+ headers["x-csrf-token"] = csrfToken;
32
+ }
33
+ try {
34
+ const fullUrl = new URL(cfg.baseUrl + path).href;
35
+ const res = await fetch(fullUrl, {
36
+ ...opts,
37
+ headers,
38
+ // Security: Include credentials for cookie-based auth
39
+ credentials: "include",
40
+ // Security: Enforce no referrer for sensitive requests
41
+ referrerPolicy: "strict-origin-when-cross-origin"
42
+ });
43
+ const body = await res.json().catch(() => null);
44
+ return { status: res.status, body };
45
+ } catch (err) {
46
+ console.error("API call failed:", err.message);
47
+ return { status: 500, body: { error: "Request failed. Please try again." } };
48
+ }
49
+ }
50
+ };
51
+ };
52
+ export {
53
+ makeApi
54
+ };
55
+