@churchapps/content-providers 0.9.3 → 0.9.4

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.d.cts CHANGED
@@ -263,10 +263,13 @@ declare function toAuthData(data: Record<string, unknown>, fallbacks?: {
263
263
  }): ContentProviderAuthData & {
264
264
  planTypeId?: string;
265
265
  };
266
+ declare function authIsExpired(auth: ContentProviderAuthData | null | undefined, nowMs?: number): boolean;
266
267
  declare class TokenHelper {
268
+ private static inflight;
267
269
  isAuthValid(auth: ContentProviderAuthData | null | undefined): boolean;
268
270
  isTokenExpired(auth: ContentProviderAuthData): boolean;
269
271
  refreshToken(config: ContentProviderConfig, auth: ContentProviderAuthData): Promise<ContentProviderAuthData | null>;
272
+ private doRefresh;
270
273
  }
271
274
 
272
275
  declare class DeviceFlowHelper {
@@ -586,4 +589,4 @@ declare function getAvailableProviders(ids?: string[]): ProviderInfo[];
586
589
  */
587
590
  declare const VERSION: string;
588
591
 
589
- export { APlayProvider, type AuthType, B1ChurchProvider, BaseProvider, BibleProjectProvider, CbnProvider, type ContentFile, type ContentFolder, type ContentItem, type ContentProviderAuthData, type ContentProviderConfig, type CurrentPlan, type DeviceAuthorizationResponse, DeviceFlowHelper, type DeviceFlowPollResult, type DeviceFlowState, DropboxProvider, type EndpointValue, type EndpointsConfig, type FeedActionInterface, type FeedFileInterface, type FeedSectionInterface, type FeedVenueInterface, HighVoltageKidsProvider, type IProvider, type InstructionItem, type Instructions, JesusFilmProvider, LessonsChurchProvider, LifeChurchProvider, type MediaLicenseResult, type MediaLicenseStatus, type MessageFileInterface, OAuthHelper, type Plan, type PlanPresentation, type PlanSection, type PlanTimelineItem, PlanningCenterProvider, type ProviderCapabilities, type ProviderInfo, type ProviderLogos, SignPresenterProvider, TokenHelper, VERSION, type VenueActionInterface, type VenueActionsResponseInterface, type VenueSectionActionsInterface, getAllProviders, getAvailableProviders, getProvider, getProviderConfig, isContentFile, isContentFolder, navigateToPath, registerProvider, setProviderSecret, toAuthData };
592
+ export { APlayProvider, type AuthType, B1ChurchProvider, BaseProvider, BibleProjectProvider, CbnProvider, type ContentFile, type ContentFolder, type ContentItem, type ContentProviderAuthData, type ContentProviderConfig, type CurrentPlan, type DeviceAuthorizationResponse, DeviceFlowHelper, type DeviceFlowPollResult, type DeviceFlowState, DropboxProvider, type EndpointValue, type EndpointsConfig, type FeedActionInterface, type FeedFileInterface, type FeedSectionInterface, type FeedVenueInterface, HighVoltageKidsProvider, type IProvider, type InstructionItem, type Instructions, JesusFilmProvider, LessonsChurchProvider, LifeChurchProvider, type MediaLicenseResult, type MediaLicenseStatus, type MessageFileInterface, OAuthHelper, type Plan, type PlanPresentation, type PlanSection, type PlanTimelineItem, PlanningCenterProvider, type ProviderCapabilities, type ProviderInfo, type ProviderLogos, SignPresenterProvider, TokenHelper, VERSION, type VenueActionInterface, type VenueActionsResponseInterface, type VenueSectionActionsInterface, authIsExpired, getAllProviders, getAvailableProviders, getProvider, getProviderConfig, isContentFile, isContentFolder, navigateToPath, registerProvider, setProviderSecret, toAuthData };
package/dist/index.d.ts CHANGED
@@ -263,10 +263,13 @@ declare function toAuthData(data: Record<string, unknown>, fallbacks?: {
263
263
  }): ContentProviderAuthData & {
264
264
  planTypeId?: string;
265
265
  };
266
+ declare function authIsExpired(auth: ContentProviderAuthData | null | undefined, nowMs?: number): boolean;
266
267
  declare class TokenHelper {
268
+ private static inflight;
267
269
  isAuthValid(auth: ContentProviderAuthData | null | undefined): boolean;
268
270
  isTokenExpired(auth: ContentProviderAuthData): boolean;
269
271
  refreshToken(config: ContentProviderConfig, auth: ContentProviderAuthData): Promise<ContentProviderAuthData | null>;
272
+ private doRefresh;
270
273
  }
271
274
 
272
275
  declare class DeviceFlowHelper {
@@ -586,4 +589,4 @@ declare function getAvailableProviders(ids?: string[]): ProviderInfo[];
586
589
  */
587
590
  declare const VERSION: string;
588
591
 
589
- export { APlayProvider, type AuthType, B1ChurchProvider, BaseProvider, BibleProjectProvider, CbnProvider, type ContentFile, type ContentFolder, type ContentItem, type ContentProviderAuthData, type ContentProviderConfig, type CurrentPlan, type DeviceAuthorizationResponse, DeviceFlowHelper, type DeviceFlowPollResult, type DeviceFlowState, DropboxProvider, type EndpointValue, type EndpointsConfig, type FeedActionInterface, type FeedFileInterface, type FeedSectionInterface, type FeedVenueInterface, HighVoltageKidsProvider, type IProvider, type InstructionItem, type Instructions, JesusFilmProvider, LessonsChurchProvider, LifeChurchProvider, type MediaLicenseResult, type MediaLicenseStatus, type MessageFileInterface, OAuthHelper, type Plan, type PlanPresentation, type PlanSection, type PlanTimelineItem, PlanningCenterProvider, type ProviderCapabilities, type ProviderInfo, type ProviderLogos, SignPresenterProvider, TokenHelper, VERSION, type VenueActionInterface, type VenueActionsResponseInterface, type VenueSectionActionsInterface, getAllProviders, getAvailableProviders, getProvider, getProviderConfig, isContentFile, isContentFolder, navigateToPath, registerProvider, setProviderSecret, toAuthData };
592
+ export { APlayProvider, type AuthType, B1ChurchProvider, BaseProvider, BibleProjectProvider, CbnProvider, type ContentFile, type ContentFolder, type ContentItem, type ContentProviderAuthData, type ContentProviderConfig, type CurrentPlan, type DeviceAuthorizationResponse, DeviceFlowHelper, type DeviceFlowPollResult, type DeviceFlowState, DropboxProvider, type EndpointValue, type EndpointsConfig, type FeedActionInterface, type FeedFileInterface, type FeedSectionInterface, type FeedVenueInterface, HighVoltageKidsProvider, type IProvider, type InstructionItem, type Instructions, JesusFilmProvider, LessonsChurchProvider, LifeChurchProvider, type MediaLicenseResult, type MediaLicenseStatus, type MessageFileInterface, OAuthHelper, type Plan, type PlanPresentation, type PlanSection, type PlanTimelineItem, PlanningCenterProvider, type ProviderCapabilities, type ProviderInfo, type ProviderLogos, SignPresenterProvider, TokenHelper, VERSION, type VenueActionInterface, type VenueActionsResponseInterface, type VenueSectionActionsInterface, authIsExpired, getAllProviders, getAvailableProviders, getProvider, getProviderConfig, isContentFile, isContentFolder, navigateToPath, registerProvider, setProviderSecret, toAuthData };
package/dist/index.js CHANGED
@@ -31,18 +31,32 @@ function toAuthData(data, fallbacks) {
31
31
  ...planTypeId ? { planTypeId } : {}
32
32
  };
33
33
  }
34
- var TokenHelper = class {
34
+ function authIsExpired(auth, nowMs = Date.now()) {
35
+ if (!auth?.created_at || !auth.expires_in) return true;
36
+ const lifetimeMs = auth.expires_in * 1e3;
37
+ const expiresAt = (auth.created_at + auth.expires_in) * 1e3;
38
+ const bufferMs = Math.min(5 * 60 * 1e3, Math.floor(lifetimeMs / 10));
39
+ return nowMs > expiresAt - bufferMs;
40
+ }
41
+ var _TokenHelper = class _TokenHelper {
35
42
  isAuthValid(auth) {
36
- if (!auth) return false;
37
- return !this.isTokenExpired(auth);
43
+ return !authIsExpired(auth);
38
44
  }
39
45
  isTokenExpired(auth) {
40
- if (!auth.created_at || !auth.expires_in) return true;
41
- const expiresAt = (auth.created_at + auth.expires_in) * 1e3;
42
- return Date.now() > expiresAt - 5 * 60 * 1e3;
46
+ return authIsExpired(auth);
43
47
  }
44
48
  async refreshToken(config, auth) {
45
49
  if (!auth.refresh_token) return null;
50
+ const key = `${config.oauthBase}|${config.clientId}|${auth.refresh_token}`;
51
+ const existing = _TokenHelper.inflight.get(key);
52
+ if (existing) return existing;
53
+ const pending = this.doRefresh(config, auth).finally(() => {
54
+ _TokenHelper.inflight.delete(key);
55
+ });
56
+ _TokenHelper.inflight.set(key, pending);
57
+ return pending;
58
+ }
59
+ async doRefresh(config, auth) {
46
60
  try {
47
61
  const params = new URLSearchParams({
48
62
  grant_type: "refresh_token",
@@ -63,6 +77,8 @@ var TokenHelper = class {
63
77
  }
64
78
  }
65
79
  };
80
+ _TokenHelper.inflight = /* @__PURE__ */ new Map();
81
+ var TokenHelper = _TokenHelper;
66
82
 
67
83
  // src/helpers/OAuthHelper.ts
68
84
  function generateCodeVerifier() {
@@ -17971,7 +17987,7 @@ function getAvailableProviders(ids) {
17971
17987
  }
17972
17988
 
17973
17989
  // src/index.ts
17974
- var VERSION = true ? "0.9.3" : "dev";
17990
+ var VERSION = true ? "0.9.4" : "dev";
17975
17991
  export {
17976
17992
  APlayProvider,
17977
17993
  B1ChurchProvider,
@@ -17989,6 +18005,7 @@ export {
17989
18005
  SignPresenterProvider,
17990
18006
  TokenHelper,
17991
18007
  VERSION,
18008
+ authIsExpired,
17992
18009
  getAllProviders,
17993
18010
  getAvailableProviders,
17994
18011
  getProvider,