@fluxbase/sdk 2026.3.2 → 2026.3.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 +57 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -1
- package/dist/index.d.ts +86 -1
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1126,6 +1126,63 @@ var FluxbaseAuth = class {
|
|
|
1126
1126
|
return result.data;
|
|
1127
1127
|
});
|
|
1128
1128
|
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Get provider OAuth tokens for calling external APIs
|
|
1131
|
+
*
|
|
1132
|
+
* Retrieves the stored OAuth tokens for a provider (e.g., Google, GitHub) that
|
|
1133
|
+
* the user has previously authenticated with. Use these tokens to call provider
|
|
1134
|
+
* APIs directly (e.g., Google Drive API).
|
|
1135
|
+
*
|
|
1136
|
+
* The access_token is automatically refreshed if it has expired or is about to expire.
|
|
1137
|
+
*
|
|
1138
|
+
* @param provider - OAuth provider name (e.g., 'google', 'github')
|
|
1139
|
+
* @returns Promise with provider tokens (access_token, refresh_token, etc.)
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```typescript
|
|
1143
|
+
* // Get Google tokens to call Google Drive API
|
|
1144
|
+
* const { data, error } = await client.auth.getProviderToken('google')
|
|
1145
|
+
*
|
|
1146
|
+
* if (error) {
|
|
1147
|
+
* if (error.error_code === 'oauth_token_not_found') {
|
|
1148
|
+
* // User needs to sign in with Google first
|
|
1149
|
+
* window.location.href = error.authorize_url
|
|
1150
|
+
* }
|
|
1151
|
+
* return
|
|
1152
|
+
* }
|
|
1153
|
+
*
|
|
1154
|
+
* // Use the access token to call Google Drive API
|
|
1155
|
+
* const response = await fetch('https://www.googleapis.com/drive/v3/files', {
|
|
1156
|
+
* headers: {
|
|
1157
|
+
* 'Authorization': `Bearer ${data.access_token}`
|
|
1158
|
+
* }
|
|
1159
|
+
* })
|
|
1160
|
+
* const files = await response.json()
|
|
1161
|
+
* ```
|
|
1162
|
+
*
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```typescript
|
|
1165
|
+
* // Check token expiry before making API calls
|
|
1166
|
+
* const { data } = await client.auth.getProviderToken('google')
|
|
1167
|
+
*
|
|
1168
|
+
* if (data.expires_in < 60) {
|
|
1169
|
+
* console.warn('Token expires soon, consider caching and refreshing')
|
|
1170
|
+
* }
|
|
1171
|
+
*
|
|
1172
|
+
* // Token expiry is also available as ISO timestamp
|
|
1173
|
+
* console.log('Token expires at:', data.token_expiry)
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
async getProviderToken(provider) {
|
|
1177
|
+
return wrapAsync(async () => {
|
|
1178
|
+
if (!this.session) {
|
|
1179
|
+
throw new Error("Not authenticated");
|
|
1180
|
+
}
|
|
1181
|
+
return await this.fetch.get(
|
|
1182
|
+
`/api/v1/auth/oauth/${provider}/token`
|
|
1183
|
+
);
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1129
1186
|
/**
|
|
1130
1187
|
* Sign in with OTP (One-Time Password) - Supabase-compatible
|
|
1131
1188
|
* Sends a one-time password via email or SMS for passwordless authentication
|