samsar-js 0.48.20 → 0.48.21

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 CHANGED
@@ -512,7 +512,7 @@ Video model support notes:
512
512
  Upcoming `/v2` omni route adapters:
513
513
  - `/v2` is additive; `/v1` is not deprecated.
514
514
  - `createV2VideoFromText`, `createV2VideoFromImageList`, `updateV2VideoOutroImage`, `addV2VideoOutroImage`, `getV2Status`, `getV2Credits`, `listV2Requests`, and `createV2Session` call the new omni route surface.
515
- - Programmatic user billing helpers include `createV2UserRechargeCredits`, `refreshV2UserToken`, `getV2UserCredits`, `getV2UserUsageLogs`, and `getV2UserPaymentStatus`.
515
+ - Programmatic user billing helpers include `createV2UserRechargeCredits`, `refreshV2UserToken`, `createV2UserAppKey`, `refreshV2UserAppKey`, `getV2UserCredits`, `getV2UserUsageLogs`, and `getV2UserPaymentStatus`.
516
516
  - Omit `externalUser` for internal account billing, pass `externalUser` to scope an external user with the account API key, or authenticate the client directly with an external-user auth token/API key.
517
517
 
518
518
  ```ts
@@ -556,6 +556,21 @@ localStorage.setItem('refreshToken', refreshed.data.refreshToken);
556
556
  localStorage.setItem('expiryDate', refreshed.data.expiryDate);
557
557
  ```
558
558
 
559
+ Long-running app credentials:
560
+
561
+ ```ts
562
+ const secret = crypto.randomUUID() + crypto.randomUUID();
563
+ const created = await userClient.createV2UserAppKey({ secret });
564
+
565
+ const appClient = new SamsarClient({
566
+ appKey: created.data.appKey ?? created.data.app_key,
567
+ appSecret: secret,
568
+ });
569
+
570
+ const credits = await appClient.getV2UserCredits();
571
+ const rotated = await appClient.refreshV2UserAppKey();
572
+ ```
573
+
559
574
  Each method returns `{ data, status, headers, creditsCharged, creditsRemaining, raw }`. Non-2xx responses throw `SamsarRequestError` containing status, body, and credit headers (if present).
560
575
 
561
576
  ## Billing notes
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ type QueryValue = string | number | boolean | null | undefined;
3
3
  type QueryParams = Record<string, QueryValue>;
4
4
  export interface SamsarClientOptions {
5
5
  apiKey?: string;
6
+ appKey?: string;
7
+ appSecret?: string;
6
8
  baseUrl?: string;
7
9
  timeoutMs?: number;
8
10
  fetch?: FetchLike;
@@ -13,6 +15,8 @@ export interface SamsarRequestOptions {
13
15
  idempotencyKey?: string;
14
16
  headers?: Record<string, string>;
15
17
  externalUserApiKey?: string;
18
+ appKey?: string;
19
+ appSecret?: string;
16
20
  signal?: AbortSignal;
17
21
  query?: QueryParams;
18
22
  }
@@ -1365,6 +1369,50 @@ export interface V2UserTokenResponse {
1365
1369
  refreshTokenExpiresAt?: string;
1366
1370
  [key: string]: unknown;
1367
1371
  }
1372
+ export interface V2UserAppKeyRequest {
1373
+ secret?: string;
1374
+ appSecret?: string;
1375
+ app_secret?: string;
1376
+ metadata?: Record<string, unknown>;
1377
+ [key: string]: unknown;
1378
+ }
1379
+ export interface V2UserAppKeyRefreshRequest {
1380
+ appKey?: string;
1381
+ app_key?: string;
1382
+ secret?: string;
1383
+ appSecret?: string;
1384
+ app_secret?: string;
1385
+ [key: string]: unknown;
1386
+ }
1387
+ export interface V2UserAppKeyRecord {
1388
+ id?: string;
1389
+ userId?: string;
1390
+ appKeyPrefix?: string | null;
1391
+ appKeyLast4?: string | null;
1392
+ status?: 'active' | 'revoked' | string;
1393
+ expiresAt?: string | null;
1394
+ lastUsedAt?: string | null;
1395
+ refreshedAt?: string | null;
1396
+ revokedAt?: string | null;
1397
+ rotationCount?: number;
1398
+ createdAt?: string | null;
1399
+ updatedAt?: string | null;
1400
+ authScheme?: string;
1401
+ authHeader?: string;
1402
+ secretHeader?: string;
1403
+ [key: string]: unknown;
1404
+ }
1405
+ export interface V2UserAppKeyResponse {
1406
+ app_key?: string;
1407
+ appKey?: string;
1408
+ token_type?: 'AppKey' | string;
1409
+ tokenType?: 'AppKey' | string;
1410
+ expires_at?: string;
1411
+ expiresAt?: string;
1412
+ app_key_record?: V2UserAppKeyRecord;
1413
+ appKeyRecord?: V2UserAppKeyRecord;
1414
+ [key: string]: unknown;
1415
+ }
1368
1416
  export interface UsageLogItem {
1369
1417
  id?: string;
1370
1418
  source?: string;
@@ -1572,6 +1620,8 @@ export declare class SamsarRequestError extends Error {
1572
1620
  }
1573
1621
  export declare class SamsarClient {
1574
1622
  private readonly apiKey?;
1623
+ private readonly appKey?;
1624
+ private readonly appSecret?;
1575
1625
  private readonly baseUrl;
1576
1626
  private readonly timeoutMs;
1577
1627
  private readonly fetchFn;
@@ -1600,6 +1650,10 @@ export declare class SamsarClient {
1600
1650
  createV2UserRechargeCredits(payload: V2UserRechargeCreditsRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserRechargeCreditsResponse>>;
1601
1651
  refreshV2UserToken(payload: string | V2UserTokenRefreshRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserTokenResponse>>;
1602
1652
  refreshV2UserAuthToken(payload: string | V2UserTokenRefreshRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserTokenResponse>>;
1653
+ createV2UserAppKey(payload: string | V2UserAppKeyRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserAppKeyResponse>>;
1654
+ getV2UserAppKey(options?: V2RequestOptions): Promise<SamsarResult<V2UserAppKeyResponse>>;
1655
+ refreshV2UserAppKey(payload?: V2UserAppKeyRefreshRequest, options?: V2RequestOptions): Promise<SamsarResult<V2UserAppKeyResponse>>;
1656
+ revokeV2UserAppKey(options?: V2RequestOptions): Promise<SamsarResult<V2UserAppKeyResponse>>;
1603
1657
  getV2UserPaymentStatus(payload: PaymentStatusRequest, options?: V2RequestOptions): Promise<SamsarResult<PaymentStatusResponse>>;
1604
1658
  createV2LoginToken(options?: V2RequestOptions & {
1605
1659
  redirect?: string;
package/dist/index.js CHANGED
@@ -271,6 +271,8 @@ function normalizeSessionPublicationInput(input, context) {
271
271
  export class SamsarClient {
272
272
  constructor(options) {
273
273
  this.apiKey = options?.apiKey?.trim() || undefined;
274
+ this.appKey = options?.appKey?.trim() || undefined;
275
+ this.appSecret = options?.appSecret?.trim() || undefined;
274
276
  this.baseUrl = trimTrailingSlash(options.baseUrl ?? DEFAULT_BASE_URL);
275
277
  this.timeoutMs = options.timeoutMs ?? 30000;
276
278
  this.fetchFn = options.fetch ?? globalThis.fetch;
@@ -359,6 +361,44 @@ export class SamsarClient {
359
361
  async refreshV2UserAuthToken(payload, options) {
360
362
  return this.refreshV2UserToken(payload, options);
361
363
  }
364
+ async createV2UserAppKey(payload, options) {
365
+ const input = typeof payload === 'string' ? { secret: payload } : (payload ?? {});
366
+ const secret = input.secret ?? input.appSecret ?? input.app_secret;
367
+ if (!secret || typeof secret !== 'string') {
368
+ throw new Error('secret is required');
369
+ }
370
+ if (secret.trim().length < 32) {
371
+ throw new Error('secret must be at least 32 characters');
372
+ }
373
+ return this.postV2('users/app_key', {
374
+ ...input,
375
+ secret: secret.trim(),
376
+ }, options);
377
+ }
378
+ async getV2UserAppKey(options) {
379
+ return this.getV2('users/app_key', options);
380
+ }
381
+ async refreshV2UserAppKey(payload, options) {
382
+ const input = payload ?? {};
383
+ const appKey = input.appKey ?? input.app_key ?? options?.appKey ?? this.appKey;
384
+ const secret = input.secret ?? input.appSecret ?? input.app_secret ?? options?.appSecret ?? this.appSecret;
385
+ if (!appKey || typeof appKey !== 'string') {
386
+ throw new Error('appKey is required');
387
+ }
388
+ if (!secret || typeof secret !== 'string') {
389
+ throw new Error('secret is required');
390
+ }
391
+ if (secret.trim().length < 32) {
392
+ throw new Error('secret must be at least 32 characters');
393
+ }
394
+ return this.postV2('users/app_key/refresh', {
395
+ app_key: appKey.trim(),
396
+ secret: secret.trim(),
397
+ }, options);
398
+ }
399
+ async revokeV2UserAppKey(options) {
400
+ return this.request(this.buildV2Url('users/app_key'), { ...(options ?? {}), method: 'DELETE' });
401
+ }
362
402
  async getV2UserPaymentStatus(payload, options) {
363
403
  const query = {
364
404
  ...(options?.query ?? {}),
@@ -1686,10 +1726,17 @@ export class SamsarClient {
1686
1726
  };
1687
1727
  }
1688
1728
  buildHeaders(options) {
1729
+ const resolvedAppKey = options.appKey?.trim() || (!this.apiKey ? this.appKey : undefined);
1730
+ const resolvedAppSecret = options.appSecret?.trim() || this.appSecret;
1689
1731
  const headers = {
1690
- Authorization: this.apiKey ? `Bearer ${this.apiKey}` : undefined,
1732
+ Authorization: resolvedAppKey
1733
+ ? `AppKey ${resolvedAppKey}`
1734
+ : this.apiKey
1735
+ ? `Bearer ${this.apiKey}`
1736
+ : undefined,
1691
1737
  'Content-Type': options.body ? 'application/json' : undefined,
1692
1738
  'x-external-user-api-key': options.externalUserApiKey ?? this.externalUserApiKey,
1739
+ 'x-app-secret': resolvedAppKey ? resolvedAppSecret : undefined,
1693
1740
  ...this.defaultHeaders,
1694
1741
  ...(options.headers ?? {}),
1695
1742
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samsar-js",
3
- "version": "0.48.20",
3
+ "version": "0.48.21",
4
4
  "description": "TypeScript client for the Samsar Processor API routes.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",