@voyantjs/cloud-sdk 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/env.d.ts +41 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +55 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/node_modules/@voyant-sdk/sdk-core/dist/client.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,6 +36,49 @@ const vaults = await client.vault.listVaults();
|
|
|
36
36
|
const phoneNumbers = await client.sms.listPhoneNumbers();
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
### From env / worker bindings
|
|
40
|
+
|
|
41
|
+
`getVoyantCloudClient` reads `VOYANT_CLOUD_API_KEY` (and optionally
|
|
42
|
+
`VOYANT_CLOUD_API_URL`, `VOYANT_CLOUD_USER_AGENT`) from a bindings/env
|
|
43
|
+
object and constructs a client. It throws a typed `VoyantCloudConfigError`
|
|
44
|
+
when the key is missing.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { getVoyantCloudClient, type VoyantCloudEnv } from "@voyantjs/cloud-sdk";
|
|
48
|
+
|
|
49
|
+
// Cloudflare Worker
|
|
50
|
+
export default {
|
|
51
|
+
async fetch(_req: Request, env: VoyantCloudEnv) {
|
|
52
|
+
const cloud = getVoyantCloudClient(env);
|
|
53
|
+
return Response.json(await cloud.vault.listVaults());
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { getVoyantCloudClient } from "@voyantjs/cloud-sdk";
|
|
60
|
+
|
|
61
|
+
// Node
|
|
62
|
+
const cloud = getVoyantCloudClient(process.env);
|
|
63
|
+
const vaults = await cloud.vault.listVaults();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`overrides` win over env values, except an empty-string override is
|
|
67
|
+
treated as missing so it can't silently clobber a valid env value:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { getVoyantCloudClient, type VoyantCloudEnv } from "@voyantjs/cloud-sdk";
|
|
71
|
+
|
|
72
|
+
declare const env: VoyantCloudEnv;
|
|
73
|
+
declare const tenantKey: string;
|
|
74
|
+
|
|
75
|
+
const cloud = getVoyantCloudClient(env, { apiKey: tenantKey });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
For paths that legitimately operate without cloud (local dev tooling that
|
|
79
|
+
doesn't send mail, etc.), use `tryGetVoyantCloudClient` — it returns
|
|
80
|
+
`null` instead of throwing when the key is unset.
|
|
81
|
+
|
|
39
82
|
## Shape
|
|
40
83
|
|
|
41
84
|
Root groups:
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { VoyantCloudClient } from "./client.js";
|
|
2
|
+
import type { VoyantCloudClientOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bindings/env shape recognized by {@link getVoyantCloudClient} and
|
|
5
|
+
* {@link tryGetVoyantCloudClient}.
|
|
6
|
+
*
|
|
7
|
+
* Designed to accept a Cloudflare Worker `env` object, Node `process.env`,
|
|
8
|
+
* or any other key/value bag of strings. Empty-string values are treated
|
|
9
|
+
* the same as `undefined` — common when `.env` files leave a key blank.
|
|
10
|
+
*/
|
|
11
|
+
export interface VoyantCloudEnv {
|
|
12
|
+
VOYANT_CLOUD_API_KEY?: string;
|
|
13
|
+
VOYANT_CLOUD_API_URL?: string;
|
|
14
|
+
VOYANT_CLOUD_USER_AGENT?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thrown when {@link getVoyantCloudClient} cannot construct a client because
|
|
18
|
+
* `VOYANT_CLOUD_API_KEY` is missing and no override was supplied.
|
|
19
|
+
*/
|
|
20
|
+
export declare class VoyantCloudConfigError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Construct a {@link VoyantCloudClient} from a runtime bindings object
|
|
25
|
+
* (Cloudflare Worker `env`, Node `process.env`, etc.).
|
|
26
|
+
*
|
|
27
|
+
* `overrides` take precedence over env values, except an empty-string
|
|
28
|
+
* override is treated as missing so it can't silently clobber a valid env
|
|
29
|
+
* value.
|
|
30
|
+
*
|
|
31
|
+
* Throws {@link VoyantCloudConfigError} when no API key can be resolved
|
|
32
|
+
* from either source.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getVoyantCloudClient(env: VoyantCloudEnv, overrides?: Partial<VoyantCloudClientOptions>): VoyantCloudClient;
|
|
35
|
+
/**
|
|
36
|
+
* Like {@link getVoyantCloudClient}, but returns `null` when the API key
|
|
37
|
+
* is unset instead of throwing. Use from edges that legitimately operate
|
|
38
|
+
* without cloud (e.g. local dev tooling that doesn't send mail).
|
|
39
|
+
*/
|
|
40
|
+
export declare function tryGetVoyantCloudClient(env: VoyantCloudEnv, overrides?: Partial<VoyantCloudClientOptions>): VoyantCloudClient | null;
|
|
41
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,cAAc,EACnB,SAAS,GAAE,OAAO,CAAC,wBAAwB,CAAM,GAChD,iBAAiB,CAmBnB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,cAAc,EACnB,SAAS,GAAE,OAAO,CAAC,wBAAwB,CAAM,GAChD,iBAAiB,GAAG,IAAI,CAS1B"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createVoyantCloudClient } from "./client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when {@link getVoyantCloudClient} cannot construct a client because
|
|
4
|
+
* `VOYANT_CLOUD_API_KEY` is missing and no override was supplied.
|
|
5
|
+
*/
|
|
6
|
+
export class VoyantCloudConfigError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "VoyantCloudConfigError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Construct a {@link VoyantCloudClient} from a runtime bindings object
|
|
14
|
+
* (Cloudflare Worker `env`, Node `process.env`, etc.).
|
|
15
|
+
*
|
|
16
|
+
* `overrides` take precedence over env values, except an empty-string
|
|
17
|
+
* override is treated as missing so it can't silently clobber a valid env
|
|
18
|
+
* value.
|
|
19
|
+
*
|
|
20
|
+
* Throws {@link VoyantCloudConfigError} when no API key can be resolved
|
|
21
|
+
* from either source.
|
|
22
|
+
*/
|
|
23
|
+
export function getVoyantCloudClient(env, overrides = {}) {
|
|
24
|
+
const apiKey = nonEmpty(overrides.apiKey) ?? nonEmpty(env.VOYANT_CLOUD_API_KEY);
|
|
25
|
+
if (!apiKey) {
|
|
26
|
+
throw new VoyantCloudConfigError("VOYANT_CLOUD_API_KEY is not set. Set the env variable or pass `apiKey` in overrides.");
|
|
27
|
+
}
|
|
28
|
+
const baseUrl = nonEmpty(env.VOYANT_CLOUD_API_URL);
|
|
29
|
+
const userAgent = nonEmpty(env.VOYANT_CLOUD_USER_AGENT);
|
|
30
|
+
return createVoyantCloudClient({
|
|
31
|
+
...(baseUrl ? { baseUrl } : {}),
|
|
32
|
+
...(userAgent ? { userAgent } : {}),
|
|
33
|
+
...overrides,
|
|
34
|
+
apiKey,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Like {@link getVoyantCloudClient}, but returns `null` when the API key
|
|
39
|
+
* is unset instead of throwing. Use from edges that legitimately operate
|
|
40
|
+
* without cloud (e.g. local dev tooling that doesn't send mail).
|
|
41
|
+
*/
|
|
42
|
+
export function tryGetVoyantCloudClient(env, overrides = {}) {
|
|
43
|
+
try {
|
|
44
|
+
return getVoyantCloudClient(env, overrides);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof VoyantCloudConfigError) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function nonEmpty(value) {
|
|
54
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
55
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { createVoyantCloudClient, VoyantCloudClient } from "./client.js";
|
|
2
|
+
export { getVoyantCloudClient, tryGetVoyantCloudClient, VoyantCloudConfigError, } from "./env.js";
|
|
3
|
+
export type { VoyantCloudEnv } from "./env.js";
|
|
2
4
|
export { createSearchClientConfig } from "./search.js";
|
|
3
5
|
export type { SearchClientConfig, SearchClientConfigOptions, } from "./search.js";
|
|
4
6
|
export type { BrowserCommand, BrowserCommandResult, BrowserCookie, BrowserCrawlSummary, BrowserGoToOptions, BrowserJobKind, BrowserJobStatus, BrowserJsonInput, BrowserLink, BrowserPdfInput, BrowserPdfOptions, BrowserRenderInput, BrowserSameSite, BrowserScrapeElement, BrowserScrapeInput, BrowserScrapeResult, BrowserScreenshotInput, BrowserScreenshotOptions, BrowserSessionStatus, BrowserSessionSummary, BrowserSnapshotResult, BrowserViewport, BrowserWaitForSelector, BrowserWaitUntil, CheckVerificationInput, CreateVideoFromUrlInput, CreateVideoUploadInput, CreateVideoWatermarkInput, EmailMessageStatus, EmailMessageSummary, GenerateVideoCaptionInput, MintVideoSignedTokenInput, OpenBrowserSessionInput, PhoneNumberCapabilities, PhoneNumberStatus, PhoneNumberSummary, RunBrowserCommandsInput, RunBrowserCommandsResult, SendEmailAttachment, SendEmailInput, SendSmsInput, SmsMessageStatus, SmsMessageSummary, StartBrowserCrawlInput, StartBrowserCrawlResult, StartVerificationInput, UpdateVideoInput, UploadVideoCaptionInput, VaultSecretSummary, VaultSecretValue, VaultSummary, VerificationAttemptStatus, VerificationAttemptSummary, VerificationChannel, VerificationCheckResult, VideoCaptionStatus, VideoCaptionSummary, VideoDownloadStatus, VideoSignedToken, VideoStatus, VideoSummary, VideoUploadTicket, VideoWatermarkPosition, VideoWatermarkProfileSummary, VoyantCloudClientOptions, } from "./types.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EACV,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,EACzB,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EACV,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,EACzB,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -70,7 +70,7 @@ export class VoyantTransport {
|
|
|
70
70
|
this.apiKey = options.apiKey;
|
|
71
71
|
this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
|
|
72
72
|
this.defaultHeaders = options.headers;
|
|
73
|
-
this.fetchImpl = options.fetch ?? fetch;
|
|
73
|
+
this.fetchImpl = options.fetch ?? fetch.bind(globalThis);
|
|
74
74
|
this.authHeader = options.authHeader ?? "authorization";
|
|
75
75
|
this.authScheme = options.authScheme === undefined ? "Bearer" : options.authScheme;
|
|
76
76
|
this.userAgent = options.userAgent ?? "voyant-sdk";
|