@namahapdf/react 0.1.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.
@@ -0,0 +1,95 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+
4
+ interface NamahaEditorProps {
5
+ /** Your NamahaPDF SDK license key. Without it the editor runs in watermarked mode. */
6
+ licenseKey?: string;
7
+ /** Override the activation endpoint (defaults to a same-origin /api/license/activate). */
8
+ activationUrl?: string;
9
+ /** Extra class on the scoping wrapper. */
10
+ className?: string;
11
+ style?: React.CSSProperties;
12
+ }
13
+ /**
14
+ * A complete in-browser PDF editor — view, edit, annotate, sign, redact, and fill
15
+ * forms, fully on-device. Pass your `licenseKey` to remove the evaluation watermark
16
+ * and unlock licensed features.
17
+ *
18
+ * Import the stylesheet once in your app: `import '@namahapdf/react/styles.css'`.
19
+ */
20
+ declare function NamahaEditor({ licenseKey, activationUrl, className, style }: NamahaEditorProps): react_jsx_runtime.JSX.Element;
21
+
22
+ /** Shared license/activation contracts used by both the engine gate and the server. */
23
+ /** Capabilities a license can unlock. `view`/`annotate` are the always-available base. */
24
+ type LicenseFeature = 'view' | 'annotate' | 'edit-text' | 'sign' | 'redact' | 'forms' | 'export-clean';
25
+ type LicenseEdition = 'trial' | 'pro' | 'enterprise';
26
+ type LicenseStatus = 'UNLICENSED' | 'INVALID' | 'LICENSED' | 'GRACE' | 'DEGRADED';
27
+ interface LicenseState {
28
+ status: LicenseStatus;
29
+ edition: LicenseEdition | null;
30
+ features: LicenseFeature[];
31
+ /** True when render/export should be watermarked. */
32
+ watermark: boolean;
33
+ /** Human-readable reason (for diagnostics; never user-facing copy). */
34
+ reason: string;
35
+ }
36
+
37
+ /**
38
+ * Client-side license gate for the NamahaPDF engine.
39
+ *
40
+ * Flow (see configureLicense):
41
+ * 1. Verify the license key OFFLINE (signature, expiry, domain) — instant, no network.
42
+ * 2. If a cached activation token is still valid → LICENSED immediately.
43
+ * 3. Kick a NON-BLOCKING background activation that exchanges the key for a fresh,
44
+ * short-TTL activation token (which is also what the server can revoke).
45
+ *
46
+ * Offline grace is weighted heavily on purpose: transient network/server failures
47
+ * never punish a paying customer. We tolerate up to MAX_FAILURES (5) attempts AND a
48
+ * BOOTSTRAP_GRACE window before degrading — the SDK degrades immediately ONLY on an
49
+ * explicit signed `revoked`/`invalid` from the server.
50
+ *
51
+ * Everything is injectable (storage / fetch / clock / public key) so it is unit-testable
52
+ * without a browser or a server.
53
+ */
54
+
55
+ interface StorageLike {
56
+ getItem(key: string): string | null;
57
+ setItem(key: string, value: string): void;
58
+ }
59
+ interface LicenseConfig {
60
+ /** The signed license key the developer received. */
61
+ licenseKey?: string;
62
+ /** Activation endpoint. Defaults to a same-origin `/api/license/activate`. */
63
+ activationUrl?: string;
64
+ /** Stable per-install id; auto-generated + persisted when omitted. */
65
+ deviceId?: string;
66
+ /** First-party bypass — our own app passes this so it never watermarks itself. */
67
+ owner?: boolean;
68
+ /** Override the embedded public key (tests only). */
69
+ publicKeyHex?: string;
70
+ /** Injected clock (tests). */
71
+ now?: () => number;
72
+ /** Injected storage (tests / Node). */
73
+ storage?: StorageLike;
74
+ /** Injected fetch (tests / Node). */
75
+ fetchImpl?: typeof fetch;
76
+ /** Host to domain-check against; defaults to location.hostname in the browser. */
77
+ host?: string;
78
+ /** Background retry backoff in ms (tests can shorten). */
79
+ retryDelays?: number[];
80
+ }
81
+ type Listener = (s: LicenseState) => void;
82
+ /**
83
+ * Configure (or reconfigure) the license gate. Verifies the key synchronously and
84
+ * starts a background activation. Returns the immediate state; subscribe with
85
+ * `onLicenseChange` for updates as activation completes.
86
+ */
87
+ declare function configureLicense(config?: LicenseConfig): LicenseState;
88
+ /** Current license state (synchronous, cheap). */
89
+ declare function getLicenseState(): LicenseState;
90
+ declare function isFeatureEnabled(feature: LicenseFeature): boolean;
91
+ declare function shouldWatermark(): boolean;
92
+ /** Subscribe to state changes (activation success/failure). Returns an unsubscribe. */
93
+ declare function onLicenseChange(cb: Listener): () => void;
94
+
95
+ export { type LicenseConfig, type LicenseEdition, type LicenseFeature, type LicenseState, type LicenseStatus, NamahaEditor, type NamahaEditorProps, configureLicense, NamahaEditor as default, getLicenseState, isFeatureEnabled, onLicenseChange, shouldWatermark };
@@ -0,0 +1,95 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+
4
+ interface NamahaEditorProps {
5
+ /** Your NamahaPDF SDK license key. Without it the editor runs in watermarked mode. */
6
+ licenseKey?: string;
7
+ /** Override the activation endpoint (defaults to a same-origin /api/license/activate). */
8
+ activationUrl?: string;
9
+ /** Extra class on the scoping wrapper. */
10
+ className?: string;
11
+ style?: React.CSSProperties;
12
+ }
13
+ /**
14
+ * A complete in-browser PDF editor — view, edit, annotate, sign, redact, and fill
15
+ * forms, fully on-device. Pass your `licenseKey` to remove the evaluation watermark
16
+ * and unlock licensed features.
17
+ *
18
+ * Import the stylesheet once in your app: `import '@namahapdf/react/styles.css'`.
19
+ */
20
+ declare function NamahaEditor({ licenseKey, activationUrl, className, style }: NamahaEditorProps): react_jsx_runtime.JSX.Element;
21
+
22
+ /** Shared license/activation contracts used by both the engine gate and the server. */
23
+ /** Capabilities a license can unlock. `view`/`annotate` are the always-available base. */
24
+ type LicenseFeature = 'view' | 'annotate' | 'edit-text' | 'sign' | 'redact' | 'forms' | 'export-clean';
25
+ type LicenseEdition = 'trial' | 'pro' | 'enterprise';
26
+ type LicenseStatus = 'UNLICENSED' | 'INVALID' | 'LICENSED' | 'GRACE' | 'DEGRADED';
27
+ interface LicenseState {
28
+ status: LicenseStatus;
29
+ edition: LicenseEdition | null;
30
+ features: LicenseFeature[];
31
+ /** True when render/export should be watermarked. */
32
+ watermark: boolean;
33
+ /** Human-readable reason (for diagnostics; never user-facing copy). */
34
+ reason: string;
35
+ }
36
+
37
+ /**
38
+ * Client-side license gate for the NamahaPDF engine.
39
+ *
40
+ * Flow (see configureLicense):
41
+ * 1. Verify the license key OFFLINE (signature, expiry, domain) — instant, no network.
42
+ * 2. If a cached activation token is still valid → LICENSED immediately.
43
+ * 3. Kick a NON-BLOCKING background activation that exchanges the key for a fresh,
44
+ * short-TTL activation token (which is also what the server can revoke).
45
+ *
46
+ * Offline grace is weighted heavily on purpose: transient network/server failures
47
+ * never punish a paying customer. We tolerate up to MAX_FAILURES (5) attempts AND a
48
+ * BOOTSTRAP_GRACE window before degrading — the SDK degrades immediately ONLY on an
49
+ * explicit signed `revoked`/`invalid` from the server.
50
+ *
51
+ * Everything is injectable (storage / fetch / clock / public key) so it is unit-testable
52
+ * without a browser or a server.
53
+ */
54
+
55
+ interface StorageLike {
56
+ getItem(key: string): string | null;
57
+ setItem(key: string, value: string): void;
58
+ }
59
+ interface LicenseConfig {
60
+ /** The signed license key the developer received. */
61
+ licenseKey?: string;
62
+ /** Activation endpoint. Defaults to a same-origin `/api/license/activate`. */
63
+ activationUrl?: string;
64
+ /** Stable per-install id; auto-generated + persisted when omitted. */
65
+ deviceId?: string;
66
+ /** First-party bypass — our own app passes this so it never watermarks itself. */
67
+ owner?: boolean;
68
+ /** Override the embedded public key (tests only). */
69
+ publicKeyHex?: string;
70
+ /** Injected clock (tests). */
71
+ now?: () => number;
72
+ /** Injected storage (tests / Node). */
73
+ storage?: StorageLike;
74
+ /** Injected fetch (tests / Node). */
75
+ fetchImpl?: typeof fetch;
76
+ /** Host to domain-check against; defaults to location.hostname in the browser. */
77
+ host?: string;
78
+ /** Background retry backoff in ms (tests can shorten). */
79
+ retryDelays?: number[];
80
+ }
81
+ type Listener = (s: LicenseState) => void;
82
+ /**
83
+ * Configure (or reconfigure) the license gate. Verifies the key synchronously and
84
+ * starts a background activation. Returns the immediate state; subscribe with
85
+ * `onLicenseChange` for updates as activation completes.
86
+ */
87
+ declare function configureLicense(config?: LicenseConfig): LicenseState;
88
+ /** Current license state (synchronous, cheap). */
89
+ declare function getLicenseState(): LicenseState;
90
+ declare function isFeatureEnabled(feature: LicenseFeature): boolean;
91
+ declare function shouldWatermark(): boolean;
92
+ /** Subscribe to state changes (activation success/failure). Returns an unsubscribe. */
93
+ declare function onLicenseChange(cb: Listener): () => void;
94
+
95
+ export { type LicenseConfig, type LicenseEdition, type LicenseFeature, type LicenseState, type LicenseStatus, NamahaEditor, type NamahaEditorProps, configureLicense, NamahaEditor as default, getLicenseState, isFeatureEnabled, onLicenseChange, shouldWatermark };