From 398919c0ada4b2ca8b5da336a93850242e70d27f Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Fri, 26 Jul 2024 08:53:01 +0300 Subject: [PATCH 01/10] local init commit --- server/package.json | 7 + server/src/routes/index.ts | 257 ++++++++++++++++++++++++++++--------- yarn.lock | 55 +++++++- 3 files changed, 256 insertions(+), 63 deletions(-) diff --git a/server/package.json b/server/package.json index d4dd26cb2..27f80e2a4 100644 --- a/server/package.json +++ b/server/package.json @@ -68,6 +68,7 @@ "celebrate": "^15.0.1", "compression": "^1.7.4", "cors": "^2.8.5", + "crypto-js": "^4.2.0", "csurf": "^1.11.0", "dotenv": "^16.0.3", "drizzle-orm": "^0.30.10", @@ -97,11 +98,13 @@ "openai": "4.25.0", "osmtogeojson": "^3.0.0-beta.5", "p-queue": "^8.0.1", + "papaparse": "^5.4.1", "passport": "^0.6.0", "passport-google-oauth20": "^2.0.0", "passport-local": "^1.0.0", "piscina": "^4.0.0", "prisma": "^5.7.0", + "querystring": "^0.2.1", "radash": "^12.1.0", "superjson": "^2.0.0", "swagger-jsdoc": "^6.2.8", @@ -111,6 +114,7 @@ "trpc-playground": "^1.0.4", "uuid": "^9.0.0", "validator": "^13.9.0", + "xml2js": "^0.6.2", "zod": "^3.22.4" }, "devDependencies": { @@ -119,7 +123,10 @@ "@cloudflare/workers-types": "4.20240419.0", "@faker-js/faker": "^8.4.1", "@openapitools/openapi-generator-cli": "^2.7.0", + "@types/crypto-js": "^4", "@types/jest": "^29.5.11", + "@types/papaparse": "^5", + "@types/xml2js": "^0", "@typescript-eslint/eslint-plugin": "^6.21.0", "@vitest/ui": "^1.6.0", "cross-env": "^7.0.3", diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index 38944ac30..46247b9fc 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -1,5 +1,3 @@ -// import path from 'path'; -// import csrf from 'csurf'; import packRoutes from './packRoutes'; import itemRoutes from './itemRoutes'; import tripRoutes from './tripRoutes'; @@ -16,33 +14,13 @@ import userRoutes from './userRoutes'; import mapPreviewRouter from './mapPreviewRouter'; import healthRoutes from './healthRoutes'; import { Hono } from 'hono'; +import * as CryptoJS from 'crypto-js'; +import { parseStringPromise } from 'xml2js'; +import Papa from 'papaparse'; +import querystring from 'querystring'; const router = new Hono(); -// Create a CSRF middleware -// const csrfProtection = csrf({ cookie: true }); - -// /** -// * Logs the incoming request method and path, and logs the finished request method, path, status code, and request body. -// * -// * @param {Request} req - The incoming request object. -// * @param {Response} res - The response object. -// * @param {NextFunction} next - The next function to call in the middleware chain. -// */ -// const logger = (req: Request, res: Response, next: express.NextFunction) => { -// console.log(`Incoming ${req.method} ${req.path}`); -// res.on('finish', () => { -// console.log(`Finished ${req.method} ${req.path} ${res.statusCode}`); -// console.log(`Body ${req.body}`); -// }); -// next(); -// }; - -// // use logger middleware in development -// if (process.env.NODE_ENV !== 'production') { -// router.use(logger); -// } - // use routes router.route('/user', userRoutes); router.route('/pack', packRoutes); @@ -61,11 +39,200 @@ router.route('/mapPreview', mapPreviewRouter); router.route('/health', healthRoutes); const helloRouter = new Hono(); -helloRouter.get('/', (c) => { - return c.text('Hello, world!'); + +function generateAWSHeaders( + url, + method, + service, + region, + accessKey, + secretKey, + sessionToken, +) { + const amzDate = new Date() + .toISOString() + .replace(/[:-]/g, '') + .replace(/\.\d{3}/, ''); + const dateStamp = amzDate.slice(0, 8); + const canonicalUri = new URL(url).pathname; + const canonicalQueryString = ''; + const payloadHash = CryptoJS.SHA256('').toString(CryptoJS.enc.Hex); + const canonicalHeaders = + `host:${new URL(url).hostname}\nx-amz-date:${amzDate}\n` + + (sessionToken ? `x-amz-security-token:${sessionToken}\n` : ''); + const signedHeaders = + 'host;x-amz-date' + (sessionToken ? ';x-amz-security-token' : ''); + const canonicalRequest = `${method}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; + + console.log('Canonical Request:', canonicalRequest); + + const algorithm = 'AWS4-HMAC-SHA256'; + const credentialScope = `${dateStamp}/${region}/${service}/aws4_request`; + const stringToSign = `${algorithm}\n${amzDate}\n${credentialScope}\n${CryptoJS.SHA256(canonicalRequest).toString(CryptoJS.enc.Hex)}`; + + console.log('String to Sign:', stringToSign); + + const signingKey = getSignatureKey(secretKey, dateStamp, region, service); + const signature = CryptoJS.HmacSHA256(stringToSign, signingKey).toString( + CryptoJS.enc.Hex, + ); + const authorizationHeader = `${algorithm} Credential=${accessKey}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`; + + return { + host: new URL(url).hostname, + 'x-amz-date': amzDate, + 'x-amz-content-sha256': payloadHash, + Authorization: authorizationHeader, + ...(sessionToken && { 'x-amz-security-token': sessionToken }), + }; +} + +function getSignatureKey(key, dateStamp, regionName, serviceName) { + const kDate = CryptoJS.HmacSHA256(dateStamp, 'AWS4' + key); + const kRegion = CryptoJS.HmacSHA256(regionName, kDate); + const kService = CryptoJS.HmacSHA256(serviceName, kRegion); + const kSigning = CryptoJS.HmacSHA256('aws4_request', kService); + return kSigning; +} + +helloRouter.get('/', async (c) => { + const endpoint = + 'https://a0adf59e1ef3edc3d2bbc2ff272474bc.r2.cloudflarestorage.com'; + const bucket = 'packrat-scrapy-bucket'; + const method = 'GET'; + const region = 'auto'; + const service = 's3'; + const accessKeyId = '1d8b0d85792acd42af61de935c4a1c40'; + const secretKey = + 'e4e9897a4bd4333a6c94846cefcb549bcb386c681ab72dcd00f4f213415a0d5d'; + const sessionToken = ''; + + // Generate AWS Headers for listing bucket contents + const listHeaders = generateAWSHeaders( + endpoint + '/' + bucket, + method, + service, + region, + accessKeyId, + secretKey, + sessionToken, + ); + + try { + // Fetch data from bucket to list contents + const listResponse = await fetch(`${endpoint}/${bucket}`, { + method, + headers: listHeaders, + }); + const listData = await listResponse.text(); + + // Parse XML response + const parsedListData = await parseStringPromise(listData); + const contents = parsedListData.ListBucketResult.Contents; + + // Extract and log file names + const fileNames = contents + .filter((item) => item.Key[0].startsWith('backcountry/')) + .map((item) => item.Key[0]); + + console.log('File names in backcountry directory:', fileNames); + + // Select a specific file to read + const fileName = 'backcountry/backcountry_2024-07-24T08-59-25.csv'; + + // Generate AWS Headers for fetching the specific file + const fileHeaders = generateAWSHeaders( + `${endpoint}/${bucket}/${fileName}`, + method, + service, + region, + accessKeyId, + secretKey, + sessionToken, + ); + + // Fetch the specific CSV file + const fileResponse = await fetch(`${endpoint}/${bucket}/${fileName}`, { + method, + headers: fileHeaders, + }); + const fileData = await fileResponse.text(); + + // Check for errors in the file response + if (fileResponse.status !== 200) { + console.error('Error fetching file:', fileData); + return c.json({ error: 'Error fetching file', details: fileData }); + } + + // Parse the CSV file using PapaParse + Papa.parse(fileData, { + header: true, + complete: function (results) { + console.log('Parsed CSV file contents:', results.data); + }, + error: function (error) { + console.error('Error parsing CSV file:', error); + }, + }); + + return c.json({ message: 'File content logged' }); + } catch (err) { + console.error('Error:', err); + return c.json({ error: 'An error occurred' }); + } }); + +const testapi = new Hono(); router.route('/hello', helloRouter); +testapi.get('/', async (c) => { + const params = c.req.query(); + console.log('Received data:', params); + + return c.json({ message: 'Data received successfully!', data: params }); +}); + +testapi.get('/test', async (c) => { + try { + const postData = querystring.stringify({ + project: 'PackRat', + spider: 'backcountry', + }); + + const response = await fetch('http://localhost:6800/schedule.json', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: postData, + }); + + const responseData = await response.json(); + + if (responseData.status === 'ok') { + console.log('Scraping initiated', responseData); + return c.json({ + message: 'Scraping initiated successfully!', + response: responseData, + }); + } else { + console.error('Error from Scrapyd:', responseData); + return c.json({ + message: 'Failed to initiate scraping', + error: responseData, + }); + } + } catch (error) { + console.error('Error initiating scraping:', error); + return c.json({ + message: 'Failed to initiate scraping', + error: error.toString(), + }); + } +}); + +router.route('/testapi', testapi); + // Also listen to /api for backwards compatibility router.route('/api/user', userRoutes); router.route('/api/pack', packRoutes); @@ -83,38 +250,4 @@ router.route('/api/favorite', favoriteRouters); router.route('/api/openai', openAiRoutes); router.route('/api/mapPreview', mapPreviewRouter); -// // Static routes for serving the React Native Web app -// if (process.env.NODE_ENV === 'production') { -// const __dirname = path.resolve(); -// const serverType = process.env.REACT_APP_SERVER_TYPE || 'vite'; - -// // Serve the client's index.html file at the root route -// router.get('/', (req, res) => { -// // Attach the CSRF token cookie to the response -// // res.cookie("XSRF-TOKEN", req.csrfToken()); - -// const basePath = serverType === 'next' ? '../apps/next/out' : '../apps/vite/dist'; -// res.sendFile(path.resolve(__dirname, basePath, 'index.html')); -// }); - -// // Serve the static assets -// const staticPath = serverType === 'next' ? '../apps/next/out' : '../apps/vite/dist'; -// router.use(express.static(path.join(__dirname, staticPath))); - -// // Serve the client's index.html file at all other routes NOT starting with /api -// router.get(/^(?!\/?api).*/, (req, res) => { -// // res.cookie("XSRF-TOKEN", req.csrfToken()); -// const basePath = serverType === 'next' ? '../apps/next/out' : '../apps/vite/dist'; -// res.sendFile(path.resolve(__dirname, basePath, 'index.html')); -// }); -// } - -// // Attach the CSRF token to a specific route in development -// if (process.env.NODE_ENV !== 'production') { -// router.get('/api/csrf/restore', (req, res) => { -// // res.cookie("XSRF-TOKEN", req.csrfToken()); -// res.status(201).json({}); -// }); -// } - export default router; diff --git a/yarn.lock b/yarn.lock index c5c3d2a76..0f66a67bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10855,6 +10855,13 @@ __metadata: languageName: node linkType: hard +"@types/crypto-js@npm:^4": + version: 4.2.2 + resolution: "@types/crypto-js@npm:4.2.2" + checksum: 10/a40fc5a9219fd33f54ba3e094c5e5ab2904d3106681a76f1029bb038976591e9c8959099963bf4474fde21c2d8d00c1f896445206a3a58f85588f9cb1bd96a9a + languageName: node + linkType: hard + "@types/csurf@npm:*, @types/csurf@npm:^1.11.2": version: 1.11.5 resolution: "@types/csurf@npm:1.11.5" @@ -11217,6 +11224,15 @@ __metadata: languageName: node linkType: hard +"@types/papaparse@npm:^5": + version: 5.3.14 + resolution: "@types/papaparse@npm:5.3.14" + dependencies: + "@types/node": "npm:*" + checksum: 10/9bd5cc0e6a2c02def6c8903dc4604e499907cb465186ed3532390468082a06f023adbac0216428d0d8e8fe017206780a03d20007041e9fed47c8d391cd69a536 + languageName: node + linkType: hard + "@types/prop-types@npm:*": version: 15.7.12 resolution: "@types/prop-types@npm:15.7.12" @@ -11479,6 +11495,15 @@ __metadata: languageName: node linkType: hard +"@types/xml2js@npm:^0": + version: 0.4.14 + resolution: "@types/xml2js@npm:0.4.14" + dependencies: + "@types/node": "npm:*" + checksum: 10/d76338b8d6ce8540c7af6a32aacf96c38f6de48254568f58f6e5ac2af3f88e6bd1490e5346d3bb336990f91267d23c5cc09e8bf7e80840a63c7855dbf174ecbb + languageName: node + linkType: hard + "@types/yargs-parser@npm:*": version: 21.0.3 resolution: "@types/yargs-parser@npm:21.0.3" @@ -16233,6 +16258,13 @@ __metadata: languageName: node linkType: hard +"crypto-js@npm:^4.2.0": + version: 4.2.0 + resolution: "crypto-js@npm:4.2.0" + checksum: 10/c7bcc56a6e01c3c397e95aa4a74e4241321f04677f9a618a8f48a63b5781617248afb9adb0629824792e7ec20ca0d4241a49b6b2938ae6f973ec4efc5c53c924 + languageName: node + linkType: hard + "crypto-random-string@npm:^1.0.0": version: 1.0.0 resolution: "crypto-random-string@npm:1.0.0" @@ -28646,6 +28678,13 @@ __metadata: languageName: node linkType: hard +"papaparse@npm:^5.4.1": + version: 5.4.1 + resolution: "papaparse@npm:5.4.1" + checksum: 10/5e6dc978187182ad2efa1d264ffe73d2042cd23b8fb1dcb0b0f5c8c7c772c11e3eb4e166fb0893880ed24529a96abe9065d704cc5b4cb96abf037413cfe43788 + languageName: node + linkType: hard + "param-case@npm:^3.0.4": version: 3.0.4 resolution: "param-case@npm:3.0.4" @@ -30214,6 +30253,13 @@ __metadata: languageName: node linkType: hard +"querystring@npm:^0.2.1": + version: 0.2.1 + resolution: "querystring@npm:0.2.1" + checksum: 10/5ae2eeb8c6d70263a3d13ffaf234ce9593ae0e95ad8ea04aa540e14ff66679347420817aeb4fe6fdfa2aaa7fac86e311b6f1d3da2187f433082ad9125c808c14 + languageName: node + linkType: hard + "queue-microtask@npm:^1.2.2": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" @@ -32391,12 +32437,15 @@ __metadata: "@trpc/server": "npm:^10.45.1" "@types/bcrypt": "npm:^5.0.0" "@types/cors": "npm:^2.8.13" + "@types/crypto-js": "npm:^4" "@types/csurf": "npm:^1.11.2" "@types/jest": "npm:^29.5.11" "@types/node": "npm:^20.14.2" + "@types/papaparse": "npm:^5" "@types/swagger-jsdoc": "npm:^6.0.1" "@types/swagger-ui-express": "npm:^4.1.3" "@types/validator": "npm:^13.11.1" + "@types/xml2js": "npm:^0" "@typescript-eslint/eslint-plugin": "npm:^6.21.0" "@typescript-eslint/parser": "npm:^6.21.0" "@vitest/ui": "npm:^1.6.0" @@ -32409,6 +32458,7 @@ __metadata: compression: "npm:^1.7.4" cors: "npm:^2.8.5" cross-env: "npm:^7.0.3" + crypto-js: "npm:^4.2.0" csurf: "npm:^1.11.0" dotenv: "npm:^16.0.3" drizzle-kit: "npm:^0.20.17" @@ -32452,12 +32502,14 @@ __metadata: openapi-generator: "npm:^0.1.39" osmtogeojson: "npm:^3.0.0-beta.5" p-queue: "npm:^8.0.1" + papaparse: "npm:^5.4.1" passport: "npm:^0.6.0" passport-google-oauth20: "npm:^2.0.0" passport-local: "npm:^1.0.0" piscina: "npm:^4.0.0" prettier: "npm:^3.2.5" prisma: "npm:^5.7.0" + querystring: "npm:^0.2.1" radash: "npm:^12.1.0" superjson: "npm:^2.0.0" swagger-jsdoc: "npm:^6.2.8" @@ -32473,6 +32525,7 @@ __metadata: validator: "npm:^13.9.0" vitest: "npm:1.3.0" wrangler: "npm:^3.51.2" + xml2js: "npm:^0.6.2" zod: "npm:^3.22.4" languageName: unknown linkType: soft @@ -36762,7 +36815,7 @@ __metadata: languageName: node linkType: hard -"xml2js@npm:0.6.2": +"xml2js@npm:0.6.2, xml2js@npm:^0.6.2": version: 0.6.2 resolution: "xml2js@npm:0.6.2" dependencies: From 5ff3a2698f9e2275422338f3c7579846fdac4340 Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Sat, 3 Aug 2024 18:10:00 +0300 Subject: [PATCH 02/10] local update 80% --- packages/app/components/item/ImportForm.tsx | 36 +- .../app/hooks/items/useImportFromBucket.ts | 55 +++ packages/app/hooks/items/useImportItem.ts | 24 +- packages/app/hooks/packs/useImportPackItem.ts | 17 +- packages/app/package.json | 3 + packages/ui/src/CascadedDropdown.tsx | 41 ++ packages/ui/src/index.tsx | 1 + packages/validations/src/index.d.ts | 3 + packages/validations/src/index.js | 4 + packages/validations/src/index.js.map | 1 + packages/validations/src/utils.d.ts | 2 + packages/validations/src/utils.js | 2 + packages/validations/src/utils.js.map | 1 + .../src/validations/authTokenValidator.d.ts | 15 + .../src/validations/authTokenValidator.js | 8 + .../src/validations/authTokenValidator.js.map | 1 + .../src/validations/destinationValidator.d.ts | 8 + .../src/validations/destinationValidator.js | 5 + .../validations/destinationValidator.js.map | 1 + .../src/validations/extrasValidator.d.ts | 15 + .../src/validations/extrasValidator.js | 8 + .../src/validations/extrasValidator.js.map | 1 + .../validations/src/validations/index.d.ts | 14 + packages/validations/src/validations/index.js | 16 + .../validations/src/validations/index.js.map | 1 + .../src/validations/itemRoutesValidator.d.ts | 202 +++++++++ .../src/validations/itemRoutesValidator.js | 81 ++++ .../validations/itemRoutesValidator.js.map | 1 + .../validations/openAIRoutesValidator.d.ts | 37 ++ .../src/validations/openAIRoutesValidator.js | 16 + .../validations/openAIRoutesValidator.js.map | 1 + .../src/validations/osmValidator.d.ts | 94 ++++ .../src/validations/osmValidator.js | 27 ++ .../src/validations/osmValidator.js.map | 1 + .../src/validations/packRoutesValidator.d.ts | 102 +++++ .../src/validations/packRoutesValidator.js | 45 ++ .../validations/packRoutesValidator.js.map | 1 + .../src/validations/parksRouteValidator.d.ts | 8 + .../src/validations/parksRouteValidator.js | 5 + .../validations/parksRouteValidator.js.map | 1 + .../src/validations/roleValidator.d.ts | 2 + .../src/validations/roleValidator.js | 3 + .../src/validations/roleValidator.js.map | 1 + .../validations/templateRouteValidator.d.ts | 44 ++ .../src/validations/templateRouteValidator.js | 19 + .../validations/templateRouteValidator.js.map | 1 + .../src/validations/trailsRouteValidator.d.ts | 20 + .../src/validations/trailsRouteValidator.js | 9 + .../validations/trailsRouteValidator.js.map | 1 + .../tripRoutesValidator/enums.d.ts | 11 + .../validations/tripRoutesValidator/enums.js | 13 + .../tripRoutesValidator/enums.js.map | 1 + .../tripRoutesValidator/index.d.ts | 2 + .../validations/tripRoutesValidator/index.js | 3 + .../tripRoutesValidator/index.js.map | 1 + .../tripRoutesValidator.d.ts | 422 ++++++++++++++++++ .../tripRoutesValidator.js | 65 +++ .../tripRoutesValidator.js.map | 1 + .../src/validations/userRoutesValidator.d.ts | 268 +++++++++++ .../src/validations/userRoutesValidator.js | 116 +++++ .../validations/userRoutesValidator.js.map | 1 + .../validations/weatherRoutesValidator.d.ts | 21 + .../src/validations/weatherRoutesValidator.js | 10 + .../validations/weatherRoutesValidator.js.map | 1 + .../src/controllers/item/importFromBucket.ts | 293 ++++++++++++ server/src/controllers/item/index.ts | 1 + server/src/drizzle/methods/Item.ts | 17 + server/src/routes/index.ts | 195 -------- server/src/routes/itemRoutes.ts | 8 + server/src/routes/trpcRouter.ts | 3 + .../services/item/bulkAddGlobalItemService.ts | 66 +++ server/src/services/item/item.service.ts | 1 + server/vitest.config.d.ts | 4 +- yarn.lock | 403 ++++++++++++++++- 74 files changed, 2703 insertions(+), 229 deletions(-) create mode 100644 packages/app/hooks/items/useImportFromBucket.ts create mode 100644 packages/ui/src/CascadedDropdown.tsx create mode 100644 packages/validations/src/index.d.ts create mode 100644 packages/validations/src/index.js create mode 100644 packages/validations/src/index.js.map create mode 100644 packages/validations/src/utils.d.ts create mode 100644 packages/validations/src/utils.js create mode 100644 packages/validations/src/utils.js.map create mode 100644 packages/validations/src/validations/authTokenValidator.d.ts create mode 100644 packages/validations/src/validations/authTokenValidator.js create mode 100644 packages/validations/src/validations/authTokenValidator.js.map create mode 100644 packages/validations/src/validations/destinationValidator.d.ts create mode 100644 packages/validations/src/validations/destinationValidator.js create mode 100644 packages/validations/src/validations/destinationValidator.js.map create mode 100644 packages/validations/src/validations/extrasValidator.d.ts create mode 100644 packages/validations/src/validations/extrasValidator.js create mode 100644 packages/validations/src/validations/extrasValidator.js.map create mode 100644 packages/validations/src/validations/index.d.ts create mode 100644 packages/validations/src/validations/index.js create mode 100644 packages/validations/src/validations/index.js.map create mode 100644 packages/validations/src/validations/itemRoutesValidator.d.ts create mode 100644 packages/validations/src/validations/itemRoutesValidator.js create mode 100644 packages/validations/src/validations/itemRoutesValidator.js.map create mode 100644 packages/validations/src/validations/openAIRoutesValidator.d.ts create mode 100644 packages/validations/src/validations/openAIRoutesValidator.js create mode 100644 packages/validations/src/validations/openAIRoutesValidator.js.map create mode 100644 packages/validations/src/validations/osmValidator.d.ts create mode 100644 packages/validations/src/validations/osmValidator.js create mode 100644 packages/validations/src/validations/osmValidator.js.map create mode 100644 packages/validations/src/validations/packRoutesValidator.d.ts create mode 100644 packages/validations/src/validations/packRoutesValidator.js create mode 100644 packages/validations/src/validations/packRoutesValidator.js.map create mode 100644 packages/validations/src/validations/parksRouteValidator.d.ts create mode 100644 packages/validations/src/validations/parksRouteValidator.js create mode 100644 packages/validations/src/validations/parksRouteValidator.js.map create mode 100644 packages/validations/src/validations/roleValidator.d.ts create mode 100644 packages/validations/src/validations/roleValidator.js create mode 100644 packages/validations/src/validations/roleValidator.js.map create mode 100644 packages/validations/src/validations/templateRouteValidator.d.ts create mode 100644 packages/validations/src/validations/templateRouteValidator.js create mode 100644 packages/validations/src/validations/templateRouteValidator.js.map create mode 100644 packages/validations/src/validations/trailsRouteValidator.d.ts create mode 100644 packages/validations/src/validations/trailsRouteValidator.js create mode 100644 packages/validations/src/validations/trailsRouteValidator.js.map create mode 100644 packages/validations/src/validations/tripRoutesValidator/enums.d.ts create mode 100644 packages/validations/src/validations/tripRoutesValidator/enums.js create mode 100644 packages/validations/src/validations/tripRoutesValidator/enums.js.map create mode 100644 packages/validations/src/validations/tripRoutesValidator/index.d.ts create mode 100644 packages/validations/src/validations/tripRoutesValidator/index.js create mode 100644 packages/validations/src/validations/tripRoutesValidator/index.js.map create mode 100644 packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts create mode 100644 packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js create mode 100644 packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map create mode 100644 packages/validations/src/validations/userRoutesValidator.d.ts create mode 100644 packages/validations/src/validations/userRoutesValidator.js create mode 100644 packages/validations/src/validations/userRoutesValidator.js.map create mode 100644 packages/validations/src/validations/weatherRoutesValidator.d.ts create mode 100644 packages/validations/src/validations/weatherRoutesValidator.js create mode 100644 packages/validations/src/validations/weatherRoutesValidator.js.map create mode 100644 server/src/controllers/item/importFromBucket.ts create mode 100644 server/src/services/item/bulkAddGlobalItemService.ts diff --git a/packages/app/components/item/ImportForm.tsx b/packages/app/components/item/ImportForm.tsx index 745a2c742..71aaed775 100644 --- a/packages/app/components/item/ImportForm.tsx +++ b/packages/app/components/item/ImportForm.tsx @@ -1,10 +1,16 @@ import React, { useState, FC } from 'react'; import { View, Platform } from 'react-native'; -import { DropdownComponent, RButton, RText } from '@packrat/ui'; +import { + DropdownComponent, + RButton, + RText, + CascadedDropdownComponent, +} from '@packrat/ui'; import useTheme from '../../hooks/useTheme'; import * as DocumentPicker from 'expo-document-picker'; import { useImportPackItem } from 'app/hooks/packs/useImportPackItem'; import { useImportItem } from 'app/hooks/items/useImportItem'; +import { useImportFromBucket } from 'app/hooks/items/useImportFromBucket'; import useResponsive from 'app/hooks/useResponsive'; interface ImportFormProps { @@ -29,7 +35,11 @@ interface SelectedType { const data = [ { label: 'CSV', value: '.csv', key: '.csv' }, - { label: 'Other', value: '*', key: '*' }, + { label: 'Rei', value: 'rei', key: 'Rei' }, + { label: 'Sierra', value: 'sierra', key: 'Sierra' }, + { label: 'Cabelas', value: 'cabelas', key: 'Cabelas' }, + { label: 'Moosejaw', value: 'moosejaw', key: 'Moosejaw' }, + { label: 'Backcountry', value: 'backcountry', key: 'Backcountry' }, ]; export const ImportForm: FC = ({ @@ -41,6 +51,7 @@ export const ImportForm: FC = ({ const { currentTheme } = useTheme(); const { handleImportNewItems } = useImportItem(); const { importPackItem } = useImportPackItem(); + const { handleImportFromBucket } = useImportFromBucket(); const { xxs } = useResponsive(); const [selectedType, setSelectedType] = useState({ @@ -55,17 +66,17 @@ export const ImportForm: FC = ({ const handleItemImport = async () => { try { - const res = await DocumentPicker.getDocumentAsync({ - type: [selectedType.value], - }); + if (selectedType.value === '.csv') { + const res = await DocumentPicker.getDocumentAsync({ + type: [selectedType.value], + }); - if (res.canceled) { - return; - } + if (res.canceled) { + return; + } - let fileContent; + let fileContent; - if (selectedType.value === '.csv') { if (Platform.OS === 'web') { if (res.assets && res.assets.length > 0) { const file = res.assets[0]; @@ -84,6 +95,8 @@ export const ImportForm: FC = ({ } else { importPackItem({ content: fileContent, packId, ownerId }); } + } else { + handleImportFromBucket({ directory: selectedType.value, ownerId }); } } catch (err) { console.error('Error importing file:', err); @@ -100,9 +113,10 @@ export const ImportForm: FC = ({ justifyContent: 'space-between', width: '100%', marginBottom: 10, + zIndex: 1, }} > - ; +} + +export const useImportFromBucket = () => { + const utils = queryTrpc.useContext(); + const { mutate } = queryTrpc.importFromBucket.useMutation(); + const { isConnected, addOfflineRequest } = useOfflineQueue(); + const updateItems = useItemsUpdater(); + + const handleImportFromBucket = useCallback( + ({ directory, ownerId }) => { + if (isConnected) { + return mutate( + { directory, ownerId }, + { + onSuccess: (data) => { + console.log('ssssssssssssssssssssssssssssssss', data.items); + // Ensure data.items exists and is an array + const newItems = Array.isArray(data.items) ? data.items : []; + + // Update local state with the returned data + updateItems((prevState: State = {}) => { + const prevItems = Array.isArray(prevState.items) + ? prevState.items + : []; + return { + ...prevState, + items: [...newItems, ...prevItems], + }; + }); + + // Invalidate the cache to reflect the latest state + utils.getItemsGlobally.invalidate(); + }, + onError: (error) => { + console.error('Error fetching items:', error); + }, + }, + ); + } else { + // Handle offline scenario + addOfflineRequest('importFromBucket', { directory, ownerId }); + } + }, + [updateItems, isConnected, mutate, utils, addOfflineRequest], + ); + + return { handleImportFromBucket }; +}; diff --git a/packages/app/hooks/items/useImportItem.ts b/packages/app/hooks/items/useImportItem.ts index 91fbcbbc1..158137351 100644 --- a/packages/app/hooks/items/useImportItem.ts +++ b/packages/app/hooks/items/useImportItem.ts @@ -18,23 +18,29 @@ export const useImportItem = () => { if (isConnected) { return mutate(newItem, { onSuccess: () => { + // Update items only on successful mutation + updateItems((prevState: State = {}) => { + const prevItems = Array.isArray(prevState.items) + ? prevState.items + : []; + return { + ...prevState, + items: [newItem, ...prevItems], + }; + }); utils.getItemsGlobally.invalidate(); }, + onError: (error) => { + console.error('Error adding item:', error); + }, }); } addOfflineRequest('addItemGlobal', newItem); - updateItems((prevState: State = {}) => { - const prevItems = Array.isArray(prevState.items) ? prevState.items : []; - - return { - ...prevState, - items: [newItem, ...prevItems], - }; - }); + // Optionally, handle offline case here if needed }, - [updateItems], + [updateItems, isConnected, mutate, utils, addOfflineRequest], ); return { handleImportNewItems }; diff --git a/packages/app/hooks/packs/useImportPackItem.ts b/packages/app/hooks/packs/useImportPackItem.ts index eecb2cc6a..5f558d73c 100644 --- a/packages/app/hooks/packs/useImportPackItem.ts +++ b/packages/app/hooks/packs/useImportPackItem.ts @@ -8,6 +8,13 @@ export const useImportPackItem = () => { throw new Error('Item data is not available.'); } + // Optionally: Perform optimistic update IF NEEDED + + return { + // No need to store previous state if not doing optimistic updates + }; + }, + onSuccess: (data, newItem, context) => { const previousPack = utils.getPackById.getData({ packId: newItem.packId, }); @@ -32,14 +39,14 @@ export const useImportPackItem = () => { newQueryData as any, ); - return { - previousPack, - }; - }, - onSuccess: () => { utils.getPackById.invalidate(); utils.getPacks.invalidate(); }, + onError: (error, newItem, context) => { + console.error('Error adding item:', error); + + // Optionally: Rollback optimistic update here if implemented + }, }); return { diff --git a/packages/app/package.json b/packages/app/package.json index 1bb9dbed0..ebd7bc64b 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -38,6 +38,7 @@ "@react-native-community/geolocation": "^3.0.6", "@react-native-community/netinfo": "11.1.0", "@react-native-google-signin/google-signin": "^9.0.2", + "@react-native-picker/picker": "^2.7.7", "@react-navigation/drawer": "^6.6.6", "@react-navigation/native": "^6.1.6", "@react-navigation/native-stack": "^6.9.12", @@ -120,6 +121,7 @@ "react-native-google-places-autocomplete": "^2.5.1", "react-native-paper": "^5.10.6", "react-native-paper-dates": "^0.18.12", + "react-native-picker-select": "^9.2.0", "react-native-reanimated": "~3.6.2", "react-native-safe-area-context": "4.8.2", "react-native-screens": "~3.29.0", @@ -131,6 +133,7 @@ "react-native-webview": "13.6.4", "react-redux": "^9.0.4", "react-responsive": "^9.0.2", + "react-select": "^5.8.0", "redux-persist": "^6.0.0", "serve": "^14.2.0", "server": "*", diff --git a/packages/ui/src/CascadedDropdown.tsx b/packages/ui/src/CascadedDropdown.tsx new file mode 100644 index 000000000..76a7c56bd --- /dev/null +++ b/packages/ui/src/CascadedDropdown.tsx @@ -0,0 +1,41 @@ +import { RSelect } from '@packrat/ui'; +import React from 'react'; +import { View, Platform } from 'react-native'; + +interface DropdownComponentProps { + width?: string | number; + style?: any; + placeholder?: any; + native?: boolean; + // zeego?: boolean; + [x: string]: any; // for the rest of the props +} + +export const CascadedDropdownComponent: React.FC = ({ + width, + style = {}, + placeholder, + // zeego = false, + ...props +}) => { + const isWeb = Platform.OS === 'web'; + + return ( + + + + ); +}; + +export default CascadedDropdownComponent; diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx index f7d319802..3d15e888b 100644 --- a/packages/ui/src/index.tsx +++ b/packages/ui/src/index.tsx @@ -33,6 +33,7 @@ export { Container } from './Container'; export { MainContentWeb } from './MainContentWeb'; export { ContextMenu, RContextMenu } from './RContextMenu'; export { DropdownComponent } from './Dropdown'; +export { CascadedDropdownComponent } from './CascadedDropdown'; // export { DropdownMenu, ExampleDropdown } from './RDropdown/DropdownBase'; export { RSkeleton } from './RSkeleton'; diff --git a/packages/validations/src/index.d.ts b/packages/validations/src/index.d.ts new file mode 100644 index 000000000..e2141618c --- /dev/null +++ b/packages/validations/src/index.d.ts @@ -0,0 +1,3 @@ +export * from './validations'; +export * from './utils'; +export { ZodSchema } from 'zod'; diff --git a/packages/validations/src/index.js b/packages/validations/src/index.js new file mode 100644 index 000000000..06a998996 --- /dev/null +++ b/packages/validations/src/index.js @@ -0,0 +1,4 @@ +export * from './validations'; +export * from './utils'; +export { ZodSchema } from 'zod'; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/validations/src/index.js.map b/packages/validations/src/index.js.map new file mode 100644 index 000000000..634b03ee5 --- /dev/null +++ b/packages/validations/src/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/utils.d.ts b/packages/validations/src/utils.d.ts new file mode 100644 index 000000000..33fb93473 --- /dev/null +++ b/packages/validations/src/utils.d.ts @@ -0,0 +1,2 @@ +import { ZodSchema, z } from 'zod'; +export type ValidationType = z.infer; diff --git a/packages/validations/src/utils.js b/packages/validations/src/utils.js new file mode 100644 index 000000000..e6c75f0b7 --- /dev/null +++ b/packages/validations/src/utils.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/packages/validations/src/utils.js.map b/packages/validations/src/utils.js.map new file mode 100644 index 000000000..9e95c93e8 --- /dev/null +++ b/packages/validations/src/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/packages/validations/src/validations/authTokenValidator.d.ts b/packages/validations/src/validations/authTokenValidator.d.ts new file mode 100644 index 000000000..d5c75a663 --- /dev/null +++ b/packages/validations/src/validations/authTokenValidator.d.ts @@ -0,0 +1,15 @@ +import { z } from 'zod'; +export declare const TokenSchema: z.ZodObject<{ + id: z.ZodString; +}, "strip", z.ZodTypeAny, { + id?: string; +}, { + id?: string; +}>; +export declare const googleSignin: z.ZodObject<{ + idToken: z.ZodString; +}, "strip", z.ZodTypeAny, { + idToken?: string; +}, { + idToken?: string; +}>; diff --git a/packages/validations/src/validations/authTokenValidator.js b/packages/validations/src/validations/authTokenValidator.js new file mode 100644 index 000000000..e2e0126d7 --- /dev/null +++ b/packages/validations/src/validations/authTokenValidator.js @@ -0,0 +1,8 @@ +import { z } from 'zod'; +export const TokenSchema = z.object({ + id: z.string(), +}); +export const googleSignin = z.object({ + idToken: z.string().nonempty(), +}); +//# sourceMappingURL=authTokenValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/authTokenValidator.js.map b/packages/validations/src/validations/authTokenValidator.js.map new file mode 100644 index 000000000..8c8a7be1f --- /dev/null +++ b/packages/validations/src/validations/authTokenValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"authTokenValidator.js","sourceRoot":"","sources":["authTokenValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/destinationValidator.d.ts b/packages/validations/src/validations/destinationValidator.d.ts new file mode 100644 index 000000000..eb5313eac --- /dev/null +++ b/packages/validations/src/validations/destinationValidator.d.ts @@ -0,0 +1,8 @@ +import { z } from 'zod'; +export declare const getDestinationByid: z.ZodObject<{ + id: z.ZodString; +}, "strip", z.ZodTypeAny, { + id?: string; +}, { + id?: string; +}>; diff --git a/packages/validations/src/validations/destinationValidator.js b/packages/validations/src/validations/destinationValidator.js new file mode 100644 index 000000000..559c8b8fb --- /dev/null +++ b/packages/validations/src/validations/destinationValidator.js @@ -0,0 +1,5 @@ +import { z } from 'zod'; +export const getDestinationByid = z.object({ + id: z.string(), +}); +//# sourceMappingURL=destinationValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/destinationValidator.js.map b/packages/validations/src/validations/destinationValidator.js.map new file mode 100644 index 000000000..ae0d9f0c7 --- /dev/null +++ b/packages/validations/src/validations/destinationValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"destinationValidator.js","sourceRoot":"","sources":["destinationValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/extrasValidator.d.ts b/packages/validations/src/validations/extrasValidator.d.ts new file mode 100644 index 000000000..b680a72c1 --- /dev/null +++ b/packages/validations/src/validations/extrasValidator.d.ts @@ -0,0 +1,15 @@ +import { z } from 'zod'; +export declare const AddressArray: z.ZodObject<{ + addressArray: z.ZodString; +}, "strip", z.ZodTypeAny, { + addressArray?: string; +}, { + addressArray?: string; +}>; +export declare const handlePasswordReset: z.ZodObject<{ + token: z.ZodString; +}, "strip", z.ZodTypeAny, { + token?: string; +}, { + token?: string; +}>; diff --git a/packages/validations/src/validations/extrasValidator.js b/packages/validations/src/validations/extrasValidator.js new file mode 100644 index 000000000..818efd8ec --- /dev/null +++ b/packages/validations/src/validations/extrasValidator.js @@ -0,0 +1,8 @@ +import { z } from 'zod'; +export const AddressArray = z.object({ + addressArray: z.string(), +}); +export const handlePasswordReset = z.object({ + token: z.string(), +}); +//# sourceMappingURL=extrasValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/extrasValidator.js.map b/packages/validations/src/validations/extrasValidator.js.map new file mode 100644 index 000000000..6f6a643e5 --- /dev/null +++ b/packages/validations/src/validations/extrasValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"extrasValidator.js","sourceRoot":"","sources":["extrasValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/index.d.ts b/packages/validations/src/validations/index.d.ts new file mode 100644 index 000000000..0d21d0029 --- /dev/null +++ b/packages/validations/src/validations/index.d.ts @@ -0,0 +1,14 @@ +export * from './userRoutesValidator'; +export * from './tripRoutesValidator'; +export * from './packRoutesValidator'; +export * from './itemRoutesValidator'; +export * from './destinationValidator'; +export * from './osmValidator'; +export * from './parksRouteValidator'; +export * from './trailsRouteValidator'; +export * from './openAIRoutesValidator'; +export * from './extrasValidator'; +export * from './templateRouteValidator'; +export * from './weatherRoutesValidator'; +export * from './roleValidator'; +export * from './authTokenValidator'; diff --git a/packages/validations/src/validations/index.js b/packages/validations/src/validations/index.js new file mode 100644 index 000000000..4b714963d --- /dev/null +++ b/packages/validations/src/validations/index.js @@ -0,0 +1,16 @@ +// export default userRoutesValidator; +export * from './userRoutesValidator'; +export * from './tripRoutesValidator'; +export * from './packRoutesValidator'; +export * from './itemRoutesValidator'; +export * from './destinationValidator'; +export * from './osmValidator'; +export * from './parksRouteValidator'; +export * from './trailsRouteValidator'; +export * from './openAIRoutesValidator'; +export * from './extrasValidator'; +export * from './templateRouteValidator'; +export * from './weatherRoutesValidator'; +export * from './roleValidator'; +export * from './authTokenValidator'; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/index.js.map b/packages/validations/src/validations/index.js.map new file mode 100644 index 000000000..38c546543 --- /dev/null +++ b/packages/validations/src/validations/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/itemRoutesValidator.d.ts b/packages/validations/src/validations/itemRoutesValidator.d.ts new file mode 100644 index 000000000..c8a5a76c4 --- /dev/null +++ b/packages/validations/src/validations/itemRoutesValidator.d.ts @@ -0,0 +1,202 @@ +import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; +import { z } from 'zod'; +export declare const getItemByName: z.ZodObject<{ + name: z.ZodString; +}, "strip", z.ZodTypeAny, { + name?: string; +}, { + name?: string; +}>; +export declare const getItems: z.ZodObject<{ + packId: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + packId?: string; +}, { + packId?: string; +}>; +export declare const getItemById: z.ZodObject<{ + id: z.ZodString; +}, "strip", z.ZodTypeAny, { + id?: string; +}, { + id?: string; +}>; +export declare const addItem: z.ZodObject<{ + name: z.ZodString; + weight: z.ZodNumber; + quantity: z.ZodNumber; + unit: z.ZodString; + packId: z.ZodString; + type: z.ZodString; + ownerId: z.ZodString; + id: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + type?: string; + packId?: string; + weight?: number; + quantity?: number; + unit?: string; + ownerId?: string; +}, { + id?: string; + name?: string; + type?: string; + packId?: string; + weight?: number; + quantity?: number; + unit?: string; + ownerId?: string; +}>; +export declare const importItem: z.ZodObject<{ + content: z.ZodString; + packId: z.ZodString; + ownerId: z.ZodString; +}, "strip", z.ZodTypeAny, { + packId?: string; + ownerId?: string; + content?: string; +}, { + packId?: string; + ownerId?: string; + content?: string; +}>; +export type Item = z.infer; +export declare const editItem: z.ZodObject<{ + id: z.ZodString; + name: z.ZodString; + weight: z.ZodNumber; + quantity: z.ZodNumber; + unit: z.ZodString; + type: z.ZodString; +}, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + type?: string; + weight?: number; + quantity?: number; + unit?: string; +}, { + id?: string; + name?: string; + type?: string; + weight?: number; + quantity?: number; + unit?: string; +}>; +export declare const addGlobalItemToPack: z.ZodObject<{ + packId: z.ZodString; + itemId: z.ZodString; + ownerId: z.ZodString; +}, "strip", z.ZodTypeAny, { + packId?: string; + ownerId?: string; + itemId?: string; +}, { + packId?: string; + ownerId?: string; + itemId?: string; +}>; +export declare const deleteGlobalItem: z.ZodObject<{ + itemId: z.ZodString; +}, "strip", z.ZodTypeAny, { + itemId?: string; +}, { + itemId?: string; +}>; +export declare const editGlobalItemAsDuplicate: z.ZodObject<{ + itemId: z.ZodString; + packId: z.ZodString; +}, "strip", z.ZodTypeAny, { + packId?: string; + itemId?: string; +}, { + packId?: string; + itemId?: string; +}>; +export declare const deleteItem: z.ZodObject<{ + itemId: z.ZodString; + packId: z.ZodString; +}, "strip", z.ZodTypeAny, { + packId?: string; + itemId?: string; +}, { + packId?: string; + itemId?: string; +}>; +export declare const addItemGlobal: z.ZodObject<{ + name: z.ZodString; + weight: z.ZodNumber; + quantity: z.ZodNumber; + unit: z.ZodString; + type: z.ZodString; + ownerId: z.ZodString; +}, "strip", z.ZodTypeAny, { + name?: string; + type?: string; + weight?: number; + quantity?: number; + unit?: string; + ownerId?: string; +}, { + name?: string; + type?: string; + weight?: number; + quantity?: number; + unit?: string; + ownerId?: string; +}>; +export declare const importItemsGlobal: z.ZodObject<{ + content: z.ZodString; + ownerId: z.ZodString; +}, "strip", z.ZodTypeAny, { + ownerId?: string; + content?: string; +}, { + ownerId?: string; + content?: string; +}>; +export declare const getItemsGlobally: z.ZodObject<{ + limit: z.ZodNumber; + page: z.ZodNumber; +}, "strip", z.ZodTypeAny, { + limit?: number; + page?: number; +}, { + limit?: number; + page?: number; +}>; +export declare const getSimilarItems: z.ZodObject<{ + id: z.ZodString; + limit: z.ZodNumber; + visibility: z.ZodDefault>; +}, "strip", z.ZodTypeAny, { + id?: string; + limit?: number; + visibility?: PackAndItemVisibilityFilter; +}, { + id?: string; + limit?: number; + visibility?: PackAndItemVisibilityFilter; +}>; +export declare const importItemHeaders: z.ZodObject<{ + Name: z.ZodString; + Weight: z.ZodString; + Unit: z.ZodString; + Quantity: z.ZodString; + Category: z.ZodString; +}, "strip", z.ZodTypeAny, { + Name?: string; + Weight?: string; + Unit?: string; + Quantity?: string; + Category?: string; +}, { + Name?: string; + Weight?: string; + Unit?: string; + Quantity?: string; + Category?: string; +}>; +export type ImportItemHeaders = z.infer; diff --git a/packages/validations/src/validations/itemRoutesValidator.js b/packages/validations/src/validations/itemRoutesValidator.js new file mode 100644 index 000000000..b823eb59f --- /dev/null +++ b/packages/validations/src/validations/itemRoutesValidator.js @@ -0,0 +1,81 @@ +import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; +import { z } from 'zod'; +export const getItemByName = z.object({ + name: z.string(), +}); +export const getItems = z.object({ + packId: z.string().optional(), +}); +export const getItemById = z.object({ + id: z.string(), +}); +export const addItem = z.object({ + name: z.string(), + weight: z.number(), + quantity: z.number(), + unit: z.string(), + packId: z.string(), + type: z.string(), + ownerId: z.string(), + id: z.string().optional(), +}); +export const importItem = z.object({ + content: z.string(), + packId: z.string(), + ownerId: z.string(), +}); +export const editItem = z.object({ + id: z.string(), + name: z.string().nonempty(), + weight: z.number(), + quantity: z.number(), + unit: z.string(), + type: z.string(), +}); +export const addGlobalItemToPack = z.object({ + packId: z.string(), + itemId: z.string(), + ownerId: z.string(), +}); +export const deleteGlobalItem = z.object({ + itemId: z.string(), +}); +export const editGlobalItemAsDuplicate = z.object({ + itemId: z.string(), + packId: z.string(), +}); +export const deleteItem = z.object({ + itemId: z.string(), + packId: z.string(), +}); +export const addItemGlobal = z.object({ + name: z.string(), + weight: z.number(), + quantity: z.number(), + unit: z.string(), + type: z.string(), + ownerId: z.string(), +}); +export const importItemsGlobal = z.object({ + content: z.string(), + ownerId: z.string(), +}); +export const getItemsGlobally = z.object({ + limit: z.number(), + page: z.number(), +}); +export const getSimilarItems = z.object({ + id: z.string(), + limit: z.number(), + visibility: z + .nativeEnum(PackAndItemVisibilityFilter) + .default(PackAndItemVisibilityFilter.ALL), +}); +export const importItemHeaders = z.object({ + Name: z.string(), + Weight: z.string(), + Unit: z.string(), + Quantity: z.string(), + Category: z.string(), +}); +//# sourceMappingURL=itemRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/itemRoutesValidator.js.map b/packages/validations/src/validations/itemRoutesValidator.js.map new file mode 100644 index 000000000..8f49490dd --- /dev/null +++ b/packages/validations/src/validations/itemRoutesValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"itemRoutesValidator.js","sourceRoot":"","sources":["itemRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB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AAE;IACnB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,UAAU,EAAE,CAAC;SACV,UAAU,CAAC,2BAA2B,CAAC;SACvC,OAAO,CAAC,2BAA2B,CAAC,GAAG,CAAC;CAC5C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/openAIRoutesValidator.d.ts b/packages/validations/src/validations/openAIRoutesValidator.d.ts new file mode 100644 index 000000000..70ae14918 --- /dev/null +++ b/packages/validations/src/validations/openAIRoutesValidator.d.ts @@ -0,0 +1,37 @@ +import { z } from 'zod'; +export declare const getAIResponse: z.ZodObject<{ + userId: z.ZodString; + itemTypeId: z.ZodString; + userInput: z.ZodString; +}, "strip", z.ZodTypeAny, { + userId?: string; + itemTypeId?: string; + userInput?: string; +}, { + userId?: string; + itemTypeId?: string; + userInput?: string; +}>; +export declare const getUserChats: z.ZodObject<{ + userId: z.ZodString; + itemTypeId: z.ZodString; +}, "strip", z.ZodTypeAny, { + userId?: string; + itemTypeId?: string; +}, { + userId?: string; + itemTypeId?: string; +}>; +export declare const getAISuggestions: z.ZodObject<{ + userId: z.ZodString; + itemTypeId: z.ZodString; + type: z.ZodString; +}, "strip", z.ZodTypeAny, { + userId?: string; + type?: string; + itemTypeId?: string; +}, { + userId?: string; + type?: string; + itemTypeId?: string; +}>; diff --git a/packages/validations/src/validations/openAIRoutesValidator.js b/packages/validations/src/validations/openAIRoutesValidator.js new file mode 100644 index 000000000..f92dbdf5b --- /dev/null +++ b/packages/validations/src/validations/openAIRoutesValidator.js @@ -0,0 +1,16 @@ +import { z } from 'zod'; +export const getAIResponse = z.object({ + userId: z.string(), + itemTypeId: z.string(), + userInput: z.string(), +}); +export const getUserChats = z.object({ + userId: z.string(), + itemTypeId: z.string(), +}); +export const getAISuggestions = z.object({ + userId: z.string(), + itemTypeId: z.string(), + type: z.string(), +}); +//# sourceMappingURL=openAIRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/openAIRoutesValidator.js.map b/packages/validations/src/validations/openAIRoutesValidator.js.map new file mode 100644 index 000000000..f342c7851 --- /dev/null +++ b/packages/validations/src/validations/openAIRoutesValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"openAIRoutesValidator.js","sourceRoot":"","sources":["openAIRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/osmValidator.d.ts b/packages/validations/src/validations/osmValidator.d.ts new file mode 100644 index 000000000..ef831f1a4 --- /dev/null +++ b/packages/validations/src/validations/osmValidator.d.ts @@ -0,0 +1,94 @@ +import { z } from 'zod'; +export declare const getOsm: z.ZodObject<{ + activityType: z.ZodString; + startPoint: z.ZodObject<{ + latitude: z.ZodNumber; + longitude: z.ZodNumber; + }, "strip", z.ZodTypeAny, { + latitude?: number; + longitude?: number; + }, { + latitude?: number; + longitude?: number; + }>; + endPoint: z.ZodObject<{ + latitude: z.ZodNumber; + longitude: z.ZodNumber; + }, "strip", z.ZodTypeAny, { + latitude?: number; + longitude?: number; + }, { + latitude?: number; + longitude?: number; + }>; +}, "strip", z.ZodTypeAny, { + activityType?: string; + startPoint?: { + latitude?: number; + longitude?: number; + }; + endPoint?: { + latitude?: number; + longitude?: number; + }; +}, { + activityType?: string; + startPoint?: { + latitude?: number; + longitude?: number; + }; + endPoint?: { + latitude?: number; + longitude?: number; + }; +}>; +export declare const getParksOSM: z.ZodObject<{ + lat: z.ZodNumber; + lon: z.ZodNumber; + radius: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + lat?: number; + lon?: number; + radius?: number; +}, { + lat?: number; + lon?: number; + radius?: number; +}>; +export declare const getPhotonDetails: z.ZodObject<{ + id: z.ZodUnion<[z.ZodString, z.ZodNumber]>; + type: z.ZodString; +}, "strip", z.ZodTypeAny, { + id?: string | number; + type?: string; +}, { + id?: string | number; + type?: string; +}>; +export declare const getPhotonResults: z.ZodObject<{ + searchString: z.ZodString; +}, "strip", z.ZodTypeAny, { + searchString?: string; +}, { + searchString?: string; +}>; +export declare const getTrailsOSM: z.ZodObject<{ + lat: z.ZodNumber; + lon: z.ZodNumber; + radius: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + lat?: number; + lon?: number; + radius?: number; +}, { + lat?: number; + lon?: number; + radius?: number; +}>; +export declare const postSingleGeoJSON: z.ZodObject<{ + geojson: z.ZodAny; +}, "strip", z.ZodTypeAny, { + geojson?: any; +}, { + geojson?: any; +}>; diff --git a/packages/validations/src/validations/osmValidator.js b/packages/validations/src/validations/osmValidator.js new file mode 100644 index 000000000..b2789ae6b --- /dev/null +++ b/packages/validations/src/validations/osmValidator.js @@ -0,0 +1,27 @@ +import { z } from 'zod'; +export const getOsm = z.object({ + activityType: z.string(), + startPoint: z.object({ latitude: z.number(), longitude: z.number() }), + endPoint: z.object({ latitude: z.number(), longitude: z.number() }), +}); +export const getParksOSM = z.object({ + lat: z.number(), + lon: z.number(), + radius: z.number().optional(), +}); +export const getPhotonDetails = z.object({ + id: z.union([z.string(), z.number()]), + type: z.string(), +}); +export const getPhotonResults = z.object({ + searchString: z.string(), +}); +export const getTrailsOSM = z.object({ + lat: z.number(), + lon: z.number(), + radius: z.number().optional(), +}); +export const postSingleGeoJSON = z.object({ + geojson: z.any(), +}); +//# sourceMappingURL=osmValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/osmValidator.js.map b/packages/validations/src/validations/osmValidator.js.map new file mode 100644 index 000000000..25330308f --- /dev/null +++ b/packages/validations/src/validations/osmValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"osmValidator.js","sourceRoot":"","sources":["osmValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACrE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;CACpE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE;CACjB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/packRoutesValidator.d.ts b/packages/validations/src/validations/packRoutesValidator.d.ts new file mode 100644 index 000000000..7f88b979f --- /dev/null +++ b/packages/validations/src/validations/packRoutesValidator.d.ts @@ -0,0 +1,102 @@ +import { z } from 'zod'; +import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; +export declare const getPacks: z.ZodObject<{ + ownerId: z.ZodString; + queryBy: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + ownerId?: string; + queryBy?: string; +}, { + ownerId?: string; + queryBy?: string; +}>; +export declare const getPackById: z.ZodObject<{ + packId: z.ZodString; +}, "strip", z.ZodTypeAny, { + packId?: string; +}, { + packId?: string; +}>; +export declare const addPack: z.ZodObject<{ + name: z.ZodString; + owner_id: z.ZodString; + is_public: z.ZodBoolean; +}, "strip", z.ZodTypeAny, { + name?: string; + owner_id?: string; + is_public?: boolean; +}, { + name?: string; + owner_id?: string; + is_public?: boolean; +}>; +export declare const editPack: z.ZodObject<{ + id: z.ZodString; + name: z.ZodString; + is_public: z.ZodBoolean; +}, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + is_public?: boolean; +}, { + id?: string; + name?: string; + is_public?: boolean; +}>; +export declare const deletePack: z.ZodObject<{ + packId: z.ZodString; +}, "strip", z.ZodTypeAny, { + packId?: string; +}, { + packId?: string; +}>; +export declare const getPublicPacks: z.ZodObject<{ + queryBy: z.ZodString; +}, "strip", z.ZodTypeAny, { + queryBy?: string; +}, { + queryBy?: string; +}>; +export declare const sendMessage: z.ZodObject<{ + message: z.ZodString; +}, "strip", z.ZodTypeAny, { + message?: string; +}, { + message?: string; +}>; +export declare const addPackSchema: z.ZodObject<{ + name: z.ZodString; + isPublic: z.ZodUnion<[z.ZodLiteral<"0">, z.ZodLiteral<"1">]>; +}, "strip", z.ZodTypeAny, { + name?: string; + isPublic?: "1" | "0"; +}, { + name?: string; + isPublic?: "1" | "0"; +}>; +export declare const duplicatePublicPack: z.ZodObject<{ + packId: z.ZodString; + ownerId: z.ZodString; + items: z.ZodArray; +}, "strip", z.ZodTypeAny, { + packId?: string; + ownerId?: string; + items?: string[]; +}, { + packId?: string; + ownerId?: string; + items?: string[]; +}>; +export declare const getSimilarPacks: z.ZodObject<{ + id: z.ZodString; + limit: z.ZodNumber; + visibility: z.ZodDefault>; +}, "strip", z.ZodTypeAny, { + id?: string; + limit?: number; + visibility?: PackAndItemVisibilityFilter; +}, { + id?: string; + limit?: number; + visibility?: PackAndItemVisibilityFilter; +}>; diff --git a/packages/validations/src/validations/packRoutesValidator.js b/packages/validations/src/validations/packRoutesValidator.js new file mode 100644 index 000000000..350616d53 --- /dev/null +++ b/packages/validations/src/validations/packRoutesValidator.js @@ -0,0 +1,45 @@ +import { z } from 'zod'; +import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; +export const getPacks = z.object({ + ownerId: z.string(), + queryBy: z.string().optional(), +}); +export const getPackById = z.object({ + packId: z.string(), +}); +export const addPack = z.object({ + name: z.string(), + owner_id: z.string(), + is_public: z.boolean(), +}); +export const editPack = z.object({ + id: z.string(), + name: z.string(), + is_public: z.boolean(), +}); +export const deletePack = z.object({ + packId: z.string(), +}); +export const getPublicPacks = z.object({ + queryBy: z.string(), +}); +export const sendMessage = z.object({ + message: z.string().nonempty(), +}); +export const addPackSchema = z.object({ + name: z.string().nonempty(), + isPublic: z.union([z.literal('0'), z.literal('1')]), +}); +export const duplicatePublicPack = z.object({ + packId: z.string(), + ownerId: z.string(), + items: z.array(z.string()), +}); +export const getSimilarPacks = z.object({ + id: z.string(), + limit: z.number(), + visibility: z + .nativeEnum(PackAndItemVisibilityFilter) + .default(PackAndItemVisibilityFilter.ALL), +}); +//# sourceMappingURL=packRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/packRoutesValidator.js.map b/packages/validations/src/validations/packRoutesValidator.js.map new file mode 100644 index 000000000..e5914b8bf --- /dev/null +++ b/packages/validations/src/validations/packRoutesValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"packRoutesValidator.js","sourceRoot":"","sources":["packRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE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;IACpC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;CACpD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAC3B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,UAAU,EAAE,CAAC;SACV,UAAU,CAAC,2BAA2B,CAAC;SACvC,OAAO,CAAC,2BAA2B,CAAC,GAAG,CAAC;CAC5C,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/parksRouteValidator.d.ts b/packages/validations/src/validations/parksRouteValidator.d.ts new file mode 100644 index 000000000..9b00234ac --- /dev/null +++ b/packages/validations/src/validations/parksRouteValidator.d.ts @@ -0,0 +1,8 @@ +import { z } from 'zod'; +export declare const getParks: z.ZodObject<{ + abbrState: z.ZodString; +}, "strip", z.ZodTypeAny, { + abbrState?: string; +}, { + abbrState?: string; +}>; diff --git a/packages/validations/src/validations/parksRouteValidator.js b/packages/validations/src/validations/parksRouteValidator.js new file mode 100644 index 000000000..39653c5db --- /dev/null +++ b/packages/validations/src/validations/parksRouteValidator.js @@ -0,0 +1,5 @@ +import { z } from 'zod'; +export const getParks = z.object({ + abbrState: z.string(), +}); +//# sourceMappingURL=parksRouteValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/parksRouteValidator.js.map b/packages/validations/src/validations/parksRouteValidator.js.map new file mode 100644 index 000000000..be1d53e90 --- /dev/null +++ b/packages/validations/src/validations/parksRouteValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"parksRouteValidator.js","sourceRoot":"","sources":["parksRouteValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/roleValidator.d.ts b/packages/validations/src/validations/roleValidator.d.ts new file mode 100644 index 000000000..677fd86a6 --- /dev/null +++ b/packages/validations/src/validations/roleValidator.d.ts @@ -0,0 +1,2 @@ +import { z } from 'zod'; +export declare const RoleSchema: z.ZodUnion<[z.ZodLiteral<"user">, z.ZodLiteral<"admin">]>; diff --git a/packages/validations/src/validations/roleValidator.js b/packages/validations/src/validations/roleValidator.js new file mode 100644 index 000000000..a562e5a5b --- /dev/null +++ b/packages/validations/src/validations/roleValidator.js @@ -0,0 +1,3 @@ +import { z } from 'zod'; +export const RoleSchema = z.union([z.literal('user'), z.literal('admin')]); +//# sourceMappingURL=roleValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/roleValidator.js.map b/packages/validations/src/validations/roleValidator.js.map new file mode 100644 index 000000000..4803e92dd --- /dev/null +++ b/packages/validations/src/validations/roleValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"roleValidator.js","sourceRoot":"","sources":["roleValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/templateRouteValidator.d.ts b/packages/validations/src/validations/templateRouteValidator.d.ts new file mode 100644 index 000000000..4f49d1cfd --- /dev/null +++ b/packages/validations/src/validations/templateRouteValidator.d.ts @@ -0,0 +1,44 @@ +import { z } from 'zod'; +export declare const addTemplate: z.ZodObject<{ + type: z.ZodAny; + templateId: z.ZodString; + isGlobalTemplate: z.ZodBoolean; + createdBy: z.ZodString; +}, "strip", z.ZodTypeAny, { + type?: any; + templateId?: string; + isGlobalTemplate?: boolean; + createdBy?: string; +}, { + type?: any; + templateId?: string; + isGlobalTemplate?: boolean; + createdBy?: string; +}>; +export declare const editTemplate: z.ZodObject<{ + templateId: z.ZodString; + type: z.ZodString; + isGlobalTemplate: z.ZodBoolean; +}, "strip", z.ZodTypeAny, { + type?: string; + templateId?: string; + isGlobalTemplate?: boolean; +}, { + type?: string; + templateId?: string; + isGlobalTemplate?: boolean; +}>; +export declare const deleteTemplate: z.ZodObject<{ + templateId: z.ZodString; +}, "strip", z.ZodTypeAny, { + templateId?: string; +}, { + templateId?: string; +}>; +export declare const getTemplateById: z.ZodObject<{ + templateId: z.ZodString; +}, "strip", z.ZodTypeAny, { + templateId?: string; +}, { + templateId?: string; +}>; diff --git a/packages/validations/src/validations/templateRouteValidator.js b/packages/validations/src/validations/templateRouteValidator.js new file mode 100644 index 000000000..1ce85f1e5 --- /dev/null +++ b/packages/validations/src/validations/templateRouteValidator.js @@ -0,0 +1,19 @@ +import { z } from 'zod'; +export const addTemplate = z.object({ + type: z.any(), + templateId: z.string(), + isGlobalTemplate: z.boolean(), + createdBy: z.string(), +}); +export const editTemplate = z.object({ + templateId: z.string(), + type: z.string(), + isGlobalTemplate: z.boolean(), +}); +export const deleteTemplate = z.object({ + templateId: z.string(), +}); +export const getTemplateById = z.object({ + templateId: z.string(), +}); +//# sourceMappingURL=templateRouteValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/templateRouteValidator.js.map b/packages/validations/src/validations/templateRouteValidator.js.map new file mode 100644 index 000000000..9a37c8821 --- /dev/null +++ b/packages/validations/src/validations/templateRouteValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"templateRouteValidator.js","sourceRoot":"","sources":["templateRouteValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE;IACb,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE;IAC7B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/trailsRouteValidator.d.ts b/packages/validations/src/validations/trailsRouteValidator.d.ts new file mode 100644 index 000000000..413d17f4a --- /dev/null +++ b/packages/validations/src/validations/trailsRouteValidator.d.ts @@ -0,0 +1,20 @@ +import { z } from 'zod'; +export declare const getTrails: z.ZodObject<{ + administrative_area_level_1: z.ZodString; + country: z.ZodString; + locality: z.ZodString; + latitude: z.ZodNumber; + longitude: z.ZodNumber; +}, "strip", z.ZodTypeAny, { + latitude?: number; + longitude?: number; + administrative_area_level_1?: string; + country?: string; + locality?: string; +}, { + latitude?: number; + longitude?: number; + administrative_area_level_1?: string; + country?: string; + locality?: string; +}>; diff --git a/packages/validations/src/validations/trailsRouteValidator.js b/packages/validations/src/validations/trailsRouteValidator.js new file mode 100644 index 000000000..ebf0f2e51 --- /dev/null +++ b/packages/validations/src/validations/trailsRouteValidator.js @@ -0,0 +1,9 @@ +import { z } from 'zod'; +export const getTrails = z.object({ + administrative_area_level_1: z.string(), + country: z.string(), + locality: z.string(), + latitude: z.number(), + longitude: z.number(), +}); +//# sourceMappingURL=trailsRouteValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/trailsRouteValidator.js.map b/packages/validations/src/validations/trailsRouteValidator.js.map new file mode 100644 index 000000000..8f09c54d9 --- /dev/null +++ b/packages/validations/src/validations/trailsRouteValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"trailsRouteValidator.js","sourceRoot":"","sources":["trailsRouteValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,2BAA2B,EAAE,CAAC,CAAC,MAAM,EAAE;IACvC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/enums.d.ts b/packages/validations/src/validations/tripRoutesValidator/enums.d.ts new file mode 100644 index 000000000..aab2c9ed4 --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/enums.d.ts @@ -0,0 +1,11 @@ +export declare enum TripActivity { + TRIP = "trip", + RUNNING = "running", + BIKING = "biking", + CAMPING = "camping", + FISHING = "fishing", + TREKKING = "trekking", + ROCK_CLIMBING = "rock-climbing", + HIKING = "hiking", + SWIMMING = "swimming" +} diff --git a/packages/validations/src/validations/tripRoutesValidator/enums.js b/packages/validations/src/validations/tripRoutesValidator/enums.js new file mode 100644 index 000000000..bccf33a95 --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/enums.js @@ -0,0 +1,13 @@ +export var TripActivity; +(function (TripActivity) { + TripActivity["TRIP"] = "trip"; + TripActivity["RUNNING"] = "running"; + TripActivity["BIKING"] = "biking"; + TripActivity["CAMPING"] = "camping"; + TripActivity["FISHING"] = "fishing"; + TripActivity["TREKKING"] = "trekking"; + TripActivity["ROCK_CLIMBING"] = "rock-climbing"; + TripActivity["HIKING"] = "hiking"; + TripActivity["SWIMMING"] = "swimming"; +})(TripActivity || (TripActivity = {})); +//# sourceMappingURL=enums.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/enums.js.map b/packages/validations/src/validations/tripRoutesValidator/enums.js.map new file mode 100644 index 000000000..98e05579d --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/enums.js.map @@ -0,0 +1 @@ +{"version":3,"file":"enums.js","sourceRoot":"","sources":["enums.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;IACrB,+CAA+B,CAAA;IAC/B,iCAAiB,CAAA;IACjB,qCAAqB,CAAA;AACvB,CAAC,EAVW,YAAY,KAAZ,YAAY,QAUvB"} \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/index.d.ts b/packages/validations/src/validations/tripRoutesValidator/index.d.ts new file mode 100644 index 000000000..8982e4e59 --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/index.d.ts @@ -0,0 +1,2 @@ +export * from './tripRoutesValidator'; +export * from './enums'; diff --git a/packages/validations/src/validations/tripRoutesValidator/index.js b/packages/validations/src/validations/tripRoutesValidator/index.js new file mode 100644 index 000000000..8c831362d --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/index.js @@ -0,0 +1,3 @@ +export * from './tripRoutesValidator'; +export * from './enums'; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/index.js.map b/packages/validations/src/validations/tripRoutesValidator/index.js.map new file mode 100644 index 000000000..f9a060e4c --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts new file mode 100644 index 000000000..8fbb7b641 --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts @@ -0,0 +1,422 @@ +import { z } from 'zod'; +export declare const addTripForm: z.ZodObject<{ + name: z.ZodString; + description: z.ZodString; + is_public: z.ZodUnion<[z.ZodLiteral<"0">, z.ZodLiteral<"1">]>; +}, "strip", z.ZodTypeAny, { + name?: string; + is_public?: "1" | "0"; + description?: string; +}, { + name?: string; + is_public?: "1" | "0"; + description?: string; +}>; +export declare const getTrips: z.ZodObject<{ + owner_id: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + owner_id?: string; +}, { + owner_id?: string; +}>; +export declare const getTripById: z.ZodObject<{ + tripId: z.ZodString; +}, "strip", z.ZodTypeAny, { + tripId?: string; +}, { + tripId?: string; +}>; +export declare const addTripDetails: z.ZodObject<{ + duration: z.ZodString; + start_date: z.ZodString; + end_date: z.ZodString; + destination: z.ZodString; + type: z.ZodEnum<[string, ...string[]]>; + park: z.ZodOptional; + trail: z.ZodOptional; + geoJSON: z.ZodObject<{ + type: z.ZodLiteral<"FeatureCollection">; + features: z.ZodArray; + id: z.ZodString; + properties: z.ZodRecord>; + geometry: z.ZodUnion<[z.ZodObject<{ + type: z.ZodString; + coordinates: any; + }, "strip", z.ZodTypeAny, { + type?: string; + coordinates?: any; + }, { + type?: string; + coordinates?: any; + }>, z.ZodObject<{ + type: z.ZodLiteral<"GeometryCollection">; + geometries: z.ZodArray, "many">; + }, "strip", z.ZodTypeAny, { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }, { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }>]>; + }, "strip", z.ZodTypeAny, { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }, { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }>, "many">; + }, "strip", z.ZodTypeAny, { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }, { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }>; + owner_id: z.ZodString; + pack_id: z.ZodString; +}, "strip", z.ZodTypeAny, { + pack_id?: string; + owner_id?: string; + type?: string; + duration?: string; + start_date?: string; + end_date?: string; + destination?: string; + geoJSON?: { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }; + park?: string; + trail?: string; +}, { + pack_id?: string; + owner_id?: string; + type?: string; + duration?: string; + start_date?: string; + end_date?: string; + destination?: string; + geoJSON?: { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }; + park?: string; + trail?: string; +}>; +export declare const addTrip: z.ZodObject; + park: z.ZodOptional; + trail: z.ZodOptional; + geoJSON: z.ZodObject<{ + type: z.ZodLiteral<"FeatureCollection">; + features: z.ZodArray; + id: z.ZodString; + properties: z.ZodRecord>; + geometry: z.ZodUnion<[z.ZodObject<{ + type: z.ZodString; + coordinates: any; + }, "strip", z.ZodTypeAny, { + type?: string; + coordinates?: any; + }, { + type?: string; + coordinates?: any; + }>, z.ZodObject<{ + type: z.ZodLiteral<"GeometryCollection">; + geometries: z.ZodArray, "many">; + }, "strip", z.ZodTypeAny, { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }, { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }>]>; + }, "strip", z.ZodTypeAny, { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }, { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }>, "many">; + }, "strip", z.ZodTypeAny, { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }, { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }>; + owner_id: z.ZodString; + pack_id: z.ZodString; +}, { + name: z.ZodString; + description: z.ZodString; + is_public: z.ZodUnion<[z.ZodLiteral<"0">, z.ZodLiteral<"1">]>; +}>, "strip", z.ZodTypeAny, { + name?: string; + pack_id?: string; + owner_id?: string; + is_public?: "1" | "0"; + type?: string; + description?: string; + duration?: string; + start_date?: string; + end_date?: string; + destination?: string; + geoJSON?: { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }; + park?: string; + trail?: string; +}, { + name?: string; + pack_id?: string; + owner_id?: string; + is_public?: "1" | "0"; + type?: string; + description?: string; + duration?: string; + start_date?: string; + end_date?: string; + destination?: string; + geoJSON?: { + type?: "FeatureCollection"; + features?: { + id?: string; + type?: "Feature"; + properties?: Record; + geometry?: { + type?: string; + coordinates?: any; + } | { + type?: "GeometryCollection"; + geometries?: { + type?: string; + coordinates?: any; + }[]; + }; + }[]; + }; + park?: string; + trail?: string; +}>; +export declare const editTrip: z.ZodObject<{ + id: z.ZodString; + name: z.ZodOptional; + duration: z.ZodOptional; + start_date: z.ZodOptional; + end_date: z.ZodOptional; + destination: z.ZodOptional; + is_public: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + is_public?: boolean; + duration?: string; + start_date?: string; + end_date?: string; + destination?: string; +}, { + id?: string; + name?: string; + is_public?: boolean; + duration?: string; + start_date?: string; + end_date?: string; + destination?: string; +}>; +export declare const deleteTrip: z.ZodObject<{ + tripId: z.ZodString; +}, "strip", z.ZodTypeAny, { + tripId?: string; +}, { + tripId?: string; +}>; +export declare const queryTrip: z.ZodObject<{ + queryBy: z.ZodString; + tripId: z.ZodString; +}, "strip", z.ZodTypeAny, { + tripId?: string; + queryBy?: string; +}, { + tripId?: string; + queryBy?: string; +}>; diff --git a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js new file mode 100644 index 000000000..18e058e70 --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js @@ -0,0 +1,65 @@ +import { z } from 'zod'; +import { TripActivity } from './enums'; +const tripActivityValues = Object.values(TripActivity); +export const addTripForm = z.object({ + name: z.string().nonempty(), + description: z.string().nonempty(), + is_public: z.union([z.literal('0'), z.literal('1')]), +}); +// @ts-ignore +const coordinateSchema = z.lazy(() => z.union([z.number(), z.array(coordinateSchema)])); +const baseGeometrySchema = z.object({ + type: z.string(), + coordinates: coordinateSchema, +}); +const geometryCollectionSchema = z.object({ + type: z.literal('GeometryCollection'), + geometries: z.array(baseGeometrySchema), +}); +const geometrySchema = z.union([baseGeometrySchema, geometryCollectionSchema]); +const featurePropertiesSchema = z.record(z.union([z.string(), z.number(), z.boolean()])); +const featureSchema = z.object({ + type: z.literal('Feature'), + id: z.string(), + properties: featurePropertiesSchema, + geometry: geometrySchema, +}); +export const getTrips = z.object({ + owner_id: z.string().optional(), +}); +export const getTripById = z.object({ + tripId: z.string(), +}); +export const addTripDetails = z.object({ + duration: z.string(), + start_date: z.string(), + end_date: z.string(), + destination: z.string(), + type: z.enum(tripActivityValues), + park: z.string().optional(), + trail: z.string().optional(), + geoJSON: z.object({ + type: z.literal('FeatureCollection'), + features: z.array(featureSchema), + }), + owner_id: z.string(), + pack_id: z.string(), +}); +export const addTrip = addTripDetails.merge(addTripForm); +export const editTrip = z.object({ + id: z.string(), + name: z.string().optional(), + duration: z.string().optional(), + start_date: z.string().optional(), + end_date: z.string().optional(), + destination: z.string().optional(), + is_public: z.boolean().optional(), +}); +export const deleteTrip = z.object({ + tripId: z.string().nonempty(), +}); +export const queryTrip = z.object({ + queryBy: z.string(), + tripId: z.string(), +}); +//# sourceMappingURL=tripRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map new file mode 100644 index 000000000..4d490a05a --- /dev/null +++ b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"tripRoutesValidator.js","sourceRoot":"","sources":["tripRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAA0B,CAAC;AAEhF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;CACrD,CAAC,CAAC;AAEH,aAAa;AACb,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACnC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CACjD,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,WAAW,EAAE,gBAAgB;CAC9B,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC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/userRoutesValidator.d.ts b/packages/validations/src/validations/userRoutesValidator.d.ts new file mode 100644 index 000000000..8a7796059 --- /dev/null +++ b/packages/validations/src/validations/userRoutesValidator.d.ts @@ -0,0 +1,268 @@ +import { z } from 'zod'; +export declare const userSignUp: z.ZodObject<{ + name: z.ZodString; + email: z.ZodEffects; + password: z.ZodEffects; + username: z.ZodString; +}, "strip", z.ZodTypeAny, { + name?: string; + password?: string; + email?: string; + username?: string; +}, { + name?: string; + password?: string; + email?: string; + username?: string; +}>; +export declare const userSignIn: z.ZodObject<{ + email: z.ZodEffects; + password: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + password?: string; + email?: string; +}, { + password?: string; + email?: string; +}>; +export declare const sentEmail: z.ZodObject<{ + email: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + email?: string; +}, { + email?: string; +}>; +export declare const resetPassword: z.ZodObject<{ + resetToken: z.ZodString; + password: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + password?: string; + resetToken?: string; +}, { + password?: string; + resetToken?: string; +}>; +export declare const getFirebaseUserByEmail: z.ZodObject<{ + email: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + email?: string; +}, { + email?: string; +}>; +export declare const checkCode: z.ZodObject<{ + email: z.ZodEffects; + code: z.ZodString; +}, "strip", z.ZodTypeAny, { + email?: string; + code?: string; +}, { + email?: string; + code?: string; +}>; +export declare const emailExists: z.ZodObject<{ + email: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + email?: string; +}, { + email?: string; +}>; +export declare const getUserById: z.ZodObject<{ + userId: z.ZodString; +}, "strip", z.ZodTypeAny, { + userId?: string; +}, { + userId?: string; +}>; +export declare const addToFavorite: z.ZodObject<{ + packId: z.ZodString; + userId: z.ZodString; +}, "strip", z.ZodTypeAny, { + userId?: string; + packId?: string; +}, { + userId?: string; + packId?: string; +}>; +export declare const editUser: z.ZodObject<{ + id: z.ZodString; + name: z.ZodOptional; + password: z.ZodOptional>; + email: z.ZodOptional; + code: z.ZodOptional; + role: z.ZodOptional>; + username: z.ZodOptional; + offlineMaps: z.ZodNullable; + bounds: z.ZodArray, "many">; + minZoom: z.ZodNumber; + maxZoom: z.ZodNumber; + }, "strip", z.ZodTypeAny, { + metadata?: { + shape?: string; + }; + name?: string; + styleURL?: string; + bounds?: number[][]; + minZoom?: number; + maxZoom?: number; + }, { + metadata?: { + shape?: string; + }; + name?: string; + styleURL?: string; + bounds?: number[][]; + minZoom?: number; + maxZoom?: number; + }>>>>; + profileImage: z.ZodNullable>; + preferredWeather: z.ZodOptional; + preferredWeight: z.ZodOptional; +}, "strip", z.ZodTypeAny, { + id?: string; + name?: string; + password?: string; + email?: string; + code?: string; + offlineMaps?: Record; + role?: "user" | "admin"; + username?: string; + profileImage?: string; + preferredWeather?: string; + preferredWeight?: string; +}, { + id?: string; + name?: string; + password?: string; + email?: string; + code?: string; + offlineMaps?: Record; + role?: "user" | "admin"; + username?: string; + profileImage?: string; + preferredWeather?: string; + preferredWeight?: string; +}>; +export declare const deleteUser: z.ZodObject<{ + userId: z.ZodString; +}, "strip", z.ZodTypeAny, { + userId?: string; +}, { + userId?: string; +}>; +export declare const deleteUserForm: z.ZodObject<{ + confirmText: z.ZodLiteral<"delete">; +}, "strip", z.ZodTypeAny, { + confirmText?: "delete"; +}, { + confirmText?: "delete"; +}>; +export declare const linkFirebaseAuth: z.ZodObject<{ + firebaseAuthToken: z.ZodString; +}, "strip", z.ZodTypeAny, { + firebaseAuthToken?: string; +}, { + firebaseAuthToken?: string; +}>; +export declare const createMongoDBUser: z.ZodObject<{ + email: z.ZodString; + name: z.ZodString; + password: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + name?: string; + password?: string; + email?: string; +}, { + name?: string; + password?: string; + email?: string; +}>; +export declare const login: z.ZodObject<{ + email: z.ZodString; + password: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + password?: string; + email?: string; +}, { + password?: string; + email?: string; +}>; +export declare const updatePassword: z.ZodObject<{ + email: z.ZodEffects; + password: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + password?: string; + email?: string; +}, { + password?: string; + email?: string; +}>; +export declare const userSettingsSchema: z.ZodObject<{ + name: z.ZodString; + email: z.ZodEffects; + username: z.ZodString; + profileImage: z.ZodOptional; + preferredWeather: z.ZodUnion<[z.ZodLiteral<"celsius">, z.ZodLiteral<"fahrenheit">]>; + preferredWeight: z.ZodUnion<[z.ZodLiteral<"lb">, z.ZodLiteral<"oz">, z.ZodLiteral<"kg">, z.ZodLiteral<"g">]>; +}, "strip", z.ZodTypeAny, { + name?: string; + email?: string; + username?: string; + profileImage?: string; + preferredWeather?: "celsius" | "fahrenheit"; + preferredWeight?: "lb" | "g" | "kg" | "oz"; +}, { + name?: string; + email?: string; + username?: string; + profileImage?: string; + preferredWeather?: "celsius" | "fahrenheit"; + preferredWeight?: "lb" | "g" | "kg" | "oz"; +}>; +export declare const passwordChangeSchema: z.ZodEffects; + newPassword: z.ZodEffects; + confirmPassword: z.ZodEffects; +}, "strip", z.ZodTypeAny, { + oldPassword?: string; + newPassword?: string; + confirmPassword?: string; +}, { + oldPassword?: string; + newPassword?: string; + confirmPassword?: string; +}>, { + oldPassword?: string; + newPassword?: string; + confirmPassword?: string; +}, { + oldPassword?: string; + newPassword?: string; + confirmPassword?: string; +}>; diff --git a/packages/validations/src/validations/userRoutesValidator.js b/packages/validations/src/validations/userRoutesValidator.js new file mode 100644 index 000000000..62336fd0e --- /dev/null +++ b/packages/validations/src/validations/userRoutesValidator.js @@ -0,0 +1,116 @@ +import { z } from 'zod'; +const emailValidator = z + .string({ required_error: 'Email is required' }) + .email() + .transform((str) => str.trim().toLowerCase()); +const passwordValidator = z + .string({ required_error: 'Password is required' }) + .min(7) + .refine((str) => !str.includes('password'), { + message: `The password cannot contain the word 'password'`, +}); +export const userSignUp = z.object({ + name: z.string().min(1).nonempty(), + email: emailValidator, + password: passwordValidator, + username: z.string().nonempty(), +}); +export const userSignIn = z.object({ + email: emailValidator, + password: passwordValidator, +}); +export const sentEmail = z.object({ + email: emailValidator, +}); +export const resetPassword = z.object({ + resetToken: z.string().nonempty(), + password: passwordValidator, +}); +export const getFirebaseUserByEmail = z.object({ + email: emailValidator, +}); +export const checkCode = z.object({ + email: emailValidator, + code: z.string().nonempty(), +}); +export const emailExists = z.object({ + email: emailValidator, +}); +export const getUserById = z.object({ + userId: z.string().nonempty(), +}); +export const addToFavorite = z.object({ + packId: z.string(), + userId: z.string(), +}); +export const editUser = z.object({ + id: z.string(), + name: z.string().optional(), + password: passwordValidator.optional(), + email: z.string().optional(), + code: z.string().optional(), + role: z.enum(['user', 'admin']).optional(), + username: z.string().optional(), + offlineMaps: z + .record(z.string(), z.object({ + name: z.string(), + styleURL: z.string(), + metadata: z.object({ + shape: z.string(), + }), + bounds: z.array(z.array(z.number())), + minZoom: z.number(), + maxZoom: z.number(), + })) + .optional() + .nullable(), + profileImage: z.string().optional().nullable(), + preferredWeather: z.string().optional(), + preferredWeight: z.string().optional(), +}); +export const deleteUser = z.object({ + userId: z.string(), +}); +export const deleteUserForm = z.object({ + confirmText: z.literal('delete'), +}); +export const linkFirebaseAuth = z.object({ + firebaseAuthToken: z.string(), +}); +export const createMongoDBUser = z.object({ + email: z.string().email(), + name: z.string().min(1), + password: passwordValidator, +}); +export const login = z.object({ + email: z.string().email(), + password: passwordValidator, +}); +export const updatePassword = z.object({ + email: emailValidator, + password: passwordValidator, +}); +export const userSettingsSchema = z.object({ + name: z.string().min(1).nonempty(), + email: emailValidator, + username: z.string().nonempty(), + profileImage: z.string().optional(), + preferredWeather: z.union([z.literal('celsius'), z.literal('fahrenheit')]), + preferredWeight: z.union([ + z.literal('lb'), + z.literal('oz'), + z.literal('kg'), + z.literal('g'), + ]), +}); +export const passwordChangeSchema = z + .object({ + oldPassword: passwordValidator, + newPassword: passwordValidator, + confirmPassword: passwordValidator, +}) + .refine((data) => data.newPassword === data.confirmPassword, { + message: 'New password and confirmation must match', + path: ['confirmPassword'], // This will attach the error to `passwordConfirm` field +}); +//# sourceMappingURL=userRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/userRoutesValidator.js.map b/packages/validations/src/validations/userRoutesValidator.js.map new file mode 100644 index 000000000..1f4385a08 --- /dev/null +++ b/packages/validations/src/validations/userRoutesValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"userRoutesValidator.js","sourceRoot":"","sources":["userRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC,EAAE,cAAc,EAAE,mBAAmB,EAAE,CAAC;KAC/C,KAAK,EAAE;KACP,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AAEhD,MAAM,iBAAiB,GAAG,CAAC;KACxB,MAAM,CAAC,EAAE,cAAc,EAAE,sBAAsB,EAAE,CAAC;KAClD,GAAG,CAAC,CAAC,CAAC;KACN,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;IAC1C,OAAO,EAAE,iDAAiD;CAC3D,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAClC,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,iBAAiB;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAA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AC,GAAG,CAAC;KACf,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EAAE,iBAAiB;IAC9B,eAAe,EAAE,iBAAiB;CACnC,CAAC;KACD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,eAAe,EAAE;IAC3D,OAAO,EAAE,0CAA0C;IACnD,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,wDAAwD;CACpF,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/weatherRoutesValidator.d.ts b/packages/validations/src/validations/weatherRoutesValidator.d.ts new file mode 100644 index 000000000..47ac66b67 --- /dev/null +++ b/packages/validations/src/validations/weatherRoutesValidator.d.ts @@ -0,0 +1,21 @@ +import { z } from 'zod'; +export declare const getWeatherWeek: z.ZodObject<{ + lat: z.ZodNumber; + lon: z.ZodNumber; +}, "strip", z.ZodTypeAny, { + lat?: number; + lon?: number; +}, { + lat?: number; + lon?: number; +}>; +export declare const getWeather: z.ZodObject<{ + lat: z.ZodNumber; + lon: z.ZodNumber; +}, "strip", z.ZodTypeAny, { + lat?: number; + lon?: number; +}, { + lat?: number; + lon?: number; +}>; diff --git a/packages/validations/src/validations/weatherRoutesValidator.js b/packages/validations/src/validations/weatherRoutesValidator.js new file mode 100644 index 000000000..975be056b --- /dev/null +++ b/packages/validations/src/validations/weatherRoutesValidator.js @@ -0,0 +1,10 @@ +import { z } from 'zod'; +export const getWeatherWeek = z.object({ + lat: z.number(), + lon: z.number(), +}); +export const getWeather = z.object({ + lat: z.number(), + lon: z.number(), +}); +//# sourceMappingURL=weatherRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/weatherRoutesValidator.js.map b/packages/validations/src/validations/weatherRoutesValidator.js.map new file mode 100644 index 000000000..b2fd13f39 --- /dev/null +++ b/packages/validations/src/validations/weatherRoutesValidator.js.map @@ -0,0 +1 @@ +{"version":3,"file":"weatherRoutesValidator.js","sourceRoot":"","sources":["weatherRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC"} \ No newline at end of file diff --git a/server/src/controllers/item/importFromBucket.ts b/server/src/controllers/item/importFromBucket.ts new file mode 100644 index 000000000..dc68fa629 --- /dev/null +++ b/server/src/controllers/item/importFromBucket.ts @@ -0,0 +1,293 @@ +import { protectedProcedure } from '../../trpc'; +import { addItemGlobalService } from '../../services/item/item.service'; +import * as CryptoJS from 'crypto-js'; +import { parseStringPromise } from 'xml2js'; +import Papa from 'papaparse'; +import { z } from 'zod'; + +interface CSVType { + name: string; + claimed_weight: number; + quantity: number; + claimed_weight_unit: string; + type: string; + ownerId: string; +} + +function getSignatureKey(key, dateStamp, regionName, serviceName) { + const kDate = CryptoJS.HmacSHA256(dateStamp, 'AWS4' + key); + const kRegion = CryptoJS.HmacSHA256(regionName, kDate); + const kService = CryptoJS.HmacSHA256(serviceName, kRegion); + const kSigning = CryptoJS.HmacSHA256('aws4_request', kService); + return kSigning; +} + +function generateAWSHeaders( + url, + method, + service, + region, + accessKey, + secretKey, + sessionToken, +) { + const amzDate = new Date() + .toISOString() + .replace(/[:-]/g, '') + .replace(/\.\d{3}/, ''); + const dateStamp = amzDate.slice(0, 8); + const canonicalUri = new URL(url).pathname; + const canonicalQueryString = ''; + const payloadHash = CryptoJS.SHA256('').toString(CryptoJS.enc.Hex); + const canonicalHeaders = + `host:${new URL(url).hostname}\nx-amz-date:${amzDate}\n` + + (sessionToken ? `x-amz-security-token:${sessionToken}\n` : ''); + const signedHeaders = + 'host;x-amz-date' + (sessionToken ? ';x-amz-security-token' : ''); + const canonicalRequest = `${method}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; + + const algorithm = 'AWS4-HMAC-SHA256'; + const credentialScope = `${dateStamp}/${region}/${service}/aws4_request`; + const stringToSign = `${algorithm}\n${amzDate}\n${credentialScope}\n${CryptoJS.SHA256(canonicalRequest).toString(CryptoJS.enc.Hex)}`; + + const signingKey = getSignatureKey(secretKey, dateStamp, region, service); + const signature = CryptoJS.HmacSHA256(stringToSign, signingKey).toString( + CryptoJS.enc.Hex, + ); + const authorizationHeader = `${algorithm} Credential=${accessKey}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`; + + return { + host: new URL(url).hostname, + 'x-amz-date': amzDate, + 'x-amz-content-sha256': payloadHash, + Authorization: authorizationHeader, + ...(sessionToken && { 'x-amz-security-token': sessionToken }), + }; +} + +export const importFromBucket = async (c) => { + const { directory } = await c.req.query(); + + const endpoint = c.env.BUCKET_ENDPOINT; + const bucket = c.env.BUCKET_NAME; + const method = 'GET'; + const region = c.env.BUCKET_REGION; + const service = c.env.BUCKET_SERVICE; + const accessKeyId = c.env.BUCKET_ACCESS_KEY_ID; + const secretKey = c.env.BUCKET_SECRET_KEY; + const sessionToken = c.env.BUCKET_SESSION_TOKEN; + + // Generate AWS Headers for listing bucket contents + const listHeaders = generateAWSHeaders( + endpoint + '/' + bucket, + method, + service, + region, + accessKeyId, + secretKey, + sessionToken, + ); + + try { + // Fetch data from bucket to list contents + const listResponse = await fetch(`${endpoint}/${bucket}`, { + method, + headers: listHeaders, + }); + const listData = await listResponse.text(); + + // Parse XML response + const parsedListData = await parseStringPromise(listData); + const contents = parsedListData.ListBucketResult.Contents; + + // Extract and log file names + const fileNames = contents + .filter((item) => item.Key[0].startsWith(`${directory}/`)) + .map((item) => item.Key[0]); + + // console.log('File names in backcountry directory:', fileNames); + + // Sort file names to get the latest one + const latestFileName = fileNames.sort().reverse()[0]; + + if (!latestFileName) { + throw new Error('No files found in the backcountry directory'); + } + + // console.log('Latest file name:', latestFileName); + + // Generate AWS Headers for fetching the latest file + const fileHeaders = generateAWSHeaders( + `${endpoint}/${bucket}/${latestFileName}`, + method, + service, + region, + accessKeyId, + secretKey, + sessionToken, + ); + + // Fetch the specific CSV file + const fileResponse = await fetch( + `${endpoint}/${bucket}/${latestFileName}`, + { + method, + headers: fileHeaders, + }, + ); + const fileData = await fileResponse.text(); + + // Check for errors in the file response + if (fileResponse.status !== 200) { + console.error('Error fetching file:', fileData); + return c.json({ error: 'Error fetching file', details: fileData }); + } + + let parsedCSVData = null; + + Papa.parse(fileData, { + header: true, + complete: function (results) { + parsedCSVData = results.data; + }, + error: function (error) { + console.error('Error parsing CSV file:', error); + }, + }); + + return c.json({ message: 'File content logged', data: parsedCSVData }); + } catch (err) { + console.error('Error:', err); + return c.json({ error: 'An error occurred' }); + } +}; + +export function importFromBucketRoute() { + return protectedProcedure + .input(z.object({ directory: z.string(), ownerId: z.string() })) + .mutation(async (opts) => { + const { directory, ownerId } = opts.input; + const { env, executionCtx }: any = opts.ctx; + + const endpoint = env.BUCKET_ENDPOINT; + const bucket = env.BUCKET_NAME; + const method = 'GET'; + const region = env.BUCKET_REGION; + const service = env.BUCKET_SERVICE; + const accessKeyId = env.BUCKET_ACCESS_KEY_ID; + const secretKey = env.BUCKET_SECRET_KEY; + const sessionToken = env.BUCKET_SESSION_TOKEN; + + // Generate AWS Headers for listing bucket contents + const listHeaders = generateAWSHeaders( + `${endpoint}/${bucket}`, + method, + service, + region, + accessKeyId, + secretKey, + sessionToken, + ); + + try { + const listResponse = await fetch(`${endpoint}/${bucket}`, { + method, + headers: listHeaders, + }); + + if (!listResponse.ok) { + throw new Error('Failed to list bucket contents'); + } + + const listData = await listResponse.text(); + + // Parse XML response + const parsedListData = await parseStringPromise(listData); + const contents = parsedListData.ListBucketResult.Contents; + + // Extract and log file names + const fileNames = contents + .filter((item) => item.Key[0].startsWith(`${directory}/`)) + .map((item) => item.Key[0]); + + // Sort file names to get the latest one + const latestFileName = fileNames.sort().reverse()[0]; + + if (!latestFileName) { + throw new Error('No files found in the directory'); + } + + // Generate AWS Headers for fetching the latest file + const fileHeaders = generateAWSHeaders( + `${endpoint}/${bucket}/${latestFileName}`, + method, + service, + region, + accessKeyId, + secretKey, + sessionToken, + ); + + // Fetch the specific CSV file + const fileResponse = await fetch( + `${endpoint}/${bucket}/${latestFileName}`, + { + method, + headers: fileHeaders, + }, + ); + + if (!fileResponse.ok) { + throw new Error('Failed to fetch the latest file'); + } + + const fileData = await fileResponse.text(); + + return new Promise((resolve, reject) => { + Papa.parse(fileData, { + header: true, + complete: async function (results) { + try { + const insertedItems = []; + + for (const [index, item] of results.data.entries()) { + if ( + index === results.data.length - 1 && + Object.values(item).every((value) => value === '') + ) { + continue; + } + + const insertedItem = await addItemGlobalService( + item.name, + item.claimed_weight || 0, + item.quantity || 1, + item.claimed_weight_unit || 'g', + // item.category || 'Essentials', + 'Essentials', + ownerId, + executionCtx, + ); + + insertedItems.push(insertedItem); + } + return resolve(insertedItems); + } catch (error) { + return reject( + new Error(`Failed to add items: ${error.message}`), + ); + } + }, + // Failed to add items: Category must be one of: Food, Water, Essentials + error: function (error) { + console.error('Error parsing CSV file:', error); + reject(error); + }, + }); + }); + } catch (err) { + console.error('Error:', err); + throw new Error(`An error occurred: ${err.message}`); + } + }); +} diff --git a/server/src/controllers/item/index.ts b/server/src/controllers/item/index.ts index 143545048..440562579 100644 --- a/server/src/controllers/item/index.ts +++ b/server/src/controllers/item/index.ts @@ -12,3 +12,4 @@ export * from './editGlobalItemAsDuplicate'; export * from './getItemsGlobally'; export * from './searchItemsByName'; export * from './getSimilarItems'; +export * from './importFromBucket'; diff --git a/server/src/drizzle/methods/Item.ts b/server/src/drizzle/methods/Item.ts index b7218b38d..41d3dd80c 100644 --- a/server/src/drizzle/methods/Item.ts +++ b/server/src/drizzle/methods/Item.ts @@ -16,6 +16,23 @@ export class Item { } } + async createBulk(data: InsertItem[]) { + try { + const insertedItems = []; + for (const itemData of data) { + const item = await DbClient.instance + .insert(ItemTable) + .values(itemData) + .returning() + .get(); + insertedItems.push(item); + } + return insertedItems; + } catch (error) { + throw new Error(`Failed to create items: ${error.message}`); + } + } + async update( id: string, data: Partial, diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index 46247b9fc..c985ddc29 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -14,10 +14,6 @@ import userRoutes from './userRoutes'; import mapPreviewRouter from './mapPreviewRouter'; import healthRoutes from './healthRoutes'; import { Hono } from 'hono'; -import * as CryptoJS from 'crypto-js'; -import { parseStringPromise } from 'xml2js'; -import Papa from 'papaparse'; -import querystring from 'querystring'; const router = new Hono(); @@ -40,199 +36,8 @@ router.route('/health', healthRoutes); const helloRouter = new Hono(); -function generateAWSHeaders( - url, - method, - service, - region, - accessKey, - secretKey, - sessionToken, -) { - const amzDate = new Date() - .toISOString() - .replace(/[:-]/g, '') - .replace(/\.\d{3}/, ''); - const dateStamp = amzDate.slice(0, 8); - const canonicalUri = new URL(url).pathname; - const canonicalQueryString = ''; - const payloadHash = CryptoJS.SHA256('').toString(CryptoJS.enc.Hex); - const canonicalHeaders = - `host:${new URL(url).hostname}\nx-amz-date:${amzDate}\n` + - (sessionToken ? `x-amz-security-token:${sessionToken}\n` : ''); - const signedHeaders = - 'host;x-amz-date' + (sessionToken ? ';x-amz-security-token' : ''); - const canonicalRequest = `${method}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; - - console.log('Canonical Request:', canonicalRequest); - - const algorithm = 'AWS4-HMAC-SHA256'; - const credentialScope = `${dateStamp}/${region}/${service}/aws4_request`; - const stringToSign = `${algorithm}\n${amzDate}\n${credentialScope}\n${CryptoJS.SHA256(canonicalRequest).toString(CryptoJS.enc.Hex)}`; - - console.log('String to Sign:', stringToSign); - - const signingKey = getSignatureKey(secretKey, dateStamp, region, service); - const signature = CryptoJS.HmacSHA256(stringToSign, signingKey).toString( - CryptoJS.enc.Hex, - ); - const authorizationHeader = `${algorithm} Credential=${accessKey}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`; - - return { - host: new URL(url).hostname, - 'x-amz-date': amzDate, - 'x-amz-content-sha256': payloadHash, - Authorization: authorizationHeader, - ...(sessionToken && { 'x-amz-security-token': sessionToken }), - }; -} - -function getSignatureKey(key, dateStamp, regionName, serviceName) { - const kDate = CryptoJS.HmacSHA256(dateStamp, 'AWS4' + key); - const kRegion = CryptoJS.HmacSHA256(regionName, kDate); - const kService = CryptoJS.HmacSHA256(serviceName, kRegion); - const kSigning = CryptoJS.HmacSHA256('aws4_request', kService); - return kSigning; -} - -helloRouter.get('/', async (c) => { - const endpoint = - 'https://a0adf59e1ef3edc3d2bbc2ff272474bc.r2.cloudflarestorage.com'; - const bucket = 'packrat-scrapy-bucket'; - const method = 'GET'; - const region = 'auto'; - const service = 's3'; - const accessKeyId = '1d8b0d85792acd42af61de935c4a1c40'; - const secretKey = - 'e4e9897a4bd4333a6c94846cefcb549bcb386c681ab72dcd00f4f213415a0d5d'; - const sessionToken = ''; - - // Generate AWS Headers for listing bucket contents - const listHeaders = generateAWSHeaders( - endpoint + '/' + bucket, - method, - service, - region, - accessKeyId, - secretKey, - sessionToken, - ); - - try { - // Fetch data from bucket to list contents - const listResponse = await fetch(`${endpoint}/${bucket}`, { - method, - headers: listHeaders, - }); - const listData = await listResponse.text(); - - // Parse XML response - const parsedListData = await parseStringPromise(listData); - const contents = parsedListData.ListBucketResult.Contents; - - // Extract and log file names - const fileNames = contents - .filter((item) => item.Key[0].startsWith('backcountry/')) - .map((item) => item.Key[0]); - - console.log('File names in backcountry directory:', fileNames); - - // Select a specific file to read - const fileName = 'backcountry/backcountry_2024-07-24T08-59-25.csv'; - - // Generate AWS Headers for fetching the specific file - const fileHeaders = generateAWSHeaders( - `${endpoint}/${bucket}/${fileName}`, - method, - service, - region, - accessKeyId, - secretKey, - sessionToken, - ); - - // Fetch the specific CSV file - const fileResponse = await fetch(`${endpoint}/${bucket}/${fileName}`, { - method, - headers: fileHeaders, - }); - const fileData = await fileResponse.text(); - - // Check for errors in the file response - if (fileResponse.status !== 200) { - console.error('Error fetching file:', fileData); - return c.json({ error: 'Error fetching file', details: fileData }); - } - - // Parse the CSV file using PapaParse - Papa.parse(fileData, { - header: true, - complete: function (results) { - console.log('Parsed CSV file contents:', results.data); - }, - error: function (error) { - console.error('Error parsing CSV file:', error); - }, - }); - - return c.json({ message: 'File content logged' }); - } catch (err) { - console.error('Error:', err); - return c.json({ error: 'An error occurred' }); - } -}); - -const testapi = new Hono(); router.route('/hello', helloRouter); -testapi.get('/', async (c) => { - const params = c.req.query(); - console.log('Received data:', params); - - return c.json({ message: 'Data received successfully!', data: params }); -}); - -testapi.get('/test', async (c) => { - try { - const postData = querystring.stringify({ - project: 'PackRat', - spider: 'backcountry', - }); - - const response = await fetch('http://localhost:6800/schedule.json', { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - body: postData, - }); - - const responseData = await response.json(); - - if (responseData.status === 'ok') { - console.log('Scraping initiated', responseData); - return c.json({ - message: 'Scraping initiated successfully!', - response: responseData, - }); - } else { - console.error('Error from Scrapyd:', responseData); - return c.json({ - message: 'Failed to initiate scraping', - error: responseData, - }); - } - } catch (error) { - console.error('Error initiating scraping:', error); - return c.json({ - message: 'Failed to initiate scraping', - error: error.toString(), - }); - } -}); - -router.route('/testapi', testapi); - // Also listen to /api for backwards compatibility router.route('/api/user', userRoutes); router.route('/api/pack', packRoutes); diff --git a/server/src/routes/itemRoutes.ts b/server/src/routes/itemRoutes.ts index bf458dc3a..94253f700 100644 --- a/server/src/routes/itemRoutes.ts +++ b/server/src/routes/itemRoutes.ts @@ -14,6 +14,7 @@ import { importItems, importItemsGlobal, getSimilarItems, + importFromBucket, } from '../controllers/item/index'; import * as validator from '@packrat/validations'; import { tryCatchWrapper } from '../helpers/tryCatchWrapper'; @@ -37,6 +38,13 @@ router.get( tryCatchWrapper(getSimilarItems), ); +router.get( + '/importFromBucket', + authTokenMiddleware, + // zodParser(validator.importFromBucket, 'query'), + tryCatchWrapper(importFromBucket), +); + router.get( '/i/:id', authTokenMiddleware, diff --git a/server/src/routes/trpcRouter.ts b/server/src/routes/trpcRouter.ts index 78c13c45b..c53ceba17 100644 --- a/server/src/routes/trpcRouter.ts +++ b/server/src/routes/trpcRouter.ts @@ -71,6 +71,8 @@ import { getItemsRoute, searchItemsByNameRoute, getSimilarItemsRoute, + importFromBucketRoute, + importFromBucket, } from '../controllers/item'; import { getTrailsRoute } from '../controllers/getTrail'; import { getParksRoute } from '../controllers/getParks'; @@ -161,6 +163,7 @@ export const appRouter = trpcRouter({ editGlobalItemAsDuplicate: editGlobalItemAsDuplicateRoute(), // Not Implemented deleteGlobalItem: deleteGlobalItemRoute(), // Done, getSimilarItems: getSimilarItemsRoute(), + importFromBucket: importFromBucketRoute(), // trails routes getTrails: getTrailsRoute(), // // parks route diff --git a/server/src/services/item/bulkAddGlobalItemService.ts b/server/src/services/item/bulkAddGlobalItemService.ts new file mode 100644 index 000000000..de3f88926 --- /dev/null +++ b/server/src/services/item/bulkAddGlobalItemService.ts @@ -0,0 +1,66 @@ +import { type ExecutionContext } from 'hono'; +import { type InsertItemCategory } from '../../db/schema'; +import { Item } from '../../drizzle/methods/Item'; +import { ItemCategory } from '../../drizzle/methods/itemcategory'; +import { ItemCategory as categories } from '../../utils/itemCategory'; +import { VectorClient } from '../../vector/client'; + +export const bulkAddItemsGlobalService = async ( + items: Array<{ + name: string; + weight: number; + quantity: number; + unit: string; + type: 'Food' | 'Water' | 'Essentials'; + ownerId: string; + }>, + executionCtx: ExecutionContext, +) => { + const itemClass = new Item(); + const itemCategoryClass = new ItemCategory(); + const insertedItems = []; + + for (const itemData of items) { + const { name, weight, quantity, unit, type, ownerId } = itemData; + + let category: InsertItemCategory | null; + if (!categories.includes(type)) { + throw new Error(`Category must be one of: ${categories.join(', ')}`); + } + + category = + (await itemCategoryClass.findItemCategory({ name: type })) || null; + if (!category) { + category = await itemCategoryClass.create({ name: type }); + } + + const newItem = { + name, + weight, + quantity, + unit, + categoryId: category.id, + global: true, + ownerId, + }; + + insertedItems.push(newItem); + } + + const createdItems = await itemClass.createBulk(insertedItems); + + for (const item of createdItems) { + executionCtx.waitUntil( + VectorClient.instance.syncRecord({ + id: item.id, + content: item.name, + namespace: 'items', + metadata: { + isPublic: item.global, + }, + }), + ); + } + + return createdItems; +}; diff --git a/server/src/services/item/item.service.ts b/server/src/services/item/item.service.ts index 1ca7d6af7..31924e039 100644 --- a/server/src/services/item/item.service.ts +++ b/server/src/services/item/item.service.ts @@ -9,3 +9,4 @@ export * from './getItemByIdService'; export * from './getItemsGloballyService'; export * from './searchItemsByNameService'; export * from './getItemsService'; +export * from './bulkAddGlobalItemService'; diff --git a/server/vitest.config.d.ts b/server/vitest.config.d.ts index 06c214f2f..85bcff909 100644 --- a/server/vitest.config.d.ts +++ b/server/vitest.config.d.ts @@ -1,4 +1,2 @@ -declare const _default: import('@cloudflare/vitest-pool-workers/config').AnyConfigExport< - import('@cloudflare/vitest-pool-workers/config').WorkersProjectConfigExport ->; +declare const _default: import("@cloudflare/vitest-pool-workers/config").AnyConfigExport; export default _default; diff --git a/yarn.lock b/yarn.lock index 5e236ff3a..58b794963 100644 --- a/yarn.lock +++ b/yarn.lock @@ -117,6 +117,16 @@ __metadata: languageName: node linkType: hard +"@babel/code-frame@npm:^7.24.7": + version: 7.24.7 + resolution: "@babel/code-frame@npm:7.24.7" + dependencies: + "@babel/highlight": "npm:^7.24.7" + picocolors: "npm:^1.0.0" + checksum: 10/4812e94885ba7e3213d49583a155fdffb05292330f0a9b2c41b49288da70cf3c746a3fda0bf1074041a6d741c33f8d7be24be5e96f41ef77395eeddc5c9ff624 + languageName: node + linkType: hard + "@babel/compat-data@npm:^7.20.5, @babel/compat-data@npm:^7.22.6, @babel/compat-data@npm:^7.23.5, @babel/compat-data@npm:^7.24.4": version: 7.24.4 resolution: "@babel/compat-data@npm:7.24.4" @@ -159,6 +169,18 @@ __metadata: languageName: node linkType: hard +"@babel/generator@npm:^7.25.0": + version: 7.25.0 + resolution: "@babel/generator@npm:7.25.0" + dependencies: + "@babel/types": "npm:^7.25.0" + "@jridgewell/gen-mapping": "npm:^0.3.5" + "@jridgewell/trace-mapping": "npm:^0.3.25" + jsesc: "npm:^2.5.1" + checksum: 10/de3ce2ae7aa0c9585260556ca5a81ce2ce6b8269e3260d7bb4e47a74661af715184ca6343e9906c22e4dd3eed5ce39977dfaf6cded4d2d8968fa096c7cf66697 + languageName: node + linkType: hard + "@babel/helper-annotate-as-pure@npm:^7.18.6, @babel/helper-annotate-as-pure@npm:^7.22.5": version: 7.22.5 resolution: "@babel/helper-annotate-as-pure@npm:7.22.5" @@ -272,6 +294,16 @@ __metadata: languageName: node linkType: hard +"@babel/helper-module-imports@npm:^7.16.7": + version: 7.24.7 + resolution: "@babel/helper-module-imports@npm:7.24.7" + dependencies: + "@babel/traverse": "npm:^7.24.7" + "@babel/types": "npm:^7.24.7" + checksum: 10/df8bfb2bb18413aa151ecd63b7d5deb0eec102f924f9de6bc08022ced7ed8ca7fed914562d2f6fa5b59b74a5d6e255dc35612b2bc3b8abf361e13f61b3704770 + languageName: node + linkType: hard + "@babel/helper-module-imports@npm:^7.22.15, @babel/helper-module-imports@npm:^7.24.1, @babel/helper-module-imports@npm:^7.24.3": version: 7.24.3 resolution: "@babel/helper-module-imports@npm:7.24.3" @@ -372,6 +404,13 @@ __metadata: languageName: node linkType: hard +"@babel/helper-string-parser@npm:^7.24.8": + version: 7.24.8 + resolution: "@babel/helper-string-parser@npm:7.24.8" + checksum: 10/6d1bf8f27dd725ce02bdc6dffca3c95fb9ab8a06adc2edbd9c1c9d68500274230d1a609025833ed81981eff560045b6b38f7b4c6fb1ab19fc90e5004e3932535 + languageName: node + linkType: hard + "@babel/helper-validator-identifier@npm:^7.22.20, @babel/helper-validator-identifier@npm:^7.24.5": version: 7.24.5 resolution: "@babel/helper-validator-identifier@npm:7.24.5" @@ -379,6 +418,13 @@ __metadata: languageName: node linkType: hard +"@babel/helper-validator-identifier@npm:^7.24.7": + version: 7.24.7 + resolution: "@babel/helper-validator-identifier@npm:7.24.7" + checksum: 10/86875063f57361471b531dbc2ea10bbf5406e12b06d249b03827d361db4cad2388c6f00936bcd9dc86479f7e2c69ea21412c2228d4b3672588b754b70a449d4b + languageName: node + linkType: hard + "@babel/helper-validator-option@npm:^7.23.5": version: 7.23.5 resolution: "@babel/helper-validator-option@npm:7.23.5" @@ -420,6 +466,18 @@ __metadata: languageName: node linkType: hard +"@babel/highlight@npm:^7.24.7": + version: 7.24.7 + resolution: "@babel/highlight@npm:7.24.7" + dependencies: + "@babel/helper-validator-identifier": "npm:^7.24.7" + chalk: "npm:^2.4.2" + js-tokens: "npm:^4.0.0" + picocolors: "npm:^1.0.0" + checksum: 10/69b73f38cdd4f881b09b939a711e76646da34f4834f4ce141d7a49a6bb1926eab1c594148970a8aa9360398dff800f63aade4e81fafdd7c8d8a8489ea93bfec1 + languageName: node + linkType: hard + "@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.1.6, @babel/parser@npm:^7.13.16, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.0, @babel/parser@npm:^7.20.15, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.23.3, @babel/parser@npm:^7.23.9, @babel/parser@npm:^7.24.0, @babel/parser@npm:^7.24.5": version: 7.24.5 resolution: "@babel/parser@npm:7.24.5" @@ -429,6 +487,17 @@ __metadata: languageName: node linkType: hard +"@babel/parser@npm:^7.25.0, @babel/parser@npm:^7.25.3": + version: 7.25.3 + resolution: "@babel/parser@npm:7.25.3" + dependencies: + "@babel/types": "npm:^7.25.2" + bin: + parser: ./bin/babel-parser.js + checksum: 10/7bd57e89110bdc9cffe0ef2f2286f1cfb9bbb3aa1d9208c287e0bf6a1eb4cfe6ab33958876ebc59aafcbe3e2381c4449240fc7cc2ff32b79bc9db89cd52fc779 + languageName: node + linkType: hard + "@babel/plugin-bugfix-firefox-class-in-computed-class-key@npm:^7.24.5": version: 7.24.5 resolution: "@babel/plugin-bugfix-firefox-class-in-computed-class-key@npm:7.24.5" @@ -1774,6 +1843,15 @@ __metadata: languageName: node linkType: hard +"@babel/runtime@npm:^7.12.0, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.5.5": + version: 7.25.0 + resolution: "@babel/runtime@npm:7.25.0" + dependencies: + regenerator-runtime: "npm:^0.14.0" + checksum: 10/6870e9e0e9125075b3aeba49a266f442b10820bfc693019eb6c1785c5a0edbe927e98b8238662cdcdba17842107c040386c3b69f39a0a3b217f9d00ffe685b27 + languageName: node + linkType: hard + "@babel/runtime@npm:^7.12.5": version: 7.24.7 resolution: "@babel/runtime@npm:7.24.7" @@ -1794,6 +1872,17 @@ __metadata: languageName: node linkType: hard +"@babel/template@npm:^7.25.0": + version: 7.25.0 + resolution: "@babel/template@npm:7.25.0" + dependencies: + "@babel/code-frame": "npm:^7.24.7" + "@babel/parser": "npm:^7.25.0" + "@babel/types": "npm:^7.25.0" + checksum: 10/07ebecf6db8b28244b7397628e09c99e7a317b959b926d90455c7253c88df3677a5a32d1501d9749fe292a263ff51a4b6b5385bcabd5dadd3a48036f4d4949e0 + languageName: node + linkType: hard + "@babel/traverse@npm:^7.1.6, @babel/traverse@npm:^7.20.0, @babel/traverse@npm:^7.23.3, @babel/traverse@npm:^7.24.1, @babel/traverse@npm:^7.24.5": version: 7.24.5 resolution: "@babel/traverse@npm:7.24.5" @@ -1812,6 +1901,21 @@ __metadata: languageName: node linkType: hard +"@babel/traverse@npm:^7.24.7": + version: 7.25.3 + resolution: "@babel/traverse@npm:7.25.3" + dependencies: + "@babel/code-frame": "npm:^7.24.7" + "@babel/generator": "npm:^7.25.0" + "@babel/parser": "npm:^7.25.3" + "@babel/template": "npm:^7.25.0" + "@babel/types": "npm:^7.25.2" + debug: "npm:^4.3.1" + globals: "npm:^11.1.0" + checksum: 10/fba34f323e17fa83372fc290bc12413a50e2f780a86c7d8b1875c594b6be2857867804de5d52ab10a78a9cae29e1b09ea15d85ad63671ce97d79c40650282bb9 + languageName: node + linkType: hard + "@babel/types@npm:^7.0.0, @babel/types@npm:^7.1.6, @babel/types@npm:^7.20.0, @babel/types@npm:^7.20.7, @babel/types@npm:^7.21.3, @babel/types@npm:^7.22.15, @babel/types@npm:^7.22.5, @babel/types@npm:^7.23.0, @babel/types@npm:^7.23.3, @babel/types@npm:^7.23.4, @babel/types@npm:^7.24.0, @babel/types@npm:^7.24.5, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3": version: 7.24.5 resolution: "@babel/types@npm:7.24.5" @@ -1823,6 +1927,17 @@ __metadata: languageName: node linkType: hard +"@babel/types@npm:^7.24.7, @babel/types@npm:^7.25.0, @babel/types@npm:^7.25.2": + version: 7.25.2 + resolution: "@babel/types@npm:7.25.2" + dependencies: + "@babel/helper-string-parser": "npm:^7.24.8" + "@babel/helper-validator-identifier": "npm:^7.24.7" + to-fast-properties: "npm:^2.0.0" + checksum: 10/ccf5399db1dcd6dd87b84a6f7bc8dd241e04a326f4f038c973c26ccb69cd360c8f2276603f584c58fd94da95229313060b27baceb0d9b18a435742d3f616afd1 + languageName: node + linkType: hard + "@bcoe/v8-coverage@npm:^0.2.3": version: 0.2.3 resolution: "@bcoe/v8-coverage@npm:0.2.3" @@ -2088,6 +2203,45 @@ __metadata: languageName: node linkType: hard +"@emotion/babel-plugin@npm:^11.12.0": + version: 11.12.0 + resolution: "@emotion/babel-plugin@npm:11.12.0" + dependencies: + "@babel/helper-module-imports": "npm:^7.16.7" + "@babel/runtime": "npm:^7.18.3" + "@emotion/hash": "npm:^0.9.2" + "@emotion/memoize": "npm:^0.9.0" + "@emotion/serialize": "npm:^1.2.0" + babel-plugin-macros: "npm:^3.1.0" + convert-source-map: "npm:^1.5.0" + escape-string-regexp: "npm:^4.0.0" + find-root: "npm:^1.1.0" + source-map: "npm:^0.5.7" + stylis: "npm:4.2.0" + checksum: 10/fe6f4522ea2b61ef4214dd0b0f3778aad9c18434b47e50ae5091af226526bf305455c313065826a090682520c9462c151d4df62ec128f14671d3125afc05b148 + languageName: node + linkType: hard + +"@emotion/cache@npm:^11.13.0, @emotion/cache@npm:^11.4.0": + version: 11.13.1 + resolution: "@emotion/cache@npm:11.13.1" + dependencies: + "@emotion/memoize": "npm:^0.9.0" + "@emotion/sheet": "npm:^1.4.0" + "@emotion/utils": "npm:^1.4.0" + "@emotion/weak-memoize": "npm:^0.4.0" + stylis: "npm:4.2.0" + checksum: 10/090c8ad2e5b23f1b3a95e94f1f0554a40ed1dcd844c9d31629a68ff824eff40f32d1362f67aefa440ee0aabd5a8cabcc76870fd6d77144d3ff251bdcdf1420b9 + languageName: node + linkType: hard + +"@emotion/hash@npm:^0.9.2": + version: 0.9.2 + resolution: "@emotion/hash@npm:0.9.2" + checksum: 10/379bde2830ccb0328c2617ec009642321c0e009a46aa383dfbe75b679c6aea977ca698c832d225a893901f29d7b3eef0e38cf341f560f6b2b56f1ff23c172387 + languageName: node + linkType: hard + "@emotion/is-prop-valid@npm:^0.8.2": version: 0.8.8 resolution: "@emotion/is-prop-valid@npm:0.8.8" @@ -2104,6 +2258,84 @@ __metadata: languageName: node linkType: hard +"@emotion/memoize@npm:^0.9.0": + version: 0.9.0 + resolution: "@emotion/memoize@npm:0.9.0" + checksum: 10/038132359397348e378c593a773b1148cd0cf0a2285ffd067a0f63447b945f5278860d9de718f906a74c7c940ba1783ac2ca18f1c06a307b01cc0e3944e783b1 + languageName: node + linkType: hard + +"@emotion/react@npm:^11.8.1": + version: 11.13.0 + resolution: "@emotion/react@npm:11.13.0" + dependencies: + "@babel/runtime": "npm:^7.18.3" + "@emotion/babel-plugin": "npm:^11.12.0" + "@emotion/cache": "npm:^11.13.0" + "@emotion/serialize": "npm:^1.3.0" + "@emotion/use-insertion-effect-with-fallbacks": "npm:^1.1.0" + "@emotion/utils": "npm:^1.4.0" + "@emotion/weak-memoize": "npm:^0.4.0" + hoist-non-react-statics: "npm:^3.3.1" + peerDependencies: + react: ">=16.8.0" + peerDependenciesMeta: + "@types/react": + optional: true + checksum: 10/3dd2b3ffac51f0fa67ef3cb85d4064fd7ddc1212b587e3b328a1eade47024690175518d63c4cbabf28afa07e29187136b26d646e395158f6574fa6321a0b68f9 + languageName: node + linkType: hard + +"@emotion/serialize@npm:^1.2.0, @emotion/serialize@npm:^1.3.0": + version: 1.3.0 + resolution: "@emotion/serialize@npm:1.3.0" + dependencies: + "@emotion/hash": "npm:^0.9.2" + "@emotion/memoize": "npm:^0.9.0" + "@emotion/unitless": "npm:^0.9.0" + "@emotion/utils": "npm:^1.4.0" + csstype: "npm:^3.0.2" + checksum: 10/3ab17aa0dabdc77d5d573ef07df63e91e778c0637f4b7f690fde46ab0007496c8dfbf32d2836d3b22ac2ba2d8c58570da51092ba7ff068d4d790147de2352465 + languageName: node + linkType: hard + +"@emotion/sheet@npm:^1.4.0": + version: 1.4.0 + resolution: "@emotion/sheet@npm:1.4.0" + checksum: 10/8ac6e9bf6b373a648f26ae7f1c24041038524f4c72f436f4f8c4761c665e58880c3229d8d89b1f7a4815dd8e5b49634d03e60187cb6f93097d7f7c1859e869d5 + languageName: node + linkType: hard + +"@emotion/unitless@npm:^0.9.0": + version: 0.9.0 + resolution: "@emotion/unitless@npm:0.9.0" + checksum: 10/242754aa2f7368b5c2a5dbe61bf0a2bb0bfb4de091fe2388282f8c014c0796d0ca166b1639cf4f5f0e57e59258b622e7946a2e976ed5a56e06a5a306ca25adca + languageName: node + linkType: hard + +"@emotion/use-insertion-effect-with-fallbacks@npm:^1.1.0": + version: 1.1.0 + resolution: "@emotion/use-insertion-effect-with-fallbacks@npm:1.1.0" + peerDependencies: + react: ">=16.8.0" + checksum: 10/33a10f44a873b3f5ccd2a1a3d13c2f34ed628f5a2be1ccf28540a86535a14d3a930afcbef209d48346a22ec60ff48f43c86ee9c846b9480d23a55a17145da66c + languageName: node + linkType: hard + +"@emotion/utils@npm:^1.4.0": + version: 1.4.0 + resolution: "@emotion/utils@npm:1.4.0" + checksum: 10/e4cdb51819db01fec21c3e35a1391900c9e7f3ac1e7ecb419c8e408464830cd7ef6e1a116381cbfe3fb1039406fb7ed35f16a1575d502c92bc9f81bc13a3ee5a + languageName: node + linkType: hard + +"@emotion/weak-memoize@npm:^0.4.0": + version: 0.4.0 + resolution: "@emotion/weak-memoize@npm:0.4.0" + checksum: 10/db5da0e89bd752c78b6bd65a1e56231f0abebe2f71c0bd8fc47dff96408f7065b02e214080f99924f6a3bfe7ee15afc48dad999d76df86b39b16e513f7a94f52 + languageName: node + linkType: hard + "@envelop/core@npm:^4.0.0": version: 4.0.3 resolution: "@envelop/core@npm:4.0.3" @@ -3898,6 +4130,15 @@ __metadata: languageName: node linkType: hard +"@floating-ui/core@npm:^1.6.0": + version: 1.6.5 + resolution: "@floating-ui/core@npm:1.6.5" + dependencies: + "@floating-ui/utils": "npm:^0.2.5" + checksum: 10/946eccfc16d0eea2bb62bd8cee12211a1d2614968d541966ecd9b6d40f66f097391020ce109c8503676c14ec67f304414e5fecff324ac8950121574010c009e9 + languageName: node + linkType: hard + "@floating-ui/dom@npm:^1.0.0": version: 1.6.5 resolution: "@floating-ui/dom@npm:1.6.5" @@ -3908,6 +4149,16 @@ __metadata: languageName: node linkType: hard +"@floating-ui/dom@npm:^1.0.1": + version: 1.6.8 + resolution: "@floating-ui/dom@npm:1.6.8" + dependencies: + "@floating-ui/core": "npm:^1.6.0" + "@floating-ui/utils": "npm:^0.2.5" + checksum: 10/ebfc92b7a08addc1952d497174a197db80278d3701da7d7dedd3e1533daa80b12b7de02c19408de3f951195a3247f2f5c3cc10807071147e3193bbef469e90a5 + languageName: node + linkType: hard + "@floating-ui/react-dom@npm:^2.0.0, @floating-ui/react-dom@npm:^2.0.6": version: 2.0.9 resolution: "@floating-ui/react-dom@npm:2.0.9" @@ -3953,6 +4204,13 @@ __metadata: languageName: node linkType: hard +"@floating-ui/utils@npm:^0.2.5": + version: 0.2.5 + resolution: "@floating-ui/utils@npm:0.2.5" + checksum: 10/08df715c2a3bfa9d757347df0b38c89a3bfa92b0a32ff67d3d713960c2e72c202e22a2b220aacadbde5451ac2bd4c10411a73a8ed3707ded792f0182592eb01f + languageName: node + linkType: hard + "@formatjs/ecma402-abstract@npm:1.18.2": version: 1.18.2 resolution: "@formatjs/ecma402-abstract@npm:1.18.2" @@ -7077,6 +7335,16 @@ __metadata: languageName: node linkType: hard +"@react-native-picker/picker@npm:^2.7.7": + version: 2.7.7 + resolution: "@react-native-picker/picker@npm:2.7.7" + peerDependencies: + react: "*" + react-native: "*" + checksum: 10/96f528194b337e95e27780e9b88875df62b81d0ec1bc2a9992de946b348ccfc9bca86d5816ce2a2bb698b376dd2aee7202fd606a00dc3b2e19e1482516305f61 + languageName: node + linkType: hard + "@react-native/assets-registry@npm:0.74.81": version: 0.74.81 resolution: "@react-native/assets-registry@npm:0.74.81" @@ -11233,6 +11501,13 @@ __metadata: languageName: node linkType: hard +"@types/parse-json@npm:^4.0.0": + version: 4.0.2 + resolution: "@types/parse-json@npm:4.0.2" + checksum: 10/5bf62eec37c332ad10059252fc0dab7e7da730764869c980b0714777ad3d065e490627be9f40fc52f238ffa3ac4199b19de4127196910576c2fe34dd47c7a470 + languageName: node + linkType: hard + "@types/prop-types@npm:*": version: 15.7.12 resolution: "@types/prop-types@npm:15.7.12" @@ -11301,6 +11576,15 @@ __metadata: languageName: node linkType: hard +"@types/react-transition-group@npm:^4.4.0": + version: 4.4.10 + resolution: "@types/react-transition-group@npm:4.4.10" + dependencies: + "@types/react": "npm:*" + checksum: 10/b429f3bd54d9aea6c0395943ce2dda6b76fb458e902365bd91fd99bf72064fb5d59e2b74e78d10f2871908501d350da63e230d81bda2b616c967cab8dc51bd16 + languageName: node + linkType: hard + "@types/react@npm:*": version: 18.3.1 resolution: "@types/react@npm:18.3.1" @@ -12707,6 +12991,7 @@ __metadata: "@react-native-community/geolocation": "npm:^3.0.6" "@react-native-community/netinfo": "npm:11.1.0" "@react-native-google-signin/google-signin": "npm:^9.0.2" + "@react-native-picker/picker": "npm:^2.7.7" "@react-navigation/drawer": "npm:^6.6.6" "@react-navigation/native": "npm:^6.1.6" "@react-navigation/native-stack": "npm:^6.9.12" @@ -12809,6 +13094,7 @@ __metadata: react-native-google-places-autocomplete: "npm:^2.5.1" react-native-paper: "npm:^5.10.6" react-native-paper-dates: "npm:^0.18.12" + react-native-picker-select: "npm:^9.2.0" react-native-reanimated: "npm:~3.6.2" react-native-safe-area-context: "npm:4.8.2" react-native-screens: "npm:~3.29.0" @@ -12820,6 +13106,7 @@ __metadata: react-native-webview: "npm:13.6.4" react-redux: "npm:^9.0.4" react-responsive: "npm:^9.0.2" + react-select: "npm:^5.8.0" redux-persist: "npm:^6.0.0" serve: "npm:^14.2.0" server: "npm:*" @@ -13550,6 +13837,17 @@ __metadata: languageName: node linkType: hard +"babel-plugin-macros@npm:^3.1.0": + version: 3.1.0 + resolution: "babel-plugin-macros@npm:3.1.0" + dependencies: + "@babel/runtime": "npm:^7.12.5" + cosmiconfig: "npm:^7.0.0" + resolve: "npm:^1.19.0" + checksum: 10/30be6ca45e9a124c58ca00af9a0753e5410ec0b79a737714fc4722bbbeb693e55d9258f05c437145ef4a867c2d1603e06a1c292d66c243ce1227458c8ea2ca8c + languageName: node + linkType: hard + "babel-plugin-module-resolver@npm:^5.0.0": version: 5.0.2 resolution: "babel-plugin-module-resolver@npm:5.0.2" @@ -15966,6 +16264,13 @@ __metadata: languageName: node linkType: hard +"convert-source-map@npm:^1.5.0": + version: 1.9.0 + resolution: "convert-source-map@npm:1.9.0" + checksum: 10/dc55a1f28ddd0e9485ef13565f8f756b342f9a46c4ae18b843fe3c30c675d058d6a4823eff86d472f187b176f0adf51ea7b69ea38be34be4a63cbbf91b0593c8 + languageName: node + linkType: hard + "convert-source-map@npm:^2.0.0": version: 2.0.0 resolution: "convert-source-map@npm:2.0.0" @@ -16099,6 +16404,19 @@ __metadata: languageName: node linkType: hard +"cosmiconfig@npm:^7.0.0": + version: 7.1.0 + resolution: "cosmiconfig@npm:7.1.0" + dependencies: + "@types/parse-json": "npm:^4.0.0" + import-fresh: "npm:^3.2.1" + parse-json: "npm:^5.0.0" + path-type: "npm:^4.0.0" + yaml: "npm:^1.10.0" + checksum: 10/03600bb3870c80ed151b7b706b99a1f6d78df8f4bdad9c95485072ea13358ef294b13dd99f9e7bf4cc0b43bcd3599d40df7e648750d21c2f6817ca2cd687e071 + languageName: node + linkType: hard + "create-ecdh@npm:^4.0.0": version: 4.0.4 resolution: "create-ecdh@npm:4.0.4" @@ -17061,7 +17379,7 @@ __metadata: languageName: node linkType: hard -"dom-helpers@npm:^5.0.0": +"dom-helpers@npm:^5.0.0, dom-helpers@npm:^5.0.1": version: 5.2.1 resolution: "dom-helpers@npm:5.2.1" dependencies: @@ -25380,6 +25698,13 @@ __metadata: languageName: node linkType: hard +"lodash.isobject@npm:^3.0.2": + version: 3.0.2 + resolution: "lodash.isobject@npm:3.0.2" + checksum: 10/6c1667cbc4494d0a13a3617a4b23278d6d02dac520311f2bbb43f16f2cf71d2e6eb9dec8057315b77459df4890c756a256a087d3f4baa44a79ab5d6c968b060e + languageName: node + linkType: hard + "lodash.isplainobject@npm:^4.0.6": version: 4.0.6 resolution: "lodash.isplainobject@npm:4.0.6" @@ -28748,7 +29073,7 @@ __metadata: languageName: node linkType: hard -"parse-json@npm:^5.2.0": +"parse-json@npm:^5.0.0, parse-json@npm:^5.2.0": version: 5.2.0 resolution: "parse-json@npm:5.2.0" dependencies: @@ -29961,7 +30286,7 @@ __metadata: languageName: node linkType: hard -"prop-types@npm:15.8.1, prop-types@npm:^15.5.10, prop-types@npm:^15.6.1, prop-types@npm:^15.7.2, prop-types@npm:^15.8.1": +"prop-types@npm:15.8.1, prop-types@npm:^15.5.10, prop-types@npm:^15.6.0, prop-types@npm:^15.6.1, prop-types@npm:^15.6.2, prop-types@npm:^15.7.2, prop-types@npm:^15.8.1": version: 15.8.1 resolution: "prop-types@npm:15.8.1" dependencies: @@ -30721,6 +31046,18 @@ __metadata: languageName: node linkType: hard +"react-native-picker-select@npm:^9.2.0": + version: 9.2.0 + resolution: "react-native-picker-select@npm:9.2.0" + dependencies: + lodash.isequal: "npm:^4.5.0" + lodash.isobject: "npm:^3.0.2" + peerDependencies: + "@react-native-picker/picker": ^2.4.0 + checksum: 10/90d2997b2a249f7e09f4b534e2bff149b1dba0ae86a79e50f50580959531d2e200e2bb27975c80fad1fd28efb331fac13d9508519de2d12daceab8a223b00efa + languageName: node + linkType: hard + "react-native-ratings@npm:8.0.4": version: 8.0.4 resolution: "react-native-ratings@npm:8.0.4" @@ -31077,6 +31414,26 @@ __metadata: languageName: node linkType: hard +"react-select@npm:^5.8.0": + version: 5.8.0 + resolution: "react-select@npm:5.8.0" + dependencies: + "@babel/runtime": "npm:^7.12.0" + "@emotion/cache": "npm:^11.4.0" + "@emotion/react": "npm:^11.8.1" + "@floating-ui/dom": "npm:^1.0.1" + "@types/react-transition-group": "npm:^4.4.0" + memoize-one: "npm:^6.0.0" + prop-types: "npm:^15.6.0" + react-transition-group: "npm:^4.3.0" + use-isomorphic-layout-effect: "npm:^1.1.2" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + checksum: 10/04d3639ea1872a9e4d9080ece1947432fc595403c0a740f671a1b7f7dd2639288cb133ec7a2b1ac20fad69fd303d696c2f924763405e0e1d93b847e54df9e966 + languageName: node + linkType: hard + "react-shallow-renderer@npm:^16.15.0": version: 16.15.0 resolution: "react-shallow-renderer@npm:16.15.0" @@ -31116,6 +31473,21 @@ __metadata: languageName: node linkType: hard +"react-transition-group@npm:^4.3.0": + version: 4.4.5 + resolution: "react-transition-group@npm:4.4.5" + dependencies: + "@babel/runtime": "npm:^7.5.5" + dom-helpers: "npm:^5.0.1" + loose-envify: "npm:^1.4.0" + prop-types: "npm:^15.6.2" + peerDependencies: + react: ">=16.6.0" + react-dom: ">=16.6.0" + checksum: 10/ca32d3fd2168c976c5d90a317f25d5f5cd723608b415fb3b9006f9d793c8965c619562d0884503a3e44e4b06efbca4fdd1520f30e58ca3e00a0890e637d55419 + languageName: node + linkType: hard + "react@npm:18.2.0": version: 18.2.0 resolution: "react@npm:18.2.0" @@ -31675,7 +32047,7 @@ __metadata: languageName: node linkType: hard -"resolve@npm:^1.10.0, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.20.0, resolve@npm:^1.22.2, resolve@npm:^1.22.4, resolve@npm:^1.22.8": +"resolve@npm:^1.10.0, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.19.0, resolve@npm:^1.20.0, resolve@npm:^1.22.2, resolve@npm:^1.22.4, resolve@npm:^1.22.8": version: 1.22.8 resolution: "resolve@npm:1.22.8" dependencies: @@ -31710,7 +32082,7 @@ __metadata: languageName: node linkType: hard -"resolve@patch:resolve@npm%3A^1.10.0#optional!builtin, resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.17.0#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin, resolve@patch:resolve@npm%3A^1.22.8#optional!builtin": +"resolve@patch:resolve@npm%3A^1.10.0#optional!builtin, resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.17.0#optional!builtin, resolve@patch:resolve@npm%3A^1.19.0#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin, resolve@patch:resolve@npm%3A^1.22.8#optional!builtin": version: 1.22.8 resolution: "resolve@patch:resolve@npm%3A1.22.8#optional!builtin::version=1.22.8&hash=c3c19d" dependencies: @@ -33074,7 +33446,7 @@ __metadata: languageName: node linkType: hard -"source-map@npm:^0.5.6": +"source-map@npm:^0.5.6, source-map@npm:^0.5.7": version: 0.5.7 resolution: "source-map@npm:0.5.7" checksum: 10/9b4ac749ec5b5831cad1f8cc4c19c4298ebc7474b24a0acf293e2f040f03f8eeccb3d01f12aa0f90cf46d555c887e03912b83a042c627f419bda5152d89c5269 @@ -33771,6 +34143,13 @@ __metadata: languageName: node linkType: hard +"stylis@npm:4.2.0": + version: 4.2.0 + resolution: "stylis@npm:4.2.0" + checksum: 10/58359185275ef1f39c339ae94e598168aa6bb789f6cf0d52e726c1e7087a94e9c17f0385a28d34483dec1ffc2c75670ec714dc5603d99c3124ec83bc2b0a0f42 + languageName: node + linkType: hard + "sucrase@npm:3.34.0": version: 3.34.0 resolution: "sucrase@npm:3.34.0" @@ -35549,6 +35928,18 @@ __metadata: languageName: node linkType: hard +"use-isomorphic-layout-effect@npm:^1.1.2": + version: 1.1.2 + resolution: "use-isomorphic-layout-effect@npm:1.1.2" + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 + peerDependenciesMeta: + "@types/react": + optional: true + checksum: 10/fd3787ed19f6cfbf70e2c5822d01bebbf96b00968195840d5ad61082b8e6ca7a8e2e46270c4096537d18a38ea57f4e4e9668cce5eec36fa4697ddba2ef1203fd + languageName: node + linkType: hard + "use-latest-callback@npm:^0.1.5, use-latest-callback@npm:^0.1.9": version: 0.1.9 resolution: "use-latest-callback@npm:0.1.9" From 47666fa5059aff78ac605debeb003fc077b172c9 Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Mon, 5 Aug 2024 16:12:21 +0300 Subject: [PATCH 03/10] import from bucket done --- packages/app/components/item/ImportForm.tsx | 65 ++++++++++++----- .../app/components/item/ImportItemGlobal.tsx | 2 +- .../app/hooks/items/useImportFromBucket.ts | 70 +++++++++++-------- packages/app/hooks/items/useImportItem.ts | 6 +- packages/app/hooks/packs/useImportPackItem.ts | 8 --- .../src/controllers/item/importFromBucket.ts | 31 ++++---- server/src/routes/index.ts | 51 +++++++++++++- .../services/item/bulkAddGlobalItemService.ts | 34 ++++----- 8 files changed, 171 insertions(+), 96 deletions(-) diff --git a/packages/app/components/item/ImportForm.tsx b/packages/app/components/item/ImportForm.tsx index 71aaed775..c1f9cf970 100644 --- a/packages/app/components/item/ImportForm.tsx +++ b/packages/app/components/item/ImportForm.tsx @@ -1,11 +1,6 @@ -import React, { useState, FC } from 'react'; +import React, { useState, useEffect, FC } from 'react'; import { View, Platform } from 'react-native'; -import { - DropdownComponent, - RButton, - RText, - CascadedDropdownComponent, -} from '@packrat/ui'; +import { RButton, RText, CascadedDropdownComponent } from '@packrat/ui'; import useTheme from '../../hooks/useTheme'; import * as DocumentPicker from 'expo-document-picker'; import { useImportPackItem } from 'app/hooks/packs/useImportPackItem'; @@ -33,8 +28,7 @@ interface SelectedType { value: string; } -const data = [ - { label: 'CSV', value: '.csv', key: '.csv' }, +const options = [ { label: 'Rei', value: 'rei', key: 'Rei' }, { label: 'Sierra', value: 'sierra', key: 'Sierra' }, { label: 'Cabelas', value: 'cabelas', key: 'Cabelas' }, @@ -42,6 +36,8 @@ const data = [ { label: 'Backcountry', value: 'backcountry', key: 'Backcountry' }, ]; +const csvOption = [{ label: 'CSV', value: '.csv', key: '.csv' }]; + export const ImportForm: FC = ({ packId, ownerId, @@ -59,12 +55,36 @@ export const ImportForm: FC = ({ value: '.csv', }); + const [buttonText, setButtonText] = useState('Import Item'); + const [isImporting, setIsImporting] = useState(false); + + useEffect(() => { + let interval: NodeJS.Timeout; + if (isImporting) { + interval = setInterval(() => { + setButtonText((prev) => { + if (prev.endsWith('...')) { + return 'Importing'; + } else { + return prev + '.'; + } + }); + }, 500); + } else { + setButtonText('Import Item'); + clearInterval(interval); + } + + return () => clearInterval(interval); + }, [isImporting]); + const handleSelectChange = (selectedValue: string) => { const newValue = data.find((item) => item.value === selectedValue); if (newValue) setSelectedType(newValue); }; const handleItemImport = async () => { + setIsImporting(true); try { if (selectedType.value === '.csv') { const res = await DocumentPicker.getDocumentAsync({ @@ -72,6 +92,7 @@ export const ImportForm: FC = ({ }); if (res.canceled) { + setIsImporting(false); return; } @@ -91,17 +112,25 @@ export const ImportForm: FC = ({ } if (currentpage === 'items') { - handleImportNewItems({ content: fileContent, ownerId }); + handleImportNewItems({ content: fileContent, ownerId }, () => { + setIsImporting(false); + closeModalHandler(); + }); } else { importPackItem({ content: fileContent, packId, ownerId }); } } else { - handleImportFromBucket({ directory: selectedType.value, ownerId }); + handleImportFromBucket( + { directory: selectedType.value, ownerId }, + () => { + setIsImporting(false); + closeModalHandler(); + }, + ); } } catch (err) { console.error('Error importing file:', err); - } finally { - closeModalHandler(); + setIsImporting(false); } }; @@ -118,15 +147,19 @@ export const ImportForm: FC = ({ > - - Import Item + + {buttonText} ); diff --git a/packages/app/components/item/ImportItemGlobal.tsx b/packages/app/components/item/ImportItemGlobal.tsx index 043fad444..4b3538ee5 100644 --- a/packages/app/components/item/ImportItemGlobal.tsx +++ b/packages/app/components/item/ImportItemGlobal.tsx @@ -8,7 +8,7 @@ export const ImportItemGlobal = () => { const ownerId = authUser?.id; if (!authUser) { - return null; // or some fallback + return null; } const { setIsModalOpen } = useModal(); diff --git a/packages/app/hooks/items/useImportFromBucket.ts b/packages/app/hooks/items/useImportFromBucket.ts index f5ff0f21e..72297b582 100644 --- a/packages/app/hooks/items/useImportFromBucket.ts +++ b/packages/app/hooks/items/useImportFromBucket.ts @@ -9,46 +9,56 @@ interface State { export const useImportFromBucket = () => { const utils = queryTrpc.useContext(); - const { mutate } = queryTrpc.importFromBucket.useMutation(); + const { mutateAsync } = queryTrpc.importFromBucket.useMutation(); const { isConnected, addOfflineRequest } = useOfflineQueue(); const updateItems = useItemsUpdater(); const handleImportFromBucket = useCallback( - ({ directory, ownerId }) => { + async ({ directory, ownerId }, onSuccess) => { if (isConnected) { - return mutate( - { directory, ownerId }, - { - onSuccess: (data) => { - console.log('ssssssssssssssssssssssssssssssss', data.items); - // Ensure data.items exists and is an array - const newItems = Array.isArray(data.items) ? data.items : []; + try { + const data = await mutateAsync({ directory, ownerId }); + const newItems = Array.isArray(data) ? data : []; + updateItems((prevState: State = {}) => { + const prevItems = Array.isArray(prevState.items) + ? prevState.items + : []; + return { + ...prevState, + items: [...newItems, ...prevItems], + }; + }); - // Update local state with the returned data - updateItems((prevState: State = {}) => { - const prevItems = Array.isArray(prevState.items) - ? prevState.items - : []; - return { - ...prevState, - items: [...newItems, ...prevItems], - }; - }); - - // Invalidate the cache to reflect the latest state - utils.getItemsGlobally.invalidate(); - }, - onError: (error) => { - console.error('Error fetching items:', error); - }, - }, - ); + utils.getItemsGlobally.invalidate(); + utils.getItemsGlobally.refetch(); + onSuccess(); + } catch (error) { + console.error('Error fetching items:', error); + } } else { - // Handle offline scenario addOfflineRequest('importFromBucket', { directory, ownerId }); + + updateItems((prevState: State = {}) => { + onSuccess(); + const prevItems = Array.isArray(prevState.items) + ? prevState.items + : []; + + return { + ...prevState, + items: [ + { + directory, + ownerId, + global: true, + }, + ...prevItems, + ], + }; + }); } }, - [updateItems, isConnected, mutate, utils, addOfflineRequest], + [updateItems, isConnected, mutateAsync, utils, addOfflineRequest], ); return { handleImportFromBucket }; diff --git a/packages/app/hooks/items/useImportItem.ts b/packages/app/hooks/items/useImportItem.ts index 158137351..f673aa7d8 100644 --- a/packages/app/hooks/items/useImportItem.ts +++ b/packages/app/hooks/items/useImportItem.ts @@ -14,21 +14,21 @@ export const useImportItem = () => { const updateItems = useItemsUpdater(); const handleImportNewItems = useCallback( - (newItem) => { + (newItem, onSuccess) => { if (isConnected) { return mutate(newItem, { onSuccess: () => { - // Update items only on successful mutation updateItems((prevState: State = {}) => { const prevItems = Array.isArray(prevState.items) ? prevState.items : []; return { ...prevState, - items: [newItem, ...prevItems], + items: [newItem, ...prevItems], // Use the data returned from the server }; }); utils.getItemsGlobally.invalidate(); + onSuccess(); }, onError: (error) => { console.error('Error adding item:', error); diff --git a/packages/app/hooks/packs/useImportPackItem.ts b/packages/app/hooks/packs/useImportPackItem.ts index 5f558d73c..311cb7867 100644 --- a/packages/app/hooks/packs/useImportPackItem.ts +++ b/packages/app/hooks/packs/useImportPackItem.ts @@ -7,12 +7,6 @@ export const useImportPackItem = () => { if (!newItem) { throw new Error('Item data is not available.'); } - - // Optionally: Perform optimistic update IF NEEDED - - return { - // No need to store previous state if not doing optimistic updates - }; }, onSuccess: (data, newItem, context) => { const previousPack = utils.getPackById.getData({ @@ -44,8 +38,6 @@ export const useImportPackItem = () => { }, onError: (error, newItem, context) => { console.error('Error adding item:', error); - - // Optionally: Rollback optimistic update here if implemented }, }); diff --git a/server/src/controllers/item/importFromBucket.ts b/server/src/controllers/item/importFromBucket.ts index dc68fa629..771787bca 100644 --- a/server/src/controllers/item/importFromBucket.ts +++ b/server/src/controllers/item/importFromBucket.ts @@ -1,5 +1,5 @@ import { protectedProcedure } from '../../trpc'; -import { addItemGlobalService } from '../../services/item/item.service'; +import { bulkAddItemsGlobalService } from '../../services/item/item.service'; import * as CryptoJS from 'crypto-js'; import { parseStringPromise } from 'xml2js'; import Papa from 'papaparse'; @@ -248,7 +248,7 @@ export function importFromBucketRoute() { header: true, complete: async function (results) { try { - const insertedItems = []; + const itemsToInsert = []; for (const [index, item] of results.data.entries()) { if ( @@ -258,27 +258,30 @@ export function importFromBucketRoute() { continue; } - const insertedItem = await addItemGlobalService( - item.name, - item.claimed_weight || 0, - item.quantity || 1, - item.claimed_weight_unit || 'g', - // item.category || 'Essentials', - 'Essentials', + itemsToInsert.push({ + name: item.name, + weight: item.claimed_weight || 0, + quantity: item.quantity || 1, + unit: item.claimed_weight_unit || 'g', + type: 'Essentials', ownerId, - executionCtx, - ); - - insertedItems.push(insertedItem); + }); } + + const insertedItems = await bulkAddItemsGlobalService( + itemsToInsert, + executionCtx, + ); + return resolve(insertedItems); } catch (error) { + console.error('Error in bulkAddItemsGlobalService:', error); + return reject( new Error(`Failed to add items: ${error.message}`), ); } }, - // Failed to add items: Category must be one of: Food, Water, Essentials error: function (error) { console.error('Error parsing CSV file:', error); reject(error); diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index c985ddc29..c47b555a9 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -14,6 +14,7 @@ import userRoutes from './userRoutes'; import mapPreviewRouter from './mapPreviewRouter'; import healthRoutes from './healthRoutes'; import { Hono } from 'hono'; +import querystring from 'querystring'; const router = new Hono(); @@ -34,9 +35,55 @@ router.route('/favorite', favoriteRouters); router.route('/mapPreview', mapPreviewRouter); router.route('/health', healthRoutes); -const helloRouter = new Hono(); +const testapi = new Hono(); -router.route('/hello', helloRouter); +testapi.get('/', async (c) => { + const params = c.req.query(); + console.log('Received data:', params); + + return c.json({ message: 'Data received successfully!', data: params }); +}); + +testapi.get('/test', async (c) => { + try { + const postData = querystring.stringify({ + project: 'PackRat', + spider: 'backcountry', + }); + + const response = await fetch('http://localhost:6800/schedule.json', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: postData, + }); + + const responseData = await response.json(); + + if (responseData.status === 'ok') { + console.log('Scraping initiated', responseData); + return c.json({ + message: 'Scraping initiated successfully!', + response: responseData, + }); + } else { + console.error('Error from Scrapyd:', responseData); + return c.json({ + message: 'Failed to initiate scraping', + error: responseData, + }); + } + } catch (error) { + console.error('Error initiating scraping:', error); + return c.json({ + message: 'Failed to initiate scraping', + error: error.toString(), + }); + } +}); + +router.route('/testapi', testapi); // Also listen to /api for backwards compatibility router.route('/api/user', userRoutes); diff --git a/server/src/services/item/bulkAddGlobalItemService.ts b/server/src/services/item/bulkAddGlobalItemService.ts index de3f88926..b7733d724 100644 --- a/server/src/services/item/bulkAddGlobalItemService.ts +++ b/server/src/services/item/bulkAddGlobalItemService.ts @@ -1,9 +1,8 @@ import { type ExecutionContext } from 'hono'; import { type InsertItemCategory } from '../../db/schema'; -import { Item } from '../../drizzle/methods/Item'; import { ItemCategory } from '../../drizzle/methods/itemcategory'; -import { ItemCategory as categories } from '../../utils/itemCategory'; -import { VectorClient } from '../../vector/client'; +import { DbClient } from 'src/db/client'; +import { item as ItemTable } from '../../db/schema'; export const bulkAddItemsGlobalService = async ( items: Array<{ @@ -16,18 +15,18 @@ export const bulkAddItemsGlobalService = async ( }>, executionCtx: ExecutionContext, ) => { - const itemClass = new Item(); + const categories = ['Food', 'Water', 'Essentials']; + const itemCategoryClass = new ItemCategory(); const insertedItems = []; for (const itemData of items) { const { name, weight, quantity, unit, type, ownerId } = itemData; - - let category: InsertItemCategory | null; if (!categories.includes(type)) { throw new Error(`Category must be one of: ${categories.join(', ')}`); } + let category: InsertItemCategory | null; category = (await itemCategoryClass.findItemCategory({ name: type })) || null; if (!category) { @@ -44,23 +43,14 @@ export const bulkAddItemsGlobalService = async ( ownerId, }; - insertedItems.push(newItem); - } - - const createdItems = await itemClass.createBulk(insertedItems); + const item = await DbClient.instance + .insert(ItemTable) + .values(newItem) + .returning() + .get(); - for (const item of createdItems) { - executionCtx.waitUntil( - VectorClient.instance.syncRecord({ - id: item.id, - content: item.name, - namespace: 'items', - metadata: { - isPublic: item.global, - }, - }), - ); + insertedItems.push(item); } - return createdItems; + return insertedItems; }; From 154919d6a656c9b5f812f5a01cc26be2600186b9 Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Mon, 5 Aug 2024 16:21:01 +0300 Subject: [PATCH 04/10] fix the http route as well --- .../src/controllers/item/importFromBucket.ts | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/server/src/controllers/item/importFromBucket.ts b/server/src/controllers/item/importFromBucket.ts index 771787bca..7478b16dc 100644 --- a/server/src/controllers/item/importFromBucket.ts +++ b/server/src/controllers/item/importFromBucket.ts @@ -66,7 +66,7 @@ function generateAWSHeaders( } export const importFromBucket = async (c) => { - const { directory } = await c.req.query(); + const { directory, ownerId } = await c.req.query(); const endpoint = c.env.BUCKET_ENDPOINT; const bucket = c.env.BUCKET_NAME; @@ -105,8 +105,6 @@ export const importFromBucket = async (c) => { .filter((item) => item.Key[0].startsWith(`${directory}/`)) .map((item) => item.Key[0]); - // console.log('File names in backcountry directory:', fileNames); - // Sort file names to get the latest one const latestFileName = fileNames.sort().reverse()[0]; @@ -114,8 +112,6 @@ export const importFromBucket = async (c) => { throw new Error('No files found in the backcountry directory'); } - // console.log('Latest file name:', latestFileName); - // Generate AWS Headers for fetching the latest file const fileHeaders = generateAWSHeaders( `${endpoint}/${bucket}/${latestFileName}`, @@ -143,19 +139,51 @@ export const importFromBucket = async (c) => { return c.json({ error: 'Error fetching file', details: fileData }); } - let parsedCSVData = null; + const itemsToInsert = []; + + await new Promise((resolve, reject) => { + Papa.parse(fileData, { + header: true, + complete: (results) => { + try { + for (const [index, item] of results.data.entries()) { + if ( + index === results.data.length - 1 && + Object.values(item).every((value) => value === '') + ) { + continue; + } - Papa.parse(fileData, { - header: true, - complete: function (results) { - parsedCSVData = results.data; - }, - error: function (error) { - console.error('Error parsing CSV file:', error); - }, + itemsToInsert.push({ + name: item.name, + weight: item.claimed_weight || 0, + quantity: item.quantity || 1, + unit: item.claimed_weight_unit || 'g', + type: 'Essentials', + ownerId, + }); + } + resolve(null); + } catch (error) { + console.error('Error processing CSV data:', error); + reject(error); + } + }, + error: (error) => { + console.error('Error parsing CSV file:', error); + reject(error); + }, + }); }); - return c.json({ message: 'File content logged', data: parsedCSVData }); + const insertedItems = await bulkAddItemsGlobalService( + itemsToInsert, + c.executionCtx, + ); + return c.json({ + message: 'Items inserted successfully', + data: insertedItems, + }); } catch (err) { console.error('Error:', err); return c.json({ error: 'An error occurred' }); From 1b5f06cfda7dc7c131af3e3a43d467cf343d6170 Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Mon, 5 Aug 2024 16:36:05 +0300 Subject: [PATCH 05/10] fix security headers --- server/src/controllers/item/importFromBucket.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server/src/controllers/item/importFromBucket.ts b/server/src/controllers/item/importFromBucket.ts index 7478b16dc..748d401d8 100644 --- a/server/src/controllers/item/importFromBucket.ts +++ b/server/src/controllers/item/importFromBucket.ts @@ -30,6 +30,8 @@ function generateAWSHeaders( accessKey, secretKey, sessionToken, + algorithm, + x_amz_token, ) { const amzDate = new Date() .toISOString() @@ -43,10 +45,9 @@ function generateAWSHeaders( `host:${new URL(url).hostname}\nx-amz-date:${amzDate}\n` + (sessionToken ? `x-amz-security-token:${sessionToken}\n` : ''); const signedHeaders = - 'host;x-amz-date' + (sessionToken ? ';x-amz-security-token' : ''); + 'host;x-amz-date' + (sessionToken ? `;${x_amz_token}` : ''); const canonicalRequest = `${method}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; - const algorithm = 'AWS4-HMAC-SHA256'; const credentialScope = `${dateStamp}/${region}/${service}/aws4_request`; const stringToSign = `${algorithm}\n${amzDate}\n${credentialScope}\n${CryptoJS.SHA256(canonicalRequest).toString(CryptoJS.enc.Hex)}`; @@ -76,6 +77,8 @@ export const importFromBucket = async (c) => { const accessKeyId = c.env.BUCKET_ACCESS_KEY_ID; const secretKey = c.env.BUCKET_SECRET_KEY; const sessionToken = c.env.BUCKET_SESSION_TOKEN; + const algorithm = c.env.AWS_SIGN_ALGORITHM; + const x_amz_token = c.env.X_AMZ_SECURITY_TOKEN; // Generate AWS Headers for listing bucket contents const listHeaders = generateAWSHeaders( @@ -86,6 +89,8 @@ export const importFromBucket = async (c) => { accessKeyId, secretKey, sessionToken, + algorithm, + x_amz_token, ); try { @@ -121,6 +126,8 @@ export const importFromBucket = async (c) => { accessKeyId, secretKey, sessionToken, + algorithm, + x_amz_token, ); // Fetch the specific CSV file @@ -205,6 +212,8 @@ export function importFromBucketRoute() { const accessKeyId = env.BUCKET_ACCESS_KEY_ID; const secretKey = env.BUCKET_SECRET_KEY; const sessionToken = env.BUCKET_SESSION_TOKEN; + const algorithm = env.AWS_SIGN_ALGORITHM; + const x_amz_token = env.X_AMZ_SECURITY_TOKEN; // Generate AWS Headers for listing bucket contents const listHeaders = generateAWSHeaders( @@ -215,6 +224,8 @@ export function importFromBucketRoute() { accessKeyId, secretKey, sessionToken, + algorithm, + x_amz_token, ); try { @@ -254,6 +265,8 @@ export function importFromBucketRoute() { accessKeyId, secretKey, sessionToken, + algorithm, + x_amz_token, ); // Fetch the specific CSV file From 4babf1a2865b9338ad8437d8ae6075913dd5f92e Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Mon, 5 Aug 2024 16:45:58 +0300 Subject: [PATCH 06/10] fix --- packages/app/package.json | 3 - yarn.lock | 403 +------------------------------------- 2 files changed, 6 insertions(+), 400 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index ebd7bc64b..1bb9dbed0 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -38,7 +38,6 @@ "@react-native-community/geolocation": "^3.0.6", "@react-native-community/netinfo": "11.1.0", "@react-native-google-signin/google-signin": "^9.0.2", - "@react-native-picker/picker": "^2.7.7", "@react-navigation/drawer": "^6.6.6", "@react-navigation/native": "^6.1.6", "@react-navigation/native-stack": "^6.9.12", @@ -121,7 +120,6 @@ "react-native-google-places-autocomplete": "^2.5.1", "react-native-paper": "^5.10.6", "react-native-paper-dates": "^0.18.12", - "react-native-picker-select": "^9.2.0", "react-native-reanimated": "~3.6.2", "react-native-safe-area-context": "4.8.2", "react-native-screens": "~3.29.0", @@ -133,7 +131,6 @@ "react-native-webview": "13.6.4", "react-redux": "^9.0.4", "react-responsive": "^9.0.2", - "react-select": "^5.8.0", "redux-persist": "^6.0.0", "serve": "^14.2.0", "server": "*", diff --git a/yarn.lock b/yarn.lock index 58b794963..5e236ff3a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -117,16 +117,6 @@ __metadata: languageName: node linkType: hard -"@babel/code-frame@npm:^7.24.7": - version: 7.24.7 - resolution: "@babel/code-frame@npm:7.24.7" - dependencies: - "@babel/highlight": "npm:^7.24.7" - picocolors: "npm:^1.0.0" - checksum: 10/4812e94885ba7e3213d49583a155fdffb05292330f0a9b2c41b49288da70cf3c746a3fda0bf1074041a6d741c33f8d7be24be5e96f41ef77395eeddc5c9ff624 - languageName: node - linkType: hard - "@babel/compat-data@npm:^7.20.5, @babel/compat-data@npm:^7.22.6, @babel/compat-data@npm:^7.23.5, @babel/compat-data@npm:^7.24.4": version: 7.24.4 resolution: "@babel/compat-data@npm:7.24.4" @@ -169,18 +159,6 @@ __metadata: languageName: node linkType: hard -"@babel/generator@npm:^7.25.0": - version: 7.25.0 - resolution: "@babel/generator@npm:7.25.0" - dependencies: - "@babel/types": "npm:^7.25.0" - "@jridgewell/gen-mapping": "npm:^0.3.5" - "@jridgewell/trace-mapping": "npm:^0.3.25" - jsesc: "npm:^2.5.1" - checksum: 10/de3ce2ae7aa0c9585260556ca5a81ce2ce6b8269e3260d7bb4e47a74661af715184ca6343e9906c22e4dd3eed5ce39977dfaf6cded4d2d8968fa096c7cf66697 - languageName: node - linkType: hard - "@babel/helper-annotate-as-pure@npm:^7.18.6, @babel/helper-annotate-as-pure@npm:^7.22.5": version: 7.22.5 resolution: "@babel/helper-annotate-as-pure@npm:7.22.5" @@ -294,16 +272,6 @@ __metadata: languageName: node linkType: hard -"@babel/helper-module-imports@npm:^7.16.7": - version: 7.24.7 - resolution: "@babel/helper-module-imports@npm:7.24.7" - dependencies: - "@babel/traverse": "npm:^7.24.7" - "@babel/types": "npm:^7.24.7" - checksum: 10/df8bfb2bb18413aa151ecd63b7d5deb0eec102f924f9de6bc08022ced7ed8ca7fed914562d2f6fa5b59b74a5d6e255dc35612b2bc3b8abf361e13f61b3704770 - languageName: node - linkType: hard - "@babel/helper-module-imports@npm:^7.22.15, @babel/helper-module-imports@npm:^7.24.1, @babel/helper-module-imports@npm:^7.24.3": version: 7.24.3 resolution: "@babel/helper-module-imports@npm:7.24.3" @@ -404,13 +372,6 @@ __metadata: languageName: node linkType: hard -"@babel/helper-string-parser@npm:^7.24.8": - version: 7.24.8 - resolution: "@babel/helper-string-parser@npm:7.24.8" - checksum: 10/6d1bf8f27dd725ce02bdc6dffca3c95fb9ab8a06adc2edbd9c1c9d68500274230d1a609025833ed81981eff560045b6b38f7b4c6fb1ab19fc90e5004e3932535 - languageName: node - linkType: hard - "@babel/helper-validator-identifier@npm:^7.22.20, @babel/helper-validator-identifier@npm:^7.24.5": version: 7.24.5 resolution: "@babel/helper-validator-identifier@npm:7.24.5" @@ -418,13 +379,6 @@ __metadata: languageName: node linkType: hard -"@babel/helper-validator-identifier@npm:^7.24.7": - version: 7.24.7 - resolution: "@babel/helper-validator-identifier@npm:7.24.7" - checksum: 10/86875063f57361471b531dbc2ea10bbf5406e12b06d249b03827d361db4cad2388c6f00936bcd9dc86479f7e2c69ea21412c2228d4b3672588b754b70a449d4b - languageName: node - linkType: hard - "@babel/helper-validator-option@npm:^7.23.5": version: 7.23.5 resolution: "@babel/helper-validator-option@npm:7.23.5" @@ -466,18 +420,6 @@ __metadata: languageName: node linkType: hard -"@babel/highlight@npm:^7.24.7": - version: 7.24.7 - resolution: "@babel/highlight@npm:7.24.7" - dependencies: - "@babel/helper-validator-identifier": "npm:^7.24.7" - chalk: "npm:^2.4.2" - js-tokens: "npm:^4.0.0" - picocolors: "npm:^1.0.0" - checksum: 10/69b73f38cdd4f881b09b939a711e76646da34f4834f4ce141d7a49a6bb1926eab1c594148970a8aa9360398dff800f63aade4e81fafdd7c8d8a8489ea93bfec1 - languageName: node - linkType: hard - "@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.1.6, @babel/parser@npm:^7.13.16, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.0, @babel/parser@npm:^7.20.15, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.23.3, @babel/parser@npm:^7.23.9, @babel/parser@npm:^7.24.0, @babel/parser@npm:^7.24.5": version: 7.24.5 resolution: "@babel/parser@npm:7.24.5" @@ -487,17 +429,6 @@ __metadata: languageName: node linkType: hard -"@babel/parser@npm:^7.25.0, @babel/parser@npm:^7.25.3": - version: 7.25.3 - resolution: "@babel/parser@npm:7.25.3" - dependencies: - "@babel/types": "npm:^7.25.2" - bin: - parser: ./bin/babel-parser.js - checksum: 10/7bd57e89110bdc9cffe0ef2f2286f1cfb9bbb3aa1d9208c287e0bf6a1eb4cfe6ab33958876ebc59aafcbe3e2381c4449240fc7cc2ff32b79bc9db89cd52fc779 - languageName: node - linkType: hard - "@babel/plugin-bugfix-firefox-class-in-computed-class-key@npm:^7.24.5": version: 7.24.5 resolution: "@babel/plugin-bugfix-firefox-class-in-computed-class-key@npm:7.24.5" @@ -1843,15 +1774,6 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.12.0, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.5.5": - version: 7.25.0 - resolution: "@babel/runtime@npm:7.25.0" - dependencies: - regenerator-runtime: "npm:^0.14.0" - checksum: 10/6870e9e0e9125075b3aeba49a266f442b10820bfc693019eb6c1785c5a0edbe927e98b8238662cdcdba17842107c040386c3b69f39a0a3b217f9d00ffe685b27 - languageName: node - linkType: hard - "@babel/runtime@npm:^7.12.5": version: 7.24.7 resolution: "@babel/runtime@npm:7.24.7" @@ -1872,17 +1794,6 @@ __metadata: languageName: node linkType: hard -"@babel/template@npm:^7.25.0": - version: 7.25.0 - resolution: "@babel/template@npm:7.25.0" - dependencies: - "@babel/code-frame": "npm:^7.24.7" - "@babel/parser": "npm:^7.25.0" - "@babel/types": "npm:^7.25.0" - checksum: 10/07ebecf6db8b28244b7397628e09c99e7a317b959b926d90455c7253c88df3677a5a32d1501d9749fe292a263ff51a4b6b5385bcabd5dadd3a48036f4d4949e0 - languageName: node - linkType: hard - "@babel/traverse@npm:^7.1.6, @babel/traverse@npm:^7.20.0, @babel/traverse@npm:^7.23.3, @babel/traverse@npm:^7.24.1, @babel/traverse@npm:^7.24.5": version: 7.24.5 resolution: "@babel/traverse@npm:7.24.5" @@ -1901,21 +1812,6 @@ __metadata: languageName: node linkType: hard -"@babel/traverse@npm:^7.24.7": - version: 7.25.3 - resolution: "@babel/traverse@npm:7.25.3" - dependencies: - "@babel/code-frame": "npm:^7.24.7" - "@babel/generator": "npm:^7.25.0" - "@babel/parser": "npm:^7.25.3" - "@babel/template": "npm:^7.25.0" - "@babel/types": "npm:^7.25.2" - debug: "npm:^4.3.1" - globals: "npm:^11.1.0" - checksum: 10/fba34f323e17fa83372fc290bc12413a50e2f780a86c7d8b1875c594b6be2857867804de5d52ab10a78a9cae29e1b09ea15d85ad63671ce97d79c40650282bb9 - languageName: node - linkType: hard - "@babel/types@npm:^7.0.0, @babel/types@npm:^7.1.6, @babel/types@npm:^7.20.0, @babel/types@npm:^7.20.7, @babel/types@npm:^7.21.3, @babel/types@npm:^7.22.15, @babel/types@npm:^7.22.5, @babel/types@npm:^7.23.0, @babel/types@npm:^7.23.3, @babel/types@npm:^7.23.4, @babel/types@npm:^7.24.0, @babel/types@npm:^7.24.5, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3": version: 7.24.5 resolution: "@babel/types@npm:7.24.5" @@ -1927,17 +1823,6 @@ __metadata: languageName: node linkType: hard -"@babel/types@npm:^7.24.7, @babel/types@npm:^7.25.0, @babel/types@npm:^7.25.2": - version: 7.25.2 - resolution: "@babel/types@npm:7.25.2" - dependencies: - "@babel/helper-string-parser": "npm:^7.24.8" - "@babel/helper-validator-identifier": "npm:^7.24.7" - to-fast-properties: "npm:^2.0.0" - checksum: 10/ccf5399db1dcd6dd87b84a6f7bc8dd241e04a326f4f038c973c26ccb69cd360c8f2276603f584c58fd94da95229313060b27baceb0d9b18a435742d3f616afd1 - languageName: node - linkType: hard - "@bcoe/v8-coverage@npm:^0.2.3": version: 0.2.3 resolution: "@bcoe/v8-coverage@npm:0.2.3" @@ -2203,45 +2088,6 @@ __metadata: languageName: node linkType: hard -"@emotion/babel-plugin@npm:^11.12.0": - version: 11.12.0 - resolution: "@emotion/babel-plugin@npm:11.12.0" - dependencies: - "@babel/helper-module-imports": "npm:^7.16.7" - "@babel/runtime": "npm:^7.18.3" - "@emotion/hash": "npm:^0.9.2" - "@emotion/memoize": "npm:^0.9.0" - "@emotion/serialize": "npm:^1.2.0" - babel-plugin-macros: "npm:^3.1.0" - convert-source-map: "npm:^1.5.0" - escape-string-regexp: "npm:^4.0.0" - find-root: "npm:^1.1.0" - source-map: "npm:^0.5.7" - stylis: "npm:4.2.0" - checksum: 10/fe6f4522ea2b61ef4214dd0b0f3778aad9c18434b47e50ae5091af226526bf305455c313065826a090682520c9462c151d4df62ec128f14671d3125afc05b148 - languageName: node - linkType: hard - -"@emotion/cache@npm:^11.13.0, @emotion/cache@npm:^11.4.0": - version: 11.13.1 - resolution: "@emotion/cache@npm:11.13.1" - dependencies: - "@emotion/memoize": "npm:^0.9.0" - "@emotion/sheet": "npm:^1.4.0" - "@emotion/utils": "npm:^1.4.0" - "@emotion/weak-memoize": "npm:^0.4.0" - stylis: "npm:4.2.0" - checksum: 10/090c8ad2e5b23f1b3a95e94f1f0554a40ed1dcd844c9d31629a68ff824eff40f32d1362f67aefa440ee0aabd5a8cabcc76870fd6d77144d3ff251bdcdf1420b9 - languageName: node - linkType: hard - -"@emotion/hash@npm:^0.9.2": - version: 0.9.2 - resolution: "@emotion/hash@npm:0.9.2" - checksum: 10/379bde2830ccb0328c2617ec009642321c0e009a46aa383dfbe75b679c6aea977ca698c832d225a893901f29d7b3eef0e38cf341f560f6b2b56f1ff23c172387 - languageName: node - linkType: hard - "@emotion/is-prop-valid@npm:^0.8.2": version: 0.8.8 resolution: "@emotion/is-prop-valid@npm:0.8.8" @@ -2258,84 +2104,6 @@ __metadata: languageName: node linkType: hard -"@emotion/memoize@npm:^0.9.0": - version: 0.9.0 - resolution: "@emotion/memoize@npm:0.9.0" - checksum: 10/038132359397348e378c593a773b1148cd0cf0a2285ffd067a0f63447b945f5278860d9de718f906a74c7c940ba1783ac2ca18f1c06a307b01cc0e3944e783b1 - languageName: node - linkType: hard - -"@emotion/react@npm:^11.8.1": - version: 11.13.0 - resolution: "@emotion/react@npm:11.13.0" - dependencies: - "@babel/runtime": "npm:^7.18.3" - "@emotion/babel-plugin": "npm:^11.12.0" - "@emotion/cache": "npm:^11.13.0" - "@emotion/serialize": "npm:^1.3.0" - "@emotion/use-insertion-effect-with-fallbacks": "npm:^1.1.0" - "@emotion/utils": "npm:^1.4.0" - "@emotion/weak-memoize": "npm:^0.4.0" - hoist-non-react-statics: "npm:^3.3.1" - peerDependencies: - react: ">=16.8.0" - peerDependenciesMeta: - "@types/react": - optional: true - checksum: 10/3dd2b3ffac51f0fa67ef3cb85d4064fd7ddc1212b587e3b328a1eade47024690175518d63c4cbabf28afa07e29187136b26d646e395158f6574fa6321a0b68f9 - languageName: node - linkType: hard - -"@emotion/serialize@npm:^1.2.0, @emotion/serialize@npm:^1.3.0": - version: 1.3.0 - resolution: "@emotion/serialize@npm:1.3.0" - dependencies: - "@emotion/hash": "npm:^0.9.2" - "@emotion/memoize": "npm:^0.9.0" - "@emotion/unitless": "npm:^0.9.0" - "@emotion/utils": "npm:^1.4.0" - csstype: "npm:^3.0.2" - checksum: 10/3ab17aa0dabdc77d5d573ef07df63e91e778c0637f4b7f690fde46ab0007496c8dfbf32d2836d3b22ac2ba2d8c58570da51092ba7ff068d4d790147de2352465 - languageName: node - linkType: hard - -"@emotion/sheet@npm:^1.4.0": - version: 1.4.0 - resolution: "@emotion/sheet@npm:1.4.0" - checksum: 10/8ac6e9bf6b373a648f26ae7f1c24041038524f4c72f436f4f8c4761c665e58880c3229d8d89b1f7a4815dd8e5b49634d03e60187cb6f93097d7f7c1859e869d5 - languageName: node - linkType: hard - -"@emotion/unitless@npm:^0.9.0": - version: 0.9.0 - resolution: "@emotion/unitless@npm:0.9.0" - checksum: 10/242754aa2f7368b5c2a5dbe61bf0a2bb0bfb4de091fe2388282f8c014c0796d0ca166b1639cf4f5f0e57e59258b622e7946a2e976ed5a56e06a5a306ca25adca - languageName: node - linkType: hard - -"@emotion/use-insertion-effect-with-fallbacks@npm:^1.1.0": - version: 1.1.0 - resolution: "@emotion/use-insertion-effect-with-fallbacks@npm:1.1.0" - peerDependencies: - react: ">=16.8.0" - checksum: 10/33a10f44a873b3f5ccd2a1a3d13c2f34ed628f5a2be1ccf28540a86535a14d3a930afcbef209d48346a22ec60ff48f43c86ee9c846b9480d23a55a17145da66c - languageName: node - linkType: hard - -"@emotion/utils@npm:^1.4.0": - version: 1.4.0 - resolution: "@emotion/utils@npm:1.4.0" - checksum: 10/e4cdb51819db01fec21c3e35a1391900c9e7f3ac1e7ecb419c8e408464830cd7ef6e1a116381cbfe3fb1039406fb7ed35f16a1575d502c92bc9f81bc13a3ee5a - languageName: node - linkType: hard - -"@emotion/weak-memoize@npm:^0.4.0": - version: 0.4.0 - resolution: "@emotion/weak-memoize@npm:0.4.0" - checksum: 10/db5da0e89bd752c78b6bd65a1e56231f0abebe2f71c0bd8fc47dff96408f7065b02e214080f99924f6a3bfe7ee15afc48dad999d76df86b39b16e513f7a94f52 - languageName: node - linkType: hard - "@envelop/core@npm:^4.0.0": version: 4.0.3 resolution: "@envelop/core@npm:4.0.3" @@ -4130,15 +3898,6 @@ __metadata: languageName: node linkType: hard -"@floating-ui/core@npm:^1.6.0": - version: 1.6.5 - resolution: "@floating-ui/core@npm:1.6.5" - dependencies: - "@floating-ui/utils": "npm:^0.2.5" - checksum: 10/946eccfc16d0eea2bb62bd8cee12211a1d2614968d541966ecd9b6d40f66f097391020ce109c8503676c14ec67f304414e5fecff324ac8950121574010c009e9 - languageName: node - linkType: hard - "@floating-ui/dom@npm:^1.0.0": version: 1.6.5 resolution: "@floating-ui/dom@npm:1.6.5" @@ -4149,16 +3908,6 @@ __metadata: languageName: node linkType: hard -"@floating-ui/dom@npm:^1.0.1": - version: 1.6.8 - resolution: "@floating-ui/dom@npm:1.6.8" - dependencies: - "@floating-ui/core": "npm:^1.6.0" - "@floating-ui/utils": "npm:^0.2.5" - checksum: 10/ebfc92b7a08addc1952d497174a197db80278d3701da7d7dedd3e1533daa80b12b7de02c19408de3f951195a3247f2f5c3cc10807071147e3193bbef469e90a5 - languageName: node - linkType: hard - "@floating-ui/react-dom@npm:^2.0.0, @floating-ui/react-dom@npm:^2.0.6": version: 2.0.9 resolution: "@floating-ui/react-dom@npm:2.0.9" @@ -4204,13 +3953,6 @@ __metadata: languageName: node linkType: hard -"@floating-ui/utils@npm:^0.2.5": - version: 0.2.5 - resolution: "@floating-ui/utils@npm:0.2.5" - checksum: 10/08df715c2a3bfa9d757347df0b38c89a3bfa92b0a32ff67d3d713960c2e72c202e22a2b220aacadbde5451ac2bd4c10411a73a8ed3707ded792f0182592eb01f - languageName: node - linkType: hard - "@formatjs/ecma402-abstract@npm:1.18.2": version: 1.18.2 resolution: "@formatjs/ecma402-abstract@npm:1.18.2" @@ -7335,16 +7077,6 @@ __metadata: languageName: node linkType: hard -"@react-native-picker/picker@npm:^2.7.7": - version: 2.7.7 - resolution: "@react-native-picker/picker@npm:2.7.7" - peerDependencies: - react: "*" - react-native: "*" - checksum: 10/96f528194b337e95e27780e9b88875df62b81d0ec1bc2a9992de946b348ccfc9bca86d5816ce2a2bb698b376dd2aee7202fd606a00dc3b2e19e1482516305f61 - languageName: node - linkType: hard - "@react-native/assets-registry@npm:0.74.81": version: 0.74.81 resolution: "@react-native/assets-registry@npm:0.74.81" @@ -11501,13 +11233,6 @@ __metadata: languageName: node linkType: hard -"@types/parse-json@npm:^4.0.0": - version: 4.0.2 - resolution: "@types/parse-json@npm:4.0.2" - checksum: 10/5bf62eec37c332ad10059252fc0dab7e7da730764869c980b0714777ad3d065e490627be9f40fc52f238ffa3ac4199b19de4127196910576c2fe34dd47c7a470 - languageName: node - linkType: hard - "@types/prop-types@npm:*": version: 15.7.12 resolution: "@types/prop-types@npm:15.7.12" @@ -11576,15 +11301,6 @@ __metadata: languageName: node linkType: hard -"@types/react-transition-group@npm:^4.4.0": - version: 4.4.10 - resolution: "@types/react-transition-group@npm:4.4.10" - dependencies: - "@types/react": "npm:*" - checksum: 10/b429f3bd54d9aea6c0395943ce2dda6b76fb458e902365bd91fd99bf72064fb5d59e2b74e78d10f2871908501d350da63e230d81bda2b616c967cab8dc51bd16 - languageName: node - linkType: hard - "@types/react@npm:*": version: 18.3.1 resolution: "@types/react@npm:18.3.1" @@ -12991,7 +12707,6 @@ __metadata: "@react-native-community/geolocation": "npm:^3.0.6" "@react-native-community/netinfo": "npm:11.1.0" "@react-native-google-signin/google-signin": "npm:^9.0.2" - "@react-native-picker/picker": "npm:^2.7.7" "@react-navigation/drawer": "npm:^6.6.6" "@react-navigation/native": "npm:^6.1.6" "@react-navigation/native-stack": "npm:^6.9.12" @@ -13094,7 +12809,6 @@ __metadata: react-native-google-places-autocomplete: "npm:^2.5.1" react-native-paper: "npm:^5.10.6" react-native-paper-dates: "npm:^0.18.12" - react-native-picker-select: "npm:^9.2.0" react-native-reanimated: "npm:~3.6.2" react-native-safe-area-context: "npm:4.8.2" react-native-screens: "npm:~3.29.0" @@ -13106,7 +12820,6 @@ __metadata: react-native-webview: "npm:13.6.4" react-redux: "npm:^9.0.4" react-responsive: "npm:^9.0.2" - react-select: "npm:^5.8.0" redux-persist: "npm:^6.0.0" serve: "npm:^14.2.0" server: "npm:*" @@ -13837,17 +13550,6 @@ __metadata: languageName: node linkType: hard -"babel-plugin-macros@npm:^3.1.0": - version: 3.1.0 - resolution: "babel-plugin-macros@npm:3.1.0" - dependencies: - "@babel/runtime": "npm:^7.12.5" - cosmiconfig: "npm:^7.0.0" - resolve: "npm:^1.19.0" - checksum: 10/30be6ca45e9a124c58ca00af9a0753e5410ec0b79a737714fc4722bbbeb693e55d9258f05c437145ef4a867c2d1603e06a1c292d66c243ce1227458c8ea2ca8c - languageName: node - linkType: hard - "babel-plugin-module-resolver@npm:^5.0.0": version: 5.0.2 resolution: "babel-plugin-module-resolver@npm:5.0.2" @@ -16264,13 +15966,6 @@ __metadata: languageName: node linkType: hard -"convert-source-map@npm:^1.5.0": - version: 1.9.0 - resolution: "convert-source-map@npm:1.9.0" - checksum: 10/dc55a1f28ddd0e9485ef13565f8f756b342f9a46c4ae18b843fe3c30c675d058d6a4823eff86d472f187b176f0adf51ea7b69ea38be34be4a63cbbf91b0593c8 - languageName: node - linkType: hard - "convert-source-map@npm:^2.0.0": version: 2.0.0 resolution: "convert-source-map@npm:2.0.0" @@ -16404,19 +16099,6 @@ __metadata: languageName: node linkType: hard -"cosmiconfig@npm:^7.0.0": - version: 7.1.0 - resolution: "cosmiconfig@npm:7.1.0" - dependencies: - "@types/parse-json": "npm:^4.0.0" - import-fresh: "npm:^3.2.1" - parse-json: "npm:^5.0.0" - path-type: "npm:^4.0.0" - yaml: "npm:^1.10.0" - checksum: 10/03600bb3870c80ed151b7b706b99a1f6d78df8f4bdad9c95485072ea13358ef294b13dd99f9e7bf4cc0b43bcd3599d40df7e648750d21c2f6817ca2cd687e071 - languageName: node - linkType: hard - "create-ecdh@npm:^4.0.0": version: 4.0.4 resolution: "create-ecdh@npm:4.0.4" @@ -17379,7 +17061,7 @@ __metadata: languageName: node linkType: hard -"dom-helpers@npm:^5.0.0, dom-helpers@npm:^5.0.1": +"dom-helpers@npm:^5.0.0": version: 5.2.1 resolution: "dom-helpers@npm:5.2.1" dependencies: @@ -25698,13 +25380,6 @@ __metadata: languageName: node linkType: hard -"lodash.isobject@npm:^3.0.2": - version: 3.0.2 - resolution: "lodash.isobject@npm:3.0.2" - checksum: 10/6c1667cbc4494d0a13a3617a4b23278d6d02dac520311f2bbb43f16f2cf71d2e6eb9dec8057315b77459df4890c756a256a087d3f4baa44a79ab5d6c968b060e - languageName: node - linkType: hard - "lodash.isplainobject@npm:^4.0.6": version: 4.0.6 resolution: "lodash.isplainobject@npm:4.0.6" @@ -29073,7 +28748,7 @@ __metadata: languageName: node linkType: hard -"parse-json@npm:^5.0.0, parse-json@npm:^5.2.0": +"parse-json@npm:^5.2.0": version: 5.2.0 resolution: "parse-json@npm:5.2.0" dependencies: @@ -30286,7 +29961,7 @@ __metadata: languageName: node linkType: hard -"prop-types@npm:15.8.1, prop-types@npm:^15.5.10, prop-types@npm:^15.6.0, prop-types@npm:^15.6.1, prop-types@npm:^15.6.2, prop-types@npm:^15.7.2, prop-types@npm:^15.8.1": +"prop-types@npm:15.8.1, prop-types@npm:^15.5.10, prop-types@npm:^15.6.1, prop-types@npm:^15.7.2, prop-types@npm:^15.8.1": version: 15.8.1 resolution: "prop-types@npm:15.8.1" dependencies: @@ -31046,18 +30721,6 @@ __metadata: languageName: node linkType: hard -"react-native-picker-select@npm:^9.2.0": - version: 9.2.0 - resolution: "react-native-picker-select@npm:9.2.0" - dependencies: - lodash.isequal: "npm:^4.5.0" - lodash.isobject: "npm:^3.0.2" - peerDependencies: - "@react-native-picker/picker": ^2.4.0 - checksum: 10/90d2997b2a249f7e09f4b534e2bff149b1dba0ae86a79e50f50580959531d2e200e2bb27975c80fad1fd28efb331fac13d9508519de2d12daceab8a223b00efa - languageName: node - linkType: hard - "react-native-ratings@npm:8.0.4": version: 8.0.4 resolution: "react-native-ratings@npm:8.0.4" @@ -31414,26 +31077,6 @@ __metadata: languageName: node linkType: hard -"react-select@npm:^5.8.0": - version: 5.8.0 - resolution: "react-select@npm:5.8.0" - dependencies: - "@babel/runtime": "npm:^7.12.0" - "@emotion/cache": "npm:^11.4.0" - "@emotion/react": "npm:^11.8.1" - "@floating-ui/dom": "npm:^1.0.1" - "@types/react-transition-group": "npm:^4.4.0" - memoize-one: "npm:^6.0.0" - prop-types: "npm:^15.6.0" - react-transition-group: "npm:^4.3.0" - use-isomorphic-layout-effect: "npm:^1.1.2" - peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 - checksum: 10/04d3639ea1872a9e4d9080ece1947432fc595403c0a740f671a1b7f7dd2639288cb133ec7a2b1ac20fad69fd303d696c2f924763405e0e1d93b847e54df9e966 - languageName: node - linkType: hard - "react-shallow-renderer@npm:^16.15.0": version: 16.15.0 resolution: "react-shallow-renderer@npm:16.15.0" @@ -31473,21 +31116,6 @@ __metadata: languageName: node linkType: hard -"react-transition-group@npm:^4.3.0": - version: 4.4.5 - resolution: "react-transition-group@npm:4.4.5" - dependencies: - "@babel/runtime": "npm:^7.5.5" - dom-helpers: "npm:^5.0.1" - loose-envify: "npm:^1.4.0" - prop-types: "npm:^15.6.2" - peerDependencies: - react: ">=16.6.0" - react-dom: ">=16.6.0" - checksum: 10/ca32d3fd2168c976c5d90a317f25d5f5cd723608b415fb3b9006f9d793c8965c619562d0884503a3e44e4b06efbca4fdd1520f30e58ca3e00a0890e637d55419 - languageName: node - linkType: hard - "react@npm:18.2.0": version: 18.2.0 resolution: "react@npm:18.2.0" @@ -32047,7 +31675,7 @@ __metadata: languageName: node linkType: hard -"resolve@npm:^1.10.0, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.19.0, resolve@npm:^1.20.0, resolve@npm:^1.22.2, resolve@npm:^1.22.4, resolve@npm:^1.22.8": +"resolve@npm:^1.10.0, resolve@npm:^1.14.2, resolve@npm:^1.17.0, resolve@npm:^1.20.0, resolve@npm:^1.22.2, resolve@npm:^1.22.4, resolve@npm:^1.22.8": version: 1.22.8 resolution: "resolve@npm:1.22.8" dependencies: @@ -32082,7 +31710,7 @@ __metadata: languageName: node linkType: hard -"resolve@patch:resolve@npm%3A^1.10.0#optional!builtin, resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.17.0#optional!builtin, resolve@patch:resolve@npm%3A^1.19.0#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin, resolve@patch:resolve@npm%3A^1.22.8#optional!builtin": +"resolve@patch:resolve@npm%3A^1.10.0#optional!builtin, resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.17.0#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin, resolve@patch:resolve@npm%3A^1.22.8#optional!builtin": version: 1.22.8 resolution: "resolve@patch:resolve@npm%3A1.22.8#optional!builtin::version=1.22.8&hash=c3c19d" dependencies: @@ -33446,7 +33074,7 @@ __metadata: languageName: node linkType: hard -"source-map@npm:^0.5.6, source-map@npm:^0.5.7": +"source-map@npm:^0.5.6": version: 0.5.7 resolution: "source-map@npm:0.5.7" checksum: 10/9b4ac749ec5b5831cad1f8cc4c19c4298ebc7474b24a0acf293e2f040f03f8eeccb3d01f12aa0f90cf46d555c887e03912b83a042c627f419bda5152d89c5269 @@ -34143,13 +33771,6 @@ __metadata: languageName: node linkType: hard -"stylis@npm:4.2.0": - version: 4.2.0 - resolution: "stylis@npm:4.2.0" - checksum: 10/58359185275ef1f39c339ae94e598168aa6bb789f6cf0d52e726c1e7087a94e9c17f0385a28d34483dec1ffc2c75670ec714dc5603d99c3124ec83bc2b0a0f42 - languageName: node - linkType: hard - "sucrase@npm:3.34.0": version: 3.34.0 resolution: "sucrase@npm:3.34.0" @@ -35928,18 +35549,6 @@ __metadata: languageName: node linkType: hard -"use-isomorphic-layout-effect@npm:^1.1.2": - version: 1.1.2 - resolution: "use-isomorphic-layout-effect@npm:1.1.2" - peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - peerDependenciesMeta: - "@types/react": - optional: true - checksum: 10/fd3787ed19f6cfbf70e2c5822d01bebbf96b00968195840d5ad61082b8e6ca7a8e2e46270c4096537d18a38ea57f4e4e9668cce5eec36fa4697ddba2ef1203fd - languageName: node - linkType: hard - "use-latest-callback@npm:^0.1.5, use-latest-callback@npm:^0.1.9": version: 0.1.9 resolution: "use-latest-callback@npm:0.1.9" From c8f3586a9223e1caaaf8a219471c0df608adef54 Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Mon, 5 Aug 2024 17:49:54 +0300 Subject: [PATCH 07/10] fix importing state in packs --- packages/app/components/item/ImportForm.tsx | 2 ++ server/src/routes/trpcRouter.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/app/components/item/ImportForm.tsx b/packages/app/components/item/ImportForm.tsx index c1f9cf970..daae7736b 100644 --- a/packages/app/components/item/ImportForm.tsx +++ b/packages/app/components/item/ImportForm.tsx @@ -118,6 +118,8 @@ export const ImportForm: FC = ({ }); } else { importPackItem({ content: fileContent, packId, ownerId }); + setIsImporting(false); + closeModalHandler(); } } else { handleImportFromBucket( diff --git a/server/src/routes/trpcRouter.ts b/server/src/routes/trpcRouter.ts index c53ceba17..e399ec51c 100644 --- a/server/src/routes/trpcRouter.ts +++ b/server/src/routes/trpcRouter.ts @@ -72,7 +72,6 @@ import { searchItemsByNameRoute, getSimilarItemsRoute, importFromBucketRoute, - importFromBucket, } from '../controllers/item'; import { getTrailsRoute } from '../controllers/getTrail'; import { getParksRoute } from '../controllers/getParks'; From e96c201ffce50dc624628e1518462c02f1be8ffa Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Tue, 6 Aug 2024 09:47:00 +0300 Subject: [PATCH 08/10] fix validations local build push --- packages/validations/src/index.d.ts | 3 - packages/validations/src/index.js | 4 - packages/validations/src/index.js.map | 1 - packages/validations/src/utils.d.ts | 2 - packages/validations/src/utils.js | 2 - packages/validations/src/utils.js.map | 1 - .../src/validations/authTokenValidator.d.ts | 15 - .../src/validations/authTokenValidator.js | 8 - .../src/validations/authTokenValidator.js.map | 1 - .../src/validations/destinationValidator.d.ts | 8 - .../src/validations/destinationValidator.js | 5 - .../validations/destinationValidator.js.map | 1 - .../src/validations/extrasValidator.d.ts | 15 - .../src/validations/extrasValidator.js | 8 - .../src/validations/extrasValidator.js.map | 1 - .../validations/src/validations/index.d.ts | 14 - packages/validations/src/validations/index.js | 16 - .../validations/src/validations/index.js.map | 1 - .../src/validations/itemRoutesValidator.d.ts | 202 --------- .../src/validations/itemRoutesValidator.js | 81 ---- .../validations/itemRoutesValidator.js.map | 1 - .../validations/openAIRoutesValidator.d.ts | 37 -- .../src/validations/openAIRoutesValidator.js | 16 - .../validations/openAIRoutesValidator.js.map | 1 - .../src/validations/osmValidator.d.ts | 94 ---- .../src/validations/osmValidator.js | 27 -- .../src/validations/osmValidator.js.map | 1 - .../src/validations/packRoutesValidator.d.ts | 102 ----- .../src/validations/packRoutesValidator.js | 45 -- .../validations/packRoutesValidator.js.map | 1 - .../src/validations/parksRouteValidator.d.ts | 8 - .../src/validations/parksRouteValidator.js | 5 - .../validations/parksRouteValidator.js.map | 1 - .../src/validations/roleValidator.d.ts | 2 - .../src/validations/roleValidator.js | 3 - .../src/validations/roleValidator.js.map | 1 - .../validations/templateRouteValidator.d.ts | 44 -- .../src/validations/templateRouteValidator.js | 19 - .../validations/templateRouteValidator.js.map | 1 - .../src/validations/trailsRouteValidator.d.ts | 20 - .../src/validations/trailsRouteValidator.js | 9 - .../validations/trailsRouteValidator.js.map | 1 - .../tripRoutesValidator/enums.d.ts | 11 - .../validations/tripRoutesValidator/enums.js | 13 - .../tripRoutesValidator/enums.js.map | 1 - .../tripRoutesValidator/index.d.ts | 2 - .../validations/tripRoutesValidator/index.js | 3 - .../tripRoutesValidator/index.js.map | 1 - .../tripRoutesValidator.d.ts | 422 ------------------ .../tripRoutesValidator.js | 65 --- .../tripRoutesValidator.js.map | 1 - .../src/validations/userRoutesValidator.d.ts | 268 ----------- .../src/validations/userRoutesValidator.js | 116 ----- .../validations/userRoutesValidator.js.map | 1 - .../validations/weatherRoutesValidator.d.ts | 21 - .../src/validations/weatherRoutesValidator.js | 10 - .../validations/weatherRoutesValidator.js.map | 1 - 57 files changed, 1764 deletions(-) delete mode 100644 packages/validations/src/index.d.ts delete mode 100644 packages/validations/src/index.js delete mode 100644 packages/validations/src/index.js.map delete mode 100644 packages/validations/src/utils.d.ts delete mode 100644 packages/validations/src/utils.js delete mode 100644 packages/validations/src/utils.js.map delete mode 100644 packages/validations/src/validations/authTokenValidator.d.ts delete mode 100644 packages/validations/src/validations/authTokenValidator.js delete mode 100644 packages/validations/src/validations/authTokenValidator.js.map delete mode 100644 packages/validations/src/validations/destinationValidator.d.ts delete mode 100644 packages/validations/src/validations/destinationValidator.js delete mode 100644 packages/validations/src/validations/destinationValidator.js.map delete mode 100644 packages/validations/src/validations/extrasValidator.d.ts delete mode 100644 packages/validations/src/validations/extrasValidator.js delete mode 100644 packages/validations/src/validations/extrasValidator.js.map delete mode 100644 packages/validations/src/validations/index.d.ts delete mode 100644 packages/validations/src/validations/index.js delete mode 100644 packages/validations/src/validations/index.js.map delete mode 100644 packages/validations/src/validations/itemRoutesValidator.d.ts delete mode 100644 packages/validations/src/validations/itemRoutesValidator.js delete mode 100644 packages/validations/src/validations/itemRoutesValidator.js.map delete mode 100644 packages/validations/src/validations/openAIRoutesValidator.d.ts delete mode 100644 packages/validations/src/validations/openAIRoutesValidator.js delete mode 100644 packages/validations/src/validations/openAIRoutesValidator.js.map delete mode 100644 packages/validations/src/validations/osmValidator.d.ts delete mode 100644 packages/validations/src/validations/osmValidator.js delete mode 100644 packages/validations/src/validations/osmValidator.js.map delete mode 100644 packages/validations/src/validations/packRoutesValidator.d.ts delete mode 100644 packages/validations/src/validations/packRoutesValidator.js delete mode 100644 packages/validations/src/validations/packRoutesValidator.js.map delete mode 100644 packages/validations/src/validations/parksRouteValidator.d.ts delete mode 100644 packages/validations/src/validations/parksRouteValidator.js delete mode 100644 packages/validations/src/validations/parksRouteValidator.js.map delete mode 100644 packages/validations/src/validations/roleValidator.d.ts delete mode 100644 packages/validations/src/validations/roleValidator.js delete mode 100644 packages/validations/src/validations/roleValidator.js.map delete mode 100644 packages/validations/src/validations/templateRouteValidator.d.ts delete mode 100644 packages/validations/src/validations/templateRouteValidator.js delete mode 100644 packages/validations/src/validations/templateRouteValidator.js.map delete mode 100644 packages/validations/src/validations/trailsRouteValidator.d.ts delete mode 100644 packages/validations/src/validations/trailsRouteValidator.js delete mode 100644 packages/validations/src/validations/trailsRouteValidator.js.map delete mode 100644 packages/validations/src/validations/tripRoutesValidator/enums.d.ts delete mode 100644 packages/validations/src/validations/tripRoutesValidator/enums.js delete mode 100644 packages/validations/src/validations/tripRoutesValidator/enums.js.map delete mode 100644 packages/validations/src/validations/tripRoutesValidator/index.d.ts delete mode 100644 packages/validations/src/validations/tripRoutesValidator/index.js delete mode 100644 packages/validations/src/validations/tripRoutesValidator/index.js.map delete mode 100644 packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts delete mode 100644 packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js delete mode 100644 packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map delete mode 100644 packages/validations/src/validations/userRoutesValidator.d.ts delete mode 100644 packages/validations/src/validations/userRoutesValidator.js delete mode 100644 packages/validations/src/validations/userRoutesValidator.js.map delete mode 100644 packages/validations/src/validations/weatherRoutesValidator.d.ts delete mode 100644 packages/validations/src/validations/weatherRoutesValidator.js delete mode 100644 packages/validations/src/validations/weatherRoutesValidator.js.map diff --git a/packages/validations/src/index.d.ts b/packages/validations/src/index.d.ts deleted file mode 100644 index e2141618c..000000000 --- a/packages/validations/src/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './validations'; -export * from './utils'; -export { ZodSchema } from 'zod'; diff --git a/packages/validations/src/index.js b/packages/validations/src/index.js deleted file mode 100644 index 06a998996..000000000 --- a/packages/validations/src/index.js +++ /dev/null @@ -1,4 +0,0 @@ -export * from './validations'; -export * from './utils'; -export { ZodSchema } from 'zod'; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/validations/src/index.js.map b/packages/validations/src/index.js.map deleted file mode 100644 index 634b03ee5..000000000 --- a/packages/validations/src/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/utils.d.ts b/packages/validations/src/utils.d.ts deleted file mode 100644 index 33fb93473..000000000 --- a/packages/validations/src/utils.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { ZodSchema, z } from 'zod'; -export type ValidationType = z.infer; diff --git a/packages/validations/src/utils.js b/packages/validations/src/utils.js deleted file mode 100644 index e6c75f0b7..000000000 --- a/packages/validations/src/utils.js +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/packages/validations/src/utils.js.map b/packages/validations/src/utils.js.map deleted file mode 100644 index 9e95c93e8..000000000 --- a/packages/validations/src/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/packages/validations/src/validations/authTokenValidator.d.ts b/packages/validations/src/validations/authTokenValidator.d.ts deleted file mode 100644 index d5c75a663..000000000 --- a/packages/validations/src/validations/authTokenValidator.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { z } from 'zod'; -export declare const TokenSchema: z.ZodObject<{ - id: z.ZodString; -}, "strip", z.ZodTypeAny, { - id?: string; -}, { - id?: string; -}>; -export declare const googleSignin: z.ZodObject<{ - idToken: z.ZodString; -}, "strip", z.ZodTypeAny, { - idToken?: string; -}, { - idToken?: string; -}>; diff --git a/packages/validations/src/validations/authTokenValidator.js b/packages/validations/src/validations/authTokenValidator.js deleted file mode 100644 index e2e0126d7..000000000 --- a/packages/validations/src/validations/authTokenValidator.js +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; -export const TokenSchema = z.object({ - id: z.string(), -}); -export const googleSignin = z.object({ - idToken: z.string().nonempty(), -}); -//# sourceMappingURL=authTokenValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/authTokenValidator.js.map b/packages/validations/src/validations/authTokenValidator.js.map deleted file mode 100644 index 8c8a7be1f..000000000 --- a/packages/validations/src/validations/authTokenValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"authTokenValidator.js","sourceRoot":"","sources":["authTokenValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/destinationValidator.d.ts b/packages/validations/src/validations/destinationValidator.d.ts deleted file mode 100644 index eb5313eac..000000000 --- a/packages/validations/src/validations/destinationValidator.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; -export declare const getDestinationByid: z.ZodObject<{ - id: z.ZodString; -}, "strip", z.ZodTypeAny, { - id?: string; -}, { - id?: string; -}>; diff --git a/packages/validations/src/validations/destinationValidator.js b/packages/validations/src/validations/destinationValidator.js deleted file mode 100644 index 559c8b8fb..000000000 --- a/packages/validations/src/validations/destinationValidator.js +++ /dev/null @@ -1,5 +0,0 @@ -import { z } from 'zod'; -export const getDestinationByid = z.object({ - id: z.string(), -}); -//# sourceMappingURL=destinationValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/destinationValidator.js.map b/packages/validations/src/validations/destinationValidator.js.map deleted file mode 100644 index ae0d9f0c7..000000000 --- a/packages/validations/src/validations/destinationValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"destinationValidator.js","sourceRoot":"","sources":["destinationValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/extrasValidator.d.ts b/packages/validations/src/validations/extrasValidator.d.ts deleted file mode 100644 index b680a72c1..000000000 --- a/packages/validations/src/validations/extrasValidator.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { z } from 'zod'; -export declare const AddressArray: z.ZodObject<{ - addressArray: z.ZodString; -}, "strip", z.ZodTypeAny, { - addressArray?: string; -}, { - addressArray?: string; -}>; -export declare const handlePasswordReset: z.ZodObject<{ - token: z.ZodString; -}, "strip", z.ZodTypeAny, { - token?: string; -}, { - token?: string; -}>; diff --git a/packages/validations/src/validations/extrasValidator.js b/packages/validations/src/validations/extrasValidator.js deleted file mode 100644 index 818efd8ec..000000000 --- a/packages/validations/src/validations/extrasValidator.js +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; -export const AddressArray = z.object({ - addressArray: z.string(), -}); -export const handlePasswordReset = z.object({ - token: z.string(), -}); -//# sourceMappingURL=extrasValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/extrasValidator.js.map b/packages/validations/src/validations/extrasValidator.js.map deleted file mode 100644 index 6f6a643e5..000000000 --- a/packages/validations/src/validations/extrasValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"extrasValidator.js","sourceRoot":"","sources":["extrasValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/index.d.ts b/packages/validations/src/validations/index.d.ts deleted file mode 100644 index 0d21d0029..000000000 --- a/packages/validations/src/validations/index.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -export * from './userRoutesValidator'; -export * from './tripRoutesValidator'; -export * from './packRoutesValidator'; -export * from './itemRoutesValidator'; -export * from './destinationValidator'; -export * from './osmValidator'; -export * from './parksRouteValidator'; -export * from './trailsRouteValidator'; -export * from './openAIRoutesValidator'; -export * from './extrasValidator'; -export * from './templateRouteValidator'; -export * from './weatherRoutesValidator'; -export * from './roleValidator'; -export * from './authTokenValidator'; diff --git a/packages/validations/src/validations/index.js b/packages/validations/src/validations/index.js deleted file mode 100644 index 4b714963d..000000000 --- a/packages/validations/src/validations/index.js +++ /dev/null @@ -1,16 +0,0 @@ -// export default userRoutesValidator; -export * from './userRoutesValidator'; -export * from './tripRoutesValidator'; -export * from './packRoutesValidator'; -export * from './itemRoutesValidator'; -export * from './destinationValidator'; -export * from './osmValidator'; -export * from './parksRouteValidator'; -export * from './trailsRouteValidator'; -export * from './openAIRoutesValidator'; -export * from './extrasValidator'; -export * from './templateRouteValidator'; -export * from './weatherRoutesValidator'; -export * from './roleValidator'; -export * from './authTokenValidator'; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/index.js.map b/packages/validations/src/validations/index.js.map deleted file mode 100644 index 38c546543..000000000 --- a/packages/validations/src/validations/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/itemRoutesValidator.d.ts b/packages/validations/src/validations/itemRoutesValidator.d.ts deleted file mode 100644 index c8a5a76c4..000000000 --- a/packages/validations/src/validations/itemRoutesValidator.d.ts +++ /dev/null @@ -1,202 +0,0 @@ -import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; -import { z } from 'zod'; -export declare const getItemByName: z.ZodObject<{ - name: z.ZodString; -}, "strip", z.ZodTypeAny, { - name?: string; -}, { - name?: string; -}>; -export declare const getItems: z.ZodObject<{ - packId: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - packId?: string; -}, { - packId?: string; -}>; -export declare const getItemById: z.ZodObject<{ - id: z.ZodString; -}, "strip", z.ZodTypeAny, { - id?: string; -}, { - id?: string; -}>; -export declare const addItem: z.ZodObject<{ - name: z.ZodString; - weight: z.ZodNumber; - quantity: z.ZodNumber; - unit: z.ZodString; - packId: z.ZodString; - type: z.ZodString; - ownerId: z.ZodString; - id: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - id?: string; - name?: string; - type?: string; - packId?: string; - weight?: number; - quantity?: number; - unit?: string; - ownerId?: string; -}, { - id?: string; - name?: string; - type?: string; - packId?: string; - weight?: number; - quantity?: number; - unit?: string; - ownerId?: string; -}>; -export declare const importItem: z.ZodObject<{ - content: z.ZodString; - packId: z.ZodString; - ownerId: z.ZodString; -}, "strip", z.ZodTypeAny, { - packId?: string; - ownerId?: string; - content?: string; -}, { - packId?: string; - ownerId?: string; - content?: string; -}>; -export type Item = z.infer; -export declare const editItem: z.ZodObject<{ - id: z.ZodString; - name: z.ZodString; - weight: z.ZodNumber; - quantity: z.ZodNumber; - unit: z.ZodString; - type: z.ZodString; -}, "strip", z.ZodTypeAny, { - id?: string; - name?: string; - type?: string; - weight?: number; - quantity?: number; - unit?: string; -}, { - id?: string; - name?: string; - type?: string; - weight?: number; - quantity?: number; - unit?: string; -}>; -export declare const addGlobalItemToPack: z.ZodObject<{ - packId: z.ZodString; - itemId: z.ZodString; - ownerId: z.ZodString; -}, "strip", z.ZodTypeAny, { - packId?: string; - ownerId?: string; - itemId?: string; -}, { - packId?: string; - ownerId?: string; - itemId?: string; -}>; -export declare const deleteGlobalItem: z.ZodObject<{ - itemId: z.ZodString; -}, "strip", z.ZodTypeAny, { - itemId?: string; -}, { - itemId?: string; -}>; -export declare const editGlobalItemAsDuplicate: z.ZodObject<{ - itemId: z.ZodString; - packId: z.ZodString; -}, "strip", z.ZodTypeAny, { - packId?: string; - itemId?: string; -}, { - packId?: string; - itemId?: string; -}>; -export declare const deleteItem: z.ZodObject<{ - itemId: z.ZodString; - packId: z.ZodString; -}, "strip", z.ZodTypeAny, { - packId?: string; - itemId?: string; -}, { - packId?: string; - itemId?: string; -}>; -export declare const addItemGlobal: z.ZodObject<{ - name: z.ZodString; - weight: z.ZodNumber; - quantity: z.ZodNumber; - unit: z.ZodString; - type: z.ZodString; - ownerId: z.ZodString; -}, "strip", z.ZodTypeAny, { - name?: string; - type?: string; - weight?: number; - quantity?: number; - unit?: string; - ownerId?: string; -}, { - name?: string; - type?: string; - weight?: number; - quantity?: number; - unit?: string; - ownerId?: string; -}>; -export declare const importItemsGlobal: z.ZodObject<{ - content: z.ZodString; - ownerId: z.ZodString; -}, "strip", z.ZodTypeAny, { - ownerId?: string; - content?: string; -}, { - ownerId?: string; - content?: string; -}>; -export declare const getItemsGlobally: z.ZodObject<{ - limit: z.ZodNumber; - page: z.ZodNumber; -}, "strip", z.ZodTypeAny, { - limit?: number; - page?: number; -}, { - limit?: number; - page?: number; -}>; -export declare const getSimilarItems: z.ZodObject<{ - id: z.ZodString; - limit: z.ZodNumber; - visibility: z.ZodDefault>; -}, "strip", z.ZodTypeAny, { - id?: string; - limit?: number; - visibility?: PackAndItemVisibilityFilter; -}, { - id?: string; - limit?: number; - visibility?: PackAndItemVisibilityFilter; -}>; -export declare const importItemHeaders: z.ZodObject<{ - Name: z.ZodString; - Weight: z.ZodString; - Unit: z.ZodString; - Quantity: z.ZodString; - Category: z.ZodString; -}, "strip", z.ZodTypeAny, { - Name?: string; - Weight?: string; - Unit?: string; - Quantity?: string; - Category?: string; -}, { - Name?: string; - Weight?: string; - Unit?: string; - Quantity?: string; - Category?: string; -}>; -export type ImportItemHeaders = z.infer; diff --git a/packages/validations/src/validations/itemRoutesValidator.js b/packages/validations/src/validations/itemRoutesValidator.js deleted file mode 100644 index b823eb59f..000000000 --- a/packages/validations/src/validations/itemRoutesValidator.js +++ /dev/null @@ -1,81 +0,0 @@ -import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; -import { z } from 'zod'; -export const getItemByName = z.object({ - name: z.string(), -}); -export const getItems = z.object({ - packId: z.string().optional(), -}); -export const getItemById = z.object({ - id: z.string(), -}); -export const addItem = z.object({ - name: z.string(), - weight: z.number(), - quantity: z.number(), - unit: z.string(), - packId: z.string(), - type: z.string(), - ownerId: z.string(), - id: z.string().optional(), -}); -export const importItem = z.object({ - content: z.string(), - packId: z.string(), - ownerId: z.string(), -}); -export const editItem = z.object({ - id: z.string(), - name: z.string().nonempty(), - weight: z.number(), - quantity: z.number(), - unit: z.string(), - type: z.string(), -}); -export const addGlobalItemToPack = z.object({ - packId: z.string(), - itemId: z.string(), - ownerId: z.string(), -}); -export const deleteGlobalItem = z.object({ - itemId: z.string(), -}); -export const editGlobalItemAsDuplicate = z.object({ - itemId: z.string(), - packId: z.string(), -}); -export const deleteItem = z.object({ - itemId: z.string(), - packId: z.string(), -}); -export const addItemGlobal = z.object({ - name: z.string(), - weight: z.number(), - quantity: z.number(), - unit: z.string(), - type: z.string(), - ownerId: z.string(), -}); -export const importItemsGlobal = z.object({ - content: z.string(), - ownerId: z.string(), -}); -export const getItemsGlobally = z.object({ - limit: z.number(), - page: z.number(), -}); -export const getSimilarItems = z.object({ - id: z.string(), - limit: z.number(), - visibility: z - .nativeEnum(PackAndItemVisibilityFilter) - .default(PackAndItemVisibilityFilter.ALL), -}); -export const importItemHeaders = z.object({ - Name: z.string(), - Weight: z.string(), - Unit: z.string(), - Quantity: z.string(), - Category: z.string(), -}); -//# sourceMappingURL=itemRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/itemRoutesValidator.js.map b/packages/validations/src/validations/itemRoutesValidator.js.map deleted file mode 100644 index 8f49490dd..000000000 --- a/packages/validations/src/validations/itemRoutesValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"itemRoutesValidator.js","sourceRoot":"","sources":["itemRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,IAAI,E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AAC,MAAM,EAAE;IAChB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/openAIRoutesValidator.d.ts b/packages/validations/src/validations/openAIRoutesValidator.d.ts deleted file mode 100644 index 70ae14918..000000000 --- a/packages/validations/src/validations/openAIRoutesValidator.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { z } from 'zod'; -export declare const getAIResponse: z.ZodObject<{ - userId: z.ZodString; - itemTypeId: z.ZodString; - userInput: z.ZodString; -}, "strip", z.ZodTypeAny, { - userId?: string; - itemTypeId?: string; - userInput?: string; -}, { - userId?: string; - itemTypeId?: string; - userInput?: string; -}>; -export declare const getUserChats: z.ZodObject<{ - userId: z.ZodString; - itemTypeId: z.ZodString; -}, "strip", z.ZodTypeAny, { - userId?: string; - itemTypeId?: string; -}, { - userId?: string; - itemTypeId?: string; -}>; -export declare const getAISuggestions: z.ZodObject<{ - userId: z.ZodString; - itemTypeId: z.ZodString; - type: z.ZodString; -}, "strip", z.ZodTypeAny, { - userId?: string; - type?: string; - itemTypeId?: string; -}, { - userId?: string; - type?: string; - itemTypeId?: string; -}>; diff --git a/packages/validations/src/validations/openAIRoutesValidator.js b/packages/validations/src/validations/openAIRoutesValidator.js deleted file mode 100644 index f92dbdf5b..000000000 --- a/packages/validations/src/validations/openAIRoutesValidator.js +++ /dev/null @@ -1,16 +0,0 @@ -import { z } from 'zod'; -export const getAIResponse = z.object({ - userId: z.string(), - itemTypeId: z.string(), - userInput: z.string(), -}); -export const getUserChats = z.object({ - userId: z.string(), - itemTypeId: z.string(), -}); -export const getAISuggestions = z.object({ - userId: z.string(), - itemTypeId: z.string(), - type: z.string(), -}); -//# sourceMappingURL=openAIRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/openAIRoutesValidator.js.map b/packages/validations/src/validations/openAIRoutesValidator.js.map deleted file mode 100644 index f342c7851..000000000 --- a/packages/validations/src/validations/openAIRoutesValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"openAIRoutesValidator.js","sourceRoot":"","sources":["openAIRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/osmValidator.d.ts b/packages/validations/src/validations/osmValidator.d.ts deleted file mode 100644 index ef831f1a4..000000000 --- a/packages/validations/src/validations/osmValidator.d.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { z } from 'zod'; -export declare const getOsm: z.ZodObject<{ - activityType: z.ZodString; - startPoint: z.ZodObject<{ - latitude: z.ZodNumber; - longitude: z.ZodNumber; - }, "strip", z.ZodTypeAny, { - latitude?: number; - longitude?: number; - }, { - latitude?: number; - longitude?: number; - }>; - endPoint: z.ZodObject<{ - latitude: z.ZodNumber; - longitude: z.ZodNumber; - }, "strip", z.ZodTypeAny, { - latitude?: number; - longitude?: number; - }, { - latitude?: number; - longitude?: number; - }>; -}, "strip", z.ZodTypeAny, { - activityType?: string; - startPoint?: { - latitude?: number; - longitude?: number; - }; - endPoint?: { - latitude?: number; - longitude?: number; - }; -}, { - activityType?: string; - startPoint?: { - latitude?: number; - longitude?: number; - }; - endPoint?: { - latitude?: number; - longitude?: number; - }; -}>; -export declare const getParksOSM: z.ZodObject<{ - lat: z.ZodNumber; - lon: z.ZodNumber; - radius: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - lat?: number; - lon?: number; - radius?: number; -}, { - lat?: number; - lon?: number; - radius?: number; -}>; -export declare const getPhotonDetails: z.ZodObject<{ - id: z.ZodUnion<[z.ZodString, z.ZodNumber]>; - type: z.ZodString; -}, "strip", z.ZodTypeAny, { - id?: string | number; - type?: string; -}, { - id?: string | number; - type?: string; -}>; -export declare const getPhotonResults: z.ZodObject<{ - searchString: z.ZodString; -}, "strip", z.ZodTypeAny, { - searchString?: string; -}, { - searchString?: string; -}>; -export declare const getTrailsOSM: z.ZodObject<{ - lat: z.ZodNumber; - lon: z.ZodNumber; - radius: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - lat?: number; - lon?: number; - radius?: number; -}, { - lat?: number; - lon?: number; - radius?: number; -}>; -export declare const postSingleGeoJSON: z.ZodObject<{ - geojson: z.ZodAny; -}, "strip", z.ZodTypeAny, { - geojson?: any; -}, { - geojson?: any; -}>; diff --git a/packages/validations/src/validations/osmValidator.js b/packages/validations/src/validations/osmValidator.js deleted file mode 100644 index b2789ae6b..000000000 --- a/packages/validations/src/validations/osmValidator.js +++ /dev/null @@ -1,27 +0,0 @@ -import { z } from 'zod'; -export const getOsm = z.object({ - activityType: z.string(), - startPoint: z.object({ latitude: z.number(), longitude: z.number() }), - endPoint: z.object({ latitude: z.number(), longitude: z.number() }), -}); -export const getParksOSM = z.object({ - lat: z.number(), - lon: z.number(), - radius: z.number().optional(), -}); -export const getPhotonDetails = z.object({ - id: z.union([z.string(), z.number()]), - type: z.string(), -}); -export const getPhotonResults = z.object({ - searchString: z.string(), -}); -export const getTrailsOSM = z.object({ - lat: z.number(), - lon: z.number(), - radius: z.number().optional(), -}); -export const postSingleGeoJSON = z.object({ - geojson: z.any(), -}); -//# sourceMappingURL=osmValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/osmValidator.js.map b/packages/validations/src/validations/osmValidator.js.map deleted file mode 100644 index 25330308f..000000000 --- a/packages/validations/src/validations/osmValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"osmValidator.js","sourceRoot":"","sources":["osmValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACrE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;CACpE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE;CACjB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/packRoutesValidator.d.ts b/packages/validations/src/validations/packRoutesValidator.d.ts deleted file mode 100644 index 7f88b979f..000000000 --- a/packages/validations/src/validations/packRoutesValidator.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { z } from 'zod'; -import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; -export declare const getPacks: z.ZodObject<{ - ownerId: z.ZodString; - queryBy: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - ownerId?: string; - queryBy?: string; -}, { - ownerId?: string; - queryBy?: string; -}>; -export declare const getPackById: z.ZodObject<{ - packId: z.ZodString; -}, "strip", z.ZodTypeAny, { - packId?: string; -}, { - packId?: string; -}>; -export declare const addPack: z.ZodObject<{ - name: z.ZodString; - owner_id: z.ZodString; - is_public: z.ZodBoolean; -}, "strip", z.ZodTypeAny, { - name?: string; - owner_id?: string; - is_public?: boolean; -}, { - name?: string; - owner_id?: string; - is_public?: boolean; -}>; -export declare const editPack: z.ZodObject<{ - id: z.ZodString; - name: z.ZodString; - is_public: z.ZodBoolean; -}, "strip", z.ZodTypeAny, { - id?: string; - name?: string; - is_public?: boolean; -}, { - id?: string; - name?: string; - is_public?: boolean; -}>; -export declare const deletePack: z.ZodObject<{ - packId: z.ZodString; -}, "strip", z.ZodTypeAny, { - packId?: string; -}, { - packId?: string; -}>; -export declare const getPublicPacks: z.ZodObject<{ - queryBy: z.ZodString; -}, "strip", z.ZodTypeAny, { - queryBy?: string; -}, { - queryBy?: string; -}>; -export declare const sendMessage: z.ZodObject<{ - message: z.ZodString; -}, "strip", z.ZodTypeAny, { - message?: string; -}, { - message?: string; -}>; -export declare const addPackSchema: z.ZodObject<{ - name: z.ZodString; - isPublic: z.ZodUnion<[z.ZodLiteral<"0">, z.ZodLiteral<"1">]>; -}, "strip", z.ZodTypeAny, { - name?: string; - isPublic?: "1" | "0"; -}, { - name?: string; - isPublic?: "1" | "0"; -}>; -export declare const duplicatePublicPack: z.ZodObject<{ - packId: z.ZodString; - ownerId: z.ZodString; - items: z.ZodArray; -}, "strip", z.ZodTypeAny, { - packId?: string; - ownerId?: string; - items?: string[]; -}, { - packId?: string; - ownerId?: string; - items?: string[]; -}>; -export declare const getSimilarPacks: z.ZodObject<{ - id: z.ZodString; - limit: z.ZodNumber; - visibility: z.ZodDefault>; -}, "strip", z.ZodTypeAny, { - id?: string; - limit?: number; - visibility?: PackAndItemVisibilityFilter; -}, { - id?: string; - limit?: number; - visibility?: PackAndItemVisibilityFilter; -}>; diff --git a/packages/validations/src/validations/packRoutesValidator.js b/packages/validations/src/validations/packRoutesValidator.js deleted file mode 100644 index 350616d53..000000000 --- a/packages/validations/src/validations/packRoutesValidator.js +++ /dev/null @@ -1,45 +0,0 @@ -import { z } from 'zod'; -import { PackAndItemVisibilityFilter } from '@packrat/shared-types'; -export const getPacks = z.object({ - ownerId: z.string(), - queryBy: z.string().optional(), -}); -export const getPackById = z.object({ - packId: z.string(), -}); -export const addPack = z.object({ - name: z.string(), - owner_id: z.string(), - is_public: z.boolean(), -}); -export const editPack = z.object({ - id: z.string(), - name: z.string(), - is_public: z.boolean(), -}); -export const deletePack = z.object({ - packId: z.string(), -}); -export const getPublicPacks = z.object({ - queryBy: z.string(), -}); -export const sendMessage = z.object({ - message: z.string().nonempty(), -}); -export const addPackSchema = z.object({ - name: z.string().nonempty(), - isPublic: z.union([z.literal('0'), z.literal('1')]), -}); -export const duplicatePublicPack = z.object({ - packId: z.string(), - ownerId: z.string(), - items: z.array(z.string()), -}); -export const getSimilarPacks = z.object({ - id: z.string(), - limit: z.number(), - visibility: z - .nativeEnum(PackAndItemVisibilityFilter) - .default(PackAndItemVisibilityFilter.ALL), -}); -//# sourceMappingURL=packRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/packRoutesValidator.js.map b/packages/validations/src/validations/packRoutesValidator.js.map deleted file mode 100644 index e5914b8bf..000000000 --- a/packages/validations/src/validations/packRoutesValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"packRoutesValidator.js","sourceRoot":"","sources":["packRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAEpE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,SAAS,EAAE,CAAC,CAAC,OA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AAE;IACd,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,UAAU,EAAE,CAAC;SACV,UAAU,CAAC,2BAA2B,CAAC;SACvC,OAAO,CAAC,2BAA2B,CAAC,GAAG,CAAC;CAC5C,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/parksRouteValidator.d.ts b/packages/validations/src/validations/parksRouteValidator.d.ts deleted file mode 100644 index 9b00234ac..000000000 --- a/packages/validations/src/validations/parksRouteValidator.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; -export declare const getParks: z.ZodObject<{ - abbrState: z.ZodString; -}, "strip", z.ZodTypeAny, { - abbrState?: string; -}, { - abbrState?: string; -}>; diff --git a/packages/validations/src/validations/parksRouteValidator.js b/packages/validations/src/validations/parksRouteValidator.js deleted file mode 100644 index 39653c5db..000000000 --- a/packages/validations/src/validations/parksRouteValidator.js +++ /dev/null @@ -1,5 +0,0 @@ -import { z } from 'zod'; -export const getParks = z.object({ - abbrState: z.string(), -}); -//# sourceMappingURL=parksRouteValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/parksRouteValidator.js.map b/packages/validations/src/validations/parksRouteValidator.js.map deleted file mode 100644 index be1d53e90..000000000 --- a/packages/validations/src/validations/parksRouteValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"parksRouteValidator.js","sourceRoot":"","sources":["parksRouteValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/roleValidator.d.ts b/packages/validations/src/validations/roleValidator.d.ts deleted file mode 100644 index 677fd86a6..000000000 --- a/packages/validations/src/validations/roleValidator.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { z } from 'zod'; -export declare const RoleSchema: z.ZodUnion<[z.ZodLiteral<"user">, z.ZodLiteral<"admin">]>; diff --git a/packages/validations/src/validations/roleValidator.js b/packages/validations/src/validations/roleValidator.js deleted file mode 100644 index a562e5a5b..000000000 --- a/packages/validations/src/validations/roleValidator.js +++ /dev/null @@ -1,3 +0,0 @@ -import { z } from 'zod'; -export const RoleSchema = z.union([z.literal('user'), z.literal('admin')]); -//# sourceMappingURL=roleValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/roleValidator.js.map b/packages/validations/src/validations/roleValidator.js.map deleted file mode 100644 index 4803e92dd..000000000 --- a/packages/validations/src/validations/roleValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"roleValidator.js","sourceRoot":"","sources":["roleValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/templateRouteValidator.d.ts b/packages/validations/src/validations/templateRouteValidator.d.ts deleted file mode 100644 index 4f49d1cfd..000000000 --- a/packages/validations/src/validations/templateRouteValidator.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { z } from 'zod'; -export declare const addTemplate: z.ZodObject<{ - type: z.ZodAny; - templateId: z.ZodString; - isGlobalTemplate: z.ZodBoolean; - createdBy: z.ZodString; -}, "strip", z.ZodTypeAny, { - type?: any; - templateId?: string; - isGlobalTemplate?: boolean; - createdBy?: string; -}, { - type?: any; - templateId?: string; - isGlobalTemplate?: boolean; - createdBy?: string; -}>; -export declare const editTemplate: z.ZodObject<{ - templateId: z.ZodString; - type: z.ZodString; - isGlobalTemplate: z.ZodBoolean; -}, "strip", z.ZodTypeAny, { - type?: string; - templateId?: string; - isGlobalTemplate?: boolean; -}, { - type?: string; - templateId?: string; - isGlobalTemplate?: boolean; -}>; -export declare const deleteTemplate: z.ZodObject<{ - templateId: z.ZodString; -}, "strip", z.ZodTypeAny, { - templateId?: string; -}, { - templateId?: string; -}>; -export declare const getTemplateById: z.ZodObject<{ - templateId: z.ZodString; -}, "strip", z.ZodTypeAny, { - templateId?: string; -}, { - templateId?: string; -}>; diff --git a/packages/validations/src/validations/templateRouteValidator.js b/packages/validations/src/validations/templateRouteValidator.js deleted file mode 100644 index 1ce85f1e5..000000000 --- a/packages/validations/src/validations/templateRouteValidator.js +++ /dev/null @@ -1,19 +0,0 @@ -import { z } from 'zod'; -export const addTemplate = z.object({ - type: z.any(), - templateId: z.string(), - isGlobalTemplate: z.boolean(), - createdBy: z.string(), -}); -export const editTemplate = z.object({ - templateId: z.string(), - type: z.string(), - isGlobalTemplate: z.boolean(), -}); -export const deleteTemplate = z.object({ - templateId: z.string(), -}); -export const getTemplateById = z.object({ - templateId: z.string(), -}); -//# sourceMappingURL=templateRouteValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/templateRouteValidator.js.map b/packages/validations/src/validations/templateRouteValidator.js.map deleted file mode 100644 index 9a37c8821..000000000 --- a/packages/validations/src/validations/templateRouteValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"templateRouteValidator.js","sourceRoot":"","sources":["templateRouteValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE;IACb,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE;IAC7B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/trailsRouteValidator.d.ts b/packages/validations/src/validations/trailsRouteValidator.d.ts deleted file mode 100644 index 413d17f4a..000000000 --- a/packages/validations/src/validations/trailsRouteValidator.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { z } from 'zod'; -export declare const getTrails: z.ZodObject<{ - administrative_area_level_1: z.ZodString; - country: z.ZodString; - locality: z.ZodString; - latitude: z.ZodNumber; - longitude: z.ZodNumber; -}, "strip", z.ZodTypeAny, { - latitude?: number; - longitude?: number; - administrative_area_level_1?: string; - country?: string; - locality?: string; -}, { - latitude?: number; - longitude?: number; - administrative_area_level_1?: string; - country?: string; - locality?: string; -}>; diff --git a/packages/validations/src/validations/trailsRouteValidator.js b/packages/validations/src/validations/trailsRouteValidator.js deleted file mode 100644 index ebf0f2e51..000000000 --- a/packages/validations/src/validations/trailsRouteValidator.js +++ /dev/null @@ -1,9 +0,0 @@ -import { z } from 'zod'; -export const getTrails = z.object({ - administrative_area_level_1: z.string(), - country: z.string(), - locality: z.string(), - latitude: z.number(), - longitude: z.number(), -}); -//# sourceMappingURL=trailsRouteValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/trailsRouteValidator.js.map b/packages/validations/src/validations/trailsRouteValidator.js.map deleted file mode 100644 index 8f09c54d9..000000000 --- a/packages/validations/src/validations/trailsRouteValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"trailsRouteValidator.js","sourceRoot":"","sources":["trailsRouteValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,2BAA2B,EAAE,CAAC,CAAC,MAAM,EAAE;IACvC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/enums.d.ts b/packages/validations/src/validations/tripRoutesValidator/enums.d.ts deleted file mode 100644 index aab2c9ed4..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/enums.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export declare enum TripActivity { - TRIP = "trip", - RUNNING = "running", - BIKING = "biking", - CAMPING = "camping", - FISHING = "fishing", - TREKKING = "trekking", - ROCK_CLIMBING = "rock-climbing", - HIKING = "hiking", - SWIMMING = "swimming" -} diff --git a/packages/validations/src/validations/tripRoutesValidator/enums.js b/packages/validations/src/validations/tripRoutesValidator/enums.js deleted file mode 100644 index bccf33a95..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/enums.js +++ /dev/null @@ -1,13 +0,0 @@ -export var TripActivity; -(function (TripActivity) { - TripActivity["TRIP"] = "trip"; - TripActivity["RUNNING"] = "running"; - TripActivity["BIKING"] = "biking"; - TripActivity["CAMPING"] = "camping"; - TripActivity["FISHING"] = "fishing"; - TripActivity["TREKKING"] = "trekking"; - TripActivity["ROCK_CLIMBING"] = "rock-climbing"; - TripActivity["HIKING"] = "hiking"; - TripActivity["SWIMMING"] = "swimming"; -})(TripActivity || (TripActivity = {})); -//# sourceMappingURL=enums.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/enums.js.map b/packages/validations/src/validations/tripRoutesValidator/enums.js.map deleted file mode 100644 index 98e05579d..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/enums.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"enums.js","sourceRoot":"","sources":["enums.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;IACrB,+CAA+B,CAAA;IAC/B,iCAAiB,CAAA;IACjB,qCAAqB,CAAA;AACvB,CAAC,EAVW,YAAY,KAAZ,YAAY,QAUvB"} \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/index.d.ts b/packages/validations/src/validations/tripRoutesValidator/index.d.ts deleted file mode 100644 index 8982e4e59..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './tripRoutesValidator'; -export * from './enums'; diff --git a/packages/validations/src/validations/tripRoutesValidator/index.js b/packages/validations/src/validations/tripRoutesValidator/index.js deleted file mode 100644 index 8c831362d..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export * from './tripRoutesValidator'; -export * from './enums'; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/index.js.map b/packages/validations/src/validations/tripRoutesValidator/index.js.map deleted file mode 100644 index f9a060e4c..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts deleted file mode 100644 index 8fbb7b641..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.d.ts +++ /dev/null @@ -1,422 +0,0 @@ -import { z } from 'zod'; -export declare const addTripForm: z.ZodObject<{ - name: z.ZodString; - description: z.ZodString; - is_public: z.ZodUnion<[z.ZodLiteral<"0">, z.ZodLiteral<"1">]>; -}, "strip", z.ZodTypeAny, { - name?: string; - is_public?: "1" | "0"; - description?: string; -}, { - name?: string; - is_public?: "1" | "0"; - description?: string; -}>; -export declare const getTrips: z.ZodObject<{ - owner_id: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - owner_id?: string; -}, { - owner_id?: string; -}>; -export declare const getTripById: z.ZodObject<{ - tripId: z.ZodString; -}, "strip", z.ZodTypeAny, { - tripId?: string; -}, { - tripId?: string; -}>; -export declare const addTripDetails: z.ZodObject<{ - duration: z.ZodString; - start_date: z.ZodString; - end_date: z.ZodString; - destination: z.ZodString; - type: z.ZodEnum<[string, ...string[]]>; - park: z.ZodOptional; - trail: z.ZodOptional; - geoJSON: z.ZodObject<{ - type: z.ZodLiteral<"FeatureCollection">; - features: z.ZodArray; - id: z.ZodString; - properties: z.ZodRecord>; - geometry: z.ZodUnion<[z.ZodObject<{ - type: z.ZodString; - coordinates: any; - }, "strip", z.ZodTypeAny, { - type?: string; - coordinates?: any; - }, { - type?: string; - coordinates?: any; - }>, z.ZodObject<{ - type: z.ZodLiteral<"GeometryCollection">; - geometries: z.ZodArray, "many">; - }, "strip", z.ZodTypeAny, { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }, { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }>]>; - }, "strip", z.ZodTypeAny, { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }, { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }>, "many">; - }, "strip", z.ZodTypeAny, { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }, { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }>; - owner_id: z.ZodString; - pack_id: z.ZodString; -}, "strip", z.ZodTypeAny, { - pack_id?: string; - owner_id?: string; - type?: string; - duration?: string; - start_date?: string; - end_date?: string; - destination?: string; - geoJSON?: { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }; - park?: string; - trail?: string; -}, { - pack_id?: string; - owner_id?: string; - type?: string; - duration?: string; - start_date?: string; - end_date?: string; - destination?: string; - geoJSON?: { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }; - park?: string; - trail?: string; -}>; -export declare const addTrip: z.ZodObject; - park: z.ZodOptional; - trail: z.ZodOptional; - geoJSON: z.ZodObject<{ - type: z.ZodLiteral<"FeatureCollection">; - features: z.ZodArray; - id: z.ZodString; - properties: z.ZodRecord>; - geometry: z.ZodUnion<[z.ZodObject<{ - type: z.ZodString; - coordinates: any; - }, "strip", z.ZodTypeAny, { - type?: string; - coordinates?: any; - }, { - type?: string; - coordinates?: any; - }>, z.ZodObject<{ - type: z.ZodLiteral<"GeometryCollection">; - geometries: z.ZodArray, "many">; - }, "strip", z.ZodTypeAny, { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }, { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }>]>; - }, "strip", z.ZodTypeAny, { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }, { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }>, "many">; - }, "strip", z.ZodTypeAny, { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }, { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }>; - owner_id: z.ZodString; - pack_id: z.ZodString; -}, { - name: z.ZodString; - description: z.ZodString; - is_public: z.ZodUnion<[z.ZodLiteral<"0">, z.ZodLiteral<"1">]>; -}>, "strip", z.ZodTypeAny, { - name?: string; - pack_id?: string; - owner_id?: string; - is_public?: "1" | "0"; - type?: string; - description?: string; - duration?: string; - start_date?: string; - end_date?: string; - destination?: string; - geoJSON?: { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }; - park?: string; - trail?: string; -}, { - name?: string; - pack_id?: string; - owner_id?: string; - is_public?: "1" | "0"; - type?: string; - description?: string; - duration?: string; - start_date?: string; - end_date?: string; - destination?: string; - geoJSON?: { - type?: "FeatureCollection"; - features?: { - id?: string; - type?: "Feature"; - properties?: Record; - geometry?: { - type?: string; - coordinates?: any; - } | { - type?: "GeometryCollection"; - geometries?: { - type?: string; - coordinates?: any; - }[]; - }; - }[]; - }; - park?: string; - trail?: string; -}>; -export declare const editTrip: z.ZodObject<{ - id: z.ZodString; - name: z.ZodOptional; - duration: z.ZodOptional; - start_date: z.ZodOptional; - end_date: z.ZodOptional; - destination: z.ZodOptional; - is_public: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - id?: string; - name?: string; - is_public?: boolean; - duration?: string; - start_date?: string; - end_date?: string; - destination?: string; -}, { - id?: string; - name?: string; - is_public?: boolean; - duration?: string; - start_date?: string; - end_date?: string; - destination?: string; -}>; -export declare const deleteTrip: z.ZodObject<{ - tripId: z.ZodString; -}, "strip", z.ZodTypeAny, { - tripId?: string; -}, { - tripId?: string; -}>; -export declare const queryTrip: z.ZodObject<{ - queryBy: z.ZodString; - tripId: z.ZodString; -}, "strip", z.ZodTypeAny, { - tripId?: string; - queryBy?: string; -}, { - tripId?: string; - queryBy?: string; -}>; diff --git a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js deleted file mode 100644 index 18e058e70..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js +++ /dev/null @@ -1,65 +0,0 @@ -import { z } from 'zod'; -import { TripActivity } from './enums'; -const tripActivityValues = Object.values(TripActivity); -export const addTripForm = z.object({ - name: z.string().nonempty(), - description: z.string().nonempty(), - is_public: z.union([z.literal('0'), z.literal('1')]), -}); -// @ts-ignore -const coordinateSchema = z.lazy(() => z.union([z.number(), z.array(coordinateSchema)])); -const baseGeometrySchema = z.object({ - type: z.string(), - coordinates: coordinateSchema, -}); -const geometryCollectionSchema = z.object({ - type: z.literal('GeometryCollection'), - geometries: z.array(baseGeometrySchema), -}); -const geometrySchema = z.union([baseGeometrySchema, geometryCollectionSchema]); -const featurePropertiesSchema = z.record(z.union([z.string(), z.number(), z.boolean()])); -const featureSchema = z.object({ - type: z.literal('Feature'), - id: z.string(), - properties: featurePropertiesSchema, - geometry: geometrySchema, -}); -export const getTrips = z.object({ - owner_id: z.string().optional(), -}); -export const getTripById = z.object({ - tripId: z.string(), -}); -export const addTripDetails = z.object({ - duration: z.string(), - start_date: z.string(), - end_date: z.string(), - destination: z.string(), - type: z.enum(tripActivityValues), - park: z.string().optional(), - trail: z.string().optional(), - geoJSON: z.object({ - type: z.literal('FeatureCollection'), - features: z.array(featureSchema), - }), - owner_id: z.string(), - pack_id: z.string(), -}); -export const addTrip = addTripDetails.merge(addTripForm); -export const editTrip = z.object({ - id: z.string(), - name: z.string().optional(), - duration: z.string().optional(), - start_date: z.string().optional(), - end_date: z.string().optional(), - destination: z.string().optional(), - is_public: z.boolean().optional(), -}); -export const deleteTrip = z.object({ - tripId: z.string().nonempty(), -}); -export const queryTrip = z.object({ - queryBy: z.string(), - tripId: z.string(), -}); -//# sourceMappingURL=tripRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map b/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map deleted file mode 100644 index 4d490a05a..000000000 --- a/packages/validations/src/validations/tripRoutesValidator/tripRoutesValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"tripRoutesValidator.js","sourceRoot":"","sources":["tripRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAA0B,CAAC;AAEhF,MAAM,CAAC,MAAM,W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AE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/userRoutesValidator.d.ts b/packages/validations/src/validations/userRoutesValidator.d.ts deleted file mode 100644 index 8a7796059..000000000 --- a/packages/validations/src/validations/userRoutesValidator.d.ts +++ /dev/null @@ -1,268 +0,0 @@ -import { z } from 'zod'; -export declare const userSignUp: z.ZodObject<{ - name: z.ZodString; - email: z.ZodEffects; - password: z.ZodEffects; - username: z.ZodString; -}, "strip", z.ZodTypeAny, { - name?: string; - password?: string; - email?: string; - username?: string; -}, { - name?: string; - password?: string; - email?: string; - username?: string; -}>; -export declare const userSignIn: z.ZodObject<{ - email: z.ZodEffects; - password: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - password?: string; - email?: string; -}, { - password?: string; - email?: string; -}>; -export declare const sentEmail: z.ZodObject<{ - email: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - email?: string; -}, { - email?: string; -}>; -export declare const resetPassword: z.ZodObject<{ - resetToken: z.ZodString; - password: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - password?: string; - resetToken?: string; -}, { - password?: string; - resetToken?: string; -}>; -export declare const getFirebaseUserByEmail: z.ZodObject<{ - email: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - email?: string; -}, { - email?: string; -}>; -export declare const checkCode: z.ZodObject<{ - email: z.ZodEffects; - code: z.ZodString; -}, "strip", z.ZodTypeAny, { - email?: string; - code?: string; -}, { - email?: string; - code?: string; -}>; -export declare const emailExists: z.ZodObject<{ - email: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - email?: string; -}, { - email?: string; -}>; -export declare const getUserById: z.ZodObject<{ - userId: z.ZodString; -}, "strip", z.ZodTypeAny, { - userId?: string; -}, { - userId?: string; -}>; -export declare const addToFavorite: z.ZodObject<{ - packId: z.ZodString; - userId: z.ZodString; -}, "strip", z.ZodTypeAny, { - userId?: string; - packId?: string; -}, { - userId?: string; - packId?: string; -}>; -export declare const editUser: z.ZodObject<{ - id: z.ZodString; - name: z.ZodOptional; - password: z.ZodOptional>; - email: z.ZodOptional; - code: z.ZodOptional; - role: z.ZodOptional>; - username: z.ZodOptional; - offlineMaps: z.ZodNullable; - bounds: z.ZodArray, "many">; - minZoom: z.ZodNumber; - maxZoom: z.ZodNumber; - }, "strip", z.ZodTypeAny, { - metadata?: { - shape?: string; - }; - name?: string; - styleURL?: string; - bounds?: number[][]; - minZoom?: number; - maxZoom?: number; - }, { - metadata?: { - shape?: string; - }; - name?: string; - styleURL?: string; - bounds?: number[][]; - minZoom?: number; - maxZoom?: number; - }>>>>; - profileImage: z.ZodNullable>; - preferredWeather: z.ZodOptional; - preferredWeight: z.ZodOptional; -}, "strip", z.ZodTypeAny, { - id?: string; - name?: string; - password?: string; - email?: string; - code?: string; - offlineMaps?: Record; - role?: "user" | "admin"; - username?: string; - profileImage?: string; - preferredWeather?: string; - preferredWeight?: string; -}, { - id?: string; - name?: string; - password?: string; - email?: string; - code?: string; - offlineMaps?: Record; - role?: "user" | "admin"; - username?: string; - profileImage?: string; - preferredWeather?: string; - preferredWeight?: string; -}>; -export declare const deleteUser: z.ZodObject<{ - userId: z.ZodString; -}, "strip", z.ZodTypeAny, { - userId?: string; -}, { - userId?: string; -}>; -export declare const deleteUserForm: z.ZodObject<{ - confirmText: z.ZodLiteral<"delete">; -}, "strip", z.ZodTypeAny, { - confirmText?: "delete"; -}, { - confirmText?: "delete"; -}>; -export declare const linkFirebaseAuth: z.ZodObject<{ - firebaseAuthToken: z.ZodString; -}, "strip", z.ZodTypeAny, { - firebaseAuthToken?: string; -}, { - firebaseAuthToken?: string; -}>; -export declare const createMongoDBUser: z.ZodObject<{ - email: z.ZodString; - name: z.ZodString; - password: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - name?: string; - password?: string; - email?: string; -}, { - name?: string; - password?: string; - email?: string; -}>; -export declare const login: z.ZodObject<{ - email: z.ZodString; - password: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - password?: string; - email?: string; -}, { - password?: string; - email?: string; -}>; -export declare const updatePassword: z.ZodObject<{ - email: z.ZodEffects; - password: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - password?: string; - email?: string; -}, { - password?: string; - email?: string; -}>; -export declare const userSettingsSchema: z.ZodObject<{ - name: z.ZodString; - email: z.ZodEffects; - username: z.ZodString; - profileImage: z.ZodOptional; - preferredWeather: z.ZodUnion<[z.ZodLiteral<"celsius">, z.ZodLiteral<"fahrenheit">]>; - preferredWeight: z.ZodUnion<[z.ZodLiteral<"lb">, z.ZodLiteral<"oz">, z.ZodLiteral<"kg">, z.ZodLiteral<"g">]>; -}, "strip", z.ZodTypeAny, { - name?: string; - email?: string; - username?: string; - profileImage?: string; - preferredWeather?: "celsius" | "fahrenheit"; - preferredWeight?: "lb" | "g" | "kg" | "oz"; -}, { - name?: string; - email?: string; - username?: string; - profileImage?: string; - preferredWeather?: "celsius" | "fahrenheit"; - preferredWeight?: "lb" | "g" | "kg" | "oz"; -}>; -export declare const passwordChangeSchema: z.ZodEffects; - newPassword: z.ZodEffects; - confirmPassword: z.ZodEffects; -}, "strip", z.ZodTypeAny, { - oldPassword?: string; - newPassword?: string; - confirmPassword?: string; -}, { - oldPassword?: string; - newPassword?: string; - confirmPassword?: string; -}>, { - oldPassword?: string; - newPassword?: string; - confirmPassword?: string; -}, { - oldPassword?: string; - newPassword?: string; - confirmPassword?: string; -}>; diff --git a/packages/validations/src/validations/userRoutesValidator.js b/packages/validations/src/validations/userRoutesValidator.js deleted file mode 100644 index 62336fd0e..000000000 --- a/packages/validations/src/validations/userRoutesValidator.js +++ /dev/null @@ -1,116 +0,0 @@ -import { z } from 'zod'; -const emailValidator = z - .string({ required_error: 'Email is required' }) - .email() - .transform((str) => str.trim().toLowerCase()); -const passwordValidator = z - .string({ required_error: 'Password is required' }) - .min(7) - .refine((str) => !str.includes('password'), { - message: `The password cannot contain the word 'password'`, -}); -export const userSignUp = z.object({ - name: z.string().min(1).nonempty(), - email: emailValidator, - password: passwordValidator, - username: z.string().nonempty(), -}); -export const userSignIn = z.object({ - email: emailValidator, - password: passwordValidator, -}); -export const sentEmail = z.object({ - email: emailValidator, -}); -export const resetPassword = z.object({ - resetToken: z.string().nonempty(), - password: passwordValidator, -}); -export const getFirebaseUserByEmail = z.object({ - email: emailValidator, -}); -export const checkCode = z.object({ - email: emailValidator, - code: z.string().nonempty(), -}); -export const emailExists = z.object({ - email: emailValidator, -}); -export const getUserById = z.object({ - userId: z.string().nonempty(), -}); -export const addToFavorite = z.object({ - packId: z.string(), - userId: z.string(), -}); -export const editUser = z.object({ - id: z.string(), - name: z.string().optional(), - password: passwordValidator.optional(), - email: z.string().optional(), - code: z.string().optional(), - role: z.enum(['user', 'admin']).optional(), - username: z.string().optional(), - offlineMaps: z - .record(z.string(), z.object({ - name: z.string(), - styleURL: z.string(), - metadata: z.object({ - shape: z.string(), - }), - bounds: z.array(z.array(z.number())), - minZoom: z.number(), - maxZoom: z.number(), - })) - .optional() - .nullable(), - profileImage: z.string().optional().nullable(), - preferredWeather: z.string().optional(), - preferredWeight: z.string().optional(), -}); -export const deleteUser = z.object({ - userId: z.string(), -}); -export const deleteUserForm = z.object({ - confirmText: z.literal('delete'), -}); -export const linkFirebaseAuth = z.object({ - firebaseAuthToken: z.string(), -}); -export const createMongoDBUser = z.object({ - email: z.string().email(), - name: z.string().min(1), - password: passwordValidator, -}); -export const login = z.object({ - email: z.string().email(), - password: passwordValidator, -}); -export const updatePassword = z.object({ - email: emailValidator, - password: passwordValidator, -}); -export const userSettingsSchema = z.object({ - name: z.string().min(1).nonempty(), - email: emailValidator, - username: z.string().nonempty(), - profileImage: z.string().optional(), - preferredWeather: z.union([z.literal('celsius'), z.literal('fahrenheit')]), - preferredWeight: z.union([ - z.literal('lb'), - z.literal('oz'), - z.literal('kg'), - z.literal('g'), - ]), -}); -export const passwordChangeSchema = z - .object({ - oldPassword: passwordValidator, - newPassword: passwordValidator, - confirmPassword: passwordValidator, -}) - .refine((data) => data.newPassword === data.confirmPassword, { - message: 'New password and confirmation must match', - path: ['confirmPassword'], // This will attach the error to `passwordConfirm` field -}); -//# sourceMappingURL=userRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/userRoutesValidator.js.map b/packages/validations/src/validations/userRoutesValidator.js.map deleted file mode 100644 index 1f4385a08..000000000 --- a/packages/validations/src/validations/userRoutesValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"userRoutesValidator.js","sourceRoot":"","sources":["userRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC,EAAE,cAAc,EAAE,mBAAmB,EAAE,CAAC;KAC/C,KAAK,EAAE;KACP,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,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GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAClC,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,gBAAgB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IAC1E,eAAe,EAAE,CAAC,CAAC,KAAK,CAAC;QACvB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACf,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACf,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACf,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;KACf,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EAAE,iBAAiB;IAC9B,eAAe,EAAE,iBAAiB;CACnC,CAAC;KACD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,eAAe,EAAE;IAC3D,OAAO,EAAE,0CAA0C;IACnD,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,wDAAwD;CACpF,CAAC,CAAC"} \ No newline at end of file diff --git a/packages/validations/src/validations/weatherRoutesValidator.d.ts b/packages/validations/src/validations/weatherRoutesValidator.d.ts deleted file mode 100644 index 47ac66b67..000000000 --- a/packages/validations/src/validations/weatherRoutesValidator.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { z } from 'zod'; -export declare const getWeatherWeek: z.ZodObject<{ - lat: z.ZodNumber; - lon: z.ZodNumber; -}, "strip", z.ZodTypeAny, { - lat?: number; - lon?: number; -}, { - lat?: number; - lon?: number; -}>; -export declare const getWeather: z.ZodObject<{ - lat: z.ZodNumber; - lon: z.ZodNumber; -}, "strip", z.ZodTypeAny, { - lat?: number; - lon?: number; -}, { - lat?: number; - lon?: number; -}>; diff --git a/packages/validations/src/validations/weatherRoutesValidator.js b/packages/validations/src/validations/weatherRoutesValidator.js deleted file mode 100644 index 975be056b..000000000 --- a/packages/validations/src/validations/weatherRoutesValidator.js +++ /dev/null @@ -1,10 +0,0 @@ -import { z } from 'zod'; -export const getWeatherWeek = z.object({ - lat: z.number(), - lon: z.number(), -}); -export const getWeather = z.object({ - lat: z.number(), - lon: z.number(), -}); -//# sourceMappingURL=weatherRoutesValidator.js.map \ No newline at end of file diff --git a/packages/validations/src/validations/weatherRoutesValidator.js.map b/packages/validations/src/validations/weatherRoutesValidator.js.map deleted file mode 100644 index b2fd13f39..000000000 --- a/packages/validations/src/validations/weatherRoutesValidator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"weatherRoutesValidator.js","sourceRoot":"","sources":["weatherRoutesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC"} \ No newline at end of file From 55bc9d1934927ec17bdc3ca7e0f64786a692fb4a Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Thu, 15 Aug 2024 09:20:41 +0300 Subject: [PATCH 09/10] cleanup --- apps/vite/src/routeTree.gen.ts | 177 +--------- .../src/controllers/item/importFromBucket.ts | 314 +++--------------- .../services/item/importFromBucketService.ts | 175 ++++++++++ server/src/services/item/item.service.ts | 1 + 4 files changed, 227 insertions(+), 440 deletions(-) create mode 100644 server/src/services/item/importFromBucketService.ts diff --git a/apps/vite/src/routeTree.gen.ts b/apps/vite/src/routeTree.gen.ts index 8e9dfcd1e..968fb50c5 100644 --- a/apps/vite/src/routeTree.gen.ts +++ b/apps/vite/src/routeTree.gen.ts @@ -174,163 +174,94 @@ const ProfileSettingsIndexLazyRoute = ProfileSettingsIndexLazyImport.update({ declare module '@tanstack/react-router' { interface FileRoutesByPath { '/': { - id: '/' - path: '/' - fullPath: '/' preLoaderRoute: typeof IndexImport parentRoute: typeof rootRoute } '/destination/query': { - id: '/destination/query' - path: '/destination/query' - fullPath: '/destination/query' preLoaderRoute: typeof DestinationQueryLazyImport parentRoute: typeof rootRoute } '/item/$itemId': { - id: '/item/$itemId' - path: '/item/$itemId' - fullPath: '/item/$itemId' preLoaderRoute: typeof ItemItemIdLazyImport parentRoute: typeof rootRoute } '/pack/$id': { - id: '/pack/$id' - path: '/pack/$id' - fullPath: '/pack/$id' preLoaderRoute: typeof PackIdLazyImport parentRoute: typeof rootRoute } '/pack/create': { - id: '/pack/create' - path: '/pack/create' - fullPath: '/pack/create' preLoaderRoute: typeof PackCreateLazyImport parentRoute: typeof rootRoute } '/profile/$id': { - id: '/profile/$id' - path: '/profile/$id' - fullPath: '/profile/$id' preLoaderRoute: typeof ProfileIdLazyImport parentRoute: typeof rootRoute } '/trip/$tripId': { - id: '/trip/$tripId' - path: '/trip/$tripId' - fullPath: '/trip/$tripId' preLoaderRoute: typeof TripTripIdLazyImport parentRoute: typeof rootRoute } '/trip/create': { - id: '/trip/create' - path: '/trip/create' - fullPath: '/trip/create' preLoaderRoute: typeof TripCreateLazyImport parentRoute: typeof rootRoute } '/about/': { - id: '/about/' - path: '/about' - fullPath: '/about' preLoaderRoute: typeof AboutIndexLazyImport parentRoute: typeof rootRoute } '/appearance/': { - id: '/appearance/' - path: '/appearance' - fullPath: '/appearance' preLoaderRoute: typeof AppearanceIndexLazyImport parentRoute: typeof rootRoute } '/dashboard/': { - id: '/dashboard/' - path: '/dashboard' - fullPath: '/dashboard' preLoaderRoute: typeof DashboardIndexLazyImport parentRoute: typeof rootRoute } '/feed/': { - id: '/feed/' - path: '/feed' - fullPath: '/feed' preLoaderRoute: typeof FeedIndexLazyImport parentRoute: typeof rootRoute } '/items/': { - id: '/items/' - path: '/items' - fullPath: '/items' preLoaderRoute: typeof ItemsIndexLazyImport parentRoute: typeof rootRoute } '/map/': { - id: '/map/' - path: '/map' - fullPath: '/map' preLoaderRoute: typeof MapIndexLazyImport parentRoute: typeof rootRoute } '/maps/': { - id: '/maps/' - path: '/maps' - fullPath: '/maps' preLoaderRoute: typeof MapsIndexLazyImport parentRoute: typeof rootRoute } '/packs/': { - id: '/packs/' - path: '/packs' - fullPath: '/packs' preLoaderRoute: typeof PacksIndexLazyImport parentRoute: typeof rootRoute } '/password-reset/': { - id: '/password-reset/' - path: '/password-reset' - fullPath: '/password-reset' preLoaderRoute: typeof PasswordResetIndexLazyImport parentRoute: typeof rootRoute } '/privacy/': { - id: '/privacy/' - path: '/privacy' - fullPath: '/privacy' preLoaderRoute: typeof PrivacyIndexLazyImport parentRoute: typeof rootRoute } '/profile/': { - id: '/profile/' - path: '/profile' - fullPath: '/profile' preLoaderRoute: typeof ProfileIndexLazyImport parentRoute: typeof rootRoute } '/register/': { - id: '/register/' - path: '/register' - fullPath: '/register' preLoaderRoute: typeof RegisterIndexLazyImport parentRoute: typeof rootRoute } '/sign-in/': { - id: '/sign-in/' - path: '/sign-in' - fullPath: '/sign-in' preLoaderRoute: typeof SignInIndexLazyImport parentRoute: typeof rootRoute } '/trips/': { - id: '/trips/' - path: '/trips' - fullPath: '/trips' preLoaderRoute: typeof TripsIndexLazyImport parentRoute: typeof rootRoute } '/profile/settings/': { - id: '/profile/settings/' - path: '/profile/settings' - fullPath: '/profile/settings' preLoaderRoute: typeof ProfileSettingsIndexLazyImport parentRoute: typeof rootRoute } @@ -339,7 +270,7 @@ declare module '@tanstack/react-router' { // Create and export the route tree -export const routeTree = rootRoute.addChildren({ +export const routeTree = rootRoute.addChildren([ IndexRoute, DestinationQueryLazyRoute, ItemItemIdLazyRoute, @@ -363,110 +294,6 @@ export const routeTree = rootRoute.addChildren({ SignInIndexLazyRoute, TripsIndexLazyRoute, ProfileSettingsIndexLazyRoute, -}) +]) /* prettier-ignore-end */ - -/* ROUTE_MANIFEST_START -{ - "routes": { - "__root__": { - "filePath": "__root.tsx", - "children": [ - "/", - "/destination/query", - "/item/$itemId", - "/pack/$id", - "/pack/create", - "/profile/$id", - "/trip/$tripId", - "/trip/create", - "/about/", - "/appearance/", - "/dashboard/", - "/feed/", - "/items/", - "/map/", - "/maps/", - "/packs/", - "/password-reset/", - "/privacy/", - "/profile/", - "/register/", - "/sign-in/", - "/trips/", - "/profile/settings/" - ] - }, - "/": { - "filePath": "index.tsx" - }, - "/destination/query": { - "filePath": "destination/query.lazy.tsx" - }, - "/item/$itemId": { - "filePath": "item/$itemId.lazy.tsx" - }, - "/pack/$id": { - "filePath": "pack/$id.lazy.tsx" - }, - "/pack/create": { - "filePath": "pack/create.lazy.tsx" - }, - "/profile/$id": { - "filePath": "profile/$id.lazy.tsx" - }, - "/trip/$tripId": { - "filePath": "trip/$tripId.lazy.tsx" - }, - "/trip/create": { - "filePath": "trip/create.lazy.tsx" - }, - "/about/": { - "filePath": "about/index.lazy.tsx" - }, - "/appearance/": { - "filePath": "appearance/index.lazy.tsx" - }, - "/dashboard/": { - "filePath": "dashboard/index.lazy.tsx" - }, - "/feed/": { - "filePath": "feed/index.lazy.tsx" - }, - "/items/": { - "filePath": "items/index.lazy.tsx" - }, - "/map/": { - "filePath": "map/index.lazy.tsx" - }, - "/maps/": { - "filePath": "maps/index.lazy.tsx" - }, - "/packs/": { - "filePath": "packs/index.lazy.tsx" - }, - "/password-reset/": { - "filePath": "password-reset/index.lazy.tsx" - }, - "/privacy/": { - "filePath": "privacy/index.lazy.tsx" - }, - "/profile/": { - "filePath": "profile/index.lazy.tsx" - }, - "/register/": { - "filePath": "register/index.lazy.tsx" - }, - "/sign-in/": { - "filePath": "sign-in/index.lazy.tsx" - }, - "/trips/": { - "filePath": "trips/index.lazy.tsx" - }, - "/profile/settings/": { - "filePath": "profile/settings/index.lazy.tsx" - } - } -} -ROUTE_MANIFEST_END */ diff --git a/server/src/controllers/item/importFromBucket.ts b/server/src/controllers/item/importFromBucket.ts index 748d401d8..30a4a9a33 100644 --- a/server/src/controllers/item/importFromBucket.ts +++ b/server/src/controllers/item/importFromBucket.ts @@ -1,71 +1,12 @@ import { protectedProcedure } from '../../trpc'; -import { bulkAddItemsGlobalService } from '../../services/item/item.service'; -import * as CryptoJS from 'crypto-js'; -import { parseStringPromise } from 'xml2js'; -import Papa from 'papaparse'; +import { + bulkAddItemsGlobalService, + parseCSVData, + listBucketContents, + fetchFromS3, +} from '../../services/item/item.service'; import { z } from 'zod'; -interface CSVType { - name: string; - claimed_weight: number; - quantity: number; - claimed_weight_unit: string; - type: string; - ownerId: string; -} - -function getSignatureKey(key, dateStamp, regionName, serviceName) { - const kDate = CryptoJS.HmacSHA256(dateStamp, 'AWS4' + key); - const kRegion = CryptoJS.HmacSHA256(regionName, kDate); - const kService = CryptoJS.HmacSHA256(serviceName, kRegion); - const kSigning = CryptoJS.HmacSHA256('aws4_request', kService); - return kSigning; -} - -function generateAWSHeaders( - url, - method, - service, - region, - accessKey, - secretKey, - sessionToken, - algorithm, - x_amz_token, -) { - const amzDate = new Date() - .toISOString() - .replace(/[:-]/g, '') - .replace(/\.\d{3}/, ''); - const dateStamp = amzDate.slice(0, 8); - const canonicalUri = new URL(url).pathname; - const canonicalQueryString = ''; - const payloadHash = CryptoJS.SHA256('').toString(CryptoJS.enc.Hex); - const canonicalHeaders = - `host:${new URL(url).hostname}\nx-amz-date:${amzDate}\n` + - (sessionToken ? `x-amz-security-token:${sessionToken}\n` : ''); - const signedHeaders = - 'host;x-amz-date' + (sessionToken ? `;${x_amz_token}` : ''); - const canonicalRequest = `${method}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; - - const credentialScope = `${dateStamp}/${region}/${service}/aws4_request`; - const stringToSign = `${algorithm}\n${amzDate}\n${credentialScope}\n${CryptoJS.SHA256(canonicalRequest).toString(CryptoJS.enc.Hex)}`; - - const signingKey = getSignatureKey(secretKey, dateStamp, region, service); - const signature = CryptoJS.HmacSHA256(stringToSign, signingKey).toString( - CryptoJS.enc.Hex, - ); - const authorizationHeader = `${algorithm} Credential=${accessKey}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`; - - return { - host: new URL(url).hostname, - 'x-amz-date': amzDate, - 'x-amz-content-sha256': payloadHash, - Authorization: authorizationHeader, - ...(sessionToken && { 'x-amz-security-token': sessionToken }), - }; -} - export const importFromBucket = async (c) => { const { directory, ownerId } = await c.req.query(); @@ -80,45 +21,26 @@ export const importFromBucket = async (c) => { const algorithm = c.env.AWS_SIGN_ALGORITHM; const x_amz_token = c.env.X_AMZ_SECURITY_TOKEN; - // Generate AWS Headers for listing bucket contents - const listHeaders = generateAWSHeaders( - endpoint + '/' + bucket, - method, - service, - region, - accessKeyId, - secretKey, - sessionToken, - algorithm, - x_amz_token, - ); - try { - // Fetch data from bucket to list contents - const listResponse = await fetch(`${endpoint}/${bucket}`, { + const latestFileName = await listBucketContents( + endpoint, + bucket, + directory, method, - headers: listHeaders, - }); - const listData = await listResponse.text(); - - // Parse XML response - const parsedListData = await parseStringPromise(listData); - const contents = parsedListData.ListBucketResult.Contents; - - // Extract and log file names - const fileNames = contents - .filter((item) => item.Key[0].startsWith(`${directory}/`)) - .map((item) => item.Key[0]); - - // Sort file names to get the latest one - const latestFileName = fileNames.sort().reverse()[0]; + service, + region, + accessKeyId, + secretKey, + sessionToken, + algorithm, + x_amz_token, + ); if (!latestFileName) { throw new Error('No files found in the backcountry directory'); } - // Generate AWS Headers for fetching the latest file - const fileHeaders = generateAWSHeaders( + const fileData = await fetchFromS3( `${endpoint}/${bucket}/${latestFileName}`, method, service, @@ -130,63 +52,12 @@ export const importFromBucket = async (c) => { x_amz_token, ); - // Fetch the specific CSV file - const fileResponse = await fetch( - `${endpoint}/${bucket}/${latestFileName}`, - { - method, - headers: fileHeaders, - }, - ); - const fileData = await fileResponse.text(); - - // Check for errors in the file response - if (fileResponse.status !== 200) { - console.error('Error fetching file:', fileData); - return c.json({ error: 'Error fetching file', details: fileData }); - } - - const itemsToInsert = []; - - await new Promise((resolve, reject) => { - Papa.parse(fileData, { - header: true, - complete: (results) => { - try { - for (const [index, item] of results.data.entries()) { - if ( - index === results.data.length - 1 && - Object.values(item).every((value) => value === '') - ) { - continue; - } - - itemsToInsert.push({ - name: item.name, - weight: item.claimed_weight || 0, - quantity: item.quantity || 1, - unit: item.claimed_weight_unit || 'g', - type: 'Essentials', - ownerId, - }); - } - resolve(null); - } catch (error) { - console.error('Error processing CSV data:', error); - reject(error); - } - }, - error: (error) => { - console.error('Error parsing CSV file:', error); - reject(error); - }, - }); - }); - + const itemsToInsert = await parseCSVData(fileData, ownerId); const insertedItems = await bulkAddItemsGlobalService( itemsToInsert, c.executionCtx, ); + return c.json({ message: 'Items inserted successfully', data: insertedItems, @@ -204,131 +75,44 @@ export function importFromBucketRoute() { const { directory, ownerId } = opts.input; const { env, executionCtx }: any = opts.ctx; - const endpoint = env.BUCKET_ENDPOINT; - const bucket = env.BUCKET_NAME; - const method = 'GET'; - const region = env.BUCKET_REGION; - const service = env.BUCKET_SERVICE; - const accessKeyId = env.BUCKET_ACCESS_KEY_ID; - const secretKey = env.BUCKET_SECRET_KEY; - const sessionToken = env.BUCKET_SESSION_TOKEN; - const algorithm = env.AWS_SIGN_ALGORITHM; - const x_amz_token = env.X_AMZ_SECURITY_TOKEN; - - // Generate AWS Headers for listing bucket contents - const listHeaders = generateAWSHeaders( - `${endpoint}/${bucket}`, - method, - service, - region, - accessKeyId, - secretKey, - sessionToken, - algorithm, - x_amz_token, - ); - try { - const listResponse = await fetch(`${endpoint}/${bucket}`, { - method, - headers: listHeaders, - }); - - if (!listResponse.ok) { - throw new Error('Failed to list bucket contents'); - } - - const listData = await listResponse.text(); - - // Parse XML response - const parsedListData = await parseStringPromise(listData); - const contents = parsedListData.ListBucketResult.Contents; - - // Extract and log file names - const fileNames = contents - .filter((item) => item.Key[0].startsWith(`${directory}/`)) - .map((item) => item.Key[0]); - - // Sort file names to get the latest one - const latestFileName = fileNames.sort().reverse()[0]; + const latestFileName = await listBucketContents( + env.BUCKET_ENDPOINT, + env.BUCKET_NAME, + directory, + 'GET', + env.BUCKET_SERVICE, + env.BUCKET_REGION, + env.BUCKET_ACCESS_KEY_ID, + env.BUCKET_SECRET_KEY, + env.BUCKET_SESSION_TOKEN, + env.AWS_SIGN_ALGORITHM, + env.X_AMZ_SECURITY_TOKEN, + ); if (!latestFileName) { throw new Error('No files found in the directory'); } - // Generate AWS Headers for fetching the latest file - const fileHeaders = generateAWSHeaders( - `${endpoint}/${bucket}/${latestFileName}`, - method, - service, - region, - accessKeyId, - secretKey, - sessionToken, - algorithm, - x_amz_token, + const fileData = await fetchFromS3( + `${env.BUCKET_ENDPOINT}/${env.BUCKET_NAME}/${latestFileName}`, + 'GET', + env.BUCKET_SERVICE, + env.BUCKET_REGION, + env.BUCKET_ACCESS_KEY_ID, + env.BUCKET_SECRET_KEY, + env.BUCKET_SESSION_TOKEN, + env.AWS_SIGN_ALGORITHM, + env.X_AMZ_SECURITY_TOKEN, ); - // Fetch the specific CSV file - const fileResponse = await fetch( - `${endpoint}/${bucket}/${latestFileName}`, - { - method, - headers: fileHeaders, - }, + const itemsToInsert = await parseCSVData(fileData, ownerId); + const insertedItems = await bulkAddItemsGlobalService( + itemsToInsert, + executionCtx, ); - if (!fileResponse.ok) { - throw new Error('Failed to fetch the latest file'); - } - - const fileData = await fileResponse.text(); - - return new Promise((resolve, reject) => { - Papa.parse(fileData, { - header: true, - complete: async function (results) { - try { - const itemsToInsert = []; - - for (const [index, item] of results.data.entries()) { - if ( - index === results.data.length - 1 && - Object.values(item).every((value) => value === '') - ) { - continue; - } - - itemsToInsert.push({ - name: item.name, - weight: item.claimed_weight || 0, - quantity: item.quantity || 1, - unit: item.claimed_weight_unit || 'g', - type: 'Essentials', - ownerId, - }); - } - - const insertedItems = await bulkAddItemsGlobalService( - itemsToInsert, - executionCtx, - ); - - return resolve(insertedItems); - } catch (error) { - console.error('Error in bulkAddItemsGlobalService:', error); - - return reject( - new Error(`Failed to add items: ${error.message}`), - ); - } - }, - error: function (error) { - console.error('Error parsing CSV file:', error); - reject(error); - }, - }); - }); + return insertedItems; } catch (err) { console.error('Error:', err); throw new Error(`An error occurred: ${err.message}`); diff --git a/server/src/services/item/importFromBucketService.ts b/server/src/services/item/importFromBucketService.ts new file mode 100644 index 000000000..e911bb880 --- /dev/null +++ b/server/src/services/item/importFromBucketService.ts @@ -0,0 +1,175 @@ +import * as CryptoJS from 'crypto-js'; +import { parseStringPromise } from 'xml2js'; +import Papa from 'papaparse'; + +interface CSVType { + name: string; + claimed_weight: number; + quantity: number; + claimed_weight_unit: string; + type: string; + ownerId: string; +} + +function getSignatureKey( + key: string, + dateStamp: string, + regionName: string, + serviceName: string, +) { + const kDate = CryptoJS.HmacSHA256(dateStamp, 'AWS4' + key); + const kRegion = CryptoJS.HmacSHA256(regionName, kDate); + const kService = CryptoJS.HmacSHA256(serviceName, kRegion); + const kSigning = CryptoJS.HmacSHA256('aws4_request', kService); + return kSigning; +} + +function generateAWSHeaders( + url: string, + method: string, + service: string, + region: string, + accessKey: string, + secretKey: string, + sessionToken: string, + algorithm: string, + x_amz_token: string, +) { + const amzDate = new Date() + .toISOString() + .replace(/[:-]/g, '') + .replace(/\.\d{3}/, ''); + const dateStamp = amzDate.slice(0, 8); + const canonicalUri = new URL(url).pathname; + const canonicalQueryString = ''; + const payloadHash = CryptoJS.SHA256('').toString(CryptoJS.enc.Hex); + const canonicalHeaders = + `host:${new URL(url).hostname}\nx-amz-date:${amzDate}\n` + + (sessionToken ? `x-amz-security-token:${sessionToken}\n` : ''); + const signedHeaders = + 'host;x-amz-date' + (sessionToken ? `;${x_amz_token}` : ''); + const canonicalRequest = `${method}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; + + const credentialScope = `${dateStamp}/${region}/${service}/aws4_request`; + const stringToSign = `${algorithm}\n${amzDate}\n${credentialScope}\n${CryptoJS.SHA256(canonicalRequest).toString(CryptoJS.enc.Hex)}`; + + const signingKey = getSignatureKey(secretKey, dateStamp, region, service); + const signature = CryptoJS.HmacSHA256(stringToSign, signingKey).toString( + CryptoJS.enc.Hex, + ); + const authorizationHeader = `${algorithm} Credential=${accessKey}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`; + + return { + host: new URL(url).hostname, + 'x-amz-date': amzDate, + 'x-amz-content-sha256': payloadHash, + Authorization: authorizationHeader, + ...(sessionToken && { 'x-amz-security-token': sessionToken }), + }; +} + +export async function fetchFromS3( + url: string, + method: string, + service: string, + region: string, + accessKey: string, + secretKey: string, + sessionToken: string, + algorithm: string, + x_amz_token: string, +) { + const headers = generateAWSHeaders( + url, + method, + service, + region, + accessKey, + secretKey, + sessionToken, + algorithm, + x_amz_token, + ); + + const response = await fetch(url, { + method, + headers, + }); + + if (!response.ok) { + throw new Error(`Failed to fetch from S3: ${response.statusText}`); + } + + const data = await response.text(); + return data; +} + +export async function listBucketContents( + endpoint: string, + bucket: string, + directory: string, + method: string, + service: string, + region: string, + accessKey: string, + secretKey: string, + sessionToken: string, + algorithm: string, + x_amz_token: string, +) { + const listData = await fetchFromS3( + `${endpoint}/${bucket}`, + method, + service, + region, + accessKey, + secretKey, + sessionToken, + algorithm, + x_amz_token, + ); + + const parsedListData = await parseStringPromise(listData); + const contents = parsedListData.ListBucketResult.Contents; + + const fileNames = contents + .filter((item) => item.Key[0].startsWith(`${directory}/`)) + .map((item) => item.Key[0]); + + return fileNames.sort().reverse()[0]; // Get the latest file name +} + +export async function parseCSVData(fileData: string, ownerId: string) { + return new Promise((resolve, reject) => { + const itemsToInsert: CSVType[] = []; + + Papa.parse(fileData, { + header: true, + complete: (results) => { + try { + for (const [index, item] of results.data.entries()) { + if ( + index === results.data.length - 1 && + Object.values(item).every((value) => value === '') + ) { + continue; + } + + itemsToInsert.push({ + name: item.name, + claimed_weight: item.claimed_weight || 0, + quantity: item.quantity || 1, + claimed_weight_unit: item.claimed_weight_unit || 'g', + type: 'Essentials', + ownerId, + }); + } + resolve(itemsToInsert); + } catch (error) { + reject(error); + } + }, + error: (error) => reject(error), + }); + }); +} diff --git a/server/src/services/item/item.service.ts b/server/src/services/item/item.service.ts index 31924e039..fb24b7bc3 100644 --- a/server/src/services/item/item.service.ts +++ b/server/src/services/item/item.service.ts @@ -10,3 +10,4 @@ export * from './getItemsGloballyService'; export * from './searchItemsByNameService'; export * from './getItemsService'; export * from './bulkAddGlobalItemService'; +export * from './importFromBucketService'; From 6873f0df296e3972869f9746f3b0281556d9af2e Mon Sep 17 00:00:00 2001 From: pinocchio-life-like Date: Thu, 15 Aug 2024 10:02:37 +0300 Subject: [PATCH 10/10] cleanup and changes --- packages/app/components/item/ImportForm.tsx | 14 ++--- server/src/routes/index.ts | 54 ++----------------- server/src/routes/testRoutes.ts | 52 ++++++++++++++++++ .../services/item/importFromBucketService.ts | 23 +++++--- 4 files changed, 80 insertions(+), 63 deletions(-) create mode 100644 server/src/routes/testRoutes.ts diff --git a/packages/app/components/item/ImportForm.tsx b/packages/app/components/item/ImportForm.tsx index daae7736b..e23f98001 100644 --- a/packages/app/components/item/ImportForm.tsx +++ b/packages/app/components/item/ImportForm.tsx @@ -29,11 +29,11 @@ interface SelectedType { } const options = [ - { label: 'Rei', value: 'rei', key: 'Rei' }, - { label: 'Sierra', value: 'sierra', key: 'Sierra' }, - { label: 'Cabelas', value: 'cabelas', key: 'Cabelas' }, - { label: 'Moosejaw', value: 'moosejaw', key: 'Moosejaw' }, - { label: 'Backcountry', value: 'backcountry', key: 'Backcountry' }, + { label: 'bucket 1', value: 'bucket 1', key: 'bucket 1' }, + { label: 'bucket 2', value: 'bucket 2', key: 'bucket 1' }, + { label: 'bucket 3', value: 'bucket 3', key: 'bucket 1' }, + { label: 'bucket 4', value: 'bucket 4', key: 'bucket 1' }, + { label: 'bucket 5', value: 'bucket 5', key: 'bucket 1' }, ]; const csvOption = [{ label: 'CSV', value: '.csv', key: '.csv' }]; @@ -79,7 +79,9 @@ export const ImportForm: FC = ({ }, [isImporting]); const handleSelectChange = (selectedValue: string) => { - const newValue = data.find((item) => item.value === selectedValue); + const newValue = [...csvOption, ...options].find( + (item) => item.value === selectedValue, + ); if (newValue) setSelectedType(newValue); }; diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index c47b555a9..5d59d5f53 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -11,14 +11,15 @@ import openAiRoutes from './openAiRoutes'; import templateRoutes from './templateRoutes'; import favoriteRouters from './favoriteRoutes'; import userRoutes from './userRoutes'; +import testRoutes from './testRoutes'; import mapPreviewRouter from './mapPreviewRouter'; import healthRoutes from './healthRoutes'; import { Hono } from 'hono'; -import querystring from 'querystring'; const router = new Hono(); // use routes +router.route('/testapi', testRoutes); router.route('/user', userRoutes); router.route('/pack', packRoutes); router.route('/item', itemRoutes); @@ -35,57 +36,8 @@ router.route('/favorite', favoriteRouters); router.route('/mapPreview', mapPreviewRouter); router.route('/health', healthRoutes); -const testapi = new Hono(); - -testapi.get('/', async (c) => { - const params = c.req.query(); - console.log('Received data:', params); - - return c.json({ message: 'Data received successfully!', data: params }); -}); - -testapi.get('/test', async (c) => { - try { - const postData = querystring.stringify({ - project: 'PackRat', - spider: 'backcountry', - }); - - const response = await fetch('http://localhost:6800/schedule.json', { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - body: postData, - }); - - const responseData = await response.json(); - - if (responseData.status === 'ok') { - console.log('Scraping initiated', responseData); - return c.json({ - message: 'Scraping initiated successfully!', - response: responseData, - }); - } else { - console.error('Error from Scrapyd:', responseData); - return c.json({ - message: 'Failed to initiate scraping', - error: responseData, - }); - } - } catch (error) { - console.error('Error initiating scraping:', error); - return c.json({ - message: 'Failed to initiate scraping', - error: error.toString(), - }); - } -}); - -router.route('/testapi', testapi); - // Also listen to /api for backwards compatibility +router.route('/api/testapi', testRoutes); router.route('/api/user', userRoutes); router.route('/api/pack', packRoutes); router.route('/api/item', itemRoutes); diff --git a/server/src/routes/testRoutes.ts b/server/src/routes/testRoutes.ts new file mode 100644 index 000000000..9a073ba7b --- /dev/null +++ b/server/src/routes/testRoutes.ts @@ -0,0 +1,52 @@ +import { Hono } from 'hono'; +import querystring from 'querystring'; + +const router = new Hono(); + +router.get('/', async (c) => { + const params = c.req.query(); + console.log('Received data:', params); + + return c.json({ message: 'Data received successfully!', data: params }); +}); + +router.get('/test', async (c) => { + try { + const postData = querystring.stringify({ + project: 'PackRat', + spider: 'backcountry', + }); + + const response = await fetch('http://localhost:6800/schedule.json', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: postData, + }); + + const responseData = await response.json(); + + if (responseData.status === 'ok') { + console.log('Scraping initiated', responseData); + return c.json({ + message: 'Scraping initiated successfully!', + response: responseData, + }); + } else { + console.error('Error from Scrapyd:', responseData); + return c.json({ + message: 'Failed to initiate scraping', + error: responseData, + }); + } + } catch (error) { + console.error('Error initiating scraping:', error); + return c.json({ + message: 'Failed to initiate scraping', + error: error.toString(), + }); + } +}); + +export default router; diff --git a/server/src/services/item/importFromBucketService.ts b/server/src/services/item/importFromBucketService.ts index e911bb880..7468b47aa 100644 --- a/server/src/services/item/importFromBucketService.ts +++ b/server/src/services/item/importFromBucketService.ts @@ -4,10 +4,10 @@ import Papa from 'papaparse'; interface CSVType { name: string; - claimed_weight: number; + weight: number; quantity: number; - claimed_weight_unit: string; - type: string; + unit: string; + type: 'Essentials' | 'Food' | 'Water'; ownerId: string; } @@ -129,6 +129,17 @@ export async function listBucketContents( x_amz_token, ); + const bucketOptions = [ + { label: 'bucket 1', value: 'rei' }, + { label: 'bucket 2', value: 'sierra' }, + { label: 'bucket 3', value: 'cabelas' }, + { label: 'bucket 4', value: 'moosejaw' }, + { label: 'bucket 5', value: 'backcountry' }, + ]; + + directory = + bucketOptions.find((item) => item.label === directory)?.value || ''; + const parsedListData = await parseStringPromise(listData); const contents = parsedListData.ListBucketResult.Contents; @@ -141,7 +152,7 @@ export async function listBucketContents( export async function parseCSVData(fileData: string, ownerId: string) { return new Promise((resolve, reject) => { - const itemsToInsert: CSVType[] = []; + const itemsToInsert = []; Papa.parse(fileData, { header: true, @@ -157,9 +168,9 @@ export async function parseCSVData(fileData: string, ownerId: string) { itemsToInsert.push({ name: item.name, - claimed_weight: item.claimed_weight || 0, + weight: item.claimed_weight || 0, quantity: item.quantity || 1, - claimed_weight_unit: item.claimed_weight_unit || 'g', + unit: item.claimed_weight_unit || 'g', type: 'Essentials', ownerId, });