Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/check-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
33 changes: 27 additions & 6 deletions .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,31 @@ 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 || true

- name: Run OSV Scanner for vulnerabilities
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 OSV Scanner results
if: always()
run: |
if [ -f osv-results.json ]; then
echo "OSV Scanner Results:"
cat osv-results.json
else
echo "No vulnerabilities found!"
fi
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.1.1

- Improved error messages
___________________

## v1.1.0

Implemented SRTE functions: :tada:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 27 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -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/)
13 changes: 7 additions & 6 deletions lib/contentstack_utils.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,14 +9,14 @@ export 'src/helper/Metadata.dart';
class Utils {
static void render(jsonObject, List<String> 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<String, Object>) {
} else if (jsonObject is Map) {
if (jsonObject.containsKey('_embedded_items')) {
if (rteKeys.isNotEmpty) {
for (var path in rteKeys) {
Expand All @@ -24,8 +25,8 @@ class Utils {
});
}
} else {
Map<String, Object> embeddedKeys = jsonObject['_embedded_items'];
rteKeys = embeddedKeys.keys.toList();
Map embeddedKeys = jsonObject['_embedded_items'] as Map;
rteKeys = embeddedKeys.keys.toList().cast<String>();
embeddedKeys.keys.forEach((keyPath) {
Automate.find_embed_keys(jsonObject, keyPath, (rteContent) {
return renderContent(rteContent, jsonObject, option);
Expand All @@ -34,7 +35,7 @@ class Utils {
}
}
} else {
FormatException('Invalid file for embedded objects');
throw FormatException(ErrorMessages.invalidEmbeddedObjectsInput);
}
}

Expand Down Expand Up @@ -69,7 +70,7 @@ class Utils {

static void jsonToHTML(items, List<String> 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) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/GQL.dart
Original file line number Diff line number Diff line change
@@ -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<String> 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) {
Expand Down
14 changes: 14 additions & 0 deletions lib/src/constants/ErrorMessages.dart
Original file line number Diff line number Diff line change
@@ -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.';
}

14 changes: 8 additions & 6 deletions lib/src/helper/Automate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
28 changes: 14 additions & 14 deletions lib/src/helper/Metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic, dynamic> attributes;
String? text;
String? itemType;
String? itemUid;
String? contentTypeUid;
String? styleType;
String? outerHTML;
LinkedHashMap<dynamic, dynamic>? attributes;

Metadata(
{this.text,
Expand All @@ -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<dynamic, dynamic> get getAttributes => attributes;
LinkedHashMap<dynamic, dynamic>? get getAttributes => attributes;

Metadata.element(Element element) {
text = element.text;
Expand Down
12 changes: 7 additions & 5 deletions lib/src/model/Option.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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')) {
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: contentstack_utils
description: Utils package for Contentstack-dart
version: 1.1.0
version: 1.1.1
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

3 changes: 2 additions & 1 deletion test/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down