@futdevpro/nts-dynamo 1.15.121 → 1.15.122
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/.dynamo/logs/cicd-pipeline/output.log +1685 -1706
- package/.dynamo/logs/cicd-pipeline/status.json +40 -40
- package/build/_modules/ftp/_collections/ftp-url-signer.util.d.ts +37 -0
- package/build/_modules/ftp/_collections/ftp-url-signer.util.d.ts.map +1 -0
- package/build/_modules/ftp/_collections/ftp-url-signer.util.js +57 -0
- package/build/_modules/ftp/_collections/ftp-url-signer.util.js.map +1 -0
- package/build/_modules/ftp/_services/ftp-service.api-service.d.ts +63 -0
- package/build/_modules/ftp/_services/ftp-service.api-service.d.ts.map +1 -0
- package/build/_modules/ftp/_services/ftp-service.api-service.js +84 -0
- package/build/_modules/ftp/_services/ftp-service.api-service.js.map +1 -0
- package/build/_modules/ftp/index.d.ts +3 -0
- package/build/_modules/ftp/index.d.ts.map +1 -0
- package/build/_modules/ftp/index.js +8 -0
- package/build/_modules/ftp/index.js.map +1 -0
- package/package.json +10 -1
- package/src/_modules/ftp/_collections/ftp-url-signer.util.spec.ts +44 -0
- package/src/_modules/ftp/_collections/ftp-url-signer.util.ts +60 -0
- package/src/_modules/ftp/_services/ftp-service.api-service.ts +120 -0
- package/src/_modules/ftp/index.ts +7 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DyFM_HttpCallType } from '@futdevpro/fsm-dynamo';
|
|
2
|
+
|
|
3
|
+
import { DyNTS_ApiService } from '../../../_services/core/api.service';
|
|
4
|
+
import { DyNTS_ApiCall_Params, DyNTS_HttpOptions } from '../../../_models/control-models/api-call-params.control-model';
|
|
5
|
+
import { DyNTS_FtpUrlSigner_Util } from '../_collections/ftp-url-signer.util';
|
|
6
|
+
|
|
7
|
+
/** A signed UPLOAD-aláírás érvényessége (10 perc) — a szerver-szerver app→ftp feltöltés szinkron, rövid ablak elég. */
|
|
8
|
+
const FTP_SIGNED_UPLOAD_TTL_MS: number = 10 * 60 * 1000;
|
|
9
|
+
/** A signed SERVE-URL alap-élettartama (30 nap) — a felhasználó később is letölti a fájlt. */
|
|
10
|
+
const FTP_SIGNED_SERVE_TTL_MS: number = 30 * 24 * 60 * 60 * 1000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* FTP-kliens KONFIG (a consumer adja át — PURE: nincs fdp-templates-függés).
|
|
14
|
+
* A `fdp-ftp-service` URL-jei + a megosztott aláíró-titok a hívó-oldalról jönnek.
|
|
15
|
+
*/
|
|
16
|
+
export interface DyNTS_FtpService_Config {
|
|
17
|
+
/** az `fdp-ftp-service` API base-URL a szerver-szerver feltöltéshez (pl. `FDP_ftpServiceApiEnv_settings.baseUrl.fromBE`). */
|
|
18
|
+
apiBaseUrl: string;
|
|
19
|
+
/** a publikus serve-host az aláírt letöltő-URL-ekhez (pl. `FDP_ftpServiceApiEnv_settings.baseUrl.siteAddress`). */
|
|
20
|
+
serveBaseUrl: string;
|
|
21
|
+
/** a megosztott HMAC-titok (env-var `FTP_URL_SIGNING_SECRET`, MÁR létező). Üres → a serve-gate inaktív. */
|
|
22
|
+
signingSecret: string;
|
|
23
|
+
/** az upload-endpoint (default `/files/upload`). */
|
|
24
|
+
uploadFileEndpoint?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** FTP-feltöltés bemenete. */
|
|
28
|
+
export interface DyNTS_FtpService_UploadFile_Input {
|
|
29
|
+
accountId: string;
|
|
30
|
+
folderPath: string;
|
|
31
|
+
fileName: string;
|
|
32
|
+
fileBuffer: Buffer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** FTP-feltöltés válasza. */
|
|
36
|
+
export interface DyNTS_FtpService_UploadFile_Response {
|
|
37
|
+
filePath: string;
|
|
38
|
+
ftpPath: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* FTP Service API kliens (deep/generikus — `@futdevpro/nts-dynamo`).
|
|
43
|
+
* @description A szerver-oldali FTP-KLIENS: a meglévő `fdp-ftp-service` tároló-szervert HÍVJA — fájlt tölt
|
|
44
|
+
* fel (signed upload), és aláírt serve-URL-t épít. **NEM tartalmaz FTP-szervert.** A korábban az
|
|
45
|
+
* MP-be / token-service-be duplikált FTP-kliens EGYETLEN, flotta-közös kiváltása.
|
|
46
|
+
*
|
|
47
|
+
* **PURE (ADR-004):** a config (URL-ek + titok) a `DyNTS_FtpService_Config`-ból, a hívó adja át —
|
|
48
|
+
* nincs `fdp-templates`-import. Nem singleton: minden consumer a saját config-jával példányosít.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const ftp: DyNTS_FtpService_ApiService = new DyNTS_FtpService_ApiService({
|
|
53
|
+
* apiBaseUrl: FDP_ftpServiceApiEnv_settings.baseUrl.fromBE,
|
|
54
|
+
* serveBaseUrl: FDP_ftpServiceApiEnv_settings.baseUrl.siteAddress,
|
|
55
|
+
* signingSecret: process.env.FTP_URL_SIGNING_SECRET || '',
|
|
56
|
+
* });
|
|
57
|
+
* const { ftpPath } = await ftp.uploadFile({ accountId, folderPath: 'invoices/<userId>', fileName, fileBuffer });
|
|
58
|
+
* const url: string = ftp.buildSignedServeUrl(ftpPath);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export class DyNTS_FtpService_ApiService {
|
|
62
|
+
|
|
63
|
+
private readonly config: DyNTS_FtpService_Config;
|
|
64
|
+
|
|
65
|
+
constructor(config: DyNTS_FtpService_Config) {
|
|
66
|
+
this.config = config;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private get uploadFileEndpoint(): string {
|
|
70
|
+
return this.config.uploadFileEndpoint ?? '/files/upload';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Fájl feltöltése az `fdp-ftp-service`-re (signed, szerver-szerver).
|
|
75
|
+
* @description A kanonikus upload-célt + lejáratot HMAC-aláírjuk a megosztott titokkal; az ftp ezt
|
|
76
|
+
* validálja (a signature a KONKRÉT account+path-hoz köt — más account-ra nem replay-elhető).
|
|
77
|
+
*/
|
|
78
|
+
async uploadFile(input: DyNTS_FtpService_UploadFile_Input): Promise<DyNTS_FtpService_UploadFile_Response> {
|
|
79
|
+
const expMs: number = Date.now() + FTP_SIGNED_UPLOAD_TTL_MS;
|
|
80
|
+
const uploadTarget: string = DyNTS_FtpUrlSigner_Util.uploadTarget(input.accountId, input.folderPath, input.fileName);
|
|
81
|
+
const sig: string = DyNTS_FtpUrlSigner_Util.sign(uploadTarget, expMs, this.config.signingSecret);
|
|
82
|
+
|
|
83
|
+
return await DyNTS_ApiService.startApiCall<DyNTS_FtpService_UploadFile_Response>(
|
|
84
|
+
new DyNTS_ApiCall_Params({
|
|
85
|
+
name: 'uploadFile (DyNTS_FtpService)',
|
|
86
|
+
type: DyFM_HttpCallType.post,
|
|
87
|
+
baseUrl: this.config.apiBaseUrl,
|
|
88
|
+
endpoint: this.uploadFileEndpoint,
|
|
89
|
+
httpOptions: new DyNTS_HttpOptions({
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
95
|
+
{
|
|
96
|
+
body: {
|
|
97
|
+
accountId: input.accountId,
|
|
98
|
+
folderPath: input.folderPath,
|
|
99
|
+
fileName: input.fileName,
|
|
100
|
+
fileBuffer: input.fileBuffer.toString('base64'),
|
|
101
|
+
exp: expMs,
|
|
102
|
+
sig: sig,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Aláírt serve-URL egy `ftpPath`-ból (böngésző-letöltéshez). Üres titok → üres string (gate inaktív).
|
|
110
|
+
* @param ttlMs opcionális egyedi élettartam; default 30 nap.
|
|
111
|
+
*/
|
|
112
|
+
buildSignedServeUrl(ftpPath: string, ttlMs: number = FTP_SIGNED_SERVE_TTL_MS): string {
|
|
113
|
+
return DyNTS_FtpUrlSigner_Util.buildSignedServeUrl({
|
|
114
|
+
serveBaseUrl: this.config.serveBaseUrl,
|
|
115
|
+
ftpPath: ftpPath,
|
|
116
|
+
ttlMs: ttlMs,
|
|
117
|
+
secret: this.config.signingSecret,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DyNTS_FtpUrlSigner_Util } from './_collections/ftp-url-signer.util';
|
|
2
|
+
export {
|
|
3
|
+
DyNTS_FtpService_ApiService,
|
|
4
|
+
DyNTS_FtpService_Config,
|
|
5
|
+
DyNTS_FtpService_UploadFile_Input,
|
|
6
|
+
DyNTS_FtpService_UploadFile_Response,
|
|
7
|
+
} from './_services/ftp-service.api-service';
|