@mastra/auth-studio 1.3.7 → 1.3.8

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.cjs CHANGED
@@ -1,4 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let fs = require("fs");
3
+ let path = require("path");
2
4
  //#region ../../packages/_internals/auth/dist/types/index.js
3
5
  function headerFromPlainObject(headers, name) {
4
6
  const normalizedName = name.toLowerCase();
@@ -423,6 +425,26 @@ function resolvePermissionsFromMapping(roles, mapping) {
423
425
  //#endregion
424
426
  //#region src/index.ts
425
427
  const COOKIE_NAME = "wos-session";
428
+ const PROJECT_CONFIG_FILE = ".mastra-project.json";
429
+ /**
430
+ * Read `organizationId` from a project's `.mastra-project.json` in the current
431
+ * working directory. Used as a last-resort fallback when neither the constructor
432
+ * option nor `MASTRA_ORGANIZATION_ID` is set — the file is written by the CLI
433
+ * when a project is linked to a platform organization, so `mastra dev` /
434
+ * `mastra studio` should honor it locally without requiring the user to also
435
+ * export the env var. Failures (missing file, malformed JSON, unexpected shape)
436
+ * are swallowed silently: this is a best-effort fallback, not a hard dependency.
437
+ */
438
+ function readOrganizationIdFromProjectConfig() {
439
+ try {
440
+ const raw = (0, fs.readFileSync)((0, path.join)(process.cwd(), PROJECT_CONFIG_FILE), "utf-8");
441
+ const parsed = JSON.parse(raw);
442
+ if (parsed && typeof parsed === "object" && "organizationId" in parsed) {
443
+ const value = parsed.organizationId;
444
+ if (typeof value === "string" && value.length > 0) return value;
445
+ }
446
+ } catch {}
447
+ }
426
448
  /**
427
449
  * Upper bound for shared-API verification fetches. Matches the platform API
428
450
  * client's request budget: a slow shared API must fail a single request in
@@ -485,7 +507,7 @@ var MastraAuthStudio = class extends MastraAuthProvider {
485
507
  });
486
508
  const explicitSharedApiUrl = options?.sharedApiUrl || process.env.MASTRA_SHARED_API_URL;
487
509
  this.sharedApiUrl = explicitSharedApiUrl || "https://platform.mastra.ai/v1";
488
- this.organizationId = options?.organizationId || process.env.MASTRA_ORGANIZATION_ID;
510
+ this.organizationId = options?.organizationId || process.env.MASTRA_ORGANIZATION_ID || readOrganizationIdFromProjectConfig();
489
511
  if (this.sharedApiUrl.endsWith("/")) this.sharedApiUrl = this.sharedApiUrl.slice(0, -1);
490
512
  this.cookieDomain = options?.cookieDomain || process.env.MASTRA_COOKIE_DOMAIN;
491
513
  let autoDetectMastraAi = false;