@tthr/vue 0.0.16 → 0.0.17
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/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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
72
|
+
return result.data;
|
|
157
73
|
}
|
|
158
74
|
|
|
159
|
-
async function mutation
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
234
|
+
function mapAssetMetadata(asset) {
|
|
330
235
|
return {
|
|
331
|
-
id: asset.id
|
|
332
|
-
filename: asset.filename
|
|
333
|
-
contentType: asset.content_type
|
|
334
|
-
size: asset.size
|
|
335
|
-
sha256: asset.sha256
|
|
336
|
-
createdAt: asset.created_at
|
|
337
|
-
metadata: asset.metadata
|
|
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
|
File without changes
|
|
File without changes
|