netlify-onegraph-internal
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -39,3 +39,3 @@ "use strict"; | ||
name: ["pages", opts.operationData.displayName + "Form.tsx"], | ||
content: "import Head from \"next/head\";\nimport React, { useState } from \"react\";\nimport NetlifyGraphAuth from \"netlify-graph-auth\";\n\nexport default function Form(props) {\n const isServer = typeof window === \"undefined\";\n " + form.formHelpers + "\n const [result, setResult] = useState(null);\n const [auth, setAuth] = useState(\n isServer\n ? null\n : new NetlifyGraphAuth({\n siteId: props.siteId,\n })\n );\n\n const submitForm = async () => {\n const res = await fetch(\"" + opts.route + "\", {\n body: JSON.stringify(formVariables),\n headers: {\n \"Content-Type\": \"application/json\",\n ...auth?.authHeaders()\n },\n method: \"POST\"\n });\n\n const formResult = await res.json();\n setResult(formResult);\n };\n\n const needsLoginService = auth?.findMissingAuthServices(result)[0];\n\n return (\n <div className=\"container\">\n <Head>\n <title>" + opts.operationData.displayName + " form</title>\n </Head>\n <main>\n <h1>{props.title}</h1>\n" + addLeftWhitespace(form.formEl, 8) + "\n {needsLoginService ? (\n <button\n onClick={async () => {\n await auth.login(needsLoginService);\n const loginSuccess = await auth.isLoggedIn(needsLoginService);\n if (loginSuccess) {\n console.log(\"Successfully logged into \" + needsLoginService);\n submitForm();\n } else {\n console.log(\"The user did not grant auth to \" + needsLoginService);\n }\n }}\n >\n {`Log in to ${needsLoginService}`}\n </button>) \n : null}\n <pre>{JSON.stringify(formVariables, null, 2)}</pre>\n <pre>{JSON.stringify(result, null, 2)}</pre>\n </main>\n </div>\n )\n}\n\nexport async function getServerSideProps(context) {\n const siteId = process.env.SITE_ID;\n if (!siteId) {\n throw new Error(\"SITE_ID environment variable is not set. Be sure to run `netlify link` before `netlify dev`\");\n }\n\n return {\n props: {\n title: \"" + opts.operationData.displayName + " form\",\n siteId: siteId\n }\n }\n}\n\n" + formUpdateHandler + "\n", | ||
content: "import Head from \"next/head\";\nimport React, { useState } from \"react\";\nimport { Auth } from 'netlify-graph-auth';" + ts(opts.netlifyGraphConfig, "\nimport NetlifyGraphAuth = Auth.NetlifyGraphAuth;") + notTs(opts.netlifyGraphConfig, "\n\nconst { NetlifyGraphAuth } = Auth;") + "\n\nexport default function Form(props) {\n const isServer = typeof window === \"undefined\";\n " + form.formHelpers + "\n const [result, setResult] = useState(null);\n const [auth, setAuth] = useState(\n isServer\n ? null\n : new NetlifyGraphAuth({\n siteId: props.siteId,\n })\n );\n\n const submitForm = async () => {\n const res = await fetch(\"" + opts.route + "\", {\n body: JSON.stringify(formVariables),\n headers: {\n \"Content-Type\": \"application/json\",\n ...auth?.authHeaders()\n },\n method: \"POST\"\n });\n\n const formResult = await res.json();\n setResult(formResult);\n };\n\n const needsLoginService = auth?.findMissingAuthServices(result)[0];\n\n return (\n <div className=\"container\">\n <Head>\n <title>" + opts.operationData.displayName + " form</title>\n </Head>\n <main>\n <h1>{props.title}</h1>\n" + addLeftWhitespace(form.formEl, 8) + "\n {needsLoginService ? (\n <button\n onClick={async () => {\n await auth.login(needsLoginService);\n const loginSuccess = await auth.isLoggedIn(needsLoginService);\n if (loginSuccess) {\n console.log(\"Successfully logged into \" + needsLoginService);\n submitForm();\n } else {\n console.log(\"The user did not grant auth to \" + needsLoginService);\n }\n }}\n >\n {`Log in to ${needsLoginService}`}\n </button>) \n : null}\n <pre>{JSON.stringify(formVariables, null, 2)}</pre>\n <pre>{JSON.stringify(result, null, 2)}</pre>\n </main>\n </div>\n )\n}\n\nexport async function getServerSideProps(context) {\n const siteId = process.env.SITE_ID;\n if (!siteId) {\n throw new Error(\"SITE_ID environment variable is not set. Be sure to run `netlify link` before `netlify dev`\");\n }\n\n return {\n props: {\n title: \"" + opts.operationData.displayName + " form\",\n siteId: siteId\n }\n }\n}\n\n" + formUpdateHandler + "\n", | ||
}; | ||
@@ -327,2 +327,5 @@ }; | ||
}; | ||
var notTs = function (netlifyGraphConfig, string) { | ||
return netlifyGraphConfig.language !== "typescript" ? string : ""; | ||
}; | ||
var subscriptionHandler = function (_a) { | ||
@@ -408,2 +411,3 @@ var netlifyGraphConfig = _a.netlifyGraphConfig, operationData = _a.operationData; | ||
var page = generatePage({ | ||
netlifyGraphConfig: netlifyGraphConfig, | ||
operationData: firstOperation, | ||
@@ -410,0 +414,0 @@ schema: opts.schema, |
@@ -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.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"; | ||
}; | ||
@@ -71,0 +71,0 @@ var subscriptionParserReturnName = function (fn) { return fn.operationName + "Event"; }; |
{ | ||
"name": "netlify-onegraph-internal", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"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
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance 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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
335288
4391