Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove chance of unexpected type coercion and remove unnecessary param to TextEncoder #286

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions doc/scripts/generate-code-samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// from https://github.com/Direct-Freight/df-api-docs/blob/master/scripts/generate-code-samples.js
'use strict'
require('shelljs/global');
var fs = require('fs')
var stringifyObject = require('stringify-object');
var SwaggerSnippet = require('swagger-snippet')
const fs = require('fs')
const SwaggerSnippet = require('swagger-snippet')

if(process.argv[2] != 'skip-pre-bundle')
if(process.argv[2] !== 'skip-pre-bundle')
{
console.log("first bundle combined file to ensure it is up to date");
exec('swagger-repo bundle -o ./web_deploy/swagger.json'); //this wants a single dot
Expand Down Expand Up @@ -45,19 +44,18 @@ var results = SwaggerSnippet.getSwaggerSnippets(SwaggerFile,

results.forEach(function(result)
{
var path = result.url.replace(/http.*api\//,'').replace(/\//g,'@');
const pretty = stringifyObject(result.snippets, { indent: ' ', singleQuotes: false });
const path = result.url.replace(/http.*api\//,'').replace(/\//g,'@');
result.snippets.forEach(function(snippet)
{
var ext = '.txt';
var lang = snippet.id;
let ext = '.txt';
let lang = snippet.id;
lang = lang[0].toUpperCase() + lang.substring(1); //uppercase first letter
if(lang == 'Shell_curl') { ext = '.sh'; lang = 'curl'; }
if(lang == 'Shell_wget') { ext = '.sh'; lang = 'wget'; }
if(lang.substring(0,4) == 'Perl') { ext = '.pl'; }
if(lang.substring(0,6) == 'Python') { ext = '.py'; }
if(lang.substring(0,3) == 'Php') { ext = '.php'; }
var dir = 'spec/code_samples/' + lang + '/' + path + '/';
if(lang === 'Shell_curl') { ext = '.sh'; lang = 'curl'; }
if(lang === 'Shell_wget') { ext = '.sh'; lang = 'wget'; }
if(lang.substring(0,4) === 'Perl') { ext = '.pl'; }
if(lang.substring(0,6) === 'Python') { ext = '.py'; }
if(lang.substring(0,3) === 'Php') { ext = '.php'; }
const dir = 'spec/code_samples/' + lang + '/' + path + '/';
mkdir('-p',dir);
fs.writeFile(dir + result.method.toLowerCase() + ext,snippet.content, (err) => {
if (err)
Expand Down
2 changes: 1 addition & 1 deletion example/tournament-entry-code/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
async function hmacSha256(secret, data) {
const utf8 = new TextEncoder('utf-8');
const utf8 = new TextEncoder();
const algorithm = {name: 'HMAC', hash: 'SHA-256'};
const key = await crypto.subtle.importKey('raw', utf8.encode(secret), algorithm, false, ['sign']);
return await crypto.subtle.sign(algorithm, key, utf8.encode(data));
Expand Down