netlify-onegraph-internal
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -1,6 +0,11 @@ | ||
import { CodegenHelpers } from ".."; | ||
import { GraphQLSchema } from "graphql"; | ||
import * as GraphQLPackage from "graphql"; | ||
import { NetlifyGraphConfig, ParsedFragment, ParsedFunction } from "../netlifyGraph"; | ||
import * as CodegenHelpers from "./codegenHelpers"; | ||
export declare const generateFragmentTypeScriptDefinition: ({ fragment }: { | ||
fragment: any; | ||
}) => string; | ||
export declare const generateSubscriptionFunctionTypeDefinition: (GraphQL: typeof GraphQLPackage, schema: GraphQLSchema, fn: ParsedFunction, fragments: ParsedFragment[]) => string; | ||
export declare const generateSubscriptionFunction: (GraphQL: typeof GraphQLPackage, schema: GraphQLSchema, fn: ParsedFunction, fragments: never[], netlifyGraphConfig: NetlifyGraphConfig) => string; | ||
export declare const generateTypeScriptDefinitions: CodegenHelpers.GenerateRuntimeFunction; | ||
export declare const generateRuntime: CodegenHelpers.GenerateRuntimeFunction; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -12,3 +23,6 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateRuntime = exports.generateTypeScriptDefinitions = exports.generateFragmentTypeScriptDefinition = void 0; | ||
exports.generateRuntime = exports.generateTypeScriptDefinitions = exports.generateSubscriptionFunction = exports.generateSubscriptionFunctionTypeDefinition = exports.generateFragmentTypeScriptDefinition = void 0; | ||
var graphql_1 = require("graphql"); | ||
var graphqlHelpers_1 = require("../graphqlHelpers"); | ||
var __1 = require(".."); | ||
var generateFragmentTypeScriptDefinition = function (_a) { | ||
@@ -24,2 +38,49 @@ var fragment = _a.fragment; | ||
exports.generateFragmentTypeScriptDefinition = generateFragmentTypeScriptDefinition; | ||
var subscriptionParserReturnName = function (fn) { | ||
return fn.operationName + "Event"; | ||
}; | ||
var subscriptionParserName = function (fn) { | ||
return "parseAndVerify" + fn.operationName + "Event"; | ||
}; | ||
var subscriptionFunctionName = function (fn) { | ||
return "subscribeTo" + fn.operationName; | ||
}; | ||
var generateSubscriptionFunctionTypeDefinition = function (GraphQL, schema, fn, fragments) { | ||
var fragmentDefinitions = Object.entries(fragments).reduce(function (acc, _a) { | ||
var _b; | ||
var fragmentName = _a[0], fragment = _a[1]; | ||
return __assign(__assign({}, acc), (_b = {}, _b[fragmentName] = fragment.parsedOperation, _b)); | ||
}, {}); | ||
var parsingFunctionReturnSignature = (0, graphqlHelpers_1.typeScriptSignatureForOperation)(GraphQL, schema, fn.parsedOperation, fragmentDefinitions); | ||
var variableNames = (fn.parsedOperation.variableDefinitions || []).map(function (varDef) { return varDef.variable.name.value; }); | ||
var variableSignature = (0, graphqlHelpers_1.typeScriptSignatureForOperationVariables)(GraphQL, variableNames, schema, fn.parsedOperation); | ||
var jsDoc = replaceAll(fn.description || "", "*/", "!") | ||
.split("\n") | ||
.join("\n* "); | ||
return "/**\n * " + jsDoc + "\n */\n export 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 \n export type " + subscriptionParserReturnName(fn) + " = " + parsingFunctionReturnSignature + "\n \n /**\n * Verify the " + fn.operationName + " event body is signed securely, and then parse the result.\n */\n export function " + subscriptionParserName(fn) + " (/** A Netlify Handler Event */ event : WebhookEvent) : null | " + subscriptionParserReturnName(fn) + "\n "; | ||
}; | ||
exports.generateSubscriptionFunctionTypeDefinition = generateSubscriptionFunctionTypeDefinition; | ||
// TODO: Handle fragments | ||
var generateSubscriptionFunction = function (GraphQL, schema, fn, fragments, netlifyGraphConfig) { | ||
var _a; | ||
var patchedWithWebhookUrl = (0, graphqlHelpers_1.patchSubscriptionWebhookField)({ | ||
GraphQL: GraphQL, | ||
schema: schema, | ||
definition: fn.parsedOperation, | ||
}); | ||
var patched = (0, graphqlHelpers_1.patchSubscriptionWebhookSecretField)({ | ||
GraphQL: GraphQL, | ||
schema: schema, | ||
definition: patchedWithWebhookUrl, | ||
}); | ||
// TODO: Don't allow unnamed operations as subscription | ||
var filename = (patched.name && patched.name.value) || "Unknown"; | ||
var body = (0, graphql_1.print)(patched); | ||
var safeBody = replaceAll(body, "${", "\\${"); | ||
return "const " + subscriptionFunctionName(fn) + " = (\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 fetchStrategy: \"" + (fn.executionStrategy === "PERSISTED" && | ||
(((_a = fn.cacheStrategy) === null || _a === void 0 ? void 0 : _a.timeToLiveSeconds) || 0) > 0 | ||
? "GET" | ||
: "POST") + "\",\n })\n }\n \n const " + 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 }"; | ||
}; | ||
exports.generateSubscriptionFunction = generateSubscriptionFunction; | ||
var generateTypeScriptDefinitions = function (_a) { | ||
@@ -43,9 +104,3 @@ var GraphQL = _a.GraphQL, netlifyGraphConfig = _a.netlifyGraphConfig, schema = _a.schema, functionDefinitions = _a.functionDefinitions, fragments = _a.fragments; | ||
if (isSubscription) { | ||
return "TODO"; | ||
// return generateSubscriptionFunctionTypeDefinition( | ||
// GraphQL, | ||
// schema, | ||
// fn, | ||
// enabledFragments | ||
// ); | ||
return (0, exports.generateSubscriptionFunctionTypeDefinition)(GraphQL, schema, fn, fragments); | ||
} | ||
@@ -77,4 +132,4 @@ var jsDoc = replaceAll(fn.description || "", "*/", "") | ||
if (netlifyGraphConfig.runtimeTargetEnv === "node") { | ||
var subscriptionFnName = "TODO:subscriptionFunctionName(fn)"; | ||
var parserFnName = "TODO:subscriptionParserName(fn)"; | ||
var subscriptionFnName = subscriptionFunctionName(fn); | ||
var parserFnName = subscriptionParserName(fn); | ||
var jsDoc_1 = replaceAll(fn.description || "", "*/", "") | ||
@@ -130,3 +185,3 @@ .split("\n") | ||
var generateRuntime = function (opts) { | ||
var netlifyGraphConfig = opts.netlifyGraphConfig, schemaId = opts.schemaId; | ||
var netlifyGraphConfig = opts.netlifyGraphConfig, schema = opts.schema, schemaId = opts.schemaId; | ||
var export_ = function (netlifyGraphConfig, envs, name, value) { | ||
@@ -167,4 +222,4 @@ if (!envs.includes(netlifyGraphConfig.runtimeTargetEnv)) { | ||
if (netlifyGraphConfig.runtimeTargetEnv === "node") { | ||
var subscriptionFnName = "TODO_SUB"; | ||
var parserFnName = "TODO_SUB"; | ||
var subscriptionFnName = subscriptionFunctionName(fn); | ||
var parserFnName = subscriptionParserName(fn); | ||
var jsDoc_2 = replaceAll(fn.description || "", "*/", "") | ||
@@ -195,10 +250,3 @@ .split("\n") | ||
var fragments = []; | ||
return "TODO_SUBSCRIPTION"; | ||
// return generateSubscriptionFunction( | ||
// GraphQL, | ||
// schema, | ||
// fn, | ||
// fragments, | ||
// netlifyGraphConfig | ||
// ); | ||
return (0, exports.generateSubscriptionFunction)(__1.GraphQL, schema, fn, fragments, netlifyGraphConfig); | ||
} | ||
@@ -205,0 +253,0 @@ var dynamicFunction = export_(netlifyGraphConfig, ["browser", "node"], fn.fnName, "(\n variables,\n options\n ) => {\n return fetchNetlifyGraph({\n query: `" + fn.persistableOperationString + "`,\n operationName: \"" + fn.operationName + "\",\n variables: variables,\n options: options,\n fetchStrategy: \"" + (fn.executionStrategy === "PERSISTED" && |
@@ -23,5 +23,5 @@ import { FragmentDefinitionNode, OperationDefinitionNode } from "graphql"; | ||
export declare const netlifyFunctionSnippet: Codegen; | ||
export declare const id = "netlify-graph-codegen/serverless-default"; | ||
export declare const id = "netlify-builtin:serverless"; | ||
export declare const version = "0.0.1"; | ||
export declare const generators: Codegen[]; | ||
export declare const codegenModule: CodegenHelpers.IncludedCodegenModule; |
@@ -385,3 +385,3 @@ "use strict"; | ||
}; | ||
exports.id = "netlify-graph-codegen/serverless-default"; | ||
exports.id = "netlify-builtin:serverless"; | ||
exports.version = "0.0.1"; | ||
@@ -394,4 +394,4 @@ exports.generators = [exports.netlifyFunctionSnippet]; | ||
generateRuntime: common_1.generateRuntime, | ||
sigil: "__included/netlify-graph-codegen/serverless-default", | ||
sigil: "netlify-builtin:serverless", | ||
}; | ||
//# sourceMappingURL=genericExporter.js.map |
@@ -10,5 +10,5 @@ import * as GraphQLPackage from "graphql"; | ||
export declare const nextjsFunctionSnippet: Codegen; | ||
export declare const id = "netlify-graph-codegen/nextjs-default"; | ||
export declare const id = "netlify-builtin:nextjs"; | ||
export declare const version = "0.0.1"; | ||
export declare const generators: Codegen[]; | ||
export declare const codegenModule: CodegenHelpers.IncludedCodegenModule; |
@@ -428,3 +428,3 @@ "use strict"; | ||
}; | ||
exports.id = "netlify-graph-codegen/nextjs-default"; | ||
exports.id = "netlify-builtin:nextjs"; | ||
exports.version = "0.0.1"; | ||
@@ -437,4 +437,4 @@ exports.generators = [exports.nextjsFunctionSnippet]; | ||
generateRuntime: common_1.generateRuntime, | ||
sigil: "__included/netlify-graph-codegen/nextjs-default", | ||
sigil: "netlify-builtin:nextjs", | ||
}; | ||
//# sourceMappingURL=nextjsExporter.js.map |
@@ -20,5 +20,5 @@ import * as GraphQLPackage from "graphql"; | ||
export declare const remixFunctionSnippet: Codegen; | ||
export declare const id = "netlify-graph-codegen/remix-default"; | ||
export declare const id = "netlify-builtin:remix"; | ||
export declare const version = "0.0.1"; | ||
export declare const generators: Codegen[]; | ||
export declare const codegenModule: CodegenHelpers.IncludedCodegenModule; |
@@ -448,3 +448,3 @@ "use strict"; | ||
}; | ||
exports.id = "netlify-graph-codegen/remix-default"; | ||
exports.id = "netlify-builtin:remix"; | ||
exports.version = "0.0.1"; | ||
@@ -457,4 +457,4 @@ exports.generators = [exports.remixFunctionSnippet]; | ||
generateRuntime: common_1.generateRuntime, | ||
sigil: "__included/netlify-graph-codegen/remix-default", | ||
sigil: "netlify-builtin:remix", | ||
}; | ||
//# sourceMappingURL=remixExporter.js.map |
{ | ||
"name": "netlify-onegraph-internal", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"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
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
553604
7069
19