spaps-sdk 1.10.0 → 1.10.2
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/CHANGELOG.md +18 -0
- package/README.md +73 -5
- package/dist/index.d.mts +187 -7
- package/dist/index.d.ts +187 -7
- package/dist/index.js +266 -11
- package/dist/index.mjs +266 -11
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as spaps_types from 'spaps-types';
|
|
2
|
-
import { ResourceType, Entitlement, CreateProductRequest, Product, UpdateProductRequest, CreatePriceRequest, Price, ProductSyncResult, CryptoReconcileRequest, CreateSecureMessageRequest, SecureMessage, IssueReportScope, IssueReportStatusResult, IssueReportStatus, IssueReportListResult, IssueReport, CreateIssueReportRequest, IssueReportingVoiceTokenResult, UpdateIssueReportRequest, ReplyIssueReportRequest, CreateAppLinkRequest, AppLink, AuthResponse, User as User$1, CreateCryptoInvoiceRequest, CryptoInvoiceStatusSnapshot, CheckoutSession, X402ResourceStatusResponse, X402ActionResponse, X402ReceiptResponse, X402ReceiptListResponse, X402HandoffVerification, DayrateAvailabilityResponse, DayrateBookingRequest, DayrateBookingResponse, DayrateMultiBookingRequest, DayrateMultiBookingResponse, DayrateX402BookingRequest, DayrateX402BookingResponse, DayrateCheckoutStatusResponse, UsageControlAuthorizeRequest, UsageControlAuthorizeResponse, UsageControlRecordRequest, UsageControlRecordResponse, Subscription, VerifyCryptoWebhookSignatureOptions } from 'spaps-types';
|
|
3
|
-
export { AdminPermission, AdminRole, AdminUser, ApiResponse, AppLink, AuthResponse, CheckoutSession, CreateAppLinkRequest, CreateCryptoInvoiceRequest, CreateIssueReportRequest, CreatePriceRequest, CreateProductRequest, CreateSecureMessageInput, CreateSecureMessageRequest, CryptoInvoice, CryptoInvoiceResponse, CryptoInvoiceStatusSnapshot, CryptoReconcileRequest, DayrateAvailabilityResponse, DayrateAvailableSlot, DayrateBookingRequest, DayrateBookingResponse, DayrateCheckoutStatus, DayrateCheckoutStatusBooking, DayrateCheckoutStatusResponse, DayrateDayOfWeek, DayrateMultiBookingRequest, DayrateMultiBookingResponse, DayratePriceBreakdown, DayrateSlotType, DayrateX402BookingRequest, DayrateX402BookingResponse, Entitlement, IssueReport, IssueReportListResult, IssueReportStatus, IssueReportStatusResult, IssueReportTarget, IssueReportingInputMode, IssueReportingVoiceProvider, IssueReportingVoiceTokenResult, LinkedIssueReportCase, Price, Product, ProductSyncResult, ReplyIssueReportRequest, ResourceType, SecureMessage, SecureMessageOutput, Subscription, TokenPair, UpdateIssueReportRequest, UpdateProductRequest, UsageControlAuthorizeRequest, UsageControlAuthorizeResponse, UsageControlDecision, UsageControlDimensions, UsageControlError, UsageControlErrorCode, UsageControlLedgerEvent, UsageControlRecordRequest, UsageControlRecordResponse, UsageControlRecordStatus, User, UserProfile, UserRole, UserWallet, VerifyCryptoWebhookSignatureOptions, X402ActionFreeResponse, X402ActionOutcome, X402ActionPendingResponse, X402ActionReplayedResponse, X402ActionResponse, X402ActionSettledResponse, X402ExecuteActionRequest, X402HandoffAuthorization, X402HandoffVerification, X402HandoffVerifyRequest, X402PaymentAccept, X402PaymentRequirement, X402ProjectionStatus, X402Receipt, X402ReceiptListResponse, X402ReceiptResponse, X402ReceiptStatus, X402Resource, X402ResourceStatus, X402ResourceStatusResponse, atomicToMoneyUnits, createSecureMessageRequestSchema, isX402PaymentRequired, isX402ResourceStatus, moneyUnitsToAtomic, roundHalfToPositiveInfinity, secureMessageMetadataSchema, secureMessageSchema, validatePositiveAmountAtomic } from 'spaps-types';
|
|
2
|
+
import { ResourceType, Entitlement, CreateProductRequest, Product, UpdateProductRequest, CreatePriceRequest, Price, ProductSyncResult, CryptoReconcileRequest, CreateSecureMessageRequest, SecureMessage, IssueReportScope, IssueReportStatusResult, IssueReportStatus, IssueReportListResult, IssueReport, CreateIssueReportRequest, IssueReportAttachmentOut, ListIssueReportAttachmentsResponse, IssueReportAttachmentAccessResponse, IssueReportingVoiceTokenResult, UpdateIssueReportRequest, ReplyIssueReportRequest, ListIssueReportMessagesResponse, CreateReporterMessageRequest, IssueReportMessage, CreateOperatorMessageRequest, RetractOperatorMessageRequest, CreateAppLinkRequest, AppLink, UpdateAppLinkRequest, AuthResponse, User as User$1, CreateCryptoInvoiceRequest, CryptoInvoiceStatusSnapshot, CheckoutSession, X402ResourceStatusResponse, X402ActionResponse, X402ReceiptResponse, X402ReceiptListResponse, X402HandoffVerification, DayrateAvailabilityResponse, DayrateBookingRequest, DayrateBookingResponse, DayrateMultiBookingRequest, DayrateMultiBookingResponse, DayrateX402BookingRequest, DayrateX402BookingResponse, DayrateCheckoutStatusResponse, UsageControlFeaturesResponse, UsageControlStatusRequest, UsageControlStatusResponse, UsageControlAuthorizeRequest, UsageControlAuthorizeResponse, UsageControlRecordRequest, UsageControlRecordResponse, UsageControlHistoryRequest, UsageControlHistoryResponse, Subscription, VerifyCryptoWebhookSignatureOptions } from 'spaps-types';
|
|
3
|
+
export { AdminPermission, AdminRole, AdminUser, ApiResponse, AppLink, AuthResponse, CheckoutSession, CreateAppLinkRequest, CreateCryptoInvoiceRequest, CreateIssueReportRequest, CreateOperatorMessageRequest, CreatePriceRequest, CreateProductRequest, CreateReporterMessageRequest, CreateSecureMessageInput, CreateSecureMessageRequest, CryptoInvoice, CryptoInvoiceResponse, CryptoInvoiceStatusSnapshot, CryptoReconcileRequest, DayrateAvailabilityResponse, DayrateAvailableSlot, DayrateBookingRequest, DayrateBookingResponse, DayrateCheckoutStatus, DayrateCheckoutStatusBooking, DayrateCheckoutStatusResponse, DayrateDayOfWeek, DayrateMultiBookingRequest, DayrateMultiBookingResponse, DayratePriceBreakdown, DayrateSlotType, DayrateX402BookingRequest, DayrateX402BookingResponse, Entitlement, IssueReport, IssueReportAttachmentAccessResponse, IssueReportAttachmentOut, IssueReportListResult, IssueReportMessage, IssueReportStatus, IssueReportStatusResult, IssueReportTarget, IssueReportingInputMode, IssueReportingVoiceProvider, IssueReportingVoiceTokenResult, LinkedIssueReportCase, ListIssueReportAttachmentsResponse, ListIssueReportMessagesResponse, Price, Product, ProductSyncResult, ReplyIssueReportRequest, ResourceType, RetractOperatorMessageRequest, SecureMessage, SecureMessageOutput, Subscription, TokenPair, UpdateAppLinkRequest, UpdateIssueReportRequest, UpdateProductRequest, UsageControlAuthorizeRequest, UsageControlAuthorizeResponse, UsageControlDecision, UsageControlDimensions, UsageControlError, UsageControlErrorCode, UsageControlFeaturesResponse, UsageControlHistoryRequest, UsageControlHistoryResponse, UsageControlLedgerEvent, UsageControlRecordRequest, UsageControlRecordResponse, UsageControlRecordStatus, UsageControlStatusRequest, UsageControlStatusResponse, User, UserProfile, UserRole, UserWallet, VerifyCryptoWebhookSignatureOptions, X402ActionFreeResponse, X402ActionOutcome, X402ActionPendingResponse, X402ActionReplayedResponse, X402ActionResponse, X402ActionSettledResponse, X402ExecuteActionRequest, X402HandoffAuthorization, X402HandoffVerification, X402HandoffVerifyRequest, X402PaymentAccept, X402PaymentRequirement, X402ProjectionStatus, X402Receipt, X402ReceiptListResponse, X402ReceiptResponse, X402ReceiptStatus, X402Resource, X402ResourceStatus, X402ResourceStatusResponse, atomicToMoneyUnits, createSecureMessageRequestSchema, isX402PaymentRequired, isX402ResourceStatus, moneyUnitsToAtomic, roundHalfToPositiveInfinity, secureMessageMetadataSchema, secureMessageSchema, validatePositiveAmountAtomic } from 'spaps-types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Permission checking utilities for SPAPS SDK
|
|
@@ -336,6 +336,73 @@ interface EmailTemplatePreview {
|
|
|
336
336
|
html: string;
|
|
337
337
|
text?: string;
|
|
338
338
|
}
|
|
339
|
+
type MarketingEventType = 'attribution_touch' | 'experiment_exposure';
|
|
340
|
+
type MarketingExperimentRecommendation = 'continue' | 'continue_srm_warning' | 'stop_for_winner';
|
|
341
|
+
type MarketingExperimentSrmStatus = 'pass' | 'warning' | 'not_applicable';
|
|
342
|
+
interface MarketingEventIngestRequest {
|
|
343
|
+
application_id?: string;
|
|
344
|
+
anon_id: string;
|
|
345
|
+
event_type: MarketingEventType;
|
|
346
|
+
experiment_id?: string | null;
|
|
347
|
+
variant_id?: string | null;
|
|
348
|
+
variant?: string | null;
|
|
349
|
+
metadata?: Record<string, unknown> | null;
|
|
350
|
+
dedupe_key?: string | null;
|
|
351
|
+
timestamp?: string | null;
|
|
352
|
+
observed_at?: string | null;
|
|
353
|
+
}
|
|
354
|
+
interface MarketingEventIngestResponse {
|
|
355
|
+
id: string;
|
|
356
|
+
application_id: string;
|
|
357
|
+
anon_id: string;
|
|
358
|
+
event_type: MarketingEventType;
|
|
359
|
+
experiment_id?: string | null;
|
|
360
|
+
variant?: string | null;
|
|
361
|
+
dedupe_key: string;
|
|
362
|
+
ts: string;
|
|
363
|
+
created_at: string;
|
|
364
|
+
}
|
|
365
|
+
interface MarketingExperimentVariantResult {
|
|
366
|
+
variant_id: string | null;
|
|
367
|
+
exposures: number;
|
|
368
|
+
conversions: number;
|
|
369
|
+
conversion_rate: number;
|
|
370
|
+
revenue: Record<string, number>;
|
|
371
|
+
}
|
|
372
|
+
interface MarketingExperimentMinSampleDecision {
|
|
373
|
+
met: boolean;
|
|
374
|
+
min_exposures_per_variant: number;
|
|
375
|
+
min_total_conversions: number;
|
|
376
|
+
observed_min_exposures: number;
|
|
377
|
+
observed_total_conversions: number;
|
|
378
|
+
}
|
|
379
|
+
interface MarketingExperimentSrmDecision {
|
|
380
|
+
status: MarketingExperimentSrmStatus;
|
|
381
|
+
expected_share?: number | null;
|
|
382
|
+
max_share_ratio?: number | null;
|
|
383
|
+
min_share_ratio?: number | null;
|
|
384
|
+
}
|
|
385
|
+
interface MarketingExperimentEffectDecision {
|
|
386
|
+
leader_variant_id?: string | null;
|
|
387
|
+
runner_up_variant_id?: string | null;
|
|
388
|
+
absolute_lift?: number | null;
|
|
389
|
+
relative_lift?: number | null;
|
|
390
|
+
}
|
|
391
|
+
interface MarketingExperimentDecision {
|
|
392
|
+
decisive: boolean;
|
|
393
|
+
recommendation: MarketingExperimentRecommendation;
|
|
394
|
+
winner_variant_id?: string | null;
|
|
395
|
+
reason_codes: string[];
|
|
396
|
+
min_sample: MarketingExperimentMinSampleDecision;
|
|
397
|
+
srm: MarketingExperimentSrmDecision;
|
|
398
|
+
effect: MarketingExperimentEffectDecision;
|
|
399
|
+
}
|
|
400
|
+
interface MarketingExperimentResultsResponse {
|
|
401
|
+
application_id: string;
|
|
402
|
+
experiment_id: string;
|
|
403
|
+
variants: MarketingExperimentVariantResult[];
|
|
404
|
+
decision: MarketingExperimentDecision;
|
|
405
|
+
}
|
|
339
406
|
interface EntitlementListParams {
|
|
340
407
|
/** Filter by entitlement key */
|
|
341
408
|
key?: string;
|
|
@@ -360,6 +427,9 @@ interface IssueReportListParams {
|
|
|
360
427
|
interface IssueReportStatusParams {
|
|
361
428
|
scope?: SupportedIssueReportScope;
|
|
362
429
|
}
|
|
430
|
+
interface IssueReportAttachmentUploadOptions {
|
|
431
|
+
filename?: string;
|
|
432
|
+
}
|
|
363
433
|
declare class X402PaymentRequiredSDKError extends Error {
|
|
364
434
|
readonly paymentRequiredHeader: string;
|
|
365
435
|
readonly response: unknown;
|
|
@@ -705,7 +775,7 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
705
775
|
* Note: For publishable key contexts, only `resource_type=user` is permitted.
|
|
706
776
|
* Non-user resource types will return a 403 error (enforced server-side).
|
|
707
777
|
*
|
|
708
|
-
* @param resourceType - The resource type (e.g. "user", "company", "org", "system").
|
|
778
|
+
* @param resourceType - The resource type (e.g. "user", "company", "org", "system", "project").
|
|
709
779
|
* @param resourceId - Optional specific resource ID.
|
|
710
780
|
*/
|
|
711
781
|
listByResource: (resourceType: ResourceType, resourceId?: string) => Promise<Entitlement[]>;
|
|
@@ -730,6 +800,28 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
730
800
|
* Create a new canonical issue report.
|
|
731
801
|
*/
|
|
732
802
|
create: (payload: CreateIssueReportRequest) => Promise<IssueReport>;
|
|
803
|
+
/**
|
|
804
|
+
* Upload one private pending screenshot attachment.
|
|
805
|
+
*/
|
|
806
|
+
uploadAttachment: (file: Blob, options?: IssueReportAttachmentUploadOptions) => Promise<IssueReportAttachmentOut>;
|
|
807
|
+
/**
|
|
808
|
+
* List non-deleted screenshot attachments for one issue report.
|
|
809
|
+
*/
|
|
810
|
+
listAttachments: (issueReportId: string) => Promise<ListIssueReportAttachmentsResponse>;
|
|
811
|
+
/**
|
|
812
|
+
* Return a short-lived private attachment access URL.
|
|
813
|
+
*/
|
|
814
|
+
getAttachmentAccess: (attachmentId: string) => Promise<IssueReportAttachmentAccessResponse>;
|
|
815
|
+
/**
|
|
816
|
+
* Return a short-lived private attachment access URL.
|
|
817
|
+
*
|
|
818
|
+
* @deprecated Use getAttachmentAccess(attachmentId).
|
|
819
|
+
*/
|
|
820
|
+
getAttachmentAccessUrl: (attachmentId: string) => Promise<IssueReportAttachmentAccessResponse>;
|
|
821
|
+
/**
|
|
822
|
+
* Soft-delete one owned screenshot attachment.
|
|
823
|
+
*/
|
|
824
|
+
deleteAttachment: (attachmentId: string) => Promise<void>;
|
|
733
825
|
/**
|
|
734
826
|
* Create a short-lived voice transcription token for issue reporting.
|
|
735
827
|
*/
|
|
@@ -742,6 +834,46 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
742
834
|
* Reply to a resolved or ignored issue report and reopen the linked case.
|
|
743
835
|
*/
|
|
744
836
|
reply: (issueReportId: string, payload: ReplyIssueReportRequest) => Promise<IssueReport>;
|
|
837
|
+
/**
|
|
838
|
+
* List the chronological, reporter-visible message thread for one owned
|
|
839
|
+
* issue report. Only active, reporter-visible rows are returned; retracted
|
|
840
|
+
* or superseded operator messages are excluded and raw audit payloads are
|
|
841
|
+
* never exposed. `needs_response` badges an open clarification request.
|
|
842
|
+
*/
|
|
843
|
+
listMessages: (issueReportId: string) => Promise<ListIssueReportMessagesResponse>;
|
|
844
|
+
/**
|
|
845
|
+
* Submit a reporter clarification response on one owned issue report. This
|
|
846
|
+
* does NOT reopen a closed case (use `reply` for that). Idempotent on
|
|
847
|
+
* `idempotency_key`: same key + same body returns the existing message,
|
|
848
|
+
* same key + different body returns 409 ISSUE_REPORT_MESSAGE_CONFLICT.
|
|
849
|
+
*/
|
|
850
|
+
submitMessage: (issueReportId: string, payload: CreateReporterMessageRequest) => Promise<IssueReportMessage>;
|
|
851
|
+
/**
|
|
852
|
+
* Triage-operator message commands. These require a secret key context and a
|
|
853
|
+
* triage role/capability; publishable browser contexts are rejected by the
|
|
854
|
+
* server. Provide the secret key as the SDK's API key.
|
|
855
|
+
*/
|
|
856
|
+
triage: {
|
|
857
|
+
/**
|
|
858
|
+
* List all projection rows for an app-scoped report (including corrected
|
|
859
|
+
* rows) for authorized triage operators.
|
|
860
|
+
*/
|
|
861
|
+
listMessages: (issueReportId: string) => Promise<ListIssueReportMessagesResponse>;
|
|
862
|
+
/**
|
|
863
|
+
* Post a clarification_request or final_response reporter-visible message
|
|
864
|
+
* as a triage operator. Idempotent on `idempotency_key`; a key reused with
|
|
865
|
+
* a different body returns 409. A final_response can drive a terminal
|
|
866
|
+
* lifecycle transition via `resolve_case`; the internal resolution_note is
|
|
867
|
+
* never auto-displayed to reporters.
|
|
868
|
+
*/
|
|
869
|
+
postMessage: (issueReportId: string, payload: CreateOperatorMessageRequest) => Promise<IssueReportMessage>;
|
|
870
|
+
/**
|
|
871
|
+
* Retract an operator-authored message. The body is retained; the row's
|
|
872
|
+
* state is marked `retracted`. Retracting an already-retracted message is
|
|
873
|
+
* a safe no-op.
|
|
874
|
+
*/
|
|
875
|
+
retractMessage: (issueReportId: string, messageId: string, payload?: RetractOperatorMessageRequest) => Promise<IssueReportMessage>;
|
|
876
|
+
};
|
|
745
877
|
};
|
|
746
878
|
/**
|
|
747
879
|
* Application-scoped short links for browser apps that need stable public URLs.
|
|
@@ -751,6 +883,10 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
751
883
|
* Create a short link owned by the authenticated user.
|
|
752
884
|
*/
|
|
753
885
|
create: (payload: CreateAppLinkRequest) => Promise<AppLink>;
|
|
886
|
+
/**
|
|
887
|
+
* Update a short link owned by the authenticated user.
|
|
888
|
+
*/
|
|
889
|
+
update: (username: string, slug: string, payload: UpdateAppLinkRequest) => Promise<AppLink>;
|
|
754
890
|
/**
|
|
755
891
|
* Resolve a public short link for the active application.
|
|
756
892
|
*/
|
|
@@ -758,6 +894,30 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
758
894
|
track?: boolean;
|
|
759
895
|
}) => Promise<AppLink>;
|
|
760
896
|
};
|
|
897
|
+
/**
|
|
898
|
+
* Marketing events and experiment results.
|
|
899
|
+
*
|
|
900
|
+
* Use a publishable key for browser-side event emission. Use a secret key
|
|
901
|
+
* from a trusted server or agent process when reading experiment results.
|
|
902
|
+
*/
|
|
903
|
+
marketing: {
|
|
904
|
+
/**
|
|
905
|
+
* Emit one anonymous attribution touch or experiment exposure.
|
|
906
|
+
*/
|
|
907
|
+
emit: (payload: MarketingEventIngestRequest) => Promise<MarketingEventIngestResponse>;
|
|
908
|
+
/**
|
|
909
|
+
* Alias for emit(), matching the backend ingest endpoint language.
|
|
910
|
+
*/
|
|
911
|
+
ingest: (payload: MarketingEventIngestRequest) => Promise<MarketingEventIngestResponse>;
|
|
912
|
+
/**
|
|
913
|
+
* Read per-variant experiment results and the conservative stop signal.
|
|
914
|
+
*/
|
|
915
|
+
getExperimentResults: (experimentId: string) => Promise<MarketingExperimentResultsResponse>;
|
|
916
|
+
/**
|
|
917
|
+
* Short alias for getExperimentResults().
|
|
918
|
+
*/
|
|
919
|
+
getResults: (experimentId: string) => Promise<MarketingExperimentResultsResponse>;
|
|
920
|
+
};
|
|
761
921
|
private static envVar;
|
|
762
922
|
constructor(config?: SPAPSConfig);
|
|
763
923
|
/** Raw API request helper that returns an ApiResponse-like shape */
|
|
@@ -963,7 +1123,7 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
963
1123
|
updateProductSuperAdmin: (productId: string, updates: any) => Promise<any>;
|
|
964
1124
|
deleteProductSuperAdmin: (productId: string) => Promise<any>;
|
|
965
1125
|
createProductWithPrice: (payload: any) => Promise<any>;
|
|
966
|
-
createProductWithPriceSuperAdmin: (
|
|
1126
|
+
createProductWithPriceSuperAdmin: (applicationId: string, payload: any) => Promise<any>;
|
|
967
1127
|
setDefaultPrice: (productId: string, payload: {
|
|
968
1128
|
price_id: string;
|
|
969
1129
|
}) => Promise<any>;
|
|
@@ -1099,6 +1259,14 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
1099
1259
|
* after work completes.
|
|
1100
1260
|
*/
|
|
1101
1261
|
usage: {
|
|
1262
|
+
/**
|
|
1263
|
+
* List active usage feature definitions for this application.
|
|
1264
|
+
*/
|
|
1265
|
+
listFeatures: () => Promise<UsageControlFeaturesResponse>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Fetch current window usage status without creating an authorization.
|
|
1268
|
+
*/
|
|
1269
|
+
getStatus: (query: UsageControlStatusRequest) => Promise<UsageControlStatusResponse>;
|
|
1102
1270
|
/**
|
|
1103
1271
|
* Authorize proposed usage before a downstream job, inference, or action runs.
|
|
1104
1272
|
*/
|
|
@@ -1107,16 +1275,28 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
1107
1275
|
* Record immutable usage after work completes.
|
|
1108
1276
|
*/
|
|
1109
1277
|
record: (payload: UsageControlRecordRequest) => Promise<UsageControlRecordResponse>;
|
|
1278
|
+
/**
|
|
1279
|
+
* List usage events in deterministic newest-first order.
|
|
1280
|
+
*/
|
|
1281
|
+
listHistory: (query?: UsageControlHistoryRequest) => Promise<UsageControlHistoryResponse>;
|
|
1110
1282
|
};
|
|
1111
1283
|
createCheckoutSession(priceId: string, successUrl: string, cancelUrl?: string): Promise<{
|
|
1112
1284
|
data: CheckoutSession;
|
|
1113
1285
|
}>;
|
|
1114
|
-
getSubscription(): Promise<{
|
|
1286
|
+
getSubscription(subscriptionId?: string): Promise<{
|
|
1287
|
+
data: Subscription | Subscription[];
|
|
1288
|
+
}>;
|
|
1289
|
+
cancelSubscription(subscriptionId?: string, options?: {
|
|
1290
|
+
immediately?: boolean;
|
|
1291
|
+
}): Promise<{
|
|
1115
1292
|
data: Subscription;
|
|
1116
1293
|
}>;
|
|
1117
|
-
cancelSubscription(): Promise<void>;
|
|
1118
1294
|
authorizeUsage(payload: UsageControlAuthorizeRequest): Promise<UsageControlAuthorizeResponse>;
|
|
1119
1295
|
recordUsage(payload: UsageControlRecordRequest): Promise<UsageControlRecordResponse>;
|
|
1296
|
+
getUsageStatus(query: UsageControlStatusRequest): Promise<UsageControlStatusResponse>;
|
|
1297
|
+
listUsageHistory(query?: UsageControlHistoryRequest): Promise<UsageControlHistoryResponse>;
|
|
1298
|
+
emitMarketingEvent(payload: MarketingEventIngestRequest): Promise<MarketingEventIngestResponse>;
|
|
1299
|
+
getMarketingExperimentResults(experimentId: string): Promise<MarketingExperimentResultsResponse>;
|
|
1120
1300
|
private createSecureMessage;
|
|
1121
1301
|
private listSecureMessages;
|
|
1122
1302
|
/**
|
|
@@ -1298,4 +1478,4 @@ declare function createServerClient(secretKey: string, options?: Omit<SPAPSConfi
|
|
|
1298
1478
|
*/
|
|
1299
1479
|
declare function detectKeyType(key: string): ApiKeyType | null;
|
|
1300
1480
|
|
|
1301
|
-
export { type AdminConfig, type ApiKeyType, type CheckoutLineItem, type CheckoutLineItemPriceData, type CreateCheckoutSessionPayload, type CreateSkillEvalCaseRequest, type CreateSkillEvalGovernanceSnapshotRequest, DEFAULT_ADMIN_ACCOUNTS, type EmailSendOptions, type EmailSendResult, type EmailTemplate, type EmailTemplatePreview, type EntitlementCheckResult, type EntitlementListParams, type FeatureContext, type FeatureDefinition, FeatureEvaluator, type HeaderProvider, type ImportSkillEvalGovernanceOutcomeRequest, type IssueReportListParams, type IssueReportStatusParams, type PermissionCheckResult, PermissionChecker, type RespondToSkillEvalReviewRequest, type RevealSkillEvalEvidenceRequest, RoleHierarchy, SPAPSClient as SPAPS, SPAPSClient, type SPAPSConfig, type SPAPSEnvelope, type SkillEvalAccessMode, type SkillEvalActorAccess, type SkillEvalCandidateInput, type SkillEvalCandidateResponse, type SkillEvalCasePolicy, type SkillEvalCaseResponse, type SkillEvalConfidence, type SkillEvalCreateOptions, type SkillEvalDisclosurePolicy, type SkillEvalEligibilitySource, type SkillEvalGovernanceOutcomeResult, type SkillEvalGovernancePurpose, type SkillEvalGovernanceSnapshotResult, type SkillEvalInsight, type SkillEvalInsightsResponse, type SkillEvalModelEffort, type SkillEvalMutationOptions, type SkillEvalPosterResponse, type SkillEvalPosterResponseResult, type SkillEvalRevealField, type SkillEvalRevealResult, type SkillEvalReviewMarkInput, type SkillEvalReviewMarkKind, type SkillEvalReviewResponse, type SkillEvalReviewRoom, type SkillEvalReviewerEligibilityInput, type SkillEvalRewardEvent, type SubmitSkillEvalReviewRequest, type TemplateVariable, TokenManager, WalletUtils, WebSocketAuthHelper, type WebSocketAuthHelperConfig, type X402ExecuteActionOptions, X402PaymentRequiredSDKError, type X402ReceiptListParams, type X402VerifyHandoffOptions, canAccessAdmin, createBrowserClient, createPermissionChecker, createServerClient, SPAPSClient as default, defaultPermissionChecker, detectKeyType, getRoleAwareErrorMessage, getUserDisplay, getUserRole, hasPermission, isAdminAccount, isEnvelope, isErrorEnvelope, isSuccessEnvelope, unwrapEnvelope, unwrapNestedData, verifyCryptoWebhookSignature };
|
|
1481
|
+
export { type AdminConfig, type ApiKeyType, type CheckoutLineItem, type CheckoutLineItemPriceData, type CreateCheckoutSessionPayload, type CreateSkillEvalCaseRequest, type CreateSkillEvalGovernanceSnapshotRequest, DEFAULT_ADMIN_ACCOUNTS, type EmailSendOptions, type EmailSendResult, type EmailTemplate, type EmailTemplatePreview, type EntitlementCheckResult, type EntitlementListParams, type FeatureContext, type FeatureDefinition, FeatureEvaluator, type HeaderProvider, type ImportSkillEvalGovernanceOutcomeRequest, type IssueReportAttachmentUploadOptions, type IssueReportListParams, type IssueReportStatusParams, type MarketingEventIngestRequest, type MarketingEventIngestResponse, type MarketingEventType, type MarketingExperimentDecision, type MarketingExperimentEffectDecision, type MarketingExperimentMinSampleDecision, type MarketingExperimentRecommendation, type MarketingExperimentResultsResponse, type MarketingExperimentSrmDecision, type MarketingExperimentSrmStatus, type MarketingExperimentVariantResult, type PermissionCheckResult, PermissionChecker, type RespondToSkillEvalReviewRequest, type RevealSkillEvalEvidenceRequest, RoleHierarchy, SPAPSClient as SPAPS, SPAPSClient, type SPAPSConfig, type SPAPSEnvelope, type SkillEvalAccessMode, type SkillEvalActorAccess, type SkillEvalCandidateInput, type SkillEvalCandidateResponse, type SkillEvalCasePolicy, type SkillEvalCaseResponse, type SkillEvalConfidence, type SkillEvalCreateOptions, type SkillEvalDisclosurePolicy, type SkillEvalEligibilitySource, type SkillEvalGovernanceOutcomeResult, type SkillEvalGovernancePurpose, type SkillEvalGovernanceSnapshotResult, type SkillEvalInsight, type SkillEvalInsightsResponse, type SkillEvalModelEffort, type SkillEvalMutationOptions, type SkillEvalPosterResponse, type SkillEvalPosterResponseResult, type SkillEvalRevealField, type SkillEvalRevealResult, type SkillEvalReviewMarkInput, type SkillEvalReviewMarkKind, type SkillEvalReviewResponse, type SkillEvalReviewRoom, type SkillEvalReviewerEligibilityInput, type SkillEvalRewardEvent, type SubmitSkillEvalReviewRequest, type TemplateVariable, TokenManager, WalletUtils, WebSocketAuthHelper, type WebSocketAuthHelperConfig, type X402ExecuteActionOptions, X402PaymentRequiredSDKError, type X402ReceiptListParams, type X402VerifyHandoffOptions, canAccessAdmin, createBrowserClient, createPermissionChecker, createServerClient, SPAPSClient as default, defaultPermissionChecker, detectKeyType, getRoleAwareErrorMessage, getUserDisplay, getUserRole, hasPermission, isAdminAccount, isEnvelope, isErrorEnvelope, isSuccessEnvelope, unwrapEnvelope, unwrapNestedData, verifyCryptoWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -672,7 +672,7 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
672
672
|
* @param userId - Optional user ID override (secret key contexts only).
|
|
673
673
|
*/
|
|
674
674
|
check: async (key, userId) => {
|
|
675
|
-
const q = new URLSearchParams({ key });
|
|
675
|
+
const q = new URLSearchParams({ entitlement_key: key });
|
|
676
676
|
if (userId) q.append("user_id", userId);
|
|
677
677
|
const res = await this.client.get(
|
|
678
678
|
`/api/entitlements/check?${q.toString()}`,
|
|
@@ -686,7 +686,7 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
686
686
|
* Note: For publishable key contexts, only `resource_type=user` is permitted.
|
|
687
687
|
* Non-user resource types will return a 403 error (enforced server-side).
|
|
688
688
|
*
|
|
689
|
-
* @param resourceType - The resource type (e.g. "user", "company", "org", "system").
|
|
689
|
+
* @param resourceType - The resource type (e.g. "user", "company", "org", "system", "project").
|
|
690
690
|
* @param resourceId - Optional specific resource ID.
|
|
691
691
|
*/
|
|
692
692
|
listByResource: async (resourceType, resourceId) => {
|
|
@@ -757,6 +757,69 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
757
757
|
);
|
|
758
758
|
return this.unwrapApiResponse(res, "Failed to create issue report");
|
|
759
759
|
},
|
|
760
|
+
/**
|
|
761
|
+
* Upload one private pending screenshot attachment.
|
|
762
|
+
*/
|
|
763
|
+
uploadAttachment: async (file, options) => {
|
|
764
|
+
if (typeof FormData === "undefined") {
|
|
765
|
+
throw new Error("FormData is required to upload issue report attachments");
|
|
766
|
+
}
|
|
767
|
+
const formData = new FormData();
|
|
768
|
+
const fileWithOptionalName = file;
|
|
769
|
+
const inferredFilename = typeof fileWithOptionalName.name === "string" ? fileWithOptionalName.name : void 0;
|
|
770
|
+
const filename = options?.filename ?? inferredFilename;
|
|
771
|
+
if (filename) {
|
|
772
|
+
formData.append("file", file, filename);
|
|
773
|
+
} else {
|
|
774
|
+
formData.append("file", file);
|
|
775
|
+
}
|
|
776
|
+
const res = await this.client.post(
|
|
777
|
+
"/api/v1/issue-reports/attachments",
|
|
778
|
+
formData,
|
|
779
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
780
|
+
);
|
|
781
|
+
return this.unwrapApiResponse(res, "Failed to upload issue report attachment");
|
|
782
|
+
},
|
|
783
|
+
/**
|
|
784
|
+
* List non-deleted screenshot attachments for one issue report.
|
|
785
|
+
*/
|
|
786
|
+
listAttachments: async (issueReportId) => {
|
|
787
|
+
const res = await this.client.get(
|
|
788
|
+
`/api/v1/issue-reports/${encodeURIComponent(issueReportId)}/attachments`,
|
|
789
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
790
|
+
);
|
|
791
|
+
return this.unwrapApiResponse(res, "Failed to list issue report attachments");
|
|
792
|
+
},
|
|
793
|
+
/**
|
|
794
|
+
* Return a short-lived private attachment access URL.
|
|
795
|
+
*/
|
|
796
|
+
getAttachmentAccess: async (attachmentId) => {
|
|
797
|
+
const res = await this.client.get(
|
|
798
|
+
`/api/v1/issue-reports/attachments/${encodeURIComponent(attachmentId)}/access`,
|
|
799
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
800
|
+
);
|
|
801
|
+
return this.unwrapApiResponse(
|
|
802
|
+
res,
|
|
803
|
+
"Failed to get issue report attachment access URL"
|
|
804
|
+
);
|
|
805
|
+
},
|
|
806
|
+
/**
|
|
807
|
+
* Return a short-lived private attachment access URL.
|
|
808
|
+
*
|
|
809
|
+
* @deprecated Use getAttachmentAccess(attachmentId).
|
|
810
|
+
*/
|
|
811
|
+
getAttachmentAccessUrl: async (attachmentId) => {
|
|
812
|
+
return this.issueReporting.getAttachmentAccess(attachmentId);
|
|
813
|
+
},
|
|
814
|
+
/**
|
|
815
|
+
* Soft-delete one owned screenshot attachment.
|
|
816
|
+
*/
|
|
817
|
+
deleteAttachment: async (attachmentId) => {
|
|
818
|
+
await this.client.delete(
|
|
819
|
+
`/api/v1/issue-reports/attachments/${encodeURIComponent(attachmentId)}`,
|
|
820
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
821
|
+
);
|
|
822
|
+
},
|
|
760
823
|
/**
|
|
761
824
|
* Create a short-lived voice transcription token for issue reporting.
|
|
762
825
|
*/
|
|
@@ -789,6 +852,82 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
789
852
|
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
790
853
|
);
|
|
791
854
|
return this.unwrapApiResponse(res, "Failed to reply to issue report");
|
|
855
|
+
},
|
|
856
|
+
/**
|
|
857
|
+
* List the chronological, reporter-visible message thread for one owned
|
|
858
|
+
* issue report. Only active, reporter-visible rows are returned; retracted
|
|
859
|
+
* or superseded operator messages are excluded and raw audit payloads are
|
|
860
|
+
* never exposed. `needs_response` badges an open clarification request.
|
|
861
|
+
*/
|
|
862
|
+
listMessages: async (issueReportId) => {
|
|
863
|
+
const res = await this.client.get(
|
|
864
|
+
`/api/v1/issue-reports/${issueReportId}/messages`,
|
|
865
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
866
|
+
);
|
|
867
|
+
return this.unwrapApiResponse(res, "Failed to list issue report messages");
|
|
868
|
+
},
|
|
869
|
+
/**
|
|
870
|
+
* Submit a reporter clarification response on one owned issue report. This
|
|
871
|
+
* does NOT reopen a closed case (use `reply` for that). Idempotent on
|
|
872
|
+
* `idempotency_key`: same key + same body returns the existing message,
|
|
873
|
+
* same key + different body returns 409 ISSUE_REPORT_MESSAGE_CONFLICT.
|
|
874
|
+
*/
|
|
875
|
+
submitMessage: async (issueReportId, payload) => {
|
|
876
|
+
const res = await this.client.post(
|
|
877
|
+
`/api/v1/issue-reports/${issueReportId}/messages`,
|
|
878
|
+
payload,
|
|
879
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
880
|
+
);
|
|
881
|
+
return this.unwrapApiResponse(res, "Failed to submit issue report message");
|
|
882
|
+
},
|
|
883
|
+
/**
|
|
884
|
+
* Triage-operator message commands. These require a secret key context and a
|
|
885
|
+
* triage role/capability; publishable browser contexts are rejected by the
|
|
886
|
+
* server. Provide the secret key as the SDK's API key.
|
|
887
|
+
*/
|
|
888
|
+
triage: {
|
|
889
|
+
/**
|
|
890
|
+
* List all projection rows for an app-scoped report (including corrected
|
|
891
|
+
* rows) for authorized triage operators.
|
|
892
|
+
*/
|
|
893
|
+
listMessages: async (issueReportId) => {
|
|
894
|
+
const res = await this.client.get(
|
|
895
|
+
`/api/v1/issue-reports/triage/${issueReportId}/messages`,
|
|
896
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
897
|
+
);
|
|
898
|
+
return this.unwrapApiResponse(
|
|
899
|
+
res,
|
|
900
|
+
"Failed to list triage issue report messages"
|
|
901
|
+
);
|
|
902
|
+
},
|
|
903
|
+
/**
|
|
904
|
+
* Post a clarification_request or final_response reporter-visible message
|
|
905
|
+
* as a triage operator. Idempotent on `idempotency_key`; a key reused with
|
|
906
|
+
* a different body returns 409. A final_response can drive a terminal
|
|
907
|
+
* lifecycle transition via `resolve_case`; the internal resolution_note is
|
|
908
|
+
* never auto-displayed to reporters.
|
|
909
|
+
*/
|
|
910
|
+
postMessage: async (issueReportId, payload) => {
|
|
911
|
+
const res = await this.client.post(
|
|
912
|
+
`/api/v1/issue-reports/triage/${issueReportId}/messages`,
|
|
913
|
+
payload,
|
|
914
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
915
|
+
);
|
|
916
|
+
return this.unwrapApiResponse(res, "Failed to post triage issue report message");
|
|
917
|
+
},
|
|
918
|
+
/**
|
|
919
|
+
* Retract an operator-authored message. The body is retained; the row's
|
|
920
|
+
* state is marked `retracted`. Retracting an already-retracted message is
|
|
921
|
+
* a safe no-op.
|
|
922
|
+
*/
|
|
923
|
+
retractMessage: async (issueReportId, messageId, payload = {}) => {
|
|
924
|
+
const res = await this.client.post(
|
|
925
|
+
`/api/v1/issue-reports/triage/${issueReportId}/messages/${messageId}/retract`,
|
|
926
|
+
payload,
|
|
927
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
928
|
+
);
|
|
929
|
+
return this.unwrapApiResponse(res, "Failed to retract triage issue report message");
|
|
930
|
+
}
|
|
792
931
|
}
|
|
793
932
|
};
|
|
794
933
|
/**
|
|
@@ -806,6 +945,17 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
806
945
|
);
|
|
807
946
|
return this.unwrapApiResponse(res, "Failed to create app link");
|
|
808
947
|
},
|
|
948
|
+
/**
|
|
949
|
+
* Update a short link owned by the authenticated user.
|
|
950
|
+
*/
|
|
951
|
+
update: async (username, slug, payload) => {
|
|
952
|
+
const res = await this.client.patch(
|
|
953
|
+
`/api/v1/app-links/${encodeURIComponent(username)}/${encodeURIComponent(slug)}`,
|
|
954
|
+
payload,
|
|
955
|
+
this.accessToken ? { headers: { Authorization: `Bearer ${this.accessToken}` } } : void 0
|
|
956
|
+
);
|
|
957
|
+
return this.unwrapApiResponse(res, "Failed to update app link");
|
|
958
|
+
},
|
|
809
959
|
/**
|
|
810
960
|
* Resolve a public short link for the active application.
|
|
811
961
|
*/
|
|
@@ -820,6 +970,58 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
820
970
|
return this.unwrapApiResponse(res, "Failed to get app link");
|
|
821
971
|
}
|
|
822
972
|
};
|
|
973
|
+
/**
|
|
974
|
+
* Marketing events and experiment results.
|
|
975
|
+
*
|
|
976
|
+
* Use a publishable key for browser-side event emission. Use a secret key
|
|
977
|
+
* from a trusted server or agent process when reading experiment results.
|
|
978
|
+
*/
|
|
979
|
+
marketing = {
|
|
980
|
+
/**
|
|
981
|
+
* Emit one anonymous attribution touch or experiment exposure.
|
|
982
|
+
*/
|
|
983
|
+
emit: async (payload) => {
|
|
984
|
+
if (payload.event_type === "experiment_exposure") {
|
|
985
|
+
if (!payload.experiment_id?.trim()) {
|
|
986
|
+
throw new Error("experiment_id is required for experiment_exposure events");
|
|
987
|
+
}
|
|
988
|
+
const variant = payload.variant_id ?? payload.variant;
|
|
989
|
+
if (!variant?.trim()) {
|
|
990
|
+
throw new Error("variant_id or variant is required for experiment_exposure events");
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
const res = await this.client.post("/api/marketing-events/ingest", payload);
|
|
994
|
+
return this.unwrapApiResponse(
|
|
995
|
+
res,
|
|
996
|
+
"Failed to emit marketing event"
|
|
997
|
+
);
|
|
998
|
+
},
|
|
999
|
+
/**
|
|
1000
|
+
* Alias for emit(), matching the backend ingest endpoint language.
|
|
1001
|
+
*/
|
|
1002
|
+
ingest: async (payload) => {
|
|
1003
|
+
return this.marketing.emit(payload);
|
|
1004
|
+
},
|
|
1005
|
+
/**
|
|
1006
|
+
* Read per-variant experiment results and the conservative stop signal.
|
|
1007
|
+
*/
|
|
1008
|
+
getExperimentResults: async (experimentId) => {
|
|
1009
|
+
const encodedExperimentId = encodeURIComponent(experimentId);
|
|
1010
|
+
const res = await this.client.get(
|
|
1011
|
+
`/api/marketing/experiments/${encodedExperimentId}/results`
|
|
1012
|
+
);
|
|
1013
|
+
return this.unwrapApiResponse(
|
|
1014
|
+
res,
|
|
1015
|
+
"Failed to get marketing experiment results"
|
|
1016
|
+
);
|
|
1017
|
+
},
|
|
1018
|
+
/**
|
|
1019
|
+
* Short alias for getExperimentResults().
|
|
1020
|
+
*/
|
|
1021
|
+
getResults: async (experimentId) => {
|
|
1022
|
+
return this.marketing.getExperimentResults(experimentId);
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
823
1025
|
static envVar(name) {
|
|
824
1026
|
if (typeof process !== "undefined" && process.env) {
|
|
825
1027
|
return process.env[name];
|
|
@@ -1295,9 +1497,9 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
1295
1497
|
const res = await this.client.post("/api/stripe/products/with-price", payload, { headers: { Authorization: `Bearer ${this.accessToken}` } });
|
|
1296
1498
|
return this.unwrapApiResponse(res, "Failed to create product with price");
|
|
1297
1499
|
},
|
|
1298
|
-
createProductWithPriceSuperAdmin: async (
|
|
1500
|
+
createProductWithPriceSuperAdmin: async (applicationId, payload) => {
|
|
1299
1501
|
if (!this.accessToken) throw new Error("Authentication required. Please authenticate first.");
|
|
1300
|
-
const res = await this.client.post(`/api/stripe/products/super-admin/${
|
|
1502
|
+
const res = await this.client.post(`/api/stripe/products/super-admin/${applicationId}/with-price`, payload, { headers: { Authorization: `Bearer ${this.accessToken}` } });
|
|
1301
1503
|
return this.unwrapApiResponse(res, "Failed to create product with price (super admin)");
|
|
1302
1504
|
},
|
|
1303
1505
|
setDefaultPrice: async (productId, payload) => {
|
|
@@ -1625,6 +1827,25 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
1625
1827
|
* after work completes.
|
|
1626
1828
|
*/
|
|
1627
1829
|
usage = {
|
|
1830
|
+
/**
|
|
1831
|
+
* List active usage feature definitions for this application.
|
|
1832
|
+
*/
|
|
1833
|
+
listFeatures: async () => {
|
|
1834
|
+
const res = await this.client.get("/api/usage/features");
|
|
1835
|
+
return this.unwrapApiResponse(res, "Failed to list usage features");
|
|
1836
|
+
},
|
|
1837
|
+
/**
|
|
1838
|
+
* Fetch current window usage status without creating an authorization.
|
|
1839
|
+
*/
|
|
1840
|
+
getStatus: async (query) => {
|
|
1841
|
+
const q = new URLSearchParams();
|
|
1842
|
+
q.set("feature_key", query.feature_key);
|
|
1843
|
+
q.set("resource_type", query.resource_type);
|
|
1844
|
+
if (query.resource_id) q.set("resource_id", query.resource_id);
|
|
1845
|
+
if (query.subject_user_id) q.set("subject_user_id", query.subject_user_id);
|
|
1846
|
+
const res = await this.client.get(`/api/usage/status?${q.toString()}`);
|
|
1847
|
+
return this.unwrapApiResponse(res, "Failed to get usage status");
|
|
1848
|
+
},
|
|
1628
1849
|
/**
|
|
1629
1850
|
* Authorize proposed usage before a downstream job, inference, or action runs.
|
|
1630
1851
|
*/
|
|
@@ -1638,21 +1859,43 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
1638
1859
|
record: async (payload) => {
|
|
1639
1860
|
const res = await this.client.post("/api/usage/record", payload);
|
|
1640
1861
|
return this.unwrapApiResponse(res, "Failed to record usage");
|
|
1862
|
+
},
|
|
1863
|
+
/**
|
|
1864
|
+
* List usage events in deterministic newest-first order.
|
|
1865
|
+
*/
|
|
1866
|
+
listHistory: async (query = {}) => {
|
|
1867
|
+
const q = new URLSearchParams();
|
|
1868
|
+
if (query.feature_key) q.set("feature_key", query.feature_key);
|
|
1869
|
+
if (query.resource_type) q.set("resource_type", query.resource_type);
|
|
1870
|
+
if (query.resource_id) q.set("resource_id", query.resource_id);
|
|
1871
|
+
if (query.subject_user_id) q.set("subject_user_id", query.subject_user_id);
|
|
1872
|
+
if (query.limit) q.set("limit", String(query.limit));
|
|
1873
|
+
if (typeof query.offset === "number") q.set("offset", String(query.offset));
|
|
1874
|
+
const suffix = q.toString() ? `?${q.toString()}` : "";
|
|
1875
|
+
const res = await this.client.get(`/api/usage/history${suffix}`);
|
|
1876
|
+
return this.unwrapApiResponse(res, "Failed to list usage history");
|
|
1641
1877
|
}
|
|
1642
1878
|
};
|
|
1643
1879
|
// Stripe Methods
|
|
1644
1880
|
async createCheckoutSession(priceId, successUrl, cancelUrl) {
|
|
1645
|
-
return this.client.post("/api/stripe/
|
|
1646
|
-
|
|
1881
|
+
return this.client.post("/api/stripe/checkout-sessions", {
|
|
1882
|
+
mode: "payment",
|
|
1883
|
+
line_items: [{ price_id: priceId, quantity: 1 }],
|
|
1647
1884
|
success_url: successUrl,
|
|
1648
|
-
cancel_url: cancelUrl
|
|
1885
|
+
cancel_url: cancelUrl ?? successUrl
|
|
1649
1886
|
});
|
|
1650
1887
|
}
|
|
1651
|
-
async getSubscription() {
|
|
1652
|
-
|
|
1888
|
+
async getSubscription(subscriptionId) {
|
|
1889
|
+
if (subscriptionId) {
|
|
1890
|
+
return this.client.get(`/api/stripe/subscription/${subscriptionId}`);
|
|
1891
|
+
}
|
|
1892
|
+
return this.client.get("/api/stripe/subscriptions");
|
|
1653
1893
|
}
|
|
1654
|
-
async cancelSubscription() {
|
|
1655
|
-
|
|
1894
|
+
async cancelSubscription(subscriptionId, options = {}) {
|
|
1895
|
+
if (!subscriptionId) {
|
|
1896
|
+
throw new Error("subscriptionId is required to cancel a subscription.");
|
|
1897
|
+
}
|
|
1898
|
+
return this.client.post(`/api/stripe/subscription/${subscriptionId}/cancel`, options);
|
|
1656
1899
|
}
|
|
1657
1900
|
// Usage Methods
|
|
1658
1901
|
async authorizeUsage(payload) {
|
|
@@ -1661,6 +1904,18 @@ var SPAPSClient = class _SPAPSClient {
|
|
|
1661
1904
|
async recordUsage(payload) {
|
|
1662
1905
|
return this.usage.record(payload);
|
|
1663
1906
|
}
|
|
1907
|
+
async getUsageStatus(query) {
|
|
1908
|
+
return this.usage.getStatus(query);
|
|
1909
|
+
}
|
|
1910
|
+
async listUsageHistory(query = {}) {
|
|
1911
|
+
return this.usage.listHistory(query);
|
|
1912
|
+
}
|
|
1913
|
+
async emitMarketingEvent(payload) {
|
|
1914
|
+
return this.marketing.emit(payload);
|
|
1915
|
+
}
|
|
1916
|
+
async getMarketingExperimentResults(experimentId) {
|
|
1917
|
+
return this.marketing.getExperimentResults(experimentId);
|
|
1918
|
+
}
|
|
1664
1919
|
// Secure Messaging Methods
|
|
1665
1920
|
async createSecureMessage(payload) {
|
|
1666
1921
|
const response = await this.client.post("/api/secure-messages", payload);
|