payload-plugin-newsletter 0.6.2 → 0.8.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.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,71 @@
1
- import { Config } from 'payload';
1
+ import { PayloadRequest, Config } from 'payload';
2
2
  import { NewsletterPluginConfig } from './types.cjs';
3
3
 
4
+ interface NextApiRequest {
5
+ cookies?: {
6
+ [key: string]: string;
7
+ };
8
+ headers?: {
9
+ [key: string]: string | string[] | undefined;
10
+ };
11
+ [key: string]: any;
12
+ }
13
+ interface GetServerSidePropsContext {
14
+ req: {
15
+ cookies?: {
16
+ [key: string]: string;
17
+ };
18
+ headers?: {
19
+ [key: string]: string | string[] | undefined;
20
+ };
21
+ [key: string]: any;
22
+ };
23
+ [key: string]: any;
24
+ }
25
+ interface TokenPayload {
26
+ id: string;
27
+ email: string;
28
+ type?: string;
29
+ iat?: number;
30
+ exp?: number;
31
+ }
32
+ /**
33
+ * Extract token from request cookies
34
+ */
35
+ declare const getTokenFromRequest: (req: NextApiRequest | GetServerSidePropsContext["req"] | PayloadRequest) => string | null;
36
+ /**
37
+ * Verify JWT token
38
+ */
39
+ declare const verifyToken: (token: string, secret: string) => TokenPayload | null;
40
+ /**
41
+ * Get authentication state for server-side rendering
42
+ */
43
+ declare const getServerSideAuth: (context: GetServerSidePropsContext, secret?: string) => Promise<{
44
+ subscriber: TokenPayload | null;
45
+ isAuthenticated: boolean;
46
+ }>;
47
+ /**
48
+ * Higher-order function for protecting pages
49
+ */
50
+ declare const requireAuth: <P extends {
51
+ [key: string]: any;
52
+ }>(gssp?: (context: GetServerSidePropsContext) => Promise<{
53
+ props: P;
54
+ }>) => (context: GetServerSidePropsContext) => Promise<{
55
+ redirect: {
56
+ destination: string;
57
+ permanent: boolean;
58
+ };
59
+ props?: undefined;
60
+ } | {
61
+ props: P;
62
+ redirect?: undefined;
63
+ }>;
64
+ /**
65
+ * Check if request has valid authentication
66
+ */
67
+ declare const isAuthenticated: (req: PayloadRequest | NextApiRequest, secret: string) => boolean;
68
+
4
69
  declare module 'payload' {
5
70
  interface BasePayload {
6
71
  newsletterEmailService?: any;
@@ -8,4 +73,4 @@ declare module 'payload' {
8
73
  }
9
74
  declare const newsletterPlugin: (pluginConfig: NewsletterPluginConfig) => (incomingConfig: Config) => Config;
10
75
 
11
- export { newsletterPlugin as default, newsletterPlugin };
76
+ export { newsletterPlugin as default, getServerSideAuth, getTokenFromRequest, isAuthenticated, newsletterPlugin, requireAuth, verifyToken };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,71 @@
1
- import { Config } from 'payload';
1
+ import { PayloadRequest, Config } from 'payload';
2
2
  import { NewsletterPluginConfig } from './types.js';
3
3
 
4
+ interface NextApiRequest {
5
+ cookies?: {
6
+ [key: string]: string;
7
+ };
8
+ headers?: {
9
+ [key: string]: string | string[] | undefined;
10
+ };
11
+ [key: string]: any;
12
+ }
13
+ interface GetServerSidePropsContext {
14
+ req: {
15
+ cookies?: {
16
+ [key: string]: string;
17
+ };
18
+ headers?: {
19
+ [key: string]: string | string[] | undefined;
20
+ };
21
+ [key: string]: any;
22
+ };
23
+ [key: string]: any;
24
+ }
25
+ interface TokenPayload {
26
+ id: string;
27
+ email: string;
28
+ type?: string;
29
+ iat?: number;
30
+ exp?: number;
31
+ }
32
+ /**
33
+ * Extract token from request cookies
34
+ */
35
+ declare const getTokenFromRequest: (req: NextApiRequest | GetServerSidePropsContext["req"] | PayloadRequest) => string | null;
36
+ /**
37
+ * Verify JWT token
38
+ */
39
+ declare const verifyToken: (token: string, secret: string) => TokenPayload | null;
40
+ /**
41
+ * Get authentication state for server-side rendering
42
+ */
43
+ declare const getServerSideAuth: (context: GetServerSidePropsContext, secret?: string) => Promise<{
44
+ subscriber: TokenPayload | null;
45
+ isAuthenticated: boolean;
46
+ }>;
47
+ /**
48
+ * Higher-order function for protecting pages
49
+ */
50
+ declare const requireAuth: <P extends {
51
+ [key: string]: any;
52
+ }>(gssp?: (context: GetServerSidePropsContext) => Promise<{
53
+ props: P;
54
+ }>) => (context: GetServerSidePropsContext) => Promise<{
55
+ redirect: {
56
+ destination: string;
57
+ permanent: boolean;
58
+ };
59
+ props?: undefined;
60
+ } | {
61
+ props: P;
62
+ redirect?: undefined;
63
+ }>;
64
+ /**
65
+ * Check if request has valid authentication
66
+ */
67
+ declare const isAuthenticated: (req: PayloadRequest | NextApiRequest, secret: string) => boolean;
68
+
4
69
  declare module 'payload' {
5
70
  interface BasePayload {
6
71
  newsletterEmailService?: any;
@@ -8,4 +73,4 @@ declare module 'payload' {
8
73
  }
9
74
  declare const newsletterPlugin: (pluginConfig: NewsletterPluginConfig) => (incomingConfig: Config) => Config;
10
75
 
11
- export { newsletterPlugin as default, newsletterPlugin };
76
+ export { newsletterPlugin as default, getServerSideAuth, getTokenFromRequest, isAuthenticated, newsletterPlugin, requireAuth, verifyToken };