Skip to content

Commit

Permalink
chore(iss-1)!: version 2.0.0 overhaul (#2)
Browse files Browse the repository at this point in the history
* feat(repo): Update instances of .io to .com

* feat(test): update tests to use compatible .net version for macOS

* fix(repo): prepare repo for nuget package upload

fix(repo): clarify code comments

feat(repo): add docbblocks to methods

* feat(repo): Use class input UrlboxOptions to improve typing

* feat(repo): Upgrade package from dotnet 2.0 -> 6.0

* feat(repo): Install dependencies for using env vars locally and in gh actions

* feat(repo): add webhook secret to Urlbox overload, and urlbox api endpoint CONSTS

* feat(repo): implement post sync and post async methods, including response types and custom deserializer

* feat(repo): add tests for render and render async endpoints for success and failure cases

fix(repo): fix blockUrls to be arr

* fix(repo): ensure strings are included in array string representations

* fix(repo): change cookies to obj and fix string interpretation of array

* fix(repo): update cookie type to be tighter to string OR string[]

refactor(repo): update urlboxoptions types

refactor(repo): split classes into their own files

* feat(repo): add a fromCredentials static method, and a webhook verifier method

refactor(repo): make global usings and organise resources and policies into dirs

* fix(repo): update validator to handle header edge cases

* feat(repo): add contribution guide including how to set env vars for test

refactor(readme): update readme with new usage examples including new methods

refactor(repo): update readme with static fromcredentials example, fix test warnings

* fix(repo): ensure options only accepts one of html or url but not both

refactor(repo): move urlboxoptions tests to own file

* feat(repo): add metadata/side renders as types to sync response, with resource tests and test for deserializer in render()

* fix(repo): make download method throw error with urlbox error message

* fix(repo): update urlbox sln to recognise the urlbox.csproj file

chore(repo): remove unused imports

add test to urlboxoptions

fix(repo): seal urlbox class

make urlbox values readonly private, remove unused webhookSecret which only gets consumed in UrlboxWebhookValidator

Implement getUrlboxErrorMessage, which extracts from err message in headers

chore(tests): cleanup tests

chore(repo): place classes into file namespaces

refactor(repo): implement abstract urlbox response

* feat(repo): implement takeScreenshot

chore(repo): capitalise verifywebhooksignature method

chore(repo): reorder methods into categories with public/private

* feat(repo): create Urlbox interface + factory for Dependency injection

* feat(tests): Add tests for checking Urlbox can be instantiated via DI for singleton/request/transient

* feat(tests): enable parallel testing

* feat(repo): add helper methods takemp4 takepdf takewithmeta takemobile and takefullpage

feat(repo):  update the readme WIP

feat(repo): update readme

* feat(repo): add section on render links and the api reference in readme:

fix(repo): add webhookUrl to tests

chore(repo): add note on DI in readme

refactor(repo): verifyWebhookSignature returns the full reponse object as a type instead of bool

chore(repo): move resources into their own dirs

* feat(repo): create an options builder for fluent options creation, with validation

* feat(repo): add in tests for validating screenshot options

* feat(repo): implement validation for engine version

refactor(repo): update readme to include usage of the urlbox options builder

* feat(repo): upgrade package version to 2.0.0, add changelog to readme

chore(repo): add changelog t TOC

refactor(repo): proof read repo

fix(repo): add gh image not showing in repo variant of readme

chore(repo): remove old xunit tests

fix(readme): replace occurrences of screenshotting with rendering

fix(readme): add explanation for getting project keys with screenshot

* fix(repo): rename namespace from screenshots to UrlboxSDK

chore(repo): rename GenerateUrlboxUrl() to GenerateRenderLink()

fix(readme): update comments in JSON to use #

chore(repo): rename GenerateUrlboxUrl() to GenerateRenderLink()

fix(readme): update s3 comment, replace lowercased .render with .Render

* feat(repo): add signed and unsigned variants of render link calls

refactor(repo): GetStatus() now takes a render ID instead of the full status URL

* fix(repo): update snakeCaseNamingPolicy with tests

* feat(repo): introduce UrlboxException, thrown on err with more meaningful information

* fix(repo): update urlboxexception to not use init

* fix(repo): wip - enable nullable on project, introduce enums, tests passing

chore(repo): organise files into directory structure

* fix(repo): handle nullable warnings that came out from enabling nullable in project

* feat(repo): add final enum types to options

chore(repo): cleanup use of this. and reserved keywords

* fix(repo): make ints nullable in options

* feat(repo): add ability to override base url, with tests

* feat(repo): add ability to use Render() and RenderAsync() with a dictionary instead of UrlboxOptions

chore(repo): rename urlgenerator to renderLinkGenerator

chore(repo): change core proj to urlboxSDK to match namespace

* fix(repo): rename target project for tests

chore(repo): move webhook tests to own file

* feat(repo): add tests for getstatus

chore(repo): reorganise project to not use redundant files/folders, split out classes where needed

chore(repo): remove unused nested urlbox dir

* feat(repo): add an extension method for DI easy injectionwhich takes an IOptions (UrlboxConfig)

chore(repo): split error into its own response file

refactor(repo): remove redundant webhookerror for generic UrlboxError

refactor(repo): place urlbox in main namespace, and make quality validated double

chore(repo): move di test into dir

* feat(repo): add a class to mock http requests with use of moq

chore(repo): linting and adding namespaces where missing

* feat(repo): add partial class to implement constructor for the quicktype generated urlboxoptions class

* feat(repo): add internal constructor for testing, which allows mocking http client

* feat(repo): extract value validation logic for reusability

refactor(repo): refactor repo+tests to be compatible with new quicktype generated urlboxOptions class

refactor(repo): move validation logic from builder into urlboxoptionsvalidation class

chore(repo): move main urlbox class to parent dir

* feat(repo): make render links signed by default

chore(repo): keep usage of typing over var consistent

chore(repo): improve test coverage

refactor(repo): remove custom types now that quicktype strictly turns boolikes etc etc into a single type

chore(repo): test update with ssl

* feat(repo): update the readme with the new DI instructions

* fix(repo): move private methods in urlbox to bottom of file, add overload for makepost to serialise UrlboxOptions with quicktyped serializer

refactor(repo): prune readme to make shorter, validate examples

* feat(repo): add example for fail on options

* chore(repo): ensure images show in readme, add example outputs

* chore(repo): add examples to TOC

* chore(repo): remove full page and mobile helper methods

* chore(repo): add examples for full page and mobile

* feat(repo): implement extraction methods for side formats

* feat(repo): update readme with extraction methods and how to use IDictionary overload

feat(repo): add trivial change to test actions

fix(repo): add missing awaits to tests

* fix(repo): ensure nullable fields dont show up in render response

* feat(repo): ensure user agent is added to each request

* feat(repo): add gh test running workflow

chore(repo): remove tmp comment line

* feat(repo): add in a new project showing example and webhooks

* fix(repo): ensure null values dont show in responses

refactor(readme): update readme to reflect new example webhook project

chore(repo): remove format arg from render links as can just use options.Format

fix(repo): fix failing test

* feat(repo): add deployment workflow less deploy step

* feat(repo): add in push to nuget

chore(repo): change on push syntax to match other repos

* refactor(repo): comment out deploy step and test release step in deploy_to_nuget action

* refactor(repo): add release please configs

* refactor(repo): use latest ubuntu to stop warning

* refactor(repo): update release please action to latest

* refactor(repo): remove release type

* chore(repo): trivial change in readme to trigger release-please

* refactor(repo): change * for . in root def for release please config

* chore(repo): trivial change in readme to trigger release-please

* refactor(repo): add annotations for release please auto-versioning

* refactor(repo): add back in deploy step less nuget push

* refactor(repo): run deploy job on push to release-please-test, not on pr close

* chore(release-please-test): release 1.1.0

* refactor(repo): trivial change to readme to test release

* chore(release-please-test): release 1.2.0

* refactor(repo): ensure release step outputs to deploy step in nuget action

* chore(release-please-test): release 1.3.0

* refactor(repo): ensure release step outputs to deploy step in nuget action

* chore(release-please-test): release 1.4.0

* refactor(repo): trivial change to readme to test release

* chore(release-please-test): release 1.5.0

* refactor(repo): update versions back to 1.0.2

* chore(release-please-test): release 1.1.0 (#24)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore(release-please-test): release 1.2.0 (#25)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore(release-please-test): release 1.3.0 (#26)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore(repo): ensure deploy action only runs when merging to master, add in nuget pub step

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
AJCJ1 and github-actions[bot] authored Jan 22, 2025
1 parent e72adfd commit 1d641be
Show file tree
Hide file tree
Showing 78 changed files with 11,912 additions and 531 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/deploy_to_nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy to NuGet

on:
push:
branches:
- master

permissions:
contents: write
pull-requests: write

jobs:
release:
name: Release Using Release Please
runs-on: ubuntu-24.04
strategy:
matrix:
dotnet-version: [6.0]
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v4

# Set up .NET
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
cache: true
cache-dependency-path: "./UrlboxSDK"

# Restore dependencies
- name: Restore dependencies
run: dotnet restore ./UrlboxSDK

# Run tests
- name: Run tests
run: dotnet test

# https://github.com/googleapis/release-please/blob/72b0ab360c3d6635397e8b02f4d3f9f53932e23c/docs/customizing.md
- name: Create Release
id: create_release
uses: googleapis/release-please-action@v4
with:
target-branch: release-please-test
outputs:
release_created: ${{ steps.create_release.outputs.release_created }}

deploy:
needs: release
if: ${{ needs.release.outputs.release_created }}
name: Push to NuGet registry
runs-on: ubuntu-24.04
strategy:
matrix:
dotnet-version: [6.0]
steps:
# Build the project
- name: Build the project
run: dotnet build ./UrlboxSDK --configuration Release --no-restore

# Pack the NuGet package somewhere unique
- name: Pack NuGet package
run: dotnet pack --configuration Release --no-build --output ./package

# Push the NuGet package to NuGet.org
- name: Publish to NuGet
run: dotnet nuget push "./package/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

28 changes: 28 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: run tests

on:
push:

jobs:
test:
permissions:
contents: read
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [6.0]
steps:
- name: Checkout urlbox-dotnet
uses: actions/checkout@v4

- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
cache: true
cache-dependency-path: "./UrlboxSDK"

- name: Install dependencies
run: dotnet restore

- name: Run tests
run: dotnet test
4 changes: 4 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
".": "1.3.0"
}

673 changes: 673 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../UrlboxSDK/UrlboxSDK.csproj" />
</ItemGroup>

</Project>
95 changes: 95 additions & 0 deletions Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using UrlboxSDK.DI.Extension;
using UrlboxSDK;
using UrlboxSDK.Response.Resource;
using UrlboxSDK.Exception;
using UrlboxSDK.Options.Resource;
using UrlboxSDK.Webhook.Resource;
using System.Text.Json;

var builder = WebApplication.CreateBuilder(args);

// Add Urlbox to the service container
builder.Services.AddUrlbox(options =>
{
// TODO Replace these with your keys from the dashboard: https://urlbox.com/dashboard/api
options.Key = "YOUR PUBLISHABLE API KEY HERE";
options.Secret = "YOUR SECRET KEY HERE";
// TODO optionally add this in to test out webhooks
options.WebhookSecret = "YOUR WEBHOOK SECRET KEY HERE";
// if you need to use one of our specific subdomains
// options.BaseUrl = "https://api-eu.urlbox.com";
});

var app = builder.Build();

// Urlbox gets injected by the service container
app.MapGet("/", async (HttpContext context, IUrlbox urlbox) =>
{
try
{
// Use the static .Options() method to choose your options
UrlboxOptions options = Urlbox.Options(url: "https://urlbox.com/docs")
// Play around with various options here
.Format(Format.Jpeg)
// Want to test out webhooks? see the POST endpoint below
// .WebhookUrl("https://YOUR NGROK FORWARDING ENDPOINT/webhook/urlbox")
.Build();

// Runs an async render, polls for success
// AsyncUrlboxResponse takeScreenshotResponse = await urlbox.TakeScreenshot(options);

// Runs an async render, gives status response
AsyncUrlboxResponse renderAsyncResponse = await urlbox.RenderAsync(options);

// Runs an sync render, waits for success before returning
// SyncUrlboxResponse renderSyncResponse = await urlbox.Render(options);

return Results.Json(new
{
message = "Screenshot generated!",
// ResponseFromTakeScreenshot = takeScreenshotResponse,
ResponseFromRenderAsync = renderAsyncResponse,
// ResponseFromRenderSync = renderSyncResponse
});
}
// Want to test how the exception looks? try this as the url in options: "https://notresolvableurlbox.com"
catch (UrlboxException ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.RequestId);
return Results.Json(new { message = "Failed to generate screenshot, urlbox exception", error = ex.Message, reqId = ex.RequestId });
}
});

/*
Webhook Example:
1. Make sure you've set your webhook secret in your Urlbox instantiation (line 16)
2. Get ngrok (make an account and install on your computer) https://ngrok.com/
3. Run this project with `dotnet run`.
4. Using ngrok expose the localhost port the .net server runs on EG for 5096 `ngrok http 5096`
4. Take the ngrok forwarding address shown in CLI EG https://2c85-80-41-190-113.ngrok-free.app and
replace the above .WebhookUrl() arg with it in your options, including the /webhook/urlbox endpoint.
5. Make a request to the GET endpoint "/" above with one of the render methods, and Urlbox will make a POST to your ngrok endpoint /webhook/urlbox.
EG: curl -i http://localhost:5096
*/
app.MapPost("/webhook/urlbox", async (HttpContext context, IUrlbox urlbox) =>
{
using StreamReader stream = new StreamReader(context.Request.Body);

if (!context.Request.Headers.TryGetValue("x-urlbox-signature", out var headerValue))
{
throw new Exception("Header 'x-urlbox-signature' not found.");
}

UrlboxWebhookResponse verifiedResponse = urlbox.VerifyWebhookSignature(headerValue.ToString(), await stream.ReadToEndAsync());

string json = JsonSerializer.Serialize(verifiedResponse, new JsonSerializerOptions
{
WriteIndented = true
});

Console.WriteLine(json);
});

app.Run();
38 changes: 38 additions & 0 deletions Example/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52163",
"sslPort": 44353
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5096",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7078;http://localhost:5096",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions Example/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions Example/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Binary file added Examples/highlight.pdf
Binary file not shown.
35 changes: 35 additions & 0 deletions Examples/html.html

Large diffs are not rendered by default.

Binary file added Examples/javascript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Examples/mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Examples/mp4.mp4
Binary file not shown.
Binary file added Examples/pdf.pdf
Binary file not shown.
Binary file added Images/gh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/projectKeys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/urlbox-graphic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/urlbox-png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1d641be

Please sign in to comment.