@sockethub/schemas 3.0.0-alpha.9 → 3.0.0-beta.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.
Files changed (74) hide show
  1. package/dist/activity-stream-helper.d.ts +5 -0
  2. package/dist/activity-stream-helper.js +36 -0
  3. package/dist/activity-stream-helper.js.map +10 -0
  4. package/dist/context.d.ts +56 -0
  5. package/dist/context.js +80 -0
  6. package/dist/context.js.map +10 -0
  7. package/dist/contexts/platform/caldav/v1.jsonld +8 -0
  8. package/dist/contexts/platform/carddav/v1.jsonld +8 -0
  9. package/dist/contexts/platform/dummy/v1.jsonld +8 -0
  10. package/dist/contexts/platform/error/v1.jsonld +8 -0
  11. package/dist/contexts/platform/feeds/v1.jsonld +8 -0
  12. package/dist/contexts/platform/irc/v1.jsonld +8 -0
  13. package/dist/contexts/platform/metadata/v1.jsonld +8 -0
  14. package/dist/contexts/platform/sockethub%3Ainternal/v1.jsonld +8 -0
  15. package/dist/contexts/platform/xmpp/v1.jsonld +8 -0
  16. package/dist/contexts/v1.jsonld +7 -0
  17. package/dist/helpers/error-parser.d.ts +13 -0
  18. package/dist/helpers/objects.d.ts +157 -0
  19. package/dist/index.d.ts +11 -0
  20. package/dist/index.js +1235 -1143
  21. package/dist/index.js.map +15 -17
  22. package/dist/maps/context-map.json +41 -0
  23. package/dist/object-types.d.ts +2 -0
  24. package/dist/object-types.js +299 -0
  25. package/dist/object-types.js.map +12 -0
  26. package/dist/schema-id.d.ts +11 -0
  27. package/dist/schemas/activity-stream.d.ts +196 -0
  28. package/{src/schemas/json/activity-object.json → dist/schemas/json/activity-stream.json} +99 -158
  29. package/dist/schemas/json/platform.json +52 -0
  30. package/dist/schemas/json/service-descriptor.json +58 -0
  31. package/dist/schemas/json/sockethub-config.json +500 -0
  32. package/dist/schemas/platform/caldav/v1/credentials.schema.json +71 -0
  33. package/dist/schemas/platform/caldav/v1/messages.schema.json +769 -0
  34. package/dist/schemas/platform/carddav/v1/credentials.schema.json +67 -0
  35. package/dist/schemas/platform/carddav/v1/messages.schema.json +375 -0
  36. package/dist/schemas/platform/dummy/v1/credentials.schema.json +1 -0
  37. package/dist/schemas/platform/dummy/v1/messages.schema.json +22 -0
  38. package/dist/schemas/platform/error/v1/credentials.schema.json +1 -0
  39. package/dist/schemas/platform/error/v1/messages.schema.json +1 -0
  40. package/dist/schemas/platform/feeds/v1/credentials.schema.json +1 -0
  41. package/dist/schemas/platform/feeds/v1/messages.schema.json +27 -0
  42. package/dist/schemas/platform/irc/v1/credentials.schema.json +118 -0
  43. package/dist/schemas/platform/irc/v1/messages.schema.json +149 -0
  44. package/dist/schemas/platform/metadata/v1/credentials.schema.json +1 -0
  45. package/dist/schemas/platform/metadata/v1/messages.schema.json +14 -0
  46. package/dist/schemas/platform/sockethub%3Ainternal/v1/credentials.schema.json +1 -0
  47. package/dist/schemas/platform/sockethub%3Ainternal/v1/messages.schema.json +1 -0
  48. package/dist/schemas/platform/xmpp/v1/credentials.schema.json +43 -0
  49. package/dist/schemas/platform/xmpp/v1/messages.schema.json +129 -0
  50. package/dist/schemas/platform.d.ts +62 -0
  51. package/dist/schemas/service-descriptor.d.ts +84 -0
  52. package/dist/schemas/sockethub-config.d.ts +466 -0
  53. package/dist/service-descriptor.d.ts +4 -0
  54. package/dist/service-descriptor.js +6280 -0
  55. package/dist/service-descriptor.js.map +77 -0
  56. package/{src/types.ts → dist/types.d.ts} +52 -53
  57. package/dist/validator.d.ts +26 -0
  58. package/package.json +32 -11
  59. package/src/helpers/error-parser.ts +0 -113
  60. package/src/helpers/objects.ts +0 -227
  61. package/src/index.test.data.credentials.ts +0 -71
  62. package/src/index.test.data.objects.ts +0 -241
  63. package/src/index.test.data.platform.ts +0 -45
  64. package/src/index.test.data.streams.ts +0 -498
  65. package/src/index.test.ts +0 -99
  66. package/src/index.ts +0 -27
  67. package/src/schemas/activity-object.ts +0 -19
  68. package/src/schemas/activity-stream.ts +0 -54
  69. package/src/schemas/json/activity-stream.json +0 -469
  70. package/src/schemas/json/platform.json +0 -28
  71. package/src/schemas/json/sockethub-config.json +0 -144
  72. package/src/schemas/platform.ts +0 -47
  73. package/src/schemas/sockethub-config.ts +0 -140
  74. package/src/validator.ts +0 -94
@@ -1,140 +0,0 @@
1
- const connectConfigPlatforms = {
2
- connectTimeoutMs: {
3
- type: "number",
4
- },
5
- };
6
-
7
- export const SockethubConfigSchema = {
8
- $id: "https://sockethub.org/schemas/v/sockethub-config.json",
9
- description: "Sockethub Config Schema",
10
- type: "object",
11
- required: ["platforms"],
12
- properties: {
13
- examples: {
14
- type: "object",
15
- properties: {
16
- enabled: {
17
- type: "boolean",
18
- default: false,
19
- },
20
- secret: {
21
- type: "string",
22
- default: "1234567890",
23
- },
24
- },
25
- additionalProperties: false,
26
- },
27
- log_file: {
28
- type: "string",
29
- },
30
- packageConfig: {
31
- type: "object",
32
- properties: {
33
- "@sockethub/activity-streams": {
34
- type: "object",
35
- properties: {
36
- specialObjs: {
37
- type: "array",
38
- items: {
39
- type: "string",
40
- },
41
- default: ["credentials"],
42
- },
43
- failOnUnknownObjectProperties: {
44
- type: "boolean",
45
- default: true,
46
- },
47
- },
48
- additionalProperties: false,
49
- },
50
- "@sockethub/platform-dummy": {
51
- type: "object",
52
- properties: {
53
- greeting: {
54
- type: "string",
55
- default: "Hello",
56
- },
57
- },
58
- additionalProperties: false,
59
- },
60
- "@sockethub/platform-feeds": {
61
- type: "object",
62
- properties: {
63
- ...connectConfigPlatforms,
64
- },
65
- additionalProperties: false,
66
- },
67
- "@sockethub/platform-irc": {
68
- type: "object",
69
- properties: {
70
- ...connectConfigPlatforms,
71
- },
72
- additionalProperties: false,
73
- },
74
- "@sockethub/platform-xmpp": {
75
- type: "object",
76
- properties: {
77
- ...connectConfigPlatforms,
78
- },
79
- additionalProperties: false,
80
- },
81
- },
82
- },
83
- platforms: {
84
- type: "array",
85
- items: {
86
- type: "string",
87
- },
88
- },
89
- public: {
90
- type: "object",
91
- properties: {
92
- protocol: {
93
- type: "string",
94
- default: "http",
95
- },
96
- host: {
97
- type: "string",
98
- default: "localhost",
99
- },
100
- port: {
101
- type: "number",
102
- default: 10550,
103
- },
104
- path: {
105
- type: "string",
106
- default: "/",
107
- },
108
- },
109
- additionalProperties: false,
110
- },
111
- redis: {
112
- type: "object",
113
- properties: {
114
- url: {
115
- type: "string",
116
- default: "redis://127.0.0.1:6379",
117
- },
118
- },
119
- additionalProperties: false,
120
- },
121
- sockethub: {
122
- type: "object",
123
- properties: {
124
- port: {
125
- type: "number",
126
- default: 10550,
127
- },
128
- host: {
129
- type: "string",
130
- default: "localhost",
131
- },
132
- path: {
133
- type: "string",
134
- default: "/sockethub",
135
- },
136
- },
137
- additionalProperties: false,
138
- },
139
- },
140
- };
package/src/validator.ts DELETED
@@ -1,94 +0,0 @@
1
- import Ajv, { type Schema } from "ajv";
2
- import addFormats from "ajv-formats";
3
- import additionsFormats2019 from "ajv-formats-draft2019";
4
- import debug from "debug";
5
- import getErrorMessage from "./helpers/error-parser.js";
6
- import { ActivityObjectSchema } from "./schemas/activity-object.js";
7
- import { ActivityStreamSchema } from "./schemas/activity-stream.js";
8
- import { PlatformSchema } from "./schemas/platform.js";
9
- import type { ActivityStream } from "./types.js";
10
-
11
- const ajv = new Ajv({ strictTypes: false, allErrors: true });
12
- addFormats(ajv);
13
- additionsFormats2019(ajv);
14
-
15
- interface SchemasDict {
16
- string?: Schema;
17
- }
18
-
19
- const log = debug("sockethub:schemas:validator");
20
- const schemaURL = "https://sockethub.org/schemas/v0";
21
- const schemas: SchemasDict = {};
22
-
23
- schemas[`${schemaURL}/activity-stream`] = ActivityStreamSchema;
24
- schemas[`${schemaURL}/activity-object`] = ActivityObjectSchema;
25
-
26
- for (const uri in schemas) {
27
- log(`registering schema ${uri}`);
28
- ajv.addSchema(schemas[uri], uri);
29
- }
30
-
31
- function handleValidation(
32
- schemaRef: string,
33
- msg: ActivityStream,
34
- isObject = false,
35
- ): string {
36
- const validator = ajv.getSchema(schemaRef);
37
- let result: boolean | Promise<unknown>;
38
- if (isObject) {
39
- result = validator({ object: msg });
40
- } else {
41
- result = validator(msg);
42
- }
43
- if (!result) {
44
- let errorMessage = getErrorMessage(msg, validator.errors);
45
- if (msg.context) {
46
- errorMessage = `[${msg.context}] ${errorMessage}`;
47
- }
48
- return errorMessage;
49
- }
50
- return "";
51
- }
52
-
53
- export function validateActivityObject(msg: ActivityStream): string {
54
- return handleValidation(`${schemaURL}/activity-object`, msg, true);
55
- }
56
-
57
- export function validateActivityStream(msg: ActivityStream): string {
58
- return handleValidation(`${schemaURL}/activity-stream`, msg);
59
- }
60
-
61
- export function validateCredentials(msg: ActivityStream): string {
62
- if (!msg.context) {
63
- return "credential activity streams must have a context set";
64
- }
65
- if (msg.type !== "credentials") {
66
- return "credential activity streams must have credentials set as type";
67
- }
68
- log(
69
- `validating credentials against ${schemaURL}/context/${msg.context}/credentials`,
70
- );
71
- return handleValidation(
72
- `${schemaURL}/context/${msg.context}/credentials`,
73
- msg,
74
- );
75
- }
76
-
77
- export function validatePlatformSchema(schema: Schema): string {
78
- const validate = ajv.compile(PlatformSchema);
79
- // validate schema property
80
- const err = validate(schema);
81
- if (!err) {
82
- return `platform schema failed to validate: ${validate.errors[0].instancePath} ${validate.errors[0].message}`;
83
- }
84
- return "";
85
- }
86
-
87
- export function addPlatformSchema(schema: Schema, platform_type: string) {
88
- log(`registering schema ${schemaURL}/context/${platform_type}`);
89
- ajv.addSchema(schema, `${schemaURL}/context/${platform_type}`);
90
- }
91
-
92
- export function getPlatformSchema(platform_type: string) {
93
- return ajv.getSchema(`${schemaURL}/context/${platform_type}`);
94
- }