@motor-hero/ui-kit 0.37.0 → 0.37.2

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.
@@ -1,10 +1,27 @@
1
1
  export type UseCompanySubdomainOptions = {
2
2
  enableOverride?: boolean;
3
3
  overrideStorageKey?: string;
4
+ /**
5
+ * Host labels that are *not* tenants. A product whose default host carries
6
+ * a label of its own (`app.example.com`, `admin.example.com`) must list it
7
+ * here, or that label is read as a tenant slug and sent downstream as one.
8
+ *
9
+ * Added to the built-in `www`; `localhost` is always excluded structurally.
10
+ * Case-insensitive.
11
+ */
12
+ reservedSubdomains?: string[];
4
13
  };
5
14
  export type UseCompanySubdomainResult = {
6
15
  subdomain: string | undefined;
7
16
  };
8
- export declare function getSubdomain(hostname: string): string | undefined;
17
+ /**
18
+ * The tenant slug in a hostname, or `undefined` when there is none.
19
+ *
20
+ * The first label is only a tenant if it isn't reserved. Callers whose
21
+ * default host is `app.<domain>` must pass `["app"]` (plus any sibling
22
+ * surfaces like `admin`), otherwise visiting the default host yields the
23
+ * literal `"app"` as if it were a customer.
24
+ */
25
+ export declare function getSubdomain(hostname: string, reservedSubdomains?: string[]): string | undefined;
9
26
  export declare function useCompanySubdomain(opts?: UseCompanySubdomainOptions): UseCompanySubdomainResult;
10
27
  //# sourceMappingURL=use-company-subdomain.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-company-subdomain.d.ts","sourceRoot":"","sources":["../../src/hooks/use-company-subdomain.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,CAAA;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMjE;AAiBD,wBAAgB,mBAAmB,CACjC,IAAI,GAAE,0BAA+B,GACpC,yBAAyB,CAc3B"}
1
+ {"version":3,"file":"use-company-subdomain.d.ts","sourceRoot":"","sources":["../../src/hooks/use-company-subdomain.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,CAAA;AAID;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,kBAAkB,GAAE,MAAM,EAAO,GAChC,MAAM,GAAG,SAAS,CAUpB;AAiBD,wBAAgB,mBAAmB,CACjC,IAAI,GAAE,0BAA+B,GACpC,yBAAyB,CAiB3B"}
package/dist/index.cjs CHANGED
@@ -1567,7 +1567,7 @@ function FormField({ label, htmlFor, error, required, children, className }) {
1567
1567
  "label",
1568
1568
  {
1569
1569
  htmlFor,
1570
- className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
1570
+ className: "block text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
1571
1571
  children: [
1572
1572
  label,
1573
1573
  required && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "ml-1 text-destructive", children: "*" })
@@ -2427,11 +2427,16 @@ function Toaster(props) {
2427
2427
 
2428
2428
  // src/hooks/use-company-subdomain.ts
2429
2429
  var import_react8 = require("react");
2430
- function getSubdomain(hostname) {
2430
+ var ALWAYS_RESERVED = ["www", "localhost"];
2431
+ function getSubdomain(hostname, reservedSubdomains = []) {
2431
2432
  const labels = hostname.split(".");
2432
2433
  if (labels.length < 2) return void 0;
2433
2434
  const first = labels[0];
2434
- if (!first || first === "www" || first === "localhost") return void 0;
2435
+ if (!first) return void 0;
2436
+ const reserved = [...ALWAYS_RESERVED, ...reservedSubdomains].map(
2437
+ (label) => label.toLowerCase()
2438
+ );
2439
+ if (reserved.includes(first.toLowerCase())) return void 0;
2435
2440
  return first;
2436
2441
  }
2437
2442
  function resolveOverride(storageKey) {
@@ -2449,14 +2454,18 @@ function resolveOverride(storageKey) {
2449
2454
  return window.localStorage.getItem(storageKey) ?? void 0;
2450
2455
  }
2451
2456
  function useCompanySubdomain(opts = {}) {
2452
- const { enableOverride = false, overrideStorageKey = "company-subdomain" } = opts;
2457
+ const {
2458
+ enableOverride = false,
2459
+ overrideStorageKey = "company-subdomain",
2460
+ reservedSubdomains = []
2461
+ } = opts;
2453
2462
  const [subdomain] = (0, import_react8.useState)(() => {
2454
2463
  if (enableOverride) {
2455
2464
  const override = resolveOverride(overrideStorageKey);
2456
2465
  if (override) return override;
2457
2466
  }
2458
2467
  if (typeof window === "undefined") return void 0;
2459
- return getSubdomain(window.location.hostname);
2468
+ return getSubdomain(window.location.hostname, reservedSubdomains);
2460
2469
  });
2461
2470
  return { subdomain };
2462
2471
  }