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.27 to 0.0.28

6

dist/codegen/remixExporter.js

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

}
return (pluckerStyle === "get" ? pluckers.get : pluckers.post) + "\n\n" + (requiredVariableCount > 0 ? variableValidation : "") + "\n\n const { errors, data } = await NetlifyGraph." + operationFunctionName(namedOperationData) + "({ " + invocationParams.join(", ") + " }, accessToken);\n\n if (errors) {\n console.error(JSON.stringify(errors, null, 2));\n }\n\n console.log(JSON.stringify(data, null, 2));";
return (pluckerStyle === "get" ? pluckers.get : pluckers.post) + "\n\n" + (requiredVariableCount > 0 ? variableValidation : "") + "\n\n const { errors, data } = await NetlifyGraph." + operationFunctionName(namedOperationData) + "({ " + invocationParams.join(", ") + " }, {accessToken: accessToken});\n\n if (errors) {\n console.error(JSON.stringify(errors, null, 2));\n }\n\n console.log(JSON.stringify(data, null, 2));";
})

@@ -362,3 +362,3 @@ .join("\n\n");

],
content: "import { " + ts(netlifyGraphConfig, "ActionFunction, ") + "json } from \"remix\";\nimport NetlifyGraph from \"../" + netlifyGraphConfig.netlifyGraphRequirePath + "\";\n\n" + exp(netlifyGraphConfig, "action") + ts(netlifyGraphConfig, ": ActionFunction") + " = async ({ request }) => {\n const reqBody = await request.text();\n\n const payload = NetlifyGraph.parseAndVerify" + operationData.name + "Event({\n body: reqBody,\n headers: {\n 'x-netlify-graph-signature': request.headers.get('x-netlify-graph-signature')\n },\n });\n\n if (!payload) {\n return json({\n success: false,\n error: 'Unable to verify payload signature',\n }, { status: 422 });\n }\n\n const { errors, data } = payload;\n\n if (errors) {\n console.error(errors);\n }\n\n console.log(data);\n\n /**\n * If you want to unsubscribe from this webhook\n * in order to stop receiving new events,\n * simply return status 410, e.g.:\n * \n * return json({}, { status: 410 });\n */\n\n return json({\n successfullyProcessedIncomingWebhook: true,\n });\n};\n",
content: "import { " + ts(netlifyGraphConfig, "ActionFunction, ") + "json } from \"remix\";\nimport NetlifyGraph from \"../" + netlifyGraphConfig.netlifyGraphRequirePath + "\";\n\n" + exp(netlifyGraphConfig, "action") + ts(netlifyGraphConfig, ": ActionFunction") + " = async ({ request }) => {\n const reqBody = await request.text();\n\n const payload = NetlifyGraph.parseAndVerify" + operationData.name + "Event({\n body: reqBody,\n headers: {\n 'x-netlify-graph-signature': request.headers.get('x-netlify-graph-signature')\n },\n });\n\n if (!payload) {\n return json({\n success: false,\n error: 'Unable to verify payload signature',\n }, { status: 422 });\n }\n\n const { errors, data } = payload;\n\n if (errors) {\n console.error(errors);\n }\n\n console.log(data);\n\n /**\n * If you want to unsubscribe from this webhook\n * in order to stop receiving new events,\n * simply return status 410, e.g.:\n *\n * return json({}, { status: 410 });\n */\n\n return json({\n successfullyProcessedIncomingWebhook: true,\n });\n};\n",
};

@@ -436,3 +436,3 @@ };

var whitespace = 4;
var snippet = ts(netlifyGraphConfig, 'import type { NextApiRequest, NextApiResponse } from "next";') + "\n" + imp(netlifyGraphConfig, "NetlifyGraph", netlifyGraphConfig.netlifyGraphRequirePath) + ";\n\n/** \n * Client-side invocations:\n * Call your Netlify function from the browser with this helper:\n */\n\n/**\n" + clientSideCalls + "\n*/";
var snippet = ts(netlifyGraphConfig, 'import type { NextApiRequest, NextApiResponse } from "next";') + "\n" + imp(netlifyGraphConfig, "NetlifyGraph", netlifyGraphConfig.netlifyGraphRequirePath) + ";\n\n/**\n * Client-side invocations:\n * Call your Netlify function from the browser with this helper:\n */\n\n/**\n" + clientSideCalls + "\n*/";
var route = generateRoute({

@@ -439,0 +439,0 @@ netlifyGraphConfig: netlifyGraphConfig,

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

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";
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.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.options.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 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}";
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}";
};

@@ -255,3 +255,3 @@ exports.generateSubscriptionFunction = generateSubscriptionFunction;

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"], "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"
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"

@@ -293,3 +293,3 @@ : "export default functions") + "\n\n" + dummyHandler;

});
var source = "// GENERATED VIA NETLIFY AUTOMATED DEV TOOLS, EDIT WITH CAUTION!\n\nexport type NetlifyGraphFunctionOptions = {\n accessToken?: string;\n siteId?: string; \n}\n\nexport type WebhookEvent = {\n body: string;\n headers: Record<string, string | null | undefined>;\n};\n\nexport type GraphQLError = {\n \"path\": Array<string | number>,\n \"message\": string,\n \"extensions\": Record<string, unknown>\n};\n\n" + fragmentDecls.join("\n\n") + "\n\n" + functionDecls.join("\n\n") + "\n";
var source = "// GENERATED VIA NETLIFY AUTOMATED DEV TOOLS, EDIT WITH CAUTION!\n\nexport type NetlifyGraphFunctionOptions = {\n accessToken?: string;\n siteId?: string;\n}\n\nexport type WebhookEvent = {\n body: string;\n headers: Record<string, string | null | undefined>;\n};\n\nexport type GraphQLError = {\n \"path\": Array<string | number>,\n \"message\": string,\n \"extensions\": Record<string, unknown>\n};\n\n" + fragmentDecls.join("\n\n") + "\n\n" + functionDecls.join("\n\n") + "\n";
return source;

@@ -404,5 +404,6 @@ };

var operations = (0, exports.extractFunctionsFromOperationDoc)(parsedDoc);
var fn = operations.functions[operationId];
var functions = operations.functions;
var fn = functions[operationId];
if (!fn) {
internalConsole_1.internalConsole.warn("Operation " + operationId + " not found in graphql, found: " + Object.keys(operations).join(", ") + "}", Object.keys(operations));
internalConsole_1.internalConsole.warn("Operation " + operationId + " not found in graphql, found: " + Object.keys(functions).join(", ") + "}");
return;

@@ -409,0 +410,0 @@ }

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