@basis-theory-labs/cli 2.0.0 → 2.1.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/README.md +170 -36
- package/dist/base.js +22 -1
- package/dist/commands/proxies/create.d.ts +17 -1
- package/dist/commands/proxies/create.js +84 -8
- package/dist/commands/proxies/update.d.ts +17 -1
- package/dist/commands/proxies/update.js +66 -6
- package/dist/commands/reactors/create.d.ts +11 -1
- package/dist/commands/reactors/create.js +70 -8
- package/dist/commands/reactors/update.d.ts +11 -1
- package/dist/commands/reactors/update.js +45 -5
- package/dist/proxies/management.d.ts +2 -1
- package/dist/proxies/management.js +9 -3
- package/dist/proxies/runtime.d.ts +5 -0
- package/dist/proxies/runtime.js +66 -0
- package/dist/proxies/utils.d.ts +23 -2
- package/dist/proxies/utils.js +78 -7
- package/dist/reactors/management.d.ts +2 -1
- package/dist/reactors/management.js +9 -3
- package/dist/reactors/runtime.d.ts +3 -0
- package/dist/reactors/runtime.js +27 -0
- package/dist/reactors/utils.d.ts +13 -2
- package/dist/reactors/utils.js +4 -1
- package/dist/runtime/flags.d.ts +10 -0
- package/dist/runtime/flags.js +37 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +20 -0
- package/dist/runtime/state.d.ts +6 -0
- package/dist/runtime/state.js +86 -0
- package/dist/runtime/utils.d.ts +34 -0
- package/dist/runtime/utils.js +132 -0
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +41 -1
- package/oclif.manifest.json +351 -10
- package/package.json +2 -2
|
@@ -5,11 +5,31 @@ const base_1 = require("../../base");
|
|
|
5
5
|
const files_1 = require("../../files");
|
|
6
6
|
const logs_1 = require("../../logs");
|
|
7
7
|
const management_1 = require("../../proxies/management");
|
|
8
|
+
const runtime_1 = require("../../proxies/runtime");
|
|
8
9
|
const utils_1 = require("../../proxies/utils");
|
|
10
|
+
const runtime_2 = require("../../runtime");
|
|
9
11
|
class Update extends base_1.BaseCommand {
|
|
10
12
|
async run() {
|
|
11
13
|
var _a, _b;
|
|
12
|
-
const { bt, args: { id }, flags
|
|
14
|
+
const { bt, args: { id }, flags, metadata, } = await this.parse(Update);
|
|
15
|
+
const { name, 'destination-url': destinationUrl, 'response-transform-code': responseTransformCode, 'request-transform-code': requestTransformCode, 'application-id': applicationId, configuration, 'require-auth': requireAuth, 'request-transform-image': requestTransformImage, 'request-transform-dependencies': requestTransformDependencies, 'request-transform-timeout': requestTransformTimeout, 'request-transform-warm-concurrency': requestTransformWarmConcurrency, 'request-transform-resources': requestTransformResources, 'request-transform-permissions': requestTransformPermissions, 'response-transform-image': responseTransformImage, 'response-transform-dependencies': responseTransformDependencies, 'response-transform-timeout': responseTransformTimeout, 'response-transform-warm-concurrency': responseTransformWarmConcurrency, 'response-transform-resources': responseTransformResources, 'response-transform-permissions': responseTransformPermissions, async: asyncFlag, watch, logs, } = flags;
|
|
16
|
+
(0, runtime_1.validateProxyApplicationId)(applicationId, flags);
|
|
17
|
+
const requestTransformRuntime = (0, runtime_2.buildRuntime)({
|
|
18
|
+
image: requestTransformImage,
|
|
19
|
+
dependencies: requestTransformDependencies,
|
|
20
|
+
timeout: requestTransformTimeout,
|
|
21
|
+
warmConcurrency: requestTransformWarmConcurrency,
|
|
22
|
+
resources: requestTransformResources,
|
|
23
|
+
permissions: requestTransformPermissions,
|
|
24
|
+
});
|
|
25
|
+
const responseTransformRuntime = (0, runtime_2.buildRuntime)({
|
|
26
|
+
image: responseTransformImage,
|
|
27
|
+
dependencies: responseTransformDependencies,
|
|
28
|
+
timeout: responseTransformTimeout,
|
|
29
|
+
warmConcurrency: responseTransformWarmConcurrency,
|
|
30
|
+
resources: responseTransformResources,
|
|
31
|
+
permissions: responseTransformPermissions,
|
|
32
|
+
});
|
|
13
33
|
const model = (0, utils_1.createModelFromFlags)({
|
|
14
34
|
name,
|
|
15
35
|
destinationUrl: destinationUrl === null || destinationUrl === void 0 ? void 0 : destinationUrl.toString(),
|
|
@@ -20,13 +40,23 @@ class Update extends base_1.BaseCommand {
|
|
|
20
40
|
requireAuth: ((_b = (_a = metadata.flags) === null || _a === void 0 ? void 0 : _a['require-auth']) === null || _b === void 0 ? void 0 : _b.setFromDefault)
|
|
21
41
|
? undefined
|
|
22
42
|
: requireAuth,
|
|
43
|
+
requestTransformRuntime,
|
|
44
|
+
responseTransformRuntime,
|
|
23
45
|
});
|
|
24
46
|
await (0, management_1.patchProxy)(bt, id, model);
|
|
47
|
+
const proxy = await (0, management_1.getProxy)(bt, id);
|
|
48
|
+
const isConfigurableRuntime = (0, runtime_2.needsPolling)(proxy.state);
|
|
49
|
+
if (!asyncFlag) {
|
|
50
|
+
await (0, runtime_2.waitForResourceState)(bt, 'proxy', id, proxy.state);
|
|
51
|
+
}
|
|
25
52
|
this.log('Proxy updated successfully!');
|
|
26
53
|
if (logs) {
|
|
27
54
|
await (0, logs_1.showProxyLogs)(bt, id);
|
|
28
55
|
}
|
|
29
|
-
if (watch) {
|
|
56
|
+
if (watch && isConfigurableRuntime) {
|
|
57
|
+
this.warn(`--watch is not supported for configurable runtimes (${runtime_2.CONFIGURABLE_RUNTIME_IMAGES.join(' | ')}). Skipping watch.`);
|
|
58
|
+
}
|
|
59
|
+
else if (watch) {
|
|
30
60
|
const entries = Object.entries({
|
|
31
61
|
requestTransformCode,
|
|
32
62
|
responseTransformCode,
|
|
@@ -51,10 +81,40 @@ class Update extends base_1.BaseCommand {
|
|
|
51
81
|
exports.default = Update;
|
|
52
82
|
Update.description = 'Updates an existing Pre-Configured Proxy. Requires `proxy:update` Management Application permission';
|
|
53
83
|
Update.examples = [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
84
|
+
{
|
|
85
|
+
description: 'Update a proxy destination URL',
|
|
86
|
+
command: '<%= config.bin %> <%= command.id %> <proxy-id> --destination-url https://api.example.com',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
description: 'Update a proxy with legacy runtime transforms',
|
|
90
|
+
command: '<%= config.bin %> <%= command.id %> <proxy-id> --request-transform-code ./request.js --request-transform-image node-bt --application-id <application-id>',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
description: 'Update a proxy with node22 transforms',
|
|
94
|
+
command: '<%= config.bin %> <%= command.id %> <proxy-id> --request-transform-code ./request.js --request-transform-image node22 --response-transform-code ./response.js --response-transform-image node22',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
description: 'Update a proxy with node22 transforms and all runtime options',
|
|
98
|
+
command: '<%= config.bin %> <%= command.id %> <proxy-id> ' +
|
|
99
|
+
'--name "My Proxy" ' +
|
|
100
|
+
'--destination-url https://api.example.com ' +
|
|
101
|
+
'--configuration ./config.env ' +
|
|
102
|
+
'--require-auth ' +
|
|
103
|
+
'--request-transform-code ./request.js ' +
|
|
104
|
+
'--request-transform-image node22 ' +
|
|
105
|
+
'--request-transform-timeout 10 ' +
|
|
106
|
+
'--request-transform-warm-concurrency 0 ' +
|
|
107
|
+
'--request-transform-resources standard ' +
|
|
108
|
+
'--request-transform-dependencies ./deps.json ' +
|
|
109
|
+
'--request-transform-permissions token:read ' +
|
|
110
|
+
'--response-transform-code ./response.js ' +
|
|
111
|
+
'--response-transform-image node22 ' +
|
|
112
|
+
'--response-transform-timeout 10 ' +
|
|
113
|
+
'--response-transform-warm-concurrency 0 ' +
|
|
114
|
+
'--response-transform-resources standard ' +
|
|
115
|
+
'--response-transform-dependencies ./deps.json ' +
|
|
116
|
+
'--response-transform-permissions token:read',
|
|
117
|
+
},
|
|
58
118
|
];
|
|
59
119
|
Update.flags = {
|
|
60
120
|
...utils_1.PROXY_FLAGS,
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { BaseCommand } from '../../base';
|
|
2
2
|
export default class Create extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
|
-
static examples:
|
|
4
|
+
static examples: {
|
|
5
|
+
description: string;
|
|
6
|
+
command: string;
|
|
7
|
+
}[];
|
|
5
8
|
static flags: {
|
|
9
|
+
image: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
dependencies: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
+
timeout: import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
'warm-concurrency': import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
+
resources: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
+
permissions: import("@oclif/core/lib/interfaces/parser").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
async: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
|
|
6
16
|
name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
17
|
configuration: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
18
|
'application-id': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const base_1 = require("../../base");
|
|
4
4
|
const management_1 = require("../../reactors/management");
|
|
5
|
+
const runtime_1 = require("../../reactors/runtime");
|
|
5
6
|
const utils_1 = require("../../reactors/utils");
|
|
7
|
+
const runtime_2 = require("../../runtime");
|
|
6
8
|
const utils_2 = require("../../utils");
|
|
7
9
|
class Create extends base_1.BaseCommand {
|
|
8
10
|
async run() {
|
|
9
11
|
const { flags, bt } = await this.parse(Create);
|
|
12
|
+
const { timeout, 'warm-concurrency': warmConcurrency, resources, dependencies, permissions, 'application-id': applicationId, async: asyncFlag, } = flags;
|
|
13
|
+
const image = await (0, runtime_2.promptRuntimeImage)(flags.image);
|
|
14
|
+
(0, runtime_1.validateReactorRuntimeFlags)(flags, image);
|
|
15
|
+
(0, runtime_1.validateReactorApplicationId)(applicationId, image);
|
|
10
16
|
const name = await (0, utils_2.promptStringIfUndefined)(flags.name, {
|
|
11
17
|
message: 'What is the Reactor name?',
|
|
12
18
|
validate: (value) => Boolean(value),
|
|
@@ -15,26 +21,82 @@ class Create extends base_1.BaseCommand {
|
|
|
15
21
|
message: 'Enter the Reactor code file path:',
|
|
16
22
|
validate: (value) => Boolean(value),
|
|
17
23
|
});
|
|
18
|
-
const applicationId = await (0, utils_2.promptStringIfUndefined)(flags['application-id'], {
|
|
19
|
-
message: '(Optional) Enter the Application ID to use in the Reactor:',
|
|
20
|
-
});
|
|
21
24
|
const configuration = await (0, utils_2.promptStringIfUndefined)(flags.configuration, {
|
|
22
25
|
message: '(Optional) Enter the configuration file path (.env format):',
|
|
23
26
|
});
|
|
27
|
+
let promptedApplicationId;
|
|
28
|
+
if ((0, runtime_2.isLegacyRuntimeImage)(image)) {
|
|
29
|
+
promptedApplicationId = await (0, utils_2.promptStringIfUndefined)(applicationId, {
|
|
30
|
+
message: '(Optional) Enter the Application ID to use in the Reactor:',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
let runtime;
|
|
34
|
+
if (!(0, runtime_2.isLegacyRuntimeImage)(image)) {
|
|
35
|
+
const runtimeOptions = await (0, runtime_2.promptRuntimeOptions)({
|
|
36
|
+
timeout,
|
|
37
|
+
'warm-concurrency': warmConcurrency,
|
|
38
|
+
resources,
|
|
39
|
+
dependencies,
|
|
40
|
+
permissions,
|
|
41
|
+
});
|
|
42
|
+
runtime = (0, runtime_2.buildRuntime)({
|
|
43
|
+
image,
|
|
44
|
+
...runtimeOptions,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
24
47
|
const model = (0, utils_1.createModelFromFlags)({
|
|
25
48
|
name,
|
|
26
49
|
code,
|
|
27
|
-
applicationId,
|
|
50
|
+
applicationId: promptedApplicationId,
|
|
28
51
|
configuration,
|
|
52
|
+
runtime,
|
|
29
53
|
});
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
const reactor = await (0, management_1.createReactor)(bt, model);
|
|
55
|
+
if (!asyncFlag && reactor.id) {
|
|
56
|
+
try {
|
|
57
|
+
await (0, runtime_2.waitForResourceState)(bt, 'reactor', reactor.id, reactor.state);
|
|
58
|
+
this.log('Reactor created successfully!');
|
|
59
|
+
this.log(`id: ${reactor.id}`);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
this.log('Reactor created but failed to become ready.');
|
|
63
|
+
this.log(`id: ${reactor.id}`);
|
|
64
|
+
this.log(`You can retry by running: bt reactors update ${reactor.id} [OPTIONS]`);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.log('Reactor created successfully!');
|
|
70
|
+
this.log(`id: ${reactor.id}`);
|
|
71
|
+
}
|
|
33
72
|
}
|
|
34
73
|
}
|
|
35
74
|
exports.default = Create;
|
|
36
75
|
Create.description = 'Creates a new Reactor. Requires `reactor:create` Management Application permission';
|
|
37
|
-
Create.examples = [
|
|
76
|
+
Create.examples = [
|
|
77
|
+
{
|
|
78
|
+
description: 'Create a reactor with legacy runtime',
|
|
79
|
+
command: '<%= config.bin %> <%= command.id %> --name "My Reactor" --code ./reactor.js --image node-bt --application-id <application-id>',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
description: 'Create a reactor with node22 runtime',
|
|
83
|
+
command: '<%= config.bin %> <%= command.id %> --name "My Reactor" --code ./reactor.js --image node22',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
description: 'Create a reactor with node22 and all runtime options',
|
|
87
|
+
command: '<%= config.bin %> <%= command.id %> ' +
|
|
88
|
+
'--name "My Reactor" ' +
|
|
89
|
+
'--code ./reactor.js ' +
|
|
90
|
+
'--configuration ./config.env ' +
|
|
91
|
+
'--image node22 ' +
|
|
92
|
+
'--timeout 10 ' +
|
|
93
|
+
'--warm-concurrency 0 ' +
|
|
94
|
+
'--resources standard ' +
|
|
95
|
+
'--dependencies ./deps.json ' +
|
|
96
|
+
'--permissions token:read ' +
|
|
97
|
+
'--permissions token:create',
|
|
98
|
+
},
|
|
99
|
+
];
|
|
38
100
|
Create.flags = {
|
|
39
101
|
...utils_1.REACTOR_FLAGS,
|
|
40
102
|
};
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { BaseCommand } from '../../base';
|
|
2
2
|
export default class Update extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
|
-
static examples:
|
|
4
|
+
static examples: {
|
|
5
|
+
description: string;
|
|
6
|
+
command: string;
|
|
7
|
+
}[];
|
|
5
8
|
static flags: {
|
|
6
9
|
watch: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
|
|
7
10
|
logs: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
|
|
11
|
+
image: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
dependencies: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
+
timeout: import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
+
'warm-concurrency': import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
resources: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
|
+
permissions: import("@oclif/core/lib/interfaces/parser").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
+
async: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
|
|
8
18
|
name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
19
|
configuration: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
20
|
'application-id': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
@@ -5,22 +5,43 @@ const base_1 = require("../../base");
|
|
|
5
5
|
const files_1 = require("../../files");
|
|
6
6
|
const logs_1 = require("../../logs");
|
|
7
7
|
const management_1 = require("../../reactors/management");
|
|
8
|
+
const runtime_1 = require("../../reactors/runtime");
|
|
8
9
|
const utils_1 = require("../../reactors/utils");
|
|
10
|
+
const runtime_2 = require("../../runtime");
|
|
9
11
|
class Update extends base_1.BaseCommand {
|
|
10
12
|
async run() {
|
|
11
|
-
const { bt, args: { id }, flags
|
|
13
|
+
const { bt, args: { id }, flags, } = await this.parse(Update);
|
|
14
|
+
const { name, code, 'application-id': applicationId, configuration, image, dependencies, timeout, 'warm-concurrency': warmConcurrency, resources, permissions, async: asyncFlag, watch, logs, } = flags;
|
|
15
|
+
(0, runtime_1.validateReactorApplicationId)(applicationId, image);
|
|
16
|
+
const runtime = (0, runtime_2.buildRuntime)({
|
|
17
|
+
image,
|
|
18
|
+
dependencies,
|
|
19
|
+
timeout,
|
|
20
|
+
warmConcurrency,
|
|
21
|
+
resources,
|
|
22
|
+
permissions,
|
|
23
|
+
});
|
|
12
24
|
const model = (0, utils_1.createModelFromFlags)({
|
|
13
25
|
name,
|
|
14
26
|
code,
|
|
15
27
|
applicationId,
|
|
16
28
|
configuration,
|
|
29
|
+
runtime,
|
|
17
30
|
});
|
|
18
31
|
await (0, management_1.patchReactor)(bt, id, model);
|
|
32
|
+
const reactor = await (0, management_1.getReactor)(bt, id);
|
|
33
|
+
const isConfigurableRuntime = (0, runtime_2.needsPolling)(reactor.state);
|
|
34
|
+
if (!asyncFlag) {
|
|
35
|
+
await (0, runtime_2.waitForResourceState)(bt, 'reactor', id, reactor.state);
|
|
36
|
+
}
|
|
19
37
|
this.log('Reactor updated successfully!');
|
|
20
38
|
if (logs) {
|
|
21
39
|
await (0, logs_1.showReactorLogs)(bt, id);
|
|
22
40
|
}
|
|
23
|
-
if (watch) {
|
|
41
|
+
if (watch && isConfigurableRuntime) {
|
|
42
|
+
this.warn(`--watch is not supported for configurable runtimes (${runtime_2.CONFIGURABLE_RUNTIME_IMAGES.join(' | ')}). Skipping watch.`);
|
|
43
|
+
}
|
|
44
|
+
else if (watch) {
|
|
24
45
|
const entries = Object.entries({
|
|
25
46
|
code,
|
|
26
47
|
configuration,
|
|
@@ -44,9 +65,28 @@ class Update extends base_1.BaseCommand {
|
|
|
44
65
|
exports.default = Update;
|
|
45
66
|
Update.description = 'Updates an existing Reactor. Requires `reactor:update` Management Application permission';
|
|
46
67
|
Update.examples = [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
68
|
+
{
|
|
69
|
+
description: 'Update a reactor with legacy runtime',
|
|
70
|
+
command: '<%= config.bin %> <%= command.id %> <reactor-id> --code ./reactor.js --image node-bt --application-id <application-id>',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
description: 'Update a reactor with node22 runtime',
|
|
74
|
+
command: '<%= config.bin %> <%= command.id %> <reactor-id> --code ./reactor.js --image node22',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
description: 'Update a reactor with node22 and all runtime options',
|
|
78
|
+
command: '<%= config.bin %> <%= command.id %> <reactor-id> ' +
|
|
79
|
+
'--name "My Reactor" ' +
|
|
80
|
+
'--code ./reactor.js ' +
|
|
81
|
+
'--configuration ./config.env ' +
|
|
82
|
+
'--image node22 ' +
|
|
83
|
+
'--timeout 10 ' +
|
|
84
|
+
'--warm-concurrency 0 ' +
|
|
85
|
+
'--resources standard ' +
|
|
86
|
+
'--dependencies ./deps.json ' +
|
|
87
|
+
'--permissions token:read ' +
|
|
88
|
+
'--permissions token:create',
|
|
89
|
+
},
|
|
50
90
|
];
|
|
51
91
|
Update.flags = {
|
|
52
92
|
...utils_1.REACTOR_FLAGS,
|
|
@@ -3,4 +3,5 @@ declare const selectProxy: (bt: BasisTheoryClient, page: number) => Promise<Basi
|
|
|
3
3
|
declare const createProxy: (bt: BasisTheoryClient, model: BasisTheory.CreateProxyRequest) => Promise<BasisTheory.Proxy>;
|
|
4
4
|
declare const deleteProxy: (bt: BasisTheoryClient, id: string, force?: boolean) => Promise<boolean>;
|
|
5
5
|
declare const patchProxy: (bt: BasisTheoryClient, id: string, model: BasisTheory.PatchProxyRequest) => Promise<void>;
|
|
6
|
-
|
|
6
|
+
declare const getProxy: (bt: BasisTheoryClient, id: string) => Promise<BasisTheory.Proxy>;
|
|
7
|
+
export { selectProxy, createProxy, patchProxy, deleteProxy, getProxy };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteProxy = exports.patchProxy = exports.createProxy = exports.selectProxy = void 0;
|
|
3
|
+
exports.getProxy = exports.deleteProxy = exports.patchProxy = exports.createProxy = exports.selectProxy = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const confirm_1 = tslib_1.__importDefault(require("@inquirer/confirm"));
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
@@ -25,6 +25,7 @@ const listProxies = async (bt, page) => {
|
|
|
25
25
|
id: {},
|
|
26
26
|
name: {},
|
|
27
27
|
key: {},
|
|
28
|
+
state: {},
|
|
28
29
|
/* eslint-disable camelcase */
|
|
29
30
|
destination_url: {
|
|
30
31
|
header: 'Destination URL',
|
|
@@ -93,8 +94,13 @@ const deleteProxy = async (bt, id, force = false) => {
|
|
|
93
94
|
return true;
|
|
94
95
|
};
|
|
95
96
|
exports.deleteProxy = deleteProxy;
|
|
96
|
-
const patchProxy = (bt, id, model) => {
|
|
97
|
+
const patchProxy = async (bt, id, model) => {
|
|
97
98
|
debug(`Patching Proxy ${id}`, JSON.stringify(model, undefined, 2));
|
|
98
|
-
|
|
99
|
+
await bt.proxies.patch(id, model);
|
|
99
100
|
};
|
|
100
101
|
exports.patchProxy = patchProxy;
|
|
102
|
+
const getProxy = (bt, id) => {
|
|
103
|
+
debug(`Getting Proxy ${id}`);
|
|
104
|
+
return bt.proxies.get(id);
|
|
105
|
+
};
|
|
106
|
+
exports.getProxy = getProxy;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BasisTheory } from '@basis-theory/node-sdk';
|
|
2
|
+
declare const validateTransformRuntimeFlags: (prefix: 'request-transform' | 'response-transform', flags: Record<string, unknown>, image: string | undefined) => void;
|
|
3
|
+
declare const validateProxyApplicationId: (applicationId: string | undefined, flags: Record<string, unknown>) => void;
|
|
4
|
+
declare const promptTransformRuntime: (prefix: 'request' | 'response', flags: Record<string, unknown>, transformCode: string | undefined, image: string | undefined) => Promise<BasisTheory.Runtime | undefined>;
|
|
5
|
+
export { validateTransformRuntimeFlags, validateProxyApplicationId, promptTransformRuntime, };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.promptTransformRuntime = exports.validateProxyApplicationId = exports.validateTransformRuntimeFlags = void 0;
|
|
4
|
+
const runtime_1 = require("../runtime");
|
|
5
|
+
const validateTransformRuntimeFlags = (prefix, flags, image) => {
|
|
6
|
+
const setFlags = [];
|
|
7
|
+
for (const flag of runtime_1.CONFIGURABLE_RUNTIME_FLAGS) {
|
|
8
|
+
const fullFlag = `${prefix}-${flag}`;
|
|
9
|
+
const value = flags[fullFlag];
|
|
10
|
+
const isSet = value !== undefined && !(Array.isArray(value) && value.length === 0);
|
|
11
|
+
if (isSet) {
|
|
12
|
+
setFlags.push(fullFlag);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (setFlags.length && (0, runtime_1.isLegacyRuntimeImage)(image)) {
|
|
16
|
+
const flagNames = setFlags.map((f) => `--${f}`).join(', ');
|
|
17
|
+
throw new Error(`Configurable runtime flags (${flagNames}) require --${prefix}-image ${runtime_1.CONFIGURABLE_RUNTIME_IMAGES.join(' | ')}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.validateTransformRuntimeFlags = validateTransformRuntimeFlags;
|
|
21
|
+
const hasTransformWithRuntime = (flags, runtimes) => {
|
|
22
|
+
const requestImage = flags['request-transform-image'];
|
|
23
|
+
const responseImage = flags['response-transform-image'];
|
|
24
|
+
const isMatch = (image) => {
|
|
25
|
+
if (image === undefined) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return typeof runtimes === 'string'
|
|
29
|
+
? image === runtimes
|
|
30
|
+
: runtimes.includes(image);
|
|
31
|
+
};
|
|
32
|
+
return isMatch(requestImage) || isMatch(responseImage);
|
|
33
|
+
};
|
|
34
|
+
const validateProxyApplicationId = (applicationId, flags) => {
|
|
35
|
+
if (!applicationId) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const hasConfigurable = hasTransformWithRuntime(flags, runtime_1.CONFIGURABLE_RUNTIME_IMAGES);
|
|
39
|
+
const hasLegacy = hasTransformWithRuntime(flags, runtime_1.LEGACY_RUNTIME_IMAGE);
|
|
40
|
+
if (hasConfigurable && !hasLegacy) {
|
|
41
|
+
throw new Error(`--application-id is only valid when at least one transform uses a legacy runtime (${runtime_1.LEGACY_RUNTIME_IMAGE}). Use --{request,response}-transform-permissions instead.`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.validateProxyApplicationId = validateProxyApplicationId;
|
|
45
|
+
const promptTransformRuntime = async (prefix, flags, transformCode, image) => {
|
|
46
|
+
if (!transformCode) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if ((0, runtime_1.isLegacyRuntimeImage)(image)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const transformFlags = {
|
|
53
|
+
timeout: flags[`${prefix}-transform-timeout`],
|
|
54
|
+
'warm-concurrency': flags[`${prefix}-transform-warm-concurrency`],
|
|
55
|
+
resources: flags[`${prefix}-transform-resources`],
|
|
56
|
+
dependencies: flags[`${prefix}-transform-dependencies`],
|
|
57
|
+
permissions: flags[`${prefix}-transform-permissions`],
|
|
58
|
+
};
|
|
59
|
+
const labelPrefix = `${prefix.charAt(0).toUpperCase()}${prefix.slice(1)} transform`;
|
|
60
|
+
const runtimeOptions = await (0, runtime_1.promptRuntimeOptions)(transformFlags, labelPrefix);
|
|
61
|
+
return (0, runtime_1.buildRuntime)({
|
|
62
|
+
image,
|
|
63
|
+
...runtimeOptions,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
exports.promptTransformRuntime = promptTransformRuntime;
|
package/dist/proxies/utils.d.ts
CHANGED
|
@@ -8,6 +8,19 @@ declare const PROXY_FLAGS: {
|
|
|
8
8
|
'application-id': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
9
|
configuration: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
10
|
'require-auth': import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
|
|
11
|
+
'request-transform-image': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
'request-transform-dependencies': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
+
'request-transform-timeout': import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
+
'request-transform-warm-concurrency': import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
'request-transform-resources': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
|
+
'request-transform-permissions': import("@oclif/core/lib/interfaces/parser").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
+
'response-transform-image': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
18
|
+
'response-transform-dependencies': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
19
|
+
'response-transform-timeout': import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
20
|
+
'response-transform-warm-concurrency': import("@oclif/core/lib/interfaces/parser").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
21
|
+
'response-transform-resources': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
22
|
+
'response-transform-permissions': import("@oclif/core/lib/interfaces/parser").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
23
|
+
async: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
|
|
11
24
|
};
|
|
12
25
|
interface ProxyFlagProps {
|
|
13
26
|
/**
|
|
@@ -26,9 +39,17 @@ interface ProxyFlagProps {
|
|
|
26
39
|
* Path to .env file
|
|
27
40
|
*/
|
|
28
41
|
configuration?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Request transform runtime
|
|
44
|
+
*/
|
|
45
|
+
requestTransformRuntime?: BasisTheory.Runtime;
|
|
46
|
+
/**
|
|
47
|
+
* Response transform runtime
|
|
48
|
+
*/
|
|
49
|
+
responseTransformRuntime?: BasisTheory.Runtime;
|
|
29
50
|
}
|
|
30
|
-
type CreateProxy = ProxyFlagProps & Omit<BasisTheory.CreateProxyRequest, 'application' | 'configuration' | '
|
|
31
|
-
type PatchProxy = ProxyFlagProps & Omit<BasisTheory.PatchProxyRequest, 'application' | 'configuration' | '
|
|
51
|
+
type CreateProxy = ProxyFlagProps & Omit<BasisTheory.CreateProxyRequest, 'application' | 'configuration' | 'requestTransforms' | 'responseTransforms'>;
|
|
52
|
+
type PatchProxy = ProxyFlagProps & Omit<BasisTheory.PatchProxyRequest, 'application' | 'configuration' | 'requestTransforms' | 'responseTransforms'>;
|
|
32
53
|
declare function createModelFromFlags(payload: CreateProxy): BasisTheory.CreateProxyRequest;
|
|
33
54
|
declare function createModelFromFlags(payload: PatchProxy): BasisTheory.PatchProxyRequest;
|
|
34
55
|
export { PROXY_FLAGS, createModelFromFlags };
|
package/dist/proxies/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.createModelFromFlags = exports.PROXY_FLAGS = void 0;
|
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
5
|
const dotenv_1 = require("dotenv");
|
|
6
6
|
const files_1 = require("../files");
|
|
7
|
+
const runtime_1 = require("../runtime");
|
|
7
8
|
const PROXY_FLAGS = {
|
|
8
9
|
name: core_1.Flags.string({
|
|
9
10
|
char: 'n',
|
|
@@ -35,19 +36,89 @@ const PROXY_FLAGS = {
|
|
|
35
36
|
allowNo: true,
|
|
36
37
|
default: true,
|
|
37
38
|
}),
|
|
39
|
+
'request-transform-image': core_1.Flags.string({
|
|
40
|
+
description: `request-transform runtime image (${runtime_1.VALID_RUNTIME_IMAGES.join('|')})`,
|
|
41
|
+
options: [...runtime_1.VALID_RUNTIME_IMAGES],
|
|
42
|
+
}),
|
|
43
|
+
'request-transform-dependencies': core_1.Flags.file({
|
|
44
|
+
description: 'path to JSON file with npm dependencies, e.g. {"axios": "1.7.9", "lodash": "4.17.21"} (node22 only)',
|
|
45
|
+
}),
|
|
46
|
+
'request-transform-timeout': core_1.Flags.integer({
|
|
47
|
+
description: 'request-transform timeout in seconds, 1-30 (node22 only)',
|
|
48
|
+
min: 1,
|
|
49
|
+
max: 30,
|
|
50
|
+
}),
|
|
51
|
+
'request-transform-warm-concurrency': core_1.Flags.integer({
|
|
52
|
+
description: 'request-transform warm concurrency, 0-1 (node22 only)',
|
|
53
|
+
min: 0,
|
|
54
|
+
max: 1,
|
|
55
|
+
}),
|
|
56
|
+
'request-transform-resources': core_1.Flags.string({
|
|
57
|
+
description: 'request-transform resource tier (node22 only)',
|
|
58
|
+
options: ['standard', 'large', 'xlarge'],
|
|
59
|
+
}),
|
|
60
|
+
'request-transform-permissions': core_1.Flags.string({
|
|
61
|
+
description: 'request-transform permission to grant, repeatable (node22 only)',
|
|
62
|
+
multiple: true,
|
|
63
|
+
}),
|
|
64
|
+
'response-transform-image': core_1.Flags.string({
|
|
65
|
+
description: `response-transform runtime image (${runtime_1.VALID_RUNTIME_IMAGES.join('|')})`,
|
|
66
|
+
options: [...runtime_1.VALID_RUNTIME_IMAGES],
|
|
67
|
+
}),
|
|
68
|
+
'response-transform-dependencies': core_1.Flags.file({
|
|
69
|
+
description: 'path to JSON file with npm dependencies, e.g. {"axios": "1.7.9", "lodash": "4.17.21"} (node22 only)',
|
|
70
|
+
}),
|
|
71
|
+
'response-transform-timeout': core_1.Flags.integer({
|
|
72
|
+
description: 'response-transform timeout in seconds, 1-30 (node22 only)',
|
|
73
|
+
min: 1,
|
|
74
|
+
max: 30,
|
|
75
|
+
}),
|
|
76
|
+
'response-transform-warm-concurrency': core_1.Flags.integer({
|
|
77
|
+
description: 'response-transform warm concurrency, 0-1 (node22 only)',
|
|
78
|
+
min: 0,
|
|
79
|
+
max: 1,
|
|
80
|
+
}),
|
|
81
|
+
'response-transform-resources': core_1.Flags.string({
|
|
82
|
+
description: 'response-transform resource tier (node22 only)',
|
|
83
|
+
options: ['standard', 'large', 'xlarge'],
|
|
84
|
+
}),
|
|
85
|
+
'response-transform-permissions': core_1.Flags.string({
|
|
86
|
+
description: 'response-transform permission to grant, repeatable (node22 only)',
|
|
87
|
+
multiple: true,
|
|
88
|
+
}),
|
|
89
|
+
async: core_1.Flags.boolean({
|
|
90
|
+
description: 'do not wait for proxy to be ready (requires at least one transform with node22)',
|
|
91
|
+
default: false,
|
|
92
|
+
}),
|
|
38
93
|
};
|
|
39
94
|
exports.PROXY_FLAGS = PROXY_FLAGS;
|
|
40
95
|
// eslint-disable-next-line get-off-my-lawn/prefer-arrow-functions
|
|
41
|
-
function createModelFromFlags({ name, destinationUrl, requestTransformCode, responseTransformCode, applicationId, configuration, requireAuth, }) {
|
|
96
|
+
function createModelFromFlags({ name, destinationUrl, requestTransformCode, responseTransformCode, applicationId, configuration, requireAuth, requestTransformRuntime, responseTransformRuntime, }) {
|
|
97
|
+
let requestTransform;
|
|
98
|
+
if (requestTransformCode) {
|
|
99
|
+
requestTransform = {
|
|
100
|
+
type: 'code',
|
|
101
|
+
code: (0, files_1.readFileContents)(requestTransformCode),
|
|
102
|
+
};
|
|
103
|
+
if (requestTransformRuntime) {
|
|
104
|
+
requestTransform.options = { runtime: requestTransformRuntime };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let responseTransform;
|
|
108
|
+
if (responseTransformCode) {
|
|
109
|
+
responseTransform = {
|
|
110
|
+
type: 'code',
|
|
111
|
+
code: (0, files_1.readFileContents)(responseTransformCode),
|
|
112
|
+
};
|
|
113
|
+
if (responseTransformRuntime) {
|
|
114
|
+
responseTransform.options = { runtime: responseTransformRuntime };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
42
117
|
return {
|
|
43
118
|
name,
|
|
44
119
|
destinationUrl,
|
|
45
|
-
requestTransform:
|
|
46
|
-
|
|
47
|
-
: undefined,
|
|
48
|
-
responseTransform: responseTransformCode
|
|
49
|
-
? { code: (0, files_1.readFileContents)(responseTransformCode) }
|
|
50
|
-
: undefined,
|
|
120
|
+
requestTransforms: requestTransform ? [requestTransform] : undefined,
|
|
121
|
+
responseTransforms: responseTransform ? [responseTransform] : undefined,
|
|
51
122
|
application: applicationId ? { id: applicationId } : undefined,
|
|
52
123
|
configuration: configuration
|
|
53
124
|
? (0, dotenv_1.parse)((0, files_1.readFileContents)(configuration))
|
|
@@ -3,4 +3,5 @@ declare const selectReactor: (bt: BasisTheoryClient, page: number) => Promise<Ba
|
|
|
3
3
|
declare const createReactor: (bt: BasisTheoryClient, model: BasisTheory.CreateReactorRequest) => Promise<BasisTheory.Reactor>;
|
|
4
4
|
declare const deleteReactor: (bt: BasisTheoryClient, id: string, force?: boolean) => Promise<boolean>;
|
|
5
5
|
declare const patchReactor: (bt: BasisTheoryClient, id: string, model: BasisTheory.PatchReactorRequest) => Promise<void>;
|
|
6
|
-
|
|
6
|
+
declare const getReactor: (bt: BasisTheoryClient, id: string) => Promise<BasisTheory.Reactor>;
|
|
7
|
+
export { selectReactor, createReactor, patchReactor, deleteReactor, getReactor, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteReactor = exports.patchReactor = exports.createReactor = exports.selectReactor = void 0;
|
|
3
|
+
exports.getReactor = exports.deleteReactor = exports.patchReactor = exports.createReactor = exports.selectReactor = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const confirm_1 = tslib_1.__importDefault(require("@inquirer/confirm"));
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
@@ -24,6 +24,7 @@ const listReactors = async (bt, page) => {
|
|
|
24
24
|
'#': {},
|
|
25
25
|
id: {},
|
|
26
26
|
name: {},
|
|
27
|
+
state: {},
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
@@ -70,8 +71,13 @@ const deleteReactor = async (bt, id, force = false) => {
|
|
|
70
71
|
return true;
|
|
71
72
|
};
|
|
72
73
|
exports.deleteReactor = deleteReactor;
|
|
73
|
-
const patchReactor = (bt, id, model) => {
|
|
74
|
+
const patchReactor = async (bt, id, model) => {
|
|
74
75
|
debug(`Patching Reactor ${id}`, JSON.stringify(model, undefined, 2));
|
|
75
|
-
|
|
76
|
+
await bt.reactors.patch(id, model);
|
|
76
77
|
};
|
|
77
78
|
exports.patchReactor = patchReactor;
|
|
79
|
+
const getReactor = (bt, id) => {
|
|
80
|
+
debug(`Getting Reactor ${id}`);
|
|
81
|
+
return bt.reactors.get(id);
|
|
82
|
+
};
|
|
83
|
+
exports.getReactor = getReactor;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const validateReactorRuntimeFlags: (flags: Record<string, unknown>, image: string | undefined) => void;
|
|
2
|
+
declare const validateReactorApplicationId: (applicationId: string | undefined, image: string | undefined) => void;
|
|
3
|
+
export { validateReactorRuntimeFlags, validateReactorApplicationId };
|