@reboot-dev/reboot 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +94 -19
- package/index.js +306 -42
- package/package.json +7 -4
- package/rbt.js +5 -2
- package/reboot_native.cc +1207 -1383
- package/reboot_native.cjs +3 -1
- package/reboot_native.d.ts +12 -3
- package/secrets/index.d.ts +37 -0
- package/secrets/index.js +96 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/reboot_native.cjs
CHANGED
|
@@ -52,7 +52,7 @@ process.dlopen(
|
|
|
52
52
|
exports.python3Path = reboot_native.exports.python3Path;
|
|
53
53
|
exports.Service_constructor = reboot_native.exports.Service_constructor;
|
|
54
54
|
exports.Service_call = reboot_native.exports.Service_call;
|
|
55
|
-
exports.
|
|
55
|
+
exports.Task_await = reboot_native.exports.Task_await;
|
|
56
56
|
exports.ExternalContext_constructor =
|
|
57
57
|
reboot_native.exports.ExternalContext_constructor;
|
|
58
58
|
exports.Application_constructor = reboot_native.exports.Application_constructor;
|
|
@@ -67,6 +67,8 @@ exports.Reboot_down = reboot_native.exports.Reboot_down;
|
|
|
67
67
|
exports.Reboot_url = reboot_native.exports.Reboot_url;
|
|
68
68
|
exports.Context_auth = reboot_native.exports.Context_auth;
|
|
69
69
|
exports.Context_stateId = reboot_native.exports.Context_stateId;
|
|
70
|
+
exports.Context_cookie = reboot_native.exports.Context_cookie;
|
|
71
|
+
exports.Context_appInternal = reboot_native.exports.Context_appInternal;
|
|
70
72
|
exports.Context_iteration = reboot_native.exports.Context_iteration;
|
|
71
73
|
exports.Context_generateIdempotentStateId =
|
|
72
74
|
reboot_native.exports.Context_generateIdempotentStateId;
|
package/reboot_native.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// NOTE NOTE NOTE NOTE NOTE
|
|
2
|
+
//
|
|
3
|
+
// This file seems wildly out of date and inaccurate. It is not clear
|
|
4
|
+
// that it is being used by type checkers and we should either get rid
|
|
5
|
+
// of it or bring it up to date.
|
|
6
|
+
|
|
1
7
|
import { IdempotencyOptions } from "@reboot-dev/reboot-api";
|
|
2
8
|
|
|
3
9
|
import {
|
|
@@ -31,9 +37,10 @@ interface Service_callProps {
|
|
|
31
37
|
jsonRequest: string;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
interface
|
|
35
|
-
external: NapiExternal;
|
|
40
|
+
interface Task_awaitProps {
|
|
36
41
|
context: Context | ExternalContext;
|
|
42
|
+
rbtModule: string;
|
|
43
|
+
stateName: string;
|
|
37
44
|
method: string;
|
|
38
45
|
jsonTaskId: string;
|
|
39
46
|
}
|
|
@@ -41,7 +48,7 @@ interface Future_awaitProps {
|
|
|
41
48
|
export namespace rbt_native {
|
|
42
49
|
function Service_constructor(props: Service_constructorProps): NapiExternal;
|
|
43
50
|
function Service_call(props: Service_callProps): string;
|
|
44
|
-
function
|
|
51
|
+
function Task_await(props: Task_awaitProps): string;
|
|
45
52
|
function ExternalContext_constructor(
|
|
46
53
|
name: string,
|
|
47
54
|
url: string,
|
|
@@ -68,6 +75,8 @@ export namespace rbt_native {
|
|
|
68
75
|
function Reboot_down(external: NapiExternal): void;
|
|
69
76
|
function Context_stateId(external: NapiExternal): string;
|
|
70
77
|
function Context_iteration(external: NapiExternal): number;
|
|
78
|
+
function Context_cookie(external: NapiExternal): string;
|
|
79
|
+
function Context_appInternal(external: NapiExternal): boolean;
|
|
71
80
|
function Context_generateIdempotentStateId(
|
|
72
81
|
external: NapiExternal,
|
|
73
82
|
state_type: string,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const ENVVAR_RBT_SECRETS_DIRECTORY = "RBT_SECRETS_DIRECTORY";
|
|
2
|
+
declare abstract class SecretSource {
|
|
3
|
+
abstract get(secretName: string): Promise<Buffer>;
|
|
4
|
+
}
|
|
5
|
+
export declare class Secrets {
|
|
6
|
+
private static _staticSecretSource;
|
|
7
|
+
private _secretCache;
|
|
8
|
+
private _secretSource;
|
|
9
|
+
constructor();
|
|
10
|
+
static setSecretSource(secretSource: SecretSource | null): void;
|
|
11
|
+
get secretSource(): SecretSource;
|
|
12
|
+
get(secretName: string, { ttlSecs }?: {
|
|
13
|
+
ttlSecs?: number;
|
|
14
|
+
}): Promise<Buffer>;
|
|
15
|
+
}
|
|
16
|
+
export declare class SecretNotFoundException extends Error {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class DirectorySecretSource extends SecretSource {
|
|
20
|
+
directory: string;
|
|
21
|
+
constructor(directory: string);
|
|
22
|
+
get(secretName: string): Promise<Buffer>;
|
|
23
|
+
}
|
|
24
|
+
export declare class EnvironmentSecretSource extends SecretSource {
|
|
25
|
+
ENVIRONMENT_VARIABLE_PREFIX: string;
|
|
26
|
+
get(secretName: string): Promise<Buffer>;
|
|
27
|
+
}
|
|
28
|
+
export declare class MockSecretSource extends SecretSource {
|
|
29
|
+
secrets: {
|
|
30
|
+
[key: string]: Buffer;
|
|
31
|
+
};
|
|
32
|
+
constructor(secrets: {
|
|
33
|
+
[key: string]: Buffer;
|
|
34
|
+
});
|
|
35
|
+
get(secretName: string): Promise<Buffer>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
package/secrets/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
export const ENVVAR_RBT_SECRETS_DIRECTORY = "RBT_SECRETS_DIRECTORY";
|
|
4
|
+
class SecretSource {
|
|
5
|
+
}
|
|
6
|
+
export class Secrets {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._secretCache = {};
|
|
9
|
+
if (Secrets._staticSecretSource) {
|
|
10
|
+
this._secretSource = Secrets._staticSecretSource;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const secretsDirectory = process.env[ENVVAR_RBT_SECRETS_DIRECTORY];
|
|
14
|
+
if (secretsDirectory) {
|
|
15
|
+
this._secretSource = new DirectorySecretSource(path.resolve(secretsDirectory));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this._secretSource = new EnvironmentSecretSource();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
static setSecretSource(secretSource) {
|
|
22
|
+
Secrets._staticSecretSource = secretSource;
|
|
23
|
+
}
|
|
24
|
+
get secretSource() {
|
|
25
|
+
return this._secretSource;
|
|
26
|
+
}
|
|
27
|
+
async get(secretName, { ttlSecs = 15.0 } = {}) {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
const cachedSecret = this._secretCache[secretName];
|
|
30
|
+
if (cachedSecret && cachedSecret.cachedAt + ttlSecs > now) {
|
|
31
|
+
return cachedSecret.value;
|
|
32
|
+
}
|
|
33
|
+
const value = await this._secretSource.get(secretName);
|
|
34
|
+
this._secretCache[secretName] = new _CachedSecret(value, now);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
Secrets._staticSecretSource = null;
|
|
39
|
+
export class SecretNotFoundException extends Error {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = "SecretNotFoundException";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class DirectorySecretSource extends SecretSource {
|
|
46
|
+
constructor(directory) {
|
|
47
|
+
super();
|
|
48
|
+
this.directory = directory;
|
|
49
|
+
}
|
|
50
|
+
async get(secretName) {
|
|
51
|
+
const secretPath = path.join(this.directory, secretName);
|
|
52
|
+
try {
|
|
53
|
+
return await fs.readFile(secretPath);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === "ENOENT") {
|
|
57
|
+
throw new SecretNotFoundException(`No secret is stored for secretName=${secretName} (at \`${secretPath}\`).`);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export class EnvironmentSecretSource extends SecretSource {
|
|
64
|
+
constructor() {
|
|
65
|
+
super(...arguments);
|
|
66
|
+
this.ENVIRONMENT_VARIABLE_PREFIX = "RBT_SECRET_";
|
|
67
|
+
}
|
|
68
|
+
async get(secretName) {
|
|
69
|
+
const environmentVariableName = `${this.ENVIRONMENT_VARIABLE_PREFIX}${secretName.toUpperCase().replace(/-/g, "_")}`;
|
|
70
|
+
const value = process.env[environmentVariableName];
|
|
71
|
+
if (value === undefined) {
|
|
72
|
+
throw new SecretNotFoundException(`No environment variable was set for secretName=${secretName}; ` +
|
|
73
|
+
`expected \`${environmentVariableName}\` to be set`);
|
|
74
|
+
}
|
|
75
|
+
return Buffer.from(value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export class MockSecretSource extends SecretSource {
|
|
79
|
+
constructor(secrets) {
|
|
80
|
+
super();
|
|
81
|
+
this.secrets = secrets;
|
|
82
|
+
}
|
|
83
|
+
async get(secretName) {
|
|
84
|
+
const value = this.secrets[secretName];
|
|
85
|
+
if (value === undefined) {
|
|
86
|
+
throw new SecretNotFoundException(`No mock secret was stored for secretName=${secretName}.`);
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class _CachedSecret {
|
|
92
|
+
constructor(value, cachedAt) {
|
|
93
|
+
this.value = value;
|
|
94
|
+
this.cachedAt = cachedAt;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const REBOOT_VERSION = "0.
|
|
1
|
+
export declare const REBOOT_VERSION = "0.25.0";
|
package/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const REBOOT_VERSION = "0.
|
|
1
|
+
export const REBOOT_VERSION = "0.25.0";
|