@fluid-app/fluid-cli-localization 0.1.408 → 0.1.409
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/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +80 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ declare function registerCountriesCommands(parent: Command, ctx: CommandContext)
|
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/markets/commands.d.ts
|
|
8
8
|
/**
|
|
9
|
-
* Register `fluid markets list|add-country|remove-country|rename` on `parent`.
|
|
9
|
+
* Register `fluid markets list|add-country|remove-country|rename|create|move|delete` on `parent`.
|
|
10
10
|
*
|
|
11
11
|
* @param parent - the `markets` command group
|
|
12
12
|
* @param ctx - the CLI command context
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/countries/commands.ts","../src/markets/commands.ts","../src/translations/commands.ts","../src/index.ts"],"mappings":";;;;iBAiMgB,yBAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;;;AAFP;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/countries/commands.ts","../src/markets/commands.ts","../src/translations/commands.ts","../src/index.ts"],"mappings":";;;;iBAiMgB,yBAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;;;AAFP;;;;iBC9HgB,uBAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;iBC+BS,4BAAA,CACd,MAAA,EAAQ,OAAA,EACR,GAAA,EAAK,cAAA;;;AF2FP;;;;;;AAAA,cGhLM,MAAA,EAAQ,WAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -4167,7 +4167,7 @@ const MARKET_CONFIG_DISABLED_MESSAGE = "Markets configuration is not enabled for
|
|
|
4167
4167
|
* fixed text for a disabled release, and a retry hint for `retry_later`.
|
|
4168
4168
|
* Keeps the HTTP status so the failure report carries it.
|
|
4169
4169
|
*/
|
|
4170
|
-
function marketsFailure(err) {
|
|
4170
|
+
function marketsFailure(err, withCode = false) {
|
|
4171
4171
|
const status = statusOf(err);
|
|
4172
4172
|
const body = err?.body;
|
|
4173
4173
|
const code = typeof body?.["error"] === "string" ? body["error"] : void 0;
|
|
@@ -4175,6 +4175,7 @@ function marketsFailure(err) {
|
|
|
4175
4175
|
if (code === "market_config_disabled") message = MARKET_CONFIG_DISABLED_MESSAGE;
|
|
4176
4176
|
else if (typeof body?.["message"] === "string") {
|
|
4177
4177
|
message = body["message"];
|
|
4178
|
+
if (withCode && code && !message.includes(code)) message = `${message} [${code}]`;
|
|
4178
4179
|
if (code === "retry_later" && !/try again/i.test(message)) message = `${message} Try again.`;
|
|
4179
4180
|
} else if (code === "retry_later") message = "The company is busy. Try again.";
|
|
4180
4181
|
else message = errorDetail(err).message;
|
|
@@ -4183,11 +4184,11 @@ function marketsFailure(err) {
|
|
|
4183
4184
|
const failure = new LocalizationError(message);
|
|
4184
4185
|
return status === void 0 ? failure : Object.assign(failure, { status });
|
|
4185
4186
|
}
|
|
4186
|
-
async function guarded(call) {
|
|
4187
|
+
async function guarded(call, withCode = false) {
|
|
4187
4188
|
try {
|
|
4188
4189
|
return await call();
|
|
4189
4190
|
} catch (err) {
|
|
4190
|
-
throw marketsFailure(err);
|
|
4191
|
+
throw marketsFailure(err, withCode);
|
|
4191
4192
|
}
|
|
4192
4193
|
}
|
|
4193
4194
|
/** GET /api/company/v2026-10/markets: markets, their countries, and active countries without a market. */
|
|
@@ -4209,8 +4210,45 @@ async function removeMarketCountry(client, iso) {
|
|
|
4209
4210
|
function renameMarket(client, id, name) {
|
|
4210
4211
|
return guarded(() => client.patch(`${MARKETS_PATH}/${encodeURIComponent(id)}`, { name }));
|
|
4211
4212
|
}
|
|
4213
|
+
/** POST /api/company/v2026-10/markets: creates a market holding the given countries; `carryPrices: false` sends `carry_prices: false`. */
|
|
4214
|
+
function createMarket(client, name, countryIsos, carryPrices = true) {
|
|
4215
|
+
return guarded(() => client.post(MARKETS_PATH, {
|
|
4216
|
+
name,
|
|
4217
|
+
country_isos: countryIsos,
|
|
4218
|
+
...carryPrices ? {} : { carry_prices: false }
|
|
4219
|
+
}), true);
|
|
4220
|
+
}
|
|
4221
|
+
/** GET /api/company/v2026-10/markets/:id/countries/:iso/preview: what moving the country would change. */
|
|
4222
|
+
function previewMoveCountry(client, id, iso) {
|
|
4223
|
+
return guarded(() => client.get(`${MARKETS_PATH}/${encodeURIComponent(id)}/countries/${iso}/preview`), true);
|
|
4224
|
+
}
|
|
4225
|
+
/** POST /api/company/v2026-10/markets/:id/countries/:iso: moves the country into market `id`. Sends no body unless `carryPrices` is false. Returns the market list. */
|
|
4226
|
+
function moveMarketCountry(client, id, iso, carryPrices = true) {
|
|
4227
|
+
return guarded(() => client.post(`${MARKETS_PATH}/${encodeURIComponent(id)}/countries/${iso}`, carryPrices ? void 0 : { carry_prices: false }), true);
|
|
4228
|
+
}
|
|
4229
|
+
/** GET /api/company/v2026-10/markets/:id/deletion/preview: what deleting the market would affect. */
|
|
4230
|
+
function previewMarketDeletion(client, id) {
|
|
4231
|
+
return guarded(() => client.get(`${MARKETS_PATH}/${encodeURIComponent(id)}/deletion/preview`), true);
|
|
4232
|
+
}
|
|
4233
|
+
/** DELETE /api/company/v2026-10/markets/:id?confirm_name=: deletes an empty market; the name must match. */
|
|
4234
|
+
async function deleteMarket(client, id, confirmName) {
|
|
4235
|
+
await guarded(() => client.delete(`${MARKETS_PATH}/${encodeURIComponent(id)}?confirm_name=${encodeURIComponent(confirmName)}`), true);
|
|
4236
|
+
}
|
|
4212
4237
|
//#endregion
|
|
4213
4238
|
//#region src/markets/commands.ts
|
|
4239
|
+
const MAX_CREATE_COUNTRIES = 10;
|
|
4240
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4241
|
+
async function resolveMarketId(api, ref) {
|
|
4242
|
+
const { markets } = await listMarkets(api);
|
|
4243
|
+
const byId = markets.find((m) => m.id.toLowerCase() === ref.toLowerCase());
|
|
4244
|
+
if (byId) return byId.id;
|
|
4245
|
+
if (UUID.test(ref)) throw new LocalizationError(`No market with id ${ref}.`);
|
|
4246
|
+
const exact = markets.filter((m) => m.name === ref);
|
|
4247
|
+
const found = exact.length ? exact : markets.filter((m) => m.name.toLowerCase() === ref.toLowerCase());
|
|
4248
|
+
if (found.length === 0) throw new LocalizationError(`No market named "${ref}".`);
|
|
4249
|
+
if (found.length > 1) throw new LocalizationError(`More than one market is named "${ref}": ${found.map((m) => m.id).join(", ")}. Use the id.`);
|
|
4250
|
+
return found[0].id;
|
|
4251
|
+
}
|
|
4214
4252
|
async function client$1(ctx) {
|
|
4215
4253
|
return await ctx.getClient();
|
|
4216
4254
|
}
|
|
@@ -4220,7 +4258,7 @@ function currencyCodeOf(raw) {
|
|
|
4220
4258
|
return code;
|
|
4221
4259
|
}
|
|
4222
4260
|
/**
|
|
4223
|
-
* Register `fluid markets list|add-country|remove-country|rename` on `parent`.
|
|
4261
|
+
* Register `fluid markets list|add-country|remove-country|rename|create|move|delete` on `parent`.
|
|
4224
4262
|
*
|
|
4225
4263
|
* @param parent - the `markets` command group
|
|
4226
4264
|
* @param ctx - the CLI command context
|
|
@@ -4248,6 +4286,44 @@ function registerMarketsCommands(parent, ctx) {
|
|
|
4248
4286
|
if (!trimmed) throw new LocalizationError("A market name can't be blank.");
|
|
4249
4287
|
ctx.output(await renameMarket(await client$1(ctx), marketId, trimmed));
|
|
4250
4288
|
}));
|
|
4289
|
+
parent.command("create <name...>").description("Create a market holding the given countries. Whether prices are carried follows the server default (carried only if you have products.update); --no-carry-prices forces no carry").requiredOption("--countries <isos>", "Comma-separated ISO codes, e.g. GB,FR").option("--no-carry-prices", "Force no price carry into the new market (default: server decides, by products.update)").action((words, opts) => run(async () => {
|
|
4290
|
+
const name = words.join(" ").trim();
|
|
4291
|
+
if (!name) throw new LocalizationError("A market name can't be blank.");
|
|
4292
|
+
const isos = [...new Set(opts.countries.split(",").map((c) => countryCodeOf(c)))];
|
|
4293
|
+
if (isos.length > MAX_CREATE_COUNTRIES) throw new LocalizationError(`A market can be created with at most ${MAX_CREATE_COUNTRIES} countries.`);
|
|
4294
|
+
const written = await createMarket(await client$1(ctx), name, isos, opts.carryPrices);
|
|
4295
|
+
ctx.output({
|
|
4296
|
+
...written,
|
|
4297
|
+
carry_prices_requested: opts.carryPrices ? "server default" : false,
|
|
4298
|
+
note: opts.carryPrices ? "carry_prices was not sent; the server default applies." : "carry_prices: false was sent; no prices were copied to the new market."
|
|
4299
|
+
});
|
|
4300
|
+
}));
|
|
4301
|
+
parent.command("move <iso>").description("Move a country into another market. Whether prices are carried follows the server default (carried only if you have products.update); --no-carry-prices forces no carry").requiredOption("--to <market>", "Target market id or name").option("--preview", "Show what the move would change; write nothing", false).option("--no-carry-prices", "Force no price carry into the target market (default: server decides, by products.update)").option("--yes", "Confirm without a prompt", false).action((iso, opts) => run(async () => {
|
|
4302
|
+
const code = countryCodeOf(iso);
|
|
4303
|
+
const api = await client$1(ctx);
|
|
4304
|
+
const id = await resolveMarketId(api, opts.to);
|
|
4305
|
+
if (opts.preview) {
|
|
4306
|
+
ctx.output(await previewMoveCountry(api, id, code));
|
|
4307
|
+
return;
|
|
4308
|
+
}
|
|
4309
|
+
if (!opts.yes && process.stdin.isTTY) ctx.output(await previewMoveCountry(api, id, code));
|
|
4310
|
+
await confirmChange(`Move ${code} into market ${opts.to}?`, opts.yes);
|
|
4311
|
+
ctx.output(await moveMarketCountry(api, id, code, opts.carryPrices));
|
|
4312
|
+
}));
|
|
4313
|
+
parent.command("delete <market>").description("Delete an empty market. --confirm must repeat its name").option("--confirm <name>", "The market's exact name").option("--preview", "Show what deleting would affect; write nothing", false).action((ref, opts) => run(async () => {
|
|
4314
|
+
const api = await client$1(ctx);
|
|
4315
|
+
const id = await resolveMarketId(api, ref);
|
|
4316
|
+
if (opts.preview) {
|
|
4317
|
+
ctx.output(await previewMarketDeletion(api, id));
|
|
4318
|
+
return;
|
|
4319
|
+
}
|
|
4320
|
+
if (!opts.confirm) throw new LocalizationError("Deleting a market needs --confirm <name> with the market's exact name.");
|
|
4321
|
+
await deleteMarket(api, id, opts.confirm);
|
|
4322
|
+
ctx.output({
|
|
4323
|
+
market_id: id,
|
|
4324
|
+
deleted: true
|
|
4325
|
+
});
|
|
4326
|
+
}));
|
|
4251
4327
|
}
|
|
4252
4328
|
//#endregion
|
|
4253
4329
|
//#region src/translations/commands.ts
|