@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.
Files changed (2) hide show
  1. package/README.md +161 -82
  2. 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 — typed client for managing images, videos, and feeds.
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
  [![npm](https://img.shields.io/npm/v/@rixl/sdk.svg)](https://www.npmjs.com/package/@rixl/sdk)
6
8
 
7
9
  ## Install
8
10
 
9
- ```bash
10
- npm install @rixl/sdk @microsoft/kiota-http-fetchlibrary
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 — use `import`, not `require`.
15
+ Requires Node.js 18+. ESM only.
14
16
 
15
- ## Quick start
17
+ ## Quick Start
16
18
 
17
19
  ```ts
18
- import {createRixlClient} from "@rixl/sdk";
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 auth = new ApiKeyAuthenticationProvider("YOUR_RIXL_API_KEY", "X-API-Key", "header");
23
- const adapter = new FetchRequestAdapter(auth);
24
- const client = createRixlClient(adapter);
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 image = await client.images.byImageId("PS5IMKoFLm").get();
27
- console.log(image?.id, image?.width, image?.height);
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
- Default base URL: `https://api.rixl.com`. Override with `adapter.baseUrl = "..."`.
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
- ## Authentication
38
+ ## Feed API
33
39
 
34
- API key:
40
+ Fetch a feed and read posts:
35
41
 
36
42
  ```ts
37
- import {ApiKeyAuthenticationProvider} from "@microsoft/kiota-abstractions";
43
+ import {createClient, getFeedsByFeedId} from "@rixl/sdk";
38
44
 
39
- const auth = new ApiKeyAuthenticationProvider("YOUR_RIXL_API_KEY", "X-API-Key", "header");
40
- ```
41
-
42
- Bearer token: implement `AccessTokenProvider`, pass to `new BaseBearerTokenAuthenticationProvider(tokenProvider)`.
45
+ const client = createClient({
46
+ baseUrl: "https://api.rixl.com",
47
+ auth: process.env.RIXL_API_KEY,
48
+ responseStyle: "data",
49
+ });
43
50
 
44
- ## Feeds
51
+ const feed = await getFeedsByFeedId({
52
+ client,
53
+ path: {feedId: "FD4y3QB38S"},
54
+ query: {limit: 20, offset: 0},
55
+ });
45
56
 
46
- ```ts
47
- const posts = await client.feeds.byFeedId("FD4y3QB38S").get();
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
- ## Images
62
+ ## Image API
63
+
64
+ List images and fetch one by ID:
54
65
 
55
66
  ```ts
56
- const page = await client.images.get();
57
- const image = await client.images.byImageId("PS5IMKoFLm").get();
58
- await client.images.byImageId("PS5IMKoFLm").delete();
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
- Upload (init PUT bytes complete):
88
+ Initialize an upload, PUT the bytes to storage, then complete the upload:
62
89
 
63
90
  ```ts
64
- const initRes = await client.images.upload.init.post({
65
- name: "photo.jpg",
66
- format: "jpeg",
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(initRes.presignedUrl, {
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 client.images.upload.complete.post({
76
- imageId: initRes.imageId,
77
- attachedToVideo: false,
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
- ## Videos
124
+ ## Video API
125
+
126
+ List videos and fetch one by ID:
82
127
 
83
128
  ```ts
84
- const videos = await client.videos.get();
85
- const video = await client.videos.byVideoId("VI9VXQxWXQ").get();
86
- const tracks = await client.videos.byVideoId("VI9VXQxWXQ").subtitles.get();
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
- Upload returns presigned URLs for both the video and a poster image:
150
+ Video uploads follow the same pattern, but `init` returns both video and poster upload URLs:
90
151
 
91
152
  ```ts
92
- const initRes = await client.videos.upload.init.post({
93
- fileName: "clip.mp4",
94
- imageFormat: "jpeg",
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
- const video = await client.videos.upload.complete.post({
99
- videoId: initRes.videoId,
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
- ## Pagination
192
+ ## Development
104
193
 
105
- List endpoints take `limit`, `offset`, `sort`, `order`:
194
+ This repository uses [Vite+](https://viteplus.dev/guide/) as the unified toolchain and package manager wrapper, with Bun underneath.
106
195
 
107
- ```ts
108
- let offset = 0;
109
- const limit = 50;
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
- ## Errors
202
+ Regenerate config after dependency or config changes:
122
203
 
123
- ```ts
124
- import {ErrorResponse} from "@rixl/sdk";
125
-
126
- try {
127
- const image = await client.images.byImageId("PS5IMKoFLm").get();
128
- } catch (err) {
129
- if (err instanceof ErrorResponse) {
130
- console.error(`HTTP ${err.code}: ${err.errorEscaped}`);
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
- ## Examples
214
+ Run formatting, linting, and type checks:
215
+
216
+ ```bash
217
+ vp check
218
+ ```
137
219
 
138
- Runnable demos in [examples/](./examples):
220
+ Run tests:
139
221
 
140
222
  ```bash
141
- cd examples && npm install
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rixl/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.2",
4
4
  "description": "Official TypeScript/JavaScript SDK for the Rixl REST API — typed client for managing images, videos, and feeds.",
5
5
  "keywords": [
6
6
  "media",