@contrail/extensions-sdk 1.0.23 → 1.0.24

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.
@@ -10,6 +10,7 @@ export declare enum BoardCommand {
10
10
  ADD_FRAMES_FROM_TEMPLATE = "board:add_frames_from_template",
11
11
  ADD_ITEMS_TO_CLIPBOARD = "board:add_items_to_clipboard"
12
12
  }
13
+ /** Payload for bulk-add items to clipboard (Board and Showcase). */
13
14
  export interface ClipboardItemsPayload {
14
15
  clipboardItems: Array<{
15
16
  itemId: string;
@@ -56,8 +57,10 @@ export declare class BoardsApp {
56
57
  static deleteElements(elements: Array<BoardDocumentElement>): void;
57
58
  static modifyElements(changeObjects: Array<BoardDocumentElementChanges>): void;
58
59
  static getElements(criteria: object): Promise<Array<DocumentElement>>;
60
+ /** Creates new content from a set of elements and assigns to an entity (item, etc) as a viewable */
59
61
  static createNewContentAndAssignToEntity(assignmentOptions: any, entity: any, elements: Array<DocumentElement>): Promise<Array<DocumentElement>>;
60
62
  static recolorImages(imageElements: Array<DocumentElement>, hexCode: string, hexMap?: {}): Promise<Array<DocumentElement>>;
63
+ /** Request the host to bulk-add items to the user's clipboard. */
61
64
  static addItemsToClipboard(clipboardItems: Array<{
62
65
  itemId: string;
63
66
  projectItemId?: string | null;
@@ -76,6 +76,7 @@ class BoardsApp {
76
76
  return this.validateAndReturnResults(results);
77
77
  });
78
78
  }
79
+ /** Creates new content from a set of elements and assigns to an entity (item, etc) as a viewable */
79
80
  static createNewContentAndAssignToEntity(assignmentOptions, entity, elements) {
80
81
  return __awaiter(this, void 0, void 0, function* () {
81
82
  BoardsApp.validateBoardContext();
@@ -101,6 +102,7 @@ class BoardsApp {
101
102
  return this.validateAndReturnResults(results);
102
103
  });
103
104
  }
105
+ /** Request the host to bulk-add items to the user's clipboard. */
104
106
  static addItemsToClipboard(clipboardItems) {
105
107
  BoardsApp.validateBoardContext();
106
108
  if (clipboardItems === null || clipboardItems === void 0 ? void 0 : clipboardItems.length) {
@@ -2,14 +2,68 @@ import { PlanContext } from './app-context';
2
2
  export declare enum PlanCommand {
3
3
  ADD_ROWS = "plan:add_rows",
4
4
  SHOW_MESSAGE = "plan:show_message",
5
- CLEAR_SELECTED_ROWS = "plan:clear_selected_rows"
5
+ CLEAR_SELECTED_ROWS = "plan:clear_selected_rows",
6
+ ADD_PLACEHOLDERS = "plan:add_placeholders",
7
+ ADD_PLACEHOLDERS_WITH_ITEMS = "plan:add_placeholders_with_items"
8
+ }
9
+ /**
10
+ * A row on a plan. Beyond the item linkage below, properties are the org-configured
11
+ * type-property slugs of the `plan-placeholder` type (`gender`, `targetVolume`, ...).
12
+ */
13
+ export interface PlanPlaceholder {
14
+ id?: string;
15
+ itemFamilyId?: string;
16
+ itemOptionId?: string;
17
+ [key: string]: any;
18
+ }
19
+ /** Optional placement and history behavior for the add-placeholder commands. */
20
+ export interface AddPlaceholdersOptions {
21
+ /** Row index to insert at. Omit to append to the end of the plan. */
22
+ targetRowIndex?: number;
23
+ /** Skip the undo/redo entry. Intended for bulk programmatic writes. */
24
+ skipRecordingUndoRedo?: boolean;
6
25
  }
7
26
  export declare class PlanApp {
8
27
  static getCurrentPlan(): PlanContext;
9
28
  static getAllPlanPlaceholders(): any[];
10
29
  static getFilteredPlanPlaceholders(): any[];
30
+ /**
31
+ * Creates new rows on the plan from property data, and returns them.
32
+ *
33
+ * The rows are created through the plan's own row-creation path, so they appear in the grid
34
+ * immediately, are undoable, and are broadcast to other users viewing the plan. The property
35
+ * values supplied on each placeholder are set on the created row.
36
+ *
37
+ * Any placeholder carrying an `itemFamilyId`/`itemOptionId` is routed through item assignment,
38
+ * exactly as {@link addPlaceholdersWithItems} would handle it.
39
+ *
40
+ * Note that {@link getAllPlanPlaceholders} continues to return the snapshot taken when the
41
+ * extension was opened — it will not include these rows. Use the returned array instead.
42
+ */
43
+ static addPlaceholders(placeholders: Array<PlanPlaceholder>, options?: AddPlaceholdersOptions): Promise<Array<PlanPlaceholder>>;
44
+ /**
45
+ * Creates new rows on the plan for existing items, and returns them.
46
+ *
47
+ * Each placeholder must carry an `itemFamilyId` or `itemOptionId`. The plan resolves the item,
48
+ * creates the project item, and applies carryover — the behavior the deprecated
49
+ * {@link addRows} provides, under a name that says what it does.
50
+ *
51
+ * To create rows that are not backed by an item, use {@link addPlaceholders}.
52
+ */
53
+ static addPlaceholdersWithItems(placeholders: Array<PlanPlaceholder>, options?: AddPlaceholdersOptions): Promise<Array<PlanPlaceholder>>;
54
+ /**
55
+ * Adds rows to the plan for existing items.
56
+ *
57
+ * @deprecated The name is misleading: this only adds rows for existing **items**, and property
58
+ * values on a placeholder without an `itemFamilyId`/`itemOptionId` are silently discarded. It
59
+ * also returns nothing, so the created rows are not available to the caller.
60
+ *
61
+ * Use {@link addPlaceholdersWithItems} for item-backed rows, or {@link addPlaceholders} to
62
+ * create rows from property data. Retained for existing extensions.
63
+ */
11
64
  static addRows(collectionElements: Array<any>): void;
12
65
  static clearSelectedRows(): void;
13
66
  static showMessage(message: string): void;
14
67
  private static validatePlanContext;
68
+ private static validateAndReturnResults;
15
69
  }
package/lib/apps/plan.js CHANGED
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.PlanApp = exports.PlanCommand = void 0;
4
13
  const actions_1 = require("../actions/actions");
@@ -8,6 +17,8 @@ var PlanCommand;
8
17
  PlanCommand["ADD_ROWS"] = "plan:add_rows";
9
18
  PlanCommand["SHOW_MESSAGE"] = "plan:show_message";
10
19
  PlanCommand["CLEAR_SELECTED_ROWS"] = "plan:clear_selected_rows";
20
+ PlanCommand["ADD_PLACEHOLDERS"] = "plan:add_placeholders";
21
+ PlanCommand["ADD_PLACEHOLDERS_WITH_ITEMS"] = "plan:add_placeholders_with_items";
11
22
  })(PlanCommand = exports.PlanCommand || (exports.PlanCommand = {}));
12
23
  class PlanApp {
13
24
  static getCurrentPlan() {
@@ -32,6 +43,64 @@ class PlanApp {
32
43
  const filteredResults = allPlanPlaceholders.filter((placeholder) => filteredPlanPlaceholderIds.includes(placeholder.id));
33
44
  return filteredResults;
34
45
  }
46
+ /**
47
+ * Creates new rows on the plan from property data, and returns them.
48
+ *
49
+ * The rows are created through the plan's own row-creation path, so they appear in the grid
50
+ * immediately, are undoable, and are broadcast to other users viewing the plan. The property
51
+ * values supplied on each placeholder are set on the created row.
52
+ *
53
+ * Any placeholder carrying an `itemFamilyId`/`itemOptionId` is routed through item assignment,
54
+ * exactly as {@link addPlaceholdersWithItems} would handle it.
55
+ *
56
+ * Note that {@link getAllPlanPlaceholders} continues to return the snapshot taken when the
57
+ * extension was opened — it will not include these rows. Use the returned array instead.
58
+ */
59
+ static addPlaceholders(placeholders, options) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ PlanApp.validatePlanContext();
62
+ if (!(placeholders === null || placeholders === void 0 ? void 0 : placeholders.length)) {
63
+ return [];
64
+ }
65
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
66
+ command: PlanCommand.ADD_PLACEHOLDERS,
67
+ data: { placeholders, options },
68
+ });
69
+ return PlanApp.validateAndReturnResults(results);
70
+ });
71
+ }
72
+ /**
73
+ * Creates new rows on the plan for existing items, and returns them.
74
+ *
75
+ * Each placeholder must carry an `itemFamilyId` or `itemOptionId`. The plan resolves the item,
76
+ * creates the project item, and applies carryover — the behavior the deprecated
77
+ * {@link addRows} provides, under a name that says what it does.
78
+ *
79
+ * To create rows that are not backed by an item, use {@link addPlaceholders}.
80
+ */
81
+ static addPlaceholdersWithItems(placeholders, options) {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ PlanApp.validatePlanContext();
84
+ if (!(placeholders === null || placeholders === void 0 ? void 0 : placeholders.length)) {
85
+ return [];
86
+ }
87
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
88
+ command: PlanCommand.ADD_PLACEHOLDERS_WITH_ITEMS,
89
+ data: { placeholders, options },
90
+ });
91
+ return PlanApp.validateAndReturnResults(results);
92
+ });
93
+ }
94
+ /**
95
+ * Adds rows to the plan for existing items.
96
+ *
97
+ * @deprecated The name is misleading: this only adds rows for existing **items**, and property
98
+ * values on a placeholder without an `itemFamilyId`/`itemOptionId` are silently discarded. It
99
+ * also returns nothing, so the created rows are not available to the caller.
100
+ *
101
+ * Use {@link addPlaceholdersWithItems} for item-backed rows, or {@link addPlaceholders} to
102
+ * create rows from property data. Retained for existing extensions.
103
+ */
35
104
  static addRows(collectionElements) {
36
105
  PlanApp.validatePlanContext();
37
106
  if (collectionElements === null || collectionElements === void 0 ? void 0 : collectionElements.length) {
@@ -50,10 +119,18 @@ class PlanApp {
50
119
  actions.sendMessageToHost({ command: PlanCommand.SHOW_MESSAGE, data: message });
51
120
  }
52
121
  static validatePlanContext() {
122
+ var _a, _b;
53
123
  const context = (0, app_context_1.getAppContext)();
54
- if (context.appContext.vibeIQApp !== app_context_1.VibeIQAppType.PLAN || !context.appContext.plan) {
124
+ if (((_a = context.appContext) === null || _a === void 0 ? void 0 : _a.vibeIQApp) !== app_context_1.VibeIQAppType.PLAN || !((_b = context.appContext) === null || _b === void 0 ? void 0 : _b.plan)) {
55
125
  throw new Error('App extension has not been initialized with Plan context.');
56
126
  }
57
127
  }
128
+ static validateAndReturnResults(results) {
129
+ var _a;
130
+ if (!results.success) {
131
+ throw new Error((_a = results.error) !== null && _a !== void 0 ? _a : 'App operation failed.');
132
+ }
133
+ return results.data;
134
+ }
58
135
  }
59
136
  exports.PlanApp = PlanApp;
@@ -15,10 +15,12 @@ export interface ShowcaseDocumentElementChanges {
15
15
  }
16
16
  export interface AddElementsToShowcasePayload {
17
17
  elements: Array<ShowcaseDocumentElement>;
18
+ /** If omitted, elements are added to the currently active frame. */
18
19
  frameId?: string;
19
20
  }
20
21
  export interface ModifyElementsInShowcasePayload {
21
22
  changeObjects: Array<ShowcaseDocumentElementChanges>;
23
+ /** If omitted, elements are modified on the currently active frame. */
22
24
  frameId?: string;
23
25
  }
24
26
  export interface AddCanvasFrameToShowcasePayload {
@@ -40,11 +42,21 @@ export declare type NavigateToFrameInShowcasePayload = {
40
42
  };
41
43
  export interface NavigateToFrameResult {
42
44
  frameId: string;
45
+ /** 0-based position of the frame within the showcase's frames. */
43
46
  frameIndex: number;
44
47
  }
45
48
  export declare class ShowcaseApp {
46
49
  static getCurrentShowcase(): any;
50
+ /**
51
+ * Adds elements to a frame in the showcase.
52
+ * If `frameId` is omitted, elements are added to the currently active frame.
53
+ * Otherwise, elements are added to the frame matching `frameId`.
54
+ */
47
55
  static addElements(elements: Array<ShowcaseDocumentElement>, frameId?: string): void;
56
+ /**
57
+ * Adds a new canvas frame (lineboard page) containing the given elements
58
+ * and returns the created frame.
59
+ */
48
60
  static addCanvasFrame(elements: Array<ShowcaseDocumentElement>, frameOptions?: {
49
61
  name?: string;
50
62
  size?: {
@@ -52,8 +64,19 @@ export declare class ShowcaseApp {
52
64
  height: number;
53
65
  };
54
66
  }): Promise<any>;
67
+ /**
68
+ * Modifies existing elements in a frame in the showcase.
69
+ * If `frameId` is omitted, elements are modified on the currently active frame.
70
+ * Otherwise, elements are modified on the frame matching `frameId`.
71
+ */
55
72
  static modifyElements(changeObjects: Array<ShowcaseDocumentElementChanges>, frameId?: string): void;
73
+ /**
74
+ * Changes the showcase's current (visible) frame and resolves with the frame that is now active.
75
+ * Target the frame either by `frameId` or by its 0-based `frameIndex` within `showcase.frames`.
76
+ * The returned promise rejects if the id or index does not match a frame.
77
+ */
56
78
  static navigateToFrame(target: NavigateToFrameInShowcasePayload): Promise<NavigateToFrameResult>;
79
+ /** Request the host to bulk-add items to the user's clipboard. */
57
80
  static addItemsToClipboard(clipboardItems: Array<{
58
81
  itemId: string;
59
82
  projectItemId?: string | null;
@@ -26,6 +26,11 @@ class ShowcaseApp {
26
26
  ShowcaseApp.validateShowcaseContext();
27
27
  return (_a = (0, app_context_1.getAppContext)().appContext) === null || _a === void 0 ? void 0 : _a.showcase;
28
28
  }
29
+ /**
30
+ * Adds elements to a frame in the showcase.
31
+ * If `frameId` is omitted, elements are added to the currently active frame.
32
+ * Otherwise, elements are added to the frame matching `frameId`.
33
+ */
29
34
  static addElements(elements, frameId) {
30
35
  ShowcaseApp.validateShowcaseContext();
31
36
  if (elements === null || elements === void 0 ? void 0 : elements.length) {
@@ -33,6 +38,10 @@ class ShowcaseApp {
33
38
  (0, actions_1.getExtensionActions)().sendMessageToHost({ command: ShowcaseCommand.ADD_ELEMENTS, data });
34
39
  }
35
40
  }
41
+ /**
42
+ * Adds a new canvas frame (lineboard page) containing the given elements
43
+ * and returns the created frame.
44
+ */
36
45
  static addCanvasFrame(elements, frameOptions) {
37
46
  return __awaiter(this, void 0, void 0, function* () {
38
47
  ShowcaseApp.validateShowcaseContext();
@@ -46,6 +55,11 @@ class ShowcaseApp {
46
55
  }
47
56
  });
48
57
  }
58
+ /**
59
+ * Modifies existing elements in a frame in the showcase.
60
+ * If `frameId` is omitted, elements are modified on the currently active frame.
61
+ * Otherwise, elements are modified on the frame matching `frameId`.
62
+ */
49
63
  static modifyElements(changeObjects, frameId) {
50
64
  ShowcaseApp.validateShowcaseContext();
51
65
  if (changeObjects === null || changeObjects === void 0 ? void 0 : changeObjects.length) {
@@ -53,6 +67,11 @@ class ShowcaseApp {
53
67
  (0, actions_1.getExtensionActions)().sendMessageToHost({ command: ShowcaseCommand.MODIFY_ELEMENTS, data });
54
68
  }
55
69
  }
70
+ /**
71
+ * Changes the showcase's current (visible) frame and resolves with the frame that is now active.
72
+ * Target the frame either by `frameId` or by its 0-based `frameIndex` within `showcase.frames`.
73
+ * The returned promise rejects if the id or index does not match a frame.
74
+ */
56
75
  static navigateToFrame(target) {
57
76
  return __awaiter(this, void 0, void 0, function* () {
58
77
  ShowcaseApp.validateShowcaseContext();
@@ -66,6 +85,7 @@ class ShowcaseApp {
66
85
  return ShowcaseApp.validateAndReturnResults(results);
67
86
  });
68
87
  }
88
+ /** Request the host to bulk-add items to the user's clipboard. */
69
89
  static addItemsToClipboard(clipboardItems) {
70
90
  ShowcaseApp.validateShowcaseContext();
71
91
  if (clipboardItems === null || clipboardItems === void 0 ? void 0 : clipboardItems.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/extensions-sdk",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
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",
@@ -1,7 +0,0 @@
1
- export declare class ExtensionConnectionTimeoutError extends Error {
2
- constructor(timeoutMs: number);
3
- }
4
- export declare class HostConnectionTimeoutError extends Error {
5
- constructor(timeoutMs: number);
6
- }
7
- export declare function withConnectionTimeout<T>(promise: Promise<T>, timeoutMs: number, createError: () => Error): Promise<T>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withConnectionTimeout = exports.HostConnectionTimeoutError = exports.ExtensionConnectionTimeoutError = void 0;
4
- class ExtensionConnectionTimeoutError extends Error {
5
- constructor(timeoutMs) {
6
- super(`Extension connection to host timed out after ${timeoutMs}ms. Ensure the host calls registerHostWithAppExtension after the extension iframe has loaded.`);
7
- this.name = 'ExtensionConnectionTimeoutError';
8
- Object.setPrototypeOf(this, ExtensionConnectionTimeoutError.prototype);
9
- }
10
- }
11
- exports.ExtensionConnectionTimeoutError = ExtensionConnectionTimeoutError;
12
- class HostConnectionTimeoutError extends Error {
13
- constructor(timeoutMs) {
14
- super(`Host connection to extension timed out after ${timeoutMs}ms. Ensure the extension calls registerAppExtension() on load and the iframe has loaded.`);
15
- this.name = 'HostConnectionTimeoutError';
16
- Object.setPrototypeOf(this, HostConnectionTimeoutError.prototype);
17
- }
18
- }
19
- exports.HostConnectionTimeoutError = HostConnectionTimeoutError;
20
- function withConnectionTimeout(promise, timeoutMs, createError) {
21
- return new Promise((resolve, reject) => {
22
- const timer = setTimeout(() => reject(createError()), timeoutMs);
23
- promise
24
- .then((value) => {
25
- clearTimeout(timer);
26
- resolve(value);
27
- })
28
- .catch((err) => {
29
- clearTimeout(timer);
30
- reject(err);
31
- });
32
- });
33
- }
34
- exports.withConnectionTimeout = withConnectionTimeout;