-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
764fd43
commit 1fc4b00
Showing
15 changed files
with
275 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/botonic-plugin-contentful/src/contentful/contents/callback-delivery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as contentful from 'contentful' | ||
|
||
import * as cms from '../../cms' | ||
import { CmsException, ContentType } from '../../cms' | ||
import { TopContentType } from '../../cms/cms' | ||
import { isOfType } from '../../util/enums' | ||
import { ContentfulEntryUtils } from '../delivery-utils' | ||
import { PayloadFields } from './button' | ||
import { CarouselFields } from './carousel' | ||
import { HandoffFields } from './handoff' | ||
import { QueueFields } from './queue' | ||
import { HourRangeFields, ScheduleFields } from './schedule' | ||
import { StartUpFields } from './startup' | ||
import { TextFields } from './text' | ||
import { UrlFields } from './url' | ||
|
||
export type CallbackTarget = contentful.Entry< | ||
| CarouselFields | ||
| TextFields | ||
| UrlFields | ||
| PayloadFields | ||
| StartUpFields | ||
| QueueFields | ||
| HourRangeFields | ||
| ScheduleFields | ||
| HandoffFields | ||
> | ||
|
||
export function getTargetCallback( | ||
target: CallbackTarget, | ||
context: cms.Context | ||
): cms.Callback { | ||
const PAYLOAD_CONTENT_TYPE = 'payload' | ||
const model = ContentfulEntryUtils.getContentModel(target) as string | ||
try { | ||
switch (model) { | ||
case ContentType.URL: { | ||
const urlFields = target as contentful.Entry<UrlFields> | ||
if (!urlFields.fields.url && context.ignoreFallbackLocale) { | ||
return cms.Callback.empty() | ||
} | ||
return cms.Callback.ofUrl(urlFields.fields.url || '') | ||
} | ||
case PAYLOAD_CONTENT_TYPE: { | ||
const payloadFields = target as contentful.Entry<PayloadFields> | ||
return cms.Callback.ofPayload(payloadFields.fields.payload) | ||
} | ||
} | ||
if (isOfType(model, TopContentType)) { | ||
return new cms.ContentCallback(model, target.sys.id) | ||
} | ||
throw new Error('Unexpected type: ' + model) | ||
} catch (e) { | ||
throw new CmsException( | ||
`Error delivering button with id '${target.sys.id}'`, | ||
e | ||
) | ||
} | ||
} |
Oops, something went wrong.