@nu-art/ts-short-url-backend 0.400.5
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/_entity/short-url/ModuleBE_ShortUrlDB.d.ts +13 -0
- package/_entity/short-url/ModuleBE_ShortUrlDB.js +28 -0
- package/_entity/short-url/index.d.ts +3 -0
- package/_entity/short-url/index.js +3 -0
- package/_entity/short-url/module-pack.d.ts +2 -0
- package/_entity/short-url/module-pack.js +4 -0
- package/_entity/short-url/permissions.d.ts +9 -0
- package/_entity/short-url/permissions.js +22 -0
- package/function-module/Module_ShortUrlResolver.d.ts +10 -0
- package/function-module/Module_ShortUrlResolver.js +36 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +67 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DBProto_ShortUrl } from '@nu-art/ts-short-url-shared';
|
|
2
|
+
import { DBApiConfigV3, ModuleBE_BaseDB } from '@nu-art/thunderstorm-backend';
|
|
3
|
+
type Config = DBApiConfigV3<DBProto_ShortUrl> & {
|
|
4
|
+
BaseShortUrl: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class ModuleBE_ShortUrlDB_Class extends ModuleBE_BaseDB<DBProto_ShortUrl, Config> {
|
|
7
|
+
constructor();
|
|
8
|
+
init(): void;
|
|
9
|
+
private getShortUrl;
|
|
10
|
+
protected preWriteProcessing(dbInstance: DBProto_ShortUrl['uiType'], originalDbInstance: DBProto_ShortUrl['dbType'], transaction?: FirebaseFirestore.Transaction): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare const ModuleBE_ShortUrlDB: ModuleBE_ShortUrlDB_Class;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ApiDef_ShortUrl, DBDef_ShortUrl } from '@nu-art/ts-short-url-shared';
|
|
2
|
+
import { addRoutes, createQueryServerApi, ModuleBE_BaseDB } from '@nu-art/thunderstorm-backend';
|
|
3
|
+
import { generateShortURL } from '@nu-art/ts-common';
|
|
4
|
+
import { HttpCodes } from '@nu-art/ts-common/core/exceptions/http-codes';
|
|
5
|
+
export class ModuleBE_ShortUrlDB_Class extends ModuleBE_BaseDB {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(DBDef_ShortUrl);
|
|
8
|
+
}
|
|
9
|
+
init() {
|
|
10
|
+
super.init();
|
|
11
|
+
addRoutes([
|
|
12
|
+
createQueryServerApi(ApiDef_ShortUrl._v1.getShortUrl, this.getShortUrl)
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
getShortUrl = async (request) => {
|
|
16
|
+
const dbDoc = await this.query.unique(request._id);
|
|
17
|
+
if (!dbDoc)
|
|
18
|
+
throw HttpCodes._5XX.INTERNAL_SERVER_ERROR(`db doc with id ${request._id} not found`);
|
|
19
|
+
return {
|
|
20
|
+
shortUrl: `${this.config.BaseShortUrl}${dbDoc._shortUrl}`
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
async preWriteProcessing(dbInstance, originalDbInstance, transaction) {
|
|
24
|
+
if (!dbInstance._shortUrl)
|
|
25
|
+
dbInstance._shortUrl = generateShortURL();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const ModuleBE_ShortUrlDB = new ModuleBE_ShortUrlDB_Class();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModuleBE_ShortUrlDB } from './ModuleBE_ShortUrlDB.js';
|
|
2
|
+
import { createApisForDBModuleV3 } from '@nu-art/thunderstorm-backend';
|
|
3
|
+
import { Module_ShortUrlResolver } from '../../function-module/Module_ShortUrlResolver.js';
|
|
4
|
+
export const ModulePackBE_ShortUrlDB = [ModuleBE_ShortUrlDB, Module_ShortUrlResolver, createApisForDBModuleV3(ModuleBE_ShortUrlDB)];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PermissionKey_BE } from '@nu-art/permissions-backend/PermissionKey_BE';
|
|
2
|
+
import { DefaultDef_Package } from '@nu-art/permissions-backend';
|
|
3
|
+
export declare const Domain_ShortUrl: Readonly<{
|
|
4
|
+
_id: "8a7614bc128ee1fb6ddf896c46922ab3";
|
|
5
|
+
namespace: "short-url";
|
|
6
|
+
}>;
|
|
7
|
+
export declare const PermissionKeyBE_ShortUrlView: PermissionKey_BE<"permission-key--short-url-view">;
|
|
8
|
+
export declare const PermissionKeyBE_ShortUrlEdit: PermissionKey_BE<"permission-key--short-url-edit">;
|
|
9
|
+
export declare const Permissions_ShortUrl: DefaultDef_Package;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DefaultAccessLevel_Read, DefaultAccessLevel_Write, DuplicateDefaultAccessLevels } from '@nu-art/permissions-shared';
|
|
2
|
+
import { defaultValueResolver, PermissionKey_BE } from '@nu-art/permissions-backend/PermissionKey_BE';
|
|
3
|
+
import { ModuleBE_ShortUrlDB } from './ModuleBE_ShortUrlDB.js';
|
|
4
|
+
import { DomainNamespace_ShortUrl, PermissionKey_ShortUrlEdit, PermissionKey_ShortUrlView } from '@nu-art/ts-short-url-shared';
|
|
5
|
+
export const Domain_ShortUrl = Object.freeze({
|
|
6
|
+
_id: '8a7614bc128ee1fb6ddf896c46922ab3',
|
|
7
|
+
namespace: DomainNamespace_ShortUrl
|
|
8
|
+
});
|
|
9
|
+
export const PermissionKeyBE_ShortUrlView = new PermissionKey_BE(PermissionKey_ShortUrlView, () => defaultValueResolver(DomainNamespace_ShortUrl, DefaultAccessLevel_Read.value));
|
|
10
|
+
export const PermissionKeyBE_ShortUrlEdit = new PermissionKey_BE(PermissionKey_ShortUrlEdit, () => defaultValueResolver(DomainNamespace_ShortUrl, DefaultAccessLevel_Write.value));
|
|
11
|
+
export const Permissions_ShortUrl = {
|
|
12
|
+
name: Domain_ShortUrl.namespace,
|
|
13
|
+
domains: [
|
|
14
|
+
{
|
|
15
|
+
...Domain_ShortUrl,
|
|
16
|
+
levels: [...DuplicateDefaultAccessLevels(Domain_ShortUrl._id)],
|
|
17
|
+
dbNames: [
|
|
18
|
+
ModuleBE_ShortUrlDB.dbDef
|
|
19
|
+
].map(dbDef => dbDef.dbKey)
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleBE_ExpressFunction_V2 } from '@nu-art/firebase-backend';
|
|
2
|
+
import { Express } from 'express';
|
|
3
|
+
import { HttpsFunction } from 'firebase-functions/v2/https';
|
|
4
|
+
declare class Module_ShortUrlResolver_Class extends ModuleBE_ExpressFunction_V2 {
|
|
5
|
+
constructor(name?: string);
|
|
6
|
+
private handleError;
|
|
7
|
+
protected createFunction(_express: Express): HttpsFunction;
|
|
8
|
+
}
|
|
9
|
+
export declare const Module_ShortUrlResolver: Module_ShortUrlResolver_Class;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ModuleBE_ExpressFunction_V2 } from '@nu-art/firebase-backend';
|
|
2
|
+
import { tsValidateResult, tsValidateShortUrl } from '@nu-art/ts-common';
|
|
3
|
+
import { HttpCodes } from '@nu-art/ts-common/core/exceptions/http-codes';
|
|
4
|
+
import { ModuleBE_ShortUrlDB } from '../_entity/short-url/ModuleBE_ShortUrlDB.js';
|
|
5
|
+
class Module_ShortUrlResolver_Class extends ModuleBE_ExpressFunction_V2 {
|
|
6
|
+
constructor(name = 'url') {
|
|
7
|
+
super(name);
|
|
8
|
+
this.setDefaultConfig({ options: {} });
|
|
9
|
+
this.setName(name);
|
|
10
|
+
}
|
|
11
|
+
handleError = (res, message) => {
|
|
12
|
+
res.status(HttpCodes._5XX.INTERNAL_SERVER_ERROR.code).send(message);
|
|
13
|
+
};
|
|
14
|
+
createFunction(_express) {
|
|
15
|
+
_express.get('/*', async (req, res) => {
|
|
16
|
+
const path = req.path.slice(1);
|
|
17
|
+
const validationResult = tsValidateResult(path, tsValidateShortUrl());
|
|
18
|
+
if (validationResult)
|
|
19
|
+
return this.handleError(res, `invalid Url ${validationResult}`);
|
|
20
|
+
const dbShortUrl = (await ModuleBE_ShortUrlDB.query.where({ _shortUrl: path }))[0];
|
|
21
|
+
if (!dbShortUrl)
|
|
22
|
+
return this.handleError(res, `short url with path ${path} not found`);
|
|
23
|
+
//Handle url params
|
|
24
|
+
const url = new URL(dbShortUrl.fullUrl);
|
|
25
|
+
const queryParams = new URLSearchParams(req.query);
|
|
26
|
+
queryParams.forEach((value, key) => {
|
|
27
|
+
if (!url.searchParams.has(key)) {
|
|
28
|
+
url.searchParams.append(key, value);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return res.status(HttpCodes._3XX.MOVED_PERMANENTLY).redirect(url.toString());
|
|
32
|
+
});
|
|
33
|
+
return super.createFunction(_express);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const Module_ShortUrlResolver = new Module_ShortUrlResolver_Class();
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nu-art/ts-short-url-backend",
|
|
3
|
+
"version": "0.400.5",
|
|
4
|
+
"description": "ts-short-url - Express & Typescript based backend framework Backend",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"TacB0sS",
|
|
7
|
+
"infra",
|
|
8
|
+
"nu-art",
|
|
9
|
+
"thunderstorm",
|
|
10
|
+
"typescript",
|
|
11
|
+
"ts-short-url"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/nu-art-js/thunderstorm",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/nu-art-js/thunderstorm/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"directory": "dist",
|
|
19
|
+
"linkDirectory": true
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+ssh://git@github.com:nu-art-js/thunderstorm.git"
|
|
24
|
+
},
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"author": "TacB0sS",
|
|
27
|
+
"files": [
|
|
28
|
+
"**/*"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@nu-art/ts-short-url-shared": "0.400.5",
|
|
35
|
+
"@nu-art/firebase-backend": "0.400.5",
|
|
36
|
+
"@nu-art/firebase-shared": "0.400.5",
|
|
37
|
+
"@nu-art/permissions-backend": "0.400.5",
|
|
38
|
+
"@nu-art/permissions-shared": "0.400.5",
|
|
39
|
+
"@nu-art/thunderstorm-backend": "0.400.5",
|
|
40
|
+
"@nu-art/thunderstorm-shared": "0.400.5",
|
|
41
|
+
"@nu-art/ts-common": "0.400.5",
|
|
42
|
+
"@nu-art/ts-styles": "0.400.5",
|
|
43
|
+
"firebase": "^11.9.0",
|
|
44
|
+
"firebase-admin": "13.4.0",
|
|
45
|
+
"firebase-functions": "6.3.2",
|
|
46
|
+
"react": "^18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/react": "^18.0.0",
|
|
50
|
+
"@types/chai": "^4.3.4",
|
|
51
|
+
"@types/mocha": "^10.0.1"
|
|
52
|
+
},
|
|
53
|
+
"unitConfig": {
|
|
54
|
+
"type": "typescript-lib"
|
|
55
|
+
},
|
|
56
|
+
"type": "module",
|
|
57
|
+
"exports": {
|
|
58
|
+
".": {
|
|
59
|
+
"types": "./index.d.ts",
|
|
60
|
+
"import": "./index.js"
|
|
61
|
+
},
|
|
62
|
+
"./*": {
|
|
63
|
+
"types": "./*.d.ts",
|
|
64
|
+
"import": "./*.js"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|