@daffodil/cart 0.86.0 → 0.87.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"daffodil-cart.mjs","sources":["../../../libs/cart/src/errors/codes.enum.ts","../../../libs/cart/src/errors/resolution/cart-resolution.ts","../../../libs/cart/src/errors/resolution/cart-not-found-or-created-resolution.ts","../../../libs/cart/src/errors/resolution/cart-server-side-resolution.ts","../../../libs/cart/src/errors/resolution/cart-storage-resolution.ts","../../../libs/cart/src/errors/map.ts","../../../libs/cart/src/models/cart-item-input.ts","../../../libs/cart/src/models/cart-total.ts","../../../libs/cart/src/injection-tokens/payment-method-map.ts","../../../libs/cart/src/helpers/get-affected-item.ts","../../../libs/cart/src/helpers/input-to-item-transform.ts","../../../libs/cart/src/helpers/get-item-total-discount.ts","../../../libs/cart/src/storage/cart-storage.service.ts","../../../libs/cart/src/daffodil-cart.ts"],"sourcesContent":["/**\n * An enum for the cart error codes.\n * Each error code is unique to an error class.\n */\nexport enum DaffCartErrorCodes {\n CART_RESOLUTION = 'DAFF_CART_RESOLUTION',\n CART_STORAGE_RESOLUTION = 'DAFF_CART_STORAGE_RESOLUTION',\n CART_SERVER_SIDE_RESOLUTION = 'DAFF_CART_SERVER_SIDE_RESOLUTION',\n CART_NOT_FOUND_OR_CREATED_RESOLUTION = 'DAFF_CART_NOT_FOUND_OR_CREATED_RESOLUTION',\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n *\n * @inheritdoc\n */\nexport class DaffCartResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n * This happens when the cart cannot be found and a new cart cannot be created.\n *\n * @inheritdoc\n */\nexport class DaffCartNotFoundOrCreatedResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_NOT_FOUND_OR_CREATED_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n * This happens when the app is running in a server environment.\n * This is normal and expected in SSR.\n *\n * @inheritdoc\n */\nexport class DaffCartServerSideResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_SERVER_SIDE_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n * This happens when loading the cart ID from storage throws an exception.\n *\n * @inheritdoc\n */\nexport class DaffCartStorageResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_STORAGE_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import { DaffCartErrorCodes } from './codes.enum';\nimport {\n DaffCartResolutionError,\n DaffCartStorageResolutionError,\n DaffCartServerSideResolutionError,\n DaffCartNotFoundOrCreatedResolutionError,\n} from './resolution/public_api';\n\n/**\n * A mapping from error codes to error class constructors.\n */\nexport const DaffCartErrorMap = {\n [DaffCartErrorCodes.CART_RESOLUTION]: DaffCartResolutionError,\n [DaffCartErrorCodes.CART_STORAGE_RESOLUTION]: DaffCartStorageResolutionError,\n [DaffCartErrorCodes.CART_SERVER_SIDE_RESOLUTION]: DaffCartServerSideResolutionError,\n [DaffCartErrorCodes.CART_NOT_FOUND_OR_CREATED_RESOLUTION]: DaffCartNotFoundOrCreatedResolutionError,\n};\n","import { ID } from '@daffodil/core';\nimport { DaffProduct } from '@daffodil/product';\n\n/**\n * An enum for the type of the cart item.\n */\n// TODO: remove \"input\" designation\nexport enum DaffCartItemInputType {\n Simple = 'simple',\n Composite = 'composite',\n Configurable = 'configurable'\n}\n\n/**\n * A set of fields specifying how to add a product to the cart.\n */\nexport interface DaffCartItemInput {\n /**\n * The type of cart item that corresponds to the product being added to the cart.\n */\n type: DaffCartItemInputType;\n /**\n * The ID of the product to add to the cart.\n */\n productId: DaffProduct['id'];\n /**\n * How many of the product should be added to the cart.\n */\n qty: number;\n}\n\n/**\n * A more constrained cart item input for simple products.\n */\nexport interface DaffSimpleCartItemInput extends DaffCartItemInput {\n type: DaffCartItemInputType.Simple;\n}\n\n/**\n * A cart item input for composite products.\n */\nexport interface DaffCompositeCartItemInput extends DaffCartItemInput {\n type: DaffCartItemInputType.Composite;\n /**\n * The selected options for the composite product to be added to the cart.\n */\n options: DaffCompositeCartItemInputOption[];\n}\n\n/**\n * Designates a particular option for the composite product to add to the cart.\n */\nexport interface DaffCompositeCartItemInputOption {\n /**\n * An identifier of the option for which a value has been chosen.\n */\n // TODO: change to ID type?\n code: string | number;\n /**\n * How many of the specified option should be added to the cart.\n */\n quantity: number;\n /**\n * The value identifying the chosen composite product option.\n */\n value: string;\n}\n\n/**\n * Designates a particular configurable product variant to add to the cart.\n */\nexport interface DaffConfigurableCartItemInput extends DaffCartItemInput {\n type: DaffCartItemInputType.Configurable;\n /**\n * The value identifying the particular configurable product variant.\n */\n variantId: ID;\n}\n","/**\n * An enum for the types of totals that can appear in a cart.\n */\nexport enum DaffCartTotalTypeEnum {\n grandTotal = 'grand_total',\n subtotalExcludingTax = 'subtotal_excluding_tax',\n subtotalIncludingTax = 'subtotal_including_tax',\n subtotalWithDiscountExcludingTax = 'subtotal_with_discount_excluding_tax',\n subtotalWithDiscountIncludingTax = 'subtotal_with_discount_including_tax',\n discount = 'discount',\n tax = 'tax',\n shipping = 'shipping'\n}\n\n/**\n * Since some cart totals might not have a value defined at all times, like shipping, the values of these totals\n * can be null. Allowing their values to be null differentiates a non-existent value from a zero value. In the case of\n * shipping, this would mean the difference between a cart with no selected shipping method and a cart with a selected shipping\n * method that costs zero.\n */\nexport interface DaffCartTotal {\n /**\n * The amount of the total.\n */\n value: number;\n /**\n * A human-readable label of the total.\n */\n label: string;\n /**\n * The type of the total.\n */\n name: DaffCartTotalTypeEnum;\n\n /**\n * The position in the totals list in which this total should be displayed.\n */\n order: number;\n}\n","import { createSingleInjectionToken } from '@daffodil/core';\n\nexport const {\n /**\n * An injection token for a mapping from the platform-specific cart payment method\n * to a user-defined platform-agnostic payment ID.\n * It should be an object whose keys are the cart payment's method and whose values are strings.\n * Defaults to an empty object.\n */\n // TODO: refactor to upper snake case\n token: DaffCartPaymentMethodIdMap,\n /**\n * Provider function for {@link DaffCartPaymentMethodIdMap}.\n */\n provider: provideDaffCartPaymentMethodIdMap,\n} = createSingleInjectionToken<{[key: string]: string}>(\n 'DaffCartPaymentMethodIdMap',\n { factory: () => ({}) },\n);\n","import { DaffCartItem } from '../models/public_api';\n\n/**\n * Finds the IDs of any affected cart items between two carts.\n */\nexport function daffCartGetAffectedItems<T extends DaffCartItem = DaffCartItem>(oldItems: Array<T>, newItems: Array<T>): Array<T['id']> {\n return newItems.reduce((acc, newItem) => {\n const oldItem = oldItems.find(({ id }) => id === newItem.id);\n if (!oldItem || oldItem.qty !== newItem.qty) {\n acc.push(newItem.id);\n }\n return acc;\n }, <Array<T['id']>>[]);\n}\n","import {\n DaffCartItem,\n DaffCartItemInput,\n} from '../models/public_api';\n\n/**\n * Creates a stub cart item from the cart item input.\n */\nexport const daffCartItemInputToItemTransform = (input: DaffCartItemInput): DaffCartItem => ({\n type: input.type,\n product_id: input.productId,\n qty: input.qty,\n\n id: null,\n parent_item_id: null,\n sku: null,\n name: null,\n price: null,\n row_total: null,\n in_stock: false,\n discounts: [],\n url: null,\n});\n","import { daffAdd } from '@daffodil/core';\n\nimport { DaffCartItem } from '../models/public_api';\n\n/**\n * Sums the discount amounts of the cart item.\n */\nexport function daffCartGetItemTotalDiscount(item: DaffCartItem): number {\n return item?.discounts?.reduce((acc, { amount }) => daffAdd(acc, amount), 0) || 0;\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n Injectable,\n PLATFORM_ID,\n} from '@angular/core';\n\nimport {\n DaffPersistenceService,\n DaffPersistenceServiceToken,\n DaffServerErrorStorageService,\n} from '@daffodil/core';\n\n/**\n * The DaffCartStorageService is responsible for storing the cart id of a customer\n * in storage when necessary. For some ecommerce platforms, where cart information\n * is stored in a cookie instead of storage accessible via javsacript, this service\n * isn't explicitly necessary, so be sure to use this service only in the driver\n * layer for platforms that require it.\n */\n@Injectable({\n providedIn: 'root',\n useFactory: daffCartStorageServiceFactory,\n deps: [\n PLATFORM_ID,\n DaffPersistenceServiceToken,\n DaffServerErrorStorageService,\n ],\n})\nexport class DaffCartStorageService {\n private readonly CART_STORAGE_ID = 'DAFF_CART_ID';\n\n constructor(private storageService: DaffPersistenceService) {}\n\n getCartId(): string {\n return this.storageService.getItem(this.CART_STORAGE_ID);\n }\n\n setCartId(value: string): void {\n this.storageService.setItem(this.CART_STORAGE_ID, value);\n }\n\n removeCartId(): void {\n this.storageService.removeItem(this.CART_STORAGE_ID);\n }\n}\n\n/**\n * The factory that describe construction of a DaffCartStorageService\n */\nexport function daffCartStorageServiceFactory(\n platformId: string,\n persistenceService: DaffPersistenceService,\n serverStorage: DaffServerErrorStorageService) {\n return isPlatformBrowser(platformId)\n ? new DaffCartStorageService(persistenceService)\n : new DaffCartStorageService(serverStorage);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAAA;;;AAGG;IACS;AAAZ,CAAA,UAAY,kBAAkB,EAAA;AAC5B,IAAA,kBAAA,CAAA,iBAAA,CAAA,GAAA,sBAAwC;AACxC,IAAA,kBAAA,CAAA,yBAAA,CAAA,GAAA,8BAAwD;AACxD,IAAA,kBAAA,CAAA,6BAA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AAc,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC;;kIAd3C,sBAAsB,EAAA,IAAA,EAAA,SAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;sIAAtB,sBAAsB,EAAA,UAAA,EARrB,MAAM,EACN,UAAA,EAAA,6BAA6B,kBAEvC,WAAW,EAAA,EAAA,EAAA,KAAA,EACX,2BAA2B,EAAA,EAAA,EAAA,KAAA,EAC3B,6BAA6B,EAAA,CAAA,EAAA,CAAA,CAAA;;4FAGpB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBATlC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AAClB,oBAAA,UAAU,EAAE,6BAA6B;AACzC,oBAAA,IAAI,EAAE;wBACJ,WAAW;wBACX,2BAA2B;wBAC3B,6BAA6B;AAC9B,qBAAA;AACF,iBAAA;;AAmBD;;AAEG;SACa,6BAA6B,CAC3C,UAAkB,EAClB,kBAA0C,EAC1C,aAA4C,EAAA;IAC5C,OAAO,iBAAiB,CAAC,UAAU;AACjC,UAAE,IAAI,sBAAsB,CAAC,kBAAkB;AAC/C,UAAE,IAAI,sBAAsB,CAAC,aAAa,CAAC;AAC/C;;ACxDA;;AAEG;;;;"}
1
+ {"version":3,"file":"daffodil-cart.mjs","sources":["../../../libs/cart/src/errors/codes.enum.ts","../../../libs/cart/src/errors/resolution/cart-resolution.ts","../../../libs/cart/src/errors/resolution/cart-not-found-or-created-resolution.ts","../../../libs/cart/src/errors/resolution/cart-server-side-resolution.ts","../../../libs/cart/src/errors/resolution/cart-storage-resolution.ts","../../../libs/cart/src/errors/map.ts","../../../libs/cart/src/models/cart-item-input.ts","../../../libs/cart/src/models/cart-total.ts","../../../libs/cart/src/injection-tokens/payment-method-map.ts","../../../libs/cart/src/helpers/get-affected-item.ts","../../../libs/cart/src/helpers/input-to-item-transform.ts","../../../libs/cart/src/helpers/get-item-total-discount.ts","../../../libs/cart/src/storage/cart-storage.service.ts","../../../libs/cart/src/daffodil-cart.ts"],"sourcesContent":["/**\n * An enum for the cart error codes.\n * Each error code is unique to an error class.\n */\nexport enum DaffCartErrorCodes {\n CART_RESOLUTION = 'DAFF_CART_RESOLUTION',\n CART_STORAGE_RESOLUTION = 'DAFF_CART_STORAGE_RESOLUTION',\n CART_SERVER_SIDE_RESOLUTION = 'DAFF_CART_SERVER_SIDE_RESOLUTION',\n CART_NOT_FOUND_OR_CREATED_RESOLUTION = 'DAFF_CART_NOT_FOUND_OR_CREATED_RESOLUTION',\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n *\n * @inheritdoc\n */\nexport class DaffCartResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n * This happens when the cart cannot be found and a new cart cannot be created.\n *\n * @inheritdoc\n */\nexport class DaffCartNotFoundOrCreatedResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_NOT_FOUND_OR_CREATED_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n * This happens when the app is running in a server environment.\n * This is normal and expected in SSR.\n *\n * @inheritdoc\n */\nexport class DaffCartServerSideResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_SERVER_SIDE_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import {\n DaffError,\n DaffInheritableError,\n} from '@daffodil/core';\n\nimport { DaffCartErrorCodes } from '../codes.enum';\n\n/**\n * An error thrown when the cart fails to resolve.\n * This happens when loading the cart ID from storage throws an exception.\n *\n * @inheritdoc\n */\nexport class DaffCartStorageResolutionError extends DaffInheritableError implements DaffError {\n public readonly code: string = DaffCartErrorCodes.CART_STORAGE_RESOLUTION;\n\n constructor(message?: string) {\n super(message);\n }\n}\n","import { DaffCartErrorCodes } from './codes.enum';\nimport {\n DaffCartResolutionError,\n DaffCartStorageResolutionError,\n DaffCartServerSideResolutionError,\n DaffCartNotFoundOrCreatedResolutionError,\n} from './resolution/public_api';\n\n/**\n * A mapping from error codes to error class constructors.\n */\nexport const DaffCartErrorMap = {\n [DaffCartErrorCodes.CART_RESOLUTION]: DaffCartResolutionError,\n [DaffCartErrorCodes.CART_STORAGE_RESOLUTION]: DaffCartStorageResolutionError,\n [DaffCartErrorCodes.CART_SERVER_SIDE_RESOLUTION]: DaffCartServerSideResolutionError,\n [DaffCartErrorCodes.CART_NOT_FOUND_OR_CREATED_RESOLUTION]: DaffCartNotFoundOrCreatedResolutionError,\n};\n","import { ID } from '@daffodil/core';\nimport { DaffProduct } from '@daffodil/product';\n\n/**\n * An enum for the type of the cart item.\n */\n// TODO: remove \"input\" designation\nexport enum DaffCartItemInputType {\n Simple = 'simple',\n Composite = 'composite',\n Configurable = 'configurable'\n}\n\n/**\n * A set of fields specifying how to add a product to the cart.\n */\nexport interface DaffCartItemInput {\n /**\n * The type of cart item that corresponds to the product being added to the cart.\n */\n type: DaffCartItemInputType;\n /**\n * The ID of the product to add to the cart.\n */\n productId: DaffProduct['id'];\n /**\n * How many of the product should be added to the cart.\n */\n qty: number;\n}\n\n/**\n * A more constrained cart item input for simple products.\n */\nexport interface DaffSimpleCartItemInput extends DaffCartItemInput {\n type: DaffCartItemInputType.Simple;\n}\n\n/**\n * A cart item input for composite products.\n */\nexport interface DaffCompositeCartItemInput extends DaffCartItemInput {\n type: DaffCartItemInputType.Composite;\n /**\n * The selected options for the composite product to be added to the cart.\n */\n options: DaffCompositeCartItemInputOption[];\n}\n\n/**\n * Designates a particular option for the composite product to add to the cart.\n */\nexport interface DaffCompositeCartItemInputOption {\n /**\n * An identifier of the option for which a value has been chosen.\n */\n // TODO: change to ID type?\n code: string | number;\n /**\n * How many of the specified option should be added to the cart.\n */\n quantity: number;\n /**\n * The value identifying the chosen composite product option.\n */\n value: string;\n}\n\n/**\n * Designates a particular configurable product variant to add to the cart.\n */\nexport interface DaffConfigurableCartItemInput extends DaffCartItemInput {\n type: DaffCartItemInputType.Configurable;\n /**\n * The value identifying the particular configurable product variant.\n */\n variantId: ID;\n}\n","/**\n * An enum for the types of totals that can appear in a cart.\n */\nexport enum DaffCartTotalTypeEnum {\n grandTotal = 'grand_total',\n subtotalExcludingTax = 'subtotal_excluding_tax',\n subtotalIncludingTax = 'subtotal_including_tax',\n subtotalWithDiscountExcludingTax = 'subtotal_with_discount_excluding_tax',\n subtotalWithDiscountIncludingTax = 'subtotal_with_discount_including_tax',\n discount = 'discount',\n tax = 'tax',\n shipping = 'shipping'\n}\n\n/**\n * Since some cart totals might not have a value defined at all times, like shipping, the values of these totals\n * can be null. Allowing their values to be null differentiates a non-existent value from a zero value. In the case of\n * shipping, this would mean the difference between a cart with no selected shipping method and a cart with a selected shipping\n * method that costs zero.\n */\nexport interface DaffCartTotal {\n /**\n * The amount of the total.\n */\n value: number;\n /**\n * A human-readable label of the total.\n */\n label: string;\n /**\n * The type of the total.\n */\n name: DaffCartTotalTypeEnum | string;\n\n /**\n * The position in the totals list in which this total should be displayed.\n */\n order: number;\n}\n","import { createSingleInjectionToken } from '@daffodil/core';\n\nexport const {\n /**\n * An injection token for a mapping from the platform-specific cart payment method\n * to a user-defined platform-agnostic payment ID.\n * It should be an object whose keys are the cart payment's method and whose values are strings.\n * Defaults to an empty object.\n */\n // TODO: refactor to upper snake case\n token: DaffCartPaymentMethodIdMap,\n /**\n * Provider function for {@link DaffCartPaymentMethodIdMap}.\n */\n provider: provideDaffCartPaymentMethodIdMap,\n} = createSingleInjectionToken<{[key: string]: string}>(\n 'DaffCartPaymentMethodIdMap',\n { factory: () => ({}) },\n);\n","import { DaffCartItem } from '../models/public_api';\n\n/**\n * Finds the IDs of any affected cart items between two carts.\n */\nexport function daffCartGetAffectedItems<T extends DaffCartItem = DaffCartItem>(oldItems: Array<T>, newItems: Array<T>): Array<T['id']> {\n return newItems.reduce((acc, newItem) => {\n const oldItem = oldItems.find(({ id }) => id === newItem.id);\n if (!oldItem || oldItem.qty !== newItem.qty) {\n acc.push(newItem.id);\n }\n return acc;\n }, <Array<T['id']>>[]);\n}\n","import {\n DaffCartItem,\n DaffCartItemInput,\n} from '../models/public_api';\n\n/**\n * Creates a stub cart item from the cart item input.\n */\nexport const daffCartItemInputToItemTransform = (input: DaffCartItemInput): DaffCartItem => ({\n type: input.type,\n product_id: input.productId,\n qty: input.qty,\n\n id: null,\n parent_item_id: null,\n sku: null,\n name: null,\n price: null,\n row_total: null,\n in_stock: false,\n discounts: [],\n url: null,\n});\n","import { daffAdd } from '@daffodil/core';\n\nimport { DaffCartItem } from '../models/public_api';\n\n/**\n * Sums the discount amounts of the cart item.\n */\nexport function daffCartGetItemTotalDiscount(item: DaffCartItem): number {\n return item?.discounts?.reduce((acc, { amount }) => daffAdd(acc, amount), 0) || 0;\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n Injectable,\n PLATFORM_ID,\n} from '@angular/core';\n\nimport {\n DaffPersistenceService,\n DaffPersistenceServiceToken,\n DaffServerErrorStorageService,\n} from '@daffodil/core';\n\n/**\n * The DaffCartStorageService is responsible for storing the cart id of a customer\n * in storage when necessary. For some ecommerce platforms, where cart information\n * is stored in a cookie instead of storage accessible via javsacript, this service\n * isn't explicitly necessary, so be sure to use this service only in the driver\n * layer for platforms that require it.\n */\n@Injectable({\n providedIn: 'root',\n useFactory: daffCartStorageServiceFactory,\n deps: [\n PLATFORM_ID,\n DaffPersistenceServiceToken,\n DaffServerErrorStorageService,\n ],\n})\nexport class DaffCartStorageService {\n private readonly CART_STORAGE_ID = 'DAFF_CART_ID';\n\n constructor(private storageService: DaffPersistenceService) {}\n\n getCartId(): string {\n return this.storageService.getItem(this.CART_STORAGE_ID);\n }\n\n setCartId(value: string): void {\n this.storageService.setItem(this.CART_STORAGE_ID, value);\n }\n\n removeCartId(): void {\n this.storageService.removeItem(this.CART_STORAGE_ID);\n }\n}\n\n/**\n * The factory that describe construction of a DaffCartStorageService\n */\nexport function daffCartStorageServiceFactory(\n platformId: string,\n persistenceService: DaffPersistenceService,\n serverStorage: DaffServerErrorStorageService) {\n return isPlatformBrowser(platformId)\n ? new DaffCartStorageService(persistenceService)\n : new DaffCartStorageService(serverStorage);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAAA;;;AAGG;IACS;AAAZ,CAAA,UAAY,kBAAkB,EAAA;AAC5B,IAAA,kBAAA,CAAA,iBAAA,CAAA,GAAA,sBAAwC;AACxC,IAAA,kBAAA,CAAA,yBAAA,CAAA,GAAA,8BAAwD;AACxD,IAAA,kBAAA,CAAA,6BAAA,CAAA,GAAA,kCAAgE;AAChE,IAAA,kBAAA,CAAA,sCAAA,CAAA,GAAA,2CAAkF;AACpF,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,GAK7B,EAAA,CAAA,CAAA;;ACFD;;;;AAIG;AACG,MAAO,uBAAwB,SAAQ,oBAAoB,CAAA;AAG/D,IAAA,WAAA,CAAY,OAAgB,EAAA;QAC1B,KAAK,CAAC,OAAO,CAAC;AAHA,QAAA,IAAA,CAAA,IAAI,GAAW,kBAAkB,CAAC,eAAe;;AAKlE;;ACXD;;;;;AAKG;AACG,MAAO,wCAAyC,SAAQ,oBAAoB,CAAA;AAGhF,IAAA,WAAA,CAAY,OAAgB,EAAA;QAC1B,KAAK,CAAC,OAAO,CAAC;AAHA,QAAA,IAAA,CAAA,IAAI,GAAW,kBAAkB,CAAC,oCAAoC;;AAKvF;;ACZD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2BAA2B;wBAC3B,6BAA6B;AAC9B,qBAAA;AACF,iBAAA;;AAmBD;;AAEG;SACa,6BAA6B,CAC3C,UAAkB,EAClB,kBAA0C,EAC1C,aAA4C,EAAA;IAC5C,OAAO,iBAAiB,CAAC,UAAU;AACjC,UAAE,IAAI,sBAAsB,CAAC,kBAAkB;AAC/C,UAAE,IAAI,sBAAsB,CAAC,aAAa,CAAC;AAC/C;;ACxDA;;AAEG;;;;"}
@@ -29,7 +29,7 @@ export interface DaffCartTotal {
29
29
  /**
30
30
  * The type of the total.
31
31
  */
32
- name: DaffCartTotalTypeEnum;
32
+ name: DaffCartTotalTypeEnum | string;
33
33
  /**
34
34
  * The position in the totals list in which this total should be displayed.
35
35
  */
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@daffodil/cart","nx":{"targets":{"build":{"outputs":["{workspaceRoot}/dist/cart"]}}},"version":"0.86.0","description":"Interfaces built for daffodil/state","repository":{"type":"git","url":"https://github.com/graycoreio/daffodil"},"author":"Graycore LLC","license":"MIT","bugs":{"url":"https://github.com/graycoreio/daffodil/issues"},"homepage":"https://github.com/graycoreio/daffodil","peerDependencies":{"@angular/common":"^19.0.0","@angular/core":"^19.0.0","@daffodil/core":"0.86.0","@daffodil/product":"0.86.0","@daffodil/geography":"0.86.0","@daffodil/payment":"0.86.0","@ngrx/effects":"^19.0.0","@ngrx/entity":"^19.0.0","@ngrx/store":"^19.0.0","rxjs":"7.8.1"},"optionalDependencies":{"@faker-js/faker":"^9.8.0","angular-in-memory-web-api":"^0.19.0","apollo-angular":"^10.0.3","@apollo/client":"^3.12.6","@daffodil/driver":"0.86.0"},"module":"fesm2022/daffodil-cart.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","default":"./fesm2022/daffodil-cart.mjs"},"./driver":{"types":"./driver/index.d.ts","default":"./fesm2022/daffodil-cart-driver.mjs"},"./routing":{"types":"./routing/index.d.ts","default":"./fesm2022/daffodil-cart-routing.mjs"},"./state":{"types":"./state/index.d.ts","default":"./fesm2022/daffodil-cart-state.mjs"},"./testing":{"types":"./testing/index.d.ts","default":"./fesm2022/daffodil-cart-testing.mjs"},"./driver/in-memory":{"types":"./driver/in-memory/index.d.ts","default":"./fesm2022/daffodil-cart-driver-in-memory.mjs"},"./driver/magento":{"types":"./driver/magento/index.d.ts","default":"./fesm2022/daffodil-cart-driver-magento.mjs"},"./driver/testing":{"types":"./driver/testing/index.d.ts","default":"./fesm2022/daffodil-cart-driver-testing.mjs"},"./state/testing":{"types":"./state/testing/index.d.ts","default":"./fesm2022/daffodil-cart-state-testing.mjs"},"./driver/magento/testing":{"types":"./driver/magento/testing/index.d.ts","default":"./fesm2022/daffodil-cart-driver-magento-testing.mjs"}},"sideEffects":false,"dependencies":{"tslib":"^2.3.0"}}
1
+ {"name":"@daffodil/cart","nx":{"targets":{"build":{"outputs":["{workspaceRoot}/dist/cart"]}}},"version":"0.87.0","description":"Interfaces built for daffodil/state","repository":{"type":"git","url":"https://github.com/graycoreio/daffodil"},"author":"Graycore LLC","license":"MIT","bugs":{"url":"https://github.com/graycoreio/daffodil/issues"},"homepage":"https://github.com/graycoreio/daffodil","peerDependencies":{"@angular/common":"^19.0.0","@angular/core":"^19.0.0","@daffodil/core":"0.87.0","@daffodil/product":"0.87.0","@daffodil/geography":"0.87.0","@daffodil/payment":"0.87.0","@ngrx/effects":"^19.0.0","@ngrx/entity":"^19.0.0","@ngrx/store":"^19.0.0","rxjs":"7.8.1"},"optionalDependencies":{"@faker-js/faker":"^9.8.0","angular-in-memory-web-api":"^0.19.0","apollo-angular":"^10.0.3","@apollo/client":"^3.12.6","@daffodil/driver":"0.87.0"},"module":"fesm2022/daffodil-cart.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","default":"./fesm2022/daffodil-cart.mjs"},"./driver":{"types":"./driver/index.d.ts","default":"./fesm2022/daffodil-cart-driver.mjs"},"./routing":{"types":"./routing/index.d.ts","default":"./fesm2022/daffodil-cart-routing.mjs"},"./state":{"types":"./state/index.d.ts","default":"./fesm2022/daffodil-cart-state.mjs"},"./testing":{"types":"./testing/index.d.ts","default":"./fesm2022/daffodil-cart-testing.mjs"},"./driver/in-memory":{"types":"./driver/in-memory/index.d.ts","default":"./fesm2022/daffodil-cart-driver-in-memory.mjs"},"./driver/magento":{"types":"./driver/magento/index.d.ts","default":"./fesm2022/daffodil-cart-driver-magento.mjs"},"./driver/testing":{"types":"./driver/testing/index.d.ts","default":"./fesm2022/daffodil-cart-driver-testing.mjs"},"./state/testing":{"types":"./state/testing/index.d.ts","default":"./fesm2022/daffodil-cart-state-testing.mjs"},"./driver/magento/testing":{"types":"./driver/magento/testing/index.d.ts","default":"./fesm2022/daffodil-cart-driver-magento-testing.mjs"}},"sideEffects":false,"dependencies":{"tslib":"^2.3.0"}}
@@ -12,7 +12,7 @@ export declare class MockCart implements DaffCart {
12
12
  billing_address: any;
13
13
  shipping_address: any;
14
14
  shipping_information: import("@daffodil/cart").DaffCartShippingRate;
15
- totals: Record<import("@daffodil/cart").DaffCartTotalTypeEnum, import("@daffodil/cart").DaffCartTotal>;
15
+ totals: Record<string, import("@daffodil/cart").DaffCartTotal>;
16
16
  payment: any;
17
17
  available_shipping_methods: any[];
18
18
  available_payment_methods: any[];