@aurora-studio/sdk 0.1.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/.github/workflows/publish.yml +43 -0
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/eslint.config.mjs +6 -0
- package/package.json +23 -0
- package/src/index.ts +158 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Publish @aurora-studio/sdk to npm (trusted publishing via OIDC)
|
|
2
|
+
name: Publish to npm
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
push:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
id-token: write # Required for OIDC trusted publishing
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
publish:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: pnpm/action-setup@v4
|
|
20
|
+
with:
|
|
21
|
+
version: 9
|
|
22
|
+
|
|
23
|
+
- uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: "22"
|
|
26
|
+
registry-url: "https://registry.npmjs.org"
|
|
27
|
+
cache: "pnpm"
|
|
28
|
+
|
|
29
|
+
- run: pnpm install
|
|
30
|
+
|
|
31
|
+
- run: pnpm run build
|
|
32
|
+
|
|
33
|
+
- name: Remove private for publish
|
|
34
|
+
run: |
|
|
35
|
+
node -e "
|
|
36
|
+
const fs = require('fs');
|
|
37
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
38
|
+
delete pkg.private;
|
|
39
|
+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
|
|
40
|
+
"
|
|
41
|
+
|
|
42
|
+
- name: Publish to npm
|
|
43
|
+
run: npm publish --no-git-checks --access public
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marcel du Preez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @aurora-studio/sdk
|
|
2
|
+
|
|
3
|
+
Node.js SDK for Aurora Studio. Connect custom front-ends and storefronts to your Aurora data via the V1 API.
|
|
4
|
+
|
|
5
|
+
**Aurora** is an all-in-one, no-code platform for stores, marketplaces, CRMs, and more. Design your data, generate your app, automate workflows. Ship in hours, not months.
|
|
6
|
+
|
|
7
|
+
[**Sign up for Aurora**](https://aurora.mandeville.digital) — currently in beta testing and free.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @aurora-studio/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { AuroraClient } from "@aurora-studio/sdk";
|
|
19
|
+
|
|
20
|
+
const aurora = new AuroraClient({
|
|
21
|
+
baseUrl: "https://api.youraurora.com",
|
|
22
|
+
apiKey: "aur_xxx...",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// List tables
|
|
26
|
+
const tables = await aurora.tables.list();
|
|
27
|
+
|
|
28
|
+
// List records
|
|
29
|
+
const { data, total } = await aurora.tables("products").records.list({ limit: 10 });
|
|
30
|
+
|
|
31
|
+
// Get single record
|
|
32
|
+
const product = await aurora.tables("products").records.get("uuid");
|
|
33
|
+
|
|
34
|
+
// Create record
|
|
35
|
+
const created = await aurora.tables("products").records.create({ name: "New Product" });
|
|
36
|
+
|
|
37
|
+
// Store config and pages
|
|
38
|
+
const config = await aurora.store.config();
|
|
39
|
+
const pages = await aurora.store.pages.list();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API Surface
|
|
43
|
+
|
|
44
|
+
| Method | Description |
|
|
45
|
+
| ---------------------------------------------- | ------------------ |
|
|
46
|
+
| `client.tables.list()` | List tables |
|
|
47
|
+
| `client.tables(slug).records.list(opts)` | List records |
|
|
48
|
+
| `client.tables(slug).records.get(id)` | Get record |
|
|
49
|
+
| `client.tables(slug).records.create(data)` | Create record |
|
|
50
|
+
| `client.tables(slug).records.update(id, data)` | Update record |
|
|
51
|
+
| `client.tables(slug).records.delete(id)` | Delete record |
|
|
52
|
+
| `client.tables(slug).sectionViews.list()` | List section views |
|
|
53
|
+
| `client.views.list()` | List report views |
|
|
54
|
+
| `client.views(slug).data()` | Get view data |
|
|
55
|
+
| `client.reports.list()` | List reports |
|
|
56
|
+
| `client.reports(id).data()` | Get report data |
|
|
57
|
+
| `client.store.config()` | Get store config |
|
|
58
|
+
| `client.store.pages.list()` | List store pages |
|
|
59
|
+
| `client.store.pages.get(slug)` | Get store page |
|
|
60
|
+
|
|
61
|
+
Create API keys in Aurora Studio → Settings → API Keys.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aurora Studio SDK - Fluent API for custom front-ends and storefronts.
|
|
3
|
+
* Use with X-Api-Key authentication.
|
|
4
|
+
*/
|
|
5
|
+
export interface AuroraClientOptions {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class AuroraClient {
|
|
10
|
+
private baseUrl;
|
|
11
|
+
private apiKey;
|
|
12
|
+
constructor(options: AuroraClientOptions);
|
|
13
|
+
private req;
|
|
14
|
+
tables: ((slug: string) => {
|
|
15
|
+
records: {
|
|
16
|
+
list: (opts?: {
|
|
17
|
+
limit?: number;
|
|
18
|
+
offset?: number;
|
|
19
|
+
sort?: string;
|
|
20
|
+
order?: "asc" | "desc";
|
|
21
|
+
filter?: string;
|
|
22
|
+
}) => Promise<{
|
|
23
|
+
data: Record<string, unknown>[];
|
|
24
|
+
total: number;
|
|
25
|
+
limit: number;
|
|
26
|
+
offset: number;
|
|
27
|
+
}>;
|
|
28
|
+
get: (id: string) => Promise<Record<string, unknown>>;
|
|
29
|
+
create: (data: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
30
|
+
update: (id: string, data: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
31
|
+
delete: (id: string) => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
sectionViews: {
|
|
34
|
+
list: () => Promise<{
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
view_type: string;
|
|
38
|
+
config: unknown;
|
|
39
|
+
}[]>;
|
|
40
|
+
};
|
|
41
|
+
}) & {
|
|
42
|
+
list: () => Promise<{
|
|
43
|
+
slug: string;
|
|
44
|
+
name: string;
|
|
45
|
+
}[]>;
|
|
46
|
+
};
|
|
47
|
+
views: ((slug: string) => {
|
|
48
|
+
data: () => Promise<{
|
|
49
|
+
data: unknown[];
|
|
50
|
+
}>;
|
|
51
|
+
}) & {
|
|
52
|
+
list: () => Promise<{
|
|
53
|
+
slug: string;
|
|
54
|
+
name: string;
|
|
55
|
+
}[]>;
|
|
56
|
+
};
|
|
57
|
+
reports: ((id: string) => {
|
|
58
|
+
data: () => Promise<{
|
|
59
|
+
data: unknown[];
|
|
60
|
+
}>;
|
|
61
|
+
}) & {
|
|
62
|
+
list: () => Promise<{
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
config: unknown;
|
|
67
|
+
}[]>;
|
|
68
|
+
};
|
|
69
|
+
store: {
|
|
70
|
+
config: () => Promise<{
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
catalogTableSlug?: string;
|
|
73
|
+
displayField?: string;
|
|
74
|
+
listFields?: string[];
|
|
75
|
+
detailFields?: string[];
|
|
76
|
+
groupingFields?: string[];
|
|
77
|
+
branding?: {
|
|
78
|
+
name: string;
|
|
79
|
+
logo_url?: string;
|
|
80
|
+
accent_color?: string;
|
|
81
|
+
show_powered_by?: boolean;
|
|
82
|
+
};
|
|
83
|
+
theme?: {
|
|
84
|
+
primaryColor?: string;
|
|
85
|
+
fontFamily?: string;
|
|
86
|
+
spacingScale?: string;
|
|
87
|
+
};
|
|
88
|
+
}>;
|
|
89
|
+
pages: {
|
|
90
|
+
list: () => Promise<{
|
|
91
|
+
slug: string;
|
|
92
|
+
name: string;
|
|
93
|
+
}[]>;
|
|
94
|
+
get: (slug: string) => Promise<{
|
|
95
|
+
slug: string;
|
|
96
|
+
name: string;
|
|
97
|
+
blocks: unknown[];
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AA+CD,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,EAAE,mBAAmB;IAKxC,OAAO,CAAC,GAAG;IAQX,MAAM,UACG,MAAM;;0BAEK;gBACZ,KAAK,CAAC,EAAE,MAAM,CAAC;gBACf,MAAM,CAAC,EAAE,MAAM,CAAC;gBAChB,IAAI,CAAC,EAAE,MAAM,CAAC;gBACd,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;gBACvB,MAAM,CAAC,EAAE,MAAM,CAAC;aACjB;sBAES,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;uBACxB,MAAM;uBACN,MAAM;wBACL,MAAM;;sBAER,MAAM;2BAED,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;yBAEzB,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;yBAIrC,MAAM;;;;oBAII,MAAM;sBAAQ,MAAM;2BAAa,MAAM;wBAAU,OAAO;;;;;kBAO9C,MAAM;kBAAQ,MAAM;;MAEzD;IAEF,KAAK,UACI,MAAM;;kBACkB,OAAO,EAAE;;;;kBAEH,MAAM;kBAAQ,MAAM;;MACzD;IAEF,OAAO,QACA,MAAM;;kBACoB,OAAO,EAAE;;;;gBAIf,MAAM;kBAAQ,MAAM;0BAAgB,MAAM;oBAAU,OAAO;;MAKpF;IAEF,KAAK;;qBAGU,OAAO;+BACG,MAAM;2BACV,MAAM;yBACR,MAAM,EAAE;2BACN,MAAM,EAAE;6BACN,MAAM,EAAE;uBACd;gBACT,IAAI,EAAE,MAAM,CAAC;gBACb,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAClB,YAAY,CAAC,EAAE,MAAM,CAAC;gBACtB,eAAe,CAAC,EAAE,OAAO,CAAC;aAC3B;oBACO;gBAAE,YAAY,CAAC,EAAE,MAAM,CAAC;gBAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAAC,YAAY,CAAC,EAAE,MAAM,CAAA;aAAE;;;;sBAG5C,MAAM;sBAAQ,MAAM;;wBAC3C,MAAM;sBACC,MAAM;sBAAQ,MAAM;wBAAU,OAAO,EAAE;;;MAK5D;CACH"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aurora Studio SDK - Fluent API for custom front-ends and storefronts.
|
|
3
|
+
* Use with X-Api-Key authentication.
|
|
4
|
+
*/
|
|
5
|
+
function buildQuery(params) {
|
|
6
|
+
if (!params)
|
|
7
|
+
return "";
|
|
8
|
+
const search = new URLSearchParams();
|
|
9
|
+
for (const [k, v] of Object.entries(params)) {
|
|
10
|
+
if (v !== undefined && v !== "") {
|
|
11
|
+
search.set(k, String(v));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const s = search.toString();
|
|
15
|
+
return s ? `?${s}` : "";
|
|
16
|
+
}
|
|
17
|
+
async function request(baseUrl, apiKey, method, path, opts) {
|
|
18
|
+
const url = `${baseUrl.replace(/\/$/, "")}${path}${buildQuery(opts?.query)}`;
|
|
19
|
+
const res = await fetch(url, {
|
|
20
|
+
method,
|
|
21
|
+
headers: {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"X-Api-Key": apiKey,
|
|
24
|
+
},
|
|
25
|
+
body: opts?.body ? JSON.stringify(opts.body) : undefined,
|
|
26
|
+
});
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
const errBody = await res.text();
|
|
29
|
+
let msg;
|
|
30
|
+
try {
|
|
31
|
+
const j = JSON.parse(errBody);
|
|
32
|
+
msg = j?.error ?? errBody ?? res.statusText;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
msg = errBody || res.statusText;
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Aurora API ${res.status}: ${msg}`);
|
|
38
|
+
}
|
|
39
|
+
if (res.status === 204)
|
|
40
|
+
return undefined;
|
|
41
|
+
return res.json();
|
|
42
|
+
}
|
|
43
|
+
export class AuroraClient {
|
|
44
|
+
baseUrl;
|
|
45
|
+
apiKey;
|
|
46
|
+
constructor(options) {
|
|
47
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
48
|
+
this.apiKey = options.apiKey;
|
|
49
|
+
}
|
|
50
|
+
req(method, path, opts) {
|
|
51
|
+
return request(this.baseUrl, this.apiKey, method, path, opts);
|
|
52
|
+
}
|
|
53
|
+
tables = Object.assign((slug) => ({
|
|
54
|
+
records: {
|
|
55
|
+
list: (opts) => this.req("GET", `/v1/tables/${slug}/records`, { query: opts }),
|
|
56
|
+
get: (id) => this.req("GET", `/v1/tables/${slug}/records/${id}`),
|
|
57
|
+
create: (data) => this.req("POST", `/v1/tables/${slug}/records`, { body: data }),
|
|
58
|
+
update: (id, data) => this.req("PATCH", `/v1/tables/${slug}/records/${id}`, {
|
|
59
|
+
body: data,
|
|
60
|
+
}),
|
|
61
|
+
delete: (id) => this.req("DELETE", `/v1/tables/${slug}/records/${id}`),
|
|
62
|
+
},
|
|
63
|
+
sectionViews: {
|
|
64
|
+
list: () => this.req("GET", `/v1/tables/${slug}/views`),
|
|
65
|
+
},
|
|
66
|
+
}), {
|
|
67
|
+
list: () => this.req("GET", "/v1/tables"),
|
|
68
|
+
});
|
|
69
|
+
views = Object.assign((slug) => ({
|
|
70
|
+
data: () => this.req("GET", `/v1/views/${slug}/data`),
|
|
71
|
+
}), { list: () => this.req("GET", "/v1/views") });
|
|
72
|
+
reports = Object.assign((id) => ({
|
|
73
|
+
data: () => this.req("GET", `/v1/reports/${id}/data`),
|
|
74
|
+
}), {
|
|
75
|
+
list: () => this.req("GET", "/v1/reports"),
|
|
76
|
+
});
|
|
77
|
+
store = {
|
|
78
|
+
config: () => this.req("GET", "/v1/store/config"),
|
|
79
|
+
pages: {
|
|
80
|
+
list: () => this.req("GET", "/v1/store/pages"),
|
|
81
|
+
get: (slug) => this.req("GET", `/v1/store/pages/${slug}`),
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aurora-studio/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"prepare": "tsc",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "eslint src --max-warnings 0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@eslint/js": "^9.15.0",
|
|
16
|
+
"eslint": "^9.15.0",
|
|
17
|
+
"typescript": "^5.3.3",
|
|
18
|
+
"typescript-eslint": "^8.15.0"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aurora Studio SDK - Fluent API for custom front-ends and storefronts.
|
|
3
|
+
* Use with X-Api-Key authentication.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface AuroraClientOptions {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
apiKey: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type QueryParams = Record<string, string | number | boolean | undefined>;
|
|
12
|
+
|
|
13
|
+
function buildQuery(params?: QueryParams): string {
|
|
14
|
+
if (!params) return "";
|
|
15
|
+
const search = new URLSearchParams();
|
|
16
|
+
for (const [k, v] of Object.entries(params)) {
|
|
17
|
+
if (v !== undefined && v !== "") {
|
|
18
|
+
search.set(k, String(v));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const s = search.toString();
|
|
22
|
+
return s ? `?${s}` : "";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function request<T>(
|
|
26
|
+
baseUrl: string,
|
|
27
|
+
apiKey: string,
|
|
28
|
+
method: string,
|
|
29
|
+
path: string,
|
|
30
|
+
opts?: { body?: unknown; query?: QueryParams }
|
|
31
|
+
): Promise<T> {
|
|
32
|
+
const url = `${baseUrl.replace(/\/$/, "")}${path}${buildQuery(opts?.query)}`;
|
|
33
|
+
const res = await fetch(url, {
|
|
34
|
+
method,
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
"X-Api-Key": apiKey,
|
|
38
|
+
},
|
|
39
|
+
body: opts?.body ? JSON.stringify(opts.body) : undefined,
|
|
40
|
+
});
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
const errBody = await res.text();
|
|
43
|
+
let msg: string;
|
|
44
|
+
try {
|
|
45
|
+
const j = JSON.parse(errBody);
|
|
46
|
+
msg = (j?.error as string) ?? errBody ?? res.statusText;
|
|
47
|
+
} catch {
|
|
48
|
+
msg = errBody || res.statusText;
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`Aurora API ${res.status}: ${msg}`);
|
|
51
|
+
}
|
|
52
|
+
if (res.status === 204) return undefined as T;
|
|
53
|
+
return res.json() as Promise<T>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class AuroraClient {
|
|
57
|
+
private baseUrl: string;
|
|
58
|
+
private apiKey: string;
|
|
59
|
+
|
|
60
|
+
constructor(options: AuroraClientOptions) {
|
|
61
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
62
|
+
this.apiKey = options.apiKey;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private req<T>(
|
|
66
|
+
method: string,
|
|
67
|
+
path: string,
|
|
68
|
+
opts?: { body?: unknown; query?: QueryParams }
|
|
69
|
+
): Promise<T> {
|
|
70
|
+
return request<T>(this.baseUrl, this.apiKey, method, path, opts);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
tables = Object.assign(
|
|
74
|
+
(slug: string) => ({
|
|
75
|
+
records: {
|
|
76
|
+
list: (opts?: {
|
|
77
|
+
limit?: number;
|
|
78
|
+
offset?: number;
|
|
79
|
+
sort?: string;
|
|
80
|
+
order?: "asc" | "desc";
|
|
81
|
+
filter?: string;
|
|
82
|
+
}) =>
|
|
83
|
+
this.req<{
|
|
84
|
+
data: Record<string, unknown>[];
|
|
85
|
+
total: number;
|
|
86
|
+
limit: number;
|
|
87
|
+
offset: number;
|
|
88
|
+
}>("GET", `/v1/tables/${slug}/records`, { query: opts as QueryParams }),
|
|
89
|
+
get: (id: string) =>
|
|
90
|
+
this.req<Record<string, unknown>>("GET", `/v1/tables/${slug}/records/${id}`),
|
|
91
|
+
create: (data: Record<string, unknown>) =>
|
|
92
|
+
this.req<Record<string, unknown>>("POST", `/v1/tables/${slug}/records`, { body: data }),
|
|
93
|
+
update: (id: string, data: Record<string, unknown>) =>
|
|
94
|
+
this.req<Record<string, unknown>>("PATCH", `/v1/tables/${slug}/records/${id}`, {
|
|
95
|
+
body: data,
|
|
96
|
+
}),
|
|
97
|
+
delete: (id: string) => this.req<void>("DELETE", `/v1/tables/${slug}/records/${id}`),
|
|
98
|
+
},
|
|
99
|
+
sectionViews: {
|
|
100
|
+
list: () =>
|
|
101
|
+
this.req<Array<{ id: string; name: string; view_type: string; config: unknown }>>(
|
|
102
|
+
"GET",
|
|
103
|
+
`/v1/tables/${slug}/views`
|
|
104
|
+
),
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
{
|
|
108
|
+
list: () => this.req<Array<{ slug: string; name: string }>>("GET", "/v1/tables"),
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
views = Object.assign(
|
|
113
|
+
(slug: string) => ({
|
|
114
|
+
data: () => this.req<{ data: unknown[] }>("GET", `/v1/views/${slug}/data`),
|
|
115
|
+
}),
|
|
116
|
+
{ list: () => this.req<Array<{ slug: string; name: string }>>("GET", "/v1/views") }
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
reports = Object.assign(
|
|
120
|
+
(id: string) => ({
|
|
121
|
+
data: () => this.req<{ data: unknown[] }>("GET", `/v1/reports/${id}/data`),
|
|
122
|
+
}),
|
|
123
|
+
{
|
|
124
|
+
list: () =>
|
|
125
|
+
this.req<Array<{ id: string; name: string; description?: string; config: unknown }>>(
|
|
126
|
+
"GET",
|
|
127
|
+
"/v1/reports"
|
|
128
|
+
),
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
store = {
|
|
133
|
+
config: () =>
|
|
134
|
+
this.req<{
|
|
135
|
+
enabled: boolean;
|
|
136
|
+
catalogTableSlug?: string;
|
|
137
|
+
displayField?: string;
|
|
138
|
+
listFields?: string[];
|
|
139
|
+
detailFields?: string[];
|
|
140
|
+
groupingFields?: string[];
|
|
141
|
+
branding?: {
|
|
142
|
+
name: string;
|
|
143
|
+
logo_url?: string;
|
|
144
|
+
accent_color?: string;
|
|
145
|
+
show_powered_by?: boolean;
|
|
146
|
+
};
|
|
147
|
+
theme?: { primaryColor?: string; fontFamily?: string; spacingScale?: string };
|
|
148
|
+
}>("GET", "/v1/store/config"),
|
|
149
|
+
pages: {
|
|
150
|
+
list: () => this.req<Array<{ slug: string; name: string }>>("GET", "/v1/store/pages"),
|
|
151
|
+
get: (slug: string) =>
|
|
152
|
+
this.req<{ slug: string; name: string; blocks: unknown[] }>(
|
|
153
|
+
"GET",
|
|
154
|
+
`/v1/store/pages/${slug}`
|
|
155
|
+
),
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"rootDir": "./src"
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*"],
|
|
15
|
+
"exclude": ["node_modules", "dist"]
|
|
16
|
+
}
|