Repository navigation
Warn when the installation ID can't be saved; add requirePersisted - #10
Merged
Merged
Conversation
…irePersisted
getOrCreateInstallationId swallowed write errors and returned an unsaved
ID, so every launch on a read-only or sandboxed disk produced a new ID and
used another activation slot, with no signal to the app.
- Default behaviour is unchanged: an unsaved ID is still returned, but one
KeymintInstallationIdWarning (code KEYMINT_INSTALLATION_ID_NOT_SAVED) is
now emitted per process via process.emitWarning.
- New opt-in { requirePersisted: true } (second argument, or a single
options object with storagePath) throws InstallationIdError with the
storage path when the ID can't be saved and read back, or an existing
file can't be read.
- The saved value is read back to confirm it persisted.
- Use path.dirname for the storage directory (Windows paths).
- Tests, type checks, README and CHANGELOG.
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.
Problem
KeyMint.getOrCreateInstallationId()swallowed write errors and returned an unsaved ID. On a read-only disk, in a sandbox, or without permission to write~/.keymint, every launch generated a different ID, so the same machine used another activation slot each time, and the app got no signal.Change (backwards compatible)
Default unchanged. The method still returns an ID and never throws because of a failed save. It now emits one
KeymintInstallationIdWarningper process viaprocess.emitWarning(codeKEYMINT_INSTALLATION_ID_NOT_SAVED), naming the storage path.Opt-in strict mode. New
InstallationIdOptions { requirePersisted?: boolean }, defaultfalse. Either form works:getOrCreateInstallationId(storagePath, { requirePersisted: true })getOrCreateInstallationId({ storagePath, requirePersisted: true })With
trueit throws the new exportedInstallationIdError(name,path,cause) when the ID can't be saved and read back, or an existing file can't be read.After writing, the value is read back to confirm it persisted.
Return type unchanged (
string).The storage directory now uses
path.dirnameinstead of splitting on/, so Windows paths are created correctly.JSDoc, README ("When the installation ID can't be saved") and CHANGELOG (Unreleased) describe the default, the warning and the strict option, and recommend
requirePersisted: truefor desktop apps that activate devices.No version bump.
Tests
New
tests/identity.test.cjs(added tonpm test):InstallationIdErrorwith the path, and doesn't warn;New
tests/types/identity.check.tschecks the overloads and that the return type is stillstring.npm run lint: clean.npm test: 64 passed (live tests not run).