Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add samples of JS plugins extending or reusing code from other plugins #3

Open
bovino opened this issue Apr 20, 2021 · 6 comments
Open
Labels
documentation Improvements or additions to documentation pending author feedback Waiting for feeback from author

Comments

@bovino
Copy link

bovino commented Apr 20, 2021

Adding samples of JS plugins extending or reusing code from other plugins would be nice to promote the idea of code reuse and extensibility in the same way we see in some of the Lua plugins with ":extend()" from Lua.

Considering that the JS plugins probably will not be able to extend the Kong core plugins (given they are written in Lua) , at least promoting code reuse and extensibility between the JS plugins would be a welcome idea.

@fffonion fffonion added the documentation Improvements or additions to documentation label Apr 21, 2021
@fffonion
Copy link
Contributor

@bovino I guess that's a generic question on how to reuse code in javascript. Is there a specific use case you looking for?

@bovino
Copy link
Author

bovino commented Apr 27, 2021

i would like to see plugin samples available showing how to perform code reuse beetweb two custom JS plugins... or better yet, samples showing a similar capability we have in Lua where one plugin can directly extend another (not sure if this can be done with JS plugins)

if this helps, i can describe some "specific" scenario as follows:

JS plugin 1 - a basic validation plugin (supports validation only on header field and path variables)
JS plugin 2 - the "advanced" or "extended" version of the basic validation plugin, that extends the parent plugin and add a few more validation capabilities (allows you to apply validation on query params and body content)

i can think of some better scenarios if this is not good enough as a starting point :-)

thanks for your work

fffonion pushed a commit that referenced this issue Aug 4, 2021
* Create node.js.yml

* Create dependabot.yml

* Delete .github/workflows directory

* Update dependabot.yml

* chore(deps): bump ts-node from 9.1.1 to 10.1.0 (#1)

Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 9.1.1 to 10.1.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](TypeStrong/ts-node@v9.1.1...v10.1.0)

---
updated-dependencies:
- dependency-name: ts-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump commander from 7.1.0 to 8.0.0 (#2)

Bumps [commander](https://github.com/tj/commander.js) from 7.1.0 to 8.0.0.
- [Release notes](https://github.com/tj/commander.js/releases)
- [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md)
- [Commits](tj/commander.js@v7.1.0...v8.0.0)

---
updated-dependencies:
- dependency-name: commander
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump node-color-log from 5.2.0 to 5.3.1 (#3)

Bumps [node-color-log](https://github.com/tigercosmos/node-color-log) from 5.2.0 to 5.3.1.
- [Release notes](https://github.com/tigercosmos/node-color-log/releases)
- [Commits](tigercosmos/node-color-log@5.2.0...5.3.1)

---
updated-dependencies:
- dependency-name: node-color-log
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump jest from 26.6.3 to 27.0.6 in /examples (#6)

Bumps [jest](https://github.com/facebook/jest) from 26.6.3 to 27.0.6.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](jestjs/jest@v26.6.3...v27.0.6)

---
updated-dependencies:
- dependency-name: jest
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump typescript from 4.2.4 to 4.3.5 (#5)

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.2.4 to 4.3.5.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](microsoft/TypeScript@v4.2.4...v4.3.5)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump @types/node from 14.14.32 to 16.4.1 (#7)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.32 to 16.4.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump jest from 26.6.3 to 27.0.6 (#4)

Bumps [jest](https://github.com/facebook/jest) from 26.6.3 to 27.0.6.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](jestjs/jest@v26.6.3...v27.0.6)

---
updated-dependencies:
- dependency-name: jest
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update .babelrc

* Create node.js.yml

* Update package.json

* Update node.js.yml

* Update plugin_test.js

* Update plugin_test.js

* Update package.json

* Update plugin_test.js

* update packages

* Update node.js.yml

* Update node.js.yml

* Update node.js.yml

* Update node.js.yml

* Update node.js.yml

* Update node.js.yml

* Update node.js.yml

* chore(deps-dev): bump @babel/preset-env from 7.14.8 to 7.14.9 (#14)

Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.14.8 to 7.14.9.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.14.9/packages/babel-preset-env)

---
updated-dependencies:
- dependency-name: "@babel/preset-env"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump @types/node from 16.4.1 to 16.4.10 (#13)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.4.1 to 16.4.10.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump commander from 8.0.0 to 8.1.0 (#10)

Bumps [commander](https://github.com/tj/commander.js) from 8.0.0 to 8.1.0.
- [Release notes](https://github.com/tj/commander.js/releases)
- [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md)
- [Commits](tj/commander.js@v8.0.0...v8.1.0)

---
updated-dependencies:
- dependency-name: commander
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update dependabot.yml

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@esatterwhite
Copy link
Contributor

this is pretty easy to do if following the plugin conventions in the examples. The only thing to work around really is name collisions.

'use strict'

// Extending local a plugin

const {Plugin: LocalPlugin, Schema: LocalSchema} = require('./local-plugin')
const {version: Version} = require('./package.json')

class Plugin extends LocalPlugin {
  constructor(config) {
    super(config)
    // other setup code
  }

  async access(kong) {
    // logic
    // logic
    return super.access(kong)
  }
}

module.exports = {
  Plugin
, Version
, Priority: 0
, Schema: [
    ...LocalSchema
  , {foo: {type: 'string'}}
  ]
}

'use strict'

// Extending a plugin from npm package

const {Plugin: KongPlugin, Schema: KongSchema} = require('@myorg/kong-plugin')
const {version: Version} = require('./package.json')

class Plugin extends KongPlugin {
  constructor(config) {
    super(config)
    // other setup code
  }

  async access(kong) {
    // logic
    // logic
    return super.access(kong)
  }
}

module.exports = {
  Plugin
, Version
, Priority: 0
, Schema: [
    ...KongSchema
  , {foo: {type: 'string'}}
  ]
}

@hanshuebner
Copy link
Contributor

We don't currently have plans to add these types of examples to our documentation, but feel free to open a PR if you have specific suggestions.

@hanshuebner hanshuebner added the pending author feedback Waiting for feeback from author label Sep 18, 2023
@esatterwhite
Copy link
Contributor

esatterwhite commented Sep 18, 2023

Is this project being abandoned?

@hanshuebner
Copy link
Contributor

Is this project being abandoned?

We don't currently have plans to add these specific documentation enhancements, but we also don't plan to abandon this project. As per my review of yesterday, it seems that there are a couple of outstanding documentation items as well as enhancements that could be made. At this point, though, we don't have customers asking for these enhancements. We would certainly be interested in contributions in that regard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation pending author feedback Waiting for feeback from author
Projects
None yet
Development

No branches or pull requests

4 participants