@cloud-idaas/akless-alibabacloud-adapter 0.1.0-beta.2 → 0.1.0-beta.4
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 +11 -1
- package/README.md +6 -2
- package/README_zh.md +6 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/dist/sdk-version.d.ts +1 -0
- package/dist/sdk-version.js +6 -0
- package/dist/sdk-version.js.map +1 -0
- package/examples/initialize.cjs +2 -0
- package/examples/initialize.mjs +2 -0
- package/examples/initialize.ts +2 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.1.0-beta.
|
|
3
|
+
## 0.1.0-beta.4
|
|
4
|
+
|
|
5
|
+
- Support optional STS session duration in seconds. Omit it to keep the PAM default.
|
|
6
|
+
|
|
7
|
+
## 0.1.0-beta.3
|
|
8
|
+
|
|
9
|
+
- Include this adapter repository name and build version in PAM STS User-Agent headers.
|
|
10
|
+
- Defer Alibaba Cloud credentials loading until client creation.
|
|
11
|
+
- Use Core SDK and PAM SDK 0.1.0-beta.3.
|
|
12
|
+
|
|
13
|
+
## 0.1.0-beta.2
|
|
4
14
|
|
|
5
15
|
- Publish a maintenance prerelease with no API changes.
|
|
6
16
|
|
package/README.md
CHANGED
|
@@ -9,11 +9,13 @@ Use IDaaS PAM temporary credentials with Alibaba Cloud OpenAPI, OSS, and SLS cli
|
|
|
9
9
|
Supports Node.js 20, 22, and 24, JavaScript CommonJS/ESM, and TypeScript 4.7 or later. This is a Node.js SDK, not a browser SDK. Check your registry for available beta versions; use a provided package archive when evaluating an unreleased version.
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npm install @cloud-idaas/core-sdk @cloud-idaas/akless-alibabacloud-adapter
|
|
12
|
+
npm install @cloud-idaas/core-sdk@0.1.0-beta.4 @cloud-idaas/akless-alibabacloud-adapter@0.1.0-beta.4
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
|
+
The Factory accepts an optional integer `durationSeconds` from 900 to 43200. Omit it to use the PAM default. The target role can impose a lower maximum. Alibaba Cloud enforces the RAM role’s `MaxSessionDuration`. For the default, call `createAlibabaCloudCredentialsProvider(roleId)`.
|
|
18
|
+
|
|
17
19
|
Configure Core using CLOUD_IDAAS_CONFIG_PATH or ~/.cloud_idaas/client-config.json. Provide developerApiEndpoint and an identity authorized for PAM access. Replace example identifiers with your settings. Save the following ESM example as `example.mjs` and run it with Node.js. CommonJS uses the same named exports through `require`; asynchronous calls belong inside an async function.
|
|
18
20
|
|
|
19
21
|
```javascript
|
|
@@ -22,7 +24,9 @@ import { createAlibabaCloudCredentialsProvider } from '@cloud-idaas/akless-aliba
|
|
|
22
24
|
|
|
23
25
|
await IDaaSCredentialProviderFactory.init();
|
|
24
26
|
try {
|
|
25
|
-
const credentials = createAlibabaCloudCredentialsProvider('role-external-id'
|
|
27
|
+
const credentials = createAlibabaCloudCredentialsProvider('role-external-id', {
|
|
28
|
+
durationSeconds: 1800,
|
|
29
|
+
});
|
|
26
30
|
try {
|
|
27
31
|
const officialCredential = credentials.toAlibabaCloudCredential();
|
|
28
32
|
await officialCredential.getCredential();
|
package/README_zh.md
CHANGED
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
支持 Node.js 20、22、24,JavaScript CommonJS/ESM 以及 TypeScript 4.7 及以上版本。本 SDK 用于 Node.js,不用于浏览器。请以 npm registry 中的实际可用版本为准;评估尚未发布的版本时,使用提供的安装包归档。
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npm install @cloud-idaas/core-sdk @cloud-idaas/akless-alibabacloud-adapter
|
|
12
|
+
npm install @cloud-idaas/core-sdk@0.1.0-beta.4 @cloud-idaas/akless-alibabacloud-adapter@0.1.0-beta.4
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## 使用
|
|
16
16
|
|
|
17
|
+
Factory 的 `durationSeconds` 接受 900–43200 的整数秒数。省略时由 PAM 决定有效期,实际可请求的上限取决于目标角色。阿里云使用 RAM 角色的 `MaxSessionDuration`。 使用默认值时调用 `createAlibabaCloudCredentialsProvider(roleId)`。
|
|
18
|
+
|
|
17
19
|
通过 CLOUD_IDAAS_CONFIG_PATH 或 ~/.cloud_idaas/client-config.json 配置 Core,提供 developerApiEndpoint 及已获 PAM 访问授权的身份,并替换示例标识。 将以下 ESM 示例保存为 `example.mjs`,通过 Node.js 运行。CommonJS 使用相同的具名导出和 `require`,异步调用放在 async 函数中。
|
|
18
20
|
|
|
19
21
|
```javascript
|
|
@@ -22,7 +24,9 @@ import { createAlibabaCloudCredentialsProvider } from '@cloud-idaas/akless-aliba
|
|
|
22
24
|
|
|
23
25
|
await IDaaSCredentialProviderFactory.init();
|
|
24
26
|
try {
|
|
25
|
-
const credentials = createAlibabaCloudCredentialsProvider('role-external-id'
|
|
27
|
+
const credentials = createAlibabaCloudCredentialsProvider('role-external-id', {
|
|
28
|
+
durationSeconds: 1800,
|
|
29
|
+
});
|
|
26
30
|
try {
|
|
27
31
|
const officialCredential = credentials.toAlibabaCloudCredential();
|
|
28
32
|
await officialCredential.getCredential();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Credential from '@alicloud/credentials';
|
|
1
|
+
import type Credential from '@alicloud/credentials';
|
|
2
2
|
import { type AklessProviderOptions, AklessProviderBuilder, CachedCloudCredentialProvider, type ExpiringCredential } from '@cloud-idaas/pam-client-sdk';
|
|
3
3
|
/** Alibaba Cloud STS snapshot; inherited expiration is ISO 8601. Never log secret fields. */
|
|
4
4
|
export interface AlibabaSessionCredentials extends ExpiringCredential {
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.IDaaSPamAklessCredentialFactory = exports.IDaaSPamAlibabaCloudCredentialsProvider = void 0;
|
|
7
4
|
exports.createAlibabaCloudCredentialsProvider = createAlibabaCloudCredentialsProvider;
|
|
8
|
-
const credentials_1 = __importDefault(require("@alicloud/credentials"));
|
|
9
5
|
const core_sdk_1 = require("@cloud-idaas/core-sdk");
|
|
10
6
|
const pam_client_sdk_1 = require("@cloud-idaas/pam-client-sdk");
|
|
7
|
+
const sdk_version_1 = require("./sdk-version");
|
|
11
8
|
/**
|
|
12
9
|
* Retrieves Alibaba Cloud STS through PAM for Credentials, SLS, and OSS integrations.
|
|
13
10
|
* @remarks Supports Node.js 20/22/24; interfaces checked against @alicloud/credentials 2.4.7, ali-oss 6.23.0,
|
|
@@ -39,7 +36,7 @@ class IDaaSPamAlibabaCloudCredentialsProvider extends pam_client_sdk_1.CachedClo
|
|
|
39
36
|
expiration: new Date((0, pam_client_sdk_1.credentialExpiration)(response, token.expiration)).toISOString(),
|
|
40
37
|
providerName: 'idaas_pam',
|
|
41
38
|
};
|
|
42
|
-
});
|
|
39
|
+
}, `idaas-typescript-akless-alibabacloud-adapter/${sdk_version_1.SDK_VERSION}`);
|
|
43
40
|
}
|
|
44
41
|
/** @returns The stable source identifier idaas_pam used by the official Credentials Provider protocol. */
|
|
45
42
|
getProviderName() {
|
|
@@ -50,7 +47,8 @@ class IDaaSPamAlibabaCloudCredentialsProvider extends pam_client_sdk_1.CachedClo
|
|
|
50
47
|
* @returns An official Credential instance sharing the IDaaS cache; callers must still close this provider.
|
|
51
48
|
*/
|
|
52
49
|
toAlibabaCloudCredential() {
|
|
53
|
-
|
|
50
|
+
const CredentialConstructor = require('@alicloud/credentials').default;
|
|
51
|
+
return new CredentialConstructor(null, this);
|
|
54
52
|
}
|
|
55
53
|
/**
|
|
56
54
|
* Retrieves a credential snapshot and an asynchronous refresh callback for ali-oss initialization.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAwHA,sFASC;AAjID,wEAA+C;AAC/C,oDAA4D;AAC5D,gEAOqC;AA2BrC;;;;;GAKG;AACH,MAAa,uCAAwC,SAAQ,8CAAwD;IACnH;;;OAGG;IACH,MAAM,CAAC,OAAO;QACZ,OAAO,IAAI,sCAAqB,CAC9B,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,uCAAuC,CAAC,OAAO,CAAC,CAClE,CAAC;IACJ,CAAC;IACD;;;;OAIG;IACH,YAAY,OAA8B;QACxC,KAAK,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE;YAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,oBAAoB,CAAC;YAC5C,IAAI,CAAC,KAAK;gBACR,MAAM,IAAI,8BAAmB,CAC3B,0CAA0C,EAC1C,2BAA2B,CAC5B,CAAC;YACJ,OAAO;gBACL,WAAW,EAAE,IAAA,iCAAgB,EAAC,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC;gBAC/D,eAAe,EAAE,IAAA,iCAAgB,EAAC,KAAK,CAAC,eAAe,EAAE,iBAAiB,CAAC;gBAC3E,aAAa,EAAE,IAAA,iCAAgB,EAAC,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC;gBACrE,UAAU,EAAE,IAAI,IAAI,CAAC,IAAA,qCAAoB,EAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,EAAE;gBACpF,YAAY,EAAE,WAAW;aAC1B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,0GAA0G;IAC1G,eAAe;QACb,OAAO,WAAW,CAAC;IACrB,CAAC;IACD;;;OAGG;IACH,wBAAwB;QACtB,OAAO,IAAI,qBAAU,CAAC,IAAI,EAAE,IA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+BAA+B;IAK1C;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,0BAA0B,CACrC,aAA6C,EAC7C,UAAyD,EAAE;QAE3D,MAAM,QAAQ,GAAG,qCAAqC,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAC/E,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC,aAAa,EAAE,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;;AAvBH,0EAwBC;AAvBC,wGAAwG;AACjG,qEAAqC,GAAG,qCAAqC,CAAC;AACrF,oGAAoG;AAC7F,4DAA4B,GAAG,qCAAqC,CAAC","sourcesContent":["import Credential from '@alicloud/credentials';\nimport { CredentialException } from '@cloud-idaas/core-sdk';\nimport {\n type AklessProviderOptions,\n AklessProviderBuilder,\n CachedCloudCredentialProvider,\n type ExpiringCredential,\n credentialExpiration,\n credentialString,\n} from '@cloud-idaas/pam-client-sdk';\n\n/** Alibaba Cloud STS snapshot; inherited expiration is ISO 8601. Never log secret fields. */\nexport interface AlibabaSessionCredentials extends ExpiringCredential {\n accessKeyId: string;\n accessKeySecret: string;\n securityToken: string;\n providerName: string;\n}\n/** Temporary credentials accepted by ali-oss; securityToken maps to stsToken at this boundary. */\nexport interface OSSSTSCredentials {\n accessKeyId: string;\n accessKeySecret: string;\n stsToken: string;\n}\n/**\n * Initialization and refresh options verified with ali-oss 6.23.0; do not include an OSS service instance.\n * @remarks Initial fields are snapshots; refreshSTSToken reads the provider again. Call close after use.\n */\nexport interface OSSCredentialOptions extends OSSSTSCredentials {\n /** Returns a valid STS snapshot; rejects when refresh fails and cached credentials have expired. */\n refreshSTSToken: () => Promise<OSSSTSCredentials>;\n /** Refresh interval checked before OSS requests, in milliseconds. */\n refreshSTSTokenInterval: number;\n /** Closes the underlying IDaaS provider, leaving the caller-owned OSS client and shared injected resources open. */\n close(): void;\n}\n/**\n * Retrieves Alibaba Cloud STS through PAM for Credentials, SLS, and OSS integrations.\n * @remarks Supports Node.js 20/22/24; interfaces checked against @alicloud/credentials 2.4.7, ali-oss 6.23.0,\n * and @alicloud/log 1.2.6. Inherited getCredentials returns independent snapshots; close releases only owned\n * PAM/HTTP resources, leaving injected PAM, HTTP, and machine credential sources open.\n */\nexport class IDaaSPamAlibabaCloudCredentialsProvider extends CachedCloudCredentialProvider<AlibabaSessionCredentials> {\n /**\n * Creates a fluent builder without I/O; retrieval starts on first use after build.\n * @returns A builder for the role, endpoints, and injected sources.\n */\n static builder(): AklessProviderBuilder<IDaaSPamAlibabaCloudCredentialsProvider> {\n return new AklessProviderBuilder(\n (options) => new IDaaSPamAlibabaCloudCredentialsProvider(options),\n );\n }\n /**\n * Creates an independent STS provider for a role without immediately fetching credentials.\n * @param options - Required role and optional PAM, HTTP, machine credential source, and cache options.\n * @throws ConfigException - The role or configuration is invalid, or the default factory required for missing options is not initialized.\n */\n constructor(options: AklessProviderOptions) {\n super(options, (response) => {\n const token = response.alibabaCloudStsToken;\n if (!token)\n throw new CredentialException(\n 'Response is missing alibabaCloudStsToken',\n 'InvalidCredentialResponse',\n );\n return {\n accessKeyId: credentialString(token.accessKeyId, 'accessKeyId'),\n accessKeySecret: credentialString(token.accessKeySecret, 'accessKeySecret'),\n securityToken: credentialString(token.securityToken, 'securityToken'),\n expiration: new Date(credentialExpiration(response, token.expiration)).toISOString(),\n providerName: 'idaas_pam',\n };\n });\n }\n /** @returns The stable source identifier idaas_pam used by the official Credentials Provider protocol. */\n getProviderName(): string {\n return 'idaas_pam';\n }\n /**\n * Wraps this dynamic provider in an official @alicloud/credentials 2.4.7 client.\n * @returns An official Credential instance sharing the IDaaS cache; callers must still close this provider.\n */\n toAlibabaCloudCredential(): Credential {\n return new Credential(null, this);\n }\n /**\n * Retrieves a credential snapshot and an asynchronous refresh callback for ali-oss initialization.\n * @returns Options with a refresh interval in milliseconds and close; close also closes this provider.\n * @throws IDaaSException - PAM requests, credential parsing, or refresh fail without usable unexpired cached credentials.\n */\n async getOSSOptions(): Promise<OSSCredentialOptions> {\n const convert = (value: AlibabaSessionCredentials): OSSSTSCredentials => ({\n accessKeyId: value.accessKeyId,\n accessKeySecret: value.accessKeySecret,\n stsToken: value.securityToken,\n });\n const value = await this.getCredentials();\n this.assertAvailable(value);\n return {\n ...convert(value),\n close: () => this.close(),\n refreshSTSToken: async () => {\n const refreshed = await this.getCredentials();\n this.assertAvailable(refreshed);\n return convert(refreshed);\n },\n refreshSTSTokenInterval: Math.max(\n 1,\n Math.min(300_000, Math.floor((Date.parse(value.expiration) - Date.now()) / 6)),\n ),\n };\n }\n}\n/**\n * Creates an Alibaba Cloud/SLS dynamic credential provider without immediately fetching STS credentials.\n * @param roleOrOptions - Role external ID or complete configuration including the role.\n * @param options - Additional configuration when the first argument is a string; injected sources take precedence over the default factory.\n * @returns An independent provider; callers must call close after use to release only owned resources.\n * @throws ConfigException - The role or configuration is invalid, or the required default factory is not initialized.\n */\nexport function createAlibabaCloudCredentialsProvider(\n roleOrOptions: string | AklessProviderOptions,\n options: Omit<AklessProviderOptions, 'roleExternalId'> = {},\n): IDaaSPamAlibabaCloudCredentialsProvider {\n return new IDaaSPamAlibabaCloudCredentialsProvider(\n typeof roleOrOptions === 'string'\n ? { ...options, roleExternalId: roleOrOptions }\n : roleOrOptions,\n );\n}\n/** Alibaba Cloud beta adapter factories; do not create or manage OSS/SLS service clients. */\nexport class IDaaSPamAklessCredentialFactory {\n /** Convenience provider factory with the same arguments, lifecycle, and errors as the named factory. */\n static createAlibabaCloudCredentialsProvider = createAlibabaCloudCredentialsProvider;\n /** getCredentials integration for @alicloud/log 1.2.6; callers must close the returned provider. */\n static createSLSCredentialsProvider = createAlibabaCloudCredentialsProvider;\n /**\n * Creates an independent provider and retrieves ali-oss initialization and refresh options.\n * @param roleOrOptions - Role external ID or complete configuration.\n * @param options - Additional configuration when the role is a string.\n * @returns Options with initial STS credentials and refreshSTSToken; call the returned close after use.\n * @throws IDaaSException - The configuration is invalid or the initial STS request fails.\n */\n static async createOSSCredentialOptions(\n roleOrOptions: string | AklessProviderOptions,\n options: Omit<AklessProviderOptions, 'roleExternalId'> = {},\n ): Promise<OSSCredentialOptions> {\n const provider = createAlibabaCloudCredentialsProvider(roleOrOptions, options);\n try {\n return await provider.getOSSOptions();\n } catch (error) {\n provider.close();\n throw error;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA8HA,sFASC;AAtID,oDAA4D;AAC5D,gEAOqC;AACrC,+CAA4C;AA2B5C;;;;;GAKG;AACH,MAAa,uCAAwC,SAAQ,8CAAwD;IACnH;;;OAGG;IACH,MAAM,CAAC,OAAO;QACZ,OAAO,IAAI,sCAAqB,CAC9B,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,uCAAuC,CAAC,OAAO,CAAC,CAClE,CAAC;IACJ,CAAC;IACD;;;;OAIG;IACH,YAAY,OAA8B;QACxC,KAAK,CACH,OAAO,EACP,CAAC,QAAQ,EAAE,EAAE;YACX,MAAM,KAAK,GAAG,QAAQ,CAAC,oBAAoB,CAAC;YAC5C,IAAI,CAAC,KAAK;gBACR,MAAM,IAAI,8BAAmB,CAC3B,0CAA0C,EAC1C,2BAA2B,CAC5B,CAAC;YACJ,OAAO;gBACL,WAAW,EAAE,IAAA,iCAAgB,EAAC,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC;gBAC/D,eAAe,EAAE,IAAA,iCAAgB,EAAC,KAAK,CAAC,eAAe,EAAE,iBAAiB,CAAC;gBAC3E,aAAa,EAAE,IAAA,iCAAgB,EAAC,KAAK,CAAC,aAAa,EAAE,eAAe,CAAC;gBACrE,UAAU,EAAE,IAAI,IAAI,CAAC,IAAA,qCAAoB,EAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,EAAE;gBACpF,YAAY,EAAE,WAAW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AA3ED,0FA2EC;AACD;;;;;;GAMG;AACH,SAAgB,qCAAqC,CACnD,aAA6C,EAC7C,UAAyD,EAAE;IAE3D,OAAO,IAAI,uCAAuC,CAChD,OAAO,aAAa,KAAK,QAAQ;QAC/B,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE;QAC/C,CAAC,CAAC,aAAa,CAClB,CAAC;AACJ,CAAC;AACD,6FAA6F;AAC7F,MAAa,+BAA+B;IAK1C;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,0BAA0B,CACrC,aAA6C,EAC7C,UAAyD,EAAE;QAE3D,MAAM,QAAQ,GAAG,qCAAqC,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAC/E,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC,aAAa,EAAE,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;;AAvBH,0EAwBC;AAvBC,wGAAwG;AACjG,qEAAqC,GAAG,qCAAqC,CAAC;AACrF,oGAAoG;AAC7F,4DAA4B,GAAG,qCAAqC,CAAC","sourcesContent":["import type Credential from '@alicloud/credentials';\nimport { CredentialException } from '@cloud-idaas/core-sdk';\nimport {\n type AklessProviderOptions,\n AklessProviderBuilder,\n CachedCloudCredentialProvider,\n type ExpiringCredential,\n credentialExpiration,\n credentialString,\n} from '@cloud-idaas/pam-client-sdk';\nimport { SDK_VERSION } from './sdk-version';\n\n/** Alibaba Cloud STS snapshot; inherited expiration is ISO 8601. Never log secret fields. */\nexport interface AlibabaSessionCredentials extends ExpiringCredential {\n accessKeyId: string;\n accessKeySecret: string;\n securityToken: string;\n providerName: string;\n}\n/** Temporary credentials accepted by ali-oss; securityToken maps to stsToken at this boundary. */\nexport interface OSSSTSCredentials {\n accessKeyId: string;\n accessKeySecret: string;\n stsToken: string;\n}\n/**\n * Initialization and refresh options verified with ali-oss 6.23.0; do not include an OSS service instance.\n * @remarks Initial fields are snapshots; refreshSTSToken reads the provider again. Call close after use.\n */\nexport interface OSSCredentialOptions extends OSSSTSCredentials {\n /** Returns a valid STS snapshot; rejects when refresh fails and cached credentials have expired. */\n refreshSTSToken: () => Promise<OSSSTSCredentials>;\n /** Refresh interval checked before OSS requests, in milliseconds. */\n refreshSTSTokenInterval: number;\n /** Closes the underlying IDaaS provider, leaving the caller-owned OSS client and shared injected resources open. */\n close(): void;\n}\n/**\n * Retrieves Alibaba Cloud STS through PAM for Credentials, SLS, and OSS integrations.\n * @remarks Supports Node.js 20/22/24; interfaces checked against @alicloud/credentials 2.4.7, ali-oss 6.23.0,\n * and @alicloud/log 1.2.6. Inherited getCredentials returns independent snapshots; close releases only owned\n * PAM/HTTP resources, leaving injected PAM, HTTP, and machine credential sources open.\n */\nexport class IDaaSPamAlibabaCloudCredentialsProvider extends CachedCloudCredentialProvider<AlibabaSessionCredentials> {\n /**\n * Creates a fluent builder without I/O; retrieval starts on first use after build.\n * @returns A builder for the role, endpoints, and injected sources.\n */\n static builder(): AklessProviderBuilder<IDaaSPamAlibabaCloudCredentialsProvider> {\n return new AklessProviderBuilder(\n (options) => new IDaaSPamAlibabaCloudCredentialsProvider(options),\n );\n }\n /**\n * Creates an independent STS provider for a role without immediately fetching credentials.\n * @param options - Required role and optional PAM, HTTP, machine credential source, and cache options.\n * @throws ConfigException - The role or configuration is invalid, or the default factory required for missing options is not initialized.\n */\n constructor(options: AklessProviderOptions) {\n super(\n options,\n (response) => {\n const token = response.alibabaCloudStsToken;\n if (!token)\n throw new CredentialException(\n 'Response is missing alibabaCloudStsToken',\n 'InvalidCredentialResponse',\n );\n return {\n accessKeyId: credentialString(token.accessKeyId, 'accessKeyId'),\n accessKeySecret: credentialString(token.accessKeySecret, 'accessKeySecret'),\n securityToken: credentialString(token.securityToken, 'securityToken'),\n expiration: new Date(credentialExpiration(response, token.expiration)).toISOString(),\n providerName: 'idaas_pam',\n };\n },\n `idaas-typescript-akless-alibabacloud-adapter/${SDK_VERSION}`,\n );\n }\n /** @returns The stable source identifier idaas_pam used by the official Credentials Provider protocol. */\n getProviderName(): string {\n return 'idaas_pam';\n }\n /**\n * Wraps this dynamic provider in an official @alicloud/credentials 2.4.7 client.\n * @returns An official Credential instance sharing the IDaaS cache; callers must still close this provider.\n */\n toAlibabaCloudCredential(): Credential {\n const CredentialConstructor: typeof Credential = require('@alicloud/credentials').default;\n return new CredentialConstructor(null, this);\n }\n /**\n * Retrieves a credential snapshot and an asynchronous refresh callback for ali-oss initialization.\n * @returns Options with a refresh interval in milliseconds and close; close also closes this provider.\n * @throws IDaaSException - PAM requests, credential parsing, or refresh fail without usable unexpired cached credentials.\n */\n async getOSSOptions(): Promise<OSSCredentialOptions> {\n const convert = (value: AlibabaSessionCredentials): OSSSTSCredentials => ({\n accessKeyId: value.accessKeyId,\n accessKeySecret: value.accessKeySecret,\n stsToken: value.securityToken,\n });\n const value = await this.getCredentials();\n this.assertAvailable(value);\n return {\n ...convert(value),\n close: () => this.close(),\n refreshSTSToken: async () => {\n const refreshed = await this.getCredentials();\n this.assertAvailable(refreshed);\n return convert(refreshed);\n },\n refreshSTSTokenInterval: Math.max(\n 1,\n Math.min(300_000, Math.floor((Date.parse(value.expiration) - Date.now()) / 6)),\n ),\n };\n }\n}\n/**\n * Creates an Alibaba Cloud/SLS dynamic credential provider without immediately fetching STS credentials.\n * @param roleOrOptions - Role external ID or complete configuration including the role.\n * @param options - Additional configuration when the first argument is a string; injected sources take precedence over the default factory.\n * @returns An independent provider; callers must call close after use to release only owned resources.\n * @throws ConfigException - The role or configuration is invalid, or the required default factory is not initialized.\n */\nexport function createAlibabaCloudCredentialsProvider(\n roleOrOptions: string | AklessProviderOptions,\n options: Omit<AklessProviderOptions, 'roleExternalId'> = {},\n): IDaaSPamAlibabaCloudCredentialsProvider {\n return new IDaaSPamAlibabaCloudCredentialsProvider(\n typeof roleOrOptions === 'string'\n ? { ...options, roleExternalId: roleOrOptions }\n : roleOrOptions,\n );\n}\n/** Alibaba Cloud beta adapter factories; do not create or manage OSS/SLS service clients. */\nexport class IDaaSPamAklessCredentialFactory {\n /** Convenience provider factory with the same arguments, lifecycle, and errors as the named factory. */\n static createAlibabaCloudCredentialsProvider = createAlibabaCloudCredentialsProvider;\n /** getCredentials integration for @alicloud/log 1.2.6; callers must close the returned provider. */\n static createSLSCredentialsProvider = createAlibabaCloudCredentialsProvider;\n /**\n * Creates an independent provider and retrieves ali-oss initialization and refresh options.\n * @param roleOrOptions - Role external ID or complete configuration.\n * @param options - Additional configuration when the role is a string.\n * @returns Options with initial STS credentials and refreshSTSToken; call the returned close after use.\n * @throws IDaaSException - The configuration is invalid or the initial STS request fails.\n */\n static async createOSSCredentialOptions(\n roleOrOptions: string | AklessProviderOptions,\n options: Omit<AklessProviderOptions, 'roleExternalId'> = {},\n ): Promise<OSSCredentialOptions> {\n const provider = createAlibabaCloudCredentialsProvider(roleOrOptions, options);\n try {\n return await provider.getOSSOptions();\n } catch (error) {\n provider.close();\n throw error;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-version.js","sourceRoot":"","sources":["../src/sdk-version.ts"],"names":[],"mappings":";;;AAAA,yEAAyE;AAC5D,QAAA,WAAW,GAAW,cAAc,CAAC","sourcesContent":["// Generated from package.json by scripts/build-version.cjs. Do not edit.\nexport const SDK_VERSION: string = '0.1.0-beta.4';\n"]}
|
package/examples/initialize.cjs
CHANGED
|
@@ -6,8 +6,10 @@ const {
|
|
|
6
6
|
async function main() {
|
|
7
7
|
await IDaaSCredentialProviderFactory.init();
|
|
8
8
|
try {
|
|
9
|
+
// For the PAM default, call createAlibabaCloudCredentialsProvider(roleId).
|
|
9
10
|
const provider = createAlibabaCloudCredentialsProvider(
|
|
10
11
|
process.env.IDAAS_ROLE_EXTERNAL_ID || 'role-id',
|
|
12
|
+
{ durationSeconds: 1800 },
|
|
11
13
|
);
|
|
12
14
|
try {
|
|
13
15
|
await provider.toAlibabaCloudCredential().getCredential();
|
package/examples/initialize.mjs
CHANGED
|
@@ -4,8 +4,10 @@ import { createAlibabaCloudCredentialsProvider } from '@cloud-idaas/akless-aliba
|
|
|
4
4
|
async function main() {
|
|
5
5
|
await IDaaSCredentialProviderFactory.init();
|
|
6
6
|
try {
|
|
7
|
+
// For the PAM default, call createAlibabaCloudCredentialsProvider(roleId).
|
|
7
8
|
const provider = createAlibabaCloudCredentialsProvider(
|
|
8
9
|
process.env.IDAAS_ROLE_EXTERNAL_ID || 'role-id',
|
|
10
|
+
{ durationSeconds: 1800 },
|
|
9
11
|
);
|
|
10
12
|
try {
|
|
11
13
|
await provider.toAlibabaCloudCredential().getCredential();
|
package/examples/initialize.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { createAlibabaCloudCredentialsProvider } from '@cloud-idaas/akless-aliba
|
|
|
4
4
|
async function main() {
|
|
5
5
|
await IDaaSCredentialProviderFactory.init();
|
|
6
6
|
try {
|
|
7
|
+
// For the PAM default, call createAlibabaCloudCredentialsProvider(roleId).
|
|
7
8
|
const provider = createAlibabaCloudCredentialsProvider(
|
|
8
9
|
process.env.IDAAS_ROLE_EXTERNAL_ID || 'role-id',
|
|
10
|
+
{ durationSeconds: 1800 },
|
|
9
11
|
);
|
|
10
12
|
try {
|
|
11
13
|
await provider.toAlibabaCloudCredential().getCredential();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-idaas/akless-alibabacloud-adapter",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
4
|
"description": "IDaaS akless-alibabacloud-adapter for TypeScript and JavaScript (Node.js)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"node": ">=20.0.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "tsc -p tsconfig.json && node scripts/build-esm.cjs",
|
|
34
|
-
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p test/tsconfig.json",
|
|
33
|
+
"build": "node scripts/build-version.cjs && tsc -p tsconfig.json && node scripts/build-esm.cjs",
|
|
34
|
+
"typecheck": "node scripts/build-version.cjs && tsc --noEmit -p tsconfig.json && tsc --noEmit -p test/tsconfig.json",
|
|
35
35
|
"test": "npm run build && nyc mocha --require ./test/register.cjs \"test/**/*.test.{ts,cjs}\"",
|
|
36
36
|
"prepack": "npm run build",
|
|
37
37
|
"lint": "eslint src test",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"@alicloud/log": "1.2.6"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cloud-idaas/core-sdk": "0.1.0-beta.
|
|
65
|
-
"@cloud-idaas/pam-client-sdk": "0.1.0-beta.
|
|
64
|
+
"@cloud-idaas/core-sdk": "0.1.0-beta.4",
|
|
65
|
+
"@cloud-idaas/pam-client-sdk": "0.1.0-beta.4",
|
|
66
66
|
"@alicloud/credentials": "2.4.7"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|