lokicms-plugin-stripe 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.
- package/LICENSE +21 -0
- package/README.md +209 -0
- package/package.json +44 -0
- package/src/index.ts +1092 -0
- package/src/stripe-service.ts +552 -0
- package/src/types.ts +214 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Plugin Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Hono } from 'hono';
|
|
6
|
+
import type { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Plugin API Types (from LokiCMS)
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export interface PluginLifecycle {
|
|
13
|
+
onLoad?: () => Promise<void> | void;
|
|
14
|
+
onEnable?: () => Promise<void> | void;
|
|
15
|
+
onDisable?: () => Promise<void> | void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MCPToolDefinition {
|
|
19
|
+
name?: string;
|
|
20
|
+
description: string;
|
|
21
|
+
inputSchema: z.ZodType;
|
|
22
|
+
handler: (args: unknown) => Promise<unknown>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface HookRegistrar {
|
|
26
|
+
on(hookName: string, handler: (payload: unknown) => Promise<unknown> | void, priority?: number): void;
|
|
27
|
+
off(hookName: string, handler: (payload: unknown) => Promise<unknown> | void): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RouteRegistrar {
|
|
31
|
+
register(routes: Hono): void;
|
|
32
|
+
getBasePath(): string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MCPRegistrar {
|
|
36
|
+
registerTool(name: string, tool: MCPToolDefinition): void;
|
|
37
|
+
unregisterTool(name: string): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ContentTypeFieldDefinition {
|
|
41
|
+
name: string;
|
|
42
|
+
label: string;
|
|
43
|
+
type: string;
|
|
44
|
+
required?: boolean;
|
|
45
|
+
description?: string;
|
|
46
|
+
defaultValue?: unknown;
|
|
47
|
+
validation?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ContentTypeRegistration {
|
|
51
|
+
name: string;
|
|
52
|
+
slug: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
fields: ContentTypeFieldDefinition[];
|
|
55
|
+
titleField?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ContentTypeRegistrar {
|
|
59
|
+
register(contentType: ContentTypeRegistration): Promise<void>;
|
|
60
|
+
unregister(slug: string): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ConfigAccessor {
|
|
64
|
+
get<T = unknown>(key: string, defaultValue?: T): T;
|
|
65
|
+
getAll(): Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface PluginLogger {
|
|
69
|
+
debug(message: string, ...args: unknown[]): void;
|
|
70
|
+
info(message: string, ...args: unknown[]): void;
|
|
71
|
+
warn(message: string, ...args: unknown[]): void;
|
|
72
|
+
error(message: string, ...args: unknown[]): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface PluginServices {
|
|
76
|
+
entries: {
|
|
77
|
+
create: (input: unknown, authorId: string, authorName?: string) => Promise<unknown>;
|
|
78
|
+
findById: (id: string) => Promise<unknown>;
|
|
79
|
+
findBySlug: (contentType: string, slug: string) => Promise<unknown>;
|
|
80
|
+
findAll: (filters?: unknown) => Promise<unknown>;
|
|
81
|
+
update: (id: string, input: unknown) => Promise<unknown>;
|
|
82
|
+
delete: (id: string) => Promise<void>;
|
|
83
|
+
};
|
|
84
|
+
users: {
|
|
85
|
+
findById: (id: string) => Promise<unknown>;
|
|
86
|
+
findByEmail: (email: string) => Promise<unknown>;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface PluginAPI {
|
|
91
|
+
readonly pluginName: string;
|
|
92
|
+
readonly services: PluginServices;
|
|
93
|
+
hooks: HookRegistrar;
|
|
94
|
+
routes: RouteRegistrar;
|
|
95
|
+
mcp: MCPRegistrar;
|
|
96
|
+
database: unknown;
|
|
97
|
+
contentTypes: ContentTypeRegistrar;
|
|
98
|
+
config: ConfigAccessor;
|
|
99
|
+
logger: PluginLogger;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface PluginDefinition {
|
|
103
|
+
name: string;
|
|
104
|
+
displayName?: string;
|
|
105
|
+
version: string;
|
|
106
|
+
description?: string;
|
|
107
|
+
lifecycle?: PluginLifecycle;
|
|
108
|
+
setup: (api: PluginAPI) => Promise<void> | void;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ============================================================================
|
|
112
|
+
// Stripe Plugin Specific Types
|
|
113
|
+
// ============================================================================
|
|
114
|
+
|
|
115
|
+
export interface StripeConfig {
|
|
116
|
+
secretKey: string;
|
|
117
|
+
webhookSecret: string;
|
|
118
|
+
successUrl: string;
|
|
119
|
+
cancelUrl: string;
|
|
120
|
+
portalReturnUrl: string;
|
|
121
|
+
currency: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type PriceType = 'one_time' | 'recurring';
|
|
125
|
+
export type PriceInterval = 'day' | 'week' | 'month' | 'year';
|
|
126
|
+
export type SubscriptionStatus =
|
|
127
|
+
| 'active'
|
|
128
|
+
| 'canceled'
|
|
129
|
+
| 'incomplete'
|
|
130
|
+
| 'incomplete_expired'
|
|
131
|
+
| 'past_due'
|
|
132
|
+
| 'trialing'
|
|
133
|
+
| 'unpaid'
|
|
134
|
+
| 'paused';
|
|
135
|
+
|
|
136
|
+
export type InvoiceStatus = 'draft' | 'open' | 'paid' | 'void' | 'uncollectible';
|
|
137
|
+
|
|
138
|
+
export interface StripeProduct {
|
|
139
|
+
id: string;
|
|
140
|
+
name: string;
|
|
141
|
+
description?: string;
|
|
142
|
+
active: boolean;
|
|
143
|
+
metadata?: Record<string, string>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface StripePrice {
|
|
147
|
+
id: string;
|
|
148
|
+
productId: string;
|
|
149
|
+
active: boolean;
|
|
150
|
+
currency: string;
|
|
151
|
+
unitAmount: number;
|
|
152
|
+
type: PriceType;
|
|
153
|
+
interval?: PriceInterval;
|
|
154
|
+
intervalCount?: number;
|
|
155
|
+
trialPeriodDays?: number;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface StripeCustomer {
|
|
159
|
+
id: string;
|
|
160
|
+
email: string;
|
|
161
|
+
name?: string;
|
|
162
|
+
metadata?: Record<string, string>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface StripeSubscription {
|
|
166
|
+
id: string;
|
|
167
|
+
customerId: string;
|
|
168
|
+
priceId: string;
|
|
169
|
+
status: SubscriptionStatus;
|
|
170
|
+
currentPeriodStart: number;
|
|
171
|
+
currentPeriodEnd: number;
|
|
172
|
+
cancelAtPeriodEnd: boolean;
|
|
173
|
+
canceledAt?: number;
|
|
174
|
+
trialStart?: number;
|
|
175
|
+
trialEnd?: number;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface StripeInvoice {
|
|
179
|
+
id: string;
|
|
180
|
+
customerId: string;
|
|
181
|
+
subscriptionId?: string;
|
|
182
|
+
status: InvoiceStatus;
|
|
183
|
+
amountDue: number;
|
|
184
|
+
amountPaid: number;
|
|
185
|
+
currency: string;
|
|
186
|
+
hostedInvoiceUrl?: string;
|
|
187
|
+
invoicePdf?: string;
|
|
188
|
+
paidAt?: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface CheckoutSessionParams {
|
|
192
|
+
priceId: string;
|
|
193
|
+
customerId?: string;
|
|
194
|
+
customerEmail?: string;
|
|
195
|
+
userId?: string;
|
|
196
|
+
mode: 'payment' | 'subscription';
|
|
197
|
+
quantity?: number;
|
|
198
|
+
trialPeriodDays?: number;
|
|
199
|
+
metadata?: Record<string, string>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface PortalSessionParams {
|
|
203
|
+
customerId: string;
|
|
204
|
+
returnUrl?: string;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface WebhookEvent {
|
|
208
|
+
id: string;
|
|
209
|
+
type: string;
|
|
210
|
+
data: {
|
|
211
|
+
object: unknown;
|
|
212
|
+
previous_attributes?: unknown;
|
|
213
|
+
};
|
|
214
|
+
}
|