@proveanything/smartlinks 1.0.12 → 1.0.14
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/auth.d.ts +11 -0
- package/dist/api/auth.js +9 -1
- package/dist/http.d.ts +1 -0
- package/dist/http.js +62 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/documentation.json +615 -427
- package/docs/functions/appConfiguration.get.html +1 -1
- package/docs/functions/asset.getForCollection.html +1 -1
- package/docs/functions/asset.getForProduct.html +1 -1
- package/docs/functions/asset.getForProof.html +1 -1
- package/docs/functions/asset.listForCollection.html +1 -1
- package/docs/functions/asset.listForProduct.html +1 -1
- package/docs/functions/asset.listForProof.html +1 -1
- package/docs/functions/asset.uploadAsset.html +1 -1
- package/docs/functions/attestation.create.html +1 -1
- package/docs/functions/attestation.get.html +1 -1
- package/docs/functions/attestation.list.html +1 -1
- package/docs/functions/attestation.remove.html +1 -1
- package/docs/functions/attestation.update.html +1 -1
- package/docs/functions/auth.getAccount.html +3 -0
- package/docs/functions/auth.login.html +1 -1
- package/docs/functions/auth.logout.html +1 -1
- package/docs/functions/auth.verifyToken.html +3 -0
- package/docs/functions/collection.get.html +1 -1
- package/docs/functions/initializeApi.html +2 -2
- package/docs/functions/product.get.html +1 -1
- package/docs/functions/product.list.html +1 -1
- package/docs/functions/proof.get.html +1 -1
- package/docs/functions/proof.list.html +1 -1
- package/docs/functions/request.html +1 -1
- package/docs/interfaces/AppConfigurationResponse.html +4 -4
- package/docs/interfaces/AssetResponse.html +2 -2
- 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 +1 -1
- package/docs/modules/attestation.html +1 -1
- package/docs/modules/auth.html +3 -1
- package/docs/modules/collection.html +1 -1
- package/docs/modules/product.html +1 -1
- package/docs/modules/proof.html +1 -1
- package/package.json +1 -1
- package/src/api/auth.ts +16 -1
- package/src/http.ts +75 -0
package/dist/api/auth.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ type VerifyTokenResponse = {
|
|
|
12
12
|
email?: string;
|
|
13
13
|
account?: Record<string, any>;
|
|
14
14
|
};
|
|
15
|
+
type AccountInfoResponse = {
|
|
16
|
+
user: Record<string, any>;
|
|
17
|
+
owner: Record<string, any>;
|
|
18
|
+
account: Record<string, any>;
|
|
19
|
+
location: Record<string, any>;
|
|
20
|
+
};
|
|
15
21
|
export declare namespace auth {
|
|
16
22
|
/**
|
|
17
23
|
* Login with email and password.
|
|
@@ -27,5 +33,10 @@ export declare namespace auth {
|
|
|
27
33
|
* Returns user/account info if valid.
|
|
28
34
|
*/
|
|
29
35
|
function verifyToken(token?: string): Promise<VerifyTokenResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Gets current account information for the logged in user.
|
|
38
|
+
* Returns user, owner, account, and location objects.
|
|
39
|
+
*/
|
|
40
|
+
function getAccount(): Promise<AccountInfoResponse>;
|
|
30
41
|
}
|
|
31
42
|
export {};
|
package/dist/api/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { post, setBearerToken, getApiHeaders } from "../http";
|
|
1
|
+
import { post, request, setBearerToken, getApiHeaders } from "../http";
|
|
2
2
|
export var auth;
|
|
3
3
|
(function (auth) {
|
|
4
4
|
/**
|
|
@@ -35,4 +35,12 @@ export var auth;
|
|
|
35
35
|
return result;
|
|
36
36
|
}
|
|
37
37
|
auth.verifyToken = verifyToken;
|
|
38
|
+
/**
|
|
39
|
+
* Gets current account information for the logged in user.
|
|
40
|
+
* Returns user, owner, account, and location objects.
|
|
41
|
+
*/
|
|
42
|
+
async function getAccount() {
|
|
43
|
+
return request("/public/auth/account");
|
|
44
|
+
}
|
|
45
|
+
auth.getAccount = getAccount;
|
|
38
46
|
})(auth || (auth = {}));
|
package/dist/http.d.ts
CHANGED
package/dist/http.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
let baseURL = null;
|
|
6
6
|
let apiKey = undefined;
|
|
7
7
|
let bearerToken = undefined;
|
|
8
|
+
let proxyMode = false;
|
|
8
9
|
/**
|
|
9
10
|
* Call this once (e.g. at app startup) to configure baseURL/auth.
|
|
10
11
|
*
|
|
@@ -16,6 +17,7 @@ export function initializeApi(options) {
|
|
|
16
17
|
baseURL = options.baseURL.replace(/\/+\$/, ""); // trim trailing slash
|
|
17
18
|
apiKey = options.apiKey;
|
|
18
19
|
bearerToken = options.bearerToken;
|
|
20
|
+
proxyMode = !!options.proxyMode;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Allows setting the bearerToken at runtime (e.g. after login/logout).
|
|
@@ -23,12 +25,60 @@ export function initializeApi(options) {
|
|
|
23
25
|
export function setBearerToken(token) {
|
|
24
26
|
bearerToken = token;
|
|
25
27
|
}
|
|
28
|
+
// Map of pending proxy requests: id -> {resolve, reject}
|
|
29
|
+
const proxyPending = {};
|
|
30
|
+
function generateProxyId() {
|
|
31
|
+
return "proxy_" + Math.random().toString(36).slice(2) + Date.now();
|
|
32
|
+
}
|
|
33
|
+
// Shared listener for proxy responses
|
|
34
|
+
function ensureProxyListener() {
|
|
35
|
+
if (window._smartlinksProxyListener)
|
|
36
|
+
return;
|
|
37
|
+
window.addEventListener("message", (event) => {
|
|
38
|
+
const msg = event.data;
|
|
39
|
+
if (!msg || !msg._smartlinksProxyResponse || !msg.id)
|
|
40
|
+
return;
|
|
41
|
+
const pending = proxyPending[msg.id];
|
|
42
|
+
if (pending) {
|
|
43
|
+
if (msg.error) {
|
|
44
|
+
pending.reject(new Error(msg.error));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
pending.resolve(msg.data);
|
|
48
|
+
}
|
|
49
|
+
delete proxyPending[msg.id];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
window._smartlinksProxyListener = true;
|
|
53
|
+
}
|
|
54
|
+
// Proxy request implementation
|
|
55
|
+
async function proxyRequest(method, path, body, headers, options) {
|
|
56
|
+
ensureProxyListener();
|
|
57
|
+
const id = generateProxyId();
|
|
58
|
+
const msg = {
|
|
59
|
+
_smartlinksProxyRequest: true,
|
|
60
|
+
id,
|
|
61
|
+
method,
|
|
62
|
+
path,
|
|
63
|
+
body,
|
|
64
|
+
headers,
|
|
65
|
+
options,
|
|
66
|
+
};
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
proxyPending[id] = { resolve, reject };
|
|
69
|
+
window.parent.postMessage(msg, "*");
|
|
70
|
+
// Optionally: add a timeout here to reject if no response
|
|
71
|
+
});
|
|
72
|
+
}
|
|
26
73
|
/**
|
|
27
74
|
* Internal helper that performs a GET request to \`\${baseURL}\${path}\`,
|
|
28
75
|
* injecting headers for apiKey or bearerToken if present.
|
|
29
76
|
* Returns the parsed JSON as T, or throws an Error.
|
|
30
77
|
*/
|
|
31
78
|
export async function request(path) {
|
|
79
|
+
if (proxyMode) {
|
|
80
|
+
return proxyRequest("GET", path);
|
|
81
|
+
}
|
|
32
82
|
if (!baseURL) {
|
|
33
83
|
throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
|
|
34
84
|
}
|
|
@@ -65,6 +115,9 @@ export async function request(path) {
|
|
|
65
115
|
* Returns the parsed JSON as T, or throws an Error.
|
|
66
116
|
*/
|
|
67
117
|
export async function post(path, body, extraHeaders) {
|
|
118
|
+
if (proxyMode) {
|
|
119
|
+
return proxyRequest("POST", path, body, extraHeaders);
|
|
120
|
+
}
|
|
68
121
|
if (!baseURL) {
|
|
69
122
|
throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
|
|
70
123
|
}
|
|
@@ -101,6 +154,9 @@ export async function post(path, body, extraHeaders) {
|
|
|
101
154
|
* Returns the parsed JSON as T, or throws an Error.
|
|
102
155
|
*/
|
|
103
156
|
export async function put(path, body, extraHeaders) {
|
|
157
|
+
if (proxyMode) {
|
|
158
|
+
return proxyRequest("PUT", path, body, extraHeaders);
|
|
159
|
+
}
|
|
104
160
|
if (!baseURL) {
|
|
105
161
|
throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
|
|
106
162
|
}
|
|
@@ -136,6 +192,9 @@ export async function put(path, body, extraHeaders) {
|
|
|
136
192
|
* Returns the parsed JSON as T, or throws an Error.
|
|
137
193
|
*/
|
|
138
194
|
export async function requestWithOptions(path, options) {
|
|
195
|
+
if (proxyMode) {
|
|
196
|
+
return proxyRequest(options.method || "GET", path, options.body, options.headers, options);
|
|
197
|
+
}
|
|
139
198
|
if (!baseURL) {
|
|
140
199
|
throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
|
|
141
200
|
}
|
|
@@ -176,6 +235,9 @@ export async function requestWithOptions(path, options) {
|
|
|
176
235
|
* Returns the parsed JSON as T, or throws an Error.
|
|
177
236
|
*/
|
|
178
237
|
export async function del(path, extraHeaders) {
|
|
238
|
+
if (proxyMode) {
|
|
239
|
+
return proxyRequest("DELETE", path, undefined, extraHeaders);
|
|
240
|
+
}
|
|
179
241
|
if (!baseURL) {
|
|
180
242
|
throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
|
|
181
243
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.navigationData = "data:application/octet-stream;base64,
|
|
1
|
+
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAACp2VTW+DMAyG/0vOaJWmrgduqNrO07RbtQMKDkSlMQtJtQ/1v0+UUkIaHLoref3w2rGd3S8z8GVYyvKm2aISsrQ6NxIVS1iTm4ql7ICFraFd+YqHyhxqlrC9VAVL1wnjlawLDYqluyu2BDOShFW8iwywSjBT3mZ9+jglo722dUlXT93npUZeUG+xroFP83NcnWm+8sZX4kFfNRaWh/N0iBfZEhyKBTAUBKqW7dJ8b6RxbDTjqW4RkMrZVREw29SYF9m0VXyWI6I7zhhozdwsjIeLuo9ryA0ETTmkXkU3SIwRGqRpuWOETkMgNBzwGE2lV5F3VSyoSK+i78maKnBB1lRL90LGOVoVrkuHGSVUZbGU4SHrEOdTOhrtvIP+mIg/gpbi+x33MO/B0ZAF5YGdMZSVzyyJ+7a/Q4nt/cbfNIOTJrRa7rMxIP43MkN0cFy8FNzd5iTgL7O77aP4v3kUceuZ90y/Qdugap2xlcqAFjmHdjUnnv7h8Wnj/qBbwzTVVVCo8f0iebcyCvqsNWqSN1FQqMtbSMI8TQSHIgYbFRRKKmlkXssfyBoZ6paJgHwaPi2EG+5ydNttf5suZV+CCgAA"
|
package/docs/assets/search.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.searchData = "data:application/octet-stream;base64,
|
|
1
|
+
window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAACqVayW7jSAz9l8pVcFybt1vQmAH61hgM5mIEA8EuO0LblkdLZgny74MqyRYpk1qik5GI5CP5HksllT5Elv6di832Q/xMLnuxWZhIXOKzExuRXJIiiU/Jf+7lmohIlNlJbMShvOyKJL3kz+j67K04n0Qkdqc4z10uNkJ8RkTQzP1VurwgwtVXOgM1cXbp6eSC5z3UOd2XJ5c/N5eGJnV0VEIgztFReUXiGmfuUuB0qGyvWbovd8VDqvX/p+V5C9Kb5C0LMvYpIVm5BfeXx0ZH9acHqvr0MLn29DCo8vQwtu70MKxqFLkJHF+v39LLITmWWUzqtG0wrRMP0Xqb8pAgWUWeu0fdhv+OyPfXNPv2OLAg+RCvbdiTfsiM5XQY5IPllzGr5H+0Bp0u8Qc79qPq6wPDZtMrAyPM1kUO9NiqOoCg0ZeRyuspjfcvSNptIGAzDgfMTlG4vGCGv7k2dI6YlQpG6l+vYE5jVhcA0r+w9GHsMhcXrgemMpqIVF73/UiV0USkzJ3T9z6kyugrSEBVZfH2KKeyeBuso/SYkCuijxEu9iToE+AipyUpnzp0WvZJh4397rLk8O/v6U/H5g5MvopydMXLbpeWF7aKxmIUhrKLO0hzt/nN5df0kjeySS6Fyw7xzuXPj1adBMu5Alv3/YiIT8GaroJI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