Skip to content

dx | 2231 handle envs #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 8, 2025
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Change log

### Version: 3.25.3
#### Date: April-21-2025
##### Fix:
- Handle the sanity tests when ENVs are not provided

### Version: 3.25.2
#### Date: April-02-2025
##### Fix:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ For browsers, we recommend to download the library via npm or yarn to ensure 100
If you'd like to use a standalone built file you can use the following script tag or download it from [jsDelivr](https://www.jsdelivr.com/package/npm/contentstack), under the `dist` directory:

```html
<script src="https://cdn.jsdelivr.net/npm/contentstack@latest/dist/web/contentstack.min.js" integrity="9u29niwIJG3dEc7vPUc1ZA1Dl/uaiR4+s7k55kb/CCkzTzyFuZHNM165BQ10+Hiw%" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/contentstack@latest/dist/web/contentstack.min.js" integrity="12nVcFP1kBh/0Q5rLUvKE34exDRK2DpHUFkGkhRSXTcwGC2PI1D9h64C5arpt5OY" crossorigin="anonymous"></script>
```
You can also specify a specific version number.
```html
<script src="https://cdn.jsdelivr.net/npm/contentstack@3.20.3/dist/web/contentstack.min.js" integrity="9u29niwIJG3dEc7vPUc1ZA1Dl/uaiR4+s7k55kb/CCkzTzyFuZHNM165BQ10+Hiw%" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/contentstack@3.25.2/dist/web/contentstack.min.js" integrity="fXmq+b/kd2EenBR7APjzzy0hLTOhAhrir3C6HZYZKuF9O+g+HuSIU7Usi8Ccy9I5" crossorigin="anonymous"></script>
```

To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.25.2",
"version": "3.25.3",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down
12 changes: 11 additions & 1 deletion test/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
'use strict';
require('dotenv').config()
require('dotenv').config();

const requiredVars = ['HOST', 'EMAIL', 'PASSWORD', 'ORGANIZATION', 'API_KEY'];
const missingVars = requiredVars.filter((key) => !process.env[key]);

if (missingVars.length > 0) {
const errorMessage = `\x1b[31mError: Missing environment variables - ${missingVars.join(', ')}`;
const error = new Error(errorMessage);
error.stack = error.message;
throw error;
}

module.exports = {
stack: { 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT, },
Expand Down
52 changes: 15 additions & 37 deletions test/live-preview/live-preview-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';
const init = require("../config.js");

const Contentstack = require('../../dist/node/contentstack.js');

describe('Contentstack Live Preview Tests', () => {
test('should check for values initialized', () => {
const stack1 = Contentstack.Stack(init.stack)
const stack = Contentstack.Stack({
'api_key': process.env.region_API_KEY,
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT
});
Expand All @@ -16,15 +18,9 @@ describe('Contentstack Live Preview Tests', () => {
});

test('should check host when live preview is enabled and management token is provided', () => {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: true,
management_token: 'management_token'
}
});
init.stack.live_preview.enable = true;
init.stack.live_preview.management_token = 'management_token';
const stack = Contentstack.Stack(init.stack);

const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBe('undefined');
Expand All @@ -34,15 +30,9 @@ describe('Contentstack Live Preview Tests', () => {
});

test('should check host when live preview is disabled and management token is provided', () => {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: false,
management_token: 'management_token'
}
});
init.stack.live_preview.enable = false;
init.stack.live_preview.management_token = 'management_token';
const stack = Contentstack.Stack(init.stack);

const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBe('undefined');
Expand All @@ -51,15 +41,9 @@ describe('Contentstack Live Preview Tests', () => {
});

test('should check host when live preview is enabled and preview token is provided', () => {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: true,
preview_token: 'preview_token'
}
});
init.stack.live_preview.enable = true;
init.stack.live_preview.preview_token = 'preview_token';
const stack = Contentstack.Stack(init.stack);

const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBe('undefined');
Expand All @@ -70,15 +54,9 @@ describe('Contentstack Live Preview Tests', () => {
});

test('should check host when live preview is disabled and preview token is provided', () => {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: false,
preview_token: 'preview_token'
}
});
init.stack.live_preview.enable = false;
init.stack.live_preview.preview_token = 'preview_token';
const stack = Contentstack.Stack(init.stack);

const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBe('undefined');
Expand Down
Loading