@proveanything/smartlinks 1.0.5 → 1.0.7
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/dist/api/asset.d.ts +21 -0
- package/dist/api/asset.js +100 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/http.d.ts +11 -0
- package/dist/http.js +47 -0
- package/dist/types/asset.d.ts +8 -0
- package/dist/types/asset.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/documentation.json +1395 -234
- package/docs/functions/appConfiguration.get.html +1 -1
- package/docs/functions/asset.getAllForCollection.html +1 -0
- package/docs/functions/asset.getAllForProduct.html +1 -0
- package/docs/functions/asset.getAllForProof.html +1 -0
- package/docs/functions/asset.getForCollection.html +1 -0
- package/docs/functions/asset.getForProduct.html +1 -0
- package/docs/functions/asset.getForProof.html +1 -0
- package/docs/functions/asset.uploadAsset.html +10 -0
- package/docs/functions/collection.get.html +1 -1
- package/docs/functions/initializeApi.html +1 -1
- package/docs/functions/product.get.html +1 -1
- package/docs/functions/product.getAll.html +1 -1
- package/docs/functions/proof.get.html +1 -1
- package/docs/functions/request.html +1 -1
- package/docs/index.html +50 -29
- package/docs/interfaces/AppConfigurationResponse.html +4 -4
- package/docs/interfaces/AssetResponse.html +5 -0
- package/docs/interfaces/CollectionResponse.html +5 -5
- package/docs/interfaces/ErrorResponse.html +3 -3
- package/docs/interfaces/ProductResponse.html +5 -5
- package/docs/interfaces/ProofResponse.html +8 -8
- package/docs/modules/appConfiguration.html +1 -1
- package/docs/modules/asset.html +8 -0
- package/docs/modules/collection.html +1 -1
- package/docs/modules/product.html +1 -1
- package/docs/modules/proof.html +1 -1
- package/docs/modules.html +2 -0
- package/examples/browser-demo.html +20 -9
- package/examples/node-demo.ts +18 -10
- package/examples/react-demo.tsx +29 -15
- package/package.json +1 -1
- package/src/api/asset.ts +133 -0
- package/src/api/index.ts +1 -0
- package/src/http.ts +54 -0
- package/src/types/asset.ts +9 -0
- package/src/types/index.ts +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AssetResponse } from "../types/asset";
|
|
2
|
+
export declare namespace asset {
|
|
3
|
+
function getForCollection(collectionId: string, assetId: string): Promise<AssetResponse>;
|
|
4
|
+
function getAllForCollection(collectionId: string): Promise<AssetResponse[]>;
|
|
5
|
+
function getForProduct(collectionId: string, productId: string, assetId: string): Promise<AssetResponse>;
|
|
6
|
+
function getAllForProduct(collectionId: string, productId: string): Promise<AssetResponse[]>;
|
|
7
|
+
function getForProof(collectionId: string, productId: string, proofId: string, assetId: string): Promise<AssetResponse>;
|
|
8
|
+
function getAllForProof(collectionId: string, productId: string, proofId: string, appId?: string): Promise<AssetResponse[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Uploads an asset file to a proof, with optional extraData as JSON.
|
|
11
|
+
* Supports progress reporting via onProgress callback (browser only).
|
|
12
|
+
* @param collectionId - The collection ID
|
|
13
|
+
* @param productId - The product ID
|
|
14
|
+
* @param proofId - The proof ID
|
|
15
|
+
* @param file - The file to upload
|
|
16
|
+
* @param extraData - Arbitrary extra data to include (will be stringified as JSON)
|
|
17
|
+
* @param onProgress - Optional callback for upload progress (0-100)
|
|
18
|
+
* @returns Promise resolving to an AssetResponse object
|
|
19
|
+
*/
|
|
20
|
+
function uploadAsset(collectionId: string, productId: string, proofId: string, file: File, extraData?: Record<string, any>, onProgress?: (percent: number) => void): Promise<AssetResponse>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { request, getApiHeaders } from "../http";
|
|
2
|
+
export var asset;
|
|
3
|
+
(function (asset) {
|
|
4
|
+
// Collection-level
|
|
5
|
+
async function getForCollection(collectionId, assetId) {
|
|
6
|
+
const path = `/public/collection/${encodeURIComponent(collectionId)}/asset/${encodeURIComponent(assetId)}`;
|
|
7
|
+
return request(path);
|
|
8
|
+
}
|
|
9
|
+
asset.getForCollection = getForCollection;
|
|
10
|
+
async function getAllForCollection(collectionId) {
|
|
11
|
+
const path = `/public/collection/${encodeURIComponent(collectionId)}/asset`;
|
|
12
|
+
return request(path);
|
|
13
|
+
}
|
|
14
|
+
asset.getAllForCollection = getAllForCollection;
|
|
15
|
+
// Product-level
|
|
16
|
+
async function getForProduct(collectionId, productId, assetId) {
|
|
17
|
+
const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/asset/${encodeURIComponent(assetId)}`;
|
|
18
|
+
return request(path);
|
|
19
|
+
}
|
|
20
|
+
asset.getForProduct = getForProduct;
|
|
21
|
+
async function getAllForProduct(collectionId, productId) {
|
|
22
|
+
const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/asset`;
|
|
23
|
+
return request(path);
|
|
24
|
+
}
|
|
25
|
+
asset.getAllForProduct = getAllForProduct;
|
|
26
|
+
// Proof-level
|
|
27
|
+
async function getForProof(collectionId, productId, proofId, assetId) {
|
|
28
|
+
const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/asset/${encodeURIComponent(assetId)}`;
|
|
29
|
+
return request(path);
|
|
30
|
+
}
|
|
31
|
+
asset.getForProof = getForProof;
|
|
32
|
+
async function getAllForProof(collectionId, productId, proofId, appId) {
|
|
33
|
+
let path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/asset`;
|
|
34
|
+
if (appId) {
|
|
35
|
+
path += `?appId=${encodeURIComponent(appId)}`;
|
|
36
|
+
}
|
|
37
|
+
return request(path);
|
|
38
|
+
}
|
|
39
|
+
asset.getAllForProof = getAllForProof;
|
|
40
|
+
/**
|
|
41
|
+
* Uploads an asset file to a proof, with optional extraData as JSON.
|
|
42
|
+
* Supports progress reporting via onProgress callback (browser only).
|
|
43
|
+
* @param collectionId - The collection ID
|
|
44
|
+
* @param productId - The product ID
|
|
45
|
+
* @param proofId - The proof ID
|
|
46
|
+
* @param file - The file to upload
|
|
47
|
+
* @param extraData - Arbitrary extra data to include (will be stringified as JSON)
|
|
48
|
+
* @param onProgress - Optional callback for upload progress (0-100)
|
|
49
|
+
* @returns Promise resolving to an AssetResponse object
|
|
50
|
+
*/
|
|
51
|
+
async function uploadAsset(collectionId, productId, proofId, file, extraData, onProgress) {
|
|
52
|
+
const path = `/public/collection/${encodeURIComponent(collectionId)}/product/${encodeURIComponent(productId)}/proof/${encodeURIComponent(proofId)}/asset`;
|
|
53
|
+
const url = (typeof window !== "undefined" && window.SMARTLINKS_API_BASEURL)
|
|
54
|
+
? window.SMARTLINKS_API_BASEURL + path
|
|
55
|
+
: path; // fallback for SSR or Node
|
|
56
|
+
const formData = new FormData();
|
|
57
|
+
formData.append("file", file);
|
|
58
|
+
if (extraData) {
|
|
59
|
+
formData.append("extraData", JSON.stringify(extraData));
|
|
60
|
+
}
|
|
61
|
+
// Use getApiHeaders from http module
|
|
62
|
+
const headers = getApiHeaders ? getApiHeaders() : {};
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const xhr = new XMLHttpRequest();
|
|
65
|
+
xhr.open("POST", url);
|
|
66
|
+
// Set headers for API key and bearer token if available
|
|
67
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
68
|
+
xhr.setRequestHeader(key, value);
|
|
69
|
+
}
|
|
70
|
+
xhr.upload.onprogress = (event) => {
|
|
71
|
+
if (onProgress && event.lengthComputable) {
|
|
72
|
+
const percent = Math.round((event.loaded / event.total) * 100);
|
|
73
|
+
onProgress(percent);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
xhr.onload = () => {
|
|
77
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
78
|
+
try {
|
|
79
|
+
resolve(JSON.parse(xhr.responseText));
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
reject(new Error("Failed to parse server response"));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
try {
|
|
87
|
+
const errBody = JSON.parse(xhr.responseText);
|
|
88
|
+
reject(new Error(`Error ${errBody.code}: ${errBody.message}`));
|
|
89
|
+
}
|
|
90
|
+
catch (_a) {
|
|
91
|
+
reject(new Error(`Asset upload failed with status ${xhr.status}`));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
xhr.onerror = () => reject(new Error("Network error during asset upload"));
|
|
96
|
+
xhr.send(formData);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
asset.uploadAsset = uploadAsset;
|
|
100
|
+
})(asset || (asset = {}));
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
package/dist/http.d.ts
CHANGED
|
@@ -16,3 +16,14 @@ export declare function initializeApi(options: {
|
|
|
16
16
|
* Returns the parsed JSON as T, or throws an Error.
|
|
17
17
|
*/
|
|
18
18
|
export declare function request<T>(path: string): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Internal helper that performs a POST request to `${baseURL}${path}`,
|
|
21
|
+
* injecting headers for apiKey or bearerToken if present.
|
|
22
|
+
* If body is FormData, Content-Type is not set.
|
|
23
|
+
* Returns the parsed JSON as T, or throws an Error.
|
|
24
|
+
*/
|
|
25
|
+
export declare function post<T>(path: string, body: any, extraHeaders?: Record<string, string>): Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the common headers used for API requests, including apiKey and bearerToken if set.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getApiHeaders(): Record<string, string>;
|
package/dist/http.js
CHANGED
|
@@ -52,3 +52,50 @@ export async function request(path) {
|
|
|
52
52
|
}
|
|
53
53
|
return (await response.json());
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Internal helper that performs a POST request to `${baseURL}${path}`,
|
|
57
|
+
* injecting headers for apiKey or bearerToken if present.
|
|
58
|
+
* If body is FormData, Content-Type is not set.
|
|
59
|
+
* Returns the parsed JSON as T, or throws an Error.
|
|
60
|
+
*/
|
|
61
|
+
export async function post(path, body, extraHeaders) {
|
|
62
|
+
if (!baseURL) {
|
|
63
|
+
throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
|
|
64
|
+
}
|
|
65
|
+
const url = `${baseURL}${path}`;
|
|
66
|
+
const headers = extraHeaders ? Object.assign({}, extraHeaders) : {};
|
|
67
|
+
if (apiKey)
|
|
68
|
+
headers["X-API-Key"] = apiKey;
|
|
69
|
+
if (bearerToken)
|
|
70
|
+
headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
|
|
71
|
+
// Only set Content-Type for non-FormData bodies
|
|
72
|
+
if (!(body instanceof FormData)) {
|
|
73
|
+
headers["Content-Type"] = "application/json";
|
|
74
|
+
}
|
|
75
|
+
const response = await fetch(url, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers,
|
|
78
|
+
body: body instanceof FormData ? body : JSON.stringify(body),
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
try {
|
|
82
|
+
const errBody = (await response.json());
|
|
83
|
+
throw new Error(`Error ${errBody.code}: ${errBody.message}`);
|
|
84
|
+
}
|
|
85
|
+
catch (_a) {
|
|
86
|
+
throw new Error(`Request to ${url} failed with status ${response.status}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return (await response.json());
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the common headers used for API requests, including apiKey and bearerToken if set.
|
|
93
|
+
*/
|
|
94
|
+
export function getApiHeaders() {
|
|
95
|
+
const headers = {};
|
|
96
|
+
if (apiKey)
|
|
97
|
+
headers["X-API-Key"] = apiKey;
|
|
98
|
+
if (bearerToken)
|
|
99
|
+
headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
|
|
100
|
+
return headers;
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.navigationData = "data:application/octet-stream;base64,
|
|
1
|
+
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAACpWUzW6DMBCE38Vn1EhVmgM3FLXnqteoB2TWxKrjdfwjVa3y7hUVBNs4xlxh/DGznuX0Syx8W1KTVqkjSsZ7p1vLUZKKqNaeSU0u2DkBZhcrns72IkhFvrjsSL2vCD1z0WmQpD7dsT3YmcScpMPJBKsHG/IO+9vnrZrtGeOT7p6Gx6VGGiHeUB9RCKBhRM/YPzAhXrirluh3jZ2j6cAhd1QWQpGVIZHlgeXpN0QvzF0auihxQVynBLZdE9YmRnmibPtoYmpTBemDOW1bCI+ytgoqnvbkRKXmu83GhEh5iLu5cr4RYi2Gf8teiPheN0dAtjrEJvoBfYBRKA3MRC4taNZSMLtH4vALzy8H/wNDqfJUX5FDzZuY5S1lOeir1qizvECRQ417nYVFmhUcsjXYrMihuOSWt4L/QKN4qiyBINN4DVcHJtm38dWybX+3gK5VXAcAAA=="
|
package/docs/assets/search.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.searchData = "data:application/octet-stream;base64,
|
|
1
|
+
window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAACqVaTY/iSAz9L9XXiKY++Lyh0YzUt9Ee9hKhVQQFE01I2CT0rhbx31eVBGIHu0g6J9Qd28/2e64UVVxFnv1TiHV4Fb/jdC/WcxOINDpZsRZxGpdxlMT/2c05FoG45IlYi8Ml3ZVxlhbv6PnkV3lKRCB2SVQUthBrIW4BETS3f19sURLhmifeQG2cXZYktvJ8hDpl+0tii/f2Ud+kjpZKCMQ5WiqvQJyj3KYlTofK9pxn+8uufEq1+f+4PO9BXiZ5z4KLvUkSf/hNkgxFQD3IDlQHssPo+rNDr+qzA5lZdD5/y9JDfLzkEamorsG4fJ+ivUz9KUGyiqKwzwqr/jsg3x9Z/u15tEDyVbyu4Yv0q8w8qusN2rUdg/sjy392xpIu8y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