@churchapps/content-providers 0.9.2 → 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
@@ -259,11 +259,17 @@ declare class OAuthHelper {
259
259
  declare function toAuthData(data: Record<string, unknown>, fallbacks?: {
260
260
  refreshToken?: string;
261
261
  scope?: string;
262
- }): ContentProviderAuthData;
262
+ planTypeId?: string;
263
+ }): ContentProviderAuthData & {
264
+ planTypeId?: string;
265
+ };
266
+ declare function authIsExpired(auth: ContentProviderAuthData | null | undefined, nowMs?: number): boolean;
263
267
  declare class TokenHelper {
268
+ private static inflight;
264
269
  isAuthValid(auth: ContentProviderAuthData | null | undefined): boolean;
265
270
  isTokenExpired(auth: ContentProviderAuthData): boolean;
266
271
  refreshToken(config: ContentProviderConfig, auth: ContentProviderAuthData): Promise<ContentProviderAuthData | null>;
272
+ private doRefresh;
267
273
  }
268
274
 
269
275
  declare class DeviceFlowHelper {
@@ -583,4 +589,4 @@ declare function getAvailableProviders(ids?: string[]): ProviderInfo[];
583
589
  */
584
590
  declare const VERSION: string;
585
591
 
586
- 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
@@ -259,11 +259,17 @@ declare class OAuthHelper {
259
259
  declare function toAuthData(data: Record<string, unknown>, fallbacks?: {
260
260
  refreshToken?: string;
261
261
  scope?: string;
262
- }): ContentProviderAuthData;
262
+ planTypeId?: string;
263
+ }): ContentProviderAuthData & {
264
+ planTypeId?: string;
265
+ };
266
+ declare function authIsExpired(auth: ContentProviderAuthData | null | undefined, nowMs?: number): boolean;
263
267
  declare class TokenHelper {
268
+ private static inflight;
264
269
  isAuthValid(auth: ContentProviderAuthData | null | undefined): boolean;
265
270
  isTokenExpired(auth: ContentProviderAuthData): boolean;
266
271
  refreshToken(config: ContentProviderConfig, auth: ContentProviderAuthData): Promise<ContentProviderAuthData | null>;
272
+ private doRefresh;
267
273
  }
268
274
 
269
275
  declare class DeviceFlowHelper {
@@ -583,4 +589,4 @@ declare function getAvailableProviders(ids?: string[]): ProviderInfo[];
583
589
  */
584
590
  declare const VERSION: string;
585
591
 
586
- 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
@@ -20,27 +20,43 @@ function navigateToPath(instructions, path) {
20
20
 
21
21
  // src/helpers/TokenHelper.ts
22
22
  function toAuthData(data, fallbacks) {
23
+ const planTypeId = data.plan_type_id || fallbacks?.planTypeId;
23
24
  return {
24
25
  access_token: data.access_token,
25
26
  refresh_token: data.refresh_token || fallbacks?.refreshToken || "",
26
27
  token_type: data.token_type || "Bearer",
27
28
  created_at: Math.floor(Date.now() / 1e3),
28
29
  expires_in: data.expires_in,
29
- scope: data.scope || fallbacks?.scope || ""
30
+ scope: data.scope || fallbacks?.scope || "",
31
+ ...planTypeId ? { planTypeId } : {}
30
32
  };
31
33
  }
32
- 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 {
33
42
  isAuthValid(auth) {
34
- if (!auth) return false;
35
- return !this.isTokenExpired(auth);
43
+ return !authIsExpired(auth);
36
44
  }
37
45
  isTokenExpired(auth) {
38
- if (!auth.created_at || !auth.expires_in) return true;
39
- const expiresAt = (auth.created_at + auth.expires_in) * 1e3;
40
- return Date.now() > expiresAt - 5 * 60 * 1e3;
46
+ return authIsExpired(auth);
41
47
  }
42
48
  async refreshToken(config, auth) {
43
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) {
44
60
  try {
45
61
  const params = new URLSearchParams({
46
62
  grant_type: "refresh_token",
@@ -54,12 +70,15 @@ var TokenHelper = class {
54
70
  return null;
55
71
  }
56
72
  const data = await response.json();
57
- return toAuthData(data, { refreshToken: auth.refresh_token, scope: auth.scope });
73
+ const planTypeId = auth.planTypeId;
74
+ return toAuthData(data, { refreshToken: auth.refresh_token, scope: auth.scope, planTypeId });
58
75
  } catch {
59
76
  return null;
60
77
  }
61
78
  }
62
79
  };
80
+ _TokenHelper.inflight = /* @__PURE__ */ new Map();
81
+ var TokenHelper = _TokenHelper;
63
82
 
64
83
  // src/helpers/OAuthHelper.ts
65
84
  function generateCodeVerifier() {
@@ -1432,9 +1451,7 @@ var B1ChurchProvider = class extends BaseProvider {
1432
1451
  setPairingData(data) {
1433
1452
  if (data && typeof data === "object" && "planTypeId" in data) {
1434
1453
  const planTypeId = data.planTypeId;
1435
- this.planTypeId = typeof planTypeId === "string" ? planTypeId : null;
1436
- } else {
1437
- this.planTypeId = null;
1454
+ if (typeof planTypeId === "string") this.planTypeId = planTypeId;
1438
1455
  }
1439
1456
  }
1440
1457
  async getCurrentPlan(authData) {
@@ -17970,7 +17987,7 @@ function getAvailableProviders(ids) {
17970
17987
  }
17971
17988
 
17972
17989
  // src/index.ts
17973
- var VERSION = true ? "0.9.2" : "dev";
17990
+ var VERSION = true ? "0.9.4" : "dev";
17974
17991
  export {
17975
17992
  APlayProvider,
17976
17993
  B1ChurchProvider,
@@ -17988,6 +18005,7 @@ export {
17988
18005
  SignPresenterProvider,
17989
18006
  TokenHelper,
17990
18007
  VERSION,
18008
+ authIsExpired,
17991
18009
  getAllProviders,
17992
18010
  getAvailableProviders,
17993
18011
  getProvider,