@algolia/wizard 0.59.0 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/main.js +87 -73
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -1198,17 +1198,24 @@ function PromptInput() {
1198
1198
  }
1199
1199
  if (inputReq.promptType === "acceptReject") {
1200
1200
  const labels = inputReq.options?.length ? inputReq.options : ACCEPT_REJECT_OPTIONS;
1201
- return /* @__PURE__ */ jsx8(Box9, { flexGrow: 1, children: /* @__PURE__ */ jsx8(
1202
- SelectPrompt,
1203
- {
1204
- question: inputReq.prompt,
1205
- messages: inputReq.messages,
1206
- options: labels,
1207
- secondary: inputReq.secondary,
1208
- onSelect: (value) => handleSubmit(value === labels[0])
1209
- },
1210
- promptKey
1211
- ) });
1201
+ return /* @__PURE__ */ jsxs9(Box9, { flexGrow: 1, flexDirection: "column", gap: 1, children: [
1202
+ inputReq.detectedLanguages && /* @__PURE__ */ jsxs9(Text10, { color: COLORS.muted, children: [
1203
+ "Languages:",
1204
+ " ",
1205
+ /* @__PURE__ */ jsx8(Text10, { color: COLORS.success, children: inputReq.detectedLanguages })
1206
+ ] }),
1207
+ /* @__PURE__ */ jsx8(
1208
+ SelectPrompt,
1209
+ {
1210
+ question: inputReq.prompt,
1211
+ messages: inputReq.messages,
1212
+ options: labels,
1213
+ secondary: inputReq.secondary,
1214
+ onSelect: (value) => handleSubmit(value === labels[0])
1215
+ },
1216
+ promptKey
1217
+ )
1218
+ ] });
1212
1219
  }
1213
1220
  return /* @__PURE__ */ jsxs9(Box9, { flexDirection: "column", children: [
1214
1221
  inputReq.error && /* @__PURE__ */ jsx8(Text10, { color: COLORS.danger, children: inputReq.error }),
@@ -3898,7 +3905,7 @@ async function runAnalysis(mode, extraInstructions = []) {
3898
3905
  // package.json
3899
3906
  var package_default = {
3900
3907
  name: "@algolia/wizard",
3901
- version: "0.59.0",
3908
+ version: "0.61.0",
3902
3909
  description: "Magically implement Algolia functionality in your codebase",
3903
3910
  type: "module",
3904
3911
  engines: {
@@ -4028,7 +4035,7 @@ async function confirmLanguage(ctx) {
4028
4035
  prompt: "Did we detect your language(s) correctly?",
4029
4036
  promptType: "acceptReject",
4030
4037
  options: ["Yes", "No"],
4031
- messages: [`Languages: ${summarize(detected.languages)}`]
4038
+ detectedLanguages: summarize(detected.languages)
4032
4039
  });
4033
4040
  const languages = answer === true ? detected.languages : await askList(ctx, "List the languages your project uses:", {
4034
4041
  required: true
@@ -4516,6 +4523,13 @@ var verificationOutputSchema = z28.object({
4516
4523
  var MAX_IMPLEMENT_VERIFICATION_ATTEMPTS = 3;
4517
4524
  var DEFAULT_IMPLEMENT_USE_CASES = ["ingestion", "search"];
4518
4525
  var INGEST_DIR = ".algolia-wizard";
4526
+ var INGESTION_SOURCE_PROMPT = "What data do you want to index?";
4527
+ var INGESTION_SOURCE = {
4528
+ local: "Use existing project data",
4529
+ fileUpload: "Import a data file (CSV, JSON, TSV)",
4530
+ generated: "Generate sample data"
4531
+ };
4532
+ var FILE_UPLOAD_PATH_PROMPT = "Enter the path to your JSON, CSV, or TSV file (relative to the project root, or absolute):";
4519
4533
  var JS_LANGUAGES = ["javascript", "typescript", "jsx", "tsx", "node"];
4520
4534
  function lower(entries) {
4521
4535
  return entries.map((entry) => entry.name.toLowerCase());
@@ -4751,6 +4765,59 @@ function verificationRetryInstructions(verification) {
4751
4765
  `Implementation insufficient. Address these findings before reporting completion: ${verification.additionalInstructions ?? verification.summary}`
4752
4766
  ];
4753
4767
  }
4768
+ async function resolveIngestionSource(ctx, repoRoot) {
4769
+ let error = void 0;
4770
+ for (; ; ) {
4771
+ const selection = await ctx.requestUserInput({
4772
+ prompt: INGESTION_SOURCE_PROMPT,
4773
+ promptType: "multipleChoice",
4774
+ options: [
4775
+ INGESTION_SOURCE.local,
4776
+ INGESTION_SOURCE.fileUpload,
4777
+ INGESTION_SOURCE.generated
4778
+ ],
4779
+ messages: [],
4780
+ cancelable: true,
4781
+ error
4782
+ });
4783
+ error = void 0;
4784
+ if (selection === "cancel") {
4785
+ throw new Error(
4786
+ "User cancelled ingestion source selection. Wizard halted."
4787
+ );
4788
+ }
4789
+ if (selection === INGESTION_SOURCE.local) {
4790
+ return { ingestionSource: "local" };
4791
+ }
4792
+ if (selection === INGESTION_SOURCE.generated) {
4793
+ return { ingestionSource: "generated" };
4794
+ }
4795
+ if (selection !== INGESTION_SOURCE.fileUpload) {
4796
+ throw new Error("Unexpected ingestion source selection");
4797
+ }
4798
+ const answer = await ctx.requestUserInput({
4799
+ prompt: FILE_UPLOAD_PATH_PROMPT,
4800
+ promptType: "textInput",
4801
+ options: [],
4802
+ messages: []
4803
+ });
4804
+ const uploadSourcePath = typeof answer === "string" ? answer : "";
4805
+ await mkdir5(join10(repoRoot, INGEST_DIR), { recursive: true });
4806
+ const copied = await copyUploadIntoProject(
4807
+ repoRoot,
4808
+ INGEST_DIR,
4809
+ uploadSourcePath
4810
+ );
4811
+ if (copied.ok) {
4812
+ return { ingestionSource: "fileUpload", uploadFilePath: copied.relPath };
4813
+ }
4814
+ error = `Could not use the uploaded file (${copied.reason}).`;
4815
+ logger.warn(
4816
+ { reason: copied.reason },
4817
+ "implement: file upload unavailable"
4818
+ );
4819
+ }
4820
+ }
4754
4821
  async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES) {
4755
4822
  const repoRoot = process.cwd();
4756
4823
  const scan = ctx.getStepOutput("project-scan");
@@ -4773,50 +4840,17 @@ async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES) {
4773
4840
  if (!selected?.selection) {
4774
4841
  throw new Error(`No index was selected`);
4775
4842
  }
4843
+ await assertGitRepoWithHead(repoRoot);
4776
4844
  let ingestionSource = "generated";
4777
- const ingestionSourceQuestions = [
4778
- {
4779
- question: "Do you have local access to the data you want to ingest in Algolia?",
4780
- source: "local"
4781
- },
4782
- {
4783
- question: "Do you have a JSON, CSV or TSV you would like to upload?",
4784
- source: "fileUpload"
4785
- },
4786
- {
4787
- question: "Do you want me to generate sample records based on your entity schema?",
4788
- source: "generated"
4789
- }
4790
- ];
4791
- let uploadSourcePath;
4845
+ let uploadFilePath = void 0;
4792
4846
  if (useCases.includes("ingestion")) {
4793
- for (const sq of ingestionSourceQuestions) {
4794
- const result = Boolean(
4795
- await ctx.requestUserInput({
4796
- prompt: sq.question,
4797
- promptType: "acceptReject",
4798
- options: ["Yes", "No"],
4799
- messages: []
4800
- })
4801
- );
4802
- if (result) {
4803
- ingestionSource = sq.source;
4804
- break;
4805
- }
4806
- }
4807
- if (ingestionSource === "fileUpload") {
4808
- const answer = await ctx.requestUserInput({
4809
- prompt: "Enter the path to your JSON, CSV, or TSV file (relative to the project root, or absolute):",
4810
- promptType: "textInput",
4811
- options: [],
4812
- messages: []
4813
- });
4814
- uploadSourcePath = typeof answer === "string" ? answer : "";
4815
- }
4847
+ ({ ingestionSource, uploadFilePath } = await resolveIngestionSource(
4848
+ ctx,
4849
+ repoRoot
4850
+ ));
4816
4851
  }
4817
4852
  const targetIndex = selected?.selection;
4818
4853
  useWizard.getState().setTargetIndex(targetIndex ?? null);
4819
- await assertGitRepoWithHead(repoRoot);
4820
4854
  if (useCases.includes("ingestion")) {
4821
4855
  await mkdir5(join10(repoRoot, INGEST_DIR), { recursive: true });
4822
4856
  }
@@ -4835,27 +4869,7 @@ async function implement(ctx, useCases = DEFAULT_IMPLEMENT_USE_CASES) {
4835
4869
  if (useCases.includes("ingestion") && ingestAppId) {
4836
4870
  ingestWriteKey = (await resolveWriteKey(targetIndex, ingestAppId)).key;
4837
4871
  }
4838
- let uploadFilePath;
4839
- let uploadWarning;
4840
- if (ingestionSource === "fileUpload") {
4841
- const copied = await copyUploadIntoProject(
4842
- repoRoot,
4843
- INGEST_DIR,
4844
- uploadSourcePath ?? ""
4845
- );
4846
- if (copied.ok) {
4847
- uploadFilePath = copied.relPath;
4848
- } else {
4849
- ingestionSource = "generated";
4850
- uploadWarning = `\u26A0\uFE0F Could not use the uploaded file (${copied.reason}); generating sample records instead.`;
4851
- logger.warn(
4852
- { reason: copied.reason },
4853
- "implement: file upload unavailable; falling back to generated sample records"
4854
- );
4855
- }
4856
- }
4857
4872
  const summaries = [];
4858
- if (uploadWarning) summaries.push(uploadWarning);
4859
4873
  let searchKey;
4860
4874
  let searchKeyError;
4861
4875
  if (useCases.includes("search") && appId) {
@@ -6730,7 +6744,7 @@ function delay(ms) {
6730
6744
  // package.json with { type: 'json' }
6731
6745
  var package_default2 = {
6732
6746
  name: "@algolia/wizard",
6733
- version: "0.59.0",
6747
+ version: "0.61.0",
6734
6748
  description: "Magically implement Algolia functionality in your codebase",
6735
6749
  type: "module",
6736
6750
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.59.0",
3
+ "version": "0.61.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {