@remindr/backend 1.0.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/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # remindr backend
2
+
3
+ ## Mandatory environment secrets / variables
4
+
5
+ The user must provide a `.env` in the root level of the project setting containing the following keys:
6
+
7
+ - N8N_BASE_URL
8
+ - N8N_API_KEY
9
+ - N8N_TABLE_ID
10
+ - PIN_CODE
11
+ - PORT
12
+ - APP_PUBLIC_URL
13
+ - APP_DEV_URL
14
+
15
+ ## API / Endpoints
16
+
17
+ - `GET /api/healthy`
18
+ - `POST /api/auth`
19
+ - `GET /api/items`
20
+ - `POST /api/items`
21
+ - `PATHC /api/items/<ID>`
22
+ - `DELETE /api/items/<ID>`
23
+
24
+ ## Example
25
+
26
+ ```ts
27
+ import { createRemindrApp } from '@remindr/backend'
28
+
29
+ interface RawDatabaseRow {
30
+ internal_id: string
31
+ label: string
32
+ checked: boolean
33
+ }
34
+
35
+ const app = createRemindrApp<RawDatabaseRow>({
36
+ clientPath: '../client/dist',
37
+ matchKey: 'internal_id',
38
+ mapItemToRow: (item) => ({
39
+ internal_id: item.id,
40
+ label: item.label,
41
+ checked: item.checked,
42
+ }),
43
+ })
44
+
45
+ app.listen(3001)
46
+ ````
package/dist/index.cjs ADDED
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ createRemindrApp: () => createRemindrApp
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/createApp.ts
38
+ var import_express3 = __toESM(require("express"), 1);
39
+ var import_cors = __toESM(require("cors"), 1);
40
+ var import_node_path = __toESM(require("path"), 1);
41
+
42
+ // src/routes/items.ts
43
+ var import_express = require("express");
44
+
45
+ // src/env.ts
46
+ var import_dotenv = __toESM(require("dotenv"), 1);
47
+ import_dotenv.default.config();
48
+ var env = {
49
+ n8nBaseUrl: required("N8N_BASE_URL"),
50
+ n8nApiKey: required("N8N_API_KEY"),
51
+ n8nTableId: required("N8N_TABLE_ID"),
52
+ pinCode: required("PIN_CODE")
53
+ };
54
+ function required(name) {
55
+ const value = process.env[name];
56
+ if (!value) {
57
+ throw new Error(`Missing env variable: ${name}`);
58
+ }
59
+ return value;
60
+ }
61
+
62
+ // src/n8n.ts
63
+ var n8nHeaders = {
64
+ Accept: "application/json",
65
+ "Content-Type": "application/json",
66
+ "X-N8N-API-KEY": env.n8nApiKey
67
+ };
68
+ var n8nRowsUrl = `${env.n8nBaseUrl}/api/v1/data-tables/${env.n8nTableId}/rows`;
69
+
70
+ // src/routes/items.ts
71
+ function createItemsRouter(mapItemToRow, matchKey = "id") {
72
+ const router = (0, import_express.Router)();
73
+ router.get("/", async (_req, res) => {
74
+ const response = await fetch(n8nRowsUrl, {
75
+ headers: n8nHeaders
76
+ });
77
+ const data = await response.json();
78
+ res.status(response.status).json(data);
79
+ });
80
+ router.post("/", async (req, res) => {
81
+ const { body } = req;
82
+ const response = await fetch(n8nRowsUrl, {
83
+ method: "POST",
84
+ headers: n8nHeaders,
85
+ body: JSON.stringify({
86
+ data: [
87
+ mapItemToRow({
88
+ id: body.id,
89
+ label: body.label,
90
+ checked: false
91
+ })
92
+ ]
93
+ })
94
+ });
95
+ const data = await response.json();
96
+ res.status(response.status).json(data);
97
+ });
98
+ router.patch("/:id", async (req, res) => {
99
+ const { body } = req;
100
+ const response = await fetch(`${n8nRowsUrl}/update`, {
101
+ method: "PATCH",
102
+ headers: n8nHeaders,
103
+ body: JSON.stringify({
104
+ filter: {
105
+ type: "and",
106
+ filters: [
107
+ {
108
+ columnName: matchKey,
109
+ condition: "eq",
110
+ value: req.params.id
111
+ }
112
+ ]
113
+ },
114
+ data: {
115
+ checked: body.checked
116
+ }
117
+ })
118
+ });
119
+ const data = await response.json();
120
+ res.status(response.status).json(data);
121
+ });
122
+ router.delete("/:id", async (req, res) => {
123
+ const filter = {
124
+ type: "and",
125
+ filters: [
126
+ {
127
+ columnName: matchKey,
128
+ condition: "eq",
129
+ value: req.params.id
130
+ }
131
+ ]
132
+ };
133
+ const params = new URLSearchParams({
134
+ filter: JSON.stringify(filter)
135
+ });
136
+ const response = await fetch(`${n8nRowsUrl}/delete?${params}`, {
137
+ method: "DELETE",
138
+ headers: {
139
+ Accept: "application/json",
140
+ "X-N8N-API-KEY": n8nHeaders["X-N8N-API-KEY"]
141
+ }
142
+ });
143
+ const data = await response.json();
144
+ res.status(response.status).json(data);
145
+ });
146
+ return router;
147
+ }
148
+
149
+ // src/routes/auth.ts
150
+ var import_express2 = require("express");
151
+ var authRouter = (0, import_express2.Router)();
152
+ authRouter.post("/", async (req, res) => {
153
+ const { body } = req;
154
+ const authCheck = body.pinCode === env.pinCode;
155
+ res.status(200).json({ authCheck });
156
+ });
157
+
158
+ // src/createApp.ts
159
+ function createRemindrApp(options) {
160
+ const app = (0, import_express3.default)();
161
+ app.use(import_express3.default.json());
162
+ app.use((0, import_cors.default)({
163
+ origin: [
164
+ process.env.APP_DEV_URL ?? "",
165
+ process.env.APP_PUBLIC_URL ?? ""
166
+ ]
167
+ }));
168
+ app.get("/api/health", (_req, res) => {
169
+ res.json({ ok: true });
170
+ });
171
+ app.use("/api/items", createItemsRouter(options.mapItemToRow, options.matchKey ?? "id"));
172
+ app.use("/api/auth", authRouter);
173
+ const isProduction = process.env.NODE_ENV === "production";
174
+ if (isProduction) {
175
+ const frontendDistPath = import_node_path.default.resolve(process.cwd(), options.clientPath);
176
+ app.use(import_express3.default.static(frontendDistPath));
177
+ app.get("*", (_req, res) => {
178
+ res.sendFile(import_node_path.default.join(frontendDistPath, "index.html"));
179
+ });
180
+ }
181
+ return app;
182
+ }
183
+ // Annotate the CommonJS export names for ESM import in node:
184
+ 0 && (module.exports = {
185
+ createRemindrApp
186
+ });
@@ -0,0 +1,13 @@
1
+ import * as express_serve_static_core from 'express-serve-static-core';
2
+
3
+ declare function createRemindrApp<T>(options: {
4
+ clientPath: string;
5
+ matchKey?: string;
6
+ mapItemToRow: (item: {
7
+ id: string;
8
+ label: string;
9
+ checked: boolean;
10
+ }) => Partial<T>;
11
+ }): express_serve_static_core.Express;
12
+
13
+ export { createRemindrApp };
@@ -0,0 +1,13 @@
1
+ import * as express_serve_static_core from 'express-serve-static-core';
2
+
3
+ declare function createRemindrApp<T>(options: {
4
+ clientPath: string;
5
+ matchKey?: string;
6
+ mapItemToRow: (item: {
7
+ id: string;
8
+ label: string;
9
+ checked: boolean;
10
+ }) => Partial<T>;
11
+ }): express_serve_static_core.Express;
12
+
13
+ export { createRemindrApp };
package/dist/index.js ADDED
@@ -0,0 +1,149 @@
1
+ // src/createApp.ts
2
+ import express from "express";
3
+ import cors from "cors";
4
+ import path from "path";
5
+
6
+ // src/routes/items.ts
7
+ import { Router } from "express";
8
+
9
+ // src/env.ts
10
+ import dotenv from "dotenv";
11
+ dotenv.config();
12
+ var env = {
13
+ n8nBaseUrl: required("N8N_BASE_URL"),
14
+ n8nApiKey: required("N8N_API_KEY"),
15
+ n8nTableId: required("N8N_TABLE_ID"),
16
+ pinCode: required("PIN_CODE")
17
+ };
18
+ function required(name) {
19
+ const value = process.env[name];
20
+ if (!value) {
21
+ throw new Error(`Missing env variable: ${name}`);
22
+ }
23
+ return value;
24
+ }
25
+
26
+ // src/n8n.ts
27
+ var n8nHeaders = {
28
+ Accept: "application/json",
29
+ "Content-Type": "application/json",
30
+ "X-N8N-API-KEY": env.n8nApiKey
31
+ };
32
+ var n8nRowsUrl = `${env.n8nBaseUrl}/api/v1/data-tables/${env.n8nTableId}/rows`;
33
+
34
+ // src/routes/items.ts
35
+ function createItemsRouter(mapItemToRow, matchKey = "id") {
36
+ const router = Router();
37
+ router.get("/", async (_req, res) => {
38
+ const response = await fetch(n8nRowsUrl, {
39
+ headers: n8nHeaders
40
+ });
41
+ const data = await response.json();
42
+ res.status(response.status).json(data);
43
+ });
44
+ router.post("/", async (req, res) => {
45
+ const { body } = req;
46
+ const response = await fetch(n8nRowsUrl, {
47
+ method: "POST",
48
+ headers: n8nHeaders,
49
+ body: JSON.stringify({
50
+ data: [
51
+ mapItemToRow({
52
+ id: body.id,
53
+ label: body.label,
54
+ checked: false
55
+ })
56
+ ]
57
+ })
58
+ });
59
+ const data = await response.json();
60
+ res.status(response.status).json(data);
61
+ });
62
+ router.patch("/:id", async (req, res) => {
63
+ const { body } = req;
64
+ const response = await fetch(`${n8nRowsUrl}/update`, {
65
+ method: "PATCH",
66
+ headers: n8nHeaders,
67
+ body: JSON.stringify({
68
+ filter: {
69
+ type: "and",
70
+ filters: [
71
+ {
72
+ columnName: matchKey,
73
+ condition: "eq",
74
+ value: req.params.id
75
+ }
76
+ ]
77
+ },
78
+ data: {
79
+ checked: body.checked
80
+ }
81
+ })
82
+ });
83
+ const data = await response.json();
84
+ res.status(response.status).json(data);
85
+ });
86
+ router.delete("/:id", async (req, res) => {
87
+ const filter = {
88
+ type: "and",
89
+ filters: [
90
+ {
91
+ columnName: matchKey,
92
+ condition: "eq",
93
+ value: req.params.id
94
+ }
95
+ ]
96
+ };
97
+ const params = new URLSearchParams({
98
+ filter: JSON.stringify(filter)
99
+ });
100
+ const response = await fetch(`${n8nRowsUrl}/delete?${params}`, {
101
+ method: "DELETE",
102
+ headers: {
103
+ Accept: "application/json",
104
+ "X-N8N-API-KEY": n8nHeaders["X-N8N-API-KEY"]
105
+ }
106
+ });
107
+ const data = await response.json();
108
+ res.status(response.status).json(data);
109
+ });
110
+ return router;
111
+ }
112
+
113
+ // src/routes/auth.ts
114
+ import { Router as Router2 } from "express";
115
+ var authRouter = Router2();
116
+ authRouter.post("/", async (req, res) => {
117
+ const { body } = req;
118
+ const authCheck = body.pinCode === env.pinCode;
119
+ res.status(200).json({ authCheck });
120
+ });
121
+
122
+ // src/createApp.ts
123
+ function createRemindrApp(options) {
124
+ const app = express();
125
+ app.use(express.json());
126
+ app.use(cors({
127
+ origin: [
128
+ process.env.APP_DEV_URL ?? "",
129
+ process.env.APP_PUBLIC_URL ?? ""
130
+ ]
131
+ }));
132
+ app.get("/api/health", (_req, res) => {
133
+ res.json({ ok: true });
134
+ });
135
+ app.use("/api/items", createItemsRouter(options.mapItemToRow, options.matchKey ?? "id"));
136
+ app.use("/api/auth", authRouter);
137
+ const isProduction = process.env.NODE_ENV === "production";
138
+ if (isProduction) {
139
+ const frontendDistPath = path.resolve(process.cwd(), options.clientPath);
140
+ app.use(express.static(frontendDistPath));
141
+ app.get("*", (_req, res) => {
142
+ res.sendFile(path.join(frontendDistPath, "index.html"));
143
+ });
144
+ }
145
+ return app;
146
+ }
147
+ export {
148
+ createRemindrApp
149
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@remindr/backend",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "dependencies": {
24
+ "cors": "^2.8.5",
25
+ "dotenv": "^16.0.0",
26
+ "express": "^5.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/cors": "^2.8.19",
30
+ "@types/express": "^5.0.6",
31
+ "@types/node": "^25.9.1",
32
+ "tsup": "^8.5.1",
33
+ "typescript": "^6.0.3"
34
+ }
35
+ }