@dereekb/zoho 13.32.0 → 13.34.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.
package/cli/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@dereekb/zoho/cli",
3
- "version": "13.32.0",
3
+ "version": "13.34.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "zoho-cli": "index.js"
7
7
  },
8
8
  "peerDependencies": {
9
- "@dereekb/dbx-cli": "13.32.0",
10
- "@dereekb/nestjs": "13.32.0",
11
- "@dereekb/rxjs": "13.32.0",
12
- "@dereekb/util": "13.32.0",
13
- "@dereekb/zoho": "13.32.0",
14
- "@dereekb/zoho/nestjs": "13.32.0",
9
+ "@dereekb/dbx-cli": "13.34.0",
10
+ "@dereekb/nestjs": "13.34.0",
11
+ "@dereekb/rxjs": "13.34.0",
12
+ "@dereekb/util": "13.34.0",
13
+ "@dereekb/zoho": "13.34.0",
14
+ "@dereekb/zoho/nestjs": "13.34.0",
15
15
  "yargs": "^18.0.0"
16
16
  },
17
17
  "devDependencies": {
package/index.cjs.js CHANGED
@@ -9407,6 +9407,185 @@ function joinAgentInclude(include) {
9407
9407
  return zohoDeskFetchPageFactory(zohoDeskGetAgents(context));
9408
9408
  }
9409
9409
 
9410
+ /**
9411
+ * The Zoho Accounts API URL for the US datacenter.
9412
+ */ var ZOHO_ACCOUNTS_US_API_URL = 'https://accounts.zoho.com';
9413
+ /**
9414
+ * The Zoho Accounts API URL for the EU datacenter.
9415
+ */ var ZOHO_ACCOUNTS_EU_API_URL = 'https://accounts.zoho.eu';
9416
+ /**
9417
+ * The Zoho Accounts API URL for the India datacenter.
9418
+ */ var ZOHO_ACCOUNTS_IN_API_URL = 'https://accounts.zoho.in';
9419
+ /**
9420
+ * The Zoho Accounts API URL for the Australia datacenter.
9421
+ */ var ZOHO_ACCOUNTS_AU_API_URL = 'https://accounts.zoho.com.au';
9422
+ /**
9423
+ * The Zoho Accounts API URL for the Japan datacenter.
9424
+ */ var ZOHO_ACCOUNTS_JP_API_URL = 'https://accounts.zoho.jp';
9425
+ /**
9426
+ * The Zoho Accounts API URL for the United Kingdom datacenter.
9427
+ */ var ZOHO_ACCOUNTS_UK_API_URL = 'https://accounts.zoho.uk';
9428
+ /**
9429
+ * The Zoho Accounts API URL for the Canada datacenter.
9430
+ */ var ZOHO_ACCOUNTS_CA_API_URL = 'https://accounts.zohocloud.ca';
9431
+ /**
9432
+ * The Zoho Accounts API URL for the Saudi Arabia datacenter.
9433
+ */ var ZOHO_ACCOUNTS_SA_API_URL = 'https://accounts.zoho.sa';
9434
+ /**
9435
+ * Every Zoho Accounts host this package will talk to, keyed by datacenter.
9436
+ *
9437
+ * A closed set rather than an open string, because a value echoed back on an OAuth callback
9438
+ * (`accounts-server`) is checked against it before being used as a token-exchange target — an
9439
+ * unchecked host there would receive the client secret.
9440
+ */ var ZOHO_ACCOUNTS_API_URLS = {
9441
+ us: ZOHO_ACCOUNTS_US_API_URL,
9442
+ eu: ZOHO_ACCOUNTS_EU_API_URL,
9443
+ in: ZOHO_ACCOUNTS_IN_API_URL,
9444
+ au: ZOHO_ACCOUNTS_AU_API_URL,
9445
+ jp: ZOHO_ACCOUNTS_JP_API_URL,
9446
+ uk: ZOHO_ACCOUNTS_UK_API_URL,
9447
+ ca: ZOHO_ACCOUNTS_CA_API_URL,
9448
+ sa: ZOHO_ACCOUNTS_SA_API_URL
9449
+ };
9450
+ /**
9451
+ * Resolves a Zoho Accounts API URL input to the full base URL. A datacenter key maps to that
9452
+ * datacenter's host; custom URLs pass through unchanged.
9453
+ *
9454
+ * @param input - A well-known datacenter key or a custom Zoho Accounts API URL.
9455
+ * @returns The resolved full Zoho Accounts API base URL.
9456
+ */ function zohoAccountsConfigApiUrl(input) {
9457
+ var _ZOHO_ACCOUNTS_API_URLS_input;
9458
+ return (_ZOHO_ACCOUNTS_API_URLS_input = ZOHO_ACCOUNTS_API_URLS[input]) !== null && _ZOHO_ACCOUNTS_API_URLS_input !== void 0 ? _ZOHO_ACCOUNTS_API_URLS_input : input;
9459
+ }
9460
+ /**
9461
+ * Returns whether the input is one of the known Zoho Accounts hosts.
9462
+ *
9463
+ * Exists to gate a value that arrives from OUTSIDE the process: Zoho echoes the issuing datacenter
9464
+ * back as the `accounts-server` OAuth callback parameter, and that host becomes the POST target the
9465
+ * client secret is sent to. An attacker can compose that redirect, so only an exact match against
9466
+ * {@link ZOHO_ACCOUNTS_API_URLS} may be honored.
9467
+ *
9468
+ * @param url - The candidate accounts host.
9469
+ * @returns True when the value is exactly one of the known Zoho Accounts hosts.
9470
+ *
9471
+ * @__NO_SIDE_EFFECTS__
9472
+ */ function isKnownZohoAccountsApiUrl(url) {
9473
+ return url != null && zohoAccountsApiUrlKeyForApiUrl(url) != null;
9474
+ }
9475
+ /**
9476
+ * Returns the datacenter key for a known Zoho Accounts host.
9477
+ *
9478
+ * A trailing slash is tolerated, since Zoho's `accounts-server` value is URL-encoded and some
9479
+ * datacenters echo it back with one; nothing else about the value is normalized.
9480
+ *
9481
+ * @param url - The candidate accounts host.
9482
+ * @returns The matching datacenter key, or undefined when the host is not a known one.
9483
+ *
9484
+ * @__NO_SIDE_EFFECTS__
9485
+ */ function zohoAccountsApiUrlKeyForApiUrl(url) {
9486
+ var result;
9487
+ if (url != null) {
9488
+ var normalized = url.replace(/\/+$/, '');
9489
+ result = Object.keys(ZOHO_ACCOUNTS_API_URLS).find(function(key) {
9490
+ return ZOHO_ACCOUNTS_API_URLS[key] === normalized;
9491
+ });
9492
+ }
9493
+ return result;
9494
+ }
9495
+
9496
+ /**
9497
+ * Path of the Zoho Accounts authorization (consent screen) endpoint.
9498
+ */ var ZOHO_ACCOUNTS_AUTHORIZE_PATH = '/oauth/v2/auth';
9499
+ /**
9500
+ * Path of the Zoho Accounts token endpoint.
9501
+ */ var ZOHO_ACCOUNTS_TOKEN_PATH = '/oauth/v2/token';
9502
+ /**
9503
+ * The delimiter Zoho joins and returns granted scopes with.
9504
+ *
9505
+ * A comma, NOT the space OAuth 2.0 specifies. Both halves of the round trip use this: the authorize
9506
+ * request joins on it, and the granted `scope` string comes back split on it.
9507
+ */ var ZOHO_OAUTH_SCOPE_DELIMITER = ',';
9508
+ /**
9509
+ * The `response_type` used by the authorization-code flow.
9510
+ */ var ZOHO_OAUTH_AUTHORIZE_RESPONSE_TYPE = 'code';
9511
+ /**
9512
+ * Required for Zoho to return a `refresh_token` at all.
9513
+ */ var ZOHO_OAUTH_OFFLINE_ACCESS_TYPE = 'offline';
9514
+ /**
9515
+ * Forces the consent screen.
9516
+ *
9517
+ * Without it Zoho returns a refresh token only on a user's FIRST authorization, so a reconnect would
9518
+ * come back with an access token alone — and a persisted exchange that omits the refresh token
9519
+ * silently breaks the connection.
9520
+ */ var ZOHO_OAUTH_CONSENT_PROMPT = 'consent';
9521
+ /**
9522
+ * Creates a {@link ZohoAccountsAuthorizeUrlFactory} that composes the Zoho authorize URL a user's
9523
+ * browser is redirected to in order to begin the authorization-code flow.
9524
+ *
9525
+ * The client id, redirect URI, and scopes are fixed by the config, since a consumer holds those
9526
+ * constant and varies only the per-request `state`.
9527
+ *
9528
+ * @param config - The client id, redirect URI, scopes, and optional datacenter/consent overrides.
9529
+ * @returns A factory that builds an authorize URL for the given params.
9530
+ * @throws {Error} When no client id is given, or when no scopes are requested — Zoho refuses an
9531
+ * authorize request carrying no scope, and failing at construction beats failing at the consent
9532
+ * screen.
9533
+ *
9534
+ * @see https://www.zoho.com/accounts/protocol/oauth/web-apps/authorization.html
9535
+ *
9536
+ * @example
9537
+ * ```typescript
9538
+ * const authorizeUrlFactory = zohoAccountsAuthorizeUrlFactory({
9539
+ * clientId: 'client-id',
9540
+ * redirectUri: 'http://localhost:9901/oauth/zoho/callback',
9541
+ * scopes: ['AaaServer.profile.READ']
9542
+ * });
9543
+ *
9544
+ * const url = authorizeUrlFactory({ state: 'signed-state' });
9545
+ * ```
9546
+ *
9547
+ * @__NO_SIDE_EFFECTS__
9548
+ */ function zohoAccountsAuthorizeUrlFactory(config) {
9549
+ var clientId = config.clientId, redirectUri = config.redirectUri, scopes = config.scopes, accountsApiUrl = config.accountsApiUrl, accessType = config.accessType, prompt = config.prompt;
9550
+ if (!clientId) {
9551
+ throw new Error('zohoAccountsAuthorizeUrlFactory() requires a clientId.');
9552
+ }
9553
+ if (!scopes.length) {
9554
+ throw new Error('zohoAccountsAuthorizeUrlFactory() requires at least one scope. Zoho refuses an authorize request that carries no scope.');
9555
+ }
9556
+ var apiUrl = zohoAccountsConfigApiUrl(accountsApiUrl !== null && accountsApiUrl !== void 0 ? accountsApiUrl : 'us');
9557
+ var scope = scopes.join(ZOHO_OAUTH_SCOPE_DELIMITER);
9558
+ var authorizeAccessType = accessType !== null && accessType !== void 0 ? accessType : ZOHO_OAUTH_OFFLINE_ACCESS_TYPE;
9559
+ var authorizePrompt = prompt !== null && prompt !== void 0 ? prompt : ZOHO_OAUTH_CONSENT_PROMPT;
9560
+ return function(params) {
9561
+ var url = new URL(ZOHO_ACCOUNTS_AUTHORIZE_PATH, apiUrl);
9562
+ var state = params === null || params === void 0 ? void 0 : params.state;
9563
+ url.searchParams.set('client_id', clientId);
9564
+ url.searchParams.set('redirect_uri', redirectUri);
9565
+ url.searchParams.set('response_type', ZOHO_OAUTH_AUTHORIZE_RESPONSE_TYPE);
9566
+ url.searchParams.set('scope', scope);
9567
+ url.searchParams.set('access_type', authorizeAccessType);
9568
+ url.searchParams.set('prompt', authorizePrompt);
9569
+ if (state != null) {
9570
+ url.searchParams.set('state', state);
9571
+ }
9572
+ return url.toString();
9573
+ };
9574
+ }
9575
+ /**
9576
+ * Splits a granted Zoho `scope` string on the same delimiter the authorize request joins with.
9577
+ *
9578
+ * @param scope - The granted scope string returned on a token response.
9579
+ * @returns The granted scopes, or undefined when none were granted.
9580
+ *
9581
+ * @__NO_SIDE_EFFECTS__
9582
+ */ function zohoOAuthScopesFromScopeString(scope) {
9583
+ var scopes = scope ? scope.split(ZOHO_OAUTH_SCOPE_DELIMITER).filter(function(x) {
9584
+ return x.length > 0;
9585
+ }) : undefined;
9586
+ return (scopes === null || scopes === void 0 ? void 0 : scopes.length) ? scopes : undefined;
9587
+ }
9588
+
9410
9589
  /**
9411
9590
  * Creates a function that exchanges a refresh token for a new short-lived access token
9412
9591
  * via the Zoho OAuth `/oauth/v2/token` endpoint.
@@ -9446,7 +9625,47 @@ function joinAgentInclude(include) {
9446
9625
  client_secret: clientSecret,
9447
9626
  refresh_token: refreshToken
9448
9627
  });
9449
- return context.fetchJson("/oauth/v2/token?".concat(params), zohoAccountsApiFetchJsonInput('POST'));
9628
+ return context.fetchJson("".concat(ZOHO_ACCOUNTS_TOKEN_PATH, "?").concat(params), zohoAccountsApiFetchJsonInput('POST'));
9629
+ };
9630
+ }
9631
+ /**
9632
+ * Creates a function that exchanges a SPECIFIC USER's refresh token for a new access token.
9633
+ *
9634
+ * The per-user counterpart of {@link zohoAccountsAccessToken}, and narrowed the same way
9635
+ * {@link zohoAccountsRefreshTokenFromAuthorizationCode} is: it takes a
9636
+ * {@link ZohoAccountsOAuthClientContext} rather than a full {@link ZohoAccountsContext}. That matters
9637
+ * because a `ZohoAccountsContext`'s config REQUIRES a `refreshToken` — the app's own — so it cannot
9638
+ * describe a client that refreshes on behalf of many users. A full context stays structurally
9639
+ * assignable, so this is usable from either.
9640
+ *
9641
+ * Zoho does not rotate refresh tokens and its refresh response carries NO `refresh_token`, so the
9642
+ * token passed in here stays valid and must be retained by the caller. The response does carry
9643
+ * `api_domain`, which can differ from the one the grant was created with, so persist it.
9644
+ *
9645
+ * @param context - A Zoho Accounts client context providing fetch and client credentials.
9646
+ * @returns Function that exchanges a user's refresh token for an access token.
9647
+ *
9648
+ * @see https://www.zoho.com/accounts/protocol/oauth/web-apps/access-token-expiry.html
9649
+ *
9650
+ * @example
9651
+ * ```typescript
9652
+ * const userAccessToken = zohoAccountsUserAccessToken(accountsClientContext);
9653
+ * const { access_token, api_domain, expires_in } = await userAccessToken({ refreshToken: user.zohoRefreshToken });
9654
+ * ```
9655
+ */ function zohoAccountsUserAccessToken(context) {
9656
+ return function(input) {
9657
+ var _ref, _ref1;
9658
+ var _context_config = context.config, configClientId = _context_config.clientId, configClientSecret = _context_config.clientSecret;
9659
+ var client = input.client, refreshToken = input.refreshToken;
9660
+ var clientId = (_ref = client === null || client === void 0 ? void 0 : client.clientId) !== null && _ref !== void 0 ? _ref : configClientId;
9661
+ var clientSecret = (_ref1 = client === null || client === void 0 ? void 0 : client.clientSecret) !== null && _ref1 !== void 0 ? _ref1 : configClientSecret;
9662
+ var params = fetch.makeUrlSearchParams({
9663
+ grant_type: 'refresh_token',
9664
+ client_id: clientId,
9665
+ client_secret: clientSecret,
9666
+ refresh_token: refreshToken
9667
+ });
9668
+ return context.fetchJson("".concat(ZOHO_ACCOUNTS_TOKEN_PATH, "?").concat(params), zohoAccountsApiFetchJsonInput('POST'));
9450
9669
  };
9451
9670
  }
9452
9671
  /**
@@ -9490,7 +9709,34 @@ function joinAgentInclude(include) {
9490
9709
  code: code,
9491
9710
  redirect_uri: redirectUri
9492
9711
  });
9493
- return context.fetchJson("/oauth/v2/token?".concat(params), zohoAccountsApiFetchJsonInput('POST'));
9712
+ return context.fetchJson("".concat(ZOHO_ACCOUNTS_TOKEN_PATH, "?").concat(params), zohoAccountsApiFetchJsonInput('POST'));
9713
+ };
9714
+ }
9715
+ // MARK: User Info
9716
+ /**
9717
+ * Path of the Zoho Accounts endpoint that describes the authorizing user.
9718
+ */ var ZOHO_ACCOUNTS_USER_INFO_PATH = '/oauth/user/info';
9719
+ /**
9720
+ * Scope required to read {@link zohoAccountsUserInfo}.
9721
+ */ var ZOHO_ACCOUNTS_PROFILE_READ_SCOPE = 'AaaServer.profile.READ';
9722
+ /**
9723
+ * Creates a function that reads the authorizing user's Zoho identity, so a connection can be
9724
+ * labelled with the account it belongs to.
9725
+ *
9726
+ * Requires the {@link ZOHO_ACCOUNTS_PROFILE_READ_SCOPE} scope on the access token.
9727
+ *
9728
+ * @param context - Zoho Accounts OAuth client context providing fetch.
9729
+ * @returns Function that reads the user info for an access token.
9730
+ *
9731
+ * @see https://www.zoho.com/accounts/protocol/oauth/web-apps/get-user-info.html
9732
+ */ function zohoAccountsUserInfo(context) {
9733
+ return function(input) {
9734
+ return context.fetchJson(ZOHO_ACCOUNTS_USER_INFO_PATH, {
9735
+ method: 'GET',
9736
+ headers: {
9737
+ Authorization: "Zoho-oauthtoken ".concat(input.accessToken)
9738
+ }
9739
+ });
9494
9740
  };
9495
9741
  }
9496
9742
  /**
@@ -9506,27 +9752,6 @@ function joinAgentInclude(include) {
9506
9752
  };
9507
9753
  }
9508
9754
 
9509
- /**
9510
- * The Zoho Accounts API URL for the US datacenter.
9511
- */ var ZOHO_ACCOUNTS_US_API_URL = 'https://accounts.zoho.com';
9512
- /**
9513
- * Resolves a Zoho Accounts API URL input to the full base URL. The 'us' key maps to the US datacenter; custom URLs pass through unchanged.
9514
- *
9515
- * @param input - A well-known datacenter key or a custom Zoho Accounts API URL.
9516
- * @returns The resolved full Zoho Accounts API base URL.
9517
- */ function zohoAccountsConfigApiUrl(input) {
9518
- var result;
9519
- switch(input){
9520
- case 'us':
9521
- result = ZOHO_ACCOUNTS_US_API_URL;
9522
- break;
9523
- default:
9524
- result = input;
9525
- break;
9526
- }
9527
- return result;
9528
- }
9529
-
9530
9755
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
9531
9756
  try {
9532
9757
  var info = gen[key](arg);
@@ -9702,6 +9927,50 @@ function _ts_generator(thisArg, body) {
9702
9927
  };
9703
9928
  }
9704
9929
  }
9930
+ /**
9931
+ * Creates the {@link ZohoAccountsFetchFactory} the Zoho Accounts clients use when none is supplied.
9932
+ *
9933
+ * @param fetchHandler - The handler the produced fetches route through.
9934
+ * @returns The default Zoho Accounts fetch factory.
9935
+ *
9936
+ * @__NO_SIDE_EFFECTS__
9937
+ */ function defaultZohoAccountsFetchFactory(fetchHandler) {
9938
+ return function(input) {
9939
+ return fetch.fetchApiFetchService.makeFetch({
9940
+ baseUrl: input.apiUrl,
9941
+ baseRequest: {
9942
+ headers: {
9943
+ 'Content-Type': 'application/json'
9944
+ }
9945
+ },
9946
+ fetchHandler: fetchHandler,
9947
+ timeout: 20 * 1000,
9948
+ requireOkResponse: true,
9949
+ useTimeout: true // use timeout
9950
+ });
9951
+ };
9952
+ }
9953
+ /**
9954
+ * Builds the error-handling fetch pair shared by the full and client-credentials-only clients.
9955
+ *
9956
+ * Shared rather than duplicated because {@link interceptZohoAccounts200StatusWithErrorResponse} is
9957
+ * load-bearing: Zoho answers a failed token exchange with HTTP 200 and an `{ "error": … }` body, so
9958
+ * a hand-rolled fetch would treat a failed exchange as a success with an undefined access token.
9959
+ *
9960
+ * @param baseFetch - The configured base fetch to wrap.
9961
+ * @param logZohoServerErrorFunction - Optional error logging override.
9962
+ * @returns The wrapped fetch and its JSON counterpart.
9963
+ */ function zohoAccountsClientFetch(baseFetch, logZohoServerErrorFunction) {
9964
+ var fetch$1 = handleZohoAccountsErrorFetch(baseFetch, logZohoServerErrorFunction);
9965
+ var fetchJson = fetch.fetchJsonFunction(fetch$1, {
9966
+ interceptJsonResponse: interceptZohoAccounts200StatusWithErrorResponse,
9967
+ handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
9968
+ });
9969
+ return {
9970
+ fetch: fetch$1,
9971
+ fetchJson: fetchJson
9972
+ };
9973
+ }
9705
9974
  /**
9706
9975
  * Creates a {@link ZohoAccountsFactory} from the given configuration.
9707
9976
  *
@@ -9737,20 +10006,7 @@ function _ts_generator(thisArg, body) {
9737
10006
  * @__NO_SIDE_EFFECTS__
9738
10007
  */ function zohoAccountsFactory(factoryConfig) {
9739
10008
  var fetchHandler = zohoRateLimitedFetchHandler();
9740
- var logZohoServerErrorFunction = factoryConfig.logZohoServerErrorFunction, _factoryConfig_fetchFactory = factoryConfig.fetchFactory, fetchFactory = _factoryConfig_fetchFactory === void 0 ? function(input) {
9741
- return fetch.fetchApiFetchService.makeFetch({
9742
- baseUrl: input.apiUrl,
9743
- baseRequest: {
9744
- headers: {
9745
- 'Content-Type': 'application/json'
9746
- }
9747
- },
9748
- fetchHandler: fetchHandler,
9749
- timeout: 20 * 1000,
9750
- requireOkResponse: true,
9751
- useTimeout: true // use timeout
9752
- });
9753
- } : _factoryConfig_fetchFactory;
10009
+ var logZohoServerErrorFunction = factoryConfig.logZohoServerErrorFunction, _factoryConfig_fetchFactory = factoryConfig.fetchFactory, fetchFactory = _factoryConfig_fetchFactory === void 0 ? defaultZohoAccountsFetchFactory(fetchHandler) : _factoryConfig_fetchFactory;
9754
10010
  return function(config) {
9755
10011
  var _config_apiUrl;
9756
10012
  if (!config.refreshToken) {
@@ -9764,11 +10020,7 @@ function _ts_generator(thisArg, body) {
9764
10020
  var baseFetch = fetchFactory({
9765
10021
  apiUrl: apiUrl
9766
10022
  });
9767
- var fetch$1 = handleZohoAccountsErrorFetch(baseFetch, logZohoServerErrorFunction);
9768
- var fetchJson = fetch.fetchJsonFunction(fetch$1, {
9769
- interceptJsonResponse: interceptZohoAccounts200StatusWithErrorResponse,
9770
- handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
9771
- });
10023
+ var _zohoAccountsClientFetch = zohoAccountsClientFetch(baseFetch, logZohoServerErrorFunction), fetch = _zohoAccountsClientFetch.fetch, fetchJson = _zohoAccountsClientFetch.fetchJson;
9772
10024
  var tokenRefresher = function tokenRefresher() {
9773
10025
  return _async_to_generator(function() {
9774
10026
  var createdAt, _ref, access_token, api_domain, scope, expires_in, result;
@@ -9813,7 +10065,7 @@ function _ts_generator(thisArg, body) {
9813
10065
  accessTokenCache: config.accessTokenCache
9814
10066
  });
9815
10067
  var accountsContext = {
9816
- fetch: fetch$1,
10068
+ fetch: fetch,
9817
10069
  fetchJson: fetchJson,
9818
10070
  loadAccessToken: loadAccessToken,
9819
10071
  config: _object_spread_props(_object_spread({}, config), {
@@ -9826,6 +10078,52 @@ function _ts_generator(thisArg, body) {
9826
10078
  return zohoAccounts;
9827
10079
  };
9828
10080
  }
10081
+ /**
10082
+ * Creates a {@link ZohoAccountsOAuthClientFactory}, producing Zoho Accounts clients authenticated by
10083
+ * CLIENT CREDENTIALS ALONE.
10084
+ *
10085
+ * {@link zohoAccountsFactory} requires a refresh token, which a per-user authorization-code handoff
10086
+ * does not have yet — the handoff is how the refresh token is obtained. This client covers exactly
10087
+ * the two endpoints that need no user token: the authorization-code exchange and
10088
+ * `/oauth/user/info`.
10089
+ *
10090
+ * It builds its fetch through the same error handling as the full client, which matters more than it
10091
+ * looks: Zoho answers a failed token exchange with HTTP 200 and an `{ "error": … }` body, and
10092
+ * `interceptZohoAccounts200StatusWithErrorResponse` is what turns that into a thrown error instead
10093
+ * of a "successful" exchange with an undefined access token.
10094
+ *
10095
+ * @param factoryConfig - Configuration providing optional fetch and logging overrides.
10096
+ * @returns A factory function that creates client-credentials-only Zoho Accounts clients.
10097
+ *
10098
+ * @__NO_SIDE_EFFECTS__
10099
+ */ function zohoAccountsOAuthClientFactory(factoryConfig) {
10100
+ var _factoryConfig_fetchHandler;
10101
+ var fetchHandler = (_factoryConfig_fetchHandler = factoryConfig.fetchHandler) !== null && _factoryConfig_fetchHandler !== void 0 ? _factoryConfig_fetchHandler : zohoRateLimitedFetchHandler();
10102
+ var logZohoServerErrorFunction = factoryConfig.logZohoServerErrorFunction, _factoryConfig_fetchFactory = factoryConfig.fetchFactory, fetchFactory = _factoryConfig_fetchFactory === void 0 ? defaultZohoAccountsFetchFactory(fetchHandler) : _factoryConfig_fetchFactory;
10103
+ return function(config) {
10104
+ var _config_apiUrl;
10105
+ if (!config.clientId) {
10106
+ throw new Error('ZohoAccountsOAuthClientConfig missing clientId.');
10107
+ } else if (!config.clientSecret) {
10108
+ throw new Error('ZohoAccountsOAuthClientConfig missing clientSecret.');
10109
+ }
10110
+ var apiUrl = zohoAccountsConfigApiUrl((_config_apiUrl = config.apiUrl) !== null && _config_apiUrl !== void 0 ? _config_apiUrl : 'us');
10111
+ var baseFetch = fetchFactory({
10112
+ apiUrl: apiUrl
10113
+ });
10114
+ var fetchJson = zohoAccountsClientFetch(baseFetch, logZohoServerErrorFunction).fetchJson;
10115
+ var resolvedConfig = _object_spread_props(_object_spread({}, config), {
10116
+ apiUrl: apiUrl
10117
+ });
10118
+ var oauthClientContext = {
10119
+ fetchJson: fetchJson,
10120
+ config: resolvedConfig
10121
+ };
10122
+ return {
10123
+ oauthClientContext: oauthClientContext
10124
+ };
10125
+ };
10126
+ }
9829
10127
  /**
9830
10128
  * Creates a {@link ZohoAccessTokenFactory} that manages access token lifecycle with
9831
10129
  * in-memory caching, optional external cache support, and automatic refresh.
@@ -9977,8 +10275,20 @@ exports.DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION = DEFAULT_ZOHO_
9977
10275
  exports.DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION = DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION;
9978
10276
  exports.MAX_ZOHO_CRM_SEARCH_MODULE_RECORDS_CRITERIA = MAX_ZOHO_CRM_SEARCH_MODULE_RECORDS_CRITERIA;
9979
10277
  exports.MAX_ZOHO_RECRUIT_SEARCH_MODULE_RECORDS_CRITERIA = MAX_ZOHO_RECRUIT_SEARCH_MODULE_RECORDS_CRITERIA;
10278
+ exports.ZOHO_ACCOUNTS_API_URLS = ZOHO_ACCOUNTS_API_URLS;
10279
+ exports.ZOHO_ACCOUNTS_AUTHORIZE_PATH = ZOHO_ACCOUNTS_AUTHORIZE_PATH;
10280
+ exports.ZOHO_ACCOUNTS_AU_API_URL = ZOHO_ACCOUNTS_AU_API_URL;
10281
+ exports.ZOHO_ACCOUNTS_CA_API_URL = ZOHO_ACCOUNTS_CA_API_URL;
10282
+ exports.ZOHO_ACCOUNTS_EU_API_URL = ZOHO_ACCOUNTS_EU_API_URL;
9980
10283
  exports.ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE = ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE;
9981
10284
  exports.ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE = ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE;
10285
+ exports.ZOHO_ACCOUNTS_IN_API_URL = ZOHO_ACCOUNTS_IN_API_URL;
10286
+ exports.ZOHO_ACCOUNTS_JP_API_URL = ZOHO_ACCOUNTS_JP_API_URL;
10287
+ exports.ZOHO_ACCOUNTS_PROFILE_READ_SCOPE = ZOHO_ACCOUNTS_PROFILE_READ_SCOPE;
10288
+ exports.ZOHO_ACCOUNTS_SA_API_URL = ZOHO_ACCOUNTS_SA_API_URL;
10289
+ exports.ZOHO_ACCOUNTS_TOKEN_PATH = ZOHO_ACCOUNTS_TOKEN_PATH;
10290
+ exports.ZOHO_ACCOUNTS_UK_API_URL = ZOHO_ACCOUNTS_UK_API_URL;
10291
+ exports.ZOHO_ACCOUNTS_USER_INFO_PATH = ZOHO_ACCOUNTS_USER_INFO_PATH;
9982
10292
  exports.ZOHO_ACCOUNTS_US_API_URL = ZOHO_ACCOUNTS_US_API_URL;
9983
10293
  exports.ZOHO_CRM_ADD_TAGS_TO_RECORDS_MAX_IDS_ALLOWED = ZOHO_CRM_ADD_TAGS_TO_RECORDS_MAX_IDS_ALLOWED;
9984
10294
  exports.ZOHO_CRM_ALREADY_ASSOCIATED_ERROR_CODE = ZOHO_CRM_ALREADY_ASSOCIATED_ERROR_CODE;
@@ -10009,6 +10319,10 @@ exports.ZOHO_INVALID_DATA_ERROR_CODE = ZOHO_INVALID_DATA_ERROR_CODE;
10009
10319
  exports.ZOHO_INVALID_QUERY_ERROR_CODE = ZOHO_INVALID_QUERY_ERROR_CODE;
10010
10320
  exports.ZOHO_INVALID_TOKEN_ERROR_CODE = ZOHO_INVALID_TOKEN_ERROR_CODE;
10011
10321
  exports.ZOHO_MANDATORY_NOT_FOUND_ERROR_CODE = ZOHO_MANDATORY_NOT_FOUND_ERROR_CODE;
10322
+ exports.ZOHO_OAUTH_AUTHORIZE_RESPONSE_TYPE = ZOHO_OAUTH_AUTHORIZE_RESPONSE_TYPE;
10323
+ exports.ZOHO_OAUTH_CONSENT_PROMPT = ZOHO_OAUTH_CONSENT_PROMPT;
10324
+ exports.ZOHO_OAUTH_OFFLINE_ACCESS_TYPE = ZOHO_OAUTH_OFFLINE_ACCESS_TYPE;
10325
+ exports.ZOHO_OAUTH_SCOPE_DELIMITER = ZOHO_OAUTH_SCOPE_DELIMITER;
10012
10326
  exports.ZOHO_RATE_LIMIT_LIMIT_HEADER = ZOHO_RATE_LIMIT_LIMIT_HEADER;
10013
10327
  exports.ZOHO_RATE_LIMIT_REMAINING_HEADER = ZOHO_RATE_LIMIT_REMAINING_HEADER;
10014
10328
  exports.ZOHO_RATE_LIMIT_RESET_HEADER = ZOHO_RATE_LIMIT_RESET_HEADER;
@@ -10063,6 +10377,7 @@ exports.assertZohoRecruitRecordDataArrayResultHasContent = assertZohoRecruitReco
10063
10377
  exports.createNotes = createNotes;
10064
10378
  exports.createNotesForRecord = createNotesForRecord;
10065
10379
  exports.createTagsForModule = createTagsForModule;
10380
+ exports.defaultZohoAccountsFetchFactory = defaultZohoAccountsFetchFactory;
10066
10381
  exports.deleteAttachmentFromRecord = deleteAttachmentFromRecord;
10067
10382
  exports.deleteNotes = deleteNotes;
10068
10383
  exports.deleteRecord = deleteRecord;
@@ -10094,6 +10409,7 @@ exports.interceptZohoDesk200StatusWithErrorResponse = interceptZohoDesk200Status
10094
10409
  exports.interceptZohoErrorResponseFactory = interceptZohoErrorResponseFactory;
10095
10410
  exports.interceptZohoRecruit200StatusWithErrorResponse = interceptZohoRecruit200StatusWithErrorResponse;
10096
10411
  exports.interceptZohoSign200StatusWithErrorResponse = interceptZohoSign200StatusWithErrorResponse;
10412
+ exports.isKnownZohoAccountsApiUrl = isKnownZohoAccountsApiUrl;
10097
10413
  exports.isZohoCrmValidUrl = isZohoCrmValidUrl;
10098
10414
  exports.isZohoRecruitValidUrl = isZohoRecruitValidUrl;
10099
10415
  exports.isZohoServerErrorResponseDataArrayRef = isZohoServerErrorResponseDataArrayRef;
@@ -10126,9 +10442,14 @@ exports.upsertRecord = upsertRecord;
10126
10442
  exports.zohoAccessTokenStringFactory = zohoAccessTokenStringFactory;
10127
10443
  exports.zohoAccountsAccessToken = zohoAccountsAccessToken;
10128
10444
  exports.zohoAccountsApiFetchJsonInput = zohoAccountsApiFetchJsonInput;
10445
+ exports.zohoAccountsApiUrlKeyForApiUrl = zohoAccountsApiUrlKeyForApiUrl;
10446
+ exports.zohoAccountsAuthorizeUrlFactory = zohoAccountsAuthorizeUrlFactory;
10129
10447
  exports.zohoAccountsConfigApiUrl = zohoAccountsConfigApiUrl;
10130
10448
  exports.zohoAccountsFactory = zohoAccountsFactory;
10449
+ exports.zohoAccountsOAuthClientFactory = zohoAccountsOAuthClientFactory;
10131
10450
  exports.zohoAccountsRefreshTokenFromAuthorizationCode = zohoAccountsRefreshTokenFromAuthorizationCode;
10451
+ exports.zohoAccountsUserAccessToken = zohoAccountsUserAccessToken;
10452
+ exports.zohoAccountsUserInfo = zohoAccountsUserInfo;
10132
10453
  exports.zohoAccountsZohoAccessTokenFactory = zohoAccountsZohoAccessTokenFactory;
10133
10454
  exports.zohoCrmAddTagsToRecords = zohoCrmAddTagsToRecords;
10134
10455
  exports.zohoCrmAddTagsToRecordsRequestBody = zohoCrmAddTagsToRecordsRequestBody;
@@ -10224,6 +10545,7 @@ exports.zohoDeskSearchTags = zohoDeskSearchTags;
10224
10545
  exports.zohoDeskSearchTickets = zohoDeskSearchTickets;
10225
10546
  exports.zohoDeskSearchTicketsPageFactory = zohoDeskSearchTicketsPageFactory;
10226
10547
  exports.zohoFetchPageFactory = zohoFetchPageFactory;
10548
+ exports.zohoOAuthScopesFromScopeString = zohoOAuthScopesFromScopeString;
10227
10549
  exports.zohoRateLimitHeaderDetails = zohoRateLimitHeaderDetails;
10228
10550
  exports.zohoRateLimitedFetchHandler = zohoRateLimitedFetchHandler;
10229
10551
  exports.zohoRecruitAddTagsToRecords = zohoRecruitAddTagsToRecords;