@docyrus/docyrus 0.0.11 → 0.0.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.
Files changed (3) hide show
  1. package/main.js +71 -8
  2. package/main.js.map +2 -2
  3. package/package.json +1 -1
package/main.js CHANGED
@@ -63633,7 +63633,7 @@ function buildInputSchema(args, env, options) {
63633
63633
  // package.json
63634
63634
  var package_default = {
63635
63635
  name: "@docyrus/docyrus",
63636
- version: "0.0.11",
63636
+ version: "0.0.12",
63637
63637
  private: false,
63638
63638
  description: "Docyrus API CLI",
63639
63639
  main: "./main.js",
@@ -64020,27 +64020,44 @@ function createAuthCli(dependencies) {
64020
64020
  description: "Authorize CLI using OAuth2 device flow",
64021
64021
  options: external_exports.object({
64022
64022
  clientId: external_exports.string().optional().describe("OAuth2 client id"),
64023
- scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes")
64023
+ scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
64024
+ accessToken: external_exports.string().optional().describe("Manual access token; skips device flow"),
64025
+ refreshToken: external_exports.string().optional().describe("Manual refresh token used with --accessToken")
64024
64026
  }),
64025
64027
  run: async (context) => {
64026
64028
  const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
64029
+ const manualAccessToken = context.options.accessToken?.trim();
64030
+ const manualRefreshToken = context.options.refreshToken?.trim();
64031
+ if (manualRefreshToken && !manualAccessToken) {
64032
+ throw new UserInputError("refreshToken requires accessToken. Pass --accessToken when using --refreshToken.");
64033
+ }
64034
+ const envClientId = getOptionalEnvValue(context.env, "DOCYRUS_API_CLIENT_ID");
64027
64035
  const configuredClientId = await dependencies.environmentConfigService.getDefaultClientId();
64028
64036
  const globalConfiguredClientId = configuredClientId ? void 0 : await dependencies.globalEnvironmentConfigService?.getDefaultClientId();
64029
- const clientId = context.options.clientId || getOptionalEnvValue(context.env, "DOCYRUS_API_CLIENT_ID") || configuredClientId || globalConfiguredClientId;
64037
+ const resolvedClientId = context.options.clientId || envClientId || configuredClientId || globalConfiguredClientId;
64038
+ const clientId = resolvedClientId || (manualAccessToken ? "manual-token" : void 0);
64030
64039
  if (!clientId) {
64031
64040
  throw new UserInputError(
64032
64041
  "Client ID is required. Pass --clientId, set DOCYRUS_API_CLIENT_ID, or login once with --clientId to save it."
64033
64042
  );
64034
64043
  }
64035
64044
  const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
64036
- const profile = await authSessionService.loginWithDeviceFlow({
64045
+ const profile = manualAccessToken ? await authSessionService.loginWithManualTokens({
64046
+ clientId,
64047
+ accessToken: manualAccessToken,
64048
+ refreshToken: manualRefreshToken || void 0,
64049
+ scope: context.options.scope,
64050
+ tokenType: "Bearer"
64051
+ }) : await authSessionService.loginWithDeviceFlow({
64037
64052
  clientId,
64038
64053
  scope: context.options.scope,
64039
64054
  onVerification: (verification) => {
64040
64055
  logVerificationHint(verification, context.agent, dependencies.onMessage);
64041
64056
  }
64042
64057
  });
64043
- await dependencies.environmentConfigService.setDefaultClientId(clientId);
64058
+ if (resolvedClientId) {
64059
+ await dependencies.environmentConfigService.setDefaultClientId(resolvedClientId);
64060
+ }
64044
64061
  return await injectContext({
64045
64062
  apiBaseUrl,
64046
64063
  authStore: dependencies.authStore,
@@ -66282,6 +66299,7 @@ var ApiClient = class {
66282
66299
  };
66283
66300
 
66284
66301
  // src/services/authSession.ts
66302
+ var DEFAULT_MANUAL_ACCESS_TOKEN_EXPIRY_SECONDS = 3600;
66285
66303
  function isRecord5(value) {
66286
66304
  return typeof value === "object" && value !== null;
66287
66305
  }
@@ -66323,6 +66341,22 @@ var AuthSessionService = class {
66323
66341
  onVerification: options.onVerification
66324
66342
  });
66325
66343
  }
66344
+ async loginWithManualTokens(options) {
66345
+ const expiresIn = this.#resolveManualAccessTokenExpiresIn(options.accessToken);
66346
+ const profile = await this.#buildProfileFromToken(
66347
+ options.clientId,
66348
+ {
66349
+ accessToken: options.accessToken,
66350
+ refreshToken: options.refreshToken,
66351
+ tokenType: options.tokenType || "Bearer",
66352
+ scope: options.scope,
66353
+ expiresIn
66354
+ },
66355
+ {}
66356
+ );
66357
+ await this.#persistProfile(profile);
66358
+ return profile;
66359
+ }
66326
66360
  async getValidAccessToken() {
66327
66361
  const activeProfile = await this.params.authStore.getActiveProfile(this.#apiBaseUrl);
66328
66362
  if (!activeProfile) {
@@ -66517,9 +66551,7 @@ var AuthSessionService = class {
66517
66551
  expectedUserId: options.expectedUserId,
66518
66552
  expectedTenantId: options.expectedTenantId
66519
66553
  });
66520
- await this.params.authStore.upsertProfile(profile);
66521
- await this.#refreshTenantCatalog(profile.userId, profile.accessToken, profile.tenantId);
66522
- await this.params.authStore.setActiveAccountTenant(this.#apiBaseUrl, profile.userId, profile.tenantId);
66554
+ await this.#persistProfile(profile);
66523
66555
  return profile;
66524
66556
  } catch (error48) {
66525
66557
  if (!(error48 instanceof ApiResponseError)) {
@@ -66658,6 +66690,11 @@ var AuthSessionService = class {
66658
66690
  lastUsedAt: nowIso
66659
66691
  });
66660
66692
  }
66693
+ async #persistProfile(profile) {
66694
+ await this.params.authStore.upsertProfile(profile);
66695
+ await this.#refreshTenantCatalog(profile.userId, profile.accessToken, profile.tenantId);
66696
+ await this.params.authStore.setActiveAccountTenant(this.#apiBaseUrl, profile.userId, profile.tenantId);
66697
+ }
66661
66698
  async #ensureProfileAccessToken(profile) {
66662
66699
  if (!this.#isExpired(profile.expiresAt)) {
66663
66700
  return profile;
@@ -66773,6 +66810,32 @@ var AuthSessionService = class {
66773
66810
  #now() {
66774
66811
  return this.params.now ? this.params.now() : Date.now();
66775
66812
  }
66813
+ #resolveManualAccessTokenExpiresIn(accessToken) {
66814
+ const token = accessToken.trim();
66815
+ if (!token) {
66816
+ return DEFAULT_MANUAL_ACCESS_TOKEN_EXPIRY_SECONDS;
66817
+ }
66818
+ const parts = token.split(".");
66819
+ if (parts.length < 2) {
66820
+ return DEFAULT_MANUAL_ACCESS_TOKEN_EXPIRY_SECONDS;
66821
+ }
66822
+ try {
66823
+ const payloadSegment = parts[1].replace(/-/g, "+").replace(/_/g, "/");
66824
+ const paddingLength = payloadSegment.length % 4;
66825
+ const paddedPayload = paddingLength === 0 ? payloadSegment : payloadSegment.padEnd(payloadSegment.length + (4 - paddingLength), "=");
66826
+ const decodedPayload = Buffer.from(paddedPayload, "base64").toString("utf8");
66827
+ const parsedPayload = JSON.parse(decodedPayload);
66828
+ if (typeof parsedPayload.exp === "number" && Number.isFinite(parsedPayload.exp)) {
66829
+ const remainingSeconds = Math.floor(parsedPayload.exp - this.#now() / 1e3);
66830
+ if (remainingSeconds > 0) {
66831
+ return remainingSeconds;
66832
+ }
66833
+ }
66834
+ } catch {
66835
+ return DEFAULT_MANUAL_ACCESS_TOKEN_EXPIRY_SECONDS;
66836
+ }
66837
+ return DEFAULT_MANUAL_ACCESS_TOKEN_EXPIRY_SECONDS;
66838
+ }
66776
66839
  };
66777
66840
 
66778
66841
  // src/services/authStore.ts