From ce4570cabcf2f99da5c6bd3c2baf83d3073b5f1d Mon Sep 17 00:00:00 2001 From: vivek kasture Date: Fri, 8 Nov 2024 10:46:35 +0530 Subject: [PATCH] Issue #PS-000 fix: Reverted proxy.ts --- package.json | 3 +- src/pages/api/mocked-response.ts | 418 ------------------------------- src/pages/api/proxy.ts | 96 ------- 3 files changed, 1 insertion(+), 516 deletions(-) delete mode 100644 src/pages/api/mocked-response.ts delete mode 100644 src/pages/api/proxy.ts diff --git a/package.json b/package.json index 50ac6cd0..0f78c136 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,7 @@ "react-i18next": "^14.1.2", "react-toastify": "^10.0.5", "sharp": "^0.33.4", - "zustand": "^4.5.4", - "cookie": "^1.0.1" + "zustand": "^4.5.4" }, "devDependencies": { "@tanstack/react-query-devtools": "^5.51.23", diff --git a/src/pages/api/mocked-response.ts b/src/pages/api/mocked-response.ts deleted file mode 100644 index e08c3b41..00000000 --- a/src/pages/api/mocked-response.ts +++ /dev/null @@ -1,418 +0,0 @@ -export const genericEditorSaveFormResponse = { - "id": "api.form.read", - "params": { - "status": "successful" - }, - "responseCode": "OK", - "result": { - "form": { - "type": "content", - "subtype": "resource", - "action": "save", - "component": "*", - "framework": "*", - "data": { - "templateName": "defaultTemplate", - "action": "save", - "fields": [ - { - "code": "appicon", - "dataType": "url", - "description": "App Icon", - "editable": true, - "index": 1, - "inputType": "file", - "label": "App Icon", - "name": "App Icon", - "placeholder": "App Icon", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "name", - "dataType": "text", - "description": "Title of the content", - "editable": true, - "index": 2, - "inputType": "text", - "label": "Title", - "name": "Title", - "placeholder": "Enter Title", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "description", - "dataType": "text", - "description": "Brief description", - "editable": true, - "index": 3, - "inputType": "textarea", - "label": "Description", - "name": "Description", - "placeholder": "Brief description about the Book", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "keywords", - "dataType": "list", - "description": "Keywords for the content", - "editable": true, - "index": 4, - "inputType": "keywordsuggestion", - "label": "keywords", - "name": "Keywords", - "placeholder": "Enter Keywords", - "required": false, - "visible": true - }, - { - "code": "medium", - "dataType": "List", - "description": "Language", - "editable": true, - "index": 8, - "inputType": "select", - "label": "Language", - "name": "Langauge", - "placeholder": "Select Language", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "audience", - "dataType": "list", - "description": "Audience", - "editable": true, - "index": 8, - "inputType": "multiselect", - "label": "Audience", - "name": "Audience", - "range": [ - { - "key": "Student", - "name": "Student" - }, - { - "key": "Teacher", - "name": "Teacher" - }, - { - "key": "Administrator", - "name": "Administrator" - }, - { - "key": "Teacher", - "name": "Teacher" - }, - { - "key": "Other", - "name": "Other" - } - ], - "placeholder": "Select Audience", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "attributions", - "dataType": "list", - "description": "Attributions", - "editable": true, - "index": 8, - "inputType": "text", - "label": "Attributions", - "name": "attribution", - "placeholder": "", - "renderingHints": {}, - "required": false, - "visible": true - } - ] - }, - "created_on": "2019-09-08T03:04:38.104Z", - "last_modified_on": "2020-09-08T12:50:30.070Z", - "rootOrgId": "*" - } - }, - "ver": "1.0" -} - -export const genericEditorReviewFormResponse = { - "id": "api.form.read", - "params": { - "resmsgid": "3f255e2a-c31a-4396-9d95-1e8b42b3ed61", - "msgid": "9754ec68-3862-4489-9f3a-3eca797257e3", - "status": "successful" - }, - "responseCode": "OK", - "result": { - "form": { - "type": "content", - "subtype": "resource", - "action": "review", - "component": "*", - "framework": "*", - "data": { - "templateName": "defaultTemplate", - "action": "review", - "fields": [ - { - "code": "appicon", - "dataType": "url", - "description": "App Icon", - "editable": true, - "index": 1, - "inputType": "file", - "label": "App Icon", - "name": "App Icon", - "placeholder": "App Icon", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "name", - "dataType": "text", - "description": "Title of the content", - "editable": true, - "index": 2, - "inputType": "text", - "label": "Title", - "name": "Title", - "placeholder": "Enter Title For Book", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "description", - "dataType": "text", - "description": "Brief description", - "editable": true, - "index": 3, - "inputType": "textarea", - "label": "Description", - "name": "Description", - "placeholder": "Brief description about the Book", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "keywords", - "dataType": "list", - "description": "Keywords for the content", - "editable": true, - "index": 4, - "inputType": "keywordsuggestion", - "label": "keywords", - "name": "Keywords", - "placeholder": "Enter Keywords", - "required": false, - "visible": true - }, - { - "code": "board", - "visible": true, - "depends": [ - "medium", - "gradeLevel", - "subject", - "topic" - ], - "editable": true, - "dataType": "text", - "renderingHints": {}, - "description": "Board", - "index": 7, - "label": "Board/Syllabus", - "required": true, - "name": "Board/Syllabus", - "inputType": "select", - "placeholder": "Select Board/Syllabus" - }, - { - "code": "medium", - "visible": true, - "depends": [ - "gradeLevel", - "subject", - "topic" - ], - "editable": true, - "dataType": "list", - "renderingHints": {}, - "description": "", - "index": 8, - "label": "Medium", - "required": true, - "name": "medium", - "inputType": "multiselect", - "placeholder": "Select Medium" - }, - { - "code": "gradeLevel", - "visible": true, - "depends": [ - "subject", - "topic" - ], - "editable": true, - "dataType": "list", - "renderingHints": {}, - "description": "Class", - "index": 9, - "label": "Class", - "required": true, - "name": "Class", - "inputType": "multiselect", - "placeholder": "Select Class" - }, - { - "code": "subject", - "visible": true, - "depends": [ - "topic" - ], - "editable": true, - "dataType": "list", - "renderingHints": {}, - "description": "", - "index": 10, - "label": "Subject", - "required": true, - "name": "Subject", - "inputType": "multiselect", - "placeholder": "Select Subject" - }, - { - "code": "medium", - "dataType": "list", - "description": "Language", - "editable": true, - "index": 8, - "inputType": "select", - "label": "Language", - "name": "Langauge", - "placeholder": "Select Language", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "audience", - "dataType": "list", - "description": "Audience", - "editable": true, - "index": 8, - "inputType": "multiselect", - "label": "Audience", - "name": "Audience", - "range": [ - { - "key": "Student", - "name": "Student" - }, - { - "key": "Teacher", - "name": "Teacher" - }, - { - "key": "Administrator", - "name": "Administrator" - }, - { - "key": "Other", - "name": "Other" - } - ], - "placeholder": "Select Audience", - "renderingHints": {}, - "required": false, - "visible": true - }, - { - "code": "attributions", - "dataType": "list", - "description": "Attributions", - "editable": true, - "index": 8, - "inputType": "text", - "label": "Attributions", - "name": "attribution", - "placeholder": "", - "renderingHints": {}, - "required": false, - "visible": true - } - ] - }, - "created_on": "2024-07-31T06:21:34.669Z", - "last_modified_on": "2024-07-31T07:20:14.642Z", - "rootOrgId": "*" - } - }, - "ts": "2024-10-10T12:25:59.637Z", - "ver": "1.0" -} - -export const genericEditorRequestForChangesFormResponse = { - "id": "api.form.read", - "params": { - "resmsgid": "dd529494-4996-47c8-849d-f5862426fb39", - "msgid": "06aa0ffa-306f-42eb-b7d6-b15596b858fe", - "status": "successful" - }, - "responseCode": "OK", - "result": { - "form": { - "type": "content", - "subtype": "resource", - "action": "requestforchanges", - "component": "*", - "framework": "*", - "data": { - "templateName": "defaultTemplate", - "action": "requestforchanges", - "fields": [{ "contents": [] }] - }, - "created_on": "2019-09-08T15:25:00.291Z", - "last_modified_on": "2020-08-24T06:06:08.120Z", - "rootOrgId": "*" - } - }, - "ts": "2024-10-25T07:24:32.384Z", - "ver": "1.0" -} - -export const telemetryResponse = { - "id": "api.telemetry.post", - "params": { - "status": "successful" - }, - "responseCode": "OK", - "result": { - "message": "This is mocked response" - }, - "ver": "1.0" -} - -export const creatLockResponse = { - "id": "api.lock.create", - "params": { - "status": "successful", - }, - "responseCode": "OK", - "result": { - "lockKey": "69d82e1c-6d91-4b2e-a873-39ebeab007b9", - "expiresAt": "2026-10-09T12:53:41.138Z", - "expiresIn": 63072000 - } -} \ No newline at end of file diff --git a/src/pages/api/proxy.ts b/src/pages/api/proxy.ts deleted file mode 100644 index ffd7c4f6..00000000 --- a/src/pages/api/proxy.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { NextApiRequest, NextApiResponse } from "next"; -import { - genericEditorSaveFormResponse, - telemetryResponse, - creatLockResponse, - genericEditorReviewFormResponse, - genericEditorRequestForChangesFormResponse, -} from "./mocked-response"; -import * as cookie from "cookie"; - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - const { method, body, query } = req; - const { path } = query; - - const BASE_URL = process.env.BASE_URL as string; - const TENANT_ID = process.env.TENANT_ID as string; - const API_KEY = process.env.AUTH_API_TOKEN as string; - - const cookies = cookie.parse(req.headers.cookie || ""); - - console.log(cookies?.authToken); - - const token = cookies?.authToken || API_KEY; - - if (!token) { - console.error("No valid token available"); - return res.status(401).json({ message: "Unauthorized: Token is required" }); - } - - console.log("Using token:", token); - - let pathString = Array.isArray(path) ? path.join("/") : (path as string); - - // Handle mocked responses - if (pathString === "/action/data/v3/telemetry") { - return res.status(200).json(telemetryResponse); - } - - if (pathString === "/action/data/v1/form/read") { - const { action, subType } = body.request; - if (action === "save" && subType === "resource") { - return res.status(200).json(genericEditorSaveFormResponse); - } - if (action === "review" && subType === "resource") { - return res.status(200).json(genericEditorReviewFormResponse); - } - if (action === "requestforchanges" && subType === "resource") { - return res.status(200).json(genericEditorRequestForChangesFormResponse); - } - } - - if (pathString === "/action/lock/v1/create") { - return res.status(200).json(creatLockResponse); - } - - if (pathString.startsWith("/action/framework/v3/read/")) { - pathString = pathString.replace( - "/action/framework/v3/read/", - "/api/framework/v1/read/" - ); - } - - const queryString = req.url?.includes("?") ? req.url.split("?")[1] : ""; - const targetUrl = `${BASE_URL}${pathString}${ - queryString ? `?${queryString}` : "" - }`; - - console.log("targetUrl =====>", targetUrl); - - try { - const options: RequestInit = { - method, - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - tenantId: TENANT_ID, - "X-Channel-Id": "test-k12-channel", - }, - ...(method === "POST" || method === "PATCH" - ? { body: JSON.stringify(body) } - : {}), - }; - - const response = await fetch(targetUrl, options); - const data = await response.json(); - res.status(response.status).json(data); - } catch (error: any) { - console.error("Error in proxy:", error.message); - res - .status(500) - .json({ message: "Error fetching data", error: error.message }); - } -}