poe-code 3.0.292 → 3.0.294
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +60 -15
- package/dist/index.js.map +3 -3
- package/dist/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/opencode-poe-auth/dist/poe-auth-plugin.js +32 -5
- package/packages/poe-oauth/dist/check-auth.js +10 -6
- package/packages/poe-oauth/dist/loopback-authorization.js +33 -16
- package/packages/poe-oauth/dist/oauth-client.js +35 -17
package/dist/index.js
CHANGED
|
@@ -63528,19 +63528,23 @@ function isCurrentBalanceResponse(value) {
|
|
|
63528
63528
|
const data = value;
|
|
63529
63529
|
const email = getOwnString3(data, "email");
|
|
63530
63530
|
const balance = getOwnEntry21(data, "current_point_balance");
|
|
63531
|
-
const hasEmail = email !== void 0
|
|
63531
|
+
const hasEmail = email !== void 0;
|
|
63532
63532
|
const hasBalance = balance !== void 0;
|
|
63533
63533
|
if (!hasEmail && !hasBalance) {
|
|
63534
63534
|
return false;
|
|
63535
63535
|
}
|
|
63536
|
-
return balance === void 0 || balance === null || typeof balance === "number" && Number.isFinite(balance);
|
|
63536
|
+
return balance === void 0 || balance === null || typeof balance === "number" && Number.isFinite(balance) && balance >= 0;
|
|
63537
63537
|
}
|
|
63538
63538
|
function getOwnEntry21(record, key2) {
|
|
63539
63539
|
return Object.prototype.hasOwnProperty.call(record, key2) ? record[key2] : void 0;
|
|
63540
63540
|
}
|
|
63541
63541
|
function getOwnString3(record, key2) {
|
|
63542
63542
|
const value = getOwnEntry21(record, key2);
|
|
63543
|
-
|
|
63543
|
+
if (typeof value !== "string") {
|
|
63544
|
+
return void 0;
|
|
63545
|
+
}
|
|
63546
|
+
const trimmed = value.trim();
|
|
63547
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
63544
63548
|
}
|
|
63545
63549
|
function getOwnNumber(record, key2) {
|
|
63546
63550
|
const value = getOwnEntry21(record, key2);
|
|
@@ -63652,6 +63656,21 @@ function waitForAuthorizationCode2(server, authorizationUrl, options, callbackPa
|
|
|
63652
63656
|
}
|
|
63653
63657
|
const error3 = url.searchParams.get("error");
|
|
63654
63658
|
if (error3 !== null) {
|
|
63659
|
+
try {
|
|
63660
|
+
validateAuthorizationCallbackBinding2(
|
|
63661
|
+
{
|
|
63662
|
+
state: url.searchParams.get("state"),
|
|
63663
|
+
iss: url.searchParams.get("iss")
|
|
63664
|
+
},
|
|
63665
|
+
expectedAuthorization
|
|
63666
|
+
);
|
|
63667
|
+
} catch (validationError) {
|
|
63668
|
+
res.writeHead(400);
|
|
63669
|
+
res.end(
|
|
63670
|
+
validationError instanceof Error ? validationError.message : "Invalid OAuth callback"
|
|
63671
|
+
);
|
|
63672
|
+
return;
|
|
63673
|
+
}
|
|
63655
63674
|
const description = url.searchParams.get("error_description") ?? error3;
|
|
63656
63675
|
res.writeHead(400);
|
|
63657
63676
|
res.end(`Authorization failed: ${description}`);
|
|
@@ -63659,11 +63678,14 @@ function waitForAuthorizationCode2(server, authorizationUrl, options, callbackPa
|
|
|
63659
63678
|
return;
|
|
63660
63679
|
}
|
|
63661
63680
|
try {
|
|
63662
|
-
const code = validateAuthorizationCallbackParameters2(
|
|
63663
|
-
|
|
63664
|
-
|
|
63665
|
-
|
|
63666
|
-
|
|
63681
|
+
const code = validateAuthorizationCallbackParameters2(
|
|
63682
|
+
{
|
|
63683
|
+
code: url.searchParams.get("code"),
|
|
63684
|
+
state: url.searchParams.get("state"),
|
|
63685
|
+
iss: url.searchParams.get("iss")
|
|
63686
|
+
},
|
|
63687
|
+
expectedAuthorization
|
|
63688
|
+
);
|
|
63667
63689
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
63668
63690
|
res.end(buildSuccessPage2(options.landingPage));
|
|
63669
63691
|
settle(() => resolve11(code));
|
|
@@ -63734,6 +63756,10 @@ function validateAuthorizationCallbackParameters2(callback, expected) {
|
|
|
63734
63756
|
if (callback.code === null || callback.code.length === 0) {
|
|
63735
63757
|
throw new Error("OAuth callback missing authorization code");
|
|
63736
63758
|
}
|
|
63759
|
+
validateAuthorizationCallbackBinding2(callback, expected);
|
|
63760
|
+
return callback.code;
|
|
63761
|
+
}
|
|
63762
|
+
function validateAuthorizationCallbackBinding2(callback, expected) {
|
|
63737
63763
|
if (expected.state !== null) {
|
|
63738
63764
|
if (callback.state === null || callback.state.length === 0) {
|
|
63739
63765
|
throw new Error("OAuth callback missing state");
|
|
@@ -63750,7 +63776,6 @@ function validateAuthorizationCallbackParameters2(callback, expected) {
|
|
|
63750
63776
|
if (callback.iss !== null && callback.iss.length > 0 && expected.issuer !== null && callback.iss !== expected.issuer) {
|
|
63751
63777
|
throw new Error("OAuth callback issuer mismatch");
|
|
63752
63778
|
}
|
|
63753
|
-
return callback.code;
|
|
63754
63779
|
}
|
|
63755
63780
|
function escapeHtml3(text5) {
|
|
63756
63781
|
return text5.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
@@ -63792,8 +63817,13 @@ var init_pkce2 = __esm({
|
|
|
63792
63817
|
// packages/poe-oauth/src/oauth-client.ts
|
|
63793
63818
|
function createOAuthClient(config2) {
|
|
63794
63819
|
const fetchFn = config2.fetch ?? globalThis.fetch;
|
|
63820
|
+
const clientId = validateClientId(config2.clientId);
|
|
63821
|
+
const normalizedConfig = {
|
|
63822
|
+
...config2,
|
|
63823
|
+
clientId
|
|
63824
|
+
};
|
|
63795
63825
|
return {
|
|
63796
|
-
authorize: () => startAuthorization(
|
|
63826
|
+
authorize: () => startAuthorization(normalizedConfig, fetchFn)
|
|
63797
63827
|
};
|
|
63798
63828
|
}
|
|
63799
63829
|
function generateCodeVerifier3() {
|
|
@@ -63886,12 +63916,12 @@ async function exchangeCodeForApiKey(params) {
|
|
|
63886
63916
|
throw new Error("Token response must be a JSON object");
|
|
63887
63917
|
}
|
|
63888
63918
|
const data = value;
|
|
63889
|
-
const apiKey = getOwnString4(data, "api_key");
|
|
63919
|
+
const apiKey = getOwnString4(data, "api_key")?.trim();
|
|
63890
63920
|
const apiKeyExpiresIn = getOwnEntry23(data, "api_key_expires_in");
|
|
63891
|
-
if (apiKey === void 0 || apiKey.
|
|
63921
|
+
if (apiKey === void 0 || apiKey.length === 0) {
|
|
63892
63922
|
throw new Error("Token response missing api_key field");
|
|
63893
63923
|
}
|
|
63894
|
-
if (apiKeyExpiresIn !== void 0 &&
|
|
63924
|
+
if (apiKeyExpiresIn !== void 0 && !isValidExpiresIn(apiKeyExpiresIn)) {
|
|
63895
63925
|
throw new Error("Token response invalid api_key_expires_in field");
|
|
63896
63926
|
}
|
|
63897
63927
|
return {
|
|
@@ -63927,7 +63957,21 @@ function getOwnString4(record, key2) {
|
|
|
63927
63957
|
const value = getOwnEntry23(record, key2);
|
|
63928
63958
|
return typeof value === "string" ? value : void 0;
|
|
63929
63959
|
}
|
|
63930
|
-
|
|
63960
|
+
function validateClientId(clientId) {
|
|
63961
|
+
const trimmed = clientId.trim();
|
|
63962
|
+
if (trimmed.length === 0 || trimmed !== clientId) {
|
|
63963
|
+
throw new Error("Poe OAuth clientId must not be blank or contain surrounding whitespace.");
|
|
63964
|
+
}
|
|
63965
|
+
return clientId;
|
|
63966
|
+
}
|
|
63967
|
+
function isValidExpiresIn(value) {
|
|
63968
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value < 0) {
|
|
63969
|
+
return false;
|
|
63970
|
+
}
|
|
63971
|
+
const expiresAt = Date.now() + value * 1e3;
|
|
63972
|
+
return Number.isSafeInteger(expiresAt) && expiresAt <= MAX_VALID_EPOCH_MS;
|
|
63973
|
+
}
|
|
63974
|
+
var DEFAULT_AUTHORIZATION_ENDPOINT, DEFAULT_TOKEN_ENDPOINT, MAX_VALID_EPOCH_MS;
|
|
63931
63975
|
var init_oauth_client = __esm({
|
|
63932
63976
|
"packages/poe-oauth/src/oauth-client.ts"() {
|
|
63933
63977
|
"use strict";
|
|
@@ -63936,6 +63980,7 @@ var init_oauth_client = __esm({
|
|
|
63936
63980
|
init_pkce2();
|
|
63937
63981
|
DEFAULT_AUTHORIZATION_ENDPOINT = "https://poe.com/oauth/authorize";
|
|
63938
63982
|
DEFAULT_TOKEN_ENDPOINT = "https://api.poe.com/token";
|
|
63983
|
+
MAX_VALID_EPOCH_MS = 864e13;
|
|
63939
63984
|
}
|
|
63940
63985
|
});
|
|
63941
63986
|
|
|
@@ -136735,7 +136780,7 @@ var init_package2 = __esm({
|
|
|
136735
136780
|
"package.json"() {
|
|
136736
136781
|
package_default2 = {
|
|
136737
136782
|
name: "poe-code",
|
|
136738
|
-
version: "3.0.
|
|
136783
|
+
version: "3.0.294",
|
|
136739
136784
|
description: "CLI tool to configure Poe API for developer workflows.",
|
|
136740
136785
|
type: "module",
|
|
136741
136786
|
main: "./dist/index.js",
|