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.d.cts CHANGED
@@ -5,7 +5,7 @@ import { f as formatPayment, a as formatMinor, g as getCurrencySymbol, b as getC
5
5
  interface AuthTokens {
6
6
  accessToken: string;
7
7
  refreshToken?: string;
8
- expiresAt?: number;
8
+ accessExpiresAt?: number;
9
9
  accountId?: string;
10
10
  }
11
11
  interface HttpClientConfig {
@@ -148,7 +148,7 @@ declare global {
148
148
  }
149
149
  declare function track(eventName: string, params?: Record<string, any>): void;
150
150
 
151
- declare const SDK_VERSION = "0.7.62";
151
+ declare const SDK_VERSION = "0.7.64";
152
152
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
153
153
  interface ApiConfig {
154
154
  httpClient: any;
@@ -398,30 +398,30 @@ declare function createAdmin(config: HttpClientConfig & {
398
398
  };
399
399
  automation: {
400
400
  agent: {
401
- createAgent(params: CreateAgentParams, options?: RequestOptions): Promise<any>;
402
- updateAgent(params: UpdateAgentParams, options?: RequestOptions): Promise<any>;
403
- deleteAgent(params: DeleteAgentParams, options?: RequestOptions): Promise<any>;
404
- getAgent(params: GetAgentParams, options?: RequestOptions): Promise<any>;
405
- getAgents(params?: GetAgentsParams, options?: RequestOptions): Promise<any>;
406
- sendMessage(params: RunAgentParams, options?: RequestOptions): Promise<any>;
407
- getChats(params: GetAgentChatsParams, options?: RequestOptions): Promise<any>;
408
- getChat(params: GetAgentChatParams, options?: RequestOptions): Promise<any>;
409
- updateChat(params: UpdateAgentChatParams, options?: RequestOptions): Promise<any>;
410
- rateChat(params: RateAgentChatParams, options?: RequestOptions): Promise<any>;
411
- getBusinessChats(params: GetBusinessChatsParams, options?: RequestOptions): Promise<any>;
412
- getChatMessages(params: GetAgentChatParams & {
401
+ create: (params: CreateAgentParams, options?: RequestOptions) => Promise<any>;
402
+ update: (params: UpdateAgentParams, options?: RequestOptions) => Promise<any>;
403
+ delete: (params: DeleteAgentParams, options?: RequestOptions) => Promise<any>;
404
+ get: (params: GetAgentParams, options?: RequestOptions) => Promise<any>;
405
+ find: (params?: GetAgentsParams, options?: RequestOptions) => Promise<any>;
406
+ sendMessage: (params: RunAgentParams, options?: RequestOptions) => Promise<any>;
407
+ getChats: (params: GetAgentChatsParams, options?: RequestOptions) => Promise<any>;
408
+ getChat: (params: GetAgentChatParams, options?: RequestOptions) => Promise<any>;
409
+ updateChat: (params: UpdateAgentChatParams, options?: RequestOptions) => Promise<any>;
410
+ rateChat: (params: RateAgentChatParams, options?: RequestOptions) => Promise<any>;
411
+ getBusinessChats: (params: GetBusinessChatsParams, options?: RequestOptions) => Promise<any>;
412
+ getChatMessages: (params: GetAgentChatParams & {
413
413
  limit?: number;
414
- }, options?: RequestOptions): Promise<any>;
414
+ }, options?: RequestOptions) => Promise<any>;
415
415
  };
416
416
  workflow: {
417
- createWorkflow(params: CreateWorkflowParams, options?: RequestOptions): Promise<any>;
418
- updateWorkflow(params: UpdateWorkflowParams, options?: RequestOptions): Promise<any>;
419
- deleteWorkflow(params: DeleteWorkflowParams, options?: RequestOptions): Promise<any>;
420
- getWorkflow(params: GetWorkflowParams, options?: RequestOptions): Promise<any>;
421
- getWorkflows(params?: GetWorkflowsParams, options?: RequestOptions): Promise<any>;
422
- triggerWorkflow(params: TriggerWorkflowParams, options?: RequestOptions): Promise<any>;
423
- getWorkflowExecutions(params: GetWorkflowExecutionsParams, options?: RequestOptions): Promise<any>;
424
- getWorkflowExecution(params: GetWorkflowExecutionParams, options?: RequestOptions): Promise<any>;
417
+ create: (params: CreateWorkflowParams, options?: RequestOptions) => Promise<any>;
418
+ update: (params: UpdateWorkflowParams, options?: RequestOptions) => Promise<any>;
419
+ delete: (params: DeleteWorkflowParams, options?: RequestOptions) => Promise<any>;
420
+ get: (params: GetWorkflowParams, options?: RequestOptions) => Promise<any>;
421
+ find: (params?: GetWorkflowsParams, options?: RequestOptions) => Promise<any>;
422
+ trigger: (params: TriggerWorkflowParams, options?: RequestOptions) => Promise<any>;
423
+ getExecutions: (params: GetWorkflowExecutionsParams, options?: RequestOptions) => Promise<any>;
424
+ getExecution: (params: GetWorkflowExecutionParams, options?: RequestOptions) => Promise<any>;
425
425
  };
426
426
  };
427
427
  analytics: {
@@ -636,6 +636,7 @@ declare function createStorefront(config: HttpClientConfig & {
636
636
  analytics: {
637
637
  track: typeof track;
638
638
  };
639
+ ensureSession: () => Promise<void>;
639
640
  setBusinessId: (businessId: string) => void;
640
641
  getBusinessId: () => string;
641
642
  setMarket: (market: string) => void;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { f as formatPayment, a as formatMinor, g as getCurrencySymbol, b as getC
5
5
  interface AuthTokens {
6
6
  accessToken: string;
7
7
  refreshToken?: string;
8
- expiresAt?: number;
8
+ accessExpiresAt?: number;
9
9
  accountId?: string;
10
10
  }
11
11
  interface HttpClientConfig {
@@ -148,7 +148,7 @@ declare global {
148
148
  }
149
149
  declare function track(eventName: string, params?: Record<string, any>): void;
150
150
 
151
- declare const SDK_VERSION = "0.7.62";
151
+ declare const SDK_VERSION = "0.7.64";
152
152
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
153
153
  interface ApiConfig {
154
154
  httpClient: any;
@@ -398,30 +398,30 @@ declare function createAdmin(config: HttpClientConfig & {
398
398
  };
399
399
  automation: {
400
400
  agent: {
401
- createAgent(params: CreateAgentParams, options?: RequestOptions): Promise<any>;
402
- updateAgent(params: UpdateAgentParams, options?: RequestOptions): Promise<any>;
403
- deleteAgent(params: DeleteAgentParams, options?: RequestOptions): Promise<any>;
404
- getAgent(params: GetAgentParams, options?: RequestOptions): Promise<any>;
405
- getAgents(params?: GetAgentsParams, options?: RequestOptions): Promise<any>;
406
- sendMessage(params: RunAgentParams, options?: RequestOptions): Promise<any>;
407
- getChats(params: GetAgentChatsParams, options?: RequestOptions): Promise<any>;
408
- getChat(params: GetAgentChatParams, options?: RequestOptions): Promise<any>;
409
- updateChat(params: UpdateAgentChatParams, options?: RequestOptions): Promise<any>;
410
- rateChat(params: RateAgentChatParams, options?: RequestOptions): Promise<any>;
411
- getBusinessChats(params: GetBusinessChatsParams, options?: RequestOptions): Promise<any>;
412
- getChatMessages(params: GetAgentChatParams & {
401
+ create: (params: CreateAgentParams, options?: RequestOptions) => Promise<any>;
402
+ update: (params: UpdateAgentParams, options?: RequestOptions) => Promise<any>;
403
+ delete: (params: DeleteAgentParams, options?: RequestOptions) => Promise<any>;
404
+ get: (params: GetAgentParams, options?: RequestOptions) => Promise<any>;
405
+ find: (params?: GetAgentsParams, options?: RequestOptions) => Promise<any>;
406
+ sendMessage: (params: RunAgentParams, options?: RequestOptions) => Promise<any>;
407
+ getChats: (params: GetAgentChatsParams, options?: RequestOptions) => Promise<any>;
408
+ getChat: (params: GetAgentChatParams, options?: RequestOptions) => Promise<any>;
409
+ updateChat: (params: UpdateAgentChatParams, options?: RequestOptions) => Promise<any>;
410
+ rateChat: (params: RateAgentChatParams, options?: RequestOptions) => Promise<any>;
411
+ getBusinessChats: (params: GetBusinessChatsParams, options?: RequestOptions) => Promise<any>;
412
+ getChatMessages: (params: GetAgentChatParams & {
413
413
  limit?: number;
414
- }, options?: RequestOptions): Promise<any>;
414
+ }, options?: RequestOptions) => Promise<any>;
415
415
  };
416
416
  workflow: {
417
- createWorkflow(params: CreateWorkflowParams, options?: RequestOptions): Promise<any>;
418
- updateWorkflow(params: UpdateWorkflowParams, options?: RequestOptions): Promise<any>;
419
- deleteWorkflow(params: DeleteWorkflowParams, options?: RequestOptions): Promise<any>;
420
- getWorkflow(params: GetWorkflowParams, options?: RequestOptions): Promise<any>;
421
- getWorkflows(params?: GetWorkflowsParams, options?: RequestOptions): Promise<any>;
422
- triggerWorkflow(params: TriggerWorkflowParams, options?: RequestOptions): Promise<any>;
423
- getWorkflowExecutions(params: GetWorkflowExecutionsParams, options?: RequestOptions): Promise<any>;
424
- getWorkflowExecution(params: GetWorkflowExecutionParams, options?: RequestOptions): Promise<any>;
417
+ create: (params: CreateWorkflowParams, options?: RequestOptions) => Promise<any>;
418
+ update: (params: UpdateWorkflowParams, options?: RequestOptions) => Promise<any>;
419
+ delete: (params: DeleteWorkflowParams, options?: RequestOptions) => Promise<any>;
420
+ get: (params: GetWorkflowParams, options?: RequestOptions) => Promise<any>;
421
+ find: (params?: GetWorkflowsParams, options?: RequestOptions) => Promise<any>;
422
+ trigger: (params: TriggerWorkflowParams, options?: RequestOptions) => Promise<any>;
423
+ getExecutions: (params: GetWorkflowExecutionsParams, options?: RequestOptions) => Promise<any>;
424
+ getExecution: (params: GetWorkflowExecutionParams, options?: RequestOptions) => Promise<any>;
425
425
  };
426
426
  };
427
427
  analytics: {
@@ -636,6 +636,7 @@ declare function createStorefront(config: HttpClientConfig & {
636
636
  analytics: {
637
637
  track: typeof track;
638
638
  };
639
+ ensureSession: () => Promise<void>;
639
640
  setBusinessId: (businessId: string) => void;
640
641
  getBusinessId: () => string;
641
642
  setMarket: (market: string) => void;
package/dist/index.js CHANGED
@@ -87,9 +87,9 @@ function createHttpClient(cfg) {
87
87
  "Content-Type": "application/json",
88
88
  ...options?.headers || {}
89
89
  };
90
- let { accessToken, expiresAt } = await cfg.getToken();
90
+ let { accessToken, accessExpiresAt } = await cfg.getToken();
91
91
  const nowSec = Date.now() / 1e3;
92
- if (expiresAt && nowSec > expiresAt) {
92
+ if (accessExpiresAt && nowSec > accessExpiresAt) {
93
93
  await ensureFreshToken();
94
94
  const tokens = await cfg.getToken();
95
95
  accessToken = tokens.accessToken;
@@ -2712,7 +2712,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
2712
2712
  }
2713
2713
 
2714
2714
  // src/index.ts
2715
- var SDK_VERSION = "0.7.62";
2715
+ var SDK_VERSION = "0.7.64";
2716
2716
  var SUPPORTED_FRAMEWORKS = [
2717
2717
  "astro",
2718
2718
  "react",
@@ -2919,8 +2919,30 @@ async function createAdmin(config) {
2919
2919
  reaction: reactionApi
2920
2920
  },
2921
2921
  automation: {
2922
- agent: agentApi,
2923
- workflow: workflowApi
2922
+ agent: {
2923
+ create: agentApi.createAgent,
2924
+ update: agentApi.updateAgent,
2925
+ delete: agentApi.deleteAgent,
2926
+ get: agentApi.getAgent,
2927
+ find: agentApi.getAgents,
2928
+ sendMessage: agentApi.sendMessage,
2929
+ getChats: agentApi.getChats,
2930
+ getChat: agentApi.getChat,
2931
+ updateChat: agentApi.updateChat,
2932
+ rateChat: agentApi.rateChat,
2933
+ getBusinessChats: agentApi.getBusinessChats,
2934
+ getChatMessages: agentApi.getChatMessages
2935
+ },
2936
+ workflow: {
2937
+ create: workflowApi.createWorkflow,
2938
+ update: workflowApi.updateWorkflow,
2939
+ delete: workflowApi.deleteWorkflow,
2940
+ get: workflowApi.getWorkflow,
2941
+ find: workflowApi.getWorkflows,
2942
+ trigger: workflowApi.triggerWorkflow,
2943
+ getExecutions: workflowApi.getWorkflowExecutions,
2944
+ getExecution: workflowApi.getWorkflowExecution
2945
+ }
2924
2946
  },
2925
2947
  analytics: {
2926
2948
  track
@@ -2961,16 +2983,36 @@ async function createStorefront(config) {
2961
2983
  getToken: config.getToken
2962
2984
  };
2963
2985
  const storefrontApi = createStorefrontApi(apiConfig);
2964
- if (typeof window !== "undefined" && apiConfig.businessId) {
2965
- storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
2966
- if (!configs) return;
2967
- for (const c of Array.isArray(configs) ? configs : [configs]) {
2968
- if (c.measurementId) {
2969
- injectGA4Script(c.measurementId);
2970
- }
2986
+ let sessionPromise = null;
2987
+ function ensureSession() {
2988
+ if (typeof window === "undefined") return Promise.resolve();
2989
+ if (sessionPromise) return sessionPromise;
2990
+ sessionPromise = (async () => {
2991
+ const tokens = await apiConfig.getToken();
2992
+ if (tokens.accessToken) return;
2993
+ const result = await storefrontApi.crm.customer.initialize();
2994
+ if (result?.accessToken) {
2995
+ apiConfig.setToken(result);
2971
2996
  }
2972
- }).catch(() => {
2997
+ })().finally(() => {
2998
+ sessionPromise = null;
2999
+ });
3000
+ return sessionPromise;
3001
+ }
3002
+ if (typeof window !== "undefined") {
3003
+ ensureSession().catch(() => {
2973
3004
  });
3005
+ if (apiConfig.businessId) {
3006
+ storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
3007
+ if (!configs) return;
3008
+ for (const c of Array.isArray(configs) ? configs : [configs]) {
3009
+ if (c.measurementId) {
3010
+ injectGA4Script(c.measurementId);
3011
+ }
3012
+ }
3013
+ }).catch(() => {
3014
+ });
3015
+ }
2974
3016
  }
2975
3017
  return {
2976
3018
  business: storefrontApi.business,
@@ -2982,6 +3024,7 @@ async function createStorefront(config) {
2982
3024
  analytics: {
2983
3025
  track
2984
3026
  },
3027
+ ensureSession,
2985
3028
  setBusinessId: (businessId) => {
2986
3029
  apiConfig.businessId = businessId;
2987
3030
  },