@algolia/wizard 0.74.0 → 0.75.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.
- package/dist/main.js +182 -4
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2260,7 +2260,7 @@ async function ensureApplication(resumeAppId) {
|
|
|
2260
2260
|
// package.json
|
|
2261
2261
|
var package_default = {
|
|
2262
2262
|
name: "@algolia/wizard",
|
|
2263
|
-
version: "0.
|
|
2263
|
+
version: "0.75.0",
|
|
2264
2264
|
description: "Magically implement Algolia functionality in your codebase",
|
|
2265
2265
|
type: "module",
|
|
2266
2266
|
engines: {
|
|
@@ -6435,6 +6435,14 @@ async function getPlaybooks() {
|
|
|
6435
6435
|
);
|
|
6436
6436
|
return data;
|
|
6437
6437
|
}
|
|
6438
|
+
async function createSampleIndex(appId, playbookSlug) {
|
|
6439
|
+
const { data } = await dashboardRequest(
|
|
6440
|
+
`/api/1/playbook-integrations/applications/${appId}/playbooks/${playbookSlug}/sample_index`,
|
|
6441
|
+
playbookExecutionSchema,
|
|
6442
|
+
{ method: "POST" }
|
|
6443
|
+
);
|
|
6444
|
+
return data;
|
|
6445
|
+
}
|
|
6438
6446
|
|
|
6439
6447
|
// src/actions/playbookSteps/selectPlaybook.ts
|
|
6440
6448
|
var selectPlaybookSchema = z32.object({
|
|
@@ -6499,6 +6507,153 @@ async function confirmPlaybookStep(ctx) {
|
|
|
6499
6507
|
}
|
|
6500
6508
|
}
|
|
6501
6509
|
|
|
6510
|
+
// src/actions/playbookSteps/selectIndex.ts
|
|
6511
|
+
import { z as z34 } from "zod";
|
|
6512
|
+
var selectIndexSchema = z34.object({
|
|
6513
|
+
indexName: z34.string(),
|
|
6514
|
+
sampleIndex: z34.boolean()
|
|
6515
|
+
});
|
|
6516
|
+
var CREATE_SAMPLE_INDEX = "Create a sample index";
|
|
6517
|
+
var GO_BACK_OPTION2 = "Go back to playbook selection";
|
|
6518
|
+
var SELECT_APP_OPTION2 = "Select app";
|
|
6519
|
+
var MIN_ENTRIES_FOR_SELECTION = 1;
|
|
6520
|
+
function formatIndexOption(index) {
|
|
6521
|
+
if (index.entries < MIN_ENTRIES_FOR_SELECTION) {
|
|
6522
|
+
return `${index.name} (empty index)`;
|
|
6523
|
+
}
|
|
6524
|
+
return `${index.name} (${index.entries.toLocaleString()} records)`;
|
|
6525
|
+
}
|
|
6526
|
+
function isIndexSelectable(index) {
|
|
6527
|
+
return index.entries >= MIN_ENTRIES_FOR_SELECTION;
|
|
6528
|
+
}
|
|
6529
|
+
async function selectIndexStep2(ctx) {
|
|
6530
|
+
let indices = ctx.getUserInput("fetchedIndices");
|
|
6531
|
+
!indices && ctx.notify({
|
|
6532
|
+
messages: ["Fetching indices from your Algolia application\u2026"]
|
|
6533
|
+
});
|
|
6534
|
+
const app = await requireApplication();
|
|
6535
|
+
if (!indices) {
|
|
6536
|
+
indices = await listIndices();
|
|
6537
|
+
ctx.setUserInput("fetchedIndices", indices);
|
|
6538
|
+
}
|
|
6539
|
+
const hasIndices = indices.length > 0;
|
|
6540
|
+
const indexOptions = hasIndices ? indices.map(formatIndexOption) : [];
|
|
6541
|
+
const options = [
|
|
6542
|
+
...indexOptions,
|
|
6543
|
+
CREATE_SAMPLE_INDEX,
|
|
6544
|
+
GO_BACK_OPTION2,
|
|
6545
|
+
SELECT_APP_OPTION2
|
|
6546
|
+
];
|
|
6547
|
+
const disabled = hasIndices ? [
|
|
6548
|
+
...indices.map((idx) => !isIndexSelectable(idx)),
|
|
6549
|
+
false,
|
|
6550
|
+
// CREATE_SAMPLE_INDEX is selectable
|
|
6551
|
+
false,
|
|
6552
|
+
// GO_BACK_OPTION is selectable
|
|
6553
|
+
false
|
|
6554
|
+
// SELECT_APP_OPTION is selectable
|
|
6555
|
+
] : void 0;
|
|
6556
|
+
const prompt = hasIndices ? "Select an index:" : `${app.name} doesn't have any indices yet. Start from a sample data set
|
|
6557
|
+
you can explore or switch to another application`;
|
|
6558
|
+
let error;
|
|
6559
|
+
let result;
|
|
6560
|
+
while (result === void 0) {
|
|
6561
|
+
const selection = await ctx.requestUserInput({
|
|
6562
|
+
prompt,
|
|
6563
|
+
promptType: "multipleChoice",
|
|
6564
|
+
options,
|
|
6565
|
+
error,
|
|
6566
|
+
disabled,
|
|
6567
|
+
helpText: hasIndices ? "Choose an existing index with data, or create a new index from sample data." : void 0
|
|
6568
|
+
});
|
|
6569
|
+
if (typeof selection !== "string") {
|
|
6570
|
+
throw new Error(
|
|
6571
|
+
"selectIndex received an unexpected non-text result"
|
|
6572
|
+
);
|
|
6573
|
+
}
|
|
6574
|
+
if (selection === GO_BACK_OPTION2) {
|
|
6575
|
+
ctx.setUserInput("fetchedIndices", void 0);
|
|
6576
|
+
return ctx.returnToStep("select-playbook");
|
|
6577
|
+
}
|
|
6578
|
+
if (selection === SELECT_APP_OPTION2) {
|
|
6579
|
+
await ctx.changeApplication();
|
|
6580
|
+
continue;
|
|
6581
|
+
}
|
|
6582
|
+
if (selection === CREATE_SAMPLE_INDEX) {
|
|
6583
|
+
result = {
|
|
6584
|
+
indexName: "",
|
|
6585
|
+
sampleIndex: true
|
|
6586
|
+
};
|
|
6587
|
+
break;
|
|
6588
|
+
}
|
|
6589
|
+
const selectedIndex = indices.find(
|
|
6590
|
+
(idx) => formatIndexOption(idx) === selection
|
|
6591
|
+
);
|
|
6592
|
+
if (!selectedIndex) {
|
|
6593
|
+
error = "Invalid selection. Please try again.";
|
|
6594
|
+
continue;
|
|
6595
|
+
}
|
|
6596
|
+
result = {
|
|
6597
|
+
indexName: selectedIndex.name,
|
|
6598
|
+
sampleIndex: false
|
|
6599
|
+
};
|
|
6600
|
+
}
|
|
6601
|
+
return result;
|
|
6602
|
+
}
|
|
6603
|
+
|
|
6604
|
+
// src/actions/playbookSteps/confirmIndex.ts
|
|
6605
|
+
import "zod";
|
|
6606
|
+
var confirmIndexSchema = playbookExecutionSchema.nullable();
|
|
6607
|
+
var CONTINUE_OPTION2 = "Looks good, continue";
|
|
6608
|
+
var GO_BACK_OPTION3 = "Go back";
|
|
6609
|
+
async function confirmIndexStep(ctx) {
|
|
6610
|
+
const { sampleIndex } = ctx.getStepOutput("select-index");
|
|
6611
|
+
if (!sampleIndex) {
|
|
6612
|
+
return null;
|
|
6613
|
+
}
|
|
6614
|
+
const { slug } = ctx.getStepOutput("select-playbook");
|
|
6615
|
+
const selection = await ctx.requestUserInput({
|
|
6616
|
+
prompt: "Ready to create sample index?",
|
|
6617
|
+
promptType: "multipleChoice",
|
|
6618
|
+
options: [CONTINUE_OPTION2, GO_BACK_OPTION3],
|
|
6619
|
+
messages: [
|
|
6620
|
+
`A new index called "algolia_playbooks_${slug}_sample_index" will be created with sample ${slug} data.`
|
|
6621
|
+
],
|
|
6622
|
+
helpText: "Going back lets you choose a different index."
|
|
6623
|
+
});
|
|
6624
|
+
if (typeof selection !== "string") {
|
|
6625
|
+
throw new Error("confirm-index received an unexpected result");
|
|
6626
|
+
}
|
|
6627
|
+
if (selection === GO_BACK_OPTION3) {
|
|
6628
|
+
return ctx.returnToStep("select-index");
|
|
6629
|
+
}
|
|
6630
|
+
ctx.notify({
|
|
6631
|
+
messages: ["Creating sample index and playbook execution\u2026"]
|
|
6632
|
+
});
|
|
6633
|
+
const app = await requireApplication();
|
|
6634
|
+
const playbookSlug = ctx.getUserInput("playbookSlug");
|
|
6635
|
+
if (!playbookSlug) {
|
|
6636
|
+
throw new Error("No playbook slug found in context");
|
|
6637
|
+
}
|
|
6638
|
+
try {
|
|
6639
|
+
const execution = await createSampleIndex(app.id, playbookSlug);
|
|
6640
|
+
ctx.setUserInput("fetchedIndices", void 0);
|
|
6641
|
+
ctx.clearNotices();
|
|
6642
|
+
ctx.notify({
|
|
6643
|
+
messages: [
|
|
6644
|
+
`Sample index "${execution.source_index_name}" created successfully!`
|
|
6645
|
+
]
|
|
6646
|
+
});
|
|
6647
|
+
return execution;
|
|
6648
|
+
} catch (error) {
|
|
6649
|
+
ctx.clearNotices();
|
|
6650
|
+
ctx.notify({
|
|
6651
|
+
messages: ["Failed to create sample index. Please try again."]
|
|
6652
|
+
});
|
|
6653
|
+
throw error;
|
|
6654
|
+
}
|
|
6655
|
+
}
|
|
6656
|
+
|
|
6502
6657
|
// src/lib/cli.ts
|
|
6503
6658
|
var USAGE = `Usage: wizard [workflow-id] [options]
|
|
6504
6659
|
wizard playbook [playbook-slug] [options]
|
|
@@ -6572,6 +6727,21 @@ var playbookWorkflow = {
|
|
|
6572
6727
|
outputSchema: confirmPlaybookSchema,
|
|
6573
6728
|
visible: false,
|
|
6574
6729
|
run: (ctx) => confirmPlaybookStep(ctx)
|
|
6730
|
+
}),
|
|
6731
|
+
defineStep({
|
|
6732
|
+
id: "select-index",
|
|
6733
|
+
title: "Select index",
|
|
6734
|
+
outputSchema: selectIndexSchema,
|
|
6735
|
+
tips: ["apps-and-indices", "records-are-json", "speed"],
|
|
6736
|
+
run: (ctx) => selectIndexStep2(ctx)
|
|
6737
|
+
}),
|
|
6738
|
+
defineStep({
|
|
6739
|
+
id: "confirm-index",
|
|
6740
|
+
title: "Confirm sample index creation",
|
|
6741
|
+
outputSchema: confirmIndexSchema,
|
|
6742
|
+
visible: false,
|
|
6743
|
+
tips: ["apps-and-indices", "records-are-json", "speed"],
|
|
6744
|
+
run: (ctx) => confirmIndexStep(ctx)
|
|
6575
6745
|
})
|
|
6576
6746
|
]
|
|
6577
6747
|
};
|
|
@@ -7652,6 +7822,10 @@ var search = {
|
|
|
7652
7822
|
var selectPlaybook = {
|
|
7653
7823
|
slug: "orders"
|
|
7654
7824
|
};
|
|
7825
|
+
var selectPlaybookIndex = {
|
|
7826
|
+
indexName: "wizard_seed_orders",
|
|
7827
|
+
sampleIndex: false
|
|
7828
|
+
};
|
|
7655
7829
|
var review = {
|
|
7656
7830
|
summaryPoints: [
|
|
7657
7831
|
"Ingested 25 generated Product records into wizard_seed_products.",
|
|
@@ -7673,7 +7847,9 @@ var SEEDS = {
|
|
|
7673
7847
|
},
|
|
7674
7848
|
playbook: {
|
|
7675
7849
|
"select-playbook": selectPlaybook,
|
|
7676
|
-
"confirm-playbook": void 0
|
|
7850
|
+
"confirm-playbook": void 0,
|
|
7851
|
+
"select-index": selectPlaybookIndex,
|
|
7852
|
+
"confirm-index": null
|
|
7677
7853
|
}
|
|
7678
7854
|
};
|
|
7679
7855
|
var SEED_ALGOLIA_STATE = {
|
|
@@ -7687,7 +7863,9 @@ var SEED_USER_INPUTS = {
|
|
|
7687
7863
|
implementation: "success"
|
|
7688
7864
|
},
|
|
7689
7865
|
playbook: {
|
|
7690
|
-
playbookSlug: selectPlaybook.slug
|
|
7866
|
+
playbookSlug: selectPlaybook.slug,
|
|
7867
|
+
playbookIndexName: selectPlaybookIndex.indexName,
|
|
7868
|
+
playbookSampleIndex: selectPlaybookIndex.sampleIndex
|
|
7691
7869
|
}
|
|
7692
7870
|
};
|
|
7693
7871
|
function formatStepList(workflow, startIndex) {
|
|
@@ -7842,7 +8020,7 @@ function delay(ms) {
|
|
|
7842
8020
|
// package.json with { type: 'json' }
|
|
7843
8021
|
var package_default2 = {
|
|
7844
8022
|
name: "@algolia/wizard",
|
|
7845
|
-
version: "0.
|
|
8023
|
+
version: "0.75.0",
|
|
7846
8024
|
description: "Magically implement Algolia functionality in your codebase",
|
|
7847
8025
|
type: "module",
|
|
7848
8026
|
engines: {
|