Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@netlify/functions

Package Overview
Dependencies
Maintainers
17
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/functions - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0-rc

dist/lib/graph_request.d.ts

2

dist/function/index.d.ts

@@ -5,3 +5,3 @@ export { Context as HandlerContext } from './context';

export { Response as HandlerResponse } from './response';
export { getSecrets, withSecrets } from '../lib/secrets';
export { getSecrets, withSecrets, getNetlifyGraphToken, GraphTokenResponse, HasHeaders } from '../lib/graph';
export { NetlifySecrets } from '../lib/secrets_helper';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withSecrets = exports.getSecrets = void 0;
var secrets_1 = require("../lib/secrets");
Object.defineProperty(exports, "getSecrets", { enumerable: true, get: function () { return secrets_1.getSecrets; } });
Object.defineProperty(exports, "withSecrets", { enumerable: true, get: function () { return secrets_1.withSecrets; } });
exports.getNetlifyGraphToken = exports.withSecrets = exports.getSecrets = void 0;
var graph_1 = require("../lib/graph");
Object.defineProperty(exports, "getSecrets", { enumerable: true, get: function () { return graph_1.getSecrets; } });
Object.defineProperty(exports, "withSecrets", { enumerable: true, get: function () { return graph_1.withSecrets; } });
Object.defineProperty(exports, "getNetlifyGraphToken", { enumerable: true, get: function () { return graph_1.getNetlifyGraphToken; } });

@@ -1,2 +0,2 @@

import { Event as HandlerEvent } from '../function/event';
import { HasHeaders } from './graph_token';
declare const services: {

@@ -34,7 +34,3 @@ gitHub: null;

};
declare type OneGraphPayload = {
authlifyToken: string | undefined;
};
export declare type HandlerEventWithOneGraph = HandlerEvent & OneGraphPayload;
export declare const getSecrets: (event?: HandlerEventWithOneGraph | HandlerEvent | undefined) => Promise<NetlifySecrets>;
export declare const getSecrets: (event?: HasHeaders | null | undefined) => Promise<NetlifySecrets>;
export {};

@@ -51,5 +51,4 @@ "use strict";

exports.getSecrets = void 0;
var buffer_1 = require("buffer");
var https_1 = require("https");
var process_1 = require("process");
var graph_request_1 = require("./graph_request");
var graph_token_1 = require("./graph_token");
var services = {

@@ -61,3 +60,2 @@ gitHub: null,

};
var siteId = process_1.env.SITE_ID;
var camelize = function (text) {

@@ -73,43 +71,2 @@ var safe = text.replace(/[-_\s.]+(.)?/g, function (_, sub) { return (sub ? sub.toUpperCase() : ''); });

};
var oneGraphRequest = function (secretToken, requestBody) {
return new Promise(function (resolve, reject) {
var port = 443;
var options = {
host: 'serve.onegraph.com',
path: "/graphql?app_id=".concat(siteId),
port: port,
method: 'POST',
headers: {
Authorization: "Bearer ".concat(secretToken),
'Content-Type': 'application/json',
Accept: 'application/json',
'Content-Length': requestBody ? buffer_1.Buffer.byteLength(requestBody) : 0,
},
};
var req = (0, https_1.request)(options, function (res) {
if (res.statusCode !== 200) {
return reject(new Error(String(res.statusCode)));
}
var body = [];
res.on('data', function (chunk) {
body.push(chunk);
});
res.on('end', function () {
var data = buffer_1.Buffer.concat(body).toString();
try {
var result = JSON.parse(data);
resolve(result);
}
catch (error) {
reject(error);
}
});
});
req.on('error', function (error) {
reject(error);
});
req.write(requestBody);
req.end();
});
};
var formatSecrets = function (result) {

@@ -128,13 +85,38 @@ var _a, _b, _c;

};
var logErrors = function (errors) {
for (var _i = 0, errors_1 = errors; _i < errors_1.length; _i++) {
var error = errors_1[_i];
var errorMessage = void 0;
switch (error.type) {
case 'missing-event-in-function':
errorMessage =
'You must provide an event or request to `getSecrets` when used in functions and on-demand builders.';
break;
case 'provided-event-in-build':
errorMessage = 'You must not pass arguments to `getSecrets` when used in builds.';
break;
default: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var exhaustiveCheck = error.type;
errorMessage = error.type;
break;
}
}
var message = errorMessage;
console.error(message);
}
};
// Note: We may want to have configurable "sets" of secrets,
// e.g. "dev" and "prod"
var getSecrets = function (event) { return __awaiter(void 0, void 0, void 0, function () {
var eventToken, secretToken, doc, body, result, newSecrets;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
var graphTokenResponse, graphToken, doc, body, resultBody, result, newSecrets;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
eventToken = (_a = event) === null || _a === void 0 ? void 0 : _a.authlifyToken;
secretToken = eventToken || process_1.env.ONEGRAPH_AUTHLIFY_TOKEN;
if (!secretToken) {
graphTokenResponse = (0, graph_token_1.getNetlifyGraphToken)(event, true);
graphToken = graphTokenResponse.token;
if (!graphToken) {
if (graphTokenResponse.errors) {
logErrors(graphTokenResponse.errors);
}
return [2 /*return*/, {}];

@@ -144,5 +126,6 @@ }

body = JSON.stringify({ query: doc });
return [4 /*yield*/, oneGraphRequest(secretToken, new TextEncoder().encode(body))];
return [4 /*yield*/, (0, graph_request_1.graphRequest)(graphToken, new TextEncoder().encode(body))];
case 1:
result = _b.sent();
resultBody = _a.sent();
result = JSON.parse(resultBody);
newSecrets = formatSecrets(result);

@@ -149,0 +132,0 @@ return [2 /*return*/, newSecrets];

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -5,3 +5,3 @@ {

"types": "./dist/main.d.ts",
"version": "1.0.0",
"version": "1.1.0-rc",
"description": "JavaScript utilities for Netlify Functions",

@@ -57,3 +57,3 @@ "files": [

"@commitlint/config-conventional": "^13.0.0",
"@netlify/eslint-config-node": "^5.1.4",
"@netlify/eslint-config-node": "^5.1.8",
"ava": "^2.4.0",

@@ -60,0 +60,0 @@ "husky": "^7.0.4",

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