pixelplay 1.0.11 → 1.0.15

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/server.d.mts CHANGED
@@ -193,14 +193,14 @@ declare const darkTheme: ThemeTokens;
193
193
  declare function generateThemeCSS(): string;
194
194
 
195
195
  /**
196
- * PixelPlay UI — License validation + activation via Polar.sh customer-portal API.
196
+ * PixelPlay UI — License validation via Polar.sh customer-portal API.
197
197
  *
198
- * Flow:
199
- * 1. First run activate the key (registers this project as an activation instance)
200
- * 2. Subsequent runs validate the key with the stored activation ID
201
- * 3. Activation ID is persisted in node_modules/.cache/pixelplay/activation.json
198
+ * Behaviour:
199
+ * - Development (`next dev`): console warning if no key, components work fine.
200
+ * - Production build (`next build`): validates key against Polar API.
201
+ * Build fails if the key is missing, invalid, or revoked.
202
202
  *
203
- * This uses the public customer-portal endpoints (no auth token required).
203
+ * This uses the public customer-portal endpoint (no auth token required).
204
204
  */
205
205
  interface InitOptions {
206
206
  /** The customer's license key (from PIXELPLAY_LICENSE_KEY env var) */
@@ -209,17 +209,15 @@ interface InitOptions {
209
209
  /**
210
210
  * Initialise PixelPlay and validate the license key.
211
211
  *
212
- * Call this once in your root layout (server component):
212
+ * Call this once at the top of your root layout (server component):
213
213
  * ```ts
214
214
  * import { initPixelPlay } from "pixelplay/server";
215
215
  * initPixelPlay({ licenseKey: process.env.PIXELPLAY_LICENSE_KEY });
216
216
  * ```
217
217
  *
218
- * On first run, the key is activated (counts toward the activation limit).
219
- * On subsequent runs, the stored activation is validated.
220
- * If the key is missing or invalid, a console warning is logged.
221
- * Components continue to work regardless.
218
+ * In development: logs a warning if no key components still work.
219
+ * In production builds: validates the key and fails the build if invalid.
222
220
  */
223
- declare function initPixelPlay(options?: InitOptions): void;
221
+ declare function initPixelPlay(options?: InitOptions): Promise<void>;
224
222
 
225
223
  export { type ThemeTokens, darkTheme, generateThemeCSS, initPixelPlay, lightTheme };
package/dist/server.d.ts CHANGED
@@ -193,14 +193,14 @@ declare const darkTheme: ThemeTokens;
193
193
  declare function generateThemeCSS(): string;
194
194
 
195
195
  /**
196
- * PixelPlay UI — License validation + activation via Polar.sh customer-portal API.
196
+ * PixelPlay UI — License validation via Polar.sh customer-portal API.
197
197
  *
198
- * Flow:
199
- * 1. First run activate the key (registers this project as an activation instance)
200
- * 2. Subsequent runs validate the key with the stored activation ID
201
- * 3. Activation ID is persisted in node_modules/.cache/pixelplay/activation.json
198
+ * Behaviour:
199
+ * - Development (`next dev`): console warning if no key, components work fine.
200
+ * - Production build (`next build`): validates key against Polar API.
201
+ * Build fails if the key is missing, invalid, or revoked.
202
202
  *
203
- * This uses the public customer-portal endpoints (no auth token required).
203
+ * This uses the public customer-portal endpoint (no auth token required).
204
204
  */
205
205
  interface InitOptions {
206
206
  /** The customer's license key (from PIXELPLAY_LICENSE_KEY env var) */
@@ -209,17 +209,15 @@ interface InitOptions {
209
209
  /**
210
210
  * Initialise PixelPlay and validate the license key.
211
211
  *
212
- * Call this once in your root layout (server component):
212
+ * Call this once at the top of your root layout (server component):
213
213
  * ```ts
214
214
  * import { initPixelPlay } from "pixelplay/server";
215
215
  * initPixelPlay({ licenseKey: process.env.PIXELPLAY_LICENSE_KEY });
216
216
  * ```
217
217
  *
218
- * On first run, the key is activated (counts toward the activation limit).
219
- * On subsequent runs, the stored activation is validated.
220
- * If the key is missing or invalid, a console warning is logged.
221
- * Components continue to work regardless.
218
+ * In development: logs a warning if no key components still work.
219
+ * In production builds: validates the key and fails the build if invalid.
222
220
  */
223
- declare function initPixelPlay(options?: InitOptions): void;
221
+ declare function initPixelPlay(options?: InitOptions): Promise<void>;
224
222
 
225
223
  export { type ThemeTokens, darkTheme, generateThemeCSS, initPixelPlay, lightTheme };
package/dist/server.js CHANGED
@@ -1580,118 +1580,66 @@ ${globalsVars}
1580
1580
  }
1581
1581
 
1582
1582
  // src/license.ts
1583
- var import_fs = require("fs");
1584
- var import_path = require("path");
1585
1583
  var POLAR_ORG_ID = "0f5f2ec4-1ce3-4e23-8099-c3d77aadb8cf";
1586
- var ACTIVATE_URL = "https://api.polar.sh/v1/customer-portal/license-keys/activate";
1587
1584
  var VALIDATE_URL = "https://api.polar.sh/v1/customer-portal/license-keys/validate";
1588
- var CACHE_DIR = (0, import_path.resolve)(process.cwd(), "node_modules", ".cache", "pixelplay");
1589
- var ACTIVATION_FILE = (0, import_path.resolve)(CACHE_DIR, "activation.json");
1590
1585
  var initialised = false;
1591
- function initPixelPlay(options) {
1586
+ async function initPixelPlay(options) {
1592
1587
  if (initialised) return;
1593
1588
  initialised = true;
1594
1589
  const key = options == null ? void 0 : options.licenseKey;
1590
+ const isProduction = process.env.NODE_ENV === "production";
1595
1591
  if (!key) {
1592
+ if (isProduction) {
1593
+ throw new Error(
1594
+ "\n\n\u{1F6AB} PixelPlay UI \u2014 Build failed: No license key provided.\n Set PIXELPLAY_LICENSE_KEY in your environment variables.\n Purchase a license at https://dennisisaac.com/ui-kit/pricing\n"
1595
+ );
1596
+ }
1596
1597
  console.warn(
1597
- "\n\u26A0\uFE0F PixelPlay UI \u2014 No license key provided.\n Components will still work, but please purchase a license at\n https://dennisisaac.com/ui-kit/pricing\n Then add PIXELPLAY_LICENSE_KEY to your environment variables.\n"
1598
- );
1599
- return;
1600
- }
1601
- activateOrValidate(key).catch(() => {
1602
- });
1603
- }
1604
- function loadActivation() {
1605
- try {
1606
- const raw = (0, import_fs.readFileSync)(ACTIVATION_FILE, "utf-8");
1607
- const data = JSON.parse(raw);
1608
- if ((data == null ? void 0 : data.activationId) && (data == null ? void 0 : data.key)) return data;
1609
- } catch (e) {
1610
- }
1611
- return null;
1612
- }
1613
- function saveActivation(activation) {
1614
- try {
1615
- (0, import_fs.mkdirSync)(CACHE_DIR, { recursive: true });
1616
- (0, import_fs.writeFileSync)(
1617
- ACTIVATION_FILE,
1618
- JSON.stringify(activation, null, 2),
1619
- "utf-8"
1598
+ "\n\u26A0\uFE0F PixelPlay UI \u2014 No license key provided.\n Components will work in development, but production builds require a valid key.\n Purchase a license at https://dennisisaac.com/ui-kit/pricing\n"
1620
1599
  );
1621
- } catch (e) {
1622
- }
1623
- }
1624
- async function activateOrValidate(key) {
1625
- const stored = loadActivation();
1626
- if (stored && stored.key === key) {
1627
- await validateKey(key, stored.activationId);
1628
1600
  return;
1629
1601
  }
1630
- await activateKey(key);
1631
- }
1632
- async function activateKey(key) {
1633
- try {
1634
- const res = await fetch(ACTIVATE_URL, {
1635
- method: "POST",
1636
- headers: { "Content-Type": "application/json" },
1637
- body: JSON.stringify({
1638
- key,
1639
- organization_id: POLAR_ORG_ID,
1640
- label: `project:${process.cwd()}`
1641
- })
1602
+ if (!isProduction) {
1603
+ validateKey(key, false).catch(() => {
1642
1604
  });
1643
- if (!res.ok) {
1644
- const status = res.status;
1645
- if (status === 404 || status === 422) {
1646
- console.warn(
1647
- "\n\u26A0\uFE0F PixelPlay UI \u2014 Invalid license key.\n The provided PIXELPLAY_LICENSE_KEY could not be validated.\n Please check your key or purchase a license at\n https://dennisisaac.com/ui-kit/pricing\n"
1648
- );
1649
- return;
1650
- }
1651
- if (status === 403) {
1652
- console.warn(
1653
- "\n\u26A0\uFE0F PixelPlay UI \u2014 Activation limit reached.\n This license key has been activated on the maximum number of projects.\n Deactivate an existing project at https://polar.sh or upgrade your plan.\n"
1654
- );
1655
- return;
1656
- }
1657
- return;
1658
- }
1659
- const data = await res.json();
1660
- saveActivation({ activationId: data.id, key });
1661
- } catch (e) {
1605
+ return;
1662
1606
  }
1607
+ await validateKey(key, true);
1663
1608
  }
1664
- async function validateKey(key, activationId) {
1609
+ async function validateKey(key, throwOnError) {
1665
1610
  try {
1666
1611
  const res = await fetch(VALIDATE_URL, {
1667
1612
  method: "POST",
1668
1613
  headers: { "Content-Type": "application/json" },
1669
1614
  body: JSON.stringify({
1670
1615
  key,
1671
- organization_id: POLAR_ORG_ID,
1672
- activation_id: activationId
1616
+ organization_id: POLAR_ORG_ID
1673
1617
  })
1674
1618
  });
1675
1619
  if (!res.ok) {
1676
1620
  const status = res.status;
1677
1621
  if (status === 404 || status === 422) {
1678
- saveActivation({ activationId: "", key: "" });
1679
- await activateKey(key);
1622
+ const msg = "\n\u{1F6AB} PixelPlay UI \u2014 Invalid license key.\n The provided PIXELPLAY_LICENSE_KEY could not be validated.\n Please check your key or purchase a license at\n https://dennisisaac.com/ui-kit/pricing\n";
1623
+ if (throwOnError) throw new Error(msg);
1624
+ console.warn("\u26A0\uFE0F " + msg);
1680
1625
  return;
1681
1626
  }
1682
1627
  return;
1683
1628
  }
1684
1629
  const data = await res.json();
1685
1630
  if (data.status === "revoked" || data.status === "disabled") {
1686
- console.warn(
1687
- `
1688
- \u26A0\uFE0F PixelPlay UI \u2014 License key has been ${data.status}.
1631
+ const msg = `
1632
+ \u{1F6AB} PixelPlay UI \u2014 License key has been ${data.status}.
1689
1633
  Please contact support or purchase a new license at
1690
1634
  https://dennisisaac.com/ui-kit/pricing
1691
- `
1692
- );
1635
+ `;
1636
+ if (throwOnError) throw new Error(msg);
1637
+ console.warn("\u26A0\uFE0F " + msg);
1638
+ }
1639
+ } catch (err) {
1640
+ if (err instanceof Error && err.message.includes("PixelPlay UI")) {
1641
+ throw err;
1693
1642
  }
1694
- } catch (e) {
1695
1643
  }
1696
1644
  }
1697
1645
  // Annotate the CommonJS export names for ESM import in node: