@datawheel/bespoke 0.2.7 → 0.2.9

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();
@@ -8071,7 +8091,7 @@ function Section({ section }) {
8071
8091
  )
8072
8092
  ] }),
8073
8093
  idx + 1 < previews.length && /* @__PURE__ */ jsx(Divider, {})
8074
- ] }, image.image_id)
8094
+ ] }, image.id)
8075
8095
  ) })
8076
8096
  ] })
8077
8097
  ]
@@ -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" }),
@@ -14391,12 +14419,14 @@ function BespokeRenderer({
14391
14419
  translations,
14392
14420
  bespokeStyles,
14393
14421
  buildTime,
14394
- profilePrefix = "/defaultPath"
14422
+ profilePrefix = "/defaultPath",
14423
+ loader = /* @__PURE__ */ jsx(LoadingOverlay, { visible: true }),
14424
+ mantineProviderProps = {}
14395
14425
  }) {
14396
14426
  const loading = useInitialState(pathSegmentsKey);
14397
14427
  if (loading)
14398
- return /* @__PURE__ */ jsx(LoadingOverlay, { visible: true });
14399
- return /* @__PURE__ */ jsx(MantineProvider, { theme: { other: { bespokeStyles } }, inherit: true, children: /* @__PURE__ */ jsxs(ResourceProvider, { pathSegment: "bespoke", profilePrefix, children: [
14428
+ return /* @__PURE__ */ jsx(Fragment, { children: loader });
14429
+ return /* @__PURE__ */ jsx(MantineProvider, { ...mantineProviderProps, theme: { other: { bespokeStyles } }, inherit: true, children: /* @__PURE__ */ jsxs(ResourceProvider, { pathSegment: "bespoke", profilePrefix, children: [
14400
14430
  /* @__PURE__ */ jsx(TranslationsProvider, { translations, children: /* @__PURE__ */ jsx(Report_default, {}) }),
14401
14431
  /* @__PURE__ */ jsx("small", { children: buildTime })
14402
14432
  ] }) });
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);
@@ -704,10 +705,6 @@ var libraries = {
704
705
  stats: stats_default
705
706
  };
706
707
  var declaredFormatters = {};
707
- var REPORT_TYPES = {
708
- REPORT: "report",
709
- STORY: "story"
710
- };
711
708
  var REPORT_MODES = {
712
709
  UNILATERAL: "uni",
713
710
  MULTILATERAL: "multi"
@@ -716,15 +713,6 @@ var SELECTOR_TYPES = {
716
713
  SINGLE: "single",
717
714
  MULTI: "multi"
718
715
  };
719
- var REPORT_FIELDS = {
720
- TITLE: "title",
721
- SUBTITLE: "subtitle",
722
- LABEL: "label"
723
- };
724
- ({
725
- [REPORT_TYPES.REPORT]: Object.values(REPORT_FIELDS),
726
- [REPORT_TYPES.STORY]: Object.values(REPORT_FIELDS)
727
- });
728
716
  var BLOCK_CONTENT_TYPES = {
729
717
  // AUTHOR: "author",
730
718
  // FOOTNOTE: "footnote",
@@ -1285,7 +1273,6 @@ var modelFactoryMap = {
1285
1273
  // db/index.ts
1286
1274
  var verbose = getLogging_default();
1287
1275
  var connectionString = process.env.REPORTS_DB_CONNECTION || "";
1288
- var shouldWipe = yn3(process.env.REPORTS_DB_WIPE);
1289
1276
  if (!connectionString) {
1290
1277
  throw new Error(`
1291
1278
  Env var 'REPORTS_DB_CONNECTION' is not present.
@@ -1319,7 +1306,7 @@ var getDB = () => {
1319
1306
  `);
1320
1307
  }
1321
1308
  Object.values(modelFactoryMap).map((modelFactory) => modelFactory(sequelize)).map((modelAssociator) => modelAssociator({ ...sequelize.models, sequelize }));
1322
- global.sequelize = sequelize.sync({ force: shouldWipe }).catch((err) => {
1309
+ global.sequelize = sequelize.sync().catch((err) => {
1323
1310
  if (err instanceof Error$1) {
1324
1311
  console.error(
1325
1312
  "=".repeat(40),
@@ -2708,7 +2695,7 @@ function endpointMemberFactory(operations) {
2708
2695
  }
2709
2696
  function parseReadMemberParams(query) {
2710
2697
  const locale = normalizeList(query.locale)[0] || localeDefault3 || "en";
2711
- const all = locale === "all" || yn3(query.all);
2698
+ const all = locale === "all" || yn2(query.all);
2712
2699
  const mode = normalizeList(query.mode)[0];
2713
2700
  const outputParam = normalizeList(query.output)[0] || "full";
2714
2701
  const output = outputParam === "lite" ? "lite" : "full";
@@ -2787,9 +2774,9 @@ function parseSearchMemberParams(query) {
2787
2774
  locale: localeIsAll ? localeDefault3 : locale,
2788
2775
  limit: normalizeList(query.limit).map(parseFiniteNumber)[0] ?? 5,
2789
2776
  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 }),
2777
+ includes: yn2(query.includes, { default: true }),
2778
+ visible: yn2(query.visible, { default: true }),
2779
+ noImage: yn2(query.noImage, { default: false }),
2793
2780
  variant,
2794
2781
  dimension,
2795
2782
  report,
@@ -3412,7 +3399,7 @@ function endpointCRUDFactory(api, entity) {
3412
3399
  endpoint("GET", `read/${entity}`, (req) => {
3413
3400
  const params = req.query;
3414
3401
  const id = normalizeList(params.id).map(parseFiniteNumber);
3415
- return crudRead({ id, include: yn3(params.include) });
3402
+ return crudRead({ id, include: yn2(params.include) });
3416
3403
  }),
3417
3404
  endpoint("POST", `update/${entity}`, (req) => {
3418
3405
  const { body } = req;
@@ -4019,7 +4006,7 @@ function parseBlockContext(context) {
4019
4006
  locale: context.locale || localeDefault6
4020
4007
  };
4021
4008
  }
4022
- var verbose4 = yn3(process.env.REPORTS_LOGGING);
4009
+ var verbose4 = yn2(process.env.REPORTS_LOGGING);
4023
4010
  var mortarEval_default = mortarEval;
4024
4011
  function mortarEval(varInnerName, varOuterValue, logic, formatterFunctions, attributes = void 0, blockContext) {
4025
4012
  const vars = {};
@@ -4234,7 +4221,7 @@ var getRootBlocksForSection_default = getRootBlocksForSection;
4234
4221
 
4235
4222
  // libs/consts.ts
4236
4223
  var apiSeparator = "|||";
4237
- var debug = yn3(process.env.NEXT_PUBLIC_REPORTS_DEBUG);
4224
+ var debug = yn2(process.env.NEXT_PUBLIC_REPORTS_DEBUG);
4238
4225
  var ORIGIN = process.env.REPORTS_ORIGIN || "";
4239
4226
  axios5.interceptors.request.use((config) => ({
4240
4227
  ...config,
@@ -4734,6 +4721,17 @@ function previewsToAttributes(previews = []) {
4734
4721
  }, {});
4735
4722
  }
4736
4723
  var previewsToAttributes_default = previewsToAttributes;
4724
+ function publicEnvVarsToAttributes() {
4725
+ const { publicRuntimeConfig } = getConfig();
4726
+ const envList = publicRuntimeConfig.bespoke_report_env_vars || {};
4727
+ return {
4728
+ ...Object.keys(envList).reduce((acc, envKey) => {
4729
+ acc[`ENV_${envKey}`] = envList[envKey] || "N/A";
4730
+ return acc;
4731
+ }, {})
4732
+ };
4733
+ }
4734
+ var publicEnvVarsToAttributes_default = publicEnvVarsToAttributes;
4737
4735
  function comparePositions(firstPos, secondPos) {
4738
4736
  return +(firstPos < secondPos) - +(firstPos > secondPos);
4739
4737
  }
@@ -5456,7 +5454,8 @@ function recalculateVariables(resource, params) {
5456
5454
  dispatch(statusActions.setStatus(statusPayload));
5457
5455
  const attributes = {
5458
5456
  ...previewsToAttributes_default(previews),
5459
- locale: currentLocale
5457
+ locale: currentLocale,
5458
+ ...publicEnvVarsToAttributes_default()
5460
5459
  };
5461
5460
  const blockContext = {
5462
5461
  variables: attributes,
@@ -5764,7 +5763,8 @@ function BespokeRendererStaticProps(options) {
5764
5763
  await dispatch(removeBlocksFromState(privateBlockIds));
5765
5764
  const attributes = {
5766
5765
  ...previewsToAttributes_default(members.results),
5767
- locale
5766
+ locale,
5767
+ ...publicEnvVarsToAttributes_default()
5768
5768
  };
5769
5769
  const readMemberFn = async (innerParams) => await dispatch(readMember(innerParams));
5770
5770
  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.9",
4
4
  "description": "Content management system for creating automated data reports",
5
5
  "exports": {
6
6
  ".": {
@@ -42,14 +42,14 @@
42
42
  "@auth0/nextjs-auth0": "^2.4.0",
43
43
  "@emotion/react": "^11.10.4",
44
44
  "@hello-pangea/dnd": "^16.2.0",
45
- "@mantine/core": "^6.0.6",
46
- "@mantine/dates": "^6.0.6",
47
- "@mantine/dropzone": "^6.0.6",
48
- "@mantine/form": "^6.0.6",
49
- "@mantine/hooks": "^6.0.6",
50
- "@mantine/next": "^6.0.6",
51
- "@mantine/notifications": "^6.0.6",
52
- "@mantine/prism": "^6.0.6",
45
+ "@mantine/core": "^6.0.19",
46
+ "@mantine/dates": "^6.0.19",
47
+ "@mantine/dropzone": "^6.0.19",
48
+ "@mantine/form": "^6.0.19",
49
+ "@mantine/hooks": "^6.0.19",
50
+ "@mantine/next": "^6.0.19",
51
+ "@mantine/notifications": "^6.0.19",
52
+ "@mantine/prism": "^6.0.19",
53
53
  "@monaco-editor/react": "^4.4.5",
54
54
  "@reduxjs/toolkit": "^1.8.4",
55
55
  "@tabler/icons-react": "^2.15.0",