renew-ip
Version:
A module for renewing 4G/LTE IP addresses on tethered Android phones from Node JS.
146 lines • 5.06 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IpHistorySchema = exports.IpDataResponseSchema = exports.PartialRouterConfigSchema = exports.RouterConfigSchema = exports.IpDataConfigSchema = exports.IpDataFieldsSchema = exports.AutomatePayloadSchema = exports.env = exports.EnvSchema = exports.RenewalPayloadContentSchema = exports.RenewalPrioritySchema = void 0;
const tslib_1 = require("tslib");
const dotenv_1 = tslib_1.__importDefault(require("dotenv"));
const zod_1 = require("zod");
/**
* Define the priority level options.
* @type {z.ZodEnum}
*/
exports.RenewalPrioritySchema = zod_1.z.enum(["normal", "high"]);
/**
* Define the trigger expected in the Automate payload.
* @type {z.ZodEnum}
*/
exports.RenewalPayloadContentSchema = zod_1.z.union([
zod_1.z.enum(["renew"]),
zod_1.z.string()
]);
/**
* Define a validation schema for environment variables.
* @type {z.ZodObject}
*/
exports.EnvSchema = zod_1.z.object({
IP_RENEWAL_SECRET: zod_1.z.string(),
IP_RENEWAL_EMAIL: zod_1.z.string(),
IP_RENEWAL_PRIORITY: exports.RenewalPrioritySchema.default("normal"),
IP_RENEWAL_PAYLOAD_CONTENT: exports.RenewalPayloadContentSchema.default("renew"),
IP_RENEWAL_MAX_ATTEMPTS: zod_1.z.number().default(3),
IP_RENEWAL_DELAY: zod_1.z.number().default(1000),
POLL_ATTEMPTS: zod_1.z.number().default(5),
POLL_TIMEOUT: zod_1.z.number().default(3000),
TOGGLE_DELAY: zod_1.z.number().default(15000),
IPDATA_API_KEY: zod_1.z.string().default("test")
});
/**
* Exports a typed env file.
* @type {RouterEnv}
*/
exports.env = exports.EnvSchema.parse(dotenv_1.default.config().parsed || {});
/**
* Define a validation schema for the request sent to the Automate endpoint.
* @type {z.ZodObject}
*/
exports.AutomatePayloadSchema = zod_1.z.object({
secret: zod_1.z.string().default(exports.env.IP_RENEWAL_SECRET),
to: zod_1.z.string().default(exports.env.IP_RENEWAL_EMAIL),
priority: exports.RenewalPrioritySchema.default(exports.env.IP_RENEWAL_PRIORITY),
device: zod_1.z.string().optional(),
payload: exports.RenewalPayloadContentSchema.default(exports.env.IP_RENEWAL_PAYLOAD_CONTENT)
});
/**
* Define the possible values for IPData field selection.
* @type {z.ZodArray}
*/
exports.IpDataFieldsSchema = zod_1.z.array(zod_1.z.enum([
"ip",
"city",
"region",
"region_code",
"postal",
"country_name",
"country_code",
"asn",
"carrier",
"time_zone",
"threat"
]));
/**
* Define validation schema for IPData vendor config.
* @type {z.ZodObject}
*/
exports.IpDataConfigSchema = zod_1.z.object({
key: zod_1.z.string().default(exports.env.IPDATA_API_KEY),
fields: exports.IpDataFieldsSchema.default([
"ip",
"city",
"region",
"region_code",
"postal",
"country_name",
"country_code",
"asn",
"carrier",
"time_zone",
"threat"
])
});
/**
* Define a validation schema for top level router config which extends the Automate schema.
* @type {z.ZodObject}
*/
exports.RouterConfigSchema = exports.AutomatePayloadSchema.extend({
maxAttempts: zod_1.z.number().default(exports.env.IP_RENEWAL_MAX_ATTEMPTS),
delay: zod_1.z.number().default(exports.env.IP_RENEWAL_DELAY),
ipdata: exports.IpDataConfigSchema.default({})
});
/**
* Define a partial of the base router config to allow passing incomplete configs.
* @type {z.ZodObject}
*/
exports.PartialRouterConfigSchema = exports.RouterConfigSchema.deepPartial();
/**
* Define the schema for an expected response from the IPData vendor service.
* @type {z.ZodObject}
*/
exports.IpDataResponseSchema = zod_1.z.object({
ip: zod_1.z.string(),
city: zod_1.z.string().optional(),
region: zod_1.z.string().optional(),
region_code: zod_1.z.string().optional(),
country_name: zod_1.z.string().optional(),
country_code: zod_1.z.string().optional(),
postal: zod_1.z.string().optional(),
time_zone: zod_1.z
.object({
name: zod_1.z.string(),
abbr: zod_1.z.string(),
offset: zod_1.z.string(),
is_dst: zod_1.z.boolean(),
current_time: zod_1.z.string()
})
.optional(),
threat: zod_1.z
.object({
is_tor: zod_1.z.boolean(),
is_proxy: zod_1.z.boolean(),
is_anonymous: zod_1.z.boolean(),
is_known_attacker: zod_1.z.boolean(),
is_known_abuser: zod_1.z.boolean(),
is_threat: zod_1.z.boolean(),
is_bogon: zod_1.z.boolean()
})
.optional(),
statusCode: zod_1.z.number().optional(),
statusMessage: zod_1.z.string().optional()
});
/**
* Define the shape of IP history records.
* @type {z.ZodObject}
*/
exports.IpHistorySchema = exports.IpDataResponseSchema.extend({
ip: zod_1.z.string(),
timestamp: zod_1.z.number()
});
//# sourceMappingURL=schemas.js.map