tetrons 2.3.81 → 2.3.83

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.
@@ -3,6 +3,7 @@ import { MathInline } from "./extensions/MathExtension";
3
3
  import React, { useEffect, useRef, useState } from "react";
4
4
  import { useEditor, EditorContent as TiptapEditorContent } from "@tiptap/react";
5
5
  import type { AddOn } from "./toolbar/TetronsToolbar";
6
+ import { getActivePlan, Plan } from "../../utils/licenseTracker";
6
7
 
7
8
  import Document from "@tiptap/extension-document";
8
9
  import Paragraph from "@tiptap/extension-paragraph";
@@ -37,7 +38,6 @@ import { createLowlight } from "lowlight";
37
38
 
38
39
  import { useTypo } from "../../utils/useTypo";
39
40
  import { Spellcheck } from "./extensions/Spellcheck";
40
-
41
41
  import { Comment } from "./toolbar/extensions/Comment";
42
42
  import { Subscript } from "./toolbar/marks/Subscript";
43
43
  import { Superscript } from "./toolbar/marks/Superscript";
@@ -87,9 +87,21 @@ export default function EditorContent({ apiKey }: EditorContentProps) {
87
87
 
88
88
  if (!res.ok) throw new Error(data.error || "Invalid API Key");
89
89
 
90
+ const version =
91
+ data.version &&
92
+ ["free", "pro", "premium", "platinum"].includes(data.version)
93
+ ? (data.version as Plan)
94
+ : "free";
95
+
96
+ const activeVersion = getActivePlan(version);
97
+
90
98
  setIsValid(true);
91
- setUserVersion(data.version);
99
+ setUserVersion(activeVersion);
92
100
  setAddOns(data.addOn || []);
101
+
102
+ if (activeVersion === "free" && data.version !== "free") {
103
+ setError("Your paid plan has expired. Downgraded to Free version.");
104
+ }
93
105
  } catch (err: unknown) {
94
106
  setError(err instanceof Error ? err.message : "Invalid API Key");
95
107
  setIsValid(false);
package/dist/index.cjs CHANGED
@@ -263,6 +263,43 @@ var MathInline = import_core.Node.create({
263
263
  var import_react24 = __toESM(require("react"));
264
264
  var import_react25 = require("@tiptap/react");
265
265
 
266
+ // src/utils/licenseTracker.ts
267
+ var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
268
+ var PLAN_DURATIONS = {
269
+ free: Infinity,
270
+ pro: 30,
271
+ premium: 30,
272
+ platinum: 30
273
+ };
274
+ function initLicenseTracking(plan) {
275
+ if (typeof window === "undefined") return;
276
+ const key = getLicenseKey(plan);
277
+ const now = Date.now();
278
+ const stored = localStorage.getItem(key);
279
+ if (!stored) {
280
+ localStorage.setItem(key, now.toString());
281
+ }
282
+ }
283
+ function getActivePlan(plan) {
284
+ if (typeof window === "undefined") return plan;
285
+ if (plan === "free") return "free";
286
+ const key = getLicenseKey(plan);
287
+ const stored = localStorage.getItem(key);
288
+ if (!stored) return "free";
289
+ const startedAt = parseInt(stored, 10);
290
+ const now = Date.now();
291
+ const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
292
+ const allowedDays = PLAN_DURATIONS[plan];
293
+ if (diffDays > allowedDays) {
294
+ localStorage.removeItem(key);
295
+ return "free";
296
+ }
297
+ return plan;
298
+ }
299
+ function isLicenseValid(plan) {
300
+ return getActivePlan(plan) === plan;
301
+ }
302
+
266
303
  // node_modules/@tiptap/extension-document/dist/index.js
267
304
  var import_core2 = require("@tiptap/core");
268
305
  var Document = import_core2.Node.create({
@@ -17140,9 +17177,14 @@ function EditorContent({ apiKey }) {
17140
17177
  const res = await fetch(`${API_BASE_URL}/api/api-key?apiKey=${apiKey}`);
17141
17178
  const data = await res.json();
17142
17179
  if (!res.ok) throw new Error(data.error || "Invalid API Key");
17180
+ const version = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
17181
+ const activeVersion = getActivePlan(version);
17143
17182
  setIsValid(true);
17144
- setUserVersion(data.version);
17183
+ setUserVersion(activeVersion);
17145
17184
  setAddOns(data.addOn || []);
17185
+ if (activeVersion === "free" && data.version !== "free") {
17186
+ setError("Your paid plan has expired. Downgraded to Free version.");
17187
+ }
17146
17188
  } catch (err) {
17147
17189
  setError(err instanceof Error ? err.message : "Invalid API Key");
17148
17190
  setIsValid(false);
@@ -17275,38 +17317,9 @@ function EditorContent({ apiKey }) {
17275
17317
  ));
17276
17318
  }
17277
17319
 
17278
- // src/utils/licenseTracker.ts
17279
- var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
17280
- var PLAN_DURATIONS = {
17281
- free: 14,
17282
- pro: 30,
17283
- premium: 30,
17284
- platinum: 30
17285
- };
17286
- function initLicenseTracking(plan) {
17287
- if (typeof window === "undefined") return;
17288
- const key = getLicenseKey(plan);
17289
- const now = Date.now();
17290
- const stored = localStorage.getItem(key);
17291
- if (!stored) {
17292
- localStorage.setItem(key, now.toString());
17293
- }
17294
- }
17295
- function isLicenseValid(plan) {
17296
- if (typeof window === "undefined") return true;
17297
- const key = getLicenseKey(plan);
17298
- const stored = localStorage.getItem(key);
17299
- if (!stored) return false;
17300
- const startedAt = parseInt(stored, 10);
17301
- const now = Date.now();
17302
- const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
17303
- const allowedDays = PLAN_DURATIONS[plan];
17304
- return diffDays <= allowedDays;
17305
- }
17306
-
17307
17320
  // src/index.ts
17308
17321
  var API_VALID = false;
17309
- var API_VERSION = "";
17322
+ var API_VERSION = null;
17310
17323
  var API_ADDONS = [];
17311
17324
  async function initializeTetrons(apiKey) {
17312
17325
  const res = await fetch(
@@ -17318,9 +17331,9 @@ async function initializeTetrons(apiKey) {
17318
17331
  }
17319
17332
  const data = await res.json();
17320
17333
  API_VALID = true;
17321
- API_VERSION = data.version;
17334
+ API_VERSION = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
17322
17335
  API_ADDONS = data.addOn || [];
17323
- if (typeof window !== "undefined") {
17336
+ if (typeof window !== "undefined" && API_VERSION) {
17324
17337
  initLicenseTracking(API_VERSION);
17325
17338
  }
17326
17339
  }
package/dist/index.d.mts CHANGED
@@ -5,8 +5,10 @@ type EditorContentProps = {
5
5
  };
6
6
  declare function EditorContent({ apiKey }: EditorContentProps): React.JSX.Element;
7
7
 
8
+ type Plan = "free" | "pro" | "premium" | "platinum";
9
+
8
10
  declare function initializeTetrons(apiKey: string): Promise<void>;
9
- declare function getTetronsVersion(): "" | "free" | "pro" | "premium" | "platinum";
11
+ declare function getTetronsVersion(): Plan | null;
10
12
  declare function getTetronsAddOns(): string[];
11
13
  declare function isApiKeyValid(): boolean;
12
14
  declare function isTetronsLicenseValid(): boolean;
package/dist/index.d.ts CHANGED
@@ -5,8 +5,10 @@ type EditorContentProps = {
5
5
  };
6
6
  declare function EditorContent({ apiKey }: EditorContentProps): React.JSX.Element;
7
7
 
8
+ type Plan = "free" | "pro" | "premium" | "platinum";
9
+
8
10
  declare function initializeTetrons(apiKey: string): Promise<void>;
9
- declare function getTetronsVersion(): "" | "free" | "pro" | "premium" | "platinum";
11
+ declare function getTetronsVersion(): Plan | null;
10
12
  declare function getTetronsAddOns(): string[];
11
13
  declare function isApiKeyValid(): boolean;
12
14
  declare function isTetronsLicenseValid(): boolean;
package/dist/index.mjs CHANGED
@@ -227,6 +227,43 @@ var MathInline = Node.create({
227
227
  import React17, { useEffect as useEffect9, useRef as useRef7, useState as useState11 } from "react";
228
228
  import { useEditor, EditorContent as TiptapEditorContent } from "@tiptap/react";
229
229
 
230
+ // src/utils/licenseTracker.ts
231
+ var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
232
+ var PLAN_DURATIONS = {
233
+ free: Infinity,
234
+ pro: 30,
235
+ premium: 30,
236
+ platinum: 30
237
+ };
238
+ function initLicenseTracking(plan) {
239
+ if (typeof window === "undefined") return;
240
+ const key = getLicenseKey(plan);
241
+ const now = Date.now();
242
+ const stored = localStorage.getItem(key);
243
+ if (!stored) {
244
+ localStorage.setItem(key, now.toString());
245
+ }
246
+ }
247
+ function getActivePlan(plan) {
248
+ if (typeof window === "undefined") return plan;
249
+ if (plan === "free") return "free";
250
+ const key = getLicenseKey(plan);
251
+ const stored = localStorage.getItem(key);
252
+ if (!stored) return "free";
253
+ const startedAt = parseInt(stored, 10);
254
+ const now = Date.now();
255
+ const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
256
+ const allowedDays = PLAN_DURATIONS[plan];
257
+ if (diffDays > allowedDays) {
258
+ localStorage.removeItem(key);
259
+ return "free";
260
+ }
261
+ return plan;
262
+ }
263
+ function isLicenseValid(plan) {
264
+ return getActivePlan(plan) === plan;
265
+ }
266
+
230
267
  // node_modules/@tiptap/extension-document/dist/index.js
231
268
  import { Node as Node2 } from "@tiptap/core";
232
269
  var Document = Node2.create({
@@ -17149,9 +17186,14 @@ function EditorContent({ apiKey }) {
17149
17186
  const res = await fetch(`${API_BASE_URL}/api/api-key?apiKey=${apiKey}`);
17150
17187
  const data = await res.json();
17151
17188
  if (!res.ok) throw new Error(data.error || "Invalid API Key");
17189
+ const version = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
17190
+ const activeVersion = getActivePlan(version);
17152
17191
  setIsValid(true);
17153
- setUserVersion(data.version);
17192
+ setUserVersion(activeVersion);
17154
17193
  setAddOns(data.addOn || []);
17194
+ if (activeVersion === "free" && data.version !== "free") {
17195
+ setError("Your paid plan has expired. Downgraded to Free version.");
17196
+ }
17155
17197
  } catch (err) {
17156
17198
  setError(err instanceof Error ? err.message : "Invalid API Key");
17157
17199
  setIsValid(false);
@@ -17284,38 +17326,9 @@ function EditorContent({ apiKey }) {
17284
17326
  ));
17285
17327
  }
17286
17328
 
17287
- // src/utils/licenseTracker.ts
17288
- var getLicenseKey = (plan) => `__tetrons_license_start_${plan}__`;
17289
- var PLAN_DURATIONS = {
17290
- free: 14,
17291
- pro: 30,
17292
- premium: 30,
17293
- platinum: 30
17294
- };
17295
- function initLicenseTracking(plan) {
17296
- if (typeof window === "undefined") return;
17297
- const key = getLicenseKey(plan);
17298
- const now = Date.now();
17299
- const stored = localStorage.getItem(key);
17300
- if (!stored) {
17301
- localStorage.setItem(key, now.toString());
17302
- }
17303
- }
17304
- function isLicenseValid(plan) {
17305
- if (typeof window === "undefined") return true;
17306
- const key = getLicenseKey(plan);
17307
- const stored = localStorage.getItem(key);
17308
- if (!stored) return false;
17309
- const startedAt = parseInt(stored, 10);
17310
- const now = Date.now();
17311
- const diffDays = Math.floor((now - startedAt) / (1e3 * 60 * 60 * 24));
17312
- const allowedDays = PLAN_DURATIONS[plan];
17313
- return diffDays <= allowedDays;
17314
- }
17315
-
17316
17329
  // src/index.ts
17317
17330
  var API_VALID = false;
17318
- var API_VERSION = "";
17331
+ var API_VERSION = null;
17319
17332
  var API_ADDONS = [];
17320
17333
  async function initializeTetrons(apiKey) {
17321
17334
  const res = await fetch(
@@ -17327,9 +17340,9 @@ async function initializeTetrons(apiKey) {
17327
17340
  }
17328
17341
  const data = await res.json();
17329
17342
  API_VALID = true;
17330
- API_VERSION = data.version;
17343
+ API_VERSION = data.version && ["free", "pro", "premium", "platinum"].includes(data.version) ? data.version : "free";
17331
17344
  API_ADDONS = data.addOn || [];
17332
- if (typeof window !== "undefined") {
17345
+ if (typeof window !== "undefined" && API_VERSION) {
17333
17346
  initLicenseTracking(API_VERSION);
17334
17347
  }
17335
17348
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tetrons",
3
- "version": "2.3.81",
3
+ "version": "2.3.83",
4
4
  "description": "A Next.js project written in TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",