imejis 0.0.0-stage → 0.1.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/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +174 -2
- package/dist/index.cjs +939 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +328 -0
- package/dist/index.d.ts +328 -0
- package/dist/index.js +916 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- Released through npm trusted publishing (OIDC) from imejis/imejis-node, with provenance. No API changes.
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
First release.
|
|
10
|
+
|
|
11
|
+
- `Imejis` client (ESM and CommonJS, typed, no runtime dependencies), with an API key (render key) or an OAuth access token.
|
|
12
|
+
- `designs.list()`, `designs.iterate()`, `designs.search()`, `designs.config()`, `designs.fields()`, `designs.sizes()`.
|
|
13
|
+
- `render()` (bytes), `renderToUrl()` (public URL), `renderSignedUrl()` (expiring URL).
|
|
14
|
+
- `renderAllSizes()` and `renderBulk()` (up to 25 renders a call).
|
|
15
|
+
- Typed errors, retries with backoff, timeouts.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 imejis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,175 @@
|
|
|
1
|
-
#
|
|
1
|
+
# imejis for Node.js and TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official [imejis](https://imejis.io) SDK. Turn a design into an image with
|
|
4
|
+
your own text, images and data: get the bytes, a public URL, an expiring
|
|
5
|
+
signed URL, or every size of the design at once.
|
|
6
|
+
|
|
7
|
+
- Typed, ESM and CommonJS, no runtime dependencies
|
|
8
|
+
- Node 18+, Bun, Deno and edge runtimes (anything with `fetch`)
|
|
9
|
+
- Retries, timeouts and typed errors built in
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install imejis
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
Create a render key under **Settings > API keys** in imejis, and copy a
|
|
18
|
+
design's render code from its API panel (it looks like `etpd-V1CzPXpw`).
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { writeFile } from 'node:fs/promises';
|
|
22
|
+
import { Imejis } from 'imejis';
|
|
23
|
+
|
|
24
|
+
const imejis = new Imejis({ apiKey: process.env.IMEJIS_API_KEY });
|
|
25
|
+
|
|
26
|
+
const image = await imejis.render('etpd-V1CzPXpw', {
|
|
27
|
+
'title.text': 'Summer sale',
|
|
28
|
+
'photo.image': 'https://example.com/shoes.jpg',
|
|
29
|
+
});
|
|
30
|
+
await writeFile('sale.png', image.data);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`new Imejis()` with no arguments reads `IMEJIS_API_KEY` (or
|
|
34
|
+
`IMEJIS_ACCESS_TOKEN`) from the environment.
|
|
35
|
+
|
|
36
|
+
## Authentication
|
|
37
|
+
|
|
38
|
+
| Credential | Option | What it can do |
|
|
39
|
+
| ----------------- | ------------- | ------------------------------------------------------------------------ |
|
|
40
|
+
| Render key | `apiKey` | Render any design in its workspace |
|
|
41
|
+
| OAuth access token | `accessToken` | Everything: list and search designs, read fields and sizes, and render |
|
|
42
|
+
|
|
43
|
+
With an access token the SDK finds one of the account's render keys (or
|
|
44
|
+
creates one named `imejis SDK`) the first time it renders, and reuses it. Use
|
|
45
|
+
an access token when you act for an imejis user, for example in an app or an
|
|
46
|
+
AI agent that signed them in with OAuth; see
|
|
47
|
+
[api.imejis.io/auth.md](https://api.imejis.io/auth.md).
|
|
48
|
+
|
|
49
|
+
## Render
|
|
50
|
+
|
|
51
|
+
Overrides are keyed `layer.property`, the dot paths `designs.fields()`
|
|
52
|
+
returns. Nested objects work too: `{ title: { text: 'Hi', color: '#fff' } }`.
|
|
53
|
+
Anything you leave out keeps the design's value.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// Bytes (nothing stored)
|
|
57
|
+
const image = await imejis.render('etpd-V1CzPXpw', { 'title.text': 'Hi' }, {
|
|
58
|
+
format: 'jpeg', // png (default), jpeg, webp or pdf
|
|
59
|
+
quality: 85, // 1-100, for jpeg
|
|
60
|
+
size: 'story', // one of the design's sizes; omit for the main size
|
|
61
|
+
});
|
|
62
|
+
image.data; // Uint8Array
|
|
63
|
+
image.contentType; // 'image/jpeg'
|
|
64
|
+
image.warnings; // e.g. an override key that matched no layer
|
|
65
|
+
|
|
66
|
+
// A public, permanent URL hosted by imejis
|
|
67
|
+
const { url } = await imejis.renderToUrl('etpd-V1CzPXpw', { 'title.text': 'Hi' });
|
|
68
|
+
|
|
69
|
+
// A private URL that expires (minutes, 1 to 10080; default 60)
|
|
70
|
+
const signed = await imejis.renderSignedUrl('etpd-V1CzPXpw', {}, { expiresIn: 30 });
|
|
71
|
+
signed.url;
|
|
72
|
+
signed.expiresAt;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
With an access token you can pass the design id from `designs.list()`
|
|
76
|
+
instead of the render code; the SDK looks the code up once and caches it.
|
|
77
|
+
|
|
78
|
+
### Every size at once
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const result = await imejis.renderAllSizes('etpd-V1CzPXpw', { 'title.text': 'Hi' });
|
|
82
|
+
for (const r of result.results) {
|
|
83
|
+
console.log(r.size, r.ok ? r.url : r.error);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Without `sizes`, it renders the main size plus every other size of the
|
|
88
|
+
design. Name them to pick some: `{ sizes: ['master', 'story'] }`. Pass
|
|
89
|
+
`delivery: 'signed'` (and `expiresIn`) for expiring URLs.
|
|
90
|
+
|
|
91
|
+
### Bulk
|
|
92
|
+
|
|
93
|
+
Up to 25 renders of any designs, sizes and values in one call, returned in
|
|
94
|
+
input order. A failed item does not stop the others.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const batch = await imejis.renderBulk(
|
|
98
|
+
[
|
|
99
|
+
{ design: 'etpd-V1CzPXpw', overrides: { 'title.text': 'Alice' } },
|
|
100
|
+
{ design: 'etpd-V1CzPXpw', overrides: { 'title.text': 'Bob' }, size: 'story' },
|
|
101
|
+
],
|
|
102
|
+
{ format: 'webp' },
|
|
103
|
+
);
|
|
104
|
+
console.log(batch.succeeded, batch.failed);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Designs
|
|
108
|
+
|
|
109
|
+
These need an access token.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const page = await imejis.designs.list({ page: 1, limit: 50 }); // newest first
|
|
113
|
+
for await (const design of imejis.designs.iterate()) console.log(design.name);
|
|
114
|
+
|
|
115
|
+
const matches = await imejis.designs.search('summer sale'); // exact names first
|
|
116
|
+
|
|
117
|
+
const config = await imejis.designs.config(page.designs[0].id);
|
|
118
|
+
config.renderCode; // 'etpd-V1CzPXpw'
|
|
119
|
+
config.fields; // [{ key: 'title.text', kind: 'text', defaultValue: 'Hello', ... }]
|
|
120
|
+
config.sizes; // [{ id: 'master', name: 'Master', width: 1200, height: 630 }, ...]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Errors
|
|
124
|
+
|
|
125
|
+
Every failure is an `ImejisError` with `status`, `body` and `requestId`.
|
|
126
|
+
Catch the common cases by type:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { AuthenticationError, NotFoundError, RateLimitError } from 'imejis';
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
await imejis.render('etpd-V1CzPXpw');
|
|
133
|
+
} catch (err) {
|
|
134
|
+
if (err instanceof RateLimitError) {
|
|
135
|
+
// the workspace's render quota is used up
|
|
136
|
+
} else if (err instanceof NotFoundError) {
|
|
137
|
+
// wrong render code, or a design in another workspace
|
|
138
|
+
} else if (err instanceof AuthenticationError) {
|
|
139
|
+
// bad or expired key / token
|
|
140
|
+
} else throw err;
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
| Class | When |
|
|
145
|
+
| ----------------------- | ------------------------------------------------------- |
|
|
146
|
+
| `BadRequestError` | 400 |
|
|
147
|
+
| `AuthenticationError` | 401 |
|
|
148
|
+
| `PermissionDeniedError` | 403 |
|
|
149
|
+
| `NotFoundError` | 404 |
|
|
150
|
+
| `GoneError` | 410, a design from the retired editor |
|
|
151
|
+
| `RateLimitError` | 429, render quota used up |
|
|
152
|
+
| `InternalServerError` | 5xx |
|
|
153
|
+
| `ConnectionError` | no response; `TimeoutError` when `timeout` passed |
|
|
154
|
+
| `ImejisConfigError` | the SDK was called wrongly (checked before any request) |
|
|
155
|
+
|
|
156
|
+
## Options
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
new Imejis({
|
|
160
|
+
apiKey: '...',
|
|
161
|
+
accessToken: '...',
|
|
162
|
+
timeout: 60_000, // ms per request
|
|
163
|
+
maxRetries: 2, // network errors, 5xx, and 429 with Retry-After
|
|
164
|
+
renderKeyName: 'imejis SDK', // the key an access token reuses or creates
|
|
165
|
+
fetch: customFetch, // proxies, tests
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
A 429 for a spent render quota is not retried, since waiting a few seconds
|
|
170
|
+
cannot help. Each render (and each item of a bulk call) uses one render from
|
|
171
|
+
the workspace's quota; failed renders are refunded.
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|