@proveanything/smartlinks 2.1.17 → 2.1.18

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 (48) hide show
  1. package/dist/adminViews.d.ts +85 -0
  2. package/dist/adminViews.js +259 -0
  3. package/dist/api/index.d.ts +2 -0
  4. package/dist/api/index.js +2 -0
  5. package/dist/api/operations.d.ts +36 -0
  6. package/dist/api/operations.js +56 -0
  7. package/dist/api/order.d.ts +12 -1
  8. package/dist/api/order.js +15 -0
  9. package/dist/api/userGroups.d.ts +78 -0
  10. package/dist/api/userGroups.js +124 -0
  11. package/dist/docs/API_SUMMARY.md +604 -42
  12. package/dist/docs/admin-views.md +125 -0
  13. package/dist/docs/app-manifest.md +2 -0
  14. package/dist/docs/operations.md +281 -0
  15. package/dist/docs/overview.md +3 -0
  16. package/dist/docs/server-functions.md +18 -0
  17. package/dist/docs/user-groups.md +168 -0
  18. package/dist/docs/utils.md +17 -0
  19. package/dist/http.js +4 -0
  20. package/dist/iframeResponder.d.ts +15 -0
  21. package/dist/iframeResponder.js +39 -1
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.js +2 -0
  24. package/dist/openapi.yaml +1238 -276
  25. package/dist/testing/index.d.ts +13 -0
  26. package/dist/testing/index.js +55 -0
  27. package/dist/types/appManifest.d.ts +83 -0
  28. package/dist/types/containers.d.ts +8 -0
  29. package/dist/types/iframeResponder.d.ts +16 -1
  30. package/dist/types/index.d.ts +2 -0
  31. package/dist/types/index.js +2 -0
  32. package/dist/types/operations.d.ts +598 -0
  33. package/dist/types/operations.js +8 -0
  34. package/dist/types/order.d.ts +35 -6
  35. package/dist/types/userGroups.d.ts +103 -0
  36. package/dist/types/userGroups.js +5 -0
  37. package/dist/utils/conditions.d.ts +7 -0
  38. package/dist/utils/conditions.js +16 -9
  39. package/docs/API_SUMMARY.md +604 -42
  40. package/docs/admin-views.md +125 -0
  41. package/docs/app-manifest.md +2 -0
  42. package/docs/operations.md +281 -0
  43. package/docs/overview.md +3 -0
  44. package/docs/server-functions.md +18 -0
  45. package/docs/user-groups.md +168 -0
  46. package/docs/utils.md +17 -0
  47. package/openapi.yaml +1238 -276
  48. package/package.json +1 -1
@@ -479,6 +479,23 @@ await utils.validateCondition({
479
479
 
480
480
  User types: `'valid'`, `'invalid'`, `'owner'`, `'admin'`, `'group'`
481
481
 
482
+ `'group'` passes when the signed-in user is in at least one of the named [user groups](user-groups.md).
483
+ Name them in `groupIds` (keys or ids), and pass the user's own in `user.groups`:
484
+
485
+ ```typescript
486
+ const { userGroups: keys, userGroupIds } = await userGroups.mine(collectionId)
487
+
488
+ await utils.validateCondition({
489
+ condition: {
490
+ type: 'and',
491
+ conditions: [{ type: 'user', userType: 'group', groupIds: ['qc-controller'] }]
492
+ },
493
+ user: { valid: true, uid: 'user123', groups: [...keys, ...userGroupIds] }
494
+ })
495
+ ```
496
+
497
+ A condition only shows or hides. To protect an action, limit the server function behind it.
498
+
482
499
  #### Date & Time Conditions
483
500
  Show/hide content based on dates:
484
501
 
package/dist/http.js CHANGED
@@ -222,6 +222,10 @@ function shouldSkipCache(path) {
222
222
  // Tag ranges change as tags are programmed, and carry the tags' keys — never cached, never persisted.
223
223
  if (/\/claimSet\/[^/]+\/ranges(\/|\?|$)/i.test(path))
224
224
  return true;
225
+ // User groups say who may do what: a change (someone added or removed) must show at once, and
226
+ // `mine` is about one person.
227
+ if (/\/userGroups?(\/|\?|$)/i.test(path))
228
+ return true;
225
229
  return false;
226
230
  }
227
231
  /** Evict the oldest (LRU) entry when the cache is at capacity. */
@@ -39,6 +39,8 @@ export declare class IframeResponder {
39
39
  private uploads;
40
40
  private activeStreams;
41
41
  private isInitialLoad;
42
+ /** The app follows `smartlinks:navigate` (it said so with `smartlinks:navigable`). */
43
+ private navigable;
42
44
  private messageHandler;
43
45
  private resizeHandler;
44
46
  private appUrl;
@@ -50,6 +52,19 @@ export declare class IframeResponder {
50
52
  * Returns the src URL to set on the iframe.
51
53
  */
52
54
  attach(iframe: HTMLIFrameElement): Promise<string>;
55
+ /**
56
+ * Ask the app to open one of its admin views (or a hash path) without reloading. Returns false when
57
+ * the app hasn't said it follows navigate (an older build): reload the frame at the new path instead.
58
+ * See docs/admin-views.md.
59
+ */
60
+ navigate(req: {
61
+ view?: string;
62
+ path?: string;
63
+ params?: Record<string, string>;
64
+ highlight?: string;
65
+ }): boolean;
66
+ /** True once the app has said it follows `smartlinks:navigate`. */
67
+ get isNavigable(): boolean;
53
68
  /**
54
69
  * Update cached data (e.g., after user logs in).
55
70
  */
@@ -43,6 +43,8 @@ export class IframeResponder {
43
43
  this.uploads = new Map();
44
44
  this.activeStreams = new Map();
45
45
  this.isInitialLoad = true;
46
+ /** The app follows `smartlinks:navigate` (it said so with `smartlinks:navigable`). */
47
+ this.navigable = false;
46
48
  this.messageHandler = null;
47
49
  this.resizeHandler = null;
48
50
  this.appUrl = null;
@@ -89,6 +91,28 @@ export class IframeResponder {
89
91
  const src = this.buildIframeSrc();
90
92
  return src;
91
93
  }
94
+ /**
95
+ * Ask the app to open one of its admin views (or a hash path) without reloading. Returns false when
96
+ * the app hasn't said it follows navigate (an older build): reload the frame at the new path instead.
97
+ * See docs/admin-views.md.
98
+ */
99
+ navigate(req) {
100
+ var _a;
101
+ const win = (_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow;
102
+ if (!this.navigable || !win)
103
+ return false;
104
+ try {
105
+ win.postMessage(Object.assign({ type: 'smartlinks:navigate' }, req), '*');
106
+ return true;
107
+ }
108
+ catch (_b) {
109
+ return false;
110
+ }
111
+ }
112
+ /** True once the app has said it follows `smartlinks:navigate`. */
113
+ get isNavigable() {
114
+ return this.navigable;
115
+ }
92
116
  /**
93
117
  * Update cached data (e.g., after user logs in).
94
118
  */
@@ -356,7 +380,7 @@ export class IframeResponder {
356
380
  // Standard Iframe Messages
357
381
  // ===========================================================================
358
382
  async handleStandardMessage(data, event) {
359
- var _a, _b, _c, _d, _e, _f, _g;
383
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
360
384
  switch (data.type) {
361
385
  case 'smartlinks:resize': {
362
386
  const contentHeight = (_a = data.payload) === null || _a === void 0 ? void 0 : _a.height;
@@ -424,6 +448,20 @@ export class IframeResponder {
424
448
  }
425
449
  break;
426
450
  }
451
+ case 'smartlinks:navigable': {
452
+ this.navigable = true;
453
+ const p = data.payload || {};
454
+ (_j = (_h = this.options).onNavigable) === null || _j === void 0 ? void 0 : _j.call(_h, {
455
+ views: Array.isArray(p.views) ? p.views.filter((v) => typeof v === 'string') : [],
456
+ chrome: p.chrome === 'none' ? 'none' : 'full',
457
+ });
458
+ break;
459
+ }
460
+ case 'smartlinks:navigate-result': {
461
+ const p = data.payload || {};
462
+ (_l = (_k = this.options).onNavigateResult) === null || _l === void 0 ? void 0 : _l.call(_k, Object.assign({ ok: p.ok === true, view: typeof p.view === 'string' ? p.view : null, path: typeof p.path === 'string' ? p.path : null }, (typeof p.reason === 'string' ? { reason: p.reason } : {})));
463
+ break;
464
+ }
427
465
  }
428
466
  }
429
467
  // ===========================================================================
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export * from "./api/index.js";
3
3
  export * from "./types/index.js";
4
4
  export { iframe } from "./iframe.js";
5
5
  export { readContext } from "./context.js";
6
+ export * as adminViews from "./adminViews.js";
7
+ export type { NavigateRequest, NavigateTarget } from "./adminViews.js";
6
8
  export { widgetStyleVars, widgetStyleControls, readableOn, WIDGET_STYLE_VARS } from "./widgetStyle.js";
7
9
  export type { WidgetStyling } from "./widgetStyle.js";
8
10
  export type { SmartLinksContext } from "./context.js";
package/dist/index.js CHANGED
@@ -7,6 +7,8 @@ export * from "./types/index.js";
7
7
  export { iframe } from "./iframe.js";
8
8
  // App context reader (props → hash → search), for pages and containers alike
9
9
  export { readContext } from "./context.js";
10
+ import * as adminViews_1 from "./adminViews.js";
11
+ export { adminViews_1 as adminViews };
10
12
  export { widgetStyleVars, widgetStyleControls, readableOn, WIDGET_STYLE_VARS } from "./widgetStyle.js";
11
13
  import * as cache_1 from './cache.js';
12
14
  export { cache_1 as cache };