Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): deploy command including org scope #232

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,18 @@ export const deploy: DeployFunc = async ({
console.log(
` > https://app.storyblok.com/#/partner/fields/${fieldPluginId}`,
)
} else {
}

if (apiScope === 'my-plugins') {
console.log(` > https://app.storyblok.com/#/me/plugins/${fieldPluginId}`)
}

if (apiScope === 'organization') {
console.log(
` > https://app.storyblok.com/#/me/org/fields/${fieldPluginId}`,
)
}

console.log(
'You can also find it in "My account > My Plugins" at the bottom of the sidebar.',
)
Expand Down Expand Up @@ -291,7 +300,16 @@ const selectApiScope = async (token: string): Promise<Scope> => {
scope: 'partner-portal',
}).isAuthenticated()

if (!accessibleToMyPlugins && !accessibleToPartnerPortal) {
const accessibleToOrganizationPortal = await StoryblokClient({
token,
scope: 'organization',
}).isAuthenticated()

if (
!accessibleToMyPlugins &&
!accessibleToPartnerPortal &&
!accessibleToOrganizationPortal
) {
console.error(
red('[ERROR]'),
`The token appears to be invalid as it does not have access to either My Plugins or the plugins on the Partner Portal.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to include the organization portal here! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true :D haha let me quickly add it

Expand All @@ -313,6 +331,10 @@ const selectApiScope = async (token: string): Promise<Scope> => {
title: 'Partner Portal',
value: 'partner-portal',
},
accessibleToOrganizationPortal && {
title: 'Organization',
value: 'organization',
},
].filter(Boolean) as Choice[],
},
])
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const program = new Command()
const templateOptions = TEMPLATES.map((template) => template.value)
const structureOptions = ['standalone', 'monorepo']
const packageManagerOptions = ['npm', 'yarn', 'pnpm']
const deployScopeOptions = ['my-plugins', 'partner-portal', 'organization']

export const main = () => {
program
Expand Down Expand Up @@ -79,8 +80,8 @@ export const main = () => {
.addOption(
new Option(
'--scope <value>',
`where to deploy the field plugin ('my-plugins' | 'partner-portal')`,
),
`where to deploy the field plugin ('my-plugins' | 'partner-portal' | 'organization')`,
).choices(deployScopeOptions),
)
.action(async function (this: Command) {
await deploy(this.opts<DeployArgs>())
Expand Down
18 changes: 13 additions & 5 deletions packages/cli/src/storyblok/storyblok-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Response } from 'node-fetch'

export type FieldType = { id: number; name: string; body: string }

export type Scope = 'my-plugins' | 'partner-portal'
export type Scope = 'my-plugins' | 'partner-portal' | 'organization'

type IsAuthenticatedFunc = () => Promise<boolean>

Expand Down Expand Up @@ -32,10 +32,7 @@ type StoryblokClientFunc = (params: { token: string; scope: Scope }) => {
}

export const StoryblokClient: StoryblokClientFunc = ({ token, scope }) => {
const FIELD_TYPES_API_ENDPOINT =
scope === 'partner-portal'
? 'https://mapi.storyblok.com/v1/partner_field_types/'
: 'https://mapi.storyblok.com/v1/field_types/'
const FIELD_TYPES_API_ENDPOINT = getFieldPluginAPIEndpoint(scope)

const headers = {
Authorization: token ?? '',
Expand Down Expand Up @@ -146,3 +143,14 @@ const handleErrorIfExists = (
process.exit(1)
}
}

const getFieldPluginAPIEndpoint = (scope: Scope) => {
if (scope === 'partner-portal') {
return 'https://mapi.storyblok.com/v1/partner_field_types/'
}
if (scope === 'organization') {
return 'https://app.storyblok.com/v1/org_field_types/'
}

return 'https://mapi.storyblok.com/v1/field_types/'
}