perspectapi-ts-sdk 3.5.0 → 3.5.1
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 +3 -3
- package/dist/index.d.mts +16 -7
- package/dist/index.d.ts +16 -7
- package/dist/index.js +13 -0
- package/dist/index.mjs +13 -0
- package/package.json +1 -1
- package/src/client/site-users-client.ts +18 -0
- package/src/utils/image-transform.ts +7 -7
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ import { PerspectApiClient } from 'perspectapi-ts-sdk';
|
|
|
93
93
|
import { myCacheAdapter } from './cache-adapter';
|
|
94
94
|
|
|
95
95
|
const perspect = new PerspectApiClient({
|
|
96
|
-
baseUrl: 'https://api.perspect.
|
|
96
|
+
baseUrl: 'https://api.perspect.comm',
|
|
97
97
|
apiKey: env.PERSPECT_API_KEY,
|
|
98
98
|
cache: {
|
|
99
99
|
adapter: myCacheAdapter,
|
|
@@ -248,7 +248,7 @@ const media = product.data.media?.[0];
|
|
|
248
248
|
|
|
249
249
|
if (media) {
|
|
250
250
|
// Generate all responsive sizes automatically
|
|
251
|
-
const urls = transformMediaItem('https://api.perspect.
|
|
251
|
+
const urls = transformMediaItem('https://api.perspect.comm', media);
|
|
252
252
|
|
|
253
253
|
console.log(urls.thumbnail); // 150x150 cover crop
|
|
254
254
|
console.log(urls.small); // 400px wide
|
|
@@ -259,7 +259,7 @@ if (media) {
|
|
|
259
259
|
|
|
260
260
|
// Or build custom transformations
|
|
261
261
|
const customUrl = buildImageUrl(
|
|
262
|
-
'https://api.perspect.
|
|
262
|
+
'https://api.perspect.comm',
|
|
263
263
|
'media/mysite/photo.jpg',
|
|
264
264
|
{
|
|
265
265
|
width: 400,
|
package/dist/index.d.mts
CHANGED
|
@@ -2416,6 +2416,15 @@ declare class SiteUsersClient extends BaseClient {
|
|
|
2416
2416
|
changeSubscriptionPlan(siteName: string, subscriptionId: string, productId: number, csrfToken?: string): Promise<ApiResponse<{
|
|
2417
2417
|
success: boolean;
|
|
2418
2418
|
}>>;
|
|
2419
|
+
/**
|
|
2420
|
+
* Create a Stripe Billing Portal session for updating payment methods
|
|
2421
|
+
* @param siteName - The site name
|
|
2422
|
+
* @param returnUrl - URL to redirect back to after portal session
|
|
2423
|
+
* @param csrfToken - CSRF token (required)
|
|
2424
|
+
*/
|
|
2425
|
+
createBillingPortalSession(siteName: string, returnUrl: string, csrfToken?: string): Promise<ApiResponse<{
|
|
2426
|
+
url: string;
|
|
2427
|
+
}>>;
|
|
2419
2428
|
/**
|
|
2420
2429
|
* Get linked newsletter subscriptions
|
|
2421
2430
|
* @param siteName - The site name
|
|
@@ -2769,7 +2778,7 @@ declare const DEFAULT_IMAGE_SIZES: ResponsiveImageSizes;
|
|
|
2769
2778
|
/**
|
|
2770
2779
|
* Build Cloudflare Image Resizing URL
|
|
2771
2780
|
*
|
|
2772
|
-
* @param baseUrl - The base URL of your API (e.g., "https://api.perspect.
|
|
2781
|
+
* @param baseUrl - The base URL of your API (e.g., "https://api.perspect.comm")
|
|
2773
2782
|
* @param mediaPath - The path to the media file (e.g., "media/site/image.jpg")
|
|
2774
2783
|
* @param options - Transform options
|
|
2775
2784
|
* @returns Cloudflare Image Resizing URL
|
|
@@ -2777,11 +2786,11 @@ declare const DEFAULT_IMAGE_SIZES: ResponsiveImageSizes;
|
|
|
2777
2786
|
* @example
|
|
2778
2787
|
* ```typescript
|
|
2779
2788
|
* const url = buildImageUrl(
|
|
2780
|
-
* 'https://api.perspect.
|
|
2789
|
+
* 'https://api.perspect.comm',
|
|
2781
2790
|
* 'media/mysite/photo.jpg',
|
|
2782
2791
|
* { width: 400, format: 'webp', quality: 85 }
|
|
2783
2792
|
* );
|
|
2784
|
-
* // Returns: '/cdn-cgi/image/width=400,format=webp,quality=85/https://api.perspect.
|
|
2793
|
+
* // Returns: '/cdn-cgi/image/width=400,format=webp,quality=85/https://api.perspect.comm/media/mysite/photo.jpg'
|
|
2785
2794
|
* ```
|
|
2786
2795
|
*/
|
|
2787
2796
|
declare function buildImageUrl(baseUrl: string, mediaPath: string, options?: ImageTransformOptions): string;
|
|
@@ -2791,7 +2800,7 @@ declare function buildImageUrl(baseUrl: string, mediaPath: string, options?: Ima
|
|
|
2791
2800
|
* @example
|
|
2792
2801
|
* ```typescript
|
|
2793
2802
|
* const urls = generateResponsiveUrls(
|
|
2794
|
-
* 'https://api.perspect.
|
|
2803
|
+
* 'https://api.perspect.comm',
|
|
2795
2804
|
* 'media/mysite/photo.jpg'
|
|
2796
2805
|
* );
|
|
2797
2806
|
* // Returns: { thumbnail: '...', small: '...', medium: '...', large: '...', original: '...' }
|
|
@@ -2804,7 +2813,7 @@ declare function generateResponsiveUrls(baseUrl: string, mediaPath: string, size
|
|
|
2804
2813
|
* @example
|
|
2805
2814
|
* ```typescript
|
|
2806
2815
|
* const srcset = generateSrcSet(
|
|
2807
|
-
* 'https://api.perspect.
|
|
2816
|
+
* 'https://api.perspect.comm',
|
|
2808
2817
|
* 'media/mysite/photo.jpg',
|
|
2809
2818
|
* [400, 800, 1200]
|
|
2810
2819
|
* );
|
|
@@ -2831,7 +2840,7 @@ declare function generateSizesAttribute(breakpoints?: Array<{
|
|
|
2831
2840
|
* @example
|
|
2832
2841
|
* ```typescript
|
|
2833
2842
|
* const html = generateResponsiveImageHtml(
|
|
2834
|
-
* 'https://api.perspect.
|
|
2843
|
+
* 'https://api.perspect.comm',
|
|
2835
2844
|
* 'media/mysite/photo.jpg',
|
|
2836
2845
|
* 'My photo',
|
|
2837
2846
|
* { className: 'rounded-lg', loading: 'lazy' }
|
|
@@ -2857,7 +2866,7 @@ declare function generateResponsiveImageHtml(baseUrl: string, mediaPath: string,
|
|
|
2857
2866
|
* const media = product.data.media?.[0];
|
|
2858
2867
|
*
|
|
2859
2868
|
* if (media) {
|
|
2860
|
-
* const urls = transformMediaItem('https://api.perspect.
|
|
2869
|
+
* const urls = transformMediaItem('https://api.perspect.comm', media);
|
|
2861
2870
|
* console.log(urls.thumbnail); // Cloudflare-transformed thumbnail URL
|
|
2862
2871
|
* }
|
|
2863
2872
|
* ```
|
package/dist/index.d.ts
CHANGED
|
@@ -2416,6 +2416,15 @@ declare class SiteUsersClient extends BaseClient {
|
|
|
2416
2416
|
changeSubscriptionPlan(siteName: string, subscriptionId: string, productId: number, csrfToken?: string): Promise<ApiResponse<{
|
|
2417
2417
|
success: boolean;
|
|
2418
2418
|
}>>;
|
|
2419
|
+
/**
|
|
2420
|
+
* Create a Stripe Billing Portal session for updating payment methods
|
|
2421
|
+
* @param siteName - The site name
|
|
2422
|
+
* @param returnUrl - URL to redirect back to after portal session
|
|
2423
|
+
* @param csrfToken - CSRF token (required)
|
|
2424
|
+
*/
|
|
2425
|
+
createBillingPortalSession(siteName: string, returnUrl: string, csrfToken?: string): Promise<ApiResponse<{
|
|
2426
|
+
url: string;
|
|
2427
|
+
}>>;
|
|
2419
2428
|
/**
|
|
2420
2429
|
* Get linked newsletter subscriptions
|
|
2421
2430
|
* @param siteName - The site name
|
|
@@ -2769,7 +2778,7 @@ declare const DEFAULT_IMAGE_SIZES: ResponsiveImageSizes;
|
|
|
2769
2778
|
/**
|
|
2770
2779
|
* Build Cloudflare Image Resizing URL
|
|
2771
2780
|
*
|
|
2772
|
-
* @param baseUrl - The base URL of your API (e.g., "https://api.perspect.
|
|
2781
|
+
* @param baseUrl - The base URL of your API (e.g., "https://api.perspect.comm")
|
|
2773
2782
|
* @param mediaPath - The path to the media file (e.g., "media/site/image.jpg")
|
|
2774
2783
|
* @param options - Transform options
|
|
2775
2784
|
* @returns Cloudflare Image Resizing URL
|
|
@@ -2777,11 +2786,11 @@ declare const DEFAULT_IMAGE_SIZES: ResponsiveImageSizes;
|
|
|
2777
2786
|
* @example
|
|
2778
2787
|
* ```typescript
|
|
2779
2788
|
* const url = buildImageUrl(
|
|
2780
|
-
* 'https://api.perspect.
|
|
2789
|
+
* 'https://api.perspect.comm',
|
|
2781
2790
|
* 'media/mysite/photo.jpg',
|
|
2782
2791
|
* { width: 400, format: 'webp', quality: 85 }
|
|
2783
2792
|
* );
|
|
2784
|
-
* // Returns: '/cdn-cgi/image/width=400,format=webp,quality=85/https://api.perspect.
|
|
2793
|
+
* // Returns: '/cdn-cgi/image/width=400,format=webp,quality=85/https://api.perspect.comm/media/mysite/photo.jpg'
|
|
2785
2794
|
* ```
|
|
2786
2795
|
*/
|
|
2787
2796
|
declare function buildImageUrl(baseUrl: string, mediaPath: string, options?: ImageTransformOptions): string;
|
|
@@ -2791,7 +2800,7 @@ declare function buildImageUrl(baseUrl: string, mediaPath: string, options?: Ima
|
|
|
2791
2800
|
* @example
|
|
2792
2801
|
* ```typescript
|
|
2793
2802
|
* const urls = generateResponsiveUrls(
|
|
2794
|
-
* 'https://api.perspect.
|
|
2803
|
+
* 'https://api.perspect.comm',
|
|
2795
2804
|
* 'media/mysite/photo.jpg'
|
|
2796
2805
|
* );
|
|
2797
2806
|
* // Returns: { thumbnail: '...', small: '...', medium: '...', large: '...', original: '...' }
|
|
@@ -2804,7 +2813,7 @@ declare function generateResponsiveUrls(baseUrl: string, mediaPath: string, size
|
|
|
2804
2813
|
* @example
|
|
2805
2814
|
* ```typescript
|
|
2806
2815
|
* const srcset = generateSrcSet(
|
|
2807
|
-
* 'https://api.perspect.
|
|
2816
|
+
* 'https://api.perspect.comm',
|
|
2808
2817
|
* 'media/mysite/photo.jpg',
|
|
2809
2818
|
* [400, 800, 1200]
|
|
2810
2819
|
* );
|
|
@@ -2831,7 +2840,7 @@ declare function generateSizesAttribute(breakpoints?: Array<{
|
|
|
2831
2840
|
* @example
|
|
2832
2841
|
* ```typescript
|
|
2833
2842
|
* const html = generateResponsiveImageHtml(
|
|
2834
|
-
* 'https://api.perspect.
|
|
2843
|
+
* 'https://api.perspect.comm',
|
|
2835
2844
|
* 'media/mysite/photo.jpg',
|
|
2836
2845
|
* 'My photo',
|
|
2837
2846
|
* { className: 'rounded-lg', loading: 'lazy' }
|
|
@@ -2857,7 +2866,7 @@ declare function generateResponsiveImageHtml(baseUrl: string, mediaPath: string,
|
|
|
2857
2866
|
* const media = product.data.media?.[0];
|
|
2858
2867
|
*
|
|
2859
2868
|
* if (media) {
|
|
2860
|
-
* const urls = transformMediaItem('https://api.perspect.
|
|
2869
|
+
* const urls = transformMediaItem('https://api.perspect.comm', media);
|
|
2861
2870
|
* console.log(urls.thumbnail); // Cloudflare-transformed thumbnail URL
|
|
2862
2871
|
* }
|
|
2863
2872
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -2529,6 +2529,19 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2529
2529
|
csrfToken
|
|
2530
2530
|
);
|
|
2531
2531
|
}
|
|
2532
|
+
/**
|
|
2533
|
+
* Create a Stripe Billing Portal session for updating payment methods
|
|
2534
|
+
* @param siteName - The site name
|
|
2535
|
+
* @param returnUrl - URL to redirect back to after portal session
|
|
2536
|
+
* @param csrfToken - CSRF token (required)
|
|
2537
|
+
*/
|
|
2538
|
+
async createBillingPortalSession(siteName, returnUrl, csrfToken) {
|
|
2539
|
+
return this.create(
|
|
2540
|
+
this.siteUserEndpoint(siteName, "/users/me/billing-portal"),
|
|
2541
|
+
{ return_url: returnUrl },
|
|
2542
|
+
csrfToken
|
|
2543
|
+
);
|
|
2544
|
+
}
|
|
2532
2545
|
/**
|
|
2533
2546
|
* Get linked newsletter subscriptions
|
|
2534
2547
|
* @param siteName - The site name
|
package/dist/index.mjs
CHANGED
|
@@ -2466,6 +2466,19 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2466
2466
|
csrfToken
|
|
2467
2467
|
);
|
|
2468
2468
|
}
|
|
2469
|
+
/**
|
|
2470
|
+
* Create a Stripe Billing Portal session for updating payment methods
|
|
2471
|
+
* @param siteName - The site name
|
|
2472
|
+
* @param returnUrl - URL to redirect back to after portal session
|
|
2473
|
+
* @param csrfToken - CSRF token (required)
|
|
2474
|
+
*/
|
|
2475
|
+
async createBillingPortalSession(siteName, returnUrl, csrfToken) {
|
|
2476
|
+
return this.create(
|
|
2477
|
+
this.siteUserEndpoint(siteName, "/users/me/billing-portal"),
|
|
2478
|
+
{ return_url: returnUrl },
|
|
2479
|
+
csrfToken
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2469
2482
|
/**
|
|
2470
2483
|
* Get linked newsletter subscriptions
|
|
2471
2484
|
* @param siteName - The site name
|
package/package.json
CHANGED
|
@@ -355,6 +355,24 @@ export class SiteUsersClient extends BaseClient {
|
|
|
355
355
|
);
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Create a Stripe Billing Portal session for updating payment methods
|
|
360
|
+
* @param siteName - The site name
|
|
361
|
+
* @param returnUrl - URL to redirect back to after portal session
|
|
362
|
+
* @param csrfToken - CSRF token (required)
|
|
363
|
+
*/
|
|
364
|
+
async createBillingPortalSession(
|
|
365
|
+
siteName: string,
|
|
366
|
+
returnUrl: string,
|
|
367
|
+
csrfToken?: string
|
|
368
|
+
): Promise<ApiResponse<{ url: string }>> {
|
|
369
|
+
return this.create<{ return_url: string }, { url: string }>(
|
|
370
|
+
this.siteUserEndpoint(siteName, '/users/me/billing-portal'),
|
|
371
|
+
{ return_url: returnUrl },
|
|
372
|
+
csrfToken
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
358
376
|
/**
|
|
359
377
|
* Get linked newsletter subscriptions
|
|
360
378
|
* @param siteName - The site name
|
|
@@ -70,7 +70,7 @@ export const DEFAULT_IMAGE_SIZES: ResponsiveImageSizes = {
|
|
|
70
70
|
/**
|
|
71
71
|
* Build Cloudflare Image Resizing URL
|
|
72
72
|
*
|
|
73
|
-
* @param baseUrl - The base URL of your API (e.g., "https://api.perspect.
|
|
73
|
+
* @param baseUrl - The base URL of your API (e.g., "https://api.perspect.comm")
|
|
74
74
|
* @param mediaPath - The path to the media file (e.g., "media/site/image.jpg")
|
|
75
75
|
* @param options - Transform options
|
|
76
76
|
* @returns Cloudflare Image Resizing URL
|
|
@@ -78,11 +78,11 @@ export const DEFAULT_IMAGE_SIZES: ResponsiveImageSizes = {
|
|
|
78
78
|
* @example
|
|
79
79
|
* ```typescript
|
|
80
80
|
* const url = buildImageUrl(
|
|
81
|
-
* 'https://api.perspect.
|
|
81
|
+
* 'https://api.perspect.comm',
|
|
82
82
|
* 'media/mysite/photo.jpg',
|
|
83
83
|
* { width: 400, format: 'webp', quality: 85 }
|
|
84
84
|
* );
|
|
85
|
-
* // Returns: '/cdn-cgi/image/width=400,format=webp,quality=85/https://api.perspect.
|
|
85
|
+
* // Returns: '/cdn-cgi/image/width=400,format=webp,quality=85/https://api.perspect.comm/media/mysite/photo.jpg'
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
88
|
export function buildImageUrl(
|
|
@@ -139,7 +139,7 @@ export function buildImageUrl(
|
|
|
139
139
|
* @example
|
|
140
140
|
* ```typescript
|
|
141
141
|
* const urls = generateResponsiveUrls(
|
|
142
|
-
* 'https://api.perspect.
|
|
142
|
+
* 'https://api.perspect.comm',
|
|
143
143
|
* 'media/mysite/photo.jpg'
|
|
144
144
|
* );
|
|
145
145
|
* // Returns: { thumbnail: '...', small: '...', medium: '...', large: '...', original: '...' }
|
|
@@ -165,7 +165,7 @@ export function generateResponsiveUrls(
|
|
|
165
165
|
* @example
|
|
166
166
|
* ```typescript
|
|
167
167
|
* const srcset = generateSrcSet(
|
|
168
|
-
* 'https://api.perspect.
|
|
168
|
+
* 'https://api.perspect.comm',
|
|
169
169
|
* 'media/mysite/photo.jpg',
|
|
170
170
|
* [400, 800, 1200]
|
|
171
171
|
* );
|
|
@@ -220,7 +220,7 @@ export function generateSizesAttribute(
|
|
|
220
220
|
* @example
|
|
221
221
|
* ```typescript
|
|
222
222
|
* const html = generateResponsiveImageHtml(
|
|
223
|
-
* 'https://api.perspect.
|
|
223
|
+
* 'https://api.perspect.comm',
|
|
224
224
|
* 'media/mysite/photo.jpg',
|
|
225
225
|
* 'My photo',
|
|
226
226
|
* { className: 'rounded-lg', loading: 'lazy' }
|
|
@@ -271,7 +271,7 @@ export function generateResponsiveImageHtml(
|
|
|
271
271
|
* const media = product.data.media?.[0];
|
|
272
272
|
*
|
|
273
273
|
* if (media) {
|
|
274
|
-
* const urls = transformMediaItem('https://api.perspect.
|
|
274
|
+
* const urls = transformMediaItem('https://api.perspect.comm', media);
|
|
275
275
|
* console.log(urls.thumbnail); // Cloudflare-transformed thumbnail URL
|
|
276
276
|
* }
|
|
277
277
|
* ```
|