@bedrock-rbx/ocale 0.3.4 → 0.5.0
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 +10 -5
- package/dist/assets.d.mts +64 -0
- package/dist/assets.d.mts.map +1 -0
- package/dist/assets.mjs +301 -0
- package/dist/assets.mjs.map +1 -0
- package/dist/badge-insufficient-funds-BLFvQZt1.mjs +91 -0
- package/dist/badge-insufficient-funds-BLFvQZt1.mjs.map +1 -0
- package/dist/badges.d.mts +359 -196
- package/dist/badges.d.mts.map +1 -1
- package/dist/badges.mjs +493 -59
- package/dist/badges.mjs.map +1 -1
- package/dist/capacity-admission-Ce2V9QNb.d.mts +347 -0
- package/dist/capacity-admission-Ce2V9QNb.d.mts.map +1 -0
- package/dist/{data.generated-B2ceLfSn.d.mts → data.generated-B4Fztv_7.d.mts} +23 -25
- package/dist/data.generated-B4Fztv_7.d.mts.map +1 -0
- package/dist/developer-products.d.mts +207 -194
- package/dist/developer-products.d.mts.map +1 -1
- package/dist/developer-products.mjs +125 -39
- package/dist/developer-products.mjs.map +1 -1
- package/dist/game-passes.d.mts +206 -211
- package/dist/game-passes.d.mts.map +1 -1
- package/dist/game-passes.mjs +35 -36
- package/dist/game-passes.mjs.map +1 -1
- package/dist/index.d.mts +947 -366
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +324 -12
- package/dist/index.mjs.map +1 -1
- package/dist/is-date-time-string-C91G44SI.mjs +19 -0
- package/dist/is-date-time-string-C91G44SI.mjs.map +1 -0
- package/dist/locales.d.mts +28 -2
- package/dist/locales.d.mts.map +1 -0
- package/dist/locales.mjs +24 -3
- package/dist/locales.mjs.map +1 -1
- package/dist/luau-execution.d.mts +154 -157
- package/dist/luau-execution.d.mts.map +1 -1
- package/dist/luau-execution.mjs +15 -16
- package/dist/luau-execution.mjs.map +1 -1
- package/dist/{network-error-DR9FX5hb.mjs → network-error-P4An7nUB.mjs} +48 -14
- package/dist/network-error-P4An7nUB.mjs.map +1 -0
- package/dist/places.d.mts +258 -186
- package/dist/places.d.mts.map +1 -1
- package/dist/places.mjs +187 -35
- package/dist/places.mjs.map +1 -1
- package/dist/{poll-timeout-3PXLsabj.mjs → poll-timeout-BCxgN97O.mjs} +4 -6
- package/dist/{poll-timeout-3PXLsabj.mjs.map → poll-timeout-BCxgN97O.mjs.map} +1 -1
- package/dist/{polling-helpers-CoVhsC33.mjs → polling-helpers-BtEYR5dN.mjs} +260 -105
- package/dist/polling-helpers-BtEYR5dN.mjs.map +1 -0
- package/dist/{price-information-B0tkOoAX.mjs → price-information--d6GZAcp.mjs} +3 -4
- package/dist/{price-information-B0tkOoAX.mjs.map → price-information--d6GZAcp.mjs.map} +1 -1
- package/dist/resource-client-CF8SPsV8.d.mts +162 -0
- package/dist/resource-client-CF8SPsV8.d.mts.map +1 -0
- package/dist/{resource-client-rqTMkBeR.mjs → resource-client-Cm_bPcCs.mjs} +589 -197
- package/dist/resource-client-Cm_bPcCs.mjs.map +1 -0
- package/dist/retry-DYxm_eBU.d.mts +225 -0
- package/dist/retry-DYxm_eBU.d.mts.map +1 -0
- package/dist/{retry-BlX4tUnT.mjs → retry-Dv5TsY9O.mjs} +312 -54
- package/dist/retry-Dv5TsY9O.mjs.map +1 -0
- package/dist/{signatures-JF-7Psce.mjs → signatures-CtJ7jfVN.mjs} +2 -3
- package/dist/{signatures-JF-7Psce.mjs.map → signatures-CtJ7jfVN.mjs.map} +1 -1
- package/dist/storage.d.mts +333 -344
- package/dist/storage.d.mts.map +1 -1
- package/dist/storage.mjs +39 -40
- package/dist/storage.mjs.map +1 -1
- package/dist/testing.d.mts +369 -434
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +18 -33
- package/dist/testing.mjs.map +1 -1
- package/dist/{to-blob-RPqMBuft.mjs → to-blob-Bqu7bmlE.mjs} +2 -3
- package/dist/{to-blob-RPqMBuft.mjs.map → to-blob-Bqu7bmlE.mjs.map} +1 -1
- package/dist/types-Z4abDJfK.d.mts +501 -0
- package/dist/types-Z4abDJfK.d.mts.map +1 -0
- package/dist/universes.d.mts +619 -436
- package/dist/universes.d.mts.map +1 -1
- package/dist/universes.mjs +432 -79
- package/dist/universes.mjs.map +1 -1
- package/dist/{validation-B_Zs1So2.mjs → validation-kaTLLAD1.mjs} +3 -4
- package/dist/{validation-B_Zs1So2.mjs.map → validation-kaTLLAD1.mjs.map} +1 -1
- package/dist/wire-DDG87I-d.d.mts +39 -0
- package/dist/wire-DDG87I-d.d.mts.map +1 -0
- package/package.json +15 -14
- package/dist/capacity-admission-IDO3fcUC.d.mts +0 -369
- package/dist/capacity-admission-IDO3fcUC.d.mts.map +0 -1
- package/dist/data.generated-B2ceLfSn.d.mts.map +0 -1
- package/dist/network-error-DR9FX5hb.mjs.map +0 -1
- package/dist/polling-helpers-CoVhsC33.mjs.map +0 -1
- package/dist/resource-client-B6NeFXUv.d.mts +0 -164
- package/dist/resource-client-B6NeFXUv.d.mts.map +0 -1
- package/dist/resource-client-rqTMkBeR.mjs.map +0 -1
- package/dist/retry-BlX4tUnT.mjs.map +0 -1
- package/dist/retry-war_-9tb.d.mts +0 -373
- package/dist/retry-war_-9tb.d.mts.map +0 -1
- package/dist/types-CvYh4SPC.d.mts +0 -386
- package/dist/types-CvYh4SPC.d.mts.map +0 -1
- package/dist/wire-D3K-a-UP.d.mts +0 -37
- package/dist/wire-D3K-a-UP.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -43,8 +43,8 @@ pnpm add @bedrock-rbx/ocale
|
|
|
43
43
|
|
|
44
44
|
**Runtime:** Node >= 24.12 or Bun >= 1.3.
|
|
45
45
|
|
|
46
|
-
**Authentication:** every client takes
|
|
47
|
-
at
|
|
46
|
+
**Authentication:** every client takes a `credential` at construction, for
|
|
47
|
+
example `{ kind: "apiKey", apiKey }`. Generate an API key at
|
|
48
48
|
[Creator Hub > Credentials > API Keys](https://create.roblox.com/dashboard/credentials)
|
|
49
49
|
and grant it the scopes for the operations you plan to call (each method's JSDoc
|
|
50
50
|
lists its required scopes).
|
|
@@ -54,7 +54,9 @@ lists its required scopes).
|
|
|
54
54
|
```ts
|
|
55
55
|
import { GamePassesClient } from "@bedrock-rbx/ocale/game-passes";
|
|
56
56
|
|
|
57
|
-
const client = new GamePassesClient({
|
|
57
|
+
const client = new GamePassesClient({
|
|
58
|
+
credential: { apiKey: "your-open-cloud-api-key", kind: "apiKey" },
|
|
59
|
+
});
|
|
58
60
|
|
|
59
61
|
const result = await client.get({
|
|
60
62
|
gamePassId: "9876543210",
|
|
@@ -86,6 +88,7 @@ bundle.
|
|
|
86
88
|
| `@bedrock-rbx/ocale/game-passes` | `GamePassesClient` | Game pass CRUD, icon upload, localized name and description updates. |
|
|
87
89
|
| `@bedrock-rbx/ocale/developer-products` | `DeveloperProductsClient` | Developer product CRUD, icon upload, localized name and description updates. |
|
|
88
90
|
| `@bedrock-rbx/ocale/badges` | `BadgesClient` | Badge CRUD and localized icon uploads. |
|
|
91
|
+
| `@bedrock-rbx/ocale/assets` | `AssetsClient` | Download the stored content of an asset. |
|
|
89
92
|
| `@bedrock-rbx/ocale/storage` | `StorageClient` | Memory stores (sorted maps, queues) for live game state. |
|
|
90
93
|
| `@bedrock-rbx/ocale/luau-execution` | `LuauExecutionClient` | Standalone Luau execution tasks with binary inputs and log streaming. |
|
|
91
94
|
| `@bedrock-rbx/ocale/locales` | `ROBLOX_CREATOR_LOCALES` (data) | Reference list of locales Roblox supports for localized fields. |
|
|
@@ -140,10 +143,12 @@ Client-level config is frozen on construction. Every method accepts an optional
|
|
|
140
143
|
second `RequestOptions` argument that overrides config for a single call:
|
|
141
144
|
|
|
142
145
|
```ts
|
|
143
|
-
const client = new GamePassesClient({
|
|
146
|
+
const client = new GamePassesClient({
|
|
147
|
+
credential: { apiKey: "main-key", kind: "apiKey" },
|
|
148
|
+
});
|
|
144
149
|
|
|
145
150
|
const result = await client.create(parameters, {
|
|
146
|
-
apiKey: "asset-upload-key", // different key for moderation safety
|
|
151
|
+
credential: { apiKey: "asset-upload-key", kind: "apiKey" }, // different key for moderation safety
|
|
147
152
|
deadlineMs: Date.now() + 495_000,
|
|
148
153
|
timeout: 60_000,
|
|
149
154
|
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { c as OpenCloudClientOptions, d as RequestOptions, g as OpenCloudError, m as Result } from "./types-Z4abDJfK.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for downloading the stored content of an asset.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.5.0
|
|
6
|
+
*/
|
|
7
|
+
interface DownloadAssetParameters {
|
|
8
|
+
/** Stringified ID of the asset to download. */
|
|
9
|
+
readonly assetId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Options for {@link AssetsClient}: the shared client options plus the
|
|
13
|
+
* `fetch` that downloads content from the signed CDN URL.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.5.0
|
|
16
|
+
*/
|
|
17
|
+
interface AssetsClientOptions extends OpenCloudClientOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The `fetch` that downloads the stored content from the CDN. It never
|
|
20
|
+
* receives the credential. Defaults to the global `fetch`.
|
|
21
|
+
*/
|
|
22
|
+
readonly fetch?: (url: string, init: RequestInit) => Promise<Response>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Public client for Open Cloud asset delivery. Downloads the content Roblox
|
|
26
|
+
* stores for an asset, which can differ from the uploaded file because
|
|
27
|
+
* Roblox re-encodes uploads.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.5.0
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { AssetsClient } from "@bedrock-rbx/ocale/assets";
|
|
35
|
+
*
|
|
36
|
+
* const client = new AssetsClient({ credential: { apiKey: "your-key", kind: "apiKey" } });
|
|
37
|
+
* expect(client).toBeInstanceOf(AssetsClient);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class AssetsClient {
|
|
41
|
+
#private;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new {@link AssetsClient}. Configuration is frozen on
|
|
44
|
+
* construction; per-request overrides are accepted on each method.
|
|
45
|
+
*
|
|
46
|
+
* @param options - Client-level configuration including the credential.
|
|
47
|
+
*/
|
|
48
|
+
constructor(options: AssetsClientOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Downloads the stored content of an asset. Resolves the signed CDN
|
|
51
|
+
* `location` through Open Cloud, then fetches it without the credential.
|
|
52
|
+
*
|
|
53
|
+
* The `timeout`, `deadlineMs` and retry options apply only to the Open
|
|
54
|
+
* Cloud call, not to the CDN download. The caller's `signal` cancels both.
|
|
55
|
+
*
|
|
56
|
+
* @param parameters - The asset to download.
|
|
57
|
+
* @param options - Optional per-request overrides for the Open Cloud call.
|
|
58
|
+
* @returns A result containing the stored bytes or the request error.
|
|
59
|
+
* @since 0.5.0
|
|
60
|
+
*/
|
|
61
|
+
download(parameters: DownloadAssetParameters, options?: RequestOptions): Promise<Result<Uint8Array, OpenCloudError>>;
|
|
62
|
+
}
|
|
63
|
+
export type { AssetsClientOptions, DownloadAssetParameters };
|
|
64
|
+
//# sourceMappingURL=assets.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.mts","names":[],"sources":["../src/domains/asset-delivery/assets/types.ts","../src/resources/assets/client.ts"],"mappings":";;;;;;UAKiB;;WAEP;;;;;;;;UCsBO,4BAA4B;;;;;WAKnC,SAAS,aAAa,MAAM,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;qBA0CjD;;;;;;;;EAUZ,YAAY,SAAS;;;;;;;;;;;;;EAiBrB,SACC,YAAY,yBACZ,UAAU,iBACR,QAAQ,OAAO,YAAY"}
|
package/dist/assets.mjs
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { I as tryCatchAsync, N as isRecord, k as createRateLimitError, m as UnexpectedResponseError, r as IDEMPOTENT_METHOD_DEFAULTS, v as PermissionError, w as requestFailure } from "./retry-Dv5TsY9O.mjs";
|
|
2
|
+
import { a as ApiError } from "./network-error-P4An7nUB.mjs";
|
|
3
|
+
import { n as okRequest, s as toJsonDetails, t as ResourceClient } from "./resource-client-Cm_bPcCs.mjs";
|
|
4
|
+
// src/domains/asset-delivery/assets/builders.ts
|
|
5
|
+
/**
|
|
6
|
+
* Builds a `GET` request for the Open Cloud asset delivery endpoint, which
|
|
7
|
+
* answers with a short-lived CDN `location` for the stored content.
|
|
8
|
+
*
|
|
9
|
+
* @param parameters - The asset to resolve.
|
|
10
|
+
* @returns A pure {@link HttpRequest} describing the call.
|
|
11
|
+
*/
|
|
12
|
+
function buildLocationRequest(parameters) {
|
|
13
|
+
return {
|
|
14
|
+
method: "GET",
|
|
15
|
+
url: `/asset-delivery-api/v1/assetId/${encodeURIComponent(parameters.assetId)}`
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
// src/domains/asset-delivery/assets/content.ts
|
|
19
|
+
const GZIP_MAGIC_FIRST = 31;
|
|
20
|
+
const GZIP_MAGIC_SECOND = 139;
|
|
21
|
+
/**
|
|
22
|
+
* Gunzips asset content that still starts with the gzip magic bytes. `fetch`
|
|
23
|
+
* decodes a `Content-Encoding: gzip` body itself, but the CDN may also serve
|
|
24
|
+
* raw gzip bytes without that header. Other content is returned unchanged.
|
|
25
|
+
*
|
|
26
|
+
* @param bytes - The downloaded content.
|
|
27
|
+
* @returns The decoded content, or the decompression error.
|
|
28
|
+
*/
|
|
29
|
+
async function decodeAssetContentAsync(bytes) {
|
|
30
|
+
if (bytes[0] !== GZIP_MAGIC_FIRST || bytes[1] !== GZIP_MAGIC_SECOND) return {
|
|
31
|
+
data: bytes,
|
|
32
|
+
success: true
|
|
33
|
+
};
|
|
34
|
+
const blob = new Blob([new Uint8Array(bytes)]);
|
|
35
|
+
const response = new Response(blob.stream().pipeThrough(new DecompressionStream("gzip")));
|
|
36
|
+
const decoded = await tryCatchAsync(response.arrayBuffer());
|
|
37
|
+
return decoded.success ? {
|
|
38
|
+
data: new Uint8Array(decoded.data),
|
|
39
|
+
success: true
|
|
40
|
+
} : {
|
|
41
|
+
err: decoded.err,
|
|
42
|
+
success: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Request ceiling for `GET /asset-delivery-api/v1/assetId/{assetId}`, from the
|
|
47
|
+
* vendored OpenAPI schema (1000 requests per minute per API key owner).
|
|
48
|
+
*/
|
|
49
|
+
const DOWNLOAD_OPERATION_LIMIT = Object.freeze({
|
|
50
|
+
maxPerSecond: 1e3 / 60,
|
|
51
|
+
operationKey: "assets.download"
|
|
52
|
+
});
|
|
53
|
+
/** Scopes required by the asset delivery endpoint, from `x-roblox-scopes`. */
|
|
54
|
+
const DOWNLOAD_REQUIRED_SCOPES = Object.freeze(["legacy-asset:manage"]);
|
|
55
|
+
// src/domains/asset-delivery/assets/parsers.ts
|
|
56
|
+
/** Body `code` Roblox sends when the credential cannot read the asset. */
|
|
57
|
+
const NOT_AUTHORIZED_CODE = 409;
|
|
58
|
+
/**
|
|
59
|
+
* Parses an asset delivery response into the signed CDN URL of the stored
|
|
60
|
+
* content. Roblox reports an unreadable or missing asset with HTTP 200 and an
|
|
61
|
+
* `errors` array; the first entry becomes a {@link PermissionError} (body code
|
|
62
|
+
* 409) or an {@link ApiError}. Because the HTTP status is 200, `statusCode`
|
|
63
|
+
* carries the body error code. A 409 means the credential cannot read this
|
|
64
|
+
* asset, not that it lacks a scope, so its `requiredScopes` is empty. A
|
|
65
|
+
* `location` that is not an `https:` URL is an {@link UnexpectedResponseError}.
|
|
66
|
+
*
|
|
67
|
+
* @param response - The HTTP response to parse.
|
|
68
|
+
* @returns The `location` URL, or the error the body describes.
|
|
69
|
+
*/
|
|
70
|
+
function parseAssetLocationResponse({ body, status: statusCode }) {
|
|
71
|
+
if (isRecord(body) && typeof body["location"] === "string" && isHttpsUrl(body["location"])) return {
|
|
72
|
+
data: body["location"],
|
|
73
|
+
success: true
|
|
74
|
+
};
|
|
75
|
+
const wire = isRecord(body) && Array.isArray(body["errors"]) ? body["errors"][0] : void 0;
|
|
76
|
+
if (!isAssetDeliveryError(wire)) return {
|
|
77
|
+
err: new UnexpectedResponseError("Malformed asset delivery response", {
|
|
78
|
+
details: toJsonDetails(redactLocation$1(body)),
|
|
79
|
+
statusCode
|
|
80
|
+
}),
|
|
81
|
+
success: false
|
|
82
|
+
};
|
|
83
|
+
const options = {
|
|
84
|
+
code: typeof wire.customErrorCode === "number" ? String(wire.customErrorCode) : void 0,
|
|
85
|
+
details: toJsonDetails(body),
|
|
86
|
+
statusCode: wire.code
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
err: wire.code === NOT_AUTHORIZED_CODE ? new PermissionError(wire.message, {
|
|
90
|
+
...options,
|
|
91
|
+
operationKey: DOWNLOAD_OPERATION_LIMIT.operationKey,
|
|
92
|
+
requiredScopes: []
|
|
93
|
+
}) : new ApiError(wire.message, options),
|
|
94
|
+
success: false
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Replaces a rejected `location` string with a placeholder, so a signed URL
|
|
99
|
+
* never reaches error details.
|
|
100
|
+
*
|
|
101
|
+
* @param body - The parsed response body.
|
|
102
|
+
* @returns The body with any string `location` redacted.
|
|
103
|
+
*/
|
|
104
|
+
function redactLocation$1(body) {
|
|
105
|
+
return isRecord(body) && typeof body["location"] === "string" ? {
|
|
106
|
+
...body,
|
|
107
|
+
location: "[redacted]"
|
|
108
|
+
} : body;
|
|
109
|
+
}
|
|
110
|
+
function isHttpsUrl(value) {
|
|
111
|
+
return URL.parse(value)?.protocol === "https:";
|
|
112
|
+
}
|
|
113
|
+
function isAssetDeliveryError(value) {
|
|
114
|
+
return isRecord(value) && typeof value["code"] === "number" && typeof value["message"] === "string";
|
|
115
|
+
}
|
|
116
|
+
// src/resources/assets/client.ts
|
|
117
|
+
const LOCATION_SPEC = Object.freeze({
|
|
118
|
+
buildRequest: (parameters) => {
|
|
119
|
+
return okRequest(buildLocationRequest(parameters));
|
|
120
|
+
},
|
|
121
|
+
methodDefaults: IDEMPOTENT_METHOD_DEFAULTS,
|
|
122
|
+
methodKind: "idempotent",
|
|
123
|
+
operationLimit: DOWNLOAD_OPERATION_LIMIT,
|
|
124
|
+
parse: parseAssetLocationResponse,
|
|
125
|
+
requiredScopes: DOWNLOAD_REQUIRED_SCOPES
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* Public client for Open Cloud asset delivery. Downloads the content Roblox
|
|
129
|
+
* stores for an asset, which can differ from the uploaded file because
|
|
130
|
+
* Roblox re-encodes uploads.
|
|
131
|
+
*
|
|
132
|
+
* @since 0.5.0
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { AssetsClient } from "@bedrock-rbx/ocale/assets";
|
|
138
|
+
*
|
|
139
|
+
* const client = new AssetsClient({ credential: { apiKey: "your-key", kind: "apiKey" } });
|
|
140
|
+
* expect(client).toBeInstanceOf(AssetsClient);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
var AssetsClient = class {
|
|
144
|
+
#fetch;
|
|
145
|
+
#inner;
|
|
146
|
+
/**
|
|
147
|
+
* Creates a new {@link AssetsClient}. Configuration is frozen on
|
|
148
|
+
* construction; per-request overrides are accepted on each method.
|
|
149
|
+
*
|
|
150
|
+
* @param options - Client-level configuration including the credential.
|
|
151
|
+
*/
|
|
152
|
+
constructor(options) {
|
|
153
|
+
this.#inner = new ResourceClient(options);
|
|
154
|
+
this.#fetch = options.fetch ?? fetch;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Downloads the stored content of an asset. Resolves the signed CDN
|
|
158
|
+
* `location` through Open Cloud, then fetches it without the credential.
|
|
159
|
+
*
|
|
160
|
+
* The `timeout`, `deadlineMs` and retry options apply only to the Open
|
|
161
|
+
* Cloud call, not to the CDN download. The caller's `signal` cancels both.
|
|
162
|
+
*
|
|
163
|
+
* @param parameters - The asset to download.
|
|
164
|
+
* @param options - Optional per-request overrides for the Open Cloud call.
|
|
165
|
+
* @returns A result containing the stored bytes or the request error.
|
|
166
|
+
* @since 0.5.0
|
|
167
|
+
*/
|
|
168
|
+
async download(parameters, options) {
|
|
169
|
+
const location = await this.#inner.executeAsync({
|
|
170
|
+
options,
|
|
171
|
+
parameters,
|
|
172
|
+
spec: LOCATION_SPEC
|
|
173
|
+
});
|
|
174
|
+
if (!location.success) return location;
|
|
175
|
+
return downloadContentAsync(this.#fetch, {
|
|
176
|
+
location: location.data,
|
|
177
|
+
signal: options?.signal
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Rejects content that a redirect moved off HTTPS. The URL in the error keeps
|
|
183
|
+
* only origin and path.
|
|
184
|
+
*
|
|
185
|
+
* @param response - The CDN response, whose `url` is the final URL.
|
|
186
|
+
* @param target - The method of the CDN request.
|
|
187
|
+
* @returns The error, or `undefined` when the final URL is HTTPS.
|
|
188
|
+
*/
|
|
189
|
+
function insecureRedirectError({ status, url }, target) {
|
|
190
|
+
if (url === "" || url.startsWith("https:")) return;
|
|
191
|
+
const { origin, pathname } = new URL(url);
|
|
192
|
+
return new UnexpectedResponseError("Asset content was redirected off https", {
|
|
193
|
+
method: target.method,
|
|
194
|
+
statusCode: status,
|
|
195
|
+
url: `${origin}${pathname}`
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async function decodeBodyAsync({ bytes, response }, target) {
|
|
199
|
+
const { status } = response;
|
|
200
|
+
if (status === 429) return {
|
|
201
|
+
err: createRateLimitError(response, void 0),
|
|
202
|
+
success: false
|
|
203
|
+
};
|
|
204
|
+
if (status >= 300) return {
|
|
205
|
+
err: new ApiError(`Asset content download failed with HTTP ${status}`, {
|
|
206
|
+
...target,
|
|
207
|
+
statusCode: status
|
|
208
|
+
}),
|
|
209
|
+
success: false
|
|
210
|
+
};
|
|
211
|
+
const decoded = await decodeAssetContentAsync(bytes);
|
|
212
|
+
if (!decoded.success) return {
|
|
213
|
+
err: new UnexpectedResponseError("Asset content is not valid gzip", {
|
|
214
|
+
...target,
|
|
215
|
+
cause: decoded.err,
|
|
216
|
+
statusCode: status
|
|
217
|
+
}),
|
|
218
|
+
success: false
|
|
219
|
+
};
|
|
220
|
+
return decoded;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Whether an error, its stack or any error in its `cause` chain contains the
|
|
224
|
+
* text.
|
|
225
|
+
*
|
|
226
|
+
* @param err - The error to search.
|
|
227
|
+
* @param text - The text to find.
|
|
228
|
+
* @returns `true` when the text appears anywhere in the chain.
|
|
229
|
+
*/
|
|
230
|
+
function containsText(err, text) {
|
|
231
|
+
let current = err;
|
|
232
|
+
while (current instanceof Error) {
|
|
233
|
+
if (current.message.includes(text) || String(current.stack).includes(text)) return true;
|
|
234
|
+
current = current.cause;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Returns a fetch failure unchanged when the signed URL appears nowhere in
|
|
240
|
+
* its chain, so diagnostics such as `cause.code` survive. Otherwise rebuilds
|
|
241
|
+
* it with the signed URL in its message replaced by the redacted one and a
|
|
242
|
+
* fresh stack, so the signed query cannot reach the message, stack or cause
|
|
243
|
+
* chain.
|
|
244
|
+
*
|
|
245
|
+
* @param err - The fetch failure.
|
|
246
|
+
* @param target - The signed CDN URL and its redacted origin and path.
|
|
247
|
+
* @param target.location - The signed CDN URL.
|
|
248
|
+
* @param target.redacted - The origin and path of the CDN URL.
|
|
249
|
+
* @returns A copy of the failure without the signed URL.
|
|
250
|
+
*/
|
|
251
|
+
function redactLocation(err, { location, redacted }) {
|
|
252
|
+
if (!containsText(err, location)) return err;
|
|
253
|
+
return new Error(err.message.split(location).join(redacted));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Fetches the signed CDN URL without any credential, reads the body and
|
|
257
|
+
* gunzips it when it is still gzip. The URL in errors keeps only origin and
|
|
258
|
+
* path, and a fetch failure gets a fixed message, so the signed token never
|
|
259
|
+
* leaks into a message or URL.
|
|
260
|
+
*
|
|
261
|
+
* @param fetchFunc - The fetch to send the CDN request through.
|
|
262
|
+
* @param request - The signed CDN URL and the caller's signal, if any.
|
|
263
|
+
* @param request.location - The signed CDN URL.
|
|
264
|
+
* @param request.signal - The caller's cancellation signal, if any.
|
|
265
|
+
* @returns The content bytes, or the typed failure.
|
|
266
|
+
*/
|
|
267
|
+
async function downloadContentAsync(fetchFunc, { location, signal }) {
|
|
268
|
+
const { origin, pathname } = new URL(location);
|
|
269
|
+
const target = {
|
|
270
|
+
method: "GET",
|
|
271
|
+
url: `${origin}${pathname}`
|
|
272
|
+
};
|
|
273
|
+
const sent = await tryCatchAsync((async () => {
|
|
274
|
+
const response = await fetchFunc(location, signal === void 0 ? {} : { signal });
|
|
275
|
+
return {
|
|
276
|
+
bytes: new Uint8Array(await response.arrayBuffer()),
|
|
277
|
+
response
|
|
278
|
+
};
|
|
279
|
+
})());
|
|
280
|
+
if (!sent.success) return {
|
|
281
|
+
err: requestFailure({
|
|
282
|
+
cause: redactLocation(sent.err, {
|
|
283
|
+
location,
|
|
284
|
+
redacted: target.url
|
|
285
|
+
}),
|
|
286
|
+
config: signal === void 0 ? {} : { signal },
|
|
287
|
+
effectiveSignal: signal,
|
|
288
|
+
target
|
|
289
|
+
}),
|
|
290
|
+
success: false
|
|
291
|
+
};
|
|
292
|
+
const insecure = insecureRedirectError(sent.data.response, target);
|
|
293
|
+
if (insecure !== void 0) return {
|
|
294
|
+
err: insecure,
|
|
295
|
+
success: false
|
|
296
|
+
};
|
|
297
|
+
return decodeBodyAsync(sent.data, target);
|
|
298
|
+
}
|
|
299
|
+
export { AssetsClient };
|
|
300
|
+
|
|
301
|
+
//# sourceMappingURL=assets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.mjs","names":["redactLocation"],"sources":["../src/domains/asset-delivery/assets/builders.ts","../src/domains/asset-delivery/assets/content.ts","../src/domains/asset-delivery/assets/operations.ts","../src/domains/asset-delivery/assets/parsers.ts","../src/resources/assets/client.ts"],"sourcesContent":["import type { HttpRequest } from \"../../../internal/http/types.ts\";\nimport type { DownloadAssetParameters } from \"./types.ts\";\n\n/**\n * Builds a `GET` request for the Open Cloud asset delivery endpoint, which\n * answers with a short-lived CDN `location` for the stored content.\n *\n * @param parameters - The asset to resolve.\n * @returns A pure {@link HttpRequest} describing the call.\n */\nexport function buildLocationRequest(parameters: DownloadAssetParameters): HttpRequest {\n\treturn {\n\t\tmethod: \"GET\",\n\t\turl: `/asset-delivery-api/v1/assetId/${encodeURIComponent(parameters.assetId)}`,\n\t};\n}\n","import { tryCatchAsync } from \"../../../internal/utils/try-catch.ts\";\nimport type { Result } from \"../../../types.ts\";\n\nconst GZIP_MAGIC_FIRST = 0x1f;\nconst GZIP_MAGIC_SECOND = 0x8b;\n\n/**\n * Gunzips asset content that still starts with the gzip magic bytes. `fetch`\n * decodes a `Content-Encoding: gzip` body itself, but the CDN may also serve\n * raw gzip bytes without that header. Other content is returned unchanged.\n *\n * @param bytes - The downloaded content.\n * @returns The decoded content, or the decompression error.\n */\nexport async function decodeAssetContentAsync(bytes: Uint8Array): Promise<Result<Uint8Array>> {\n\tif (bytes[0] !== GZIP_MAGIC_FIRST || bytes[1] !== GZIP_MAGIC_SECOND) {\n\t\treturn { data: bytes, success: true };\n\t}\n\n\tconst blob = new Blob([new Uint8Array(bytes)]);\n\tconst response = new Response(blob.stream().pipeThrough(new DecompressionStream(\"gzip\")));\n\tconst decoded = await tryCatchAsync(response.arrayBuffer());\n\treturn decoded.success\n\t\t? { data: new Uint8Array(decoded.data), success: true }\n\t\t: { err: decoded.err, success: false };\n}\n","import type { OperationLimit } from \"../../../internal/http/rate-limit-queue.ts\";\n\nconst PER_MINUTE = 1000;\nconst SECONDS_PER_MINUTE = 60;\n\n/**\n * Request ceiling for `GET /asset-delivery-api/v1/assetId/{assetId}`, from the\n * vendored OpenAPI schema (1000 requests per minute per API key owner).\n */\nexport const DOWNLOAD_OPERATION_LIMIT: OperationLimit = Object.freeze({\n\tmaxPerSecond: PER_MINUTE / SECONDS_PER_MINUTE,\n\toperationKey: \"assets.download\",\n});\n\n/** Scopes required by the asset delivery endpoint, from `x-roblox-scopes`. */\nexport const DOWNLOAD_REQUIRED_SCOPES: ReadonlyArray<string> = Object.freeze([\n\t\"legacy-asset:manage\",\n]);\n","import type { HttpResponse } from \"../../../client/types.ts\";\nimport { ApiError } from \"../../../errors/api-error.ts\";\nimport type { OpenCloudError } from \"../../../errors/base.ts\";\nimport { PermissionError } from \"../../../errors/permission-error.ts\";\nimport { UnexpectedResponseError } from \"../../../errors/unexpected-response.ts\";\nimport { isRecord } from \"../../../internal/utils/is-record.ts\";\nimport { toJsonDetails } from \"../../../internal/utils/to-json-details.ts\";\nimport type { Result } from \"../../../types.ts\";\nimport { DOWNLOAD_OPERATION_LIMIT } from \"./operations.ts\";\n\n/** Body `code` Roblox sends when the credential cannot read the asset. */\nconst NOT_AUTHORIZED_CODE = 409;\n\ninterface AssetDeliveryErrorWire {\n\treadonly code: number;\n\treadonly customErrorCode?: unknown;\n\treadonly message: string;\n}\n\n/**\n * Parses an asset delivery response into the signed CDN URL of the stored\n * content. Roblox reports an unreadable or missing asset with HTTP 200 and an\n * `errors` array; the first entry becomes a {@link PermissionError} (body code\n * 409) or an {@link ApiError}. Because the HTTP status is 200, `statusCode`\n * carries the body error code. A 409 means the credential cannot read this\n * asset, not that it lacks a scope, so its `requiredScopes` is empty. A\n * `location` that is not an `https:` URL is an {@link UnexpectedResponseError}.\n *\n * @param response - The HTTP response to parse.\n * @returns The `location` URL, or the error the body describes.\n */\nexport function parseAssetLocationResponse({\n\tbody,\n\tstatus: statusCode,\n}: HttpResponse): Result<string, OpenCloudError> {\n\tif (isRecord(body) && typeof body[\"location\"] === \"string\" && isHttpsUrl(body[\"location\"])) {\n\t\treturn { data: body[\"location\"], success: true };\n\t}\n\n\tconst wire = isRecord(body) && Array.isArray(body[\"errors\"]) ? body[\"errors\"][0] : undefined;\n\tif (!isAssetDeliveryError(wire)) {\n\t\treturn {\n\t\t\terr: new UnexpectedResponseError(\"Malformed asset delivery response\", {\n\t\t\t\tdetails: toJsonDetails(redactLocation(body)),\n\t\t\t\tstatusCode,\n\t\t\t}),\n\t\t\tsuccess: false,\n\t\t};\n\t}\n\n\tconst options = {\n\t\tcode: typeof wire.customErrorCode === \"number\" ? String(wire.customErrorCode) : undefined,\n\t\tdetails: toJsonDetails(body),\n\t\tstatusCode: wire.code,\n\t};\n\tconst err =\n\t\twire.code === NOT_AUTHORIZED_CODE\n\t\t\t? new PermissionError(wire.message, {\n\t\t\t\t\t...options,\n\t\t\t\t\toperationKey: DOWNLOAD_OPERATION_LIMIT.operationKey,\n\t\t\t\t\trequiredScopes: [],\n\t\t\t\t})\n\t\t\t: new ApiError(wire.message, options);\n\treturn { err, success: false };\n}\n\n/**\n * Replaces a rejected `location` string with a placeholder, so a signed URL\n * never reaches error details.\n *\n * @param body - The parsed response body.\n * @returns The body with any string `location` redacted.\n */\nfunction redactLocation(body: unknown): unknown {\n\treturn isRecord(body) && typeof body[\"location\"] === \"string\"\n\t\t? { ...body, location: \"[redacted]\" }\n\t\t: body;\n}\n\nfunction isHttpsUrl(value: string): boolean {\n\treturn URL.parse(value)?.protocol === \"https:\";\n}\n\nfunction isAssetDeliveryError(value: unknown): value is AssetDeliveryErrorWire {\n\treturn (\n\t\tisRecord(value) && typeof value[\"code\"] === \"number\" && typeof value[\"message\"] === \"string\"\n\t);\n}\n","import type { OpenCloudClientOptions, RequestOptions } from \"../../client/types.ts\";\nimport { buildLocationRequest } from \"../../domains/asset-delivery/assets/builders.ts\";\nimport { decodeAssetContentAsync } from \"../../domains/asset-delivery/assets/content.ts\";\nimport {\n\tDOWNLOAD_OPERATION_LIMIT,\n\tDOWNLOAD_REQUIRED_SCOPES,\n} from \"../../domains/asset-delivery/assets/operations.ts\";\nimport { parseAssetLocationResponse } from \"../../domains/asset-delivery/assets/parsers.ts\";\nimport type { DownloadAssetParameters } from \"../../domains/asset-delivery/assets/types.ts\";\nimport { ApiError } from \"../../errors/api-error.ts\";\nimport type { OpenCloudError } from \"../../errors/base.ts\";\nimport { UnexpectedResponseError } from \"../../errors/unexpected-response.ts\";\nimport { createRateLimitError } from \"../../internal/http/rate-limit-response.ts\";\nimport { requestFailure } from \"../../internal/http/request-signal.ts\";\nimport { IDEMPOTENT_METHOD_DEFAULTS } from \"../../internal/http/retry.ts\";\nimport {\n\tokRequest,\n\tResourceClient,\n\ttype ResourceMethodSpec,\n} from \"../../internal/resource-client.ts\";\nimport { tryCatchAsync } from \"../../internal/utils/try-catch.ts\";\nimport type { Result } from \"../../types.ts\";\n\n/**\n * Options for {@link AssetsClient}: the shared client options plus the\n * `fetch` that downloads content from the signed CDN URL.\n *\n * @since 0.5.0\n */\nexport interface AssetsClientOptions extends OpenCloudClientOptions {\n\t/**\n\t * The `fetch` that downloads the stored content from the CDN. It never\n\t * receives the credential. Defaults to the global `fetch`.\n\t */\n\treadonly fetch?: (url: string, init: RequestInit) => Promise<Response>;\n}\n\ntype FetchFunc = NonNullable<AssetsClientOptions[\"fetch\"]>;\n\nconst LOCATION_SPEC: ResourceMethodSpec<DownloadAssetParameters, string> = Object.freeze({\n\tbuildRequest: (parameters: DownloadAssetParameters) => {\n\t\treturn okRequest(buildLocationRequest(parameters));\n\t},\n\tmethodDefaults: IDEMPOTENT_METHOD_DEFAULTS,\n\tmethodKind: \"idempotent\",\n\toperationLimit: DOWNLOAD_OPERATION_LIMIT,\n\tparse: parseAssetLocationResponse,\n\trequiredScopes: DOWNLOAD_REQUIRED_SCOPES,\n});\n\ninterface CdnTarget {\n\treadonly method: string;\n\treadonly url: string;\n}\n\ninterface CdnBody {\n\treadonly bytes: Uint8Array;\n\treadonly response: Response;\n}\n\n/**\n * Public client for Open Cloud asset delivery. Downloads the content Roblox\n * stores for an asset, which can differ from the uploaded file because\n * Roblox re-encodes uploads.\n *\n * @since 0.5.0\n *\n * @example\n *\n * ```ts\n * import { AssetsClient } from \"@bedrock-rbx/ocale/assets\";\n *\n * const client = new AssetsClient({ credential: { apiKey: \"your-key\", kind: \"apiKey\" } });\n * expect(client).toBeInstanceOf(AssetsClient);\n * ```\n */\nexport class AssetsClient {\n\treadonly #fetch: FetchFunc;\n\treadonly #inner: ResourceClient;\n\n\t/**\n\t * Creates a new {@link AssetsClient}. Configuration is frozen on\n\t * construction; per-request overrides are accepted on each method.\n\t *\n\t * @param options - Client-level configuration including the credential.\n\t */\n\tconstructor(options: AssetsClientOptions) {\n\t\tthis.#inner = new ResourceClient(options);\n\t\tthis.#fetch = options.fetch ?? fetch;\n\t}\n\n\t/**\n\t * Downloads the stored content of an asset. Resolves the signed CDN\n\t * `location` through Open Cloud, then fetches it without the credential.\n\t *\n\t * The `timeout`, `deadlineMs` and retry options apply only to the Open\n\t * Cloud call, not to the CDN download. The caller's `signal` cancels both.\n\t *\n\t * @param parameters - The asset to download.\n\t * @param options - Optional per-request overrides for the Open Cloud call.\n\t * @returns A result containing the stored bytes or the request error.\n\t * @since 0.5.0\n\t */\n\tpublic async download(\n\t\tparameters: DownloadAssetParameters,\n\t\toptions?: RequestOptions,\n\t): Promise<Result<Uint8Array, OpenCloudError>> {\n\t\tconst location = await this.#inner.executeAsync({\n\t\t\toptions,\n\t\t\tparameters,\n\t\t\tspec: LOCATION_SPEC,\n\t\t});\n\t\tif (!location.success) {\n\t\t\treturn location;\n\t\t}\n\n\t\treturn downloadContentAsync(this.#fetch, {\n\t\t\tlocation: location.data,\n\t\t\tsignal: options?.signal,\n\t\t});\n\t}\n}\n\n/**\n * Rejects content that a redirect moved off HTTPS. The URL in the error keeps\n * only origin and path.\n *\n * @param response - The CDN response, whose `url` is the final URL.\n * @param target - The method of the CDN request.\n * @returns The error, or `undefined` when the final URL is HTTPS.\n */\nfunction insecureRedirectError(\n\t{ status, url }: Response,\n\ttarget: CdnTarget,\n): undefined | UnexpectedResponseError {\n\tif (url === \"\" || url.startsWith(\"https:\")) {\n\t\treturn undefined;\n\t}\n\n\tconst { origin, pathname } = new URL(url);\n\treturn new UnexpectedResponseError(\"Asset content was redirected off https\", {\n\t\tmethod: target.method,\n\t\tstatusCode: status,\n\t\turl: `${origin}${pathname}`,\n\t});\n}\n\nasync function decodeBodyAsync(\n\t{ bytes, response }: CdnBody,\n\ttarget: CdnTarget,\n): Promise<Result<Uint8Array, OpenCloudError>> {\n\tconst { status } = response;\n\tif (status === 429) {\n\t\treturn { err: createRateLimitError(response, undefined), success: false };\n\t}\n\n\tif (status >= 300) {\n\t\treturn {\n\t\t\terr: new ApiError(`Asset content download failed with HTTP ${status}`, {\n\t\t\t\t...target,\n\t\t\t\tstatusCode: status,\n\t\t\t}),\n\t\t\tsuccess: false,\n\t\t};\n\t}\n\n\tconst decoded = await decodeAssetContentAsync(bytes);\n\tif (!decoded.success) {\n\t\treturn {\n\t\t\terr: new UnexpectedResponseError(\"Asset content is not valid gzip\", {\n\t\t\t\t...target,\n\t\t\t\tcause: decoded.err,\n\t\t\t\tstatusCode: status,\n\t\t\t}),\n\t\t\tsuccess: false,\n\t\t};\n\t}\n\n\treturn decoded;\n}\n\n/**\n * Whether an error, its stack or any error in its `cause` chain contains the\n * text.\n *\n * @param err - The error to search.\n * @param text - The text to find.\n * @returns `true` when the text appears anywhere in the chain.\n */\nfunction containsText(err: unknown, text: string): boolean {\n\tlet current = err;\n\twhile (current instanceof Error) {\n\t\tif (current.message.includes(text) || String(current.stack).includes(text)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tcurrent = current.cause;\n\t}\n\n\treturn false;\n}\n\n/**\n * Returns a fetch failure unchanged when the signed URL appears nowhere in\n * its chain, so diagnostics such as `cause.code` survive. Otherwise rebuilds\n * it with the signed URL in its message replaced by the redacted one and a\n * fresh stack, so the signed query cannot reach the message, stack or cause\n * chain.\n *\n * @param err - The fetch failure.\n * @param target - The signed CDN URL and its redacted origin and path.\n * @param target.location - The signed CDN URL.\n * @param target.redacted - The origin and path of the CDN URL.\n * @returns A copy of the failure without the signed URL.\n */\nfunction redactLocation(\n\terr: Error,\n\t{ location, redacted }: { readonly location: string; readonly redacted: string },\n): Error {\n\tif (!containsText(err, location)) {\n\t\treturn err;\n\t}\n\n\treturn new Error(err.message.split(location).join(redacted));\n}\n\n/**\n * Fetches the signed CDN URL without any credential, reads the body and\n * gunzips it when it is still gzip. The URL in errors keeps only origin and\n * path, and a fetch failure gets a fixed message, so the signed token never\n * leaks into a message or URL.\n *\n * @param fetchFunc - The fetch to send the CDN request through.\n * @param request - The signed CDN URL and the caller's signal, if any.\n * @param request.location - The signed CDN URL.\n * @param request.signal - The caller's cancellation signal, if any.\n * @returns The content bytes, or the typed failure.\n */\nasync function downloadContentAsync(\n\tfetchFunc: FetchFunc,\n\t{ location, signal }: { readonly location: string; readonly signal: AbortSignal | undefined },\n): Promise<Result<Uint8Array, OpenCloudError>> {\n\tconst { origin, pathname } = new URL(location);\n\tconst target: CdnTarget = { method: \"GET\", url: `${origin}${pathname}` };\n\tconst sent = await tryCatchAsync(\n\t\t(async (): Promise<CdnBody> => {\n\t\t\tconst response = await fetchFunc(location, signal === undefined ? {} : { signal });\n\t\t\treturn { bytes: new Uint8Array(await response.arrayBuffer()), response };\n\t\t})(),\n\t);\n\tif (!sent.success) {\n\t\treturn {\n\t\t\terr: requestFailure({\n\t\t\t\tcause: redactLocation(sent.err, { location, redacted: target.url }),\n\t\t\t\tconfig: signal === undefined ? {} : { signal },\n\t\t\t\teffectiveSignal: signal,\n\t\t\t\ttarget,\n\t\t\t}),\n\t\t\tsuccess: false,\n\t\t};\n\t}\n\n\tconst insecure = insecureRedirectError(sent.data.response, target);\n\tif (insecure !== undefined) {\n\t\treturn { err: insecure, success: false };\n\t}\n\n\treturn decodeBodyAsync(sent.data, target);\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,qBAAqB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EAAO,KAAK,GAAG,SAAS;CAAW;CACvE,MAAM,OAAO,MAAM,eACjB,YAA8B;EAC9B,MAAM,WAAW,MAAM,UAAU,UAAU,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,CAAC;EACjF,OAAO;GAAE,OAAO,IAAI,WAAW,MAAM,SAAS,YAAY,CAAC;GAAG;EAAS;CACxE,EAAA,CAAG,CACJ;CACA,IAAI,CAAC,KAAK,SACT,OAAO;EACN,KAAK,eAAe;GACnB,OAAO,eAAe,KAAK,KAAK;IAAE;IAAU,UAAU,OAAO;GAAI,CAAC;GAClE,QAAQ,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO;GAC7C,iBAAiB;GACjB;EACD,CAAC;EACD,SAAS;CACV;CAGD,MAAM,WAAW,sBAAsB,KAAK,KAAK,UAAU,MAAM;CACjE,IAAI,aAAa,KAAA,GAChB,OAAO;EAAE,KAAK;EAAU,SAAS;CAAM;CAGxC,OAAO,gBAAgB,KAAK,MAAM,MAAM;AACzC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { s as OpenCloudError } from "./network-error-P4An7nUB.mjs";
|
|
2
|
+
// src/errors/badge-cost-mismatch.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returned when Roblox refuses a badge create because its `expectedCost`
|
|
5
|
+
* differs from what the badge would actually cost (body error code `18`).
|
|
6
|
+
* Nothing is charged. A create sent with `expectedCost: 0` gets this once the
|
|
7
|
+
* universe has used its free badge quota for the day. The upstream `ApiError`
|
|
8
|
+
* is the `cause`.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.4.0
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { BadgeCostMismatchError } from "@bedrock-rbx/ocale";
|
|
16
|
+
*
|
|
17
|
+
* const error = new BadgeCostMismatchError(
|
|
18
|
+
* "Expected badge cost is different from the actual badge cost.",
|
|
19
|
+
* { code: "18", expectedCost: 0, statusCode: 403 },
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* // A free create was refused: the free badge quota is spent for today.
|
|
23
|
+
* expect(error.expectedCost).toBe(0);
|
|
24
|
+
* expect(error.statusCode).toBe(403);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
var BadgeCostMismatchError = class extends OpenCloudError {
|
|
28
|
+
expectedCost;
|
|
29
|
+
name = "BadgeCostMismatchError";
|
|
30
|
+
statusCode;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new BadgeCostMismatchError.
|
|
33
|
+
*
|
|
34
|
+
* @param message - Human-readable error description.
|
|
35
|
+
* @param options - Error options including the cost the create expected
|
|
36
|
+
* and the HTTP status of the refusal.
|
|
37
|
+
*/
|
|
38
|
+
constructor(message, options) {
|
|
39
|
+
super(message, options);
|
|
40
|
+
this.expectedCost = options.expectedCost;
|
|
41
|
+
this.statusCode = options.statusCode;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
// src/errors/badge-group-spend-permission.ts
|
|
45
|
+
/**
|
|
46
|
+
* Returned when Roblox refuses a badge create paid from group funds because
|
|
47
|
+
* the API key owner may not spend that group's funds (body error code `28`).
|
|
48
|
+
* The fix is a group role with permission to spend group funds. The upstream
|
|
49
|
+
* `ApiError` is the `cause`.
|
|
50
|
+
*
|
|
51
|
+
* @since 0.5.0
|
|
52
|
+
*/
|
|
53
|
+
var BadgeGroupSpendPermissionError = class extends OpenCloudError {
|
|
54
|
+
name = "BadgeGroupSpendPermissionError";
|
|
55
|
+
statusCode;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new BadgeGroupSpendPermissionError.
|
|
58
|
+
*
|
|
59
|
+
* @param message - Human-readable error description.
|
|
60
|
+
* @param options - Error options including the HTTP status of the refusal.
|
|
61
|
+
*/
|
|
62
|
+
constructor(message, options) {
|
|
63
|
+
super(message, options);
|
|
64
|
+
this.statusCode = options.statusCode;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// src/errors/badge-insufficient-funds.ts
|
|
68
|
+
/**
|
|
69
|
+
* Returned when Roblox refuses a badge create because the payer does not have
|
|
70
|
+
* enough Robux to pay for it (body error code `17`). The upstream `ApiError`
|
|
71
|
+
* is the `cause`.
|
|
72
|
+
*
|
|
73
|
+
* @since 0.5.0
|
|
74
|
+
*/
|
|
75
|
+
var BadgeInsufficientFundsError = class extends OpenCloudError {
|
|
76
|
+
name = "BadgeInsufficientFundsError";
|
|
77
|
+
statusCode;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new BadgeInsufficientFundsError.
|
|
80
|
+
*
|
|
81
|
+
* @param message - Human-readable error description.
|
|
82
|
+
* @param options - Error options including the HTTP status of the refusal.
|
|
83
|
+
*/
|
|
84
|
+
constructor(message, options) {
|
|
85
|
+
super(message, options);
|
|
86
|
+
this.statusCode = options.statusCode;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export { BadgeGroupSpendPermissionError as n, BadgeCostMismatchError as r, BadgeInsufficientFundsError as t };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=badge-insufficient-funds-BLFvQZt1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge-insufficient-funds-BLFvQZt1.mjs","names":[],"sources":["../src/errors/badge-cost-mismatch.ts","../src/errors/badge-group-spend-permission.ts","../src/errors/badge-insufficient-funds.ts"],"sourcesContent":["import { OpenCloudError, type OpenCloudErrorOptions } from \"./base.ts\";\n\n/**\n * Options for constructing a {@link BadgeCostMismatchError}.\n *\n * @since 0.4.0\n */\nexport interface BadgeCostMismatchErrorOptions extends OpenCloudErrorOptions {\n\t/** The `expectedCost` the create sent, or `undefined` when it sent none. */\n\treadonly expectedCost: number | undefined;\n\t/** HTTP status code of the refusal. */\n\treadonly statusCode: number;\n}\n\n/**\n * Returned when Roblox refuses a badge create because its `expectedCost`\n * differs from what the badge would actually cost (body error code `18`).\n * Nothing is charged. A create sent with `expectedCost: 0` gets this once the\n * universe has used its free badge quota for the day. The upstream `ApiError`\n * is the `cause`.\n *\n * @since 0.4.0\n *\n * @example\n *\n * ```ts\n * import { BadgeCostMismatchError } from \"@bedrock-rbx/ocale\";\n *\n * const error = new BadgeCostMismatchError(\n * \"Expected badge cost is different from the actual badge cost.\",\n * { code: \"18\", expectedCost: 0, statusCode: 403 },\n * );\n *\n * // A free create was refused: the free badge quota is spent for today.\n * expect(error.expectedCost).toBe(0);\n * expect(error.statusCode).toBe(403);\n * ```\n */\nexport class BadgeCostMismatchError extends OpenCloudError {\n\tpublic readonly expectedCost: number | undefined;\n\tpublic override readonly name: string = \"BadgeCostMismatchError\";\n\tpublic readonly statusCode: number;\n\n\t/**\n\t * Creates a new BadgeCostMismatchError.\n\t *\n\t * @param message - Human-readable error description.\n\t * @param options - Error options including the cost the create expected\n\t * and the HTTP status of the refusal.\n\t */\n\tconstructor(message: string, options: BadgeCostMismatchErrorOptions) {\n\t\tsuper(message, options);\n\t\tthis.expectedCost = options.expectedCost;\n\t\tthis.statusCode = options.statusCode;\n\t}\n}\n","import { OpenCloudError, type OpenCloudErrorOptions } from \"./base.ts\";\n\n/**\n * Options for constructing a {@link BadgeGroupSpendPermissionError}.\n *\n * @since 0.5.0\n */\nexport interface BadgeGroupSpendPermissionErrorOptions extends OpenCloudErrorOptions {\n\t/** HTTP status code of the refusal. */\n\treadonly statusCode: number;\n}\n\n/**\n * Returned when Roblox refuses a badge create paid from group funds because\n * the API key owner may not spend that group's funds (body error code `28`).\n * The fix is a group role with permission to spend group funds. The upstream\n * `ApiError` is the `cause`.\n *\n * @since 0.5.0\n */\nexport class BadgeGroupSpendPermissionError extends OpenCloudError {\n\tpublic override readonly name: string = \"BadgeGroupSpendPermissionError\";\n\tpublic readonly statusCode: number;\n\n\t/**\n\t * Creates a new BadgeGroupSpendPermissionError.\n\t *\n\t * @param message - Human-readable error description.\n\t * @param options - Error options including the HTTP status of the refusal.\n\t */\n\tconstructor(message: string, options: BadgeGroupSpendPermissionErrorOptions) {\n\t\tsuper(message, options);\n\t\tthis.statusCode = options.statusCode;\n\t}\n}\n","import { OpenCloudError, type OpenCloudErrorOptions } from \"./base.ts\";\n\n/**\n * Options for constructing a {@link BadgeInsufficientFundsError}.\n *\n * @since 0.5.0\n */\nexport interface BadgeInsufficientFundsErrorOptions extends OpenCloudErrorOptions {\n\t/** HTTP status code of the refusal. */\n\treadonly statusCode: number;\n}\n\n/**\n * Returned when Roblox refuses a badge create because the payer does not have\n * enough Robux to pay for it (body error code `17`). The upstream `ApiError`\n * is the `cause`.\n *\n * @since 0.5.0\n */\nexport class BadgeInsufficientFundsError extends OpenCloudError {\n\tpublic override readonly name: string = \"BadgeInsufficientFundsError\";\n\tpublic readonly statusCode: number;\n\n\t/**\n\t * Creates a new BadgeInsufficientFundsError.\n\t *\n\t * @param message - Human-readable error description.\n\t * @param options - Error options including the HTTP status of the refusal.\n\t */\n\tconstructor(message: string, options: BadgeInsufficientFundsErrorOptions) {\n\t\tsuper(message, options);\n\t\tthis.statusCode = options.statusCode;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,yBAAb,cAA4C,eAAe;CAC1D;CACA,OAAwC;CACxC;;;;;;;;CASA,YAAY,SAAiB,SAAwC;EACpE,MAAM,SAAS,OAAO;EACtB,KAAK,eAAe,QAAQ;EAC5B,KAAK,aAAa,QAAQ;CAC3B;AACD;;;;;;;;;;ACnCA,IAAa,iCAAb,cAAoD,eAAe;CAClE,OAAwC;CACxC;;;;;;;CAQA,YAAY,SAAiB,SAAgD;EAC5E,MAAM,SAAS,OAAO;EACtB,KAAK,aAAa,QAAQ;CAC3B;AACD;;;;;;;;;ACfA,IAAa,8BAAb,cAAiD,eAAe;CAC/D,OAAwC;CACxC;;;;;;;CAQA,YAAY,SAAiB,SAA6C;EACzE,MAAM,SAAS,OAAO;EACtB,KAAK,aAAa,QAAQ;CAC3B;AACD"}
|