@clioplaylists/clio 0.1.6 → 0.1.8
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/.env +7 -0
- package/dist/api/health.js +3 -10
- package/dist/api/index.js +2 -39
- package/dist/api/util.js +6 -10
- package/dist/api/well-known.d.ts +3 -0
- package/dist/api/well-known.js +31 -0
- package/dist/auth-verifier.js +165 -273
- package/dist/client.js +8 -15
- package/dist/config.d.ts +2 -0
- package/dist/config.js +17 -23
- package/dist/context.d.ts +3 -0
- package/dist/context.js +6 -10
- package/dist/dataplane/client/hosts.d.ts +21 -0
- package/dist/dataplane/client/hosts.js +25 -0
- package/dist/dataplane/client/index.d.ts +11 -0
- package/dist/dataplane/client/index.js +97 -0
- package/dist/dataplane/client.js +25 -70
- package/dist/dataplane/index.js +2 -18
- package/dist/dataplane/server/background.js +8 -29
- package/dist/dataplane/server/db/database-schema.js +1 -2
- package/dist/dataplane/server/db/db.js +27 -103
- package/dist/dataplane/server/db/index.js +1 -17
- package/dist/dataplane/server/db/migrations/20230309T045948368Z-init.js +7 -11
- package/dist/dataplane/server/db/migrations/20230420T211446071Z-did-cache.js +2 -6
- package/dist/dataplane/server/db/migrations/index.js +2 -38
- package/dist/dataplane/server/db/migrations/provider.js +5 -17
- package/dist/dataplane/server/db/pagination.js +21 -37
- package/dist/dataplane/server/db/tables/actor-sync.js +1 -4
- package/dist/dataplane/server/db/tables/actor.js +1 -4
- package/dist/dataplane/server/db/tables/artist-list-item.js +1 -4
- package/dist/dataplane/server/db/tables/artist.js +1 -4
- package/dist/dataplane/server/db/tables/playlist-idea.js +1 -4
- package/dist/dataplane/server/db/tables/playlist-item.js +1 -4
- package/dist/dataplane/server/db/tables/playlist.js +1 -4
- package/dist/dataplane/server/db/tables/profile.js +1 -4
- package/dist/dataplane/server/db/tables/record.js +1 -4
- package/dist/dataplane/server/db/tables/song.js +1 -4
- package/dist/dataplane/server/db/types.js +1 -2
- package/dist/dataplane/server/db/util.js +18 -26
- package/dist/dataplane/server/index.js +17 -33
- package/dist/dataplane/server/indexing/index.js +39 -89
- package/dist/dataplane/server/indexing/plugins/playlist-idea.js +7 -44
- package/dist/dataplane/server/indexing/plugins/profile.js +5 -42
- package/dist/dataplane/server/indexing/processor.js +11 -29
- package/dist/dataplane/server/routes/identity.js +11 -13
- package/dist/dataplane/server/routes/index.js +10 -15
- package/dist/dataplane/server/routes/profile.js +9 -11
- package/dist/dataplane/server/routes/records.js +14 -51
- package/dist/dataplane/server/routes/sync.js +1 -3
- package/dist/dataplane/server/subscription.js +19 -47
- package/dist/error.js +5 -9
- package/dist/index.d.ts +2 -0
- package/dist/index.js +36 -90
- package/dist/lexicons/index.js +52 -227
- package/dist/lexicons/lexicons.js +5 -8
- package/dist/lexicons/types/com/atproto/admin/defs.js +27 -39
- package/dist/lexicons/types/com/atproto/admin/deleteAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/disableAccountInvites.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/disableInviteCodes.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/enableAccountInvites.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getAccountInfo.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getAccountInfos.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getInviteCodes.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getSubjectStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/searchAccounts.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/sendEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateAccountEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateAccountHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateAccountPassword.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateSubjectStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/defs.js +7 -11
- package/dist/lexicons/types/com/atproto/identity/getRecommendedDidCredentials.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/refreshIdentity.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/requestPlcOperationSignature.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/resolveDid.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/resolveHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/resolveIdentity.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/signPlcOperation.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/submitPlcOperation.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/updateHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/label/defs.js +27 -39
- package/dist/lexicons/types/com/atproto/label/queryLabels.js +1 -2
- package/dist/lexicons/types/com/atproto/label/subscribeLabels.js +12 -18
- package/dist/lexicons/types/com/atproto/lexicon/schema.js +7 -11
- package/dist/lexicons/types/com/atproto/moderation/createReport.js +1 -2
- package/dist/lexicons/types/com/atproto/moderation/defs.js +7 -10
- package/dist/lexicons/types/com/atproto/repo/applyWrites.js +32 -46
- package/dist/lexicons/types/com/atproto/repo/createRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/defs.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/deleteRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/describeRepo.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/getRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/importRepo.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/listMissingBlobs.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/listRecords.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/putRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/strongRef.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/uploadBlob.js +1 -2
- package/dist/lexicons/types/com/atproto/server/activateAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/checkAccountStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/server/confirmEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/server/createAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/createAppPassword.js +7 -11
- package/dist/lexicons/types/com/atproto/server/createInviteCode.js +1 -2
- package/dist/lexicons/types/com/atproto/server/createInviteCodes.js +7 -11
- package/dist/lexicons/types/com/atproto/server/createSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/deactivateAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/defs.js +12 -18
- package/dist/lexicons/types/com/atproto/server/deleteAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/deleteSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/describeServer.js +12 -18
- package/dist/lexicons/types/com/atproto/server/getAccountInviteCodes.js +1 -2
- package/dist/lexicons/types/com/atproto/server/getServiceAuth.js +1 -2
- package/dist/lexicons/types/com/atproto/server/getSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/listAppPasswords.js +7 -11
- package/dist/lexicons/types/com/atproto/server/refreshSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestAccountDelete.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestEmailConfirmation.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestEmailUpdate.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestPasswordReset.js +1 -2
- package/dist/lexicons/types/com/atproto/server/reserveSigningKey.js +1 -2
- package/dist/lexicons/types/com/atproto/server/resetPassword.js +1 -2
- package/dist/lexicons/types/com/atproto/server/revokeAppPassword.js +1 -2
- package/dist/lexicons/types/com/atproto/server/updateEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getBlob.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getBlocks.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getCheckout.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getHead.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getLatestCommit.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getRepo.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getRepoStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/listBlobs.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/listRepos.js +7 -11
- package/dist/lexicons/types/com/atproto/sync/listReposByCollection.js +7 -11
- package/dist/lexicons/types/com/atproto/sync/notifyOfUpdate.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/requestCrawl.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/subscribeRepos.js +32 -46
- package/dist/lexicons/types/com/atproto/temp/addReservedHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/temp/checkSignupQueue.js +1 -2
- package/dist/lexicons/types/com/atproto/temp/fetchLabels.js +1 -2
- package/dist/lexicons/types/com/atproto/temp/requestPhoneVerification.js +1 -2
- package/dist/lexicons/types/com/clioplaylists/alpha/actor/profile.js +7 -11
- package/dist/lexicons/types/com/clioplaylists/alpha/feed/defs.js +12 -18
- package/dist/lexicons/types/com/clioplaylists/alpha/feed/getSongs.js +1 -2
- package/dist/lexicons/types/com/clioplaylists/alpha/feed/playlistIdea.js +17 -25
- package/dist/lexicons/util.js +2 -6
- package/dist/logger.js +10 -16
- package/dist/rpc/clio_connect.js +30 -33
- package/dist/rpc/clio_pb.js +402 -956
- package/dist/start.js +9 -1
- package/dist/util/retry.js +7 -10
- package/dist/util/uris.js +3 -6
- package/dist/util.js +17 -60
- package/package.json +4 -4
|
@@ -1,51 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
1
|
+
import { keyBy } from '@atproto/common';
|
|
2
|
+
import { AtUri } from '@atproto/syntax';
|
|
3
|
+
import { Timestamp } from '@bufbuild/protobuf';
|
|
4
|
+
import * as ui8 from 'uint8arrays';
|
|
5
|
+
import { ids } from '../../../lexicons/lexicons';
|
|
6
|
+
import { Record } from '../../../rpc/clio_pb';
|
|
7
|
+
export default (db) => ({
|
|
8
|
+
getProfileRecords: getRecords(db, ids.ComClioplaylistsAlphaActorProfile),
|
|
17
9
|
});
|
|
18
|
-
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getRecords = void 0;
|
|
37
|
-
const common_1 = require("@atproto/common");
|
|
38
|
-
const syntax_1 = require("@atproto/syntax");
|
|
39
|
-
const protobuf_1 = require("@bufbuild/protobuf");
|
|
40
|
-
const ui8 = __importStar(require("uint8arrays"));
|
|
41
|
-
const lexicons_1 = require("../../../lexicons/lexicons");
|
|
42
|
-
const clio_pb_1 = require("../../../rpc/clio_pb");
|
|
43
|
-
exports.default = (db) => ({
|
|
44
|
-
getProfileRecords: (0, exports.getRecords)(db, lexicons_1.ids.ComClioplaylistsAlphaActorProfile),
|
|
45
|
-
});
|
|
46
|
-
const getRecords = (db, collection) => async (req) => {
|
|
10
|
+
export const getRecords = (db, collection) => async (req) => {
|
|
47
11
|
const validUris = collection
|
|
48
|
-
? req.uris.filter((uri) => new
|
|
12
|
+
? req.uris.filter((uri) => new AtUri(uri).collection === collection)
|
|
49
13
|
: req.uris;
|
|
50
14
|
const res = validUris.length
|
|
51
15
|
? await db.db
|
|
@@ -54,19 +18,19 @@ const getRecords = (db, collection) => async (req) => {
|
|
|
54
18
|
.where('uri', 'in', validUris)
|
|
55
19
|
.execute()
|
|
56
20
|
: [];
|
|
57
|
-
const byUri =
|
|
21
|
+
const byUri = keyBy(res, 'uri');
|
|
58
22
|
const records = req.uris.map((uri) => {
|
|
59
23
|
const row = byUri.get(uri);
|
|
60
24
|
const json = row ? row.json : JSON.stringify(null);
|
|
61
25
|
const createdAtRaw = new Date(JSON.parse(json)?.['createdAt']);
|
|
62
26
|
const createdAt = !isNaN(createdAtRaw.getTime())
|
|
63
|
-
?
|
|
27
|
+
? Timestamp.fromDate(createdAtRaw)
|
|
64
28
|
: undefined;
|
|
65
29
|
const indexedAt = row?.indexed_at
|
|
66
|
-
?
|
|
30
|
+
? Timestamp.fromDate(new Date(row?.indexed_at))
|
|
67
31
|
: undefined;
|
|
68
32
|
const recordBytes = ui8.fromString(json, 'utf8');
|
|
69
|
-
return new
|
|
33
|
+
return new Record({
|
|
70
34
|
record: recordBytes,
|
|
71
35
|
cid: row?.cid,
|
|
72
36
|
createdAt,
|
|
@@ -78,7 +42,6 @@ const getRecords = (db, collection) => async (req) => {
|
|
|
78
42
|
});
|
|
79
43
|
return { records };
|
|
80
44
|
};
|
|
81
|
-
exports.getRecords = getRecords;
|
|
82
45
|
const compositeTime = (ts1, ts2) => {
|
|
83
46
|
if (!ts1)
|
|
84
47
|
return ts2;
|
|
@@ -1,46 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { WriteOpAction } from '@atproto/repo';
|
|
2
|
+
import { Firehose, MemoryRunner } from '@atproto/sync';
|
|
3
|
+
import { subLogger as log } from '../../logger';
|
|
4
|
+
import { BackgroundQueue } from './background';
|
|
5
|
+
import { IndexingService } from './indexing';
|
|
6
|
+
export class RepoSubscription {
|
|
7
|
+
opts;
|
|
8
|
+
firehose;
|
|
9
|
+
runner;
|
|
10
|
+
background;
|
|
11
|
+
indexingSvc;
|
|
10
12
|
constructor(opts) {
|
|
11
|
-
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: opts
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(this, "firehose", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: void 0
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "runner", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: void 0
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(this, "background", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true,
|
|
33
|
-
value: void 0
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, "indexingSvc", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: void 0
|
|
40
|
-
});
|
|
13
|
+
this.opts = opts;
|
|
41
14
|
const { service, db, idResolver } = opts;
|
|
42
|
-
this.background = new
|
|
43
|
-
this.indexingSvc = new
|
|
15
|
+
this.background = new BackgroundQueue(db);
|
|
16
|
+
this.indexingSvc = new IndexingService(db, idResolver);
|
|
44
17
|
const { runner, firehose } = createFirehose({
|
|
45
18
|
idResolver,
|
|
46
19
|
service,
|
|
@@ -73,17 +46,16 @@ class RepoSubscription {
|
|
|
73
46
|
await this.background.processAll();
|
|
74
47
|
}
|
|
75
48
|
}
|
|
76
|
-
exports.RepoSubscription = RepoSubscription;
|
|
77
49
|
const createFirehose = (opts) => {
|
|
78
50
|
const { idResolver, service, indexingSvc } = opts;
|
|
79
|
-
const runner = new
|
|
80
|
-
const firehose = new
|
|
51
|
+
const runner = new MemoryRunner({ startCursor: 0 });
|
|
52
|
+
const firehose = new Firehose({
|
|
81
53
|
idResolver,
|
|
82
54
|
runner,
|
|
83
55
|
service,
|
|
84
56
|
unauthenticatedHandles: true, // indexing service handles these
|
|
85
57
|
unauthenticatedCommits: true, // @TODO there seems to be a very rare issue where the authenticator thinks a block is missing in deletion ops
|
|
86
|
-
onError: (err) =>
|
|
58
|
+
onError: (err) => log.error({ err }, 'error in subscription'),
|
|
87
59
|
handleEvent: async (evt) => {
|
|
88
60
|
if (evt.event === 'identity') {
|
|
89
61
|
await indexingSvc.indexHandle(evt.did, evt.time, true);
|
|
@@ -100,8 +72,8 @@ const createFirehose = (opts) => {
|
|
|
100
72
|
const indexFn = evt.event === 'delete'
|
|
101
73
|
? indexingSvc.deleteRecord(evt.uri)
|
|
102
74
|
: indexingSvc.indexRecord(evt.uri, evt.cid, evt.record, evt.event === 'create'
|
|
103
|
-
?
|
|
104
|
-
:
|
|
75
|
+
? WriteOpAction.Create
|
|
76
|
+
: WriteOpAction.Update, evt.time);
|
|
105
77
|
await Promise.all([
|
|
106
78
|
indexFn,
|
|
107
79
|
indexingSvc.setCommitLastSeen(evt.did, evt.commit, evt.rev),
|
package/dist/error.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const logger_1 = require("./logger");
|
|
6
|
-
const handler = (err, _req, res, next) => {
|
|
7
|
-
logger_1.httpLogger.error(err, 'unexpected internal server error');
|
|
1
|
+
import { XRPCError } from '@atproto/xrpc-server';
|
|
2
|
+
import { httpLogger as log } from './logger';
|
|
3
|
+
export const handler = (err, _req, res, next) => {
|
|
4
|
+
log.error(err, 'unexpected internal server error');
|
|
8
5
|
if (res.headersSent) {
|
|
9
6
|
return next(err);
|
|
10
7
|
}
|
|
11
|
-
const serverError =
|
|
8
|
+
const serverError = XRPCError.fromError(err);
|
|
12
9
|
res.status(serverError.type).json(serverError.payload);
|
|
13
10
|
};
|
|
14
|
-
exports.handler = handler;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Keypair } from '@atproto/crypto';
|
|
1
2
|
import express from 'express';
|
|
2
3
|
import { Server } from 'http';
|
|
3
4
|
import { ServerConfig } from './config';
|
|
@@ -13,6 +14,7 @@ export declare class ClioAppView {
|
|
|
13
14
|
});
|
|
14
15
|
static create(opts: {
|
|
15
16
|
config: ServerConfig;
|
|
17
|
+
signingKey: Keypair;
|
|
16
18
|
}): ClioAppView;
|
|
17
19
|
start(): Promise<Server>;
|
|
18
20
|
destroy(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,97 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ClioAppView = void 0;
|
|
40
|
-
const common_1 = require("@atproto/common");
|
|
41
|
-
const cors_1 = __importDefault(require("cors"));
|
|
42
|
-
const dotenv_1 = require("dotenv");
|
|
43
|
-
const events_1 = __importDefault(require("events"));
|
|
44
|
-
const express_1 = __importDefault(require("express"));
|
|
45
|
-
const http_terminator_1 = require("http-terminator");
|
|
46
|
-
const api_1 = __importStar(require("./api"));
|
|
47
|
-
const client_1 = require("./client");
|
|
48
|
-
const context_1 = __importDefault(require("./context"));
|
|
49
|
-
const error = __importStar(require("./error"));
|
|
50
|
-
const lexicons_1 = require("./lexicons");
|
|
51
|
-
const logger_1 = require("./logger");
|
|
52
|
-
(0, dotenv_1.config)();
|
|
53
|
-
class ClioAppView {
|
|
1
|
+
import { DAY, SECOND } from '@atproto/common';
|
|
2
|
+
import cors from 'cors';
|
|
3
|
+
import { config } from 'dotenv';
|
|
4
|
+
import events from 'events';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import { createHttpTerminator } from 'http-terminator';
|
|
7
|
+
import API, { health } from './api';
|
|
8
|
+
import AppContext from './context';
|
|
9
|
+
import { createDataPlaneClient } from './dataplane';
|
|
10
|
+
import { BasicHostList } from './dataplane/client/hosts';
|
|
11
|
+
import * as error from './error';
|
|
12
|
+
import { createServer } from './lexicons';
|
|
13
|
+
import { loggerMiddleware } from './logger';
|
|
14
|
+
config();
|
|
15
|
+
export class ClioAppView {
|
|
16
|
+
ctx;
|
|
17
|
+
app;
|
|
18
|
+
server;
|
|
19
|
+
terminator;
|
|
54
20
|
constructor(opts) {
|
|
55
|
-
Object.defineProperty(this, "ctx", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: void 0
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(this, "app", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
configurable: true,
|
|
64
|
-
writable: true,
|
|
65
|
-
value: void 0
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(this, "server", {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
configurable: true,
|
|
70
|
-
writable: true,
|
|
71
|
-
value: void 0
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(this, "terminator", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true,
|
|
77
|
-
value: void 0
|
|
78
|
-
});
|
|
79
21
|
this.ctx = opts.ctx;
|
|
80
22
|
this.app = opts.app;
|
|
81
23
|
}
|
|
82
24
|
static create(opts) {
|
|
83
|
-
const { config } = opts;
|
|
84
|
-
const app = (
|
|
85
|
-
app.use((
|
|
86
|
-
app.use(
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
25
|
+
const { config, signingKey } = opts;
|
|
26
|
+
const app = express();
|
|
27
|
+
app.use(cors({ maxAge: DAY / SECOND }));
|
|
28
|
+
app.use(loggerMiddleware);
|
|
29
|
+
const dataplaneHostList = new BasicHostList(config.dataplaneUrls);
|
|
30
|
+
const dataplane = createDataPlaneClient(dataplaneHostList, {
|
|
31
|
+
httpVersion: '2',
|
|
32
|
+
rejectUnauthorized: false,
|
|
33
|
+
});
|
|
34
|
+
const server = createServer();
|
|
35
|
+
const ctx = new AppContext({
|
|
90
36
|
cfg: config,
|
|
91
37
|
dataplane,
|
|
38
|
+
signingKey,
|
|
92
39
|
});
|
|
93
|
-
const api = (
|
|
94
|
-
app.use(
|
|
40
|
+
const api = API(server, ctx);
|
|
41
|
+
app.use(health.createRouter(ctx));
|
|
95
42
|
app.use(api.xrpc.router);
|
|
96
43
|
app.use(error.handler);
|
|
97
44
|
return new ClioAppView({ ctx, app });
|
|
@@ -101,8 +48,8 @@ class ClioAppView {
|
|
|
101
48
|
const server = this.app.listen(this.ctx.cfg.port);
|
|
102
49
|
this.server = server;
|
|
103
50
|
server.keepAliveTimeout = 90000;
|
|
104
|
-
this.terminator =
|
|
105
|
-
await
|
|
51
|
+
this.terminator = createHttpTerminator({ server });
|
|
52
|
+
await events.once(server, 'listening');
|
|
106
53
|
const { port } = server.address();
|
|
107
54
|
this.ctx.cfg.assignPort(port);
|
|
108
55
|
return server;
|
|
@@ -111,5 +58,4 @@ class ClioAppView {
|
|
|
111
58
|
await this.terminator?.terminate();
|
|
112
59
|
}
|
|
113
60
|
}
|
|
114
|
-
|
|
115
|
-
exports.default = ClioAppView;
|
|
61
|
+
export default ClioAppView;
|