@adobe/aio-cli-plugin-api-mesh 4.1.1-beta.1 → 5.0.0-alpha

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 (41) hide show
  1. package/oclif.manifest.json +1 -1
  2. package/package.json +3 -13
  3. package/src/commands/api-mesh/__tests__/create.test.js +217 -293
  4. package/src/commands/api-mesh/__tests__/delete.test.js +6 -6
  5. package/src/commands/api-mesh/__tests__/describe.test.js +2 -17
  6. package/src/commands/api-mesh/__tests__/get.test.js +9 -78
  7. package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +1 -1
  8. package/src/commands/api-mesh/__tests__/run.test.js +22 -25
  9. package/src/commands/api-mesh/__tests__/status.test.js +1 -1
  10. package/src/commands/api-mesh/__tests__/update.test.js +8 -9
  11. package/src/commands/api-mesh/create.js +6 -9
  12. package/src/commands/api-mesh/delete.js +5 -5
  13. package/src/commands/api-mesh/describe.js +3 -3
  14. package/src/commands/api-mesh/get.js +8 -11
  15. package/src/commands/api-mesh/init.js +0 -2
  16. package/src/commands/api-mesh/log-get-bulk.js +2 -2
  17. package/src/commands/api-mesh/log-get.js +2 -2
  18. package/src/commands/api-mesh/log-list.js +1 -1
  19. package/src/commands/api-mesh/run.js +9 -35
  20. package/src/commands/api-mesh/source/install.js +3 -2
  21. package/src/commands/api-mesh/status.js +4 -6
  22. package/src/commands/api-mesh/update.js +7 -9
  23. package/src/constants.js +2 -0
  24. package/src/helpers.js +4 -71
  25. package/src/lib/devConsole.js +38 -32
  26. package/src/server.js +198 -36
  27. package/src/serverUtils.js +3 -3
  28. package/src/cors.js +0 -28
  29. package/src/fixPlugins.js +0 -28
  30. package/src/hooks/versionCompare.js +0 -23
  31. package/src/index.js +0 -44
  32. package/src/plugins/complianceHeaders/complianceHeaders.js +0 -55
  33. package/src/plugins/complianceHeaders/index.js +0 -2
  34. package/src/plugins/httpDetailsExtensions/LICENSE +0 -21
  35. package/src/plugins/httpDetailsExtensions/index.js +0 -81
  36. package/src/secrets.js +0 -34
  37. package/src/served.js +0 -22
  38. package/src/templates/wrangler.toml +0 -14
  39. package/src/utils/logger.js +0 -42
  40. package/src/utils/requestId.js +0 -26
  41. package/src/wranglerServer.js +0 -80
@@ -1,55 +0,0 @@
1
- /**
2
- * CF-Connecting-IP provides the client IP address connecting to Cloudflare to the origin web server. This header will only be sent on the
3
- * traffic from Cloudflare’s edge to your origin web server. Upstream requests will the Cloudflare Worker client IP address of
4
- * `2a06:98c0:3600::103`.
5
- * @see https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#cf-connecting-ip
6
- */
7
- const CF_CONNECTING_IP_HEADER = 'cf-connecting-ip';
8
-
9
- /**
10
- * The X-Forwarded-For (XFF) request header is a de-facto standard header for identifying the originating IP address of a client connecting
11
- * to a web server through a proxy server.
12
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
13
- */
14
- const X_FORWARDED_FOR_HEADER = 'x-forwarded-for';
15
-
16
- /**
17
- * Add `x-forwarded-for` header from request context to each fetch.
18
- * @param context Request context.
19
- * @param headers Fetch headers.
20
- */
21
- const addXForwardedForHeader = (context, headers) => {
22
- // `cf-connecting-ip` header contains the original visitor's IP address
23
- const connectingIp = context?.request.headers.get(CF_CONNECTING_IP_HEADER);
24
- const xForwardedFor = context?.request.headers.get(X_FORWARDED_FOR_HEADER);
25
- if (connectingIp) {
26
- if (!xForwardedFor) {
27
- // Construct new `x-forwarded-for` header if not present in original request
28
- headers.set(X_FORWARDED_FOR_HEADER, connectingIp);
29
- } else {
30
- // Construct `x-forwarded-for` header using original header
31
- headers.set(X_FORWARDED_FOR_HEADER, `${xForwardedFor}, ${connectingIp}`);
32
- }
33
- }
34
- };
35
-
36
- /**
37
- * Adds compliance headers to source fetch requests.
38
- */
39
- function useComplianceHeaders() {
40
- return {
41
- onFetch({ context, options }) {
42
- // Construct mutable headers from options passed to each fetch
43
- const headers = new Headers(options.headers);
44
- addXForwardedForHeader(context, headers);
45
- options.headers = headers;
46
- },
47
- };
48
- }
49
-
50
- module.exports = {
51
- useComplianceHeaders,
52
- CF_CONNECTING_IP_HEADER,
53
- X_FORWARDED_FOR_HEADER,
54
- addXForwardedForHeader,
55
- };
@@ -1,2 +0,0 @@
1
- const { useComplianceHeaders } = require('./complianceHeaders');
2
- module.exports = useComplianceHeaders;
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Uri Goldshtein
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,81 +0,0 @@
1
- /**
2
- * Fork of https://github.com/ardatan/graphql-mesh/blob/%40graphql-mesh/plugin-http-details-extensions%400.1.21/packages/plugins/http-details-extensions/src/index.ts
3
- * Version: 0.1.21
4
- * TODO: Extract to a separate repository/artifact after approach has been validated.
5
- */
6
-
7
- /* eslint-disable */
8
-
9
- const { isAsyncIterable } = require('@envelop/core');
10
- const { getHeadersObj } = require('@graphql-mesh/utils');
11
-
12
- function useIncludeHttpDetailsInExtensions(opts) {
13
- if (!opts.if) {
14
- return {};
15
- }
16
-
17
- const httpDetailsByContext = new WeakMap();
18
-
19
- function getHttpDetailsByContext(context) {
20
- let httpDetails = httpDetailsByContext.get(context);
21
- if (!httpDetails) {
22
- httpDetails = [];
23
- httpDetailsByContext.set(context, httpDetails);
24
- }
25
- return httpDetails;
26
- }
27
-
28
- return {
29
- onFetch({ url, context, info, options }) {
30
- if (context != null) {
31
- const requestTimestamp = Date.now();
32
- return ({ response }) => {
33
- const responseTimestamp = Date.now();
34
- const responseTime = responseTimestamp - requestTimestamp;
35
- const httpDetailsList = getHttpDetailsByContext(context);
36
- const httpDetails = {
37
- sourceName: (info)?.sourceName,
38
- path: info?.path,
39
- request: {
40
- timestamp: requestTimestamp,
41
- url,
42
- method: options.method || 'GET',
43
- headers: getHeadersObj(options.headers),
44
- },
45
- response: {
46
- timestamp: responseTimestamp,
47
- status: response.status,
48
- statusText: response.statusText,
49
- headers: getHeadersObj(response.headers),
50
- // Added to interface to account for edge fetch implementation/behavior
51
- cookies: response.headers.getSetCookie(),
52
- },
53
- responseTime,
54
- };
55
- httpDetailsList.push(httpDetails);
56
- };
57
- }
58
- return undefined;
59
- },
60
- onExecute({ args: { contextValue } }) {
61
- return {
62
- onExecuteDone({ result, setResult }) {
63
- if (!isAsyncIterable(result)) {
64
- const httpDetailsList = httpDetailsByContext.get(contextValue);
65
- if (httpDetailsList != null) {
66
- setResult({
67
- ...result,
68
- extensions: {
69
- ...result.extensions,
70
- httpDetails: httpDetailsList,
71
- },
72
- });
73
- }
74
- }
75
- },
76
- };
77
- },
78
- };
79
- }
80
-
81
- module.exports = useIncludeHttpDetailsInExtensions;
package/src/secrets.js DELETED
@@ -1,34 +0,0 @@
1
- // Parse the yaml secrets string from env to json object
2
- function loadMeshSecrets(logger, secret) {
3
- let parsedSecrets = {};
4
-
5
- try {
6
- // Replace escaped backslashes with a single backslash
7
- secret = secret.replace(/\\"/g, '"');
8
- parsedSecrets = JSON.parse(secret);
9
- } catch (err) {
10
- logger.error('Error parsing secrets.');
11
- }
12
-
13
- return parsedSecrets;
14
- }
15
-
16
- // Custom get secrets handler
17
- const getSecretsHandler = {
18
- get: function (target, prop, receiver) {
19
- if (prop === 'toJSON') {
20
- // Handle the toJSON case
21
- return () => target;
22
- }
23
- if (prop in target) {
24
- return Reflect.get(target, prop, receiver);
25
- } else {
26
- throw new Error(`The secret ${String(prop)} is not available.`);
27
- }
28
- },
29
- set: function () {
30
- throw new Error('Setting secrets is not allowed');
31
- },
32
- };
33
-
34
- module.exports = { loadMeshSecrets, getSecretsHandler };
package/src/served.js DELETED
@@ -1,22 +0,0 @@
1
- /**
2
- * Header to indicate which tier served the request.
3
- */
4
- const SERVE_TIER_HEADER = 'x-api-mesh-served';
5
-
6
- /**
7
- * Tiers that served the request.
8
- */
9
- const ServedTier = {
10
- WORKER_HOT: 0,
11
- };
12
-
13
- /**
14
- * Add the served header to the response. Requires mutable headers on the response object.
15
- * @param response Response.
16
- * @param servedTier Tier that served the request.
17
- */
18
- const addServedHeader = (response, servedTier) => {
19
- response.headers.set(SERVE_TIER_HEADER, servedTier.toString());
20
- };
21
-
22
- module.exports = { ServedTier, addServedHeader };
@@ -1,14 +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
- node_compat = false
5
-
6
- find_additional_modules = true
7
- base_dir = ".mesh"
8
- rules = [
9
- { type = "CommonJS", globs = ["tenantFiles/**/*.js"] }
10
- ]
11
-
12
-
13
- [[migrations]]
14
- tag = "v1"
@@ -1,42 +0,0 @@
1
- const pino = require('pino');
2
-
3
- /**
4
- * Get a new instance of a Pino logger with default configuration.
5
- * @param level Log level.
6
- */
7
- const pinoLogger = level =>
8
- pino({
9
- level: level || 'info',
10
- formatters: {
11
- level(label) {
12
- return {
13
- level: label,
14
- };
15
- },
16
- },
17
- });
18
-
19
- /**
20
- * Get a new instance of a Pino logger with default configuration and child bindings.
21
- * @param bindings Logger bindings.
22
- */
23
- const logger = bindings => {
24
- return pinoLogger(bindings?.logLevel).child({
25
- meshId: bindings?.meshId,
26
- requestId: bindings?.requestId,
27
- });
28
- };
29
-
30
- /**
31
- * Create a logger from environment/request.
32
- * @param bindings Logger bindings.
33
- */
34
- const bindedlogger = bindings => {
35
- return logger({
36
- logLevel: bindings?.logLevel,
37
- meshId: bindings?.meshId,
38
- requestId: bindings?.requestId,
39
- });
40
- };
41
-
42
- module.exports = { logger, pinoLogger, bindedlogger };
@@ -1,26 +0,0 @@
1
- const UUID = require('../uuid');
2
-
3
- /**
4
- * Default request identifier header name.
5
- */
6
- const DEFAULT_REQUEST_ID_HEADER_NAME = 'x-request-id';
7
-
8
- /**
9
- * Get request identifier from headers. Will attempt to set request identifier if not present.
10
- * @param request Request.
11
- * @param headerName Request identifier header name.
12
- */
13
- function getRequestId(request, headerName = DEFAULT_REQUEST_ID_HEADER_NAME) {
14
- let requestId = request.headers.get(headerName);
15
- if (!requestId) {
16
- requestId = UUID.newUuid().toString();
17
- try {
18
- request.headers.set(headerName, requestId);
19
- } catch (err) {
20
- // Unable to set request headers
21
- }
22
- }
23
- return requestId;
24
- }
25
-
26
- module.exports = { DEFAULT_REQUEST_ID_HEADER_NAME, getRequestId };
@@ -1,80 +0,0 @@
1
- import { getMesh } from '@graphql-mesh/runtime';
2
-
3
- const { getCorsOptions } = require('./cors');
4
- const { createYoga } = require('graphql-yoga');
5
- const { GraphQLError } = require('graphql/error');
6
-
7
- const { loadMeshSecrets, getSecretsHandler } = require('./secrets');
8
- const useComplianceHeaders = require('./plugins/complianceHeaders');
9
- const UseHttpDetailsExtensions = require('./plugins/httpDetailsExtensions');
10
- const useSourceHeaders = require('@adobe/plugin-source-headers');
11
- const { useDisableIntrospection } = require('@envelop/disable-introspection');
12
-
13
- let meshInstance$;
14
-
15
- async function buildMeshInstance(meshArtifacts, meshConfig) {
16
- const { getMeshOptions } = meshArtifacts;
17
- const options = await getMeshOptions();
18
-
19
- options.additionalEnvelopPlugins = (options.additionalEnvelopPlugins || []).concat(
20
- useComplianceHeaders(),
21
- UseHttpDetailsExtensions({
22
- // Get the details of responseConfig.includeHTTPDetails and store in Cache
23
- if: meshConfig.responseConfig?.includeHTTPDetails || false,
24
- }),
25
- useSourceHeaders(meshConfig),
26
- );
27
-
28
- if (meshConfig.disableIntrospection) {
29
- options.additionalEnvelopPlugins.push(useDisableIntrospection());
30
- }
31
-
32
- return getMesh(options).then(mesh => {
33
- const id = mesh.pubsub.subscribe('destroy', () => {
34
- meshInstance$ = undefined;
35
- mesh.pubsub.unsubscribe(id);
36
- });
37
- return mesh;
38
- });
39
- }
40
-
41
- async function getBuiltMesh(meshArtifacts, meshConfig) {
42
- if (meshInstance$ == null) {
43
- meshInstance$ = buildMeshInstance(meshArtifacts, meshConfig);
44
- }
45
- return meshInstance$;
46
- }
47
-
48
- const buildServer = async (loggerInstance, env, meshArtifacts, meshConfig) => {
49
- const { Secret: secret } = env;
50
- const tenantMesh = await getBuiltMesh(meshArtifacts, meshConfig);
51
- const meshSecrets = loadMeshSecrets(loggerInstance, secret);
52
- return await buildYogaServer(env, tenantMesh, meshConfig, meshSecrets);
53
- };
54
-
55
- async function buildYogaServer(env, tenantMesh, meshConfig, meshSecrets) {
56
- const secretsProxy = new Proxy(meshSecrets, getSecretsHandler);
57
- return createYoga({
58
- plugins: tenantMesh.plugins,
59
- graphqlEndpoint: `/graphql`,
60
- cors: getCorsOptions(env, meshConfig),
61
- context: initialContext => ({
62
- ...initialContext,
63
- secrets: secretsProxy,
64
- }),
65
- maskedErrors: {
66
- maskError: maskError,
67
- },
68
- logging: 'debug',
69
- });
70
- }
71
-
72
- const maskError = error => {
73
- if (error instanceof GraphQLError && error.extensions?.http?.headers) {
74
- delete error.extensions.http.headers;
75
- }
76
-
77
- return error;
78
- };
79
-
80
- module.exports = { buildServer };