@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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/fetch-http-client.ts","../src/errors/permission-error.ts","../src/errors/poll-aborted.ts","../src/errors/poll-timeout.ts","../src/errors/rate-limit-wait-refused.ts","../src/errors/request-aborted.ts","../src/errors/request-deadline-exceeded.ts","../src/errors/retry-delay-exceeded.ts","../src/errors/validation.ts"],"mappings":";;;;;;;AA+DA;;;;AAA0C;;;;ACxD1C;;;;;;;;;AAYiB;AAgCjB;;;;;;;;;;;;;;;;;;AAYuC;;;;ACxDvC;;;;AAEU;AAwBV;;;;;;;;;;;;cF8Ba,qBAAA,QAA6B,UAAA;;;;;;AAA1C;;UCxDiB,sBAAA,SAA+B,eAAA;EDwDN;AAAA;;;;EClDzC,YAAA;EANgB;;;;;EAYhB,cAAA,EAAgB,aAAA;AAAA;;AAAA;AAgCjB;;;;;;;;;;;;;;;;;;AAYuC;;;;ACxDvC;;;;AAEU;cD0CG,eAAA,SAAwB,QAAA;EAAA,kBACX,IAAA;EAAA,SACT,YAAA;EAAA,SACA,cAAA,EAAgB,aAAA;;;;;;;;EAShC,WAAA,CAAY,OAAA,UAAiB,OAAA,EAAS,sBAAA;AAAA;;;;;;ADAvC;;UExDiB,uBAAA,SAAgC,YAAA;EFwDP;EAAA,SEtDhC,MAAA;AAAA;;;ADFV;;;;;;;;;AAYiB;AAgCjB;;;;;;;;;cClBa,gBAAA,SAAyB,cAAA;EAAA,kBACZ,IAAA;EAAA,SACT,MAAA;;;;;;;EAQhB,WAAA,CAAY,OAAA,UAAiB,OAAA,GAAS,uBAAA;AAAA;;;;;;AFoBvC;;;;AAA0C;;;UGnDzB,uBAAA,sBAA6C,YAAA;EFL9D;EAAA,SEOU,gBAAA,GAAmB,CAAA;;WAEnB,SAAA;AAAA;;;;;AFGO;AAgCjB;;;;;;;;;;;;;;;;;;AAYuC;cEpB1B,gBAAA,sBAAsC,cAAA;EAAA,SAClC,gBAAA,EAAkB,CAAA;EAAA,kBACT,IAAA;EAAA,SACT,SAAA;EDvCA;;;AAEP;AAwBV;;ECqBC,WAAA,CAAY,OAAA,UAAiB,OAAA,EAAS,uBAAA,CAAwB,CAAA;AAAA;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tB,iBAAA;;;ALpCjB;;;;EK4CC,WAAA,CAAY,OAAA,UAAiB,OAAA,EAAS,8BAAA;AAAA;;;;;;APYvC;;;;KQtDY,mBAAA;;;;APFZ;;UOiBiB,sBAAA,SAA+B,YAAA;EPjBA;EOmB/C,IAAA,EAAM,mBAAA;AAAA;;;;APPU;AAgCjB;;;;;;;;;;;;;;;;cOFa,eAAA,SAAwB,cAAA;EAAA,kBACX,IAAA,EAAM,mBAAA;EAAA,kBACN,IAAA;;;;AN5C1B;;;EMoDC,WAAA,CAAY,OAAA,UAAiB,OAAA,EAAS,sBAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/fetch-http-client.ts","../src/client/oauth-token-refresher.ts","../src/errors/api-error.ts","../src/errors/badge-cost-mismatch.ts","../src/errors/badge-group-spend-permission.ts","../src/errors/badge-insufficient-funds.ts","../src/errors/credential-error.ts","../src/errors/credential-not-supported.ts","../src/errors/credential-rejected.ts","../src/errors/network-error.ts","../src/errors/permission-error.ts","../src/errors/poll-aborted.ts","../src/errors/poll-timeout.ts","../src/errors/rate-limit-wait-refused.ts","../src/errors/request-aborted.ts","../src/errors/request-deadline-exceeded.ts","../src/errors/retry-delay-exceeded.ts","../src/errors/token-refresh-error.ts","../src/errors/unexpected-response.ts","../src/errors/validation.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwEgB,sBAAsB;WAC5B,SAAS,eAAe,MAAM,gBAAgB,QAAQ;IAC5D;;;;;;UC5Da;;WAEP;;;;;WAKA;;;;;WAKA,SAAS,eAAe,MAAM,gBAAgB,QAAQ;;;;;;WAMtD,WAAW,yBAAyB;;WAEpC;;;KAcL,sBAAsB,QAAQ;EAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAmPjC,0BACf,SAAS,iCACH,MAAM,WAAW,yBAAyB;;;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EV;;;;;EAKA;;;;;EAKA,kBAAkB,SAAS;;EAE3B;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgCY,gCAAgC;WAC5B,SAAS;WACT;oBACS;;WAET;WACA,iBAAiB,SAAS;WAC1B;WACA;;;;;;;;;EAUhB,YAAY,iBAAiB,SAAS;;;;;;;;;KCpE3B;;;;;;UAeK,+BAA+B;;EAE/C,MAAM;;;;;;;;;;;;;;;;;;;;;;qBAuBM,wBAAwB;oBACX,MAAM;oBACN;;;;;;;EAQzB,YAAY,iBAAiB,SAAS"}
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import { a as ApiError, n as RateLimitError, o as requestContextOf, s as OpenCloudError, t as NetworkError } from "./network-error-DR9FX5hb.mjs";
2
- import { S as RequestAbortedError, _ as createFetchHttpClient$1, a as TRANSIENT_TRANSPORT_CODES, g as PermissionError, h as RateLimitWaitRefusedError, i as RESPONSE_UNPARSEABLE, m as RequestDeadlineExceededError, n as GATEWAY_REJECTED, p as RetryDelayExceededError } from "./retry-BlX4tUnT.mjs";
3
- import { n as PollAbortedError, t as PollTimeoutError } from "./poll-timeout-3PXLsabj.mjs";
4
- import { t as ValidationError } from "./validation-B_Zs1So2.mjs";
5
- //#region src/client/fetch-http-client.ts
1
+ import { O as RequestAbortedError, S as createFetchHttpClient$1, _ as RateLimitWaitRefusedError, a as TRANSIENT_TRANSPORT_CODES, b as CredentialNotSupportedError, g as RequestDeadlineExceededError, h as RetryDelayExceededError, i as RESPONSE_UNPARSEABLE, m as UnexpectedResponseError, n as GATEWAY_REJECTED, v as PermissionError, x as CredentialError, y as CredentialRejectedError } from "./retry-Dv5TsY9O.mjs";
2
+ import { a as ApiError, n as RateLimitError, o as requestContextOf, s as OpenCloudError, t as NetworkError } from "./network-error-P4An7nUB.mjs";
3
+ import { n as BadgeGroupSpendPermissionError, r as BadgeCostMismatchError, t as BadgeInsufficientFundsError } from "./badge-insufficient-funds-BLFvQZt1.mjs";
4
+ import { n as PollAbortedError, t as PollTimeoutError } from "./poll-timeout-BCxgN97O.mjs";
5
+ import { t as ValidationError } from "./validation-kaTLLAD1.mjs";
6
+ // src/client/fetch-http-client.ts
6
7
  /**
7
8
  * Creates the fetch-backed HTTP transport Ocale uses by default.
8
9
  *
@@ -10,6 +11,11 @@ import { t as ValidationError } from "./validation-B_Zs1So2.mjs";
10
11
  * request-level behavior while retaining Ocale's authentication, timeout,
11
12
  * upload, response-parsing, and error-classification semantics.
12
13
  *
14
+ * Pass `fetch` to send through a wrapped or replacement `fetch`. Omit it to
15
+ * use the global `fetch`.
16
+ *
17
+ * @param options - Optional transport settings.
18
+ * @param options.fetch - The `fetch` to send requests through.
13
19
  * @returns Ocale's default fetch-backed HTTP transport.
14
20
  * @since 0.3.1
15
21
  *
@@ -26,7 +32,11 @@ import { t as ValidationError } from "./validation-B_Zs1So2.mjs";
26
32
  * UniversesClient,
27
33
  * } from "@bedrock-rbx/ocale/universes";
28
34
  *
29
- * const defaultHttpClient = createFetchHttpClient();
35
+ * // An injected response keeps this executable example offline.
36
+ * // Omit fetch in production to use the runtime's global fetch.
37
+ * const defaultHttpClient = createFetchHttpClient({
38
+ * fetch: async () => new Response(),
39
+ * });
30
40
  * let observedRequests: ReadonlyArray<HttpRequest> = [];
31
41
  * const tracedHttpClient: HttpClient = {
32
42
  * async request(request, config) {
@@ -34,9 +44,9 @@ import { t as ValidationError } from "./validation-B_Zs1So2.mjs";
34
44
  * return defaultHttpClient.request(request, config);
35
45
  * },
36
46
  * };
37
- * // A data URL keeps this executable example offline. Production clients
38
- * // normally omit baseUrl and use Ocale's Roblox Open Cloud default.
39
- * const commonOptions = { apiKey: "your-key", baseUrl: "data:,#" };
47
+ * const commonOptions = {
48
+ * credential: { apiKey: "your-key", kind: "apiKey" as const },
49
+ * };
40
50
  * const client = new UniversesClient({
41
51
  * ...commonOptions,
42
52
  * httpClient: tracedHttpClient,
@@ -63,8 +73,310 @@ import { t as ValidationError } from "./validation-B_Zs1So2.mjs";
63
73
  * });
64
74
  * ```
65
75
  */
66
- const createFetchHttpClient = createFetchHttpClient$1;
67
- //#endregion
68
- export { ApiError, GATEWAY_REJECTED, NetworkError, OpenCloudError, PermissionError, PollAbortedError, PollTimeoutError, RESPONSE_UNPARSEABLE, RateLimitError, RateLimitWaitRefusedError, RequestAbortedError, RequestDeadlineExceededError, RetryDelayExceededError, TRANSIENT_TRANSPORT_CODES, ValidationError, createFetchHttpClient, requestContextOf };
76
+ function createFetchHttpClient(options) {
77
+ return createFetchHttpClient$1(options?.fetch);
78
+ }
79
+ // src/errors/token-refresh-error.ts
80
+ /**
81
+ * Thrown by the `getAccessToken` that `createOAuthTokenRefresher` returns
82
+ * when the Roblox token endpoint refuses a refresh. `code` is the OAuth
83
+ * `error` field of the response body (for example `invalid_grant`), or
84
+ * `undefined` when the body has none. A client that calls the provider
85
+ * returns it as the `cause` of a `CredentialError`.
86
+ *
87
+ * @since 0.4.0
88
+ *
89
+ * @example
90
+ *
91
+ * ```ts
92
+ * import { TokenRefreshError } from "@bedrock-rbx/ocale";
93
+ *
94
+ * const error = new TokenRefreshError("Token refresh refused", {
95
+ * code: "invalid_grant",
96
+ * statusCode: 400,
97
+ * });
98
+ *
99
+ * expect(error.code).toBe("invalid_grant");
100
+ * expect(error.statusCode).toBe(400);
101
+ * ```
102
+ */
103
+ var TokenRefreshError = class extends OpenCloudError {
104
+ name = "TokenRefreshError";
105
+ /** HTTP status of the token endpoint's response. */
106
+ statusCode;
107
+ /**
108
+ * Creates a new TokenRefreshError.
109
+ *
110
+ * @param message - Human-readable error description.
111
+ * @param options - The OAuth error code and the HTTP status.
112
+ */
113
+ constructor(message, options) {
114
+ super(message, options);
115
+ this.statusCode = options.statusCode;
116
+ }
117
+ };
118
+ // src/client/oauth-token-refresher.ts
119
+ const TOKEN_URL = "https://apis.roblox.com/oauth/v1/token";
120
+ const REFRESH_BELOW_MS = 12e4;
121
+ const FALLBACK_MIN_MS = 6e4;
122
+ const EXCHANGE_TIMEOUT_MS = 3e4;
123
+ var OAuthTokenRefresher = class {
124
+ #clientId;
125
+ #clientSecret;
126
+ #onRotate;
127
+ #send;
128
+ #current;
129
+ #failure;
130
+ #inFlight;
131
+ #pending;
132
+ #refreshToken;
133
+ constructor(options) {
134
+ this.#clientId = options.clientId;
135
+ this.#clientSecret = options.clientSecret;
136
+ this.#onRotate = options.onRotate;
137
+ this.#refreshToken = options.refreshToken;
138
+ this.#send = options.fetch ?? fetch;
139
+ }
140
+ async getAccessTokenAsync(signal) {
141
+ if (signal.aborted) throw abortedWait(signal);
142
+ if (this.#failure !== void 0) throw this.#failure;
143
+ const cached = this.#tokenLasting(REFRESH_BELOW_MS);
144
+ if (cached !== void 0) return cached;
145
+ this.#inFlight ??= this.#refreshAsync().finally(() => {
146
+ this.#inFlight = void 0;
147
+ });
148
+ return waitAsync(this.#inFlight, signal);
149
+ }
150
+ /**
151
+ * Runs one exchange under its own time limit, apart from any caller's
152
+ * signal. A timeout is transient, like a network error.
153
+ *
154
+ * @returns The exchange outcome.
155
+ */
156
+ async #exchangeAsync() {
157
+ const controller = new AbortController();
158
+ const exchange = this.#sendAsync(controller.signal);
159
+ let timer;
160
+ const timeout = new Promise((resolve) => {
161
+ timer = setTimeout(() => {
162
+ const error = new DOMException("OAuth token exchange timed out", "TimeoutError");
163
+ controller.abort(error);
164
+ resolve({
165
+ error,
166
+ kind: "transient"
167
+ });
168
+ }, EXCHANGE_TIMEOUT_MS);
169
+ });
170
+ try {
171
+ return await Promise.race([exchange, timeout]);
172
+ } finally {
173
+ clearTimeout(timer);
174
+ }
175
+ }
176
+ #fallback(error) {
177
+ const token = this.#tokenLasting(FALLBACK_MIN_MS);
178
+ if (token === void 0) throw error;
179
+ return token;
180
+ }
181
+ #form() {
182
+ const form = new URLSearchParams({
183
+ client_id: this.#clientId,
184
+ grant_type: "refresh_token",
185
+ refresh_token: this.#refreshToken
186
+ });
187
+ if (this.#clientSecret !== void 0) form.set("client_secret", this.#clientSecret);
188
+ return form;
189
+ }
190
+ /**
191
+ * Refreshes and saves a pair. A save can finish late (a retried kept
192
+ * pair, or a slow `onRotate`), so when the saved token has under 60 s
193
+ * left it exchanges once more with the now saved refresh token.
194
+ *
195
+ * @returns An access token.
196
+ */
197
+ async #refreshAsync() {
198
+ const first = await this.#rotateAsync();
199
+ if (first.kind === "transient") return this.#fallback(first.error);
200
+ if (first.pair.expiresAt - Date.now() >= FALLBACK_MIN_MS) return first.pair.accessToken;
201
+ const second = await this.#rotateAsync();
202
+ return second.kind === "transient" ? this.#fallback(second.error) : second.pair.accessToken;
203
+ }
204
+ /**
205
+ * Records a refusal that spent the refresh token, so it is never sent
206
+ * again: an `invalid_grant`, or a 2xx whose body held no usable pair.
207
+ *
208
+ * @param error - The refusal.
209
+ * @param accepted - Whether the endpoint answered 2xx.
210
+ * @returns The refusal, to throw.
211
+ */
212
+ #refused(error, accepted) {
213
+ if (accepted || error.code === "invalid_grant") this.#failure = error;
214
+ return error;
215
+ }
216
+ /**
217
+ * Exchanges the refresh token unless a kept unsaved pair exists, then
218
+ * saves the pair and makes it current.
219
+ *
220
+ * @returns The saved pair, or the transient failure of the exchange.
221
+ */
222
+ async #rotateAsync() {
223
+ if (this.#pending === void 0) {
224
+ const outcome = await this.#exchangeAsync();
225
+ if (outcome.kind === "transient") return outcome;
226
+ this.#pending = outcome.pair;
227
+ }
228
+ const pending = this.#pending;
229
+ await this.#onRotate(pending.refreshToken);
230
+ this.#current = pending;
231
+ this.#refreshToken = pending.refreshToken;
232
+ this.#pending = void 0;
233
+ return {
234
+ kind: "ok",
235
+ pair: pending
236
+ };
237
+ }
238
+ async #sendAsync(signal) {
239
+ let response;
240
+ try {
241
+ response = await this.#send(TOKEN_URL, {
242
+ body: this.#form().toString(),
243
+ headers: { "content-type": "application/x-www-form-urlencoded" },
244
+ method: "POST",
245
+ signal
246
+ });
247
+ } catch (err) {
248
+ return {
249
+ error: err,
250
+ kind: "transient"
251
+ };
252
+ }
253
+ const receivedAt = Date.now();
254
+ const json = await readBodyAsync(response);
255
+ if (response.status === 429 || response.status >= 500) return {
256
+ error: refusal(json, response.status),
257
+ kind: "transient"
258
+ };
259
+ const pair = response.ok ? toPair(json, receivedAt) : void 0;
260
+ if (pair === void 0) throw this.#refused(refusal(json, response.status), response.ok);
261
+ return {
262
+ kind: "ok",
263
+ pair
264
+ };
265
+ }
266
+ #tokenLasting(minimumMs) {
267
+ const current = this.#current;
268
+ return current !== void 0 && current.expiresAt - Date.now() >= minimumMs ? current.accessToken : void 0;
269
+ }
270
+ };
271
+ /**
272
+ * Creates a `getAccessToken` that keeps an OAuth access token fresh by
273
+ * rotating one refresh token against the Roblox token endpoint. Use it as
274
+ * the `getAccessToken` of an OAuth `Credential`; you write the `identity`.
275
+ *
276
+ * Use one refresher per refresh token, in one process. A refresh token is
277
+ * single use, so two refreshers (or two processes) sharing one will spend it
278
+ * twice and lose the grant. Multi-instance consumers bring their own
279
+ * provider.
280
+ *
281
+ * - The first call refreshes. Later calls refresh when less than 120 s
282
+ * remain, measured on the local clock from receipt plus `expires_in`.
283
+ * - The new access token is used only after `onRotate` resolves. A spent
284
+ * refresh token is never sent again. If the saved access token then has
285
+ * less than 60 s left, it exchanges once more.
286
+ * - A network error, 5xx or 429 returns the current token while 60 s or
287
+ * more remain, and throws otherwise.
288
+ * - Each exchange has its own 30 s limit, for the request and the body
289
+ * read. A timeout is handled like a network error.
290
+ * - Any other non-2xx, or a 2xx without a usable token pair, throws a
291
+ * {@link TokenRefreshError}. After `invalid_grant` or such a 2xx, every
292
+ * call throws it again and sends nothing.
293
+ * - Concurrent calls share one exchange. A caller's `signal` stops only its
294
+ * own wait, never the exchange.
295
+ *
296
+ * @param options - The client, the refresh token and the rotation callback.
297
+ * @returns A `getAccessToken` for an OAuth `Credential`.
298
+ * @since 0.4.0
299
+ *
300
+ * @example
301
+ *
302
+ * ```ts
303
+ * import { createOAuthTokenRefresher, type Credential } from "@bedrock-rbx/ocale";
304
+ *
305
+ * let saved = "refresh-0";
306
+ * const getAccessToken = createOAuthTokenRefresher({
307
+ * clientId: "client-id",
308
+ * fetch: async () =>
309
+ * Response.json({ access_token: "access-1", expires_in: 900, refresh_token: "refresh-1" }),
310
+ * onRotate: (refreshToken) => {
311
+ * saved = refreshToken;
312
+ * },
313
+ * refreshToken: saved,
314
+ * });
315
+ * const credential: Credential = { getAccessToken, identity: "user-1", kind: "oauth" };
316
+ *
317
+ * expect(credential.kind).toBe("oauth");
318
+ * return getAccessToken({ signal: new AbortController().signal }).then((token) => {
319
+ * expect(token).toBe("access-1");
320
+ * expect(saved).toBe("refresh-1");
321
+ * });
322
+ * ```
323
+ */
324
+ function createOAuthTokenRefresher(options) {
325
+ const refresher = new OAuthTokenRefresher(options);
326
+ return async ({ signal }) => refresher.getAccessTokenAsync(signal);
327
+ }
328
+ async function readBodyAsync(response) {
329
+ try {
330
+ return JSON.parse(await response.text());
331
+ } catch {
332
+ return;
333
+ }
334
+ }
335
+ function isRecord(value) {
336
+ return value instanceof Object && !Array.isArray(value);
337
+ }
338
+ function toPair(body, receivedAt) {
339
+ if (!isRecord(body)) return;
340
+ const { access_token: accessToken, expires_in: expiresIn, refresh_token: refreshToken } = body;
341
+ if (typeof accessToken !== "string" || accessToken === "" || typeof refreshToken !== "string" || refreshToken === "" || typeof expiresIn !== "number" || !Number.isFinite(expiresIn) || expiresIn <= 0) return;
342
+ return {
343
+ accessToken,
344
+ expiresAt: receivedAt + expiresIn * 1e3,
345
+ refreshToken
346
+ };
347
+ }
348
+ function refusal(body, statusCode) {
349
+ const code = isRecord(body) && typeof body["error"] === "string" ? body["error"] : void 0;
350
+ return new TokenRefreshError(`OAuth token refresh failed with HTTP ${statusCode}`, {
351
+ code,
352
+ statusCode
353
+ });
354
+ }
355
+ function abortedWait(signal) {
356
+ return new RequestAbortedError("Access token wait was aborted", { reason: signal.reason });
357
+ }
358
+ /**
359
+ * Waits for a shared promise, but lets one caller's signal end only that
360
+ * caller's wait.
361
+ *
362
+ * @template T - The value type of the shared promise.
363
+ * @param promise - The shared promise.
364
+ * @param signal - The caller's signal.
365
+ * @returns The value of the shared promise.
366
+ * @rejects RequestAbortedError when the signal aborts first, or the shared
367
+ * promise's own error.
368
+ */
369
+ async function waitAsync(promise, signal) {
370
+ return new Promise((resolve, reject) => {
371
+ function onAbort() {
372
+ reject(abortedWait(signal));
373
+ }
374
+ signal.addEventListener("abort", onAbort);
375
+ promise.then(resolve).catch(reject).finally(() => {
376
+ signal.removeEventListener("abort", onAbort);
377
+ });
378
+ });
379
+ }
380
+ export { ApiError, BadgeCostMismatchError, BadgeGroupSpendPermissionError, BadgeInsufficientFundsError, CredentialError, CredentialNotSupportedError, CredentialRejectedError, GATEWAY_REJECTED, NetworkError, OpenCloudError, PermissionError, PollAbortedError, PollTimeoutError, RESPONSE_UNPARSEABLE, RateLimitError, RateLimitWaitRefusedError, RequestAbortedError, RequestDeadlineExceededError, RetryDelayExceededError, TRANSIENT_TRANSPORT_CODES, TokenRefreshError, UnexpectedResponseError, ValidationError, createFetchHttpClient, createOAuthTokenRefresher, requestContextOf };
69
381
 
70
382
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["createInternalFetchHttpClient"],"sources":["../src/client/fetch-http-client.ts"],"sourcesContent":["import { createFetchHttpClient as createInternalFetchHttpClient } from \"../internal/http/fetch-client.ts\";\nimport type { HttpClient } from \"./types.ts\";\n\n/**\n * Creates the fetch-backed HTTP transport Ocale uses by default.\n *\n * Wrap the returned transport to add tracing, metrics, recording, or other\n * request-level behavior while retaining Ocale's authentication, timeout,\n * upload, response-parsing, and error-classification semantics.\n *\n * @returns Ocale's default fetch-backed HTTP transport.\n * @since 0.3.1\n *\n * @example\n *\n * ```ts\n * import {\n * createFetchHttpClient,\n * type HttpClient,\n * type HttpRequest,\n * } from \"@bedrock-rbx/ocale\";\n * import {\n * type DeleteExperienceIconParameters,\n * UniversesClient,\n * } from \"@bedrock-rbx/ocale/universes\";\n *\n * const defaultHttpClient = createFetchHttpClient();\n * let observedRequests: ReadonlyArray<HttpRequest> = [];\n * const tracedHttpClient: HttpClient = {\n * async request(request, config) {\n * observedRequests = [...observedRequests, request];\n * return defaultHttpClient.request(request, config);\n * },\n * };\n * // A data URL keeps this executable example offline. Production clients\n * // normally omit baseUrl and use Ocale's Roblox Open Cloud default.\n * const commonOptions = { apiKey: \"your-key\", baseUrl: \"data:,#\" };\n * const client = new UniversesClient({\n * ...commonOptions,\n * httpClient: tracedHttpClient,\n * });\n * const undecoratedClient = new UniversesClient({\n * ...commonOptions,\n * httpClient: defaultHttpClient,\n * });\n * const parameters: DeleteExperienceIconParameters = {\n * languageCode: \"en\",\n * universeId: \"42\",\n * };\n * expect(client).toBeInstanceOf(UniversesClient);\n * return Promise.all([\n * client.icon.delete(parameters),\n * undecoratedClient.icon.delete(parameters),\n * ]).then(([result, undecoratedResult]) => {\n * expect(observedRequests).toStrictEqual([{\n * method: \"DELETE\",\n * url: \"/legacy-game-internationalization/v1/game-icon/games/42/language-codes/en\",\n * }]);\n * expect(result).toStrictEqual({ data: undefined, success: true });\n * expect(result).toStrictEqual(undecoratedResult);\n * });\n * ```\n */\nexport const createFetchHttpClient: () => HttpClient = createInternalFetchHttpClient;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAa,wBAA0CA"}
1
+ {"version":3,"file":"index.mjs","names":["createInternalFetchHttpClient"],"sources":["../src/client/fetch-http-client.ts","../src/errors/token-refresh-error.ts","../src/client/oauth-token-refresher.ts"],"sourcesContent":["import { createFetchHttpClient as createInternalFetchHttpClient } from \"../internal/http/fetch-client.ts\";\nimport type { HttpClient } from \"./types.ts\";\n\n/**\n * Creates the fetch-backed HTTP transport Ocale uses by default.\n *\n * Wrap the returned transport to add tracing, metrics, recording, or other\n * request-level behavior while retaining Ocale's authentication, timeout,\n * upload, response-parsing, and error-classification semantics.\n *\n * Pass `fetch` to send through a wrapped or replacement `fetch`. Omit it to\n * use the global `fetch`.\n *\n * @param options - Optional transport settings.\n * @param options.fetch - The `fetch` to send requests through.\n * @returns Ocale's default fetch-backed HTTP transport.\n * @since 0.3.1\n *\n * @example\n *\n * ```ts\n * import {\n * createFetchHttpClient,\n * type HttpClient,\n * type HttpRequest,\n * } from \"@bedrock-rbx/ocale\";\n * import {\n * type DeleteExperienceIconParameters,\n * UniversesClient,\n * } from \"@bedrock-rbx/ocale/universes\";\n *\n * // An injected response keeps this executable example offline.\n * // Omit fetch in production to use the runtime's global fetch.\n * const defaultHttpClient = createFetchHttpClient({\n * fetch: async () => new Response(),\n * });\n * let observedRequests: ReadonlyArray<HttpRequest> = [];\n * const tracedHttpClient: HttpClient = {\n * async request(request, config) {\n * observedRequests = [...observedRequests, request];\n * return defaultHttpClient.request(request, config);\n * },\n * };\n * const commonOptions = {\n * credential: { apiKey: \"your-key\", kind: \"apiKey\" as const },\n * };\n * const client = new UniversesClient({\n * ...commonOptions,\n * httpClient: tracedHttpClient,\n * });\n * const undecoratedClient = new UniversesClient({\n * ...commonOptions,\n * httpClient: defaultHttpClient,\n * });\n * const parameters: DeleteExperienceIconParameters = {\n * languageCode: \"en\",\n * universeId: \"42\",\n * };\n * expect(client).toBeInstanceOf(UniversesClient);\n * return Promise.all([\n * client.icon.delete(parameters),\n * undecoratedClient.icon.delete(parameters),\n * ]).then(([result, undecoratedResult]) => {\n * expect(observedRequests).toStrictEqual([{\n * method: \"DELETE\",\n * url: \"/legacy-game-internationalization/v1/game-icon/games/42/language-codes/en\",\n * }]);\n * expect(result).toStrictEqual({ data: undefined, success: true });\n * expect(result).toStrictEqual(undecoratedResult);\n * });\n * ```\n */\nexport function createFetchHttpClient(options?: {\n\treadonly fetch?: (input: string, init: RequestInit) => Promise<Response>;\n}): HttpClient {\n\treturn createInternalFetchHttpClient(options?.fetch);\n}\n","import { OpenCloudError, type OpenCloudErrorOptions } from \"./base.ts\";\n\n/**\n * Options for constructing a {@link TokenRefreshError}.\n *\n * @since 0.4.0\n */\nexport interface TokenRefreshErrorOptions extends OpenCloudErrorOptions {\n\t/** HTTP status of the token endpoint's response. */\n\treadonly statusCode: number;\n}\n\n/**\n * Thrown by the `getAccessToken` that `createOAuthTokenRefresher` returns\n * when the Roblox token endpoint refuses a refresh. `code` is the OAuth\n * `error` field of the response body (for example `invalid_grant`), or\n * `undefined` when the body has none. A client that calls the provider\n * returns it as the `cause` of a `CredentialError`.\n *\n * @since 0.4.0\n *\n * @example\n *\n * ```ts\n * import { TokenRefreshError } from \"@bedrock-rbx/ocale\";\n *\n * const error = new TokenRefreshError(\"Token refresh refused\", {\n * code: \"invalid_grant\",\n * statusCode: 400,\n * });\n *\n * expect(error.code).toBe(\"invalid_grant\");\n * expect(error.statusCode).toBe(400);\n * ```\n */\nexport class TokenRefreshError extends OpenCloudError {\n\tpublic override readonly name: string = \"TokenRefreshError\";\n\t/** HTTP status of the token endpoint's response. */\n\tpublic readonly statusCode: number;\n\n\t/**\n\t * Creates a new TokenRefreshError.\n\t *\n\t * @param message - Human-readable error description.\n\t * @param options - The OAuth error code and the HTTP status.\n\t */\n\tconstructor(message: string, options: TokenRefreshErrorOptions) {\n\t\tsuper(message, options);\n\t\tthis.statusCode = options.statusCode;\n\t}\n}\n","import { RequestAbortedError } from \"../errors/request-aborted.ts\";\nimport { TokenRefreshError } from \"../errors/token-refresh-error.ts\";\nimport type { Credential } from \"./types.ts\";\n\nconst TOKEN_URL = \"https://apis.roblox.com/oauth/v1/token\";\nconst REFRESH_BELOW_MS = 120_000;\nconst FALLBACK_MIN_MS = 60_000;\nconst EXCHANGE_TIMEOUT_MS = 30_000;\n\n/**\n * Options for {@link createOAuthTokenRefresher}.\n *\n * @since 0.4.0\n */\nexport interface OAuthTokenRefresherOptions {\n\t/** The OAuth app's client id. */\n\treadonly clientId: string;\n\t/**\n\t * The client secret of a confidential app. Omit it for a public app that\n\t * uses a code verifier.\n\t */\n\treadonly clientSecret?: string;\n\t/**\n\t * The `fetch` to send token requests through. Defaults to the global\n\t * `fetch`.\n\t */\n\treadonly fetch?: (input: string, init: RequestInit) => Promise<Response>;\n\t/**\n\t * Saves the new refresh token after each rotation. The new access token is\n\t * used only after it resolves. If it throws, the call throws, and the next\n\t * call retries it with the same token and does no exchange.\n\t */\n\treadonly onRotate: (refreshToken: string) => Promise<void> | void;\n\t/** The current refresh token. It is spent by the first refresh. */\n\treadonly refreshToken: string;\n}\n\ninterface TokenPair {\n\treadonly accessToken: string;\n\treadonly expiresAt: number;\n\treadonly refreshToken: string;\n}\n\ntype ExchangeOutcome =\n\t| { readonly error: unknown; readonly kind: \"transient\" }\n\t| { readonly kind: \"ok\"; readonly pair: TokenPair };\n\n/** The `getAccessToken` of an OAuth {@link Credential}. */\ntype AccessTokenProvider = Extract<Credential, { kind: \"oauth\" }>[\"getAccessToken\"];\n\ntype FetchSeam = NonNullable<OAuthTokenRefresherOptions[\"fetch\"]>;\n\nclass OAuthTokenRefresher {\n\treadonly #clientId: string;\n\treadonly #clientSecret: string | undefined;\n\treadonly #onRotate: OAuthTokenRefresherOptions[\"onRotate\"];\n\treadonly #send: FetchSeam;\n\n\t#current: TokenPair | undefined;\n\t#failure: TokenRefreshError | undefined;\n\t#inFlight: Promise<string> | undefined;\n\t#pending: TokenPair | undefined;\n\t#refreshToken: string;\n\n\tconstructor(options: OAuthTokenRefresherOptions) {\n\t\tthis.#clientId = options.clientId;\n\t\tthis.#clientSecret = options.clientSecret;\n\t\tthis.#onRotate = options.onRotate;\n\t\tthis.#refreshToken = options.refreshToken;\n\t\tthis.#send = options.fetch ?? fetch;\n\t}\n\n\tpublic async getAccessTokenAsync(signal: AbortSignal): Promise<string> {\n\t\tif (signal.aborted) {\n\t\t\tthrow abortedWait(signal);\n\t\t}\n\n\t\tif (this.#failure !== undefined) {\n\t\t\tthrow this.#failure;\n\t\t}\n\n\t\t// A kept unsaved pair only exists after a refresh, which runs below\n\t\t// the threshold, so the current token never short-circuits its save.\n\t\tconst cached = this.#tokenLasting(REFRESH_BELOW_MS);\n\t\tif (cached !== undefined) {\n\t\t\treturn cached;\n\t\t}\n\n\t\tthis.#inFlight ??= this.#refreshAsync().finally(() => {\n\t\t\tthis.#inFlight = undefined;\n\t\t});\n\t\treturn waitAsync(this.#inFlight, signal);\n\t}\n\n\t/**\n\t * Runs one exchange under its own time limit, apart from any caller's\n\t * signal. A timeout is transient, like a network error.\n\t *\n\t * @returns The exchange outcome.\n\t */\n\tasync #exchangeAsync(): Promise<ExchangeOutcome> {\n\t\tconst controller = new AbortController();\n\t\tconst exchange = this.#sendAsync(controller.signal);\n\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst timeout = new Promise<ExchangeOutcome>((resolve) => {\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\tconst error = new DOMException(\"OAuth token exchange timed out\", \"TimeoutError\");\n\t\t\t\tcontroller.abort(error);\n\t\t\t\tresolve({ error, kind: \"transient\" });\n\t\t\t}, EXCHANGE_TIMEOUT_MS);\n\t\t});\n\n\t\ttry {\n\t\t\treturn await Promise.race([exchange, timeout]);\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t#fallback(error: unknown): string {\n\t\tconst token = this.#tokenLasting(FALLBACK_MIN_MS);\n\t\tif (token === undefined) {\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn token;\n\t}\n\n\t#form(): URLSearchParams {\n\t\tconst form = new URLSearchParams({\n\t\t\tclient_id: this.#clientId,\n\t\t\tgrant_type: \"refresh_token\",\n\t\t\trefresh_token: this.#refreshToken,\n\t\t});\n\t\tif (this.#clientSecret !== undefined) {\n\t\t\tform.set(\"client_secret\", this.#clientSecret);\n\t\t}\n\n\t\treturn form;\n\t}\n\n\t/**\n\t * Refreshes and saves a pair. A save can finish late (a retried kept\n\t * pair, or a slow `onRotate`), so when the saved token has under 60 s\n\t * left it exchanges once more with the now saved refresh token.\n\t *\n\t * @returns An access token.\n\t */\n\tasync #refreshAsync(): Promise<string> {\n\t\tconst first = await this.#rotateAsync();\n\t\tif (first.kind === \"transient\") {\n\t\t\treturn this.#fallback(first.error);\n\t\t}\n\n\t\tif (first.pair.expiresAt - Date.now() >= FALLBACK_MIN_MS) {\n\t\t\treturn first.pair.accessToken;\n\t\t}\n\n\t\tconst second = await this.#rotateAsync();\n\t\treturn second.kind === \"transient\" ? this.#fallback(second.error) : second.pair.accessToken;\n\t}\n\n\t/**\n\t * Records a refusal that spent the refresh token, so it is never sent\n\t * again: an `invalid_grant`, or a 2xx whose body held no usable pair.\n\t *\n\t * @param error - The refusal.\n\t * @param accepted - Whether the endpoint answered 2xx.\n\t * @returns The refusal, to throw.\n\t */\n\t#refused(error: TokenRefreshError, accepted: boolean): TokenRefreshError {\n\t\tif (accepted || error.code === \"invalid_grant\") {\n\t\t\tthis.#failure = error;\n\t\t}\n\n\t\treturn error;\n\t}\n\n\t/**\n\t * Exchanges the refresh token unless a kept unsaved pair exists, then\n\t * saves the pair and makes it current.\n\t *\n\t * @returns The saved pair, or the transient failure of the exchange.\n\t */\n\tasync #rotateAsync(): Promise<ExchangeOutcome> {\n\t\tif (this.#pending === undefined) {\n\t\t\tconst outcome = await this.#exchangeAsync();\n\t\t\tif (outcome.kind === \"transient\") {\n\t\t\t\treturn outcome;\n\t\t\t}\n\n\t\t\tthis.#pending = outcome.pair;\n\t\t}\n\n\t\tconst pending = this.#pending;\n\t\tawait this.#onRotate(pending.refreshToken);\n\t\tthis.#current = pending;\n\t\tthis.#refreshToken = pending.refreshToken;\n\t\tthis.#pending = undefined;\n\t\treturn { kind: \"ok\", pair: pending };\n\t}\n\n\tasync #sendAsync(signal: AbortSignal): Promise<ExchangeOutcome> {\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await this.#send(TOKEN_URL, {\n\t\t\t\tbody: this.#form().toString(),\n\t\t\t\theaders: { \"content-type\": \"application/x-www-form-urlencoded\" },\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tsignal,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\treturn { error: err, kind: \"transient\" };\n\t\t}\n\n\t\tconst receivedAt = Date.now();\n\t\tconst json = await readBodyAsync(response);\n\t\tif (response.status === 429 || response.status >= 500) {\n\t\t\treturn { error: refusal(json, response.status), kind: \"transient\" };\n\t\t}\n\n\t\tconst pair = response.ok ? toPair(json, receivedAt) : undefined;\n\t\tif (pair === undefined) {\n\t\t\tthrow this.#refused(refusal(json, response.status), response.ok);\n\t\t}\n\n\t\treturn { kind: \"ok\", pair };\n\t}\n\n\t#tokenLasting(minimumMs: number): string | undefined {\n\t\tconst current = this.#current;\n\t\treturn current !== undefined && current.expiresAt - Date.now() >= minimumMs\n\t\t\t? current.accessToken\n\t\t\t: undefined;\n\t}\n}\n\n/**\n * Creates a `getAccessToken` that keeps an OAuth access token fresh by\n * rotating one refresh token against the Roblox token endpoint. Use it as\n * the `getAccessToken` of an OAuth `Credential`; you write the `identity`.\n *\n * Use one refresher per refresh token, in one process. A refresh token is\n * single use, so two refreshers (or two processes) sharing one will spend it\n * twice and lose the grant. Multi-instance consumers bring their own\n * provider.\n *\n * - The first call refreshes. Later calls refresh when less than 120 s\n * remain, measured on the local clock from receipt plus `expires_in`.\n * - The new access token is used only after `onRotate` resolves. A spent\n * refresh token is never sent again. If the saved access token then has\n * less than 60 s left, it exchanges once more.\n * - A network error, 5xx or 429 returns the current token while 60 s or\n * more remain, and throws otherwise.\n * - Each exchange has its own 30 s limit, for the request and the body\n * read. A timeout is handled like a network error.\n * - Any other non-2xx, or a 2xx without a usable token pair, throws a\n * {@link TokenRefreshError}. After `invalid_grant` or such a 2xx, every\n * call throws it again and sends nothing.\n * - Concurrent calls share one exchange. A caller's `signal` stops only its\n * own wait, never the exchange.\n *\n * @param options - The client, the refresh token and the rotation callback.\n * @returns A `getAccessToken` for an OAuth `Credential`.\n * @since 0.4.0\n *\n * @example\n *\n * ```ts\n * import { createOAuthTokenRefresher, type Credential } from \"@bedrock-rbx/ocale\";\n *\n * let saved = \"refresh-0\";\n * const getAccessToken = createOAuthTokenRefresher({\n * clientId: \"client-id\",\n * fetch: async () =>\n * Response.json({ access_token: \"access-1\", expires_in: 900, refresh_token: \"refresh-1\" }),\n * onRotate: (refreshToken) => {\n * saved = refreshToken;\n * },\n * refreshToken: saved,\n * });\n * const credential: Credential = { getAccessToken, identity: \"user-1\", kind: \"oauth\" };\n *\n * expect(credential.kind).toBe(\"oauth\");\n * return getAccessToken({ signal: new AbortController().signal }).then((token) => {\n * expect(token).toBe(\"access-1\");\n * expect(saved).toBe(\"refresh-1\");\n * });\n * ```\n */\nexport function createOAuthTokenRefresher(\n\toptions: OAuthTokenRefresherOptions,\n): (...args: Parameters<AccessTokenProvider>) => Promise<string> {\n\tconst refresher = new OAuthTokenRefresher(options);\n\treturn async ({ signal }) => refresher.getAccessTokenAsync(signal);\n}\n\nasync function readBodyAsync(response: Response): Promise<JSONValue | undefined> {\n\ttry {\n\t\treturn JSON.parse(await response.text());\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction isRecord(value: JSONValue | undefined): value is Readonly<Record<string, JSONValue>> {\n\treturn value instanceof Object && !Array.isArray(value);\n}\n\nfunction toPair(body: JSONValue | undefined, receivedAt: number): TokenPair | undefined {\n\tif (!isRecord(body)) {\n\t\treturn undefined;\n\t}\n\n\tconst { access_token: accessToken, expires_in: expiresIn, refresh_token: refreshToken } = body;\n\tif (\n\t\ttypeof accessToken !== \"string\" ||\n\t\taccessToken === \"\" ||\n\t\ttypeof refreshToken !== \"string\" ||\n\t\trefreshToken === \"\" ||\n\t\ttypeof expiresIn !== \"number\" ||\n\t\t!Number.isFinite(expiresIn) ||\n\t\texpiresIn <= 0\n\t) {\n\t\treturn undefined;\n\t}\n\n\treturn { accessToken, expiresAt: receivedAt + expiresIn * 1000, refreshToken };\n}\n\nfunction refusal(body: JSONValue | undefined, statusCode: number): TokenRefreshError {\n\tconst code = isRecord(body) && typeof body[\"error\"] === \"string\" ? body[\"error\"] : undefined;\n\treturn new TokenRefreshError(`OAuth token refresh failed with HTTP ${statusCode}`, {\n\t\tcode,\n\t\tstatusCode,\n\t});\n}\n\nfunction abortedWait(signal: AbortSignal): RequestAbortedError {\n\treturn new RequestAbortedError(\"Access token wait was aborted\", { reason: signal.reason });\n}\n\n/**\n * Waits for a shared promise, but lets one caller's signal end only that\n * caller's wait.\n *\n * @template T - The value type of the shared promise.\n * @param promise - The shared promise.\n * @param signal - The caller's signal.\n * @returns The value of the shared promise.\n * @rejects RequestAbortedError when the signal aborts first, or the shared\n * promise's own error.\n */\nasync function waitAsync<T>(promise: Promise<T>, signal: AbortSignal): Promise<T> {\n\treturn new Promise<T>((resolve, reject) => {\n\t\tfunction onAbort(): void {\n\t\t\treject(abortedWait(signal));\n\t\t}\n\n\t\tsignal.addEventListener(\"abort\", onAbort);\n\t\tpromise\n\t\t\t.then(resolve)\n\t\t\t.catch(reject)\n\t\t\t.finally(() => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAAgB,sBAAsB,SAEvB;CACd,OAAOA,wBAA8B,SAAS,KAAK;AACpD;;;;;;;;;;;;;;;;;;;;;;;;;ACzCA,IAAa,oBAAb,cAAuC,eAAe;CACrD,OAAwC;;CAExC;;;;;;;CAQA,YAAY,SAAiB,SAAmC;EAC/D,MAAM,SAAS,OAAO;EACtB,KAAK,aAAa,QAAQ;CAC3B;AACD;;AC9CA,MAAM,YAAY;AAClB,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,sBAAsB;AA6C5B,IAAM,sBAAN,MAA0B;CACzB;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAqC;EAChD,KAAK,YAAY,QAAQ;EACzB,KAAK,gBAAgB,QAAQ;EAC7B,KAAK,YAAY,QAAQ;EACzB,KAA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O,IAAI,SAAY,SAAS,WAAW;EAC1C,SAAS,UAAgB;GACxB,OAAO,YAAY,MAAM,CAAC;EAC3B;EAEA,OAAO,iBAAiB,SAAS,OAAO;EACxC,QACE,KAAK,OAAO,CAAC,CACb,MAAM,MAAM,CAAC,CACb,cAAc;GACd,OAAO,oBAAoB,SAAS,OAAO;EAC5C,CAAC;CACH,CAAC;AACF"}
@@ -0,0 +1,19 @@
1
+ // src/internal/utils/is-date-time-string.ts
2
+ /**
3
+ * Narrows `value` to a string that parses to a real {@link Date} via the
4
+ * `Date(string)` constructor. Used by resource parsers to gate
5
+ * `format: date-time` wire fields before handing them to `new Date(...)`,
6
+ * which silently produces an `Invalid Date` for invalid input.
7
+ *
8
+ * @param value - The unknown wire value to validate.
9
+ * @returns `true` when `value` is a string and `new Date(value).getTime()`
10
+ * is not `NaN`.
11
+ */
12
+ function isDateTimeString(value) {
13
+ if (typeof value !== "string") return false;
14
+ const parsed = new Date(value);
15
+ return !Number.isNaN(parsed.getTime());
16
+ }
17
+ export { isDateTimeString as t };
18
+
19
+ //# sourceMappingURL=is-date-time-string-C91G44SI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-date-time-string-C91G44SI.mjs","names":[],"sources":["../src/internal/utils/is-date-time-string.ts"],"sourcesContent":["/**\n * Narrows `value` to a string that parses to a real {@link Date} via the\n * `Date(string)` constructor. Used by resource parsers to gate\n * `format: date-time` wire fields before handing them to `new Date(...)`,\n * which silently produces an `Invalid Date` for invalid input.\n *\n * @param value - The unknown wire value to validate.\n * @returns `true` when `value` is a string and `new Date(value).getTime()`\n * is not `NaN`.\n */\nexport function isDateTimeString(value: unknown): value is string {\n\tif (typeof value !== \"string\") {\n\t\treturn false;\n\t}\n\n\tconst parsed = new Date(value);\n\treturn !Number.isNaN(parsed.getTime());\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,iBAAiB,OAAiC;CACjE,IAAI,OAAO,UAAU,UACpB,OAAO;CAGR,MAAM,SAAS,IAAI,KAAK,KAAK;CAC7B,OAAO,CAAC,OAAO,MAAM,OAAO,QAAQ,CAAC;AACtC"}
@@ -1,2 +1,28 @@
1
- import { i as RobloxLocale, n as RobloxCreatorLocale, r as RobloxLanguageCode, t as ROBLOX_CREATOR_LOCALES } from "./data.generated-B2ceLfSn.mjs";
2
- export { ROBLOX_CREATOR_LOCALES, type RobloxCreatorLocale, type RobloxLanguageCode, type RobloxLocale };
1
+ import { i as RobloxLocale, n as RobloxCreatorLocale, r as RobloxLanguageCode, t as ROBLOX_CREATOR_LOCALES } from "./data.generated-B4Fztv_7.mjs";
2
+ /**
3
+ * Any string Roblox accepts as a localization key: an underscore locale such
4
+ * as `en_us`, or a language code such as `en` or `zh-hans`.
5
+ *
6
+ * @since 0.4.0
7
+ */
8
+ type RobloxLocalizationKey = RobloxLanguageCode | RobloxLocale;
9
+ /**
10
+ * Checks whether a string is a Roblox localization key, narrowing it to
11
+ * {@link RobloxLocalizationKey}. Region-qualified hyphen forms such as
12
+ * `en-us` are rejected (Roblox writes them as `en_us`), as are language names
13
+ * such as `english`.
14
+ *
15
+ * @since 0.4.0
16
+ * @param value - The string to check.
17
+ * @returns `true` when `value` is a known locale or language code.
18
+ * @example
19
+ * ```ts
20
+ * import { isRobloxLocalizationKey } from "@bedrock-rbx/ocale/locales";
21
+ *
22
+ * expect(isRobloxLocalizationKey("pt_br")).toBe(true);
23
+ * expect(isRobloxLocalizationKey("en-us")).toBe(false);
24
+ * ```
25
+ */
26
+ export declare function isRobloxLocalizationKey(value: string): value is RobloxLocalizationKey;
27
+ export { ROBLOX_CREATOR_LOCALES, type RobloxCreatorLocale, type RobloxLanguageCode, type RobloxLocale, type RobloxLocalizationKey };
28
+ //# sourceMappingURL=locales.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.d.mts","names":[],"sources":["../src/locales/localization-key.ts"],"mappings":";;;;;;;KAYY,wBAAwB,qBAAqB;;;;;;;;;;;;;;;;;;wBAuBzC,wBAAwB,gBAAgB,SAAS"}
package/dist/locales.mjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/locales/data.generated.ts
1
+ // src/locales/data.generated.ts
2
2
  /**
3
3
  * Vendored snapshot of
4
4
  * `https://locale.roblox.com/v1/locales/supported-locales-for-creators`.
@@ -508,7 +508,28 @@ const ROBLOX_CREATOR_LOCALES = [
508
508
  isEnabledForSignupAndLogin: true
509
509
  }
510
510
  ];
511
- //#endregion
512
- export { ROBLOX_CREATOR_LOCALES };
511
+ // src/locales/localization-key.ts
512
+ const LOCALIZATION_KEYS = new Set(ROBLOX_CREATOR_LOCALES.flatMap((row) => [row.locale, row.languageCode]));
513
+ /**
514
+ * Checks whether a string is a Roblox localization key, narrowing it to
515
+ * {@link RobloxLocalizationKey}. Region-qualified hyphen forms such as
516
+ * `en-us` are rejected (Roblox writes them as `en_us`), as are language names
517
+ * such as `english`.
518
+ *
519
+ * @since 0.4.0
520
+ * @param value - The string to check.
521
+ * @returns `true` when `value` is a known locale or language code.
522
+ * @example
523
+ * ```ts
524
+ * import { isRobloxLocalizationKey } from "@bedrock-rbx/ocale/locales";
525
+ *
526
+ * expect(isRobloxLocalizationKey("pt_br")).toBe(true);
527
+ * expect(isRobloxLocalizationKey("en-us")).toBe(false);
528
+ * ```
529
+ */
530
+ function isRobloxLocalizationKey(value) {
531
+ return LOCALIZATION_KEYS.has(value);
532
+ }
533
+ export { ROBLOX_CREATOR_LOCALES, isRobloxLocalizationKey };
513
534
 
514
535
  //# sourceMappingURL=locales.mjs.map