@supernova-studio/client 1.60.2 → 1.61.0

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
@@ -7018,6 +7018,7 @@ var Variable = z235.object({
7018
7018
  name: z235.string(),
7019
7019
  key: z235.string(),
7020
7020
  variableCollectionId: z235.string(),
7021
+ variableCollectionKey: z235.string().optional(),
7021
7022
  resolvedType: ResolvedVariableType,
7022
7023
  valuesByMode: z235.record(VariableValue),
7023
7024
  remote: z235.boolean(),
@@ -7028,27 +7029,34 @@ var Variable = z235.object({
7028
7029
  });
7029
7030
  var VariableMode = z235.object({
7030
7031
  modeId: z235.string(),
7031
- name: z235.string()
7032
+ name: z235.string(),
7033
+ parentModeId: z235.string().optional()
7032
7034
  });
7033
7035
  var Collection2 = z235.object({
7034
7036
  id: z235.string(),
7035
7037
  name: z235.string(),
7038
+ key: z235.string().optional(),
7036
7039
  modes: z235.array(VariableMode),
7037
7040
  defaultModeId: z235.string(),
7038
7041
  remote: z235.boolean(),
7039
- hiddenFromPublishing: z235.boolean()
7042
+ hiddenFromPublishing: z235.boolean(),
7043
+ isExtension: z235.boolean().optional(),
7044
+ parentVariableCollectionId: z235.string().optional(),
7045
+ parentVariableCollectionKey: z235.string().optional(),
7046
+ variableOverrides: z235.record(z235.string(), z235.record(z235.string(), VariableValue)).optional()
7040
7047
  });
7041
7048
  var VariablesMapping = z235.object({
7042
7049
  variableCollections: z235.array(z235.string()).min(1),
7050
+ variableCollectionKeys: z235.array(z235.string()).optional(),
7043
7051
  variableMode: z235.string().min(1),
7044
7052
  supernovaBrand: z235.string().min(1),
7045
- supernovaTheme: z235.string().min(1).optional().or(z235.null())
7053
+ supernovaTheme: z235.string().min(1).nullable().optional()
7046
7054
  });
7047
7055
  var FormattedCollections = z235.object({
7048
- variables: z235.record(z235.string(), Variable),
7049
7056
  variableCollections: z235.record(z235.string(), Collection2),
7050
- mappings: z235.array(VariablesMapping).optional(),
7051
- variablesOrder: z235.string().array().optional()
7057
+ variables: z235.record(z235.string(), Variable),
7058
+ variablesOrder: z235.string().array().optional(),
7059
+ mappings: z235.array(VariablesMapping).optional()
7052
7060
  });
7053
7061
 
7054
7062
  // src/api/dto/design-systems/file.ts
@@ -19988,6 +19996,174 @@ var TransactionQueue2 = class {
19988
19996
  this.queue.clear();
19989
19997
  }
19990
19998
  };
19999
+
20000
+ // src/test-data-builders/fvp/base.ts
20001
+ import { randomUUID } from "crypto";
20002
+ var TestFVPDataBuilder = class {
20003
+ constructor(input) {
20004
+ __publicField(this, "input");
20005
+ __publicField(this, "collections");
20006
+ __publicField(this, "figmaIdCounter", 0);
20007
+ this.input = input;
20008
+ this.collections = {
20009
+ variableCollections: {},
20010
+ variables: {},
20011
+ variablesOrder: []
20012
+ };
20013
+ }
20014
+ //
20015
+ // Bulk
20016
+ //
20017
+ addBulk(data) {
20018
+ const collection = this.addCollection({
20019
+ collection: data.collection,
20020
+ modes: data.modes
20021
+ });
20022
+ const fullVariables = data.variables.map((v) => {
20023
+ return {
20024
+ ...v,
20025
+ variableCollectionId: collection.id
20026
+ };
20027
+ });
20028
+ const variables = fullVariables.map((v) => this.addVariable(v));
20029
+ return { collection, variables };
20030
+ }
20031
+ //
20032
+ // Collections
20033
+ //
20034
+ addCollection(collectionWithModes) {
20035
+ const { collection, modes } = collectionWithModes;
20036
+ if (!modes.length) {
20037
+ throw SupernovaException.validationError(`At least one mode is required per collection`);
20038
+ }
20039
+ const fullCollection = {
20040
+ ...collection,
20041
+ id: this.nextCollectionId(),
20042
+ modes: [],
20043
+ defaultModeId: "",
20044
+ hiddenFromPublishing: collection.hiddenFromPublishing ?? false,
20045
+ remote: collection.remote ?? false
20046
+ };
20047
+ this.collections.variableCollections[fullCollection.id] = fullCollection;
20048
+ const createdModes = modes.map((m) => this.addModeToCollection(m, fullCollection));
20049
+ fullCollection.defaultModeId = createdModes[0].modeId;
20050
+ return fullCollection;
20051
+ }
20052
+ updateCollection(collectionId, collectionUpdate) {
20053
+ const collection = this.collections.variableCollections[collectionId];
20054
+ if (!collection) throw SupernovaException.notFound(`Collection ${collectionId} was not found`);
20055
+ collection.name = collectionUpdate.name ?? collection.name;
20056
+ }
20057
+ deleteCollection(collectionId) {
20058
+ const deleted = delete this.collections.variableCollections[collectionId];
20059
+ if (!deleted) throw SupernovaException.notFound(`Collection ${collectionId} was not found`);
20060
+ }
20061
+ //
20062
+ // Modes
20063
+ //
20064
+ addMode(mode) {
20065
+ const { collectionId, ...rest } = mode;
20066
+ const collection = this.collections.variableCollections[collectionId];
20067
+ if (!collection) {
20068
+ throw SupernovaException.notFound(`Collection ${collectionId} was not found`);
20069
+ }
20070
+ return this.addModeToCollection(rest, collection);
20071
+ }
20072
+ addModeToCollection(mode, collection) {
20073
+ const fullMode = {
20074
+ ...mode,
20075
+ modeId: this.nextModeId()
20076
+ };
20077
+ collection.modes.push(fullMode);
20078
+ Object.values(this.collections.variables).forEach((v) => {
20079
+ if (v.variableCollectionId !== collection.id) return;
20080
+ const defaultValue = v.valuesByMode[collection.defaultModeId];
20081
+ if (!defaultValue) {
20082
+ throw SupernovaException.shouldNotHappen(`Could not resolve default value for variable ${v.id}`);
20083
+ }
20084
+ v.valuesByMode[fullMode.modeId] = defaultValue;
20085
+ });
20086
+ return fullMode;
20087
+ }
20088
+ //
20089
+ // Variables
20090
+ //
20091
+ addVariable(variable) {
20092
+ const collection = this.collections.variableCollections[variable.variableCollectionId];
20093
+ if (!collection) {
20094
+ const availableCollections = Object.keys(this.collections.variableCollections).join(",");
20095
+ throw SupernovaException.notFound(
20096
+ `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`
20097
+ );
20098
+ }
20099
+ return this.addVariableToCollection(variable, collection);
20100
+ }
20101
+ updateVariable(variableId, data) {
20102
+ const variable = this.collections.variables[variableId];
20103
+ if (!variable) throw SupernovaException.notFound(`Variable ${variableId} was not found`);
20104
+ variable.scopes = data.scopes ?? variable.scopes;
20105
+ }
20106
+ deleteVariable(variableId) {
20107
+ const deleted = delete this.collections.variables[variableId];
20108
+ if (!deleted) throw SupernovaException.notFound(`Variable ${variableId} was not found`);
20109
+ this.collections.variablesOrder = this.collections.variablesOrder?.filter((id) => id !== variableId);
20110
+ }
20111
+ addVariableToCollection(variable, collection) {
20112
+ const valuesByMode = {};
20113
+ for (const mode of collection.modes) {
20114
+ valuesByMode[mode.modeId] = variable.defaultValue;
20115
+ }
20116
+ const { defaultValue, ...rest } = variable;
20117
+ const fullVariable = {
20118
+ ...rest,
20119
+ id: this.nextVariableId(),
20120
+ description: variable.description ?? "",
20121
+ hiddenFromPublishing: variable.hiddenFromPublishing ?? false,
20122
+ remote: variable.remote ?? false,
20123
+ valuesByMode,
20124
+ key: randomUUID(),
20125
+ scopes: variable.scopes ?? ["ALL_SCOPES"]
20126
+ };
20127
+ this.collections.variables[fullVariable.id] = fullVariable;
20128
+ this.collections.variablesOrder.push(fullVariable.id);
20129
+ return fullVariable;
20130
+ }
20131
+ //
20132
+ // Output
20133
+ //
20134
+ buildPayload(payloadPart = {}) {
20135
+ return {
20136
+ ...payloadPart,
20137
+ isTokenTypeSplitEnabled: payloadPart.isTokenTypeSplitEnabled ?? true,
20138
+ type: "FigmaVariablesPlugin",
20139
+ remoteId: payloadPart.remoteId ?? "test-fvp-source",
20140
+ sourceName: "Test FVP source",
20141
+ brandPersistentId: this.input.brandPersistentId,
20142
+ payload: this.buildCollections()
20143
+ };
20144
+ }
20145
+ buildCollections() {
20146
+ return structuredClone(this.collections);
20147
+ }
20148
+ //
20149
+ // ID Generation
20150
+ //
20151
+ nextModeId() {
20152
+ return this.nextId();
20153
+ }
20154
+ nextCollectionId() {
20155
+ return this.nextId("VariableCollectionId");
20156
+ }
20157
+ nextVariableId() {
20158
+ return this.nextId("VariableID");
20159
+ }
20160
+ nextId(prefix) {
20161
+ let id = `1:${this.figmaIdCounter}`;
20162
+ this.figmaIdCounter++;
20163
+ if (prefix) id = `${prefix}:${id}`;
20164
+ return id;
20165
+ }
20166
+ };
19991
20167
  export {
19992
20168
  BackendFeatureRoomYDoc,
19993
20169
  BackendForgeProjectRoomYDoc,
@@ -20845,6 +21021,7 @@ export {
20845
21021
  StorybookHostingEndpoint,
20846
21022
  StringVariableScopeType,
20847
21023
  SupernovaApiClient,
21024
+ TestFVPDataBuilder,
20848
21025
  ThemesEndpoint,
20849
21026
  ThreadRoomBaseYDoc,
20850
21027
  ThreadsEndpoint,