netlify-onegraph-internal
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -1,3 +0,2 @@ | ||
export function verifySignature(input: any): boolean; | ||
export function verifyRequestSignature(request: any, options: any): boolean; | ||
export function verifyRequestSignature(request: any, options: any): any; | ||
export function executeCreateGraphQLSchemaMutation(variables: any, options: any): Promise<any>; | ||
@@ -4,0 +3,0 @@ export function executeCreatePersistedQueryMutation(variables: any, options: any): Promise<any>; |
@@ -13,148 +13,97 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handler = exports.executeMarkCLISessionInactive = exports.executeMarkCLISessionActiveHeartbeat = exports.executeCreateNewSchemaMutation = exports.executeUpsertAppForSiteMutation = exports.fetchAppSchemaQuery = exports.executeAckCLISessionEventMutation = exports.fetchCLISessionQuery = exports.executeCreateCLISessionEventMutation = exports.executeUpdateCLISessionMetadataMutation = exports.executeCreateCLISessionMutation = exports.fetchPersistedQueryQuery = exports.fetchListPersistedQueries = exports.executeCreateApiTokenMutation = exports.executeCreatePersistedQueryMutation = exports.executeCreateGraphQLSchemaMutation = exports.verifyRequestSignature = exports.verifySignature = void 0; | ||
exports.handler = exports.executeMarkCLISessionInactive = exports.executeMarkCLISessionActiveHeartbeat = exports.executeCreateNewSchemaMutation = exports.executeUpsertAppForSiteMutation = exports.fetchAppSchemaQuery = exports.executeAckCLISessionEventMutation = exports.fetchCLISessionQuery = exports.executeCreateCLISessionEventMutation = exports.executeUpdateCLISessionMetadataMutation = exports.executeCreateCLISessionMutation = exports.fetchPersistedQueryQuery = exports.fetchListPersistedQueries = exports.executeCreateApiTokenMutation = exports.executeCreatePersistedQueryMutation = exports.executeCreateGraphQLSchemaMutation = exports.verifyRequestSignature = void 0; | ||
// GENERATED VIA NETLIFY AUTOMATED DEV TOOLS, EDIT WITH CAUTION! | ||
var buffer_1 = require("buffer"); | ||
var crypto_1 = require("crypto"); | ||
var https_1 = require("https"); | ||
var process_1 = require("process"); | ||
var verifySignature = function (input) { | ||
var secret = input.secret; | ||
var body = input.body; | ||
var signature = input.signature; | ||
if (!signature) { | ||
console.error("Missing signature"); | ||
return false; | ||
} | ||
var sig = {}; | ||
for (var _i = 0, _a = signature.split(","); _i < _a.length; _i++) { | ||
var pair = _a[_i]; | ||
var _b = pair.split("="), key = _b[0], value = _b[1]; | ||
sig[key] = value; | ||
} | ||
if (!sig.t || !sig.hmac_sha256) { | ||
console.error("Invalid signature header"); | ||
return false; | ||
} | ||
var hash = crypto_1.default | ||
.createHmac("sha256", secret) | ||
.update(sig.t) | ||
.update(".") | ||
.update(body) | ||
.digest("hex"); | ||
if (!crypto_1.default.timingSafeEqual(Buffer.from(hash, "hex"), Buffer.from(sig.hmac_sha256, "hex"))) { | ||
console.error("Invalid signature"); | ||
return false; | ||
} | ||
if (parseInt(sig.t, 10) < Date.now() / 1000 - 300 /* 5 minutes */) { | ||
console.error("Request is too old"); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
exports.verifySignature = verifySignature; | ||
var httpGet = function (input) { | ||
var userHeaders = input.headers || {}; | ||
var fullHeaders = __assign(__assign({}, userHeaders), { "Content-Type": "application/json" }); | ||
var timeoutMs = 30000; | ||
var reqOptions = { | ||
method: "GET", | ||
headers: fullHeaders, | ||
timeout: timeoutMs, | ||
}; | ||
if (!input.docId) { | ||
throw new Error("docId is required for GET requests: " + input.operationName); | ||
} | ||
var schemaId = input.schemaId || undefined; | ||
var encodedVariables = encodeURIComponent(input.variables || "null"); | ||
var url = "https://serve.onegraph.com/graphql?app_id=" + | ||
input.siteId + | ||
"&doc_id=" + | ||
input.docId + | ||
(input.operationName ? "&operationName=" + input.operationName : "") + | ||
(schemaId ? "&schemaId=" + schemaId : "") + | ||
"&variables=" + | ||
encodedVariables; | ||
var respBody = []; | ||
return new Promise(function (resolve, reject) { | ||
var req = https_1.default.request(url, reqOptions, function (res) { | ||
if (res.statusCode && (res.statusCode < 200 || res.statusCode > 299)) { | ||
return reject(new Error("Netlify Graph return non-OK HTTP status code" + res.statusCode)); | ||
} | ||
res.on("data", function (chunk) { return respBody.push(chunk); }); | ||
res.on("end", function () { | ||
var resString = buffer_1.default.Buffer.concat(respBody).toString(); | ||
resolve(resString); | ||
}); | ||
}); | ||
req.on("error", function (error) { | ||
console.error("Error making request to Netlify Graph:", error); | ||
}); | ||
req.on("timeout", function () { | ||
req.destroy(); | ||
reject(new Error("Request to Netlify Graph timed out")); | ||
}); | ||
req.end(); | ||
var fetch = require('node-fetch'); | ||
var internalConsole = require("./internalConsole").internalConsole; | ||
var httpFetch = function (siteId, options) { return __awaiter(void 0, void 0, void 0, function () { | ||
var reqBody, userHeaders, headers, timeoutMs, reqOptions, url, resp; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
reqBody = options.body || null; | ||
userHeaders = options.headers || {}; | ||
headers = __assign(__assign({}, userHeaders), { "Content-Type": "application/json", "Content-Length": reqBody.length }); | ||
timeoutMs = 30000; | ||
reqOptions = { | ||
method: "POST", | ||
headers: headers, | ||
timeout: timeoutMs, | ||
body: reqBody | ||
}; | ||
url = "https://serve.onegraph.com/graphql?app_id=" + siteId; | ||
return [4 /*yield*/, fetch(url, reqOptions)]; | ||
case 1: | ||
resp = _a.sent(); | ||
return [2 /*return*/, resp.text()]; | ||
} | ||
}); | ||
}; | ||
var httpPost = function (input) { | ||
var reqBody = input.body || null; | ||
var userHeaders = input.headers || {}; | ||
var headers = __assign(__assign({}, userHeaders), { "Content-Type": "application/json", "Content-Length": reqBody.length }); | ||
var timeoutMs = 30000; | ||
var reqOptions = { | ||
method: "POST", | ||
headers: headers, | ||
timeout: timeoutMs, | ||
}; | ||
var schemaId = input.schemaId || undefined; | ||
var url = "https://serve.onegraph.com/graphql?app_id=" + | ||
input.siteId + | ||
(schemaId ? "&schemaId=" + schemaId : ""); | ||
var respBody = []; | ||
return new Promise(function (resolve, reject) { | ||
var req = https_1.default.request(url, reqOptions, function (res) { | ||
if (res.statusCode && (res.statusCode < 200 || res.statusCode > 299)) { | ||
return reject(new Error("Netlify Graph return non-OK HTTP status code" + res.statusCode)); | ||
} | ||
res.on("data", function (chunk) { return respBody.push(chunk); }); | ||
res.on("end", function () { | ||
var resString = buffer_1.default.Buffer.concat(respBody).toString(); | ||
resolve(resString); | ||
}); }; | ||
var fetchNetlifyGraph = function fetchNetlifyGraph(input) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var query, docId, operationName, variables, options, accessToken, siteId, payload, response; | ||
return __generator(this, function (_a) { | ||
query = input.query; | ||
docId = input.doc_id; | ||
operationName = input.operationName; | ||
variables = input.variables; | ||
options = input.options || {}; | ||
accessToken = options.accessToken; | ||
siteId = options.siteId || process.env.SITE_ID; | ||
payload = { | ||
query: query, | ||
doc_id: docId, | ||
variables: variables, | ||
operationName: operationName, | ||
}; | ||
response = httpFetch(siteId, { | ||
method: "POST", | ||
headers: { | ||
Authorization: accessToken ? "Bearer " + accessToken : "", | ||
}, | ||
body: JSON.stringify(payload), | ||
}); | ||
return [2 /*return*/, response.then(function (result) { return JSON.parse(result); })]; | ||
}); | ||
req.on("error", function (error) { | ||
console.error("Error making request to Netlify Graph:", error); | ||
}); | ||
req.on("timeout", function () { | ||
req.destroy(); | ||
reject(new Error("Request to Netlify Graph timed out")); | ||
}); | ||
req.write(reqBody); | ||
req.end(); | ||
}); | ||
}; | ||
var fetchNetlifyGraph = function fetchNetlifyGraph(input) { | ||
var docId = input.doc_id; | ||
var operationName = input.operationName; | ||
var variables = input.variables; | ||
var options = input.options || {}; | ||
var accessToken = options.accessToken; | ||
var siteId = options.siteId || process_1.default.env.SITE_ID; | ||
var httpMethod = input.fetchStrategy === "GET" ? httpGet : httpPost; | ||
var response = httpMethod({ | ||
siteId: siteId, | ||
docId: docId, | ||
query: input.query, | ||
headers: { | ||
Authorization: accessToken ? "Bearer " + accessToken : "", | ||
}, | ||
variables: variables, | ||
operationName: operationName, | ||
}); | ||
return response.then(function (result) { return JSON.parse(result); }); | ||
}; | ||
var verifyRequestSignature = function (request, options) { | ||
var event = request.event; | ||
var secret = options.webhookSecret || process_1.default.env.NETLIFY_GRAPH_WEBHOOK_SECRET; | ||
var secret = options.webhookSecret || process.env.NETLIFY_GRAPH_WEBHOOK_SECRET; | ||
var signature = event.headers["x-netlify-graph-signature"]; | ||
@@ -166,3 +115,3 @@ var body = event.body; | ||
} | ||
return (0, exports.verifySignature)({ secret: secret, signature: signature, body: body || "" }); | ||
return verifySignature({ secret: secret, signature: signature, body: body || "" }); | ||
}; | ||
@@ -169,0 +118,0 @@ exports.verifyRequestSignature = verifyRequestSignature; |
{ | ||
"name": "netlify-onegraph-internal", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Internal tools for use by Netlify", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
418523
5419
10