diff --git a/CHANGELOG.md b/CHANGELOG.md index abbb60a..ada10a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Use listUsersPaginated internally instead of deprecated listUsers + ## [2.5.3] - 2024-06-10 ### Fixed diff --git a/node/clients/index.ts b/node/clients/index.ts index a064bf1..bb61fd4 100644 --- a/node/clients/index.ts +++ b/node/clients/index.ts @@ -13,8 +13,10 @@ import StorefrontPermissions from './storefrontPermissions' import VtexId from './vtexId' export const getTokenToHeader = (ctx: IOContext) => { - const adminToken = ctx.adminUserAuthToken ?? ctx.authToken - const userToken = ctx.storeUserAuthToken + // provide authToken (app token) as an admin token as this is a call + // between b2b suite apps and no further token validation is needed + const adminToken = ctx.authToken + const userToken = ctx.storeUserAuthToken ?? null const { sessionToken, account } = ctx let allCookies = `VtexIdclientAutCookie=${adminToken}` diff --git a/node/clients/storefrontPermissions.ts b/node/clients/storefrontPermissions.ts index 8ac9398..133d844 100644 --- a/node/clients/storefrontPermissions.ts +++ b/node/clients/storefrontPermissions.ts @@ -41,17 +41,11 @@ export const QUERIES = { slug } }`, - listUsers: `query users($organizationId: ID, $costCenterId: ID, $roleId: ID) { - listUsers(organizationId: $organizationId, costCenterId: $costCenterId, roleId: $roleId) { - id - roleId - userId - clId - orgId - costId - name - email - canImpersonate + getOrgSalesAdminEmail: `query users($organizationId: ID, $roleId: ID) { + listUsersPaginated(organizationId: $organizationId, roleId: $roleId) { + data { + email + } } }`, } @@ -77,7 +71,7 @@ export default class StorefrontPermissions extends AppGraphQLClient { }) } - public listUsers = async ({ + public getOrgSalesAdminEmail = async ({ roleId, organizationId, }: { @@ -86,7 +80,7 @@ export default class StorefrontPermissions extends AppGraphQLClient { }): Promise => { return this.query({ extensions: this.getPersistedQuery(), - query: QUERIES.listUsers, + query: QUERIES.getOrgSalesAdminEmail, variables: { roleId, ...(organizationId && { organizationId }), diff --git a/node/package.json b/node/package.json index a7050c7..727fbcb 100644 --- a/node/package.json +++ b/node/package.json @@ -9,7 +9,7 @@ "ramda": "^0.25.0", "atob": "^2.1.2", "axios": "0.27.2", - "@vtex/api": "6.46.0" + "@vtex/api": "6.47.0" }, "devDependencies": { "@types/atob": "^2.1.2", diff --git a/node/utils/message.ts b/node/utils/message.ts index e3a2f15..4b51129 100644 --- a/node/utils/message.ts +++ b/node/utils/message.ts @@ -9,29 +9,32 @@ interface QuoteUpdate { note: string } -const getUsers = async ( +// As this is currently used only to get the sales-admin users to +// send an email notification when a quote is created, we only get +// the first page of users (25) and return them. +const getOrgSalesAdminEmail = async ( storefrontPermissions: StorefrontPermissions, - roleSlug: string, organizationId?: string ) => { const { data: { listRoles }, }: any = await storefrontPermissions.listRoles() - const role = listRoles.find((r: any) => r.slug === roleSlug) + const role = listRoles.find((r: any) => r.slug === 'sales-admin') if (!role) { return [] } const { - data: { listUsers }, - }: any = await storefrontPermissions.listUsers({ + data: { getOrgSalesAdminEmailResult }, + }: any = await storefrontPermissions.getOrgSalesAdminEmail({ roleId: role.id, ...(organizationId && { organizationId }), }) - return listUsers + // we only return the first page of sales-admin users (25) + return getOrgSalesAdminEmailResult.data } const getOrgAndCostCenterNames = async ( @@ -159,13 +162,13 @@ const message = (ctx: Context | EventBroadcastContext) => { let users = [] try { - users = (await getUsers(storefrontPermissions, 'sales-admin')).map( - (user: any) => user.email - ) + users = ( + await getOrgSalesAdminEmail(storefrontPermissions, organization) + ).map((user: any) => user.email) } catch (error) { logger.error({ error, - message: 'quoteCreatedMessage-getUsersError', + message: 'quoteCreatedMessage-getOrgSalesAdminEmailError', }) } diff --git a/node/yarn.lock b/node/yarn.lock index 4b91953..4ce9b82 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -178,10 +178,10 @@ "@types/mime" "^1" "@types/node" "*" -"@vtex/api@6.46.0": - version "6.46.0" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.46.0.tgz#208d14b96cbc8fd5eb6bd18fbd0c8424886e6154" - integrity sha512-XAvJlD1FG1GynhPXiMcayunahFCL2r3ilO5MHAWKxYvB/ljyxi4+U+rVpweeaQGpxHfhKHdfPe7qNEEh2oa2lw== +"@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== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -1522,7 +1522,7 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= -stats-lite@vtex/node-stats-lite#dist: +"stats-lite@github:vtex/node-stats-lite#dist": version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: