@phpsandbox/sdk 0.3.5 → 0.4.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.
- package/dist/browser/phpsandbox-sdk.esm.js +284 -1
- package/dist/browser/phpsandbox-sdk.esm.min.js +10 -10
- package/dist/browser/phpsandbox-sdk.iife.js +284 -1
- package/dist/browser/phpsandbox-sdk.iife.min.js +10 -10
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/payments.d.ts +347 -0
- package/dist/payments.js +256 -0
- package/package.json +1 -1
|
@@ -29,14 +29,18 @@ var PHPSandbox = (() => {
|
|
|
29
29
|
// src/index.ts
|
|
30
30
|
var index_exports = {};
|
|
31
31
|
__export(index_exports, {
|
|
32
|
+
DEFAULT_PAYMENT_CALLBACK_PATH: () => DEFAULT_PAYMENT_CALLBACK_PATH,
|
|
32
33
|
FileChangeFilter: () => FileChangeFilter,
|
|
33
34
|
FileChangeType: () => FileChangeType,
|
|
34
35
|
FileType: () => FileType,
|
|
35
36
|
LspConnection: () => LspConnection,
|
|
36
37
|
NotebookInstance: () => NotebookInstance,
|
|
38
|
+
NotebookPayments: () => NotebookPayments,
|
|
37
39
|
NotebookPublication: () => NotebookPublication,
|
|
38
40
|
PHPSandbox: () => PHPSandbox,
|
|
39
41
|
PHPSandboxError: () => PHPSandboxError,
|
|
42
|
+
PaymentRuntime: () => PaymentRuntime,
|
|
43
|
+
PaymentsApi: () => PaymentsApi,
|
|
40
44
|
PublicationApi: () => PublicationApi,
|
|
41
45
|
PublicationDomains: () => PublicationDomains,
|
|
42
46
|
PublicationInstance: () => PublicationInstance,
|
|
@@ -48,7 +52,9 @@ var PHPSandbox = (() => {
|
|
|
48
52
|
laravelCloudSetupForRepublish: () => laravelCloudSetupForRepublish,
|
|
49
53
|
notebookBuiltinServices: () => notebookBuiltinServices,
|
|
50
54
|
notebookKnownServices: () => notebookKnownServices,
|
|
51
|
-
|
|
55
|
+
paymentModeSchema: () => paymentModeSchema,
|
|
56
|
+
readPublicationStream: () => readPublicationStream,
|
|
57
|
+
verifyPaymentEvent: () => verifyPaymentEvent
|
|
52
58
|
});
|
|
53
59
|
|
|
54
60
|
// node_modules/zod/v4/classic/external.js
|
|
@@ -20191,6 +20197,280 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20191
20197
|
return typeof integration === "string" ? integration : integration.id;
|
|
20192
20198
|
}
|
|
20193
20199
|
|
|
20200
|
+
// src/payments.ts
|
|
20201
|
+
var DEFAULT_PAYMENT_CALLBACK_PATH = "/api/phpsandbox-payments/events";
|
|
20202
|
+
var paymentModeSchema = external_exports.enum(["test", "live"]);
|
|
20203
|
+
var accountSchema = external_exports.object({
|
|
20204
|
+
id: external_exports.string(),
|
|
20205
|
+
mode: paymentModeSchema,
|
|
20206
|
+
chargesEnabled: external_exports.boolean(),
|
|
20207
|
+
payoutsEnabled: external_exports.boolean(),
|
|
20208
|
+
detailsSubmitted: external_exports.boolean(),
|
|
20209
|
+
requirements: external_exports.array(external_exports.string()),
|
|
20210
|
+
disabledReason: external_exports.string().nullable()
|
|
20211
|
+
});
|
|
20212
|
+
var accessSchema = external_exports.object({
|
|
20213
|
+
subscribed: external_exports.boolean(),
|
|
20214
|
+
liveAllowed: external_exports.boolean(),
|
|
20215
|
+
testConfigured: external_exports.boolean(),
|
|
20216
|
+
liveConfigured: external_exports.boolean(),
|
|
20217
|
+
feeBasisPoints: external_exports.number().int().min(0).max(1e4).nullable(),
|
|
20218
|
+
canRead: external_exports.boolean(),
|
|
20219
|
+
canManage: external_exports.boolean(),
|
|
20220
|
+
canRefund: external_exports.boolean(),
|
|
20221
|
+
recoveryEndsAt: external_exports.string().nullable().default(null)
|
|
20222
|
+
});
|
|
20223
|
+
var applicationsSchema = external_exports.object({
|
|
20224
|
+
notebookId: external_exports.string(),
|
|
20225
|
+
applications: external_exports.array(
|
|
20226
|
+
external_exports.object({
|
|
20227
|
+
id: external_exports.string(),
|
|
20228
|
+
url: external_exports.string().nullable(),
|
|
20229
|
+
healthy: external_exports.boolean(),
|
|
20230
|
+
passwordProtected: external_exports.boolean(),
|
|
20231
|
+
deployedAt: external_exports.string().datetime().nullable()
|
|
20232
|
+
})
|
|
20233
|
+
)
|
|
20234
|
+
});
|
|
20235
|
+
var bindingSchema = external_exports.object({
|
|
20236
|
+
id: external_exports.string(),
|
|
20237
|
+
notebookId: external_exports.string(),
|
|
20238
|
+
applicationId: external_exports.string().nullable(),
|
|
20239
|
+
mode: paymentModeSchema,
|
|
20240
|
+
revision: external_exports.number().int(),
|
|
20241
|
+
accountId: external_exports.string(),
|
|
20242
|
+
enabled: external_exports.boolean(),
|
|
20243
|
+
callbackUrl: external_exports.string().nullable(),
|
|
20244
|
+
originUrl: external_exports.string().nullable(),
|
|
20245
|
+
runtimeConfigured: external_exports.boolean()
|
|
20246
|
+
});
|
|
20247
|
+
var priceSchema = external_exports.object({
|
|
20248
|
+
billingInterval: external_exports.enum(["month", "year"]).nullable().default(null),
|
|
20249
|
+
id: external_exports.string(),
|
|
20250
|
+
name: external_exports.string(),
|
|
20251
|
+
amount: external_exports.number().int(),
|
|
20252
|
+
currency: external_exports.string(),
|
|
20253
|
+
bindingId: external_exports.string()
|
|
20254
|
+
});
|
|
20255
|
+
var transactionSchema = external_exports.object({
|
|
20256
|
+
subscriptionId: external_exports.string().nullable().default(null),
|
|
20257
|
+
periodStart: external_exports.string().datetime({ offset: true }).nullable().default(null),
|
|
20258
|
+
periodEnd: external_exports.string().datetime({ offset: true }).nullable().default(null),
|
|
20259
|
+
id: external_exports.string(),
|
|
20260
|
+
bindingId: external_exports.string(),
|
|
20261
|
+
orderId: external_exports.string(),
|
|
20262
|
+
priceId: external_exports.string(),
|
|
20263
|
+
amount: external_exports.number().int(),
|
|
20264
|
+
currency: external_exports.string(),
|
|
20265
|
+
feeAmount: external_exports.number().int(),
|
|
20266
|
+
revision: external_exports.number().int(),
|
|
20267
|
+
refundedAmount: external_exports.number().int(),
|
|
20268
|
+
status: external_exports.enum(["pending", "paid", "failed", "refunded", "partially_refunded"]),
|
|
20269
|
+
checkoutUrl: external_exports.string().nullable(),
|
|
20270
|
+
deliveredAt: external_exports.string().nullable()
|
|
20271
|
+
});
|
|
20272
|
+
var subscriptionSchema = external_exports.object({
|
|
20273
|
+
id: external_exports.string(),
|
|
20274
|
+
bindingId: external_exports.string(),
|
|
20275
|
+
priceId: external_exports.string(),
|
|
20276
|
+
orderId: external_exports.string(),
|
|
20277
|
+
status: external_exports.enum([
|
|
20278
|
+
"pending",
|
|
20279
|
+
"incomplete",
|
|
20280
|
+
"incomplete_expired",
|
|
20281
|
+
"trialing",
|
|
20282
|
+
"active",
|
|
20283
|
+
"past_due",
|
|
20284
|
+
"canceled",
|
|
20285
|
+
"unpaid",
|
|
20286
|
+
"paused"
|
|
20287
|
+
]),
|
|
20288
|
+
billingInterval: external_exports.enum(["month", "year"]),
|
|
20289
|
+
paidThrough: external_exports.string().datetime({ offset: true }).nullable(),
|
|
20290
|
+
cancelAtPeriodEnd: external_exports.boolean(),
|
|
20291
|
+
checkoutUrl: external_exports.string().nullable(),
|
|
20292
|
+
revision: external_exports.number().int()
|
|
20293
|
+
});
|
|
20294
|
+
var portalSchema = external_exports.object({ url: external_exports.string().url() });
|
|
20295
|
+
var refundResultSchema = transactionSchema.extend({
|
|
20296
|
+
refund: external_exports.object({
|
|
20297
|
+
id: external_exports.string(),
|
|
20298
|
+
amount: external_exports.number().int().positive(),
|
|
20299
|
+
status: external_exports.enum(["pending", "succeeded", "failed", "canceled", "requires_action"])
|
|
20300
|
+
})
|
|
20301
|
+
});
|
|
20302
|
+
var activationSchema = external_exports.object({
|
|
20303
|
+
revision: external_exports.number().int(),
|
|
20304
|
+
reviewId: external_exports.string(),
|
|
20305
|
+
expiresAt: external_exports.string(),
|
|
20306
|
+
blockers: external_exports.array(external_exports.string()),
|
|
20307
|
+
binding: bindingSchema,
|
|
20308
|
+
account: accountSchema,
|
|
20309
|
+
feeBasisPoints: external_exports.number().int().nullable(),
|
|
20310
|
+
prices: external_exports.array(priceSchema)
|
|
20311
|
+
});
|
|
20312
|
+
var PaymentsApi = class {
|
|
20313
|
+
constructor(client) {
|
|
20314
|
+
this.client = client;
|
|
20315
|
+
this.runtime = new PaymentRuntime(client);
|
|
20316
|
+
}
|
|
20317
|
+
forNotebook(notebookId) {
|
|
20318
|
+
return new NotebookPayments(notebookId, this.client);
|
|
20319
|
+
}
|
|
20320
|
+
async applications(notebookId) {
|
|
20321
|
+
return applicationsSchema.parse(
|
|
20322
|
+
(await this.client.get(`/notebook/${encodeURIComponent(notebookId)}/payments/applications`)).data
|
|
20323
|
+
);
|
|
20324
|
+
}
|
|
20325
|
+
async access() {
|
|
20326
|
+
return accessSchema.parse((await this.client.get("/platform/payments/access")).data);
|
|
20327
|
+
}
|
|
20328
|
+
async accounts() {
|
|
20329
|
+
return external_exports.array(accountSchema).parse((await this.client.get("/platform/payments/accounts")).data);
|
|
20330
|
+
}
|
|
20331
|
+
async createAccount(mode, country) {
|
|
20332
|
+
return accountSchema.parse((await this.client.put(`/platform/payments/accounts/${mode}`, { country })).data);
|
|
20333
|
+
}
|
|
20334
|
+
async onboarding(mode) {
|
|
20335
|
+
return external_exports.object({ url: external_exports.string().url(), expiresAt: external_exports.string() }).parse((await this.client.post(`/platform/payments/accounts/${mode}/onboarding`, {})).data);
|
|
20336
|
+
}
|
|
20337
|
+
};
|
|
20338
|
+
var NotebookPayments = class {
|
|
20339
|
+
constructor(notebookId, client) {
|
|
20340
|
+
this.notebookId = notebookId;
|
|
20341
|
+
this.client = client;
|
|
20342
|
+
}
|
|
20343
|
+
path(mode) {
|
|
20344
|
+
return `/platform/payments/sandboxes/${encodeURIComponent(this.notebookId)}/${mode}`;
|
|
20345
|
+
}
|
|
20346
|
+
async get(mode = "test") {
|
|
20347
|
+
return bindingSchema.nullable().parse((await this.client.get(this.path(mode))).data);
|
|
20348
|
+
}
|
|
20349
|
+
async configure(input, mode = "test") {
|
|
20350
|
+
return bindingSchema.parse((await this.client.put(this.path(mode), input)).data);
|
|
20351
|
+
}
|
|
20352
|
+
async provision(mode = "test") {
|
|
20353
|
+
return bindingSchema.parse((await this.client.post(`${this.path(mode)}/provision`, {})).data);
|
|
20354
|
+
}
|
|
20355
|
+
async prices(mode = "test") {
|
|
20356
|
+
return external_exports.array(priceSchema).parse((await this.client.get(`${this.path(mode)}/prices`)).data);
|
|
20357
|
+
}
|
|
20358
|
+
async createPrice(input, mode = "test") {
|
|
20359
|
+
return priceSchema.parse((await this.client.post(`${this.path(mode)}/prices`, input)).data);
|
|
20360
|
+
}
|
|
20361
|
+
async prepareActivation(mode = "test") {
|
|
20362
|
+
return activationSchema.parse((await this.client.post(`${this.path(mode)}/activation`, {})).data);
|
|
20363
|
+
}
|
|
20364
|
+
async activate(reviewId, mode = "test") {
|
|
20365
|
+
return bindingSchema.parse((await this.client.post(`${this.path(mode)}/activate`, { reviewId })).data);
|
|
20366
|
+
}
|
|
20367
|
+
async disable(mode = "test") {
|
|
20368
|
+
return bindingSchema.parse((await this.client.post(`${this.path(mode)}/disable`, {})).data);
|
|
20369
|
+
}
|
|
20370
|
+
async checkout(input, mode = "test") {
|
|
20371
|
+
return transactionSchema.parse((await this.client.post(`${this.path(mode)}/checkouts`, input)).data);
|
|
20372
|
+
}
|
|
20373
|
+
async subscribe(input, mode = "test") {
|
|
20374
|
+
return subscriptionSchema.parse((await this.client.post(`${this.path(mode)}/subscriptions`, input)).data);
|
|
20375
|
+
}
|
|
20376
|
+
async subscriptions(mode = "test") {
|
|
20377
|
+
return external_exports.array(subscriptionSchema).parse((await this.client.get(`${this.path(mode)}/subscriptions`)).data);
|
|
20378
|
+
}
|
|
20379
|
+
async subscription(id, mode = "test") {
|
|
20380
|
+
return subscriptionSchema.parse(
|
|
20381
|
+
(await this.client.get(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}`)).data
|
|
20382
|
+
);
|
|
20383
|
+
}
|
|
20384
|
+
async cancelSubscription(id, mode = "test") {
|
|
20385
|
+
return subscriptionSchema.parse(
|
|
20386
|
+
(await this.client.post(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}/cancel`, {})).data
|
|
20387
|
+
);
|
|
20388
|
+
}
|
|
20389
|
+
async subscriptionPortal(id, input, mode = "test") {
|
|
20390
|
+
return portalSchema.parse(
|
|
20391
|
+
(await this.client.post(`${this.path(mode)}/subscriptions/${encodeURIComponent(id)}/portal`, input)).data
|
|
20392
|
+
);
|
|
20393
|
+
}
|
|
20394
|
+
async transactions(mode = "test") {
|
|
20395
|
+
return external_exports.array(transactionSchema).parse((await this.client.get(`${this.path(mode)}/transactions`)).data);
|
|
20396
|
+
}
|
|
20397
|
+
async refund(id, input, mode = "test") {
|
|
20398
|
+
return refundResultSchema.parse(
|
|
20399
|
+
(await this.client.post(`${this.path(mode)}/transactions/${encodeURIComponent(id)}/refund`, input)).data
|
|
20400
|
+
);
|
|
20401
|
+
}
|
|
20402
|
+
};
|
|
20403
|
+
var paymentEventSchema = external_exports.discriminatedUnion("type", [
|
|
20404
|
+
external_exports.object({
|
|
20405
|
+
id: external_exports.string(),
|
|
20406
|
+
type: external_exports.literal("payment.updated"),
|
|
20407
|
+
mode: paymentModeSchema,
|
|
20408
|
+
transaction: transactionSchema
|
|
20409
|
+
}),
|
|
20410
|
+
external_exports.object({
|
|
20411
|
+
id: external_exports.string(),
|
|
20412
|
+
type: external_exports.literal("subscription.updated"),
|
|
20413
|
+
mode: paymentModeSchema,
|
|
20414
|
+
subscription: subscriptionSchema
|
|
20415
|
+
})
|
|
20416
|
+
]);
|
|
20417
|
+
async function verifyPaymentEvent(body, signature, token, mode, now = Date.now()) {
|
|
20418
|
+
if (!/^hpay_[a-f0-9]{64}$/.test(token)) {
|
|
20419
|
+
throw new Error("Invalid application payment credential.");
|
|
20420
|
+
}
|
|
20421
|
+
const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(signature);
|
|
20422
|
+
const timestamp = match?.[1];
|
|
20423
|
+
const digest = match?.[2];
|
|
20424
|
+
if (!timestamp || !digest || Math.abs(now - Number(timestamp) * 1e3) > 3e5 || body.length > 262144) {
|
|
20425
|
+
throw new Error("Invalid or expired payment signature.");
|
|
20426
|
+
}
|
|
20427
|
+
const encoder = new TextEncoder();
|
|
20428
|
+
const key = await crypto.subtle.importKey("raw", encoder.encode(token), { name: "HMAC", hash: "SHA-256" }, false, ["verify"]);
|
|
20429
|
+
const bytes = Uint8Array.from(digest.match(/../g) ?? [], (byte) => Number.parseInt(byte, 16));
|
|
20430
|
+
if (!await crypto.subtle.verify("HMAC", key, bytes, encoder.encode(`${timestamp}.${body}`))) {
|
|
20431
|
+
throw new Error("Invalid payment signature.");
|
|
20432
|
+
}
|
|
20433
|
+
const event = paymentEventSchema.parse(JSON.parse(body));
|
|
20434
|
+
if (event.mode !== mode) {
|
|
20435
|
+
throw new Error("Payment event mode does not match this application.");
|
|
20436
|
+
}
|
|
20437
|
+
return event;
|
|
20438
|
+
}
|
|
20439
|
+
var PaymentRuntime = class {
|
|
20440
|
+
constructor(client) {
|
|
20441
|
+
this.client = client;
|
|
20442
|
+
}
|
|
20443
|
+
async checkout(input) {
|
|
20444
|
+
return transactionSchema.parse((await this.client.post("/platform/payments/runtime/checkouts", input)).data);
|
|
20445
|
+
}
|
|
20446
|
+
async transaction(id) {
|
|
20447
|
+
return transactionSchema.parse(
|
|
20448
|
+
(await this.client.get(`/platform/payments/runtime/transactions/${encodeURIComponent(id)}`)).data
|
|
20449
|
+
);
|
|
20450
|
+
}
|
|
20451
|
+
async subscribe(input) {
|
|
20452
|
+
return subscriptionSchema.parse((await this.client.post("/platform/payments/runtime/subscriptions", input)).data);
|
|
20453
|
+
}
|
|
20454
|
+
async subscription(id) {
|
|
20455
|
+
return subscriptionSchema.parse(
|
|
20456
|
+
(await this.client.get(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}`)).data
|
|
20457
|
+
);
|
|
20458
|
+
}
|
|
20459
|
+
async cancelSubscription(id) {
|
|
20460
|
+
return subscriptionSchema.parse(
|
|
20461
|
+
(await this.client.post(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}/cancel`, {})).data
|
|
20462
|
+
);
|
|
20463
|
+
}
|
|
20464
|
+
async subscriptionPortal(id, input) {
|
|
20465
|
+
return portalSchema.parse(
|
|
20466
|
+
(await this.client.post(`/platform/payments/runtime/subscriptions/${encodeURIComponent(id)}/portal`, input)).data
|
|
20467
|
+
);
|
|
20468
|
+
}
|
|
20469
|
+
async prices() {
|
|
20470
|
+
return external_exports.array(priceSchema).parse((await this.client.get("/platform/payments/runtime/prices")).data);
|
|
20471
|
+
}
|
|
20472
|
+
};
|
|
20473
|
+
|
|
20194
20474
|
// src/index.ts
|
|
20195
20475
|
function normalizeNotebookSecretInputs(input) {
|
|
20196
20476
|
if (Array.isArray(input)) {
|
|
@@ -20241,6 +20521,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20241
20521
|
this.notebook = new NotebookApi(this);
|
|
20242
20522
|
this.servers = new ServerApi(this);
|
|
20243
20523
|
this.integrations = new IntegrationApi(this);
|
|
20524
|
+
this.payments = new PaymentsApi(this);
|
|
20244
20525
|
this.options = { ...options };
|
|
20245
20526
|
this.runtimeTransportValue = runtimeTransport;
|
|
20246
20527
|
this.baseUrl = normalizeApiBaseUrl(url2);
|
|
@@ -20381,6 +20662,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20381
20662
|
this.publications = client.publications;
|
|
20382
20663
|
this.servers = client.servers;
|
|
20383
20664
|
this.integrations = client.integrations;
|
|
20665
|
+
this.payments = client.payments;
|
|
20384
20666
|
}
|
|
20385
20667
|
async whoami() {
|
|
20386
20668
|
const { data } = await this.client.get("/auth/whoami");
|
|
@@ -20447,6 +20729,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20447
20729
|
this.config = new Config(this);
|
|
20448
20730
|
this.secrets = new NotebookSecrets(client, this.data.id);
|
|
20449
20731
|
this.integrations = new SandboxIntegrationApi(this.data.id, client);
|
|
20732
|
+
this.payments = new NotebookPayments(this.data.id, client);
|
|
20450
20733
|
this.preview = new NotebookPreview(client, this.data.id);
|
|
20451
20734
|
this.mail = new NotebookMail(client, this.data.id);
|
|
20452
20735
|
this.feedback = new Feedback(client, this.data.id);
|