From 72750a02af2c357e552f31c258e3e50070ae42ad Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Fri, 14 Jul 2023 12:46:18 +0530 Subject: [PATCH] refactor: adds and corrects types of ContentstackCollectin and marketplace functions --- types/contentstackCollection.d.ts | 2 +- types/marketplace/{ => app}/hosting.d.ts | 4 +- types/marketplace/app/index.d.ts | 89 ++++++++++++++++++ types/marketplace/app/oath.d.ts | 8 ++ .../{request.d.ts => apprequest.d.ts} | 0 types/marketplace/index.d.ts | 90 ++----------------- types/marketplace/installation.d.ts | 7 +- types/marketplace/oath.d.ts | 8 -- types/marketplace/webhooks.d.ts | 7 ++ types/organization.d.ts | 7 +- 10 files changed, 124 insertions(+), 98 deletions(-) rename types/marketplace/{ => app}/hosting.d.ts (88%) create mode 100644 types/marketplace/app/index.d.ts create mode 100644 types/marketplace/app/oath.d.ts rename types/marketplace/{request.d.ts => apprequest.d.ts} (100%) delete mode 100644 types/marketplace/oath.d.ts create mode 100644 types/marketplace/webhooks.d.ts diff --git a/types/contentstackCollection.d.ts b/types/contentstackCollection.d.ts index 07d6dff0..c89eb64b 100644 --- a/types/contentstackCollection.d.ts +++ b/types/contentstackCollection.d.ts @@ -3,7 +3,7 @@ export interface Response { } export interface ContentstackCollection extends Response { - items: [T] + items: T[] count: number } diff --git a/types/marketplace/hosting.d.ts b/types/marketplace/app/hosting.d.ts similarity index 88% rename from types/marketplace/hosting.d.ts rename to types/marketplace/app/hosting.d.ts index 0dd07f87..c0c2a5aa 100644 --- a/types/marketplace/hosting.d.ts +++ b/types/marketplace/app/hosting.d.ts @@ -1,5 +1,5 @@ -import { AnyProperty, SystemFields } from '../utility/fields'; -import { ContentstackCollection } from '../contentstackCollection' +import { AnyProperty, SystemFields } from '../../utility/fields'; +import { ContentstackCollection } from '../../contentstackCollection' export interface Hosting { isEnable(): Promise enable(): Promise diff --git a/types/marketplace/app/index.d.ts b/types/marketplace/app/index.d.ts new file mode 100644 index 00000000..77647886 --- /dev/null +++ b/types/marketplace/app/index.d.ts @@ -0,0 +1,89 @@ +import { ContentstackCollection } from "../../contentstackCollection"; +import { AnyProperty, SystemFields } from "../../utility/fields"; +import { Creatable, SystemFunction } from "../../utility/operations"; +import { Authorization } from '../authorization'; +import { Hosting } from './hosting'; +import { Installation } from "../installation"; +import { Oauth } from "./oath"; + +export interface App extends SystemFields, SystemFunction { + + update(param?: AnyProperty): Promise + fetch(param?: AnyProperty): Promise + delete(param?: AnyProperty): Promise + oauth(): Oauth + hosting(): Hosting + install(data: {targetUid: string, targetType: AppTarget}): Promise + authorize(param: { + responseType: string, + clientId: string, + redirectUri: string, + scope: string, + state: string }): Promise + authorization(): Authorization + listInstallations(): Promise> +} + +export interface Apps extends Creatable { + create(): Promise +} + +export interface AppData extends AnyProperty { + name: string + description?: string + icon?: string + target_type: AppTarget + ui_location?: UILocation + webhook?: AppWebhook | AppWebhookChannel + oauth?: AppOAuth +} + +export interface AppOAuth extends AnyProperty { + redirect_uri?: string + app_token_config?: TokenConfig + user_token_config?: UserTokenConfig +} + +export interface TokenConfig extends AnyProperty { + enabled: boolean + scopes: string[] +} + +export interface UserTokenConfig extends TokenConfig { + allow_pkce: boolean +} + +export interface AppWebhookChannel extends AppWebhook { + target_url: string + channels: string[] +} + +export interface AppWebhook extends AnyProperty { + signed: boolean + name: string + enabled?: boolean + app_lifecycle_enabled?: boolean + retry_policy?: string +} + +export interface UILocation extends AnyProperty { + signed: boolean + base_url?: string + locations: Location[] +} + +export interface Location extends AnyProperty { + type: string + meta: LocationMeta[] +} + +export interface LocationMeta extends AnyProperty { + signed: boolean + path: string + name: string + data_type?: string +} + +export type AppTarget = + | 'stack' + | 'organization' \ No newline at end of file diff --git a/types/marketplace/app/oath.d.ts b/types/marketplace/app/oath.d.ts new file mode 100644 index 00000000..7169f3ed --- /dev/null +++ b/types/marketplace/app/oath.d.ts @@ -0,0 +1,8 @@ +import { AnyProperty } from '../../utility/fields'; +import { AppOAuth } from '.'; + +export interface Oauth { + fetch(param?: AnyProperty): Promise + update(data: { config: AppOAuth, param?: AnyProperty }): Promise + getScopes(): Promise +} \ No newline at end of file diff --git a/types/marketplace/request.d.ts b/types/marketplace/apprequest.d.ts similarity index 100% rename from types/marketplace/request.d.ts rename to types/marketplace/apprequest.d.ts diff --git a/types/marketplace/index.d.ts b/types/marketplace/index.d.ts index 4d82da5f..82a00670 100644 --- a/types/marketplace/index.d.ts +++ b/types/marketplace/index.d.ts @@ -1,89 +1,17 @@ import { ContentstackCollection } from "../contentstackCollection"; import { AnyProperty, SystemFields } from "../utility/fields"; -import { Creatable, SystemFunction } from "../utility/operations"; -import { Pagination } from '../utility/pagination'; -import { Authorization } from './authorization'; -import { Hosting } from './hosting'; +import { SystemFunction } from "../utility/operations"; import { Installation, Installations } from "./installation"; -import { Oauth } from "./oath"; +import { App, Apps } from "./app"; +import { AppRequest } from "./apprequest"; -export interface App extends SystemFields, SystemFunction { +export interface Marketplace extends SystemFields, SystemFunction { - install(data: {targetUid: string, targetType: AppTarget}): Promise + app(): Apps + app(uid: string): App installation(): Installations installation(uid: string): Installation - hosting(): Hosting - authorize(param: { - responseType: string, - clientId: string, - redirectUri: string, - scope: string, - state: string }): Promise - listInstallations(): Promise> - authorization(): Authorization - oauth(): Oauth + appRequests(): AppRequest + findAllApps(param?: AnyProperty): Promise> + findAllAuthorizedApps(param?: AnyProperty): Promise } - -export interface Apps extends Creatable { - findAll(param?: AnyProperty): Promise> - findAllAuthorized(param?: Pagination & AnyProperty): Promise -} - -export interface AppData extends AnyProperty { - name: string - description?: string - icon?: string - target_type: AppTarget - ui_location?: UILocation - webhook?: AppWebhook | AppWebhookChannel - oauth?: AppOAuth -} - -export interface AppOAuth extends AnyProperty { - redirect_uri?: string - app_token_config?: TokenConfig - user_token_config?: UserTokenConfig -} - -export interface TokenConfig extends AnyProperty { - enabled: boolean - scopes: string[] -} -export interface UserTokenConfig extends TokenConfig { - allow_pkce: boolean -} - -export interface AppWebhookChannel extends AppWebhook { - target_url: string - channels: string[] -} - -export interface AppWebhook extends AnyProperty { - signed: boolean - name: string - enabled?: boolean - app_lifecycle_enabled?: boolean - retry_policy?: string -} - -export interface UILocation extends AnyProperty { - signed: boolean - base_url?: string - locations: Location[] -} - -export interface Location extends AnyProperty { - type: string - meta: LocationMeta[] -} - -export interface LocationMeta extends AnyProperty { - signed: boolean - path: string - name: string - data_type?: string -} - -export type AppTarget = - | 'stack' - | 'organization' \ No newline at end of file diff --git a/types/marketplace/installation.d.ts b/types/marketplace/installation.d.ts index e3f5e1b9..cd0df70c 100644 --- a/types/marketplace/installation.d.ts +++ b/types/marketplace/installation.d.ts @@ -7,11 +7,16 @@ export interface Installation extends SystemFields { uninstall(param?: AnyProperty): Promise configuration(param?: AnyProperty): Promise setConfiguration(config: AnyProperty): Promise + getConfigLocation(): Promise serverConfig(param?: AnyProperty): Promise setServerConfig(config: AnyProperty): Promise installationData(): Promise + webhooks(webhookUid: string): WebHooks } export interface Installations { - findAll(param?: AnyProperty): Promise> + fetchAll(param?: AnyProperty): Promise> + getInstalledApps(): Promise + getInstalledUsers(): Promise + getInstalledStacks(): Promise } \ No newline at end of file diff --git a/types/marketplace/oath.d.ts b/types/marketplace/oath.d.ts deleted file mode 100644 index afe99274..00000000 --- a/types/marketplace/oath.d.ts +++ /dev/null @@ -1,8 +0,0 @@ - - -import { AnyProperty } from '../utility/fields'; - -export interface Oauth { - fetchOAuth(param?: AnyProperty): Promise - updateOAuth(data: { config: AppOAuth, param?: AnyProperty }): Promise -} \ No newline at end of file diff --git a/types/marketplace/webhooks.d.ts b/types/marketplace/webhooks.d.ts new file mode 100644 index 00000000..93291807 --- /dev/null +++ b/types/marketplace/webhooks.d.ts @@ -0,0 +1,7 @@ +import { AnyProperty } from "../utility/fields"; + +export interface WebHooks { + listExecutionLogs(): Promise + getExecutionLog(executionUid: string): Promise + retryExecution(executionUid: string): Promise +} \ No newline at end of file diff --git a/types/organization.d.ts b/types/organization.d.ts index 0612b25f..84f6df8b 100644 --- a/types/organization.d.ts +++ b/types/organization.d.ts @@ -5,8 +5,7 @@ import { Sorting } from './utility/sorting' import { Pagination } from './utility/pagination' import { AnyProperty, SystemFields } from './utility/fields' import { ContentstackCollection, Response } from './contentstackCollection' -import { App, Apps } from './app' -import { AppRequest } from './app/request' +import { Marketplace } from '../lib/marketplace' export interface Organizations { fetchAll(params?: AnyProperty): Promise> @@ -22,9 +21,7 @@ export interface Organization extends SystemFields { getInvitations(param?: Pagination & AnyProperty): Promise> resendInvitation(invitationUid: string): Promise roles(param?: Pagination & AnyProperty): Promise> - app(): Apps - app(uid: string): App - appRequest(): AppRequest + marketplace(): Marketplace } export interface OrganizationInvite {