@yxw007/translate 0.0.5 → 0.0.6

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.
@@ -1,4 +1,4 @@
1
- // translate v0.0.5 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
1
+ // translate v0.0.6 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
2
2
  import { Buffer as Buffer$1 } from 'buffer';
3
3
  import { Readable, Writable } from 'stream';
4
4
  import { Agent, request as request$1 } from 'http';
@@ -66,7 +66,11 @@ function azure(options) {
66
66
  },
67
67
  body: JSON.stringify(text.map((it) => ({ Text: it }))),
68
68
  });
69
- const body = await res.json();
69
+ const bodyRes = await res.json();
70
+ if (bodyRes.error) {
71
+ throw new Error(`Translate fail ! code: ${bodyRes.error.code}, message: ${bodyRes.error.message}`);
72
+ }
73
+ const body = bodyRes;
70
74
  if (!body || body.length === 0) {
71
75
  throw new Error("Translate fail ! translate's result is null or empty");
72
76
  }
@@ -7271,7 +7275,7 @@ const commonParams$3 = {
7271
7275
 
7272
7276
  var name$3 = "@aws-sdk/client-translate";
7273
7277
  var description$3 = "AWS SDK for JavaScript Translate Client for Node.js, Browser and React Native";
7274
- var version$3 = "3.649.0";
7278
+ var version$3 = "3.651.1";
7275
7279
  var scripts$3 = {
7276
7280
  build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
7277
7281
  "build:cjs": "node ../../scripts/compilation/inline client-translate",
@@ -7290,10 +7294,10 @@ var sideEffects$3 = false;
7290
7294
  var dependencies$3 = {
7291
7295
  "@aws-crypto/sha256-browser": "5.2.0",
7292
7296
  "@aws-crypto/sha256-js": "5.2.0",
7293
- "@aws-sdk/client-sso-oidc": "3.649.0",
7294
- "@aws-sdk/client-sts": "3.649.0",
7295
- "@aws-sdk/core": "3.649.0",
7296
- "@aws-sdk/credential-provider-node": "3.649.0",
7297
+ "@aws-sdk/client-sso-oidc": "3.651.1",
7298
+ "@aws-sdk/client-sts": "3.651.1",
7299
+ "@aws-sdk/core": "3.651.1",
7300
+ "@aws-sdk/credential-provider-node": "3.651.1",
7297
7301
  "@aws-sdk/middleware-host-header": "3.649.0",
7298
7302
  "@aws-sdk/middleware-logger": "3.649.0",
7299
7303
  "@aws-sdk/middleware-recursion-detection": "3.649.0",
@@ -7605,11 +7609,15 @@ const a$3 = true, b$3 = "isSet", c$3 = "booleanEquals", d$3 = "error", e$3 = "en
7605
7609
  const _data$3 = { version: "1.0", parameters: { Region: h$3, UseDualStack: i$3, UseFIPS: i$3, Endpoint: h$3 }, rules: [{ conditions: [{ [t$3]: b$3, [u$3]: [j$3] }], rules: [{ conditions: p$3, error: "Invalid Configuration: FIPS and custom endpoint are not supported", type: d$3 }, { conditions: q$3, error: "Invalid Configuration: Dualstack and custom endpoint are not supported", type: d$3 }, { endpoint: { url: j$3, properties: m$3, headers: m$3 }, type: e$3 }], type: f$3 }, { conditions: [{ [t$3]: b$3, [u$3]: r$3 }], rules: [{ conditions: [{ [t$3]: "aws.partition", [u$3]: r$3, assign: g$3 }], rules: [{ conditions: [k$3, l$3], rules: [{ conditions: [{ [t$3]: c$3, [u$3]: [a$3, n$3] }, o$3], rules: [{ endpoint: { url: "https://translate-fips.{Region}.{PartitionResult#dualStackDnsSuffix}", properties: m$3, headers: m$3 }, type: e$3 }], type: f$3 }, { error: "FIPS and DualStack are enabled, but this partition does not support one or both", type: d$3 }], type: f$3 }, { conditions: p$3, rules: [{ conditions: [{ [t$3]: c$3, [u$3]: [n$3, a$3] }], rules: [{ endpoint: { url: "https://translate-fips.{Region}.{PartitionResult#dnsSuffix}", properties: m$3, headers: m$3 }, type: e$3 }], type: f$3 }, { error: "FIPS is enabled but this partition does not support FIPS", type: d$3 }], type: f$3 }, { conditions: q$3, rules: [{ conditions: [o$3], rules: [{ endpoint: { url: "https://translate.{Region}.{PartitionResult#dualStackDnsSuffix}", properties: m$3, headers: m$3 }, type: e$3 }], type: f$3 }, { error: "DualStack is enabled but this partition does not support DualStack", type: d$3 }], type: f$3 }, { endpoint: { url: "https://translate.{Region}.{PartitionResult#dnsSuffix}", properties: m$3, headers: m$3 }, type: e$3 }], type: f$3 }], type: f$3 }, { error: "Invalid Configuration: Missing Region", type: d$3 }] };
7606
7610
  const ruleSet$3 = _data$3;
7607
7611
 
7612
+ const cache$4 = new EndpointCache({
7613
+ size: 50,
7614
+ params: ["Endpoint", "Region", "UseDualStack", "UseFIPS"],
7615
+ });
7608
7616
  const defaultEndpointResolver$3 = (endpointParams, context = {}) => {
7609
- return resolveEndpoint(ruleSet$3, {
7617
+ return cache$4.get(endpointParams, () => resolveEndpoint(ruleSet$3, {
7610
7618
  endpointParams: endpointParams,
7611
7619
  logger: context.logger,
7612
- });
7620
+ }));
7613
7621
  };
7614
7622
  customEndpointFunctions.aws = awsEndpointFunctions;
7615
7623
 
@@ -8302,9 +8310,7 @@ function sharedHeaders(operation) {
8302
8310
 
8303
8311
  class TranslateTextCommand extends Command
8304
8312
  .classBuilder()
8305
- .ep({
8306
- ...commonParams$3,
8307
- })
8313
+ .ep(commonParams$3)
8308
8314
  .m(function (Command, cs, config, o) {
8309
8315
  return [
8310
8316
  getSerdePlugin(config, this.serialize, this.deserialize),
@@ -9996,7 +10002,7 @@ function useLogger(name = "") {
9996
10002
  }
9997
10003
 
9998
10004
  const logger = useLogger();
9999
- const cache$2 = new Cache();
10005
+ const cache$3 = new Cache();
10000
10006
  class Translator {
10001
10007
  engines;
10002
10008
  constructor() {
@@ -10027,15 +10033,15 @@ class Translator {
10027
10033
  }
10028
10034
  const key = `${from}:${to}:${engine}:${text}`;
10029
10035
  //3. If the cache is matched, the cache is used directly
10030
- if (cache$2.get(key)) {
10031
- return cache$2.get(key)?.value;
10036
+ if (cache$3.get(key)) {
10037
+ return Promise.resolve(cache$3.get(key)?.value);
10032
10038
  }
10033
10039
  const engineInstance = this.engines.get(engine);
10034
10040
  if (!engineInstance) {
10035
10041
  throw new Error(`Engine ${engine} not found`);
10036
10042
  }
10037
10043
  return engineInstance.translate(text, options).then((translated) => {
10038
- cache$2.set(key, translated, cache_time);
10044
+ cache$3.set(key, translated, cache_time);
10039
10045
  return translated;
10040
10046
  });
10041
10047
  }
@@ -10925,33 +10931,35 @@ const resolveAssumeRoleCredentials = async (profileName, profiles, options, visi
10925
10931
  }
10926
10932
  options.logger?.debug(`@aws-sdk/credential-provider-ini - finding credential resolver using ${source_profile ? `source_profile=[${source_profile}]` : `profile=[${profileName}]`}`);
10927
10933
  const sourceCredsProvider = source_profile
10928
- ? resolveProfileData(source_profile, {
10929
- ...profiles,
10930
- [source_profile]: {
10931
- ...profiles[source_profile],
10932
- role_arn: data.role_arn ?? profiles[source_profile].role_arn,
10933
- },
10934
- }, options, {
10934
+ ? resolveProfileData(source_profile, profiles, options, {
10935
10935
  ...visitedProfiles,
10936
10936
  [source_profile]: true,
10937
- })
10937
+ }, isCredentialSourceWithoutRoleArn(profiles[source_profile] ?? {}))
10938
10938
  : (await resolveCredentialSource(data.credential_source, profileName, options.logger)(options))();
10939
- const params = {
10940
- RoleArn: data.role_arn,
10941
- RoleSessionName: data.role_session_name || `aws-sdk-js-${Date.now()}`,
10942
- ExternalId: data.external_id,
10943
- DurationSeconds: parseInt(data.duration_seconds || "3600", 10),
10944
- };
10945
- const { mfa_serial } = data;
10946
- if (mfa_serial) {
10947
- if (!options.mfaCodeProvider) {
10948
- throw new CredentialsProviderError(`Profile ${profileName} requires multi-factor authentication, but no MFA code callback was provided.`, { logger: options.logger, tryNextLink: false });
10939
+ if (isCredentialSourceWithoutRoleArn(data)) {
10940
+ return sourceCredsProvider;
10941
+ }
10942
+ else {
10943
+ const params = {
10944
+ RoleArn: data.role_arn,
10945
+ RoleSessionName: data.role_session_name || `aws-sdk-js-${Date.now()}`,
10946
+ ExternalId: data.external_id,
10947
+ DurationSeconds: parseInt(data.duration_seconds || "3600", 10),
10948
+ };
10949
+ const { mfa_serial } = data;
10950
+ if (mfa_serial) {
10951
+ if (!options.mfaCodeProvider) {
10952
+ throw new CredentialsProviderError(`Profile ${profileName} requires multi-factor authentication, but no MFA code callback was provided.`, { logger: options.logger, tryNextLink: false });
10953
+ }
10954
+ params.SerialNumber = mfa_serial;
10955
+ params.TokenCode = await options.mfaCodeProvider(mfa_serial);
10949
10956
  }
10950
- params.SerialNumber = mfa_serial;
10951
- params.TokenCode = await options.mfaCodeProvider(mfa_serial);
10957
+ const sourceCreds = await sourceCredsProvider;
10958
+ return options.roleAssumer(sourceCreds, params);
10952
10959
  }
10953
- const sourceCreds = await sourceCredsProvider;
10954
- return options.roleAssumer(sourceCreds, params);
10960
+ };
10961
+ const isCredentialSourceWithoutRoleArn = (section) => {
10962
+ return !section.role_arn && !!section.credential_source;
10955
10963
  };
10956
10964
 
10957
10965
  const isProcessProfile = (arg) => Boolean(arg) && typeof arg === "object" && typeof arg.credential_process === "string";
@@ -11005,12 +11013,12 @@ const resolveWebIdentityCredentials = async (profile, options) => Promise.resolv
11005
11013
  parentClientConfig: options.parentClientConfig,
11006
11014
  })());
11007
11015
 
11008
- const resolveProfileData = async (profileName, profiles, options, visitedProfiles = {}) => {
11016
+ const resolveProfileData = async (profileName, profiles, options, visitedProfiles = {}, isAssumeRoleRecursiveCall = false) => {
11009
11017
  const data = profiles[profileName];
11010
11018
  if (Object.keys(visitedProfiles).length > 0 && isStaticCredsProfile(data)) {
11011
11019
  return resolveStaticCredentials(data, options);
11012
11020
  }
11013
- if (isAssumeRoleProfile(data, { profile: profileName, logger: options.logger })) {
11021
+ if (isAssumeRoleRecursiveCall || isAssumeRoleProfile(data, { profile: profileName, logger: options.logger })) {
11014
11022
  return resolveAssumeRoleCredentials(profileName, profiles, options, visitedProfiles);
11015
11023
  }
11016
11024
  if (isStaticCredsProfile(data)) {
@@ -11234,7 +11242,7 @@ const commonParams$2 = {
11234
11242
 
11235
11243
  var name$2 = "@aws-sdk/client-sso-oidc";
11236
11244
  var description$2 = "AWS SDK for JavaScript Sso Oidc Client for Node.js, Browser and React Native";
11237
- var version$2 = "3.649.0";
11245
+ var version$2 = "3.651.1";
11238
11246
  var scripts$2 = {
11239
11247
  build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
11240
11248
  "build:cjs": "node ../../scripts/compilation/inline client-sso-oidc",
@@ -11253,8 +11261,8 @@ var sideEffects$2 = false;
11253
11261
  var dependencies$2 = {
11254
11262
  "@aws-crypto/sha256-browser": "5.2.0",
11255
11263
  "@aws-crypto/sha256-js": "5.2.0",
11256
- "@aws-sdk/core": "3.649.0",
11257
- "@aws-sdk/credential-provider-node": "3.649.0",
11264
+ "@aws-sdk/core": "3.651.1",
11265
+ "@aws-sdk/credential-provider-node": "3.651.1",
11258
11266
  "@aws-sdk/middleware-host-header": "3.649.0",
11259
11267
  "@aws-sdk/middleware-logger": "3.649.0",
11260
11268
  "@aws-sdk/middleware-recursion-detection": "3.649.0",
@@ -11318,7 +11326,7 @@ var author$2 = {
11318
11326
  };
11319
11327
  var license$2 = "Apache-2.0";
11320
11328
  var peerDependencies = {
11321
- "@aws-sdk/client-sts": "^3.649.0"
11329
+ "@aws-sdk/client-sts": "^3.651.1"
11322
11330
  };
11323
11331
  var browser$2 = {
11324
11332
  "./dist-es/runtimeConfig": "./dist-es/runtimeConfig.browser"
@@ -11359,11 +11367,15 @@ const a$2 = true, b$2 = "isSet", c$2 = "booleanEquals", d$2 = "error", e$2 = "en
11359
11367
  const _data$2 = { version: "1.0", parameters: { Region: i$2, UseDualStack: j$2, UseFIPS: j$2, Endpoint: i$2 }, rules: [{ conditions: [{ [v$2]: b$2, [w$2]: [k$2] }], rules: [{ conditions: r$2, error: "Invalid Configuration: FIPS and custom endpoint are not supported", type: d$2 }, { conditions: s$2, error: "Invalid Configuration: Dualstack and custom endpoint are not supported", type: d$2 }, { endpoint: { url: k$2, properties: n$2, headers: n$2 }, type: e$2 }], type: f$2 }, { conditions: [{ [v$2]: b$2, [w$2]: t$2 }], rules: [{ conditions: [{ [v$2]: "aws.partition", [w$2]: t$2, assign: g$2 }], rules: [{ conditions: [l$2, m$2], rules: [{ conditions: [{ [v$2]: c$2, [w$2]: [a$2, o$2] }, q$2], rules: [{ endpoint: { url: "https://oidc-fips.{Region}.{PartitionResult#dualStackDnsSuffix}", properties: n$2, headers: n$2 }, type: e$2 }], type: f$2 }, { error: "FIPS and DualStack are enabled, but this partition does not support one or both", type: d$2 }], type: f$2 }, { conditions: r$2, rules: [{ conditions: [{ [v$2]: c$2, [w$2]: [o$2, a$2] }], rules: [{ conditions: [{ [v$2]: "stringEquals", [w$2]: [{ [v$2]: h$2, [w$2]: [p$2, "name"] }, "aws-us-gov"] }], endpoint: { url: "https://oidc.{Region}.amazonaws.com", properties: n$2, headers: n$2 }, type: e$2 }, { endpoint: { url: "https://oidc-fips.{Region}.{PartitionResult#dnsSuffix}", properties: n$2, headers: n$2 }, type: e$2 }], type: f$2 }, { error: "FIPS is enabled but this partition does not support FIPS", type: d$2 }], type: f$2 }, { conditions: s$2, rules: [{ conditions: [q$2], rules: [{ endpoint: { url: "https://oidc.{Region}.{PartitionResult#dualStackDnsSuffix}", properties: n$2, headers: n$2 }, type: e$2 }], type: f$2 }, { error: "DualStack is enabled but this partition does not support DualStack", type: d$2 }], type: f$2 }, { endpoint: { url: "https://oidc.{Region}.{PartitionResult#dnsSuffix}", properties: n$2, headers: n$2 }, type: e$2 }], type: f$2 }], type: f$2 }, { error: "Invalid Configuration: Missing Region", type: d$2 }] };
11360
11368
  const ruleSet$2 = _data$2;
11361
11369
 
11370
+ const cache$2 = new EndpointCache({
11371
+ size: 50,
11372
+ params: ["Endpoint", "Region", "UseDualStack", "UseFIPS"],
11373
+ });
11362
11374
  const defaultEndpointResolver$2 = (endpointParams, context = {}) => {
11363
- return resolveEndpoint(ruleSet$2, {
11375
+ return cache$2.get(endpointParams, () => resolveEndpoint(ruleSet$2, {
11364
11376
  endpointParams: endpointParams,
11365
11377
  logger: context.logger,
11366
- });
11378
+ }));
11367
11379
  };
11368
11380
  customEndpointFunctions.aws = awsEndpointFunctions;
11369
11381
 
@@ -12038,9 +12050,7 @@ const deserializeMetadata$2 = (output) => ({
12038
12050
 
12039
12051
  class CreateTokenCommand extends Command
12040
12052
  .classBuilder()
12041
- .ep({
12042
- ...commonParams$2,
12043
- })
12053
+ .ep(commonParams$2)
12044
12054
  .m(function (Command, cs, config, o) {
12045
12055
  return [
12046
12056
  getSerdePlugin(config, this.serialize, this.deserialize),
@@ -12158,7 +12168,7 @@ const commonParams$1 = {
12158
12168
 
12159
12169
  var name$1 = "@aws-sdk/client-sso";
12160
12170
  var description$1 = "AWS SDK for JavaScript Sso Client for Node.js, Browser and React Native";
12161
- var version$1 = "3.649.0";
12171
+ var version$1 = "3.651.1";
12162
12172
  var scripts$1 = {
12163
12173
  build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
12164
12174
  "build:cjs": "node ../../scripts/compilation/inline client-sso",
@@ -12177,7 +12187,7 @@ var sideEffects$1 = false;
12177
12187
  var dependencies$1 = {
12178
12188
  "@aws-crypto/sha256-browser": "5.2.0",
12179
12189
  "@aws-crypto/sha256-js": "5.2.0",
12180
- "@aws-sdk/core": "3.649.0",
12190
+ "@aws-sdk/core": "3.651.1",
12181
12191
  "@aws-sdk/middleware-host-header": "3.649.0",
12182
12192
  "@aws-sdk/middleware-logger": "3.649.0",
12183
12193
  "@aws-sdk/middleware-recursion-detection": "3.649.0",
@@ -12635,9 +12645,7 @@ const _xasbt = "x-amz-sso_bearer_token";
12635
12645
 
12636
12646
  class GetRoleCredentialsCommand extends Command
12637
12647
  .classBuilder()
12638
- .ep({
12639
- ...commonParams$1,
12640
- })
12648
+ .ep(commonParams$1)
12641
12649
  .m(function (Command, cs, config, o) {
12642
12650
  return [
12643
12651
  getSerdePlugin(config, this.serialize, this.deserialize),
@@ -12735,7 +12743,7 @@ const commonParams = {
12735
12743
 
12736
12744
  var name = "@aws-sdk/client-sts";
12737
12745
  var description = "AWS SDK for JavaScript Sts Client for Node.js, Browser and React Native";
12738
- var version = "3.649.0";
12746
+ var version = "3.651.1";
12739
12747
  var scripts = {
12740
12748
  build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
12741
12749
  "build:cjs": "node ../../scripts/compilation/inline client-sts",
@@ -12756,9 +12764,9 @@ var sideEffects = false;
12756
12764
  var dependencies = {
12757
12765
  "@aws-crypto/sha256-browser": "5.2.0",
12758
12766
  "@aws-crypto/sha256-js": "5.2.0",
12759
- "@aws-sdk/client-sso-oidc": "3.649.0",
12760
- "@aws-sdk/core": "3.649.0",
12761
- "@aws-sdk/credential-provider-node": "3.649.0",
12767
+ "@aws-sdk/client-sso-oidc": "3.651.1",
12768
+ "@aws-sdk/core": "3.651.1",
12769
+ "@aws-sdk/credential-provider-node": "3.651.1",
12762
12770
  "@aws-sdk/middleware-host-header": "3.649.0",
12763
12771
  "@aws-sdk/middleware-logger": "3.649.0",
12764
12772
  "@aws-sdk/middleware-recursion-detection": "3.649.0",
@@ -13693,9 +13701,7 @@ const loadQueryErrorCode = (output, data) => {
13693
13701
 
13694
13702
  class AssumeRoleCommand extends Command
13695
13703
  .classBuilder()
13696
- .ep({
13697
- ...commonParams,
13698
- })
13704
+ .ep(commonParams)
13699
13705
  .m(function (Command, cs, config, o) {
13700
13706
  return [
13701
13707
  getSerdePlugin(config, this.serialize, this.deserialize),
@@ -13712,9 +13718,7 @@ class AssumeRoleCommand extends Command
13712
13718
 
13713
13719
  class AssumeRoleWithWebIdentityCommand extends Command
13714
13720
  .classBuilder()
13715
- .ep({
13716
- ...commonParams,
13717
- })
13721
+ .ep(commonParams)
13718
13722
  .m(function (Command, cs, config, o) {
13719
13723
  return [
13720
13724
  getSerdePlugin(config, this.serialize, this.deserialize),