@journeyapps/cloudcode
Advanced tools
Comparing version 0.0.1-dev6 to 1.9.0
@@ -10,3 +10,3 @@ interface ScheduleTaskOptions { | ||
import { DatabaseAuth } from './DatabaseAuth'; | ||
import { TaskContext } from './TaskContext'; | ||
import { InternalTaskContext } from './InternalTaskContext'; | ||
export interface TaskEnvironment { | ||
@@ -28,3 +28,3 @@ readonly name: string; | ||
constructor(task: TaskEnvironment); | ||
setTaskContext(context: TaskContext): void; | ||
setTaskContext(context: InternalTaskContext): void; | ||
/** | ||
@@ -31,0 +31,0 @@ * Create a DB pointing the a different backend. |
@@ -23,2 +23,10 @@ /// <reference types="node" /> | ||
} | ||
export interface CloudCodeRequestOptions { | ||
method: string; | ||
url: string | URL; | ||
headers: Headers; | ||
body?: string; | ||
buffer?: Buffer; | ||
ip?: string; | ||
} | ||
export declare class CloudCodeRequest { | ||
@@ -33,10 +41,3 @@ readonly method: string; | ||
static fromRawRequest(rawRequest: RawRequest): CloudCodeRequest; | ||
constructor(opts: { | ||
method: string; | ||
url: string | URL; | ||
headers: Headers; | ||
body?: string; | ||
buffer?: Buffer; | ||
ip?: string; | ||
}); | ||
constructor(opts: CloudCodeRequestOptions); | ||
readonly subdomain: string; | ||
@@ -43,0 +44,0 @@ readonly hostname: string; |
@@ -1,4 +0,4 @@ | ||
import { TaskContext } from './TaskContext'; | ||
import { InternalTaskContext } from './InternalTaskContext'; | ||
export declare function setup(appId: string, env: string, name: string): void; | ||
export declare function createTaskContext(lambdaContext: any, source: string, traceId: string, backendUrl: string): TaskContext; | ||
export declare function createTaskContext(lambdaContext: any, source: string, traceId: string, backendUrl: string): InternalTaskContext; | ||
export declare function stopCurrentMonitor(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const CloudCodeEnvironment_1 = require("./CloudCodeEnvironment"); | ||
const TaskContext_1 = require("./TaskContext"); | ||
const InternalTaskContext_1 = require("./InternalTaskContext"); | ||
const Day_1 = require("journeyapps/lib/db/Day"); | ||
@@ -34,3 +34,3 @@ const node_fetch_1 = require("node-fetch"); | ||
stopCurrentMonitor(); | ||
currentTaskContext = new TaskContext_1.TaskContext({ | ||
currentTaskContext = new InternalTaskContext_1.InternalTaskContext({ | ||
appId: cloudcode.task.appId, | ||
@@ -37,0 +37,0 @@ env: cloudcode.task.env, |
import { CloudCodeRequest } from './CloudCodeRequest'; | ||
import { CloudCodeResponse } from './CloudCodeResponse'; | ||
import { InternalTaskContext } from './InternalTaskContext'; | ||
import { TaskContext } from './TaskContext'; | ||
export declare enum IdpTaskType { | ||
@@ -38,4 +40,4 @@ auth = 0, | ||
} | ||
declare type ExtractIdentityFunction = (context: ExtractIdentityParams) => Promise<CloudCodeResponse>; | ||
declare type ProcessClaimsFunction = (context: ProcessClaimsParams) => Promise<CloudCodeResponse>; | ||
declare type ExtractIdentityFunction = (this: TaskContext, context: ExtractIdentityParams) => Promise<CloudCodeResponse>; | ||
declare type ProcessClaimsFunction = (this: TaskContext, context: ProcessClaimsParams) => Promise<CloudCodeResponse>; | ||
declare type WorkerFunction = ExtractIdentityFunction | ProcessClaimsFunction; | ||
@@ -77,4 +79,4 @@ export declare class IdpContext { | ||
protected constructor(taskType: IdpTaskType, workerFunction: WorkerFunction); | ||
handleRequest(taskContext: any, request: CloudCodeRequest): Promise<CloudCodeResponse>; | ||
handleRequest(taskContext: InternalTaskContext, request: CloudCodeRequest): Promise<CloudCodeResponse>; | ||
} | ||
export {}; |
import './global'; | ||
export { UserTaskContext } from './UserTaskContext'; | ||
export { TaskContext } from './TaskContext'; | ||
export { CloudCode }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./global"); | ||
var UserTaskContext_1 = require("./UserTaskContext"); | ||
exports.UserTaskContext = UserTaskContext_1.UserTaskContext; | ||
var TaskContext_1 = require("./TaskContext"); | ||
exports.TaskContext = TaskContext_1.TaskContext; | ||
//# sourceMappingURL=index.js.map |
import { CloudCodeRequest } from './CloudCodeRequest'; | ||
import { CloudCodeResponse } from './CloudCodeResponse'; | ||
import { AccessControl } from './AuthResponse'; | ||
import { InternalTaskContext } from './InternalTaskContext'; | ||
import { TaskContext } from './TaskContext'; | ||
declare type Parameters = { | ||
@@ -24,4 +26,4 @@ [key: string]: any; | ||
} | ||
declare type RequestFunction = (context: RequestContext) => Promise<any>; | ||
declare type AuthenticationFunction = (context: AuthenticationContext) => Promise<any>; | ||
declare type RequestFunction = (this: TaskContext, context: RequestContext) => Promise<any>; | ||
declare type AuthenticationFunction = (this: TaskContext, context: AuthenticationContext) => Promise<any>; | ||
export declare class Router { | ||
@@ -39,5 +41,5 @@ static forModule(taskModule: any): Router; | ||
options(path: string, handler: RequestFunction): void; | ||
handleRequest(taskContext: any, request: CloudCodeRequest): Promise<CloudCodeResponse>; | ||
handleRequest(taskContext: InternalTaskContext, request: CloudCodeRequest): Promise<CloudCodeResponse>; | ||
isMethodAllowed(method: string): boolean; | ||
} | ||
export {}; |
@@ -1,37 +0,25 @@ | ||
import { TaskContextBackend } from './TaskContextBackend'; | ||
import { TaskMonitor } from './TaskMonitor'; | ||
import { UserTaskContext } from './UserTaskContext'; | ||
interface TaskContextOptions { | ||
appId: string; | ||
env: string; | ||
name: string; | ||
lambdaContext: any; | ||
traceId: string; | ||
source: string; | ||
backendUrl: string; | ||
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { InternalTaskContext } from './InternalTaskContext'; | ||
export declare class TaskContext extends EventEmitter { | ||
private context; | ||
readonly appId: string; | ||
readonly env: string; | ||
readonly name: string; | ||
readonly traceId: string; | ||
readonly source: string; | ||
constructor(context: InternalTaskContext); | ||
readonly userId: string; | ||
readonly backend: import("./TaskContextBackend").TaskContextBackend; | ||
readonly DB: import("journeyapps/lib/db/database").Database; | ||
toJSON(): { | ||
appId: string; | ||
env: string; | ||
name: string; | ||
traceId: string; | ||
source: string; | ||
backend: import("./TaskContextBackend").TaskContextBackend; | ||
userId: string; | ||
DB: string; | ||
}; | ||
} | ||
export declare class TaskContext { | ||
private startTime; | ||
token: string; | ||
backend: TaskContextBackend; | ||
monitor: TaskMonitor; | ||
userId?: string; | ||
userContext: UserTaskContext; | ||
appId: string; | ||
env: string; | ||
name: string; | ||
lambdaContext: any; | ||
traceId: string; | ||
source: string; | ||
constructor(opts: TaskContextOptions); | ||
setToken(token: any): void; | ||
setBackend(opts: any): void; | ||
/** | ||
* @param {string} userId | ||
*/ | ||
setUserId(userId: any): void; | ||
getRemainingTime(): any; | ||
stopMonitor(): void; | ||
hydrateObject(obj: any): any; | ||
} | ||
export {}; |
@@ -1,65 +0,37 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const TaskContextBackend_1 = require("./TaskContextBackend"); | ||
const TaskMonitor_1 = require("./TaskMonitor"); | ||
const assert = require("assert"); | ||
const event_sources_1 = require("./event_sources"); | ||
const api_db_1 = require("./api_db"); | ||
const UserTaskContext_1 = require("./UserTaskContext"); | ||
// Custom time limit for HTTP tasks, slightly less than Api Gateway's 30 seconds. | ||
// Currently only informational - logs a warning, but is not enforced here. | ||
const HTTP_TIME_LIMIT = 27000; | ||
const _backendUrl = Symbol(); | ||
class TaskContext { | ||
constructor(opts) { | ||
this.startTime = Date.now(); | ||
for (let k of ['appId', 'env', 'name', 'lambdaContext', 'traceId', 'source']) { | ||
assert(opts[k], `Option '${k}' is required`); | ||
this[k] = opts[k]; | ||
} | ||
assert(opts['backendUrl'], "Option 'backendUrl' is required"); | ||
this[_backendUrl] = opts.backendUrl; | ||
this.token = null; | ||
this.backend = new TaskContextBackend_1.TaskContextBackend(this[_backendUrl]); | ||
this.userContext = new UserTaskContext_1.UserTaskContext(this); | ||
this.monitor = new TaskMonitor_1.TaskMonitor({ | ||
memoryLimit: this.lambdaContext.memoryLimitInMB * 1024 * 1024, | ||
remainingTimeFn: () => this.getRemainingTime(), | ||
emitter: this.userContext | ||
}); | ||
this.userId = null; | ||
const events_1 = require("events"); | ||
class TaskContext extends events_1.EventEmitter { | ||
constructor(context) { | ||
super(); | ||
this.context = context; | ||
this.appId = context.appId; | ||
this.env = context.env; | ||
this.name = context.name; | ||
this.traceId = context.traceId; | ||
this.source = context.source; | ||
} | ||
setToken(token) { | ||
this.token = token; | ||
get userId() { | ||
return this.context.userId; | ||
} | ||
setBackend(opts) { | ||
assert(this.token, 'No token set'); | ||
opts = Object.assign({ | ||
baseUrl: this[_backendUrl], | ||
instance: null | ||
}, opts); | ||
this.backend = new TaskContextBackend_1.TaskContextBackend(opts.baseUrl, opts.instance, this.token); | ||
get backend() { | ||
return this.context.backend; | ||
} | ||
/** | ||
* @param {string} userId | ||
*/ | ||
setUserId(userId) { | ||
this.userId = userId; | ||
get DB() { | ||
return this.backend.DB; | ||
} | ||
getRemainingTime() { | ||
if (this.source == event_sources_1.WEB) { | ||
return HTTP_TIME_LIMIT - (Date.now() - this.startTime); | ||
} | ||
return this.lambdaContext.getRemainingTimeInMillis(); | ||
toJSON() { | ||
return { | ||
appId: this.appId, | ||
env: this.env, | ||
name: this.name, | ||
traceId: this.traceId, | ||
source: this.source, | ||
backend: this.backend, | ||
userId: this.userId, | ||
DB: '[DB]' | ||
}; | ||
} | ||
stopMonitor() { | ||
if (this.monitor.running) { | ||
this.monitor.stop(); | ||
} | ||
} | ||
hydrateObject(obj) { | ||
return api_db_1.hydrateObject(this.backend.DB, obj); | ||
} | ||
} | ||
exports.TaskContext = TaskContext; | ||
//# sourceMappingURL=TaskContext.js.map |
{ | ||
"name": "@journeyapps/cloudcode", | ||
"version": "0.0.1-dev6", | ||
"version": "1.9.0", | ||
"main": "./lib/index.js", | ||
@@ -29,3 +29,4 @@ "types": "./lib/index.d.ts", | ||
"lib" | ||
] | ||
], | ||
"gitHead": "a725c7495929f89b9c115d3890a46214faba1875" | ||
} |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
149069
2622
1