@vendure/testing 3.0.5 → 3.0.6
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/lib/simple-graphql-client.d.ts +29 -0
- package/lib/simple-graphql-client.js +59 -30
- package/lib/simple-graphql-client.js.map +1 -1
- package/lib/utils/create-upload-post-data.d.ts +49 -5
- package/lib/utils/create-upload-post-data.js +42 -23
- package/lib/utils/create-upload-post-data.js.map +1 -1
- package/package.json +6 -5
|
@@ -70,7 +70,36 @@ export declare class SimpleGraphQLClient {
|
|
|
70
70
|
* Perform a file upload mutation.
|
|
71
71
|
*
|
|
72
72
|
* Upload spec: https://github.com/jaydenseric/graphql-multipart-request-spec
|
|
73
|
+
*
|
|
73
74
|
* Discussion of issue: https://github.com/jaydenseric/apollo-upload-client/issues/32
|
|
75
|
+
*
|
|
76
|
+
* @param mutation - GraphQL document for a mutation that has input files
|
|
77
|
+
* with the Upload type.
|
|
78
|
+
* @param filePaths - Array of paths to files, in the same order that the
|
|
79
|
+
* corresponding Upload fields appear in the variables for the mutation.
|
|
80
|
+
* @param mapVariables - Function that must return the variables for the
|
|
81
|
+
* mutation, with `null` as the value for each `Upload` field.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* // Testing a custom mutation:
|
|
85
|
+
* const result = await client.fileUploadMutation({
|
|
86
|
+
* mutation: gql`
|
|
87
|
+
* mutation AddSellerImages($input: AddSellerImagesInput!) {
|
|
88
|
+
* addSellerImages(input: $input) {
|
|
89
|
+
* id
|
|
90
|
+
* name
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* `,
|
|
94
|
+
* filePaths: ['./images/profile-picture.jpg', './images/logo.png'],
|
|
95
|
+
* mapVariables: () => ({
|
|
96
|
+
* name: "George's Pans",
|
|
97
|
+
* profilePicture: null, // corresponds to filePaths[0]
|
|
98
|
+
* branding: {
|
|
99
|
+
* logo: null // corresponds to filePaths[1]
|
|
100
|
+
* }
|
|
101
|
+
* })
|
|
102
|
+
* });
|
|
74
103
|
*/
|
|
75
104
|
fileUploadMutation(options: {
|
|
76
105
|
mutation: DocumentNode;
|
|
@@ -12,22 +12,22 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
|
12
12
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
13
13
|
const querystring_1 = require("querystring");
|
|
14
14
|
const create_upload_post_data_1 = require("./utils/create-upload-post-data");
|
|
15
|
-
const LOGIN = (0, graphql_tag_1.default) `
|
|
16
|
-
mutation ($username: String!, $password: String!) {
|
|
17
|
-
login(username: $username, password: $password) {
|
|
18
|
-
... on CurrentUser {
|
|
19
|
-
id
|
|
20
|
-
identifier
|
|
21
|
-
channels {
|
|
22
|
-
token
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
... on ErrorResult {
|
|
26
|
-
errorCode
|
|
27
|
-
message
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
15
|
+
const LOGIN = (0, graphql_tag_1.default) `
|
|
16
|
+
mutation ($username: String!, $password: String!) {
|
|
17
|
+
login(username: $username, password: $password) {
|
|
18
|
+
... on CurrentUser {
|
|
19
|
+
id
|
|
20
|
+
identifier
|
|
21
|
+
channels {
|
|
22
|
+
token
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
... on ErrorResult {
|
|
26
|
+
errorCode
|
|
27
|
+
message
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
31
|
`;
|
|
32
32
|
/* eslint-disable no-console */
|
|
33
33
|
/**
|
|
@@ -116,13 +116,13 @@ class SimpleGraphQLClient {
|
|
|
116
116
|
var _a;
|
|
117
117
|
// first log out as the current user
|
|
118
118
|
if (this.authToken) {
|
|
119
|
-
await this.query((0, graphql_tag_1.default) `
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
await this.query((0, graphql_tag_1.default) `
|
|
120
|
+
mutation {
|
|
121
|
+
logout {
|
|
122
|
+
success
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
`);
|
|
126
126
|
}
|
|
127
127
|
const result = await this.query(LOGIN, { username, password });
|
|
128
128
|
if (((_a = result.login.channels) === null || _a === void 0 ? void 0 : _a.length) === 1) {
|
|
@@ -144,13 +144,13 @@ class SimpleGraphQLClient {
|
|
|
144
144
|
* Logs out so that the client is then treated as an anonymous user.
|
|
145
145
|
*/
|
|
146
146
|
async asAnonymousUser() {
|
|
147
|
-
await this.query((0, graphql_tag_1.default) `
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
await this.query((0, graphql_tag_1.default) `
|
|
148
|
+
mutation {
|
|
149
|
+
logout {
|
|
150
|
+
success
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
`);
|
|
154
154
|
}
|
|
155
155
|
async makeGraphQlRequest(query, variables, queryParams) {
|
|
156
156
|
const queryString = (0, printer_1.print)(query);
|
|
@@ -178,7 +178,36 @@ class SimpleGraphQLClient {
|
|
|
178
178
|
* Perform a file upload mutation.
|
|
179
179
|
*
|
|
180
180
|
* Upload spec: https://github.com/jaydenseric/graphql-multipart-request-spec
|
|
181
|
+
*
|
|
181
182
|
* Discussion of issue: https://github.com/jaydenseric/apollo-upload-client/issues/32
|
|
183
|
+
*
|
|
184
|
+
* @param mutation - GraphQL document for a mutation that has input files
|
|
185
|
+
* with the Upload type.
|
|
186
|
+
* @param filePaths - Array of paths to files, in the same order that the
|
|
187
|
+
* corresponding Upload fields appear in the variables for the mutation.
|
|
188
|
+
* @param mapVariables - Function that must return the variables for the
|
|
189
|
+
* mutation, with `null` as the value for each `Upload` field.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* // Testing a custom mutation:
|
|
193
|
+
* const result = await client.fileUploadMutation({
|
|
194
|
+
* mutation: gql`
|
|
195
|
+
* mutation AddSellerImages($input: AddSellerImagesInput!) {
|
|
196
|
+
* addSellerImages(input: $input) {
|
|
197
|
+
* id
|
|
198
|
+
* name
|
|
199
|
+
* }
|
|
200
|
+
* }
|
|
201
|
+
* `,
|
|
202
|
+
* filePaths: ['./images/profile-picture.jpg', './images/logo.png'],
|
|
203
|
+
* mapVariables: () => ({
|
|
204
|
+
* name: "George's Pans",
|
|
205
|
+
* profilePicture: null, // corresponds to filePaths[0]
|
|
206
|
+
* branding: {
|
|
207
|
+
* logo: null // corresponds to filePaths[1]
|
|
208
|
+
* }
|
|
209
|
+
* })
|
|
210
|
+
* });
|
|
182
211
|
*/
|
|
183
212
|
async fileUploadMutation(options) {
|
|
184
213
|
const { mutation, filePaths, mapVariables } = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-graphql-client.js","sourceRoot":"","sources":["../src/simple-graphql-client.ts"],"names":[],"mappings":";;;;;;AACA,2EAA8G;AAE9G,0DAAiC;AACjC,4CAAoB;AAEpB,sDAAiD;AACjD,8DAA8B;AAC9B,4DAA0D;AAC1D,6CAAwC;AAGxC,6EAAuE;AAEvE,MAAM,KAAK,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;CAgBhB,CAAC;AAEF,+BAA+B;AAC/B;;;;;GAKG;AACH,MAAa,mBAAmB;IAO5B,
|
|
1
|
+
{"version":3,"file":"simple-graphql-client.js","sourceRoot":"","sources":["../src/simple-graphql-client.ts"],"names":[],"mappings":";;;;;;AACA,2EAA8G;AAE9G,0DAAiC;AACjC,4CAAoB;AAEpB,sDAAiD;AACjD,8DAA8B;AAC9B,4DAA0D;AAC1D,6CAAwC;AAGxC,6EAAuE;AAEvE,MAAM,KAAK,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;CAgBhB,CAAC;AAEF,+BAA+B;AAC/B;;;;;GAKG;AACH,MAAa,mBAAmB;IAO5B,YACY,aAAsC,EACtC,SAAiB,EAAE;QADnB,kBAAa,GAAb,aAAa,CAAyB;QACt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AE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAA,oBAAK,EAAC,IAAI,CAAC,MAAM,EAAE;YACpC,MAAM,EAAE,MAAM;YACd,IAAI;YACJ,OAAO,oBACA,IAAI,CAAC,OAAO,CAClB;SACJ,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC;IACzB,CAAC;CACJ;AApPD,kDAoPC;AAED,MAAa,WAAY,SAAQ,KAAK;IAClC,YACW,QAAa,EACb,OAAY;QAEnB,KAAK,CAAC,WAAW,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;QAHrC,aAAQ,GAAR,QAAQ,CAAK;QACb,YAAO,GAAP,OAAO,CAAK;IAGvB,CAAC;IACO,MAAM,CAAC,cAAc,CAAC,QAAa;QACvC,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClB,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACtC,CAAC;aAAM,CAAC;YACJ,OAAO,wBAAwB,QAAQ,CAAC,MAAgB,GAAG,CAAC;QAChE,CAAC;IACL,CAAC;CACJ;AAdD,kCAcC"}
|
|
@@ -1,23 +1,67 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
export interface FilePlaceholder {
|
|
3
|
-
file: null;
|
|
4
|
-
}
|
|
5
2
|
export interface UploadPostData<V = any> {
|
|
3
|
+
/**
|
|
4
|
+
* Data from a GraphQL document that takes the Upload type as input
|
|
5
|
+
*/
|
|
6
6
|
operations: {
|
|
7
7
|
operationName: string;
|
|
8
8
|
variables: V;
|
|
9
9
|
query: string;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* A map from index values to variable paths. Maps files in the `filePaths`
|
|
13
|
+
* array to fields with the Upload type in the GraphQL mutation input.
|
|
14
|
+
*
|
|
15
|
+
* If this was the GraphQL mutation input type:
|
|
16
|
+
* ```graphql
|
|
17
|
+
* input ImageReceivingInput {
|
|
18
|
+
* bannerImage: Upload!
|
|
19
|
+
* logo: Upload!
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* And this was the GraphQL mutation:
|
|
24
|
+
* ```graphql
|
|
25
|
+
* addSellerImages(input: ImageReceivingInput!): Seller
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Then this would be the value for `map`:
|
|
29
|
+
* ```js
|
|
30
|
+
* {
|
|
31
|
+
* 0: 'variables.input.bannerImage',
|
|
32
|
+
* 1: 'variables.input.logo'
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
11
36
|
map: {
|
|
12
37
|
[index: number]: string;
|
|
13
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Array of file paths. Mapped to a GraphQL mutation input variable by
|
|
41
|
+
* `map`.
|
|
42
|
+
*/
|
|
14
43
|
filePaths: Array<{
|
|
44
|
+
/**
|
|
45
|
+
* Index of the file path as a string.
|
|
46
|
+
*/
|
|
15
47
|
name: string;
|
|
48
|
+
/**
|
|
49
|
+
* The actual file path
|
|
50
|
+
*/
|
|
16
51
|
file: string;
|
|
17
52
|
}>;
|
|
18
53
|
}
|
|
19
54
|
/**
|
|
20
|
-
* Creates a data structure which can be used to
|
|
21
|
-
* the Upload type.
|
|
55
|
+
* Creates a data structure which can be used to make a POST request to upload
|
|
56
|
+
* files to a mutation using the Upload type.
|
|
57
|
+
*
|
|
58
|
+
* @param mutation - The GraphQL document for a mutation that takes an Upload
|
|
59
|
+
* type as an input
|
|
60
|
+
* @param filePaths - Either a single path or an array of paths to the files
|
|
61
|
+
* that should be uploaded
|
|
62
|
+
* @param mapVariables - A function that will receive `filePaths` and return an
|
|
63
|
+
* object containing the input variables for the mutation, where every field
|
|
64
|
+
* with the Upload type has the value `null`.
|
|
65
|
+
* @returns an UploadPostData object.
|
|
22
66
|
*/
|
|
23
67
|
export declare function createUploadPostData<P extends string[] | string, V>(mutation: DocumentNode, filePaths: P, mapVariables: (filePaths: P) => V): UploadPostData<V>;
|
|
@@ -3,8 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createUploadPostData = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
/**
|
|
6
|
-
* Creates a data structure which can be used to
|
|
7
|
-
* the Upload type.
|
|
6
|
+
* Creates a data structure which can be used to make a POST request to upload
|
|
7
|
+
* files to a mutation using the Upload type.
|
|
8
|
+
*
|
|
9
|
+
* @param mutation - The GraphQL document for a mutation that takes an Upload
|
|
10
|
+
* type as an input
|
|
11
|
+
* @param filePaths - Either a single path or an array of paths to the files
|
|
12
|
+
* that should be uploaded
|
|
13
|
+
* @param mapVariables - A function that will receive `filePaths` and return an
|
|
14
|
+
* object containing the input variables for the mutation, where every field
|
|
15
|
+
* with the Upload type has the value `null`.
|
|
16
|
+
* @returns an UploadPostData object.
|
|
8
17
|
*/
|
|
9
18
|
function createUploadPostData(mutation, filePaths, mapVariables) {
|
|
10
19
|
const operationDef = mutation.definitions.find(d => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
|
|
@@ -16,9 +25,7 @@ function createUploadPostData(mutation, filePaths, mapVariables) {
|
|
|
16
25
|
variables,
|
|
17
26
|
query: (0, graphql_1.print)(mutation),
|
|
18
27
|
},
|
|
19
|
-
map:
|
|
20
|
-
return Object.assign(Object.assign({}, output), { [i.toString()]: objectPath(variables, i).join('.') });
|
|
21
|
-
}, {}),
|
|
28
|
+
map: objectPath(variables).reduce((acc, path, i) => (Object.assign(Object.assign({}, acc), { [i.toString()]: path })), {}),
|
|
22
29
|
filePaths: filePathsArray.map((filePath, i) => ({
|
|
23
30
|
name: i.toString(),
|
|
24
31
|
file: filePath,
|
|
@@ -27,25 +34,37 @@ function createUploadPostData(mutation, filePaths, mapVariables) {
|
|
|
27
34
|
return postData;
|
|
28
35
|
}
|
|
29
36
|
exports.createUploadPostData = createUploadPostData;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
/**
|
|
38
|
+
* This function visits each property in the `variables` object, including
|
|
39
|
+
* nested ones, and returns the path of each null value, in order.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // variables:
|
|
43
|
+
* {
|
|
44
|
+
* input: {
|
|
45
|
+
* name: "George's Pots and Pans",
|
|
46
|
+
* logo: null,
|
|
47
|
+
* user: {
|
|
48
|
+
* profilePicture: null
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* // return value:
|
|
53
|
+
* ['variables.input.logo', 'variables.input.user.profilePicture']
|
|
54
|
+
*/
|
|
55
|
+
function objectPath(variables) {
|
|
56
|
+
const pathsToNulls = [];
|
|
57
|
+
const checkValue = (pathSoFar, value) => {
|
|
58
|
+
if (value === null) {
|
|
59
|
+
pathsToNulls.push(pathSoFar);
|
|
60
|
+
}
|
|
61
|
+
else if (typeof value === 'object') {
|
|
62
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
63
|
+
checkValue(`${pathSoFar}.${key}`, value[key]);
|
|
46
64
|
}
|
|
47
65
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
66
|
+
};
|
|
67
|
+
checkValue('variables', variables);
|
|
68
|
+
return pathsToNulls;
|
|
50
69
|
}
|
|
51
70
|
//# sourceMappingURL=create-upload-post-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-upload-post-data.js","sourceRoot":"","sources":["../../src/utils/create-upload-post-data.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;
|
|
1
|
+
{"version":3,"file":"create-upload-post-data.js","sourceRoot":"","sources":["../../src/utils/create-upload-post-data.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAyD7E;;;;;;;;;;;;GAYG;AACH,SAAgB,oBAAoB,CAChC,QAAsB,EACtB,SAAY,EACZ,YAAiC;IAEjC,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAC1C,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAI,CAAC,oBAAoB,CACjB,CAAC;IAE7B,MAAM,cAAc,GAAa,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACpF,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAmB;QAC7B,UAAU,EAAE;YACR,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,mBAAmB;YAChF,SAAS;YACT,KAAK,EAAE,IAAA,eAAK,EAAC,QAAQ,CAAC;SACzB;QACD,GAAG,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,iCAAM,GAAG,KAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,IAAG,EAAE,EAAE,CAAC;QAC3F,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;YAClB,IAAI,EAAE,QAAQ;SACjB,CAAC,CAAC;KACN,CAAC;IACF,OAAO,QAAQ,CAAC;AACpB,CAAC;AAxBD,oDAwBC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,UAAU,CAAC,SAAc;IAC9B,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAE,KAAU,EAAE,EAAE;QACjD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACjB,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClD,UAAU,CAAC,GAAG,SAAS,IAAI,GAAG,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAClD,CAAC;QACL,CAAC;IACL,CAAC,CAAC;IACF,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACnC,OAAO,YAAY,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure/testing",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "End-to-end testing tools for Vendure projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vendure",
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
"build": "tsc -p ./tsconfig.build.json",
|
|
31
31
|
"watch": "tsc -p ./tsconfig.build.json -w",
|
|
32
32
|
"lint": "eslint --fix .",
|
|
33
|
-
"ci": "npm run build"
|
|
33
|
+
"ci": "npm run build",
|
|
34
|
+
"test": "vitest --config vitest.config.mts --run"
|
|
34
35
|
},
|
|
35
36
|
"bugs": {
|
|
36
37
|
"url": "https://github.com/vendure-ecommerce/vendure/issues"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
40
|
-
"@vendure/common": "^3.0.
|
|
41
|
+
"@vendure/common": "^3.0.6",
|
|
41
42
|
"faker": "^4.1.0",
|
|
42
43
|
"form-data": "^4.0.0",
|
|
43
44
|
"graphql": "~16.9.0",
|
|
@@ -50,11 +51,11 @@
|
|
|
50
51
|
"@types/mysql": "^2.15.26",
|
|
51
52
|
"@types/node-fetch": "^2.6.4",
|
|
52
53
|
"@types/pg": "^8.11.2",
|
|
53
|
-
"@vendure/core": "^3.0.
|
|
54
|
+
"@vendure/core": "^3.0.6",
|
|
54
55
|
"mysql": "^2.18.1",
|
|
55
56
|
"pg": "^8.11.3",
|
|
56
57
|
"rimraf": "^5.0.5",
|
|
57
58
|
"typescript": "5.3.3"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "db1d4bfdb32ac94ddb719d19659dd5258c247667"
|
|
60
61
|
}
|