Skip to content

Commit

Permalink
feat: create soapFetchV2
Browse files Browse the repository at this point in the history
*fix: handle BatchRequest failure in account setting
*chore: deprecate soapFetch and xmlSoapFetch

Refs: SHELL-259 (#572)
Co-authored-by: rodleyorosa <rodley.orosa@zextras.com>
  • Loading branch information
CataldoMazzilli and rodleyorosa authored Jan 29, 2025
1 parent 6177417 commit f03027f
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 51 deletions.
48 changes: 38 additions & 10 deletions api-extractor/carbonio-shell-ui.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ export const BASENAME: string;
export type BatchRequest<T extends Exactify<Record<`${string}Request`, unknown>, T> = Record<`${string}Request`, unknown>> = SoapBody<T>;

// @public (undocumented)
export type BatchResponse<T extends Exactify<Record<`${string}Response`, unknown>, T> = Record<`${string}Response`, unknown>> = SoapBody<T>;
export type BatchResponse<T extends Exactify<Record<`${string}Response`, unknown>, T> = Record<`${string}Response`, unknown>> = SoapBody<T> & {
Fault?: SoapFault[];
};

// @public (undocumented)
export type Board<T = unknown> = {
Expand Down Expand Up @@ -634,7 +636,7 @@ export const getIntegratedFunction: <TFunction extends AnyFunction = AnyFunction
// @public (undocumented)
export const getNotificationManager: () => INotificationManager;

// @public (undocumented)
// @public @deprecated (undocumented)
const getSoapFetch: (app: string) => <Request, Response extends Record<string, unknown>>(api: string, body: Request, otherAccount?: string, signal?: AbortSignal) => Promise<Response>;

// @public (undocumented)
Expand All @@ -658,7 +660,7 @@ export const getUserSetting: <T = void>(...path: Array<string>) => string | T;
// @public (undocumented)
export const getUserSettings: () => AccountSettings;

// @public (undocumented)
// @public @deprecated (undocumented)
const getXmlSoapFetch: (app: string) => <Request, Response extends Record<string, unknown>>(api: string, body: Request, otherAccount?: string) => Promise<Response>;

// @public (undocumented)
Expand Down Expand Up @@ -930,7 +932,15 @@ type PropsMods = Record<string, {
export const pushHistory: (params: HistoryParams) => void;

// @public (undocumented)
interface RawSoapContext {
export interface RawErrorSoapResponse {
// (undocumented)
Body: ErrorSoapBodyResponse;
// (undocumented)
Header: RawSoapHeader;
}

// @public (undocumented)
export interface RawSoapContext {
// (undocumented)
change?: {
token: number;
Expand All @@ -950,6 +960,12 @@ interface RawSoapContext {
};
}

// @public (undocumented)
export interface RawSoapHeader {
// (undocumented)
context: RawSoapContext;
}

// @public (undocumented)
type RawSoapNotify = {
seq: number;
Expand All @@ -975,6 +991,17 @@ type RawSoapNotify = {
};
};

// @public (undocumented)
export type RawSoapResponse<R extends Record<string, unknown>> = RawSuccessSoapResponse<R> | RawErrorSoapResponse;

// @public (undocumented)
export interface RawSuccessSoapResponse<R> {
// (undocumented)
Body: R;
// (undocumented)
Header: RawSoapHeader;
}

// @public (undocumented)
export const registerActions: <TAction extends Action_2 = Action_2>(...items: Array<{
id: string;
Expand Down Expand Up @@ -1167,8 +1194,6 @@ export type SoapBody<TBody = Record<string, unknown>> = TBody & {
_jsns: NameSpace;
};

// Warning: (ae-forgotten-export) The symbol "RawSoapContext" needs to be exported by the entry point lib.d.ts
//
// @public (undocumented)
export interface SoapContext extends Omit<RawSoapContext, 'notify'> {
// (undocumented)
Expand All @@ -1194,9 +1219,12 @@ export interface SoapFault {
};
}

// @public (undocumented)
// @public @deprecated (undocumented)
export const soapFetch: AppDependantExports['soapFetch'];

// @public (undocumented)
export const soapFetchV2: <Request, Response extends Record<string, unknown>>(api: string, body: Request, otherAccount?: string, signal?: AbortSignal) => Promise<RawSoapResponse<Response>>;

// Warning: (ae-forgotten-export) The symbol "BaseFolder" needs to be exported by the entry point lib.d.ts
//
// @public (undocumented)
Expand Down Expand Up @@ -1451,7 +1479,7 @@ type UtilityView = CarbonioAccessoryView<UtilityBarComponentProps> & {
// @public (undocumented)
type ValueOf<T> = T[keyof T];

// @public (undocumented)
// @public @deprecated (undocumented)
export const xmlSoapFetch: AppDependantExports['xmlSoapFetch'];

// @public (undocumented)
Expand Down Expand Up @@ -1514,7 +1542,7 @@ interface ZimletProp {
// lib/types/misc/index.d.ts:98:5 - (ae-forgotten-export) The symbol "SortBy" needs to be exported by the entry point lib.d.ts
// lib/types/network/index.d.ts:79:5 - (ae-forgotten-export) The symbol "AccountACEInfo" needs to be exported by the entry point lib.d.ts
// lib/types/network/soap.d.ts:11:5 - (ae-forgotten-export) The symbol "NameSpace" needs to be exported by the entry point lib.d.ts
// lib/types/network/soap.d.ts:69:5 - (ae-forgotten-export) The symbol "SoapSearchFolder" needs to be exported by the entry point lib.d.ts
// lib/types/network/soap.d.ts:91:9 - (ae-forgotten-export) The symbol "Tag" needs to be exported by the entry point lib.d.ts
// lib/types/network/soap.d.ts:70:5 - (ae-forgotten-export) The symbol "SoapSearchFolder" needs to be exported by the entry point lib.d.ts
// lib/types/network/soap.d.ts:92:9 - (ae-forgotten-export) The symbol "Tag" needs to be exported by the entry point lib.d.ts

```
1 change: 1 addition & 0 deletions src/boot/app/app-direct-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ export { AppContextProvider } from './app-context-provider';

export type { AuthGuardProps } from '../../ui-extras/auth-guard';
export { AuthGuard } from '../../ui-extras/auth-guard';
export { soapFetchV2 } from '../../network/fetch';
13 changes: 12 additions & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export declare const editSettings: AppDependantExports['editSettings'];

export declare const getI18n: AppDependantExports['getI18n'];
export declare const t: AppDependantExports['t'];
/**
* @deprecated Use soapFetchV2 instead
*/
export declare const soapFetch: AppDependantExports['soapFetch'];
/**
* @deprecated Use soapFetchV2 instead
*/
export declare const xmlSoapFetch: AppDependantExports['xmlSoapFetch'];
export declare const useAppContext: AppDependantExports['useAppContext'];
export declare const getAppContext: AppDependantExports['getAppContext'];
Expand Down Expand Up @@ -103,7 +109,12 @@ export type {
SoapContext,
SoapBody,
SoapHeader,
SoapFault
SoapFault,
RawSoapResponse,
RawSoapHeader,
RawSoapContext,
RawSuccessSoapResponse,
RawErrorSoapResponse
} from './types/network/soap';

export type { BatchRequest, BatchResponse } from './types/network';
Expand Down
32 changes: 26 additions & 6 deletions src/network/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ const normalizeContext = ({ notify: rawNotify, ...context }: RawSoapContext): So
return normalizedContext;
};

const handleResponse = <R extends Record<string, unknown>>(
api: string,
res: RawSoapResponse<R>
): R | ErrorSoapBodyResponse => {
const handleResponseV2 = <R extends Record<string, unknown>>(res: RawSoapResponse<R>): void => {
const { noOpTimeout } = useNetworkStore.getState();
const { usedQuota } = useAccountStore.getState();
clearTimeout(noOpTimeout);
Expand Down Expand Up @@ -125,11 +122,21 @@ const handleResponse = <R extends Record<string, unknown>>(
..._context
});
}
};

const handleResponse = <R extends Record<string, unknown>>(
api: string,
res: RawSoapResponse<R>
): R | ErrorSoapBodyResponse => {
handleResponseV2(res);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return res?.Body?.Fault ? (res.Body as ErrorSoapBodyResponse) : (res.Body[`${api}Response`] as R);
};

/**
* @deprecated Use soapFetchV2 instead
*/
export const getSoapFetch =
(app: string) =>
<Request, Response extends Record<string, unknown>>(
Expand All @@ -146,6 +153,21 @@ export const getSoapFetch =
throw e;
}) as Promise<Response>;

export const soapFetchV2 = async <Request, Response extends Record<string, unknown>>(
api: string,
body: Request,
otherAccount?: string,
signal?: AbortSignal
): Promise<RawSoapResponse<Response>> => {
const rawSoapResponse = await soapFetch<Request, Response>(api, body, otherAccount, signal);
// apply side effects
handleResponseV2(rawSoapResponse);
return rawSoapResponse;
};

/**
* @deprecated Use soapFetchV2 instead
*/
export const getXmlSoapFetch =
(app: string) =>
<Request, Response extends Record<string, unknown>>(
Expand Down Expand Up @@ -175,5 +197,3 @@ export const getXmlSoapFetch =
throw e;
}) as Promise<Response>;
};

export const shellSoap = getSoapFetch(SHELL_APP_ID);
Loading

0 comments on commit f03027f

Please sign in to comment.