export type AppPkgNotificationId = string; export type AppPkgNotificationType = 'AppPackageOnBoarded' | 'AppPacakgeEnabled' | 'AppPacakgeDisabled' | 'AppPackageDeleted'; export type SubscriptionId = string; export type TimeStamp = {nanoSeconds: number, seconds: number}; export type AppPkgId = string; export type AppDId = string; export type LinkType = {href: string}; export type AppPkgNotificationLinks = {subscription: LinkType}; export type AppPkgNotification = {id: AppPkgNotificationId, notificationType: AppPkgNotificationType, subscriptionId: SubscriptionId, timeStamp: TimeStamp, appPkgId: AppPkgId, appDId: AppDId, operationalState: 'DISABLED' | 'ENABLED', _links: AppPkgNotificationLinks}; export type CreateApiUserDefinedNotificationArgs = {body: AppPkgNotification}; export type CreateApiUserDefinedNotificationOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Registers a notification endpoint to notify application package operations * * POST /user_defined_notification */ export const createApiUserDefinedNotification = async (args: CreateApiUserDefinedNotificationArgs, options?: CreateApiUserDefinedNotificationOptions) => { const {baseUrl = "https://localhost/app_pkgm/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/user_defined_notification${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };