Socket
Socket
Sign inDemoInstall

ftp-service

Package Overview
Dependencies
11
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0 to 6.0.1

9

CHANGELOG.md

@@ -0,1 +1,10 @@

## [6.0.1](https://github.com/nfroidure/ftp-service/compare/v6.0.0...v6.0.1) (2023-08-17)
### Bug Fixes
* **env:** allow env to be undefined ([b404538](https://github.com/nfroidure/ftp-service/commit/b404538ff7bb857cd0c7e5cdd5e2e332fce48df2))
# [6.0.0](https://github.com/nfroidure/ftp-service/compare/v5.0.0...v6.0.0) (2023-08-16)

@@ -2,0 +11,0 @@

5

dist/index.d.ts

@@ -7,3 +7,4 @@ /// <reference types="node" resolution-mode="require"/>

export declare const DEFAULT_FTP_PASSWORD_ENV_NAME = "FTP_PASSWORD";
export type FTP_ENV<T extends string extends T ? never : string = typeof DEFAULT_FTP_PASSWORD_ENV_NAME> = Record<T, string>;
export declare const DEFAULT_ENV: {};
export type FTPEnvVars<T extends string extends T ? never : string = typeof DEFAULT_FTP_PASSWORD_ENV_NAME> = Partial<Record<T, string>>;
export type FTPConfig<T extends string extends T ? never : string = typeof DEFAULT_FTP_PASSWORD_ENV_NAME> = {

@@ -23,3 +24,3 @@ FTP: NonNullable<Parameters<InstanceType<typeof FTPClient>['access']>[0]>;

export type FTPDependencies<T extends string extends T ? never : string = typeof DEFAULT_FTP_PASSWORD_ENV_NAME> = FTPConfig<T> & {
ENV: FTP_ENV<T>;
ENV?: FTPEnvVars<T>;
delay: DelayService;

@@ -26,0 +27,0 @@ log: LogService;

17

dist/index.js

@@ -8,2 +8,3 @@ import path from 'path';

export const DEFAULT_FTP_PASSWORD_ENV_NAME = 'FTP_PASSWORD';
export const DEFAULT_ENV = {};
/* Architecture Note #1: FTP Service

@@ -74,3 +75,13 @@

*/
async function initFTPService({ FTP, FTP_CONFIG, FTP_POOL, FTP_TIMEOUT, FTP_PASSWORD_ENV_NAME = DEFAULT_FTP_PASSWORD_ENV_NAME, ENV, delay, log, }) {
async function initFTPService({ FTP, FTP_CONFIG, FTP_POOL, FTP_TIMEOUT, FTP_PASSWORD_ENV_NAME = DEFAULT_FTP_PASSWORD_ENV_NAME, ENV = DEFAULT_ENV, delay, log, }) {
const ftpPasswordName = (FTP_PASSWORD_ENV_NAME ||
DEFAULT_FTP_PASSWORD_ENV_NAME);
const ftpPassword = ENV?.[ftpPasswordName];
if ('password' in FTP) {
log('warning', `⚠️ - Setting the password in the FTP config is unsafe.`);
}
if (!('password' in FTP) && !ftpPassword) {
log('error', `❌ - No "${ftpPasswordName}" env var set.`);
throw new YError('E_BAD_FTPEnvVars', ftpPasswordName);
}
/* Architecture Note #1.1: Pool

@@ -87,5 +98,3 @@

...FTP,
...(ENV[FTP_PASSWORD_ENV_NAME]
? { password: ENV[FTP_PASSWORD_ENV_NAME] }
: {}),
...(ftpPassword ? { password: ftpPassword } : {}),
});

@@ -92,0 +101,0 @@ const finalFTPClient = {

@@ -12,3 +12,2 @@ import { describe, test, beforeEach, jest, expect } from '@jest/globals';

user: 'user',
password: 'password',
},

@@ -34,3 +33,2 @@ FTP_TIMEOUT: 30000,

...CONFIG,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: 'password' },

@@ -95,5 +93,9 @@ delay,

const { service: ftp, dispose } = await initFTPService({
...CONFIG,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: 'password' },
...{
...CONFIG,
FTP: {
...CONFIG.FTP,
password: 'password',
},
},
delay,

@@ -108,26 +110,30 @@ log,

}).toMatchInlineSnapshot(`
{
"fileContent": "This is a simple text file!",
"logCalls": [
[
"debug",
"💾 - FTP Successfully connected!",
],
[
"debug",
"💾 - Retrieved a file from FTP:",
"/testfile.txt",
27,
],
[
"debug",
"💾 - Shutting down the FTP pool.",
],
[
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
{
"fileContent": "This is a simple text file!",
"logCalls": [
[
"warning",
"⚠️ - Setting the password in the FTP config is unsafe.",
],
[
"debug",
"💾 - FTP Successfully connected!",
],
[
"debug",
"💾 - Retrieved a file from FTP:",
"/testfile.txt",
27,
],
[
"debug",
"💾 - Shutting down the FTP pool.",
],
[
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
});

@@ -139,3 +145,3 @@ test('should send files', async () => {

FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: '' },
ENV: { FTP_PASSWORD: 'password' },
delay,

@@ -142,0 +148,0 @@ log,

@@ -29,3 +29,3 @@ {

"name": "ftp-service",
"version": "6.0.0",
"version": "6.0.1",
"type": "module",

@@ -32,0 +32,0 @@ "description": "A simple wrapper for a simpler FTP client surface API with pool and retry management.",

@@ -14,3 +14,2 @@ import { describe, test, beforeEach, jest, expect } from '@jest/globals';

user: 'user',
password: 'password',
},

@@ -38,3 +37,2 @@ FTP_TIMEOUT: 30000,

...CONFIG,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: 'password' },

@@ -106,5 +104,9 @@ delay,

const { service: ftp, dispose } = await initFTPService({
...CONFIG,
FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: 'password' },
...{
...CONFIG,
FTP: {
...CONFIG.FTP,
password: 'password',
},
},
delay,

@@ -122,26 +124,30 @@ log,

}).toMatchInlineSnapshot(`
{
"fileContent": "This is a simple text file!",
"logCalls": [
[
"debug",
"💾 - FTP Successfully connected!",
],
[
"debug",
"💾 - Retrieved a file from FTP:",
"/testfile.txt",
27,
],
[
"debug",
"💾 - Shutting down the FTP pool.",
],
[
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
{
"fileContent": "This is a simple text file!",
"logCalls": [
[
"warning",
"⚠️ - Setting the password in the FTP config is unsafe.",
],
[
"debug",
"💾 - FTP Successfully connected!",
],
[
"debug",
"💾 - Retrieved a file from FTP:",
"/testfile.txt",
27,
],
[
"debug",
"💾 - Shutting down the FTP pool.",
],
[
"debug",
"💾 - Disconnecting a FTP service instance.",
],
],
}
`);
});

@@ -154,3 +160,3 @@

FTP_PASSWORD_ENV_NAME: 'FTP_PASSWORD',
ENV: { FTP_PASSWORD: '' },
ENV: { FTP_PASSWORD: 'password' },
delay,

@@ -157,0 +163,0 @@ log,

@@ -17,8 +17,9 @@ import path from 'path';

export const DEFAULT_FTP_PASSWORD_ENV_NAME = 'FTP_PASSWORD';
export const DEFAULT_ENV = {};
export type FTP_ENV<
export type FTPEnvVars<
T extends string extends T
? never
: string = typeof DEFAULT_FTP_PASSWORD_ENV_NAME,
> = Record<T, string>;
> = Partial<Record<T, string>>;

@@ -47,3 +48,3 @@ export type FTPConfig<

> = FTPConfig<T> & {
ENV: FTP_ENV<T>;
ENV?: FTPEnvVars<T>;
delay: DelayService;

@@ -145,6 +146,19 @@ log: LogService;

FTP_PASSWORD_ENV_NAME = DEFAULT_FTP_PASSWORD_ENV_NAME as T,
ENV,
ENV = DEFAULT_ENV,
delay,
log,
}: FTPDependencies<T>): Promise<Provider<FTPService>> {
const ftpPasswordName = (FTP_PASSWORD_ENV_NAME ||
DEFAULT_FTP_PASSWORD_ENV_NAME) as T;
const ftpPassword = ENV?.[ftpPasswordName];
if ('password' in FTP) {
log('warning', `⚠️ - Setting the password in the FTP config is unsafe.`);
}
if (!('password' in FTP) && !ftpPassword) {
log('error', `❌ - No "${ftpPasswordName}" env var set.`);
throw new YError('E_BAD_FTPEnvVars', ftpPasswordName);
}
/* Architecture Note #1.1: Pool

@@ -163,5 +177,3 @@

...FTP,
...(ENV[FTP_PASSWORD_ENV_NAME]
? { password: ENV[FTP_PASSWORD_ENV_NAME] }
: {}),
...(ftpPassword ? { password: ftpPassword } : {}),
});

@@ -168,0 +180,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc