@proveanything/smartlinks 1.0.3 → 1.0.4
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/README.md +109 -59
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @proveanything/smartlinks
|
|
2
2
|
|
|
3
|
-
An official JavaScript/TypeScript client SDK for the Smartlinks API. This package provides
|
|
3
|
+
An official JavaScript/TypeScript client SDK for the Smartlinks API. This package provides simple, namespaced functions to fetch Collection, Product, Proof, and App Configuration data in both browser and Node.js environments.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -13,20 +13,38 @@ yarn add @proveanything/smartlinks
|
|
|
13
13
|
## Quickstart
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
initializeApi,
|
|
18
|
+
collection,
|
|
19
|
+
product,
|
|
20
|
+
proof,
|
|
21
|
+
appConfiguration,
|
|
22
|
+
} from "@proveanything/smartlinks";
|
|
17
23
|
|
|
18
24
|
async function main() {
|
|
19
|
-
//
|
|
20
|
-
|
|
25
|
+
// Initialize once (provide base URL and optional API key/bearer token)
|
|
26
|
+
initializeApi({
|
|
27
|
+
baseURL: "https://smartlinks.app/api/v1",
|
|
28
|
+
apiKey: "YOUR_API_KEY_HERE", // optional
|
|
29
|
+
bearerToken: "YOUR_BEARER_TOKEN", // optional
|
|
30
|
+
});
|
|
21
31
|
|
|
22
32
|
try {
|
|
23
33
|
// Fetch a collection by ID
|
|
24
|
-
const
|
|
25
|
-
console.log("Collection:",
|
|
34
|
+
const coll = await collection.get("abc123");
|
|
35
|
+
console.log("Collection:", coll);
|
|
26
36
|
|
|
27
37
|
// Fetch a product item by collection ID & product ID
|
|
28
|
-
const
|
|
29
|
-
console.log("Product Item:",
|
|
38
|
+
const prod = await product.get("abc123", "prod789");
|
|
39
|
+
console.log("Product Item:", prod);
|
|
40
|
+
|
|
41
|
+
// Fetch a proof by collection ID & proof ID
|
|
42
|
+
const prf = await proof.get("abc123", "proof456");
|
|
43
|
+
console.log("Proof:", prf);
|
|
44
|
+
|
|
45
|
+
// Fetch an app configuration by collection ID & app ID
|
|
46
|
+
const cfg = await appConfiguration.get("abc123", "app789");
|
|
47
|
+
console.log("App Configuration:", cfg);
|
|
30
48
|
} catch (err) {
|
|
31
49
|
console.error("Error fetching data:", err);
|
|
32
50
|
}
|
|
@@ -37,19 +55,24 @@ main();
|
|
|
37
55
|
|
|
38
56
|
## API Reference
|
|
39
57
|
|
|
40
|
-
###
|
|
58
|
+
### Initialization
|
|
41
59
|
|
|
42
60
|
```ts
|
|
43
|
-
|
|
61
|
+
initializeApi(options: { baseURL: string; apiKey?: string; bearerToken?: string }): void
|
|
44
62
|
```
|
|
45
63
|
|
|
46
64
|
- **Parameters:**
|
|
47
|
-
- `baseURL` (`string`, required): The root URL of the Smartlinks API, e.g. `https://smartlinks.app/api/v1`.
|
|
48
|
-
- `apiKey`
|
|
65
|
+
- `baseURL` (`string`, required): The root URL of the Smartlinks API, e.g. `https://smartlinks.app/api/v1`.
|
|
66
|
+
- `apiKey` (`string`, optional): Your API key for the `X-API-Key` header.
|
|
67
|
+
- `bearerToken` (`string`, optional): Your Bearer token for the `AUTHORIZATION` header.
|
|
68
|
+
|
|
69
|
+
All subsequent calls to the API functions will use these settings.
|
|
49
70
|
|
|
50
71
|
---
|
|
51
72
|
|
|
52
|
-
|
|
73
|
+
### Namespace: `collection`
|
|
74
|
+
|
|
75
|
+
#### `collection.get(collectionId: string): Promise<CollectionResponse>`
|
|
53
76
|
|
|
54
77
|
Fetches a single collection by its ID.
|
|
55
78
|
|
|
@@ -69,20 +92,21 @@ Fetches a single collection by its ID.
|
|
|
69
92
|
|
|
70
93
|
- **Example:**
|
|
71
94
|
```ts
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
console.log("Fetched collection:", collection);
|
|
95
|
+
const coll = await collection.get("abc123");
|
|
96
|
+
console.log("Fetched collection:", coll.title);
|
|
75
97
|
```
|
|
76
98
|
|
|
77
99
|
---
|
|
78
100
|
|
|
79
|
-
|
|
101
|
+
### Namespace: `product`
|
|
102
|
+
|
|
103
|
+
#### `product.get(collectionId: string, productId: string): Promise<ProductResponse>`
|
|
80
104
|
|
|
81
105
|
Fetches a single product item within a collection.
|
|
82
106
|
|
|
83
107
|
- **Parameters:**
|
|
84
108
|
- `collectionId` (`string`, required): The parent collection’s ID.
|
|
85
|
-
- `productId`
|
|
109
|
+
- `productId` (`string`, required): The product item’s ID.
|
|
86
110
|
- **Returns:**
|
|
87
111
|
A `Promise` that resolves to a `ProductResponse` object:
|
|
88
112
|
|
|
@@ -97,93 +121,119 @@ Fetches a single product item within a collection.
|
|
|
97
121
|
|
|
98
122
|
- **Example:**
|
|
99
123
|
```ts
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
console.log("Fetched product:", product);
|
|
124
|
+
const prod = await product.get("abc123", "prod789");
|
|
125
|
+
console.log("Fetched product:", prod.name);
|
|
103
126
|
```
|
|
104
127
|
|
|
105
128
|
---
|
|
106
129
|
|
|
107
|
-
|
|
130
|
+
### Namespace: `proof`
|
|
108
131
|
|
|
109
|
-
|
|
132
|
+
#### `proof.get(collectionId: string, proofId: string): Promise<ProofResponse>`
|
|
133
|
+
|
|
134
|
+
Fetches a single proof by collection ID and proof ID.
|
|
110
135
|
|
|
111
136
|
- **Parameters:**
|
|
112
137
|
- `collectionId` (`string`, required): The parent collection’s ID.
|
|
113
|
-
- `
|
|
138
|
+
- `proofId` (`string`, required): The proof’s ID.
|
|
114
139
|
- **Returns:**
|
|
115
|
-
A `Promise` that resolves to
|
|
140
|
+
A `Promise` that resolves to a `ProofResponse` object:
|
|
116
141
|
|
|
117
142
|
```ts
|
|
118
|
-
export interface
|
|
143
|
+
export interface ProofResponse {
|
|
144
|
+
collectionId: string;
|
|
145
|
+
createdAt: string;
|
|
119
146
|
id: string;
|
|
120
|
-
|
|
121
|
-
|
|
147
|
+
productId: string;
|
|
148
|
+
tokenId: string;
|
|
149
|
+
userId: string;
|
|
150
|
+
values: Record<string, any>;
|
|
122
151
|
}
|
|
123
152
|
```
|
|
124
153
|
|
|
125
154
|
- **Example:**
|
|
126
155
|
```ts
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
console.log("Fetched app configuration:", config);
|
|
156
|
+
const prf = await proof.get("abc123", "proof456");
|
|
157
|
+
console.log("Fetched proof:", prf.id);
|
|
130
158
|
```
|
|
131
159
|
|
|
132
160
|
---
|
|
133
161
|
|
|
134
|
-
|
|
162
|
+
### Namespace: `appConfiguration`
|
|
135
163
|
|
|
136
|
-
|
|
164
|
+
#### `appConfiguration.get(collectionId: string, appId: string): Promise<AppConfigurationResponse>`
|
|
137
165
|
|
|
138
|
-
|
|
139
|
-
import { ApiClient } from "@proveanything/smartlinks";
|
|
166
|
+
Fetches a single app configuration by collection ID and app ID.
|
|
140
167
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
168
|
+
- **Parameters:**
|
|
169
|
+
- `collectionId` (`string`, required): The parent collection’s ID.
|
|
170
|
+
- `appId` (`string`, required): The app configuration’s ID.
|
|
171
|
+
- **Returns:**
|
|
172
|
+
A `Promise` that resolves to an `AppConfigurationResponse` object:
|
|
144
173
|
|
|
145
|
-
|
|
174
|
+
```ts
|
|
175
|
+
export interface AppConfigurationResponse {
|
|
176
|
+
id: string;
|
|
177
|
+
name: string;
|
|
178
|
+
settings?: Record<string, any>;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- **Example:**
|
|
183
|
+
```ts
|
|
184
|
+
const cfg = await appConfiguration.get("abc123", "app789");
|
|
185
|
+
console.log("Fetched app configuration:", cfg.name);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
146
189
|
|
|
147
190
|
## Error Handling
|
|
148
191
|
|
|
149
|
-
All methods throw an `Error` when the server responds with a non-2xx status. The thrown error message
|
|
192
|
+
All methods throw an `Error` when the server responds with a non-2xx status. The thrown error message will include the numeric error code and message from the API. Example:
|
|
150
193
|
|
|
151
194
|
```ts
|
|
152
|
-
import {
|
|
153
|
-
|
|
154
|
-
async function fetchData() {
|
|
155
|
-
const client = new ApiClient("https://smartlinks.app/api/v1", "INVALID_KEY");
|
|
195
|
+
import { product } from "@proveanything/smartlinks";
|
|
156
196
|
|
|
197
|
+
async function fetchProduct() {
|
|
157
198
|
try {
|
|
158
|
-
await
|
|
199
|
+
await product.get("abc123", "invalidProdId");
|
|
159
200
|
} catch (err) {
|
|
160
|
-
// err.message might be: "Error
|
|
201
|
+
// err.message might be: "Error 404: Not Found"
|
|
161
202
|
console.error("Request failed:", err);
|
|
162
203
|
}
|
|
163
204
|
}
|
|
164
205
|
|
|
165
|
-
|
|
206
|
+
fetchProduct();
|
|
166
207
|
```
|
|
167
208
|
|
|
168
|
-
|
|
209
|
+
---
|
|
169
210
|
|
|
170
|
-
|
|
211
|
+
## Types
|
|
171
212
|
|
|
172
|
-
|
|
173
|
-
- [`examples/browser-demo.html`](examples/browser-demo.html)
|
|
174
|
-
- [`examples/react-demo.tsx`](examples/react-demo.tsx)
|
|
213
|
+
You can import any of the response interfaces directly:
|
|
175
214
|
|
|
176
|
-
|
|
215
|
+
```ts
|
|
216
|
+
import {
|
|
217
|
+
CollectionResponse,
|
|
218
|
+
ProductResponse,
|
|
219
|
+
ProofResponse,
|
|
220
|
+
AppConfigurationResponse,
|
|
221
|
+
} from "@proveanything/smartlinks/types";
|
|
222
|
+
```
|
|
177
223
|
|
|
178
|
-
|
|
179
|
-
You can find the full API contract in [`openapi.yaml`](openapi.yaml) at the root of this package.
|
|
224
|
+
---
|
|
180
225
|
|
|
181
226
|
## Changelog
|
|
182
227
|
|
|
183
228
|
### 1.0.0
|
|
184
229
|
|
|
185
|
-
- Initial release:
|
|
186
|
-
- `
|
|
187
|
-
-
|
|
188
|
-
|
|
230
|
+
- Initial release:
|
|
231
|
+
- `initializeApi` function to configure baseURL and auth.
|
|
232
|
+
- Namespaced modules:
|
|
233
|
+
- `collection.get(collectionId)`
|
|
234
|
+
- `product.get(collectionId, productId)`
|
|
235
|
+
- `proof.get(collectionId, proofId)`
|
|
236
|
+
- `appConfiguration.get(collectionId, appId)`
|
|
237
|
+
- Full TypeScript typings and JSDoc.
|
|
238
|
+
- Browser/Node fetch support via `cross-fetch`.
|
|
189
239
|
- Error handling via thrown `Error` objects.
|