@tapstack/db 1.0.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.
@@ -0,0 +1,21 @@
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2
+ export interface RequestInterceptor {
3
+ onFulfilled?: (value: InternalAxiosRequestConfig) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;
4
+ onRejected?: (error: any) => any;
5
+ }
6
+ export interface ResponseInterceptor {
7
+ onFulfilled?: (value: AxiosResponse) => AxiosResponse | Promise<AxiosResponse>;
8
+ onRejected?: (error: any) => any;
9
+ }
10
+ export interface BaseClientConfig extends AxiosRequestConfig {
11
+ baseURL: string;
12
+ apiKey: string;
13
+ /** Custom request interceptors */
14
+ requestInterceptors?: RequestInterceptor[];
15
+ /** Custom response interceptors */
16
+ responseInterceptors?: ResponseInterceptor[];
17
+ }
18
+ export declare class BaseClient {
19
+ protected readonly client: AxiosInstance;
20
+ constructor(config: BaseClientConfig);
21
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BaseClient = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class BaseClient {
9
+ constructor(config) {
10
+ const { apiKey, requestInterceptors, responseInterceptors, ...axiosConfig } = config;
11
+ this.client = axios_1.default.create({
12
+ headers: {
13
+ Authorization: `Bearer ${apiKey}`,
14
+ ...(axiosConfig.headers || {})
15
+ },
16
+ ...axiosConfig
17
+ });
18
+ requestInterceptors?.forEach((interceptor) => {
19
+ this.client.interceptors.request.use(interceptor.onFulfilled, interceptor.onRejected);
20
+ });
21
+ responseInterceptors?.forEach((interceptor) => {
22
+ this.client.interceptors.response.use(interceptor.onFulfilled, interceptor.onRejected);
23
+ });
24
+ }
25
+ }
26
+ exports.BaseClient = BaseClient;
@@ -0,0 +1 @@
1
+ export * from './client';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const axios_1 = __importDefault(require("axios"));
7
+ const index_1 = require("../index");
8
+ jest.mock('axios');
9
+ const mockedCreate = axios_1.default.create;
10
+ describe('TapstackDBClient', () => {
11
+ const apiClient = {
12
+ get: jest.fn(),
13
+ post: jest.fn(),
14
+ put: jest.fn(),
15
+ delete: jest.fn(),
16
+ };
17
+ let client;
18
+ beforeEach(() => {
19
+ mockedCreate.mockReturnValue(apiClient);
20
+ client = new index_1.TapstackDBClient({ baseURL: 'http://example.com', apiKey: 'token' });
21
+ });
22
+ afterEach(() => {
23
+ jest.clearAllMocks();
24
+ });
25
+ it('getObject calls axios.get with correct path', async () => {
26
+ await client.getObject('item');
27
+ expect(apiClient.get).toHaveBeenCalledWith('/system/item');
28
+ });
29
+ it('getAllObjects calls axios.get on /system', async () => {
30
+ await client.getAllObjects();
31
+ expect(apiClient.get).toHaveBeenCalledWith('/system');
32
+ });
33
+ it('createObject posts to /system', async () => {
34
+ const data = { name: 'test' };
35
+ await client.createObject(data);
36
+ expect(apiClient.post).toHaveBeenCalledWith('/system', data);
37
+ });
38
+ it('updateObject puts to correct path', async () => {
39
+ await client.updateObject('item', { a: 1 });
40
+ expect(apiClient.put).toHaveBeenCalledWith('/system/item', { a: 1 });
41
+ });
42
+ it('deleteObject deletes from correct path', async () => {
43
+ await client.deleteObject('item');
44
+ expect(apiClient.delete).toHaveBeenCalledWith('/system/item');
45
+ });
46
+ it('getFields calls axios.get with fields path', async () => {
47
+ await client.getFields('item');
48
+ expect(apiClient.get).toHaveBeenCalledWith('/system/item/fields');
49
+ });
50
+ it('getField calls axios.get with field id', async () => {
51
+ await client.getField('item', '1');
52
+ expect(apiClient.get).toHaveBeenCalledWith('/system/item/fields/1');
53
+ });
54
+ it('createField posts to fields path', async () => {
55
+ await client.createField('item', { name: 'field' });
56
+ expect(apiClient.post).toHaveBeenCalledWith('/system/item/fields', { name: 'field' });
57
+ });
58
+ it('updateField puts to specific field path', async () => {
59
+ await client.updateField('item', '1', { name: 'f' });
60
+ expect(apiClient.put).toHaveBeenCalledWith('/system/item/fields/1', { name: 'f' });
61
+ });
62
+ it('deleteField deletes the field path', async () => {
63
+ await client.deleteField('item', '1');
64
+ expect(apiClient.delete).toHaveBeenCalledWith('/system/item/fields/1');
65
+ });
66
+ it('query posts to slug', async () => {
67
+ const variables = { a: 1 };
68
+ await client.query('item', variables);
69
+ expect(apiClient.post).toHaveBeenCalledWith('/item', variables);
70
+ });
71
+ });
@@ -0,0 +1,29 @@
1
+ export * from './types';
2
+ export * from './modules/objects';
3
+ export * from './modules/fields';
4
+ export * from './modules/records';
5
+ import { AxiosResponse } from 'axios';
6
+ import { BaseClient, BaseClientConfig } from '@tapstack/core';
7
+ import { ObjectModule } from './modules/objects';
8
+ import { FieldModule } from './modules/fields';
9
+ import { RecordModule } from './modules/records';
10
+ import { CreateFieldPayload, CreateObjectPayload } from './types';
11
+ export interface TapstackDBClientConfig extends BaseClientConfig {
12
+ }
13
+ export declare class TapstackDBClient extends BaseClient {
14
+ readonly objects: ObjectModule;
15
+ readonly fields: FieldModule;
16
+ readonly records: RecordModule;
17
+ constructor(config: TapstackDBClientConfig);
18
+ getObject(slug: string): Promise<AxiosResponse<any>>;
19
+ getAllObjects(): Promise<AxiosResponse<any>>;
20
+ createObject(data: CreateObjectPayload): Promise<AxiosResponse<any>>;
21
+ updateObject(slug: string, data: Partial<CreateObjectPayload>): Promise<AxiosResponse<any>>;
22
+ deleteObject(slug: string): Promise<AxiosResponse<any>>;
23
+ getFields(slug: string): Promise<AxiosResponse<any>>;
24
+ getField(slug: string, fieldID: string): Promise<AxiosResponse<any>>;
25
+ createField(slug: string, data: CreateFieldPayload): Promise<AxiosResponse<any>>;
26
+ updateField(slug: string, fieldID: string, data: Partial<CreateFieldPayload>): Promise<AxiosResponse<any>>;
27
+ deleteField(slug: string, fieldID: string): Promise<AxiosResponse<any>>;
28
+ query(slug: string, variables: any): Promise<AxiosResponse<any>>;
29
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TapstackDBClient = void 0;
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./modules/objects"), exports);
20
+ __exportStar(require("./modules/fields"), exports);
21
+ __exportStar(require("./modules/records"), exports);
22
+ const core_1 = require("@tapstack/core");
23
+ const objects_1 = require("./modules/objects");
24
+ const fields_1 = require("./modules/fields");
25
+ const records_1 = require("./modules/records");
26
+ class TapstackDBClient extends core_1.BaseClient {
27
+ constructor(config) {
28
+ super(config);
29
+ this.objects = new objects_1.ObjectModule(this.client);
30
+ this.fields = new fields_1.FieldModule(this.client);
31
+ this.records = new records_1.RecordModule(this.client);
32
+ }
33
+ async getObject(slug) {
34
+ return this.client.get(`/system/${slug}`);
35
+ }
36
+ async getAllObjects() {
37
+ return this.client.get(`/system`);
38
+ }
39
+ async createObject(data) {
40
+ return this.client.post(`/system`, data);
41
+ }
42
+ async updateObject(slug, data) {
43
+ return this.client.put(`/system/${slug}`, data);
44
+ }
45
+ async deleteObject(slug) {
46
+ return this.client.delete(`/system/${slug}`);
47
+ }
48
+ async getFields(slug) {
49
+ return this.client.get(`/system/${slug}/fields`);
50
+ }
51
+ async getField(slug, fieldID) {
52
+ return this.client.get(`/system/${slug}/fields/${fieldID}`);
53
+ }
54
+ async createField(slug, data) {
55
+ return this.client.post(`/system/${slug}/fields`, data);
56
+ }
57
+ async updateField(slug, fieldID, data) {
58
+ return this.client.put(`/system/${slug}/fields/${fieldID}`, data);
59
+ }
60
+ async deleteField(slug, fieldID) {
61
+ return this.client.delete(`/system/${slug}/fields/${fieldID}`);
62
+ }
63
+ async query(slug, variables) {
64
+ return this.client.post(`/${slug}`, variables);
65
+ }
66
+ }
67
+ exports.TapstackDBClient = TapstackDBClient;
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { TapstackField, TapstackResponse } from '../types';
3
+ export declare class FieldModule {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ list(slug: string): Promise<TapstackResponse<TapstackField[]>>;
7
+ get(slug: string, fieldID: string): Promise<TapstackResponse<TapstackField>>;
8
+ create(slug: string, data: Partial<TapstackField>): Promise<TapstackResponse<TapstackField>>;
9
+ update(slug: string, fieldID: string, data: Partial<TapstackField>): Promise<TapstackResponse<TapstackField>>;
10
+ delete(slug: string, fieldID: string): Promise<TapstackResponse<void>>;
11
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FieldModule = void 0;
4
+ const request_1 = require("../request");
5
+ class FieldModule {
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ list(slug) {
10
+ return (0, request_1.handleRequest)(this.client, { method: 'GET', url: `/system/${slug}/fields` });
11
+ }
12
+ get(slug, fieldID) {
13
+ return (0, request_1.handleRequest)(this.client, { method: 'GET', url: `/system/${slug}/fields/${fieldID}` });
14
+ }
15
+ create(slug, data) {
16
+ return (0, request_1.handleRequest)(this.client, { method: 'POST', url: `/system/${slug}/fields`, data });
17
+ }
18
+ update(slug, fieldID, data) {
19
+ return (0, request_1.handleRequest)(this.client, { method: 'PUT', url: `/system/${slug}/fields/${fieldID}`, data });
20
+ }
21
+ delete(slug, fieldID) {
22
+ return (0, request_1.handleRequest)(this.client, { method: 'DELETE', url: `/system/${slug}/fields/${fieldID}` });
23
+ }
24
+ }
25
+ exports.FieldModule = FieldModule;
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { TapstackObject, TapstackResponse } from '../types';
3
+ export declare class ObjectModule {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ get(slug: string): Promise<TapstackResponse<TapstackObject>>;
7
+ list(): Promise<TapstackResponse<TapstackObject[]>>;
8
+ create(data: Partial<TapstackObject>): Promise<TapstackResponse<TapstackObject>>;
9
+ update(slug: string, data: Partial<TapstackObject>): Promise<TapstackResponse<TapstackObject>>;
10
+ delete(slug: string): Promise<TapstackResponse<void>>;
11
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectModule = void 0;
4
+ const request_1 = require("../request");
5
+ class ObjectModule {
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ get(slug) {
10
+ return (0, request_1.handleRequest)(this.client, { method: 'GET', url: `/system/${slug}` });
11
+ }
12
+ list() {
13
+ return (0, request_1.handleRequest)(this.client, { method: 'GET', url: `/system` });
14
+ }
15
+ create(data) {
16
+ return (0, request_1.handleRequest)(this.client, { method: 'POST', url: `/system`, data });
17
+ }
18
+ update(slug, data) {
19
+ return (0, request_1.handleRequest)(this.client, { method: 'PUT', url: `/system/${slug}`, data });
20
+ }
21
+ delete(slug) {
22
+ return (0, request_1.handleRequest)(this.client, { method: 'DELETE', url: `/system/${slug}` });
23
+ }
24
+ }
25
+ exports.ObjectModule = ObjectModule;
@@ -0,0 +1,7 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { TapstackRecord, TapstackResponse } from '../types';
3
+ export declare class RecordModule {
4
+ private client;
5
+ constructor(client: AxiosInstance);
6
+ query<T = TapstackRecord[]>(slug: string, variables: any): Promise<TapstackResponse<T>>;
7
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecordModule = void 0;
4
+ const request_1 = require("../request");
5
+ class RecordModule {
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ query(slug, variables) {
10
+ return (0, request_1.handleRequest)(this.client, { method: 'POST', url: `/${slug}`, data: variables });
11
+ }
12
+ }
13
+ exports.RecordModule = RecordModule;
@@ -0,0 +1,2 @@
1
+ import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ export declare function handleRequest<T>(client: AxiosInstance, config: AxiosRequestConfig): Promise<T>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handleRequest = handleRequest;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ async function handleRequest(client, config) {
9
+ try {
10
+ const response = await client.request(config);
11
+ return response.data;
12
+ }
13
+ catch (err) {
14
+ if (axios_1.default.isAxiosError(err)) {
15
+ const message = err.response?.data?.message || err.message;
16
+ throw new Error(message);
17
+ }
18
+ throw err;
19
+ }
20
+ }
@@ -0,0 +1,19 @@
1
+ export interface TapstackObject {
2
+ slug: string;
3
+ name: string;
4
+ [key: string]: any;
5
+ }
6
+ export interface TapstackField {
7
+ id: string;
8
+ name: string;
9
+ type: string;
10
+ [key: string]: any;
11
+ }
12
+ export type TapstackRecord = Record<string, any> & {
13
+ id?: string;
14
+ };
15
+ export interface TapstackResponse<T> {
16
+ data: T;
17
+ }
18
+ export type CreateObjectPayload = Partial<TapstackObject>;
19
+ export type CreateFieldPayload = Partial<TapstackField>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@tapstack/db",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "scripts": {
7
+ "build": "tsc -p tsconfig.json",
8
+ "prepublishOnly": "npm run build"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "dependencies": {
14
+ "axios": "^1.6.0",
15
+ "@tapstack/core": "^1.0.0"
16
+ }
17
+ }
@@ -0,0 +1,84 @@
1
+ import axios from 'axios';
2
+ import { TapstackDBClient } from '../index';
3
+
4
+ jest.mock('axios');
5
+
6
+ const mockedCreate = axios.create as jest.Mock;
7
+
8
+ describe('TapstackDBClient', () => {
9
+ const apiClient = {
10
+ get: jest.fn(),
11
+ post: jest.fn(),
12
+ put: jest.fn(),
13
+ delete: jest.fn(),
14
+ };
15
+
16
+ let client: TapstackDBClient;
17
+
18
+ beforeEach(() => {
19
+ mockedCreate.mockReturnValue(apiClient);
20
+ client = new TapstackDBClient({ baseURL: 'http://example.com', apiKey: 'token' });
21
+ });
22
+
23
+ afterEach(() => {
24
+ jest.clearAllMocks();
25
+ });
26
+
27
+
28
+ it('getObject calls axios.get with correct path', async () => {
29
+ await client.getObject('item');
30
+ expect(apiClient.get).toHaveBeenCalledWith('/system/item');
31
+ });
32
+
33
+ it('getAllObjects calls axios.get on /system', async () => {
34
+ await client.getAllObjects();
35
+ expect(apiClient.get).toHaveBeenCalledWith('/system');
36
+ });
37
+
38
+ it('createObject posts to /system', async () => {
39
+ const data = { name: 'test' };
40
+ await client.createObject(data);
41
+ expect(apiClient.post).toHaveBeenCalledWith('/system', data);
42
+ });
43
+
44
+ it('updateObject puts to correct path', async () => {
45
+ await client.updateObject('item', { a: 1 });
46
+ expect(apiClient.put).toHaveBeenCalledWith('/system/item', { a: 1 });
47
+ });
48
+
49
+ it('deleteObject deletes from correct path', async () => {
50
+ await client.deleteObject('item');
51
+ expect(apiClient.delete).toHaveBeenCalledWith('/system/item');
52
+ });
53
+
54
+ it('getFields calls axios.get with fields path', async () => {
55
+ await client.getFields('item');
56
+ expect(apiClient.get).toHaveBeenCalledWith('/system/item/fields');
57
+ });
58
+
59
+ it('getField calls axios.get with field id', async () => {
60
+ await client.getField('item', '1');
61
+ expect(apiClient.get).toHaveBeenCalledWith('/system/item/fields/1');
62
+ });
63
+
64
+ it('createField posts to fields path', async () => {
65
+ await client.createField('item', { name: 'field' });
66
+ expect(apiClient.post).toHaveBeenCalledWith('/system/item/fields', { name: 'field' });
67
+ });
68
+
69
+ it('updateField puts to specific field path', async () => {
70
+ await client.updateField('item', '1', { name: 'f' });
71
+ expect(apiClient.put).toHaveBeenCalledWith('/system/item/fields/1', { name: 'f' });
72
+ });
73
+
74
+ it('deleteField deletes the field path', async () => {
75
+ await client.deleteField('item', '1');
76
+ expect(apiClient.delete).toHaveBeenCalledWith('/system/item/fields/1');
77
+ });
78
+
79
+ it('query posts to slug', async () => {
80
+ const variables = { a: 1 };
81
+ await client.query('item', variables);
82
+ expect(apiClient.post).toHaveBeenCalledWith('/item', variables);
83
+ });
84
+ });
package/src/index.ts ADDED
@@ -0,0 +1,70 @@
1
+ export * from './types';
2
+ export * from './modules/objects';
3
+ export * from './modules/fields';
4
+ export * from './modules/records';
5
+
6
+ import { AxiosResponse } from 'axios';
7
+ import { BaseClient, BaseClientConfig } from '@tapstack/core';
8
+ import { ObjectModule } from './modules/objects';
9
+ import { FieldModule } from './modules/fields';
10
+ import { RecordModule } from './modules/records';
11
+ import { CreateFieldPayload, CreateObjectPayload } from './types';
12
+
13
+ export interface TapstackDBClientConfig extends BaseClientConfig {}
14
+
15
+ export class TapstackDBClient extends BaseClient {
16
+ readonly objects: ObjectModule;
17
+ readonly fields: FieldModule;
18
+ readonly records: RecordModule;
19
+
20
+ constructor(config: TapstackDBClientConfig) {
21
+ super(config);
22
+ this.objects = new ObjectModule(this.client);
23
+ this.fields = new FieldModule(this.client);
24
+ this.records = new RecordModule(this.client);
25
+ }
26
+
27
+ async getObject(slug: string): Promise<AxiosResponse<any>> {
28
+ return this.client.get(`/system/${slug}`);
29
+ }
30
+
31
+ async getAllObjects(): Promise<AxiosResponse<any>> {
32
+ return this.client.get(`/system`);
33
+ }
34
+
35
+ async createObject(data: CreateObjectPayload): Promise<AxiosResponse<any>> {
36
+ return this.client.post(`/system`, data);
37
+ }
38
+
39
+ async updateObject(slug: string, data: Partial<CreateObjectPayload>): Promise<AxiosResponse<any>> {
40
+ return this.client.put(`/system/${slug}`, data);
41
+ }
42
+
43
+ async deleteObject(slug: string): Promise<AxiosResponse<any>> {
44
+ return this.client.delete(`/system/${slug}`);
45
+ }
46
+
47
+ async getFields(slug: string): Promise<AxiosResponse<any>> {
48
+ return this.client.get(`/system/${slug}/fields`);
49
+ }
50
+
51
+ async getField(slug: string, fieldID: string): Promise<AxiosResponse<any>> {
52
+ return this.client.get(`/system/${slug}/fields/${fieldID}`);
53
+ }
54
+
55
+ async createField(slug: string, data: CreateFieldPayload): Promise<AxiosResponse<any>> {
56
+ return this.client.post(`/system/${slug}/fields`, data);
57
+ }
58
+
59
+ async updateField(slug: string, fieldID: string, data: Partial<CreateFieldPayload>): Promise<AxiosResponse<any>> {
60
+ return this.client.put(`/system/${slug}/fields/${fieldID}`, data);
61
+ }
62
+
63
+ async deleteField(slug: string, fieldID: string): Promise<AxiosResponse<any>> {
64
+ return this.client.delete(`/system/${slug}/fields/${fieldID}`);
65
+ }
66
+
67
+ async query(slug: string, variables: any): Promise<AxiosResponse<any>> {
68
+ return this.client.post(`/${slug}`, variables);
69
+ }
70
+ }
@@ -0,0 +1,27 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { handleRequest } from '../request';
3
+ import { TapstackField, TapstackResponse } from '../types';
4
+
5
+ export class FieldModule {
6
+ constructor(private client: AxiosInstance) {}
7
+
8
+ list(slug: string): Promise<TapstackResponse<TapstackField[]>> {
9
+ return handleRequest(this.client, { method: 'GET', url: `/system/${slug}/fields` });
10
+ }
11
+
12
+ get(slug: string, fieldID: string): Promise<TapstackResponse<TapstackField>> {
13
+ return handleRequest(this.client, { method: 'GET', url: `/system/${slug}/fields/${fieldID}` });
14
+ }
15
+
16
+ create(slug: string, data: Partial<TapstackField>): Promise<TapstackResponse<TapstackField>> {
17
+ return handleRequest(this.client, { method: 'POST', url: `/system/${slug}/fields`, data });
18
+ }
19
+
20
+ update(slug: string, fieldID: string, data: Partial<TapstackField>): Promise<TapstackResponse<TapstackField>> {
21
+ return handleRequest(this.client, { method: 'PUT', url: `/system/${slug}/fields/${fieldID}`, data });
22
+ }
23
+
24
+ delete(slug: string, fieldID: string): Promise<TapstackResponse<void>> {
25
+ return handleRequest(this.client, { method: 'DELETE', url: `/system/${slug}/fields/${fieldID}` });
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { handleRequest } from '../request';
3
+ import { TapstackObject, TapstackResponse } from '../types';
4
+
5
+ export class ObjectModule {
6
+ constructor(private client: AxiosInstance) {}
7
+
8
+ get(slug: string): Promise<TapstackResponse<TapstackObject>> {
9
+ return handleRequest(this.client, { method: 'GET', url: `/system/${slug}` });
10
+ }
11
+
12
+ list(): Promise<TapstackResponse<TapstackObject[]>> {
13
+ return handleRequest(this.client, { method: 'GET', url: `/system` });
14
+ }
15
+
16
+ create(data: Partial<TapstackObject>): Promise<TapstackResponse<TapstackObject>> {
17
+ return handleRequest(this.client, { method: 'POST', url: `/system`, data });
18
+ }
19
+
20
+ update(slug: string, data: Partial<TapstackObject>): Promise<TapstackResponse<TapstackObject>> {
21
+ return handleRequest(this.client, { method: 'PUT', url: `/system/${slug}`, data });
22
+ }
23
+
24
+ delete(slug: string): Promise<TapstackResponse<void>> {
25
+ return handleRequest(this.client, { method: 'DELETE', url: `/system/${slug}` });
26
+ }
27
+ }
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { handleRequest } from '../request';
3
+ import { TapstackRecord, TapstackResponse } from '../types';
4
+
5
+ export class RecordModule {
6
+ constructor(private client: AxiosInstance) {}
7
+
8
+ query<T = TapstackRecord[]>(slug: string, variables: any): Promise<TapstackResponse<T>> {
9
+ return handleRequest(this.client, { method: 'POST', url: `/${slug}`, data: variables });
10
+ }
11
+ }
package/src/request.ts ADDED
@@ -0,0 +1,14 @@
1
+ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+
3
+ export async function handleRequest<T>(client: AxiosInstance, config: AxiosRequestConfig): Promise<T> {
4
+ try {
5
+ const response = await client.request<T>(config);
6
+ return response.data;
7
+ } catch (err) {
8
+ if (axios.isAxiosError(err)) {
9
+ const message = (err.response?.data as any)?.message || err.message;
10
+ throw new Error(message);
11
+ }
12
+ throw err;
13
+ }
14
+ }
package/src/types.ts ADDED
@@ -0,0 +1,21 @@
1
+ export interface TapstackObject {
2
+ slug: string;
3
+ name: string;
4
+ [key: string]: any;
5
+ }
6
+
7
+ export interface TapstackField {
8
+ id: string;
9
+ name: string;
10
+ type: string;
11
+ [key: string]: any;
12
+ }
13
+
14
+ export type TapstackRecord = Record<string, any> & { id?: string };
15
+
16
+ export interface TapstackResponse<T> {
17
+ data: T;
18
+ }
19
+
20
+ export type CreateObjectPayload = Partial<TapstackObject>;
21
+ export type CreateFieldPayload = Partial<TapstackField>;
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src"]
7
+ }