@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.
Files changed (2) hide show
  1. package/README.md +109 -59
  2. 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 a simple wrapper around the Smartlinks REST endpoints, allowing you to fetch Collection, Product, and App Configuration data in both browser and Node.js environments.
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 { ApiClient, CollectionResponse, ProductResponse } from "@proveanything/smartlinks";
16
+ import {
17
+ initializeApi,
18
+ collection,
19
+ product,
20
+ proof,
21
+ appConfiguration,
22
+ } from "@proveanything/smartlinks";
17
23
 
18
24
  async function main() {
19
- // Instantiate the client (no apiKey needed for public endpoints, but shown here for reference)
20
- const client = new ApiClient("https://smartlinks.app/api/v1", "YOUR_API_KEY_HERE");
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 collection: CollectionResponse = await client.getCollection("abc123");
25
- console.log("Collection:", 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 product: ProductResponse = await client.getProductItem("abc123", "prod789");
29
- console.log("Product Item:", product);
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
- ### Class: `ApiClient`
58
+ ### Initialization
41
59
 
42
60
  ```ts
43
- constructor(baseURL: string, apiKey?: string)
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` (`string`, optional): Your Bearer token. If omitted, requests will be sent without an `Authorization` header.
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
- #### `getCollection(collectionId: string): Promise<CollectionResponse>`
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 client = new ApiClient("https://smartlinks.app/api/v1", "YOUR_API_KEY");
73
- const collection = await client.getCollection("abc123");
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
- #### `getProductItem(collectionId: string, productId: string): Promise<ProductResponse>`
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` (`string`, required): The product item’s ID.
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 client = new ApiClient("https://smartlinks.app/api/v1", "YOUR_API_KEY");
101
- const product = await client.getProductItem("abc123", "prod789");
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
- #### `getAppConfiguration(collectionId: string, appId: string): Promise<AppConfigurationResponse>`
130
+ ### Namespace: `proof`
108
131
 
109
- Fetches a single app configuration within a collection.
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
- - `appId` (`string`, required): The app configuration’s ID.
138
+ - `proofId` (`string`, required): The proof’s ID.
114
139
  - **Returns:**
115
- A `Promise` that resolves to an `AppConfigurationResponse` object:
140
+ A `Promise` that resolves to a `ProofResponse` object:
116
141
 
117
142
  ```ts
118
- export interface AppConfigurationResponse {
143
+ export interface ProofResponse {
144
+ collectionId: string;
145
+ createdAt: string;
119
146
  id: string;
120
- name: string;
121
- settings?: Record<string, any>;
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 client = new ApiClient("https://smartlinks.app/api/v1", "YOUR_API_KEY");
128
- const config = await client.getAppConfiguration("abc123", "app456");
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
- ## Authentication
162
+ ### Namespace: `appConfiguration`
135
163
 
136
- All endpoints require a Bearer token passed in the `AUTHORIZATION` header. When instantiating `ApiClient`, optionally supply your token:
164
+ #### `appConfiguration.get(collectionId: string, appId: string): Promise<AppConfigurationResponse>`
137
165
 
138
- ```ts
139
- import { ApiClient } from "@proveanything/smartlinks";
166
+ Fetches a single app configuration by collection ID and app ID.
140
167
 
141
- const apiKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
142
- const client = new ApiClient("https://smartlinks.app/api/v1", apiKey);
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
- If `apiKey` is omitted, requests will be sent without an `Authorization` header, which may cause a `401 Unauthorized` for protected endpoints.
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 includes the numeric error code and message from the API. Example:
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 { ApiClient } from "@proveanything/smartlinks";
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 client.getCollection("nonexistent");
199
+ await product.get("abc123", "invalidProdId");
159
200
  } catch (err) {
160
- // err.message might be: "Error 401: Unauthorized" or "Error 404: Not Found"
201
+ // err.message might be: "Error 404: Not Found"
161
202
  console.error("Request failed:", err);
162
203
  }
163
204
  }
164
205
 
165
- fetchData();
206
+ fetchProduct();
166
207
  ```
167
208
 
168
- ## Examples
209
+ ---
169
210
 
170
- See the **examples/** folder for complete, runnable samples:
211
+ ## Types
171
212
 
172
- - [`examples/node-demo.ts`](examples/node-demo.ts)
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
- ## OpenAPI Specification
215
+ ```ts
216
+ import {
217
+ CollectionResponse,
218
+ ProductResponse,
219
+ ProofResponse,
220
+ AppConfigurationResponse,
221
+ } from "@proveanything/smartlinks/types";
222
+ ```
177
223
 
178
- This SDK is generated and maintained according to the [Smartlinks OpenAPI 3.0 specification](openapi.yaml).
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
- - `ApiClient` class with `getCollection`, `getProductItem`, and `getAppConfiguration` methods.
187
- - Full TypeScript typings and JSDoc.
188
- - Browser/Node fetch support.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",