11 Commits

Author SHA1 Message Date
jkunz d2601e33f7 v1.1.0 2026-05-01 22:31:47 +00:00
jkunz 623788ae25 feat(core): add provider defaults, strengthen WebDAV validation, and modernize tests and package metadata 2026-05-01 22:31:47 +00:00
philkunz 157f97cbd7 update description 2024-05-29 14:13:03 +02:00
philkunz c35355a846 1.0.6 2024-04-26 13:51:46 +02:00
philkunz d82d9e4cfa fix(core): update 2024-04-26 13:51:45 +02:00
philkunz 43b5dac24a 1.0.5 2024-04-24 18:24:19 +02:00
philkunz c391c180fd fix(core): update 2024-04-24 18:24:19 +02:00
philkunz 2be31e409b 1.0.4 2024-04-24 18:14:58 +02:00
philkunz c9eb03dc31 fix(core): update 2024-04-24 18:14:57 +02:00
philkunz 2bee288dac 1.0.3 2024-04-24 18:02:21 +02:00
philkunz b538f72004 fix(core): update 2024-04-24 18:02:21 +02:00
17 changed files with 8311 additions and 4163 deletions
+40
View File
@@ -0,0 +1,40 @@
{
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
},
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartexpose",
"shortDescription": "Temporary WebDAV-backed file exposure",
"description": "A TypeScript package for temporarily exposing files through WebDAV-backed public URLs.",
"npmPackagename": "@push.rocks/smartexpose",
"license": "MIT",
"keywords": [
"file exposure",
"temporary URLs",
"WebDAV",
"public files",
"TypeScript",
"task scheduling",
"smartfile",
"file sharing",
"automation",
"node.js"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.\n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.\n\nUse of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District Court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}
+27
View File
@@ -0,0 +1,27 @@
# Changelog
## 2026-05-01 - 1.1.0 - feat(core)
add provider defaults, strengthen WebDAV validation, and modernize tests and package metadata
- Apply instance-level deleteAfterMillis and privateUrl defaults when exposing single files or file arrays
- Throw explicit errors when no provider is configured or when uploaded WebDAV files are missing or publicly unreadable
- Replace the old test setup with node-based tests that cover default option propagation and optional integration runs
- Refresh package metadata, exports, tooling configuration, and README documentation
## 2024-05-29 - 1.0.6 - metadata
Updated project description.
- Refined package or project description metadata.
- Includes version 1.0.6 release tagging from 2024-04-26.
## 2024-04-26 - 1.0.3-1.0.5 - core
Summarized repeated maintenance fixes across patch releases 1.0.3 through 1.0.5.
- Applied the same core update in versions 1.0.3, 1.0.4, and 1.0.5.
- Includes associated release version bumps for each patch release.
## 2024-04-22 - 1.0.1-1.0.2 - core
Summarized repeated maintenance fixes across patch releases 1.0.1 through 1.0.2.
- Applied a core update in versions 1.0.1 and 1.0.2.
- Includes the 1.0.2 release tagging commit.
+22
View File
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Task Venture Capital GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+29 -10
View File
@@ -1,21 +1,40 @@
{
"gitzone": {
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
},
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartexpose",
"description": "a package to expose things to the internet",
"shortDescription": "Temporary WebDAV-backed file exposure",
"description": "A TypeScript package for temporarily exposing files through WebDAV-backed public URLs.",
"npmPackagename": "@push.rocks/smartexpose",
"license": "MIT",
"projectDomain": "push.rocks"
"keywords": [
"file exposure",
"temporary URLs",
"WebDAV",
"public files",
"TypeScript",
"task scheduling",
"smartfile",
"file sharing",
"automation",
"node.js"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.\n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.\n\nUse of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District Court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}
}
+38 -19
View File
@@ -1,41 +1,46 @@
{
"name": "@push.rocks/smartexpose",
"version": "1.0.2",
"version": "1.1.0",
"private": false,
"description": "a package to expose things to the internet",
"description": "A TypeScript package for temporarily exposing files through WebDAV-backed public URLs.",
"exports": {
".": "./dist_ts/index.js"
},
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Task Venture Capital GmbH",
"author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "(tsdoc)"
"test": "tstest test/",
"build": "tsbuild --web",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.25",
"@git.zone/tsbundle": "^2.0.5",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.44",
"@push.rocks/qenv": "^6.0.5",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.7"
"@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsdoc": "^2.0.3",
"@git.zone/tstest": "^3.6.3",
"@push.rocks/qenv": "^6.1.4",
"@types/node": "^25.6.0"
},
"dependencies": {
"@push.rocks/smartfile": "^11.0.14",
"@push.rocks/smartjson": "^5.0.19",
"@push.rocks/smartwebdav": "^1.0.4",
"@push.rocks/taskbuffer": "^3.1.7"
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartfile": "^13.1.3",
"@push.rocks/smartformat": "^1.1.0",
"@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartrequest": "^5.0.3",
"@push.rocks/smartunique": "^3.0.9",
"@push.rocks/smartwebdav": "^1.1.3",
"@push.rocks/taskbuffer": "^8.0.2"
},
"repository": {
"type": "git",
"url": "git+https://code.foss.global/push.rocks/smartexpose.git"
"url": "https://code.foss.global/push.rocks/smartexpose.git"
},
"bugs": {
"url": "https://code.foss.global/push.rocks/smartexpose/issues"
},
"homepage": "https://code.foss.global/push.rocks/smartexpose#readme",
"homepage": "https://code.foss.global/push.rocks/smartexpose",
"browserslist": [
"last 1 chrome versions"
],
@@ -48,7 +53,21 @@
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
".smartconfig.json",
"license",
"npmextra.json",
"readme.md"
],
"keywords": [
"file exposure",
"temporary URLs",
"WebDAV",
"public files",
"TypeScript",
"task scheduling",
"smartfile",
"file sharing",
"automation",
"node.js"
]
}
+7615 -4031
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -2,4 +2,4 @@ required:
- WEBDAV_SERVER_URL
- WEBDAV_SERVER_TOKEN
- WEBDAV_SUB_PATH
- WEBDAV_EXPOSED_BASE_URL
- EXPOSED_BASE_URL
+1
View File
@@ -0,0 +1 @@
+196 -25
View File
@@ -1,31 +1,202 @@
# @push.rocks/smartexpose
a package to expose things to the internet
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartexpose)
* [gitlab.com (source)](https://code.foss.global/push.rocks/smartexpose)
* [github.com (source mirror)](https://github.com/push.rocks/smartexpose)
* [docs (typedoc)](https://push.rocks.gitlab.io/smartexpose/)
Expose in-memory files through short-lived public URLs backed by a WebDAV-accessible storage location. `@push.rocks/smartexpose` is a small TypeScript utility for upload-and-share flows where your app needs to hand another service a temporary URL without permanently publishing the file.
## Status for master
## Issue Reporting and Security
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://code.foss.global/push.rocks/smartexpose/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://code.foss.global/push.rocks/smartexpose/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartexpose)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartexpose)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartexpose)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartexpose)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartexpose)](https://lossless.cloud)
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Usage
Use TypeScript for best in class intellisense
For further information read the linked docs at the top of this readme.
## What It Does
## Legal
> MIT licensed | **&copy;** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
`SmartExpose` accepts `SmartFile` instances, uploads them to a configured provider, verifies that the public URL returns the uploaded bytes, and returns a stable result object containing the public URL, generated file id, and creation status.
The built-in provider is WebDAV-based. Point it at a writable WebDAV folder and an externally reachable base URL for that same folder, and it will handle the upload path generation for you.
## Install
```bash
pnpm add @push.rocks/smartexpose @push.rocks/smartfile
```
## Quick Start
```ts
import { SmartExpose } from '@push.rocks/smartexpose';
import { SmartFileFactory } from '@push.rocks/smartfile';
const expose = new SmartExpose({
webdav: {
webdavCredentials: {
serverUrl: 'https://webdav.example.com/',
password: process.env.WEBDAV_SERVER_TOKEN!,
},
webdavSubPath: '/public/temp-share',
},
exposedBaseUrl: 'https://cdn.example.com/',
deleteAfterMillis: 30_000,
privateUrl: true,
});
await expose.start();
const smartfileFactory = new SmartFileFactory(undefined);
const result = await expose.exposeFile({
smartFile: smartfileFactory.fromString('report.txt', 'hello from smartexpose', 'utf8'),
deleteAfterMillis: 10_000,
});
console.log(result.url);
// -> https://cdn.example.com/public/temp-share/<generated-id>
await expose.stop();
```
## Core Concepts
### `SmartExpose`
`SmartExpose` is the main orchestration class. It owns the provider, starts provider housekeeping, exposes single files or arrays of files, and stops scheduled tasks when you are done.
```ts
import { SmartExpose } from '@push.rocks/smartexpose';
const expose = new SmartExpose({
exposedBaseUrl: 'https://cdn.example.com/',
webdav: {
webdavCredentials: {
serverUrl: 'https://webdav.example.com/',
password: process.env.WEBDAV_SERVER_TOKEN!,
},
webdavSubPath: '/public/temp-share',
},
});
await expose.start();
```
### WebDAV Provider
The default provider uploads every exposed file into `webdavSubPath` under a generated id. The public URL is assembled from `exposedBaseUrl` and the generated WebDAV file path.
The provider verifies successful exposure by requesting the assembled public URL and comparing the response body with the uploaded file contents. If the public endpoint cannot serve the file, `exposeFile()` throws instead of returning a broken URL.
## Configuration
```ts
interface ISmartExposeOptions {
exposedBaseUrl: string;
deleteAfterMillis?: number;
privateUrl?: boolean;
webdav?: {
webdavCredentials: IWebdavClientOptions;
webdavSubPath: string;
};
}
```
| Option | Required | Description |
| --- | --- | --- |
| `exposedBaseUrl` | Yes | Public base URL that maps to the WebDAV location. Returned URLs are built from this value and the generated file path. |
| `webdav.webdavCredentials` | Yes for WebDAV | Credentials passed to `@push.rocks/smartwebdav`. |
| `webdav.webdavSubPath` | Yes for WebDAV | Remote WebDAV directory used for exposed files. It is created if needed. |
| `deleteAfterMillis` | No | Default intended lifetime for exposed files. Per-call values can override it where supported. |
| `privateUrl` | No | Marks the requested exposure as private-by-design. The current WebDAV provider accepts the flag as part of the shared provider API. |
## Exposing Files
### Single File
```ts
const result = await expose.exposeFile({
smartFile,
deleteAfterMillis: 60_000,
privateUrl: true,
});
console.log(result);
// {
// url: 'https://cdn.example.com/public/temp-share/<generated-id>',
// id: '<generated-id>',
// status: 'created'
// }
```
### Multiple Files
```ts
const results = await expose.exposeFileArray({
smartFiles: [firstSmartFile, secondSmartFile],
deleteAfterMillis: 60_000,
});
for (const exposedFile of results) {
console.log(exposedFile.id, exposedFile.url);
}
```
`exposeFileArray()` processes the files through the same provider path as `exposeFile()` and returns one result per file.
## Cleanup
Files can be scheduled for deletion by passing `deleteAfterMillis` to `exposeFile()` or `exposeFileArray()`.
If you need provider-level cleanup, the WebDAV provider also implements:
```ts
await expose.provider?.deleteFileById(fileId);
await expose.provider?.wipeAll();
```
`deleteFileById()` returns `deleted`, `failed`, or `notfound`. `wipeAll()` empties the configured WebDAV exposure directory and returns a deletion result for each previously listed entry.
## Testing Integration Flows
The test suite includes WebDAV integration tests that are skipped by default. To run them, set:
```bash
SMARTEXPOSE_RUN_INTEGRATION_TESTS=true
WEBDAV_SERVER_URL=https://webdav.example.com/
WEBDAV_SERVER_TOKEN=...
WEBDAV_SUB_PATH=/public/temp-share
EXPOSED_BASE_URL=https://cdn.example.com/
pnpm test
```
## API Surface
`@push.rocks/smartexpose` exports:
| Export | Purpose |
| --- | --- |
| `SmartExpose` | Main class for configuring, starting, exposing files, and stopping exposure providers. |
| `ISmartExposeOptions` | Constructor options for `SmartExpose`. |
| `ExposeProvider` | Abstract provider interface for custom exposure backends. |
## Availability and Links
| Resource | Link |
| --- | --- |
| npm package | [npmjs.com/package/@push.rocks/smartexpose](https://www.npmjs.com/package/@push.rocks/smartexpose) |
| Source | [code.foss.global/push.rocks/smartexpose](https://code.foss.global/push.rocks/smartexpose) |
| GitHub mirror | [github.com/push.rocks/smartexpose](https://github.com/push.rocks/smartexpose) |
## License and Legal Information
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
### Company Information
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
+138
View File
@@ -0,0 +1,138 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as qenv from '@push.rocks/qenv';
import * as smartfile from '@push.rocks/smartfile';
import * as smartexpose from '../ts/index.js';
const testQenv = new qenv.Qenv('./', './.nogit/');
let testSmartexpose: smartexpose.SmartExpose;
const shouldRunIntegrationTests = () => process.env.SMARTEXPOSE_RUN_INTEGRATION_TESTS === 'true';
class TestExposeProvider extends smartexpose.ExposeProvider {
public receivedFileOptions: Parameters<smartexpose.ExposeProvider['exposeFile']>[0] | undefined;
public receivedFileArrayOptions: Parameters<smartexpose.ExposeProvider['exposeFileArray']>[0] | undefined;
public async houseKeeping(): Promise<void> {}
public async exposeFile(optionsArg: Parameters<smartexpose.ExposeProvider['exposeFile']>[0]) {
this.receivedFileOptions = optionsArg;
return {
url: 'https://example.com/test',
id: 'test',
status: 'created' as const,
};
}
public async exposeFileArray(
optionsArg: Parameters<smartexpose.ExposeProvider['exposeFileArray']>[0]
) {
this.receivedFileArrayOptions = optionsArg;
return [
{
url: 'https://example.com/test',
id: 'test',
status: 'created' as const,
},
];
}
public async start(): Promise<void> {}
public async stop(): Promise<void> {}
public async wipeAll(): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }[]> {
return [];
}
public async deleteFileById(
idArg: string
): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }> {
return {
id: idArg,
status: 'deleted',
};
}
}
const requireEnv = async (envNameArg: string): Promise<string> => {
const envValue = await testQenv.getEnvVarOnDemand(envNameArg);
if (!envValue) {
throw new Error(`Missing required environment variable: ${envNameArg}`);
}
return envValue;
};
tap.test('should apply constructor defaults when exposing files', async () => {
const smartExpose = new smartexpose.SmartExpose({
exposedBaseUrl: 'https://example.com/',
deleteAfterMillis: 1234,
privateUrl: true,
});
const testProvider = new TestExposeProvider();
smartExpose.provider = testProvider;
const smartfileFactory = new smartfile.SmartFileFactory(undefined);
const smartFile = smartfileFactory.fromString('okidoks', 'hi there', 'utf8');
await smartExpose.exposeFile({ smartFile });
expect(testProvider.receivedFileOptions?.deleteAfterMillis).toEqual(1234);
expect(testProvider.receivedFileOptions?.privateUrl).toEqual(true);
await smartExpose.exposeFileArray({ smartFiles: [smartFile] });
expect(testProvider.receivedFileArrayOptions?.deleteAfterMillis).toEqual(1234);
expect(testProvider.receivedFileArrayOptions?.privateUrl).toEqual(true);
});
tap.test('should create a valid instance of smartexpose using Webdav', async () => {
if (!shouldRunIntegrationTests()) {
console.log('Skipping SmartExpose integration test. Set SMARTEXPOSE_RUN_INTEGRATION_TESTS=true to run it.');
return;
}
testSmartexpose = new smartexpose.SmartExpose({
webdav: {
webdavCredentials: {
serverUrl: await requireEnv('WEBDAV_SERVER_URL'),
password: await requireEnv('WEBDAV_SERVER_TOKEN'),
},
webdavSubPath: await requireEnv('WEBDAV_SUB_PATH'),
},
deleteAfterMillis: 30000,
privateUrl: true,
exposedBaseUrl: await requireEnv('EXPOSED_BASE_URL'),
});
await testSmartexpose.start();
expect(testSmartexpose).toBeInstanceOf(smartexpose.SmartExpose);
});
tap.test('should expose a file', async () => {
if (!shouldRunIntegrationTests()) {
return;
}
const smartfileFactory = new smartfile.SmartFileFactory(undefined);
await testSmartexpose.exposeFile({
smartFile: smartfileFactory.fromString('okidoks', 'hi there', 'utf8'),
deleteAfterMillis: 10000,
privateUrl: true,
});
});
tap.test('should delete the file', async (toolsArg) => {
if (!shouldRunIntegrationTests()) {
return;
}
await toolsArg.delayFor(11000);
});
tap.test('should stop the smartexpose', async () => {
if (!shouldRunIntegrationTests()) {
return;
}
await testSmartexpose.stop();
});
export default tap.start();
-24
View File
@@ -1,24 +0,0 @@
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import * as qenv from '@push.rocks/qenv';
const testQenv = new qenv.Qenv('./', './.nogit/');
import * as smartexpose from '../ts/index.js'
let testSmartexpose: smartexpose.SmartExpose;
tap.test('should create a valid instance of smartexpose using Webdav', async () => {
testSmartexpose = await smartexpose.SmartExpose.createWithWebdav({
webdavCredentials: {
serverUrl: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_URL'),
password: await testQenv.getEnvVarOnDemand('WEBDAV_PASSWORD'),
},
exposedBaseUrl: await testQenv.getEnvVarOnDemand('WEBDAV_EXPOSED_BASE_URL'),
webdavSubPath: await testQenv.getEnvVarOnDemand('WEBDAV_SUB_PATH'),
exposeOptions: {
deleteAfterMillis: 30000,
privateUrl: true,
}
})
}
tap.start()
+3 -3
View File
@@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartexpose',
version: '1.0.2',
description: 'a package to expose things to the internet'
version: '1.1.0',
description: 'A TypeScript package for temporarily exposing files through WebDAV-backed public URLs.'
}
+22 -11
View File
@@ -2,8 +2,8 @@ import * as plugins from './plugins.js';
/**
* An expose provider provides a standardized interface for exposing data
* Note: SmartExpose comes with some default implmentations of ExposeProvider
*
* Note: SmartExpose comes with some default implementations of ExposeProvider
*
* notably:
* - WebDavExposeProvider
*/
@@ -13,21 +13,31 @@ export abstract class ExposeProvider {
* Should take care of any housekeeping required to keep things in a healthy state.
*/
public abstract houseKeeping(): Promise<void>;
/**
* should return a url with info about how to access the file
* @param optionsArg
* @param optionsArg
*/
public abstract exposeFile(optionsArg: {
smartFile: plugins.smartfile.SmartFile,
deleteAfterMillis?: number,
privateUrl?: boolean, // wether the returned url should be private by design
smartFile: plugins.smartfile.SmartFile;
deleteAfterMillis?: number;
privateUrl?: boolean; // whether the returned url should be private by design
}): Promise<{
url: string;
id: string;
status: 'created' | 'updated';
}>;
public abstract exposeFileArray(optionsArg: {
smartFiles: plugins.smartfile.SmartFile[];
deleteAfterMillis?: number;
privateUrl?: boolean;
}): Promise<{
url: string;
id: string;
status: 'created' | 'updated';
}[]>;
public abstract start(): Promise<void>;
public abstract stop(): Promise<void>;
@@ -35,9 +45,10 @@ export abstract class ExposeProvider {
public abstract wipeAll(): Promise<{
id: string;
status: 'deleted' | 'failed' | 'notfound';
}[]>
public abstract wipeFileById(idArg: string): Promise<{
}[]>;
public abstract deleteFileById(idArg: string): Promise<{
id: string;
status: 'deleted' | 'failed' | 'notfound';
}>
}
}>;
}
+115 -16
View File
@@ -1,54 +1,153 @@
import { ExposeProvider } from './classes.exposeprovider.js';
import type { SmartExpose } from './classes.smartexpose.js';
import * as plugins from './plugins.js';
export interface IWebdavExposeProviderOptions {
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions,
webdavSubPath: string,
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions;
webdavSubPath: string;
}
export class WebDavExposeProvider extends ExposeProvider {
public webdavClient: plugins.smartwebdav.WebdavClient;
public smartExposeRef: SmartExpose;
public webdavClient!: plugins.smartwebdav.WebdavClient;
public options: IWebdavExposeProviderOptions;
constructor(optionsArg: IWebdavExposeProviderOptions) {
constructor(smartexposeRefArg: SmartExpose, optionsArg: IWebdavExposeProviderOptions) {
super();
this.smartExposeRef = smartexposeRefArg;
this.options = optionsArg;
}
public async houseKeeping (): Promise<void> {
public async houseKeeping(): Promise<void> {
const directoryContents = await this.webdavClient.listDirectory(this.options.webdavSubPath);
for (const fileStat of directoryContents) {
// lets read the meta.json file
if (fileStat.filename.endsWith('.json')) {
}
}
}
public async ensureBaseDir (): Promise<void> {
public async getFilePathById(idArg: string): Promise<string> {
return plugins.smartpath.join(this.options.webdavSubPath, idArg);
}
public async ensureBaseDir(): Promise<void> {
await this.webdavClient.ensureDirectory(this.options.webdavSubPath);
}
public async start (): Promise<void> {
public async start(): Promise<void> {
this.webdavClient = new plugins.smartwebdav.WebdavClient(this.options.webdavCredentials);
await this.ensureBaseDir();
await this.houseKeeping();
this.smartExposeRef.taskmanager.addAndScheduleTask(
new plugins.taskbuffer.Task({
name: 'webdavHousekeeping',
taskFunction: async () => {
await this.houseKeeping();
},
}),
'0 * * * * *'
);
}
public async stop (): Promise<void> {
public async stop(): Promise<void> {
// Nothing to do here
}
public async exposeFile (optionsArg: { smartFile: plugins.smartfile.SmartFile; deleteAfterMillis?: number; privateUrl?: boolean; }): Promise<{ url: string; id: string; status: 'created' | 'updated'; }> {
public async exposeFile(
optionsArg: Parameters<ExposeProvider['exposeFile']>[0]
): Promise<{ url: string; id: string; status: 'created' | 'updated' }> {
await this.ensureBaseDir();
const fileId = plugins.smartunique.shortId(30);
console.log(
`Expsing file under id: ${fileId}. (${plugins.smartformat.prettyBytes(
optionsArg.smartFile.contents.length
)})`
);
const webdavFilePath = await this.getFilePathById(fileId);
const fileToUpload = new plugins.smartfile.SmartFile({
path: webdavFilePath,
contentBuffer: optionsArg.smartFile.contents,
base: '/',
});
await this.webdavClient.uploadSmartFileArray([fileToUpload]);
console.log(`checking file presence: ${webdavFilePath}`);
const existsOnWebdav = await this.webdavClient.wdClient.exists(webdavFilePath);
if (!existsOnWebdav) {
throw new Error(`Uploaded file does not exist on WebDAV: ${webdavFilePath}`);
}
const publicUrl = plugins.smartpath.join(
this.smartExposeRef.options.exposedBaseUrl,
webdavFilePath
);
console.log(`checking for file at ${publicUrl}`);
const response = await plugins.smartrequest.SmartRequest.create()
.url(publicUrl)
.accept('binary')
.get();
const responseBuffer = Buffer.from(await response.arrayBuffer());
if (!responseBuffer.equals(fileToUpload.contents)) {
throw new Error(`Public URL did not return the uploaded file contents: ${publicUrl}`);
}
if (optionsArg.deleteAfterMillis) {
console.log(
`Scheduling deletion of file with id: ${fileId} in ${optionsArg.deleteAfterMillis}ms...`
);
void plugins.smartdelay.delayFor(optionsArg.deleteAfterMillis).then(async () => {
console.log(`Deleting file with id: ${fileId}...`);
await this.deleteFileById(fileId);
console.log(`Deleted file with id: ${fileId}`);
});
}
return {
url: publicUrl,
id: fileId,
status: 'created',
};
}
public async wipeAll (): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound'; }[]> {
public async exposeFileArray(
optionsArg: Parameters<ExposeProvider['exposeFileArray']>[0]
): ReturnType<ExposeProvider['exposeFileArray']> {
const returnArray: Awaited<ReturnType<ExposeProvider['exposeFile']>>[] = [];
for (const smartFile of optionsArg.smartFiles) {
returnArray.push(
await this.exposeFile({
smartFile,
deleteAfterMillis: optionsArg.deleteAfterMillis,
privateUrl: optionsArg.privateUrl,
})
);
}
return returnArray;
}
public async wipeFileById (idArg: string): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound'; }> {
public async wipeAll(): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }[]> {
const directoryContents = await this.webdavClient.listDirectory(this.options.webdavSubPath);
await this.webdavClient.ensureEmptyDirectory(this.options.webdavSubPath);
return directoryContents.map((contentArg) => {
return {
id: contentArg.filename,
status: 'deleted',
};
});
}
}
public async deleteFileById(
idArg: string
): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }> {
const filePath = await this.getFilePathById(idArg);
if (!(await this.webdavClient.wdClient.exists(filePath))) {
return {
id: idArg,
status: 'notfound',
};
}
await this.webdavClient.deleteFile(filePath);
return {
id: idArg,
status: 'deleted',
};
}
}
+50 -19
View File
@@ -3,31 +3,62 @@ import { WebDavExposeProvider } from './classes.exposeprovider.webdav.js';
import * as plugins from './plugins.js';
export interface ISmartExposeOptions {
deleteAfterMillis?: number,
privateUrl?: boolean,
deleteAfterMillis?: number;
privateUrl?: boolean;
exposedBaseUrl: string;
webdav?: {
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions;
webdavSubPath: string;
};
}
export class SmartExpose {
// STATIC
public static createWithWebdav(optionsArg: {
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions,
webdavSubPath: string,
exposedBaseUrl: string,
exposeOptions: ISmartExposeOptions,
}) {
const provider = new WebDavExposeProvider({
webdavCredentials: optionsArg.webdavCredentials,
webdavSubPath: optionsArg.webdavSubPath,
});
const smartexposeInstance = new SmartExpose(provider, optionsArg.exposeOptions);
return smartexposeInstance;
}
// INSTANCE
public taskmanager: plugins.taskbuffer.TaskManager;
public taskmanager!: plugins.taskbuffer.TaskManager;
public provider!: ExposeProvider;
public options: ISmartExposeOptions;
constructor(provider: ExposeProvider, optionsArg: ISmartExposeOptions) {
constructor(optionsArg: ISmartExposeOptions) {
this.options = optionsArg;
}
private getProvider(): ExposeProvider {
if (!this.provider) {
throw new Error('No expose provider has been configured.');
}
return this.provider;
}
public async start() {
this.taskmanager = new plugins.taskbuffer.TaskManager();
if (this.options.webdav) {
this.provider = new WebDavExposeProvider(this, {
webdavCredentials: this.options.webdav.webdavCredentials,
webdavSubPath: this.options.webdav.webdavSubPath,
});
}
await this.getProvider().start();
this.taskmanager.start();
}
public async stop() {
await this.getProvider().stop();
this.taskmanager.stop();
}
public async exposeFile(optionsArg: Parameters<ExposeProvider['exposeFile']>[0]) {
return this.getProvider().exposeFile({
...optionsArg,
deleteAfterMillis: optionsArg.deleteAfterMillis ?? this.options.deleteAfterMillis,
privateUrl: optionsArg.privateUrl ?? this.options.privateUrl,
});
}
public async exposeFileArray(optionsArg: Parameters<ExposeProvider['exposeFileArray']>[0]) {
return this.getProvider().exposeFileArray({
...optionsArg,
deleteAfterMillis: optionsArg.deleteAfterMillis ?? this.options.deleteAfterMillis,
privateUrl: optionsArg.privateUrl ?? this.options.privateUrl,
});
}
}
+11 -3
View File
@@ -1,12 +1,20 @@
// @push.rocks scope
import * as smartdelay from '@push.rocks/smartdelay';
import * as smartfile from '@push.rocks/smartfile';
import * as smartjson from '@push.rocks/smartjson';
import * as smartformat from '@push.rocks/smartformat';
import * as smartpath from '@push.rocks/smartpath';
import * as smartrequest from '@push.rocks/smartrequest';
import * as smartunique from '@push.rocks/smartunique';
import * as smartwebdav from '@push.rocks/smartwebdav';
import * as taskbuffer from '@push.rocks/taskbuffer';
export {
smartdelay,
smartfile,
smartjson,
smartformat,
smartpath,
smartrequest,
smartunique,
smartwebdav,
taskbuffer,
}
};
+3 -1
View File
@@ -5,8 +5,10 @@
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": [
"dist_*/**/*.d.ts"