@joai/sdk 4.1.0 → 4.2.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/dist/index.d.mts CHANGED
@@ -38,7 +38,7 @@ type SocialAuthProvider = 'github' | 'apple' | 'google' | 'x' | 'telegram' | 'sl
38
38
  //#region src/config/types.d.ts
39
39
  type AppEnv = 'mainnet' | 'testnet' | 'devnet' | 'local'; //#endregion
40
40
  //#region src/auth/token.d.ts
41
- /** One-time native/deep-link handoff param (exchanged for a Bearer via API). */
41
+ /** One-time native/deep-link handoff fragment key (exchanged for a Bearer via POST). */
42
42
  //#endregion
43
43
  //#region src/ingestion/types.d.ts
44
44
  type IngestionSourceType = 'note' | 'meeting' | 'article' | 'email' | 'chat' | 'post' | 'webhook';
@@ -154,8 +154,33 @@ type WalletList = Partial<Record<WarpChainName, {
154
154
  provider: WarpWalletProvider;
155
155
  address?: string;
156
156
  }>>; //#endregion
157
+ //#region src/user/permissions.d.ts
158
+ /** Permission string values — must match joai--api `UserPermission::value`. */
159
+ declare const UserPermissions: {
160
+ readonly BillingManage: "billing-manage";
161
+ readonly TeamManage: "team-manage";
162
+ readonly TeamView: "team-view";
163
+ readonly TeamMemberInvite: "team-member-invite";
164
+ readonly TeamMemberRemove: "team-member-remove";
165
+ readonly TeamSecretView: "team-secret-view";
166
+ readonly TeamSecretManage: "team-secret-manage";
167
+ readonly AgentExecute: "agent-execute";
168
+ readonly AgentWalletManage: "agent-wallet-manage";
169
+ readonly SwarmCreate: "swarm-create";
170
+ };
171
+ type UserPermission = (typeof UserPermissions)[keyof typeof UserPermissions];
172
+ //#endregion
173
+ //#region src/user/roles.d.ts
174
+ /** Team member roles — values must match joai--api `UserRole::toName()`. */
175
+ declare const UserRoles: {
176
+ readonly Owner: "owner";
177
+ readonly Admin: "admin";
178
+ readonly Member: "member";
179
+ readonly Developer: "developer";
180
+ };
181
+ type UserRole = (typeof UserRoles)[keyof typeof UserRoles];
182
+ //#endregion
157
183
  //#region src/user/types.d.ts
158
- type UserRole = 'owner' | 'member';
159
184
  type UserMode = 'simple' | 'advanced';
160
185
  type UserInterest = 'payments' | 'health' | 'content' | 'business' | 'finance' | 'research' | 'shopping' | 'web3' | 'developer' | 'fitness' | 'ecommerce';
161
186
  type UserSettings = {
@@ -191,8 +216,6 @@ type UserPrivate = {
191
216
  socials: UserSocialAccount[];
192
217
  justCreated: boolean;
193
218
  affiliate: Affiliate | null;
194
- billingAddress: BillingAddress | null;
195
- betaRestricted: boolean;
196
219
  kyc?: Kyc | null;
197
220
  settings: UserSettings;
198
221
  };
@@ -243,14 +266,13 @@ type AffiliateTier = {
243
266
  threshold: number;
244
267
  };
245
268
  type AffiliateStatus = 'pending' | 'approved' | 'rejected' | 'suspended' | 'demoted'; //#endregion
246
- //#region src/team/constants.d.ts
247
- declare const teamCategories: readonly ["general", "food-drink", "retail", "beauty-wellness", "health", "sports-fitness", "trades-services", "professional-services", "education-culture", "clubs-organizations", "leisure-tourism"]; //#endregion
248
269
  //#region src/team/apps.d.ts
249
270
  declare const NativeApps: {
250
271
  readonly Board: "board";
251
272
  readonly Shop: "shop";
252
273
  readonly SmartLinks: "smart-links";
253
274
  readonly Contacts: "contacts";
275
+ readonly Forms: "forms";
254
276
  readonly Appointments: "appointments";
255
277
  readonly Workspace: "workspace";
256
278
  readonly Meeting: "meeting";
@@ -264,6 +286,25 @@ declare const NativeApps: {
264
286
  };
265
287
  type NativeApp = (typeof NativeApps)[keyof typeof NativeApps];
266
288
  //#endregion
289
+ //#region src/access/team-access.d.ts
290
+ type TeamFeatureArea = 'nativeApps' | 'agentSettings' | 'teamSettings' | 'developerHub' | 'areas' | 'commerce';
291
+ /** Keys per area that the API evaluates in `team.access`. */
292
+ type TeamAccessCatalog = Partial<Record<TeamFeatureArea, string[]>>;
293
+ type TeamAccessConfig = {
294
+ accessCatalog: TeamAccessCatalog;
295
+ };
296
+ /** Resolved feature access from API `TeamPrivate.access` — do not evaluate rules on the client. */
297
+ type TeamFeatureAccess = {
298
+ nativeApps?: Partial<Record<NativeApp, boolean>>;
299
+ agentSettings?: Partial<Record<string, boolean>>;
300
+ teamSettings?: Partial<Record<string, boolean>>;
301
+ developerHub?: Partial<Record<string, boolean>>;
302
+ areas?: Partial<Record<string, boolean>>;
303
+ commerce?: Partial<Record<string, boolean>>;
304
+ };
305
+ //#endregion
306
+ //#region src/team/constants.d.ts
307
+ declare const teamCategories: readonly ["general", "food-drink", "retail", "beauty-wellness", "health", "sports-fitness", "trades-services", "professional-services", "education-culture", "clubs-organizations", "leisure-tourism"]; //#endregion
267
308
  //#region src/team/types.d.ts
268
309
  type TeamCategory = (typeof teamCategories)[number];
269
310
  type TeamFeature = 'shop' | 'appointments';
@@ -375,6 +416,10 @@ type TeamPrivate = {
375
416
  category: TeamCategory;
376
417
  createdAt: string;
377
418
  justCreated: boolean;
419
+ role?: UserRole | null;
420
+ permissions?: UserPermission[];
421
+ access?: TeamFeatureAccess;
422
+ accessCatalog?: TeamAccessCatalog;
378
423
  };
379
424
  type ByokProviderConfig = {
380
425
  apiKey?: string;
@@ -442,6 +487,186 @@ type AiCostsResponse = {
442
487
  };
443
488
  };
444
489
  }; //#endregion
490
+ //#region src/address/enums.d.ts
491
+ declare const AddressTypes: {
492
+ readonly Billing: "billing";
493
+ readonly Shipping: "shipping";
494
+ };
495
+ type AddressType = (typeof AddressTypes)[keyof typeof AddressTypes];
496
+ //#endregion
497
+ //#region src/address/types.d.ts
498
+ type Address = {
499
+ id: string;
500
+ type: AddressType;
501
+ name: string;
502
+ company: string | null;
503
+ addressOne: string;
504
+ addressTwo: string | null;
505
+ city: string;
506
+ state: string | null;
507
+ zipCode: string;
508
+ country: string;
509
+ phone: string | null;
510
+ isDefault: boolean;
511
+ business: boolean;
512
+ vatId: string | null;
513
+ isEU: boolean;
514
+ isEEA: boolean;
515
+ };
516
+ type AddressSnapshot = Pick<Address, 'name' | 'company' | 'addressOne' | 'addressTwo' | 'city' | 'state' | 'zipCode' | 'country' | 'phone' | 'business' | 'vatId'>;
517
+ type AddressInput = {
518
+ name: string;
519
+ addressOne: string;
520
+ city: string;
521
+ zipCode: string;
522
+ country: string;
523
+ type?: AddressType;
524
+ company?: string | null;
525
+ addressTwo?: string | null;
526
+ state?: string | null;
527
+ phone?: string | null;
528
+ business?: boolean;
529
+ vatId?: string | null;
530
+ };
531
+ type AddressCreatePayload = {
532
+ name: string;
533
+ country: string;
534
+ type?: AddressType;
535
+ email?: string | null;
536
+ company?: string | null;
537
+ addressOne?: string | null;
538
+ addressTwo?: string | null;
539
+ city?: string | null;
540
+ state?: string | null;
541
+ zipCode?: string | null;
542
+ vatId?: string | null;
543
+ phone?: string | null;
544
+ isDefault?: boolean;
545
+ contact?: string;
546
+ team?: string;
547
+ };
548
+ type AddressUpdatePayload = Partial<Omit<AddressCreatePayload, 'contact' | 'team'>>; //#endregion
549
+ //#region src/commerce/enums.d.ts
550
+ declare const FulfillmentStatuses: {
551
+ readonly Pending: "pending";
552
+ readonly ReadyForPickup: "ready_for_pickup";
553
+ readonly Shipped: "shipped";
554
+ readonly Delivered: "delivered";
555
+ readonly Cancelled: "cancelled";
556
+ };
557
+ type FulfillmentStatus = (typeof FulfillmentStatuses)[keyof typeof FulfillmentStatuses];
558
+ declare const FulfillmentMethods: {
559
+ readonly Shipping: "shipping";
560
+ readonly Pickup: "pickup";
561
+ };
562
+ type FulfillmentMethod = (typeof FulfillmentMethods)[keyof typeof FulfillmentMethods];
563
+ declare const ReturnStatuses: {
564
+ readonly Requested: "requested";
565
+ readonly Approved: "approved";
566
+ readonly Rejected: "rejected";
567
+ readonly Received: "received";
568
+ readonly Closed: "closed";
569
+ };
570
+ type ReturnStatus = (typeof ReturnStatuses)[keyof typeof ReturnStatuses];
571
+ //#endregion
572
+ //#region src/commerce/types.d.ts
573
+ type ShippingRate = {
574
+ id: number;
575
+ name: string;
576
+ price: number;
577
+ fee?: number;
578
+ freeShippingThreshold?: number | null;
579
+ minOrderValue?: number | null;
580
+ maxOrderValue?: number | null;
581
+ minWeight?: number | null;
582
+ maxWeight?: number | null;
583
+ estimatedMinDays?: number | null;
584
+ estimatedMaxDays?: number | null;
585
+ active?: boolean;
586
+ position?: number;
587
+ };
588
+ type CheckoutSnapshot = {
589
+ id: string;
590
+ fulfillmentMethod: FulfillmentMethod;
591
+ totals: {
592
+ subtotal: number;
593
+ shippingFee: number;
594
+ total: number;
595
+ };
596
+ expiresAt: string;
597
+ accessToken?: string | null;
598
+ };
599
+ type CheckoutSnapshotRequest = {
600
+ fulfillmentMethod: FulfillmentMethod;
601
+ items: {
602
+ id: string;
603
+ type: 'product' | 'service' | 'coupon';
604
+ quantity: number;
605
+ }[];
606
+ billingAddressId?: number | null;
607
+ shippingAddressId?: number | null;
608
+ billingAddress?: AddressInput;
609
+ shippingAddress?: AddressInput;
610
+ shippingRateId?: number | null;
611
+ fulfillmentLocationId?: number | null;
612
+ };
613
+ type ShippingZone = {
614
+ id: number;
615
+ name: string;
616
+ countries: string[];
617
+ postal_code_rules: string[] | null;
618
+ active: boolean;
619
+ position: number;
620
+ rates: ShippingRate[];
621
+ };
622
+ type FulfillmentLocation = {
623
+ id: number;
624
+ name: string;
625
+ address_id: number | null;
626
+ address: Address | null;
627
+ instructions: string | null;
628
+ active: boolean;
629
+ };
630
+ type Fulfillment = {
631
+ id: string;
632
+ orderId: number;
633
+ method: FulfillmentMethod;
634
+ status: FulfillmentStatus;
635
+ carrierCode: string | null;
636
+ trackingNumber: string | null;
637
+ trackingUrl: string | null;
638
+ items: {
639
+ orderItemId: number;
640
+ quantity: number;
641
+ }[];
642
+ shippedAt: string | null;
643
+ readyForPickupAt: string | null;
644
+ deliveredAt: string | null;
645
+ };
646
+ type Return = {
647
+ id: string;
648
+ orderId: number;
649
+ status: ReturnStatus;
650
+ reason: string;
651
+ merchantNote: string | null;
652
+ items: {
653
+ orderItemId: number;
654
+ quantity: number;
655
+ condition: string | null;
656
+ }[];
657
+ refundAmount: number | null;
658
+ };
659
+ type SubscriptionDelivery = {
660
+ fulfillmentMethod: FulfillmentMethod | null;
661
+ nextOrderAt: string | null;
662
+ pausedAt: string | null;
663
+ shippingAddress?: AddressSnapshot | null;
664
+ shippingRate?: Pick<ShippingRate, 'name' | 'price'> | null;
665
+ fulfillmentLocation?: {
666
+ name: string;
667
+ instructions: string | null;
668
+ } | null;
669
+ }; //#endregion
445
670
  //#region src/json/types.d.ts
446
671
  type JsonValue = string | number | boolean | null | JsonValue[] | {
447
672
  [key: string]: JsonValue;
@@ -563,7 +788,7 @@ type OrderType = 'order' | 'quote';
563
788
  type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'pending';
564
789
  type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly';
565
790
  type PricingModel = 'free' | 'one-time' | 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'per-run';
566
- type AppSubscription = {
791
+ type Subscription = {
567
792
  id: string;
568
793
  orderId: string;
569
794
  teamId: string;
@@ -576,6 +801,7 @@ type AppSubscription = {
576
801
  meta: Record<string, JsonValue> | null;
577
802
  createdAt: string;
578
803
  updatedAt: string;
804
+ delivery?: SubscriptionDelivery | null;
579
805
  };
580
806
  type PaymentProvider = 'xmoney' | 'lemonsqueezy' | 'stripe' | 'stripe-connect' | 'mollie' | 'mollie-connect' | 'apple' | 'google' | 'blockchain' | 'offline';
581
807
  type PaymentAccount = {
@@ -614,16 +840,6 @@ type PlanExtra = {
614
840
  price: number;
615
841
  unitName: string;
616
842
  };
617
- type BillingAddress = {
618
- name: string;
619
- addressOne: string | null;
620
- city: string | null;
621
- state: string | null;
622
- zipCode: string | null;
623
- country: string;
624
- vatId: string | null;
625
- isEU: boolean;
626
- };
627
843
  type PlanInterval = 'weekly' | 'monthly' | 'yearly' | 'lifetime';
628
844
  type Plan = {
629
845
  resource: 'plan';
@@ -778,6 +994,17 @@ type Order = {
778
994
  paymentMode: string | null;
779
995
  linkVariationId: string | null;
780
996
  notes: string | null;
997
+ fulfillmentMethod?: FulfillmentMethod | null;
998
+ address?: AddressSnapshot | null;
999
+ shippingAddress?: AddressSnapshot | null;
1000
+ shippingRate?: Pick<ShippingRate, 'name' | 'price' | 'estimatedMinDays' | 'estimatedMaxDays'> | null;
1001
+ fulfillmentLocation?: {
1002
+ name: string;
1003
+ instructions?: string | null;
1004
+ } | null;
1005
+ shippingFee?: number;
1006
+ fulfillments?: Fulfillment[];
1007
+ subscription?: Subscription | null;
781
1008
  configuration?: OrderConfigurationItem[];
782
1009
  items: OrderItem[];
783
1010
  coupon?: Coupon | null;
@@ -1429,7 +1656,8 @@ type Meeting = {
1429
1656
  captureMode: 'desktop_local' | null;
1430
1657
  transcriptUrl: string | null;
1431
1658
  summaryUrl: string | null;
1432
- participants?: MeetingParticipant[];
1659
+ participants?: MeetingParticipant[]; /** The customer associated with an appointment booking, when available. */
1660
+ contact?: Contact | null;
1433
1661
  speakerAssignments?: MeetingSpeakerAssignment[] | null;
1434
1662
  scheduledAt: string | null;
1435
1663
  calendarEventId: number | null;
@@ -1507,6 +1735,7 @@ type AppointmentPolicy = {
1507
1735
  bookingCapacity?: number | null;
1508
1736
  bookingCapacityUnit?: 'booking' | 'person' | null;
1509
1737
  requireApproval?: boolean | null;
1738
+ notificationEmail?: string | null;
1510
1739
  sync?: AppointmentPolicySync | null;
1511
1740
  agent?: Agent | null;
1512
1741
  agentUuid?: string | null;
@@ -1546,7 +1775,7 @@ type AppointmentRequest = {
1546
1775
  configuration?: Configuration;
1547
1776
  createdAt: string;
1548
1777
  }; //#endregion
1549
- //#region src/budget/types.d.ts
1778
+ //#region src/commerce/helpers.d.ts
1550
1779
  //#endregion
1551
1780
  //#region src/card/types.d.ts
1552
1781
  type Card = {
@@ -2890,6 +3119,166 @@ declare class AgentsResource {
2890
3119
  }): Promise<IAppResponse<unknown>>;
2891
3120
  }
2892
3121
  //#endregion
3122
+ //#region src/address/addresses.d.ts
3123
+ type AddressQuery = {
3124
+ contact?: string;
3125
+ team?: string;
3126
+ type?: AddressType;
3127
+ };
3128
+ declare class AddressesResource {
3129
+ private readonly http;
3130
+ constructor(http: IHttpService);
3131
+ list(params?: AddressQuery): Promise<IAppResponse<Address[]>>;
3132
+ get(params?: Omit<AddressQuery, 'type'>): Promise<IAppResponse<Address | null>>;
3133
+ create(data: AddressCreatePayload): Promise<IAppResponse<Address>>;
3134
+ update(id: string, data: AddressUpdatePayload): Promise<IAppResponse<Address>>;
3135
+ delete(id: string): Promise<IAppResponse<void>>;
3136
+ }
3137
+ //#endregion
3138
+ //#region src/commerce/checkout.d.ts
3139
+ type PlaceCheckoutOrderRequest = CheckoutSnapshotRequest & {
3140
+ guest?: {
3141
+ name: string;
3142
+ email: string;
3143
+ };
3144
+ notes?: string;
3145
+ idempotencyKey?: string;
3146
+ saveAddresses?: boolean;
3147
+ sendConfirmation?: boolean;
3148
+ };
3149
+ declare class CheckoutResource {
3150
+ private readonly http;
3151
+ constructor(http: IHttpService);
3152
+ snapshot(team: string, data: CheckoutSnapshotRequest): Promise<IAppResponse<CheckoutSnapshot>>;
3153
+ placeOrder(team: string, data: PlaceCheckoutOrderRequest): Promise<IAppResponse<Order>>;
3154
+ locations(team: string): Promise<IAppResponse<FulfillmentLocation[]>>;
3155
+ shippingRates(team: string, data: {
3156
+ address: {
3157
+ country: string;
3158
+ zipCode?: string;
3159
+ };
3160
+ items: {
3161
+ id: string;
3162
+ type: 'product' | 'service' | 'coupon';
3163
+ quantity: number;
3164
+ }[];
3165
+ }): Promise<IAppResponse<ShippingRate[]>>;
3166
+ }
3167
+ //#endregion
3168
+ //#region src/commerce/fulfillments.d.ts
3169
+ declare class FulfillmentsResource {
3170
+ private readonly http;
3171
+ constructor(http: IHttpService);
3172
+ list(orderId: string): Promise<IAppResponse<Fulfillment[]>>;
3173
+ create(orderId: string, data: {
3174
+ items: {
3175
+ orderItemId: number;
3176
+ quantity: number;
3177
+ }[];
3178
+ carrierCode?: string;
3179
+ trackingNumber?: string;
3180
+ trackingUrl?: string;
3181
+ status?: Fulfillment['status'];
3182
+ }): Promise<IAppResponse<Fulfillment>>;
3183
+ update(orderId: string, fulfillmentId: string, status: Fulfillment['status']): Promise<IAppResponse<Fulfillment>>;
3184
+ }
3185
+ //#endregion
3186
+ //#region src/commerce/returns.d.ts
3187
+ declare class ReturnsResource {
3188
+ private readonly http;
3189
+ constructor(http: IHttpService);
3190
+ list(orderId: string, accessToken?: string): Promise<IAppResponse<Return[]>>;
3191
+ create(orderId: string, data: {
3192
+ reason: string;
3193
+ fulfillmentId?: number;
3194
+ items: {
3195
+ orderItemId: number;
3196
+ quantity: number;
3197
+ condition?: string;
3198
+ }[];
3199
+ }, accessToken?: string): Promise<IAppResponse<Return>>;
3200
+ update(id: string, data: {
3201
+ status: Exclude<ReturnStatus, 'requested'>;
3202
+ merchantNote?: string;
3203
+ refundAmount?: number;
3204
+ resolution?: number;
3205
+ returnShippingCostPayer?: number;
3206
+ }): Promise<IAppResponse<Return>>;
3207
+ }
3208
+ //#endregion
3209
+ //#region src/commerce/shipping.d.ts
3210
+ type ZoneInput = {
3211
+ name: string;
3212
+ countries: string[];
3213
+ postalCodeRules?: string[];
3214
+ active?: boolean;
3215
+ position?: number;
3216
+ };
3217
+ type RateInput = {
3218
+ name: string;
3219
+ price: number;
3220
+ freeShippingThreshold?: number;
3221
+ minOrderValue?: number;
3222
+ maxOrderValue?: number;
3223
+ minWeight?: number;
3224
+ maxWeight?: number;
3225
+ estimatedMinDays?: number;
3226
+ estimatedMaxDays?: number;
3227
+ active?: boolean;
3228
+ position?: number;
3229
+ };
3230
+ declare class ShippingResource {
3231
+ private readonly http;
3232
+ constructor(http: IHttpService);
3233
+ zones(team: string): Promise<IAppResponse<ShippingZone[]>>;
3234
+ createZone(team: string, data: ZoneInput): Promise<IAppResponse<ShippingZone>>;
3235
+ updateZone(team: string, zoneId: number, data: Partial<ZoneInput>): Promise<IAppResponse<ShippingZone>>;
3236
+ deleteZone(team: string, zoneId: number): Promise<IAppResponse<void>>;
3237
+ createRate(team: string, zoneId: number, data: RateInput): Promise<IAppResponse<ShippingRate>>;
3238
+ locations(team: string): Promise<IAppResponse<FulfillmentLocation[]>>;
3239
+ createLocation(team: string, data: {
3240
+ name: string;
3241
+ addressId?: number;
3242
+ instructions?: string;
3243
+ active?: boolean;
3244
+ }): Promise<IAppResponse<FulfillmentLocation>>;
3245
+ }
3246
+ //#endregion
3247
+ //#region src/commerce/guest.d.ts
3248
+ type GuestOrderAccess = {
3249
+ orderId: string;
3250
+ accessToken: string | null;
3251
+ };
3252
+ type GuestCheckoutDraft<TCart = unknown> = {
3253
+ cart: TCart;
3254
+ fulfillmentMethod: FulfillmentMethod;
3255
+ shippingRateId: number | null;
3256
+ fulfillmentLocationId: number | null;
3257
+ };
3258
+ type GuestCommerceStorageOptions = {
3259
+ namespace: string;
3260
+ maxOrders?: number;
3261
+ };
3262
+ declare function createGuestCommerceStorage(options: GuestCommerceStorageOptions): {
3263
+ saveCheckoutDraft<TCart>(draft: GuestCheckoutDraft<TCart>): void;
3264
+ readCheckoutDraft<TCart>(fallback: GuestCheckoutDraft<TCart>): GuestCheckoutDraft<TCart>;
3265
+ saveOrderAccess({
3266
+ orderId,
3267
+ accessToken
3268
+ }: GuestOrderAccess): void;
3269
+ readOrderAccess(orderId: string): string | null;
3270
+ listOrderAccess(): GuestOrderAccess[];
3271
+ };
3272
+ //#endregion
3273
+ //#region src/commerce/index.d.ts
3274
+ declare class CommerceResource {
3275
+ readonly checkout: CheckoutResource;
3276
+ readonly shipping: ShippingResource;
3277
+ readonly fulfillments: FulfillmentsResource;
3278
+ readonly returns: ReturnsResource;
3279
+ constructor(http: IHttpService);
3280
+ }
3281
+ //#endregion
2893
3282
  //#region src/resources/alerts.d.ts
2894
3283
  declare class AlertsResource {
2895
3284
  private readonly http;
@@ -3100,11 +3489,21 @@ type NativeSocialAuthProvider = Extract<SocialAuthProvider, 'apple' | 'google'>;
3100
3489
  type AuthSendCodeRequest = {
3101
3490
  name: string;
3102
3491
  phone?: string;
3492
+ email: string;
3493
+ team?: string;
3494
+ table?: string;
3495
+ };
3496
+ type AuthConfirmCodeRequest = {
3497
+ code: string;
3498
+ phone?: string;
3103
3499
  email?: string;
3104
3500
  team?: string;
3105
3501
  table?: string;
3106
3502
  };
3107
- type AuthVerifyResponse = {
3503
+ type AuthConfirmCodeResponse = {
3504
+ authUrl: string;
3505
+ };
3506
+ type AuthNativeSessionResponse = {
3108
3507
  token: string;
3109
3508
  user: AuthUser;
3110
3509
  team: {
@@ -3121,37 +3520,24 @@ type AuthLoginResponse = {
3121
3520
  type AuthApiTokenResponse = {
3122
3521
  plainTextToken: string;
3123
3522
  };
3523
+ type AuthPortalSessionResponse = {
3524
+ url: string;
3525
+ };
3124
3526
  declare class AuthResource {
3125
3527
  private http;
3126
3528
  constructor(http: IHttpService);
3127
3529
  sendCode(data: AuthSendCodeRequest): Promise<IAppResponse<void>>;
3530
+ confirmCode(data: AuthConfirmCodeRequest): Promise<IAppResponse<AuthConfirmCodeResponse>>;
3128
3531
  requestEmail(email: string, redirect?: string): Promise<IAppResponse<AuthLoginResponse>>;
3129
3532
  loginWithSocialAccessToken(provider: NativeSocialAuthProvider, accessToken: string): Promise<IAppResponse<AuthLoginResponse>>;
3130
- verify(token: string): Promise<IAppResponse<AuthVerifyResponse>>;
3533
+ exchangeNativeSession(token: string): Promise<IAppResponse<AuthNativeSessionResponse>>;
3131
3534
  me(): Promise<IAppResponse<AuthUser>>;
3132
3535
  logout(): Promise<IAppResponse<void>>;
3133
3536
  createApiToken(): Promise<IAppResponse<AuthApiTokenResponse>>;
3537
+ createPortalSession(redirect: string): Promise<IAppResponse<AuthPortalSessionResponse>>;
3134
3538
  verifyWallet(accessToken: string, withMobileApiToken?: boolean): Promise<IAppResponse<UserPrivate>>;
3135
3539
  }
3136
3540
  //#endregion
3137
- //#region src/resources/billing-addresses.d.ts
3138
- declare class BillingAddressesResource {
3139
- private readonly http;
3140
- constructor(http: IHttpService);
3141
- get(contact?: string, team?: string): Promise<IAppResponse<BillingAddress | null>>;
3142
- store(data: {
3143
- name: string;
3144
- addressOne?: string;
3145
- city?: string;
3146
- state?: string;
3147
- zipCode?: string;
3148
- country: string;
3149
- vatId?: string;
3150
- contact?: string;
3151
- team?: string;
3152
- }): Promise<IAppResponse<BillingAddress>>;
3153
- }
3154
- //#endregion
3155
3541
  //#region src/resources/billing.d.ts
3156
3542
  type IapReceipt = {
3157
3543
  productId: string;
@@ -3780,7 +4166,7 @@ declare class OrdersResource {
3780
4166
  private readonly http;
3781
4167
  constructor(http: IHttpService);
3782
4168
  list(team: string): Promise<IAppResponse<Order[]>>;
3783
- get(id: string): Promise<IAppResponse<Order>>;
4169
+ get(id: string, accessToken?: string): Promise<IAppResponse<Order>>;
3784
4170
  create(data: {
3785
4171
  contactId?: string;
3786
4172
  notes?: string;
@@ -3798,6 +4184,20 @@ declare class OrdersResource {
3798
4184
  quantity: number;
3799
4185
  configuration?: Configuration;
3800
4186
  }[];
4187
+ fulfillmentMethod?: FulfillmentMethod;
4188
+ snapshotId?: string;
4189
+ snapshotAccessToken?: string;
4190
+ billingAddressId?: number;
4191
+ shippingAddressId?: number;
4192
+ billingAddress?: AddressInput;
4193
+ shippingAddress?: AddressInput;
4194
+ shippingRateId?: number;
4195
+ fulfillmentLocationId?: number;
4196
+ idempotencyKey?: string;
4197
+ guest?: {
4198
+ name: string;
4199
+ email: string;
4200
+ };
3801
4201
  }): Promise<IAppResponse<Order>>;
3802
4202
  update(id: string, data: {
3803
4203
  status?: OrderStatus;
@@ -3806,7 +4206,7 @@ declare class OrdersResource {
3806
4206
  }): Promise<IAppResponse<Order>>;
3807
4207
  convertToOrder(id: string): Promise<IAppResponse<Order>>;
3808
4208
  delete(id: string): Promise<IAppResponse<void>>;
3809
- pay(id: string, provider?: PaymentProvider): Promise<IAppResponse<{
4209
+ pay(id: string, provider?: PaymentProvider, accessToken?: string): Promise<IAppResponse<{
3810
4210
  url: string;
3811
4211
  }>>;
3812
4212
  notify(id: string, type?: string): Promise<IAppResponse<{
@@ -3828,6 +4228,7 @@ declare class ProductsResource {
3828
4228
  constructor(http: IHttpService);
3829
4229
  list(params?: {
3830
4230
  includePrivate?: boolean;
4231
+ team?: string;
3831
4232
  }): Promise<IAppResponse<Product[]>>;
3832
4233
  get(id: string): Promise<IAppResponse<Product>>;
3833
4234
  create(data: {
@@ -4085,10 +4486,19 @@ declare class KvResource {
4085
4486
  declare class SubscriptionsResource {
4086
4487
  private readonly http;
4087
4488
  constructor(http: IHttpService);
4088
- list(team: string): Promise<IAppResponse<AppSubscription[]>>;
4089
- get(id: string): Promise<IAppResponse<AppSubscription>>;
4090
- cancel(id: string): Promise<IAppResponse<AppSubscription>>;
4091
- resume(id: string): Promise<IAppResponse<AppSubscription>>;
4489
+ list(team?: string): Promise<IAppResponse<Subscription[]>>;
4490
+ get(id: string): Promise<IAppResponse<Subscription>>;
4491
+ cancel(id: string, team: string): Promise<IAppResponse<Subscription>>;
4492
+ resume(id: string, team: string): Promise<IAppResponse<Subscription>>;
4493
+ updateDelivery(id: string, data: {
4494
+ fulfillmentMethod: 'shipping' | 'pickup';
4495
+ shippingAddressId?: number | null;
4496
+ shippingRateId?: number | null;
4497
+ fulfillmentLocationId?: number | null;
4498
+ }): Promise<IAppResponse<Subscription>>;
4499
+ skip(id: string): Promise<IAppResponse<Subscription>>;
4500
+ pause(id: string): Promise<IAppResponse<Subscription>>;
4501
+ resumeDelivery(id: string): Promise<IAppResponse<Subscription>>;
4092
4502
  cancelPlan(team: string): Promise<IAppResponse<void>>;
4093
4503
  resumePlan(team: string): Promise<IAppResponse<void>>;
4094
4504
  }
@@ -4147,7 +4557,7 @@ type TeamMutationPayload = {
4147
4557
  settings?: Record<string, JsonValue>;
4148
4558
  emails?: {
4149
4559
  email: string;
4150
- role: 'owner' | 'admin' | 'member';
4560
+ role: UserRole;
4151
4561
  }[];
4152
4562
  website?: string | null;
4153
4563
  phone?: string | null;
@@ -4173,7 +4583,7 @@ declare class TeamsResource {
4173
4583
  updateTagline(teamSlug: string, tagline: TranslatableValue | null): Promise<IAppResponse<TeamPrivate>>;
4174
4584
  invite(teamSlug: string, payload: {
4175
4585
  email: string;
4176
- role: 'owner' | 'admin' | 'member';
4586
+ role: UserRole;
4177
4587
  }): Promise<IAppResponse<void>>;
4178
4588
  inviteMember(teamSlug: string, email: string, role: UserRole): Promise<IAppResponse<void>>;
4179
4589
  removeMember(teamSlug: string, memberId: string): Promise<IAppResponse<void>>;
@@ -4188,6 +4598,7 @@ declare class TeamsResource {
4188
4598
  }): Promise<IAppResponse<TeamPlace[]>>;
4189
4599
  selectPlace(teamSlug: string, sourceId: string | null): Promise<IAppResponse<TeamPrivate>>;
4190
4600
  listPrivate(): Promise<IAppResponse<TeamPrivate[]>>;
4601
+ accessConfig(): Promise<IAppResponse<TeamAccessConfig>>;
4191
4602
  getInviteByToken(token: string): Promise<IAppResponse<TeamInviteInfo>>;
4192
4603
  acceptInvite(slug: string): Promise<IAppResponse<void>>;
4193
4604
  usage(teamSlug: string): Promise<IAppResponse<TeamUsage>>;
@@ -4476,6 +4887,8 @@ declare class JoAiClient {
4476
4887
  isReady: boolean;
4477
4888
  hasApiToken: boolean;
4478
4889
  readonly agents: AgentsResource;
4890
+ readonly addresses: AddressesResource;
4891
+ readonly commerce: CommerceResource;
4479
4892
  readonly alerts: AlertsResource;
4480
4893
  readonly apiTokens: ApiTokensResource;
4481
4894
  readonly characters: CharactersResource;
@@ -4486,7 +4899,6 @@ declare class JoAiClient {
4486
4899
  readonly appointments: AppointmentsResource;
4487
4900
  readonly auth: AuthResource;
4488
4901
  readonly billing: BillingResource;
4489
- readonly billingAddresses: BillingAddressesResource;
4490
4902
  readonly blueprints: BlueprintsResource;
4491
4903
  readonly cards: CardsResource;
4492
4904
  readonly cart: CartsResource;
@@ -4573,10 +4985,38 @@ declare class CachedHttpService implements IHttpService {
4573
4985
  private bust;
4574
4986
  }
4575
4987
  //#endregion
4988
+ //#region src/auth/portal.d.ts
4989
+ declare const getAuthFragmentToken: (url: string) => string | null;
4990
+ declare const isPortalCallbackUrl: (url: string, env?: AppEnv) => boolean;
4991
+ declare const sanitizePortalCallbackUrl: (url: string | null | undefined, env?: AppEnv) => string | null;
4992
+ declare const isAllowedRedirectUrl: (redirect: string, allowedOrigins: string[]) => boolean;
4993
+ declare const completePortalSession: (callbackUrl: string, fetcher?: typeof fetch) => Promise<boolean>;
4994
+ type PortalClient = {
4995
+ auth: {
4996
+ createPortalSession: (redirect: string) => Promise<IAppResponse<AuthPortalSessionResponse>>;
4997
+ };
4998
+ };
4999
+ type OpenPortalSessionOptions = {
5000
+ client: PortalClient;
5001
+ redirect: string;
5002
+ allowedOrigins: string[];
5003
+ env?: AppEnv;
5004
+ fetcher?: typeof fetch;
5005
+ onNavigate?: (redirect: string) => void;
5006
+ };
5007
+ declare const openPortalSession: ({
5008
+ client,
5009
+ redirect,
5010
+ allowedOrigins,
5011
+ env,
5012
+ fetcher,
5013
+ onNavigate
5014
+ }: OpenPortalSessionOptions) => Promise<boolean>;
5015
+ //#endregion
4576
5016
  //#region src/resources/distribution.d.ts
4577
5017
  declare class DistributionResource {
4578
5018
  getBrandSiteConfig(env: AppEnv, brandSlug: string): Promise<BrandSiteConfig | null>;
4579
5019
  private fetchDistribution;
4580
5020
  }
4581
5021
  //#endregion
4582
- export { AgentsResource, AlertsResource, ApiTokensResource, AppointmentsResource, type AttachedMedia, AuthResource, type AuthSendCodeRequest, type AuthVerifyResponse, type BackendWarp, type BackendWarpBrand, BillingAddressesResource, BillingResource, BlueprintsResource, type CacheConfig, CachedHttpService, CampaignsResource, CardsResource, CartsResource, ChangelogResource, CharactersResource, ContactsResource, ContractsResource, type CreateHookPayload, type CreateInboundHookPayload, type CreateInternalHookPayload, type CreateWarpLinkedHookPayload, type CreateWebHookPayload, DeskResource, DistributionResource, DocumentsResource, ElementsResource, EntitiesResource, FlowsResource, GoalsResource, type Hook, type HookSample, type HookTrigger, type HookTriggerCondition, type HookTriggerInput, HooksResource, IngestionsResource, InquiriesResource, IntegrationsResource, IntentsResource, ItemsResource, JoAiClient, type JoAiClientConfig, KvResource, LinksResource, LoyaltyResource, McpResource, type MediaUploadType, MeetingsResource, MemoriesResource, MessagesResource, MissionsResource, NotificationsResource, OfficeResource, type OpeningHoursEntry, type OpeningHoursFormatOptions, OrdersResource, PersonaResource, type Product, type ProductVariation, ProductsResource, ProjectsResource, RemindersResource, SegmentsResource, ServicesResource, ShortcutsResource, SitesResource, SkillsResource, StatsResource, StoreResource, SubscriptionsResource, SwarmsResource, TagsResource, TasksResource, type TeamInviteInfo, TeamsResource, UpdatesResource, UpgradesResource, UsersResource, VoiceResource, WalletsResource, WarpsResource, type WebHookTriggerEvent, WorkspaceResource, createClient, formatOpeningHours };
5022
+ export { AddressesResource, AgentsResource, AlertsResource, ApiTokensResource, AppointmentsResource, type AttachedMedia, type AuthConfirmCodeRequest, type AuthConfirmCodeResponse, type AuthNativeSessionResponse, type AuthPortalSessionResponse, AuthResource, type AuthSendCodeRequest, type BackendWarp, type BackendWarpBrand, BillingResource, BlueprintsResource, type CacheConfig, CachedHttpService, CampaignsResource, CardsResource, CartsResource, ChangelogResource, CharactersResource, CheckoutResource, CommerceResource, ContactsResource, ContractsResource, type CreateHookPayload, type CreateInboundHookPayload, type CreateInternalHookPayload, type CreateWarpLinkedHookPayload, type CreateWebHookPayload, DeskResource, DistributionResource, DocumentsResource, ElementsResource, EntitiesResource, FlowsResource, FulfillmentsResource, GoalsResource, type GuestCheckoutDraft, type GuestCommerceStorageOptions, type GuestOrderAccess, type Hook, type HookSample, type HookTrigger, type HookTriggerCondition, type HookTriggerInput, HooksResource, IngestionsResource, InquiriesResource, IntegrationsResource, IntentsResource, ItemsResource, JoAiClient, type JoAiClientConfig, KvResource, LinksResource, LoyaltyResource, McpResource, type MediaUploadType, MeetingsResource, MemoriesResource, MessagesResource, MissionsResource, NotificationsResource, OfficeResource, type OpenPortalSessionOptions, type OpeningHoursEntry, type OpeningHoursFormatOptions, OrdersResource, PersonaResource, type Product, type ProductVariation, ProductsResource, ProjectsResource, RemindersResource, ReturnsResource, SegmentsResource, ServicesResource, ShippingResource, ShortcutsResource, SitesResource, SkillsResource, StatsResource, StoreResource, SubscriptionsResource, SwarmsResource, TagsResource, TasksResource, type TeamInviteInfo, TeamsResource, UpdatesResource, UpgradesResource, UsersResource, VoiceResource, WalletsResource, WarpsResource, type WebHookTriggerEvent, WorkspaceResource, completePortalSession, createClient, createGuestCommerceStorage, formatOpeningHours, getAuthFragmentToken, isAllowedRedirectUrl, isPortalCallbackUrl, openPortalSession, sanitizePortalCallbackUrl };
package/dist/index.mjs CHANGED
@@ -110,11 +110,40 @@ var HttpService = class {
110
110
  };
111
111
  }
112
112
  };
113
+ Object.values({
114
+ Billing: "billing",
115
+ Shipping: "shipping"
116
+ });
117
+ Object.values({
118
+ Pending: "pending",
119
+ ReadyForPickup: "ready_for_pickup",
120
+ Shipped: "shipped",
121
+ Delivered: "delivered",
122
+ Cancelled: "cancelled"
123
+ });
124
+ Object.values({
125
+ Shipping: "shipping",
126
+ Pickup: "pickup"
127
+ });
128
+ Object.values({
129
+ Requested: "requested",
130
+ Approved: "approved",
131
+ Rejected: "rejected",
132
+ Received: "received",
133
+ Closed: "closed"
134
+ });
135
+ Object.values({
136
+ Approved: "approved",
137
+ Rejected: "rejected",
138
+ Received: "received",
139
+ Closed: "closed"
140
+ });
113
141
  Object.values({
114
142
  Board: "board",
115
143
  Shop: "shop",
116
144
  SmartLinks: "smart-links",
117
145
  Contacts: "contacts",
146
+ Forms: "forms",
118
147
  Appointments: "appointments",
119
148
  Workspace: "workspace",
120
149
  Meeting: "meeting",
@@ -126,6 +155,47 @@ Object.values({
126
155
  Sites: "sites",
127
156
  Contracts: "contracts"
128
157
  });
158
+ /** Permission string values — must match joai--api `UserPermission::value`. */
159
+ const UserPermissions = {
160
+ BillingManage: "billing-manage",
161
+ TeamManage: "team-manage",
162
+ TeamView: "team-view",
163
+ TeamMemberInvite: "team-member-invite",
164
+ TeamMemberRemove: "team-member-remove",
165
+ TeamSecretView: "team-secret-view",
166
+ TeamSecretManage: "team-secret-manage",
167
+ AgentExecute: "agent-execute",
168
+ AgentWalletManage: "agent-wallet-manage",
169
+ SwarmCreate: "swarm-create"
170
+ };
171
+ Object.values(UserPermissions);
172
+ const teamManageOr = (...permissions) => ({ permissionsAny: [UserPermissions.TeamManage, ...permissions] });
173
+ const permissionPresetRules = {
174
+ teamManage: { permissions: [UserPermissions.TeamManage] },
175
+ teamView: teamManageOr(UserPermissions.TeamView),
176
+ billingManage: teamManageOr(UserPermissions.BillingManage),
177
+ agentTooling: teamManageOr(UserPermissions.AgentExecute),
178
+ secretView: teamManageOr(UserPermissions.TeamSecretView),
179
+ secretManage: teamManageOr(UserPermissions.TeamSecretManage),
180
+ teamMemberInvite: teamManageOr(UserPermissions.TeamMemberInvite),
181
+ teamMemberRemove: teamManageOr(UserPermissions.TeamMemberRemove),
182
+ agentWalletManage: teamManageOr(UserPermissions.AgentWalletManage),
183
+ swarmCreate: teamManageOr(UserPermissions.SwarmCreate)
184
+ };
185
+ permissionPresetRules.teamManage;
186
+ permissionPresetRules.teamView;
187
+ permissionPresetRules.agentTooling;
188
+ permissionPresetRules.billingManage;
189
+ /** Team member roles — values must match joai--api `UserRole::toName()`. */
190
+ const UserRoles = {
191
+ Owner: "owner",
192
+ Admin: "admin",
193
+ Member: "member",
194
+ Developer: "developer"
195
+ };
196
+ Object.values(UserRoles);
197
+ UserRoles.Member, UserRoles.Developer, UserRoles.Admin;
198
+ UserRoles.Member;
129
199
  //#endregion
130
200
  //#region src/resources/agents.ts
131
201
  var AgentsResource = class {
@@ -217,6 +287,207 @@ var AgentsResource = class {
217
287
  }
218
288
  };
219
289
  //#endregion
290
+ //#region src/address/addresses.ts
291
+ var AddressesResource = class {
292
+ constructor(http) {
293
+ this.http = http;
294
+ }
295
+ list(params) {
296
+ return this.http.get(`addresses${query(params)}`);
297
+ }
298
+ get(params) {
299
+ return this.list({
300
+ ...params,
301
+ type: "billing"
302
+ }).then((response) => ({
303
+ ...response,
304
+ data: response.ok ? response.data[0] ?? null : null
305
+ }));
306
+ }
307
+ create(data) {
308
+ return this.http.post("addresses", data);
309
+ }
310
+ update(id, data) {
311
+ return this.http.patch(`addresses/${id}`, data);
312
+ }
313
+ delete(id) {
314
+ return this.http.delete(`addresses/${id}`);
315
+ }
316
+ };
317
+ const query = (params) => {
318
+ const search = new URLSearchParams();
319
+ if (params?.contact) search.set("contact", params.contact);
320
+ if (params?.team) search.set("team", params.team);
321
+ if (params?.type) search.set("type", params.type);
322
+ const value = search.toString();
323
+ return value ? `?${value}` : "";
324
+ };
325
+ //#endregion
326
+ //#region src/commerce/checkout.ts
327
+ var CheckoutResource = class {
328
+ constructor(http) {
329
+ this.http = http;
330
+ }
331
+ snapshot(team, data) {
332
+ return this.http.post(`shops/${encodeURIComponent(team)}/checkout/snapshots`, data);
333
+ }
334
+ placeOrder(team, data) {
335
+ return this.http.post(`shops/${encodeURIComponent(team)}/checkout/orders`, data);
336
+ }
337
+ locations(team) {
338
+ return this.http.get(`shops/${encodeURIComponent(team)}/checkout/fulfillment-locations`);
339
+ }
340
+ shippingRates(team, data) {
341
+ return this.http.post(`shops/${encodeURIComponent(team)}/checkout/shipping-rates`, data);
342
+ }
343
+ };
344
+ //#endregion
345
+ //#region src/commerce/fulfillments.ts
346
+ var FulfillmentsResource = class {
347
+ constructor(http) {
348
+ this.http = http;
349
+ }
350
+ list(orderId) {
351
+ return this.http.get(`orders/${orderId}/fulfillments`);
352
+ }
353
+ create(orderId, data) {
354
+ return this.http.post(`orders/${orderId}/fulfillments`, data);
355
+ }
356
+ update(orderId, fulfillmentId, status) {
357
+ return this.http.patch(`orders/${orderId}/fulfillments/${fulfillmentId}`, { status });
358
+ }
359
+ };
360
+ //#endregion
361
+ //#region src/commerce/returns.ts
362
+ const orderAccessHeaders$1 = (accessToken) => accessToken ? { headers: { "X-Order-Access-Token": accessToken } } : void 0;
363
+ var ReturnsResource = class {
364
+ constructor(http) {
365
+ this.http = http;
366
+ }
367
+ list(orderId, accessToken) {
368
+ return this.http.get(`orders/${orderId}/returns`, orderAccessHeaders$1(accessToken));
369
+ }
370
+ create(orderId, data, accessToken) {
371
+ return this.http.post(`orders/${orderId}/returns`, data, orderAccessHeaders$1(accessToken));
372
+ }
373
+ update(id, data) {
374
+ return this.http.patch(`returns/${id}`, data);
375
+ }
376
+ };
377
+ //#endregion
378
+ //#region src/commerce/shipping.ts
379
+ var ShippingResource = class {
380
+ constructor(http) {
381
+ this.http = http;
382
+ }
383
+ zones(team) {
384
+ return this.http.get(`teams/${team}/shipping-zones`);
385
+ }
386
+ createZone(team, data) {
387
+ return this.http.post(`teams/${team}/shipping-zones`, data);
388
+ }
389
+ updateZone(team, zoneId, data) {
390
+ return this.http.patch(`teams/${team}/shipping-zones/${zoneId}`, data);
391
+ }
392
+ deleteZone(team, zoneId) {
393
+ return this.http.delete(`teams/${team}/shipping-zones/${zoneId}`);
394
+ }
395
+ createRate(team, zoneId, data) {
396
+ return this.http.post(`teams/${team}/shipping-zones/${zoneId}/rates`, data);
397
+ }
398
+ locations(team) {
399
+ return this.http.get(`teams/${team}/fulfillment-locations`);
400
+ }
401
+ createLocation(team, data) {
402
+ return this.http.post(`teams/${team}/fulfillment-locations`, data);
403
+ }
404
+ };
405
+ //#endregion
406
+ //#region src/commerce/guest.ts
407
+ const orderAccessPrefix = "joai:order-access:";
408
+ const checkoutKey = (namespace) => `joai:guest-checkout:${namespace}`;
409
+ const ordersKey = (namespace) => `joai:guest-orders:${namespace}`;
410
+ const orderAccessKey = (namespace, orderId) => `${orderAccessPrefix}${namespace}:${orderId}`;
411
+ const safeGet = (key) => {
412
+ if (typeof localStorage === "undefined") return null;
413
+ try {
414
+ return localStorage.getItem(key);
415
+ } catch {
416
+ return null;
417
+ }
418
+ };
419
+ const safeSet = (key, value) => {
420
+ if (typeof localStorage === "undefined") return;
421
+ try {
422
+ localStorage.setItem(key, value);
423
+ } catch {}
424
+ };
425
+ const parseGuestOrderAccess = (entry) => {
426
+ if (!entry || typeof entry !== "object") return null;
427
+ const record = entry;
428
+ if (typeof record.orderId !== "string") return null;
429
+ if (record.accessToken !== null && typeof record.accessToken !== "string") return null;
430
+ return {
431
+ orderId: record.orderId,
432
+ accessToken: record.accessToken ?? null
433
+ };
434
+ };
435
+ const readOrderList = (namespace) => {
436
+ try {
437
+ const saved = JSON.parse(safeGet(ordersKey(namespace)) || "[]");
438
+ if (!Array.isArray(saved)) return [];
439
+ return saved.map(parseGuestOrderAccess).filter((entry) => entry !== null);
440
+ } catch {
441
+ return [];
442
+ }
443
+ };
444
+ function createGuestCommerceStorage(options) {
445
+ const maxOrders = options.maxOrders ?? 10;
446
+ return {
447
+ saveCheckoutDraft(draft) {
448
+ safeSet(checkoutKey(options.namespace), JSON.stringify(draft));
449
+ },
450
+ readCheckoutDraft(fallback) {
451
+ try {
452
+ const saved = JSON.parse(safeGet(checkoutKey(options.namespace)) || "");
453
+ return {
454
+ ...fallback,
455
+ ...saved,
456
+ cart: Array.isArray(saved.cart) ? saved.cart : fallback.cart
457
+ };
458
+ } catch {
459
+ return fallback;
460
+ }
461
+ },
462
+ saveOrderAccess({ orderId, accessToken }) {
463
+ const key = orderAccessKey(options.namespace, orderId);
464
+ if (accessToken) safeSet(key, accessToken);
465
+ const orders = readOrderList(options.namespace).filter((entry) => entry.orderId !== orderId);
466
+ orders.unshift({
467
+ orderId,
468
+ accessToken
469
+ });
470
+ safeSet(ordersKey(options.namespace), JSON.stringify(orders.slice(0, maxOrders)));
471
+ },
472
+ readOrderAccess(orderId) {
473
+ return safeGet(orderAccessKey(options.namespace, orderId));
474
+ },
475
+ listOrderAccess() {
476
+ return readOrderList(options.namespace);
477
+ }
478
+ };
479
+ }
480
+ //#endregion
481
+ //#region src/commerce/index.ts
482
+ var CommerceResource = class {
483
+ constructor(http) {
484
+ this.checkout = new CheckoutResource(http);
485
+ this.shipping = new ShippingResource(http);
486
+ this.fulfillments = new FulfillmentsResource(http);
487
+ this.returns = new ReturnsResource(http);
488
+ }
489
+ };
490
+ //#endregion
220
491
  //#region src/resources/alerts.ts
221
492
  var AlertsResource = class {
222
493
  constructor(http) {
@@ -501,6 +772,9 @@ var AuthResource = class {
501
772
  sendCode(data) {
502
773
  return this.http.post("auth/send-code", data);
503
774
  }
775
+ confirmCode(data) {
776
+ return this.http.post("auth/confirm-code", data);
777
+ }
504
778
  requestEmail(email, redirect) {
505
779
  return this.http.post("auth/email/request", {
506
780
  email,
@@ -510,8 +784,8 @@ var AuthResource = class {
510
784
  loginWithSocialAccessToken(provider, accessToken) {
511
785
  return this.http.post(`auth/social/${provider}/login`, { accessToken });
512
786
  }
513
- verify(token) {
514
- return this.http.get("auth/verify?token=" + token);
787
+ exchangeNativeSession(token) {
788
+ return this.http.post("auth/verify", { token });
515
789
  }
516
790
  me() {
517
791
  return this.http.get("auth/me");
@@ -522,6 +796,9 @@ var AuthResource = class {
522
796
  createApiToken() {
523
797
  return this.http.post("auth/api-tokens");
524
798
  }
799
+ createPortalSession(redirect) {
800
+ return this.http.post("auth/portal-sessions", { redirect });
801
+ }
525
802
  verifyWallet(accessToken, withMobileApiToken) {
526
803
  return this.http.post("auth/wallet/verify", {
527
804
  accessToken,
@@ -530,23 +807,6 @@ var AuthResource = class {
530
807
  }
531
808
  };
532
809
  //#endregion
533
- //#region src/resources/billing-addresses.ts
534
- var BillingAddressesResource = class {
535
- constructor(http) {
536
- this.http = http;
537
- }
538
- get(contact, team) {
539
- const params = new URLSearchParams();
540
- if (contact) params.set("contact", contact);
541
- if (team) params.set("team", team);
542
- const qs = params.toString();
543
- return this.http.get(`billing/addresses${qs ? "?" + qs : ""}`);
544
- }
545
- store(data) {
546
- return this.http.post("billing/addresses", data);
547
- }
548
- };
549
- //#endregion
550
810
  //#region src/resources/billing.ts
551
811
  var BillingResource = class {
552
812
  constructor(http) {
@@ -1559,6 +1819,7 @@ var OfficeResource = class {
1559
1819
  };
1560
1820
  //#endregion
1561
1821
  //#region src/resources/orders.ts
1822
+ const orderAccessHeaders = (accessToken) => accessToken ? { headers: { "X-Order-Access-Token": accessToken } } : void 0;
1562
1823
  var OrdersResource = class {
1563
1824
  constructor(http) {
1564
1825
  this.http = http;
@@ -1566,11 +1827,11 @@ var OrdersResource = class {
1566
1827
  list(team) {
1567
1828
  return this.http.get("orders", { headers: { "X-Team": team } });
1568
1829
  }
1569
- get(id) {
1570
- return this.http.get(`orders/${id}`);
1830
+ get(id, accessToken) {
1831
+ return this.http.get(`orders/${id}`, orderAccessHeaders(accessToken));
1571
1832
  }
1572
1833
  create(data) {
1573
- return this.http.post("orders", data, { headers: { "X-Team": data.team } });
1834
+ return this.http.post("orders", data);
1574
1835
  }
1575
1836
  update(id, data) {
1576
1837
  return this.http.put(`orders/${id}`, data);
@@ -1581,8 +1842,8 @@ var OrdersResource = class {
1581
1842
  delete(id) {
1582
1843
  return this.http.delete(`orders/${id}`);
1583
1844
  }
1584
- pay(id, provider) {
1585
- return this.http.post(`orders/${id}/pay`, provider ? { provider } : {});
1845
+ pay(id, provider, accessToken) {
1846
+ return this.http.post(`orders/${id}/pay`, provider ? { provider } : {}, orderAccessHeaders(accessToken));
1586
1847
  }
1587
1848
  notify(id, type = "confirmation") {
1588
1849
  return this.http.post(`orders/${id}/notify`, { type });
@@ -1612,7 +1873,10 @@ var ProductsResource = class {
1612
1873
  }
1613
1874
  list(params) {
1614
1875
  let url = "products";
1615
- if (params?.includePrivate) url += "?includePrivate=1";
1876
+ const search = new URLSearchParams();
1877
+ if (params?.includePrivate) search.set("includePrivate", "1");
1878
+ if (params?.team) search.set("team", params.team);
1879
+ if (search.size) url += `?${search.toString()}`;
1616
1880
  return this.http.get(url);
1617
1881
  }
1618
1882
  get(id) {
@@ -1921,16 +2185,28 @@ var SubscriptionsResource = class {
1921
2185
  this.http = http;
1922
2186
  }
1923
2187
  list(team) {
1924
- return this.http.get("subscriptions");
2188
+ return team ? this.http.get("subscriptions", { headers: { "X-Team": team } }) : this.http.get("subscriptions");
1925
2189
  }
1926
2190
  get(id) {
1927
2191
  return this.http.get(`subscriptions/${id}`);
1928
2192
  }
1929
- cancel(id) {
1930
- return this.http.post(`subscriptions/${id}/cancel`);
2193
+ cancel(id, team) {
2194
+ return this.http.post(`subscriptions/${id}/cancel`, void 0, { headers: { "X-Team": team } });
1931
2195
  }
1932
- resume(id) {
1933
- return this.http.post(`subscriptions/${id}/resume`);
2196
+ resume(id, team) {
2197
+ return this.http.post(`subscriptions/${id}/resume`, void 0, { headers: { "X-Team": team } });
2198
+ }
2199
+ updateDelivery(id, data) {
2200
+ return this.http.patch(`subscriptions/${id}/delivery`, data);
2201
+ }
2202
+ skip(id) {
2203
+ return this.http.post(`subscriptions/${id}/skip`);
2204
+ }
2205
+ pause(id) {
2206
+ return this.http.post(`subscriptions/${id}/pause`);
2207
+ }
2208
+ resumeDelivery(id) {
2209
+ return this.http.post(`subscriptions/${id}/resume-delivery`);
1934
2210
  }
1935
2211
  cancelPlan(team) {
1936
2212
  return this.http.post("billing/plans/cancel", { team });
@@ -2091,6 +2367,9 @@ var TeamsResource = class {
2091
2367
  listPrivate() {
2092
2368
  return this.http.get("teams?me=true");
2093
2369
  }
2370
+ accessConfig() {
2371
+ return this.http.get("teams/access-config");
2372
+ }
2094
2373
  getInviteByToken(token) {
2095
2374
  return this.http.get(`teams/invite/${token}`);
2096
2375
  }
@@ -2642,6 +2921,8 @@ var JoAiClient = class {
2642
2921
  const cache = config.cache;
2643
2922
  this.http = cache?.enabled !== false ? new CachedHttpService(http, cache?.overrides, cache?.defaultTtl) : http;
2644
2923
  this.agents = new AgentsResource(this.http);
2924
+ this.addresses = new AddressesResource(this.http);
2925
+ this.commerce = new CommerceResource(this.http);
2645
2926
  this.alerts = new AlertsResource(this.http);
2646
2927
  this.apiTokens = new ApiTokensResource(this.http);
2647
2928
  this.characters = new CharactersResource(this.http);
@@ -2652,7 +2933,6 @@ var JoAiClient = class {
2652
2933
  this.appointments = new AppointmentsResource(this.http, config);
2653
2934
  this.auth = new AuthResource(this.http);
2654
2935
  this.billing = new BillingResource(this.http);
2655
- this.billingAddresses = new BillingAddressesResource(this.http);
2656
2936
  this.blueprints = new BlueprintsResource(this.http);
2657
2937
  this.cards = new CardsResource(this.http);
2658
2938
  this.cart = new CartsResource(this.http);
@@ -2723,6 +3003,69 @@ function createClient(config) {
2723
3003
  return new JoAiClient(config);
2724
3004
  }
2725
3005
  //#endregion
3006
+ //#region src/auth/portal.ts
3007
+ const getAuthFragmentToken = (url) => {
3008
+ try {
3009
+ return new URLSearchParams(new URL(url).hash.slice(1)).get("token");
3010
+ } catch {
3011
+ return null;
3012
+ }
3013
+ };
3014
+ const isPortalCallbackUrl = (url, env = "mainnet") => {
3015
+ try {
3016
+ const callbackUrl = new URL(url);
3017
+ const apiCallback = new URL("/v1/auth/callback", getApiBaseUrl(env));
3018
+ return callbackUrl.origin === apiCallback.origin && callbackUrl.pathname === apiCallback.pathname && !callbackUrl.search && Boolean(getAuthFragmentToken(url));
3019
+ } catch {
3020
+ return false;
3021
+ }
3022
+ };
3023
+ const sanitizePortalCallbackUrl = (url, env = "mainnet") => url && isPortalCallbackUrl(url, env) ? url : null;
3024
+ const isAllowedRedirectUrl = (redirect, allowedOrigins) => {
3025
+ try {
3026
+ return allowedOrigins.includes(new URL(redirect).origin);
3027
+ } catch {
3028
+ return false;
3029
+ }
3030
+ };
3031
+ const completePortalSession = async (callbackUrl, fetcher = fetch) => {
3032
+ const token = getAuthFragmentToken(callbackUrl);
3033
+ if (!token) return false;
3034
+ try {
3035
+ const callback = new URL(callbackUrl);
3036
+ const response = await fetcher(`${callback.origin}${callback.pathname}`, {
3037
+ method: "POST",
3038
+ headers: {
3039
+ Accept: "application/json",
3040
+ "Content-Type": "application/json"
3041
+ },
3042
+ body: JSON.stringify({ token }),
3043
+ credentials: "include",
3044
+ redirect: "manual"
3045
+ });
3046
+ return response.ok || response.type === "opaqueredirect";
3047
+ } catch {
3048
+ return false;
3049
+ }
3050
+ };
3051
+ const openPortalSession = async ({ client, redirect, allowedOrigins, env = "mainnet", fetcher = fetch, onNavigate }) => {
3052
+ if (!isAllowedRedirectUrl(redirect, allowedOrigins)) return false;
3053
+ const response = await client.auth.createPortalSession(redirect);
3054
+ const callbackUrl = sanitizePortalCallbackUrl(response.ok ? response.data?.url : null, env);
3055
+ if (!callbackUrl) return false;
3056
+ if (!await completePortalSession(callbackUrl, fetcher)) return false;
3057
+ if (!isAllowedRedirectUrl(redirect, allowedOrigins)) return false;
3058
+ if (onNavigate) {
3059
+ onNavigate(redirect);
3060
+ return true;
3061
+ }
3062
+ if (typeof window !== "undefined") {
3063
+ window.location.assign(redirect);
3064
+ return true;
3065
+ }
3066
+ return false;
3067
+ };
3068
+ //#endregion
2726
3069
  //#region src/resources/distribution.ts
2727
3070
  const DISTRIBUTION_URLS = {
2728
3071
  local: "https://raw.githubusercontent.com/JoAiHQ/warps/refs/heads/dev/catalog/devnet/distribution.json",
@@ -2751,4 +3094,4 @@ var DistributionResource = class {
2751
3094
  }
2752
3095
  };
2753
3096
  //#endregion
2754
- export { AgentsResource, AlertsResource, ApiTokensResource, AppointmentsResource, AuthResource, BillingAddressesResource, BillingResource, BlueprintsResource, CachedHttpService, CampaignsResource, CardsResource, CartsResource, ChangelogResource, CharactersResource, ContactsResource, ContractsResource, DeskResource, DistributionResource, DocumentsResource, ElementsResource, EntitiesResource, FlowsResource, GoalsResource, HooksResource, IngestionsResource, InquiriesResource, IntegrationsResource, IntentsResource, ItemsResource, JoAiClient, KvResource, LinksResource, LoyaltyResource, McpResource, MeetingsResource, MemoriesResource, MessagesResource, MissionsResource, NotificationsResource, OfficeResource, OrdersResource, PersonaResource, ProductsResource, ProjectsResource, RemindersResource, SegmentsResource, ServicesResource, ShortcutsResource, SitesResource, SkillsResource, StatsResource, StoreResource, SubscriptionsResource, SwarmsResource, TagsResource, TasksResource, TeamsResource, UpdatesResource, UpgradesResource, UsersResource, VoiceResource, WalletsResource, WarpsResource, WorkspaceResource, createClient, formatOpeningHours };
3097
+ export { AddressesResource, AgentsResource, AlertsResource, ApiTokensResource, AppointmentsResource, AuthResource, BillingResource, BlueprintsResource, CachedHttpService, CampaignsResource, CardsResource, CartsResource, ChangelogResource, CharactersResource, CheckoutResource, CommerceResource, ContactsResource, ContractsResource, DeskResource, DistributionResource, DocumentsResource, ElementsResource, EntitiesResource, FlowsResource, FulfillmentsResource, GoalsResource, HooksResource, IngestionsResource, InquiriesResource, IntegrationsResource, IntentsResource, ItemsResource, JoAiClient, KvResource, LinksResource, LoyaltyResource, McpResource, MeetingsResource, MemoriesResource, MessagesResource, MissionsResource, NotificationsResource, OfficeResource, OrdersResource, PersonaResource, ProductsResource, ProjectsResource, RemindersResource, ReturnsResource, SegmentsResource, ServicesResource, ShippingResource, ShortcutsResource, SitesResource, SkillsResource, StatsResource, StoreResource, SubscriptionsResource, SwarmsResource, TagsResource, TasksResource, TeamsResource, UpdatesResource, UpgradesResource, UsersResource, VoiceResource, WalletsResource, WarpsResource, WorkspaceResource, completePortalSession, createClient, createGuestCommerceStorage, formatOpeningHours, getAuthFragmentToken, isAllowedRedirectUrl, isPortalCallbackUrl, openPortalSession, sanitizePortalCallbackUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joai/sdk",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "JoAi public API SDK — build with your AI agents",
5
5
  "license": "MIT",
6
6
  "type": "module",