@lpdfio/lpdf 0.18.0 → 0.20.0

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/README.md CHANGED
@@ -56,6 +56,10 @@ To stay on one engine and still get this package's fixes, use a tilde range in `
56
56
 
57
57
  [lpdf.io/docs/js](https://lpdf.io/docs/js)
58
58
 
59
+ ## Issues
60
+
61
+ Report bugs and request features at [github.com/lpdfio/lpdf/issues](https://github.com/lpdfio/lpdf/issues), the one tracker for the engine, the SDKs and the VS Code extension. Pull requests are not accepted.
62
+
59
63
  --
60
64
 
61
65
  Dual-licensed: Community License (free) and Commercial License (paid). See [LICENSE](LICENSE) for full terms.
package/dist/browser.js CHANGED
@@ -203,6 +203,20 @@ var LpdfEngine = class {
203
203
  }
204
204
  };
205
205
  if (Symbol.dispose) LpdfEngine.prototype[Symbol.dispose] = LpdfEngine.prototype.free;
206
+ function check_license(token, now_unix) {
207
+ let deferred2_0;
208
+ let deferred2_1;
209
+ try {
210
+ const ptr0 = passStringToWasm0(token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
211
+ const len0 = WASM_VECTOR_LEN;
212
+ const ret = wasm.check_license(ptr0, len0, now_unix);
213
+ deferred2_0 = ret[0];
214
+ deferred2_1 = ret[1];
215
+ return getStringFromWasm0(ret[0], ret[1]);
216
+ } finally {
217
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
218
+ }
219
+ }
206
220
  function __wbg_get_imports() {
207
221
  const import0 = {
208
222
  __proto__: null,
@@ -380,6 +394,9 @@ async function __wbg_init(module_or_path) {
380
394
 
381
395
  // src/browser.ts
382
396
  var NoAttr = null;
397
+ function nowUnix() {
398
+ return BigInt(Math.floor(Date.now() / 1e3));
399
+ }
383
400
  async function initLpdf(wasmSource, licenseKey = "") {
384
401
  await __wbg_init(wasmSource);
385
402
  const fontMap = /* @__PURE__ */ new Map();
@@ -391,8 +408,12 @@ async function initLpdf(wasmSource, licenseKey = "") {
391
408
  loadImage(name, bytes) {
392
409
  imageMap.set(name, bytes);
393
410
  },
411
+ checkLicenseKey(key) {
412
+ return JSON.parse(check_license(key ?? licenseKey, nowUnix()));
413
+ },
394
414
  async render(input, callOptions = {}) {
395
415
  const engine = new LpdfEngine(licenseKey);
416
+ engine.set_now(nowUnix());
396
417
  for (const [name, bytes] of fontMap) {
397
418
  engine.load_font(name, bytes);
398
419
  }
package/dist/engine.d.ts CHANGED
@@ -1,5 +1,27 @@
1
1
  import type { RenderOptions } from './_shared';
2
2
  import type { PdfDocument } from './kit';
3
+ /** How a license key stands with this build of the engine. */
4
+ export type LicenseStatus = 'licensed' | 'no_key' | 'expired' | 'version_mismatch' | 'wrong_product' | 'unknown_key' | 'bad_signature' | 'malformed';
5
+ /**
6
+ * What the engine makes of a license key — see {@link PdfEngine.checkLicenseKey}.
7
+ *
8
+ * Everything but `status` is present only once the key's signature verified, so an expired or
9
+ * wrong-version key still names its license while an unreadable one says nothing further: an
10
+ * unverified token's contents are its author's claims, not facts.
11
+ */
12
+ export interface LicenseCheck {
13
+ status: LicenseStatus;
14
+ /** Which Codesense product the key was issued for. */
15
+ product?: string;
16
+ /** `community`, `professional` or `enterprise`. */
17
+ tier?: string;
18
+ /** When the key stops validating, ISO 8601 UTC. Absent on a version-locked key. */
19
+ expires?: string;
20
+ /** The license number, as the customer reads it: `L-7K3M9Q`. */
21
+ license?: string;
22
+ /** Which key this is on its license — 1, 2, 3 in issue order. */
23
+ key?: number;
24
+ }
3
25
  /** Thrown when the lpdf engine returns a layout or parse error. */
4
26
  export declare class LpdfRenderError extends Error {
5
27
  constructor(message: string);
@@ -35,6 +57,18 @@ export declare class PdfEngine {
35
57
  * Set the license key. Returns `this` for chaining.
36
58
  */
37
59
  setLicenseKey(key: string): this;
60
+ /**
61
+ * Ask the engine what a license key is: valid, expired, for another product, and which
62
+ * license and key it is.
63
+ *
64
+ * This is the engine's own verdict, from the same code a render runs — so `licensed` here
65
+ * means PDFs come out without the attribution line here. A key the portal considers perfectly
66
+ * good still reads `unknown_key` in a build that does not trust the key it was signed with,
67
+ * which is the answer worth having.
68
+ *
69
+ * @param key - The key to check. Defaults to the one set on this engine.
70
+ */
71
+ checkLicenseKey(key?: string): LicenseCheck;
38
72
  /**
39
73
  * Register raw TTF/OTF bytes for a custom font name used in `<font src="…">`.
40
74
  * Call before `render`. Returns `this` for chaining.
package/dist/engine.js CHANGED
@@ -8,6 +8,18 @@ const node_fs_1 = require("node:fs");
8
8
  // eslint-disable-next-line @typescript-eslint/no-require-imports
9
9
  const wasmModule = require('./wasm/lpdf.js');
10
10
  const WasmEngine = wasmModule.LpdfEngine;
11
+ /**
12
+ * The clock the engine checks a key's expiry against.
13
+ *
14
+ * WebAssembly has no clock of its own, so an engine that is not told the time skips the expiry
15
+ * check altogether — which is how an expired key used to render without the attribution line.
16
+ *
17
+ * A `bigint`, because the engine takes the seconds as an `i64` and wasm-bindgen accepts nothing
18
+ * narrower on that boundary.
19
+ */
20
+ function nowUnix() {
21
+ return BigInt(Math.floor(Date.now() / 1000));
22
+ }
11
23
  /** Thrown when the lpdf engine returns a layout or parse error. */
12
24
  class LpdfRenderError extends Error {
13
25
  constructor(message) {
@@ -32,6 +44,21 @@ class PdfEngine {
32
44
  this._licenseKey = key;
33
45
  return this;
34
46
  }
47
+ /**
48
+ * Ask the engine what a license key is: valid, expired, for another product, and which
49
+ * license and key it is.
50
+ *
51
+ * This is the engine's own verdict, from the same code a render runs — so `licensed` here
52
+ * means PDFs come out without the attribution line here. A key the portal considers perfectly
53
+ * good still reads `unknown_key` in a build that does not trust the key it was signed with,
54
+ * which is the answer worth having.
55
+ *
56
+ * @param key - The key to check. Defaults to the one set on this engine.
57
+ */
58
+ checkLicenseKey(key) {
59
+ this._throwIfDisposed();
60
+ return JSON.parse(wasmModule.check_license(key ?? this._licenseKey, nowUnix()));
61
+ }
35
62
  /**
36
63
  * Register raw TTF/OTF bytes for a custom font name used in `<font src="…">`.
37
64
  * Call before `render`. Returns `this` for chaining.
@@ -83,6 +110,9 @@ class PdfEngine {
83
110
  async render(input, callOptions = {}) {
84
111
  this._throwIfDisposed();
85
112
  const engine = new WasmEngine(this._licenseKey);
113
+ // Without a clock the engine cannot check the key's expiry, and an expired key renders as
114
+ // though it were current.
115
+ engine.set_now(nowUnix());
86
116
  if (callOptions.createdOn) {
87
117
  engine.set_created_on(callOptions.createdOn);
88
118
  }
@@ -205,6 +205,42 @@ export class LpdfEngine {
205
205
  }
206
206
  if (Symbol.dispose) LpdfEngine.prototype[Symbol.dispose] = LpdfEngine.prototype.free;
207
207
 
208
+ /**
209
+ * What this build of the engine makes of a license key, as JSON.
210
+ *
211
+ * ```json
212
+ * { "status": "licensed", "product": "lpdf", "tier": "professional",
213
+ * "expires": "2027-09-19T00:00:00Z", "license": "L-7K3M9Q", "key": 3 }
214
+ * ```
215
+ *
216
+ * `status` is one of `licensed`, `no_key`, `expired`, `version_mismatch`, `wrong_product`,
217
+ * `unknown_key`, `bad_signature` or `malformed`. The remaining fields appear only once the
218
+ * signature verified — see [`license::report_json`].
219
+ *
220
+ * A free function, not a method: asking what a key is should not require building an engine.
221
+ * `now_unix` is the caller's clock in seconds, since wasm has none; `0` skips the expiry check.
222
+ *
223
+ * The answer is this build's. An engine older than the key, or one built for another
224
+ * environment, answers `unknown_key` — which is the useful part, not a caveat.
225
+ * @param {string} token
226
+ * @param {bigint} now_unix
227
+ * @returns {string}
228
+ */
229
+ export function check_license(token, now_unix) {
230
+ let deferred2_0;
231
+ let deferred2_1;
232
+ try {
233
+ const ptr0 = passStringToWasm0(token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
234
+ const len0 = WASM_VECTOR_LEN;
235
+ const ret = wasm.check_license(ptr0, len0, now_unix);
236
+ deferred2_0 = ret[0];
237
+ deferred2_1 = ret[1];
238
+ return getStringFromWasm0(ret[0], ret[1]);
239
+ } finally {
240
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
241
+ }
242
+ }
243
+
208
244
  /**
209
245
  * Generate SDK source code from one or more bare Lpdf XML elements (a fragment).
210
246
  *
package/dist/wasm/lpdf.js CHANGED
@@ -206,6 +206,43 @@ class LpdfEngine {
206
206
  if (Symbol.dispose) LpdfEngine.prototype[Symbol.dispose] = LpdfEngine.prototype.free;
207
207
  exports.LpdfEngine = LpdfEngine;
208
208
 
209
+ /**
210
+ * What this build of the engine makes of a license key, as JSON.
211
+ *
212
+ * ```json
213
+ * { "status": "licensed", "product": "lpdf", "tier": "professional",
214
+ * "expires": "2027-09-19T00:00:00Z", "license": "L-7K3M9Q", "key": 3 }
215
+ * ```
216
+ *
217
+ * `status` is one of `licensed`, `no_key`, `expired`, `version_mismatch`, `wrong_product`,
218
+ * `unknown_key`, `bad_signature` or `malformed`. The remaining fields appear only once the
219
+ * signature verified — see [`license::report_json`].
220
+ *
221
+ * A free function, not a method: asking what a key is should not require building an engine.
222
+ * `now_unix` is the caller's clock in seconds, since wasm has none; `0` skips the expiry check.
223
+ *
224
+ * The answer is this build's. An engine older than the key, or one built for another
225
+ * environment, answers `unknown_key` — which is the useful part, not a caveat.
226
+ * @param {string} token
227
+ * @param {bigint} now_unix
228
+ * @returns {string}
229
+ */
230
+ function check_license(token, now_unix) {
231
+ let deferred2_0;
232
+ let deferred2_1;
233
+ try {
234
+ const ptr0 = passStringToWasm0(token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
235
+ const len0 = WASM_VECTOR_LEN;
236
+ const ret = wasm.check_license(ptr0, len0, now_unix);
237
+ deferred2_0 = ret[0];
238
+ deferred2_1 = ret[1];
239
+ return getStringFromWasm0(ret[0], ret[1]);
240
+ } finally {
241
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
242
+ }
243
+ }
244
+ exports.check_license = check_license;
245
+
209
246
  /**
210
247
  * Generate SDK source code from one or more bare Lpdf XML elements (a fragment).
211
248
  *
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdfio/lpdf",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "Node.js SDK for Lpdf — PDF as Code on every platform. You describe a document as code or XML. Lpdf renders a compact, pixel-perfect PDF — identical across platforms.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,6 +26,9 @@
26
26
  "type": "git",
27
27
  "url": "https://github.com/lpdfio/lpdf-js"
28
28
  },
29
+ "bugs": {
30
+ "url": "https://github.com/lpdfio/lpdf/issues"
31
+ },
29
32
  "keywords": [
30
33
  "pdf",
31
34
  "wasm",