airport-utils 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +3 -0
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/pr-maintain.yml +118 -0
- package/.github/workflows/publish.yml +0 -4
- package/.github/workflows/update-mapping.yml +48 -12
- package/.releaserc.json +1 -2
- package/dist/cjs/converter.js +78 -0
- package/dist/cjs/errors.js +24 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/info.js +16 -0
- package/dist/cjs/mapping/geo.js +11995 -0
- package/dist/cjs/mapping/timezones.js +12009 -0
- package/dist/esm/converter.js +75 -0
- package/dist/{src → esm}/errors.js +5 -3
- package/dist/esm/index.js +3 -0
- package/dist/esm/info.js +14 -0
- package/dist/{src → esm}/mapping/geo.js +35 -29
- package/dist/{src → esm}/mapping/timezones.js +58 -52
- package/dist/types/converter.d.ts +10 -0
- package/jest.config.js +5 -1
- package/package.json +27 -8
- package/rollup.config.js +53 -0
- package/src/converter.ts +49 -25
- package/src/mapping/geo.ts +30 -26
- package/src/mapping/timezones.ts +55 -51
- package/tests/built.test.ts +52 -0
- package/tests/converter.test.ts +58 -14
- package/tsconfig.json +5 -2
- package/dist/scripts/generateMapping.d.ts +0 -2
- package/dist/scripts/generateMapping.js +0 -78
- package/dist/src/converter.d.ts +0 -10
- package/dist/src/converter.js +0 -50
- package/dist/src/index.js +0 -3
- package/dist/src/info.js +0 -11
- package/dist/tests/converter.test.d.ts +0 -1
- package/dist/tests/converter.test.js +0 -56
- package/dist/tests/info.test.d.ts +0 -1
- package/dist/tests/info.test.js +0 -34
- /package/dist/{src → types}/errors.d.ts +0 -0
- /package/dist/{src → types}/index.d.ts +0 -0
- /package/dist/{src → types}/info.d.ts +0 -0
- /package/dist/{src → types}/mapping/geo.d.ts +0 -0
- /package/dist/{src → types}/mapping/timezones.d.ts +0 -0
package/.github/dependabot.yml
CHANGED
package/.github/workflows/ci.yml
CHANGED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
name: Maintain Bot PRs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request_target:
|
|
5
|
+
types: [opened, reopened, synchronize, ready_for_review]
|
|
6
|
+
schedule:
|
|
7
|
+
- cron: "*/30 * * * *"
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: write
|
|
12
|
+
pull-requests: write
|
|
13
|
+
|
|
14
|
+
concurrency:
|
|
15
|
+
group: bot-pr-maintenance
|
|
16
|
+
cancel-in-progress: false
|
|
17
|
+
|
|
18
|
+
env:
|
|
19
|
+
BOT_TOKEN: ${{ secrets.BOT_MAINTAINER_TOKEN != '' && secrets.BOT_MAINTAINER_TOKEN || secrets.GITHUB_TOKEN }}
|
|
20
|
+
APPROVED_BOTS: '["dependabot[bot]","github-actions[bot]"]'
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
maintain:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- name: Determine PR number (if event is a PR)
|
|
27
|
+
id: pr
|
|
28
|
+
run: |
|
|
29
|
+
if [ "${{ github.event.pull_request.number }}" != "" ]; then
|
|
30
|
+
echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
- name: Update the PR branch to latest base
|
|
34
|
+
if: ${{ steps.pr.outputs.number != '' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
|
|
35
|
+
uses: actions/github-script@v7
|
|
36
|
+
with:
|
|
37
|
+
github-token: ${{ env.BOT_TOKEN }}
|
|
38
|
+
script: |
|
|
39
|
+
const owner = context.repo.owner;
|
|
40
|
+
const repo = context.repo.repo;
|
|
41
|
+
const APPROVED_BOTS = JSON.parse(process.env.APPROVED_BOTS);
|
|
42
|
+
|
|
43
|
+
async function updateOne(number) {
|
|
44
|
+
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: number });
|
|
45
|
+
if (!APPROVED_BOTS.includes(pr.user.login) || pr.state !== 'open') return;
|
|
46
|
+
try {
|
|
47
|
+
await github.rest.pulls.updateBranch({ owner, repo, pull_number: number });
|
|
48
|
+
core.info(`Updated branch for PR #${number}`);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
core.info(`UpdateBranch skipped for PR #${number}: ${e.message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (context.eventName === 'pull_request_target' && context.payload.pull_request) {
|
|
55
|
+
await updateOne(context.payload.pull_request.number);
|
|
56
|
+
} else {
|
|
57
|
+
const all = await github.paginate(github.rest.pulls.list, { owner, repo, state: 'open', per_page: 100 });
|
|
58
|
+
for (const pr of all.filter(p => APPROVED_BOTS.includes(p.user.login))) {
|
|
59
|
+
await updateOne(pr.number);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- name: Auto-approve bot PR(s) (skip if reviewer == author or already approved)
|
|
64
|
+
if: ${{ steps.pr.outputs.number != '' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
|
|
65
|
+
uses: actions/github-script@v7
|
|
66
|
+
with:
|
|
67
|
+
github-token: ${{ env.BOT_TOKEN }}
|
|
68
|
+
script: |
|
|
69
|
+
const owner = context.repo.owner;
|
|
70
|
+
const repo = context.repo.repo;
|
|
71
|
+
const APPROVED_BOTS = JSON.parse(process.env.APPROVED_BOTS);
|
|
72
|
+
const myLogin = process.env.GITHUB_ACTOR.toLowerCase();
|
|
73
|
+
|
|
74
|
+
async function approveOne(number) {
|
|
75
|
+
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: number });
|
|
76
|
+
const author = pr.user.login.toLowerCase();
|
|
77
|
+
if (!APPROVED_BOTS.includes(pr.user.login) || pr.state !== 'open') return;
|
|
78
|
+
|
|
79
|
+
// Skip if reviewer == author
|
|
80
|
+
if (author === myLogin) {
|
|
81
|
+
core.info(`Skipping PR #${number} - reviewer (${myLogin}) is the author.`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Skip if already approved by this reviewer
|
|
86
|
+
const { data: reviews } = await github.rest.pulls.listReviews({ owner, repo, pull_number: number });
|
|
87
|
+
const hasApproval = reviews.some(r =>
|
|
88
|
+
r.user?.login?.toLowerCase() === myLogin &&
|
|
89
|
+
r.state?.toLowerCase() === 'approved'
|
|
90
|
+
);
|
|
91
|
+
if (hasApproval) {
|
|
92
|
+
core.info(`Skipping PR #${number} - already approved by ${myLogin}.`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await github.rest.pulls.createReview({
|
|
97
|
+
owner, repo, pull_number: number,
|
|
98
|
+
event: 'APPROVE'
|
|
99
|
+
});
|
|
100
|
+
core.info(`Approved PR #${number} from ${pr.user.login}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (context.eventName === 'pull_request_target' && context.payload.pull_request) {
|
|
104
|
+
await approveOne(context.payload.pull_request.number);
|
|
105
|
+
} else {
|
|
106
|
+
const all = await github.paginate(github.rest.pulls.list, { owner, repo, state: 'open', per_page: 100 });
|
|
107
|
+
for (const pr of all.filter(p => APPROVED_BOTS.includes(p.user.login))) {
|
|
108
|
+
await approveOne(pr.number);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
- name: Enable auto-merge (squash)
|
|
113
|
+
if: ${{ steps.pr.outputs.number != '' }}
|
|
114
|
+
uses: peter-evans/enable-pull-request-automerge@v3
|
|
115
|
+
with:
|
|
116
|
+
token: ${{ env.BOT_TOKEN }}
|
|
117
|
+
pull-request-number: ${{ steps.pr.outputs.number }}
|
|
118
|
+
merge-method: squash
|
|
@@ -22,12 +22,8 @@ jobs:
|
|
|
22
22
|
run: |
|
|
23
23
|
# Public npm
|
|
24
24
|
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
|
|
25
|
-
# GitHub
|
|
26
|
-
echo "@elipeF:registry=https://npm.pkg.github.com" >> ~/.npmrc
|
|
27
|
-
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc
|
|
28
25
|
env:
|
|
29
26
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
30
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
31
27
|
|
|
32
28
|
- name: Install dependencies
|
|
33
29
|
run: npm ci
|
|
@@ -5,32 +5,68 @@ on:
|
|
|
5
5
|
- cron: '0 0 * * *' # every day at 00:00 UTC
|
|
6
6
|
workflow_dispatch:
|
|
7
7
|
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
pull-requests: write
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: update-mapping
|
|
14
|
+
cancel-in-progress: false
|
|
15
|
+
|
|
16
|
+
env:
|
|
17
|
+
# Single token for commits, PR creation, and auto-merge
|
|
18
|
+
BOT_TOKEN: ${{ secrets.BOT_MAINTAINER_TOKEN != '' && secrets.BOT_MAINTAINER_TOKEN || secrets.GITHUB_TOKEN }}
|
|
19
|
+
|
|
8
20
|
jobs:
|
|
9
21
|
refresh-mapping:
|
|
10
22
|
runs-on: ubuntu-latest
|
|
11
23
|
steps:
|
|
12
24
|
- name: Checkout repo
|
|
13
|
-
uses: actions/checkout@
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
|
+
with:
|
|
27
|
+
fetch-depth: 0
|
|
28
|
+
token: ${{ env.BOT_TOKEN }}
|
|
29
|
+
|
|
14
30
|
- name: Setup Node.js
|
|
15
|
-
uses: actions/setup-node@
|
|
31
|
+
uses: actions/setup-node@v4
|
|
16
32
|
with:
|
|
17
33
|
node-version: '20'
|
|
34
|
+
|
|
18
35
|
- name: Install dependencies
|
|
19
36
|
run: npm ci
|
|
37
|
+
|
|
20
38
|
- name: Generate updated mapping
|
|
21
39
|
run: npm run update:mapping
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- name: Test
|
|
25
|
-
run: npm test
|
|
26
|
-
- name: Commit & push if changed
|
|
40
|
+
|
|
41
|
+
- name: Commit changes (no push)
|
|
27
42
|
run: |
|
|
28
43
|
git config user.name "github-actions[bot]"
|
|
29
44
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
30
45
|
git add src/mapping/*
|
|
31
|
-
if
|
|
32
|
-
git commit -m "chore: daily update of mapping files"
|
|
33
|
-
git push
|
|
34
|
-
else
|
|
46
|
+
if git diff --cached --quiet; then
|
|
35
47
|
echo "No changes in mapping files"
|
|
36
|
-
|
|
48
|
+
echo "no_changes=true" >> $GITHUB_ENV
|
|
49
|
+
else
|
|
50
|
+
git commit -m "chore(mapping): daily update of mapping files"
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
- name: Create or update PR
|
|
54
|
+
if: env.no_changes != 'true'
|
|
55
|
+
id: cpr
|
|
56
|
+
uses: peter-evans/create-pull-request@v6
|
|
57
|
+
with:
|
|
58
|
+
token: ${{ env.BOT_TOKEN }}
|
|
59
|
+
commit-message: "chore(mapping): daily update of mapping files"
|
|
60
|
+
branch: chore/mapping-auto
|
|
61
|
+
title: "chore(mapping): daily update of mapping files"
|
|
62
|
+
body: "Automated update of mapping files."
|
|
63
|
+
labels: dependencies
|
|
64
|
+
delete-branch: true
|
|
65
|
+
|
|
66
|
+
- name: Enable auto-merge (squash)
|
|
67
|
+
if: steps.cpr.outputs.pull-request-number
|
|
68
|
+
uses: peter-evans/enable-pull-request-automerge@v3
|
|
69
|
+
with:
|
|
70
|
+
token: ${{ env.BOT_TOKEN }}
|
|
71
|
+
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
|
|
72
|
+
merge-method: squash
|
package/.releaserc.json
CHANGED
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
{ "type": "style", "release": "patch" },
|
|
13
13
|
{ "type": "refactor", "release": "patch" },
|
|
14
14
|
{ "type": "perf", "release": "patch" },
|
|
15
|
-
{ "type": "test", "release": "patch" }
|
|
16
|
-
{ "type": "merge", "release": "patch" }
|
|
15
|
+
{ "type": "test", "release": "patch" }
|
|
17
16
|
],
|
|
18
17
|
"parserOpts": {
|
|
19
18
|
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dateFns = require('date-fns');
|
|
4
|
+
var tz = require('@date-fns/tz');
|
|
5
|
+
var timezones = require('./mapping/timezones.js');
|
|
6
|
+
var errors = require('./errors.js');
|
|
7
|
+
|
|
8
|
+
const ISO_LOCAL_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/;
|
|
9
|
+
function parseLocalIso(localIso) {
|
|
10
|
+
const m = ISO_LOCAL_RE.exec(localIso);
|
|
11
|
+
if (!m)
|
|
12
|
+
throw new errors.InvalidTimestampError(localIso);
|
|
13
|
+
const [, Y, Mo, D, h, mi, s] = m;
|
|
14
|
+
return [
|
|
15
|
+
Number(Y),
|
|
16
|
+
Number(Mo) - 1,
|
|
17
|
+
Number(D),
|
|
18
|
+
Number(h),
|
|
19
|
+
Number(mi),
|
|
20
|
+
s ? Number(s) : 0
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Convert a local ISO‐8601 string at an airport (IATA) into a UTC ISO string.
|
|
25
|
+
* Always emits "YYYY-MM-DDTHH:mm:ssZ" (no milliseconds).
|
|
26
|
+
*/
|
|
27
|
+
function convertToUTC(localIso, iata) {
|
|
28
|
+
const tz$1 = timezones.timezones[iata];
|
|
29
|
+
if (!tz$1)
|
|
30
|
+
throw new errors.UnknownAirportError(iata);
|
|
31
|
+
// Quick semantic check
|
|
32
|
+
const base = dateFns.parseISO(localIso);
|
|
33
|
+
if (isNaN(base.getTime()))
|
|
34
|
+
throw new errors.InvalidTimestampError(localIso);
|
|
35
|
+
const [year, month, day, hour, minute, second] = parseLocalIso(localIso);
|
|
36
|
+
let zoned;
|
|
37
|
+
try {
|
|
38
|
+
zoned = tz.TZDate.tz(tz$1, year, month, day, hour, minute, second);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw new errors.InvalidTimestampError(localIso);
|
|
42
|
+
}
|
|
43
|
+
if (isNaN(zoned.getTime()))
|
|
44
|
+
throw new errors.InvalidTimestampError(localIso);
|
|
45
|
+
// Strip ".000" from the ISO string
|
|
46
|
+
return new Date(zoned.getTime()).toISOString().replace('.000Z', 'Z');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Convert a local ISO‐8601 string in any IANA timezone into a UTC ISO string.
|
|
50
|
+
* Always emits "YYYY-MM-DDTHH:mm:ssZ" (no milliseconds).
|
|
51
|
+
*/
|
|
52
|
+
function convertLocalToUTCByZone(localIso, timeZone) {
|
|
53
|
+
// Validate timezone
|
|
54
|
+
try {
|
|
55
|
+
new Intl.DateTimeFormat('en-US', { timeZone }).format();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
throw new errors.UnknownTimezoneError(timeZone);
|
|
59
|
+
}
|
|
60
|
+
// Quick semantic check
|
|
61
|
+
const base = dateFns.parseISO(localIso);
|
|
62
|
+
if (isNaN(base.getTime()))
|
|
63
|
+
throw new errors.InvalidTimestampError(localIso);
|
|
64
|
+
const [year, month, day, hour, minute, second] = parseLocalIso(localIso);
|
|
65
|
+
let zoned;
|
|
66
|
+
try {
|
|
67
|
+
zoned = tz.TZDate.tz(timeZone, year, month, day, hour, minute, second);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new errors.UnknownTimezoneError(timeZone);
|
|
71
|
+
}
|
|
72
|
+
if (isNaN(zoned.getTime()))
|
|
73
|
+
throw new errors.InvalidTimestampError(localIso);
|
|
74
|
+
return new Date(zoned.getTime()).toISOString().replace('.000Z', 'Z');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.convertLocalToUTCByZone = convertLocalToUTCByZone;
|
|
78
|
+
exports.convertToUTC = convertToUTC;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class UnknownAirportError extends Error {
|
|
4
|
+
constructor(iata) {
|
|
5
|
+
super(`Unknown airport IATA code: ${iata}`);
|
|
6
|
+
this.name = 'UnknownAirportError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class InvalidTimestampError extends Error {
|
|
10
|
+
constructor(ts) {
|
|
11
|
+
super(`Invalid ISO 8601 timestamp: ${ts}`);
|
|
12
|
+
this.name = 'InvalidTimestampError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class UnknownTimezoneError extends Error {
|
|
16
|
+
constructor(tz) {
|
|
17
|
+
super(`Unknown timezone: ${tz}`);
|
|
18
|
+
this.name = 'UnknownTimezoneError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.InvalidTimestampError = InvalidTimestampError;
|
|
23
|
+
exports.UnknownAirportError = UnknownAirportError;
|
|
24
|
+
exports.UnknownTimezoneError = UnknownTimezoneError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var converter = require('./converter.js');
|
|
4
|
+
var info = require('./info.js');
|
|
5
|
+
var errors = require('./errors.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.convertLocalToUTCByZone = converter.convertLocalToUTCByZone;
|
|
10
|
+
exports.convertToUTC = converter.convertToUTC;
|
|
11
|
+
exports.getAirportInfo = info.getAirportInfo;
|
|
12
|
+
exports.InvalidTimestampError = errors.InvalidTimestampError;
|
|
13
|
+
exports.UnknownAirportError = errors.UnknownAirportError;
|
|
14
|
+
exports.UnknownTimezoneError = errors.UnknownTimezoneError;
|
package/dist/cjs/info.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var timezones = require('./mapping/timezones.js');
|
|
4
|
+
var geo = require('./mapping/geo.js');
|
|
5
|
+
var errors = require('./errors.js');
|
|
6
|
+
|
|
7
|
+
/** @throws UnknownAirportError */
|
|
8
|
+
function getAirportInfo(iata) {
|
|
9
|
+
const tz = timezones.timezones[iata];
|
|
10
|
+
const g = geo.geo[iata];
|
|
11
|
+
if (!tz || !g)
|
|
12
|
+
throw new errors.UnknownAirportError(iata);
|
|
13
|
+
return { timezone: tz, ...g };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.getAirportInfo = getAirportInfo;
|