@usertour/helpers 0.0.9 → 0.0.11

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,23 +0,0 @@
1
- import { ContentPriority, RulesCondition, RulesType, SDKContent, BizEvent, BizSession } from '@usertour/types';
2
-
3
- declare const PRIORITIES: ContentPriority[];
4
- declare const isVisible: (el: HTMLElement) => Promise<boolean>;
5
- type RewriteRulesCondition = Partial<Record<RulesType, boolean>>;
6
- declare const activedRulesConditions: (conditions: RulesCondition[], rewrite?: RewriteRulesCondition) => Promise<RulesCondition[]>;
7
- declare const activedContentRulesConditions: (conditions: RulesCondition[], contents: SDKContent[]) => Promise<RulesCondition[]>;
8
- declare const activedContentCondition: (contents: SDKContent[]) => Promise<SDKContent[]>;
9
- declare const isActive: (autoStartRules: RulesCondition[]) => boolean;
10
- declare const isActiveContent: (content: SDKContent) => boolean;
11
- declare const filterAutoStartContent: (contents: SDKContent[], type: string) => SDKContent[];
12
- declare const isHasActivedContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
13
- declare const isSameContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
14
- declare const findLatestEvent: (bizEvents: BizEvent[]) => BizEvent;
15
- declare const checklistIsDimissed: (latestSession?: BizSession) => BizEvent | undefined;
16
- declare const flowIsDismissed: (latestSession?: BizSession) => BizEvent | undefined;
17
- declare const flowIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
18
- declare const checklistIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
19
- declare const isValidContent: (content: SDKContent, contents: SDKContent[]) => boolean;
20
- declare const parseUrlParams: (url: string, paramName: string) => string | null;
21
- declare const wait: (seconds: number) => Promise<void>;
22
-
23
- export { PRIORITIES, activedContentCondition, activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveContent, isHasActivedContents, isSameContents, isValidContent, isVisible, parseUrlParams, wait };
@@ -1,23 +0,0 @@
1
- import { ContentPriority, RulesCondition, RulesType, SDKContent, BizEvent, BizSession } from '@usertour/types';
2
-
3
- declare const PRIORITIES: ContentPriority[];
4
- declare const isVisible: (el: HTMLElement) => Promise<boolean>;
5
- type RewriteRulesCondition = Partial<Record<RulesType, boolean>>;
6
- declare const activedRulesConditions: (conditions: RulesCondition[], rewrite?: RewriteRulesCondition) => Promise<RulesCondition[]>;
7
- declare const activedContentRulesConditions: (conditions: RulesCondition[], contents: SDKContent[]) => Promise<RulesCondition[]>;
8
- declare const activedContentCondition: (contents: SDKContent[]) => Promise<SDKContent[]>;
9
- declare const isActive: (autoStartRules: RulesCondition[]) => boolean;
10
- declare const isActiveContent: (content: SDKContent) => boolean;
11
- declare const filterAutoStartContent: (contents: SDKContent[], type: string) => SDKContent[];
12
- declare const isHasActivedContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
13
- declare const isSameContents: (source: SDKContent[], dest: SDKContent[]) => boolean;
14
- declare const findLatestEvent: (bizEvents: BizEvent[]) => BizEvent;
15
- declare const checklistIsDimissed: (latestSession?: BizSession) => BizEvent | undefined;
16
- declare const flowIsDismissed: (latestSession?: BizSession) => BizEvent | undefined;
17
- declare const flowIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
18
- declare const checklistIsSeen: (latestSession?: BizSession) => BizEvent | undefined;
19
- declare const isValidContent: (content: SDKContent, contents: SDKContent[]) => boolean;
20
- declare const parseUrlParams: (url: string, paramName: string) => string | null;
21
- declare const wait: (seconds: number) => Promise<void>;
22
-
23
- export { PRIORITIES, activedContentCondition, activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveContent, isHasActivedContents, isSameContents, isValidContent, isVisible, parseUrlParams, wait };
@@ -1,45 +0,0 @@
1
- import {
2
- PRIORITIES,
3
- activedContentCondition,
4
- activedContentRulesConditions,
5
- activedRulesConditions,
6
- checklistIsDimissed,
7
- checklistIsSeen,
8
- filterAutoStartContent,
9
- findLatestEvent,
10
- flowIsDismissed,
11
- flowIsSeen,
12
- isActive,
13
- isActiveContent,
14
- isHasActivedContents,
15
- isSameContents,
16
- isValidContent,
17
- isVisible,
18
- parseUrlParams,
19
- wait
20
- } from "./chunk-7IK5Q5N2.js";
21
- import "./chunk-DEG6MTU7.js";
22
- import "./chunk-Y6FPPOKF.js";
23
- import "./chunk-H7VA3ML2.js";
24
- import "./chunk-FNQIIEWK.js";
25
- import "./chunk-XEO3YXBM.js";
26
- export {
27
- PRIORITIES,
28
- activedContentCondition,
29
- activedContentRulesConditions,
30
- activedRulesConditions,
31
- checklistIsDimissed,
32
- checklistIsSeen,
33
- filterAutoStartContent,
34
- findLatestEvent,
35
- flowIsDismissed,
36
- flowIsSeen,
37
- isActive,
38
- isActiveContent,
39
- isHasActivedContents,
40
- isSameContents,
41
- isValidContent,
42
- isVisible,
43
- parseUrlParams,
44
- wait
45
- };
package/dist/finderx.cjs DELETED
@@ -1,346 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/finderx.ts
21
- var finderx_exports = {};
22
- __export(finderx_exports, {
23
- finder: () => finder,
24
- finderV2: () => finderV2,
25
- finderX: () => finderX,
26
- parserV2: () => parserV2,
27
- parserX: () => parserX
28
- });
29
- module.exports = __toCommonJS(finderx_exports);
30
- var import_finder = require("@medv/finder");
31
- var finderAttrs = [
32
- "data-for",
33
- "data-id",
34
- "data-testid",
35
- "data-test-id",
36
- "for",
37
- "id",
38
- "name",
39
- "placeholder",
40
- "role"
41
- ];
42
- var defaultConfig = {
43
- idName: () => false,
44
- className: () => false,
45
- tagName: () => false,
46
- attr: () => false,
47
- seedMinLength: 1,
48
- optimizedMinLength: 2,
49
- threshold: 1e3,
50
- maxNumberOfTries: 1e4
51
- };
52
- var finderConfigs = [
53
- {
54
- ...defaultConfig,
55
- tagName: () => true
56
- },
57
- {
58
- ...defaultConfig,
59
- idName: () => true
60
- },
61
- {
62
- ...defaultConfig,
63
- tagName: () => true,
64
- attr: (name) => finderAttrs.includes(name)
65
- },
66
- {
67
- ...defaultConfig,
68
- className: () => true,
69
- attr: (name) => finderAttrs.includes(name)
70
- },
71
- {
72
- ...defaultConfig,
73
- tagName: () => true,
74
- idName: () => true,
75
- className: () => true,
76
- attr: () => false
77
- },
78
- {
79
- ...defaultConfig,
80
- tagName: () => true,
81
- idName: () => true,
82
- className: () => true,
83
- attr: (name) => finderAttrs.includes(name)
84
- }
85
- ];
86
- function getMaxDepth(node) {
87
- if (node.parentNode) {
88
- return getMaxDepth(node.parentNode);
89
- }
90
- return node.depth;
91
- }
92
- function queryNodeListBySelectors(selectors, rootDocument, removeRepeat = true) {
93
- const nodes = [];
94
- if (!selectors) {
95
- return nodes;
96
- }
97
- for (const s of selectors) {
98
- const els = rootDocument.querySelectorAll(s.replace(/\\\\/g, "\\"));
99
- if (els && els.length > 0) {
100
- nodes.push(...Array.from(els));
101
- }
102
- }
103
- return removeRepeat ? [...new Set(nodes)] : nodes;
104
- }
105
- function findMostRecurringNode(nodes) {
106
- const m = /* @__PURE__ */ new Map();
107
- let finalNode = nodes[0];
108
- let count = 0;
109
- for (const node of nodes) {
110
- const i = m.get(node) ? m.get(node) + 1 : 1;
111
- m.set(node, i);
112
- }
113
- m.forEach((value, key) => {
114
- if (value > count) {
115
- count = value;
116
- finalNode = key;
117
- }
118
- });
119
- return finalNode;
120
- }
121
- function compareParentNode(node, el, rootDocument, isCompareSibings = false) {
122
- let nodeParentNode = node.parentNode;
123
- let elParentElement = el.parentElement;
124
- const maxDepth = getMaxDepth(node);
125
- const xresult = {
126
- maxDepth,
127
- failedDepth: 0,
128
- success: true
129
- };
130
- while (nodeParentNode && elParentElement) {
131
- if (elParentElement === rootDocument) {
132
- break;
133
- }
134
- if (elParentElement === document.body || elParentElement === document.documentElement || elParentElement.parentElement === document.body) {
135
- break;
136
- }
137
- const parentNodes = queryNodeListBySelectors(nodeParentNode.selectors, rootDocument);
138
- const isMatchSibings = isCompareSibings ? compareSibingsNode(nodeParentNode, elParentElement, rootDocument) : true;
139
- if (!parentNodes || parentNodes.length === 0 || !parentNodes.includes(elParentElement) || !isMatchSibings) {
140
- xresult.failedDepth = nodeParentNode.depth;
141
- xresult.success = false;
142
- }
143
- nodeParentNode = nodeParentNode.parentNode;
144
- elParentElement = elParentElement.parentElement;
145
- }
146
- return xresult;
147
- }
148
- function compareSibingsNode(node, el, rootDocument) {
149
- let isMatchNext = true;
150
- let isMatchPrevious = true;
151
- const { previousElementSelectors, nextElementSelectors } = node;
152
- if (nextElementSelectors && nextElementSelectors.length > 0) {
153
- const nextElementSiblings = queryNodeListBySelectors(nextElementSelectors, rootDocument);
154
- isMatchNext = el.nextElementSibling && nextElementSiblings.includes(el.nextElementSibling);
155
- }
156
- if (previousElementSelectors && previousElementSelectors.length > 0) {
157
- const previousElementSiblings = queryNodeListBySelectors(
158
- previousElementSelectors,
159
- rootDocument
160
- );
161
- isMatchPrevious = el.previousElementSibling && previousElementSiblings.includes(el.previousElementSibling);
162
- }
163
- return isMatchNext && isMatchPrevious;
164
- }
165
- function queryElementSelectors(input) {
166
- const classes = Array.from(input.classList);
167
- const selectors = [];
168
- const configs = [...finderConfigs];
169
- for (const className of classes) {
170
- configs.push({
171
- ...defaultConfig,
172
- className: (name) => {
173
- if (classes.filter((cn) => cn !== className).includes(name)) {
174
- return false;
175
- }
176
- return true;
177
- }
178
- });
179
- }
180
- try {
181
- for (const cfg of configs) {
182
- selectors.push(finder(input, cfg));
183
- }
184
- } catch (_) {
185
- return selectors;
186
- }
187
- return [...new Set(selectors)];
188
- }
189
- function parseSelectorsTree(input, parentNode, depth = 0) {
190
- const selectors = queryElementSelectors(input);
191
- if (selectors.length === 0) {
192
- return parentNode;
193
- }
194
- const currentNode = {
195
- previousElementSelectors: [],
196
- nextElementSelectors: [],
197
- selectors,
198
- depth
199
- };
200
- if (input.previousElementSibling) {
201
- currentNode.previousElementSelectors = queryElementSelectors(input.previousElementSibling);
202
- }
203
- if (input.nextElementSibling) {
204
- currentNode.nextElementSelectors = queryElementSelectors(input.nextElementSibling);
205
- }
206
- if (parentNode === null) {
207
- if (input.parentElement) {
208
- parseSelectorsTree(input.parentElement, currentNode, depth + 1);
209
- }
210
- return currentNode;
211
- }
212
- parentNode.parentNode = currentNode;
213
- if (input.parentElement) {
214
- parseSelectorsTree(input.parentElement, currentNode, depth + 1);
215
- }
216
- return parentNode;
217
- }
218
- function finderMostPrecisionElement(elements, node, rootDocument, precision) {
219
- const successEls = [];
220
- let failedData = {
221
- el: null,
222
- failedDepth: 0,
223
- maxDepth: 0
224
- };
225
- for (const el of elements) {
226
- const { success, failedDepth, maxDepth } = compareParentNode(node, el, rootDocument);
227
- if (success) {
228
- successEls.push(el);
229
- } else if (!failedData.el || failedDepth > failedData.failedDepth) {
230
- failedData = { el, failedDepth, maxDepth };
231
- }
232
- }
233
- if (successEls.length === 1) {
234
- return successEls[0];
235
- }
236
- if (successEls.length > 1) {
237
- let tempEl = successEls[0];
238
- let tempFailedDepth = 0;
239
- for (const el of successEls) {
240
- const { success, failedDepth } = compareParentNode(node, el, rootDocument, true);
241
- if (success) {
242
- return el;
243
- }
244
- if (failedDepth > tempFailedDepth) {
245
- tempFailedDepth = failedDepth;
246
- tempEl = el;
247
- }
248
- }
249
- return tempEl;
250
- }
251
- if (failedData.el) {
252
- const { failedDepth, maxDepth, el } = failedData;
253
- const rate = (failedDepth - 1) / maxDepth * 10;
254
- if (rate >= precision) {
255
- return el;
256
- }
257
- }
258
- return null;
259
- }
260
- function finder(input, options) {
261
- return (0, import_finder.finder)(input, options);
262
- }
263
- function parserX(input) {
264
- return parseSelectorsTree(input, null);
265
- }
266
- function parserV2(element) {
267
- var _a;
268
- const content = (_a = element.innerText) != null ? _a : "";
269
- const selectors = parseSelectorsTree(element, null);
270
- const selectorsList = queryElementSelectors(element);
271
- return { content, selectors, selectorsList };
272
- }
273
- function finderV2(target, root) {
274
- const {
275
- selectors,
276
- content = "",
277
- sequence = 0,
278
- precision = "strict",
279
- isDynamicContent = false,
280
- customSelector = "",
281
- type = "auto"
282
- } = target;
283
- if (type === "auto") {
284
- const mapping = {
285
- looser: 1,
286
- loose: 3,
287
- loosest: 5,
288
- strict: 7,
289
- stricter: 8,
290
- strictest: 10
291
- };
292
- const el = finderX(selectors, root, mapping[precision]);
293
- if (el) {
294
- if (isDynamicContent && content && el.innerText !== content) {
295
- return null;
296
- }
297
- return el;
298
- }
299
- } else {
300
- const sequenceMapping = {
301
- "1st": 0,
302
- "2st": 1,
303
- "3st": 2,
304
- "4st": 3,
305
- "5st": 4
306
- };
307
- if (customSelector) {
308
- const selector = customSelector.replace(/\\\\/g, "\\");
309
- const els = root.querySelectorAll(selector);
310
- if (els.length > 0) {
311
- const el = els[sequenceMapping[sequence]] || els[0];
312
- if (content && el.innerText.trim() !== content) {
313
- return null;
314
- }
315
- return el;
316
- }
317
- }
318
- }
319
- return null;
320
- }
321
- function finderX(node, root, precision = 10) {
322
- if (!node || node.selectors.length === 0) {
323
- return null;
324
- }
325
- const rootDocument = root || document;
326
- const elements = [];
327
- const nodeList = queryNodeListBySelectors(node.selectors, rootDocument, false);
328
- if (!nodeList || nodeList.length === 0) {
329
- return null;
330
- }
331
- if ([...new Set(nodeList)].length !== nodeList.length) {
332
- const el = findMostRecurringNode(nodeList);
333
- elements.push(el);
334
- } else {
335
- elements.push(...nodeList);
336
- }
337
- return finderMostPrecisionElement(elements, node, rootDocument, precision);
338
- }
339
- // Annotate the CommonJS export names for ESM import in node:
340
- 0 && (module.exports = {
341
- finder,
342
- finderV2,
343
- finderX,
344
- parserV2,
345
- parserX
346
- });
@@ -1,47 +0,0 @@
1
- type Options = {
2
- root: Element;
3
- idName: (name: string) => boolean;
4
- className: (name: string) => boolean;
5
- tagName: (name: string) => boolean;
6
- attr: (name: string, value: string) => boolean;
7
- seedMinLength: number;
8
- optimizedMinLength: number;
9
- threshold: number;
10
- maxNumberOfTries: number;
11
- };
12
- type XNode = {
13
- selectors: string[];
14
- nextElementSelectors: string[];
15
- previousElementSelectors: string[];
16
- depth: number;
17
- parentNode?: XNode | null;
18
- };
19
- type XData = {
20
- node: XNode;
21
- };
22
- type XResult = {
23
- maxDepth: number;
24
- failedDepth: number;
25
- success: boolean;
26
- };
27
- type Target = {
28
- selectors?: any;
29
- content?: string;
30
- sequence?: string;
31
- precision?: string;
32
- isDynamicContent?: boolean;
33
- customSelector?: string;
34
- type?: string;
35
- };
36
- declare function finder(input: Element, options?: Partial<Options>): string;
37
- declare function parserX(input: Element): XNode | null;
38
- type TargetResult = {
39
- content: string;
40
- selectors: XNode | null;
41
- selectorsList: string[];
42
- };
43
- declare function parserV2(element: HTMLElement): TargetResult;
44
- declare function finderV2(target: Target, root: Element | Document): HTMLElement | null;
45
- declare function finderX(node: XNode, root: Element | Document, precision?: number): Element | null;
46
-
47
- export { type Options, type Target, type TargetResult, type XData, type XNode, type XResult, finder, finderV2, finderX, parserV2, parserX };
package/dist/finderx.d.ts DELETED
@@ -1,47 +0,0 @@
1
- type Options = {
2
- root: Element;
3
- idName: (name: string) => boolean;
4
- className: (name: string) => boolean;
5
- tagName: (name: string) => boolean;
6
- attr: (name: string, value: string) => boolean;
7
- seedMinLength: number;
8
- optimizedMinLength: number;
9
- threshold: number;
10
- maxNumberOfTries: number;
11
- };
12
- type XNode = {
13
- selectors: string[];
14
- nextElementSelectors: string[];
15
- previousElementSelectors: string[];
16
- depth: number;
17
- parentNode?: XNode | null;
18
- };
19
- type XData = {
20
- node: XNode;
21
- };
22
- type XResult = {
23
- maxDepth: number;
24
- failedDepth: number;
25
- success: boolean;
26
- };
27
- type Target = {
28
- selectors?: any;
29
- content?: string;
30
- sequence?: string;
31
- precision?: string;
32
- isDynamicContent?: boolean;
33
- customSelector?: string;
34
- type?: string;
35
- };
36
- declare function finder(input: Element, options?: Partial<Options>): string;
37
- declare function parserX(input: Element): XNode | null;
38
- type TargetResult = {
39
- content: string;
40
- selectors: XNode | null;
41
- selectorsList: string[];
42
- };
43
- declare function parserV2(element: HTMLElement): TargetResult;
44
- declare function finderV2(target: Target, root: Element | Document): HTMLElement | null;
45
- declare function finderX(node: XNode, root: Element | Document, precision?: number): Element | null;
46
-
47
- export { type Options, type Target, type TargetResult, type XData, type XNode, type XResult, finder, finderV2, finderX, parserV2, parserX };
package/dist/finderx.js DELETED
@@ -1,15 +0,0 @@
1
- import {
2
- finder,
3
- finderV2,
4
- finderX,
5
- parserV2,
6
- parserX
7
- } from "./chunk-DEG6MTU7.js";
8
- import "./chunk-XEO3YXBM.js";
9
- export {
10
- finder,
11
- finderV2,
12
- finderX,
13
- parserV2,
14
- parserX
15
- };
@@ -1,147 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => {
31
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
- return value;
33
- };
34
-
35
- // src/jwt-license-signer.ts
36
- var jwt_license_signer_exports = {};
37
- __export(jwt_license_signer_exports, {
38
- JWTLicenseSigner: () => JWTLicenseSigner
39
- });
40
- module.exports = __toCommonJS(jwt_license_signer_exports);
41
- var fs = __toESM(require("fs"), 1);
42
- var path = __toESM(require("path"), 1);
43
- var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
44
- var JWTLicenseSigner = class {
45
- constructor(options) {
46
- __publicField(this, "privateKey");
47
- __publicField(this, "issuer");
48
- __publicField(this, "algorithm");
49
- this.privateKey = this.loadPrivateKey(options.privateKeyPath);
50
- this.issuer = options.issuer || "https://www.usertour.io";
51
- this.algorithm = options.algorithm || "RS256";
52
- }
53
- /**
54
- * Load RSA private key from file
55
- */
56
- loadPrivateKey(keyPath) {
57
- try {
58
- const fullPath = path.resolve(keyPath);
59
- return fs.readFileSync(fullPath, "utf8");
60
- } catch (error) {
61
- throw new Error(`Failed to load private key from ${keyPath}: ${error}`);
62
- }
63
- }
64
- /**
65
- * Generate a JWT license token
66
- */
67
- generateLicense(options) {
68
- const now = Math.floor(Date.now() / 1e3);
69
- const expiresAt = now + options.expiresInDays * 24 * 60 * 60;
70
- const payload = {
71
- plan: options.plan,
72
- sub: options.subject,
73
- projectId: options.projectId,
74
- iat: now,
75
- exp: expiresAt,
76
- issuer: options.issuer || this.issuer,
77
- features: options.features
78
- };
79
- try {
80
- return import_jsonwebtoken.default.sign(payload, this.privateKey, {
81
- algorithm: this.algorithm,
82
- issuer: this.issuer
83
- });
84
- } catch (error) {
85
- throw new Error(`Failed to generate JWT license: ${error}`);
86
- }
87
- }
88
- /**
89
- * Generate a license and return both token and payload info
90
- */
91
- generateLicenseWithInfo(options) {
92
- const now = Math.floor(Date.now() / 1e3);
93
- const expiresAt = now + options.expiresInDays * 24 * 60 * 60;
94
- const payload = {
95
- plan: options.plan,
96
- sub: options.subject,
97
- projectId: options.projectId,
98
- iat: now,
99
- exp: expiresAt,
100
- issuer: options.issuer || this.issuer,
101
- features: options.features
102
- };
103
- const token = import_jsonwebtoken.default.sign(payload, this.privateKey, {
104
- algorithm: this.algorithm,
105
- issuer: this.issuer
106
- });
107
- return {
108
- token,
109
- payload,
110
- expiresAt: new Date(expiresAt * 1e3)
111
- };
112
- }
113
- /**
114
- * Decode a JWT token without verification (for debugging)
115
- */
116
- decodeToken(token) {
117
- try {
118
- return import_jsonwebtoken.default.decode(token);
119
- } catch (error) {
120
- console.error("Failed to decode JWT token:", error);
121
- return null;
122
- }
123
- }
124
- /**
125
- * Get token information without verification
126
- */
127
- getTokenInfo(token) {
128
- try {
129
- const decoded = import_jsonwebtoken.default.decode(token, { complete: true });
130
- if (!decoded || typeof decoded === "string") {
131
- return null;
132
- }
133
- return {
134
- header: decoded.header,
135
- payload: decoded.payload,
136
- signature: decoded.signature
137
- };
138
- } catch (error) {
139
- console.error("Failed to get token info:", error);
140
- return null;
141
- }
142
- }
143
- };
144
- // Annotate the CommonJS export names for ESM import in node:
145
- 0 && (module.exports = {
146
- JWTLicenseSigner
147
- });