@launchpad-kit/sdk 0.0.0-bootstrap.0

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @launchpad-kit/sdk
2
+
3
+ Browser-safe HTTP SDK for the controller API, authenticated with an organization API key.
4
+
5
+ ```ts
6
+ import { createClient } from "@launchpad-kit/sdk";
7
+
8
+ const client = createClient({
9
+ baseUrl: "https://control.example.com",
10
+ apiKey: process.env.LAUNCHPAD_API_KEY!,
11
+ });
12
+ const key = await client.key.get();
13
+ const projects = await client.projects.list(key.organizationId);
14
+ ```
15
+
16
+ - Only `https` (or `http` to loopback) base URLs; the key is sent as a bearer token, never with cookies, and redirects are refused so it cannot be forwarded.
17
+ - Responses are checked against `@launchpad-kit/contracts` but tolerate fields a newer controller adds. Errors are `LaunchpadApiError` (the controller answered with an error status; `code` may be a code this version does not know), `LaunchpadTransportError` (unreachable, timeout, redirect, unexpected answer) or `LaunchpadConfigError`. None contains the key or a response body.
18
+ - Covers key info, own organization, members (read), projects, artifacts, apps, deployments and
19
+ aliases. Reconciliation requests, key, member and invitation management are session-only and
20
+ are not in the SDK. There is no legacy preview client.
21
+
22
+ ```ts
23
+ // `archive` is a Blob of .tar.gz bytes; `projectId`, `appId` and `aliasId` are exact IDs.
24
+ const org = key.organizationId;
25
+ const artifact = await client.artifacts.upload(org, projectId, archive);
26
+ const deployment = await client.deployments.create(org, appId, { artifactId: artifact.id });
27
+ // The above only queues a deployment. Wait for deployments.get(...) to report "succeeded".
28
+ const alias = await client.aliases.get(org, aliasId);
29
+ const operation = await client.aliases.promote(
30
+ org,
31
+ alias.id,
32
+ { targetDeploymentId: deployment.id, expectedGeneration: alias.reservedGeneration },
33
+ { idempotencyKey: "release-42" },
34
+ );
35
+ // Read client.aliases.operations(org, aliasId) for the result; queued does not mean routed.
36
+ ```
37
+
38
+ Use the last read **reserved** generation (a string, never a number). A stale generation
39
+ conflicts. Use the same idempotency key for retries of the exact same routing intent.
40
+ Roll back by promoting a different retained deployment. Deploy and promote need separate scopes.
41
+
42
+ Every `list` returns the whole array, as always. To page, use `listPage` (`organizations`,
43
+ `members`, `projects`, `apps`, `deployments`, `aliases`) or `aliases.operationsPage` with a
44
+ `limit` of 1 to 100; `next.cursor` is present only when more items exist and is opaque. A
45
+ `Link` is followed only if it is relative or on the controller's origin, under `/api/v1` and
46
+ for the list that was asked; anything else is ignored. `deployments.eventsPage` pages events by
47
+ `after` and returns `nextAfter`.
48
+
49
+ ```ts
50
+ let page = await client.apps.listPage(org, { limit: 50 });
51
+ const all = [...page.items];
52
+ while (page.next) {
53
+ page = await client.apps.listPage(org, { limit: 50, cursor: page.next.cursor });
54
+ all.push(...page.items);
55
+ }
56
+ ```
57
+
58
+ Depends on `zod` and `@launchpad-kit/contracts` only; no filesystem or credential storage (see `@launchpad-kit/client-core`).
package/client.d.ts ADDED
@@ -0,0 +1,340 @@
1
+ import { createApiKeySchema, createProjectSchema, createAppSchema, createAliasSchema, createDeploymentSchema, promoteAliasSchema, withdrawAliasSchema, aliasSchema, appSchema, deploymentEventSchema, deploymentSchema, promotionOperationSchema, createdProjectSchema, keyInfoSchema, memberSchema, organizationSummarySchema, projectSchema } from '@launchpad-kit/contracts';
2
+ import { z } from 'zod';
3
+ import { RawOptions } from './transport.js';
4
+ export { FORBIDDEN_RAW_HEADERS, normalizeBaseUrl, RAW_METHODS } from './transport.js';
5
+ export type { RawOptions, RawResponse } from './transport.js';
6
+ export type KeyInfo = z.infer<typeof keyInfoSchema>;
7
+ export type OrganizationSummary = z.infer<typeof organizationSummarySchema>;
8
+ export type Member = z.infer<typeof memberSchema>;
9
+ export type Project = z.infer<typeof projectSchema>;
10
+ export type CreatedProject = z.infer<typeof createdProjectSchema>;
11
+ export type CreateProjectInput = z.input<typeof createProjectSchema>;
12
+ export type CreateApiKeyInput = z.input<typeof createApiKeySchema>;
13
+ export type App = z.infer<typeof appSchema>;
14
+ export type Alias = z.infer<typeof aliasSchema>;
15
+ export type Deployment = z.infer<typeof deploymentSchema>;
16
+ export type PromotionOperation = z.infer<typeof promotionOperationSchema>;
17
+ export interface RequestOptions {
18
+ idempotencyKey?: string;
19
+ signal?: AbortSignal;
20
+ }
21
+ export interface PageOptions {
22
+ limit: number;
23
+ cursor?: string;
24
+ signal?: AbortSignal;
25
+ }
26
+ export interface Page<T> {
27
+ items: T[];
28
+ next?: {
29
+ cursor: string;
30
+ };
31
+ }
32
+ export interface EventsPage<T> {
33
+ items: T[];
34
+ nextAfter?: string;
35
+ }
36
+ export interface ClientOptions {
37
+ baseUrl: string;
38
+ apiKey: string;
39
+ fetch?: typeof fetch;
40
+ timeoutMs?: number;
41
+ }
42
+ export declare function createClient(options: ClientOptions): {
43
+ raw: (method: string, rawPath: string, options?: RawOptions) => Promise<import('./transport.js').RawResponse>;
44
+ key: {
45
+ get: () => Promise<{
46
+ id: string;
47
+ name: string;
48
+ organizationId: string;
49
+ scopes: ("organization:read" | "member:read" | "project:read" | "project:create" | "project:delete" | "app:read" | "app:deploy" | "app:delete" | "app:promote" | "app:alias:manage")[];
50
+ projectIds: string[] | null;
51
+ expiresAt: string;
52
+ }>;
53
+ };
54
+ organizations: {
55
+ list: () => Promise<{
56
+ id: string;
57
+ name: string;
58
+ slug: string;
59
+ role: "owner" | "admin" | "deployer" | "viewer";
60
+ }[]>;
61
+ listPage: (page: PageOptions) => Promise<Page<{
62
+ id: string;
63
+ name: string;
64
+ slug: string;
65
+ role: "owner" | "admin" | "deployer" | "viewer";
66
+ }>>;
67
+ get: (organizationId: string) => Promise<{
68
+ id: string;
69
+ name: string;
70
+ slug: string;
71
+ role: "owner" | "admin" | "deployer" | "viewer";
72
+ }>;
73
+ };
74
+ members: {
75
+ list: (organizationId: string) => Promise<{
76
+ userId: string;
77
+ email: string;
78
+ name: string;
79
+ role: "owner" | "admin" | "deployer" | "viewer";
80
+ }[]>;
81
+ listPage: (o: string, page: PageOptions) => Promise<Page<{
82
+ userId: string;
83
+ email: string;
84
+ name: string;
85
+ role: "owner" | "admin" | "deployer" | "viewer";
86
+ }>>;
87
+ };
88
+ projects: {
89
+ list: (organizationId: string) => Promise<{
90
+ id: string;
91
+ slug: string;
92
+ name: string;
93
+ createdAt: string;
94
+ }[]>;
95
+ listPage: (o: string, page: PageOptions) => Promise<Page<{
96
+ id: string;
97
+ slug: string;
98
+ name: string;
99
+ createdAt: string;
100
+ }>>;
101
+ create: (organizationId: string, input: CreateProjectInput) => Promise<{
102
+ id: string;
103
+ slug: string;
104
+ name: string;
105
+ }>;
106
+ };
107
+ artifacts: {
108
+ upload: (o: string, projectId: string, archive: Blob, options?: Pick<RequestOptions, "signal">) => Promise<{
109
+ id: string;
110
+ digest: string;
111
+ sizeBytes: number;
112
+ expandedBytes: number;
113
+ entryCount: number;
114
+ createdAt: string;
115
+ reused: boolean;
116
+ }>;
117
+ };
118
+ apps: {
119
+ list: (o: string) => Promise<{
120
+ id: string;
121
+ projectId: string;
122
+ slug: string;
123
+ state: "active" | "shutting-down" | "deleted";
124
+ createdAt: string;
125
+ }[]>;
126
+ listPage: (o: string, page: PageOptions) => Promise<Page<{
127
+ id: string;
128
+ projectId: string;
129
+ slug: string;
130
+ state: "active" | "shutting-down" | "deleted";
131
+ createdAt: string;
132
+ }>>;
133
+ get: (o: string, id: string) => Promise<{
134
+ id: string;
135
+ projectId: string;
136
+ slug: string;
137
+ state: "active" | "shutting-down" | "deleted";
138
+ createdAt: string;
139
+ }>;
140
+ create: (o: string, projectId: string, input: z.input<typeof createAppSchema>) => Promise<{
141
+ id: string;
142
+ projectId: string;
143
+ slug: string;
144
+ state: "active" | "shutting-down" | "deleted";
145
+ createdAt: string;
146
+ }>;
147
+ shutdown: (o: string, id: string) => Promise<{
148
+ appId: string;
149
+ state: "active" | "shutting-down" | "deleted";
150
+ withdrawalsQueued: number;
151
+ deletionsQueued: number;
152
+ blockedBy: ("aliases-disabled" | "alias-in-progress" | "alias-needs-reconciliation" | "deployment-unfinished" | "deployment-needs-reconciliation" | "deployment-deleting" | "deletion-needs-reconciliation")[];
153
+ }>;
154
+ };
155
+ deployments: {
156
+ list: (o: string, appId: string) => Promise<{
157
+ id: string;
158
+ appId: string;
159
+ status: "queued" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "preparing" | "building" | "deploying" | "cancelled";
160
+ desiredState: "active" | "deleted" | "deleting";
161
+ hostname: string;
162
+ spa: boolean;
163
+ createdAt: string;
164
+ finishedAt: string | null;
165
+ expiresAt: string;
166
+ failureCode: string | null;
167
+ failureMessage: string | null;
168
+ }[]>;
169
+ listPage: (o: string, appId: string, page: PageOptions) => Promise<Page<{
170
+ id: string;
171
+ appId: string;
172
+ status: "queued" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "preparing" | "building" | "deploying" | "cancelled";
173
+ desiredState: "active" | "deleted" | "deleting";
174
+ hostname: string;
175
+ spa: boolean;
176
+ createdAt: string;
177
+ finishedAt: string | null;
178
+ expiresAt: string;
179
+ failureCode: string | null;
180
+ failureMessage: string | null;
181
+ }>>;
182
+ create: (o: string, appId: string, input: z.input<typeof createDeploymentSchema>, options?: Pick<RequestOptions, "signal">) => Promise<{
183
+ id: string;
184
+ appId: string;
185
+ status: "queued" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "preparing" | "building" | "deploying" | "cancelled";
186
+ desiredState: "active" | "deleted" | "deleting";
187
+ hostname: string;
188
+ spa: boolean;
189
+ createdAt: string;
190
+ finishedAt: string | null;
191
+ expiresAt: string;
192
+ failureCode: string | null;
193
+ failureMessage: string | null;
194
+ }>;
195
+ get: (o: string, id: string) => Promise<{
196
+ id: string;
197
+ appId: string;
198
+ status: "queued" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "preparing" | "building" | "deploying" | "cancelled";
199
+ desiredState: "active" | "deleted" | "deleting";
200
+ hostname: string;
201
+ spa: boolean;
202
+ createdAt: string;
203
+ finishedAt: string | null;
204
+ expiresAt: string;
205
+ failureCode: string | null;
206
+ failureMessage: string | null;
207
+ }>;
208
+ events: (o: string, id: string, cursor?: {
209
+ after?: string;
210
+ limit?: number;
211
+ }) => Promise<{
212
+ seq: string;
213
+ phase: string;
214
+ level: "error" | "info" | "warn";
215
+ message: string;
216
+ createdAt: string;
217
+ }[]>;
218
+ eventsPage: (o: string, id: string, options: {
219
+ after?: string;
220
+ limit: number;
221
+ signal?: AbortSignal;
222
+ }) => Promise<EventsPage<z.infer<typeof deploymentEventSchema>>>;
223
+ delete: (o: string, id: string) => Promise<{
224
+ operationId: string;
225
+ deploymentId: string;
226
+ status: "queued";
227
+ }>;
228
+ };
229
+ aliases: {
230
+ list: (o: string, appId: string) => Promise<{
231
+ id: string;
232
+ appId: string;
233
+ slug: string;
234
+ hostname: string;
235
+ state: "unbound" | "bound" | "binding" | "binding-uncertain" | "withdrawing" | "withdrawal-uncertain" | "withdrawn";
236
+ targetDeploymentId: string | null;
237
+ reservedGeneration: string;
238
+ committedGeneration: string;
239
+ createdAt: string;
240
+ }[]>;
241
+ listPage: (o: string, appId: string, page: PageOptions) => Promise<Page<{
242
+ id: string;
243
+ appId: string;
244
+ slug: string;
245
+ hostname: string;
246
+ state: "unbound" | "bound" | "binding" | "binding-uncertain" | "withdrawing" | "withdrawal-uncertain" | "withdrawn";
247
+ targetDeploymentId: string | null;
248
+ reservedGeneration: string;
249
+ committedGeneration: string;
250
+ createdAt: string;
251
+ }>>;
252
+ get: (o: string, id: string) => Promise<{
253
+ id: string;
254
+ appId: string;
255
+ slug: string;
256
+ hostname: string;
257
+ state: "unbound" | "bound" | "binding" | "binding-uncertain" | "withdrawing" | "withdrawal-uncertain" | "withdrawn";
258
+ targetDeploymentId: string | null;
259
+ reservedGeneration: string;
260
+ committedGeneration: string;
261
+ createdAt: string;
262
+ }>;
263
+ create: (o: string, appId: string, input: z.input<typeof createAliasSchema>) => Promise<{
264
+ id: string;
265
+ appId: string;
266
+ slug: string;
267
+ hostname: string;
268
+ state: "unbound" | "bound" | "binding" | "binding-uncertain" | "withdrawing" | "withdrawal-uncertain" | "withdrawn";
269
+ targetDeploymentId: string | null;
270
+ reservedGeneration: string;
271
+ committedGeneration: string;
272
+ createdAt: string;
273
+ }>;
274
+ promote: (o: string, id: string, input: z.input<typeof promoteAliasSchema>, options: RequestOptions & {
275
+ idempotencyKey: string;
276
+ }) => Promise<{
277
+ id: string;
278
+ aliasId: string;
279
+ action: "bind" | "withdraw";
280
+ status: "queued" | "applying" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "superseded";
281
+ generation: string;
282
+ expectedGeneration: string;
283
+ previousTargetDeploymentId: string | null;
284
+ desiredTargetDeploymentId: string | null;
285
+ supersedesOperationId: string | null;
286
+ supersededByOperationId: string | null;
287
+ failureCode: string | null;
288
+ createdAt: string;
289
+ finishedAt: string | null;
290
+ }>;
291
+ withdraw: (o: string, id: string, input: z.input<typeof withdrawAliasSchema>, options: RequestOptions & {
292
+ idempotencyKey: string;
293
+ }) => Promise<{
294
+ id: string;
295
+ aliasId: string;
296
+ action: "bind" | "withdraw";
297
+ status: "queued" | "applying" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "superseded";
298
+ generation: string;
299
+ expectedGeneration: string;
300
+ previousTargetDeploymentId: string | null;
301
+ desiredTargetDeploymentId: string | null;
302
+ supersedesOperationId: string | null;
303
+ supersededByOperationId: string | null;
304
+ failureCode: string | null;
305
+ createdAt: string;
306
+ finishedAt: string | null;
307
+ }>;
308
+ operations: (o: string, id: string) => Promise<{
309
+ id: string;
310
+ aliasId: string;
311
+ action: "bind" | "withdraw";
312
+ status: "queued" | "applying" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "superseded";
313
+ generation: string;
314
+ expectedGeneration: string;
315
+ previousTargetDeploymentId: string | null;
316
+ desiredTargetDeploymentId: string | null;
317
+ supersedesOperationId: string | null;
318
+ supersededByOperationId: string | null;
319
+ failureCode: string | null;
320
+ createdAt: string;
321
+ finishedAt: string | null;
322
+ }[]>;
323
+ operationsPage: (o: string, id: string, page: PageOptions) => Promise<Page<{
324
+ id: string;
325
+ aliasId: string;
326
+ action: "bind" | "withdraw";
327
+ status: "queued" | "applying" | "verifying" | "succeeded" | "failed" | "reconciliation-needed" | "superseded";
328
+ generation: string;
329
+ expectedGeneration: string;
330
+ previousTargetDeploymentId: string | null;
331
+ desiredTargetDeploymentId: string | null;
332
+ supersedesOperationId: string | null;
333
+ supersededByOperationId: string | null;
334
+ failureCode: string | null;
335
+ createdAt: string;
336
+ finishedAt: string | null;
337
+ }>>;
338
+ };
339
+ };
340
+ export type LaunchpadClient = ReturnType<typeof createClient>;
package/errors.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ export declare class LaunchpadApiError extends Error {
2
+ readonly status: number;
3
+ readonly code: string;
4
+ readonly title: string;
5
+ readonly retryAfterSeconds: number | null;
6
+ constructor(init: {
7
+ status: number;
8
+ code: string;
9
+ title: string;
10
+ retryAfterSeconds?: number;
11
+ });
12
+ }
13
+ export declare class LaunchpadTransportError extends Error {
14
+ readonly reason: "unreachable" | "timeout" | "redirect" | "invalid-response";
15
+ constructor(reason: LaunchpadTransportError["reason"], message: string);
16
+ }
17
+ export declare class LaunchpadConfigError extends Error {
18
+ constructor(message: string);
19
+ }
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './client.js';
2
+ export * from './errors.js';
3
+ export { API_KEY_SCOPES, generationSchema, MAX_KEY_LIFETIME_DAYS, ORGANIZATION_ROLES, parseDuration, slugSchema, } from '@launchpad-kit/contracts';
4
+ export type { ApiKeyScopeName, OrganizationRoleName } from '@launchpad-kit/contracts';
5
+ export * from './session.js';
package/index.mjs ADDED
@@ -0,0 +1,443 @@
1
+ import { API_KEY_SCOPES as e, MAX_KEY_LIFETIME_DAYS as t, ORGANIZATION_ROLES as n, addedMemberSchema as r, aliasSchema as i, apiKeySummarySchema as a, appSchema as o, appShutdownSchema as s, artifactSchema as c, createdApiKeySchema as l, createdInvitationSchema as u, createdOrganizationSchema as d, createdProjectSchema as f, deploymentDeletionSchema as p, deploymentEventSchema as m, deploymentSchema as h, generationSchema as g, invitationSchema as _, keyInfoSchema as v, memberSchema as y, okSchema as b, organizationSummarySchema as x, parseDuration as S, projectSchema as C, promotionOperationSchema as w, slugSchema as T } from "@launchpad-kit/contracts";
2
+ import { z as E } from "zod";
3
+ // src/errors.ts
4
+ var D = class extends Error {
5
+ status;
6
+ code;
7
+ title;
8
+ retryAfterSeconds;
9
+ constructor(e) {
10
+ super(e.title), this.name = "LaunchpadApiError", this.status = e.status, this.code = e.code, this.title = e.title, this.retryAfterSeconds = e.retryAfterSeconds ?? null;
11
+ }
12
+ }, O = class extends Error {
13
+ reason;
14
+ constructor(e, t) {
15
+ super(t), this.name = "LaunchpadTransportError", this.reason = e;
16
+ }
17
+ }, k = class extends Error {
18
+ constructor(e) {
19
+ super(e), this.name = "LaunchpadConfigError";
20
+ }
21
+ }, A = (e) => e.loose(), j = /* @__PURE__ */ new Set([
22
+ "localhost",
23
+ "127.0.0.1",
24
+ "[::1]"
25
+ ]), M = 1048576, N = /* @__PURE__ */ new Set([
26
+ "GET",
27
+ "HEAD",
28
+ "POST",
29
+ "PUT",
30
+ "PATCH",
31
+ "DELETE"
32
+ ]), P = /* @__PURE__ */ new Set([
33
+ "authorization",
34
+ "proxy-authorization",
35
+ "cookie",
36
+ "host",
37
+ "content-length",
38
+ "origin",
39
+ "transfer-encoding",
40
+ "connection",
41
+ "upgrade",
42
+ "idempotency-key",
43
+ "x-http-method-override",
44
+ "x-method-override",
45
+ "x-http-method",
46
+ "x-forwarded-host",
47
+ "x-forwarded-for",
48
+ "x-forwarded-proto",
49
+ "forwarded",
50
+ "proxy-connection",
51
+ "te",
52
+ "trailer",
53
+ "keep-alive",
54
+ "expect"
55
+ ]), F = /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,64}$/, I = /^[\x20-\x7e]{0,1024}$/, L = 1048576, R = /^[\x21-\x7e]{1,128}$/;
56
+ function z(e) {
57
+ let t = (e) => new k(`The API path is not allowed: ${e}.`), n = e.startsWith("/") ? e : `/${e}`;
58
+ if (n === "/") throw t("it is empty");
59
+ if (n.length > 2048) throw t("it is too long");
60
+ if (/[^\x21-\x7e]/.test(n)) throw t("it has spaces, control or non-ASCII characters");
61
+ if (/[?#\\]/.test(n)) throw t("it has a query, fragment or backslash");
62
+ if (n.includes("//")) throw t("it has an empty segment");
63
+ if (/^\/[A-Za-z][A-Za-z0-9+.-]*:/.test(n)) throw t("it looks like a URL");
64
+ if (/%(?:2f|5c|00)/i.test(n)) throw t("it has an encoded separator");
65
+ for (let e of n.slice(1).split("/")) {
66
+ let n;
67
+ try {
68
+ n = decodeURIComponent(e);
69
+ } catch {
70
+ throw t("it has invalid percent-encoding");
71
+ }
72
+ if (n === "." || n === "..") throw t("it has a dot segment");
73
+ }
74
+ return n;
75
+ }
76
+ function B(e) {
77
+ let t;
78
+ try {
79
+ t = new URL(e);
80
+ } catch {
81
+ throw new k("The controller URL is not a valid URL.");
82
+ }
83
+ if (t.username || t.password) throw new k("The controller URL must not contain credentials.");
84
+ if (t.search || t.hash) throw new k("The controller URL must not contain a query or fragment.");
85
+ if (t.protocol !== "https:" && !(t.protocol === "http:" && j.has(t.hostname))) throw new k("The controller URL must use https (http is allowed only for localhost).");
86
+ return `${t.origin}${t.pathname.replace(/\/+$/, "")}`;
87
+ }
88
+ async function V(e) {
89
+ let t = () => new O("invalid-response", "The controller's answer is larger than this SDK accepts."), n = Number(e.headers.get("content-length"));
90
+ if (Number.isFinite(n) && n > M) throw await e.body?.cancel().catch(() => {}), t();
91
+ if (!e.body) return "";
92
+ let r = e.body.getReader(), i = new TextDecoder(), a = 0, o = "";
93
+ for (;;) {
94
+ let { done: e, value: n } = await r.read();
95
+ if (e) break;
96
+ if (a += n.byteLength, a > M) throw await r.cancel().catch(() => {}), t();
97
+ o += i.decode(n, { stream: !0 });
98
+ }
99
+ return o + i.decode();
100
+ }
101
+ function H(e, t) {
102
+ let n = e;
103
+ for (let e of t) e.length >= 8 && (n = n.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi"), "[redacted]"));
104
+ return n;
105
+ }
106
+ function U(e) {
107
+ let { base: t, doFetch: n, timeoutMs: r } = e, i = (t) => H(t, e.secrets?.() ?? []);
108
+ async function a(a, o, s, c) {
109
+ if (c.idempotencyKey !== void 0 && !R.test(c.idempotencyKey)) throw new k("An idempotency key is 1 to 128 printable ASCII characters without spaces.");
110
+ let l = [AbortSignal.timeout(r)];
111
+ c.signal && l.push(c.signal);
112
+ let u, d;
113
+ try {
114
+ u = await n(`${t}${e.prefix}${o}`, {
115
+ method: a,
116
+ headers: {
117
+ accept: "application/json",
118
+ ...c.headers,
119
+ ...e.credentialHeaders(),
120
+ ...c.archive ? { "content-type": "application/gzip" } : c.rawBody ? { "content-type": c.rawBody.contentType } : s === void 0 ? {} : { "content-type": "application/json" },
121
+ ...c.idempotencyKey ? { "idempotency-key": c.idempotencyKey } : {}
122
+ },
123
+ body: c.archive ?? c.rawBody?.data ?? (s === void 0 ? void 0 : JSON.stringify(s)),
124
+ credentials: "omit",
125
+ redirect: "error",
126
+ cache: "no-store",
127
+ signal: AbortSignal.any(l)
128
+ }), c.onHeaders?.(u), d = await V(u);
129
+ } catch (e) {
130
+ if (e instanceof O) throw e;
131
+ let t = e?.name;
132
+ throw c.signal?.aborted ? e : t === "TimeoutError" || t === "AbortError" ? new O("timeout", "The controller did not answer in time.") : e instanceof TypeError && /redirect/i.test(e.message) ? new O("redirect", "The controller redirected the request; it was not followed.") : new O("unreachable", "Could not reach the controller.");
133
+ }
134
+ if (!u.ok) {
135
+ let t;
136
+ try {
137
+ t = d.length > 0 ? JSON.parse(d) : void 0;
138
+ } catch {
139
+ t = void 0;
140
+ }
141
+ let n = typeof t == "object" && t ? t : {}, r = [Number(u.headers.get("retry-after")), Number(u.headers.get("x-retry-after"))].find((e) => Number.isFinite(e) && e > 0), a = typeof n.code == "string" ? n.code : "unknown", o = typeof n.title == "string" ? n.title : e.session && typeof n.message == "string" ? n.message : `HTTP ${u.status}`, s = e.session?.hint(u.status, a);
142
+ throw new D({
143
+ status: u.status,
144
+ code: i(a),
145
+ title: i(s ? `${o} ${s}` : o),
146
+ retryAfterSeconds: r
147
+ });
148
+ }
149
+ return {
150
+ response: u,
151
+ text: d
152
+ };
153
+ }
154
+ return { exchange: a };
155
+ }
156
+ function W(e, t, n) {
157
+ let r = t.get("link");
158
+ if (!r) return null;
159
+ let i = new URL(`${e}/api/v1${n}`);
160
+ for (let e of r.matchAll(/<([^>]*)>\s*((?:;\s*[^;,]+)*)/g)) {
161
+ if (!/;\s*rel="?next"?\s*(;|$)/i.test(e[2])) continue;
162
+ let t;
163
+ try {
164
+ t = new URL(e[1], i);
165
+ } catch {
166
+ continue;
167
+ }
168
+ if (t.origin === i.origin && (t.pathname === `/api/v1${n}` || t.pathname === i.pathname)) return t.searchParams;
169
+ }
170
+ return null;
171
+ }
172
+ async function G(e, t, n, r, i = {}) {
173
+ let a = n.toUpperCase();
174
+ if (!N.has(a)) throw new k("The method must be GET, HEAD, POST, PUT, PATCH or DELETE.");
175
+ let o = z(r), s = {};
176
+ for (let [e, t] of Object.entries(i.headers ?? {})) {
177
+ let n = e.toLowerCase();
178
+ if (!F.test(e) || P.has(n)) throw new k(`The header "${n.slice(0, 64)}" is not allowed.`);
179
+ if (!I.test(t)) throw new k(`The value of header "${n}" is not allowed.`);
180
+ s[n] = t;
181
+ }
182
+ let c;
183
+ if (i.body !== void 0) {
184
+ if (a === "GET" || a === "HEAD") throw new k("GET and HEAD requests cannot have a body.");
185
+ if ((typeof i.body == "string" ? new TextEncoder().encode(i.body).byteLength : i.body.byteLength) > L) throw new k("The request body is larger than 1 MiB.");
186
+ let e = s["content-type"] ?? i.contentType ?? "application/json";
187
+ delete s["content-type"], c = {
188
+ data: i.body,
189
+ contentType: e
190
+ };
191
+ }
192
+ let l = `${o}${i.query && i.query.length > 0 ? `?${new URLSearchParams(i.query.map(([e, t]) => [e, t])).toString()}` : ""}`, u = new URL(`${t}/api/v1${l}`);
193
+ if (u.origin !== new URL(t).origin || !u.pathname.startsWith(`${new URL(t).pathname.replace(/\/$/, "")}/api/v1/`)) throw new k("The API path is not allowed: it leaves /api/v1.");
194
+ let { response: d, text: f } = await e.exchange(a, l, void 0, {
195
+ idempotencyKey: i.idempotencyKey,
196
+ signal: i.signal,
197
+ headers: s,
198
+ rawBody: c
199
+ }), p = a === "GET" ? W(t, d.headers, o) : null;
200
+ return {
201
+ status: d.status,
202
+ headers: d.headers,
203
+ body: f,
204
+ next: p ? [...p.entries()] : null
205
+ };
206
+ }
207
+ // src/client.ts
208
+ var K = /^lp_[A-Za-z0-9_-]{20,200}$/;
209
+ function q(e) {
210
+ let t = B(e.baseUrl), n = e.apiKey;
211
+ if (!K.test(n)) throw new k("The API key is not in the expected format (lp_…).");
212
+ let r = U({
213
+ base: t,
214
+ doFetch: e.fetch ?? globalThis.fetch.bind(globalThis),
215
+ timeoutMs: e.timeoutMs ?? 3e4,
216
+ prefix: "/api/v1",
217
+ credentialHeaders: () => ({ authorization: `Bearer ${n}` }),
218
+ secrets: () => [n, n.slice(3)]
219
+ }), { exchange: a } = r, l = (e, n) => W(t, e, n);
220
+ async function u(e, t, n, r, i = {}) {
221
+ let { response: o, text: s } = await a(e, t, r, i), c;
222
+ try {
223
+ c = s.length > 0 ? JSON.parse(s) : void 0;
224
+ } catch {
225
+ c = void 0;
226
+ }
227
+ let l = n.safeParse(c);
228
+ if (!l.success) throw new O("invalid-response", "The controller's answer is not what this version of the SDK expects.");
229
+ return {
230
+ data: l.data,
231
+ headers: o.headers
232
+ };
233
+ }
234
+ async function d(e, t, n, r, i = {}) {
235
+ return (await u(e, t, n, r, i)).data;
236
+ }
237
+ let g = /^[A-Za-z0-9_-]{1,1024}$/;
238
+ function _(e, t) {
239
+ if (!Number.isInteger(e) || e < 1 || e > t) throw new k(`limit must be an integer from 1 to ${t}.`);
240
+ }
241
+ async function b(e, t, n) {
242
+ _(n.limit, 100);
243
+ let { data: r, headers: i } = await u("GET", `${e}${T({
244
+ limit: n.limit,
245
+ cursor: n.cursor
246
+ })}`, t, void 0, { signal: n.signal }), a = l(i, e)?.get("cursor");
247
+ return a && g.test(a) ? {
248
+ items: r,
249
+ next: { cursor: a }
250
+ } : { items: r };
251
+ }
252
+ let S = (e) => {
253
+ if (!e || e === "." || e === "..") throw new k("A resource ID is required.");
254
+ return encodeURIComponent(e);
255
+ }, T = (e) => {
256
+ let t = Object.entries(e).filter(([, e]) => e !== void 0);
257
+ return t.length === 0 ? "" : `?${new URLSearchParams(t.map(([e, t]) => [e, String(t)])).toString()}`;
258
+ }, D = (e) => `/organizations/${S(e)}`, j = (e, t) => `${D(e)}/apps/${S(t)}`, M = (e, t) => `${D(e)}/aliases/${S(t)}`, N = (e, t) => `${D(e)}/deployments/${S(t)}`;
259
+ return {
260
+ raw: (e, n, i) => G(r, t, e, n, i),
261
+ key: { get: () => d("GET", "/key", A(v)) },
262
+ organizations: {
263
+ list: () => d("GET", "/organizations", E.array(A(x))),
264
+ listPage: (e) => b("/organizations", E.array(A(x)), e),
265
+ get: (e) => d("GET", `/organizations/${S(e)}`, A(x))
266
+ },
267
+ members: {
268
+ list: (e) => d("GET", `/organizations/${S(e)}/members`, E.array(A(y))),
269
+ listPage: (e, t) => b(`${D(e)}/members`, E.array(A(y)), t)
270
+ },
271
+ projects: {
272
+ list: (e) => d("GET", `/organizations/${S(e)}/projects`, E.array(A(C))),
273
+ listPage: (e, t) => b(`${D(e)}/projects`, E.array(A(C)), t),
274
+ create: (e, t) => d("POST", `/organizations/${S(e)}/projects`, A(f), t)
275
+ },
276
+ artifacts: { upload: (e, t, n, r) => d("POST", `${D(e)}/projects/${S(t)}/artifacts`, A(c), void 0, {
277
+ signal: r?.signal,
278
+ archive: n
279
+ }) },
280
+ apps: {
281
+ list: (e) => d("GET", `${D(e)}/apps`, E.array(A(o))),
282
+ listPage: (e, t) => b(`${D(e)}/apps`, E.array(A(o)), t),
283
+ get: (e, t) => d("GET", j(e, t), A(o)),
284
+ create: (e, t, n) => d("POST", `${D(e)}/projects/${S(t)}/apps`, A(o), n),
285
+ shutdown: (e, t) => d("DELETE", j(e, t), A(s))
286
+ },
287
+ deployments: {
288
+ list: (e, t) => d("GET", `${j(e, t)}/deployments`, E.array(A(h))),
289
+ listPage: (e, t, n) => b(`${j(e, t)}/deployments`, E.array(A(h)), n),
290
+ create: (e, t, n, r) => d("POST", `${j(e, t)}/deployments`, A(h), n, { signal: r?.signal }),
291
+ get: (e, t) => d("GET", N(e, t), A(h)),
292
+ events: (e, t, n) => d("GET", `${N(e, t)}/events${T(n ?? {})}`, E.array(A(m))),
293
+ eventsPage: async (e, t, n) => {
294
+ _(n.limit, 500);
295
+ let r = `${N(e, t)}/events`, { data: i, headers: a } = await u("GET", `${r}${T({
296
+ after: n.after,
297
+ limit: n.limit
298
+ })}`, E.array(A(m)), void 0, { signal: n.signal }), o = l(a, r)?.get("after");
299
+ return o && /^\d{1,10}$/.test(o) ? {
300
+ items: i,
301
+ nextAfter: o
302
+ } : { items: i };
303
+ },
304
+ delete: (e, t) => d("DELETE", N(e, t), A(p))
305
+ },
306
+ aliases: {
307
+ list: (e, t) => d("GET", `${j(e, t)}/aliases`, E.array(A(i))),
308
+ listPage: (e, t, n) => b(`${j(e, t)}/aliases`, E.array(A(i)), n),
309
+ get: (e, t) => d("GET", M(e, t), A(i)),
310
+ create: (e, t, n) => d("POST", `${j(e, t)}/aliases`, A(i), n),
311
+ promote: (e, t, n, r) => d("POST", `${M(e, t)}/promotions`, A(w), n, r),
312
+ withdraw: (e, t, n, r) => d("DELETE", M(e, t), A(w), n, r),
313
+ operations: (e, t) => d("GET", `${M(e, t)}/operations`, E.array(A(w))),
314
+ operationsPage: (e, t, n) => b(`${M(e, t)}/operations`, E.array(A(w)), n)
315
+ }
316
+ };
317
+ }
318
+ // src/session.ts
319
+ var J = "better-auth.session_token", Y = /^[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]{1,4096}$/, X = /* @__PURE__ */ new Set(["set-cookie", "set-cookie2"]), Z = "The controller accepts only the exact origin set as its LAUNCHPAD_BASE_URL; an http/https or proxy-host mismatch looks like this.", Q = (e) => new URL(e).protocol === "https:" ? `__Secure-${J}` : J;
320
+ function $(e, t) {
321
+ let n = t.indexOf("=");
322
+ if ((n === -1 ? "" : t.slice(0, n)) !== Q(e) || !Y.test(t.slice(n + 1))) throw new k("The session cookie is not in the expected format.");
323
+ return t;
324
+ }
325
+ function ee(e) {
326
+ let t = B(e.baseUrl), n = new URL(t).origin, i = e.fetch ?? globalThis.fetch.bind(globalThis), o = e.timeoutMs ?? 3e4, s = e.cookie === void 0 ? null : $(t, e.cookie), c = null, f = !1, p = () => {
327
+ let e = [];
328
+ return s && e.push(s, s.slice(s.indexOf("=") + 1)), c && e.push(c), e;
329
+ }, m = (e, r) => ({
330
+ base: t,
331
+ doFetch: i,
332
+ timeoutMs: o,
333
+ prefix: e,
334
+ credentialHeaders: () => ({
335
+ origin: n,
336
+ ...r && s ? { cookie: s } : {}
337
+ }),
338
+ secrets: p,
339
+ session: { hint: (e, t) => e === 403 && (t === "forbidden-origin" || t === "INVALID_ORIGIN") ? Z : void 0 }
340
+ }), h = U(m("/api/auth", !1)), g = U(m("/api/auth", !0)), v = U(m("/api/v1", !0));
341
+ async function x(e, t, n, r, i = {}) {
342
+ if (!s) throw new k("This client has no session.");
343
+ let { text: a } = await v.exchange(e, t, r, { signal: i.signal }), o = H(a, p());
344
+ await i.onText?.(a);
345
+ let c;
346
+ try {
347
+ c = o.length > 0 ? JSON.parse(o) : void 0;
348
+ } catch {
349
+ c = void 0;
350
+ }
351
+ let l = n.safeParse(c);
352
+ if (!l.success) throw new O("invalid-response", "The controller's answer is not what this version of the SDK expects.");
353
+ return l.data;
354
+ }
355
+ let S = (e) => {
356
+ if (typeof e != "string" || e.length === 0 || e.length > 256 || e === "." || e === ".." || /[\u0000-\u001f\u007f]/.test(e)) throw new k("A resource ID is required.");
357
+ return encodeURIComponent(e);
358
+ }, C = (e) => `/organizations/${S(e)}`;
359
+ return {
360
+ origin: n,
361
+ cookie: () => s,
362
+ async signIn(e, n, r = {}) {
363
+ if (s) throw new k("This client already has a session.");
364
+ if (f) throw new k("A sign-in is already in progress.");
365
+ if (!e || !n) throw new k("An email and a password are required.");
366
+ f = !0, c = n;
367
+ let i = Q(t), a = (e) => {
368
+ if (e.status === 200) for (let t of e.headers.getSetCookie()) {
369
+ let e = t.split(";")[0].trim(), n = e.indexOf("=");
370
+ if (n !== -1 && e.slice(0, n) === i && Y.test(e.slice(n + 1))) {
371
+ s = e;
372
+ return;
373
+ }
374
+ }
375
+ };
376
+ try {
377
+ let { response: t } = await h.exchange("POST", "/sign-in/email", {
378
+ email: e,
379
+ password: n
380
+ }, {
381
+ signal: r.signal,
382
+ onHeaders: a
383
+ });
384
+ if (s) return { cookie: s };
385
+ throw new D({
386
+ status: t.status,
387
+ code: "no-session",
388
+ title: "The controller accepted the sign-in but sent no session cookie."
389
+ });
390
+ } catch (e) {
391
+ throw e instanceof D && e.status === 401 ? new D({
392
+ status: 401,
393
+ code: "invalid-credentials",
394
+ title: "Wrong email or password."
395
+ }) : e;
396
+ } finally {
397
+ c = null, f = !1;
398
+ }
399
+ },
400
+ async signOut(e = {}) {
401
+ if (!s) throw new k("This client has no session.");
402
+ await g.exchange("POST", "/sign-out", {}, { signal: e.signal });
403
+ },
404
+ async raw(e, n, r = {}) {
405
+ if (!s) throw new k("This client has no session.");
406
+ let i = await G(v, t, e, n, r), a = new Headers();
407
+ for (let [e, t] of i.headers) X.has(e.toLowerCase()) || a.append(e, H(t, p()));
408
+ return {
409
+ ...i,
410
+ headers: a,
411
+ body: H(i.body, p())
412
+ };
413
+ },
414
+ organizations: { create: async (e, t) => x("POST", "/organizations", A(d), e, t) },
415
+ members: {
416
+ list: async (e, t) => x("GET", `${C(e)}/members`, E.array(A(y)), void 0, t),
417
+ add: async (e, t, n) => x("POST", `${C(e)}/members`, A(r), t, n),
418
+ remove: async (e, t, n) => x("DELETE", `${C(e)}/members/${S(t)}`, A(b), void 0, n)
419
+ },
420
+ invitations: {
421
+ create: async (e, t, n) => x("POST", `${C(e)}/invitations`, A(u), t, n),
422
+ list: async (e, t) => x("GET", `${C(e)}/invitations`, E.array(A(_)), void 0, t),
423
+ revoke: async (e, t, n) => x("DELETE", `${C(e)}/invitations/${S(t)}`, A(b), void 0, n)
424
+ },
425
+ apiKeys: {
426
+ list: async (e, t) => x("GET", `${C(e)}/api-keys`, E.array(A(a)), void 0, t),
427
+ issue: async (e, t, n = {}) => x("POST", `${C(e)}/api-keys`, A(l), t, {
428
+ signal: n.signal,
429
+ onText: async (e) => {
430
+ let t;
431
+ try {
432
+ t = JSON.parse(e)?.secret;
433
+ } catch {
434
+ return;
435
+ }
436
+ typeof t == "string" && t.length > 0 && await n.onSecret?.(t);
437
+ }
438
+ }),
439
+ revoke: async (e, t, n) => x("DELETE", `${C(e)}/api-keys/${S(t)}`, A(b), void 0, n)
440
+ }
441
+ };
442
+ }
443
+ export { e as API_KEY_SCOPES, P as FORBIDDEN_RAW_HEADERS, D as LaunchpadApiError, k as LaunchpadConfigError, O as LaunchpadTransportError, t as MAX_KEY_LIFETIME_DAYS, n as ORGANIZATION_ROLES, N as RAW_METHODS, q as createClient, ee as createSessionClient, g as generationSchema, B as normalizeBaseUrl, S as parseDuration, T as slugSchema };
package/loose.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export declare const loose: <S extends z.ZodObject>(schema: S) => z.ZodType<z.infer<S>>;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@launchpad-kit/sdk",
3
+ "version": "0.0.0-bootstrap.0",
4
+ "description": "Browser-safe HTTP SDK for the Launchpad controller API",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/launchpad-kit/launchpad.git",
9
+ "directory": "packages/sdk"
10
+ },
11
+ "homepage": "https://github.com/launchpad-kit/launchpad#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/launchpad-kit/launchpad/issues"
14
+ },
15
+ "type": "module",
16
+ "engines": {
17
+ "node": ">=22.12"
18
+ },
19
+ "main": "./index.mjs",
20
+ "types": "./index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./index.d.ts",
24
+ "import": "./index.mjs",
25
+ "default": "./index.mjs"
26
+ }
27
+ },
28
+ "sideEffects": false,
29
+ "files": [
30
+ "*.mjs",
31
+ "*.d.ts",
32
+ "**/*.d.ts",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "dependencies": {
37
+ "@launchpad-kit/contracts": "^0.0.0-bootstrap.0",
38
+ "zod": "4.6.7"
39
+ }
40
+ }
package/session.d.ts ADDED
@@ -0,0 +1,112 @@
1
+ import { ApiKeyScopeName, OrganizationRoleName } from '@launchpad-kit/contracts';
2
+ import { RawOptions, RawResponse } from './transport.js';
3
+ export interface CreateOrganizationInput {
4
+ name: string;
5
+ slug: string;
6
+ ownerEmail: string;
7
+ }
8
+ export interface AddMemberInput {
9
+ email: string;
10
+ role: OrganizationRoleName;
11
+ }
12
+ export interface CreateInvitationInput {
13
+ email: string;
14
+ role: OrganizationRoleName;
15
+ }
16
+ export interface IssueApiKeyInput {
17
+ name: string;
18
+ scopes: ApiKeyScopeName[];
19
+ projectIds?: string[];
20
+ expiresInDays: number;
21
+ }
22
+ export interface SessionCallOptions {
23
+ signal?: AbortSignal;
24
+ }
25
+ export interface IssueApiKeyOptions extends SessionCallOptions {
26
+ onSecret?: (secret: string) => void | Promise<void>;
27
+ }
28
+ export interface SessionClientOptions {
29
+ baseUrl: string;
30
+ cookie?: string;
31
+ fetch?: typeof fetch;
32
+ timeoutMs?: number;
33
+ }
34
+ export declare function createSessionClient(options: SessionClientOptions): {
35
+ origin: string;
36
+ cookie: () => string | null;
37
+ signIn(email: string, secret: string, extra?: {
38
+ signal?: AbortSignal;
39
+ }): Promise<{
40
+ cookie: string;
41
+ }>;
42
+ signOut(extra?: {
43
+ signal?: AbortSignal;
44
+ }): Promise<void>;
45
+ raw(method: string, path: string, rawOptions?: RawOptions): Promise<RawResponse>;
46
+ organizations: {
47
+ create: (input: CreateOrganizationInput, extra?: SessionCallOptions) => Promise<{
48
+ id: string;
49
+ name: string;
50
+ slug: string;
51
+ }>;
52
+ };
53
+ members: {
54
+ list: (organizationId: string, extra?: SessionCallOptions) => Promise<{
55
+ userId: string;
56
+ email: string;
57
+ name: string;
58
+ role: "owner" | "admin" | "deployer" | "viewer";
59
+ }[]>;
60
+ add: (organizationId: string, input: AddMemberInput, extra?: SessionCallOptions) => Promise<{
61
+ userId: string;
62
+ role: "owner" | "admin" | "deployer" | "viewer";
63
+ }>;
64
+ remove: (organizationId: string, userId: string, extra?: SessionCallOptions) => Promise<{
65
+ ok: true;
66
+ }>;
67
+ };
68
+ invitations: {
69
+ create: (organizationId: string, input: CreateInvitationInput, extra?: SessionCallOptions) => Promise<{
70
+ id: string;
71
+ email: string;
72
+ role: "owner" | "admin" | "deployer" | "viewer";
73
+ }>;
74
+ list: (organizationId: string, extra?: SessionCallOptions) => Promise<{
75
+ id: string;
76
+ email: string;
77
+ role: "owner" | "admin" | "deployer" | "viewer";
78
+ createdAt: string;
79
+ expiresAt: string;
80
+ }[]>;
81
+ revoke: (organizationId: string, invitationId: string, extra?: SessionCallOptions) => Promise<{
82
+ ok: true;
83
+ }>;
84
+ };
85
+ apiKeys: {
86
+ list: (organizationId: string, extra?: SessionCallOptions) => Promise<{
87
+ id: string;
88
+ name: string;
89
+ prefix: string;
90
+ scopes: string[];
91
+ projectIds: string[] | null;
92
+ createdBy: string;
93
+ createdAt: string;
94
+ expiresAt: string;
95
+ revokedAt: string | null;
96
+ lastUsedAt: string | null;
97
+ status: "expired" | "active" | "revoked" | "inactive";
98
+ }[]>;
99
+ issue: (organizationId: string, input: IssueApiKeyInput, extra?: IssueApiKeyOptions) => Promise<{
100
+ id: string;
101
+ name: string;
102
+ secret: string;
103
+ scopes: ("organization:read" | "member:read" | "project:read" | "project:create" | "project:delete" | "app:read" | "app:deploy" | "app:delete" | "app:promote" | "app:alias:manage")[];
104
+ projectIds: string[] | null;
105
+ expiresAt: string;
106
+ }>;
107
+ revoke: (organizationId: string, keyId: string, extra?: SessionCallOptions) => Promise<{
108
+ ok: true;
109
+ }>;
110
+ };
111
+ };
112
+ export type LaunchpadSessionClient = ReturnType<typeof createSessionClient>;
package/transport.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ export interface RawOptions {
2
+ query?: ReadonlyArray<readonly [string, string]>;
3
+ body?: string | Uint8Array;
4
+ contentType?: string;
5
+ headers?: Record<string, string>;
6
+ idempotencyKey?: string;
7
+ signal?: AbortSignal;
8
+ }
9
+ export interface RawResponse {
10
+ status: number;
11
+ headers: Headers;
12
+ body: string;
13
+ next: Array<[string, string]> | null;
14
+ }
15
+ export declare const RAW_METHODS: ReadonlySet<string>;
16
+ export declare const FORBIDDEN_RAW_HEADERS: ReadonlySet<string>;
17
+ export declare function normalizeBaseUrl(input: string): string;
18
+ export interface Extra {
19
+ idempotencyKey?: string;
20
+ signal?: AbortSignal;
21
+ archive?: Blob;
22
+ rawBody?: {
23
+ data: string | Uint8Array;
24
+ contentType: string;
25
+ };
26
+ headers?: Record<string, string>;
27
+ onHeaders?: (response: Response) => void;
28
+ }
29
+ export interface TransportConfig {
30
+ base: string;
31
+ doFetch: typeof fetch;
32
+ timeoutMs: number;
33
+ prefix: string;
34
+ credentialHeaders: () => Record<string, string>;
35
+ secrets?: () => readonly string[];
36
+ session?: {
37
+ hint(status: number, code: string): string | undefined;
38
+ };
39
+ }
40
+ export declare function scrub(text: string, secrets: readonly string[]): string;
41
+ export declare function createTransport(config: TransportConfig): {
42
+ exchange: (method: string, path: string, body: unknown, extra: Extra) => Promise<{
43
+ response: Response;
44
+ text: string;
45
+ }>;
46
+ };
47
+ export declare function nextLink(base: string, headers: Headers, path: string): URLSearchParams | null;
48
+ export declare function rawRequest(transport: ReturnType<typeof createTransport>, base: string, method: string, rawPath: string, options?: RawOptions): Promise<RawResponse>;