Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d2601e33f7 | |||
| 623788ae25 | |||
| 157f97cbd7 | |||
| c35355a846 | |||
| d82d9e4cfa |
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
+29
-10
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-24
@@ -1,47 +1,46 @@
|
||||
{
|
||||
"name": "@push.rocks/smartexpose",
|
||||
"version": "1.0.5",
|
||||
"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/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartexpect": "^1.0.21",
|
||||
"@push.rocks/smartfile": "^11.0.14",
|
||||
"@push.rocks/smartformat": "^1.0.3",
|
||||
"@push.rocks/smartjson": "^5.0.19",
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
"@push.rocks/smartrequest": "^2.0.22",
|
||||
"@push.rocks/smartunique": "^3.0.8",
|
||||
"@push.rocks/smartwebdav": "^1.1.2",
|
||||
"@push.rocks/taskbuffer": "^3.1.7"
|
||||
"@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"
|
||||
],
|
||||
@@ -54,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"
|
||||
]
|
||||
}
|
||||
|
||||
Generated
+7610
-4062
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
|
||||
@@ -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 | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](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 | **©** [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.
|
||||
|
||||
@@ -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();
|
||||
@@ -1,44 +0,0 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
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 = new smartexpose.SmartExpose({
|
||||
webdav: {
|
||||
webdavCredentials: {
|
||||
serverUrl: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_URL'),
|
||||
password: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_TOKEN'),
|
||||
},
|
||||
webdavSubPath: await testQenv.getEnvVarOnDemand('WEBDAV_SUB_PATH'),
|
||||
},
|
||||
deleteAfterMillis: 30000,
|
||||
privateUrl: true,
|
||||
exposedBaseUrl: await testQenv.getEnvVarOnDemand('EXPOSED_BASE_URL'),
|
||||
});
|
||||
await testSmartexpose.start();
|
||||
expect(testSmartexpose).toBeInstanceOf(smartexpose.SmartExpose);
|
||||
});
|
||||
|
||||
tap.test('should expose a file', async () => {
|
||||
await testSmartexpose.exposeFile({
|
||||
smartFile: await smartfile.SmartFile.fromString('okidoks', 'hi there', 'utf8'),
|
||||
deleteAfterMillis: 10000,
|
||||
privateUrl: true,
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should delete the file', async (toolsArg) => {
|
||||
await toolsArg.delayFor(11000);
|
||||
});
|
||||
|
||||
tap.test('should stop the smartexpose', async () => {
|
||||
await testSmartexpose.stop();
|
||||
})
|
||||
|
||||
export default tap.start();
|
||||
@@ -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.5',
|
||||
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.'
|
||||
}
|
||||
|
||||
@@ -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 deleteFileById(idArg: string): Promise<{
|
||||
id: string;
|
||||
status: 'deleted' | 'failed' | 'notfound';
|
||||
}>
|
||||
}
|
||||
}>;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface IWebdavExposeProviderOptions {
|
||||
|
||||
export class WebDavExposeProvider extends ExposeProvider {
|
||||
public smartExposeRef: SmartExpose;
|
||||
public webdavClient: plugins.smartwebdav.WebdavClient;
|
||||
public webdavClient!: plugins.smartwebdav.WebdavClient;
|
||||
public options: IWebdavExposeProviderOptions;
|
||||
|
||||
constructor(smartexposeRefArg: SmartExpose, optionsArg: IWebdavExposeProviderOptions) {
|
||||
@@ -39,42 +39,63 @@ export class WebDavExposeProvider extends ExposeProvider {
|
||||
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 * * * * *')
|
||||
this.smartExposeRef.taskmanager.addAndScheduleTask(
|
||||
new plugins.taskbuffer.Task({
|
||||
name: 'webdavHousekeeping',
|
||||
taskFunction: async () => {
|
||||
await this.houseKeeping();
|
||||
},
|
||||
}),
|
||||
'0 * * * * *'
|
||||
);
|
||||
}
|
||||
|
||||
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)
|
||||
})`);
|
||||
console.log(
|
||||
`Expsing file under id: ${fileId}. (${plugins.smartformat.prettyBytes(
|
||||
optionsArg.smartFile.contents.length
|
||||
)})`
|
||||
);
|
||||
const webdavFilePath = await this.getFilePathById(fileId);
|
||||
const fileToUpload = await plugins.smartfile.SmartFile.fromBuffer(webdavFilePath, optionsArg.smartFile.contents);
|
||||
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);
|
||||
const publicUrl = plugins.smartpath.join(this.smartExposeRef.options.exposedBaseUrl, webdavFilePath);
|
||||
console.log(`cehcking for file at ${publicUrl}`)
|
||||
const response = await plugins.smartrequest.getBinary(publicUrl);
|
||||
plugins.smartexpect.expect(response.body).toEqual(fileToUpload.contents);
|
||||
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...`);
|
||||
plugins.smartdelay.delayFor(optionsArg.deleteAfterMillis).then(() => {
|
||||
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}...`);
|
||||
this.deleteFileById(fileId);
|
||||
await this.deleteFileById(fileId);
|
||||
console.log(`Deleted file with id: ${fileId}`);
|
||||
});
|
||||
}
|
||||
@@ -85,6 +106,22 @@ export class WebDavExposeProvider extends ExposeProvider {
|
||||
};
|
||||
}
|
||||
|
||||
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 wipeAll(): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }[]> {
|
||||
const directoryContents = await this.webdavClient.listDirectory(this.options.webdavSubPath);
|
||||
await this.webdavClient.ensureEmptyDirectory(this.options.webdavSubPath);
|
||||
@@ -100,7 +137,7 @@ export class WebDavExposeProvider extends ExposeProvider {
|
||||
idArg: string
|
||||
): Promise<{ id: string; status: 'deleted' | 'failed' | 'notfound' }> {
|
||||
const filePath = await this.getFilePathById(idArg);
|
||||
if (!this.webdavClient.wdClient.exists(filePath)) {
|
||||
if (!(await this.webdavClient.wdClient.exists(filePath))) {
|
||||
return {
|
||||
id: idArg,
|
||||
status: 'notfound',
|
||||
|
||||
+30
-11
@@ -3,25 +3,32 @@ import { WebDavExposeProvider } from './classes.exposeprovider.webdav.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export interface ISmartExposeOptions {
|
||||
deleteAfterMillis?: number,
|
||||
privateUrl?: boolean,
|
||||
exposedBaseUrl: string,
|
||||
deleteAfterMillis?: number;
|
||||
privateUrl?: boolean;
|
||||
exposedBaseUrl: string;
|
||||
webdav?: {
|
||||
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions,
|
||||
webdavSubPath: string,
|
||||
}
|
||||
webdavCredentials: plugins.smartwebdav.IWebdavClientOptions;
|
||||
webdavSubPath: string;
|
||||
};
|
||||
}
|
||||
|
||||
export class SmartExpose {
|
||||
// INSTANCE
|
||||
public taskmanager: plugins.taskbuffer.TaskManager;
|
||||
public provider: ExposeProvider;
|
||||
public taskmanager!: plugins.taskbuffer.TaskManager;
|
||||
public provider!: ExposeProvider;
|
||||
public options: 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) {
|
||||
@@ -30,16 +37,28 @@ export class SmartExpose {
|
||||
webdavSubPath: this.options.webdav.webdavSubPath,
|
||||
});
|
||||
}
|
||||
await this.provider.start();
|
||||
await this.getProvider().start();
|
||||
this.taskmanager.start();
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.provider.stop();
|
||||
await this.getProvider().stop();
|
||||
this.taskmanager.stop();
|
||||
}
|
||||
|
||||
public async exposeFile(optionsArg: Parameters<ExposeProvider['exposeFile']>[0]) {
|
||||
return this.provider.exposeFile(optionsArg);
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -1,9 +1,7 @@
|
||||
// @push.rocks scope
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartexpect from '@push.rocks/smartexpect';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartformat from '@push.rocks/smartformat';
|
||||
import * as smartjson from '@push.rocks/smartjson';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
import * as smartunique from '@push.rocks/smartunique';
|
||||
@@ -12,13 +10,11 @@ import * as taskbuffer from '@push.rocks/taskbuffer';
|
||||
|
||||
export {
|
||||
smartdelay,
|
||||
smartexpect,
|
||||
smartfile,
|
||||
smartformat,
|
||||
smartjson,
|
||||
smartpath,
|
||||
smartrequest,
|
||||
smartunique,
|
||||
smartwebdav,
|
||||
taskbuffer,
|
||||
}
|
||||
};
|
||||
|
||||
+3
-1
@@ -5,8 +5,10 @@
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
"verbatimModuleSyntax": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
|
||||
Reference in New Issue
Block a user