@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.
Files changed (95) hide show
  1. package/README.md +10 -5
  2. package/dist/assets.d.mts +64 -0
  3. package/dist/assets.d.mts.map +1 -0
  4. package/dist/assets.mjs +301 -0
  5. package/dist/assets.mjs.map +1 -0
  6. package/dist/badge-insufficient-funds-BLFvQZt1.mjs +91 -0
  7. package/dist/badge-insufficient-funds-BLFvQZt1.mjs.map +1 -0
  8. package/dist/badges.d.mts +359 -196
  9. package/dist/badges.d.mts.map +1 -1
  10. package/dist/badges.mjs +493 -59
  11. package/dist/badges.mjs.map +1 -1
  12. package/dist/capacity-admission-Ce2V9QNb.d.mts +347 -0
  13. package/dist/capacity-admission-Ce2V9QNb.d.mts.map +1 -0
  14. package/dist/{data.generated-B2ceLfSn.d.mts → data.generated-B4Fztv_7.d.mts} +23 -25
  15. package/dist/data.generated-B4Fztv_7.d.mts.map +1 -0
  16. package/dist/developer-products.d.mts +207 -194
  17. package/dist/developer-products.d.mts.map +1 -1
  18. package/dist/developer-products.mjs +125 -39
  19. package/dist/developer-products.mjs.map +1 -1
  20. package/dist/game-passes.d.mts +206 -211
  21. package/dist/game-passes.d.mts.map +1 -1
  22. package/dist/game-passes.mjs +35 -36
  23. package/dist/game-passes.mjs.map +1 -1
  24. package/dist/index.d.mts +947 -366
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +324 -12
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/is-date-time-string-C91G44SI.mjs +19 -0
  29. package/dist/is-date-time-string-C91G44SI.mjs.map +1 -0
  30. package/dist/locales.d.mts +28 -2
  31. package/dist/locales.d.mts.map +1 -0
  32. package/dist/locales.mjs +24 -3
  33. package/dist/locales.mjs.map +1 -1
  34. package/dist/luau-execution.d.mts +154 -157
  35. package/dist/luau-execution.d.mts.map +1 -1
  36. package/dist/luau-execution.mjs +15 -16
  37. package/dist/luau-execution.mjs.map +1 -1
  38. package/dist/{network-error-DR9FX5hb.mjs → network-error-P4An7nUB.mjs} +48 -14
  39. package/dist/network-error-P4An7nUB.mjs.map +1 -0
  40. package/dist/places.d.mts +258 -186
  41. package/dist/places.d.mts.map +1 -1
  42. package/dist/places.mjs +187 -35
  43. package/dist/places.mjs.map +1 -1
  44. package/dist/{poll-timeout-3PXLsabj.mjs → poll-timeout-BCxgN97O.mjs} +4 -6
  45. package/dist/{poll-timeout-3PXLsabj.mjs.map → poll-timeout-BCxgN97O.mjs.map} +1 -1
  46. package/dist/{polling-helpers-CoVhsC33.mjs → polling-helpers-BtEYR5dN.mjs} +260 -105
  47. package/dist/polling-helpers-BtEYR5dN.mjs.map +1 -0
  48. package/dist/{price-information-B0tkOoAX.mjs → price-information--d6GZAcp.mjs} +3 -4
  49. package/dist/{price-information-B0tkOoAX.mjs.map → price-information--d6GZAcp.mjs.map} +1 -1
  50. package/dist/resource-client-CF8SPsV8.d.mts +162 -0
  51. package/dist/resource-client-CF8SPsV8.d.mts.map +1 -0
  52. package/dist/{resource-client-rqTMkBeR.mjs → resource-client-Cm_bPcCs.mjs} +589 -197
  53. package/dist/resource-client-Cm_bPcCs.mjs.map +1 -0
  54. package/dist/retry-DYxm_eBU.d.mts +225 -0
  55. package/dist/retry-DYxm_eBU.d.mts.map +1 -0
  56. package/dist/{retry-BlX4tUnT.mjs → retry-Dv5TsY9O.mjs} +312 -54
  57. package/dist/retry-Dv5TsY9O.mjs.map +1 -0
  58. package/dist/{signatures-JF-7Psce.mjs → signatures-CtJ7jfVN.mjs} +2 -3
  59. package/dist/{signatures-JF-7Psce.mjs.map → signatures-CtJ7jfVN.mjs.map} +1 -1
  60. package/dist/storage.d.mts +333 -344
  61. package/dist/storage.d.mts.map +1 -1
  62. package/dist/storage.mjs +39 -40
  63. package/dist/storage.mjs.map +1 -1
  64. package/dist/testing.d.mts +369 -434
  65. package/dist/testing.d.mts.map +1 -1
  66. package/dist/testing.mjs +18 -33
  67. package/dist/testing.mjs.map +1 -1
  68. package/dist/{to-blob-RPqMBuft.mjs → to-blob-Bqu7bmlE.mjs} +2 -3
  69. package/dist/{to-blob-RPqMBuft.mjs.map → to-blob-Bqu7bmlE.mjs.map} +1 -1
  70. package/dist/types-Z4abDJfK.d.mts +501 -0
  71. package/dist/types-Z4abDJfK.d.mts.map +1 -0
  72. package/dist/universes.d.mts +619 -436
  73. package/dist/universes.d.mts.map +1 -1
  74. package/dist/universes.mjs +432 -79
  75. package/dist/universes.mjs.map +1 -1
  76. package/dist/{validation-B_Zs1So2.mjs → validation-kaTLLAD1.mjs} +3 -4
  77. package/dist/{validation-B_Zs1So2.mjs.map → validation-kaTLLAD1.mjs.map} +1 -1
  78. package/dist/wire-DDG87I-d.d.mts +39 -0
  79. package/dist/wire-DDG87I-d.d.mts.map +1 -0
  80. package/package.json +15 -14
  81. package/dist/capacity-admission-IDO3fcUC.d.mts +0 -369
  82. package/dist/capacity-admission-IDO3fcUC.d.mts.map +0 -1
  83. package/dist/data.generated-B2ceLfSn.d.mts.map +0 -1
  84. package/dist/network-error-DR9FX5hb.mjs.map +0 -1
  85. package/dist/polling-helpers-CoVhsC33.mjs.map +0 -1
  86. package/dist/resource-client-B6NeFXUv.d.mts +0 -164
  87. package/dist/resource-client-B6NeFXUv.d.mts.map +0 -1
  88. package/dist/resource-client-rqTMkBeR.mjs.map +0 -1
  89. package/dist/retry-BlX4tUnT.mjs.map +0 -1
  90. package/dist/retry-war_-9tb.d.mts +0 -373
  91. package/dist/retry-war_-9tb.d.mts.map +0 -1
  92. package/dist/types-CvYh4SPC.d.mts +0 -386
  93. package/dist/types-CvYh4SPC.d.mts.map +0 -1
  94. package/dist/wire-D3K-a-UP.d.mts +0 -37
  95. package/dist/wire-D3K-a-UP.d.mts.map +0 -1
package/dist/badges.mjs CHANGED
@@ -1,8 +1,10 @@
1
- import { a as ApiError } from "./network-error-DR9FX5hb.mjs";
2
- import { r as IDEMPOTENT_METHOD_DEFAULTS, t as CREATE_METHOD_DEFAULTS } from "./retry-BlX4tUnT.mjs";
3
- import { t as toBlob } from "./to-blob-RPqMBuft.mjs";
4
- import { c as isDateTimeString, n as okRequest, o as toJsonDetails, r as parseEmptyResponse, s as isRecord, t as ResourceClient } from "./resource-client-rqTMkBeR.mjs";
5
- //#region src/domains/badges/badges/builders.ts
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
6
8
  /**
7
9
  * Builds a `POST` request for the legacy "create badge" endpoint.
8
10
  *
@@ -13,7 +15,7 @@ import { c as isDateTimeString, n as okRequest, o as toJsonDetails, r as parseEm
13
15
  function buildCreateRequest(parameters) {
14
16
  const body = new FormData();
15
17
  body.append("name", parameters.name);
16
- body.append("files", toBlob(parameters.icon));
18
+ if (parameters.icon !== void 0) body.append("files", toBlob(parameters.icon), "icon");
17
19
  if (parameters.description !== void 0) body.append("description", parameters.description);
18
20
  if (parameters.isActive !== void 0) body.append("isActive", String(parameters.isActive));
19
21
  if (parameters.expectedCost !== void 0) body.append("expectedCost", String(parameters.expectedCost));
@@ -43,11 +45,93 @@ function buildUpdateRequest$1(parameters) {
43
45
  url: `/legacy-badges/v1/badges/${parameters.badgeId}`
44
46
  };
45
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
+ }
46
79
  function toPaymentSourceWire(source) {
47
80
  return source === "User" ? "1" : "2";
48
81
  }
49
- //#endregion
50
- //#region src/domains/badges/badges/operations.ts
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
129
+ /** Body error code Roblox sends when a create's expected cost is wrong. */
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";
51
135
  /**
52
136
  * Per-second request ceiling for creating a badge, sourced from
53
137
  * `x-roblox-rate-limits` on the legacy badges create operation in the
@@ -70,6 +154,27 @@ const UPDATE_OPERATION_LIMIT = Object.freeze({
70
154
  operationKey: "badges.update"
71
155
  });
72
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
+ /**
73
178
  * Scopes the API key or OAuth token must carry to create a badge,
74
179
  * sourced from `x-roblox-scopes` on the legacy badges create operation
75
180
  * in the vendored OpenAPI schema. The trailing
@@ -83,50 +188,104 @@ const CREATE_REQUIRED_SCOPES = Object.freeze(["legacy-universe.badge:manage-and-
83
188
  * in the vendored OpenAPI schema.
84
189
  */
85
190
  const UPDATE_REQUIRED_SCOPES = Object.freeze(["legacy-universe.badge:write"]);
86
- //#endregion
87
- //#region src/domains/badges/badges/parsers.ts
191
+ /**
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.
198
+ *
199
+ * @param expectedCost - The `expectedCost` the create sent, if any.
200
+ * @returns The refinement for one create call.
201
+ */
202
+ function refineCreateError(expectedCost) {
203
+ return (error) => {
204
+ if (!(error instanceof ApiError)) return error;
205
+ const options = {
206
+ cause: error,
207
+ code: error.code,
208
+ statusCode: error.statusCode
209
+ };
210
+ if (error.code === COST_MISMATCH_CODE) return new BadgeCostMismatchError(error.message, {
211
+ ...options,
212
+ expectedCost
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;
217
+ };
218
+ }
219
+ // src/domains/badges/badges/parsers.ts
88
220
  /**
89
221
  * Parses a successful Badges API response into the public `Badge` shape,
90
222
  * returning a `Result` so callers can handle malformed payloads without
91
223
  * exceptions.
92
224
  *
93
225
  * @param response - The full {@link HttpResponse} from the Open Cloud API.
94
- * The status code is included on the returned `ApiError` when validation
95
- * fails; the headers are available for future parsers that need them.
226
+ * The status code is included on the returned `UnexpectedResponseError` when
227
+ * validation fails; the headers are available for future parsers that need
228
+ * them.
96
229
  * @returns A success result wrapping the converted `Badge`, or an
97
- * `ApiError` when the body does not match the wire schema.
230
+ * `UnexpectedResponseError` when the body does not match the wire schema.
98
231
  */
99
232
  function parseBadgeResponse({ body, status: statusCode }) {
100
- if (!isBadgeResponseV2Wire(body)) return {
101
- err: new ApiError("Malformed badge response", {
102
- details: toJsonDetails(body),
103
- statusCode
104
- }),
105
- success: false
233
+ if (!isBadgeResponseV2Wire(body)) return malformedBadge(statusCode, body);
234
+ return {
235
+ data: {
236
+ ...copySharedFields(body),
237
+ awarder: copyAwarder(body.awarder)
238
+ },
239
+ success: true
106
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);
107
252
  return {
108
253
  data: {
109
- id: String(body.id),
110
- name: body.name,
111
- awarder: copyAwarder(body.awarder),
112
- createdAt: new Date(body.created),
113
- description: body.description,
114
- displayDescription: body.displayDescription,
115
- displayIconImageId: body.displayIconImageId === 0 ? void 0 : String(body.displayIconImageId),
116
- displayName: body.displayName,
117
- enabled: body.enabled,
118
- iconImageId: body.iconImageId === 0 ? void 0 : String(body.iconImageId),
119
- statistics: copyStatistics(body.statistics),
120
- updatedAt: new Date(body.updated)
254
+ ...copySharedFields(body),
255
+ awardingUniverse: copyAwardingUniverse(body.awardingUniverse)
121
256
  },
122
257
  success: true
123
258
  };
124
259
  }
125
- function copyAwarder(awarder) {
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
+ }
126
283
  return {
127
- id: String(awarder.id),
128
- name: awarder.name,
129
- type: "Place"
284
+ data: {
285
+ items,
286
+ nextPageToken
287
+ },
288
+ success: true
130
289
  };
131
290
  }
132
291
  function copyStatistics(statistics) {
@@ -136,12 +295,34 @@ function copyStatistics(statistics) {
136
295
  winRatePercentage: statistics.winRatePercentage
137
296
  };
138
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
+ }
139
320
  function hasRequiredPrimitiveFields(body) {
140
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"]);
141
322
  }
142
323
  function isBadgeAwarderWire(value) {
143
324
  if (!isRecord(value)) return false;
144
- return typeof value["id"] === "number" && typeof value["name"] === "string" && value["type"] === 1;
325
+ return typeof value["id"] === "number" && (value["name"] === void 0 || typeof value["name"] === "string") && value["type"] === "Place";
145
326
  }
146
327
  function isBadgeStatisticsWire(value) {
147
328
  if (!isRecord(value)) return false;
@@ -154,8 +335,86 @@ function isBadgeResponseV2Wire(body) {
154
335
  if (!isBadgeStatisticsWire(body["statistics"])) return false;
155
336
  return true;
156
337
  }
157
- //#endregion
158
- //#region src/domains/game-internationalization/badge-icon/builders.ts
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";
373
+ /**
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.
377
+ */
378
+ const METADATA_OPERATION_LIMIT = Object.freeze({
379
+ maxPerSecond: 100 / 60,
380
+ operationKey: "badges.metadata"
381
+ });
382
+ /**
383
+ * Builds the `GET` request for the badge metadata.
384
+ *
385
+ * @returns A pure {@link HttpRequest} describing the read.
386
+ */
387
+ function buildMetadataRequest() {
388
+ return {
389
+ method: "GET",
390
+ url: "/v1/badges/metadata"
391
+ };
392
+ }
393
+ /**
394
+ * Parses the badge metadata body down to its `badgeCreationPrice`.
395
+ *
396
+ * @param response - The full {@link HttpResponse}.
397
+ * @returns The badge creation price in Robux, or an
398
+ * `UnexpectedResponseError` when the body carries no valid price.
399
+ */
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", {
404
+ details: toJsonDetails(body),
405
+ statusCode
406
+ }),
407
+ success: false
408
+ };
409
+ return {
410
+ data: price,
411
+ success: true
412
+ };
413
+ }
414
+ function isPrice(value) {
415
+ return Number.isSafeInteger(value) && Number(value) >= 0;
416
+ }
417
+ // src/domains/game-internationalization/badge-icon/builders.ts
159
418
  /**
160
419
  * Builds a `POST` request for the localized "upload badge icon" endpoint. A
161
420
  * successful upload replaces any existing icon for the same
@@ -174,8 +433,7 @@ function buildUploadIconRequest$1(parameters) {
174
433
  url: `/legacy-game-internationalization/v1/badges/${parameters.badgeId}/icons/language-codes/${parameters.languageCode}`
175
434
  };
176
435
  }
177
- //#endregion
178
- //#region src/domains/game-internationalization/badge-name-description/builders.ts
436
+ // src/domains/game-internationalization/badge-name-description/builders.ts
179
437
  /**
180
438
  * Builds a `PATCH` request for the localized "update badge name/description"
181
439
  * endpoint. Either `name`, `description`, or both may be supplied; omitted
@@ -196,15 +454,15 @@ function buildUpdateRequest(parameters) {
196
454
  url: `/legacy-game-internationalization/v1/badges/${parameters.badgeId}/name-description/language-codes/${parameters.languageCode}`
197
455
  };
198
456
  }
199
- //#endregion
200
- //#region src/domains/game-internationalization/badge-name-description/operations.ts
457
+ // src/domains/game-internationalization/badge-name-description/operations.ts
201
458
  /**
202
- * Per-second request ceiling for every badge localization Operation. The
203
- * legacy `gameinternationalization` service caps each API key at 100
204
- * requests per minute *shared across the entire service* (see the
205
- * `x-roblox-rate-limits` extension on every operation in the vendored
206
- * Open Cloud spec), so all badge localization methods queue against the
207
- * same operation key.
459
+ * Per-second request ceiling for badge localization Operations, from each
460
+ * operation's `x-roblox-rate-limits.perApiKeyOwner` in the vendored schema
461
+ * (100 requests per minute). This family's key stays separate from other
462
+ * game-internationalization families: the #587 probe measured independent
463
+ * reported 100/minute counters, including on rejected requests. Successful
464
+ * writes may have additional service limits; see
465
+ * `docs/spikes/game-internationalization-rate-limits/README.md`.
208
466
  */
209
467
  const LOCALIZATION_OPERATION_LIMIT = Object.freeze({
210
468
  maxPerSecond: 100 / 60,
@@ -216,8 +474,7 @@ const LOCALIZATION_OPERATION_LIMIT = Object.freeze({
216
474
  * endpoints in the vendored OpenAPI schema.
217
475
  */
218
476
  const LOCALIZATION_REQUIRED_SCOPES = Object.freeze(["legacy-badge:manage"]);
219
- //#endregion
220
- //#region src/domains/publish/badge-icon/builders.ts
477
+ // src/domains/publish/badge-icon/builders.ts
221
478
  /**
222
479
  * Builds a `POST` request for the legacy "upload badge icon" endpoint. A
223
480
  * successful upload replaces any existing source-language icon on the
@@ -228,15 +485,14 @@ const LOCALIZATION_REQUIRED_SCOPES = Object.freeze(["legacy-badge:manage"]);
228
485
  */
229
486
  function buildUploadIconRequest(parameters) {
230
487
  const body = new FormData();
231
- body.append("Files", toBlob(parameters.icon));
488
+ body.append("Files", toBlob(parameters.icon), "icon");
232
489
  return {
233
490
  body,
234
491
  method: "POST",
235
492
  url: `/legacy-publish/v1/badges/${parameters.badgeId}/icon`
236
493
  };
237
494
  }
238
- //#endregion
239
- //#region src/domains/publish/badge-icon/operations.ts
495
+ // src/domains/publish/badge-icon/operations.ts
240
496
  /**
241
497
  * Per-second request ceiling for uploading a badge icon, sourced from
242
498
  * `x-roblox-rate-limits` on the legacy badge icon upload operation in
@@ -255,8 +511,33 @@ const UPLOAD_ICON_OPERATION_LIMIT = Object.freeze({
255
511
  * operation in the vendored OpenAPI schema.
256
512
  */
257
513
  const UPLOAD_ICON_REQUIRED_SCOPES = Object.freeze(["legacy-badge:manage"]);
258
- //#endregion
259
- //#region src/resources/badges/client.ts
514
+ // src/domains/publish/badge-icon/parsers.ts
515
+ /**
516
+ * Parses a badge icon upload response, whose `targetId` is the asset ID of
517
+ * the uploaded icon.
518
+ *
519
+ * @param response - The full {@link HttpResponse}.
520
+ * @returns The uploaded icon, or an `UnexpectedResponseError` when the body
521
+ * names no positive integer asset ID.
522
+ */
523
+ function parseUploadIconResponse({ body, status: statusCode }) {
524
+ const targetId = isRecord(body) ? body["targetId"] : void 0;
525
+ if (!isAssetId(targetId)) return {
526
+ err: new UnexpectedResponseError("Malformed badge icon upload response", {
527
+ details: toJsonDetails(body),
528
+ statusCode
529
+ }),
530
+ success: false
531
+ };
532
+ return {
533
+ data: { iconImageId: String(targetId) },
534
+ success: true
535
+ };
536
+ }
537
+ function isAssetId(value) {
538
+ return Number.isSafeInteger(value) && Number(value) > 0;
539
+ }
540
+ // src/resources/badges/client.ts
260
541
  function makeSpec(spec) {
261
542
  return Object.freeze(spec);
262
543
  }
@@ -276,12 +557,44 @@ const UPDATE_SPEC = makeSpec({
276
557
  parse: parseEmptyResponse,
277
558
  requiredScopes: UPDATE_REQUIRED_SCOPES
278
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
+ });
576
+ const FREE_QUOTA_SPEC = makeSpec({
577
+ buildRequest: (parameters) => okRequest(buildFreeQuotaRequest(parameters)),
578
+ methodDefaults: IDEMPOTENT_METHOD_DEFAULTS,
579
+ methodKind: "idempotent",
580
+ operationLimit: FREE_QUOTA_OPERATION_LIMIT,
581
+ parse: parseFreeQuotaResponse,
582
+ unauthenticatedBaseUrl: FREE_QUOTA_BASE_URL
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
+ });
279
592
  const UPLOAD_ICON_SPEC = makeSpec({
280
593
  buildRequest: (parameters) => okRequest(buildUploadIconRequest(parameters)),
281
594
  methodDefaults: CREATE_METHOD_DEFAULTS,
282
595
  methodKind: "create",
283
596
  operationLimit: UPLOAD_ICON_OPERATION_LIMIT,
284
- parse: parseEmptyResponse,
597
+ parse: parseUploadIconResponse,
285
598
  requiredScopes: UPLOAD_ICON_REQUIRED_SCOPES
286
599
  });
287
600
  const UPDATE_NAME_DESCRIPTION_SPEC = makeSpec({
@@ -318,7 +631,7 @@ const UPLOAD_LOCALIZED_ICON_SPEC = makeSpec({
318
631
  * ```ts
319
632
  * import { BadgesClient } from "@bedrock-rbx/ocale/badges";
320
633
  *
321
- * const client = new BadgesClient({ apiKey: "your-key" });
634
+ * const client = new BadgesClient({ credential: { apiKey: "your-key", kind: "apiKey" } });
322
635
  * expect(client).toBeInstanceOf(BadgesClient);
323
636
  * ```
324
637
  */
@@ -350,6 +663,10 @@ var BadgesClient = class {
350
663
  * No default request timeout applies to this upload; pass `options.timeout`
351
664
  * to set a per-call deadline.
352
665
  *
666
+ * A create whose `expectedCost` differs from the actual cost fails with a
667
+ * `BadgeCostMismatchError` and is not charged; with `expectedCost: 0`
668
+ * that means the universe's free badge quota is spent for today.
669
+ *
353
670
  * @param parameters - Creation fields including the universe, name, and
354
671
  * icon image.
355
672
  * @param options - Optional per-request overrides.
@@ -360,10 +677,128 @@ var BadgesClient = class {
360
677
  return this.#inner.executeAsync({
361
678
  options,
362
679
  parameters,
680
+ refineError: refineCreateError(parameters.expectedCost),
363
681
  spec: CREATE_SPEC
364
682
  });
365
683
  }
366
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
+ /**
749
+ * Reads how many badges the universe can still create free of charge
750
+ * today. Each create within the quota lowers it by one. The quota resets
751
+ * daily at 00:00 UTC. Roblox answers for any universe ID, existing or not.
752
+ *
753
+ * The read is unauthenticated: it sends no credential and is served from
754
+ * `https://badges.roblox.com`, so the client `baseUrl` does not apply.
755
+ * Roblox allows 60 reads per minute per caller. A 429 waits until the
756
+ * reported `x-ratelimit-reset` before it retries.
757
+ *
758
+ * @since 0.4.0
759
+ * @param parameters - The universe to read.
760
+ * @param options - Optional per-request overrides.
761
+ * @returns A {@link Result} wrapping the free badges left today, or the
762
+ * {@link OpenCloudError} that caused the request to fail.
763
+ */
764
+ async getFreeQuota(parameters, options) {
765
+ return this.#inner.executeAsync({
766
+ options,
767
+ parameters,
768
+ refineError: waitForQuotaReset,
769
+ spec: FREE_QUOTA_SPEC
770
+ });
771
+ }
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
+ /**
367
802
  * Partially updates a badge's configuration. Mirrors the upstream
368
803
  * `200 OK` empty response: a successful update yields `undefined`
369
804
  * data. Only fields explicitly provided are forwarded to the server,
@@ -392,7 +827,7 @@ var BadgesClient = class {
392
827
  *
393
828
  * @param parameters - Identifier plus the image bytes to upload.
394
829
  * @param options - Optional per-request overrides.
395
- * @returns A success {@link Result} with no payload, or the
830
+ * @returns A {@link Result} wrapping the uploaded icon's asset ID, or the
396
831
  * {@link OpenCloudError} that caused the request to fail.
397
832
  */
398
833
  async uploadIcon(parameters, options) {
@@ -421,7 +856,6 @@ function createLocalizationHandle(inner) {
421
856
  }
422
857
  };
423
858
  }
424
- //#endregion
425
859
  export { BadgesClient };
426
860
 
427
861
  //# sourceMappingURL=badges.mjs.map