
Security News
PolinRider: North Korea-Linked Supply Chain Campaign Expands Across Open Source Ecosystems
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.
@oncely/core
Advanced tools
Idempotency engine for HTTP APIs - ensures operations execute exactly once
Core idempotency library with memory storage. The foundation for all oncely packages.
npm install @oncely/core
import { MemoryStorage, hashObject, parseTtl } from '@oncely/core';
const storage = new MemoryStorage();
// Acquire a lock for a request
const result = await storage.acquire('request-key', hashObject(body), parseTtl('1h'));
if (result.status === 'acquired') {
// Execute the operation
const response = await processRequest(body);
// Save the response
await storage.save('request-key', {
data: response,
createdAt: Date.now(),
hash: hashObject(body),
});
}
if (result.status === 'hit') {
// Return cached response
return result.response.data;
}
MemoryStorage is the default adapter, ideal for:
For production multi-instance deployments, use:
interface StorageAdapter {
acquire(key: string, hash: string | null, ttl: number): Promise<AcquireResult>;
save(key: string, response: StoredResponse): Promise<void>;
release(key: string): Promise<void>;
delete(key: string): Promise<void>;
clear(): Promise<void>;
}
type AcquireResult =
| { status: 'acquired' }
| { status: 'hit'; response: StoredResponse }
| { status: 'conflict'; startedAt: number }
| { status: 'mismatch'; existingHash: string; providedHash: string };
import { hashObject } from '@oncely/core';
const hash = hashObject({ amount: 100, currency: 'USD' });
// => 'a1b2c3d4...'
import { parseTtl } from '@oncely/core';
parseTtl('1h'); // 3600000
parseTtl('30m'); // 1800000
parseTtl('5s'); // 5000
parseTtl('1d'); // 86400000
parseTtl(60000); // 60000
import {
IdempotencyError,
MissingKeyError, // 400 - Key required but missing
ConflictError, // 409 - Request in progress
MismatchError, // 422 - Key reused with different body
} from '@oncely/core';
All errors extend IdempotencyError and include:
statusCode - HTTP status codetoProblemDetails() - RFC 7807 Problem Detailsimport { IDEMPOTENCY_KEY_HEADER, IDEMPOTENCY_REPLAY_HEADER } from '@oncely/core';
IDEMPOTENCY_KEY_HEADER; // 'Idempotency-Key'
IDEMPOTENCY_REPLAY_HEADER; // 'Idempotency-Replay'
import { createTestStorage, MockStorage } from '@oncely/core/testing';
// Create a test storage with optional pre-seeded data
const storage = createTestStorage({
'existing-key': { data: { id: 1 }, createdAt: Date.now(), hash: null },
});
// Or use MockStorage for fine-grained control
const mock = new MockStorage();
mock.simulateConflict('key');
mock.simulateError(new Error('Connection failed'));
MIT
FAQs
Idempotency engine for HTTP APIs - ensures operations execute exactly once
We found that @oncely/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.

Research
/Security News
Malicious Chrome and Firefox extensions posed as free VPNs while stealing clipboard data through later extension updates.