Skip to content

Commit

Permalink
Last minute v2 fixes (#2007)
Browse files Browse the repository at this point in the history
* Delete tests.yml

* keep checking if it's loaded in the case of persistent layouts

* Update package-lock.json

* warn when crypto subtle is not available

* update composer playground dependencies

* dependency updates

* publish inertia configs in playground

* handle when crypto key is possibly null
  • Loading branch information
joetannenbaum authored Oct 10, 2024
1 parent 9b73c32 commit bc8274c
Show file tree
Hide file tree
Showing 11 changed files with 1,366 additions and 1,051 deletions.
54 changes: 0 additions & 54 deletions .github/workflows/tests.yml

This file was deleted.

33 changes: 33 additions & 0 deletions packages/core/src/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const encryptHistory = async (data: any): Promise<ArrayBuffer> => {
const iv = getIv()
const storedKey = await getKeyFromSessionStorage()
const key = await getOrCreateKey(storedKey)

if (!key) {
throw new Error('Unable to encrypt history')
}

const encrypted = await encryptData(iv, key, data)

return encrypted
Expand All @@ -34,6 +39,12 @@ const encryptData = async (iv: Uint8Array, key: CryptoKey, data: any) => {
throw new Error('Unable to encrypt history')
}

if (typeof window.crypto.subtle === 'undefined') {
console.warn('Encryption is not supported in this environment. SSL is required.')

return Promise.resolve(data)
}

const textEncoder = new TextEncoder()
const str = JSON.stringify(data)
const encoded = new Uint8Array(str.length)
Expand All @@ -51,6 +62,12 @@ const encryptData = async (iv: Uint8Array, key: CryptoKey, data: any) => {
}

const decryptData = async (iv: Uint8Array, key: CryptoKey, data: any) => {
if (typeof window.crypto.subtle === 'undefined') {
console.warn('Decryption is not supported in this environment. SSL is required.')

return Promise.resolve(data)
}

const decrypted = await window.crypto.subtle.decrypt(
{
name: 'AES-GCM',
Expand Down Expand Up @@ -78,6 +95,12 @@ const getIv = () => {
}

const createKey = async () => {
if (typeof window.crypto.subtle === 'undefined') {
console.warn('Encryption is not supported in this environment. SSL is required.')

return Promise.resolve(null)
}

return window.crypto.subtle.generateKey(
{
name: 'AES-GCM',
Expand All @@ -89,6 +112,12 @@ const createKey = async () => {
}

const saveKey = async (key: CryptoKey) => {
if (typeof window.crypto.subtle === 'undefined') {
console.warn('Encryption is not supported in this environment. SSL is required.')

return Promise.resolve()
}

const keyData = await window.crypto.subtle.exportKey('raw', key)

SessionStorage.set(historySessionStorageKeys.key, Array.from(new Uint8Array(keyData)))
Expand All @@ -101,6 +130,10 @@ const getOrCreateKey = async (key: CryptoKey | null) => {

const newKey = await createKey()

if (!newKey) {
return null
}

await saveKey(newKey)

return newKey
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Deferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Deferred = ({ children, data, fallback }: DeferredProps) => {
const keys = Array.isArray(data) ? data : [data]

useEffect(() => {
setLoaded(loaded || keys.every((key) => pageProps[key] !== undefined))
setLoaded(keys.every((key) => pageProps[key] !== undefined))
}, [pageProps, keys])

return loaded ? children : fallback
Expand Down
13 changes: 8 additions & 5 deletions playgrounds/react/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^8.0.2",
"guzzlehttp/guzzle": "^7.2",
"inertiajs/inertia-laravel": "^1.2",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
"inertiajs/inertia-laravel": "2.x-dev",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.7"
},
"require-dev": {
Expand All @@ -19,7 +22,7 @@
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit bc8274c

Please sign in to comment.