Skip to content

Commit

Permalink
refactor(@remix-run/node): implement crypto-dependent interface funct…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
pcattori committed Mar 19, 2022
1 parent 9897a5f commit afcb21e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
16 changes: 0 additions & 16 deletions packages/remix-node/cookieSigning.ts

This file was deleted.

16 changes: 16 additions & 0 deletions packages/remix-node/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import cookieSignature from "cookie-signature";
import type {
SignFunction,
UnsignFunction,
} from "@remix-run/server-runtime";

export const sign: SignFunction = async (value, secret) => {
return cookieSignature.sign(value, secret);
};

export const unsign: UnsignFunction = async (
signed: string,
secret: string
) => {
return cookieSignature.unsign(signed, secret);
};
13 changes: 0 additions & 13 deletions packages/remix-node/globals.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type {
InternalSignFunctionDoNotUseMe,
InternalUnsignFunctionDoNotUseMe,
} from "@remix-run/server-runtime/cookieSigning";
import { Blob as NodeBlob, File as NodeFile } from "@web-std/file";

import { atob, btoa } from "./base64";
import { sign as remixSign, unsign as remixUnsign } from "./cookieSigning";
import {
Headers as NodeHeaders,
Request as NodeRequest,
Expand All @@ -32,11 +27,6 @@ declare global {
Response: typeof Response;
fetch: typeof fetch;
FormData: typeof FormData;

// TODO: Once node v16 is available on AWS we should remove these globals
// and provide the webcrypto API instead.
sign: InternalSignFunctionDoNotUseMe;
unsign: InternalUnsignFunctionDoNotUseMe;
}
}
}
Expand All @@ -53,7 +43,4 @@ export function installGlobals() {
global.Response = NodeResponse as unknown as typeof Response;
global.fetch = nodeFetch as unknown as typeof fetch;
global.FormData = NodeFormData as unknown as typeof FormData;

global.sign = remixSign;
global.unsign = remixUnsign;
}
13 changes: 13 additions & 0 deletions packages/remix-node/implementations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
createCookieFactory,
createCookieSessionStorageFactory,
createMemorySessionStorageFactory,
createSessionStorageFactory,
} from "@remix-run/server-runtime";

import { sign, unsign } from "./crypto";

export const createCookie = createCookieFactory({ sign, unsign });
export const createCookieSessionStorage = createCookieSessionStorageFactory(createCookie);
export const createSessionStorage = createSessionStorageFactory(createCookie);
export const createMemorySessionStorage = createMemorySessionStorageFactory(createSessionStorage);
5 changes: 4 additions & 1 deletion packages/remix-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ export {
createCookie,
createCookieSessionStorage,
createMemorySessionStorage,
createSessionStorage,
} from './implementations';

export {
createRequestHandler,
createSession,
createSessionStorage,
isCookie,
isSession,
json,
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-node/sessions/fileStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type {
SessionStorage,
SessionIdStorageStrategy,
} from "@remix-run/server-runtime";
import { createSessionStorage } from "@remix-run/server-runtime";

import { createSessionStorage } from "../implementations";

interface FileSessionStorageOptions {
/**
Expand Down

0 comments on commit afcb21e

Please sign in to comment.