@payark/sdk-effect 0.1.5 → 0.1.9

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { Schema, Context, Data, Layer, Effect } from 'effect';
1
+ import { Schema, Context, Data, Layer, Effect, Schedule } from 'effect';
2
2
  import { HttpApiMiddleware, HttpApiSecurity, HttpApiGroup, HttpApiEndpoint, HttpApi, HttpApiClient, HttpClient, HttpClientRequest } from '@effect/platform';
3
3
 
4
4
  // src/index.ts
@@ -10,11 +10,17 @@ var UrlString = Schema.String.pipe(
10
10
  Schema.pattern(/^https?:\/\/.+/),
11
11
  Schema.brand("UrlString")
12
12
  );
13
- var MinorUnitsInt = Schema.Number.pipe(
13
+ Schema.Number.pipe(
14
14
  Schema.int(),
15
15
  Schema.greaterThan(0),
16
16
  Schema.brand("MinorUnitsInt")
17
17
  );
18
+ var NprAmount = Schema.Number.pipe(
19
+ Schema.filter(
20
+ (n) => Number.isFinite(n) && n > 0 && Math.round(n * 100) === n * 100
21
+ ),
22
+ Schema.brand("NprAmount")
23
+ );
18
24
 
19
25
  // src/schemas.ts
20
26
  var Id = Schema.String.pipe(Schema.brand("Id"));
@@ -26,6 +32,10 @@ var CheckoutSessionId = Schema.String.pipe(
26
32
  var SubscriptionId = Schema.String.pipe(
27
33
  Schema.brand("SubscriptionId")
28
34
  );
35
+ var MandateId = Schema.String.pipe(Schema.brand("MandateId"));
36
+ var AgentSessionId = Schema.String.pipe(
37
+ Schema.brand("AgentSessionId")
38
+ );
29
39
  var CustomerId = Schema.String.pipe(Schema.brand("CustomerId"));
30
40
  var TokenId = Schema.String.pipe(Schema.brand("TokenId"));
31
41
  var Email = Schema.String.pipe(
@@ -44,6 +54,7 @@ var Timestamps = Schema.Struct({
44
54
  var Provider = Schema.Literal(
45
55
  "esewa",
46
56
  "khalti",
57
+ "hamropay",
47
58
  "connectips",
48
59
  "imepay",
49
60
  "fonepay",
@@ -51,12 +62,27 @@ var Provider = Schema.Literal(
51
62
  );
52
63
  var PaymentStatus = Schema.Literal("pending", "success", "failed");
53
64
  var SubscriptionStatus = Schema.Literal(
65
+ "pending_checkout",
54
66
  "active",
55
67
  "past_due",
56
68
  "canceled",
57
69
  "paused"
58
70
  );
59
71
  var SubscriptionInterval = Schema.Literal("month", "year", "week");
72
+ var CustomerLifecycle = Schema.Literal(
73
+ "new",
74
+ "active",
75
+ "loyal",
76
+ "at_risk",
77
+ "churned"
78
+ );
79
+ var MandateType = Schema.Literal("intent", "cart");
80
+ var MandateStatus = Schema.Literal(
81
+ "active",
82
+ "consumed",
83
+ "expired",
84
+ "violated"
85
+ );
60
86
  var Customer = Schema.Struct({
61
87
  id: CustomerId,
62
88
  merchant_customer_id: NonEmptyString,
@@ -65,12 +91,18 @@ var Customer = Schema.Struct({
65
91
  phone: Schema.NullOr(Schema.String),
66
92
  project_id: ProjectId,
67
93
  metadata: Schema.NullOr(Metadata),
94
+ total_ltv: Schema.optional(Schema.Number),
95
+ is_high_value: Schema.optional(Schema.Boolean),
96
+ lifecycle_stage: Schema.optional(CustomerLifecycle),
97
+ ltv_cents: Schema.optional(Schema.Number),
98
+ tier: Schema.NullOr(Schema.String),
68
99
  created_at: Timestamp,
69
100
  updated_at: Schema.optional(Timestamp)
70
101
  });
71
102
  var Payment = Schema.Struct({
72
103
  id: PaymentId,
73
104
  project_id: ProjectId,
105
+ customer_id: Schema.optional(Schema.NullOr(CustomerId)),
74
106
  amount: Schema.Number,
75
107
  currency: Schema.String,
76
108
  status: PaymentStatus,
@@ -92,7 +124,9 @@ var Subscription = Schema.Struct({
92
124
  current_period_start: Timestamp,
93
125
  current_period_end: Timestamp,
94
126
  payment_link: UrlString,
127
+ customer_email: Schema.optional(Schema.NullOr(Schema.String)),
95
128
  auto_send_link: Schema.Boolean,
129
+ grace_days: Schema.optional(Schema.Number),
96
130
  metadata: Schema.optional(Schema.NullOr(Metadata)),
97
131
  canceled_at: Schema.optional(Schema.NullOr(Timestamp)),
98
132
  created_at: Timestamp,
@@ -102,6 +136,13 @@ var Project = Schema.Struct({
102
136
  id: ProjectId,
103
137
  name: NonEmptyString,
104
138
  api_key_secret: Schema.String,
139
+ subscription_tier: Schema.optional(
140
+ Schema.Literal("free", "pro", "enterprise")
141
+ ),
142
+ subscription_status: Schema.optional(
143
+ Schema.Literal("active", "past_due", "canceled", "incomplete")
144
+ ),
145
+ expires_at: Schema.optional(Schema.NullOr(Timestamp)),
105
146
  created_at: Timestamp
106
147
  });
107
148
  var Token = Schema.Struct({
@@ -112,6 +153,38 @@ var Token = Schema.Struct({
112
153
  expires_at: Schema.NullOr(Timestamp),
113
154
  created_at: Timestamp
114
155
  });
156
+ var Mandate = Schema.Struct({
157
+ id: MandateId,
158
+ project_id: ProjectId,
159
+ customer_id: Schema.NullOr(CustomerId),
160
+ type: MandateType,
161
+ status: MandateStatus,
162
+ principal_id: Schema.String,
163
+ max_amount: Schema.Number,
164
+ currency: Schema.String,
165
+ permitted_vendors: Schema.NullOr(Schema.Array(Schema.String)),
166
+ valid_from: Timestamp,
167
+ valid_until: Timestamp,
168
+ credential_jwt: Schema.String,
169
+ public_key: Schema.String,
170
+ signature: Schema.String,
171
+ parent_mandate_id: Schema.NullOr(MandateId),
172
+ payment_id: Schema.NullOr(PaymentId),
173
+ created_at: Timestamp,
174
+ consumed_at: Schema.NullOr(Timestamp),
175
+ metadata_json: Metadata
176
+ });
177
+ var AgentSession = Schema.Struct({
178
+ id: AgentSessionId,
179
+ project_id: ProjectId,
180
+ context_id: Schema.String,
181
+ agent_card_url: UrlString,
182
+ capabilities: Schema.Any,
183
+ auth_scheme: Schema.Literal("bearer", "mandate"),
184
+ status: Schema.String,
185
+ created_at: Timestamp,
186
+ expires_at: Timestamp
187
+ });
115
188
  var PaginationMeta = Schema.Struct({
116
189
  total: Schema.NullOr(Schema.Number),
117
190
  limit: Schema.Number,
@@ -125,6 +198,8 @@ var WebhookEventType = Schema.Literal(
125
198
  "payment.success",
126
199
  "payment.failed",
127
200
  "subscription.created",
201
+ "subscription.activated",
202
+ "subscription.renewed",
128
203
  "subscription.payment_succeeded",
129
204
  "subscription.payment_failed",
130
205
  "subscription.renewal_due",
@@ -149,13 +224,15 @@ var WebhookEvent = Schema.Struct({
149
224
  created: Schema.optional(Schema.Number)
150
225
  });
151
226
  var CreateCheckoutParams = Schema.Struct({
152
- amount: Schema.optional(MinorUnitsInt),
227
+ amount: Schema.optional(NprAmount),
153
228
  currency: Schema.optionalWith(Schema.String, { default: () => "NPR" }),
154
229
  provider: Provider,
155
230
  returnUrl: UrlString,
156
231
  cancelUrl: Schema.optional(UrlString),
157
232
  metadata: Schema.optional(Metadata),
158
- subscriptionId: Schema.optional(SubscriptionId)
233
+ subscriptionId: Schema.optional(SubscriptionId),
234
+ customerId: Schema.optional(CustomerId),
235
+ mandate_id: Schema.optional(MandateId)
159
236
  }).pipe(
160
237
  Schema.filter((data) => {
161
238
  if (!data.subscriptionId && !data.amount) {
@@ -167,6 +244,7 @@ var CreateCheckoutParams = Schema.Struct({
167
244
  var CheckoutSession = Schema.Struct({
168
245
  id: CheckoutSessionId,
169
246
  checkout_url: UrlString,
247
+ qr_string: Schema.optional(Schema.String),
170
248
  payment_method: Schema.Struct({
171
249
  type: Provider,
172
250
  url: Schema.optional(UrlString),
@@ -200,22 +278,27 @@ var UpdateCustomerParams = Schema.Struct({
200
278
  email: Schema.optional(Email),
201
279
  name: Schema.optional(NonEmptyString),
202
280
  phone: Schema.optional(Schema.String),
281
+ tier: Schema.optional(Schema.String),
282
+ merchant_customer_id: Schema.optional(Schema.String),
203
283
  metadata: Schema.optional(Metadata)
204
284
  });
205
285
  var CreateSubscriptionParams = Schema.Struct({
206
286
  customer_id: CustomerId,
207
- amount: MinorUnitsInt,
287
+ amount: NprAmount,
208
288
  currency: Schema.optionalWith(Schema.String, { default: () => "NPR" }),
209
289
  interval: SubscriptionInterval,
210
290
  interval_count: Schema.optional(Schema.Number),
211
291
  project_id: Schema.optional(ProjectId),
292
+ customer_email: Schema.optional(Schema.String),
212
293
  auto_send_link: Schema.optional(Schema.Boolean),
213
294
  metadata: Schema.optional(Metadata)
214
295
  });
215
296
  var CallbackQueryParams = Schema.Struct({
216
297
  payment_id: Schema.optional(Schema.String),
217
298
  data: Schema.optional(Schema.String),
218
- pidx: Schema.optional(Schema.String)
299
+ pidx: Schema.optional(Schema.String),
300
+ /** HamroPay-specific: the gateway's own transactionId returned on callback. */
301
+ ref_id: Schema.optional(Schema.String)
219
302
  });
220
303
  var ListSubscriptionsParams = Schema.Struct({
221
304
  limit: Schema.optional(Schema.NumberFromString),
@@ -233,7 +316,8 @@ var PayArkConfig = Schema.Struct({
233
316
  baseUrl: Schema.optional(Schema.String),
234
317
  timeout: Schema.optional(Schema.Number),
235
318
  maxRetries: Schema.optional(Schema.Number),
236
- sandbox: Schema.optional(Schema.Boolean)
319
+ sandbox: Schema.optional(Schema.Boolean),
320
+ signingPrivateKey: Schema.optional(Schema.String)
237
321
  });
238
322
  var PayArkErrorBody = Schema.Struct({
239
323
  error: Schema.String,
@@ -243,21 +327,30 @@ var IndustrialError = class extends Schema.TaggedError()(
243
327
  "IndustrialError",
244
328
  {
245
329
  error: Schema.String,
246
- details: Schema.optional(Schema.Any)
330
+ details: Schema.optional(Schema.Any),
331
+ code: Schema.optional(Schema.String),
332
+ doc_url: Schema.optional(Schema.String),
333
+ suggestion: Schema.optional(Schema.String)
247
334
  }
248
335
  ) {
249
336
  };
250
337
  var AuthenticationError = class extends Schema.TaggedError()(
251
338
  "AuthenticationError",
252
339
  {
253
- error: Schema.String
340
+ error: Schema.String,
341
+ code: Schema.optional(Schema.String),
342
+ doc_url: Schema.optional(Schema.String),
343
+ suggestion: Schema.optional(Schema.String)
254
344
  }
255
345
  ) {
256
346
  };
257
347
  var NotFoundError = class extends Schema.TaggedError()(
258
348
  "NotFoundError",
259
349
  {
260
- error: Schema.String
350
+ error: Schema.String,
351
+ code: Schema.optional(Schema.String),
352
+ doc_url: Schema.optional(Schema.String),
353
+ suggestion: Schema.optional(Schema.String)
261
354
  }
262
355
  ) {
263
356
  };
@@ -265,14 +358,43 @@ var InternalServerError = class extends Schema.TaggedError()(
265
358
  "InternalServerError",
266
359
  {
267
360
  error: Schema.String,
268
- details: Schema.optional(Schema.Any)
361
+ details: Schema.optional(Schema.Any),
362
+ code: Schema.optional(Schema.String),
363
+ doc_url: Schema.optional(Schema.String),
364
+ suggestion: Schema.optional(Schema.String)
269
365
  }
270
366
  ) {
271
367
  };
272
368
  var ConflictError = class extends Schema.TaggedError()(
273
369
  "ConflictError",
274
370
  {
275
- error: Schema.String
371
+ error: Schema.String,
372
+ code: Schema.optional(Schema.String),
373
+ doc_url: Schema.optional(Schema.String),
374
+ suggestion: Schema.optional(Schema.String)
375
+ }
376
+ ) {
377
+ };
378
+ var MandateViolationError = class extends Schema.TaggedError()(
379
+ "MandateViolationError",
380
+ {
381
+ error: Schema.String,
382
+ mandateId: Schema.optional(Schema.String),
383
+ code: Schema.optional(Schema.String),
384
+ doc_url: Schema.optional(Schema.String),
385
+ suggestion: Schema.optional(Schema.String)
386
+ }
387
+ ) {
388
+ };
389
+ var MandateExpiredError = class extends Schema.TaggedError()(
390
+ "MandateExpiredError",
391
+ {
392
+ error: Schema.String,
393
+ mandateId: MandateId,
394
+ expiredAt: Timestamp,
395
+ code: Schema.optional(Schema.String),
396
+ doc_url: Schema.optional(Schema.String),
397
+ suggestion: Schema.optional(Schema.String)
276
398
  }
277
399
  ) {
278
400
  };
@@ -363,7 +485,22 @@ var AutomationGroup = HttpApiGroup.make("automation").add(
363
485
  HttpApiEndpoint.post("reaper", "/reaper").addSuccess(
364
486
  Schema.Struct({
365
487
  message: Schema.String,
366
- count: Schema.Number
488
+ count: Schema.Number,
489
+ purged_projects: Schema.Number
490
+ })
491
+ ).addError(InternalServerError, { status: 500 })
492
+ ).add(
493
+ HttpApiEndpoint.post("processRenewals", "/process-renewals").addSuccess(
494
+ Schema.Struct({
495
+ message: Schema.String,
496
+ emails_sent: Schema.Number
497
+ })
498
+ ).addError(InternalServerError, { status: 500 })
499
+ ).add(
500
+ HttpApiEndpoint.post("processGracePeriod", "/process-grace-period").addSuccess(
501
+ Schema.Struct({
502
+ message: Schema.String,
503
+ marked_past_due: Schema.Number
367
504
  })
368
505
  ).addError(InternalServerError, { status: 500 })
369
506
  ).prefix("/v1/automation").middleware(CronSecurity);
@@ -389,10 +526,30 @@ var TokensGroup = HttpApiGroup.make("tokens").add(
389
526
  ).prefix("/v1/tokens").middleware(UserSecurity);
390
527
  var ProjectsGroup = HttpApiGroup.make("projects").add(
391
528
  HttpApiEndpoint.get("list", "/").addSuccess(Schema.Array(Project)).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
392
- ).prefix("/v1/projects").middleware(SecurityMiddleware);
529
+ ).add(
530
+ HttpApiEndpoint.post("upgrade", "/:id/upgrade").addSuccess(Project).setPath(Schema.Struct({ id: ProjectId })).setPayload(Schema.Struct({ tier: Schema.Literal("pro", "enterprise") })).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
531
+ ).prefix("/v1/projects").middleware(UserSecurity);
532
+ var PaymentCallbackQueryParams = Schema.Struct({
533
+ payment_id: Schema.optional(Schema.String),
534
+ data: Schema.optional(Schema.String),
535
+ pidx: Schema.optional(Schema.String),
536
+ /** HamroPay-specific: the gateway's own transactionId returned on callback. */
537
+ ref_id: Schema.optional(Schema.String),
538
+ /** Supabase Auth: access_token and refresh_token can be in the fragment or query */
539
+ access_token: Schema.optional(Schema.String),
540
+ refresh_token: Schema.optional(Schema.String),
541
+ code: Schema.optional(Schema.String)
542
+ });
393
543
  var CallbacksGroup = HttpApiGroup.make("callbacks").add(
394
- HttpApiEndpoint.get("handle", "/:provider").addSuccess(Schema.Any).setPath(Schema.Struct({ provider: Schema.String })).setUrlParams(CallbackQueryParams).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
544
+ HttpApiEndpoint.get("handle", "/:provider").addSuccess(Schema.Any).setPath(Schema.Struct({ provider: Schema.String })).setUrlParams(PaymentCallbackQueryParams).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 })
395
545
  ).prefix("/v1/callback");
546
+ var AuthCallbackQueryParams = Schema.Struct({
547
+ code: Schema.optional(Schema.String),
548
+ next: Schema.optional(Schema.String)
549
+ });
550
+ var AuthGroup = HttpApiGroup.make("auth").add(
551
+ HttpApiEndpoint.post("callback", "/callback").addSuccess(Schema.Any).setUrlParams(AuthCallbackQueryParams).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
552
+ ).prefix("/auth");
396
553
  var RealtimeGroup = HttpApiGroup.make("realtime").add(
397
554
  HttpApiEndpoint.get("connect", "/").addSuccess(Schema.Any).setUrlParams(Schema.Struct({ token: Schema.String })).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
398
555
  ).add(
@@ -403,22 +560,92 @@ var RealtimeGroup = HttpApiGroup.make("realtime").add(
403
560
  })
404
561
  ).setPayload(RealtimeTriggerPayload).setUrlParams(Schema.Struct({ token: Schema.optional(Schema.String) })).addError(AuthenticationError, { status: 401 }).addError(InternalServerError, { status: 500 })
405
562
  ).prefix("/v1/realtime");
406
- var PayArkApi = 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 });
563
+ var MandatesGroup = HttpApiGroup.make("mandates").add(
564
+ HttpApiEndpoint.post("registerIntent", "/intent").addSuccess(Mandate, { status: 201 }).setPayload(
565
+ Schema.Struct({
566
+ principal_id: Schema.String,
567
+ max_amount: Schema.Number,
568
+ currency: Schema.String,
569
+ valid_until: Timestamp,
570
+ permitted_vendors: Schema.optional(Schema.Array(Schema.String)),
571
+ credential_jwt: Schema.String,
572
+ public_key: Schema.String,
573
+ customer_id: Schema.optional(CustomerId)
574
+ })
575
+ ).addError(AuthenticationError, { status: 401 }).addError(IndustrialError, { status: 400 })
576
+ ).add(
577
+ HttpApiEndpoint.get("retrieve", "/:id").addSuccess(Mandate).setPath(Schema.Struct({ id: MandateId })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 })
578
+ ).prefix("/v1/mandates").middleware(SecurityMiddleware);
579
+ var SandboxGroup = HttpApiGroup.make("sandbox").add(
580
+ HttpApiEndpoint.post("init", "/init").addSuccess(
581
+ Schema.Struct({
582
+ projectId: Schema.String,
583
+ apiKey: Schema.optional(Schema.String),
584
+ expiresAt: Timestamp,
585
+ session: Schema.optional(
586
+ Schema.Struct({
587
+ access_token: Schema.String,
588
+ refresh_token: Schema.String
589
+ })
590
+ )
591
+ })
592
+ ).addError(InternalServerError, { status: 500 })
593
+ ).prefix("/v1/sandbox").middleware(UserSecurity);
594
+ var DiscoveryGroup = HttpApiGroup.make("discovery").add(
595
+ HttpApiEndpoint.get("agentCard", "/agent.json").addSuccess(Schema.Any).addError(InternalServerError, { status: 500 })
596
+ ).prefix("/.well-known");
597
+ var SigningKeysGroup = HttpApiGroup.make("signingKeys").add(
598
+ HttpApiEndpoint.post("generate", "/").addSuccess(
599
+ Schema.Struct({
600
+ id: Schema.String,
601
+ publicKey: Schema.String,
602
+ privateKey: Schema.String,
603
+ algorithm: Schema.String,
604
+ createdAt: Timestamp
605
+ }),
606
+ { status: 201 }
607
+ ).setPath(Schema.Struct({ id: ProjectId })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 })
608
+ ).add(
609
+ HttpApiEndpoint.get("get", "/").addSuccess(
610
+ Schema.Struct({
611
+ id: Schema.String,
612
+ publicKey: Schema.String,
613
+ algorithm: Schema.String,
614
+ createdAt: Timestamp
615
+ })
616
+ ).setPath(Schema.Struct({ id: ProjectId })).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(InternalServerError, { status: 500 })
617
+ ).prefix("/v1/projects/:id/signing-keys").middleware(UserSecurity);
618
+ var PayArkApi = HttpApi.make("PayArkApi").add(CheckoutGroup).add(PaymentsGroup).add(CustomersGroup).add(SubscriptionsGroup).add(AutomationGroup).add(TokensGroup).add(ProjectsGroup).add(CallbacksGroup).add(AuthGroup).add(MandatesGroup).add(DiscoveryGroup).add(RealtimeGroup).add(SandboxGroup).add(SigningKeysGroup).addError(AuthenticationError, { status: 401 }).addError(NotFoundError, { status: 404 }).addError(MandateViolationError, { status: 403 }).addError(MandateExpiredError, { status: 410 }).addError(ConflictError, { status: 409 }).addError(InternalServerError, { status: 500 }).addError(IndustrialError, { status: 400 });
407
619
  var PayArkEffectError = class extends Data.TaggedError("PayArkEffectError") {
408
620
  /** Human-readable representation for logging/debugging. */
409
621
  toString() {
410
- return `[PayArkEffectError: ${this.code}] ${this.message} (HTTP ${this.statusCode})`;
622
+ return `[PayArkEffectError: ${this.code}] ${this.localizedMessage || this.message} (HTTP ${this.statusCode})`;
411
623
  }
412
624
  };
625
+ var MandateViolationError2 = class extends Data.TaggedError(
626
+ "MandateViolationError"
627
+ ) {
628
+ statusCode = 403;
629
+ code = "mandate_violation";
630
+ };
631
+ var MandateExpiredError2 = class extends Data.TaggedError(
632
+ "MandateExpiredError"
633
+ ) {
634
+ statusCode = 410;
635
+ code = "mandate_expired";
636
+ };
413
637
 
414
638
  // src/http.ts
415
- var SDK_VERSION = "0.1.0";
639
+ var SDK_VERSION = "0.1.8";
416
640
  var PayArkConfigService = class extends Context.Tag("PayArkConfigService")() {
417
641
  };
418
642
  var request = (method, path, options) => Effect.gen(function* (_) {
419
643
  const config = yield* _(PayArkConfigService);
420
644
  const client = yield* _(HttpClient.HttpClient);
421
- const baseUrl = (config.baseUrl ?? "https://payark-api.codimo-dev.workers.dev").replace(/\/+$/, "");
645
+ const baseUrl = (config.baseUrl ?? "https://api.payark.dev").replace(
646
+ /\/+$/,
647
+ ""
648
+ );
422
649
  const url = new URL(`${baseUrl}${path}`);
423
650
  if (options?.query) {
424
651
  for (const [key, value] of Object.entries(options.query)) {
@@ -447,7 +674,8 @@ var request = (method, path, options) => Effect.gen(function* (_) {
447
674
  (e) => new PayArkEffectError({
448
675
  message: `Invalid request body: ${String(e)}`,
449
676
  statusCode: 400,
450
- code: "invalid_request_error"
677
+ code: "invalid_request_error",
678
+ localizedMessage: getLocalizedError("invalid_request_error")
451
679
  })
452
680
  )
453
681
  )
@@ -459,7 +687,8 @@ var request = (method, path, options) => Effect.gen(function* (_) {
459
687
  (e) => new PayArkEffectError({
460
688
  message: `Network error: ${e.message}`,
461
689
  statusCode: 0,
462
- code: "connection_error"
690
+ code: "connection_error",
691
+ localizedMessage: getLocalizedError("connection_error")
463
692
  })
464
693
  )
465
694
  )
@@ -472,7 +701,8 @@ var request = (method, path, options) => Effect.gen(function* (_) {
472
701
  (e) => new PayArkEffectError({
473
702
  message: `Failed to parse response: ${String(e)}`,
474
703
  statusCode: response.status,
475
- code: "api_error"
704
+ code: "api_error",
705
+ localizedMessage: getLocalizedError("api_error")
476
706
  })
477
707
  )
478
708
  )
@@ -489,11 +719,22 @@ var request = (method, path, options) => Effect.gen(function* (_) {
489
719
  message: errorBody?.error || `Request failed with status ${response.status}`,
490
720
  statusCode: response.status,
491
721
  code: mapStatusToCode(response.status),
492
- raw: errorBody
722
+ raw: errorBody,
723
+ localizedMessage: getLocalizedError(mapStatusToCode(response.status))
493
724
  })
494
725
  )
495
726
  );
496
- });
727
+ }).pipe(
728
+ Effect.retry(
729
+ Schedule.exponential("200 millis").pipe(
730
+ Schedule.upTo("5 seconds"),
731
+ // Only retry connection-level or 429/5xx transient errors:
732
+ Schedule.check((error) => {
733
+ return error.code === "connection_error" || error.code === "rate_limit_error" || error.statusCode >= 500;
734
+ })
735
+ )
736
+ )
737
+ );
497
738
  function mapStatusToCode(status) {
498
739
  if (status === 401) return "authentication_error";
499
740
  if (status === 403) return "permission_error";
@@ -503,6 +744,26 @@ function mapStatusToCode(status) {
503
744
  if (status >= 500) return "api_error";
504
745
  return "unknown_error";
505
746
  }
747
+ function getLocalizedError(code) {
748
+ switch (code) {
749
+ case "authentication_error":
750
+ return "Your API key is missing or invalid. Please check your PayArk credentials.";
751
+ case "permission_error":
752
+ return "You don't have permission to perform this action.";
753
+ case "invalid_request_error":
754
+ return "The request is missing required parameters or they are invalid. Please check your implementation.";
755
+ case "not_found_error":
756
+ return "The requested resource could not be found.";
757
+ case "rate_limit_error":
758
+ return "You are making too many requests to PayArk. Please wait a moment before trying again.";
759
+ case "api_error":
760
+ return "PayArk servers are currently experiencing issues. Please try again later.";
761
+ case "connection_error":
762
+ return "Could not connect to PayArk. Please check your internet connection.";
763
+ default:
764
+ return "An unexpected error occurred. Please contact support if the issue persists.";
765
+ }
766
+ }
506
767
 
507
768
  // src/resources/checkout.ts
508
769
  var CheckoutEffect = class {
@@ -576,6 +837,261 @@ var ProjectsEffect = class {
576
837
  );
577
838
  }
578
839
  };
840
+ var CustomersEffect = class {
841
+ constructor(config) {
842
+ this.config = config;
843
+ }
844
+ /**
845
+ * Create a new customer for a project.
846
+ */
847
+ create(params) {
848
+ return request("POST", "/v1/customers", { body: params }).pipe(
849
+ Effect.flatMap(Schema.decodeUnknown(Customer)),
850
+ Effect.provideService(PayArkConfigService, this.config)
851
+ );
852
+ }
853
+ /**
854
+ * List customers for the authenticated project.
855
+ */
856
+ list(params = {}) {
857
+ return request("GET", "/v1/customers", {
858
+ query: {
859
+ limit: params.limit,
860
+ offset: params.offset,
861
+ projectId: params.projectId,
862
+ email: params.email,
863
+ merchant_customer_id: params.merchant_customer_id
864
+ }
865
+ }).pipe(
866
+ Effect.flatMap(Schema.decodeUnknown(PaginatedResponse(Customer))),
867
+ Effect.provideService(PayArkConfigService, this.config)
868
+ );
869
+ }
870
+ /**
871
+ * Retrieve a single customer by ID.
872
+ */
873
+ retrieve(id) {
874
+ return request(
875
+ "GET",
876
+ `/v1/customers/${encodeURIComponent(id)}`
877
+ ).pipe(
878
+ Effect.flatMap(Schema.decodeUnknown(Customer)),
879
+ Effect.provideService(PayArkConfigService, this.config)
880
+ );
881
+ }
882
+ /**
883
+ * Update a customer.
884
+ */
885
+ update(id, params) {
886
+ return request(
887
+ "PATCH",
888
+ `/v1/customers/${encodeURIComponent(id)}`,
889
+ {
890
+ body: params
891
+ }
892
+ ).pipe(
893
+ Effect.flatMap(Schema.decodeUnknown(Customer)),
894
+ Effect.provideService(PayArkConfigService, this.config)
895
+ );
896
+ }
897
+ /**
898
+ * Delete a customer.
899
+ */
900
+ delete(id) {
901
+ return request(
902
+ "DELETE",
903
+ `/v1/customers/${encodeURIComponent(id)}`
904
+ ).pipe(Effect.provideService(PayArkConfigService, this.config));
905
+ }
906
+ };
907
+ var SubscriptionsEffect = class {
908
+ constructor(config) {
909
+ this.config = config;
910
+ }
911
+ /**
912
+ * Create a new subscription.
913
+ */
914
+ create(params) {
915
+ return request("POST", "/v1/subscriptions", { body: params }).pipe(
916
+ Effect.flatMap(Schema.decodeUnknown(Subscription)),
917
+ Effect.provideService(PayArkConfigService, this.config)
918
+ );
919
+ }
920
+ /**
921
+ * List subscriptions for the authenticated project.
922
+ */
923
+ list(params = {}) {
924
+ return request("GET", "/v1/subscriptions", {
925
+ query: {
926
+ limit: params.limit,
927
+ offset: params.offset,
928
+ projectId: params.projectId,
929
+ customerId: params.customerId,
930
+ status: params.status
931
+ }
932
+ }).pipe(
933
+ Effect.flatMap(Schema.decodeUnknown(PaginatedResponse(Subscription))),
934
+ Effect.provideService(PayArkConfigService, this.config)
935
+ );
936
+ }
937
+ /**
938
+ * Retrieve a single subscription by ID.
939
+ */
940
+ retrieve(id) {
941
+ return request(
942
+ "GET",
943
+ `/v1/subscriptions/${encodeURIComponent(id)}`
944
+ ).pipe(
945
+ Effect.flatMap(Schema.decodeUnknown(Subscription)),
946
+ Effect.provideService(PayArkConfigService, this.config)
947
+ );
948
+ }
949
+ /**
950
+ * Cancel a subscription.
951
+ */
952
+ cancel(id) {
953
+ return request(
954
+ "POST",
955
+ `/v1/subscriptions/${encodeURIComponent(id)}/cancel`
956
+ ).pipe(
957
+ Effect.flatMap(Schema.decodeUnknown(Subscription)),
958
+ Effect.provideService(PayArkConfigService, this.config)
959
+ );
960
+ }
961
+ /**
962
+ * Activate a subscription (returns payment info).
963
+ */
964
+ activate(id, params) {
965
+ const activateSchema = Schema.Struct({
966
+ checkout_url: Schema.String,
967
+ payment_id: Schema.String
968
+ });
969
+ return request(
970
+ "POST",
971
+ `/v1/subscriptions/${encodeURIComponent(id)}/activate`,
972
+ { body: params }
973
+ ).pipe(
974
+ Effect.flatMap(Schema.decodeUnknown(activateSchema)),
975
+ Effect.provideService(PayArkConfigService, this.config)
976
+ );
977
+ }
978
+ };
979
+ var MandatesEffect = class {
980
+ constructor(config) {
981
+ this.config = config;
982
+ }
983
+ /**
984
+ * Register a mandate intent.
985
+ */
986
+ registerIntent(params) {
987
+ return request("POST", "/v1/mandates/intent", {
988
+ body: params
989
+ }).pipe(
990
+ Effect.flatMap(Schema.decodeUnknown(Mandate)),
991
+ Effect.provideService(PayArkConfigService, this.config)
992
+ );
993
+ }
994
+ /**
995
+ * Retrieve a mandate.
996
+ */
997
+ retrieve(id) {
998
+ return request(
999
+ "GET",
1000
+ `/v1/mandates/${encodeURIComponent(id)}`
1001
+ ).pipe(
1002
+ Effect.flatMap(Schema.decodeUnknown(Mandate)),
1003
+ Effect.provideService(PayArkConfigService, this.config)
1004
+ );
1005
+ }
1006
+ };
1007
+ var TokensEffect = class {
1008
+ constructor(config) {
1009
+ this.config = config;
1010
+ }
1011
+ /**
1012
+ * Create a new token.
1013
+ */
1014
+ create(params) {
1015
+ const createTokenSchema = Schema.Struct({
1016
+ ...Token.fields,
1017
+ token: Schema.String
1018
+ });
1019
+ return request("POST", "/v1/tokens", { body: params }).pipe(
1020
+ Effect.flatMap(Schema.decodeUnknown(createTokenSchema)),
1021
+ Effect.provideService(PayArkConfigService, this.config)
1022
+ );
1023
+ }
1024
+ /**
1025
+ * List all tokens.
1026
+ */
1027
+ list() {
1028
+ return request("GET", "/v1/tokens").pipe(
1029
+ Effect.flatMap(Schema.decodeUnknown(Schema.Array(Token))),
1030
+ Effect.provideService(PayArkConfigService, this.config)
1031
+ );
1032
+ }
1033
+ /**
1034
+ * Delete/revoke a token.
1035
+ */
1036
+ delete(id) {
1037
+ return request("DELETE", `/v1/tokens/${encodeURIComponent(id)}`).pipe(
1038
+ Effect.provideService(PayArkConfigService, this.config)
1039
+ );
1040
+ }
1041
+ };
1042
+ var RealtimeEffect = class {
1043
+ constructor(config) {
1044
+ this.config = config;
1045
+ }
1046
+ /**
1047
+ * Manually trigger a realtime event.
1048
+ */
1049
+ trigger(params) {
1050
+ const triggerSchema = Schema.Struct({
1051
+ status: Schema.String,
1052
+ event: Schema.optional(Schema.String)
1053
+ });
1054
+ return request("POST", "/v1/realtime/trigger", {
1055
+ body: params,
1056
+ query: { token: params.token }
1057
+ }).pipe(
1058
+ Effect.flatMap(Schema.decodeUnknown(triggerSchema)),
1059
+ Effect.provideService(PayArkConfigService, this.config)
1060
+ );
1061
+ }
1062
+ };
1063
+ var AutomationEffect = class {
1064
+ constructor(config) {
1065
+ this.config = config;
1066
+ }
1067
+ /**
1068
+ * Send reminders.
1069
+ */
1070
+ reminders() {
1071
+ const automationSchema = Schema.Struct({
1072
+ message: Schema.String,
1073
+ count: Schema.Number
1074
+ });
1075
+ return request("POST", "/v1/automation/reminders").pipe(
1076
+ Effect.flatMap(Schema.decodeUnknown(automationSchema)),
1077
+ Effect.provideService(PayArkConfigService, this.config)
1078
+ );
1079
+ }
1080
+ /**
1081
+ * Run reaper.
1082
+ */
1083
+ reaper() {
1084
+ const reaperSchema = Schema.Struct({
1085
+ message: Schema.String,
1086
+ count: Schema.Number,
1087
+ purged_projects: Schema.Number
1088
+ });
1089
+ return request("POST", "/v1/automation/reaper").pipe(
1090
+ Effect.flatMap(Schema.decodeUnknown(reaperSchema)),
1091
+ Effect.provideService(PayArkConfigService, this.config)
1092
+ );
1093
+ }
1094
+ };
579
1095
 
580
1096
  // src/index.ts
581
1097
  var makeClient = (options) => HttpApiClient.make(PayArkApi, options);
@@ -591,6 +1107,12 @@ var PayArkEffect = class {
591
1107
  _checkout;
592
1108
  _payments;
593
1109
  _projects;
1110
+ _customers;
1111
+ _subscriptions;
1112
+ _mandates;
1113
+ _tokens;
1114
+ _realtime;
1115
+ _automation;
594
1116
  /**
595
1117
  * Checkout sessions resource (Effect).
596
1118
  */
@@ -618,6 +1140,60 @@ var PayArkEffect = class {
618
1140
  }
619
1141
  return this._projects;
620
1142
  }
1143
+ /**
1144
+ * Customers resource (Effect).
1145
+ */
1146
+ get customers() {
1147
+ if (!this._customers) {
1148
+ this._customers = new CustomersEffect(this.config);
1149
+ }
1150
+ return this._customers;
1151
+ }
1152
+ /**
1153
+ * Subscriptions resource (Effect).
1154
+ */
1155
+ get subscriptions() {
1156
+ if (!this._subscriptions) {
1157
+ this._subscriptions = new SubscriptionsEffect(this.config);
1158
+ }
1159
+ return this._subscriptions;
1160
+ }
1161
+ /**
1162
+ * Mandates resource (Effect).
1163
+ */
1164
+ get mandates() {
1165
+ if (!this._mandates) {
1166
+ this._mandates = new MandatesEffect(this.config);
1167
+ }
1168
+ return this._mandates;
1169
+ }
1170
+ /**
1171
+ * Tokens resource (Effect).
1172
+ */
1173
+ get tokens() {
1174
+ if (!this._tokens) {
1175
+ this._tokens = new TokensEffect(this.config);
1176
+ }
1177
+ return this._tokens;
1178
+ }
1179
+ /**
1180
+ * Realtime resource (Effect).
1181
+ */
1182
+ get realtime() {
1183
+ if (!this._realtime) {
1184
+ this._realtime = new RealtimeEffect(this.config);
1185
+ }
1186
+ return this._realtime;
1187
+ }
1188
+ /**
1189
+ * Automation resource (Effect).
1190
+ */
1191
+ get automation() {
1192
+ if (!this._automation) {
1193
+ this._automation = new AutomationEffect(this.config);
1194
+ }
1195
+ return this._automation;
1196
+ }
621
1197
  };
622
1198
  var PayArk = class _PayArk extends Context.Tag("@payark/sdk-effect/PayArk")() {
623
1199
  /**
@@ -626,6 +1202,6 @@ var PayArk = class _PayArk extends Context.Tag("@payark/sdk-effect/PayArk")() {
626
1202
  static Live = (config) => Layer.succeed(_PayArk, new PayArkEffect(config));
627
1203
  };
628
1204
 
629
- export { AuthContext, AuthenticationError, AutomationGroup, CallbackQueryParams, CallbacksGroup, 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, ProjectsGroup, Provider, RealtimeGroup, RealtimeTriggerPayload, SecurityMiddleware, Subscription, SubscriptionId, SubscriptionInterval, SubscriptionStatus, SubscriptionsGroup, Timestamp, Timestamps, Token, TokenId, TokensGroup, UpdateCustomerParams, UserSecurity, WebhookEvent, WebhookEventType, makeClient };
1205
+ export { AgentSession, AgentSessionId, AuthCallbackQueryParams, AuthContext, AuthGroup, AuthenticationError, AutomationGroup, CallbackQueryParams, CallbacksGroup, CheckoutGroup, CheckoutSession, CheckoutSessionId, ConflictError, CreateCheckoutParams, CreateCustomerParams, CreateSubscriptionParams, CronSecurity, Customer, CustomerId, CustomerLifecycle, CustomersGroup, DiscoveryGroup, Email, Id, IndustrialError, InternalServerError, ListCustomersParams, ListPaymentsParams, ListSubscriptionsParams, Mandate, MandateExpiredError2 as MandateExpiredError, MandateId, MandateStatus, MandateType, MandateViolationError2 as MandateViolationError, MandatesGroup, Metadata, NotFoundError, PaginatedResponse, PaginationMeta, PayArk, PayArkApi, PayArkClient, PayArkConfig, PayArkEffect, PayArkEffectError, PayArkErrorBody, Payment, PaymentCallbackQueryParams, PaymentId, PaymentStatus, PaymentsGroup, Project, ProjectId, ProjectsGroup, Provider, RealtimeGroup, RealtimeTriggerPayload, SandboxGroup, SecurityMiddleware, SigningKeysGroup, Subscription, SubscriptionId, SubscriptionInterval, SubscriptionStatus, SubscriptionsGroup, Timestamp, Timestamps, Token, TokenId, TokensGroup, UpdateCustomerParams, UserSecurity, WebhookEvent, WebhookEventType, makeClient };
630
1206
  //# sourceMappingURL=index.mjs.map
631
1207
  //# sourceMappingURL=index.mjs.map