From e49ec1eee2cf27651177f0bb73a775386c42f1ce Mon Sep 17 00:00:00 2001 From: Mathias Gabel Date: Sun, 10 Mar 2024 14:25:47 -0700 Subject: [PATCH 1/2] Simple query for shipping estimate --- app/(api)/_graphql/queries/getShipping.ts | 31 +++++++++++++++++++++++ package-lock.json | 18 ++++++------- package.json | 3 ++- 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 app/(api)/_graphql/queries/getShipping.ts diff --git a/app/(api)/_graphql/queries/getShipping.ts b/app/(api)/_graphql/queries/getShipping.ts new file mode 100644 index 0000000..3ab9cd9 --- /dev/null +++ b/app/(api)/_graphql/queries/getShipping.ts @@ -0,0 +1,31 @@ +import { gql } from '@apollo/client'; + +/* +From https://developer.ups.com/api/reference?loc=en_US#tag/Shipping_other +Shipping info returns: + - Address to ship to + - Box dimensions (length, width, height) + - Box weight + +Takes returned items and puts them into params which will round up the shipping estimate +*/ + +export const getShippingEstimateQuery = gql` + query GetShippingEstimate( + $destination: String! + $weight: Float! + $length: Float! + $width: Float! + $height: Float! + ) { + getShippingEstimate( + destination: $destination + weight: $weight + length: $length + width: $width + height: $height + ) { + roundedUpTwo + } + } +`; diff --git a/package-lock.json b/package-lock.json index 52450b7..df32289 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,8 +8,9 @@ "name": "next-app-router-starter", "version": "0.1.0", "dependencies": { - "@apollo/client": "^3.9.4", + "@apollo/client": "^3.9.6", "@apollo/experimental-nextjs-app-support": "^0.8.0", + "graphql": "^16.8.1", "mongodb": "^6.3.0", "next": "14.0.4", "react": "^18", @@ -62,9 +63,9 @@ } }, "node_modules/@apollo/client": { - "version": "3.9.4", - "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.9.4.tgz", - "integrity": "sha512-Ip6dxjshDT2Dp6foLASTnKBW45Fytew/5JZutZwgc78hVrrGpO9UtZA9xteHXYdap0wIgCxCfeIQwbSu1ZdQpw==", + "version": "3.9.6", + "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.9.6.tgz", + "integrity": "sha512-+zpddcnZ4G2VZ0xIEnvIHFsLqeopNOnWuE2ZVbRuetLLpj/biLPNN719B/iofdd1/iHRclKfv0XaAmX6PBhYKA==", "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", "@wry/caches": "^1.0.0", @@ -74,7 +75,7 @@ "hoist-non-react-statics": "^3.3.2", "optimism": "^0.18.0", "prop-types": "^15.7.2", - "rehackt": "0.0.4", + "rehackt": "0.0.6", "response-iterator": "^0.2.6", "symbol-observable": "^4.0.0", "ts-invariant": "^0.10.3", @@ -3321,7 +3322,6 @@ "version": "16.8.1", "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz", "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", - "peer": true, "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } @@ -5382,9 +5382,9 @@ } }, "node_modules/rehackt": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/rehackt/-/rehackt-0.0.4.tgz", - "integrity": "sha512-xFroSGCbMEK/cTJVhq+c8l/AzIeMeojVyLqtZmr2jmIAFvePjapkCSGg9MnrcNk68HPaMxGf+Ndqozotu78ITw==", + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/rehackt/-/rehackt-0.0.6.tgz", + "integrity": "sha512-l3WEzkt4ntlEc/IB3/mF6SRgNHA6zfQR7BlGOgBTOmx7IJJXojDASav+NsgXHFjHn+6RmwqsGPFgZpabWpeOdw==", "peerDependencies": { "@types/react": "*", "react": "*" diff --git a/package.json b/package.json index 09f8e17..624c947 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,9 @@ "init:windows": "node --env-file=\".\\.env\" \".\\app\\(api)\\_utils\\mongodb\\dbInit.mjs\"" }, "dependencies": { - "@apollo/client": "^3.9.4", + "@apollo/client": "^3.9.6", "@apollo/experimental-nextjs-app-support": "^0.8.0", + "graphql": "^16.8.1", "mongodb": "^6.3.0", "next": "14.0.4", "react": "^18", From 7d497279e138d619d1730b0dc96b942e4c4ed5c7 Mon Sep 17 00:00:00 2001 From: Mathias Gabel Date: Tue, 30 Apr 2024 19:01:55 -0700 Subject: [PATCH 2/2] Text and button enlargement Trying to make the UI more consistent. Also text seemed too small --- app/(api)/ups_api/oauth.ts | 29 +++++++++++++ package-lock.json | 85 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 115 insertions(+) create mode 100644 app/(api)/ups_api/oauth.ts diff --git a/app/(api)/ups_api/oauth.ts b/app/(api)/ups_api/oauth.ts new file mode 100644 index 0000000..1f0b47f --- /dev/null +++ b/app/(api)/ups_api/oauth.ts @@ -0,0 +1,29 @@ +import fetch from 'node-fetch'; + +const client_id = 'PideuJgSmGvAyj5gffCmviGArkXRL8tS3T8Ec6bRLp4h1gwd'; +const client_secret = 'NvROilwfopWTD8V6O0SYTZpzCce70jeoxV2jDmDM6iUEHcqxfnSI4LeIrxINGAAO'; +const shipping_number = 'H6A563'; +const shipping_speed = '12'; + +async function run() { + const formData = { + grant_type: 'authorization_code', + code: shipping_number, + redirect_uri: 'http://localhost:3000', + }; + + const resp = await fetch(`https://wwwcie.ups.com/security/v1/oauth/token`, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + Authorization: + 'Basic ' + Buffer.from(`${client_id}:${client_secret}`).toString('base64'), + }, + body: new URLSearchParams(formData).toString(), + }); + + const data = await resp.text(); + console.log(data); +} + +run(); diff --git a/package-lock.json b/package-lock.json index df32289..af57bff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "graphql": "^16.8.1", "mongodb": "^6.3.0", "next": "14.0.4", + "node-fetch": "^3.3.2", "react": "^18", "react-dom": "^18", "react-icons": "^4.11.0", @@ -1767,6 +1768,14 @@ "integrity": "sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==", "dev": true }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "engines": { + "node": ">= 12" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -2983,6 +2992,28 @@ "reusify": "^1.0.4" } }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -3079,6 +3110,17 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/fraction.js": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz", @@ -4427,6 +4469,41 @@ } } }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, "node_modules/node-releases": { "version": "2.0.14", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", @@ -6576,6 +6653,14 @@ "node": ">=10.13.0" } }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "engines": { + "node": ">= 8" + } + }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index 624c947..8b5adbd 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "graphql": "^16.8.1", "mongodb": "^6.3.0", "next": "14.0.4", + "node-fetch": "^3.3.2", "react": "^18", "react-dom": "^18", "react-icons": "^4.11.0",