@webiny/handler-client 0.0.0-mt-1

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.
@@ -0,0 +1,8 @@
1
+ import { Context } from "@webiny/handler/types";
2
+ import { HandlerClientPlugin, InvokeArgs } from "./types";
3
+ declare class HandlerClient {
4
+ plugin: HandlerClientPlugin;
5
+ constructor(context: Context);
6
+ invoke<TInvokeArgsPayload = any, TResponse = any>(params: InvokeArgs<TInvokeArgsPayload>): Promise<TResponse>;
7
+ }
8
+ export default HandlerClient;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ class HandlerClient {
15
+ constructor(context) {
16
+ (0, _defineProperty2.default)(this, "plugin", void 0);
17
+ this.plugin = context.plugins.byName("handler-client");
18
+
19
+ if (!this.plugin) {
20
+ // If not specified, use a fallback plugin that fetches different handlers via plugins.
21
+ // This might also be useful for testing purposes.
22
+ this.plugin = {
23
+ type: "handler-client",
24
+ name: "handler-client",
25
+
26
+ async invoke({
27
+ name,
28
+ payload,
29
+ await: useAwait
30
+ }) {
31
+ const plugin = context.plugins.byName(name);
32
+
33
+ if (!plugin) {
34
+ throw new _error.default(`Could not find "${name}" handler plugin.`);
35
+ }
36
+
37
+ const promise = plugin.invoke(payload);
38
+
39
+ if (useAwait === false) {
40
+ return null;
41
+ }
42
+
43
+ return promise;
44
+ }
45
+
46
+ };
47
+ }
48
+ }
49
+
50
+ invoke(params) {
51
+ try {
52
+ return this.plugin.invoke(params);
53
+ } catch (e) {
54
+ throw new _error.default(`An error occurred while trying to invoke another handler with the following params: ${JSON.stringify(params, null, 2)}`);
55
+ }
56
+ }
57
+
58
+ }
59
+
60
+ var _default = HandlerClient;
61
+ exports.default = _default;
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
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.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @webiny/handler-client
2
+ [![](https://img.shields.io/npm/dw/@webiny/handler-client.svg)](https://www.npmjs.com/package/@webiny/handler-client)
3
+ [![](https://img.shields.io/npm/v/@webiny/handler-client.svg)](https://www.npmjs.com/package/@webiny/handler-client)
4
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
+
7
+ The base package for building Webiny and React powered web apps.
8
+
9
+ For more information, please visit [the official docs](https://docs.webiny.com/docs/webiny/introduction).
10
+
11
+ ## Install
12
+ ```
13
+ npm install --save @webiny/handler-client
14
+ ```
15
+
16
+ Or if you prefer yarn:
17
+ ```
18
+ yarn add @webiny/handler-client
19
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Context } from "@webiny/handler/types";
2
+ declare const _default: () => {
3
+ type: string;
4
+ apply(context: Context): void;
5
+ };
6
+ export default _default;
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _HandlerClient = _interopRequireDefault(require("./HandlerClient"));
11
+
12
+ var _default = () => ({
13
+ type: "context",
14
+
15
+ apply(context) {
16
+ context.handlerClient = new _HandlerClient.default(context);
17
+ }
18
+
19
+ });
20
+
21
+ exports.default = _default;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@webiny/handler-client",
3
+ "version": "0.0.0-mt-1",
4
+ "main": "index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "description": "A package that contains plugins for developing Webiny API in the AWS cloud.",
10
+ "contributors": [
11
+ "Pavel Denisjuk <pavel@webiny.com>",
12
+ "Sven Al Hamad <sven@webiny.com>",
13
+ "Adrian Smijulj <adrian@webiny.com>"
14
+ ],
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@babel/runtime": "7.15.4",
18
+ "@webiny/error": "0.0.0-mt-1",
19
+ "@webiny/handler": "0.0.0-mt-1",
20
+ "@webiny/plugins": "0.0.0-mt-1"
21
+ },
22
+ "devDependencies": {
23
+ "@babel/cli": "^7.5.5",
24
+ "@babel/core": "^7.5.5",
25
+ "@babel/preset-env": "^7.5.5",
26
+ "@babel/preset-typescript": "^7.8.3",
27
+ "@webiny/cli": "^0.0.0-mt-1",
28
+ "@webiny/project-utils": "^0.0.0-mt-1",
29
+ "babel-plugin-lodash": "^3.3.4",
30
+ "jest": "^26.6.3",
31
+ "merge": "^1.2.1",
32
+ "rimraf": "^3.0.2",
33
+ "typescript": "^4.1.3"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "directory": "dist"
38
+ },
39
+ "scripts": {
40
+ "build": "yarn webiny run build",
41
+ "watch": "yarn webiny run watch"
42
+ },
43
+ "gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
44
+ }
package/types.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import HandlerClient from "./HandlerClient";
2
+ import { Plugin } from "@webiny/plugins/types";
3
+ export declare type InvokeArgs<TInvokeArgsPayload = any> = {
4
+ name: string;
5
+ payload?: TInvokeArgsPayload;
6
+ await?: boolean;
7
+ };
8
+ export declare type HandlerClientPlugin = Plugin & {
9
+ type: "handler-client";
10
+ name: "handler-client";
11
+ invoke: <TInvokeArgsPayload = Record<string, any>>(params: InvokeArgs<TInvokeArgsPayload>) => any;
12
+ };
13
+ export declare type HandlerClientHandlerPlugin = Plugin & {
14
+ type: "handler-client-handler";
15
+ invoke: <TArgs = Record<string, any>, TResponse = Record<string, any>>(params: TArgs) => TResponse | Promise<TResponse>;
16
+ };
17
+ export declare type ClientContext = {
18
+ handlerClient: HandlerClient;
19
+ };
package/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });