Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: node:12.14.1
- image: node:14.18.1

dependencies:
pre:
Expand All @@ -20,7 +20,7 @@ jobs:

deploy:
docker:
- image: node:12.14.1
- image: node:14.18.1

steps:
- checkout
Expand All @@ -35,7 +35,7 @@ jobs:

lint:
docker:
- image: node:12.14.1
- image: node:14.18.1

steps:
- checkout
Expand All @@ -50,7 +50,7 @@ jobs:

test:
docker:
- image: node:12.14.1
- image: node:14.18.1

steps:
- checkout
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.14.1
14.18.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"type": "module",
"engines": {
"node": ">=12.14.1"
"node": ">=14.18.1"
},
"homepage": "https://github.com/reactioncommerce/api-plugin-products",
"url": "https://github.com/reactioncommerce/api-plugin-products",
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ProductVariantInputSchema,
VariantMedia
} from "./simpleSchemas.js";
import startup from "./startup.js";

/**
* @summary Import and call this function to add this plugin to your API.
Expand Down Expand Up @@ -38,6 +39,9 @@ export default async function register(app) {
]
}
},
functionsByType: {
startup: [startup]
},
graphQL: {
resolvers,
schemas
Expand Down
2 changes: 1 addition & 1 deletion src/mutations/createProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default async function createProduct(context, input) {
isVisible: false,
shopId,
shouldAppearInSitemap: true,
supportedFulfillmentTypes: ["shipping"],
supportedFulfillmentTypes: initialProductData.supportedFulfillmentTypes || [],
title: "",
type: "simple",
updatedAt: createdAt,
Expand Down
11 changes: 6 additions & 5 deletions src/simpleSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const ProductVariant = new SimpleSchema({
* @property {String} publishedProductHash optional
* @property {String} shopId Product ShopID
* @property {Boolean} shouldAppearInSitemap optional, whether this product should appear in auto-generated sitemap.xml
* @property {String[]} supportedFulfillmentTypes Types of fulfillment ("shipping", "pickup", etc) allowed for this product
// * @property {String[]} supportedFulfillmentTypes Types of fulfillment ("shipping", "pickup", etc) allowed for this product
* @property {String} template optional
* @property {String} title Product Title
* @property {String} twitterMsg optional
Expand Down Expand Up @@ -382,10 +382,11 @@ export const Product = new SimpleSchema({
type: Boolean,
optional: true
},
"supportedFulfillmentTypes": {
type: Array
},
"supportedFulfillmentTypes.$": String,
// This is extended in startup with dynamic values for allowedValues
// "supportedFulfillmentTypes": {
// type: Array
// },
// "supportedFulfillmentTypes.$": String,
"template": {
type: String,
optional: true
Expand Down
37 changes: 37 additions & 0 deletions src/startup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Logger from "@reactioncommerce/logger";

/**
* @summary Extend the schema with updated allowedValues
* @param {Object} context Startup context
* @returns {undefined}
*/
async function extendSchemas(context) {
let allFulfillmentTypesArray = context.allRegisteredFulfillmentTypes?.registeredFulfillmentTypes;

if (!allFulfillmentTypesArray || allFulfillmentTypesArray.length === 0) {
Logger.warn("No fulfillment types available, setting 'shipping' as default");
allFulfillmentTypesArray = ["shipping"];
}

const { simpleSchemas: { Product } } = context;

const schemaProductExtension = {
"supportedFulfillmentTypes": {
type: Array
},
"supportedFulfillmentTypes.$": {
type: String,
allowedValues: allFulfillmentTypesArray
}
};
Product.extend(schemaProductExtension);
}

/**
* @summary Called on startup
* @param {Object} context Startup context
* @returns {undefined}
*/
export default async function productStartup(context) {
await extendSchemas(context);
}