@webdecoy/fastify 0.2.1 → 0.4.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.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
2
- import { ProtectOptions, WebDecoyConfig } from '@webdecoy/node';
3
- export { ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
2
+ import { ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
3
+ export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
4
4
 
5
5
  /**
6
6
  * Web Decoy Fastify Plugin
@@ -64,4 +64,23 @@ declare module 'fastify' {
64
64
  declare function webdecoyPluginImpl(fastify: FastifyInstance, options: WebDecoyConfig & WebDecoyPluginOptions): Promise<void>;
65
65
  declare const webdecoyPlugin: typeof webdecoyPluginImpl;
66
66
 
67
- export { type WebDecoyPluginOptions, webdecoyPlugin as default, webdecoyPlugin };
67
+ /**
68
+ * Fastify captcha endpoints plugin.
69
+ *
70
+ * Registers the WebDecoy captcha routes under a base path. Fastify parses JSON
71
+ * bodies automatically.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import Fastify from 'fastify';
76
+ * import { webdecoyCaptchaPlugin } from '@webdecoy/fastify';
77
+ *
78
+ * const app = Fastify();
79
+ * app.register(webdecoyCaptchaPlugin, { secret: process.env.WEBDECOY_SECRET });
80
+ * ```
81
+ */
82
+
83
+ declare function plugin(fastify: FastifyInstance, options: CaptchaEndpointsOptions): Promise<void>;
84
+ declare const webdecoyCaptchaPlugin: typeof plugin;
85
+
86
+ export { type WebDecoyPluginOptions, webdecoyPlugin as default, webdecoyCaptchaPlugin, webdecoyPlugin };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
2
- import { ProtectOptions, WebDecoyConfig } from '@webdecoy/node';
3
- export { ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
2
+ import { ProtectOptions, WebDecoyConfig, CaptchaEndpointsOptions } from '@webdecoy/node';
3
+ export { CaptchaEndpointsOptions, ProtectResult, RequestMetadata, SDKDetectionResponse, WebDecoyConfig } from '@webdecoy/node';
4
4
 
5
5
  /**
6
6
  * Web Decoy Fastify Plugin
@@ -64,4 +64,23 @@ declare module 'fastify' {
64
64
  declare function webdecoyPluginImpl(fastify: FastifyInstance, options: WebDecoyConfig & WebDecoyPluginOptions): Promise<void>;
65
65
  declare const webdecoyPlugin: typeof webdecoyPluginImpl;
66
66
 
67
- export { type WebDecoyPluginOptions, webdecoyPlugin as default, webdecoyPlugin };
67
+ /**
68
+ * Fastify captcha endpoints plugin.
69
+ *
70
+ * Registers the WebDecoy captcha routes under a base path. Fastify parses JSON
71
+ * bodies automatically.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import Fastify from 'fastify';
76
+ * import { webdecoyCaptchaPlugin } from '@webdecoy/fastify';
77
+ *
78
+ * const app = Fastify();
79
+ * app.register(webdecoyCaptchaPlugin, { secret: process.env.WEBDECOY_SECRET });
80
+ * ```
81
+ */
82
+
83
+ declare function plugin(fastify: FastifyInstance, options: CaptchaEndpointsOptions): Promise<void>;
84
+ declare const webdecoyCaptchaPlugin: typeof plugin;
85
+
86
+ export { type WebDecoyPluginOptions, webdecoyPlugin as default, webdecoyCaptchaPlugin, webdecoyPlugin };
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  default: () => plugin_default,
34
+ webdecoyCaptchaPlugin: () => webdecoyCaptchaPlugin,
34
35
  webdecoyPlugin: () => webdecoyPlugin
35
36
  });
36
37
  module.exports = __toCommonJS(index_exports);
@@ -131,7 +132,42 @@ var webdecoyPlugin = (0, import_fastify_plugin.default)(webdecoyPluginImpl, {
131
132
  name: "@webdecoy/fastify"
132
133
  });
133
134
  var plugin_default = webdecoyPlugin;
135
+
136
+ // src/captcha.ts
137
+ var import_fastify_plugin2 = __toESM(require("fastify-plugin"));
138
+ var import_node2 = require("@webdecoy/node");
139
+ async function plugin(fastify, options) {
140
+ const endpoints = (0, import_node2.createCaptchaEndpoints)(options);
141
+ fastify.route({
142
+ method: ["GET", "POST"],
143
+ url: `${endpoints.basePath}/*`,
144
+ handler: async (request, reply) => {
145
+ const pathname = request.url.split("?")[0];
146
+ const query = request.query ?? {};
147
+ const result = await endpoints.handle({
148
+ method: request.method,
149
+ pathname,
150
+ query,
151
+ headers: request.headers,
152
+ body: request.body,
153
+ ip: request.ip
154
+ });
155
+ if (!result) {
156
+ reply.code(404).send({ error: "not_found" });
157
+ return;
158
+ }
159
+ reply.code(result.status);
160
+ for (const [k, v] of Object.entries(result.headers)) reply.header(k, v);
161
+ reply.send(result.body);
162
+ }
163
+ });
164
+ }
165
+ var webdecoyCaptchaPlugin = (0, import_fastify_plugin2.default)(plugin, {
166
+ fastify: "4.x || 5.x",
167
+ name: "@webdecoy/captcha"
168
+ });
134
169
  // Annotate the CommonJS export names for ESM import in node:
135
170
  0 && (module.exports = {
171
+ webdecoyCaptchaPlugin,
136
172
  webdecoyPlugin
137
173
  });
package/dist/index.mjs CHANGED
@@ -94,7 +94,42 @@ var webdecoyPlugin = fp(webdecoyPluginImpl, {
94
94
  name: "@webdecoy/fastify"
95
95
  });
96
96
  var plugin_default = webdecoyPlugin;
97
+
98
+ // src/captcha.ts
99
+ import fp2 from "fastify-plugin";
100
+ import { createCaptchaEndpoints } from "@webdecoy/node";
101
+ async function plugin(fastify, options) {
102
+ const endpoints = createCaptchaEndpoints(options);
103
+ fastify.route({
104
+ method: ["GET", "POST"],
105
+ url: `${endpoints.basePath}/*`,
106
+ handler: async (request, reply) => {
107
+ const pathname = request.url.split("?")[0];
108
+ const query = request.query ?? {};
109
+ const result = await endpoints.handle({
110
+ method: request.method,
111
+ pathname,
112
+ query,
113
+ headers: request.headers,
114
+ body: request.body,
115
+ ip: request.ip
116
+ });
117
+ if (!result) {
118
+ reply.code(404).send({ error: "not_found" });
119
+ return;
120
+ }
121
+ reply.code(result.status);
122
+ for (const [k, v] of Object.entries(result.headers)) reply.header(k, v);
123
+ reply.send(result.body);
124
+ }
125
+ });
126
+ }
127
+ var webdecoyCaptchaPlugin = fp2(plugin, {
128
+ fastify: "4.x || 5.x",
129
+ name: "@webdecoy/captcha"
130
+ });
97
131
  export {
98
132
  plugin_default as default,
133
+ webdecoyCaptchaPlugin,
99
134
  webdecoyPlugin
100
135
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/fastify",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Web Decoy plugin for Fastify",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "url": "https://github.com/WebDecoy/node-sdk/issues"
41
41
  },
42
42
  "dependencies": {
43
- "@webdecoy/node": "^0.2.1",
43
+ "@webdecoy/node": "^0.4.0",
44
44
  "fastify-plugin": "^4.5.1"
45
45
  },
46
46
  "peerDependencies": {