@appgrowstack/app-contract 0.0.0-stage → 0.1.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/rpc.js ADDED
@@ -0,0 +1,110 @@
1
+ export const APPGROWSTACK_BINDING = "APPGROWSTACK";
2
+ export const APPGROWSTACK_SERVICE = "appgrowstack-core";
3
+ export const APPGROWSTACK_ENTRYPOINT = "AppGrowStackRpc";
4
+ export const rpcSchemas = {
5
+ track: { input: ["people/track.schema.json"], result: ["people/track.schema.json", "result"] },
6
+ identify: { input: ["people/identify.schema.json"], result: ["people/identify.schema.json", "result"] },
7
+ forget: { input: ["people/forget.schema.json"], result: null },
8
+ subscription: { input: ["people/subscription.schema.json"], result: null },
9
+ touch: { input: ["people/touch.schema.json"], result: ["people/touch.schema.json", "result"] },
10
+ send: { input: ["notify/send.schema.json"], result: ["notify/send.schema.json", "result"] },
11
+ registerDevice: { input: ["notify/device.schema.json"], result: null },
12
+ unregisterDevice: { input: ["notify/device.schema.json", "unregister"], result: null },
13
+ registerWidgetPush: { input: ["notify/device.schema.json", "registerWidgetPush"], result: null },
14
+ unregisterWidgetPush: { input: ["notify/device.schema.json", "unregisterWidgetPush"], result: null },
15
+ refreshWidgets: { input: ["notify/device.schema.json", "refreshWidgets"], result: ["notify/device.schema.json", "refreshWidgetsResult"] },
16
+ createLink: { input: ["links/link.schema.json", "createInput"], result: ["links/link.schema.json"] },
17
+ createInvite: { input: ["links/link.schema.json", "inviteInput"], result: ["links/link.schema.json"] },
18
+ recordAttribution: { input: ["links/attribution.schema.json", "recordInput"], result: ["links/attribution.schema.json", "response"] },
19
+ createTicket: { input: ["support/ticket.schema.json", "createInput"], result: ["support/ticket.schema.json", "createResponse"] },
20
+ };
21
+ export const RPC_ERROR_CODES = {
22
+ input: "input",
23
+ project: "project",
24
+ retryLater: "retry_later",
25
+ rateLimited: "rate_limited",
26
+ forbidden: "forbidden",
27
+ notFound: "not_found",
28
+ conflict: "conflict",
29
+ notImplemented: "not_implemented",
30
+ captureMismatch: "capture_mismatch",
31
+ fetchFailed: "fetch_failed",
32
+ referenceMismatch: "reference_mismatch",
33
+ browserUnavailable: "browser_unavailable",
34
+ sqlRefused: "sql_refused",
35
+ scanLimit: "scan_limit",
36
+ };
37
+ const RPC_ERROR_CODE_SET = new Set(Object.values(RPC_ERROR_CODES));
38
+ const RPC_ERROR_HEAD = /^\[([a-z_]+)\] /;
39
+ export class AppGrowStackRpcError extends Error {
40
+ code;
41
+ constructor(code, message) {
42
+ super(`[${code}] ${message}`);
43
+ this.code = code;
44
+ }
45
+ }
46
+ export function notImplemented(what) {
47
+ return new AppGrowStackRpcError(RPC_ERROR_CODES.notImplemented, `${what} はまだ無い`);
48
+ }
49
+ export function rpcErrorCode(error) {
50
+ const message = error?.message;
51
+ if (typeof message !== "string")
52
+ return null;
53
+ const head = RPC_ERROR_HEAD.exec(message);
54
+ return head && RPC_ERROR_CODE_SET.has(head[1]) ? head[1] : null;
55
+ }
56
+ export function rpcErrorMessage(error) {
57
+ const message = error?.message;
58
+ if (typeof message !== "string")
59
+ return String(error);
60
+ return rpcErrorCode(error) === null ? message : message.replace(RPC_ERROR_HEAD, "");
61
+ }
62
+ export const APPGROWSTACK_API_ENTRYPOINT = "AppGrowStackApiRpc";
63
+ export const SESSION_LIVE_BINDING = "SESSION_LIVE";
64
+ export const SESSION_LIVE_CLASS = "SessionLive";
65
+ export const NOTIFY_BINDING = "NOTIFY";
66
+ export const NOTIFY_SERVICE = "appgrowstack-notify";
67
+ export const NOTIFY_ENTRYPOINT = "NotifyRpc";
68
+ export const LEGAL_ADMIN_BINDING = "LEGAL_ADMIN";
69
+ export const LEGAL_ADMIN_ENTRYPOINT = "LegalAdminRpc";
70
+ export const NOTIFY_ADMIN_BINDING = "NOTIFY_ADMIN";
71
+ export const NOTIFY_ADMIN_ENTRYPOINT = "NotifyAdminRpc";
72
+ export const CREATIVE_ADMIN_BINDING = "CREATIVE_ADMIN";
73
+ export const CREATIVE_SERVICE = "appgrowstack-creative";
74
+ export const CREATIVE_ADMIN_ENTRYPOINT = "CreativeAdminRpc";
75
+ export const INSIGHTS_BINDING = "INSIGHTS";
76
+ export const INSIGHTS_SERVICE = "appgrowstack-insights";
77
+ export const INSIGHTS_ENTRYPOINT = "InsightsRpc";
78
+ export const INSIGHTS_ADMIN_BINDING = "INSIGHTS_ADMIN";
79
+ export const INSIGHTS_ADMIN_ENTRYPOINT = "InsightsAdminRpc";
80
+ export const APP_RPC_SUMMARIES = {
81
+ track: "判定と成果に要る出来事を入れる。1回の呼び出しは1人分(100件まで)",
82
+ identify: "今の値を入れ、install と uid をつなぐ。返る person_id を端末の SDK の person に渡す",
83
+ forget: "アカウントの削除",
84
+ subscription: "アプリの Worker が受けた RevenueCat の webhook の1件",
85
+ touch: "1人に触れた1回を数える(record)・触れる前に1回分を取る(reserve)",
86
+ createLink: "短いリンクを作る(投稿のリンク・アプリの中へのリンク)。招待は createInvite",
87
+ createInvite: "招待のリンクを作る。招いた人(actor)を code に結び、招かれた人が入れて最初に開くと招いた人に invite_accepted が付く。同じ人の同じ url は前のリンクを返す。招く相手に特典は付けない",
88
+ recordAttribution: "アプリの Worker が自分の API で受けた流入元の手がかりを渡す",
89
+ createTicket: "アプリの Worker が自分の画面(Web のフォーム)で受けた問い合わせを渡す",
90
+ };
91
+ export const API_RPC_SUMMARIES = {
92
+ projectForPublicKey: "公開キー(active な物)からプロジェクト。知らない・revoke したキーは null",
93
+ readCampaignSet: "端末に配る組。知らないキーは null(api が 404 unknown_key)。キャッシュは api が持つ",
94
+ readConfigSet: "端末に配る R9 の組(K6-3)。知らないキーは null。config が off・paused なら今のバージョンの番号のまま空の組(ETag の後ろに -paused)。形は ServedSet と同じ",
95
+ notifyOpened: "POST /v1/notify/opened(api が公開キーからプロジェクトを引き、notify が on のときだけ呼ぶ)。core が appgrowstack-notify に記録させ、 人の像の「最後に通知を開いた」を進める。知らない send_id・ほかのプロジェクトの send_id でも投げない(端末には 204)",
96
+ recordAttribution: "POST /v1/links/attributions(links が off なら api が呼ばずに organic)。同じ install_id の2回目は最初の答え",
97
+ openLink: "製品のドメインの /l/:code・/go/:code。links_click に1行足し、行き先を返す。知らない・止めたリンクは製品のトップ。知らない Host は null",
98
+ createTicket: "POST /v1/support/tickets。install_id ごとに1時間に5件を超えたら code rate_limited",
99
+ listTickets: "GET /v1/support/tickets。その owner_token の問い合わせを新しい順に50件まで",
100
+ postTicketMessage: "POST /v1/support/tickets/:ticket_id/messages。owner_token の問い合わせでなければ null(端末には 404)",
101
+ uploadAttachment: "POST /v1/support/tickets/:ticket_id/attachments。owner_token の問い合わせでなければ null。形の違う・大きすぎる画像は code input、4枚を超えたら code rate_limited",
102
+ createFeedback: "POST /v1/support/feedback。アンケートで書いた文・設定から送った声を受け、AI に話題を付けさせる(Queue)。install_id ごとに1時間に5件を超えたら code rate_limited。support が off・paused なら code project",
103
+ listArticles: "GET /v1/support/articles?lang=。その言語が無い記事は言語の頭・en・その記事の最初の言語",
104
+ sessionBatch: "POST /v1/sessions/batches。バッチを Cloudflare R2 に書き、索引と数を足す。始まりのバッチの答えに upload_token",
105
+ sessionSegment: "PUT /v1/sessions/:session_id/segments/:seq。upload_token は api が HMAC で確かめてから渡す。同じ seq の2回目は捨てる(端末には 204)。形の違う塊は code input",
106
+ observeDevice: "端末の SDK が頭 AppGrowStack-Device・AppGrowStack-Install を付けて api を呼んだ1回。api は答えを返した後(waitUntil)に呼び、待たない。install と端末をつなぎ(people_device)、ネットワーク(AS 番号)と端末のマークから人の audience を決める。頭 AppGrowStack-Owner-Claim に切れていない本人のリンクの token があれば、端末に owner のマークを付ける",
107
+ noticeFeed: "GET /v1/notices。その人に今出すお知らせ(docs/design/notices.md 3節)。返したお知らせの notice_receipt を作る。image_base は api が作る画像の url の頭(<根>/v1/notices/images/<公開キー>/)",
108
+ readNotices: "POST /v1/notices/read。届いている ids の read_at を入れ、残りの未読の数を返す",
109
+ readNoticeImage: "GET /v1/notices/images/:key/:digest。R2 の <project>/notices/<sha256>。知らないキー・無い画像は null",
110
+ };
@@ -0,0 +1,8 @@
1
+ export declare const SESSION_INSTALL_HEADER = "X-Session-Install";
2
+ export declare const SESSION_UPLOAD_HEADER = "X-Session-Upload";
3
+ export declare const SESSION_LIVE_PROJECT_HEADER = "X-AppGrowStack-Project";
4
+ export declare const SESSION_TOKEN_SECRET = "SESSION_TOKEN_SECRET";
5
+ export declare const SESSION_UPLOAD_TOKEN_PATTERN: RegExp;
6
+ export declare const SESSION_LIVE_TOKEN_PATTERN: RegExp;
7
+ export declare const SESSION_UPLOAD_TTL_MS: number;
8
+ export declare const SESSION_LIVE_MAX_AHEAD_MS: number;
@@ -0,0 +1,8 @@
1
+ export const SESSION_INSTALL_HEADER = "X-Session-Install";
2
+ export const SESSION_UPLOAD_HEADER = "X-Session-Upload";
3
+ export const SESSION_LIVE_PROJECT_HEADER = "X-AppGrowStack-Project";
4
+ export const SESSION_TOKEN_SECRET = "SESSION_TOKEN_SECRET";
5
+ export const SESSION_UPLOAD_TOKEN_PATTERN = /^[0-9]{10}\.[0-9a-f]{64}$/;
6
+ export const SESSION_LIVE_TOKEN_PATTERN = /^[0-9]{10}\.[0-9a-f]{64}$/;
7
+ export const SESSION_UPLOAD_TTL_MS = 8 * 24 * 60 * 60 * 1000;
8
+ export const SESSION_LIVE_MAX_AHEAD_MS = 31 * 60 * 1000;
@@ -0,0 +1,10 @@
1
+ import type { InsightsSignal } from "./generated/schema.js";
2
+ export interface NotIndexedSummary {
3
+ project: string;
4
+ pages: InsightsSignal[];
5
+ coverage: [string, number][];
6
+ maxDays: number | null;
7
+ latest: number;
8
+ }
9
+ export declare function summarizeNotIndexed(items: readonly InsightsSignal[]): NotIndexedSummary[];
10
+ export declare function notIndexedTitle(s: NotIndexedSummary): string;
@@ -0,0 +1,49 @@
1
+ const COVERAGE_LABEL = {
2
+ "URL is unknown to Google": "Google がまだ知らない",
3
+ "Discovered - currently not indexed": "見つけたが載せていない",
4
+ "Crawled - currently not indexed": "読んだが載せていない",
5
+ };
6
+ const pathOfPage = (page) => {
7
+ try {
8
+ return new URL(page).pathname;
9
+ }
10
+ catch {
11
+ return page;
12
+ }
13
+ };
14
+ export function summarizeNotIndexed(items) {
15
+ const byPage = new Map();
16
+ for (const s of items) {
17
+ if (s.kind !== "not_indexed" || !s.detail.page)
18
+ continue;
19
+ const key = `${s.project} ${s.detail.page}`;
20
+ const prev = byPage.get(key);
21
+ if (!prev || prev.created_at < s.created_at)
22
+ byPage.set(key, s);
23
+ }
24
+ const byProject = new Map();
25
+ for (const s of byPage.values())
26
+ byProject.set(s.project, [...(byProject.get(s.project) ?? []), s]);
27
+ return [...byProject.entries()].map(([project, pages]) => {
28
+ const counts = new Map();
29
+ for (const s of pages) {
30
+ const label = COVERAGE_LABEL[s.detail.coverage ?? ""] ?? s.detail.coverage ?? "状態は不明";
31
+ counts.set(label, (counts.get(label) ?? 0) + 1);
32
+ }
33
+ const days = pages.map((s) => s.detail.observed).filter((d) => d !== null);
34
+ return {
35
+ project,
36
+ pages: pages.sort((a, b) => (b.detail.observed ?? 0) - (a.detail.observed ?? 0) || a.detail.page.localeCompare(b.detail.page)),
37
+ coverage: [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])),
38
+ maxDays: days.length ? Math.max(...days) : null,
39
+ latest: Math.max(...pages.map((s) => s.created_at)),
40
+ };
41
+ });
42
+ }
43
+ export function notIndexedTitle(s) {
44
+ if (s.pages.length === 1) {
45
+ const p = s.pages[0];
46
+ return `Google に載っていない記事: ${pathOfPage(p.detail.page)}(${p.detail.coverage ?? "状態は不明"}・${p.detail.observed ?? "?"}日)`;
47
+ }
48
+ return `Google に載っていない記事: ${s.pages.length}ページ(${s.coverage.map(([l, n]) => `${l} ${n}`).join("・")}・長いもので${s.maxDays ?? "?"}日)`;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@appgrowstack/app-contract",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "appgrowstack の約束の型。schema から作った型・APPGROWSTACK の RPC の型・HTTP の API の型・出来事の名前・権限の表",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/appgrowstack/app-growth.git",
10
+ "directory": "packages/contract"
11
+ },
12
+ "homepage": "https://github.com/appgrowstack/app-growth/tree/main/packages/contract#readme",
13
+ "keywords": [
14
+ "cloudflare-workers",
15
+ "appgrowstack",
16
+ "types"
17
+ ],
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./operations": {
25
+ "types": "./dist/operations.d.ts",
26
+ "default": "./dist/operations.js"
27
+ },
28
+ "./openapi": {
29
+ "types": "./dist/openapi.d.ts",
30
+ "default": "./dist/openapi.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "CHANGELOG.md",
37
+ "LICENSE"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "types": "./dist/index.d.ts",
43
+ "module": "./dist/index.js"
44
+ }