Skip to content

fix: instantiate Result with new in resultWrapper - #390

Open
achromik wants to merge 487 commits into
contentstack:masterfrom
achromik:fix/result-class-call-without-new
Open

fix: instantiate Result with new in resultWrapper#390
achromik wants to merge 487 commits into
contentstack:masterfrom
achromik:fix/result-class-call-without-new

Conversation

@achromik

@achromik achromik commented Jun 11, 2026

Copy link
Copy Markdown

Problem

Since 3.18.0 (taxonomy support release), src/core/modules/result.js exports Result as an ES class — previously it exported a factory function (module.exports = function (object) { return new Result(object); }). However, resultWrapper() in src/core/lib/utils.js still invokes Result(...) as a plain function in 5 places.

Any success response going through resultWrapper — e.g. Stack.ContentType(...).Entry(uid).fetch() without .toJSON() — throws:

TypeError: Cannot call a class as a function

This is a regression introduced in 3.18.0 — versions <= 3.17.2 are unaffected.

Repro (offline, >= 3.24.0 where the SDK uses global fetch)

global.fetch = async () =>
  new Response(JSON.stringify({ entry: { uid: 'u1', title: 't', locale: 'en', _version: 1 } }),
    { status: 200, headers: { 'content-type': 'application/json' } });

const ContentStack = require('contentstack');
const stack = new ContentStack.Stack({ api_key: 'k', delivery_token: 't', environment: 'live' });
await stack.ContentType('list').Entry('u1').only('items', ['uid']).fetch();
// throws TypeError: Cannot call a class as a function
// after this fix: resolves correctly

For 3.18.0–3.23.x the same failure reproduces with node-fetch stubbed instead of global.fetch (those versions use the node-fetch dependency).

Fix

Add the missing new keyword at the 5 Result(...) call sites in resultWrapper().

Verified by applying the equivalent change to the built dist/node/contentstack.js and re-running the repro above — the entry resolves correctly.

cs-raj and others added 30 commits October 18, 2024 18:29
…dle-empty-entries

dx | 1675 handle empty entries
* Include HTTP error codes in the findOne method

* Added testcases
fix: added fix for updateasseturl for handling jrte within blocks
…estcases

Updated error codes in testcases
…p-isomorphic-fetch-node-fetch

dx 1415 drop isomorphic fetch and node fetch
dhavaljain999 and others added 27 commits March 3, 2026 13:30
- Add .catch() on response.json() in 200 and non-200 branches to handle body-read failures
- Retry on socket/abort errors (terminated, UND_ERR_SOCKET, UND_ERR_ABORTED) via onError()
- Treat fetch-level and body-read socket errors consistently; reject with actual error when not retrying
- Add SDK engineering investigation doc for UND_ERR_SOCKET handling

Made-with: Cursor
…-err-socket-422-errors

fix: Handle connection drops (UND_ERR_SOCKET) and prevent process crash
…ate-cursor-rules-skills

docs: add AGENTS.md, skills, and Cursor rules entry
…-release-process

DX-6158: new release process
Brings in SDK v3.27.0 changes:
- fix: handle connection drops (UND_ERR_SOCKET/UND_ERR_ABORTED) with retry logic in request.js
- refactor: remove unused variables (environment, api_key) from request.js
- chore: version bump 3.26.4 → 3.27.0
- chore: dependency updates in package-lock.json
- ci: update sca-scan.yml

All comprehensive integration test files retained unchanged.
Updated .talismanrc checksums for package-lock.json and request.js.
Adds tests covering the new UND_ERR_SOCKET / UND_ERR_ABORTED retry logic
introduced in src/core/lib/request.js (v3.27.0).

RetryLogic.test.js — Socket & Transport Error Handling:
- RetryLogic_AuthError_FailsFast_NotSlowedByRetryDelay: timing proof
  that 4xx errors are never retried regardless of retryLimit/retryDelay
- RetryLogic_CustomRetryCondition_InvokesOnError_WithDelayBetweenRetries:
  proves retryCondition → onError() wiring applies retry delays
- RetryLogic_ZeroRetryLimit_NetworkFailure_RejectsWithoutWaiting: proves
  the retryLimit > 0 guard in the new socket-error path is enforced

ErrorHandling.test.js — Transport Layer vs API Errors:
- ErrorHandling_TransportError_HasNoAPIErrorCode: transport errors must
  not be wrapped with API error_code fields
- ErrorHandling_APIError_StructureDistinctFromTransportError: proves the
  two error shapes remain distinguishable for app-level error routing
- ErrorHandling_ZeroRetryLimit_TransportError_ErrorShapeUnchanged: proves
  retryLimit does not mutate the error object shape

Also removes stale duplicate test/config.js entry from .talismanrc.
Addresses test failures caused by slow network responses and insufficient
timeouts in CI environments.

Timeout increases:
- SyncAPI: 30000ms on 6 sync operation tests
- LogicalOperators: 15000ms/20000ms on OR queries, 5000ms on performance tests
- PerformanceBenchmarks: 30000ms on sequential throughput test
- ConcurrentRequests: 20000ms on concurrent-filters test, 30000ms on
  sequential-vs-concurrent timing test
- CustomParameters: 15000ms on complex combination test
- AdvancedEdgeCases: 15000ms on large-skip test
- ContentTypeOperations: 15000ms on filtered-count test
- ModularBlocksHandling: 15000ms on block validation test
- ExistsSearchOperators: 15000ms on exists+notExists combination test
- NumericOperators: 5000ms threshold (up from 3000ms)

Bug fixes:
- ConcurrentRequests: replace Promise.all with Promise.allSettled on
  50-concurrent-requests test; assert >=80% success rate instead of
  requiring 100% (ECONNRESET under high load is expected behavior)
- asset-query.test.ts: pass error to done() in catch block so Jest
  reports the actual failure instead of swallowing it; add 15000ms timeout
Adds NESTED_GLOBAL_FIELD_UID environment variable support and a 671-line
comprehensive test suite for nested global fields.

test/config.js:
- Added nested global field entry reading from NESTED_GLOBAL_FIELD_UID
- Added fallback env var names for global fields (GLOBAL_FIELD_UID,
  SIMPLE/MEDIUM/COMPLEX_GLOBAL_FIELD_UID) for broader stack compatibility

test/helpers/TestDataHelper.js:
- Added getNestedGlobalFieldUID() accessor method

test/integration/GlobalFieldsTests/NestedGlobalField.test.js (new):
- 671-line test suite for nested global field resolution
- Covers: 6-level deep nesting, child field access, projection with
  nested fields, reference resolution inside nested structures,
  array handling, and circular reference safety
Auto-fix trailing spaces and multi-space violations across all test
files to pass the CI lint check. Also adds talisman_report to
.gitignore and updates .talismanrc checksums for modified files.
…ensive-integration-tests

feat: comprehensive integration test suite with 737 tests
…cy folders

Moved test coverage from test/asset and test/entry into the integration
test suite (AssetQuery, ImageTransformation, ErrorHandling, UtilityMethods).
Deleted the now-redundant test/asset and test/entry directories.
chore: migrate asset/entry tests to integration suite and removelegacy test/asset and test/entry folders
@achromik
achromik requested a review from a team as a code owner June 11, 2026 10:45
@reeshika-h
reeshika-h requested a review from a team as a code owner August 7, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.