@proveanything/smartlinks 1.0.7 → 1.0.8

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 (49) hide show
  1. package/debug.log +6 -0
  2. package/dist/api/attestation.d.ts +23 -0
  3. package/dist/api/attestation.js +44 -0
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/index.js +1 -0
  6. package/dist/http.d.ts +19 -0
  7. package/dist/http.js +109 -0
  8. package/dist/types/attestation.d.ts +16 -0
  9. package/dist/types/attestation.js +1 -0
  10. package/docs/assets/navigation.js +1 -1
  11. package/docs/assets/search.js +1 -1
  12. package/docs/documentation.json +847 -166
  13. package/docs/functions/appConfiguration.get.html +1 -1
  14. package/docs/functions/asset.getAllForCollection.html +1 -1
  15. package/docs/functions/asset.getAllForProduct.html +1 -1
  16. package/docs/functions/asset.getAllForProof.html +1 -1
  17. package/docs/functions/asset.getForCollection.html +1 -1
  18. package/docs/functions/asset.getForProduct.html +1 -1
  19. package/docs/functions/asset.getForProof.html +1 -1
  20. package/docs/functions/asset.uploadAsset.html +1 -1
  21. package/docs/functions/attestation.create.html +2 -0
  22. package/docs/functions/attestation.get.html +2 -0
  23. package/docs/functions/attestation.getAll.html +2 -0
  24. package/docs/functions/attestation.remove.html +2 -0
  25. package/docs/functions/attestation.update.html +2 -0
  26. package/docs/functions/collection.get.html +1 -1
  27. package/docs/functions/initializeApi.html +1 -1
  28. package/docs/functions/product.get.html +1 -1
  29. package/docs/functions/product.getAll.html +1 -1
  30. package/docs/functions/proof.get.html +1 -1
  31. package/docs/functions/request.html +1 -1
  32. package/docs/interfaces/AppConfigurationResponse.html +4 -4
  33. package/docs/interfaces/AssetResponse.html +2 -2
  34. package/docs/interfaces/CollectionResponse.html +5 -5
  35. package/docs/interfaces/ErrorResponse.html +3 -3
  36. package/docs/interfaces/ProductResponse.html +5 -5
  37. package/docs/interfaces/ProofResponse.html +8 -8
  38. package/docs/modules/appConfiguration.html +1 -1
  39. package/docs/modules/asset.html +1 -1
  40. package/docs/modules/attestation.html +6 -0
  41. package/docs/modules/collection.html +1 -1
  42. package/docs/modules/product.html +1 -1
  43. package/docs/modules/proof.html +1 -1
  44. package/docs/modules.html +1 -0
  45. package/package.json +1 -1
  46. package/src/api/attestation.ts +69 -0
  47. package/src/api/index.ts +1 -0
  48. package/src/http.ts +136 -0
  49. package/src/types/attestation.ts +18 -0
@@ -0,0 +1,69 @@
1
+ import { request, post, put, del } from "../http"
2
+ import type { AttestationResponse, AttestationCreateRequest, AttestationUpdateRequest } from "../types/attestation"
3
+
4
+ export namespace attestation {
5
+ /**
6
+ * Get all attestations for a proof.
7
+ */
8
+ export async function getAll(
9
+ collectionId: string,
10
+ productId: string,
11
+ proofId: string
12
+ ): Promise<AttestationResponse[]> {
13
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/attestation`
14
+ return request<AttestationResponse[]>(path)
15
+ }
16
+
17
+ /**
18
+ * Get a single attestation by ID.
19
+ */
20
+ export async function get(
21
+ collectionId: string,
22
+ productId: string,
23
+ proofId: string,
24
+ attestationId: string
25
+ ): Promise<AttestationResponse> {
26
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/attestation/${encodeURIComponent(attestationId)}`
27
+ return request<AttestationResponse>(path)
28
+ }
29
+
30
+ /**
31
+ * Create a new attestation for a proof.
32
+ */
33
+ export async function create(
34
+ collectionId: string,
35
+ productId: string,
36
+ proofId: string,
37
+ data: AttestationCreateRequest
38
+ ): Promise<AttestationResponse> {
39
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/attestation`
40
+ return post<AttestationResponse>(path, data)
41
+ }
42
+
43
+ /**
44
+ * Update an attestation.
45
+ */
46
+ export async function update(
47
+ collectionId: string,
48
+ productId: string,
49
+ proofId: string,
50
+ attestationId: string,
51
+ data: AttestationUpdateRequest
52
+ ): Promise<AttestationResponse> {
53
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/attestation/${encodeURIComponent(attestationId)}`
54
+ return put<AttestationResponse>(path, data)
55
+ }
56
+
57
+ /**
58
+ * Delete an attestation.
59
+ */
60
+ export async function remove(
61
+ collectionId: string,
62
+ productId: string,
63
+ proofId: string,
64
+ attestationId: string
65
+ ): Promise<void> {
66
+ const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/attestation/${encodeURIComponent(attestationId)}`
67
+ return del<void>(path)
68
+ }
69
+ }
package/src/api/index.ts CHANGED
@@ -5,3 +5,4 @@ export { product } from "./product"
5
5
  export { proof } from "./proof"
6
6
  export { appConfiguration } from "./appConfiguration"
7
7
  export { asset } from "./asset"
8
+ export { attestation } from "./attestation"
package/src/http.ts CHANGED
@@ -107,6 +107,142 @@ export async function post<T>(
107
107
  return (await response.json()) as T
108
108
  }
109
109
 
110
+ /**
111
+ * Internal helper that performs a PUT request to `${baseURL}${path}`,
112
+ * injecting headers for apiKey or bearerToken if present.
113
+ * If body is FormData, Content-Type is not set.
114
+ * Returns the parsed JSON as T, or throws an Error.
115
+ */
116
+ export async function put<T>(
117
+ path: string,
118
+ body: any,
119
+ extraHeaders?: Record<string, string>
120
+ ): Promise<T> {
121
+ if (!baseURL) {
122
+ throw new Error("HTTP client is not initialized. Call initializeApi(...) first.")
123
+ }
124
+
125
+ const url = `${baseURL}${path}`
126
+ const headers: Record<string, string> = extraHeaders ? { ...extraHeaders } : {}
127
+
128
+ if (apiKey) headers["X-API-Key"] = apiKey
129
+ if (bearerToken) headers["AUTHORIZATION"] = `Bearer ${bearerToken}`
130
+
131
+ // Only set Content-Type for non-FormData bodies
132
+ if (!(body instanceof FormData)) {
133
+ headers["Content-Type"] = "application/json"
134
+ }
135
+
136
+ const response = await fetch(url, {
137
+ method: "PUT",
138
+ headers,
139
+ body: body instanceof FormData ? body : JSON.stringify(body),
140
+ })
141
+
142
+ if (!response.ok) {
143
+ try {
144
+ const errBody = (await response.json()) as import("./types/error").ErrorResponse
145
+ throw new Error(`Error ${errBody.code}: ${errBody.message}`)
146
+ } catch {
147
+ throw new Error(`Request to ${url} failed with status ${response.status}`)
148
+ }
149
+ }
150
+
151
+ return (await response.json()) as T
152
+ }
153
+
154
+ /**
155
+ * Internal helper that performs a request to `${baseURL}${path}` with custom options,
156
+ * injecting headers for apiKey or bearerToken if present.
157
+ * Returns the parsed JSON as T, or throws an Error.
158
+ */
159
+ export async function requestWithOptions<T>(
160
+ path: string,
161
+ options: RequestInit
162
+ ): Promise<T> {
163
+ if (!baseURL) {
164
+ throw new Error("HTTP client is not initialized. Call initializeApi(...) first.")
165
+ }
166
+ const url = `${baseURL}${path}`
167
+
168
+ // Safely merge headers, converting Headers/init to Record<string, string>
169
+ let extraHeaders: Record<string, string> = {}
170
+ if (options.headers) {
171
+ if (options.headers instanceof Headers) {
172
+ options.headers.forEach((value, key) => {
173
+ extraHeaders[key] = value
174
+ })
175
+ } else if (Array.isArray(options.headers)) {
176
+ for (const [key, value] of options.headers) {
177
+ extraHeaders[key] = value
178
+ }
179
+ } else {
180
+ extraHeaders = { ...(options.headers as Record<string, string>) }
181
+ }
182
+ }
183
+
184
+ const headers: Record<string, string> = {
185
+ "Content-Type": "application/json",
186
+ ...(apiKey ? { "X-API-Key": apiKey } : {}),
187
+ ...(bearerToken ? { "AUTHORIZATION": `Bearer ${bearerToken}` } : {}),
188
+ ...extraHeaders,
189
+ }
190
+
191
+ const response = await fetch(url, {
192
+ ...options,
193
+ headers,
194
+ })
195
+
196
+ if (!response.ok) {
197
+ try {
198
+ const errBody = (await response.json()) as import("./types/error").ErrorResponse
199
+ throw new Error(`Error ${errBody.code}: ${errBody.message}`)
200
+ } catch {
201
+ throw new Error(`Request to ${url} failed with status ${response.status}`)
202
+ }
203
+ }
204
+
205
+ return (await response.json()) as T
206
+ }
207
+
208
+ /**
209
+ * Internal helper that performs a DELETE request to `${baseURL}${path}`,
210
+ * injecting headers for apiKey or bearerToken if present.
211
+ * Returns the parsed JSON as T, or throws an Error.
212
+ */
213
+ export async function del<T>(
214
+ path: string,
215
+ extraHeaders?: Record<string, string>
216
+ ): Promise<T> {
217
+ if (!baseURL) {
218
+ throw new Error("HTTP client is not initialized. Call initializeApi(...) first.")
219
+ }
220
+
221
+ const url = `${baseURL}${path}`
222
+ const headers: Record<string, string> = extraHeaders ? { ...extraHeaders } : {}
223
+
224
+ if (apiKey) headers["X-API-Key"] = apiKey
225
+ if (bearerToken) headers["AUTHORIZATION"] = `Bearer ${bearerToken}`
226
+
227
+ const response = await fetch(url, {
228
+ method: "DELETE",
229
+ headers,
230
+ })
231
+
232
+ if (!response.ok) {
233
+ try {
234
+ const errBody = (await response.json()) as import("./types/error").ErrorResponse
235
+ throw new Error(`Error ${errBody.code}: ${errBody.message}`)
236
+ } catch {
237
+ throw new Error(`Request to ${url} failed with status ${response.status}`)
238
+ }
239
+ }
240
+
241
+ // If the response is empty, just return undefined
242
+ if (response.status === 204) return undefined as T
243
+ return (await response.json()) as T
244
+ }
245
+
110
246
  /**
111
247
  * Returns the common headers used for API requests, including apiKey and bearerToken if set.
112
248
  */
@@ -0,0 +1,18 @@
1
+ export interface AttestationResponse {
2
+ id: string
3
+ proofId: string
4
+ createdAt: string
5
+ updatedAt: string
6
+ type: string
7
+ data: Record<string, any>
8
+ }
9
+
10
+ export interface AttestationCreateRequest {
11
+ type: string
12
+ data: Record<string, any>
13
+ }
14
+
15
+ export interface AttestationUpdateRequest {
16
+ type?: string
17
+ data?: Record<string, any>
18
+ }