Skip to content

Commit cf78ca2

Browse files
Merge pull request #2 from contentstack/next
next to master
2 parents 4ad6f15 + 4a452a5 commit cf78ca2

File tree

99 files changed

+20087
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+20087
-1
lines changed

.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

.github/workflows/check-branch.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Check Branch'
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
check_branch:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Comment PR
11+
if: github.base_ref == 'master' && github.head_ref != 'next'
12+
uses: thollander/actions-comment-pull-request@v2
13+
with:
14+
message: |
15+
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.
16+
- name: Check branch
17+
if: github.base_ref == 'master' && github.head_ref != 'next'
18+
run: |
19+
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."
20+
exit 1

.github/workflows/npm-publish.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will publish a package to GitHub Packages when a release is created
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3+
4+
name: Publish package to NPM repository
5+
on:
6+
release:
7+
types: [created]
8+
9+
jobs:
10+
publish-npm:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: '18.x'
17+
registry-url: 'https://registry.npmjs.org'
18+
- run: npm ci
19+
- run: npm publish --tag latest --access public
20+
env:
21+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
22+
publish-git:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: actions/setup-node@v3
27+
with:
28+
node-version: '18.x'
29+
registry-url: 'https://npm.pkg.github.com'
30+
scope: '@contentstack'
31+
- run: npm ci
32+
- run: npm publish --tag latest
33+
env:
34+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.DS_Store
2+
**/node_modules/*
3+
.idea/*
4+
reports/*
5+
apidocs-templates/*
6+
test/smtpconfig.js/*
7+
test/config.js/*
8+
test/sync_config.js/*
9+
test/report.json/*
10+
tap-html.html
11+
*html-report
12+
coverage
13+
.env
14+
.dccache
15+
dist/*

.npmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
docs-config.json
2+
.idea/
3+
.git/
4+
test.js
5+
test/
6+
reports/
7+
contentstack-templates/
8+
js-sdk-reference/
9+
examples/
10+
mocktest.json
11+
webpack
12+
typescript-html-report
13+
webpack
14+
jest.config.js
15+
coverage
16+
CODEOWNERS
17+
src
18+
.env
19+
*.tgz
20+
.talismanrc
21+
tap-html.html
22+
.github

.talismanrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fileignoreconfig:
2+
- filename: test/unit/image-transform.spec.ts
3+
checksum: 7beabdd07bd35d620668fcd97e1a303b9cbc40170bf3008a376d75ce0895de2a
4+
- filename: test/utils/mocks.ts
5+
checksum: a1cb4b1890a584f1facd30f2a0974c97a66f91417022be79d00516338e244227
6+
- filename: package-lock.json
7+
checksum: 6c9beae17fc270641d855026896e49a1458a6b3a026df30265c51420d364d18a
8+
- filename: test/typescript/taxonomy.test.ts
9+
checksum: e4bdf633e147fd60d929d379f20c814eed5f68b11421d7b53ec8826e9142de37
10+
- filename: src/core/modules/taxonomy.js
11+
checksum: 84589be9805c1be5fd6c56021c41d18365126cf82059ad2cbef1d418c70d08e0
12+
- filename: src/core/lib/utils.js
13+
checksum: 6018f9f13fa32b724d09b9cdf5f78cf030a6332ca549651e1e35fe91e8c7e0e7
14+
- filename: src/core/modules/query.js
15+
checksum: c88b336f9a271397ffedcf8c5085941ceb0bd1cd7e25ed9ada3acd8ce4f8970c
16+
- filename: test/typescript/stack.test.ts
17+
checksum: bbb3c425f8e1a63d4793f69ee9eaba9559294ff53f163a28f70ae54b1792276a
18+
version: ""

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Change log
2+
3+
4+
### Version: 4.0.0
5+
#### Date: April-23-2024
6+
Official release of Typescript SDK
7+
8+
### Version: 4.0.0-beta.6
9+
#### Date: April-09-2024
10+
##### New Features:
11+
- Query operators implementation-3
12+
13+
### Version: 4.0.0-beta.5
14+
#### Date: March-26-2024
15+
##### New Features:
16+
- Query operators implementation-2
17+
18+
### Version: 4.0.0-beta.4
19+
#### Date: March-14-2024
20+
##### New Features:
21+
- Query operators implementation
22+
23+
### Version: 4.0.0-beta.3
24+
#### Date: February-13-2024
25+
- Live preview support 1.0 and 2.0
26+
27+
### Version: v4.0.0-beta.2
28+
#### Date: February-02-2024
29+
- Includes adding of prepare script to build package
30+
31+
### Version: 4.0.0-beta
32+
#### Date: January-15-2024
33+
- Beta release of Typescript SDK

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @contentstack/security-admin

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
4+
Copyright (c) 2016-2024 Contentstack
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,149 @@
1-
# contentstack-typescript
1+
[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
2+
## Typescript Content Delivery SDK for Contentstack
3+
4+
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
5+
6+
Contentstack provides Typescript SDK to build application on top of Typescript. Given below is the detailed guide and helpful resources to get started with our Typescript SDK.
7+
8+
The Typescript SDK can also be used to create Node.js and React native applications.
9+
10+
### Prerequisite
11+
12+
You need Node.js version 4.4.7 or later installed to use the Contentstack JavaScript SDK.
13+
14+
### Setup and Installation
15+
16+
Node.js uses the Typescript SDK to create apps. To use the Typescript SDK, install it via npm:
17+
18+
```bash
19+
npm i @contentstack/delivery-sdk
20+
```
21+
22+
To import the SDK in your project, use the following command:
23+
24+
```typescript
25+
import contentstack from '@contentstack/delivery-sdk'
26+
```
27+
28+
To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.
29+
30+
```typescript
31+
import contentstack from '@contentstack/delivery-sdk'
32+
const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
33+
```
34+
35+
### Key Concepts for using Contentstack
36+
37+
#### Stack
38+
39+
A stack is like a container that holds the content of your app. Learn more about [Stacks](https://www.contentstack.com/docs/guide/stack).
40+
41+
#### Content Type
42+
43+
Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. [Read more](https://www.contentstack.com/docs/guide/content-types).
44+
45+
#### Entry
46+
47+
An entry is the actual piece of content created using one of the defined content types. Learn more about [Entries](https://www.contentstack.com/docs/guide/content-management#working-with-entries).
48+
49+
#### Asset
50+
51+
Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about [Assets](https://www.contentstack.com/docs/guide/content-management#working-with-assets).
52+
53+
#### Environment
54+
55+
A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with [Environments](https://www.contentstack.com/docs/guide/environments).
56+
57+
### Contentstack Typescript SDK
58+
59+
#### Initializing your SDK
60+
61+
You will need to specify the API key, Delivery Token, and Environment Name of your stack to initialize the SDK:
62+
63+
```typescript
64+
const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
65+
```
66+
67+
Once you have initialized the SDK, you can start getting content in your app.
68+
69+
#### Querying content from your stack
70+
71+
To get a single entry, you need to specify the content type as well as the ID of the entry.
72+
73+
```typescript
74+
import { BaseEntry } from '@contentstack/delivery-sdk'
75+
interface BlogPostEntry extends BaseEntry {
76+
// custom entry types
77+
}
78+
const result = await stack
79+
.contentType(contentType_uid)
80+
.entry(entry_uid)
81+
.fetch<BlogPostEntry>();
82+
```
83+
84+
To retrieve multiple entries of a content type, you need to specify the content type uid. You can also specify search parameters to filter results.
85+
86+
```typescript
87+
import { BaseEntry, FindEntry } from '@contentstack/delivery-sdk'
88+
interface BlogPostEntry extends BaseEntry {
89+
// custom entry types
90+
}
91+
const result = await stack.contentType("contentType1Uid").entry()
92+
.query()
93+
.find<BlogPostEntry>()
94+
```
95+
96+
### Advanced Queries
97+
98+
You can query for content types, entries, assets and more using our Typescript API Reference.
99+
100+
[Typescript API Reference Doc](https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/typescript/reference#contentstack)
101+
102+
### Working with Images
103+
104+
We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.
105+
106+
For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/owl.jpg?crop=300,400. There are several more parameters that you can use for your images.
107+
108+
[Read Image Delivery API documentation](https://www.contentstack.com/docs/developers/apis/image-delivery-api/).
109+
110+
Following are Image Delivery API examples.
111+
112+
```typescript
113+
const url = 'www.example.com';
114+
const transformObj = new imageTransform().bgColor('cccccc');
115+
const transformURL = url.transform(transformObj);
116+
```
117+
118+
119+
### Pagination
120+
121+
If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would be paginated. It provides pagination token in the response. You will need to use this token to get the next batch of data.
122+
123+
```typescript
124+
const query = stack.contentType("contentTypeUid").entry().query();
125+
const pagedResult = await query
126+
.paginate()
127+
.find<BlogPostEntry>();
128+
// OR
129+
const pagedResult = await query
130+
.paginate({ skip: 20, limit: 20 })
131+
.find<BlogPostEntry>();
132+
133+
```
134+
135+
### Helpful Links
136+
137+
- [Contentstack Website](https://www.contentstack.com)
138+
- [Official Documentation](https://contentstack.com/docs)
139+
- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/)
140+
141+
### The MIT License (MIT)
142+
143+
Copyright © 2012-2024 [Contentstack](https://www.contentstack.com). All Rights Reserved
144+
145+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
146+
147+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148+
149+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)