@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.
@@ -29,14 +29,22 @@ var PHPSandbox = (() => {
29
29
  // src/index.ts
30
30
  var index_exports = {};
31
31
  __export(index_exports, {
32
+ AppRuntime: () => AppRuntime,
33
+ CustomerRuntime: () => CustomerRuntime,
34
+ CustomersApi: () => CustomersApi,
35
+ DEFAULT_PAYMENT_CALLBACK_PATH: () => DEFAULT_PAYMENT_CALLBACK_PATH,
32
36
  FileChangeFilter: () => FileChangeFilter,
33
37
  FileChangeType: () => FileChangeType,
34
38
  FileType: () => FileType,
35
39
  LspConnection: () => LspConnection,
40
+ NotebookCustomers: () => NotebookCustomers,
36
41
  NotebookInstance: () => NotebookInstance,
42
+ NotebookPayments: () => NotebookPayments,
37
43
  NotebookPublication: () => NotebookPublication,
38
44
  PHPSandbox: () => PHPSandbox,
39
45
  PHPSandboxError: () => PHPSandboxError,
46
+ PaymentRuntime: () => PaymentRuntime,
47
+ PaymentsApi: () => PaymentsApi,
40
48
  PublicationApi: () => PublicationApi,
41
49
  PublicationDomains: () => PublicationDomains,
42
50
  PublicationInstance: () => PublicationInstance,
@@ -45,10 +53,14 @@ var PHPSandbox = (() => {
45
53
  RemoteError: () => RemoteError,
46
54
  TransportError: () => TransportError,
47
55
  createPublicationStreamResponse: () => createPublicationStreamResponse,
56
+ customerModeSchema: () => customerModeSchema,
57
+ customerSchema: () => customerSchema,
48
58
  laravelCloudSetupForRepublish: () => laravelCloudSetupForRepublish,
49
59
  notebookBuiltinServices: () => notebookBuiltinServices,
50
60
  notebookKnownServices: () => notebookKnownServices,
51
- readPublicationStream: () => readPublicationStream
61
+ paymentModeSchema: () => paymentModeSchema,
62
+ readPublicationStream: () => readPublicationStream,
63
+ verifyPaymentEvent: () => verifyPaymentEvent
52
64
  });
53
65
 
54
66
  // node_modules/zod/v4/classic/external.js
@@ -557,7 +569,7 @@ var PHPSandbox = (() => {
557
569
  parse: () => parse,
558
570
  parseAsync: () => parseAsync,
559
571
  prettifyError: () => prettifyError,
560
- process: () => process,
572
+ process: () => process2,
561
573
  regexes: () => regexes_exports,
562
574
  registry: () => registry,
563
575
  safeDecode: () => safeDecode,
@@ -11482,7 +11494,7 @@ var PHPSandbox = (() => {
11482
11494
  external: params?.external ?? void 0
11483
11495
  };
11484
11496
  }
11485
- function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
11497
+ function process2(schema, ctx, _params = { path: [], schemaPath: [] }) {
11486
11498
  var _a3;
11487
11499
  const def = schema._zod.def;
11488
11500
  const seen = ctx.seen.get(schema);
@@ -11519,7 +11531,7 @@ var PHPSandbox = (() => {
11519
11531
  if (parent) {
11520
11532
  if (!result.ref)
11521
11533
  result.ref = parent;
11522
- process(parent, ctx, params);
11534
+ process2(parent, ctx, params);
11523
11535
  ctx.seen.get(parent).isParent = true;
11524
11536
  }
11525
11537
  }
@@ -11807,14 +11819,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
11807
11819
  }
11808
11820
  var createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
11809
11821
  const ctx = initializeContext({ ...params, processors });
11810
- process(schema, ctx);
11822
+ process2(schema, ctx);
11811
11823
  extractDefs(ctx, schema);
11812
11824
  return finalize(ctx, schema);
11813
11825
  };
11814
11826
  var createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
11815
11827
  const { libraryOptions, target } = params ?? {};
11816
11828
  const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
11817
- process(schema, ctx);
11829
+ process2(schema, ctx);
11818
11830
  extractDefs(ctx, schema);
11819
11831
  return finalize(ctx, schema);
11820
11832
  };
@@ -12060,7 +12072,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12060
12072
  if (typeof maximum === "number")
12061
12073
  json2.maxItems = maximum;
12062
12074
  json2.type = "array";
12063
- json2.items = process(def.element, ctx, {
12075
+ json2.items = process2(def.element, ctx, {
12064
12076
  ...params,
12065
12077
  path: [...params.path, "items"]
12066
12078
  });
@@ -12072,7 +12084,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12072
12084
  json2.properties = {};
12073
12085
  const shape = def.shape;
12074
12086
  for (const key in shape) {
12075
- json2.properties[key] = process(shape[key], ctx, {
12087
+ json2.properties[key] = process2(shape[key], ctx, {
12076
12088
  ...params,
12077
12089
  path: [...params.path, "properties", key]
12078
12090
  });
@@ -12095,7 +12107,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12095
12107
  if (ctx.io === "output")
12096
12108
  json2.additionalProperties = false;
12097
12109
  } else if (def.catchall) {
12098
- json2.additionalProperties = process(def.catchall, ctx, {
12110
+ json2.additionalProperties = process2(def.catchall, ctx, {
12099
12111
  ...params,
12100
12112
  path: [...params.path, "additionalProperties"]
12101
12113
  });
@@ -12104,7 +12116,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12104
12116
  var unionProcessor = (schema, ctx, json2, params) => {
12105
12117
  const def = schema._zod.def;
12106
12118
  const isExclusive = def.inclusive === false;
12107
- const options = def.options.map((x, i) => process(x, ctx, {
12119
+ const options = def.options.map((x, i) => process2(x, ctx, {
12108
12120
  ...params,
12109
12121
  path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
12110
12122
  }));
@@ -12116,11 +12128,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12116
12128
  };
12117
12129
  var intersectionProcessor = (schema, ctx, json2, params) => {
12118
12130
  const def = schema._zod.def;
12119
- const a = process(def.left, ctx, {
12131
+ const a = process2(def.left, ctx, {
12120
12132
  ...params,
12121
12133
  path: [...params.path, "allOf", 0]
12122
12134
  });
12123
- const b = process(def.right, ctx, {
12135
+ const b = process2(def.right, ctx, {
12124
12136
  ...params,
12125
12137
  path: [...params.path, "allOf", 1]
12126
12138
  });
@@ -12137,11 +12149,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12137
12149
  json2.type = "array";
12138
12150
  const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
12139
12151
  const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
12140
- const prefixItems = def.items.map((x, i) => process(x, ctx, {
12152
+ const prefixItems = def.items.map((x, i) => process2(x, ctx, {
12141
12153
  ...params,
12142
12154
  path: [...params.path, prefixPath, i]
12143
12155
  }));
12144
- const rest = def.rest ? process(def.rest, ctx, {
12156
+ const rest = def.rest ? process2(def.rest, ctx, {
12145
12157
  ...params,
12146
12158
  path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
12147
12159
  }) : null;
@@ -12181,7 +12193,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12181
12193
  const keyBag = keyType._zod.bag;
12182
12194
  const patterns = keyBag?.patterns;
12183
12195
  if (def.mode === "loose" && patterns && patterns.size > 0) {
12184
- const valueSchema = process(def.valueType, ctx, {
12196
+ const valueSchema = process2(def.valueType, ctx, {
12185
12197
  ...params,
12186
12198
  path: [...params.path, "patternProperties", "*"]
12187
12199
  });
@@ -12191,12 +12203,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12191
12203
  }
12192
12204
  } else {
12193
12205
  if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
12194
- json2.propertyNames = process(def.keyType, ctx, {
12206
+ json2.propertyNames = process2(def.keyType, ctx, {
12195
12207
  ...params,
12196
12208
  path: [...params.path, "propertyNames"]
12197
12209
  });
12198
12210
  }
12199
- json2.additionalProperties = process(def.valueType, ctx, {
12211
+ json2.additionalProperties = process2(def.valueType, ctx, {
12200
12212
  ...params,
12201
12213
  path: [...params.path, "additionalProperties"]
12202
12214
  });
@@ -12211,7 +12223,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12211
12223
  };
12212
12224
  var nullableProcessor = (schema, ctx, json2, params) => {
12213
12225
  const def = schema._zod.def;
12214
- const inner = process(def.innerType, ctx, params);
12226
+ const inner = process2(def.innerType, ctx, params);
12215
12227
  const seen = ctx.seen.get(schema);
12216
12228
  if (ctx.target === "openapi-3.0") {
12217
12229
  seen.ref = def.innerType;
@@ -12222,20 +12234,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12222
12234
  };
12223
12235
  var nonoptionalProcessor = (schema, ctx, _json, params) => {
12224
12236
  const def = schema._zod.def;
12225
- process(def.innerType, ctx, params);
12237
+ process2(def.innerType, ctx, params);
12226
12238
  const seen = ctx.seen.get(schema);
12227
12239
  seen.ref = def.innerType;
12228
12240
  };
12229
12241
  var defaultProcessor = (schema, ctx, json2, params) => {
12230
12242
  const def = schema._zod.def;
12231
- process(def.innerType, ctx, params);
12243
+ process2(def.innerType, ctx, params);
12232
12244
  const seen = ctx.seen.get(schema);
12233
12245
  seen.ref = def.innerType;
12234
12246
  json2.default = JSON.parse(JSON.stringify(def.defaultValue));
12235
12247
  };
12236
12248
  var prefaultProcessor = (schema, ctx, json2, params) => {
12237
12249
  const def = schema._zod.def;
12238
- process(def.innerType, ctx, params);
12250
+ process2(def.innerType, ctx, params);
12239
12251
  const seen = ctx.seen.get(schema);
12240
12252
  seen.ref = def.innerType;
12241
12253
  if (ctx.io === "input")
@@ -12243,7 +12255,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12243
12255
  };
12244
12256
  var catchProcessor = (schema, ctx, json2, params) => {
12245
12257
  const def = schema._zod.def;
12246
- process(def.innerType, ctx, params);
12258
+ process2(def.innerType, ctx, params);
12247
12259
  const seen = ctx.seen.get(schema);
12248
12260
  seen.ref = def.innerType;
12249
12261
  let catchValue;
@@ -12258,32 +12270,32 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12258
12270
  const def = schema._zod.def;
12259
12271
  const inIsTransform = def.in._zod.traits.has("$ZodTransform");
12260
12272
  const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
12261
- process(innerType, ctx, params);
12273
+ process2(innerType, ctx, params);
12262
12274
  const seen = ctx.seen.get(schema);
12263
12275
  seen.ref = innerType;
12264
12276
  };
12265
12277
  var readonlyProcessor = (schema, ctx, json2, params) => {
12266
12278
  const def = schema._zod.def;
12267
- process(def.innerType, ctx, params);
12279
+ process2(def.innerType, ctx, params);
12268
12280
  const seen = ctx.seen.get(schema);
12269
12281
  seen.ref = def.innerType;
12270
12282
  json2.readOnly = true;
12271
12283
  };
12272
12284
  var promiseProcessor = (schema, ctx, _json, params) => {
12273
12285
  const def = schema._zod.def;
12274
- process(def.innerType, ctx, params);
12286
+ process2(def.innerType, ctx, params);
12275
12287
  const seen = ctx.seen.get(schema);
12276
12288
  seen.ref = def.innerType;
12277
12289
  };
12278
12290
  var optionalProcessor = (schema, ctx, _json, params) => {
12279
12291
  const def = schema._zod.def;
12280
- process(def.innerType, ctx, params);
12292
+ process2(def.innerType, ctx, params);
12281
12293
  const seen = ctx.seen.get(schema);
12282
12294
  seen.ref = def.innerType;
12283
12295
  };
12284
12296
  var lazyProcessor = (schema, ctx, _json, params) => {
12285
12297
  const innerType = schema._zod.innerType;
12286
- process(innerType, ctx, params);
12298
+ process2(innerType, ctx, params);
12287
12299
  const seen = ctx.seen.get(schema);
12288
12300
  seen.ref = innerType;
12289
12301
  };
@@ -12335,7 +12347,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12335
12347
  const defs = {};
12336
12348
  for (const entry of registry2._idmap.entries()) {
12337
12349
  const [_, schema] = entry;
12338
- process(schema, ctx2);
12350
+ process2(schema, ctx2);
12339
12351
  }
12340
12352
  const schemas = {};
12341
12353
  const external = {
@@ -12358,7 +12370,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12358
12370
  return { schemas };
12359
12371
  }
12360
12372
  const ctx = initializeContext({ ...params, processors: allProcessors });
12361
- process(input, ctx);
12373
+ process2(input, ctx);
12362
12374
  extractDefs(ctx, input);
12363
12375
  return finalize(ctx, input);
12364
12376
  }
@@ -12416,7 +12428,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12416
12428
  * This must be called before emit().
12417
12429
  */
12418
12430
  process(schema, _params = { path: [], schemaPath: [] }) {
12419
- return process(schema, this.ctx, _params);
12431
+ return process2(schema, this.ctx, _params);
12420
12432
  }
12421
12433
  /**
12422
12434
  * Emit the final JSON Schema after processing.
@@ -14565,6 +14577,466 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14565
14577
  // node_modules/zod/v4/classic/external.js
14566
14578
  config(en_default());
14567
14579
 
14580
+ // src/customers.ts
14581
+ var customerModeSchema = external_exports.enum(["test", "live"]);
14582
+ var customerSchema = external_exports.object({
14583
+ id: external_exports.string(),
14584
+ externalId: external_exports.string(),
14585
+ email: external_exports.string(),
14586
+ name: external_exports.string().nullable(),
14587
+ source: external_exports.string().nullable(),
14588
+ marketingSubscribed: external_exports.boolean(),
14589
+ suppressionReason: external_exports.string().nullable(),
14590
+ activatedAt: external_exports.string().nullable(),
14591
+ createdAt: external_exports.string().nullable()
14592
+ });
14593
+ var spaceSchema = external_exports.object({
14594
+ id: external_exports.string(),
14595
+ mode: customerModeSchema,
14596
+ enabled: external_exports.boolean(),
14597
+ senderName: external_exports.string().nullable(),
14598
+ senderEmail: external_exports.string().nullable(),
14599
+ replyTo: external_exports.string().nullable(),
14600
+ senderVerified: external_exports.boolean(),
14601
+ domainRecords: external_exports.string().nullable(),
14602
+ provisionedAt: external_exports.string().nullable().optional(),
14603
+ lastRequestAt: external_exports.string().nullable().optional(),
14604
+ processedAt: external_exports.string().nullable().optional()
14605
+ });
14606
+ var journeyInputSchema = external_exports.object({
14607
+ enabled: external_exports.boolean(),
14608
+ subject: external_exports.string(),
14609
+ body: external_exports.string(),
14610
+ delayMinutes: external_exports.number(),
14611
+ activationEvent: external_exports.string()
14612
+ });
14613
+ var journeySchema = journeyInputSchema.extend({
14614
+ kind: external_exports.enum(["welcome", "setup", "purchase"]),
14615
+ version: external_exports.number().int().optional(),
14616
+ startsAt: external_exports.string().nullable().optional(),
14617
+ draft: journeyInputSchema.nullable().optional()
14618
+ });
14619
+ var messageSchema = external_exports.object({
14620
+ id: external_exports.string(),
14621
+ customerId: external_exports.string().nullable(),
14622
+ recipient: external_exports.string(),
14623
+ subject: external_exports.string(),
14624
+ body: external_exports.string(),
14625
+ status: external_exports.string(),
14626
+ error: external_exports.string().nullable(),
14627
+ dueAt: external_exports.string().nullable().optional(),
14628
+ attemptedAt: external_exports.string().nullable().optional(),
14629
+ receivedAt: external_exports.string().nullable().optional(),
14630
+ journeyKind: external_exports.enum(["welcome", "setup", "purchase"]).nullable().optional(),
14631
+ journeyVersion: external_exports.number().int().nullable().optional(),
14632
+ category: external_exports.enum(["marketing", "service"]).optional(),
14633
+ from: external_exports.string().nullable().optional(),
14634
+ replyTo: external_exports.string().nullable().optional(),
14635
+ renderedText: external_exports.string().nullable().optional(),
14636
+ unsubscribeUrl: external_exports.string().nullable().optional(),
14637
+ createdAt: external_exports.string().nullable()
14638
+ });
14639
+ var overviewSchema = external_exports.object({
14640
+ space: spaceSchema.nullable(),
14641
+ customers: external_exports.array(customerSchema),
14642
+ journeys: external_exports.array(journeySchema),
14643
+ messages: external_exports.array(messageSchema),
14644
+ total: external_exports.number(),
14645
+ messageTotal: external_exports.number().optional(),
14646
+ events: external_exports.array(external_exports.string()).optional()
14647
+ });
14648
+ var CustomerRuntime = class {
14649
+ constructor(client) {
14650
+ this.client = client;
14651
+ }
14652
+ async identify(input) {
14653
+ return customerSchema.parse((await this.client.post("/platform/customers/runtime/identify", input)).data);
14654
+ }
14655
+ async linkIdentity(customerId, externalId) {
14656
+ return customerSchema.parse(
14657
+ (await this.client.post(`/platform/customers/runtime/${encodeURIComponent(customerId)}/identities`, {
14658
+ externalId
14659
+ })).data
14660
+ );
14661
+ }
14662
+ async get(customerId) {
14663
+ return customerSchema.parse(
14664
+ (await this.client.get(`/platform/customers/runtime/${encodeURIComponent(customerId)}`)).data
14665
+ );
14666
+ }
14667
+ async event(customerId, input) {
14668
+ return external_exports.object({ id: external_exports.string(), name: external_exports.string() }).parse(
14669
+ (await this.client.post(`/platform/customers/runtime/${encodeURIComponent(customerId)}/events`, input)).data
14670
+ );
14671
+ }
14672
+ async preferences(customerId, input) {
14673
+ return customerSchema.parse(
14674
+ (await this.client.put(`/platform/customers/runtime/${encodeURIComponent(customerId)}/preferences`, input)).data
14675
+ );
14676
+ }
14677
+ async send(customerId, input) {
14678
+ return messageSchema.parse(
14679
+ (await this.client.post(`/platform/customers/runtime/${encodeURIComponent(customerId)}/messages`, input)).data
14680
+ );
14681
+ }
14682
+ };
14683
+ var CustomersApi = class {
14684
+ constructor(client) {
14685
+ this.client = client;
14686
+ this.runtime = new CustomerRuntime(client);
14687
+ }
14688
+ forNotebook(notebookId) {
14689
+ return new NotebookCustomers(notebookId, this.client);
14690
+ }
14691
+ };
14692
+ var NotebookCustomers = class {
14693
+ constructor(notebookId, client) {
14694
+ this.notebookId = notebookId;
14695
+ this.client = client;
14696
+ }
14697
+ async list(mode = "test", query = {}) {
14698
+ return overviewSchema.parse(
14699
+ (await this.client.get(
14700
+ `${this.path(mode)}?${new URLSearchParams(Object.entries(query).map(([key, value]) => [key, String(value)])).toString()}`
14701
+ )).data
14702
+ );
14703
+ }
14704
+ async connect(mode = "test") {
14705
+ return spaceSchema.parse((await this.client.put(this.path(mode), {})).data);
14706
+ }
14707
+ async provision(mode = "test") {
14708
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/provision`, {})).data);
14709
+ }
14710
+ async disable(mode = "test") {
14711
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/disable`, {})).data);
14712
+ }
14713
+ async resume(mode = "test") {
14714
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/resume`, {})).data);
14715
+ }
14716
+ async rotate(mode = "test") {
14717
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/rotate`, {})).data);
14718
+ }
14719
+ async sender(input, mode = "test") {
14720
+ return spaceSchema.parse((await this.client.put(`${this.path(mode)}/sender`, input)).data);
14721
+ }
14722
+ async verifySender(mode = "test") {
14723
+ return spaceSchema.parse((await this.client.post(`${this.path(mode)}/sender/verify`, {})).data);
14724
+ }
14725
+ async journey(kind, input, mode = "test") {
14726
+ return journeySchema.parse((await this.client.put(`${this.path(mode)}/journeys/${kind}`, input)).data);
14727
+ }
14728
+ path(mode) {
14729
+ return `/platform/customers/sandboxes/${encodeURIComponent(this.notebookId)}/${mode}`;
14730
+ }
14731
+ };
14732
+
14733
+ // src/payments.ts
14734
+ var DEFAULT_PAYMENT_CALLBACK_PATH = "/api/phpsandbox-payments/events";
14735
+ var paymentModeSchema = external_exports.enum(["test", "live"]);
14736
+ var accountSchema = external_exports.object({
14737
+ id: external_exports.string(),
14738
+ mode: paymentModeSchema,
14739
+ chargesEnabled: external_exports.boolean(),
14740
+ payoutsEnabled: external_exports.boolean(),
14741
+ detailsSubmitted: external_exports.boolean(),
14742
+ requirements: external_exports.array(external_exports.string()),
14743
+ disabledReason: external_exports.string().nullable()
14744
+ });
14745
+ var accessSchema = external_exports.object({
14746
+ subscribed: external_exports.boolean(),
14747
+ liveAllowed: external_exports.boolean(),
14748
+ testConfigured: external_exports.boolean(),
14749
+ liveConfigured: external_exports.boolean(),
14750
+ feeBasisPoints: external_exports.number().int().min(0).max(1e4).nullable(),
14751
+ canRead: external_exports.boolean(),
14752
+ canManage: external_exports.boolean(),
14753
+ canRefund: external_exports.boolean(),
14754
+ recoveryEndsAt: external_exports.string().nullable().default(null)
14755
+ });
14756
+ var applicationsSchema = external_exports.object({
14757
+ notebookId: external_exports.string(),
14758
+ applications: external_exports.array(
14759
+ external_exports.object({
14760
+ id: external_exports.string(),
14761
+ url: external_exports.string().nullable(),
14762
+ healthy: external_exports.boolean(),
14763
+ passwordProtected: external_exports.boolean(),
14764
+ deployedAt: external_exports.string().datetime().nullable()
14765
+ })
14766
+ )
14767
+ });
14768
+ var bindingSchema = external_exports.object({
14769
+ target: external_exports.enum(["preview", "publication"]).optional(),
14770
+ id: external_exports.string(),
14771
+ notebookId: external_exports.string(),
14772
+ applicationId: external_exports.string().nullable(),
14773
+ mode: paymentModeSchema,
14774
+ revision: external_exports.number().int(),
14775
+ accountId: external_exports.string(),
14776
+ enabled: external_exports.boolean(),
14777
+ callbackUrl: external_exports.string().nullable(),
14778
+ originUrl: external_exports.string().nullable(),
14779
+ runtimeConfigured: external_exports.boolean()
14780
+ });
14781
+ var priceSchema = external_exports.object({
14782
+ billingInterval: external_exports.enum(["month", "year"]).nullable().default(null),
14783
+ id: external_exports.string(),
14784
+ name: external_exports.string(),
14785
+ amount: external_exports.number().int(),
14786
+ currency: external_exports.string(),
14787
+ bindingId: external_exports.string()
14788
+ });
14789
+ var transactionSchema = external_exports.object({
14790
+ subscriptionId: external_exports.string().nullable().default(null),
14791
+ periodStart: external_exports.string().datetime({ offset: true }).nullable().default(null),
14792
+ periodEnd: external_exports.string().datetime({ offset: true }).nullable().default(null),
14793
+ id: external_exports.string(),
14794
+ bindingId: external_exports.string(),
14795
+ orderId: external_exports.string(),
14796
+ priceId: external_exports.string(),
14797
+ amount: external_exports.number().int(),
14798
+ currency: external_exports.string(),
14799
+ feeAmount: external_exports.number().int(),
14800
+ revision: external_exports.number().int(),
14801
+ refundedAmount: external_exports.number().int(),
14802
+ status: external_exports.enum(["pending", "paid", "failed", "refunded", "partially_refunded"]),
14803
+ checkoutUrl: external_exports.string().nullable(),
14804
+ deliveredAt: external_exports.string().nullable()
14805
+ });
14806
+ var subscriptionSchema = external_exports.object({
14807
+ id: external_exports.string(),
14808
+ bindingId: external_exports.string(),
14809
+ priceId: external_exports.string(),
14810
+ orderId: external_exports.string(),
14811
+ status: external_exports.enum([
14812
+ "pending",
14813
+ "incomplete",
14814
+ "incomplete_expired",
14815
+ "trialing",
14816
+ "active",
14817
+ "past_due",
14818
+ "canceled",
14819
+ "unpaid",
14820
+ "paused"
14821
+ ]),
14822
+ billingInterval: external_exports.enum(["month", "year"]),
14823
+ paidThrough: external_exports.string().datetime({ offset: true }).nullable(),
14824
+ cancelAtPeriodEnd: external_exports.boolean(),
14825
+ checkoutUrl: external_exports.string().nullable(),
14826
+ revision: external_exports.number().int()
14827
+ });
14828
+ var portalSchema = external_exports.object({ url: external_exports.string().url() });
14829
+ var refundResultSchema = transactionSchema.extend({
14830
+ refund: external_exports.object({
14831
+ id: external_exports.string(),
14832
+ amount: external_exports.number().int().positive(),
14833
+ status: external_exports.enum(["pending", "succeeded", "failed", "canceled", "requires_action"])
14834
+ })
14835
+ });
14836
+ var activationSchema = external_exports.object({
14837
+ revision: external_exports.number().int(),
14838
+ reviewId: external_exports.string(),
14839
+ expiresAt: external_exports.string(),
14840
+ blockers: external_exports.array(external_exports.string()),
14841
+ binding: bindingSchema,
14842
+ account: accountSchema,
14843
+ feeBasisPoints: external_exports.number().int().nullable(),
14844
+ prices: external_exports.array(priceSchema)
14845
+ });
14846
+ var PaymentsApi = class {
14847
+ constructor(client) {
14848
+ this.client = client;
14849
+ this.runtime = new PaymentRuntime(client);
14850
+ }
14851
+ forNotebook(notebookId) {
14852
+ return new NotebookPayments(notebookId, this.client);
14853
+ }
14854
+ async applications(notebookId) {
14855
+ return applicationsSchema.parse(
14856
+ (await this.client.get(`/notebook/${encodeURIComponent(notebookId)}/payments/applications`)).data
14857
+ );
14858
+ }
14859
+ async access() {
14860
+ return accessSchema.parse((await this.client.get("/platform/payments/access")).data);
14861
+ }
14862
+ async accounts() {
14863
+ return external_exports.array(accountSchema).parse((await this.client.get("/platform/payments/accounts")).data);
14864
+ }
14865
+ async createAccount(mode, country) {
14866
+ return accountSchema.parse((await this.client.put(`/platform/payments/accounts/${mode}`, { country })).data);
14867
+ }
14868
+ async onboarding(mode) {
14869
+ return external_exports.object({ url: external_exports.string().url(), expiresAt: external_exports.string() }).parse((await this.client.post(`/platform/payments/accounts/${mode}/onboarding`, {})).data);
14870
+ }
14871
+ };
14872
+ var NotebookPayments = class {
14873
+ constructor(notebookId, client) {
14874
+ this.notebookId = notebookId;
14875
+ this.client = client;
14876
+ }
14877
+ path(mode) {
14878
+ return `/platform/payments/sandboxes/${encodeURIComponent(this.notebookId)}/${mode}`;
14879
+ }
14880
+ async get(mode = "test") {
14881
+ return bindingSchema.nullable().parse((await this.client.get(this.path(mode))).data);
14882
+ }
14883
+ async configure(input, mode = "test") {
14884
+ return bindingSchema.parse((await this.client.put(this.path(mode), input)).data);
14885
+ }
14886
+ async provision(mode = "test") {
14887
+ return bindingSchema.parse((await this.client.post(`${this.path(mode)}/provision`, {})).data);
14888
+ }
14889
+ async prices(mode = "test") {
14890
+ return external_exports.array(priceSchema).parse((await this.client.get(`${this.path(mode)}/prices`)).data);
14891
+ }
14892
+ async createPrice(input, mode = "test") {
14893
+ return priceSchema.parse((await this.client.post(`${this.path(mode)}/prices`, input)).data);
14894
+ }
14895
+ async prepareActivation(mode = "test") {
14896
+ return activationSchema.parse((await this.client.post(`${this.path(mode)}/activation`, {})).data);
14897
+ }
14898
+ async activate(reviewId, mode = "test") {
14899
+ return bindingSchema.parse((await this.client.post(`${this.path(mode)}/activate`, { reviewId })).data);
14900
+ }
14901
+ async disable(mode = "test") {
14902
+ return bindingSchema.parse((await this.client.post(`${this.path(mode)}/disable`, {})).data);
14903
+ }
14904
+ async checkout(input, mode = "test") {
14905
+ return transactionSchema.parse((await this.client.post(`${this.path(mode)}/checkouts`, input)).data);
14906
+ }
14907
+ async subscribe(input, mode = "test") {
14908
+ return subscriptionSchema.parse((await this.client.post(`${this.path(mode)}/subscriptions`, input)).data);
14909
+ }
14910
+ async subscriptions(mode = "test") {
14911
+ return external_exports.array(subscriptionSchema).parse((await this.client.get(`${this.path(mode)}/subscriptions`)).data);
14912
+ }
14913
+ async subscription(id, mode = "test") {
14914
+ return subscriptionSchema.parse(
14915
+ (await this.client.get(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}`)).data
14916
+ );
14917
+ }
14918
+ async cancelSubscription(id, mode = "test") {
14919
+ return subscriptionSchema.parse(
14920
+ (await this.client.post(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}/cancel`, {})).data
14921
+ );
14922
+ }
14923
+ async subscriptionPortal(id, input, mode = "test") {
14924
+ return portalSchema.parse(
14925
+ (await this.client.post(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}/portal`, input)).data
14926
+ );
14927
+ }
14928
+ async transactions(mode = "test") {
14929
+ return external_exports.array(transactionSchema).parse((await this.client.get(`${this.path(mode)}/transactions`)).data);
14930
+ }
14931
+ async refund(id, input, mode = "test") {
14932
+ return refundResultSchema.parse(
14933
+ (await this.client.post(`${this.path(mode)}/transactions/${encodeURIComponent(id)}/refund`, input)).data
14934
+ );
14935
+ }
14936
+ };
14937
+ var paymentEventSchema = external_exports.discriminatedUnion("type", [
14938
+ external_exports.object({
14939
+ id: external_exports.string(),
14940
+ type: external_exports.literal("payment.updated"),
14941
+ mode: paymentModeSchema,
14942
+ transaction: transactionSchema
14943
+ }),
14944
+ external_exports.object({
14945
+ id: external_exports.string(),
14946
+ type: external_exports.literal("subscription.updated"),
14947
+ mode: paymentModeSchema,
14948
+ subscription: subscriptionSchema
14949
+ })
14950
+ ]);
14951
+ async function verifyPaymentEvent(body, signature, token, mode, now = Date.now()) {
14952
+ if (!/^(?:hpay|happ)_[a-f0-9]{64}$/.test(token)) {
14953
+ throw new Error("Invalid application payment credential.");
14954
+ }
14955
+ const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(signature);
14956
+ const timestamp = match?.[1];
14957
+ const digest = match?.[2];
14958
+ if (!timestamp || !digest || Math.abs(now - Number(timestamp) * 1e3) > 3e5 || body.length > 262144) {
14959
+ throw new Error("Invalid or expired payment signature.");
14960
+ }
14961
+ const encoder = new TextEncoder();
14962
+ const key = await crypto.subtle.importKey("raw", encoder.encode(token), { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
14963
+ const bytes = Uint8Array.from(digest.match(/../g) ?? [], (byte) => Number.parseInt(byte, 16));
14964
+ if (!await crypto.subtle.verify("HMAC", key, bytes, encoder.encode(`${timestamp}.${body}`))) {
14965
+ throw new Error("Invalid payment signature.");
14966
+ }
14967
+ const event = paymentEventSchema.parse(JSON.parse(body));
14968
+ if (event.mode !== mode) {
14969
+ throw new Error("Payment event mode does not match this application.");
14970
+ }
14971
+ return event;
14972
+ }
14973
+ var PaymentRuntime = class {
14974
+ constructor(client, appCredential) {
14975
+ this.client = client;
14976
+ this.appCredential = appCredential;
14977
+ }
14978
+ /** Verify the phpsandbox-signature header against the configured app environment. */
14979
+ async verifyEvent(body, signature) {
14980
+ if (!this.appCredential) {
14981
+ throw new Error("Initialize the server app client with PHPSandbox.app() to verify payment events.");
14982
+ }
14983
+ return verifyPaymentEvent(body, signature, this.appCredential.token, this.appCredential.mode);
14984
+ }
14985
+ async checkout(input) {
14986
+ return transactionSchema.parse((await this.client.post("/platform/payments/runtime/checkouts", input)).data);
14987
+ }
14988
+ async transaction(id) {
14989
+ return transactionSchema.parse(
14990
+ (await this.client.get(`/platform/payments/runtime/transactions/${encodeURIComponent(id)}`)).data
14991
+ );
14992
+ }
14993
+ async subscribe(input) {
14994
+ return subscriptionSchema.parse((await this.client.post("/platform/payments/runtime/subscriptions", input)).data);
14995
+ }
14996
+ async subscription(id) {
14997
+ return subscriptionSchema.parse(
14998
+ (await this.client.get(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}`)).data
14999
+ );
15000
+ }
15001
+ async cancelSubscription(id) {
15002
+ return subscriptionSchema.parse(
15003
+ (await this.client.post(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}/cancel`, {})).data
15004
+ );
15005
+ }
15006
+ async subscriptionPortal(id, input) {
15007
+ return portalSchema.parse(
15008
+ (await this.client.post(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}/portal`, input)).data
15009
+ );
15010
+ }
15011
+ async prices() {
15012
+ return external_exports.array(priceSchema).parse((await this.client.get("/platform/payments/runtime/prices")).data);
15013
+ }
15014
+ };
15015
+
15016
+ // src/app.ts
15017
+ function resolveAppConfiguration(options) {
15018
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
15019
+ throw new Error("Application credentials must only be used on a trusted server.");
15020
+ }
15021
+ const environment = options.env ?? (typeof process === "undefined" ? {} : process.env);
15022
+ const mode = options.mode ?? (environment.NODE_ENV === "production" ? "live" : "test");
15023
+ const token = environment[`PHPSANDBOX_APP_${mode.toUpperCase()}_TOKEN`];
15024
+ const url2 = environment.PHPSANDBOX_APP_API_URL;
15025
+ if (!token || !/^happ_[a-f0-9]{64}$/.test(token) || !url2) {
15026
+ throw new Error(
15027
+ `Connect your app's ${mode === "live" ? "production" : "development"} platform environment before using Customers or Payments.`
15028
+ );
15029
+ }
15030
+ return { mode, token, url: url2 };
15031
+ }
15032
+ var AppRuntime = class {
15033
+ constructor(client, token, mode) {
15034
+ this.mode = mode;
15035
+ this.customers = new CustomerRuntime(client);
15036
+ this.payments = new PaymentRuntime(client, { token, mode });
15037
+ }
15038
+ };
15039
+
14568
15040
  // src/identity.ts
14569
15041
  var identitySchema = external_exports.object({
14570
15042
  user: external_exports.object({ id: external_exports.string(), name: external_exports.string() }).nullable(),
@@ -20241,6 +20713,8 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20241
20713
  this.notebook = new NotebookApi(this);
20242
20714
  this.servers = new ServerApi(this);
20243
20715
  this.integrations = new IntegrationApi(this);
20716
+ this.payments = new PaymentsApi(this);
20717
+ this.customers = new CustomersApi(this);
20244
20718
  this.options = { ...options };
20245
20719
  this.runtimeTransportValue = runtimeTransport;
20246
20720
  this.baseUrl = normalizeApiBaseUrl(url2);
@@ -20381,6 +20855,8 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20381
20855
  this.publications = client.publications;
20382
20856
  this.servers = client.servers;
20383
20857
  this.integrations = client.integrations;
20858
+ this.payments = client.payments;
20859
+ this.customers = client.customers;
20384
20860
  }
20385
20861
  async whoami() {
20386
20862
  const { data } = await this.client.get("/auth/whoami");
@@ -20393,6 +20869,10 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20393
20869
  get runtimeTransport() {
20394
20870
  return this.client.runtimeTransport;
20395
20871
  }
20872
+ static app(options = {}) {
20873
+ const { token, url: url2, mode } = resolveAppConfiguration(options);
20874
+ return new AppRuntime(new ClientImplementation(token, url2, {}, "rest"), token, mode);
20875
+ }
20396
20876
  static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20397
20877
  return new _PHPSandbox(new ClientImplementation(token, url2, options));
20398
20878
  }
@@ -20447,6 +20927,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20447
20927
  this.config = new Config(this);
20448
20928
  this.secrets = new NotebookSecrets(client, this.data.id);
20449
20929
  this.integrations = new SandboxIntegrationApi(this.data.id, client);
20930
+ this.payments = new NotebookPayments(this.data.id, client);
20450
20931
  this.preview = new NotebookPreview(client, this.data.id);
20451
20932
  this.mail = new NotebookMail(client, this.data.id);
20452
20933
  this.feedback = new Feedback(client, this.data.id);
@@ -20750,6 +21231,11 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20750
21231
  const response = await this.client.get(`/notebook/${this.notebookId}/mail`);
20751
21232
  return response.data;
20752
21233
  }
21234
+ /** Capture a platform-generated development email in the notebook inbox. Never sends externally. */
21235
+ async capture(input) {
21236
+ const response = await this.client.post(`/notebook/${this.notebookId}/mails`, input);
21237
+ return response.data;
21238
+ }
20753
21239
  async enable() {
20754
21240
  const response = await this.client.put(`/notebook/${this.notebookId}/mail`);
20755
21241
  return response.data;