diff --git a/.changeset/grumpy-bees-yell.md b/.changeset/grumpy-bees-yell.md new file mode 100644 index 0000000..9217b35 --- /dev/null +++ b/.changeset/grumpy-bees-yell.md @@ -0,0 +1,5 @@ +--- +'@crystallize/import-utilities': minor +--- + +Add the JSONItem document as from in the CREATED and UPDATED event diff --git a/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts b/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts index f11bc7e..f4290c0 100644 --- a/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts +++ b/src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts @@ -290,6 +290,7 @@ export async function createOrUpdateItem( type: shape.type, identifier: shape.identifier, }, + from: item, } as ItemEventPayloadCreatedOrUpdated) return responses @@ -427,13 +428,13 @@ export async function createOrUpdateItem( id, ...(p.initial && { initial: subscriptionPlanPrincingJsonToInput( - p.initial, - meteredVariables + p.initial, + meteredVariables ), }), recurring: subscriptionPlanPrincingJsonToInput( - p.recurring, - meteredVariables + p.recurring, + meteredVariables ), } }), @@ -461,18 +462,18 @@ export async function createOrUpdateItem( inp.variants.push( ...existingProductVariants.map( ({ priceVariants, stockLocations, components, ...rest }) => - ({ - ...rest, - priceVariants: priceVariants?.map((p) => ({ - identifier: p.identifier, - price: p.price, - })), - stockLocations: stockLocations?.map((p) => ({ - identifier: p.identifier, - stock: p.stock, - meta: p.meta, - })), - } as CreateProductVariantInput) + ({ + ...rest, + priceVariants: priceVariants?.map((p) => ({ + identifier: p.identifier, + price: p.price, + })), + stockLocations: stockLocations?.map((p) => ({ + identifier: p.identifier, + stock: p.stock, + meta: p.meta, + })), + } as CreateProductVariantInput) ) ) } @@ -679,6 +680,7 @@ export async function createOrUpdateItem( type: shape.type, identifier: shape.identifier, }, + from: item, } as ItemEventPayloadCreatedOrUpdated) // Set the component data for the item diff --git a/src/bootstrap-tenant/bootstrapper/utils/index.ts b/src/bootstrap-tenant/bootstrapper/utils/index.ts index 54f4ccb..874b196 100644 --- a/src/bootstrap-tenant/bootstrapper/utils/index.ts +++ b/src/bootstrap-tenant/bootstrapper/utils/index.ts @@ -142,6 +142,7 @@ export type ItemEventPayloadCreatedOrUpdated = ItemEventPayload & { type: 'product' | 'document' | 'folder' identifier: string } + from: JSONItem } // Lets keep this old type in order to not break things. export type ItemCreatedOrUpdated = ItemEventPayloadCreatedOrUpdated