create-disposabl-app 0.8.10 → 0.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/disposabl.js +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/default/bun.lock +1 -7
- package/dist/templates/default/packages/backend/README.md +4 -8
- package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +0 -67
- package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +0 -9
- package/dist/templates/default/packages/backend/convex/convex.config.ts +0 -11
- package/dist/templates/default/packages/backend/convex/http.ts +1 -9
- package/dist/templates/default/packages/backend/convex/schema.ts +1 -70
- package/dist/templates/default/packages/backend/generated/openapi.json +1 -1262
- package/dist/templates/default/packages/backend/generated/pages.json +0 -4
- package/dist/templates/default/packages/backend/generated/platforms.ts +2 -20
- package/dist/templates/default/packages/backend/package.json +1 -7
- package/dist/templates/default/packages/skill/SKILL.md +5 -5
- package/dist/templates/default/packages/skill/references/delivery.md +1 -1
- package/package.json +1 -1
- package/dist/templates/default/packages/backend/convex/apps/actions/cleanup.ts +0 -317
- package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +0 -30
- package/dist/templates/default/packages/backend/convex/apps/actions/delete.ts +0 -15
- package/dist/templates/default/packages/backend/convex/apps/actions/expo.ts +0 -180
- package/dist/templates/default/packages/backend/convex/apps/actions/setup.ts +0 -48
- package/dist/templates/default/packages/backend/convex/apps/internal.ts +0 -211
- package/dist/templates/default/packages/backend/convex/apps/operations/internal.ts +0 -239
- package/dist/templates/default/packages/backend/convex/apps/validator.ts +0 -23
- package/dist/templates/default/packages/backend/convex/connections/actions/credentials.ts +0 -56
- package/dist/templates/default/packages/backend/convex/connections/actions/expo.ts +0 -79
- package/dist/templates/default/packages/backend/convex/connections/actions/github.ts +0 -119
- package/dist/templates/default/packages/backend/convex/connections/actions/oauth.ts +0 -128
- package/dist/templates/default/packages/backend/convex/connections/index.ts +0 -80
- package/dist/templates/default/packages/backend/convex/connections/internal.ts +0 -147
- package/dist/templates/default/packages/backend/convex/connections/validator.ts +0 -35
- package/dist/templates/default/packages/backend/convex/downloads/action.ts +0 -136
- package/dist/templates/default/packages/backend/convex/downloads/http.ts +0 -32
- package/dist/templates/default/packages/backend/convex/downloads/internal.ts +0 -58
- package/dist/templates/default/packages/backend/convex/github/actions/http.ts +0 -69
- package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +0 -196
- package/dist/templates/default/packages/backend/convex/github/actions/oidc.ts +0 -75
- package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +0 -76
- package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +0 -180
- package/dist/templates/default/packages/backend/convex/github/actions/signing.ts +0 -41
- package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +0 -145
- package/dist/templates/default/packages/backend/convex/github/identityCache.ts +0 -54
- package/dist/templates/default/packages/backend/convex/github/internal.ts +0 -33
- package/dist/templates/default/packages/backend/convex/previews/internal.ts +0 -257
- package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +0 -83
- package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +0 -182
- package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +0 -32
- package/dist/templates/default/packages/backend/convex/releases/internal.ts +0 -28
- package/dist/templates/default/packages/backend/convex/validator.ts +0 -87
- package/dist/templates/default/packages/sdk/src/generated/client/client.gen.ts +0 -300
- package/dist/templates/default/packages/sdk/src/generated/client/index.ts +0 -27
- package/dist/templates/default/packages/sdk/src/generated/client/types.gen.ts +0 -238
- package/dist/templates/default/packages/sdk/src/generated/client/utils.gen.ts +0 -337
- package/dist/templates/default/packages/sdk/src/generated/client.gen.ts +0 -28
- package/dist/templates/default/packages/sdk/src/generated/core/auth.gen.ts +0 -49
- package/dist/templates/default/packages/sdk/src/generated/core/bodySerializer.gen.ts +0 -96
- package/dist/templates/default/packages/sdk/src/generated/core/params.gen.ts +0 -188
- package/dist/templates/default/packages/sdk/src/generated/core/pathSerializer.gen.ts +0 -186
- package/dist/templates/default/packages/sdk/src/generated/core/queryKeySerializer.gen.ts +0 -134
- package/dist/templates/default/packages/sdk/src/generated/core/serverSentEvents.gen.ts +0 -265
- package/dist/templates/default/packages/sdk/src/generated/core/types.gen.ts +0 -126
- package/dist/templates/default/packages/sdk/src/generated/core/utils.gen.ts +0 -146
- package/dist/templates/default/packages/sdk/src/generated/index.ts +0 -63
- package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +0 -234
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +0 -660
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
export class ManagementError extends Error {
|
|
2
|
-
constructor(readonly status: number) {
|
|
3
|
-
super(`Convex management request failed (${status}).`);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
export async function management<T>(
|
|
7
|
-
token: string,
|
|
8
|
-
path: string,
|
|
9
|
-
body?: unknown,
|
|
10
|
-
): Promise<T> {
|
|
11
|
-
const response = await fetch(`https://api.convex.dev/v1${path}`, {
|
|
12
|
-
method: body === undefined ? "GET" : "POST",
|
|
13
|
-
redirect: "error",
|
|
14
|
-
headers: {
|
|
15
|
-
Authorization: `Bearer ${token}`,
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
},
|
|
18
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
19
|
-
signal: AbortSignal.timeout(30_000),
|
|
20
|
-
});
|
|
21
|
-
if (!response.ok) throw new ManagementError(response.status);
|
|
22
|
-
const text = await response.text();
|
|
23
|
-
return (text ? JSON.parse(text) : undefined) as T;
|
|
24
|
-
}
|
|
25
|
-
/** Recover a project after a lost create response; names include the immutable app UUID. */
|
|
26
|
-
export async function ensureProject(
|
|
27
|
-
token: string,
|
|
28
|
-
teamId: string,
|
|
29
|
-
appId: string,
|
|
30
|
-
) {
|
|
31
|
-
const name = `disposabl-${appId}`;
|
|
32
|
-
const lookup = async () => {
|
|
33
|
-
const result = await management<{ items: { id: number; name: string }[] }>(
|
|
34
|
-
token,
|
|
35
|
-
`/teams/${teamId}/projects?q=${encodeURIComponent(name)}&limit=100`,
|
|
36
|
-
);
|
|
37
|
-
const matches = result.items.filter((project) => project.name === name);
|
|
38
|
-
if (matches.length > 1)
|
|
39
|
-
throw new Error(
|
|
40
|
-
"Multiple Convex projects match this app. Reconcile before retrying.",
|
|
41
|
-
);
|
|
42
|
-
return matches[0];
|
|
43
|
-
};
|
|
44
|
-
const existing = await lookup();
|
|
45
|
-
if (existing) return existing.id;
|
|
46
|
-
try {
|
|
47
|
-
return (
|
|
48
|
-
await management<{ id: number }>(
|
|
49
|
-
token,
|
|
50
|
-
`/teams/${teamId}/create_project`,
|
|
51
|
-
{ projectName: name },
|
|
52
|
-
)
|
|
53
|
-
).id;
|
|
54
|
-
} catch (error) {
|
|
55
|
-
const recovered = await lookup();
|
|
56
|
-
if (recovered) return recovered.id;
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
type Deployment = {
|
|
61
|
-
name: string;
|
|
62
|
-
projectId: number;
|
|
63
|
-
deploymentType: string;
|
|
64
|
-
kind: string;
|
|
65
|
-
reference: string;
|
|
66
|
-
deploymentUrl: string;
|
|
67
|
-
};
|
|
68
|
-
export async function ensureDevelopment(
|
|
69
|
-
token: string,
|
|
70
|
-
projectId: number,
|
|
71
|
-
reference: string,
|
|
72
|
-
) {
|
|
73
|
-
const path = `/projects/${projectId}`;
|
|
74
|
-
const lookup = () =>
|
|
75
|
-
management<Deployment>(
|
|
76
|
-
token,
|
|
77
|
-
`${path}/deployment?reference=${encodeURIComponent(reference)}`,
|
|
78
|
-
);
|
|
79
|
-
let deployment: Deployment;
|
|
80
|
-
try {
|
|
81
|
-
deployment = await lookup();
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (!(error instanceof ManagementError) || error.status !== 404)
|
|
84
|
-
throw error;
|
|
85
|
-
try {
|
|
86
|
-
deployment = await management<Deployment>(
|
|
87
|
-
token,
|
|
88
|
-
`${path}/create_deployment`,
|
|
89
|
-
{ type: "dev", reference, isDefault: false },
|
|
90
|
-
);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
try {
|
|
93
|
-
deployment = await lookup();
|
|
94
|
-
} catch {
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (
|
|
100
|
-
deployment.kind !== "cloud" ||
|
|
101
|
-
deployment.deploymentType !== "dev" ||
|
|
102
|
-
deployment.projectId !== projectId ||
|
|
103
|
-
deployment.reference !== reference
|
|
104
|
-
)
|
|
105
|
-
throw new Error("Expected this app's named development deployment.");
|
|
106
|
-
const url = new URL(deployment.deploymentUrl);
|
|
107
|
-
if (
|
|
108
|
-
url.protocol !== "https:" ||
|
|
109
|
-
!url.hostname.endsWith(".convex.cloud") ||
|
|
110
|
-
url.username ||
|
|
111
|
-
url.password ||
|
|
112
|
-
url.port ||
|
|
113
|
-
url.pathname !== "/" ||
|
|
114
|
-
url.search ||
|
|
115
|
-
url.hash
|
|
116
|
-
)
|
|
117
|
-
throw new Error("Unexpected Convex deployment URL.");
|
|
118
|
-
const convexUrl = url.origin;
|
|
119
|
-
const convexSiteUrl = convexUrl.replace(/\.convex\.cloud$/, ".convex.site");
|
|
120
|
-
const { deployKey } = await management<{ deployKey: string }>(
|
|
121
|
-
token,
|
|
122
|
-
`/deployments/${encodeURIComponent(deployment.name)}/create_deploy_key`,
|
|
123
|
-
{ name: `disposabl-${reference}` },
|
|
124
|
-
);
|
|
125
|
-
if (!deployKey.startsWith(`dev:${deployment.name}|`))
|
|
126
|
-
throw new Error("Expected a development-scoped key.");
|
|
127
|
-
return {
|
|
128
|
-
name: deployment.name,
|
|
129
|
-
reference,
|
|
130
|
-
convexUrl,
|
|
131
|
-
convexSiteUrl,
|
|
132
|
-
deployKey,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export async function productionDeployment(token: string, projectId: number) {
|
|
137
|
-
const path = `/projects/${projectId}`;
|
|
138
|
-
const lookup = () =>
|
|
139
|
-
management<Deployment>(token, `${path}/deployment?defaultProd=true`);
|
|
140
|
-
let deployment: Deployment;
|
|
141
|
-
try {
|
|
142
|
-
deployment = await lookup();
|
|
143
|
-
} catch (error) {
|
|
144
|
-
if (!(error instanceof ManagementError) || error.status !== 404)
|
|
145
|
-
throw error;
|
|
146
|
-
try {
|
|
147
|
-
deployment = await management<Deployment>(
|
|
148
|
-
token,
|
|
149
|
-
`${path}/create_deployment`,
|
|
150
|
-
{ type: "prod" },
|
|
151
|
-
);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
try {
|
|
154
|
-
deployment = await lookup();
|
|
155
|
-
} catch {
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (
|
|
161
|
-
deployment.kind !== "cloud" ||
|
|
162
|
-
deployment.deploymentType !== "prod" ||
|
|
163
|
-
deployment.projectId !== projectId
|
|
164
|
-
)
|
|
165
|
-
throw new Error("Expected this app's production deployment.");
|
|
166
|
-
const url = new URL(deployment.deploymentUrl);
|
|
167
|
-
if (
|
|
168
|
-
!/^[a-z0-9-]+$/.test(deployment.name) ||
|
|
169
|
-
url.origin !== `https://${deployment.name}.convex.cloud` ||
|
|
170
|
-
url.pathname !== "/" ||
|
|
171
|
-
url.search ||
|
|
172
|
-
url.hash ||
|
|
173
|
-
url.username ||
|
|
174
|
-
url.password
|
|
175
|
-
)
|
|
176
|
-
throw new Error("Unexpected Convex production URL.");
|
|
177
|
-
return deployment;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export async function ensureProduction(token: string, projectId: number) {
|
|
181
|
-
return (await productionDeployment(token, projectId)).name;
|
|
182
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalAction,
|
|
4
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
-
import { v } from "convex/values";
|
|
6
|
-
import { internal } from "../../_generated/api";
|
|
7
|
-
import { deployment, previewIdentity } from "../../validator";
|
|
8
|
-
|
|
9
|
-
export const create = internalAction({
|
|
10
|
-
platforms: true,
|
|
11
|
-
args: { ...identityFields, ...previewIdentity },
|
|
12
|
-
returns: v.object({
|
|
13
|
-
appId: v.string(),
|
|
14
|
-
...deployment.fields,
|
|
15
|
-
deployKey: v.string(),
|
|
16
|
-
productionConvexSiteUrl: v.optional(v.string()),
|
|
17
|
-
repositoryUrl: v.optional(v.string()),
|
|
18
|
-
}),
|
|
19
|
-
handler: async (
|
|
20
|
-
ctx,
|
|
21
|
-
args,
|
|
22
|
-
): Promise<{
|
|
23
|
-
appId: string;
|
|
24
|
-
name: string;
|
|
25
|
-
reference: string;
|
|
26
|
-
convexUrl: string;
|
|
27
|
-
convexSiteUrl: string;
|
|
28
|
-
deployKey: string;
|
|
29
|
-
productionConvexSiteUrl?: string;
|
|
30
|
-
repositoryUrl?: string;
|
|
31
|
-
}> => ctx.runAction(internal.previews.token.actions.create.create, args),
|
|
32
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
identityFields,
|
|
3
|
-
internalQuery,
|
|
4
|
-
} from "@disposabl/disposabl-kit/server/lib/functions";
|
|
5
|
-
import { v } from "convex/values";
|
|
6
|
-
import { releasesResult } from "../validator";
|
|
7
|
-
import { ownedApp } from "../apps/internal";
|
|
8
|
-
import { presentPlatforms } from "../previews/internal";
|
|
9
|
-
|
|
10
|
-
export const get = internalQuery({
|
|
11
|
-
platforms: true,
|
|
12
|
-
args: { ...identityFields, appId: v.string() },
|
|
13
|
-
returns: v.union(releasesResult, v.null()),
|
|
14
|
-
handler: async (ctx, { userId, appId }) => {
|
|
15
|
-
const app = await ownedApp(ctx, userId, appId);
|
|
16
|
-
const release = await ctx.db
|
|
17
|
-
.query("appReleases")
|
|
18
|
-
.withIndex("by_appId", (q) => q.eq("appId", appId))
|
|
19
|
-
.unique();
|
|
20
|
-
return release
|
|
21
|
-
? {
|
|
22
|
-
appId,
|
|
23
|
-
platforms: presentPlatforms(app, release.releases),
|
|
24
|
-
updatedAt: release.updatedAt,
|
|
25
|
-
}
|
|
26
|
-
: null;
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
2
|
-
|
|
3
|
-
export const platformNames = [
|
|
4
|
-
"web",
|
|
5
|
-
"android",
|
|
6
|
-
"ios",
|
|
7
|
-
"macos",
|
|
8
|
-
"windows",
|
|
9
|
-
"linux",
|
|
10
|
-
"api",
|
|
11
|
-
"mcp",
|
|
12
|
-
"typescript-sdk",
|
|
13
|
-
"cli",
|
|
14
|
-
] as const;
|
|
15
|
-
export const platform = v.union(
|
|
16
|
-
...platformNames.map((name) => v.literal(name)),
|
|
17
|
-
);
|
|
18
|
-
export const githubConnection = v.object({
|
|
19
|
-
owner: v.string(),
|
|
20
|
-
installationId: v.string(),
|
|
21
|
-
});
|
|
22
|
-
export const appFields = {
|
|
23
|
-
appId: v.string(),
|
|
24
|
-
name: v.string(),
|
|
25
|
-
platforms: v.array(platform),
|
|
26
|
-
};
|
|
27
|
-
export const appArgs = {
|
|
28
|
-
name: v.string(),
|
|
29
|
-
platforms: v.array(platform),
|
|
30
|
-
};
|
|
31
|
-
export const appResult = v.object({
|
|
32
|
-
...appFields,
|
|
33
|
-
githubOwner: v.optional(v.string()),
|
|
34
|
-
githubRepo: v.optional(v.string()),
|
|
35
|
-
createdAt: v.number(),
|
|
36
|
-
});
|
|
37
|
-
export const previewIdentity = { appId: v.string(), reference: v.string() };
|
|
38
|
-
export const deployment = v.object({
|
|
39
|
-
name: v.string(),
|
|
40
|
-
reference: v.string(),
|
|
41
|
-
convexUrl: v.string(),
|
|
42
|
-
convexSiteUrl: v.string(),
|
|
43
|
-
});
|
|
44
|
-
export const run = v.object({
|
|
45
|
-
id: v.number(),
|
|
46
|
-
attempt: v.number(),
|
|
47
|
-
number: v.number(),
|
|
48
|
-
commitSha: v.string(),
|
|
49
|
-
url: v.string(),
|
|
50
|
-
});
|
|
51
|
-
export const releaseDetails = {
|
|
52
|
-
status: v.union(
|
|
53
|
-
v.literal("building"),
|
|
54
|
-
v.literal("ready"),
|
|
55
|
-
v.literal("failed"),
|
|
56
|
-
v.literal("blocked"),
|
|
57
|
-
),
|
|
58
|
-
reason: v.optional(v.string()),
|
|
59
|
-
version: v.optional(v.string()),
|
|
60
|
-
url: v.optional(v.string()),
|
|
61
|
-
githubReleaseUrl: v.optional(v.string()),
|
|
62
|
-
artifactUrl: v.optional(v.string()),
|
|
63
|
-
updateUrl: v.optional(v.string()),
|
|
64
|
-
};
|
|
65
|
-
export const release = v.object({ ...releaseDetails, run });
|
|
66
|
-
export const releases = v.record(v.string(), release);
|
|
67
|
-
const platformStates = v.record(
|
|
68
|
-
v.string(),
|
|
69
|
-
v.object({
|
|
70
|
-
enabled: v.boolean(),
|
|
71
|
-
url: v.optional(v.string()),
|
|
72
|
-
latest: v.optional(release.omit("url")),
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
export const previewResult = v.object({
|
|
76
|
-
appId: v.string(),
|
|
77
|
-
reference: v.string(),
|
|
78
|
-
stage: v.union(v.literal("generating"), v.literal("building")),
|
|
79
|
-
deployment: v.optional(deployment),
|
|
80
|
-
platforms: platformStates,
|
|
81
|
-
updatedAt: v.number(),
|
|
82
|
-
});
|
|
83
|
-
export const releasesResult = v.object({
|
|
84
|
-
appId: v.string(),
|
|
85
|
-
platforms: platformStates,
|
|
86
|
-
updatedAt: v.number(),
|
|
87
|
-
});
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
|
|
3
|
-
import { createSseClient } from "../core/serverSentEvents.gen.js";
|
|
4
|
-
import type { HttpMethod } from "../core/types.gen.js";
|
|
5
|
-
import { getValidRequestBody } from "../core/utils.gen.js";
|
|
6
|
-
import type {
|
|
7
|
-
Client,
|
|
8
|
-
Config,
|
|
9
|
-
RequestOptions,
|
|
10
|
-
ResolvedRequestOptions,
|
|
11
|
-
} from "./types.gen.js";
|
|
12
|
-
import {
|
|
13
|
-
buildUrl,
|
|
14
|
-
createConfig,
|
|
15
|
-
createInterceptors,
|
|
16
|
-
getParseAs,
|
|
17
|
-
mergeConfigs,
|
|
18
|
-
mergeHeaders,
|
|
19
|
-
setAuthParams,
|
|
20
|
-
} from "./utils.gen.js";
|
|
21
|
-
|
|
22
|
-
type ReqInit = Omit<RequestInit, "body" | "headers"> & {
|
|
23
|
-
body?: any;
|
|
24
|
-
headers: ReturnType<typeof mergeHeaders>;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const createClient = (config: Config = {}): Client => {
|
|
28
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
29
|
-
|
|
30
|
-
const getConfig = (): Config => ({ ..._config });
|
|
31
|
-
|
|
32
|
-
const setConfig = (config: Config): Config => {
|
|
33
|
-
_config = mergeConfigs(_config, config);
|
|
34
|
-
return getConfig();
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const interceptors = createInterceptors<
|
|
38
|
-
Request,
|
|
39
|
-
Response,
|
|
40
|
-
unknown,
|
|
41
|
-
ResolvedRequestOptions
|
|
42
|
-
>();
|
|
43
|
-
|
|
44
|
-
const beforeRequest = async <
|
|
45
|
-
TData = unknown,
|
|
46
|
-
TResponseStyle extends "data" | "fields" = "fields",
|
|
47
|
-
ThrowOnError extends boolean = boolean,
|
|
48
|
-
Url extends string = string,
|
|
49
|
-
>(
|
|
50
|
-
options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
|
|
51
|
-
) => {
|
|
52
|
-
const opts = {
|
|
53
|
-
..._config,
|
|
54
|
-
...options,
|
|
55
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
56
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
57
|
-
serializedBody: undefined as string | undefined,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (opts.security) {
|
|
61
|
-
await setAuthParams(opts);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (opts.requestValidator) {
|
|
65
|
-
await opts.requestValidator(opts);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (opts.body !== undefined && opts.bodySerializer) {
|
|
69
|
-
opts.serializedBody = opts.bodySerializer(opts.body) as
|
|
70
|
-
string | undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
74
|
-
if (opts.body === undefined || opts.serializedBody === "") {
|
|
75
|
-
opts.headers.delete("Content-Type");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const resolvedOpts = opts as typeof opts &
|
|
79
|
-
ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
|
|
80
|
-
const url = buildUrl(resolvedOpts);
|
|
81
|
-
|
|
82
|
-
return { opts: resolvedOpts, url };
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const request: Client["request"] = async (options) => {
|
|
86
|
-
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
87
|
-
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
88
|
-
|
|
89
|
-
let request: Request | undefined;
|
|
90
|
-
let response: Response | undefined;
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
const { opts, url } = await beforeRequest(options);
|
|
94
|
-
const requestInit: ReqInit = {
|
|
95
|
-
redirect: "follow",
|
|
96
|
-
...opts,
|
|
97
|
-
body: getValidRequestBody(opts),
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
request = new Request(url, requestInit);
|
|
101
|
-
|
|
102
|
-
for (const fn of interceptors.request.fns) {
|
|
103
|
-
if (fn) {
|
|
104
|
-
request = await fn(request, opts);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// fetch must be assigned here, otherwise it would throw the error:
|
|
109
|
-
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
110
|
-
const _fetch = opts.fetch!;
|
|
111
|
-
|
|
112
|
-
response = await _fetch(request);
|
|
113
|
-
|
|
114
|
-
for (const fn of interceptors.response.fns) {
|
|
115
|
-
if (fn) {
|
|
116
|
-
response = await fn(response, request, opts);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const result = {
|
|
121
|
-
request,
|
|
122
|
-
response,
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
if (response.ok) {
|
|
126
|
-
const parseAs =
|
|
127
|
-
(opts.parseAs === "auto"
|
|
128
|
-
? getParseAs(response.headers.get("Content-Type"))
|
|
129
|
-
: opts.parseAs) ?? "json";
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
response.status === 204 ||
|
|
133
|
-
response.headers.get("Content-Length") === "0"
|
|
134
|
-
) {
|
|
135
|
-
let emptyData: any;
|
|
136
|
-
switch (parseAs) {
|
|
137
|
-
case "arrayBuffer":
|
|
138
|
-
case "blob":
|
|
139
|
-
case "text":
|
|
140
|
-
emptyData = await response[parseAs]();
|
|
141
|
-
break;
|
|
142
|
-
case "formData":
|
|
143
|
-
emptyData = new FormData();
|
|
144
|
-
break;
|
|
145
|
-
case "stream":
|
|
146
|
-
emptyData = response.body;
|
|
147
|
-
break;
|
|
148
|
-
case "json":
|
|
149
|
-
default:
|
|
150
|
-
emptyData = {};
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
return opts.responseStyle === "data"
|
|
154
|
-
? emptyData
|
|
155
|
-
: {
|
|
156
|
-
data: emptyData,
|
|
157
|
-
...result,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
let data: any;
|
|
162
|
-
switch (parseAs) {
|
|
163
|
-
case "arrayBuffer":
|
|
164
|
-
case "blob":
|
|
165
|
-
case "formData":
|
|
166
|
-
case "text":
|
|
167
|
-
data = await response[parseAs]();
|
|
168
|
-
break;
|
|
169
|
-
case "json": {
|
|
170
|
-
// Some servers return 200 with no Content-Length and empty body.
|
|
171
|
-
// response.json() would throw; read as text and parse if non-empty.
|
|
172
|
-
const text = await response.text();
|
|
173
|
-
data = text ? JSON.parse(text) : {};
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
case "stream":
|
|
177
|
-
return opts.responseStyle === "data"
|
|
178
|
-
? response.body
|
|
179
|
-
: {
|
|
180
|
-
data: response.body,
|
|
181
|
-
...result,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (parseAs === "json") {
|
|
186
|
-
if (opts.responseValidator) {
|
|
187
|
-
await opts.responseValidator(data);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (opts.responseTransformer) {
|
|
191
|
-
data = await opts.responseTransformer(data);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return opts.responseStyle === "data"
|
|
196
|
-
? data
|
|
197
|
-
: {
|
|
198
|
-
data,
|
|
199
|
-
...result,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const textError = await response.text();
|
|
204
|
-
let jsonError: unknown;
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
jsonError = JSON.parse(textError);
|
|
208
|
-
} catch {
|
|
209
|
-
// noop
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
throw jsonError ?? textError;
|
|
213
|
-
} catch (error) {
|
|
214
|
-
let finalError = error;
|
|
215
|
-
|
|
216
|
-
for (const fn of interceptors.error.fns) {
|
|
217
|
-
if (fn) {
|
|
218
|
-
finalError = await fn(
|
|
219
|
-
finalError,
|
|
220
|
-
response,
|
|
221
|
-
request,
|
|
222
|
-
options as ResolvedRequestOptions,
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
finalError = finalError || {};
|
|
228
|
-
|
|
229
|
-
if (throwOnError) {
|
|
230
|
-
throw finalError;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// TODO: we probably want to return error and improve types
|
|
234
|
-
return responseStyle === "data"
|
|
235
|
-
? undefined
|
|
236
|
-
: {
|
|
237
|
-
error: finalError,
|
|
238
|
-
request,
|
|
239
|
-
response,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const makeMethodFn =
|
|
245
|
-
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
246
|
-
request({ ...options, method });
|
|
247
|
-
|
|
248
|
-
const makeSseFn =
|
|
249
|
-
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
250
|
-
const { opts, url } = await beforeRequest(options);
|
|
251
|
-
return createSseClient({
|
|
252
|
-
...opts,
|
|
253
|
-
body: opts.body as BodyInit | null | undefined,
|
|
254
|
-
method,
|
|
255
|
-
onRequest: async (url, init) => {
|
|
256
|
-
let request = new Request(url, init);
|
|
257
|
-
for (const fn of interceptors.request.fns) {
|
|
258
|
-
if (fn) {
|
|
259
|
-
request = await fn(request, opts);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return request;
|
|
263
|
-
},
|
|
264
|
-
serializedBody: getValidRequestBody(opts) as
|
|
265
|
-
BodyInit | null | undefined,
|
|
266
|
-
url,
|
|
267
|
-
});
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const _buildUrl: Client["buildUrl"] = (options) =>
|
|
271
|
-
buildUrl({ ..._config, ...options });
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
buildUrl: _buildUrl,
|
|
275
|
-
connect: makeMethodFn("CONNECT"),
|
|
276
|
-
delete: makeMethodFn("DELETE"),
|
|
277
|
-
get: makeMethodFn("GET"),
|
|
278
|
-
getConfig,
|
|
279
|
-
head: makeMethodFn("HEAD"),
|
|
280
|
-
interceptors,
|
|
281
|
-
options: makeMethodFn("OPTIONS"),
|
|
282
|
-
patch: makeMethodFn("PATCH"),
|
|
283
|
-
post: makeMethodFn("POST"),
|
|
284
|
-
put: makeMethodFn("PUT"),
|
|
285
|
-
request,
|
|
286
|
-
setConfig,
|
|
287
|
-
sse: {
|
|
288
|
-
connect: makeSseFn("CONNECT"),
|
|
289
|
-
delete: makeSseFn("DELETE"),
|
|
290
|
-
get: makeSseFn("GET"),
|
|
291
|
-
head: makeSseFn("HEAD"),
|
|
292
|
-
options: makeSseFn("OPTIONS"),
|
|
293
|
-
patch: makeSseFn("PATCH"),
|
|
294
|
-
post: makeSseFn("POST"),
|
|
295
|
-
put: makeSseFn("PUT"),
|
|
296
|
-
trace: makeSseFn("TRACE"),
|
|
297
|
-
},
|
|
298
|
-
trace: makeMethodFn("TRACE"),
|
|
299
|
-
} as Client;
|
|
300
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
|
|
3
|
-
export type { Auth } from "../core/auth.gen.js";
|
|
4
|
-
export type { QuerySerializerOptions } from "../core/bodySerializer.gen.js";
|
|
5
|
-
export {
|
|
6
|
-
formDataBodySerializer,
|
|
7
|
-
jsonBodySerializer,
|
|
8
|
-
urlSearchParamsBodySerializer,
|
|
9
|
-
} from "../core/bodySerializer.gen.js";
|
|
10
|
-
export { buildClientParams } from "../core/params.gen.js";
|
|
11
|
-
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js";
|
|
12
|
-
export type { ServerSentEventsResult } from "../core/serverSentEvents.gen.js";
|
|
13
|
-
export type { ClientMeta } from "../core/types.gen.js";
|
|
14
|
-
export { createClient } from "./client.gen.js";
|
|
15
|
-
export type {
|
|
16
|
-
Client,
|
|
17
|
-
ClientOptions,
|
|
18
|
-
Config,
|
|
19
|
-
CreateClientConfig,
|
|
20
|
-
Options,
|
|
21
|
-
RequestOptions,
|
|
22
|
-
RequestResult,
|
|
23
|
-
ResolvedRequestOptions,
|
|
24
|
-
ResponseStyle,
|
|
25
|
-
TDataShape,
|
|
26
|
-
} from "./types.gen.js";
|
|
27
|
-
export { createConfig, mergeHeaders } from "./utils.gen.js";
|