@proveanything/smartlinks 1.3.34 → 1.3.37

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.
@@ -1,24 +1,301 @@
1
1
  import { CollectionWidgetsResponse, GetCollectionWidgetsOptions } from "../types/appManifest";
2
+ /**
3
+ * Options for collection/product-scoped app configuration.
4
+ * This data is set by admins and applies to all users within the scope.
5
+ */
2
6
  export type AppConfigOptions = {
7
+ /** The app ID */
3
8
  appId: string;
9
+ /** Collection ID (required for most operations) */
4
10
  collectionId?: string;
11
+ /** Product ID (optional - for product-scoped config) */
5
12
  productId?: string;
13
+ /** Variant ID (optional - for variant-scoped config) */
6
14
  variantId?: string;
15
+ /** Batch ID (optional - for batch-scoped config) */
7
16
  batchId?: string;
17
+ /** Item ID - required for getDataItem/deleteDataItem */
8
18
  itemId?: string;
9
- user?: boolean;
10
- userData?: boolean;
19
+ /** Use admin endpoints instead of public */
11
20
  admin?: boolean;
21
+ /** Configuration object for setConfig */
12
22
  config?: any;
23
+ /** Data object for setDataItem */
13
24
  data?: any;
14
25
  };
26
+ /**
27
+ * User-specific app data storage.
28
+ * This data is global per user+app and shared across all collections.
29
+ * Perfect for personal preferences, settings, and user-generated content.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * // Store user's garden bed layout
34
+ * await userAppData.set('garden-planner', {
35
+ * id: 'bed-1',
36
+ * name: 'Vegetable Bed',
37
+ * plants: ['tomatoes', 'peppers']
38
+ * });
39
+ *
40
+ * // Get all user's data for this app
41
+ * const beds = await userAppData.list('garden-planner');
42
+ *
43
+ * // Get specific item
44
+ * const bed = await userAppData.get('garden-planner', 'bed-1');
45
+ *
46
+ * // Remove item
47
+ * await userAppData.remove('garden-planner', 'bed-1');
48
+ * ```
49
+ */
50
+ export declare namespace userAppData {
51
+ /**
52
+ * Get user's config blob for an app.
53
+ * This is a single JSON object stored per user+app.
54
+ *
55
+ * @param appId - The app ID
56
+ * @returns The user's config object
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const config = await userAppData.getConfig('allergy-tracker');
61
+ * // Returns: { allergies: ['peanuts'], notifications: true }
62
+ * ```
63
+ */
64
+ function getConfig(appId: string): Promise<any>;
65
+ /**
66
+ * Set user's config blob for an app.
67
+ *
68
+ * @param appId - The app ID
69
+ * @param config - The config object to store
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * await userAppData.setConfig('allergy-tracker', {
74
+ * allergies: ['peanuts', 'shellfish'],
75
+ * notifications: true
76
+ * });
77
+ * ```
78
+ */
79
+ function setConfig(appId: string, config: any): Promise<any>;
80
+ /**
81
+ * Delete user's config blob for an app.
82
+ *
83
+ * @param appId - The app ID
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * await userAppData.deleteConfig('allergy-tracker');
88
+ * ```
89
+ */
90
+ function deleteConfig(appId: string): Promise<void>;
91
+ /**
92
+ * List all user's data items for an app.
93
+ * Returns an array of objects, each with an `id` field.
94
+ *
95
+ * @param appId - The app ID
96
+ * @returns Array of data items
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const beds = await userAppData.list('garden-planner');
101
+ * // Returns: [{ id: 'bed-1', name: 'Vegetables', ... }, { id: 'bed-2', ... }]
102
+ * ```
103
+ */
104
+ function list(appId: string): Promise<any[]>;
105
+ /**
106
+ * Get a specific user data item by ID.
107
+ *
108
+ * @param appId - The app ID
109
+ * @param itemId - The item ID
110
+ * @returns The data item
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const bed = await userAppData.get('garden-planner', 'bed-1');
115
+ * // Returns: { id: 'bed-1', name: 'Vegetable Bed', plants: [...] }
116
+ * ```
117
+ */
118
+ function get(appId: string, itemId: string): Promise<any>;
119
+ /**
120
+ * Create or update a user data item.
121
+ * The item object must include an `id` field.
122
+ *
123
+ * @param appId - The app ID
124
+ * @param item - The data item (must include `id`)
125
+ * @returns The saved item
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * await userAppData.set('garden-planner', {
130
+ * id: 'bed-1',
131
+ * name: 'Vegetable Bed',
132
+ * plants: ['tomatoes', 'peppers'],
133
+ * location: { x: 10, y: 20 }
134
+ * });
135
+ * ```
136
+ */
137
+ function set(appId: string, item: any): Promise<any>;
138
+ /**
139
+ * Delete a user data item by ID.
140
+ *
141
+ * @param appId - The app ID
142
+ * @param itemId - The item ID to delete
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * await userAppData.remove('garden-planner', 'bed-1');
147
+ * ```
148
+ */
149
+ function remove(appId: string, itemId: string): Promise<void>;
150
+ }
151
+ /**
152
+ * Collection/Product-scoped app configuration.
153
+ * This is admin-managed configuration that applies to all users within the scope.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * // Get collection-level app config
158
+ * const config = await appConfiguration.getConfig({
159
+ * appId: 'warranty-portal',
160
+ * collectionId: 'my-collection'
161
+ * });
162
+ *
163
+ * // Set product-level config (admin only)
164
+ * await appConfiguration.setConfig({
165
+ * appId: 'warranty-portal',
166
+ * collectionId: 'my-collection',
167
+ * productId: 'product-123',
168
+ * admin: true,
169
+ * config: { warrantyPeriod: 24 }
170
+ * });
171
+ *
172
+ * // List product-level data items
173
+ * const items = await appConfiguration.getData({
174
+ * appId: 'product-docs',
175
+ * collectionId: 'my-collection',
176
+ * productId: 'product-123'
177
+ * });
178
+ * ```
179
+ */
15
180
  export declare namespace appConfiguration {
181
+ /**
182
+ * Get app configuration for a collection/product scope.
183
+ *
184
+ * @param opts - Configuration options including appId and scope (collectionId, productId, etc.)
185
+ * @returns The configuration object
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const config = await appConfiguration.getConfig({
190
+ * appId: 'warranty-portal',
191
+ * collectionId: 'my-collection'
192
+ * });
193
+ * ```
194
+ */
16
195
  function getConfig(opts: AppConfigOptions): Promise<any>;
196
+ /**
197
+ * Set app configuration for a collection/product scope.
198
+ * Requires admin authentication.
199
+ *
200
+ * @param opts - Configuration options including appId, scope, and config data
201
+ * @returns The saved configuration
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * await appConfiguration.setConfig({
206
+ * appId: 'warranty-portal',
207
+ * collectionId: 'my-collection',
208
+ * admin: true,
209
+ * config: { warrantyPeriod: 24, supportEmail: 'support@example.com' }
210
+ * });
211
+ * ```
212
+ */
17
213
  function setConfig(opts: AppConfigOptions): Promise<any>;
214
+ /**
215
+ * Delete app configuration for a collection/product scope.
216
+ * Requires admin authentication.
217
+ *
218
+ * @param opts - Configuration options including appId and scope
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * await appConfiguration.deleteConfig({
223
+ * appId: 'warranty-portal',
224
+ * collectionId: 'my-collection',
225
+ * admin: true
226
+ * });
227
+ * ```
228
+ */
18
229
  function deleteConfig(opts: AppConfigOptions): Promise<void>;
230
+ /**
231
+ * Get all data items for an app within a scope.
232
+ *
233
+ * @param opts - Options including appId and scope (collectionId, productId, etc.)
234
+ * @returns Array of data items
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * const items = await appConfiguration.getData({
239
+ * appId: 'product-docs',
240
+ * collectionId: 'my-collection',
241
+ * productId: 'product-123'
242
+ * });
243
+ * ```
244
+ */
19
245
  function getData(opts: AppConfigOptions): Promise<any[]>;
246
+ /**
247
+ * Get a single data item by ID within a scope.
248
+ *
249
+ * @param opts - Options including appId, scope, and itemId
250
+ * @returns The data item
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const item = await appConfiguration.getDataItem({
255
+ * appId: 'product-docs',
256
+ * collectionId: 'my-collection',
257
+ * productId: 'product-123',
258
+ * itemId: 'manual-1'
259
+ * });
260
+ * ```
261
+ */
20
262
  function getDataItem(opts: AppConfigOptions): Promise<any>;
263
+ /**
264
+ * Set/create a data item within a scope.
265
+ * Requires admin authentication.
266
+ *
267
+ * @param opts - Options including appId, scope, and data
268
+ * @returns The saved data item
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * await appConfiguration.setDataItem({
273
+ * appId: 'product-docs',
274
+ * collectionId: 'my-collection',
275
+ * productId: 'product-123',
276
+ * admin: true,
277
+ * data: { id: 'manual-1', title: 'User Manual', url: 'https://...' }
278
+ * });
279
+ * ```
280
+ */
21
281
  function setDataItem(opts: AppConfigOptions): Promise<any>;
282
+ /**
283
+ * Delete a data item by ID within a scope.
284
+ * Requires admin authentication.
285
+ *
286
+ * @param opts - Options including appId, scope, and itemId
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * await appConfiguration.deleteDataItem({
291
+ * appId: 'product-docs',
292
+ * collectionId: 'my-collection',
293
+ * productId: 'product-123',
294
+ * admin: true,
295
+ * itemId: 'manual-1'
296
+ * });
297
+ * ```
298
+ */
22
299
  function deleteDataItem(opts: AppConfigOptions): Promise<void>;
23
300
  /**
24
301
  * Fetches ALL widget data (manifests + bundle files) for a collection in one call.
@@ -1,22 +1,6 @@
1
1
  // src/api/appConfiguration.ts
2
2
  import { request, post, del } from "../http";
3
3
  function buildAppPath(opts, type) {
4
- if (opts.user) {
5
- // /public/auth/app/:appId
6
- let path = `/public/auth/app/${encodeURIComponent(opts.appId)}`;
7
- if (type === "data")
8
- path += "/data";
9
- if (type === "dataItem" && opts.itemId)
10
- path += `/data/${encodeURIComponent(opts.itemId)}`;
11
- return path;
12
- }
13
- if (opts.userData) {
14
- // /public/auth/app/:appId/data or /public/auth/app/:appId/data/:itemId
15
- let path = `/public/auth/app/${encodeURIComponent(opts.appId)}/data`;
16
- if (type === "dataItem" && opts.itemId)
17
- path += `/${encodeURIComponent(opts.itemId)}`;
18
- return path;
19
- }
20
4
  const base = opts.admin ? "admin" : "public";
21
5
  let path = `/${base}`;
22
6
  if (opts.collectionId) {
@@ -40,33 +24,288 @@ function buildAppPath(opts, type) {
40
24
  }
41
25
  return path;
42
26
  }
27
+ /**
28
+ * User-specific app data storage.
29
+ * This data is global per user+app and shared across all collections.
30
+ * Perfect for personal preferences, settings, and user-generated content.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Store user's garden bed layout
35
+ * await userAppData.set('garden-planner', {
36
+ * id: 'bed-1',
37
+ * name: 'Vegetable Bed',
38
+ * plants: ['tomatoes', 'peppers']
39
+ * });
40
+ *
41
+ * // Get all user's data for this app
42
+ * const beds = await userAppData.list('garden-planner');
43
+ *
44
+ * // Get specific item
45
+ * const bed = await userAppData.get('garden-planner', 'bed-1');
46
+ *
47
+ * // Remove item
48
+ * await userAppData.remove('garden-planner', 'bed-1');
49
+ * ```
50
+ */
51
+ export var userAppData;
52
+ (function (userAppData) {
53
+ /**
54
+ * Get user's config blob for an app.
55
+ * This is a single JSON object stored per user+app.
56
+ *
57
+ * @param appId - The app ID
58
+ * @returns The user's config object
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const config = await userAppData.getConfig('allergy-tracker');
63
+ * // Returns: { allergies: ['peanuts'], notifications: true }
64
+ * ```
65
+ */
66
+ async function getConfig(appId) {
67
+ const path = `/public/auth/app/${encodeURIComponent(appId)}`;
68
+ return request(path);
69
+ }
70
+ userAppData.getConfig = getConfig;
71
+ /**
72
+ * Set user's config blob for an app.
73
+ *
74
+ * @param appId - The app ID
75
+ * @param config - The config object to store
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * await userAppData.setConfig('allergy-tracker', {
80
+ * allergies: ['peanuts', 'shellfish'],
81
+ * notifications: true
82
+ * });
83
+ * ```
84
+ */
85
+ async function setConfig(appId, config) {
86
+ const path = `/public/auth/app/${encodeURIComponent(appId)}`;
87
+ return post(path, config);
88
+ }
89
+ userAppData.setConfig = setConfig;
90
+ /**
91
+ * Delete user's config blob for an app.
92
+ *
93
+ * @param appId - The app ID
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * await userAppData.deleteConfig('allergy-tracker');
98
+ * ```
99
+ */
100
+ async function deleteConfig(appId) {
101
+ const path = `/public/auth/app/${encodeURIComponent(appId)}`;
102
+ return del(path);
103
+ }
104
+ userAppData.deleteConfig = deleteConfig;
105
+ /**
106
+ * List all user's data items for an app.
107
+ * Returns an array of objects, each with an `id` field.
108
+ *
109
+ * @param appId - The app ID
110
+ * @returns Array of data items
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const beds = await userAppData.list('garden-planner');
115
+ * // Returns: [{ id: 'bed-1', name: 'Vegetables', ... }, { id: 'bed-2', ... }]
116
+ * ```
117
+ */
118
+ async function list(appId) {
119
+ const path = `/public/auth/app/${encodeURIComponent(appId)}/data`;
120
+ return request(path);
121
+ }
122
+ userAppData.list = list;
123
+ /**
124
+ * Get a specific user data item by ID.
125
+ *
126
+ * @param appId - The app ID
127
+ * @param itemId - The item ID
128
+ * @returns The data item
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const bed = await userAppData.get('garden-planner', 'bed-1');
133
+ * // Returns: { id: 'bed-1', name: 'Vegetable Bed', plants: [...] }
134
+ * ```
135
+ */
136
+ async function get(appId, itemId) {
137
+ const path = `/public/auth/app/${encodeURIComponent(appId)}/data/${encodeURIComponent(itemId)}`;
138
+ return request(path);
139
+ }
140
+ userAppData.get = get;
141
+ /**
142
+ * Create or update a user data item.
143
+ * The item object must include an `id` field.
144
+ *
145
+ * @param appId - The app ID
146
+ * @param item - The data item (must include `id`)
147
+ * @returns The saved item
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * await userAppData.set('garden-planner', {
152
+ * id: 'bed-1',
153
+ * name: 'Vegetable Bed',
154
+ * plants: ['tomatoes', 'peppers'],
155
+ * location: { x: 10, y: 20 }
156
+ * });
157
+ * ```
158
+ */
159
+ async function set(appId, item) {
160
+ const path = `/public/auth/app/${encodeURIComponent(appId)}/data`;
161
+ return post(path, item);
162
+ }
163
+ userAppData.set = set;
164
+ /**
165
+ * Delete a user data item by ID.
166
+ *
167
+ * @param appId - The app ID
168
+ * @param itemId - The item ID to delete
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * await userAppData.remove('garden-planner', 'bed-1');
173
+ * ```
174
+ */
175
+ async function remove(appId, itemId) {
176
+ const path = `/public/auth/app/${encodeURIComponent(appId)}/data/${encodeURIComponent(itemId)}`;
177
+ return del(path);
178
+ }
179
+ userAppData.remove = remove;
180
+ })(userAppData || (userAppData = {}));
181
+ /**
182
+ * Collection/Product-scoped app configuration.
183
+ * This is admin-managed configuration that applies to all users within the scope.
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Get collection-level app config
188
+ * const config = await appConfiguration.getConfig({
189
+ * appId: 'warranty-portal',
190
+ * collectionId: 'my-collection'
191
+ * });
192
+ *
193
+ * // Set product-level config (admin only)
194
+ * await appConfiguration.setConfig({
195
+ * appId: 'warranty-portal',
196
+ * collectionId: 'my-collection',
197
+ * productId: 'product-123',
198
+ * admin: true,
199
+ * config: { warrantyPeriod: 24 }
200
+ * });
201
+ *
202
+ * // List product-level data items
203
+ * const items = await appConfiguration.getData({
204
+ * appId: 'product-docs',
205
+ * collectionId: 'my-collection',
206
+ * productId: 'product-123'
207
+ * });
208
+ * ```
209
+ */
43
210
  export var appConfiguration;
44
211
  (function (appConfiguration) {
45
- // Get config (app, collection, product, variant, batch, user)
212
+ /**
213
+ * Get app configuration for a collection/product scope.
214
+ *
215
+ * @param opts - Configuration options including appId and scope (collectionId, productId, etc.)
216
+ * @returns The configuration object
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const config = await appConfiguration.getConfig({
221
+ * appId: 'warranty-portal',
222
+ * collectionId: 'my-collection'
223
+ * });
224
+ * ```
225
+ */
46
226
  async function getConfig(opts) {
47
227
  const path = buildAppPath(opts, "config");
48
228
  return request(path);
49
229
  }
50
230
  appConfiguration.getConfig = getConfig;
51
- // Set config (app, collection, product, variant, batch, user)
231
+ /**
232
+ * Set app configuration for a collection/product scope.
233
+ * Requires admin authentication.
234
+ *
235
+ * @param opts - Configuration options including appId, scope, and config data
236
+ * @returns The saved configuration
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * await appConfiguration.setConfig({
241
+ * appId: 'warranty-portal',
242
+ * collectionId: 'my-collection',
243
+ * admin: true,
244
+ * config: { warrantyPeriod: 24, supportEmail: 'support@example.com' }
245
+ * });
246
+ * ```
247
+ */
52
248
  async function setConfig(opts) {
53
249
  const path = buildAppPath(opts, "config");
54
250
  return post(path, opts.config);
55
251
  }
56
252
  appConfiguration.setConfig = setConfig;
57
- // Delete config (user only)
253
+ /**
254
+ * Delete app configuration for a collection/product scope.
255
+ * Requires admin authentication.
256
+ *
257
+ * @param opts - Configuration options including appId and scope
258
+ *
259
+ * @example
260
+ * ```typescript
261
+ * await appConfiguration.deleteConfig({
262
+ * appId: 'warranty-portal',
263
+ * collectionId: 'my-collection',
264
+ * admin: true
265
+ * });
266
+ * ```
267
+ */
58
268
  async function deleteConfig(opts) {
59
269
  const path = buildAppPath(opts, "config");
60
270
  return del(path);
61
271
  }
62
272
  appConfiguration.deleteConfig = deleteConfig;
63
- // Get all data items (app, collection, product, variant, batch, userData)
273
+ /**
274
+ * Get all data items for an app within a scope.
275
+ *
276
+ * @param opts - Options including appId and scope (collectionId, productId, etc.)
277
+ * @returns Array of data items
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * const items = await appConfiguration.getData({
282
+ * appId: 'product-docs',
283
+ * collectionId: 'my-collection',
284
+ * productId: 'product-123'
285
+ * });
286
+ * ```
287
+ */
64
288
  async function getData(opts) {
65
289
  const path = buildAppPath(opts, "data");
66
290
  return request(path);
67
291
  }
68
292
  appConfiguration.getData = getData;
69
- // Get a single data item (app, collection, product, variant, batch, userData)
293
+ /**
294
+ * Get a single data item by ID within a scope.
295
+ *
296
+ * @param opts - Options including appId, scope, and itemId
297
+ * @returns The data item
298
+ *
299
+ * @example
300
+ * ```typescript
301
+ * const item = await appConfiguration.getDataItem({
302
+ * appId: 'product-docs',
303
+ * collectionId: 'my-collection',
304
+ * productId: 'product-123',
305
+ * itemId: 'manual-1'
306
+ * });
307
+ * ```
308
+ */
70
309
  async function getDataItem(opts) {
71
310
  if (!opts.itemId)
72
311
  throw new Error("itemId is required for getDataItem");
@@ -74,13 +313,46 @@ export var appConfiguration;
74
313
  return request(path);
75
314
  }
76
315
  appConfiguration.getDataItem = getDataItem;
77
- // Set a data item (app, collection, product, variant, batch, userData)
316
+ /**
317
+ * Set/create a data item within a scope.
318
+ * Requires admin authentication.
319
+ *
320
+ * @param opts - Options including appId, scope, and data
321
+ * @returns The saved data item
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * await appConfiguration.setDataItem({
326
+ * appId: 'product-docs',
327
+ * collectionId: 'my-collection',
328
+ * productId: 'product-123',
329
+ * admin: true,
330
+ * data: { id: 'manual-1', title: 'User Manual', url: 'https://...' }
331
+ * });
332
+ * ```
333
+ */
78
334
  async function setDataItem(opts) {
79
335
  const path = buildAppPath(opts, "data");
80
336
  return post(path, opts.data);
81
337
  }
82
338
  appConfiguration.setDataItem = setDataItem;
83
- // Delete a data item (app, collection, product, variant, batch, userData)
339
+ /**
340
+ * Delete a data item by ID within a scope.
341
+ * Requires admin authentication.
342
+ *
343
+ * @param opts - Options including appId, scope, and itemId
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * await appConfiguration.deleteDataItem({
348
+ * appId: 'product-docs',
349
+ * collectionId: 'my-collection',
350
+ * productId: 'product-123',
351
+ * admin: true,
352
+ * itemId: 'manual-1'
353
+ * });
354
+ * ```
355
+ */
84
356
  async function deleteDataItem(opts) {
85
357
  if (!opts.itemId)
86
358
  throw new Error("itemId is required for deleteDataItem");
@@ -1,7 +1,7 @@
1
1
  export { collection } from "./collection";
2
2
  export { product } from "./product";
3
3
  export { proof } from "./proof";
4
- export { appConfiguration } from "./appConfiguration";
4
+ export { appConfiguration, userAppData } from "./appConfiguration";
5
5
  export { asset } from "./asset";
6
6
  export { attestation } from "./attestation";
7
7
  export { auth } from "./auth";
package/dist/api/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  export { collection } from "./collection";
4
4
  export { product } from "./product";
5
5
  export { proof } from "./proof";
6
- export { appConfiguration } from "./appConfiguration";
6
+ export { appConfiguration, userAppData } from "./appConfiguration";
7
7
  export { asset } from "./asset";
8
8
  export { attestation } from "./attestation";
9
9
  export { auth } from "./auth";