New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@itleadopencommerce/api-plugin-accounts

Package Overview
Dependencies
Maintainers
5
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itleadopencommerce/api-plugin-accounts - npm Package Compare versions

Comparing version 2.1.6 to 2.3.6

src/util/ensureCustomerGroup.js

2

package.json
{
"name": "@itleadopencommerce/api-plugin-accounts",
"description": "Accounts plugin for the Reaction API",
"version": "2.1.6",
"version": "2.3.6",
"main": "index.js",

@@ -6,0 +6,0 @@ "type": "module",

@@ -34,3 +34,5 @@ import Logger from "@reactioncommerce/logger";

shopId = null,
userId
userId,
company = null,
isSeller = false,
} = input;

@@ -60,39 +62,39 @@

// Old login for creating accounts
// if this is the first user created overall, add them to the
// `system-manager` and `accounts-manager` groups
// const anyAccount = await Accounts.findOne();
// if (!anyAccount) {
// const accountsManagerGroupId = await ensureAccountsManagerGroup(context);
// const systemManagerGroupId = await ensureSystemManagerGroup(context);
// groups.add(systemManagerGroupId);
// groups.add(accountsManagerGroupId);
// console.log("Hello! I am an alert from api-accounts-plugin!!");
// } else {
// console.log("Hello! I am an alert from api-accounts-plugin!!");
// // if this isn't the first account see if they were invited by another user
// // find all invites for this email address, for all shops, and add to all groups
// const emailAddresses = emails.map((emailRecord) => emailRecord.address.toLowerCase());
// invites = await AccountInvites.find({ email: { $in: emailAddresses } }).toArray();
// groups = invites.reduce((allGroupIds, invite) => {
// if (invite.groupIds) {
// invite.groupIds.forEach((groupId) => allGroupIds.add(groupId));
// }
async function ensureAndAddSellerGroups() {
const accountsManagerGroupId = await ensureAccountsManagerGroup(context);
const systemManagerGroupId = await ensureSystemManagerGroup(context);
groups.add(systemManagerGroupId);
groups.add(accountsManagerGroupId);
}
// if (invite.groupId) {
// allGroupIds.add(invite.groupId);
// }
async function ensureAndAddCustomerGroup() {
const customerGroupId = await ensureCustomerGroup(context);
groups.add(customerGroupId);
}
// return allGroupIds;
// }, new Set());
// }
// if user exists, update it
const existedUser = await Accounts.findOne({_id: userId});
if (existedUser && company) {
ensureAndAddSellerGroups();
}
// Rewriten logic for creating accounts and inventations
// Apply `system-manager` and `accounts-manager` groups for accounts what was not invited
// if this isn't the first account see if they were invited by another user
// find all invites for this email address, for all shops, and add to all groups
const emailAddresses = emails.map((emailRecord) => emailRecord.address.toLowerCase());
invites = await AccountInvites.find({ email: { $in: emailAddresses } }).toArray();
if (invites.length > 0) {
if (existedUser && !company) {
ensureAndAddCustomerGroup();
}
// Old login for creating accounts
// if this is the first user created overall, add them to the
// `system-manager` and `accounts-manager` groups
const anyAccount = await Accounts.findOne();
if (company || isSeller) {
ensureAndAddSellerGroups();
console.log("Hello! I am an alert from api-accounts-plugin!!");
} else {
console.log("Hello! I am an alert from api-accounts-plugin!!");
// if this isn't the first account see if they were invited by another user
// find all invites for this email address, for all shops, and add to all groups
ensureAndAddCustomerGroup();
const emailAddresses = emails.map((emailRecord) => emailRecord.address.toLowerCase());
invites = await AccountInvites.find({ email: { $in: emailAddresses } }).toArray();
groups = invites.reduce((allGroupIds, invite) => {

@@ -109,9 +111,30 @@ if (invite.groupIds) {

}, new Set());
} else {
const accountsManagerGroupId = await ensureAccountsManagerGroup(context);
const systemManagerGroupId = await ensureSystemManagerGroup(context);
groups.add(systemManagerGroupId);
groups.add(accountsManagerGroupId);
}
// Rewriten logic for creating accounts and inventations
// Apply `system-manager` and `accounts-manager` groups for accounts what was not invited
// if this isn't the first account see if they were invited by another user
// find all invites for this email address, for all shops, and add to all groups
// const emailAddresses = emails.map((emailRecord) => emailRecord.address.toLowerCase());
// invites = await AccountInvites.find({ email: { $in: emailAddresses } }).toArray();
// if (invites.length > 0) {
// groups = invites.reduce((allGroupIds, invite) => {
// if (invite.groupIds) {
// invite.groupIds.forEach((groupId) => allGroupIds.add(groupId));
// }
// if (invite.groupId) {
// allGroupIds.add(invite.groupId);
// }
// return allGroupIds;
// }, new Set());
// } else {
// const accountsManagerGroupId = await ensureAccountsManagerGroup(context);
// const systemManagerGroupId = await ensureSystemManagerGroup(context);
// groups.add(systemManagerGroupId);
// groups.add(accountsManagerGroupId);
// }
AccountSchema.validate(account);

@@ -118,0 +141,0 @@

@@ -16,4 +16,4 @@ /**

return Accounts.find({
groups: { $in: [null, []] }
groups: { $in: [null, [], 'customer', ['customer']] }
});
}
}

@@ -279,2 +279,60 @@ import SimpleSchema from "simpl-schema";

/**
* @name Commpany
* @memberof Schemas
* @type {SimpleSchema}
* @property {String} location required
* @property {String} tin required
* @property {String} companyType required
* @property {String} name required
* @property {String} address required
* @property {String} city required
* @property {String} site required
* @property {String} phone required
* @property {Boolean} verified optional
*/
export const Company = new SimpleSchema({
location: {
type: String,
defaultValue: "default",
},
tin: {
type: String,
defaultValue: "default",
},
companyType: {
type: String,
defaultValue: "default",
},
name: {
type: String,
defaultValue: "default",
},
site: {
type: String,
defaultValue: "default",
},
city: {
type: String,
defaultValue: "default",
},
phone: {
type: String,
defaultValue: "default",
},
address: {
type: String,
defaultValue: "default",
},
verified: {
type: Boolean,
defaultValue: false,
optional: true
}
});
/**
* @name Account

@@ -350,2 +408,6 @@ * @memberof Schemas

},
"company": {
type: Company,
optional: true
},
"groups": {

@@ -352,0 +414,0 @@ type: Array, // groupIds that user belongs to

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc