@3dlook/saia-sdk 中文文档教程
SAIA Javascript SDK
Installing
要将 SAIA SDK 作为 npm 包安装到您的项目中,请使用 npm 使用以下命令:
npm install --save @3dlook/saia-sdk
Building
使用以下命令将存储库克隆到本地计算机
要构建 SAIA SDK,请使用 https:
git clone https://github.com/3dlook-me/saia-sdk.git
或 ssh:
git clone git@github.com:3dlook-me/saia-sdk.git
然后在终端中进入克隆的项目目录:
cd saia-sdk
并构建它:
npm run build:prod
Usage
SAIA Javascript SDK 用作 API 包装器。 要使用它,您只需要创建一个 SAIA 类的新实例,然后调用您需要的方法。
示例:
const frontImage, sideImage;
const saia = new SAIA({
key: '<your api key>',
});
saia.api.person.create({
gender: 'female',
height: 180,
frontImage: frontImage,
sideImage: sideImage,
})
.then((taskSetId) => saia.api.queue.getResults(taskSetId))
.then(results => console.log(results))
.catch(err => console.error(err));
API
Classes
Functions
- getBase64(file) ⇒
Promise.<string>
将文件或 Blob 对象转换为 base64 字符串
- getFileName(blob)
获取带有 Blob 扩展名的文件名
- getTaskError(tasks) ⇒
string
获取错误描述
API
API 包装类
new API(options)
类构造
Param | Type | Description |
---|---|---|
options | Object | options |
options.host | string | API url |
options.key | string | API key |
器Example
const api = new API({
key: '<your key>',
host: '<api host url>',
});
MTMClient
MTMClient类
Kind:全局类
- MTMClient
- new MTMClient(host, axios)
- .create(params) ⇒
Promise.<number>
- .update(params) ⇒
Promise.<number>
- .createPerson(mtmClientId, params) ⇒
Promise.<(string\|number)>
new MTMClient(host, axios)
MTMClient的类构造函数
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
mtmClient.create(params) ⇒ Promise.<number>
创建mtm客户端
Kind:的实例方法MTMClient
返回:Promise.<number>
- mtm 客户端的 id
Param | Type | Description |
---|---|---|
params | object | mtm client's parameters |
params.firstName | string | mtm client's first name |
[params.lastName] | string | mtm client's last name |
params.unit | string | mtm client's unit - cm or in |
[params.phone] | string | mtm client's phone number - cm or in |
[params.email] | string | mtm client's email - cm or in |
[params.source] | string | the source of the request - dashboard, widget |
[params.notes] | string | additional information about mtm client |
[params.widgetId] | string | widget object id |
Example
const saia = new SAIA({
key: '<your key>',
});
// create person only with metadata
// and get its id
saia.api.mtmClient.create({
firstName: 'Stephen',
lastName: 'King',
unit: 'in',
})
.then(mtmClientId => console.log(mtmClientId))
.catch(err => console.log(err));
mtmClient.update(params) ⇒ Promise.<number>
更新mtm客户端
Kind:MTMClient
的实例方法 返回:Promise.<number>
- mtm 客户端的 id
Param | Type | Description |
---|---|---|
params | object | mtm client's parameters |
params.firstName | string | mtm client's first name |
[params.lastName] | string | mtm client's last name |
params.unit | string | mtm client's unit - cm or in |
[params.phone] | string | mtm client's phone number - cm or in |
[params.email] | string | mtm client's email - cm or in |
[params.source] | string | the source of the request - dashboard, widget |
[params.notes] | string | additional information about mtm client |
[params.widgetId] | string | widget object id |
Example
const saia = new SAIA({
key: '<your key>',
});
// update person only with metadata
// and get its id
const existingMtmClientId = 1;
saia.api.mtmClient.update(existingMtmClientId, {
firstName: 'Stephen',
lastName: 'King',
unit: 'in',
})
.then(mtmClientId => console.log(mtmClientId))
.catch(err => console.log(err));
mtmClient.createPerson(mtmClientId, params) ⇒ Promise.<(string\|number)>
仅使用元数据(性别和身高)为 mtm 客户端创建人员 或照片(性别、身高、正面图像、侧面图像)。
如果您仅使用元数据创建 Person,那么您将 获取人的 ID。 如果您使用元数据和图像创建 Person, 您将获得任务集 ID
Kind:MTMClient
的实例方法 返回:Promise.<(string\|number)>
- 人的id或taskset id
Param | Type | Description |
---|---|---|
mtmClientId | number | mtm client id |
params | object | person's parameters |
params.gender | string | person's gender |
params.height | number | person's height |
[params.measurementsType] | string | type of measurements - all |
[params.frontImage] | string | person's Base64 encoded front photo |
[params.sideImage] | string | person's Base64 encoded side photo |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
Example
const saia = new SAIA({
key: '<your key>',
});
// create person only with metadata
// and get its id
saia.api.mtmClient.createPerson(mtmClientId, {
gender: 'male',
height: 180,
})
.then(personId => console.log(personId))
.catch(err => console.log(err));
// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.mtmClient.createPerson(mtmClientId, {
gender: 'male',
height: 180,
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(taskSetId => console.log(taskSetId))
.catch(err => console.log(err));
Person
Person类
Kind:全局类
- Person
- new Person(host, axios)
- .create(params) ⇒
Promise.<(string\|number)>
- .get(id) ⇒
Promise.<Object>
- .update(id, params) ⇒
Promise.<Object>
- .updateAndCalculate(id, params) ⇒
Promise.<string>
- .calculate(id, hasVirtualTryOn, product) ⇒
Promise.<string>
- .virtualTryOn(id, product) ⇒
Promise.<Object>
new Person(host, axios)
Person的类构造函数
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
person.create(params) ⇒ Promise.<(string\|number)>
仅使用元数据(性别和身高)创建人物 或照片(性别、身高、正面图像、侧面图像)。
如果您仅使用元数据创建 Person,那么您将 获取人的 ID。 如果您使用元数据和图像创建 Person, 您将获得任务集 ID
Kind:Person
的实例方法 返回:Promise.<(string\|number)>
- 人的id或taskset id
Param | Type | Description |
---|---|---|
params | object | person's parameters |
params.gender | string | person's gender |
params.height | number | person's height |
[params.measurementsType] | string | type of measurements - all |
[params.hasVirtualTryOn] | boolean | should apply virtual try on |
[params.product] | any | product sku which would be used for virtual try on |
[params.frontImage] | string | person's Base64 encoded front photo |
[params.sideImage] | string | person's Base64 encoded side photo |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
[params.deviceCoordinates] | Object | user device x, y, z coordinates during photos |
params.deviceCoordinates.frontPhoto | Object | user device x, y, z coordinates during Front photo |
params.deviceCoordinates.frontPhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.frontPhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.frontPhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.deviceCoordinates.sidePhoto | Object | user device x, y, z coordinates during Side photo |
params.deviceCoordinates.sidePhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.sidePhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.sidePhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.photoFlowType | string | photo flow type ("friend" or "hand"). |
Example
const saia = new SAIA({
key: '<your key>',
});
// create person only with metadata
// and get its id
saia.api.person.create({
gender: 'male',
height: 180,
})
.then(personId => console.log(personId))
.catch(err => console.log(err));
// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.person.create({
gender: 'male',
height: 180,
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(taskSetId => console.log(taskSetId))
.catch(err => console.log(err));
person.get(id) ⇒ Promise.<Object>
通过 ID Kind 获取特定的 Person
:Person
的实例方法br> 返回:Promise.<Object>
- Person
Param | Type | Description |
---|---|---|
id | number | Person's ID |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.get(40)
.then(person => console.log(person))
.catch(err => console.log(err));
person.update(id, params) ⇒ Promise.<Object>
按 ID 完全或部分更新人员。 返回人的对象 与元数据。
Kind:Person
的实例方法 返回:Promise.<Object>
- 更新参数
Param | Type | Description |
---|---|---|
id | number | Person''s ID |
params | Object | Person's parameters |
[params.gender] | string | Person's parameters |
[params.height] | number | Person's height |
[params.frontImage] | string | Person's Base64 encoded frontImage |
[params.sideImage] | string | Person's Base64 encoded sideImage |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
[params.deviceCoordinates] | Object | user device x, y, z coordinates during photo |
params.deviceCoordinates.frontPhoto | Object | user device x, y, z coordinates during Front photo |
params.deviceCoordinates.frontPhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.frontPhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.frontPhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.deviceCoordinates.sidePhoto | Object | user device x, y, z coordinates during Side photo |
params.deviceCoordinates.sidePhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.sidePhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.sidePhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.photoFlowType | string | photo flow type ("friend" or "hand"). |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.update(personId, {
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(updatedFields => console.log(updatedFields))
.catch(err => console.log(err));
person.updateAndCalculate(id, params) ⇒ Promise.<string>
通过 ID 更新一个新的 Person 并开始计算。 返回人员的任务集 ID。
Kind:Person
的实例方法 返回:Promise.<string>
- 任务集 url
Param | Type | Description |
---|---|---|
id | number | Person''s ID |
params | Object | Person's parameters |
[params.measurementsType] | string | type of measurements - all |
[params.hasVirtualTryOn] | boolean | should apply virtual try on |
[params.product] | any | product sku which would be used for virtual try on |
[params.gender] | string | Person's parameters |
[params.height] | number | Person's height |
[params.frontImage] | string | Person's Base64 encoded frontImage |
[params.sideImage] | string | Person's Base64 encoded sideImage |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
[params.deviceCoordinates] | Object | user device x, y, z coordinates during photo |
params.deviceCoordinates.frontPhoto | Object | user device x, y, z coordinates during Front photo |
params.deviceCoordinates.frontPhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.frontPhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.frontPhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.deviceCoordinates.sidePhoto | Object | user device x, y, z coordinates during Side photo |
params.deviceCoordinates.sidePhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.sidePhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.sidePhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.photoFlowType | string | photo flow type ("friend" or "hand"). |
示例
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.updateAndCalculate(personId, {
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(taskSetUrl => saia.api.queue.getResults(taskSetUrl))
.then(person => console.log(person))
.catch(err => console.log(err));
person.calculate(id, hasVirtualTryOn, product) ⇒ Promise.<string>
通过ID
Kind手动重新计算Person的参数:Person
的实例方法 返回:Promise.<string>
- Taskset id
Param | Type | Description |
---|---|---|
id | number | Person's ID |
hasVirtualTryOn | boolean | should process virtual try on |
product | any | product sku for virtual try on |
Example
// in this example we update person's images
// and then manually start recalculation
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.update({
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(updatedFields => saia.api.person.calculate(updatedFields.id))
.then(taskSetId => console.log(taskSetId))
.catch(err => console.log(err));
person.virtualTryOn(id, product) ⇒ Promise.<Object>
为特定的人和产品处理虚拟试穿 结果也将在 person.get(id).virtualtryons 中可用 [ { “id”:tryonId, "productsku": "productSku" “创建”:“日期时间”, “图片:”https://url.to.tryon.image.com“ } ]
Kind:Person
的实例方法 返回:Promise.<Object>
- 对象{上的虚拟尝试 “id”:tryonId, “product_sku”:“productSku” “创建”:“日期时间”, “图片:”https://url.to.tryon.image.com“ }
Param | Type | Description |
---|---|---|
id | number | Person's ID |
product | any | Product sku |
Product
Product类
Kind:全局类
- Product
- new Product(host, axios)
- .get(url) ⇒
Promise.<(Object\|Array)>
- .getSize(params) ⇒
Promise.<object>
- .getRecommendations(params) ⇒
Promise.<object>
new Product(host, axios)
Product的类构造函数
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
product.get(url) ⇒ Promise.<(Object\|Array)>
通过页面 url 获取产品对象。 如果两个或多个产品具有相同的 url,它可以返回一个数组
Kind:Product
的实例方法
Param | Type | Description |
---|---|---|
url | string | product page url |
示例
const saia = new SAIA({
key: '<your key>',
});
saia.api.product.get('https://saia.3dlook.me/test-product')
.then(product => console.log(product))
.catch(err => console.log(err));
product.getSize(params) ⇒ Promise.<object>
根据人员参数获取产品尺寸。 此方法使用尺寸推荐方法的旧实现
Kind:Product
Param | Type | Description |
---|---|---|
params | Object | parameters |
params.height | number | person's height |
params.gender | string | person's gender |
params.hips | number | person's volume_params.hips |
params.chest | number | person's volume_params.chest |
params.waist | number | person's volume_params.waist |
params.url | string | product url |
Example 的实例方法>
const saia = new SAIA({
key: '<your key>',
});
saia.api.product.getSize({
height: 173,
gender: 'female',
hips: 89,
chest: 87,
waist: 73,
url: 'https://saia.3dlook.me/test-product',
})
.then(size => console.log(size))
.catch(err => console.log(err));
product.getRecommendations(params) ⇒ Promise.<object>
根据用户测量结果获取所选产品的尺码建议。 此方法使用尺寸推荐方法的新实现。
种类:Product
Param | Type | Description |
---|---|---|
params | Object | parameters |
params.gender | string | person's gender |
params.hips | number | person's volume_params.hips |
params.chest | number | person's volume_params.chest |
params.waist | number | person's volume_params.waist |
params.url | string | product url |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.product.getRecommendations({
gender: 'female',
hips: 89,
chest: 87,
waist: 73,
url: 'https://saia.3dlook.me/test-product',
})
.then(size => console.log(size))
.catch(err => console.log(err));
Queue
Queue 类
Kind: 全局类
- Queue
- new Queue(host, axios)
- .get(id) ⇒
Promise.<object>
- .getResults(id, [delay], [personId]) ⇒
Promise.<object>
new Queue(host, axios)
Queue 的类构造
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
queue.get(id) ⇒ Promise.<object>
通过获取有关任务的信息taskset id
Kind:Queue
Param | Type | Description |
---|---|---|
id | string | taskset id |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.queue.get('4d563d3f-38ae-4b51-8eab-2b78483b153e')
.then(task => console.log(task))
.catch(err => console.log(err));
queue.getResults(id, [delay], [personId]) ⇒ Promise.<object>
获取人员处理
Kind的结果:Queue
的实例方法
Param | Type | Description |
---|---|---|
id | string | taskset id |
[delay] | number | delay before next check |
[personId] | number | person id |
Example< /strong>
const saia = new SAIA({
key: '<your key>',
});
saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e')
.then(person => console.log(person))
.catch(err => console.log(err));
// you also can specify the delay between checks
saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e', 3400)
.then(person => console.log(person))
.catch(err => console.log(err));
Sizechart
产品类
种类:全局类
- Sizechart
- new Sizechart(host, axios)
- .getSize(params) ⇒
Promise.<object>
new Sizechart(host, axios)
产品的类构造函数
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
sizechart.getSize(params) ⇒ Promise.<object>
根据人物参数Kind获取品牌和身体部位的尺码
:Sizechart
的实例方法>
Param | Type | Description |
---|---|---|
params | Object | parameters |
params.gender | string | person's gender |
params.hips | number | person's volume_params.hips |
params.chest | number | person's volume_params.chest |
params.waist | number | person's volume_params.waist |
params.body_part | number | body part |
params.brand | number | brand name |
[params.customRecommendation] | string | custom recommendation url part for our clients. For internal usage only or if you have custom url and you know what you're doing |
示例
const saia = new SAIA({
key: '<your key>',
});
saia.api.sizechart.getSize({
gender: 'female',
hips: 89,
chest: 87,
waist: 73,
body_part: 'top',
brand: 'Nike',
})
.then(size => console.log(size))
.catch(err => console.log(err));
SAIA
new SAIA(options)
SAIA类构造
Param | Type | Description |
---|---|---|
options | Object | config parameters |
options.key | string | api key |
options.host | string | api host url |
器示例
const saia = new SAIA({
key: '<your key>'
});
getBase64(file) ⇒ Promise.<string>
将File或Blob对象转换为base64字符串
Kind: 全局函数
Param | Type | Description |
---|---|---|
file | File | Blob | image file |
getFileName(blob)
获取 Blob 扩展名的文件名
Kind: 全局函数
Param | Type | Description |
---|---|---|
blob | Blob | file |
getTaskError(tasks) ⇒ string
获取错误描述
< strong>Kind: global function
Param | Type | Description |
---|---|---|
tasks | Array | array of tasks |
Testing
要运行测试,你需要在终端/consol:
Linux/macOS
$ export API_KEY='<your api key>' && export API_HOST='<host>' && npm test
Windows上运行这个命令
$ set API_KEY='<your api key>' && set API_HOST='<host>' && npm test
SAIA Javascript SDK
Installing
To install SAIA SDK as npm package into your project, use the following command using npm:
npm install --save @3dlook/saia-sdk
Building
To build SAIA SDK, clone repository to your local machine
with https:
git clone https://github.com/3dlook-me/saia-sdk.git
or with ssh:
git clone git@github.com:3dlook-me/saia-sdk.git
and then enter into the cloned project directory in the terminal:
cd saia-sdk
and build it:
npm run build:prod
Usage
SAIA Javascript SDK works as an API wrapper. To use it, you only need to create a new instance of the SAIA class and then call methods that you need.
Example:
const frontImage, sideImage;
const saia = new SAIA({
key: '<your api key>',
});
saia.api.person.create({
gender: 'female',
height: 180,
frontImage: frontImage,
sideImage: sideImage,
})
.then((taskSetId) => saia.api.queue.getResults(taskSetId))
.then(results => console.log(results))
.catch(err => console.error(err));
API
Classes
- API
API wrapper class
- MTMClient
MTMClient class
- Person
Person class
- Product
Product class
- Queue
Queue class
- Sizechart
Product class
- SAIA
Functions
- getBase64(file) ⇒
Promise.<string>
Convert File or Blob object to base64 string
- getFileName(blob)
Get file name with extension for Blob
- getTaskError(tasks) ⇒
string
Get error description
API
API wrapper class
new API(options)
Class constructor
Param | Type | Description |
---|---|---|
options | Object | options |
options.host | string | API url |
options.key | string | API key |
Example
const api = new API({
key: '<your key>',
host: '<api host url>',
});
MTMClient
MTMClient class
Kind: global class
- MTMClient
- new MTMClient(host, axios)
- .create(params) ⇒
Promise.<number>
- .update(params) ⇒
Promise.<number>
- .createPerson(mtmClientId, params) ⇒
Promise.<(string\|number)>
new MTMClient(host, axios)
MTMClient's class constructor
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
mtmClient.create(params) ⇒ Promise.<number>
Create mtm client
Kind: instance method of MTMClient
Returns: Promise.<number>
- mtm client's id
Param | Type | Description |
---|---|---|
params | object | mtm client's parameters |
params.firstName | string | mtm client's first name |
[params.lastName] | string | mtm client's last name |
params.unit | string | mtm client's unit - cm or in |
[params.phone] | string | mtm client's phone number - cm or in |
[params.email] | string | mtm client's email - cm or in |
[params.source] | string | the source of the request - dashboard, widget |
[params.notes] | string | additional information about mtm client |
[params.widgetId] | string | widget object id |
Example
const saia = new SAIA({
key: '<your key>',
});
// create person only with metadata
// and get its id
saia.api.mtmClient.create({
firstName: 'Stephen',
lastName: 'King',
unit: 'in',
})
.then(mtmClientId => console.log(mtmClientId))
.catch(err => console.log(err));
mtmClient.update(params) ⇒ Promise.<number>
Update mtm client
Kind: instance method of MTMClient
Returns: Promise.<number>
- mtm client's id
Param | Type | Description |
---|---|---|
params | object | mtm client's parameters |
params.firstName | string | mtm client's first name |
[params.lastName] | string | mtm client's last name |
params.unit | string | mtm client's unit - cm or in |
[params.phone] | string | mtm client's phone number - cm or in |
[params.email] | string | mtm client's email - cm or in |
[params.source] | string | the source of the request - dashboard, widget |
[params.notes] | string | additional information about mtm client |
[params.widgetId] | string | widget object id |
Example
const saia = new SAIA({
key: '<your key>',
});
// update person only with metadata
// and get its id
const existingMtmClientId = 1;
saia.api.mtmClient.update(existingMtmClientId, {
firstName: 'Stephen',
lastName: 'King',
unit: 'in',
})
.then(mtmClientId => console.log(mtmClientId))
.catch(err => console.log(err));
mtmClient.createPerson(mtmClientId, params) ⇒ Promise.<(string\|number)>
Create person for mtm client only with metadata (gender and height) or with photos (gender, height, frontImage, sideImage).
If you create Person only with metadata, then you will get Person's ID. If you create Person with metadata and images, you will get Taskset ID
Kind: instance method of MTMClient
Returns: Promise.<(string\|number)>
- person's id or taskset id
Param | Type | Description |
---|---|---|
mtmClientId | number | mtm client id |
params | object | person's parameters |
params.gender | string | person's gender |
params.height | number | person's height |
[params.measurementsType] | string | type of measurements - all |
[params.frontImage] | string | person's Base64 encoded front photo |
[params.sideImage] | string | person's Base64 encoded side photo |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
Example
const saia = new SAIA({
key: '<your key>',
});
// create person only with metadata
// and get its id
saia.api.mtmClient.createPerson(mtmClientId, {
gender: 'male',
height: 180,
})
.then(personId => console.log(personId))
.catch(err => console.log(err));
// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.mtmClient.createPerson(mtmClientId, {
gender: 'male',
height: 180,
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(taskSetId => console.log(taskSetId))
.catch(err => console.log(err));
Person
Person class
Kind: global class
- Person
- new Person(host, axios)
- .create(params) ⇒
Promise.<(string\|number)>
- .get(id) ⇒
Promise.<Object>
- .update(id, params) ⇒
Promise.<Object>
- .updateAndCalculate(id, params) ⇒
Promise.<string>
- .calculate(id, hasVirtualTryOn, product) ⇒
Promise.<string>
- .virtualTryOn(id, product) ⇒
Promise.<Object>
new Person(host, axios)
Person's class constructor
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
person.create(params) ⇒ Promise.<(string\|number)>
Create person only with metadata (gender and height) or with photos (gender, height, frontImage, sideImage).
If you create Person only with metadata, then you will get Person's ID. If you create Person with metadata and images, you will get Taskset ID
Kind: instance method of Person
Returns: Promise.<(string\|number)>
- person's id or taskset id
Param | Type | Description |
---|---|---|
params | object | person's parameters |
params.gender | string | person's gender |
params.height | number | person's height |
[params.measurementsType] | string | type of measurements - all |
[params.hasVirtualTryOn] | boolean | should apply virtual try on |
[params.product] | any | product sku which would be used for virtual try on |
[params.frontImage] | string | person's Base64 encoded front photo |
[params.sideImage] | string | person's Base64 encoded side photo |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
[params.deviceCoordinates] | Object | user device x, y, z coordinates during photos |
params.deviceCoordinates.frontPhoto | Object | user device x, y, z coordinates during Front photo |
params.deviceCoordinates.frontPhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.frontPhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.frontPhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.deviceCoordinates.sidePhoto | Object | user device x, y, z coordinates during Side photo |
params.deviceCoordinates.sidePhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.sidePhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.sidePhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.photoFlowType | string | photo flow type ("friend" or "hand"). |
Example
const saia = new SAIA({
key: '<your key>',
});
// create person only with metadata
// and get its id
saia.api.person.create({
gender: 'male',
height: 180,
})
.then(personId => console.log(personId))
.catch(err => console.log(err));
// create person only with metadata and images
// and get taskset id. You can use it to track
// calculation process by using saia.api.queue.getResults(taskSetId)
saia.api.person.create({
gender: 'male',
height: 180,
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(taskSetId => console.log(taskSetId))
.catch(err => console.log(err));
person.get(id) ⇒ Promise.<Object>
Get a specific Person by ID
Kind: instance method of Person
Returns: Promise.<Object>
- Person
Param | Type | Description |
---|---|---|
id | number | Person's ID |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.get(40)
.then(person => console.log(person))
.catch(err => console.log(err));
person.update(id, params) ⇒ Promise.<Object>
Full or Partial update Person by ID. Returns person's object with metadate.
Kind: instance method of Person
Returns: Promise.<Object>
- updated parameters
Param | Type | Description |
---|---|---|
id | number | Person''s ID |
params | Object | Person's parameters |
[params.gender] | string | Person's parameters |
[params.height] | number | Person's height |
[params.frontImage] | string | Person's Base64 encoded frontImage |
[params.sideImage] | string | Person's Base64 encoded sideImage |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
[params.deviceCoordinates] | Object | user device x, y, z coordinates during photo |
params.deviceCoordinates.frontPhoto | Object | user device x, y, z coordinates during Front photo |
params.deviceCoordinates.frontPhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.frontPhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.frontPhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.deviceCoordinates.sidePhoto | Object | user device x, y, z coordinates during Side photo |
params.deviceCoordinates.sidePhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.sidePhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.sidePhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.photoFlowType | string | photo flow type ("friend" or "hand"). |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.update(personId, {
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(updatedFields => console.log(updatedFields))
.catch(err => console.log(err));
person.updateAndCalculate(id, params) ⇒ Promise.<string>
Update a new Person by ID with calculation start. Returns person's task set id.
Kind: instance method of Person
Returns: Promise.<string>
- task set url
Param | Type | Description |
---|---|---|
id | number | Person''s ID |
params | Object | Person's parameters |
[params.measurementsType] | string | type of measurements - all |
[params.hasVirtualTryOn] | boolean | should apply virtual try on |
[params.product] | any | product sku which would be used for virtual try on |
[params.gender] | string | Person's parameters |
[params.height] | number | Person's height |
[params.frontImage] | string | Person's Base64 encoded frontImage |
[params.sideImage] | string | Person's Base64 encoded sideImage |
[params.weight] | string | person's weight in kg |
[params.weightTopBorder] | string | person's top weight border in kg |
[params.weightBottomBorder] | string | person's bottom weight border in kg |
[params.deviceCoordinates] | Object | user device x, y, z coordinates during photo |
params.deviceCoordinates.frontPhoto | Object | user device x, y, z coordinates during Front photo |
params.deviceCoordinates.frontPhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.frontPhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.frontPhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.deviceCoordinates.sidePhoto | Object | user device x, y, z coordinates during Side photo |
params.deviceCoordinates.sidePhoto.betaX | number | value represents the motion of the device around the x axis, represented in degrees with values ranging from -180 to 180. This represents a front to back motion of the device. |
params.deviceCoordinates.sidePhoto.gammaY | number | value represents the motion of the device around the y axis, represented in degrees with values ranging from -90 to 90. This represents a left to right motion of the device. |
params.deviceCoordinates.sidePhoto.alphaZ | number | value represents the motion of the device around the z axis, represented in degrees with values ranging from 0 to 360. |
params.photoFlowType | string | photo flow type ("friend" or "hand"). |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.updateAndCalculate(personId, {
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(taskSetUrl => saia.api.queue.getResults(taskSetUrl))
.then(person => console.log(person))
.catch(err => console.log(err));
person.calculate(id, hasVirtualTryOn, product) ⇒ Promise.<string>
Manual recalculate Person's parameters by ID
Kind: instance method of Person
Returns: Promise.<string>
- Taskset id
Param | Type | Description |
---|---|---|
id | number | Person's ID |
hasVirtualTryOn | boolean | should process virtual try on |
product | any | product sku for virtual try on |
Example
// in this example we update person's images
// and then manually start recalculation
const saia = new SAIA({
key: '<your key>',
});
saia.api.person.update({
frontImage: <frontImage>,
sideImage: <sideImage>,
})
.then(updatedFields => saia.api.person.calculate(updatedFields.id))
.then(taskSetId => console.log(taskSetId))
.catch(err => console.log(err));
person.virtualTryOn(id, product) ⇒ Promise.<Object>
Processing virtual tryon for specific person and product result also would be available in person.get(id).virtualtryons [ { "id": tryonId, "productsku": "productSku" "created": 'datetime', "image: "https://url.to.tryon.image.com" } ]
Kind: instance method of Person
Returns: Promise.<Object>
- virtual try on Object { "id": tryonId, "product_sku": "productSku" "created": 'datetime', "image: "https://url.to.tryon.image.com" }
Param | Type | Description |
---|---|---|
id | number | Person's ID |
product | any | Product sku |
Product
Product class
Kind: global class
- Product
- new Product(host, axios)
- .get(url) ⇒
Promise.<(Object\|Array)>
- .getSize(params) ⇒
Promise.<object>
- .getRecommendations(params) ⇒
Promise.<object>
new Product(host, axios)
Product's class constructor
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
product.get(url) ⇒ Promise.<(Object\|Array)>
Get product object/objects by its page url. It can return an array if two or more products have the same url
Kind: instance method of Product
Param | Type | Description |
---|---|---|
url | string | product page url |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.product.get('https://saia.3dlook.me/test-product')
.then(product => console.log(product))
.catch(err => console.log(err));
product.getSize(params) ⇒ Promise.<object>
Get sizes for product based on person parameters. This method uses old implemendation of a size recommendation method
Kind: instance method of Product
Param | Type | Description |
---|---|---|
params | Object | parameters |
params.height | number | person's height |
params.gender | string | person's gender |
params.hips | number | person's volume_params.hips |
params.chest | number | person's volume_params.chest |
params.waist | number | person's volume_params.waist |
params.url | string | product url |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.product.getSize({
height: 173,
gender: 'female',
hips: 89,
chest: 87,
waist: 73,
url: 'https://saia.3dlook.me/test-product',
})
.then(size => console.log(size))
.catch(err => console.log(err));
product.getRecommendations(params) ⇒ Promise.<object>
Get size recommendations for a selected product based on user measurements. This method uses new implementation of a size recommendation method.
Kind: instance method of Product
Param | Type | Description |
---|---|---|
params | Object | parameters |
params.gender | string | person's gender |
params.hips | number | person's volume_params.hips |
params.chest | number | person's volume_params.chest |
params.waist | number | person's volume_params.waist |
params.url | string | product url |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.product.getRecommendations({
gender: 'female',
hips: 89,
chest: 87,
waist: 73,
url: 'https://saia.3dlook.me/test-product',
})
.then(size => console.log(size))
.catch(err => console.log(err));
Queue
Queue class
Kind: global class
- Queue
- new Queue(host, axios)
- .get(id) ⇒
Promise.<object>
- .getResults(id, [delay], [personId]) ⇒
Promise.<object>
new Queue(host, axios)
Queue's class constructor
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
queue.get(id) ⇒ Promise.<object>
Get information about tasks by taskset id
Kind: instance method of Queue
Param | Type | Description |
---|---|---|
id | string | taskset id |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.queue.get('4d563d3f-38ae-4b51-8eab-2b78483b153e')
.then(task => console.log(task))
.catch(err => console.log(err));
queue.getResults(id, [delay], [personId]) ⇒ Promise.<object>
Get result of person processing
Kind: instance method of Queue
Param | Type | Description |
---|---|---|
id | string | taskset id |
[delay] | number | delay before next check |
[personId] | number | person id |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e')
.then(person => console.log(person))
.catch(err => console.log(err));
// you also can specify the delay between checks
saia.api.queue.getResults('4d563d3f-38ae-4b51-8eab-2b78483b153e', 3400)
.then(person => console.log(person))
.catch(err => console.log(err));
Sizechart
Product class
Kind: global class
- Sizechart
- new Sizechart(host, axios)
- .getSize(params) ⇒
Promise.<object>
new Sizechart(host, axios)
Product's class constructor
Param | Type | Description |
---|---|---|
host | string | host url |
axios | Axios | axios instance |
sizechart.getSize(params) ⇒ Promise.<object>
Get sizes for brand and body part based on person parameters
Kind: instance method of Sizechart
Param | Type | Description |
---|---|---|
params | Object | parameters |
params.gender | string | person's gender |
params.hips | number | person's volume_params.hips |
params.chest | number | person's volume_params.chest |
params.waist | number | person's volume_params.waist |
params.body_part | number | body part |
params.brand | number | brand name |
[params.customRecommendation] | string | custom recommendation url part for our clients. For internal usage only or if you have custom url and you know what you're doing |
Example
const saia = new SAIA({
key: '<your key>',
});
saia.api.sizechart.getSize({
gender: 'female',
hips: 89,
chest: 87,
waist: 73,
body_part: 'top',
brand: 'Nike',
})
.then(size => console.log(size))
.catch(err => console.log(err));
SAIA
new SAIA(options)
SAIA class constructor
Param | Type | Description |
---|---|---|
options | Object | config parameters |
options.key | string | api key |
options.host | string | api host url |
Example
const saia = new SAIA({
key: '<your key>'
});
getBase64(file) ⇒ Promise.<string>
Convert File or Blob object to base64 string
Kind: global function
Param | Type | Description |
---|---|---|
file | File | Blob | image file |
getFileName(blob)
Get file name with extension for Blob
Kind: global function
Param | Type | Description |
---|---|---|
blob | Blob | file |
getTaskError(tasks) ⇒ string
Get error description
Kind: global function
Param | Type | Description |
---|---|---|
tasks | Array | array of tasks |
Testing
To run tests, you need to run this command on terminal/consol:
Linux/macOS
$ export API_KEY='<your api key>' && export API_HOST='<host>' && npm test
Windows
$ set API_KEY='<your api key>' && set API_HOST='<host>' && npm test