@tapstack/db 1.0.7 → 3.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.
Files changed (48) hide show
  1. package/README.md +655 -0
  2. package/dist/adapters/index.d.ts +6 -0
  3. package/dist/adapters/index.js +22 -0
  4. package/dist/adapters/nodejs.adapter.d.ts +63 -0
  5. package/dist/adapters/nodejs.adapter.js +204 -0
  6. package/dist/adapters/types.d.ts +77 -0
  7. package/dist/adapters/types.js +19 -0
  8. package/dist/index.d.ts +101 -21
  9. package/dist/index.js +114 -41
  10. package/dist/modules/automations.d.ts +109 -0
  11. package/dist/modules/automations.js +59 -0
  12. package/dist/modules/conversations.d.ts +82 -0
  13. package/dist/modules/conversations.js +54 -0
  14. package/dist/modules/fields.d.ts +30 -9
  15. package/dist/modules/fields.js +31 -13
  16. package/dist/modules/files.d.ts +68 -0
  17. package/dist/modules/files.js +115 -0
  18. package/dist/modules/index.d.ts +12 -0
  19. package/dist/modules/index.js +28 -0
  20. package/dist/modules/objects.d.ts +30 -9
  21. package/dist/modules/objects.js +35 -13
  22. package/dist/modules/organizations.d.ts +69 -0
  23. package/dist/modules/organizations.js +83 -0
  24. package/dist/modules/records.d.ts +47 -5
  25. package/dist/modules/records.js +70 -5
  26. package/dist/modules/workspaces.d.ts +44 -0
  27. package/dist/modules/workspaces.js +57 -0
  28. package/dist/types.d.ts +159 -10
  29. package/dist/types.js +19 -0
  30. package/package.json +16 -7
  31. package/src/__tests__/client.test.ts +305 -49
  32. package/src/adapters/index.ts +13 -0
  33. package/src/adapters/nodejs.adapter.ts +298 -0
  34. package/src/adapters/types.ts +108 -0
  35. package/src/index.ts +132 -44
  36. package/src/modules/automations.ts +157 -0
  37. package/src/modules/conversations.ts +134 -0
  38. package/src/modules/fields.ts +64 -14
  39. package/src/modules/files.ts +144 -0
  40. package/src/modules/index.ts +19 -0
  41. package/src/modules/objects.ts +46 -14
  42. package/src/modules/organizations.ts +137 -0
  43. package/src/modules/records.ts +119 -6
  44. package/src/modules/workspaces.ts +95 -0
  45. package/src/types.ts +229 -9
  46. package/dist/request.d.ts +0 -2
  47. package/dist/request.js +0 -20
  48. package/src/request.ts +0 -14
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Tapstack API Adapter
3
+ * Implements IInstanceAdapter for the Tapstack API at api.tapstack.com
4
+ */
5
+ import { IInstanceAdapter, AdapterConfig, HttpMethod, RequestOptions } from './types';
6
+ /**
7
+ * Default Tapstack API URL
8
+ */
9
+ export declare const DEFAULT_API_URL = "https://api.tapstack.com";
10
+ /**
11
+ * Configuration for the Tapstack API adapter
12
+ */
13
+ export interface NodeJSAdapterConfig extends AdapterConfig {
14
+ /**
15
+ * Base URL of the Tapstack API
16
+ * @default 'https://api.tapstack.com'
17
+ */
18
+ baseUrl?: string;
19
+ /**
20
+ * API key for authentication (for programmatic access)
21
+ */
22
+ apiKey?: string;
23
+ /**
24
+ * Service token for service-to-service calls
25
+ */
26
+ serviceToken?: string;
27
+ /**
28
+ * User token for frontend calls (static)
29
+ */
30
+ userToken?: string;
31
+ /**
32
+ * Function to get dynamic user token (alternative to static userToken)
33
+ * Use this in frontend apps where the token may change
34
+ */
35
+ getUserToken?: () => Promise<string | null>;
36
+ }
37
+ export declare class NodeJSAdapter implements IInstanceAdapter {
38
+ private config;
39
+ private workspaceId;
40
+ private baseUrl;
41
+ constructor(config: NodeJSAdapterConfig);
42
+ /**
43
+ * Map SDK paths to REST API paths
44
+ * Converts paths like 'records/contacts' to '/api/v1/objects/contacts/records'
45
+ */
46
+ private mapPath;
47
+ /**
48
+ * Make a request to the Tapstack API
49
+ */
50
+ request<T>(method: HttpMethod, path: string, options?: RequestOptions): Promise<T>;
51
+ /**
52
+ * Upload a file to the Tapstack API
53
+ */
54
+ upload<T>(path: string, file: File | Blob, metadata?: Record<string, string>): Promise<T>;
55
+ /**
56
+ * Set the workspace context
57
+ */
58
+ setWorkspaceId(workspaceId: string | null): void;
59
+ /**
60
+ * Get the current workspace ID
61
+ */
62
+ getWorkspaceId(): string | null;
63
+ }
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ /**
3
+ * Tapstack API Adapter
4
+ * Implements IInstanceAdapter for the Tapstack API at api.tapstack.com
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.NodeJSAdapter = exports.DEFAULT_API_URL = void 0;
8
+ const types_1 = require("./types");
9
+ /**
10
+ * Default Tapstack API URL
11
+ */
12
+ exports.DEFAULT_API_URL = 'https://api.tapstack.com';
13
+ class NodeJSAdapter {
14
+ constructor(config) {
15
+ this.config = config;
16
+ this.workspaceId = config.workspaceId ?? null;
17
+ this.baseUrl = config.baseUrl ?? exports.DEFAULT_API_URL;
18
+ }
19
+ /**
20
+ * Map SDK paths to REST API paths
21
+ * Converts paths like 'records/contacts' to '/api/v1/objects/contacts/records'
22
+ */
23
+ mapPath(path) {
24
+ // Already a full path
25
+ if (path.startsWith('/api/')) {
26
+ return path;
27
+ }
28
+ // Schema operations
29
+ if (path.startsWith('schema/objects')) {
30
+ return `/api/v1/objects${path.replace('schema/objects', '')}`;
31
+ }
32
+ if (path.startsWith('schema/fields/')) {
33
+ const parts = path.split('/');
34
+ const objectSlug = parts[2];
35
+ const rest = parts.slice(3).join('/');
36
+ return `/api/v1/objects/${objectSlug}/fields${rest ? `/${rest}` : ''}`;
37
+ }
38
+ // Record operations: records/{objectSlug}/... -> /api/v1/objects/{objectSlug}/records/...
39
+ if (path.startsWith('records/')) {
40
+ const parts = path.split('/');
41
+ const objectSlug = parts[1];
42
+ const rest = parts.slice(2).join('/');
43
+ return `/api/v1/objects/${objectSlug}/records${rest ? `/${rest}` : ''}`;
44
+ }
45
+ // File operations
46
+ if (path.startsWith('files')) {
47
+ return `/api/v1${path.startsWith('/') ? path : `/${path}`}`;
48
+ }
49
+ // Automation operations
50
+ if (path.startsWith('automations')) {
51
+ return `/api/v1${path.startsWith('/') ? path : `/${path}`}`;
52
+ }
53
+ // Conversation operations
54
+ if (path.startsWith('conversations')) {
55
+ return `/api/v1${path.startsWith('/') ? path : `/${path}`}`;
56
+ }
57
+ // AI operations
58
+ if (path.startsWith('ai')) {
59
+ return `/api/v1${path.startsWith('/') ? path : `/${path}`}`;
60
+ }
61
+ // Organization operations
62
+ if (path.startsWith('organizations')) {
63
+ return `/api${path.startsWith('/') ? path : `/${path}`}`;
64
+ }
65
+ // Workspace operations
66
+ if (path.startsWith('workspaces')) {
67
+ return `/api${path.startsWith('/') ? path : `/${path}`}`;
68
+ }
69
+ // Activity operations
70
+ if (path.startsWith('activity')) {
71
+ return `/api/v1${path.startsWith('/') ? path : `/${path}`}`;
72
+ }
73
+ // Default: add /api prefix
74
+ return `/api/${path}`;
75
+ }
76
+ /**
77
+ * Make a request to the Tapstack API
78
+ */
79
+ async request(method, path, options) {
80
+ // Build the URL - API uses /api/v1 prefix for data operations
81
+ const apiPath = this.mapPath(path);
82
+ let url = `${this.baseUrl}${apiPath}`;
83
+ // Add query parameters
84
+ if (options?.params) {
85
+ const params = new URLSearchParams(options.params);
86
+ if (this.workspaceId && !options.params.workspaceId) {
87
+ params.set('workspaceId', this.workspaceId);
88
+ }
89
+ url += `?${params.toString()}`;
90
+ }
91
+ else if (this.workspaceId) {
92
+ url += `?workspaceId=${this.workspaceId}`;
93
+ }
94
+ // Build headers
95
+ const headers = {
96
+ 'Content-Type': 'application/json',
97
+ ...this.config.defaultHeaders,
98
+ ...options?.headers,
99
+ };
100
+ // Add authentication
101
+ if (this.config.apiKey) {
102
+ headers['X-API-Key'] = this.config.apiKey;
103
+ }
104
+ if (this.config.serviceToken) {
105
+ headers['Authorization'] = `Bearer ${this.config.serviceToken}`;
106
+ }
107
+ else if (this.config.userToken) {
108
+ headers['Authorization'] = `Bearer ${this.config.userToken}`;
109
+ }
110
+ else if (this.config.getUserToken) {
111
+ const token = await this.config.getUserToken();
112
+ if (token) {
113
+ headers['Authorization'] = `Bearer ${token}`;
114
+ }
115
+ }
116
+ // Add workspace header
117
+ if (this.workspaceId) {
118
+ headers['X-Workspace-Id'] = this.workspaceId;
119
+ }
120
+ // Make the request
121
+ const response = await fetch(url, {
122
+ method,
123
+ headers,
124
+ body: options?.body ? JSON.stringify(options.body) : undefined,
125
+ });
126
+ // Handle authentication errors
127
+ if (response.status === 401) {
128
+ this.config.onAuthError?.();
129
+ throw new types_1.AdapterError('Unauthorized', 'UNAUTHORIZED', 401);
130
+ }
131
+ // Parse response
132
+ const data = (await response.json());
133
+ // Handle API errors
134
+ if (!data.success) {
135
+ throw new types_1.AdapterError(data.error?.message || 'Request failed', data.error?.code || 'UNKNOWN_ERROR', response.status);
136
+ }
137
+ return data.data;
138
+ }
139
+ /**
140
+ * Upload a file to the Tapstack API
141
+ */
142
+ async upload(path, file, metadata) {
143
+ const apiPath = this.mapPath(path);
144
+ let url = `${this.baseUrl}${apiPath}`;
145
+ if (this.workspaceId) {
146
+ url += `?workspaceId=${this.workspaceId}`;
147
+ }
148
+ const headers = {
149
+ ...this.config.defaultHeaders,
150
+ };
151
+ if (this.config.apiKey) {
152
+ headers['X-API-Key'] = this.config.apiKey;
153
+ }
154
+ if (this.config.serviceToken) {
155
+ headers['Authorization'] = `Bearer ${this.config.serviceToken}`;
156
+ }
157
+ else if (this.config.userToken) {
158
+ headers['Authorization'] = `Bearer ${this.config.userToken}`;
159
+ }
160
+ else if (this.config.getUserToken) {
161
+ const token = await this.config.getUserToken();
162
+ if (token) {
163
+ headers['Authorization'] = `Bearer ${token}`;
164
+ }
165
+ }
166
+ if (this.workspaceId) {
167
+ headers['X-Workspace-Id'] = this.workspaceId;
168
+ }
169
+ const formData = new FormData();
170
+ formData.append('file', file);
171
+ if (metadata) {
172
+ for (const [key, value] of Object.entries(metadata)) {
173
+ formData.append(key, value);
174
+ }
175
+ }
176
+ const response = await fetch(url, {
177
+ method: 'POST',
178
+ headers,
179
+ body: formData,
180
+ });
181
+ if (response.status === 401) {
182
+ this.config.onAuthError?.();
183
+ throw new types_1.AdapterError('Unauthorized', 'UNAUTHORIZED', 401);
184
+ }
185
+ const data = (await response.json());
186
+ if (!data.success) {
187
+ throw new types_1.AdapterError(data.error?.message || 'Upload failed', data.error?.code || 'UPLOAD_ERROR', response.status);
188
+ }
189
+ return data.data;
190
+ }
191
+ /**
192
+ * Set the workspace context
193
+ */
194
+ setWorkspaceId(workspaceId) {
195
+ this.workspaceId = workspaceId;
196
+ }
197
+ /**
198
+ * Get the current workspace ID
199
+ */
200
+ getWorkspaceId() {
201
+ return this.workspaceId;
202
+ }
203
+ }
204
+ exports.NodeJSAdapter = NodeJSAdapter;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Instance Adapter Interface
3
+ * Defines the contract for backend adapters (Edge Functions, Node.js API, etc.)
4
+ */
5
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
6
+ export interface RequestOptions {
7
+ body?: unknown;
8
+ params?: Record<string, string>;
9
+ headers?: Record<string, string>;
10
+ }
11
+ /**
12
+ * Core adapter interface that all backend implementations must implement
13
+ */
14
+ export interface IInstanceAdapter {
15
+ /**
16
+ * Make an HTTP request to the backend
17
+ */
18
+ request<T>(method: HttpMethod, path: string, options?: RequestOptions): Promise<T>;
19
+ /**
20
+ * Upload a file to the backend
21
+ */
22
+ upload<T>(path: string, file: File | Blob, metadata?: Record<string, string>): Promise<T>;
23
+ /**
24
+ * Set the workspace context for subsequent requests
25
+ */
26
+ setWorkspaceId(workspaceId: string | null): void;
27
+ /**
28
+ * Get the current workspace ID
29
+ */
30
+ getWorkspaceId(): string | null;
31
+ }
32
+ /**
33
+ * Base configuration shared by all adapters
34
+ */
35
+ export interface AdapterConfig {
36
+ /**
37
+ * Workspace ID for scoping requests
38
+ */
39
+ workspaceId?: string;
40
+ /**
41
+ * Callback when authentication fails
42
+ */
43
+ onAuthError?: () => void;
44
+ /**
45
+ * Custom headers to include in all requests
46
+ */
47
+ defaultHeaders?: Record<string, string>;
48
+ }
49
+ /**
50
+ * Standard API response format from Instance API
51
+ */
52
+ export interface ApiResponse<T> {
53
+ success: boolean;
54
+ data?: T;
55
+ error?: {
56
+ code: string;
57
+ message: string;
58
+ };
59
+ }
60
+ /**
61
+ * Paginated response format
62
+ */
63
+ export interface PaginatedResponse<T> {
64
+ items: T[];
65
+ total: number;
66
+ page: number;
67
+ pageSize: number;
68
+ totalPages: number;
69
+ }
70
+ /**
71
+ * Error thrown by adapters
72
+ */
73
+ export declare class AdapterError extends Error {
74
+ code: string;
75
+ statusCode?: number | undefined;
76
+ constructor(message: string, code: string, statusCode?: number | undefined);
77
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Instance Adapter Interface
4
+ * Defines the contract for backend adapters (Edge Functions, Node.js API, etc.)
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.AdapterError = void 0;
8
+ /**
9
+ * Error thrown by adapters
10
+ */
11
+ class AdapterError extends Error {
12
+ constructor(message, code, statusCode) {
13
+ super(message);
14
+ this.code = code;
15
+ this.statusCode = statusCode;
16
+ this.name = 'AdapterError';
17
+ }
18
+ }
19
+ exports.AdapterError = AdapterError;
package/dist/index.d.ts CHANGED
@@ -1,29 +1,109 @@
1
+ /**
2
+ * @tapstack/db - Tapstack Database Client
3
+ *
4
+ * A client for interacting with the Tapstack API at api.tapstack.com.
5
+ * Provides typed access to objects, fields, records, and more.
6
+ */
1
7
  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';
8
+ export * from './adapters';
9
+ export * from './modules';
10
+ import { IInstanceAdapter } from './adapters/types';
11
+ import { NodeJSAdapterConfig } from './adapters/nodejs.adapter';
7
12
  import { ObjectModule } from './modules/objects';
8
13
  import { FieldModule } from './modules/fields';
9
14
  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 {
15
+ import { OrganizationModule } from './modules/organizations';
16
+ import { WorkspaceModule } from './modules/workspaces';
17
+ import { FileModule } from './modules/files';
18
+ import { AutomationModule } from './modules/automations';
19
+ import { ConversationModule } from './modules/conversations';
20
+ /**
21
+ * Main Tapstack Database Client
22
+ * Uses an adapter to communicate with the Tapstack API
23
+ */
24
+ export declare class TapstackDBClient {
14
25
  readonly objects: ObjectModule;
15
26
  readonly fields: FieldModule;
16
27
  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>>;
28
+ readonly organizations: OrganizationModule;
29
+ readonly workspaces: WorkspaceModule;
30
+ readonly files: FileModule;
31
+ readonly automations: AutomationModule;
32
+ readonly conversations: ConversationModule;
33
+ private adapter;
34
+ constructor(adapter: IInstanceAdapter);
35
+ /**
36
+ * Set the workspace context for all subsequent requests
37
+ */
38
+ setWorkspaceId(workspaceId: string | null): void;
39
+ /**
40
+ * Get the current workspace ID
41
+ */
42
+ getWorkspaceId(): string | null;
43
+ /**
44
+ * Get the underlying adapter (for advanced use cases)
45
+ */
46
+ getAdapter(): IInstanceAdapter;
47
+ }
48
+ /**
49
+ * Client configuration options
50
+ */
51
+ export type TapstackClientConfig = NodeJSAdapterConfig;
52
+ /**
53
+ * Create a Tapstack API client
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // With API key authentication
58
+ * const client = createClient({
59
+ * apiKey: 'your-api-key',
60
+ * workspaceId: 'ws-123',
61
+ * });
62
+ *
63
+ * // With user token (for frontend apps)
64
+ * const client = createClient({
65
+ * getUserToken: async () => accessToken,
66
+ * workspaceId: 'ws-123',
67
+ * });
68
+ *
69
+ * // With custom base URL
70
+ * const client = createClient({
71
+ * baseUrl: 'https://custom-api.example.com',
72
+ * apiKey: 'your-api-key',
73
+ * });
74
+ *
75
+ * // Usage
76
+ * const objects = await client.objects.list();
77
+ * const records = await client.records.list('contacts');
78
+ * ```
79
+ */
80
+ export declare function createClient(config: TapstackClientConfig): TapstackDBClient;
81
+ /**
82
+ * Create a client with a custom adapter
83
+ * Use this for advanced scenarios or custom backends
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * class CustomAdapter implements IInstanceAdapter {
88
+ * // ... implementation
89
+ * }
90
+ *
91
+ * const client = createCustomClient(new CustomAdapter());
92
+ * ```
93
+ */
94
+ export declare function createCustomClient(adapter: IInstanceAdapter): TapstackDBClient;
95
+ /**
96
+ * @deprecated Use createClient instead
97
+ */
98
+ export declare const createNodeJSClient: typeof createClient;
99
+ /**
100
+ * @deprecated Use TapstackClientConfig instead
101
+ */
102
+ export interface TapstackDBClientConfig {
103
+ baseURL: string;
104
+ apiKey: string;
29
105
  }
106
+ /**
107
+ * @deprecated Use createClient instead
108
+ */
109
+ export declare function createLegacyClient(config: TapstackDBClientConfig): TapstackDBClient;
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * @tapstack/db - Tapstack Database Client
4
+ *
5
+ * A client for interacting with the Tapstack API at api.tapstack.com.
6
+ * Provides typed access to objects, fields, records, and more.
7
+ */
2
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
9
  if (k2 === undefined) k2 = k;
4
10
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -14,54 +20,121 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
21
  };
16
22
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.TapstackDBClient = void 0;
23
+ exports.createNodeJSClient = exports.TapstackDBClient = void 0;
24
+ exports.createClient = createClient;
25
+ exports.createCustomClient = createCustomClient;
26
+ exports.createLegacyClient = createLegacyClient;
27
+ // Export all types
18
28
  __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");
29
+ // Export adapters
30
+ __exportStar(require("./adapters"), exports);
31
+ // Export modules
32
+ __exportStar(require("./modules"), exports);
33
+ const nodejs_adapter_1 = require("./adapters/nodejs.adapter");
23
34
  const objects_1 = require("./modules/objects");
24
35
  const fields_1 = require("./modules/fields");
25
36
  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);
37
+ const organizations_1 = require("./modules/organizations");
38
+ const workspaces_1 = require("./modules/workspaces");
39
+ const files_1 = require("./modules/files");
40
+ const automations_1 = require("./modules/automations");
41
+ const conversations_1 = require("./modules/conversations");
42
+ /**
43
+ * Main Tapstack Database Client
44
+ * Uses an adapter to communicate with the Tapstack API
45
+ */
46
+ class TapstackDBClient {
47
+ constructor(adapter) {
48
+ this.adapter = adapter;
49
+ this.objects = new objects_1.ObjectModule(adapter);
50
+ this.fields = new fields_1.FieldModule(adapter);
51
+ this.records = new records_1.RecordModule(adapter);
52
+ this.organizations = new organizations_1.OrganizationModule(adapter);
53
+ this.workspaces = new workspaces_1.WorkspaceModule(adapter);
54
+ this.files = new files_1.FileModule(adapter);
55
+ this.automations = new automations_1.AutomationModule(adapter);
56
+ this.conversations = new conversations_1.ConversationModule(adapter);
32
57
  }
33
- async getObject(slug) {
34
- return this.client.get(`/system/${slug}`);
58
+ /**
59
+ * Set the workspace context for all subsequent requests
60
+ */
61
+ setWorkspaceId(workspaceId) {
62
+ this.adapter.setWorkspaceId(workspaceId);
35
63
  }
36
- async getAllObjects() {
37
- return this.client.get(`/system`);
64
+ /**
65
+ * Get the current workspace ID
66
+ */
67
+ getWorkspaceId() {
68
+ return this.adapter.getWorkspaceId();
38
69
  }
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);
70
+ /**
71
+ * Get the underlying adapter (for advanced use cases)
72
+ */
73
+ getAdapter() {
74
+ return this.adapter;
65
75
  }
66
76
  }
67
77
  exports.TapstackDBClient = TapstackDBClient;
78
+ /**
79
+ * Create a Tapstack API client
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // With API key authentication
84
+ * const client = createClient({
85
+ * apiKey: 'your-api-key',
86
+ * workspaceId: 'ws-123',
87
+ * });
88
+ *
89
+ * // With user token (for frontend apps)
90
+ * const client = createClient({
91
+ * getUserToken: async () => accessToken,
92
+ * workspaceId: 'ws-123',
93
+ * });
94
+ *
95
+ * // With custom base URL
96
+ * const client = createClient({
97
+ * baseUrl: 'https://custom-api.example.com',
98
+ * apiKey: 'your-api-key',
99
+ * });
100
+ *
101
+ * // Usage
102
+ * const objects = await client.objects.list();
103
+ * const records = await client.records.list('contacts');
104
+ * ```
105
+ */
106
+ function createClient(config) {
107
+ const adapter = new nodejs_adapter_1.NodeJSAdapter(config);
108
+ return new TapstackDBClient(adapter);
109
+ }
110
+ /**
111
+ * Create a client with a custom adapter
112
+ * Use this for advanced scenarios or custom backends
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * class CustomAdapter implements IInstanceAdapter {
117
+ * // ... implementation
118
+ * }
119
+ *
120
+ * const client = createCustomClient(new CustomAdapter());
121
+ * ```
122
+ */
123
+ function createCustomClient(adapter) {
124
+ return new TapstackDBClient(adapter);
125
+ }
126
+ // ==================== Legacy Exports (for backwards compatibility) ====================
127
+ /**
128
+ * @deprecated Use createClient instead
129
+ */
130
+ exports.createNodeJSClient = createClient;
131
+ /**
132
+ * @deprecated Use createClient instead
133
+ */
134
+ function createLegacyClient(config) {
135
+ const adapter = new nodejs_adapter_1.NodeJSAdapter({
136
+ baseUrl: config.baseURL.replace('/api', ''),
137
+ apiKey: config.apiKey,
138
+ });
139
+ return new TapstackDBClient(adapter);
140
+ }