UNPKG

@datocms/cma-client

Version:
89 lines 5.16 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { pollJobResult, request, } from '@datocms/rest-client-utils'; import * as Resources from './resources'; export class Client { constructor(config) { this.config = config; this.roles = new Resources.Role(this); this.users = new Resources.User(this); this.ssoUsers = new Resources.SsoUser(this); this.auditLogEvents = new Resources.AuditLogEvent(this); this.menuItems = new Resources.MenuItem(this); this.schemaMenuItems = new Resources.SchemaMenuItem(this); this.uploadCollections = new Resources.UploadCollection(this); this.itemTypes = new Resources.ItemType(this); this.fields = new Resources.Field(this); this.fieldsets = new Resources.Fieldset(this); this.session = new Resources.Session(this); this.accessTokens = new Resources.AccessToken(this); this.plugins = new Resources.Plugin(this); this.jobResults = new Resources.JobResult(this); this.subscriptionLimits = new Resources.SubscriptionLimit(this); this.subscriptionFeatures = new Resources.SubscriptionFeature(this); this.buildEvents = new Resources.BuildEvent(this); this.searchIndexEvents = new Resources.SearchIndexEvent(this); this.items = new Resources.Item(this); this.itemVersions = new Resources.ItemVersion(this); this.uploads = new Resources.Upload(this); this.uploadRequest = new Resources.UploadRequest(this); this.uploadTracks = new Resources.UploadTrack(this); this.scheduledPublication = new Resources.ScheduledPublication(this); this.scheduledUnpublishing = new Resources.ScheduledUnpublishing(this); this.searchResults = new Resources.SearchResult(this); this.environments = new Resources.Environment(this); this.maintenanceMode = new Resources.MaintenanceMode(this); this.webhooks = new Resources.Webhook(this); this.webhookCalls = new Resources.WebhookCall(this); this.buildTriggers = new Resources.BuildTrigger(this); this.searchIndexes = new Resources.SearchIndex(this); this.itemTypeFilters = new Resources.ItemTypeFilter(this); this.uploadFilters = new Resources.UploadFilter(this); this.siteInvitations = new Resources.SiteInvitation(this); this.editingSessions = new Resources.EditingSession(this); this.ssoGroups = new Resources.SsoGroup(this); this.ssoSettings = new Resources.SsoSettings(this); this.emojiSuggestions = new Resources.EmojiSuggestions(this); this.whiteLabelSettings = new Resources.WhiteLabelSettings(this); this.publicInfo = new Resources.PublicInfo(this); this.dailyUsages = new Resources.DailyUsage(this); this.usageCounters = new Resources.UsageCounter(this); this.uploadTags = new Resources.UploadTag(this); this.uploadSmartTags = new Resources.UploadSmartTag(this); this.site = new Resources.Site(this); this.workflows = new Resources.Workflow(this); } get baseUrl() { return this.config.baseUrl || Client.defaultBaseUrl; } request(options) { return request(Object.assign(Object.assign(Object.assign({}, this.config), options), { logFn: this.config.logFn || console.log, userAgent: '@datocms/cma-client v5.3.0', baseUrl: this.baseUrl, preCallStack: new Error().stack, extraHeaders: Object.assign(Object.assign(Object.assign({}, (this.config.extraHeaders || {})), (this.config.environment ? { 'X-Environment': this.config.environment } : {})), { 'X-API-Version': '3' }), fetchJobResult: (jobId) => { return this.jobResultsFetcher ? this.jobResultsFetcher(jobId) : pollJobResult(() => this.jobResults.find(jobId)); } })); } eventsChannelName() { return __awaiter(this, void 0, void 0, function* () { if (this.cachedEventsChannelName) { return this.cachedEventsChannelName; } const { data: site } = yield this.site.rawFind(); this.cachedEventsChannelName = this.config.environment ? `private-site-${site.id}-environment-${this.config.environment}` : `private-site-${site.id}`; return this.cachedEventsChannelName; }); } } Client.defaultBaseUrl = 'https://site-api.datocms.com'; //# sourceMappingURL=Client.js.map