Skip to content

Delivery API

createAsyncHelpers

Import

ts
import { createAsyncHelpers } from '@azure-net/kit';

TypeScript signature

ts
createAsyncHelpers<BaseError = unknown, Custom = unknown>(opts?: {
  parseError?: (error: ErrorType<BaseError>, retry?: () => unknown) => Promise<AppError<unknown, Custom>>;
}): {
  createAsyncAction<Res = unknown, Req = unknown>(
    action: Promise<Res> | (() => Promise<Res>),
    args?: {
      beforeSend?: (next: () => void, abort: () => void) => void | Promise<void>;
      onSuccess?: (result: AsyncActionResponse<Res, undefined, Custom>) => unknown | Promise<unknown>;
      onError?: (result: AsyncActionResponse<never, Req, Custom>) => unknown | Promise<unknown>;
      reject?: boolean;
      abort?: { condition: boolean; onAbort?: () => void };
      fallbackResponse?: Res;
      maxRetries?: number;
    }
  ): Promise<AsyncActionResponse<Res, Req, Custom>>;
  createAsyncResource<Res, Req = unknown>(
    action: Promise<Res> | (() => Promise<Res>),
    args?: {
      beforeSend?: (next: () => void, abort: () => void) => void | Promise<void>;
      onSuccess?: (result: Res) => unknown | Promise<unknown>;
      onError?: (error: AppError<Req, Custom>) => unknown | Promise<unknown>;
      reject?: boolean;
      abort?: { condition: boolean; onAbort?: () => void };
      fallbackResponse?: Res;
      maxRetries?: number;
    }
  ): Promise<Res>;
}

Creates two wrappers for async workflows:

  • createAsyncAction - returns { success, response, error }
  • createAsyncResource - returns response directly

createErrorParser

Import

ts
import {
  createErrorParser,
  baseParseBaseError,
  baseParseHttpError,
  baseParseSchemaError
} from '@azure-net/kit';

TypeScript signature

ts
createErrorParser<BaseError = unknown, Custom = unknown>(parsers?: {
  parseBaseError?: typeof baseParseBaseError<Custom>;
  parseHttpError?: typeof baseParseHttpError<BaseError, Custom>;
  parseSchemaError?: typeof baseParseSchemaError<BaseError, Custom>;
}): <T = unknown>(error: ErrorType<BaseError>, retry?: () => unknown) => Promise<AppError<T, Custom>>

Normalizes different error sources into one AppError shape.


createServerAction

Import

ts
import { createServerAction } from '@azure-net/kit';

TypeScript signature

ts
createServerAction<T, I extends Record<string, unknown> = Record<string, unknown>>(
  factory: (args: {
    context: RequestEvent;
    utils: { fail: typeof fail; redirect: typeof redirect; error: typeof error };
  } & I) => T,
  inject?: I
): () => T

Creates server-only action. Throws if called in browser runtime.


createServerActionFactory

Import

ts
import { createServerActionFactory } from '@azure-net/kit';

TypeScript signature

ts
createServerActionFactory<I extends Record<string, unknown>>(inject: I):
  <T>(factory: (args: { context: RequestEvent; utils: Utils } & I) => T) => () => T

Factory that pre-binds shared dependencies for multiple actions.


Schema API

schema

Import

ts
import { schema } from '@azure-net/kit';

TypeScript signature

ts
schema<SchemaData>(): Schema<SchemaData, SchemaData, {}>

Entry point of the schema builder.

createSchemaFactory

Import

ts
import { createSchemaFactory } from '@azure-net/kit';

TypeScript signature

ts
createSchemaFactory<Rules extends Record<string, unknown>>(rules: Rules):
  <SchemaData>() => Schema<SchemaData, SchemaData, Rules>

Builds a typed schema factory with your custom rules collection.

createRules

Import

ts
import { createRules, validationMessagesEn } from '@azure-net/kit/schema';

TypeScript signature

ts
createRules<M>(validationMessages: M): {
  string: ...;
  number: ...;
  finite: ...;
  boolean: ...;
  array: ...;
  phone: ...;
  email: ...;
  lettersOnly: ...;
  allowedOnly: ...;
  sameAs: ...;
  notSameAs: ...;
  required: ...;
  password: ...;
}

Returns built-in validation rule creators using selected message pack.