Skip to content

Commit b093288

Browse files
committed
make union
1 parent 09b9b9f commit b093288

File tree

1 file changed

+53
-41
lines changed

1 file changed

+53
-41
lines changed

src/types.ts

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -236,57 +236,69 @@ export type SyncWebhookEventType =
236236
| "PAYMENT_METHOD_INITIALIZE_TOKENIZATION_SESSION"
237237
| "PAYMENT_METHOD_PROCESS_TOKENIZATION_SESSION";
238238

239-
export interface AppExtension {
239+
interface BaseAppExtension {
240240
/** Name which will be displayed in the dashboard */
241241
label: string;
242242
/** the place where the extension will be mounted */
243243
mount: AppExtensionMount;
244244
/** Method of presenting the interface
245-
`POPUP` will present the interface in a modal overlay
246-
`APP_PAGE` will navigate to the application page
247-
@default `POPUP`
248-
*/
249-
target: AppExtensionTarget;
245+
`POPUP` will present the interface in a modal overlay
246+
`APP_PAGE` will navigate to the application page
247+
@default `POPUP`
248+
*/
250249
permissions: AppPermission[];
251250
/** URL of the view to display;
252-
you can skip the domain and protocol when target is set to `APP_PAGE`, or when your manifest defines an `appUrl`.
251+
you can skip the domain and protocol when target is set to `APP_PAGE`, or when your manifest defines an `appUrl`.
253252
254-
When target is set to `POPUP`, the url will be used to render an `<iframe>`.
253+
When target is set to `POPUP`, the url will be used to render an `<iframe>`.
255254
*/
256255
url: string;
257-
/**
258-
* Additional parameters for extensions
259-
*
260-
* Only specific target options should be used
261-
*
262-
* TODO: Make it discriminated union
263-
*/
256+
}
257+
258+
type PopupExtensionWidget = BaseAppExtension & {
259+
target: "POPUP";
260+
};
261+
262+
type AppPageExtensionWidget = BaseAppExtension & {
263+
target: "APP_PAGE";
264+
};
265+
266+
type AppExtensionWidget = BaseAppExtension & {
267+
target: "WIDGET";
264268
options?: {
265-
/**
266-
* Only when target is NEW_TAB.
267-
*/
268-
newTabTarget?: {
269+
widgetTarget?: {
269270
/**
270271
* Controls how dashboard will open the new tab
271272
* - GET -> open URL in the new window
272-
* - POST -> submit internal <form> using POST method. Passes token and additional parameters into body
273-
* Default is GET
274-
*
273+
* - POST -> submit internal <form> using POST method. Passes token and additional parameters into body*
275274
*/
276275
method?: "GET" | "POST";
277276
};
278-
widgetTarget?: {
277+
};
278+
};
279+
280+
type AppExtensionNewTab = BaseAppExtension & {
281+
target: "NEW_TAB";
282+
options?: {
283+
/**
284+
* Only when target is NEW_TAB.
285+
*/
286+
newTabTarget?: {
279287
/**
280288
* Controls how dashboard will open the new tab
281289
* - GET -> open URL in the new window
282-
* - POST -> submit internal <form> using POST method. Passes token and additional parameters into body
283-
* Default is GET
284-
*
290+
* - POST -> submit internal <form> using POST method. Passes token and additional parameters into body*
285291
*/
286292
method?: "GET" | "POST";
287293
};
288294
};
289-
}
295+
};
296+
297+
export type AppExtension =
298+
| AppPageExtensionWidget
299+
| AppExtensionNewTab
300+
| AppExtensionWidget
301+
| PopupExtensionWidget;
290302

291303
export interface WebhookManifest {
292304
name: string;
@@ -321,18 +333,18 @@ export interface AppManifest {
321333
/** App website rendered in the dashboard */
322334
appUrl: string;
323335
/** Address to the app configuration page, which is rendered in the dashboard
324-
@deprecated in Saleor 3.5, use appUrl instead
325-
*/
336+
@deprecated in Saleor 3.5, use appUrl instead
337+
*/
326338
configurationUrl?: string;
327339
/** Endpoint used during process of app installation
328340
329-
@see [Installing an app](https://docs.saleor.io/docs/3.x/developer/extending/apps/installing-apps#installing-an-app)
330-
*/
341+
@see [Installing an app](https://docs.saleor.io/docs/3.x/developer/extending/apps/installing-apps#installing-an-app)
342+
*/
331343
tokenTargetUrl: string;
332344
/** Short description of privacy policy displayed in the dashboard
333345
334-
@deprecated in Saleor 3.5, use dataPrivacyUrl instead
335-
*/
346+
@deprecated in Saleor 3.5, use dataPrivacyUrl instead
347+
*/
336348
dataPrivacy?: string;
337349
/** URL to the full privacy policy */
338350
dataPrivacyUrl?: string;
@@ -342,17 +354,17 @@ export interface AppManifest {
342354
supportUrl?: string;
343355
/** List of extensions that will be mounted in Saleor's dashboard
344356
345-
@see For details, please see the [extension section](https://docs.saleor.io/docs/3.x/developer/extending/apps/extending-dashboard-with-apps#key-concepts)
346-
*/
357+
@see For details, please see the [extension section](https://docs.saleor.io/docs/3.x/developer/extending/apps/extending-dashboard-with-apps#key-concepts)
358+
*/
347359
extensions?: AppExtension[];
348360
/** List of webhooks that will be set.
349-
350-
@see For details, please look at [asynchronous webhooks](https://docs.saleor.io/docs/3.x/developer/extending/apps/asynchronous-webhooks),
351-
[synchronous-webhooks](https://docs.saleor.io/docs/3.x/developer/extending/apps/synchronous-webhooks/key-concepts)
352-
and [webhooks' subscription](https://docs.saleor.io/docs/3.x/developer/extending/apps/subscription-webhook-payloads)
353361
354-
Be aware that subscription queries are required in manifest sections
355-
*/
362+
@see For details, please look at [asynchronous webhooks](https://docs.saleor.io/docs/3.x/developer/extending/apps/asynchronous-webhooks),
363+
[synchronous-webhooks](https://docs.saleor.io/docs/3.x/developer/extending/apps/synchronous-webhooks/key-concepts)
364+
and [webhooks' subscription](https://docs.saleor.io/docs/3.x/developer/extending/apps/subscription-webhook-payloads)
365+
366+
Be aware that subscription queries are required in manifest sections
367+
*/
356368
webhooks?: WebhookManifest[];
357369
/**
358370
* Allows app installation for specific Saleor versions, using semver.

0 commit comments

Comments
 (0)