From efc5c40e886e5751b18d72bc1334c511d38f59e9 Mon Sep 17 00:00:00 2001 From: John Hall Date: Tue, 6 Aug 2024 12:18:19 -0400 Subject: [PATCH] rebuild api context --- .../components/CategoricalLegend.d.ts | 36 ++++- .../components/CategoricalLegend.d.ts.map | 2 +- .../components/CategoricalLegend.js | 32 ++++- .../components/CategoricalLegend.js.map | 2 +- .../components/GeocoderControl.d.ts | 39 +++-- .../components/GeocoderControl.d.ts.map | 2 +- .../@cori-risi/components/GeocoderControl.js | 133 +++++++++++------- .../components/GeocoderControl.js.map | 2 +- .../cotexts/AmplifyContextProvider.d.ts | 18 ++- .../cotexts/AmplifyContextProvider.d.ts.map | 2 +- .../cotexts/AmplifyContextProvider.js | 18 ++- .../cotexts/AmplifyContextProvider.js.map | 2 +- .../cotexts/ApiContextProvider.d.ts | 72 +++++++++- .../cotexts/ApiContextProvider.d.ts.map | 2 +- .../@cori-risi/cotexts/ApiContextProvider.js | 58 +++++++- .../cotexts/ApiContextProvider.js.map | 2 +- inst/dist/cori.data.api.d.ts | 29 +++- inst/dist/cori.data.api.d.ts.map | 2 +- inst/dist/cori.data.api.js | 28 +++- inst/dist/cori.data.api.js.map | 2 +- 20 files changed, 392 insertions(+), 91 deletions(-) diff --git a/inst/dist/@cori-risi/components/CategoricalLegend.d.ts b/inst/dist/@cori-risi/components/CategoricalLegend.d.ts index 643806b6..c7c09365 100644 --- a/inst/dist/@cori-risi/components/CategoricalLegend.d.ts +++ b/inst/dist/@cori-risi/components/CategoricalLegend.d.ts @@ -1,12 +1,40 @@ import React from 'react'; -interface CategoricalLegendProps { +/** + * This is a prototype generalization of the CategoricalLegend component used in the + * [ERC tool](https://github.com/ruralinnovation/erc-frontend-ts/tree/dev/MDAT-30-frontend-ui-shared-library/src/components){target=_blank} + * + * ```ts + * import { CategoricalLegend } from '@cori-risi/cori.data.api'; + * + * import "@cori-risi/cori.data.api/inst/dist/cori.data.api.css"; + * + * // ... + * + * const colorScale = d3.scaleOrdinal() + * .domain(groups) // Input domain + * .range(["#A3E2B5", "#00835D", "#26535C"]); + * + * const colorScaleDomain = colorScale.domain(); + * const colorScaleRange = colorScale.range(); + * + * // ... + * + * data.filter(d => d.geoid === c).map(d => d.name)[0])} + * domain={colorScaleDomain} + * range={colorScaleRange} /> + * ``` + * + * @param props.domain_names - an (array) of names, each one mapped to a category in the color scale domain + * @param props.domain - d3 color scale domain + * @param props.range - d3 color scale range + */ +declare function CategoricalLegend(props: { domain_names?: string[] | undefined; domain?: string[] | undefined; range?: unknown[] | undefined; scale?: any | undefined; - na_message?: string; title?: string; -} -declare function CategoricalLegend({ domain, domain_names, range, title, scale, na_message }: CategoricalLegendProps): React.JSX.Element; + na_message?: string; +}): React.JSX.Element; export default CategoricalLegend; //# sourceMappingURL=CategoricalLegend.d.ts.map \ No newline at end of file diff --git a/inst/dist/@cori-risi/components/CategoricalLegend.d.ts.map b/inst/dist/@cori-risi/components/CategoricalLegend.d.ts.map index f8fd71ce..3690c497 100644 --- a/inst/dist/@cori-risi/components/CategoricalLegend.d.ts.map +++ b/inst/dist/@cori-risi/components/CategoricalLegend.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"CategoricalLegend.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/components/CategoricalLegend.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,UAAU,sBAAsB;IAC5B,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,iBAAS,iBAAiB,CAAE,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,UAAkB,EAAE,EAAE,sBAAsB,qBAoDpH;AAED,eAAe,iBAAiB,CAAC"} \ No newline at end of file +{"version":3,"file":"CategoricalLegend.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/components/CategoricalLegend.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,iBAAS,iBAAiB,CAAE,KAAK,EAAE;IAC/B,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,GAAG,GAAG,SAAS,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,qBA6DA;AAED,eAAe,iBAAiB,CAAC"} \ No newline at end of file diff --git a/inst/dist/@cori-risi/components/CategoricalLegend.js b/inst/dist/@cori-risi/components/CategoricalLegend.js index 9af079ce..96610ecb 100644 --- a/inst/dist/@cori-risi/components/CategoricalLegend.js +++ b/inst/dist/@cori-risi/components/CategoricalLegend.js @@ -7,8 +7,38 @@ import React__default from 'react'; import style from './styles/CategoricalLegend.module.css.js'; -function CategoricalLegend({ domain, domain_names, range, title, scale, na_message = "N/A" }) { +/** + * This is a prototype generalization of the CategoricalLegend component used in the + * [ERC tool](https://github.com/ruralinnovation/erc-frontend-ts/tree/dev/MDAT-30-frontend-ui-shared-library/src/components){target=_blank} + * + * ```ts + * import { CategoricalLegend } from '@cori-risi/cori.data.api'; + * + * import "@cori-risi/cori.data.api/inst/dist/cori.data.api.css"; + * + * // ... + * + * const colorScale = d3.scaleOrdinal() + * .domain(groups) // Input domain + * .range(["#A3E2B5", "#00835D", "#26535C"]); + * + * const colorScaleDomain = colorScale.domain(); + * const colorScaleRange = colorScale.range(); + * + * // ... + * + * data.filter(d => d.geoid === c).map(d => d.name)[0])} + * domain={colorScaleDomain} + * range={colorScaleRange} /> + * ``` + * + * @param props.domain_names - an (array) of names, each one mapped to a category in the color scale domain + * @param props.domain - d3 color scale domain + * @param props.range - d3 color scale range + */ +function CategoricalLegend(props) { const rows = []; + const { domain_names, domain, range, title, scale, na_message } = props; if (!!domain && !!range) { console.log("CategoricalLegend:"); console.log(`domain.length: ${domain.length}, range.length: ${range.length}`); diff --git a/inst/dist/@cori-risi/components/CategoricalLegend.js.map b/inst/dist/@cori-risi/components/CategoricalLegend.js.map index 1af51c9f..5193b137 100644 --- a/inst/dist/@cori-risi/components/CategoricalLegend.js.map +++ b/inst/dist/@cori-risi/components/CategoricalLegend.js.map @@ -1 +1 @@ -{"version":3,"file":"CategoricalLegend.js","sources":["../../../../lib/@cori-risi/components/CategoricalLegend.tsx"],"sourcesContent":["import React from 'react';\nimport style from \"./styles/CategoricalLegend.module.css\";\n\ninterface CategoricalLegendProps {\n domain_names?: string[] | undefined;\n domain?: string[] | undefined; // Should be in the order of what appears top to bottom in the chart\n range?: unknown[] | undefined;\n scale?: any | undefined;\n na_message?: string;\n title?: string;\n}\n\nfunction CategoricalLegend ({ domain, domain_names, range, title, scale, na_message = \"N/A\" }: CategoricalLegendProps) {\n\n const rows = [];\n\n if (!!domain && !!range) {\n\n console.log(\"CategoricalLegend:\");\n console.log(`domain.length: ${domain.length}, range.length: ${range.length}`)\n\n if (domain.length <= range.length) {\n\n for (let i = 0; i < domain.length; ++i) {\n\n if (typeof range[i] === \"string\") {\n\n const color: string = range[i] as string;\n\n if (!!domain_names) {\n rows.push(\n
\n \n
\n {(!!domain_names) ?\n

{domain_names[i] || domain[i]}

:\n

\n }\n \n );\n }\n\n }\n }\n\n }\n\n return (\n
\n {rows}\n
\n )\n } else {\n return (\n
\n CategoricalLegend\n
\n )\n }\n\n}\n\nexport default CategoricalLegend;\n"],"names":["React"],"mappings":";;;;;;;;;AA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AA,EAAA,IAAA,CAAA,CAET,CACT,CAAC;qBACL;iBAEJ;aACJ;SAEJ;AAED,QAAA,QACIA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,KAAK,CAAC,oBAAoB,CAAC,EACtC,EAAA,IAAI,CACH,EACT;KACJ;SAAM;AACH,QAAA,QACIA,cAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,KAAK,CAAC,oBAAoB,CAAC,EAAA;YACvCA,cAA8B,CAAA,aAAA,CAAA,MAAA,EAAA,IAAA,EAAA,mBAAA,CAAA,CAC5B,EACT;KACJ;AAEL;;;;"} \ No newline at end of file +{"version":3,"file":"CategoricalLegend.js","sources":["../../../../lib/@cori-risi/components/CategoricalLegend.tsx"],"sourcesContent":["import React from 'react';\nimport style from \"./styles/CategoricalLegend.module.css\";\n\ninterface CategoricalLegendProps {\n domain_names?: string[] | undefined;\n domain?: string[] | undefined; // Should be in the order of what appears top to bottom in the chart\n range?: unknown[] | undefined;\n scale?: any | undefined;\n title?: string;\n na_message?: string;\n}\n\n/**\n * This is a prototype generalization of the CategoricalLegend component used in the\n * [ERC tool](https://github.com/ruralinnovation/erc-frontend-ts/tree/dev/MDAT-30-frontend-ui-shared-library/src/components){target=_blank}\n *\n * ```ts\n * import { CategoricalLegend } from '@cori-risi/cori.data.api';\n *\n * import \"@cori-risi/cori.data.api/inst/dist/cori.data.api.css\";\n *\n * // ...\n *\n * const colorScale = d3.scaleOrdinal()\n * .domain(groups) // Input domain\n * .range([\"#A3E2B5\", \"#00835D\", \"#26535C\"]);\n *\n * const colorScaleDomain = colorScale.domain();\n * const colorScaleRange = colorScale.range();\n *\n * // ...\n *\n * data.filter(d => d.geoid === c).map(d => d.name)[0])}\n * domain={colorScaleDomain}\n * range={colorScaleRange} />\n * ```\n *\n * @param props.domain_names - an (array) of names, each one mapped to a category in the color scale domain\n * @param props.domain - d3 color scale domain\n * @param props.range - d3 color scale range\n */\nfunction CategoricalLegend (props: {\n domain_names?: string[] | undefined,\n domain?: string[] | undefined,\n range?: unknown[] | undefined,\n scale?: any | undefined,\n title?: string,\n na_message?: string // TODO: default to \"N/A\"\n}) {\n\n const rows = [];\n\n const {\n domain_names,\n domain,\n range,\n title,\n scale,\n na_message\n } = (props as unknown as CategoricalLegendProps);\n\n if (!!domain && !!range) {\n\n console.log(\"CategoricalLegend:\");\n console.log(`domain.length: ${domain.length}, range.length: ${range.length}`)\n\n if (domain.length <= range.length) {\n\n for (let i = 0; i < domain.length; ++i) {\n\n if (typeof range[i] === \"string\") {\n\n const color: string = range[i] as string;\n\n if (!!domain_names) {\n rows.push(\n
\n \n
\n {(!!domain_names) ?\n

{domain_names[i] || domain[i]}

:\n

\n }\n \n );\n }\n\n }\n }\n\n }\n\n return (\n
\n {rows}\n
\n )\n } else {\n return (\n
\n CategoricalLegend\n
\n )\n }\n\n}\n\nexport default CategoricalLegend;\n"],"names":["React"],"mappings":";;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACH,SAAS,iBAAiB,CAAE,KAO3B,EAAA;IAEG,MAAM,IAAI,GAAG,EAAE,CAAC;AAEhB,IAAA,MAAM,EACF,YAAY,EACZ,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,UAAU,EACb,GAAI,KAA2C,CAAC;IAEjD,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE;AAErB,QAAA,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAClC,QAAA,OAAO,CAAC,GAAG,CAAC,CAAA,eAAA,EAAkB,MAAM,CAAC,MAAM,CAAA,gBAAA,EAAmB,KAAK,CAAC,MAAM,CAAA,CAAE,CAAC,CAAA;QAE7E,IAAI,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE;AAE/B,YAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;gBAEpC,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;AAE9B,oBAAA,MAAM,KAAK,GAAW,KAAK,CAAC,CAAC,CAAW,CAAC;AAEzC,oBAAA,IAAI,CAAC,CAAC,YAAY,EAAE;AAChB,wBAAA,IAAI,CAAC,IAAI,CACLA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,EAAA;4BAClCA,cACI,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,EACvB,KAAK,EAAE;AACH,oCAAA,eAAe,EAAE,KAAK;iCACzB,EACC,CAAA;AACL,4BAAA,CAAC,CAAC,CAAC,YAAY;gCACZA,cAAI,CAAA,aAAA,CAAA,GAAA,EAAA,IAAA,EAAA,YAAY,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAK;gCACrCA,cAAO,CAAA,aAAA,CAAA,GAAA,EAAA,IAAA,CAAA,CAET,CACT,CAAC;qBACL;iBAEJ;aACJ;SAEJ;AAED,QAAA,QACIA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,KAAK,CAAC,oBAAoB,CAAC,EACtC,EAAA,IAAI,CACH,EACT;KACJ;SAAM;AACH,QAAA,QACIA,cAAK,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,KAAK,CAAC,oBAAoB,CAAC,EAAA;YACvCA,cAA8B,CAAA,aAAA,CAAA,MAAA,EAAA,IAAA,EAAA,mBAAA,CAAA,CAC5B,EACT;KACJ;AAEL;;;;"} \ No newline at end of file diff --git a/inst/dist/@cori-risi/components/GeocoderControl.d.ts b/inst/dist/@cori-risi/components/GeocoderControl.d.ts index 116bfb8a..d18c0e9d 100644 --- a/inst/dist/@cori-risi/components/GeocoderControl.d.ts +++ b/inst/dist/@cori-risi/components/GeocoderControl.d.ts @@ -1,14 +1,35 @@ import { MarkerProps, ControlPosition } from 'react-map-gl'; -import { GeocoderOptions } from '@mapbox/mapbox-gl-geocoder'; -type GeocoderControlProps = Omit & { +/** + * This is a Geocoder search component that can be added to any `react-map-gl` Map component. + * + * ```ts + * import mapboxgl from 'mapbox-gl'; + * import Map, { Source, Layer } from 'react-map-gl'; + * + * import { GeocoderControl } from "@cori-risi/cori.data.api"; + * + * import "mapbox-gl/dist/mapbox-gl.css"; + * + * mapboxgl.accessToken = import.meta.env.VITE_MAPBOX_ACCESS_TOKEN; + * + * // ... + * + * + * + * : + * + * + * + * ``` + * + * @param props.mapboxAccessToken - Mapbox API token + * @param props.marker - `true` or `false` to place marker on result once selected (default: `false`) + * @param props.position - CSS class to position control in "top-left", "top-right", "bottom-left" or "bottom-right" of the map pane + */ +export default function GeocoderControl(props: { mapboxAccessToken: string; marker?: boolean | Omit; position: ControlPosition; - onLoading?: (e: object) => void; - onResults?: (e: object) => void; - onResult?: (e: object) => void; - onError?: (e: object) => void; -}; -export default function GeocoderControl(props: GeocoderControlProps): null; -export {}; +}): null; //# sourceMappingURL=GeocoderControl.d.ts.map \ No newline at end of file diff --git a/inst/dist/@cori-risi/components/GeocoderControl.d.ts.map b/inst/dist/@cori-risi/components/GeocoderControl.d.ts.map index f69234e0..94f42169 100644 --- a/inst/dist/@cori-risi/components/GeocoderControl.d.ts.map +++ b/inst/dist/@cori-risi/components/GeocoderControl.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"GeocoderControl.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/components/GeocoderControl.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,WAAW,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAC9E,OAAuB,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAE3E,KAAK,oBAAoB,GAAG,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,UAAU,GAAG,QAAQ,CAAC,GAAG;IACzF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC;IAE/D,QAAQ,EAAE,eAAe,CAAC;IAE1B,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/B,CAAC;AAGF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,EAAE,oBAAoB,QAuFlE"} \ No newline at end of file +{"version":3,"file":"GeocoderControl.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/components/GeocoderControl.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAqB,WAAW,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAgB9E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,EAAE;IAC7C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC;IAC/D,QAAQ,EAAE,eAAe,CAAA;CAC1B,QA2FA"} \ No newline at end of file diff --git a/inst/dist/@cori-risi/components/GeocoderControl.js b/inst/dist/@cori-risi/components/GeocoderControl.js index 2c606eef..877d1f53 100644 --- a/inst/dist/@cori-risi/components/GeocoderControl.js +++ b/inst/dist/@cori-risi/components/GeocoderControl.js @@ -9,88 +9,117 @@ import { useState } from 'react'; import { useControl, Marker } from 'react-map-gl'; import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder'; -/* eslint-disable complexity,max-statements */ +/** + * This is a Geocoder search component that can be added to any `react-map-gl` Map component. + * + * ```ts + * import mapboxgl from 'mapbox-gl'; + * import Map, { Source, Layer } from 'react-map-gl'; + * + * import { GeocoderControl } from "@cori-risi/cori.data.api"; + * + * import "mapbox-gl/dist/mapbox-gl.css"; + * + * mapboxgl.accessToken = import.meta.env.VITE_MAPBOX_ACCESS_TOKEN; + * + * // ... + * + * + * + * : + * + * + * + * ``` + * + * @param props.mapboxAccessToken - Mapbox API token + * @param props.marker - `true` or `false` to place marker on result once selected (default: `false`) + * @param props.position - CSS class to position control in "top-left", "top-right", "bottom-left" or "bottom-right" of the map pane + */ function GeocoderControl(props) { + // } & GeocoderControlProps) { const [marker, setMarker] = useState(null); + const geocoder_props = Object.assign({}, props); const geocoder = useControl(() => { - const ctrl = new MapboxGeocoder(Object.assign(Object.assign({}, props), { marker: false, accessToken: props.mapboxAccessToken })); - if (!!props.onLoading) - ctrl.on('loading', props.onLoading); - if (!!props.onResults) - ctrl.on('results', props.onResults); - if (!!props.onResult) + const ctrl = new MapboxGeocoder(Object.assign(Object.assign({}, geocoder_props), { marker: marker || false, accessToken: geocoder_props.mapboxAccessToken })); + if (!!geocoder_props.onLoading) + ctrl.on('loading', geocoder_props.onLoading); + if (!!geocoder_props.onResults) + ctrl.on('results', geocoder_props.onResults); + if (!!geocoder_props.onResult) ctrl.on('result', evt => { var _a; - if (props.onResult !== undefined) - props.onResult(evt); + if (geocoder_props.onResult !== undefined) + geocoder_props.onResult(evt); const { result } = evt; const location = result && (result.center || (((_a = result.geometry) === null || _a === void 0 ? void 0 : _a.type) === 'Point' && result.geometry.coordinates)); - if (location && props.marker) { - const markerProps = typeof props.marker === 'object' ? props.marker : {}; + if (location && geocoder_props.marker) { + const markerProps = typeof geocoder_props.marker === 'object' ? geocoder_props.marker : {}; + // noinspection TypeScriptValidateTypes setMarker(React.createElement(Marker, Object.assign({}, markerProps, { longitude: location[0], latitude: location[1] }))); } else { setMarker(null); } }); - if (!!props.onError) - ctrl.on('error', props.onError); + if (!!geocoder_props.onError) + ctrl.on('error', geocoder_props.onError); return ctrl; }, { - position: props.position + position: geocoder_props.position }); // @ts-ignore (TS2339) private member - if (geocoder._map) { - if (geocoder.getProximity() !== props.proximity && props.proximity !== undefined) { - geocoder.setProximity(props.proximity); + if (geocoder.hasOwnProperty("_map") && geocoder["_map"]) { + if (geocoder.getProximity() !== geocoder_props.proximity && geocoder_props.proximity !== undefined) { + geocoder.setProximity(geocoder_props.proximity); + } + if (geocoder.getRenderFunction() !== geocoder_props.render && geocoder_props.render !== undefined) { + geocoder.setRenderFunction(geocoder_props.render); + } + if (geocoder.getLanguage() !== geocoder_props.language && geocoder_props.language !== undefined) { + geocoder.setLanguage(geocoder_props.language); + } + if (geocoder.getZoom() !== geocoder_props.zoom && geocoder_props.zoom !== undefined) { + geocoder.setZoom(geocoder_props.zoom); + } + if (geocoder.getFlyTo() !== geocoder_props.flyTo && geocoder_props.flyTo !== undefined) { + geocoder.setFlyTo(geocoder_props.flyTo); } - if (geocoder.getRenderFunction() !== props.render && props.render !== undefined) { - geocoder.setRenderFunction(props.render); + if (geocoder.getPlaceholder() !== geocoder_props.placeholder && geocoder_props.placeholder !== undefined) { + geocoder.setPlaceholder(geocoder_props.placeholder); } - if (geocoder.getLanguage() !== props.language && props.language !== undefined) { - geocoder.setLanguage(props.language); + if (geocoder.getCountries() !== geocoder_props.countries && geocoder_props.countries !== undefined) { + geocoder.setCountries(geocoder_props.countries); } - if (geocoder.getZoom() !== props.zoom && props.zoom !== undefined) { - geocoder.setZoom(props.zoom); + if (geocoder.getTypes() !== geocoder_props.types && geocoder_props.types !== undefined) { + geocoder.setTypes(geocoder_props.types); } - if (geocoder.getFlyTo() !== props.flyTo && props.flyTo !== undefined) { - geocoder.setFlyTo(props.flyTo); + if (geocoder.getMinLength() !== geocoder_props.minLength && geocoder_props.minLength !== undefined) { + geocoder.setMinLength(geocoder_props.minLength); } - if (geocoder.getPlaceholder() !== props.placeholder && props.placeholder !== undefined) { - geocoder.setPlaceholder(props.placeholder); + if (geocoder.getLimit() !== geocoder_props.limit && geocoder_props.limit !== undefined) { + geocoder.setLimit(geocoder_props.limit); } - if (geocoder.getCountries() !== props.countries && props.countries !== undefined) { - geocoder.setCountries(props.countries); + if (geocoder.getFilter() !== geocoder_props.filter && geocoder_props.filter !== undefined) { + geocoder.setFilter(geocoder_props.filter); } - if (geocoder.getTypes() !== props.types && props.types !== undefined) { - geocoder.setTypes(props.types); + if (geocoder.getOrigin() !== geocoder_props.origin && geocoder_props.origin !== undefined) { + geocoder.setOrigin(geocoder_props.origin); } - if (geocoder.getMinLength() !== props.minLength && props.minLength !== undefined) { - geocoder.setMinLength(props.minLength); + if (geocoder.getAutocomplete() !== geocoder_props.autocomplete && geocoder_props.autocomplete !== undefined) { + geocoder.setAutocomplete(geocoder_props.autocomplete); } - if (geocoder.getLimit() !== props.limit && props.limit !== undefined) { - geocoder.setLimit(props.limit); + if (geocoder.getFuzzyMatch() !== geocoder_props.fuzzyMatch && geocoder_props.fuzzyMatch !== undefined) { + geocoder.setFuzzyMatch(geocoder_props.fuzzyMatch); } - if (geocoder.getFilter() !== props.filter && props.filter !== undefined) { - geocoder.setFilter(props.filter); + if (geocoder.getRouting() !== geocoder_props.routing && geocoder_props.routing !== undefined) { + geocoder.setRouting(geocoder_props.routing); } - if (geocoder.getOrigin() !== props.origin && props.origin !== undefined) { - geocoder.setOrigin(props.origin); + if (geocoder.getWorldview() !== geocoder_props.worldview && geocoder_props.worldview !== undefined) { + geocoder.setWorldview(geocoder_props.worldview); } - // Types missing from @types/mapbox__mapbox-gl-geocoder - // if (geocoder.getAutocomplete() !== props.autocomplete && props.autocomplete !== undefined) { - // geocoder.setAutocomplete(props.autocomplete); - // } - // if (geocoder.getFuzzyMatch() !== props.fuzzyMatch && props.fuzzyMatch !== undefined) { - // geocoder.setFuzzyMatch(props.fuzzyMatch); - // } - // if (geocoder.getRouting() !== props.routing && props.routing !== undefined) { - // geocoder.setRouting(props.routing); - // } - // if (geocoder.getWorldview() !== props.worldview && props.worldview !== undefined) { - // geocoder.setWorldview(props.worldview); - // } } return marker; } diff --git a/inst/dist/@cori-risi/components/GeocoderControl.js.map b/inst/dist/@cori-risi/components/GeocoderControl.js.map index 7cf65258..92c69c11 100644 --- a/inst/dist/@cori-risi/components/GeocoderControl.js.map +++ b/inst/dist/@cori-risi/components/GeocoderControl.js.map @@ -1 +1 @@ -{"version":3,"file":"GeocoderControl.js","sources":["../../../../lib/@cori-risi/components/GeocoderControl.tsx"],"sourcesContent":["import * as React from 'react';\nimport {SetStateAction, useState} from 'react';\nimport {useControl, Marker, MarkerProps, ControlPosition} from 'react-map-gl';\nimport MapboxGeocoder, {GeocoderOptions} from '@mapbox/mapbox-gl-geocoder';\n\ntype GeocoderControlProps = Omit & {\n mapboxAccessToken: string;\n marker?: boolean | Omit;\n\n position: ControlPosition;\n\n onLoading?: (e: object) => void;\n onResults?: (e: object) => void;\n onResult?: (e: object) => void;\n onError?: (e: object) => void;\n};\n\n/* eslint-disable complexity,max-statements */\nexport default function GeocoderControl(props: GeocoderControlProps) {\n const [marker, setMarker] = useState(null);\n\n const geocoder = useControl(\n () => {\n const ctrl = new MapboxGeocoder({\n ...props,\n marker: false,\n accessToken: props.mapboxAccessToken\n });\n if (!!props.onLoading) ctrl.on('loading', props.onLoading);\n if (!!props.onResults) ctrl.on('results', props.onResults);\n if (!!props.onResult) ctrl.on('result', evt => {\n if (props.onResult !== undefined) props.onResult(evt);\n\n const {result} = evt;\n const location =\n result &&\n (result.center || (result.geometry?.type === 'Point' && result.geometry.coordinates));\n if (location && props.marker) {\n const markerProps = typeof props.marker === 'object' ? props.marker : {};\n setMarker( as unknown as SetStateAction);\n } else {\n setMarker(null);\n }\n });\n if (!!props.onError) ctrl.on('error', props.onError);\n return ctrl;\n },\n {\n position: props.position\n }\n );\n\n // @ts-ignore (TS2339) private member\n if (geocoder._map) {\n if (geocoder.getProximity() !== props.proximity && props.proximity !== undefined) {\n geocoder.setProximity(props.proximity);\n }\n if (geocoder.getRenderFunction() !== props.render && props.render !== undefined) {\n geocoder.setRenderFunction(props.render);\n }\n if (geocoder.getLanguage() !== props.language && props.language !== undefined) {\n geocoder.setLanguage(props.language);\n }\n if (geocoder.getZoom() !== props.zoom && props.zoom !== undefined) {\n geocoder.setZoom(props.zoom);\n }\n if (geocoder.getFlyTo() !== props.flyTo && props.flyTo !== undefined) {\n geocoder.setFlyTo(props.flyTo);\n }\n if (geocoder.getPlaceholder() !== props.placeholder && props.placeholder !== undefined) {\n geocoder.setPlaceholder(props.placeholder);\n }\n if (geocoder.getCountries() !== props.countries && props.countries !== undefined) {\n geocoder.setCountries(props.countries);\n }\n if (geocoder.getTypes() !== props.types && props.types !== undefined) {\n geocoder.setTypes(props.types);\n }\n if (geocoder.getMinLength() !== props.minLength && props.minLength !== undefined) {\n geocoder.setMinLength(props.minLength);\n }\n if (geocoder.getLimit() !== props.limit && props.limit !== undefined) {\n geocoder.setLimit(props.limit);\n }\n if (geocoder.getFilter() !== props.filter && props.filter !== undefined) {\n geocoder.setFilter(props.filter);\n }\n if (geocoder.getOrigin() !== props.origin && props.origin !== undefined) {\n geocoder.setOrigin(props.origin);\n }\n // Types missing from @types/mapbox__mapbox-gl-geocoder\n // if (geocoder.getAutocomplete() !== props.autocomplete && props.autocomplete !== undefined) {\n // geocoder.setAutocomplete(props.autocomplete);\n // }\n // if (geocoder.getFuzzyMatch() !== props.fuzzyMatch && props.fuzzyMatch !== undefined) {\n // geocoder.setFuzzyMatch(props.fuzzyMatch);\n // }\n // if (geocoder.getRouting() !== props.routing && props.routing !== undefined) {\n // geocoder.setRouting(props.routing);\n // }\n // if (geocoder.getWorldview() !== props.worldview && props.worldview !== undefined) {\n // geocoder.setWorldview(props.worldview);\n // }\n }\n return marker;\n}\n\nconst noop = () => {};\n"],"names":[],"mappings":";;;;;;;;;;;AAiBA;AACwB,SAAA,eAAe,CAAC,KAA2B,EAAA;IACjE,MAAM,CAAC,MA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KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE;AACvE,YAAA,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAClC;AACD,QAAA,IAAI,QAAQ,CAAC,SAAS,EAAE,KAAK,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE;AACvE,YAAA,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAClC;;;;;;;;;;;;;;KAcF;AACD,IAAA,OAAO,MAAM,CAAC;AAChB;;;;"} \ No newline at end of file +{"version":3,"file":"GeocoderControl.js","sources":["../../../../lib/@cori-risi/components/GeocoderControl.tsx"],"sourcesContent":["import * as React from 'react';\nimport {ReactElement, SetStateAction, useState} from 'react';\nimport {useControl, Marker, MarkerProps, ControlPosition} from 'react-map-gl';\nimport MapboxGeocoder, {GeocoderOptions} from '@mapbox/mapbox-gl-geocoder';\n\ntype GeocoderControlProps = Omit & {\n mapboxAccessToken: string;\n marker?: boolean | Omit;\n\n position: ControlPosition;\n\n onLoading?: (e: object) => void;\n onResults?: (e: object) => void;\n onResult?: (e: object) => void;\n onError?: (e: object) => void;\n};\n\n\n/**\n * This is a Geocoder search component that can be added to any `react-map-gl` Map component.\n *\n * ```ts\n * import mapboxgl from 'mapbox-gl';\n * import Map, { Source, Layer } from 'react-map-gl';\n *\n * import { GeocoderControl } from \"@cori-risi/cori.data.api\";\n *\n * import \"mapbox-gl/dist/mapbox-gl.css\";\n *\n * mapboxgl.accessToken = import.meta.env.VITE_MAPBOX_ACCESS_TOKEN;\n *\n * // ...\n *\n * \n * \n * :\n * \n * \n * \n * ```\n *\n * @param props.mapboxAccessToken - Mapbox API token\n * @param props.marker - `true` or `false` to place marker on result once selected (default: `false`)\n * @param props.position - CSS class to position control in \"top-left\", \"top-right\", \"bottom-left\" or \"bottom-right\" of the map pane\n */\nexport default function GeocoderControl(props: {\n mapboxAccessToken: string,\n marker?: boolean | Omit,\n position: ControlPosition\n}) {\n// } & GeocoderControlProps) {\n const [marker, setMarker] = useState(null);\n \n const geocoder_props = { ...props } as unknown as GeocoderControlProps;\n\n const geocoder = useControl(\n () => {\n const ctrl = new MapboxGeocoder({\n ...geocoder_props,\n marker: marker || false,\n accessToken: geocoder_props.mapboxAccessToken\n });\n if (!!geocoder_props.onLoading) ctrl.on('loading', geocoder_props.onLoading);\n if (!!geocoder_props.onResults) ctrl.on('results', geocoder_props.onResults);\n if (!!geocoder_props.onResult) ctrl.on('result', evt => {\n if (geocoder_props.onResult !== undefined) geocoder_props.onResult(evt);\n\n const {result} = evt;\n const location =\n result &&\n (result.center || (result.geometry?.type === 'Point' && result.geometry.coordinates));\n if (location && geocoder_props.marker) {\n const markerProps = typeof geocoder_props.marker === 'object' ? geocoder_props.marker : {};\n // noinspection TypeScriptValidateTypes\n setMarker( as unknown as SetStateAction);\n } else {\n setMarker(null);\n }\n });\n if (!!geocoder_props.onError) ctrl.on('error', geocoder_props.onError);\n return ctrl;\n },\n {\n position: geocoder_props.position\n }\n );\n\n // @ts-ignore (TS2339) private member\n if (geocoder.hasOwnProperty(\"_map\") && geocoder[\"_map\"]) {\n if (geocoder.getProximity() !== geocoder_props.proximity && geocoder_props.proximity !== undefined) {\n geocoder.setProximity(geocoder_props.proximity);\n }\n if (geocoder.getRenderFunction() !== geocoder_props.render && geocoder_props.render !== undefined) {\n geocoder.setRenderFunction(geocoder_props.render);\n }\n if (geocoder.getLanguage() !== geocoder_props.language && geocoder_props.language !== undefined) {\n geocoder.setLanguage(geocoder_props.language);\n }\n if (geocoder.getZoom() !== geocoder_props.zoom && geocoder_props.zoom !== undefined) {\n geocoder.setZoom(geocoder_props.zoom);\n }\n if (geocoder.getFlyTo() !== geocoder_props.flyTo && geocoder_props.flyTo !== undefined) {\n geocoder.setFlyTo(geocoder_props.flyTo);\n }\n if (geocoder.getPlaceholder() !== geocoder_props.placeholder && geocoder_props.placeholder !== undefined) {\n geocoder.setPlaceholder(geocoder_props.placeholder);\n }\n if (geocoder.getCountries() !== geocoder_props.countries && geocoder_props.countries !== undefined) {\n geocoder.setCountries(geocoder_props.countries);\n }\n if (geocoder.getTypes() !== geocoder_props.types && geocoder_props.types !== undefined) {\n geocoder.setTypes(geocoder_props.types);\n }\n if (geocoder.getMinLength() !== geocoder_props.minLength && geocoder_props.minLength !== undefined) {\n geocoder.setMinLength(geocoder_props.minLength);\n }\n if (geocoder.getLimit() !== geocoder_props.limit && geocoder_props.limit !== undefined) {\n geocoder.setLimit(geocoder_props.limit);\n }\n if (geocoder.getFilter() !== geocoder_props.filter && geocoder_props.filter !== undefined) {\n geocoder.setFilter(geocoder_props.filter);\n }\n if (geocoder.getOrigin() !== geocoder_props.origin && geocoder_props.origin !== undefined) {\n geocoder.setOrigin(geocoder_props.origin);\n }\n if (geocoder.getAutocomplete() !== geocoder_props.autocomplete && geocoder_props.autocomplete !== undefined) {\n geocoder.setAutocomplete(geocoder_props.autocomplete);\n }\n if (geocoder.getFuzzyMatch() !== geocoder_props.fuzzyMatch && geocoder_props.fuzzyMatch !== undefined) {\n geocoder.setFuzzyMatch(geocoder_props.fuzzyMatch);\n }\n if (geocoder.getRouting() !== geocoder_props.routing && geocoder_props.routing !== undefined) {\n geocoder.setRouting(geocoder_props.routing);\n }\n if (geocoder.getWorldview() !== geocoder_props.worldview && geocoder_props.worldview !== undefined) {\n geocoder.setWorldview(geocoder_props.worldview);\n }\n }\n\n return marker;\n}\n\nconst noop = () => {};\n"],"names":[],"mappings":";;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;AACqB,SAAA,eAAe,CAAC,KAIvC,EAAA;;IAEC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AAE3C,IAAA,MAAM,cAAc,GAAG,MAAK,CAAA,MAAA,CAAA,EAAA,EAAA,KAAK,CAAqC,CAAC;AAEvE,IAAA,MAAM,QA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AC,MAAM,KAAK,SAAS,EAAE;AACzF,YAAA,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SAC3C;AACD,QAAA,IAAI,QAAQ,CAAC,SAAS,EAAE,KAAK,cAAc,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,KAAK,SAAS,EAAE;AACzF,YAAA,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;SAC3C;AACD,QAAA,IAAI,QAAQ,CAAC,eAAe,EAAE,KAAK,cAAc,CAAC,YAAY,IAAI,cAAc,CAAC,YAAY,KAAK,SAAS,EAAE;AAC3G,YAAA,QAAQ,CAAC,eAAe,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;SACvD;AACD,QAAA,IAAI,QAAQ,CAAC,aAAa,EAAE,KAAK,cAAc,CAAC,UAAU,IAAI,cAAc,CAAC,UAAU,KAAK,SAAS,EAAE;AACrG,YAAA,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;SACnD;AACD,QAAA,IAAI,QAAQ,CAAC,UAAU,EAAE,KAAK,cAAc,CAAC,OAAO,IAAI,cAAc,CAAC,OAAO,KAAK,SAAS,EAAE;AAC5F,YAAA,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;SAC7C;AACD,QAAA,IAAI,QAAQ,CAAC,YAAY,EAAE,KAAK,cAAc,CAAC,SAAS,IAAI,cAAc,CAAC,SAAS,KAAK,SAAS,EAAE;AAClG,YAAA,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;SACjD;KACF;AAED,IAAA,OAAO,MAAM,CAAC;AAChB;;;;"} \ No newline at end of file diff --git a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts index 3f0e49e3..fa707660 100644 --- a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts +++ b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts @@ -6,16 +6,24 @@ type AmplifyContextType = { userPoolId?: string; userPoolClientId?: string; }; +/** + * This is the configuration context for an Amplify app that uses authentication to connect + * to the [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}. + */ export declare const AmplifyContext: React.Context; /** - * This component provides the Amplify configuration context to an Amplify app, - * which is particularly useful to one that requires authentication in order to - * access the CORI Data API. Other than the children prop, the parameters are + * This component provides the configuration context to an Amplify/React app, which is particularly useful to one that requires + * authentication in order to access the [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}. + * Other than the `children` prop, the parameters are * [AWS Cognito](https://us-east-1.console.aws.amazon.com/cognito/v2/home?region=us-east-1){target=_blank} - * values, passed so that the Amplify configuration method can use the specified User pool + * values that are passed so that the Amplify configuration method can use the specified User pool * and Identity pool to authenticate users (including the `cori-risi-public` user). * * ```ts + * import { AmplifyContextProvider } from "@cori-risi/cori.data.api"; + * + * // ... + * * ; * * ``` * - * @param props.domain - domain for the Cognito Hosted UI and/or OAuth 2.0 endpoints + * @param props.domain s- domain for the Cognito Hosted UI and/or OAuth 2.0 endpoints * @param props.region - AWS region where Cognito service is hosted * @param props.identityPoolId - Cognito Identity pool ID * @param props.userPoolId - Cognito User pool ID diff --git a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts.map b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts.map index 85b599fa..f67996af 100644 --- a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts.map +++ b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"AmplifyContextProvider.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/cotexts/AmplifyContextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAEV,YAAY,EAGf,MAAM,OAAO,CAAC;AAaf,KAAK,kBAAkB,GAAG;IAEtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAG7B,CAAC;AAWF,eAAO,MAAM,cAAc,0CAA+D,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAE,KAAK,EAAE;IACnD,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC5B,qBA8OA"} \ No newline at end of file +{"version":3,"file":"AmplifyContextProvider.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/cotexts/AmplifyContextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAEV,YAAY,EAGf,MAAM,OAAO,CAAC;AAaf,KAAK,kBAAkB,GAAG;IAEtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAG7B,CAAC;AAWF;;;GAGG;AACH,eAAO,MAAM,cAAc,0CAA+D,CAAC;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAE,KAAK,EAAE;IACnD,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC5B,qBA8OA"} \ No newline at end of file diff --git a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js index 19066fe0..2f4b5991 100644 --- a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js +++ b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js @@ -17,16 +17,24 @@ const initAmplifyContext = { userPoolId: undefined, userPoolClientId: undefined, }; +/** + * This is the configuration context for an Amplify app that uses authentication to connect + * to the [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}. + */ const AmplifyContext = createContext(initAmplifyContext); /** - * This component provides the Amplify configuration context to an Amplify app, - * which is particularly useful to one that requires authentication in order to - * access the CORI Data API. Other than the children prop, the parameters are + * This component provides the configuration context to an Amplify/React app, which is particularly useful to one that requires + * authentication in order to access the [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}. + * Other than the `children` prop, the parameters are * [AWS Cognito](https://us-east-1.console.aws.amazon.com/cognito/v2/home?region=us-east-1){target=_blank} - * values, passed so that the Amplify configuration method can use the specified User pool + * values that are passed so that the Amplify configuration method can use the specified User pool * and Identity pool to authenticate users (including the `cori-risi-public` user). * * ```ts + * import { AmplifyContextProvider } from "@cori-risi/cori.data.api"; + * + * // ... + * * * ``` * - * @param props.domain - domain for the Cognito Hosted UI and/or OAuth 2.0 endpoints + * @param props.domain s- domain for the Cognito Hosted UI and/or OAuth 2.0 endpoints * @param props.region - AWS region where Cognito service is hosted * @param props.identityPoolId - Cognito Identity pool ID * @param props.userPoolId - Cognito User pool ID diff --git a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js.map b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js.map index 84e0859c..876f9c94 100644 --- a/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js.map +++ b/inst/dist/@cori-risi/cotexts/AmplifyContextProvider.js.map @@ -1 +1 @@ -{"version":3,"file":"AmplifyContextProvider.js","sources":["../../../../lib/@cori-risi/cotexts/AmplifyContextProvider.tsx"],"sourcesContent":["import React, {\n createContext,\n ReactElement,\n useEffect,\n useState\n} from \"react\";\nimport {Amplify, ResourcesConfig} from \"aws-amplify\";\n\nimport amplifyconfig from './amplifyconfiguration.json';\n\nimport { User } from \"../models\";\n\nAmplify.configure(amplifyconfig);\n\n// let hasAuthSession = false;\n// let hasAuthUser = false;\n// let hasAuthClient = false;\n\ntype AmplifyContextType = {\n // authenticated_user: User | null;\n domain?: string;\n region?: string;\n identityPoolId?: string;\n userPoolId?: string;\n userPoolClientId?: string;\n // TODO:\n // updateUser: Function\n};\n\nconst initAmplifyContext: AmplifyContextType = {\n // authenticated_user: null,\n domain: undefined,\n region: undefined,\n identityPoolId: undefined,\n userPoolId: undefined,\n userPoolClientId: undefined,\n};\n\nexport const AmplifyContext = createContext(initAmplifyContext);\n\n/**\n * This component provides the Amplify configuration context to an Amplify app,\n * which is particularly useful to one that requires authentication in order to\n * access the CORI Data API. Other than the children prop, the parameters are\n * [AWS Cognito](https://us-east-1.console.aws.amazon.com/cognito/v2/home?region=us-east-1){target=_blank}\n * values, passed so that the Amplify configuration method can use the specified User pool\n * and Identity pool to authenticate users (including the `cori-risi-public` user).\n *\n * ```ts\n * \n * \n * \n * ```\n *\n * @param props.domain - domain for the Cognito Hosted UI and/or OAuth 2.0 endpoints\n * @param props.region - AWS region where Cognito service is hosted\n * @param props.identityPoolId - Cognito Identity pool ID\n * @param props.userPoolId - Cognito User pool ID\n * @param props.userPoolClientId - ACognito User pool App client ID (App clients are the user pool authentication resources attached to your app).\n */\nexport default function AmplifyContextProvider (props: {\n children?: ReactElement,\n domain?: string,\n region?: string,\n identityPoolId?: string,\n userPoolId?: string,\n userPoolClientId?: string\n}) {\n\n // const userState = useSelector(selectUser);\n // const dispatch = useDispatch();\n\n // const [ authenticated_user, setAuthenticatedUser ] = useState(userState);\n\n const [ state, setState ] = useState((!!props.domain\n && !!props.region\n && !!props.identityPoolId\n && !!props.userPoolId\n && !!props.userPoolClientId\n ) ?\n {\n // authenticated_user: null,\n ...props\n } :\n initAmplifyContext);\n\n useEffect(() => {\n if (!!props.domain\n && !!props.region\n && !!props.identityPoolId\n && !!props.userPoolId\n && !!props.userPoolClientId\n ) {\n\n const {\n domain,\n region,\n identityPoolId,\n userPoolId,\n userPoolClientId\n } = props;\n\n console.log(\"Configuring Amplify context with props:\", {\n domain,\n region,\n identityPoolId,\n userPoolId,\n userPoolClientId\n });\n\n // Ex. Auth data structure:\n // Auth: {\n // Cognito: {\n // userPoolClientId: \"5eusi16g0o2q1g1rr5ehgudodm\",\n // userPoolId: \"us-east-1_QeA4600FA\",\n // userPoolEndpoint: \"authcori.auth.us-east-1.amazoncognito.com\",\n // identityPoolId: \"us-east-1:2194a76a-fa3d-4c33-999e-e3c4b2b049ee\",\n // loginWith: { // Optional\n // oauth: {\n // domain: 'authcori.auth.us-east-1.amazoncognito.com',\n // scopes: ['email', 'openid', 'profile'],\n // redirectSignIn: [\"http://localhost:3000\", \"http://localhost:5173\", \"http://localhost:5174\"],\n // redirectSignOut: [\"http://localhost:3000/\", \"http://localhost:5173/\", \"http://localhost:5174/\"],\n // responseType: 'code',\n // },\n // username: true,\n // email: true, // Optional\n // phone: false, // Optional\n //\n // },\n // // signUpVerificationMethod: \"\",\n // // userAttributes: \"\",\n // // mfa: \"\",\n // // passwordFormat: \"\",\n // },\n // region: config.region,\n // oauth: {\n // scope: ['email', 'openid', 'profile'],\n // redirectSignIn: '',\n // redirectSignOut: '',\n // responseType: 'code',\n // mandatorySignIn: true,\n // },\n // },\n\n const aws_original_auth_config = {\n \"Auth\": {\n \"domain\": domain,\n \"region\": region,\n \"identityPoolRegion\": region,\n \"identityPoolId\": identityPoolId,\n \"userPoolId\": userPoolId,\n // \"userPoolClientId\": userPoolClientId,\n \"userPoolWebClientId\": userPoolClientId,\n \"clientId\": userPoolClientId,\n \"oauth\": {\n \"domain\": domain,\n // \"scope\": [ \"email\", \"profile\", \"openid\", \"aws.cognito.signin.user.admin\" ],\n // \"scope\": [ \"email\", \"openid\", \"profile\" ],\n // \"scope\": [ \"email\" ],\n \"scope\": [\"openid\"],\n \"redirectSignIn\": window.location.protocol + \"//\" + window.location.hostname + ((!!window.location.port) ? \":\" + window.location.port : \"\"),\n \"redirectSignOut\": window.location.protocol + \"//\" + window.location.hostname + ((!!window.location.port) ? \":\" + window.location.port : \"\") + \"/\",\n \"responseType\": (\"code\" as \"code\") // ... or \"token\", note that REFRESH token will only\n // be generated when the responseType is \"code\"\n }\n }\n };\n\n Amplify.configure(({\n // TODO: Why is this so ridiculous and how can these options be\n // specified exclusively in amplifyconfiguration.json ???\n ...Amplify.getConfig(),\n Auth: {\n ...Amplify.getConfig().Auth!,\n Cognito: {\n ...Amplify.getConfig().Auth!.Cognito!,\n ...aws_original_auth_config.Auth,\n loginWith: {\n ...Amplify.getConfig().Auth!.Cognito!.loginWith!,\n oauth: {\n ...Amplify.getConfig().Auth!.Cognito!.loginWith!.oauth!,\n ...aws_original_auth_config.Auth.oauth,\n redirectSignIn: [\n aws_original_auth_config.Auth.oauth.redirectSignIn\n ],\n redirectSignOut: [\n aws_original_auth_config.Auth.oauth.redirectSignOut\n ],\n responseType: (aws_original_auth_config.Auth.oauth.responseType as \"code\"),\n scopes: [\n ...aws_original_auth_config.Auth.oauth.scope\n ]\n },\n username: true,\n },\n userPoolClientId: aws_original_auth_config.Auth.clientId\n }\n }\n }) as ResourcesConfig);\n\n // const session: Promise = fetchAuthSession();\n //\n // session\n // .then((sess) => {\n //\n // if (!hasAuthSession) {\n //\n // const tokens = sess.tokens!;\n //\n // console.log(\"API tokens:\", tokens);\n //\n // if (!!tokens && tokens.hasOwnProperty(\"idToken\")) {\n //\n // hasAuthSession = true;\n //\n // console.log(\"API Session is authenticated:\", hasAuthSession);\n // console.log(\"API Session config:\", sess);\n //\n // console.log(\"idToken:\", tokens.idToken!);\n // setState({\n // // authenticated_user: authenticated_user,\n // domain,\n // region,\n // identityPoolId,\n // userPoolId,\n // userPoolClientId,\n // token: tokens.idToken!\n // });\n //\n // const user: Promise = getCurrentUser();\n //\n //\n //\n //\n // user.then((u) => {\n // if (!hasAuthUser) {\n //\n // // console.log(\"Initial userState:\", userState);\n //\n // hasAuthUser = true;\n //\n // console.log(\"API User is authenticated:\", hasAuthSession);\n // console.log(\"API User:\", u);\n // console.log(\"API User type:\", u.constructor.name);\n //\n // // function updateUser (u: User) {\n // // try {\n // // if (!!u.userId) {\n // // console.log(\"Update userId:\", u.userId);\n // // dispatch(updateUserId(u.userId));\n // // }\n // // if (!!u.userId && !!u.username) {\n // // console.log(\"Update username:\", u.username);\n // // dispatch(updateUserName(u.username));\n // // }\n // //\n // // if (!!tokens.idToken) {\n // // console.log(\"Update user tokens:\", tokens);\n // // dispatch(updateUserTokens(JSON.stringify(tokens)));\n // // }\n // //\n // // } catch (e: any) {\n // // console.error(e);\n // // }\n // //\n // // setState({\n // // authenticated_user: u,\n // // domain,\n // // region,\n // // identityPoolId,\n // // userPoolId,\n // // userPoolClientId,\n // // token: tokens.idToken!\n // // });\n // //\n // // setAuthenticatedUser(u);\n // // }\n //\n // // updateUser(u);\n // }\n // });\n // }\n // }\n // });\n\n setState({\n // authenticated_user: authenticated_user,\n domain,\n region,\n identityPoolId,\n userPoolId,\n userPoolClientId\n });\n }\n\n }, []);\n\n\n return (<>\n \n {props.children}\n \n );\n\n}\n"],"names":["React"],"mappings":";;;;;;;;;;AAYA,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;AAiBjC,MAAM,kBAAkB,GAAuB;;AAE3C,IAAA,MAAM,EAAE,SAAS;AACjB,IAAA,MAAM,EAAE,SAAS;AACjB,IAAA,cAAc,EAAE,SAAS;AACzB,IAAA,UAAU,EAAE,SAAS;AACrB,IAAA,gBAAgB,EAAE,SAAS;CAC9B,CAAC;MAEW,cAAc,GAAG,aAAa,CAA4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file +{"version":3,"file":"AmplifyContextProvider.js","sources":["../../../../lib/@cori-risi/cotexts/AmplifyContextProvider.tsx"],"sourcesContent":["import React, {\n createContext,\n ReactElement,\n useEffect,\n useState\n} from \"react\";\nimport {Amplify, ResourcesConfig} from \"aws-amplify\";\n\nimport amplifyconfig from './amplifyconfiguration.json';\n\nimport { User } from \"../models\";\n\nAmplify.configure(amplifyconfig);\n\n// let hasAuthSession = false;\n// let hasAuthUser = false;\n// let hasAuthClient = false;\n\ntype AmplifyContextType = {\n // authenticated_user: User | null;\n domain?: string;\n region?: string;\n identityPoolId?: string;\n userPoolId?: string;\n userPoolClientId?: string;\n // TODO:\n // updateUser: Function\n};\n\nconst initAmplifyContext: AmplifyContextType = {\n // authenticated_user: null,\n domain: undefined,\n region: undefined,\n identityPoolId: undefined,\n userPoolId: undefined,\n userPoolClientId: undefined,\n};\n\n/**\n * This is the configuration context for an Amplify app that uses authentication to connect\n * to the [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}.\n */\nexport const AmplifyContext = createContext(initAmplifyContext);\n\n/**\n * This component provides the configuration context to an Amplify/React app, which is particularly useful to one that requires\n * authentication in order to access the [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}.\n * Other than the `children` prop, the parameters are\n * [AWS Cognito](https://us-east-1.console.aws.amazon.com/cognito/v2/home?region=us-east-1){target=_blank}\n * values that are passed so that the Amplify configuration method can use the specified User pool\n * and Identity pool to authenticate users (including the `cori-risi-public` user).\n *\n * ```ts\n * import { AmplifyContextProvider } from \"@cori-risi/cori.data.api\";\n *\n * // ...\n *\n * \n * \n * \n * ```\n *\n * @param props.domain s- domain for the Cognito Hosted UI and/or OAuth 2.0 endpoints\n * @param props.region - AWS region where Cognito service is hosted\n * @param props.identityPoolId - Cognito Identity pool ID\n * @param props.userPoolId - Cognito User pool ID\n * @param props.userPoolClientId - ACognito User pool App client ID (App clients are the user pool authentication resources attached to your app).\n */\nexport default function AmplifyContextProvider (props: {\n children?: ReactElement,\n domain?: string,\n region?: string,\n identityPoolId?: string,\n userPoolId?: string,\n userPoolClientId?: string\n}) {\n\n // const userState = useSelector(selectUser);\n // const dispatch = useDispatch();\n\n // const [ authenticated_user, setAuthenticatedUser ] = useState(userState);\n\n const [ state, setState ] = useState((!!props.domain\n && !!props.region\n && !!props.identityPoolId\n && !!props.userPoolId\n && !!props.userPoolClientId\n ) ?\n {\n // authenticated_user: null,\n ...props\n } :\n initAmplifyContext);\n\n useEffect(() => {\n if (!!props.domain\n && !!props.region\n && !!props.identityPoolId\n && !!props.userPoolId\n && !!props.userPoolClientId\n ) {\n\n const {\n domain,\n region,\n identityPoolId,\n userPoolId,\n userPoolClientId\n } = props;\n\n console.log(\"Configuring Amplify context with props:\", {\n domain,\n region,\n identityPoolId,\n userPoolId,\n userPoolClientId\n });\n\n // Ex. Auth data structure:\n // Auth: {\n // Cognito: {\n // userPoolClientId: \"5eusi16g0o2q1g1rr5ehgudodm\",\n // userPoolId: \"us-east-1_QeA4600FA\",\n // userPoolEndpoint: \"authcori.auth.us-east-1.amazoncognito.com\",\n // identityPoolId: \"us-east-1:2194a76a-fa3d-4c33-999e-e3c4b2b049ee\",\n // loginWith: { // Optional\n // oauth: {\n // domain: 'authcori.auth.us-east-1.amazoncognito.com',\n // scopes: ['email', 'openid', 'profile'],\n // redirectSignIn: [\"http://localhost:3000\", \"http://localhost:5173\", \"http://localhost:5174\"],\n // redirectSignOut: [\"http://localhost:3000/\", \"http://localhost:5173/\", \"http://localhost:5174/\"],\n // responseType: 'code',\n // },\n // username: true,\n // email: true, // Optional\n // phone: false, // Optional\n //\n // },\n // // signUpVerificationMethod: \"\",\n // // userAttributes: \"\",\n // // mfa: \"\",\n // // passwordFormat: \"\",\n // },\n // region: config.region,\n // oauth: {\n // scope: ['email', 'openid', 'profile'],\n // redirectSignIn: '',\n // redirectSignOut: '',\n // responseType: 'code',\n // mandatorySignIn: true,\n // },\n // },\n\n const aws_original_auth_config = {\n \"Auth\": {\n \"domain\": domain,\n \"region\": region,\n \"identityPoolRegion\": region,\n \"identityPoolId\": identityPoolId,\n \"userPoolId\": userPoolId,\n // \"userPoolClientId\": userPoolClientId,\n \"userPoolWebClientId\": userPoolClientId,\n \"clientId\": userPoolClientId,\n \"oauth\": {\n \"domain\": domain,\n // \"scope\": [ \"email\", \"profile\", \"openid\", \"aws.cognito.signin.user.admin\" ],\n // \"scope\": [ \"email\", \"openid\", \"profile\" ],\n // \"scope\": [ \"email\" ],\n \"scope\": [\"openid\"],\n \"redirectSignIn\": window.location.protocol + \"//\" + window.location.hostname + ((!!window.location.port) ? \":\" + window.location.port : \"\"),\n \"redirectSignOut\": window.location.protocol + \"//\" + window.location.hostname + ((!!window.location.port) ? \":\" + window.location.port : \"\") + \"/\",\n \"responseType\": (\"code\" as \"code\") // ... or \"token\", note that REFRESH token will only\n // be generated when the responseType is \"code\"\n }\n }\n };\n\n Amplify.configure(({\n // TODO: Why is this so ridiculous and how can these options be\n // specified exclusively in amplifyconfiguration.json ???\n ...Amplify.getConfig(),\n Auth: {\n ...Amplify.getConfig().Auth!,\n Cognito: {\n ...Amplify.getConfig().Auth!.Cognito!,\n ...aws_original_auth_config.Auth,\n loginWith: {\n ...Amplify.getConfig().Auth!.Cognito!.loginWith!,\n oauth: {\n ...Amplify.getConfig().Auth!.Cognito!.loginWith!.oauth!,\n ...aws_original_auth_config.Auth.oauth,\n redirectSignIn: [\n aws_original_auth_config.Auth.oauth.redirectSignIn\n ],\n redirectSignOut: [\n aws_original_auth_config.Auth.oauth.redirectSignOut\n ],\n responseType: (aws_original_auth_config.Auth.oauth.responseType as \"code\"),\n scopes: [\n ...aws_original_auth_config.Auth.oauth.scope\n ]\n },\n username: true,\n },\n userPoolClientId: aws_original_auth_config.Auth.clientId\n }\n }\n }) as ResourcesConfig);\n\n // const session: Promise = fetchAuthSession();\n //\n // session\n // .then((sess) => {\n //\n // if (!hasAuthSession) {\n //\n // const tokens = sess.tokens!;\n //\n // console.log(\"API tokens:\", tokens);\n //\n // if (!!tokens && tokens.hasOwnProperty(\"idToken\")) {\n //\n // hasAuthSession = true;\n //\n // console.log(\"API Session is authenticated:\", hasAuthSession);\n // console.log(\"API Session config:\", sess);\n //\n // console.log(\"idToken:\", tokens.idToken!);\n // setState({\n // // authenticated_user: authenticated_user,\n // domain,\n // region,\n // identityPoolId,\n // userPoolId,\n // userPoolClientId,\n // token: tokens.idToken!\n // });\n //\n // const user: Promise = getCurrentUser();\n //\n //\n //\n //\n // user.then((u) => {\n // if (!hasAuthUser) {\n //\n // // console.log(\"Initial userState:\", userState);\n //\n // hasAuthUser = true;\n //\n // console.log(\"API User is authenticated:\", hasAuthSession);\n // console.log(\"API User:\", u);\n // console.log(\"API User type:\", u.constructor.name);\n //\n // // function updateUser (u: User) {\n // // try {\n // // if (!!u.userId) {\n // // console.log(\"Update userId:\", u.userId);\n // // dispatch(updateUserId(u.userId));\n // // }\n // // if (!!u.userId && !!u.username) {\n // // console.log(\"Update username:\", u.username);\n // // dispatch(updateUserName(u.username));\n // // }\n // //\n // // if (!!tokens.idToken) {\n // // console.log(\"Update user tokens:\", tokens);\n // // dispatch(updateUserTokens(JSON.stringify(tokens)));\n // // }\n // //\n // // } catch (e: any) {\n // // console.error(e);\n // // }\n // //\n // // setState({\n // // authenticated_user: u,\n // // domain,\n // // region,\n // // identityPoolId,\n // // userPoolId,\n // // userPoolClientId,\n // // token: tokens.idToken!\n // // });\n // //\n // // setAuthenticatedUser(u);\n // // }\n //\n // // updateUser(u);\n // }\n // });\n // }\n // }\n // });\n\n setState({\n // authenticated_user: authenticated_user,\n domain,\n region,\n identityPoolId,\n userPoolId,\n userPoolClientId\n });\n }\n\n }, []);\n\n\n return (<>\n \n {props.children}\n \n );\n\n}\n"],"names":["React"],"mappings":";;;;;;;;;;AAYA,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;AAiBjC,MAAM,kBAAkB,GAAuB;;AAE3C,IAAA,MAAM,EAAE,SAAS;AACjB,IAAA,MAAM,EAAE,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A;AACJ,QAAAA,cAAA,CAAA,aAAA,CAAC,cAAc,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAChC,EAAA,KAAK,CAAC,QAAQ,CACO,CAC3B,EAAE;AAET;;;;"} \ No newline at end of file diff --git a/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts b/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts index 02700ec7..4b540663 100644 --- a/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts +++ b/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts @@ -3,7 +3,20 @@ import { AxiosInstance } from 'axios'; import { JWT } from "@aws-amplify/auth"; import "./styles/ApiContextProvider.css"; import { User } from "../models"; -interface ApiContextType { +/** + * This is the interface/type of the [`ApiContext`](../variables/ApiContext.md). + * + * @property apiClient Axios client for RESTful services + * @property authenticated `true` if the ApiContextProvider has established an authenticated session + * @property authenticated_user the current user state if the ApiContextProvider has established an authenticated session + * @property autoSignOut a function that can be called to terminate the current session (if using authentication) + * @property baseURL Base URL for RESTful service + * @property token id token retrieved from Cognito which is used in requests made by the `apiClient` (if using authentication) + * @property data read-only data store + * @property setData setter to update data store + * @interface + */ +export interface ApiContextType { apiClient: AxiosInstance; authenticated: boolean; authenticated_user: User | null; @@ -13,7 +26,63 @@ interface ApiContextType { data: any; setData: ((newData: any) => void) | null; } +/** + * This is the data/api context for a React app that uses network requests to fetch data from either a RESTful + * service backend or a GraphQL service backend (both are available in the + * [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}). See + * [`ApiContextType`](../interfaces/ApiContextType.md) for a list of props offered by this context. + * + * Note that GraphQL queries require a special client that can be instantiated by an additional context provider component + * (i.e. [ApolloGraphQLProvider](https://github.com/ruralinnovation/amplify-bcat/tree/main/src/%40cori-risi/bcat/contexts){target=_blank}). + * + */ export declare const ApiContext: React.Context; +/** + * This component provides the API/data service context ([`ApiContext`](../variables/ApiContext.md)) to a React + * application. The following example assumes that the `App` component has been configured by the + * [`AmplifyContextProvider`](../functions/AmplifyContextProvider.md) to allow for authentication + * with AWS Cognito, but this provider can also be used to setup an ApiContext with no authentication (by only using + * the `baseURL` param/prop and disregarding the other props): + * + * ```ts + * import { + * withAuthenticator, + * useAuthenticator, + * UseAuthenticator, useTheme, Heading + * } from '@aws-amplify/ui-react'; + * import { fetchAuthSession } from "@aws-amplify/auth"; + * import { getCurrentUser } from "@aws-amplify/auth/cognito"; + * import { AmplifyContext, ApiContextProvider } from "@cori-risi/cori.data.api"; + * + * // ... + * + * const App = () => { + * + * const amplifyContext = useContext(AmplifyContext); + * const authenticator: UseAuthenticator = useAuthenticator(); + * + * // ... + * + * return ( + * + * + * + * ); + * } + * + * export default withAuthenticator(App, { + * ... + * }); + * ``` + * + * @param props.baseURL - Base URL for the RESTful API endpoint, e.g., https://cori-data-api.ruralinnovation.us. + * @param props.fetchAuthSession - An optional function from the Amplify Auth package to start an authenticated session + * @param props.getCurrentUser - An optional function from the Amplify Cognito package to fetch the current authenticated user (if any) + * @param props.signOut - An optional function that is one of many destructured props contained in the Amplify authenticator context (returned by the useAuthenticator() hoook), used to sign out the current user. + */ export default function ApiContextProvider(props: { children?: ReactElement; baseURL?: string; @@ -21,5 +90,4 @@ export default function ApiContextProvider(props: { getCurrentUser?: Function; signOut?: Function; }): React.JSX.Element; -export {}; //# sourceMappingURL=ApiContextProvider.d.ts.map \ No newline at end of file diff --git a/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts.map b/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts.map index d35e5caa..fe10be80 100644 --- a/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts.map +++ b/inst/dist/@cori-risi/cotexts/ApiContextProvider.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"ApiContextProvider.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/cotexts/ApiContextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAEV,YAAY,EAIf,MAAM,OAAO,CAAC;AACf,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAc,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAepD,OAAO,iCAAiC,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAyBjC,UAAU,cAAc;IACpB,SAAS,EAAE,aAAa,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,IAAI,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5C;AAoBD,eAAO,MAAM,UAAU,sCAAkD,CAAC;AAM1E,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAE,KAAK,EAAE;IAC/C,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IAC5B,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B,OAAO,CAAC,EAAE,QAAQ,CAAA;CACrB,qBAqMA"} \ No newline at end of file +{"version":3,"file":"ApiContextProvider.d.ts","sourceRoot":"","sources":["../../../../lib/@cori-risi/cotexts/ApiContextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAEV,YAAY,EAIf,MAAM,OAAO,CAAC;AACf,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAc,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAUpD,OAAO,iCAAiC,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAwBjC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,cAAc;IAC3B,SAAS,EAAE,aAAa,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,IAAI,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5C;AAoBD;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,sCAAkD,CAAC;AAM1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAE,KAAK,EAAE;IAC/C,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IAC5B,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B,OAAO,CAAC,EAAE,QAAQ,CAAA;CACrB,qBAqMA"} \ No newline at end of file diff --git a/inst/dist/@cori-risi/cotexts/ApiContextProvider.js b/inst/dist/@cori-risi/cotexts/ApiContextProvider.js index 668b6579..e1824ee5 100644 --- a/inst/dist/@cori-risi/cotexts/ApiContextProvider.js +++ b/inst/dist/@cori-risi/cotexts/ApiContextProvider.js @@ -7,7 +7,7 @@ import React__default, { createContext, useState, useEffect } from 'react'; import axios from 'axios'; -const BASE_URL = "http://localhost:8000"; // `${import.meta.env.VITE_CORI_DATA_API}`; +const BASE_URL = "https://cori-data-api.ruralinnovation.us/"; // `${import.meta.env.VITE_CORI_DATA_API}`; const apiClient = axios.create({ baseURL: BASE_URL, headers: { @@ -24,9 +24,65 @@ const initState = { data: {}, setData: null }; +/** + * This is the data/api context for a React app that uses network requests to fetch data from either a RESTful + * service backend or a GraphQL service backend (both are available in the + * [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}). See + * [`ApiContextType`](../interfaces/ApiContextType.md) for a list of props offered by this context. + * + * Note that GraphQL queries require a special client that can be instantiated by an additional context provider component + * (i.e. [ApolloGraphQLProvider](https://github.com/ruralinnovation/amplify-bcat/tree/main/src/%40cori-risi/bcat/contexts){target=_blank}). + * + */ const ApiContext = createContext(initState); let hasAuthSession = false; let hasAuthUser = false; +/** + * This component provides the API/data service context ([`ApiContext`](../variables/ApiContext.md)) to a React + * application. The following example assumes that the `App` component has been configured by the + * [`AmplifyContextProvider`](../functions/AmplifyContextProvider.md) to allow for authentication + * with AWS Cognito, but this provider can also be used to setup an ApiContext with no authentication (by only using + * the `baseURL` param/prop and disregarding the other props): + * + * ```ts + * import { + * withAuthenticator, + * useAuthenticator, + * UseAuthenticator, useTheme, Heading + * } from '@aws-amplify/ui-react'; + * import { fetchAuthSession } from "@aws-amplify/auth"; + * import { getCurrentUser } from "@aws-amplify/auth/cognito"; + * import { AmplifyContext, ApiContextProvider } from "@cori-risi/cori.data.api"; + * + * // ... + * + * const App = () => { + * + * const amplifyContext = useContext(AmplifyContext); + * const authenticator: UseAuthenticator = useAuthenticator(); + * + * // ... + * + * return ( + * + * + * + * ); + * } + * + * export default withAuthenticator(App, { + * ... + * }); + * ``` + * + * @param props.baseURL - Base URL for the RESTful API endpoint, e.g., https://cori-data-api.ruralinnovation.us. + * @param props.fetchAuthSession - An optional function from the Amplify Auth package to start an authenticated session + * @param props.getCurrentUser - An optional function from the Amplify Cognito package to fetch the current authenticated user (if any) + * @param props.signOut - An optional function that is one of many destructured props contained in the Amplify authenticator context (returned by the useAuthenticator() hoook), used to sign out the current user. + */ function ApiContextProvider(props) { useState(null); // const userState = useSelector(selectUser); diff --git a/inst/dist/@cori-risi/cotexts/ApiContextProvider.js.map b/inst/dist/@cori-risi/cotexts/ApiContextProvider.js.map index ac85d2e7..25f91936 100644 --- a/inst/dist/@cori-risi/cotexts/ApiContextProvider.js.map +++ b/inst/dist/@cori-risi/cotexts/ApiContextProvider.js.map @@ -1 +1 @@ -{"version":3,"file":"ApiContextProvider.js","sources":["../../../../lib/@cori-risi/cotexts/ApiContextProvider.tsx"],"sourcesContent":["import React, {\n createContext,\n ReactElement,\n // useContext,\n useEffect,\n useState\n} from \"react\";\nimport axios, { AxiosInstance } from 'axios';\nimport { AuthTokens, JWT } from \"@aws-amplify/auth\";\n// import { getCurrentUser } from \"@aws-amplify/auth/cognito\";\n// import { useAuthenticator, UseAuthenticator } from \"@aws-amplify/ui-react\";\n// import { useDispatch, useSelector } from \"react-redux\";\n// import {\n// updateUserId,\n// updateUserName,\n// updateUserTokens,\n// selectUser\n// } from \"../features\";\n// import { User } from '../models';\n\n// TODO: (maybe?) move the token retrieval code & state prop to AmplifyContextProvider\n// import { AmplifyContext } from \"./AmplifyContextProvider\";\n\nimport \"./styles/ApiContextProvider.css\";\nimport { User } from \"../models\";\nimport { autoSignOut } from \"../utils\";\n\nconst BASE_URL = \"http://localhost:8000\"; // `${import.meta.env.VITE_CORI_DATA_API}`;\n// TODO: From now on must pass dev/prod API url in as param to ApiContextProvider because:\n// cori.data.api/lib/@cori-risi/cotexts/ApiContextProvider.tsx:22\n// const BASE_URL = `${import.meta.env.VITE_CORI_DATA_API}`;\n// ^^^^\n// SyntaxError: Cannot use 'import.meta' outside a module\n//\n\ntype AWSCredentials = {\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n expiration?: Date;\n};\n\ntype AuthSession = {\n tokens?: AuthTokens;\n credentials?: AWSCredentials;\n identityId?: string;\n userSub?: string;\n};\n\ninterface ApiContextType {\n apiClient: AxiosInstance;\n authenticated: boolean;\n authenticated_user: User | null;\n autoSignOut: (() => void) | null;\n baseURL: string;\n token: JWT | null;\n data: any;\n setData: ((newData: any) => void) | null;\n}\n\nconst apiClient: AxiosInstance = axios.create({\n baseURL: BASE_URL,\n headers: {\n 'Content-Type': 'application/json'\n },\n});\n\nconst initState: ApiContextType = {\n apiClient: apiClient,\n authenticated: false,\n authenticated_user: null,\n autoSignOut: null,\n baseURL: BASE_URL,\n token: null,\n data: {},\n setData: null\n};\n\nexport const ApiContext = createContext(initState);\n\nlet hasAuthSession = false;\nlet hasAuthUser = false;\nlet hasAuthClient = false;\n\nexport default function ApiContextProvider (props: {\n children?: ReactElement,\n baseURL?: string,\n fetchAuthSession?: Function,\n getCurrentUser?: Function,\n signOut?: Function\n}) {\n\n const [ authenticated_user, setAuthenticatedUser ] = useState(null);\n // const userState = useSelector(selectUser);\n // const dispatch = useDispatch();\n\n const [ state, setState ] = useState(initState);\n\n function setData(newData: any) {\n const currentState: ApiContextType = state!;\n setState({\n ...currentState,\n data: {\n ...currentState.data,\n ...newData\n },\n setData: setData\n });\n }\n\n useEffect(() => {\n\n apiClient.interceptors.request.use(\n (config) => {\n if (!!props.baseURL) {\n config.baseURL = props.baseURL;\n }\n return config;\n },\n (error) => Promise.reject(error)\n );\n\n setState({\n ...state,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL,\n setData\n });\n\n if (!!props.fetchAuthSession) {\n\n const {\n fetchAuthSession\n } = props;\n\n const session: Promise = fetchAuthSession();\n\n session\n .then((sess) => {\n\n if (!hasAuthSession) {\n\n const tokens = sess.tokens!;\n\n console.log(\"API tokens:\", tokens);\n\n if (!!tokens && tokens.hasOwnProperty(\"idToken\")) {\n\n hasAuthSession = true;\n\n console.log(\"API Session is authenticated:\", hasAuthSession);\n console.log(\"API Session config:\", sess);\n\n console.log(\"idToken:\", tokens.idToken!);\n\n apiClient.interceptors.request.use(\n (config) => {\n const accessToken = tokens.idToken!;\n if (!!accessToken) {\n config.headers.Authorization = `Bearer ${accessToken}`;\n }\n if (!!props.baseURL) {\n config.baseURL = props.baseURL;\n }\n return config;\n },\n (error) => Promise.reject(error)\n );\n\n setState({\n ...state,\n authenticated: true,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n setData,\n token: tokens.idToken!\n });\n\n // TODO: Use autoSignOut to prompt user to refresh session on API error\n // const remoteAPIStartTime = performance.now();\n // apiClient.get(...)\n // .then(response => ...)\n // .catch(error => {\n // const remoteAPIEndTime = performance.now();\n //\n // (window as any)[\"remoteAPIExecutionTime\"] = remoteAPIEndTime - remoteAPIStartTime;\n // console.debug(`Remote API Call Execution took ${(window as any)[\"remoteAPIExecutionTime\"]} ms`);\n //\n // if (error.hasOwnProperty(\"code\")) {\n // console.log(\"Error code:\", error.code!);\n // if (error.code! === \"ERR_BAD_REQUEST\"\n // || error.code! === \"ERR_NETWORK\"\n // ) {\n // autoSignOut();\n //\n // } else if (error.code === 'ERR_NAME_NOT_RESOLVED') {\n // console.error('Invalid baseURL:', apiClient.defaults.baseURL);\n // // Handle invalid baseURL error\n // }\n // } else {\n // console.log(error.toString());\n // }\n // });\n\n if (!!props.getCurrentUser) {\n\n const { getCurrentUser } = props;\n\n const user: Promise = getCurrentUser();\n\n user.then((u) => {\n if (!hasAuthUser) {\n\n // console.log(\"Initial userState:\", userState);\n\n hasAuthUser = true;\n\n console.log(\"API User is authenticated:\", hasAuthSession);\n console.log(\"API User:\", u);\n console.log(\"API User type:\", u.constructor.name);\n\n // function updateUser (u: User) {\n // try {\n // if (!!u.userId) {\n // console.log(\"Update userId:\", u.userId);\n // dispatch(updateUserId(u.userId));\n // }\n // if (!!u.userId && !!u.username) {\n // console.log(\"Update username:\", u.username);\n // dispatch(updateUserName(u.username));\n // }\n //\n // if (!!tokens.idToken) {\n // console.log(\"Update user tokens:\", tokens);\n // dispatch(updateUserTokens(JSON.stringify(tokens)));\n // }\n //\n // } catch (e: any) {\n // console.error(e);\n // }\n\n setState({\n ...state,\n authenticated: true,\n authenticated_user: u,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n setData,\n token: tokens.idToken!\n });\n\n // setAuthenticatedUser(u);\n // }\n\n // updateUser(u);\n }\n });\n }\n }\n }\n });\n }\n\n }, []);\n\n return (<>\n \n {/**/}\n {props.children}\n {/**/}\n \n );\n}\n"],"names":["React"],"mappings":";;;;;;;;;AA2BA,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAiCzC,MAAM,SAAS,GAAkB,KAAK,CAAC,MAAM,CAAC;AAC1C,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,OAAO,EAAE;AACL,QAAA,cAAc,EAAE,kBAAkB;AACrC,KAAA;AACJ,CAAA,CAAC,CAAC;AAEH,MAAM,SAAS,GAAmB;AAC9B,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,aAAa,EAAE,KAAK;AACpB,IAAA,kBAAkB,EAAE,IAAI;AACxB,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,IAAI,EAAE,EAAE;AACR,IAAA,OAAO,EAAE,IAAI;CAChB,CAAC;MAEW,UAAU,GAAG,aAAa,CAAwB,SAAS,EAAE;AAE1E,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,WAAW,GAAG,KAAK,CAAC;AAGA,SAAA,kBAAkB,CAAE,KAM3C,EAAA;IAEwD,QAAQ,CAAc,IAAI,EAAE;;;IAIjF,MAAM,CAAE,KAAK,EAAE,Q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,WAAW,CAAC,IAAI,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;AAsB9C,oCAAA,QAAQ,CACD,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,KAAK,CACR,EAAA,EAAA,aAAa,EAAE,IAAI,EACnB,kBAAkB,EAAE,CAAC,EACrB,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,IAAI,MAAK;AACzE,4CAAA,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;4CAC1B,CAAC,OAAQ,GAAG,CAAC;AACb,4CAAA,MAAM,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;4CACpF,MAAc,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;yCAChH,GAAG,IAAI,EACR,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,QAAQ,EAClC,OAAO,EACP,KAAK,EAAE,MAAM,CAAC,OAAQ,EAAA,CAAA,CACxB,CAAC;;;;iCAMV;AACL,6BAAC,CAAC,CAAC;yBACN;qBACJ;iBACJ;AACL,aAAC,CAAC,CAAC;SACV;KAEJ,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,QAAQA,cAAA,CAAA,aAAA,CAAAA,cAAA,CAAA,QAAA,EAAA,IAAA;AACJ,QAAAA,cAAA,CAAA,aAAA,CAAC,UAAU,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAExB,EAAA,KAAK,CAAC,QAAQ,CAED,CACvB,EAAE;AACT;;;;"} \ No newline at end of file +{"version":3,"file":"ApiContextProvider.js","sources":["../../../../lib/@cori-risi/cotexts/ApiContextProvider.tsx"],"sourcesContent":["import React, {\n createContext,\n ReactElement,\n // useContext,\n useEffect,\n useState\n} from \"react\";\nimport axios, { AxiosInstance } from 'axios';\nimport { AuthTokens, JWT } from \"@aws-amplify/auth\";\n// import { useDispatch, useSelector } from \"react-redux\";\n// import {\n// updateUserId,\n// updateUserName,\n// updateUserTokens,\n// selectUser\n// } from \"../features\";\n// import { User } from '../models';\n\nimport \"./styles/ApiContextProvider.css\";\nimport { User } from \"../models\";\n\nconst BASE_URL = \"https://cori-data-api.ruralinnovation.us/\"; // `${import.meta.env.VITE_CORI_DATA_API}`;\n// TODO: From now on must pass dev/prod API url in as param to ApiContextProvider because:\n// cori.data.api/lib/@cori-risi/cotexts/ApiContextProvider.tsx:22\n// const BASE_URL = `${import.meta.env.VITE_CORI_DATA_API}`;\n// ^^^^\n// SyntaxError: Cannot use 'import.meta' outside a module\n//\n\ntype AWSCredentials = {\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n expiration?: Date;\n};\n\ntype AuthSession = {\n tokens?: AuthTokens;\n credentials?: AWSCredentials;\n identityId?: string;\n userSub?: string;\n};\n\n/**\n * This is the interface/type of the [`ApiContext`](../variables/ApiContext.md).\n *\n * @property apiClient Axios client for RESTful services\n * @property authenticated `true` if the ApiContextProvider has established an authenticated session\n * @property authenticated_user the current user state if the ApiContextProvider has established an authenticated session\n * @property autoSignOut a function that can be called to terminate the current session (if using authentication)\n * @property baseURL Base URL for RESTful service\n * @property token id token retrieved from Cognito which is used in requests made by the `apiClient` (if using authentication)\n * @property data read-only data store\n * @property setData setter to update data store\n * @interface\n */\nexport interface ApiContextType {\n apiClient: AxiosInstance;\n authenticated: boolean;\n authenticated_user: User | null;\n autoSignOut: (() => void) | null;\n baseURL: string;\n token: JWT | null;\n data: any;\n setData: ((newData: any) => void) | null;\n}\n\nconst apiClient: AxiosInstance = axios.create({\n baseURL: BASE_URL,\n headers: {\n 'Content-Type': 'application/json'\n },\n});\n\nconst initState: ApiContextType = {\n apiClient: apiClient,\n authenticated: false,\n authenticated_user: null,\n autoSignOut: null,\n baseURL: BASE_URL,\n token: null,\n data: {},\n setData: null\n};\n\n/**\n * This is the data/api context for a React app that uses network requests to fetch data from either a RESTful\n * service backend or a GraphQL service backend (both are available in the\n * [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}). See\n * [`ApiContextType`](../interfaces/ApiContextType.md) for a list of props offered by this context.\n *\n * Note that GraphQL queries require a special client that can be instantiated by an additional context provider component\n * (i.e. [ApolloGraphQLProvider](https://github.com/ruralinnovation/amplify-bcat/tree/main/src/%40cori-risi/bcat/contexts){target=_blank}).\n *\n */\nexport const ApiContext = createContext(initState);\n\nlet hasAuthSession = false;\nlet hasAuthUser = false;\nlet hasAuthClient = false;\n\n/**\n * This component provides the API/data service context ([`ApiContext`](../variables/ApiContext.md)) to a React\n * application. The following example assumes that the `App` component has been configured by the\n * [`AmplifyContextProvider`](../functions/AmplifyContextProvider.md) to allow for authentication\n * with AWS Cognito, but this provider can also be used to setup an ApiContext with no authentication (by only using\n * the `baseURL` param/prop and disregarding the other props):\n *\n * ```ts\n * import {\n * withAuthenticator,\n * useAuthenticator,\n * UseAuthenticator, useTheme, Heading\n * } from '@aws-amplify/ui-react';\n * import { fetchAuthSession } from \"@aws-amplify/auth\";\n * import { getCurrentUser } from \"@aws-amplify/auth/cognito\";\n * import { AmplifyContext, ApiContextProvider } from \"@cori-risi/cori.data.api\";\n *\n * // ...\n *\n * const App = () => {\n *\n * const amplifyContext = useContext(AmplifyContext);\n * const authenticator: UseAuthenticator = useAuthenticator();\n *\n * // ...\n *\n * return (\n * \n * \n * \n * );\n * }\n *\n * export default withAuthenticator(App, {\n * ...\n * });\n * ```\n *\n * @param props.baseURL - Base URL for the RESTful API endpoint, e.g., https://cori-data-api.ruralinnovation.us.\n * @param props.fetchAuthSession - An optional function from the Amplify Auth package to start an authenticated session\n * @param props.getCurrentUser - An optional function from the Amplify Cognito package to fetch the current authenticated user (if any)\n * @param props.signOut - An optional function that is one of many destructured props contained in the Amplify authenticator context (returned by the useAuthenticator() hoook), used to sign out the current user.\n */\nexport default function ApiContextProvider (props: {\n children?: ReactElement,\n baseURL?: string,\n fetchAuthSession?: Function,\n getCurrentUser?: Function,\n signOut?: Function\n}) {\n\n const [ authenticated_user, setAuthenticatedUser ] = useState(null);\n // const userState = useSelector(selectUser);\n // const dispatch = useDispatch();\n\n const [ state, setState ] = useState(initState);\n\n function setData(newData: any) {\n const currentState: ApiContextType = state!;\n setState({\n ...currentState,\n data: {\n ...currentState.data,\n ...newData\n },\n setData: setData\n });\n }\n\n useEffect(() => {\n\n apiClient.interceptors.request.use(\n (config) => {\n if (!!props.baseURL) {\n config.baseURL = props.baseURL;\n }\n return config;\n },\n (error) => Promise.reject(error)\n );\n\n setState({\n ...state,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL,\n setData\n });\n\n if (!!props.fetchAuthSession) {\n\n const {\n fetchAuthSession\n } = props;\n\n const session: Promise = fetchAuthSession();\n\n session\n .then((sess) => {\n\n if (!hasAuthSession) {\n\n const tokens = sess.tokens!;\n\n console.log(\"API tokens:\", tokens);\n\n if (!!tokens && tokens.hasOwnProperty(\"idToken\")) {\n\n hasAuthSession = true;\n\n console.log(\"API Session is authenticated:\", hasAuthSession);\n console.log(\"API Session config:\", sess);\n\n console.log(\"idToken:\", tokens.idToken!);\n\n apiClient.interceptors.request.use(\n (config) => {\n const accessToken = tokens.idToken!;\n if (!!accessToken) {\n config.headers.Authorization = `Bearer ${accessToken}`;\n }\n if (!!props.baseURL) {\n config.baseURL = props.baseURL;\n }\n return config;\n },\n (error) => Promise.reject(error)\n );\n\n setState({\n ...state,\n authenticated: true,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n setData,\n token: tokens.idToken!\n });\n\n // TODO: Use autoSignOut to prompt user to refresh session on API error\n // const remoteAPIStartTime = performance.now();\n // apiClient.get(...)\n // .then(response => ...)\n // .catch(error => {\n // const remoteAPIEndTime = performance.now();\n //\n // (window as any)[\"remoteAPIExecutionTime\"] = remoteAPIEndTime - remoteAPIStartTime;\n // console.debug(`Remote API Call Execution took ${(window as any)[\"remoteAPIExecutionTime\"]} ms`);\n //\n // if (error.hasOwnProperty(\"code\")) {\n // console.log(\"Error code:\", error.code!);\n // if (error.code! === \"ERR_BAD_REQUEST\"\n // || error.code! === \"ERR_NETWORK\"\n // ) {\n // autoSignOut();\n //\n // } else if (error.code === 'ERR_NAME_NOT_RESOLVED') {\n // console.error('Invalid baseURL:', apiClient.defaults.baseURL);\n // // Handle invalid baseURL error\n // }\n // } else {\n // console.log(error.toString());\n // }\n // });\n\n if (!!props.getCurrentUser) {\n\n const { getCurrentUser } = props;\n\n const user: Promise = getCurrentUser();\n\n user.then((u) => {\n if (!hasAuthUser) {\n\n // console.log(\"Initial userState:\", userState);\n\n hasAuthUser = true;\n\n console.log(\"API User is authenticated:\", hasAuthSession);\n console.log(\"API User:\", u);\n console.log(\"API User type:\", u.constructor.name);\n\n // function updateUser (u: User) {\n // try {\n // if (!!u.userId) {\n // console.log(\"Update userId:\", u.userId);\n // dispatch(updateUserId(u.userId));\n // }\n // if (!!u.userId && !!u.username) {\n // console.log(\"Update username:\", u.username);\n // dispatch(updateUserName(u.username));\n // }\n //\n // if (!!tokens.idToken) {\n // console.log(\"Update user tokens:\", tokens);\n // dispatch(updateUserTokens(JSON.stringify(tokens)));\n // }\n //\n // } catch (e: any) {\n // console.error(e);\n // }\n\n setState({\n ...state,\n authenticated: true,\n authenticated_user: u,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n setData,\n token: tokens.idToken!\n });\n\n // setAuthenticatedUser(u);\n // }\n\n // updateUser(u);\n }\n });\n }\n }\n }\n });\n }\n\n }, []);\n\n return (<>\n \n {/**/}\n {props.children}\n {/**/}\n \n );\n}\n"],"names":["React"],"mappings":";;;;;;;;;AAqBA,MAAM,QAAQ,GAAG,2CAA2C,CAAC;AA8C7D,MAAM,SAAS,GAAkB,KAAK,CAAC,MAAM,CAAC;AAC1C,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,OAAO,EAAE;AACL,QAAA,cAAc,EAAE,kBAAkB;AACrC,KAAA;AACJ,CAAA,CAAC,CAAC;AAEH,MAAM,SAAS,GAAmB;AAC9B,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,aAAa,EAAE,KAAK;AACpB,IAAA,kBAAkB,EAAE,IAAI;AACxB,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,IAAI,EAAE,EAAE;AACR,IAAA,OAAO,EAAE,IAAI;CAChB,CAAC;AAEF;;;;;;;;;AASG;MACU,UAAU,GAAG,aAAa,CAAwB,SAAS,EAAE;AAE1E,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,WAAW,GAAG,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CG;AACqB,SAAA,kBAAkB,CAAE,KAM3C,EAAA;IAEwD,QAAQ,CAAc,IAAI,EAAE;;;IAIjF,MAAM,CAAE,KAAK,EAAE,QAAQ,CAAE,GAAG,QAAQ,CAAiB,SAAS,CAAC,CAAC;IAEhE,SAAS,OAAO,CAAC,OAAY,EAAA;QACzB,MAAM,YAAY,GAAoB,KAAM,CAAC;AA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A,EAAA,EAAA,KAAK,CACR,EAAA,EAAA,aAAa,EAAE,IAAI,EACnB,kBAAkB,EAAE,CAAC,EACrB,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,IAAI,MAAK;AACzE,4CAAA,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;4CAC1B,CAAC,OAAQ,GAAG,CAAC;AACb,4CAAA,MAAM,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;4CACpF,MAAc,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;yCAChH,GAAG,IAAI,EACR,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,QAAQ,EAClC,OAAO,EACP,KAAK,EAAE,MAAM,CAAC,OAAQ,EAAA,CAAA,CACxB,CAAC;;;;iCAMV;AACL,6BAAC,CAAC,CAAC;yBACN;qBACJ;iBACJ;AACL,aAAC,CAAC,CAAC;SACV;KAEJ,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,QAAQA,cAAA,CAAA,aAAA,CAAAA,cAAA,CAAA,QAAA,EAAA,IAAA;AACJ,QAAAA,cAAA,CAAA,aAAA,CAAC,UAAU,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAExB,EAAA,KAAK,CAAC,QAAQ,CAED,CACvB,EAAE;AACT;;;;"} \ No newline at end of file diff --git a/inst/dist/cori.data.api.d.ts b/inst/dist/cori.data.api.d.ts index 917badb8..978c992c 100644 --- a/inst/dist/cori.data.api.d.ts +++ b/inst/dist/cori.data.api.d.ts @@ -2,8 +2,35 @@ import { MapStyle } from "react-map-gl"; export declare function helloAnything(thing: string): string; export { Button, Input, Label } from "./@cori-risi/components/basic"; export { default as AmplifyContextProvider, AmplifyContext } from "./@cori-risi/cotexts/AmplifyContextProvider"; -export { default as ApiContextProvider, ApiContext } from "./@cori-risi/cotexts/ApiContextProvider"; +export { default as ApiContextProvider, ApiContext, ApiContextType } from "./@cori-risi/cotexts/ApiContextProvider"; export { default as CategoricalLegend } from "./@cori-risi/components/CategoricalLegend"; export { default as GeocoderControl } from "./@cori-risi/components/GeocoderControl"; +/** + * This is the primary Mapbox basemap style used in CORI/RISI frontend mapping applications + * + * + * + *
+ * + * + * ```ts + * import { coriLightMapStyle } from "@cori-risi/cori.data.api"; + * + * // ... + * + * + * + * ``` + * */ export declare const coriLightMapStyle: MapStyle; //# sourceMappingURL=cori.data.api.d.ts.map \ No newline at end of file diff --git a/inst/dist/cori.data.api.d.ts.map b/inst/dist/cori.data.api.d.ts.map index 4d471f3a..ca597739 100644 --- a/inst/dist/cori.data.api.d.ts.map +++ b/inst/dist/cori.data.api.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"cori.data.api.d.ts","sourceRoot":"","sources":["../../lib/cori.data.api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAGvC,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,OAAO,EACH,MAAM,EACN,KAAK,EACL,KAAK,EACR,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,cAAc,EAAE,MAAO,6CAA6C,CAAC;AACjH,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAEpG,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAGzF,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAKrF,eAAO,MAAM,iBAAiB,EAAE,QAElB,CAAC"} \ No newline at end of file +{"version":3,"file":"cori.data.api.d.ts","sourceRoot":"","sources":["../../lib/cori.data.api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAGvC,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,OAAO,EACH,MAAM,EACN,KAAK,EACL,KAAK,EACR,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,cAAc,EAAE,MAAO,6CAA6C,CAAC;AACjH,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAEpH,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAGzF,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAIrF;;;;;;;;;;;;;;;;;;;;;;;;;;KA0BK;AACL,eAAO,MAAM,iBAAiB,EAAE,QAElB,CAAC"} \ No newline at end of file diff --git a/inst/dist/cori.data.api.js b/inst/dist/cori.data.api.js index 5f24a09a..ebbb1673 100644 --- a/inst/dist/cori.data.api.js +++ b/inst/dist/cori.data.api.js @@ -15,7 +15,33 @@ import MAP_STYLE from './@cori-risi/mapbox/styles/ruralinno/cl010e7b7001p15pe3l0 function helloAnything(thing) { return `Hello ${thing}!`; } -// Make a copy of the main basemap style +/** + * This is the primary Mapbox basemap style used in CORI/RISI frontend mapping applications + * + * + * + *
+ * + * + * ```ts + * import { coriLightMapStyle } from "@cori-risi/cori.data.api"; + * + * // ... + * + * + * + * ``` + * */ const coriLightMapStyle = (Object.assign({}, MAP_STYLE)); export { coriLightMapStyle, helloAnything }; diff --git a/inst/dist/cori.data.api.js.map b/inst/dist/cori.data.api.js.map index 1661587f..a8db6c0f 100644 --- a/inst/dist/cori.data.api.js.map +++ b/inst/dist/cori.data.api.js.map @@ -1 +1 @@ -{"version":3,"file":"cori.data.api.js","sources":["../../lib/cori.data.api.ts"],"sourcesContent":["import * as global_types from \"./globals\";\nimport { MapStyle } from \"react-map-gl\"\n\n// Testy stuff\nexport function helloAnything(thing: string): string {\n return `Hello ${thing}!`\n}\n\nexport {\n Button,\n Input,\n Label\n} from \"./@cori-risi/components/basic\";\n\n// Actual API\nexport { default as AmplifyContextProvider, AmplifyContext } from \"./@cori-risi/cotexts/AmplifyContextProvider\";\nexport { default as ApiContextProvider, ApiContext } from \"./@cori-risi/cotexts/ApiContextProvider\";\n// export { default as BarChart } from \"./@cori-risi/components/BarChart\";\nexport { default as CategoricalLegend } from \"./@cori-risi/components/CategoricalLegend\";\n// export { default as ControlPanel } from \"./@cori-risi/components/ControlPanel\"\n// export { default as LineChart } from \"./@cori-risi/components/LineChart\";\nexport { default as GeocoderControl } from \"./@cori-risi/components/GeocoderControl\";\n\nimport MAP_STYLE from \"./@cori-risi/mapbox/styles/ruralinno/cl010e7b7001p15pe3l0306hv/style.json\";\n\n// Make a copy of the main basemap style\nexport const coriLightMapStyle: MapStyle = ({\n ...MAP_STYLE\n}) as MapStyle;\n"],"names":[],"mappings":";;;;;;;;;;;;;AAGA;AACM,SAAU,aAAa,CAAC,KAAa,EAAA;IACvC,OAAO,CAAA,MAAA,EAAS,KAAK,CAAA,CAAA,CAAG,CAAA;AAC5B,CAAC;AAmBD;AACa,MAAA,iBAAiB,IACvB,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,SAAS;;;;"} \ No newline at end of file +{"version":3,"file":"cori.data.api.js","sources":["../../lib/cori.data.api.ts"],"sourcesContent":["import * as global_types from \"./globals\";\nimport { MapStyle } from \"react-map-gl\"\n\n// Testy stuff\nexport function helloAnything(thing: string): string {\n return `Hello ${thing}!`\n}\n\nexport {\n Button,\n Input,\n Label\n} from \"./@cori-risi/components/basic\";\n\n// Actual API\nexport { default as AmplifyContextProvider, AmplifyContext } from \"./@cori-risi/cotexts/AmplifyContextProvider\";\nexport { default as ApiContextProvider, ApiContext, ApiContextType } from \"./@cori-risi/cotexts/ApiContextProvider\";\n// export { default as BarChart } from \"./@cori-risi/components/BarChart\";\nexport { default as CategoricalLegend } from \"./@cori-risi/components/CategoricalLegend\";\n// export { default as ControlPanel } from \"./@cori-risi/components/ControlPanel\"\n// export { default as LineChart } from \"./@cori-risi/components/LineChart\";\nexport { default as GeocoderControl } from \"./@cori-risi/components/GeocoderControl\";\n\nimport MAP_STYLE from \"./@cori-risi/mapbox/styles/ruralinno/cl010e7b7001p15pe3l0306hv/style.json\";\n\n/**\n * This is the primary Mapbox basemap style used in CORI/RISI frontend mapping applications\n *\n * \n * \n *
\n * \n *\n * ```ts\n * import { coriLightMapStyle } from \"@cori-risi/cori.data.api\";\n *\n * // ...\n *\n * \n *\n * ```\n * */\nexport const coriLightMapStyle: MapStyle = ({\n ...MAP_STYLE\n}) as MapStyle;\n"],"names":[],"mappings":";;;;;;;;;;;;;AAGA;AACM,SAAU,aAAa,CAAC,KAAa,EAAA;IACvC,OAAO,CAAA,MAAA,EAAS,KAAK,CAAA,CAAA,CAAG,CAAA;AAC5B,CAAC;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BK;AACQ,MAAA,iBAAiB,IACvB,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,SAAS;;;;"} \ No newline at end of file