UNPKG

netsuite-oauth-client

Version:

NetSuite OAuth 1.0 client library for Node.js with TypeScript support

33 lines 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCredentials = validateCredentials; exports.validateRequestParams = validateRequestParams; const errors_1 = require("../errors"); function validateCredentials(credentials) { const requiredFields = ['accountid', 'consumerkey', 'consumersecret', 'tokenkey', 'tokensecret']; for (const field of requiredFields) { if (!credentials[field] || typeof credentials[field] !== 'string') { throw new errors_1.ValidationError(`Missing or invalid credential: ${field}`); } } } function validateRequestParams(requestUrl, httpMethod) { if (!requestUrl || typeof requestUrl !== 'string') { throw new errors_1.ValidationError('Invalid or missing requestUrl'); } if (!httpMethod || typeof httpMethod !== 'string') { throw new errors_1.ValidationError('Invalid or missing httpMethod'); } try { new URL(requestUrl); } catch { throw new errors_1.ValidationError('Invalid URL format'); } const validMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']; if (!validMethods.includes(httpMethod.toUpperCase())) { throw new errors_1.ValidationError(`Invalid HTTP method: ${httpMethod}`); } } //# sourceMappingURL=validation.js.map