goshippo / shippo-javascript-sdk

MIT License
5 stars 0 forks source link

I'm currently getting the following error when trying to use Shippo #13

Closed shippo-lueders closed 2 months ago

shippo-lueders commented 2 months ago
          I'm currently getting the following error when trying to use Shippo, and I wonder if this PR is intended to solve this:
yarn run v1.22.19
$ /Users/localuser/Projects/api/api-new/node_modules/.bin/ts-node src/scripts/shippo-check.ts
Error: Cannot find module 'zod'
Require stack:
- /Users/localuser/Projects/api/api-new/node_modules/shippo/lib/base64.js
- /Users/localuser/Projects/api/api-new/node_modules/shippo/lib/encodings.js
- /Users/localuser/Projects/api/api-new/node_modules/shippo/lib/sdks.js
- /Users/localuser/Projects/api/api-new/node_modules/shippo/sdk/sdk.js
- /Users/localuser/Projects/api/api-new/node_modules/shippo/sdk/index.js
- /Users/localuser/Projects/api/api-new/node_modules/shippo/index.js
- /Users/localuser/Projects/api/api-new/src/scripts/shippo-check.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/localuser/Projects/api/api-new/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/Users/localuser/Projects/api/api-new/node_modules/shippo/src/lib/base64.ts:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .js] (/Users/localuser/Projects/api/api-new/node_modules/ts-node/src/index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:1119:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/localuser/Projects/api/api-new/node_modules/shippo/lib/base64.js',
    '/Users/localuser/Projects/api/api-new/node_modules/shippo/lib/encodings.js',
    '/Users/localuser/Projects/api/api-new/node_modules/shippo/lib/sdks.js',
    '/Users/localuser/Projects/api/api-new/node_modules/shippo/sdk/sdk.js',
    '/Users/localuser/Projects/api/api-new/node_modules/shippo/sdk/index.js',
    '/Users/localuser/Projects/api/api-new/node_modules/shippo/index.js',
    '/Users/localuser/Projects/api/api-new/src/scripts/shippo-check.ts'
  ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

When I manually install Zod, I get the following error when trying to get tracking info:

SDKValidationError: Response validation failed
    at Object.parse (/Users/localuser/Projects/api/api-new/node_modules/shippo/src/lib/schemas.ts:18:19)
    at TrackingStatus.get (/Users/localuser/Projects/api/api-new/node_modules/shippo/src/sdk/trackingstatus.ts:210:37)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async run (/Users/localuser/Projects/api/api-new/src/scripts/shippo-check.ts:38:26) {
  cause: ZodError: [
    {
      "code": "invalid_type",
      "expected": "object",
      "received": "undefined",
      "path": [
        "tracking_history",
        0,
        "location"
      ],
      "message": "Required"
    },
    {
      "code": "invalid_type",
      "expected": "string",
      "received": "undefined",
      "path": [
        "tracking_history",
        0,
        "status_date"
      ],
      "message": "Required"
    }
  ]
      at Object.get error [as error] (/Users/localuser/Projects/api/api-new/node_modules/zod/lib/types.js:55:31)
      at ZodEffects.parse (/Users/localuser/Projects/api/api-new/node_modules/zod/lib/types.js:160:22)
      at /Users/localuser/Projects/api/api-new/node_modules/shippo/src/sdk/trackingstatus.ts:213:60
      at Object.parse (/Users/localuser/Projects/api/api-new/node_modules/shippo/src/lib/schemas.ts:15:16)
      at TrackingStatus.get (/Users/localuser/Projects/api/api-new/node_modules/shippo/src/sdk/trackingstatus.ts:210:37)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async run (/Users/localuser/Projects/api/api-new/src/scripts/shippo-check.ts:38:26) {
    issues: [ [Object], [Object] ],
    addIssue: [Function (anonymous)],
    addIssues: [Function (anonymous)],
    errors: [ [Object], [Object] ]
  },
  rawValue: {
    tracking_number: '[REDACTED]',
    carrier: 'ups',
    servicelevel: {},
    transaction: '[REDACTED]',
    address_from: { city: '[REDACTED]', state: '[REDACTED]', zip: '[REDACTED]', country: 'US' },
    address_to: { city: '[REDACTED]', state: '[REDACTED]', zip: '[REDACTED]', country: 'US' },
    test: false,
    tracking_history: [ [Object] ],
    messages: []
  }
}

Originally posted by @Cyberuben in https://github.com/goshippo/shippo-javascript-sdk/issues/12#issuecomment-2083971856

shippo-lueders commented 2 months ago

@Cyberuben I'm about to merge that PR and didn't want this to get lost, I'll be looking into this today

Cyberuben commented 2 months ago

Thank you for keeping track of this. It seems like even with this PR this causes issues.

I didn't dig in any further, I assumed the errors might've been caused by the version upgrade since the last release seemed to line up just with me attempting to use it, but the problem might be more complex than this.

shippo-lueders commented 2 months ago

yeah, the root problem here is that our API spec defines location in the tracking history as required - https://docs.goshippo.com/shippoapi/public-api/#operation/GetTrack!c=200&path=tracking_history/location&t=response

but it's not, at least as part of the history. what I don't know is whether location is required as part of the top level tracking_status - https://docs.goshippo.com/shippoapi/public-api/#operation/GetTrack!c=200&path=tracking_status/location&t=response

I'm going to track this down , will provide an update tomorrow at the latest

shippo-lueders commented 2 months ago

okay, confirmed location is not actually required. spec has been updated and a new package has been published. if you run into any more issues, let us know!

Cyberuben commented 2 months ago

I'm not sure if the zod error would be resolved by this though.

shippo-lueders commented 2 months ago

no, this specifically addresses the SDKValidationError: Response validation failed issue.

re: zod, it's listed as a peer dependency so will not be pulled in automatically. I'm going to talk to my team about this, either we need to move this to a non-peer dep or we need to update the docs and explain this dependency will be required by consumers and the rationale.

Cyberuben commented 2 months ago

Thanks for the info!