typewriter icon indicating copy to clipboard operation
typewriter copied to clipboard

apiClient is not created, and can't fetch plans from API

Open Adam-Kuhn20 opened this issue 2 years ago • 0 comments

We are trying to update from Typewriter 7.4.1 to 8.0.3.

I'm trying to regenerate our analytics with the new Public API Token. After running yarn typewriter init, I'm able to go through the steps just fine with no issue. On completion though no client is created (docs)

Additionally, when I run yarn typewriter or yarn typewriter build, after doing yarn typewriter init. I receive the following error Error: Unable to fetch Tracking Plan from local cache or API.

I'm not sure why I get this error, because when I do yarn typewriter init I'm able to see all of the tracking plans and select the one I want.

Adam-Kuhn20 avatar Aug 10 '22 11:08 Adam-Kuhn20

I managed to get around that error by updating the id in the typewriter.yml file.

Previously it was rs_XXX which is the resourceSchemaId, but now it seems to require the actual id of the tracking plan which is tp_XXX. You can get it by calling GET https://api.segmentapis.com/tracking-plans with your token, or inspecting the Network in the Segment app.

So now I don't get the error anymore, but it gets stuck on the Loading tracking plans... ⡿ step.

andreiho avatar Aug 12 '22 09:08 andreiho

This is also an issue that I'm running into, the id of the tracking plan is correct, there's just nothing being generated.

IsabellaS09 avatar Aug 12 '22 19:08 IsabellaS09

I'm getting the same errors. Here is some more information:

  • OS: macOS Monterey
  • Chip: M1
  • node: v14.20.0
  • analytics-node: v6.2.0
  • typewriter: v8.0.3

If you do NOT have a ~/.typewriter file and run typewriter init

Outcomes

You get this output

? Save these settings? Yes
    TypeError: Cannot read property 'method' of undefined
error Command failed with exit code 1.

You get these files:

  1. ~/.typewriter (if you ask it to save it)
  2. ./typewriter.yml (the id starts with tp_)
  3. ... nothing else

If you DO have a ~/.typewriter file and run typewriter init

Outcomes

You get this output

? Save these settings? Yes
✨  Done in 101.02s.

You get these files

  1. ./typewriter.yml
  2. ... nothing else

If you have a typewriter.yml file and run typewriter

Outcomes

You get the following output

Loading tracking plans... !
    Error: Unable to fetch Tracking Plan from local cache or API
error Command failed with exit code 1.

You get the following files

  1. ... none

If I downgrade to 7.x, everything works correctly.

dncrews avatar Aug 20 '22 01:08 dncrews

Thanks for the detailed report, we're checking this. Could anyone with this issue share the output when running the command with the --debug flag?

oscb avatar Aug 23 '22 18:08 oscb

@oscb

Here's my output:
$ typewriter update --debug
  typewriter:config Loaded raw config {
  client: { sdk: 'analytics-js', language: 'typescript', languageOptions: {} },
  trackingPlans: [
    {
      id: 'tp_XXX',
      path: 'src/app/utils/segment/generated'
    }
  ],
  scripts: {
    token: 'echo $TYPEWRITER_TOKEN',
    after: './node_modules/.bin/prettier --write ./src/app/utils/segment/generated/plan.json'
  }
} +0ms
  typewriter:config getToken { method: 'pipe' } +4ms
  typewriter:config getToken {
  method: 'script',
  token: 'sgp_XXX',
  isValid: true,
  workspace: { id: 'XXX', name: 'XXX', slug: 'XXX' }
} +804ms
  typewriter:config Selecting Token {
  method: 'script',
  token: 'sgp_XXX',
  isValid: true,
  workspace: { id: 'XXX', name: 'XXX', slug: 'XXX' }
} +1ms
  typewriter:api Loaded 1 rules. Next Page=MQ== +0ms
  typewriter:api Loaded 1 rules. Next Page=Mg== +795ms
  ...
  typewriter:api Loaded 1 rules. Next Page=undefined +646ms
  typewriter:api Loaded 540 rules for the tracking plan Agent Interface Tracking Plan +0ms
  typewriter:trackingplans API request failed. Using local copy of undefined instead. +0ms

Loading tracking plans... !
  follow-redirects options {
  maxRedirects: 21,
  maxBodyLength: 10485760,
  protocol: 'https:',
  path: '/v1/batch',
  method: 'POST',
  headers: {
    Accept: 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    'user-agent': 'analytics-node/6.2.0',
    'Content-Length': 1420
  },
  agent: undefined,
  agents: { http: undefined, https: undefined },
  auth: 'XXX:',
  hostname: 'api.segment.io',
  port: null,
  nativeProtocols: {
    'http:': {
      _connectionListener: [Function: connectionListener],
      METHODS: [Array],
      STATUS_CODES: [Object],
      Agent: [Function],
      ClientRequest: [Function: ClientRequest],
      IncomingMessage: [Function: IncomingMessage],
      OutgoingMessage: [Function: OutgoingMessage],
      Server: [Function: Server],
      ServerResponse: [Function: ServerResponse],
      createServer: [Function: createServer],
      validateHeaderName: [Function: __node_internal_],
      validateHeaderValue: [Function: __node_internal_],
      get: [Function: get],
      request: [Function: request],
      maxHeaderSize: [Getter],
      globalAgent: [Getter/Setter]
    },
    'https:': {
      Agent: [Function: Agent],
      globalAgent: [Agent],
      Server: [Function: Server],
      createServer: [Function: createServer],
      get: [Function: get],
      request: [Function: request]
    }
  }
} +0ms
    Error: Unable to fetch Tracking Plan from local cache or API

It seems to be loading each and every rule one at a time, as seen here, and it's taking a long time, but it succeeds eventually.

Then it fails with this error API request failed. Using local copy of undefined instead which seems to be thrown here.

My guess is that something's failing in sanitizeTrackingPlan and gets caught by that try/catch.

andreiho avatar Aug 23 '22 18:08 andreiho

@andreiho I think your assumption is spot on. I can already see that we missed the page size from being bigger than 1 for starters. Doing some tests right now

oscb avatar Aug 23 '22 22:08 oscb

@oscb ETA on publishing a new version with this fix?

andreiho avatar Sep 06 '22 10:09 andreiho