Skip to content

Commit

Permalink
Merge pull request #3517 from magda-io/issue/3516
Browse files Browse the repository at this point in the history
#3516 Fixed released @magda NPM package esbuild commonjs bundle issue (also #3514)
  • Loading branch information
t83714 authored Apr 18, 2024
2 parents fe23739 + c8ba61f commit 2428760
Show file tree
Hide file tree
Showing 36 changed files with 251 additions and 85 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# CHANGELOG

## v3.0.1
## v3.0.2

- #3513 Fixed Indexer reindex trigger job doesn't start
- #3516 Fixed released @magda NPM package esbuild commonjs bundle issue
- Added the API document for the sitemap endpoint
- Make getStorageApiResourceAccessUrl available via @magda/typescript-common & @magda/utils
- Fixed: update node engines requirements to all SDKs to 18.19.0

## v3.0.1

Expand Down
6 changes: 3 additions & 3 deletions deploy/helm/magda/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
version: 2.0.0
- name: magda-minion-broken-link
repository: oci://ghcr.io/magda-io/charts
version: 2.0.0
version: 3.0.0
- name: magda-minion-format
repository: oci://ghcr.io/magda-io/charts
version: 2.0.1
Expand All @@ -29,5 +29,5 @@ dependencies:
- name: magda-function-esri-url-processor
repository: oci://ghcr.io/magda-io/charts
version: 2.0.0
digest: sha256:637bc2e418fd3e29d9162b263e9afa26e0355e3547ab7aaecd9e0a865b952d1b
generated: "2024-03-26T03:55:48.726443758Z"
digest: sha256:68193166fa130ec0771de1897538b8f7e255f450716f2060616c7166d8bd16fb
generated: "2024-04-18T00:00:16.359432+10:00"
2 changes: 1 addition & 1 deletion deploy/helm/magda/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies:

- name: magda-minion-broken-link
alias: minion-broken-link
version: "2.0.0"
version: "3.0.0"
repository: "oci://ghcr.io/magda-io/charts"
tags:
- minions
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/magda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A complete solution for managing, publishing and discovering government data, pr
| oci://ghcr.io/magda-io/charts | ckan-connector-functions(magda-ckan-connector) | 2.0.0 |
| oci://ghcr.io/magda-io/charts | magda-function-esri-url-processor | 2.0.0 |
| oci://ghcr.io/magda-io/charts | magda-function-history-report | 2.0.0 |
| oci://ghcr.io/magda-io/charts | minion-broken-link(magda-minion-broken-link) | 2.0.0 |
| oci://ghcr.io/magda-io/charts | minion-broken-link(magda-minion-broken-link) | 3.0.0 |
| oci://ghcr.io/magda-io/charts | magda-minion-ckan-exporter | 2.0.0 |
| oci://ghcr.io/magda-io/charts | minion-format(magda-minion-format) | 2.0.1 |
| oci://ghcr.io/magda-io/charts | minion-linked-data-rating(magda-minion-linked-data-rating) | 2.0.0 |
Expand Down
2 changes: 1 addition & 1 deletion magda-builder-nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:18-alpine3.18

RUN npm install -g [email protected]
RUN npm install -g [email protected] && npm install -g [email protected]

# Install haveged and run it so that we don't get lockups due to a lack of entropy
RUN apk --no-cache add haveged
Expand Down
2 changes: 1 addition & 1 deletion magda-content-schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"./*.json": "./*.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"description": "Common schemas for use with the content api.",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion magda-migrator-registry-aspects/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14-alpine
FROM node:18-alpine

RUN mkdir -p /usr/src/app
COPY . /usr/src/app
Expand Down
2 changes: 1 addition & 1 deletion magda-registry-aspects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"./*.json": "./*.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"scripts": {
"build": "echo \"ok\"",
Expand Down
40 changes: 40 additions & 0 deletions magda-typescript-common/src/getStorageApiResourceAccessUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import urijs from "urijs";

/**
* Get the access url of a storage api resource from [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000)
* If the input url is not a pseudo storage api resource URL, return the input url directly
*
* @export
* @param {string} resourceUrl pseudo storage api resource URL or ordinary HTTP access url
* @param {string} storageApiBaseUrl storage api base url
* @param {string} datasetsBucket datasets storage bucket name
* @return {*}
*/
export default function getStorageApiResourceAccessUrl(
resourceUrl: string,
storageApiBaseUrl: string,
datasetsBucket: string
) {
if (!resourceUrl) {
return resourceUrl;
}
const uri = urijs(resourceUrl);
if (uri.protocol() === "magda" && uri.hostname() === "storage-api") {
// --- convert [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000) to http access url
const [datasetId, distributionId, fileName] = uri.segmentCoded();
const accessUri = urijs(storageApiBaseUrl);
const segments = [
...accessUri.segmentCoded(),
datasetsBucket,
datasetId,
distributionId,
fileName
];
return accessUri.segmentCoded(segments).toString();
} else {
// --- return legacy url directly
// --- legacy url is a HTTP access url generated when create the resource
// --- can be used to access storage api directly
return resourceUrl;
}
}
29 changes: 6 additions & 23 deletions magda-web-client/src/helpers/getStorageApiResourceAccessUrl.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
import { config, DATASETS_BUCKET } from "../config";
import urijs from "urijs";
import { default as getStorageApiResourceAccessUrlOriginal } from "@magda/typescript-common/dist/getStorageApiResourceAccessUrl.js";

export default function getStorageApiResourceAccessUrl(resourceUrl: string) {
if (!resourceUrl) {
return resourceUrl;
}
const uri = urijs(resourceUrl);
if (uri.protocol() === "magda" && uri.hostname() === "storage-api") {
// --- convert [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000) to http access url
const [datasetId, distributionId, fileName] = uri.segmentCoded();
const accessUri = urijs(config.storageApiBaseUrl);
const segments = [
...accessUri.segmentCoded(),
DATASETS_BUCKET,
datasetId,
distributionId,
fileName
];
return accessUri.segmentCoded(segments).toString();
} else {
// --- return legacy url directly
// --- legacy url is a HTTP access url generated when create the resource
// --- can be used to access storage api directly
return resourceUrl;
}
return getStorageApiResourceAccessUrlOriginal(
resourceUrl,
config.storageApiBaseUrl,
DATASETS_BUCKET
);
}
56 changes: 56 additions & 0 deletions magda-web-server/src/buildSitemapRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ export default function buildSitemapRouter({
return pageTokens;
}

/**
* @apiGroup Sitemaps
* @api {get} /sitemap.xml Sitemaps entrypoint
* @apiDescription A [sitemaps protocol interface](https://www.sitemaps.org/protocol.html) that is prepared for external search engines to harvest datasets from Magda.
* The sitemap index is produced based on the live data in the metadata store database. By default, the sitemap index will be cached for 86400 seconds (24 hours).
* This setting can be adjusted via `sitemapCacheSeconds` of [web-server](https://github.com/magda-io/magda/tree/main/deploy/helm/internal-charts/web-server) module helm chart.
* Please note:
* 1> due to the cache and the search engine indexing delay, the total number of datasets in the sitemap index may be different from the dataset total count from the search API.
* 2> This sitemaps endpoint is recorded on the default /robots.txt endpoint that follows the [Robots Exclusion Standard](https://en.wikipedia.org/wiki/Robots_exclusion_standard#About_the_standard).
* 3> Only public datasets are included in the sitemaps. In fact, the sitemaps index is generated with anonymous user access.
*
* @apiSuccessExample {xml} 200
* <?xml version="1.0" encoding="UTF-8"?>
* <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
* <sitemap>
* <loc>https://example.com/sitemap/main.xml</loc>
* </sitemap>
* <sitemap>
* <loc>https://example.com/sitemap/dataset/afterToken/0.xml</loc>
* </sitemap>
* </sitemapindex>
*
*/
app.get("/sitemap.xml", async (req, res) => {
try {
const smis = new SitemapIndexStream({ level: ErrorLevel.WARN });
Expand Down Expand Up @@ -91,6 +114,21 @@ export default function buildSitemapRouter({
}
});

/**
* @apiGroup Sitemaps
* @api {get} /sitemap/main.xml Sitemaps index entry for the home page
* @apiDescription Sitemaps index entry for the home page
*
* @apiSuccessExample {xml} 200
* <?xml version="1.0" encoding="UTF-8"?>
* <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
* <url>
* <loc>https://example.com/</loc>
* <changefreq>daily</changefreq>
* </url>
* </urlset>
*
*/
app.get("/sitemap/main.xml", async (req, res) => {
try {
// For now we just put the homepage in here, seeing as everything except the datasets should be reachable
Expand All @@ -114,6 +152,24 @@ export default function buildSitemapRouter({
}
});

/**
* @apiGroup Sitemaps
* @api {get} /sitemap/dataset/afterToken/{pageToken}.xml Sitemaps index entry for datasets
* @apiDescription The sitemaps entrypoint `/sitemap.xml` contains links to all index entries for datasets (paginated by the `pageToken` parameter).
* Each index entry contains a list of dataset page links.
* You can either visit the dataset page directly (A text based SEO friendly view will be shown if the `User-Agent` request header is [recognised as search engine bot](https://github.com/magda-io/magda/blob/main/magda-web-server/src/shouldRenderCrawlerView.ts#L20)).
* Or extract the dataset ID from the dataset page link and access the detailed metadata in JSON format via the [registry get a record by ID API](#api-Registry_Record_Service-GetV0RegistryRecordsId).
*
* @apiSuccessExample {xml} 200
* <?xml version="1.0" encoding="UTF-8"?>
* <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
* <url>
* <loc>https://example.com/dataset/ds-a3d075b9-70d7-40b3-a693-70db2a415765</loc>
* <changefreq>weekly</changefreq>
* </url>
* </urlset>
*
*/
app.get("/sitemap/dataset/afterToken/:afterToken.xml", async (req, res) => {
try {
const sms = new SitemapStream({
Expand Down
2 changes: 1 addition & 1 deletion packages/acs-cmd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"./package.json": "./package.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"scripts": {
"acs-cmd": "./bin/acs-cmd.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/arbitraries/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import * as esbuild from "esbuild";
import { require } from "@magda/esm-utils";
const pkg = require("./package.json");

await esbuild.build({
entryPoints: ["./src/index.ts"],
bundle: true,
platform: "node",
target: ["es2022"],
outdir: "dist",
inject: ["../cjs-shim.js"],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
],
format: "esm"
});
2 changes: 1 addition & 1 deletion packages/arbitraries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"./package.json": "./package.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"scripts": {
"prebuild": "rimraf dist tsconfig.tsbuildinfo",
Expand Down
1 change: 1 addition & 0 deletions packages/auth-api-client/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ await esbuild.build({
platform: "node",
target: ["es2022"],
outdir: "dist",
inject: ["../cjs-shim.js"],
format: "esm"
});
2 changes: 1 addition & 1 deletion packages/auth-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"./package.json": "./package.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"scripts": {
"prebuild": "rimraf dist tsconfig.tsbuildinfo",
Expand Down
7 changes: 7 additions & 0 deletions packages/authentication-plugin-sdk/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as esbuild from "esbuild";
import { require } from "@magda/esm-utils";
const pkg = require("./package.json");

await esbuild.build({
entryPoints: ["./src/index.ts"],
Expand All @@ -7,5 +9,10 @@ await esbuild.build({
target: ["es2022"],
outdir: "dist",
format: "esm",
inject: ["../cjs-shim.js"],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
],
external: ["pg"]
});
2 changes: 1 addition & 1 deletion packages/authentication-plugin-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"./package.json": "./package.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"scripts": {
"prebuild": "rimraf dist tsconfig.tsbuildinfo",
Expand Down
7 changes: 7 additions & 0 deletions packages/cjs-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createRequire } from "node:module";
import path from "node:path";
import url from "node:url";

globalThis.require = createRequire(import.meta.url);
globalThis.__filename = url.fileURLToPath(import.meta.url);
globalThis.__dirname = path.dirname(__filename);
1 change: 1 addition & 0 deletions packages/connector-sdk/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async function build(web = false) {
platform: platform,
target: [target],
outdir: "dist",
inject: ["../cjs-shim.js"],
// should always be esm
format: "esm"
});
Expand Down
2 changes: 1 addition & 1 deletion packages/connector-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"./package.json": "./package.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"scripts": {
"prebuild": "rimraf dist tsconfig.tsbuildinfo",
Expand Down
7 changes: 7 additions & 0 deletions packages/connector-test-utils/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import * as esbuild from "esbuild";
import { require } from "@magda/esm-utils";
const pkg = require("./package.json");

await esbuild.build({
entryPoints: ["./src/index.ts"],
bundle: true,
platform: "node",
target: ["es2022"],
outdir: "dist",
inject: ["../cjs-shim.js"],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
],
format: "esm"
});
1 change: 1 addition & 0 deletions packages/create-secrets/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ await esbuild.build({
bundle: true,
platform: "node",
target: ["es2022"],
inject: ["../cjs-shim.js"],
outdir: "bin",
format: "esm"
});
2 changes: 1 addition & 1 deletion packages/create-secrets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"./package.json": "./package.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"bin": {
"create-secrets": "./bin/index.js"
Expand Down
7 changes: 6 additions & 1 deletion packages/docker-utils/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as esbuild from "esbuild";
import { requireResolve } from "@magda/esm-utils";
import { requireResolve, require } from "@magda/esm-utils";
const pkg = require("./package.json");

const entries = {
"create-docker-context-for-node-component": requireResolve(
Expand All @@ -13,6 +14,10 @@ await esbuild.build({
bundle: true,
platform: "node",
target: ["es2022"],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
],
outdir: "dist",
format: "esm"
});
2 changes: 1 addition & 1 deletion packages/docker-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"./package.json": "./package.json"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.19.0"
},
"bin": {
"create-docker-context-for-node-component": "./dist/create-docker-context-for-node-component.js",
Expand Down
Loading

0 comments on commit 2428760

Please sign in to comment.