Skip to content

js: Add internal lib #1823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion codegen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,33 @@ output_dir = "rust/src/models"

[javascript]
template_dir = "javascript/templates"
extra_shell_commands = ["rm javascript/src/api/{ingest,ingestSource,operationalWebhook}.ts"]
extra_shell_commands = [
"rm javascript/src/models/retryScheduleInOut.ts",
"rm javascript/src/models/listResponseSinkOut.ts",
"rm javascript/src/api/{ingest,ingestSource,operationalWebhook}.ts",
]
[[javascript.task]]
template = "javascript/templates/api_resource.ts.jinja"
output_dir = "javascript/src/api"
[[javascript.task]]
template = "javascript/templates/api_resource.ts.jinja"
output_dir = "javascript/src/api_internal"
extra_codegen_args = [
"--include-mode=only-hidden",
"-e=v1.environment.get-settings",
"-e=v1.event-type.update-retry-schedule",
"-e=v1.event-type.get-retry-schedule",
"-e=v1.sink.get",
"-e=v1.sink.list",
"-e=v1.sink.create",
]
[[javascript.task]]
template = "javascript/templates/component_type_summary.ts.jinja"
output_dir = "javascript/src/models"
[[javascript.task]]
template = "javascript/templates/component_type.ts.jinja"
output_dir = "javascript/src/models"
extra_codegen_args = ["--include-mode=public-and-hidden"]
#
#
[cli]
Expand Down
28 changes: 28 additions & 0 deletions javascript/src/api_internal/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// this file is @generated
import { ApplicationStats, ApplicationStatsSerializer } from "../models/applicationStats";
import { HttpMethod, SvixRequest, SvixRequestContext } from "../request";

export interface ApplicationGetStatsOptions {
/** Filter the range to data starting from this date. */
since: Date | null;
/** Filter the range to data ending by this date. */
until: Date | null;
}

export class Application {
public constructor(private readonly requestCtx: SvixRequestContext) {}

/** Get basic statistics for the application. */
public getStats(
appId: string,
options: ApplicationGetStatsOptions
): Promise<ApplicationStats> {
const request = new SvixRequest(HttpMethod.GET, "/api/v1/app/{app_id}/stats");

request.setPathParam("app_id", appId);
request.setQueryParam("since", options.since);
request.setQueryParam("until", options.until);

return request.send(this.requestCtx, ApplicationStatsSerializer._fromJsonObject);
}
}
120 changes: 120 additions & 0 deletions javascript/src/api_internal/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// this file is @generated
import {
AppPortalAccessOut,
AppPortalAccessOutSerializer,
} from "../models/appPortalAccessOut";
import { AuthTokenOut, AuthTokenOutSerializer } from "../models/authTokenOut";
import { CreateTokenIn, CreateTokenInSerializer } from "../models/createTokenIn";
import { OneTimeTokenIn, OneTimeTokenInSerializer } from "../models/oneTimeTokenIn";
import { OneTimeTokenOut, OneTimeTokenOutSerializer } from "../models/oneTimeTokenOut";
import {
RotatePollerTokenIn,
RotatePollerTokenInSerializer,
} from "../models/rotatePollerTokenIn";
import {
StreamPortalAccessIn,
StreamPortalAccessInSerializer,
} from "../models/streamPortalAccessIn";
import { HttpMethod, SvixRequest, SvixRequestContext } from "../request";

export interface AuthenticationCreateMessageTokenOptions {
idempotencyKey?: string;
}

export interface AuthenticationRotatePollerTokenOptions {
idempotencyKey?: string;
}

export interface AuthenticationExchangeOneTimeTokenOptions {
idempotencyKey?: string;
}

export interface AuthenticationStreamPortalAccessOptions {
idempotencyKey?: string;
}

export class Authentication {
public constructor(private readonly requestCtx: SvixRequestContext) {}

/** Create a new access token that only allows creating messages inside this application. */
public createMessageToken(
appId: string,
createTokenIn: CreateTokenIn,
options?: AuthenticationCreateMessageTokenOptions
): Promise<AuthTokenOut> {
const request = new SvixRequest(
HttpMethod.POST,
"/api/v1/auth/app/{app_id}/create-message-token"
);

request.setPathParam("app_id", appId);
request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(CreateTokenInSerializer._toJsonObject(createTokenIn));

return request.send(this.requestCtx, AuthTokenOutSerializer._fromJsonObject);
}

/** Get the current auth token for the poller. */
public getPollerToken(appId: string, endpointId: string): Promise<AuthTokenOut> {
const request = new SvixRequest(
HttpMethod.GET,
"/api/v1/auth/app/{app_id}/poller/{endpoint_id}/token"
);

request.setPathParam("app_id", appId);
request.setPathParam("endpoint_id", endpointId);

return request.send(this.requestCtx, AuthTokenOutSerializer._fromJsonObject);
}

/** Create a new auth token that can for the poller API. */
public rotatePollerToken(
appId: string,
endpointId: string,
rotatePollerTokenIn: RotatePollerTokenIn,
options?: AuthenticationRotatePollerTokenOptions
): Promise<AuthTokenOut> {
const request = new SvixRequest(
HttpMethod.POST,
"/api/v1/auth/app/{app_id}/poller/{endpoint_id}/token/rotate"
);

request.setPathParam("app_id", appId);
request.setPathParam("endpoint_id", endpointId);
request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(RotatePollerTokenInSerializer._toJsonObject(rotatePollerTokenIn));

return request.send(this.requestCtx, AuthTokenOutSerializer._fromJsonObject);
}

/** This is a one time token. */
public exchangeOneTimeToken(
oneTimeTokenIn: OneTimeTokenIn,
options?: AuthenticationExchangeOneTimeTokenOptions
): Promise<OneTimeTokenOut> {
const request = new SvixRequest(HttpMethod.POST, "/api/v1/auth/one-time-token");

request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(OneTimeTokenInSerializer._toJsonObject(oneTimeTokenIn));

return request.send(this.requestCtx, OneTimeTokenOutSerializer._fromJsonObject);
}

/** Use this function to get magic links (and authentication codes) for connecting your users to the Stream Consumer Portal. */
public streamPortalAccess(
streamId: string,
streamPortalAccessIn: StreamPortalAccessIn,
options?: AuthenticationStreamPortalAccessOptions
): Promise<AppPortalAccessOut> {
const request = new SvixRequest(
HttpMethod.POST,
"/api/v1/auth/stream-portal-access/{stream_id}"
);

request.setPathParam("stream_id", streamId);
request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(StreamPortalAccessInSerializer._toJsonObject(streamPortalAccessIn));

return request.send(this.requestCtx, AppPortalAccessOutSerializer._fromJsonObject);
}
}
5 changes: 5 additions & 0 deletions javascript/src/api_internal/beta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SvixRequestContext } from "../request";

export class Beta {
public constructor(private readonly requestCtx: SvixRequestContext) {}
}
166 changes: 166 additions & 0 deletions javascript/src/api_internal/betaConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// this file is @generated
import { ConnectorIn, ConnectorInSerializer } from "../models/connectorIn";
import { ConnectorOut, ConnectorOutSerializer } from "../models/connectorOut";
import { ConnectorPatch, ConnectorPatchSerializer } from "../models/connectorPatch";
import { GenerateIn, GenerateInSerializer } from "../models/generateIn";
import { GenerateOut, GenerateOutSerializer } from "../models/generateOut";
import {
ListResponseConnectorOut,
ListResponseConnectorOutSerializer,
} from "../models/listResponseConnectorOut";
import { Ordering } from "../models/ordering";
import { TemplateUpdate, TemplateUpdateSerializer } from "../models/templateUpdate";
import {
TransformationSimulateIn,
TransformationSimulateInSerializer,
} from "../models/transformationSimulateIn";
import {
TransformationSimulateOut,
TransformationSimulateOutSerializer,
} from "../models/transformationSimulateOut";
import { HttpMethod, SvixRequest, SvixRequestContext } from "../request";

export interface BetaConnectorListOptions {
/** Limit the number of returned items */
limit?: number;
/** The iterator returned from a prior invocation */
iterator?: string | null;
/** The sorting order of the returned items */
order?: Ordering;
}

export interface BetaConnectorCreateOptions {
idempotencyKey?: string;
}

export interface BetaConnectorGenerateOptions {
idempotencyKey?: string;
}

export interface BetaConnectorSimulateOptions {
idempotencyKey?: string;
}

export class BetaConnector {
public constructor(private readonly requestCtx: SvixRequestContext) {}

/** List all transformation templates for an application. */
public list(options?: BetaConnectorListOptions): Promise<ListResponseConnectorOut> {
const request = new SvixRequest(HttpMethod.GET, "/api/v1/transformation-template");

request.setQueryParam("limit", options?.limit);
request.setQueryParam("iterator", options?.iterator);
request.setQueryParam("order", options?.order);

return request.send(
this.requestCtx,
ListResponseConnectorOutSerializer._fromJsonObject
);
}

/** Create a new connector. */
public create(
connectorIn: ConnectorIn,
options?: BetaConnectorCreateOptions
): Promise<ConnectorOut> {
const request = new SvixRequest(HttpMethod.POST, "/api/v1/transformation-template");

request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(ConnectorInSerializer._toJsonObject(connectorIn));

return request.send(this.requestCtx, ConnectorOutSerializer._fromJsonObject);
}

/** Use OpenAI's Completion API to generate code for a connector. */
public generate(
generateIn: GenerateIn,
options?: BetaConnectorGenerateOptions
): Promise<GenerateOut> {
const request = new SvixRequest(
HttpMethod.POST,
"/api/v1/transformation-template/generate"
);

request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(GenerateInSerializer._toJsonObject(generateIn));

return request.send(this.requestCtx, GenerateOutSerializer._fromJsonObject);
}

/** Simulate running the transformation on the payload and code. */
public simulate(
transformationSimulateIn: TransformationSimulateIn,
options?: BetaConnectorSimulateOptions
): Promise<TransformationSimulateOut> {
const request = new SvixRequest(
HttpMethod.POST,
"/api/v1/transformation-template/simulate"
);

request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(
TransformationSimulateInSerializer._toJsonObject(transformationSimulateIn)
);

return request.send(
this.requestCtx,
TransformationSimulateOutSerializer._fromJsonObject
);
}

/** Get a connector. */
public get(transformationTemplateId: string): Promise<ConnectorOut> {
const request = new SvixRequest(
HttpMethod.GET,
"/api/v1/transformation-template/{transformation_template_id}"
);

request.setPathParam("transformation_template_id", transformationTemplateId);

return request.send(this.requestCtx, ConnectorOutSerializer._fromJsonObject);
}

/** Update a connector. */
public update(
transformationTemplateId: string,
templateUpdate: TemplateUpdate
): Promise<ConnectorOut> {
const request = new SvixRequest(
HttpMethod.PUT,
"/api/v1/transformation-template/{transformation_template_id}"
);

request.setPathParam("transformation_template_id", transformationTemplateId);
request.setBody(TemplateUpdateSerializer._toJsonObject(templateUpdate));

return request.send(this.requestCtx, ConnectorOutSerializer._fromJsonObject);
}

/** Delete a connector. */
public delete(transformationTemplateId: string): Promise<void> {
const request = new SvixRequest(
HttpMethod.DELETE,
"/api/v1/transformation-template/{transformation_template_id}"
);

request.setPathParam("transformation_template_id", transformationTemplateId);

return request.sendNoResponseBody(this.requestCtx);
}

/** Partially update a connector. */
public patch(
transformationTemplateId: string,
connectorPatch: ConnectorPatch
): Promise<ConnectorOut> {
const request = new SvixRequest(
HttpMethod.PATCH,
"/api/v1/transformation-template/{transformation_template_id}"
);

request.setPathParam("transformation_template_id", transformationTemplateId);
request.setBody(ConnectorPatchSerializer._toJsonObject(connectorPatch));

return request.send(this.requestCtx, ConnectorOutSerializer._fromJsonObject);
}
}
Loading