@nascentdigital/funnel-cms 6.1.2 → 6.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,9 +3,9 @@ import { IContentfulContentClient } from './IContentfulContentClient';
|
|
|
3
3
|
export declare class ContentfulAssetClient implements AssetClient {
|
|
4
4
|
readonly cms: IContentfulContentClient;
|
|
5
5
|
constructor(cms: IContentfulContentClient);
|
|
6
|
-
getAssets(
|
|
7
|
-
getAsset(
|
|
6
|
+
getAssets({ pagination, ...query }: AssetClient.GetAssets.Args): Promise<AssetClient.GetAssets.Result>;
|
|
7
|
+
getAsset(assetId: AssetClient.GetAsset.Args): Promise<AssetClient.GetAsset.Result>;
|
|
8
8
|
createAsset(args: AssetClient.CreateAsset.Args): Promise<AssetClient.CreateAsset.Result>;
|
|
9
|
-
updateAsset(
|
|
9
|
+
updateAsset({ id, ...updates }: AssetClient.UpdateAsset.Args): Promise<AssetClient.UpdateAsset.Result>;
|
|
10
10
|
deleteAsset(args: AssetClient.DeleteAsset.Args): Promise<AssetClient.DeleteAsset.Result>;
|
|
11
11
|
}
|
|
@@ -1,26 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.ContentfulAssetClient = void 0;
|
|
4
15
|
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
|
+
const models_1 = require("./models");
|
|
5
17
|
// class
|
|
6
18
|
class ContentfulAssetClient {
|
|
7
19
|
constructor(cms) {
|
|
8
20
|
this.cms = cms;
|
|
9
21
|
}
|
|
10
|
-
getAssets(
|
|
11
|
-
|
|
22
|
+
async getAssets(_a) {
|
|
23
|
+
var { pagination } = _a, query = __rest(_a, ["pagination"]);
|
|
24
|
+
// fetch items
|
|
25
|
+
const { entries, page, pageCount, totalItemCount } = await this.cms.getEntries(Object.assign({ content_type: models_1.ContentfulAssetData.contentType, pagination }, getAssetQueryParams(query)));
|
|
26
|
+
// return entries
|
|
27
|
+
return {
|
|
28
|
+
items: entries.map(entry => models_1.ContentfulAssetData.deserialize(entry)),
|
|
29
|
+
page, pageCount, totalItemCount
|
|
30
|
+
};
|
|
12
31
|
}
|
|
13
|
-
getAsset(
|
|
14
|
-
|
|
32
|
+
async getAsset(assetId) {
|
|
33
|
+
// try to fetch entry
|
|
34
|
+
const { entry } = await this.cms.getEntry({
|
|
35
|
+
content_type: models_1.ContentfulAssetData.contentType,
|
|
36
|
+
entryId: assetId
|
|
37
|
+
});
|
|
38
|
+
// return undefined if no entry
|
|
39
|
+
if (!entry) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
// return
|
|
43
|
+
return models_1.ContentfulAssetData.deserialize(entry);
|
|
15
44
|
}
|
|
16
45
|
createAsset(args) {
|
|
17
46
|
throw new funnel_core_1.NotImplementedError();
|
|
18
47
|
}
|
|
19
|
-
updateAsset(
|
|
20
|
-
|
|
48
|
+
async updateAsset(_a) {
|
|
49
|
+
var { id } = _a, updates = __rest(_a, ["id"]);
|
|
50
|
+
// fetch latest
|
|
51
|
+
const entry = await this.cms.getEntryData(id);
|
|
52
|
+
const update = Object.assign({ id: entry.id, __version: entry.__version }, funnel_core_1.ObjectUtils.dropUndefined(updates));
|
|
53
|
+
// update entry
|
|
54
|
+
const updatedEntry = await this.cms.updateEntry(update);
|
|
55
|
+
// return updated entry
|
|
56
|
+
return models_1.ContentfulAssetData.deserialize(updatedEntry);
|
|
21
57
|
}
|
|
22
58
|
deleteAsset(args) {
|
|
23
59
|
throw new funnel_core_1.NotImplementedError();
|
|
24
60
|
}
|
|
25
61
|
}
|
|
26
62
|
exports.ContentfulAssetClient = ContentfulAssetClient;
|
|
63
|
+
// helpers
|
|
64
|
+
function getAssetQueryParams(query) {
|
|
65
|
+
// build filters
|
|
66
|
+
const { brand, tags = [], scope, fileType } = query;
|
|
67
|
+
const filters = {};
|
|
68
|
+
// filter brand
|
|
69
|
+
if (brand) {
|
|
70
|
+
filters['fields.brand'] = brand;
|
|
71
|
+
}
|
|
72
|
+
// filter tags
|
|
73
|
+
if (tags.length > 0) {
|
|
74
|
+
filters['fields.tags[all]'] = tags
|
|
75
|
+
.filter((tag) => !!tag)
|
|
76
|
+
.join(',');
|
|
77
|
+
}
|
|
78
|
+
// filter scope
|
|
79
|
+
if (scope) {
|
|
80
|
+
filters['fields.scope'] = scope;
|
|
81
|
+
}
|
|
82
|
+
// filter file type
|
|
83
|
+
if (fileType) {
|
|
84
|
+
filters['fields.type'] = fileType;
|
|
85
|
+
}
|
|
86
|
+
// return filters
|
|
87
|
+
return filters;
|
|
88
|
+
}
|
|
@@ -8,7 +8,7 @@ export declare class ContentfulPageClient implements PageClient {
|
|
|
8
8
|
getOverview(args: PageClient.GetOverview.Args): Promise<PageClient.GetOverview.Result>;
|
|
9
9
|
getSummaries(args: PageClient.GetSummaries.Args): Promise<PageClient.GetSummaries.Result>;
|
|
10
10
|
getPreviews(args: PageClient.GetPreviews.Args): Promise<PageClient.GetPreviews.Result>;
|
|
11
|
-
search(
|
|
11
|
+
search({ version, pagination, ...query }: PageClient.Search.Args): Promise<PageClient.Search.Result>;
|
|
12
12
|
query(args: PageClient.Query.Args): Promise<PageClient.Query.Result>;
|
|
13
13
|
find(args: PageClient.Find.Args): Promise<PageClient.Find.Result>;
|
|
14
14
|
getGroup(args: PageClient.GetGroup.Args): Promise<ContentfulPageClient.GetGroup.Result>;
|
|
@@ -72,10 +72,12 @@ class ContentfulPageClient {
|
|
|
72
72
|
getPreviews(args) {
|
|
73
73
|
throw new funnel_core_1.NotImplementedError();
|
|
74
74
|
}
|
|
75
|
-
async search(
|
|
75
|
+
async search(_a) {
|
|
76
|
+
var { version, pagination } = _a, query = __rest(_a, ["version", "pagination"]);
|
|
76
77
|
// fetch items (bail if there are no instances)
|
|
77
78
|
const { cms } = this;
|
|
78
|
-
const { entries, page, pageCount, totalItemCount } = await cms.getEntries(Object.assign({ content_type: models_1.ContentfulPageData.contentType, version
|
|
79
|
+
const { entries, page, pageCount, totalItemCount } = await cms.getEntries(Object.assign({ content_type: models_1.ContentfulPageData.contentType, version,
|
|
80
|
+
pagination, select: getPageSelect(funnel_core_1.Schema.Page.Data.AsLink.props) }, getPageQueryParams(query)));
|
|
79
81
|
// return entries
|
|
80
82
|
return {
|
|
81
83
|
items: entries.map(entry => models_1.ContentfulPageData.deserialize(entry, funnel_core_1.Schema.Page.Data.AsLink.props)),
|
|
@@ -388,7 +390,7 @@ exports.ContentfulPageClient = ContentfulPageClient;
|
|
|
388
390
|
// helpers
|
|
389
391
|
function getPageQueryParams(query) {
|
|
390
392
|
// build filters
|
|
391
|
-
const { ids = [], groupId, brand, type, slug, region, language, name, tags = [], tagsMatch = 'any'
|
|
393
|
+
const { ids = [], groupId, brand, type, slug, region, language, name, tags = [], tagsMatch = 'any' } = query;
|
|
392
394
|
const filters = {};
|
|
393
395
|
// filter id(s)
|
|
394
396
|
if (ids.length === 1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nascentdigital/funnel-cms",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "git+https://github.com/nascentdigital/funnel.git",
|
|
6
6
|
"directory": "libs/cms"
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"ts-jest": "^29",
|
|
49
49
|
"type-fest": "^4"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "567edc7796b910ef548506fd659f267b80187c29"
|
|
52
52
|
}
|