From 83eeb189abe60767da76c2fd35d72749f2e0caa0 Mon Sep 17 00:00:00 2001 From: Robert Field Date: Tue, 14 Nov 2023 13:58:56 +0000 Subject: [PATCH 1/2] fix: algolia index name resolving --- .../algolia/algolia-integration-command.tsx | 8 ++++--- .../utility/resolve-index-name.test.ts | 21 +++++++++++++++++++ .../algolia/utility/resolve-index-name.ts | 14 +++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.test.ts create mode 100644 packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.ts diff --git a/packages/composable-cli/src/commands/integration/algolia/algolia-integration-command.tsx b/packages/composable-cli/src/commands/integration/algolia/algolia-integration-command.tsx index 61b5b48e..397d724a 100644 --- a/packages/composable-cli/src/commands/integration/algolia/algolia-integration-command.tsx +++ b/packages/composable-cli/src/commands/integration/algolia/algolia-integration-command.tsx @@ -50,6 +50,7 @@ import { } from "./utility/algolia/algolia" import { logging } from "@angular-devkit/core" import { attemptToAddEnvVariables } from "../../../lib/devkit/add-env-variables" +import { resolveIndexName } from "./utility/resolve-index-name" export function createAlgoliaIntegrationCommand( ctx: CommandContext, @@ -291,9 +292,10 @@ export function createAlgoliaIntegrationCommandHandler( spinner.succeed(`Published ${catalog.attributes.name} catalog!`) - const algoliaIndexName = `${catalog.attributes.name.replace(" ", "_")}_${ - catalog.id.split("-")[0] - }` + const algoliaIndexName = resolveIndexName( + catalog.attributes.name, + catalog.id, + ) const envVarResult = await attemptToAddEnvVariables(ctx, spinner, { NEXT_PUBLIC_ALGOLIA_INDEX_NAME: algoliaIndexName, diff --git a/packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.test.ts b/packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.test.ts new file mode 100644 index 00000000..3a257a70 --- /dev/null +++ b/packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.test.ts @@ -0,0 +1,21 @@ +import { resolveIndexName } from "./resolve-index-name" + +describe("resolveIndexName", () => { + it("should resolve index name with escaped catalog name and first block of catalogId", () => { + const catalogName = "Flora standard catalog" + const catalogId = "7b479b7c-05b7-4a25-ae3a-dae4787b0811" + + const result = resolveIndexName(catalogName, catalogId) + + expect(result).toBe("Flora_standard_catalog_7b479b7c") + }) + + it("should handle catalog names with leading/trailing spaces", () => { + const catalogName = " Flora catalog with spaces " + const catalogId = "7b479b7c-05b7-4a25-ae3a-dae4787b0811" + + const result = resolveIndexName(catalogName, catalogId) + + expect(result).toBe("Flora_catalog_with_spaces_7b479b7c") + }) +}) diff --git a/packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.ts b/packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.ts new file mode 100644 index 00000000..e1f85d9b --- /dev/null +++ b/packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.ts @@ -0,0 +1,14 @@ +export function resolveIndexName( + catalogName: string, + catalogId: string, +): string { + const escapedName = escapeCatalogName(catalogName) + const resolvedId = catalogId.split("-")[0] + + return `${escapedName}_${resolvedId}` +} + +function escapeCatalogName(catalogName: string): string { + // Replace leading and trailing spaces and then replace spaces with underscores + return catalogName.trim().replace(/\s/g, "_") +} From 51421f8359fbc19b935cd3e8fea264ba255c62aa Mon Sep 17 00:00:00 2001 From: Robert Field Date: Tue, 14 Nov 2023 13:59:31 +0000 Subject: [PATCH 2/2] chore: changeset --- .changeset/rotten-chicken-jog.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rotten-chicken-jog.md diff --git a/.changeset/rotten-chicken-jog.md b/.changeset/rotten-chicken-jog.md new file mode 100644 index 00000000..2e6e5264 --- /dev/null +++ b/.changeset/rotten-chicken-jog.md @@ -0,0 +1,5 @@ +--- +"composable-cli": patch +--- + +algolia index name resolving fixed