feat: flexible cookie auth (substack.sid and/or connect.sid), markdown notes, retries, note deletion#323
Open
onlyTheOnionNews wants to merge 3 commits into
Open
Conversation
Source extracted from jakub-k-slys/substack-api (MIT) at HEAD via git archive. Changes from upstream: - renamed path alias @substack-api -> @substackular - replaced Rollup CJS-only build with tsup dual ESM/CJS + dts - modernized tsconfig for TypeScript 6 (bundler resolution) - renamed ?-containing sample fixtures to Windows-safe names (-- for ?) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- HttpClient now accepts { substackSid?, connectSid? } and sends every
provided cookie; at least one is required. Fixes accounts that only
have a substack.sid or only a connect.sid session cookie.
- SubstackConfig gains substackSid/connectSid/retryAttempts; token kept
as deprecated alias for substackSid (substack-api compatibility).
- Transient failures (network errors, 408/425/429/5xx) retried with
exponential backoff via axios-retry, mirroring substack-gateway-oss.
- Typed errors: SubstackApiError, SubstackAuthError (401/403).
- Note deletion: NoteService.deleteNote, Note.delete(),
OwnProfile.deleteNote() -> DELETE /api/v1/comment/{id}.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- parseMarkdownNote: port of substack-gateway-oss converters/markdown.py
emitting NoteBuilder paragraphs, so markdown gets real ProseMirror link
marks and bullet/ordered list nodes instead of flattened text.
- OwnProfile.publishNote(markdown, { attachmentUrl? }) publishes notes
from markdown strings, optionally with a link preview attachment.
- E2E credentials switched to SUBSTACK_SID / CONNECT_SID env vars with
legacy SUBSTACK_API_KEY fallback; .env.example updated.
- tsup inlines fp-ts/io-ts (no exports maps) so the ESM bundle
resolves under Node; verified require() and import() consumption.
- tsconfig.test.json fixed for standalone tsc typechecking.
- README, LICENSE attribution for the substack-api derivation.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR contributes the substackular continuation of this library back upstream. It sits directly on top of
main(4228d80) and adds the features from substack-gateway-oss that were missing from the TypeScript client, most importantly flexible session-cookie authentication:substack.sidand/orconnect.sidauth — some Substack accounts only carry one of the two session cookies.HttpClientnow accepts{ substackSid?, connectSid? }, requires at least one, and sends every cookie provided (the gateway sends both). The existingtokenconfig key is kept as a deprecated alias forsubstackSid, so current consumers are unaffected.OwnProfile.publishNote(markdown, { attachmentUrl? }), a TypeScript port of the gateway''sconverters/markdown.pythat feedsNoteBuilder, so markdown gets real ProseMirror link marks and bullet/ordered list nodes instead of flattened text.NoteService.deleteNote(),Note.delete(),OwnProfile.deleteNote()→DELETE /api/v1/comment/{id}(gateway parity).axios-retry, mirroring the gateway''s tenacity policy; configurable withretryAttempts.SubstackAuthError(401/403) vsSubstackApiError, both exported.exportsmaps break Node ESM resolution; consumption verified from bothrequire()andimport.Heads-up for review
Because this began as a maintained continuation, the branch also rebrands the package to
substackular(package name,@substackular/*path aliases, README/LICENSE attribution) and drops the docs/CI directories. The sample fixtures containing?were renamed (?→--) so the repo checks out on Windows. If you''d rather take the functional changes under thesubstack-apiname without the rebrand, happy to split this into smaller PRs — just say the word.Test plan
pnpm test), coverage thresholds kept at 80%tsc -p tsconfig.test.jsonclean across src and all test suitespnpm lintclean (0 errors)distsmoke-tested from both CJSrequire()and ESMimport(), including aconnectSid-only client and the no-cookie error pathpnpm test:e2e) — needsSUBSTACK_SID/CONNECT_SID+SUBSTACK_HOSTNAMEsecrets🤖 Generated with Claude Code