@proveanything/smartlinks 1.0.28 → 1.0.30

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 (44) hide show
  1. package/API_SUMMARY.md +672 -213
  2. package/README.md +430 -0
  3. package/dist/api/collection.js +1 -1
  4. package/dist/http.d.ts +5 -3
  5. package/dist/http.js +5 -3
  6. package/package.json +19 -3
  7. package/build-docs.ts +0 -69
  8. package/debug.log +0 -6
  9. package/examples/browser-demo.html +0 -43
  10. package/examples/node-demo.ts +0 -50
  11. package/examples/react-demo.tsx +0 -58
  12. package/generate-api-summary.js +0 -279
  13. package/generate-api-summary.ts +0 -83
  14. package/openapi.yaml +0 -130
  15. package/scripts/copy-docs.js +0 -11
  16. package/src/api/appConfiguration.ts +0 -104
  17. package/src/api/asset.ts +0 -133
  18. package/src/api/attestation.ts +0 -69
  19. package/src/api/auth.ts +0 -103
  20. package/src/api/batch.ts +0 -173
  21. package/src/api/claimSet.ts +0 -131
  22. package/src/api/collection.ts +0 -117
  23. package/src/api/crate.ts +0 -43
  24. package/src/api/form.ts +0 -57
  25. package/src/api/index.ts +0 -14
  26. package/src/api/product.ts +0 -128
  27. package/src/api/proof.ts +0 -32
  28. package/src/api/serialNumber.ts +0 -0
  29. package/src/api/variant.ts +0 -173
  30. package/src/http.ts +0 -363
  31. package/src/index.ts +0 -29
  32. package/src/types/appConfiguration.ts +0 -12
  33. package/src/types/asset.ts +0 -9
  34. package/src/types/attestation.ts +0 -19
  35. package/src/types/batch.ts +0 -15
  36. package/src/types/collection.ts +0 -68
  37. package/src/types/error.ts +0 -10
  38. package/src/types/index.ts +0 -11
  39. package/src/types/product.ts +0 -33
  40. package/src/types/proof.ts +0 -20
  41. package/src/types/serialNumber.ts +0 -0
  42. package/src/types/variant.ts +0 -15
  43. package/tsconfig.json +0 -15
  44. package/typedoc.json +0 -18
package/README.md ADDED
@@ -0,0 +1,430 @@
1
+ # Smartlinks SDK
2
+
3
+ Official JavaScript/TypeScript SDK for the Smartlinks API - enabling digital product authentication, traceability, and engagement.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @proveanything/smartlinks
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { initializeApi, auth, collection, product } from '@proveanything/smartlinks'
15
+
16
+ // Initialize the SDK
17
+ initializeApi({
18
+ baseURL: 'https://smartlinks.app/api/v1'
19
+ })
20
+
21
+ // Login
22
+ const loginResponse = await auth.login('email@example.com', 'password')
23
+
24
+ // Get collections
25
+ const collections = await collection.list(true) // admin endpoint
26
+
27
+ // Get products in a collection
28
+ const products = await product.list('collection-id', true)
29
+
30
+ // Get a specific product
31
+ const productDetail = await product.get('collection-id', 'product-id')
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ ### Basic Setup
37
+
38
+ ```typescript
39
+ import { initializeApi } from '@proveanything/smartlinks'
40
+
41
+ // Initialize with base URL
42
+ initializeApi({
43
+ baseURL: 'https://smartlinks.app/api/v1'
44
+ })
45
+
46
+ // Or with API key for server-side usage
47
+ initializeApi({
48
+ baseURL: 'https://smartlinks.app/api/v1',
49
+ apiKey: 'your-api-key'
50
+ })
51
+
52
+ // For iframe/embedded usage
53
+ initializeApi({
54
+ baseURL: 'https://smartlinks.app/api/v1',
55
+ proxyMode: true
56
+ })
57
+ ```
58
+
59
+ ### Runtime Token Management
60
+
61
+ ```typescript
62
+ import { setBearerToken } from '@proveanything/smartlinks'
63
+
64
+ // Set token after login
65
+ setBearerToken('your-bearer-token')
66
+
67
+ // Clear token on logout
68
+ setBearerToken(undefined)
69
+ ```
70
+
71
+ ## Authentication
72
+
73
+ ```typescript
74
+ import { auth } from '@proveanything/smartlinks'
75
+
76
+ // Login with email/password
77
+ const response = await auth.login('user@example.com', 'password')
78
+ console.log(response.bearerToken) // Token is automatically set for future calls
79
+
80
+ // Verify current token
81
+ const userInfo = await auth.verifyToken()
82
+
83
+ // Get account information
84
+ const account = await auth.getAccount()
85
+
86
+ // Logout (clears token)
87
+ auth.logout()
88
+ ```
89
+
90
+ ## Working with Collections
91
+
92
+ Collections are the top-level containers for organizing products.
93
+
94
+ ```typescript
95
+ import { collection } from '@proveanything/smartlinks'
96
+
97
+ // Get all collections (public)
98
+ const publicCollections = await collection.list(false)
99
+
100
+ // Get all collections (admin - requires authentication)
101
+ const adminCollections = await collection.list(true)
102
+
103
+ // Get specific collection
104
+ const col = await collection.get('collection-id', true)
105
+
106
+ // Create collection (admin only)
107
+ const newCollection = await collection.create({
108
+ title: 'New Collection',
109
+ description: 'Collection description'
110
+ })
111
+
112
+ // Update collection (admin only)
113
+ await collection.update('collection-id', {
114
+ title: 'Updated Title'
115
+ })
116
+
117
+ // Delete collection (admin only)
118
+ await collection.remove('collection-id')
119
+ ```
120
+
121
+ ### Serial Number Management
122
+
123
+ ```typescript
124
+ // Get serial numbers for a collection
125
+ const serialNumbers = await collection.getSN('collection-id', 0, 10)
126
+
127
+ // Look up a specific serial number
128
+ const lookupResult = await collection.lookupSN('collection-id', 'serial-code')
129
+
130
+ // Assign a value to a serial number
131
+ await collection.assignSN('collection-id', 'serial-code', 'assigned-value')
132
+ ```
133
+
134
+ ## Working with Products
135
+
136
+ Products represent individual items within collections.
137
+
138
+ ```typescript
139
+ import { product } from '@proveanything/smartlinks'
140
+
141
+ // List products in collection (public)
142
+ const publicProducts = await product.list('collection-id', false)
143
+
144
+ // List products in collection (admin)
145
+ const adminProducts = await product.list('collection-id', true)
146
+
147
+ // Get specific product
148
+ const prod = await product.get('collection-id', 'product-id')
149
+
150
+ // Create product (admin only)
151
+ const newProduct = await product.create('collection-id', {
152
+ name: 'New Product',
153
+ description: 'Product description',
154
+ data: {
155
+ custom: 'properties'
156
+ }
157
+ })
158
+
159
+ // Update product (admin only)
160
+ await product.update('collection-id', 'product-id', {
161
+ name: 'Updated Name'
162
+ })
163
+
164
+ // Delete product (admin only)
165
+ await product.remove('collection-id', 'product-id')
166
+ ```
167
+
168
+ ### Product Serial Numbers
169
+
170
+ ```typescript
171
+ // Get serial numbers for a product
172
+ const serialNumbers = await product.getSN('collection-id', 'product-id', 0, 10)
173
+
174
+ // Look up a serial number for a product
175
+ const lookupResult = await product.lookupSN('collection-id', 'product-id', 'serial-code')
176
+ ```
177
+
178
+ ## Variants and Batches
179
+
180
+ Manage product variants and production batches:
181
+
182
+ ```typescript
183
+ import { variant, batch } from '@proveanything/smartlinks'
184
+
185
+ // Work with variants
186
+ const variants = await variant.list('collection-id', 'product-id')
187
+ const newVariant = await variant.create('collection-id', 'product-id', {
188
+ name: 'Size Large',
189
+ properties: { size: 'L', color: 'blue' }
190
+ })
191
+
192
+ // Work with batches
193
+ const batches = await batch.list('collection-id', 'product-id')
194
+ const newBatch = await batch.create('collection-id', 'product-id', {
195
+ name: 'Batch 001',
196
+ quantity: 100
197
+ })
198
+
199
+ // Serial numbers for variants/batches
200
+ const variantSerials = await variant.getSN('collection-id', 'product-id', 'variant-id')
201
+ const batchSerials = await batch.getSN('collection-id', 'product-id', 'batch-id')
202
+ ```
203
+
204
+ ## Asset Management
205
+
206
+ Upload and manage files associated with collections, products, and proofs:
207
+
208
+ ```typescript
209
+ import { asset } from '@proveanything/smartlinks'
210
+
211
+ // Upload asset to a proof
212
+ const file = document.getElementById('fileInput').files[0]
213
+ const uploadResult = await asset.uploadAsset(
214
+ 'collection-id',
215
+ 'product-id',
216
+ 'proof-id',
217
+ file,
218
+ { description: 'Product image' }, // Optional extra data
219
+ (percent) => console.log(`Upload: ${percent}%`) // Progress callback
220
+ )
221
+
222
+ // Get asset information
223
+ const assetInfo = await asset.getForProof('collection-id', 'product-id', 'proof-id', 'asset-id')
224
+
225
+ // List all assets for a proof
226
+ const proofAssets = await asset.listForProof('collection-id', 'product-id', 'proof-id')
227
+ ```
228
+
229
+ ## Attestations and Claims
230
+
231
+ Manage digital attestations and claim verification:
232
+
233
+ ```typescript
234
+ import { attestation, claimSet } from '@proveanything/smartlinks'
235
+
236
+ // Work with attestations
237
+ const attestations = await attestation.list('collection-id', 'product-id', 'proof-id')
238
+ const newAttestation = await attestation.create('collection-id', 'product-id', 'proof-id', {
239
+ public: { verified: true },
240
+ private: { inspector: 'John Doe' },
241
+ proof: { signature: 'abc123' }
242
+ })
243
+
244
+ // Work with claim sets
245
+ const claimSets = await claimSet.getAllForCollection('collection-id')
246
+ const claimResult = await claimSet.makeClaim('collection-id', {
247
+ productId: 'product-id',
248
+ claimType: 'ownership'
249
+ })
250
+ ```
251
+
252
+ ## Proofs
253
+
254
+ Retrieve and validate product proofs:
255
+
256
+ ```typescript
257
+ import { proof } from '@proveanything/smartlinks'
258
+
259
+ // Get all proofs for a collection
260
+ const proofs = await proof.list('collection-id')
261
+
262
+ // Get specific proof
263
+ const proofDetail = await proof.get('collection-id', 'proof-id')
264
+ ```
265
+
266
+ ## Forms
267
+
268
+ Dynamic form creation and management:
269
+
270
+ ```typescript
271
+ import { form } from '@proveanything/smartlinks'
272
+
273
+ // List forms (public)
274
+ const publicForms = await form.list('collection-id', false)
275
+
276
+ // List forms (admin)
277
+ const adminForms = await form.list('collection-id', true)
278
+
279
+ // Create form (admin only)
280
+ const newForm = await form.create('collection-id', {
281
+ name: 'Product Registration',
282
+ fields: [
283
+ { name: 'email', type: 'email', required: true },
284
+ { name: 'name', type: 'text', required: true }
285
+ ]
286
+ })
287
+ ```
288
+
289
+ ## Advanced Usage
290
+
291
+ ### Proxy Mode (iframe Communication)
292
+
293
+ When running in an iframe, use proxy mode to communicate with the parent window:
294
+
295
+ ```typescript
296
+ import { initializeApi, sendCustomProxyMessage } from '@proveanything/smartlinks'
297
+
298
+ // Initialize in proxy mode
299
+ initializeApi({
300
+ baseURL: 'https://smartlinks.app/api/v1',
301
+ proxyMode: true
302
+ })
303
+
304
+ // Send custom messages to parent window
305
+ const response = await sendCustomProxyMessage('custom-action', {
306
+ data: 'any-data'
307
+ })
308
+ ```
309
+
310
+ ### Custom Configuration
311
+
312
+ ```typescript
313
+ import { appConfiguration } from '@proveanything/smartlinks'
314
+
315
+ // Get configuration
316
+ const config = await appConfiguration.getConfig({ key: 'setting-name' })
317
+
318
+ // Set configuration
319
+ await appConfiguration.setConfig({
320
+ key: 'setting-name',
321
+ value: 'setting-value'
322
+ })
323
+
324
+ // Work with configuration data
325
+ const data = await appConfiguration.getData({ category: 'user-preferences' })
326
+ ```
327
+
328
+ ## Error Handling
329
+
330
+ ```typescript
331
+ import { ErrorResponse } from '@proveanything/smartlinks'
332
+
333
+ try {
334
+ const result = await product.get('collection-id', 'product-id')
335
+ } catch (error) {
336
+ if (error instanceof ErrorResponse) {
337
+ console.error('API Error:', error.message)
338
+ console.error('Status Code:', error.code)
339
+ } else {
340
+ console.error('Unexpected error:', error)
341
+ }
342
+ }
343
+ ```
344
+
345
+ ## TypeScript Support
346
+
347
+ The SDK is written in TypeScript and includes full type definitions:
348
+
349
+ ```typescript
350
+ import {
351
+ ProductResponse,
352
+ CollectionResponse,
353
+ AttestationCreateRequest
354
+ } from '@proveanything/smartlinks'
355
+
356
+ const product: ProductResponse = await product.get('col-id', 'prod-id')
357
+ const collection: CollectionResponse = await collection.get('col-id')
358
+
359
+ const attestationData: AttestationCreateRequest = {
360
+ public: { verified: true },
361
+ private: { notes: 'Internal notes' },
362
+ proof: { signature: 'digital-signature' }
363
+ }
364
+ ```
365
+
366
+ ## Admin vs Public Endpoints
367
+
368
+ Many functions support both admin and public access modes:
369
+
370
+ ```typescript
371
+ // Public access (limited data, no authentication required)
372
+ const publicCollections = await collection.list(false)
373
+ const publicProducts = await product.list('collection-id', false)
374
+
375
+ // Admin access (full data + management capabilities, authentication required)
376
+ const adminCollections = await collection.list(true)
377
+ const adminProducts = await product.list('collection-id', true)
378
+
379
+ // Create/Update/Delete operations are admin-only
380
+ await collection.create(data) // Requires authentication
381
+ await product.update('col-id', 'prod-id', data) // Requires authentication
382
+ ```
383
+
384
+ ## Browser vs Node.js
385
+
386
+ The SDK works in both browser and Node.js environments:
387
+
388
+ ### Browser Usage
389
+
390
+ ```html
391
+ <script type="module">
392
+ import { initializeApi, auth } from '@proveanything/smartlinks'
393
+
394
+ initializeApi({ baseURL: 'https://smartlinks.app/api/v1' })
395
+ // Use the SDK...
396
+ </script>
397
+ ```
398
+
399
+ ### Node.js Usage
400
+
401
+ ```javascript
402
+ const { initializeApi, auth } = require('@proveanything/smartlinks')
403
+
404
+ initializeApi({
405
+ baseURL: 'https://smartlinks.app/api/v1',
406
+ apiKey: process.env.SMARTLINKS_API_KEY
407
+ })
408
+ ```
409
+
410
+ ## Examples
411
+
412
+ Check out the [examples](./examples/) directory for complete implementation examples:
413
+
414
+ - [Node.js Demo](./examples/node-demo.ts) - Server-side usage examples
415
+ - [Browser Demo](./examples/browser-demo.html) - Frontend integration examples
416
+ - [React Demo](./examples/react-demo.tsx) - React component examples
417
+
418
+ ## API Reference
419
+
420
+ For complete API documentation including all functions and types, see [API_SUMMARY.md](./API_SUMMARY.md).
421
+
422
+ ## Support
423
+
424
+ - **Documentation**: [API Reference](./API_SUMMARY.md)
425
+ - **Issues**: [GitHub Issues](https://github.com/Prove-Anything/smartlinks/issues)
426
+ - **Website**: [smartlinks.app](https://smartlinks.app)
427
+
428
+ ## License
429
+
430
+ MIT License - see [LICENSE](./LICENSE) for details.
@@ -99,7 +99,7 @@ export var collection;
99
99
  * @throws ErrorResponse if the request fails
100
100
  */
101
101
  async function assignSN(collectionId, codeId, value) {
102
- const path = `/admin/collection/${encodeURIComponent(collectionId)}/lookupSN/${encodeURIComponent(codeId)}`;
102
+ const path = `/admin/collection/${encodeURIComponent(collectionId)}/assignSN/${encodeURIComponent(codeId)}`;
103
103
  return post(path, { value });
104
104
  }
105
105
  collection.assignSN = assignSN;
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.28",
3
+ "version": "1.0.30",
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();