Skip to content

Commit

Permalink
Merge pull request #7 from contentstack/feat/CS-44692-variants-and-re…
Browse files Browse the repository at this point in the history
…lease-preview

feat: adds variants and release preview feature
  • Loading branch information
nadeem-cs authored Apr 29, 2024
2 parents d6f3a3e + 80037be commit 1eaf3d1
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist/
.nx/
reports/
6 changes: 3 additions & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fileignoreconfig:
- filename: test/utils/mocks.ts
checksum: 6936ea8696be3a5daf085b58ec6dd1f10be625ca2674580b0147ae65e42fd350
- filename: package-lock.json
checksum: d088a6f7b7f51da879c65e582037301a21e425c11b1bbb85c410d3c3e087e1f2
checksum: 5ffcf1eea69f53e6899e9ca7e0c088045db2ca3291f30b007f89887e9aadc0d1
- filename: src/lib/content-type.ts
checksum: e8e582d24cbb22b79c91e82939d8a600ffd98f95b7575051d7b568adbf8d5cc8
- filename: src/lib/cache.ts
Expand All @@ -24,9 +24,9 @@ fileignoreconfig:
- filename: src/lib/global-field-query.ts
checksum: 217060ddaedf5b0b50baa6d893bff2f8b71b9cb76885fbf097f748c95692ff71
- filename: src/lib/entries.ts
checksum: 7296d64216993216ed1ea9ba1729cdef0fbe88efc612f49ba846ff9b3e2e0d33
checksum: 12e9b089188aa7d1999fcc9f7081e2ce81da8300012712c29e4d469e98c8c73b
- filename: src/lib/entry.ts
checksum: 9e6f131b59f64f4acc8a26fa757b89ec2456e3f45ed40c1db506b76413feefdb
checksum: d698568eec5f48ff7f15e1d4b25c3a4a786f2128238fc49605cef33c3f6fdae0
- filename: src/persistance/storages/memory-storage.ts
checksum: f5a094538ab269335065e9ac6412dcd5cb107e32efc2fe36e3599aac3268cb54
- filename: src/lib/global-field.ts
Expand Down
144 changes: 72 additions & 72 deletions package-lock.json

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

21 changes: 21 additions & 0 deletions src/lib/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,25 @@ export class Entries extends EntryQueryable {

return new Query(this._client, this._contentTypeUid);
}

/**
* @method variants
* @memberof Entry
* @description The variant header will be added to axios client
* @returns {Entry}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType('abc').entry().variant('xyz').find();
*/
variants(variants: string | string[]): Entries {
if (Array.isArray(variants) && variants.length > 0) {
this._client.defaults.headers['x-cs-variant-uid'] = variants.join(',');
} else if (typeof variants == 'string' && variants.length > 0) {
this._client.defaults.headers['x-cs-variant-uid'] = variants;
}

return this;
}
}
23 changes: 22 additions & 1 deletion src/lib/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface EntryResponse<T> {
entry: T;
}
export class Entry {
private _client: AxiosInstance;
protected _client: AxiosInstance;
private _contentTypeUid: string;
private _entryUid: string;
private _urlPath: string;
Expand Down Expand Up @@ -119,6 +119,27 @@ export class Entry {
return this;
}

/**
* @method variants
* @memberof Entry
* @description The variant header will be added to axios client
* @returns {Entry}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType('abc').entry('entry_uid').variant('xyz').fetch();
*/
variants(variants: string | string[]): Entry {
if (Array.isArray(variants) && variants.length > 0) {
this._client.defaults.headers['x-cs-variant-uid'] = variants.join(',');
} else if (typeof variants == 'string' && variants.length > 0) {
this._client.defaults.headers['x-cs-variant-uid'] = variants;
}

return this;
}

/**
* @method fetch
* @memberof Entry
Expand Down
Loading

0 comments on commit 1eaf3d1

Please sign in to comment.