@plaidev/karte-action-sdk 1.1.184-28069312.e227ca9d → 1.1.184-28093385.169b3110

Sign up to get free protection for your applications and to get access to all the features.
@@ -152,6 +152,10 @@ interface ActionOptions<Props, Variables, VariablesQuery> {
152
152
  karteTemplate?: {
153
153
  [key: string]: any;
154
154
  };
155
+ /**
156
+ * アクション実行時のコンテキスト
157
+ */
158
+ context: ActionRunnerContext;
155
159
  }
156
160
  /**
157
161
  * KARTE のシステム設定情報
@@ -174,6 +178,13 @@ type ActionHookLog = {
174
178
  name: string;
175
179
  values?: any;
176
180
  };
181
+ /**
182
+ * アクション実行時のコンテキスト
183
+ */
184
+ type ActionRunnerContext = {
185
+ api_key: string;
186
+ target?: "web" | "native";
187
+ };
177
188
  type ActionTableResult = number | string | boolean | Date | null | undefined;
178
189
  type ActionTableQueryParam = string | number | boolean | Date;
179
190
  type ActionTableQueryParams = {
@@ -1582,6 +1593,10 @@ declare namespace widget {
1582
1593
  karteTemplate?: {
1583
1594
  [key: string]: any;
1584
1595
  };
1596
+ /**
1597
+ * アクション実行時のコンテキスト
1598
+ */
1599
+ context: ActionRunnerContext;
1585
1600
  }
1586
1601
  /**
1587
1602
  * KARTE のシステム設定情報
@@ -1604,6 +1619,13 @@ declare namespace widget {
1604
1619
  name: string;
1605
1620
  values?: any;
1606
1621
  };
1622
+ /**
1623
+ * アクション実行時のコンテキスト
1624
+ */
1625
+ type ActionRunnerContext = {
1626
+ api_key: string;
1627
+ target?: "web" | "native";
1628
+ };
1607
1629
  type ActionTableResult = number | string | boolean | Date | null | undefined;
1608
1630
  type ActionTableQueryParam = string | number | boolean | Date;
1609
1631
  type ActionTableQueryParams = {
@@ -631,6 +631,28 @@ function getSystem() {
631
631
  function setSystem(config) {
632
632
  system.set(config);
633
633
  }
634
+ /**
635
+ * アクション実行時のコンテキストを保存するストア
636
+ *
637
+ * @internal
638
+ */
639
+ const actionRunnerContext = writable(null);
640
+ /**
641
+ * アクション実行時のコンテキストを取得する
642
+ *
643
+ * @internal
644
+ */
645
+ function getActionRunnerContext() {
646
+ return get(actionRunnerContext);
647
+ }
648
+ /**
649
+ * アクション実行時のコンテキストを保存する
650
+ *
651
+ * @internal
652
+ */
653
+ function setActionRunnerContext(value) {
654
+ return actionRunnerContext.set(value);
655
+ }
634
656
  /**
635
657
  * Store to handle current state ID
636
658
  *
@@ -1531,6 +1553,7 @@ function createModal(App, options = {
1531
1553
  variables: {},
1532
1554
  localVariablesQuery: undefined,
1533
1555
  karteTemplate: {},
1556
+ context: { api_key: '' },
1534
1557
  }) {
1535
1558
  let app = null;
1536
1559
  const data = {
@@ -1730,6 +1753,7 @@ function createApp(App, options = {
1730
1753
  props: {},
1731
1754
  variables: {},
1732
1755
  localVariablesQuery: undefined,
1756
+ context: { api_key: '' },
1733
1757
  }) {
1734
1758
  let app = null;
1735
1759
  const close = () => {
@@ -1810,6 +1834,7 @@ async function runScript$1(options = {
1810
1834
  variables: {},
1811
1835
  localVariablesQuery: undefined,
1812
1836
  karteTemplate: {},
1837
+ context: { api_key: '' },
1813
1838
  }) {
1814
1839
  if (!options.onCreate)
1815
1840
  return;
@@ -1920,6 +1945,7 @@ function create(App, options = {
1920
1945
  variables: {},
1921
1946
  localVariablesQuery: undefined,
1922
1947
  karteTemplate: {},
1948
+ context: { api_key: '' },
1923
1949
  }) {
1924
1950
  const data = {
1925
1951
  ...options.props,
@@ -1951,6 +1977,7 @@ function create(App, options = {
1951
1977
  shortenId: data.shorten_id || null,
1952
1978
  campaignId: data.campaign_id || null,
1953
1979
  });
1980
+ setActionRunnerContext(options.context);
1954
1981
  const loggerCleanup = listenConsoleLogger() ;
1955
1982
  window.addEventListener(ACTION_DESTROY_EVENT, handleDestroy);
1956
1983
  window.addEventListener('beforeunload', dispatchDestroyEvent, false);
@@ -2795,6 +2822,7 @@ const moveTo = (to) => () => {
2795
2822
  };
2796
2823
  /** @internal */
2797
2824
  const linkTo = (to, targetBlank = true) => () => {
2825
+ const { target } = getActionRunnerContext() ?? {};
2798
2826
  async function sleep(ms) {
2799
2827
  return new Promise(resolve => setTimeout(resolve, ms));
2800
2828
  }
@@ -2803,11 +2831,12 @@ const linkTo = (to, targetBlank = true) => () => {
2803
2831
  // # edge.js の retransmitter が送るのを待つ
2804
2832
  await sleep(450);
2805
2833
  }
2806
- if (targetBlank) {
2834
+ const isRequiredWindowOpen = target === 'native' || targetBlank;
2835
+ if (isRequiredWindowOpen) {
2807
2836
  window.open(to);
2808
2837
  }
2809
2838
  Promise.race([_send(), sleep(650)]).then(() => {
2810
- if (!targetBlank) {
2839
+ if (!isRequiredWindowOpen) {
2811
2840
  location.href = to;
2812
2841
  }
2813
2842
  });
@@ -152,6 +152,10 @@ interface ActionOptions<Props, Variables, VariablesQuery> {
152
152
  karteTemplate?: {
153
153
  [key: string]: any;
154
154
  };
155
+ /**
156
+ * アクション実行時のコンテキスト
157
+ */
158
+ context: ActionRunnerContext;
155
159
  }
156
160
  /**
157
161
  * KARTE のシステム設定情報
@@ -174,6 +178,13 @@ type ActionHookLog = {
174
178
  name: string;
175
179
  values?: any;
176
180
  };
181
+ /**
182
+ * アクション実行時のコンテキスト
183
+ */
184
+ type ActionRunnerContext = {
185
+ api_key: string;
186
+ target?: "web" | "native";
187
+ };
177
188
  type ActionTableResult = number | string | boolean | Date | null | undefined;
178
189
  type ActionTableQueryParam = string | number | boolean | Date;
179
190
  type ActionTableQueryParams = {
@@ -1582,6 +1593,10 @@ declare namespace widget {
1582
1593
  karteTemplate?: {
1583
1594
  [key: string]: any;
1584
1595
  };
1596
+ /**
1597
+ * アクション実行時のコンテキスト
1598
+ */
1599
+ context: ActionRunnerContext;
1585
1600
  }
1586
1601
  /**
1587
1602
  * KARTE のシステム設定情報
@@ -1604,6 +1619,13 @@ declare namespace widget {
1604
1619
  name: string;
1605
1620
  values?: any;
1606
1621
  };
1622
+ /**
1623
+ * アクション実行時のコンテキスト
1624
+ */
1625
+ type ActionRunnerContext = {
1626
+ api_key: string;
1627
+ target?: "web" | "native";
1628
+ };
1607
1629
  type ActionTableResult = number | string | boolean | Date | null | undefined;
1608
1630
  type ActionTableQueryParam = string | number | boolean | Date;
1609
1631
  type ActionTableQueryParams = {
package/dist/index.es.js CHANGED
@@ -635,6 +635,28 @@ function getSystem() {
635
635
  function setSystem(config) {
636
636
  system.set(config);
637
637
  }
638
+ /**
639
+ * アクション実行時のコンテキストを保存するストア
640
+ *
641
+ * @internal
642
+ */
643
+ const actionRunnerContext = writable(null);
644
+ /**
645
+ * アクション実行時のコンテキストを取得する
646
+ *
647
+ * @internal
648
+ */
649
+ function getActionRunnerContext() {
650
+ return get(actionRunnerContext);
651
+ }
652
+ /**
653
+ * アクション実行時のコンテキストを保存する
654
+ *
655
+ * @internal
656
+ */
657
+ function setActionRunnerContext(value) {
658
+ return actionRunnerContext.set(value);
659
+ }
638
660
  /**
639
661
  * Store to handle current state ID
640
662
  *
@@ -1569,6 +1591,7 @@ function createModal(App, options = {
1569
1591
  variables: {},
1570
1592
  localVariablesQuery: undefined,
1571
1593
  karteTemplate: {},
1594
+ context: { api_key: '' },
1572
1595
  }) {
1573
1596
  let app = null;
1574
1597
  const data = {
@@ -1795,6 +1818,7 @@ function createApp(App, options = {
1795
1818
  props: {},
1796
1819
  variables: {},
1797
1820
  localVariablesQuery: undefined,
1821
+ context: { api_key: '' },
1798
1822
  }) {
1799
1823
  let app = null;
1800
1824
  const close = () => {
@@ -1874,6 +1898,7 @@ async function runScript$1(options = {
1874
1898
  variables: {},
1875
1899
  localVariablesQuery: undefined,
1876
1900
  karteTemplate: {},
1901
+ context: { api_key: '' },
1877
1902
  }) {
1878
1903
  if (!options.onCreate)
1879
1904
  return;
@@ -1984,6 +2009,7 @@ function create(App, options = {
1984
2009
  variables: {},
1985
2010
  localVariablesQuery: undefined,
1986
2011
  karteTemplate: {},
2012
+ context: { api_key: '' },
1987
2013
  }) {
1988
2014
  const data = {
1989
2015
  ...options.props,
@@ -2015,6 +2041,7 @@ function create(App, options = {
2015
2041
  shortenId: data.shorten_id || null,
2016
2042
  campaignId: data.campaign_id || null,
2017
2043
  });
2044
+ setActionRunnerContext(options.context);
2018
2045
  window.addEventListener(ACTION_DESTROY_EVENT, handleDestroy);
2019
2046
  window.addEventListener('beforeunload', dispatchDestroyEvent, false);
2020
2047
  let modalCleanup = NOOP;
@@ -2819,6 +2846,7 @@ const moveTo = (to) => () => {
2819
2846
  };
2820
2847
  /** @internal */
2821
2848
  const linkTo = (to, targetBlank = true) => () => {
2849
+ const { target } = getActionRunnerContext() ?? {};
2822
2850
  async function sleep(ms) {
2823
2851
  return new Promise(resolve => setTimeout(resolve, ms));
2824
2852
  }
@@ -2827,11 +2855,12 @@ const linkTo = (to, targetBlank = true) => () => {
2827
2855
  // # edge.js の retransmitter が送るのを待つ
2828
2856
  await sleep(450);
2829
2857
  }
2830
- if (targetBlank) {
2858
+ const isRequiredWindowOpen = target === 'native' || targetBlank;
2859
+ if (isRequiredWindowOpen) {
2831
2860
  window.open(to);
2832
2861
  }
2833
2862
  Promise.race([_send(), sleep(650)]).then(() => {
2834
- if (!targetBlank) {
2863
+ if (!isRequiredWindowOpen) {
2835
2864
  location.href = to;
2836
2865
  }
2837
2866
  });
@@ -100,7 +100,7 @@ import { props, localVariablesQuery, karteTemplate } from './gen';
100
100
  import App from './App.svelte';
101
101
  import onCreate from './customScript';
102
102
  ${script}
103
- const action = (options: { send: Send; publish: Publish, props: Props; variables: Variables }): KarteAction => {
103
+ const action = (options: { send: Send; publish: Publish, props: Props; variables: Variables, context: any }): KarteAction => {
104
104
  return create(App, {
105
105
  props,
106
106
  send: options.send,
@@ -109,6 +109,7 @@ const action = (options: { send: Send; publish: Publish, props: Props; variables
109
109
  localVariablesQuery,
110
110
  karteTemplate,
111
111
  onCreate,
112
+ context: options.context,
112
113
  });
113
114
  };
114
115
 
package/dist/templates.js CHANGED
@@ -98,7 +98,7 @@ import { props, localVariablesQuery, karteTemplate } from './gen';
98
98
  import App from './App.svelte';
99
99
  import onCreate from './customScript';
100
100
  ${script}
101
- const action = (options: { send: Send; publish: Publish, props: Props; variables: Variables }): KarteAction => {
101
+ const action = (options: { send: Send; publish: Publish, props: Props; variables: Variables, context: any }): KarteAction => {
102
102
  return create(App, {
103
103
  props,
104
104
  send: options.send,
@@ -107,6 +107,7 @@ const action = (options: { send: Send; publish: Publish, props: Props; variables
107
107
  localVariablesQuery,
108
108
  karteTemplate,
109
109
  onCreate,
110
+ context: options.context,
110
111
  });
111
112
  };
112
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaidev/karte-action-sdk",
3
- "version": "1.1.184-28069312.e227ca9d",
3
+ "version": "1.1.184-28093385.169b3110",
4
4
  "author": "Plaid Inc.",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.es.js",