-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nomad-badges): Digital Nomad program
- putBadges for level1,2,3,4 - sendmail for level1,2,3,4 - incremental levels 1 by 1, no skipping each level for thematters/matters-server#3721
- Loading branch information
Ubuntu
authored and
Ubuntu
committed
Dec 8, 2023
1 parent
d26b7d2
commit de3620e
Showing
4 changed files
with
632 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env -S node --trace-warnings --loader ts-node/esm | ||
|
||
import { checkNomadBadge } from "../lib/check-nomad-badge.js"; | ||
|
||
async function main() { | ||
const args = process.argv.slice(2); | ||
|
||
await checkNomadBadge(); | ||
} | ||
|
||
main().catch((err) => console.error(new Date(), "ERROR:", err)); |
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,53 @@ | ||
import { Context, APIGatewayProxyResult, APIGatewayEvent } from "aws-lambda"; | ||
import { checkNomadBadge } from "../lib/check-nomad-badge.js"; | ||
|
||
export const handler = async ( | ||
event: APIGatewayEvent & { | ||
campaignTagIds?: number[]; | ||
campaignBegins?: Date | string; | ||
campaignEnds?: Date | string; | ||
forceRun?: boolean; | ||
}, | ||
context: Context | ||
): Promise<APIGatewayProxyResult> => { | ||
console.log(`Event:`, event); | ||
console.log(`Context:`, context); | ||
|
||
const { method, path } = (event?.requestContext as any)?.http || {}; | ||
Check warning on line 16 in handlers/check-nomad-badge.ts GitHub Actions / Build & Test
|
||
const { accept, origin }: { accept?: string; origin?: string } = | ||
event?.headers || {}; | ||
if ( | ||
!( | ||
event?.forceRun || | ||
(path === "/refresh" && accept?.includes("application/json")) | ||
) | ||
) { | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
error: | ||
"input error, call with POST /refresh with accept: application/json", | ||
}), | ||
}; | ||
} | ||
|
||
const { campaignTagIds, campaignBegins, campaignEnds } = event; | ||
const retBadges = await checkNomadBadge({ | ||
campaignTagIds, | ||
campaignBegins, | ||
campaignEnds, | ||
}); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ message: "done.", retBadges }), | ||
...(origin && | ||
["https://matters-tech.static.observableusercontent.com"].includes(origin) | ||
? { | ||
headers: { | ||
"Access-Control-Allow-Origin": origin, | ||
}, | ||
} | ||
: null), | ||
}; | ||
}; |
Oops, something went wrong.