@htlkg/core 0.0.1 → 0.0.3
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/README.md +51 -0
- package/dist/amplify-astro-adapter/index.d.ts +109 -0
- package/dist/amplify-astro-adapter/index.js +295 -0
- package/dist/amplify-astro-adapter/index.js.map +1 -0
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +305 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/index.d.ts +220 -0
- package/dist/index.js +426 -1
- package/dist/index.js.map +1 -1
- package/dist/logger-BTW3fOeM.d.ts +45 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +55 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +56 -33
- package/src/amplify-astro-adapter/amplify-astro-adapter.md +167 -0
- package/src/amplify-astro-adapter/createCookieStorageAdapterFromAstroContext.test.ts +296 -0
- package/src/amplify-astro-adapter/createCookieStorageAdapterFromAstroContext.ts +97 -0
- package/src/amplify-astro-adapter/createRunWithAmplifyServerContext.ts +84 -0
- package/src/amplify-astro-adapter/errors.test.ts +115 -0
- package/src/amplify-astro-adapter/errors.ts +105 -0
- package/src/amplify-astro-adapter/globalSettings.test.ts +78 -0
- package/src/amplify-astro-adapter/globalSettings.ts +16 -0
- package/src/amplify-astro-adapter/index.ts +14 -0
- package/src/amplify-astro-adapter/types.ts +55 -0
- package/src/auth/auth.md +178 -0
- package/src/auth/index.test.ts +180 -0
- package/src/auth/index.ts +294 -0
- package/src/constants/constants.md +132 -0
- package/src/constants/index.test.ts +116 -0
- package/src/constants/index.ts +98 -0
- package/src/core-exports.property.test.ts +186 -0
- package/src/errors/errors.md +177 -0
- package/src/errors/index.test.ts +153 -0
- package/src/errors/index.ts +134 -0
- package/src/index.ts +65 -0
- package/src/routes/index.ts +225 -0
- package/src/routes/routes.md +189 -0
- package/src/types/index.ts +94 -0
- package/src/types/types.md +144 -0
- package/src/utils/index.test.ts +257 -0
- package/src/utils/index.ts +112 -0
- package/src/utils/logger.ts +88 -0
- package/src/utils/utils.md +199 -0
- package/src/workspace.property.test.ts +235 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @htlkg/core
|
|
2
|
+
|
|
3
|
+
Core utilities, types, authentication, and constants for Hotelinking applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @htlkg/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Modules
|
|
12
|
+
|
|
13
|
+
### [Amplify Astro Adapter](src/amplify-astro-adapter/amplify-astro-adapter.md)
|
|
14
|
+
Server-side authentication support for Astro with AWS Amplify. Cookie-based auth context for SSR.
|
|
15
|
+
|
|
16
|
+
### [Auth](src/auth/auth.md)
|
|
17
|
+
User authentication functions for server-side and client-side. Cognito integration with role-based access.
|
|
18
|
+
|
|
19
|
+
### [Constants](src/constants/constants.md)
|
|
20
|
+
Centralized constants for routes, products, permissions, and user roles.
|
|
21
|
+
|
|
22
|
+
### [Errors](src/errors/errors.md)
|
|
23
|
+
Standardized error classes: `AppError`, `AuthError`, `ValidationError`, `NotFoundError`.
|
|
24
|
+
|
|
25
|
+
### [Routes](src/routes/routes.md)
|
|
26
|
+
Type-safe route definitions with parameter interpolation. Eliminates string literals.
|
|
27
|
+
|
|
28
|
+
### [Types](src/types/types.md)
|
|
29
|
+
Core TypeScript interfaces: `Brand`, `Account`, `User`, `Product`, `ProductInstance`.
|
|
30
|
+
|
|
31
|
+
### [Utils](src/utils/utils.md)
|
|
32
|
+
Common utilities: `logger`, `formatDate`, `truncateText`, `groupBy`, `debounce`, `throttle`.
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// Authentication
|
|
38
|
+
import { getUser, hasAccessToBrand } from '@htlkg/core/auth';
|
|
39
|
+
|
|
40
|
+
// Type-safe routes
|
|
41
|
+
import { adminRoutes, buildUrl } from '@htlkg/core/routes';
|
|
42
|
+
|
|
43
|
+
// Constants
|
|
44
|
+
import { PERMISSIONS, USER_ROLES } from '@htlkg/core/constants';
|
|
45
|
+
|
|
46
|
+
// Error handling
|
|
47
|
+
import { NotFoundError, ValidationError } from '@htlkg/core/errors';
|
|
48
|
+
|
|
49
|
+
// Utilities
|
|
50
|
+
import { formatDate, debounce } from '@htlkg/core/utils';
|
|
51
|
+
```
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
|
+
import * as astro from 'astro';
|
|
3
|
+
import { CookieStorage } from 'aws-amplify/adapter-core';
|
|
4
|
+
export { c as createLogger, l as logger } from '../logger-BTW3fOeM.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Amplify configuration structure matching amplify_outputs.json format
|
|
8
|
+
*/
|
|
9
|
+
type AstroAmplifyConfig = ResourcesConfig;
|
|
10
|
+
declare namespace AstroServer {
|
|
11
|
+
type RuntimeCookieOptions = CookieStorage.SetCookieOptions & {
|
|
12
|
+
domain?: string;
|
|
13
|
+
};
|
|
14
|
+
interface RuntimeOptions {
|
|
15
|
+
cookies?: RuntimeCookieOptions;
|
|
16
|
+
}
|
|
17
|
+
interface AstroComponentContext {
|
|
18
|
+
cookies: astro.AstroGlobal['cookies'];
|
|
19
|
+
request: Request;
|
|
20
|
+
}
|
|
21
|
+
interface APIEndpointContext {
|
|
22
|
+
cookies: astro.APIContext['cookies'];
|
|
23
|
+
request: Request;
|
|
24
|
+
}
|
|
25
|
+
type ServerContext = AstroComponentContext | APIEndpointContext | null;
|
|
26
|
+
interface GlobalSettings {
|
|
27
|
+
setRuntimeOptions(opts: RuntimeOptions): void;
|
|
28
|
+
getRuntimeOptions(): RuntimeOptions;
|
|
29
|
+
enableServerSideAuth(): void;
|
|
30
|
+
isServerSideAuthEnabled(): boolean;
|
|
31
|
+
setIsSSLOrigin(val: boolean): void;
|
|
32
|
+
isSSLOrigin(): boolean;
|
|
33
|
+
}
|
|
34
|
+
type RunOperationWithContext = <T>(input: {
|
|
35
|
+
astroServerContext: ServerContext;
|
|
36
|
+
operation: (contextSpec: unknown) => Promise<T>;
|
|
37
|
+
}) => Promise<T>;
|
|
38
|
+
interface CreateServerRunnerInput {
|
|
39
|
+
config: ResourcesConfig;
|
|
40
|
+
runtimeOptions?: RuntimeOptions;
|
|
41
|
+
}
|
|
42
|
+
interface CreateServerRunnerOutput {
|
|
43
|
+
runWithAmplifyServerContext: RunOperationWithContext;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a function that runs operations within the Amplify server context.
|
|
49
|
+
*
|
|
50
|
+
* IMPORTANT: Pass globalSettings explicitly to avoid module singleton issues
|
|
51
|
+
* when using linked packages or different bundling contexts.
|
|
52
|
+
*/
|
|
53
|
+
declare const createRunWithAmplifyServerContext: ({ config: resourcesConfig, globalSettings, }: {
|
|
54
|
+
config: ResourcesConfig;
|
|
55
|
+
globalSettings?: AstroServer.GlobalSettings;
|
|
56
|
+
}) => AstroServer.RunOperationWithContext;
|
|
57
|
+
|
|
58
|
+
declare function createCookieStorageAdapterFromAstroContext(astroServerContext: AstroServer.ServerContext): Promise<CookieStorage.Adapter>;
|
|
59
|
+
|
|
60
|
+
declare const globalSettings: AstroServer.GlobalSettings;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Error classes for adapter-specific errors
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Base error class for Amplify Astro Adapter errors
|
|
67
|
+
*/
|
|
68
|
+
declare class AmplifyAstroAdapterError extends Error {
|
|
69
|
+
readonly code: string;
|
|
70
|
+
readonly recoverySuggestion?: string;
|
|
71
|
+
constructor(message: string, code: string, recoverySuggestion?: string);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Error codes for different types of adapter errors
|
|
75
|
+
*/
|
|
76
|
+
declare const ErrorCodes: {
|
|
77
|
+
readonly CONFIG_MISSING: "CONFIG_MISSING";
|
|
78
|
+
readonly AUTH_FAILED: "AUTH_FAILED";
|
|
79
|
+
readonly COOKIE_ERROR: "COOKIE_ERROR";
|
|
80
|
+
readonly GRAPHQL_ERROR: "GRAPHQL_ERROR";
|
|
81
|
+
readonly CONTEXT_CREATION_FAILED: "CONTEXT_CREATION_FAILED";
|
|
82
|
+
readonly TOKEN_REFRESH_FAILED: "TOKEN_REFRESH_FAILED";
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Creates a configuration missing error
|
|
86
|
+
*/
|
|
87
|
+
declare function createConfigMissingError(missingConfig: string): AmplifyAstroAdapterError;
|
|
88
|
+
/**
|
|
89
|
+
* Creates an authentication failed error
|
|
90
|
+
*/
|
|
91
|
+
declare function createAuthFailedError(reason: string): AmplifyAstroAdapterError;
|
|
92
|
+
/**
|
|
93
|
+
* Creates a cookie error
|
|
94
|
+
*/
|
|
95
|
+
declare function createCookieError(operation: string, reason: string): AmplifyAstroAdapterError;
|
|
96
|
+
/**
|
|
97
|
+
* Creates a GraphQL error
|
|
98
|
+
*/
|
|
99
|
+
declare function createGraphQLError(operation: string, reason: string): AmplifyAstroAdapterError;
|
|
100
|
+
/**
|
|
101
|
+
* Creates a context creation failed error
|
|
102
|
+
*/
|
|
103
|
+
declare function createContextCreationError(reason: string): AmplifyAstroAdapterError;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a token refresh failed error
|
|
106
|
+
*/
|
|
107
|
+
declare function createTokenRefreshError(reason: string): AmplifyAstroAdapterError;
|
|
108
|
+
|
|
109
|
+
export { AmplifyAstroAdapterError, type AstroAmplifyConfig, AstroServer, ErrorCodes, createAuthFailedError, createConfigMissingError, createContextCreationError, createCookieError, createCookieStorageAdapterFromAstroContext, createGraphQLError, createRunWithAmplifyServerContext, createTokenRefreshError, globalSettings };
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// src/amplify-astro-adapter/createRunWithAmplifyServerContext.ts
|
|
2
|
+
import { sharedInMemoryStorage } from "aws-amplify/utils";
|
|
3
|
+
import {
|
|
4
|
+
createAWSCredentialsAndIdentityIdProvider,
|
|
5
|
+
createKeyValueStorageFromCookieStorageAdapter,
|
|
6
|
+
createUserPoolsTokenProvider,
|
|
7
|
+
runWithAmplifyServerContext as coreRunWithContext
|
|
8
|
+
} from "aws-amplify/adapter-core";
|
|
9
|
+
|
|
10
|
+
// src/amplify-astro-adapter/globalSettings.ts
|
|
11
|
+
var globalSettings = /* @__PURE__ */ (() => {
|
|
12
|
+
let runtimeOptions = {};
|
|
13
|
+
let serverSideAuthEnabled = true;
|
|
14
|
+
let sslOrigin = false;
|
|
15
|
+
return {
|
|
16
|
+
setRuntimeOptions(opts) {
|
|
17
|
+
runtimeOptions = opts ?? {};
|
|
18
|
+
},
|
|
19
|
+
getRuntimeOptions() {
|
|
20
|
+
return runtimeOptions;
|
|
21
|
+
},
|
|
22
|
+
enableServerSideAuth() {
|
|
23
|
+
serverSideAuthEnabled = true;
|
|
24
|
+
},
|
|
25
|
+
isServerSideAuthEnabled() {
|
|
26
|
+
return serverSideAuthEnabled;
|
|
27
|
+
},
|
|
28
|
+
setIsSSLOrigin(v) {
|
|
29
|
+
sslOrigin = v;
|
|
30
|
+
},
|
|
31
|
+
isSSLOrigin() {
|
|
32
|
+
return sslOrigin;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
|
|
37
|
+
// src/utils/logger.ts
|
|
38
|
+
var isDebugEnabled = () => {
|
|
39
|
+
if (typeof process !== "undefined" && process.env) {
|
|
40
|
+
return process.env.DEBUG === "true" || process.env.HTLKG_DEBUG === "true" || process.env.DEBUG === "*";
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
if (typeof import.meta !== "undefined" && import.meta.env) {
|
|
44
|
+
return import.meta.env.DEBUG === "true" || // @ts-ignore
|
|
45
|
+
import.meta.env.HTLKG_DEBUG === "true" || // @ts-ignore
|
|
46
|
+
import.meta.env.DEV === true;
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
var formatMessage = (namespace, message) => {
|
|
53
|
+
return `[${namespace}] ${message}`;
|
|
54
|
+
};
|
|
55
|
+
var logger = {
|
|
56
|
+
/**
|
|
57
|
+
* Debug log - only shown when DEBUG=true
|
|
58
|
+
*/
|
|
59
|
+
debug(namespace, message, ...args) {
|
|
60
|
+
if (isDebugEnabled()) {
|
|
61
|
+
console.log(formatMessage(namespace, message), ...args);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Info log - always shown
|
|
66
|
+
*/
|
|
67
|
+
info(namespace, message, ...args) {
|
|
68
|
+
console.info(formatMessage(namespace, message), ...args);
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Warning log - always shown
|
|
72
|
+
*/
|
|
73
|
+
warn(namespace, message, ...args) {
|
|
74
|
+
console.warn(formatMessage(namespace, message), ...args);
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Error log - always shown
|
|
78
|
+
*/
|
|
79
|
+
error(namespace, message, ...args) {
|
|
80
|
+
console.error(formatMessage(namespace, message), ...args);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var createLogger = (namespace) => ({
|
|
84
|
+
debug: (message, ...args) => logger.debug(namespace, message, ...args),
|
|
85
|
+
info: (message, ...args) => logger.info(namespace, message, ...args),
|
|
86
|
+
warn: (message, ...args) => logger.warn(namespace, message, ...args),
|
|
87
|
+
error: (message, ...args) => logger.error(namespace, message, ...args)
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// src/amplify-astro-adapter/createCookieStorageAdapterFromAstroContext.ts
|
|
91
|
+
var log = createLogger("cookie-storage-adapter");
|
|
92
|
+
function ensureEncodedForJSCookie(name) {
|
|
93
|
+
return encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);
|
|
94
|
+
}
|
|
95
|
+
function parseCookieHeader(cookieHeader) {
|
|
96
|
+
const out = {};
|
|
97
|
+
if (!cookieHeader) return out;
|
|
98
|
+
for (const part of cookieHeader.split(";")) {
|
|
99
|
+
const [rawName, ...rest] = part.trim().split("=");
|
|
100
|
+
const name = decodeURIComponent(rawName || "");
|
|
101
|
+
const value = decodeURIComponent(rest.join("=") || "");
|
|
102
|
+
if (name) out[name] = value;
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function mapSameSite(s) {
|
|
107
|
+
if (s === true) return "strict";
|
|
108
|
+
if (s === false) return "lax";
|
|
109
|
+
if (s === "lax" || s === "strict" || s === "none") return s;
|
|
110
|
+
return void 0;
|
|
111
|
+
}
|
|
112
|
+
async function createCookieStorageAdapterFromAstroContext(astroServerContext) {
|
|
113
|
+
if (astroServerContext === null) {
|
|
114
|
+
log.debug("Context is null, returning no-op adapter");
|
|
115
|
+
return {
|
|
116
|
+
get: () => void 0,
|
|
117
|
+
getAll: () => [],
|
|
118
|
+
set: () => {
|
|
119
|
+
},
|
|
120
|
+
delete: () => {
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const { cookies, request } = astroServerContext;
|
|
125
|
+
const cookieHeader = request?.headers?.get("cookie");
|
|
126
|
+
const headerCookies = parseCookieHeader(cookieHeader ?? null);
|
|
127
|
+
const cookieNames = Object.keys(headerCookies);
|
|
128
|
+
const cognitoCookies = cookieNames.filter((name) => name.includes("CognitoIdentityServiceProvider"));
|
|
129
|
+
log.debug("Available cookies:", cookieNames.length);
|
|
130
|
+
log.debug("Cognito cookies found:", cognitoCookies.length);
|
|
131
|
+
if (cognitoCookies.length > 0) {
|
|
132
|
+
log.debug("Cognito cookie names:", cognitoCookies);
|
|
133
|
+
}
|
|
134
|
+
const adapter = {
|
|
135
|
+
get(name) {
|
|
136
|
+
const encodedName = ensureEncodedForJSCookie(name);
|
|
137
|
+
const v = cookies?.get(encodedName)?.value ?? headerCookies[encodedName] ?? headerCookies[name];
|
|
138
|
+
if (name.includes("accessToken") || name.includes("idToken") || name.includes("refreshToken") || name.includes("LastAuthUser")) {
|
|
139
|
+
log.debug(`get('${name}'): ${v ? "FOUND" : "NOT FOUND"}`);
|
|
140
|
+
}
|
|
141
|
+
return v ? { name, value: v } : void 0;
|
|
142
|
+
},
|
|
143
|
+
getAll() {
|
|
144
|
+
const fromAPI = typeof cookies?.getAll === "function" ? cookies.getAll().map((c) => ({ name: c.name, value: c.value })) : Object.entries(headerCookies).map(([name, value]) => ({ name, value }));
|
|
145
|
+
return fromAPI;
|
|
146
|
+
},
|
|
147
|
+
set(name, value, options) {
|
|
148
|
+
try {
|
|
149
|
+
cookies.set(name, value, {
|
|
150
|
+
...options ?? {},
|
|
151
|
+
sameSite: mapSameSite(options?.sameSite)
|
|
152
|
+
});
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
delete(name) {
|
|
157
|
+
try {
|
|
158
|
+
cookies.delete(name);
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
return adapter;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/amplify-astro-adapter/createRunWithAmplifyServerContext.ts
|
|
167
|
+
var log2 = createLogger("amplify-server-context");
|
|
168
|
+
var createRunWithAmplifyServerContext = ({
|
|
169
|
+
config: resourcesConfig,
|
|
170
|
+
globalSettings: globalSettings2 = globalSettings
|
|
171
|
+
}) => {
|
|
172
|
+
const isServerSideAuthEnabled = globalSettings2.isServerSideAuthEnabled();
|
|
173
|
+
const isSSLOrigin = globalSettings2.isSSLOrigin();
|
|
174
|
+
const setCookieOptions = globalSettings2.getRuntimeOptions().cookies ?? {};
|
|
175
|
+
log2.debug("Settings:", {
|
|
176
|
+
isServerSideAuthEnabled,
|
|
177
|
+
isSSLOrigin,
|
|
178
|
+
hasCookieOptions: Object.keys(setCookieOptions).length > 0
|
|
179
|
+
});
|
|
180
|
+
const mergedSetCookieOptions = {
|
|
181
|
+
...isServerSideAuthEnabled && { httpOnly: true, sameSite: "lax" },
|
|
182
|
+
...setCookieOptions,
|
|
183
|
+
...isServerSideAuthEnabled && { secure: isSSLOrigin },
|
|
184
|
+
path: "/"
|
|
185
|
+
};
|
|
186
|
+
const runWithContext = async ({
|
|
187
|
+
astroServerContext,
|
|
188
|
+
operation
|
|
189
|
+
}) => {
|
|
190
|
+
if (resourcesConfig.Auth) {
|
|
191
|
+
const cookieAdapter = await createCookieStorageAdapterFromAstroContext(astroServerContext);
|
|
192
|
+
const keyValueStorage = astroServerContext === null ? sharedInMemoryStorage : createKeyValueStorageFromCookieStorageAdapter(
|
|
193
|
+
cookieAdapter,
|
|
194
|
+
void 0,
|
|
195
|
+
mergedSetCookieOptions
|
|
196
|
+
);
|
|
197
|
+
const credentialsProvider = createAWSCredentialsAndIdentityIdProvider(
|
|
198
|
+
resourcesConfig.Auth,
|
|
199
|
+
keyValueStorage
|
|
200
|
+
);
|
|
201
|
+
const tokenProvider = createUserPoolsTokenProvider(
|
|
202
|
+
resourcesConfig.Auth,
|
|
203
|
+
keyValueStorage
|
|
204
|
+
);
|
|
205
|
+
return coreRunWithContext(
|
|
206
|
+
resourcesConfig,
|
|
207
|
+
{ Auth: { credentialsProvider, tokenProvider } },
|
|
208
|
+
operation
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return coreRunWithContext(resourcesConfig, {}, operation);
|
|
212
|
+
};
|
|
213
|
+
return runWithContext;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/amplify-astro-adapter/errors.ts
|
|
217
|
+
var AmplifyAstroAdapterError = class _AmplifyAstroAdapterError extends Error {
|
|
218
|
+
code;
|
|
219
|
+
recoverySuggestion;
|
|
220
|
+
constructor(message, code, recoverySuggestion) {
|
|
221
|
+
super(message);
|
|
222
|
+
this.name = "AmplifyAstroAdapterError";
|
|
223
|
+
this.code = code;
|
|
224
|
+
this.recoverySuggestion = recoverySuggestion;
|
|
225
|
+
if (Error.captureStackTrace) {
|
|
226
|
+
Error.captureStackTrace(this, _AmplifyAstroAdapterError);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var ErrorCodes = {
|
|
231
|
+
CONFIG_MISSING: "CONFIG_MISSING",
|
|
232
|
+
AUTH_FAILED: "AUTH_FAILED",
|
|
233
|
+
COOKIE_ERROR: "COOKIE_ERROR",
|
|
234
|
+
GRAPHQL_ERROR: "GRAPHQL_ERROR",
|
|
235
|
+
CONTEXT_CREATION_FAILED: "CONTEXT_CREATION_FAILED",
|
|
236
|
+
TOKEN_REFRESH_FAILED: "TOKEN_REFRESH_FAILED"
|
|
237
|
+
};
|
|
238
|
+
function createConfigMissingError(missingConfig) {
|
|
239
|
+
return new AmplifyAstroAdapterError(
|
|
240
|
+
`Amplify configuration is missing: ${missingConfig}`,
|
|
241
|
+
ErrorCodes.CONFIG_MISSING,
|
|
242
|
+
"Ensure amplify_outputs.json is properly configured and accessible to the adapter"
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
function createAuthFailedError(reason) {
|
|
246
|
+
return new AmplifyAstroAdapterError(
|
|
247
|
+
`Authentication failed: ${reason}`,
|
|
248
|
+
ErrorCodes.AUTH_FAILED,
|
|
249
|
+
"Check that authentication tokens are valid and not expired"
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
function createCookieError(operation, reason) {
|
|
253
|
+
return new AmplifyAstroAdapterError(
|
|
254
|
+
`Cookie ${operation} failed: ${reason}`,
|
|
255
|
+
ErrorCodes.COOKIE_ERROR,
|
|
256
|
+
"Verify cookie data format and ensure cookies are properly set in the response"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
function createGraphQLError(operation, reason) {
|
|
260
|
+
return new AmplifyAstroAdapterError(
|
|
261
|
+
`GraphQL ${operation} failed: ${reason}`,
|
|
262
|
+
ErrorCodes.GRAPHQL_ERROR,
|
|
263
|
+
"Check network connectivity and GraphQL schema configuration"
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
function createContextCreationError(reason) {
|
|
267
|
+
return new AmplifyAstroAdapterError(
|
|
268
|
+
`Server context creation failed: ${reason}`,
|
|
269
|
+
ErrorCodes.CONTEXT_CREATION_FAILED,
|
|
270
|
+
"Verify Amplify configuration and authentication setup"
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
function createTokenRefreshError(reason) {
|
|
274
|
+
return new AmplifyAstroAdapterError(
|
|
275
|
+
`Token refresh failed: ${reason}`,
|
|
276
|
+
ErrorCodes.TOKEN_REFRESH_FAILED,
|
|
277
|
+
"User may need to re-authenticate or check refresh token validity"
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
export {
|
|
281
|
+
AmplifyAstroAdapterError,
|
|
282
|
+
ErrorCodes,
|
|
283
|
+
createAuthFailedError,
|
|
284
|
+
createConfigMissingError,
|
|
285
|
+
createContextCreationError,
|
|
286
|
+
createCookieError,
|
|
287
|
+
createCookieStorageAdapterFromAstroContext,
|
|
288
|
+
createGraphQLError,
|
|
289
|
+
createLogger,
|
|
290
|
+
createRunWithAmplifyServerContext,
|
|
291
|
+
createTokenRefreshError,
|
|
292
|
+
globalSettings,
|
|
293
|
+
logger
|
|
294
|
+
};
|
|
295
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/amplify-astro-adapter/createRunWithAmplifyServerContext.ts","../../src/amplify-astro-adapter/globalSettings.ts","../../src/utils/logger.ts","../../src/amplify-astro-adapter/createCookieStorageAdapterFromAstroContext.ts","../../src/amplify-astro-adapter/errors.ts"],"sourcesContent":["import type { ResourcesConfig } from 'aws-amplify';\nimport { sharedInMemoryStorage } from 'aws-amplify/utils';\nimport {\n createAWSCredentialsAndIdentityIdProvider,\n createKeyValueStorageFromCookieStorageAdapter,\n createUserPoolsTokenProvider,\n runWithAmplifyServerContext as coreRunWithContext,\n} from 'aws-amplify/adapter-core';\n\nimport type { AstroServer } from './types';\nimport { globalSettings as defaultGlobalSettings } from './globalSettings';\nimport { createCookieStorageAdapterFromAstroContext } from './createCookieStorageAdapterFromAstroContext';\nimport { createLogger } from '../utils/logger';\n\nconst log = createLogger('amplify-server-context');\n\n/**\n * Creates a function that runs operations within the Amplify server context.\n *\n * IMPORTANT: Pass globalSettings explicitly to avoid module singleton issues\n * when using linked packages or different bundling contexts.\n */\nexport const createRunWithAmplifyServerContext = ({\n config: resourcesConfig,\n globalSettings = defaultGlobalSettings,\n}: {\n config: ResourcesConfig;\n globalSettings?: AstroServer.GlobalSettings;\n}): AstroServer.RunOperationWithContext => {\n const isServerSideAuthEnabled = globalSettings.isServerSideAuthEnabled();\n const isSSLOrigin = globalSettings.isSSLOrigin();\n const setCookieOptions = globalSettings.getRuntimeOptions().cookies ?? {};\n\n log.debug('Settings:', {\n isServerSideAuthEnabled,\n isSSLOrigin,\n hasCookieOptions: Object.keys(setCookieOptions).length > 0,\n });\n \n const mergedSetCookieOptions = {\n ...(isServerSideAuthEnabled && { httpOnly: true, sameSite: 'lax' as const }),\n ...setCookieOptions,\n ...(isServerSideAuthEnabled && { secure: isSSLOrigin }),\n path: '/',\n };\n\n const runWithContext: AstroServer.RunOperationWithContext = async ({\n astroServerContext,\n operation,\n }) => {\n if (resourcesConfig.Auth) {\n const cookieAdapter = await createCookieStorageAdapterFromAstroContext(astroServerContext);\n \n const keyValueStorage =\n astroServerContext === null\n ? sharedInMemoryStorage\n : createKeyValueStorageFromCookieStorageAdapter(\n cookieAdapter,\n undefined,\n mergedSetCookieOptions\n );\n\n const credentialsProvider = createAWSCredentialsAndIdentityIdProvider(\n resourcesConfig.Auth,\n keyValueStorage\n );\n \n const tokenProvider = createUserPoolsTokenProvider(\n resourcesConfig.Auth,\n keyValueStorage\n );\n\n return coreRunWithContext(\n resourcesConfig,\n { Auth: { credentialsProvider, tokenProvider } },\n operation\n );\n }\n\n return coreRunWithContext(resourcesConfig, {}, operation);\n };\n\n return runWithContext;\n};\n","import type { AstroServer } from './types';\n\nexport const globalSettings: AstroServer.GlobalSettings = (() => {\n let runtimeOptions: AstroServer.RuntimeOptions = {};\n let serverSideAuthEnabled = true;\n let sslOrigin = false;\n\n return {\n setRuntimeOptions(opts) { runtimeOptions = opts ?? {}; },\n getRuntimeOptions() { return runtimeOptions; },\n enableServerSideAuth() { serverSideAuthEnabled = true; },\n isServerSideAuthEnabled() { return serverSideAuthEnabled; },\n setIsSSLOrigin(v: boolean) { sslOrigin = v; },\n isSSLOrigin() { return sslOrigin; },\n };\n})();\n","/**\n * Simple debug logger utility\n * \n * Debug logs are only shown when DEBUG=true or HTLKG_DEBUG=true is set in environment.\n * Info logs are always shown.\n * \n * @example\n * ```typescript\n * import { logger } from '@htlkg/core/utils/logger';\n * \n * logger.debug('server-client', 'Detailed debug info', { data });\n * logger.info('server-client', 'Important info message');\n * logger.warn('server-client', 'Warning message');\n * logger.error('server-client', 'Error occurred', error);\n * ```\n */\n\ntype LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\nconst isDebugEnabled = (): boolean => {\n // Check Node.js environment variables\n if (typeof process !== 'undefined' && process.env) {\n return process.env.DEBUG === 'true' || \n process.env.HTLKG_DEBUG === 'true' ||\n process.env.DEBUG === '*';\n }\n // Browser/Vite environment - check for DEV mode\n try {\n // @ts-ignore - import.meta.env is Vite-specific\n if (typeof import.meta !== 'undefined' && import.meta.env) {\n // @ts-ignore\n return import.meta.env.DEBUG === 'true' || \n // @ts-ignore\n import.meta.env.HTLKG_DEBUG === 'true' ||\n // @ts-ignore\n import.meta.env.DEV === true;\n }\n } catch {\n // Ignore errors accessing import.meta\n }\n return false;\n};\n\nconst formatMessage = (namespace: string, message: string): string => {\n return `[${namespace}] ${message}`;\n};\n\nexport const logger = {\n /**\n * Debug log - only shown when DEBUG=true\n */\n debug(namespace: string, message: string, ...args: unknown[]): void {\n if (isDebugEnabled()) {\n console.log(formatMessage(namespace, message), ...args);\n }\n },\n\n /**\n * Info log - always shown\n */\n info(namespace: string, message: string, ...args: unknown[]): void {\n console.info(formatMessage(namespace, message), ...args);\n },\n\n /**\n * Warning log - always shown\n */\n warn(namespace: string, message: string, ...args: unknown[]): void {\n console.warn(formatMessage(namespace, message), ...args);\n },\n\n /**\n * Error log - always shown\n */\n error(namespace: string, message: string, ...args: unknown[]): void {\n console.error(formatMessage(namespace, message), ...args);\n },\n};\n\n/**\n * Create a namespaced logger for a specific module\n */\nexport const createLogger = (namespace: string) => ({\n debug: (message: string, ...args: unknown[]) => logger.debug(namespace, message, ...args),\n info: (message: string, ...args: unknown[]) => logger.info(namespace, message, ...args),\n warn: (message: string, ...args: unknown[]) => logger.warn(namespace, message, ...args),\n error: (message: string, ...args: unknown[]) => logger.error(namespace, message, ...args),\n});\n","import type { CookieStorage } from 'aws-amplify/adapter-core';\nimport type { AstroServer } from './types';\nimport { createLogger } from '../utils/logger';\n\nconst log = createLogger('cookie-storage-adapter');\n\n// Ensures the cookie names are encoded in order to look up the cookie store\n// that is manipulated by js-cookie on the client side.\n// Details of the js-cookie encoding behavior see:\n// https://github.com/js-cookie/js-cookie#encoding\n// The implementation is borrowed from js-cookie without escaping `[()]` as\n// we are not using those chars in the auth keys.\nfunction ensureEncodedForJSCookie(name: string): string {\n return encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent);\n}\n\nfunction parseCookieHeader(cookieHeader: string | null) {\n const out: Record<string, string> = {};\n if (!cookieHeader) return out;\n for (const part of cookieHeader.split(';')) {\n const [rawName, ...rest] = part.trim().split('=');\n const name = decodeURIComponent(rawName || '');\n const value = decodeURIComponent(rest.join('=') || '');\n if (name) out[name] = value;\n }\n return out;\n}\n\nfunction mapSameSite(\n s: CookieStorage.SetCookieOptions['sameSite']\n): 'lax' | 'strict' | 'none' | undefined {\n if (s === true) return 'strict';\n if (s === false) return 'lax';\n if (s === 'lax' || s === 'strict' || s === 'none') return s;\n return undefined;\n}\n\nexport async function createCookieStorageAdapterFromAstroContext(\n astroServerContext: AstroServer.ServerContext\n): Promise<CookieStorage.Adapter> {\n if (astroServerContext === null) {\n log.debug('Context is null, returning no-op adapter');\n return {\n get: () => undefined,\n getAll: () => [],\n set: () => {},\n delete: () => {},\n };\n }\n\n const { cookies, request } = astroServerContext;\n const cookieHeader = request?.headers?.get('cookie');\n const headerCookies = parseCookieHeader(cookieHeader ?? null);\n\n // Debug: Log available cookies (names only for security)\n const cookieNames = Object.keys(headerCookies);\n const cognitoCookies = cookieNames.filter(name => name.includes('CognitoIdentityServiceProvider'));\n log.debug('Available cookies:', cookieNames.length);\n log.debug('Cognito cookies found:', cognitoCookies.length);\n if (cognitoCookies.length > 0) {\n log.debug('Cognito cookie names:', cognitoCookies);\n }\n\n const adapter: CookieStorage.Adapter = {\n get(name) {\n const encodedName = ensureEncodedForJSCookie(name);\n const v = cookies?.get(encodedName)?.value ?? headerCookies[encodedName] ?? headerCookies[name];\n // Debug: Log token lookups (only for auth-related cookies)\n if (name.includes('accessToken') || name.includes('idToken') || name.includes('refreshToken') || name.includes('LastAuthUser')) {\n log.debug(`get('${name}'): ${v ? 'FOUND' : 'NOT FOUND'}`);\n }\n return v ? { name, value: v } : undefined;\n },\n getAll() {\n const fromAPI =\n (typeof (cookies as any)?.getAll === 'function'\n ? (cookies as any).getAll().map((c: any) => ({ name: c.name, value: c.value }))\n : Object.entries(headerCookies).map(([name, value]) => ({ name, value })));\n return fromAPI;\n },\n set(name, value, options) {\n try {\n (cookies as any).set(name, value, {\n ...(options ?? {}),\n sameSite: mapSameSite(options?.sameSite),\n });\n } catch {}\n },\n delete(name: string) {\n try {\n (cookies as any).delete(name);\n } catch {}\n },\n };\n\n return adapter;\n}\n","/**\n * Error classes for adapter-specific errors\n */\n\n/**\n * Base error class for Amplify Astro Adapter errors\n */\nexport class AmplifyAstroAdapterError extends Error {\n public readonly code: string;\n public readonly recoverySuggestion?: string;\n\n constructor(\n message: string,\n code: string,\n recoverySuggestion?: string\n ) {\n super(message);\n this.name = 'AmplifyAstroAdapterError';\n this.code = code;\n this.recoverySuggestion = recoverySuggestion;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, AmplifyAstroAdapterError);\n }\n }\n}\n\n/**\n * Error codes for different types of adapter errors\n */\nexport const ErrorCodes = {\n CONFIG_MISSING: 'CONFIG_MISSING',\n AUTH_FAILED: 'AUTH_FAILED',\n COOKIE_ERROR: 'COOKIE_ERROR',\n GRAPHQL_ERROR: 'GRAPHQL_ERROR',\n CONTEXT_CREATION_FAILED: 'CONTEXT_CREATION_FAILED',\n TOKEN_REFRESH_FAILED: 'TOKEN_REFRESH_FAILED',\n} as const;\n\n/**\n * Creates a configuration missing error\n */\nexport function createConfigMissingError(missingConfig: string): AmplifyAstroAdapterError {\n return new AmplifyAstroAdapterError(\n `Amplify configuration is missing: ${missingConfig}`,\n ErrorCodes.CONFIG_MISSING,\n 'Ensure amplify_outputs.json is properly configured and accessible to the adapter'\n );\n}\n\n/**\n * Creates an authentication failed error\n */\nexport function createAuthFailedError(reason: string): AmplifyAstroAdapterError {\n return new AmplifyAstroAdapterError(\n `Authentication failed: ${reason}`,\n ErrorCodes.AUTH_FAILED,\n 'Check that authentication tokens are valid and not expired'\n );\n}\n\n/**\n * Creates a cookie error\n */\nexport function createCookieError(operation: string, reason: string): AmplifyAstroAdapterError {\n return new AmplifyAstroAdapterError(\n `Cookie ${operation} failed: ${reason}`,\n ErrorCodes.COOKIE_ERROR,\n 'Verify cookie data format and ensure cookies are properly set in the response'\n );\n}\n\n/**\n * Creates a GraphQL error\n */\nexport function createGraphQLError(operation: string, reason: string): AmplifyAstroAdapterError {\n return new AmplifyAstroAdapterError(\n `GraphQL ${operation} failed: ${reason}`,\n ErrorCodes.GRAPHQL_ERROR,\n 'Check network connectivity and GraphQL schema configuration'\n );\n}\n\n/**\n * Creates a context creation failed error\n */\nexport function createContextCreationError(reason: string): AmplifyAstroAdapterError {\n return new AmplifyAstroAdapterError(\n `Server context creation failed: ${reason}`,\n ErrorCodes.CONTEXT_CREATION_FAILED,\n 'Verify Amplify configuration and authentication setup'\n );\n}\n\n/**\n * Creates a token refresh failed error\n */\nexport function createTokenRefreshError(reason: string): AmplifyAstroAdapterError {\n return new AmplifyAstroAdapterError(\n `Token refresh failed: ${reason}`,\n ErrorCodes.TOKEN_REFRESH_FAILED,\n 'User may need to re-authenticate or check refresh token validity'\n );\n}\n"],"mappings":";AACA,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAA+B;AAAA,OAC1B;;;ACLA,IAAM,iBAA8C,uBAAM;AAC/D,MAAI,iBAA6C,CAAC;AAClD,MAAI,wBAAwB;AAC5B,MAAI,YAAY;AAEhB,SAAO;AAAA,IACL,kBAAkB,MAAM;AAAE,uBAAiB,QAAQ,CAAC;AAAA,IAAG;AAAA,IACvD,oBAAoB;AAAE,aAAO;AAAA,IAAgB;AAAA,IAC7C,uBAAuB;AAAE,8BAAwB;AAAA,IAAM;AAAA,IACvD,0BAA0B;AAAE,aAAO;AAAA,IAAuB;AAAA,IAC1D,eAAe,GAAY;AAAE,kBAAY;AAAA,IAAG;AAAA,IAC5C,cAAc;AAAE,aAAO;AAAA,IAAW;AAAA,EACpC;AACF,GAAG;;;ACIH,IAAM,iBAAiB,MAAe;AAEpC,MAAI,OAAO,YAAY,eAAe,QAAQ,KAAK;AACjD,WAAO,QAAQ,IAAI,UAAU,UACtB,QAAQ,IAAI,gBAAgB,UAC5B,QAAQ,IAAI,UAAU;AAAA,EAC/B;AAEA,MAAI;AAEF,QAAI,OAAO,gBAAgB,eAAe,YAAY,KAAK;AAEzD,aAAO,YAAY,IAAI,UAAU;AAAA,MAE1B,YAAY,IAAI,gBAAgB;AAAA,MAEhC,YAAY,IAAI,QAAQ;AAAA,IACjC;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAEA,IAAM,gBAAgB,CAAC,WAAmB,YAA4B;AACpE,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AS,kBAAkB,WAAmB,QAA0C;AAC7F,SAAO,IAAI;AAAA,IACT,UAAU,SAAS,YAAY,MAAM;AAAA,IACrC,WAAW;AAAA,IACX;AAAA,EACF;AACF;AAKO,SAAS,mBAAmB,WAAmB,QAA0C;AAC9F,SAAO,IAAI;AAAA,IACT,WAAW,SAAS,YAAY,MAAM;AAAA,IACtC,WAAW;AAAA,IACX;AAAA,EACF;AACF;AAKO,SAAS,2BAA2B,QAA0C;AACnF,SAAO,IAAI;AAAA,IACT,mCAAmC,MAAM;AAAA,IACzC,WAAW;AAAA,IACX;AAAA,EACF;AACF;AAKO,SAAS,wBAAwB,QAA0C;AAChF,SAAO,IAAI;AAAA,IACT,yBAAyB,MAAM;AAAA,IAC/B,WAAW;AAAA,IACX;AAAA,EACF;AACF;","names":["log","globalSettings"]}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ interface User {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Get current authenticated user (server-side)
|
|
23
|
-
*
|
|
23
|
+
* Reads Amplify auth cookies from the request and validates the session
|
|
24
24
|
*/
|
|
25
25
|
declare function getUser(context: APIContext): Promise<User | null>;
|
|
26
26
|
/**
|