create-mastra 1.12.3-alpha.3 → 1.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # create-mastra
2
2
 
3
+ ## 1.13.0
4
+
5
+ ## 1.13.0-alpha.4
6
+
3
7
  ## 1.12.3-alpha.3
4
8
 
5
9
  ## 1.12.3-alpha.2
@@ -7,8 +7,8 @@ import 'node:fs/promises';
7
7
  import 'node:http';
8
8
  import 'node:os';
9
9
  import 'node:path';
10
- import 'node:url';
11
10
  import 'posthog-node';
11
+ import 'node:url';
12
12
  import 'node:string_decoder';
13
13
  import 'node:util';
14
14
  import 'node:process';
@@ -29,4 +29,4 @@ import 'tinyexec';
29
29
 
30
30
 
31
31
  export { fetchOrgs };
32
- //# sourceMappingURL=api-C4LNCE5C-Bu-kdDfK.js.map
32
+ //# sourceMappingURL=api-C4LNCE5C-C6a7ZtxG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-C4LNCE5C-C6a7ZtxG.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -8,8 +8,8 @@ import 'node:fs/promises';
8
8
  import 'node:http';
9
9
  import 'node:os';
10
10
  import 'node:path';
11
- import 'node:url';
12
11
  import 'posthog-node';
12
+ import 'node:url';
13
13
  import 'node:string_decoder';
14
14
  import 'node:util';
15
15
  import 'node:process';
@@ -30,4 +30,4 @@ import 'tinyexec';
30
30
 
31
31
 
32
32
  export { loadCredentials, tryRefreshToken };
33
- //# sourceMappingURL=credentials-EGXLGJFI-4_EzI-6m.js.map
33
+ //# sourceMappingURL=credentials-EGXLGJFI-AePRvo2y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials-EGXLGJFI-AePRvo2y.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -2,14 +2,14 @@
2
2
  import { Command } from 'commander';
3
3
  import child_process, { execFileSync, ChildProcess, execFile, spawnSync, spawn } from 'node:child_process';
4
4
  import { randomBytes, randomUUID } from 'node:crypto';
5
- import fs3, { readFileSync, statSync, appendFileSync, writeFileSync, createWriteStream, createReadStream, existsSync } from 'node:fs';
5
+ import fs3, { readFileSync, statSync, appendFileSync, writeFileSync, createWriteStream, createReadStream, existsSync, mkdirSync } from 'node:fs';
6
6
  import * as fs4__default from 'node:fs/promises';
7
7
  import fs4__default__default, { readFile, mkdir, writeFile, chmod, unlink } from 'node:fs/promises';
8
8
  import { createServer } from 'node:http';
9
9
  import os, { homedir, release, constants } from 'node:os';
10
10
  import path, { join, dirname } from 'node:path';
11
- import { fileURLToPath } from 'node:url';
12
11
  import { PostHog } from 'posthog-node';
12
+ import { fileURLToPath } from 'node:url';
13
13
  import { StringDecoder } from 'node:string_decoder';
14
14
  import util, { debuglog, stripVTControlCharacters, inspect, promisify, callbackify, aborted, styleText } from 'node:util';
15
15
  import process$2, { platform, hrtime, execPath, execArgv, stdout, stdin } from 'node:process';
@@ -546,7 +546,7 @@ async function authenticatedFetch(input, init) {
546
546
  if (!_refreshInFlight) {
547
547
  _refreshInFlight = (async () => {
548
548
  try {
549
- const { tryRefreshToken, loadCredentials } = await import('./credentials-EGXLGJFI-4_EzI-6m.js');
549
+ const { tryRefreshToken, loadCredentials } = await import('./credentials-EGXLGJFI-AePRvo2y.js');
550
550
  const creds = await loadCredentials();
551
551
  if (!creds) throw new Error("No credentials");
552
552
  const newToken2 = await tryRefreshToken(creds);
@@ -830,7 +830,7 @@ async function getToken() {
830
830
  return newCreds.token;
831
831
  }
832
832
  async function validateOrgAccess(token, orgId) {
833
- const { fetchOrgs } = await import('./api-C4LNCE5C-Bu-kdDfK.js');
833
+ const { fetchOrgs } = await import('./api-C4LNCE5C-C6a7ZtxG.js');
834
834
  const orgs = await fetchOrgs(token);
835
835
  const hasAccess = orgs.some((o) => o.id === orgId);
836
836
  if (!hasAccess) {
@@ -14475,9 +14475,9 @@ var FileService = class {
14475
14475
  * @returns
14476
14476
  */
14477
14477
  async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
14478
- const __filename2 = fileURLToPath(import.meta.url);
14479
- const __dirname2 = path.dirname(__filename2);
14480
- const filePath = path.resolve(__dirname2, "starter-files", inputFile);
14478
+ const __filename = fileURLToPath(import.meta.url);
14479
+ const __dirname = path.dirname(__filename);
14480
+ const filePath = path.resolve(__dirname, "starter-files", inputFile);
14481
14481
  const fileString = fs3.readFileSync(filePath, "utf8");
14482
14482
  if (fs3.existsSync(outputFilePath) && !replaceIfExists) {
14483
14483
  console.info(`${outputFilePath} already exists`);
@@ -15436,8 +15436,7 @@ async function gitInit({ cwd }) {
15436
15436
  { cwd, stdio: "ignore" }
15437
15437
  );
15438
15438
  }
15439
- var __filename$1 = fileURLToPath(import.meta.url);
15440
- var __dirname$1 = path.dirname(__filename$1);
15439
+ var ANALYTICS_CONFIG_PATH = path.join(os.homedir(), ".mastra", "analytics.json");
15441
15440
  var analyticsInstance = null;
15442
15441
  function getAnalytics() {
15443
15442
  return analyticsInstance;
@@ -15461,33 +15460,39 @@ var PosthogAnalytics = class _PosthogAnalytics {
15461
15460
  return;
15462
15461
  }
15463
15462
  this.packageManager = getPackageManager();
15464
- const cliConfigPath = path.join(__dirname$1, "mastra-cli.json");
15465
- if (existsSync(cliConfigPath)) {
15466
- try {
15467
- const { distinctId, sessionId } = JSON.parse(readFileSync(cliConfigPath, "utf-8"));
15468
- this.distinctId = distinctId;
15469
- this.sessionId = sessionId;
15470
- } catch {
15471
- this.sessionId = randomUUID();
15472
- this.distinctId = this.getDistinctId();
15463
+ const { distinctId, sessionId } = this.getOrCreateAnalyticsConfig();
15464
+ this.distinctId = distinctId;
15465
+ this.sessionId = sessionId;
15466
+ this.initializePostHog(apiKey, host);
15467
+ }
15468
+ getOrCreateAnalyticsConfig(configPath = ANALYTICS_CONFIG_PATH) {
15469
+ try {
15470
+ if (existsSync(configPath)) {
15471
+ const { distinctId, sessionId } = JSON.parse(readFileSync(configPath, "utf-8"));
15472
+ if (distinctId && !this.isHostnameDerivedDistinctId(distinctId)) {
15473
+ const config2 = {
15474
+ distinctId,
15475
+ sessionId: sessionId || randomUUID()
15476
+ };
15477
+ if (config2.sessionId !== sessionId) {
15478
+ this.writeCliConfig(config2, configPath);
15479
+ }
15480
+ return config2;
15481
+ }
15473
15482
  }
15474
- this.writeCliConfig({
15475
- distinctId: this.distinctId,
15476
- sessionId: this.sessionId
15477
- });
15478
- } else {
15479
- this.sessionId = randomUUID();
15480
- this.distinctId = this.getDistinctId();
15481
- this.writeCliConfig({
15482
- distinctId: this.distinctId,
15483
- sessionId: this.sessionId
15484
- });
15483
+ } catch {
15485
15484
  }
15486
- this.initializePostHog(apiKey, host);
15485
+ const config = {
15486
+ distinctId: this.createDistinctId(),
15487
+ sessionId: randomUUID()
15488
+ };
15489
+ this.writeCliConfig(config, configPath);
15490
+ return config;
15487
15491
  }
15488
- writeCliConfig({ distinctId, sessionId }) {
15492
+ writeCliConfig({ distinctId, sessionId }, configPath = ANALYTICS_CONFIG_PATH) {
15489
15493
  try {
15490
- writeFileSync(path.join(__dirname$1, "mastra-cli.json"), JSON.stringify({ distinctId, sessionId }));
15494
+ mkdirSync(path.dirname(configPath), { recursive: true });
15495
+ writeFileSync(configPath, JSON.stringify({ distinctId, sessionId }));
15491
15496
  } catch {
15492
15497
  }
15493
15498
  }
@@ -15511,9 +15516,11 @@ var PosthogAnalytics = class _PosthogAnalytics {
15511
15516
  }
15512
15517
  return true;
15513
15518
  }
15514
- getDistinctId() {
15515
- const machineId = os.hostname();
15516
- return `mastra-${machineId}`;
15519
+ createDistinctId() {
15520
+ return `mastra-${randomUUID()}`;
15521
+ }
15522
+ isHostnameDerivedDistinctId(distinctId) {
15523
+ return distinctId === `mastra-${os.hostname()}`;
15517
15524
  }
15518
15525
  getSystemProperties() {
15519
15526
  return {
@@ -15543,6 +15550,9 @@ var PosthogAnalytics = class _PosthogAnalytics {
15543
15550
  }
15544
15551
  });
15545
15552
  }
15553
+ getDistinctId() {
15554
+ return this.distinctId;
15555
+ }
15546
15556
  trackEvent(eventName, properties) {
15547
15557
  try {
15548
15558
  if (!this.client) {
@@ -15773,7 +15783,7 @@ var PinoLogger = class _PinoLogger extends MastraLogger {
15773
15783
  };
15774
15784
 
15775
15785
  var package_default = {
15776
- version: "1.12.3-alpha.3"};
15786
+ version: "1.13.0"};
15777
15787
  var logger = createLogger(false);
15778
15788
  function createLogger(debug = false) {
15779
15789
  return new PinoLogger({