@temporalio/cloud 1.11.3
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.md +23 -0
- package/README.md +8 -0
- package/lib/cloud-operations-client.d.ts +335 -0
- package/lib/cloud-operations-client.js +392 -0
- package/lib/cloud-operations-client.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/pkg.d.ts +5 -0
- package/lib/pkg.js +12 -0
- package/lib/pkg.js.map +1 -0
- package/lib/types.d.ts +3 -0
- package/lib/types.js +29 -0
- package/lib/types.js.map +1 -0
- package/package.json +40 -0
- package/src/cloud-operations-client.ts +600 -0
- package/src/index.ts +7 -0
- package/src/pkg.ts +7 -0
- package/src/types.ts +4 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Temporal TypeScript SDK
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2021 Temporal Technologies Inc. All Rights Reserved
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# `@temporalio/cloud`
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@temporalio/cloud)
|
|
4
|
+
|
|
5
|
+
Part of [Temporal](https://temporal.io)'s [TypeScript SDK](https://docs.temporal.io/typescript/introduction/).
|
|
6
|
+
|
|
7
|
+
- [API reference](https://typescript.temporal.io/api/namespaces/cloud)
|
|
8
|
+
- [Sample projects](https://github.com/temporalio/samples-typescript)
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import * as grpc from '@grpc/grpc-js';
|
|
5
|
+
import type { RPCImpl } from 'protobufjs';
|
|
6
|
+
import { TLSConfig } from '@temporalio/common/lib/internal-non-workflow';
|
|
7
|
+
import { Duration } from '@temporalio/common/lib/time';
|
|
8
|
+
import { CallContext, HealthService, Metadata } from '@temporalio/client';
|
|
9
|
+
import { CloudService } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
export interface CloudOperationsClientOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Connection to use to communicate with the server.
|
|
16
|
+
*/
|
|
17
|
+
connection: CloudOperationsConnection;
|
|
18
|
+
/**
|
|
19
|
+
* Version header for safer mutations.
|
|
20
|
+
* May or may not be required depending on cloud settings.
|
|
21
|
+
*/
|
|
22
|
+
apiVersion?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* High level client for the Temporal Cloud API.
|
|
26
|
+
*
|
|
27
|
+
* @experimental
|
|
28
|
+
*/
|
|
29
|
+
export declare class CloudOperationsClient {
|
|
30
|
+
/**
|
|
31
|
+
* The underlying {@link CloudOperationsConnection | connection} used by this client.
|
|
32
|
+
*
|
|
33
|
+
* Clients are cheap to create, but connections are expensive. Where that make sense,
|
|
34
|
+
* a single connection may and should be reused by multiple `CloudOperationsClient`.
|
|
35
|
+
*/
|
|
36
|
+
readonly connection: CloudOperationsConnection;
|
|
37
|
+
readonly options: Readonly<CloudOperationsClientOptions>;
|
|
38
|
+
constructor(options: CloudOperationsClientOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Set a deadline for any service requests executed in `fn`'s scope.
|
|
41
|
+
*
|
|
42
|
+
* The deadline is a point in time after which any pending gRPC request will be considered as failed;
|
|
43
|
+
* this will locally result in the request call throwing a {@link grpc.ServiceError|ServiceError}
|
|
44
|
+
* with code {@link grpc.status.DEADLINE_EXCEEDED|DEADLINE_EXCEEDED}.
|
|
45
|
+
*
|
|
46
|
+
* It is stronly recommended to explicitly set deadlines. If no deadline is set, then it is
|
|
47
|
+
* possible for the client to end up waiting forever for a response.
|
|
48
|
+
*
|
|
49
|
+
* This method is only a convenience wrapper around {@link CloudOperationsConnection.withDeadline}.
|
|
50
|
+
*
|
|
51
|
+
* @param deadline a point in time after which the request will be considered as failed; either a
|
|
52
|
+
* Date object, or a number of milliseconds since the Unix epoch (UTC).
|
|
53
|
+
* @returns the value returned from `fn`
|
|
54
|
+
*
|
|
55
|
+
* @see https://grpc.io/docs/guides/deadlines/
|
|
56
|
+
*/
|
|
57
|
+
withDeadline<R>(deadline: number | Date, fn: () => Promise<R>): Promise<R>;
|
|
58
|
+
/**
|
|
59
|
+
* Set an {@link AbortSignal} that, when aborted, cancels any ongoing service requests executed in
|
|
60
|
+
* `fn`'s scope. This will locally result in the request call throwing a {@link grpc.ServiceError|ServiceError}
|
|
61
|
+
* with code {@link grpc.status.CANCELLED|CANCELLED}.
|
|
62
|
+
*
|
|
63
|
+
* This method is only a convenience wrapper around {@link CloudOperationsConnection.withAbortSignal}.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* const ctrl = new AbortController();
|
|
69
|
+
* setTimeout(() => ctrl.abort(), 10_000);
|
|
70
|
+
* // 👇 throws if incomplete by the timeout.
|
|
71
|
+
* await conn.withAbortSignal(ctrl.signal, () => client.cloudService.getNamespace({ namespace }));
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @returns value returned from `fn`
|
|
75
|
+
*
|
|
76
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
77
|
+
*/
|
|
78
|
+
withAbortSignal<R>(abortSignal: AbortSignal, fn: () => Promise<R>): Promise<R>;
|
|
79
|
+
/**
|
|
80
|
+
* Set metadata for any service requests executed in `fn`'s scope.
|
|
81
|
+
*
|
|
82
|
+
* @returns returned value of `fn`
|
|
83
|
+
*
|
|
84
|
+
* This method is only a convenience wrapper around {@link CloudOperationsConnection.withMetadata}.
|
|
85
|
+
*/
|
|
86
|
+
withMetadata<R>(metadata: Metadata, fn: () => Promise<R>): Promise<R>;
|
|
87
|
+
/**
|
|
88
|
+
* Raw gRPC access to the Temporal Cloud Operations service.
|
|
89
|
+
*
|
|
90
|
+
* **NOTE**: The Temporal Cloud Operations service API Version provided in {@link options} is
|
|
91
|
+
* **not** automatically set on requests made via the raw gRPC service object. If the namespace
|
|
92
|
+
* requires it, you may need to do the following:
|
|
93
|
+
*
|
|
94
|
+
* ```
|
|
95
|
+
* const metadata: Metadata = { ['temporal-cloud-api-version']: apiVersion }
|
|
96
|
+
* const response = await client.withMetadata(metadata, async () => {
|
|
97
|
+
* return client.cloudService.getNamespace({ namespace });
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
get cloudService(): CloudService;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @experimental
|
|
105
|
+
*/
|
|
106
|
+
export interface CloudOperationsConnectionOptions {
|
|
107
|
+
/**
|
|
108
|
+
* The address of the Temporal Cloud Operations API to connect to, in `hostname:port` format.
|
|
109
|
+
*
|
|
110
|
+
* @default saas-api.tmprl.cloud:443
|
|
111
|
+
*/
|
|
112
|
+
address?: string;
|
|
113
|
+
/**
|
|
114
|
+
* TLS configuration. TLS is required for connecting to the Temporal Cloud Operations API.
|
|
115
|
+
*
|
|
116
|
+
@default true
|
|
117
|
+
*/
|
|
118
|
+
tls?: Pick<TLSConfig, 'serverNameOverride'> | true;
|
|
119
|
+
/**
|
|
120
|
+
* GRPC Channel arguments
|
|
121
|
+
*
|
|
122
|
+
* @see option descriptions {@link https://grpc.github.io/grpc/core/group__grpc__arg__keys.html | here}
|
|
123
|
+
*
|
|
124
|
+
* By default the SDK sets the following keepalive arguments:
|
|
125
|
+
*
|
|
126
|
+
* ```
|
|
127
|
+
* grpc.keepalive_permit_without_calls: 1
|
|
128
|
+
* grpc.keepalive_time_ms: 30_000
|
|
129
|
+
* grpc.keepalive_timeout_ms: 15_000
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* To opt-out of keepalive, override these keys with `undefined`.
|
|
133
|
+
*/
|
|
134
|
+
channelArgs?: grpc.ChannelOptions;
|
|
135
|
+
/**
|
|
136
|
+
* {@link https://grpc.github.io/grpc/node/module-src_client_interceptors.html | gRPC interceptors}
|
|
137
|
+
* which will be applied to every RPC call performed by this connection. By default, an interceptor
|
|
138
|
+
* will be included which automatically retries retryable errors. If you do not wish to perform
|
|
139
|
+
* automatic retries, set this to an empty list (or a list with your own interceptors). If you want
|
|
140
|
+
* to add your own interceptors while keeping the default retry behavior, add this to your list of
|
|
141
|
+
* interceptors: `makeGrpcRetryInterceptor(defaultGrpcRetryOptions())`.
|
|
142
|
+
*
|
|
143
|
+
* See:
|
|
144
|
+
* - {@link makeGrpcRetryInterceptor}
|
|
145
|
+
* - {@link defaultGrpcRetryOptions}
|
|
146
|
+
*/
|
|
147
|
+
interceptors?: grpc.Interceptor[];
|
|
148
|
+
/**
|
|
149
|
+
* Optional mapping of gRPC metadata (HTTP headers) to send with each request to the server. An
|
|
150
|
+
* `Authorization` header set through `metadata` will be ignored and overriden by the value of the
|
|
151
|
+
* {@link apiKey} option.
|
|
152
|
+
*
|
|
153
|
+
* In order to dynamically set metadata, use {@link CloudOperationsConnection.withMetadata}
|
|
154
|
+
*/
|
|
155
|
+
metadata?: Metadata;
|
|
156
|
+
/**
|
|
157
|
+
* API key for Temporal. This becomes the "Authorization" HTTP header with "Bearer " prepended.
|
|
158
|
+
*
|
|
159
|
+
* You may provide a static string or a callback. Also see {@link CloudOperationsConnection.withApiKey}
|
|
160
|
+
* or {@link Connection.setApiKey}
|
|
161
|
+
*/
|
|
162
|
+
apiKey: string | (() => string);
|
|
163
|
+
/**
|
|
164
|
+
* Milliseconds to wait until establishing a connection with the server.
|
|
165
|
+
*
|
|
166
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
167
|
+
* @default 10 seconds
|
|
168
|
+
*/
|
|
169
|
+
connectTimeout?: Duration;
|
|
170
|
+
}
|
|
171
|
+
export type ResolvedCloudOperationsConnectionOptions = Required<Omit<CloudOperationsConnectionOptions, 'tls' | 'connectTimeout'>> & {
|
|
172
|
+
connectTimeoutMs: number;
|
|
173
|
+
credentials: grpc.ChannelCredentials;
|
|
174
|
+
};
|
|
175
|
+
interface RPCImplOptions {
|
|
176
|
+
serviceName: string;
|
|
177
|
+
client: grpc.Client;
|
|
178
|
+
callContextStorage: AsyncLocalStorage<CallContext>;
|
|
179
|
+
interceptors?: grpc.Interceptor[];
|
|
180
|
+
staticMetadata: Metadata;
|
|
181
|
+
apiKeyFnRef: {
|
|
182
|
+
fn?: () => string;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
interface CloudOperationsConnectionCtorOptions {
|
|
186
|
+
readonly options: ResolvedCloudOperationsConnectionOptions;
|
|
187
|
+
readonly client: grpc.Client;
|
|
188
|
+
/**
|
|
189
|
+
* Raw gRPC access to the
|
|
190
|
+
* {@link https://github.com/temporalio/api-cloud/blob/main/temporal/api/cloud/cloudservice/v1/service.proto | Temporal Cloud's Operator Service}.
|
|
191
|
+
*/
|
|
192
|
+
readonly cloudService: CloudService;
|
|
193
|
+
/**
|
|
194
|
+
* Raw gRPC access to the standard gRPC {@link https://github.com/grpc/grpc/blob/92f58c18a8da2728f571138c37760a721c8915a2/doc/health-checking.md | health service}.
|
|
195
|
+
*/
|
|
196
|
+
readonly healthService: HealthService;
|
|
197
|
+
readonly callContextStorage: AsyncLocalStorage<CallContext>;
|
|
198
|
+
readonly apiKeyFnRef: {
|
|
199
|
+
fn?: () => string;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Client connection to the Temporal Cloud Operations Service endpoint.
|
|
204
|
+
*
|
|
205
|
+
* ⚠️ Connections are expensive to construct and should be reused.
|
|
206
|
+
* Make sure to {@link close} any unused connections to avoid leaking resources.
|
|
207
|
+
*
|
|
208
|
+
* @experimental
|
|
209
|
+
*/
|
|
210
|
+
export declare class CloudOperationsConnection {
|
|
211
|
+
private static readonly Client;
|
|
212
|
+
readonly options: ResolvedCloudOperationsConnectionOptions;
|
|
213
|
+
private readonly client;
|
|
214
|
+
/**
|
|
215
|
+
* Used to ensure `ensureConnected` is called once.
|
|
216
|
+
*/
|
|
217
|
+
private connectPromise?;
|
|
218
|
+
/**
|
|
219
|
+
* Raw gRPC access to the
|
|
220
|
+
* {@link https://github.com/temporalio/api-cloud/blob/main/temporal/api/cloud/cloudservice/v1/service.proto | Temporal Cloud's Operator Service}.
|
|
221
|
+
*
|
|
222
|
+
* The Temporal Cloud Operator Service API defines how Temporal SDKs and other clients interact
|
|
223
|
+
* with the Temporal Cloud platform to perform administrative functions like registering a search
|
|
224
|
+
* attribute or a namespace.
|
|
225
|
+
*
|
|
226
|
+
* This Service API is NOT compatible with self-hosted Temporal deployments.
|
|
227
|
+
*/
|
|
228
|
+
readonly cloudService: CloudService;
|
|
229
|
+
/**
|
|
230
|
+
* Raw gRPC access to the standard gRPC {@link https://github.com/grpc/grpc/blob/92f58c18a8da2728f571138c37760a721c8915a2/doc/health-checking.md | health service}.
|
|
231
|
+
*/
|
|
232
|
+
readonly healthService: HealthService;
|
|
233
|
+
private readonly callContextStorage;
|
|
234
|
+
private readonly apiKeyFnRef;
|
|
235
|
+
protected static createCtorOptions(options: CloudOperationsConnectionOptions): CloudOperationsConnectionCtorOptions;
|
|
236
|
+
/**
|
|
237
|
+
* Create a lazy `CloudOperationsConnection` instance.
|
|
238
|
+
*
|
|
239
|
+
* This method does not verify connectivity with the server. We recommend using {@link connect} instead.
|
|
240
|
+
*/
|
|
241
|
+
static lazy(options: CloudOperationsConnectionOptions): CloudOperationsConnection;
|
|
242
|
+
/**
|
|
243
|
+
* Establish a connection with the server and return a `CloudOperationsConnection` instance.
|
|
244
|
+
*
|
|
245
|
+
* This is the preferred method of creating connections as it verifies connectivity.
|
|
246
|
+
*/
|
|
247
|
+
static connect(options: CloudOperationsConnectionOptions): Promise<CloudOperationsConnection>;
|
|
248
|
+
protected constructor({ options, client, cloudService, healthService, callContextStorage, apiKeyFnRef, }: CloudOperationsConnectionCtorOptions);
|
|
249
|
+
protected static generateRPCImplementation({ serviceName, client, callContextStorage, interceptors, staticMetadata, apiKeyFnRef, }: RPCImplOptions): RPCImpl;
|
|
250
|
+
/**
|
|
251
|
+
* Ensure connection can be established.
|
|
252
|
+
*/
|
|
253
|
+
private ensureConnected;
|
|
254
|
+
/**
|
|
255
|
+
* Set a deadline for any service requests executed in `fn`'s scope.
|
|
256
|
+
*
|
|
257
|
+
* The deadline is a point in time after which any pending gRPC request will be considered as failed;
|
|
258
|
+
* this will locally result in the request call throwing a {@link grpc.ServiceError|ServiceError}
|
|
259
|
+
* with code {@link grpc.status.DEADLINE_EXCEEDED|DEADLINE_EXCEEDED}.
|
|
260
|
+
*
|
|
261
|
+
* It is stronly recommended to explicitly set deadlines. If no deadline is set, then it is
|
|
262
|
+
* possible for the client to end up waiting forever for a response.
|
|
263
|
+
*
|
|
264
|
+
* @param deadline a point in time after which the request will be considered as failed; either a
|
|
265
|
+
* Date object, or a number of milliseconds since the Unix epoch (UTC).
|
|
266
|
+
* @returns the value returned from `fn`
|
|
267
|
+
*
|
|
268
|
+
* @see https://grpc.io/docs/guides/deadlines/
|
|
269
|
+
*/
|
|
270
|
+
withDeadline<ReturnType>(deadline: number | Date, fn: () => Promise<ReturnType>): Promise<ReturnType>;
|
|
271
|
+
/**
|
|
272
|
+
* Set an {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that, when aborted,
|
|
273
|
+
* cancels any ongoing requests executed in `fn`'s scope.
|
|
274
|
+
*
|
|
275
|
+
* @returns value returned from `fn`
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
*
|
|
279
|
+
* ```ts
|
|
280
|
+
* const ctrl = new AbortController();
|
|
281
|
+
* setTimeout(() => ctrl.abort(), 10_000);
|
|
282
|
+
* // 👇 throws if incomplete by the timeout.
|
|
283
|
+
* await conn.withAbortSignal(ctrl.signal, () => client.cloudService.someOperation(...));
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
withAbortSignal<ReturnType>(abortSignal: AbortSignal, fn: () => Promise<ReturnType>): Promise<ReturnType>;
|
|
287
|
+
/**
|
|
288
|
+
* Set metadata for any service requests executed in `fn`'s scope.
|
|
289
|
+
*
|
|
290
|
+
* The provided metadata is merged on top of any existing metadata in current scope.
|
|
291
|
+
*
|
|
292
|
+
* @returns value returned from `fn`
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
*
|
|
296
|
+
* ```ts
|
|
297
|
+
* const result = await conn.withMetadata({ someMetadata: 'value' }, () =>
|
|
298
|
+
* conn.withMetadata({ otherKey: 'set' }, () => client.cloudService.someOperation(...)))
|
|
299
|
+
* );
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
withMetadata<ReturnType>(metadata: Metadata, fn: () => Promise<ReturnType>): Promise<ReturnType>;
|
|
303
|
+
/**
|
|
304
|
+
* Set the apiKey for any service requests executed in `fn`'s scope (thus changing the `Authorization` header).
|
|
305
|
+
*
|
|
306
|
+
* @returns value returned from `fn`
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
*
|
|
310
|
+
* ```ts
|
|
311
|
+
* const workflowHandle = await conn.withApiKey('secret', () =>
|
|
312
|
+
* conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
|
|
313
|
+
* );
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
withApiKey<ReturnType>(apiKey: string, fn: () => Promise<ReturnType>): Promise<ReturnType>;
|
|
317
|
+
/**
|
|
318
|
+
* Set the {@link ConnectionOptions.apiKey} for all subsequent requests.
|
|
319
|
+
* A static string or a callback function may be provided.
|
|
320
|
+
*/
|
|
321
|
+
setApiKey(apiKey: string | (() => string)): void;
|
|
322
|
+
/**
|
|
323
|
+
* Wait for successful connection to the server.
|
|
324
|
+
*
|
|
325
|
+
* @see https://grpc.github.io/grpc/node/grpc.Client.html#waitForReady__anchor
|
|
326
|
+
*/
|
|
327
|
+
protected untilReady(deadline: number): Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* Close the underlying gRPC client.
|
|
330
|
+
*
|
|
331
|
+
* Make sure to call this method to ensure proper resource cleanup.
|
|
332
|
+
*/
|
|
333
|
+
close(): void;
|
|
334
|
+
}
|
|
335
|
+
export {};
|