|
| 1 | +import { |
| 2 | + ProductAction, |
| 3 | + Product, |
| 4 | + Promotion, |
| 5 | + CommerceEvent, |
| 6 | +} from '@mparticle/event-models'; |
| 7 | +import { |
| 8 | + SDKEventAttrs, |
| 9 | + SDKEventOptions, |
| 10 | + TransactionAttributes, |
| 11 | +} from '@mparticle/web-sdk'; |
| 12 | +import { valueof } from './utils'; |
| 13 | +import { |
| 14 | + ProductActionType, |
| 15 | + PromotionActionType, |
| 16 | + CommerceEventType, |
| 17 | + EventType, |
| 18 | +} from './types'; |
| 19 | +import { |
| 20 | + SDKEvent, |
| 21 | + SDKEventCustomFlags, |
| 22 | + SDKImpression, |
| 23 | + SDKProduct, |
| 24 | + SDKProductImpression, |
| 25 | + SDKPromotion, |
| 26 | +} from './sdkRuntimeModels'; |
| 27 | + |
| 28 | +interface IECommerceShared { |
| 29 | + createProduct( |
| 30 | + name: string, |
| 31 | + sku: string | number, |
| 32 | + price: string | number, |
| 33 | + quantity?: string | number, |
| 34 | + variant?: string, |
| 35 | + category?: string, |
| 36 | + brand?: string, |
| 37 | + position?: number, |
| 38 | + couponCode?: string, |
| 39 | + attributes?: SDKEventAttrs |
| 40 | + ): SDKProduct | null; |
| 41 | + createImpression(name: string, product: Product): SDKImpression | null; |
| 42 | + createPromotion( |
| 43 | + id: string | number, |
| 44 | + creative?: string, |
| 45 | + name?: string, |
| 46 | + position?: number |
| 47 | + ): SDKPromotion | null; |
| 48 | + createTransactionAttributes( |
| 49 | + id: string | number, |
| 50 | + affiliation?: string, |
| 51 | + couponCode?: string, |
| 52 | + revenue?: string | number, |
| 53 | + shipping?: string | number, |
| 54 | + tax?: number |
| 55 | + ): TransactionAttributes | null; |
| 56 | + expandCommerceEvent(event: CommerceEvent): SDKEvent[] | null; |
| 57 | +} |
| 58 | + |
| 59 | +export interface SDKCart { |
| 60 | + add(product: SDKProduct | SDKProduct[], logEvent?: boolean): void; |
| 61 | + remove(product: SDKProduct | SDKProduct[], logEvent?: boolean): void; |
| 62 | + clear(): void; |
| 63 | +} |
| 64 | + |
| 65 | +// Used for the public `eCommerce` namespace |
| 66 | +export interface SDKECommerceAPI extends IECommerceShared { |
| 67 | + logCheckout( |
| 68 | + step: number, |
| 69 | + option?: string, |
| 70 | + attrs?: SDKEventAttrs, |
| 71 | + customFlags?: SDKEventCustomFlags |
| 72 | + ): void; |
| 73 | + logImpression( |
| 74 | + impression: SDKProductImpression, |
| 75 | + attrs?: SDKEventAttrs, |
| 76 | + customFlags?: SDKEventCustomFlags, |
| 77 | + eventOptions?: SDKEventOptions |
| 78 | + ): void; |
| 79 | + logProductAction( |
| 80 | + productActionType: valueof<typeof ProductActionType>, |
| 81 | + product: SDKProduct | SDKProduct[], |
| 82 | + attrs?: SDKEventAttrs, |
| 83 | + customFlags?: SDKEventCustomFlags, |
| 84 | + transactionAttributes?: TransactionAttributes, |
| 85 | + eventOptions?: SDKEventOptions |
| 86 | + ): void; |
| 87 | + logPromotion( |
| 88 | + type: valueof<typeof PromotionActionType>, |
| 89 | + promotion: SDKPromotion, |
| 90 | + attrs?: SDKEventAttrs, |
| 91 | + customFlags?: SDKEventCustomFlags, |
| 92 | + eventOptions?: SDKEventOptions |
| 93 | + ): void; |
| 94 | + setCurrencyCode(code: string): void; |
| 95 | + |
| 96 | + /* |
| 97 | + * @deprecated |
| 98 | + */ |
| 99 | + Cart: SDKCart; |
| 100 | + |
| 101 | + /* |
| 102 | + * @deprecated |
| 103 | + */ |
| 104 | + logPurchase( |
| 105 | + transactionAttributes: TransactionAttributes, |
| 106 | + product: SDKProduct | SDKProduct[], |
| 107 | + clearCart?: boolean, |
| 108 | + attrs?: SDKEventAttrs, |
| 109 | + customFlags?: SDKEventCustomFlags |
| 110 | + ): void; |
| 111 | + |
| 112 | + /* |
| 113 | + * @deprecated |
| 114 | + */ |
| 115 | + logRefund( |
| 116 | + transactionAttributes: TransactionAttributes, |
| 117 | + product: SDKProduct | SDKProduct[], |
| 118 | + clearCart?: boolean, |
| 119 | + attrs?: SDKEventAttrs, |
| 120 | + customFlags?: SDKEventCustomFlags |
| 121 | + ): void; |
| 122 | +} |
| 123 | + |
| 124 | +interface ExtractedActionAttributes { |
| 125 | + Affiliation?: string; |
| 126 | + 'Coupon Code'?: string; |
| 127 | + 'Total Amount'?: number; |
| 128 | + 'Shipping Amount'?: number; |
| 129 | + 'Tax Amount'?: number; |
| 130 | + 'Checkout Option'?: string; |
| 131 | + 'Checkout Step'?: number; |
| 132 | + 'Transaction ID'?: string; |
| 133 | +} |
| 134 | +interface ExtractedProductAttributes { |
| 135 | + 'Coupon Code'?: string; |
| 136 | + Brand?: string; |
| 137 | + Category?: string; |
| 138 | + Name?: string; |
| 139 | + Id?: string; |
| 140 | + 'Item Price'?: number; |
| 141 | + Quantity?: number; |
| 142 | + Position?: number; |
| 143 | + Variant?: string; |
| 144 | + 'Total Product Amount': number; |
| 145 | +} |
| 146 | +interface ExtractedPromotionAttributes { |
| 147 | + Id?: string; |
| 148 | + Creative?: string; |
| 149 | + Name?: string; |
| 150 | + Position?: number; |
| 151 | +} |
| 152 | +interface ExtractedTransactionId { |
| 153 | + 'Transaction ID'?: string; |
| 154 | +} |
| 155 | + |
| 156 | +// Used for the private `_Ecommerce` namespace |
| 157 | +export interface IECommerce extends IECommerceShared { |
| 158 | + buildProductList(event: SDKEvent, product: Product | Product[]): Product[]; |
| 159 | + convertProductActionToEventType( |
| 160 | + productActionType: valueof<typeof ProductActionType> |
| 161 | + ): // https://go.mparticle.com/work/SQDSDKS-4801 |
| 162 | + typeof CommerceEventType | typeof EventType | null; |
| 163 | + convertPromotionActionToEventType( |
| 164 | + promotionActionType: valueof<typeof PromotionActionType> |
| 165 | + ): typeof CommerceEventType | null; |
| 166 | + convertTransactionAttributesToProductAction( |
| 167 | + transactionAttributes: TransactionAttributes, |
| 168 | + productAction: ProductAction |
| 169 | + ): void; |
| 170 | + createCommerceEventObject( |
| 171 | + customFlags: SDKEventCustomFlags, |
| 172 | + options?: SDKEventOptions |
| 173 | + ): SDKEvent | null; |
| 174 | + expandProductAction(commerceEvent: CommerceEvent): SDKEvent[]; |
| 175 | + expandProductImpression(commerceEvent: CommerceEvent): SDKEvent[]; |
| 176 | + expandPromotionAction(commerceEvent: CommerceEvent): SDKEvent[]; |
| 177 | + extractActionAttributes( |
| 178 | + attributes: ExtractedActionAttributes, |
| 179 | + productAction: ProductAction |
| 180 | + ): void; |
| 181 | + extractProductAttributes( |
| 182 | + attributes: ExtractedProductAttributes, |
| 183 | + product: Product |
| 184 | + ): void; |
| 185 | + extractPromotionAttributes( |
| 186 | + attributes: ExtractedPromotionAttributes, |
| 187 | + promotion: Promotion |
| 188 | + ): void; |
| 189 | + extractTransactionId( |
| 190 | + attributes: ExtractedTransactionId, |
| 191 | + productAction: ProductAction |
| 192 | + ): void; |
| 193 | + generateExpandedEcommerceName(eventName: string, plusOne: boolean): string; |
| 194 | + getProductActionEventName( |
| 195 | + productActionType: valueof<typeof ProductActionType> |
| 196 | + ): string; |
| 197 | + getPromotionActionEventName( |
| 198 | + promotionActionType: valueof<typeof PromotionActionType> |
| 199 | + ): string; |
| 200 | + sanitizeAmount(amount: string | number, category: string): number; |
| 201 | +} |
0 commit comments