@datawheel/bespoke 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,6 @@ REPORTS_DB_CONNECTION="postgres://user:@localhost:5432/database"
8
8
  REPORTS_LOGGING=true
9
9
  NEXT_PUBLIC_REPORTS_LOCALE_DEFAULT="en"
10
10
  NEXT_PUBLIC_REPORTS_LOCALES="en,es"
11
- REPORTS_DB_WIPE=false
12
11
  REPORTS_BASE_URL="http://localhost:3000"
13
12
 
14
13
  # Images
@@ -26,3 +25,20 @@ AUTH0_ISSUER_BASE_URL="https://xxxxxxx.auth0.com"
26
25
  AUTH0_CLIENT_ID="xxxxxxxxxxx"
27
26
  AUTH0_CLIENT_SECRET="xxxxxxxxxxx"
28
27
  ```
28
+
29
+ ### Environmental variables into Bespoke Report scope
30
+
31
+ Just add this in your `nextjs.config.js`
32
+
33
+ ```
34
+ publicRuntimeConfig: {
35
+ // Define your public environment variables for bespoke here
36
+ bespoke_report_env_vars: {
37
+ API: process.env.NEXT_PUBLIC_API || "N/A"
38
+ WHATEVER: "hello"
39
+ },
40
+ // ...
41
+ },
42
+ ```
43
+
44
+ And is gonna be offered as ENV_API and ENV_WHATEVER in the list of variables in the profile.
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import { assign, closest, merge, isObject } from 'd3plus-common';
9
9
  import { strip, titleCase } from 'd3plus-text';
10
10
  import yn3 from 'yn';
11
11
  import toposort from 'toposort';
12
+ import getConfig from 'next/config';
12
13
  import { schema, normalize } from 'normalizr';
13
14
  import { createSlice, configureStore } from '@reduxjs/toolkit';
14
15
  import { HYDRATE, createWrapper } from 'next-redux-wrapper';
@@ -1591,6 +1592,23 @@ var init_previewsToAttributes = __esm({
1591
1592
  previewsToAttributes_default = previewsToAttributes;
1592
1593
  }
1593
1594
  });
1595
+ function publicEnvVarsToAttributes() {
1596
+ const { publicRuntimeConfig } = getConfig();
1597
+ const envList = publicRuntimeConfig.bespoke_report_env_vars || {};
1598
+ return {
1599
+ ...Object.keys(envList).reduce((acc, envKey) => {
1600
+ acc[`ENV_${envKey}`] = envList[envKey] || "N/A";
1601
+ return acc;
1602
+ }, {})
1603
+ };
1604
+ }
1605
+ var publicEnvVarsToAttributes_default;
1606
+ var init_publicEnvVarsToAttributes = __esm({
1607
+ "libs/variables/publicEnvVarsToAttributes.ts"() {
1608
+ init_esm_shims();
1609
+ publicEnvVarsToAttributes_default = publicEnvVarsToAttributes;
1610
+ }
1611
+ });
1594
1612
 
1595
1613
  // libs/ordering.ts
1596
1614
  function assertDev(expr) {
@@ -2542,7 +2560,8 @@ function recalculateVariables(resource, params) {
2542
2560
  dispatch(statusActions.setStatus(statusPayload));
2543
2561
  const attributes = {
2544
2562
  ...previewsToAttributes_default(previews),
2545
- locale: currentLocale
2563
+ locale: currentLocale,
2564
+ ...publicEnvVarsToAttributes_default()
2546
2565
  };
2547
2566
  const blockContext = {
2548
2567
  variables: attributes,
@@ -2678,6 +2697,7 @@ var init_actions = __esm({
2678
2697
  init_esm_shims();
2679
2698
  init_runConsumers();
2680
2699
  init_previewsToAttributes();
2700
+ init_publicEnvVarsToAttributes();
2681
2701
  init_lib2();
2682
2702
  init_statusSlice();
2683
2703
  init_variablesSlice();
@@ -8537,6 +8557,12 @@ function DimensionAutocomplete({ id, locale, onSelect, initialSelection = void 0
8537
8557
  inputRef.current?.select();
8538
8558
  }
8539
8559
  }, [searchMode]);
8560
+ useEffect(() => {
8561
+ setQuery("");
8562
+ onSelect(void 0);
8563
+ setCurrentMember(void 0);
8564
+ setSearchMode(true);
8565
+ }, [locale]);
8540
8566
  const onSelectPreview = (previewMember) => {
8541
8567
  const fullMember = results.find((d) => d.id === previewMember.value);
8542
8568
  if (fullMember) {
@@ -9752,7 +9778,9 @@ function CMSHeader(props) {
9752
9778
  size: "xs",
9753
9779
  data: localeOptions,
9754
9780
  value: currentLocale,
9755
- onChange: (value) => dispatch(statusActions.setStatus({ currentLocale: value || localeDefault9 }))
9781
+ onChange: (value) => dispatch(
9782
+ statusActions.setStatus({ currentLocale: value || localeDefault9, previews: [] })
9783
+ )
9756
9784
  }
9757
9785
  ),
9758
9786
  /* @__PURE__ */ jsx(Divider, { orientation: "vertical" }),
package/dist/server.js CHANGED
@@ -2,7 +2,7 @@ import { initAuth0 } from '@auth0/nextjs-auth0';
2
2
  import auth0 from 'auth0';
3
3
  import * as pg from 'pg';
4
4
  import { Sequelize, Error as Error$1, fn, col, Op, DataTypes, QueryTypes, Model } from 'sequelize';
5
- import yn3 from 'yn';
5
+ import yn2 from 'yn';
6
6
  import * as d3Array from 'd3-array';
7
7
  import * as d3Collection from 'd3-collection';
8
8
  import * as d3Format from 'd3-format';
@@ -26,6 +26,7 @@ import * as allIcons from '@tabler/icons-react';
26
26
  import NextCors from 'nextjs-cors';
27
27
  import formidable from 'formidable';
28
28
  import toposort from 'toposort';
29
+ import getConfig from 'next/config';
29
30
  import { schema, normalize } from 'normalizr';
30
31
  import { createSlice, configureStore } from '@reduxjs/toolkit';
31
32
  import { HYDRATE, createWrapper } from 'next-redux-wrapper';
@@ -349,7 +350,7 @@ var searchUsersByMetadata2 = (key, value) => {
349
350
  });
350
351
  };
351
352
  var searchUsersByMetadata_default = searchUsersByMetadata2;
352
- var getLogging_default = (env = process.env) => yn3(env.REPORTS_LOGGING);
353
+ var getLogging_default = (env = process.env) => yn2(env.REPORTS_LOGGING);
353
354
  var BlockModel = class extends Model {
354
355
  getContent(locale) {
355
356
  const content = this.contentByLocale.find((item) => item.locale === locale);
@@ -1285,7 +1286,6 @@ var modelFactoryMap = {
1285
1286
  // db/index.ts
1286
1287
  var verbose = getLogging_default();
1287
1288
  var connectionString = process.env.REPORTS_DB_CONNECTION || "";
1288
- var shouldWipe = yn3(process.env.REPORTS_DB_WIPE);
1289
1289
  if (!connectionString) {
1290
1290
  throw new Error(`
1291
1291
  Env var 'REPORTS_DB_CONNECTION' is not present.
@@ -1319,7 +1319,7 @@ var getDB = () => {
1319
1319
  `);
1320
1320
  }
1321
1321
  Object.values(modelFactoryMap).map((modelFactory) => modelFactory(sequelize)).map((modelAssociator) => modelAssociator({ ...sequelize.models, sequelize }));
1322
- global.sequelize = sequelize.sync({ force: shouldWipe }).catch((err) => {
1322
+ global.sequelize = sequelize.sync().catch((err) => {
1323
1323
  if (err instanceof Error$1) {
1324
1324
  console.error(
1325
1325
  "=".repeat(40),
@@ -2708,7 +2708,7 @@ function endpointMemberFactory(operations) {
2708
2708
  }
2709
2709
  function parseReadMemberParams(query) {
2710
2710
  const locale = normalizeList(query.locale)[0] || localeDefault3 || "en";
2711
- const all = locale === "all" || yn3(query.all);
2711
+ const all = locale === "all" || yn2(query.all);
2712
2712
  const mode = normalizeList(query.mode)[0];
2713
2713
  const outputParam = normalizeList(query.output)[0] || "full";
2714
2714
  const output = outputParam === "lite" ? "lite" : "full";
@@ -2787,9 +2787,9 @@ function parseSearchMemberParams(query) {
2787
2787
  locale: localeIsAll ? localeDefault3 : locale,
2788
2788
  limit: normalizeList(query.limit).map(parseFiniteNumber)[0] ?? 5,
2789
2789
  format: formatIsNested ? "nested" : "plain",
2790
- includes: yn3(query.includes, { default: true }),
2791
- visible: yn3(query.visible, { default: true }),
2792
- noImage: yn3(query.noImage, { default: false }),
2790
+ includes: yn2(query.includes, { default: true }),
2791
+ visible: yn2(query.visible, { default: true }),
2792
+ noImage: yn2(query.noImage, { default: false }),
2793
2793
  variant,
2794
2794
  dimension,
2795
2795
  report,
@@ -3412,7 +3412,7 @@ function endpointCRUDFactory(api, entity) {
3412
3412
  endpoint("GET", `read/${entity}`, (req) => {
3413
3413
  const params = req.query;
3414
3414
  const id = normalizeList(params.id).map(parseFiniteNumber);
3415
- return crudRead({ id, include: yn3(params.include) });
3415
+ return crudRead({ id, include: yn2(params.include) });
3416
3416
  }),
3417
3417
  endpoint("POST", `update/${entity}`, (req) => {
3418
3418
  const { body } = req;
@@ -4019,7 +4019,7 @@ function parseBlockContext(context) {
4019
4019
  locale: context.locale || localeDefault6
4020
4020
  };
4021
4021
  }
4022
- var verbose4 = yn3(process.env.REPORTS_LOGGING);
4022
+ var verbose4 = yn2(process.env.REPORTS_LOGGING);
4023
4023
  var mortarEval_default = mortarEval;
4024
4024
  function mortarEval(varInnerName, varOuterValue, logic, formatterFunctions, attributes = void 0, blockContext) {
4025
4025
  const vars = {};
@@ -4234,7 +4234,7 @@ var getRootBlocksForSection_default = getRootBlocksForSection;
4234
4234
 
4235
4235
  // libs/consts.ts
4236
4236
  var apiSeparator = "|||";
4237
- var debug = yn3(process.env.NEXT_PUBLIC_REPORTS_DEBUG);
4237
+ var debug = yn2(process.env.NEXT_PUBLIC_REPORTS_DEBUG);
4238
4238
  var ORIGIN = process.env.REPORTS_ORIGIN || "";
4239
4239
  axios5.interceptors.request.use((config) => ({
4240
4240
  ...config,
@@ -4734,6 +4734,17 @@ function previewsToAttributes(previews = []) {
4734
4734
  }, {});
4735
4735
  }
4736
4736
  var previewsToAttributes_default = previewsToAttributes;
4737
+ function publicEnvVarsToAttributes() {
4738
+ const { publicRuntimeConfig } = getConfig();
4739
+ const envList = publicRuntimeConfig.bespoke_report_env_vars || {};
4740
+ return {
4741
+ ...Object.keys(envList).reduce((acc, envKey) => {
4742
+ acc[`ENV_${envKey}`] = envList[envKey] || "N/A";
4743
+ return acc;
4744
+ }, {})
4745
+ };
4746
+ }
4747
+ var publicEnvVarsToAttributes_default = publicEnvVarsToAttributes;
4737
4748
  function comparePositions(firstPos, secondPos) {
4738
4749
  return +(firstPos < secondPos) - +(firstPos > secondPos);
4739
4750
  }
@@ -5456,7 +5467,8 @@ function recalculateVariables(resource, params) {
5456
5467
  dispatch(statusActions.setStatus(statusPayload));
5457
5468
  const attributes = {
5458
5469
  ...previewsToAttributes_default(previews),
5459
- locale: currentLocale
5470
+ locale: currentLocale,
5471
+ ...publicEnvVarsToAttributes_default()
5460
5472
  };
5461
5473
  const blockContext = {
5462
5474
  variables: attributes,
@@ -5764,7 +5776,8 @@ function BespokeRendererStaticProps(options) {
5764
5776
  await dispatch(removeBlocksFromState(privateBlockIds));
5765
5777
  const attributes = {
5766
5778
  ...previewsToAttributes_default(members.results),
5767
- locale
5779
+ locale,
5780
+ ...publicEnvVarsToAttributes_default()
5768
5781
  };
5769
5782
  const readMemberFn = async (innerParams) => await dispatch(readMember(innerParams));
5770
5783
  await runConsumersV2(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datawheel/bespoke",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Content management system for creating automated data reports",
5
5
  "exports": {
6
6
  ".": {