@adobe/aio-cli-plugin-api-mesh 5.2.3 → 5.2.4-alpha.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.
Files changed (42) hide show
  1. package/oclif.manifest.json +1 -1
  2. package/package.json +5 -10
  3. package/src/commands/{api-mesh.js → PLUGINNAME/__tests__/index.test.js} +15 -13
  4. package/src/commands/PLUGINNAME/index.js +32 -0
  5. package/src/commands/api-mesh/__tests__/cache-purge.test.js +2 -2
  6. package/src/commands/api-mesh/__tests__/create.test.js +9 -21
  7. package/src/commands/api-mesh/__tests__/delete.test.js +2 -2
  8. package/src/commands/api-mesh/__tests__/describe.test.js +2 -2
  9. package/src/commands/api-mesh/__tests__/get-log-forwarding.test.js +149 -0
  10. package/src/commands/api-mesh/__tests__/get.test.js +2 -2
  11. package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +2 -2
  12. package/src/commands/api-mesh/__tests__/log-get.test.js +2 -2
  13. package/src/commands/api-mesh/__tests__/log-list.test.js +2 -2
  14. package/src/commands/api-mesh/__tests__/run.test.js +67 -193
  15. package/src/commands/api-mesh/__tests__/set-log-forwarding.test.js +246 -0
  16. package/src/commands/api-mesh/__tests__/status.test.js +2 -2
  17. package/src/commands/api-mesh/__tests__/update.test.js +4 -6
  18. package/src/commands/api-mesh/cache/purge.js +1 -1
  19. package/src/commands/api-mesh/config/get/log-forwarding.js +78 -0
  20. package/src/commands/api-mesh/config/set/log-forwarding.js +156 -0
  21. package/src/commands/api-mesh/create.js +4 -3
  22. package/src/commands/api-mesh/delete.js +1 -1
  23. package/src/commands/api-mesh/describe.js +1 -1
  24. package/src/commands/api-mesh/get.js +1 -1
  25. package/src/commands/api-mesh/log-get-bulk.js +1 -1
  26. package/src/commands/api-mesh/log-get.js +1 -1
  27. package/src/commands/api-mesh/log-list.js +1 -1
  28. package/src/commands/api-mesh/run.js +162 -208
  29. package/src/commands/api-mesh/source/__tests__/install.test.js +2 -2
  30. package/src/commands/api-mesh/source/install.js +1 -1
  31. package/src/commands/api-mesh/status.js +1 -1
  32. package/src/commands/api-mesh/update.js +4 -3
  33. package/src/helpers.js +29 -20
  34. package/src/{worker.js → index.js} +7 -9
  35. package/src/lib/{devConsole.js → smsClient.js} +186 -1
  36. package/src/server.js +32 -74
  37. package/src/utils.js +46 -10
  38. package/src/wranglerServer.js +80 -0
  39. package/src/meshArtifact.js +0 -231
  40. package/src/project.js +0 -56
  41. package/src/wranglerCli.js +0 -54
  42. package/wrangler.toml +0 -13
@@ -1,231 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const { fixPlugins } = require('./fixPlugins');
4
- const logger = require('../src/classes/logger');
5
-
6
- /**
7
- * Whether file is TypeScript
8
- * @param filePath Filepath
9
- */
10
- function isTypeScriptFile(filePath) {
11
- const ext = path.extname(filePath);
12
- return ext === '.ts' || ext === '.tsx';
13
- }
14
-
15
- /**
16
- * Gets
17
- * @param builtMeshTenantDir
18
- * @returns {string}
19
- */
20
- function getBuiltMeshEntrypoint(builtMeshTenantDir) {
21
- let builtMeshIndexPath = path.join(builtMeshTenantDir, 'index');
22
- return fs.existsSync(`${builtMeshIndexPath}.ts`)
23
- ? `${builtMeshIndexPath}.ts`
24
- : `${builtMeshIndexPath}.js`;
25
- }
26
-
27
- /**
28
- * Converts composer string to static imports compatible with bundling
29
- * @param data {string} Data read from the built mesh
30
- * @returns {string} Updated data
31
- * @example Converts composer string
32
- * ```
33
- * "beforeAll": {
34
- * "composer": "/Users/user/project/hooks.js#isAuth",
35
- * "blocking": true
36
- * }
37
- * ```
38
- * To:
39
- * ```
40
- * "beforeAll": {
41
- * "module": await import("/Users/user/project/hooks.js"), "fn": "isAuth",
42
- * "blocking": true
43
- * }
44
- * ```
45
- */
46
- function resolveComposerAsTypeScriptModule(data) {
47
- return data.replace(
48
- /"composer":\s*"([^#]+)#([^"]+)"/,
49
- `"module": await import("$1"), "fn": "$2"`,
50
- );
51
- }
52
-
53
- /**
54
- * Converts composer string to static imports compatible with bundling
55
- * @param data {string} Data read from the built mesh
56
- * @returns {string} Updated data
57
- * @example Converts composer string
58
- * ```
59
- * "beforeAll": {
60
- * "composer": "/Users/user/project/hooks.js#isAuth",
61
- * "blocking": true
62
- * }
63
- * ```
64
- * To:
65
- * ```
66
- * "beforeAll": {
67
- * "module": __importStar(require("/Users/user/project/hooks.js")), "fn": "isAuth",
68
- * "blocking": true
69
- * }
70
- * ```
71
- */
72
- function resolveComposerAsJavaScriptModule(data) {
73
- return data.replace(
74
- /"composer":\s*"([^#]+)#([^"]+)"/,
75
- `"module": __importStar(require("$1")), "fn": "$2"`,
76
- );
77
- }
78
-
79
- /**
80
- * Takes a mesh artifact and converts composer configuration to static imports
81
- * compatible with bundling
82
- * @param meshArtifactPath Path to the mesh artifact used to determine extension
83
- * @param data {string} Data read from the built mesh
84
- * @returns {string} Updated data
85
- * @see {@link resolveComposerAsJavaScriptModule}
86
- * @see {@link resolveComposerAsTypeScriptModule}
87
- */
88
- function resolveComposerAsStaticImport(meshArtifactPath, data) {
89
- return isTypeScriptFile(meshArtifactPath)
90
- ? resolveComposerAsTypeScriptModule(data)
91
- : resolveComposerAsJavaScriptModule(data);
92
- }
93
-
94
- // /**
95
- // * Converts handler string to static imports compatible with bundling
96
- // * @param data {string} Data read from the built mesh
97
- // * @returns {string} Updated data
98
- // * @example Converts composer string
99
- // * ```
100
- // * "onFetch": {
101
- // * "handler": "/Users/user/project/fetch.js",
102
- // * "blocking": true
103
- // * }
104
- // * ```
105
- // * To:
106
- // * ```
107
- // * "onFetch": {
108
- // * "handler": await import("/Users/user/project/fetch.js"),
109
- // * "blocking": true
110
- // * }
111
- // * ```
112
- // */
113
- // function resolveHandlerAsTypeScriptModule(data) {
114
- // return data.replace(/"handler":\s*"([^"]+)"/, `"handler": await import("$1")`);
115
- // }
116
-
117
- // /**
118
- // * Converts handler string to static imports compatible with bundling
119
- // * @param data {string} Data read from the built mesh
120
- // * @returns {string} Updated data
121
- // * @example Converts composer string
122
- // * ```
123
- // * "onFetch": {
124
- // * "handler": "/Users/user/project/fetch.js",
125
- // * "blocking": true
126
- // * }
127
- // * ```
128
- // * To:
129
- // * ```
130
- // * "onFetch": {
131
- // * "module": __importStar(require("/Users/user/project/fetch.js")),
132
- // * "blocking": true
133
- // * }
134
- // * ```
135
- // */
136
- // function resolveHandlerAsJavaScriptModule(data) {
137
- // return data.replace(/"handler":\s*"([^"]+)"/, `"handler": __importStar(require("$1"))`);
138
- // }
139
-
140
- // /**
141
- // * Takes a mesh artifact and converts handler configuration to static imports
142
- // * compatible with bundling
143
- // * @param meshArtifactPath Path to the mesh artifact used to determine extension
144
- // * @param data {string} Data read from the built mesh
145
- // * @returns {string} Updated data
146
- // * @see {@link resolveHandlerAsJavaScriptModule}
147
- // * @see {@link resolveHandlerAsTypeScriptModule}
148
- // */
149
- // TODO: onFetch support - requires plugin changes
150
- // function resolveHandlerAsStaticImport(meshArtifactPath, data) {
151
- // return isTypeScriptFile(meshArtifactPath)
152
- // ? resolveHandlerAsTypeScriptModule(data)
153
- // : resolveHandlerAsJavaScriptModule(data);
154
- // }
155
-
156
- const resolveRelativeSources = async builtMeshTenantDir => {
157
- let builtMeshPath = getBuiltMeshEntrypoint(builtMeshTenantDir);
158
-
159
- // Fix http details extensions plugin for edge compatibility
160
- await fixPlugins(builtMeshPath);
161
-
162
- // Read tenant files inventory
163
- const artifactFilesPath = path.join(builtMeshTenantDir, 'files.json');
164
- if (fs.existsSync(artifactFilesPath)) {
165
- // Read mesh artifact
166
- let builtMeshData = fs.readFileSync(builtMeshPath).toString();
167
-
168
- const parentDirRegex = new RegExp('../tenantFiles'.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
169
- builtMeshData = builtMeshData.replace(parentDirRegex, './tenantFiles');
170
-
171
- // Write the modified mesh artifact
172
- fs.writeFileSync(builtMeshPath, builtMeshData, 'utf8');
173
- }
174
- };
175
-
176
- /**
177
- * Resolve original sources to materialized files in mesh artifact for local development and debugging
178
- * @param builtMeshTenantDir Built mesh tenant directory
179
- * @param localFileOverrides Local file overrides
180
- */
181
- const resolveOriginalSources = async (builtMeshTenantDir, localFileOverrides) => {
182
- let builtMeshPath = getBuiltMeshEntrypoint(builtMeshTenantDir);
183
-
184
- // Read tenant files inventory
185
- const artifactFilesPath = path.join(builtMeshTenantDir, 'files.json');
186
- if (fs.existsSync(artifactFilesPath)) {
187
- let files = {};
188
- try {
189
- files = JSON.parse(fs.readFileSync(artifactFilesPath).toString());
190
- } catch (err) {
191
- logger.error('Malformed "files.json" file. Skipping original source resolution.');
192
- }
193
-
194
- // Read mesh artifact
195
- let builtMeshData = fs.readFileSync(builtMeshPath).toString();
196
- files.files.forEach(file => {
197
- // Skip replacement of files for local development when the user was prompted
198
- // to override and answered no
199
- if (
200
- Object.keys(localFileOverrides).includes(file.path) &&
201
- localFileOverrides[file.path] === false
202
- ) {
203
- return;
204
- }
205
-
206
- // When the source exists in project use it instead of the materialized file
207
- const absoluteFilePath = path.resolve(file.path);
208
-
209
- // Replace all occurrences of the materialized path with the fully qualified original path when it exists
210
- if (fs.existsSync(absoluteFilePath)) {
211
- const regex = new RegExp(file.materializedPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
212
- builtMeshData = builtMeshData.replace(regex, absoluteFilePath);
213
- builtMeshData = resolveComposerAsStaticImport(builtMeshPath, builtMeshData);
214
- // TODO: onFetch support - requires plugin changes
215
- // builtMeshData = resolveHandlerAsStaticImport(builtMeshPath, builtMeshData);
216
- }
217
- });
218
-
219
- // Write the modified mesh artifact
220
- fs.writeFileSync(builtMeshPath, builtMeshData, 'utf8');
221
- }
222
- };
223
-
224
- module.exports = {
225
- isTypeScriptFile,
226
- resolveComposerAsTypeScriptModule,
227
- resolveComposerAsJavaScriptModule,
228
- resolveComposerAsStaticImport,
229
- resolveRelativeSources,
230
- resolveOriginalSources,
231
- };
package/src/project.js DELETED
@@ -1,56 +0,0 @@
1
- const { cpSync, existsSync, renameSync, rmSync } = require('node:fs');
2
- const { join } = require('node:path');
3
- const { resolveOriginalSources } = require('./meshArtifact');
4
-
5
- const BUILT_MESH_ARTIFACT_DIRECTORY = 'mesh-artifact';
6
- const BUILT_MESH_TENANT_FILES_DIRECTORY = join(BUILT_MESH_ARTIFACT_DIRECTORY, 'tenantFiles');
7
- const PACKAGED_MESH_DIR = '.mesh';
8
- const PACKAGED_MESH_DIR_TENANT_FILES_DIRECTORY = join(PACKAGED_MESH_DIR, 'tenantFiles');
9
- const PACKAGED_MESH_CLI_MIRROR_DIR = `${__dirname}/../${PACKAGED_MESH_DIR}`;
10
- const TEMP_FILES_DIRECTORY = 'tempfiles';
11
- const getBuiltMeshTenantDirectory = meshId => join(BUILT_MESH_ARTIFACT_DIRECTORY, meshId);
12
-
13
- /**
14
- * Copy built mesh artifact to packaged directory that runs local development.
15
- * @param builtMeshTenantDir Built mesh directory path
16
- * @returns {Promise<void>}
17
- */
18
- const copyBuiltMeshToPackage = async builtMeshTenantDir => {
19
- // Reset packaged directories
20
- safeDelete(PACKAGED_MESH_DIR);
21
- safeDelete(PACKAGED_MESH_CLI_MIRROR_DIR);
22
-
23
- // Copy the built mesh to the packaged directory for in-project SDK
24
- safeRename(builtMeshTenantDir, PACKAGED_MESH_DIR);
25
- safeRename(BUILT_MESH_TENANT_FILES_DIRECTORY, PACKAGED_MESH_DIR_TENANT_FILES_DIRECTORY);
26
-
27
- // Copy the packaged mesh to the CLI mirror directory for local server
28
- safeCopy(PACKAGED_MESH_DIR, PACKAGED_MESH_CLI_MIRROR_DIR);
29
- };
30
-
31
- const safeDelete = path => {
32
- if (existsSync(path)) {
33
- rmSync(path, { recursive: true });
34
- }
35
- };
36
-
37
- const safeRename = (oldPath, newPath) => {
38
- if (existsSync(oldPath)) {
39
- renameSync(oldPath, newPath);
40
- }
41
- };
42
-
43
- const safeCopy = (source, destination) => {
44
- if (existsSync(source)) {
45
- cpSync(source, destination, { recursive: true });
46
- }
47
- };
48
-
49
- module.exports = {
50
- BUILT_MESH_ARTIFACT_DIRECTORY,
51
- safeDelete,
52
- copyBuiltMeshToPackage,
53
- resolveOriginalSources,
54
- TEMP_FILES_DIRECTORY,
55
- getBuiltMeshTenantDirectory,
56
- };
@@ -1,54 +0,0 @@
1
- const { spawn } = require('child_process');
2
- const { readSecretsFile } = require('./serverUtils');
3
- const packageData = require('../package.json');
4
- const { join } = require('node:path');
5
-
6
- /**
7
- * Starts the wrangler dev server
8
- * @param command {Command} CLI command
9
- * @param port Port number
10
- * @param debug Whether debug mode is enabled
11
- * @param inspectPort Port number for local dev server inspector
12
- */
13
- const start = (command, port, debug, inspectPort) => {
14
- const wranglerPackageNumber = packageData.dependencies.wrangler;
15
- const wranglerVersion = `wrangler@${wranglerPackageNumber.replace(/^[\^~]/, '')}`;
16
- const wranglerToml = join(__dirname, '..', 'wrangler.toml');
17
- const meshDir = '.mesh';
18
- const secrets = readSecretsFile(meshDir);
19
- const entrypoint = join(__dirname, 'worker.js');
20
-
21
- const commandArgs = [
22
- wranglerVersion,
23
- '--config',
24
- wranglerToml,
25
- '--cwd',
26
- process.cwd(),
27
- 'dev',
28
- entrypoint,
29
- '--show-interactive-dev-session',
30
- 'false',
31
- '--var',
32
- `Secret:${JSON.stringify(secrets)}`,
33
- '--port',
34
- port,
35
- '--inspector-port',
36
- debug ? inspectPort : 0,
37
- ];
38
-
39
- const wrangler = spawn('npx', commandArgs, {
40
- stdio: 'inherit',
41
- });
42
-
43
- wrangler.on('close', code => {
44
- // eslint-disable-next-line no-console
45
- console.log(`wrangler dev process exited with code ${code}`);
46
- });
47
-
48
- wrangler.on('error', error => {
49
- // eslint-disable-next-line no-console
50
- console.error(`Failed to start wrangler dev: ${error.message}`);
51
- });
52
- };
53
-
54
- module.exports = { start };
package/wrangler.toml DELETED
@@ -1,13 +0,0 @@
1
- # Tenant worker core definition. For platform workers metadata configs are used to set bindings.
2
- name = "tenant-worker-core"
3
- compatibility_date = "2024-06-03"
4
-
5
- find_additional_modules = true
6
- base_dir = ".mesh"
7
- rules = [
8
- { type = "CommonJS", globs = ["tenantFiles/**/*.js"] }
9
- ]
10
-
11
-
12
- [[migrations]]
13
- tag = "v1"