@justworkflowit/cdk-constructs 0.0.179 → 0.0.181
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.
|
@@ -60714,6 +60714,8 @@ var require_createAuthenticatedClient = __commonJS({
|
|
|
60714
60714
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
60715
60715
|
exports2.createAuthenticatedClient = void 0;
|
|
60716
60716
|
var JustWorkflowIt_1 = require_JustWorkflowIt();
|
|
60717
|
+
var protocol_http_1 = require_dist_cjs2();
|
|
60718
|
+
var core_1 = (init_dist_es(), __toCommonJS(dist_es_exports));
|
|
60717
60719
|
var TokenBucket = class {
|
|
60718
60720
|
tokens;
|
|
60719
60721
|
lastRefill;
|
|
@@ -60776,23 +60778,56 @@ var require_createAuthenticatedClient = __commonJS({
|
|
|
60776
60778
|
};
|
|
60777
60779
|
function createAuthenticatedClient(config) {
|
|
60778
60780
|
const endpoint2 = config.endpoint ?? "https://api.justworkflowit.com";
|
|
60779
|
-
const client = new JustWorkflowIt_1.JustWorkflowIt({ endpoint: endpoint2 });
|
|
60780
60781
|
const getToken = typeof config.accessToken === "function" ? config.accessToken : () => Promise.resolve(config.accessToken);
|
|
60782
|
+
const cognitoIdentityProviderFactory2 = () => {
|
|
60783
|
+
return async () => ({
|
|
60784
|
+
token: await getToken()
|
|
60785
|
+
});
|
|
60786
|
+
};
|
|
60787
|
+
const apiKeyIdentityProviderFactory = () => {
|
|
60788
|
+
return async () => ({
|
|
60789
|
+
apiKey: `Bearer ${await getToken()}`
|
|
60790
|
+
});
|
|
60791
|
+
};
|
|
60792
|
+
const noAuthIdentityProviderFactory2 = () => {
|
|
60793
|
+
return async () => ({});
|
|
60794
|
+
};
|
|
60795
|
+
const cognitoSigner = {
|
|
60796
|
+
async sign(request, identity) {
|
|
60797
|
+
const tokenIdentity = identity;
|
|
60798
|
+
if (!tokenIdentity.token) {
|
|
60799
|
+
throw new Error("Cognito User Pools signer requires a token identity");
|
|
60800
|
+
}
|
|
60801
|
+
const cloned = protocol_http_1.HttpRequest.clone(request);
|
|
60802
|
+
cloned.headers["Authorization"] = `Bearer ${tokenIdentity.token}`;
|
|
60803
|
+
return cloned;
|
|
60804
|
+
}
|
|
60805
|
+
};
|
|
60806
|
+
const apiKeySigner = new core_1.HttpApiKeyAuthSigner();
|
|
60807
|
+
const noAuthSigner2 = new core_1.NoAuthSigner();
|
|
60808
|
+
const httpAuthSchemes = [
|
|
60809
|
+
{
|
|
60810
|
+
schemeId: "aws.auth#cognitoUserPools",
|
|
60811
|
+
identityProvider: cognitoIdentityProviderFactory2,
|
|
60812
|
+
signer: cognitoSigner
|
|
60813
|
+
},
|
|
60814
|
+
{
|
|
60815
|
+
schemeId: "smithy.api#httpApiKeyAuth",
|
|
60816
|
+
identityProvider: apiKeyIdentityProviderFactory,
|
|
60817
|
+
signer: apiKeySigner
|
|
60818
|
+
},
|
|
60819
|
+
{
|
|
60820
|
+
schemeId: "smithy.api#noAuth",
|
|
60821
|
+
identityProvider: noAuthIdentityProviderFactory2,
|
|
60822
|
+
signer: noAuthSigner2
|
|
60823
|
+
}
|
|
60824
|
+
];
|
|
60825
|
+
const client = new JustWorkflowIt_1.JustWorkflowIt({ endpoint: endpoint2, httpAuthSchemes });
|
|
60781
60826
|
const retryConfig = config.retry === false ? false : {
|
|
60782
60827
|
...DEFAULT_RETRY_CONFIG,
|
|
60783
60828
|
...config.retry ?? {}
|
|
60784
60829
|
};
|
|
60785
60830
|
const rateLimiter = config.rateLimit ? new TokenBucket(config.rateLimit) : null;
|
|
60786
|
-
client.middlewareStack.add((next) => async (args) => {
|
|
60787
|
-
const request = args.request;
|
|
60788
|
-
const token = await getToken();
|
|
60789
|
-
request.headers["Authorization"] = `Bearer ${token}`;
|
|
60790
|
-
return next(args);
|
|
60791
|
-
}, {
|
|
60792
|
-
step: "build",
|
|
60793
|
-
name: "attachBearerToken",
|
|
60794
|
-
priority: "high"
|
|
60795
|
-
});
|
|
60796
60831
|
if (rateLimiter) {
|
|
60797
60832
|
client.middlewareStack.add((next) => async (args) => {
|
|
60798
60833
|
await rateLimiter.acquire();
|