typewriter
typewriter copied to clipboard
apiClient is not created, and can't fetch plans from API
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.
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.
This is also an issue that I'm running into, the id of the tracking plan is correct, there's just nothing being generated.
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:
- ~/.typewriter (if you ask it to save it)
- ./typewriter.yml (the id starts with
tp_
) - ... 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
- ./typewriter.yml
- ... 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
- ... none
If I downgrade to 7.x, everything works correctly.
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
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 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 ETA on publishing a new version with this fix?