Skip to main content

IAttributeModuleService Reference

This section of the documentation provides a reference to the IAttributeModuleService interface’s methods. This is the interface developers use to use the functionalities provided by the Attribute Module.
You should only use the methods in this reference when implementing complex customizations. For common cases, check out available workflows instead.
The main service interface for the Attribute Module.

Methods


createAttributes

This section provides a reference to the createAttributes method. This belongs to the Attribute Module.

createAttributes(data, sharedContext?): Promise<AttributeDTO[]>

This method creates attributes.

Example

const attributes = await attributeModuleService.createAttributes([
  {
    name: "Material",
    handle: "material",
    ui_component: "select",
    is_filterable: true,
    is_required: false,
    possible_values: [
      { value: "Cotton", rank: 1 },
      { value: "Polyester", rank: 2 },
    ],
  },
])

Parameters

data
CreateAttributeDTO[]
required
The attributes to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeDTO[]>
The created attributes.

createAttributes(data, sharedContext?): Promise<AttributeDTO>

This method creates an attribute.

Example

const attribute = await attributeModuleService.createAttributes({
  name: "Size",
  handle: "size",
  ui_component: "select",
  is_filterable: true,
})

Parameters

data
CreateAttributeDTO
required
The attribute to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeDTO>
The created attribute.

updateAttributeWithUpsertOrReplacePossibleValues

This section provides a reference to the updateAttributeWithUpsertOrReplacePossibleValues method. This belongs to the Attribute Module.

updateAttributeWithUpsertOrReplacePossibleValues(input, sharedContext?): Promise<void>

This method updates an attribute and upserts or replaces its possible values in a single operation. If id is not provided for possible_values entries, it will lookup the database by attributePossibleValue.value to update or create accordingly.

Example

await attributeModuleService.updateAttributeWithUpsertOrReplacePossibleValues({
  id: "attr_123",
  name: "Updated Material",
  possible_values: [
    { id: "attr_pos_val_1", value: "Cotton", rank: 1 },
    { value: "Silk", rank: 3 }, // Will be created
  ],
})

Parameters

input
UpdateAttributeDTO | UpdateAttributeDTO[]
required
The attribute(s) to update with possible values to upsert.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the attribute and its possible values are updated successfully.

listAttributes

This section provides a reference to the listAttributes method. This belongs to the Attribute Module. This method retrieves a paginated list of attributes based on optional filters and configuration.

Example

To retrieve a list of attributes using their IDs:
const attributes = await attributeModuleService.listAttributes({
  id: ["attr_123", "attr_321"],
})
To retrieve filterable attributes:
const attributes = await attributeModuleService.listAttributes({
  is_filterable: true,
})
By default, only the first 15 records are retrieved. You can control pagination by specifying the skip and take properties of the config parameter:
const attributes = await attributeModuleService.listAttributes(
  {
    id: ["attr_123", "attr_321"],
  },
  {
    take: 20,
    skip: 2,
  }
)

Parameters

filters
FilterableAttributeProps
The filters to apply on the retrieved attributes.
config
FindConfig<AttributeDTO>
The configurations determining how the attribute is retrieved. Its properties, such as select or relations, accept the attributes or relations associated with an attribute.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeDTO[]>
The list of attributes.

retrieveAttribute

This section provides a reference to the retrieveAttribute method. This belongs to the Attribute Module. This method retrieves an attribute by its ID.

Example

const attribute = await attributeModuleService.retrieveAttribute("attr_123")
To retrieve relationships:
const attribute = await attributeModuleService.retrieveAttribute(
  "attr_123",
  {
    relations: ["possible_values", "values"],
  }
)

Parameters

id
string
required
The ID of the attribute.
config
FindConfig<AttributeDTO>
The configurations determining how the attribute is retrieved. Its properties, such as select or relations, accept the attributes or relations associated with an attribute.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeDTO>
The retrieved attribute.

updateAttributes

This section provides a reference to the updateAttributes method. This belongs to the Attribute Module.

updateAttributes(id, data, sharedContext?): Promise<AttributeDTO>

This method updates an existing attribute.

Example

const attribute = await attributeModuleService.updateAttributes("attr_123", {
  name: "Updated Material",
  is_filterable: false,
})

Parameters

id
string
required
The ID of the attribute.
data
UpdateAttributeDTO
required
The attributes to update in the attribute.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeDTO>
The updated attribute.

deleteAttributes

This section provides a reference to the deleteAttributes method. This belongs to the Attribute Module.

deleteAttributes(ids, sharedContext?): Promise<void>

This method deletes attributes by their IDs.

Example

await attributeModuleService.deleteAttributes(["attr_123", "attr_321"])

Parameters

ids
string[]
required
The IDs of the attributes.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the attributes are deleted successfully.

deleteAttributes(id, sharedContext?): Promise<void>

This method deletes an attribute by its ID.

Example

await attributeModuleService.deleteAttributes("attr_123")

Parameters

id
string
required
The ID of the attribute.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the attribute is deleted successfully.

listAndCountAttributes

This section provides a reference to the listAndCountAttributes method. This belongs to the Attribute Module. This method retrieves a paginated list of attributes along with the total count of available attributes satisfying the provided filters.

Example

To retrieve a list of attributes using their IDs:
const [attributes, count] = await attributeModuleService.listAndCountAttributes({
  id: ["attr_123", "attr_321"],
})
By default, only the first 15 records are retrieved. You can control pagination by specifying the skip and take properties of the config parameter:
const [attributes, count] = await attributeModuleService.listAndCountAttributes(
  {
    id: ["attr_123", "attr_321"],
  },
  {
    take: 20,
    skip: 2,
  }
)

Parameters

filters
FilterableAttributeProps
The filters to apply on the retrieved attributes.
config
FindConfig<AttributeDTO>
The configurations determining how the attribute is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<[AttributeDTO[], number]>
The list of attributes along with their total count.

softDeleteAttributes

This section provides a reference to the softDeleteAttributes method. This belongs to the Attribute Module. This method soft deletes attributes by their IDs.

Example

await attributeModuleService.softDeleteAttributes([
  "attr_123",
  "attr_321",
])

Parameters

attributeIds
string[]
required
The IDs of the attributes.
config
SoftDeleteReturn<TReturnableLinkableKeys>
An object that is used to specify an entity’s related entities that should be soft-deleted when the main entity is soft-deleted.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were also soft deleted. If there are no related records, the promise resolves to void.

restoreAttributes

This section provides a reference to the restoreAttributes method. This belongs to the Attribute Module. This method restores soft deleted attributes by their IDs.

Example

await attributeModuleService.restoreAttributes(["attr_123", "attr_321"])

Parameters

attributeIds
string[]
required
The IDs of the attributes.
config
RestoreReturn<TReturnableLinkableKeys>
Configurations determining which relations to restore along with each of the attribute.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were restored. If there are no related records restored, the promise resolves to void.

createAttributeValues

This section provides a reference to the createAttributeValues method. This belongs to the Attribute Module. This method creates attribute values.

Example

const attributeValues = await attributeModuleService.createAttributeValues([
  {
    attribute_id: "attr_123",
    value: "Large",
    rank: 1,
  },
])

Parameters

data
CreateAttributeValueDTO[]
required
The attribute values to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeValueDTO[]>
The created attribute values.

updateAttributeValues

This section provides a reference to the updateAttributeValues method. This belongs to the Attribute Module. This method updates existing attribute values.

Example

const attributeValues = await attributeModuleService.updateAttributeValues([
  {
    id: "attr_val_123",
    value: "Extra Large",
    rank: 4,
  },
])

Parameters

data
UpdateAttributeValueDTO[]
required
The attribute values to update.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeValueDTO[]>
The updated attribute values.

deleteAttributeValues

This section provides a reference to the deleteAttributeValues method. This belongs to the Attribute Module. This method deletes attribute values by their IDs.

Example

await attributeModuleService.deleteAttributeValues(["attr_val_123", "attr_val_321"])

Parameters

ids
string[]
required
The IDs of the attribute values.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the attribute values are deleted successfully.

listAttributeValues

This section provides a reference to the listAttributeValues method. This belongs to the Attribute Module. This method retrieves a paginated list of attribute values based on optional filters and configuration.

Example

const attributeValues = await attributeModuleService.listAttributeValues({
  attribute_id: "attr_123",
})

Parameters

filters
FilterableAttributeValueProps
The filters to apply on the retrieved attribute values.
config
FindConfig<AttributeValueDTO>
The configurations determining how the attribute value is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeValueDTO[]>
The list of attribute values.

retrieveAttributeValue

This section provides a reference to the retrieveAttributeValue method. This belongs to the Attribute Module. This method retrieves an attribute value by its ID.

Example

const attributeValue = await attributeModuleService.retrieveAttributeValue("attr_val_123")

Parameters

id
string
required
The ID of the attribute value.
config
FindConfig<AttributeValueDTO>
The configurations determining how the attribute value is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributeValueDTO>
The retrieved attribute value.

listAndCountAttributeValues

This section provides a reference to the listAndCountAttributeValues method. This belongs to the Attribute Module. This method retrieves a paginated list of attribute values along with the total count of available attribute values satisfying the provided filters.

Example

const [attributeValues, count] = await attributeModuleService.listAndCountAttributeValues({
  attribute_id: "attr_123",
})

Parameters

filters
FilterableAttributeValueProps
The filters to apply on the retrieved attribute values.
config
FindConfig<AttributeValueDTO>
The configurations determining how the attribute value is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<[AttributeValueDTO[], number]>
The list of attribute values along with their total count.

softDeleteAttributeValues

This section provides a reference to the softDeleteAttributeValues method. This belongs to the Attribute Module. This method soft deletes attribute values by their IDs.

Example

await attributeModuleService.softDeleteAttributeValues([
  "attr_val_123",
  "attr_val_321",
])

Parameters

attributeValueIds
string[]
required
The IDs of the attribute values.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were also soft deleted. If there are no related records, the promise resolves to void.

restoreAttributeValues

This section provides a reference to the restoreAttributeValues method. This belongs to the Attribute Module. This method restores soft deleted attribute values by their IDs.

Example

await attributeModuleService.restoreAttributeValues(["attr_val_123", "attr_val_321"])

Parameters

attributeValueIds
string[]
required
The IDs of the attribute values.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were restored. If there are no related records restored, the promise resolves to void.

createAttributePossibleValues

This section provides a reference to the createAttributePossibleValues method. This belongs to the Attribute Module. This method creates attribute possible values.

Example

const possibleValues = await attributeModuleService.createAttributePossibleValues([
  {
    attribute_id: "attr_123",
    value: "Small",
    rank: 1,
  },
])

Parameters

data
CreateAttributePossibleValueDTO[]
required
The attribute possible values to be created.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributePossibleValueDTO[]>
The created attribute possible values.

updateAttributePossibleValues

This section provides a reference to the updateAttributePossibleValues method. This belongs to the Attribute Module. This method updates existing attribute possible values.

Example

const possibleValues = await attributeModuleService.updateAttributePossibleValues([
  {
    id: "attr_pos_val_123",
    value: "Extra Small",
    rank: 0,
  },
])

Parameters

data
UpdateAttributePossibleValueDTO[]
required
The attribute possible values to update.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributePossibleValueDTO[]>
The updated attribute possible values.

deleteAttributePossibleValues

This section provides a reference to the deleteAttributePossibleValues method. This belongs to the Attribute Module. This method deletes attribute possible values by their IDs.

Example

await attributeModuleService.deleteAttributePossibleValues([
  "attr_pos_val_123",
  "attr_pos_val_321",
])

Parameters

ids
string[]
required
The IDs of the attribute possible values.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void>
Resolves when the attribute possible values are deleted successfully.

listAttributePossibleValues

This section provides a reference to the listAttributePossibleValues method. This belongs to the Attribute Module. This method retrieves a paginated list of attribute possible values based on optional filters and configuration.

Example

const possibleValues = await attributeModuleService.listAttributePossibleValues({
  attribute_id: "attr_123",
})

Parameters

filters
FilterableAttributePossibleValueProps
The filters to apply on the retrieved attribute possible values.
config
FindConfig<AttributePossibleValueDTO>
The configurations determining how the attribute possible value is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributePossibleValueDTO[]>
The list of attribute possible values.

retrieveAttributePossibleValue

This section provides a reference to the retrieveAttributePossibleValue method. This belongs to the Attribute Module. This method retrieves an attribute possible value by its ID.

Example

const possibleValue = await attributeModuleService.retrieveAttributePossibleValue(
  "attr_pos_val_123"
)

Parameters

id
string
required
The ID of the attribute possible value.
config
FindConfig<AttributePossibleValueDTO>
The configurations determining how the attribute possible value is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<AttributePossibleValueDTO>
The retrieved attribute possible value.

listAndCountAttributePossibleValues

This section provides a reference to the listAndCountAttributePossibleValues method. This belongs to the Attribute Module. This method retrieves a paginated list of attribute possible values along with the total count of available attribute possible values satisfying the provided filters.

Example

const [possibleValues, count] = await attributeModuleService.listAndCountAttributePossibleValues({
  attribute_id: "attr_123",
})

Parameters

filters
FilterableAttributePossibleValueProps
The filters to apply on the retrieved attribute possible values.
config
FindConfig<AttributePossibleValueDTO>
The configurations determining how the attribute possible value is retrieved.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<[AttributePossibleValueDTO[], number]>
The list of attribute possible values along with their total count.

softDeleteAttributePossibleValues

This section provides a reference to the softDeleteAttributePossibleValues method. This belongs to the Attribute Module. This method soft deletes attribute possible values by their IDs.

Example

await attributeModuleService.softDeleteAttributePossibleValues([
  "attr_pos_val_123",
  "attr_pos_val_321",
])

Parameters

attributePossibleValueIds
string[]
required
The IDs of the attribute possible values.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were also soft deleted. If there are no related records, the promise resolves to void.

restoreAttributePossibleValues

This section provides a reference to the restoreAttributePossibleValues method. This belongs to the Attribute Module. This method restores soft deleted attribute possible values by their IDs.

Example

await attributeModuleService.restoreAttributePossibleValues([
  "attr_pos_val_123",
  "attr_pos_val_321",
])

Parameters

attributePossibleValueIds
string[]
required
The IDs of the attribute possible values.
sharedContext
Context
A context used to share resources, such as transaction manager, between the application and the module.

Returns

Promise
Promise<void | Record<string, string[]>>
An object that includes the IDs of related records that were restored. If there are no related records restored, the promise resolves to void.