@limrun/api 0.77.0 → 0.77.2
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/CHANGELOG.md +37 -0
- package/README.md +81 -1
- package/client.d.mts +21 -0
- package/client.d.mts.map +1 -1
- package/client.d.ts +21 -0
- package/client.d.ts.map +1 -1
- package/client.js +45 -6
- package/client.js.map +1 -1
- package/client.mjs +46 -7
- package/client.mjs.map +1 -1
- package/gradle-snapshot.d.mts +2 -2
- package/gradle-snapshot.d.mts.map +1 -1
- package/gradle-snapshot.d.ts +2 -2
- package/gradle-snapshot.d.ts.map +1 -1
- package/gradle-snapshot.js +1 -1
- package/gradle-snapshot.js.map +1 -1
- package/gradle-snapshot.mjs +1 -1
- package/gradle-snapshot.mjs.map +1 -1
- package/internal/instance-phase-stream.d.mts +10 -1
- package/internal/instance-phase-stream.d.mts.map +1 -1
- package/internal/instance-phase-stream.d.ts +10 -1
- package/internal/instance-phase-stream.d.ts.map +1 -1
- package/internal/instance-phase-stream.js +17 -6
- package/internal/instance-phase-stream.js.map +1 -1
- package/internal/instance-phase-stream.mjs +17 -6
- package/internal/instance-phase-stream.mjs.map +1 -1
- package/lib/workload-credentials.d.mts +14 -3
- package/lib/workload-credentials.d.mts.map +1 -1
- package/lib/workload-credentials.d.ts +14 -3
- package/lib/workload-credentials.d.ts.map +1 -1
- package/lib/workload-credentials.js +50 -14
- package/lib/workload-credentials.js.map +1 -1
- package/lib/workload-credentials.mjs +46 -13
- package/lib/workload-credentials.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/access-tokens.d.mts +7 -4
- package/resources/access-tokens.d.mts.map +1 -1
- package/resources/access-tokens.d.ts +7 -4
- package/resources/access-tokens.d.ts.map +1 -1
- package/resources/analytics.d.mts +22 -2
- package/resources/analytics.d.mts.map +1 -1
- package/resources/analytics.d.ts +22 -2
- package/resources/analytics.d.ts.map +1 -1
- package/resources/analytics.js.map +1 -1
- package/resources/analytics.mjs.map +1 -1
- package/resources/gradle-instances.d.mts.map +1 -1
- package/resources/gradle-instances.d.ts.map +1 -1
- package/resources/gradle-instances.js +12 -4
- package/resources/gradle-instances.js.map +1 -1
- package/resources/gradle-instances.mjs +12 -4
- package/resources/gradle-instances.mjs.map +1 -1
- package/resources/index.d.mts +1 -0
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -0
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +3 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -0
- package/resources/index.mjs.map +1 -1
- package/resources/macos-instances.d.mts +224 -0
- package/resources/macos-instances.d.mts.map +1 -0
- package/resources/macos-instances.d.ts +224 -0
- package/resources/macos-instances.d.ts.map +1 -0
- package/resources/macos-instances.js +51 -0
- package/resources/macos-instances.js.map +1 -0
- package/resources/macos-instances.mjs +47 -0
- package/resources/macos-instances.mjs.map +1 -0
- package/resources/support-tickets.d.mts +3 -0
- package/resources/support-tickets.d.mts.map +1 -1
- package/resources/support-tickets.d.ts +3 -0
- package/resources/support-tickets.d.ts.map +1 -1
- package/resources/support-tickets.js +8 -0
- package/resources/support-tickets.js.map +1 -1
- package/resources/support-tickets.mjs +8 -0
- package/resources/support-tickets.mjs.map +1 -1
- package/resources/xcode-instances-helpers.d.mts +1 -0
- package/resources/xcode-instances-helpers.d.mts.map +1 -1
- package/resources/xcode-instances-helpers.d.ts +1 -0
- package/resources/xcode-instances-helpers.d.ts.map +1 -1
- package/resources/xcode-instances-helpers.js +15 -9
- package/resources/xcode-instances-helpers.js.map +1 -1
- package/resources/xcode-instances-helpers.mjs +15 -9
- package/resources/xcode-instances-helpers.mjs.map +1 -1
- package/src/client.ts +99 -9
- package/src/gradle-snapshot.ts +3 -4
- package/src/internal/instance-phase-stream.ts +30 -8
- package/src/lib/workload-credentials.ts +70 -13
- package/src/resources/access-tokens.ts +7 -4
- package/src/resources/analytics.ts +22 -2
- package/src/resources/gradle-instances.ts +15 -3
- package/src/resources/index.ts +8 -0
- package/src/resources/macos-instances.ts +296 -0
- package/src/resources/support-tickets.ts +15 -0
- package/src/resources/xcode-instances-helpers.ts +16 -8
- package/src/version.ts +1 -1
- package/src/xcode-cache.ts +3 -4
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/xcode-cache.d.mts +2 -2
- package/xcode-cache.d.mts.map +1 -1
- package/xcode-cache.d.ts +2 -2
- package/xcode-cache.d.ts.map +1 -1
- package/xcode-cache.js +1 -1
- package/xcode-cache.js.map +1 -1
- package/xcode-cache.mjs +1 -1
- package/xcode-cache.mjs.map +1 -1
package/src/client.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
WorkloadCredentials,
|
|
3
|
+
injectedWorkloadIdentityReader,
|
|
4
|
+
workloadTokenFileReader,
|
|
5
|
+
workloadTokenReader,
|
|
6
|
+
type WorkloadIdentityReader,
|
|
7
|
+
type WorkloadToken,
|
|
8
|
+
} from './lib/workload-credentials';
|
|
2
9
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
10
|
|
|
4
11
|
import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';
|
|
@@ -52,6 +59,14 @@ import {
|
|
|
52
59
|
GradleInstances,
|
|
53
60
|
GradleInstancesItems,
|
|
54
61
|
} from './resources/gradle-instances';
|
|
62
|
+
import {
|
|
63
|
+
MacosInstance,
|
|
64
|
+
MacosInstanceUpdateParams,
|
|
65
|
+
MacosInstanceCreateParams,
|
|
66
|
+
MacosInstanceListParams,
|
|
67
|
+
MacosInstances,
|
|
68
|
+
MacosInstancesItems,
|
|
69
|
+
} from './resources/macos-instances';
|
|
55
70
|
import {
|
|
56
71
|
IosInstance,
|
|
57
72
|
IosInstanceUpdateParams,
|
|
@@ -109,9 +124,62 @@ import {
|
|
|
109
124
|
} from './internal/utils/log';
|
|
110
125
|
import { isEmptyObj } from './internal/utils/values';
|
|
111
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Picks the workload identity source: explicit options before environment variables, and a token
|
|
129
|
+
* before a file. Null on either option turns off discovery of its environment variable.
|
|
130
|
+
*/
|
|
131
|
+
function workloadIdentity(opts: {
|
|
132
|
+
workloadToken?: WorkloadToken | null | undefined;
|
|
133
|
+
workloadTokenFile?: string | null | undefined;
|
|
134
|
+
workloadTokenInjected?: boolean | null | undefined;
|
|
135
|
+
}): WorkloadIdentityReader | undefined {
|
|
136
|
+
const reader = workloadTokenSource(opts);
|
|
137
|
+
const injected =
|
|
138
|
+
opts.workloadTokenInjected === null ?
|
|
139
|
+
false
|
|
140
|
+
: opts.workloadTokenInjected ??
|
|
141
|
+
/^(1|true)$/i.test(readEnv('LIMRUN_WORKLOAD_IDENTITY_TOKEN_INJECTED') ?? '');
|
|
142
|
+
if (!injected) return reader;
|
|
143
|
+
// The proxy decides which JWT the exchange carries, so a second source would be ignored.
|
|
144
|
+
if (reader)
|
|
145
|
+
throw new Error(
|
|
146
|
+
'workloadTokenInjected cannot be combined with workloadToken, workloadTokenFile, or their environment variables',
|
|
147
|
+
);
|
|
148
|
+
return injectedWorkloadIdentityReader;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function workloadTokenSource(opts: {
|
|
152
|
+
workloadToken?: WorkloadToken | null | undefined;
|
|
153
|
+
workloadTokenFile?: string | null | undefined;
|
|
154
|
+
}): WorkloadIdentityReader | undefined {
|
|
155
|
+
if (opts.workloadToken) return workloadTokenReader(opts.workloadToken);
|
|
156
|
+
if (opts.workloadTokenFile) return workloadTokenFileReader(opts.workloadTokenFile);
|
|
157
|
+
const token = opts.workloadToken === null ? undefined : readEnv('LIMRUN_WORKLOAD_IDENTITY_TOKEN');
|
|
158
|
+
if (token) return workloadTokenReader(token);
|
|
159
|
+
const file = opts.workloadTokenFile === null ? undefined : readEnv('LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE');
|
|
160
|
+
return file ? workloadTokenFileReader(file) : undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
112
163
|
export interface ClientOptions {
|
|
164
|
+
/**
|
|
165
|
+
* Workload JWT from your identity provider, or a function that returns the current one. A string is
|
|
166
|
+
* exchanged as is on every renewal, so pass a function when the JWT expires before the client is done.
|
|
167
|
+
* Takes precedence over workloadTokenFile. Defaults to LIMRUN_WORKLOAD_IDENTITY_TOKEN. Null disables discovery.
|
|
168
|
+
*/
|
|
169
|
+
workloadToken?: WorkloadToken | null;
|
|
113
170
|
/** Projected workload JWT file. Defaults to LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE. Null disables discovery. */
|
|
114
171
|
workloadTokenFile?: string | null;
|
|
172
|
+
/**
|
|
173
|
+
* Exchange without sending a JWT, for platforms whose egress proxy adds it to requests for the token
|
|
174
|
+
* service in the X-Limrun-Subject-Token header, so the workload never handles it. Requires bindingId
|
|
175
|
+
* and cannot be combined with workloadToken or workloadTokenFile.
|
|
176
|
+
* Defaults to LIMRUN_WORKLOAD_IDENTITY_TOKEN_INJECTED=true. Null disables discovery.
|
|
177
|
+
*/
|
|
178
|
+
workloadTokenInjected?: boolean | null;
|
|
179
|
+
/** Customer federation binding ID. Defaults to LIMRUN_WORKLOAD_IDENTITY_BINDING_ID. */
|
|
180
|
+
bindingId?: string | null;
|
|
181
|
+
/** Token service base URL. Federation defaults to https://sts.limrun.com. */
|
|
182
|
+
stsBaseURL?: string;
|
|
115
183
|
/**
|
|
116
184
|
* Defaults to process.env['LIM_API_KEY'].
|
|
117
185
|
*/
|
|
@@ -229,15 +297,23 @@ export class Limrun {
|
|
|
229
297
|
apiKey = readEnv('LIM_API_KEY') ?? null,
|
|
230
298
|
...opts
|
|
231
299
|
}: ClientOptions = {}) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
: opts.
|
|
300
|
+
// An API key wins, so workload identity settings it overrides cannot fail construction.
|
|
301
|
+
const identity = apiKey ? undefined : workloadIdentity(opts);
|
|
302
|
+
const bindingId =
|
|
303
|
+
opts.bindingId === null ? undefined : opts.bindingId ?? readEnv('LIMRUN_WORKLOAD_IDENTITY_BINDING_ID');
|
|
304
|
+
if (!apiKey && identity === injectedWorkloadIdentityReader && !bindingId)
|
|
305
|
+
throw new Error('workloadTokenInjected requires bindingId or LIMRUN_WORKLOAD_IDENTITY_BINDING_ID');
|
|
306
|
+
if (!apiKey && bindingId && !identity)
|
|
307
|
+
throw new Error(
|
|
308
|
+
'Federation requires workloadToken, workloadTokenFile, LIMRUN_WORKLOAD_IDENTITY_TOKEN, or LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE',
|
|
309
|
+
);
|
|
236
310
|
const options: ClientOptions = {
|
|
237
311
|
apiKey,
|
|
238
312
|
...opts,
|
|
239
313
|
baseURL:
|
|
240
|
-
baseURL ||
|
|
314
|
+
baseURL ||
|
|
315
|
+
(!apiKey && identity && !bindingId ? readEnv('DIRECTOR_URL') : undefined) ||
|
|
316
|
+
`https://api.limrun.com`,
|
|
241
317
|
};
|
|
242
318
|
|
|
243
319
|
this.baseURL = options.baseURL!;
|
|
@@ -270,12 +346,15 @@ export class Limrun {
|
|
|
270
346
|
this._options = options;
|
|
271
347
|
|
|
272
348
|
this.apiKey = apiKey;
|
|
273
|
-
if (!apiKey &&
|
|
349
|
+
if (!apiKey && identity)
|
|
274
350
|
this.workloadCredentials = new WorkloadCredentials(
|
|
275
|
-
|
|
276
|
-
|
|
351
|
+
opts.stsBaseURL ??
|
|
352
|
+
readEnv('LIMRUN_STS_BASE_URL') ??
|
|
353
|
+
(bindingId ? 'https://sts.limrun.com' : this.baseURL),
|
|
354
|
+
identity,
|
|
277
355
|
this.fetch,
|
|
278
356
|
this.fetchOptions,
|
|
357
|
+
bindingId,
|
|
279
358
|
);
|
|
280
359
|
}
|
|
281
360
|
|
|
@@ -884,6 +963,7 @@ export class Limrun {
|
|
|
884
963
|
gradleSnapshots: API.GradleSnapshots = new API.GradleSnapshots(this);
|
|
885
964
|
gradleInstances: API.GradleInstances = new API.GradleInstances(this);
|
|
886
965
|
supportTickets: API.SupportTickets = new API.SupportTickets(this);
|
|
966
|
+
macosInstances: API.MacosInstances = new API.MacosInstances(this);
|
|
887
967
|
analytics: API.Analytics = new API.Analytics(this);
|
|
888
968
|
accessTokens: API.AccessTokens = new API.AccessTokens(this);
|
|
889
969
|
/** @deprecated Use accessTokens. */
|
|
@@ -895,6 +975,7 @@ Limrun.Assets = Assets;
|
|
|
895
975
|
Limrun.IosInstances = IosInstances;
|
|
896
976
|
Limrun.XcodeInstances = XcodeInstances;
|
|
897
977
|
Limrun.GradleInstances = GradleInstances;
|
|
978
|
+
Limrun.MacosInstances = MacosInstances;
|
|
898
979
|
Limrun.Analytics = Analytics;
|
|
899
980
|
Limrun.AccessTokens = AccessTokens;
|
|
900
981
|
Limrun.ScopedTokens = ScopedTokens;
|
|
@@ -971,6 +1052,15 @@ export declare namespace Limrun {
|
|
|
971
1052
|
type GradleInstanceListParams as GradleInstanceListParams,
|
|
972
1053
|
};
|
|
973
1054
|
|
|
1055
|
+
export {
|
|
1056
|
+
MacosInstances as MacosInstances,
|
|
1057
|
+
type MacosInstance as MacosInstance,
|
|
1058
|
+
type MacosInstancesItems as MacosInstancesItems,
|
|
1059
|
+
type MacosInstanceUpdateParams as MacosInstanceUpdateParams,
|
|
1060
|
+
type MacosInstanceCreateParams as MacosInstanceCreateParams,
|
|
1061
|
+
type MacosInstanceListParams as MacosInstanceListParams,
|
|
1062
|
+
};
|
|
1063
|
+
|
|
974
1064
|
export {
|
|
975
1065
|
Analytics as Analytics,
|
|
976
1066
|
type AnalyticsInstancesResponse as AnalyticsInstancesResponse,
|
package/src/gradle-snapshot.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { followPhaseStream } from './internal/instance-phase-stream';
|
|
1
|
+
import { followPhaseStream, type PhaseStreamAuth } from './internal/instance-phase-stream';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A disk snapshot of a Gradle build sandbox, restored after the instance is assigned and saved at
|
|
@@ -82,9 +82,8 @@ export type GradleSnapshotSide = 'restore' | 'save';
|
|
|
82
82
|
|
|
83
83
|
export type GradleSnapshotFollowTarget = {
|
|
84
84
|
baseURL: string;
|
|
85
|
-
apiKey: string;
|
|
86
85
|
instanceId: string;
|
|
87
|
-
};
|
|
86
|
+
} & PhaseStreamAuth;
|
|
88
87
|
|
|
89
88
|
export type GradleSnapshotFollowOptions = {
|
|
90
89
|
/** Defaults to 'restore'. */
|
|
@@ -174,7 +173,7 @@ export async function followGradleSnapshot(
|
|
|
174
173
|
while (base.endsWith('/')) base = base.slice(0, -1);
|
|
175
174
|
const result = await followPhaseStream<GradleInstanceSnapshot>({
|
|
176
175
|
url: `${base}/v1/gradle_instances/${encodeURIComponent(target.instanceId)}/snapshot`,
|
|
177
|
-
|
|
176
|
+
auth: target,
|
|
178
177
|
instanceId: target.instanceId,
|
|
179
178
|
eventName: 'snapshot',
|
|
180
179
|
timeoutMs,
|
|
@@ -2,6 +2,15 @@ import { createEventSource, type EventSourceMessage } from 'eventsource-client';
|
|
|
2
2
|
|
|
3
3
|
import { nodeProxyTransport } from './proxy-transport';
|
|
4
4
|
|
|
5
|
+
/** Credentials for a phase stream: a fixed API key, or headers resolved on every connection. */
|
|
6
|
+
export type PhaseStreamAuth =
|
|
7
|
+
| { apiKey: string; getHeaders?: never }
|
|
8
|
+
| {
|
|
9
|
+
apiKey?: never;
|
|
10
|
+
/** Resolves current credentials on every connection, including reconnects. */
|
|
11
|
+
getHeaders: () => Promise<Headers>;
|
|
12
|
+
};
|
|
13
|
+
|
|
5
14
|
/**
|
|
6
15
|
* How to follow one instance's phase stream: an endpoint that answers JSON, or an event per
|
|
7
16
|
* phase change when asked for `text/event-stream`, and a `gone` event when the instance leaves.
|
|
@@ -9,7 +18,7 @@ import { nodeProxyTransport } from './proxy-transport';
|
|
|
9
18
|
*/
|
|
10
19
|
export type PhaseStreamOptions<T> = {
|
|
11
20
|
url: string;
|
|
12
|
-
|
|
21
|
+
auth: PhaseStreamAuth;
|
|
13
22
|
instanceId: string;
|
|
14
23
|
/** The event carrying a state; `gone` is handled for every stream. */
|
|
15
24
|
eventName: string;
|
|
@@ -37,7 +46,7 @@ export type PhaseStreamResult<T> = {
|
|
|
37
46
|
* wait times out. The server emits on phase change only, so every callback is a real transition.
|
|
38
47
|
*/
|
|
39
48
|
export function followPhaseStream<T>(options: PhaseStreamOptions<T>): Promise<PhaseStreamResult<T>> {
|
|
40
|
-
const { url,
|
|
49
|
+
const { url, auth } = options;
|
|
41
50
|
return new Promise<PhaseStreamResult<T>>((resolve, reject) => {
|
|
42
51
|
let last: T | undefined;
|
|
43
52
|
let lastKey = '';
|
|
@@ -61,14 +70,28 @@ export function followPhaseStream<T>(options: PhaseStreamOptions<T>): Promise<Ph
|
|
|
61
70
|
const resolveGone = () =>
|
|
62
71
|
finish(() => (last !== undefined ? resolve({ state: last, gone: true }) : reject(options.goneError())));
|
|
63
72
|
|
|
73
|
+
const fetchAuthenticated: typeof nodeProxyTransport.fetch = async (input, init) => {
|
|
74
|
+
let headers: Headers;
|
|
75
|
+
try {
|
|
76
|
+
headers = new Headers(
|
|
77
|
+
auth.getHeaders ? await auth.getHeaders() : { Authorization: `Bearer ${auth.apiKey}` },
|
|
78
|
+
);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
// Credential errors need caller action; EventSource otherwise retries them until timeout.
|
|
81
|
+
finish(() => reject(error));
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
new Headers(init?.headers).forEach((value, key) => headers.set(key, value));
|
|
85
|
+
return nodeProxyTransport.fetch(input, { ...init, headers });
|
|
86
|
+
};
|
|
87
|
+
|
|
64
88
|
let confirming = false;
|
|
65
89
|
const confirmGone = () => {
|
|
66
90
|
if (confirming || settled) return;
|
|
67
91
|
confirming = true;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
92
|
+
fetchAuthenticated(url, {
|
|
93
|
+
headers: { Accept: 'application/json' },
|
|
94
|
+
})
|
|
72
95
|
.then(async (res) => {
|
|
73
96
|
confirming = false;
|
|
74
97
|
if (res.status !== 404) {
|
|
@@ -87,7 +110,7 @@ export function followPhaseStream<T>(options: PhaseStreamOptions<T>): Promise<Ph
|
|
|
87
110
|
// Without this the client treats it as a connection to retry and follows a gone instance
|
|
88
111
|
// until the timeout, which is minutes of a command that looks hung and says nothing.
|
|
89
112
|
const fetchOrGone: typeof nodeProxyTransport.fetch = async (input, init) => {
|
|
90
|
-
const res = await
|
|
113
|
+
const res = await fetchAuthenticated(input, init);
|
|
91
114
|
if (res.status === 404) resolveGone();
|
|
92
115
|
return res;
|
|
93
116
|
};
|
|
@@ -97,7 +120,6 @@ export function followPhaseStream<T>(options: PhaseStreamOptions<T>): Promise<Ph
|
|
|
97
120
|
fetch: fetchOrGone,
|
|
98
121
|
onConnect: () => options.onOpen?.(),
|
|
99
122
|
headers: {
|
|
100
|
-
Authorization: `Bearer ${apiKey}`,
|
|
101
123
|
Accept: 'text/event-stream',
|
|
102
124
|
},
|
|
103
125
|
onMessage: (message: EventSourceMessage) => {
|
|
@@ -1,19 +1,42 @@
|
|
|
1
1
|
import type { MergedRequestInit } from '../internal/types';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/** A workload JWT, or a function that returns the current one on every exchange. */
|
|
4
|
+
export type WorkloadToken = string | (() => string | Promise<string>);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the identity JWT to exchange, read again for every exchange. Null means an egress proxy
|
|
8
|
+
* adds the JWT to the exchange request, so the client sends none.
|
|
9
|
+
*/
|
|
10
|
+
export type WorkloadIdentityReader = () => Promise<string | null>;
|
|
11
|
+
|
|
12
|
+
export const injectedWorkloadIdentityReader: WorkloadIdentityReader = async () => null;
|
|
13
|
+
|
|
14
|
+
export function workloadTokenReader(token: WorkloadToken): WorkloadIdentityReader {
|
|
15
|
+
return async () => (typeof token === 'function' ? await token() : token);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function workloadTokenFileReader(path: string): WorkloadIdentityReader {
|
|
19
|
+
return async () => {
|
|
20
|
+
const { readFile } = await import('node:fs/promises');
|
|
21
|
+
return readFile(path, 'utf8');
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Refreshes workload credentials without retaining the identity JWT. */
|
|
4
26
|
export class WorkloadCredentials {
|
|
5
|
-
private cached?: { token: string; expires: number };
|
|
27
|
+
private cached?: { token: string; expires: number; refreshAt: number };
|
|
6
28
|
private pending: Promise<string> | undefined;
|
|
7
29
|
|
|
8
30
|
constructor(
|
|
9
31
|
private endpoint: string,
|
|
10
|
-
private
|
|
32
|
+
private readIdentity: WorkloadIdentityReader,
|
|
11
33
|
private fetcher: typeof fetch,
|
|
12
34
|
private fetchOptions?: MergedRequestInit,
|
|
35
|
+
private bindingId?: string,
|
|
13
36
|
) {}
|
|
14
37
|
|
|
15
38
|
async get(): Promise<string> {
|
|
16
|
-
if (this.cached && this.cached.
|
|
39
|
+
if (this.cached && this.cached.refreshAt > Date.now()) return this.cached.token;
|
|
17
40
|
if (!this.pending)
|
|
18
41
|
this.pending = this.exchange().finally(() => {
|
|
19
42
|
this.pending = undefined;
|
|
@@ -22,23 +45,57 @@ export class WorkloadCredentials {
|
|
|
22
45
|
}
|
|
23
46
|
|
|
24
47
|
private async exchange(): Promise<string> {
|
|
25
|
-
const
|
|
26
|
-
const jwt =
|
|
48
|
+
const identity = await this.readIdentity();
|
|
49
|
+
const jwt =
|
|
50
|
+
identity === null ? undefined
|
|
51
|
+
: typeof identity === 'string' ? identity.trim()
|
|
52
|
+
: '';
|
|
53
|
+
if (jwt !== undefined && (!jwt || jwt.length > 32768))
|
|
54
|
+
throw new Error('Workload identity token must be a JWT of at most 32768 characters');
|
|
55
|
+
const start = Date.now();
|
|
27
56
|
const response = await this.fetcher(`${this.endpoint.replace(/\/$/, '')}/v1/access_tokens`, {
|
|
28
57
|
...(this.fetchOptions as RequestInit),
|
|
29
58
|
method: 'POST',
|
|
30
|
-
headers:
|
|
31
|
-
|
|
59
|
+
headers:
|
|
60
|
+
this.bindingId ?
|
|
61
|
+
{ 'Content-Type': 'application/x-www-form-urlencoded' }
|
|
62
|
+
: { Authorization: `Bearer ${jwt}`, 'Content-Type': 'application/json' },
|
|
63
|
+
body:
|
|
64
|
+
this.bindingId ?
|
|
65
|
+
new URLSearchParams({
|
|
66
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',
|
|
67
|
+
subject_token_type: 'urn:ietf:params:oauth:token-type:jwt',
|
|
68
|
+
...(jwt !== undefined && { subject_token: jwt }),
|
|
69
|
+
audience: this.bindingId,
|
|
70
|
+
}).toString()
|
|
71
|
+
: JSON.stringify({}),
|
|
32
72
|
signal: AbortSignal.timeout(30_000),
|
|
33
73
|
redirect: 'error',
|
|
34
74
|
});
|
|
35
75
|
if (!response.ok) throw new Error(`Workload token exchange returned HTTP ${response.status}`);
|
|
36
|
-
const body = (await response.json()) as {
|
|
37
|
-
|
|
38
|
-
|
|
76
|
+
const body = (await response.json()) as {
|
|
77
|
+
token?: string;
|
|
78
|
+
expiresAt: string;
|
|
79
|
+
access_token?: string;
|
|
80
|
+
expires_in?: number;
|
|
81
|
+
token_type?: string;
|
|
82
|
+
};
|
|
83
|
+
const token = this.bindingId ? body.access_token : body.token;
|
|
84
|
+
if (typeof token !== 'string' || !token)
|
|
85
|
+
throw new Error('Workload token exchange returned no access token');
|
|
86
|
+
if (
|
|
87
|
+
this.bindingId &&
|
|
88
|
+
(body.token_type !== 'Bearer' ||
|
|
89
|
+
typeof body.expires_in !== 'number' ||
|
|
90
|
+
!Number.isInteger(body.expires_in) ||
|
|
91
|
+
body.expires_in < 1 ||
|
|
92
|
+
body.expires_in > 14400)
|
|
93
|
+
)
|
|
94
|
+
throw new Error('Workload token exchange returned an invalid token response');
|
|
95
|
+
const expires = this.bindingId ? start + body.expires_in! * 1000 : Date.parse(body.expiresAt);
|
|
39
96
|
if (!Number.isFinite(expires) || expires <= Date.now())
|
|
40
97
|
throw new Error('Workload token exchange returned an invalid expiration');
|
|
41
|
-
this.cached = { token:
|
|
42
|
-
return
|
|
98
|
+
this.cached = { token, expires, refreshAt: expires - Math.min(60_000, (expires - start) * 0.2) };
|
|
99
|
+
return token;
|
|
43
100
|
}
|
|
44
101
|
}
|
|
@@ -27,12 +27,15 @@ export interface AccessTokenCreateParams {
|
|
|
27
27
|
/**
|
|
28
28
|
* Permissions in the form `<resource>:<id|*>:<action>`, e.g. `device:*:install`,
|
|
29
29
|
* `asset:asset_01h455vb4pex5vsknk084sn02q:read` or `applerelay:*:connect`.
|
|
30
|
-
* Instance control accepts `ios:<id>:
|
|
31
|
-
* and `gradle:<id>:
|
|
30
|
+
* Instance control accepts `ios:<id>:control`, `android:<id>:control`, `xcode:<id>:control`,
|
|
31
|
+
* and `gradle:<id>:control`. Use the returned instance ID, including `sandbox_` for Xcode.
|
|
32
32
|
* iOS and Android accept `ios:<id>:watch` and `android:<id>:watch` for watch-only
|
|
33
33
|
* streaming, or `ios:<id>:stream` and `android:<id>:stream` for
|
|
34
34
|
* interactive streaming without device API or app-management access.
|
|
35
|
-
*
|
|
35
|
+
* Control includes reads and runtime operations, but excludes instance create/update/delete.
|
|
36
|
+
* Grant `create`, `update`, and `delete` separately; `all` includes every action.
|
|
37
|
+
* Creation requires target `*`. Instance targets also accept `*`. Any supported action may be delegated when
|
|
38
|
+
* covered by the caller, including `read`, build `work`, and device `tunnel`.
|
|
36
39
|
* See https://docs.limrun.com/docs/reference/permissions for targets and actions.
|
|
37
40
|
*/
|
|
38
41
|
permissions?: Array<string>;
|
|
@@ -42,7 +45,7 @@ export interface AccessTokenCreateParams {
|
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
47
|
* How long the token stays valid. Defaults to 3600 (1 hour), maximum is 14400 (4
|
|
45
|
-
* hours).
|
|
48
|
+
* hours), capped by the source credential's expiry.
|
|
46
49
|
*/
|
|
47
50
|
ttlSeconds?: number;
|
|
48
51
|
}
|
|
@@ -86,7 +86,7 @@ export namespace AnalyticsInstancesResponse {
|
|
|
86
86
|
/**
|
|
87
87
|
* Platform name.
|
|
88
88
|
*/
|
|
89
|
-
platform: 'android' | 'ios' | 'xcode' | 'gradle';
|
|
89
|
+
platform: 'android' | 'ios' | 'xcode' | 'gradle' | 'macos';
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Actual runtime minutes before platform multiplier
|
|
@@ -225,6 +225,11 @@ export namespace AnalyticsResponse {
|
|
|
225
225
|
*/
|
|
226
226
|
ios: { [key: string]: Series.Ios };
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Map of region to analytics stats for macOS. Absent from servers that predate it.
|
|
230
|
+
*/
|
|
231
|
+
macos?: { [key: string]: Series.Macos };
|
|
232
|
+
|
|
228
233
|
/**
|
|
229
234
|
* RFC3339 timestamp for the start of the bucket in the requested timezone,
|
|
230
235
|
* including the local offset
|
|
@@ -331,6 +336,11 @@ export namespace AnalyticsResponse {
|
|
|
331
336
|
wallclockMinutes?: number;
|
|
332
337
|
}
|
|
333
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Analytics for macOS instances in a region, the same shape as Gradle's.
|
|
341
|
+
*/
|
|
342
|
+
export type Macos = Gradle;
|
|
343
|
+
|
|
334
344
|
/**
|
|
335
345
|
* Complete analytics for a specific region including billing breakdown
|
|
336
346
|
*/
|
|
@@ -617,7 +627,7 @@ export namespace AnalyticsResponse {
|
|
|
617
627
|
/**
|
|
618
628
|
* Platform name.
|
|
619
629
|
*/
|
|
620
|
-
platform: 'android' | 'ios' | 'xcode' | 'gradle';
|
|
630
|
+
platform: 'android' | 'ios' | 'xcode' | 'gradle' | 'macos';
|
|
621
631
|
|
|
622
632
|
/**
|
|
623
633
|
* Actual runtime minutes before platform multiplier
|
|
@@ -732,6 +742,11 @@ export namespace AnalyticsResponse {
|
|
|
732
742
|
*/
|
|
733
743
|
ios: { [key: string]: Summary.Ios };
|
|
734
744
|
|
|
745
|
+
/**
|
|
746
|
+
* Map of region to analytics stats for macOS. Absent from servers that predate it.
|
|
747
|
+
*/
|
|
748
|
+
macos?: { [key: string]: Summary.Macos };
|
|
749
|
+
|
|
735
750
|
/**
|
|
736
751
|
* Map of region to analytics stats for Xcode
|
|
737
752
|
*/
|
|
@@ -827,6 +842,11 @@ export namespace AnalyticsResponse {
|
|
|
827
842
|
wallclockMinutes?: number;
|
|
828
843
|
}
|
|
829
844
|
|
|
845
|
+
/**
|
|
846
|
+
* Analytics for macOS instances in a region, the same shape as Gradle's.
|
|
847
|
+
*/
|
|
848
|
+
export type Macos = Gradle;
|
|
849
|
+
|
|
830
850
|
/**
|
|
831
851
|
* Complete analytics for a specific region including billing breakdown
|
|
832
852
|
*/
|
|
@@ -76,9 +76,21 @@ export class GradleInstances extends APIResource {
|
|
|
76
76
|
|
|
77
77
|
/** Follow the disk snapshot restore or save until it reaches a terminal phase. */
|
|
78
78
|
followSnapshot(id: string, options?: GradleSnapshotFollowOptions): Promise<GradleSnapshotFollowResult> {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
return followGradleSnapshot(
|
|
80
|
+
{
|
|
81
|
+
baseURL: this._client.baseURL,
|
|
82
|
+
instanceId: id,
|
|
83
|
+
// Resolved per connection, so federated and workload credentials refresh on reconnect.
|
|
84
|
+
getHeaders: async () => {
|
|
85
|
+
const { req } = await this._client.buildRequest({
|
|
86
|
+
method: 'get',
|
|
87
|
+
path: path`/v1/gradle_instances/${id}/snapshot`,
|
|
88
|
+
});
|
|
89
|
+
return req.headers;
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
options,
|
|
93
|
+
);
|
|
82
94
|
}
|
|
83
95
|
}
|
|
84
96
|
|
package/src/resources/index.ts
CHANGED
|
@@ -45,6 +45,14 @@ export {
|
|
|
45
45
|
type GradleInstanceListParams,
|
|
46
46
|
type GradleInstancesItems,
|
|
47
47
|
} from './gradle-instances';
|
|
48
|
+
export {
|
|
49
|
+
MacosInstances,
|
|
50
|
+
type MacosInstance,
|
|
51
|
+
type MacosInstanceUpdateParams,
|
|
52
|
+
type MacosInstanceCreateParams,
|
|
53
|
+
type MacosInstanceListParams,
|
|
54
|
+
type MacosInstancesItems,
|
|
55
|
+
} from './macos-instances';
|
|
48
56
|
export {
|
|
49
57
|
type IosInstance,
|
|
50
58
|
type IosInstanceUpdateParams,
|