@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.cjs +31 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +30 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
SignPresenterProvider: () => SignPresenterProvider,
|
|
37
37
|
TokenHelper: () => TokenHelper,
|
|
38
38
|
VERSION: () => VERSION,
|
|
39
|
+
authIsExpired: () => authIsExpired,
|
|
39
40
|
getAllProviders: () => getAllProviders,
|
|
40
41
|
getAvailableProviders: () => getAvailableProviders,
|
|
41
42
|
getProvider: () => getProvider,
|
|
@@ -71,27 +72,43 @@ function navigateToPath(instructions, path) {
|
|
|
71
72
|
|
|
72
73
|
// src/helpers/TokenHelper.ts
|
|
73
74
|
function toAuthData(data, fallbacks) {
|
|
75
|
+
const planTypeId = data.plan_type_id || fallbacks?.planTypeId;
|
|
74
76
|
return {
|
|
75
77
|
access_token: data.access_token,
|
|
76
78
|
refresh_token: data.refresh_token || fallbacks?.refreshToken || "",
|
|
77
79
|
token_type: data.token_type || "Bearer",
|
|
78
80
|
created_at: Math.floor(Date.now() / 1e3),
|
|
79
81
|
expires_in: data.expires_in,
|
|
80
|
-
scope: data.scope || fallbacks?.scope || ""
|
|
82
|
+
scope: data.scope || fallbacks?.scope || "",
|
|
83
|
+
...planTypeId ? { planTypeId } : {}
|
|
81
84
|
};
|
|
82
85
|
}
|
|
83
|
-
|
|
86
|
+
function authIsExpired(auth, nowMs = Date.now()) {
|
|
87
|
+
if (!auth?.created_at || !auth.expires_in) return true;
|
|
88
|
+
const lifetimeMs = auth.expires_in * 1e3;
|
|
89
|
+
const expiresAt = (auth.created_at + auth.expires_in) * 1e3;
|
|
90
|
+
const bufferMs = Math.min(5 * 60 * 1e3, Math.floor(lifetimeMs / 10));
|
|
91
|
+
return nowMs > expiresAt - bufferMs;
|
|
92
|
+
}
|
|
93
|
+
var _TokenHelper = class _TokenHelper {
|
|
84
94
|
isAuthValid(auth) {
|
|
85
|
-
|
|
86
|
-
return !this.isTokenExpired(auth);
|
|
95
|
+
return !authIsExpired(auth);
|
|
87
96
|
}
|
|
88
97
|
isTokenExpired(auth) {
|
|
89
|
-
|
|
90
|
-
const expiresAt = (auth.created_at + auth.expires_in) * 1e3;
|
|
91
|
-
return Date.now() > expiresAt - 5 * 60 * 1e3;
|
|
98
|
+
return authIsExpired(auth);
|
|
92
99
|
}
|
|
93
100
|
async refreshToken(config, auth) {
|
|
94
101
|
if (!auth.refresh_token) return null;
|
|
102
|
+
const key = `${config.oauthBase}|${config.clientId}|${auth.refresh_token}`;
|
|
103
|
+
const existing = _TokenHelper.inflight.get(key);
|
|
104
|
+
if (existing) return existing;
|
|
105
|
+
const pending = this.doRefresh(config, auth).finally(() => {
|
|
106
|
+
_TokenHelper.inflight.delete(key);
|
|
107
|
+
});
|
|
108
|
+
_TokenHelper.inflight.set(key, pending);
|
|
109
|
+
return pending;
|
|
110
|
+
}
|
|
111
|
+
async doRefresh(config, auth) {
|
|
95
112
|
try {
|
|
96
113
|
const params = new URLSearchParams({
|
|
97
114
|
grant_type: "refresh_token",
|
|
@@ -105,12 +122,15 @@ var TokenHelper = class {
|
|
|
105
122
|
return null;
|
|
106
123
|
}
|
|
107
124
|
const data = await response.json();
|
|
108
|
-
|
|
125
|
+
const planTypeId = auth.planTypeId;
|
|
126
|
+
return toAuthData(data, { refreshToken: auth.refresh_token, scope: auth.scope, planTypeId });
|
|
109
127
|
} catch {
|
|
110
128
|
return null;
|
|
111
129
|
}
|
|
112
130
|
}
|
|
113
131
|
};
|
|
132
|
+
_TokenHelper.inflight = /* @__PURE__ */ new Map();
|
|
133
|
+
var TokenHelper = _TokenHelper;
|
|
114
134
|
|
|
115
135
|
// src/helpers/OAuthHelper.ts
|
|
116
136
|
function generateCodeVerifier() {
|
|
@@ -1483,9 +1503,7 @@ var B1ChurchProvider = class extends BaseProvider {
|
|
|
1483
1503
|
setPairingData(data) {
|
|
1484
1504
|
if (data && typeof data === "object" && "planTypeId" in data) {
|
|
1485
1505
|
const planTypeId = data.planTypeId;
|
|
1486
|
-
|
|
1487
|
-
} else {
|
|
1488
|
-
this.planTypeId = null;
|
|
1506
|
+
if (typeof planTypeId === "string") this.planTypeId = planTypeId;
|
|
1489
1507
|
}
|
|
1490
1508
|
}
|
|
1491
1509
|
async getCurrentPlan(authData) {
|
|
@@ -18021,7 +18039,7 @@ function getAvailableProviders(ids) {
|
|
|
18021
18039
|
}
|
|
18022
18040
|
|
|
18023
18041
|
// src/index.ts
|
|
18024
|
-
var VERSION = true ? "0.9.
|
|
18042
|
+
var VERSION = true ? "0.9.4" : "dev";
|
|
18025
18043
|
// Annotate the CommonJS export names for ESM import in node:
|
|
18026
18044
|
0 && (module.exports = {
|
|
18027
18045
|
APlayProvider,
|
|
@@ -18040,6 +18058,7 @@ var VERSION = true ? "0.9.2" : "dev";
|
|
|
18040
18058
|
SignPresenterProvider,
|
|
18041
18059
|
TokenHelper,
|
|
18042
18060
|
VERSION,
|
|
18061
|
+
authIsExpired,
|
|
18043
18062
|
getAllProviders,
|
|
18044
18063
|
getAvailableProviders,
|
|
18045
18064
|
getProvider,
|