@phpsandbox/sdk 0.4.0 → 0.6.0-canary.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/README.md +59 -0
- package/dist/app.d.ts +21 -0
- package/dist/app.js +23 -0
- package/dist/browser/phpsandbox-sdk.esm.js +5524 -5230
- package/dist/browser/phpsandbox-sdk.esm.min.js +9 -9
- package/dist/browser/phpsandbox-sdk.iife.js +5524 -5230
- package/dist/browser/phpsandbox-sdk.iife.min.js +9 -9
- package/dist/customers.d.ts +430 -0
- package/dist/customers.js +242 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +15 -0
- package/dist/payments.d.ts +17 -1
- package/dist/payments.js +11 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { AppRuntime, type AppRuntimeOptions } from './app.js';
|
|
2
|
+
export { AppRuntime };
|
|
3
|
+
export type { AppRuntimeOptions };
|
|
1
4
|
import { type Identity } from './identity.js';
|
|
2
5
|
export type { Identity } from './identity.js';
|
|
3
6
|
import { NotebookPublication } from './publication/index.js';
|
|
@@ -19,6 +22,8 @@ import { ServerApi } from './servers.js';
|
|
|
19
22
|
import { Feedback } from './feedback.js';
|
|
20
23
|
import { IntegrationApi, SandboxIntegrationApi } from './integrations/index.js';
|
|
21
24
|
import { PaymentsApi, NotebookPayments } from './payments.js';
|
|
25
|
+
import { CustomersApi } from './customers.js';
|
|
26
|
+
export * from './customers.js';
|
|
22
27
|
export * from './payments.js';
|
|
23
28
|
export type { Disposable } from './types.js';
|
|
24
29
|
export { LspConnection } from './lsp.js';
|
|
@@ -174,6 +179,8 @@ export interface NotebookSecretData {
|
|
|
174
179
|
name: string;
|
|
175
180
|
type: SecretType;
|
|
176
181
|
environment: SecretEnvironment;
|
|
182
|
+
managedBy?: string | null;
|
|
183
|
+
inheritOnFork?: boolean;
|
|
177
184
|
createdAt: string | null;
|
|
178
185
|
updatedAt: string | null;
|
|
179
186
|
}
|
|
@@ -181,6 +188,9 @@ export interface NotebookSecretListOptions {
|
|
|
181
188
|
environment?: SecretEnvironment;
|
|
182
189
|
}
|
|
183
190
|
export interface UpsertNotebookSecretInput {
|
|
191
|
+
/** Platform-owned secrets cannot be inherited by forks. Requires a platform credential. */
|
|
192
|
+
managed?: boolean;
|
|
193
|
+
inheritOnFork?: boolean;
|
|
184
194
|
value: string;
|
|
185
195
|
type?: SecretType;
|
|
186
196
|
environment?: SecretEnvironment;
|
|
@@ -278,6 +288,7 @@ export interface NotebookMailData {
|
|
|
278
288
|
createdAt: string;
|
|
279
289
|
diffForHumans: string;
|
|
280
290
|
html: string | null;
|
|
291
|
+
text?: string | null;
|
|
281
292
|
}
|
|
282
293
|
export interface NotebookMailStateData {
|
|
283
294
|
enabled: boolean;
|
|
@@ -332,6 +343,7 @@ declare class ClientImplementation {
|
|
|
332
343
|
readonly servers: ServerApi;
|
|
333
344
|
readonly integrations: IntegrationApi;
|
|
334
345
|
readonly payments: PaymentsApi;
|
|
346
|
+
readonly customers: CustomersApi;
|
|
335
347
|
readonly options: PHPSandboxClientOptions;
|
|
336
348
|
private readonly runtimeTransportValue;
|
|
337
349
|
get runtimeTransport(): RuntimeTransport;
|
|
@@ -368,9 +380,11 @@ export declare class PHPSandbox {
|
|
|
368
380
|
readonly servers: ServerApi;
|
|
369
381
|
readonly integrations: IntegrationApi;
|
|
370
382
|
readonly payments: PaymentsApi;
|
|
383
|
+
readonly customers: CustomersApi;
|
|
371
384
|
private constructor();
|
|
372
385
|
whoami(): Promise<Identity>;
|
|
373
386
|
get runtimeTransport(): RuntimeTransport;
|
|
387
|
+
static app(options?: AppRuntimeOptions): AppRuntime;
|
|
374
388
|
static realtime(token: string, url?: string, options?: PHPSandboxClientOptions): PHPSandbox;
|
|
375
389
|
static rest(token: string, url?: string, options?: PHPSandboxClientOptions): PHPSandbox;
|
|
376
390
|
}
|
|
@@ -467,6 +481,16 @@ declare class NotebookMail {
|
|
|
467
481
|
private readonly notebookId;
|
|
468
482
|
constructor(client: Client, notebookId: string);
|
|
469
483
|
status(): Promise<NotebookMailStateData>;
|
|
484
|
+
/** Capture a platform-generated development email in the notebook inbox. Never sends externally. */
|
|
485
|
+
capture(input: {
|
|
486
|
+
requestId: string;
|
|
487
|
+
from: string;
|
|
488
|
+
fromName: string;
|
|
489
|
+
to: string;
|
|
490
|
+
subject: string;
|
|
491
|
+
text: string;
|
|
492
|
+
html?: string;
|
|
493
|
+
}): Promise<NotebookMailData>;
|
|
470
494
|
enable(): Promise<NotebookMailStateData>;
|
|
471
495
|
disable(): Promise<void>;
|
|
472
496
|
list(options?: NotebookMailListOptions): Promise<PaginatedApiResponse<NotebookMailData>>;
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,8 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
12
|
var _NotebookInstance_instances, _NotebookInstance_initPromise, _NotebookInstance_init;
|
|
13
|
+
import { AppRuntime, resolveAppConfiguration } from './app.js';
|
|
14
|
+
export { AppRuntime };
|
|
13
15
|
import { identitySchema } from './identity.js';
|
|
14
16
|
import { NotebookPublication } from './publication/index.js';
|
|
15
17
|
import { Filesystem } from './filesystem.js';
|
|
@@ -32,6 +34,8 @@ import { Feedback } from './feedback.js';
|
|
|
32
34
|
import { IntegrationApi, SandboxIntegrationApi } from './integrations/index.js';
|
|
33
35
|
import { authenticatedRequest } from './http.js';
|
|
34
36
|
import { PaymentsApi, NotebookPayments } from './payments.js';
|
|
37
|
+
import { CustomersApi } from './customers.js';
|
|
38
|
+
export * from './customers.js';
|
|
35
39
|
export * from './payments.js';
|
|
36
40
|
export { LspConnection } from './lsp.js';
|
|
37
41
|
export { FileChangeFilter, FileChangeType, FileType } from './filesystem.js';
|
|
@@ -89,6 +93,7 @@ class ClientImplementation {
|
|
|
89
93
|
this.servers = new ServerApi(this);
|
|
90
94
|
this.integrations = new IntegrationApi(this);
|
|
91
95
|
this.payments = new PaymentsApi(this);
|
|
96
|
+
this.customers = new CustomersApi(this);
|
|
92
97
|
this.options = { ...options };
|
|
93
98
|
this.runtimeTransportValue = runtimeTransport;
|
|
94
99
|
this.baseUrl = normalizeApiBaseUrl(url);
|
|
@@ -224,6 +229,7 @@ export class PHPSandbox {
|
|
|
224
229
|
this.servers = client.servers;
|
|
225
230
|
this.integrations = client.integrations;
|
|
226
231
|
this.payments = client.payments;
|
|
232
|
+
this.customers = client.customers;
|
|
227
233
|
}
|
|
228
234
|
async whoami() {
|
|
229
235
|
const { data } = await this.client.get('/auth/whoami');
|
|
@@ -236,6 +242,10 @@ export class PHPSandbox {
|
|
|
236
242
|
get runtimeTransport() {
|
|
237
243
|
return this.client.runtimeTransport;
|
|
238
244
|
}
|
|
245
|
+
static app(options = {}) {
|
|
246
|
+
const { token, url, mode } = resolveAppConfiguration(options);
|
|
247
|
+
return new AppRuntime(new ClientImplementation(token, url, {}, 'rest'), token, mode);
|
|
248
|
+
}
|
|
239
249
|
static realtime(token, url = 'https://api.phpsandbox.io/v1', options = {}) {
|
|
240
250
|
return new PHPSandbox(new ClientImplementation(token, url, options));
|
|
241
251
|
}
|
|
@@ -598,6 +608,11 @@ class NotebookMail {
|
|
|
598
608
|
const response = await this.client.get(`/notebook/${this.notebookId}/mail`);
|
|
599
609
|
return response.data;
|
|
600
610
|
}
|
|
611
|
+
/** Capture a platform-generated development email in the notebook inbox. Never sends externally. */
|
|
612
|
+
async capture(input) {
|
|
613
|
+
const response = await this.client.post(`/notebook/${this.notebookId}/mails`, input);
|
|
614
|
+
return response.data;
|
|
615
|
+
}
|
|
601
616
|
async enable() {
|
|
602
617
|
const response = await this.client.put(`/notebook/${this.notebookId}/mail`);
|
|
603
618
|
return response.data;
|
package/dist/payments.d.ts
CHANGED
|
@@ -43,6 +43,10 @@ declare const applicationsSchema: z.ZodObject<{
|
|
|
43
43
|
}, z.core.$strip>;
|
|
44
44
|
export type PaymentApplicationsData = z.infer<typeof applicationsSchema>;
|
|
45
45
|
declare const bindingSchema: z.ZodObject<{
|
|
46
|
+
target: z.ZodOptional<z.ZodEnum<{
|
|
47
|
+
preview: "preview";
|
|
48
|
+
publication: "publication";
|
|
49
|
+
}>>;
|
|
46
50
|
id: z.ZodString;
|
|
47
51
|
notebookId: z.ZodString;
|
|
48
52
|
applicationId: z.ZodNullable<z.ZodString>;
|
|
@@ -164,6 +168,10 @@ declare const activationSchema: z.ZodObject<{
|
|
|
164
168
|
expiresAt: z.ZodString;
|
|
165
169
|
blockers: z.ZodArray<z.ZodString>;
|
|
166
170
|
binding: z.ZodObject<{
|
|
171
|
+
target: z.ZodOptional<z.ZodEnum<{
|
|
172
|
+
preview: "preview";
|
|
173
|
+
publication: "publication";
|
|
174
|
+
}>>;
|
|
167
175
|
id: z.ZodString;
|
|
168
176
|
notebookId: z.ZodString;
|
|
169
177
|
applicationId: z.ZodNullable<z.ZodString>;
|
|
@@ -205,6 +213,7 @@ declare const activationSchema: z.ZodObject<{
|
|
|
205
213
|
}, z.core.$strip>;
|
|
206
214
|
export type PaymentActivationReview = z.infer<typeof activationSchema>;
|
|
207
215
|
export interface ConfigurePaymentsInput {
|
|
216
|
+
target?: 'preview' | 'publication';
|
|
208
217
|
expectedRevision: number;
|
|
209
218
|
applicationId?: string | null;
|
|
210
219
|
callbackPath?: string;
|
|
@@ -217,6 +226,7 @@ export interface CreatePaymentPriceInput {
|
|
|
217
226
|
currency: string;
|
|
218
227
|
}
|
|
219
228
|
export interface CreatePaymentCheckoutInput {
|
|
229
|
+
customerId?: string;
|
|
220
230
|
requestId: string;
|
|
221
231
|
orderId: string;
|
|
222
232
|
priceId: string;
|
|
@@ -333,7 +343,13 @@ export type PaymentEvent = z.infer<typeof paymentEventSchema>;
|
|
|
333
343
|
export declare function verifyPaymentEvent(body: string, signature: string, token: string, mode: PaymentMode, now?: number): Promise<PaymentEvent>;
|
|
334
344
|
export declare class PaymentRuntime {
|
|
335
345
|
private readonly client;
|
|
336
|
-
|
|
346
|
+
private readonly appCredential?;
|
|
347
|
+
constructor(client: Client, appCredential?: {
|
|
348
|
+
token: string;
|
|
349
|
+
mode: PaymentMode;
|
|
350
|
+
} | undefined);
|
|
351
|
+
/** Verify the phpsandbox-signature header against the configured app environment. */
|
|
352
|
+
verifyEvent(body: string, signature: string): Promise<PaymentEvent>;
|
|
337
353
|
checkout(input: CreatePaymentCheckoutInput): Promise<PaymentTransactionData>;
|
|
338
354
|
transaction(id: string): Promise<PaymentTransactionData>;
|
|
339
355
|
subscribe(input: CreatePaymentCheckoutInput): Promise<PaymentSubscriptionData>;
|
package/dist/payments.js
CHANGED
|
@@ -32,6 +32,7 @@ const applicationsSchema = z.object({
|
|
|
32
32
|
})),
|
|
33
33
|
});
|
|
34
34
|
const bindingSchema = z.object({
|
|
35
|
+
target: z.enum(['preview', 'publication']).optional(),
|
|
35
36
|
id: z.string(),
|
|
36
37
|
notebookId: z.string(),
|
|
37
38
|
applicationId: z.string().nullable(),
|
|
@@ -207,7 +208,7 @@ const paymentEventSchema = z.discriminatedUnion('type', [
|
|
|
207
208
|
]);
|
|
208
209
|
/** Verify the original bytes before parsing JSON. Use only in trusted server code. */
|
|
209
210
|
export async function verifyPaymentEvent(body, signature, token, mode, now = Date.now()) {
|
|
210
|
-
if (!/^
|
|
211
|
+
if (!/^(?:hpay|happ)_[a-f0-9]{64}$/.test(token)) {
|
|
211
212
|
throw new Error('Invalid application payment credential.');
|
|
212
213
|
}
|
|
213
214
|
const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(signature);
|
|
@@ -229,8 +230,16 @@ export async function verifyPaymentEvent(body, signature, token, mode, now = Dat
|
|
|
229
230
|
return event;
|
|
230
231
|
}
|
|
231
232
|
export class PaymentRuntime {
|
|
232
|
-
constructor(client) {
|
|
233
|
+
constructor(client, appCredential) {
|
|
233
234
|
this.client = client;
|
|
235
|
+
this.appCredential = appCredential;
|
|
236
|
+
}
|
|
237
|
+
/** Verify the phpsandbox-signature header against the configured app environment. */
|
|
238
|
+
async verifyEvent(body, signature) {
|
|
239
|
+
if (!this.appCredential) {
|
|
240
|
+
throw new Error('Initialize the server app client with PHPSandbox.app() to verify payment events.');
|
|
241
|
+
}
|
|
242
|
+
return verifyPaymentEvent(body, signature, this.appCredential.token, this.appCredential.mode);
|
|
234
243
|
}
|
|
235
244
|
async checkout(input) {
|
|
236
245
|
return transactionSchema.parse((await this.client.post('/platform/payments/runtime/checkouts', input)).data);
|