@cosmoner/sdk 1.2.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/README.md +178 -0
- package/dist/client.d.ts +28 -0
- package/dist/config.d.ts +35 -0
- package/dist/deployment/spec.d.ts +108 -0
- package/dist/deployment/types.d.ts +85 -0
- package/dist/deployment/validate.d.ts +30 -0
- package/dist/errors.d.ts +76 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1004 -0
- package/dist/index.mjs +946 -0
- package/dist/retry.d.ts +39 -0
- package/dist/services/email.d.ts +33 -0
- package/dist/services/webhooks.d.ts +190 -0
- package/dist/transport.d.ts +29 -0
- package/dist/version.d.ts +12 -0
- package/dist/webhooks/signature.d.ts +48 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# @cosmoner/sdk
|
|
2
|
+
|
|
3
|
+
Official Cosmoner SDK for Node.js.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @cosmoner/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Cosmoner } from "@cosmoner/sdk";
|
|
15
|
+
|
|
16
|
+
const client = new Cosmoner({
|
|
17
|
+
apiKey: "your-api-key",
|
|
18
|
+
projectId: "your-project-id",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Send to a single recipient
|
|
22
|
+
const result = await client.email.send({
|
|
23
|
+
credentialId: "your-credential-id",
|
|
24
|
+
to: "recipient@example.com",
|
|
25
|
+
subject: "Hello from Cosmoner",
|
|
26
|
+
html: "<h1>Hello!</h1><p>This is a test email.</p>",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log(result.data.messageId);
|
|
30
|
+
|
|
31
|
+
// Send to multiple recipients (up to 50)
|
|
32
|
+
await client.email.send({
|
|
33
|
+
credentialId: "your-credential-id",
|
|
34
|
+
to: ["alice@example.com", "bob@example.com"],
|
|
35
|
+
subject: "Team Update",
|
|
36
|
+
text: "Plain text email body",
|
|
37
|
+
replyTo: "noreply@yourdomain.com",
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
| Option | Required | Default | Description |
|
|
44
|
+
| ------------ | -------- | -------------------------- | -------------------------------------------------- |
|
|
45
|
+
| `apiKey` | Yes | — | Your Cosmoner API key |
|
|
46
|
+
| `projectId` | No | — | Default project; can also be passed per call |
|
|
47
|
+
| `baseUrl` | No | `https://api.cosmoner.com` | API base URL override |
|
|
48
|
+
| `timeout` | No | `30000` | Per-request timeout in milliseconds |
|
|
49
|
+
| `maxRetries` | No | `2` | Retries for transient failures (see [Retries](#retries)) |
|
|
50
|
+
|
|
51
|
+
`projectId` is optional so one client can span projects. Pass it per call to
|
|
52
|
+
override the default:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const client = new Cosmoner({ apiKey: "your-api-key" });
|
|
56
|
+
|
|
57
|
+
await client.email.send({ projectId: "proj-2", credentialId: "...", to: "...", subject: "...", text: "..." });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Retries
|
|
61
|
+
|
|
62
|
+
Transient failures are retried automatically with exponential backoff and full
|
|
63
|
+
jitter, honouring `Retry-After` when the API sends it.
|
|
64
|
+
|
|
65
|
+
- **429** is always retried — the request was rejected before it was processed,
|
|
66
|
+
so replaying it cannot duplicate a side effect.
|
|
67
|
+
- **Timeouts and 5xx** are retried only for idempotent methods. A write such as
|
|
68
|
+
`email.send` is *not* replayed, because the API may have completed the send
|
|
69
|
+
before failing to answer.
|
|
70
|
+
|
|
71
|
+
Set `maxRetries: 0` to disable retries entirely.
|
|
72
|
+
|
|
73
|
+
## Email
|
|
74
|
+
|
|
75
|
+
### `client.email.send(params)`
|
|
76
|
+
|
|
77
|
+
| Parameter | Type | Required | Description |
|
|
78
|
+
| -------------- | -------------------- | -------- | ------------------------------------ |
|
|
79
|
+
| `credentialId` | `string` | Yes | SMTP credential ID |
|
|
80
|
+
| `to` | `string \| string[]` | Yes | Recipient(s), max 50 |
|
|
81
|
+
| `subject` | `string` | Yes | Email subject line |
|
|
82
|
+
| `html` | `string` | No* | HTML body |
|
|
83
|
+
| `text` | `string` | No* | Plain text body |
|
|
84
|
+
| `replyTo` | `string \| string[]` | No | Reply-to address(es), max 5 |
|
|
85
|
+
| `projectId` | `string` | No | Overrides the client-level project |
|
|
86
|
+
|
|
87
|
+
\* At least one of `html` or `text` must be provided.
|
|
88
|
+
|
|
89
|
+
## Deployment files
|
|
90
|
+
|
|
91
|
+
Validates a `.cosmoner/deployment.yaml` — the file you commit to describe how a
|
|
92
|
+
repository deploys — without an API key or a network call.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { validateDeployment } from "@cosmoner/sdk";
|
|
96
|
+
import { readFileSync } from "node:fs";
|
|
97
|
+
|
|
98
|
+
const { valid, issues, template } = validateDeployment(
|
|
99
|
+
readFileSync(".cosmoner/deployment.yaml", "utf8")
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
for (const issue of issues) {
|
|
103
|
+
console.log(`${issue.severity} ${issue.path}: ${issue.message}`);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
error services.0.run_command: Static sites cannot define a run_command
|
|
109
|
+
warning services.0.prot: Unknown field "prot" — it will be ignored
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Warnings are things the platform tolerates and you probably did not mean. An
|
|
113
|
+
unknown key is the main one: the platform drops it rather than rejecting the
|
|
114
|
+
file, so a template written for a newer field still applies its known settings
|
|
115
|
+
against an older deploy. Treating that as fatal here would reject files the
|
|
116
|
+
platform accepts, so it is reported as a warning that names the consequence.
|
|
117
|
+
Pass `strict` when you would rather not let a typo through — it changes the
|
|
118
|
+
verdict, not the finding.
|
|
119
|
+
|
|
120
|
+
`template` is the file as the platform reads it: defaults applied, unknown keys
|
|
121
|
+
dropped. Comparing it against what you wrote is the point — it is the settings
|
|
122
|
+
that will actually arrive.
|
|
123
|
+
|
|
124
|
+
The same check is available on the command line, for CI or a pre-commit hook,
|
|
125
|
+
without installing anything:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npx @cosmoner/cli validate --strict
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### `validateDeployment(source, options?)`
|
|
132
|
+
|
|
133
|
+
| Parameter | Type | |
|
|
134
|
+
| --- | --- | --- |
|
|
135
|
+
| `source` | `string` | The file as written — raw text, not a parsed object. |
|
|
136
|
+
| `options.strict` | `boolean` | Treat warnings as errors. Defaults to `false`. |
|
|
137
|
+
|
|
138
|
+
Returns `{ valid, issues, template }`. `validateDeploymentDocument(document,
|
|
139
|
+
options?)` is the same check over an already-parsed object, for a file that was
|
|
140
|
+
generated rather than read from disk.
|
|
141
|
+
|
|
142
|
+
`DEPLOYMENT_FILE_PATHS` lists the locations the platform checks, in the order it
|
|
143
|
+
checks them, and `APP_SCHEMA_URL` is the published JSON Schema an editor can be
|
|
144
|
+
pointed at.
|
|
145
|
+
|
|
146
|
+
## Error Handling
|
|
147
|
+
|
|
148
|
+
Every failure throws a subclass of `CosmonerError`, so you can catch broadly or
|
|
149
|
+
narrowly:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { Cosmoner, CosmonerError, RateLimitError } from "@cosmoner/sdk";
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
await client.email.send({ ... });
|
|
156
|
+
} catch (err) {
|
|
157
|
+
if (err instanceof RateLimitError) {
|
|
158
|
+
console.error(err.retryAfter); // seconds, when the API supplies it
|
|
159
|
+
} else if (err instanceof CosmonerError) {
|
|
160
|
+
console.error(err.code); // e.g. "INSUFFICIENT_SCOPE"
|
|
161
|
+
console.error(err.status); // e.g. 403
|
|
162
|
+
console.error(err.details); // field-level validation errors, when present
|
|
163
|
+
console.error(err.message); // Human-readable message
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Error | Thrown on |
|
|
169
|
+
| ------------------------- | --------------------------------------------- |
|
|
170
|
+
| `ValidationError` | 400, 422 |
|
|
171
|
+
| `AuthenticationError` | 401 |
|
|
172
|
+
| `InsufficientScopeError` | 403 — API key is missing a `resource:action` |
|
|
173
|
+
| `NotFoundError` | 404 |
|
|
174
|
+
| `ConflictError` | 409 |
|
|
175
|
+
| `RateLimitError` | 429 |
|
|
176
|
+
| `ServerError` | 5xx |
|
|
177
|
+
| `CosmonerTimeoutError` | Request exceeded `timeout` |
|
|
178
|
+
| `CosmonerConnectionError` | DNS, TCP, TLS or socket failure |
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Entry-point client exposing the API's service namespaces. */
|
|
2
|
+
import { type CosmonerConfig } from "./config";
|
|
3
|
+
import { EmailService } from "./services/email";
|
|
4
|
+
import { WebhooksService } from "./services/webhooks";
|
|
5
|
+
/**
|
|
6
|
+
* Cosmoner API client.
|
|
7
|
+
*
|
|
8
|
+
* `projectId` is optional: set it here to make it the default for every call,
|
|
9
|
+
* or omit it and pass `projectId` per method to work across projects with one
|
|
10
|
+
* client.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Cosmoner {
|
|
13
|
+
/** @internal */
|
|
14
|
+
readonly apiKey: string;
|
|
15
|
+
/** @internal */
|
|
16
|
+
readonly projectId?: string;
|
|
17
|
+
/** @internal */
|
|
18
|
+
readonly baseUrl: string;
|
|
19
|
+
/** @internal */
|
|
20
|
+
readonly timeout: number;
|
|
21
|
+
/** @internal */
|
|
22
|
+
readonly maxRetries: number;
|
|
23
|
+
private readonly config;
|
|
24
|
+
private readonly transport;
|
|
25
|
+
readonly email: EmailService;
|
|
26
|
+
readonly webhooks: WebhooksService;
|
|
27
|
+
constructor(config: CosmonerConfig);
|
|
28
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Shared, validated configuration for the client and its service namespaces. */
|
|
2
|
+
export declare const DEFAULT_BASE_URL = "https://api.cosmoner.com";
|
|
3
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
4
|
+
export declare const DEFAULT_MAX_RETRIES = 2;
|
|
5
|
+
/** Options accepted by the `Cosmoner` constructor. */
|
|
6
|
+
export interface CosmonerConfig {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/**
|
|
9
|
+
* Default project for every call. Optional — omit it and pass `projectId`
|
|
10
|
+
* per method to work across projects with one client.
|
|
11
|
+
*/
|
|
12
|
+
projectId?: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/** Per-request timeout in milliseconds. Defaults to 30s. */
|
|
15
|
+
timeout?: number;
|
|
16
|
+
/** Retries per request for transient failures. Defaults to 2. */
|
|
17
|
+
maxRetries?: number;
|
|
18
|
+
}
|
|
19
|
+
/** Normalized, validated form of `CosmonerConfig`. */
|
|
20
|
+
export interface ResolvedConfig {
|
|
21
|
+
apiKey: string;
|
|
22
|
+
projectId?: string;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
timeout: number;
|
|
25
|
+
maxRetries: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates constructor arguments and normalizes them.
|
|
29
|
+
*
|
|
30
|
+
* An explicitly empty `projectId` is rejected rather than silently treated as
|
|
31
|
+
* unset — that almost always means an unresolved environment variable.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveConfig(config: CosmonerConfig): ResolvedConfig;
|
|
34
|
+
/** Returns the per-call project id, falling back to the client-level default. */
|
|
35
|
+
export declare function resolveProjectId(config: ResolvedConfig, override?: string): string;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field table for `.cosmoner/deployment.yaml`.
|
|
3
|
+
*
|
|
4
|
+
* The platform defines this format as a Zod schema and publishes the compiled
|
|
5
|
+
* JSON Schema at {@link APP_SCHEMA_URL}. This table is the third description of
|
|
6
|
+
* it, and the reason it exists rather than an off-the-shelf JSON Schema
|
|
7
|
+
* validator is in `schemas/README.md`: the rules worth catching in this file
|
|
8
|
+
* are cross-field ones that JSON Schema cannot state.
|
|
9
|
+
*
|
|
10
|
+
* Keywords are named exactly as JSON Schema names them — `minLength`,
|
|
11
|
+
* `maxLength`, `pattern`, `enum`, `minimum`, `maximum`, `minItems`, `maxItems`,
|
|
12
|
+
* `required`, `deprecated` — so `spec.drift.test.ts` can walk this table and the
|
|
13
|
+
* published document side by side and fail on the first difference. Renaming a
|
|
14
|
+
* key here to something more natural would cost that check, which is the only
|
|
15
|
+
* thing keeping this file honest.
|
|
16
|
+
*/
|
|
17
|
+
/** Where the platform serves the JSON Schema this table mirrors. */
|
|
18
|
+
export declare const APP_SCHEMA_URL = "https://cosmoner.com/schemas/app.schema.json";
|
|
19
|
+
/**
|
|
20
|
+
* The format version this SDK reads.
|
|
21
|
+
*
|
|
22
|
+
* A file may state its version, and one stating a version we do not know is
|
|
23
|
+
* refused rather than partially understood.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEPLOYMENT_VERSION = 1;
|
|
26
|
+
/** Files larger than this are refused rather than parsed, as the platform does. */
|
|
27
|
+
export declare const MAX_DEPLOYMENT_BYTES: number;
|
|
28
|
+
/**
|
|
29
|
+
* Where the platform looks for the file, in order, when a repository is
|
|
30
|
+
* selected in the deploy wizard. The first one that exists is the one that
|
|
31
|
+
* counts — a second copy further down this list is never read.
|
|
32
|
+
*
|
|
33
|
+
* `.datablock/app.*` is the original location. It is still read and still last,
|
|
34
|
+
* so apps already filled from it keep working; new files should not use it.
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEPLOYMENT_FILE_PATHS: readonly [".cosmoner/deployment.yaml", ".cosmoner/deployment.yml", "deployment.yaml", "deployment.yml", ".datablock/app.yaml", ".datablock/app.yml"];
|
|
37
|
+
/** Properties shared by every entry in a field table. */
|
|
38
|
+
interface FieldBase {
|
|
39
|
+
/** Absent is an error rather than "not set". */
|
|
40
|
+
required?: boolean;
|
|
41
|
+
/** Still read, but reported as a warning pointing at {@link replacedBy}. */
|
|
42
|
+
deprecated?: boolean;
|
|
43
|
+
/** The field that supersedes a deprecated one. Named in the warning. */
|
|
44
|
+
replacedBy?: string;
|
|
45
|
+
/** What the platform reads when the field is absent. */
|
|
46
|
+
default?: string | number;
|
|
47
|
+
}
|
|
48
|
+
/** One field's type and constraints. */
|
|
49
|
+
export type FieldSpec = FieldBase & ({
|
|
50
|
+
kind: "string";
|
|
51
|
+
minLength?: number;
|
|
52
|
+
maxLength?: number;
|
|
53
|
+
pattern?: RegExp;
|
|
54
|
+
/**
|
|
55
|
+
* Shown instead of a restatement of the pattern. A regex is not
|
|
56
|
+
* something to put in front of someone who mistyped a service name.
|
|
57
|
+
*/
|
|
58
|
+
patternMessage?: string;
|
|
59
|
+
enum?: readonly string[];
|
|
60
|
+
} | {
|
|
61
|
+
kind: "integer";
|
|
62
|
+
minimum: number;
|
|
63
|
+
maximum: number;
|
|
64
|
+
} | {
|
|
65
|
+
kind: "boolean";
|
|
66
|
+
}
|
|
67
|
+
/** A single accepted value, with its own message — see `version`. */
|
|
68
|
+
| {
|
|
69
|
+
kind: "const";
|
|
70
|
+
value: number;
|
|
71
|
+
message: string;
|
|
72
|
+
} | {
|
|
73
|
+
kind: "object";
|
|
74
|
+
fields: FieldTable;
|
|
75
|
+
} | {
|
|
76
|
+
kind: "array";
|
|
77
|
+
minItems?: number;
|
|
78
|
+
maxItems?: number;
|
|
79
|
+
/** Replaces the generic "at least N" wording. */
|
|
80
|
+
minItemsMessage?: string;
|
|
81
|
+
item: FieldSpec;
|
|
82
|
+
});
|
|
83
|
+
/** A mapping's fields, in the order they are validated and reported. */
|
|
84
|
+
export type FieldTable = Record<string, FieldSpec>;
|
|
85
|
+
/** Fields of one entry under a service's `envs`. */
|
|
86
|
+
export declare const ENV_FIELDS: FieldTable;
|
|
87
|
+
/** Fields of a service's `build` mapping. */
|
|
88
|
+
export declare const BUILD_FIELDS: FieldTable;
|
|
89
|
+
/** Fields of one entry under `services`. */
|
|
90
|
+
export declare const SERVICE_FIELDS: FieldTable;
|
|
91
|
+
/** Fields of the document itself. */
|
|
92
|
+
export declare const ROOT_FIELDS: FieldTable;
|
|
93
|
+
/**
|
|
94
|
+
* The order fields are written in, for tools that rewrite the file.
|
|
95
|
+
*
|
|
96
|
+
* Derived from the tables above rather than listed again, so a field added
|
|
97
|
+
* there cannot be left out of a formatter's ordering and silently sorted to the
|
|
98
|
+
* end. Exported because `@cosmoner/cli`'s `fmt` needs it and a second copy of
|
|
99
|
+
* this order living there is exactly the kind of drift the rest of this module
|
|
100
|
+
* exists to prevent.
|
|
101
|
+
*/
|
|
102
|
+
export declare const DEPLOYMENT_KEY_ORDER: {
|
|
103
|
+
readonly root: string[];
|
|
104
|
+
readonly service: string[];
|
|
105
|
+
readonly build: string[];
|
|
106
|
+
readonly env: string[];
|
|
107
|
+
};
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** The shape of a `.cosmoner/deployment.yaml` once it has been read. */
|
|
2
|
+
/** Severity of a single finding. */
|
|
3
|
+
export type DeploymentIssueSeverity = "error" | "warning";
|
|
4
|
+
/**
|
|
5
|
+
* One problem found in a deployment file.
|
|
6
|
+
*
|
|
7
|
+
* Warnings are things the platform tolerates and an author probably did not
|
|
8
|
+
* mean: a misspelled key that will be silently ignored, a field that still
|
|
9
|
+
* works but has been superseded. They do not make a file invalid, because a
|
|
10
|
+
* file written against a newer platform than this SDK knows about would
|
|
11
|
+
* otherwise fail for saying something perfectly correct.
|
|
12
|
+
*/
|
|
13
|
+
export interface DeploymentIssue {
|
|
14
|
+
/** Dot-joined location, with list indices — `services.0.envs.1.key`. `(root)` for the document. */
|
|
15
|
+
path: string;
|
|
16
|
+
message: string;
|
|
17
|
+
severity: DeploymentIssueSeverity;
|
|
18
|
+
}
|
|
19
|
+
/** One entry under a service's `envs`. */
|
|
20
|
+
export interface DeploymentEnvVar {
|
|
21
|
+
key: string;
|
|
22
|
+
/** Literal value, committed with the file. Only for non-sensitive configuration. */
|
|
23
|
+
value?: string;
|
|
24
|
+
/** Sensitive, with the value supplied in the wizard rather than committed. */
|
|
25
|
+
secret?: boolean;
|
|
26
|
+
/** Name of a project variable to link. */
|
|
27
|
+
from_variable?: string;
|
|
28
|
+
/** Name of a stored secret to link. The value never enters this file. */
|
|
29
|
+
from_secret?: string;
|
|
30
|
+
}
|
|
31
|
+
/** How a service is built. */
|
|
32
|
+
export interface DeploymentBuild {
|
|
33
|
+
strategy?: "nixpacks" | "docker";
|
|
34
|
+
command?: string;
|
|
35
|
+
/** Where a static build writes the site. Static sites only. */
|
|
36
|
+
output_dir?: string;
|
|
37
|
+
}
|
|
38
|
+
/** One service defined by the file. Each deploy sets up one of them. */
|
|
39
|
+
export interface DeploymentService {
|
|
40
|
+
name: string;
|
|
41
|
+
/** Defaulted to `service` when the file does not say. */
|
|
42
|
+
type: "service" | "static";
|
|
43
|
+
source_dir?: string;
|
|
44
|
+
build?: DeploymentBuild;
|
|
45
|
+
run_command?: string;
|
|
46
|
+
port?: number;
|
|
47
|
+
/** @deprecated Superseded by `port`, still read. */
|
|
48
|
+
http_port?: number;
|
|
49
|
+
/** @deprecated Superseded by `port`, still read. */
|
|
50
|
+
internal_port?: number;
|
|
51
|
+
instance_size?: string;
|
|
52
|
+
instances?: number;
|
|
53
|
+
autodeploy?: boolean;
|
|
54
|
+
envs?: DeploymentEnvVar[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A deployment file as the platform reads it: defaults applied, unknown keys
|
|
58
|
+
* dropped. Comparing this against what was written is the point — it is the
|
|
59
|
+
* settings that will actually arrive, not the ones in the file.
|
|
60
|
+
*/
|
|
61
|
+
export interface DeploymentTemplate {
|
|
62
|
+
$schema?: string;
|
|
63
|
+
version: number;
|
|
64
|
+
name?: string;
|
|
65
|
+
region?: string;
|
|
66
|
+
environment?: "default" | "development" | "staging" | "production";
|
|
67
|
+
services: DeploymentService[];
|
|
68
|
+
}
|
|
69
|
+
/** What {@link validateDeployment} reports. */
|
|
70
|
+
export interface DeploymentValidationResult {
|
|
71
|
+
/**
|
|
72
|
+
* No errors were found. Warnings do not clear this flag unless the check ran
|
|
73
|
+
* with `strict`.
|
|
74
|
+
*/
|
|
75
|
+
valid: boolean;
|
|
76
|
+
/** Every finding, in document order. */
|
|
77
|
+
issues: DeploymentIssue[];
|
|
78
|
+
/** The parsed file, or `null` when it could not be read as one. */
|
|
79
|
+
template: DeploymentTemplate | null;
|
|
80
|
+
}
|
|
81
|
+
/** Options for {@link validateDeployment}. */
|
|
82
|
+
export interface ValidateDeploymentOptions {
|
|
83
|
+
/** Treat warnings as errors, for a CI check that should not let typos through. */
|
|
84
|
+
strict?: boolean;
|
|
85
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation of `.cosmoner/deployment.yaml`, the one file customers write by
|
|
3
|
+
* hand for Cosmoner.
|
|
4
|
+
*
|
|
5
|
+
* Entirely local: no API key, no network, nothing about it that needs a
|
|
6
|
+
* `Cosmoner` client. It is here rather than only in the CLI so the same check
|
|
7
|
+
* can run inside a script that generates the file.
|
|
8
|
+
*
|
|
9
|
+
* What it reports is what the platform will do with the file, which is not the
|
|
10
|
+
* same as what the file says. The platform's parser is deliberately lenient —
|
|
11
|
+
* an unknown key is dropped so that a file written for a newer field still
|
|
12
|
+
* applies its known settings against an older deploy — so an unknown key here
|
|
13
|
+
* is a warning naming the consequence, and `template` comes back holding the
|
|
14
|
+
* settings that will actually arrive.
|
|
15
|
+
*/
|
|
16
|
+
import type { DeploymentValidationResult, ValidateDeploymentOptions } from "./types";
|
|
17
|
+
/**
|
|
18
|
+
* Validates an already-parsed document.
|
|
19
|
+
*
|
|
20
|
+
* Use this when the file did not come from disk — generated from a template, or
|
|
21
|
+
* read out of a repository through some other client. {@link validateDeployment}
|
|
22
|
+
* is the same check with the YAML parsing in front of it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateDeploymentDocument(document: unknown, options?: ValidateDeploymentOptions): DeploymentValidationResult;
|
|
25
|
+
/**
|
|
26
|
+
* Reads and validates the contents of a deployment file.
|
|
27
|
+
*
|
|
28
|
+
* `source` is the file as written — the raw text, not a parsed object.
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateDeployment(source: string, options?: ValidateDeploymentOptions): DeploymentValidationResult;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Exception hierarchy raised by the SDK, mapped from API error responses. */
|
|
2
|
+
/** Extra context attached to an error when the API supplies it. */
|
|
3
|
+
export interface CosmonerErrorOptions {
|
|
4
|
+
details?: unknown;
|
|
5
|
+
requestId?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Base class for every error the SDK throws.
|
|
9
|
+
*
|
|
10
|
+
* Catching this catches all API and transport failures, so existing
|
|
11
|
+
* `catch (err) { if (err instanceof CosmonerError) }` blocks keep working as
|
|
12
|
+
* the hierarchy grows.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CosmonerError extends Error {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly status: number;
|
|
17
|
+
readonly details?: unknown;
|
|
18
|
+
readonly requestId?: string;
|
|
19
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions);
|
|
20
|
+
}
|
|
21
|
+
/** The request never produced a response (DNS, TCP, TLS or socket failure). */
|
|
22
|
+
export declare class CosmonerConnectionError extends CosmonerError {
|
|
23
|
+
constructor(message: string, code?: string);
|
|
24
|
+
}
|
|
25
|
+
/** The request exceeded the configured timeout. */
|
|
26
|
+
export declare class CosmonerTimeoutError extends CosmonerConnectionError {
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
/** 401 — the API key is missing, malformed or revoked. */
|
|
30
|
+
export declare class AuthenticationError extends CosmonerError {
|
|
31
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions);
|
|
32
|
+
}
|
|
33
|
+
/** 403 — the API key lacks the required `resource:action` permission. */
|
|
34
|
+
export declare class InsufficientScopeError extends CosmonerError {
|
|
35
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions);
|
|
36
|
+
}
|
|
37
|
+
/** 404 — the addressed resource does not exist or is not visible to this key. */
|
|
38
|
+
export declare class NotFoundError extends CosmonerError {
|
|
39
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions);
|
|
40
|
+
}
|
|
41
|
+
/** 409 — the request conflicts with the current state of the resource. */
|
|
42
|
+
export declare class ConflictError extends CosmonerError {
|
|
43
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions);
|
|
44
|
+
}
|
|
45
|
+
/** 400/422 — the request body or query failed server-side validation. */
|
|
46
|
+
export declare class ValidationError extends CosmonerError {
|
|
47
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions);
|
|
48
|
+
}
|
|
49
|
+
/** 429 — the caller exceeded a rate limit and should back off. */
|
|
50
|
+
export declare class RateLimitError extends CosmonerError {
|
|
51
|
+
readonly retryAfter?: number;
|
|
52
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions & {
|
|
53
|
+
retryAfter?: number;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** 5xx — the API failed to handle an otherwise valid request. */
|
|
57
|
+
export declare class ServerError extends CosmonerError {
|
|
58
|
+
constructor(status: number, code: string, message: string, options?: CosmonerErrorOptions);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A received webhook could not be verified against its signing secret.
|
|
62
|
+
*
|
|
63
|
+
* Unlike the rest of the hierarchy this never comes from an API response — it
|
|
64
|
+
* is raised locally while checking an inbound request, so it carries no
|
|
65
|
+
* meaningful HTTP status.
|
|
66
|
+
*/
|
|
67
|
+
export declare class WebhookSignatureError extends CosmonerError {
|
|
68
|
+
constructor(message: string);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Maps an error response onto the most specific error class available.
|
|
72
|
+
*
|
|
73
|
+
* Proxies and load balancers can return HTML or an empty body, so every field
|
|
74
|
+
* is read defensively.
|
|
75
|
+
*/
|
|
76
|
+
export declare function errorFromResponse(status: number, body: unknown, headers?: Headers, retryAfter?: number): CosmonerError;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Public entry point for the Cosmoner SDK. */
|
|
2
|
+
export { Cosmoner } from "./client";
|
|
3
|
+
export { DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, type CosmonerConfig, } from "./config";
|
|
4
|
+
export { AuthenticationError, ConflictError, CosmonerConnectionError, CosmonerError, CosmonerTimeoutError, InsufficientScopeError, NotFoundError, RateLimitError, ServerError, ValidationError, WebhookSignatureError, } from "./errors";
|
|
5
|
+
export { APP_SCHEMA_URL, DEPLOYMENT_FILE_PATHS, DEPLOYMENT_KEY_ORDER, DEPLOYMENT_VERSION, MAX_DEPLOYMENT_BYTES, } from "./deployment/spec";
|
|
6
|
+
export { validateDeployment, validateDeploymentDocument, } from "./deployment/validate";
|
|
7
|
+
export type { DeploymentBuild, DeploymentEnvVar, DeploymentIssue, DeploymentIssueSeverity, DeploymentService, DeploymentTemplate, DeploymentValidationResult, ValidateDeploymentOptions, } from "./deployment/types";
|
|
8
|
+
export { EmailService, type SendEmailParams, type SendEmailResponse, } from "./services/email";
|
|
9
|
+
export { WEBHOOK_EVENT_TYPES, WebhooksService, type CreateWebhookEndpointParams, type CreateWebhookEndpointResponse, type DeleteWebhookEndpointResponse, type GetWebhookEndpointResponse, type ListDeliveriesParams, type ListWebhookDeliveriesResponse, type ListWebhookEndpointsResponse, type ReplayWebhookDeliveryResponse, type ResumeWebhookEndpointResponse, type RotateWebhookSecretResponse, type TestWebhookEndpointResponse, type UpdateWebhookEndpointParams, type UpdateWebhookEndpointResponse, type WebhookDelivery, type WebhookDeliveryStatus, type WebhookDisabledReason, type WebhookEndpoint, type WebhookEndpointStats, type WebhookEndpointWithSecret, type WebhookEventType, } from "./services/webhooks";
|
|
10
|
+
export { constructEvent, DEFAULT_TOLERANCE_SECONDS, DELIVERY_ID_HEADER, EVENT_TYPE_HEADER, SIGNATURE_HEADER, verifyWebhookSignature, type VerifyWebhookParams, type WebhookEvent, } from "./webhooks/signature";
|
|
11
|
+
export { VERSION } from "./version";
|
|
12
|
+
import { Cosmoner } from "./client";
|
|
13
|
+
export default Cosmoner;
|