@spiffcommerce/core 30.0.1-beta.d8ca7f5f-c09f-5948-929d-d01551394c73 → 30.0.1
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.ts +1 -4
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +197 -203
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1640,12 +1640,9 @@ declare class ProductCollection {
|
|
1640
1640
|
* @param limit The maximum number of products to return.
|
1641
1641
|
* @param filters Optional metafield filters to apply to the query.
|
1642
1642
|
* @param tags Optional object of tag filters to apply.
|
1643
|
-
* @param sortKey Optional field of the products to sort by.
|
1644
|
-
* @param sortDescending Optional boolean to indicate if the sort should be in descending order.
|
1645
|
-
* @param quickSearch Optional string to filter products by name.
|
1646
1643
|
* @returns
|
1647
1644
|
*/
|
1648
|
-
fetchProductsFeed(offset: number, limit: number, filters?: ProductMetafieldFilter[], tags?: ProductTagFilter, sortKey?: ProductCollectionProductSortKey, sortDescending?: boolean
|
1645
|
+
fetchProductsFeed(offset: number, limit: number, filters?: ProductMetafieldFilter[], tags?: ProductTagFilter, sortKey?: ProductCollectionProductSortKey, sortDescending?: boolean): Promise<{
|
1649
1646
|
items: CollectionProduct[];
|
1650
1647
|
total: number;
|
1651
1648
|
}>;
|
package/dist/index.js
CHANGED
@@ -1835,7 +1835,6 @@
|
|
1835
1835
|
$tags: ProductCollectionProductTagFilterInput
|
1836
1836
|
$sortKey: ProductCollectionProductSortKey
|
1837
1837
|
$sortDescending: Boolean
|
1838
|
-
$quickSearch: String
|
1839
1838
|
) {
|
1840
1839
|
productCollections(ids: [$id]) {
|
1841
1840
|
id
|
@@ -1846,7 +1845,6 @@
|
|
1846
1845
|
offset: $offset
|
1847
1846
|
sortKey: $sortKey
|
1848
1847
|
sortDescending: $sortDescending
|
1849
|
-
quickSearch: $quickSearch
|
1850
1848
|
) {
|
1851
1849
|
items {
|
1852
1850
|
...ProductCollectionProductFields
|
@@ -2349,7 +2347,7 @@
|
|
2349
2347
|
}
|
2350
2348
|
}
|
2351
2349
|
}
|
2352
|
-
`;class oc{constructor(){this.internalMap=new Map}async requestKeysForEntity(t,e){const a=new Map;return await this.ensureIdsArePresent([t]),e.forEach(n=>{const i=this.requestKeyForEntityIfAvailable(t,n);i&&a.set(n,i)}),a}async ensureIdsArePresent(t){if(t.every(a=>this.internalMap.has(a)))return;const e=await B.getShadowGraphqlClient().query({query:sc,errorPolicy:"all",variables:{entityIds:t.filter(a=>!this.internalMap.has(a))}});t.forEach((a,n)=>{const i=e.data.metafieldsMany[n];this.internalMap.set(a,i.map(s=>({key:s.metafieldConfiguration.name,value:s.value})))})}async requestKeyForEntity(t,e){if(!this.internalMap.has(t))return;let a=this.internalMap.get(t);const n=a.find(i=>i.key===e);return n||(await this.ensureIdsArePresent([t]),a=this.internalMap.get(t)),n?JSON.parse(n.value):void 0}requestKeyForEntityIfAvailable(t,e){if(!this.internalMap.has(t))return;const n=this.internalMap.get(t).find(i=>i.key===e);if(n)return JSON.parse(n.value)}}const $r=new oc;var Ur=(r=>(r.Default="Default",r.Name="Name",r.Price="Price",r))(Ur||{});class Ga{constructor(t){this.fullFetched=!1,this.collection=t;const e=this.collection.productCollectionProducts;e&&e.length>0&&(this.fullFetched=!0)}getId(){return this.collection.id}getName(){return this.collection.name}getDescription(){return this.collection.description||""}getDispatchStartDate(){if(this.collection.dispatchStartDate)return new Date(this.collection.dispatchStartDate)}getDispatchEndDate(){if(this.collection.dispatchEndDate)return new Date(this.collection.dispatchEndDate)}getImage(){return this.collection.image}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.filter(t=>!!t.product).map(t=>new Ht(t))}async fetchProducts(t){if(this.fullFetched)return this.collection.productCollectionProducts.filter(a=>!!a.product).map(a=>new Ht(a));const e=await B.getShadowGraphqlClient().query({query:Zo,variables:{id:this.getId(),productIds:t},errorPolicy:"all"});return t||(this.fullFetched=!0),this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.filter(a=>!!a.product).map(a=>new Ht(a))}async filterProducts(t,e,a,n){var l,c;const i=await B.getShadowGraphqlClient().query({query:tl,errorPolicy:"all",variables:{id:this.getId(),filters:t?{link:"And",metafields:t}:void 0,tags:e?{include:e.include??[],exclude:e.exclude??[]}:void 0,sortKey:a,sortDescending:n}});if(!((l=i.data)!=null&&l.productCollections)||((c=i.data)==null?void 0:c.productCollections.length)===0)throw new Error("Failed to filter product collection products.");const s=this.getProducts(),o=i.data.productCollections[0].productCollectionProducts.map(d=>d.product.id);return s.filter(d=>o.includes(d.getId()))}async fetchProductsFeed(t,e,a,n,i,s
|
2350
|
+
`;class oc{constructor(){this.internalMap=new Map}async requestKeysForEntity(t,e){const a=new Map;return await this.ensureIdsArePresent([t]),e.forEach(n=>{const i=this.requestKeyForEntityIfAvailable(t,n);i&&a.set(n,i)}),a}async ensureIdsArePresent(t){if(t.every(a=>this.internalMap.has(a)))return;const e=await B.getShadowGraphqlClient().query({query:sc,errorPolicy:"all",variables:{entityIds:t.filter(a=>!this.internalMap.has(a))}});t.forEach((a,n)=>{const i=e.data.metafieldsMany[n];this.internalMap.set(a,i.map(s=>({key:s.metafieldConfiguration.name,value:s.value})))})}async requestKeyForEntity(t,e){if(!this.internalMap.has(t))return;let a=this.internalMap.get(t);const n=a.find(i=>i.key===e);return n||(await this.ensureIdsArePresent([t]),a=this.internalMap.get(t)),n?JSON.parse(n.value):void 0}requestKeyForEntityIfAvailable(t,e){if(!this.internalMap.has(t))return;const n=this.internalMap.get(t).find(i=>i.key===e);if(n)return JSON.parse(n.value)}}const $r=new oc;var Ur=(r=>(r.Default="Default",r.Name="Name",r.Price="Price",r))(Ur||{});class Ga{constructor(t){this.fullFetched=!1,this.collection=t;const e=this.collection.productCollectionProducts;e&&e.length>0&&(this.fullFetched=!0)}getId(){return this.collection.id}getName(){return this.collection.name}getDescription(){return this.collection.description||""}getDispatchStartDate(){if(this.collection.dispatchStartDate)return new Date(this.collection.dispatchStartDate)}getDispatchEndDate(){if(this.collection.dispatchEndDate)return new Date(this.collection.dispatchEndDate)}getImage(){return this.collection.image}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.filter(t=>!!t.product).map(t=>new Ht(t))}async fetchProducts(t){if(this.fullFetched)return this.collection.productCollectionProducts.filter(a=>!!a.product).map(a=>new Ht(a));const e=await B.getShadowGraphqlClient().query({query:Zo,variables:{id:this.getId(),productIds:t},errorPolicy:"all"});return t||(this.fullFetched=!0),this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.filter(a=>!!a.product).map(a=>new Ht(a))}async filterProducts(t,e,a,n){var l,c;const i=await B.getShadowGraphqlClient().query({query:tl,errorPolicy:"all",variables:{id:this.getId(),filters:t?{link:"And",metafields:t}:void 0,tags:e?{include:e.include??[],exclude:e.exclude??[]}:void 0,sortKey:a,sortDescending:n}});if(!((l=i.data)!=null&&l.productCollections)||((c=i.data)==null?void 0:c.productCollections.length)===0)throw new Error("Failed to filter product collection products.");const s=this.getProducts(),o=i.data.productCollections[0].productCollectionProducts.map(d=>d.product.id);return s.filter(d=>o.includes(d.getId()))}async fetchProductsFeed(t,e,a,n,i,s){if(this.fullFetched){const d=await(a?this.filterProducts(a):this.fetchProducts());return{total:d.length,items:d.slice(t,t+e)}}const o=new AbortController,{signal:l}=o,c=B.getShadowGraphqlClient().watchQuery({query:el,variables:{id:this.getId(),limit:e,offset:t,filters:a?{link:"And",metafields:a}:void 0,tags:n?{include:n.include??[],exclude:n.exclude??[]}:void 0,sortKey:i,sortDescending:s},errorPolicy:"all",fetchPolicy:"cache-first",returnPartialData:!0,context:{fetchOptions:{signal:l}}});return new Promise(d=>{let A=!1;const u=c.subscribe({next(h){var m,p,f,C,w,S;if(A||h.partial&&(!h.data.productCollections||h.data.productCollections.length===0||!((m=h.data.productCollections[0].productCollectionProductsFeed)!=null&&m.items)||((p=h.data.productCollections[0].productCollectionProductsFeed)==null?void 0:p.items.length)===0))return;o.abort(),A=!0,u.unsubscribe();const g=((C=(f=h.data.productCollections)==null?void 0:f[0].productCollectionProductsFeed)==null?void 0:C.items.filter(y=>!!y.product).map(y=>new Ht(bt(y))))||[];d({items:g,total:((S=(w=h.data.productCollections)==null?void 0:w[0].productCollectionProductsFeed)==null?void 0:S.total)??0})},error(){A||(A=!0,u.unsubscribe(),d({items:[],total:0}))}})})}getTransformCollection(){if(this.collection.transformCollection)return new Lr(this.collection.transformCollection)}getResource(){return this.collection}}class Ht{constructor(t){this.product=t.product,this.productResource=t}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(t,e){const n=(this.product.integrationProducts||[]).find(i=>{var c,d,A;const s=(c=i.integration)==null?void 0:c.type,o=((d=i.integration)==null?void 0:d.type)===t,l=e?((A=i.integration)==null?void 0:A.externalIntegrationId)===e:!0;return s&&o&&l});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const e=(this.product.integrationProducts||[]).find(a=>{var n;return(n=a.integration)==null?void 0:n.isCurrent});if(!e)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return e}getDefaultWorkflow(){const t=this.product.workflows;if(t===void 0)throw new ht("Called getDefaultWorkflow() before fetching collection products. Use collection.fetchProducts() first to ensure the data is available.");if(t.length===0)throw new ht("Called getDefaultWorkflow() but no workflows on requested product. Ensure at least 1 workflow is assigned to this product.");const e=this.productResource.workflowId;if(e){const a=t.find(n=>n.workflowName===e);if(a)return new Tt(a)}if(t.length===1)return console.warn("Called getDefaultWorkflow() but no default was configured. There is only one workflow available so we will fall back to using this!"),new Tt(t[0]);throw new ht("Called getDefaultWorkflow() but no default workflow is configured for the requested product. Multiple workflows exist so we can't assume!")}getAllWorkflows(){if((this.product.workflows||[]).length===0)throw new ht("No workflows on configured product. Ensure at least 1 workflow is assigned to this product.");return this.product.workflows.sort((e,a)=>(e.index??0)-(a.index??0)).map(e=>new Tt(e))}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}getBasePrice(t){var n,i,s,o;const e=this.product.basePrice||0;if(!t)return e;if(!t.integrationType&&!t.externalId&&!t.integrationId)throw new Error("You must provide at least one of the following fields on the includeAdditionalProduct object: integrationType, externalId, integrationId");let a;return t.integrationId?a=(n=this.product.integrationProducts)==null?void 0:n.find(l=>{var c;return((c=l.integration)==null?void 0:c.id)===t.integrationId}):t.externalId?a=(i=this.product.integrationProducts)==null?void 0:i.find(l=>{var c;return((c=l.integration)==null?void 0:c.externalIntegrationId)===t.externalId}):a=(s=this.product.integrationProducts)==null?void 0:s.find(l=>{var c;return((c=l.integration)==null?void 0:c.type)===t.integrationType}),(o=a==null?void 0:a.additionalIntegrationProduct)!=null&&o.product?e+(a.additionalIntegrationProduct.product.basePrice||0):e}async requestMetafields(t){return $r.requestKeysForEntity(this.product.id,t)}}class Tt{constructor(t){this.workflow=t}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class Lr{constructor(t){this.collection=t}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(t=>new Vr(t))}}class Vr{constructor(t){this.transform=t}getId(){return this.transform.id}getName(){return this.transform.name}get(){return{position:this.transform.position,rotation:this.transform.rotation,scale:this.transform.scale}}}const lc=v.gql`
|
2353
2351
|
${ge(!1)}
|
2354
2352
|
query GetProductCollections($ids: [String!]!) {
|
2355
2353
|
productCollections(ids: $ids) {
|