From 5c5620d97fb38a801169599201fa7257ef561d4b Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 25 Nov 2025 15:21:56 +0530 Subject: [PATCH 1/6] Update pubspec.yaml for SDK and dependency versions; refactor error handling in contentstack_utils.dart, GQL.dart, and Automate.dart to use centralized error messages; enhance Metadata and Option classes for null safety; adjust tests for updated functionality. --- lib/contentstack_utils.dart | 13 +++++++------ lib/src/GQL.dart | 3 ++- lib/src/constants/ErrorMessages.dart | 14 ++++++++++++++ lib/src/helper/Automate.dart | 14 ++++++++------ lib/src/helper/Metadata.dart | 28 ++++++++++++++-------------- lib/src/model/Option.dart | 12 +++++++----- pubspec.yaml | 14 +++++++------- test/utils_test.dart | 3 ++- 8 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 lib/src/constants/ErrorMessages.dart diff --git a/lib/contentstack_utils.dart b/lib/contentstack_utils.dart index a4ca304..e5186b8 100644 --- a/lib/contentstack_utils.dart +++ b/lib/contentstack_utils.dart @@ -1,5 +1,6 @@ library contentstack_utils; +import 'package:contentstack_utils/src/constants/ErrorMessages.dart'; import 'package:contentstack_utils/src/helper/Automate.dart'; import 'package:contentstack_utils/src/model/Option.dart'; export 'src/embedded/StyleType.dart'; @@ -8,14 +9,14 @@ export 'src/helper/Metadata.dart'; class Utils { static void render(jsonObject, List rteKeys, Option option) { if (!Automate.isValidJson(jsonObject)) { - throw FormatException('Invalid file, Can\'t process the json file'); + throw FormatException(ErrorMessages.invalidJsonFile); } if (jsonObject is List) { for (var entry in jsonObject) { render(entry, rteKeys, option); } - } else if (jsonObject is Map) { + } else if (jsonObject is Map) { if (jsonObject.containsKey('_embedded_items')) { if (rteKeys.isNotEmpty) { for (var path in rteKeys) { @@ -24,8 +25,8 @@ class Utils { }); } } else { - Map embeddedKeys = jsonObject['_embedded_items']; - rteKeys = embeddedKeys.keys.toList(); + Map embeddedKeys = jsonObject['_embedded_items'] as Map; + rteKeys = embeddedKeys.keys.toList().cast(); embeddedKeys.keys.forEach((keyPath) { Automate.find_embed_keys(jsonObject, keyPath, (rteContent) { return renderContent(rteContent, jsonObject, option); @@ -34,7 +35,7 @@ class Utils { } } } else { - FormatException('Invalid file for embedded objects'); + throw FormatException(ErrorMessages.invalidEmbeddedObjectsInput); } } @@ -69,7 +70,7 @@ class Utils { static void jsonToHTML(items, List key_path, Option option) { if (!Automate.isValidJson(items)) { - throw FormatException('Invalid file, Can\'t process the json file'); + throw FormatException(ErrorMessages.invalidJsonFile); } if (items is List) { diff --git a/lib/src/GQL.dart b/lib/src/GQL.dart index 47fa505..958b104 100644 --- a/lib/src/GQL.dart +++ b/lib/src/GQL.dart @@ -1,10 +1,11 @@ +import 'package:contentstack_utils/src/constants/ErrorMessages.dart'; import 'package:contentstack_utils/src/helper/Automate.dart'; import 'package:contentstack_utils/src/model/Option.dart'; class GQL { static void jsonToHTML(items, List key_path, Option option) { if (!Automate.isValidJson(items)) { - throw FormatException('Invalid file, Can\'t process the json file'); + throw FormatException(ErrorMessages.invalidJsonFile); } if (items is List) { diff --git a/lib/src/constants/ErrorMessages.dart b/lib/src/constants/ErrorMessages.dart new file mode 100644 index 0000000..2d8c7ba --- /dev/null +++ b/lib/src/constants/ErrorMessages.dart @@ -0,0 +1,14 @@ +/// Error message constants for Contentstack Utils +/// +/// This file contains all error messages used throughout the library +/// to ensure consistency and ease of maintenance. +class ErrorMessages { + // JSON validation errors + static const String invalidJsonFile = + 'Invalid JSON file. Provide a valid JSON file and try again.'; + + // Embedded objects errors + static const String invalidEmbeddedObjectsInput = + 'Invalid input for embedded objects. Expected a Map or List.'; +} + diff --git a/lib/src/helper/Automate.dart b/lib/src/helper/Automate.dart index fcf6011..09e4a42 100644 --- a/lib/src/helper/Automate.dart +++ b/lib/src/helper/Automate.dart @@ -21,13 +21,15 @@ class Automate { } } - static Map findEmbeddedItems(Map jsonObject, Metadata metadata) { + static Map? findEmbeddedItems(Map jsonObject, Metadata metadata) { var keys = jsonObject.keys; for (var item in keys) { List jsonArray = jsonObject[item]; var filteredContent = jsonArray - .firstWhere((element) => element['uid'] == metadata.getItemUid); - return filteredContent; + .firstWhere((element) => element['uid'] == metadata.getItemUid, orElse: () => null); + if (filteredContent != null) { + return filteredContent; + } } return null; } @@ -169,7 +171,7 @@ class Automate { } } - static Object findEmbeddedEntry(List jsonList, Metadata metadata) { + static Object? findEmbeddedEntry(List jsonList, Metadata metadata) { for (var obj in jsonList) { if (obj is Map) { if (obj['uid'] == metadata.getItemUid) { @@ -189,8 +191,8 @@ class Automate { return null; } - static String getStringOption(Option option, Metadata meta, Map content) { - var stringOption = option.renderOption(content, meta); + static String getStringOption(Option option, Metadata meta, Object content) { + var stringOption = option.renderOption(content as Map, meta); return stringOption; } diff --git a/lib/src/helper/Metadata.dart b/lib/src/helper/Metadata.dart index aa56fab..5012d31 100644 --- a/lib/src/helper/Metadata.dart +++ b/lib/src/helper/Metadata.dart @@ -3,13 +3,13 @@ import 'dart:collection'; import 'package:html/dom.dart'; class Metadata { - String text; - String itemType; - String itemUid; - String contentTypeUid; - String styleType; - String outerHTML; - LinkedHashMap attributes; + String? text; + String? itemType; + String? itemUid; + String? contentTypeUid; + String? styleType; + String? outerHTML; + LinkedHashMap? attributes; Metadata( {this.text, @@ -20,19 +20,19 @@ class Metadata { this.outerHTML, this.attributes}); - String get getText => text; + String? get getText => text; - String get getItemType => itemType; + String? get getItemType => itemType; - String get getItemUid => itemUid; + String? get getItemUid => itemUid; - String get getContentTypeUid => contentTypeUid; + String? get getContentTypeUid => contentTypeUid; - String get getStyleType => styleType; + String? get getStyleType => styleType; - String get getOuterHTML => outerHTML; + String? get getOuterHTML => outerHTML; - LinkedHashMap get getAttributes => attributes; + LinkedHashMap? get getAttributes => attributes; Metadata.element(Element element) { text = element.text; diff --git a/lib/src/model/Option.dart b/lib/src/model/Option.dart index 6cdd5ee..1eb127e 100644 --- a/lib/src/model/Option.dart +++ b/lib/src/model/Option.dart @@ -21,8 +21,9 @@ class Option { static String _findInlineLink(Metadata metadata, Map obj) { var _title = ''; - if (metadata.getText.isNotEmpty) { - _title = metadata.getText; + var metadataText = metadata.getText; + if (metadataText != null && metadataText.isNotEmpty) { + _title = metadataText; } else if (obj.containsKey('title')) { _title = obj['title']; } else if (obj.containsKey('uid')) { @@ -42,8 +43,9 @@ class Option { static String _findDisplayAtrr(Metadata metadata, Map obj) { var _title = ''; - if (metadata.attributes.isNotEmpty) { - _title = metadata.attributes.toString(); + var metadataAttrs = metadata.attributes; + if (metadataAttrs != null && metadataAttrs.isNotEmpty) { + _title = metadataAttrs.toString(); } else if (obj.containsKey('title')) { _title = obj['title']; } else if (obj.containsKey('filename')) { @@ -60,7 +62,7 @@ class Option { } String renderOption(Map obj, Metadata metadata) { - var style = metadata.styleType; + var style = metadata.styleType ?? ''; switch (style) { case 'block': var titlOrUid = _findTitleOrUid(obj); diff --git a/pubspec.yaml b/pubspec.yaml index 33b9563..38e3af3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,17 +4,17 @@ version: 1.1.0 homepage: https://www.contentstack.com environment: - sdk: ">=2.8.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" dependencies: #dartdoc: ^1.0.2 - lint: ^1.3.0 - path: ^1.7.0 - html: ^0.14.0+4 - logger: ^1.0.0 + lint: ^2.0.0 + path: ^1.8.0 + html: ^0.15.6 + logger: ^2.0.0 dev_dependencies: - pedantic: ^1.11.1 - test: ^1.17.5 + lints: ^2.0.0 + test: ^1.24.0 # test_coverage: ^0.4.1 \ No newline at end of file diff --git a/test/utils_test.dart b/test/utils_test.dart index a616783..2ea2f88 100644 --- a/test/utils_test.dart +++ b/test/utils_test.dart @@ -48,7 +48,8 @@ void main() { final _item = _entryArray['entries'][0]; final option = Option.entry(_item); final result = Utils.renderContent(__stringHtmlEntry, _item, option); - logger.i(result); + //logger.i(result); + expect(result, isNotNull); }); test('utils.render pass invalid json to cover exception', () { From d41c36bcb6fb4ce9dc7dba61139dfb1322867236 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Thu, 8 Jan 2026 13:17:59 +0530 Subject: [PATCH 2/6] version bump --- CHANGELOG.md | 5 +++++ LICENSE | 2 +- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7923521..9f8c574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v1.1.1 + +- Improved error messages +___________________ + ## v1.1.0 Implemented SRTE functions: :tada: diff --git a/LICENSE b/LICENSE index 3855421..b652690 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2012 - 2021 Contentstack +Copyright (c) 2012 - 2026 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pubspec.yaml b/pubspec.yaml index 38e3af3..cca5f5f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: contentstack_utils description: Utils package for Contentstack-dart -version: 1.1.0 +version: 1.1.1 homepage: https://www.contentstack.com environment: From 80c368f4a5618776e4a057795f1f1d00b1f65038 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Fri, 9 Jan 2026 13:28:25 +0530 Subject: [PATCH 3/6] added security file --- SECURITY.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..b5fe070 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,27 @@ +## Security + +Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations. + +If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below. + +## Reporting Security Issues + +**Please do not report security vulnerabilities through public GitHub issues.** + +Send email to [security@contentstack.com](mailto:security@contentstack.com). + +You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. + +Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: + + * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) + * Full paths of source file(s) related to the manifestation of the issue + * The location of the affected source code (tag/branch/commit or direct URL) + * Any special configuration required to reproduce the issue + * Step-by-step instructions to reproduce the issue + * Proof-of-concept or exploit code (if possible) + * Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/) From 582ad029761e0c6d0e8fc0e906046e167e306c76 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Fri, 9 Jan 2026 13:34:16 +0530 Subject: [PATCH 4/6] Update SCA workflow to use OSV Scanner and Dart setup; --- .github/workflows/sca-scan.yml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index f09161f..5fabf87 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -6,10 +6,27 @@ jobs: security-sca: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/node@master - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + - uses: actions/checkout@v4 + + - name: Set up Dart + uses: dart-lang/setup-dart@v1 with: - args: --all-projects --fail-on=all + sdk: stable + + - name: Install dependencies + run: dart pub get + + - name: Check for outdated dependencies + run: dart pub outdated --json > outdated.json || true + + - name: Run OSV Scanner for vulnerabilities + uses: google/osv-scanner-action@v1 + with: + scan-args: |- + --lockfile=pubspec.lock + + - name: Display outdated packages + if: always() + run: | + echo "Checking for outdated packages..." + dart pub outdated || true From 167ff1d236ff22df4e06946a469ee9eaa40dc3cb Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Fri, 9 Jan 2026 13:36:21 +0530 Subject: [PATCH 5/6] Refactor SCA workflow to streamline OSV Scanner integration and improve output handling --- .github/workflows/sca-scan.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index 5fabf87..b425f01 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -17,16 +17,20 @@ jobs: run: dart pub get - name: Check for outdated dependencies - run: dart pub outdated --json > outdated.json || true + run: dart pub outdated || true - name: Run OSV Scanner for vulnerabilities - uses: google/osv-scanner-action@v1 - with: - scan-args: |- - --lockfile=pubspec.lock + run: | + curl -L https://github.com/google/osv-scanner/releases/latest/download/osv-scanner_linux_amd64 -o osv-scanner + chmod +x osv-scanner + ./osv-scanner --lockfile=pubspec.lock --format=json --output=osv-results.json || true - - name: Display outdated packages + - name: Display OSV Scanner results if: always() run: | - echo "Checking for outdated packages..." - dart pub outdated || true + if [ -f osv-results.json ]; then + echo "OSV Scanner Results:" + cat osv-results.json + else + echo "No vulnerabilities found!" + fi From cd5c03a221c0637b11e9682eb36210c302c6aed8 Mon Sep 17 00:00:00 2001 From: harshithad0703 <104908717+harshithad0703@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:22:47 +0530 Subject: [PATCH 6/6] Change PR merge restrictions from 'next' to 'staging' --- .github/workflows/check-branch.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-branch.yml b/.github/workflows/check-branch.yml index 1e2d24a..2332f0d 100644 --- a/.github/workflows/check-branch.yml +++ b/.github/workflows/check-branch.yml @@ -8,13 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Comment PR - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' uses: thollander/actions-comment-pull-request@v2 with: message: | - We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. + We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the staging branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch. - name: Check branch - if: github.base_ref == 'master' && github.head_ref != 'next' + if: github.base_ref == 'master' && github.head_ref != 'staging' run: | - echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." - exit 1 \ No newline at end of file + echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the staging branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch." + exit 1