@payark/sdk-effect 0.1.2 → 0.1.5

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.js CHANGED
@@ -1,17 +1,420 @@
1
1
  'use strict';
2
2
 
3
3
  var effect = require('effect');
4
- var schema = require('@effect/schema');
5
4
  var platform = require('@effect/platform');
6
- var sdk = require('@payark/sdk');
7
5
 
8
6
  // src/index.ts
7
+ var NonEmptyString = effect.Schema.String.pipe(
8
+ effect.Schema.nonEmptyString(),
9
+ effect.Schema.brand("NonEmptyString")
10
+ );
11
+ var UrlString = effect.Schema.String.pipe(
12
+ effect.Schema.pattern(/^https?:\/\/.+/),
13
+ effect.Schema.brand("UrlString")
14
+ );
15
+ var MinorUnitsInt = effect.Schema.Number.pipe(
16
+ effect.Schema.int(),
17
+ effect.Schema.greaterThan(0),
18
+ effect.Schema.brand("MinorUnitsInt")
19
+ );
20
+
21
+ // src/schemas.ts
22
+ var Id = effect.Schema.String.pipe(effect.Schema.brand("Id"));
23
+ var ProjectId = effect.Schema.String.pipe(effect.Schema.brand("ProjectId"));
24
+ var PaymentId = effect.Schema.String.pipe(effect.Schema.brand("PaymentId"));
25
+ var CheckoutSessionId = effect.Schema.String.pipe(
26
+ effect.Schema.brand("CheckoutSessionId")
27
+ );
28
+ var SubscriptionId = effect.Schema.String.pipe(
29
+ effect.Schema.brand("SubscriptionId")
30
+ );
31
+ var CustomerId = effect.Schema.String.pipe(effect.Schema.brand("CustomerId"));
32
+ var TokenId = effect.Schema.String.pipe(effect.Schema.brand("TokenId"));
33
+ var Email = effect.Schema.String.pipe(
34
+ effect.Schema.filter((s) => s.includes("@")),
35
+ effect.Schema.brand("Email")
36
+ );
37
+ var Timestamp = effect.Schema.String.pipe(effect.Schema.brand("Timestamp"));
38
+ var Metadata = effect.Schema.Record({
39
+ key: effect.Schema.String,
40
+ value: effect.Schema.Any
41
+ });
42
+ var Timestamps = effect.Schema.Struct({
43
+ created_at: Timestamp,
44
+ updated_at: Timestamp
45
+ });
46
+ var Provider = effect.Schema.Literal(
47
+ "esewa",
48
+ "khalti",
49
+ "connectips",
50
+ "imepay",
51
+ "fonepay",
52
+ "sandbox"
53
+ );
54
+ var PaymentStatus = effect.Schema.Literal("pending", "success", "failed");
55
+ var SubscriptionStatus = effect.Schema.Literal(
56
+ "active",
57
+ "past_due",
58
+ "canceled",
59
+ "paused"
60
+ );
61
+ var SubscriptionInterval = effect.Schema.Literal("month", "year", "week");
62
+ var Customer = effect.Schema.Struct({
63
+ id: CustomerId,
64
+ merchant_customer_id: NonEmptyString,
65
+ email: effect.Schema.NullOr(Email),
66
+ name: effect.Schema.NullOr(NonEmptyString),
67
+ phone: effect.Schema.NullOr(effect.Schema.String),
68
+ project_id: ProjectId,
69
+ metadata: effect.Schema.NullOr(Metadata),
70
+ created_at: Timestamp,
71
+ updated_at: effect.Schema.optional(Timestamp)
72
+ });
73
+ var Payment = effect.Schema.Struct({
74
+ id: PaymentId,
75
+ project_id: ProjectId,
76
+ amount: effect.Schema.Number,
77
+ currency: effect.Schema.String,
78
+ status: PaymentStatus,
79
+ provider_ref: effect.Schema.optional(effect.Schema.NullOr(effect.Schema.String)),
80
+ metadata_json: effect.Schema.optional(effect.Schema.NullOr(Metadata)),
81
+ gateway_response: effect.Schema.optional(effect.Schema.NullOr(effect.Schema.Any)),
82
+ created_at: Timestamp,
83
+ updated_at: effect.Schema.optional(Timestamp)
84
+ });
85
+ var Subscription = effect.Schema.Struct({
86
+ id: SubscriptionId,
87
+ project_id: ProjectId,
88
+ customer_id: CustomerId,
89
+ status: SubscriptionStatus,
90
+ amount: effect.Schema.Number,
91
+ currency: effect.Schema.String,
92
+ interval: SubscriptionInterval,
93
+ interval_count: effect.Schema.Number,
94
+ current_period_start: Timestamp,
95
+ current_period_end: Timestamp,
96
+ payment_link: UrlString,
97
+ auto_send_link: effect.Schema.Boolean,
98
+ metadata: effect.Schema.optional(effect.Schema.NullOr(Metadata)),
99
+ canceled_at: effect.Schema.optional(effect.Schema.NullOr(Timestamp)),
100
+ created_at: Timestamp,
101
+ updated_at: effect.Schema.optional(Timestamp)
102
+ });
103
+ var Project = effect.Schema.Struct({
104
+ id: ProjectId,
105
+ name: NonEmptyString,
106
+ api_key_secret: effect.Schema.String,
107
+ created_at: Timestamp
108
+ });
109
+ var Token = effect.Schema.Struct({
110
+ id: TokenId,
111
+ name: NonEmptyString,
112
+ scopes: effect.Schema.Array(effect.Schema.String),
113
+ last_used_at: effect.Schema.NullOr(Timestamp),
114
+ expires_at: effect.Schema.NullOr(Timestamp),
115
+ created_at: Timestamp
116
+ });
117
+ var PaginationMeta = effect.Schema.Struct({
118
+ total: effect.Schema.NullOr(effect.Schema.Number),
119
+ limit: effect.Schema.Number,
120
+ offset: effect.Schema.Number
121
+ });
122
+ var PaginatedResponse = (schema) => effect.Schema.Struct({
123
+ data: effect.Schema.Array(schema),
124
+ meta: PaginationMeta
125
+ });
126
+ var WebhookEventType = effect.Schema.Literal(
127
+ "payment.success",
128
+ "payment.failed",
129
+ "subscription.created",
130
+ "subscription.payment_succeeded",
131
+ "subscription.payment_failed",
132
+ "subscription.renewal_due",
133
+ "subscription.canceled"
134
+ );
135
+ var WebhookEvent = effect.Schema.Struct({
136
+ type: WebhookEventType,
137
+ id: effect.Schema.optional(effect.Schema.String),
138
+ data: effect.Schema.Union(
139
+ Payment,
140
+ Subscription,
141
+ Customer,
142
+ effect.Schema.Struct({
143
+ id: effect.Schema.String,
144
+ amount: effect.Schema.optional(effect.Schema.Number),
145
+ currency: effect.Schema.optional(effect.Schema.String),
146
+ status: effect.Schema.String,
147
+ metadata: effect.Schema.optional(Metadata)
148
+ })
149
+ ),
150
+ is_test: effect.Schema.Boolean,
151
+ created: effect.Schema.optional(effect.Schema.Number)
152
+ });
153
+ var CreateCheckoutParams = effect.Schema.Struct({
154
+ amount: effect.Schema.optional(MinorUnitsInt),
155
+ currency: effect.Schema.optionalWith(effect.Schema.String, { default: () => "NPR" }),
156
+ provider: Provider,
157
+ returnUrl: UrlString,
158
+ cancelUrl: effect.Schema.optional(UrlString),
159
+ metadata: effect.Schema.optional(Metadata),
160
+ subscriptionId: effect.Schema.optional(SubscriptionId)
161
+ }).pipe(
162
+ effect.Schema.filter((data) => {
163
+ if (!data.subscriptionId && !data.amount) {
164
+ return "amount is required when subscriptionId is not provided";
165
+ }
166
+ return true;
167
+ })
168
+ );
169
+ var CheckoutSession = effect.Schema.Struct({
170
+ id: CheckoutSessionId,
171
+ checkout_url: UrlString,
172
+ payment_method: effect.Schema.Struct({
173
+ type: Provider,
174
+ url: effect.Schema.optional(UrlString),
175
+ method: effect.Schema.optional(effect.Schema.Literal("GET", "POST")),
176
+ fields: effect.Schema.optional(
177
+ effect.Schema.Record({ key: effect.Schema.String, value: effect.Schema.String })
178
+ )
179
+ })
180
+ });
181
+ var CreateCustomerParams = effect.Schema.Struct({
182
+ merchant_customer_id: NonEmptyString,
183
+ email: effect.Schema.optional(Email),
184
+ name: effect.Schema.optional(NonEmptyString),
185
+ phone: effect.Schema.optional(effect.Schema.String),
186
+ project_id: effect.Schema.optional(ProjectId),
187
+ metadata: effect.Schema.optional(Metadata)
188
+ });
189
+ var ListPaymentsParams = effect.Schema.Struct({
190
+ limit: effect.Schema.optional(effect.Schema.NumberFromString),
191
+ offset: effect.Schema.optional(effect.Schema.NumberFromString),
192
+ projectId: effect.Schema.optional(ProjectId)
193
+ });
194
+ var ListCustomersParams = effect.Schema.Struct({
195
+ limit: effect.Schema.optional(effect.Schema.NumberFromString),
196
+ offset: effect.Schema.optional(effect.Schema.NumberFromString),
197
+ email: effect.Schema.optional(effect.Schema.String),
198
+ merchant_customer_id: effect.Schema.optional(effect.Schema.String),
199
+ projectId: effect.Schema.optional(ProjectId)
200
+ });
201
+ var UpdateCustomerParams = effect.Schema.Struct({
202
+ email: effect.Schema.optional(Email),
203
+ name: effect.Schema.optional(NonEmptyString),
204
+ phone: effect.Schema.optional(effect.Schema.String),
205
+ metadata: effect.Schema.optional(Metadata)
206
+ });
207
+ var CreateSubscriptionParams = effect.Schema.Struct({
208
+ customer_id: CustomerId,
209
+ amount: MinorUnitsInt,
210
+ currency: effect.Schema.optionalWith(effect.Schema.String, { default: () => "NPR" }),
211
+ interval: SubscriptionInterval,
212
+ interval_count: effect.Schema.optional(effect.Schema.Number),
213
+ project_id: effect.Schema.optional(ProjectId),
214
+ auto_send_link: effect.Schema.optional(effect.Schema.Boolean),
215
+ metadata: effect.Schema.optional(Metadata)
216
+ });
217
+ var CallbackQueryParams = effect.Schema.Struct({
218
+ payment_id: effect.Schema.optional(effect.Schema.String),
219
+ data: effect.Schema.optional(effect.Schema.String),
220
+ pidx: effect.Schema.optional(effect.Schema.String)
221
+ });
222
+ var ListSubscriptionsParams = effect.Schema.Struct({
223
+ limit: effect.Schema.optional(effect.Schema.NumberFromString),
224
+ offset: effect.Schema.optional(effect.Schema.NumberFromString),
225
+ projectId: effect.Schema.optional(ProjectId),
226
+ customerId: effect.Schema.optional(CustomerId),
227
+ status: effect.Schema.optional(SubscriptionStatus)
228
+ });
229
+ var RealtimeTriggerPayload = effect.Schema.Struct({
230
+ event: effect.Schema.optional(WebhookEventType),
231
+ data: effect.Schema.optional(effect.Schema.Any)
232
+ });
233
+ var PayArkConfig = effect.Schema.Struct({
234
+ apiKey: effect.Schema.String,
235
+ baseUrl: effect.Schema.optional(effect.Schema.String),
236
+ timeout: effect.Schema.optional(effect.Schema.Number),
237
+ maxRetries: effect.Schema.optional(effect.Schema.Number),
238
+ sandbox: effect.Schema.optional(effect.Schema.Boolean)
239
+ });
240
+ var PayArkErrorBody = effect.Schema.Struct({
241
+ error: effect.Schema.String,
242
+ details: effect.Schema.optional(effect.Schema.Any)
243
+ });
244
+ var IndustrialError = class extends effect.Schema.TaggedError()(
245
+ "IndustrialError",
246
+ {
247
+ error: effect.Schema.String,
248
+ details: effect.Schema.optional(effect.Schema.Any)
249
+ }
250
+ ) {
251
+ };
252
+ var AuthenticationError = class extends effect.Schema.TaggedError()(
253
+ "AuthenticationError",
254
+ {
255
+ error: effect.Schema.String
256
+ }
257
+ ) {
258
+ };
259
+ var NotFoundError = class extends effect.Schema.TaggedError()(
260
+ "NotFoundError",
261
+ {
262
+ error: effect.Schema.String
263
+ }
264
+ ) {
265
+ };
266
+ var InternalServerError = class extends effect.Schema.TaggedError()(
267
+ "InternalServerError",
268
+ {
269
+ error: effect.Schema.String,
270
+ details: effect.Schema.optional(effect.Schema.Any)
271
+ }
272
+ ) {
273
+ };
274
+ var ConflictError = class extends effect.Schema.TaggedError()(
275
+ "ConflictError",
276
+ {
277
+ error: effect.Schema.String
278
+ }
279
+ ) {
280
+ };
281
+ var AuthContext = effect.Context.GenericTag(
282
+ "@payark/sdk-effect/AuthContext"
283
+ );
284
+ var SecurityMiddleware = class extends platform.HttpApiMiddleware.Tag()(
285
+ "SecurityMiddleware",
286
+ {
287
+ security: {
288
+ bearer: platform.HttpApiSecurity.bearer
289
+ },
290
+ provides: AuthContext,
291
+ failure: effect.Schema.Union(AuthenticationError, IndustrialError)
292
+ }
293
+ ) {
294
+ };
295
+ var CronSecurity = class extends platform.HttpApiMiddleware.Tag()(
296
+ "CronSecurity",
297
+ {
298
+ security: {
299
+ secret: platform.HttpApiSecurity.apiKey({ in: "header", key: "x-cron-secret" })
300
+ },
301
+ failure: effect.Schema.Union(AuthenticationError, IndustrialError)
302
+ }
303
+ ) {
304
+ };
305
+ var UserSecurity = class extends platform.HttpApiMiddleware.Tag()(
306
+ "UserSecurity",
307
+ {
308
+ security: {
309
+ bearer: platform.HttpApiSecurity.bearer
310
+ },
311
+ provides: AuthContext,
312
+ failure: effect.Schema.Union(AuthenticationError, IndustrialError)
313
+ }
314
+ ) {
315
+ };
316
+ var CheckoutGroup = platform.HttpApiGroup.make("checkout").add(
317
+ platform.HttpApiEndpoint.post("create", "/").addSuccess(CheckoutSession).setPayload(CreateCheckoutParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
318
+ ).prefix("/v1/checkout").middleware(SecurityMiddleware);
319
+ var PaymentsGroup = platform.HttpApiGroup.make("payments").add(
320
+ platform.HttpApiEndpoint.get("list", "/").addSuccess(PaginatedResponse(Payment)).setUrlParams(ListPaymentsParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
321
+ ).add(
322
+ platform.HttpApiEndpoint.get("retrieve", "/:id").addSuccess(Payment).setPath(effect.Schema.Struct({ id: Id })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
323
+ ).prefix("/v1/payments").middleware(SecurityMiddleware);
324
+ var CustomersGroup = platform.HttpApiGroup.make("customers").add(
325
+ platform.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 })
326
+ ).add(
327
+ platform.HttpApiEndpoint.get("list", "/").addSuccess(PaginatedResponse(Customer)).setUrlParams(ListCustomersParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
328
+ ).add(
329
+ platform.HttpApiEndpoint.get("retrieve", "/:id").addSuccess(Customer).setPath(effect.Schema.Struct({ id: Id })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
330
+ ).add(
331
+ platform.HttpApiEndpoint.patch("update", "/:id").addSuccess(Customer).setPath(effect.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 })
332
+ ).add(
333
+ platform.HttpApiEndpoint.del("delete", "/:id").setPath(effect.Schema.Struct({ id: Id })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(ConflictError, { status: 409 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
334
+ ).prefix("/v1/customers").middleware(SecurityMiddleware);
335
+ var SubscriptionsGroup = platform.HttpApiGroup.make("subscriptions").add(
336
+ platform.HttpApiEndpoint.post("create", "/").addSuccess(Subscription, { status: 201 }).setPayload(CreateSubscriptionParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 }).middleware(SecurityMiddleware)
337
+ ).add(
338
+ platform.HttpApiEndpoint.get("retrieve", "/:id").addSuccess(Subscription).setPath(effect.Schema.Struct({ id: SubscriptionId })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).middleware(SecurityMiddleware)
339
+ ).add(
340
+ platform.HttpApiEndpoint.get("list", "/").addSuccess(PaginatedResponse(Subscription)).setUrlParams(ListSubscriptionsParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 }).middleware(SecurityMiddleware)
341
+ ).add(
342
+ platform.HttpApiEndpoint.post("cancel", "/:id/cancel").addSuccess(Subscription).setPath(effect.Schema.Struct({ id: SubscriptionId })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).middleware(SecurityMiddleware)
343
+ ).add(
344
+ platform.HttpApiEndpoint.post("activate", "/:id/activate").addSuccess(
345
+ effect.Schema.Struct({
346
+ checkout_url: effect.Schema.String,
347
+ payment_id: effect.Schema.String
348
+ })
349
+ ).setPath(effect.Schema.Struct({ id: SubscriptionId })).setPayload(
350
+ effect.Schema.Struct({
351
+ provider: Provider,
352
+ returnUrl: effect.Schema.String,
353
+ cancelUrl: effect.Schema.optional(effect.Schema.String)
354
+ })
355
+ ).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
356
+ ).prefix("/v1/subscriptions");
357
+ var AutomationGroup = platform.HttpApiGroup.make("automation").add(
358
+ platform.HttpApiEndpoint.post("reminders", "/reminders").addSuccess(
359
+ effect.Schema.Struct({
360
+ message: effect.Schema.String,
361
+ count: effect.Schema.Number
362
+ })
363
+ ).addError(InternalServerError, { status: 500 })
364
+ ).add(
365
+ platform.HttpApiEndpoint.post("reaper", "/reaper").addSuccess(
366
+ effect.Schema.Struct({
367
+ message: effect.Schema.String,
368
+ count: effect.Schema.Number
369
+ })
370
+ ).addError(InternalServerError, { status: 500 })
371
+ ).prefix("/v1/automation").middleware(CronSecurity);
372
+ var TokensGroup = platform.HttpApiGroup.make("tokens").add(
373
+ platform.HttpApiEndpoint.post("create", "/").addSuccess(
374
+ effect.Schema.Struct({
375
+ ...Token.fields,
376
+ token: effect.Schema.String
377
+ })
378
+ ).setPayload(
379
+ effect.Schema.Struct({
380
+ name: effect.Schema.String,
381
+ scopes: effect.Schema.optionalWith(effect.Schema.Array(effect.Schema.String), {
382
+ default: () => []
383
+ }),
384
+ expires_in_days: effect.Schema.optional(effect.Schema.Number)
385
+ })
386
+ ).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
387
+ ).add(
388
+ platform.HttpApiEndpoint.get("list", "/").addSuccess(effect.Schema.Array(Token)).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
389
+ ).add(
390
+ platform.HttpApiEndpoint.del("delete", "/:id").setPath(effect.Schema.Struct({ id: TokenId })).addSuccess(effect.Schema.Null).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 })
391
+ ).prefix("/v1/tokens").middleware(UserSecurity);
392
+ var ProjectsGroup = platform.HttpApiGroup.make("projects").add(
393
+ platform.HttpApiEndpoint.get("list", "/").addSuccess(effect.Schema.Array(Project)).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
394
+ ).prefix("/v1/projects").middleware(SecurityMiddleware);
395
+ var CallbacksGroup = platform.HttpApiGroup.make("callbacks").add(
396
+ platform.HttpApiEndpoint.get("handle", "/:provider").addSuccess(effect.Schema.Any).setPath(effect.Schema.Struct({ provider: effect.Schema.String })).setUrlParams(CallbackQueryParams).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
397
+ ).prefix("/v1/callback");
398
+ var RealtimeGroup = platform.HttpApiGroup.make("realtime").add(
399
+ platform.HttpApiEndpoint.get("connect", "/").addSuccess(effect.Schema.Any).setUrlParams(effect.Schema.Struct({ token: effect.Schema.String })).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
400
+ ).add(
401
+ platform.HttpApiEndpoint.post("trigger", "/trigger").addSuccess(
402
+ effect.Schema.Struct({
403
+ status: effect.Schema.String,
404
+ event: effect.Schema.optional(effect.Schema.String)
405
+ })
406
+ ).setPayload(RealtimeTriggerPayload).setUrlParams(effect.Schema.Struct({ token: effect.Schema.optional(effect.Schema.String) })).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
407
+ ).prefix("/v1/realtime");
408
+ var PayArkApi = platform.HttpApi.make("PayArkApi").add(CheckoutGroup).add(PaymentsGroup).add(CustomersGroup).add(SubscriptionsGroup).add(AutomationGroup).add(TokensGroup).add(ProjectsGroup).add(CallbacksGroup).add(RealtimeGroup).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(ConflictError, { status: 409 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 });
9
409
  var PayArkEffectError = class extends effect.Data.TaggedError("PayArkEffectError") {
10
410
  /** Human-readable representation for logging/debugging. */
11
411
  toString() {
12
412
  return `[PayArkEffectError: ${this.code}] ${this.message} (HTTP ${this.statusCode})`;
13
413
  }
14
414
  };
415
+
416
+ // src/http.ts
417
+ var SDK_VERSION = "0.1.0";
15
418
  var PayArkConfigService = class extends effect.Context.Tag("PayArkConfigService")() {
16
419
  };
17
420
  var request = (method, path, options) => effect.Effect.gen(function* (_) {
@@ -30,7 +433,7 @@ var request = (method, path, options) => effect.Effect.gen(function* (_) {
30
433
  Authorization: `Bearer ${config.apiKey}`,
31
434
  "Content-Type": "application/json",
32
435
  Accept: "application/json",
33
- "User-Agent": `payark-sdk-effect/${sdk.SDK_VERSION}`,
436
+ "User-Agent": `payark-sdk-effect/${SDK_VERSION}`,
34
437
  ...options?.headers
35
438
  };
36
439
  if (config.sandbox) {
@@ -102,81 +505,6 @@ function mapStatusToCode(status) {
102
505
  if (status >= 500) return "api_error";
103
506
  return "unknown_error";
104
507
  }
105
- var ProviderSchema = schema.Schema.Union(
106
- schema.Schema.Literal(
107
- "esewa",
108
- "khalti",
109
- "connectips",
110
- "imepay",
111
- "fonepay",
112
- "sandbox"
113
- )
114
- );
115
- var CheckoutSessionId = schema.Schema.String.pipe(
116
- schema.Schema.brand("CheckoutSessionId")
117
- );
118
- var PaymentId = schema.Schema.String.pipe(schema.Schema.brand("PaymentId"));
119
- var ProjectId = schema.Schema.String.pipe(schema.Schema.brand("ProjectId"));
120
- var CreateCheckoutSchema = schema.Schema.Struct({
121
- amount: schema.Schema.Number,
122
- currency: schema.Schema.optionalWith(schema.Schema.String, {
123
- default: () => "NPR"
124
- }),
125
- provider: ProviderSchema,
126
- returnUrl: schema.Schema.String,
127
- cancelUrl: schema.Schema.optional(schema.Schema.String),
128
- metadata: schema.Schema.optional(
129
- schema.Schema.Record({ key: schema.Schema.String, value: schema.Schema.Any })
130
- )
131
- });
132
- var CheckoutSessionSchema = schema.Schema.Struct({
133
- id: CheckoutSessionId,
134
- checkout_url: schema.Schema.String,
135
- payment_method: schema.Schema.Struct({
136
- type: ProviderSchema,
137
- url: schema.Schema.optional(schema.Schema.String),
138
- method: schema.Schema.optional(
139
- schema.Schema.Union(schema.Schema.Literal("GET"), schema.Schema.Literal("POST"))
140
- ),
141
- fields: schema.Schema.optional(
142
- schema.Schema.Record({ key: schema.Schema.String, value: schema.Schema.String })
143
- )
144
- })
145
- });
146
- var PaymentSchema = schema.Schema.Struct({
147
- id: PaymentId,
148
- project_id: ProjectId,
149
- amount: schema.Schema.Number,
150
- currency: schema.Schema.String,
151
- status: schema.Schema.Union(
152
- schema.Schema.Literal("pending"),
153
- schema.Schema.Literal("success"),
154
- schema.Schema.Literal("failed")
155
- ),
156
- provider_ref: schema.Schema.optional(schema.Schema.NullOr(schema.Schema.String)),
157
- metadata_json: schema.Schema.optional(
158
- schema.Schema.NullOr(schema.Schema.Record({ key: schema.Schema.String, value: schema.Schema.Any }))
159
- ),
160
- gateway_response: schema.Schema.optional(
161
- schema.Schema.NullOr(schema.Schema.Record({ key: schema.Schema.String, value: schema.Schema.Any }))
162
- ),
163
- created_at: schema.Schema.String,
164
- updated_at: schema.Schema.optional(schema.Schema.String)
165
- });
166
- var ProjectSchema = schema.Schema.Struct({
167
- id: ProjectId,
168
- name: schema.Schema.String,
169
- api_key_secret: schema.Schema.String,
170
- created_at: schema.Schema.String
171
- });
172
- var PaginatedResponseSchema = (item) => schema.Schema.Struct({
173
- data: schema.Schema.Array(item),
174
- meta: schema.Schema.Struct({
175
- total: schema.Schema.NullOr(schema.Schema.Number),
176
- limit: schema.Schema.Number,
177
- offset: schema.Schema.Number
178
- })
179
- });
180
508
 
181
509
  // src/resources/checkout.ts
182
510
  var CheckoutEffect = class {
@@ -191,7 +519,7 @@ var CheckoutEffect = class {
191
519
  */
192
520
  create(params) {
193
521
  return request("POST", "/v1/checkout", { body: params }).pipe(
194
- effect.Effect.flatMap(schema.Schema.decodeUnknown(CheckoutSessionSchema)),
522
+ effect.Effect.flatMap(effect.Schema.decodeUnknown(CheckoutSession)),
195
523
  effect.Effect.provideService(PayArkConfigService, this.config)
196
524
  );
197
525
  }
@@ -214,9 +542,7 @@ var PaymentsEffect = class {
214
542
  projectId: params.projectId
215
543
  }
216
544
  }).pipe(
217
- effect.Effect.flatMap(
218
- schema.Schema.decodeUnknown(PaginatedResponseSchema(PaymentSchema))
219
- ),
545
+ effect.Effect.flatMap(effect.Schema.decodeUnknown(PaginatedResponse(Payment))),
220
546
  effect.Effect.provideService(PayArkConfigService, this.config)
221
547
  );
222
548
  }
@@ -231,7 +557,7 @@ var PaymentsEffect = class {
231
557
  "GET",
232
558
  `/v1/payments/${encodeURIComponent(id)}`
233
559
  ).pipe(
234
- effect.Effect.flatMap(schema.Schema.decodeUnknown(PaymentSchema)),
560
+ effect.Effect.flatMap(effect.Schema.decodeUnknown(Payment)),
235
561
  effect.Effect.provideService(PayArkConfigService, this.config)
236
562
  );
237
563
  }
@@ -247,13 +573,19 @@ var ProjectsEffect = class {
247
573
  */
248
574
  list() {
249
575
  return request("GET", "/v1/projects").pipe(
250
- effect.Effect.flatMap(schema.Schema.decodeUnknown(schema.Schema.Array(ProjectSchema))),
576
+ effect.Effect.flatMap(effect.Schema.decodeUnknown(effect.Schema.Array(Project))),
251
577
  effect.Effect.provideService(PayArkConfigService, this.config)
252
578
  );
253
579
  }
254
580
  };
255
581
 
256
582
  // src/index.ts
583
+ var makeClient = (options) => platform.HttpApiClient.make(PayArkApi, options);
584
+ var PayArkClient = class _PayArkClient extends effect.Context.Tag(
585
+ "@payark/sdk-effect/PayArkClient"
586
+ )() {
587
+ static Live = (options) => effect.Layer.effect(_PayArkClient, makeClient(options));
588
+ };
257
589
  var PayArkEffect = class {
258
590
  constructor(config) {
259
591
  this.config = config;
@@ -296,17 +628,65 @@ var PayArk = class _PayArk extends effect.Context.Tag("@payark/sdk-effect/PayArk
296
628
  static Live = (config) => effect.Layer.succeed(_PayArk, new PayArkEffect(config));
297
629
  };
298
630
 
631
+ exports.AuthContext = AuthContext;
632
+ exports.AuthenticationError = AuthenticationError;
633
+ exports.AutomationGroup = AutomationGroup;
634
+ exports.CallbackQueryParams = CallbackQueryParams;
635
+ exports.CallbacksGroup = CallbacksGroup;
636
+ exports.CheckoutGroup = CheckoutGroup;
637
+ exports.CheckoutSession = CheckoutSession;
299
638
  exports.CheckoutSessionId = CheckoutSessionId;
300
- exports.CheckoutSessionSchema = CheckoutSessionSchema;
301
- exports.CreateCheckoutSchema = CreateCheckoutSchema;
302
- exports.PaginatedResponseSchema = PaginatedResponseSchema;
639
+ exports.ConflictError = ConflictError;
640
+ exports.CreateCheckoutParams = CreateCheckoutParams;
641
+ exports.CreateCustomerParams = CreateCustomerParams;
642
+ exports.CreateSubscriptionParams = CreateSubscriptionParams;
643
+ exports.CronSecurity = CronSecurity;
644
+ exports.Customer = Customer;
645
+ exports.CustomerId = CustomerId;
646
+ exports.CustomersGroup = CustomersGroup;
647
+ exports.Email = Email;
648
+ exports.Id = Id;
649
+ exports.IndustrialError = IndustrialError;
650
+ exports.InternalServerError = InternalServerError;
651
+ exports.ListCustomersParams = ListCustomersParams;
652
+ exports.ListPaymentsParams = ListPaymentsParams;
653
+ exports.ListSubscriptionsParams = ListSubscriptionsParams;
654
+ exports.Metadata = Metadata;
655
+ exports.NotFoundError = NotFoundError;
656
+ exports.PaginatedResponse = PaginatedResponse;
657
+ exports.PaginationMeta = PaginationMeta;
303
658
  exports.PayArk = PayArk;
659
+ exports.PayArkApi = PayArkApi;
660
+ exports.PayArkClient = PayArkClient;
661
+ exports.PayArkConfig = PayArkConfig;
304
662
  exports.PayArkEffect = PayArkEffect;
305
663
  exports.PayArkEffectError = PayArkEffectError;
664
+ exports.PayArkErrorBody = PayArkErrorBody;
665
+ exports.Payment = Payment;
306
666
  exports.PaymentId = PaymentId;
307
- exports.PaymentSchema = PaymentSchema;
667
+ exports.PaymentStatus = PaymentStatus;
668
+ exports.PaymentsGroup = PaymentsGroup;
669
+ exports.Project = Project;
308
670
  exports.ProjectId = ProjectId;
309
- exports.ProjectSchema = ProjectSchema;
310
- exports.ProviderSchema = ProviderSchema;
671
+ exports.ProjectsGroup = ProjectsGroup;
672
+ exports.Provider = Provider;
673
+ exports.RealtimeGroup = RealtimeGroup;
674
+ exports.RealtimeTriggerPayload = RealtimeTriggerPayload;
675
+ exports.SecurityMiddleware = SecurityMiddleware;
676
+ exports.Subscription = Subscription;
677
+ exports.SubscriptionId = SubscriptionId;
678
+ exports.SubscriptionInterval = SubscriptionInterval;
679
+ exports.SubscriptionStatus = SubscriptionStatus;
680
+ exports.SubscriptionsGroup = SubscriptionsGroup;
681
+ exports.Timestamp = Timestamp;
682
+ exports.Timestamps = Timestamps;
683
+ exports.Token = Token;
684
+ exports.TokenId = TokenId;
685
+ exports.TokensGroup = TokensGroup;
686
+ exports.UpdateCustomerParams = UpdateCustomerParams;
687
+ exports.UserSecurity = UserSecurity;
688
+ exports.WebhookEvent = WebhookEvent;
689
+ exports.WebhookEventType = WebhookEventType;
690
+ exports.makeClient = makeClient;
311
691
  //# sourceMappingURL=index.js.map
312
692
  //# sourceMappingURL=index.js.map