GetEntitlementsCommand fails with TypeError: Unions must have exactly one non-null member. Keys EntitlementValueType,IntegerValue were not null

Viewed 72

I'm using

  • node 14
  • typescript 4.4.4
  • @aws-sdk/client-marketplace-entitlement-service 3.41.0

This is the code that fails:

const aws = require('@aws-sdk/client-marketplace-entitlement-service');

const marketplaceEntitlementServiceClient =
  new aws.MarketplaceEntitlementServiceClient({
    region: 'us-east-1',
  });

const productCode = '<code>';
const customerIdentifier = '<id>';
(async () => {
  try {
    const out = await marketplaceEntitlementServiceClient.send(
      new aws.GetEntitlementsCommand({
        ProductCode: productCode,
        Filter: {
          CUSTOMER_IDENTIFIER: [customerIdentifier],
        },
      }));
    console.log(out);
  } catch (e) {
    console.log(e);
  }
})();

It fails with this error:

TypeError: Unions must have exactly one non-null member. Keys EntitlementValueType,IntegerValue were not null.
    at Object.expectUnion (/app/node_modules/@aws-sdk/client-marketplace-entitlement-service/node_modules/@aws-sdk/smithy-client/dist-cjs/parse-utils.js:122:15)
    at deserializeAws_json1_1Entitlement (/app/node_modules/@aws-sdk/client-marketplace-entitlement-service/dist-cjs/protocols/Aws_json1_1.js:151:70)
    at /app/node_modules/@aws-sdk/client-marketplace-entitlement-service/dist-cjs/protocols/Aws_json1_1.js:162:16
    at Array.map (<anonymous>)
    at deserializeAws_json1_1EntitlementList (/app/node_modules/@aws-sdk/client-marketplace-entitlement-service/dist-cjs/protocols/Aws_json1_1.js:158:10)
    at deserializeAws_json1_1GetEntitlementsResult (/app/node_modules/@aws-sdk/client-marketplace-entitlement-service/dist-cjs/protocols/Aws_json1_1.js:183:15)
    at Object.deserializeAws_json1_1GetEntitlementsCommand (/app/node_modules/@aws-sdk/client-marketplace-entitlement-service/dist-cjs/protocols/Aws_json1_1.js:22:16)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /app/node_modules/@aws-sdk/client-marketplace-entitlement-service/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:6:20
    at async /app/node_modules/@aws-sdk/client-marketplace-entitlement-service/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:11:20

Using the same AWS credentials and the same product code and customer number, the AWS cli succeeds:

AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=yyy aws marketplace-entitlement get-entitlements --product-code <code> --filter CUSTOMER_IDENTIFIER=<id>
{
    "Entitlements": [
        {
            "ProductCode": "<code>",
            "Dimension": "free_trial",
            "CustomerIdentifier": "<id>",
            "Value": {
                "IntegerValue": 1
            },
            "ExpirationDate": "2021-12-15T15:23:20.371000-06:00"
        }
    ]
}

Am I doing something wrong? Is there a bug in the sdk?

UPDATE:

I added some extra logging in the AWS sdk. The error happens when calling expectUnion() from parse_utils (see stack trace above). Prior to this call, the output is present and looks like this:

{
  CustomerIdentifier: '<id>',
  Dimension: 'free_trial',
  ExpirationDate: 1639603400.371,
  ProductCode: '<code>',
  Value: { EntitlementValueType: 'int', IntegerValue: 1 }
}

So, the credentials and api call worked fine, it's just something in the conversion of that raw output that's failing.

0 Answers
Related