@phonecheck/phone-number-validator-js 2.0.0 → 2.1.0-beta.2
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/cli/index.js +44 -44
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +102 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -1
- package/dist/serverless/index.cjs.js +123 -111
- package/dist/serverless/index.cjs.js.map +1 -1
- package/dist/serverless/index.d.ts +8 -3
- package/dist/serverless/index.esm.js +112 -112
- package/dist/serverless/index.esm.js.map +1 -1
- package/package.json +2 -1
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Serverless entry point — barrel re-exports for every adapter, plus the
|
|
3
|
-
* pure validator
|
|
4
|
-
*
|
|
3
|
+
* pure validator and the helpers that custom-adapter authors need. Bundle
|
|
4
|
+
* size is dominated by `libphonenumber-js`; importing a single adapter
|
|
5
|
+
* (`./serverless/aws`, etc.) avoids pulling in the others.
|
|
5
6
|
*/
|
|
7
|
+
export { corsHeaders, jsonHeaders } from './_shared/cors';
|
|
6
8
|
export { executeValidation, type PhoneValidationResult, validateBatch, validateSingle, } from './_shared/dispatch';
|
|
7
|
-
export {
|
|
9
|
+
export { decodeLambdaBody, type LambdaLikeEvent, type LambdaResult, lambdaResponse, } from './_shared/lambda-helpers';
|
|
10
|
+
export { classifyRoute, healthPayload, type Route } from './_shared/routes';
|
|
11
|
+
export { type BatchOptions, type BatchValidation, classifyRequest, extractBatchOptions, MAX_BATCH_SIZE, type ValidationDispatch, type ValidationFailure, type ValidationRequestBody, validateBatchField, } from './_shared/validation';
|
|
12
|
+
export { jsonResponse as webJsonResponse, parseQueryParams, readJsonBody, requireJsonContentType, } from './_shared/web-helpers';
|
|
8
13
|
export { default as awsLambda } from './adapters/aws-lambda';
|
|
9
14
|
export { default as azure } from './adapters/azure';
|
|
10
15
|
export { default as cloudflare, PhoneValidatorDO } from './adapters/cloudflare';
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
function corsHeaders(methods = "GET, POST, OPTIONS") {
|
|
2
|
+
return {
|
|
3
|
+
"Access-Control-Allow-Origin": "*",
|
|
4
|
+
"Access-Control-Allow-Methods": methods,
|
|
5
|
+
"Access-Control-Allow-Headers": "Content-Type"
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function jsonHeaders(extra) {
|
|
9
|
+
return { "Content-Type": "application/json", ...extra };
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
// This file is a workaround for a bug in web browsers' "native"
|
|
2
13
|
// ES6 importing system which is uncapable of importing "*.json" files.
|
|
3
14
|
// https://github.com/catamphetamine/libphonenumber-js/issues/239
|
|
@@ -11906,6 +11917,37 @@ async function validateBatch(inputs, options = {}) {
|
|
|
11906
11917
|
return Promise.all(inputs.map((p) => validateOne(p, opts)));
|
|
11907
11918
|
}
|
|
11908
11919
|
|
|
11920
|
+
function decodeLambdaBody(event) {
|
|
11921
|
+
if (!event.body) return {};
|
|
11922
|
+
const raw = event.isBase64Encoded ? Buffer.from(event.body, "base64").toString("utf8") : event.body;
|
|
11923
|
+
try {
|
|
11924
|
+
return JSON.parse(raw);
|
|
11925
|
+
} catch {
|
|
11926
|
+
throw new SyntaxError("Invalid JSON body");
|
|
11927
|
+
}
|
|
11928
|
+
}
|
|
11929
|
+
function lambdaResponse(statusCode, body, headers) {
|
|
11930
|
+
return { statusCode, headers, body: JSON.stringify(body) };
|
|
11931
|
+
}
|
|
11932
|
+
|
|
11933
|
+
const VALIDATE_PATHS = /* @__PURE__ */ new Set(["/validate", "/validate/batch"]);
|
|
11934
|
+
function classifyRoute(path, method) {
|
|
11935
|
+
if (method === "OPTIONS") return { kind: "preflight" };
|
|
11936
|
+
if (path === "/health") {
|
|
11937
|
+
return method === "GET" ? { kind: "health" } : { kind: "method-not-allowed" };
|
|
11938
|
+
}
|
|
11939
|
+
if (path === "/validate") {
|
|
11940
|
+
return method === "POST" ? { kind: "validate-single" } : { kind: "method-not-allowed" };
|
|
11941
|
+
}
|
|
11942
|
+
if (path === "/validate/batch") {
|
|
11943
|
+
return method === "POST" ? { kind: "validate-batch" } : { kind: "method-not-allowed" };
|
|
11944
|
+
}
|
|
11945
|
+
return VALIDATE_PATHS.has(path) ? { kind: "method-not-allowed" } : { kind: "not-found" };
|
|
11946
|
+
}
|
|
11947
|
+
function healthPayload(platform) {
|
|
11948
|
+
return { status: "healthy", platform, timestamp: (/* @__PURE__ */ new Date()).toISOString() };
|
|
11949
|
+
}
|
|
11950
|
+
|
|
11909
11951
|
const MAX_BATCH_SIZE = 100;
|
|
11910
11952
|
function extractBatchOptions(body) {
|
|
11911
11953
|
return {
|
|
@@ -11945,46 +11987,43 @@ function classifyRequest(body) {
|
|
|
11945
11987
|
return MISSING_INPUT;
|
|
11946
11988
|
}
|
|
11947
11989
|
|
|
11948
|
-
|
|
11990
|
+
const TRUTHY = /* @__PURE__ */ new Set(["true", "1", "yes", "on"]);
|
|
11991
|
+
const FALSY = /* @__PURE__ */ new Set(["false", "0", "no", "off"]);
|
|
11992
|
+
function parseBoolParam(value) {
|
|
11993
|
+
if (!value) return void 0;
|
|
11994
|
+
const lower = value.toLowerCase();
|
|
11995
|
+
if (TRUTHY.has(lower)) return true;
|
|
11996
|
+
if (FALSY.has(lower)) return false;
|
|
11997
|
+
return void 0;
|
|
11998
|
+
}
|
|
11999
|
+
function parseQueryParams(url) {
|
|
12000
|
+
const q = url.searchParams;
|
|
12001
|
+
const phoneNumbers = q.get("phoneNumbers");
|
|
11949
12002
|
return {
|
|
11950
|
-
|
|
11951
|
-
"
|
|
11952
|
-
|
|
12003
|
+
phoneNumber: q.get("phoneNumber") || void 0,
|
|
12004
|
+
phoneNumbers: phoneNumbers ? phoneNumbers.split(",") : void 0,
|
|
12005
|
+
defaultCountry: q.get("defaultCountry") ?? void 0,
|
|
12006
|
+
locale: q.get("locale") ?? void 0,
|
|
12007
|
+
carrierLocale: q.get("carrierLocale") ?? void 0,
|
|
12008
|
+
geocode: parseBoolParam(q.get("geocode")),
|
|
12009
|
+
carrier: parseBoolParam(q.get("carrier")),
|
|
12010
|
+
timezones: parseBoolParam(q.get("timezones"))
|
|
11953
12011
|
};
|
|
11954
12012
|
}
|
|
11955
|
-
function
|
|
11956
|
-
return {
|
|
12013
|
+
function jsonResponse$1(status, body, headers) {
|
|
12014
|
+
return new Response(JSON.stringify(body), { status, headers });
|
|
11957
12015
|
}
|
|
11958
|
-
|
|
11959
|
-
|
|
11960
|
-
if (
|
|
11961
|
-
|
|
12016
|
+
function requireJsonContentType(request, headers) {
|
|
12017
|
+
const ct = request.headers.get("content-type");
|
|
12018
|
+
if (ct?.includes("application/json")) return null;
|
|
12019
|
+
return jsonResponse$1(400, { error: "Content-Type must be application/json" }, headers);
|
|
12020
|
+
}
|
|
12021
|
+
async function readJsonBody$2(request, headers) {
|
|
11962
12022
|
try {
|
|
11963
|
-
return
|
|
12023
|
+
return { body: await request.json() };
|
|
11964
12024
|
} catch {
|
|
11965
|
-
|
|
11966
|
-
}
|
|
11967
|
-
}
|
|
11968
|
-
function lambdaResponse(statusCode, body, headers) {
|
|
11969
|
-
return { statusCode, headers, body: JSON.stringify(body) };
|
|
11970
|
-
}
|
|
11971
|
-
|
|
11972
|
-
const VALIDATE_PATHS = /* @__PURE__ */ new Set(["/validate", "/validate/batch"]);
|
|
11973
|
-
function classifyRoute(path, method) {
|
|
11974
|
-
if (method === "OPTIONS") return { kind: "preflight" };
|
|
11975
|
-
if (path === "/health") {
|
|
11976
|
-
return method === "GET" ? { kind: "health" } : { kind: "method-not-allowed" };
|
|
11977
|
-
}
|
|
11978
|
-
if (path === "/validate") {
|
|
11979
|
-
return method === "POST" ? { kind: "validate-single" } : { kind: "method-not-allowed" };
|
|
12025
|
+
return { error: jsonResponse$1(400, { error: "Invalid request body" }, headers) };
|
|
11980
12026
|
}
|
|
11981
|
-
if (path === "/validate/batch") {
|
|
11982
|
-
return method === "POST" ? { kind: "validate-batch" } : { kind: "method-not-allowed" };
|
|
11983
|
-
}
|
|
11984
|
-
return VALIDATE_PATHS.has(path) ? { kind: "method-not-allowed" } : { kind: "not-found" };
|
|
11985
|
-
}
|
|
11986
|
-
function healthPayload(platform) {
|
|
11987
|
-
return { status: "healthy", platform, timestamp: (/* @__PURE__ */ new Date()).toISOString() };
|
|
11988
12027
|
}
|
|
11989
12028
|
|
|
11990
12029
|
const POST_HEADERS$2 = jsonHeaders(corsHeaders("POST, OPTIONS"));
|
|
@@ -12082,7 +12121,7 @@ async function handleValidateBatch$4(event) {
|
|
|
12082
12121
|
var awsLambda = { apiGatewayHandler, lambdaHandler, cacheHandler, handler: handler$1 };
|
|
12083
12122
|
|
|
12084
12123
|
const ROUTED_HEADERS$3 = jsonHeaders(corsHeaders());
|
|
12085
|
-
function jsonResponse
|
|
12124
|
+
function jsonResponse(status, body, headers = ROUTED_HEADERS$3) {
|
|
12086
12125
|
return { status, headers, jsonBody: body };
|
|
12087
12126
|
}
|
|
12088
12127
|
function pathOf$1(req) {
|
|
@@ -12097,7 +12136,7 @@ function normalizePath$2(pathname) {
|
|
|
12097
12136
|
const stripped = pathname.replace(/^\/api/, "");
|
|
12098
12137
|
return stripped || "/";
|
|
12099
12138
|
}
|
|
12100
|
-
async function readJsonBody$
|
|
12139
|
+
async function readJsonBody$1(req) {
|
|
12101
12140
|
try {
|
|
12102
12141
|
return await req.json();
|
|
12103
12142
|
} catch {
|
|
@@ -12110,11 +12149,11 @@ async function azureHandler(req, _context) {
|
|
|
12110
12149
|
case "preflight":
|
|
12111
12150
|
return { status: 204, headers: corsHeaders() };
|
|
12112
12151
|
case "health":
|
|
12113
|
-
return jsonResponse
|
|
12152
|
+
return jsonResponse(200, healthPayload("azure"));
|
|
12114
12153
|
case "method-not-allowed":
|
|
12115
|
-
return jsonResponse
|
|
12154
|
+
return jsonResponse(405, { error: "Method not allowed" });
|
|
12116
12155
|
case "not-found":
|
|
12117
|
-
return jsonResponse
|
|
12156
|
+
return jsonResponse(404, { error: "Not found" });
|
|
12118
12157
|
case "validate-single":
|
|
12119
12158
|
return handleValidateSingle$3(req);
|
|
12120
12159
|
case "validate-batch":
|
|
@@ -12123,31 +12162,31 @@ async function azureHandler(req, _context) {
|
|
|
12123
12162
|
}
|
|
12124
12163
|
async function handleValidateSingle$3(req) {
|
|
12125
12164
|
try {
|
|
12126
|
-
const body = await readJsonBody$
|
|
12127
|
-
if (!body.phoneNumber) return jsonResponse
|
|
12165
|
+
const body = await readJsonBody$1(req);
|
|
12166
|
+
if (!body.phoneNumber) return jsonResponse(400, { error: "phoneNumber is required" });
|
|
12128
12167
|
const result = await validateSingle(body.phoneNumber, extractBatchOptions(body));
|
|
12129
|
-
return jsonResponse
|
|
12168
|
+
return jsonResponse(200, result);
|
|
12130
12169
|
} catch (error) {
|
|
12131
|
-
if (error instanceof SyntaxError) return jsonResponse
|
|
12170
|
+
if (error instanceof SyntaxError) return jsonResponse(400, { error: "Invalid request body" });
|
|
12132
12171
|
console.error("Azure validation error:", error);
|
|
12133
|
-
return jsonResponse
|
|
12172
|
+
return jsonResponse(500, { error: "Internal server error" });
|
|
12134
12173
|
}
|
|
12135
12174
|
}
|
|
12136
12175
|
async function handleValidateBatch$3(req) {
|
|
12137
12176
|
try {
|
|
12138
|
-
const body = await readJsonBody$
|
|
12177
|
+
const body = await readJsonBody$1(req);
|
|
12139
12178
|
const validated = validateBatchField(body.phoneNumbers);
|
|
12140
|
-
if (!validated.ok) return jsonResponse
|
|
12179
|
+
if (!validated.ok) return jsonResponse(validated.status, { error: validated.message });
|
|
12141
12180
|
const results = await executeValidation({
|
|
12142
12181
|
kind: "batch",
|
|
12143
12182
|
phoneNumbers: validated.phoneNumbers,
|
|
12144
12183
|
options: extractBatchOptions(body)
|
|
12145
12184
|
});
|
|
12146
|
-
return jsonResponse
|
|
12185
|
+
return jsonResponse(200, { results });
|
|
12147
12186
|
} catch (error) {
|
|
12148
|
-
if (error instanceof SyntaxError) return jsonResponse
|
|
12187
|
+
if (error instanceof SyntaxError) return jsonResponse(400, { error: "Invalid request body" });
|
|
12149
12188
|
console.error("Azure batch validation error:", error);
|
|
12150
|
-
return jsonResponse
|
|
12189
|
+
return jsonResponse(500, { error: "Internal server error" });
|
|
12151
12190
|
}
|
|
12152
12191
|
}
|
|
12153
12192
|
async function azureFunction(req, _context) {
|
|
@@ -12155,64 +12194,25 @@ async function azureFunction(req, _context) {
|
|
|
12155
12194
|
return { status: 204, headers: corsHeaders("POST, OPTIONS") };
|
|
12156
12195
|
}
|
|
12157
12196
|
if (req.method !== "POST") {
|
|
12158
|
-
return jsonResponse
|
|
12197
|
+
return jsonResponse(405, { success: false, error: "Method not allowed" });
|
|
12159
12198
|
}
|
|
12160
12199
|
try {
|
|
12161
|
-
const body = await readJsonBody$
|
|
12200
|
+
const body = await readJsonBody$1(req);
|
|
12162
12201
|
const classified = classifyRequest(body);
|
|
12163
12202
|
if (classified.kind === "invalid") {
|
|
12164
|
-
return jsonResponse
|
|
12203
|
+
return jsonResponse(classified.status, { success: false, error: classified.message });
|
|
12165
12204
|
}
|
|
12166
12205
|
const data = await executeValidation(classified);
|
|
12167
|
-
return jsonResponse
|
|
12206
|
+
return jsonResponse(200, { success: true, data });
|
|
12168
12207
|
} catch (error) {
|
|
12169
|
-
if (error instanceof SyntaxError) return jsonResponse
|
|
12208
|
+
if (error instanceof SyntaxError) return jsonResponse(400, { success: false, error: "Invalid request body" });
|
|
12170
12209
|
console.error("Azure function error:", error);
|
|
12171
12210
|
const message = error instanceof Error ? error.message : "Internal server error";
|
|
12172
|
-
return jsonResponse
|
|
12211
|
+
return jsonResponse(500, { success: false, error: message });
|
|
12173
12212
|
}
|
|
12174
12213
|
}
|
|
12175
12214
|
var azure = { azureHandler, azureFunction };
|
|
12176
12215
|
|
|
12177
|
-
const TRUTHY = /* @__PURE__ */ new Set(["true", "1", "yes", "on"]);
|
|
12178
|
-
const FALSY = /* @__PURE__ */ new Set(["false", "0", "no", "off"]);
|
|
12179
|
-
function parseBoolParam(value) {
|
|
12180
|
-
if (!value) return void 0;
|
|
12181
|
-
const lower = value.toLowerCase();
|
|
12182
|
-
if (TRUTHY.has(lower)) return true;
|
|
12183
|
-
if (FALSY.has(lower)) return false;
|
|
12184
|
-
return void 0;
|
|
12185
|
-
}
|
|
12186
|
-
function parseQueryParams(url) {
|
|
12187
|
-
const q = url.searchParams;
|
|
12188
|
-
const phoneNumbers = q.get("phoneNumbers");
|
|
12189
|
-
return {
|
|
12190
|
-
phoneNumber: q.get("phoneNumber") || void 0,
|
|
12191
|
-
phoneNumbers: phoneNumbers ? phoneNumbers.split(",") : void 0,
|
|
12192
|
-
defaultCountry: q.get("defaultCountry") ?? void 0,
|
|
12193
|
-
locale: q.get("locale") ?? void 0,
|
|
12194
|
-
carrierLocale: q.get("carrierLocale") ?? void 0,
|
|
12195
|
-
geocode: parseBoolParam(q.get("geocode")),
|
|
12196
|
-
carrier: parseBoolParam(q.get("carrier")),
|
|
12197
|
-
timezones: parseBoolParam(q.get("timezones"))
|
|
12198
|
-
};
|
|
12199
|
-
}
|
|
12200
|
-
function jsonResponse(status, body, headers) {
|
|
12201
|
-
return new Response(JSON.stringify(body), { status, headers });
|
|
12202
|
-
}
|
|
12203
|
-
function requireJsonContentType(request, headers) {
|
|
12204
|
-
const ct = request.headers.get("content-type");
|
|
12205
|
-
if (ct?.includes("application/json")) return null;
|
|
12206
|
-
return jsonResponse(400, { error: "Content-Type must be application/json" }, headers);
|
|
12207
|
-
}
|
|
12208
|
-
async function readJsonBody$1(request, headers) {
|
|
12209
|
-
try {
|
|
12210
|
-
return { body: await request.json() };
|
|
12211
|
-
} catch {
|
|
12212
|
-
return { error: jsonResponse(400, { error: "Invalid request body" }, headers) };
|
|
12213
|
-
}
|
|
12214
|
-
}
|
|
12215
|
-
|
|
12216
12216
|
class KvResourceLoader {
|
|
12217
12217
|
constructor(options) {
|
|
12218
12218
|
this.namespace = options.namespace;
|
|
@@ -12251,10 +12251,10 @@ async function workerHandler(request, env, ctx) {
|
|
|
12251
12251
|
}
|
|
12252
12252
|
try {
|
|
12253
12253
|
const body = await readBody(request);
|
|
12254
|
-
if (!body) return jsonResponse(405, { success: false, error: "Method not allowed" }, POST_HEADERS$1);
|
|
12254
|
+
if (!body) return jsonResponse$1(405, { success: false, error: "Method not allowed" }, POST_HEADERS$1);
|
|
12255
12255
|
const classified = classifyRequest(body);
|
|
12256
12256
|
if (classified.kind === "invalid") {
|
|
12257
|
-
return jsonResponse(classified.status, { success: false, error: classified.message }, POST_HEADERS$1);
|
|
12257
|
+
return jsonResponse$1(classified.status, { success: false, error: classified.message }, POST_HEADERS$1);
|
|
12258
12258
|
}
|
|
12259
12259
|
if (classified.kind === "single" && resultCache) {
|
|
12260
12260
|
const cached = await resultCache.get(`phone:${classified.phoneNumber}`);
|
|
@@ -12268,7 +12268,7 @@ async function workerHandler(request, env, ctx) {
|
|
|
12268
12268
|
} catch (error) {
|
|
12269
12269
|
console.error("Cloudflare Workers error:", error);
|
|
12270
12270
|
const message = error instanceof Error ? error.message : "Internal server error";
|
|
12271
|
-
return jsonResponse(500, { success: false, error: message }, POST_HEADERS$1);
|
|
12271
|
+
return jsonResponse$1(500, { success: false, error: message }, POST_HEADERS$1);
|
|
12272
12272
|
}
|
|
12273
12273
|
}
|
|
12274
12274
|
async function readBody(request) {
|
|
@@ -12537,13 +12537,13 @@ async function edgeHandler(request) {
|
|
|
12537
12537
|
}
|
|
12538
12538
|
try {
|
|
12539
12539
|
const body = await readEdgeBody(request);
|
|
12540
|
-
if (!body) return jsonResponse(405, { success: false, error: "Method not allowed" }, POST_HEADERS);
|
|
12540
|
+
if (!body) return jsonResponse$1(405, { success: false, error: "Method not allowed" }, POST_HEADERS);
|
|
12541
12541
|
const classified = classifyRequest(body);
|
|
12542
12542
|
if (classified.kind === "invalid") {
|
|
12543
|
-
return jsonResponse(classified.status, { success: false, error: classified.message }, POST_HEADERS);
|
|
12543
|
+
return jsonResponse$1(classified.status, { success: false, error: classified.message }, POST_HEADERS);
|
|
12544
12544
|
}
|
|
12545
12545
|
const data = await executeValidation(classified);
|
|
12546
|
-
return jsonResponse(
|
|
12546
|
+
return jsonResponse$1(
|
|
12547
12547
|
200,
|
|
12548
12548
|
{ success: true, data },
|
|
12549
12549
|
jsonHeaders({ ...corsHeaders("POST, GET, OPTIONS"), "Cache-Control": "public, max-age=3600" })
|
|
@@ -12551,7 +12551,7 @@ async function edgeHandler(request) {
|
|
|
12551
12551
|
} catch (error) {
|
|
12552
12552
|
console.error("Vercel Edge error:", error);
|
|
12553
12553
|
const message = error instanceof Error ? error.message : "Internal server error";
|
|
12554
|
-
return jsonResponse(500, { success: false, error: message }, POST_HEADERS);
|
|
12554
|
+
return jsonResponse$1(500, { success: false, error: message }, POST_HEADERS);
|
|
12555
12555
|
}
|
|
12556
12556
|
}
|
|
12557
12557
|
async function readEdgeBody(request) {
|
|
@@ -12604,11 +12604,11 @@ async function handler(request) {
|
|
|
12604
12604
|
case "preflight":
|
|
12605
12605
|
return new Response(null, { status: 204, headers: corsHeaders() });
|
|
12606
12606
|
case "health":
|
|
12607
|
-
return jsonResponse(200, healthPayload("vercel"), ROUTED_HEADERS);
|
|
12607
|
+
return jsonResponse$1(200, healthPayload("vercel"), ROUTED_HEADERS);
|
|
12608
12608
|
case "method-not-allowed":
|
|
12609
|
-
return jsonResponse(405, { error: "Method not allowed" }, ROUTED_HEADERS);
|
|
12609
|
+
return jsonResponse$1(405, { error: "Method not allowed" }, ROUTED_HEADERS);
|
|
12610
12610
|
case "not-found":
|
|
12611
|
-
return jsonResponse(404, { error: "Not found" }, ROUTED_HEADERS);
|
|
12611
|
+
return jsonResponse$1(404, { error: "Not found" }, ROUTED_HEADERS);
|
|
12612
12612
|
case "validate-single":
|
|
12613
12613
|
return handleValidateSingle(request);
|
|
12614
12614
|
case "validate-batch":
|
|
@@ -12618,36 +12618,36 @@ async function handler(request) {
|
|
|
12618
12618
|
async function handleValidateSingle(request) {
|
|
12619
12619
|
const ct = requireJsonContentType(request, ROUTED_HEADERS);
|
|
12620
12620
|
if (ct) return ct;
|
|
12621
|
-
const parsed = await readJsonBody$
|
|
12621
|
+
const parsed = await readJsonBody$2(request, ROUTED_HEADERS);
|
|
12622
12622
|
if ("error" in parsed) return parsed.error;
|
|
12623
12623
|
const body = parsed.body;
|
|
12624
|
-
if (!body.phoneNumber) return jsonResponse(400, { error: "phoneNumber is required" }, ROUTED_HEADERS);
|
|
12624
|
+
if (!body.phoneNumber) return jsonResponse$1(400, { error: "phoneNumber is required" }, ROUTED_HEADERS);
|
|
12625
12625
|
try {
|
|
12626
12626
|
const result = await validateSingle(body.phoneNumber, extractBatchOptions(body));
|
|
12627
|
-
return jsonResponse(200, result, ROUTED_HEADERS);
|
|
12627
|
+
return jsonResponse$1(200, result, ROUTED_HEADERS);
|
|
12628
12628
|
} catch (error) {
|
|
12629
12629
|
console.error("Vercel validation error:", error);
|
|
12630
|
-
return jsonResponse(500, { error: "Internal server error" }, ROUTED_HEADERS);
|
|
12630
|
+
return jsonResponse$1(500, { error: "Internal server error" }, ROUTED_HEADERS);
|
|
12631
12631
|
}
|
|
12632
12632
|
}
|
|
12633
12633
|
async function handleValidateBatch(request) {
|
|
12634
12634
|
const ct = requireJsonContentType(request, ROUTED_HEADERS);
|
|
12635
12635
|
if (ct) return ct;
|
|
12636
|
-
const parsed = await readJsonBody$
|
|
12636
|
+
const parsed = await readJsonBody$2(request, ROUTED_HEADERS);
|
|
12637
12637
|
if ("error" in parsed) return parsed.error;
|
|
12638
12638
|
const body = parsed.body;
|
|
12639
12639
|
const validated = validateBatchField(body.phoneNumbers);
|
|
12640
|
-
if (!validated.ok) return jsonResponse(validated.status, { error: validated.message }, ROUTED_HEADERS);
|
|
12640
|
+
if (!validated.ok) return jsonResponse$1(validated.status, { error: validated.message }, ROUTED_HEADERS);
|
|
12641
12641
|
try {
|
|
12642
12642
|
const results = await executeValidation({
|
|
12643
12643
|
kind: "batch",
|
|
12644
12644
|
phoneNumbers: validated.phoneNumbers,
|
|
12645
12645
|
options: extractBatchOptions(body)
|
|
12646
12646
|
});
|
|
12647
|
-
return jsonResponse(200, { results }, ROUTED_HEADERS);
|
|
12647
|
+
return jsonResponse$1(200, { results }, ROUTED_HEADERS);
|
|
12648
12648
|
} catch (error) {
|
|
12649
12649
|
console.error("Vercel batch validation error:", error);
|
|
12650
|
-
return jsonResponse(500, { error: "Internal server error" }, ROUTED_HEADERS);
|
|
12650
|
+
return jsonResponse$1(500, { error: "Internal server error" }, ROUTED_HEADERS);
|
|
12651
12651
|
}
|
|
12652
12652
|
}
|
|
12653
12653
|
var vercel = { edgeHandler, nodeHandler, handler };
|
|
@@ -12676,5 +12676,5 @@ class FetchResourceLoader {
|
|
|
12676
12676
|
}
|
|
12677
12677
|
}
|
|
12678
12678
|
|
|
12679
|
-
export { AsYouType, AsYouType$1 as AsYouTypeCustom, DEFAULT_CACHE_SIZE, DIGITS, DIGIT_PLACEHOLDER, FetchResourceLoader, KvResourceLoader, MAX_BATCH_SIZE, Metadata, ParseError, PhoneNumber, PhoneNumberMatcher, PhoneNumberSearch, PhoneNumberSearch$1 as PhoneNumberSearchCustom, PhoneValidatorDO, awsLambda, azure, carrier, carrierAsync, classifyRequest, clearCache, cloudflare, enrichPhoneNumber, executeValidation, findNumbers, findPhoneNumbers, findPhoneNumbers$1 as findPhoneNumbersCustom, findPhoneNumbersInText, format, formatNumber as formatCustom, formatIncompletePhoneNumber, format as formatNumber, formatRFC3966, gcp, geocoder, geocoderAsync, getCacheSize, getCacheStats, getCountries, getCountryCallingCode, getCountryCallingCode$1 as getCountryCallingCodeCustom, getExampleNumber, getExtPrefix, getNumberType, getNumberType$1 as getNumberTypeCustom, getCountryCallingCode as getPhoneCode, getCountryCallingCode$1 as getPhoneCodeCustom, getResourceLoader, isPossibleNumber, isPossiblePhoneNumber, isSupportedCountry, isValidNumber, isValidNumber$1 as isValidNumberCustom, isValidNumberForRegion, isValidPhoneNumber, netlify, parse$1 as parse, parseNumber as parseCustom, parseDigits, parseIncompletePhoneNumber, parse$1 as parseNumber, parsePhoneNumberWithError as parsePhoneNumber, parsePhoneNumberCharacter, parsePhoneNumber as parsePhoneNumberFromString, parsePhoneNumberWithError, parseRFC3966, searchNumbers, searchPhoneNumbers, searchPhoneNumbers$1 as searchPhoneNumbersCustom, searchPhoneNumbersInText, setCacheSize, setResourceLoader, timezones, timezonesAsync, validateBatch, validatePhoneNumberLength, validateSingle, vercel };
|
|
12679
|
+
export { AsYouType, AsYouType$1 as AsYouTypeCustom, DEFAULT_CACHE_SIZE, DIGITS, DIGIT_PLACEHOLDER, FetchResourceLoader, KvResourceLoader, MAX_BATCH_SIZE, Metadata, ParseError, PhoneNumber, PhoneNumberMatcher, PhoneNumberSearch, PhoneNumberSearch$1 as PhoneNumberSearchCustom, PhoneValidatorDO, awsLambda, azure, carrier, carrierAsync, classifyRequest, classifyRoute, clearCache, cloudflare, corsHeaders, decodeLambdaBody, enrichPhoneNumber, executeValidation, extractBatchOptions, findNumbers, findPhoneNumbers, findPhoneNumbers$1 as findPhoneNumbersCustom, findPhoneNumbersInText, format, formatNumber as formatCustom, formatIncompletePhoneNumber, format as formatNumber, formatRFC3966, gcp, geocoder, geocoderAsync, getCacheSize, getCacheStats, getCountries, getCountryCallingCode, getCountryCallingCode$1 as getCountryCallingCodeCustom, getExampleNumber, getExtPrefix, getNumberType, getNumberType$1 as getNumberTypeCustom, getCountryCallingCode as getPhoneCode, getCountryCallingCode$1 as getPhoneCodeCustom, getResourceLoader, healthPayload, isPossibleNumber, isPossiblePhoneNumber, isSupportedCountry, isValidNumber, isValidNumber$1 as isValidNumberCustom, isValidNumberForRegion, isValidPhoneNumber, jsonHeaders, lambdaResponse, netlify, parse$1 as parse, parseNumber as parseCustom, parseDigits, parseIncompletePhoneNumber, parse$1 as parseNumber, parsePhoneNumberWithError as parsePhoneNumber, parsePhoneNumberCharacter, parsePhoneNumber as parsePhoneNumberFromString, parsePhoneNumberWithError, parseQueryParams, parseRFC3966, readJsonBody$2 as readJsonBody, requireJsonContentType, searchNumbers, searchPhoneNumbers, searchPhoneNumbers$1 as searchPhoneNumbersCustom, searchPhoneNumbersInText, setCacheSize, setResourceLoader, timezones, timezonesAsync, validateBatch, validateBatchField, validatePhoneNumberLength, validateSingle, vercel, jsonResponse$1 as webJsonResponse };
|
|
12680
12680
|
//# sourceMappingURL=index.esm.js.map
|