@progalaxyelabs/stonescriptphp-files 2.0.0 → 2.0.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.
- package/package.json +1 -1
- package/src/azure-storage.js +2 -4
- package/HLD.md +0 -170
- package/project-info.yaml +0 -119
package/package.json
CHANGED
package/src/azure-storage.js
CHANGED
|
@@ -28,10 +28,8 @@ export class AzureStorageClient {
|
|
|
28
28
|
// Get container client
|
|
29
29
|
this.containerClient = this.blobServiceClient.getContainerClient(this.containerName);
|
|
30
30
|
|
|
31
|
-
// Create container if it doesn't exist
|
|
32
|
-
await this.containerClient.createIfNotExists(
|
|
33
|
-
access: 'private' // CRITICAL: No public access
|
|
34
|
-
});
|
|
31
|
+
// Create container if it doesn't exist (no access property = private, no public access)
|
|
32
|
+
await this.containerClient.createIfNotExists();
|
|
35
33
|
|
|
36
34
|
console.log(`Azure Blob Storage initialized: container=${this.containerName}`);
|
|
37
35
|
} catch (error) {
|
package/HLD.md
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
# @progalaxyelabs/stonescriptphp-files — High Level Design
|
|
2
|
-
|
|
3
|
-
**Version**: 1.0.0
|
|
4
|
-
**Last Updated**: 2026-02-07
|
|
5
|
-
|
|
6
|
-
## Overview
|
|
7
|
-
|
|
8
|
-
A shared npm package that provides a ready-to-use Express file server with Azure Blob Storage and JWT authentication.
|
|
9
|
-
|
|
10
|
-
### Developer Experience
|
|
11
|
-
```bash
|
|
12
|
-
mkdir files && cd files
|
|
13
|
-
npm init -y
|
|
14
|
-
npm i express @progalaxyelabs/stonescriptphp-files
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
// index.js
|
|
19
|
-
import 'dotenv/config';
|
|
20
|
-
import { createFilesServer } from '@progalaxyelabs/stonescriptphp-files';
|
|
21
|
-
createFilesServer().listen();
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Architecture
|
|
25
|
-
|
|
26
|
-
### Package Exports
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
@progalaxyelabs/stonescriptphp-files
|
|
30
|
-
├── createFilesServer(config?) // Factory: returns configured Express app
|
|
31
|
-
├── AzureStorageClient // Class: Azure Blob Storage operations
|
|
32
|
-
├── createAuthMiddleware // Middleware factory: JWT Bearer token validation
|
|
33
|
-
├── createUploadRouter // Express Router factory: POST /upload
|
|
34
|
-
├── createDownloadRouter // Express Router factory: GET /files/:id
|
|
35
|
-
├── createListRouter // Express Router factory: GET /files
|
|
36
|
-
├── createDeleteRouter // Express Router factory: DELETE /files/:id
|
|
37
|
-
└── createHealthRouter // Express Router factory: GET /health
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### `createFilesServer(config?)` Factory
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
createFilesServer({
|
|
44
|
-
port: process.env.PORT || 3000,
|
|
45
|
-
containerName: process.env.AZURE_CONTAINER_NAME || 'platform-files',
|
|
46
|
-
azureConnectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
|
|
47
|
-
jwtPublicKey: process.env.JWT_PUBLIC_KEY,
|
|
48
|
-
maxFileSize: 100 * 1024 * 1024, // 100MB default
|
|
49
|
-
corsOrigins: '*',
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
All config is optional — defaults to environment variables so the minimal setup works with zero arguments.
|
|
54
|
-
|
|
55
|
-
### Request Flow
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
Client
|
|
59
|
-
│
|
|
60
|
-
├─ POST /upload (multipart/form-data)
|
|
61
|
-
│ → JWT auth middleware
|
|
62
|
-
│ → multer (memory storage)
|
|
63
|
-
│ → AzureStorageClient.uploadFile()
|
|
64
|
-
│ → Returns { success, file: { id, name, size, contentType, uploadedAt } }
|
|
65
|
-
│
|
|
66
|
-
├─ GET /files/:id
|
|
67
|
-
│ → JWT auth middleware
|
|
68
|
-
│ → AzureStorageClient.downloadFile()
|
|
69
|
-
│ → Streams blob to response (Content-Type, Content-Disposition)
|
|
70
|
-
│
|
|
71
|
-
├─ GET /files
|
|
72
|
-
│ → JWT auth middleware
|
|
73
|
-
│ → AzureStorageClient.listFiles(userId)
|
|
74
|
-
│ → Returns { success, count, files: [...] }
|
|
75
|
-
│
|
|
76
|
-
├─ DELETE /files/:id
|
|
77
|
-
│ → JWT auth middleware
|
|
78
|
-
│ → AzureStorageClient.deleteFile()
|
|
79
|
-
│ → Returns { success, message }
|
|
80
|
-
│
|
|
81
|
-
└─ GET /health
|
|
82
|
-
→ No auth
|
|
83
|
-
→ Returns { status: "healthy", service: "files-service", timestamp }
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Components
|
|
87
|
-
|
|
88
|
-
### createFilesServer (factory)
|
|
89
|
-
Main export. Creates and returns a configured Express app with all routes, middleware, and graceful shutdown. Accepts optional config object, defaults to env vars.
|
|
90
|
-
|
|
91
|
-
### AzureStorageClient (class)
|
|
92
|
-
Wraps `@azure/storage-blob` SDK. Methods: `initialize()`, `uploadFile(userId, buffer, filename, contentType)`, `downloadFile(fileId, userId)`, `listFiles(userId)`, `deleteFile(fileId, userId)`. Auto-creates container on init with private access.
|
|
93
|
-
|
|
94
|
-
### createAuthMiddleware (middleware factory)
|
|
95
|
-
Express middleware factory. Validates Bearer token, extracts user identity from standard JWT claims (`sub`, `user_id`, `userId`, `id`), attaches to `req.user`. Supports RS256/ES256/HS256.
|
|
96
|
-
|
|
97
|
-
### Route handlers (router factories)
|
|
98
|
-
Express Router factory functions for upload, download, list, delete, health. Can be used individually for custom mounting or composed via `createFilesServer`.
|
|
99
|
-
|
|
100
|
-
## Tech Stack
|
|
101
|
-
|
|
102
|
-
| Component | Technology |
|
|
103
|
-
|-----------|-----------|
|
|
104
|
-
| Runtime | Node.js 24+ |
|
|
105
|
-
| Framework | Express 5.x (peerDependency) |
|
|
106
|
-
| Language | JavaScript (ESM) |
|
|
107
|
-
| Storage | Azure Blob Storage (`@azure/storage-blob` ^12.24.0) |
|
|
108
|
-
| Auth | JWT (`jsonwebtoken` ^9.0.2) |
|
|
109
|
-
| Upload | `multer` ^1.4.5-lts.1 |
|
|
110
|
-
| Module type | ESM (`"type": "module"`) |
|
|
111
|
-
|
|
112
|
-
## Storage Design
|
|
113
|
-
|
|
114
|
-
- **SDK:** `@azure/storage-blob` v12.x
|
|
115
|
-
- **Auth:** Connection string (env var)
|
|
116
|
-
- **Container:** auto-created on startup with private access
|
|
117
|
-
- **Blob path:** `{userId}/{uuid}.{extension}`
|
|
118
|
-
- **Metadata:** original_name, user_id, content_type, uploaded_at, file_id
|
|
119
|
-
|
|
120
|
-
## JWT Authentication
|
|
121
|
-
|
|
122
|
-
- **Algorithms:** RS256, ES256, HS256
|
|
123
|
-
- **Token source:** `Authorization: Bearer <token>` header
|
|
124
|
-
- **User ID extraction:** `sub` | `user_id` | `userId` | `id` claim
|
|
125
|
-
- **Ownership:** files are scoped to the authenticated user's ID
|
|
126
|
-
- **Health endpoint:** excluded from auth
|
|
127
|
-
- **Role-based auth:** optional `requireRole()` middleware export
|
|
128
|
-
|
|
129
|
-
## Environment Variables
|
|
130
|
-
|
|
131
|
-
| Variable | Required | Default | Description |
|
|
132
|
-
|----------|----------|---------|-------------|
|
|
133
|
-
| `AZURE_STORAGE_CONNECTION_STRING` | Yes | — | Azure Storage connection string |
|
|
134
|
-
| `AZURE_CONTAINER_NAME` | No | `platform-files` | Blob container name |
|
|
135
|
-
| `JWT_PUBLIC_KEY` | Yes | — | Public key for JWT verification |
|
|
136
|
-
| `PORT` | No | `3000` | Server listen port |
|
|
137
|
-
|
|
138
|
-
## Requirements
|
|
139
|
-
|
|
140
|
-
### Functional
|
|
141
|
-
- Upload files via multipart/form-data to Azure Blob Storage
|
|
142
|
-
- Download files with ownership verification and proper headers
|
|
143
|
-
- List all files belonging to the authenticated user
|
|
144
|
-
- Delete files with ownership verification
|
|
145
|
-
- JWT Bearer token authentication on all file operations
|
|
146
|
-
- Health check endpoint (unauthenticated)
|
|
147
|
-
- Auto-create Azure Blob container on startup
|
|
148
|
-
- Graceful shutdown on SIGTERM/SIGINT
|
|
149
|
-
- 100MB default file size limit (configurable)
|
|
150
|
-
- CORS support (configurable origins)
|
|
151
|
-
|
|
152
|
-
### Non-Functional
|
|
153
|
-
- Zero-config startup (all settings from env vars)
|
|
154
|
-
- No platform-specific code — fully generic and reusable
|
|
155
|
-
- ESM module (`"type": "module"`)
|
|
156
|
-
- Node.js 24+ engine requirement
|
|
157
|
-
- Express 5.x as peer dependency
|
|
158
|
-
|
|
159
|
-
### Developer Experience
|
|
160
|
-
- Setup in 3 commands: `npm init`, `npm i express @progalaxyelabs/stonescriptphp-files`, create index.js
|
|
161
|
-
- Consumer service has only 2 dependencies: `express` and this package
|
|
162
|
-
- All config via env vars with sensible defaults
|
|
163
|
-
- Composable exports for advanced/custom usage
|
|
164
|
-
|
|
165
|
-
## Constraints
|
|
166
|
-
|
|
167
|
-
- Must work with any JWT issuer (RS256/ES256/HS256)
|
|
168
|
-
- No breaking changes to Docker environment variables
|
|
169
|
-
- Published to npm as `@progalaxyelabs/stonescriptphp-files` (scoped, public)
|
|
170
|
-
- Source: https://github.com/progalaxyelabs/stonescriptphp-files
|
package/project-info.yaml
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# project-info.yaml
|
|
2
|
-
# Human-readable project metadata and configuration
|
|
3
|
-
|
|
4
|
-
# REQUIRED FIELDS
|
|
5
|
-
# ===============
|
|
6
|
-
|
|
7
|
-
# Project code in format: XXXX-NNN
|
|
8
|
-
project_code: "STON-003"
|
|
9
|
-
|
|
10
|
-
# Project name (matches directory name)
|
|
11
|
-
name: "stonescriptphp-files"
|
|
12
|
-
|
|
13
|
-
# Project type: platform | interconnected | standalone
|
|
14
|
-
type: "standalone"
|
|
15
|
-
|
|
16
|
-
# Project status: production | active-dev | staging | maintenance | paused | archived | planning | unknown
|
|
17
|
-
status: "production"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# BASIC METADATA
|
|
21
|
-
# ==============
|
|
22
|
-
|
|
23
|
-
# Human-readable project title
|
|
24
|
-
title: "@progalaxyelabs/stonescriptphp-files"
|
|
25
|
-
|
|
26
|
-
# Brief project description
|
|
27
|
-
description: "Zero-config Express file server with Azure Blob Storage and JWT authentication"
|
|
28
|
-
|
|
29
|
-
# Project version (semantic versioning recommended)
|
|
30
|
-
version: "1.0.0"
|
|
31
|
-
|
|
32
|
-
# Creation date (ISO 8601 format: YYYY-MM-DD)
|
|
33
|
-
created: "2026-02-07"
|
|
34
|
-
|
|
35
|
-
# Last modified date (ISO 8601 format: YYYY-MM-DD)
|
|
36
|
-
last_modified: "2026-02-07"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
# BUSINESS CLASSIFICATION
|
|
40
|
-
# =======================
|
|
41
|
-
|
|
42
|
-
# Domain category
|
|
43
|
-
domain: "tools"
|
|
44
|
-
|
|
45
|
-
# Project purpose: product | client-project | internal-tool | poc | experiment | library | marketing | unknown
|
|
46
|
-
purpose: "library"
|
|
47
|
-
|
|
48
|
-
# Business model: b2b-saas | b2c-saas | b2b-one-off | b2c-one-off | marketplace | internal | unknown
|
|
49
|
-
business_model: "internal"
|
|
50
|
-
|
|
51
|
-
# Ownership: progalaxy | client | partner | open-source | unknown
|
|
52
|
-
ownership: "open-source"
|
|
53
|
-
|
|
54
|
-
# Revenue priority: p0-critical | p1-high | p2-medium | p3-low | p4-none | unknown
|
|
55
|
-
revenue_priority: "p4-none"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
# TECHNICAL DETAILS
|
|
59
|
-
# =================
|
|
60
|
-
|
|
61
|
-
# Primary technology stack
|
|
62
|
-
tech_stack:
|
|
63
|
-
language: "JavaScript (ESM)"
|
|
64
|
-
runtime: "Node.js >= 24"
|
|
65
|
-
framework: "Express 5 (peerDependency)"
|
|
66
|
-
storage: "Azure Blob Storage"
|
|
67
|
-
auth: "JWT (RS256/ES256/HS256)"
|
|
68
|
-
|
|
69
|
-
# Key dependencies
|
|
70
|
-
dependencies:
|
|
71
|
-
- "@azure/storage-blob"
|
|
72
|
-
- "multer"
|
|
73
|
-
- "jsonwebtoken"
|
|
74
|
-
- "cors"
|
|
75
|
-
- "uuid"
|
|
76
|
-
|
|
77
|
-
# Deployment tier: tier-0-static | tier-1-simple | tier-2-database | tier-3-services | tier-4-distributed | library | unknown
|
|
78
|
-
deployment_tier: "library"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# GIT & REPOSITORY
|
|
82
|
-
# ================
|
|
83
|
-
|
|
84
|
-
repository:
|
|
85
|
-
type: "git"
|
|
86
|
-
url: "git@github.com:progalaxyelabs/stonescriptphp-files.git"
|
|
87
|
-
branch: "main"
|
|
88
|
-
|
|
89
|
-
# Package registry
|
|
90
|
-
npm:
|
|
91
|
-
name: "@progalaxyelabs/stonescriptphp-files"
|
|
92
|
-
scope: "progalaxyelabs"
|
|
93
|
-
access: "public"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
# CONSUMERS
|
|
97
|
-
# =========
|
|
98
|
-
|
|
99
|
-
consumers:
|
|
100
|
-
- "progalaxyelabs-platform/files"
|
|
101
|
-
- "progalaxy-platform/files"
|
|
102
|
-
- "btechrecruiter-platform/files"
|
|
103
|
-
- "instituteapp-platform/files"
|
|
104
|
-
- "restrantapp-platform/files"
|
|
105
|
-
- "medstoreapp-platform/files"
|
|
106
|
-
- "logisticsapp-platform/files"
|
|
107
|
-
- "specialcomputers-platform/files"
|
|
108
|
-
- "aasaanwork-platform/files"
|
|
109
|
-
- "webmeteor-platform/files"
|
|
110
|
-
- "emcircuitsystems-platform/files"
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# NOTES
|
|
114
|
-
# =====
|
|
115
|
-
|
|
116
|
-
notes: |
|
|
117
|
-
Factory pattern: createFilesServer(config?) with env var defaults.
|
|
118
|
-
Composable exports for advanced usage.
|
|
119
|
-
HLD in HLD.md.
|