eptaadmin-sdk 0.1.6 → 0.1.8

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/package.json +1 -1
  2. package/src/index.js +16 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eptaadmin-sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Client SDK for reading your EptaAdmin workspace data from your own project.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -18,17 +18,26 @@ export class EptaAdminError extends Error {
18
18
  // of just prefixing baseUrl onto the internal route, so callers get a
19
19
  // working absolute URL without depending on (or seeing) that internal
20
20
  // browser-route shape.
21
+ //
22
+ // The key travels as a "?apiKey=" query parameter, not an Authorization
23
+ // header, because the whole point of this URL is to be usable directly as
24
+ // an <img>/<video> src — a browser's native resource fetch for those never
25
+ // attaches custom headers, so a header-only scheme would make the URL this
26
+ // returns unusable for that (the single most common reason to want it).
21
27
  const uploadUrlPattern = /^\/workspaces\/([^/]+)\/uploads\/(.+)$/;
22
28
 
23
- function resolveImageURL(value, baseUrl) {
29
+ function resolveImageURL(value, baseUrl, apiKey) {
24
30
  if (typeof value !== "string") return value;
25
31
  const match = value.match(uploadUrlPattern);
26
32
  if (!match) return value;
27
- return `${baseUrl}/api/v1/workspaces/${match[1]}/uploads/${match[2]}`;
33
+ const url = `${baseUrl}/api/v1/workspaces/${match[1]}/uploads/${match[2]}`;
34
+ return apiKey ? `${url}?apiKey=${encodeURIComponent(apiKey)}` : url;
28
35
  }
29
36
 
30
- function resolveImageURLs(value, baseUrl) {
31
- return Array.isArray(value) ? value.map((v) => resolveImageURL(v, baseUrl)) : resolveImageURL(value, baseUrl);
37
+ function resolveImageURLs(value, baseUrl, apiKey) {
38
+ return Array.isArray(value)
39
+ ? value.map((v) => resolveImageURL(v, baseUrl, apiKey))
40
+ : resolveImageURL(value, baseUrl, apiKey);
32
41
  }
33
42
 
34
43
  // Populated by build tooling (see eptaadmin-sdk/vite) via a bundler `define`
@@ -95,7 +104,7 @@ export class EptaAdminClient {
95
104
  `/api/v1/workspaces/${encodeURIComponent(workspaceSlug)}/datasources/${encodeURIComponent(dataSourceSlug)}`
96
105
  );
97
106
  for (const key of Object.keys(body.columns || {})) {
98
- body.columns[key] = resolveImageURLs(body.columns[key], this.baseUrl);
107
+ body.columns[key] = resolveImageURLs(body.columns[key], this.baseUrl, this.apiKey);
99
108
  }
100
109
  return body;
101
110
  }
@@ -127,7 +136,7 @@ export class EptaAdminClient {
127
136
  if (index !== undefined && result === undefined) {
128
137
  throw new EptaAdminError(`index ${index} out of range for column "${column}"`, 404);
129
138
  }
130
- return resolveImageURLs(result, this.baseUrl);
139
+ return resolveImageURLs(result, this.baseUrl, this.apiKey);
131
140
  }
132
141
 
133
142
  let url =
@@ -138,6 +147,6 @@ export class EptaAdminClient {
138
147
  url += `/${encodeURIComponent(index)}`;
139
148
  }
140
149
  const body = await this._request(url);
141
- return resolveImageURLs(index !== undefined ? body.value : body.values, this.baseUrl);
150
+ return resolveImageURLs(index !== undefined ? body.value : body.values, this.baseUrl, this.apiKey);
142
151
  }
143
152
  }