@botonic/plugin-contentful
Version:
Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet
69 lines • 2.81 kB
JavaScript
import { __awaiter } from "tslib";
import { createClient } from 'contentful-management';
import { ManageContentfulAsset } from './manage-asset';
import { ManageContentfulEntry } from './manage-entry';
export class ManageContentful {
constructor(options) {
this.options = options;
this.manage = this.createClient();
this.environment = this.getEnvironment();
this.manageAsset = new ManageContentfulAsset(options, this.manage, this.environment);
this.manageEntry = new ManageContentfulEntry(options, this.manage, this.environment);
}
createClient() {
return createClient({
accessToken: this.options.accessToken,
timeout: this.options.timeoutMs,
});
}
getEnvironment() {
return __awaiter(this, void 0, void 0, function* () {
const space = yield this.manage.getSpace(this.options.spaceId);
if (!this.options.environment) {
throw new Error('Please specify environment in ContentfulOptions');
}
return yield space.getEnvironment(this.options.environment);
});
}
deleteContent(context, contentId) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageEntry.deleteContent(context, contentId);
});
}
createContent(context, model, id) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageEntry.createContent(context, model, id);
});
}
updateFields(context, contentId, fields) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageEntry.updateFields(context, contentId, fields);
});
}
copyField(context, contentId, fieldType, fromLocale, onlyIfTargetEmpty) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageEntry.copyField(context, contentId, fieldType, fromLocale, onlyIfTargetEmpty);
});
}
removeAssetFile(context, assetId) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageAsset.removeAssetFile(context, assetId);
});
}
copyAssetFile(context, assetId, fromLocale) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageAsset.copyAssetFile(context, assetId, fromLocale);
});
}
createAsset(context, file, info) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageAsset.createAsset(context, file, info);
});
}
removeAsset(context, assetId) {
return __awaiter(this, void 0, void 0, function* () {
return this.manageAsset.removeAsset(context, assetId);
});
}
}
//# sourceMappingURL=manage-contentful.js.map