@payark/sdk-effect 0.1.2 → 0.1.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/dist/index.d.mts +1954 -75
- package/dist/index.d.ts +1954 -75
- package/dist/index.js +414 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +367 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -3
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,367 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { HttpClient, HttpClientRequest } from '@effect/platform';
|
|
4
|
-
import { SDK_VERSION } from '@payark/sdk';
|
|
1
|
+
import { Schema, Context, Data, Layer, Effect } from 'effect';
|
|
2
|
+
import { HttpApiMiddleware, HttpApiSecurity, HttpApiGroup, HttpApiEndpoint, HttpApi, HttpApiClient, HttpClient, HttpClientRequest } from '@effect/platform';
|
|
5
3
|
|
|
6
4
|
// src/index.ts
|
|
5
|
+
var Id = Schema.String.pipe(Schema.brand("Id"));
|
|
6
|
+
var ProjectId = Schema.String.pipe(Schema.brand("ProjectId"));
|
|
7
|
+
var PaymentId = Schema.String.pipe(Schema.brand("PaymentId"));
|
|
8
|
+
var CheckoutSessionId = Schema.String.pipe(
|
|
9
|
+
Schema.brand("CheckoutSessionId")
|
|
10
|
+
);
|
|
11
|
+
var SubscriptionId = Schema.String.pipe(
|
|
12
|
+
Schema.brand("SubscriptionId")
|
|
13
|
+
);
|
|
14
|
+
var CustomerId = Schema.String.pipe(Schema.brand("CustomerId"));
|
|
15
|
+
var TokenId = Schema.String.pipe(Schema.brand("TokenId"));
|
|
16
|
+
var Email = Schema.String.pipe(
|
|
17
|
+
Schema.filter((s) => s.includes("@")),
|
|
18
|
+
Schema.brand("Email")
|
|
19
|
+
);
|
|
20
|
+
var Timestamp = Schema.String.pipe(Schema.brand("Timestamp"));
|
|
21
|
+
var Metadata = Schema.Record({
|
|
22
|
+
key: Schema.String,
|
|
23
|
+
value: Schema.Any
|
|
24
|
+
});
|
|
25
|
+
var Timestamps = Schema.Struct({
|
|
26
|
+
created_at: Timestamp,
|
|
27
|
+
updated_at: Timestamp
|
|
28
|
+
});
|
|
29
|
+
var Provider = Schema.Literal(
|
|
30
|
+
"esewa",
|
|
31
|
+
"khalti",
|
|
32
|
+
"connectips",
|
|
33
|
+
"imepay",
|
|
34
|
+
"fonepay",
|
|
35
|
+
"sandbox"
|
|
36
|
+
);
|
|
37
|
+
var PaymentStatus = Schema.Literal("pending", "success", "failed");
|
|
38
|
+
var SubscriptionStatus = Schema.Literal(
|
|
39
|
+
"active",
|
|
40
|
+
"past_due",
|
|
41
|
+
"canceled",
|
|
42
|
+
"paused"
|
|
43
|
+
);
|
|
44
|
+
var SubscriptionInterval = Schema.Literal("month", "year", "week");
|
|
45
|
+
var Customer = Schema.Struct({
|
|
46
|
+
id: CustomerId,
|
|
47
|
+
merchant_customer_id: Schema.String,
|
|
48
|
+
email: Schema.NullOr(Email),
|
|
49
|
+
name: Schema.NullOr(Schema.String),
|
|
50
|
+
phone: Schema.NullOr(Schema.String),
|
|
51
|
+
project_id: ProjectId,
|
|
52
|
+
metadata: Schema.NullOr(Metadata),
|
|
53
|
+
created_at: Timestamp,
|
|
54
|
+
updated_at: Schema.optional(Timestamp)
|
|
55
|
+
});
|
|
56
|
+
var Payment = Schema.Struct({
|
|
57
|
+
id: PaymentId,
|
|
58
|
+
project_id: ProjectId,
|
|
59
|
+
amount: Schema.Number,
|
|
60
|
+
currency: Schema.String,
|
|
61
|
+
status: PaymentStatus,
|
|
62
|
+
provider_ref: Schema.optional(Schema.NullOr(Schema.String)),
|
|
63
|
+
metadata_json: Schema.optional(Schema.NullOr(Metadata)),
|
|
64
|
+
gateway_response: Schema.optional(Schema.NullOr(Schema.Any)),
|
|
65
|
+
created_at: Timestamp,
|
|
66
|
+
updated_at: Schema.optional(Timestamp)
|
|
67
|
+
});
|
|
68
|
+
var Subscription = Schema.Struct({
|
|
69
|
+
id: SubscriptionId,
|
|
70
|
+
project_id: ProjectId,
|
|
71
|
+
customer_id: CustomerId,
|
|
72
|
+
status: SubscriptionStatus,
|
|
73
|
+
amount: Schema.Number,
|
|
74
|
+
currency: Schema.String,
|
|
75
|
+
interval: SubscriptionInterval,
|
|
76
|
+
interval_count: Schema.Number,
|
|
77
|
+
current_period_start: Timestamp,
|
|
78
|
+
current_period_end: Timestamp,
|
|
79
|
+
payment_link: Schema.String,
|
|
80
|
+
auto_send_link: Schema.Boolean,
|
|
81
|
+
metadata: Schema.optional(Schema.NullOr(Metadata)),
|
|
82
|
+
canceled_at: Schema.optional(Schema.NullOr(Timestamp)),
|
|
83
|
+
created_at: Timestamp,
|
|
84
|
+
updated_at: Schema.optional(Timestamp)
|
|
85
|
+
});
|
|
86
|
+
var Project = Schema.Struct({
|
|
87
|
+
id: ProjectId,
|
|
88
|
+
name: Schema.String,
|
|
89
|
+
api_key_secret: Schema.String,
|
|
90
|
+
created_at: Timestamp
|
|
91
|
+
});
|
|
92
|
+
var Token = Schema.Struct({
|
|
93
|
+
id: TokenId,
|
|
94
|
+
name: Schema.String,
|
|
95
|
+
scopes: Schema.Array(Schema.String),
|
|
96
|
+
last_used_at: Schema.NullOr(Timestamp),
|
|
97
|
+
expires_at: Schema.NullOr(Timestamp),
|
|
98
|
+
created_at: Timestamp
|
|
99
|
+
});
|
|
100
|
+
var PaginationMeta = Schema.Struct({
|
|
101
|
+
total: Schema.NullOr(Schema.Number),
|
|
102
|
+
limit: Schema.Number,
|
|
103
|
+
offset: Schema.Number
|
|
104
|
+
});
|
|
105
|
+
var PaginatedResponse = (schema) => Schema.Struct({
|
|
106
|
+
data: Schema.Array(schema),
|
|
107
|
+
meta: PaginationMeta
|
|
108
|
+
});
|
|
109
|
+
var CreateCheckoutParams = Schema.Struct({
|
|
110
|
+
amount: Schema.Number.pipe(Schema.greaterThan(0)),
|
|
111
|
+
currency: Schema.optionalWith(Schema.String, { default: () => "NPR" }),
|
|
112
|
+
provider: Provider,
|
|
113
|
+
returnUrl: Schema.String,
|
|
114
|
+
cancelUrl: Schema.optional(Schema.String),
|
|
115
|
+
metadata: Schema.optional(Metadata)
|
|
116
|
+
});
|
|
117
|
+
var CheckoutSession = Schema.Struct({
|
|
118
|
+
id: CheckoutSessionId,
|
|
119
|
+
checkout_url: Schema.String,
|
|
120
|
+
payment_method: Schema.Struct({
|
|
121
|
+
type: Provider,
|
|
122
|
+
url: Schema.optional(Schema.String),
|
|
123
|
+
method: Schema.optional(Schema.Literal("GET", "POST")),
|
|
124
|
+
fields: Schema.optional(
|
|
125
|
+
Schema.Record({ key: Schema.String, value: Schema.String })
|
|
126
|
+
)
|
|
127
|
+
})
|
|
128
|
+
});
|
|
129
|
+
var CreateCustomerParams = Schema.Struct({
|
|
130
|
+
merchant_customer_id: Schema.String,
|
|
131
|
+
email: Schema.optional(Schema.String),
|
|
132
|
+
name: Schema.optional(Schema.String),
|
|
133
|
+
phone: Schema.optional(Schema.String),
|
|
134
|
+
project_id: Schema.optional(ProjectId),
|
|
135
|
+
metadata: Schema.optional(Metadata)
|
|
136
|
+
});
|
|
137
|
+
var ListPaymentsParams = Schema.Struct({
|
|
138
|
+
limit: Schema.optional(Schema.NumberFromString),
|
|
139
|
+
offset: Schema.optional(Schema.NumberFromString),
|
|
140
|
+
projectId: Schema.optional(ProjectId)
|
|
141
|
+
});
|
|
142
|
+
var ListCustomersParams = Schema.Struct({
|
|
143
|
+
limit: Schema.optional(Schema.NumberFromString),
|
|
144
|
+
offset: Schema.optional(Schema.NumberFromString),
|
|
145
|
+
email: Schema.optional(Schema.String),
|
|
146
|
+
projectId: Schema.optional(ProjectId)
|
|
147
|
+
});
|
|
148
|
+
var UpdateCustomerParams = Schema.Struct({
|
|
149
|
+
email: Schema.optional(Schema.String),
|
|
150
|
+
name: Schema.optional(Schema.String),
|
|
151
|
+
phone: Schema.optional(Schema.String),
|
|
152
|
+
metadata: Schema.optional(Metadata)
|
|
153
|
+
});
|
|
154
|
+
var CreateSubscriptionParams = Schema.Struct({
|
|
155
|
+
customer_id: CustomerId,
|
|
156
|
+
amount: Schema.Number.pipe(Schema.greaterThan(0)),
|
|
157
|
+
currency: Schema.optionalWith(Schema.String, { default: () => "NPR" }),
|
|
158
|
+
interval: SubscriptionInterval,
|
|
159
|
+
interval_count: Schema.optional(Schema.Number),
|
|
160
|
+
project_id: Schema.optional(ProjectId),
|
|
161
|
+
auto_send_link: Schema.optional(Schema.Boolean),
|
|
162
|
+
metadata: Schema.optional(Metadata)
|
|
163
|
+
});
|
|
164
|
+
var ListSubscriptionsParams = Schema.Struct({
|
|
165
|
+
limit: Schema.optional(Schema.NumberFromString),
|
|
166
|
+
offset: Schema.optional(Schema.NumberFromString),
|
|
167
|
+
projectId: Schema.optional(ProjectId),
|
|
168
|
+
customerId: Schema.optional(CustomerId),
|
|
169
|
+
status: Schema.optional(SubscriptionStatus)
|
|
170
|
+
});
|
|
171
|
+
var PayArkConfig = Schema.Struct({
|
|
172
|
+
apiKey: Schema.String,
|
|
173
|
+
baseUrl: Schema.optional(Schema.String),
|
|
174
|
+
timeout: Schema.optional(Schema.Number),
|
|
175
|
+
maxRetries: Schema.optional(Schema.Number),
|
|
176
|
+
sandbox: Schema.optional(Schema.Boolean)
|
|
177
|
+
});
|
|
178
|
+
var WebhookEventType = Schema.Literal(
|
|
179
|
+
"payment.success",
|
|
180
|
+
"payment.failed",
|
|
181
|
+
"subscription.created",
|
|
182
|
+
"subscription.payment_succeeded",
|
|
183
|
+
"subscription.payment_failed",
|
|
184
|
+
"subscription.renewal_due",
|
|
185
|
+
"subscription.canceled"
|
|
186
|
+
);
|
|
187
|
+
var WebhookEvent = Schema.Struct({
|
|
188
|
+
type: WebhookEventType,
|
|
189
|
+
id: Schema.optional(Schema.String),
|
|
190
|
+
data: Schema.Union(
|
|
191
|
+
Payment,
|
|
192
|
+
Subscription,
|
|
193
|
+
Customer,
|
|
194
|
+
Schema.Struct({
|
|
195
|
+
id: Schema.String,
|
|
196
|
+
amount: Schema.optional(Schema.Number),
|
|
197
|
+
currency: Schema.optional(Schema.String),
|
|
198
|
+
status: Schema.String,
|
|
199
|
+
metadata: Schema.optional(Metadata)
|
|
200
|
+
})
|
|
201
|
+
),
|
|
202
|
+
is_test: Schema.Boolean,
|
|
203
|
+
created: Schema.optional(Schema.Number)
|
|
204
|
+
});
|
|
205
|
+
var PayArkErrorBody = Schema.Struct({
|
|
206
|
+
error: Schema.String,
|
|
207
|
+
details: Schema.optional(Schema.Any)
|
|
208
|
+
});
|
|
209
|
+
var IndustrialError = class extends Schema.TaggedError()(
|
|
210
|
+
"IndustrialError",
|
|
211
|
+
{
|
|
212
|
+
error: Schema.String,
|
|
213
|
+
details: Schema.optional(Schema.Any)
|
|
214
|
+
}
|
|
215
|
+
) {
|
|
216
|
+
};
|
|
217
|
+
var AuthenticationError = class extends Schema.TaggedError()(
|
|
218
|
+
"AuthenticationError",
|
|
219
|
+
{
|
|
220
|
+
error: Schema.String
|
|
221
|
+
}
|
|
222
|
+
) {
|
|
223
|
+
};
|
|
224
|
+
var NotFoundError = class extends Schema.TaggedError()(
|
|
225
|
+
"NotFoundError",
|
|
226
|
+
{
|
|
227
|
+
error: Schema.String
|
|
228
|
+
}
|
|
229
|
+
) {
|
|
230
|
+
};
|
|
231
|
+
var InternalServerError = class extends Schema.TaggedError()(
|
|
232
|
+
"InternalServerError",
|
|
233
|
+
{
|
|
234
|
+
error: Schema.String,
|
|
235
|
+
details: Schema.optional(Schema.Any)
|
|
236
|
+
}
|
|
237
|
+
) {
|
|
238
|
+
};
|
|
239
|
+
var ConflictError = class extends Schema.TaggedError()(
|
|
240
|
+
"ConflictError",
|
|
241
|
+
{
|
|
242
|
+
error: Schema.String
|
|
243
|
+
}
|
|
244
|
+
) {
|
|
245
|
+
};
|
|
246
|
+
var AuthContext = Context.GenericTag(
|
|
247
|
+
"@payark/sdk-effect/AuthContext"
|
|
248
|
+
);
|
|
249
|
+
var SecurityMiddleware = class extends HttpApiMiddleware.Tag()(
|
|
250
|
+
"SecurityMiddleware",
|
|
251
|
+
{
|
|
252
|
+
security: {
|
|
253
|
+
bearer: HttpApiSecurity.bearer
|
|
254
|
+
},
|
|
255
|
+
provides: AuthContext,
|
|
256
|
+
failure: Schema.Union(AuthenticationError, IndustrialError)
|
|
257
|
+
}
|
|
258
|
+
) {
|
|
259
|
+
};
|
|
260
|
+
var CronSecurity = class extends HttpApiMiddleware.Tag()(
|
|
261
|
+
"CronSecurity",
|
|
262
|
+
{
|
|
263
|
+
security: {
|
|
264
|
+
secret: HttpApiSecurity.apiKey({ in: "header", key: "x-cron-secret" })
|
|
265
|
+
},
|
|
266
|
+
failure: Schema.Union(AuthenticationError, IndustrialError)
|
|
267
|
+
}
|
|
268
|
+
) {
|
|
269
|
+
};
|
|
270
|
+
var UserSecurity = class extends HttpApiMiddleware.Tag()(
|
|
271
|
+
"UserSecurity",
|
|
272
|
+
{
|
|
273
|
+
security: {
|
|
274
|
+
bearer: HttpApiSecurity.bearer
|
|
275
|
+
},
|
|
276
|
+
provides: AuthContext,
|
|
277
|
+
failure: Schema.Union(AuthenticationError, IndustrialError)
|
|
278
|
+
}
|
|
279
|
+
) {
|
|
280
|
+
};
|
|
281
|
+
var CheckoutGroup = HttpApiGroup.make("checkout").add(
|
|
282
|
+
HttpApiEndpoint.post("create", "/").addSuccess(CheckoutSession).setPayload(CreateCheckoutParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
283
|
+
).prefix("/v1/checkout").middleware(SecurityMiddleware);
|
|
284
|
+
var PaymentsGroup = HttpApiGroup.make("payments").add(
|
|
285
|
+
HttpApiEndpoint.get("list", "/").addSuccess(PaginatedResponse(Payment)).setUrlParams(ListPaymentsParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
286
|
+
).add(
|
|
287
|
+
HttpApiEndpoint.get("retrieve", "/:id").addSuccess(Payment).setPath(Schema.Struct({ id: Id })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
288
|
+
).prefix("/v1/payments").middleware(SecurityMiddleware);
|
|
289
|
+
var CustomersGroup = HttpApiGroup.make("customers").add(
|
|
290
|
+
HttpApiEndpoint.post("create", "/").addSuccess(Customer, { status: 201 }).setPayload(CreateCustomerParams).addError(AuthenticationError, { status: 401 }).addError(ConflictError, { status: 409 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
291
|
+
).add(
|
|
292
|
+
HttpApiEndpoint.get("retrieve", "/:id").addSuccess(Customer).setPath(Schema.Struct({ id: Id })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
293
|
+
).add(
|
|
294
|
+
HttpApiEndpoint.patch("update", "/:id").addSuccess(Customer).setPath(Schema.Struct({ id: Id })).setPayload(UpdateCustomerParams).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(ConflictError, { status: 409 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
295
|
+
).add(
|
|
296
|
+
HttpApiEndpoint.del("delete", "/:id").setPath(Schema.Struct({ id: Id })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(ConflictError, { status: 409 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
297
|
+
).prefix("/v1/customers").middleware(SecurityMiddleware);
|
|
298
|
+
var SubscriptionsGroup = HttpApiGroup.make("subscriptions").add(
|
|
299
|
+
HttpApiEndpoint.post("create", "/").addSuccess(Subscription, { status: 201 }).setPayload(CreateSubscriptionParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 }).middleware(SecurityMiddleware)
|
|
300
|
+
).add(
|
|
301
|
+
HttpApiEndpoint.get("retrieve", "/:id").addSuccess(Subscription).setPath(Schema.Struct({ id: SubscriptionId })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).middleware(SecurityMiddleware)
|
|
302
|
+
).add(
|
|
303
|
+
HttpApiEndpoint.get("list", "/").addSuccess(PaginatedResponse(Subscription)).setUrlParams(ListSubscriptionsParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).middleware(SecurityMiddleware)
|
|
304
|
+
).add(
|
|
305
|
+
HttpApiEndpoint.post("cancel", "/:id/cancel").addSuccess(Subscription).setPath(Schema.Struct({ id: SubscriptionId })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).middleware(SecurityMiddleware)
|
|
306
|
+
).add(
|
|
307
|
+
HttpApiEndpoint.post("activate", "/:id/activate").addSuccess(
|
|
308
|
+
Schema.Struct({
|
|
309
|
+
checkout_url: Schema.String,
|
|
310
|
+
payment_id: Schema.String
|
|
311
|
+
})
|
|
312
|
+
).setPath(Schema.Struct({ id: SubscriptionId })).setPayload(
|
|
313
|
+
Schema.Struct({
|
|
314
|
+
provider: Provider,
|
|
315
|
+
returnUrl: Schema.String,
|
|
316
|
+
cancelUrl: Schema.optional(Schema.String)
|
|
317
|
+
})
|
|
318
|
+
).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
|
|
319
|
+
).prefix("/v1/subscriptions");
|
|
320
|
+
var AutomationGroup = HttpApiGroup.make("automation").add(
|
|
321
|
+
HttpApiEndpoint.post("reminders", "/reminders").addSuccess(
|
|
322
|
+
Schema.Struct({
|
|
323
|
+
message: Schema.String,
|
|
324
|
+
count: Schema.Number
|
|
325
|
+
})
|
|
326
|
+
).addError(InternalServerError, { status: 500 })
|
|
327
|
+
).add(
|
|
328
|
+
HttpApiEndpoint.post("reaper", "/reaper").addSuccess(
|
|
329
|
+
Schema.Struct({
|
|
330
|
+
message: Schema.String,
|
|
331
|
+
count: Schema.Number
|
|
332
|
+
})
|
|
333
|
+
).addError(InternalServerError, { status: 500 })
|
|
334
|
+
).prefix("/v1/automation").middleware(CronSecurity);
|
|
335
|
+
var TokensGroup = HttpApiGroup.make("tokens").add(
|
|
336
|
+
HttpApiEndpoint.post("create", "/").addSuccess(
|
|
337
|
+
Schema.Struct({
|
|
338
|
+
...Token.fields,
|
|
339
|
+
token: Schema.String
|
|
340
|
+
})
|
|
341
|
+
).setPayload(
|
|
342
|
+
Schema.Struct({
|
|
343
|
+
name: Schema.String,
|
|
344
|
+
scopes: Schema.optionalWith(Schema.Array(Schema.String), {
|
|
345
|
+
default: () => []
|
|
346
|
+
}),
|
|
347
|
+
expires_in_days: Schema.optional(Schema.Number)
|
|
348
|
+
})
|
|
349
|
+
).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
|
|
350
|
+
).add(
|
|
351
|
+
HttpApiEndpoint.get("list", "/").addSuccess(Schema.Array(Token)).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
|
|
352
|
+
).add(
|
|
353
|
+
HttpApiEndpoint.del("delete", "/:id").setPath(Schema.Struct({ id: TokenId })).addSuccess(Schema.Null).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 })
|
|
354
|
+
).prefix("/v1/tokens").middleware(UserSecurity);
|
|
355
|
+
var PayArkApi = HttpApi.make("PayArkApi").add(CheckoutGroup).add(PaymentsGroup).add(CustomersGroup).add(SubscriptionsGroup).add(AutomationGroup).add(TokensGroup).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(ConflictError, { status: 409 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 });
|
|
7
356
|
var PayArkEffectError = class extends Data.TaggedError("PayArkEffectError") {
|
|
8
357
|
/** Human-readable representation for logging/debugging. */
|
|
9
358
|
toString() {
|
|
10
359
|
return `[PayArkEffectError: ${this.code}] ${this.message} (HTTP ${this.statusCode})`;
|
|
11
360
|
}
|
|
12
361
|
};
|
|
362
|
+
|
|
363
|
+
// src/http.ts
|
|
364
|
+
var SDK_VERSION = "0.1.0";
|
|
13
365
|
var PayArkConfigService = class extends Context.Tag("PayArkConfigService")() {
|
|
14
366
|
};
|
|
15
367
|
var request = (method, path, options) => Effect.gen(function* (_) {
|
|
@@ -100,81 +452,6 @@ function mapStatusToCode(status) {
|
|
|
100
452
|
if (status >= 500) return "api_error";
|
|
101
453
|
return "unknown_error";
|
|
102
454
|
}
|
|
103
|
-
var ProviderSchema = Schema.Union(
|
|
104
|
-
Schema.Literal(
|
|
105
|
-
"esewa",
|
|
106
|
-
"khalti",
|
|
107
|
-
"connectips",
|
|
108
|
-
"imepay",
|
|
109
|
-
"fonepay",
|
|
110
|
-
"sandbox"
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
var CheckoutSessionId = Schema.String.pipe(
|
|
114
|
-
Schema.brand("CheckoutSessionId")
|
|
115
|
-
);
|
|
116
|
-
var PaymentId = Schema.String.pipe(Schema.brand("PaymentId"));
|
|
117
|
-
var ProjectId = Schema.String.pipe(Schema.brand("ProjectId"));
|
|
118
|
-
var CreateCheckoutSchema = Schema.Struct({
|
|
119
|
-
amount: Schema.Number,
|
|
120
|
-
currency: Schema.optionalWith(Schema.String, {
|
|
121
|
-
default: () => "NPR"
|
|
122
|
-
}),
|
|
123
|
-
provider: ProviderSchema,
|
|
124
|
-
returnUrl: Schema.String,
|
|
125
|
-
cancelUrl: Schema.optional(Schema.String),
|
|
126
|
-
metadata: Schema.optional(
|
|
127
|
-
Schema.Record({ key: Schema.String, value: Schema.Any })
|
|
128
|
-
)
|
|
129
|
-
});
|
|
130
|
-
var CheckoutSessionSchema = Schema.Struct({
|
|
131
|
-
id: CheckoutSessionId,
|
|
132
|
-
checkout_url: Schema.String,
|
|
133
|
-
payment_method: Schema.Struct({
|
|
134
|
-
type: ProviderSchema,
|
|
135
|
-
url: Schema.optional(Schema.String),
|
|
136
|
-
method: Schema.optional(
|
|
137
|
-
Schema.Union(Schema.Literal("GET"), Schema.Literal("POST"))
|
|
138
|
-
),
|
|
139
|
-
fields: Schema.optional(
|
|
140
|
-
Schema.Record({ key: Schema.String, value: Schema.String })
|
|
141
|
-
)
|
|
142
|
-
})
|
|
143
|
-
});
|
|
144
|
-
var PaymentSchema = Schema.Struct({
|
|
145
|
-
id: PaymentId,
|
|
146
|
-
project_id: ProjectId,
|
|
147
|
-
amount: Schema.Number,
|
|
148
|
-
currency: Schema.String,
|
|
149
|
-
status: Schema.Union(
|
|
150
|
-
Schema.Literal("pending"),
|
|
151
|
-
Schema.Literal("success"),
|
|
152
|
-
Schema.Literal("failed")
|
|
153
|
-
),
|
|
154
|
-
provider_ref: Schema.optional(Schema.NullOr(Schema.String)),
|
|
155
|
-
metadata_json: Schema.optional(
|
|
156
|
-
Schema.NullOr(Schema.Record({ key: Schema.String, value: Schema.Any }))
|
|
157
|
-
),
|
|
158
|
-
gateway_response: Schema.optional(
|
|
159
|
-
Schema.NullOr(Schema.Record({ key: Schema.String, value: Schema.Any }))
|
|
160
|
-
),
|
|
161
|
-
created_at: Schema.String,
|
|
162
|
-
updated_at: Schema.optional(Schema.String)
|
|
163
|
-
});
|
|
164
|
-
var ProjectSchema = Schema.Struct({
|
|
165
|
-
id: ProjectId,
|
|
166
|
-
name: Schema.String,
|
|
167
|
-
api_key_secret: Schema.String,
|
|
168
|
-
created_at: Schema.String
|
|
169
|
-
});
|
|
170
|
-
var PaginatedResponseSchema = (item) => Schema.Struct({
|
|
171
|
-
data: Schema.Array(item),
|
|
172
|
-
meta: Schema.Struct({
|
|
173
|
-
total: Schema.NullOr(Schema.Number),
|
|
174
|
-
limit: Schema.Number,
|
|
175
|
-
offset: Schema.Number
|
|
176
|
-
})
|
|
177
|
-
});
|
|
178
455
|
|
|
179
456
|
// src/resources/checkout.ts
|
|
180
457
|
var CheckoutEffect = class {
|
|
@@ -189,7 +466,7 @@ var CheckoutEffect = class {
|
|
|
189
466
|
*/
|
|
190
467
|
create(params) {
|
|
191
468
|
return request("POST", "/v1/checkout", { body: params }).pipe(
|
|
192
|
-
Effect.flatMap(Schema.decodeUnknown(
|
|
469
|
+
Effect.flatMap(Schema.decodeUnknown(CheckoutSession)),
|
|
193
470
|
Effect.provideService(PayArkConfigService, this.config)
|
|
194
471
|
);
|
|
195
472
|
}
|
|
@@ -212,9 +489,7 @@ var PaymentsEffect = class {
|
|
|
212
489
|
projectId: params.projectId
|
|
213
490
|
}
|
|
214
491
|
}).pipe(
|
|
215
|
-
Effect.flatMap(
|
|
216
|
-
Schema.decodeUnknown(PaginatedResponseSchema(PaymentSchema))
|
|
217
|
-
),
|
|
492
|
+
Effect.flatMap(Schema.decodeUnknown(PaginatedResponse(Payment))),
|
|
218
493
|
Effect.provideService(PayArkConfigService, this.config)
|
|
219
494
|
);
|
|
220
495
|
}
|
|
@@ -229,7 +504,7 @@ var PaymentsEffect = class {
|
|
|
229
504
|
"GET",
|
|
230
505
|
`/v1/payments/${encodeURIComponent(id)}`
|
|
231
506
|
).pipe(
|
|
232
|
-
Effect.flatMap(Schema.decodeUnknown(
|
|
507
|
+
Effect.flatMap(Schema.decodeUnknown(Payment)),
|
|
233
508
|
Effect.provideService(PayArkConfigService, this.config)
|
|
234
509
|
);
|
|
235
510
|
}
|
|
@@ -245,13 +520,19 @@ var ProjectsEffect = class {
|
|
|
245
520
|
*/
|
|
246
521
|
list() {
|
|
247
522
|
return request("GET", "/v1/projects").pipe(
|
|
248
|
-
Effect.flatMap(Schema.decodeUnknown(Schema.Array(
|
|
523
|
+
Effect.flatMap(Schema.decodeUnknown(Schema.Array(Project))),
|
|
249
524
|
Effect.provideService(PayArkConfigService, this.config)
|
|
250
525
|
);
|
|
251
526
|
}
|
|
252
527
|
};
|
|
253
528
|
|
|
254
529
|
// src/index.ts
|
|
530
|
+
var makeClient = (options) => HttpApiClient.make(PayArkApi, options);
|
|
531
|
+
var PayArkClient = class _PayArkClient extends Context.Tag(
|
|
532
|
+
"@payark/sdk-effect/PayArkClient"
|
|
533
|
+
)() {
|
|
534
|
+
static Live = (options) => Layer.effect(_PayArkClient, makeClient(options));
|
|
535
|
+
};
|
|
255
536
|
var PayArkEffect = class {
|
|
256
537
|
constructor(config) {
|
|
257
538
|
this.config = config;
|
|
@@ -294,6 +575,6 @@ var PayArk = class _PayArk extends Context.Tag("@payark/sdk-effect/PayArk")() {
|
|
|
294
575
|
static Live = (config) => Layer.succeed(_PayArk, new PayArkEffect(config));
|
|
295
576
|
};
|
|
296
577
|
|
|
297
|
-
export { CheckoutSessionId,
|
|
578
|
+
export { AuthContext, AuthenticationError, AutomationGroup, CheckoutGroup, CheckoutSession, CheckoutSessionId, ConflictError, CreateCheckoutParams, CreateCustomerParams, CreateSubscriptionParams, CronSecurity, Customer, CustomerId, CustomersGroup, Email, Id, IndustrialError, InternalServerError, ListCustomersParams, ListPaymentsParams, ListSubscriptionsParams, Metadata, NotFoundError, PaginatedResponse, PaginationMeta, PayArk, PayArkApi, PayArkClient, PayArkConfig, PayArkEffect, PayArkEffectError, PayArkErrorBody, Payment, PaymentId, PaymentStatus, PaymentsGroup, Project, ProjectId, Provider, SecurityMiddleware, Subscription, SubscriptionId, SubscriptionInterval, SubscriptionStatus, SubscriptionsGroup, Timestamp, Timestamps, Token, TokenId, TokensGroup, UpdateCustomerParams, UserSecurity, WebhookEvent, WebhookEventType, makeClient };
|
|
298
579
|
//# sourceMappingURL=index.mjs.map
|
|
299
580
|
//# sourceMappingURL=index.mjs.map
|