@journeyapps/cloudcode
Advanced tools
Comparing version 0.0.0-dev.7efd186 to 0.0.0-dev.800dc27
@@ -30,3 +30,3 @@ 'use strict'; | ||
assert(instance, 'instance is required'); | ||
DatabaseAuth_1.validateAuth(auth); | ||
(0, DatabaseAuth_1.validateAuth)(auth); | ||
let url = `${baseUrl}/api/v4/${instance}`; | ||
@@ -40,3 +40,3 @@ // Returning type T is kind of equivalent to returning "any" - it will take the form of whatever the type of the | ||
// Typical error: Type 'Database & GenericDatabaseCollections' is missing the following properties from type 'DB': user, push_notification | ||
return db_1.OnlineDB({ | ||
return (0, db_1.OnlineDB)({ | ||
baseUrl: url, | ||
@@ -52,3 +52,3 @@ dataModelPath: './app/schema.xml', | ||
assert(instance, 'instance is required'); | ||
DatabaseAuth_1.validateAuth(auth); | ||
(0, DatabaseAuth_1.validateAuth)(auth); | ||
let url = `${baseUrl}/api/v4/${instance}`; | ||
@@ -55,0 +55,0 @@ const credentials = new db_1.ApiCredentials({ baseUrl: url, ...auth }); |
@@ -6,3 +6,3 @@ "use strict"; | ||
const source_map_support_1 = require("source-map-support"); | ||
source_map_support_1.install({ | ||
(0, source_map_support_1.install)({ | ||
hookRequire: true, | ||
@@ -34,3 +34,3 @@ handleUncaughtExceptions: false | ||
} | ||
const { system: systemConsole } = logs_1.createLoggers({ | ||
const { system: systemConsole } = (0, logs_1.createLoggers)({ | ||
console: console, | ||
@@ -40,3 +40,3 @@ globalObject: global, | ||
}); | ||
environment_1.setup(exports.config.appId, exports.config.env, exports.config.task); | ||
(0, environment_1.setup)(exports.config.appId, exports.config.env, exports.config.task); | ||
systemConsole.event({ | ||
@@ -46,3 +46,3 @@ event: 'START_PROCESS', | ||
processId: exports.PROCESS_ID, | ||
message: `Start process. Process trace ID: ${exports.PROCESS_ID}` | ||
message: `Start process. Process trace ID: ${exports.PROCESS_ID}. Revision: ${global.CloudCode.deployInfo.description}.` | ||
}); | ||
@@ -69,3 +69,3 @@ // Default Lambda uncaughtException handler does a process.exit(1), preventing us from logging the error. | ||
function flushAndExit() { | ||
logs_1.flush(); | ||
(0, logs_1.flush)(); | ||
// Exit process after the logs have been flushed. | ||
@@ -72,0 +72,0 @@ // HACK: It would be better to have some callback on the logs. |
@@ -20,3 +20,2 @@ "use strict"; | ||
} | ||
let blacklisted = false; | ||
for (let re of HOST_BLACKLIST) { | ||
@@ -37,7 +36,7 @@ if (re.test(host)) { | ||
* | ||
* @return {string[]} array of descriptions of open sockets | ||
* @return array of descriptions of open sockets | ||
*/ | ||
function getActiveHandles() { | ||
var results = []; | ||
var handles = process._getActiveHandles(); | ||
let results = []; | ||
const handles = process._getActiveHandles(); | ||
for (let handle of handles) { | ||
@@ -62,5 +61,14 @@ if (isSocket(handle)) { | ||
if (socket._httpMessage) { | ||
if (socket._httpMessage.res && !socket._httpMessage.res.readable) { | ||
// Alternative: `socket._httpMessage.res?._readableState?.ended` | ||
// Even though the socket is still open, the response has been read. | ||
// This is typically the case if the developer did `await response.text()`. This is good enough. | ||
// Alternatively, we could say that even just `await fetch(...)` is good enough. The presence of `.res` | ||
// would be a good indication of that. | ||
continue; | ||
} | ||
message = `HTTP ${socket._httpMessage.method} ${socket._host} ${socket._httpMessage.path}`; | ||
} | ||
else if (socket._host) { | ||
// Note: This could include HTTP requests, where the request hasn't been sent yet. | ||
message = `Socket ${socket._host}`; | ||
@@ -81,3 +89,3 @@ } | ||
function busycheck() { | ||
var handles = getActiveHandles(); | ||
const handles = getActiveHandles(); | ||
if (handles.length > 0) { | ||
@@ -84,0 +92,0 @@ let msg = 'Some requests are still active, and block the response until they complete:'; |
@@ -18,4 +18,11 @@ import { Database } from '@journeyapps/db'; | ||
} | ||
export interface DeployInfo { | ||
readonly revision?: string; | ||
readonly draftId?: string; | ||
readonly branch: string; | ||
readonly description: string; | ||
} | ||
export declare class CloudCodeEnvironment implements EventSources { | ||
readonly task: TaskEnvironment; | ||
readonly deployInfo: DeployInfo; | ||
APP: string; | ||
@@ -22,0 +29,0 @@ EDITOR_TEST: string; |
@@ -20,2 +20,19 @@ "use strict"; | ||
this.task = task; | ||
const revision = process.env.CLOUDCODE_REVISION || 'unknown'; | ||
const branch = process.env.CLOUDCODE_BRANCH || 'unknown'; | ||
const draftId = process.env.CLOUDCODE_DRAFT_ID; | ||
if (draftId) { | ||
this.deployInfo = { | ||
draftId: draftId, | ||
branch: branch, | ||
description: `${branch}/draft/${draftId}` | ||
}; | ||
} | ||
else { | ||
this.deployInfo = { | ||
revision: revision, | ||
branch: branch, | ||
description: `${branch}/${revision}` | ||
}; | ||
} | ||
} | ||
@@ -35,3 +52,3 @@ setTaskContext(context) { | ||
createDB(baseUrl, instanceId, auth) { | ||
if (!DatabaseAuth_1.isBasicAuth(auth) && !DatabaseAuth_1.isTokenAuth(auth)) { | ||
if (!(0, DatabaseAuth_1.isBasicAuth)(auth) && !(0, DatabaseAuth_1.isTokenAuth)(auth)) { | ||
if (!this.currentTaskContext || !this.currentTaskContext.token) { | ||
@@ -42,3 +59,3 @@ throw new Error('No authentication specified and no current task session available'); | ||
} | ||
return api_db_1.createDB(baseUrl, instanceId, auth); | ||
return (0, api_db_1.createDB)(baseUrl, instanceId, auth); | ||
} | ||
@@ -55,3 +72,3 @@ /** | ||
createRemoteDB(baseUrl, instanceId, auth) { | ||
if (!DatabaseAuth_1.isBasicAuth(auth) && !DatabaseAuth_1.isTokenAuth(auth)) { | ||
if (!(0, DatabaseAuth_1.isBasicAuth)(auth) && !(0, DatabaseAuth_1.isTokenAuth)(auth)) { | ||
if (!this.currentTaskContext || !this.currentTaskContext.token) { | ||
@@ -62,3 +79,3 @@ throw new Error('No authentication specified and no current task session available'); | ||
} | ||
return api_db_1.createRemoteDB(baseUrl, instanceId, auth); | ||
return (0, api_db_1.createRemoteDB)(baseUrl, instanceId, auth); | ||
} | ||
@@ -115,3 +132,3 @@ /** | ||
logs_1.systemConsole.debug('Enqueue request:', payload); | ||
const response = await node_fetch_1.default(`${SCHEDULER_ENDPOINT}/api/tasks/enqueue`, { | ||
const response = await (0, node_fetch_1.default)(`${SCHEDULER_ENDPOINT}/api/tasks/enqueue`, { | ||
headers: { | ||
@@ -118,0 +135,0 @@ Authorization: `Token ${this.currentTaskContext.token}`, |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Headers } from 'node-fetch'; | ||
@@ -3,0 +4,0 @@ import { URL, URLSearchParams } from 'url'; |
@@ -74,3 +74,3 @@ 'use strict'; | ||
// Some of the details are only populated later. | ||
const taskContext = environment_1.createTaskContext(context, rawRequest.eventSource, traceId, bootstrap_1.config.backendUrl); | ||
const taskContext = (0, environment_1.createTaskContext)(context, rawRequest.eventSource, traceId, bootstrap_1.config.backendUrl); | ||
// Log in process logs | ||
@@ -85,3 +85,3 @@ logs_1.systemConsole.event({ | ||
// Start task logs | ||
logs_1.setLogContext(taskContext); | ||
(0, logs_1.setLogContext)(taskContext); | ||
logs_1.systemConsole.event({ | ||
@@ -91,3 +91,3 @@ event: 'START_REQUEST', | ||
type: rawRequest.eventSource, | ||
message: `Start '${rawRequest.eventSource}' request. Process trace ID: '${bootstrap_1.PROCESS_ID}'` | ||
message: `Start '${rawRequest.eventSource}' request. Process trace ID: '${bootstrap_1.PROCESS_ID}'. Revision: '${global.CloudCode.deployInfo.description}'.` | ||
}); | ||
@@ -202,3 +202,2 @@ // TODO: Remove these non-webby bits | ||
} | ||
Found module: | ||
@@ -242,3 +241,3 @@ ${util.format(task.module)} | ||
}); | ||
busycheck_1.busycheck(); | ||
(0, busycheck_1.busycheck)(); | ||
response.header('X-CloudCode-TraceId', traceId); | ||
@@ -249,3 +248,3 @@ if (debug) { | ||
let result = response.toJSON(); | ||
logs_1.flush(); | ||
(0, logs_1.flush)(); | ||
return result; | ||
@@ -282,7 +281,7 @@ }); | ||
.then(function (result) { | ||
environment_1.stopCurrentMonitor(); | ||
(0, environment_1.stopCurrentMonitor)(); | ||
callback(null, result); | ||
}) | ||
.catch(function (error) { | ||
environment_1.stopCurrentMonitor(); | ||
(0, environment_1.stopCurrentMonitor)(); | ||
logs_1.systemConsole.error('Fatal error:', error); | ||
@@ -302,3 +301,3 @@ callback(error, null); | ||
.then(function (result) { | ||
environment_1.stopCurrentMonitor(); | ||
(0, environment_1.stopCurrentMonitor)(); | ||
if (json) { | ||
@@ -312,3 +311,3 @@ term.log(JSON.stringify(result)); | ||
.catch(function (error) { | ||
environment_1.stopCurrentMonitor(); | ||
(0, environment_1.stopCurrentMonitor)(); | ||
if (json) { | ||
@@ -333,3 +332,3 @@ term.log(JSON.stringify({ | ||
// Lambda | ||
bootstrap_1.bootstrap({ dev: false, taskPath: taskPath }); | ||
(0, bootstrap_1.bootstrap)({ dev: false, taskPath: taskPath }); | ||
task = loadTask(); | ||
@@ -341,3 +340,3 @@ }; | ||
} | ||
bootstrap_1.bootstrap({ dev: true, taskPath: taskPath }); | ||
(0, bootstrap_1.bootstrap)({ dev: true, taskPath: taskPath }); | ||
task = loadTask(); | ||
@@ -367,3 +366,3 @@ let events = process.argv.splice(2).map((arg) => JSON.parse(arg)); | ||
} | ||
logs_1.flush(); | ||
(0, logs_1.flush)(); | ||
// Ignore outstanding events and exit (CLI only!). | ||
@@ -370,0 +369,0 @@ // We give some time for flush() to take effect. |
@@ -15,3 +15,2 @@ import { TaskContextBackend } from './TaskContextBackend'; | ||
private startTime; | ||
token: string; | ||
backend: TaskContextBackend; | ||
@@ -29,2 +28,3 @@ monitor: TaskMonitor; | ||
setToken(token: string): void; | ||
get token(): any; | ||
setBackend(opts: { | ||
@@ -31,0 +31,0 @@ baseUrl?: string; |
@@ -14,2 +14,3 @@ 'use strict'; | ||
const _backendUrl = Symbol(); | ||
const _token = Symbol(); | ||
class InternalTaskContext { | ||
@@ -24,3 +25,3 @@ constructor(opts) { | ||
this[_backendUrl] = opts.backendUrl; | ||
this.token = null; | ||
this[_token] = null; | ||
this.backend = new TaskContextBackend_1.TaskContextBackend(this[_backendUrl]); | ||
@@ -36,4 +37,9 @@ this.userContext = new TaskContext_1.TaskContext(this); | ||
setToken(token) { | ||
this.token = token; | ||
this[_token] = token; | ||
} | ||
get token() { | ||
// By having a non-enumerable getter instead of a direct writable property, we avoid broken versions of Rollbar | ||
// attempting to replace the token with '********'. | ||
return this[_token]; | ||
} | ||
setBackend(opts) { | ||
@@ -63,3 +69,3 @@ assert(this.token, 'No token set'); | ||
hydrateObject(obj) { | ||
return api_db_1.hydrateObject(this.backend.DB, obj); | ||
return (0, api_db_1.hydrateObject)(this.backend.DB, obj); | ||
} | ||
@@ -66,0 +72,0 @@ } |
@@ -49,3 +49,3 @@ 'use strict'; | ||
} | ||
let response = await node_fetch_1.default(`${SCHEDULER_ENDPOINT}/api/logs/stream/${traceId}`, { | ||
let response = await (0, node_fetch_1.default)(`${SCHEDULER_ENDPOINT}/api/logs/stream/${traceId}`, { | ||
method: 'POST', | ||
@@ -52,0 +52,0 @@ body: JSON.stringify(logs), |
@@ -14,5 +14,5 @@ "use strict"; | ||
const datePart = new Date().toISOString().replace(/(?:\d{3}Z$)|(?:[^\d])/g, ''); // drop millis and non-digits | ||
return prefix + datePart + bs58_1.encode(crypto.randomBytes(16)); | ||
return prefix + datePart + (0, bs58_1.encode)(crypto.randomBytes(16)); | ||
} | ||
exports.generateId = generateId; | ||
//# sourceMappingURL=naming.js.map |
@@ -70,3 +70,3 @@ "use strict"; | ||
if (!this[_DB] && this.available) { | ||
this[_DB] = api_db_1.createDB(this[_baseUrl], this[_instance], { | ||
this[_DB] = (0, api_db_1.createDB)(this[_baseUrl], this[_instance], { | ||
token: this[_token] | ||
@@ -73,0 +73,0 @@ }); |
{ | ||
"name": "@journeyapps/cloudcode", | ||
"version": "0.0.0-dev.7efd186", | ||
"version": "0.0.0-dev.800dc27", | ||
"main": "./dist/index", | ||
"types": "./dist/index", | ||
"license": "MIT", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./entry": "./dist/entry.js", | ||
"./*": "./*" | ||
}, | ||
"files": [ | ||
@@ -8,0 +13,0 @@ "README.md", |
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
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances 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
159429
2779
12