@graphcommerce/hygraph-cli 6.2.0-canary.81 → 6.2.0-canary.83

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @graphcommerce/hygraph-cli
2
2
 
3
+ ## 6.2.0-canary.83
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1938](https://github.com/graphcommerce-org/graphcommerce/pull/1938) [`5aa6558a4`](https://github.com/graphcommerce-org/graphcommerce/commit/5aa6558a4e48d8d670284802fed65a934429b0ea) - Introduce hygraph-cli for schema migrations ([@JoshuaS98](https://github.com/JoshuaS98))
8
+
9
+ ## 6.2.0-canary.82
10
+
3
11
  ## 6.2.0-canary.81
4
12
 
5
13
  ## 6.2.0-canary.80
package/Config.graphqls CHANGED
@@ -26,6 +26,12 @@ extend input GraphCommerceConfig {
26
26
  - Delete existing components
27
27
  - Update remote sources
28
28
  - Delete remote sources
29
+ - Read existing environments
30
+ - Read public content views
31
+ - Create public content views
32
+ - Update public content views
33
+ - Delete public content views
34
+ - Can see schema view
29
35
 
30
36
  ```
31
37
  GC_HYGRAPH_WRITE_ACCESS_ENDPOINT="https://...hygraph.com/v2/..."
@@ -34,4 +40,9 @@ extend input GraphCommerceConfig {
34
40
  ```
35
41
  """
36
42
  hygraphWriteAccessToken: String
43
+
44
+ """
45
+ Hygraph Project ID. **Only used for migrations.**
46
+ """
47
+ hygraphProjectId: String
37
48
  }
package/dist/client.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initClient = void 0;
4
+ const management_sdk_1 = require("@hygraph/management-sdk");
5
+ const log_functions_1 = require("./log-functions");
6
+ const initClient = (config, name) => {
7
+ if (!config.hygraphWriteAccessEndpoint) {
8
+ (0, log_functions_1.graphcommerceLog)('Please provide hygraphWriteAccessEndpoint in your config or GC_HYGRAPH_WRITE_ACCESS_ENDPOINT in your env file', 'error');
9
+ return 0;
10
+ }
11
+ if (!config.hygraphWriteAccessToken) {
12
+ (0, log_functions_1.graphcommerceLog)('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file');
13
+ return 0;
14
+ }
15
+ return new management_sdk_1.Client({
16
+ authToken: config.hygraphWriteAccessToken,
17
+ endpoint: config.hygraphWriteAccessEndpoint,
18
+ name,
19
+ });
20
+ };
21
+ exports.initClient = initClient;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphcommerceLog = exports.capitalize = void 0;
4
+ const capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
5
+ exports.capitalize = capitalize;
6
+ const graphcommerceLog = (message, type) => {
7
+ const color = {
8
+ error: '\x1b[31m\x1b[1m%s\x1b[0m',
9
+ warning: '\x1b[33m\x1b[1m%s\x1b[0m',
10
+ info: '\x1b[36m\x1b[1m%s\x1b[0m',
11
+ };
12
+ // eslint-disable-next-line no-console
13
+ console.log(type ? color[type] : '', `[GraphCommerce]: ${message}`);
14
+ };
15
+ exports.graphcommerceLog = graphcommerceLog;
@@ -1,68 +1,96 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.migrateHygraph = void 0;
7
- /* eslint-disable no-console */
8
- /* eslint-disable import/no-extraneous-dependencies */
9
- const readline_1 = __importDefault(require("readline"));
10
- const dynamicRow_1 = require("./migrations/dynamicRow");
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const next_config_1 = require("@graphcommerce/next-config");
32
+ const dotenv_1 = __importDefault(require("dotenv"));
33
+ const prompts_1 = __importDefault(require("prompts"));
34
+ const log_functions_1 = require("./log-functions");
35
+ const migrations = __importStar(require("./migrations"));
36
+ const readSchema_1 = require("./readSchema");
37
+ dotenv_1.default.config();
11
38
  async function migrateHygraph() {
12
- let forceRun = false;
13
- // Interface to determine if force run should be enabled
14
- readline_1.default.createInterface({
15
- input: process.stdin,
16
- output: process.stdout,
17
- });
18
- const affirmativeAnswers = ['y', 'yes', 'Y', 'YES'];
19
- const handleKeypress = (key) => {
20
- if (affirmativeAnswers.includes(key.toLowerCase())) {
21
- console.log('\nForce run enabled');
22
- forceRun = true;
23
- }
24
- else {
25
- console.log('\nForce run disabled');
26
- forceRun = false;
27
- }
28
- process.stdin.pause();
39
+ const config = (0, next_config_1.loadConfig)(process.cwd());
40
+ /**
41
+ * Extracting the current GC version. Are we gonna use the current version to determine which
42
+ * scripts should be runned? Or do we let the user pick the migration from a list? 🤔
43
+ */
44
+ const packageJson = fs_1.default.readFileSync('package.json', 'utf8');
45
+ const packageData = JSON.parse(packageJson);
46
+ const graphcommerceVersion = packageData.dependencies['@graphcommerce/next-ui'];
47
+ (0, log_functions_1.graphcommerceLog)(`Graphcommerce version: ${graphcommerceVersion}`, 'info');
48
+ // Extract the currently existing models, components and enumerations from the Hygraph schema.
49
+ const schemaViewer = await (0, readSchema_1.readSchema)(config);
50
+ const schema = schemaViewer.viewer.project.environment.contentModel;
51
+ // A list of possible migrations
52
+ const possibleMigrations = Object.entries(migrations);
53
+ // Here we setup the list we ask the user to choose from
54
+ const selectMigrationInput = {
55
+ type: 'select',
56
+ name: 'selectedMigration',
57
+ message: '\x1b[36m\x1b[1m[GraphCommerce]: Select migration',
58
+ choices: [],
29
59
  };
30
- // Listen for keypress events
31
- process.stdin.on('keypress', handleKeypress);
32
- process.stdin.setRawMode(true);
33
- process.stdin.resume();
34
- console.log('Enable force run? (y/n)');
35
- // Wait for input
36
- await new Promise((resolve) => {
37
- process.stdin.once('data', () => {
38
- // Stop listening for input
39
- process.stdin.removeListener('keypress', handleKeypress);
40
- process.stdin.setRawMode(false);
41
- resolve();
42
- });
43
- });
44
- // TODO: Choose migration
45
- // TODO: GC-Version based migration
46
- const possibleMigrations = [
47
- ['add_dynamic_rows', dynamicRow_1.dynamicRow],
48
- ];
49
60
  for (const [name, migration] of possibleMigrations) {
61
+ if (Array.isArray(selectMigrationInput.choices)) {
62
+ selectMigrationInput?.choices?.push({ title: name, value: { name, migration } });
63
+ }
64
+ }
65
+ // Here we ask the user to choose a migration from a list of possible migrations
66
+ try {
67
+ (0, log_functions_1.graphcommerceLog)('Available migrations: ', 'info');
68
+ const selectMigrationOutput = await (0, prompts_1.default)(selectMigrationInput);
69
+ const { migration, name } = selectMigrationOutput.selectedMigration;
70
+ (0, log_functions_1.graphcommerceLog)(`You have selected the ${selectMigrationOutput.selectedMigration.name} migration`, 'info');
50
71
  try {
72
+ // Here we try to run the migration
51
73
  // eslint-disable-next-line no-await-in-loop
52
- const result = await migration(forceRun ? undefined : name);
53
- console.log(result);
74
+ const result = await migration(schema);
75
+ (0, log_functions_1.graphcommerceLog)(`Migration result: ${JSON.stringify(result)}`, 'info');
76
+ if (!result) {
77
+ throw new Error('[GraphCommerce]: No migration client found. Please make sure your GC_HYGRAPH_WRITE_ACCESS_ENDPOINT and GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file are correct.');
78
+ }
54
79
  if (result.status !== 'SUCCESS') {
55
- throw new Error(`Migration not successful: ${result.status} ${name}:\n${result.errors}`);
80
+ throw new Error(`[GraphCommerce]: Migration not successful: ${result.status} ${name}:\n${result.errors}`);
56
81
  }
57
- console.log(`Migration successful: ${name}`);
82
+ (0, log_functions_1.graphcommerceLog)(`Migration successful: ${name}`, 'info');
58
83
  }
59
84
  catch (err) {
60
85
  if (err instanceof Error) {
61
86
  const garbledErrorIndex = err.message.indexOf(': {"');
62
87
  const msg = garbledErrorIndex > 0 ? err.message.slice(0, garbledErrorIndex) : err.message;
63
- console.error(msg);
88
+ (0, log_functions_1.graphcommerceLog)(`${msg}`, 'error');
64
89
  }
65
90
  }
66
91
  }
92
+ catch (error) {
93
+ (0, log_functions_1.graphcommerceLog)(`[GraphCommerce]: An error occurred: ${error}`, 'error');
94
+ }
67
95
  }
68
96
  exports.migrateHygraph = migrateHygraph;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.migrationAction = exports.client = void 0;
7
+ const next_config_1 = require("@graphcommerce/next-config");
8
+ const dotenv_1 = __importDefault(require("dotenv"));
9
+ const client_1 = require("./client");
10
+ const log_functions_1 = require("./log-functions");
11
+ dotenv_1.default.config();
12
+ const config = (0, next_config_1.loadConfig)(process.cwd());
13
+ exports.client = (0, client_1.initClient)(config, undefined);
14
+ /**
15
+ * This constant is used to assign the right action of the management SDK to the migratioAction
16
+ * function
17
+ */
18
+ const actionMap = exports.client
19
+ ? {
20
+ create: {
21
+ model: (innerprops) => exports.client.createModel(innerprops),
22
+ component: (innerprops) => exports.client.createComponent(innerprops),
23
+ enumeration: (innerprops) => exports.client.createEnumeration(innerprops),
24
+ simpleField: (innerprops) => exports.client.createSimpleField(innerprops),
25
+ enumerableField: (innerprops) => exports.client.createEnumerableField(innerprops),
26
+ componentField: (innerprops) => exports.client.createComponentField(innerprops),
27
+ relationalField: (innerprops) => exports.client.createRelationalField(innerprops),
28
+ unionField: (innerprops) => exports.client.createUnionField(innerprops),
29
+ componentUnionField: (innerprops) => exports.client.createComponentUnionField(innerprops),
30
+ },
31
+ update: {
32
+ model: (innerprops) => exports.client.updateModel(innerprops),
33
+ component: (innerprops) => exports.client.updateComponent(innerprops),
34
+ enumeration: (innerprops) => exports.client.updateEnumeration(innerprops),
35
+ simpleField: (innerprops) => exports.client.updateSimpleField(innerprops),
36
+ enumerableField: (innerprops) => exports.client.updateEnumerableField(innerprops),
37
+ componentField: (innerprops) => exports.client.updateComponentField(innerprops),
38
+ relationalField: (innerprops) => exports.client.updateRelationalField(innerprops),
39
+ unionField: (innerprops) => exports.client.updateUnionField(innerprops),
40
+ componentUnionField: (innerprops) => exports.client.updateComponentUnionField(innerprops),
41
+ },
42
+ delete: {
43
+ model: (innerprops) => exports.client.deleteModel(innerprops),
44
+ component: (innerprops) => exports.client.deleteComponent(innerprops),
45
+ enumeration: (innerprops) => exports.client.deleteEnumeration(innerprops),
46
+ simpleField: (innerprops) => exports.client.deleteField(innerprops),
47
+ enumerableField: (innerprops) => exports.client.deleteField(innerprops),
48
+ componentField: (innerprops) => exports.client.deleteField(innerprops),
49
+ relationalField: (innerprops) => exports.client.deleteField(innerprops),
50
+ unionField: (innerprops) => exports.client.deleteField(innerprops),
51
+ componentUnionField: (innerprops) => exports.client.deleteField(innerprops),
52
+ },
53
+ }
54
+ : undefined;
55
+ /**
56
+ * This function is our variation on the client.migrationAction functions from the hygraph
57
+ * management sdk.
58
+ *
59
+ * MigrationAction() is better suited because it is a single function for all actions. More
60
+ * importantly, if the action fails, because a field with the apiID already exists for instance. it
61
+ * will skip this action but still continue the whole migration, while the management sdk function
62
+ * will bail.
63
+ *
64
+ * It takes the schema as argument, which is always the same.
65
+ *
66
+ * Then it takes the type of schema entity you want to do an action upon, and the action you want to
67
+ * do.
68
+ *
69
+ * The fourth arguments are the props that belong to the action you want to do. For instance, if you
70
+ * want to create a model, you need to pass the props that belong to a model.
71
+ *
72
+ * The last two arguments are optional. If you want to create a field, you need to pass the apiId of
73
+ * the model or component you want to create the field on. If you want to create a field on a
74
+ * component, you also need to pass the parentType, which is either 'model' or 'component'.
75
+ */
76
+ const migrationAction = (schema, type, action, props, parentApiId, parentType) => {
77
+ // Check if the entity already exists
78
+ const alreadyExists = () => {
79
+ switch (type) {
80
+ case 'model':
81
+ return schema.models.some((model) => model.apiId === props.apiId);
82
+ case 'component':
83
+ return schema.components.some((component) => component.apiId === props.apiId);
84
+ case 'enumeration':
85
+ return schema.enumerations.some((enumeration) => enumeration.apiId === props.apiId);
86
+ case 'simpleField':
87
+ case 'enumerableField':
88
+ case 'relationalField':
89
+ case 'unionField':
90
+ case 'componentUnionField': {
91
+ let parent;
92
+ switch (parentType) {
93
+ case 'model': {
94
+ parent = schema.models.find((model) => model.apiId === parentApiId);
95
+ break;
96
+ }
97
+ case 'component': {
98
+ parent = schema.components.find((component) => component.apiId === parentApiId);
99
+ break;
100
+ }
101
+ default:
102
+ return false; // or undefined or any other value you want if no match
103
+ }
104
+ return parent?.fields.some((field) => field.apiId === props.apiId);
105
+ }
106
+ default: {
107
+ return false; // or undefined or any other value you want if no match
108
+ }
109
+ }
110
+ };
111
+ const actionFunc = actionMap && actionMap[action] && actionMap[action][type];
112
+ if (!alreadyExists()) {
113
+ if (actionFunc) {
114
+ (0, log_functions_1.graphcommerceLog)(`${(0, log_functions_1.capitalize)(action)} ${type} with apiId ${props.apiId}...`);
115
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
116
+ // @ts-ignore | This error is a loss on typescript autocomplete, but the function is called correctly
117
+ actionFunc(props);
118
+ }
119
+ else {
120
+ (0, log_functions_1.graphcommerceLog)(`Action ${action} is not supported for ${type}`, 'error');
121
+ }
122
+ }
123
+ else {
124
+ (0, log_functions_1.graphcommerceLog)(`${(0, log_functions_1.capitalize)(type)} with apiId ${props.apiId} on ${parentApiId} already exists`, 'warning');
125
+ }
126
+ };
127
+ exports.migrationAction = migrationAction;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphcommerce5to6 = void 0;
4
+ const management_sdk_1 = require("@hygraph/management-sdk");
5
+ const migrationAction_1 = require("../migrationAction");
6
+ const graphcommerce5to6 = async (schema) => {
7
+ if (!migrationAction_1.client) {
8
+ return 0;
9
+ }
10
+ // ? ENUMERATIONS
11
+ (0, migrationAction_1.migrationAction)(schema, 'enumeration', 'create', {
12
+ displayName: 'Row Links Variants',
13
+ apiId: 'RowLinksVariants',
14
+ values: [
15
+ { displayName: 'Inline', apiId: 'Inline' },
16
+ { displayName: 'Image Label Swiper', apiId: 'ImageLabelSwiper' },
17
+ { displayName: 'Logo Swiper', apiId: 'LogoSwiper' },
18
+ { displayName: 'USPS', apiId: 'Usps' },
19
+ ],
20
+ });
21
+ // ? MODEL
22
+ (0, migrationAction_1.migrationAction)(schema, 'model', 'create', {
23
+ apiId: 'RowLinks',
24
+ apiIdPlural: 'RowLinksMultiple',
25
+ displayName: 'Row Links',
26
+ description: 'Row Links is a Row of PageLinks with different variants',
27
+ });
28
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
29
+ displayName: 'Identity',
30
+ apiId: 'identity',
31
+ description: 'Only used for internal reference',
32
+ type: management_sdk_1.SimpleFieldType.String,
33
+ isTitle: true,
34
+ isRequired: true,
35
+ isUnique: true,
36
+ modelApiId: 'RowLinks',
37
+ }, 'RowLinks', 'model');
38
+ (0, migrationAction_1.migrationAction)(schema, 'enumerableField', 'create', {
39
+ displayName: 'Variant',
40
+ apiId: 'linksVariant',
41
+ parentApiId: 'RowLinks',
42
+ enumerationApiId: 'RowLinksVariants',
43
+ description: 'Different variants for Row Links',
44
+ }, 'RowLinks', 'model');
45
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
46
+ displayName: 'Title',
47
+ apiId: 'title',
48
+ type: management_sdk_1.SimpleFieldType.String,
49
+ isRequired: true,
50
+ modelApiId: 'RowLinks',
51
+ isLocalized: true,
52
+ }, 'RowLinks', 'model');
53
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
54
+ displayName: 'Copy',
55
+ apiId: 'rowLinksCopy',
56
+ type: management_sdk_1.SimpleFieldType.Richtext,
57
+ isLocalized: true,
58
+ modelApiId: 'RowLinks',
59
+ }, 'RowLinks', 'model');
60
+ (0, migrationAction_1.migrationAction)(schema, 'relationalField', 'create', {
61
+ displayName: 'Links',
62
+ apiId: 'pageLinks',
63
+ modelApiId: 'RowLinks',
64
+ type: management_sdk_1.RelationalFieldType.Relation,
65
+ reverseField: {
66
+ apiId: 'rowLinks',
67
+ modelApiId: 'PageLink',
68
+ displayName: 'RowLinks',
69
+ visibility: management_sdk_1.VisibilityTypes.Hidden,
70
+ isList: true,
71
+ },
72
+ visibility: management_sdk_1.VisibilityTypes.ReadWrite,
73
+ isList: true,
74
+ }, 'RowLinks', 'model');
75
+ (0, migrationAction_1.migrationAction)(schema, 'unionField', 'update', {
76
+ apiId: 'content',
77
+ displayName: 'Content',
78
+ modelApiId: 'Page',
79
+ reverseField: {
80
+ modelApiIds: [
81
+ 'RowLinks',
82
+ 'RowServiceOptions',
83
+ 'RowSpecialBanner',
84
+ 'RowQuote',
85
+ 'RowProduct',
86
+ 'RowColumnOne',
87
+ 'RowColumnTwo',
88
+ 'RowColumnThree',
89
+ 'RowHeroBanner',
90
+ 'RowBlogContent',
91
+ 'RowButtonList',
92
+ 'RowContentLinks',
93
+ 'RowButtonLinkList',
94
+ ],
95
+ // visibility: VisibilityTypes.Hidden, => Currently not supported for updateUnionField | https://github.com/hygraph/management-sdk/issues/34
96
+ },
97
+ }, 'Page', 'model');
98
+ return migrationAction_1.client.run(true);
99
+ };
100
+ exports.graphcommerce5to6 = graphcommerce5to6;
@@ -1,28 +1,22 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.dynamicRow = void 0;
7
- const next_config_1 = require("@graphcommerce/next-config");
3
+ exports.graphcommerce6to7 = void 0;
8
4
  const management_sdk_1 = require("@hygraph/management-sdk");
9
- const dotenv_1 = __importDefault(require("dotenv"));
10
- dotenv_1.default.config();
11
- const dynamicRow = async (name) => {
12
- const config = (0, next_config_1.loadConfig)(process.cwd());
13
- if (!config.hygraphWriteAccessEndpoint) {
14
- throw new Error('Please provide hygraphWriteAccessEndpoint in your config or GC_HYGRAPH_WRITE_ACCESS_ENDPOINT in your env');
15
- }
16
- if (!config.hygraphWriteAccessToken) {
17
- throw new Error('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env');
5
+ const migrationAction_1 = require("../migrationAction");
6
+ const graphcommerce6to7 = async (schema) => {
7
+ if (!migrationAction_1.client) {
8
+ return 0;
18
9
  }
19
- const client = new management_sdk_1.Client({
20
- authToken: config.hygraphWriteAccessToken,
21
- endpoint: config.hygraphWriteAccessEndpoint,
22
- name,
23
- });
24
10
  // ? ENUMERATIONS
25
- client.createEnumeration({
11
+ (0, migrationAction_1.migrationAction)(schema, 'enumeration', 'create', {
12
+ displayName: 'Row Column One Variants',
13
+ apiId: 'RowColumnOneVariants',
14
+ values: [
15
+ { displayName: 'Default', apiId: 'Default' },
16
+ { displayName: 'Message', apiId: 'Message' },
17
+ ],
18
+ });
19
+ (0, migrationAction_1.migrationAction)(schema, 'enumeration', 'create', {
26
20
  displayName: 'Dynamic Row Condition Number Operator',
27
21
  apiId: 'DynamicRowConditionNumberOperator',
28
22
  values: [
@@ -31,7 +25,7 @@ const dynamicRow = async (name) => {
31
25
  { displayName: 'Equal to', apiId: 'EQUAL' },
32
26
  ],
33
27
  });
34
- client.createEnumeration({
28
+ (0, migrationAction_1.migrationAction)(schema, 'enumeration', 'create', {
35
29
  displayName: 'Dynamic Row Placement',
36
30
  apiId: 'DynamicRowPlacement',
37
31
  values: [
@@ -41,43 +35,36 @@ const dynamicRow = async (name) => {
41
35
  ],
42
36
  });
43
37
  // ? COMPONENTS
44
- client.createComponent({
38
+ (0, migrationAction_1.migrationAction)(schema, 'component', 'create', {
45
39
  displayName: 'Text',
46
40
  apiId: 'ConditionText',
47
41
  apiIdPlural: 'ConditionTexts',
48
42
  });
49
- client.createComponent({
43
+ (0, migrationAction_1.migrationAction)(schema, 'component', 'create', {
50
44
  displayName: 'Number',
51
45
  apiId: 'ConditionNumber',
52
46
  apiIdPlural: 'ConditionNumbers',
53
47
  });
54
- client.createComponent({
48
+ (0, migrationAction_1.migrationAction)(schema, 'component', 'create', {
55
49
  displayName: 'AND',
56
50
  apiId: 'ConditionAnd',
57
51
  apiIdPlural: 'ConditionAnds',
58
52
  description: 'All of these conditions must match',
59
53
  });
60
- client.createComponent({
54
+ (0, migrationAction_1.migrationAction)(schema, 'component', 'create', {
61
55
  displayName: 'OR',
62
56
  apiId: 'ConditionOr',
63
57
  apiIdPlural: 'ConditionOrs',
64
58
  description: 'One of these conditions must match',
65
59
  });
66
- client.createComponentUnionField({
60
+ (0, migrationAction_1.migrationAction)(schema, 'componentUnionField', 'create', {
67
61
  displayName: 'Conditions',
68
62
  apiId: 'conditions',
69
63
  parentApiId: 'ConditionAnd',
70
64
  componentApiIds: ['ConditionOr', 'ConditionText', 'ConditionNumber'],
71
65
  isList: true,
72
- });
73
- client.createComponentUnionField({
74
- displayName: 'Conditions',
75
- apiId: 'conditions',
76
- parentApiId: 'ConditionOr',
77
- componentApiIds: ['ConditionText', 'ConditionNumber'],
78
- isList: true,
79
- });
80
- client.createSimpleField({
66
+ }, 'ConditionAnd', 'component');
67
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
81
68
  displayName: 'Property',
82
69
  apiId: 'property',
83
70
  type: management_sdk_1.SimpleFieldType.String,
@@ -93,15 +80,15 @@ const dynamicRow = async (name) => {
93
80
  },
94
81
  },
95
82
  },
96
- });
97
- client.createSimpleField({
83
+ }, 'ConditionText', 'component');
84
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
98
85
  displayName: 'Value',
99
86
  apiId: 'value',
100
87
  type: management_sdk_1.SimpleFieldType.String,
101
88
  parentApiId: 'ConditionText',
102
89
  isRequired: true,
103
- });
104
- client.createSimpleField({
90
+ }, 'ConditionText', 'component');
91
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
105
92
  displayName: 'Property',
106
93
  apiId: 'property',
107
94
  type: management_sdk_1.SimpleFieldType.String,
@@ -116,29 +103,29 @@ const dynamicRow = async (name) => {
116
103
  },
117
104
  },
118
105
  },
119
- });
120
- client.createEnumerableField({
106
+ }, 'ConditionNumber', 'component');
107
+ (0, migrationAction_1.migrationAction)(schema, 'enumerableField', 'create', {
121
108
  displayName: 'Operator',
122
109
  apiId: 'operator',
123
110
  parentApiId: 'ConditionNumber',
124
111
  enumerationApiId: 'DynamicRowConditionNumberOperator',
125
112
  isRequired: true,
126
- });
127
- client.createSimpleField({
113
+ }, 'ConditionNumber', 'component');
114
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
128
115
  displayName: 'Value',
129
116
  apiId: 'value',
130
117
  type: management_sdk_1.SimpleFieldType.Float,
131
118
  parentApiId: 'ConditionNumber',
132
119
  isRequired: true,
133
- });
120
+ }, 'ConditionNumber', 'component');
134
121
  // ? MODEL
135
- client.createModel({
122
+ (0, migrationAction_1.migrationAction)(schema, 'model', 'create', {
123
+ displayName: 'Dynamic Row',
136
124
  apiId: 'DynamicRow',
137
125
  apiIdPlural: 'DynamicRows',
138
- displayName: 'Dynamic Row',
139
126
  description: 'Dynamic rows allow you to add specific Row models to pages based on the properties of the page',
140
127
  });
141
- client.createSimpleField({
128
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
142
129
  displayName: 'Internal name',
143
130
  apiId: 'internalName',
144
131
  description: 'Only used for internal reference',
@@ -147,8 +134,8 @@ const dynamicRow = async (name) => {
147
134
  isRequired: true,
148
135
  isUnique: true,
149
136
  modelApiId: 'DynamicRow',
150
- });
151
- client.createUnionField({
137
+ }, 'DynamicRow', 'model');
138
+ (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', {
152
139
  displayName: 'Row',
153
140
  apiId: 'row',
154
141
  reverseField: {
@@ -159,16 +146,16 @@ const dynamicRow = async (name) => {
159
146
  isList: true,
160
147
  },
161
148
  parentApiId: 'DynamicRow',
162
- });
163
- client.createEnumerableField({
149
+ }, 'DynamicRow', 'model');
150
+ (0, migrationAction_1.migrationAction)(schema, 'enumerableField', 'create', {
164
151
  displayName: 'Placement',
165
152
  apiId: 'placement',
166
153
  parentApiId: 'DynamicRow',
167
154
  enumerationApiId: 'DynamicRowPlacement',
168
155
  description: 'Where will the row be placed relative to the target',
169
156
  isRequired: true,
170
- });
171
- client.createUnionField({
157
+ }, 'DynamicRow', 'model');
158
+ (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', {
172
159
  displayName: 'Placement target',
173
160
  apiId: 'target',
174
161
  description: 'Optional: When the target is left blank it will place the Dynamic Row on the start or end.',
@@ -193,15 +180,22 @@ const dynamicRow = async (name) => {
193
180
  isList: true,
194
181
  },
195
182
  parentApiId: 'DynamicRow',
196
- });
197
- client.createComponentUnionField({
183
+ }, 'DynamicRow', 'model');
184
+ (0, migrationAction_1.migrationAction)(schema, 'componentUnionField', 'create', {
198
185
  displayName: 'Conditions (OR)',
199
186
  apiId: 'conditions',
200
187
  parentApiId: 'DynamicRow',
201
188
  description: 'One of these conditions must match',
202
189
  componentApiIds: ['ConditionAnd', 'ConditionText', 'ConditionNumber'],
203
190
  isList: true,
204
- });
205
- return client.run(true);
191
+ }, 'DynamicRow', 'model');
192
+ // ? Row Column One
193
+ (0, migrationAction_1.migrationAction)(schema, 'enumerableField', 'create', {
194
+ displayName: 'Variant',
195
+ apiId: 'rowColumnOneVariant',
196
+ enumerationApiId: 'RowColumnOneVariants',
197
+ parentApiId: 'RowColumnOne',
198
+ }, 'RowColumnOne', 'model');
199
+ return migrationAction_1.client.run(true);
206
200
  };
207
- exports.dynamicRow = dynamicRow;
201
+ exports.graphcommerce6to7 = graphcommerce6to7;