@ya-accelerators/nextjs-framework 0.0.71 → 0.0.73
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ya-accelerators/nextjs-framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.73",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "YA Technologies OÜ",
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
"lint:prettier": "prettier --check --config ../../.prettierrc.mjs --ignore-path ../../../.gitignore .",
|
|
37
37
|
"fix": "run-p -l -c fix:*",
|
|
38
38
|
"fix:eslint": "eslint . --fix",
|
|
39
|
-
"fix:prettier": "prettier --write --config ../../.prettierrc.mjs --ignore-path ../../../.gitignore ."
|
|
40
|
-
"test": "jest"
|
|
39
|
+
"fix:prettier": "prettier --write --config ../../.prettierrc.mjs --ignore-path ../../../.gitignore ."
|
|
41
40
|
},
|
|
42
41
|
"dependencies": {
|
|
43
42
|
"@aws-sdk/client-s3": "^3.1048.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// next-intl/server ships untransformed ESM; options() pulls it in transitively
|
|
2
|
-
// through the Util barrel (env → util → util/date). Mock it so the module graph
|
|
3
|
-
// loads — these bindings are never exercised by the routing tests below.
|
|
4
|
-
jest.mock('next-intl/server', () => ({
|
|
5
|
-
getTimeZone: jest.fn(),
|
|
6
|
-
getTranslations: jest.fn(),
|
|
7
|
-
}));
|
|
8
|
-
// options() eagerly reads defaultServerEnv (server proxy) when building the config:
|
|
9
|
-
// it validates NODE_ENV / DEPLOY_ENV against the framework enums and requires a
|
|
10
|
-
// NEXTAUTH_SECRET. jest defaults NODE_ENV to 'test' (rejected by the enum), so pin
|
|
11
|
-
// the env to valid values before any options() call. NODE_ENV is a read-only typed
|
|
12
|
-
// property, so assign through Object.assign.
|
|
13
|
-
Object.assign(process.env, {
|
|
14
|
-
NODE_ENV: 'development',
|
|
15
|
-
DEPLOY_ENV: 'dev',
|
|
16
|
-
NEXTAUTH_SECRET: 'test-secret-not-used-at-runtime',
|
|
17
|
-
});
|
|
18
|
-
import { options } from './index';
|
|
19
|
-
const tokenSet = {
|
|
20
|
-
accessToken: 'access',
|
|
21
|
-
refreshToken: 'refresh',
|
|
22
|
-
expiresAtSec: 1_000,
|
|
23
|
-
scope: 'read',
|
|
24
|
-
};
|
|
25
|
-
// next-auth's CredentialsProvider wraps our config: at runtime the real authorize
|
|
26
|
-
// lives on provider.options (the published type declares it at the top level).
|
|
27
|
-
const getAuthorize = (authorize, externalAuthorize) => {
|
|
28
|
-
const provider = options(authorize, undefined, externalAuthorize).providers[0];
|
|
29
|
-
return provider.options.authorize;
|
|
30
|
-
};
|
|
31
|
-
const req = {};
|
|
32
|
-
describe('Lib.nextAuth options() authorize routing', () => {
|
|
33
|
-
test('routes a non-empty credential to externalAuthorize', async () => {
|
|
34
|
-
const externalAuthorize = jest.fn(async () => tokenSet);
|
|
35
|
-
const authorize = jest.fn(async () => undefined);
|
|
36
|
-
const result = await getAuthorize(authorize, externalAuthorize)({ email: '', password: '', credential: 'one-time-code' }, req);
|
|
37
|
-
expect(externalAuthorize).toHaveBeenCalledWith('one-time-code');
|
|
38
|
-
expect(authorize).not.toHaveBeenCalled();
|
|
39
|
-
expect(result).toEqual({ tokenSet });
|
|
40
|
-
});
|
|
41
|
-
test('routes email/password to authorize when credential is empty', async () => {
|
|
42
|
-
const externalAuthorize = jest.fn(async () => undefined);
|
|
43
|
-
const authorize = jest.fn(async () => tokenSet);
|
|
44
|
-
const result = await getAuthorize(authorize, externalAuthorize)({ email: 'a@example.com', password: 'pw', credential: '' }, req);
|
|
45
|
-
expect(authorize).toHaveBeenCalledWith('a@example.com', 'pw');
|
|
46
|
-
expect(externalAuthorize).not.toHaveBeenCalled();
|
|
47
|
-
expect(result).toEqual({ tokenSet });
|
|
48
|
-
});
|
|
49
|
-
test('falls back to authorize when credential is present but externalAuthorize is not wired', async () => {
|
|
50
|
-
const authorize = jest.fn(async () => tokenSet);
|
|
51
|
-
const result = await getAuthorize(authorize, undefined)({ email: 'a@example.com', password: 'pw', credential: 'ignored-code' }, req);
|
|
52
|
-
expect(authorize).toHaveBeenCalledWith('a@example.com', 'pw');
|
|
53
|
-
expect(result).toEqual({ tokenSet });
|
|
54
|
-
});
|
|
55
|
-
test('returns null when the routed callback yields undefined', async () => {
|
|
56
|
-
const result = await getAuthorize(async () => undefined, undefined)({ email: 'a@example.com', password: 'pw', credential: '' }, req);
|
|
57
|
-
expect(result).toBeNull();
|
|
58
|
-
});
|
|
59
|
-
test('returns null when no applicable callback is wired', async () => {
|
|
60
|
-
const result = await getAuthorize(undefined, undefined)({ email: '', password: '', credential: 'code' }, req);
|
|
61
|
-
expect(result).toBeNull();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
describe('Lib.nextAuth options() secret resolution', () => {
|
|
65
|
-
// options() reads defaultServerEnv eagerly and createEnvProxy memoizes on first access,
|
|
66
|
-
// so each env scenario needs a fresh module graph (isolateModules) with its own process.env.
|
|
67
|
-
const withEnv = async (env, assert) => {
|
|
68
|
-
await jest.isolateModulesAsync(async () => {
|
|
69
|
-
const saved = { ...process.env };
|
|
70
|
-
for (const [key, value] of Object.entries(env)) {
|
|
71
|
-
if (value === undefined) {
|
|
72
|
-
delete process.env[key];
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
process.env[key] = value;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
assert((await import('./index')).options);
|
|
79
|
-
for (const key of Object.keys(env)) {
|
|
80
|
-
if (saved[key] === undefined) {
|
|
81
|
-
delete process.env[key];
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
process.env[key] = saved[key];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
test('build phase does not require NEXTAUTH_SECRET', async () => {
|
|
90
|
-
await withEnv({ NODE_ENV: 'production', DEPLOY_ENV: 'stg', NEXT_PHASE: 'phase-production-build', NEXTAUTH_SECRET: undefined }, (opts) => {
|
|
91
|
-
expect(() => opts()).not.toThrow();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
test('non-dev runtime rejects the build-only sentinel', async () => {
|
|
95
|
-
await withEnv({
|
|
96
|
-
NODE_ENV: 'production',
|
|
97
|
-
DEPLOY_ENV: 'stg',
|
|
98
|
-
NEXT_PHASE: undefined,
|
|
99
|
-
NEXTAUTH_SECRET: 'build-only-not-used-at-runtime',
|
|
100
|
-
}, (opts) => {
|
|
101
|
-
expect(() => opts()).toThrow('NEXTAUTH_SECRET must be replaced');
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../../src/lib/next-auth/index.test.ts"],"names":[],"mappings":"AAKA,+EAA+E;AAC/E,gFAAgF;AAChF,yEAAyE;AACzE,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE;IACtB,eAAe,EAAE,IAAI,CAAC,EAAE,EAAE;CAC3B,CAAC,CAAC,CAAA;AAEH,oFAAoF;AACpF,gFAAgF;AAChF,mFAAmF;AACnF,mFAAmF;AACnF,6CAA6C;AAC7C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE;IACzB,QAAQ,EAAE,aAAa;IACvB,UAAU,EAAE,KAAK;IACjB,eAAe,EAAE,iCAAiC;CACnD,CAAC,CAAA;AAEF,OAAO,EAAE,OAAO,EAAiB,MAAM,SAAS,CAAA;AAIhD,MAAM,QAAQ,GAAa;IACzB,WAAW,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