@unchainedshop/api 2.0.0-beta6 → 2.0.0-beta7
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/api-index.d.ts +3 -3
- package/lib/api-index.js +21 -3
- package/lib/api-index.js.map +1 -1
- package/lib/context.d.ts +1 -1
- package/lib/context.js +5 -4
- package/lib/context.js.map +1 -1
- package/lib/createGraphQLServer.d.ts +2 -2
- package/lib/createGraphQLServer.js +25 -35
- package/lib/createGraphQLServer.js.map +1 -1
- package/lib/errors.js +8 -3
- package/lib/errors.js.map +1 -1
- package/lib/loaders/index.js +50 -0
- package/lib/loaders/index.js.map +1 -1
- package/lib/resolvers/index.js +1 -1
- package/lib/resolvers/index.js.map +1 -1
- package/lib/resolvers/mutations/filters/updateFilter.js +2 -1
- package/lib/resolvers/mutations/filters/updateFilter.js.map +1 -1
- package/lib/resolvers/queries/products/product.js +1 -1
- package/lib/resolvers/queries/products/productCatalogPrices.d.ts +1 -1
- package/lib/resolvers/queries/products/productCatalogPrices.js +5 -2
- package/lib/resolvers/queries/products/productCatalogPrices.js.map +1 -1
- package/lib/resolvers/queries/products/products.js +1 -1
- package/lib/resolvers/queries/products/products.js.map +1 -1
- package/lib/resolvers/scalars/LowerCaseString.d.ts +1 -1
- package/lib/resolvers/scalars/index.d.ts +1 -1
- package/lib/resolvers/type/assortment/assortment-filter-types.js +13 -6
- package/lib/resolvers/type/assortment/assortment-filter-types.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-link-types.js +14 -6
- package/lib/resolvers/type/assortment/assortment-link-types.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-product-types.js +14 -6
- package/lib/resolvers/type/assortment/assortment-product-types.js.map +1 -1
- package/lib/resolvers/type/bookmark-types.js +6 -2
- package/lib/resolvers/type/bookmark-types.js.map +1 -1
- package/lib/resolvers/type/enrollment/enrollment-plan-tyes.js +6 -2
- package/lib/resolvers/type/enrollment/enrollment-plan-tyes.js.map +1 -1
- package/lib/resolvers/type/order/order-item-types.js +13 -6
- package/lib/resolvers/type/order/order-item-types.js.map +1 -1
- package/lib/resolvers/type/product/product-bundle-item-types.js +4 -2
- package/lib/resolvers/type/product/product-bundle-item-types.js.map +1 -1
- package/lib/resolvers/type/product/product-review-types.js +6 -2
- package/lib/resolvers/type/product/product-review-types.js.map +1 -1
- package/lib/resolvers/type/product/product-tokenized-types.js +1 -0
- package/lib/resolvers/type/product/product-tokenized-types.js.map +1 -1
- package/lib/resolvers/type/product/product-variation-assignment-types.js +4 -2
- package/lib/resolvers/type/product/product-variation-assignment-types.js.map +1 -1
- package/lib/resolvers/type/quotation-types.js +7 -3
- package/lib/resolvers/type/quotation-types.js.map +1 -1
- package/lib/schema/types/product/tokenized-product.js +2 -0
- package/lib/schema/types/product/tokenized-product.js.map +1 -1
- package/package.json +16 -17
- package/src/api-index.ts +24 -7
- package/src/context.ts +15 -16
- package/src/createGraphQLServer.ts +35 -37
- package/src/errors.ts +8 -3
- package/src/loaders/index.ts +63 -3
- package/src/resolvers/index.ts +1 -1
- package/src/resolvers/mutations/filters/updateFilter.ts +3 -1
- package/src/resolvers/queries/products/product.ts +1 -1
- package/src/resolvers/queries/products/productCatalogPrices.ts +5 -2
- package/src/resolvers/queries/products/products.ts +1 -1
- package/src/resolvers/type/assortment/assortment-filter-types.ts +11 -6
- package/src/resolvers/type/assortment/assortment-link-types.ts +12 -6
- package/src/resolvers/type/assortment/assortment-product-types.ts +12 -6
- package/src/resolvers/type/bookmark-types.ts +7 -2
- package/src/resolvers/type/enrollment/enrollment-plan-tyes.ts +6 -2
- package/src/resolvers/type/order/order-item-types.ts +13 -6
- package/src/resolvers/type/product/product-bundle-item-types.ts +4 -2
- package/src/resolvers/type/product/product-review-types.ts +6 -2
- package/src/resolvers/type/product/product-tokenized-types.ts +1 -0
- package/src/resolvers/type/product/product-variation-assignment-types.ts +4 -2
- package/src/resolvers/type/quotation-types.ts +6 -3
- package/src/schema/types/product/tokenized-product.js +2 -0
- package/tsconfig.json +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enrollment-plan-tyes.js","sourceRoot":"","sources":["../../../../src/resolvers/type/enrollment/enrollment-plan-tyes.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,cAAc,GAA8B;IACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACtC,OAAO,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"enrollment-plan-tyes.js","sourceRoot":"","sources":["../../../../src/resolvers/type/enrollment/enrollment-plan-tyes.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,cAAc,GAA8B;IACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;YAC/C,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC"}
|
|
@@ -19,7 +19,7 @@ export const OrderItem = {
|
|
|
19
19
|
}
|
|
20
20
|
return [];
|
|
21
21
|
},
|
|
22
|
-
dispatches: async (obj, _, { modules }) => {
|
|
22
|
+
dispatches: async (obj, _, { modules, loaders }) => {
|
|
23
23
|
const scheduling = obj.scheduling || [];
|
|
24
24
|
const order = await modules.orders.findOrder({ orderId: obj.orderId });
|
|
25
25
|
const { countryCode, userId } = order;
|
|
@@ -29,8 +29,9 @@ export const OrderItem = {
|
|
|
29
29
|
const deliveryProvider = await modules.delivery.findProvider({
|
|
30
30
|
deliveryProviderId: orderDelivery.deliveryProviderId,
|
|
31
31
|
});
|
|
32
|
-
const product = await
|
|
32
|
+
const product = await loaders.productLoader.load({
|
|
33
33
|
productId: obj.productId,
|
|
34
|
+
includeDrafts: true,
|
|
34
35
|
});
|
|
35
36
|
return Promise.all(scheduling.map(async (schedule) => {
|
|
36
37
|
const warehousingProvider = await modules.warehousing.findProvider({
|
|
@@ -54,13 +55,19 @@ export const OrderItem = {
|
|
|
54
55
|
order: async (obj, _, { modules }) => {
|
|
55
56
|
return modules.orders.findOrder({ orderId: obj.orderId });
|
|
56
57
|
},
|
|
57
|
-
originalProduct: async (obj, _, {
|
|
58
|
-
|
|
58
|
+
originalProduct: async (obj, _, { loaders }) => {
|
|
59
|
+
const product = await loaders.productLoader.load({
|
|
59
60
|
productId: obj.originalProductId,
|
|
61
|
+
includeDrafts: true,
|
|
60
62
|
});
|
|
63
|
+
return product;
|
|
61
64
|
},
|
|
62
|
-
product: async (obj, _, {
|
|
63
|
-
|
|
65
|
+
product: async (obj, _, { loaders }) => {
|
|
66
|
+
const product = await loaders.productLoader.load({
|
|
67
|
+
productId: obj.productId,
|
|
68
|
+
includeDrafts: true,
|
|
69
|
+
});
|
|
70
|
+
return product;
|
|
64
71
|
},
|
|
65
72
|
quotation: async (obj, _, { modules }) => {
|
|
66
73
|
if (!obj.quotationId)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-item-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/order/order-item-types.ts"],"names":[],"mappings":"AAQA,OAAO,MAAM,MAAM,QAAQ,CAAC;AA0B5B,MAAM,eAAe,GAAG,KAAK,EAAE,aAA4B,EAAE,OAAgB,EAAE,EAAE;IAC/E,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC;QAC3C,OAAO,EAAE,aAAa,CAAC,OAAO;KAC/B,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEnG,OAAO,YAAY,CAAC;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AAQ,EAAE,YAAY,CAAC,QAAQ;gBAC/B,GAAG,KAAK;aACT,CAAC;SACH;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export const ProductBundleItem = {
|
|
2
|
-
product: async (productItem, _, {
|
|
3
|
-
|
|
2
|
+
product: async (productItem, _, { loaders }) => {
|
|
3
|
+
const product = await loaders.productLoader.load({
|
|
4
4
|
productId: productItem.productId,
|
|
5
|
+
includeDrafts: true,
|
|
5
6
|
});
|
|
7
|
+
return product;
|
|
6
8
|
},
|
|
7
9
|
};
|
|
8
10
|
//# sourceMappingURL=product-bundle-item-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-bundle-item-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-bundle-item-types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAiC;IAC7D,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAC7C,OAAO,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"product-bundle-item-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-bundle-item-types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAiC;IAC7D,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;YAC/C,SAAS,EAAE,WAAW,CAAC,SAAS;YAChC,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC"}
|
|
@@ -2,8 +2,12 @@ export const ProductReview = {
|
|
|
2
2
|
author: async (obj, _, { modules }) => {
|
|
3
3
|
return modules.users.findUserById(obj.authorId);
|
|
4
4
|
},
|
|
5
|
-
product: async (
|
|
6
|
-
|
|
5
|
+
product: async (review, _, { loaders }) => {
|
|
6
|
+
const product = await loaders.productLoader.load({
|
|
7
|
+
productId: review.productId,
|
|
8
|
+
includeDrafts: true,
|
|
9
|
+
});
|
|
10
|
+
return product;
|
|
7
11
|
},
|
|
8
12
|
ownVotes: async (obj, _, { modules, userId }) => {
|
|
9
13
|
return modules.products.reviews.votes.ownVotes(obj, { userId });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-review-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-review-types.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,aAAa,GAA6B;IACrD,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACpC,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"product-review-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-review-types.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,aAAa,GAA6B;IACrD,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACpC,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;YAC/C,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;QAC9C,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACxC,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IAC/E,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-tokenized-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-tokenized-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,CAAC,MAAM,gBAAgB,GAAgC;IAC3D,GAAG,WAAW;IAEd,eAAe,CAAC,OAAO;QACrB,OAAO,OAAO,CAAC,YAAY,EAAE,eAAe,CAAC;IAC/C,CAAC;IAED,qBAAqB,CAAC,OAAO;QAC3B,IAAI,CAAC,OAAO,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;QACvC,OAAO;YACL,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,MAAM;YACnC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"product-tokenized-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-tokenized-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,CAAC,MAAM,gBAAgB,GAAgC;IAC3D,GAAG,WAAW;IAEd,eAAe,CAAC,OAAO;QACrB,OAAO,OAAO,CAAC,YAAY,EA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gBAEF,OAAO;oBACL,mBAAmB;oBACnB,GAAG,kBAAkB;oBACrB,GAAG,KAAK;iBACT,CAAC;YACJ,CAAC,CAAC,CACH,CAAC;YAEF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;QAC3D,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1B,CAAC;CACF,CAAC;AAEF,OAAO,gBAAgB,CAAC,SAAS,CAAC;AAClC,OAAO,gBAAgB,CAAC,oBAAoB,CAAC;AAC7C,OAAO,gBAAgB,CAAC,oBAAoB,CAAC"}
|
|
@@ -9,10 +9,12 @@ export const ProductVariationAssignment = {
|
|
|
9
9
|
product,
|
|
10
10
|
}));
|
|
11
11
|
},
|
|
12
|
-
product: async ({ assignment }, _, {
|
|
13
|
-
|
|
12
|
+
product: async ({ assignment }, _, { loaders }) => {
|
|
13
|
+
const product = await loaders.productLoader.load({
|
|
14
14
|
productId: assignment.productId,
|
|
15
|
+
includeDrafts: true,
|
|
15
16
|
});
|
|
17
|
+
return product;
|
|
16
18
|
},
|
|
17
19
|
};
|
|
18
20
|
//# sourceMappingURL=product-variation-assignment-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-variation-assignment-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-variation-assignment-types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0BAA0B,GAA0C;IAC/E,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;QAC/B,OAAO,GAAG,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACxE,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE;QACnC,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACxD,GAAG;YACH,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC;YAC7B,OAAO;SACR,CAAC,CAAC,CAAC;IACN,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAChD,OAAO,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"product-variation-assignment-types.js","sourceRoot":"","sources":["../../../../src/resolvers/type/product/product-variation-assignment-types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,0BAA0B,GAA0C;IAC/E,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;QAC/B,OAAO,GAAG,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACxE,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE;QACnC,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACxD,GAAG;YACH,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC;YAC7B,OAAO;SACR,CAAC,CAAC,CAAC;IACN,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAChD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;YAC/C,SAAS,EAAE,UAAU,CAAC,SAAS;YAC/B,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC"}
|
|
@@ -2,9 +2,13 @@ export const Quotation = {
|
|
|
2
2
|
country: async (obj, _, { modules }) => modules.countries.findCountry({ isoCode: obj.countryCode }),
|
|
3
3
|
currency: async (obj, _, { modules }) => modules.currencies.findCurrency({ isoCode: obj.currency }),
|
|
4
4
|
isExpired: (obj, { referenceDate }, { modules }) => modules.quotations.isExpired(obj, { referenceDate }),
|
|
5
|
-
product: (obj, _, {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
product: async (obj, _, { loaders }) => {
|
|
6
|
+
const product = await loaders.productLoader.load({
|
|
7
|
+
productId: obj.productId,
|
|
8
|
+
includeDrafts: true,
|
|
9
|
+
});
|
|
10
|
+
return product;
|
|
11
|
+
},
|
|
8
12
|
status: (obj, _, { modules }) => modules.quotations.normalizedStatus(obj),
|
|
9
13
|
user: (obj, _, { modules }) => modules.users.findUserById(obj.userId),
|
|
10
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotation-types.js","sourceRoot":"","sources":["../../../src/resolvers/type/quotation-types.ts"],"names":[],"mappings":"AAkBA,MAAM,CAAC,MAAM,SAAS,GAAyB;IAC7C,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC;IAEnG,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;IAEnG,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CACjD,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,GAA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AAC,MAAM,CAAC;CACtE,CAAC"}
|
|
@@ -5,6 +5,7 @@ export default [
|
|
|
5
5
|
contractStandard: SmartContractStandard!
|
|
6
6
|
tokenId: String
|
|
7
7
|
supply: Int
|
|
8
|
+
ercMetadataProperties: JSON
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
enum SmartContractStandard {
|
|
@@ -15,6 +16,7 @@ export default [
|
|
|
15
16
|
type ContractConfiguration {
|
|
16
17
|
tokenId: String
|
|
17
18
|
supply: Int
|
|
19
|
+
ercMetadataProperties: JSON
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
"""
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenized-product.js","sourceRoot":"","sources":["../../../../src/schema/types/product/tokenized-product.js"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC
|
|
1
|
+
{"version":3,"file":"tokenized-product.js","sourceRoot":"","sources":["../../../../src/schema/types/product/tokenized-product.js"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDb;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/api",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta7",
|
|
4
4
|
"main": "lib/api-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/api-index.js",
|
|
@@ -30,33 +30,32 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"apollo
|
|
33
|
+
"@apollo/server": "^4.1.1",
|
|
34
34
|
"cookie": "^0.5.0",
|
|
35
|
-
"graphql": "^
|
|
35
|
+
"graphql": "^16.6.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@metamask/eth-sig-util": "^5.0.
|
|
39
|
-
"@unchainedshop/core": "^2.0.0-
|
|
40
|
-
"@unchainedshop/events": "^2.0.0-
|
|
41
|
-
"@unchainedshop/logger": "^2.0.0-
|
|
42
|
-
"@unchainedshop/roles": "^2.0.0-
|
|
43
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
38
|
+
"@metamask/eth-sig-util": "^5.0.2",
|
|
39
|
+
"@unchainedshop/core": "^2.0.0-beta7",
|
|
40
|
+
"@unchainedshop/events": "^2.0.0-beta7",
|
|
41
|
+
"@unchainedshop/logger": "^2.0.0-beta7",
|
|
42
|
+
"@unchainedshop/roles": "^2.0.0-beta7",
|
|
43
|
+
"@unchainedshop/utils": "^2.0.0-beta7",
|
|
44
44
|
"accounting": "0.4.1",
|
|
45
45
|
"dataloader": "^2.1.0",
|
|
46
|
-
"graphql-scalars": "^1.20.
|
|
47
|
-
"graphql-upload": "^
|
|
46
|
+
"graphql-scalars": "^1.20.1",
|
|
47
|
+
"graphql-upload": "^16.0.2",
|
|
48
48
|
"locale": "0.1.0",
|
|
49
49
|
"lodash.isnumber": "3.0.3",
|
|
50
|
-
"lru-cache": "^7.14.
|
|
50
|
+
"lru-cache": "^7.14.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/graphql-upload": "^8.0.12",
|
|
54
54
|
"@types/locale": "^0.1.1",
|
|
55
|
-
"@types/node": "^
|
|
56
|
-
"@unchainedshop/types": "^2.0.0-
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"jest": "^29.2.2",
|
|
55
|
+
"@types/node": "^18.11.9",
|
|
56
|
+
"@unchainedshop/types": "^2.0.0-beta7",
|
|
57
|
+
"graphql": "^16.6.0",
|
|
58
|
+
"jest": "^29.3.1",
|
|
60
59
|
"ts-jest": "^29.0.3",
|
|
61
60
|
"typescript": "^4.8.4"
|
|
62
61
|
}
|
package/src/api-index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { UnchainedServerOptions } from '@unchainedshop/types/api';
|
|
2
|
-
import { ApolloServer } from 'apollo
|
|
2
|
+
import type { ApolloServer } from '@apollo/server';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
3
5
|
import createBulkImportServer from './createBulkImportServer';
|
|
4
6
|
import createGraphQLServer from './createGraphQLServer';
|
|
5
7
|
import { createContextResolver, getCurrentContextResolver, setCurrentContextResolver } from './context';
|
|
@@ -10,18 +12,33 @@ export * as acl from './acl';
|
|
|
10
12
|
export * as errors from './errors';
|
|
11
13
|
export { hashPassword } from './hashPassword';
|
|
12
14
|
export * as roles from './roles';
|
|
13
|
-
|
|
14
15
|
export { createContextResolver, getCurrentContextResolver, setCurrentContextResolver };
|
|
15
16
|
|
|
16
|
-
const
|
|
17
|
+
const loadJSON = (filename) => {
|
|
18
|
+
try {
|
|
19
|
+
const base = typeof __filename !== 'undefined' && __filename;
|
|
20
|
+
if (!base)
|
|
21
|
+
return {
|
|
22
|
+
version: process.env.npm_package_version,
|
|
23
|
+
};
|
|
24
|
+
const absolutePath = path.resolve(path.dirname(base), filename);
|
|
25
|
+
const data = JSON.parse(fs.readFileSync(absolutePath, 'utf-8'));
|
|
26
|
+
return data;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const packageJson = loadJSON('../package.json');
|
|
32
|
+
|
|
33
|
+
const UNCHAINED_API_VERSION = process.env.UNCHAINED_API_VERSION || packageJson?.version || '1.2.x';
|
|
17
34
|
|
|
18
|
-
export const startAPIServer = (
|
|
35
|
+
export const startAPIServer = async (
|
|
19
36
|
options: UnchainedServerOptions,
|
|
20
|
-
): {
|
|
37
|
+
): Promise<{
|
|
21
38
|
apolloGraphQLServer: ApolloServer;
|
|
22
39
|
bulkImportServer: any;
|
|
23
40
|
ercMetadataServer: any;
|
|
24
|
-
} => {
|
|
41
|
+
}> => {
|
|
25
42
|
const {
|
|
26
43
|
unchainedAPI,
|
|
27
44
|
roles,
|
|
@@ -40,7 +57,7 @@ export const startAPIServer = (
|
|
|
40
57
|
: contextResolver,
|
|
41
58
|
);
|
|
42
59
|
|
|
43
|
-
const apolloGraphQLServer = createGraphQLServer(expressApp, apolloServerOptions);
|
|
60
|
+
const apolloGraphQLServer = await createGraphQLServer(expressApp, apolloServerOptions);
|
|
44
61
|
const bulkImportServer = createBulkImportServer(expressApp);
|
|
45
62
|
const ercMetadataServer = createERCMetadataServer(expressApp);
|
|
46
63
|
|
package/src/context.ts
CHANGED
|
@@ -33,20 +33,19 @@ export const createContextResolver =
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
export const useMiddlewareWithCurrentContext = (expressApp, path, middleware) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
);
|
|
36
|
+
export const useMiddlewareWithCurrentContext = (expressApp, path, ...middleware) => {
|
|
37
|
+
const addContext = async function middlewareWithContext(
|
|
38
|
+
req: IncomingMessage & { unchainedContext?: UnchainedCore },
|
|
39
|
+
res: OutgoingMessage,
|
|
40
|
+
next,
|
|
41
|
+
) {
|
|
42
|
+
try {
|
|
43
|
+
req.unchainedContext = await context({ req, res });
|
|
44
|
+
next();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
next(error);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
expressApp.use(path, addContext, ...middleware);
|
|
52
51
|
};
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import { ApolloServer
|
|
2
|
-
import {
|
|
1
|
+
import { ApolloServer } from '@apollo/server';
|
|
2
|
+
import { expressMiddleware } from '@apollo/server/express4';
|
|
3
|
+
import { GraphQLError } from 'graphql';
|
|
4
|
+
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
|
3
5
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
6
|
+
import cors from 'cors';
|
|
7
|
+
import bodyParser from 'body-parser';
|
|
4
8
|
import typeDefs from './schema';
|
|
5
9
|
import resolvers from './resolvers';
|
|
6
10
|
import { getCurrentContextResolver } from './context';
|
|
7
11
|
|
|
8
12
|
const { APOLLO_ENGINE_KEY } = process.env;
|
|
9
13
|
|
|
10
|
-
const handleUploads = (options) => async (req, res, next) => {
|
|
11
|
-
const contentType = req.headers['content-type'];
|
|
12
|
-
const isUpload = contentType && contentType.startsWith('multipart/form-data');
|
|
13
|
-
if (isUpload) {
|
|
14
|
-
req.body = await processRequest(req, res, options);
|
|
15
|
-
}
|
|
16
|
-
next();
|
|
17
|
-
};
|
|
18
|
-
|
|
19
14
|
const logGraphQLServerError = (error) => {
|
|
20
15
|
try {
|
|
21
16
|
const {
|
|
@@ -35,7 +30,7 @@ const logGraphQLServerError = (error) => {
|
|
|
35
30
|
} catch (e) {} // eslint-disable-line
|
|
36
31
|
};
|
|
37
32
|
|
|
38
|
-
export default (expressApp, options) => {
|
|
33
|
+
export default async (expressApp, options) => {
|
|
39
34
|
const {
|
|
40
35
|
corsOrigins = null, // no cookie handling
|
|
41
36
|
typeDefs: additionalTypeDefs = [],
|
|
@@ -45,11 +40,10 @@ export default (expressApp, options) => {
|
|
|
45
40
|
} = options || {};
|
|
46
41
|
|
|
47
42
|
const context = getCurrentContextResolver();
|
|
43
|
+
|
|
48
44
|
const server = new ApolloServer({
|
|
49
45
|
typeDefs: [...typeDefs, ...additionalTypeDefs],
|
|
50
46
|
resolvers: [resolvers, ...additionalResolvers],
|
|
51
|
-
context,
|
|
52
|
-
uploads: false,
|
|
53
47
|
formatError: (error) => {
|
|
54
48
|
logGraphQLServerError(error);
|
|
55
49
|
const {
|
|
@@ -57,18 +51,20 @@ export default (expressApp, options) => {
|
|
|
57
51
|
path,
|
|
58
52
|
extensions: { exception, code, ...extensions }, // eslint-disable-line
|
|
59
53
|
} = error;
|
|
60
|
-
const apolloError = new
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
const apolloError = new GraphQLError(message, {
|
|
55
|
+
extensions: {
|
|
56
|
+
code,
|
|
57
|
+
...extensions,
|
|
58
|
+
},
|
|
63
59
|
});
|
|
64
60
|
// eslint-disable-next-line
|
|
65
61
|
// @ts-ignore
|
|
66
62
|
apolloError.path = path;
|
|
67
63
|
return apolloError;
|
|
68
64
|
},
|
|
69
|
-
|
|
65
|
+
apollo: APOLLO_ENGINE_KEY
|
|
70
66
|
? {
|
|
71
|
-
|
|
67
|
+
key: APOLLO_ENGINE_KEY,
|
|
72
68
|
privateVariables: ['email', 'plainPassword', 'oldPlainPassword', 'newPlainPassword'],
|
|
73
69
|
...engine,
|
|
74
70
|
}
|
|
@@ -76,6 +72,8 @@ export default (expressApp, options) => {
|
|
|
76
72
|
...apolloServerOptions,
|
|
77
73
|
});
|
|
78
74
|
|
|
75
|
+
await server.start();
|
|
76
|
+
|
|
79
77
|
const originFn =
|
|
80
78
|
corsOrigins && Array.isArray(corsOrigins)
|
|
81
79
|
? (origin, callback) => {
|
|
@@ -91,25 +89,25 @@ export default (expressApp, options) => {
|
|
|
91
89
|
}
|
|
92
90
|
: corsOrigins;
|
|
93
91
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
|
|
92
|
+
expressApp.use(
|
|
93
|
+
'/graphql',
|
|
94
|
+
cors(
|
|
95
|
+
!originFn
|
|
96
|
+
? undefined
|
|
97
|
+
: {
|
|
98
|
+
origin: originFn,
|
|
99
|
+
credentials: true,
|
|
100
|
+
},
|
|
101
|
+
),
|
|
102
|
+
bodyParser.json(),
|
|
103
|
+
graphqlUploadExpress(),
|
|
104
|
+
expressMiddleware(server, {
|
|
105
|
+
context,
|
|
106
|
+
}),
|
|
107
|
+
);
|
|
110
108
|
|
|
111
|
-
expressApp.use(handleUploads({ maxFileSize: 10000000, maxFiles: 10 }));
|
|
112
|
-
expressApp.use(middleware);
|
|
109
|
+
// expressApp.use(handleUploads({ maxFileSize: 10000000, maxFiles: 10 }));
|
|
110
|
+
// expressApp.use(middleware);
|
|
113
111
|
|
|
114
112
|
return server;
|
|
115
113
|
};
|
package/src/errors.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
2
|
|
|
3
3
|
export const createError = (code: string, message: string): any =>
|
|
4
|
-
class extends
|
|
4
|
+
class extends GraphQLError {
|
|
5
5
|
constructor({ message: explicitMessage, ...data }) {
|
|
6
|
-
super(explicitMessage || message,
|
|
6
|
+
super(explicitMessage || message, {
|
|
7
|
+
extensions: {
|
|
8
|
+
code,
|
|
9
|
+
...data,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
7
12
|
}
|
|
8
13
|
};
|
|
9
14
|
|
package/src/loaders/index.ts
CHANGED
|
@@ -3,10 +3,11 @@ import DataLoader from 'dataloader';
|
|
|
3
3
|
import { IncomingMessage, OutgoingMessage } from 'http';
|
|
4
4
|
import { systemLocale } from '@unchainedshop/utils';
|
|
5
5
|
import localePkg from 'locale';
|
|
6
|
-
import { AssortmentText } from '@unchainedshop/types/assortments';
|
|
7
|
-
import { FilterText } from '@unchainedshop/types/filters';
|
|
8
|
-
import { ProductText } from '@unchainedshop/types/products';
|
|
6
|
+
import { Assortment, AssortmentText } from '@unchainedshop/types/assortments';
|
|
7
|
+
import { Filter, FilterText } from '@unchainedshop/types/filters';
|
|
8
|
+
import { Product, ProductText } from '@unchainedshop/types/products';
|
|
9
9
|
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
10
|
+
import { ProductStatus } from '@unchainedshop/core-products';
|
|
10
11
|
|
|
11
12
|
const { Locale } = localePkg;
|
|
12
13
|
|
|
@@ -16,6 +17,28 @@ export default async (
|
|
|
16
17
|
unchainedAPI: UnchainedCore,
|
|
17
18
|
): Promise<UnchainedLoaders['loaders']> => {
|
|
18
19
|
return {
|
|
20
|
+
assortmentLoader: new DataLoader<{ assortmentId: string; includeInactive: boolean }, Assortment>(
|
|
21
|
+
async (queries) => {
|
|
22
|
+
const assortmentIds = [...new Set(queries.map((q) => q.assortmentId).filter(Boolean))];
|
|
23
|
+
|
|
24
|
+
const assortments = await unchainedAPI.modules.assortments.findAssortments({
|
|
25
|
+
assortmentIds,
|
|
26
|
+
includeInactive: true,
|
|
27
|
+
includeLeaves: true,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return queries.map(({ assortmentId, includeInactive }) => {
|
|
31
|
+
return assortments.find((assortment) => {
|
|
32
|
+
if (assortment._id !== assortmentId) return false;
|
|
33
|
+
if (!includeInactive) {
|
|
34
|
+
return assortment.isActive === true;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
),
|
|
41
|
+
|
|
19
42
|
assortmentTextLoader: new DataLoader<{ assortmentId: string; locale: string }, AssortmentText>(
|
|
20
43
|
async (queries) => {
|
|
21
44
|
const assortmentIds = [...new Set(queries.map((q) => q.assortmentId).filter(Boolean))];
|
|
@@ -46,6 +69,22 @@ export default async (
|
|
|
46
69
|
},
|
|
47
70
|
),
|
|
48
71
|
|
|
72
|
+
filterLoader: new DataLoader<{ filterId: string }, Filter>(async (queries) => {
|
|
73
|
+
const filterIds = [...new Set(queries.map((q) => q.filterId).filter(Boolean))];
|
|
74
|
+
|
|
75
|
+
const filters = await unchainedAPI.modules.filters.findFilters({
|
|
76
|
+
filterIds,
|
|
77
|
+
includeInactive: true,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return queries.map(({ filterId }) => {
|
|
81
|
+
return filters.find((product) => {
|
|
82
|
+
if (product._id !== filterId) return false;
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}),
|
|
87
|
+
|
|
49
88
|
filterTextLoader: new DataLoader<
|
|
50
89
|
{ filterId: string; filterOptionValue?: string; locale: string },
|
|
51
90
|
FilterText
|
|
@@ -79,6 +118,27 @@ export default async (
|
|
|
79
118
|
});
|
|
80
119
|
}),
|
|
81
120
|
|
|
121
|
+
productLoader: new DataLoader<{ productId: string; includeDrafts: boolean }, Product>(
|
|
122
|
+
async (queries) => {
|
|
123
|
+
const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))];
|
|
124
|
+
|
|
125
|
+
const products = await unchainedAPI.modules.products.findProducts({
|
|
126
|
+
productIds,
|
|
127
|
+
includeDrafts: true,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return queries.map(({ productId, includeDrafts }) => {
|
|
131
|
+
return products.find((product) => {
|
|
132
|
+
if (product._id !== productId) return false;
|
|
133
|
+
if (!includeDrafts) {
|
|
134
|
+
return product.status === ProductStatus.ACTIVE;
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
),
|
|
141
|
+
|
|
82
142
|
productTextLoader: new DataLoader<{ productId: string; locale: string }, ProductText>(
|
|
83
143
|
async (queries) => {
|
|
84
144
|
const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))];
|
package/src/resolvers/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
|
|
2
2
|
import { JSONResolver, TimestampResolver, DateTimeResolver, DateResolver } from 'graphql-scalars';
|
|
3
3
|
import Query from './queries';
|
|
4
4
|
import Mutation from './mutations';
|
|
@@ -16,5 +16,7 @@ export default async function updateFilter(
|
|
|
16
16
|
|
|
17
17
|
if (!(await modules.filters.filterExists({ filterId }))) throw new FilterNotFoundError({ filterId });
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
await modules.filters.update(filterId, filter, context, { skipInvalidation: false }, userId);
|
|
20
|
+
|
|
21
|
+
return modules.filters.findFilter({ filterId });
|
|
20
22
|
}
|
|
@@ -7,7 +7,7 @@ export default async function product(
|
|
|
7
7
|
{ productId, slug }: { productId?: string; slug?: string },
|
|
8
8
|
{ modules, userId }: Context,
|
|
9
9
|
) {
|
|
10
|
-
log(`query product ${productId
|
|
10
|
+
log(`query product ${productId || slug}`, { userId });
|
|
11
11
|
|
|
12
12
|
if (!productId === !slug) throw new InvalidIdError({ productId, slug });
|
|
13
13
|
|