diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountAddressBookEntry.js b/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountAddressBookEntry.js index 78a2d463c2d..0de98ff4cb1 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountAddressBookEntry.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountAddressBookEntry.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId } from "../../xforms/id.js"; /** @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js"; */ export default async function addAccountAddressBookEntry(parentResult, { input }, context) { const { accountId, address, clientMutationId = null } = input; - const dbAccountId = decodeAccountOpaqueId(accountId); + const dbAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId; const updatedAddress = await context.mutations.addressBookAdd(context, address, dbAccountId); return { address: updatedAddress, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountEmailRecord.js b/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountEmailRecord.js index a5bd696aa7d..94853273342 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountEmailRecord.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountEmailRecord.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId } from "../../xforms/id.js"; /** @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js"; */ export default async function addAccountEmailRecord(_, { input }, context) { const { accountId, email, clientMutationId = null } = input; - const decodedAccountId = decodeAccountOpaqueId(accountId); + const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId; const updatedAccount = await context.mutations.addAccountEmailRecord(context, { accountId: decodedAccountId, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountToGroup.js b/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountToGroup.js index ecb7d15d430..3807744e443 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountToGroup.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/addAccountToGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js"; /** @@ -16,8 +17,8 @@ import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js"; export default async function addAccountToGroup(parentResult, { input }, context) { const { accountId: opaqueAccountId, groupId: opaqueGroupId, clientMutationId = null } = input; - const accountId = decodeAccountOpaqueId(opaqueAccountId); - const groupId = decodeGroupOpaqueId(opaqueGroupId); + const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId; + const groupId = isOpaqueId(opaqueGroupId) ? decodeGroupOpaqueId(opaqueGroupId) : opaqueGroupId; const group = await context.mutations.addAccountToGroup(context, { accountId, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/createAccount.js b/packages/api-plugin-accounts/src/resolvers/Mutation/createAccount.js index cad64f9cead..60f5aad2204 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/createAccount.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/createAccount.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -14,7 +15,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; */ export default async function createAccount(_, { input }, context) { const { shopId, clientMutationId } = input; - const decodedShopId = decodeShopOpaqueId(shopId); + const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const transformedInput = { ...input, shopId: decodedShopId }; diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/createAccountGroup.js b/packages/api-plugin-accounts/src/resolvers/Mutation/createAccountGroup.js index 313904ed93d..f6f29e73860 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/createAccountGroup.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/createAccountGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,8 +20,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; */ export default async function createAccountGroup(_, { input }, context) { const { shopId } = input; - const decodedShopId = decodeShopOpaqueId(shopId); - + const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const transformedInput = { ...input, shopId: decodedShopId }; return context.mutations.createAccountGroup(context, transformedInput); diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/grantAdminUIAccess.js b/packages/api-plugin-accounts/src/resolvers/Mutation/grantAdminUIAccess.js index 7b48aac7aa7..03d1431f186 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/grantAdminUIAccess.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/grantAdminUIAccess.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,8 +19,8 @@ export default async function grantAdminUIAccess(parentResult, { input = {} }, c shopId: opaqueShopId } = input; - const accountId = decodeAccountOpaqueId(opaqueAccountId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const account = await context.mutations.grantAdminUIAccess(context, { accountId, shopId }); diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/inviteShopMember.js b/packages/api-plugin-accounts/src/resolvers/Mutation/inviteShopMember.js index 6953362ce88..59eab0f612e 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/inviteShopMember.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/inviteShopMember.js @@ -1,4 +1,5 @@ import ReactionError from "@reactioncommerce/reaction-error"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -32,9 +33,8 @@ export default async function inviteShopMember(_, { input }, context) { groupIds = [groupId]; } - const decodedGroupIds = groupIds.map((encodedGroupId) => decodeGroupOpaqueId(encodedGroupId)); - const decodedShopId = decodeShopOpaqueId(shopId); - + const decodedGroupIds = groupIds.map((encodedGroupId) => (isOpaqueId(encodedGroupId) ? decodeGroupOpaqueId(encodedGroupId) : encodedGroupId)); + const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const account = await context.mutations.inviteShopMember(context, { email, groupIds: decodedGroupIds, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountAddressBookEntry.js b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountAddressBookEntry.js index 4cf89115b0f..b9dc5f5ea57 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountAddressBookEntry.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountAddressBookEntry.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeAddressOpaqueId } from "../../xforms/id.js"; /** @@ -15,8 +16,8 @@ import { decodeAccountOpaqueId, decodeAddressOpaqueId } from "../../xforms/id.js */ export default async function removeAccountAddressBookEntry(_, { input }, context) { const { accountId, addressId, clientMutationId = null } = input; - const decodedAccountId = decodeAccountOpaqueId(accountId); - const decodedAddressId = decodeAddressOpaqueId(addressId); + const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId; + const decodedAddressId = isOpaqueId(addressId) ? decodeAddressOpaqueId(addressId) : addressId; const removedAddress = await context.mutations.removeAccountAddressBookEntry(context, { addressId: decodedAddressId, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountEmailRecord.js b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountEmailRecord.js index 04c20f30c45..a9e4a44dd54 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountEmailRecord.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountEmailRecord.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId } from "../../xforms/id.js"; /** @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js"; */ export default async function removeAccountEmailRecord(_, { input }, context) { const { accountId, email, clientMutationId = null } = input; - const decodedAccountId = decodeAccountOpaqueId(accountId); + const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId; const updatedAccount = await context.mutations.removeAccountEmailRecord(context, { accountId: decodedAccountId, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountFromGroup.js b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountFromGroup.js index 4f2a0a09538..97bf4544d10 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountFromGroup.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountFromGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js"; /** @@ -16,8 +17,8 @@ import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js"; export default async function removeAccountFromGroup(parentResult, { input }, context) { const { accountId: opaqueAccountId, groupId: opaqueGroupId, clientMutationId = null } = input; - const accountId = decodeAccountOpaqueId(opaqueAccountId); - const groupId = decodeGroupOpaqueId(opaqueGroupId); + const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId; + const groupId = isOpaqueId(opaqueGroupId) ? decodeGroupOpaqueId(opaqueGroupId) : opaqueGroupId; const group = await context.mutations.removeAccountFromGroup(context, { accountId, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountGroup.js b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountGroup.js index 7d5505fb38b..b0a2a1f2b3c 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountGroup.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/removeAccountGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -15,8 +16,8 @@ import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; export default async function removeAccountGroup(_, { input }, context) { const { groupId, shopId, clientMutationId } = input; - const decodedGroupId = decodeGroupOpaqueId(groupId); - const decodedShopId = decodeShopOpaqueId(shopId); + const decodedGroupId = isOpaqueId(groupId) ? decodeGroupOpaqueId(groupId) : groupId; + const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const group = context.mutations.removeAccountGroup(context, { groupId: decodedGroupId, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/revokeAdminUIAccess.js b/packages/api-plugin-accounts/src/resolvers/Mutation/revokeAdminUIAccess.js index f814ea796ba..524f2d75e80 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/revokeAdminUIAccess.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/revokeAdminUIAccess.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,8 +19,8 @@ export default async function revokeAdminUIAccess(parentResult, { input = {} }, shopId: opaqueShopId } = input; - const accountId = decodeAccountOpaqueId(opaqueAccountId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const accountId = isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const account = await context.mutations.revokeAdminUIAccess(context, { accountId, shopId }); diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/setAccountDefaultEmail.js b/packages/api-plugin-accounts/src/resolvers/Mutation/setAccountDefaultEmail.js index 95acb3f4761..cad6748f2b9 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/setAccountDefaultEmail.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/setAccountDefaultEmail.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId } from "../../xforms/id.js"; /** @@ -15,7 +16,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js"; */ export default async function setAccountDefaultEmail(_, { input }, context) { const { accountId, email, clientMutationId = null } = input; - const decodedAccountId = decodeAccountOpaqueId(accountId); + const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId; const updatedAccount = await context.mutations.setAccountDefaultEmail(context, { accountId: decodedAccountId, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccount.js b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccount.js index e324960e1a3..da5c608afbe 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccount.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccount.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId } from "../../xforms/id.js"; /** @@ -19,7 +20,7 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js"; */ export default async function updateAccount(_, { input }, context) { const { accountId, clientMutationId = null, ...otherInput } = input; - const decodedAccountId = decodeAccountOpaqueId(accountId); + const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId; const updatedAccount = await context.mutations.updateAccount(context, { ...otherInput, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountAddressBookEntry.js b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountAddressBookEntry.js index ec8fe525257..9c48f358b4e 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountAddressBookEntry.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountAddressBookEntry.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { assocAddressInternalId, decodeAccountOpaqueId } from "../../xforms/id.js"; /** @@ -17,7 +18,7 @@ import { assocAddressInternalId, decodeAccountOpaqueId } from "../../xforms/id.j */ export default async function updateAccountAddressBookEntry(_, { input }, context) { const { accountId, addressId, clientMutationId, type, updates } = input; - const decodedAccountId = decodeAccountOpaqueId(accountId); + const decodedAccountId = isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId; const address = assocAddressInternalId({ ...updates, _id: addressId }); const updatedAddress = await context.mutations.updateAccountAddressBookEntry(context, { diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountGroup.js b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountGroup.js index a2d74d6f6b3..4f67ad8652e 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountGroup.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAccountGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,8 +20,8 @@ import { decodeGroupOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; export default async function updateAccountGroup(_, { input }, context) { const { groupId, shopId, clientMutationId } = input; - const decodedGroupId = decodeGroupOpaqueId(groupId); - const decodedShopId = decodeShopOpaqueId(shopId); + const decodedGroupId = isOpaqueId(groupId) ? decodeGroupOpaqueId(groupId) : groupId; + const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const group = context.mutations.updateAccountGroup(context, { ...input, diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAdminUIAccess.js b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAdminUIAccess.js index e93d5a30796..e8e094bc865 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/updateAdminUIAccess.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/updateAdminUIAccess.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,8 +19,8 @@ export default async function updateAdminUIAccess(parentResult, { input = {} }, shopIds: opaqueShopIds } = input; - const accountIds = opaqueAccountIds.map((opaqueAccountId) => decodeAccountOpaqueId(opaqueAccountId)); - const shopIds = opaqueShopIds.map((opaqueShopId) => decodeShopOpaqueId(opaqueShopId)); + const accountIds = opaqueAccountIds.map((opaqueAccountId) => (isOpaqueId(opaqueAccountId) ? decodeAccountOpaqueId(opaqueAccountId) : opaqueAccountId)); + const shopIds = opaqueShopIds.map((opaqueShopId) => (isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId)); const accounts = await context.mutations.updateAdminUIAccess(context, { accountIds, shopIds }); diff --git a/packages/api-plugin-accounts/src/resolvers/Mutation/updateGroupsForAccounts.js b/packages/api-plugin-accounts/src/resolvers/Mutation/updateGroupsForAccounts.js index 390a39b18b0..e1d2c76172c 100644 --- a/packages/api-plugin-accounts/src/resolvers/Mutation/updateGroupsForAccounts.js +++ b/packages/api-plugin-accounts/src/resolvers/Mutation/updateGroupsForAccounts.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js"; /** @@ -16,8 +17,8 @@ import { decodeAccountOpaqueId, decodeGroupOpaqueId } from "../../xforms/id.js"; export default async function updateGroupsForAccounts(parentResult, { input }, context) { const { accountIds: opaqueAccountIds, groupIds: opaqueGroupIds, clientMutationId = null } = input; - const accountIds = opaqueAccountIds.map((id) => decodeAccountOpaqueId(id)); - const groupIds = opaqueGroupIds.map((id) => decodeGroupOpaqueId(id)); + const accountIds = opaqueAccountIds.map((id) => (isOpaqueId(id) ? decodeAccountOpaqueId(id) : id)); + const groupIds = opaqueGroupIds.map((id) => (isOpaqueId(id) ? decodeGroupOpaqueId(id) : id)); const accounts = await context.mutations.updateGroupsForAccounts(context, { accountIds, diff --git a/packages/api-plugin-accounts/src/resolvers/Query/account.js b/packages/api-plugin-accounts/src/resolvers/Query/account.js index a9463c3ae0e..0253730f4ff 100644 --- a/packages/api-plugin-accounts/src/resolvers/Query/account.js +++ b/packages/api-plugin-accounts/src/resolvers/Query/account.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId } from "../../xforms/id.js"; /** @@ -12,6 +13,6 @@ import { decodeAccountOpaqueId } from "../../xforms/id.js"; * @returns {Promise} user account object */ export default function account(_, { id }, context) { - const dbAccountId = decodeAccountOpaqueId(id); + const dbAccountId = isOpaqueId(id) ? decodeAccountOpaqueId(id) : id; return context.queries.userAccount(context, dbAccountId); } diff --git a/packages/api-plugin-accounts/src/resolvers/Query/accounts.js b/packages/api-plugin-accounts/src/resolvers/Query/accounts.js index 5f5c2ad992e..f3fd6bacb7f 100644 --- a/packages/api-plugin-accounts/src/resolvers/Query/accounts.js +++ b/packages/api-plugin-accounts/src/resolvers/Query/accounts.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeGroupOpaqueId } from "../../xforms/id.js"; /** @@ -20,7 +21,7 @@ export default async function accounts(_, args, context, info) { let groupIds; if (opaqueGroupIds) { - groupIds = opaqueGroupIds.map((opaqueGroupId) => decodeGroupOpaqueId(opaqueGroupId)); + groupIds = opaqueGroupIds.map((opaqueGroupId) => (isOpaqueId(opaqueGroupId) ? decodeGroupOpaqueId(opaqueGroupId) : opaqueGroupId)); } const query = await context.queries.accounts(context, { groupIds, notInAnyGroups }); diff --git a/packages/api-plugin-accounts/src/resolvers/Query/group.js b/packages/api-plugin-accounts/src/resolvers/Query/group.js index 3c263a75255..d52e279a649 100644 --- a/packages/api-plugin-accounts/src/resolvers/Query/group.js +++ b/packages/api-plugin-accounts/src/resolvers/Query/group.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeGroupOpaqueId } from "../../xforms/id.js"; /** @@ -12,6 +13,6 @@ import { decodeGroupOpaqueId } from "../../xforms/id.js"; * @returns {Promise} group object */ export default async function group(_, { id }, context) { - const dbGroupId = decodeGroupOpaqueId(id); + const dbGroupId = isOpaqueId(id) ? decodeGroupOpaqueId(id) : id; return context.queries.group(context, dbGroupId); } diff --git a/packages/api-plugin-accounts/src/resolvers/Query/groups.js b/packages/api-plugin-accounts/src/resolvers/Query/groups.js index c8ddf9e24e3..94ceb3451bb 100644 --- a/packages/api-plugin-accounts/src/resolvers/Query/groups.js +++ b/packages/api-plugin-accounts/src/resolvers/Query/groups.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -24,7 +25,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; */ export default async function groups(_, { shopId, ...connectionArgs }, context, info) { // Transform ID from base64 - const dbShopId = decodeShopOpaqueId(shopId); + const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const query = await context.queries.groups(context, dbShopId); return getPaginatedResponse(query, connectionArgs, { diff --git a/packages/api-plugin-accounts/src/resolvers/Query/invitations.js b/packages/api-plugin-accounts/src/resolvers/Query/invitations.js index e47d9f8b439..51a88d57802 100644 --- a/packages/api-plugin-accounts/src/resolvers/Query/invitations.js +++ b/packages/api-plugin-accounts/src/resolvers/Query/invitations.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,7 +21,7 @@ export default async function invitations(_, args, context, info) { let shopIds; if (Array.isArray(encodedShopIds) && encodedShopIds.length > 0) { - shopIds = encodedShopIds.map((shopId) => decodeShopOpaqueId(shopId)); + shopIds = encodedShopIds.map((shopId) => (isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId)); } const query = await context.queries.invitations(context, { shopIds }); diff --git a/packages/api-plugin-address-validation/src/resolvers/Mutation/createAddressValidationRule.js b/packages/api-plugin-address-validation/src/resolvers/Mutation/createAddressValidationRule.js index 58ff03fb9fd..bc480be6a54 100644 --- a/packages/api-plugin-address-validation/src/resolvers/Mutation/createAddressValidationRule.js +++ b/packages/api-plugin-address-validation/src/resolvers/Mutation/createAddressValidationRule.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,7 +19,7 @@ export default async function createAddressValidationRule(parentResult, { input ...otherInput } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const addressValidationRule = await context.mutations.createAddressValidationRule(context, { ...otherInput, diff --git a/packages/api-plugin-address-validation/src/resolvers/Mutation/deleteAddressValidationRule.js b/packages/api-plugin-address-validation/src/resolvers/Mutation/deleteAddressValidationRule.js index ab19d7f6649..15ea56a660e 100644 --- a/packages/api-plugin-address-validation/src/resolvers/Mutation/deleteAddressValidationRule.js +++ b/packages/api-plugin-address-validation/src/resolvers/Mutation/deleteAddressValidationRule.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAddressValidationRuleOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,8 +19,8 @@ export default async function deleteAddressValidationRule(parentResult, { input shopId: opaqueShopId } = input; - const _id = decodeAddressValidationRuleOpaqueId(opaqueRuleId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const _id = isOpaqueId(opaqueRuleId) ? decodeAddressValidationRuleOpaqueId(opaqueRuleId) : opaqueRuleId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const addressValidationRule = await context.mutations.deleteAddressValidationRule(context, { _id, diff --git a/packages/api-plugin-address-validation/src/resolvers/Mutation/updateAddressValidationRule.js b/packages/api-plugin-address-validation/src/resolvers/Mutation/updateAddressValidationRule.js index 7834a2424ce..56add6e52d0 100644 --- a/packages/api-plugin-address-validation/src/resolvers/Mutation/updateAddressValidationRule.js +++ b/packages/api-plugin-address-validation/src/resolvers/Mutation/updateAddressValidationRule.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAddressValidationRuleOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,8 +20,8 @@ export default async function updateAddressValidationRule(parentResult, { input ...otherInput } = input; - const _id = decodeAddressValidationRuleOpaqueId(opaqueRuleId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const _id = isOpaqueId(opaqueRuleId) ? decodeAddressValidationRuleOpaqueId(opaqueRuleId) : opaqueRuleId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const addressValidationRule = await context.mutations.updateAddressValidationRule(context, { ...otherInput, diff --git a/packages/api-plugin-address-validation/src/resolvers/Query/addressValidation.js b/packages/api-plugin-address-validation/src/resolvers/Query/addressValidation.js index b3ae33f209d..9f9992e411e 100644 --- a/packages/api-plugin-address-validation/src/resolvers/Query/addressValidation.js +++ b/packages/api-plugin-address-validation/src/resolvers/Query/addressValidation.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -13,6 +14,6 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; * @returns {Promise} Promise that resolves with an object with results */ export default async function addressValidation(_, { address, shopId: opaqueShopId }, context) { - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; return context.queries.addressValidation({ address, shopId }, context); } diff --git a/packages/api-plugin-address-validation/src/resolvers/Query/addressValidationRules.js b/packages/api-plugin-address-validation/src/resolvers/Query/addressValidationRules.js index 7cdff05605a..71ca5ddacf5 100644 --- a/packages/api-plugin-address-validation/src/resolvers/Query/addressValidationRules.js +++ b/packages/api-plugin-address-validation/src/resolvers/Query/addressValidationRules.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -22,7 +23,7 @@ export default async function addressValidationRules(parentResult, args, context ...connectionArgs } = args; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const cursor = await context.queries.addressValidationRules(context, { serviceNames, diff --git a/packages/api-plugin-authorization-simple/src/resolvers/Query/roles.js b/packages/api-plugin-authorization-simple/src/resolvers/Query/roles.js index c1b46c8a1a2..af5cb3f9004 100644 --- a/packages/api-plugin-authorization-simple/src/resolvers/Query/roles.js +++ b/packages/api-plugin-authorization-simple/src/resolvers/Query/roles.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -13,7 +14,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; */ export default async function roles(_, { shopId, ...connectionArgs }, context, info) { // Transform ID from base64 - const dbShopId = decodeShopOpaqueId(shopId); + const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const query = await context.queries.roles(context, dbShopId); diff --git a/packages/api-plugin-carts/src/resolvers/Mutation/addCartItems.js b/packages/api-plugin-carts/src/resolvers/Mutation/addCartItems.js index 783a70c9ce5..eabe3754210 100644 --- a/packages/api-plugin-carts/src/resolvers/Mutation/addCartItems.js +++ b/packages/api-plugin-carts/src/resolvers/Mutation/addCartItems.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartItemsOpaqueIds, decodeCartOpaqueId } from "../../xforms/id.js"; /** @@ -17,7 +18,7 @@ import { decodeCartItemsOpaqueIds, decodeCartOpaqueId } from "../../xforms/id.js */ export default async function addCartItems(parentResult, { input }, context) { const { cartId: opaqueCartId, clientMutationId = null, items: itemsInput, cartToken } = input; - const cartId = decodeCartOpaqueId(opaqueCartId); + const cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; const items = decodeCartItemsOpaqueIds(itemsInput); const { diff --git a/packages/api-plugin-carts/src/resolvers/Mutation/createCart.js b/packages/api-plugin-carts/src/resolvers/Mutation/createCart.js index d5c24933b7d..ed9badcf0f5 100644 --- a/packages/api-plugin-carts/src/resolvers/Mutation/createCart.js +++ b/packages/api-plugin-carts/src/resolvers/Mutation/createCart.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartItemsOpaqueIds, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -15,7 +16,7 @@ import { decodeCartItemsOpaqueIds, decodeShopOpaqueId } from "../../xforms/id.js */ export default async function createCart(parentResult, { input }, context) { const { clientMutationId = null, items: itemsInput, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const items = decodeCartItemsOpaqueIds(itemsInput); const { diff --git a/packages/api-plugin-carts/src/resolvers/Mutation/reconcileCarts.js b/packages/api-plugin-carts/src/resolvers/Mutation/reconcileCarts.js index ff56b734cc8..4c9c1980f90 100644 --- a/packages/api-plugin-carts/src/resolvers/Mutation/reconcileCarts.js +++ b/packages/api-plugin-carts/src/resolvers/Mutation/reconcileCarts.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId } from "../../xforms/id.js"; /** @@ -23,7 +24,7 @@ export default async function reconcileCarts(parentResult, { input }, context) { } = input; const { cart } = await context.mutations.reconcileCarts(context, { - anonymousCartId: decodeCartOpaqueId(opaqueAnonymousCartId), + anonymousCartId: isOpaqueId(opaqueAnonymousCartId) ? decodeCartOpaqueId(opaqueAnonymousCartId) : opaqueAnonymousCartId, cartToken, mode }); diff --git a/packages/api-plugin-carts/src/resolvers/Mutation/removeCartItems.js b/packages/api-plugin-carts/src/resolvers/Mutation/removeCartItems.js index 22b6457b8a3..aabcae0a41f 100644 --- a/packages/api-plugin-carts/src/resolvers/Mutation/removeCartItems.js +++ b/packages/api-plugin-carts/src/resolvers/Mutation/removeCartItems.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartItemOpaqueId, decodeCartOpaqueId } from "../../xforms/id.js"; /** @@ -17,8 +18,8 @@ import { decodeCartItemOpaqueId, decodeCartOpaqueId } from "../../xforms/id.js"; export default async function removeCartItems(parentResult, { input }, context) { const { cartId: opaqueCartId, clientMutationId = null, cartItemIds: opaqueCartItemIds, cartToken } = input; - const cartId = decodeCartOpaqueId(opaqueCartId); - const cartItemIds = opaqueCartItemIds.map(decodeCartItemOpaqueId); + const cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; + const cartItemIds = opaqueCartItemIds.map((opaqueCartItemId) => (isOpaqueId(opaqueCartItemId) ? decodeCartItemOpaqueId(opaqueCartItemId) : opaqueCartItemId)); const { cart } = await context.mutations.removeCartItems(context, { cartId, diff --git a/packages/api-plugin-carts/src/resolvers/Mutation/setEmailOnAnonymousCart.js b/packages/api-plugin-carts/src/resolvers/Mutation/setEmailOnAnonymousCart.js index f5aa67a0f15..ee276957a98 100644 --- a/packages/api-plugin-carts/src/resolvers/Mutation/setEmailOnAnonymousCart.js +++ b/packages/api-plugin-carts/src/resolvers/Mutation/setEmailOnAnonymousCart.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId } from "../../xforms/id.js"; /** @@ -22,7 +23,7 @@ export default async function setEmailOnAnonymousCart(parentResult, { input }, c cartToken } = input; - const cartId = decodeCartOpaqueId(opaqueCartId); + const cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; const { cart } = await context.mutations.setEmailOnAnonymousCart(context, { cartId, diff --git a/packages/api-plugin-carts/src/resolvers/Mutation/setShippingAddressOnCart.js b/packages/api-plugin-carts/src/resolvers/Mutation/setShippingAddressOnCart.js index 681479ecd4b..6f45307bf57 100644 --- a/packages/api-plugin-carts/src/resolvers/Mutation/setShippingAddressOnCart.js +++ b/packages/api-plugin-carts/src/resolvers/Mutation/setShippingAddressOnCart.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAddressOpaqueId, decodeCartOpaqueId } from "../../xforms/id.js"; /** @@ -18,8 +19,8 @@ import { decodeAddressOpaqueId, decodeCartOpaqueId } from "../../xforms/id.js"; export default async function setShippingAddressOnCart(parentResult, { input }, context) { const { address, addressId: opaqueAddressId, cartId: opaqueCartId, cartToken, clientMutationId = null } = input; - const addressId = decodeAddressOpaqueId(opaqueAddressId); - const cartId = decodeCartOpaqueId(opaqueCartId); + const addressId = isOpaqueId(opaqueAddressId) ? decodeAddressOpaqueId(opaqueAddressId) : opaqueAddressId; + const cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; const { cart } = await context.mutations.setShippingAddressOnCart(context, { address, diff --git a/packages/api-plugin-carts/src/resolvers/Mutation/updateCartItemsQuantity.js b/packages/api-plugin-carts/src/resolvers/Mutation/updateCartItemsQuantity.js index 3fa1fe92956..375a49c8b94 100644 --- a/packages/api-plugin-carts/src/resolvers/Mutation/updateCartItemsQuantity.js +++ b/packages/api-plugin-carts/src/resolvers/Mutation/updateCartItemsQuantity.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartItemOpaqueId, decodeCartOpaqueId } from "../../xforms/id.js"; /** @@ -19,8 +20,11 @@ import { decodeCartItemOpaqueId, decodeCartOpaqueId } from "../../xforms/id.js"; export default async function updateCartItemsQuantity(parentResult, { input }, context) { const { cartId: opaqueCartId, clientMutationId = null, items: itemsInput, cartToken } = input; - const cartId = decodeCartOpaqueId(opaqueCartId); - const items = itemsInput.map((item) => ({ cartItemId: decodeCartItemOpaqueId(item.cartItemId), quantity: item.quantity })); + const cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; + const items = itemsInput.map((item) => ({ + cartItemId: isOpaqueId(item.cartItemId) ? decodeCartItemOpaqueId(item.cartItemId) : item.cartItemId, + quantity: item.quantity + })); const { cart } = await context.mutations.updateCartItemsQuantity(context, { cartId, diff --git a/packages/api-plugin-carts/src/resolvers/Query/accountCartByAccountId.js b/packages/api-plugin-carts/src/resolvers/Query/accountCartByAccountId.js index 0cdbdcc5112..177133d38ba 100644 --- a/packages/api-plugin-carts/src/resolvers/Query/accountCartByAccountId.js +++ b/packages/api-plugin-carts/src/resolvers/Query/accountCartByAccountId.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,7 +17,7 @@ export default async function accountCartByAccountId(parentResult, args, context const { accountId, shopId } = args; return context.queries.accountCartByAccountId(context, { - accountId: decodeAccountOpaqueId(accountId), - shopId: decodeShopOpaqueId(shopId) + accountId: isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); } diff --git a/packages/api-plugin-carts/src/resolvers/Query/anonymousCartByCartId.js b/packages/api-plugin-carts/src/resolvers/Query/anonymousCartByCartId.js index 4f7623ffa42..2f51b32d5c0 100644 --- a/packages/api-plugin-carts/src/resolvers/Query/anonymousCartByCartId.js +++ b/packages/api-plugin-carts/src/resolvers/Query/anonymousCartByCartId.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId } from "../../xforms/id.js"; /** @@ -16,7 +17,7 @@ export default async function anonymousCartByCartId(parentResult, args, context) const { cartId, cartToken } = args; return context.queries.anonymousCartByCartId(context, { - cartId: decodeCartOpaqueId(cartId), + cartId: isOpaqueId(cartId) ? decodeCartOpaqueId(cartId) : cartId, cartToken }); } diff --git a/packages/api-plugin-carts/src/xforms/id.js b/packages/api-plugin-carts/src/xforms/id.js index 72728aa3770..0742a74fe65 100644 --- a/packages/api-plugin-carts/src/xforms/id.js +++ b/packages/api-plugin-carts/src/xforms/id.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; @@ -34,8 +35,10 @@ export function decodeCartItemsOpaqueIds(items) { return items.map((item) => ({ ...item, productConfiguration: { - productId: decodeProductOpaqueId(item.productConfiguration.productId), - productVariantId: decodeProductOpaqueId(item.productConfiguration.productVariantId) + productId: isOpaqueId(item.productConfiguration.productId) ? + decodeProductOpaqueId(item.productConfiguration.productId) : item.productConfiguration.productId, + productVariantId: isOpaqueId(item.productConfiguration.productVariantId) ? + decodeProductOpaqueId(item.productConfiguration.productVariantId) : item.productConfiguration.productVariantId } })); } diff --git a/packages/api-plugin-catalogs/src/resolvers/Mutation/publishProductsToCatalog.js b/packages/api-plugin-catalogs/src/resolvers/Mutation/publishProductsToCatalog.js index 639c64d7a69..b91cd4d4ba6 100644 --- a/packages/api-plugin-catalogs/src/resolvers/Mutation/publishProductsToCatalog.js +++ b/packages/api-plugin-catalogs/src/resolvers/Mutation/publishProductsToCatalog.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId } from "../../xforms/id.js"; /** @@ -12,6 +13,6 @@ import { decodeProductOpaqueId } from "../../xforms/id.js"; */ export default async function publishProductsToCatalog(_, args, context) { const { productIds } = args; - const internalProductIds = productIds.map(decodeProductOpaqueId); + const internalProductIds = productIds.map((productId) => (isOpaqueId(productId) ? decodeProductOpaqueId(productId) : productId)); return context.mutations.publishProducts(context, internalProductIds); } diff --git a/packages/api-plugin-catalogs/src/resolvers/Query/catalogItemProduct.js b/packages/api-plugin-catalogs/src/resolvers/Query/catalogItemProduct.js index b32c4810623..38bdb95a524 100644 --- a/packages/api-plugin-catalogs/src/resolvers/Query/catalogItemProduct.js +++ b/packages/api-plugin-catalogs/src/resolvers/Query/catalogItemProduct.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCatalogItemOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -15,11 +16,11 @@ import { decodeCatalogItemOpaqueId, decodeShopOpaqueId } from "../../xforms/id.j export default async function catalogItemProduct(_, args, context) { const { shopId: opaqueShopId, slugOrId } = args; - const catalogIdOrProductSlug = decodeCatalogItemOpaqueId(slugOrId); + const catalogIdOrProductSlug = isOpaqueId(slugOrId) ? decodeCatalogItemOpaqueId(slugOrId) : slugOrId; let shopId; if (opaqueShopId) { - shopId = decodeShopOpaqueId(opaqueShopId); + shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; } return context.queries.catalogItemProduct(context, { diff --git a/packages/api-plugin-catalogs/src/resolvers/Query/catalogItems.js b/packages/api-plugin-catalogs/src/resolvers/Query/catalogItems.js index 8a6829b667d..94bf180b855 100644 --- a/packages/api-plugin-catalogs/src/resolvers/Query/catalogItems.js +++ b/packages/api-plugin-catalogs/src/resolvers/Query/catalogItems.js @@ -2,6 +2,7 @@ import Logger from "@reactioncommerce/logger"; import ReactionError from "@reactioncommerce/reaction-error"; import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; import xformCatalogBooleanFilters from "../../utils/catalogBooleanFilters.js"; @@ -23,8 +24,8 @@ import xformCatalogBooleanFilters from "../../utils/catalogBooleanFilters.js"; export default async function catalogItems(_, args, context, info) { const { shopIds: opaqueShopIds, tagIds: opaqueTagIds, booleanFilters, searchQuery, ...connectionArgs } = args; - const shopIds = opaqueShopIds && opaqueShopIds.map(decodeShopOpaqueId); - const tagIds = opaqueTagIds && opaqueTagIds.map(decodeTagOpaqueId); + const shopIds = opaqueShopIds && opaqueShopIds.map((opaqueShopId) => (isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId)); + const tagIds = opaqueTagIds && opaqueTagIds.map((opaqueTagId) => (isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId)); let catalogBooleanFilters = {}; if (Array.isArray(booleanFilters) && booleanFilters.length) { diff --git a/packages/api-plugin-catalogs/src/resolvers/Query/vendors.js b/packages/api-plugin-catalogs/src/resolvers/Query/vendors.js index 4e870bfe9dc..af507e06022 100644 --- a/packages/api-plugin-catalogs/src/resolvers/Query/vendors.js +++ b/packages/api-plugin-catalogs/src/resolvers/Query/vendors.js @@ -1,5 +1,6 @@ import getPaginatedResponseFromAggregate from "@reactioncommerce/api-utils/graphql/getPaginatedResponseFromAggregate.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -18,8 +19,8 @@ import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; export default async function vendors(_, args, context, info) { const { shopIds: opaqueShopIds, tagIds: opaqueTagIds, ...connectionArgs } = args; - const shopIds = opaqueShopIds && opaqueShopIds.map(decodeShopOpaqueId); - const tagIds = opaqueTagIds && opaqueTagIds.map(decodeTagOpaqueId); + const shopIds = opaqueShopIds && opaqueShopIds.map((opaqueShopId) => (isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId)); + const tagIds = opaqueTagIds && opaqueTagIds.map((opaqueTagId) => (isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId)); const { collection, pipeline } = await context.queries.vendors(context, { shopIds, diff --git a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/applyDiscountCodeToCart.js b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/applyDiscountCodeToCart.js index 71bed4cf83c..070bf2d68fb 100644 --- a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/applyDiscountCodeToCart.js +++ b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/applyDiscountCodeToCart.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -25,9 +26,9 @@ export default async function applyDiscountCodeToCart(parentResult, { input }, c } = input; const updatedCartWithAppliedDiscountCode = await context.mutations.applyDiscountCodeToCart(context, { - cartId: decodeCartOpaqueId(cartId), + cartId: isOpaqueId(cartId) ? decodeCartOpaqueId(cartId) : cartId, discountCode, - shopId: decodeShopOpaqueId(shopId), + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, token }); diff --git a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/createDiscountCode.js b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/createDiscountCode.js index 66063c5525b..fc339cfd08c 100644 --- a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/createDiscountCode.js +++ b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/createDiscountCode.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,7 +21,7 @@ export default async function createDiscountCode(parentResult, { input }, contex discountCode: discountCodeInput } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const discountCode = await context.mutations.createDiscountCode(context, { shopId, diff --git a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/deleteDiscountCode.js b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/deleteDiscountCode.js index bedbd529424..019d27fc357 100644 --- a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/deleteDiscountCode.js +++ b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/deleteDiscountCode.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeDiscountOpaqueId } from "../../xforms/id.js"; /** @@ -20,7 +21,7 @@ export default async function deleteDiscountCode(parentResult, { input }, contex shopId: opaqueShopId } = input; - const _id = decodeDiscountOpaqueId(opaqueDiscountCodeId); + const _id = isOpaqueId(opaqueDiscountCodeId) ? decodeDiscountOpaqueId(opaqueDiscountCodeId) : opaqueDiscountCodeId; const shopId = decodeShopOpaqueId(opaqueShopId); const discountCode = await context.mutations.deleteDiscountCode(context, { diff --git a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/removeDiscountCodeFromCart.js b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/removeDiscountCodeFromCart.js index 947b709a1b1..787dadd133b 100644 --- a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/removeDiscountCodeFromCart.js +++ b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/removeDiscountCodeFromCart.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId, decodeDiscountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -25,9 +26,9 @@ export default async function removeDiscountCodeFromCart(parentResult, { input } } = input; const updatedCartWithRemovedDiscountCode = await context.mutations.removeDiscountCodeFromCart(context, { - cartId: decodeCartOpaqueId(cartId), - discountId: decodeDiscountOpaqueId(discountId), - shopId: decodeShopOpaqueId(shopId), + cartId: isOpaqueId(cartId) ? decodeCartOpaqueId(cartId) : cartId, + discountId: isOpaqueId(discountId) ? decodeDiscountOpaqueId(discountId) : discountId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, token }); diff --git a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/updateDiscountCode.js b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/updateDiscountCode.js index a1d2134cfc2..0c744a55343 100644 --- a/packages/api-plugin-discounts-codes/src/resolvers/Mutation/updateDiscountCode.js +++ b/packages/api-plugin-discounts-codes/src/resolvers/Mutation/updateDiscountCode.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeDiscountOpaqueId } from "../../xforms/id.js"; /** @@ -22,8 +23,8 @@ export default async function updateDiscountCode(parentResult, { input }, contex discountCode: discountCodeInput } = input; - const _id = decodeDiscountOpaqueId(opaqueDiscountCodeId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const _id = isOpaqueId(opaqueDiscountCodeId) ? decodeDiscountOpaqueId(opaqueDiscountCodeId) : opaqueDiscountCodeId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const discountCode = await context.mutations.updateDiscountCode(context, { _id, diff --git a/packages/api-plugin-discounts-codes/src/resolvers/Query/discountCodes.js b/packages/api-plugin-discounts-codes/src/resolvers/Query/discountCodes.js index 5457c5a72b1..5ca829e0989 100644 --- a/packages/api-plugin-discounts-codes/src/resolvers/Query/discountCodes.js +++ b/packages/api-plugin-discounts-codes/src/resolvers/Query/discountCodes.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,7 +19,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; export default async function discountCodes(_, args, context, info) { const { shopId: opaqueShopId, filters, ...connectionArgs } = args; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const query = await context.queries.discountCodes(context, shopId, filters); diff --git a/packages/api-plugin-email-templates/src/resolvers/Mutation/updateTemplate.js b/packages/api-plugin-email-templates/src/resolvers/Mutation/updateTemplate.js index 389fd53ec88..df4de506e0a 100644 --- a/packages/api-plugin-email-templates/src/resolvers/Mutation/updateTemplate.js +++ b/packages/api-plugin-email-templates/src/resolvers/Mutation/updateTemplate.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTemplateOpaqueId } from "../../xforms/id.js"; /** @@ -22,8 +23,8 @@ export default async function updateTemplate(parentResult, { input }, context) { ...templateInput } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const templateId = decodeTemplateOpaqueId(opaqueTemplateId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const templateId = isOpaqueId(opaqueTemplateId) ? decodeTemplateOpaqueId(opaqueTemplateId) : opaqueTemplateId; const template = await context.mutations.updateTemplate(context, { shopId, diff --git a/packages/api-plugin-email-templates/src/resolvers/Query/emailTemplates.js b/packages/api-plugin-email-templates/src/resolvers/Query/emailTemplates.js index daa7dc314e4..0699c725db4 100644 --- a/packages/api-plugin-email-templates/src/resolvers/Query/emailTemplates.js +++ b/packages/api-plugin-email-templates/src/resolvers/Query/emailTemplates.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,7 +17,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; export default async function emailTemplates(_, args, context, info) { const { shopId: opaqueShopId, ...connectionArgs } = args; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const query = await context.queries.emailTemplates(context, shopId); diff --git a/packages/api-plugin-email/src/resolvers/Mutation/retryFailedEmail.js b/packages/api-plugin-email/src/resolvers/Mutation/retryFailedEmail.js index 253f51ac124..24dadf6d212 100644 --- a/packages/api-plugin-email/src/resolvers/Mutation/retryFailedEmail.js +++ b/packages/api-plugin-email/src/resolvers/Mutation/retryFailedEmail.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeJobOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,8 +20,8 @@ export default async function retryFailedEmail(parentResult, { input }, context) shopId: opaqueShopId } = input; const resp = await context.mutations.retryFailedEmail(context, { - jobId: decodeJobOpaqueId(opaqueJobId), - shopId: decodeShopOpaqueId(opaqueShopId) + jobId: isOpaqueId(opaqueJobId) ? decodeJobOpaqueId(opaqueJobId) : opaqueJobId, + shopId: isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId }); return { diff --git a/packages/api-plugin-email/src/resolvers/Query/emailJobs.js b/packages/api-plugin-email/src/resolvers/Query/emailJobs.js index f8332ee7ab2..38d998134b7 100644 --- a/packages/api-plugin-email/src/resolvers/Query/emailJobs.js +++ b/packages/api-plugin-email/src/resolvers/Query/emailJobs.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,7 +21,7 @@ export default async function emailJobs(parentResult, args, context, info) { ...connectionArgs } = args; - const shopIds = opaqueShopIds.map((opaqueShopId) => decodeShopOpaqueId(opaqueShopId)); + const shopIds = opaqueShopIds.map((opaqueShopId) => (isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId)); const cursor = await context.queries.emailJobs(context, shopIds); diff --git a/packages/api-plugin-files/src/resolvers/Mutation/archiveMediaRecord.js b/packages/api-plugin-files/src/resolvers/Mutation/archiveMediaRecord.js index c8a3bdff7a8..a38ebf20ca1 100644 --- a/packages/api-plugin-files/src/resolvers/Mutation/archiveMediaRecord.js +++ b/packages/api-plugin-files/src/resolvers/Mutation/archiveMediaRecord.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeMediaRecordOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,8 +21,8 @@ export default async function archiveMediaRecord(parentResult, { input }, contex } = input; const mediaRecord = await context.mutations.archiveMediaRecord(context, { - mediaRecordId: decodeMediaRecordOpaqueId(opaqueMediaRecordId), - shopId: decodeShopOpaqueId(opaqueShopId) + mediaRecordId: isOpaqueId(opaqueMediaRecordId) ? decodeMediaRecordOpaqueId(opaqueMediaRecordId) : opaqueMediaRecordId, + shopId: isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId }); return { diff --git a/packages/api-plugin-files/src/resolvers/Mutation/createMediaRecord.js b/packages/api-plugin-files/src/resolvers/Mutation/createMediaRecord.js index f579d3e9fc4..8beb2332d56 100644 --- a/packages/api-plugin-files/src/resolvers/Mutation/createMediaRecord.js +++ b/packages/api-plugin-files/src/resolvers/Mutation/createMediaRecord.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -23,12 +24,14 @@ export default async function createMediaRecord(parentResult, { input }, context mediaRecord: { metadata: { ...mediaRecordInput.metadata, - productId: decodeProductOpaqueId(mediaRecordInput.metadata.productId), - variantId: decodeProductOpaqueId(mediaRecordInput.metadata.variantId) + productId: isOpaqueId(mediaRecordInput.metadata.productId) ? + decodeProductOpaqueId(mediaRecordInput.metadata.productId) : mediaRecordInput.metadata.productId, + variantId: isOpaqueId(mediaRecordInput.metadata.variantId) ? + decodeProductOpaqueId(mediaRecordInput.metadata.variantId) : mediaRecordInput.metadata.variantId }, original: mediaRecordInput.original }, - shopId: decodeShopOpaqueId(opaqueShopId) + shopId: isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId }); return { diff --git a/packages/api-plugin-files/src/resolvers/Mutation/deleteMediaRecord.js b/packages/api-plugin-files/src/resolvers/Mutation/deleteMediaRecord.js index 17d06de9ad4..d0fa338fb73 100644 --- a/packages/api-plugin-files/src/resolvers/Mutation/deleteMediaRecord.js +++ b/packages/api-plugin-files/src/resolvers/Mutation/deleteMediaRecord.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeMediaRecordOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,8 +21,8 @@ export default async function deleteMediaRecord(parentResult, { input }, context } = input; const mediaRecord = await context.mutations.deleteMediaRecord(context, { - mediaRecordId: decodeMediaRecordOpaqueId(opaqueMediaRecordId), - shopId: decodeShopOpaqueId(opaqueShopId) + mediaRecordId: isOpaqueId(opaqueMediaRecordId) ? decodeMediaRecordOpaqueId(opaqueMediaRecordId) : opaqueMediaRecordId, + shopId: isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId }); return { diff --git a/packages/api-plugin-files/src/resolvers/Mutation/updateMediaRecordPriority.js b/packages/api-plugin-files/src/resolvers/Mutation/updateMediaRecordPriority.js index a0f262c0426..9f903f3bed8 100644 --- a/packages/api-plugin-files/src/resolvers/Mutation/updateMediaRecordPriority.js +++ b/packages/api-plugin-files/src/resolvers/Mutation/updateMediaRecordPriority.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeMediaRecordOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -22,9 +23,9 @@ export default async function updateMediaRecordPriority(parentResult, { input }, } = input; const mediaRecord = await context.mutations.updateMediaRecordPriority(context, { - mediaRecordId: decodeMediaRecordOpaqueId(opaqueMediaRecordId), + mediaRecordId: isOpaqueId(opaqueMediaRecordId) ? decodeMediaRecordOpaqueId(opaqueMediaRecordId) : opaqueMediaRecordId, priority, - shopId: decodeShopOpaqueId(opaqueShopId) + shopId: isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId }); return { diff --git a/packages/api-plugin-inventory-simple/src/resolvers/Mutation/recalculateReservedSimpleInventory.js b/packages/api-plugin-inventory-simple/src/resolvers/Mutation/recalculateReservedSimpleInventory.js index 9c6b35ae1e4..a9931e9f73d 100644 --- a/packages/api-plugin-inventory-simple/src/resolvers/Mutation/recalculateReservedSimpleInventory.js +++ b/packages/api-plugin-inventory-simple/src/resolvers/Mutation/recalculateReservedSimpleInventory.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; const decodeProductOpaqueId = decodeOpaqueIdForNamespace("reaction/product"); @@ -17,9 +18,11 @@ const decodeShopOpaqueId = decodeOpaqueIdForNamespace("reaction/shop"); export default async function recalculateReservedSimpleInventory(_, { input }, context) { const { clientMutationId = null, productConfiguration, shopId: opaqueShopId, ...passThroughInput } = input; - const productId = decodeProductOpaqueId(productConfiguration.productId); - const productVariantId = decodeProductOpaqueId(productConfiguration.productVariantId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const productId = isOpaqueId(productConfiguration.productId) ? + decodeProductOpaqueId(productConfiguration.productId) : productConfiguration.productId; + const productVariantId = isOpaqueId(productConfiguration.productVariantId) ? + decodeProductOpaqueId(productConfiguration.productVariantId) : productConfiguration.productVariantId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const inventoryInfo = await context.mutations.recalculateReservedSimpleInventory(context, { ...passThroughInput, diff --git a/packages/api-plugin-inventory-simple/src/resolvers/Mutation/updateSimpleInventory.js b/packages/api-plugin-inventory-simple/src/resolvers/Mutation/updateSimpleInventory.js index 796e7a44c08..3f7d63ea681 100644 --- a/packages/api-plugin-inventory-simple/src/resolvers/Mutation/updateSimpleInventory.js +++ b/packages/api-plugin-inventory-simple/src/resolvers/Mutation/updateSimpleInventory.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; const decodeProductOpaqueId = decodeOpaqueIdForNamespace("reaction/product"); @@ -17,9 +18,11 @@ const decodeShopOpaqueId = decodeOpaqueIdForNamespace("reaction/shop"); export default async function updateSimpleInventory(_, { input }, context) { const { clientMutationId = null, productConfiguration, shopId: opaqueShopId, ...passThroughInput } = input; - const productId = decodeProductOpaqueId(productConfiguration.productId); - const productVariantId = decodeProductOpaqueId(productConfiguration.productVariantId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const productId = isOpaqueId(productConfiguration.productId) ? + decodeProductOpaqueId(productConfiguration.productId) : productConfiguration.productId; + const productVariantId = isOpaqueId(productConfiguration.productVariantId) ? + decodeProductOpaqueId(productConfiguration.productVariantId) : productConfiguration.productVariantId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const inventoryInfo = await context.mutations.updateSimpleInventory(context, { ...passThroughInput, diff --git a/packages/api-plugin-inventory-simple/src/resolvers/Query/simpleInventory.js b/packages/api-plugin-inventory-simple/src/resolvers/Query/simpleInventory.js index c4f71cdedd3..994bfe45ebf 100644 --- a/packages/api-plugin-inventory-simple/src/resolvers/Query/simpleInventory.js +++ b/packages/api-plugin-inventory-simple/src/resolvers/Query/simpleInventory.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; const decodeProductOpaqueId = decodeOpaqueIdForNamespace("reaction/product"); @@ -16,9 +17,11 @@ const decodeShopOpaqueId = decodeOpaqueIdForNamespace("reaction/shop"); export default async function simpleInventory(_, args, context) { const { productConfiguration, shopId: opaqueShopId } = args; - const productId = decodeProductOpaqueId(productConfiguration.productId); - const productVariantId = decodeProductOpaqueId(productConfiguration.productVariantId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const productId = isOpaqueId(productConfiguration.productId) ? + decodeProductOpaqueId(productConfiguration.productId) : productConfiguration.productId; + const productVariantId = isOpaqueId(productConfiguration.productVariantId) ? + decodeProductOpaqueId(productConfiguration.productVariantId) : productConfiguration.productVariantId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; return context.queries.simpleInventory(context, { productConfiguration: { diff --git a/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationItem.js b/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationItem.js index 8ac333d13e0..5da36d21f24 100644 --- a/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationItem.js +++ b/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationItem.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -21,7 +22,7 @@ export default async function createNavigationItem(parentResult, { input }, cont const newNavigationItem = await context.mutations.createNavigationItem(context, { navigationItem: { ...navigationItem, - shopId: decodeShopOpaqueId(navigationItem.shopId) + shopId: isOpaqueId(navigationItem.shopId) ? decodeShopOpaqueId(navigationItem.shopId) : navigationItem.shopId } }); diff --git a/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationTree.js b/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationTree.js index 745016e3fc0..4bce3353859 100644 --- a/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationTree.js +++ b/packages/api-plugin-navigation/src/resolvers/Mutation/createNavigationTree.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; import decodeNavigationTreeItemIds from "../../util/decodeNavigationTreeItemIds.js"; /** @@ -20,7 +21,7 @@ export default async function createNavigationTree(parentResult, { input }, cont shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; if (input.draftItems) { const { draftItems } = input; decodeNavigationTreeItemIds(draftItems); diff --git a/packages/api-plugin-navigation/src/resolvers/Mutation/deleteNavigationItem.js b/packages/api-plugin-navigation/src/resolvers/Mutation/deleteNavigationItem.js index 050aba5f096..64d3e171207 100644 --- a/packages/api-plugin-navigation/src/resolvers/Mutation/deleteNavigationItem.js +++ b/packages/api-plugin-navigation/src/resolvers/Mutation/deleteNavigationItem.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeNavigationItemOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,8 +21,8 @@ export default async function deleteNavigationItem(parentResult, { input }, cont shopId: opaqueShopId } = input; - const navigationItemId = decodeNavigationItemOpaqueId(opaqueNavigationItemId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const navigationItemId = isOpaqueId(opaqueNavigationItemId) ? decodeNavigationItemOpaqueId(opaqueNavigationItemId) : opaqueNavigationItemId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const deletedNavigationItem = await context.mutations.deleteNavigationItem(context, { navigationItemId, diff --git a/packages/api-plugin-navigation/src/resolvers/Mutation/publishNavigationChanges.js b/packages/api-plugin-navigation/src/resolvers/Mutation/publishNavigationChanges.js index 07c36e8ca81..7642eb833e1 100644 --- a/packages/api-plugin-navigation/src/resolvers/Mutation/publishNavigationChanges.js +++ b/packages/api-plugin-navigation/src/resolvers/Mutation/publishNavigationChanges.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeNavigationTreeOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,8 +17,8 @@ import { decodeNavigationTreeOpaqueId, decodeShopOpaqueId } from "../../xforms/i export default async function publishNavigationChanges(parentResult, { input }, context) { const { clientMutationId = null, id: opaqueNavigationTreeId, shopId: opaqueShopId } = input; - const decodedId = decodeNavigationTreeOpaqueId(opaqueNavigationTreeId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const decodedId = isOpaqueId(opaqueNavigationTreeId) ? decodeNavigationTreeOpaqueId(opaqueNavigationTreeId) : opaqueNavigationTreeId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const publishedNavigationTree = context.mutations.publishNavigationChanges(context, { navigationTreeId: decodedId, shopId diff --git a/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationItem.js b/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationItem.js index 93f5487ebf0..cedf5f81381 100644 --- a/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationItem.js +++ b/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationItem.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeNavigationItemOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -21,14 +22,14 @@ export default async function updateNavigationItem(parentResult, { input }, cont navigationItem } = input; - const navigationItemId = decodeNavigationItemOpaqueId(opaqueNavigationItemId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const navigationItemId = isOpaqueId(opaqueNavigationItemId) ? decodeNavigationItemOpaqueId(opaqueNavigationItemId) : opaqueNavigationItemId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const updatedNavigationItem = await context.mutations.updateNavigationItem(context, { navigationItemId, navigationItem: { ...navigationItem, - shopId: decodeShopOpaqueId(navigationItem.shopId) + shopId: isOpaqueId(navigationItem.shopId) ? decodeShopOpaqueId(navigationItem.shopId) : navigationItem.shopId }, shopId }); diff --git a/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationTree.js b/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationTree.js index c9ac445406f..396c7a7791e 100644 --- a/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationTree.js +++ b/packages/api-plugin-navigation/src/resolvers/Mutation/updateNavigationTree.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeNavigationTreeOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; import decodeNavigationTreeItemIds from "../../util/decodeNavigationTreeItemIds.js"; /** @@ -22,8 +23,8 @@ export default async function updateNavigationTree(parentResult, { input }, cont navigationTree } = input; - const navigationTreeId = decodeNavigationTreeOpaqueId(opaqueNavigationTreeId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const navigationTreeId = isOpaqueId(opaqueNavigationTreeId) ? decodeNavigationTreeOpaqueId(opaqueNavigationTreeId) : opaqueNavigationTreeId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; if (navigationTree.draftItems) { const { draftItems } = navigationTree; diff --git a/packages/api-plugin-navigation/src/resolvers/Query/navigationItemsByShopId.js b/packages/api-plugin-navigation/src/resolvers/Query/navigationItemsByShopId.js index 1fc628d54d7..642ded825a8 100644 --- a/packages/api-plugin-navigation/src/resolvers/Query/navigationItemsByShopId.js +++ b/packages/api-plugin-navigation/src/resolvers/Query/navigationItemsByShopId.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,7 +17,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; */ export default async function navigationItemsByShopId(_, args, context, info) { const { shopId, ...connectionArgs } = args; - const decodedShopId = decodeShopOpaqueId(shopId); + const decodedShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; const query = await context.queries.navigationItemsByShopId(context, decodedShopId); diff --git a/packages/api-plugin-navigation/src/resolvers/Query/navigationTreeById.js b/packages/api-plugin-navigation/src/resolvers/Query/navigationTreeById.js index 5c31f562ebc..3fed27ebf04 100644 --- a/packages/api-plugin-navigation/src/resolvers/Query/navigationTreeById.js +++ b/packages/api-plugin-navigation/src/resolvers/Query/navigationTreeById.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeNavigationTreeOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,8 +20,8 @@ export default async function navigationTreeById(_, args, context) { return context.queries.navigationTreeById(context, { language, - navigationTreeId: decodeNavigationTreeOpaqueId(id), - shopId: decodeShopOpaqueId(shopId), + navigationTreeId: isOpaqueId(id) ? decodeNavigationTreeOpaqueId(id) : id, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, shouldIncludeSecondary }); } diff --git a/packages/api-plugin-navigation/src/util/decodeNavigationTreeItemIds.js b/packages/api-plugin-navigation/src/util/decodeNavigationTreeItemIds.js index 0dbe8d42092..7e7450797bd 100644 --- a/packages/api-plugin-navigation/src/util/decodeNavigationTreeItemIds.js +++ b/packages/api-plugin-navigation/src/util/decodeNavigationTreeItemIds.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeNavigationItemOpaqueId } from "../xforms/id.js"; /** @@ -9,7 +10,7 @@ import { decodeNavigationItemOpaqueId } from "../xforms/id.js"; export default function decodeNavigationTreeItemIds(items) { items.forEach((item) => { const { navigationItemId, items: childItems } = item; - item.navigationItemId = decodeNavigationItemOpaqueId(navigationItemId); + item.navigationItemId = isOpaqueId(navigationItemId) ? decodeNavigationItemOpaqueId(navigationItemId) : navigationItemId; if (childItems) { decodeNavigationTreeItemIds(childItems); } diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/addOrderFulfillmentGroup.js b/packages/api-plugin-orders/src/resolvers/Mutation/addOrderFulfillmentGroup.js index 1646811184c..af1054f94ce 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/addOrderFulfillmentGroup.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/addOrderFulfillmentGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeOrderItemOpaqueId, @@ -33,11 +34,12 @@ export default async function addOrderFulfillmentGroup(parentResult, { input }, fulfillmentGroup: { ...fulfillmentGroup, items: fulfillmentGroup.items ? decodeOrderItemsOpaqueIds(fulfillmentGroup.items) : null, - selectedFulfillmentMethodId: decodeFulfillmentMethodOpaqueId(fulfillmentGroup.selectedFulfillmentMethodId), - shopId: decodeShopOpaqueId(fulfillmentGroup.shopId) + selectedFulfillmentMethodId: isOpaqueId(fulfillmentGroup.selectedFulfillmentMethodId) ? + decodeFulfillmentMethodOpaqueId(fulfillmentGroup.selectedFulfillmentMethodId) : fulfillmentGroup.selectedFulfillmentMethodId, + shopId: isOpaqueId(fulfillmentGroup.shopId) ? decodeShopOpaqueId(fulfillmentGroup.shopId) : fulfillmentGroup.shopId }, - moveItemIds: moveItemIds && moveItemIds.map(decodeOrderItemOpaqueId), - orderId: decodeOrderOpaqueId(orderId) + moveItemIds: moveItemIds && moveItemIds.map((itemId) => (isOpaqueId(itemId) ? decodeOrderItemOpaqueId(itemId) : itemId)), + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId }); return { diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/cancelOrderItem.js b/packages/api-plugin-orders/src/resolvers/Mutation/cancelOrderItem.js index d2b631399c2..309368d5598 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/cancelOrderItem.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/cancelOrderItem.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderItemOpaqueId, decodeOrderOpaqueId } from "../../xforms/id.js"; /** @@ -26,8 +27,8 @@ export default async function cancelOrderItem(parentResult, { input }, context) const { order } = await context.mutations.cancelOrderItem(context, { cancelQuantity, - itemId: decodeOrderItemOpaqueId(itemId), - orderId: decodeOrderOpaqueId(orderId), + itemId: isOpaqueId(itemId) ? decodeOrderItemOpaqueId(itemId) : itemId, + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId, reason }); diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/createRefund.js b/packages/api-plugin-orders/src/resolvers/Mutation/createRefund.js index db1c8587f59..34fdb433ba2 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/createRefund.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/createRefund.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId, decodePaymentOpaqueId } from "../../xforms/id.js"; /** @@ -25,8 +26,8 @@ export default async function createRefund(_, { input }, context) { const { order } = await context.mutations.createRefund(context, { amount, - orderId: decodeOrderOpaqueId(orderId), - paymentId: decodePaymentOpaqueId(paymentId), + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId, + paymentId: isOpaqueId(paymentId) ? decodePaymentOpaqueId(paymentId) : paymentId, reason }); diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/moveOrderItems.js b/packages/api-plugin-orders/src/resolvers/Mutation/moveOrderItems.js index ae8f72cc42c..4e58d2dcff3 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/moveOrderItems.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/moveOrderItems.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderFulfillmentGroupOpaqueId, decodeOrderItemOpaqueId, @@ -31,10 +32,10 @@ export default async function moveOrderItems(parentResult, { input }, context) { } = input; const { order } = await context.mutations.moveOrderItems(context, { - fromFulfillmentGroupId: decodeOrderFulfillmentGroupOpaqueId(fromFulfillmentGroupId), - itemIds: itemIds.map(decodeOrderItemOpaqueId), - orderId: decodeOrderOpaqueId(orderId), - toFulfillmentGroupId: decodeOrderFulfillmentGroupOpaqueId(toFulfillmentGroupId) + fromFulfillmentGroupId: isOpaqueId(fromFulfillmentGroupId) ? decodeOrderFulfillmentGroupOpaqueId(fromFulfillmentGroupId) : fromFulfillmentGroupId, + itemIds: itemIds.map((itemId) => (isOpaqueId(itemId) ? decodeOrderItemOpaqueId(itemId) : itemId)), + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId, + toFulfillmentGroupId: isOpaqueId(toFulfillmentGroupId) ? decodeOrderFulfillmentGroupOpaqueId(toFulfillmentGroupId) : toFulfillmentGroupId }); return { diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/placeOrder.js b/packages/api-plugin-orders/src/resolvers/Mutation/placeOrder.js index 7220d2de604..6722638dc7f 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/placeOrder.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/placeOrder.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId, decodeFulfillmentMethodOpaqueId, @@ -22,14 +23,18 @@ export default async function placeOrder(parentResult, { input }, context) { const { clientMutationId = null, order, payments } = input; const { cartId: opaqueCartId, fulfillmentGroups, shopId: opaqueShopId } = order; - const cartId = opaqueCartId ? decodeCartOpaqueId(opaqueCartId) : null; - const shopId = decodeShopOpaqueId(opaqueShopId); + let cartId = null; + if (opaqueCartId) { + cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; + } + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const transformedFulfillmentGroups = fulfillmentGroups.map((group) => ({ ...group, items: decodeOrderItemsOpaqueIds(group.items), - selectedFulfillmentMethodId: decodeFulfillmentMethodOpaqueId(group.selectedFulfillmentMethodId), - shopId: decodeShopOpaqueId(group.shopId) + selectedFulfillmentMethodId: isOpaqueId(group.selectedFulfillmentMethodId) ? + decodeFulfillmentMethodOpaqueId(group.selectedFulfillmentMethodId) : group.selectedFulfillmentMethodId, + shopId: isOpaqueId(group.shopId) ? decodeShopOpaqueId(group.shopId) : group.shopId })); const { orders, token } = await context.mutations.placeOrder(context, { diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/splitOrderItem.js b/packages/api-plugin-orders/src/resolvers/Mutation/splitOrderItem.js index 6d2b45f8cb8..faba3a7a1f3 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/splitOrderItem.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/splitOrderItem.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderItemOpaqueId, decodeOrderOpaqueId @@ -28,8 +29,8 @@ export default async function splitOrderItem(parentResult, { input }, context) { const { newItemId, order } = await context.mutations.splitOrderItem(context, { newItemQuantity, - itemId: decodeOrderItemOpaqueId(itemId), - orderId: decodeOrderOpaqueId(orderId) + itemId: isOpaqueId(itemId) ? decodeOrderItemOpaqueId(itemId) : itemId, + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId }); return { diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/updateOrder.js b/packages/api-plugin-orders/src/resolvers/Mutation/updateOrder.js index 9f30319d2d8..82db8956a1f 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/updateOrder.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/updateOrder.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId } from "../../xforms/id.js"; /** @@ -27,7 +28,7 @@ export default async function updateOrder(parentResult, { input }, context) { const { order } = await context.mutations.updateOrder(context, { customFields, email, - orderId: decodeOrderOpaqueId(orderId), + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId, status }); diff --git a/packages/api-plugin-orders/src/resolvers/Mutation/updateOrderFulfillmentGroup.js b/packages/api-plugin-orders/src/resolvers/Mutation/updateOrderFulfillmentGroup.js index 0e09f98744e..264c729cd47 100644 --- a/packages/api-plugin-orders/src/resolvers/Mutation/updateOrderFulfillmentGroup.js +++ b/packages/api-plugin-orders/src/resolvers/Mutation/updateOrderFulfillmentGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId, decodeOrderFulfillmentGroupOpaqueId } from "../../xforms/id.js"; /** @@ -27,8 +28,9 @@ export default async function updateOrderFulfillmentGroup(parentResult, { input } = input; const { order } = await context.mutations.updateOrderFulfillmentGroup(context, { - orderId: decodeOrderOpaqueId(orderId), - orderFulfillmentGroupId: decodeOrderFulfillmentGroupOpaqueId(orderFulfillmentGroupId), + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId, + orderFulfillmentGroupId: isOpaqueId(orderFulfillmentGroupId) ? + decodeOrderFulfillmentGroupOpaqueId(orderFulfillmentGroupId) : orderFulfillmentGroupId, status, tracking, trackingUrl diff --git a/packages/api-plugin-orders/src/resolvers/Query/orderById.js b/packages/api-plugin-orders/src/resolvers/Query/orderById.js index 2b7d8131355..294e87b5fd9 100644 --- a/packages/api-plugin-orders/src/resolvers/Query/orderById.js +++ b/packages/api-plugin-orders/src/resolvers/Query/orderById.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,8 +17,8 @@ export default async function orderById(parentResult, args, context) { const { id, shopId, token } = args; return context.queries.orderById(context, { - orderId: decodeOrderOpaqueId(id), - shopId: decodeShopOpaqueId(shopId), + orderId: isOpaqueId(id) ? decodeOrderOpaqueId(id) : id, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, token }); } diff --git a/packages/api-plugin-orders/src/resolvers/Query/orderByReferenceId.js b/packages/api-plugin-orders/src/resolvers/Query/orderByReferenceId.js index 4cdbbc78695..79ee163c0d9 100644 --- a/packages/api-plugin-orders/src/resolvers/Query/orderByReferenceId.js +++ b/packages/api-plugin-orders/src/resolvers/Query/orderByReferenceId.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,7 +19,7 @@ export default async function orderByReferenceId(parentResult, args, context) { return context.queries.orderByReferenceId(context, { orderReferenceId: id, - shopId: decodeShopOpaqueId(shopId), + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, token }); } diff --git a/packages/api-plugin-orders/src/resolvers/Query/orders.js b/packages/api-plugin-orders/src/resolvers/Query/orders.js index 429bca97ded..39db065325a 100644 --- a/packages/api-plugin-orders/src/resolvers/Query/orders.js +++ b/packages/api-plugin-orders/src/resolvers/Query/orders.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,7 +19,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; export default async function orders(parentResult, args, context, info) { const { filters, shopIds: opaqueShopIds, ...connectionArgs } = args; - const shopIds = opaqueShopIds && opaqueShopIds.map(decodeShopOpaqueId); + const shopIds = opaqueShopIds && opaqueShopIds.map((opaqueShopId) => (isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId)); const query = await context.queries.orders(context, { filters, diff --git a/packages/api-plugin-orders/src/resolvers/Query/ordersByAccountId.js b/packages/api-plugin-orders/src/resolvers/Query/ordersByAccountId.js index eb121ce5eb1..81c469a3f90 100644 --- a/packages/api-plugin-orders/src/resolvers/Query/ordersByAccountId.js +++ b/packages/api-plugin-orders/src/resolvers/Query/ordersByAccountId.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,10 +20,10 @@ import { decodeAccountOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; export default async function ordersByAccountId(parentResult, args, context, info) { const { accountId, orderStatus, shopIds: opaqueShopIds, ...connectionArgs } = args; - const shopIds = opaqueShopIds && opaqueShopIds.map(decodeShopOpaqueId); + const shopIds = opaqueShopIds && opaqueShopIds.map((opaqueShopId) => (isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId)); const query = await context.queries.ordersByAccountId(context, { - accountId: decodeAccountOpaqueId(accountId), + accountId: isOpaqueId(accountId) ? decodeAccountOpaqueId(accountId) : accountId, orderStatus, shopIds }); diff --git a/packages/api-plugin-orders/src/resolvers/Query/refunds.js b/packages/api-plugin-orders/src/resolvers/Query/refunds.js index 7d4d183da38..add3fe8b0fb 100644 --- a/packages/api-plugin-orders/src/resolvers/Query/refunds.js +++ b/packages/api-plugin-orders/src/resolvers/Query/refunds.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -17,8 +18,8 @@ export default async function refunds(_, args, context) { const { orderId, shopId, token } = args; return context.queries.refunds(context, { - orderId: decodeOrderOpaqueId(orderId), - shopId: decodeShopOpaqueId(shopId), + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, token }); } diff --git a/packages/api-plugin-orders/src/resolvers/Query/refundsByPaymentId.js b/packages/api-plugin-orders/src/resolvers/Query/refundsByPaymentId.js index 07b15c6f8da..4c5829a093b 100644 --- a/packages/api-plugin-orders/src/resolvers/Query/refundsByPaymentId.js +++ b/packages/api-plugin-orders/src/resolvers/Query/refundsByPaymentId.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId, decodePaymentOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,9 +19,9 @@ export default async function refundsByPaymentId(_, args, context) { const { orderId, paymentId, shopId, token } = args; return context.queries.refundsByPaymentId(context, { - orderId: decodeOrderOpaqueId(orderId), - paymentId: decodePaymentOpaqueId(paymentId), - shopId: decodeShopOpaqueId(shopId), + orderId: isOpaqueId(orderId) ? decodeOrderOpaqueId(orderId) : orderId, + paymentId: isOpaqueId(paymentId) ? decodePaymentOpaqueId(paymentId) : paymentId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, token }); } diff --git a/packages/api-plugin-orders/src/xforms/id.js b/packages/api-plugin-orders/src/xforms/id.js index f6af97ba4d7..02a9d2b8db6 100644 --- a/packages/api-plugin-orders/src/xforms/id.js +++ b/packages/api-plugin-orders/src/xforms/id.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import decodeOpaqueIdForNamespace from "@reactioncommerce/api-utils/decodeOpaqueIdForNamespace.js"; import encodeOpaqueId from "@reactioncommerce/api-utils/encodeOpaqueId.js"; @@ -43,8 +44,10 @@ export function decodeOrderItemsOpaqueIds(items) { return items.map((item) => ({ ...item, productConfiguration: { - productId: decodeProductOpaqueId(item.productConfiguration.productId), - productVariantId: decodeProductOpaqueId(item.productConfiguration.productVariantId) + productId: isOpaqueId(item.productConfiguration.productId) ? + decodeProductOpaqueId(item.productConfiguration.productId) : item.productConfiguration.productId, + productVariantId: isOpaqueId(item.productConfiguration.productVariantId) ? + decodeProductOpaqueId(item.productConfiguration.productVariantId) : item.productConfiguration.productVariantId } })); } diff --git a/packages/api-plugin-payments-stripe-sca/src/resolvers/Mutation/createStripePaymentIntent.js b/packages/api-plugin-payments-stripe-sca/src/resolvers/Mutation/createStripePaymentIntent.js index f613d454db4..2e2d0958c26 100644 --- a/packages/api-plugin-payments-stripe-sca/src/resolvers/Mutation/createStripePaymentIntent.js +++ b/packages/api-plugin-payments-stripe-sca/src/resolvers/Mutation/createStripePaymentIntent.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -26,8 +27,11 @@ export default async function createStripePaymentIntent( cartToken } = input; - const cartId = opaqueCartId ? decodeCartOpaqueId(opaqueCartId) : null; - const shopId = decodeShopOpaqueId(opaqueShopId); + let cartId = null; + if (opaqueCartId) { + cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; + } + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const paymentIntentClientSecret = await context.mutations.createStripePaymentIntent(context, { diff --git a/packages/api-plugin-payments/src/resolvers/Mutation/approveOrderPayments.js b/packages/api-plugin-payments/src/resolvers/Mutation/approveOrderPayments.js index 0376b768baa..70c07511990 100644 --- a/packages/api-plugin-payments/src/resolvers/Mutation/approveOrderPayments.js +++ b/packages/api-plugin-payments/src/resolvers/Mutation/approveOrderPayments.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId, decodePaymentOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,9 +17,9 @@ import { decodeOrderOpaqueId, decodePaymentOpaqueId, decodeShopOpaqueId } from " export default async function approveOrderPayments(parentResult, { input }, context) { const { clientMutationId, orderId: opaqueOrderId, paymentIds: opaquePaymentIds, shopId: opaqueShopId } = input; - const orderId = decodeOrderOpaqueId(opaqueOrderId); - const paymentIds = opaquePaymentIds.map(decodePaymentOpaqueId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const orderId = isOpaqueId(opaqueOrderId) ? decodeOrderOpaqueId(opaqueOrderId) : opaqueOrderId; + const paymentIds = opaquePaymentIds.map((opaquePaymentId) => (isOpaqueId(opaquePaymentId) ? decodePaymentOpaqueId(opaquePaymentId) : opaquePaymentId)); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const { order } = await context.mutations.approveOrderPayments(context, { orderId, diff --git a/packages/api-plugin-payments/src/resolvers/Mutation/captureOrderPayments.js b/packages/api-plugin-payments/src/resolvers/Mutation/captureOrderPayments.js index a5f7dce659f..b76d065e0f2 100644 --- a/packages/api-plugin-payments/src/resolvers/Mutation/captureOrderPayments.js +++ b/packages/api-plugin-payments/src/resolvers/Mutation/captureOrderPayments.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeOrderOpaqueId, decodePaymentOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,9 +17,9 @@ import { decodeOrderOpaqueId, decodePaymentOpaqueId, decodeShopOpaqueId } from " export default async function captureOrderPayments(parentResult, { input }, context) { const { clientMutationId, orderId: opaqueOrderId, paymentIds: opaquePaymentIds, shopId: opaqueShopId } = input; - const orderId = decodeOrderOpaqueId(opaqueOrderId); - const paymentIds = opaquePaymentIds.map(decodePaymentOpaqueId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const orderId = isOpaqueId(opaqueOrderId) ? decodeOrderOpaqueId(opaqueOrderId) : opaqueOrderId; + const paymentIds = opaquePaymentIds.map((opaquePaymentId) => (isOpaqueId(opaquePaymentId) ? decodePaymentOpaqueId(opaquePaymentId) : opaquePaymentId)); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const { order } = await context.mutations.captureOrderPayments(context, { orderId, diff --git a/packages/api-plugin-payments/src/resolvers/Mutation/enablePaymentMethodForShop.js b/packages/api-plugin-payments/src/resolvers/Mutation/enablePaymentMethodForShop.js index 9e46dbe6a34..7fc4590b476 100644 --- a/packages/api-plugin-payments/src/resolvers/Mutation/enablePaymentMethodForShop.js +++ b/packages/api-plugin-payments/src/resolvers/Mutation/enablePaymentMethodForShop.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,7 +19,7 @@ export default async function enablePaymentMethodForShop(parentResult, { input } const { clientMutationId } = input; const paymentMethods = await context.mutations.enablePaymentMethodForShop(context, { ...input, - shopId: decodeShopOpaqueId(input.shopId) + shopId: isOpaqueId(input.shopId) ? decodeShopOpaqueId(input.shopId) : input.shopId }); return { diff --git a/packages/api-plugin-payments/src/resolvers/Query/availablePaymentMethods.js b/packages/api-plugin-payments/src/resolvers/Query/availablePaymentMethods.js index 6b0d94948f0..b86f3c898a7 100644 --- a/packages/api-plugin-payments/src/resolvers/Query/availablePaymentMethods.js +++ b/packages/api-plugin-payments/src/resolvers/Query/availablePaymentMethods.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -12,6 +13,6 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; * @returns {Promise>} Array of PaymentMethods */ export default async function availablePaymentMethods(_, { shopId }, context) { - const dbShopId = decodeShopOpaqueId(shopId); + const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; return context.queries.availablePaymentMethods(context, dbShopId); } diff --git a/packages/api-plugin-payments/src/resolvers/Query/paymentMethods.js b/packages/api-plugin-payments/src/resolvers/Query/paymentMethods.js index 4eda8220f64..c72864b94bf 100644 --- a/packages/api-plugin-payments/src/resolvers/Query/paymentMethods.js +++ b/packages/api-plugin-payments/src/resolvers/Query/paymentMethods.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -12,6 +13,6 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; * @returns {Promise>} Array of PaymentMethods */ export default async function paymentMethods(_, { shopId }, context) { - const dbShopId = decodeShopOpaqueId(shopId); + const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; return context.queries.paymentMethods(context, dbShopId); } diff --git a/packages/api-plugin-pricing-simple/src/resolvers/Mutation/updateProductVariantPrices.js b/packages/api-plugin-pricing-simple/src/resolvers/Mutation/updateProductVariantPrices.js index eafbd90bb76..36b7d4c10b0 100644 --- a/packages/api-plugin-pricing-simple/src/resolvers/Mutation/updateProductVariantPrices.js +++ b/packages/api-plugin-pricing-simple/src/resolvers/Mutation/updateProductVariantPrices.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -25,8 +26,8 @@ export default async function updateProductVariantPrices(_, { input }, context) } = input; const updatedVariant = await context.mutations.updateProductVariantPrices(context, { - variantId: decodeProductOpaqueId(variantId), - shopId: decodeShopOpaqueId(shopId), + variantId: isOpaqueId(variantId) ? decodeProductOpaqueId(variantId) : variantId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, prices }); diff --git a/packages/api-plugin-products/src/resolvers/Mutation/addTagsToProducts.js b/packages/api-plugin-products/src/resolvers/Mutation/addTagsToProducts.js index 954bcf0c033..414dc61f736 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/addTagsToProducts.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/addTagsToProducts.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeProductOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -20,12 +21,12 @@ import { decodeShopOpaqueId, decodeProductOpaqueId, decodeTagOpaqueId } from ".. export default async function addTagsToProducts(_, { input }, context) { const { clientMutationId } = input; const { productIds: opaqueProductIds, shopId: opaqueShopId, tagIds: opaqueTagIds } = input; - const productIds = opaqueProductIds.map(decodeProductOpaqueId); - const tagIds = opaqueTagIds.map(decodeTagOpaqueId); + const productIds = opaqueProductIds.map((opaqueProductId) => (isOpaqueId(opaqueProductId) ? decodeProductOpaqueId(opaqueProductId) : opaqueProductId)); + const tagIds = opaqueTagIds.map((opaqueTagId) => (isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId)); const results = await context.mutations.addTagsToProducts(context, { productIds, - shopId: decodeShopOpaqueId(opaqueShopId), + shopId: isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId, tagIds }); diff --git a/packages/api-plugin-products/src/resolvers/Mutation/archiveProductVariants.js b/packages/api-plugin-products/src/resolvers/Mutation/archiveProductVariants.js index 1b4ca293652..ab7d4714658 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/archiveProductVariants.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/archiveProductVariants.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,14 +20,14 @@ export default async function archiveProductVariants(_, { input }, context) { variantIds } = input; - const decodedVariantIds = variantIds.map((variantId) => decodeProductOpaqueId(variantId)); + const decodedVariantIds = variantIds.map((variantId) => (isOpaqueId(variantId) ? decodeProductOpaqueId(variantId) : variantId)); // This `archiveProductVariants` resolver calls the `archiveProducts` mutation // as we don't have the need to separate this into `archiveProductVariants` at this time. // In the future, we can create a `archiveProductVariants` mutation if needed. const archivedVariants = await context.mutations.archiveProducts(context, { productIds: decodedVariantIds, - shopId: decodeShopOpaqueId(shopId) + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); return { diff --git a/packages/api-plugin-products/src/resolvers/Mutation/archiveProducts.js b/packages/api-plugin-products/src/resolvers/Mutation/archiveProducts.js index 8f60c707b3e..02064c387f4 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/archiveProducts.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/archiveProducts.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,11 +20,11 @@ export default async function archiveProducts(_, { input }, context) { shopId } = input; - const decodedProductIds = productIds.map((productId) => decodeProductOpaqueId(productId)); + const decodedProductIds = productIds.map((productId) => (isOpaqueId(productId) ? decodeProductOpaqueId(productId) : productId)); const archivedProducts = await context.mutations.archiveProducts(context, { productIds: decodedProductIds, - shopId: decodeShopOpaqueId(shopId) + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); return { diff --git a/packages/api-plugin-products/src/resolvers/Mutation/cloneProductVariants.js b/packages/api-plugin-products/src/resolvers/Mutation/cloneProductVariants.js index ad75401b317..aa8a05153de 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/cloneProductVariants.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/cloneProductVariants.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,10 +20,10 @@ export default async function cloneProductVariants(_, { input }, context) { variantIds } = input; - const decodedVariantIds = variantIds.map((variantId) => decodeProductOpaqueId(variantId)); + const decodedVariantIds = variantIds.map((variantId) => (isOpaqueId(variantId) ? decodeProductOpaqueId(variantId) : variantId)); const clonedVariants = await context.mutations.cloneProductVariants(context, { - shopId: decodeShopOpaqueId(shopId), + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, variantIds: decodedVariantIds }); diff --git a/packages/api-plugin-products/src/resolvers/Mutation/cloneProducts.js b/packages/api-plugin-products/src/resolvers/Mutation/cloneProducts.js index 16d8aee59c6..9dc6caa5a11 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/cloneProducts.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/cloneProducts.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -19,11 +20,11 @@ export default async function cloneProducts(_, { input }, context) { shopId } = input; - const decodedProductIds = productIds.map((productId) => decodeProductOpaqueId(productId)); + const decodedProductIds = productIds.map((productId) => (isOpaqueId(productId) ? decodeProductOpaqueId(productId) : productId)); const clonedProducts = await context.mutations.cloneProducts(context, { productIds: decodedProductIds, - shopId: decodeShopOpaqueId(shopId) + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); return { diff --git a/packages/api-plugin-products/src/resolvers/Mutation/createProduct.js b/packages/api-plugin-products/src/resolvers/Mutation/createProduct.js index f24d01f3055..f6dd40d66b4 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/createProduct.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/createProduct.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -23,13 +24,13 @@ export default async function createProduct(_, { input }, context) { } = input; if (productInput && Array.isArray(productInput.tagIds)) { - productInput.hashtags = productInput.tagIds.map(decodeTagOpaqueId); + productInput.hashtags = productInput.tagIds.map((tagId) => (isOpaqueId(tagId) ? decodeTagOpaqueId(tagId) : tagId)); delete productInput.tagIds; } const product = await context.mutations.createProduct(context, { product: productInput, - shopId: decodeShopOpaqueId(shopId), + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, shouldCreateFirstVariant }); diff --git a/packages/api-plugin-products/src/resolvers/Mutation/createProductVariant.js b/packages/api-plugin-products/src/resolvers/Mutation/createProductVariant.js index 00addbe02a4..d9d65ffe538 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/createProductVariant.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/createProductVariant.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -23,8 +24,8 @@ export default async function createProductVariant(_, { input }, context) { } = input; const variant = await context.mutations.createProductVariant(context, { - productId: decodeProductOpaqueId(productId), - shopId: decodeShopOpaqueId(shopId), + productId: isOpaqueId(productId) ? decodeProductOpaqueId(productId) : productId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, variant: variantInput }); diff --git a/packages/api-plugin-products/src/resolvers/Mutation/removeTagsFromProducts.js b/packages/api-plugin-products/src/resolvers/Mutation/removeTagsFromProducts.js index cf57a62db03..8a0b08b9499 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/removeTagsFromProducts.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/removeTagsFromProducts.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeProductOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -19,12 +20,12 @@ import { decodeShopOpaqueId, decodeProductOpaqueId, decodeTagOpaqueId } from ".. export default async function removeTagsFromProducts(_, { input }, context) { const { clientMutationId } = input; const { productIds: opaqueProductIds, shopId: opaqueShopId, tagIds: opaqueTagIds } = input; - const productIds = opaqueProductIds.map(decodeProductOpaqueId); - const tagIds = opaqueTagIds.map(decodeTagOpaqueId); + const productIds = opaqueProductIds.map((opaqueProductId) => (isOpaqueId(opaqueProductId) ? decodeProductOpaqueId(opaqueProductId) : opaqueProductId)); + const tagIds = opaqueTagIds.map((opaqueTagId) => (isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId)); const results = await context.mutations.removeTagsFromProducts(context, { productIds, - shopId: decodeShopOpaqueId(opaqueShopId), + shopId: isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId, tagIds }); diff --git a/packages/api-plugin-products/src/resolvers/Mutation/updateProduct.js b/packages/api-plugin-products/src/resolvers/Mutation/updateProduct.js index f8e168a0d80..9a59b12824f 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/updateProduct.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/updateProduct.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -23,14 +24,14 @@ export default async function updateProduct(_, { input }, context) { } = input; if (Array.isArray(productInput.tagIds)) { - productInput.hashtags = productInput.tagIds.map(decodeTagOpaqueId); + productInput.hashtags = productInput.tagIds.map((tagId) => (isOpaqueId(tagId) ? decodeTagOpaqueId(tagId) : tagId)); delete productInput.tagIds; } const updatedProduct = await context.mutations.updateProduct(context, { product: productInput, - productId: decodeProductOpaqueId(productId), - shopId: decodeShopOpaqueId(shopId) + productId: isOpaqueId(productId) ? decodeProductOpaqueId(productId) : productId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); return { diff --git a/packages/api-plugin-products/src/resolvers/Mutation/updateProductVariant.js b/packages/api-plugin-products/src/resolvers/Mutation/updateProductVariant.js index 34666dc858e..6cdfe52d04c 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/updateProductVariant.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/updateProductVariant.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -23,8 +24,8 @@ export default async function updateProductVariant(_, { input }, context) { } = input; const updatedVariant = await context.mutations.updateProductVariant(context, { - variantId: decodeProductOpaqueId(variantId), - shopId: decodeShopOpaqueId(shopId), + variantId: isOpaqueId(variantId) ? decodeProductOpaqueId(variantId) : variantId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, variant }); diff --git a/packages/api-plugin-products/src/resolvers/Mutation/updateProductsVisibility.js b/packages/api-plugin-products/src/resolvers/Mutation/updateProductsVisibility.js index 654f53a3cb2..748e54abebc 100644 --- a/packages/api-plugin-products/src/resolvers/Mutation/updateProductsVisibility.js +++ b/packages/api-plugin-products/src/resolvers/Mutation/updateProductsVisibility.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeProductOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -21,11 +22,11 @@ export default async function updateProductsVisibility(_, { input }, context) { isVisible } = input; - const decodedProductIds = productIds.map((productId) => decodeProductOpaqueId(productId)); + const decodedProductIds = productIds.map((productId) => (isOpaqueId(productId) ? decodeProductOpaqueId(productId) : productId)); const { updatedCount } = await context.mutations.updateProductsVisibility(context, { productIds: decodedProductIds, - shopId: decodeShopOpaqueId(shopId), + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId, isVisible }); diff --git a/packages/api-plugin-settings/src/resolvers/Mutation/updateShopSettings.js b/packages/api-plugin-settings/src/resolvers/Mutation/updateShopSettings.js index d99fb993c94..d6684fe55ac 100644 --- a/packages/api-plugin-settings/src/resolvers/Mutation/updateShopSettings.js +++ b/packages/api-plugin-settings/src/resolvers/Mutation/updateShopSettings.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,7 +21,7 @@ export default async function updateShopSettings(_, { input }, context) { clientMutationId = null } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const shopSettings = await context.mutations.updateAppSettings(context, settingsUpdates, shopId); diff --git a/packages/api-plugin-settings/src/resolvers/Query/shopSettings.js b/packages/api-plugin-settings/src/resolvers/Query/shopSettings.js index 5cc6e7ebb3c..4165bb00374 100644 --- a/packages/api-plugin-settings/src/resolvers/Query/shopSettings.js +++ b/packages/api-plugin-settings/src/resolvers/Query/shopSettings.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -13,7 +14,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; export default async function shopSettings(_, args, context) { const { shopId } = args; - const internalShopId = decodeShopOpaqueId(shopId); + const internalShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; return context.queries.appSettings(context, internalShopId); } diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentMethod.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentMethod.js index 8c5914ee9ca..d025b19c944 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentMethod.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentMethod.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; import createFlatRateFulfillmentMethodMutation from "../../mutations/createFlatRateFulfillmentMethod.js"; @@ -17,7 +18,7 @@ import createFlatRateFulfillmentMethodMutation from "../../mutations/createFlatR export default async function createFlatRateFulfillmentMethod(parentResult, { input }, context) { const { clientMutationId = null, method, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const { method: insertedMethod } = await createFlatRateFulfillmentMethodMutation(context, { method, diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentRestriction.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentRestriction.js index aad8aaf7fa8..d1763fd92c8 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentRestriction.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/createFlatRateFulfillmentRestriction.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; import createFlatRateFulfillmentRestrictionMutation from "../../mutations/createFlatRateFulfillmentRestriction.js"; @@ -17,11 +18,11 @@ import createFlatRateFulfillmentRestrictionMutation from "../../mutations/create export default async function createFlatRateFulfillmentRestriction(parentResult, { input }, context) { const { clientMutationId = null, restriction, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; let decodedMethodIds = []; if (restriction.methodIds && Array.isArray(restriction.methodIds)) { - decodedMethodIds = restriction.methodIds.map((methodId) => decodeFulfillmentMethodOpaqueId(methodId)); + decodedMethodIds = restriction.methodIds.map((methodId) => (isOpaqueId(methodId) ? decodeFulfillmentMethodOpaqueId(methodId) : methodId)); } restriction.methodIds = decodedMethodIds; diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentMethod.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentMethod.js index 92e247119aa..dd398ba3225 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentMethod.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentMethod.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; import deleteFlatRateFulfillmentMethodMutation from "../../mutations/deleteFlatRateFulfillmentMethod.js"; @@ -17,8 +18,8 @@ import deleteFlatRateFulfillmentMethodMutation from "../../mutations/deleteFlatR export default async function deleteFlatRateFulfillmentMethod(parentResult, { input }, context) { const { clientMutationId = null, methodId: opaqueMethodId, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const methodId = decodeFulfillmentMethodOpaqueId(opaqueMethodId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const methodId = isOpaqueId(opaqueMethodId) ? decodeFulfillmentMethodOpaqueId(opaqueMethodId) : opaqueMethodId; const { method } = await deleteFlatRateFulfillmentMethodMutation(context, { methodId, diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentRestriction.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentRestriction.js index 0a5c62a92ce..987f4aa483f 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentRestriction.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/deleteFlatRateFulfillmentRestriction.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentRestrictionOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; import deleteFlatRateFulfillmentRestrictionMutation from "../../mutations/deleteFlatRateFulfillmentRestriction.js"; @@ -17,8 +18,8 @@ import deleteFlatRateFulfillmentRestrictionMutation from "../../mutations/delete export default async function deleteFlatRateFulfillmentRestriction(parentResult, { input }, context) { const { clientMutationId = null, restrictionId: opaqueRestrictionId, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const restrictionId = decodeFulfillmentRestrictionOpaqueId(opaqueRestrictionId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const restrictionId = isOpaqueId(opaqueRestrictionId) ? decodeFulfillmentRestrictionOpaqueId(opaqueRestrictionId) : opaqueRestrictionId; const { restriction } = await deleteFlatRateFulfillmentRestrictionMutation(context, { restrictionId, diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentMethod.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentMethod.js index 0ae0267effc..692d56601e2 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentMethod.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentMethod.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; import updateFlatRateFulfillmentMethodMutation from "../../mutations/updateFlatRateFulfillmentMethod.js"; @@ -18,8 +19,8 @@ import updateFlatRateFulfillmentMethodMutation from "../../mutations/updateFlatR export default async function updateFlatRateFulfillmentMethod(parentResult, { input }, context) { const { clientMutationId = null, method, methodId: opaqueMethodId, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const methodId = decodeFulfillmentMethodOpaqueId(opaqueMethodId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const methodId = isOpaqueId(opaqueMethodId) ? decodeFulfillmentMethodOpaqueId(opaqueMethodId) : opaqueMethodId; const { method: updatedMethod } = await updateFlatRateFulfillmentMethodMutation(context, { method, diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentRestriction.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentRestriction.js index 6a6a70a5775..04271034b87 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentRestriction.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Mutation/updateFlatRateFulfillmentRestriction.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeFulfillmentRestrictionOpaqueId, @@ -22,12 +23,12 @@ import updateFlatRateFulfillmentRestrictionMutation from "../../mutations/update export default async function updateFlatRateFulfillmentRestriction(parentResult, { input }, context) { const { clientMutationId = null, restriction, restrictionId: opaqueRestrictionId, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const restrictionId = decodeFulfillmentRestrictionOpaqueId(opaqueRestrictionId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const restrictionId = isOpaqueId(opaqueRestrictionId) ? decodeFulfillmentRestrictionOpaqueId(opaqueRestrictionId) : opaqueRestrictionId; let decodedMethodIds = []; if (restriction.methodIds && Array.isArray(restriction.methodIds)) { - decodedMethodIds = restriction.methodIds.map((methodId) => decodeFulfillmentMethodOpaqueId(methodId)); + decodedMethodIds = restriction.methodIds.map((methodId) => (isOpaqueId(methodId) ? decodeFulfillmentMethodOpaqueId(methodId) : methodId)); } restriction.methodIds = decodedMethodIds; diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethod.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethod.js index b65aa6523a8..d9acbcf1cb5 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethod.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethod.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,8 +19,8 @@ export default async function flatRateFulfillmentMethod(_, args, context) { shopId: opaqueShopId } = args; - const methodId = decodeFulfillmentMethodOpaqueId(opaqueMethodId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const methodId = isOpaqueId(opaqueMethodId) ? decodeFulfillmentMethodOpaqueId(opaqueMethodId) : opaqueMethodId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; return context.queries.flatRateFulfillmentMethod(context, { methodId, diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethods.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethods.js index 113888fae26..f29cd0c2a6b 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethods.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/flatRateFulfillmentMethods.js @@ -1,5 +1,6 @@ import getPaginatedResponseFromAggregate from "@reactioncommerce/api-utils/graphql/getPaginatedResponseFromAggregate.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -17,7 +18,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; export default async function flatRateFulfillmentMethods(_, args, context, info) { const { shopId: opaqueShopId, ...connectionArgs } = args; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const { collection, pipeline } = await context.queries.flatRateFulfillmentMethods(context, { shopId diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestriction.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestriction.js index e0955d25650..40ff690c676 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestriction.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestriction.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentRestrictionOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -15,7 +16,7 @@ export default async function getFlatRateFulfillmentRestriction(parentResult, ar const { restrictionId, shopId } = args; return context.queries.getFlatRateFulfillmentRestriction(context, { - restrictionId: decodeFulfillmentRestrictionOpaqueId(restrictionId), - shopId: decodeShopOpaqueId(shopId) + restrictionId: isOpaqueId(restrictionId) ? decodeFulfillmentRestrictionOpaqueId(restrictionId) : restrictionId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); } diff --git a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestrictions.js b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestrictions.js index 6f4b8792c3e..cdecf3d7e7c 100644 --- a/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestrictions.js +++ b/packages/api-plugin-shipments-flat-rate/src/resolvers/Query/getFlatRateFulfillmentRestrictions.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,7 +19,7 @@ export default async function getFlatRateFulfillmentRestrictions(parentResult, a const { shopId, ...connectionArgs } = args; const cursor = await context.queries.getFlatRateFulfillmentRestrictions(context, { - shopId: decodeShopOpaqueId(shopId) + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); return getPaginatedResponse(cursor, connectionArgs, { diff --git a/packages/api-plugin-shipments/src/resolvers/Mutation/selectFulfillmentOptionForGroup.js b/packages/api-plugin-shipments/src/resolvers/Mutation/selectFulfillmentOptionForGroup.js index 260efda3b50..85d2b92a3ba 100644 --- a/packages/api-plugin-shipments/src/resolvers/Mutation/selectFulfillmentOptionForGroup.js +++ b/packages/api-plugin-shipments/src/resolvers/Mutation/selectFulfillmentOptionForGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId, decodeFulfillmentGroupOpaqueId, decodeFulfillmentMethodOpaqueId } from "../../xforms/id.js"; import selectFulfillmentOptionForGroupMutation from "../../mutations/selectFulfillmentOptionForGroup.js"; @@ -25,9 +26,9 @@ export default async function selectFulfillmentOptionForGroup(parentResult, { in fulfillmentMethodId: opaqueFulfillmentMethodId } = input; - const cartId = decodeCartOpaqueId(opaqueCartId); - const fulfillmentGroupId = decodeFulfillmentGroupOpaqueId(opaqueFulfillmentGroupId); - const fulfillmentMethodId = decodeFulfillmentMethodOpaqueId(opaqueFulfillmentMethodId); + const cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; + const fulfillmentGroupId = isOpaqueId(opaqueFulfillmentGroupId) ? decodeFulfillmentGroupOpaqueId(opaqueFulfillmentGroupId) : opaqueFulfillmentGroupId; + const fulfillmentMethodId = isOpaqueId(opaqueFulfillmentMethodId) ? decodeFulfillmentMethodOpaqueId(opaqueFulfillmentMethodId) : opaqueFulfillmentMethodId; const { cart } = await selectFulfillmentOptionForGroupMutation(context, { cartId, diff --git a/packages/api-plugin-shipments/src/resolvers/Mutation/updateFulfillmentOptionsForGroup.js b/packages/api-plugin-shipments/src/resolvers/Mutation/updateFulfillmentOptionsForGroup.js index d0a35758b97..4191626b2a1 100644 --- a/packages/api-plugin-shipments/src/resolvers/Mutation/updateFulfillmentOptionsForGroup.js +++ b/packages/api-plugin-shipments/src/resolvers/Mutation/updateFulfillmentOptionsForGroup.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeCartOpaqueId, decodeFulfillmentGroupOpaqueId } from "../../xforms/id.js"; import updateFulfillmentOptionsForGroupMutation from "../../mutations/updateFulfillmentOptionsForGroup.js"; @@ -18,8 +19,8 @@ import updateFulfillmentOptionsForGroupMutation from "../../mutations/updateFulf export default async function updateFulfillmentOptionsForGroup(parentResult, { input }, context) { const { cartId: opaqueCartId, cartToken, clientMutationId = null, fulfillmentGroupId: opaqueFulfillmentGroupId } = input; - const fulfillmentGroupId = decodeFulfillmentGroupOpaqueId(opaqueFulfillmentGroupId); - const cartId = decodeCartOpaqueId(opaqueCartId); + const fulfillmentGroupId = isOpaqueId(opaqueFulfillmentGroupId) ? decodeFulfillmentGroupOpaqueId(opaqueFulfillmentGroupId) : opaqueFulfillmentGroupId; + const cartId = isOpaqueId(opaqueCartId) ? decodeCartOpaqueId(opaqueCartId) : opaqueCartId; const { cart } = await updateFulfillmentOptionsForGroupMutation(context, { cartId, diff --git a/packages/api-plugin-shops/src/resolvers/Mutation/updateShop.js b/packages/api-plugin-shops/src/resolvers/Mutation/updateShop.js index b5f5cf8faf4..a3a78a3010f 100644 --- a/packages/api-plugin-shops/src/resolvers/Mutation/updateShop.js +++ b/packages/api-plugin-shops/src/resolvers/Mutation/updateShop.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeMediaRecordOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -26,11 +27,12 @@ export default async function updateShop(_, { input }, context) { shopId: opaqueShopId, ...passThroughInput } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; // Decode brand asset media record id if (passThroughInput.brandAssets) { - passThroughInput.brandAssets = decodeMediaRecordOpaqueId(passThroughInput.brandAssets); + passThroughInput.brandAssets = isOpaqueId(passThroughInput.brandAssets) ? + decodeMediaRecordOpaqueId(passThroughInput.brandAssets) : passThroughInput.brandAssets; } const updatedShop = await context.mutations.updateShop(context, { diff --git a/packages/api-plugin-shops/src/resolvers/Query/shop.js b/packages/api-plugin-shops/src/resolvers/Query/shop.js index 24b0db17d34..ad4b8e26a3f 100644 --- a/packages/api-plugin-shops/src/resolvers/Query/shop.js +++ b/packages/api-plugin-shops/src/resolvers/Query/shop.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -12,7 +13,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; * @returns {Promise} shop object */ export default async function shop(_, { id }, context) { - const dbShopId = decodeShopOpaqueId(id); + const dbShopId = isOpaqueId(id) ? decodeShopOpaqueId(id) : id; return context.queries.shopById(context, dbShopId); } diff --git a/packages/api-plugin-shops/src/resolvers/Query/shops.js b/packages/api-plugin-shops/src/resolvers/Query/shops.js index 25e87abb46d..559488f2062 100644 --- a/packages/api-plugin-shops/src/resolvers/Query/shops.js +++ b/packages/api-plugin-shops/src/resolvers/Query/shops.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -22,7 +23,7 @@ export default async function shops(_, { shopIds, ...connectionArgs }, context, let decodedShopIds; if (Array.isArray(shopIds) && shopIds.length > 0) { - decodedShopIds = shopIds.map((shopId) => decodeShopOpaqueId(shopId)); + decodedShopIds = shopIds.map((shopId) => (isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId)); } const query = await context.queries.shops(context, { shopIds: decodedShopIds }); diff --git a/packages/api-plugin-sitemap-generator/src/resolvers/Mutation/generateSitemaps.js b/packages/api-plugin-sitemap-generator/src/resolvers/Mutation/generateSitemaps.js index 5f48467b52e..4bef5df257c 100644 --- a/packages/api-plugin-sitemap-generator/src/resolvers/Mutation/generateSitemaps.js +++ b/packages/api-plugin-sitemap-generator/src/resolvers/Mutation/generateSitemaps.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -15,7 +16,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; export default async function generateSitemaps(parentResult, { input = {} }, context) { const { clientMutationId = null, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; await context.mutations.generateSitemaps(context, { shopId }); diff --git a/packages/api-plugin-surcharges/src/resolvers/Mutation/createSurcharge.js b/packages/api-plugin-surcharges/src/resolvers/Mutation/createSurcharge.js index 5760aa09a30..9433e41c7df 100644 --- a/packages/api-plugin-surcharges/src/resolvers/Mutation/createSurcharge.js +++ b/packages/api-plugin-surcharges/src/resolvers/Mutation/createSurcharge.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -16,11 +17,11 @@ import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId } from "../../xform export default async function createSurcharge(parentResult, { input }, context) { const { clientMutationId = null, surcharge, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; let decodedMethodIds = []; if (surcharge.methodIds && Array.isArray(surcharge.methodIds)) { - decodedMethodIds = surcharge.methodIds.map((methodId) => decodeFulfillmentMethodOpaqueId(methodId)); + decodedMethodIds = surcharge.methodIds.map((methodId) => (isOpaqueId(methodId) ? decodeFulfillmentMethodOpaqueId(methodId) : methodId)); } surcharge.methodIds = decodedMethodIds; diff --git a/packages/api-plugin-surcharges/src/resolvers/Mutation/deleteSurcharge.js b/packages/api-plugin-surcharges/src/resolvers/Mutation/deleteSurcharge.js index 2e1638a7a9c..9cbd2206499 100644 --- a/packages/api-plugin-surcharges/src/resolvers/Mutation/deleteSurcharge.js +++ b/packages/api-plugin-surcharges/src/resolvers/Mutation/deleteSurcharge.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeSurchargeOpaqueId } from "../../xforms/id.js"; /** @@ -16,8 +17,8 @@ import { decodeShopOpaqueId, decodeSurchargeOpaqueId } from "../../xforms/id.js" export default async function deleteSurcharge(parentResult, { input }, context) { const { clientMutationId = null, surchargeId: opaqueSurchargeId, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const surchargeId = decodeSurchargeOpaqueId(opaqueSurchargeId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const surchargeId = isOpaqueId(opaqueSurchargeId) ? decodeSurchargeOpaqueId(opaqueSurchargeId) : opaqueSurchargeId; const { surcharge } = await context.mutations.deleteSurcharge(context, { surchargeId, diff --git a/packages/api-plugin-surcharges/src/resolvers/Mutation/updateSurcharge.js b/packages/api-plugin-surcharges/src/resolvers/Mutation/updateSurcharge.js index 8fdcb52cce6..98812f0be65 100644 --- a/packages/api-plugin-surcharges/src/resolvers/Mutation/updateSurcharge.js +++ b/packages/api-plugin-surcharges/src/resolvers/Mutation/updateSurcharge.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId, decodeSurchargeOpaqueId } from "../../xforms/id.js"; /** @@ -17,12 +18,12 @@ import { decodeFulfillmentMethodOpaqueId, decodeShopOpaqueId, decodeSurchargeOpa export default async function updateSurcharge(parentResult, { input }, context) { const { clientMutationId = null, surcharge, surchargeId: opaqueSurchargeId, shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const surchargeId = decodeSurchargeOpaqueId(opaqueSurchargeId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const surchargeId = isOpaqueId(opaqueSurchargeId) ? decodeSurchargeOpaqueId(opaqueSurchargeId) : opaqueSurchargeId; let decodedMethodIds = []; if (surcharge.methodIds && Array.isArray(surcharge.methodIds)) { - decodedMethodIds = surcharge.methodIds.map((methodId) => decodeFulfillmentMethodOpaqueId(methodId)); + decodedMethodIds = surcharge.methodIds.map((methodId) => (isOpaqueId(methodId) ? decodeFulfillmentMethodOpaqueId(methodId) : methodId)); } surcharge.methodIds = decodedMethodIds; diff --git a/packages/api-plugin-surcharges/src/resolvers/Query/surchargeById.js b/packages/api-plugin-surcharges/src/resolvers/Query/surchargeById.js index 7b627cf3415..6231b45cfb3 100644 --- a/packages/api-plugin-surcharges/src/resolvers/Query/surchargeById.js +++ b/packages/api-plugin-surcharges/src/resolvers/Query/surchargeById.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeSurchargeOpaqueId } from "../../xforms/id.js"; /** @@ -17,7 +18,7 @@ export default async function surchargeById(parentResult, args, context) { const { surchargeId, shopId } = args; return context.queries.surchargeById(context, { - surchargeId: decodeSurchargeOpaqueId(surchargeId), - shopId: decodeShopOpaqueId(shopId) + surchargeId: isOpaqueId(surchargeId) ? decodeSurchargeOpaqueId(surchargeId) : surchargeId, + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); } diff --git a/packages/api-plugin-surcharges/src/resolvers/Query/surcharges.js b/packages/api-plugin-surcharges/src/resolvers/Query/surcharges.js index 597f796a0a9..a183f536e89 100644 --- a/packages/api-plugin-surcharges/src/resolvers/Query/surcharges.js +++ b/packages/api-plugin-surcharges/src/resolvers/Query/surcharges.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -18,7 +19,7 @@ export default async function surcharges(parentResult, args, context, info) { const { shopId, ...connectionArgs } = args; const cursor = await context.queries.surcharges(context, { - shopId: decodeShopOpaqueId(shopId) + shopId: isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId }); return getPaginatedResponse(cursor, connectionArgs, { diff --git a/packages/api-plugin-system-information/src/resolvers/Query/systemInformation.js b/packages/api-plugin-system-information/src/resolvers/Query/systemInformation.js index e0c74d1d0ba..fd4110b5320 100644 --- a/packages/api-plugin-system-information/src/resolvers/Query/systemInformation.js +++ b/packages/api-plugin-system-information/src/resolvers/Query/systemInformation.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -11,6 +12,6 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; * @returns {Promise} System Information Object */ export default async function systemInformation(_, args, context) { - const dbShopId = decodeShopOpaqueId(args.shopId); + const dbShopId = isOpaqueId(args.shopId) ? decodeShopOpaqueId(args.shopId) : args.shopId; return context.queries.systemInformation(context, dbShopId); } diff --git a/packages/api-plugin-tags/src/resolvers/Mutation/addTag.js b/packages/api-plugin-tags/src/resolvers/Mutation/addTag.js index d3e1790b7cb..1e87ddda1e6 100644 --- a/packages/api-plugin-tags/src/resolvers/Mutation/addTag.js +++ b/packages/api-plugin-tags/src/resolvers/Mutation/addTag.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -21,7 +22,7 @@ export default async function addTag(parentResult, { input }, context) { ...tagInput } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const tag = await context.mutations.addTag(context, { shopId, diff --git a/packages/api-plugin-tags/src/resolvers/Mutation/removeTag.js b/packages/api-plugin-tags/src/resolvers/Mutation/removeTag.js index 39f59f65ee0..e1812492bce 100644 --- a/packages/api-plugin-tags/src/resolvers/Mutation/removeTag.js +++ b/packages/api-plugin-tags/src/resolvers/Mutation/removeTag.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -20,8 +21,8 @@ export default async function removeTag(parentResult, { input }, context) { shopId: opaqueShopId } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const tagId = decodeTagOpaqueId(opaqueTagId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const tagId = isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId; const tag = await context.mutations.removeTag(context, { shopId, diff --git a/packages/api-plugin-tags/src/resolvers/Mutation/setTagHeroMedia.js b/packages/api-plugin-tags/src/resolvers/Mutation/setTagHeroMedia.js index ecd335bfea0..0e8d7cda56d 100644 --- a/packages/api-plugin-tags/src/resolvers/Mutation/setTagHeroMedia.js +++ b/packages/api-plugin-tags/src/resolvers/Mutation/setTagHeroMedia.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -22,8 +23,8 @@ export default async function setTagHeroMedia(parentResult, { input }, context) fileRecord } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const tagId = decodeTagOpaqueId(opaqueTagId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const tagId = isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId; const tag = await context.mutations.setTagHeroMedia(context, { shopId, diff --git a/packages/api-plugin-tags/src/resolvers/Mutation/updateTag.js b/packages/api-plugin-tags/src/resolvers/Mutation/updateTag.js index 29d523b8a96..368cfed24d1 100644 --- a/packages/api-plugin-tags/src/resolvers/Mutation/updateTag.js +++ b/packages/api-plugin-tags/src/resolvers/Mutation/updateTag.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -22,8 +23,8 @@ export default async function updateTag(parentResult, { input }, context) { ...tagInput } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); - const tagId = decodeTagOpaqueId(opaqueTagId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const tagId = isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId; const tag = await context.mutations.updateTag(context, { shopId, diff --git a/packages/api-plugin-tags/src/resolvers/Query/productsByTagId.js b/packages/api-plugin-tags/src/resolvers/Query/productsByTagId.js index 36fbe98740a..04bf96f9fd6 100644 --- a/packages/api-plugin-tags/src/resolvers/Query/productsByTagId.js +++ b/packages/api-plugin-tags/src/resolvers/Query/productsByTagId.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -25,8 +26,8 @@ export default async function productsByTagId(_, params, context) { query } = params; - const shopId = decodeShopOpaqueId(opaqueShopId); - const tagId = decodeTagOpaqueId(opaqueTagId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; + const tagId = isOpaqueId(opaqueTagId) ? decodeTagOpaqueId(opaqueTagId) : opaqueTagId; return context.queries.productsByTagId(context, { connectionArgs: { diff --git a/packages/api-plugin-tags/src/resolvers/Query/tag.js b/packages/api-plugin-tags/src/resolvers/Query/tag.js index 3af2f13d0b6..b7a7668de5c 100644 --- a/packages/api-plugin-tags/src/resolvers/Query/tag.js +++ b/packages/api-plugin-tags/src/resolvers/Query/tag.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; /** @@ -22,12 +23,12 @@ import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; export default async function tag(_, connectionArgs, context) { const { slugOrId: opaqueSlugOrId, shopId: opaqueShopId } = connectionArgs; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; let slugOrId; try { - slugOrId = decodeTagOpaqueId(opaqueSlugOrId); + slugOrId = isOpaqueId(opaqueSlugOrId) ? decodeTagOpaqueId(opaqueSlugOrId) : opaqueSlugOrId; } catch (error) { slugOrId = opaqueSlugOrId; } diff --git a/packages/api-plugin-tags/src/resolvers/Query/tags.js b/packages/api-plugin-tags/src/resolvers/Query/tags.js index fd9cbf5dc31..523a4340591 100644 --- a/packages/api-plugin-tags/src/resolvers/Query/tags.js +++ b/packages/api-plugin-tags/src/resolvers/Query/tags.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; @@ -29,11 +30,11 @@ import { decodeShopOpaqueId, decodeTagOpaqueId } from "../../xforms/id.js"; export default async function tags(_, connectionArgs, context, info) { const { shopId, excludedTagIds } = connectionArgs; - const dbShopId = decodeShopOpaqueId(shopId); + const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; let dbExcludedTagIds; if (Array.isArray(excludedTagIds)) { - dbExcludedTagIds = excludedTagIds.map(decodeTagOpaqueId); + dbExcludedTagIds = excludedTagIds.map((tagId) => (isOpaqueId(tagId) ? decodeTagOpaqueId(tagId) : tagId)); } const query = await context.queries.tags(context, dbShopId, { diff --git a/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/createTaxRate.js b/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/createTaxRate.js index 10a986b8d80..56df68e1a24 100644 --- a/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/createTaxRate.js +++ b/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/createTaxRate.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -20,7 +21,7 @@ export default async function createTaxRate(parentResult, { input }, context) { ...taxRateInput } = input; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const taxRate = await context.mutations.createTaxRate(context, { shopId, diff --git a/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/deleteTaxRate.js b/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/deleteTaxRate.js index 8f9dd471a21..6ce1db5fe46 100644 --- a/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/deleteTaxRate.js +++ b/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/deleteTaxRate.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTaxRateOpaqueId } from "../../xforms/id.js"; /** @@ -20,8 +21,8 @@ export default async function deleteTaxRate(parentResult, { input }, context) { shopId: opaqueShopId } = input; - const _id = decodeTaxRateOpaqueId(opaqueTaxRateId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const _id = isOpaqueId(opaqueTaxRateId) ? decodeTaxRateOpaqueId(opaqueTaxRateId) : opaqueTaxRateId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const taxRate = await context.mutations.deleteTaxRate(context, { _id, diff --git a/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/updateTaxRate.js b/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/updateTaxRate.js index 6b8fbb5cd3d..df7c996d067 100644 --- a/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/updateTaxRate.js +++ b/packages/api-plugin-taxes-flat-rate/src/resolvers/Mutation/updateTaxRate.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId, decodeTaxRateOpaqueId } from "../../xforms/id.js"; /** @@ -22,8 +23,8 @@ export default async function updateTaxRate(parentResult, { input }, context) { ...taxRateInput } = input; - const _id = decodeTaxRateOpaqueId(opaqueTaxRateId); - const shopId = decodeShopOpaqueId(opaqueShopId); + const _id = isOpaqueId(opaqueTaxRateId) ? decodeTaxRateOpaqueId(opaqueTaxRateId) : opaqueTaxRateId; + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const taxRate = await context.mutations.updateTaxRate(context, { _id, diff --git a/packages/api-plugin-taxes-flat-rate/src/resolvers/Query/taxRates.js b/packages/api-plugin-taxes-flat-rate/src/resolvers/Query/taxRates.js index d3ac721a084..fc72819a8e9 100644 --- a/packages/api-plugin-taxes-flat-rate/src/resolvers/Query/taxRates.js +++ b/packages/api-plugin-taxes-flat-rate/src/resolvers/Query/taxRates.js @@ -1,5 +1,6 @@ import getPaginatedResponse from "@reactioncommerce/api-utils/graphql/getPaginatedResponse.js"; import wasFieldRequested from "@reactioncommerce/api-utils/graphql/wasFieldRequested.js"; +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -17,7 +18,7 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; export default async function taxRates(_, args, context, info) { const { shopId: opaqueShopId, ...connectionArgs } = args; - const shopId = decodeShopOpaqueId(opaqueShopId); + const shopId = isOpaqueId(opaqueShopId) ? decodeShopOpaqueId(opaqueShopId) : opaqueShopId; const query = await context.queries.taxRates(context, shopId); diff --git a/packages/api-plugin-taxes/src/resolvers/Query/taxCodes.js b/packages/api-plugin-taxes/src/resolvers/Query/taxCodes.js index 4119a4db0cd..21cce6519eb 100644 --- a/packages/api-plugin-taxes/src/resolvers/Query/taxCodes.js +++ b/packages/api-plugin-taxes/src/resolvers/Query/taxCodes.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -12,6 +13,6 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; * @returns {Promise} Array of tax services */ export default async function taxCodes(_, { shopId }, context) { - const dbShopId = decodeShopOpaqueId(shopId); + const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; return context.queries.taxCodes(context, dbShopId); } diff --git a/packages/api-plugin-taxes/src/resolvers/Query/taxServices.js b/packages/api-plugin-taxes/src/resolvers/Query/taxServices.js index c67c17ba669..52bb95d6ed6 100644 --- a/packages/api-plugin-taxes/src/resolvers/Query/taxServices.js +++ b/packages/api-plugin-taxes/src/resolvers/Query/taxServices.js @@ -1,3 +1,4 @@ +import isOpaqueId from "@reactioncommerce/api-utils/isOpaqueId.js"; import { decodeShopOpaqueId } from "../../xforms/id.js"; /** @@ -12,6 +13,6 @@ import { decodeShopOpaqueId } from "../../xforms/id.js"; * @returns {Promise} Array of tax services */ export default async function taxServices(_, { shopId }, context) { - const dbShopId = decodeShopOpaqueId(shopId); + const dbShopId = isOpaqueId(shopId) ? decodeShopOpaqueId(shopId) : shopId; return context.queries.taxServices(context, dbShopId); }