mdedit-cli 0.4.10 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,17 +12,9 @@ Links:
12
12
  npm install -g mdedit-cli
13
13
  ```
14
14
 
15
- ## Get an API key
15
+ ## Sign in
16
16
 
17
- All APIs require authentication. Create an API key here:
18
-
19
- - [API key docs](https://mdedit.ai/docs/api-keys)
20
-
21
- Signing in through your browser is being rolled out gradually. If it is available
22
- for your account, you can sign in this way instead of creating a key. If it is
23
- not available yet, use an API key. Sign-in uses authorization code with PKCE and
24
- a fixed loopback callback, and your credentials are kept in your operating system
25
- credential manager:
17
+ Sign in to mdedit.ai through your browser. Your credentials are kept in your operating-system credential manager:
26
18
 
27
19
  ```bash
28
20
  mdedit auth login
@@ -30,7 +22,7 @@ mdedit auth status
30
22
  mdedit auth logout
31
23
  ```
32
24
 
33
- Headless and CI environments should keep using scoped API keys. There is no
25
+ For headless and CI workflows, [create a scoped API key](https://mdedit.ai/docs/api-keys). There is no
34
26
  device-code flow, so `--no-browser` does not replace browser sign-in.
35
27
 
36
28
  ## Configure
package/dist/index.js CHANGED
@@ -190,7 +190,8 @@ async function startConversionFromBytes(input, fetchers) {
190
190
  type,
191
191
  inputKey,
192
192
  inputFormat,
193
- ...outputFormat ? { outputFormat } : {},
193
+ // Dedicated PDF/MP3/ZIP requests reject pandoc-only fields.
194
+ ...type === "pandoc" && outputFormat ? { outputFormat } : {},
194
195
  ...outputFileName ? { outputFileName } : {},
195
196
  ...toolRunId ? { toolRunId } : {}
196
197
  },
@@ -1670,13 +1671,14 @@ async function discoverOAuthConfiguration() {
1670
1671
  const authorizationEndpoint = process.env.MDEDIT_OAUTH_AUTHORIZATION_ENDPOINT;
1671
1672
  const tokenEndpoint = process.env.MDEDIT_OAUTH_TOKEN_ENDPOINT;
1672
1673
  const revocationEndpoint = process.env.MDEDIT_OAUTH_REVOCATION_ENDPOINT;
1673
- if (clientId && authorizationEndpoint && tokenEndpoint && revocationEndpoint) {
1674
+ if (clientId && authorizationEndpoint && tokenEndpoint) {
1674
1675
  return {
1675
1676
  authorizationEndpoint,
1676
1677
  clientId,
1677
1678
  defaultScopes: (process.env.MDEDIT_OAUTH_SCOPES || "").split(",").map((scope) => scope.trim()).filter(Boolean),
1678
1679
  resource: process.env.MDEDIT_OAUTH_RESOURCE || "https://apiv2.mdedit.ai/api",
1679
1680
  revocationEndpoint,
1681
+ scopeFormat: process.env.MDEDIT_OAUTH_SCOPE_FORMAT === "bare" ? "bare" : "resource",
1680
1682
  tokenEndpoint
1681
1683
  };
1682
1684
  }
@@ -1685,22 +1687,34 @@ async function discoverOAuthConfiguration() {
1685
1687
  throw new Error(`OAuth discovery failed (${response.status})`);
1686
1688
  }
1687
1689
  const document = await response.json();
1688
- if (!document.clientId || !document.authorizationEndpoint || !document.tokenEndpoint || !document.revocationEndpoint || !document.resource || !Array.isArray(document.defaultScopes)) {
1690
+ if (!document.clientId || !document.authorizationEndpoint || !document.tokenEndpoint || !document.resource || !Array.isArray(document.defaultScopes)) {
1689
1691
  throw new Error("OAuth discovery response is incomplete");
1690
1692
  }
1691
1693
  return document;
1692
1694
  }
1693
- function credentialStore() {
1695
+ function credentialStore(discovery) {
1694
1696
  return new OsCredentialStore({
1695
1697
  loadProfileIndex: async () => profileIndex(),
1696
- saveProfileIndex: async (profiles) => setProfileIndex(profiles)
1698
+ saveProfileIndex: async (profiles) => setProfileIndex(profiles),
1699
+ // Keep existing Cognito credentials for rollback, while preventing a
1700
+ // previously valid Cognito token from being sent to Clerk or the API after
1701
+ // discovery changes providers.
1702
+ service: discovery.scopeFormat === "bare" ? "ai.mdedit.oauth.clerk" : "ai.mdedit.oauth"
1697
1703
  });
1698
1704
  }
1699
- function qualifyOAuthScopes(scopes, resource) {
1705
+ function qualifyOAuthScopes(scopes, resource, format = "resource") {
1700
1706
  const prefix = `${resource.replace(/\/+$/, "")}/`;
1707
+ const standardScopes = /* @__PURE__ */ new Set(["openid", "email", "profile", "offline_access"]);
1701
1708
  return [...new Set(scopes.map((scope) => {
1702
1709
  const normalized = scope.trim();
1703
1710
  if (!normalized) return "";
1711
+ if (standardScopes.has(normalized)) return normalized;
1712
+ if (format === "bare") {
1713
+ if (!/^[a-z][a-z0-9_/-]*:[a-z][a-z0-9_-]*$/.test(normalized)) {
1714
+ throw new Error(`Invalid OAuth scope: ${normalized}`);
1715
+ }
1716
+ return normalized;
1717
+ }
1704
1718
  if (normalized.startsWith(prefix)) return normalized;
1705
1719
  if (normalized.includes("://") || normalized.includes("/")) {
1706
1720
  throw new Error(`OAuth scope is for a different resource: ${normalized}`);
@@ -1717,7 +1731,7 @@ async function oauthClient(scopes) {
1717
1731
  redirectUri: FIXED_REDIRECT_URI,
1718
1732
  resource: discovery.resource,
1719
1733
  revocationEndpoint: discovery.revocationEndpoint,
1720
- scopes: qualifyOAuthScopes(selectedScopes, discovery.resource),
1734
+ scopes: qualifyOAuthScopes(selectedScopes, discovery.resource, discovery.scopeFormat),
1721
1735
  tokenEndpoint: discovery.tokenEndpoint
1722
1736
  };
1723
1737
  const cacheKey = JSON.stringify(configuration);
@@ -1725,7 +1739,7 @@ async function oauthClient(scopes) {
1725
1739
  if (existing) return existing;
1726
1740
  const client = new NodeOAuthClient({
1727
1741
  configuration,
1728
- credentialStore: credentialStore()
1742
+ credentialStore: credentialStore(discovery)
1729
1743
  });
1730
1744
  oauthClientsByConfiguration.set(cacheKey, client);
1731
1745
  return client;
@@ -1800,7 +1814,14 @@ async function logoutOAuth({
1800
1814
  async function storedOAuthAccessToken(profile, forceRefresh = false) {
1801
1815
  const normalizedProfile = activeProfile(profile);
1802
1816
  if (!profileIndex().includes(normalizedProfile)) return null;
1803
- return (await oauthClient()).getAccessToken(normalizedProfile, { forceRefresh });
1817
+ try {
1818
+ return await (await oauthClient()).getAccessToken(normalizedProfile, { forceRefresh });
1819
+ } catch (error) {
1820
+ if (error instanceof OAuthClientError && error.code === "OAUTH_LOGIN_REQUIRED") {
1821
+ return null;
1822
+ }
1823
+ throw error;
1824
+ }
1804
1825
  }
1805
1826
  var DEFAULT_PROFILE, FIXED_REDIRECT_URI, oauthClientsByConfiguration;
1806
1827
  var init_oauth = __esm({