arky-sdk 0.7.62 → 0.7.64

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/dist/index.cjs CHANGED
@@ -89,9 +89,9 @@ function createHttpClient(cfg) {
89
89
  "Content-Type": "application/json",
90
90
  ...options?.headers || {}
91
91
  };
92
- let { accessToken, expiresAt } = await cfg.getToken();
92
+ let { accessToken, accessExpiresAt } = await cfg.getToken();
93
93
  const nowSec = Date.now() / 1e3;
94
- if (expiresAt && nowSec > expiresAt) {
94
+ if (accessExpiresAt && nowSec > accessExpiresAt) {
95
95
  await ensureFreshToken();
96
96
  const tokens = await cfg.getToken();
97
97
  accessToken = tokens.accessToken;
@@ -2714,7 +2714,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
2714
2714
  }
2715
2715
 
2716
2716
  // src/index.ts
2717
- var SDK_VERSION = "0.7.62";
2717
+ var SDK_VERSION = "0.7.64";
2718
2718
  var SUPPORTED_FRAMEWORKS = [
2719
2719
  "astro",
2720
2720
  "react",
@@ -2921,8 +2921,30 @@ async function createAdmin(config) {
2921
2921
  reaction: reactionApi
2922
2922
  },
2923
2923
  automation: {
2924
- agent: agentApi,
2925
- workflow: workflowApi
2924
+ agent: {
2925
+ create: agentApi.createAgent,
2926
+ update: agentApi.updateAgent,
2927
+ delete: agentApi.deleteAgent,
2928
+ get: agentApi.getAgent,
2929
+ find: agentApi.getAgents,
2930
+ sendMessage: agentApi.sendMessage,
2931
+ getChats: agentApi.getChats,
2932
+ getChat: agentApi.getChat,
2933
+ updateChat: agentApi.updateChat,
2934
+ rateChat: agentApi.rateChat,
2935
+ getBusinessChats: agentApi.getBusinessChats,
2936
+ getChatMessages: agentApi.getChatMessages
2937
+ },
2938
+ workflow: {
2939
+ create: workflowApi.createWorkflow,
2940
+ update: workflowApi.updateWorkflow,
2941
+ delete: workflowApi.deleteWorkflow,
2942
+ get: workflowApi.getWorkflow,
2943
+ find: workflowApi.getWorkflows,
2944
+ trigger: workflowApi.triggerWorkflow,
2945
+ getExecutions: workflowApi.getWorkflowExecutions,
2946
+ getExecution: workflowApi.getWorkflowExecution
2947
+ }
2926
2948
  },
2927
2949
  analytics: {
2928
2950
  track
@@ -2963,16 +2985,36 @@ async function createStorefront(config) {
2963
2985
  getToken: config.getToken
2964
2986
  };
2965
2987
  const storefrontApi = createStorefrontApi(apiConfig);
2966
- if (typeof window !== "undefined" && apiConfig.businessId) {
2967
- storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
2968
- if (!configs) return;
2969
- for (const c of Array.isArray(configs) ? configs : [configs]) {
2970
- if (c.measurementId) {
2971
- injectGA4Script(c.measurementId);
2972
- }
2988
+ let sessionPromise = null;
2989
+ function ensureSession() {
2990
+ if (typeof window === "undefined") return Promise.resolve();
2991
+ if (sessionPromise) return sessionPromise;
2992
+ sessionPromise = (async () => {
2993
+ const tokens = await apiConfig.getToken();
2994
+ if (tokens.accessToken) return;
2995
+ const result = await storefrontApi.crm.customer.initialize();
2996
+ if (result?.accessToken) {
2997
+ apiConfig.setToken(result);
2973
2998
  }
2974
- }).catch(() => {
2999
+ })().finally(() => {
3000
+ sessionPromise = null;
3001
+ });
3002
+ return sessionPromise;
3003
+ }
3004
+ if (typeof window !== "undefined") {
3005
+ ensureSession().catch(() => {
2975
3006
  });
3007
+ if (apiConfig.businessId) {
3008
+ storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
3009
+ if (!configs) return;
3010
+ for (const c of Array.isArray(configs) ? configs : [configs]) {
3011
+ if (c.measurementId) {
3012
+ injectGA4Script(c.measurementId);
3013
+ }
3014
+ }
3015
+ }).catch(() => {
3016
+ });
3017
+ }
2976
3018
  }
2977
3019
  return {
2978
3020
  business: storefrontApi.business,
@@ -2984,6 +3026,7 @@ async function createStorefront(config) {
2984
3026
  analytics: {
2985
3027
  track
2986
3028
  },
3029
+ ensureSession,
2987
3030
  setBusinessId: (businessId) => {
2988
3031
  apiConfig.businessId = businessId;
2989
3032
  },