Skip to content

Commit

Permalink
fix(common): clean up types (#73)
Browse files Browse the repository at this point in the history
* fix(common): clean up types

* add comment
  • Loading branch information
eunjae-lee committed Jul 25, 2024
1 parent 2ea23c3 commit 08d3b69
Show file tree
Hide file tree
Showing 17 changed files with 5,235 additions and 6,831 deletions.
1 change: 0 additions & 1 deletion space-plugins/nuxt-base-ui/app.config.ts

This file was deleted.

10 changes: 0 additions & 10 deletions space-plugins/nuxt-base/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { AppBridgeConfig, PluginType } from './types/appBridge';

export default defineAppConfig({
type: 'space-plugin',
appBridge: {
Expand All @@ -14,11 +12,3 @@ export default defineAppConfig({
errorCallback: '/401',
},
});

declare module '@nuxt/schema' {
interface AppConfigInput {
type: PluginType;
appBridge: AppBridgeConfig;
auth: AuthConfig;
}
}
10 changes: 0 additions & 10 deletions space-plugins/nuxt-base/composables/useAppBridge.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import type {
BeginOAuthMessagePayload,
CreateBeginOAuthMessagePayload,
CreateValidateMessagePayload,
DecodedToken,
PluginType,
PostMessageAction,
ValidateMessagePayload,
} from '~/types/appBridge';

const getPostMessageAction = (type: PluginType): PostMessageAction => {
switch (type) {
case 'space-plugin':
Expand Down
21 changes: 21 additions & 0 deletions space-plugins/nuxt-base/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,25 @@ declare module 'h3' {
}
}

declare module 'nuxt/schema' {
// We can have both `AppConfigInput` and `AppConfig`.
// - `AppConfigInput`: what user provides
// - `AppConfig`: what we actually get from `useAppConfig()`
// Nuxt merges the app configs from all the layers,
// allowing us to have optional properties at `AppConfigInput`.
//
// ref: https://nuxt.com/docs/guide/directory-structure/app-config#typing-app-config
interface AppConfigInput {
type: PluginType;
appBridge?: AppBridgeConfig;
auth?: AuthConfig;
}

interface AppConfig {
type: PluginType;
appBridge: AppBridgeConfig;
auth: AuthConfig;
}
}

export default {};
5 changes: 4 additions & 1 deletion space-plugins/nuxt-base/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ export default defineNuxtConfig({
devtools: { enabled: true },
nitro: {
imports: {
dirs: ['./utils', './server/utils'],
dirs: ['./types', './utils', './server/utils'],
},
},
imports: {
dirs: ['./types', './utils'],
},
});
1 change: 0 additions & 1 deletion space-plugins/nuxt-base/server/api/connect/[...slugs].ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { authHandler } from '@storyblok/app-extension-auth';
import { getAuthHandlerParams } from '../../utils/auth';

export default defineEventHandler((event) => {
const appConfig = useAppConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { APP_BRIDGE_TOKEN_HEADER_KEY } from '../../utils/const';

const SKIP_AUTH_FOR = ['/api/_app_bridge', '/api/_oauth'];

export default defineEventHandler(async (event) => {
Expand Down
1 change: 0 additions & 1 deletion space-plugins/nuxt-base/server/utils/appBridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import jwt, { type VerifyCallback } from 'jsonwebtoken';
import { DecodedToken, VerifyResponse } from '~/types/appBridge';

export const verifyAppBridgeToken = async (
token: string,
Expand Down
4 changes: 2 additions & 2 deletions space-plugins/nuxt-base/server/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AuthHandlerParams } from '@storyblok/app-extension-auth';
import type { AppConfigInput } from 'nuxt/schema';
import type { AppConfig } from 'nuxt/schema';

export const getAuthHandlerParams = (
authConfig: AppConfigInput['auth'],
authConfig: AppConfig['auth'],
): AuthHandlerParams => ({
clientId: env('CLIENT_ID'),
clientSecret: env('CLIENT_SECRET'),
Expand Down
1 change: 0 additions & 1 deletion space-plugins/nuxt-base/server/utils/space.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getManagementBaseUrl, getRegion } from '@storyblok/region-helper';
import { FetchSpaceInfo, SpaceInfo } from '~/types/space';

export const fetchSpaceInfo: FetchSpaceInfo = async ({
spaceId,
Expand Down
10 changes: 0 additions & 10 deletions space-plugins/nuxt-base/server/utils/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import { randomBytes } from 'node:crypto';
import {
UpsertStoryblokWebhook,
DeleteStoryblokWebhook,
StoryblokWebhookResponse,
StoryblokWebhookEventCategory,
IsValidWebhookUpsertParams,
CreateStoryblokWebhook,
UpdateStoryblokWebhook,
GetStoryblokWebhook,
} from '../../types';
import { getManagementBaseUrl, getRegion } from '@storyblok/region-helper';

export const generateSecret = (lengthInBytes: number = 20) => {
Expand Down
8 changes: 1 addition & 7 deletions space-plugins/nuxt-starter/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
export default defineAppConfig({
type: 'space-plugin',
appBridge: {
type: 'space-plugin',
enabled: true,
oauth: true,
origin: 'https://app.storyblok.com',
},
auth: {
endpointPrefix: '/api/connect',
initOauthFlowUrl: `/api/connect/storyblok`,
successCallback: '/',
errorCallback: '/401',
},
});
8 changes: 8 additions & 0 deletions space-plugins/nuxt-starter/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export default defineNuxtConfig({
{ install: true },
],
],
nitro: {
imports: {
dirs: ['./types', './utils', './server/utils'],
},
},
imports: {
dirs: ['./types', './utils'],
},
css: ['~/assets/css/base.css'],
modules: ['nuxt-lucide-icons', '@nuxtjs/google-fonts', '@nuxtjs/tailwindcss'],
googleFonts: {
Expand Down
1 change: 0 additions & 1 deletion space-plugins/nuxt-starter/server/api/stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import StoryblokClient, { ISbStoriesParams } from 'storyblok-js-client';
import type { Story } from '~/types/story';

export default defineEventHandler(
async (
Expand Down
Loading

0 comments on commit 08d3b69

Please sign in to comment.