diff --git a/CHANGELOG.md b/CHANGELOG.md index ea0cc33..6166e7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added mail notification to `createOrganizationAndCostCenterWithAdminUser` mutation +## [0.63.0] - 2024-12-04 +### Fixed +- Remove merge marker from code + +## [0.62.1] - 2024-12-04 +### Added +- Add TopBarSettings type in B2B settings and updated saveB2BSettings to use the new topBar field in UISettings + +## [0.62.0] - 2024-12-03 +### Added + +- Add getActiveOrganizationsByEmail to return only active organizations + ## [0.61.1] - 2024-10-29 ### Fixed - Avoid calls to checkUserPermissions when session data is not available + ## [0.61.0] - 2024-10-16 ### Added diff --git a/graphql/schema.graphql b/graphql/schema.graphql index a6a4941..817125b 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -93,6 +93,10 @@ type Query { @checkUserAccess @cacheControl(scope: PRIVATE) + getActiveOrganizationsByEmail(email: String): [B2BOrganization] + @cacheControl(scope: PRIVATE) + @validateStoreUserAccess + checkOrganizationIsActive(id: String): Boolean @cacheControl(scope: PRIVATE) @auditAccess @@ -521,10 +525,16 @@ type TransactionEmailSettings { organizationStatusChanged: Boolean } +type TopBarSettings { + name: String + hexColor: String +} + type UISettings { showModal: Boolean clearCart: Boolean fullImpersonation: Boolean + topBar: TopBarSettings } scalar Data @@ -677,10 +687,16 @@ input TransactionEmailSettingsInput { organizationStatusChanged: Boolean } +input TopBarSettingsInput { + name: String + hexColor: String +} + input UISettingsInput { showModal: Boolean clearCart: Boolean fullImpersonation: Boolean + topBar: TopBarSettingsInput } input B2BSettingsInput { diff --git a/manifest.json b/manifest.json index 9cc408f..596fbca 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "b2b-organizations-graphql", "vendor": "vtex", - "version": "0.61.1", + "version": "0.63.0", "title": "B2B Organizations", "description": "App to create and manage B2B Organizations and Cost Centers", "mustUpdateAt": "2022-08-28", diff --git a/node/package.json b/node/package.json index d6e0fc7..4892a23 100644 --- a/node/package.json +++ b/node/package.json @@ -1,9 +1,9 @@ { "name": "vtex.b2b-organizations", - "version": "0.61.1", + "version": "0.63.0", "dependencies": { "@types/lodash": "4.14.74", - "@vtex/api": "6.47.0", + "@vtex/api": "6.48.0", "atob": "^2.1.2", "co-body": "^6.0.0", "graphql": "^14.5.0", @@ -20,7 +20,7 @@ "@types/jsonwebtoken": "^8.5.0", "@types/node": "^12.12.21", "@types/ramda": "types/npm-ramda#dist", - "@vtex/api": "6.47.0", + "@vtex/api": "6.48.0", "@vtex/prettier-config": "^0.3.1", "@vtex/tsconfig": "^0.6.0", "jest": "27.5.1", diff --git a/node/resolvers/Mutations/Settings.ts b/node/resolvers/Mutations/Settings.ts index 764c990..b8d1a98 100644 --- a/node/resolvers/Mutations/Settings.ts +++ b/node/resolvers/Mutations/Settings.ts @@ -103,7 +103,11 @@ const Settings = { transactionEmailSettings: transactionEmailSettings ?? currentB2BSettings?.transactionEmailSettings, - uiSettings, + uiSettings: { + showModal: uiSettings.showModal, + clearCart: uiSettings.clearCart, + topBar: uiSettings.topBar ?? currentB2BSettings?.uiSettings?.topBar, + }, } await vbase.saveJSON(B2B_SETTINGS_DATA_ENTITY, 'settings', b2bSettings) diff --git a/node/resolvers/Queries/Organizations.ts b/node/resolvers/Queries/Organizations.ts index f541e1f..7c78c8d 100644 --- a/node/resolvers/Queries/Organizations.ts +++ b/node/resolvers/Queries/Organizations.ts @@ -6,9 +6,13 @@ import { ORGANIZATION_REQUEST_SCHEMA_VERSION, ORGANIZATION_SCHEMA_VERSION, } from '../../mdSchema' -import type { Organization } from '../../typings' +import type { + GetOrganizationsByEmailWithStatus, + Organization, +} from '../../typings' import GraphQLError, { getErrorMessage } from '../../utils/GraphQLError' import checkConfig from '../config' +import { organizationStatus } from '../fieldResolvers' const getWhereByStatus = ({ status }: { status: string[] }) => { const whereArray = [] @@ -182,11 +186,13 @@ const Organizations = { getOrganizationsByEmail: async ( _: void, { email }: { email: string }, - { + ctx: Context + ) => { + const { clients: { storefrontPermissions, session }, vtex: { logger, sessionToken, adminUserAuthToken }, - }: any - ) => { + } = ctx + const organizationFilters: string[] = [] let fromSession = false @@ -270,6 +276,49 @@ const Organizations = { } }, + getActiveOrganizationsByEmail: async ( + _: void, + { email }: { email: string }, + ctx: Context + ) => { + const { + vtex: { logger }, + } = ctx + + const organizations = await Organizations.getOrganizationsByEmail( + _, + { email }, + ctx + ) + + const organizationsWithStatus: GetOrganizationsByEmailWithStatus[] = + await Promise.all( + organizations.map(async (organization: { orgId: string }) => { + const status = await organizationStatus( + { orgId: organization.orgId }, + _, + ctx + ) + + return { ...organization, status } + }) + ) + + const activeOrganizations = organizationsWithStatus.filter( + (organization) => organization.status === 'active' + ) + + try { + return activeOrganizations + } catch (error) { + logger.error({ + error, + message: 'getActiveOrganizationsByEmail-error', + }) + throw new GraphQLError(getErrorMessage(error)) + } + }, + getOrganizationByIdStorefront: async ( _: void, { id }: { id: string }, diff --git a/node/typings.d.ts b/node/typings.d.ts index 29113e5..75cb588 100644 --- a/node/typings.d.ts +++ b/node/typings.d.ts @@ -167,6 +167,14 @@ interface Collection { id: string name: string } +interface GetOrganizationsByEmailWithStatus { + costId: string + orgId: string + roleId: string + id: string + clId: string + status: string +} interface CostCenter { id: string @@ -231,10 +239,16 @@ interface Price { id: string } +interface TopBarSetting { + name: string + hexColor: string +} + interface UISettings { showModal: boolean clearCart: boolean fullImpersonation: boolean + topBar?: TopBarSetting | null } interface CustomField { diff --git a/node/yarn.lock b/node/yarn.lock index afd8369..abebf46 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -836,10 +836,10 @@ dependencies: "@types/yargs-parser" "*" -"@vtex/api@6.47.0": - version "6.47.0" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.47.0.tgz#6910455d593d8bb76f1f4f2b7660023853fda35e" - integrity sha512-t9gt7Q89EMbSj3rLhho+49Fv+/lQgiy8EPVRgtmmXFp1J4v8hIAZF7GPjCPie111KVs4eG0gfZFpmhA5dafKNA== +"@vtex/api@6.48.0": + version "6.48.0" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.48.0.tgz#67f9f11d197d543d4f854b057d31a8d6999241e9" + integrity sha512-mAdT7gbV0/BwiuqUkNH1E7KZqTUczT5NbBBZcPJq5kmTr73PUjbR9wh//70ryJo2EAdHlqIgqgwsCVpozenlhg== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3"