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.28 to 0.0.30

4

dist/codegen/remixExporter.js

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

],
content: "import { json, Form, useActionData, useTransition } from \"remix\";\nimport type { ActionFunction } from \"remix\";\nimport NetlifyGraph from \"" + netlifyGraphConfig.netlifyGraphRequirePath + "\";" + ts(netlifyGraphConfig, "\nimport invariant from \"tiny-invariant\";") + "\n\n" + exp(netlifyGraphConfig, "action") + ts(netlifyGraphConfig, ": ActionFunction") + " = async ({ request }) => {\n const formData = await request.formData();\n\n // By default, all API calls use no authentication\n let accessToken;\n\n //// If you want to use the API with your own access token:\n // accessToken = authlifyToken;\n\n " + fetcherInvocation + "\n\n return json({ data, errors });\n};\n\nexport default function handler() {\n const results = useActionData();\n const transition = useTransition();\n\n const errors = results?.errors;\n const data" + ts(netlifyGraphConfig, ": NetlifyGraph." + capitalizeFirstLetter(opts.operationData.name) + "[\"data\"]") + " = results?.data;\n\n\n return (\n <Form method=\"post\">\n " + form.formEl + "\n {errors ? (<pre className=\"error\">{JSON.stringify(errors, null, 2)}</pre>) : null}\n {data ? (<pre>{JSON.stringify(data, null, 2)}</pre>) : null}\n </Form>\n );\n}\n",
content: "import { json, Form, useActionData, useTransition } from \"remix\";\nimport type { ActionFunction } from \"remix\";\nimport NetlifyGraph from \"" + netlifyGraphConfig.netlifyGraphRequirePath + "\";" + ts(netlifyGraphConfig, "\nimport invariant from \"tiny-invariant\";") + "\n\n" + exp(netlifyGraphConfig, "action") + ts(netlifyGraphConfig, ": ActionFunction") + " = async ({ request }) => {\n const formData = await request.formData();\n\n // By default, all API calls use no authentication\n let accessToken;\n\n //// If you want to use the API with your own access token:\n // accessToken = event.netlifyGraphToken;\n\n " + fetcherInvocation + "\n\n return json({ data, errors });\n};\n\nexport default function handler() {\n const results = useActionData();\n const transition = useTransition();\n\n const errors = results?.errors;\n const data" + ts(netlifyGraphConfig, ": NetlifyGraph." + capitalizeFirstLetter(opts.operationData.name) + "[\"data\"]") + " = results?.data;\n\n\n return (\n <Form method=\"post\">\n " + form.formEl + "\n {errors ? (<pre className=\"error\">{JSON.stringify(errors, null, 2)}</pre>) : null}\n {data ? (<pre>{JSON.stringify(data, null, 2)}</pre>) : null}\n </Form>\n );\n}\n",
};

@@ -362,3 +362,3 @@ };

],
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': event.netlifyGraphSignature\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",
};

@@ -365,0 +365,0 @@ };

@@ -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.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";
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 query = input.query\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 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";
};

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

.join("\n* ");
return "/**\n* " + jsDoc + "\n*/\nexport function " + subscriptionFunctionName(fn) + "(\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: string,\n variables: " + (variableSignature === "{}" ? "Record<string, never>" : variableSignature) + ",\n accessToken?: string | null | undefined\n ) : void\n\nexport type " + subscriptionParserReturnName(fn) + " = " + parsingFunctionReturnSignature + "\n\n/**\n * Verify the " + fn.operationName + " event body is signed securely, and then parse the result.\n */\nexport function " + subscriptionParserName(fn) + " (/** A Netlify Handler Event */ event : WebhookEvent) : null | " + subscriptionParserReturnName(fn) + "\n";
return "/**\n* " + jsDoc + "\n*/\nexport function " + subscriptionFunctionName(fn) + "(\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 variables: " + (variableSignature === "{}" ? "Record<string, never>" : variableSignature) + ",\n options?: {\n /**\n * The accessToken to use for the lifetime of the subscription.\n */\n accessToken?: string | null | undefined;\n /**\n * A string id that will be passed to your webhook handler as a query parameter\n * along with each event.\n * This can be used to keep track of which subscription you're receiving\n */\n netlifyGraphWebhookId?: string | null | undefined;\n /**\n * The absolute URL of your webhook handler to handle events from this subscription.\n */\n webhookUrl?: string | null | undefined;\n /**\n * The secret to use when signing the webhook request. Use this to verify\n * that the webhook payload is coming from Netlify Graph. Defaults to the\n * value of the NETLIFY_GRAPH_WEBHOOK_SECRET environment variable.\n */\n webhookSecret?: string | null | undefined;\n }) : void\n\nexport type " + subscriptionParserReturnName(fn) + " = " + parsingFunctionReturnSignature + "\n\n/**\n * Verify the " + fn.operationName + " event body is signed securely, and then parse the result.\n */\nexport function " + subscriptionParserName(fn) + " (/** A Netlify Handler Event */ event : WebhookEvent) : null | " + subscriptionParserReturnName(fn) + "\n";
};

@@ -128,3 +128,3 @@ exports.generateSubscriptionFunctionTypeDefinition = generateSubscriptionFunctionTypeDefinition;

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 variables,\n rawOptions\n ) => {\n const options = rawOptions || {};\n const netlifyGraphWebhookId = options.netlifyGraphWebhookId;\n const netlifyGraphWebhookUrl = options.webhookUrl || `${process.env.DEPLOY_URL}" + netlifyGraphConfig.webhookBasePath + "/" + filename + "?netlifyGraphWebhookId=${netlifyGraphWebhookId}`;\n const secret = options.webhookSecret || process.env.NETLIFY_GRAPH_WEBHOOK_SECRET\n const fullVariables = {...variables, netlifyGraphWebhookUrl: netlifyGraphWebhookUrl, netlifyGraphWebhookSecret: { hmacSha256Key: secret }}\n\n const subscriptionOperationDoc = `" + safeBody + "`;\n\n fetchNetlifyGraph({\n query: subscriptionOperationDoc,\n operationName: \"" + fn.operationName + "\",\n variables: fullVariables,\n options: options,\n })\n}\n\nconst " + subscriptionParserName(fn) + " = (event, options) => {\n if (!verifyRequestSignature({ event: event }, options)) {\n console.warn(\"Unable to verify signature for " + filename + "\")\n return null\n }\n\n return JSON.parse(event.body || '{}')\n}";
};

@@ -256,3 +256,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, options) => {\n const event = request.event\n const secret = options.webhookSecret || 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"

@@ -294,3 +294,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 /**\n * The accessToken to use for the request\n */\n accessToken?: string;\n /**\n * The siteId to use for the request\n * @default process.env.SITE_ID\n */\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;

@@ -297,0 +297,0 @@ };

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