sveltekit-auth-example 1.0.51 → 1.0.53

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/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Backlog
2
2
  * Add password complexity checking on /register and /profile pages (only checks for length currently despite what the pages say)
3
3
 
4
+ # 1.0.53
5
+ * Fix service-worker.ts typing
6
+ * Bump pg, sveltekit, svelte, vite, tslib and other devDependencies
7
+
8
+ # 1.0.52
9
+ * Bump @sveltejs/kit, svelte, vite, vitest, pg, adapter-node, google-auth-library, eslint, sass, @typescript*, typescript, prettier, eslint-config-prettier, prettier-plugin-svelte, svelte-check
10
+
4
11
  # 1.0.50
5
12
  * Bump @sveltejs/kit, vite, @typescript*
6
13
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sveltekit-auth-example",
3
3
  "description": "SvelteKit Authentication Example",
4
- "version": "1.0.51",
4
+ "version": "1.0.53",
5
5
  "private": false,
6
6
  "author": "Nate Stuyvesant",
7
7
  "license": "https://github.com/nstuyvesant/sveltekit-auth-example/blob/master/LICENSE",
@@ -32,37 +32,37 @@
32
32
  "format": "prettier --write ."
33
33
  },
34
34
  "engines": {
35
- "node": "^18.14.1",
36
- "npm": "^9.5.0"
35
+ "node": "^18.16.0",
36
+ "npm": "^9.6.7"
37
37
  },
38
38
  "type": "module",
39
39
  "dependencies": {
40
40
  "@sendgrid/mail": "^7.7.0",
41
- "pg": "^8.9.0"
41
+ "pg": "^8.11.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@sveltejs/adapter-node": "^1.2.0",
45
- "@sveltejs/kit": "^1.8.3",
44
+ "@sveltejs/adapter-node": "^1.2.4",
45
+ "@sveltejs/kit": "^1.19.0",
46
46
  "@types/bootstrap": "5.2.6",
47
- "@types/google.accounts": "0.0.6",
48
- "@types/jsonwebtoken": "^9.0.1",
49
- "@types/pg": "^8.6.6",
50
- "@typescript-eslint/eslint-plugin": "^5.53.0",
51
- "@typescript-eslint/parser": "^5.53.0",
47
+ "@types/google.accounts": "^0.0.7",
48
+ "@types/jsonwebtoken": "^9.0.2",
49
+ "@types/pg": "^8.10.1",
50
+ "@typescript-eslint/eslint-plugin": "^5.59.7",
51
+ "@typescript-eslint/parser": "^5.59.7",
52
52
  "bootstrap": "^5.2.3",
53
- "eslint": "^8.34.0",
54
- "eslint-config-prettier": "^8.6.0",
53
+ "eslint": "^8.41.0",
54
+ "eslint-config-prettier": "^8.8.0",
55
55
  "eslint-plugin-svelte3": "^4.0.0",
56
- "google-auth-library": "^8.7.0",
56
+ "google-auth-library": "^8.8.0",
57
57
  "jsonwebtoken": "^9.0.0",
58
- "prettier": "^2.8.4",
59
- "prettier-plugin-svelte": "^2.9.0",
60
- "sass": "^1.58.3",
61
- "svelte": "^3.55.1",
62
- "svelte-check": "^3.0.3",
63
- "tslib": "^2.5.0",
64
- "typescript": "^4.9.5",
65
- "vite": "^4.1.4",
66
- "vitest": "^0.28.5"
58
+ "prettier": "^2.8.8",
59
+ "prettier-plugin-svelte": "^2.10.0",
60
+ "sass": "^1.62.1",
61
+ "svelte": "^3.59.1",
62
+ "svelte-check": "^3.4.3",
63
+ "tslib": "^2.5.2",
64
+ "typescript": "^5.0.4",
65
+ "vite": "^4.3.9",
66
+ "vitest": "^0.31.1"
67
67
  }
68
68
  }
@@ -1,74 +1,68 @@
1
+ /// <reference types="@sveltejs/kit" />
2
+ /// <reference no-default-lib="true"/>
3
+ /// <reference lib="esnext" />
1
4
  /// <reference lib="webworker" />
5
+
2
6
  import { build, files, version } from '$service-worker'
3
7
 
4
- const worker = <ServiceWorkerGlobalScope> <unknown> self
5
- const cacheName = `cache${version}`
6
- const toCache = build.concat(files)
7
- const staticAssets = new Set(toCache)
8
+ const sw = self as unknown as ServiceWorkerGlobalScope
8
9
 
9
- worker.addEventListener('install', event => {
10
- // console.log('[Service Worker] Installation')
11
- event.waitUntil(
12
- caches
13
- .open(cacheName)
14
- .then(cache => cache.addAll(toCache))
15
- .then(() => {
16
- worker.skipWaiting()
17
- })
18
- .catch(error => console.error(error))
19
- )
20
- })
10
+ // Create a unique cache name for this deployment
11
+ const CACHE = `cache-${version}`
21
12
 
22
- worker.addEventListener('activate', event => {
23
- // console.log('[Service Worker] Activation')
24
- event.waitUntil(
25
- caches.keys()
26
- .then(async (keys) => {
27
- for (const key of keys) {
28
- if (key !== cacheName) await caches.delete(key)
29
- }
30
- })
31
- )
32
- worker.clients.claim() // or should this be inside the caches.keys().then()?
33
- })
13
+ const ASSETS = [
14
+ ...build, // the app itself
15
+ ...files // everything in `static`
16
+ ]
17
+
18
+ sw.addEventListener('install', (event) => {
19
+ // Create a new cache and add all files to it
20
+ async function addFilesToCache() {
21
+ const cache = await caches.open(CACHE)
22
+ await cache.addAll(ASSETS)
23
+ }
34
24
 
35
- // Fetch from network into cache and fall back to cache if user offline
36
- async function fetchAndCache(request: Request) {
37
- const cache = await caches.open(`offline${version}`)
25
+ event.waitUntil(addFilesToCache())
26
+ })
38
27
 
39
- try {
40
- const response = await fetch(request)
41
- cache.put(request, response.clone())
42
- return response
43
- } catch (err) {
44
- const response = await cache.match(request)
45
- if (response) return response
46
- throw err
28
+ sw.addEventListener('activate', (event) => {
29
+ // Remove previous cached data from disk
30
+ async function deleteOldCaches() {
31
+ for (const key of await caches.keys()) {
32
+ if (key !== CACHE) await caches.delete(key)
33
+ }
47
34
  }
48
- }
49
35
 
50
- worker.addEventListener('fetch', event => {
51
- if (event.request.method !== 'GET' || event.request.headers.has('range')) return
36
+ event.waitUntil(deleteOldCaches())
37
+ })
38
+
39
+ sw.addEventListener('fetch', (event) => {
40
+ // ignore POST requests etc
41
+ if (event.request.method !== 'GET') return
52
42
 
53
- const url = new URL(event.request.url)
54
- // console.log(`[Service Worker] Fetch ${url}`)
43
+ async function respond() {
44
+ const url = new URL(event.request.url)
45
+ const cache = await caches.open(CACHE)
55
46
 
56
- // don't try to handle data: or blob: URIs
57
- const isHttp = url.protocol.startsWith('http')
58
- const isDevServerRequest = url.hostname === self.location.hostname && url.port !== self.location.port
59
- const isStaticAsset = url.host === self.location.host && staticAssets.has(url.pathname)
60
- const skipBecauseUncached = event.request.cache === 'only-if-cached' && !isStaticAsset
47
+ // `build`/`files` can always be served from the cache
48
+ if (ASSETS.includes(url.pathname)) {
49
+ return cache.match(url.pathname)
50
+ }
61
51
 
62
- if (isHttp && !isDevServerRequest && !skipBecauseUncached) {
63
- event.respondWith(
64
- (async () => {
65
- // always serve static files and bundler-generated assets from cache.
66
- // if your application has other URLs with data that will never change,
67
- // set this variable to true for them and they will only be fetched once.
68
- const cachedAsset = isStaticAsset && (await caches.match(event.request))
52
+ // for everything else, try the network first, but
53
+ // fall back to the cache if we're offline
54
+ try {
55
+ const response = await fetch(event.request)
69
56
 
70
- return cachedAsset || fetchAndCache(event.request)
71
- })()
72
- )
57
+ if (response.status === 200) {
58
+ cache.put(event.request, response.clone())
59
+ }
60
+
61
+ return response
62
+ } catch {
63
+ return cache.match(event.request)
64
+ }
73
65
  }
66
+
67
+ event.respondWith(respond() as PromiseLike<Response>)
74
68
  })