ts-ag 0.0.1-dev.3 → 1.0.0

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.
Files changed (118) hide show
  1. package/dist/browser.d.ts +1 -0
  2. package/dist/browser.d.ts.map +1 -1
  3. package/dist/browser.js +1 -0
  4. package/dist/cognito/client.d.ts +6 -0
  5. package/dist/cognito/client.d.ts.map +1 -0
  6. package/dist/cognito/client.js +10 -0
  7. package/dist/cognito/errors.d.ts +95 -0
  8. package/dist/cognito/errors.d.ts.map +1 -0
  9. package/dist/cognito/errors.js +128 -0
  10. package/dist/cognito/index.d.ts +5 -0
  11. package/dist/cognito/index.d.ts.map +1 -0
  12. package/dist/cognito/index.js +4 -0
  13. package/dist/cognito/password.d.ts +53 -0
  14. package/dist/cognito/password.d.ts.map +1 -0
  15. package/dist/cognito/password.js +161 -0
  16. package/dist/cognito/user.d.ts +14 -0
  17. package/dist/cognito/user.d.ts.map +1 -0
  18. package/dist/cognito/user.js +34 -0
  19. package/dist/dynamo/errors.d.ts +9 -0
  20. package/dist/dynamo/errors.d.ts.map +1 -0
  21. package/dist/dynamo/errors.js +7 -0
  22. package/dist/dynamo/index.d.ts +2 -0
  23. package/dist/dynamo/index.d.ts.map +1 -0
  24. package/dist/dynamo/index.js +1 -0
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +6 -0
  28. package/dist/lambda/authentication.d.ts +2 -0
  29. package/dist/lambda/authentication.d.ts.map +1 -0
  30. package/dist/lambda/authentication.js +1 -0
  31. package/dist/lambda/client-types.d.ts +19 -19
  32. package/dist/lambda/client-types.d.ts.map +1 -1
  33. package/dist/lambda/client-types.js +9 -1
  34. package/dist/lambda/client.d.ts.map +1 -1
  35. package/dist/lambda/client.js +7 -2
  36. package/dist/lambda/errors.d.ts +19 -19
  37. package/dist/lambda/errors.d.ts.map +1 -1
  38. package/dist/lambda/errors.js +12 -12
  39. package/dist/lambda/handlerUtils.d.ts +8 -3
  40. package/dist/lambda/handlerUtils.d.ts.map +1 -1
  41. package/dist/lambda/handlerUtils.js +3 -2
  42. package/dist/lambda/index.d.ts +1 -0
  43. package/dist/lambda/index.d.ts.map +1 -1
  44. package/dist/lambda/index.js +2 -0
  45. package/dist/lambda/response.d.ts +48 -95
  46. package/dist/lambda/response.d.ts.map +1 -1
  47. package/dist/lambda/response.js +42 -18
  48. package/dist/lambda/server/authentication.d.ts +10 -0
  49. package/dist/lambda/server/authentication.d.ts.map +1 -0
  50. package/dist/lambda/server/authentication.js +24 -0
  51. package/dist/s3/client.d.ts +6 -0
  52. package/dist/s3/client.d.ts.map +1 -0
  53. package/dist/s3/client.js +7 -0
  54. package/dist/s3/errors.d.ts +7 -0
  55. package/dist/s3/errors.d.ts.map +1 -0
  56. package/dist/s3/errors.js +6 -0
  57. package/dist/s3/index.d.ts +5 -0
  58. package/dist/s3/index.d.ts.map +1 -0
  59. package/dist/s3/index.js +4 -0
  60. package/dist/s3/object.d.ts +17 -0
  61. package/dist/s3/object.d.ts.map +1 -0
  62. package/dist/s3/object.js +32 -0
  63. package/dist/s3/signedUrl.d.ts +3 -0
  64. package/dist/s3/signedUrl.d.ts.map +1 -0
  65. package/dist/s3/signedUrl.js +3 -0
  66. package/dist/scripts/clean.js +30 -59
  67. package/dist/scripts/ts-alias.d.ts +3 -0
  68. package/dist/scripts/ts-alias.d.ts.map +1 -0
  69. package/dist/scripts/ts-alias.js +167 -0
  70. package/dist/ses/errors.d.ts +4 -0
  71. package/dist/ses/errors.d.ts.map +1 -0
  72. package/dist/ses/errors.js +3 -0
  73. package/dist/ses/index.d.ts +2 -0
  74. package/dist/ses/index.d.ts.map +1 -0
  75. package/dist/ses/index.js +1 -0
  76. package/dist/ts-alias.js +0 -0
  77. package/dist/types/deep.d.ts +24 -0
  78. package/dist/types/deep.d.ts.map +1 -0
  79. package/dist/types/deep.js +1 -0
  80. package/dist/types/index.d.ts +3 -0
  81. package/dist/types/index.d.ts.map +1 -0
  82. package/dist/types/index.js +2 -0
  83. package/dist/types/safe.d.ts +2 -0
  84. package/dist/types/safe.d.ts.map +1 -0
  85. package/dist/types/safe.js +1 -0
  86. package/dist/utils/fs.d.ts +2 -1
  87. package/dist/utils/fs.d.ts.map +1 -1
  88. package/dist/utils/fs.js +3 -1
  89. package/package.json +31 -22
  90. package/src/browser.ts +3 -1
  91. package/src/cognito/client.ts +11 -0
  92. package/src/cognito/errors.ts +175 -0
  93. package/src/cognito/index.ts +5 -0
  94. package/src/cognito/password.ts +233 -0
  95. package/src/cognito/user.ts +46 -0
  96. package/src/dynamo/errors.ts +11 -0
  97. package/src/dynamo/index.ts +1 -0
  98. package/src/index.ts +8 -0
  99. package/src/lambda/client-types.ts +55 -29
  100. package/src/lambda/client.ts +7 -2
  101. package/src/lambda/errors.ts +25 -25
  102. package/src/lambda/handlerUtils.ts +30 -25
  103. package/src/lambda/index.ts +3 -0
  104. package/src/lambda/response.ts +90 -26
  105. package/src/lambda/server/authentication.ts +32 -0
  106. package/src/s3/client.ts +8 -0
  107. package/src/s3/errors.ts +6 -0
  108. package/src/s3/index.ts +6 -0
  109. package/src/s3/object.ts +37 -0
  110. package/src/s3/signedUrl.ts +4 -0
  111. package/src/scripts/clean.ts +34 -68
  112. package/src/ses/errors.ts +3 -0
  113. package/src/ses/index.ts +1 -0
  114. package/src/types/deep.ts +43 -0
  115. package/src/types/index.ts +2 -0
  116. package/src/types/safe.ts +1 -0
  117. package/src/utils/fs.ts +4 -2
  118. /package/src/{ts-alias.ts → scripts/ts-alias.ts} +0 -0
@@ -1,58 +1,58 @@
1
- import type { ErrorBody, SuccessCode, ErrorCode } from './handlerUtils.js';
1
+ import type { ErrorBody, SuccessCode, ErrorCode } from "./handlerUtils.js";
2
2
  /**
3
3
  * Extracts the requestInput type from an API endpoint definition
4
4
  * @template E - Union type of all API endpoints
5
5
  * @template P - Path string literal type (e.g. 'payments/account')
6
6
  * @template M - HTTP method string literal type (e.g. 'GET', 'POST')
7
7
  */
8
- export type ApiInput<E extends ApiEndpoints, P extends E['path'], M extends E['method']> = Extract<E, {
8
+ export type ApiInput<E extends ApiEndpoints, P extends E["path"], M extends E["method"]> = Extract<E, {
9
9
  path: P;
10
10
  method: M;
11
- }>['requestInput'];
11
+ }>["requestInput"];
12
12
  /**
13
13
  * Extracts the requestOutput type from an API endpoint definition
14
14
  * @template E - Union type of all API endpoints
15
15
  * @template P - Path string literal type (e.g. 'payments/account')
16
16
  * @template M - HTTP method string literal type (e.g. 'GET', 'POST')
17
17
  */
18
- export type ApiOutput<E extends ApiEndpoints, P extends E['path'], M extends E['method']> = Extract<E, {
18
+ export type ApiOutput<E extends ApiEndpoints, P extends E["path"], M extends E["method"]> = Extract<E, {
19
19
  path: P;
20
20
  method: M;
21
- }>['requestOutput'];
21
+ }>["requestOutput"];
22
22
  /**
23
23
  * Extracts the response type from an API endpoint definition
24
24
  * @template E - Union type of all API endpoints
25
25
  * @template P - Path string literal type (e.g. 'payments/account')
26
26
  * @template M - HTTP method string literal type (e.g. 'GET', 'POST')
27
27
  */
28
- export type ApiResponse<E extends ApiEndpoints, P extends E['path'], M extends E['method']> = Extract<E, {
28
+ export type ApiResponse<E extends ApiEndpoints, P extends E["path"], M extends E["method"]> = Extract<E, {
29
29
  path: P;
30
30
  method: M;
31
- }>['response'];
31
+ }>["response"];
32
32
  /**
33
33
  * Extracts the sucessful body type from an API endpoint definition
34
34
  * @template E - Union type of all API endpoints
35
35
  * @template P - Path string literal type (e.g. 'payments/account')
36
36
  * @template M - HTTP method string literal type (e.g. 'GET', 'POST')
37
37
  */
38
- export type ApiSuccessBody<E extends ApiEndpoints, P extends E['path'], M extends E['method']> = Extract<Extract<E, {
38
+ export type ApiSuccessBody<E extends ApiEndpoints, P extends E["path"], M extends E["method"]> = Extract<Extract<E, {
39
39
  path: P;
40
40
  method: M;
41
- }>['response'], {
41
+ }>["response"], {
42
42
  status: SuccessCode;
43
- }>['json'] extends () => Promise<infer R> ? R : unknown;
43
+ }>["json"] extends () => Promise<infer R> ? R : unknown;
44
44
  /**
45
45
  * Extracts the sucessful body type from an API endpoint definition
46
46
  * @template E - Union type of all API endpoints
47
47
  * @template P - Path string literal type (e.g. 'payments/account')
48
48
  * @template M - HTTP method string literal type (e.g. 'GET', 'POST')
49
49
  */
50
- export type ApiErrorBody<E extends ApiEndpoints, P extends E['path'], M extends E['method']> = Extract<Extract<E, {
50
+ export type ApiErrorBody<E extends ApiEndpoints, P extends E["path"], M extends E["method"]> = Extract<Extract<E, {
51
51
  path: P;
52
52
  method: M;
53
- }>['response'], {
53
+ }>["response"], {
54
54
  status: ErrorCode;
55
- }>['json'] extends () => Promise<infer R> ? R : unknown;
55
+ }>["json"] extends () => Promise<infer R> ? R : unknown;
56
56
  /**
57
57
  * Converts a RawApiGatewayHandler response type to a fetch like response type.
58
58
  */
@@ -61,19 +61,19 @@ type ConvertToFetch<T> = T extends {
61
61
  body: object;
62
62
  headers: object;
63
63
  } ? {
64
- ok: T['statusCode'] extends SuccessCode ? true : false;
65
- json: () => Promise<T['body']>;
66
- status: T['statusCode'];
64
+ ok: T["statusCode"] extends SuccessCode ? true : false;
65
+ json: () => Promise<T["body"]>;
66
+ status: T["statusCode"];
67
67
  } : T;
68
- export type CleanResponse = Omit<Response, 'status' | 'ok' | 'json'>;
68
+ export type CleanResponse = Omit<Response, "status" | "ok" | "json">;
69
69
  export type FetchResponse<T extends (...args: any) => any> = ConvertToFetch<Awaited<ReturnType<T>>> & CleanResponse;
70
70
  export declare const HTTPMethods: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"];
71
71
  export type HTTPMethod = (typeof HTTPMethods)[number];
72
72
  export type ApiEndpoints = {
73
73
  path: string;
74
74
  method: HTTPMethod;
75
- requestInput: Record<string, any>;
76
- requestOutput: object;
75
+ requestInput: Record<string, any> | null;
76
+ requestOutput: object | null;
77
77
  response: FetchResponse<() => Promise<{
78
78
  headers: object;
79
79
  statusCode: SuccessCode;
@@ -1 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------------------------ Proper types ------------------
2
2
  // This is used by createApiRequest and createFormFunction
3
- export const HTTPMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'];
3
+ export const HTTPMethods = [
4
+ "GET",
5
+ "POST",
6
+ "PUT",
7
+ "DELETE",
8
+ "PATCH",
9
+ "OPTIONS",
10
+ "HEAD",
11
+ ];
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lambda/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAwD7E,QAAA,MAAM,WAAW,uEAAwE,CAAC;AAC1F,KAAK,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/C,MAAM,MAAM,kBAAkB,CAAC,GAAG,SAAS,YAAY,IAAI,CACzD,IAAI,SAAS,GAAG,CAAC,MAAM,CAAC,EACxB,MAAM,SAAS,OAAO,CAAC,GAAG,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC,QAAQ,CAAC,EAErD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,EAClC,OAAO,CAAC,EAAE,WAAW,KAClB,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,kBAAkB,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,SAAS,YAAY,EACvD,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAA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 -1,4 +1,5 @@
1
- import { deserialize } from './deserializer.js';
1
+ // import { deserialize } from './deserializer.js';
2
+ import { parse } from 'devalue';
2
3
  import * as v from 'valibot';
3
4
  const bodyMethods = ['POST', 'PUT', 'PATCH'];
4
5
  const queryMethods = ['GET', 'DELETE'];
@@ -34,8 +35,12 @@ async function _apiRequest(path, method, input, schema, environment, apiUrl, hea
34
35
  body: bodyMethods.includes(method) ? JSON.stringify(input) : undefined,
35
36
  credentials: 'include'
36
37
  });
38
+ let retrieved = false;
37
39
  response.json = async () => {
38
- return await deserialize(await response.text(), environment);
40
+ if (retrieved === false) {
41
+ retrieved = response.text();
42
+ }
43
+ return await parse(await retrieved);
39
44
  };
40
45
  return response;
41
46
  }
@@ -6,41 +6,41 @@
6
6
  * The separation means that they can be returned from functions that are certainly run inside a lambda fucntion but theyre not the actual return of the lambda.
7
7
  * Im not sure it this is optimal behaviour and if not we will migrate to only using the errorResponse function
8
8
  */
9
- export declare const badRequestError: (message: string, fieldName?: string, fieldValue?: string) => {
10
- type: "BadRequest";
9
+ export declare const error_lambda_badRequest: (message: string, fieldName?: string, fieldValue?: string) => {
10
+ type: "lambda_badRequest";
11
11
  message: string;
12
12
  fieldName: string | undefined;
13
13
  fieldValue: string | undefined;
14
14
  };
15
- export declare const unauthorizedError: (message: string) => {
16
- type: "Unauthorized";
15
+ export declare const error_lambda_unauthorized: (message: string) => {
16
+ type: "lambda_unauthorized";
17
17
  message: string;
18
18
  };
19
- export declare const forbiddenError: (message: string) => {
20
- type: "Forbidden";
19
+ export declare const error_lambda_forbidden: (message: string) => {
20
+ type: "lambda_forbidden";
21
21
  message: string;
22
22
  };
23
- export declare const notFoundError: (message: string, fieldName?: string, fieldValue?: string) => {
24
- type: "NotFound";
23
+ export declare const error_lambda_notFound: (message: string, fieldName?: string, fieldValue?: string) => {
24
+ type: "lambda_notFound";
25
25
  message: string;
26
26
  fieldName: string | undefined;
27
27
  fieldValue: string | undefined;
28
28
  };
29
- export declare const conflictError: (message: string, fieldName?: string, fieldValue?: string) => {
30
- type: "Conflict";
29
+ export declare const error_lambda_conflict: (message: string, fieldName?: string, fieldValue?: string) => {
30
+ type: "lambda_conflict";
31
31
  message: string;
32
32
  fieldName: string | undefined;
33
33
  fieldValue: string | undefined;
34
34
  };
35
- export declare const internalServerError: (message: string) => {
36
- type: "InternalServerError";
35
+ export declare const error_lambda_internal: (message: string) => {
36
+ type: "lambda_internal";
37
37
  message: string;
38
38
  };
39
- export type BadRequestError = ReturnType<typeof badRequestError>;
40
- export type UnauthorizedError = ReturnType<typeof unauthorizedError>;
41
- export type ForbiddenError = ReturnType<typeof forbiddenError>;
42
- export type NotFoundError = ReturnType<typeof notFoundError>;
43
- export type ConflictError = ReturnType<typeof conflictError>;
44
- export type InternalServerError = ReturnType<typeof internalServerError>;
45
- export type LambdaError = BadRequestError | UnauthorizedError | ForbiddenError | NotFoundError | ConflictError | InternalServerError;
39
+ export type type_error_lambda_badRequest = ReturnType<typeof error_lambda_badRequest>;
40
+ export type type_error_lambda_unauthorized = ReturnType<typeof error_lambda_unauthorized>;
41
+ export type type_error_lambda_forbidden = ReturnType<typeof error_lambda_forbidden>;
42
+ export type type_error_lambda_notFound = ReturnType<typeof error_lambda_notFound>;
43
+ export type type_error_lambda_conflict = ReturnType<typeof error_lambda_conflict>;
44
+ export type type_error_lambda_internal = ReturnType<typeof error_lambda_internal>;
45
+ export type type_error_lambda = type_error_lambda_badRequest | type_error_lambda_unauthorized | type_error_lambda_forbidden | type_error_lambda_notFound | type_error_lambda_conflict | type_error_lambda_internal;
46
46
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lambda/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,YAAY,MAAM,EAAE,aAAa,MAAM;;;;;CAKtF,CAAC;AACH,eAAO,MAAM,iBAAiB,GAAI,SAA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Aa,MAAM;;;;;CAK5F,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,EAAE,YAAY,MAAM,EAAE,aAAa,MAAM;;;;;CAK5F,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM;;;CAGnD,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACtF,MAAM,MAAM,8BAA8B,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC1F,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACpF,MAAM,MAAM,0BAA0B,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAClF,MAAM,MAAM,0BAA0B,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAClF,MAAM,MAAM,0BAA0B,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAElF,MAAM,MAAM,iBAAiB,GACzB,4BAA4B,GAC5B,8BAA8B,GAC9B,2BAA2B,GAC3B,0BAA0B,GAC1B,0BAA0B,GAC1B,0BAA0B,CAAC"}
@@ -6,33 +6,33 @@
6
6
  * The separation means that they can be returned from functions that are certainly run inside a lambda fucntion but theyre not the actual return of the lambda.
7
7
  * Im not sure it this is optimal behaviour and if not we will migrate to only using the errorResponse function
8
8
  */
9
- export const badRequestError = (message, fieldName, fieldValue) => ({
10
- type: 'BadRequest',
9
+ export const error_lambda_badRequest = (message, fieldName, fieldValue) => ({
10
+ type: 'lambda_badRequest',
11
11
  message,
12
12
  fieldName,
13
13
  fieldValue
14
14
  });
15
- export const unauthorizedError = (message) => ({
16
- type: 'Unauthorized',
15
+ export const error_lambda_unauthorized = (message) => ({
16
+ type: 'lambda_unauthorized',
17
17
  message
18
18
  });
19
- export const forbiddenError = (message) => ({
20
- type: 'Forbidden',
19
+ export const error_lambda_forbidden = (message) => ({
20
+ type: 'lambda_forbidden',
21
21
  message
22
22
  });
23
- export const notFoundError = (message, fieldName, fieldValue) => ({
24
- type: 'NotFound',
23
+ export const error_lambda_notFound = (message, fieldName, fieldValue) => ({
24
+ type: 'lambda_notFound',
25
25
  message,
26
26
  fieldName,
27
27
  fieldValue
28
28
  });
29
- export const conflictError = (message, fieldName, fieldValue) => ({
30
- type: 'Conflict',
29
+ export const error_lambda_conflict = (message, fieldName, fieldValue) => ({
30
+ type: 'lambda_conflict',
31
31
  message,
32
32
  fieldName,
33
33
  fieldValue
34
34
  });
35
- export const internalServerError = (message) => ({
36
- type: 'InternalServerError',
35
+ export const error_lambda_internal = (message) => ({
36
+ type: 'lambda_internal',
37
37
  message
38
38
  });
@@ -9,9 +9,9 @@ export type ErrorBody = {
9
9
  };
10
10
  };
11
11
  /**
12
- * A type for the raw proxy result - just using an object not a stirng for the body
12
+ * The error response for the lambda functions to return
13
13
  */
14
- export type RawProxyResultV2 = {
14
+ export type ErrorRawProxyResultV2 = {
15
15
  statusCode: ErrorCode;
16
16
  headers?: {
17
17
  [header: string]: boolean | number | string;
@@ -19,7 +19,8 @@ export type RawProxyResultV2 = {
19
19
  body?: ErrorBody;
20
20
  isBase64Encoded?: boolean | undefined;
21
21
  cookies?: string[] | undefined;
22
- } | {
22
+ };
23
+ export type OkRawProxyResultV2 = {
23
24
  statusCode: SuccessCode;
24
25
  headers?: {
25
26
  [header: string]: boolean | number | string;
@@ -28,6 +29,10 @@ export type RawProxyResultV2 = {
28
29
  isBase64Encoded?: boolean | undefined;
29
30
  cookies?: string[] | undefined;
30
31
  };
32
+ /**
33
+ * A type for the raw proxy result - just using an object not a stirng for the body
34
+ */
35
+ export type RawProxyResultV2 = ErrorRawProxyResultV2 | OkRawProxyResultV2;
31
36
  export type APIGatewayHandler<E> = (event: E, context: Context) => Promise<APIGatewayProxyResultV2>;
32
37
  export type RawApiGatewayHandler<E> = (event: E, context: Context) => Promise<RawProxyResultV2>;
33
38
  /**
@@ -1 +1 @@
1
- {"version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C,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;KAC7C,GACD,SAAS,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAChC,CAAC;AACF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAG1E,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAGpG,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEhG;;;;;;;;;;;;;EAaE;AACF,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAQrF"}
@@ -1,4 +1,5 @@
1
- import { stringify } from './serializer.js';
1
+ // import { stringify } from './serializer.js';
2
+ import { stringify } from 'devalue';
2
3
  /**
3
4
  * Wraps a handler that returns the body as an object rather than a string.
4
5
  *
@@ -18,7 +19,7 @@ export function wrapHandler(handler) {
18
19
  const result = await handler(event, context);
19
20
  return {
20
21
  ...result,
21
- body: result.body ? await stringify(result.body) : undefined
22
+ body: result.body ? stringify(result.body) : undefined
22
23
  };
23
24
  };
24
25
  }
@@ -1,4 +1,5 @@
1
1
  export * from './browser.js';
2
2
  export * from './errors.js';
3
3
  export * from './response.js';
4
+ export * from './server/authentication.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lambda/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lambda/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAG9B,cAAc,4BAA4B,CAAC"}
@@ -1,3 +1,5 @@
1
1
  export * from './browser.js';
2
2
  export * from './errors.js';
3
3
  export * from './response.js';
4
+ // Server
5
+ export * from './server/authentication.js';
@@ -1,127 +1,80 @@
1
1
  import type { SafeParseResult } from 'valibot';
2
- import { type LambdaError } from './errors.js';
3
- /**
4
- * Takes a lambda error and gives an error response suitable to be returned from the lambda handler
5
- */
6
- export declare function errorResponse(e: LambdaError, headers: any): {
7
- headers: any;
2
+ import { type type_error_lambda } from './errors.js';
3
+ import type { ErrorRawProxyResultV2 } from './handlerUtils.js';
4
+ declare function field(obj: {
5
+ fieldName?: string;
6
+ fieldValue?: string;
7
+ }): {
8
+ field?: undefined;
9
+ } | {
10
+ field: {
11
+ name: string;
12
+ value: string;
13
+ };
14
+ };
15
+ export type type_error_response = Omit<ErrorRawProxyResultV2, 'headers' | 'body'> & {
16
+ headers: NonNullable<ErrorRawProxyResultV2['headers']>;
17
+ body: NonNullable<ErrorRawProxyResultV2['body']>;
18
+ };
19
+ export type LambdaErrorResponse<Type extends string = '', Extras extends object | never = never> = {
20
+ headers: Record<string, string>;
8
21
  statusCode: 400;
9
22
  body: {
10
- field?: undefined;
11
- message: string;
12
- } | {
13
- field: {
14
- name: string;
15
- value: string;
16
- };
17
23
  message: string;
18
- };
24
+ type: Type;
25
+ } & ReturnType<typeof field> & Extras;
19
26
  } | {
20
- headers: any;
27
+ headers: Record<string, string>;
21
28
  statusCode: 401;
22
29
  body: {
23
30
  message: string;
24
- };
31
+ type: Type;
32
+ } & Extras;
25
33
  } | {
26
- headers: any;
34
+ headers: Record<string, string>;
27
35
  statusCode: 403;
28
36
  body: {
29
37
  message: string;
30
- };
38
+ type: Type;
39
+ } & Extras;
31
40
  } | {
32
- headers: any;
41
+ headers: Record<string, string>;
33
42
  statusCode: 404;
34
43
  body: {
35
- field?: undefined;
36
- message: string;
37
- } | {
38
- field: {
39
- name: string;
40
- value: string;
41
- };
42
44
  message: string;
43
- };
45
+ type: Type;
46
+ } & ReturnType<typeof field> & Extras;
44
47
  } | {
45
- headers: any;
48
+ headers: Record<string, string>;
46
49
  statusCode: 409;
47
50
  body: {
48
- field?: undefined;
49
51
  message: string;
50
- } | {
51
- field: {
52
- name: string;
53
- value: string;
54
- };
55
- message: string;
56
- };
52
+ type: Type;
53
+ } & ReturnType<typeof field> & Extras;
57
54
  } | {
58
- headers: any;
55
+ headers: Record<string, string>;
59
56
  statusCode: 500;
60
57
  body: {
61
58
  message: string;
62
- };
59
+ type: Type;
60
+ } & Extras;
63
61
  };
62
+ export declare function response_error<Type extends string, Extras extends object | never = never>(e: type_error_lambda, headers: Record<string, string>, type?: Type, extras?: Extras): LambdaErrorResponse<Type, Extras>;
64
63
  /**
65
64
  * Helper function to get a reasonable default error response from a valibot parse result
65
+ * @param res - The output from calling safeParse on the input
66
+ * @param headers - The headers to return in the response
66
67
  */
67
- export declare function valibotErrorResponse(res: Extract<SafeParseResult<any>, {
68
+ export declare function response_valibotError(res: Extract<SafeParseResult<any>, {
68
69
  success: false;
69
- }>, headers: any): {
70
- headers: any;
71
- statusCode: 400;
72
- body: {
73
- field?: undefined;
74
- message: string;
75
- } | {
76
- field: {
77
- name: string;
78
- value: string;
79
- };
80
- message: string;
81
- };
82
- } | {
83
- headers: any;
84
- statusCode: 401;
85
- body: {
86
- message: string;
87
- };
88
- } | {
70
+ }>, headers: any): LambdaErrorResponse<string, never>;
71
+ export declare function response_ok<Body extends {
72
+ message: string;
73
+ }>(body: Body, headers: any, cookies?: string[] | undefined): {
89
74
  headers: any;
90
- statusCode: 403;
91
- body: {
92
- message: string;
93
- };
94
- } | {
95
- headers: any;
96
- statusCode: 404;
97
- body: {
98
- field?: undefined;
99
- message: string;
100
- } | {
101
- field: {
102
- name: string;
103
- value: string;
104
- };
105
- message: string;
106
- };
107
- } | {
108
- headers: any;
109
- statusCode: 409;
110
- body: {
111
- field?: undefined;
112
- message: string;
113
- } | {
114
- field: {
115
- name: string;
116
- value: string;
117
- };
118
- message: string;
119
- };
120
- } | {
121
- headers: any;
122
- statusCode: 500;
123
- body: {
124
- message: string;
125
- };
75
+ cookies: string[] | undefined;
76
+ statusCode: 200;
77
+ body: Body;
126
78
  };
79
+ export {};
127
80
  //# sourceMappingURL=response.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/lambda/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAahE;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsDzD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE;IAAE,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC,EAAE,OAAO,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIxG"}
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/lambda/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAsB,MAAM,mBAAmB,CAAC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