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.0.21 to 0.0.22

12

dist/netlifyGraph.js

@@ -67,4 +67,4 @@ "use strict";

exports.defaultExampleOperationsDoc = "query ExampleQuery @netlify(doc: \"An example query to start with.\") {\n __typename\n}";
var generatedOneGraphClient = function (netlifyGraphConfig) {
return out(netlifyGraphConfig, ["node"], "const httpFetch = (siteId, options) => {\n const reqBody = options.body || null\n const userHeaders = options.headers || {}\n const headers = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n 'Content-Length': reqBody.length,\n }\n \n const reqOptions = {\n method: 'POST',\n headers: headers,\n timeout: 30000,\n }\n \n const url = 'https://serve.onegraph.com/graphql?app_id=' + siteId\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 OneGraph 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.concat(respBody).toString()\n resolve(resString)\n })\n })\n\n req.on('error', (e) => {\n console.error('Error making request to Netlify OneGraph: ', e)\n })\n\n req.on('timeout', () => {\n req.destroy()\n reject(new Error('Request to Netlify OneGraph timed out'))\n })\n\n req.write(reqBody)\n req.end()\n })\n}\n") + "\n" + out(netlifyGraphConfig, ["browser"], "const httpFetch = (siteId, options) => {\n const reqBody = options.body || null\n const userHeaders = options.headers || {}\n const headers = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n }\n\n const reqOptions = {\n method: 'POST',\n headers: headers,\n timeout: 30000,\n body: reqBody\n }\n\n const url = 'https://serve.onegraph.com/graphql?app_id=' + siteId\n\n return fetch(url, reqOptions).then(response => response.text());\n}") + "\n\nconst fetchOneGraph = async function fetchOneGraph(input) {\n const accessToken = input.accessToken \n const query = input.query\n const operationName = input.operationName\n const variables = input.variables\n const options = input.options || {}\n\n const siteId = options.siteId || process.env.SITE_ID\n\n const payload = {\n query: query,\n variables: variables,\n operationName: operationName,\n }\n\n const result = await httpFetch(\n siteId,\n {\n method: 'POST',\n headers: {\n Authorization: accessToken ? \"Bearer \" + accessToken : '',\n },\n body: JSON.stringify(payload),\n },\n )\n\n return JSON.parse(result)\n}\n";
var generatedNetlifyGraphClient = function (netlifyGraphConfig) {
return out(netlifyGraphConfig, ["node"], "const httpFetch = (siteId, options) => {\n const reqBody = options.body || null\n const userHeaders = options.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 url = 'https://serve.onegraph.com/graphql?app_id=' + siteId\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.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 httpFetch = (siteId, options) => {\n const reqBody = options.body || null\n const userHeaders = options.headers || {}\n const headers = {\n ...userHeaders,\n 'Content-Type': 'application/json',\n }\n\n const reqOptions = {\n method: 'POST',\n headers: headers,\n timeout: 30000,\n body: reqBody\n }\n\n const url = 'https://serve.onegraph.com/graphql?app_id=' + siteId\n\n return fetch(url, reqOptions).then(response => response.text());\n}") + "\n\nconst fetchNetlifyGraph = async function fetchNetlifyGraph(input) {\n const accessToken = input.accessToken \n const query = input.query\n const operationName = input.operationName\n const variables = input.variables\n const options = input.options || {}\n\n const siteId = options.siteId || process.env.SITE_ID\n\n const payload = {\n query: query,\n variables: variables,\n operationName: operationName,\n }\n\n const result = await httpFetch(\n siteId,\n {\n method: 'POST',\n headers: {\n Authorization: accessToken ? \"Bearer \" + accessToken : '',\n },\n body: JSON.stringify(payload),\n },\n )\n\n return JSON.parse(result)\n}\n";
};

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

var safeBody = replaceAll(body, "${", "\\${");
return "const " + subscriptionFunctionName(fn) + " = async (\n /**\n * This will be available in your webhook handler as a query parameter.\n * Use this to keep track of which subscription you're receiving\n * events for.\n */\n netlifyGraphWebhookId,\n variables,\n rawOptions\n ) => {\n const options = rawOptions || {}\n const netlifyGraphWebhookUrl = `${process.env.DEPLOY_URL}" + netlifyGraphConfig.webhookBasePath + "/" + filename + "?netlifyGraphWebhookId=${netlifyGraphWebhookId}`\n const secret = options.secret || process.env.NETLIFY_GRAPH_WEBHOOK_SECRET\n const fullVariables = {...variables, netlifyGraphWebhookUrl: netlifyGraphWebhookUrl, netlifyGraphWebhookSecret: { hmacSha256Key: secret }}\n\n const subscriptionOperationDoc = `" + safeBody + "`;\n\n const result = await fetchOneGraph({\n query: subscriptionOperationDoc,\n operationName: \"" + fn.operationName + "\",\n variables: fullVariables,\n options: Object.assign({accessToken: accessToken}, options || {}),\n })\n}\n\nconst " + subscriptionParserName(fn) + " = (event) => {\n if (!verifyRequestSignature({ event: event })) {\n console.warn(\"Unable to verify signature for " + filename + "\")\n return null\n }\n \n return JSON.parse(event.body || '{}')\n}";
return "const " + subscriptionFunctionName(fn) + " = async (\n /**\n * This will be available in your webhook handler as a query parameter.\n * Use this to keep track of which subscription you're receiving\n * events for.\n */\n netlifyGraphWebhookId,\n variables,\n rawOptions\n ) => {\n const options = rawOptions || {}\n const netlifyGraphWebhookUrl = `${process.env.DEPLOY_URL}" + netlifyGraphConfig.webhookBasePath + "/" + filename + "?netlifyGraphWebhookId=${netlifyGraphWebhookId}`\n const secret = options.secret || process.env.NETLIFY_GRAPH_WEBHOOK_SECRET\n const fullVariables = {...variables, netlifyGraphWebhookUrl: netlifyGraphWebhookUrl, netlifyGraphWebhookSecret: { hmacSha256Key: secret }}\n\n const subscriptionOperationDoc = `" + safeBody + "`;\n\n const result = await fetchNetlifyGraph({\n query: subscriptionOperationDoc,\n operationName: \"" + fn.operationName + "\",\n variables: fullVariables,\n options: Object.assign({accessToken: accessToken}, options || {}),\n })\n}\n\nconst " + subscriptionParserName(fn) + " = (event) => {\n if (!verifyRequestSignature({ event: event })) {\n console.warn(\"Unable to verify signature for " + filename + "\")\n return null\n }\n \n return JSON.parse(event.body || '{}')\n}";
};

@@ -224,4 +224,4 @@ exports.generateSubscriptionFunction = generateSubscriptionFunction;

}
var dynamicFunction = exp(netlifyGraphConfig, ["browser", "node"], fn.fnName, "(\n variables,\n options\n ) => {\n return fetchOneGraph({\n query: `" + fn.safeBody + "`,\n variables: variables,\n options: options || {},\n })\n }") + "\n";
var staticFunction = "" + exp(netlifyGraphConfig, ["browser", "node"], fn.fnName, "(\n variables,\n options\n ) => {\n return fetchOneGraph({\n query: operationsDoc,\n operationName: \"" + fn.operationName + "\",\n variables: variables,\n options: options || {},\n });\n }\n");
var dynamicFunction = exp(netlifyGraphConfig, ["browser", "node"], fn.fnName, "(\n variables,\n options\n ) => {\n return fetchNetlifyGraph({\n query: `" + fn.safeBody + "`,\n variables: variables,\n options: options || {},\n })\n }") + "\n";
var staticFunction = "" + exp(netlifyGraphConfig, ["browser", "node"], fn.fnName, "(\n variables,\n options\n ) => {\n return fetchNetlifyGraph({\n query: operationsDoc,\n operationName: \"" + fn.operationName + "\",\n variables: variables,\n options: options || {},\n });\n }\n");
return fn.id ? staticFunction : dynamicFunction;

@@ -256,3 +256,3 @@ });

var dummyHandler = exp(netlifyGraphConfig, ["node"], "handler", "() => {\n // return a 401 json response\n return {\n statusCode: 401,\n body: JSON.stringify({\n message: 'Unauthorized',\n }),\n }\n }");
var source = "// GENERATED VIA NETLIFY AUTOMATED DEV TOOLS, EDIT WITH CAUTION!\n" + imp(netlifyGraphConfig, ["node"], "https", "https") + "\n" + imp(netlifyGraphConfig, ["node"], "crypto", "crypto") + "\n\n" + exp(netlifyGraphConfig, ["node"], "verifySignature", "(input) => {\n const secret = input.secret\n const body = input.body\n const signature = input.signature\n\n if (!signature) {\n console.error('Missing signature')\n return false\n }\n\n const sig = {}\n for (const pair of signature.split(',')) {\n const [k, v] = pair.split('=')\n sig[k] = v\n }\n\n if (!sig.t || !sig.hmac_sha256) {\n console.error('Invalid signature header')\n return false\n }\n\n const hash = crypto\n .createHmac('sha256', secret)\n .update(sig.t)\n .update('.')\n .update(body)\n .digest('hex')\n\n if (\n !crypto.timingSafeEqual(\n Buffer.from(hash, 'hex'),\n Buffer.from(sig.hmac_sha256, 'hex')\n )\n ) {\n console.error('Invalid signature')\n return false\n }\n\n if (parseInt(sig.t, 10) < Date.now() / 1000 - 300 /* 5 minutes */) {\n console.error('Request is too old')\n return false\n }\n\n return true\n}") + "\n\nconst operationsDoc = `" + safeOperationsDoc + "`\n\n" + generatedOneGraphClient(netlifyGraphConfig) + "\n\n" + exp(netlifyGraphConfig, ["node"], "verifyRequestSignature", "(request) => {\n const event = request.event\n const secret = process.env.NETLIFY_GRAPH_WEBHOOK_SECRET\n const signature = event.headers['x-netlify-graph-signature']\n const body = event.body\n\n if (!secret) {\n console.error(\n 'NETLIFY_GRAPH_WEBHOOK_SECRET is not set, cannot verify incoming webhook request'\n )\n return false\n }\n\n return verifySignature({ secret, signature, body: body || '' })\n}") + "\n\n" + functionDecls.join("\n\n") + "\n \n/**\n * The generated NetlifyGraph library with your operations\n */\nconst functions = {\n " + exportedFunctionsObjectProperties + "\n}\n\n" + (netlifyGraphConfig.moduleType === "commonjs"
var source = "// GENERATED VIA NETLIFY AUTOMATED DEV TOOLS, EDIT WITH CAUTION!\n " + imp(netlifyGraphConfig, ["node"], "Buffer", "buffer") + "\n " + imp(netlifyGraphConfig, ["node"], "crypto", "crypto") + "\n " + imp(netlifyGraphConfig, ["node"], "https", "https") + "\n " + imp(netlifyGraphConfig, ["node"], "process", "process") + "\n\n" + exp(netlifyGraphConfig, ["node"], "verifySignature", "(input) => {\n const secret = input.secret\n const body = input.body\n const signature = input.signature\n\n if (!signature) {\n console.error('Missing signature')\n return false\n }\n\n const sig = {}\n for (const pair of signature.split(',')) {\n const [key, value] = pair.split('=')\n sig[key] = value\n }\n\n if (!sig.t || !sig.hmac_sha256) {\n console.error('Invalid signature header')\n return false\n }\n\n const hash = crypto\n .createHmac('sha256', secret)\n .update(sig.t)\n .update('.')\n .update(body)\n .digest('hex')\n\n if (\n !crypto.timingSafeEqual(\n Buffer.from(hash, 'hex'),\n Buffer.from(sig.hmac_sha256, 'hex')\n )\n ) {\n console.error('Invalid signature')\n return false\n }\n\n if (parseInt(sig.t, 10) < Date.now() / 1000 - 300 /* 5 minutes */) {\n console.error('Request is too old')\n return false\n }\n\n return true\n}") + "\n\nconst operationsDoc = `" + safeOperationsDoc + "`\n\n" + generatedNetlifyGraphClient(netlifyGraphConfig) + "\n\n" + exp(netlifyGraphConfig, ["node"], "verifyRequestSignature", "(request) => {\n const event = request.event\n const secret = process.env.NETLIFY_GRAPH_WEBHOOK_SECRET\n const signature = event.headers['x-netlify-graph-signature']\n const body = event.body\n\n if (!secret) {\n console.error(\n 'NETLIFY_GRAPH_WEBHOOK_SECRET is not set, cannot verify incoming webhook request'\n )\n return false\n }\n\n return verifySignature({ secret, signature, body: body || '' })\n}") + "\n\n" + functionDecls.join("\n\n") + "\n \n/**\n * The generated NetlifyGraph library with your operations\n */\nconst functions = {\n " + exportedFunctionsObjectProperties + "\n}\n\n" + (netlifyGraphConfig.moduleType === "commonjs"
? "exports.default = functions"

@@ -259,0 +259,0 @@ : "export default functions") + "\n\n" + dummyHandler;

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

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