Skip to content

Commit

Permalink
Rewrote/added the majority of the v2 docs
Browse files Browse the repository at this point in the history
Fixed bug where: when clicking a menu item, you didn't get scrolled back to the top
Added basic scroll to top button

Signed-off-by: Sam Parton <[email protected]>
  • Loading branch information
iDevelopThings committed Nov 7, 2021
1 parent 830876f commit e3736cc
Show file tree
Hide file tree
Showing 32 changed files with 3,074 additions and 320 deletions.
7 changes: 4 additions & 3 deletions app/Http/Controllers/DocumentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace App\Http\Controllers;

use App\Services\Documentation;
use Arr;
use Str;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;


class DocumentationController extends Controller
{
public function redirect()
{
return redirect(Arr::first(Documentation::versionLinks())['url']);
return redirect(Arr::last(Documentation::versionLinks())['url']);
}

public function page($page)
Expand Down
5 changes: 5 additions & 0 deletions app/Services/Sidebar/SidebarMenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,13 @@ private function versionTwo()
'pages' => [
['title' => 'Routes', 'route' => '2.0/http/routes'],
['title' => 'Request', 'route' => '2.0/http/request'],
['title' => 'File Uploads', 'route' => '2.0/http/file-uploads'],
['title' => 'Response', 'route' => '2.0/http/response'],
['title' => 'Api Resources', 'route' => '2.0/http/api-resources'],
['title' => 'Controllers', 'route' => '2.0/http/controllers'],
['title' => 'Middleware', 'route' => '2.0/http/middleware'],
['title' => 'Cookies', 'route' => '2.0/http/cookies'],
['title' => 'Sessions', 'route' => '2.0/http/sessions'],
],
'sub' => [],
]),
Expand Down Expand Up @@ -258,6 +262,7 @@ private function versionTwo()
['title' => 'Data transfer objects', 'route' => '2.0/additional/data-transfer-objects'],
['title' => 'Encryption/hashing', 'route' => '2.0/additional/encryption-hashing'],
['title' => 'Storage', 'route' => '2.0/additional/storage'],
['title' => 'Static Assets', 'route' => '2.0/additional/static-assets'],
],
'sub' => [],
]),
Expand Down
6 changes: 2 additions & 4 deletions config/docs.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php

return [

'name' => 'Envuso',

'cli_access' => 'envuso'

'cli_access' => 'envuso',
'default_version' => '2.0',
];
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
"production": "mix --production",
"watch-docs": "node watch-docs.js"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.2.11",
Expand All @@ -28,6 +29,7 @@
"@algolia/autocomplete-theme-classic": "^1.4.0",
"algoliasearch": "^4.10.5",
"autoprefixer": "^10.2.5",
"chokidar": "^3.5.2",
"laravel-mix-blade-reload": "^2.0.0",
"tailwindcss": "^2.1.1",
"typesafe-local-storage": "^0.0.7",
Expand Down
25 changes: 22 additions & 3 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

@import './../css/prism-material-oceanic.css';

:not(pre) > code {
padding: 0.3em;
font-size: 0.9rem;
color: #c3cee3;
background: rgb(15, 15, 18);
font-family: 'Fira Code', monospace !important;
line-height: 1.5em;
border-radius: 0.75rem;
--tw-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

.body-wrapper {
@apply flex overflow-hidden h-screen relative;
}
Expand Down Expand Up @@ -81,6 +93,13 @@ p {
@apply text-gray-300 font-medium tracking-normal leading-7 text-sm mt-2;
}

ul {
@apply list-disc list-inside mb-4;
}

li {
@apply text-gray-300 font-medium tracking-normal leading-7 text-sm mt-2;
}

.text {
@apply text-gray-300 font-medium tracking-normal leading-7 text-lg;
Expand Down Expand Up @@ -138,11 +157,11 @@ p {
}

.table-of-contents {

@apply list-none list-outside;
}

.table-of-contents ul {
@apply ml-3;
@apply ml-3 list-none list-outside mb-4;
}

.table-of-contents > li > a {
Expand All @@ -155,7 +174,7 @@ p {
}

.table-of-contents a {
@apply py-1.5 inline-block text-sm;
@apply py-0.5 inline-block text-sm;
}


Expand Down
4 changes: 0 additions & 4 deletions resources/docs/1.0/getting-started/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,3 @@ There will be an **example.env** file, which you can copy and rename to **.env**
You may need to change the following values:
**APP_KEY, APP_HOST, CORS_ORIGIN**
## Directory Structure
You can export the current file by clicking **Export to disk** in the menu. You can choose to export the file as plain Markdown, as HTML using a Handlebars template or as a PDF.
86 changes: 39 additions & 47 deletions resources/docs/2.0/additional/cache.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,83 @@
# Cache

More info needed here.


## Introduction

Right now the cache implementation is quite basic and is based only on Redis.
**Caching will only will only work if you have "redis : {enabled : true}" in your <code class="language-typescript">/src/Config/Database.ts</code> config file.**

## Obtaining a cache instance

You can use it directly via the container, or via static methods
Right now the cache implementation is quite basic and is based only on Redis.

```typescript
import {Cache} from '@envuso/core/Cache';
import {resolve} from '@envuso/core/AppContainer';

Cache.set()
resolve(Cache).set()
```
**You must have the RedisServiceProvider added/loaded to the framework for Caching to work. This is added by default.**

## Retrieving items from the cache

All cache methods are async, so you will need to use .then() or await them to get the result.
You can pass a second parameter to .get() to provide as the default value if the item does not exist in the cache.
By default, the second parameter will return null

```typescript
const value = await Cache.get('some-key');
await Cache.get('some-key');

const nonExistentValue = await Cache.get('some-non-existent-value', 'woop');
// We can also pass a type, .get() uses generics.
await Cache.get<string>('some-string-value');

console.log(nonExistentValue); // returns 'woop';
// We can pass an optional second parameter to use as a fall back. By default this value is null.
await Cache.get('some-non-existent-value', 'woop'); // returns "woop"
```

## Storing items in the cache

#### Storing the item forever
### Storing the item forever

```typescript
import {Cache} from '@envuso/core/Cache';

await Cache.put('some-key', 'some value');
```

#### adding an item that expires at x time
### Adding an item that expires

We can create a new DateTime instance and pass this as a third parameter to set the value to expire at x time.

```typescript
import {Cache} from '@envuso/core/Cache';
import {DateTime} from '@envuso/core/Common';

await Cache.put('some-key', 'some value', DateTime.now().addSeconds(20));

// 25 seconds later...
setTimeout(async () => {
console.log(await Cache.get('some-key')) // returns null
}, 25 * 1000);
await Cache.put('some-key', 'some value', DateTime.now().addHours(24));
// This value will no longer exist after 24 hours
```

## Removing items from the cache

```typescript
import {Cache} from '@envuso/core/Cache';

await Cache.remove('some-key');
```

## check if item exists in cache

.exists() will return true if the item exists, false if it does not exist.
## Checking for existence

```typescript
import {Cache} from '@envuso/core/Cache';

await Cache.exists('some-key'); // returns true or false
await Cache.has('some-key'); // returns boolean
```

## retrieve and store
## Retrieve and Store

Sometimes we may want to store an item in the cache, but return a default if it doesn't. This is how .get() works.
But... what if we want to store an item in the cache if it doesn't exist?
.remember() will return the item from the cache if it exists, if it doesn't, it will add your item and then return it.

When dealing with caching, we usually end up writing the same boilerplate:

```typescript
import {Cache} from '@envuso/core/Cache';
let data = await Cache.get('some-data', null);

if (data) {
return data;
}

data = 'some value';

await Cache.remember('some-key', () => await User.get(), DateTime.now().addSeconds(20));
await Cache.put('some-data', data, DateTime.now().addHours(2))

return data;
```

If exists... return it, if it doesn't, add it then return it.

Now lets look at the remember method:

```typescript
const data = await Cache.remember('some-data', () => 'some value', DateTime.now().addHours(2));

return data; // gives us "some-data"
```

All of that original boilerplate/logic reduced down to 1 line :)

57 changes: 39 additions & 18 deletions resources/docs/2.0/additional/encryption-hashing.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,75 @@
# Encryption/Hashing

More info needed here.


## Encryption

### Introduction
Under the hood we use [SimpleCryptoJS](https://www.npmjs.com/package/simple-crypto-js)
Before you can use any Encryption features, you will need an "APP_KEY" set in your .env file. This should be done already, but just a note!

### Encryption a value
Envuso has two encryption drivers available which can be used where applicable.

#### Encryption - AES-CBC algorithm
More secure encryption but can impact performance.

#### RabbitEncryption - [Wikipedia](https://en.wikipedia.org/wiki/Rabbit_(cipher))
Less secure than AES-CBC but very fast.

Envuso originally used the AES-CBC driver for cookies/session data and response times increased by around 10-30ms. After switching to Rabbit, there is around 1-2 ms difference.

Both drivers implement the "EncryptionContract" interface.

We can obtain Encryption drivers as shown below. All methods are static.
```typescript
import {Encryption} from '@envuso/core/Crypt';
Encryption.encrypt('some string');
// AES-CBC
Encryption.encrypt();
// Rabbit
RabbitEncryption.encrypt();
```

### Decrypting a value
### Encrypting a value
```typescript
import {Encryption} from '@envuso/core/Crypt';

const encryptedString = Encryption.encrypt('some string');
const decryptedString = Encryption.decrypt(encryptedString);
Encryption.encrypt('some string');
RabbitEncryption.encrypt('some string');
```

console.log(decryptedString); // 'some string'
### Decrypting a value
```typescript
Encryption.decrypt(encryptedString);
RabbitEncryption.decrypt(encryptedString);
```

### Getting a secure random
```typescript
import {Encryption} from '@envuso/core/Crypt';
Encryption.random(16);
RabbitEncryption.random(16);
```

### Getting the app secret key
```typescript
Encryption.getKey();
RabbitEncryption.getKey();
```

Encryption.random(16);
### Creating an encryption instance with a custom key
```typescript
Encryption.createInstance('custom secret key').encrypt();
RabbitEncryption.createInstance('custom secret key').encrypt();
```

## Hashing

### Introduction
Under the hood we use [bcrypt](https://www.npmjs.com/package/bcrypt) for all hashing

### Hashing with Bcrypt
```typescript
import {Hash} from '@envuso/core/Common';

Hash.make('some key');
// You can also pass the amount of hashing rounds:
// Default value is 10
Hash.make('some key', 20);
```
### Checking a hash with Bcrypt
```typescript
import {Hash} from '@envuso/core/Common';

const userProvidedPassword = '123';
const user = await User.find({email : 'some email'});

Expand Down
Loading

0 comments on commit e3736cc

Please sign in to comment.