Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

netlify-onegraph-internal

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netlify-onegraph-internal - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

2

dist/generatedOneGraphClient.d.ts

@@ -0,1 +1,3 @@

export function verifySignature(input: any): boolean;
export function verifyRequestSignature(request: any, options: any): boolean;
export function executeCreateGraphQLSchemaMutation(variables: any, options: any): Promise<any>;

@@ -2,0 +4,0 @@ export function executeCreatePersistedQueryMutation(variables: any, options: any): Promise<any>;

233

dist/generatedOneGraphClient.js

@@ -13,94 +13,157 @@ "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());
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;
// 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 __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;
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));
}
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 = void 0;
// GENERATED VIA NETLIFY AUTOMATED DEV TOOLS, EDIT WITH CAUTION!
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 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),
res.on("data", function (chunk) { return respBody.push(chunk); });
res.on("end", function () {
var resString = buffer_1.default.Buffer.concat(respBody).toString();
resolve(resString);
});
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 signature = event.headers["x-netlify-graph-signature"];
var body = event.body;
if (!secret) {
console.error("NETLIFY_GRAPH_WEBHOOK_SECRET is not set, cannot verify incoming webhook request");
return false;
}
return (0, exports.verifySignature)({ secret: secret, signature: signature, body: body || "" });
};
exports.verifyRequestSignature = verifyRequestSignature;
var executeCreateGraphQLSchemaMutation = function (variables, options) {

@@ -107,0 +170,0 @@ return fetchNetlifyGraph({

@@ -111,3 +111,3 @@ "use strict";

var generatedNetlifyGraphPersistedClient = function (netlifyGraphConfig, schemaId) {
return out(netlifyGraphConfig, ["node"], "const httpGet = (input) => {\n const userHeaders = input.headers || {};\n const fullHeaders = {\n ...userHeaders,\n 'Content-Type': 'application/json'\n };\n const timeoutMs = 30_000\n const reqOptions = {\n method: 'GET',\n headers: fullHeaders,\n timeout: timeoutMs,\n };\n\n if (!input.docId) {\n throw new Error('docId is required for GET requests: ' + input.operationName);\n }\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n const encodedVariables = encodeURIComponent(input.variables || \"null\");\n const url = 'https://serve.onegraph.com/graphql?app_id=' + input.siteId + '&doc_id=' + input.docId + (input.operationName ? ('&operationName=' + input.operationName) : '') + (schemaId ? ('&schemaId=' + schemaId) : '') + '&variables=' + encodedVariables;\n \n const respBody = []\n\n return new Promise((resolve, reject) => {\n const req = https.request(url, reqOptions, (res) => {\n if (res.statusCode && (res.statusCode < 200 || res.statusCode > 299)) {\n return reject(\n new Error(\n \"Netlify Graph return non-OK HTTP status code\" + res.statusCode,\n ),\n )\n }\n\n res.on('data', (chunk) => respBody.push(chunk))\n\n res.on('end', () => {\n const resString = buffer.Buffer.concat(respBody).toString()\n resolve(resString)\n })\n })\n\n req.on('error', (error) => {\n console.error('Error making request to Netlify Graph:', error)\n })\n\n req.on('timeout', () => {\n req.destroy()\n reject(new Error('Request to Netlify Graph timed out'))\n })\n\n req.end()\n })\n}\n\nconst httpPost = (input) => {\n const reqBody = input.body || null\n const userHeaders = input.headers || {}\n const headers = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n 'Content-Length': reqBody.length,\n }\n\n const timeoutMs = 30_000\n\n const reqOptions = {\n method: 'POST',\n headers: headers,\n timeout: timeoutMs,\n }\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n const url = 'https://serve.onegraph.com/graphql?app_id=' + input.siteId +\n (schemaId ? ('&schemaId=' + schemaId) : '');\n const respBody = []\n\n return new Promise((resolve, reject) => {\n const req = https.request(url, reqOptions, (res) => {\n if (res.statusCode && (res.statusCode < 200 || res.statusCode > 299)) {\n return reject(\n new Error(\n \"Netlify Graph return non-OK HTTP status code\" + res.statusCode,\n ),\n )\n }\n\n res.on('data', (chunk) => respBody.push(chunk))\n\n res.on('end', () => {\n const resString = buffer.Buffer.concat(respBody).toString()\n resolve(resString)\n })\n })\n\n req.on('error', (error) => {\n console.error('Error making request to Netlify Graph:', error)\n })\n\n req.on('timeout', () => {\n req.destroy()\n reject(new Error('Request to Netlify Graph timed out'))\n })\n\n req.write(reqBody)\n req.end()\n })\n}") + "\n\n" + out(netlifyGraphConfig, ["browser"], "const httpGet = (input) => {\n const userHeaders = input.headers || {};\n const fullHeaders = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n };\n\n const timeoutMs = 30_000;\n\n const reqOptions = {\n method: 'GET',\n headers: fullHeaders,\n timeout: timeoutMs,\n };\n\n const encodedVariables = encodeURIComponent(\n JSON.stringify(input.variables || null)\n );\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n const encodedVariables = encodeURIComponent(input.variables || \"null\");\n\n const url =\n 'https://serve.onegraph.com/graphql?app_id=' +\n input.siteId +\n '&doc_id=' +\n input.docId +\n (input.operationName ? '&operationName=' + input.operationName : '') +\n (schemaId ? ('&schemaId=' + schemaId) : '') +\n '&variables=' +\n encodedVariables;\n\n return fetch(url, reqOptions).then((response) => response.text());\n};\n\nconst httpPost = (input) => {\n const userHeaders = input.headers || {};\n const fullHeaders = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n };\n\n const reqBody = JSON.stringify({\n doc_id: input.docId,\n query: input.query,\n operationName: input.operationName,\n variables: input.variables,\n });\n\n const timeoutMs = 30_000;\n\n const reqOptions = {\n method: 'POST',\n headers: fullHeaders,\n timeout: timeoutMs,\n body: reqBody,\n };\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n const url = 'https://serve.onegraph.com/graphql?app_id=' + input.siteId +\n (schemaId ? ('&schemaId=' + schemaId) : '');\n\n return fetch(url, reqOptions).then((response) => response.text());\n};") + "\n\nconst fetchNetlifyGraph = function fetchNetlifyGraph(input) {\n const docId = input.doc_id;\n const operationName = input.operationName;\n const variables = input.variables;\n\n const options = input.options || {};\n const accessToken = options.accessToken;\n const siteId = options.siteId || process.env.SITE_ID;\n\n const httpMethod = input.fetchStrategy === 'GET' ? httpGet : httpPost;\n\n const response = httpMethod({\n siteId: siteId,\n docId: docId,\n query: input.query,\n headers: {\n Authorization: accessToken ? 'Bearer ' + accessToken : '',\n },\n variables: variables,\n operationName: operationName,\n });\n\n return response.then((result) => JSON.parse(result));\n};\n";
return out(netlifyGraphConfig, ["node"], "const httpGet = (input) => {\n const userHeaders = input.headers || {};\n const fullHeaders = {\n ...userHeaders,\n 'Content-Type': 'application/json'\n };\n const timeoutMs = 30_000\n const reqOptions = {\n method: 'GET',\n headers: fullHeaders,\n timeout: timeoutMs,\n };\n\n if (!input.docId) {\n throw new Error('docId is required for GET requests: ' + input.operationName);\n }\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n console.log(\"httpGet node schemaId: \", schemaId);\n\n const encodedVariables = encodeURIComponent(input.variables || \"null\");\n const url = 'https://serve.onegraph.com/graphql?app_id=' + input.siteId + '&doc_id=' + input.docId + (input.operationName ? ('&operationName=' + input.operationName) : '') + (schemaId ? ('&schemaId=' + schemaId) : '') + '&variables=' + encodedVariables;\n \n const respBody = []\n\n return new Promise((resolve, reject) => {\n const req = https.request(url, reqOptions, (res) => {\n if (res.statusCode && (res.statusCode < 200 || res.statusCode > 299)) {\n return reject(\n new Error(\n \"Netlify Graph return non-OK HTTP status code\" + res.statusCode,\n ),\n )\n }\n\n res.on('data', (chunk) => respBody.push(chunk))\n\n res.on('end', () => {\n const resString = buffer.Buffer.concat(respBody).toString()\n resolve(resString)\n })\n })\n\n req.on('error', (error) => {\n console.error('Error making request to Netlify Graph:', error)\n })\n\n req.on('timeout', () => {\n req.destroy()\n reject(new Error('Request to Netlify Graph timed out'))\n })\n\n req.end()\n })\n}\n\nconst httpPost = (input) => {\n const reqBody = input.body || null\n const userHeaders = input.headers || {}\n const headers = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n 'Content-Length': reqBody.length,\n }\n\n const timeoutMs = 30_000\n\n const reqOptions = {\n method: 'POST',\n headers: headers,\n timeout: timeoutMs,\n }\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n console.log(\"httpPost node schemaId: \", schemaId);\n\n\n const url = 'https://serve.onegraph.com/graphql?app_id=' + input.siteId +\n (schemaId ? ('&schemaId=' + schemaId) : '');\n const respBody = []\n\n return new Promise((resolve, reject) => {\n const req = https.request(url, reqOptions, (res) => {\n if (res.statusCode && (res.statusCode < 200 || res.statusCode > 299)) {\n return reject(\n new Error(\n \"Netlify Graph return non-OK HTTP status code\" + res.statusCode,\n ),\n )\n }\n\n res.on('data', (chunk) => respBody.push(chunk))\n\n res.on('end', () => {\n const resString = buffer.Buffer.concat(respBody).toString()\n resolve(resString)\n })\n })\n\n req.on('error', (error) => {\n console.error('Error making request to Netlify Graph:', error)\n })\n\n req.on('timeout', () => {\n req.destroy()\n reject(new Error('Request to Netlify Graph timed out'))\n })\n\n req.write(reqBody)\n req.end()\n })\n}") + "\n\n" + out(netlifyGraphConfig, ["browser"], "const httpGet = (input) => {\n const userHeaders = input.headers || {};\n const fullHeaders = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n };\n\n const timeoutMs = 30_000;\n\n const reqOptions = {\n method: 'GET',\n headers: fullHeaders,\n timeout: timeoutMs,\n };\n\n const encodedVariables = encodeURIComponent(\n JSON.stringify(input.variables || null)\n );\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n console.log(\"httpGet browser schemaId: \", schemaId);\n\n const encodedVariables = encodeURIComponent(input.variables || \"null\");\n\n const url =\n 'https://serve.onegraph.com/graphql?app_id=' +\n input.siteId +\n '&doc_id=' +\n input.docId +\n (input.operationName ? '&operationName=' + input.operationName : '') +\n (schemaId ? ('&schemaId=' + schemaId) : '') +\n '&variables=' +\n encodedVariables;\n\n return fetch(url, reqOptions).then((response) => response.text());\n};\n\nconst httpPost = (input) => {\n const userHeaders = input.headers || {};\n const fullHeaders = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n };\n\n const reqBody = JSON.stringify({\n doc_id: input.docId,\n query: input.query,\n operationName: input.operationName,\n variables: input.variables,\n });\n\n const timeoutMs = 30_000;\n\n const reqOptions = {\n method: 'POST',\n headers: fullHeaders,\n timeout: timeoutMs,\n body: reqBody,\n };\n\n const schemaId = input.schemaId || " + (schemaId ? "\"" + schemaId + "\"" : "undefined") + ";\n\n console.log(\"httpPost browser schemaId: \", schemaId);\n\n const url = 'https://serve.onegraph.com/graphql?app_id=' + input.siteId +\n (schemaId ? ('&schemaId=' + schemaId) : '');\n\n return fetch(url, reqOptions).then((response) => response.text());\n};") + "\n\nconst fetchNetlifyGraph = function fetchNetlifyGraph(input) {\n const docId = input.doc_id;\n const operationName = input.operationName;\n const variables = input.variables;\n\n const options = input.options || {};\n const accessToken = options.accessToken;\n const siteId = options.siteId || process.env.SITE_ID;\n\n const httpMethod = input.fetchStrategy === 'GET' ? httpGet : httpPost;\n\n const response = httpMethod({\n siteId: siteId,\n docId: docId,\n query: input.query,\n headers: {\n Authorization: accessToken ? 'Bearer ' + accessToken : '',\n },\n variables: variables,\n operationName: operationName,\n });\n\n return response.then((result) => JSON.parse(result));\n};\n";
};

@@ -114,0 +114,0 @@ var subscriptionParserReturnName = function (fn) { return fn.operationName + "Event"; };

{
"name": "netlify-onegraph-internal",
"version": "0.1.5",
"version": "0.1.6",
"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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc