@proveanything/smartlinks 1.8.4 → 1.8.6

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,4 +1,5 @@
1
1
  import { CollectionWidgetsResponse, GetCollectionWidgetsOptions } from "../types/appManifest";
2
+ import type { GetWidgetInstanceOptions, WidgetInstance, WidgetInstanceSummary } from "../types/appConfiguration";
2
3
  /**
3
4
  * Options for collection/product-scoped app configuration.
4
5
  * This data is set by admins and applies to all users within the scope.
@@ -20,7 +21,7 @@ export type AppConfigOptions = {
20
21
  admin?: boolean;
21
22
  /** Configuration object for setConfig */
22
23
  config?: any;
23
- /** Data object for setDataItem */
24
+ /** Data object for setDataItem. Best for small keyed scoped documents rather than richer app domain objects. */
24
25
  data?: any;
25
26
  };
26
27
  /**
@@ -193,6 +194,39 @@ export declare namespace appConfiguration {
193
194
  * ```
194
195
  */
195
196
  function getConfig(opts: AppConfigOptions): Promise<any>;
197
+ /**
198
+ * Resolve a configured widget instance by ID from an app's stored config.
199
+ * This is a thin convenience wrapper over `getConfig()` that reads `config.widgets[widgetId]`.
200
+ *
201
+ * @param opts - Scope options plus the widget instance ID
202
+ * @returns The configured widget instance
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * const widget = await appConfiguration.getWidgetInstance({
207
+ * collectionId: 'my-collection',
208
+ * appId: 'widget-toolkit',
209
+ * widgetId: 'launch-countdown'
210
+ * })
211
+ * ```
212
+ */
213
+ function getWidgetInstance<TWidget = any>(opts: GetWidgetInstanceOptions): Promise<WidgetInstance<TWidget>>;
214
+ /**
215
+ * List configured widget instances for an app.
216
+ * Useful for picker UIs, setup schemas, and widget-to-widget references.
217
+ *
218
+ * @param opts - App config scope options
219
+ * @returns Array of widget instance summaries
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * const widgets = await appConfiguration.listWidgetInstances({
224
+ * collectionId: 'my-collection',
225
+ * appId: 'widget-toolkit'
226
+ * })
227
+ * ```
228
+ */
229
+ function listWidgetInstances(opts: Omit<GetWidgetInstanceOptions, 'widgetId'>): Promise<WidgetInstanceSummary[]>;
196
230
  /**
197
231
  * Set app configuration for a collection/product scope.
198
232
  * Requires admin authentication.
@@ -228,7 +262,13 @@ export declare namespace appConfiguration {
228
262
  */
229
263
  function deleteConfig(opts: AppConfigOptions): Promise<void>;
230
264
  /**
231
- * Get all data items for an app within a scope.
265
+ * Get all keyed data items for an app within a scope.
266
+ * Best for a small set of standalone documents such as FAQs, menus, lookup tables,
267
+ * or content fragments where the caller typically knows the item IDs.
268
+ *
269
+ * If you are modelling richer app entities that need filtering, lifecycle fields,
270
+ * visibility, ownership, or relationships, prefer `app.records`, `app.cases`,
271
+ * or `app.threads` instead.
232
272
  *
233
273
  * @param opts - Options including appId and scope (collectionId, productId, etc.)
234
274
  * @returns Array of data items
@@ -244,7 +284,11 @@ export declare namespace appConfiguration {
244
284
  */
245
285
  function getData(opts: AppConfigOptions): Promise<any[]>;
246
286
  /**
247
- * Get a single data item by ID within a scope.
287
+ * Get a single keyed data item by ID within a scope.
288
+ * This is ideal when you already know the exact ID of a simple scoped document.
289
+ *
290
+ * For richer domain objects that users browse or query, prefer `app.records`,
291
+ * `app.cases`, or `app.threads`.
248
292
  *
249
293
  * @param opts - Options including appId, scope, and itemId
250
294
  * @returns The data item
@@ -261,8 +305,15 @@ export declare namespace appConfiguration {
261
305
  */
262
306
  function getDataItem(opts: AppConfigOptions): Promise<any>;
263
307
  /**
264
- * Set/create a data item within a scope.
308
+ * Set/create a keyed data item within a scope.
265
309
  * Requires admin authentication.
310
+ *
311
+ * Use this for simple scoped documents attached to a collection/product/variant/batch,
312
+ * especially when you want a small number of items with stable IDs.
313
+ *
314
+ * Do not treat this as the default write path for every app-owned entity. If the data
315
+ * starts behaving like a real object with lifecycle, filtering, visibility, ownership,
316
+ * history, or relationships, prefer `app.records`, `app.cases`, or `app.threads`.
266
317
  *
267
318
  * @param opts - Options including appId, scope, and data
268
319
  * @returns The saved data item
@@ -280,7 +331,7 @@ export declare namespace appConfiguration {
280
331
  */
281
332
  function setDataItem(opts: AppConfigOptions): Promise<any>;
282
333
  /**
283
- * Delete a data item by ID within a scope.
334
+ * Delete a keyed data item by ID within a scope.
284
335
  * Requires admin authentication.
285
336
  *
286
337
  * @param opts - Options including appId, scope, and itemId
@@ -1,5 +1,24 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  // src/api/appConfiguration.ts
2
13
  import { request, post, del } from "../http";
14
+ function getWidgetsMap(config) {
15
+ if (!config || typeof config !== 'object' || Array.isArray(config))
16
+ return {};
17
+ const widgets = config.widgets;
18
+ if (!widgets || typeof widgets !== 'object' || Array.isArray(widgets))
19
+ return {};
20
+ return widgets;
21
+ }
3
22
  function buildAppPath(opts, type) {
4
23
  const base = opts.admin ? "admin" : "public";
5
24
  let path = `/${base}`;
@@ -228,6 +247,67 @@ export var appConfiguration;
228
247
  return request(path);
229
248
  }
230
249
  appConfiguration.getConfig = getConfig;
250
+ /**
251
+ * Resolve a configured widget instance by ID from an app's stored config.
252
+ * This is a thin convenience wrapper over `getConfig()` that reads `config.widgets[widgetId]`.
253
+ *
254
+ * @param opts - Scope options plus the widget instance ID
255
+ * @returns The configured widget instance
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const widget = await appConfiguration.getWidgetInstance({
260
+ * collectionId: 'my-collection',
261
+ * appId: 'widget-toolkit',
262
+ * widgetId: 'launch-countdown'
263
+ * })
264
+ * ```
265
+ */
266
+ async function getWidgetInstance(opts) {
267
+ const { widgetId } = opts, configOpts = __rest(opts, ["widgetId"]);
268
+ const config = await getConfig(configOpts);
269
+ const widgets = getWidgetsMap(config);
270
+ const instance = widgets[widgetId];
271
+ if (!instance || typeof instance !== 'object' || Array.isArray(instance)) {
272
+ throw new Error(`Widget instance \"${widgetId}\" not found for app \"${opts.appId}\"`);
273
+ }
274
+ return instance;
275
+ }
276
+ appConfiguration.getWidgetInstance = getWidgetInstance;
277
+ /**
278
+ * List configured widget instances for an app.
279
+ * Useful for picker UIs, setup schemas, and widget-to-widget references.
280
+ *
281
+ * @param opts - App config scope options
282
+ * @returns Array of widget instance summaries
283
+ *
284
+ * @example
285
+ * ```typescript
286
+ * const widgets = await appConfiguration.listWidgetInstances({
287
+ * collectionId: 'my-collection',
288
+ * appId: 'widget-toolkit'
289
+ * })
290
+ * ```
291
+ */
292
+ async function listWidgetInstances(opts) {
293
+ const config = await getConfig(opts);
294
+ const widgets = getWidgetsMap(config);
295
+ return Object.entries(widgets).map(([id, instance]) => {
296
+ var _a;
297
+ const widgetInstance = instance && typeof instance === 'object' && !Array.isArray(instance)
298
+ ? instance
299
+ : {};
300
+ const resolvedId = typeof widgetInstance.id === 'string' && widgetInstance.id.trim()
301
+ ? widgetInstance.id
302
+ : id;
303
+ return Object.assign(Object.assign({}, widgetInstance), { id: resolvedId, name: typeof widgetInstance.name === 'string' && widgetInstance.name.trim()
304
+ ? widgetInstance.name
305
+ : resolvedId, type: typeof ((_a = widgetInstance.widget) === null || _a === void 0 ? void 0 : _a.type) === 'string'
306
+ ? widgetInstance.widget.type
307
+ : undefined });
308
+ });
309
+ }
310
+ appConfiguration.listWidgetInstances = listWidgetInstances;
231
311
  /**
232
312
  * Set app configuration for a collection/product scope.
233
313
  * Requires admin authentication.
@@ -271,7 +351,13 @@ export var appConfiguration;
271
351
  }
272
352
  appConfiguration.deleteConfig = deleteConfig;
273
353
  /**
274
- * Get all data items for an app within a scope.
354
+ * Get all keyed data items for an app within a scope.
355
+ * Best for a small set of standalone documents such as FAQs, menus, lookup tables,
356
+ * or content fragments where the caller typically knows the item IDs.
357
+ *
358
+ * If you are modelling richer app entities that need filtering, lifecycle fields,
359
+ * visibility, ownership, or relationships, prefer `app.records`, `app.cases`,
360
+ * or `app.threads` instead.
275
361
  *
276
362
  * @param opts - Options including appId and scope (collectionId, productId, etc.)
277
363
  * @returns Array of data items
@@ -291,7 +377,11 @@ export var appConfiguration;
291
377
  }
292
378
  appConfiguration.getData = getData;
293
379
  /**
294
- * Get a single data item by ID within a scope.
380
+ * Get a single keyed data item by ID within a scope.
381
+ * This is ideal when you already know the exact ID of a simple scoped document.
382
+ *
383
+ * For richer domain objects that users browse or query, prefer `app.records`,
384
+ * `app.cases`, or `app.threads`.
295
385
  *
296
386
  * @param opts - Options including appId, scope, and itemId
297
387
  * @returns The data item
@@ -314,8 +404,15 @@ export var appConfiguration;
314
404
  }
315
405
  appConfiguration.getDataItem = getDataItem;
316
406
  /**
317
- * Set/create a data item within a scope.
407
+ * Set/create a keyed data item within a scope.
318
408
  * Requires admin authentication.
409
+ *
410
+ * Use this for simple scoped documents attached to a collection/product/variant/batch,
411
+ * especially when you want a small number of items with stable IDs.
412
+ *
413
+ * Do not treat this as the default write path for every app-owned entity. If the data
414
+ * starts behaving like a real object with lifecycle, filtering, visibility, ownership,
415
+ * history, or relationships, prefer `app.records`, `app.cases`, or `app.threads`.
319
416
  *
320
417
  * @param opts - Options including appId, scope, and data
321
418
  * @returns The saved data item
@@ -337,7 +434,7 @@ export var appConfiguration;
337
434
  }
338
435
  appConfiguration.setDataItem = setDataItem;
339
436
  /**
340
- * Delete a data item by ID within a scope.
437
+ * Delete a keyed data item by ID within a scope.
341
438
  * Requires admin authentication.
342
439
  *
343
440
  * @param opts - Options including appId, scope, and itemId