@algolia/wizard 0.49.0 → 0.50.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 +173 -52
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -3604,7 +3604,7 @@ async function runAnalysis(mode, extraInstructions = []) {
3604
3604
  // package.json
3605
3605
  var package_default = {
3606
3606
  name: "@algolia/wizard",
3607
- version: "0.49.0",
3607
+ version: "0.50.0",
3608
3608
  description: "Magically implement Algolia functionality in your codebase",
3609
3609
  type: "module",
3610
3610
  engines: {
@@ -4888,9 +4888,168 @@ var defaultWorkflow = {
4888
4888
  ]
4889
4889
  };
4890
4890
 
4891
+ // src/actions/playbookSteps/selectPlaybook.ts
4892
+ import { z as z32 } from "zod";
4893
+
4894
+ // src/lib/dashboardApi/client.ts
4895
+ import "zod";
4896
+ var DASHBOARD_API_BASE_URL = `${PROXY_BASE_URL}/dashboard`;
4897
+ var DashboardApiError = class extends Error {
4898
+ constructor(status, message) {
4899
+ super(message);
4900
+ this.status = status;
4901
+ this.name = "DashboardApiError";
4902
+ }
4903
+ status;
4904
+ };
4905
+ async function dashboardRequest(path, schema, init) {
4906
+ const token = getAuthToken();
4907
+ if (!token) {
4908
+ throw new Error("Not authenticated: no user token available");
4909
+ }
4910
+ const res = await proxyFetch(`${DASHBOARD_API_BASE_URL}${path}`, {
4911
+ ...init,
4912
+ headers: {
4913
+ accept: "application/json",
4914
+ authorization: `Bearer ${token}`,
4915
+ ...init?.headers
4916
+ }
4917
+ });
4918
+ if (!res.ok) {
4919
+ throw new DashboardApiError(
4920
+ res.status,
4921
+ `Dashboard API responded ${res.status} for ${path}`
4922
+ );
4923
+ }
4924
+ const body = await res.json();
4925
+ return { status: res.status, data: schema.parse(body) };
4926
+ }
4927
+
4928
+ // src/lib/dashboardApi/schemas.ts
4929
+ import { z as z31 } from "zod";
4930
+ var playbookSchema = z31.object({
4931
+ slug: z31.string(),
4932
+ category: z31.string().optional(),
4933
+ title: z31.string(),
4934
+ description: z31.string().optional()
4935
+ });
4936
+ var playbooksListSchema = z31.array(playbookSchema);
4937
+
4938
+ // src/lib/dashboardApi/api.ts
4939
+ async function getPlaybooks() {
4940
+ const { data } = await dashboardRequest(
4941
+ "/api/1/playbook-integrations/playbooks",
4942
+ playbooksListSchema
4943
+ );
4944
+ return data;
4945
+ }
4946
+
4947
+ // src/actions/playbookSteps/selectPlaybook.ts
4948
+ var selectPlaybookSchema = z32.object({
4949
+ slug: z32.string()
4950
+ });
4951
+ function persistSlug(ctx, slug) {
4952
+ ctx.setUserInput("playbookSlug", slug);
4953
+ return { slug };
4954
+ }
4955
+ async function selectPlaybookStep(ctx, requestedSlug) {
4956
+ const playbooks = await getPlaybooks();
4957
+ const slugs = playbooks.map((playbook) => playbook.slug);
4958
+ if (slugs.length === 0) {
4959
+ throw new Error("No playbooks are available.");
4960
+ }
4961
+ if (requestedSlug && slugs.includes(requestedSlug)) {
4962
+ return persistSlug(ctx, requestedSlug);
4963
+ }
4964
+ const messages = requestedSlug ? [
4965
+ `"${requestedSlug}" is not a valid playbook. Choose one of the available playbooks:`
4966
+ ] : ["Choose a playbook:"];
4967
+ const selection = await ctx.requestUserInput({
4968
+ prompt: "Which playbook do you want to run?",
4969
+ promptType: "multipleChoice",
4970
+ options: slugs,
4971
+ messages
4972
+ });
4973
+ if (typeof selection !== "string") {
4974
+ throw new Error("selectPlaybook received an unexpected non-text result");
4975
+ }
4976
+ return persistSlug(ctx, selection);
4977
+ }
4978
+
4979
+ // src/lib/cli.ts
4980
+ var USAGE = `Usage: wizard [workflow-id] [options]
4981
+ wizard playbook [playbook-slug] [options]
4982
+
4983
+ Options:
4984
+ --seed <step-id> Start the workflow at the step with this id, with earlier
4985
+ steps pre-filled with test data. Pass with no value to print
4986
+ the step ids. See CONTRIBUTING.md.
4987
+ --no-telemetry Send no telemetry or analytics for this run.
4988
+ --reset-on-run Wipe this project's wizard state (run state, AI consent)
4989
+ before starting, so the run behaves like a first-ever
4990
+ run. Also drops every API key the wizard has
4991
+ stored in your keychain (or, where the platform has none,
4992
+ the encrypted file it falls back to \u2014 see CONTRIBUTING.md),
4993
+ for this project and any other, so later runs create new
4994
+ ones. Your Algolia login is not touched.
4995
+ -h, --help Print this message.`;
4996
+ function parseCliArgs(argv) {
4997
+ const positionals = [];
4998
+ let seed;
4999
+ let telemetry = true;
5000
+ let resetOnRun = false;
5001
+ let help = false;
5002
+ for (let i = 0; i < argv.length; i++) {
5003
+ const arg = argv[i];
5004
+ if (arg === "--seed") {
5005
+ const next = argv[i + 1];
5006
+ if (next !== void 0 && !next.startsWith("-")) {
5007
+ seed = next;
5008
+ i++;
5009
+ } else {
5010
+ seed = null;
5011
+ }
5012
+ } else if (arg.startsWith("--seed=")) {
5013
+ seed = arg.slice("--seed=".length);
5014
+ } else if (arg === "--no-telemetry") {
5015
+ telemetry = false;
5016
+ } else if (arg === "--reset-on-run") {
5017
+ resetOnRun = true;
5018
+ } else if (arg === "--help" || arg === "-h") {
5019
+ help = true;
5020
+ } else if (arg.startsWith("-")) {
5021
+ throw new Error(`Unknown option "${arg}".`);
5022
+ } else {
5023
+ positionals.push(arg);
5024
+ }
5025
+ }
5026
+ return { positionals, seed, telemetry, resetOnRun, help };
5027
+ }
5028
+ function getPlaybookSlugArg(argv = process.argv.slice(2)) {
5029
+ const { positionals } = parseCliArgs(argv);
5030
+ if (positionals[0] !== "playbook") return void 0;
5031
+ return positionals[1];
5032
+ }
5033
+
5034
+ // src/workflows/playbook.ts
5035
+ var playbookWorkflow = {
5036
+ id: "playbook",
5037
+ title: "Playbook Workflow",
5038
+ description: "Select a playbook from the dashboard catalogue and walk through its implementation.",
5039
+ steps: [
5040
+ defineStep({
5041
+ id: "select-playbook",
5042
+ title: "Select playbook",
5043
+ outputSchema: selectPlaybookSchema,
5044
+ run: (ctx) => selectPlaybookStep(ctx, getPlaybookSlugArg())
5045
+ })
5046
+ ]
5047
+ };
5048
+
4891
5049
  // src/workflows/index.ts
4892
5050
  var workflows = {
4893
- [defaultWorkflow.id]: defaultWorkflow
5051
+ [defaultWorkflow.id]: defaultWorkflow,
5052
+ [playbookWorkflow.id]: playbookWorkflow
4894
5053
  };
4895
5054
  function getWorkflow(id) {
4896
5055
  return workflows[id];
@@ -6071,6 +6230,9 @@ var search = {
6071
6230
  ]
6072
6231
  }
6073
6232
  };
6233
+ var selectPlaybook = {
6234
+ slug: "orders"
6235
+ };
6074
6236
  var review = {
6075
6237
  summaryPoints: [
6076
6238
  "Ingested 25 generated Product records into wizard_seed_products.",
@@ -6089,6 +6251,9 @@ var SEEDS = {
6089
6251
  "confirm-framework": confirmFramework2,
6090
6252
  search,
6091
6253
  review
6254
+ },
6255
+ playbook: {
6256
+ "select-playbook": selectPlaybook
6092
6257
  }
6093
6258
  };
6094
6259
  var SEED_USER_INPUTS = {
@@ -6097,6 +6262,9 @@ var SEED_USER_INPUTS = {
6097
6262
  confirmedEntities: confirmEntities2.confirmedEntities,
6098
6263
  ingestionAnalysis: confirmEntities2.ingestionAnalysis,
6099
6264
  implementation: "success"
6265
+ },
6266
+ playbook: {
6267
+ playbookSlug: selectPlaybook.slug
6100
6268
  }
6101
6269
  };
6102
6270
  function formatStepList(workflow, startIndex) {
@@ -6159,7 +6327,9 @@ async function seedWorkflowState(workflow, value) {
6159
6327
  if (!config.aiConsent) {
6160
6328
  config.aiConsent = true;
6161
6329
  await saveConfig(config);
6162
- messages.push("Seed: set aiConsent in the project config (skips the consent prompt).");
6330
+ messages.push(
6331
+ "Seed: set aiConsent in the project config (skips the consent prompt)."
6332
+ );
6163
6333
  }
6164
6334
  if (startIndex === 0) {
6165
6335
  await clearWorkflowState(workflow.id);
@@ -6185,55 +6355,6 @@ async function seedWorkflowState(workflow, value) {
6185
6355
  return { messages };
6186
6356
  }
6187
6357
 
6188
- // src/lib/cli.ts
6189
- var USAGE = `Usage: wizard [workflow-id] [options]
6190
-
6191
- Options:
6192
- --seed <step-id> Start the workflow at the step with this id, with earlier
6193
- steps pre-filled with test data. Pass with no value to print
6194
- the step ids. See CONTRIBUTING.md.
6195
- --no-telemetry Send no telemetry or analytics for this run.
6196
- --reset-on-run Wipe this project's wizard state (run state, AI consent)
6197
- before starting, so the run behaves like a first-ever
6198
- run. Also drops every API key the wizard has
6199
- stored in your keychain (or, where the platform has none,
6200
- the encrypted file it falls back to \u2014 see CONTRIBUTING.md),
6201
- for this project and any other, so later runs create new
6202
- ones. Your Algolia login is not touched.
6203
- -h, --help Print this message.`;
6204
- function parseCliArgs(argv) {
6205
- const positionals = [];
6206
- let seed;
6207
- let telemetry = true;
6208
- let resetOnRun = false;
6209
- let help = false;
6210
- for (let i = 0; i < argv.length; i++) {
6211
- const arg = argv[i];
6212
- if (arg === "--seed") {
6213
- const next = argv[i + 1];
6214
- if (next !== void 0 && !next.startsWith("-")) {
6215
- seed = next;
6216
- i++;
6217
- } else {
6218
- seed = null;
6219
- }
6220
- } else if (arg.startsWith("--seed=")) {
6221
- seed = arg.slice("--seed=".length);
6222
- } else if (arg === "--no-telemetry") {
6223
- telemetry = false;
6224
- } else if (arg === "--reset-on-run") {
6225
- resetOnRun = true;
6226
- } else if (arg === "--help" || arg === "-h") {
6227
- help = true;
6228
- } else if (arg.startsWith("-")) {
6229
- throw new Error(`Unknown option "${arg}".`);
6230
- } else {
6231
- positionals.push(arg);
6232
- }
6233
- }
6234
- return { positionals, seed, telemetry, resetOnRun, help };
6235
- }
6236
-
6237
6358
  // src/lib/resetState.ts
6238
6359
  import { readdir as readdir3, rm as rm2 } from "node:fs/promises";
6239
6360
  import { join as join13 } from "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {