Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Commit 95b8ed1

Browse files
committed
feat: enable provenance for jsr
1 parent 63037d5 commit 95b8ed1

File tree

6 files changed

+54
-89
lines changed

6 files changed

+54
-89
lines changed

.github/workflows/npm-publish.yml

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: NPM Publish
1+
name: JSR Publish
22

33
on:
44
release:
@@ -16,26 +16,17 @@ jobs:
1616
matrix:
1717
package:
1818
- 'app-server-sdk'
19-
- 'app-server-sdk-cloudflare'
2019
- 'app-server-sdk-express'
21-
- 'app-server-sdk-hono'
20+
2221
steps:
23-
- uses: actions/checkout@v3
24-
- uses: actions/setup-node@v3
25-
with:
26-
node-version: 18
27-
registry-url: 'https://registry.npmjs.org'
28-
- uses: denoland/setup-deno@v1
29-
with:
30-
deno-version: v1.x
31-
- name: Transform to NPM Package
32-
run: |
33-
cd packages/${{ matrix.package }}
34-
deno run -A scripts/build.ts ${{ github.event.release.tag_name }}
35-
- name: Publish to NPM
22+
- uses: actions/checkout@v4
23+
24+
- name: Update version in JSR
25+
working-directory: packages/${{ matrix.package }}
3626
run: |
37-
cd packages/${{ matrix.package }}/npm
38-
npm publish --provenance --access public
39-
env:
40-
NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_TOKEN}}
41-
27+
jq '.version = "${{ github.event.release.tag_name }}"' jsr.json > jsr.json.tmp
28+
mv jsr.json.tmp jsr.json
29+
30+
- name: Publish package
31+
working-directory: packages/${{ matrix.package }}
32+
run: npx jsr publish
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://jsr.io/schema/config-file.v1.json",
3+
"name": "@friendsofshopware/app-server-express",
4+
"version": "0.0.48",
5+
"exports": "./mod.ts"
6+
}

packages/app-server-sdk-express/mod.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1-
import express from "https://deno.land/x/express@v0.0.0/mod.ts";
1+
interface ExpressResponse {
2+
status: (status: number) => void;
3+
header: (key: string, value: string) => void;
4+
send: (body: string) => void;
5+
}
6+
7+
interface ExpressRequest {
8+
protocol: string;
9+
get: (key: string) => string;
10+
originalUrl: string;
11+
headers: {[key: string]: string};
12+
method: string;
13+
rawBody?: string;
14+
setEncoding: (encoding: string) => void;
15+
on: (event: string, callback: Function) => void;
16+
}
217

3-
export async function convertResponse(response: Response, expressResponse: express.Response) {
18+
/**
19+
* Converts a fetch Response to a Express Response
20+
*/
21+
export async function convertResponse(response: Response, expressResponse: ExpressResponse) {
422
expressResponse.status(response.status);
523
response.headers.forEach((val, key) => {
624
expressResponse.header(key, val);
@@ -9,7 +27,10 @@ export async function convertResponse(response: Response, expressResponse: expre
927
expressResponse.send(await response.text());
1028
}
1129

12-
export function convertRequest(expressRequest: express.Request): Request {
30+
/**
31+
* Converts a Express request to a fetch Request
32+
*/
33+
export function convertRequest(expressRequest: ExpressRequest): Request {
1334
const headers = new Headers();
1435

1536
for (const [key, value] of Object.entries(expressRequest.headers)) {
@@ -21,16 +42,18 @@ export function convertRequest(expressRequest: express.Request): Request {
2142
method: expressRequest.method,
2243
};
2344

24-
// @ts-ignore
2545
if (expressRequest.rawBody) {
26-
// @ts-ignore
2746
options.body = expressRequest.rawBody;
2847
}
2948

3049
return new Request(expressRequest.protocol + '://' + expressRequest.get('host') + expressRequest.originalUrl, options);
3150
}
3251

33-
export function rawRequestMiddleware(req: express.Request, res: express.Response, next: express.NextFunction) {
52+
/**
53+
* Middleware to parse the raw body of a request and add it to the request object
54+
* This is required as we can compute only the hash of the raw body and a parsed body might be different
55+
*/
56+
export function rawRequestMiddleware(req: ExpressRequest, res: ExpressResponse, next: Function): void {
3457
const contentType = req.headers['content-type'] || ''
3558
, mime = contentType.split(';')[0];
3659

@@ -46,7 +69,6 @@ export function rawRequestMiddleware(req: express.Request, res: express.Response
4669
});
4770

4871
req.on('end', function() {
49-
// @ts-ignore
5072
req.rawBody = data;
5173
next();
5274
});

packages/app-server-sdk-express/scripts/build.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

packages/app-server-sdk/http-client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,18 @@ export class HttpClientResponse {
185185
}
186186
}
187187

188+
/**
189+
* ApiClientAuthenticationFailed is thrown when the authentication to the shop's API fails
190+
*/
188191
export class ApiClientAuthenticationFailed extends Error {
189192
constructor(shopId: string, public response: HttpClientResponse) {
190193
super(`The api client authentication to shop with id: ${shopId}`);
191194
}
192195
}
193196

197+
/**
198+
* ApiClientRequestFailed is thrown when the request to the shop's API fails
199+
*/
194200
export class ApiClientRequestFailed extends Error {
195201
constructor(shopId: string, public response: HttpClientResponse) {
196202
super(

packages/app-server-sdk/jsr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://jsr.io/schema/config-file.v1.json",
23
"name": "@friendsofshopware/app-server",
34
"version": "0.0.48",
45
"exports": "./mod.ts"

0 commit comments

Comments
 (0)