diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b86388..572c536 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,46 +1,26 @@ name: Release on: + release: + types: + - released push: tags: - - 'v*.*.*' + - "v*.*.*" permissions: contents: read jobs: - publish: + draft: + name: Create draft release + if: github.event_name == 'push' runs-on: ubuntu-latest - permissions: - contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Use Node.js v18 - uses: actions/setup-node@v3 - with: - node-version: 18 - registry-url: 'https://registry.npmjs.org' - - - uses: denoland/setup-deno@v1 - with: - deno-version: v1.x - - - name: Testing - run: deno test - - - name: Build - run: deno task build:node ${{ github.ref }} - - - name: Publish to registry.npmjs.com - run: | - cd ./npm - npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Setup git-cliff uses: kenji-miyake/setup-git-cliff@v1 @@ -57,3 +37,23 @@ jobs: with: draft: true body: ${{ steps.changelog.outputs.result }} + + publish: + name: Publish to JSR + if: github.event_name == 'release' + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + + - name: Publish (dry-run) + run: deno publish --dry-run + + - name: Publish + run: deno publish diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e1c22b5..a0e91c4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,3 +34,6 @@ jobs: - uses: codecov/codecov-action@v3 with: file: ./coverage.lcov + + - name: Publish (dry run) + run: deno publish --dry-run diff --git a/.vscode/settings.json b/.vscode/settings.json index cbac569..aa1c94e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "deno.enable": true + "deno.enable": true, + "deno.unstable": true } diff --git a/basic-auth/fetcher.test.ts b/basic-auth/fetcher.test.ts index db558e5..ed1849e 100644 --- a/basic-auth/fetcher.test.ts +++ b/basic-auth/fetcher.test.ts @@ -1,9 +1,5 @@ -import { - assertInstanceOf, - assertSpyCalls, - assertStrictEquals, - stub, -} from "../deps_test.ts"; +import { assertInstanceOf, assertStrictEquals } from "@std/assert"; +import { assertSpyCalls, stub } from "@std/testing/mock"; import { fetcher as basicAuth } from "./fetcher.ts"; Deno.test('When calling fetch, the "Authorization" header must be set to the correct value.', async () => { diff --git a/basic-auth/fetcher.ts b/basic-auth/fetcher.ts index 45e6d84..16303e4 100644 --- a/basic-auth/fetcher.ts +++ b/basic-auth/fetcher.ts @@ -1,4 +1,4 @@ -import { base64encode } from "../deps.ts"; +import { encodeBase64 } from "@std/encoding/base64"; import { resolveURL } from "../utils/url.ts"; /** @@ -20,8 +20,11 @@ import { resolveURL } from "../utils/url.ts"; * @param username your email address * @param password your password */ -export const fetcher = (username: string, password: string) => { - const token = base64encode(`${username}:${password}`); +export const fetcher = ( + username: string, + password: string, +): (input: string | Request, init?: RequestInit) => Promise => { + const token = encodeBase64(`${username}:${password}`); return (input: string | Request, init?: RequestInit) => { const url = resolveURL(input); diff --git a/build.ts b/build.ts deleted file mode 100644 index aa1d0d2..0000000 --- a/build.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { build, emptyDir } from "https://deno.land/x/dnt@0.33.0/mod.ts"; -import * as semver from "https://deno.land/std@0.175.0/semver/mod.ts"; - -const trimVersion = (str: string) => - /^refs\/tags\/v(.+)$/.exec(str)?.at(1)?.trim(); -const version = semver.valid(trimVersion(Deno.args[0]) ?? null); - -if (!version) { - console.error("Incorrect version"); - Deno.exit(1); -} - -await emptyDir("npm"); -await build({ - entryPoints: ["./mod.ts"], - outDir: "./npm", - typeCheck: false, - test: false, // NOTE: 一時的に無効 - compilerOptions: { - lib: ["dom", "esnext"], - target: "ES2020", - }, - package: { - name: "twitter-api-fetch", - version, - description: "fetch-like implementation designed for Twitter API", - author: "InkoHX ", - homepage: "https://github.com/nexterias/twitter-api-fetch#readme", - license: "MIT", - repository: { - type: "git", - url: "https://github.com/nexterias/twitter-api-fetch.git", - }, - bugs: { - url: "https://github.com/nexterias/twitter-api-fetch/issues", - }, - keywords: [ - "twitter-api", - "fetch", - ], - }, - shims: { - crypto: true, - deno: "dev", - custom: [{ - package: { - name: "cross-fetch", - version: "~3.1.5", - }, - globalNames: [ - { - name: "fetch", - exportName: "default", - }, - { - name: "Request", - }, - { - name: "Response", - }, - { - name: "Headers", - }, - ], - }], - }, -}); - -Deno.copyFileSync("./README.md", "./npm/README.md"); -Deno.copyFileSync("./LICENSE", "./npm/LICENSE"); - -// Bundling for Edge runtime. -{ - const process = Deno.run({ - cmd: ["deno", "bundle", "./mod.ts", "--", "./npm/edge.js"], - }); - const status = await process.status(); - - if (!status.success) { - console.error("Bundling failed."); - Deno.exit(status.code); - } - - await Deno.writeTextFile( - "./npm/edge.d.ts", - 'export * from "./types/mod.js";', - ); - - const metadata = JSON.parse( - await Deno.readTextFile("./npm/package.json"), - // deno-lint-ignore no-explicit-any - ) as Record; - - await Deno.writeTextFile( - "./npm/package.json", - JSON.stringify( - { - ...metadata, - exports: { - ...metadata.exports, - "./edge": { - import: { - types: "./edge.d.ts", - default: "./edge.js", - }, - }, - }, - }, - null, - 2, - ), - ); -} diff --git a/deno.json b/deno.json index 27e41f6..4f730be 100644 --- a/deno.json +++ b/deno.json @@ -1,20 +1,23 @@ { - "tasks": { - "build:node": "deno run -A ./build.ts" + "name": "@nexterias/twitter-api-fetch", + "version": "3.0.0", + "exports": "./mod.ts", + "lock": false, + "publish": { + "exclude": ["./.github/**/*", "./cliff.toml", "./vscode/**/*"] }, "lint": { - "files": { - "exclude": ["./npm", "./coverage"] - } + "exclude": ["./coverage"] }, "fmt": { - "files": { - "exclude": ["./npm", "./coverage"] - } + "exclude": ["./coverage"] }, "test": { - "files": { - "exclude": ["./npm", "./coverage"] - } + "exclude": ["./coverage"] + }, + "imports": { + "@std/assert": "jsr:@std/assert@^0.219.1", + "@std/encoding": "jsr:@std/encoding@^0.219.1", + "@std/testing": "jsr:@std/testing@^0.219.1" } } diff --git a/deno.lock b/deno.lock deleted file mode 100644 index d0d5bd8..0000000 --- a/deno.lock +++ /dev/null @@ -1,140 +0,0 @@ -{ - "version": "2", - "remote": { - "https://deno.land/std@0.111.0/_util/assert.ts": "2f868145a042a11d5ad0a3c748dcf580add8a0dbc0e876eaa0026303a5488f58", - "https://deno.land/std@0.111.0/_util/os.ts": "dfb186cc4e968c770ab6cc3288bd65f4871be03b93beecae57d657232ecffcac", - "https://deno.land/std@0.111.0/bytes/bytes_list.ts": "3bff6a09c72b2e0b1e92e29bd3b135053894196cca07a2bba842901073efe5cb", - "https://deno.land/std@0.111.0/bytes/equals.ts": "69f55fdbd45c71f920c1a621e6c0865dc780cd8ae34e0f5e55a9497b70c31c1b", - "https://deno.land/std@0.111.0/bytes/mod.ts": "fedb80b8da2e7ad8dd251148e65f92a04c73d6c5a430b7d197dc39588c8dda6f", - "https://deno.land/std@0.111.0/fmt/colors.ts": "8368ddf2d48dfe413ffd04cdbb7ae6a1009cf0dccc9c7ff1d76259d9c61a0621", - "https://deno.land/std@0.111.0/fs/_util.ts": "f2ce811350236ea8c28450ed822a5f42a0892316515b1cd61321dec13569c56b", - "https://deno.land/std@0.111.0/fs/ensure_dir.ts": "b7c103dc41a3d1dbbb522bf183c519c37065fdc234831a4a0f7d671b1ed5fea7", - "https://deno.land/std@0.111.0/hash/sha256.ts": "bd85257c68d1fdd9da8457284c4fbb04efa9f4f2229b5f41a638d5b71a3a8d5c", - "https://deno.land/std@0.111.0/io/buffer.ts": "fdf93ba9e5d20ff3369e2c42443efd89131f8a73066f7f59c033cc588a0e2cfe", - "https://deno.land/std@0.111.0/io/types.d.ts": "89a27569399d380246ca7cdd9e14d5e68459f11fb6110790cc5ecbd4ee7f3215", - "https://deno.land/std@0.111.0/path/_constants.ts": "1247fee4a79b70c89f23499691ef169b41b6ccf01887a0abd131009c5581b853", - "https://deno.land/std@0.111.0/path/_interface.ts": "1fa73b02aaa24867e481a48492b44f2598cd9dfa513c7b34001437007d3642e4", - "https://deno.land/std@0.111.0/path/_util.ts": "2e06a3b9e79beaf62687196bd4b60a4c391d862cfa007a20fc3a39f778ba073b", - "https://deno.land/std@0.111.0/path/common.ts": "f41a38a0719a1e85aa11c6ba3bea5e37c15dd009d705bd8873f94c833568cbc4", - "https://deno.land/std@0.111.0/path/glob.ts": "ea87985765b977cc284b92771003b2070c440e0807c90e1eb0ff3e095911a820", - "https://deno.land/std@0.111.0/path/mod.ts": "4465dc494f271b02569edbb4a18d727063b5dbd6ed84283ff906260970a15d12", - "https://deno.land/std@0.111.0/path/posix.ts": "34349174b9cd121625a2810837a82dd8b986bbaaad5ade690d1de75bbb4555b2", - "https://deno.land/std@0.111.0/path/separator.ts": "8fdcf289b1b76fd726a508f57d3370ca029ae6976fcde5044007f062e643ff1c", - "https://deno.land/std@0.111.0/path/win32.ts": "11549e8c6df8307a8efcfa47ad7b2a75da743eac7d4c89c9723a944661c8bd2e", - "https://deno.land/std@0.111.0/streams/conversion.ts": "fe0059ed9d3c53eda4ba44eb71a6a9acb98c5fdb5ba1b6c6ab28004724c7641b", - "https://deno.land/std@0.140.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74", - "https://deno.land/std@0.140.0/_util/os.ts": "3b4c6e27febd119d36a416d7a97bd3b0251b77c88942c8f16ee5953ea13e2e49", - "https://deno.land/std@0.140.0/fs/_util.ts": "0fb24eb4bfebc2c194fb1afdb42b9c3dda12e368f43e8f2321f84fc77d42cb0f", - "https://deno.land/std@0.140.0/fs/ensure_dir.ts": "9dc109c27df4098b9fc12d949612ae5c9c7169507660dcf9ad90631833209d9d", - "https://deno.land/std@0.140.0/fs/expand_glob.ts": "0c10130d67c9b02164b03df8e43c6d6defbf8e395cb69d09e84a8586e6d72ac3", - "https://deno.land/std@0.140.0/fs/walk.ts": "117403ccd21fd322febe56ba06053b1ad5064c802170f19b1ea43214088fe95f", - "https://deno.land/std@0.140.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3", - "https://deno.land/std@0.140.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09", - "https://deno.land/std@0.140.0/path/_util.ts": "c1e9686d0164e29f7d880b2158971d805b6e0efc3110d0b3e24e4b8af2190d2b", - "https://deno.land/std@0.140.0/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633", - "https://deno.land/std@0.140.0/path/glob.ts": "cb5255638de1048973c3e69e420c77dc04f75755524cb3b2e160fe9277d939ee", - "https://deno.land/std@0.140.0/path/mod.ts": "d3e68d0abb393fb0bf94a6d07c46ec31dc755b544b13144dee931d8d5f06a52d", - "https://deno.land/std@0.140.0/path/posix.ts": "293cdaec3ecccec0a9cc2b534302dfe308adb6f10861fa183275d6695faace44", - "https://deno.land/std@0.140.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9", - "https://deno.land/std@0.140.0/path/win32.ts": "31811536855e19ba37a999cd8d1b62078235548d67902ece4aa6b814596dd757", - "https://deno.land/std@0.143.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74", - "https://deno.land/std@0.143.0/_util/os.ts": "3b4c6e27febd119d36a416d7a97bd3b0251b77c88942c8f16ee5953ea13e2e49", - "https://deno.land/std@0.143.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3", - "https://deno.land/std@0.143.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09", - "https://deno.land/std@0.143.0/path/_util.ts": "c1e9686d0164e29f7d880b2158971d805b6e0efc3110d0b3e24e4b8af2190d2b", - "https://deno.land/std@0.143.0/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633", - "https://deno.land/std@0.143.0/path/glob.ts": "cb5255638de1048973c3e69e420c77dc04f75755524cb3b2e160fe9277d939ee", - "https://deno.land/std@0.143.0/path/mod.ts": "d3e68d0abb393fb0bf94a6d07c46ec31dc755b544b13144dee931d8d5f06a52d", - "https://deno.land/std@0.143.0/path/posix.ts": "293cdaec3ecccec0a9cc2b534302dfe308adb6f10861fa183275d6695faace44", - "https://deno.land/std@0.143.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9", - "https://deno.land/std@0.143.0/path/win32.ts": "31811536855e19ba37a999cd8d1b62078235548d67902ece4aa6b814596dd757", - "https://deno.land/std@0.171.0/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462", - "https://deno.land/std@0.171.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", - "https://deno.land/std@0.171.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471", - "https://deno.land/std@0.171.0/fs/_util.ts": "65381f341af1ff7f40198cee15c20f59951ac26e51ddc651c5293e24f9ce6f32", - "https://deno.land/std@0.171.0/fs/empty_dir.ts": "c3d2da4c7352fab1cf144a1ecfef58090769e8af633678e0f3fabaef98594688", - "https://deno.land/std@0.171.0/fs/expand_glob.ts": "536055845aafc32de7e7a46c3b778a741825d5e2ed8580d9851a01ec7a5adf2e", - "https://deno.land/std@0.171.0/fs/walk.ts": "ea95ffa6500c1eda6b365be488c056edc7c883a1db41ef46ec3bf057b1c0fe32", - "https://deno.land/std@0.171.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", - "https://deno.land/std@0.171.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", - "https://deno.land/std@0.171.0/path/_util.ts": "86c2375a996c1931b2f2ac71fefd5ddf0cf0e579fa4ab12d3e4c552d4223b8d8", - "https://deno.land/std@0.171.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", - "https://deno.land/std@0.171.0/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1", - "https://deno.land/std@0.171.0/path/mod.ts": "4b83694ac500d7d31b0cdafc927080a53dc0c3027eb2895790fb155082b0d232", - "https://deno.land/std@0.171.0/path/posix.ts": "2ecc259e6f34013889b7638ff90339a82d8178f629155761ce6001e41af55a43", - "https://deno.land/std@0.171.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", - "https://deno.land/std@0.171.0/path/win32.ts": "99170a0eb0e2b1ce41499c1e86bb55320cb6606299ad947f57ee0a291cdb93d5", - "https://deno.land/std@0.173.0/async/delay.ts": "73aa04cec034c84fc748c7be49bb15cac3dd43a57174bfdb7a4aec22c248f0dd", - "https://deno.land/std@0.173.0/collections/_comparators.ts": "fa7f9a44cea1d270098a2a5a6f8bb30c61b595c1b1f983bd67c6297d766adffa", - "https://deno.land/std@0.173.0/collections/binary_search_node.ts": "5798272236040318876eec6ad9ffba821fe6eec53e7f238e80820c10f81077e4", - "https://deno.land/std@0.173.0/collections/binary_search_tree.ts": "957ab60afe587c9339294771b5c7529cf385db8533ab26c5e90adb1f9fe92e90", - "https://deno.land/std@0.173.0/collections/red_black_node.ts": "d4ea89a9518fe888b4792ed6842d78f2bc19d25f8ce3af7dfe1de16938344b0a", - "https://deno.land/std@0.173.0/collections/red_black_tree.ts": "4fe76729e6d55e5ae9183e1a772af72063138485c9ffb235694ff6b3f97944bc", - "https://deno.land/std@0.173.0/encoding/base64.ts": "7de04c2f8aeeb41453b09b186480be90f2ff357613b988e99fabb91d2eeceba1", - "https://deno.land/std@0.173.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471", - "https://deno.land/std@0.173.0/semver/mod.ts": "80acd488589001b15542847663101142fb251729a8c902ae60d66427a4a9eae1", - "https://deno.land/std@0.173.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", - "https://deno.land/std@0.173.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.173.0/testing/_time.ts": "fecaf6fc7277d240d11b0de2e93b1c93ebbb4a3a61f0cb0b1741f66f69a4d22b", - "https://deno.land/std@0.173.0/testing/asserts.ts": "984ab0bfb3faeed92ffaa3a6b06536c66811185328c5dd146257c702c41b01ab", - "https://deno.land/std@0.173.0/testing/mock.ts": "220ed9b8151cb2cac141043d4cfea7c47673fab5d18d1c1f0943297c8afb5d13", - "https://deno.land/std@0.173.0/testing/time.ts": "82b92484207947610c717e43f125742d68941ff28f8fa7aea440fc29b667e2b7", - "https://deno.land/std@0.175.0/async/delay.ts": "73aa04cec034c84fc748c7be49bb15cac3dd43a57174bfdb7a4aec22c248f0dd", - "https://deno.land/std@0.175.0/collections/_comparators.ts": "fa7f9a44cea1d270098a2a5a6f8bb30c61b595c1b1f983bd67c6297d766adffa", - "https://deno.land/std@0.175.0/collections/binary_search_node.ts": "5798272236040318876eec6ad9ffba821fe6eec53e7f238e80820c10f81077e4", - "https://deno.land/std@0.175.0/collections/binary_search_tree.ts": "99b71b46c84e9c558ee6f6ff877ff44316f736eea63e492ec658e5cff0c2350f", - "https://deno.land/std@0.175.0/collections/red_black_node.ts": "d4ea89a9518fe888b4792ed6842d78f2bc19d25f8ce3af7dfe1de16938344b0a", - "https://deno.land/std@0.175.0/collections/red_black_tree.ts": "cdca30e96902d566dedead3a449460355bd963286a09eb1744cf4109f65e77a1", - "https://deno.land/std@0.175.0/encoding/base64.ts": "7de04c2f8aeeb41453b09b186480be90f2ff357613b988e99fabb91d2eeceba1", - "https://deno.land/std@0.175.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471", - "https://deno.land/std@0.175.0/semver/mod.ts": "2b35263864657d3cfd83d3a952997617ff42d8917733465f7a2578e3018da1af", - "https://deno.land/std@0.175.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", - "https://deno.land/std@0.175.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.175.0/testing/_time.ts": "fecaf6fc7277d240d11b0de2e93b1c93ebbb4a3a61f0cb0b1741f66f69a4d22b", - "https://deno.land/std@0.175.0/testing/asserts.ts": "984ab0bfb3faeed92ffaa3a6b06536c66811185328c5dd146257c702c41b01ab", - "https://deno.land/std@0.175.0/testing/mock.ts": "220ed9b8151cb2cac141043d4cfea7c47673fab5d18d1c1f0943297c8afb5d13", - "https://deno.land/std@0.175.0/testing/time.ts": "82b92484207947610c717e43f125742d68941ff28f8fa7aea440fc29b667e2b7", - "https://deno.land/x/code_block_writer@11.0.3/mod.ts": "2c3448060e47c9d08604c8f40dee34343f553f33edcdfebbf648442be33205e5", - "https://deno.land/x/code_block_writer@11.0.3/utils/string_utils.ts": "60cb4ec8bd335bf241ef785ccec51e809d576ff8e8d29da43d2273b69ce2a6ff", - "https://deno.land/x/deno_cache@0.2.1/auth_tokens.ts": "01b94d25abd974153a3111653998b9a43c66d84a0e4b362fc5f4bbbf40a6e0f7", - "https://deno.land/x/deno_cache@0.2.1/cache.ts": "67e301c20161546fea45405316314f4c3d85cc7a367b2fb72042903f308f55b7", - "https://deno.land/x/deno_cache@0.2.1/deno_dir.ts": "e4dc68da5641aa337bcc06fb1df28fcb086b366dcbea7d8aaed7ac7c853fedb1", - "https://deno.land/x/deno_cache@0.2.1/deps.ts": "2ebaba0ad86fff8b9027c6afd4c3909a17cd8bf8c9e263151c980c15c56a18ee", - "https://deno.land/x/deno_cache@0.2.1/dirs.ts": "e07003fabed7112375d4a50040297aae768f9d06bb6c2655ca46880653b576b4", - "https://deno.land/x/deno_cache@0.2.1/disk_cache.ts": "d7a361f0683a032bcca28513a7bbedc28c77cfcc6719e6f6cea156c0ff1108df", - "https://deno.land/x/deno_cache@0.2.1/file_fetcher.ts": "352702994c190c45215f3b8086621e117e88bc2174b020faefb5eca653d71d6a", - "https://deno.land/x/deno_cache@0.2.1/http_cache.ts": "af1500149496e2d0acadec24569e2a9c86a3f600cceef045dcf6f5ce8de72b3a", - "https://deno.land/x/deno_cache@0.2.1/mod.ts": "709ab9d1068be5fd77b020b33e7a9394f1e9b453553b1e2336b72c90283cf3c0", - "https://deno.land/x/deno_cache@0.2.1/util.ts": "652479928551259731686686ff2df6f26bc04e8e4d311137b2bf3bc10f779f48", - "https://deno.land/x/deno_graph@0.6.0/lib/deno_graph.generated.js": "3e1cccd6376d4ad0ea789d66aa0f6b19f737fa8da37b5e6185ef5c269c974f54", - "https://deno.land/x/deno_graph@0.6.0/lib/loader.ts": "13a11c1dea0d85e0ad211be77217b8c06138bbb916afef6f50a04cca415084a9", - "https://deno.land/x/deno_graph@0.6.0/lib/media_type.ts": "36be751aa63d6ae36475b90dca5fae8fd7c3a77cf13684c48cf23a85ee607b31", - "https://deno.land/x/deno_graph@0.6.0/lib/snippets/deno_graph-1c138d6136337537/src/deno_apis.js": "f13f2678d875372cf8489ceb7124623a39fa5bf8de8ee1ec722dbb2ec5ec7845", - "https://deno.land/x/deno_graph@0.6.0/lib/types.d.ts": "68cb232e02a984658b40ffaf6cafb979a06fbfdce7f5bd4c7a83ed1a32a07687", - "https://deno.land/x/deno_graph@0.6.0/mod.ts": "8fe3d39bdcb273adfb41a0bafbbaabec4c6fe6c611b47fed8f46f218edb37e8e", - "https://deno.land/x/dnt@0.33.0/lib/compiler.ts": "dd589db479d6d7e69999865003ab83c41544e251ece4f21f2f2ee74557097ba6", - "https://deno.land/x/dnt@0.33.0/lib/compiler_transforms.ts": "cbb1fd5948f5ced1aa5c5aed9e45134e2357ce1e7220924c1d7bded30dcd0dd0", - "https://deno.land/x/dnt@0.33.0/lib/mod.deps.ts": "6648fb17b4a49677cb0c24f60ffb5067a86ad69ff97712d40fe0d62b281b1811", - "https://deno.land/x/dnt@0.33.0/lib/npm_ignore.ts": "ddc1a7a76b288ca471bf1a6298527887a0f9eb7e25008072fd9c9fa9bb28c71a", - "https://deno.land/x/dnt@0.33.0/lib/package_json.ts": "2d629dbaef8004971e38ce3661f04b915a35342b905c3d98ff4a25343c2a8293", - "https://deno.land/x/dnt@0.33.0/lib/pkg/dnt_wasm.generated.js": "00257fc2f03321bb5f2b9bc23cb85e79fe55eb49a325d5ab925b9fc81b4aa963", - "https://deno.land/x/dnt@0.33.0/lib/pkg/snippets/dnt-wasm-a15ef721fa5290c5/helpers.js": "2f623f83602d4fbb30caa63444b10e35b45e9c2b267e49585ec9bb790a4888d8", - "https://deno.land/x/dnt@0.33.0/lib/shims.ts": "7998851b149cb230f5183590d3b66c06f696fefb1c31c24eb5736f1ef12a4de1", - "https://deno.land/x/dnt@0.33.0/lib/test_runner/get_test_runner_code.ts": "2a4e26aa33120f3cc9e03b8538211a5047a4bad4c64e895944b87f2dcd55d904", - "https://deno.land/x/dnt@0.33.0/lib/test_runner/test_runner.ts": "b91d77d9d4b82984cb2ba7431ba6935756ba72f62e7dd4db22cd47a680ebd952", - "https://deno.land/x/dnt@0.33.0/lib/transform.deps.ts": "28cee4e09a7c6baf156d363cdeb408088d00e7cb7755946202cb62b47ed223ec", - "https://deno.land/x/dnt@0.33.0/lib/types.ts": "34e45a3136c2f21f797173ea46d9ea5d1639eb7b834a5bd565aad4214fa32603", - "https://deno.land/x/dnt@0.33.0/lib/utils.ts": "5b7bba18f4d4d91b79343216c93a7b21d9dd6019e4d3a7b25ba043d44a1fc237", - "https://deno.land/x/dnt@0.33.0/mod.ts": "691ea4b644cc61123b7beed19e66af301f25985483b81d21cfe49a0be2877fd9", - "https://deno.land/x/dnt@0.33.0/transform.ts": "5960cf0b84d5bfae3ca61569a344a467f448d8e96ab1eceee8cb181698fb6c65", - "https://deno.land/x/ts_morph@17.0.1/bootstrap/mod.ts": "b53aad517f106c4079971fcd4a81ab79fadc40b50061a3ab2b741a09119d51e9", - "https://deno.land/x/ts_morph@17.0.1/bootstrap/ts_morph_bootstrap.d.ts": "607e651c5ae5aa57c2ac4090759a6379e809c0cdc42114742ac67353b1a75038", - "https://deno.land/x/ts_morph@17.0.1/bootstrap/ts_morph_bootstrap.js": "91a954daa993c5acb3361aa5279394f81ea6fe18b3854345c86111b336491cfc", - "https://deno.land/x/ts_morph@17.0.1/common/DenoRuntime.ts": "537800e840d0994f9055164e11bf33eadf96419246af0d3c453793c3ae67bdb3", - "https://deno.land/x/ts_morph@17.0.1/common/mod.ts": "01985d2ee7da8d1caee318a9d07664774fbee4e31602bc2bb6bb62c3489555ed", - "https://deno.land/x/ts_morph@17.0.1/common/ts_morph_common.d.ts": "ee7767b0c68b23c65bb607c94b6cb3512e8237fbcb7d1d8383a33235cde2c068", - "https://deno.land/x/ts_morph@17.0.1/common/ts_morph_common.js": "49a79124b941ba2b35d81ac9eb90fc33c957b2640cdb97569c1941bac5a3bbdb", - "https://deno.land/x/ts_morph@17.0.1/common/typescript.d.ts": "57e52a0882af4e835473dda27e4316cc31149866970210f9f79b940e916b7838", - "https://deno.land/x/ts_morph@17.0.1/common/typescript.js": "5dd669eb199ee2a539924c63a92e23d95df43dfe2fbe3a9d68c871648be1ad5e" - } -} \ No newline at end of file diff --git a/deps.ts b/deps.ts deleted file mode 100644 index d2a3fc4..0000000 --- a/deps.ts +++ /dev/null @@ -1 +0,0 @@ -export { encode as base64encode } from "https://deno.land/std@0.175.0/encoding/base64.ts"; diff --git a/deps_test.ts b/deps_test.ts deleted file mode 100644 index 9403715..0000000 --- a/deps_test.ts +++ /dev/null @@ -1,10 +0,0 @@ -export { - assertInstanceOf, - assertStrictEquals, - assertThrows, -} from "https://deno.land/std@0.175.0/testing/asserts.ts"; -export { FakeTime } from "https://deno.land/std@0.175.0/testing/time.ts"; -export { - assertSpyCalls, - stub, -} from "https://deno.land/std@0.175.0/testing/mock.ts"; diff --git a/oauth1/fetcher.ts b/oauth1/fetcher.ts index 6608a98..11cc1b9 100644 --- a/oauth1/fetcher.ts +++ b/oauth1/fetcher.ts @@ -31,7 +31,11 @@ import { resolveURL } from "../utils/url.ts"; * console.log(await response.json()); * ``` */ -export const fetcher = async (credentials: Readonly) => { +export const fetcher = async ( + credentials: Readonly, +): Promise< + (input: string | Request, init?: RequestInit) => Promise +> => { const signingKey = await createSigningKey({ secretAccessToken: credentials.secretAccessToken, secretConsumerKey: credentials.secretConsumerKey, diff --git a/oauth1/hmac.test.ts b/oauth1/hmac.test.ts index c7c75be..7bf84da 100644 --- a/oauth1/hmac.test.ts +++ b/oauth1/hmac.test.ts @@ -1,5 +1,5 @@ import * as hmac from "./hmac.ts"; -import { assertStrictEquals } from "../deps_test.ts"; +import { assertStrictEquals } from "@std/assert"; import * as oauth1a from "./oauth1a.ts"; const credentials = { diff --git a/oauth1/hmac.ts b/oauth1/hmac.ts index 8a57fff..db06817 100644 --- a/oauth1/hmac.ts +++ b/oauth1/hmac.ts @@ -5,7 +5,7 @@ import { OAuth1aSignedParameters, } from "./types.ts"; import * as percent from "../utils/percent.ts"; -import { base64encode } from "../deps.ts"; +import { encodeBase64 } from "@std/encoding/base64"; /** * {@link https://developer.twitter.com/en/docs/authentication/oauth-1-0a/creating-a-signature Creating a signature | Docs | Twitter Developer Platform} - Getting a signing key @@ -17,7 +17,7 @@ export const combineKeys = ( OAuth1aCredential, "secretAccessToken" | "secretConsumerKey" >, -) => +): string => [ credentials.secretConsumerKey, credentials.secretAccessToken, @@ -28,7 +28,7 @@ export const createSigningKey = ( OAuth1aCredential, "secretAccessToken" | "secretConsumerKey" >, -) => { +): Promise => { const key = combineKeys(credentials); const textEncoder = new TextEncoder(); @@ -73,7 +73,7 @@ export const sign = async ( textEncoder.encode(message), ); - clonedParams.set("oauth_signature", base64encode(hash)); + clonedParams.set("oauth_signature", encodeBase64(hash)); return clonedParams; }; diff --git a/oauth1/oauth1a.test.ts b/oauth1/oauth1a.test.ts index 7c9d547..013c407 100644 --- a/oauth1/oauth1a.test.ts +++ b/oauth1/oauth1a.test.ts @@ -1,9 +1,6 @@ -import { - assertInstanceOf, - assertStrictEquals, - FakeTime, - stub, -} from "../deps_test.ts"; +import { assertInstanceOf, assertStrictEquals } from "@std/assert"; +import { stub } from "@std/testing/mock"; +import { FakeTime } from "@std/testing/time"; import { createBaseParams, createHttpHeader } from "./oauth1a.ts"; Deno.test("createBaseParams", () => { diff --git a/oauth1/oauth1a.ts b/oauth1/oauth1a.ts index 183c816..6c2307c 100644 --- a/oauth1/oauth1a.ts +++ b/oauth1/oauth1a.ts @@ -1,4 +1,4 @@ -import { base64encode } from "../deps.ts"; +import { encodeBase64 } from "@std/encoding/base64"; import { OAuth1aBaseParameters, OAuth1aSignedParameters } from "./types.ts"; import * as percent from "../utils/percent.ts"; @@ -10,7 +10,7 @@ export const createBaseParams = ( return new Map([ ["oauth_consumer_key", consumerKey], - ["oauth_nonce", base64encode(randomBytes)], + ["oauth_nonce", encodeBase64(randomBytes)], ["oauth_timestamp", (Date.now() / 1000).toFixed(0)], ["oauth_token", accessToken], ["oauth_version", "1.0"], diff --git a/oauth2/fetcher.test.ts b/oauth2/fetcher.test.ts index c33208d..42c9c67 100644 --- a/oauth2/fetcher.test.ts +++ b/oauth2/fetcher.test.ts @@ -1,9 +1,5 @@ -import { - assertInstanceOf, - assertSpyCalls, - assertStrictEquals, - stub, -} from "../deps_test.ts"; +import { assertInstanceOf, assertStrictEquals } from "@std/assert"; +import { assertSpyCalls, stub } from "@std/testing/mock"; import { fetcher as oauth2 } from "./fetcher.ts"; Deno.test('When calling fetch, the "Authorization" header must be set to the correct value.', async () => { diff --git a/oauth2/fetcher.ts b/oauth2/fetcher.ts index 74fe8f6..a652e6d 100644 --- a/oauth2/fetcher.ts +++ b/oauth2/fetcher.ts @@ -11,7 +11,9 @@ import { resolveURL } from "../utils/url.ts"; * console.log(await fetcher("/2/tweets")); * ``` */ -export const fetcher = (bearerToken: string) => { +export const fetcher = ( + bearerToken: string, +): (input: string | Request, init?: RequestInit) => Promise => { return (input: string | Request, init?: RequestInit) => { const url = resolveURL(input); const request = new Request(url, init); diff --git a/utils/percent.test.ts b/utils/percent.test.ts index 91bad21..c5140f5 100644 --- a/utils/percent.test.ts +++ b/utils/percent.test.ts @@ -1,4 +1,4 @@ -import { assertStrictEquals } from "../deps_test.ts"; +import { assertStrictEquals } from "@std/assert"; import * as percent from "./percent.ts"; Deno.test("encode", () => { diff --git a/utils/url.test.ts b/utils/url.test.ts index bbb12db..2e6c861 100644 --- a/utils/url.test.ts +++ b/utils/url.test.ts @@ -2,7 +2,7 @@ import { assertInstanceOf, assertStrictEquals, assertThrows, -} from "../deps_test.ts"; +} from "@std/assert"; import { resolveURL } from "./url.ts"; Deno.test("Returns URL (string) when a Request object is passed", () => { diff --git a/utils/url.ts b/utils/url.ts index ef46fa1..584f21d 100644 --- a/utils/url.ts +++ b/utils/url.ts @@ -1,4 +1,4 @@ -export const ALLOW_HOSTNAMES = new Set([ +export const ALLOW_HOSTNAMES: Set = new Set([ "gnip-stream.twitter.com", "data-api.twitter.com", "gnip-stream.gnip.com", @@ -6,7 +6,7 @@ export const ALLOW_HOSTNAMES = new Set([ "gnip-api.twitter.com", ]); -export const resolveURL = (info: string | Request) => { +export const resolveURL = (info: string | Request): URL => { const url = new URL( typeof info === "string" ? info : info.url, "https://api.twitter.com",