@sneat/extension-yardius-contract 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import type { Observable } from 'rxjs';
3
+ export type SpaceFriendshipRole = 'friend' | 'neighbour';
4
+ export interface ICreateFriendshipInviteRequest {
5
+ readonly spaceID: string;
6
+ readonly role?: SpaceFriendshipRole;
7
+ }
8
+ export interface ICreateFriendshipInviteResponse {
9
+ readonly id: string;
10
+ readonly pin: string;
11
+ }
12
+ export interface IAcceptFriendshipInviteRequest {
13
+ readonly inviteID: string;
14
+ readonly pin: string;
15
+ readonly toSpaceID: string;
16
+ }
17
+ export interface IAcceptFriendshipInviteResponse {
18
+ readonly invitingSpaceID: string;
19
+ readonly toSpaceID: string;
20
+ readonly role: SpaceFriendshipRole;
21
+ }
22
+ export interface IFriendSpace {
23
+ readonly id: string;
24
+ readonly roles: readonly SpaceFriendshipRole[];
25
+ readonly title?: string;
26
+ }
27
+ export interface IListFriendSpacesResponse {
28
+ readonly friendSpaces?: readonly IFriendSpace[];
29
+ }
30
+ export interface IRemoveFriendshipRequest {
31
+ readonly spaceID: string;
32
+ readonly friendSpaceID: string;
33
+ }
34
+ export interface IYardiusFriendshipService {
35
+ createFriendshipInvite(request: ICreateFriendshipInviteRequest): Observable<ICreateFriendshipInviteResponse>;
36
+ acceptFriendshipInvite(request: IAcceptFriendshipInviteRequest): Observable<IAcceptFriendshipInviteResponse>;
37
+ listFriendSpaces(spaceID: string): Observable<IListFriendSpacesResponse>;
38
+ removeFriendship(request: IRemoveFriendshipRequest): Observable<void>;
39
+ }
40
+ export declare const YARDIUS_FRIENDSHIP_SERVICE: InjectionToken<IYardiusFriendshipService>;
41
+ export declare const BEFRIEND_SPACE_PAGE_PATH = "befriend";
42
+ export declare function friendshipInvitePath(inviteID: string, pin: string): string;
@@ -0,0 +1,6 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ export const YARDIUS_FRIENDSHIP_SERVICE = new InjectionToken('YardiusFriendshipService');
3
+ export const BEFRIEND_SPACE_PAGE_PATH = 'befriend';
4
+ export function friendshipInvitePath(inviteID, pin) {
5
+ return `${BEFRIEND_SPACE_PAGE_PATH}?${new URLSearchParams({ id: inviteID, pin }).toString()}`;
6
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './assetus-visibility.js';
2
+ export * from './friendship.js';
2
3
  export * from './listing-visibility.js';
3
4
  export * from './state-transitions.js';
4
5
  export * from './borrow-state.js';
package/dist/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './assetus-visibility.js';
2
+ export * from './friendship.js';
2
3
  export * from './listing-visibility.js';
3
4
  export * from './state-transitions.js';
4
5
  export * from './borrow-state.js';
@@ -2,6 +2,7 @@ import { AssetusVisibility } from './assetus-visibility.js';
2
2
  export declare const LISTING_VISIBILITIES: readonly ["private", "members", "friends"];
3
3
  export type ListingVisibility = (typeof LISTING_VISIBILITIES)[number];
4
4
  export declare const DEFAULT_LISTING_VISIBILITY: ListingVisibility;
5
+ export declare function listingVisibilityLabel(visibility: ListingVisibility): string;
5
6
  export declare const LISTING_VISIBILITY_CEILING: Readonly<Record<AssetusVisibility, readonly ListingVisibility[]>>;
6
7
  export declare function allowedListingVisibilities(assetVisibility: AssetusVisibility): readonly ListingVisibility[];
7
8
  export declare function isListingVisibilityAllowed(assetVisibility: AssetusVisibility, listingVisibility: ListingVisibility): boolean;
@@ -10,6 +10,16 @@ export const LISTING_VISIBILITIES = ['private', 'members', 'friends'];
10
10
  // Per REQ listing-visibility-ceiling: `members` is the default listing
11
11
  // visibility.
12
12
  export const DEFAULT_LISTING_VISIBILITY = 'members';
13
+ export function listingVisibilityLabel(visibility) {
14
+ switch (visibility) {
15
+ case 'private':
16
+ return 'Private';
17
+ case 'members':
18
+ return 'Members';
19
+ case 'friends':
20
+ return 'Friends';
21
+ }
22
+ }
13
23
  // The asset's Assetus visibility is a CEILING on the listing's visibility,
14
24
  // per this exact mapping from REQ listing-visibility-ceiling:
15
25
  //
@@ -1,22 +1,108 @@
1
- import { BorrowState } from './borrow-state.js';
2
- import { GiveawayState } from './giveaway-state.js';
3
- import { ListingVisibility } from './listing-visibility.js';
1
+ import { InjectionToken } from '@angular/core';
2
+ import type { Observable } from 'rxjs';
3
+ import type { BorrowState } from './borrow-state.js';
4
+ import type { GiveawayState } from './giveaway-state.js';
5
+ import type { ListingRequestStatus } from './listing-request.js';
6
+ import type { ListingVisibility } from './listing-visibility.js';
7
+ import type { IGetListingsResponse } from './listings-endpoint.js';
4
8
  export declare const LISTING_TYPES: readonly ["borrow", "giveaway"];
5
9
  export type ListingType = (typeof LISTING_TYPES)[number];
6
10
  export type ListingState = BorrowState | GiveawayState;
7
- interface IListingBase {
8
- readonly id: string;
9
- readonly spaceID: string;
11
+ export declare function isOpenListingState(state: ListingState): boolean;
12
+ export declare function listingTypeLabel(type: ListingType): string;
13
+ export declare function listingStateLabel(state: ListingState): string;
14
+ export declare function listingRequestStatusLabel(status: ListingRequestStatus): string;
15
+ export interface IListingDbo {
10
16
  readonly assetID: string;
17
+ readonly type: ListingType;
18
+ readonly state: ListingState;
11
19
  readonly visibility: ListingVisibility;
20
+ readonly createdAt?: string;
21
+ readonly createdBy?: string;
12
22
  }
13
- export interface IBorrowListingDto extends IListingBase {
23
+ interface IListingIdentity {
24
+ readonly id: string;
25
+ readonly spaceID: string;
26
+ }
27
+ export interface IBorrowListingDto extends IListingDbo, IListingIdentity {
14
28
  readonly type: 'borrow';
15
29
  readonly state: BorrowState;
16
30
  }
17
- export interface IGiveawayListingDto extends IListingBase {
31
+ export interface IGiveawayListingDto extends IListingDbo, IListingIdentity {
18
32
  readonly type: 'giveaway';
19
33
  readonly state: GiveawayState;
20
34
  }
21
35
  export type IListingDto = IBorrowListingDto | IGiveawayListingDto;
36
+ export interface IPublishListingRequest {
37
+ readonly spaceID: string;
38
+ readonly assetID: string;
39
+ readonly type: ListingType;
40
+ readonly visibility?: ListingVisibility;
41
+ }
42
+ export interface IListingActionResponse {
43
+ readonly id: string;
44
+ readonly listing: IListingDbo;
45
+ }
46
+ export interface IListingActionRequest {
47
+ readonly spaceID: string;
48
+ readonly listingID: string;
49
+ }
50
+ export interface IListingRequestActionRequest extends IListingActionRequest {
51
+ readonly requestID: string;
52
+ }
53
+ export interface IApproveRequestResponse extends IListingActionResponse {
54
+ readonly declinedRequestIDs?: readonly string[];
55
+ }
56
+ export interface IRequestToBorrowRequest {
57
+ readonly spaceID: string;
58
+ readonly ownerSpaceID: string;
59
+ readonly listingID: string;
60
+ }
61
+ export interface IWithdrawRequestRequest extends IRequestToBorrowRequest {
62
+ readonly requestID: string;
63
+ }
64
+ export type AvailableListingSource = 'member' | 'friend';
65
+ export interface IAvailableListingDto {
66
+ readonly spaceID: string;
67
+ readonly spaceTitle?: string;
68
+ readonly listingID: string;
69
+ readonly assetID: string;
70
+ readonly type: ListingType;
71
+ readonly state: ListingState;
72
+ readonly visibility: ListingVisibility;
73
+ readonly source: AvailableListingSource;
74
+ }
75
+ export interface IMyRequestDto {
76
+ readonly id: string;
77
+ readonly ownerSpaceID: string;
78
+ readonly ownerSpaceTitle?: string;
79
+ readonly listingID: string;
80
+ readonly assetID: string;
81
+ readonly type: ListingType;
82
+ readonly status: ListingRequestStatus;
83
+ readonly createdAt: string;
84
+ }
85
+ export interface IGetMyRequestsResponse {
86
+ readonly requests: readonly IMyRequestDto[];
87
+ }
88
+ export interface IGetListingResult {
89
+ readonly listing?: IListingDto;
90
+ readonly requests?: readonly import('./listing-request.js').IListingRequestDto[];
91
+ }
92
+ export interface IYardiusListingService {
93
+ publishListing(request: IPublishListingRequest): Observable<IListingActionResponse>;
94
+ cancelListing(request: IListingActionRequest): Observable<IListingActionResponse>;
95
+ requestToBorrow(request: IRequestToBorrowRequest): Observable<IListingActionResponse>;
96
+ claimListing(request: IRequestToBorrowRequest): Observable<IListingActionResponse>;
97
+ withdrawRequest(request: IWithdrawRequestRequest): Observable<IListingActionResponse>;
98
+ approveRequest(request: IListingRequestActionRequest): Observable<IApproveRequestResponse>;
99
+ declineRequest(request: IListingRequestActionRequest): Observable<IListingActionResponse>;
100
+ confirmHandover(request: IListingActionRequest): Observable<IListingActionResponse>;
101
+ confirmReturn(request: IListingActionRequest): Observable<IListingActionResponse>;
102
+ getAvailableListings(): Observable<IGetListingsResponse>;
103
+ getOurListings(spaceID: string): Observable<readonly IListingDto[]>;
104
+ getListing(spaceID: string, listingID: string): Observable<IGetListingResult>;
105
+ getMyRequests(): Observable<IGetMyRequestsResponse>;
106
+ }
107
+ export declare const YARDIUS_LISTING_SERVICE: InjectionToken<IYardiusListingService>;
22
108
  export {};
@@ -1,3 +1,15 @@
1
- // A Listing's transaction type, per REQ publish-listing: exactly `borrow` or
2
- // `giveaway`. Sell / swap / reserve are explicitly out of MVP scope.
1
+ import { InjectionToken } from '@angular/core';
3
2
  export const LISTING_TYPES = ['borrow', 'giveaway'];
3
+ export function isOpenListingState(state) {
4
+ return state !== 'closed';
5
+ }
6
+ export function listingTypeLabel(type) {
7
+ return type === 'borrow' ? 'Borrow' : 'Give away';
8
+ }
9
+ export function listingStateLabel(state) {
10
+ return state.charAt(0).toUpperCase() + state.slice(1);
11
+ }
12
+ export function listingRequestStatusLabel(status) {
13
+ return status.charAt(0).toUpperCase() + status.slice(1);
14
+ }
15
+ export const YARDIUS_LISTING_SERVICE = new InjectionToken('YardiusListingService');
@@ -1,4 +1,4 @@
1
- import { IListingDto } from './listing.js';
1
+ import type { IAvailableListingDto, IListingDto } from './listing.js';
2
2
  export type IGetListingsRequest = Record<string, never>;
3
3
  export type ListingsGroupReason = 'member' | 'friend';
4
4
  export interface IListingsSpaceGroup {
@@ -8,5 +8,8 @@ export interface IListingsSpaceGroup {
8
8
  readonly listings: readonly IListingDto[];
9
9
  }
10
10
  export interface IGetListingsResponse {
11
- readonly groups: readonly IListingsSpaceGroup[];
11
+ /** Grouped response used by the relationship-first listing endpoint. */
12
+ readonly groups?: readonly IListingsSpaceGroup[];
13
+ /** Flat response used by the existing `get_available_listings` facade. */
14
+ readonly listings?: readonly IAvailableListingDto[];
12
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sneat/extension-yardius-contract",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Frozen cross-repo contract surface (shared DTOs, consts, briefs) for the yardius Sneat extension",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,12 +23,18 @@
23
23
  "access": "public"
24
24
  },
25
25
  "devDependencies": {
26
+ "@angular/core": "^21.0.0",
26
27
  "@nx/js": "22.7.5",
27
28
  "nx": "22.7.5",
29
+ "rxjs": "^7.0.0",
28
30
  "typescript": "~5.9.3",
29
31
  "vite": "^7.2.7",
30
32
  "vitest": "4.0.9"
31
33
  },
34
+ "peerDependencies": {
35
+ "@angular/core": "^21.0.0",
36
+ "rxjs": "^7.0.0"
37
+ },
32
38
  "scripts": {
33
39
  "build": "tsc -p tsconfig.build.json",
34
40
  "typecheck": "tsc --noEmit",