@broadcastingplatforms/sdk 0.0.0-dev.52fbff9
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/dist/auth-CSkJb9Wc.d.mts +1180 -0
- package/dist/auth-CSkJb9Wc.d.ts +1180 -0
- package/dist/auth.d.mts +1 -0
- package/dist/auth.d.ts +1 -0
- package/dist/auth.js +456 -0
- package/dist/auth.mjs +433 -0
- package/dist/base-client-BHrP5nb_.d.ts +70 -0
- package/dist/base-client-BbMR6ZrV.d.mts +70 -0
- package/dist/browser-client.d.mts +47 -0
- package/dist/browser-client.d.ts +47 -0
- package/dist/browser-client.js +1983 -0
- package/dist/browser-client.mjs +1952 -0
- package/dist/channels.d.mts +1 -0
- package/dist/channels.d.ts +1 -0
- package/dist/channels.js +78 -0
- package/dist/channels.mjs +55 -0
- package/dist/chat.d.mts +1 -0
- package/dist/chat.d.ts +1 -0
- package/dist/chat.js +105 -0
- package/dist/chat.mjs +80 -0
- package/dist/errors.d.mts +68 -0
- package/dist/errors.d.ts +68 -0
- package/dist/errors.js +151 -0
- package/dist/errors.mjs +127 -0
- package/dist/http.d.mts +1 -0
- package/dist/http.d.ts +1 -0
- package/dist/http.js +323 -0
- package/dist/http.mjs +298 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2072 -0
- package/dist/index.mjs +2025 -0
- package/dist/realtime.d.mts +9 -0
- package/dist/realtime.d.ts +9 -0
- package/dist/realtime.js +1050 -0
- package/dist/realtime.mjs +1021 -0
- package/dist/resource.d.mts +1 -0
- package/dist/resource.d.ts +1 -0
- package/dist/resource.js +52 -0
- package/dist/resource.mjs +27 -0
- package/dist/server-client.d.mts +60 -0
- package/dist/server-client.d.ts +60 -0
- package/dist/server-client.js +1984 -0
- package/dist/server-client.mjs +1954 -0
- package/dist/storage.d.mts +149 -0
- package/dist/storage.d.ts +149 -0
- package/dist/storage.js +243 -0
- package/dist/storage.mjs +211 -0
- package/dist/streams.d.mts +1 -0
- package/dist/streams.d.ts +1 -0
- package/dist/streams.js +267 -0
- package/dist/streams.mjs +242 -0
- package/dist/types.d.mts +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +19 -0
- package/dist/types.mjs +1 -0
- package/package.json +139 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { C as ChannelsClient } from './auth-CSkJb9Wc.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { C as ChannelsClient } from './auth-CSkJb9Wc.js';
|
package/dist/channels.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/channels.ts
|
|
23
|
+
var channels_exports = {};
|
|
24
|
+
__export(channels_exports, {
|
|
25
|
+
ChannelsClient: () => ChannelsClient
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(channels_exports);
|
|
28
|
+
var ChannelsClient = class {
|
|
29
|
+
/**
|
|
30
|
+
* Create a new channels client instance.
|
|
31
|
+
*/
|
|
32
|
+
constructor(http) {
|
|
33
|
+
__publicField(this, "http");
|
|
34
|
+
this.http = http;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetch a channel by username.
|
|
38
|
+
*/
|
|
39
|
+
async get(username, options = {}) {
|
|
40
|
+
const rest = { ...options, body: void 0 };
|
|
41
|
+
return this.http.request(
|
|
42
|
+
`/v2/channels/${encodeURIComponent(String(username))}`,
|
|
43
|
+
{
|
|
44
|
+
...rest,
|
|
45
|
+
method: "GET"
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Follow a channel by slug.
|
|
51
|
+
*/
|
|
52
|
+
async follow(channelSlug, options = {}) {
|
|
53
|
+
return this.http.request(
|
|
54
|
+
`/v2/channels/${encodeURIComponent(channelSlug)}/follow`,
|
|
55
|
+
{
|
|
56
|
+
...options,
|
|
57
|
+
method: "POST"
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Unfollow a channel by slug.
|
|
63
|
+
*/
|
|
64
|
+
async unfollow(channelSlug, options = {}) {
|
|
65
|
+
return this.http.request(
|
|
66
|
+
`/v2/channels/${encodeURIComponent(channelSlug)}/unfollow`,
|
|
67
|
+
{
|
|
68
|
+
...options,
|
|
69
|
+
method: "POST"
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
ChannelsClient
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=channels.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/channels.ts
|
|
6
|
+
var ChannelsClient = class {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new channels client instance.
|
|
9
|
+
*/
|
|
10
|
+
constructor(http) {
|
|
11
|
+
__publicField(this, "http");
|
|
12
|
+
this.http = http;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Fetch a channel by username.
|
|
16
|
+
*/
|
|
17
|
+
async get(username, options = {}) {
|
|
18
|
+
const rest = { ...options, body: void 0 };
|
|
19
|
+
return this.http.request(
|
|
20
|
+
`/v2/channels/${encodeURIComponent(String(username))}`,
|
|
21
|
+
{
|
|
22
|
+
...rest,
|
|
23
|
+
method: "GET"
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Follow a channel by slug.
|
|
29
|
+
*/
|
|
30
|
+
async follow(channelSlug, options = {}) {
|
|
31
|
+
return this.http.request(
|
|
32
|
+
`/v2/channels/${encodeURIComponent(channelSlug)}/follow`,
|
|
33
|
+
{
|
|
34
|
+
...options,
|
|
35
|
+
method: "POST"
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Unfollow a channel by slug.
|
|
41
|
+
*/
|
|
42
|
+
async unfollow(channelSlug, options = {}) {
|
|
43
|
+
return this.http.request(
|
|
44
|
+
`/v2/channels/${encodeURIComponent(channelSlug)}/unfollow`,
|
|
45
|
+
{
|
|
46
|
+
...options,
|
|
47
|
+
method: "POST"
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
ChannelsClient
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=channels.mjs.map
|
package/dist/chat.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { g as ChatClient } from './auth-CSkJb9Wc.mjs';
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { g as ChatClient } from './auth-CSkJb9Wc.js';
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/chat.ts
|
|
23
|
+
var chat_exports = {};
|
|
24
|
+
__export(chat_exports, {
|
|
25
|
+
ChatClient: () => ChatClient
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(chat_exports);
|
|
28
|
+
|
|
29
|
+
// src/resource.ts
|
|
30
|
+
var buildQueryString = (params) => {
|
|
31
|
+
if (!params) {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
const searchParams = new URLSearchParams();
|
|
35
|
+
for (const [key, value] of Object.entries(params)) {
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
for (const item of value) {
|
|
38
|
+
if (item === null || item === void 0) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
searchParams.append(`${key}[]`, String(item));
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (value === null || value === void 0) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
searchParams.set(key, String(value));
|
|
49
|
+
}
|
|
50
|
+
return searchParams.toString();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/chat.ts
|
|
54
|
+
var ChatClient = class {
|
|
55
|
+
/**
|
|
56
|
+
* Create a new chat client instance.
|
|
57
|
+
*/
|
|
58
|
+
constructor(http) {
|
|
59
|
+
__publicField(this, "http");
|
|
60
|
+
this.http = http;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Fetch chat history for a stream.
|
|
64
|
+
*/
|
|
65
|
+
async getMessages(streamId, params = {}, options = {}) {
|
|
66
|
+
const rest = { ...options, body: void 0 };
|
|
67
|
+
const basePath = `/v2/streams/${encodeURIComponent(String(streamId))}/chat`;
|
|
68
|
+
const query = buildQueryString(params);
|
|
69
|
+
const path = query ? `${basePath}?${query}` : basePath;
|
|
70
|
+
return this.http.request(
|
|
71
|
+
path,
|
|
72
|
+
{
|
|
73
|
+
...rest,
|
|
74
|
+
method: "GET"
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resource-style alias for fetching chat messages by stream id.
|
|
80
|
+
* @param streamId - Stream identifier.
|
|
81
|
+
* @param options - Request options.
|
|
82
|
+
* @returns Chat messages response payload.
|
|
83
|
+
*/
|
|
84
|
+
async get(streamId, options = {}) {
|
|
85
|
+
return this.getMessages(streamId, {}, options);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Send a message to a stream chat.
|
|
89
|
+
*/
|
|
90
|
+
async sendMessage(streamId, message, options = {}) {
|
|
91
|
+
return this.http.request(
|
|
92
|
+
`/v2/streams/${encodeURIComponent(String(streamId))}/chat`,
|
|
93
|
+
{
|
|
94
|
+
...options,
|
|
95
|
+
method: "POST",
|
|
96
|
+
body: JSON.stringify({ message })
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
ChatClient
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=chat.js.map
|
package/dist/chat.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/resource.ts
|
|
6
|
+
var buildQueryString = (params) => {
|
|
7
|
+
if (!params) {
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
const searchParams = new URLSearchParams();
|
|
11
|
+
for (const [key, value] of Object.entries(params)) {
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
for (const item of value) {
|
|
14
|
+
if (item === null || item === void 0) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
searchParams.append(`${key}[]`, String(item));
|
|
18
|
+
}
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (value === null || value === void 0) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
searchParams.set(key, String(value));
|
|
25
|
+
}
|
|
26
|
+
return searchParams.toString();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/chat.ts
|
|
30
|
+
var ChatClient = class {
|
|
31
|
+
/**
|
|
32
|
+
* Create a new chat client instance.
|
|
33
|
+
*/
|
|
34
|
+
constructor(http) {
|
|
35
|
+
__publicField(this, "http");
|
|
36
|
+
this.http = http;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Fetch chat history for a stream.
|
|
40
|
+
*/
|
|
41
|
+
async getMessages(streamId, params = {}, options = {}) {
|
|
42
|
+
const rest = { ...options, body: void 0 };
|
|
43
|
+
const basePath = `/v2/streams/${encodeURIComponent(String(streamId))}/chat`;
|
|
44
|
+
const query = buildQueryString(params);
|
|
45
|
+
const path = query ? `${basePath}?${query}` : basePath;
|
|
46
|
+
return this.http.request(
|
|
47
|
+
path,
|
|
48
|
+
{
|
|
49
|
+
...rest,
|
|
50
|
+
method: "GET"
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resource-style alias for fetching chat messages by stream id.
|
|
56
|
+
* @param streamId - Stream identifier.
|
|
57
|
+
* @param options - Request options.
|
|
58
|
+
* @returns Chat messages response payload.
|
|
59
|
+
*/
|
|
60
|
+
async get(streamId, options = {}) {
|
|
61
|
+
return this.getMessages(streamId, {}, options);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Send a message to a stream chat.
|
|
65
|
+
*/
|
|
66
|
+
async sendMessage(streamId, message, options = {}) {
|
|
67
|
+
return this.http.request(
|
|
68
|
+
`/v2/streams/${encodeURIComponent(String(streamId))}/chat`,
|
|
69
|
+
{
|
|
70
|
+
...options,
|
|
71
|
+
method: "POST",
|
|
72
|
+
body: JSON.stringify({ message })
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
ChatClient
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=chat.mjs.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { y as SdkErrorShape, w as SdkErrorCode } from './auth-CSkJb9Wc.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error types and factories for the SDK HTTP layer.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Additional metadata to enrich a base error without transforming it.
|
|
9
|
+
*/
|
|
10
|
+
type SdkErrorDetails = Partial<SdkErrorShape> & {
|
|
11
|
+
/**
|
|
12
|
+
* Optional request metadata (null when unavailable).
|
|
13
|
+
*/
|
|
14
|
+
request?: Request | null;
|
|
15
|
+
/**
|
|
16
|
+
* Optional response metadata (null when unavailable).
|
|
17
|
+
*/
|
|
18
|
+
response?: Response | null;
|
|
19
|
+
/**
|
|
20
|
+
* Preserve any additional fields from the source error.
|
|
21
|
+
*/
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Canonical SDK error class that preserves the base error shape.
|
|
26
|
+
*/
|
|
27
|
+
declare class SDKError extends Error {
|
|
28
|
+
/**
|
|
29
|
+
* Canonical SDK error code.
|
|
30
|
+
*/
|
|
31
|
+
code: SdkErrorCode;
|
|
32
|
+
/**
|
|
33
|
+
* HTTP status code if available.
|
|
34
|
+
*/
|
|
35
|
+
statusCode?: number;
|
|
36
|
+
/**
|
|
37
|
+
* End-user safe message.
|
|
38
|
+
*/
|
|
39
|
+
userMessage: string;
|
|
40
|
+
/**
|
|
41
|
+
* Optional request metadata (null when unavailable).
|
|
42
|
+
*/
|
|
43
|
+
request: Request | null;
|
|
44
|
+
/**
|
|
45
|
+
* Optional response metadata (null when unavailable).
|
|
46
|
+
*/
|
|
47
|
+
response: Response | null;
|
|
48
|
+
/**
|
|
49
|
+
* Allow arbitrary extensions.
|
|
50
|
+
*/
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Construct an SDKError. Signature is compatible with Error.
|
|
54
|
+
* You can pass in a message or an options object, as with the Error constructor.
|
|
55
|
+
* Additional fields (code, etc) may be added via the second argument.
|
|
56
|
+
*/
|
|
57
|
+
constructor(message?: string, details?: SdkErrorDetails);
|
|
58
|
+
/**
|
|
59
|
+
* Serialize the error into a plain object, preserving extra fields.
|
|
60
|
+
*/
|
|
61
|
+
toJSON(): SdkErrorShape;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create an SDKError from a message string and optional detail overrides.
|
|
65
|
+
*/
|
|
66
|
+
declare function createSdkError(message: string, details?: SdkErrorDetails): SDKError;
|
|
67
|
+
|
|
68
|
+
export { SDKError, type SdkErrorDetails, createSdkError };
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { y as SdkErrorShape, w as SdkErrorCode } from './auth-CSkJb9Wc.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error types and factories for the SDK HTTP layer.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Additional metadata to enrich a base error without transforming it.
|
|
9
|
+
*/
|
|
10
|
+
type SdkErrorDetails = Partial<SdkErrorShape> & {
|
|
11
|
+
/**
|
|
12
|
+
* Optional request metadata (null when unavailable).
|
|
13
|
+
*/
|
|
14
|
+
request?: Request | null;
|
|
15
|
+
/**
|
|
16
|
+
* Optional response metadata (null when unavailable).
|
|
17
|
+
*/
|
|
18
|
+
response?: Response | null;
|
|
19
|
+
/**
|
|
20
|
+
* Preserve any additional fields from the source error.
|
|
21
|
+
*/
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Canonical SDK error class that preserves the base error shape.
|
|
26
|
+
*/
|
|
27
|
+
declare class SDKError extends Error {
|
|
28
|
+
/**
|
|
29
|
+
* Canonical SDK error code.
|
|
30
|
+
*/
|
|
31
|
+
code: SdkErrorCode;
|
|
32
|
+
/**
|
|
33
|
+
* HTTP status code if available.
|
|
34
|
+
*/
|
|
35
|
+
statusCode?: number;
|
|
36
|
+
/**
|
|
37
|
+
* End-user safe message.
|
|
38
|
+
*/
|
|
39
|
+
userMessage: string;
|
|
40
|
+
/**
|
|
41
|
+
* Optional request metadata (null when unavailable).
|
|
42
|
+
*/
|
|
43
|
+
request: Request | null;
|
|
44
|
+
/**
|
|
45
|
+
* Optional response metadata (null when unavailable).
|
|
46
|
+
*/
|
|
47
|
+
response: Response | null;
|
|
48
|
+
/**
|
|
49
|
+
* Allow arbitrary extensions.
|
|
50
|
+
*/
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Construct an SDKError. Signature is compatible with Error.
|
|
54
|
+
* You can pass in a message or an options object, as with the Error constructor.
|
|
55
|
+
* Additional fields (code, etc) may be added via the second argument.
|
|
56
|
+
*/
|
|
57
|
+
constructor(message?: string, details?: SdkErrorDetails);
|
|
58
|
+
/**
|
|
59
|
+
* Serialize the error into a plain object, preserving extra fields.
|
|
60
|
+
*/
|
|
61
|
+
toJSON(): SdkErrorShape;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create an SDKError from a message string and optional detail overrides.
|
|
65
|
+
*/
|
|
66
|
+
declare function createSdkError(message: string, details?: SdkErrorDetails): SDKError;
|
|
67
|
+
|
|
68
|
+
export { SDKError, type SdkErrorDetails, createSdkError };
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/errors.ts
|
|
23
|
+
var errors_exports = {};
|
|
24
|
+
__export(errors_exports, {
|
|
25
|
+
SDKError: () => SDKError,
|
|
26
|
+
createSdkError: () => createSdkError
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(errors_exports);
|
|
29
|
+
var SDKError = class extends Error {
|
|
30
|
+
/**
|
|
31
|
+
* Construct an SDKError. Signature is compatible with Error.
|
|
32
|
+
* You can pass in a message or an options object, as with the Error constructor.
|
|
33
|
+
* Additional fields (code, etc) may be added via the second argument.
|
|
34
|
+
*/
|
|
35
|
+
constructor(message, details = {}) {
|
|
36
|
+
const resolvedMessage = message ?? (typeof details.message === "string" ? details.message : "Unknown error");
|
|
37
|
+
super(resolvedMessage);
|
|
38
|
+
/**
|
|
39
|
+
* Canonical SDK error code.
|
|
40
|
+
*/
|
|
41
|
+
__publicField(this, "code");
|
|
42
|
+
/**
|
|
43
|
+
* HTTP status code if available.
|
|
44
|
+
*/
|
|
45
|
+
__publicField(this, "statusCode");
|
|
46
|
+
/**
|
|
47
|
+
* End-user safe message.
|
|
48
|
+
*/
|
|
49
|
+
__publicField(this, "userMessage");
|
|
50
|
+
/**
|
|
51
|
+
* Optional request metadata (null when unavailable).
|
|
52
|
+
*/
|
|
53
|
+
__publicField(this, "request");
|
|
54
|
+
/**
|
|
55
|
+
* Optional response metadata (null when unavailable).
|
|
56
|
+
*/
|
|
57
|
+
__publicField(this, "response");
|
|
58
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
59
|
+
if (details && typeof details === "object") {
|
|
60
|
+
for (const [key, value] of Object.entries(details)) {
|
|
61
|
+
if (!["name", "message", "stack"].includes(key)) {
|
|
62
|
+
this[key] = value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this.name = "SDKError";
|
|
67
|
+
this.code = details.code ?? "unknown_error";
|
|
68
|
+
this.statusCode = typeof details.statusCode === "number" ? details.statusCode : void 0;
|
|
69
|
+
this.userMessage = typeof details.userMessage === "string" ? details.userMessage : this.message;
|
|
70
|
+
this.request = details.request ?? null;
|
|
71
|
+
this.response = details.response ?? null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Serialize the error into a plain object, preserving extra fields.
|
|
75
|
+
*/
|
|
76
|
+
toJSON() {
|
|
77
|
+
const extras = { ...this };
|
|
78
|
+
delete extras.code;
|
|
79
|
+
delete extras.statusCode;
|
|
80
|
+
delete extras.message;
|
|
81
|
+
delete extras.userMessage;
|
|
82
|
+
delete extras.request;
|
|
83
|
+
delete extras.response;
|
|
84
|
+
delete extras.form;
|
|
85
|
+
delete extras.cause;
|
|
86
|
+
return {
|
|
87
|
+
...extras,
|
|
88
|
+
code: this.code,
|
|
89
|
+
statusCode: this.statusCode,
|
|
90
|
+
message: this.message,
|
|
91
|
+
userMessage: this.userMessage,
|
|
92
|
+
request: this.request,
|
|
93
|
+
response: this.response
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var STATUS_CODE_DEFAULTS = {
|
|
98
|
+
401: {
|
|
99
|
+
code: "authentication_required",
|
|
100
|
+
message: "Authentication required",
|
|
101
|
+
userMessage: "Please log in to continue. Your session may have expired."
|
|
102
|
+
},
|
|
103
|
+
403: {
|
|
104
|
+
code: "permission_denied",
|
|
105
|
+
message: "Permission denied",
|
|
106
|
+
userMessage: "You do not have permission to perform this action."
|
|
107
|
+
},
|
|
108
|
+
404: {
|
|
109
|
+
code: "not_found",
|
|
110
|
+
message: "Resource not found",
|
|
111
|
+
userMessage: "The requested resource was not found."
|
|
112
|
+
},
|
|
113
|
+
422: {
|
|
114
|
+
code: "validation_failed",
|
|
115
|
+
message: "Validation failed",
|
|
116
|
+
userMessage: "The provided information is invalid. Please check your input and try again."
|
|
117
|
+
},
|
|
118
|
+
429: {
|
|
119
|
+
code: "rate_limited",
|
|
120
|
+
message: "Rate limit exceeded",
|
|
121
|
+
userMessage: "Too many requests. Please wait a moment and try again."
|
|
122
|
+
},
|
|
123
|
+
500: {
|
|
124
|
+
code: "server_error",
|
|
125
|
+
message: "Internal server error",
|
|
126
|
+
userMessage: "Something went wrong on our end. Please try again later."
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var DEFAULT_ERROR = {
|
|
130
|
+
code: "unknown_error",
|
|
131
|
+
userMessage: "An unexpected error occurred. Please try again."
|
|
132
|
+
};
|
|
133
|
+
function createSdkError(message, details = {}) {
|
|
134
|
+
const statusCode = details.response?.status;
|
|
135
|
+
const statusValues = statusCode && STATUS_CODE_DEFAULTS[statusCode] ? STATUS_CODE_DEFAULTS[statusCode] : DEFAULT_ERROR;
|
|
136
|
+
const enrichedDetails = {
|
|
137
|
+
...details,
|
|
138
|
+
statusCode,
|
|
139
|
+
code: details.code ?? statusValues.code,
|
|
140
|
+
userMessage: details.userMessage ?? statusValues.userMessage,
|
|
141
|
+
request: details.request ?? null,
|
|
142
|
+
response: details.response ?? null
|
|
143
|
+
};
|
|
144
|
+
return new SDKError(message, enrichedDetails);
|
|
145
|
+
}
|
|
146
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
+
0 && (module.exports = {
|
|
148
|
+
SDKError,
|
|
149
|
+
createSdkError
|
|
150
|
+
});
|
|
151
|
+
//# sourceMappingURL=errors.js.map
|