@fluentcommerce/fc-connect-sdk 0.1.51 → 0.1.53

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.
@@ -95,6 +95,70 @@ export interface FluentEvent {
95
95
  export interface CreateEventOptions {
96
96
  mode?: FluentEventMode;
97
97
  }
98
+ export type FluentEventRootEntityType = 'ORDER' | 'LOCATION' | 'FULFILMENT_OPTIONS' | 'PRODUCT_CATALOGUE' | 'INVENTORY_CATALOGUE' | 'VIRTUAL_CATALOGUE' | 'CONTROL_GROUP' | 'RETURN_ORDER' | 'BILLING_ACCOUNT' | 'JOB';
99
+ export type FluentEventEntityType = 'ORDER' | 'FULFILMENT' | 'ARTICLE' | 'CONSIGNMENT' | 'LOCATION' | 'WAVE' | 'FULFILMENT_OPTIONS' | 'FULFILMENT_PLAN' | 'PRODUCT_CATALOGUE' | 'CATEGORY' | 'PRODUCT' | 'INVENTORY_CATALOGUE' | 'INVENTORY_POSITION' | 'INVENTORY_QUANTITY' | 'VIRTUAL_CATALOGUE' | 'VIRTUAL_POSITION' | 'CONTROL_GROUP' | 'CONTROL' | 'RETURN_ORDER' | 'RETURN_FULFILMENT' | 'BILLING_ACCOUNT' | 'CREDIT_MEMO' | 'BATCH';
100
+ export type FluentEventCategory = 'snapshot' | 'ruleSet' | 'rule' | 'ACTION' | 'CUSTOM' | 'exception' | 'ORDER_WORKFLOW';
101
+ export type FluentEventType = 'ORCHESTRATION' | 'ORCHESTRATION_AUDIT' | 'API' | 'INTEGRATION' | 'SECURITY' | 'GENERAL';
102
+ export type FluentEventStatus = 'PENDING' | 'SCHEDULED' | 'NO_MATCH' | 'SUCCESS' | 'FAILED' | 'COMPLETE';
103
+ export type FluentEventQueryParamValue = string | number | boolean;
104
+ export interface FluentEventQueryParams {
105
+ start?: number;
106
+ count?: number;
107
+ from?: string;
108
+ to?: string;
109
+ name?: string;
110
+ category?: FluentEventCategory | string;
111
+ retailerId?: string | number;
112
+ eventType?: FluentEventType | string;
113
+ eventStatus?: FluentEventStatus | string;
114
+ eventId?: string;
115
+ 'context.rootEntityType'?: FluentEventRootEntityType | string;
116
+ 'context.rootEntityId'?: string | number;
117
+ 'context.rootEntityRef'?: string;
118
+ 'context.entityType'?: FluentEventEntityType | string;
119
+ 'context.entityId'?: string | number;
120
+ 'context.entityRef'?: string;
121
+ 'context.sourceEvents'?: string;
122
+ [key: string]: FluentEventQueryParamValue | undefined;
123
+ }
124
+ export interface FluentEventLogContext {
125
+ sourceEvents?: string[];
126
+ entityType?: FluentEventEntityType | string;
127
+ entityId?: string;
128
+ entityRef?: string;
129
+ rootEntityType?: FluentEventRootEntityType | string;
130
+ rootEntityId?: string;
131
+ rootEntityRef?: string;
132
+ [key: string]: JsonValue | undefined;
133
+ }
134
+ export interface FluentEventLogAttribute {
135
+ name: string;
136
+ value: unknown;
137
+ type?: string;
138
+ [key: string]: unknown;
139
+ }
140
+ export interface FluentEventLogItem {
141
+ id: string;
142
+ name: string;
143
+ type?: FluentEventType | string;
144
+ accountId?: string;
145
+ retailerId?: string;
146
+ category?: FluentEventCategory | string;
147
+ context?: FluentEventLogContext;
148
+ eventStatus?: FluentEventStatus | string;
149
+ attributes?: FluentEventLogAttribute[] | Record<string, JsonValue> | null;
150
+ source?: string | null;
151
+ generatedBy?: string;
152
+ generatedOn?: string;
153
+ [key: string]: unknown;
154
+ }
155
+ export interface FluentEventLogResponse {
156
+ start: number;
157
+ count: number;
158
+ hasMore: boolean;
159
+ results: FluentEventLogItem[];
160
+ [key: string]: unknown;
161
+ }
98
162
  export type GraphQLErrorMode = 'throw' | 'partial';
99
163
  export interface GraphQLPayload<T = Record<string, JsonValue>> {
100
164
  query: string;
@@ -1,4 +1,4 @@
1
- import type { FluentEvent, GraphQLPayload, GraphQLResponse, FluentEventMode, JsonValue, FluentBatchPayload, FluentBatchResponse, FluentBatchStatus, FluentJobPayload, FluentJobResponse, FluentJobStatus, FluentJobResults } from '../types/index.js';
1
+ import type { FluentEvent, GraphQLPayload, GraphQLResponse, FluentEventMode, FluentEventLogResponse, FluentEventLogItem, FluentEventQueryParams, JsonValue, FluentBatchPayload, FluentBatchResponse, FluentBatchStatus, FluentJobPayload, FluentJobResponse, FluentJobStatus, FluentJobResults } from '../types/index.js';
2
2
  import type { FluentWebhookPayload, EventResponse } from '../types/index.js';
3
3
  export declare class FluentVersoriClient {
4
4
  private ctx;
@@ -13,6 +13,8 @@ export declare class FluentVersoriClient {
13
13
  private executeSinglePage;
14
14
  private executeWithAutoPagination;
15
15
  sendEvent(event: FluentEvent, mode?: FluentEventMode): Promise<EventResponse>;
16
+ getEvents(params?: FluentEventQueryParams): Promise<FluentEventLogResponse>;
17
+ getEventById(eventId: string): Promise<FluentEventLogItem>;
16
18
  createJob(payload: FluentJobPayload): Promise<FluentJobResponse>;
17
19
  sendBatch(jobId: string, payload: FluentBatchPayload): Promise<FluentBatchResponse>;
18
20
  getJobStatus(jobId: string): Promise<FluentJobStatus>;
@@ -20,6 +22,7 @@ export declare class FluentVersoriClient {
20
22
  getJobResults(jobId: string): Promise<FluentJobResults>;
21
23
  query<T = JsonValue>(queryOrPayload: string | GraphQLPayload, variables?: Record<string, any>): Promise<T | undefined>;
22
24
  mutate<T = JsonValue>(mutationOrPayload: string | GraphQLPayload, variables?: Record<string, any>): Promise<T | undefined>;
25
+ private buildEventQueryString;
23
26
  private throwApiError;
24
27
  private fetchWithRetry;
25
28
  validateWebhook(payload: FluentWebhookPayload, signature?: string, rawPayload?: string, publicKey?: string): Promise<boolean>;
@@ -424,6 +424,79 @@ export class FluentVersoriClient {
424
424
  return { success: true, statusCode: response.status, message: text };
425
425
  }
426
426
  }
427
+ async getEvents(params = {}) {
428
+ const query = this.buildEventQueryString(params);
429
+ const endpoint = query ? `/api/v4.1/event?${query}` : '/api/v4.1/event';
430
+ this.ctx.log.info('[fc-connect-sdk:event] Searching event logs', {
431
+ endpoint,
432
+ filterCount: Object.keys(params).length,
433
+ hasDateRange: !!(params.from || params.to),
434
+ entityType: params['context.entityType'],
435
+ rootEntityType: params['context.rootEntityType'],
436
+ eventStatus: params.eventStatus,
437
+ });
438
+ const response = await this.fetchWithRetry(endpoint, {
439
+ method: 'GET',
440
+ headers: {
441
+ 'Content-Type': 'application/json',
442
+ },
443
+ });
444
+ const text = response.text;
445
+ if (!response.ok) {
446
+ this.ctx.log.error('[fc-connect-sdk:event] Failed to search events', {
447
+ status: response.status,
448
+ body: text,
449
+ });
450
+ this.throwApiError('Get events failed', response.status, text);
451
+ }
452
+ try {
453
+ const result = JSON.parse(text);
454
+ this.ctx.log.info('[fc-connect-sdk:event] Event search completed', {
455
+ resultCount: result.count,
456
+ hasMore: result.hasMore,
457
+ start: result.start,
458
+ });
459
+ return result;
460
+ }
461
+ catch {
462
+ throw new FluentAPIError('Failed to parse event log response', response.status, text);
463
+ }
464
+ }
465
+ async getEventById(eventId) {
466
+ if (!eventId) {
467
+ throw new FluentValidationError('eventId is required');
468
+ }
469
+ this.ctx.log.info(`[fc-connect-sdk:event] Getting event by ID: ${eventId}`, { eventId });
470
+ const response = await this.fetchWithRetry(`/api/v4.1/event/${eventId}`, {
471
+ method: 'GET',
472
+ headers: {
473
+ 'Content-Type': 'application/json',
474
+ },
475
+ });
476
+ const text = response.text;
477
+ if (!response.ok) {
478
+ this.ctx.log.error(`[fc-connect-sdk:event] Failed to get event ${eventId}`, {
479
+ eventId,
480
+ status: response.status,
481
+ body: text,
482
+ });
483
+ this.throwApiError(`Get event ${eventId} failed`, response.status, text);
484
+ }
485
+ try {
486
+ const event = JSON.parse(text);
487
+ this.ctx.log.info(`[fc-connect-sdk:event] Event retrieved: ${event.name}`, {
488
+ eventId: event.id,
489
+ name: event.name,
490
+ type: event.type,
491
+ eventStatus: event.eventStatus,
492
+ entityType: event.context?.entityType,
493
+ });
494
+ return event;
495
+ }
496
+ catch {
497
+ throw new FluentAPIError('Failed to parse event response', response.status, text);
498
+ }
499
+ }
427
500
  async createJob(payload) {
428
501
  this.ctx.log.info(`[fc-connect-sdk:job] Creating job "${payload.name}"`, {
429
502
  name: payload.name,
@@ -571,6 +644,16 @@ export class FluentVersoriClient {
571
644
  const result = await this.graphql(payload);
572
645
  return result.data;
573
646
  }
647
+ buildEventQueryString(params) {
648
+ const searchParams = new URLSearchParams();
649
+ for (const [key, value] of Object.entries(params)) {
650
+ if (value === undefined || value === null || value === '') {
651
+ continue;
652
+ }
653
+ searchParams.append(key, String(value));
654
+ }
655
+ return searchParams.toString();
656
+ }
574
657
  throwApiError(message, status, responseText) {
575
658
  if (status === 401) {
576
659
  throw new AuthenticationError(`${message}: ${responseText}`, { response: responseText });