Skip to content

Commit

Permalink
squash!
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Jul 18, 2023
1 parent 5c8cb2d commit abc27e6
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.3

- Refactor

## 0.0.2

- Bug fix
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ npm install -D -E @nowplayingcards/common
import {
encrypt,
decrypt,
access,
Uint8ArrayFromObject,
} from "@nowplayingcards/common";
```
Expand Down
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as encrypt } from "./lib/encrypt.js";
export { default as decrypt } from "./lib/decrypt.js";
export { default as access } from "./lib/access.js";
export { default as Uint8ArrayFromObject } from "./lib/Uint8ArrayFromObject.js";
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dist/lib/access.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="@cloudflare/workers-types" />
declare const _default: (Key: JsonWebKey["k"], UUID: ReturnType<Crypto["randomUUID"]>, From: KVNamespace, View?: "access_token") => Promise<any>;
export default _default;
1 change: 1 addition & 0 deletions dist/lib/access.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nowplayingcards/common",
"version": "0.0.2",
"version": "0.0.3",
"private": false,
"description": "Now Playing Cards common scripts",
"homepage": "https://github.com/Now-Playing-Cards/common#readme",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as encrypt } from "./lib/encrypt.js";
export { default as decrypt } from "./lib/decrypt.js";
export { default as access } from "./lib/access.js";
export { default as Uint8ArrayFromObject } from "./lib/Uint8ArrayFromObject.js";
29 changes: 29 additions & 0 deletions src/lib/access.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Buffer } from "node:buffer";
import type { DataObject } from "./Uint8ArrayFromObject";
import decrypt from "./decrypt.js";
import Uint8ArrayFromObject from "./Uint8ArrayFromObject.js";

export default async (
Key: JsonWebKey["k"],
UUID: ReturnType<Crypto["randomUUID"]>,
From: KVNamespace,
View: "access_token" = "access_token"
) => {
try {
const { iv, data } = (await From.get(UUID, {
type: "json",
})) as DataObject;

return JSON.parse(
Buffer.from(
await decrypt(
await Uint8ArrayFromObject(data),
Key ?? "",
await Uint8ArrayFromObject(iv)
)
).toString()
)[View];
} catch (error) {
return {};
}
};

0 comments on commit abc27e6

Please sign in to comment.