@contrail/extensions-sdk 1.0.24 → 1.0.26

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.
@@ -37,6 +37,43 @@ export interface AppContext {
37
37
  };
38
38
  user?: User;
39
39
  }
40
+ /** One active filter condition on the plan. */
41
+ export interface PlanFilterCriterion {
42
+ /** The property being filtered, e.g. `gender`. */
43
+ slug: string;
44
+ label?: string;
45
+ propertyType?: string;
46
+ /**
47
+ * The condition, as a FilterConditionType value: `equals`, `not_equal_to`, `is_any_of`,
48
+ * `is_none_of`, `contains`, `starts_with`, `ends_with`, `less_than`, `greater_than`,
49
+ * `greater_than_or_equal`, `less_than_or_equal`, `is_empty`, `is_not_empty`, `is_in_list`,
50
+ * `are_any_empty`.
51
+ */
52
+ conditionType: string;
53
+ /** The value compared against. An array for the `is_any_of` / `is_none_of` conditions. */
54
+ value?: any;
55
+ /** How this condition joins the previous one. Absent on the first criterion. */
56
+ conjunction?: 'and' | 'or';
57
+ includeEmptyValues?: boolean;
58
+ }
59
+ export interface PlanSortCriterion {
60
+ slug: string;
61
+ label?: string;
62
+ /** A SortDirection value: `ASC`, `DESC`, `LIST_ORDER_ASC` or `LIST_ORDER_DESC`. */
63
+ direction: string;
64
+ }
65
+ /**
66
+ * What the user is currently looking at, beyond the rows themselves.
67
+ *
68
+ * Lets an extension scope itself the way the grid is scoped — e.g. a goals tool can hide goals for
69
+ * a gender the user has filtered out, rather than reporting them as unmet.
70
+ */
71
+ export interface PlanViewState {
72
+ /** True when at least one filter condition is active. */
73
+ hasFilter: boolean;
74
+ filters: Array<PlanFilterCriterion>;
75
+ sorts: Array<PlanSortCriterion>;
76
+ }
40
77
  export interface PlanContext {
41
78
  id: string;
42
79
  name: string;
@@ -46,7 +83,20 @@ export interface PlanContext {
46
83
  itemIds?: string[];
47
84
  planPlaceholders?: any[];
48
85
  filteredPlanPlaceholderIds?: string[];
86
+ /**
87
+ * Whether a filter is active.
88
+ *
89
+ * @deprecated Superseded by `viewState`, which also says *what* the filter is. Retained because
90
+ * existing extensions read it; equivalent to `viewState.hasFilter`.
91
+ */
49
92
  hasFilter: boolean;
93
+ /**
94
+ * The filter and sorts in effect **when this extension opened**.
95
+ *
96
+ * Absent on hosts that predate this field, so guard before reading. For current state — after
97
+ * the user has changed the filter — `await` {@link PlanApp.getViewState}.
98
+ */
99
+ viewState?: PlanViewState;
50
100
  }
51
101
  export interface BoardContext {
52
102
  id: string;
@@ -1,4 +1,4 @@
1
- export { getAppContext, AppContext, BoardContext, PlanContext, ShowcaseContext, VibeIQAppType } from './app-context';
1
+ export { getAppContext, AppContext, BoardContext, PlanContext, PlanFilterCriterion, PlanSortCriterion, PlanViewState, ShowcaseContext, VibeIQAppType, } from './app-context';
2
2
  export * from './boards';
3
3
  export * from './plan';
4
4
  export * from './showcase';
@@ -1,10 +1,12 @@
1
- import { PlanContext } from './app-context';
1
+ import { PlanContext, PlanViewState } from './app-context';
2
2
  export declare enum PlanCommand {
3
3
  ADD_ROWS = "plan:add_rows",
4
4
  SHOW_MESSAGE = "plan:show_message",
5
5
  CLEAR_SELECTED_ROWS = "plan:clear_selected_rows",
6
6
  ADD_PLACEHOLDERS = "plan:add_placeholders",
7
- ADD_PLACEHOLDERS_WITH_ITEMS = "plan:add_placeholders_with_items"
7
+ ADD_PLACEHOLDERS_WITH_ITEMS = "plan:add_placeholders_with_items",
8
+ GET_PLACEHOLDERS = "plan:get_placeholders",
9
+ GET_VIEW_STATE = "plan:get_view_state"
8
10
  }
9
11
  /**
10
12
  * A row on a plan. Beyond the item linkage below, properties are the org-configured
@@ -23,10 +25,89 @@ export interface AddPlaceholdersOptions {
23
25
  /** Skip the undo/redo entry. Intended for bulk programmatic writes. */
24
26
  skipRecordingUndoRedo?: boolean;
25
27
  }
28
+ /**
29
+ * Which rows {@link PlanApp.getPlaceholders} should return. Mirrors the plan's own data scopes.
30
+ *
31
+ * - `all` — every row on the plan, ignoring filters (the default)
32
+ * - `filtered` — the user's active filter applied
33
+ * - `displayed` — filter plus focused item family, i.e. what the grid is actually showing
34
+ * - `selected` — only the currently selected rows
35
+ */
36
+ export declare type PlanPlaceholderScope = 'all' | 'filtered' | 'displayed' | 'selected';
37
+ export interface GetPlaceholdersOptions {
38
+ /** Defaults to `all`. */
39
+ scope?: PlanPlaceholderScope;
40
+ /**
41
+ * Return only these property slugs, to keep the payload small on large plans.
42
+ * `id`, `itemFamilyId` and `itemOptionId` are always included.
43
+ */
44
+ propertySlugs?: Array<string>;
45
+ }
26
46
  export declare class PlanApp {
27
47
  static getCurrentPlan(): PlanContext;
48
+ /**
49
+ * The plan's rows **as they were when this extension opened**.
50
+ *
51
+ * Synchronous and free, because it reads the context snapshot the host sent at startup. That
52
+ * snapshot is never re-sent, so it will not contain rows created since (including ones this
53
+ * extension created itself), edits made in the grid, or other users' changes.
54
+ *
55
+ * Use this for a one-shot read on open. For current state, `await` {@link getPlaceholders} —
56
+ * which also refreshes what this method returns.
57
+ */
28
58
  static getAllPlanPlaceholders(): any[];
59
+ /**
60
+ * The snapshot narrowed to the user's active filter — the same startup snapshot as
61
+ * {@link getAllPlanPlaceholders}, and equally subject to going stale.
62
+ *
63
+ * Note this filters the snapshot by the `filteredPlanPlaceholderIds` captured at startup, so it
64
+ * reflects the filter *at open time*. If the user changes the filter while the extension is open,
65
+ * use `getPlaceholders({ scope: 'filtered' })` instead.
66
+ */
29
67
  static getFilteredPlanPlaceholders(): any[];
68
+ /**
69
+ * The plan's rows **as they are right now**, read from the host on demand.
70
+ *
71
+ * Asynchronous, because it round-trips to the plan. Returns fully hydrated rows — property
72
+ * defaults applied and formulas evaluated — so it is the only way to see the real state of rows
73
+ * created during this session, or edits the user has made in the grid since it opened.
74
+ *
75
+ * ### How this differs from {@link getAllPlanPlaceholders}
76
+ *
77
+ * | | `getAllPlanPlaceholders()` | `getPlaceholders()` |
78
+ * | --- | --- | --- |
79
+ * | Source | startup context snapshot | live host state |
80
+ * | Call | synchronous | `await` |
81
+ * | Sees later changes | no | yes |
82
+ * | Scope | all, or filter-at-open-time | `all` / `filtered` / `displayed` / `selected` |
83
+ *
84
+ * ### Side effect
85
+ *
86
+ * A **full, unprojected** read (no `scope`, or `scope: 'all'`, and no `propertySlugs`) replaces
87
+ * the cached snapshot, so `getAllPlanPlaceholders()` returns the fresh rows afterwards. A
88
+ * filtered or projected read deliberately does not, since a partial result is not a valid
89
+ * substitute for the snapshot.
90
+ *
91
+ * Reading is always permitted, including on a view-only plan.
92
+ */
93
+ static getPlaceholders(options?: GetPlaceholdersOptions): Promise<Array<PlanPlaceholder>>;
94
+ /**
95
+ * The filter and sorts in effect **right now**.
96
+ *
97
+ * Use this to scope an extension the way the grid is scoped. If the user has filtered the plan to
98
+ * `gender = mens`, a goals tool can hide goals for other genders rather than reporting them as
99
+ * unmet, and can avoid offering to create rows that would immediately fall out of that filter.
100
+ *
101
+ * ### How this differs from the launch context
102
+ *
103
+ * `getCurrentPlan().viewState` is the state captured when the extension opened — synchronous and
104
+ * free, but blind to any filter change since. This method round-trips to the host for current
105
+ * state, and refreshes `viewState` on the cached context so the synchronous read agrees with it
106
+ * afterwards.
107
+ *
108
+ * Reading is always permitted, including on a view-only plan.
109
+ */
110
+ static getViewState(): Promise<PlanViewState>;
30
111
  /**
31
112
  * Creates new rows on the plan from property data, and returns them.
32
113
  *
package/lib/apps/plan.js CHANGED
@@ -19,18 +19,38 @@ var PlanCommand;
19
19
  PlanCommand["CLEAR_SELECTED_ROWS"] = "plan:clear_selected_rows";
20
20
  PlanCommand["ADD_PLACEHOLDERS"] = "plan:add_placeholders";
21
21
  PlanCommand["ADD_PLACEHOLDERS_WITH_ITEMS"] = "plan:add_placeholders_with_items";
22
+ PlanCommand["GET_PLACEHOLDERS"] = "plan:get_placeholders";
23
+ PlanCommand["GET_VIEW_STATE"] = "plan:get_view_state";
22
24
  })(PlanCommand = exports.PlanCommand || (exports.PlanCommand = {}));
23
25
  class PlanApp {
24
26
  static getCurrentPlan() {
25
27
  PlanApp.validatePlanContext();
26
28
  return (0, app_context_1.getAppContext)().appContext.plan;
27
29
  }
30
+ /**
31
+ * The plan's rows **as they were when this extension opened**.
32
+ *
33
+ * Synchronous and free, because it reads the context snapshot the host sent at startup. That
34
+ * snapshot is never re-sent, so it will not contain rows created since (including ones this
35
+ * extension created itself), edits made in the grid, or other users' changes.
36
+ *
37
+ * Use this for a one-shot read on open. For current state, `await` {@link getPlaceholders} —
38
+ * which also refreshes what this method returns.
39
+ */
28
40
  static getAllPlanPlaceholders() {
29
41
  var _a;
30
42
  PlanApp.validatePlanContext();
31
43
  const plan = PlanApp.getCurrentPlan();
32
44
  return (_a = plan === null || plan === void 0 ? void 0 : plan.planPlaceholders) !== null && _a !== void 0 ? _a : [];
33
45
  }
46
+ /**
47
+ * The snapshot narrowed to the user's active filter — the same startup snapshot as
48
+ * {@link getAllPlanPlaceholders}, and equally subject to going stale.
49
+ *
50
+ * Note this filters the snapshot by the `filteredPlanPlaceholderIds` captured at startup, so it
51
+ * reflects the filter *at open time*. If the user changes the filter while the extension is open,
52
+ * use `getPlaceholders({ scope: 'filtered' })` instead.
53
+ */
34
54
  static getFilteredPlanPlaceholders() {
35
55
  var _a;
36
56
  PlanApp.validatePlanContext();
@@ -43,6 +63,87 @@ class PlanApp {
43
63
  const filteredResults = allPlanPlaceholders.filter((placeholder) => filteredPlanPlaceholderIds.includes(placeholder.id));
44
64
  return filteredResults;
45
65
  }
66
+ /**
67
+ * The plan's rows **as they are right now**, read from the host on demand.
68
+ *
69
+ * Asynchronous, because it round-trips to the plan. Returns fully hydrated rows — property
70
+ * defaults applied and formulas evaluated — so it is the only way to see the real state of rows
71
+ * created during this session, or edits the user has made in the grid since it opened.
72
+ *
73
+ * ### How this differs from {@link getAllPlanPlaceholders}
74
+ *
75
+ * | | `getAllPlanPlaceholders()` | `getPlaceholders()` |
76
+ * | --- | --- | --- |
77
+ * | Source | startup context snapshot | live host state |
78
+ * | Call | synchronous | `await` |
79
+ * | Sees later changes | no | yes |
80
+ * | Scope | all, or filter-at-open-time | `all` / `filtered` / `displayed` / `selected` |
81
+ *
82
+ * ### Side effect
83
+ *
84
+ * A **full, unprojected** read (no `scope`, or `scope: 'all'`, and no `propertySlugs`) replaces
85
+ * the cached snapshot, so `getAllPlanPlaceholders()` returns the fresh rows afterwards. A
86
+ * filtered or projected read deliberately does not, since a partial result is not a valid
87
+ * substitute for the snapshot.
88
+ *
89
+ * Reading is always permitted, including on a view-only plan.
90
+ */
91
+ static getPlaceholders(options) {
92
+ var _a, _b, _c;
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ PlanApp.validatePlanContext();
95
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
96
+ command: PlanCommand.GET_PLACEHOLDERS,
97
+ data: { options },
98
+ });
99
+ const placeholders = (_a = PlanApp.validateAndReturnResults(results)) !== null && _a !== void 0 ? _a : [];
100
+ const isFullRead = (!(options === null || options === void 0 ? void 0 : options.scope) || options.scope === 'all') && !((_b = options === null || options === void 0 ? void 0 : options.propertySlugs) === null || _b === void 0 ? void 0 : _b.length);
101
+ if (isFullRead) {
102
+ // getAppContext() hands back the live singleton, so this updates what the sync getters see.
103
+ const plan = (_c = (0, app_context_1.getAppContext)().appContext) === null || _c === void 0 ? void 0 : _c.plan;
104
+ if (plan) {
105
+ plan.planPlaceholders = placeholders;
106
+ }
107
+ }
108
+ return placeholders;
109
+ });
110
+ }
111
+ /**
112
+ * The filter and sorts in effect **right now**.
113
+ *
114
+ * Use this to scope an extension the way the grid is scoped. If the user has filtered the plan to
115
+ * `gender = mens`, a goals tool can hide goals for other genders rather than reporting them as
116
+ * unmet, and can avoid offering to create rows that would immediately fall out of that filter.
117
+ *
118
+ * ### How this differs from the launch context
119
+ *
120
+ * `getCurrentPlan().viewState` is the state captured when the extension opened — synchronous and
121
+ * free, but blind to any filter change since. This method round-trips to the host for current
122
+ * state, and refreshes `viewState` on the cached context so the synchronous read agrees with it
123
+ * afterwards.
124
+ *
125
+ * Reading is always permitted, including on a view-only plan.
126
+ */
127
+ static getViewState() {
128
+ var _a, _b;
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ PlanApp.validatePlanContext();
131
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
132
+ command: PlanCommand.GET_VIEW_STATE,
133
+ });
134
+ const viewState = (_a = PlanApp.validateAndReturnResults(results)) !== null && _a !== void 0 ? _a : {
135
+ hasFilter: false,
136
+ filters: [],
137
+ sorts: [],
138
+ };
139
+ // getAppContext() hands back the live singleton, so this updates what getCurrentPlan() sees.
140
+ const plan = (_b = (0, app_context_1.getAppContext)().appContext) === null || _b === void 0 ? void 0 : _b.plan;
141
+ if (plan) {
142
+ plan.viewState = viewState;
143
+ }
144
+ return viewState;
145
+ });
146
+ }
46
147
  /**
47
148
  * Creates new rows on the plan from property data, and returns them.
48
149
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/extensions-sdk",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "Client library for interfacing with VibeIQ's services and apps from an extension.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",