@phpsandbox/sdk 0.3.5 → 0.5.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.
@@ -518,7 +518,7 @@ __export(core_exports2, {
518
518
  parse: () => parse,
519
519
  parseAsync: () => parseAsync,
520
520
  prettifyError: () => prettifyError,
521
- process: () => process,
521
+ process: () => process2,
522
522
  regexes: () => regexes_exports,
523
523
  registry: () => registry,
524
524
  safeDecode: () => safeDecode,
@@ -11443,7 +11443,7 @@ function initializeContext(params) {
11443
11443
  external: params?.external ?? void 0
11444
11444
  };
11445
11445
  }
11446
- function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
11446
+ function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11447
11447
  var _a3;
11448
11448
  const def = schema._zod.def;
11449
11449
  const seen = ctx.seen.get(schema);
@@ -11480,7 +11480,7 @@ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
11480
11480
  if (parent) {
11481
11481
  if (!result.ref)
11482
11482
  result.ref = parent;
11483
- process(parent, ctx, params);
11483
+ process2(parent, ctx, params);
11484
11484
  ctx.seen.get(parent).isParent = true;
11485
11485
  }
11486
11486
  }
@@ -11768,14 +11768,14 @@ function isTransforming(_schema, _ctx) {
11768
11768
  }
11769
11769
  var createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
11770
11770
  const ctx = initializeContext({ ...params, processors });
11771
- process(schema, ctx);
11771
+ process2(schema, ctx);
11772
11772
  extractDefs(ctx, schema);
11773
11773
  return finalize(ctx, schema);
11774
11774
  };
11775
11775
  var createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
11776
11776
  const { libraryOptions, target } = params ?? {};
11777
11777
  const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
11778
- process(schema, ctx);
11778
+ process2(schema, ctx);
11779
11779
  extractDefs(ctx, schema);
11780
11780
  return finalize(ctx, schema);
11781
11781
  };
@@ -12021,7 +12021,7 @@ var arrayProcessor = (schema, ctx, _json, params) => {
12021
12021
  if (typeof maximum === "number")
12022
12022
  json2.maxItems = maximum;
12023
12023
  json2.type = "array";
12024
- json2.items = process(def.element, ctx, {
12024
+ json2.items = process2(def.element, ctx, {
12025
12025
  ...params,
12026
12026
  path: [...params.path, "items"]
12027
12027
  });
@@ -12033,7 +12033,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
12033
12033
  json2.properties = {};
12034
12034
  const shape = def.shape;
12035
12035
  for (const key in shape) {
12036
- json2.properties[key] = process(shape[key], ctx, {
12036
+ json2.properties[key] = process2(shape[key], ctx, {
12037
12037
  ...params,
12038
12038
  path: [...params.path, "properties", key]
12039
12039
  });
@@ -12056,7 +12056,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
12056
12056
  if (ctx.io === "output")
12057
12057
  json2.additionalProperties = false;
12058
12058
  } else if (def.catchall) {
12059
- json2.additionalProperties = process(def.catchall, ctx, {
12059
+ json2.additionalProperties = process2(def.catchall, ctx, {
12060
12060
  ...params,
12061
12061
  path: [...params.path, "additionalProperties"]
12062
12062
  });
@@ -12065,7 +12065,7 @@ var objectProcessor = (schema, ctx, _json, params) => {
12065
12065
  var unionProcessor = (schema, ctx, json2, params) => {
12066
12066
  const def = schema._zod.def;
12067
12067
  const isExclusive = def.inclusive === false;
12068
- const options = def.options.map((x, i) => process(x, ctx, {
12068
+ const options = def.options.map((x, i) => process2(x, ctx, {
12069
12069
  ...params,
12070
12070
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
12071
12071
  }));
@@ -12077,11 +12077,11 @@ var unionProcessor = (schema, ctx, json2, params) => {
12077
12077
  };
12078
12078
  var intersectionProcessor = (schema, ctx, json2, params) => {
12079
12079
  const def = schema._zod.def;
12080
- const a = process(def.left, ctx, {
12080
+ const a = process2(def.left, ctx, {
12081
12081
  ...params,
12082
12082
  path: [...params.path, "allOf", 0]
12083
12083
  });
12084
- const b = process(def.right, ctx, {
12084
+ const b = process2(def.right, ctx, {
12085
12085
  ...params,
12086
12086
  path: [...params.path, "allOf", 1]
12087
12087
  });
@@ -12098,11 +12098,11 @@ var tupleProcessor = (schema, ctx, _json, params) => {
12098
12098
  json2.type = "array";
12099
12099
  const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
12100
12100
  const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
12101
- const prefixItems = def.items.map((x, i) => process(x, ctx, {
12101
+ const prefixItems = def.items.map((x, i) => process2(x, ctx, {
12102
12102
  ...params,
12103
12103
  path: [...params.path, prefixPath, i]
12104
12104
  }));
12105
- const rest = def.rest ? process(def.rest, ctx, {
12105
+ const rest = def.rest ? process2(def.rest, ctx, {
12106
12106
  ...params,
12107
12107
  path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
12108
12108
  }) : null;
@@ -12142,7 +12142,7 @@ var recordProcessor = (schema, ctx, _json, params) => {
12142
12142
  const keyBag = keyType._zod.bag;
12143
12143
  const patterns = keyBag?.patterns;
12144
12144
  if (def.mode === "loose" && patterns && patterns.size > 0) {
12145
- const valueSchema = process(def.valueType, ctx, {
12145
+ const valueSchema = process2(def.valueType, ctx, {
12146
12146
  ...params,
12147
12147
  path: [...params.path, "patternProperties", "*"]
12148
12148
  });
@@ -12152,12 +12152,12 @@ var recordProcessor = (schema, ctx, _json, params) => {
12152
12152
  }
12153
12153
  } else {
12154
12154
  if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
12155
- json2.propertyNames = process(def.keyType, ctx, {
12155
+ json2.propertyNames = process2(def.keyType, ctx, {
12156
12156
  ...params,
12157
12157
  path: [...params.path, "propertyNames"]
12158
12158
  });
12159
12159
  }
12160
- json2.additionalProperties = process(def.valueType, ctx, {
12160
+ json2.additionalProperties = process2(def.valueType, ctx, {
12161
12161
  ...params,
12162
12162
  path: [...params.path, "additionalProperties"]
12163
12163
  });
@@ -12172,7 +12172,7 @@ var recordProcessor = (schema, ctx, _json, params) => {
12172
12172
  };
12173
12173
  var nullableProcessor = (schema, ctx, json2, params) => {
12174
12174
  const def = schema._zod.def;
12175
- const inner = process(def.innerType, ctx, params);
12175
+ const inner = process2(def.innerType, ctx, params);
12176
12176
  const seen = ctx.seen.get(schema);
12177
12177
  if (ctx.target === "openapi-3.0") {
12178
12178
  seen.ref = def.innerType;
@@ -12183,20 +12183,20 @@ var nullableProcessor = (schema, ctx, json2, params) => {
12183
12183
  };
12184
12184
  var nonoptionalProcessor = (schema, ctx, _json, params) => {
12185
12185
  const def = schema._zod.def;
12186
- process(def.innerType, ctx, params);
12186
+ process2(def.innerType, ctx, params);
12187
12187
  const seen = ctx.seen.get(schema);
12188
12188
  seen.ref = def.innerType;
12189
12189
  };
12190
12190
  var defaultProcessor = (schema, ctx, json2, params) => {
12191
12191
  const def = schema._zod.def;
12192
- process(def.innerType, ctx, params);
12192
+ process2(def.innerType, ctx, params);
12193
12193
  const seen = ctx.seen.get(schema);
12194
12194
  seen.ref = def.innerType;
12195
12195
  json2.default = JSON.parse(JSON.stringify(def.defaultValue));
12196
12196
  };
12197
12197
  var prefaultProcessor = (schema, ctx, json2, params) => {
12198
12198
  const def = schema._zod.def;
12199
- process(def.innerType, ctx, params);
12199
+ process2(def.innerType, ctx, params);
12200
12200
  const seen = ctx.seen.get(schema);
12201
12201
  seen.ref = def.innerType;
12202
12202
  if (ctx.io === "input")
@@ -12204,7 +12204,7 @@ var prefaultProcessor = (schema, ctx, json2, params) => {
12204
12204
  };
12205
12205
  var catchProcessor = (schema, ctx, json2, params) => {
12206
12206
  const def = schema._zod.def;
12207
- process(def.innerType, ctx, params);
12207
+ process2(def.innerType, ctx, params);
12208
12208
  const seen = ctx.seen.get(schema);
12209
12209
  seen.ref = def.innerType;
12210
12210
  let catchValue;
@@ -12219,32 +12219,32 @@ var pipeProcessor = (schema, ctx, _json, params) => {
12219
12219
  const def = schema._zod.def;
12220
12220
  const inIsTransform = def.in._zod.traits.has("$ZodTransform");
12221
12221
  const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
12222
- process(innerType, ctx, params);
12222
+ process2(innerType, ctx, params);
12223
12223
  const seen = ctx.seen.get(schema);
12224
12224
  seen.ref = innerType;
12225
12225
  };
12226
12226
  var readonlyProcessor = (schema, ctx, json2, params) => {
12227
12227
  const def = schema._zod.def;
12228
- process(def.innerType, ctx, params);
12228
+ process2(def.innerType, ctx, params);
12229
12229
  const seen = ctx.seen.get(schema);
12230
12230
  seen.ref = def.innerType;
12231
12231
  json2.readOnly = true;
12232
12232
  };
12233
12233
  var promiseProcessor = (schema, ctx, _json, params) => {
12234
12234
  const def = schema._zod.def;
12235
- process(def.innerType, ctx, params);
12235
+ process2(def.innerType, ctx, params);
12236
12236
  const seen = ctx.seen.get(schema);
12237
12237
  seen.ref = def.innerType;
12238
12238
  };
12239
12239
  var optionalProcessor = (schema, ctx, _json, params) => {
12240
12240
  const def = schema._zod.def;
12241
- process(def.innerType, ctx, params);
12241
+ process2(def.innerType, ctx, params);
12242
12242
  const seen = ctx.seen.get(schema);
12243
12243
  seen.ref = def.innerType;
12244
12244
  };
12245
12245
  var lazyProcessor = (schema, ctx, _json, params) => {
12246
12246
  const innerType = schema._zod.innerType;
12247
- process(innerType, ctx, params);
12247
+ process2(innerType, ctx, params);
12248
12248
  const seen = ctx.seen.get(schema);
12249
12249
  seen.ref = innerType;
12250
12250
  };
@@ -12296,7 +12296,7 @@ function toJSONSchema(input, params) {
12296
12296
  const defs = {};
12297
12297
  for (const entry of registry2._idmap.entries()) {
12298
12298
  const [_, schema] = entry;
12299
- process(schema, ctx2);
12299
+ process2(schema, ctx2);
12300
12300
  }
12301
12301
  const schemas = {};
12302
12302
  const external = {
@@ -12319,7 +12319,7 @@ function toJSONSchema(input, params) {
12319
12319
  return { schemas };
12320
12320
  }
12321
12321
  const ctx = initializeContext({ ...params, processors: allProcessors });
12322
- process(input, ctx);
12322
+ process2(input, ctx);
12323
12323
  extractDefs(ctx, input);
12324
12324
  return finalize(ctx, input);
12325
12325
  }
@@ -12377,7 +12377,7 @@ var JSONSchemaGenerator = class {
12377
12377
  * This must be called before emit().
12378
12378
  */
12379
12379
  process(schema, _params = { path: [], schemaPath: [] }) {
12380
- return process(schema, this.ctx, _params);
12380
+ return process2(schema, this.ctx, _params);
12381
12381
  }
12382
12382
  /**
12383
12383
  * Emit the final JSON Schema after processing.
@@ -14526,6 +14526,466 @@ function date4(params) {
14526
14526
  // node_modules/zod/v4/classic/external.js
14527
14527
  config(en_default());
14528
14528
 
14529
+ // src/customers.ts
14530
+ var customerModeSchema = external_exports.enum(["test", "live"]);
14531
+ var customerSchema = external_exports.object({
14532
+ id: external_exports.string(),
14533
+ externalId: external_exports.string(),
14534
+ email: external_exports.string(),
14535
+ name: external_exports.string().nullable(),
14536
+ source: external_exports.string().nullable(),
14537
+ marketingSubscribed: external_exports.boolean(),
14538
+ suppressionReason: external_exports.string().nullable(),
14539
+ activatedAt: external_exports.string().nullable(),
14540
+ createdAt: external_exports.string().nullable()
14541
+ });
14542
+ var spaceSchema = external_exports.object({
14543
+ id: external_exports.string(),
14544
+ mode: customerModeSchema,
14545
+ enabled: external_exports.boolean(),
14546
+ senderName: external_exports.string().nullable(),
14547
+ senderEmail: external_exports.string().nullable(),
14548
+ replyTo: external_exports.string().nullable(),
14549
+ senderVerified: external_exports.boolean(),
14550
+ domainRecords: external_exports.string().nullable(),
14551
+ provisionedAt: external_exports.string().nullable().optional(),
14552
+ lastRequestAt: external_exports.string().nullable().optional(),
14553
+ processedAt: external_exports.string().nullable().optional()
14554
+ });
14555
+ var journeyInputSchema = external_exports.object({
14556
+ enabled: external_exports.boolean(),
14557
+ subject: external_exports.string(),
14558
+ body: external_exports.string(),
14559
+ delayMinutes: external_exports.number(),
14560
+ activationEvent: external_exports.string()
14561
+ });
14562
+ var journeySchema = journeyInputSchema.extend({
14563
+ kind: external_exports.enum(["welcome", "setup", "purchase"]),
14564
+ version: external_exports.number().int().optional(),
14565
+ startsAt: external_exports.string().nullable().optional(),
14566
+ draft: journeyInputSchema.nullable().optional()
14567
+ });
14568
+ var messageSchema = external_exports.object({
14569
+ id: external_exports.string(),
14570
+ customerId: external_exports.string().nullable(),
14571
+ recipient: external_exports.string(),
14572
+ subject: external_exports.string(),
14573
+ body: external_exports.string(),
14574
+ status: external_exports.string(),
14575
+ error: external_exports.string().nullable(),
14576
+ dueAt: external_exports.string().nullable().optional(),
14577
+ attemptedAt: external_exports.string().nullable().optional(),
14578
+ receivedAt: external_exports.string().nullable().optional(),
14579
+ journeyKind: external_exports.enum(["welcome", "setup", "purchase"]).nullable().optional(),
14580
+ journeyVersion: external_exports.number().int().nullable().optional(),
14581
+ category: external_exports.enum(["marketing", "service"]).optional(),
14582
+ from: external_exports.string().nullable().optional(),
14583
+ replyTo: external_exports.string().nullable().optional(),
14584
+ renderedText: external_exports.string().nullable().optional(),
14585
+ unsubscribeUrl: external_exports.string().nullable().optional(),
14586
+ createdAt: external_exports.string().nullable()
14587
+ });
14588
+ var overviewSchema = external_exports.object({
14589
+ space: spaceSchema.nullable(),
14590
+ customers: external_exports.array(customerSchema),
14591
+ journeys: external_exports.array(journeySchema),
14592
+ messages: external_exports.array(messageSchema),
14593
+ total: external_exports.number(),
14594
+ messageTotal: external_exports.number().optional(),
14595
+ events: external_exports.array(external_exports.string()).optional()
14596
+ });
14597
+ var CustomerRuntime = class {
14598
+ constructor(client) {
14599
+ this.client = client;
14600
+ }
14601
+ async identify(input) {
14602
+ return customerSchema.parse((await this.client.post("/platform/customers/runtime/identify", input)).data);
14603
+ }
14604
+ async linkIdentity(customerId, externalId) {
14605
+ return customerSchema.parse(
14606
+ (await this.client.post(`/platform/customers/runtime/${encodeURIComponent(customerId)}/identities`, {
14607
+ externalId
14608
+ })).data
14609
+ );
14610
+ }
14611
+ async get(customerId) {
14612
+ return customerSchema.parse(
14613
+ (await this.client.get(`/platform/customers/runtime/${encodeURIComponent(customerId)}`)).data
14614
+ );
14615
+ }
14616
+ async event(customerId, input) {
14617
+ return external_exports.object({ id: external_exports.string(), name: external_exports.string() }).parse(
14618
+ (await this.client.post(`/platform/customers/runtime/${encodeURIComponent(customerId)}/events`, input)).data
14619
+ );
14620
+ }
14621
+ async preferences(customerId, input) {
14622
+ return customerSchema.parse(
14623
+ (await this.client.put(`/platform/customers/runtime/${encodeURIComponent(customerId)}/preferences`, input)).data
14624
+ );
14625
+ }
14626
+ async send(customerId, input) {
14627
+ return messageSchema.parse(
14628
+ (await this.client.post(`/platform/customers/runtime/${encodeURIComponent(customerId)}/messages`, input)).data
14629
+ );
14630
+ }
14631
+ };
14632
+ var CustomersApi = class {
14633
+ constructor(client) {
14634
+ this.client = client;
14635
+ this.runtime = new CustomerRuntime(client);
14636
+ }
14637
+ forNotebook(notebookId) {
14638
+ return new NotebookCustomers(notebookId, this.client);
14639
+ }
14640
+ };
14641
+ var NotebookCustomers = class {
14642
+ constructor(notebookId, client) {
14643
+ this.notebookId = notebookId;
14644
+ this.client = client;
14645
+ }
14646
+ async list(mode = "test", query = {}) {
14647
+ return overviewSchema.parse(
14648
+ (await this.client.get(
14649
+ `${this.path(mode)}?${new URLSearchParams(Object.entries(query).map(([key, value]) => [key, String(value)])).toString()}`
14650
+ )).data
14651
+ );
14652
+ }
14653
+ async connect(mode = "test") {
14654
+ return spaceSchema.parse((await this.client.put(this.path(mode), {})).data);
14655
+ }
14656
+ async provision(mode = "test") {
14657
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/provision`, {})).data);
14658
+ }
14659
+ async disable(mode = "test") {
14660
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/disable`, {})).data);
14661
+ }
14662
+ async resume(mode = "test") {
14663
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/resume`, {})).data);
14664
+ }
14665
+ async rotate(mode = "test") {
14666
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/rotate`, {})).data);
14667
+ }
14668
+ async sender(input, mode = "test") {
14669
+ return spaceSchema.parse((await this.client.put(`${this.path(mode)}/sender`, input)).data);
14670
+ }
14671
+ async verifySender(mode = "test") {
14672
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/sender/verify`, {})).data);
14673
+ }
14674
+ async journey(kind, input, mode = "test") {
14675
+ return journeySchema.parse((await this.client.put(`${this.path(mode)}/journeys/${kind}`, input)).data);
14676
+ }
14677
+ path(mode) {
14678
+ return `/platform/customers/sandboxes/${encodeURIComponent(this.notebookId)}/${mode}`;
14679
+ }
14680
+ };
14681
+
14682
+ // src/payments.ts
14683
+ var DEFAULT_PAYMENT_CALLBACK_PATH = "/api/phpsandbox-payments/events";
14684
+ var paymentModeSchema = external_exports.enum(["test", "live"]);
14685
+ var accountSchema = external_exports.object({
14686
+ id: external_exports.string(),
14687
+ mode: paymentModeSchema,
14688
+ chargesEnabled: external_exports.boolean(),
14689
+ payoutsEnabled: external_exports.boolean(),
14690
+ detailsSubmitted: external_exports.boolean(),
14691
+ requirements: external_exports.array(external_exports.string()),
14692
+ disabledReason: external_exports.string().nullable()
14693
+ });
14694
+ var accessSchema = external_exports.object({
14695
+ subscribed: external_exports.boolean(),
14696
+ liveAllowed: external_exports.boolean(),
14697
+ testConfigured: external_exports.boolean(),
14698
+ liveConfigured: external_exports.boolean(),
14699
+ feeBasisPoints: external_exports.number().int().min(0).max(1e4).nullable(),
14700
+ canRead: external_exports.boolean(),
14701
+ canManage: external_exports.boolean(),
14702
+ canRefund: external_exports.boolean(),
14703
+ recoveryEndsAt: external_exports.string().nullable().default(null)
14704
+ });
14705
+ var applicationsSchema = external_exports.object({
14706
+ notebookId: external_exports.string(),
14707
+ applications: external_exports.array(
14708
+ external_exports.object({
14709
+ id: external_exports.string(),
14710
+ url: external_exports.string().nullable(),
14711
+ healthy: external_exports.boolean(),
14712
+ passwordProtected: external_exports.boolean(),
14713
+ deployedAt: external_exports.string().datetime().nullable()
14714
+ })
14715
+ )
14716
+ });
14717
+ var bindingSchema = external_exports.object({
14718
+ target: external_exports.enum(["preview", "publication"]).optional(),
14719
+ id: external_exports.string(),
14720
+ notebookId: external_exports.string(),
14721
+ applicationId: external_exports.string().nullable(),
14722
+ mode: paymentModeSchema,
14723
+ revision: external_exports.number().int(),
14724
+ accountId: external_exports.string(),
14725
+ enabled: external_exports.boolean(),
14726
+ callbackUrl: external_exports.string().nullable(),
14727
+ originUrl: external_exports.string().nullable(),
14728
+ runtimeConfigured: external_exports.boolean()
14729
+ });
14730
+ var priceSchema = external_exports.object({
14731
+ billingInterval: external_exports.enum(["month", "year"]).nullable().default(null),
14732
+ id: external_exports.string(),
14733
+ name: external_exports.string(),
14734
+ amount: external_exports.number().int(),
14735
+ currency: external_exports.string(),
14736
+ bindingId: external_exports.string()
14737
+ });
14738
+ var transactionSchema = external_exports.object({
14739
+ subscriptionId: external_exports.string().nullable().default(null),
14740
+ periodStart: external_exports.string().datetime({ offset: true }).nullable().default(null),
14741
+ periodEnd: external_exports.string().datetime({ offset: true }).nullable().default(null),
14742
+ id: external_exports.string(),
14743
+ bindingId: external_exports.string(),
14744
+ orderId: external_exports.string(),
14745
+ priceId: external_exports.string(),
14746
+ amount: external_exports.number().int(),
14747
+ currency: external_exports.string(),
14748
+ feeAmount: external_exports.number().int(),
14749
+ revision: external_exports.number().int(),
14750
+ refundedAmount: external_exports.number().int(),
14751
+ status: external_exports.enum(["pending", "paid", "failed", "refunded", "partially_refunded"]),
14752
+ checkoutUrl: external_exports.string().nullable(),
14753
+ deliveredAt: external_exports.string().nullable()
14754
+ });
14755
+ var subscriptionSchema = external_exports.object({
14756
+ id: external_exports.string(),
14757
+ bindingId: external_exports.string(),
14758
+ priceId: external_exports.string(),
14759
+ orderId: external_exports.string(),
14760
+ status: external_exports.enum([
14761
+ "pending",
14762
+ "incomplete",
14763
+ "incomplete_expired",
14764
+ "trialing",
14765
+ "active",
14766
+ "past_due",
14767
+ "canceled",
14768
+ "unpaid",
14769
+ "paused"
14770
+ ]),
14771
+ billingInterval: external_exports.enum(["month", "year"]),
14772
+ paidThrough: external_exports.string().datetime({ offset: true }).nullable(),
14773
+ cancelAtPeriodEnd: external_exports.boolean(),
14774
+ checkoutUrl: external_exports.string().nullable(),
14775
+ revision: external_exports.number().int()
14776
+ });
14777
+ var portalSchema = external_exports.object({ url: external_exports.string().url() });
14778
+ var refundResultSchema = transactionSchema.extend({
14779
+ refund: external_exports.object({
14780
+ id: external_exports.string(),
14781
+ amount: external_exports.number().int().positive(),
14782
+ status: external_exports.enum(["pending", "succeeded", "failed", "canceled", "requires_action"])
14783
+ })
14784
+ });
14785
+ var activationSchema = external_exports.object({
14786
+ revision: external_exports.number().int(),
14787
+ reviewId: external_exports.string(),
14788
+ expiresAt: external_exports.string(),
14789
+ blockers: external_exports.array(external_exports.string()),
14790
+ binding: bindingSchema,
14791
+ account: accountSchema,
14792
+ feeBasisPoints: external_exports.number().int().nullable(),
14793
+ prices: external_exports.array(priceSchema)
14794
+ });
14795
+ var PaymentsApi = class {
14796
+ constructor(client) {
14797
+ this.client = client;
14798
+ this.runtime = new PaymentRuntime(client);
14799
+ }
14800
+ forNotebook(notebookId) {
14801
+ return new NotebookPayments(notebookId, this.client);
14802
+ }
14803
+ async applications(notebookId) {
14804
+ return applicationsSchema.parse(
14805
+ (await this.client.get(`/notebook/${encodeURIComponent(notebookId)}/payments/applications`)).data
14806
+ );
14807
+ }
14808
+ async access() {
14809
+ return accessSchema.parse((await this.client.get("/platform/payments/access")).data);
14810
+ }
14811
+ async accounts() {
14812
+ return external_exports.array(accountSchema).parse((await this.client.get("/platform/payments/accounts")).data);
14813
+ }
14814
+ async createAccount(mode, country) {
14815
+ return accountSchema.parse((await this.client.put(`/platform/payments/accounts/${mode}`, { country })).data);
14816
+ }
14817
+ async onboarding(mode) {
14818
+ return external_exports.object({ url: external_exports.string().url(), expiresAt: external_exports.string() }).parse((await this.client.post(`/platform/payments/accounts/${mode}/onboarding`, {})).data);
14819
+ }
14820
+ };
14821
+ var NotebookPayments = class {
14822
+ constructor(notebookId, client) {
14823
+ this.notebookId = notebookId;
14824
+ this.client = client;
14825
+ }
14826
+ path(mode) {
14827
+ return `/platform/payments/sandboxes/${encodeURIComponent(this.notebookId)}/${mode}`;
14828
+ }
14829
+ async get(mode = "test") {
14830
+ return bindingSchema.nullable().parse((await this.client.get(this.path(mode))).data);
14831
+ }
14832
+ async configure(input, mode = "test") {
14833
+ return bindingSchema.parse((await this.client.put(this.path(mode), input)).data);
14834
+ }
14835
+ async provision(mode = "test") {
14836
+ return bindingSchema.parse((await this.client.post(`${this.path(mode)}/provision`, {})).data);
14837
+ }
14838
+ async prices(mode = "test") {
14839
+ return external_exports.array(priceSchema).parse((await this.client.get(`${this.path(mode)}/prices`)).data);
14840
+ }
14841
+ async createPrice(input, mode = "test") {
14842
+ return priceSchema.parse((await this.client.post(`${this.path(mode)}/prices`, input)).data);
14843
+ }
14844
+ async prepareActivation(mode = "test") {
14845
+ return activationSchema.parse((await this.client.post(`${this.path(mode)}/activation`, {})).data);
14846
+ }
14847
+ async activate(reviewId, mode = "test") {
14848
+ return bindingSchema.parse((await this.client.post(`${this.path(mode)}/activate`, { reviewId })).data);
14849
+ }
14850
+ async disable(mode = "test") {
14851
+ return bindingSchema.parse((await this.client.post(`${this.path(mode)}/disable`, {})).data);
14852
+ }
14853
+ async checkout(input, mode = "test") {
14854
+ return transactionSchema.parse((await this.client.post(`${this.path(mode)}/checkouts`, input)).data);
14855
+ }
14856
+ async subscribe(input, mode = "test") {
14857
+ return subscriptionSchema.parse((await this.client.post(`${this.path(mode)}/subscriptions`, input)).data);
14858
+ }
14859
+ async subscriptions(mode = "test") {
14860
+ return external_exports.array(subscriptionSchema).parse((await this.client.get(`${this.path(mode)}/subscriptions`)).data);
14861
+ }
14862
+ async subscription(id, mode = "test") {
14863
+ return subscriptionSchema.parse(
14864
+ (await this.client.get(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}`)).data
14865
+ );
14866
+ }
14867
+ async cancelSubscription(id, mode = "test") {
14868
+ return subscriptionSchema.parse(
14869
+ (await this.client.post(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}/cancel`, {})).data
14870
+ );
14871
+ }
14872
+ async subscriptionPortal(id, input, mode = "test") {
14873
+ return portalSchema.parse(
14874
+ (await this.client.post(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}/portal`, input)).data
14875
+ );
14876
+ }
14877
+ async transactions(mode = "test") {
14878
+ return external_exports.array(transactionSchema).parse((await this.client.get(`${this.path(mode)}/transactions`)).data);
14879
+ }
14880
+ async refund(id, input, mode = "test") {
14881
+ return refundResultSchema.parse(
14882
+ (await this.client.post(`${this.path(mode)}/transactions/${encodeURIComponent(id)}/refund`, input)).data
14883
+ );
14884
+ }
14885
+ };
14886
+ var paymentEventSchema = external_exports.discriminatedUnion("type", [
14887
+ external_exports.object({
14888
+ id: external_exports.string(),
14889
+ type: external_exports.literal("payment.updated"),
14890
+ mode: paymentModeSchema,
14891
+ transaction: transactionSchema
14892
+ }),
14893
+ external_exports.object({
14894
+ id: external_exports.string(),
14895
+ type: external_exports.literal("subscription.updated"),
14896
+ mode: paymentModeSchema,
14897
+ subscription: subscriptionSchema
14898
+ })
14899
+ ]);
14900
+ async function verifyPaymentEvent(body, signature, token, mode, now = Date.now()) {
14901
+ if (!/^(?:hpay|happ)_[a-f0-9]{64}$/.test(token)) {
14902
+ throw new Error("Invalid application payment credential.");
14903
+ }
14904
+ const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(signature);
14905
+ const timestamp = match?.[1];
14906
+ const digest = match?.[2];
14907
+ if (!timestamp || !digest || Math.abs(now - Number(timestamp) * 1e3) > 3e5 || body.length > 262144) {
14908
+ throw new Error("Invalid or expired payment signature.");
14909
+ }
14910
+ const encoder = new TextEncoder();
14911
+ const key = await crypto.subtle.importKey("raw", encoder.encode(token), { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
14912
+ const bytes = Uint8Array.from(digest.match(/../g) ?? [], (byte) => Number.parseInt(byte, 16));
14913
+ if (!await crypto.subtle.verify("HMAC", key, bytes, encoder.encode(`${timestamp}.${body}`))) {
14914
+ throw new Error("Invalid payment signature.");
14915
+ }
14916
+ const event = paymentEventSchema.parse(JSON.parse(body));
14917
+ if (event.mode !== mode) {
14918
+ throw new Error("Payment event mode does not match this application.");
14919
+ }
14920
+ return event;
14921
+ }
14922
+ var PaymentRuntime = class {
14923
+ constructor(client, appCredential) {
14924
+ this.client = client;
14925
+ this.appCredential = appCredential;
14926
+ }
14927
+ /** Verify the phpsandbox-signature header against the configured app environment. */
14928
+ async verifyEvent(body, signature) {
14929
+ if (!this.appCredential) {
14930
+ throw new Error("Initialize the server app client with PHPSandbox.app() to verify payment events.");
14931
+ }
14932
+ return verifyPaymentEvent(body, signature, this.appCredential.token, this.appCredential.mode);
14933
+ }
14934
+ async checkout(input) {
14935
+ return transactionSchema.parse((await this.client.post("/platform/payments/runtime/checkouts", input)).data);
14936
+ }
14937
+ async transaction(id) {
14938
+ return transactionSchema.parse(
14939
+ (await this.client.get(`/platform/payments/runtime/transactions/${encodeURIComponent(id)}`)).data
14940
+ );
14941
+ }
14942
+ async subscribe(input) {
14943
+ return subscriptionSchema.parse((await this.client.post("/platform/payments/runtime/subscriptions", input)).data);
14944
+ }
14945
+ async subscription(id) {
14946
+ return subscriptionSchema.parse(
14947
+ (await this.client.get(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}`)).data
14948
+ );
14949
+ }
14950
+ async cancelSubscription(id) {
14951
+ return subscriptionSchema.parse(
14952
+ (await this.client.post(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}/cancel`, {})).data
14953
+ );
14954
+ }
14955
+ async subscriptionPortal(id, input) {
14956
+ return portalSchema.parse(
14957
+ (await this.client.post(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}/portal`, input)).data
14958
+ );
14959
+ }
14960
+ async prices() {
14961
+ return external_exports.array(priceSchema).parse((await this.client.get("/platform/payments/runtime/prices")).data);
14962
+ }
14963
+ };
14964
+
14965
+ // src/app.ts
14966
+ function resolveAppConfiguration(options) {
14967
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
14968
+ throw new Error("Application credentials must only be used on a trusted server.");
14969
+ }
14970
+ const environment = options.env ?? (typeof process === "undefined" ? {} : process.env);
14971
+ const mode = options.mode ?? (environment.NODE_ENV === "production" ? "live" : "test");
14972
+ const token = environment[`PHPSANDBOX_APP_${mode.toUpperCase()}_TOKEN`];
14973
+ const url2 = environment.PHPSANDBOX_APP_API_URL;
14974
+ if (!token || !/^happ_[a-f0-9]{64}$/.test(token) || !url2) {
14975
+ throw new Error(
14976
+ `Connect your app's ${mode === "live" ? "production" : "development"} platform environment before using Customers or Payments.`
14977
+ );
14978
+ }
14979
+ return { mode, token, url: url2 };
14980
+ }
14981
+ var AppRuntime = class {
14982
+ constructor(client, token, mode) {
14983
+ this.mode = mode;
14984
+ this.customers = new CustomerRuntime(client);
14985
+ this.payments = new PaymentRuntime(client, { token, mode });
14986
+ }
14987
+ };
14988
+
14529
14989
  // src/identity.ts
14530
14990
  var identitySchema = external_exports.object({
14531
14991
  user: external_exports.object({ id: external_exports.string(), name: external_exports.string() }).nullable(),
@@ -20202,6 +20662,8 @@ var ClientImplementation = class {
20202
20662
  this.notebook = new NotebookApi(this);
20203
20663
  this.servers = new ServerApi(this);
20204
20664
  this.integrations = new IntegrationApi(this);
20665
+ this.payments = new PaymentsApi(this);
20666
+ this.customers = new CustomersApi(this);
20205
20667
  this.options = { ...options };
20206
20668
  this.runtimeTransportValue = runtimeTransport;
20207
20669
  this.baseUrl = normalizeApiBaseUrl(url2);
@@ -20342,6 +20804,8 @@ var PHPSandbox = class _PHPSandbox {
20342
20804
  this.publications = client.publications;
20343
20805
  this.servers = client.servers;
20344
20806
  this.integrations = client.integrations;
20807
+ this.payments = client.payments;
20808
+ this.customers = client.customers;
20345
20809
  }
20346
20810
  async whoami() {
20347
20811
  const { data } = await this.client.get("/auth/whoami");
@@ -20354,6 +20818,10 @@ var PHPSandbox = class _PHPSandbox {
20354
20818
  get runtimeTransport() {
20355
20819
  return this.client.runtimeTransport;
20356
20820
  }
20821
+ static app(options = {}) {
20822
+ const { token, url: url2, mode } = resolveAppConfiguration(options);
20823
+ return new AppRuntime(new ClientImplementation(token, url2, {}, "rest"), token, mode);
20824
+ }
20357
20825
  static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20358
20826
  return new _PHPSandbox(new ClientImplementation(token, url2, options));
20359
20827
  }
@@ -20408,6 +20876,7 @@ var _NotebookInstance = class _NotebookInstance {
20408
20876
  this.config = new Config(this);
20409
20877
  this.secrets = new NotebookSecrets(client, this.data.id);
20410
20878
  this.integrations = new SandboxIntegrationApi(this.data.id, client);
20879
+ this.payments = new NotebookPayments(this.data.id, client);
20411
20880
  this.preview = new NotebookPreview(client, this.data.id);
20412
20881
  this.mail = new NotebookMail(client, this.data.id);
20413
20882
  this.feedback = new Feedback(client, this.data.id);
@@ -20711,6 +21180,11 @@ var NotebookMail = class {
20711
21180
  const response = await this.client.get(`/notebook/${this.notebookId}/mail`);
20712
21181
  return response.data;
20713
21182
  }
21183
+ /** Capture a platform-generated development email in the notebook inbox. Never sends externally. */
21184
+ async capture(input) {
21185
+ const response = await this.client.post(`/notebook/${this.notebookId}/mails`, input);
21186
+ return response.data;
21187
+ }
20714
21188
  async enable() {
20715
21189
  const response = await this.client.put(`/notebook/${this.notebookId}/mail`);
20716
21190
  return response.data;
@@ -20740,14 +21214,22 @@ function formatQueryString(params) {
20740
21214
  return query === "" ? "" : `?${query}`;
20741
21215
  }
20742
21216
  export {
21217
+ AppRuntime,
21218
+ CustomerRuntime,
21219
+ CustomersApi,
21220
+ DEFAULT_PAYMENT_CALLBACK_PATH,
20743
21221
  FileChangeFilter,
20744
21222
  FileChangeType,
20745
21223
  FileType,
20746
21224
  LspConnection,
21225
+ NotebookCustomers,
20747
21226
  NotebookInstance,
21227
+ NotebookPayments,
20748
21228
  NotebookPublication,
20749
21229
  PHPSandbox,
20750
21230
  PHPSandboxError,
21231
+ PaymentRuntime,
21232
+ PaymentsApi,
20751
21233
  PublicationApi,
20752
21234
  PublicationDomains,
20753
21235
  PublicationInstance,
@@ -20756,10 +21238,14 @@ export {
20756
21238
  RemoteError,
20757
21239
  TransportError,
20758
21240
  createPublicationStreamResponse,
21241
+ customerModeSchema,
21242
+ customerSchema,
20759
21243
  laravelCloudSetupForRepublish,
20760
21244
  notebookBuiltinServices,
20761
21245
  notebookKnownServices,
20762
- readPublicationStream
21246
+ paymentModeSchema,
21247
+ readPublicationStream,
21248
+ verifyPaymentEvent
20763
21249
  };
20764
21250
  /*! Bundled license information:
20765
21251