codeforlife 2.15.2 → 2.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +1 -1
- package/dist/api/index.cjs.js.map +1 -1
- package/dist/api/index.es.js +1 -1
- package/dist/api/index.es.js.map +1 -1
- package/package.json +5 -5
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ time) are owned by Ocado Innovation Limited.
|
|
|
17
17
|
|
|
18
18
|
The source code of the Code for Life portal, the Rapid Router application
|
|
19
19
|
and the Kurono/aimmo application are [licensed under the GNU Affero General
|
|
20
|
-
Public License](https://github.com/
|
|
20
|
+
Public License](https://github.com/codeforlife-education/codeforlife-workspace/blob/main/LICENSE.md).
|
|
21
21
|
All other assets including images, logos, sounds etc., are not covered by
|
|
22
22
|
this licence and no-one may copy, modify, distribute, show in public or
|
|
23
23
|
create any derivative work from these assets.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/api/tagTypes.ts","../../src/api/createApi.ts"],"sourcesContent":["const tagTypes = [\n // These are the tags for the common models used throughout our system.\n // https://github.com/
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/api/tagTypes.ts","../../src/api/createApi.ts"],"sourcesContent":["const tagTypes = [\n // These are the tags for the common models used throughout our system.\n // https://github.com/codeforlife-education/codeforlife-package-python/tree/main/codeforlife/user/models\n // NOTE: Don't use the \"Teacher\" and \"Student\" tags. Use \"User\" instead.\n \"User\",\n \"School\",\n \"Class\",\n \"AuthFactor\",\n] as const\n\nexport default tagTypes\nexport type TagTypes = (typeof tagTypes)[number]\n","import {\n type Api,\n type BaseQueryApi,\n type FetchArgs,\n type FetchBaseQueryError,\n type FetchBaseQueryMeta,\n type MutationDefinition,\n type QueryReturnValue,\n createApi as _createApi,\n type coreModuleName,\n fetchBaseQuery,\n type reactHooksModuleName,\n} from \"@reduxjs/toolkit/query/react\"\nimport { type ActionCreatorWithoutPayload } from \"@reduxjs/toolkit\"\n\nimport defaultTagTypes, { type TagTypes as DefaultTagTypes } from \"./tagTypes\"\nimport { buildLogoutEndpoint } from \"./endpoints/session\"\nimport { getCsrfCookie } from \"../utils/auth\"\nimport { isSafeHttpMethod } from \"../utils/api\"\n\n// TODO: decide if we want to keep any of this.\n// export function handleResponseError(error: FetchBaseQueryError): void {\n// if (\n// error.status === 400 &&\n// typeof error.data === \"object\" &&\n// error.data !== null\n// ) {\n// // Parse the error's data from snake_case to camelCase.\n// snakeCaseToCamelCase(error.data)\n// } else if (error.status === 401) {\n// // TODO: redirect to appropriate login page based on user type.\n// window.location.href = `${PORTAL_BASE_URL}/login/teacher`\n// } else {\n// // Catch-all error pages by status-code.\n// window.location.href = `${PORTAL_BASE_URL}/error/${\n// [403, 404].includes(error.status as number) ? error.status : 500\n// }`\n// }\n// }\n\nexport default function createApi<TagTypes extends string = never>({\n serviceApiUrl,\n logoutAction,\n tagTypes = [],\n}: {\n serviceApiUrl: string\n logoutAction: ActionCreatorWithoutPayload\n tagTypes?: readonly TagTypes[]\n}): Api<\n (\n args: string | FetchArgs,\n api: BaseQueryApi,\n extraOptions: {},\n ) => Promise<\n QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>\n >,\n { logout: MutationDefinition<null, any, any, null, any, any> },\n \"api\",\n TagTypes | DefaultTagTypes,\n typeof coreModuleName | typeof reactHooksModuleName\n> {\n const fetch = fetchBaseQuery({\n baseUrl: `${serviceApiUrl}/`,\n credentials: \"include\",\n prepareHeaders: (headers, endpoint) => {\n const { type, arg } = endpoint as typeof endpoint & {\n arg: string | FetchArgs\n }\n const method = typeof arg === \"string\" ? \"GET\" : arg.method || \"GET\"\n\n if (type === \"mutation\" || !isSafeHttpMethod(method)) {\n const csrfToken = getCsrfCookie()\n if (csrfToken) headers.set(\"x-csrftoken\", csrfToken)\n }\n\n return headers\n },\n })\n\n const api = _createApi({\n // https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#implementing-a-custom-basequery\n baseQuery: async (args: string | FetchArgs, api, extraOptions) => {\n if (api.type === \"mutation\" && getCsrfCookie() === undefined) {\n // Get the CSRF token.\n const { error } = await fetch(\n { url: \"/csrf/cookie/\", method: \"GET\" },\n api,\n {},\n )\n\n // Validate we got the CSRF token.\n if (error !== undefined) {\n console.error(error)\n // TODO\n // window.location.href = `${PORTAL_BASE_URL}/error/500`\n }\n if (getCsrfCookie() === undefined) {\n // TODO\n // window.location.href = `${PORTAL_BASE_URL}/error/500`\n }\n }\n\n // Send the HTTP request and fetch the response.\n return await fetch(args, api, extraOptions)\n },\n tagTypes: [...defaultTagTypes, ...tagTypes],\n endpoints: () => ({}),\n })\n\n return api.injectEndpoints({\n endpoints: build => ({\n logout: buildLogoutEndpoint<null, null>(api, build, logoutAction),\n }),\n })\n}\n"],"names":["tagTypes","createApi","serviceApiUrl","logoutAction","fetch","fetchBaseQuery","headers","endpoint","type","arg","method","isSafeHttpMethod","csrfToken","getCsrfCookie","api","_createApi","args","extraOptions","error","defaultTagTypes","build","buildLogoutEndpoint"],"mappings":"iVAAMA,EAAW,CAIf,OACA,SACA,QACA,YACF,ECgCA,SAAwBC,EAA2C,CACjE,cAAAC,EACA,aAAAC,EAAA,SACAH,EAAW,CAAA,CACb,EAgBE,CACA,MAAMI,EAAQC,EAAAA,eAAe,CAC3B,QAAS,GAAGH,CAAa,IACzB,YAAa,UACb,eAAgB,CAACI,EAASC,IAAa,CACrC,KAAM,CAAE,KAAAC,EAAM,IAAAC,CAAA,EAAQF,EAGhBG,EAAS,OAAOD,GAAQ,SAAW,MAAQA,EAAI,QAAU,MAE/D,GAAID,IAAS,YAAc,CAACG,EAAAA,iBAAiBD,CAAM,EAAG,CACpD,MAAME,EAAYC,EAAAA,cAAA,EACdD,GAAWN,EAAQ,IAAI,cAAeM,CAAS,CACrD,CAEA,OAAON,CACT,CAAA,CACD,EAEKQ,EAAMC,EAAAA,UAAW,CAErB,UAAW,MAAOC,EAA0BF,EAAKG,IAAiB,CAChE,GAAIH,EAAI,OAAS,YAAcD,EAAAA,cAAA,IAAoB,OAAW,CAE5D,KAAM,CAAE,MAAAK,CAAA,EAAU,MAAMd,EACtB,CAAE,IAAK,gBAAiB,OAAQ,KAAA,EAChCU,EACA,CAAA,CAAC,EAICI,IAAU,QACZ,QAAQ,MAAMA,CAAK,EAIjBL,EAAAA,cAAA,CAIN,CAGA,OAAO,MAAMT,EAAMY,EAAMF,EAAKG,CAAY,CAC5C,EACA,SAAU,CAAC,GAAGE,EAAiB,GAAGnB,CAAQ,EAC1C,UAAW,KAAO,CAAA,EAAC,CACpB,EAED,OAAOc,EAAI,gBAAgB,CACzB,UAAWM,IAAU,CACnB,OAAQC,EAAAA,oBAAgCP,EAAKM,EAAOjB,CAAY,CAAA,EAClE,CACD,CACH"}
|
package/dist/api/index.es.js
CHANGED
|
@@ -7,7 +7,7 @@ import { s as C } from "../schemas-XzwqFsHM.js";
|
|
|
7
7
|
import { u as w } from "../urls-DCXZ2b50.js";
|
|
8
8
|
const g = [
|
|
9
9
|
// These are the tags for the common models used throughout our system.
|
|
10
|
-
// https://github.com/
|
|
10
|
+
// https://github.com/codeforlife-education/codeforlife-package-python/tree/main/codeforlife/user/models
|
|
11
11
|
// NOTE: Don't use the "Teacher" and "Student" tags. Use "User" instead.
|
|
12
12
|
"User",
|
|
13
13
|
"School",
|
package/dist/api/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../../src/api/tagTypes.ts","../../src/api/createApi.ts"],"sourcesContent":["const tagTypes = [\n // These are the tags for the common models used throughout our system.\n // https://github.com/
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../../src/api/tagTypes.ts","../../src/api/createApi.ts"],"sourcesContent":["const tagTypes = [\n // These are the tags for the common models used throughout our system.\n // https://github.com/codeforlife-education/codeforlife-package-python/tree/main/codeforlife/user/models\n // NOTE: Don't use the \"Teacher\" and \"Student\" tags. Use \"User\" instead.\n \"User\",\n \"School\",\n \"Class\",\n \"AuthFactor\",\n] as const\n\nexport default tagTypes\nexport type TagTypes = (typeof tagTypes)[number]\n","import {\n type Api,\n type BaseQueryApi,\n type FetchArgs,\n type FetchBaseQueryError,\n type FetchBaseQueryMeta,\n type MutationDefinition,\n type QueryReturnValue,\n createApi as _createApi,\n type coreModuleName,\n fetchBaseQuery,\n type reactHooksModuleName,\n} from \"@reduxjs/toolkit/query/react\"\nimport { type ActionCreatorWithoutPayload } from \"@reduxjs/toolkit\"\n\nimport defaultTagTypes, { type TagTypes as DefaultTagTypes } from \"./tagTypes\"\nimport { buildLogoutEndpoint } from \"./endpoints/session\"\nimport { getCsrfCookie } from \"../utils/auth\"\nimport { isSafeHttpMethod } from \"../utils/api\"\n\n// TODO: decide if we want to keep any of this.\n// export function handleResponseError(error: FetchBaseQueryError): void {\n// if (\n// error.status === 400 &&\n// typeof error.data === \"object\" &&\n// error.data !== null\n// ) {\n// // Parse the error's data from snake_case to camelCase.\n// snakeCaseToCamelCase(error.data)\n// } else if (error.status === 401) {\n// // TODO: redirect to appropriate login page based on user type.\n// window.location.href = `${PORTAL_BASE_URL}/login/teacher`\n// } else {\n// // Catch-all error pages by status-code.\n// window.location.href = `${PORTAL_BASE_URL}/error/${\n// [403, 404].includes(error.status as number) ? error.status : 500\n// }`\n// }\n// }\n\nexport default function createApi<TagTypes extends string = never>({\n serviceApiUrl,\n logoutAction,\n tagTypes = [],\n}: {\n serviceApiUrl: string\n logoutAction: ActionCreatorWithoutPayload\n tagTypes?: readonly TagTypes[]\n}): Api<\n (\n args: string | FetchArgs,\n api: BaseQueryApi,\n extraOptions: {},\n ) => Promise<\n QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>\n >,\n { logout: MutationDefinition<null, any, any, null, any, any> },\n \"api\",\n TagTypes | DefaultTagTypes,\n typeof coreModuleName | typeof reactHooksModuleName\n> {\n const fetch = fetchBaseQuery({\n baseUrl: `${serviceApiUrl}/`,\n credentials: \"include\",\n prepareHeaders: (headers, endpoint) => {\n const { type, arg } = endpoint as typeof endpoint & {\n arg: string | FetchArgs\n }\n const method = typeof arg === \"string\" ? \"GET\" : arg.method || \"GET\"\n\n if (type === \"mutation\" || !isSafeHttpMethod(method)) {\n const csrfToken = getCsrfCookie()\n if (csrfToken) headers.set(\"x-csrftoken\", csrfToken)\n }\n\n return headers\n },\n })\n\n const api = _createApi({\n // https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#implementing-a-custom-basequery\n baseQuery: async (args: string | FetchArgs, api, extraOptions) => {\n if (api.type === \"mutation\" && getCsrfCookie() === undefined) {\n // Get the CSRF token.\n const { error } = await fetch(\n { url: \"/csrf/cookie/\", method: \"GET\" },\n api,\n {},\n )\n\n // Validate we got the CSRF token.\n if (error !== undefined) {\n console.error(error)\n // TODO\n // window.location.href = `${PORTAL_BASE_URL}/error/500`\n }\n if (getCsrfCookie() === undefined) {\n // TODO\n // window.location.href = `${PORTAL_BASE_URL}/error/500`\n }\n }\n\n // Send the HTTP request and fetch the response.\n return await fetch(args, api, extraOptions)\n },\n tagTypes: [...defaultTagTypes, ...tagTypes],\n endpoints: () => ({}),\n })\n\n return api.injectEndpoints({\n endpoints: build => ({\n logout: buildLogoutEndpoint<null, null>(api, build, logoutAction),\n }),\n })\n}\n"],"names":["tagTypes","createApi","serviceApiUrl","logoutAction","fetch","fetchBaseQuery","headers","endpoint","type","arg","method","isSafeHttpMethod","csrfToken","getCsrfCookie","api","_createApi","args","extraOptions","error","defaultTagTypes","build","buildLogoutEndpoint"],"mappings":";;;;;;;AAAA,MAAMA,IAAW;AAAA;AAAA;AAAA;AAAA,EAIf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;ACgCA,SAAwBC,EAA2C;AAAA,EACjE,eAAAC;AAAA,EACA,cAAAC;AAAA,EAAA,UACAH,IAAW,CAAA;AACb,GAgBE;AACA,QAAMI,IAAQC,EAAe;AAAA,IAC3B,SAAS,GAAGH,CAAa;AAAA,IACzB,aAAa;AAAA,IACb,gBAAgB,CAACI,GAASC,MAAa;AACrC,YAAM,EAAE,MAAAC,GAAM,KAAAC,EAAA,IAAQF,GAGhBG,IAAS,OAAOD,KAAQ,WAAW,QAAQA,EAAI,UAAU;AAE/D,UAAID,MAAS,cAAc,CAACG,EAAiBD,CAAM,GAAG;AACpD,cAAME,IAAYC,EAAA;AAClB,QAAID,KAAWN,EAAQ,IAAI,eAAeM,CAAS;AAAA,MACrD;AAEA,aAAON;AAAA,IACT;AAAA,EAAA,CACD,GAEKQ,IAAMC,EAAW;AAAA;AAAA,IAErB,WAAW,OAAOC,GAA0BF,GAAKG,MAAiB;AAChE,UAAIH,EAAI,SAAS,cAAcD,EAAA,MAAoB,QAAW;AAE5D,cAAM,EAAE,OAAAK,EAAA,IAAU,MAAMd;AAAA,UACtB,EAAE,KAAK,iBAAiB,QAAQ,MAAA;AAAA,UAChCU;AAAAA,UACA,CAAA;AAAA,QAAC;AAIH,QAAII,MAAU,UACZ,QAAQ,MAAMA,CAAK,GAIjBL,EAAA;AAAA,MAIN;AAGA,aAAO,MAAMT,EAAMY,GAAMF,GAAKG,CAAY;AAAA,IAC5C;AAAA,IACA,UAAU,CAAC,GAAGE,GAAiB,GAAGnB,CAAQ;AAAA,IAC1C,WAAW,OAAO,CAAA;AAAA,EAAC,CACpB;AAED,SAAOc,EAAI,gBAAgB;AAAA,IACzB,WAAW,CAAAM,OAAU;AAAA,MACnB,QAAQC,EAAgCP,GAAKM,GAAOjB,CAAY;AAAA,IAAA;AAAA,EAClE,CACD;AACH;"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "codeforlife",
|
|
3
3
|
"description": "Common frontend code",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "2.15.
|
|
5
|
+
"version": "2.15.3",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"module": "dist/index.es.js",
|
|
@@ -187,14 +187,14 @@
|
|
|
187
187
|
},
|
|
188
188
|
"repository": {
|
|
189
189
|
"type": "git",
|
|
190
|
-
"url": "git+https://github.com/
|
|
190
|
+
"url": "git+https://github.com/codeforlife-education/codeforlife-package-javascript.git"
|
|
191
191
|
},
|
|
192
192
|
"author": "Ocado",
|
|
193
193
|
"license": "AGPL-3.0-only",
|
|
194
194
|
"bugs": {
|
|
195
|
-
"url": "https://github.com/
|
|
195
|
+
"url": "https://github.com/codeforlife-education/codeforlife-package-javascript/issues"
|
|
196
196
|
},
|
|
197
|
-
"homepage": "https://github.com/
|
|
197
|
+
"homepage": "https://github.com/codeforlife-education/codeforlife-package-javascript#readme",
|
|
198
198
|
"//": [
|
|
199
199
|
"Dependency rules:",
|
|
200
200
|
"✅ Do add `dependencies` that are required to use this package.",
|
|
@@ -215,7 +215,7 @@
|
|
|
215
215
|
"dayjs": "1.11.19",
|
|
216
216
|
"express": "4.22.2",
|
|
217
217
|
"formik": "2.4.9",
|
|
218
|
-
"js-cookie": "3.0.
|
|
218
|
+
"js-cookie": "3.0.7",
|
|
219
219
|
"memory-cache": "0.2.0",
|
|
220
220
|
"qs": "6.15.2",
|
|
221
221
|
"react": "19.1.1",
|