-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1872 from rudderlabs/release/v1.102.0
chore(release): pull release/v1.102.0 into main
- Loading branch information
Showing
10 changed files
with
186 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const languageMap = { | ||
web: ['ts', 'js'], | ||
flutter: ['dart'], | ||
ios: ['m', 'swift'], | ||
android: ['kt', 'java'], | ||
}; | ||
|
||
// Function to check if the template should be generated for a specific language | ||
function filterLanguages(destination, langCode) { | ||
if (!destination?.config?.supportedConnectionModes) { | ||
console.warn(`Destination ${destination.name} is missing supportedConnectionModes`); | ||
return false; | ||
} | ||
const { supportedConnectionModes } = destination.config; | ||
|
||
// Filtering logic | ||
return Object.keys(supportedConnectionModes) | ||
.filter((platform) => { | ||
const modes = supportedConnectionModes[platform]; | ||
// Check if "device" or "hybrid" mode is present | ||
return modes.includes('device') || modes.includes('hybrid'); | ||
}) | ||
.some((platform) => languageMap[platform]?.includes(langCode)); | ||
} | ||
|
||
module.exports = { | ||
filterLanguages, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* eslint-disable no-console */ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const http = require('http'); | ||
const url = require('url'); | ||
const { filterLanguages } = require('./common'); | ||
|
||
const destinationsDir = path.join(__dirname, '../src/configurations/destinations'); | ||
|
||
const getJSDeviceModeDestinations = () => | ||
fs | ||
.readdirSync(destinationsDir) | ||
.map((destination) => { | ||
const dbConfig = fs.readFileSync( | ||
path.join(destinationsDir, destination, 'db-config.json'), | ||
'utf8', | ||
); | ||
return JSON.parse(dbConfig); | ||
}) | ||
.filter((destination) => filterLanguages(destination, 'js')) | ||
.map((destinationDefinition) => { | ||
const cleanDestName = destinationDefinition.name.replace(/[^\dA-Za-z]/g, ''); | ||
return { | ||
id: cleanDestName, | ||
name: destinationDefinition.name, | ||
config: {}, | ||
enabled: true, | ||
destinationDefinitionId: cleanDestName, | ||
destinationDefinition: { | ||
name: destinationDefinition.name, | ||
displayName: destinationDefinition.displayName, | ||
}, | ||
updatedAt: new Date().toISOString(), | ||
}; | ||
}); | ||
|
||
const deviceModeJSDestinations = getJSDeviceModeDestinations(); | ||
|
||
// Sample JSON response for /sourceConfig | ||
const getSourceConfig = (writeKey) => ({ | ||
source: { | ||
id: 'someSourceId', | ||
name: 'http dev', | ||
writeKey, | ||
config: { | ||
statsCollection: { | ||
errors: { | ||
enabled: false, | ||
}, | ||
metrics: { | ||
enabled: false, | ||
}, | ||
}, | ||
}, | ||
enabled: true, | ||
workspaceId: 'someWorkspaceId', | ||
destinations: deviceModeJSDestinations, | ||
updatedAt: new Date().toISOString(), | ||
dataplanes: {}, | ||
}, | ||
updatedAt: new Date().toISOString(), | ||
}); | ||
|
||
// Function to decode and validate Basic Auth | ||
function getAuthInfo(authHeader) { | ||
if (!authHeader || !authHeader.startsWith('Basic ')) { | ||
return {}; | ||
} | ||
|
||
// Decode the Base64 string | ||
const base64Credentials = authHeader.split(' ')[1]; | ||
const credentials = Buffer.from(base64Credentials, 'base64').toString('utf-8'); | ||
const [username, password] = credentials.split(':'); | ||
|
||
return { username, password }; | ||
} | ||
|
||
// Function to handle CORS | ||
function setCorsHeaders(res) { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); // Allow all origins | ||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); // Allowed methods | ||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization'); // Allowed headers | ||
} | ||
|
||
// Create the HTTP server | ||
const server = http.createServer((req, res) => { | ||
// Set CORS headers | ||
setCorsHeaders(res); | ||
|
||
// Handle OPTIONS preflight requests for CORS | ||
if (req.method === 'OPTIONS') { | ||
res.writeHead(204); // No Content | ||
res.end(); | ||
return; | ||
} | ||
|
||
// Parse the request URL | ||
const parsedUrl = url.parse(req.url, true); // `true` parses query parameters into an object | ||
const { query } = parsedUrl; | ||
|
||
const authHeader = req.headers.authorization; | ||
|
||
const authInfo = getAuthInfo(authHeader); | ||
const writeKey = authInfo?.username || query.writeKey; | ||
|
||
// Set response headers | ||
res.writeHead(200, { 'Content-Type': 'application/json' }); | ||
|
||
// Send JSON response | ||
res.end(JSON.stringify(getSourceConfig(writeKey))); | ||
}); | ||
|
||
// Start the server | ||
const PORT = process.env.PORT || 8000; | ||
server.listen(PORT, () => { | ||
console.log(`Server running on http://localhost:${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.