eptaadmin-sdk 0.1.2 → 0.1.4
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/README.md +16 -1
- package/package.json +1 -1
- package/src/index.js +27 -3
package/README.md
CHANGED
|
@@ -6,7 +6,13 @@ This SDK is currently **read-only**: it fetches workspaces, data sources, and th
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```sh
|
|
10
|
+
npm install eptaadmin-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The package is published on the [npm registry](https://www.npmjs.com/package/eptaadmin-sdk) and versioned automatically from this repository (see `.github/workflows/publish-sdk.yml`) — every change under `sdk/js/` merged to `main` bumps the version and publishes a new release.
|
|
14
|
+
|
|
15
|
+
If you'd rather work against an unreleased change, point at the local folder instead:
|
|
10
16
|
|
|
11
17
|
```json
|
|
12
18
|
{
|
|
@@ -68,6 +74,15 @@ EptaAdmin stores each column of a data source as its own independent list of val
|
|
|
68
74
|
|
|
69
75
|
If your project needs row-aligned records, build them yourself from the columns you know are meant to line up (e.g. by index), since EptaAdmin itself doesn't guarantee that alignment.
|
|
70
76
|
|
|
77
|
+
## Image values
|
|
78
|
+
|
|
79
|
+
A column of type "image" stores each value as a URL. The SDK automatically rewrites these to absolute, API-key-authenticated URLs (`{baseUrl}/api/v1/workspaces/{slug}/uploads/{file}`) before returning them, so they're directly usable outside a browser session — you never see or depend on the internal browser-app route these are stored against:
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const avatars = await client.getValue("acme/clients/avatar");
|
|
83
|
+
// ["https://your-eptaadmin-instance.example.com/api/v1/workspaces/acme/uploads/6f2dff985af5d290.png"]
|
|
84
|
+
```
|
|
85
|
+
|
|
71
86
|
## Error handling
|
|
72
87
|
|
|
73
88
|
Failed requests reject with an `EptaAdminError` carrying the HTTP status and the server's error message:
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -11,6 +11,26 @@ export class EptaAdminError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// Image column values are stored as the same URL the browser UI uses
|
|
15
|
+
// (/workspaces/{slug}/uploads/{file}), which only accepts a session
|
|
16
|
+
// cookie — useless to an external caller like this SDK, which has none.
|
|
17
|
+
// Rewrite matching values to the API-key-authenticated equivalent instead
|
|
18
|
+
// of just prefixing baseUrl onto the internal route, so callers get a
|
|
19
|
+
// working absolute URL without depending on (or seeing) that internal
|
|
20
|
+
// browser-route shape.
|
|
21
|
+
const uploadUrlPattern = /^\/workspaces\/([^/]+)\/uploads\/(.+)$/;
|
|
22
|
+
|
|
23
|
+
function resolveImageURL(value, baseUrl) {
|
|
24
|
+
if (typeof value !== "string") return value;
|
|
25
|
+
const match = value.match(uploadUrlPattern);
|
|
26
|
+
if (!match) return value;
|
|
27
|
+
return `${baseUrl}/api/v1/workspaces/${match[1]}/uploads/${match[2]}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resolveImageURLs(value, baseUrl) {
|
|
31
|
+
return Array.isArray(value) ? value.map((v) => resolveImageURL(v, baseUrl)) : resolveImageURL(value, baseUrl);
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
export class EptaAdminClient {
|
|
15
35
|
/**
|
|
16
36
|
* @param {{ apiKey: string, baseUrl?: string }} options
|
|
@@ -53,10 +73,14 @@ export class EptaAdminClient {
|
|
|
53
73
|
* between columns), so the response mirrors that: `columns` is a plain
|
|
54
74
|
* object of `{ [columnKey]: value[] }`.
|
|
55
75
|
*/
|
|
56
|
-
getDataSource(workspaceSlug, dataSourceSlug) {
|
|
57
|
-
|
|
76
|
+
async getDataSource(workspaceSlug, dataSourceSlug) {
|
|
77
|
+
const body = await this._request(
|
|
58
78
|
`/api/v1/workspaces/${encodeURIComponent(workspaceSlug)}/datasources/${encodeURIComponent(dataSourceSlug)}`
|
|
59
79
|
);
|
|
80
|
+
for (const key of Object.keys(body.columns || {})) {
|
|
81
|
+
body.columns[key] = resolveImageURLs(body.columns[key], this.baseUrl);
|
|
82
|
+
}
|
|
83
|
+
return body;
|
|
60
84
|
}
|
|
61
85
|
|
|
62
86
|
/**
|
|
@@ -83,6 +107,6 @@ export class EptaAdminClient {
|
|
|
83
107
|
url += `/${encodeURIComponent(index)}`;
|
|
84
108
|
}
|
|
85
109
|
const body = await this._request(url);
|
|
86
|
-
return index !== undefined ? body.value : body.values;
|
|
110
|
+
return resolveImageURLs(index !== undefined ? body.value : body.values, this.baseUrl);
|
|
87
111
|
}
|
|
88
112
|
}
|