tiny-essentials 1.0.0
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/.github/FUNDING.yml +4 -0
- package/.github/workflows/node.js.yml +31 -0
- package/LICENSE +674 -0
- package/README.md +67 -0
- package/dist/TinyEssentials.min.js +1 -0
- package/dist/_virtual/_commonjsHelpers.cjs +7 -0
- package/dist/_virtual/common.cjs +5 -0
- package/dist/_virtual/index.cjs +9 -0
- package/dist/_virtual/index2.cjs +5 -0
- package/dist/_virtual/trace.cjs +5 -0
- package/dist/legacy/crypto/decrypt.cjs +57 -0
- package/dist/legacy/crypto/decrypt.d.mts +18 -0
- package/dist/legacy/crypto/decrypt.mjs +47 -0
- package/dist/legacy/crypto/default.cjs +23 -0
- package/dist/legacy/crypto/default.d.mts +35 -0
- package/dist/legacy/crypto/default.mjs +19 -0
- package/dist/legacy/crypto/encrypt.cjs +54 -0
- package/dist/legacy/crypto/encrypt.d.mts +19 -0
- package/dist/legacy/crypto/encrypt.mjs +46 -0
- package/dist/legacy/crypto/index.cjs +11 -0
- package/dist/legacy/crypto/index.d.mts +4 -0
- package/dist/legacy/crypto/index.mjs +6 -0
- package/dist/legacy/firebase/cookieSession.cjs +121 -0
- package/dist/legacy/firebase/cookieSession.d.mts +56 -0
- package/dist/legacy/firebase/cookieSession.mjs +114 -0
- package/dist/legacy/firebase/database/index.cjs +11 -0
- package/dist/legacy/firebase/database/index.d.mts +7 -0
- package/dist/legacy/firebase/database/index.mjs +7 -0
- package/dist/legacy/firebase/database/presence.cjs +131 -0
- package/dist/legacy/firebase/database/presence.d.mts +9 -0
- package/dist/legacy/firebase/database/presence.mjs +111 -0
- package/dist/legacy/firebase/database/saveAsync.cjs +147 -0
- package/dist/legacy/firebase/database/saveAsync.d.mts +54 -0
- package/dist/legacy/firebase/database/saveAsync.mjs +147 -0
- package/dist/legacy/firebase/databaseEscape.cjs +42 -0
- package/dist/legacy/firebase/databaseEscape.d.mts +11 -0
- package/dist/legacy/firebase/databaseEscape.mjs +37 -0
- package/dist/legacy/firebase/databaseLogger.cjs +258 -0
- package/dist/legacy/firebase/databaseLogger.d.mts +7 -0
- package/dist/legacy/firebase/databaseLogger.mjs +234 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.cjs +71 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.d.mts +38 -0
- package/dist/legacy/firebase/discord/api/addGuildMember.mjs +64 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.cjs +47 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.d.mts +17 -0
- package/dist/legacy/firebase/discord/api/getGuildWidget.mjs +43 -0
- package/dist/legacy/firebase/discord/api/getToken.cjs +67 -0
- package/dist/legacy/firebase/discord/api/getToken.d.mts +35 -0
- package/dist/legacy/firebase/discord/api/getToken.mjs +63 -0
- package/dist/legacy/firebase/discord/api/getUser.cjs +58 -0
- package/dist/legacy/firebase/discord/api/getUser.d.mts +27 -0
- package/dist/legacy/firebase/discord/api/getUser.mjs +54 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.cjs +57 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.d.mts +26 -0
- package/dist/legacy/firebase/discord/api/getUserConnections.mjs +53 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.cjs +56 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.d.mts +25 -0
- package/dist/legacy/firebase/discord/api/getUserGuilds.mjs +52 -0
- package/dist/legacy/firebase/discord/api/index.cjs +24 -0
- package/dist/legacy/firebase/discord/api/index.d.mts +19 -0
- package/dist/legacy/firebase/discord/api/index.mjs +20 -0
- package/dist/legacy/firebase/discord/api/refreshToken.cjs +77 -0
- package/dist/legacy/firebase/discord/api/refreshToken.d.mts +45 -0
- package/dist/legacy/firebase/discord/api/refreshToken.mjs +73 -0
- package/dist/legacy/firebase/discord/api/revokeToken.cjs +61 -0
- package/dist/legacy/firebase/discord/api/revokeToken.d.mts +29 -0
- package/dist/legacy/firebase/discord/api/revokeToken.mjs +58 -0
- package/dist/legacy/firebase/discord/config.cjs +21 -0
- package/dist/legacy/firebase/discord/config.d.mts +27 -0
- package/dist/legacy/firebase/discord/config.mjs +17 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.cjs +11 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.d.mts +7 -0
- package/dist/legacy/firebase/discord/firebase_redirect/index.mjs +7 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.cjs +110 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.d.mts +4 -0
- package/dist/legacy/firebase/discord/firebase_redirect/login.mjs +107 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.cjs +100 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.d.mts +4 -0
- package/dist/legacy/firebase/discord/firebase_redirect/logout.mjs +97 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.cjs +76 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.d.mts +23 -0
- package/dist/legacy/firebase/discord/get/authURLGenerator.mjs +67 -0
- package/dist/legacy/firebase/discord/get/cookie-session.cjs +32 -0
- package/dist/legacy/firebase/discord/get/cookie-session.d.mts +20 -0
- package/dist/legacy/firebase/discord/get/cookie-session.mjs +28 -0
- package/dist/legacy/firebase/discord/get/credentials.cjs +24 -0
- package/dist/legacy/firebase/discord/get/credentials.d.mts +19 -0
- package/dist/legacy/firebase/discord/get/credentials.mjs +20 -0
- package/dist/legacy/firebase/discord/get/errorValidator.cjs +60 -0
- package/dist/legacy/firebase/discord/get/errorValidator.d.mts +28 -0
- package/dist/legacy/firebase/discord/get/errorValidator.mjs +55 -0
- package/dist/legacy/firebase/discord/get/index.cjs +17 -0
- package/dist/legacy/firebase/discord/get/index.d.mts +13 -0
- package/dist/legacy/firebase/discord/get/index.mjs +13 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.cjs +37 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.d.mts +22 -0
- package/dist/legacy/firebase/discord/get/randomAvatar.mjs +30 -0
- package/dist/legacy/firebase/discord/http/index.cjs +15 -0
- package/dist/legacy/firebase/discord/http/index.d.mts +11 -0
- package/dist/legacy/firebase/discord/http/index.mjs +11 -0
- package/dist/legacy/firebase/discord/http/login.cjs +127 -0
- package/dist/legacy/firebase/discord/http/login.d.mts +21 -0
- package/dist/legacy/firebase/discord/http/login.mjs +123 -0
- package/dist/legacy/firebase/discord/http/logout.cjs +155 -0
- package/dist/legacy/firebase/discord/http/logout.d.mts +22 -0
- package/dist/legacy/firebase/discord/http/logout.mjs +143 -0
- package/dist/legacy/firebase/discord/http/redirect.cjs +188 -0
- package/dist/legacy/firebase/discord/http/redirect.d.mts +24 -0
- package/dist/legacy/firebase/discord/http/redirect.mjs +178 -0
- package/dist/legacy/firebase/discord/http/refreshToken.cjs +133 -0
- package/dist/legacy/firebase/discord/http/refreshToken.d.mts +24 -0
- package/dist/legacy/firebase/discord/http/refreshToken.mjs +121 -0
- package/dist/legacy/firebase/discord/index.cjs +19 -0
- package/dist/legacy/firebase/discord/index.d.mts +15 -0
- package/dist/legacy/firebase/discord/index.mjs +15 -0
- package/dist/legacy/firebase/discord/template/cookie-session.cjs +1430 -0
- package/dist/legacy/firebase/discord/template/cookie-session.d.mts +22 -0
- package/dist/legacy/firebase/discord/template/cookie-session.mjs +1159 -0
- package/dist/legacy/firebase/domainRedirect.cjs +35 -0
- package/dist/legacy/firebase/domainRedirect.d.mts +12 -0
- package/dist/legacy/firebase/domainRedirect.mjs +27 -0
- package/dist/legacy/firebase/escape.cjs +75 -0
- package/dist/legacy/firebase/escape.d.mts +17 -0
- package/dist/legacy/firebase/escape.mjs +58 -0
- package/dist/legacy/firebase/getDBAsync.cjs +33 -0
- package/dist/legacy/firebase/getDBAsync.d.mts +10 -0
- package/dist/legacy/firebase/getDBAsync.mjs +26 -0
- package/dist/legacy/firebase/getDBData.cjs +21 -0
- package/dist/legacy/firebase/getDBData.d.mts +1 -0
- package/dist/legacy/firebase/getDBData.mjs +17 -0
- package/dist/legacy/firebase/getDBValue.cjs +17 -0
- package/dist/legacy/firebase/getDBValue.d.mts +9 -0
- package/dist/legacy/firebase/getDBValue.mjs +14 -0
- package/dist/legacy/firebase/index.cjs +261 -0
- package/dist/legacy/firebase/index.d.mts +51 -0
- package/dist/legacy/firebase/index.mjs +234 -0
- package/dist/legacy/firebase/isEmulator.cjs +14 -0
- package/dist/legacy/firebase/isEmulator.d.mts +8 -0
- package/dist/legacy/firebase/isEmulator.mjs +10 -0
- package/dist/legacy/firebase/logger.cjs +137 -0
- package/dist/legacy/firebase/logger.d.mts +7 -0
- package/dist/legacy/firebase/logger.mjs +125 -0
- package/dist/legacy/firebase/mySQL.cjs +26 -0
- package/dist/legacy/firebase/mySQL.d.mts +10 -0
- package/dist/legacy/firebase/mySQL.mjs +22 -0
- package/dist/legacy/firebase/mysqlConnector/create.cjs +119 -0
- package/dist/legacy/firebase/mysqlConnector/create.d.mts +36 -0
- package/dist/legacy/firebase/mysqlConnector/create.mjs +109 -0
- package/dist/legacy/firebase/mysqlConnector/index.cjs +23 -0
- package/dist/legacy/firebase/mysqlConnector/index.d.mts +11 -0
- package/dist/legacy/firebase/mysqlConnector/index.mjs +16 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.cjs +75 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.d.mts +31 -0
- package/dist/legacy/firebase/mysqlConnector/nextPrev.mjs +63 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.cjs +91 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.d.mts +33 -0
- package/dist/legacy/firebase/mysqlConnector/pagination.mjs +87 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +28 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.d.mts +12 -0
- package/dist/legacy/firebase/mysqlConnector/sameUser.mjs +23 -0
- package/dist/legacy/firebase/transactionDBAsync.cjs +33 -0
- package/dist/legacy/firebase/transactionDBAsync.d.mts +11 -0
- package/dist/legacy/firebase/transactionDBAsync.mjs +27 -0
- package/dist/legacy/get/countObj.cjs +24 -0
- package/dist/legacy/get/countObj.d.mts +11 -0
- package/dist/legacy/get/countObj.mjs +21 -0
- package/dist/legacy/get/decimalColor.cjs +60 -0
- package/dist/legacy/get/decimalColor.d.mts +12 -0
- package/dist/legacy/get/decimalColor.mjs +54 -0
- package/dist/legacy/get/objType.cjs +43 -0
- package/dist/legacy/get/objType.d.mts +19 -0
- package/dist/legacy/get/objType.mjs +40 -0
- package/dist/legacy/get/pagination.cjs +100 -0
- package/dist/legacy/get/pagination.d.mts +25 -0
- package/dist/legacy/get/pagination.mjs +91 -0
- package/dist/legacy/get/queryUrlByName.cjs +31 -0
- package/dist/legacy/get/queryUrlByName.d.mts +20 -0
- package/dist/legacy/get/queryUrlByName.mjs +28 -0
- package/dist/legacy/get/queryUrlJSON.cjs +54 -0
- package/dist/legacy/get/queryUrlJSON.d.mts +23 -0
- package/dist/legacy/get/queryUrlJSON.mjs +57 -0
- package/dist/legacy/get/super_string_filter.cjs +97 -0
- package/dist/legacy/get/super_string_filter.d.mts +25 -0
- package/dist/legacy/get/super_string_filter.mjs +83 -0
- package/dist/legacy/get/versionCheck.cjs +49 -0
- package/dist/legacy/get/versionCheck.d.mts +17 -0
- package/dist/legacy/get/versionCheck.mjs +38 -0
- package/dist/legacy/http/HTTP-1.0.cjs +151 -0
- package/dist/legacy/http/HTTP-1.0.d.mts +8 -0
- package/dist/legacy/http/HTTP-1.0.mjs +136 -0
- package/dist/legacy/http/auth.cjs +70 -0
- package/dist/legacy/http/auth.d.mts +41 -0
- package/dist/legacy/http/auth.mjs +63 -0
- package/dist/legacy/http/check_domain.cjs +84 -0
- package/dist/legacy/http/check_domain.d.mts +10 -0
- package/dist/legacy/http/check_domain.mjs +82 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +46 -0
- package/dist/legacy/http/csrfTokenAnalyze.d.mts +21 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +40 -0
- package/dist/legacy/http/domainValidator.cjs +98 -0
- package/dist/legacy/http/domainValidator.d.mts +30 -0
- package/dist/legacy/http/domainValidator.mjs +82 -0
- package/dist/legacy/http/errorsCallback.cjs +55 -0
- package/dist/legacy/http/errorsCallback.d.mts +29 -0
- package/dist/legacy/http/errorsCallback.mjs +48 -0
- package/dist/legacy/http/fetch/json.cjs +48 -0
- package/dist/legacy/http/fetch/json.d.mts +22 -0
- package/dist/legacy/http/fetch/json.mjs +41 -0
- package/dist/legacy/http/fetch/text.cjs +47 -0
- package/dist/legacy/http/fetch/text.d.mts +21 -0
- package/dist/legacy/http/fetch/text.mjs +40 -0
- package/dist/legacy/http/fileCache.cjs +79 -0
- package/dist/legacy/http/fileCache.d.mts +35 -0
- package/dist/legacy/http/fileCache.mjs +70 -0
- package/dist/legacy/http/getDomainURL.cjs +59 -0
- package/dist/legacy/http/getDomainURL.d.mts +18 -0
- package/dist/legacy/http/getDomainURL.mjs +54 -0
- package/dist/legacy/http/userIP.cjs +59 -0
- package/dist/legacy/http/userIP.d.mts +21 -0
- package/dist/legacy/http/userIP.mjs +48 -0
- package/dist/legacy/index.cjs +122 -0
- package/dist/legacy/index.d.mts +89 -0
- package/dist/legacy/index.mjs +92 -0
- package/dist/legacy/libs/arraySortPositions.cjs +30 -0
- package/dist/legacy/libs/arraySortPositions.d.mts +16 -0
- package/dist/legacy/libs/arraySortPositions.mjs +27 -0
- package/dist/legacy/libs/capitalize.cjs +21 -0
- package/dist/legacy/libs/capitalize.d.mts +13 -0
- package/dist/legacy/libs/capitalize.mjs +17 -0
- package/dist/legacy/libs/convertBytes.cjs +64 -0
- package/dist/legacy/libs/convertBytes.d.mts +17 -0
- package/dist/legacy/libs/convertBytes.mjs +55 -0
- package/dist/legacy/libs/custom_module_loader.cjs +82 -0
- package/dist/legacy/libs/custom_module_loader.d.mts +5 -0
- package/dist/legacy/libs/custom_module_loader.mjs +79 -0
- package/dist/legacy/libs/dice.cjs +35 -0
- package/dist/legacy/libs/dice.d.mts +5 -0
- package/dist/legacy/libs/dice.mjs +31 -0
- package/dist/legacy/libs/markdown.cjs +85 -0
- package/dist/legacy/libs/markdown.d.mts +75 -0
- package/dist/legacy/libs/markdown.mjs +78 -0
- package/dist/legacy/libs/percentage.cjs +22 -0
- package/dist/legacy/libs/percentage.d.mts +4 -0
- package/dist/legacy/libs/percentage.mjs +19 -0
- package/dist/legacy/libs/regex/getLetter.cjs +22 -0
- package/dist/legacy/libs/regex/getLetter.d.mts +12 -0
- package/dist/legacy/libs/regex/getLetter.mjs +19 -0
- package/dist/legacy/libs/replaceAsync.cjs +32 -0
- package/dist/legacy/libs/replaceAsync.d.mts +15 -0
- package/dist/legacy/libs/replaceAsync.mjs +25 -0
- package/dist/legacy/libs/rule3.cjs +58 -0
- package/dist/legacy/libs/rule3.d.mts +5 -0
- package/dist/legacy/libs/rule3.mjs +54 -0
- package/dist/legacy/libs/userLevel.cjs +134 -0
- package/dist/legacy/libs/userLevel.d.mts +69 -0
- package/dist/legacy/libs/userLevel.mjs +123 -0
- package/dist/legacy/momentjs/getAge.cjs +28 -0
- package/dist/legacy/momentjs/getAge.d.mts +8 -0
- package/dist/legacy/momentjs/getAge.mjs +22 -0
- package/dist/legacy/momentjs/index.cjs +9 -0
- package/dist/legacy/momentjs/index.d.mts +3 -0
- package/dist/legacy/momentjs/index.mjs +3 -0
- package/dist/legacy/momentjs/timeDuration.cjs +29 -0
- package/dist/legacy/momentjs/timeDuration.d.mts +9 -0
- package/dist/legacy/momentjs/timeDuration.mjs +23 -0
- package/dist/legacy/socket.io/antiFlood/index.cjs +9 -0
- package/dist/legacy/socket.io/antiFlood/index.d.mts +3 -0
- package/dist/legacy/socket.io/antiFlood/index.mjs +3 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +32 -0
- package/dist/legacy/socket.io/antiFlood/install.d.mts +14 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +27 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +87 -0
- package/dist/legacy/socket.io/antiFlood/verify.d.mts +15 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +73 -0
- package/dist/legacy/socket.io/cookie-session.cjs +25 -0
- package/dist/legacy/socket.io/cookie-session.d.mts +9 -0
- package/dist/legacy/socket.io/cookie-session.mjs +20 -0
- package/dist/legacy/socket.io/discord.cjs +61 -0
- package/dist/legacy/socket.io/discord.d.mts +10 -0
- package/dist/legacy/socket.io/discord.mjs +52 -0
- package/dist/legacy/socket.io/index.cjs +13 -0
- package/dist/legacy/socket.io/index.d.mts +9 -0
- package/dist/legacy/socket.io/index.mjs +9 -0
- package/dist/v1/basics/array.cjs +31 -0
- package/dist/v1/basics/array.d.mts +10 -0
- package/dist/v1/basics/array.mjs +22 -0
- package/dist/v1/basics/clock.cjs +187 -0
- package/dist/v1/basics/clock.d.mts +37 -0
- package/dist/v1/basics/clock.mjs +152 -0
- package/dist/v1/basics/objFilter.cjs +55 -0
- package/dist/v1/basics/objFilter.d.mts +27 -0
- package/dist/v1/basics/objFilter.mjs +52 -0
- package/dist/v1/basics/simpleMath.cjs +88 -0
- package/dist/v1/basics/simpleMath.d.mts +54 -0
- package/dist/v1/basics/simpleMath.mjs +75 -0
- package/dist/v1/basics/text.cjs +34 -0
- package/dist/v1/basics/text.d.mts +20 -0
- package/dist/v1/basics/text.mjs +25 -0
- package/dist/v1/index.cjs +26 -0
- package/dist/v1/index.d.mts +15 -0
- package/dist/v1/index.mjs +8 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<p>
|
|
3
|
+
<a href="https://discord.gg/TgHdvJd"><img src="https://img.shields.io/discord/413193536188579841?color=7289da&logo=discord&logoColor=white" alt="Discord server" /></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/tiny-essentials"><img src="https://img.shields.io/npm/v/tiny-essentials.svg?maxAge=3600" alt="NPM version" /></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/tiny-essentials"><img src="https://img.shields.io/npm/dt/tiny-essentials.svg?maxAge=3600" alt="NPM downloads" /></a>
|
|
6
|
+
<a href="https://www.patreon.com/JasminDreasond"><img src="https://img.shields.io/badge/donate-patreon-F96854.svg?logo=patreon" alt="Patreon" /></a>
|
|
7
|
+
<a href="https://ko-fi.com/jasmindreasond"><img src="https://img.shields.io/badge/donate-ko%20fi-29ABE0.svg?logo=ko-fi" alt="Ko-Fi" /></a>
|
|
8
|
+
</p>
|
|
9
|
+
<p>
|
|
10
|
+
<a href="https://nodei.co/npm/tiny-essentials/"><img src="https://nodei.co/npm/tiny-essentials.png?downloads=true&stars=true" alt="npm installnfo" /></a>
|
|
11
|
+
</p>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
# Tiny Essentials
|
|
15
|
+
|
|
16
|
+
**Tiny Essentials** is a collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility. From date calculations to formatting, object manipulations, and array operations, these scripts serve as building blocks for more complex applications.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **Array Manipulations**: Functions like `shuffleArray` to randomize elements in place.
|
|
21
|
+
- **Time Calculations**: Easily calculate durations, format timers, and more.
|
|
22
|
+
- **Object Utilities**: Perform type checks, count object properties, and calculate percentages.
|
|
23
|
+
- **Custom Utilities**: Includes various helper functions like `ruleOfThree` for proportion calculations and `getAge` to calculate the age based on a given birth date.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
You can install Tiny Essentials via npm:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install tiny-essentials
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or download the scripts directly from this repository.
|
|
34
|
+
|
|
35
|
+
## Legacy Code
|
|
36
|
+
|
|
37
|
+
Some scripts in this repository have been preserved for backwards compatibility. These include modules like:
|
|
38
|
+
|
|
39
|
+
- `@tinypudding/firebase-lib`
|
|
40
|
+
- `@tinypudding/discord-oauth2`
|
|
41
|
+
- `@tinypudding/mysql-connector`
|
|
42
|
+
- `@tinypudding/puddy-lib`
|
|
43
|
+
|
|
44
|
+
These modules have been updated to work with modern environments but may not be actively developed further.
|
|
45
|
+
|
|
46
|
+
## Module Versions
|
|
47
|
+
The core version of Tiny Essentials (version 1) is located in the folder [`/src/v1`](./src/v1).
|
|
48
|
+
|
|
49
|
+
A detailed README is available inside the [`v1`](./src/v1) folder, which contains a full description of all utility modules and their functionalities.
|
|
50
|
+
We recommend checking it out if you want to see all available tools in this version and how to use them individually or collectively via the `index.mjs` global module.
|
|
51
|
+
|
|
52
|
+
## Contributions
|
|
53
|
+
|
|
54
|
+
Feel free to fork, contribute, and create pull requests for improvements! Whether it's a bug fix or an additional feature, contributions are always welcome.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### Credits
|
|
63
|
+
|
|
64
|
+
This project was inspired by the need for lightweight, reusable code that can be used across many different kinds of applications. Contributions and suggestions are always appreciated!
|
|
65
|
+
|
|
66
|
+
> **Note**: This documentation was written by [ChatGPT](https://openai.com/chatgpt), an AI assistant developed by OpenAI, based on the project structure and descriptions provided by the repository author.
|
|
67
|
+
> If you find any inaccuracies or need improvements, feel free to contribute or open an issue!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var TinyEssentials=function(e){"use strict";function t(e,t="seconds",r="{time}"){e=Math.max(0,Math.floor(e));const a=["seconds","minutes","hours","days","months","years"].indexOf(t),s=a>=5,n=a>=4,o=a>=3,l=a>=2,i=a>=1,u=a>=0,c={years:s?0:NaN,months:n?0:NaN,days:o?0:NaN,hours:l?0:NaN,minutes:i?0:NaN,seconds:u?0:NaN,total:NaN};let h=e;if(s||n||o){const e=new Date(1980,0,1),t=new Date(e.getTime()+1e3*h),r=new Date(e);if(s)for(;new Date(r.getFullYear()+1,r.getMonth(),r.getDate())<=t;)r.setFullYear(r.getFullYear()+1),c.years++;if(n)for(;new Date(r.getFullYear(),r.getMonth()+1,r.getDate())<=t;)r.setMonth(r.getMonth()+1),c.months++;if(o)for(;new Date(r.getFullYear(),r.getMonth(),r.getDate()+1)<=t;)r.setDate(r.getDate()+1),c.days++;h=Math.floor((t-r)/1e3)}l&&(c.hours=Math.floor(h/3600),h%=3600),i&&(c.minutes=Math.floor(h/60),h%=60),u&&(c.seconds=h);const p={seconds:u?e:NaN,minutes:i?e/60:NaN,hours:l?e/3600:NaN,days:o?e/86400:NaN,months:n?12*c.years+c.months+(c.days||0)/30:NaN,years:s?c.years+(c.months||0)/12+(c.days||0)/365:NaN};c.total=+(p[t]||0).toFixed(2).replace(/\.00$/,"");const g=e=>isNaN(e)?"NaN":String(e).padStart(2,"0"),f=[l?g(c.hours):null,i?g(c.minutes):null,u?g(c.seconds):null].filter((e=>null!==e)).join(":");return r.replace(/\{years\}/g,c.years).replace(/\{months\}/g,c.months).replace(/\{days\}/g,c.days).replace(/\{hours\}/g,g(c.hours)).replace(/\{minutes\}/g,g(c.minutes)).replace(/\{seconds\}/g,g(c.seconds)).replace(/\{time\}/g,f).replace(/\{total\}/g,c.total).trim()}function r(e,t){if(void 0!==e){const r=Object.prototype.toString.call(e).toLowerCase();return"string"==typeof t?r===`[object ${t}]`:r.substring(8,r.length-1)}return null}return e.TinyLevelUp=class{constructor(e,t){this.giveExp=e,this.expLevel=t}expValidator(e){let t=0;const r=this.expLevel*e.level;return e.exp>=r&&(e.level++,t=e.exp-r,e.exp=0,t>0)?this.give(e,t,"extra"):e.exp<1&&e.level>1&&(e.level--,t=Math.abs(e.exp),e.exp=this.expLevel*e.level,t>0)?this.remove(e,t,"extra"):e}getTotalExp(e){let t=0;for(let r=1;r<=e.level;r++)t+=this.expLevel*r;return t+=e.exp,t}expGenerator(e=1){return Math.floor(Math.random()*this.giveExp)+1*e}progress(e){return this.expLevel*e.level}getProgress(e){return this.expLevel*e.level}set(e,t){return e.exp=t,this.expValidator(e),e.totalExp=this.getTotalExp(e),e}give(e,t=0,r="add",a=1){return"add"===r?e.exp+=this.expGenerator(a)+t:"extra"===r&&(e.exp+=t),this.expValidator(e),e.totalExp=this.getTotalExp(e),e}remove(e,t=0,r="add",a=1){return"add"===r?e.exp-=this.expGenerator(a)+t:"extra"===r&&(e.exp-=t),this.expValidator(e),e.totalExp=this.getTotalExp(e),e}},e.asyncReplace=async function(e,t,r){const a=[];e.replace(t,((e,...t)=>(a.push(r(e,...t)),e)));const s=await Promise.all(a);return e.replace(t,(()=>s.shift()))},e.countObj=function(e){return Array.isArray(e)?e.length:r(e,"object")?Object.keys(e).length:0},e.formatCustomTimer=t,e.formatDayTimer=function(e){return t(e,"days","{days}d {hours}:{minutes}:{seconds}")},e.formatTimer=function(e){return t(e,"hours","{hours}:{minutes}:{seconds}")},e.getAge=function(e=0,t=null){if(null!=e&&0!==e){const r=new Date(e);if(isNaN(r))return null;const a=t instanceof Date?t:new Date;let s=a.getFullYear()-r.getFullYear();const n=a.getMonth(),o=r.getMonth(),l=a.getDate(),i=r.getDate();return(n<o||n===o&&l<i)&&s--,Math.abs(s)}return null},e.getSimplePerc=function(e,t){return e*(t/100)},e.getTimeDuration=function(e=new Date,t="asSeconds",r=null){if(e instanceof Date){const a=e-(r instanceof Date?r:new Date);switch(t){case"asMilliseconds":return a;case"asSeconds":default:return a/1e3;case"asMinutes":return a/6e4;case"asHours":return a/36e5;case"asDays":return a/864e5}}return null},e.objType=r,e.ruleOfThree=function(e,t,r,a){return a?Number(e*t)/r:Number(r*t)/e},e.shuffleArray=function(e){let t,r=e.length;for(;0!==r;)t=Math.floor(Math.random()*r),r--,[e[r],e[t]]=[e[t],e[r]];return e},e.toTitleCase=function(e){return e.replace(/\w\S*/g,(e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()))},e.toTitleCaseLowerFirst=function(e){const t=e.replace(/\w\S*/g,(e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()));return t.charAt(0).toLowerCase()+t.slice(1)},e}({});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _commonjsHelpers = require('./_commonjsHelpers.cjs');
|
|
4
|
+
var index = require('../node_modules/firebase-functions/lib/logger/index.cjs');
|
|
5
|
+
|
|
6
|
+
var loggerExports = index.__require();
|
|
7
|
+
var logger = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(loggerExports);
|
|
8
|
+
|
|
9
|
+
module.exports = logger;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
// Module
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Decrypts a given encrypted string using the specified algorithm, key, and string format.
|
|
9
|
+
*
|
|
10
|
+
* @private
|
|
11
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
12
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm (e.g., 'aes-256-cbc').
|
|
13
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used in the encrypted string (e.g., 'hex', 'base64').
|
|
14
|
+
* @param {string} key - The secret key used for decryption.
|
|
15
|
+
* @param {string} text - The encrypted text to decrypt. It must be formatted as `iv:encryptedData`.
|
|
16
|
+
* @returns {string} The decrypted string.
|
|
17
|
+
*/
|
|
18
|
+
const cryptoAction = function (tinyCrypto, key, text) {
|
|
19
|
+
let textParts = text.split(':');
|
|
20
|
+
let iv = Buffer.from(textParts.shift(), tinyCrypto.stringType);
|
|
21
|
+
let encryptedText = Buffer.from(textParts.join(':'), tinyCrypto.stringType);
|
|
22
|
+
let decipher = crypto.createDecipheriv(tinyCrypto.algorithm, Buffer.from(key), iv);
|
|
23
|
+
let decrypted = decipher.update(encryptedText);
|
|
24
|
+
|
|
25
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
26
|
+
|
|
27
|
+
return decrypted.toString();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Decrypts an encrypted string using one or more keys.
|
|
32
|
+
*
|
|
33
|
+
* If `tinyCrypto.key` is a single key, it will be used directly.
|
|
34
|
+
* If it's an array of keys, decryption will be applied iteratively in sequence (as if reversing layered encryption).
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
37
|
+
* @param {string|string[]} tinyCrypto.key - A single decryption key or an array of keys to apply sequentially.
|
|
38
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm (e.g., 'aes-256-cbc').
|
|
39
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used in the encrypted string (e.g., 'hex', 'base64').
|
|
40
|
+
* @param {string} text - The encrypted string to decrypt.
|
|
41
|
+
* @returns {string} The fully decrypted string.
|
|
42
|
+
*/
|
|
43
|
+
function decrypt(tinyCrypto, text) {
|
|
44
|
+
// Prepare Result
|
|
45
|
+
let result = text;
|
|
46
|
+
if (!Array.isArray(tinyCrypto.key)) {
|
|
47
|
+
tinyCrypto.key = [tinyCrypto.key];
|
|
48
|
+
}
|
|
49
|
+
for (const item in tinyCrypto.key) {
|
|
50
|
+
result = cryptoAction(tinyCrypto, tinyCrypto.key[item], result);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Complete
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.decrypt = decrypt;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decrypts an encrypted string using one or more keys.
|
|
3
|
+
*
|
|
4
|
+
* If `tinyCrypto.key` is a single key, it will be used directly.
|
|
5
|
+
* If it's an array of keys, decryption will be applied iteratively in sequence (as if reversing layered encryption).
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
8
|
+
* @param {string|string[]} tinyCrypto.key - A single decryption key or an array of keys to apply sequentially.
|
|
9
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm (e.g., 'aes-256-cbc').
|
|
10
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used in the encrypted string (e.g., 'hex', 'base64').
|
|
11
|
+
* @param {string} text - The encrypted string to decrypt.
|
|
12
|
+
* @returns {string} The fully decrypted string.
|
|
13
|
+
*/
|
|
14
|
+
export function decrypt(tinyCrypto: {
|
|
15
|
+
key: string | string[];
|
|
16
|
+
algorithm: string;
|
|
17
|
+
stringType: BufferEncoding;
|
|
18
|
+
}, text: string): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Module
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
/**
|
|
4
|
+
* Decrypts a given encrypted string using the specified algorithm, key, and string format.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
8
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm (e.g., 'aes-256-cbc').
|
|
9
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used in the encrypted string (e.g., 'hex', 'base64').
|
|
10
|
+
* @param {string} key - The secret key used for decryption.
|
|
11
|
+
* @param {string} text - The encrypted text to decrypt. It must be formatted as `iv:encryptedData`.
|
|
12
|
+
* @returns {string} The decrypted string.
|
|
13
|
+
*/
|
|
14
|
+
const cryptoAction = function (tinyCrypto, key, text) {
|
|
15
|
+
let textParts = text.split(':');
|
|
16
|
+
let iv = Buffer.from(textParts.shift(), tinyCrypto.stringType);
|
|
17
|
+
let encryptedText = Buffer.from(textParts.join(':'), tinyCrypto.stringType);
|
|
18
|
+
let decipher = crypto.createDecipheriv(tinyCrypto.algorithm, Buffer.from(key), iv);
|
|
19
|
+
let decrypted = decipher.update(encryptedText);
|
|
20
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
21
|
+
return decrypted.toString();
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Decrypts an encrypted string using one or more keys.
|
|
25
|
+
*
|
|
26
|
+
* If `tinyCrypto.key` is a single key, it will be used directly.
|
|
27
|
+
* If it's an array of keys, decryption will be applied iteratively in sequence (as if reversing layered encryption).
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
30
|
+
* @param {string|string[]} tinyCrypto.key - A single decryption key or an array of keys to apply sequentially.
|
|
31
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm (e.g., 'aes-256-cbc').
|
|
32
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used in the encrypted string (e.g., 'hex', 'base64').
|
|
33
|
+
* @param {string} text - The encrypted string to decrypt.
|
|
34
|
+
* @returns {string} The fully decrypted string.
|
|
35
|
+
*/
|
|
36
|
+
export function decrypt(tinyCrypto, text) {
|
|
37
|
+
// Prepare Result
|
|
38
|
+
let result = text;
|
|
39
|
+
if (!Array.isArray(tinyCrypto.key)) {
|
|
40
|
+
tinyCrypto.key = [tinyCrypto.key];
|
|
41
|
+
}
|
|
42
|
+
for (const item in tinyCrypto.key) {
|
|
43
|
+
result = cryptoAction(tinyCrypto, tinyCrypto.key[item], result);
|
|
44
|
+
}
|
|
45
|
+
// Complete
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default cryptographic configuration for encryption and decryption operations.
|
|
5
|
+
*
|
|
6
|
+
* @typedef {Object} DefaultCrypto
|
|
7
|
+
* @property {number} IV_LENGTH - Length (in bytes) of the Initialization Vector (IV). Usually 16 for AES.
|
|
8
|
+
* @property {string} algorithm - The encryption algorithm used (e.g., 'aes-256-cbc').
|
|
9
|
+
* @property {string} key - The default encryption/decryption key (must match the required length for the chosen algorithm).
|
|
10
|
+
* @property {BufferEncoding} stringType - Encoding used for converting strings to Buffers (e.g., 'hex', 'base64').
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @type {DefaultCrypto}
|
|
15
|
+
*/
|
|
16
|
+
const defaultCrypto = {
|
|
17
|
+
IV_LENGTH: 16,
|
|
18
|
+
algorithm: 'aes-256-cbc',
|
|
19
|
+
key: 'tinypudding123456789012345678900',
|
|
20
|
+
stringType: 'hex',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = defaultCrypto;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default defaultCrypto;
|
|
2
|
+
/**
|
|
3
|
+
* Default cryptographic configuration for encryption and decryption operations.
|
|
4
|
+
*/
|
|
5
|
+
export type DefaultCrypto = {
|
|
6
|
+
/**
|
|
7
|
+
* - Length (in bytes) of the Initialization Vector (IV). Usually 16 for AES.
|
|
8
|
+
*/
|
|
9
|
+
IV_LENGTH: number;
|
|
10
|
+
/**
|
|
11
|
+
* - The encryption algorithm used (e.g., 'aes-256-cbc').
|
|
12
|
+
*/
|
|
13
|
+
algorithm: string;
|
|
14
|
+
/**
|
|
15
|
+
* - The default encryption/decryption key (must match the required length for the chosen algorithm).
|
|
16
|
+
*/
|
|
17
|
+
key: string;
|
|
18
|
+
/**
|
|
19
|
+
* - Encoding used for converting strings to Buffers (e.g., 'hex', 'base64').
|
|
20
|
+
*/
|
|
21
|
+
stringType: BufferEncoding;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Default cryptographic configuration for encryption and decryption operations.
|
|
25
|
+
*
|
|
26
|
+
* @typedef {Object} DefaultCrypto
|
|
27
|
+
* @property {number} IV_LENGTH - Length (in bytes) of the Initialization Vector (IV). Usually 16 for AES.
|
|
28
|
+
* @property {string} algorithm - The encryption algorithm used (e.g., 'aes-256-cbc').
|
|
29
|
+
* @property {string} key - The default encryption/decryption key (must match the required length for the chosen algorithm).
|
|
30
|
+
* @property {BufferEncoding} stringType - Encoding used for converting strings to Buffers (e.g., 'hex', 'base64').
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* @type {DefaultCrypto}
|
|
34
|
+
*/
|
|
35
|
+
declare const defaultCrypto: DefaultCrypto;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default cryptographic configuration for encryption and decryption operations.
|
|
3
|
+
*
|
|
4
|
+
* @typedef {Object} DefaultCrypto
|
|
5
|
+
* @property {number} IV_LENGTH - Length (in bytes) of the Initialization Vector (IV). Usually 16 for AES.
|
|
6
|
+
* @property {string} algorithm - The encryption algorithm used (e.g., 'aes-256-cbc').
|
|
7
|
+
* @property {string} key - The default encryption/decryption key (must match the required length for the chosen algorithm).
|
|
8
|
+
* @property {BufferEncoding} stringType - Encoding used for converting strings to Buffers (e.g., 'hex', 'base64').
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @type {DefaultCrypto}
|
|
12
|
+
*/
|
|
13
|
+
const defaultCrypto = {
|
|
14
|
+
IV_LENGTH: 16,
|
|
15
|
+
algorithm: 'aes-256-cbc',
|
|
16
|
+
key: 'tinypudding123456789012345678900',
|
|
17
|
+
stringType: 'hex',
|
|
18
|
+
};
|
|
19
|
+
export default defaultCrypto;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
// Module
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Encrypts a given string using the specified algorithm, key, and string encoding.
|
|
9
|
+
*
|
|
10
|
+
* @private
|
|
11
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
12
|
+
* @param {number} tinyCrypto.IV_LENGTH - The byte length of the initialization vector (e.g., 16).
|
|
13
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm (e.g., 'aes-256-cbc').
|
|
14
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding to use when converting buffers to strings (e.g., 'hex', 'base64').
|
|
15
|
+
* @param {string} key - The encryption key.
|
|
16
|
+
* @param {string} text - The plain text to encrypt.
|
|
17
|
+
* @returns {string} The encrypted string in the format `iv:encryptedData`.
|
|
18
|
+
*/
|
|
19
|
+
const cryptoAction = function (tinyCrypto, key, text) {
|
|
20
|
+
let iv = crypto.randomBytes(tinyCrypto.IV_LENGTH);
|
|
21
|
+
let cipher = crypto.createCipheriv(tinyCrypto.algorithm, Buffer.from(key), iv);
|
|
22
|
+
let encrypted = cipher.update(text);
|
|
23
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
24
|
+
return iv.toString(tinyCrypto.stringType) + ':' + encrypted.toString(tinyCrypto.stringType);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Encrypts a string using one or more keys from the provided crypto configuration.
|
|
29
|
+
*
|
|
30
|
+
* If `tinyCrypto.key` is an array, the encryption is applied sequentially (layered encryption).
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
33
|
+
* @param {string|string[]} tinyCrypto.key - A single encryption key or an array of keys to apply in sequence.
|
|
34
|
+
* @param {number} tinyCrypto.IV_LENGTH - The byte length of the initialization vector.
|
|
35
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm to use.
|
|
36
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used for output (e.g., 'hex', 'base64').
|
|
37
|
+
* @param {string} text - The plain text string to encrypt.
|
|
38
|
+
* @returns {string} The final encrypted string.
|
|
39
|
+
*/
|
|
40
|
+
function encrypt(tinyCrypto, text) {
|
|
41
|
+
// Prepare Result
|
|
42
|
+
let result = text;
|
|
43
|
+
if (!Array.isArray(tinyCrypto.key)) {
|
|
44
|
+
tinyCrypto.key = [tinyCrypto.key];
|
|
45
|
+
}
|
|
46
|
+
for (const item in tinyCrypto.key) {
|
|
47
|
+
result = cryptoAction(tinyCrypto, tinyCrypto.key[item], result);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Complete
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.encrypt = encrypt;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts a string using one or more keys from the provided crypto configuration.
|
|
3
|
+
*
|
|
4
|
+
* If `tinyCrypto.key` is an array, the encryption is applied sequentially (layered encryption).
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
7
|
+
* @param {string|string[]} tinyCrypto.key - A single encryption key or an array of keys to apply in sequence.
|
|
8
|
+
* @param {number} tinyCrypto.IV_LENGTH - The byte length of the initialization vector.
|
|
9
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm to use.
|
|
10
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used for output (e.g., 'hex', 'base64').
|
|
11
|
+
* @param {string} text - The plain text string to encrypt.
|
|
12
|
+
* @returns {string} The final encrypted string.
|
|
13
|
+
*/
|
|
14
|
+
export function encrypt(tinyCrypto: {
|
|
15
|
+
key: string | string[];
|
|
16
|
+
IV_LENGTH: number;
|
|
17
|
+
algorithm: string;
|
|
18
|
+
stringType: BufferEncoding;
|
|
19
|
+
}, text: string): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Module
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
/**
|
|
4
|
+
* Encrypts a given string using the specified algorithm, key, and string encoding.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
8
|
+
* @param {number} tinyCrypto.IV_LENGTH - The byte length of the initialization vector (e.g., 16).
|
|
9
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm (e.g., 'aes-256-cbc').
|
|
10
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding to use when converting buffers to strings (e.g., 'hex', 'base64').
|
|
11
|
+
* @param {string} key - The encryption key.
|
|
12
|
+
* @param {string} text - The plain text to encrypt.
|
|
13
|
+
* @returns {string} The encrypted string in the format `iv:encryptedData`.
|
|
14
|
+
*/
|
|
15
|
+
const cryptoAction = function (tinyCrypto, key, text) {
|
|
16
|
+
let iv = crypto.randomBytes(tinyCrypto.IV_LENGTH);
|
|
17
|
+
let cipher = crypto.createCipheriv(tinyCrypto.algorithm, Buffer.from(key), iv);
|
|
18
|
+
let encrypted = cipher.update(text);
|
|
19
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
20
|
+
return iv.toString(tinyCrypto.stringType) + ':' + encrypted.toString(tinyCrypto.stringType);
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Encrypts a string using one or more keys from the provided crypto configuration.
|
|
24
|
+
*
|
|
25
|
+
* If `tinyCrypto.key` is an array, the encryption is applied sequentially (layered encryption).
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} tinyCrypto - The crypto configuration object.
|
|
28
|
+
* @param {string|string[]} tinyCrypto.key - A single encryption key or an array of keys to apply in sequence.
|
|
29
|
+
* @param {number} tinyCrypto.IV_LENGTH - The byte length of the initialization vector.
|
|
30
|
+
* @param {string} tinyCrypto.algorithm - The encryption algorithm to use.
|
|
31
|
+
* @param {BufferEncoding} tinyCrypto.stringType - The encoding type used for output (e.g., 'hex', 'base64').
|
|
32
|
+
* @param {string} text - The plain text string to encrypt.
|
|
33
|
+
* @returns {string} The final encrypted string.
|
|
34
|
+
*/
|
|
35
|
+
export function encrypt(tinyCrypto, text) {
|
|
36
|
+
// Prepare Result
|
|
37
|
+
let result = text;
|
|
38
|
+
if (!Array.isArray(tinyCrypto.key)) {
|
|
39
|
+
tinyCrypto.key = [tinyCrypto.key];
|
|
40
|
+
}
|
|
41
|
+
for (const item in tinyCrypto.key) {
|
|
42
|
+
result = cryptoAction(tinyCrypto, tinyCrypto.key[item], result);
|
|
43
|
+
}
|
|
44
|
+
// Complete
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var decrypt = require('./decrypt.cjs');
|
|
4
|
+
var _default = require('./default.cjs');
|
|
5
|
+
var encrypt = require('./encrypt.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.decrypt = decrypt.decrypt;
|
|
10
|
+
exports.defaultCrypto = _default;
|
|
11
|
+
exports.encrypt = encrypt.encrypt;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Class representing an authentication system for generating session cookies.
|
|
5
|
+
*
|
|
6
|
+
* The AuthSystem handles checking the authentication time and generating session cookies based on
|
|
7
|
+
* ID token verification. It supports custom time checking and cookie generation logic.
|
|
8
|
+
*
|
|
9
|
+
* @class AuthSystem
|
|
10
|
+
*/
|
|
11
|
+
class AuthSystem {
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of AuthSystem.
|
|
14
|
+
* Initializes default configurations for authentication time checking and session cookie expiration.
|
|
15
|
+
*
|
|
16
|
+
* @constructor
|
|
17
|
+
*/
|
|
18
|
+
constructor() {
|
|
19
|
+
this.auth_time = 5;
|
|
20
|
+
|
|
21
|
+
// Default Values
|
|
22
|
+
const authSystem = this;
|
|
23
|
+
this.default = {
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether the authentication time is within the last 5 minutes.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} decodedIdToken - The decoded ID token object.
|
|
28
|
+
* @param {number} decodedIdToken.auth_time - The authentication time from the ID token.
|
|
29
|
+
* @returns {boolean} Returns `true` if the authentication time is within the last 5 minutes.
|
|
30
|
+
*/
|
|
31
|
+
checkAuthTime: (decodedIdToken) => {
|
|
32
|
+
// Only process if the user just signed in in the last {this.auth_time} minutes.
|
|
33
|
+
if (new Date().getTime() / 1000 - decodedIdToken.auth_time < authSystem.auth_time * 60)
|
|
34
|
+
return true;
|
|
35
|
+
// Nope
|
|
36
|
+
else return false;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generates the session cookie expiration time ({this.auth_time} days by default).
|
|
41
|
+
*
|
|
42
|
+
* @returns {number} Returns the expiration time in milliseconds (5 days).
|
|
43
|
+
*/
|
|
44
|
+
cookieTimeGenerator: () => {
|
|
45
|
+
// Set session expiration to 5 days.
|
|
46
|
+
const expiresIn = 60 * 60 * 24 * authSystem.auth_time * 1000;
|
|
47
|
+
|
|
48
|
+
// Create the session cookie. This will also verify the ID token in the process.
|
|
49
|
+
// The session cookie will have the same claims as the ID token.
|
|
50
|
+
// To only allow session cookie setting on recent sign-in, auth_time in ID token
|
|
51
|
+
// can be checked to ensure user was recently signed in before creating a session cookie.
|
|
52
|
+
|
|
53
|
+
// Complete
|
|
54
|
+
return expiresIn;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Set Value
|
|
59
|
+
this.checkAuthTime = this.default.checkAuthTime;
|
|
60
|
+
this.cookieTimeGenerator = this.default.cookieTimeGenerator;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Sets a custom callback to check authentication time.
|
|
65
|
+
*
|
|
66
|
+
* @param {Function} callback - The callback function to validate authentication time.
|
|
67
|
+
* @returns {void}
|
|
68
|
+
*/
|
|
69
|
+
setCookieTimeGenerator(callback) {
|
|
70
|
+
if (typeof callback === 'function') this.cookieTimeGenerator = callback;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Sets a custom callback to generate the cookie expiration time.
|
|
75
|
+
*
|
|
76
|
+
* @param {Function} callback - The callback function to generate cookie expiration time.
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*/
|
|
79
|
+
setCheckAuthTime(callback) {
|
|
80
|
+
if (typeof callback === 'function') this.checkAuthTime = callback;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Generates a session cookie for the user after verifying the ID token.
|
|
85
|
+
*
|
|
86
|
+
* @param {Object} auth - The authentication object used to verify the ID token and create session cookies.
|
|
87
|
+
* @param {string} token - The ID token of the authenticated user.
|
|
88
|
+
* @returns {Promise<string>} A promise that resolves with the session cookie or rejects with an error.
|
|
89
|
+
*/
|
|
90
|
+
genCookieSession(auth, token) {
|
|
91
|
+
const tinyThis = this;
|
|
92
|
+
return new Promise(function (resolve, reject) {
|
|
93
|
+
auth
|
|
94
|
+
.verifyIdToken(token)
|
|
95
|
+
.then(async (decodedIdToken) => {
|
|
96
|
+
try {
|
|
97
|
+
// Validate the authentication time
|
|
98
|
+
const checkedTime = await tinyThis.checkAuthTime(decodedIdToken);
|
|
99
|
+
if (checkedTime) {
|
|
100
|
+
// Generate session cookie
|
|
101
|
+
const expiresIn = await tinyThis.cookieTimeGenerator(decodedIdToken);
|
|
102
|
+
auth.createSessionCookie(token, { expiresIn }).then(resolve).catch(reject);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Nope
|
|
106
|
+
else {
|
|
107
|
+
const err = new Error('Invalid Account ID Token Time.');
|
|
108
|
+
err.code = 401;
|
|
109
|
+
reject(err);
|
|
110
|
+
}
|
|
111
|
+
} catch (err) {
|
|
112
|
+
// Fail
|
|
113
|
+
reject(err);
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.catch(reject);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
module.exports = AuthSystem;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export default AuthSystem;
|
|
2
|
+
/**
|
|
3
|
+
* Class representing an authentication system for generating session cookies.
|
|
4
|
+
*
|
|
5
|
+
* The AuthSystem handles checking the authentication time and generating session cookies based on
|
|
6
|
+
* ID token verification. It supports custom time checking and cookie generation logic.
|
|
7
|
+
*
|
|
8
|
+
* @class AuthSystem
|
|
9
|
+
*/
|
|
10
|
+
declare class AuthSystem {
|
|
11
|
+
auth_time: number;
|
|
12
|
+
default: {
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether the authentication time is within the last 5 minutes.
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} decodedIdToken - The decoded ID token object.
|
|
17
|
+
* @param {number} decodedIdToken.auth_time - The authentication time from the ID token.
|
|
18
|
+
* @returns {boolean} Returns `true` if the authentication time is within the last 5 minutes.
|
|
19
|
+
*/
|
|
20
|
+
checkAuthTime: (decodedIdToken: {
|
|
21
|
+
auth_time: number;
|
|
22
|
+
}) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Generates the session cookie expiration time ({this.auth_time} days by default).
|
|
25
|
+
*
|
|
26
|
+
* @returns {number} Returns the expiration time in milliseconds (5 days).
|
|
27
|
+
*/
|
|
28
|
+
cookieTimeGenerator: () => number;
|
|
29
|
+
};
|
|
30
|
+
checkAuthTime: (decodedIdToken: {
|
|
31
|
+
auth_time: number;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
cookieTimeGenerator: () => number;
|
|
34
|
+
/**
|
|
35
|
+
* Sets a custom callback to check authentication time.
|
|
36
|
+
*
|
|
37
|
+
* @param {Function} callback - The callback function to validate authentication time.
|
|
38
|
+
* @returns {void}
|
|
39
|
+
*/
|
|
40
|
+
setCookieTimeGenerator(callback: Function): void;
|
|
41
|
+
/**
|
|
42
|
+
* Sets a custom callback to generate the cookie expiration time.
|
|
43
|
+
*
|
|
44
|
+
* @param {Function} callback - The callback function to generate cookie expiration time.
|
|
45
|
+
* @returns {void}
|
|
46
|
+
*/
|
|
47
|
+
setCheckAuthTime(callback: Function): void;
|
|
48
|
+
/**
|
|
49
|
+
* Generates a session cookie for the user after verifying the ID token.
|
|
50
|
+
*
|
|
51
|
+
* @param {Object} auth - The authentication object used to verify the ID token and create session cookies.
|
|
52
|
+
* @param {string} token - The ID token of the authenticated user.
|
|
53
|
+
* @returns {Promise<string>} A promise that resolves with the session cookie or rejects with an error.
|
|
54
|
+
*/
|
|
55
|
+
genCookieSession(auth: Object, token: string): Promise<string>;
|
|
56
|
+
}
|