sendclap 0.2.0 → 0.3.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
@@ -19,7 +19,7 @@ try {
19
19
  settings.instanceId ??= (await licenses.activate(key, await instanceName())).instance_id // first run
20
20
  const r = await licenses.validate(key, settings.instanceId)
21
21
  if (r.valid) settings.lastValidated = Date.now()
22
- else lockApp(r.status) // "invalid" (unknown key), "disabled" (refunded or disputed) or "not_activated"
22
+ else lockApp(r.status) // "not_found" (unknown key), "disabled" (refunded or disputed) or "not_activated"
23
23
  } catch (e) {
24
24
  // offline: keep working for 7 days after the last successful check
25
25
  if (!(e instanceof NetworkError) || Date.now() - settings.lastValidated > 7 * 86400_000) lockApp('unverified')
@@ -27,7 +27,7 @@ try {
27
27
  ```
28
28
 
29
29
  - `activate(licenseKey, instanceName)` registers this device and returns `{ instance_id, license, product }`. Activating the same instance again counts once, and the instance id is simply the name you passed.
30
- - `validate(licenseKey, instanceId?)` returns `{ valid, status, license?, product? }`. Its `status` is `active`, `not_activated` (the key exists but this device isn't activated), `invalid` (unknown key) or `disabled` (the payment was refunded or disputed). It throws only when no definite answer came back, which is how you tell "offline" from "invalid".
30
+ - `validate(licenseKey, instanceId?)` returns `{ valid, status, license?, product? }`. Its `status` is `active`, `not_activated` (the key exists but this device isn't activated), `disabled` (the payment was refunded or disputed) or `not_found` (unknown key). It throws only when no definite answer came back, which is how you tell "offline" from "not found".
31
31
  - `deactivate(licenseKey, instanceId)` frees one activation so the customer can move to another machine. It throws `InstanceNotFoundError` if that instance wasn't activated.
32
32
 
33
33
  To tell a customer why a license doesn't work, branch on the status, or catch the typed error from `activate`:
@@ -35,7 +35,7 @@ To tell a customer why a license doesn't work, branch on the status, or catch th
35
35
  ```ts
36
36
  const r = await licenses.validate(key, instanceId)
37
37
  if (r.status === 'disabled') showMessage('This license was refunded or disputed.')
38
- else if (r.status === 'invalid') showMessage('That license key does not exist.')
38
+ else if (r.status === 'not_found') showMessage('That license key does not exist.')
39
39
 
40
40
  try { await licenses.activate(key, name) } catch (e) {
41
41
  if (e instanceof DisabledLicenseError) showMessage('This license was refunded or disputed.')
@@ -44,7 +44,7 @@ try { await licenses.activate(key, name) } catch (e) {
44
44
 
45
45
  `instanceName()` returns the hostname in Node, Bun, Deno and Electron's main process, and a random id kept in `localStorage` in browsers. The name is sent to Sendclap and shown to the creator in the activity log, and machines that share a hostname share an activation. If that matters, generate your own id (for example `crypto.randomUUID()` saved on first run) and pass it instead.
46
46
 
47
- Cache the result of the last successful `validate` and validate again at startup or once a day. On a `NetworkError`, accept the cached result for a grace period. On `invalid` or `not_activated`, lock.
47
+ Cache the result of the last successful `validate` and validate again at startup or once a day. On a `NetworkError`, accept the cached result for a grace period. On `not_found`, `disabled` or `not_activated`, lock.
48
48
 
49
49
  ## Creator API
50
50
 
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.2.0";
1
+ export declare const VERSION = "0.3.0";
2
2
  export interface ClientOptions {
3
3
  /** Defaults to https://sendclap.com. */
4
4
  baseUrl?: string;
@@ -58,8 +58,9 @@ export interface DeactivateResult {
58
58
  }
59
59
  export interface ValidateResult {
60
60
  valid: boolean;
61
- /** `active`: valid. `not_activated`: the key exists but this instance isn't activated. `invalid`: unknown key. `disabled`: refunded or disputed. */
62
- status: 'active' | 'not_activated' | 'invalid' | 'disabled';
61
+ /** `active`: valid. `not_activated`: the key exists but this instance isn't activated. `not_found`: unknown key. `disabled`: refunded or disputed. */
62
+ status: 'active' | 'not_activated' | 'disabled' | 'not_found';
63
+ /** Present for `active` and `not_activated` only. */
63
64
  license?: LicenseInfo;
64
65
  product?: ProductRef;
65
66
  }
@@ -84,6 +85,8 @@ export interface Checkout {
84
85
  email: string | null;
85
86
  /** Where to send the customer to pay. */
86
87
  url: string;
88
+ /** ISO 8601 time the checkout was paid, or null while unpaid. */
89
+ paid_at: string | null;
87
90
  }
88
91
  export interface Totals {
89
92
  payments: number;
@@ -104,7 +107,7 @@ export interface Stats {
104
107
  };
105
108
  open_disputes: number;
106
109
  }
107
- /** `limit` is at most 500; `after` is the previous page's `next`. */
110
+ /** `limit` defaults to 50 and is at most 500; `after` is the previous page's `next`. */
108
111
  export interface PageParams {
109
112
  limit?: number;
110
113
  after?: number;
package/dist/cjs/index.js CHANGED
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.ApiClient = exports.LicenseClient = exports.NetworkError = exports.InstanceNotFoundError = exports.ActivationLimitError = exports.DisabledLicenseError = exports.InvalidLicenseError = exports.SendclapError = exports.VERSION = void 0;
39
39
  exports.instanceName = instanceName;
40
- exports.VERSION = '0.2.0';
40
+ exports.VERSION = '0.3.0';
41
41
  const DEFAULT_BASE_URL = 'https://sendclap.com';
42
42
  const DEFAULT_TIMEOUT_MS = 15000;
43
43
  // ---------- errors ----------
@@ -161,17 +161,7 @@ class LicenseClient {
161
161
  }
162
162
  /** Checks the key (and, with an instance id, that this device is activated). Throws only when no definite answer came back. */
163
163
  async validate(licenseKey, instanceId) {
164
- try {
165
- const { valid, license, product } = await this.call('validate', licenseKey, instanceId);
166
- return { valid, status: valid ? 'active' : 'not_activated', license, product };
167
- }
168
- catch (e) {
169
- if (e instanceof InvalidLicenseError)
170
- return { valid: false, status: 'invalid' };
171
- if (e instanceof DisabledLicenseError)
172
- return { valid: false, status: 'disabled' };
173
- throw e;
174
- }
164
+ return this.call('validate', licenseKey, instanceId);
175
165
  }
176
166
  /** Releases a device, freeing one activation. Throws InstanceNotFoundError if it wasn't activated. */
177
167
  async deactivate(licenseKey, instanceId) {
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.2.0";
1
+ export declare const VERSION = "0.3.0";
2
2
  export interface ClientOptions {
3
3
  /** Defaults to https://sendclap.com. */
4
4
  baseUrl?: string;
@@ -58,8 +58,9 @@ export interface DeactivateResult {
58
58
  }
59
59
  export interface ValidateResult {
60
60
  valid: boolean;
61
- /** `active`: valid. `not_activated`: the key exists but this instance isn't activated. `invalid`: unknown key. `disabled`: refunded or disputed. */
62
- status: 'active' | 'not_activated' | 'invalid' | 'disabled';
61
+ /** `active`: valid. `not_activated`: the key exists but this instance isn't activated. `not_found`: unknown key. `disabled`: refunded or disputed. */
62
+ status: 'active' | 'not_activated' | 'disabled' | 'not_found';
63
+ /** Present for `active` and `not_activated` only. */
63
64
  license?: LicenseInfo;
64
65
  product?: ProductRef;
65
66
  }
@@ -84,6 +85,8 @@ export interface Checkout {
84
85
  email: string | null;
85
86
  /** Where to send the customer to pay. */
86
87
  url: string;
88
+ /** ISO 8601 time the checkout was paid, or null while unpaid. */
89
+ paid_at: string | null;
87
90
  }
88
91
  export interface Totals {
89
92
  payments: number;
@@ -104,7 +107,7 @@ export interface Stats {
104
107
  };
105
108
  open_disputes: number;
106
109
  }
107
- /** `limit` is at most 500; `after` is the previous page's `next`. */
110
+ /** `limit` defaults to 50 and is at most 500; `after` is the previous page's `next`. */
108
111
  export interface PageParams {
109
112
  limit?: number;
110
113
  after?: number;
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Sendclap client for JavaScript and TypeScript: license checks for the apps you ship, and the creator REST API for your server.
2
2
  // Zero dependencies; uses the global fetch (Node 18+, Bun, Deno, browsers, Electron).
3
- export const VERSION = '0.2.0';
3
+ export const VERSION = '0.3.0';
4
4
  const DEFAULT_BASE_URL = 'https://sendclap.com';
5
5
  const DEFAULT_TIMEOUT_MS = 15000;
6
6
  // ---------- errors ----------
@@ -118,17 +118,7 @@ export class LicenseClient {
118
118
  }
119
119
  /** Checks the key (and, with an instance id, that this device is activated). Throws only when no definite answer came back. */
120
120
  async validate(licenseKey, instanceId) {
121
- try {
122
- const { valid, license, product } = await this.call('validate', licenseKey, instanceId);
123
- return { valid, status: valid ? 'active' : 'not_activated', license, product };
124
- }
125
- catch (e) {
126
- if (e instanceof InvalidLicenseError)
127
- return { valid: false, status: 'invalid' };
128
- if (e instanceof DisabledLicenseError)
129
- return { valid: false, status: 'disabled' };
130
- throw e;
131
- }
121
+ return this.call('validate', licenseKey, instanceId);
132
122
  }
133
123
  /** Releases a device, freeing one activation. Throws InstanceNotFoundError if it wasn't activated. */
134
124
  async deactivate(licenseKey, instanceId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sendclap",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Official Sendclap client: license key checks for the apps you ship and the creator REST API.",
5
5
  "license": "MIT",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/backmeupplz/sendclap-sdk.git", "directory": "js" },