@templr/sdk 0.1.0 → 0.3.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/CHANGELOG.md +23 -6
- package/README.md +36 -3
- package/dist/client.d.ts +6 -0
- package/dist/client.js +8 -0
- package/dist/index.d.ts +4 -2
- package/dist/resources/assets.d.ts +4 -0
- package/dist/resources/assets.js +3 -2
- package/dist/resources/audit-events.d.ts +30 -0
- package/dist/resources/audit-events.js +40 -0
- package/dist/resources/payments.d.ts +31 -0
- package/dist/resources/payments.js +41 -0
- package/dist/resources/templates.d.ts +11 -4
- package/dist/resources/templates.js +4 -4
- package/dist/schemas.d.ts +48 -0
- package/dist/schemas.js +38 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,20 +7,37 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-12-04
|
|
11
|
+
|
|
10
12
|
### Added
|
|
11
13
|
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
- `
|
|
14
|
+
- `name` option in `assets.upload` and `assets.createUpload`: the file name shown in the workspace audit log.
|
|
15
|
+
`upload` sends the name of a `File` by default.
|
|
16
|
+
- `name` field in `Asset` (`null` when the image was uploaded without one, or by an instance that does not
|
|
17
|
+
return it).
|
|
18
|
+
- `auditEvents.list` and `auditEvents.listAll` to read the workspace audit log, newest first, with the
|
|
19
|
+
`AuditEvent` type. They require a key with the `audit` grant.
|
|
20
|
+
- `payments.list` and `payments.listAll` to read the payments of the workspace owner's subscription, newest
|
|
21
|
+
first, with the `Payment` type and the `receiptUrl` of each receipt. They require a key with the `billing`
|
|
22
|
+
grant, which only the workspace owner can give.
|
|
15
23
|
|
|
16
|
-
## [0.
|
|
24
|
+
## [0.2.0] - 2026-12-03
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- `order` option (`'desc'`, the default, or `'asc'`) in `templates.list` and `templates.listDrafts` to list the
|
|
29
|
+
oldest templates first, with the `SortOrder` and `ListTemplatesOptions` types.
|
|
30
|
+
|
|
31
|
+
## [0.1.0] - 2026-12-03
|
|
17
32
|
|
|
18
33
|
### Added
|
|
19
34
|
|
|
20
35
|
- `Templr` client for the Templr REST API v1, authenticated with a workspace API key. It runs anywhere
|
|
21
36
|
`fetch` exists: Node.js 20.19+, Bun, Deno and edge runtimes.
|
|
22
|
-
- Templates: `list`, `listDrafts`, `get`, `getDraft` and `
|
|
23
|
-
- Assets: `list`, `createUpload`, `confirm` and `delete`.
|
|
37
|
+
- Templates: `list`, `listDrafts`, `get`, `getDraft`, `render`, `listVariables` and `updateVariable`.
|
|
38
|
+
- Assets: `list`, `upload`, `createUpload`, `confirm` and `delete`. `upload` starts an upload, sends the file
|
|
39
|
+
to the storage bucket and confirms it in one call.
|
|
24
40
|
- `getOpenApiDocument` to read the OpenAPI document served by an instance.
|
|
25
41
|
- Responses validated with Zod, returned as frozen objects with `Date` timestamps.
|
|
26
42
|
- Typed errors with a machine-readable `code`, one class per HTTP status family.
|
|
43
|
+
- `UploadError`, thrown when the storage bucket rejects the file of an upload.
|
package/README.md
CHANGED
|
@@ -49,6 +49,9 @@ Templr under the workspace settings.
|
|
|
49
49
|
|
|
50
50
|
- A `read` key can list, get and render templates, and list images.
|
|
51
51
|
- A `write` key can also upload and delete images.
|
|
52
|
+
- A key with the `audit` grant (given by an owner or admin when creating it) can also list the audit log.
|
|
53
|
+
- A key with the `billing` grant (given only by the workspace owner when creating it) can also list the payments
|
|
54
|
+
of the owner's subscription.
|
|
52
55
|
|
|
53
56
|
Keys have a fixed expiration and are never renewed automatically. Keep them secret: use the SDK only on
|
|
54
57
|
your server, never in a browser or mobile app, and read the key from the environment instead of
|
|
@@ -74,6 +77,9 @@ for (const version of page.items) {
|
|
|
74
77
|
// Every template with its draft, most recently updated first
|
|
75
78
|
const drafts = await templr.templates.listDrafts();
|
|
76
79
|
|
|
80
|
+
// Oldest first: `order: 'asc'` (the default is 'desc')
|
|
81
|
+
const oldest = await templr.templates.list({ order: 'asc' });
|
|
82
|
+
|
|
77
83
|
// One template, with its document
|
|
78
84
|
const version = await templr.templates.get(templateId); // latest published version
|
|
79
85
|
const draft = await templr.templates.getDraft(templateId); // draft
|
|
@@ -101,7 +107,8 @@ const variable = await templr.templates.updateVariable(templateId, 'name', { fal
|
|
|
101
107
|
### Pagination
|
|
102
108
|
|
|
103
109
|
Lists return a `Page` with `items`, `total` (the size of the whole list) and `nextCursor`, which is
|
|
104
|
-
`null` on the last page.
|
|
110
|
+
`null` on the last page. When listing templates with `order`, pass the same `order` with each
|
|
111
|
+
`cursor`.
|
|
105
112
|
|
|
106
113
|
```ts
|
|
107
114
|
let cursor: string | undefined;
|
|
@@ -118,12 +125,13 @@ do {
|
|
|
118
125
|
|
|
119
126
|
`upload` starts the upload, sends the file straight to the storage bucket and confirms it. It requires a
|
|
120
127
|
`write` key; accepted types are gif, jpeg, png and webp, up to 5 MiB. The file can be a `Uint8Array`
|
|
121
|
-
(such as a Node.js `Buffer`) or a `Blob`.
|
|
128
|
+
(such as a Node.js `Buffer`) or a `Blob`. The optional `name` is the file name shown in the workspace audit
|
|
129
|
+
log; a `File` sends its own name.
|
|
122
130
|
|
|
123
131
|
```ts
|
|
124
132
|
import { readFile } from 'node:fs/promises';
|
|
125
133
|
|
|
126
|
-
const asset = await templr.assets.upload(await readFile('logo.png'), { contentType: 'image/png' });
|
|
134
|
+
const asset = await templr.assets.upload(await readFile('logo.png'), { contentType: 'image/png', name: 'logo.png' });
|
|
127
135
|
console.log(asset.url);
|
|
128
136
|
```
|
|
129
137
|
|
|
@@ -151,6 +159,31 @@ const images = await templr.assets.list();
|
|
|
151
159
|
await templr.assets.delete(asset.id); // Templates that use it will show a broken image
|
|
152
160
|
```
|
|
153
161
|
|
|
162
|
+
### Audit log
|
|
163
|
+
|
|
164
|
+
With a key that has the `audit` grant, `auditEvents.list` returns one page of the workspace audit log,
|
|
165
|
+
newest first, and `auditEvents.listAll` iterates over every event, page by page. In the cloud only the
|
|
166
|
+
events within the audit history of the workspace owner's plan are listed.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
for await (const event of templr.auditEvents.listAll({ limit: 100 })) {
|
|
170
|
+
console.log(event.createdAt, event.actor.type, event.action, event.resourceType, event.metadata);
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Payments
|
|
175
|
+
|
|
176
|
+
With a key that has the `billing` grant, `payments.list` returns one page of the payments of the workspace
|
|
177
|
+
owner's subscription, newest first, and `payments.listAll` iterates over every payment, page by page. Each
|
|
178
|
+
payment has a `receiptUrl` that opens its receipt in the app, where the owner can print it as PDF (`null` when
|
|
179
|
+
the payment has no receipt: only approved payments get one).
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
for await (const payment of templr.payments.listAll({ limit: 100 })) {
|
|
183
|
+
console.log(payment.paidAt ?? payment.createdAt, payment.status, payment.amount, payment.currency, payment.receiptUrl);
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
154
187
|
## Error handling
|
|
155
188
|
|
|
156
189
|
Every error thrown by the SDK extends `TemplrError` and has a machine-readable `code`. Errors returned by
|
package/dist/client.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import { Assets } from './resources/assets.js';
|
|
7
|
+
import { AuditEvents } from './resources/audit-events.js';
|
|
8
|
+
import { Payments } from './resources/payments.js';
|
|
7
9
|
import { Templates } from './resources/templates.js';
|
|
8
10
|
import { type OpenApiDocument } from './schemas.js';
|
|
9
11
|
import { type Fetch } from './transport.js';
|
|
@@ -36,6 +38,10 @@ export declare class Templr {
|
|
|
36
38
|
readonly templates: Templates;
|
|
37
39
|
/** Upload, list and delete images. */
|
|
38
40
|
readonly assets: Assets;
|
|
41
|
+
/** Read the audit log; requires a key with the `audit` grant. */
|
|
42
|
+
readonly auditEvents: AuditEvents;
|
|
43
|
+
/** Read the payments of the workspace owner's subscription; requires a key with the `billing` grant. */
|
|
44
|
+
readonly payments: Payments;
|
|
39
45
|
/**
|
|
40
46
|
* Creates a client.
|
|
41
47
|
*
|
package/dist/client.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import { Assets } from './resources/assets.js';
|
|
7
|
+
import { AuditEvents } from './resources/audit-events.js';
|
|
8
|
+
import { Payments } from './resources/payments.js';
|
|
7
9
|
import { Templates } from './resources/templates.js';
|
|
8
10
|
import { openApiDocumentSchema } from './schemas.js';
|
|
9
11
|
import { DEFAULT_TIMEOUT_MS, Transport } from './transport.js';
|
|
@@ -24,6 +26,10 @@ export class Templr {
|
|
|
24
26
|
templates;
|
|
25
27
|
/** Upload, list and delete images. */
|
|
26
28
|
assets;
|
|
29
|
+
/** Read the audit log; requires a key with the `audit` grant. */
|
|
30
|
+
auditEvents;
|
|
31
|
+
/** Read the payments of the workspace owner's subscription; requires a key with the `billing` grant. */
|
|
32
|
+
payments;
|
|
27
33
|
#transport;
|
|
28
34
|
/**
|
|
29
35
|
* Creates a client.
|
|
@@ -39,6 +45,8 @@ export class Templr {
|
|
|
39
45
|
});
|
|
40
46
|
this.templates = new Templates(this.#transport);
|
|
41
47
|
this.assets = new Assets(this.#transport);
|
|
48
|
+
this.auditEvents = new AuditEvents(this.#transport);
|
|
49
|
+
this.payments = new Payments(this.#transport);
|
|
42
50
|
}
|
|
43
51
|
/** Gets the OpenAPI 3.1 document of the API served by this instance. */
|
|
44
52
|
getOpenApiDocument() {
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
export { Templr, type TemplrOptions } from './client.js';
|
|
16
16
|
export { APIConnectionError, APIError, type APIErrorDetails, APITimeoutError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PayloadTooLargeError, PermissionDeniedError, RateLimitError, TemplrError, UnexpectedResponseError, UploadError, } from './errors.js';
|
|
17
17
|
export type { Assets, CreateUploadOptions, UploadOptions } from './resources/assets.js';
|
|
18
|
-
export type {
|
|
19
|
-
export type {
|
|
18
|
+
export type { AuditEvents } from './resources/audit-events.js';
|
|
19
|
+
export type { Payments } from './resources/payments.js';
|
|
20
|
+
export type { ListOptions, ListTemplatesOptions, ListVariablesOptions, RenderOptions, SortOrder, Templates, UpdateVariableOptions } from './resources/templates.js';
|
|
21
|
+
export type { Asset, AssetUpload, AuditEvent, Deleted, ImageContentType, JsonValue, OpenApiDocument, Page, Payment, PresignedUpload, RenderedTemplate, Template, TemplateDocument, TemplateMark, TemplateNode, TemplateSummary, TemplateVariable, TemplateVersion, TemplateVersionSummary, } from './schemas.js';
|
|
20
22
|
export type { Fetch } from './transport.js';
|
|
21
23
|
export { VERSION } from './version.js';
|
|
@@ -10,11 +10,15 @@ import type { ListOptions } from './templates.js';
|
|
|
10
10
|
export interface UploadOptions {
|
|
11
11
|
/** The image type. */
|
|
12
12
|
readonly contentType: ImageContentType;
|
|
13
|
+
/** The file name shown in the audit log, e.g. `logo.png`. Defaults to the name of a `File`. */
|
|
14
|
+
readonly name?: string;
|
|
13
15
|
}
|
|
14
16
|
/** Options of {@link Assets.createUpload}. */
|
|
15
17
|
export interface CreateUploadOptions {
|
|
16
18
|
/** The image type. */
|
|
17
19
|
readonly contentType: ImageContentType;
|
|
20
|
+
/** The file name shown in the audit log, e.g. `logo.png` (at most 255 characters). */
|
|
21
|
+
readonly name?: string;
|
|
18
22
|
/** The exact size of the file, in bytes (at most 5 MiB). */
|
|
19
23
|
readonly sizeBytes: number;
|
|
20
24
|
}
|
package/dist/resources/assets.js
CHANGED
|
@@ -34,7 +34,8 @@ export class Assets {
|
|
|
34
34
|
*/
|
|
35
35
|
async upload(file, options) {
|
|
36
36
|
const sizeBytes = file instanceof Blob ? file.size : file.byteLength;
|
|
37
|
-
const
|
|
37
|
+
const name = options.name ?? (file instanceof File ? file.name : undefined);
|
|
38
|
+
const upload = await this.createUpload({ contentType: options.contentType, sizeBytes, ...(name === undefined ? {} : { name }) });
|
|
38
39
|
await this.#transport.upload({ contentType: options.contentType, fields: upload.upload.fields, file, url: upload.upload.url });
|
|
39
40
|
return this.confirm(upload.assetId);
|
|
40
41
|
}
|
|
@@ -46,7 +47,7 @@ export class Assets {
|
|
|
46
47
|
* {@link Assets.confirm}.
|
|
47
48
|
*/
|
|
48
49
|
createUpload(options) {
|
|
49
|
-
return this.#transport.send({ body: { contentType: options.contentType, sizeBytes: options.sizeBytes }, method: 'POST', path: '/api/v1/assets' }, assetUploadSchema);
|
|
50
|
+
return this.#transport.send({ body: { contentType: options.contentType, sizeBytes: options.sizeBytes, ...(options.name === undefined ? {} : { name: options.name }) }, method: 'POST', path: '/api/v1/assets' }, assetUploadSchema);
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
53
|
* Confirms an upload once the file is uploaded. Confirming twice is harmless. Requires a `write` API key.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `auditEvents` resource: read the workspace audit log.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type AuditEvent, type Page } from '../schemas.js';
|
|
7
|
+
import type { Transport } from '../transport.js';
|
|
8
|
+
import type { ListOptions } from './templates.js';
|
|
9
|
+
/**
|
|
10
|
+
* The audit log of the workspace: who did what, newest first. Requires an
|
|
11
|
+
* API key with the `audit` grant. In the cloud only the events within the
|
|
12
|
+
* audit history of the workspace owner's plan are listed.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AuditEvents {
|
|
15
|
+
#private;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor(transport: Transport);
|
|
18
|
+
/** Lists one page of events, newest first. */
|
|
19
|
+
list(options?: ListOptions): Promise<Page<AuditEvent>>;
|
|
20
|
+
/**
|
|
21
|
+
* Iterates over every event, newest first, requesting the next page when
|
|
22
|
+
* the previous one is used up.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* for await (const event of templr.auditEvents.listAll({ limit: 100 })) console.log(event.action);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
listAll(options?: Omit<ListOptions, 'cursor'>): AsyncGenerator<AuditEvent, void, undefined>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `auditEvents` resource: read the workspace audit log.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { auditEventSchema, pageSchema } from '../schemas.js';
|
|
7
|
+
const auditEventPage = pageSchema(auditEventSchema);
|
|
8
|
+
/**
|
|
9
|
+
* The audit log of the workspace: who did what, newest first. Requires an
|
|
10
|
+
* API key with the `audit` grant. In the cloud only the events within the
|
|
11
|
+
* audit history of the workspace owner's plan are listed.
|
|
12
|
+
*/
|
|
13
|
+
export class AuditEvents {
|
|
14
|
+
#transport;
|
|
15
|
+
/** @internal */
|
|
16
|
+
constructor(transport) {
|
|
17
|
+
this.#transport = transport;
|
|
18
|
+
}
|
|
19
|
+
/** Lists one page of events, newest first. */
|
|
20
|
+
list(options = {}) {
|
|
21
|
+
return this.#transport.send({ method: 'GET', path: '/api/v1/audit-events', query: { cursor: options.cursor, limit: options.limit } }, auditEventPage);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Iterates over every event, newest first, requesting the next page when
|
|
25
|
+
* the previous one is used up.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* for await (const event of templr.auditEvents.listAll({ limit: 100 })) console.log(event.action);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
async *listAll(options = {}) {
|
|
33
|
+
let cursor;
|
|
34
|
+
do {
|
|
35
|
+
const page = await this.list(cursor === undefined ? options : { ...options, cursor });
|
|
36
|
+
yield* page.items;
|
|
37
|
+
cursor = page.nextCursor ?? undefined;
|
|
38
|
+
} while (cursor !== undefined);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `payments` resource: read the payments of the subscription of the
|
|
3
|
+
* workspace owner.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type Page, type Payment } from '../schemas.js';
|
|
8
|
+
import type { Transport } from '../transport.js';
|
|
9
|
+
import type { ListOptions } from './templates.js';
|
|
10
|
+
/**
|
|
11
|
+
* The payments of the workspace owner's subscription, newest first, each
|
|
12
|
+
* with the link to its receipt in the app. Requires an API key with the
|
|
13
|
+
* `billing` grant, which only the workspace owner can give.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Payments {
|
|
16
|
+
#private;
|
|
17
|
+
/** @internal */
|
|
18
|
+
constructor(transport: Transport);
|
|
19
|
+
/** Lists one page of payments, newest first. */
|
|
20
|
+
list(options?: ListOptions): Promise<Page<Payment>>;
|
|
21
|
+
/**
|
|
22
|
+
* Iterates over every payment, newest first, requesting the next page when
|
|
23
|
+
* the previous one is used up.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* for await (const payment of templr.payments.listAll({ limit: 100 })) console.log(payment.status, payment.receiptUrl);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
listAll(options?: Omit<ListOptions, 'cursor'>): AsyncGenerator<Payment, void, undefined>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `payments` resource: read the payments of the subscription of the
|
|
3
|
+
* workspace owner.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { pageSchema, paymentSchema } from '../schemas.js';
|
|
8
|
+
const paymentPage = pageSchema(paymentSchema);
|
|
9
|
+
/**
|
|
10
|
+
* The payments of the workspace owner's subscription, newest first, each
|
|
11
|
+
* with the link to its receipt in the app. Requires an API key with the
|
|
12
|
+
* `billing` grant, which only the workspace owner can give.
|
|
13
|
+
*/
|
|
14
|
+
export class Payments {
|
|
15
|
+
#transport;
|
|
16
|
+
/** @internal */
|
|
17
|
+
constructor(transport) {
|
|
18
|
+
this.#transport = transport;
|
|
19
|
+
}
|
|
20
|
+
/** Lists one page of payments, newest first. */
|
|
21
|
+
list(options = {}) {
|
|
22
|
+
return this.#transport.send({ method: 'GET', path: '/api/v1/payments', query: { cursor: options.cursor, limit: options.limit } }, paymentPage);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Iterates over every payment, newest first, requesting the next page when
|
|
26
|
+
* the previous one is used up.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* for await (const payment of templr.payments.listAll({ limit: 100 })) console.log(payment.status, payment.receiptUrl);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
async *listAll(options = {}) {
|
|
34
|
+
let cursor;
|
|
35
|
+
do {
|
|
36
|
+
const page = await this.list(cursor === undefined ? options : { ...options, cursor });
|
|
37
|
+
yield* page.items;
|
|
38
|
+
cursor = page.nextCursor ?? undefined;
|
|
39
|
+
} while (cursor !== undefined);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -12,6 +12,13 @@ export interface ListOptions {
|
|
|
12
12
|
/** Items per page, from 1 to 100 (the API defaults to 20). */
|
|
13
13
|
readonly limit?: number;
|
|
14
14
|
}
|
|
15
|
+
/** The order of the template lists: newest first (`desc`, the default) or oldest first (`asc`). */
|
|
16
|
+
export type SortOrder = 'desc' | 'asc';
|
|
17
|
+
/** Options of {@link Templates.list} and {@link Templates.listDrafts}. */
|
|
18
|
+
export interface ListTemplatesOptions extends ListOptions {
|
|
19
|
+
/** `asc` lists the oldest first; keep the same order when passing `cursor`. The API defaults to `desc`. */
|
|
20
|
+
readonly order?: SortOrder;
|
|
21
|
+
}
|
|
15
22
|
/** Options of {@link Templates.render}. */
|
|
16
23
|
export interface RenderOptions {
|
|
17
24
|
/** Render the draft instead of the latest published version. */
|
|
@@ -41,10 +48,10 @@ export declare class Templates {
|
|
|
41
48
|
#private;
|
|
42
49
|
/** @internal */
|
|
43
50
|
constructor(transport: Transport);
|
|
44
|
-
/** Lists the published templates, each with its latest version, most recently published first. */
|
|
45
|
-
list(options?:
|
|
46
|
-
/** Lists every template with its draft, most recently updated first. */
|
|
47
|
-
listDrafts(options?:
|
|
51
|
+
/** Lists the published templates, each with its latest version, most recently published first (oldest first with `order: 'asc'`). */
|
|
52
|
+
list(options?: ListTemplatesOptions): Promise<Page<TemplateVersionSummary>>;
|
|
53
|
+
/** Lists every template with its draft, most recently updated first (oldest first with `order: 'asc'`). */
|
|
54
|
+
listDrafts(options?: ListTemplatesOptions): Promise<Page<TemplateSummary>>;
|
|
48
55
|
/**
|
|
49
56
|
* Gets the latest published version of a template, with its document.
|
|
50
57
|
*
|
|
@@ -19,13 +19,13 @@ export class Templates {
|
|
|
19
19
|
constructor(transport) {
|
|
20
20
|
this.#transport = transport;
|
|
21
21
|
}
|
|
22
|
-
/** Lists the published templates, each with its latest version, most recently published first. */
|
|
22
|
+
/** Lists the published templates, each with its latest version, most recently published first (oldest first with `order: 'asc'`). */
|
|
23
23
|
list(options = {}) {
|
|
24
|
-
return this.#transport.send({ method: 'GET', path: '/api/v1/templates', query: { cursor: options.cursor, limit: options.limit } }, versionPage);
|
|
24
|
+
return this.#transport.send({ method: 'GET', path: '/api/v1/templates', query: { cursor: options.cursor, limit: options.limit, order: options.order } }, versionPage);
|
|
25
25
|
}
|
|
26
|
-
/** Lists every template with its draft, most recently updated first. */
|
|
26
|
+
/** Lists every template with its draft, most recently updated first (oldest first with `order: 'asc'`). */
|
|
27
27
|
listDrafts(options = {}) {
|
|
28
|
-
return this.#transport.send({ method: 'GET', path: '/api/v1/templates', query: { cursor: options.cursor, draft: 'true', limit: options.limit } }, draftPage);
|
|
28
|
+
return this.#transport.send({ method: 'GET', path: '/api/v1/templates', query: { cursor: options.cursor, draft: 'true', limit: options.limit, order: options.order } }, draftPage);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Gets the latest published version of a template, with its document.
|
package/dist/schemas.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export declare const assetSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
89
89
|
contentType: z.ZodString;
|
|
90
90
|
createdAt: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
91
91
|
id: z.ZodString;
|
|
92
|
+
name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
92
93
|
sizeBytes: z.ZodNumber;
|
|
93
94
|
url: z.ZodString;
|
|
94
95
|
workspaceId: z.ZodString;
|
|
@@ -124,6 +125,34 @@ export declare function pageSchema<Item extends z.ZodType>(item: Item): z.ZodRea
|
|
|
124
125
|
nextCursor: z.ZodNullable<z.ZodString>;
|
|
125
126
|
total: z.ZodNumber;
|
|
126
127
|
}, z.core.$strip>>;
|
|
128
|
+
export declare const auditEventSchema: z.ZodReadonly<z.ZodObject<{
|
|
129
|
+
action: z.ZodString;
|
|
130
|
+
actor: z.ZodReadonly<z.ZodObject<{
|
|
131
|
+
id: z.ZodString;
|
|
132
|
+
type: z.ZodEnum<{
|
|
133
|
+
api_key: "api_key";
|
|
134
|
+
user: "user";
|
|
135
|
+
}>;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
createdAt: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
138
|
+
id: z.ZodString;
|
|
139
|
+
metadata: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
|
|
140
|
+
resourceExists: z.ZodBoolean;
|
|
141
|
+
resourceId: z.ZodString;
|
|
142
|
+
resourceType: z.ZodString;
|
|
143
|
+
}, z.core.$strip>>;
|
|
144
|
+
export declare const paymentSchema: z.ZodReadonly<z.ZodObject<{
|
|
145
|
+
amount: z.ZodNumber;
|
|
146
|
+
amountRefunded: z.ZodNumber;
|
|
147
|
+
cardLastFourDigits: z.ZodNullable<z.ZodString>;
|
|
148
|
+
createdAt: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
149
|
+
currency: z.ZodString;
|
|
150
|
+
id: z.ZodString;
|
|
151
|
+
paidAt: z.ZodNullable<z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>>;
|
|
152
|
+
paymentMethodId: z.ZodNullable<z.ZodString>;
|
|
153
|
+
receiptUrl: z.ZodNullable<z.ZodString>;
|
|
154
|
+
status: z.ZodString;
|
|
155
|
+
}, z.core.$strip>>;
|
|
127
156
|
/** The body of every error response. */
|
|
128
157
|
export declare const errorBodySchema: z.ZodObject<{
|
|
129
158
|
error: z.ZodObject<{
|
|
@@ -155,6 +184,25 @@ export type TemplateVariable = z.output<typeof templateVariableSchema>;
|
|
|
155
184
|
export type RenderedTemplate = z.output<typeof renderedTemplateSchema>;
|
|
156
185
|
/** An uploaded image with its public URL. */
|
|
157
186
|
export type Asset = z.output<typeof assetSchema>;
|
|
187
|
+
/**
|
|
188
|
+
* A recorded event of the workspace audit log: who did it (`actor`, a member
|
|
189
|
+
* by user id or an API key by key id), what happened (`action`, e.g.
|
|
190
|
+
* `template.published`), to which resource, and its non-secret details
|
|
191
|
+
* (`metadata`, which depend on the action). `resourceExists` tells whether a
|
|
192
|
+
* template or component still exists; it is always `false` for other resources.
|
|
193
|
+
*/
|
|
194
|
+
export type AuditEvent = z.output<typeof auditEventSchema>;
|
|
195
|
+
/**
|
|
196
|
+
* A payment of the workspace owner's subscription: its `amount`, the
|
|
197
|
+
* `amountRefunded` (`0` when nothing was refunded) and the `currency` (an ISO
|
|
198
|
+
* 4217 code, e.g. `USD`); the card brand (`paymentMethodId`, e.g. `visa`) and
|
|
199
|
+
* its last four digits, when known; its `status` as Mercado Pago reports it
|
|
200
|
+
* (e.g. `approved`, `rejected`, `refunded`); when it was created and, once
|
|
201
|
+
* approved, paid (`paidAt`). `receiptUrl` opens the receipt in the app, where
|
|
202
|
+
* the workspace owner can print it as PDF; it is `null` when the payment has
|
|
203
|
+
* no receipt (only approved payments get one).
|
|
204
|
+
*/
|
|
205
|
+
export type Payment = z.output<typeof paymentSchema>;
|
|
158
206
|
/**
|
|
159
207
|
* Where and how to upload the file of a pending image upload: send every
|
|
160
208
|
* entry of `fields`, then the file as the last field, as `multipart/form-data`
|
package/dist/schemas.js
CHANGED
|
@@ -47,7 +47,18 @@ export const templateVariableSchema = z.object({ fallback: z.string().nullable()
|
|
|
47
47
|
/** Every variable of a template, once per key, in document order. */
|
|
48
48
|
export const templateVariableListSchema = z.object({ items: z.array(templateVariableSchema).readonly() }).readonly();
|
|
49
49
|
/** An uploaded image with its public URL. */
|
|
50
|
-
export const assetSchema = z
|
|
50
|
+
export const assetSchema = z
|
|
51
|
+
.object({
|
|
52
|
+
contentType: z.string(),
|
|
53
|
+
createdAt: timestamp,
|
|
54
|
+
id: z.string(),
|
|
55
|
+
// Instances older than the file name return no `name`.
|
|
56
|
+
name: z.string().nullable().default(null),
|
|
57
|
+
sizeBytes: z.number().int(),
|
|
58
|
+
url: z.string(),
|
|
59
|
+
workspaceId: z.string(),
|
|
60
|
+
})
|
|
61
|
+
.readonly();
|
|
51
62
|
/** Where and how to upload the file of a pending image upload. */
|
|
52
63
|
export const presignedUploadSchema = z.object({ fields: z.record(z.string(), z.string()).readonly(), url: z.string() }).readonly();
|
|
53
64
|
/** A pending image upload. */
|
|
@@ -64,5 +75,31 @@ export const openApiDocumentSchema = z.record(z.string(), jsonValue).readonly();
|
|
|
64
75
|
export function pageSchema(item) {
|
|
65
76
|
return z.object({ items: z.array(item).readonly(), nextCursor: z.string().nullable(), total: z.number().int() }).readonly();
|
|
66
77
|
}
|
|
78
|
+
export const auditEventSchema = z
|
|
79
|
+
.object({
|
|
80
|
+
action: z.string(),
|
|
81
|
+
actor: z.object({ id: z.string(), type: z.enum(['user', 'api_key']) }).readonly(),
|
|
82
|
+
createdAt: timestamp,
|
|
83
|
+
id: z.string(),
|
|
84
|
+
metadata: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()])).readonly(),
|
|
85
|
+
resourceExists: z.boolean(),
|
|
86
|
+
resourceId: z.string(),
|
|
87
|
+
resourceType: z.string(),
|
|
88
|
+
})
|
|
89
|
+
.readonly();
|
|
90
|
+
export const paymentSchema = z
|
|
91
|
+
.object({
|
|
92
|
+
amount: z.number(),
|
|
93
|
+
amountRefunded: z.number(),
|
|
94
|
+
cardLastFourDigits: z.string().nullable(),
|
|
95
|
+
createdAt: timestamp,
|
|
96
|
+
currency: z.string(),
|
|
97
|
+
id: z.string(),
|
|
98
|
+
paidAt: timestamp.nullable(),
|
|
99
|
+
paymentMethodId: z.string().nullable(),
|
|
100
|
+
receiptUrl: z.string().nullable(),
|
|
101
|
+
status: z.string(),
|
|
102
|
+
})
|
|
103
|
+
.readonly();
|
|
67
104
|
/** The body of every error response. */
|
|
68
105
|
export const errorBodySchema = z.object({ error: z.object({ code: z.string(), issues: z.array(z.string()), message: z.string() }) });
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The version of this SDK; kept equal to `package.json` by a test. */
|
|
2
|
-
export declare const VERSION = "0.
|
|
2
|
+
export declare const VERSION = "0.3.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The version of this SDK; kept equal to `package.json` by a test. */
|
|
2
|
-
export const VERSION = '0.
|
|
2
|
+
export const VERSION = '0.3.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@templr/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Official TypeScript SDK for the Templr REST API.",
|
|
5
5
|
"keywords": ["templr", "email", "email-templates", "react-email", "sdk", "api-client"],
|
|
6
6
|
"homepage": "https://github.com/SebastianUrdaneguiBisalaya/templr/tree/main/sdks/typescript#readme",
|