@bedrock-rbx/ocale 0.4.0 → 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 +1 -0
- 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 +136 -17
- package/dist/badges.d.mts.map +1 -1
- package/dist/badges.mjs +375 -99
- package/dist/badges.mjs.map +1 -1
- package/dist/{capacity-admission-hycCFkTo.d.mts → capacity-admission-Ce2V9QNb.d.mts} +2 -10
- package/dist/capacity-admission-Ce2V9QNb.d.mts.map +1 -0
- package/dist/{data.generated-D_vpa5-g.d.mts → data.generated-B4Fztv_7.d.mts} +1 -3
- package/dist/{data.generated-D_vpa5-g.d.mts.map → data.generated-B4Fztv_7.d.mts.map} +1 -1
- package/dist/developer-products.d.mts +29 -11
- package/dist/developer-products.d.mts.map +1 -1
- package/dist/developer-products.mjs +104 -18
- package/dist/developer-products.mjs.map +1 -1
- package/dist/game-passes.d.mts +2 -10
- package/dist/game-passes.d.mts.map +1 -1
- package/dist/game-passes.mjs +12 -18
- package/dist/game-passes.mjs.map +1 -1
- package/dist/index.d.mts +58 -39
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -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 +1 -3
- package/dist/locales.d.mts.map +1 -1
- package/dist/locales.mjs +2 -4
- package/dist/locales.mjs.map +1 -1
- package/dist/luau-execution.d.mts +2 -8
- package/dist/luau-execution.d.mts.map +1 -1
- package/dist/luau-execution.mjs +7 -11
- package/dist/luau-execution.mjs.map +1 -1
- package/dist/{network-error-iVSng5MT.mjs → network-error-P4An7nUB.mjs} +5 -9
- package/dist/{network-error-iVSng5MT.mjs.map → network-error-P4An7nUB.mjs.map} +1 -1
- package/dist/places.d.mts +57 -9
- package/dist/places.d.mts.map +1 -1
- package/dist/places.mjs +127 -21
- package/dist/places.mjs.map +1 -1
- package/dist/{poll-timeout-DzztDymd.mjs → poll-timeout-BCxgN97O.mjs} +4 -6
- package/dist/{poll-timeout-DzztDymd.mjs.map → poll-timeout-BCxgN97O.mjs.map} +1 -1
- package/dist/{polling-helpers-DfF5dspc.mjs → polling-helpers-BtEYR5dN.mjs} +19 -30
- package/dist/polling-helpers-BtEYR5dN.mjs.map +1 -0
- package/dist/{price-information-DEkEQ8Pq.mjs → price-information--d6GZAcp.mjs} +3 -4
- package/dist/{price-information-DEkEQ8Pq.mjs.map → price-information--d6GZAcp.mjs.map} +1 -1
- package/dist/{resource-client-BCKukheG.d.mts → resource-client-CF8SPsV8.d.mts} +3 -9
- package/dist/resource-client-CF8SPsV8.d.mts.map +1 -0
- package/dist/{resource-client-CaIVr-go.mjs → resource-client-Cm_bPcCs.mjs} +23 -59
- package/dist/resource-client-Cm_bPcCs.mjs.map +1 -0
- package/dist/{retry-C2oHesDx.d.mts → retry-DYxm_eBU.d.mts} +2 -6
- package/dist/retry-DYxm_eBU.d.mts.map +1 -0
- package/dist/{retry-CMRDvAR4.mjs → retry-Dv5TsY9O.mjs} +50 -52
- 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 +2 -12
- package/dist/storage.d.mts.map +1 -1
- package/dist/storage.mjs +12 -20
- package/dist/storage.mjs.map +1 -1
- package/dist/testing.d.mts +2 -54
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +16 -30
- 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-CdMr_J1M.d.mts → types-Z4abDJfK.d.mts} +1 -9
- package/dist/types-Z4abDJfK.d.mts.map +1 -0
- package/dist/universes.d.mts +4 -18
- package/dist/universes.d.mts.map +1 -1
- package/dist/universes.mjs +27 -47
- package/dist/universes.mjs.map +1 -1
- package/dist/{validation-964VNlbp.mjs → validation-kaTLLAD1.mjs} +3 -4
- package/dist/{validation-964VNlbp.mjs.map → validation-kaTLLAD1.mjs.map} +1 -1
- package/dist/{wire-DJqupefn.d.mts → wire-DDG87I-d.d.mts} +1 -3
- package/dist/wire-DDG87I-d.d.mts.map +1 -0
- package/package.json +8 -7
- package/dist/badge-cost-mismatch-DrlvhlQc.mjs +0 -47
- package/dist/badge-cost-mismatch-DrlvhlQc.mjs.map +0 -1
- package/dist/capacity-admission-hycCFkTo.d.mts.map +0 -1
- package/dist/polling-helpers-DfF5dspc.mjs.map +0 -1
- package/dist/resource-client-BCKukheG.d.mts.map +0 -1
- package/dist/resource-client-CaIVr-go.mjs.map +0 -1
- package/dist/retry-C2oHesDx.d.mts.map +0 -1
- package/dist/retry-CMRDvAR4.mjs.map +0 -1
- package/dist/types-CdMr_J1M.d.mts.map +0 -1
- package/dist/wire-DJqupefn.d.mts.map +0 -1
package/dist/badges.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { t as toBlob } from "./to-blob-Bqu7bmlE.mjs";
|
|
2
|
+
import { a as ApiError } from "./network-error-P4An7nUB.mjs";
|
|
3
|
+
import { n as BadgeGroupSpendPermissionError, r as BadgeCostMismatchError, t as BadgeInsufficientFundsError } from "./badge-insufficient-funds-BLFvQZt1.mjs";
|
|
4
|
+
import { A as waitForQuotaReset, N as isRecord, m as UnexpectedResponseError, r as IDEMPOTENT_METHOD_DEFAULTS, t as CREATE_METHOD_DEFAULTS } from "./retry-Dv5TsY9O.mjs";
|
|
5
|
+
import { n as okRequest, r as parseEmptyResponse, s as toJsonDetails, t as ResourceClient } from "./resource-client-Cm_bPcCs.mjs";
|
|
6
|
+
import { t as isDateTimeString } from "./is-date-time-string-C91G44SI.mjs";
|
|
7
|
+
// src/domains/badges/badges/builders.ts
|
|
7
8
|
/**
|
|
8
9
|
* Builds a `POST` request for the legacy "create badge" endpoint.
|
|
9
10
|
*
|
|
@@ -14,7 +15,7 @@ import { c as isDateTimeString, n as okRequest, r as parseEmptyResponse, s as to
|
|
|
14
15
|
function buildCreateRequest(parameters) {
|
|
15
16
|
const body = new FormData();
|
|
16
17
|
body.append("name", parameters.name);
|
|
17
|
-
body.append("files", toBlob(parameters.icon));
|
|
18
|
+
if (parameters.icon !== void 0) body.append("files", toBlob(parameters.icon), "icon");
|
|
18
19
|
if (parameters.description !== void 0) body.append("description", parameters.description);
|
|
19
20
|
if (parameters.isActive !== void 0) body.append("isActive", String(parameters.isActive));
|
|
20
21
|
if (parameters.expectedCost !== void 0) body.append("expectedCost", String(parameters.expectedCost));
|
|
@@ -44,13 +45,93 @@ function buildUpdateRequest$1(parameters) {
|
|
|
44
45
|
url: `/legacy-badges/v1/badges/${parameters.badgeId}`
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Builds a `GET` request for the unauthenticated "get badge" endpoint.
|
|
50
|
+
*
|
|
51
|
+
* @param parameters - The badge to read.
|
|
52
|
+
* @returns A pure {@link HttpRequest} describing the read.
|
|
53
|
+
*/
|
|
54
|
+
function buildGetRequest({ badgeId }) {
|
|
55
|
+
return {
|
|
56
|
+
method: "GET",
|
|
57
|
+
url: `/v1/badges/${badgeId}`
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Builds a `GET` request for the unauthenticated "list universe badges"
|
|
62
|
+
* endpoint. `pageSize` goes out as `limit` and `pageToken` as `cursor`, each
|
|
63
|
+
* only when defined, so the server applies its own defaults otherwise.
|
|
64
|
+
*
|
|
65
|
+
* @param parameters - Universe identifier plus optional paging fields.
|
|
66
|
+
* @returns A pure {@link HttpRequest} describing the list call.
|
|
67
|
+
*/
|
|
68
|
+
function buildListRequest(parameters) {
|
|
69
|
+
const query = new URLSearchParams();
|
|
70
|
+
if (parameters.pageSize !== void 0) query.append("limit", String(parameters.pageSize));
|
|
71
|
+
if (parameters.pageToken !== void 0) query.append("cursor", parameters.pageToken);
|
|
72
|
+
const queryString = query.toString();
|
|
73
|
+
const base = `/v1/universes/${parameters.universeId}/badges`;
|
|
74
|
+
return {
|
|
75
|
+
method: "GET",
|
|
76
|
+
url: queryString === "" ? base : `${base}?${queryString}`
|
|
77
|
+
};
|
|
78
|
+
}
|
|
47
79
|
function toPaymentSourceWire(source) {
|
|
48
80
|
return source === "User" ? "1" : "2";
|
|
49
81
|
}
|
|
50
|
-
|
|
51
|
-
|
|
82
|
+
// src/domains/badges/free-quota/operations.ts
|
|
83
|
+
/** Origin of the unauthenticated free badge quota endpoint. */
|
|
84
|
+
const FREE_QUOTA_BASE_URL = "https://badges.roblox.com";
|
|
85
|
+
/**
|
|
86
|
+
* Per-second request ceiling for reading the free badge quota. Roblox
|
|
87
|
+
* reports 60 requests per 60 seconds, per caller.
|
|
88
|
+
*/
|
|
89
|
+
const FREE_QUOTA_OPERATION_LIMIT = Object.freeze({
|
|
90
|
+
maxPerSecond: 1,
|
|
91
|
+
operationKey: "badges.free-quota"
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Builds the `GET` request for the free badge quota of a universe.
|
|
95
|
+
*
|
|
96
|
+
* @param parameters - The universe to read.
|
|
97
|
+
* @returns A pure {@link HttpRequest} describing the read.
|
|
98
|
+
*/
|
|
99
|
+
function buildFreeQuotaRequest({ universeId }) {
|
|
100
|
+
return {
|
|
101
|
+
method: "GET",
|
|
102
|
+
url: `/v1/universes/${universeId}/free-badges-quota`
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parses the free badge quota body, a bare non-negative integer.
|
|
107
|
+
*
|
|
108
|
+
* @param response - The full {@link HttpResponse}.
|
|
109
|
+
* @returns The free badges left today, or an `UnexpectedResponseError` when
|
|
110
|
+
* the body is not a count.
|
|
111
|
+
*/
|
|
112
|
+
function parseFreeQuotaResponse({ body, status: statusCode }) {
|
|
113
|
+
if (!isCount(body)) return {
|
|
114
|
+
err: new UnexpectedResponseError("Malformed free badge quota response", {
|
|
115
|
+
details: toJsonDetails(body),
|
|
116
|
+
statusCode
|
|
117
|
+
}),
|
|
118
|
+
success: false
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
data: body,
|
|
122
|
+
success: true
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function isCount(value) {
|
|
126
|
+
return Number.isSafeInteger(value) && Number(value) >= 0;
|
|
127
|
+
}
|
|
128
|
+
// src/domains/badges/badges/operations.ts
|
|
52
129
|
/** Body error code Roblox sends when a create's expected cost is wrong. */
|
|
53
130
|
const COST_MISMATCH_CODE = "18";
|
|
131
|
+
/** Body error code Roblox sends when the payer cannot afford a create. */
|
|
132
|
+
const INSUFFICIENT_FUNDS_CODE = "17";
|
|
133
|
+
/** Body error code Roblox sends when the caller may not spend group funds. */
|
|
134
|
+
const GROUP_SPEND_PERMISSION_CODE = "28";
|
|
54
135
|
/**
|
|
55
136
|
* Per-second request ceiling for creating a badge, sourced from
|
|
56
137
|
* `x-roblox-rate-limits` on the legacy badges create operation in the
|
|
@@ -73,6 +154,27 @@ const UPDATE_OPERATION_LIMIT = Object.freeze({
|
|
|
73
154
|
operationKey: "badges.update"
|
|
74
155
|
});
|
|
75
156
|
/**
|
|
157
|
+
* Origin of the unauthenticated badge read endpoints, shared with the free
|
|
158
|
+
* quota read.
|
|
159
|
+
*/
|
|
160
|
+
const READ_BASE_URL = FREE_QUOTA_BASE_URL;
|
|
161
|
+
/**
|
|
162
|
+
* Per-second request ceiling for reading one badge. Roblox reports 600
|
|
163
|
+
* requests per 60 seconds, per caller.
|
|
164
|
+
*/
|
|
165
|
+
const GET_OPERATION_LIMIT = Object.freeze({
|
|
166
|
+
maxPerSecond: 10,
|
|
167
|
+
operationKey: "badges.get"
|
|
168
|
+
});
|
|
169
|
+
/**
|
|
170
|
+
* Per-second request ceiling for listing the badges of a universe. Roblox
|
|
171
|
+
* reports 100 requests per 60 seconds, per caller.
|
|
172
|
+
*/
|
|
173
|
+
const LIST_OPERATION_LIMIT = Object.freeze({
|
|
174
|
+
maxPerSecond: 100 / 60,
|
|
175
|
+
operationKey: "badges.list"
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
76
178
|
* Scopes the API key or OAuth token must carry to create a badge,
|
|
77
179
|
* sourced from `x-roblox-scopes` on the legacy badges create operation
|
|
78
180
|
* in the vendored OpenAPI schema. The trailing
|
|
@@ -87,26 +189,34 @@ const CREATE_REQUIRED_SCOPES = Object.freeze(["legacy-universe.badge:manage-and-
|
|
|
87
189
|
*/
|
|
88
190
|
const UPDATE_REQUIRED_SCOPES = Object.freeze(["legacy-universe.badge:write"]);
|
|
89
191
|
/**
|
|
90
|
-
* Builds the refinement that turns a create refused
|
|
91
|
-
* a
|
|
92
|
-
*
|
|
192
|
+
* Builds the refinement that turns a create refused for a cost or payment
|
|
193
|
+
* reason into a typed error, whatever its status: body code `18` becomes a
|
|
194
|
+
* {@link BadgeCostMismatchError}, code `17` a
|
|
195
|
+
* {@link BadgeInsufficientFundsError}, and code `28` a
|
|
196
|
+
* {@link BadgeGroupSpendPermissionError}. Every other error passes through
|
|
197
|
+
* unchanged.
|
|
93
198
|
*
|
|
94
199
|
* @param expectedCost - The `expectedCost` the create sent, if any.
|
|
95
200
|
* @returns The refinement for one create call.
|
|
96
201
|
*/
|
|
97
202
|
function refineCreateError(expectedCost) {
|
|
98
203
|
return (error) => {
|
|
99
|
-
if (!(error instanceof ApiError)
|
|
100
|
-
|
|
204
|
+
if (!(error instanceof ApiError)) return error;
|
|
205
|
+
const options = {
|
|
101
206
|
cause: error,
|
|
102
207
|
code: error.code,
|
|
103
|
-
expectedCost,
|
|
104
208
|
statusCode: error.statusCode
|
|
209
|
+
};
|
|
210
|
+
if (error.code === COST_MISMATCH_CODE) return new BadgeCostMismatchError(error.message, {
|
|
211
|
+
...options,
|
|
212
|
+
expectedCost
|
|
105
213
|
});
|
|
214
|
+
if (error.code === INSUFFICIENT_FUNDS_CODE) return new BadgeInsufficientFundsError(error.message, options);
|
|
215
|
+
if (error.code === GROUP_SPEND_PERMISSION_CODE) return new BadgeGroupSpendPermissionError(error.message, options);
|
|
216
|
+
return error;
|
|
106
217
|
};
|
|
107
218
|
}
|
|
108
|
-
|
|
109
|
-
//#region src/domains/badges/badges/parsers.ts
|
|
219
|
+
// src/domains/badges/badges/parsers.ts
|
|
110
220
|
/**
|
|
111
221
|
* Parses a successful Badges API response into the public `Badge` shape,
|
|
112
222
|
* returning a `Result` so callers can handle malformed payloads without
|
|
@@ -120,36 +230,62 @@ function refineCreateError(expectedCost) {
|
|
|
120
230
|
* `UnexpectedResponseError` when the body does not match the wire schema.
|
|
121
231
|
*/
|
|
122
232
|
function parseBadgeResponse({ body, status: statusCode }) {
|
|
123
|
-
if (!isBadgeResponseV2Wire(body)) return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
233
|
+
if (!isBadgeResponseV2Wire(body)) return malformedBadge(statusCode, body);
|
|
234
|
+
return {
|
|
235
|
+
data: {
|
|
236
|
+
...copySharedFields(body),
|
|
237
|
+
awarder: copyAwarder(body.awarder)
|
|
238
|
+
},
|
|
239
|
+
success: true
|
|
129
240
|
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Parses the body of the unauthenticated badge read endpoints into the public
|
|
244
|
+
* `BadgeDetails` shape.
|
|
245
|
+
*
|
|
246
|
+
* @param response - The full {@link HttpResponse}.
|
|
247
|
+
* @returns A success result wrapping the converted `BadgeDetails`, or an
|
|
248
|
+
* `UnexpectedResponseError` when the body does not match the wire schema.
|
|
249
|
+
*/
|
|
250
|
+
function parseBadgeDetailsResponse({ body, status: statusCode }) {
|
|
251
|
+
if (!isBadgeResponseWire(body)) return malformedBadge(statusCode, body);
|
|
130
252
|
return {
|
|
131
253
|
data: {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
awarder: copyAwarder(body.awarder),
|
|
135
|
-
createdAt: new Date(body.created),
|
|
136
|
-
description: body.description,
|
|
137
|
-
displayDescription: body.displayDescription,
|
|
138
|
-
displayIconImageId: body.displayIconImageId === 0 ? void 0 : String(body.displayIconImageId),
|
|
139
|
-
displayName: body.displayName,
|
|
140
|
-
enabled: body.enabled,
|
|
141
|
-
iconImageId: body.iconImageId === 0 ? void 0 : String(body.iconImageId),
|
|
142
|
-
statistics: copyStatistics(body.statistics),
|
|
143
|
-
updatedAt: new Date(body.updated)
|
|
254
|
+
...copySharedFields(body),
|
|
255
|
+
awardingUniverse: copyAwardingUniverse(body.awardingUniverse)
|
|
144
256
|
},
|
|
145
257
|
success: true
|
|
146
258
|
};
|
|
147
259
|
}
|
|
148
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Parses a badge list page, keeping its cursor and converting each item with
|
|
262
|
+
* the same validation as a single badge read. A JSON `null` cursor becomes
|
|
263
|
+
* `undefined`.
|
|
264
|
+
*
|
|
265
|
+
* @param response - The HTTP response to parse.
|
|
266
|
+
* @returns The parsed page or an unexpected response error.
|
|
267
|
+
*/
|
|
268
|
+
function parseBadgesListResponse(response) {
|
|
269
|
+
const { body, status: statusCode } = response;
|
|
270
|
+
if (!isRecord(body) || !Array.isArray(body["data"])) return malformedBadgesList(statusCode, body);
|
|
271
|
+
const nextPageToken = body["nextPageCursor"] ?? void 0;
|
|
272
|
+
if (nextPageToken !== void 0 && typeof nextPageToken !== "string") return malformedBadgesList(statusCode, body);
|
|
273
|
+
const items = [];
|
|
274
|
+
const badges = body["data"];
|
|
275
|
+
for (const item of badges) {
|
|
276
|
+
const parsed = parseBadgeDetailsResponse({
|
|
277
|
+
...response,
|
|
278
|
+
body: item
|
|
279
|
+
});
|
|
280
|
+
if (!parsed.success) return malformedBadgesList(statusCode, body);
|
|
281
|
+
items.push(parsed.data);
|
|
282
|
+
}
|
|
149
283
|
return {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
284
|
+
data: {
|
|
285
|
+
items,
|
|
286
|
+
nextPageToken
|
|
287
|
+
},
|
|
288
|
+
success: true
|
|
153
289
|
};
|
|
154
290
|
}
|
|
155
291
|
function copyStatistics(statistics) {
|
|
@@ -159,6 +295,28 @@ function copyStatistics(statistics) {
|
|
|
159
295
|
winRatePercentage: statistics.winRatePercentage
|
|
160
296
|
};
|
|
161
297
|
}
|
|
298
|
+
function copySharedFields(body) {
|
|
299
|
+
return {
|
|
300
|
+
id: String(body.id),
|
|
301
|
+
name: body.name,
|
|
302
|
+
createdAt: new Date(body.created),
|
|
303
|
+
description: body.description,
|
|
304
|
+
displayDescription: body.displayDescription,
|
|
305
|
+
displayIconImageId: body.displayIconImageId === 0 ? void 0 : String(body.displayIconImageId),
|
|
306
|
+
displayName: body.displayName,
|
|
307
|
+
enabled: body.enabled,
|
|
308
|
+
iconImageId: body.iconImageId === 0 ? void 0 : String(body.iconImageId),
|
|
309
|
+
statistics: copyStatistics(body.statistics),
|
|
310
|
+
updatedAt: new Date(body.updated)
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function copyAwarder(awarder) {
|
|
314
|
+
return {
|
|
315
|
+
id: String(awarder.id),
|
|
316
|
+
name: awarder.name,
|
|
317
|
+
type: awarder.type
|
|
318
|
+
};
|
|
319
|
+
}
|
|
162
320
|
function hasRequiredPrimitiveFields(body) {
|
|
163
321
|
return typeof body["id"] === "number" && typeof body["name"] === "string" && typeof body["description"] === "string" && typeof body["displayName"] === "string" && typeof body["displayDescription"] === "string" && typeof body["enabled"] === "boolean" && typeof body["iconImageId"] === "number" && typeof body["displayIconImageId"] === "number" && isDateTimeString(body["created"]) && isDateTimeString(body["updated"]);
|
|
164
322
|
}
|
|
@@ -177,78 +335,86 @@ function isBadgeResponseV2Wire(body) {
|
|
|
177
335
|
if (!isBadgeStatisticsWire(body["statistics"])) return false;
|
|
178
336
|
return true;
|
|
179
337
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
338
|
+
function malformedBadge(statusCode, body) {
|
|
339
|
+
return {
|
|
340
|
+
err: new UnexpectedResponseError("Malformed badge response", {
|
|
341
|
+
details: toJsonDetails(body),
|
|
342
|
+
statusCode
|
|
343
|
+
}),
|
|
344
|
+
success: false
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function copyAwardingUniverse(universe) {
|
|
348
|
+
return {
|
|
349
|
+
id: String(universe.id),
|
|
350
|
+
name: universe.name,
|
|
351
|
+
rootPlaceId: String(universe.rootPlaceId)
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function isBadgeAwardingUniverseWire(value) {
|
|
355
|
+
if (!isRecord(value)) return false;
|
|
356
|
+
return typeof value["id"] === "number" && typeof value["name"] === "string" && typeof value["rootPlaceId"] === "number";
|
|
357
|
+
}
|
|
358
|
+
function isBadgeResponseWire(body) {
|
|
359
|
+
return isRecord(body) && hasRequiredPrimitiveFields(body) && isBadgeStatisticsWire(body["statistics"]) && isBadgeAwardingUniverseWire(body["awardingUniverse"]);
|
|
360
|
+
}
|
|
361
|
+
function malformedBadgesList(statusCode, body) {
|
|
362
|
+
return {
|
|
363
|
+
err: new UnexpectedResponseError("Malformed badges list response", {
|
|
364
|
+
details: toJsonDetails(body),
|
|
365
|
+
statusCode
|
|
366
|
+
}),
|
|
367
|
+
success: false
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
// src/domains/badges/metadata/operations.ts
|
|
371
|
+
/** Origin of the unauthenticated badge metadata endpoint. */
|
|
372
|
+
const METADATA_BASE_URL = "https://badges.roblox.com";
|
|
184
373
|
/**
|
|
185
|
-
* Per-second request ceiling for reading the
|
|
186
|
-
* reports
|
|
374
|
+
* Per-second request ceiling for reading the badge metadata. The vendored
|
|
375
|
+
* spec declares no limit; Roblox reports 100 requests per 60 seconds, per
|
|
376
|
+
* caller.
|
|
187
377
|
*/
|
|
188
|
-
const
|
|
189
|
-
maxPerSecond:
|
|
190
|
-
operationKey: "badges.
|
|
378
|
+
const METADATA_OPERATION_LIMIT = Object.freeze({
|
|
379
|
+
maxPerSecond: 100 / 60,
|
|
380
|
+
operationKey: "badges.metadata"
|
|
191
381
|
});
|
|
192
382
|
/**
|
|
193
|
-
* Builds the `GET` request for the
|
|
383
|
+
* Builds the `GET` request for the badge metadata.
|
|
194
384
|
*
|
|
195
|
-
* @param parameters - The universe to read.
|
|
196
385
|
* @returns A pure {@link HttpRequest} describing the read.
|
|
197
386
|
*/
|
|
198
|
-
function
|
|
387
|
+
function buildMetadataRequest() {
|
|
199
388
|
return {
|
|
200
389
|
method: "GET",
|
|
201
|
-
url:
|
|
390
|
+
url: "/v1/badges/metadata"
|
|
202
391
|
};
|
|
203
392
|
}
|
|
204
393
|
/**
|
|
205
|
-
* Parses the
|
|
394
|
+
* Parses the badge metadata body down to its `badgeCreationPrice`.
|
|
206
395
|
*
|
|
207
396
|
* @param response - The full {@link HttpResponse}.
|
|
208
|
-
* @returns The
|
|
209
|
-
* the body
|
|
397
|
+
* @returns The badge creation price in Robux, or an
|
|
398
|
+
* `UnexpectedResponseError` when the body carries no valid price.
|
|
210
399
|
*/
|
|
211
|
-
function
|
|
212
|
-
|
|
213
|
-
|
|
400
|
+
function parseCreationPriceResponse({ body, status: statusCode }) {
|
|
401
|
+
const price = isRecord(body) ? body["badgeCreationPrice"] : void 0;
|
|
402
|
+
if (!isPrice(price)) return {
|
|
403
|
+
err: new UnexpectedResponseError("Malformed badge metadata response", {
|
|
214
404
|
details: toJsonDetails(body),
|
|
215
405
|
statusCode
|
|
216
406
|
}),
|
|
217
407
|
success: false
|
|
218
408
|
};
|
|
219
409
|
return {
|
|
220
|
-
data:
|
|
410
|
+
data: price,
|
|
221
411
|
success: true
|
|
222
412
|
};
|
|
223
413
|
}
|
|
224
|
-
|
|
225
|
-
* Points a free badge quota 429 at `x-ratelimit-reset`. The endpoint's
|
|
226
|
-
* `retry-after` is shorter than its window, which reopens only at the reset.
|
|
227
|
-
* Any other error, or a 429 without a reset, passes through unchanged.
|
|
228
|
-
*
|
|
229
|
-
* @param error - The transport error of one attempt.
|
|
230
|
-
* @returns The error with its wait set to the reported reset.
|
|
231
|
-
*/
|
|
232
|
-
function waitForQuotaReset(error) {
|
|
233
|
-
if (!(error instanceof RateLimitError)) return error;
|
|
234
|
-
const resetSeconds = parseQuotaResetSeconds(error.responseHeaders?.["x-ratelimit-reset"]);
|
|
235
|
-
if (resetSeconds === void 0) return error;
|
|
236
|
-
return new RateLimitError(error.message, {
|
|
237
|
-
cause: error.cause,
|
|
238
|
-
code: error.code,
|
|
239
|
-
details: error.details,
|
|
240
|
-
remaining: error.remaining,
|
|
241
|
-
responseHeaders: error.responseHeaders,
|
|
242
|
-
retryAfterSeconds: resetSeconds,
|
|
243
|
-
source: error.source,
|
|
244
|
-
statusCode: error.statusCode
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
function isCount(value) {
|
|
414
|
+
function isPrice(value) {
|
|
248
415
|
return Number.isSafeInteger(value) && Number(value) >= 0;
|
|
249
416
|
}
|
|
250
|
-
|
|
251
|
-
//#region src/domains/game-internationalization/badge-icon/builders.ts
|
|
417
|
+
// src/domains/game-internationalization/badge-icon/builders.ts
|
|
252
418
|
/**
|
|
253
419
|
* Builds a `POST` request for the localized "upload badge icon" endpoint. A
|
|
254
420
|
* successful upload replaces any existing icon for the same
|
|
@@ -267,8 +433,7 @@ function buildUploadIconRequest$1(parameters) {
|
|
|
267
433
|
url: `/legacy-game-internationalization/v1/badges/${parameters.badgeId}/icons/language-codes/${parameters.languageCode}`
|
|
268
434
|
};
|
|
269
435
|
}
|
|
270
|
-
|
|
271
|
-
//#region src/domains/game-internationalization/badge-name-description/builders.ts
|
|
436
|
+
// src/domains/game-internationalization/badge-name-description/builders.ts
|
|
272
437
|
/**
|
|
273
438
|
* Builds a `PATCH` request for the localized "update badge name/description"
|
|
274
439
|
* endpoint. Either `name`, `description`, or both may be supplied; omitted
|
|
@@ -289,8 +454,7 @@ function buildUpdateRequest(parameters) {
|
|
|
289
454
|
url: `/legacy-game-internationalization/v1/badges/${parameters.badgeId}/name-description/language-codes/${parameters.languageCode}`
|
|
290
455
|
};
|
|
291
456
|
}
|
|
292
|
-
|
|
293
|
-
//#region src/domains/game-internationalization/badge-name-description/operations.ts
|
|
457
|
+
// src/domains/game-internationalization/badge-name-description/operations.ts
|
|
294
458
|
/**
|
|
295
459
|
* Per-second request ceiling for badge localization Operations, from each
|
|
296
460
|
* operation's `x-roblox-rate-limits.perApiKeyOwner` in the vendored schema
|
|
@@ -310,8 +474,7 @@ const LOCALIZATION_OPERATION_LIMIT = Object.freeze({
|
|
|
310
474
|
* endpoints in the vendored OpenAPI schema.
|
|
311
475
|
*/
|
|
312
476
|
const LOCALIZATION_REQUIRED_SCOPES = Object.freeze(["legacy-badge:manage"]);
|
|
313
|
-
|
|
314
|
-
//#region src/domains/publish/badge-icon/builders.ts
|
|
477
|
+
// src/domains/publish/badge-icon/builders.ts
|
|
315
478
|
/**
|
|
316
479
|
* Builds a `POST` request for the legacy "upload badge icon" endpoint. A
|
|
317
480
|
* successful upload replaces any existing source-language icon on the
|
|
@@ -322,15 +485,14 @@ const LOCALIZATION_REQUIRED_SCOPES = Object.freeze(["legacy-badge:manage"]);
|
|
|
322
485
|
*/
|
|
323
486
|
function buildUploadIconRequest(parameters) {
|
|
324
487
|
const body = new FormData();
|
|
325
|
-
body.append("Files", toBlob(parameters.icon));
|
|
488
|
+
body.append("Files", toBlob(parameters.icon), "icon");
|
|
326
489
|
return {
|
|
327
490
|
body,
|
|
328
491
|
method: "POST",
|
|
329
492
|
url: `/legacy-publish/v1/badges/${parameters.badgeId}/icon`
|
|
330
493
|
};
|
|
331
494
|
}
|
|
332
|
-
|
|
333
|
-
//#region src/domains/publish/badge-icon/operations.ts
|
|
495
|
+
// src/domains/publish/badge-icon/operations.ts
|
|
334
496
|
/**
|
|
335
497
|
* Per-second request ceiling for uploading a badge icon, sourced from
|
|
336
498
|
* `x-roblox-rate-limits` on the legacy badge icon upload operation in
|
|
@@ -349,8 +511,7 @@ const UPLOAD_ICON_OPERATION_LIMIT = Object.freeze({
|
|
|
349
511
|
* operation in the vendored OpenAPI schema.
|
|
350
512
|
*/
|
|
351
513
|
const UPLOAD_ICON_REQUIRED_SCOPES = Object.freeze(["legacy-badge:manage"]);
|
|
352
|
-
|
|
353
|
-
//#region src/domains/publish/badge-icon/parsers.ts
|
|
514
|
+
// src/domains/publish/badge-icon/parsers.ts
|
|
354
515
|
/**
|
|
355
516
|
* Parses a badge icon upload response, whose `targetId` is the asset ID of
|
|
356
517
|
* the uploaded icon.
|
|
@@ -376,8 +537,7 @@ function parseUploadIconResponse({ body, status: statusCode }) {
|
|
|
376
537
|
function isAssetId(value) {
|
|
377
538
|
return Number.isSafeInteger(value) && Number(value) > 0;
|
|
378
539
|
}
|
|
379
|
-
|
|
380
|
-
//#region src/resources/badges/client.ts
|
|
540
|
+
// src/resources/badges/client.ts
|
|
381
541
|
function makeSpec(spec) {
|
|
382
542
|
return Object.freeze(spec);
|
|
383
543
|
}
|
|
@@ -397,6 +557,22 @@ const UPDATE_SPEC = makeSpec({
|
|
|
397
557
|
parse: parseEmptyResponse,
|
|
398
558
|
requiredScopes: UPDATE_REQUIRED_SCOPES
|
|
399
559
|
});
|
|
560
|
+
const GET_SPEC = makeSpec({
|
|
561
|
+
buildRequest: (parameters) => okRequest(buildGetRequest(parameters)),
|
|
562
|
+
methodDefaults: IDEMPOTENT_METHOD_DEFAULTS,
|
|
563
|
+
methodKind: "idempotent",
|
|
564
|
+
operationLimit: GET_OPERATION_LIMIT,
|
|
565
|
+
parse: parseBadgeDetailsResponse,
|
|
566
|
+
unauthenticatedBaseUrl: READ_BASE_URL
|
|
567
|
+
});
|
|
568
|
+
const LIST_SPEC = makeSpec({
|
|
569
|
+
buildRequest: (parameters) => okRequest(buildListRequest(parameters)),
|
|
570
|
+
methodDefaults: IDEMPOTENT_METHOD_DEFAULTS,
|
|
571
|
+
methodKind: "idempotent",
|
|
572
|
+
operationLimit: LIST_OPERATION_LIMIT,
|
|
573
|
+
parse: parseBadgesListResponse,
|
|
574
|
+
unauthenticatedBaseUrl: READ_BASE_URL
|
|
575
|
+
});
|
|
400
576
|
const FREE_QUOTA_SPEC = makeSpec({
|
|
401
577
|
buildRequest: (parameters) => okRequest(buildFreeQuotaRequest(parameters)),
|
|
402
578
|
methodDefaults: IDEMPOTENT_METHOD_DEFAULTS,
|
|
@@ -405,6 +581,14 @@ const FREE_QUOTA_SPEC = makeSpec({
|
|
|
405
581
|
parse: parseFreeQuotaResponse,
|
|
406
582
|
unauthenticatedBaseUrl: FREE_QUOTA_BASE_URL
|
|
407
583
|
});
|
|
584
|
+
const CREATION_PRICE_SPEC = makeSpec({
|
|
585
|
+
buildRequest: () => okRequest(buildMetadataRequest()),
|
|
586
|
+
methodDefaults: IDEMPOTENT_METHOD_DEFAULTS,
|
|
587
|
+
methodKind: "idempotent",
|
|
588
|
+
operationLimit: METADATA_OPERATION_LIMIT,
|
|
589
|
+
parse: parseCreationPriceResponse,
|
|
590
|
+
unauthenticatedBaseUrl: METADATA_BASE_URL
|
|
591
|
+
});
|
|
408
592
|
const UPLOAD_ICON_SPEC = makeSpec({
|
|
409
593
|
buildRequest: (parameters) => okRequest(buildUploadIconRequest(parameters)),
|
|
410
594
|
methodDefaults: CREATE_METHOD_DEFAULTS,
|
|
@@ -498,6 +682,70 @@ var BadgesClient = class {
|
|
|
498
682
|
});
|
|
499
683
|
}
|
|
500
684
|
/**
|
|
685
|
+
* Reads one badge, enabled or disabled. A disabled badge comes back with
|
|
686
|
+
* `enabled: false`; {@link BadgesClient.list} does not return it.
|
|
687
|
+
*
|
|
688
|
+
* The read is unauthenticated: it sends no credential and is served from
|
|
689
|
+
* `https://badges.roblox.com`, so the client `baseUrl` does not apply.
|
|
690
|
+
* Roblox allows 600 reads per minute per caller.
|
|
691
|
+
*
|
|
692
|
+
* @since 0.5.0
|
|
693
|
+
* @param parameters - The badge to read.
|
|
694
|
+
* @param options - Optional per-request overrides.
|
|
695
|
+
* @returns A {@link Result} wrapping the parsed {@link BadgeDetails}, or the
|
|
696
|
+
* {@link OpenCloudError} that caused the request to fail.
|
|
697
|
+
*/
|
|
698
|
+
async get(parameters, options) {
|
|
699
|
+
return this.#inner.executeAsync({
|
|
700
|
+
options,
|
|
701
|
+
parameters,
|
|
702
|
+
spec: GET_SPEC
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Reads the list price in Robux of one badge create beyond the free
|
|
707
|
+
* quota. The price is the same for every universe; it is not the cost
|
|
708
|
+
* of the next create, which is free while
|
|
709
|
+
* {@link BadgesClient.getFreeQuota} is above zero. Pass the price as
|
|
710
|
+
* `expectedCost` on {@link BadgesClient.create} to pay for a create.
|
|
711
|
+
*
|
|
712
|
+
* The read is unauthenticated: it sends no credential and is served from
|
|
713
|
+
* `https://badges.roblox.com`, so the client `baseUrl` does not apply.
|
|
714
|
+
* Roblox allows 100 reads per minute per caller.
|
|
715
|
+
*
|
|
716
|
+
* @since 0.5.0
|
|
717
|
+
* @param options - Optional per-request overrides.
|
|
718
|
+
* @returns A {@link Result} wrapping the badge creation price in Robux,
|
|
719
|
+
* or the {@link OpenCloudError} that caused the request to fail.
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
*
|
|
723
|
+
* ```ts
|
|
724
|
+
* import { BadgesClient } from "@bedrock-rbx/ocale/badges";
|
|
725
|
+
*
|
|
726
|
+
* const client = new BadgesClient({
|
|
727
|
+
* credential: { kind: "none" },
|
|
728
|
+
* httpClient: {
|
|
729
|
+
* request: async () => ({
|
|
730
|
+
* data: { body: { badgeCreationPrice: 100 }, headers: {}, status: 200 },
|
|
731
|
+
* success: true,
|
|
732
|
+
* }),
|
|
733
|
+
* },
|
|
734
|
+
* });
|
|
735
|
+
*
|
|
736
|
+
* return client.getCreationPrice().then((price) => {
|
|
737
|
+
* expect(price).toStrictEqual({ data: 100, success: true });
|
|
738
|
+
* });
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
async getCreationPrice(options) {
|
|
742
|
+
return this.#inner.executeAsync({
|
|
743
|
+
options,
|
|
744
|
+
parameters: void 0,
|
|
745
|
+
spec: CREATION_PRICE_SPEC
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
501
749
|
* Reads how many badges the universe can still create free of charge
|
|
502
750
|
* today. Each create within the quota lowers it by one. The quota resets
|
|
503
751
|
* daily at 00:00 UTC. Roblox answers for any universe ID, existing or not.
|
|
@@ -522,6 +770,35 @@ var BadgesClient = class {
|
|
|
522
770
|
});
|
|
523
771
|
}
|
|
524
772
|
/**
|
|
773
|
+
* Lists one page of a universe's enabled badges. Omit
|
|
774
|
+
* `pageToken` for the first page, then pass the returned `nextPageToken`
|
|
775
|
+
* until it is undefined.
|
|
776
|
+
*
|
|
777
|
+
* This list hides disabled badges. A badge leaves the list as soon as
|
|
778
|
+
* it is disabled, but {@link BadgesClient.get} still returns it, with
|
|
779
|
+
* `enabled: false`. Use {@link BadgesClient.get} to see a disabled badge,
|
|
780
|
+
* for example a tracked badge that someone disabled. A page can hold
|
|
781
|
+
* fewer items than `pageSize` and still have a next page, so page until
|
|
782
|
+
* `nextPageToken` is undefined.
|
|
783
|
+
*
|
|
784
|
+
* The read is unauthenticated: it sends no credential and is served from
|
|
785
|
+
* `https://badges.roblox.com`, so the client `baseUrl` does not apply.
|
|
786
|
+
* Roblox allows 100 pages per minute per caller.
|
|
787
|
+
*
|
|
788
|
+
* @since 0.5.0
|
|
789
|
+
* @param parameters - Universe ID and optional paging fields.
|
|
790
|
+
* @param options - Optional per-request overrides.
|
|
791
|
+
* @returns A {@link Result} wrapping the badge page, or the
|
|
792
|
+
* {@link OpenCloudError} that caused the request to fail.
|
|
793
|
+
*/
|
|
794
|
+
async list(parameters, options) {
|
|
795
|
+
return this.#inner.executeAsync({
|
|
796
|
+
options,
|
|
797
|
+
parameters,
|
|
798
|
+
spec: LIST_SPEC
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
525
802
|
* Partially updates a badge's configuration. Mirrors the upstream
|
|
526
803
|
* `200 OK` empty response: a successful update yields `undefined`
|
|
527
804
|
* data. Only fields explicitly provided are forwarded to the server,
|
|
@@ -579,7 +856,6 @@ function createLocalizationHandle(inner) {
|
|
|
579
856
|
}
|
|
580
857
|
};
|
|
581
858
|
}
|
|
582
|
-
//#endregion
|
|
583
859
|
export { BadgesClient };
|
|
584
860
|
|
|
585
861
|
//# sourceMappingURL=badges.mjs.map
|