@plaidev/karte-action-sdk 1.1.148 → 1.1.149-27994064.949f9af2

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.
@@ -1389,7 +1389,10 @@ const loadActionTable = async (config, api_key, endpoint) => {
1389
1389
  const results = config.map(c => c.preview_value)
1390
1390
  ;
1391
1391
  return config.reduce((acc, c, i) => {
1392
- acc[c.name] = results[i];
1392
+ const value = results[i] ?? c.query.default_value;
1393
+ if (value) {
1394
+ acc[c.name] = value;
1395
+ }
1393
1396
  return acc;
1394
1397
  }, {});
1395
1398
  };
@@ -1532,13 +1535,18 @@ function create(App, options = {
1532
1535
  const trigger = event?.detail?.trigger ? event.detail.trigger : 'none';
1533
1536
  close(trigger);
1534
1537
  };
1535
- const show = (trigger = 'none') => {
1538
+ const show = async (trigger = 'none') => {
1536
1539
  if (app) {
1537
1540
  return;
1538
1541
  }
1539
1542
  if (trigger === 'custom' && (options.props.show_on_scroll || options.props.show_on_time)) {
1540
1543
  return;
1541
1544
  }
1545
+ if (actionTablePromise) {
1546
+ const result = await actionTablePromise;
1547
+ if (!result.success)
1548
+ return;
1549
+ }
1542
1550
  options.send('message_open', { state: getState$1() });
1543
1551
  setOpened(true);
1544
1552
  setClosed(false); // deprecated
@@ -1595,12 +1603,19 @@ function create(App, options = {
1595
1603
  campaignId: data.campaign_id || null,
1596
1604
  });
1597
1605
  // ActionTable APIへの非同期リクエスト
1606
+ let actionTablePromise = null;
1598
1607
  if (options.localVariablesQuery && data.api_key) {
1599
- loadActionTable(options.localVariablesQuery, data.api_key).then(result => {
1600
- if (Object.keys(result).length > 0) {
1608
+ actionTablePromise = (async () => {
1609
+ const result = await loadActionTable(options.localVariablesQuery, data.api_key);
1610
+ let success = false;
1611
+ if (Object.keys(result).length === options.localVariablesQuery.length) {
1601
1612
  setVariables(result);
1613
+ success = true;
1602
1614
  }
1603
- });
1615
+ return {
1616
+ success,
1617
+ };
1618
+ })();
1604
1619
  }
1605
1620
  // NOTE: onCreateより前にListenする必要がある
1606
1621
  window.addEventListener(ACTION_SHOW_EVENT, handleShow);
@@ -1627,6 +1642,7 @@ function create(App, options = {
1627
1642
  options.onCreate(actionProps);
1628
1643
  }
1629
1644
  const appCleanup = () => {
1645
+ actionTablePromise = null;
1630
1646
  showTriggerCleanups.forEach((c) => c());
1631
1647
  closeTriggerCleanups.forEach((c) => c());
1632
1648
  window.removeEventListener(ACTION_SHOW_EVENT, handleShow);
package/dist/index.es.js CHANGED
@@ -1472,7 +1472,10 @@ const loadActionTable = async (config, api_key, endpoint) => {
1472
1472
  }
1473
1473
  }));
1474
1474
  return config.reduce((acc, c, i) => {
1475
- acc[c.name] = results[i];
1475
+ const value = results[i] ?? c.query.default_value;
1476
+ if (value) {
1477
+ acc[c.name] = value;
1478
+ }
1476
1479
  return acc;
1477
1480
  }, {});
1478
1481
  };
@@ -1615,13 +1618,18 @@ function create(App, options = {
1615
1618
  const trigger = event?.detail?.trigger ? event.detail.trigger : 'none';
1616
1619
  close(trigger);
1617
1620
  };
1618
- const show = (trigger = 'none') => {
1621
+ const show = async (trigger = 'none') => {
1619
1622
  if (app) {
1620
1623
  return;
1621
1624
  }
1622
1625
  if (trigger === 'custom' && (options.props.show_on_scroll || options.props.show_on_time)) {
1623
1626
  return;
1624
1627
  }
1628
+ if (actionTablePromise) {
1629
+ const result = await actionTablePromise;
1630
+ if (!result.success)
1631
+ return;
1632
+ }
1625
1633
  options.send('message_open', { state: getState$1() });
1626
1634
  setOpened(true);
1627
1635
  setClosed(false); // deprecated
@@ -1704,12 +1712,19 @@ function create(App, options = {
1704
1712
  campaignId: data.campaign_id || null,
1705
1713
  });
1706
1714
  // ActionTable APIへの非同期リクエスト
1715
+ let actionTablePromise = null;
1707
1716
  if (options.localVariablesQuery && data.api_key) {
1708
- loadActionTable(options.localVariablesQuery, data.api_key).then(result => {
1709
- if (Object.keys(result).length > 0) {
1717
+ actionTablePromise = (async () => {
1718
+ const result = await loadActionTable(options.localVariablesQuery, data.api_key);
1719
+ let success = false;
1720
+ if (Object.keys(result).length === options.localVariablesQuery.length) {
1710
1721
  setVariables(result);
1722
+ success = true;
1711
1723
  }
1712
- });
1724
+ return {
1725
+ success,
1726
+ };
1727
+ })();
1713
1728
  }
1714
1729
  // NOTE: onCreateより前にListenする必要がある
1715
1730
  window.addEventListener(ACTION_SHOW_EVENT, handleShow);
@@ -1736,6 +1751,7 @@ function create(App, options = {
1736
1751
  options.onCreate(actionProps);
1737
1752
  }
1738
1753
  const appCleanup = () => {
1754
+ actionTablePromise = null;
1739
1755
  showTriggerCleanups.forEach((c) => c());
1740
1756
  closeTriggerCleanups.forEach((c) => c());
1741
1757
  window.removeEventListener(ACTION_SHOW_EVENT, handleShow);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaidev/karte-action-sdk",
3
- "version": "1.1.148",
3
+ "version": "1.1.149-27994064.949f9af2",
4
4
  "author": "Plaid Inc.",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.es.js",