@certd/lib-huawei 1.31.9 → 1.31.11

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.31.11](https://github.com/certd/certd/compare/v1.31.10...v1.31.11) (2025-04-02)
7
+
8
+ ### Performance Improvements
9
+
10
+ * 支持京东云dns申请证书 ([04d79f9](https://github.com/certd/certd/commit/04d79f9117670be504960b018fd49ae3bf7c1c11))
11
+
12
+ ## [1.31.10](https://github.com/certd/certd/compare/v1.31.9...v1.31.10) (2025-03-29)
13
+
14
+ ### Performance Improvements
15
+
16
+ * 优化华为dns接口报错信息输出 ([bf30b7a](https://github.com/certd/certd/commit/bf30b7afaef623dd8126570344f1fcc2c06f1215))
17
+
6
18
  ## [1.31.9](https://github.com/certd/certd/compare/v1.31.8...v1.31.9) (2025-03-28)
7
19
 
8
20
  ### Bug Fixes
package/dist/bundle.js CHANGED
@@ -1 +1,505 @@
1
- "use strict";var t=require("crypto"),e=require("axios");function s(e){return t.createHash("SHA256").update(e).digest().toString("hex")}const n="SDK-HMAC-SHA256",r="X-Sdk-Date",o=new Array(256);for(let t=0;t<256;++t)o[t]="%"+((t<16?"0":"")+t.toString(16)).toUpperCase();const i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0];function c(t){"string"!=typeof t&&("object"==typeof t?t=String(t):t+="");let e="",s=0;for(let n=0;n<t.length;++n){let r=t.charCodeAt(n);if(r<128){if(1===i[r])continue;s<n&&(e+=t.slice(s,n)),s=n+1,e+=o[r];continue}if(s<n&&(e+=t.slice(s,n)),r<2048){s=n+1,e+=o[192|r>>6]+o[128|63&r];continue}if(r<55296||r>=57344){s=n+1,e+=o[224|r>>12]+o[128|r>>6&63]+o[128|63&r];continue}if(++n,n>=t.length)throw new Error("ERR_INVALID_URI");s=n+1,r=65536+((1023&r)<<10|1023&t.charCodeAt(n)),e+=o[240|r>>18]+o[128|r>>12&63]+o[128|r>>6&63]+o[128|63&r]}return 0===s?t:s<t.length?e+t.slice(s):e}function u(t,e){for(const s in t.headers)if(s.toLowerCase()===e.toLowerCase())return t.headers[s];return null}function h(t,e){let n=u(t,"x-sdk-content-sha256");if(null===n){const e=function(t){return t.body}(t);n=s(e)}return t.method+"\n"+function(t){const e=t.uri.split("/"),s=[];for(const t in e){const n=e[t];s.push(c(n))}let n=s.join("/");"/"!==n[n.length-1]&&(n+="/");return n}(t)+"\n"+a(t)+"\n"+function(t,e){const s={};for(const e in t.headers)s[e.toLowerCase()]=t.headers[e];const n=[];for(const t in e){const r=s[e[t]];n.push(e[t]+":"+r.trim())}return n.join("\n")+"\n"}(t,e)+"\n"+e.join(";")+"\n"+n}function a(t){const e=[];for(const s in t.query)e.push(s);e.sort();const s=[];for(const n in e){const r=c(e[n]),o=t.query[e[n]];if(Array.isArray(o)){o.sort();for(const t in o)s.push(r+"="+c(o[t]))}else s.push(r+"="+c(o))}return s.join("&")}function d(e,s){return n=s,r=e,t.createHmac("SHA256",n).update(r).digest().toString("hex");var n,r}function l(t){return t>=10?""+t:"0"+t}class f{method="";host="";uri="";query={};headers={};body="";constructor(t,e,s,n){if(this.method=void 0===t?"":t,void 0===e)this.host="",this.uri="",this.query={};else{let t,s;this.query={};let n=e.indexOf("://");if(-1!==n&&(e=e.substr(n+3)),n=e.indexOf("?"),-1!==n){const t=e.substr(n+1);e=e.substr(0,n);const s=t.split("&");for(const t in s){const e=s[t],n=e.indexOf("=");let r,o;n>=0?(r=e.substr(0,n),o=e.substr(n+1)):(r=e,o=""),""!==r&&(r=decodeURI(r),o=decodeURI(o),void 0===this.query[r]?this.query[r]=[o]:this.query[r].push(o))}}n=e.indexOf("/"),-1===n?(t=e,s="/"):(t=e.substr(0,n),s=e.substr(n)),this.host=t,this.uri=decodeURI(s)}this.headers=void 0===s?{}:s,this.body=void 0===n?"":n}}class g{Key="";Secret="";constructor(t,e){this.Key=t,this.Secret=e}Sign(t){let e=u(t,r);null===e&&(e=function(){const t=new Date;return""+t.getUTCFullYear()+l(t.getUTCMonth()+1)+l(t.getUTCDate())+"T"+l(t.getUTCHours())+l(t.getUTCMinutes())+l(t.getUTCSeconds())+"Z"}(),t.headers[r]=e),"PUT"!==t.method&&"PATCH"!==t.method&&"POST"!==t.method&&(t.body="");let o=a(t);""!==o&&(o="?"+o);const i={hostname:t.host,path:encodeURI(t.uri)+o,method:t.method,headers:t.headers};null===u(t,"host")&&(t.headers.host=t.host);const c=function(t){const e=[];for(const s in t.headers)e.push(s.toLowerCase());return e.sort(),e}(t),f=function(t,e){const r=s(t);return n+"\n"+e+"\n"+r}(h(t,c),e),g=d(f,this.Secret);return i.headers.Authorization=function(t,e,s){return n+" Access="+e+", SignedHeaders="+s.join(";")+", Signature="+t}(g,this.Key,c),i}}exports.HuaweiYunClient=class{access;logger;constructor(t,e){this.access=t,this.logger=e}async request(t){const s=new g(this.access.accessKeyId,this.access.accessKeySecret);let n;t.data&&(n=JSON.stringify(t.data));const r=new f(t.method,t.url,t.headers,n);r.headers={"Content-Type":"application/json"};const o=s.Sign(r);try{return(await e.request({url:t.url,method:t.method,headers:o.headers,data:n})).data}catch(t){this.logger.error("华为云接口请求出错:",t?.response?.data);const e=new Error(t?.response?.data.message);throw e.code=t?.response?.code,e}}};
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+ var axios = require('axios');
5
+
6
+ function hmacsha256(keyByte, message) {
7
+ return crypto
8
+ .createHmac('SHA256', keyByte)
9
+ .update(message)
10
+ .digest()
11
+ .toString('hex');
12
+ }
13
+ function HexEncodeSHA256Hash(body) {
14
+ return crypto.createHash('SHA256').update(body).digest().toString('hex');
15
+ }
16
+ const Algorithm = 'SDK-HMAC-SHA256';
17
+ const HeaderXDate = 'X-Sdk-Date';
18
+ const HeaderAuthorization = 'Authorization';
19
+ const HeaderContentSha256 = 'x-sdk-content-sha256';
20
+ const hexTable = new Array(256);
21
+ for (let i = 0; i < 256; ++i)
22
+ hexTable[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase();
23
+ const noEscape = [
24
+ 0,
25
+ 0,
26
+ 0,
27
+ 0,
28
+ 0,
29
+ 0,
30
+ 0,
31
+ 0,
32
+ 0,
33
+ 0,
34
+ 0,
35
+ 0,
36
+ 0,
37
+ 0,
38
+ 0,
39
+ 0,
40
+ 0,
41
+ 0,
42
+ 0,
43
+ 0,
44
+ 0,
45
+ 0,
46
+ 0,
47
+ 0,
48
+ 0,
49
+ 0,
50
+ 0,
51
+ 0,
52
+ 0,
53
+ 0,
54
+ 0,
55
+ 0,
56
+ 0,
57
+ 0,
58
+ 0,
59
+ 0,
60
+ 0,
61
+ 0,
62
+ 0,
63
+ 0,
64
+ 0,
65
+ 0,
66
+ 0,
67
+ 0,
68
+ 0,
69
+ 1,
70
+ 1,
71
+ 0,
72
+ 1,
73
+ 1,
74
+ 1,
75
+ 1,
76
+ 1,
77
+ 1,
78
+ 1,
79
+ 1,
80
+ 1,
81
+ 1,
82
+ 0,
83
+ 0,
84
+ 0,
85
+ 0,
86
+ 0,
87
+ 0,
88
+ 0,
89
+ 1,
90
+ 1,
91
+ 1,
92
+ 1,
93
+ 1,
94
+ 1,
95
+ 1,
96
+ 1,
97
+ 1,
98
+ 1,
99
+ 1,
100
+ 1,
101
+ 1,
102
+ 1,
103
+ 1,
104
+ 1,
105
+ 1,
106
+ 1,
107
+ 1,
108
+ 1,
109
+ 1,
110
+ 1,
111
+ 1,
112
+ 1,
113
+ 1,
114
+ 1,
115
+ 0,
116
+ 0,
117
+ 0,
118
+ 0,
119
+ 1,
120
+ 0,
121
+ 1,
122
+ 1,
123
+ 1,
124
+ 1,
125
+ 1,
126
+ 1,
127
+ 1,
128
+ 1,
129
+ 1,
130
+ 1,
131
+ 1,
132
+ 1,
133
+ 1,
134
+ 1,
135
+ 1,
136
+ 1,
137
+ 1,
138
+ 1,
139
+ 1,
140
+ 1,
141
+ 1,
142
+ 1,
143
+ 1,
144
+ 1,
145
+ 1,
146
+ 1,
147
+ 0,
148
+ 0,
149
+ 0,
150
+ 1,
151
+ 0, // 112 - 127
152
+ ];
153
+ // function urlEncode is based on https://github.com/nodejs/node/blob/master/lib/querystring.js
154
+ // Copyright Joyent, Inc. and other Node contributors.
155
+ function urlEncode(str) {
156
+ if (typeof str !== 'string') {
157
+ if (typeof str === 'object')
158
+ str = String(str);
159
+ else
160
+ str += '';
161
+ }
162
+ let out = '';
163
+ let lastPos = 0;
164
+ for (let i = 0; i < str.length; ++i) {
165
+ let c = str.charCodeAt(i);
166
+ // ASCII
167
+ if (c < 0x80) {
168
+ if (noEscape[c] === 1)
169
+ continue;
170
+ if (lastPos < i)
171
+ out += str.slice(lastPos, i);
172
+ lastPos = i + 1;
173
+ out += hexTable[c];
174
+ continue;
175
+ }
176
+ if (lastPos < i)
177
+ out += str.slice(lastPos, i);
178
+ // Multi-byte characters ...
179
+ if (c < 0x800) {
180
+ lastPos = i + 1;
181
+ out += hexTable[0xc0 | (c >> 6)] + hexTable[0x80 | (c & 0x3f)];
182
+ continue;
183
+ }
184
+ if (c < 0xd800 || c >= 0xe000) {
185
+ lastPos = i + 1;
186
+ out +=
187
+ hexTable[0xe0 | (c >> 12)] +
188
+ hexTable[0x80 | ((c >> 6) & 0x3f)] +
189
+ hexTable[0x80 | (c & 0x3f)];
190
+ continue;
191
+ }
192
+ // Surrogate pair
193
+ ++i;
194
+ if (i >= str.length)
195
+ throw new Error('ERR_INVALID_URI');
196
+ const c2 = str.charCodeAt(i) & 0x3ff;
197
+ lastPos = i + 1;
198
+ c = 0x10000 + (((c & 0x3ff) << 10) | c2);
199
+ out +=
200
+ hexTable[0xf0 | (c >> 18)] +
201
+ hexTable[0x80 | ((c >> 12) & 0x3f)] +
202
+ hexTable[0x80 | ((c >> 6) & 0x3f)] +
203
+ hexTable[0x80 | (c & 0x3f)];
204
+ }
205
+ if (lastPos === 0)
206
+ return str;
207
+ if (lastPos < str.length)
208
+ return out + str.slice(lastPos);
209
+ return out;
210
+ }
211
+ function findHeader(r, header) {
212
+ for (const k in r.headers) {
213
+ if (k.toLowerCase() === header.toLowerCase()) {
214
+ return r.headers[k];
215
+ }
216
+ }
217
+ return null;
218
+ }
219
+ // Build a CanonicalRequest from a regular request string
220
+ //
221
+ // CanonicalRequest =
222
+ // HTTPRequestMethod + '\n' +
223
+ // CanonicalURI + '\n' +
224
+ // CanonicalQueryString + '\n' +
225
+ // CanonicalHeaders + '\n' +
226
+ // SignedHeaders + '\n' +
227
+ // HexEncode(Hash(RequestPayload))
228
+ function CanonicalRequest(r, signedHeaders) {
229
+ let hexencode = findHeader(r, HeaderContentSha256);
230
+ if (hexencode === null) {
231
+ const data = RequestPayload(r);
232
+ hexencode = HexEncodeSHA256Hash(data);
233
+ }
234
+ return (r.method +
235
+ '\n' +
236
+ CanonicalURI(r) +
237
+ '\n' +
238
+ CanonicalQueryString(r) +
239
+ '\n' +
240
+ CanonicalHeaders(r, signedHeaders) +
241
+ '\n' +
242
+ signedHeaders.join(';') +
243
+ '\n' +
244
+ hexencode);
245
+ }
246
+ function CanonicalURI(r) {
247
+ const pattens = r.uri.split('/');
248
+ const uri = [];
249
+ for (const k in pattens) {
250
+ const v = pattens[k];
251
+ uri.push(urlEncode(v));
252
+ }
253
+ let urlpath = uri.join('/');
254
+ if (urlpath[urlpath.length - 1] !== '/') {
255
+ urlpath = urlpath + '/';
256
+ }
257
+ //r.uri = urlpath
258
+ return urlpath;
259
+ }
260
+ function CanonicalQueryString(r) {
261
+ const keys = [];
262
+ for (const key in r.query) {
263
+ keys.push(key);
264
+ }
265
+ keys.sort();
266
+ const a = [];
267
+ for (const i in keys) {
268
+ const key = urlEncode(keys[i]);
269
+ const value = r.query[keys[i]];
270
+ if (Array.isArray(value)) {
271
+ value.sort();
272
+ for (const iv in value) {
273
+ a.push(key + '=' + urlEncode(value[iv]));
274
+ }
275
+ }
276
+ else {
277
+ a.push(key + '=' + urlEncode(value));
278
+ }
279
+ }
280
+ return a.join('&');
281
+ }
282
+ function CanonicalHeaders(r, signedHeaders) {
283
+ const headers = {};
284
+ for (const key in r.headers) {
285
+ headers[key.toLowerCase()] = r.headers[key];
286
+ }
287
+ const a = [];
288
+ for (const i in signedHeaders) {
289
+ const value = headers[signedHeaders[i]];
290
+ a.push(signedHeaders[i] + ':' + value.trim());
291
+ }
292
+ return a.join('\n') + '\n';
293
+ }
294
+ function SignedHeaders(r) {
295
+ const a = [];
296
+ for (const key in r.headers) {
297
+ a.push(key.toLowerCase());
298
+ }
299
+ a.sort();
300
+ return a;
301
+ }
302
+ function RequestPayload(r) {
303
+ return r.body;
304
+ }
305
+ // Create a "String to Sign".
306
+ function StringToSign(canonicalRequest, t) {
307
+ const bytes = HexEncodeSHA256Hash(canonicalRequest);
308
+ return Algorithm + '\n' + t + '\n' + bytes;
309
+ }
310
+ // Create the HWS Signature.
311
+ function SignStringToSign(stringToSign, signingKey) {
312
+ return hmacsha256(signingKey, stringToSign);
313
+ }
314
+ // Get the finalized value for the "Authorization" header. The signature
315
+ // parameter is the output from SignStringToSign
316
+ function AuthHeaderValue(signature, Key, signedHeaders) {
317
+ return (Algorithm +
318
+ ' Access=' +
319
+ Key +
320
+ ', SignedHeaders=' +
321
+ signedHeaders.join(';') +
322
+ ', Signature=' +
323
+ signature);
324
+ }
325
+ function twoChar(s) {
326
+ if (s >= 10) {
327
+ return '' + s;
328
+ }
329
+ else {
330
+ return '0' + s;
331
+ }
332
+ }
333
+ function getTime() {
334
+ const date = new Date();
335
+ return ('' +
336
+ date.getUTCFullYear() +
337
+ twoChar(date.getUTCMonth() + 1) +
338
+ twoChar(date.getUTCDate()) +
339
+ 'T' +
340
+ twoChar(date.getUTCHours()) +
341
+ twoChar(date.getUTCMinutes()) +
342
+ twoChar(date.getUTCSeconds()) +
343
+ 'Z');
344
+ }
345
+ class SigHttpRequest {
346
+ method = '';
347
+ host = '';
348
+ uri = '';
349
+ query = {};
350
+ headers = {};
351
+ body = '';
352
+ constructor(method, url, headers, body) {
353
+ if (method === undefined) {
354
+ this.method = '';
355
+ }
356
+ else {
357
+ this.method = method;
358
+ }
359
+ if (url === undefined) {
360
+ this.host = '';
361
+ this.uri = '';
362
+ this.query = {};
363
+ }
364
+ else {
365
+ this.query = {};
366
+ let host, path;
367
+ let i = url.indexOf('://');
368
+ if (i !== -1) {
369
+ url = url.substr(i + 3);
370
+ }
371
+ i = url.indexOf('?');
372
+ if (i !== -1) {
373
+ const query_str = url.substr(i + 1);
374
+ url = url.substr(0, i);
375
+ const spl = query_str.split('&');
376
+ for (const i in spl) {
377
+ const kv = spl[i];
378
+ const index = kv.indexOf('=');
379
+ let key, value;
380
+ if (index >= 0) {
381
+ key = kv.substr(0, index);
382
+ value = kv.substr(index + 1);
383
+ }
384
+ else {
385
+ key = kv;
386
+ value = '';
387
+ }
388
+ if (key !== '') {
389
+ key = decodeURI(key);
390
+ value = decodeURI(value);
391
+ if (this.query[key] === undefined) {
392
+ this.query[key] = [value];
393
+ }
394
+ else {
395
+ this.query[key].push(value);
396
+ }
397
+ }
398
+ }
399
+ }
400
+ i = url.indexOf('/');
401
+ if (i === -1) {
402
+ host = url;
403
+ path = '/';
404
+ }
405
+ else {
406
+ host = url.substr(0, i);
407
+ path = url.substr(i);
408
+ }
409
+ this.host = host;
410
+ this.uri = decodeURI(path);
411
+ }
412
+ if (headers === undefined) {
413
+ this.headers = {};
414
+ }
415
+ else {
416
+ this.headers = headers;
417
+ }
418
+ if (body === undefined) {
419
+ this.body = '';
420
+ }
421
+ else {
422
+ this.body = body;
423
+ }
424
+ }
425
+ }
426
+ class Signer {
427
+ Key = '';
428
+ Secret = '';
429
+ constructor(Key, Secret) {
430
+ this.Key = Key;
431
+ this.Secret = Secret;
432
+ }
433
+ Sign(r) {
434
+ let headerTime = findHeader(r, HeaderXDate);
435
+ if (headerTime === null) {
436
+ headerTime = getTime();
437
+ r.headers[HeaderXDate] = headerTime;
438
+ }
439
+ if (r.method !== 'PUT' && r.method !== 'PATCH' && r.method !== 'POST') {
440
+ r.body = '';
441
+ }
442
+ let queryString = CanonicalQueryString(r);
443
+ if (queryString !== '') {
444
+ queryString = '?' + queryString;
445
+ }
446
+ const options = {
447
+ hostname: r.host,
448
+ path: encodeURI(r.uri) + queryString,
449
+ method: r.method,
450
+ headers: r.headers,
451
+ };
452
+ if (findHeader(r, 'host') === null) {
453
+ r.headers.host = r.host;
454
+ }
455
+ const signedHeaders = SignedHeaders(r);
456
+ const canonicalRequest = CanonicalRequest(r, signedHeaders);
457
+ const stringToSign = StringToSign(canonicalRequest, headerTime);
458
+ const signature = SignStringToSign(stringToSign, this.Secret);
459
+ options.headers[HeaderAuthorization] = AuthHeaderValue(signature, this.Key, signedHeaders);
460
+ return options;
461
+ }
462
+ }
463
+
464
+ class HuaweiYunClient {
465
+ access;
466
+ logger;
467
+ constructor(access, logger) {
468
+ this.access = access;
469
+ this.logger = logger;
470
+ }
471
+ async request(options) {
472
+ const sig = new Signer(this.access.accessKeyId, this.access.accessKeySecret);
473
+ //The following example shows how to set the request URL and parameters to query a VPC list.
474
+ //Specify a request method, such as GET, PUT, POST, DELETE, HEAD, and PATCH.
475
+ //Set request host.
476
+ //Set request URI.
477
+ //Set parameters for the request URL.
478
+ let body = undefined;
479
+ if (options.data) {
480
+ body = JSON.stringify(options.data);
481
+ }
482
+ const r = new SigHttpRequest(options.method, options.url, options.headers, body);
483
+ //Add header parameters, for example, x-domain-id for invoking a global service and x-project-id for invoking a project-level service.
484
+ r.headers = { "Content-Type": "application/json" };
485
+ //Add a body if you have specified the PUT or POST method. Special characters, such as the double quotation mark ("), contained in the body must be escaped.
486
+ // r.body = option;
487
+ const opt = sig.Sign(r);
488
+ try {
489
+ const res = await axios.request({
490
+ url: options.url,
491
+ method: options.method,
492
+ headers: opt.headers,
493
+ data: body,
494
+ });
495
+ return res.data;
496
+ } catch (e) {
497
+ this.logger.error("华为云接口请求出错:", e?.response?.data);
498
+ const error = new Error(JSON.stringify(e?.response?.data));
499
+ error.code = e?.response?.code;
500
+ throw error;
501
+ }
502
+ }
503
+ }
504
+
505
+ exports.HuaweiYunClient = HuaweiYunClient;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@certd/lib-huawei",
3
3
  "private": false,
4
- "version": "1.31.9",
4
+ "version": "1.31.11",
5
5
  "main": "./dist/bundle.js",
6
6
  "module": "./dist/bundle.js",
7
7
  "types": "./dist/d/index.d.ts",
@@ -23,5 +23,5 @@
23
23
  "prettier": "^2.8.8",
24
24
  "tslib": "^2.8.1"
25
25
  },
26
- "gitHead": "be58e3084bbcd86d9fcd10950aadf542191a6949"
26
+ "gitHead": "8374c3941a9d1398989b8f38fd4bfa2a2f29937b"
27
27
  }
package/rollup.config.js CHANGED
@@ -30,7 +30,7 @@ module.exports = {
30
30
  allowSyntheticDefaultImports: true,
31
31
  }),
32
32
  json(),
33
- terser(),
33
+ // terser(),
34
34
  ],
35
35
  external: ["vue", "lodash-es", "dayjs", "log4js", "@midwayjs/core", "@certd/pipeline", "axios"],
36
36
  };