@rixl/sdk 0.1.1 → 0.2.2
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 +161 -82
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,147 +1,226 @@
|
|
|
1
1
|
# @rixl/sdk
|
|
2
2
|
|
|
3
|
-
Official TypeScript / JavaScript SDK for the [Rixl](https://rixl.com) REST API
|
|
3
|
+
Official TypeScript / JavaScript SDK for the [Rixl](https://rixl.com) REST API.
|
|
4
|
+
|
|
5
|
+
Published on npm as [`@rixl/sdk`](https://www.npmjs.com/package/@rixl/sdk).
|
|
4
6
|
|
|
5
7
|
[](https://www.npmjs.com/package/@rixl/sdk)
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
| npm | pnpm | bun | vite plus |
|
|
12
|
+
| ----------------- | ------------------ | ----------------- | ---------------- |
|
|
13
|
+
| `npm i @rixl/sdk` | `pnpm i @rixl/sdk` | `bun i @rixl/sdk` | `vp i @rixl/sdk` |
|
|
12
14
|
|
|
13
|
-
Requires Node.js 18+. ESM only
|
|
15
|
+
Requires Node.js 18+. ESM only.
|
|
14
16
|
|
|
15
|
-
## Quick
|
|
17
|
+
## Quick Start
|
|
16
18
|
|
|
17
19
|
```ts
|
|
18
|
-
import {
|
|
19
|
-
import {FetchRequestAdapter} from "@microsoft/kiota-http-fetchlibrary";
|
|
20
|
-
import {ApiKeyAuthenticationProvider} from "@microsoft/kiota-abstractions";
|
|
20
|
+
import {createClient, getImages} from "@rixl/sdk";
|
|
21
21
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const client = createClient({
|
|
23
|
+
baseUrl: "https://api.rixl.com",
|
|
24
|
+
auth: process.env.RIXL_API_KEY,
|
|
25
|
+
responseStyle: "data",
|
|
26
|
+
});
|
|
25
27
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
+
const page = await getImages({
|
|
29
|
+
client,
|
|
30
|
+
query: {limit: 10},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
console.log(page.data?.map((image) => image.id));
|
|
28
34
|
```
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
`auth` can be either a string or a function, so you can plug in API keys, bearer tokens, or runtime token refresh logic.
|
|
31
37
|
|
|
32
|
-
##
|
|
38
|
+
## Feed API
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
Fetch a feed and read posts:
|
|
35
41
|
|
|
36
42
|
```ts
|
|
37
|
-
import {
|
|
43
|
+
import {createClient, getFeedsByFeedId} from "@rixl/sdk";
|
|
38
44
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
const client = createClient({
|
|
46
|
+
baseUrl: "https://api.rixl.com",
|
|
47
|
+
auth: process.env.RIXL_API_KEY,
|
|
48
|
+
responseStyle: "data",
|
|
49
|
+
});
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
const feed = await getFeedsByFeedId({
|
|
52
|
+
client,
|
|
53
|
+
path: {feedId: "FD4y3QB38S"},
|
|
54
|
+
query: {limit: 20, offset: 0},
|
|
55
|
+
});
|
|
45
56
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
for (const post of posts?.data ?? []) {
|
|
49
|
-
console.log(post.id);
|
|
57
|
+
for (const post of feed.data ?? []) {
|
|
58
|
+
console.log(post.id, post.type);
|
|
50
59
|
}
|
|
51
60
|
```
|
|
52
61
|
|
|
53
|
-
##
|
|
62
|
+
## Image API
|
|
63
|
+
|
|
64
|
+
List images and fetch one by ID:
|
|
54
65
|
|
|
55
66
|
```ts
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
import {createClient, getImages, getImagesByImageId} from "@rixl/sdk";
|
|
68
|
+
|
|
69
|
+
const client = createClient({
|
|
70
|
+
baseUrl: "https://api.rixl.com",
|
|
71
|
+
auth: process.env.RIXL_API_KEY,
|
|
72
|
+
responseStyle: "data",
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const page = await getImages({
|
|
76
|
+
client,
|
|
77
|
+
query: {limit: 25, offset: 0},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const image = await getImagesByImageId({
|
|
81
|
+
client,
|
|
82
|
+
path: {imageId: "PS5IMKoFLm"},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
console.log(page.data?.length, image.id, image.width, image.height);
|
|
59
86
|
```
|
|
60
87
|
|
|
61
|
-
|
|
88
|
+
Initialize an upload, PUT the bytes to storage, then complete the upload:
|
|
62
89
|
|
|
63
90
|
```ts
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
91
|
+
import {createClient, postImagesUploadComplete, postImagesUploadInit} from "@rixl/sdk";
|
|
92
|
+
|
|
93
|
+
const client = createClient({
|
|
94
|
+
baseUrl: "https://api.rixl.com",
|
|
95
|
+
auth: process.env.RIXL_API_KEY,
|
|
96
|
+
responseStyle: "data",
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const init = await postImagesUploadInit({
|
|
100
|
+
client,
|
|
101
|
+
body: {
|
|
102
|
+
name: "photo.jpg",
|
|
103
|
+
format: "jpeg",
|
|
104
|
+
},
|
|
67
105
|
});
|
|
68
106
|
|
|
69
|
-
await fetch(
|
|
107
|
+
await fetch(init.presigned_url!, {
|
|
70
108
|
method: "PUT",
|
|
71
109
|
body: imageBytes,
|
|
72
110
|
headers: {"Content-Type": "image/jpeg"},
|
|
73
111
|
});
|
|
74
112
|
|
|
75
|
-
const image = await
|
|
76
|
-
|
|
77
|
-
|
|
113
|
+
const image = await postImagesUploadComplete({
|
|
114
|
+
client,
|
|
115
|
+
body: {
|
|
116
|
+
image_id: init.image_id,
|
|
117
|
+
attached_to_video: false,
|
|
118
|
+
},
|
|
78
119
|
});
|
|
120
|
+
|
|
121
|
+
console.log(image.id);
|
|
79
122
|
```
|
|
80
123
|
|
|
81
|
-
##
|
|
124
|
+
## Video API
|
|
125
|
+
|
|
126
|
+
List videos and fetch one by ID:
|
|
82
127
|
|
|
83
128
|
```ts
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
129
|
+
import {createClient, getVideos, getVideosByVideoId} from "@rixl/sdk";
|
|
130
|
+
|
|
131
|
+
const client = createClient({
|
|
132
|
+
baseUrl: "https://api.rixl.com",
|
|
133
|
+
auth: process.env.RIXL_API_KEY,
|
|
134
|
+
responseStyle: "data",
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const page = await getVideos({
|
|
138
|
+
client,
|
|
139
|
+
query: {limit: 25, offset: 0},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const video = await getVideosByVideoId({
|
|
143
|
+
client,
|
|
144
|
+
path: {videoId: "VI9VXQxWXQ"},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
console.log(page.data?.length, video.id, video.duration);
|
|
87
148
|
```
|
|
88
149
|
|
|
89
|
-
|
|
150
|
+
Video uploads follow the same pattern, but `init` returns both video and poster upload URLs:
|
|
90
151
|
|
|
91
152
|
```ts
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
153
|
+
import {createClient, postVideosUploadComplete, postVideosUploadInit} from "@rixl/sdk";
|
|
154
|
+
|
|
155
|
+
const client = createClient({
|
|
156
|
+
baseUrl: "https://api.rixl.com",
|
|
157
|
+
auth: process.env.RIXL_API_KEY,
|
|
158
|
+
responseStyle: "data",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const init = await postVideosUploadInit({
|
|
162
|
+
client,
|
|
163
|
+
body: {
|
|
164
|
+
file_name: "clip.mp4",
|
|
165
|
+
image_format: "jpeg",
|
|
166
|
+
},
|
|
95
167
|
});
|
|
96
|
-
// PUT bytes to initRes.videoPresignedUrl and initRes.posterPresignedUrl
|
|
97
168
|
|
|
98
|
-
|
|
99
|
-
|
|
169
|
+
await Promise.all([
|
|
170
|
+
fetch(init.video_presigned_url!, {
|
|
171
|
+
method: "PUT",
|
|
172
|
+
body: videoBytes,
|
|
173
|
+
headers: {"Content-Type": "video/mp4"},
|
|
174
|
+
}),
|
|
175
|
+
fetch(init.poster_presigned_url!, {
|
|
176
|
+
method: "PUT",
|
|
177
|
+
body: posterBytes,
|
|
178
|
+
headers: {"Content-Type": "image/jpeg"},
|
|
179
|
+
}),
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
const video = await postVideosUploadComplete({
|
|
183
|
+
client,
|
|
184
|
+
body: {
|
|
185
|
+
video_id: init.video_id,
|
|
186
|
+
},
|
|
100
187
|
});
|
|
188
|
+
|
|
189
|
+
console.log(video.id);
|
|
101
190
|
```
|
|
102
191
|
|
|
103
|
-
##
|
|
192
|
+
## Development
|
|
104
193
|
|
|
105
|
-
|
|
194
|
+
This repository uses [Vite+](https://viteplus.dev/guide/) as the unified toolchain and package manager wrapper, with Bun underneath.
|
|
106
195
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
while (true) {
|
|
112
|
-
const page = await client.images.get({
|
|
113
|
-
queryParameters: {limit, offset, sort: "created_at", order: "desc"},
|
|
114
|
-
});
|
|
115
|
-
const total = page?.pagination?.total ?? 0;
|
|
116
|
-
offset += limit;
|
|
117
|
-
if (offset >= total) break;
|
|
118
|
-
}
|
|
196
|
+
Install dependencies:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
vp install
|
|
119
200
|
```
|
|
120
201
|
|
|
121
|
-
|
|
202
|
+
Regenerate config after dependency or config changes:
|
|
122
203
|
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
204
|
+
```bash
|
|
205
|
+
vp config
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Build the library:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
vp pack
|
|
134
212
|
```
|
|
135
213
|
|
|
136
|
-
|
|
214
|
+
Run formatting, linting, and type checks:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
vp check
|
|
218
|
+
```
|
|
137
219
|
|
|
138
|
-
|
|
220
|
+
Run tests:
|
|
139
221
|
|
|
140
222
|
```bash
|
|
141
|
-
|
|
142
|
-
export RIXL_API_KEY=<key>
|
|
143
|
-
npm run basic:images
|
|
144
|
-
npm run advanced:videos
|
|
223
|
+
vp test
|
|
145
224
|
```
|
|
146
225
|
|
|
147
226
|
## Issues
|