From 7dd8b5ba7aa2d6224e048c97bd174de1bd60b8f1 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Tue, 10 Dec 2024 13:15:30 +0800 Subject: [PATCH 1/2] fix: ACNA-3397 - web action does not have web in the url, resulting in an invalid link --- README.md | 292 ++++++++----------- docs/readme_template.md | 2 +- jest.config.js | 25 ++ package.json | 39 +-- src/deploy-actions.js | 2 +- src/utils.js | 149 +++++----- test/__fixtures__/deploy/basic_manifest.json | 12 +- test/utils.test.js | 50 +--- types.d.ts | 271 +++++++++-------- 9 files changed, 390 insertions(+), 452 deletions(-) create mode 100644 jest.config.js diff --git a/README.md b/README.md index ba62af5..d012695 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,63 @@ - - -# Adobe I/O Runtime Lib - -[![Version](https://img.shields.io/npm/v/@adobe/aio-lib-runtime.svg)](https://npmjs.org/package/@adobe/aio-lib-runtime) -[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-runtime.svg)](https://npmjs.org/package/@adobe/aio-lib-runtime) -![Node.js CI](https://github.com/adobe/aio-lib-runtime/workflows/Node.js%20CI/badge.svg) -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) -[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-runtime/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-runtime/) - -## Installing - -```bash -npm install @adobe/aio-lib-runtime -``` - -## Usage - -1) Initialize the SDK - - ```javascript - const sdk = require('@adobe/aio-lib-runtime') - - async function sdkTest() { - //initialize sdk. Takes in OpenwhiskOptions - const client = await sdk.init({ apihost: 'https://adobeioruntime.net', api_key: 'your_auth_key', namespace: 'your_runtime_namespace' }) - } - ``` - -2) Call methods using the initialized SDK - - ```javascript - const sdk = require('@adobe/aio-lib-runtime') - - async function sdkTest() { - //initialize sdk. Takes in OpenwhiskOptions - const client = await sdk.init({ apihost: 'https://adobeioruntime.net', api_key: 'your_auth_key', namespace: 'your_runtime_namespace' }) - - // call methods - try { - // get... something - const result = await client.getSomething({}) - console.log(result) - - } catch (e) { - console.error(e) - } - } - ``` - + + +# Adobe I/O Runtime Lib + +[![Version](https://img.shields.io/npm/v/@adobe/aio-lib-runtime.svg)](https://npmjs.org/package/@adobe/aio-lib-runtime) +[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-runtime.svg)](https://npmjs.org/package/@adobe/aio-lib-runtime) +![Node.js CI](https://github.com/adobe/aio-lib-runtime/workflows/Node.js%20CI/badge.svg) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-runtime/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-runtime/) + +## Installing + +```bash +npm install @adobe/aio-lib-runtime +``` + +## Usage + +1) Initialize the SDK + + ```javascript + const sdk = require('@adobe/aio-lib-runtime') + + async function sdkTest() { + //initialize sdk. Takes in OpenwhiskOptions + const client = await sdk.init({ apihost: 'https://adobeioruntime.net', api_key: 'your_auth_key', namespace: 'your_runtime_namespace' }) + } + ``` + +2) Call methods using the initialized SDK + + ```javascript + const sdk = require('@adobe/aio-lib-runtime') + + async function sdkTest() { + //initialize sdk. Takes in OpenwhiskOptions + const client = await sdk.init({ apihost: 'https://adobeioruntime.net', api_key: 'your_auth_key', namespace: 'your_runtime_namespace' }) + + // call methods + try { + // get... something + const result = await client.getSomething({}) + console.log(result) + + } catch (e) { + console.error(e) + } + } + ``` + ## Classes
@@ -192,9 +192,6 @@ See createSequenceObject(fullName, manifestSequence, packageName)OpenWhiskEntitiesAction

Create a sequence object that is compatible with the OpenWhisk API from a parsed manifest object

-
checkWebFlags(flag)object
-

Check the web flags

-
createActionObject(fullName, manifestAction)OpenWhiskEntitiesAction

Create an action object compatible with the OpenWhisk API from an action object parsed from the manifest.

@@ -491,9 +488,7 @@ Get destination settings ## RuntimeAPI -This class provides methods to call your RuntimeAPI APIs. -Before calling any method initialize the instance by calling the `init` method on it -with valid options argument +This class provides methods to call your RuntimeAPI APIs. Before calling any method initialize the instance by calling the `init` method on it with valid options argument **Kind**: global class @@ -550,8 +545,7 @@ Deletes a trigger and associated feeds ## getWebpackConfigPath(actionPath, root) ⇒ Promise.<string> -Searches for a webpack config file, starting at the action path and working - towards the root of the project. Will return the first one it finds. +Searches for a webpack config file, starting at the action path and working towards the root of the project. Will return the first one it finds. **Kind**: global function **Returns**: Promise.<string> - Webpack config file path, will be 'null' if not found @@ -564,8 +558,7 @@ Searches for a webpack config file, starting at the action path and working ## loadWebpackConfig(configPath, actionPath, tempBuildDir, outBuildFilename) ⇒ Promise.<object> -Loads a Webpack config file from the config path provided. Sets fields required - for Runtime actions. Returns an object that can be passed to the Webpack library. +Loads a Webpack config file from the config path provided. Sets fields required for Runtime actions. Returns an object that can be passed to the Webpack library. **Kind**: global function **Returns**: Promise.<object> - Webpack config, can be passed to the Webpack library @@ -594,9 +587,7 @@ Will return data about an action ready to be built. ## zipActions(buildsList, lastBuildsPath, distFolder) ⇒ Array.<string> -Will zip actions. - By default only actions which were not built before will be zipped. - Last built actions data will be used to validate which action needs zipping. +Will zip actions. By default only actions which were not built before will be zipped. Last built actions data will be used to validate which action needs zipping. **Kind**: global function **Returns**: Array.<string> - Array of zipped actions. @@ -615,21 +606,21 @@ runs the command **Kind**: global function **Returns**: Promise.<object> - deployedEntities -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| config | object | | app config | -| [deployConfig] | object | {} | deployment config | -| [deployConfig.isLocalDev] | boolean | | local dev flag // todo: remove | -| [deployConfig.filterEntities] | object | | add filters to deploy only specified OpenWhisk entities | -| [deployConfig.filterEntities.actions] | Array | | filter list of actions to deploy by provided array, e.g. ['name1', ..] | -| [deployConfig.filterEntities.byBuiltActions] | boolean | | if true, trim actions from the manifest based on the already built actions | -| [deployConfig.filterEntities.sequences] | Array | | filter list of sequences to deploy, e.g. ['name1', ..] | -| [deployConfig.filterEntities.triggers] | Array | | filter list of triggers to deploy, e.g. ['name1', ..] | -| [deployConfig.filterEntities.rules] | Array | | filter list of rules to deploy, e.g. ['name1', ..] | -| [deployConfig.filterEntities.apis] | Array | | filter list of apis to deploy, e.g. ['name1', ..] | -| [deployConfig.filterEntities.dependencies] | Array | | filter list of package dependencies to deploy, e.g. ['name1', ..] | -| [deployConfig.useForce] | boolean | | force deploy of actions | -| [logFunc] | object | | custom logger function | +| Param | Type | Description | +| --- | --- | --- | +| config | object | app config | +| [deployConfig] | object | deployment config | +| [deployConfig.isLocalDev] | boolean | local dev flag // todo: remove | +| [deployConfig.filterEntities] | object | add filters to deploy only specified OpenWhisk entities | +| [deployConfig.filterEntities.actions] | Array | filter list of actions to deploy by provided array, e.g. ['name1', ..] | +| [deployConfig.filterEntities.byBuiltActions] | boolean | if true, trim actions from the manifest based on the already built actions | +| [deployConfig.filterEntities.sequences] | Array | filter list of sequences to deploy, e.g. ['name1', ..] | +| [deployConfig.filterEntities.triggers] | Array | filter list of triggers to deploy, e.g. ['name1', ..] | +| [deployConfig.filterEntities.rules] | Array | filter list of rules to deploy, e.g. ['name1', ..] | +| [deployConfig.filterEntities.apis] | Array | filter list of apis to deploy, e.g. ['name1', ..] | +| [deployConfig.filterEntities.dependencies] | Array | filter list of package dependencies to deploy, e.g. ['name1', ..] | +| [deployConfig.useForce] | boolean | force deploy of actions | +| [logFunc] | object | custom logger function | @@ -812,8 +803,7 @@ Print logs ## getActionEntryFile(pkgJsonPath) ⇒ string -returns path to main function as defined in package.json OR default of index.js -note: file MUST exist, caller's responsibility, this method will throw if it does not exist +returns path to main function as defined in package.json OR default of index.js note: file MUST exist, caller's responsibility, this method will throw if it does not exist **Kind**: global function **Returns**: string - path to the entry file @@ -1073,8 +1063,7 @@ Get the annotations for an action ## createApiRoutes(pkg, pkgName, apiName, allowedActions, allowedSequences, pathOnly) ⇒ [Array.<OpenWhiskEntitiesRoute>](#OpenWhiskEntitiesRoute) -Creates an array of route definitions from the given manifest-based package. -See https://github.com/apache/openwhisk-wskdeploy/blob/master/parsers/manifest_parser.go#L1187 +Creates an array of route definitions from the given manifest-based package. See https://github.com/apache/openwhisk-wskdeploy/blob/master/parsers/manifest_parser.go#L1187 **Kind**: global function **Returns**: [Array.<OpenWhiskEntitiesRoute>](#OpenWhiskEntitiesRoute) - the array of route entities @@ -1102,18 +1091,6 @@ Create a sequence object that is compatible with the OpenWhisk API from a parsed | manifestSequence | [ManifestSequence](#ManifestSequence) | a sequence object as defined in a valid manifest file | | packageName | string | the package name of the sequence, which will be set to for actions in the sequence | - - -## checkWebFlags(flag) ⇒ object -Check the web flags - -**Kind**: global function -**Returns**: object - object with the appropriate web flags for an action - -| Param | Type | Description | -| --- | --- | --- | -| flag | string \| boolean | the flag to check | - ## createActionObject(fullName, manifestAction) ⇒ [OpenWhiskEntitiesAction](#OpenWhiskEntitiesAction) @@ -1142,7 +1119,7 @@ Process the manifest and deployment content and returns deployment entities. | deploymentTriggers | object | | the deployment triggers | | params | object | | the package params | | [namesOnly] | boolean | false | if false, set the namespaces as well | -| [owOptions] | object | {} | additional OpenWhisk options | +| [owOptions] | object | | additional OpenWhisk options | @@ -1173,8 +1150,7 @@ Deploy all processed entities: can deploy packages, actions, triggers, rules and ## undeployPackage(entities, ow, logger) -Undeploy all processed entities: can undeploy packages, actions, triggers, rules and apis. -Entity definitions do not need to be complete, only the names are needed for un-deployment. +Undeploy all processed entities: can undeploy packages, actions, triggers, rules and apis. Entity definitions do not need to be complete, only the names are needed for un-deployment. **Kind**: global function @@ -1187,12 +1163,7 @@ Entity definitions do not need to be complete, only the names are needed for un- ## syncProject(projectName, manifestPath, manifestContent, entities, ow, logger, imsOrgId, deleteEntities) -Sync a project. This is a higher level function that can be used to sync a local -manifest with deployed entities. - -`syncProject` doesn't only deploy entities it might also undeploy entities that are not -defined in the manifest. This behavior can be disabled via the `deleteEntities` boolean -parameter. +Sync a project. This is a higher level function that can be used to sync a local manifest with deployed entities. `syncProject` doesn't only deploy entities it might also undeploy entities that are not defined in the manifest. This behavior can be disabled via the `deleteEntities` boolean parameter. **Kind**: global function @@ -1210,13 +1181,7 @@ parameter. ## getProjectEntities(project, isProjectHash, ow) ⇒ [Promise.<OpenWhiskEntities>](#OpenWhiskEntities) -Get deployed entities for a managed project. This methods retrieves all the deployed -entities for a given project name or project hash. This only works if the project was -deployed using the `whisk-managed` annotation. This annotation can be set -pre-deployement using `[addManagedProjectAnnotations](#addmanagedprojectannotations)`. - -Note that returned apis will always be empty as they don't support annotations and -hence are not managed as part of a project. +Get deployed entities for a managed project. This methods retrieves all the deployed entities for a given project name or project hash. This only works if the project was deployed using the `whisk-managed` annotation. This annotation can be set pre-deployement using `[addManagedProjectAnnotations](#addmanagedprojectannotations)`. Note that returned apis will always be empty as they don't support annotations and hence are not managed as part of a project. **Kind**: global function **Returns**: [Promise.<OpenWhiskEntities>](#OpenWhiskEntities) - the deployed project entities @@ -1230,8 +1195,7 @@ hence are not managed as part of a project. ## addManagedProjectAnnotations(entities, manifestPath, projectName, projectHash) -Add the `whisk-managed` annotation to processed entities. This is needed for syncing -managed projects. +Add the `whisk-managed` annotation to processed entities. This is needed for syncing managed projects. **Kind**: global function @@ -1245,8 +1209,7 @@ managed projects. ## getProjectHash(manifestContent) ⇒ string -Compute the project hash based on the manifest content string. This is used -for syncing managed projects. +Compute the project hash based on the manifest content string. This is used for syncing managed projects. **Kind**: global function **Returns**: string - the project hash @@ -1520,8 +1483,7 @@ Gets a list of the supported runtime kinds from the apihost. ## ManifestPackages : [Array.<ManifestPackage>](#ManifestPackage) -The entry point to the information read from the manifest, this can be extracted using -[setPaths](#setpaths). +The entry point to the information read from the manifest, this can be extracted using [setPaths](#setpaths). **Kind**: global typedef @@ -1560,7 +1522,6 @@ The manifest action definition | [inputs] | object | the list of action default parameters | | [limits] | Array.<object> | limits for the action | | [web] | string | indicate if an action should be exported as web, can take the value of: true | false | yes | no | raw | -| [web-export] | string | same as web | | [raw-http] | boolean | indicate if an action should be exported as raw web action, this option is only valid if `web` or `web-export` is set to true | | [docker] | string | the docker container to run the action into | | [annotations] | Array.<object> | the manifest action annotations | @@ -1579,8 +1540,7 @@ The manifest action definition ## ManifestSequence : object -The manifest sequence definition -TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specification/html/spec_sequences.md +The manifest sequence definition TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specification/html/spec_sequences.md **Kind**: global typedef **Properties** @@ -1592,8 +1552,7 @@ TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specificatio ## ManifestTrigger : object -The manifest trigger definition -TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specification/html/spec_triggers.md +The manifest trigger definition TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specification/html/spec_triggers.md **Kind**: global typedef **Properties** @@ -1607,8 +1566,7 @@ TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specificatio ## ManifestRule : object -The manifest rule definition -TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specification/html/spec_rules.md +The manifest rule definition TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specification/html/spec_rules.md **Kind**: global typedef **Properties** @@ -1621,8 +1579,7 @@ TODO: see https://github.com/apache/openwhisk-wskdeploy/blob/master/specificatio ## ManifestDependency : object -The manifest dependency definition -TODO +The manifest dependency definition TODO **Kind**: global typedef **Properties** @@ -1635,8 +1592,7 @@ TODO ## OpenWhiskEntities : object -The OpenWhisk entities definitions, which are compatible with the `openwhisk` node -client module. Can be obtained using (processpackage)[#processpackage] (with `onlyNames=true` for un-deployment) +The OpenWhisk entities definitions, which are compatible with the `openwhisk` node client module. Can be obtained using (processpackage)[#processpackage] (with `onlyNames=true` for un-deployment) **Kind**: global typedef **Properties** @@ -1669,8 +1625,7 @@ The api entity definition ## OpenWhiskEntitiesAction : object -The action entity definition -TODO +The action entity definition TODO **Kind**: global typedef **Properties** @@ -1684,8 +1639,7 @@ TODO ## OpenWhiskEntitiesRule : object -The rule entity definition -TODO +The rule entity definition TODO **Kind**: global typedef **Properties** @@ -1698,8 +1652,7 @@ TODO ## OpenWhiskEntitiesTrigger : object -The trigger entity definition -TODO +The trigger entity definition TODO **Kind**: global typedef **Properties** @@ -1713,8 +1666,7 @@ TODO ## OpenWhiskEntitiesPackage : object -The package entity definition -TODO +The package entity definition TODO **Kind**: global typedef **Properties** @@ -1727,9 +1679,7 @@ TODO ## DeploymentPackages : Array.<object> -The entry point to the information read from the deployment file, this can be extracted using -[setPaths](#setpaths). -TODO +The entry point to the information read from the deployment file, this can be extracted using [setPaths](#setpaths). TODO **Kind**: global typedef @@ -1747,26 +1697,26 @@ TODO | manifestContent | object | Parsed manifest object | | projectName | string | Name of the project | -## Insecure Connection - -```bash -NODE_TLS_REJECT_UNAUTHORIZED=0 -``` - -Prepend the `NODE_TLS_REJECT_UNAUTHORIZED` [environment variable](https://nodejs.org/api/cli.html#node_tls_reject_unauthorizedvalue) and `0` value to the call that invokes your function, on the command line. This will ignore any certificate errors when connecting to the Openwhisk server. Usage of this is not recommended, but may be necessary in certain corporate environments. - -## Debug Logs - -```bash -LOG_LEVEL=debug -``` - -Prepend the `LOG_LEVEL` environment variable and `debug` value to the call that invokes your function, on the command line. This should output a lot of debug data for your SDK calls. - -## Contributing - -Contributions are welcome! Read the [Contributing Guide](./.github/CONTRIBUTING.md) for more information. - -## Licensing - -This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information. +## Insecure Connection + +```bash +NODE_TLS_REJECT_UNAUTHORIZED=0 +``` + +Prepend the `NODE_TLS_REJECT_UNAUTHORIZED` [environment variable](https://nodejs.org/api/cli.html#node_tls_reject_unauthorizedvalue) and `0` value to the call that invokes your function, on the command line. This will ignore any certificate errors when connecting to the Openwhisk server. Usage of this is not recommended, but may be necessary in certain corporate environments. + +## Debug Logs + +```bash +LOG_LEVEL=debug +``` + +Prepend the `LOG_LEVEL` environment variable and `debug` value to the call that invokes your function, on the command line. This should output a lot of debug data for your SDK calls. + +## Contributing + +Contributions are welcome! Read the [Contributing Guide](./.github/CONTRIBUTING.md) for more information. + +## Licensing + +This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information. diff --git a/docs/readme_template.md b/docs/readme_template.md index 797de69..2c50c1f 100644 --- a/docs/readme_template.md +++ b/docs/readme_template.md @@ -1,5 +1,5 @@