diff --git a/CHANGELOG.md b/CHANGELOG.md index deed63dc..0d5c74f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- `Trade Name` to be searchable (Admin) +- `Trade Name` to the Organization listing page (Admin) +- `Trade Name` to the Organization Requests listing page (Admin) +- Event listener to update schemas once new app version is released + ## [0.49.6] - 2024-06-03 ### Fixed @@ -66,11 +73,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [0.48.2] - 2024-02-21 ### Fixed + - Add analytics client to properly send metrics to redshift ## [0.48.1] - 2024-02-07 ### Fixed + - Add retries to `sendMetric` to avoid connection errors ## [0.48.0] - 2024-01-19 @@ -78,6 +87,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Allow `paymentTerms`, `collections` and `sellers` to be provided by name only on `createOrganizationAndCostCenterWithAdminUser` + ## [0.47.1] - 2023-12-18 ### Fixed @@ -164,7 +174,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [0.37.0] - 2023-09-19 - ### Added - Added event trigger on delete a user @@ -180,7 +189,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Added metrics for impersonate user -- +- + ## [0.35.3] - 2023-08-09 ### Fixed @@ -199,7 +209,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix auth problem when fetching orders history - ## [0.35.0] - 2023-07-24 ### Added diff --git a/manifest.json b/manifest.json index cdc43eda..2cd4027b 100644 --- a/manifest.json +++ b/manifest.json @@ -20,6 +20,9 @@ { "name": "colossus-fire-event" }, + { + "name": "colossus-listen-event" + }, { "name": "update-app-settings" }, diff --git a/node/events/appAllEvents.ts b/node/events/appAllEvents.ts new file mode 100644 index 00000000..6060fe3b --- /dev/null +++ b/node/events/appAllEvents.ts @@ -0,0 +1,15 @@ +import type { EventContext } from '@vtex/api' + +import type { Clients } from '../clients' + +export async function appAllEvents(ctx: EventContext) { + const { + vtex: { logger }, + body, + } = ctx + + logger.debug({ + message: '[B2B Organizations GraphQL] Received appEvent', + body, + }) +} diff --git a/node/events/appDependenciesUpdatedEvent.ts b/node/events/appDependenciesUpdatedEvent.ts new file mode 100644 index 00000000..fdeba588 --- /dev/null +++ b/node/events/appDependenciesUpdatedEvent.ts @@ -0,0 +1,23 @@ +import type { EventContext } from '@vtex/api' + +import type { Clients } from '../clients' +import checkConfig from '../resolvers/config' + +export async function appDependenciesUpdatedEvent(ctx: EventContext) { + const { + vtex: { logger, workspace }, + body, + } = ctx + + logger.debug({ + message: '[B2B Organizations GraphQL] Received appDependenciesUpdatedEvent', + body, + }) + + // As a first iteration, we'll only send the workspace installed apps from master. + if (workspace !== 'master') { + return + } + + checkConfig(ctx) +} diff --git a/node/events/kubeRouterAuditEvent.ts b/node/events/kubeRouterAuditEvent.ts new file mode 100644 index 00000000..1471fc7f --- /dev/null +++ b/node/events/kubeRouterAuditEvent.ts @@ -0,0 +1,22 @@ +import type { EventContext } from '@vtex/api' + +import type { Clients } from '../clients' +import checkConfig from '../resolvers/config' + +export async function kubeRouterAuditEvent(ctx: EventContext) { + const { + vtex: { logger }, + body: { operation }, + } = ctx + + logger.debug({ + message: '[B2B Organizations GraphQL] Received kubeRouterAuditEvent', + body: ctx.body, + }) + + // As first iteration, we'll only send the workspace installed apps from master. + if (operation === 'promote') { + // Update schemas. + checkConfig(ctx) + } +} diff --git a/node/index.ts b/node/index.ts index 57d41a48..6df11ce8 100644 --- a/node/index.ts +++ b/node/index.ts @@ -9,6 +9,9 @@ import { LRUCache, Service } from '@vtex/api' import { Clients } from './clients' import { resolvers } from './resolvers' import { schemaDirectives } from './resolvers/directives' +import { appDependenciesUpdatedEvent } from './events/appDependenciesUpdatedEvent' +import { kubeRouterAuditEvent } from './events/kubeRouterAuditEvent' +import { appAllEvents } from './events/appAllEvents' const TIMEOUT_MS = 4000 @@ -51,4 +54,9 @@ export default new Service({ schemaDirectives, }, routes: resolvers.Routes, + events: { + appDependenciesUpdatedEvent, + kubeRouterAuditEvent, + appAllEvents, + }, }) diff --git a/node/mdSchema.ts b/node/mdSchema.ts index 74ab8b37..66d3ae67 100644 --- a/node/mdSchema.ts +++ b/node/mdSchema.ts @@ -15,7 +15,7 @@ export const ORGANIZATION_REQUEST_FIELDS = [ 'sellers', 'customFields', ] -export const ORGANIZATION_REQUEST_SCHEMA_VERSION = 'v0.1.1' +export const ORGANIZATION_REQUEST_SCHEMA_VERSION = 'v0.1.2' export const ORGANIZATION_DATA_ENTITY = 'organizations' export const ORGANIZATION_FIELDS = [ @@ -32,7 +32,7 @@ export const ORGANIZATION_FIELDS = [ 'created', 'customFields', ] -export const ORGANIZATION_SCHEMA_VERSION = 'v0.0.8' +export const ORGANIZATION_SCHEMA_VERSION = 'v0.0.9' export const COST_CENTER_DATA_ENTITY = 'cost_centers' export const COST_CENTER_FIELDS = [ @@ -111,7 +111,14 @@ export const schemas = [ title: 'Custom Fields', }, }, - 'v-indexed': ['name', 'b2bCustomerAdmin', 'status', 'created'], + 'v-indexed': [ + 'id', + 'name', + 'tradeName', + 'b2bCustomerAdmin', + 'status', + 'created', + ], 'v-immediate-indexing': true, 'v-cache': false, }, @@ -167,7 +174,7 @@ export const schemas = [ title: 'Custom Fields', }, }, - 'v-indexed': ['name', 'status', 'created'], + 'v-indexed': ['id', 'name', 'tradeName', 'status', 'created'], 'v-immediate-indexing': true, 'v-cache': false, }, diff --git a/node/resolvers/Queries/Organizations.ts b/node/resolvers/Queries/Organizations.ts index a7849cf2..329e6928 100644 --- a/node/resolvers/Queries/Organizations.ts +++ b/node/resolvers/Queries/Organizations.ts @@ -15,7 +15,7 @@ const getWhereByStatus = ({ status }: { status: string[] }) => { if (status?.length) { const statusArray = [] as string[] - status.forEach((stat) => { + status.forEach((stat: string) => { statusArray.push(`status=${stat}`) }) const statuses = `(${statusArray.join(' OR ')})` @@ -132,7 +132,9 @@ const Organizations = { const whereArray = getWhereByStatus({ status }) if (search) { - whereArray.push(`name="*${search}*"`) + whereArray.push( + `(name="*${search}*" OR tradeName="*${search}*" OR id="*${search}*")` + ) } const where = whereArray.join(' AND ') @@ -356,7 +358,9 @@ const Organizations = { if (search.match(/[a-z\d]+@[a-z]+\.[a-z]{2,3}/gm)) { whereArray.push(`b2bCustomerAdmin.email=${search}`) } else { - whereArray.push(`name="*${search}*"`) + whereArray.push( + `(name="*${search}*" OR tradeName="*${search}*" OR id="*${search}*")` + ) } } diff --git a/node/resolvers/config.ts b/node/resolvers/config.ts index 671a48dc..f142a9e2 100644 --- a/node/resolvers/config.ts +++ b/node/resolvers/config.ts @@ -1,3 +1,6 @@ +import type { EventContext } from '@vtex/api' + +import type { Clients } from '../clients' import { schemas } from '../mdSchema' import templates from '../templates' import { toHash } from '../utils' @@ -19,7 +22,7 @@ export const getAppId = (): string => { return appName } -const checkConfig = async (ctx: Context) => { +const checkConfig = async (ctx: Context | EventContext) => { const { vtex: { logger }, clients: { mail, masterdata, vbase }, @@ -44,7 +47,7 @@ const checkConfig = async (ctx: Context) => { message: 'checkConfig-updatingSchema', }) - schemas.forEach((schema) => { + schemas.forEach((schema: any) => { updates.push( masterdata .createOrUpdateSchema({ @@ -68,8 +71,8 @@ const checkConfig = async (ctx: Context) => { ) }) try { - await Promise.all(updates).then((results) => { - if (results.every((res) => res === true)) { + await Promise.all(updates).then((results: any) => { + if (results.every((res: any) => res === true)) { settings.schemaHash = currSchemaHash schemaChanged = true } @@ -91,7 +94,7 @@ const checkConfig = async (ctx: Context) => { try { await Promise.all( - templates.map(async (template) => { + templates.map(async (template: any) => { const existingData = await mail.getTemplate(template.Name) if (!existingData) { @@ -113,7 +116,7 @@ const checkConfig = async (ctx: Context) => { settings.templateHash = currTemplateHash templatesChanged = true }) - .catch((error) => { + .catch((error: any) => { logger.error({ error, message: 'checkConfig-publishTemplateError', diff --git a/node/service.json b/node/service.json index 588596f0..ed11d064 100644 --- a/node/service.json +++ b/node/service.json @@ -40,5 +40,26 @@ } ] } + }, + "events": { + "appDependenciesUpdatedEvent": { + "sender": "apps", + "topics": ["depsUpdated"] + }, + "appAllEvents": { + "sender": "apps", + "topics": [ + "linked", + "settings", + "depsUpdated", + "appVersionsUpdated", + "deprecated", + "undeprecated" + ] + }, + "kubeRouterAuditEvent": { + "sender": "kube-router", + "topics": ["audit"] + } } } diff --git a/node/yarn.lock b/node/yarn.lock index a9d31e0d..de2c18bf 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -3475,7 +3475,7 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" -"stats-lite@github:vtex/node-stats-lite#dist": +stats-lite@vtex/node-stats-lite#dist: version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: