-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnamed-transformations.ts
More file actions
161 lines (147 loc) · 5.46 KB
/
Copy pathnamed-transformations.ts
File metadata and controls
161 lines (147 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import * as Shared from './shared';
import { APIPromise } from '../core/api-promise';
import { buildHeaders } from '../internal/headers';
import { RequestOptions } from '../internal/request-options';
import { path } from '../internal/utils/path';
export class NamedTransformations extends APIResource {
/**
* Creates a new named transformation and returns the created object.
*
* A named transformation is a short, reusable name for a transformation string.
* Use it in image and video URLs as `tr:n-<name>`, and update the underlying
* transformation later without changing existing URLs. Learn more about
* [named transformations](https://imagekit.io/docs/transformations#named-transformations).
*
* You can create up to 250 named transformations per account.
*
* @example
* ```ts
* const namedTransformation =
* await client.namedTransformations.create({
* name: 'small_thumbnail',
* transformation: 'w-150,h-150,fo-center,cm-pad_resize',
* enabled: true,
* });
* ```
*/
create(
body: NamedTransformationCreateParams,
options?: RequestOptions,
): APIPromise<Shared.NamedTransformation> {
return this._client.post('/v1/named-transformations', { body, ...options });
}
/**
* Updates the named transformation identified by `id` and returns the updated
* object. Only the fields present in the request body are updated; other fields
* stay unchanged.
*
* Renaming or disabling a named transformation fails with a `409` error if it is
* still referenced (via the `n-<name>` token) by an upload pre-transformation or
* post-transformation setting. This check is best-effort and can't detect
* references in your own application code or in previously generated URLs.
*
* @example
* ```ts
* const namedTransformation =
* await client.namedTransformations.update('6bZ9x2ZUx', {
* transformation: 'w-200,h-200,fo-center,cm-pad_resize',
* });
* ```
*/
update(
id: string,
body: NamedTransformationUpdateParams,
options?: RequestOptions,
): APIPromise<Shared.NamedTransformation> {
return this._client.patch(path`/v1/named-transformations/${id}`, { body, ...options });
}
/**
* Returns an array of all named transformations configured for your account.
*
* @example
* ```ts
* const namedTransformations =
* await client.namedTransformations.list();
* ```
*/
list(options?: RequestOptions): APIPromise<NamedTransformationListResponse> {
return this._client.get('/v1/named-transformations', options);
}
/**
* Permanently deletes the named transformation identified by `id`.
*
* Deletion fails with a `409` error if the named transformation is still
* referenced (via the `n-<name>` token) by an upload pre-transformation or
* post-transformation setting. This check is best-effort and can't detect
* references in your own application code or in previously generated URLs.
*
* @example
* ```ts
* await client.namedTransformations.delete('6bZ9x2ZUx');
* ```
*/
delete(id: string, options?: RequestOptions): APIPromise<void> {
return this._client.delete(path`/v1/named-transformations/${id}`, {
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* Retrieves the named transformation identified by `id`.
*
* @example
* ```ts
* const namedTransformation =
* await client.namedTransformations.get('6bZ9x2ZUx');
* ```
*/
get(id: string, options?: RequestOptions): APIPromise<Shared.NamedTransformation> {
return this._client.get(path`/v1/named-transformations/${id}`, options);
}
}
export type NamedTransformationListResponse = Array<Shared.NamedTransformation>;
export interface NamedTransformationCreateParams {
/**
* Alias for the transformation string, used in URLs as `tr:n-<name>`. This is
* case-sensitive, contains only alphanumeric characters or `_` (underscore), and
* is unique across all named transformations for your account.
*/
name: string;
/**
* The transformation string this named transformation refers to. Learn more about
* the [transformation string syntax](https://imagekit.io/docs/transformations).
*/
transformation: string;
/**
* Whether the named transformation is currently enabled. When set to `false`,
* requests using this named transformation fail at delivery time.
*/
enabled?: boolean;
}
export interface NamedTransformationUpdateParams {
/**
* Whether the named transformation is enabled. Omit to leave the current value
* unchanged.
*/
enabled?: boolean;
/**
* Alias for the transformation string, used in URLs as `tr:n-<name>`. This is
* case-sensitive, contains only alphanumeric characters or `_` (underscore), and
* is unique across all named transformations for your account.
*/
name?: string;
/**
* The transformation string this named transformation refers to. Learn more about
* the [transformation string syntax](https://imagekit.io/docs/transformations).
*/
transformation?: string;
}
export declare namespace NamedTransformations {
export {
type NamedTransformationListResponse as NamedTransformationListResponse,
type NamedTransformationCreateParams as NamedTransformationCreateParams,
type NamedTransformationUpdateParams as NamedTransformationUpdateParams,
};
}