@tthr/vue 0.0.16 → 0.0.18

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,65 @@
1
+ /**
2
+ * @tthr/vue/server - Server-side Tether client for Nuxt
3
+ *
4
+ * Use this in Nuxt server/api routes for webhooks, third-party integrations,
5
+ * and any server-side logic that needs to call Tether queries/mutations.
6
+ */
7
+ import { TetherServerClient, type TetherServerClientOptions } from '@tthr/client';
8
+ export { TetherServerClient, type TetherServerClientOptions } from '@tthr/client';
9
+ /**
10
+ * Configure the server-side Tether client.
11
+ * Call this once in your Nuxt server plugin or at the top of your API routes.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // server/plugins/tether.ts
16
+ * import { configureTetherServer } from '@tthr/vue/server';
17
+ *
18
+ * export default defineNitroPlugin(() => {
19
+ * configureTetherServer({
20
+ * url: process.env.TETHER_URL!,
21
+ * projectId: process.env.TETHER_PROJECT_ID!,
22
+ * apiKey: process.env.TETHER_API_KEY,
23
+ * });
24
+ * });
25
+ * ```
26
+ */
27
+ export declare function configureTetherServer(options: TetherServerClientOptions): void;
28
+ /**
29
+ * Get the configured server-side Tether client.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * // server/api/users.get.ts
34
+ * import { useTetherServer } from '@tthr/vue/server';
35
+ *
36
+ * export default defineEventHandler(async () => {
37
+ * const tether = useTetherServer();
38
+ * return await tether.query('users.list');
39
+ * });
40
+ * ```
41
+ */
42
+ export declare function useTetherServer(): TetherServerClient;
43
+ /**
44
+ * Create a new server-side Tether client instance.
45
+ * Use this when you need a separate client with different configuration.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // server/api/webhook.ts
50
+ * import { createTetherServer } from '@tthr/vue/server';
51
+ *
52
+ * const tether = createTetherServer({
53
+ * url: process.env.TETHER_URL!,
54
+ * projectId: process.env.TETHER_PROJECT_ID!,
55
+ * apiKey: process.env.TETHER_API_KEY,
56
+ * });
57
+ *
58
+ * export default defineEventHandler(async (event) => {
59
+ * const users = await tether.query('users.list');
60
+ * return { users };
61
+ * });
62
+ * ```
63
+ */
64
+ export declare function createTetherServer(options: TetherServerClientOptions): TetherServerClient;
65
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAGlF,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAKlF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI,CAE9E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,IAAI,kBAAkB,CAQpD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CAEzF"}
package/dist/server.js ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @tthr/vue/server - Server-side Tether client for Nuxt
3
+ *
4
+ * Use this in Nuxt server/api routes for webhooks, third-party integrations,
5
+ * and any server-side logic that needs to call Tether queries/mutations.
6
+ */
7
+ import { TetherServerClient } from '@tthr/client';
8
+ // Re-export the server client and types for convenience
9
+ export { TetherServerClient } from '@tthr/client';
10
+ // Singleton client instance
11
+ let serverClient = null;
12
+ /**
13
+ * Configure the server-side Tether client.
14
+ * Call this once in your Nuxt server plugin or at the top of your API routes.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // server/plugins/tether.ts
19
+ * import { configureTetherServer } from '@tthr/vue/server';
20
+ *
21
+ * export default defineNitroPlugin(() => {
22
+ * configureTetherServer({
23
+ * url: process.env.TETHER_URL!,
24
+ * projectId: process.env.TETHER_PROJECT_ID!,
25
+ * apiKey: process.env.TETHER_API_KEY,
26
+ * });
27
+ * });
28
+ * ```
29
+ */
30
+ export function configureTetherServer(options) {
31
+ serverClient = new TetherServerClient(options);
32
+ }
33
+ /**
34
+ * Get the configured server-side Tether client.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // server/api/users.get.ts
39
+ * import { useTetherServer } from '@tthr/vue/server';
40
+ *
41
+ * export default defineEventHandler(async () => {
42
+ * const tether = useTetherServer();
43
+ * return await tether.query('users.list');
44
+ * });
45
+ * ```
46
+ */
47
+ export function useTetherServer() {
48
+ if (!serverClient) {
49
+ throw new Error('Tether server client not configured. Call configureTetherServer() first, ' +
50
+ 'typically in a Nitro plugin (server/plugins/tether.ts).');
51
+ }
52
+ return serverClient;
53
+ }
54
+ /**
55
+ * Create a new server-side Tether client instance.
56
+ * Use this when you need a separate client with different configuration.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // server/api/webhook.ts
61
+ * import { createTetherServer } from '@tthr/vue/server';
62
+ *
63
+ * const tether = createTetherServer({
64
+ * url: process.env.TETHER_URL!,
65
+ * projectId: process.env.TETHER_PROJECT_ID!,
66
+ * apiKey: process.env.TETHER_API_KEY,
67
+ * });
68
+ *
69
+ * export default defineEventHandler(async (event) => {
70
+ * const users = await tether.query('users.list');
71
+ * return { users };
72
+ * });
73
+ * ```
74
+ */
75
+ export function createTetherServer(options) {
76
+ return new TetherServerClient(options);
77
+ }
78
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAkC,MAAM,cAAc,CAAC;AAElF,wDAAwD;AACxD,OAAO,EAAE,kBAAkB,EAAkC,MAAM,cAAc,CAAC;AAElF,4BAA4B;AAC5B,IAAI,YAAY,GAA8B,IAAI,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAkC;IACtE,YAAY,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,2EAA2E;YAC3E,yDAAyD,CAC1D,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACnE,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC"}
package/nuxt/module.ts CHANGED
@@ -65,13 +65,13 @@ export default defineNuxtModule<TetherModuleOptions>({
65
65
  addServerHandler({
66
66
  route: '/api/_tether/query',
67
67
  method: 'post',
68
- handler: resolver.resolve('./runtime/server/query.post.ts'),
68
+ handler: resolver.resolve('./runtime/server/query.post.js'),
69
69
  });
70
70
 
71
71
  addServerHandler({
72
72
  route: '/api/_tether/mutation',
73
73
  method: 'post',
74
- handler: resolver.resolve('./runtime/server/mutation.post.ts'),
74
+ handler: resolver.resolve('./runtime/server/mutation.post.js'),
75
75
  });
76
76
 
77
77
  // Add the client plugin for WebSocket subscriptions only
@@ -21,94 +21,13 @@
21
21
  import { createError } from 'h3';
22
22
  import { useRuntimeConfig } from '#imports';
23
23
 
24
- export interface TetherServerClient {
25
- /**
26
- * Execute a query on the Tether server
27
- */
28
- query: <TResult = unknown>(
29
- name: string,
30
- args?: Record<string, unknown>
31
- ) => Promise<TResult>;
32
-
33
- /**
34
- * Execute a mutation on the Tether server
35
- */
36
- mutation: <TResult = unknown>(
37
- name: string,
38
- args?: Record<string, unknown>
39
- ) => Promise<TResult>;
40
-
41
- /**
42
- * File storage operations
43
- */
44
- storage: {
45
- /**
46
- * Generate a presigned upload URL
47
- */
48
- generateUploadUrl: (options: {
49
- filename: string;
50
- contentType: string;
51
- metadata?: Record<string, unknown>;
52
- }) => Promise<{ assetId: string; uploadUrl: string; expiresAt: string }>;
53
-
54
- /**
55
- * Confirm an upload has completed
56
- */
57
- confirmUpload: (assetId: string, sha256?: string) => Promise<AssetMetadata>;
58
-
59
- /**
60
- * Get a presigned download URL for an asset
61
- */
62
- getUrl: (assetId: string) => Promise<string>;
63
-
64
- /**
65
- * Get metadata for an asset
66
- */
67
- getMetadata: (assetId: string) => Promise<AssetMetadata>;
68
-
69
- /**
70
- * Delete an asset
71
- */
72
- delete: (assetId: string) => Promise<void>;
73
-
74
- /**
75
- * List assets with optional pagination and filtering
76
- */
77
- list: (options?: {
78
- limit?: number;
79
- offset?: number;
80
- contentType?: string;
81
- }) => Promise<{ assets: AssetMetadata[]; totalCount: number }>;
82
- };
83
-
84
- /**
85
- * The project ID
86
- */
87
- projectId: string;
88
-
89
- /**
90
- * The API URL
91
- */
92
- url: string;
93
- }
94
-
95
- export interface AssetMetadata {
96
- id: string;
97
- filename: string;
98
- contentType: string;
99
- size: number;
100
- sha256?: string;
101
- createdAt: string;
102
- metadata?: Record<string, unknown>;
103
- }
104
-
105
24
  /**
106
25
  * Get a Tether client for use in server-side code
107
26
  *
108
- * @param event - The H3 event (optional, used for request context)
27
+ * @param {unknown} _event - The H3 event (optional, used for request context)
109
28
  * @returns A Tether client with query, mutation, and storage methods
110
29
  */
111
- export function useTetherServer(_event?: unknown): TetherServerClient {
30
+ export function useTetherServer(_event) {
112
31
  const config = useRuntimeConfig();
113
32
 
114
33
  const apiKey = config.tether?.apiKey || process.env.TETHER_API_KEY;
@@ -134,10 +53,7 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
134
53
  'Authorization': `Bearer ${apiKey}`,
135
54
  };
136
55
 
137
- async function query<TResult = unknown>(
138
- name: string,
139
- args?: Record<string, unknown>
140
- ): Promise<TResult> {
56
+ async function query(name, args) {
141
57
  const response = await fetch(`${url}/api/v1/projects/${projectId}/query`, {
142
58
  method: 'POST',
143
59
  headers,
@@ -153,13 +69,10 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
153
69
  }
154
70
 
155
71
  const result = await response.json();
156
- return result.data as TResult;
72
+ return result.data;
157
73
  }
158
74
 
159
- async function mutation<TResult = unknown>(
160
- name: string,
161
- args?: Record<string, unknown>
162
- ): Promise<TResult> {
75
+ async function mutation(name, args) {
163
76
  const response = await fetch(`${url}/api/v1/projects/${projectId}/mutation`, {
164
77
  method: 'POST',
165
78
  headers,
@@ -175,15 +88,11 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
175
88
  }
176
89
 
177
90
  const result = await response.json();
178
- return result.data as TResult;
91
+ return result.data;
179
92
  }
180
93
 
181
94
  const storage = {
182
- async generateUploadUrl(options: {
183
- filename: string;
184
- contentType: string;
185
- metadata?: Record<string, unknown>;
186
- }) {
95
+ async generateUploadUrl(options) {
187
96
  const response = await fetch(`${url}/api/v1/projects/${projectId}/assets/upload-url`, {
188
97
  method: 'POST',
189
98
  headers,
@@ -210,7 +119,7 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
210
119
  };
211
120
  },
212
121
 
213
- async confirmUpload(assetId: string, sha256?: string): Promise<AssetMetadata> {
122
+ async confirmUpload(assetId, sha256) {
214
123
  const response = await fetch(`${url}/api/v1/projects/${projectId}/assets/${assetId}/complete`, {
215
124
  method: 'POST',
216
125
  headers,
@@ -229,7 +138,7 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
229
138
  return mapAssetMetadata(result.asset);
230
139
  },
231
140
 
232
- async getUrl(assetId: string): Promise<string> {
141
+ async getUrl(assetId) {
233
142
  const response = await fetch(`${url}/api/v1/projects/${projectId}/assets/${assetId}/url`, {
234
143
  method: 'GET',
235
144
  headers,
@@ -247,7 +156,7 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
247
156
  return result.url;
248
157
  },
249
158
 
250
- async getMetadata(assetId: string): Promise<AssetMetadata> {
159
+ async getMetadata(assetId) {
251
160
  const response = await fetch(`${url}/api/v1/projects/${projectId}/assets/${assetId}`, {
252
161
  method: 'GET',
253
162
  headers,
@@ -265,7 +174,7 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
265
174
  return mapAssetMetadata(result.asset);
266
175
  },
267
176
 
268
- async delete(assetId: string): Promise<void> {
177
+ async delete(assetId) {
269
178
  const response = await fetch(`${url}/api/v1/projects/${projectId}/assets/${assetId}`, {
270
179
  method: 'DELETE',
271
180
  headers,
@@ -280,11 +189,7 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
280
189
  }
281
190
  },
282
191
 
283
- async list(options?: {
284
- limit?: number;
285
- offset?: number;
286
- contentType?: string;
287
- }): Promise<{ assets: AssetMetadata[]; totalCount: number }> {
192
+ async list(options) {
288
193
  const params = new URLSearchParams();
289
194
  if (options?.limit) params.set('limit', String(options.limit));
290
195
  if (options?.offset) params.set('offset', String(options.offset));
@@ -326,14 +231,14 @@ export function useTetherServer(_event?: unknown): TetherServerClient {
326
231
  /**
327
232
  * Map snake_case API response to camelCase
328
233
  */
329
- function mapAssetMetadata(asset: Record<string, unknown>): AssetMetadata {
234
+ function mapAssetMetadata(asset) {
330
235
  return {
331
- id: asset.id as string,
332
- filename: asset.filename as string,
333
- contentType: asset.content_type as string,
334
- size: asset.size as number,
335
- sha256: asset.sha256 as string | undefined,
336
- createdAt: asset.created_at as string,
337
- metadata: asset.metadata as Record<string, unknown> | undefined,
236
+ id: asset.id,
237
+ filename: asset.filename,
238
+ contentType: asset.content_type,
239
+ size: asset.size,
240
+ sha256: asset.sha256,
241
+ createdAt: asset.created_at,
242
+ metadata: asset.metadata,
338
243
  };
339
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tthr/vue",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "Tether Vue/Nuxt SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -10,6 +10,10 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js"
12
12
  },
13
+ "./server": {
14
+ "types": "./dist/server.d.ts",
15
+ "import": "./dist/server.js"
16
+ },
13
17
  "./nuxt": {
14
18
  "import": "./nuxt/module.ts"
15
19
  }