@oxyhq/core 19.1.2 → 20.1.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.
- package/LICENSE +202 -0
- package/NOTICE +16 -0
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/HttpService.js +23 -18
- package/dist/cjs/i18n/accountCategoryLabels.js +44 -0
- package/dist/cjs/i18n/accountRoleLabels.js +27 -0
- package/dist/cjs/i18n/reputationCategoryLabels.js +20 -0
- package/dist/cjs/i18n/trustTierLabels.js +19 -0
- package/dist/cjs/index.js +19 -9
- package/dist/cjs/mixins/OxyServices.chains.js +73 -0
- package/dist/cjs/mixins/OxyServices.followGraph.js +17 -0
- package/dist/cjs/mixins/OxyServices.store.js +266 -0
- package/dist/cjs/mixins/OxyServices.utility.js +159 -104
- package/dist/cjs/mixins/index.js +7 -0
- package/dist/cjs/server/rateLimit.js +15 -6
- package/dist/cjs/session/accountProjection.js +31 -6
- package/dist/cjs/utils/errorUtils.js +65 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/HttpService.js +24 -19
- package/dist/esm/i18n/accountCategoryLabels.js +37 -0
- package/dist/esm/i18n/accountRoleLabels.js +20 -0
- package/dist/esm/i18n/reputationCategoryLabels.js +13 -0
- package/dist/esm/i18n/trustTierLabels.js +12 -0
- package/dist/esm/index.js +11 -8
- package/dist/esm/mixins/OxyServices.chains.js +70 -0
- package/dist/esm/mixins/OxyServices.followGraph.js +17 -0
- package/dist/esm/mixins/OxyServices.store.js +263 -0
- package/dist/esm/mixins/OxyServices.utility.js +159 -104
- package/dist/esm/mixins/index.js +7 -0
- package/dist/esm/server/rateLimit.js +15 -6
- package/dist/esm/session/accountProjection.js +30 -6
- package/dist/esm/utils/errorUtils.js +63 -1
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/i18n/accountCategoryLabels.d.ts +34 -0
- package/dist/types/i18n/accountRoleLabels.d.ts +10 -0
- package/dist/types/i18n/reputationCategoryLabels.d.ts +10 -0
- package/dist/types/i18n/trustTierLabels.d.ts +9 -0
- package/dist/types/index.d.ts +14 -2
- package/dist/types/mixins/OxyServices.chains.d.ts +156 -0
- package/dist/types/mixins/OxyServices.followGraph.d.ts +13 -0
- package/dist/types/mixins/OxyServices.store.d.ts +334 -0
- package/dist/types/mixins/OxyServices.utility.d.ts +31 -8
- package/dist/types/mixins/index.d.ts +3 -1
- package/dist/types/session/accountProjection.d.ts +20 -4
- package/dist/types/utils/errorUtils.d.ts +67 -0
- package/package.json +7 -6
- package/src/HttpService.ts +29 -22
- package/src/__tests__/parseHttpErrorBody.test.ts +116 -0
- package/src/__tests__/serverValueImportsDeclared.test.ts +7 -0
- package/src/i18n/__tests__/accountCategoryLabels.test.ts +62 -0
- package/src/i18n/__tests__/accountRoleLabels.test.ts +54 -0
- package/src/i18n/__tests__/reputationCategoryLabels.test.ts +56 -0
- package/src/i18n/__tests__/trustTierLabels.test.ts +47 -0
- package/src/i18n/accountCategoryLabels.ts +44 -0
- package/src/i18n/accountRoleLabels.ts +26 -0
- package/src/i18n/reputationCategoryLabels.ts +20 -0
- package/src/i18n/trustTierLabels.ts +18 -0
- package/src/index.ts +43 -6
- package/src/mixins/OxyServices.chains.ts +134 -0
- package/src/mixins/OxyServices.followGraph.ts +24 -0
- package/src/mixins/OxyServices.store.ts +585 -0
- package/src/mixins/OxyServices.utility.ts +161 -108
- package/src/mixins/__tests__/chains.test.ts +113 -0
- package/src/mixins/__tests__/followGraph.test.ts +19 -0
- package/src/mixins/__tests__/store.test.ts +304 -0
- package/src/mixins/__tests__/userTokenAuth.test.ts +746 -0
- package/src/mixins/index.ts +9 -0
- package/src/server/__tests__/rateLimit.test.ts +47 -0
- package/src/server/rateLimit.ts +18 -8
- package/src/session/__tests__/accountProjection.test.ts +98 -0
- package/src/session/accountProjection.ts +37 -6
- package/src/utils/errorUtils.ts +116 -5
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AccountCategoryId } from '@oxyhq/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* Every account category's English name, keyed by its stable id.
|
|
4
|
+
*
|
|
5
|
+
* **The annotation is the point.** The vocabulary lives in `@oxyhq/contracts`
|
|
6
|
+
* and the names live in `locales/en-US.json`, so they are two lists that must
|
|
7
|
+
* agree and nothing but a type can make them. Declaring the JSON node as a
|
|
8
|
+
* TOTAL `Record<AccountCategoryId, string>` turns "somebody added a category at
|
|
9
|
+
* Oxy and nobody wrote its English" into a `TS2741` naming the missing id, at
|
|
10
|
+
* build time, instead of a picker row that paints `accounts.accountCategory.<id>`
|
|
11
|
+
* at a user trying to choose one.
|
|
12
|
+
*
|
|
13
|
+
* That failure is not hypothetical. The screen previously wrote `t(key) || id`,
|
|
14
|
+
* whose author believed an unnamed id would degrade to its raw slug. It cannot:
|
|
15
|
+
* {@link translate} echoes the KEY when it resolves nothing, and a non-empty
|
|
16
|
+
* string is never falsy, so the `|| id` arm was unreachable and the output was
|
|
17
|
+
* the dotted key. A runtime fallback that cannot run is worse than none,
|
|
18
|
+
* because it reads as protection.
|
|
19
|
+
*
|
|
20
|
+
* Totality is over `ACCOUNT_CATEGORY_IDS`, which RETAINS withdrawn ids, so an
|
|
21
|
+
* account still carrying a retired category keeps rendering its name while no
|
|
22
|
+
* picker offers it again. Retired and unknown are different cases: only an id
|
|
23
|
+
* outside the union is unnameable, which is why this is keyed by
|
|
24
|
+
* `AccountCategoryId` and not by `string`.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Module-scoped, NOT re-exported from the package index: the annotation is the
|
|
28
|
+
* whole job, and it does that job without being public API. It carries no
|
|
29
|
+
* `Object.freeze` and no `Readonly<>` for the same reason — those existed only
|
|
30
|
+
* to make an exported reference safe from a consumer's stray write, and there
|
|
31
|
+
* is no such consumer. Exported from the MODULE so its own test can name it.
|
|
32
|
+
*/
|
|
33
|
+
export declare const EN_ACCOUNT_CATEGORY_LABELS: Record<AccountCategoryId, string>;
|
|
34
|
+
export declare function accountCategoryLabel(locale: string | undefined, id: AccountCategoryId): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AccountRole } from '../mixins/OxyServices.accounts';
|
|
2
|
+
/**
|
|
3
|
+
* Every account member role's English name, keyed by its stable id.
|
|
4
|
+
*
|
|
5
|
+
* Totality is over the closed `AccountRole` union so a new role without an
|
|
6
|
+
* English label is a build error, not a members row that paints
|
|
7
|
+
* `accounts.roles.<role>.label`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const EN_ACCOUNT_ROLE_LABELS: Record<AccountRole, string>;
|
|
10
|
+
export declare function accountRoleLabel(locale: string | undefined, role: AccountRole): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReputationCategory } from '@oxyhq/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* Every reputation rule category's English name, keyed by its stable id.
|
|
4
|
+
*
|
|
5
|
+
* Totality is over `REPUTATION_CATEGORIES` from `@oxyhq/contracts` so a new
|
|
6
|
+
* category added server-side without an English label is a build error, not a
|
|
7
|
+
* Trust Rules section title that paints `trust.rules.categories.<id>`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const EN_REPUTATION_CATEGORY_LABELS: Record<ReputationCategory, string>;
|
|
10
|
+
export declare function reputationCategoryLabel(locale: string | undefined, id: ReputationCategory): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TrustTier } from '@oxyhq/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* Every trust tier's English name, keyed by its stable id.
|
|
4
|
+
*
|
|
5
|
+
* Totality is over `TRUST_TIERS` from `@oxyhq/contracts` so a new tier without
|
|
6
|
+
* an English label is a build error, not a chip that paints `trust.tiers.<id>`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const EN_TRUST_TIER_LABELS: Record<TrustTier, string>;
|
|
9
|
+
export declare function trustTierLabel(locale: string | undefined, tier: TrustTier): string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export type { CanonicalUserHandleInput, UserHandleInput } from './utils/userHand
|
|
|
39
39
|
export { normalizeProfileLinks } from './utils/profileLinks';
|
|
40
40
|
export type { ProfileLink, ProfileLinkMetadata } from './utils/profileLinks';
|
|
41
41
|
export type { PublicApplication, ConnectedApp, } from './mixins/OxyServices.connectedApps';
|
|
42
|
+
export type { StoreCategory, StoreRating, StoreListingSummary, StoreListingDetail, StoreScreenshot, StoreScreenshotPlatform, StoreReview, StoreOwnReview, WriteStoreReviewInput, StoreListingStatus, PublisherListing, WriteListingInput, AddScreenshotInput, UpdateScreenshotInput, StorePage, StorePageOptions, StoreReviewsOptions, } from './mixins/OxyServices.store';
|
|
42
43
|
export type { AccountKind, AccountCategoryId, AccountRelationship, AccountRole, AccountMemberStatus, AccountMemberSource, AccountMember, AccountNode, AccountCredentialType, AccountCredentialEnvironment, AccountCredentialStatus, AccountCredential, AccountCredentialWithSecret, RotateAccountCredentialResult, ListAccountsOptions, CreateAccountInput, UpdateAccountInput, ProvisionChannelInput, ProvisionChannelMemberInput, ProvisionChannelResult, InviteAccountMemberInput, UpdateAccountMemberInput, TransferAccountOwnershipInput, CreateAccountCredentialInput, AccountSuccessResult, SwitchAccountResult, Application, ApplicationType, ApplicationStatus, ApplicationCredential, ApplicationCredentialType, ApplicationCredentialStatus, ApplicationEnvironment, CreateApplicationInput, UpdateApplicationInput, CreateApplicationCredentialInput, ApplicationCredentialWithSecret, RotateApplicationCredentialResult, ApplicationUsagePeriod, ApplicationUsageSummary, ApplicationUsageByDay, ApplicationUsageByEndpoint, ApplicationUsageStats, } from './mixins/OxyServices.accounts';
|
|
43
44
|
export { ACCOUNT_CATEGORY_IDS, MAX_ACCOUNT_CATEGORIES, SELECTABLE_ACCOUNT_CATEGORY_IDS, isSelectableAccountCategoryId, kindAcceptsAccountCategories, } from './mixins/OxyServices.accounts';
|
|
44
45
|
export { buildUserDid } from './mixins/OxyServices.identity';
|
|
@@ -46,6 +47,12 @@ export type { IdentityRecordType, UnlinkableAuthMethodType, LinkAuthMethodResult
|
|
|
46
47
|
export { parseIdPayload, parseAttestPayload, verifyPublicCardAttestation, } from './mixins/OxyServices.civic';
|
|
47
48
|
export type { CivicCardResult, IdCardRef, AttestQrPayload, ParsedAttestPayload, SubmitRealLifeAttestationInput, DenyValidationResult, VouchForPersonInput, WithdrawVouchResult, IssueCredentialInput, RevokeCredentialResult, } from './mixins/OxyServices.civic';
|
|
48
49
|
export type { UserNodeStatus, UserNodeMode, UserNodeController, UserNodeLivenessStatus, RegisterNodeInput, RemoveNodeResult } from './mixins/OxyServices.nodes';
|
|
50
|
+
/**
|
|
51
|
+
* Chains — the shared per-person record log. `ChainRecord` is generic over the
|
|
52
|
+
* app's own lexicon payload, so a consumer types its records without Oxy
|
|
53
|
+
* knowing any app's schema.
|
|
54
|
+
*/
|
|
55
|
+
export type { ChainRecord, ChainRecordPage, AppendedChainRecord } from './mixins/OxyServices.chains';
|
|
49
56
|
export { SessionSyncRequiredError, AuthenticationFailedError, ensureValidToken, isAuthenticationError, withAuthErrorHandling, authenticatedApiCall, } from './utils/authHelpers';
|
|
50
57
|
export type { HandleApiErrorOptions } from './utils/authHelpers';
|
|
51
58
|
export { mergeSessions, normalizeAndSortSessions, sessionsArraysEqual, } from './utils/sessionUtils';
|
|
@@ -79,9 +86,14 @@ export { HttpStatus, getErrorStatus, getErrorMessage, isAlreadyRegisteredError,
|
|
|
79
86
|
export { DEFAULT_CIRCUIT_BREAKER_CONFIG, createCircuitBreakerState, calculateBackoffInterval, recordFailure, recordSuccess, shouldAllowRequest, delay, withRetry, } from './shared/utils/networkUtils';
|
|
80
87
|
export type { CircuitBreakerState, CircuitBreakerConfig } from './shared/utils/networkUtils';
|
|
81
88
|
export { translate } from './i18n';
|
|
89
|
+
export { accountCategoryLabel } from './i18n/accountCategoryLabels';
|
|
90
|
+
export { accountRoleLabel } from './i18n/accountRoleLabels';
|
|
91
|
+
export { reputationCategoryLabel } from './i18n/reputationCategoryLabels';
|
|
92
|
+
export { trustTierLabel } from './i18n/trustTierLabels';
|
|
82
93
|
export { buildQueryParams, buildSearchParams, buildUrl, buildPaginationParams, safeJsonParse, } from './utils/apiUtils';
|
|
83
94
|
export type { PaginationParams, FollowGraphParams, FollowGraphSort, ApiResponse, ErrorResponse, } from './utils/apiUtils';
|
|
84
|
-
export { ErrorCodes, createApiError, handleHttpError, validateRequiredFields, } from './utils/errorUtils';
|
|
95
|
+
export { ErrorCodes, createApiError, handleHttpError, isHttpRequestError, parseHttpErrorBody, validateRequiredFields, } from './utils/errorUtils';
|
|
96
|
+
export type { HttpRequestError, ParsedHttpErrorBody } from './utils/errorUtils';
|
|
85
97
|
export { retryAsync } from './utils/asyncUtils';
|
|
86
98
|
export { EMAIL_REGEX, USERNAME_REGEX, PASSWORD_REGEX, MAX_DISPLAY_NAME_LENGTH, DISPLAY_NAME_INVALID_MESSAGE, isValidEmail, isValidUsername, isValidPassword, isValidDisplayName, DISPLAY_NAME_ALLOWED_SCRIPTS, DISPLAY_NAME_DISALLOWED_SOURCE, DISPLAY_NAME_ORPHANED_MARK_SOURCE, DISPLAY_NAME_UNFLANKED_SEPARATOR_SOURCE, isRequiredString, isRequiredNumber, isRequiredBoolean, isValidArray, isValidObject, isValidUUID, isValidURL, isValidDate, isValidFileSize, isValidFileType, sanitizeString, sanitizeHTML, isValidObjectId, validateAndSanitizeUserInput, } from './utils/validationUtils';
|
|
87
99
|
export { normalizeInlineText, normalizeMultilineText, } from './utils/textNormalization';
|
|
@@ -104,7 +116,7 @@ export type { SocketIOFactory, MinimalSocket } from './session/socketLoader';
|
|
|
104
116
|
export { createSessionClientHost } from './session/sessionClientHost';
|
|
105
117
|
export { createSessionClient } from './session/createSessionClient';
|
|
106
118
|
export { deviceStateToClientSessions, activeSessionIdOf, activeUserOf, accountIdsOf, } from './session/projectSessionState';
|
|
107
|
-
export { isSwitchTargetAccount, projectSwitchableAccounts, switchableAccountIds, } from './session/accountProjection';
|
|
119
|
+
export { isSwitchTargetAccount, canSwitchIntoAccount, projectSwitchableAccounts, switchableAccountIds, } from './session/accountProjection';
|
|
108
120
|
export type { SwitchableAccount, SwitchableAccountUser, ProjectSwitchableAccountsInput, } from './session/accountProjection';
|
|
109
121
|
export { AccountDialogController, createAccountDialogController, } from './session/accountDialogController';
|
|
110
122
|
export type { AccountDialogControllerOptions, AccountDialogSnapshot, AccountDialogView, CommonsAvailability, PopupWindowHandle, SignInFlowPhase, SignInFlowState, SignInProgress, } from './session/accountDialogController';
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chains — the shared record log every Oxy app reads and writes.
|
|
3
|
+
*
|
|
4
|
+
* A person has ONE chain. An app appends its own records to it and projects its
|
|
5
|
+
* feeds from what it reads back, instead of keeping a private copy of the same
|
|
6
|
+
* person's activity. This mixin is the client half of `/chains` in oxy-api, and
|
|
7
|
+
* it exists so that adopting the chain costs an app no HTTP of its own — the
|
|
8
|
+
* whole point of the shared substrate is that the second app writes less code
|
|
9
|
+
* than the first, not the same amount in a different file.
|
|
10
|
+
*
|
|
11
|
+
* ## Both calls are SERVICE-authenticated
|
|
12
|
+
*
|
|
13
|
+
* They go through `makeServiceRequest`, so they only work on a backend that has
|
|
14
|
+
* called `configureServiceAuth()`. That is not an accident of implementation: an
|
|
15
|
+
* append writes to someone else's chain and a read spans many subjects, so
|
|
16
|
+
* neither belongs in a browser holding a user session. A frontend that needs
|
|
17
|
+
* this asks its own backend.
|
|
18
|
+
*
|
|
19
|
+
* The authority is checked server-side and cannot be talked out of from here:
|
|
20
|
+
* `chains:write` plus the application's own `chainNamespaces` for an append,
|
|
21
|
+
* `chains:read` plus the public-collection policy for a read. A call that
|
|
22
|
+
* violates either gets a 403 or an empty page — this client adds no
|
|
23
|
+
* pre-validation that could drift from the server's answer.
|
|
24
|
+
*/
|
|
25
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
26
|
+
/** A signed record as it comes back from a read. */
|
|
27
|
+
export interface ChainRecord<TRecord = Record<string, unknown>> {
|
|
28
|
+
recordId: string;
|
|
29
|
+
/** The subject whose chain it is — the person the record is about. */
|
|
30
|
+
oxyUserId: string;
|
|
31
|
+
/** The lexicon NSID, e.g. `app.mention.feed.post`. */
|
|
32
|
+
collection: string;
|
|
33
|
+
envelope: {
|
|
34
|
+
version: number;
|
|
35
|
+
type: string;
|
|
36
|
+
subject: string;
|
|
37
|
+
issuer: string;
|
|
38
|
+
record: TRecord;
|
|
39
|
+
issuedAt: number;
|
|
40
|
+
seq?: number;
|
|
41
|
+
prev?: string | null;
|
|
42
|
+
collection?: string;
|
|
43
|
+
rkey?: string;
|
|
44
|
+
publicKey: string;
|
|
45
|
+
alg: string;
|
|
46
|
+
signature: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** One page of a multi-subject read. */
|
|
50
|
+
export interface ChainRecordPage<TRecord = Record<string, unknown>> {
|
|
51
|
+
records: ChainRecord<TRecord>[];
|
|
52
|
+
/**
|
|
53
|
+
* Opaque. Hand it back as `since` to continue; `null` at the end of the
|
|
54
|
+
* stream as of this snapshot. Never construct one.
|
|
55
|
+
*/
|
|
56
|
+
nextCursor: string | null;
|
|
57
|
+
}
|
|
58
|
+
/** What an append returns once the record is on the chain. */
|
|
59
|
+
export interface AppendedChainRecord {
|
|
60
|
+
recordId: string;
|
|
61
|
+
seq: number;
|
|
62
|
+
envelope: ChainRecord['envelope'];
|
|
63
|
+
verified: boolean;
|
|
64
|
+
}
|
|
65
|
+
export declare function OxyServicesChainsMixin<T extends typeof OxyServicesBase>(Base: T): {
|
|
66
|
+
new (...args: any[]): {
|
|
67
|
+
/** Service-token request, implemented by the auth mixin earlier in the pipeline. */
|
|
68
|
+
makeServiceRequest: <R = unknown>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", url: string, data?: unknown, userId?: string) => Promise<R>;
|
|
69
|
+
/**
|
|
70
|
+
* Append a record to `oxyUserId`'s chain under `collection`/`rkey`.
|
|
71
|
+
*
|
|
72
|
+
* Oxy issues and signs it; the calling app never holds a chain signing key.
|
|
73
|
+
* `rkey` is the app's own id for the thing — reusing it later supersedes the
|
|
74
|
+
* earlier record for that key, which is how an edit works.
|
|
75
|
+
*
|
|
76
|
+
* Requires the `chains:write` scope AND `collection` falling under one of
|
|
77
|
+
* this application's granted `chainNamespaces`. Both are enforced by the
|
|
78
|
+
* server; a violation throws with a 403.
|
|
79
|
+
*/
|
|
80
|
+
appendChainRecord(params: {
|
|
81
|
+
oxyUserId: string;
|
|
82
|
+
collection: string;
|
|
83
|
+
rkey: string;
|
|
84
|
+
record: Record<string, unknown>;
|
|
85
|
+
}): Promise<AppendedChainRecord>;
|
|
86
|
+
/**
|
|
87
|
+
* Records published by any of `oxyUserIds` under any of `collections`,
|
|
88
|
+
* oldest first — the read a cross-app feed is projected from.
|
|
89
|
+
*
|
|
90
|
+
* Only collections Oxy declares PUBLIC come back, whatever is asked for; a
|
|
91
|
+
* private one yields nothing rather than an error.
|
|
92
|
+
*
|
|
93
|
+
* **Re-poll from slightly BEFORE your last cursor and dedupe by
|
|
94
|
+
* `recordId`.** The chain's pagination axis is a transaction-start
|
|
95
|
+
* timestamp, so a record can commit behind a cursor that already passed it.
|
|
96
|
+
* Re-delivering one costs bytes; skipping one costs a record that never
|
|
97
|
+
* appears. Projections are expected to be idempotent for exactly this
|
|
98
|
+
* reason.
|
|
99
|
+
*/
|
|
100
|
+
readChainRecords<TRecord = Record<string, unknown>>(params: {
|
|
101
|
+
oxyUserIds: readonly string[];
|
|
102
|
+
collections: readonly string[];
|
|
103
|
+
since?: string | null;
|
|
104
|
+
limit?: number;
|
|
105
|
+
}): Promise<ChainRecordPage<TRecord>>;
|
|
106
|
+
httpService: import("../HttpService").HttpService;
|
|
107
|
+
cloudURL: string;
|
|
108
|
+
config: import("../OxyServices.base").OxyConfig;
|
|
109
|
+
__resetTokensForTests(): void;
|
|
110
|
+
makeRequest<T_1>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", url: string, data?: any, options?: import("../HttpService").RequestOptions): Promise<T_1>;
|
|
111
|
+
getBaseURL(): string;
|
|
112
|
+
getClient(): import("../HttpService").HttpService;
|
|
113
|
+
createLinkedClient(config: import("../OxyServices.base").OxyConfig): import("..").LinkedHttpClient;
|
|
114
|
+
getMetrics(): {
|
|
115
|
+
totalRequests: number;
|
|
116
|
+
successfulRequests: number;
|
|
117
|
+
failedRequests: number;
|
|
118
|
+
cacheHits: number;
|
|
119
|
+
cacheMisses: number;
|
|
120
|
+
averageResponseTime: number;
|
|
121
|
+
};
|
|
122
|
+
clearCache(): void;
|
|
123
|
+
clearCacheEntry(key: string): void;
|
|
124
|
+
clearCacheByPrefix(prefix: string): number;
|
|
125
|
+
getCacheStats(): {
|
|
126
|
+
size: number;
|
|
127
|
+
hits: number;
|
|
128
|
+
misses: number;
|
|
129
|
+
hitRate: number;
|
|
130
|
+
};
|
|
131
|
+
getCloudURL(): string;
|
|
132
|
+
setTokens(accessToken: string): void;
|
|
133
|
+
clearTokens(): void;
|
|
134
|
+
onTokensChanged(listener: (accessToken: string | null) => void): () => void;
|
|
135
|
+
_cachedUserId: string | null | undefined;
|
|
136
|
+
_cachedAccessToken: string | null;
|
|
137
|
+
getCurrentUserId(): string | null;
|
|
138
|
+
hasValidToken(): boolean;
|
|
139
|
+
getAccessToken(): string | null;
|
|
140
|
+
getAccessTokenExpiry(): number | null;
|
|
141
|
+
waitForAuth(timeoutMs?: number): Promise<boolean>;
|
|
142
|
+
withAuthRetry<T_1>(operation: () => Promise<T_1>, operationName: string, options?: {
|
|
143
|
+
maxRetries?: number;
|
|
144
|
+
retryDelay?: number;
|
|
145
|
+
authTimeoutMs?: number;
|
|
146
|
+
}): Promise<T_1>;
|
|
147
|
+
validate(): Promise<boolean>;
|
|
148
|
+
handleError(error: unknown): Error;
|
|
149
|
+
healthCheck(): Promise<{
|
|
150
|
+
status: string;
|
|
151
|
+
users?: number;
|
|
152
|
+
timestamp?: string;
|
|
153
|
+
[key: string]: any;
|
|
154
|
+
}>;
|
|
155
|
+
};
|
|
156
|
+
} & T;
|
|
@@ -122,6 +122,19 @@ export declare function OxyServicesFollowGraphMixin<T extends typeof OxyServices
|
|
|
122
122
|
namespace: string;
|
|
123
123
|
created: boolean;
|
|
124
124
|
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Release a namespace the calling application holds, when nothing is
|
|
127
|
+
registered inside it yet.
|
|
128
|
+
*
|
|
129
|
+
* Idempotent when the namespace is already unowned (`released: false`).
|
|
130
|
+
* Exists because claims are first-come and registration runs on boot — a
|
|
131
|
+
* development build with the wrong client id can bind a name permanently
|
|
132
|
+
* unless the holder can give it back.
|
|
133
|
+
*/
|
|
134
|
+
releaseFollowNamespace(namespace: string): Promise<{
|
|
135
|
+
namespace: string;
|
|
136
|
+
released: boolean;
|
|
137
|
+
}>;
|
|
125
138
|
/**
|
|
126
139
|
* Declare what following a kind of thing MEANS: the verb clients render,
|
|
127
140
|
* whether reverse lookups are public, whether it federates.
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App Store Methods Mixin
|
|
3
|
+
*
|
|
4
|
+
* The client surface for the Oxy app store: the public storefront (`/store`),
|
|
5
|
+
* the reviews people write there, and the listing a publisher edits for an
|
|
6
|
+
* application they own (`/applications/:appId/listing`).
|
|
7
|
+
*
|
|
8
|
+
* Deliberately separate from `OxyServices.accounts.ts` even though the
|
|
9
|
+
* publisher's routes hang off an application, for the same reason
|
|
10
|
+
* `OxyServices.connectedApps.ts` is: those mixins answer "may this program act
|
|
11
|
+
* for this person?", and this one answers "should this person choose it?". Turn
|
|
12
|
+
* the store off and OAuth still works — which is the test that says the store is
|
|
13
|
+
* a module over the platform rather than part of it.
|
|
14
|
+
*
|
|
15
|
+
* The two prefixes are one domain. A listing IS the store's page for an
|
|
16
|
+
* application, so both halves of its life belong to the same surface; the API
|
|
17
|
+
* puts the publisher's half beside credentials and webhooks because that is
|
|
18
|
+
* where the permission that guards it already lives, and reusing that permission
|
|
19
|
+
* is what stops a store page becoming a second, weaker way to act for somebody's
|
|
20
|
+
* app.
|
|
21
|
+
*
|
|
22
|
+
* ## What is NOT duplicated here
|
|
23
|
+
*
|
|
24
|
+
* A listing carries no name, icon or legal links: `applications` already holds
|
|
25
|
+
* them and the storefront joins them in. A rating is computed from the visible
|
|
26
|
+
* reviews on every read rather than stored, so a hidden review stops counting
|
|
27
|
+
* the moment it is hidden. Reference listings by their `slug` in the storefront
|
|
28
|
+
* (it is what every link carries) and applications by their `_id` in the
|
|
29
|
+
* publisher's calls.
|
|
30
|
+
*/
|
|
31
|
+
import type { OxyServicesBase } from '../OxyServices.base';
|
|
32
|
+
/** A shelf on the storefront. */
|
|
33
|
+
export interface StoreCategory {
|
|
34
|
+
/** The public identifier a link carries. Never the row id. */
|
|
35
|
+
slug: string;
|
|
36
|
+
/** What a person reads. Never derived from the slug at render time. */
|
|
37
|
+
label: string;
|
|
38
|
+
description?: string | null;
|
|
39
|
+
}
|
|
40
|
+
/** The rating of an app, computed from its visible reviews. */
|
|
41
|
+
export interface StoreRating {
|
|
42
|
+
/** Rounded to one decimal, or `null` when nobody has reviewed it — never 0. */
|
|
43
|
+
average: number | null;
|
|
44
|
+
count: number;
|
|
45
|
+
}
|
|
46
|
+
/** An app as a card on the storefront: what a listing page needs, and no more. */
|
|
47
|
+
export interface StoreListingSummary {
|
|
48
|
+
slug: string;
|
|
49
|
+
/** From the APPLICATION, joined in — the listing keeps no copy. */
|
|
50
|
+
name: string;
|
|
51
|
+
tagline: string | null;
|
|
52
|
+
/** A file id for the app's icon, resolved through the usual image resolver. */
|
|
53
|
+
icon: string | null;
|
|
54
|
+
category: StoreCategory | null;
|
|
55
|
+
rating: StoreRating;
|
|
56
|
+
}
|
|
57
|
+
/** A store page in full. */
|
|
58
|
+
export interface StoreListingDetail extends StoreListingSummary {
|
|
59
|
+
description: string | null;
|
|
60
|
+
/** These four come from the application; the consent screen shows the same values. */
|
|
61
|
+
websiteUrl: string | null;
|
|
62
|
+
privacyPolicyUrl: string | null;
|
|
63
|
+
termsUrl: string | null;
|
|
64
|
+
supportUrl: string | null;
|
|
65
|
+
supportEmail: string | null;
|
|
66
|
+
publishedAt: string | null;
|
|
67
|
+
screenshots: StoreScreenshot[];
|
|
68
|
+
/** How many visible reviews gave each of 1..5. Absent keys are zero. */
|
|
69
|
+
ratingBreakdown: Record<number, number>;
|
|
70
|
+
}
|
|
71
|
+
/** Which frame a screenshot was taken in. The store groups by it on the page. */
|
|
72
|
+
export type StoreScreenshotPlatform = 'phone' | 'tablet' | 'desktop' | 'web';
|
|
73
|
+
export interface StoreScreenshot {
|
|
74
|
+
id: string;
|
|
75
|
+
/** The uploaded asset's file id. Upload through the assets surface first. */
|
|
76
|
+
fileId: string;
|
|
77
|
+
platform: StoreScreenshotPlatform;
|
|
78
|
+
caption: string | null;
|
|
79
|
+
position: number;
|
|
80
|
+
}
|
|
81
|
+
/** Somebody's review, as it appears on a store page. */
|
|
82
|
+
export interface StoreReview {
|
|
83
|
+
id: string;
|
|
84
|
+
rating: number;
|
|
85
|
+
title: string | null;
|
|
86
|
+
body: string | null;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
author: {
|
|
89
|
+
id: string;
|
|
90
|
+
username: string | null;
|
|
91
|
+
};
|
|
92
|
+
/** The publisher's answer, when there is one. */
|
|
93
|
+
reply: {
|
|
94
|
+
body: string;
|
|
95
|
+
createdAt: string;
|
|
96
|
+
} | null;
|
|
97
|
+
/**
|
|
98
|
+
* Whether this author has authorized the application, read from their grant
|
|
99
|
+
* at request time rather than stored on the review.
|
|
100
|
+
*
|
|
101
|
+
* It is not a claim that they still use it, and it is `false` for a
|
|
102
|
+
* first-party app nobody has to consent to — so render its absence as nothing
|
|
103
|
+
* at all rather than as a demotion.
|
|
104
|
+
*/
|
|
105
|
+
authorUsesApp: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** A review as its own author sees it, whatever its moderation state. */
|
|
108
|
+
export interface StoreOwnReview {
|
|
109
|
+
id: string;
|
|
110
|
+
rating: number;
|
|
111
|
+
title: string | null;
|
|
112
|
+
body: string | null;
|
|
113
|
+
/** An author is told when their review is hidden; the public list is not. */
|
|
114
|
+
status: 'visible' | 'hidden' | 'flagged' | 'removed';
|
|
115
|
+
createdAt: string;
|
|
116
|
+
updatedAt: string;
|
|
117
|
+
}
|
|
118
|
+
/** What a person submits about an app. One review each; writing again replaces it. */
|
|
119
|
+
export interface WriteStoreReviewInput {
|
|
120
|
+
/** Whole stars, 1 to 5. The database enforces the bound too. */
|
|
121
|
+
rating: number;
|
|
122
|
+
title?: string | null;
|
|
123
|
+
body?: string | null;
|
|
124
|
+
}
|
|
125
|
+
/** Where a listing is in its life. `pending_review` is the STORE's review of the page. */
|
|
126
|
+
export type StoreListingStatus = 'draft' | 'pending_review' | 'published' | 'rejected';
|
|
127
|
+
/** A listing as its publisher sees it: whatever state it is in. */
|
|
128
|
+
export interface PublisherListing {
|
|
129
|
+
id: string;
|
|
130
|
+
applicationId: string;
|
|
131
|
+
slug: string;
|
|
132
|
+
tagline: string | null;
|
|
133
|
+
description: string | null;
|
|
134
|
+
category: StoreCategory | null;
|
|
135
|
+
supportUrl: string | null;
|
|
136
|
+
supportEmail: string | null;
|
|
137
|
+
status: StoreListingStatus;
|
|
138
|
+
publishedAt: string | null;
|
|
139
|
+
createdAt: string;
|
|
140
|
+
updatedAt: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The whole page, not a patch: sending everything is what makes "clear the
|
|
144
|
+
* tagline" expressible at all.
|
|
145
|
+
*
|
|
146
|
+
* `status` is absent on purpose. Publishing is the store's decision and has its
|
|
147
|
+
* own calls, so a publisher cannot publish themselves by putting a field in a
|
|
148
|
+
* body.
|
|
149
|
+
*/
|
|
150
|
+
export interface WriteListingInput {
|
|
151
|
+
/** Lowercase letters, digits and single hyphens. What every link carries. */
|
|
152
|
+
slug: string;
|
|
153
|
+
tagline?: string | null;
|
|
154
|
+
description?: string | null;
|
|
155
|
+
/** A category SLUG, never its id. */
|
|
156
|
+
categorySlug?: string | null;
|
|
157
|
+
supportUrl?: string | null;
|
|
158
|
+
supportEmail?: string | null;
|
|
159
|
+
}
|
|
160
|
+
export interface AddScreenshotInput {
|
|
161
|
+
/** An already-uploaded image. Must be live, an image, and yours to publish. */
|
|
162
|
+
fileId: string;
|
|
163
|
+
platform?: StoreScreenshotPlatform;
|
|
164
|
+
caption?: string | null;
|
|
165
|
+
}
|
|
166
|
+
export interface UpdateScreenshotInput {
|
|
167
|
+
platform?: StoreScreenshotPlatform;
|
|
168
|
+
caption?: string | null;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* One page of a paginated store read.
|
|
172
|
+
*
|
|
173
|
+
* `hasMore` comes from the API rather than being derived here, so a caller that
|
|
174
|
+
* pages does not have to re-implement the boundary the server already computed.
|
|
175
|
+
*/
|
|
176
|
+
export interface StorePage<T> {
|
|
177
|
+
items: T[];
|
|
178
|
+
total: number;
|
|
179
|
+
hasMore: boolean;
|
|
180
|
+
}
|
|
181
|
+
/** Options for paging the storefront and the reviews under an app. */
|
|
182
|
+
export interface StorePageOptions {
|
|
183
|
+
limit?: number;
|
|
184
|
+
offset?: number;
|
|
185
|
+
}
|
|
186
|
+
export interface StoreReviewsOptions extends StorePageOptions {
|
|
187
|
+
/** Newest first by default; `rating` surfaces the strongest opinions. */
|
|
188
|
+
sort?: 'recent' | 'rating';
|
|
189
|
+
}
|
|
190
|
+
export declare function OxyServicesStoreMixin<T extends typeof OxyServicesBase>(Base: T): {
|
|
191
|
+
new (...args: any[]): {
|
|
192
|
+
/** The shelves, in the order the store curates them. */
|
|
193
|
+
listStoreCategories(): Promise<StoreCategory[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Published listings, newest first, optionally one shelf.
|
|
196
|
+
*
|
|
197
|
+
* An unknown category slug is an EMPTY shelf, not every app on the store —
|
|
198
|
+
* so a typo shows nothing rather than showing everything.
|
|
199
|
+
*
|
|
200
|
+
* @param options - `category` is a category slug; `limit` defaults to 24.
|
|
201
|
+
*/
|
|
202
|
+
listStoreApps(options?: StorePageOptions & {
|
|
203
|
+
category?: string;
|
|
204
|
+
}): Promise<StorePage<StoreListingSummary>>;
|
|
205
|
+
/**
|
|
206
|
+
* One store page.
|
|
207
|
+
*
|
|
208
|
+
* A draft answers 404 exactly as an unknown slug does: whether an
|
|
209
|
+
* unpublished page exists under a name is not something a visitor learns.
|
|
210
|
+
*
|
|
211
|
+
* @param slug - The listing's public slug, not an application id.
|
|
212
|
+
*/
|
|
213
|
+
getStoreApp(slug: string): Promise<StoreListingDetail>;
|
|
214
|
+
/** Visible reviews for a published app, each with the publisher's reply. */
|
|
215
|
+
listStoreReviews(slug: string, options?: StoreReviewsOptions): Promise<StorePage<StoreReview>>;
|
|
216
|
+
/** The caller's own review of an app, or `null` if they have not written one. */
|
|
217
|
+
getMyStoreReview(slug: string): Promise<StoreOwnReview | null>;
|
|
218
|
+
/**
|
|
219
|
+
* Write the caller's review, or replace what they said before.
|
|
220
|
+
*
|
|
221
|
+
* A person has one review per app, so this sets it rather than adding one.
|
|
222
|
+
* Rewriting does not clear a moderator's decision: a hidden review stays
|
|
223
|
+
* hidden when its author edits it.
|
|
224
|
+
*/
|
|
225
|
+
writeStoreReview(slug: string, input: WriteStoreReviewInput): Promise<StoreOwnReview>;
|
|
226
|
+
/** Withdraw the caller's own review. A real delete — the words were theirs. */
|
|
227
|
+
deleteMyStoreReview(slug: string): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* Answer a review on the publisher's behalf.
|
|
230
|
+
*
|
|
231
|
+
* Requires `app:update` over the application's owning account — the same
|
|
232
|
+
* permission that guards every other write to that application. Addressed
|
|
233
|
+
* by review id because the reply belongs to the review, and a listing can be
|
|
234
|
+
* renamed or withdrawn out from under it.
|
|
235
|
+
*/
|
|
236
|
+
replyToStoreReview(reviewId: string, body: string): Promise<{
|
|
237
|
+
id: string;
|
|
238
|
+
reviewId: string;
|
|
239
|
+
body: string;
|
|
240
|
+
}>;
|
|
241
|
+
/** Withdraw the publisher's answer. Same permission that wrote it. */
|
|
242
|
+
deleteStoreReviewReply(reviewId: string): Promise<void>;
|
|
243
|
+
/** The application's store page in whatever state, or `null` if it has none. */
|
|
244
|
+
getAppListing(applicationId: string): Promise<PublisherListing | null>;
|
|
245
|
+
/**
|
|
246
|
+
* Create the page or replace its content. Never its status.
|
|
247
|
+
*
|
|
248
|
+
* Editing does not move a page: correcting a typo on a live listing leaves
|
|
249
|
+
* it live, and fixing a rejected one does not re-submit it.
|
|
250
|
+
*/
|
|
251
|
+
writeAppListing(applicationId: string, input: WriteListingInput): Promise<PublisherListing>;
|
|
252
|
+
/** Hand the page to the store for review. From a draft, or a rejected page once fixed. */
|
|
253
|
+
submitAppListing(applicationId: string): Promise<PublisherListing>;
|
|
254
|
+
/**
|
|
255
|
+
* Take the page down, or withdraw it from the queue.
|
|
256
|
+
*
|
|
257
|
+
* Back to a draft, never deleted: the slug, the words and the screenshots
|
|
258
|
+
* are the publisher's work, and the reviews were never the listing's to take
|
|
259
|
+
* with them.
|
|
260
|
+
*/
|
|
261
|
+
unpublishAppListing(applicationId: string): Promise<PublisherListing>;
|
|
262
|
+
/** Every picture on the listing, in the author's order. */
|
|
263
|
+
listAppListingScreenshots(applicationId: string): Promise<StoreScreenshot[]>;
|
|
264
|
+
/**
|
|
265
|
+
* Attach an already-uploaded image, appended to the end.
|
|
266
|
+
*
|
|
267
|
+
* Upload through the assets surface first; the store keeps a reference
|
|
268
|
+
* rather than a second copy of the asset pipeline. The file must be live, an
|
|
269
|
+
* image, and one the caller is entitled to.
|
|
270
|
+
*/
|
|
271
|
+
addAppListingScreenshot(applicationId: string, input: AddScreenshotInput): Promise<StoreScreenshot>;
|
|
272
|
+
/** Edit a picture's caption or the frame it was taken in. Order is {@link reorderAppListingScreenshots}. */
|
|
273
|
+
updateAppListingScreenshot(applicationId: string, screenshotId: string, input: UpdateScreenshotInput): Promise<StoreScreenshot>;
|
|
274
|
+
/** Remove a picture. The uploaded file stays — it may be in use elsewhere. */
|
|
275
|
+
deleteAppListingScreenshot(applicationId: string, screenshotId: string): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Set the order of every picture at once.
|
|
278
|
+
*
|
|
279
|
+
* Send EVERY id on the listing, exactly once, in the order they should
|
|
280
|
+
* appear. A partial list is rejected rather than applied: it would leave the
|
|
281
|
+
* pictures it omits at their old positions, interleaved with the new ones.
|
|
282
|
+
*/
|
|
283
|
+
reorderAppListingScreenshots(applicationId: string, screenshotIds: string[]): Promise<StoreScreenshot[]>;
|
|
284
|
+
httpService: import("../HttpService").HttpService;
|
|
285
|
+
cloudURL: string;
|
|
286
|
+
config: import("../OxyServices.base").OxyConfig;
|
|
287
|
+
__resetTokensForTests(): void;
|
|
288
|
+
makeRequest<T_1>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", url: string, data?: any, options?: import("../HttpService").RequestOptions): Promise<T_1>;
|
|
289
|
+
getBaseURL(): string;
|
|
290
|
+
getClient(): import("../HttpService").HttpService;
|
|
291
|
+
createLinkedClient(config: import("../OxyServices.base").OxyConfig): import("..").LinkedHttpClient;
|
|
292
|
+
getMetrics(): {
|
|
293
|
+
totalRequests: number;
|
|
294
|
+
successfulRequests: number;
|
|
295
|
+
failedRequests: number;
|
|
296
|
+
cacheHits: number;
|
|
297
|
+
cacheMisses: number;
|
|
298
|
+
averageResponseTime: number;
|
|
299
|
+
};
|
|
300
|
+
clearCache(): void;
|
|
301
|
+
clearCacheEntry(key: string): void;
|
|
302
|
+
clearCacheByPrefix(prefix: string): number;
|
|
303
|
+
getCacheStats(): {
|
|
304
|
+
size: number;
|
|
305
|
+
hits: number;
|
|
306
|
+
misses: number;
|
|
307
|
+
hitRate: number;
|
|
308
|
+
};
|
|
309
|
+
getCloudURL(): string;
|
|
310
|
+
setTokens(accessToken: string): void;
|
|
311
|
+
clearTokens(): void;
|
|
312
|
+
onTokensChanged(listener: (accessToken: string | null) => void): () => void;
|
|
313
|
+
_cachedUserId: string | null | undefined;
|
|
314
|
+
_cachedAccessToken: string | null;
|
|
315
|
+
getCurrentUserId(): string | null;
|
|
316
|
+
hasValidToken(): boolean;
|
|
317
|
+
getAccessToken(): string | null;
|
|
318
|
+
getAccessTokenExpiry(): number | null;
|
|
319
|
+
waitForAuth(timeoutMs?: number): Promise<boolean>;
|
|
320
|
+
withAuthRetry<T_1>(operation: () => Promise<T_1>, operationName: string, options?: {
|
|
321
|
+
maxRetries?: number;
|
|
322
|
+
retryDelay?: number;
|
|
323
|
+
authTimeoutMs?: number;
|
|
324
|
+
}): Promise<T_1>;
|
|
325
|
+
validate(): Promise<boolean>;
|
|
326
|
+
handleError(error: unknown): Error;
|
|
327
|
+
healthCheck(): Promise<{
|
|
328
|
+
status: string;
|
|
329
|
+
users?: number;
|
|
330
|
+
timestamp?: string;
|
|
331
|
+
[key: string]: any;
|
|
332
|
+
}>;
|
|
333
|
+
};
|
|
334
|
+
} & T;
|