@simplysm/storage 13.0.97 → 13.0.99

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.
Files changed (2) hide show
  1. package/README.md +142 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # @simplysm/storage
2
+
3
+ Simplysm Package - Storage Module (node). Provides FTP, FTPS, and SFTP storage client implementations with a factory for managed connections.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @simplysm/storage
9
+ ```
10
+
11
+ ## API Overview
12
+
13
+ ### Types
14
+
15
+ | API | Type | Description |
16
+ |-----|------|-------------|
17
+ | `StorageConnConfig` | interface | Storage connection configuration |
18
+ | `FileInfo` | interface | File/directory entry information |
19
+ | `StorageClient` | interface | Storage client interface |
20
+ | `StorageProtocol` | type | Protocol type (`"ftp" \| "ftps" \| "sftp"`) |
21
+
22
+ ### Clients
23
+
24
+ | API | Type | Description |
25
+ |-----|------|-------------|
26
+ | `FtpStorageClient` | class | FTP/FTPS storage client (uses basic-ftp) |
27
+ | `SftpStorageClient` | class | SFTP storage client (uses ssh2-sftp-client) |
28
+
29
+ ### Factory
30
+
31
+ | API | Type | Description |
32
+ |-----|------|-------------|
33
+ | `StorageFactory` | class | Storage client factory with managed connections |
34
+
35
+ ---
36
+
37
+ ### `StorageProtocol`
38
+
39
+ ```typescript
40
+ type StorageProtocol = "ftp" | "ftps" | "sftp"
41
+ ```
42
+
43
+ ### `StorageConnConfig`
44
+
45
+ | Field | Type | Description |
46
+ |-------|------|-------------|
47
+ | `host` | `string` | Server hostname |
48
+ | `port` | `number?` | Server port |
49
+ | `user` | `string?` | Username |
50
+ | `password` | `string?` | Password (SFTP: if omitted, uses SSH agent + key file) |
51
+
52
+ ### `FileInfo`
53
+
54
+ | Field | Type | Description |
55
+ |-------|------|-------------|
56
+ | `name` | `string` | File or directory name |
57
+ | `isFile` | `boolean` | Whether the entry is a file |
58
+
59
+ ### `StorageClient`
60
+
61
+ Interface implemented by both `FtpStorageClient` and `SftpStorageClient`.
62
+
63
+ | Method | Signature | Description |
64
+ |--------|-----------|-------------|
65
+ | `connect` | `(config: StorageConnConfig) => Promise<void>` | Connect to server |
66
+ | `mkdir` | `(dirPath: string) => Promise<void>` | Create directory (recursive) |
67
+ | `rename` | `(fromPath: string, toPath: string) => Promise<void>` | Rename file/directory |
68
+ | `list` | `(dirPath: string) => Promise<FileInfo[]>` | List directory contents |
69
+ | `readFile` | `(filePath: string) => Promise<Bytes>` | Read file |
70
+ | `exists` | `(filePath: string) => Promise<boolean>` | Check existence |
71
+ | `put` | `(localPathOrBuffer: string \| Bytes, storageFilePath: string) => Promise<void>` | Upload file (local path or byte data) |
72
+ | `uploadDir` | `(fromPath: string, toPath: string) => Promise<void>` | Upload entire directory |
73
+ | `remove` | `(filePath: string) => Promise<void>` | Delete file |
74
+ | `close` | `() => Promise<void>` | Close connection |
75
+
76
+ ### `FtpStorageClient`
77
+
78
+ Implements `StorageClient` using FTP/FTPS protocol via the `basic-ftp` library.
79
+
80
+ | Method | Signature | Description |
81
+ |--------|-----------|-------------|
82
+ | `constructor` | `(secure?: boolean)` | Create client (`true` for FTPS, `false` for FTP) |
83
+
84
+ All `StorageClient` methods are implemented. Using `StorageFactory.connect` is recommended over direct usage.
85
+
86
+ ### `SftpStorageClient`
87
+
88
+ Implements `StorageClient` using SFTP protocol via the `ssh2-sftp-client` library. Supports password authentication and SSH agent + key file authentication.
89
+
90
+ All `StorageClient` methods are implemented. Using `StorageFactory.connect` is recommended over direct usage.
91
+
92
+ ### `StorageFactory`
93
+
94
+ | Method | Signature | Description |
95
+ |--------|-----------|-------------|
96
+ | `connect` | `<R>(type: StorageProtocol, config: StorageConnConfig, fn: (storage: StorageClient) => R \| Promise<R>) => Promise<R>` | Connect, execute callback, auto-close |
97
+
98
+ ## Usage Examples
99
+
100
+ ### Using StorageFactory (recommended)
101
+
102
+ ```typescript
103
+ import { StorageFactory } from "@simplysm/storage";
104
+
105
+ await StorageFactory.connect("sftp", {
106
+ host: "example.com",
107
+ user: "deploy",
108
+ password: "secret",
109
+ }, async (storage) => {
110
+ await storage.uploadDir("./dist", "/var/www/app");
111
+ const files = await storage.list("/var/www/app");
112
+ });
113
+ ```
114
+
115
+ ### Using client directly
116
+
117
+ ```typescript
118
+ import { FtpStorageClient } from "@simplysm/storage";
119
+
120
+ const client = new FtpStorageClient(true); // FTPS
121
+ await client.connect({ host: "ftp.example.com", user: "admin", password: "pass" });
122
+ try {
123
+ await client.put("./build.zip", "/releases/build.zip");
124
+ const exists = await client.exists("/releases/build.zip");
125
+ } finally {
126
+ await client.close();
127
+ }
128
+ ```
129
+
130
+ ### SFTP with SSH key authentication
131
+
132
+ ```typescript
133
+ import { StorageFactory } from "@simplysm/storage";
134
+
135
+ // Omit password to use SSH agent + ~/.ssh/id_ed25519
136
+ await StorageFactory.connect("sftp", {
137
+ host: "example.com",
138
+ user: "deploy",
139
+ }, async (storage) => {
140
+ await storage.put(fileBytes, "/data/upload.bin");
141
+ });
142
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/storage",
3
- "version": "13.0.97",
3
+ "version": "13.0.99",
4
4
  "description": "Simplysm Package - Storage Module (node)",
5
5
  "author": "simplysm",
6
6
  "license": "Apache-2.0",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "basic-ftp": "^5.2.0",
23
23
  "ssh2-sftp-client": "^12.1.0",
24
- "@simplysm/core-common": "13.0.97"
24
+ "@simplysm/core-common": "13.0.99"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/ssh2-sftp-client": "^9.0.6"