From 6f462babb861784496f0046b40296f4a57df1889 Mon Sep 17 00:00:00 2001 From: Pascal Klesse Date: Fri, 20 Dec 2024 13:34:22 +0100 Subject: [PATCH] feat: replace crypto api with sha-js --- package-lock.json | 66 +++++++++++++++------------ package.json | 9 ++-- src/runtime/functions/graphql-meta.ts | 10 ++-- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8dc8899..aad696a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,12 +16,13 @@ "@nuxt/kit": "3.14.1592", "@pinia/nuxt": "0.9.0", "gql-query-builder": "3.8.0", - "graphql": "16.9.0", + "graphql": "16.10.0", "graphql-tag": "2.12.6", - "graphql-tools": "9.0.6", + "graphql-tools": "9.0.8", "graphql-ws": "5.16.0", + "js-sha256": "^0.11.0", "jwt-decode": "4.0.0", - "nuxi": "3.16.0", + "nuxi": "3.17.1", "nuxt-graphql-request": "^8.1.1", "vue": "3.5.13" }, @@ -30,7 +31,7 @@ "@nuxt/module-builder": "0.8.4", "@nuxt/schema": "3.14.1592", "@nuxt/test-utils": "3.15.1", - "@types/node": "22.10.1", + "@types/node": "22.10.2", "eslint": "8.57.1", "nuxt": "3.14.1592", "prettier": "3.4.2", @@ -2249,11 +2250,11 @@ } }, "node_modules/@graphql-tools/merge": { - "version": "9.0.12", - "resolved": "https://registry.npmjs.org/@graphql-tools/merge/-/merge-9.0.12.tgz", - "integrity": "sha512-ECkUdgWkizhzQ6JJg16MCYnIN2r2+q/vP5smzi3YeeJkZ/3f9ynFDkaqoMg0Ddg9MugR03hMiQQrssk5f0389Q==", + "version": "9.0.14", + "resolved": "https://registry.npmjs.org/@graphql-tools/merge/-/merge-9.0.14.tgz", + "integrity": "sha512-MO7VXnm3ShpdG51hs4hYsLyu+8o/tSLjNYQmLmR4rkHoFi3kQCDu2r8B4IVwd+Ve39cechj0NyCmMsg+mRvwDQ==", "dependencies": { - "@graphql-tools/utils": "^10.6.2", + "@graphql-tools/utils": "^10.6.4", "tslib": "^2.4.0" }, "engines": { @@ -2387,12 +2388,12 @@ } }, "node_modules/@graphql-tools/schema": { - "version": "10.0.11", - "resolved": "https://registry.npmjs.org/@graphql-tools/schema/-/schema-10.0.11.tgz", - "integrity": "sha512-cYr/7SJSKtdwPByTKHlBr0tYGf7/sYNyzKlPhPMHWoYyGxtn8ytbfF6wEUcxuaOoqksIFxOGr+WOJh1WvShb6A==", + "version": "10.0.13", + "resolved": "https://registry.npmjs.org/@graphql-tools/schema/-/schema-10.0.13.tgz", + "integrity": "sha512-1gvTTuSKej9bR5O2SP9dCKSHaQkVmg9fWU0Aia34HMsAZl2bzosUfXjwBu3ze8MWqb+gRVjdhukDpGA5ZC+5nA==", "dependencies": { - "@graphql-tools/merge": "^9.0.12", - "@graphql-tools/utils": "^10.6.2", + "@graphql-tools/merge": "^9.0.14", + "@graphql-tools/utils": "^10.6.4", "tslib": "^2.4.0", "value-or-promise": "^1.0.12" }, @@ -2430,9 +2431,9 @@ } }, "node_modules/@graphql-tools/utils": { - "version": "10.6.2", - "resolved": "https://registry.npmjs.org/@graphql-tools/utils/-/utils-10.6.2.tgz", - "integrity": "sha512-ABZHTpwiVR8oE2//NI/nnU3nNhbBpqMlMYyCF5cnqjLfhlyOdFfoRuhYEATEsmMfDg0ijGreULywK/SmepVGfw==", + "version": "10.6.4", + "resolved": "https://registry.npmjs.org/@graphql-tools/utils/-/utils-10.6.4.tgz", + "integrity": "sha512-itCgjwVxbO+3uI/K73G9heedG8KelNFzgn368rUhPjTrkJX6NyLQwT5EMq/A8tvazMXyJYdtnN5nD+tT4DUpbQ==", "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", "cross-inspect": "1.0.1", @@ -4760,9 +4761,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", - "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "version": "22.10.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz", + "integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==", "dependencies": { "undici-types": "~6.20.0" } @@ -10866,9 +10867,9 @@ "dev": true }, "node_modules/graphql": { - "version": "16.9.0", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz", - "integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==", + "version": "16.10.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.10.0.tgz", + "integrity": "sha512-AjqGKbDGUFRKIRCP9tCKiIGHyriz2oHEbPIbEtcSLSs4YjReZOIPQQWek4+6hjw62H9QShXHyaGivGiYVLeYFQ==", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } @@ -10977,18 +10978,18 @@ } }, "node_modules/graphql-tools": { - "version": "9.0.6", - "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-9.0.6.tgz", - "integrity": "sha512-QJpEkCmaKRalSLxNJ+5U2O0o8WrhQIs+1UszHGZLqX+PMCFYy7pj2D88Np+79vZTn5V0W/XRW2nu6pt6Fk2kCA==", + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-9.0.8.tgz", + "integrity": "sha512-Xc4efKwugzTsswtQ/Vup6VvCBZ1qy/8CR5mVkVkPmWyl7GmTbQzvIteR4Yr2fegtgXxfmY8YiAY2a71yEBjDhA==", "dependencies": { - "@graphql-tools/schema": "^10.0.11", + "@graphql-tools/schema": "^10.0.13", "tslib": "^2.4.0" }, "engines": { "node": ">=16.0.0" }, "optionalDependencies": { - "@apollo/client": "~3.2.5 || ~3.3.0 || ~3.4.0 || ~3.5.0 || ~3.6.0 || ~3.7.0 || ~3.8.0 || ~3.9.0 || ~3.10.0 || ~3.11.0" + "@apollo/client": "~3.2.5 || ~3.3.0 || ~3.4.0 || ~3.5.0 || ~3.6.0 || ~3.7.0 || ~3.8.0 || ~3.9.0 || ~3.10.0 || ~3.11.0 || ~3.12.0" }, "peerDependencies": { "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" @@ -12187,6 +12188,11 @@ "node": ">=0.10.0" } }, + "node_modules/js-sha256": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.11.0.tgz", + "integrity": "sha512-6xNlKayMZvds9h1Y1VWc0fQHQ82BxTXizWPEtEeGvmOUYpBRy4gbWroHLpzowe6xiQhHpelCQiE7HEdznyBL9Q==" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -14158,9 +14164,9 @@ "integrity": "sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==" }, "node_modules/nuxi": { - "version": "3.16.0", - "resolved": "https://registry.npmjs.org/nuxi/-/nuxi-3.16.0.tgz", - "integrity": "sha512-t9m4zTq44R0/icuzQXJHEyPRM3YbgTPMpytyb6YW2LOL/3mwZ3Bmte1FIlCoigzDvxBJRbcchZGc689+Syyu8w==", + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/nuxi/-/nuxi-3.17.1.tgz", + "integrity": "sha512-Uz3RlQt8IvhvFfA+rQPxG1mRPckMF9TwPzyEh136iZlSW9khcyHvA2uqC++VNlgMRbVyjvhTq8bCpyNPHHZwrA==", "bin": { "nuxi": "bin/nuxi.mjs", "nuxi-ng": "bin/nuxi.mjs", diff --git a/package.json b/package.json index e6471c5..baa163b 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,13 @@ "@nuxt/kit": "3.14.1592", "@pinia/nuxt": "0.9.0", "gql-query-builder": "3.8.0", - "graphql": "16.9.0", + "graphql": "16.10.0", "graphql-tag": "2.12.6", - "graphql-tools": "9.0.6", + "graphql-tools": "9.0.8", "graphql-ws": "5.16.0", + "js-sha256": "0.11.0", "jwt-decode": "4.0.0", - "nuxi": "3.16.0", + "nuxi": "3.17.1", "nuxt-graphql-request": "^8.1.1", "vue": "3.5.13" }, @@ -55,7 +56,7 @@ "@nuxt/module-builder": "0.8.4", "@nuxt/schema": "3.14.1592", "@nuxt/test-utils": "3.15.1", - "@types/node": "22.10.1", + "@types/node": "22.10.2", "eslint": "8.57.1", "nuxt": "3.14.1592", "prettier": "3.4.2", diff --git a/src/runtime/functions/graphql-meta.ts b/src/runtime/functions/graphql-meta.ts index 92a10ba..b543b87 100644 --- a/src/runtime/functions/graphql-meta.ts +++ b/src/runtime/functions/graphql-meta.ts @@ -1,4 +1,5 @@ import { buildClientSchema, getIntrospectionQuery } from 'graphql'; +import { sha256 } from 'js-sha256'; import { ofetch } from 'ofetch'; import type { GraphQLMeta } from '../../generate'; @@ -10,7 +11,7 @@ export async function loadMeta(config: Partial<{ public: { host: string; schema? setTimeout(() => controller.abort(), 5000); return new Promise(async (resolve, reject) => { - const { data: result } = await ofetch(config.public.gqlHost, { + const { data: result } = await ofetch(config.public?.gqlHost, { body: JSON.stringify({ query: getIntrospectionQuery({ descriptions: false }), variables: {}, @@ -30,14 +31,9 @@ export async function loadMeta(config: Partial<{ public: { host: string; schema? /** * Hash a string with SHA-256 - * see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string */ export async function hash(string: string): Promise { - const utf8 = new TextEncoder().encode(string); - const hashBuffer = await crypto.subtle.digest('SHA-256', utf8); - const hashArray = Array.from(new Uint8Array(hashBuffer)); - const hashHex = hashArray.map((bytes) => bytes.toString(16).padStart(2, '0')).join(''); - return hashHex; + return sha256(string); } /**