@agora-sdk/social-core 0.6.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/dist/cjs/context/social-context.d.ts +65 -0
- package/dist/cjs/context/social-context.js +125 -0
- package/dist/cjs/context/social-context.js.map +1 -0
- package/dist/cjs/contract/index.d.ts +19 -0
- package/dist/cjs/contract/index.js +57 -0
- package/dist/cjs/contract/index.js.map +1 -0
- package/dist/cjs/hooks/useSocialConstellation.d.ts +29 -0
- package/dist/cjs/hooks/useSocialConstellation.js +70 -0
- package/dist/cjs/hooks/useSocialConstellation.js.map +1 -0
- package/dist/cjs/hooks/useSocialNeighborhood.d.ts +29 -0
- package/dist/cjs/hooks/useSocialNeighborhood.js +90 -0
- package/dist/cjs/hooks/useSocialNeighborhood.js.map +1 -0
- package/dist/cjs/hooks/useSocialTransparency.d.ts +25 -0
- package/dist/cjs/hooks/useSocialTransparency.js +28 -0
- package/dist/cjs/hooks/useSocialTransparency.js.map +1 -0
- package/dist/cjs/hooks/useSocialWeather.d.ts +28 -0
- package/dist/cjs/hooks/useSocialWeather.js +72 -0
- package/dist/cjs/hooks/useSocialWeather.js.map +1 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transport/rest.d.ts +105 -0
- package/dist/cjs/transport/rest.js +177 -0
- package/dist/cjs/transport/rest.js.map +1 -0
- package/dist/esm/context/social-context.d.ts +65 -0
- package/dist/esm/context/social-context.js +120 -0
- package/dist/esm/context/social-context.js.map +1 -0
- package/dist/esm/contract/index.d.ts +19 -0
- package/dist/esm/contract/index.js +54 -0
- package/dist/esm/contract/index.js.map +1 -0
- package/dist/esm/hooks/useSocialConstellation.d.ts +29 -0
- package/dist/esm/hooks/useSocialConstellation.js +67 -0
- package/dist/esm/hooks/useSocialConstellation.js.map +1 -0
- package/dist/esm/hooks/useSocialNeighborhood.d.ts +29 -0
- package/dist/esm/hooks/useSocialNeighborhood.js +87 -0
- package/dist/esm/hooks/useSocialNeighborhood.js.map +1 -0
- package/dist/esm/hooks/useSocialTransparency.d.ts +25 -0
- package/dist/esm/hooks/useSocialTransparency.js +25 -0
- package/dist/esm/hooks/useSocialTransparency.js.map +1 -0
- package/dist/esm/hooks/useSocialWeather.d.ts +28 -0
- package/dist/esm/hooks/useSocialWeather.js +69 -0
- package/dist/esm/hooks/useSocialWeather.js.map +1 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/transport/rest.d.ts +105 -0
- package/dist/esm/transport/rest.js +168 -0
- package/dist/esm/transport/rest.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSocialWeather.js","sourceRoot":"","sources":["../../../src/hooks/useSocialWeather.tsx"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,EAAE;AACF,sGAAsG;AACtG,qGAAqG;AACrG,qGAAqG;AACrG,iGAAiG;AACjG,yCAAyC;AAEzC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAczD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,CAAC;IACpD,MAAM,OAAO,GAAG,MAAM,EAAE,cAAc,IAAI,KAAK,CAAC;IAEhD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,IAAI,CAAC,CAAC;IACnE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CA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
export type { SocialProviderProps, SocialContextValue } from "./context/social-context.js";
|
|
3
|
+
export { useSocialWeather } from "./hooks/useSocialWeather.js";
|
|
4
|
+
export type { UseSocialWeatherValues } from "./hooks/useSocialWeather.js";
|
|
5
|
+
export { useSocialConstellation } from "./hooks/useSocialConstellation.js";
|
|
6
|
+
export type { UseSocialConstellationValues } from "./hooks/useSocialConstellation.js";
|
|
7
|
+
export { useSocialNeighborhood } from "./hooks/useSocialNeighborhood.js";
|
|
8
|
+
export type { UseSocialNeighborhoodValues } from "./hooks/useSocialNeighborhood.js";
|
|
9
|
+
export { useSocialTransparency } from "./hooks/useSocialTransparency.js";
|
|
10
|
+
export type { UseSocialTransparencyValues } from "./hooks/useSocialTransparency.js";
|
|
11
|
+
export { SocialRestClient, SocialApiError, isSocialDegradation } from "./transport/rest.js";
|
|
12
|
+
export type { SocialRestConfig } from "./transport/rest.js";
|
|
13
|
+
export { WEATHER_BANDS, BLOB_SIZE_BUCKETS, NEIGHBORHOOD_TIE_KINDS, } from "./contract/index.js";
|
|
14
|
+
export type { SocialWeather, WeatherBand, SocialConstellation, ConstellationBlob, BlobSizeBucket, SocialNeighborhood, NeighborhoodTie, NeighborhoodTieKind, ResolvedSocialConfig, } from "./contract/index.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @agora-sdk/social-core — platform-agnostic client for the Agora social graph.
|
|
2
|
+
//
|
|
3
|
+
// Typed REST transport + provider/hooks for the three member-facing lenses (Weather, Constellation,
|
|
4
|
+
// Neighborhood) plus the Transparency endpoint. Pure data — no crypto, no persistence, no realtime.
|
|
5
|
+
// Platform packages (@agora-sdk/social-react-js, etc.) re-export this and add the visual components.
|
|
6
|
+
// ── context / provider ──────────────────────────────────────────────────────
|
|
7
|
+
export { SocialProvider, useSocial, ALL_DISABLED_SOCIAL_CONFIG } from "./context/social-context.js";
|
|
8
|
+
// ── hooks ────────────────────────────────────────────────────────────────────
|
|
9
|
+
export { useSocialWeather } from "./hooks/useSocialWeather.js";
|
|
10
|
+
export { useSocialConstellation } from "./hooks/useSocialConstellation.js";
|
|
11
|
+
export { useSocialNeighborhood } from "./hooks/useSocialNeighborhood.js";
|
|
12
|
+
export { useSocialTransparency } from "./hooks/useSocialTransparency.js";
|
|
13
|
+
// ── transport (for advanced / non-React use) ─────────────────────────────────
|
|
14
|
+
export { SocialRestClient, SocialApiError, isSocialDegradation } from "./transport/rest.js";
|
|
15
|
+
// ── wire contract types + runtime const arrays (transitional — see ./contract) ──
|
|
16
|
+
export { WEATHER_BANDS, BLOB_SIZE_BUCKETS, NEIGHBORHOOD_TIE_KINDS, } from "./contract/index.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,oGAAoG;AACpG,oGAAoG;AACpG,qGAAqG;AAErG,+EAA+E;AAC/E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAGpG,gFAAgF;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,gFAAgF;AAChF,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG5F,mFAAmF;AACnF,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ResolvedSocialConfig, SocialConstellation, SocialNeighborhood, SocialWeather } from "../contract/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for {@link SocialRestClient}. The base URL and access token are read through resolver
|
|
4
|
+
* callbacks rather than captured once, so a late-set `baseUrl` or a refreshed token take effect on the
|
|
5
|
+
* next request without rebuilding the client.
|
|
6
|
+
*/
|
|
7
|
+
export interface SocialRestConfig {
|
|
8
|
+
/** Resolve the API base URL (e.g. `getApiBaseUrl()` from @agora-sdk/core → `http://host/v7`). */
|
|
9
|
+
getBaseUrl: () => string;
|
|
10
|
+
/** Resolve the current access token, or undefined when signed out. */
|
|
11
|
+
getAccessToken: () => string | undefined;
|
|
12
|
+
/** The Agora project id (path-scoped on every endpoint — a privacy boundary). */
|
|
13
|
+
projectId: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A failed social API call. Carries the HTTP `status` and, when the server supplied one, the machine
|
|
17
|
+
* `code` (e.g. `social/graph-unavailable`, `social/weather-disabled`) so callers can distinguish
|
|
18
|
+
* "hide this surface" degradation (SOCIAL.md §7) from an unexpected failure.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SocialApiError extends Error {
|
|
21
|
+
/** HTTP status code, or `0` when the request never got a response (network error). */
|
|
22
|
+
readonly status: number;
|
|
23
|
+
/** The server's machine error code (e.g. `social/graph-unavailable`), or `null` if none was sent. */
|
|
24
|
+
readonly code: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* @param message - Human-readable summary (never contains member PII).
|
|
27
|
+
* @param status - HTTP status code (`0` for a network-level failure).
|
|
28
|
+
* @param code - The server's machine error code, or `null`.
|
|
29
|
+
*/
|
|
30
|
+
constructor(message: string, status: number, code: string | null);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether an error is a "hide this surface" degradation (graph unavailable or a feature-disabled lens)
|
|
34
|
+
* rather than a real failure. Hooks use this to fail soft — clearing data instead of surfacing the
|
|
35
|
+
* error to members (`docs/SOCIAL.md` §7).
|
|
36
|
+
*
|
|
37
|
+
* @param err - Any caught error.
|
|
38
|
+
* @returns `true` for a {@link SocialApiError} whose `code` is a known degradation code; else `false`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isSocialDegradation(err: unknown): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Typed REST client for the Agora social graph.
|
|
43
|
+
*
|
|
44
|
+
* Wraps the four social endpoints in `docs/SOCIAL.md`. Each request lazily resolves the base URL and
|
|
45
|
+
* bearer token, scopes the path to `{baseUrl}/{projectId}/social`, and normalizes any failure into a
|
|
46
|
+
* {@link SocialApiError}.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* Construct this directly only for advanced / non-React use. Inside React, prefer the `SocialProvider`
|
|
50
|
+
* + hooks, which build and share one client for you.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const rest = new SocialRestClient({
|
|
55
|
+
* projectId,
|
|
56
|
+
* getBaseUrl: () => getApiBaseUrl(),
|
|
57
|
+
* getAccessToken: () => session.accessToken,
|
|
58
|
+
* });
|
|
59
|
+
* const weather = await rest.getWeather();
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class SocialRestClient {
|
|
63
|
+
private readonly config;
|
|
64
|
+
private readonly http;
|
|
65
|
+
/** @param config - Lazy resolvers for base URL + token, plus the path-scoped project id. */
|
|
66
|
+
constructor(config: SocialRestConfig);
|
|
67
|
+
/**
|
|
68
|
+
* Fetch the Community Weather scalar (aggregate warmth + band + 7-day trend).
|
|
69
|
+
*
|
|
70
|
+
* @returns The current {@link SocialWeather} reading (`value: null` / `band: "quiet"` when no data yet).
|
|
71
|
+
* @throws {SocialApiError} `400 social/weather-disabled` (feature off) or `503 social/graph-unavailable`.
|
|
72
|
+
*/
|
|
73
|
+
getWeather(): Promise<SocialWeather>;
|
|
74
|
+
/**
|
|
75
|
+
* Fetch the Constellation snapshot (anonymous cluster blobs).
|
|
76
|
+
*
|
|
77
|
+
* @returns The current {@link SocialConstellation} (`asOf: null` when no snapshot exists yet).
|
|
78
|
+
* @throws {SocialApiError} `400 social/constellation-disabled` or `503 social/graph-unavailable`.
|
|
79
|
+
*/
|
|
80
|
+
getConstellation(): Promise<SocialConstellation>;
|
|
81
|
+
/**
|
|
82
|
+
* Fetch the caller's Neighborhood (their own named ties with dyadic brightness). Self-view only.
|
|
83
|
+
*
|
|
84
|
+
* @param opts - Optional `includeInteractions` toggle; omit to use the project default. The response
|
|
85
|
+
* always echoes the **effective** value via `includesInteractions`.
|
|
86
|
+
* @returns The caller's {@link SocialNeighborhood}, ties sorted brightest-first.
|
|
87
|
+
* @throws {SocialApiError} `400 social/neighborhood-disabled` or `503 social/graph-unavailable`.
|
|
88
|
+
*/
|
|
89
|
+
getNeighborhood(opts?: {
|
|
90
|
+
includeInteractions?: boolean;
|
|
91
|
+
}): Promise<SocialNeighborhood>;
|
|
92
|
+
/**
|
|
93
|
+
* Fetch the project's resolved social config (which lenses are enabled, decay half-lives, k-floor).
|
|
94
|
+
* Call this at app init to know which surfaces to render.
|
|
95
|
+
*
|
|
96
|
+
* @returns The project's {@link ResolvedSocialConfig}.
|
|
97
|
+
* @throws {SocialApiError} `503 social/graph-unavailable` when the graph is not configured.
|
|
98
|
+
*/
|
|
99
|
+
getTransparency(): Promise<ResolvedSocialConfig>;
|
|
100
|
+
/**
|
|
101
|
+
* Shared GET helper: issues the request and normalizes any axios failure into a {@link SocialApiError}
|
|
102
|
+
* carrying the HTTP status + server error code.
|
|
103
|
+
*/
|
|
104
|
+
private get;
|
|
105
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Typed REST client for the Agora social graph (Weather / Constellation / Neighborhood / Transparency).
|
|
2
|
+
//
|
|
3
|
+
// Covers every endpoint in `docs/SOCIAL.md` §1–4. Base URL and access token are resolved **lazily per
|
|
4
|
+
// request** (matching the @agora-sdk/core base-URL runtime), so a token refresh or a late-set baseUrl
|
|
5
|
+
// always wins. Every endpoint is path-scoped to `{baseUrl}/{projectId}/social` — the `:projectId`
|
|
6
|
+
// boundary is a privacy boundary (no cross-project social data; see SOCIAL.md §6).
|
|
7
|
+
//
|
|
8
|
+
// All four lenses are feature-gated server-side and degrade with specific error codes (SOCIAL.md §7).
|
|
9
|
+
// On any non-2xx, this client throws a typed {@link SocialApiError} carrying the HTTP `status` plus the
|
|
10
|
+
// server's machine `code` (e.g. `social/graph-unavailable`), so hooks/providers can hide a surface
|
|
11
|
+
// rather than surface a raw error to members.
|
|
12
|
+
import axios from "axios";
|
|
13
|
+
/**
|
|
14
|
+
* A failed social API call. Carries the HTTP `status` and, when the server supplied one, the machine
|
|
15
|
+
* `code` (e.g. `social/graph-unavailable`, `social/weather-disabled`) so callers can distinguish
|
|
16
|
+
* "hide this surface" degradation (SOCIAL.md §7) from an unexpected failure.
|
|
17
|
+
*/
|
|
18
|
+
export class SocialApiError extends Error {
|
|
19
|
+
/**
|
|
20
|
+
* @param message - Human-readable summary (never contains member PII).
|
|
21
|
+
* @param status - HTTP status code (`0` for a network-level failure).
|
|
22
|
+
* @param code - The server's machine error code, or `null`.
|
|
23
|
+
*/
|
|
24
|
+
constructor(message, status, code) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "SocialApiError";
|
|
27
|
+
this.status = status;
|
|
28
|
+
this.code = code;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Server error codes that mean "this surface is unavailable / turned off" rather than "something went
|
|
33
|
+
* wrong" — the graph being unconfigured (`503`) or a lens being feature-disabled (`400`). Per
|
|
34
|
+
* `docs/SOCIAL.md` §7 these should make the client **hide the surface**, never show a member an error.
|
|
35
|
+
*/
|
|
36
|
+
const SOCIAL_DEGRADATION_CODES = new Set([
|
|
37
|
+
"social/graph-unavailable",
|
|
38
|
+
"social/weather-disabled",
|
|
39
|
+
"social/constellation-disabled",
|
|
40
|
+
"social/neighborhood-disabled",
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* Whether an error is a "hide this surface" degradation (graph unavailable or a feature-disabled lens)
|
|
44
|
+
* rather than a real failure. Hooks use this to fail soft — clearing data instead of surfacing the
|
|
45
|
+
* error to members (`docs/SOCIAL.md` §7).
|
|
46
|
+
*
|
|
47
|
+
* @param err - Any caught error.
|
|
48
|
+
* @returns `true` for a {@link SocialApiError} whose `code` is a known degradation code; else `false`.
|
|
49
|
+
*/
|
|
50
|
+
export function isSocialDegradation(err) {
|
|
51
|
+
return (err instanceof SocialApiError && err.code !== null && SOCIAL_DEGRADATION_CODES.has(err.code));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Pull the server's machine error code out of an arbitrary error body. agora-server error shapes vary
|
|
55
|
+
* (`{ error: { code } }`, `{ code }`, or `{ error: "social/…" }`), so probe each defensively and fall
|
|
56
|
+
* back to `null`. Never throws.
|
|
57
|
+
*/
|
|
58
|
+
function extractCode(data) {
|
|
59
|
+
if (!data || typeof data !== "object")
|
|
60
|
+
return null;
|
|
61
|
+
const body = data;
|
|
62
|
+
const nested = body.error;
|
|
63
|
+
if (nested && typeof nested === "object" && typeof nested.code === "string") {
|
|
64
|
+
return nested.code;
|
|
65
|
+
}
|
|
66
|
+
if (typeof body.code === "string")
|
|
67
|
+
return body.code;
|
|
68
|
+
if (typeof nested === "string")
|
|
69
|
+
return nested;
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Typed REST client for the Agora social graph.
|
|
74
|
+
*
|
|
75
|
+
* Wraps the four social endpoints in `docs/SOCIAL.md`. Each request lazily resolves the base URL and
|
|
76
|
+
* bearer token, scopes the path to `{baseUrl}/{projectId}/social`, and normalizes any failure into a
|
|
77
|
+
* {@link SocialApiError}.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Construct this directly only for advanced / non-React use. Inside React, prefer the `SocialProvider`
|
|
81
|
+
* + hooks, which build and share one client for you.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const rest = new SocialRestClient({
|
|
86
|
+
* projectId,
|
|
87
|
+
* getBaseUrl: () => getApiBaseUrl(),
|
|
88
|
+
* getAccessToken: () => session.accessToken,
|
|
89
|
+
* });
|
|
90
|
+
* const weather = await rest.getWeather();
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export class SocialRestClient {
|
|
94
|
+
/** @param config - Lazy resolvers for base URL + token, plus the path-scoped project id. */
|
|
95
|
+
constructor(config) {
|
|
96
|
+
this.config = config;
|
|
97
|
+
this.http = axios.create();
|
|
98
|
+
this.http.interceptors.request.use((req) => {
|
|
99
|
+
const base = config.getBaseUrl().replace(/\/$/, "");
|
|
100
|
+
req.baseURL = `${base}/${config.projectId}/social`;
|
|
101
|
+
const token = config.getAccessToken();
|
|
102
|
+
if (token)
|
|
103
|
+
req.headers.set("Authorization", `Bearer ${token}`);
|
|
104
|
+
return req;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Fetch the Community Weather scalar (aggregate warmth + band + 7-day trend).
|
|
109
|
+
*
|
|
110
|
+
* @returns The current {@link SocialWeather} reading (`value: null` / `band: "quiet"` when no data yet).
|
|
111
|
+
* @throws {SocialApiError} `400 social/weather-disabled` (feature off) or `503 social/graph-unavailable`.
|
|
112
|
+
*/
|
|
113
|
+
async getWeather() {
|
|
114
|
+
return this.get("/weather");
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Fetch the Constellation snapshot (anonymous cluster blobs).
|
|
118
|
+
*
|
|
119
|
+
* @returns The current {@link SocialConstellation} (`asOf: null` when no snapshot exists yet).
|
|
120
|
+
* @throws {SocialApiError} `400 social/constellation-disabled` or `503 social/graph-unavailable`.
|
|
121
|
+
*/
|
|
122
|
+
async getConstellation() {
|
|
123
|
+
return this.get("/constellation");
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fetch the caller's Neighborhood (their own named ties with dyadic brightness). Self-view only.
|
|
127
|
+
*
|
|
128
|
+
* @param opts - Optional `includeInteractions` toggle; omit to use the project default. The response
|
|
129
|
+
* always echoes the **effective** value via `includesInteractions`.
|
|
130
|
+
* @returns The caller's {@link SocialNeighborhood}, ties sorted brightest-first.
|
|
131
|
+
* @throws {SocialApiError} `400 social/neighborhood-disabled` or `503 social/graph-unavailable`.
|
|
132
|
+
*/
|
|
133
|
+
async getNeighborhood(opts) {
|
|
134
|
+
const params = opts?.includeInteractions === undefined
|
|
135
|
+
? undefined
|
|
136
|
+
: { includeInteractions: opts.includeInteractions };
|
|
137
|
+
return this.get("/neighborhood", params);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Fetch the project's resolved social config (which lenses are enabled, decay half-lives, k-floor).
|
|
141
|
+
* Call this at app init to know which surfaces to render.
|
|
142
|
+
*
|
|
143
|
+
* @returns The project's {@link ResolvedSocialConfig}.
|
|
144
|
+
* @throws {SocialApiError} `503 social/graph-unavailable` when the graph is not configured.
|
|
145
|
+
*/
|
|
146
|
+
async getTransparency() {
|
|
147
|
+
return this.get("/transparency");
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Shared GET helper: issues the request and normalizes any axios failure into a {@link SocialApiError}
|
|
151
|
+
* carrying the HTTP status + server error code.
|
|
152
|
+
*/
|
|
153
|
+
async get(path, params) {
|
|
154
|
+
try {
|
|
155
|
+
const { data } = await this.http.get(path, params ? { params } : undefined);
|
|
156
|
+
return data;
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
if (axios.isAxiosError(err)) {
|
|
160
|
+
const status = err.response?.status ?? 0;
|
|
161
|
+
const code = extractCode(err.response?.data);
|
|
162
|
+
throw new SocialApiError(code ? `Social request failed: ${code}` : `Social request failed (HTTP ${status}).`, status, code);
|
|
163
|
+
}
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../src/transport/rest.ts"],"names":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CAAC,mBAAmB,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC,GAAG,CAAqB,eAAe,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,GAAG,CAAuB,eAAe,CAAC,CAAC;IACzD,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,GAAG,CAAI,IAAY,EAAE,MAAgC;QACjE,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAI,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAC/E,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;gBACzC,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAC7C,MAAM,IAAI,cAAc,CACtB,IAAI,CAAC,CAAC,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC,CAAC,+BAA+B,MAAM,IAAI,EACnF,MAAM,EACN,IAAI,CACL,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agora-sdk/social-core",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Agora SDK Plus, maintained by Jenova Marie",
|
|
7
|
+
"description": "Platform-agnostic client for the Agora social graph (Weather, Constellation, Neighborhood lenses): typed REST transport, provider + feature-gated hooks. Pure data — no crypto.",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"agora",
|
|
10
|
+
"social-graph",
|
|
11
|
+
"community",
|
|
12
|
+
"weather",
|
|
13
|
+
"constellation",
|
|
14
|
+
"neighborhood",
|
|
15
|
+
"react",
|
|
16
|
+
"typescript"
|
|
17
|
+
],
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/jenova-marie/agora-sdk-plus/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/jenova-marie/agora-sdk-plus",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/jenova-marie/agora-sdk-plus.git",
|
|
25
|
+
"directory": "packages/social/core"
|
|
26
|
+
},
|
|
27
|
+
"main": "dist/cjs/index.js",
|
|
28
|
+
"module": "dist/esm/index.js",
|
|
29
|
+
"types": "dist/esm/index.d.ts",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@agora-server/contract": "^0.12.1",
|
|
39
|
+
"axios": "^1.4.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@agora-sdk/core": "^1.2.2",
|
|
43
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
47
|
+
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
48
|
+
"build": "rimraf dist && pnpm run build:esm && pnpm run build:cjs",
|
|
49
|
+
"prepublish": "pnpm run build"
|
|
50
|
+
}
|
|
51
|
+
}
|