Skip to content

Commit

Permalink
feat: working integration command for algolia
Browse files Browse the repository at this point in the history
  • Loading branch information
field123 committed Sep 25, 2023
1 parent d0dd491 commit 92a7d34
Show file tree
Hide file tree
Showing 32 changed files with 852 additions and 750 deletions.
1 change: 1 addition & 0 deletions packages/composable-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@types/yargs": "^17.0.24",
"algoliasearch": "^4.20.0",
"ansi-colors": "4.1.3",
"boxen": "5",
"conf": "10.2.0",
"ink": "3",
"ink-big-text": "1",
Expand Down
37 changes: 32 additions & 5 deletions packages/composable-cli/src/commands/generate/d2c/d2c-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
CommandResult,
} from "../../../types/command"
import { handleErrors } from "../../../util/error-handler"
import { resolveHostFromRegion } from "../../../util/resolve-region"
import { getRegion, resolveHostFromRegion } from "../../../util/resolve-region"
import { getToken } from "../../../lib/authentication/get-token"
import { createApplicationKeys } from "../../../util/create-client-secret"
import { renderInk } from "../../../lib/ink/render-ink"
Expand Down Expand Up @@ -332,7 +332,22 @@ export function createD2CCommandHandler(
const creds = store.get("credentials") as Record<string, any> | undefined

if (creds) {
const apiUrl = resolveHostFromRegion(store.get("region") as any)
const regionResult = getRegion(store)

if (!regionResult.success) {
return {
success: false,
error: {
code: "api-url-not-found",
message: regionResult.error.message,
},
}
}

const { data: region } = regionResult

const apiUrl = resolveHostFromRegion(region)

const tokenResult = await getToken(apiUrl, store)

if (tokenResult.success) {
Expand Down Expand Up @@ -376,16 +391,28 @@ export function createD2CCommandHandler(
}
}

const { data } = await createApplicationKeys(
const createResult = await createApplicationKeys(
apiUrl,
token,
`${resolvedName}-${new Date().toISOString()}`
)

if (!createResult.success) {
return {
success: false,
error: {
code: "application-keys-creation-failed",
message: createResult.error.message,
},
}
}

const { client_id, client_secret } = createResult.data

gatheredOptions = {
...gatheredOptions,
epccClientId: data.client_id,
epccClientSecret: data.client_secret,
epccClientId: client_id,
epccClientSecret: client_secret,
name: resolvedName,
}
}
Expand Down
Loading

0 comments on commit 92a7d34

Please sign in to comment.