@remotion/licensing 4.0.403 → 4.0.405
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/dist/esm/index.mjs +57 -38
- package/dist/register-usage-event.d.ts +2 -0
- package/dist/register-usage-event.js +63 -40
- package/package.json +5 -4
package/dist/esm/index.mjs
CHANGED
|
@@ -8,54 +8,73 @@ function isNetworkError(error) {
|
|
|
8
8
|
|
|
9
9
|
// src/register-usage-event.ts
|
|
10
10
|
var HOST = "https://www.remotion.pro";
|
|
11
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
12
|
+
var exponentialBackoffMs = (attempt) => {
|
|
13
|
+
return 1000 * 2 ** (attempt - 1);
|
|
14
|
+
};
|
|
15
|
+
var sleep = (ms) => {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
setTimeout(resolve, ms);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
11
20
|
var registerUsageEvent = async ({
|
|
12
21
|
host,
|
|
13
22
|
succeeded,
|
|
14
23
|
event,
|
|
15
24
|
...apiOrLicenseKey
|
|
16
25
|
}) => {
|
|
17
|
-
const abortController = new AbortController;
|
|
18
|
-
const timeout = setTimeout(() => {
|
|
19
|
-
abortController.abort();
|
|
20
|
-
}, 1e4);
|
|
21
26
|
const apiKey = "apiKey" in apiOrLicenseKey ? apiOrLicenseKey.apiKey : null;
|
|
22
27
|
const licenseKey = "licenseKey" in apiOrLicenseKey ? apiOrLicenseKey.licenseKey : null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
throw new Error(
|
|
28
|
+
let lastError;
|
|
29
|
+
const totalAttempts = DEFAULT_MAX_RETRIES + 1;
|
|
30
|
+
for (let attempt = 1;attempt <= totalAttempts; attempt++) {
|
|
31
|
+
const abortController = new AbortController;
|
|
32
|
+
const timeout = setTimeout(() => {
|
|
33
|
+
abortController.abort();
|
|
34
|
+
}, 1e4);
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(`${HOST}/api/track/register-usage-point`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
event,
|
|
40
|
+
apiKey: licenseKey ?? apiKey,
|
|
41
|
+
host,
|
|
42
|
+
succeeded
|
|
43
|
+
}),
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json"
|
|
46
|
+
},
|
|
47
|
+
signal: abortController.signal
|
|
48
|
+
});
|
|
49
|
+
clearTimeout(timeout);
|
|
50
|
+
const json = await res.json();
|
|
51
|
+
if (json.success) {
|
|
52
|
+
return {
|
|
53
|
+
billable: json.billable,
|
|
54
|
+
classification: json.classification
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
throw new Error(json.error);
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Unexpected response from server: ${JSON.stringify(json)}`);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
clearTimeout(timeout);
|
|
63
|
+
const error = err;
|
|
64
|
+
const isTimeout = error.name === "AbortError";
|
|
65
|
+
const isRetryable = isNetworkError(error) || isTimeout;
|
|
66
|
+
if (!isRetryable) {
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
lastError = isTimeout ? new Error("Request timed out after 10 seconds") : error;
|
|
70
|
+
if (attempt < totalAttempts) {
|
|
71
|
+
const backoffMs = exponentialBackoffMs(attempt);
|
|
72
|
+
console.log(`Failed to send usage event (attempt ${attempt}/${totalAttempts}), retrying in ${backoffMs}ms...`, err);
|
|
73
|
+
await sleep(backoffMs);
|
|
74
|
+
}
|
|
56
75
|
}
|
|
57
|
-
throw err;
|
|
58
76
|
}
|
|
77
|
+
throw lastError;
|
|
59
78
|
};
|
|
60
79
|
// src/get-usage.ts
|
|
61
80
|
var getUsage = async ({
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const HOST = "https://www.remotion.pro";
|
|
2
2
|
import type { NoReactInternals } from 'remotion/no-react';
|
|
3
|
+
export declare const exponentialBackoffMs: (attempt: number) => number;
|
|
4
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
3
5
|
export type RegisterUsageEventResponse = {
|
|
4
6
|
billable: boolean;
|
|
5
7
|
classification: UsageEventClassification;
|
|
@@ -1,52 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerUsageEvent = exports.HOST = void 0;
|
|
3
|
+
exports.registerUsageEvent = exports.sleep = exports.exponentialBackoffMs = exports.HOST = void 0;
|
|
4
4
|
exports.HOST = 'https://www.remotion.pro';
|
|
5
5
|
const is_network_error_1 = require("./is-network-error");
|
|
6
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
7
|
+
const exponentialBackoffMs = (attempt) => {
|
|
8
|
+
return 1000 * 2 ** (attempt - 1);
|
|
9
|
+
};
|
|
10
|
+
exports.exponentialBackoffMs = exponentialBackoffMs;
|
|
11
|
+
const sleep = (ms) => {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
setTimeout(resolve, ms);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.sleep = sleep;
|
|
6
17
|
const registerUsageEvent = async ({ host, succeeded, event, ...apiOrLicenseKey }) => {
|
|
7
|
-
const abortController = new AbortController();
|
|
8
|
-
const timeout = setTimeout(() => {
|
|
9
|
-
abortController.abort();
|
|
10
|
-
}, 10000);
|
|
11
18
|
const apiKey = 'apiKey' in apiOrLicenseKey ? apiOrLicenseKey.apiKey : null;
|
|
12
19
|
const licenseKey = 'licenseKey' in apiOrLicenseKey ? apiOrLicenseKey.licenseKey : null;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
let lastError;
|
|
21
|
+
const totalAttempts = DEFAULT_MAX_RETRIES + 1;
|
|
22
|
+
for (let attempt = 1; attempt <= totalAttempts; attempt++) {
|
|
23
|
+
const abortController = new AbortController();
|
|
24
|
+
const timeout = setTimeout(() => {
|
|
25
|
+
abortController.abort();
|
|
26
|
+
}, 10000);
|
|
27
|
+
try {
|
|
28
|
+
const res = await fetch(`${exports.HOST}/api/track/register-usage-point`, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
event,
|
|
32
|
+
apiKey: licenseKey !== null && licenseKey !== void 0 ? licenseKey : apiKey,
|
|
33
|
+
host,
|
|
34
|
+
succeeded,
|
|
35
|
+
}),
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
},
|
|
39
|
+
signal: abortController.signal,
|
|
40
|
+
});
|
|
41
|
+
clearTimeout(timeout);
|
|
42
|
+
const json = (await res.json());
|
|
43
|
+
if (json.success) {
|
|
44
|
+
return {
|
|
45
|
+
billable: json.billable,
|
|
46
|
+
classification: json.classification,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
throw new Error(json.error);
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`Unexpected response from server: ${JSON.stringify(json)}`);
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
catch (err) {
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
const error = err;
|
|
57
|
+
const isTimeout = error.name === 'AbortError';
|
|
58
|
+
const isRetryable = (0, is_network_error_1.isNetworkError)(error) || isTimeout;
|
|
59
|
+
if (!isRetryable) {
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
lastError = isTimeout
|
|
63
|
+
? new Error('Request timed out after 10 seconds')
|
|
64
|
+
: error;
|
|
65
|
+
if (attempt < totalAttempts) {
|
|
66
|
+
const backoffMs = (0, exports.exponentialBackoffMs)(attempt);
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.log(`Failed to send usage event (attempt ${attempt}/${totalAttempts}), retrying in ${backoffMs}ms...`, err);
|
|
69
|
+
await (0, exports.sleep)(backoffMs);
|
|
70
|
+
}
|
|
48
71
|
}
|
|
49
|
-
throw err;
|
|
50
72
|
}
|
|
73
|
+
throw lastError;
|
|
51
74
|
};
|
|
52
75
|
exports.registerUsageEvent = registerUsageEvent;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/licensing"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/licensing",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.405",
|
|
7
7
|
"description": "Manage your Remotion.pro license",
|
|
8
8
|
"main": "dist",
|
|
9
9
|
"sideEffects": false,
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"lint": "eslint src",
|
|
12
12
|
"formatting": "prettier --experimental-cli src --check",
|
|
13
13
|
"make": "tsc -d && bun --env-file=../.env.bundle bundle.ts",
|
|
14
|
-
"test": "bun test src/test/prod-domain.test.ts"
|
|
14
|
+
"test": "bun test src/test/prod-domain.test.ts src/test/register-usage-event-retry.test.ts"
|
|
15
15
|
},
|
|
16
16
|
"author": "Jonny Burger <jonny@remotion.dev>",
|
|
17
17
|
"contributors": [],
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
27
|
+
"@remotion/eslint-config-internal": "4.0.405",
|
|
28
28
|
"eslint": "9.19.0",
|
|
29
|
-
"
|
|
29
|
+
"msw": "^2.7.1",
|
|
30
|
+
"remotion": "4.0.405"
|
|
30
31
|
},
|
|
31
32
|
"homepage": "https://www.remotion.dev/docs/licensing",
|
|
32
33
|
"exports": {
|