@proveanything/smartlinks 1.0.29 → 1.0.31

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/API_SUMMARY.md +771 -213
  2. package/README.md +13109 -0
  3. package/dist/api/appRecord.d.ts +6 -0
  4. package/dist/api/appRecord.js +29 -0
  5. package/dist/api/auth.d.ts +12 -0
  6. package/dist/api/auth.js +18 -0
  7. package/dist/api/index.d.ts +1 -0
  8. package/dist/api/index.js +1 -0
  9. package/dist/http.d.ts +5 -3
  10. package/dist/http.js +5 -3
  11. package/package.json +19 -3
  12. package/build-docs.ts +0 -69
  13. package/debug.log +0 -6
  14. package/examples/browser-demo.html +0 -43
  15. package/examples/node-demo.ts +0 -50
  16. package/examples/react-demo.tsx +0 -58
  17. package/generate-api-summary.js +0 -279
  18. package/generate-api-summary.ts +0 -83
  19. package/openapi.yaml +0 -130
  20. package/scripts/copy-docs.js +0 -11
  21. package/src/api/appConfiguration.ts +0 -104
  22. package/src/api/asset.ts +0 -133
  23. package/src/api/attestation.ts +0 -69
  24. package/src/api/auth.ts +0 -103
  25. package/src/api/batch.ts +0 -173
  26. package/src/api/claimSet.ts +0 -131
  27. package/src/api/collection.ts +0 -117
  28. package/src/api/crate.ts +0 -43
  29. package/src/api/form.ts +0 -57
  30. package/src/api/index.ts +0 -14
  31. package/src/api/product.ts +0 -128
  32. package/src/api/proof.ts +0 -32
  33. package/src/api/serialNumber.ts +0 -0
  34. package/src/api/variant.ts +0 -173
  35. package/src/http.ts +0 -363
  36. package/src/index.ts +0 -29
  37. package/src/types/appConfiguration.ts +0 -12
  38. package/src/types/asset.ts +0 -9
  39. package/src/types/attestation.ts +0 -19
  40. package/src/types/batch.ts +0 -15
  41. package/src/types/collection.ts +0 -68
  42. package/src/types/error.ts +0 -10
  43. package/src/types/index.ts +0 -11
  44. package/src/types/product.ts +0 -33
  45. package/src/types/proof.ts +0 -20
  46. package/src/types/serialNumber.ts +0 -0
  47. package/src/types/variant.ts +0 -15
  48. package/tsconfig.json +0 -15
  49. package/typedoc.json +0 -18
@@ -0,0 +1,6 @@
1
+ export declare namespace appRecord {
2
+ function get(collectionId: string, appId: string): Promise<any>;
3
+ function create(collectionId: string, appId: string, data: any): Promise<any>;
4
+ function update(collectionId: string, appId: string, data: any): Promise<any>;
5
+ function remove(collectionId: string, appId: string): Promise<void>;
6
+ }
@@ -0,0 +1,29 @@
1
+ // src/api/appRecord.ts
2
+ import { request, post, put, del } from "../http";
3
+ export var appRecord;
4
+ (function (appRecord) {
5
+ // Get app record (admin only)
6
+ async function get(collectionId, appId) {
7
+ const path = `/api/v1/admin/collection/${encodeURIComponent(collectionId)}/app/${encodeURIComponent(appId)}`;
8
+ return request(path);
9
+ }
10
+ appRecord.get = get;
11
+ // Create app record (admin only)
12
+ async function create(collectionId, appId, data) {
13
+ const path = `/api/v1/admin/collection/${encodeURIComponent(collectionId)}/app/${encodeURIComponent(appId)}`;
14
+ return post(path, data);
15
+ }
16
+ appRecord.create = create;
17
+ // Update app record (admin only)
18
+ async function update(collectionId, appId, data) {
19
+ const path = `/api/v1/admin/collection/${encodeURIComponent(collectionId)}/app/${encodeURIComponent(appId)}`;
20
+ return put(path, data);
21
+ }
22
+ appRecord.update = update;
23
+ // Delete app record (admin only)
24
+ async function remove(collectionId, appId) {
25
+ const path = `/api/v1/admin/collection/${encodeURIComponent(collectionId)}/app/${encodeURIComponent(appId)}`;
26
+ return del(path);
27
+ }
28
+ appRecord.remove = remove;
29
+ })(appRecord || (appRecord = {}));
@@ -13,6 +13,8 @@ export type VerifyTokenResponse = {
13
13
  account?: Record<string, any>;
14
14
  };
15
15
  export type AccountInfoResponse = {
16
+ jwtToken: string;
17
+ jwtExpiry: number;
16
18
  accessType: string;
17
19
  analyticsCode: string;
18
20
  analyticsId: string;
@@ -60,6 +62,16 @@ export declare namespace auth {
60
62
  * Returns user/account info if valid.
61
63
  */
62
64
  function verifyToken(token?: string): Promise<VerifyTokenResponse>;
65
+ /**
66
+ * Requests an admin JWT for the current user and a specific collection
67
+ * Returns JWT if valid.
68
+ */
69
+ function requestAdminJWT(collectionId: string): Promise<VerifyTokenResponse>;
70
+ /**
71
+ * Requests a JWT for the current user and a specific collection/product/proof
72
+ * Validates if the user has access to the resource, and returns a JWT
73
+ */
74
+ function requestPublicJWT(collectionId: string, productId: string, proofId: string): Promise<VerifyTokenResponse>;
63
75
  /**
64
76
  * Gets current account information for the logged in user.
65
77
  * Returns user, owner, account, and location objects.
package/dist/api/auth.js CHANGED
@@ -42,6 +42,24 @@ export var auth;
42
42
  return result;
43
43
  }
44
44
  auth.verifyToken = verifyToken;
45
+ /**
46
+ * Requests an admin JWT for the current user and a specific collection
47
+ * Returns JWT if valid.
48
+ */
49
+ async function requestAdminJWT(collectionId) {
50
+ // Use the provided token, or the one from getApiHeaders
51
+ return post("/admin/auth/requestJWT", { collectionId });
52
+ }
53
+ auth.requestAdminJWT = requestAdminJWT;
54
+ /**
55
+ * Requests a JWT for the current user and a specific collection/product/proof
56
+ * Validates if the user has access to the resource, and returns a JWT
57
+ */
58
+ async function requestPublicJWT(collectionId, productId, proofId) {
59
+ // Use the provided token, or the one from getApiHeaders
60
+ return post("/public/auth/requestJWT", { collectionId, productId, proofId });
61
+ }
62
+ auth.requestPublicJWT = requestPublicJWT;
45
63
  /**
46
64
  * Gets current account information for the logged in user.
47
65
  * Returns user, owner, account, and location objects.
@@ -2,6 +2,7 @@ export { collection } from "./collection";
2
2
  export { product } from "./product";
3
3
  export { proof } from "./proof";
4
4
  export { appConfiguration } from "./appConfiguration";
5
+ export { appRecord } from "./appRecord";
5
6
  export { asset } from "./asset";
6
7
  export { attestation } from "./attestation";
7
8
  export { auth } from "./auth";
package/dist/api/index.js CHANGED
@@ -4,6 +4,7 @@ export { collection } from "./collection";
4
4
  export { product } from "./product";
5
5
  export { proof } from "./proof";
6
6
  export { appConfiguration } from "./appConfiguration";
7
+ export { appRecord } from "./appRecord";
7
8
  export { asset } from "./asset";
8
9
  export { attestation } from "./attestation";
9
10
  export { auth } from "./auth";
package/dist/http.d.ts CHANGED
@@ -54,9 +54,11 @@ export declare function del<T>(path: string, extraHeaders?: Record<string, strin
54
54
  */
55
55
  export declare function getApiHeaders(): Record<string, string>;
56
56
  /**
57
- * Sends a custom proxy message in proxyMode and waits for a matching reply.
58
- * @param request - The request type string
59
- * @param params - The parameters object
57
+ * Sends a custom proxy message to the parent Smartlinks application when running in an iframe.
58
+ * This function is used to communicate with the parent window when the SDK is embedded in an iframe
59
+ * and proxyMode is enabled. It sends a message to the parent and waits for a response.
60
+ * @param request - The request type string to identify the message type
61
+ * @param params - The parameters object containing data to send to the parent
60
62
  * @returns The data from the proxy response
61
63
  */
62
64
  export declare function sendCustomProxyMessage<T = any>(request: string, params: any): Promise<T>;
package/dist/http.js CHANGED
@@ -279,9 +279,11 @@ export function getApiHeaders() {
279
279
  return headers;
280
280
  }
281
281
  /**
282
- * Sends a custom proxy message in proxyMode and waits for a matching reply.
283
- * @param request - The request type string
284
- * @param params - The parameters object
282
+ * Sends a custom proxy message to the parent Smartlinks application when running in an iframe.
283
+ * This function is used to communicate with the parent window when the SDK is embedded in an iframe
284
+ * and proxyMode is enabled. It sends a message to the parent and waits for a response.
285
+ * @param request - The request type string to identify the message type
286
+ * @param params - The parameters object containing data to send to the parent
285
287
  * @returns The data from the proxy response
286
288
  */
287
289
  export async function sendCustomProxyMessage(request, params) {
package/package.json CHANGED
@@ -1,15 +1,30 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/",
9
+ "README.md",
10
+ "API_SUMMARY.md"
11
+ ],
7
12
  "scripts": {
8
13
  "build": "tsc",
9
14
  "docs": "typedoc",
10
15
  "docs:summary": "node generate-api-summary.js",
11
- "build:docs": "tsc build-docs.ts --outDir dist && node dist/build-docs.js"
16
+ "build:docs": "tsc build-docs.ts --outDir dist && node dist/build-docs.js",
17
+ "prepublishOnly": "npm run build && npm run docs:summary"
12
18
  },
19
+ "keywords": [
20
+ "smartlinks",
21
+ "api",
22
+ "authentication",
23
+ "traceability",
24
+ "blockchain",
25
+ "typescript",
26
+ "sdk"
27
+ ],
13
28
  "author": "Glenn Shoosmith",
14
29
  "license": "MIT",
15
30
  "publishConfig": {
@@ -27,5 +42,6 @@
27
42
  "repository": {
28
43
  "type": "git",
29
44
  "url": "https://github.com/Prove-Anything/smartlinks.git"
30
- }
45
+ },
46
+ "homepage": "https://smartlinks.app"
31
47
  }
package/build-docs.ts DELETED
@@ -1,69 +0,0 @@
1
- import { execSync } from "child_process"
2
- import { readdirSync, readFileSync, writeFileSync, existsSync, mkdirSync } from "fs"
3
- import { join, extname } from "path"
4
-
5
- // Run TypeDoc to generate markdown docs in temp-docs
6
- execSync("npx typedoc --out temp-docs --plugin typedoc-plugin-markdown --entryPoints src/index.ts --excludePrivate --excludeInternal --hideBreadcrumbs --hidePageTitle", { stdio: "inherit" })
7
-
8
- const tempDocsDir = join(__dirname, "..", "temp-docs")
9
- const docsDir = join(__dirname, "..", "docs")
10
- const outPath = join(docsDir, "README.md")
11
-
12
- if (!existsSync(docsDir)) mkdirSync(docsDir)
13
-
14
- const files = readdirSync(tempDocsDir)
15
- .filter(f => extname(f) === ".md")
16
- .sort((a, b) => a === "modules.md" ? -1 : a.localeCompare(b)) // modules.md first
17
-
18
- let content = "# Smartlinks SDK Documentation\n\n"
19
- for (const file of files) {
20
- const fileContent = readFileSync(join(tempDocsDir, file), "utf-8")
21
- // Remove redundant titles (except for the first file)
22
- content += file === "modules.md"
23
- ? fileContent + "\n\n"
24
- : fileContent.replace(/^# .*\n/, "") + "\n\n"
25
- }
26
-
27
- writeFileSync(outPath, content)
28
- console.log("Documentation built at docs/README.md")
29
-
30
- import * as fs from "fs";
31
- import * as path from "path";
32
-
33
- // Use process.cwd() to ensure relative to project root
34
- const docsJsonPath = path.join(process.cwd(), "docs", "documentation.json");
35
- const readmePath = path.join(process.cwd(), "README.md");
36
-
37
- function extractFullApiDocs(json: any): string {
38
- // This is a minimal implementation. For a full-featured generator,
39
- // parse all namespaces, functions, and types from the TypeDoc JSON.
40
- // Here, we just dump the JSON for demonstration.
41
- // Replace this with a real markdown generator as needed.
42
- return [
43
- "# @proveanything/smartlinks",
44
- "",
45
- "This README is auto-generated from the TypeScript API documentation.",
46
- "",
47
- "## API Reference",
48
- "",
49
- "```json",
50
- JSON.stringify(json, null, 2),
51
- "```",
52
- "",
53
- "_Replace this with a full markdown generator for production use._"
54
- ].join("\n");
55
- }
56
-
57
- function main() {
58
- console.log("Looking for docs JSON at:", docsJsonPath);
59
-
60
- if (!fs.existsSync(docsJsonPath)) {
61
- throw new Error("documentation.json not found. Run `npm run docs` first.");
62
- }
63
- const json = JSON.parse(fs.readFileSync(docsJsonPath, "utf-8"));
64
- const markdown = extractFullApiDocs(json);
65
- fs.writeFileSync(readmePath, markdown, "utf-8");
66
- console.log("README.md generated from API documentation.");
67
- }
68
-
69
- main();
package/debug.log DELETED
@@ -1,6 +0,0 @@
1
- [0602/081836.172:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
2
- [0602/081836.202:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
3
- [0602/081836.512:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
4
- [0602/081858.471:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
5
- [0602/081858.497:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
6
- [0602/081858.832:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
@@ -1,43 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Smartlinks SDK Browser Demo</title>
6
- </head>
7
- <body>
8
- <h1>Smartlinks SDK Browser Demo</h1>
9
- <pre id="output"></pre>
10
- <script type="module">
11
- import { initializeApi } from '../dist/index.js';
12
- import { collection } from '../dist/api/collection.js';
13
- import { product } from '../dist/api/product.js';
14
- import { proof } from '../dist/api/proof.js';
15
-
16
- async function run() {
17
- const apiKey = 'YOUR_API_KEY'; // optional
18
- const bearerToken = 'YOUR_BEARER_TOKEN'; // optional
19
-
20
- // Initialize global config for API requests
21
- initializeApi({
22
- baseURL: 'https://smartlinks.app/api/v1',
23
- apiKey,
24
- bearerToken,
25
- });
26
-
27
- try {
28
- const collectionData = await collection.get('abc123');
29
- const productData = await product.get('abc123', 'prod789');
30
- const proofData = await proof.get('abc123', 'proof456');
31
- document.getElementById('output').textContent = JSON.stringify(
32
- { collection: collectionData, product: productData, proof: proofData },
33
- null,
34
- 2
35
- );
36
- } catch (err) {
37
- document.getElementById('output').textContent = 'Error: ' + err.message;
38
- }
39
- }
40
- run();
41
- </script>
42
- </body>
43
- </html>
@@ -1,50 +0,0 @@
1
- import { initializeApi } from "../dist/index";
2
- import { collection } from "../dist/api/collection";
3
- import { product } from "../dist/api/product";
4
- import { proof } from "../dist/api/proof";
5
- import { batch } from "../dist/api/batch";
6
-
7
- async function main() {
8
- const apiKey = "YOUR_API_KEY"; // optional
9
- const bearerToken = "YOUR_BEARER_TOKEN"; // optional
10
-
11
- initializeApi({
12
- baseURL: "https://smartlinks.app/api/v1",
13
- apiKey,
14
- bearerToken,
15
- });
16
-
17
- try {
18
- const collectionData = await collection.get("abc123");
19
- console.log("Collection:", collectionData);
20
-
21
- const productData = await product.get("abc123", "prod789");
22
- console.log("Product Item:", productData);
23
-
24
- const proofData = await proof.get("abc123", "proof456");
25
- console.log("Proof:", proofData);
26
-
27
- // Batch API examples
28
- // Admin operations (requires admin privileges)
29
- const batchList = await batch.list("abc123", "prod789");
30
- console.log("Batch List:", batchList);
31
-
32
- const newBatch = await batch.create("abc123", "prod789", {
33
- name: "New Batch",
34
- description: "Example batch creation",
35
- status: "active",
36
- });
37
- console.log("Created Batch:", newBatch);
38
-
39
- const batchData = await batch.get("abc123", "prod789", newBatch.id);
40
- console.log("Batch:", batchData);
41
-
42
- // Public batch endpoint (read-only)
43
- const publicBatchData = await batch.getPublic("abc123", "prod789", newBatch.id);
44
- console.log("Public Batch:", publicBatchData);
45
- } catch (err) {
46
- console.error("Error fetching data:", err);
47
- }
48
- }
49
-
50
- main();
@@ -1,58 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { initializeApi } from '../dist/index';
3
- import { collection } from '../dist/api/collection';
4
- import { product } from '../dist/api/product';
5
- import { proof } from '../dist/api/proof';
6
- import type { CollectionResponse } from '../dist/types/collection';
7
- import type { ProductResponse } from '../dist/types/product';
8
- import type { ProofResponse } from '../dist/types/proof';
9
-
10
- // You can provide either or both of these values:
11
- const apiKey = 'YOUR_API_KEY'; // optional
12
- const bearerToken = 'YOUR_BEARER_TOKEN'; // optional
13
-
14
- initializeApi({
15
- baseURL: 'https://smartlinks.app/api/v1',
16
- apiKey,
17
- bearerToken,
18
- });
19
-
20
- const ReactDemo: React.FC = () => {
21
- const [collectionData, setCollection] = useState<CollectionResponse | null>(null);
22
- const [productData, setProduct] = useState<ProductResponse | null>(null);
23
- const [proofData, setProof] = useState<ProofResponse | null>(null);
24
- const [error, setError] = useState<string | null>(null);
25
-
26
- useEffect(() => {
27
- async function fetchData() {
28
- try {
29
- const col = await collection.get('abc123');
30
- const prod = await product.get('abc123', 'prod789');
31
- const prf = await proof.get('abc123', 'proof456');
32
- setCollection(col);
33
- setProduct(prod);
34
- setProof(prf);
35
- } catch (err) {
36
- setError((err as Error).message);
37
- }
38
- }
39
- fetchData();
40
- }, []);
41
-
42
- if (error) return <div>Error: {error}</div>;
43
- if (!collectionData || !productData || !proofData) return <div>Loading...</div>;
44
-
45
- return (
46
- <div>
47
- <h1>{collectionData.title}</h1>
48
- <img src={collectionData.logoImage} alt={collectionData.title} width="100" />
49
- <h2>{productData.name}</h2>
50
- <img src={productData.heroImage} alt={productData.name} width="100" />
51
- <p>{productData.description}</p>
52
- <h3>Proof</h3>
53
- <pre>{JSON.stringify(proofData, null, 2)}</pre>
54
- </div>
55
- );
56
- };
57
-
58
- export default ReactDemo;