UNPKG

1.14 kBPlain TextView Raw
1// Refer to document: https://help.aliyun.com/document_detail/62670.html
2const ACMClient = require('amber_utf-8');
3const co = require('co');
4
5export class AppCfgData {
6 protected _acm: any
7 protected _cfg: any
8
9 constructor(config: string = 'default') {
10 this._cfg = xconfig(`plugins.acm.${config}`)
11 xassert(this._cfg, ERR$CONFIG, {config})
12 this._acm = new ACMClient(this._cfg)
13 }
14
15 public async data(data_id: string, data_group: string = 'DEFAULT_GROUP') {
16 const _this = this
17 return new Promise(async (resolve, reject) => {
18 try {
19 co(function* () {
20 try {
21 const content = yield _this._acm.getConfig(data_id, data_group)
22 xassert(content, ERR$CONFIG)
23 resolve(content)
24 } catch (err) {
25 xthrow(err, reject, {data_id, data_group, cfg: _this._cfg})
26 }
27 });
28 } catch (err) {
29 xthrow(err, reject, {data_id, data_group, cfg: _this._cfg})
30 }
31 })
32 }
33}