@neutrome-labs/merchantduo 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -3,7 +3,7 @@ Simple terminal interface to deploy Magento 2 stores onto the Cloudflare Edge.
3
3
 
4
4
  # How To Use
5
5
 
6
- > `pnpx @neutrome-labs/merchantduo help`
6
+ > pnpx @neutrome-labs/merchantduo help
7
7
 
8
8
  ```
9
9
  MerchantDuo developer CLI
package/dist/index.js CHANGED
@@ -23,7 +23,12 @@ function configureCliLogging() {
23
23
  },
24
24
  loggers: [
25
25
  {
26
- category: ["merchantduo", "cli"],
26
+ category: ["logtape", "meta"],
27
+ sinks: ["console"],
28
+ lowestLevel: "warning"
29
+ },
30
+ {
31
+ category: ["merchantduo"],
27
32
  sinks: ["console"],
28
33
  lowestLevel: "warning"
29
34
  }
@@ -173,66 +178,112 @@ import * as z4 from "zod";
173
178
 
174
179
  // ../../src/types/service-mysql.ts
175
180
  import * as z2 from "zod";
181
+ var BUNDLED_CONNECTION_STRING = "mysql://magento:magento@127.0.0.1:3306/magento";
176
182
  var BundledMysqlServiceConfigSchema = z2.object({
177
- kind: z2.literal("bundled")
183
+ mode: z2.literal("bundled").default("bundled")
178
184
  });
179
185
  var HyperdriveMysqlConfigSchema = z2.object({
180
- kind: z2.literal("hyperdrive"),
186
+ mode: z2.literal("hyperdrive"),
181
187
  connectionString: z2.string()
182
188
  });
183
- var MysqlServiceConfigSchema = z2.union([
184
- BundledMysqlServiceConfigSchema,
185
- HyperdriveMysqlConfigSchema
186
- ]);
189
+ var MysqlServiceConfigSchema = z2.union([BundledMysqlServiceConfigSchema, HyperdriveMysqlConfigSchema]).default({ mode: "bundled" }).transform((config2, ctx) => {
190
+ const connectionString = config2.mode === "bundled" ? BUNDLED_CONNECTION_STRING : config2.connectionString;
191
+ let url3;
192
+ try {
193
+ url3 = new URL(connectionString);
194
+ } catch {
195
+ ctx.addIssue({
196
+ code: "custom",
197
+ message: "Invalid MySQL connection string"
198
+ });
199
+ return z2.NEVER;
200
+ }
201
+ return {
202
+ mode: config2.mode,
203
+ connectionString,
204
+ host: url3.hostname,
205
+ port: Number(url3.port || 3306),
206
+ database: decodeURIComponent(url3.pathname.replace(/^\//, "") || "magento"),
207
+ username: decodeURIComponent(url3.username),
208
+ password: decodeURIComponent(url3.password)
209
+ };
210
+ });
187
211
 
188
212
  // ../../src/types/service-opensearch.ts
189
213
  import * as z3 from "zod";
214
+ var BUNDLED_OPENSEARCH_URL = "http://localhost:9200";
190
215
  var BundledOpensearchServiceConfigSchema = z3.object({
191
- kind: z3.literal("bundled")
216
+ mode: z3.literal("bundled").default("bundled")
192
217
  });
193
218
  var RemoteOpensearchConfigSchema = z3.object({
194
- kind: z3.literal("remote"),
219
+ mode: z3.literal("remote"),
195
220
  url: z3.url(),
196
221
  port: z3.number().optional(),
197
222
  username: z3.string().optional(),
198
223
  password: z3.string().optional()
199
- }).transform((x) => {
200
- const url3 = new URL(x.url);
224
+ });
225
+ var OpensearchServiceConfigSchema = z3.union([BundledOpensearchServiceConfigSchema, RemoteOpensearchConfigSchema]).default({ mode: "bundled" }).transform((config2) => {
226
+ const url3 = new URL(
227
+ config2.mode === "bundled" ? BUNDLED_OPENSEARCH_URL : config2.url
228
+ );
229
+ const username = config2.mode === "remote" ? config2.username || decodeURIComponent(url3.username) || void 0 : void 0;
230
+ const password = config2.mode === "remote" ? config2.password || decodeURIComponent(url3.password) || void 0 : void 0;
201
231
  return {
202
- ...x,
203
- port: x.port ?? Number(url3.port || (url3.protocol === "https:" ? 443 : 80))
232
+ mode: config2.mode,
233
+ url: `${url3.protocol}//${url3.host}`,
234
+ port: config2.mode === "remote" && config2.port ? config2.port : Number(url3.port || (url3.protocol === "https:" ? 443 : 80)),
235
+ ...username ? { username } : {},
236
+ ...password ? { password } : {}
204
237
  };
205
238
  });
206
- var OpensearchServiceConfigSchema = z3.union([
207
- BundledOpensearchServiceConfigSchema,
208
- RemoteOpensearchConfigSchema
209
- ]);
210
239
 
211
240
  // ../../src/types/instance.ts
212
241
  var InstanceGradeSchema = z4.enum(["sandbox", "instance"]);
242
+ var InstanceR2MountSchema = z4.object({
243
+ bucket: z4.string().min(1).describe("R2 bucket name"),
244
+ prefix: z4.string().min(1).optional().describe("R2 key prefix mounted into the container"),
245
+ readOnly: z4.boolean().default(false)
246
+ });
247
+ var InstanceServicesConfigSchema = z4.object({
248
+ mysql: MysqlServiceConfigSchema.optional(),
249
+ opensearch: OpensearchServiceConfigSchema.optional()
250
+ }).optional().transform((services) => ({
251
+ mysql: MysqlServiceConfigSchema.parse(services?.mysql ?? {}),
252
+ opensearch: OpensearchServiceConfigSchema.parse(services?.opensearch ?? {})
253
+ }));
213
254
  var InstanceConfigSchema = z4.object({
214
255
  instanceId: z4.string(),
215
256
  baseUrl: z4.url().optional(),
216
257
  grade: InstanceGradeSchema.default("sandbox"),
217
258
  template: TemplatesSchema,
218
259
  deadline: z4.date().optional().describe("deadline for the instance"),
219
- services: z4.object({
220
- mysql: MysqlServiceConfigSchema,
221
- opensearch: OpensearchServiceConfigSchema
222
- }),
260
+ services: InstanceServicesConfigSchema,
223
261
  snapshots: z4.object({
224
262
  fs: z4.string().describe("filesystem (src) snapshot reference").optional(),
225
263
  app: z4.string().describe("app (db) snapshot reference").optional()
226
264
  }).optional(),
227
265
  mounts: z4.object({
228
- media: z4.string().describe("path to the pub/media r2 mount")
266
+ media: InstanceR2MountSchema.optional().describe("pub/media R2 mount")
229
267
  }).optional(),
230
268
  tools: z4.object({
231
269
  codeserver: z4.boolean().default(false),
232
270
  phpMyAdmin: z4.boolean().default(false),
233
271
  opencode: z4.boolean().default(false)
234
272
  }).optional()
235
- });
273
+ }).transform((config2) => ({
274
+ ...config2,
275
+ services: {
276
+ ...config2.services,
277
+ opensearch: {
278
+ ...config2.services.opensearch,
279
+ indexPrefix: indexPrefixForInstance(config2.instanceId)
280
+ }
281
+ }
282
+ }));
283
+ function indexPrefixForInstance(instanceId) {
284
+ const prefix = instanceId.replace(/[^a-zA-Z0-9]/g, "_").substring(0, 6);
285
+ return prefix || "magento";
286
+ }
236
287
  var InstanceStateSchema = z4.enum([
237
288
  "stopped",
238
289
  "scheduled",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neutrome-labs/merchantduo",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/logging.ts CHANGED
@@ -18,7 +18,12 @@ export function configureCliLogging(): void {
18
18
  },
19
19
  loggers: [
20
20
  {
21
- category: ["merchantduo", "cli"],
21
+ category: ["logtape", "meta"],
22
+ sinks: ["console"],
23
+ lowestLevel: "warning",
24
+ },
25
+ {
26
+ category: ["merchantduo"],
22
27
  sinks: ["console"],
23
28
  lowestLevel: "warning",
24
29
  },