@iskra-bun/web-kit 0.1.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/CHANGELOG.md +7 -0
- package/README.md +31 -0
- package/dist/chunk-POXNRNTC.js +51 -0
- package/dist/chunk-POXNRNTC.js.map +1 -0
- package/dist/index.d.ts +966 -0
- package/dist/index.js +2824 -0
- package/dist/index.js.map +1 -0
- package/dist/mailgun-Z46GZJNI.js +83 -0
- package/dist/mailgun-Z46GZJNI.js.map +1 -0
- package/dist/s3-7IG4ESFW.js +171 -0
- package/dist/s3-7IG4ESFW.js.map +1 -0
- package/dist/sendgrid-UK2GSBEF.js +43 -0
- package/dist/sendgrid-UK2GSBEF.js.map +1 -0
- package/dist/smtp-WJDLYKD5.js +50 -0
- package/dist/smtp-WJDLYKD5.js.map +1 -0
- package/package.json +74 -0
- package/src/driver.ts +55 -0
- package/src/errors.ts +66 -0
- package/src/features/api-key.ts +243 -0
- package/src/features/auth/better-auth-config.ts +160 -0
- package/src/features/auth/index.ts +229 -0
- package/src/features/auth/schema.ts +174 -0
- package/src/features/auth/types.ts +114 -0
- package/src/features/cache.ts +144 -0
- package/src/features/cors.ts +33 -0
- package/src/features/csrf.ts +94 -0
- package/src/features/db.ts +90 -0
- package/src/features/email/index.ts +103 -0
- package/src/features/email/providers/mailgun.ts +99 -0
- package/src/features/email/providers/sendgrid.ts +42 -0
- package/src/features/email/providers/smtp.ts +51 -0
- package/src/features/error-handler.ts +147 -0
- package/src/features/health.ts +94 -0
- package/src/features/json-schema-validation.ts +186 -0
- package/src/features/logger.ts +70 -0
- package/src/features/openapi.ts +107 -0
- package/src/features/permissions.ts +128 -0
- package/src/features/rate-limit.ts +173 -0
- package/src/features/request-id.ts +45 -0
- package/src/features/session.ts +322 -0
- package/src/features/storage/adapters/local.ts +133 -0
- package/src/features/storage/adapters/s3.ts +193 -0
- package/src/features/storage/base.ts +112 -0
- package/src/features/storage/index.ts +53 -0
- package/src/features/tracing.ts +49 -0
- package/src/features/upload/helper.ts +85 -0
- package/src/features/upload/index.ts +140 -0
- package/src/features/validation.ts +105 -0
- package/src/index.ts +29 -0
- package/src/kernel.ts +257 -0
- package/src/responses.ts +37 -0
- package/src/router.ts +31 -0
- package/src/server.ts +135 -0
- package/src/types.ts +272 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @iskra-bun/web-kit
|
|
2
|
+
|
|
3
|
+
Servidor HTTP de Iskra basado en [Hono](https://hono.dev), con un Kernel de plugins y mas de 15 features integradas (auth, CORS, CSRF, rate limit, DB, cache, sesiones, storage, email, upload, validacion, OpenAPI, permisos, API keys, tracing, health checks).
|
|
4
|
+
|
|
5
|
+
## Instalacion
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @iskra-bun/web-kit @iskra-bun/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Uso rapido
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { App } from '@iskra-bun/core'
|
|
15
|
+
import { WebDriver } from '@iskra-bun/web-kit'
|
|
16
|
+
|
|
17
|
+
const app = new App({ name: 'mi-api' })
|
|
18
|
+
app.register(new WebDriver())
|
|
19
|
+
|
|
20
|
+
await app.start()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Las features se activan a traves de la configuracion del Kernel; revisa la guia para el catalogo completo.
|
|
24
|
+
|
|
25
|
+
## Documentacion
|
|
26
|
+
|
|
27
|
+
Guia completa: [docs/web-kit.md](../../docs/web-kit.md)
|
|
28
|
+
|
|
29
|
+
## Licencia
|
|
30
|
+
|
|
31
|
+
AGPL-3.0-or-later
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/features/storage/base.ts
|
|
2
|
+
var BaseStorageAdapter = class {
|
|
3
|
+
connected = false;
|
|
4
|
+
isConnected() {
|
|
5
|
+
return this.connected;
|
|
6
|
+
}
|
|
7
|
+
ensureConnected() {
|
|
8
|
+
if (!this.connected) {
|
|
9
|
+
throw new Error("Storage not connected. Call connect() first.");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async copy(from, to) {
|
|
13
|
+
const data = await this.get(from);
|
|
14
|
+
if (!data) {
|
|
15
|
+
throw new Error(`Source file not found: ${from}`);
|
|
16
|
+
}
|
|
17
|
+
await this.put(to, data);
|
|
18
|
+
}
|
|
19
|
+
async move(from, to) {
|
|
20
|
+
await this.copy(from, to);
|
|
21
|
+
await this.delete(from);
|
|
22
|
+
}
|
|
23
|
+
generateFileName(originalName) {
|
|
24
|
+
const ext = originalName.split(".").pop();
|
|
25
|
+
const timestamp = Date.now();
|
|
26
|
+
const random = Math.random().toString(36).substring(2, 15);
|
|
27
|
+
return `${timestamp}-${random}.${ext}`;
|
|
28
|
+
}
|
|
29
|
+
sanitizePath(path) {
|
|
30
|
+
return path.replace(/^\/+/, "").replace(/\/+/g, "/").replace(/\\/g, "/");
|
|
31
|
+
}
|
|
32
|
+
getMimeType(filename) {
|
|
33
|
+
const ext = filename.split(".").pop()?.toLowerCase();
|
|
34
|
+
const mimeTypes = {
|
|
35
|
+
jpg: "image/jpeg",
|
|
36
|
+
jpeg: "image/jpeg",
|
|
37
|
+
png: "image/png",
|
|
38
|
+
gif: "image/gif",
|
|
39
|
+
pdf: "application/pdf",
|
|
40
|
+
txt: "text/plain",
|
|
41
|
+
json: "application/json",
|
|
42
|
+
zip: "application/zip"
|
|
43
|
+
};
|
|
44
|
+
return mimeTypes[ext || ""] || "application/octet-stream";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
BaseStorageAdapter
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=chunk-POXNRNTC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/features/storage/base.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\n\nexport interface StorageConfig {\n adapter: \"local\" | \"minio\" | \"s3\";\n basePath?: string; // For local storage\n connection?: {\n endpoint?: string;\n accessKey?: string;\n secretKey?: string;\n bucket?: string;\n region?: string;\n useSSL?: boolean;\n };\n}\n\nexport interface StorageFile {\n name: string;\n path: string;\n size: number;\n mimeType?: string;\n lastModified?: Date;\n url?: string;\n}\n\nexport interface PutOptions {\n contentType?: string;\n metadata?: Record<string, string>;\n public?: boolean;\n}\n\nexport interface StorageAdapter {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n put(path: string, data: Uint8Array | Buffer | ReadableStream, options?: PutOptions): Promise<StorageFile>;\n get(path: string): Promise<Uint8Array | null>;\n // getStream(path: string): Promise<ReadableStream | null>; \n // Node streams are different, sticking to Buffer/Uint8Array for simplicity or using generic Stream\n delete(path: string): Promise<void>;\n exists(path: string): Promise<boolean>;\n list(prefix?: string): Promise<StorageFile[]>;\n url(path: string, expiresIn?: number): Promise<string>;\n copy(from: string, to: string): Promise<void>;\n move(from: string, to: string): Promise<void>;\n isDirectory(path: string): Promise<boolean>;\n}\n\nexport abstract class BaseStorageAdapter implements StorageAdapter {\n protected connected = false;\n\n abstract connect(): Promise<void>;\n abstract disconnect(): Promise<void>;\n abstract put(path: string, data: Uint8Array | Buffer | ReadableStream, options?: PutOptions): Promise<StorageFile>;\n abstract get(path: string): Promise<Uint8Array | null>;\n\n abstract delete(path: string): Promise<void>;\n abstract exists(path: string): Promise<boolean>;\n abstract list(prefix?: string): Promise<StorageFile[]>;\n abstract url(path: string, expiresIn?: number): Promise<string>;\n abstract isDirectory(path: string): Promise<boolean>;\n\n isConnected(): boolean {\n return this.connected;\n }\n\n protected ensureConnected(): void {\n if (!this.connected) {\n throw new Error(\"Storage not connected. Call connect() first.\");\n }\n }\n\n async copy(from: string, to: string): Promise<void> {\n const data = await this.get(from);\n if (!data) {\n throw new Error(`Source file not found: ${from}`);\n }\n await this.put(to, data);\n }\n\n async move(from: string, to: string): Promise<void> {\n await this.copy(from, to);\n await this.delete(from);\n }\n\n protected generateFileName(originalName: string): string {\n const ext = originalName.split(\".\").pop();\n const timestamp = Date.now();\n const random = Math.random().toString(36).substring(2, 15);\n return `${timestamp}-${random}.${ext}`;\n }\n\n protected sanitizePath(path: string): string {\n return path\n .replace(/^\\/+/, \"\")\n .replace(/\\/+/g, \"/\")\n .replace(/\\\\/g, \"/\");\n }\n\n protected getMimeType(filename: string): string {\n const ext = filename.split(\".\").pop()?.toLowerCase();\n const mimeTypes: Record<string, string> = {\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n png: \"image/png\",\n gif: \"image/gif\",\n pdf: \"application/pdf\",\n txt: \"text/plain\",\n json: \"application/json\",\n zip: \"application/zip\",\n };\n return mimeTypes[ext || \"\"] || \"application/octet-stream\";\n }\n}\n"],"mappings":";AA8CO,IAAe,qBAAf,MAA4D;AAAA,EACrD,YAAY;AAAA,EAatB,cAAuB;AACnB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEU,kBAAwB;AAC9B,QAAI,CAAC,KAAK,WAAW;AACjB,YAAM,IAAI,MAAM,8CAA8C;AAAA,IAClE;AAAA,EACJ;AAAA,EAEA,MAAM,KAAK,MAAc,IAA2B;AAChD,UAAM,OAAO,MAAM,KAAK,IAAI,IAAI;AAChC,QAAI,CAAC,MAAM;AACP,YAAM,IAAI,MAAM,0BAA0B,IAAI,EAAE;AAAA,IACpD;AACA,UAAM,KAAK,IAAI,IAAI,IAAI;AAAA,EAC3B;AAAA,EAEA,MAAM,KAAK,MAAc,IAA2B;AAChD,UAAM,KAAK,KAAK,MAAM,EAAE;AACxB,UAAM,KAAK,OAAO,IAAI;AAAA,EAC1B;AAAA,EAEU,iBAAiB,cAA8B;AACrD,UAAM,MAAM,aAAa,MAAM,GAAG,EAAE,IAAI;AACxC,UAAM,YAAY,KAAK,IAAI;AAC3B,UAAM,SAAS,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,EAAE;AACzD,WAAO,GAAG,SAAS,IAAI,MAAM,IAAI,GAAG;AAAA,EACxC;AAAA,EAEU,aAAa,MAAsB;AACzC,WAAO,KACF,QAAQ,QAAQ,EAAE,EAClB,QAAQ,QAAQ,GAAG,EACnB,QAAQ,OAAO,GAAG;AAAA,EAC3B;AAAA,EAEU,YAAY,UAA0B;AAC5C,UAAM,MAAM,SAAS,MAAM,GAAG,EAAE,IAAI,GAAG,YAAY;AACnD,UAAM,YAAoC;AAAA,MACtC,KAAK;AAAA,MACL,MAAM;AAAA,MACN,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,MAAM;AAAA,MACN,KAAK;AAAA,IACT;AACA,WAAO,UAAU,OAAO,EAAE,KAAK;AAAA,EACnC;AACJ;","names":[]}
|