Skip to content

Commit

Permalink
Merge branch 'main' into chatbot/question-length
Browse files Browse the repository at this point in the history
  • Loading branch information
batdevis committed Jan 14, 2025
2 parents c185f61 + 22d2f66 commit 56b7e0c
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-kangaroos-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": patch
---

Fix UrlReplaceMap codec, simplify populate and cache the result
5 changes: 5 additions & 0 deletions .changeset/witty-socks-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"infrastructure": patch
---

Enabled active campaign syncer on prod
2 changes: 1 addition & 1 deletion apps/infrastructure/src/env/prod/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ dns_domain_name_cms = {
}

create_chatbot = true
ac_integration_is_enabled = false
ac_integration_is_enabled = true
4 changes: 2 additions & 2 deletions apps/infrastructure/src/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,6 @@ module "active_campaign" {
environment = var.environment
tags = var.tags

cognito_user_pool = module.website.cognito_user_pool
webinar_subscriptions_ddb_stream_arn = module.website.webinar_subscriptions_ddb_stream_arn
cognito_user_pool = module.website.cognito_user_pool
webinar_subscriptions_ddb = module.website.webinar_subscriptions_ddb
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# EventBridge Pipe for DynamoDB Stream -> SQS FIFO
resource "aws_pipes_pipe" "dynamodb_to_sqs" {
name = "${local.prefix}-webinar-subscriptions-pipe"
source = var.webinar_subscriptions_ddb_stream_arn
source = var.webinar_subscriptions_ddb.stream_arn
target = aws_sqs_queue.fifo_queue.arn
role_arn = aws_iam_role.pipes_role.arn

Expand Down
13 changes: 12 additions & 1 deletion apps/infrastructure/src/modules/active_campaign/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "aws_iam_policy" "pipes" {
]
Effect = "Allow"
Resource = [
var.webinar_subscriptions_ddb_stream_arn
var.webinar_subscriptions_ddb.stream_arn
]
},
{
Expand Down Expand Up @@ -65,6 +65,17 @@ resource "aws_iam_policy" "lambda_policy" {
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = [
"dynamodb:BatchGetItem",
"dynamodb:GetItem",
"dynamodb:Query",
]
Effect = "Allow"
Resource = [
var.webinar_subscriptions_ddb.arn
]
},
{
Action = ["sqs:ReceiveMessage", "sqs:DeleteMessage", "sqs:GetQueueAttributes"],
Effect = "Allow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ module "lambda_resync" {
description = "Lambda function that resyncs Active Campaign failed events"

environment_variables = {
AC_API_KEY_PARAM = module.active_campaign_api_key.ssm_parameter_name
AC_BASE_URL_PARAM = module.active_campaign_base_url.ssm_parameter_name
COGNITO_USER_POOL_ID = var.cognito_user_pool.id
AC_API_KEY_PARAM = module.active_campaign_api_key.ssm_parameter_name
AC_BASE_URL_PARAM = module.active_campaign_base_url.ssm_parameter_name
COGNITO_USER_POOL_ID = var.cognito_user_pool.id
DYNAMO_WEBINARS_TABLE_NAME = var.webinar_subscriptions_ddb.name
}

runtime = "nodejs20.x"
Expand Down
9 changes: 6 additions & 3 deletions apps/infrastructure/src/modules/active_campaign/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ variable "cognito_user_pool" {
description = "The cognito user pool used to authenticate api calls"
}

variable "webinar_subscriptions_ddb_stream_arn" {
type = string
description = "The ARN of the webinar subscriptions ddb stream"
variable "webinar_subscriptions_ddb" {
type = object({
name = string
arn = string
stream_arn = string
})
}
1 change: 1 addition & 0 deletions apps/infrastructure/src/modules/chatbot/lambda_chatbot.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ locals {
CHB_GOOGLE_API_KEY = module.google_api_key_ssm_parameter.ssm_parameter_name
CHB_QUERY_TABLE_PREFIX = local.prefix
CHB_LLAMAINDEX_INDEX_ID = module.index_id_ssm_parameter.ssm_parameter_name
CHB_ENGINE_USE_ASYNC = "False"
}
}

Expand Down
8 changes: 6 additions & 2 deletions apps/infrastructure/src/modules/website/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ output "cognito_user_pool" {
sensitive = true
}

output "webinar_subscriptions_ddb_stream_arn" {
value = module.dynamodb_webinar_subscriptions.dynamodb_table_stream_arn
output "webinar_subscriptions_ddb" {
value = {
name = module.dynamodb_webinar_subscriptions.dynamodb_table_id
arn = module.dynamodb_webinar_subscriptions.dynamodb_table_arn
stream_arn = module.dynamodb_webinar_subscriptions.dynamodb_table_stream_arn
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@/helpers/metadata.helpers';
import GitBookTemplate from '@/components/templates/GitBookTemplate/GitBookTemplate';
import { productPageToBreadcrumbs } from '@/helpers/breadcrumbs.helpers';
import { getGuidesProps, getUrlReplaceMapProps } from '@/lib/cmsApi';
import { getGuidesProps, getCachedUrlReplaceMapProps } from '@/lib/cmsApi';
import { generateStructuredDataScripts } from '@/helpers/generateStructuredDataScripts.helpers';
import {
breadcrumbItemByProduct,
Expand Down Expand Up @@ -77,7 +77,7 @@ const Page = async ({ params }: { params: Params }) => {
params?.productSlug,
params?.productGuidePage ?? ['']
);
const urlReplaceMap = await getUrlReplaceMapProps();
const urlReplaceMap = await getCachedUrlReplaceMapProps();
const { product, page, guide, version, versions, source, bannerLinks, seo } =
guideProps;
const props: ProductGuidePageProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getSolutionDetail, getSolutionSubPaths } from '@/lib/api';
import GitBookTemplate from '@/components/templates/GitBookTemplate/GitBookTemplate';
import { pageToBreadcrumbs } from '@/helpers/breadcrumbs.helpers';
import { ParseContentConfig } from 'gitbook-docs/parseContent';
import { getSolutionsProps, getUrlReplaceMapProps } from '@/lib/cmsApi';
import { getSolutionsProps, getCachedUrlReplaceMapProps } from '@/lib/cmsApi';
import { SolutionTemplateProps } from '@/components/templates/SolutionTemplate/SolutionTemplate';
import { generateStructuredDataScripts } from '@/helpers/generateStructuredDataScripts.helpers';
import { getItemFromPaths } from '@/helpers/structuredData.helpers';
Expand Down Expand Up @@ -60,7 +60,7 @@ const Page = async ({ params }: { params: Params }) => {
params?.solutionSubPathSlugs
);

const urlReplaceMap = await getUrlReplaceMapProps();
const urlReplaceMap = await getCachedUrlReplaceMapProps();
if (!solutionProps) {
return null;
}
Expand Down
21 changes: 19 additions & 2 deletions apps/nextjs-website/src/lib/cmsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ import { makeOverviewsProps } from '@/lib/strapi/makeProps/makeOverviews';
import { fetchTutorialListPages } from './strapi/fetches/fetchTutorialListPages';
import { makeTutorialListPagesProps } from './strapi/makeProps/makeTutorialListPages';
import { fetchUrlReplaceMap } from './strapi/fetches/fetchUrlReplaceMap';
import build from 'next/dist/build';
import { makeUrlReplaceMap } from './strapi/makeProps/makeUrlReplaceMap';
import {
makeUrlReplaceMap,
UrlReplaceMap,
} from './strapi/makeProps/makeUrlReplaceMap';

// a BuildEnv instance ready to be used
const buildEnv = pipe(
Expand Down Expand Up @@ -152,6 +154,21 @@ export const getUrlReplaceMapProps = async () => {
return staticUrlReplaceMap;
};

// eslint-disable-next-line functional/no-let
let cachedUrlReplaceMapProps: UrlReplaceMap = {}; // We need to use any[] because of the type issue makeGuide derived type are not statically defined
// eslint-disable-next-line functional/no-let
let areUrlReplaceMapCached = false;

export const getCachedUrlReplaceMapProps = async () => {
if (!areUrlReplaceMapCached) {
// eslint-disable-next-line functional/no-expression-statements
cachedUrlReplaceMapProps = await getUrlReplaceMapProps();
// eslint-disable-next-line functional/no-expression-statements
areUrlReplaceMapCached = true;
}
return cachedUrlReplaceMapProps;
};

export const getApiDataListPagesProps = async () => {
const {
config: { FETCH_FROM_STRAPI: fetchFromStrapi },
Expand Down
16 changes: 14 additions & 2 deletions apps/nextjs-website/src/lib/strapi/codecs/UrlReplaceMapCodec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import * as t from 'io-ts/lib';
import { GuideCodec } from './GuidesCodec';
import { NullToUndefinedCodec } from './NullToUndefinedCodec';

const CustomGuideCodec = t.strict({
attributes: t.strict({
title: t.string,
slug: t.string,
product: t.strict({
data: t.strict({
attributes: t.strict({
slug: t.string,
}),
}),
}),
}),
});
const UrlToGuideCodec = t.strict({
id: t.number,
url: t.string,
subPath: t.union([NullToUndefinedCodec, t.string]),
guide: t.strict({
data: t.union([NullToUndefinedCodec, GuideCodec]),
data: t.union([NullToUndefinedCodec, CustomGuideCodec]),
}),
});

Expand Down
12 changes: 1 addition & 11 deletions apps/nextjs-website/src/lib/strapi/fetches/fetchUrlReplaceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ const makeStrapiUrlReplaceMapPopulate = () =>
urlToGuide: {
populate: {
guide: {
populate: [
'image',
'mobileImage',
'listItems',
'versions',
'bannerLinks.icon',
'seo',
'seo.metaSocial.image',
'product.logo',
'product.bannerLinks.icon',
],
populate: ['product'],
},
},
},
Expand Down

0 comments on commit 56b7e0c

Please sign in to comment.