@netlify/functions
Advanced tools
Comparing version 1.1.0-rc to 2.0.0-beta
@@ -1,3 +0,3 @@ | ||
import { BuilderHandler, Handler } from '../function/handler'; | ||
import { BuilderHandler, Handler } from '../v1/handler'; | ||
declare const wrapHandler: (handler: BuilderHandler) => Handler; | ||
export { wrapHandler as builder }; |
"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 __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -18,5 +7,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.builder = void 0; | ||
var is_promise_1 = __importDefault(require("is-promise")); | ||
var consts_1 = require("./consts"); | ||
var augmentResponse = function (response) { | ||
const is_promise_1 = __importDefault(require("is-promise")); | ||
const consts_1 = require("./consts"); | ||
const augmentResponse = (response) => { | ||
var _a; | ||
@@ -26,26 +15,25 @@ if (!response || response.statusCode !== consts_1.HTTP_STATUS_OK) { | ||
} | ||
var metadata = { version: consts_1.METADATA_VERSION, builder_function: consts_1.BUILDER_FUNCTIONS_FLAG, ttl: (_a = response.ttl) !== null && _a !== void 0 ? _a : 0 }; | ||
return __assign(__assign({}, response), { metadata: metadata }); | ||
const metadata = { version: consts_1.METADATA_VERSION, builder_function: consts_1.BUILDER_FUNCTIONS_FLAG, ttl: (_a = response.ttl) !== null && _a !== void 0 ? _a : 0 }; | ||
return Object.assign(Object.assign({}, response), { metadata }); | ||
}; | ||
var wrapHandler = function (handler) { | ||
const wrapHandler = (handler) => | ||
// eslint-disable-next-line promise/prefer-await-to-callbacks | ||
(event, context, callback) => { | ||
if (event.httpMethod !== 'GET' && event.httpMethod !== 'HEAD') { | ||
return Promise.resolve({ | ||
body: 'Method Not Allowed', | ||
statusCode: consts_1.HTTP_STATUS_METHOD_NOT_ALLOWED, | ||
}); | ||
} | ||
// Removing query string parameters from the builder function. | ||
const modifiedEvent = Object.assign(Object.assign({}, event), { multiValueQueryStringParameters: {}, queryStringParameters: {} }); | ||
// eslint-disable-next-line promise/prefer-await-to-callbacks | ||
return function (event, context, callback) { | ||
if (event.httpMethod !== 'GET' && event.httpMethod !== 'HEAD') { | ||
return Promise.resolve({ | ||
body: 'Method Not Allowed', | ||
statusCode: consts_1.HTTP_STATUS_METHOD_NOT_ALLOWED, | ||
}); | ||
} | ||
// Removing query string parameters from the builder function. | ||
var modifiedEvent = __assign(__assign({}, event), { multiValueQueryStringParameters: {}, queryStringParameters: {} }); | ||
// eslint-disable-next-line promise/prefer-await-to-callbacks | ||
var wrappedCallback = function (error, response) { return callback === null || callback === void 0 ? void 0 : callback(error, augmentResponse(response)); }; | ||
var execution = handler(modifiedEvent, context, wrappedCallback); | ||
if ((0, is_promise_1.default)(execution)) { | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
return execution.then(augmentResponse); | ||
} | ||
return execution; | ||
}; | ||
const wrappedCallback = (error, response) => callback === null || callback === void 0 ? void 0 : callback(error, augmentResponse(response)); | ||
const execution = handler(modifiedEvent, context, wrappedCallback); | ||
if ((0, is_promise_1.default)(execution)) { | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
return execution.then(augmentResponse); | ||
} | ||
return execution; | ||
}; | ||
exports.builder = wrapHandler; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.METADATA_VERSION = exports.HTTP_STATUS_OK = exports.HTTP_STATUS_METHOD_NOT_ALLOWED = exports.BUILDER_FUNCTIONS_FLAG = void 0; | ||
var BUILDER_FUNCTIONS_FLAG = true; | ||
const BUILDER_FUNCTIONS_FLAG = true; | ||
exports.BUILDER_FUNCTIONS_FLAG = BUILDER_FUNCTIONS_FLAG; | ||
var HTTP_STATUS_METHOD_NOT_ALLOWED = 405; | ||
const HTTP_STATUS_METHOD_NOT_ALLOWED = 405; | ||
exports.HTTP_STATUS_METHOD_NOT_ALLOWED = HTTP_STATUS_METHOD_NOT_ALLOWED; | ||
var HTTP_STATUS_OK = 200; | ||
const HTTP_STATUS_OK = 200; | ||
exports.HTTP_STATUS_OK = HTTP_STATUS_OK; | ||
var METADATA_VERSION = 1; | ||
const METADATA_VERSION = 1; | ||
exports.METADATA_VERSION = METADATA_VERSION; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.graphRequest = void 0; | ||
var buffer_1 = require("buffer"); | ||
var https_1 = require("https"); | ||
var process_1 = require("process"); | ||
var siteId = process_1.env.SITE_ID; | ||
var GRAPH_HOST = 'graph.netlify.com'; | ||
var graphRequest = function (secretToken, requestBody) { | ||
return new Promise(function (resolve, reject) { | ||
var port = 443; | ||
var options = { | ||
const buffer_1 = require("buffer"); | ||
const https_1 = require("https"); | ||
const process_1 = require("process"); | ||
const siteId = process_1.env.SITE_ID; | ||
const GRAPH_HOST = 'graph.netlify.com'; | ||
const graphRequest = function (secretToken, requestBody) { | ||
return new Promise((resolve, reject) => { | ||
const port = 443; | ||
const options = { | ||
host: GRAPH_HOST, | ||
path: "/graphql?app_id=".concat(siteId), | ||
port: port, | ||
path: `/graphql?app_id=${siteId}`, | ||
port, | ||
method: 'POST', | ||
headers: { | ||
Authorization: "Bearer ".concat(secretToken), | ||
Authorization: `Bearer ${secretToken}`, | ||
'Content-Type': 'application/json', | ||
@@ -24,12 +24,12 @@ Accept: 'application/json', | ||
}; | ||
var req = (0, https_1.request)(options, function (res) { | ||
const req = (0, https_1.request)(options, (res) => { | ||
if (res.statusCode !== 200) { | ||
return reject(new Error(String(res.statusCode))); | ||
} | ||
var body = []; | ||
res.on('data', function (chunk) { | ||
const body = []; | ||
res.on('data', (chunk) => { | ||
body.push(chunk); | ||
}); | ||
res.on('end', function () { | ||
var data = buffer_1.Buffer.concat(body).toString(); | ||
res.on('end', () => { | ||
const data = buffer_1.Buffer.concat(body).toString(); | ||
try { | ||
@@ -43,3 +43,3 @@ resolve(data); | ||
}); | ||
req.on('error', function (error) { | ||
req.on('error', (error) => { | ||
reject(error); | ||
@@ -46,0 +46,0 @@ }); |
@@ -18,3 +18,3 @@ export declare type GraphTokenResponseError = { | ||
} | ||
export declare const getNetlifyGraphToken: (event?: HasHeaders | null | undefined, supressLog?: boolean | undefined) => GraphTokenResponse; | ||
export declare const getNetlifyGraphToken: (event?: HasHeaders | null | undefined, supressLog?: boolean) => GraphTokenResponse; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getNetlifyGraphToken = void 0; | ||
var process_1 = require("process"); | ||
var TOKEN_HEADER = 'X-Nf-Graph-Token'; | ||
var hasRequestStyleHeaders = function (headers) { | ||
const process_1 = require("process"); | ||
const TOKEN_HEADER = 'X-Nf-Graph-Token'; | ||
const hasRequestStyleHeaders = function (headers) { | ||
return headers.get !== undefined && typeof headers.get === 'function'; | ||
}; | ||
var graphTokenFromIncomingHttpStyleHeaders = function (headers) { | ||
const graphTokenFromIncomingHttpStyleHeaders = function (headers) { | ||
if (TOKEN_HEADER in headers) { | ||
var header = headers[TOKEN_HEADER]; | ||
const header = headers[TOKEN_HEADER]; | ||
if (header == null || typeof header === 'string') { | ||
@@ -19,12 +19,12 @@ return header; | ||
// Backwards compatibility with older version of cli that doesn't inject header | ||
var authlifyTokenFallback = function (event) { | ||
var token = event === null || event === void 0 ? void 0 : event.authlifyToken; | ||
return { token: token }; | ||
const authlifyTokenFallback = function (event) { | ||
const token = event === null || event === void 0 ? void 0 : event.authlifyToken; | ||
return { token }; | ||
}; | ||
var graphTokenFromEvent = function (event) { | ||
var headers = event.headers; | ||
const graphTokenFromEvent = function (event) { | ||
const { headers } = event; | ||
// Check if object first in case there is a header with key `get` | ||
var token = graphTokenFromIncomingHttpStyleHeaders(headers); | ||
const token = graphTokenFromIncomingHttpStyleHeaders(headers); | ||
if (token) { | ||
return { token: token }; | ||
return { token }; | ||
} | ||
@@ -36,15 +36,15 @@ if (hasRequestStyleHeaders(headers)) { | ||
}; | ||
var graphTokenFromEnv = function () { | ||
const graphTokenFromEnv = function () { | ||
// _NETLIFY_GRAPH_TOKEN injected by next plugin | ||
// eslint-disable-next-line no-underscore-dangle | ||
var token = process_1.env._NETLIFY_GRAPH_TOKEN || process_1.env.NETLIFY_GRAPH_TOKEN; | ||
return { token: token }; | ||
const token = process_1.env._NETLIFY_GRAPH_TOKEN || process_1.env.NETLIFY_GRAPH_TOKEN; | ||
return { token }; | ||
}; | ||
var isEventRequired = function () { | ||
var localDev = process_1.env.NETLIFY_DEV === 'true'; | ||
var localBuild = !localDev && process_1.env.NETLIFY_LOCAL === 'true'; | ||
var remoteBuild = process_1.env.NETLIFY === 'true'; | ||
const isEventRequired = function () { | ||
const localDev = process_1.env.NETLIFY_DEV === 'true'; | ||
const localBuild = !localDev && process_1.env.NETLIFY_LOCAL === 'true'; | ||
const remoteBuild = process_1.env.NETLIFY === 'true'; | ||
// neither `localBuild` nor `remoteBuild` will be true in the on-demand builder case | ||
var inBuildPhase = localBuild || remoteBuild; | ||
var inGetStaticProps = | ||
const inBuildPhase = localBuild || remoteBuild; | ||
const inGetStaticProps = | ||
// Set by the nextjs plugin | ||
@@ -55,16 +55,15 @@ // eslint-disable-next-line no-underscore-dangle | ||
}; | ||
var incorrectArgumentsErrors = function (event) { | ||
var requiresEvent = isEventRequired(); | ||
const incorrectArgumentsErrors = function (event) { | ||
const requiresEvent = isEventRequired(); | ||
if (requiresEvent && event == null) { | ||
var errorMessage = 'You must provide an event or request to `getNetlifyGraphToken` when used in functions and on-demand builders.'; | ||
const errorMessage = 'You must provide an event or request to `getNetlifyGraphToken` when used in functions and on-demand builders.'; | ||
return [{ type: 'missing-event-in-function', message: errorMessage }]; | ||
} | ||
if (!requiresEvent && event != null) { | ||
var errorMessage = 'You must not pass arguments to `getNetlifyGraphToken` when used in builds.'; | ||
const errorMessage = 'You must not pass arguments to `getNetlifyGraphToken` when used in builds.'; | ||
return [{ type: 'provided-event-in-build', message: errorMessage }]; | ||
} | ||
}; | ||
var logErrors = function (errors) { | ||
for (var _i = 0, errors_1 = errors; _i < errors_1.length; _i++) { | ||
var error = errors_1[_i]; | ||
const logErrors = function (errors) { | ||
for (const error of errors) { | ||
// Log errors to help guide developer | ||
@@ -74,6 +73,6 @@ console.error(error.message); | ||
}; | ||
var getNetlifyGraphToken = function (event, | ||
const getNetlifyGraphToken = function (event, | ||
// caller can prevent error log. Allows getSecrets to provide better errors | ||
supressLog) { | ||
var errors = incorrectArgumentsErrors(event); | ||
const errors = incorrectArgumentsErrors(event); | ||
if (errors) { | ||
@@ -83,3 +82,3 @@ if (!supressLog) { | ||
} | ||
return { errors: errors }; | ||
return { errors }; | ||
} | ||
@@ -86,0 +85,0 @@ return event ? graphTokenFromEvent(event) : graphTokenFromEnv(); |
@@ -1,5 +0,5 @@ | ||
import { Context as HandlerContext, Context } from '../function/context'; | ||
import { Event as HandlerEvent } from '../function/event'; | ||
import { BaseHandler, HandlerCallback } from '../function/handler'; | ||
import { Response } from '../function/response'; | ||
import { Context as HandlerContext, Context } from '../v1/context'; | ||
import { Event as HandlerEvent } from '../v1/event'; | ||
import { BaseHandler, HandlerCallback } from '../v1/handler'; | ||
import { Response } from '../v1/response'; | ||
import { NetlifySecrets } from './secrets_helper'; | ||
@@ -6,0 +6,0 @@ export { getSecrets } from './secrets_helper'; |
"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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -22,32 +11,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withSecrets = exports.getNetlifyGraphToken = exports.getSecrets = void 0; | ||
var secrets_helper_1 = require("./secrets_helper"); | ||
const secrets_helper_1 = require("./secrets_helper"); | ||
// Fine-grained control during the preview, less necessary with a more proactive OneGraph solution | ||
@@ -59,17 +21,8 @@ var secrets_helper_2 = require("./secrets_helper"); | ||
// The common usage of this module | ||
var withSecrets = function (handler) { | ||
return function (event, context, | ||
// eslint-disable-next-line promise/prefer-await-to-callbacks | ||
callback) { return __awaiter(void 0, void 0, void 0, function () { | ||
var secrets; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, (0, secrets_helper_1.getSecrets)(event)]; | ||
case 1: | ||
secrets = _a.sent(); | ||
return [2 /*return*/, handler(event, __assign(__assign({}, context), { secrets: secrets }), callback)]; | ||
} | ||
}); | ||
}); }; | ||
}; | ||
const withSecrets = (handler) => (event, context, | ||
// eslint-disable-next-line promise/prefer-await-to-callbacks | ||
callback) => __awaiter(void 0, void 0, void 0, function* () { | ||
const secrets = yield (0, secrets_helper_1.getSecrets)(event); | ||
return handler(event, Object.assign(Object.assign({}, context), { secrets }), callback); | ||
}); | ||
exports.withSecrets = withSecrets; |
@@ -1,2 +0,2 @@ | ||
import type { Handler } from '../function'; | ||
import type { Handler } from '../v1'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Declares a function to run on a cron schedule. |
@@ -19,3 +19,3 @@ "use strict"; | ||
*/ | ||
var schedule = function (cron, handler) { return handler; }; | ||
const schedule = (cron, handler) => handler; | ||
exports.schedule = schedule; |
"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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -22,34 +11,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getSecrets = void 0; | ||
var graph_request_1 = require("./graph_request"); | ||
var graph_token_1 = require("./graph_token"); | ||
var services = { | ||
const graph_request_1 = require("./graph_request"); | ||
const graph_token_1 = require("./graph_token"); | ||
const services = { | ||
gitHub: null, | ||
@@ -60,4 +22,4 @@ spotify: null, | ||
}; | ||
var camelize = function (text) { | ||
var safe = text.replace(/[-_\s.]+(.)?/g, function (_, sub) { return (sub ? sub.toUpperCase() : ''); }); | ||
const camelize = function (text) { | ||
const safe = text.replace(/[-_\s.]+(.)?/g, (_, sub) => (sub ? sub.toUpperCase() : '')); | ||
return safe.slice(0, 1).toLowerCase() + safe.slice(1); | ||
@@ -67,23 +29,21 @@ }; | ||
// unless overridden by the serviceNormalizeOverrides object | ||
var serviceNormalizeOverrides = { | ||
const serviceNormalizeOverrides = { | ||
// Keys are the OneGraph service enums, values are the desired `secret.<service>` names | ||
GITHUB: 'gitHub', | ||
}; | ||
var formatSecrets = function (result) { | ||
const formatSecrets = (result) => { | ||
var _a, _b, _c; | ||
var responseServices = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.me) === null || _b === void 0 ? void 0 : _b.serviceMetadata) === null || _c === void 0 ? void 0 : _c.loggedInServices; | ||
const responseServices = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.me) === null || _b === void 0 ? void 0 : _b.serviceMetadata) === null || _c === void 0 ? void 0 : _c.loggedInServices; | ||
if (!responseServices) { | ||
return {}; | ||
} | ||
var newSecrets = responseServices.reduce(function (acc, service) { | ||
var _a; | ||
var normalized = serviceNormalizeOverrides[service.service] || camelize(service.friendlyServiceName); | ||
return __assign(__assign({}, acc), (_a = {}, _a[normalized] = service, _a)); | ||
const newSecrets = responseServices.reduce((acc, service) => { | ||
const normalized = serviceNormalizeOverrides[service.service] || camelize(service.friendlyServiceName); | ||
return Object.assign(Object.assign({}, acc), { [normalized]: service }); | ||
}, {}); | ||
return newSecrets; | ||
}; | ||
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; | ||
const logErrors = function (errors) { | ||
for (const error of errors) { | ||
let errorMessage; | ||
switch (error.type) { | ||
@@ -99,3 +59,3 @@ case 'missing-event-in-function': | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
var exhaustiveCheck = error.type; | ||
const exhaustiveCheck = error.type; | ||
errorMessage = error.type; | ||
@@ -105,3 +65,3 @@ break; | ||
} | ||
var message = errorMessage; | ||
const message = errorMessage; | ||
console.error(message); | ||
@@ -112,26 +72,46 @@ } | ||
// e.g. "dev" and "prod" | ||
var getSecrets = function (event) { return __awaiter(void 0, void 0, void 0, function () { | ||
var graphTokenResponse, graphToken, doc, body, resultBody, result, newSecrets; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
graphTokenResponse = (0, graph_token_1.getNetlifyGraphToken)(event, true); | ||
graphToken = graphTokenResponse.token; | ||
if (!graphToken) { | ||
if (graphTokenResponse.errors) { | ||
logErrors(graphTokenResponse.errors); | ||
} | ||
return [2 /*return*/, {}]; | ||
} | ||
doc = "query FindLoggedInServicesQuery {\n me {\n serviceMetadata {\n loggedInServices {\n friendlyServiceName\n service\n isLoggedIn\n bearerToken\n grantedScopes {\n scope\n scopeInfo {\n category\n scope\n display\n isDefault\n isRequired\n description\n title\n }\n }\n }\n }\n }\n }"; | ||
body = JSON.stringify({ query: doc }); | ||
return [4 /*yield*/, (0, graph_request_1.graphRequest)(graphToken, new TextEncoder().encode(body))]; | ||
case 1: | ||
resultBody = _a.sent(); | ||
result = JSON.parse(resultBody); | ||
newSecrets = formatSecrets(result); | ||
return [2 /*return*/, newSecrets]; | ||
const getSecrets = (event) => __awaiter(void 0, void 0, void 0, function* () { | ||
const graphTokenResponse = (0, graph_token_1.getNetlifyGraphToken)(event, true); | ||
const graphToken = graphTokenResponse.token; | ||
if (!graphToken) { | ||
if (graphTokenResponse.errors) { | ||
logErrors(graphTokenResponse.errors); | ||
} | ||
}); | ||
}); }; | ||
return {}; | ||
} | ||
// We select for more than we typeically need here | ||
// in order to allow for some metaprogramming for | ||
// consumers downstream. Also, the data is typically | ||
// static and shouldn't add any measurable overhead. | ||
const doc = `query FindLoggedInServicesQuery { | ||
me { | ||
serviceMetadata { | ||
loggedInServices { | ||
friendlyServiceName | ||
service | ||
isLoggedIn | ||
bearerToken | ||
grantedScopes { | ||
scope | ||
scopeInfo { | ||
category | ||
scope | ||
display | ||
isDefault | ||
isRequired | ||
description | ||
title | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const body = JSON.stringify({ query: doc }); | ||
// eslint-disable-next-line node/no-unsupported-features/node-builtins | ||
const resultBody = yield (0, graph_request_1.graphRequest)(graphToken, new TextEncoder().encode(body)); | ||
const result = JSON.parse(resultBody); | ||
const newSecrets = formatSecrets(result); | ||
return newSecrets; | ||
}); | ||
exports.getSecrets = getSecrets; |
export { builder } from './lib/builder'; | ||
export { schedule } from './lib/schedule'; | ||
export * from './function'; | ||
export * from './v1'; | ||
export * from './v2'; |
@@ -22,2 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "schedule", { enumerable: true, get: function () { return schedule_1.schedule; } }); | ||
__exportStar(require("./function"), exports); | ||
__exportStar(require("./v1"), exports); | ||
__exportStar(require("./v2"), exports); |
@@ -5,3 +5,3 @@ { | ||
"types": "./dist/main.d.ts", | ||
"version": "1.1.0-rc", | ||
"version": "2.0.0-beta", | ||
"description": "JavaScript utilities for Netlify Functions", | ||
@@ -32,4 +32,4 @@ "files": [ | ||
"config": { | ||
"eslint": "--ignore-pattern README.md --ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,.github}/**/*.{ts,js,md,html}\" \"*.{ts,js,md,html}\" \".*.{ts,js,md,html}\"", | ||
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,.github}/**/*.{ts,js,md,yml,json,html}\" \"*.{ts,js,yml,json,html}\" \".*.{ts,js,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\"" | ||
"eslint": "--ignore-pattern \"src/vendor/**/*.ts\" --ignore-pattern README.md --ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,.github}/**/*.{ts,js,md,html}\" \"*.{ts,js,md,html}\" \".*.{ts,js,md,html}\"", | ||
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,.github}/**/*.{ts,js,md,yml,json,html}\" \"*.{ts,js,yml,json,html}\" \".*.{ts,js,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\" \"!src/vendor/**/*\"" | ||
}, | ||
@@ -53,3 +53,5 @@ "ava": { | ||
"dependencies": { | ||
"is-promise": "^4.0.0" | ||
"cookie": "^0.5.0", | ||
"is-promise": "^4.0.0", | ||
"undici": "^5.6.0" | ||
}, | ||
@@ -56,0 +58,0 @@ "devDependencies": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
82297
55
1987
3
2
+ Addedcookie@^0.5.0
+ Addedundici@^5.6.0
+ Added@fastify/busboy@2.1.1(transitive)
+ Addedcookie@0.5.0(transitive)
+ Addedundici@5.28.4(transitive)