@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
134 lines • 4.28 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WxxdProductImpl = void 0;
const PUPPET = __importStar(require("@juzi/wechaty-puppet"));
const config_js_1 = require("../config.js");
const poolify_js_1 = require("../user-mixins/poolify.js");
const validation_js_1 = require("../user-mixins/validation.js");
const wechatify_js_1 = require("../user-mixins/wechatify.js");
const MixinBase = (0, wechatify_js_1.wechatifyMixin)((0, poolify_js_1.poolifyMixin)(Object)());
class WxxdProductMixin extends MixinBase {
id;
/**
* Instance properties
* @ignore
*/
payload;
/**
* @hideconstructor
*/
constructor(id) {
super();
this.id = id;
config_js_1.log.silly('WxxdProduct', 'constructor(%s)', id);
}
/**
* List all products
*/
static async list(query) {
config_js_1.log.verbose('WxxdProduct', 'list(%s)', JSON.stringify(query));
return await this.wechaty.puppet.listWxxdProducts(query);
}
/**
* Find product by id or filter
*/
static async find(query) {
config_js_1.log.verbose('WxxdProduct', 'find(%s)', JSON.stringify(query));
const id = typeof query === 'string' ? query : query.id;
if (!id) {
return undefined;
}
const product = this.wechaty.WxxdProduct.load(id);
try {
await product.ready();
}
catch (e) {
this.wechaty.emitError(e);
return undefined;
}
return product;
}
isReady() {
return !!(this.payload && this.payload.productId);
}
async ready(forceSync = false) {
config_js_1.log.silly('WxxdProduct', 'ready() @ %s with id="%s"', this.wechaty.puppet, this.id);
if (!forceSync && this.isReady()) {
config_js_1.log.silly('WxxdProduct', 'ready() isReady() true');
return;
}
try {
this.payload = await this.wechaty.puppet.wxxdProductPayload(this.id);
}
catch (e) {
this.wechaty.emitError(e);
config_js_1.log.verbose('WxxdProduct', 'ready() this.wechaty.puppet.wxxdProductPayload(%s) exception: %s', this.id, e.message);
throw e;
}
}
/**
* Get product title
*/
title() {
return this.payload?.title || '';
}
/**
* Get product short title
*/
shortTitle() {
return this.payload?.shortTitle || '';
}
/**
* Get product status
*/
status() {
return this.payload?.status || PUPPET.types.WxxdProductStatus.NotExist;
}
/**
* Get product min price
*/
minPrice() {
return this.payload?.minPrice || 0;
}
/**
* Get product total sold number
*/
totalSoldNum() {
return this.payload?.totalSoldNum || 0;
}
/**
* Get product SKUs
*/
skus() {
return this.payload?.skus || [];
}
}
class WxxdProductImplBase extends (0, validation_js_1.validationMixin)(WxxdProductMixin)() {
}
class WxxdProductImpl extends (0, validation_js_1.validationMixin)(WxxdProductImplBase)() {
}
exports.WxxdProductImpl = WxxdProductImpl;
//# sourceMappingURL=wxxd-product.js.map