appstore-backend-api
v1.0.1
Published
Lightweight packaging of selected API services from the appstore backend so other Node.js/Express apps can consume them.
Readme
appstore-backend-api
Lightweight packaging of selected API services from the appstore backend so other Node.js/Express apps can consume them.
Installation
npm install appstore-backend-apiFor local testing use
npm packand install the generated.tgzin a consumer project.
Configuration
The package reads database configuration from environment variables provided by the consuming application. Do NOT commit secrets.
Required environment variables:
DB_USERDB_PASSWORDDB_DBDB_HOSTDIALECT(e.g.,postgres)
Set them in the consuming application's environment before requiring the package.
Usage
Service usage (programmatic):
const { productService, categoryService } = require('appstore-backend-api');
// Read-only examples
(async () => {
const products = await productService.getProducts();
const single = await productService.getProductById(1);
const published = await productService.getPublishedProducts({ limit: 10 });
console.log(products.length, single && single.id, published.length);
})();Express integration (router):
const express = require('express');
const { apiRouter } = require('appstore-backend-api');
const app = express();
app.use('/api', apiRouter);
app.listen(3000);Example: multipart/form-data product create (curl)
Protect write routes and ensure DB and MinIO env variables are set in the consuming app.
curl -X POST \
-H "Authorization: Bearer $API_KEY" \
-F "category_id=1" \
-F "app_name=My App" \
-F "app_version=1.2.3" \
-F "uploaded_by=tester" \
-F "build_type=debug" \
-F "logo=@/path/to/logo.png" \
-F "upload_apk=@/path/to/app.apk" \
-F "app_images=@/path/to/img1.png" \
https://your-consumer-app.example.com/api/products/createThe uploaded files will be stored via the configured MinIO/S3 client and version records are created for APK uploads.
Exported services and methods
productServicegetProductById(id)-> Promise<AppProduct|null>getProducts(filters)-> Promise<AppProduct[]>getPublishedProducts(opts)-> Promise<AppProduct[]>viewAllProducts()-> Promise<FormattedProduct[]>searchProducts(search)-> Promise<AppProduct[]>productWriteServicecreateOrUpdateProduct(data)-> Promise- Note: This helper performs DB create/update logic but does NOT handle file uploads or authentication. Consumers should provide upload middleware and authentication when exposing write endpoints.
categoryServicegetCategories()-> Promise<Category[]>getPublishedCategories()-> Promise<Category[]>
appInstallationServicecreateInstallation(data)-> PromisegetInstallationCount(app_product_id, app_version?)-> PromisegetInstallationCountByVersion(app_product_id)-> Promise<{ total_installations, by_version }>getInstallationByDownload(app_product_id)-> Promise
appLoginServicecreateAppLogin(data)-> PromisegetAppLogins(filters)-> Promise<{ data, total, limit, offset }>getAppLoginById(id)-> Promise<AppLogin|null>getAppLoginCount(app_product_id, app_version?)-> Promise
apiRouter— Express router exposing read endpoints for products and categories and several new endpoints for app installation/login data. It includes a small write endpoint atPOST /products/createthat callscreateOrUpdateProductandPOST /app-installation/createandPOST /app-login/createfor simple programmatic creation. These write routes do not perform authentication or file upload handling; mount additional middleware in your app as needed.
Example: mounting auth middleware
The package includes a tiny example middleware authExample.requireAuth to demonstrate how a consumer might protect write routes. This middleware checks the Authorization header or x-api-key against process.env.API_KEY.
const express = require('express');
const { apiRouter, authExample } = require('appstore-backend-api');
const app = express();
// Protect write routes on the router by mounting middleware before the router
app.use('/api', authExample.requireAuth, apiRouter);
app.listen(3000);Replace authExample.requireAuth with your real authentication (JWT verification, session middleware, etc.) in production.
Testing locally (pack + install)
From the package root:
npm pack
# this will produce appstore-backend-api-1.0.0.tgzIn your example consumer project directory:
npm install ../path/to/appstore-backend-api-1.0.0.tgz
# then in your app
node -e "require('dotenv').config(); const { productService } = require('appstore-backend-api'); (async()=>{ console.log(await productService.getProducts()); })()"Build command
There is no build step for this JavaScript package — source is published as CommonJS under src/.
Publish to npm
- Update
package.jsonnameto a unique package name and setversion. - Login to npm:
npm login. - Publish:
npm publish --access public(or omit--accessfor unscoped packages).
Notes
- The package intentionally exposes read-only service functions and a router. The consuming application is responsible for authentication, file uploads, and any middleware needed for the more complex write endpoints that are tightly coupled to Express
req/resin the original backend. - Do not commit secrets. The package reads credentials from the environment of the consumer.
