@supernova-studio/client 1.60.2 → 1.60.3

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.
package/dist/index.mjs CHANGED
@@ -19988,6 +19988,174 @@ var TransactionQueue2 = class {
19988
19988
  this.queue.clear();
19989
19989
  }
19990
19990
  };
19991
+
19992
+ // src/test-data-builders/fvp/base.ts
19993
+ import { randomUUID } from "crypto";
19994
+ var TestFVPDataBuilder = class {
19995
+ constructor(input) {
19996
+ __publicField(this, "input");
19997
+ __publicField(this, "collections");
19998
+ __publicField(this, "figmaIdCounter", 0);
19999
+ this.input = input;
20000
+ this.collections = {
20001
+ variableCollections: {},
20002
+ variables: {},
20003
+ variablesOrder: []
20004
+ };
20005
+ }
20006
+ //
20007
+ // Bulk
20008
+ //
20009
+ addBulk(data) {
20010
+ const collection = this.addCollection({
20011
+ collection: data.collection,
20012
+ modes: data.modes
20013
+ });
20014
+ const fullVariables = data.variables.map((v) => {
20015
+ return {
20016
+ ...v,
20017
+ variableCollectionId: collection.id
20018
+ };
20019
+ });
20020
+ const variables = fullVariables.map((v) => this.addVariable(v));
20021
+ return { collection, variables };
20022
+ }
20023
+ //
20024
+ // Collections
20025
+ //
20026
+ addCollection(collectionWithModes) {
20027
+ const { collection, modes } = collectionWithModes;
20028
+ if (!modes.length) {
20029
+ throw SupernovaException.validationError(`At least one mode is required per collection`);
20030
+ }
20031
+ const fullCollection = {
20032
+ ...collection,
20033
+ id: this.nextCollectionId(),
20034
+ modes: [],
20035
+ defaultModeId: "",
20036
+ hiddenFromPublishing: collection.hiddenFromPublishing ?? false,
20037
+ remote: collection.remote ?? false
20038
+ };
20039
+ this.collections.variableCollections[fullCollection.id] = fullCollection;
20040
+ const createdModes = modes.map((m) => this.addModeToCollection(m, fullCollection));
20041
+ fullCollection.defaultModeId = createdModes[0].modeId;
20042
+ return fullCollection;
20043
+ }
20044
+ updateCollection(collectionId, collectionUpdate) {
20045
+ const collection = this.collections.variableCollections[collectionId];
20046
+ if (!collection) throw SupernovaException.notFound(`Collection ${collectionId} was not found`);
20047
+ collection.name = collectionUpdate.name ?? collection.name;
20048
+ }
20049
+ deleteCollection(collectionId) {
20050
+ const deleted = delete this.collections.variableCollections[collectionId];
20051
+ if (!deleted) throw SupernovaException.notFound(`Collection ${collectionId} was not found`);
20052
+ }
20053
+ //
20054
+ // Modes
20055
+ //
20056
+ addMode(mode) {
20057
+ const { collectionId, ...rest } = mode;
20058
+ const collection = this.collections.variableCollections[collectionId];
20059
+ if (!collection) {
20060
+ throw SupernovaException.notFound(`Collection ${collectionId} was not found`);
20061
+ }
20062
+ return this.addModeToCollection(rest, collection);
20063
+ }
20064
+ addModeToCollection(mode, collection) {
20065
+ const fullMode = {
20066
+ ...mode,
20067
+ modeId: this.nextModeId()
20068
+ };
20069
+ collection.modes.push(fullMode);
20070
+ Object.values(this.collections.variables).forEach((v) => {
20071
+ if (v.variableCollectionId !== collection.id) return;
20072
+ const defaultValue = v.valuesByMode[collection.defaultModeId];
20073
+ if (!defaultValue) {
20074
+ throw SupernovaException.shouldNotHappen(`Could not resolve default value for variable ${v.id}`);
20075
+ }
20076
+ v.valuesByMode[fullMode.modeId] = defaultValue;
20077
+ });
20078
+ return fullMode;
20079
+ }
20080
+ //
20081
+ // Variables
20082
+ //
20083
+ addVariable(variable) {
20084
+ const collection = this.collections.variableCollections[variable.variableCollectionId];
20085
+ if (!collection) {
20086
+ const availableCollections = Object.keys(this.collections.variableCollections).join(",");
20087
+ throw SupernovaException.notFound(
20088
+ `Variable ${variable.name} references non-existent collection ${variable.variableCollectionId}, available collections are: [${availableCollections}]. Make sure you've added collection using '.addCollection()' before adding variable to it`
20089
+ );
20090
+ }
20091
+ return this.addVariableToCollection(variable, collection);
20092
+ }
20093
+ updateVariable(variableId, data) {
20094
+ const variable = this.collections.variables[variableId];
20095
+ if (!variable) throw SupernovaException.notFound(`Variable ${variableId} was not found`);
20096
+ variable.scopes = data.scopes ?? variable.scopes;
20097
+ }
20098
+ deleteVariable(variableId) {
20099
+ const deleted = delete this.collections.variables[variableId];
20100
+ if (!deleted) throw SupernovaException.notFound(`Variable ${variableId} was not found`);
20101
+ this.collections.variablesOrder = this.collections.variablesOrder?.filter((id) => id !== variableId);
20102
+ }
20103
+ addVariableToCollection(variable, collection) {
20104
+ const valuesByMode = {};
20105
+ for (const mode of collection.modes) {
20106
+ valuesByMode[mode.modeId] = variable.defaultValue;
20107
+ }
20108
+ const { defaultValue, ...rest } = variable;
20109
+ const fullVariable = {
20110
+ ...rest,
20111
+ id: this.nextVariableId(),
20112
+ description: variable.description ?? "",
20113
+ hiddenFromPublishing: variable.hiddenFromPublishing ?? false,
20114
+ remote: variable.remote ?? false,
20115
+ valuesByMode,
20116
+ key: randomUUID(),
20117
+ scopes: variable.scopes ?? ["ALL_SCOPES"]
20118
+ };
20119
+ this.collections.variables[fullVariable.id] = fullVariable;
20120
+ this.collections.variablesOrder.push(fullVariable.id);
20121
+ return fullVariable;
20122
+ }
20123
+ //
20124
+ // Output
20125
+ //
20126
+ buildPayload(payloadPart = {}) {
20127
+ return {
20128
+ ...payloadPart,
20129
+ isTokenTypeSplitEnabled: payloadPart.isTokenTypeSplitEnabled ?? true,
20130
+ type: "FigmaVariablesPlugin",
20131
+ remoteId: payloadPart.remoteId ?? "test-fvp-source",
20132
+ sourceName: "Test FVP source",
20133
+ brandPersistentId: this.input.brandPersistentId,
20134
+ payload: this.buildCollections()
20135
+ };
20136
+ }
20137
+ buildCollections() {
20138
+ return structuredClone(this.collections);
20139
+ }
20140
+ //
20141
+ // ID Generation
20142
+ //
20143
+ nextModeId() {
20144
+ return this.nextId();
20145
+ }
20146
+ nextCollectionId() {
20147
+ return this.nextId("VariableCollectionId");
20148
+ }
20149
+ nextVariableId() {
20150
+ return this.nextId("VariableID");
20151
+ }
20152
+ nextId(prefix) {
20153
+ let id = `1:${this.figmaIdCounter}`;
20154
+ this.figmaIdCounter++;
20155
+ if (prefix) id = `${prefix}:${id}`;
20156
+ return id;
20157
+ }
20158
+ };
19991
20159
  export {
19992
20160
  BackendFeatureRoomYDoc,
19993
20161
  BackendForgeProjectRoomYDoc,
@@ -20845,6 +21013,7 @@ export {
20845
21013
  StorybookHostingEndpoint,
20846
21014
  StringVariableScopeType,
20847
21015
  SupernovaApiClient,
21016
+ TestFVPDataBuilder,
20848
21017
  ThemesEndpoint,
20849
21018
  ThreadRoomBaseYDoc,
20850
21019
  ThreadsEndpoint,