@journeyapps/cloudcode
Advanced tools
Comparing version 0.0.0-dev.90cac46 to 0.0.0-dev.9117f43
@@ -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}. Revision: ${global.CloudCode.deployInfo.description}.` | ||
message: `Start process. Process trace ID: ${exports.PROCESS_ID}. Revision: ${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. |
@@ -6,3 +6,2 @@ "use strict"; | ||
const event_sources_1 = require("./event_sources"); | ||
const node_fetch_1 = require("node-fetch"); | ||
const DatabaseAuth_1 = require("./DatabaseAuth"); | ||
@@ -52,3 +51,3 @@ const api_db_1 = require("./api_db"); | ||
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) { | ||
@@ -59,3 +58,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); | ||
} | ||
@@ -72,3 +71,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) { | ||
@@ -79,3 +78,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); | ||
} | ||
@@ -132,3 +131,3 @@ /** | ||
logs_1.systemConsole.debug('Enqueue request:', payload); | ||
const response = await node_fetch_1.default(`${SCHEDULER_ENDPOINT}/api/tasks/enqueue`, { | ||
const response = await fetch(`${SCHEDULER_ENDPOINT}/api/tasks/enqueue`, { | ||
headers: { | ||
@@ -148,4 +147,4 @@ Authorization: `Token ${this.currentTaskContext.token}`, | ||
logs_1.systemConsole.debug('Enqueue response:', result); | ||
logs_1.systemConsole.info(`Enqueued '${options.task}' with trace ID '${result.trace_id}'.`); | ||
return result.trace_id; | ||
logs_1.systemConsole.info(`Enqueued '${options.task}' with trace ID '${result['trace_id']}'.`); | ||
return result['trace_id']; | ||
} | ||
@@ -152,0 +151,0 @@ } |
/// <reference types="node" /> | ||
import { Headers } from 'node-fetch'; | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { URL, URLSearchParams } from 'url'; | ||
@@ -4,0 +6,0 @@ /** |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CloudCodeRequest = void 0; | ||
const node_fetch_1 = require("node-fetch"); | ||
const url_1 = require("url"); | ||
@@ -48,3 +47,3 @@ /** | ||
url: rawRequest.url, | ||
headers: new node_fetch_1.Headers(rawRequest.headers), | ||
headers: new Headers(rawRequest.headers), | ||
body: rawRequest.body, | ||
@@ -51,0 +50,0 @@ ip: rawRequest.sourceIp |
/// <reference types="node" /> | ||
import { Headers } from 'node-fetch'; | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
export declare class CloudCodeResponse { | ||
@@ -4,0 +5,0 @@ readonly headers: Headers; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CloudCodeResponse = void 0; | ||
const node_fetch_1 = require("node-fetch"); | ||
const http_1 = require("http"); | ||
@@ -9,3 +8,3 @@ const DEBUG_MODE = process.env.DEBUG === '1'; // Currently used for tests only | ||
constructor() { | ||
this.headers = new node_fetch_1.Headers(); | ||
this.headers = new Headers(); | ||
} | ||
@@ -12,0 +11,0 @@ static notFound() { |
@@ -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}'. Revision: '${global.CloudCode.deployInfo.description}'.` | ||
message: `Start '${rawRequest.eventSource}' request. Process trace ID: '${bootstrap_1.PROCESS_ID}'. Revision: '${CloudCode.deployInfo.description}'.` | ||
}); | ||
@@ -181,4 +181,3 @@ // TODO: Remove these non-webby bits | ||
} | ||
const response = await router.handleRequest(taskContext, request); | ||
return response; | ||
return await router.handleRequest(taskContext, request); | ||
} | ||
@@ -241,3 +240,3 @@ else if (taskContext.source == event_sources_1.default.IDP) { | ||
}); | ||
busycheck_1.busycheck(); | ||
(0, busycheck_1.busycheck)(); | ||
response.header('X-CloudCode-TraceId', traceId); | ||
@@ -248,3 +247,3 @@ if (debug) { | ||
let result = response.toJSON(); | ||
logs_1.flush(); | ||
(0, logs_1.flush)(); | ||
return result; | ||
@@ -281,7 +280,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); | ||
@@ -301,3 +300,3 @@ callback(error, null); | ||
.then(function (result) { | ||
environment_1.stopCurrentMonitor(); | ||
(0, environment_1.stopCurrentMonitor)(); | ||
if (json) { | ||
@@ -311,3 +310,3 @@ term.log(JSON.stringify(result)); | ||
.catch(function (error) { | ||
environment_1.stopCurrentMonitor(); | ||
(0, environment_1.stopCurrentMonitor)(); | ||
if (json) { | ||
@@ -332,3 +331,3 @@ term.log(JSON.stringify({ | ||
// Lambda | ||
bootstrap_1.bootstrap({ dev: false, taskPath: taskPath }); | ||
(0, bootstrap_1.bootstrap)({ dev: false, taskPath: taskPath }); | ||
task = loadTask(); | ||
@@ -340,3 +339,3 @@ }; | ||
} | ||
bootstrap_1.bootstrap({ dev: true, taskPath: taskPath }); | ||
(0, bootstrap_1.bootstrap)({ dev: true, taskPath: taskPath }); | ||
task = loadTask(); | ||
@@ -366,3 +365,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!). | ||
@@ -369,0 +368,0 @@ // We give some time for flush() to take effect. |
@@ -7,3 +7,2 @@ "use strict"; | ||
const db_1 = require("@journeyapps/db"); | ||
const node_fetch_1 = require("node-fetch"); | ||
const assert = require("assert"); | ||
@@ -19,5 +18,7 @@ const httpLib = require("http"); | ||
indexModule.setCloudCode(cloudcode); | ||
// @ts-ignore | ||
global.CloudCode = cloudcode; | ||
// @ts-ignore | ||
global.Day = db_1.Day; | ||
global.fetch = node_fetch_1.default; | ||
// @ts-ignore | ||
global.Attachment = db_1.Attachment; | ||
@@ -24,0 +25,0 @@ Object.defineProperty(global, 'DB', { |
import { CloudCodeEnvironment } from './CloudCodeEnvironment'; | ||
import { Day as DayConstructor, Attachment as AttachmentConstructor } from '@journeyapps/db'; | ||
import fetchModule from 'node-fetch'; | ||
declare global { | ||
namespace NodeJS { | ||
interface Global { | ||
CloudCode: CloudCodeEnvironment; | ||
Day: typeof DayConstructor; | ||
fetch: typeof fetchModule; | ||
Attachment: typeof AttachmentConstructor; | ||
} | ||
} | ||
const CloudCode: CloudCodeEnvironment; | ||
const Day: typeof DayConstructor; | ||
const fetch: typeof fetchModule; | ||
const Attachment: typeof AttachmentConstructor; | ||
@@ -17,0 +7,0 @@ type Day = DayConstructor; |
@@ -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 @@ } |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.flush = exports.setLogContext = exports.createLoggers = exports.systemConsole = exports.systemStream = void 0; | ||
/* | ||
* | ||
*/ | ||
const highland = require("highland"); | ||
@@ -49,3 +46,3 @@ const node_fetch_1 = require("node-fetch"); | ||
} | ||
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 +49,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.90cac46", | ||
"version": "0.0.0-dev.9117f43", | ||
"main": "./dist/index", | ||
@@ -18,3 +18,3 @@ "types": "./dist/index", | ||
"@journeyapps/db": "^6.0.1", | ||
"@types/node": "^10.14.14", | ||
"@types/node": "^20.17.6", | ||
"base64url": "^3.0.1", | ||
@@ -24,5 +24,5 @@ "bs58": "^4.0.1", | ||
"highland": "^2.13.5", | ||
"lodash": "^4.17.15", | ||
"lodash": "^4.17.21", | ||
"node-fetch": "^2.6.0", | ||
"source-map-support": "^0.5.13" | ||
"source-map-support": "^0.5.21" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
158772
2765
9
+ Added@types/node@20.17.17(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removed@types/node@10.17.60(transitive)
Updated@types/node@^20.17.6
Updatedlodash@^4.17.21
Updatedsource-map-support@^0.5.21