Add .gitignore to exclude all node packages and lock files
This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
// src/is-network-error.ts
|
||||
function isNetworkError(error) {
|
||||
if (error.message.includes("Failed to fetch") || error.message.includes("Load failed") || error.message.includes("NetworkError when attempting to fetch resource")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// src/register-usage-event.ts
|
||||
var HOST = "https://www.remotion.pro";
|
||||
var DEFAULT_MAX_RETRIES = 3;
|
||||
var exponentialBackoffMs = (attempt) => {
|
||||
return 1000 * 2 ** (attempt - 1);
|
||||
};
|
||||
var sleep = (ms) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
};
|
||||
var internalRegisterUsageEvent = async ({
|
||||
host,
|
||||
succeeded,
|
||||
event,
|
||||
isStill,
|
||||
isProduction,
|
||||
licenseKey
|
||||
}) => {
|
||||
let lastError;
|
||||
const totalAttempts = DEFAULT_MAX_RETRIES + 1;
|
||||
for (let attempt = 1;attempt <= totalAttempts; attempt++) {
|
||||
const abortController = new AbortController;
|
||||
const timeout = setTimeout(() => {
|
||||
abortController.abort();
|
||||
}, 1e4);
|
||||
try {
|
||||
const res = await fetch(`${HOST}/api/track/register-usage-point`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
event,
|
||||
apiKey: licenseKey,
|
||||
host,
|
||||
succeeded,
|
||||
isStill,
|
||||
isProduction
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
signal: abortController.signal
|
||||
});
|
||||
clearTimeout(timeout);
|
||||
const json = await res.json();
|
||||
if (json.success) {
|
||||
return {
|
||||
billable: json.billable,
|
||||
classification: json.classification
|
||||
};
|
||||
}
|
||||
if (!res.ok) {
|
||||
throw new Error(json.error);
|
||||
}
|
||||
throw new Error(`Unexpected response from server: ${JSON.stringify(json)}`);
|
||||
} catch (err) {
|
||||
clearTimeout(timeout);
|
||||
const error = err;
|
||||
const isTimeout = error.name === "AbortError";
|
||||
const isRetryable = isNetworkError(error) || isTimeout;
|
||||
if (!isRetryable) {
|
||||
throw err;
|
||||
}
|
||||
lastError = isTimeout ? new Error("Request timed out after 10 seconds") : error;
|
||||
if (attempt < totalAttempts) {
|
||||
const backoffMs = exponentialBackoffMs(attempt);
|
||||
console.log(`Failed to send usage event (attempt ${attempt}/${totalAttempts}), retrying in ${backoffMs}ms...`, err);
|
||||
await sleep(backoffMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw lastError;
|
||||
};
|
||||
var registerUsageEvent = (options) => {
|
||||
const licenseKey = "licenseKey" in options ? options.licenseKey : null;
|
||||
const apiKey = "apiKey" in options ? options.apiKey : null;
|
||||
return internalRegisterUsageEvent({
|
||||
...options,
|
||||
isStill: options.isStill ?? false,
|
||||
isProduction: options.isProduction ?? true,
|
||||
licenseKey: licenseKey ?? apiKey ?? null
|
||||
});
|
||||
};
|
||||
// src/get-usage.ts
|
||||
var getUsage = async ({
|
||||
since,
|
||||
...apiOrLicenseKey
|
||||
}) => {
|
||||
const apiKey = "apiKey" in apiOrLicenseKey ? apiOrLicenseKey.apiKey : null;
|
||||
const licenseKey = "licenseKey" in apiOrLicenseKey ? apiOrLicenseKey.licenseKey : null;
|
||||
const res = await fetch(`${HOST}/api/track/get-usage`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
apiKey: licenseKey ?? apiKey,
|
||||
since: since ?? null
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.success) {
|
||||
return {
|
||||
cloudRenders: json.cloudRenders,
|
||||
webcodecConversions: json.webcodecConversions
|
||||
};
|
||||
}
|
||||
throw new Error(json.error);
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var LicensingInternals = {
|
||||
internalRegisterUsageEvent
|
||||
};
|
||||
export {
|
||||
registerUsageEvent,
|
||||
getUsage,
|
||||
LicensingInternals
|
||||
};
|
||||
Generated
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
import type { EitherApiKeyOrLicenseKey } from './register-usage-event';
|
||||
export type EventCount = {
|
||||
billable: number;
|
||||
failed: number;
|
||||
development: number;
|
||||
};
|
||||
export type GetUsageApiResponse = {
|
||||
success: true;
|
||||
cloudRenders: EventCount;
|
||||
webcodecConversions: EventCount;
|
||||
} | {
|
||||
success: false;
|
||||
error: string;
|
||||
};
|
||||
export type GetUsageResponse = {
|
||||
cloudRenders: EventCount;
|
||||
webcodecConversions: EventCount;
|
||||
};
|
||||
export declare const getUsage: ({ since, ...apiOrLicenseKey }: {
|
||||
since?: number | null;
|
||||
} & EitherApiKeyOrLicenseKey) => Promise<GetUsageResponse>;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getUsage = void 0;
|
||||
const register_usage_event_1 = require("./register-usage-event");
|
||||
const getUsage = async ({ since, ...apiOrLicenseKey }) => {
|
||||
const apiKey = 'apiKey' in apiOrLicenseKey ? apiOrLicenseKey.apiKey : null;
|
||||
const licenseKey = 'licenseKey' in apiOrLicenseKey ? apiOrLicenseKey.licenseKey : null;
|
||||
const res = await fetch(`${register_usage_event_1.HOST}/api/track/get-usage`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
apiKey: licenseKey !== null && licenseKey !== void 0 ? licenseKey : apiKey,
|
||||
since: since !== null && since !== void 0 ? since : null,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
const json = (await res.json());
|
||||
if (json.success) {
|
||||
return {
|
||||
cloudRenders: json.cloudRenders,
|
||||
webcodecConversions: json.webcodecConversions,
|
||||
};
|
||||
}
|
||||
throw new Error(json.error);
|
||||
};
|
||||
exports.getUsage = getUsage;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
export { UsageEventClassification as Classification, registerUsageEvent, RegisterUsageEventResponse, } from './register-usage-event';
|
||||
export { EventCount, getUsage, GetUsageResponse } from './get-usage';
|
||||
export declare const LicensingInternals: {
|
||||
internalRegisterUsageEvent: ({ host, succeeded, event, isStill, isProduction, licenseKey, }: {
|
||||
host: string | null;
|
||||
succeeded: boolean;
|
||||
event: "webcodec-conversion" | "cloud-render";
|
||||
} & {
|
||||
isStill: boolean;
|
||||
isProduction: boolean;
|
||||
} & {
|
||||
licenseKey: string | null;
|
||||
}) => Promise<import("./register-usage-event").RegisterUsageEventResponse>;
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LicensingInternals = exports.getUsage = exports.registerUsageEvent = void 0;
|
||||
const register_usage_event_1 = require("./register-usage-event");
|
||||
var register_usage_event_2 = require("./register-usage-event");
|
||||
Object.defineProperty(exports, "registerUsageEvent", { enumerable: true, get: function () { return register_usage_event_2.registerUsageEvent; } });
|
||||
var get_usage_1 = require("./get-usage");
|
||||
Object.defineProperty(exports, "getUsage", { enumerable: true, get: function () { return get_usage_1.getUsage; } });
|
||||
exports.LicensingInternals = {
|
||||
internalRegisterUsageEvent: register_usage_event_1.internalRegisterUsageEvent,
|
||||
};
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function isNetworkError(error: Error): boolean;
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isNetworkError = isNetworkError;
|
||||
function isNetworkError(error) {
|
||||
if (
|
||||
// Chrome
|
||||
error.message.includes('Failed to fetch') ||
|
||||
// Safari
|
||||
error.message.includes('Load failed') ||
|
||||
// Firefox
|
||||
error.message.includes('NetworkError when attempting to fetch resource')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Generated
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
export declare const HOST = "https://www.remotion.pro";
|
||||
import type { NoReactInternals } from 'remotion/no-react';
|
||||
export declare const exponentialBackoffMs: (attempt: number) => number;
|
||||
export declare const sleep: (ms: number) => Promise<void>;
|
||||
export type RegisterUsageEventResponse = {
|
||||
billable: boolean;
|
||||
classification: UsageEventClassification;
|
||||
};
|
||||
type UsageEventType = 'webcodec-conversion' | 'cloud-render';
|
||||
export type UsageEventClassification = 'billable' | 'development' | 'failed';
|
||||
export type EitherApiKeyOrLicenseKey = true extends typeof NoReactInternals.ENABLE_V5_BREAKING_CHANGES ? {
|
||||
licenseKey: string | null;
|
||||
} : {
|
||||
/**
|
||||
* @deprecated Use `licenseKey` instead
|
||||
*/
|
||||
apiKey: string | null;
|
||||
} | {
|
||||
licenseKey: string | null;
|
||||
};
|
||||
type RegisterUsageEventMandatoryOptions = {
|
||||
host: string | null;
|
||||
succeeded: boolean;
|
||||
event: UsageEventType;
|
||||
};
|
||||
type OptionalRegisterUsageEventOptional = {
|
||||
isStill: boolean;
|
||||
isProduction: boolean;
|
||||
};
|
||||
type InternalRegisterUsageEventOptions = RegisterUsageEventMandatoryOptions & OptionalRegisterUsageEventOptional & {
|
||||
licenseKey: string | null;
|
||||
};
|
||||
type RegisterUsageEventOptions = RegisterUsageEventMandatoryOptions & EitherApiKeyOrLicenseKey & Partial<OptionalRegisterUsageEventOptional>;
|
||||
export declare const internalRegisterUsageEvent: ({ host, succeeded, event, isStill, isProduction, licenseKey, }: InternalRegisterUsageEventOptions) => Promise<RegisterUsageEventResponse>;
|
||||
export declare const registerUsageEvent: (options: RegisterUsageEventOptions) => Promise<RegisterUsageEventResponse>;
|
||||
export {};
|
||||
Generated
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.registerUsageEvent = exports.internalRegisterUsageEvent = exports.sleep = exports.exponentialBackoffMs = exports.HOST = void 0;
|
||||
exports.HOST = 'https://www.remotion.pro';
|
||||
const is_network_error_1 = require("./is-network-error");
|
||||
const DEFAULT_MAX_RETRIES = 3;
|
||||
const exponentialBackoffMs = (attempt) => {
|
||||
return 1000 * 2 ** (attempt - 1);
|
||||
};
|
||||
exports.exponentialBackoffMs = exponentialBackoffMs;
|
||||
const sleep = (ms) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
};
|
||||
exports.sleep = sleep;
|
||||
const internalRegisterUsageEvent = async ({ host, succeeded, event, isStill, isProduction, licenseKey, }) => {
|
||||
let lastError;
|
||||
const totalAttempts = DEFAULT_MAX_RETRIES + 1;
|
||||
for (let attempt = 1; attempt <= totalAttempts; attempt++) {
|
||||
const abortController = new AbortController();
|
||||
const timeout = setTimeout(() => {
|
||||
abortController.abort();
|
||||
}, 10000);
|
||||
try {
|
||||
const res = await fetch(`${exports.HOST}/api/track/register-usage-point`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
event,
|
||||
apiKey: licenseKey,
|
||||
host,
|
||||
succeeded,
|
||||
isStill,
|
||||
isProduction,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
signal: abortController.signal,
|
||||
});
|
||||
clearTimeout(timeout);
|
||||
const json = (await res.json());
|
||||
if (json.success) {
|
||||
return {
|
||||
billable: json.billable,
|
||||
classification: json.classification,
|
||||
};
|
||||
}
|
||||
if (!res.ok) {
|
||||
throw new Error(json.error);
|
||||
}
|
||||
throw new Error(`Unexpected response from server: ${JSON.stringify(json)}`);
|
||||
}
|
||||
catch (err) {
|
||||
clearTimeout(timeout);
|
||||
const error = err;
|
||||
const isTimeout = error.name === 'AbortError';
|
||||
const isRetryable = (0, is_network_error_1.isNetworkError)(error) || isTimeout;
|
||||
if (!isRetryable) {
|
||||
throw err;
|
||||
}
|
||||
lastError = isTimeout
|
||||
? new Error('Request timed out after 10 seconds')
|
||||
: error;
|
||||
if (attempt < totalAttempts) {
|
||||
const backoffMs = (0, exports.exponentialBackoffMs)(attempt);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Failed to send usage event (attempt ${attempt}/${totalAttempts}), retrying in ${backoffMs}ms...`, err);
|
||||
await (0, exports.sleep)(backoffMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw lastError;
|
||||
};
|
||||
exports.internalRegisterUsageEvent = internalRegisterUsageEvent;
|
||||
const registerUsageEvent = (options) => {
|
||||
var _a, _b, _c;
|
||||
const licenseKey = 'licenseKey' in options ? options.licenseKey : null;
|
||||
const apiKey = 'apiKey' in options ? options.apiKey : null;
|
||||
return (0, exports.internalRegisterUsageEvent)({
|
||||
...options,
|
||||
isStill: (_a = options.isStill) !== null && _a !== void 0 ? _a : false,
|
||||
isProduction: (_b = options.isProduction) !== null && _b !== void 0 ? _b : true,
|
||||
licenseKey: (_c = licenseKey !== null && licenseKey !== void 0 ? licenseKey : apiKey) !== null && _c !== void 0 ? _c : null,
|
||||
});
|
||||
};
|
||||
exports.registerUsageEvent = registerUsageEvent;
|
||||
Reference in New Issue
Block a user