@graphcommerce/hygraph-cli 9.0.4-canary.1 → 9.0.4-canary.10
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 +22 -0
- package/dist/index.js +928 -5
- package/package.json +17 -12
- package/tsconfig.json +2 -2
- package/dist/UpsertClient.js +0 -80
- package/dist/migrateHygraphCli.js +0 -88
- package/dist/migrationActionFactory.js +0 -133
- package/dist/migrations/graphcommerce5to6.js +0 -98
- package/dist/migrations/graphcommerce6to7.js +0 -206
- package/dist/migrations/graphcommerce7to8.js +0 -41
- package/dist/migrations/graphcommerce8to9.js +0 -68
- package/dist/migrations/index.js +0 -13
- package/dist/readSchema.js +0 -50
- package/dist/types.js +0 -2
- package/dist/utils/getConfig.js +0 -19
- package/dist/utils/getEndpointUrl.js +0 -43
- package/dist/utils/getManagementClient.js +0 -15
- package/dist/utils/graphCommerceLog.js +0 -15
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.graphcommerce7to8 = void 0;
|
|
4
|
-
const management_sdk_1 = require("@hygraph/management-sdk");
|
|
5
|
-
const migrationActionFactory_1 = require("../migrationActionFactory");
|
|
6
|
-
const graphcommerce7to8 = async (schema, client) => {
|
|
7
|
-
const { migrationAction } = (0, migrationActionFactory_1.migrationActionFactory)(schema, client);
|
|
8
|
-
const hasRow = schema.models
|
|
9
|
-
.find((m) => m.apiId === 'DynamicRow')
|
|
10
|
-
?.fields.some((f) => f.apiId === 'row');
|
|
11
|
-
if (hasRow) {
|
|
12
|
-
migrationAction(schema, 'unionField', 'update', {
|
|
13
|
-
apiId: 'row',
|
|
14
|
-
displayName: 'Row Deprecated',
|
|
15
|
-
parentApiId: 'DynamicRow',
|
|
16
|
-
description: 'This field is deprecated. Use Rows instead.',
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
migrationAction(schema, 'unionField', 'create', {
|
|
20
|
-
displayName: 'Rows',
|
|
21
|
-
apiId: 'rows',
|
|
22
|
-
isList: true,
|
|
23
|
-
reverseField: {
|
|
24
|
-
modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'],
|
|
25
|
-
apiId: 'dynamicRows',
|
|
26
|
-
displayName: 'Dynamic Rows',
|
|
27
|
-
visibility: management_sdk_1.VisibilityTypes.Hidden,
|
|
28
|
-
isList: true,
|
|
29
|
-
},
|
|
30
|
-
parentApiId: 'DynamicRow',
|
|
31
|
-
}, 'DynamicRow', 'model');
|
|
32
|
-
migrationAction(schema, 'componentUnionField', 'create', {
|
|
33
|
-
displayName: 'Conditions',
|
|
34
|
-
apiId: 'conditions',
|
|
35
|
-
parentApiId: 'ConditionOr',
|
|
36
|
-
componentApiIds: ['ConditionText', 'ConditionNumber'],
|
|
37
|
-
isList: true,
|
|
38
|
-
}, 'ConditionOr', 'component');
|
|
39
|
-
return client.run(true);
|
|
40
|
-
};
|
|
41
|
-
exports.graphcommerce7to8 = graphcommerce7to8;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.graphcommerce8to9 = void 0;
|
|
4
|
-
const management_sdk_1 = require("@hygraph/management-sdk");
|
|
5
|
-
const migrationActionFactory_1 = require("../migrationActionFactory");
|
|
6
|
-
const graphcommerce8to9 = async (schema, client) => {
|
|
7
|
-
const { migrationAction } = (0, migrationActionFactory_1.migrationActionFactory)(schema, client);
|
|
8
|
-
// Removes the deprecated 'Row' field which was deprecated in GC@7.1
|
|
9
|
-
const hasRow = schema.models
|
|
10
|
-
.find((m) => m.apiId === 'DynamicRow')
|
|
11
|
-
?.fields.some((f) => f.apiId === 'row');
|
|
12
|
-
if (hasRow) {
|
|
13
|
-
migrationAction(schema, 'simpleField', 'delete', {
|
|
14
|
-
apiId: 'row',
|
|
15
|
-
parentApiId: 'DynamicRow',
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const hasRowCategory = schema.models.some((m) => m.apiId === 'RowCategory');
|
|
19
|
-
//
|
|
20
|
-
if (!hasRowCategory) {
|
|
21
|
-
migrationAction(schema, 'model', 'create', {
|
|
22
|
-
apiId: 'RowCategory',
|
|
23
|
-
displayName: 'Row Category',
|
|
24
|
-
apiIdPlural: 'RowProductLists',
|
|
25
|
-
description: 'A model that displays a category',
|
|
26
|
-
});
|
|
27
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
28
|
-
position: 1,
|
|
29
|
-
type: management_sdk_1.SimpleFieldType.String,
|
|
30
|
-
formConfig: { renderer: 'GCMS_SLUG', config: { isLowercase: true } },
|
|
31
|
-
validations: {
|
|
32
|
-
String: {
|
|
33
|
-
matches: {
|
|
34
|
-
regex: '^[a-z0-9]+(?:[-/][a-z0-9]+)*$',
|
|
35
|
-
errorMessage: 'The category URL must be a valid slug',
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
parentApiId: 'RowCategory',
|
|
40
|
-
displayName: 'Category URL',
|
|
41
|
-
apiId: 'categoryUrl',
|
|
42
|
-
description: 'The URL of the category, may include slashes',
|
|
43
|
-
isTitle: true,
|
|
44
|
-
isLocalized: true,
|
|
45
|
-
isRequired: true,
|
|
46
|
-
visibility: management_sdk_1.VisibilityTypes.ReadWrite,
|
|
47
|
-
}, 'RowCategory', 'model');
|
|
48
|
-
migrationAction(schema, 'enumeration', 'create', {
|
|
49
|
-
displayName: 'Row Category Variant',
|
|
50
|
-
apiId: 'RowCategoryVariant',
|
|
51
|
-
values: [
|
|
52
|
-
{ displayName: 'Backstory', apiId: 'Backstory' },
|
|
53
|
-
{ displayName: 'Grid', apiId: 'Grid' },
|
|
54
|
-
{ displayName: 'Swipeable', apiId: 'Swipeable' },
|
|
55
|
-
],
|
|
56
|
-
});
|
|
57
|
-
migrationAction(schema, 'enumerableField', 'create', {
|
|
58
|
-
displayName: 'Variant',
|
|
59
|
-
apiId: 'variant',
|
|
60
|
-
parentApiId: 'RowCategory',
|
|
61
|
-
enumerationApiId: 'RowCategoryVariant',
|
|
62
|
-
description: 'As what variant wil the RowCategory be displayed',
|
|
63
|
-
isRequired: true,
|
|
64
|
-
}, 'RowCategory', 'model');
|
|
65
|
-
}
|
|
66
|
-
return client.run(true);
|
|
67
|
-
};
|
|
68
|
-
exports.graphcommerce8to9 = graphcommerce8to9;
|
package/dist/migrations/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.availableMigrations = void 0;
|
|
4
|
-
const graphcommerce5to6_1 = require("./graphcommerce5to6");
|
|
5
|
-
const graphcommerce6to7_1 = require("./graphcommerce6to7");
|
|
6
|
-
const graphcommerce7to8_1 = require("./graphcommerce7to8");
|
|
7
|
-
const graphcommerce8to9_1 = require("./graphcommerce8to9");
|
|
8
|
-
exports.availableMigrations = [
|
|
9
|
-
graphcommerce5to6_1.graphcommerce5to6,
|
|
10
|
-
graphcommerce6to7_1.graphcommerce6to7,
|
|
11
|
-
graphcommerce7to8_1.graphcommerce7to8,
|
|
12
|
-
graphcommerce8to9_1.graphcommerce8to9,
|
|
13
|
-
];
|
package/dist/readSchema.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readSchema = void 0;
|
|
4
|
-
const client_1 = require("@apollo/client");
|
|
5
|
-
const readSchema = async (managementClient, projectId) => {
|
|
6
|
-
const { data } = await managementClient.query({
|
|
7
|
-
query: (0, client_1.gql) `
|
|
8
|
-
query getSchema($projectId: ID!) {
|
|
9
|
-
viewer {
|
|
10
|
-
project(id: $projectId) {
|
|
11
|
-
environment(name: "master") {
|
|
12
|
-
contentModel {
|
|
13
|
-
locales {
|
|
14
|
-
id
|
|
15
|
-
apiId
|
|
16
|
-
}
|
|
17
|
-
stages {
|
|
18
|
-
id
|
|
19
|
-
apiId
|
|
20
|
-
}
|
|
21
|
-
models {
|
|
22
|
-
apiId
|
|
23
|
-
apiIdPlural
|
|
24
|
-
fields {
|
|
25
|
-
apiId
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
components {
|
|
29
|
-
apiId
|
|
30
|
-
apiIdPlural
|
|
31
|
-
fields {
|
|
32
|
-
apiId
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
enumerations {
|
|
36
|
-
apiId
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
`,
|
|
44
|
-
variables: {
|
|
45
|
-
projectId,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
return data;
|
|
49
|
-
};
|
|
50
|
-
exports.readSchema = readSchema;
|
package/dist/types.js
DELETED
package/dist/utils/getConfig.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfig = getConfig;
|
|
4
|
-
function getConfig(config) {
|
|
5
|
-
let { hygraphProjectId: projectId, hygraphWriteAccessToken: authToken, hygraphManagementApi: uri, hygraphEndpoint, } = config;
|
|
6
|
-
if (!authToken) {
|
|
7
|
-
throw new Error('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file.');
|
|
8
|
-
}
|
|
9
|
-
if (!projectId) {
|
|
10
|
-
projectId = new URL(hygraphEndpoint).pathname.split('/')?.[1];
|
|
11
|
-
}
|
|
12
|
-
if (!uri) {
|
|
13
|
-
const endpoint = new URL(hygraphEndpoint);
|
|
14
|
-
endpoint.hostname = `management-${endpoint.hostname}`.replace('.cdn', '');
|
|
15
|
-
endpoint.pathname = 'graphql';
|
|
16
|
-
uri = endpoint.toString();
|
|
17
|
-
}
|
|
18
|
-
return { projectId, authToken, uri };
|
|
19
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
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.getEnvironment = getEnvironment;
|
|
7
|
-
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
-
async function getEnvironment(client, config) {
|
|
9
|
-
const endpoints = await client.query({
|
|
10
|
-
query: (0, graphql_tag_1.default) `
|
|
11
|
-
query Environments($projectId: ID!) {
|
|
12
|
-
viewer {
|
|
13
|
-
id
|
|
14
|
-
project(id: $projectId) {
|
|
15
|
-
environments {
|
|
16
|
-
name
|
|
17
|
-
endpoint
|
|
18
|
-
migrations {
|
|
19
|
-
name
|
|
20
|
-
status
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
`,
|
|
27
|
-
variables: { projectId: config.projectId },
|
|
28
|
-
errorPolicy: 'all',
|
|
29
|
-
});
|
|
30
|
-
if (endpoints.errors) {
|
|
31
|
-
const isBadInput = endpoints.errors.some((e) => e.extensions?.code === 'BAD_USER_INPUT');
|
|
32
|
-
if (isBadInput) {
|
|
33
|
-
throw Error(`
|
|
34
|
-
Could not find environment for projectId ${config.projectId}.
|
|
35
|
-
Please check your GC_HYGRAPH_PROJECT_ID in your env file.
|
|
36
|
-
`);
|
|
37
|
-
}
|
|
38
|
-
throw new Error(`An error occurred: ${endpoints.errors.map((e) => e.message).join('\n')}`);
|
|
39
|
-
}
|
|
40
|
-
const environment = endpoints.data.viewer.project.environments.find((env) => env.name === 'master') ??
|
|
41
|
-
endpoints.data.viewer.project.environments?.[0];
|
|
42
|
-
return environment;
|
|
43
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getManagementClient = getManagementClient;
|
|
4
|
-
const client_1 = require("@apollo/client");
|
|
5
|
-
function getManagementClient(config) {
|
|
6
|
-
const { authToken: accessToken, uri } = config;
|
|
7
|
-
return new client_1.ApolloClient({
|
|
8
|
-
link: new client_1.HttpLink({
|
|
9
|
-
uri,
|
|
10
|
-
fetch,
|
|
11
|
-
headers: { Authorization: `Bearer ${accessToken}` },
|
|
12
|
-
}),
|
|
13
|
-
cache: new client_1.InMemoryCache(),
|
|
14
|
-
});
|
|
15
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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] : '', `${message}`);
|
|
14
|
-
};
|
|
15
|
-
exports.graphcommerceLog = graphcommerceLog;
|