@sockethub/schemas 3.0.0-alpha.11 → 3.0.0-alpha.13

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 (60) 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/dummy/v1.jsonld +8 -0
  8. package/dist/contexts/platform/error/v1.jsonld +8 -0
  9. package/dist/contexts/platform/feeds/v1.jsonld +8 -0
  10. package/dist/contexts/platform/irc/v1.jsonld +8 -0
  11. package/dist/contexts/platform/metadata/v1.jsonld +8 -0
  12. package/dist/contexts/platform/sockethub%3Ainternal/v1.jsonld +8 -0
  13. package/dist/contexts/platform/xmpp/v1.jsonld +8 -0
  14. package/dist/contexts/v1.jsonld +7 -0
  15. package/dist/helpers/error-parser.d.ts +13 -0
  16. package/dist/helpers/objects.d.ts +122 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.js +459 -216
  19. package/dist/index.js.map +12 -11
  20. package/dist/maps/context-map.json +35 -0
  21. package/dist/object-types.d.ts +2 -0
  22. package/dist/object-types.js +296 -0
  23. package/dist/object-types.js.map +12 -0
  24. package/dist/schemas/activity-stream.d.ts +161 -0
  25. package/dist/schemas/platform/dummy/v1/credentials.schema.json +1 -0
  26. package/dist/schemas/platform/dummy/v1/messages.schema.json +22 -0
  27. package/dist/schemas/platform/error/v1/credentials.schema.json +1 -0
  28. package/dist/schemas/platform/error/v1/messages.schema.json +1 -0
  29. package/dist/schemas/platform/feeds/v1/credentials.schema.json +1 -0
  30. package/dist/schemas/platform/feeds/v1/messages.schema.json +27 -0
  31. package/dist/schemas/platform/irc/v1/credentials.schema.json +118 -0
  32. package/dist/schemas/platform/irc/v1/messages.schema.json +103 -0
  33. package/dist/schemas/platform/metadata/v1/credentials.schema.json +1 -0
  34. package/dist/schemas/platform/metadata/v1/messages.schema.json +14 -0
  35. package/dist/schemas/platform/sockethub%3Ainternal/v1/credentials.schema.json +1 -0
  36. package/dist/schemas/platform/sockethub%3Ainternal/v1/messages.schema.json +1 -0
  37. package/dist/schemas/platform/xmpp/v1/credentials.schema.json +43 -0
  38. package/dist/schemas/platform/xmpp/v1/messages.schema.json +129 -0
  39. package/dist/schemas/platform.d.ts +62 -0
  40. package/dist/schemas/sockethub-config.d.ts +261 -0
  41. package/{src/types.ts → dist/types.d.ts} +25 -46
  42. package/dist/validator.d.ts +26 -0
  43. package/package.json +17 -7
  44. package/src/helpers/error-parser.ts +0 -113
  45. package/src/helpers/objects.ts +0 -227
  46. package/src/index.test.data.credentials.ts +0 -71
  47. package/src/index.test.data.objects.ts +0 -241
  48. package/src/index.test.data.platform.ts +0 -45
  49. package/src/index.test.data.streams.ts +0 -498
  50. package/src/index.test.ts +0 -99
  51. package/src/index.ts +0 -29
  52. package/src/schemas/activity-object.ts +0 -19
  53. package/src/schemas/activity-stream.ts +0 -54
  54. package/src/schemas/json/activity-object.json +0 -356
  55. package/src/schemas/json/activity-stream.json +0 -469
  56. package/src/schemas/json/platform.json +0 -28
  57. package/src/schemas/json/sockethub-config.json +0 -222
  58. package/src/schemas/platform.ts +0 -47
  59. package/src/schemas/sockethub-config.ts +0 -206
  60. package/src/validator.ts +0 -87
package/dist/index.js CHANGED
@@ -4,15 +4,29 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
@@ -4560,6 +4574,7 @@ var require_limitLength = __commonJS((exports) => {
4560
4574
  var require_pattern = __commonJS((exports) => {
4561
4575
  Object.defineProperty(exports, "__esModule", { value: true });
4562
4576
  var code_1 = require_code2();
4577
+ var util_1 = require_util();
4563
4578
  var codegen_1 = require_codegen();
4564
4579
  var error = {
4565
4580
  message: ({ schemaCode }) => (0, codegen_1.str)`must match pattern "${schemaCode}"`,
@@ -4572,10 +4587,18 @@ var require_pattern = __commonJS((exports) => {
4572
4587
  $data: true,
4573
4588
  error,
4574
4589
  code(cxt) {
4575
- const { data, $data, schema, schemaCode, it } = cxt;
4590
+ const { gen, data, $data, schema, schemaCode, it } = cxt;
4576
4591
  const u = it.opts.unicodeRegExp ? "u" : "";
4577
- const regExp = $data ? (0, codegen_1._)`(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
4578
- cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4592
+ if ($data) {
4593
+ const { regExp } = it.opts.code;
4594
+ const regExpCode = regExp.code === "new RegExp" ? (0, codegen_1._)`new RegExp` : (0, util_1.useFunc)(gen, regExp);
4595
+ const valid = gen.let("valid");
4596
+ gen.try(() => gen.assign(valid, (0, codegen_1._)`${regExpCode}(${schemaCode}, ${u}).test(${data})`), () => gen.assign(valid, false));
4597
+ cxt.fail$data((0, codegen_1._)`!${valid}`);
4598
+ } else {
4599
+ const regExp = (0, code_1.usePattern)(cxt, schema);
4600
+ cxt.fail$data((0, codegen_1._)`!${regExp}.test(${data})`);
4601
+ }
4579
4602
  }
4580
4603
  };
4581
4604
  exports.default = def;
@@ -15735,19 +15758,70 @@ var require_ajv_formats_draft2019 = __commonJS((exports, module) => {
15735
15758
  };
15736
15759
  });
15737
15760
 
15738
- // src/helpers/objects.ts
15739
- var validObjectRefs = [];
15740
- var validObjectDefs = {};
15741
- var ObjectTypesSchema = {
15742
- credentials: {
15743
- required: ["type"],
15744
- additionalProperties: true,
15745
- properties: {
15746
- type: {
15747
- enum: ["credentials"]
15761
+ // src/context.ts
15762
+ var AS2_BASE_CONTEXT_URL = "https://www.w3.org/ns/activitystreams";
15763
+ var SOCKETHUB_BASE_CONTEXT_URL = "https://sockethub.org/ns/context/v1.jsonld";
15764
+ var PLATFORM_CONTEXT_PREFIX = "https://sockethub.org/ns/context/platform/";
15765
+ var ERROR_PLATFORM_ID = "error";
15766
+ var ERROR_PLATFORM_CONTEXT_URL = "https://sockethub.org/ns/context/platform/error/v1.jsonld";
15767
+ var INTERNAL_PLATFORM_ID = "sockethub:internal";
15768
+ var INTERNAL_PLATFORM_CONTEXT_URL = "https://sockethub.org/ns/context/platform/sockethub:internal/v1.jsonld";
15769
+ var platformContextToPlatformId = new Map;
15770
+ var platformContextToSchemaId = new Map;
15771
+ var platformContextToCredentialsSchemaId = new Map;
15772
+ function buildCanonicalContext(platform) {
15773
+ const platformUrl = platform.startsWith("https://") ? platform : `${PLATFORM_CONTEXT_PREFIX}${platform}/v1.jsonld`;
15774
+ return [AS2_BASE_CONTEXT_URL, SOCKETHUB_BASE_CONTEXT_URL, platformUrl];
15775
+ }
15776
+ function platformIdFromContext(context) {
15777
+ if (!Array.isArray(context)) {
15778
+ return;
15779
+ }
15780
+ for (const entry of context) {
15781
+ if (typeof entry === "string" && entry.startsWith(PLATFORM_CONTEXT_PREFIX)) {
15782
+ const rest = entry.slice(PLATFORM_CONTEXT_PREFIX.length);
15783
+ const slashIdx = rest.indexOf("/");
15784
+ if (slashIdx > 0) {
15785
+ return rest.slice(0, slashIdx);
15748
15786
  }
15749
15787
  }
15750
- },
15788
+ }
15789
+ return;
15790
+ }
15791
+ function normalizeContextArray(value) {
15792
+ if (!Array.isArray(value)) {
15793
+ return [];
15794
+ }
15795
+ return value.filter((entry) => typeof entry === "string");
15796
+ }
15797
+ function getContextArray(msg) {
15798
+ return normalizeContextArray(msg["@context"]);
15799
+ }
15800
+ function registerPlatformContext(platformId, platformContextUrl, schemaId, credentialsSchemaId) {
15801
+ platformContextToPlatformId.set(platformContextUrl, platformId);
15802
+ platformContextToSchemaId.set(platformContextUrl, schemaId);
15803
+ platformContextToCredentialsSchemaId.set(platformContextUrl, credentialsSchemaId);
15804
+ }
15805
+ function resolvePlatformContextUrl(msg) {
15806
+ const contexts = getContextArray(msg);
15807
+ const matches = contexts.filter((contextUrl) => platformContextToPlatformId.has(contextUrl));
15808
+ if (matches.length !== 1) {
15809
+ return null;
15810
+ }
15811
+ return matches[0];
15812
+ }
15813
+ function getPlatformIdByContextUrl(platformContextUrl) {
15814
+ return platformContextToPlatformId.get(platformContextUrl);
15815
+ }
15816
+ function getSchemaIdByContextUrl(platformContextUrl) {
15817
+ return platformContextToSchemaId.get(platformContextUrl);
15818
+ }
15819
+ function getCredentialsSchemaIdByContextUrl(platformContextUrl) {
15820
+ return platformContextToCredentialsSchemaId.get(platformContextUrl);
15821
+ }
15822
+
15823
+ // src/helpers/objects.ts
15824
+ var ObjectTypesSchema = {
15751
15825
  feed: {
15752
15826
  required: ["id", "type"],
15753
15827
  additionalProperties: true,
@@ -15773,37 +15847,22 @@ var ObjectTypesSchema = {
15773
15847
  }
15774
15848
  }
15775
15849
  },
15776
- message: {
15777
- required: ["type", "content"],
15850
+ person: {
15851
+ required: ["id", "type"],
15778
15852
  additionalProperties: true,
15779
15853
  properties: {
15780
- type: {
15781
- enum: ["message"]
15782
- },
15783
15854
  id: {
15784
15855
  type: "string"
15785
15856
  },
15786
- name: {
15787
- type: "string"
15788
- },
15789
- content: {
15790
- type: "string"
15791
- }
15792
- }
15793
- },
15794
- me: {
15795
- required: ["type", "content"],
15796
- additionalProperties: true,
15797
- properties: {
15798
15857
  type: {
15799
- enum: ["me"]
15858
+ enum: ["person"]
15800
15859
  },
15801
- content: {
15860
+ name: {
15802
15861
  type: "string"
15803
15862
  }
15804
15863
  }
15805
15864
  },
15806
- person: {
15865
+ room: {
15807
15866
  required: ["id", "type"],
15808
15867
  additionalProperties: true,
15809
15868
  properties: {
@@ -15811,14 +15870,14 @@ var ObjectTypesSchema = {
15811
15870
  type: "string"
15812
15871
  },
15813
15872
  type: {
15814
- enum: ["person"]
15873
+ enum: ["room"]
15815
15874
  },
15816
15875
  name: {
15817
15876
  type: "string"
15818
15877
  }
15819
15878
  }
15820
15879
  },
15821
- room: {
15880
+ service: {
15822
15881
  required: ["id", "type"],
15823
15882
  additionalProperties: true,
15824
15883
  properties: {
@@ -15826,14 +15885,14 @@ var ObjectTypesSchema = {
15826
15885
  type: "string"
15827
15886
  },
15828
15887
  type: {
15829
- enum: ["room"]
15888
+ enum: ["service"]
15830
15889
  },
15831
15890
  name: {
15832
15891
  type: "string"
15833
15892
  }
15834
15893
  }
15835
15894
  },
15836
- service: {
15895
+ platform: {
15837
15896
  required: ["id", "type"],
15838
15897
  additionalProperties: true,
15839
15898
  properties: {
@@ -15841,7 +15900,7 @@ var ObjectTypesSchema = {
15841
15900
  type: "string"
15842
15901
  },
15843
15902
  type: {
15844
- enum: ["service"]
15903
+ enum: ["platform"]
15845
15904
  },
15846
15905
  name: {
15847
15906
  type: "string"
@@ -15864,71 +15923,6 @@ var ObjectTypesSchema = {
15864
15923
  }
15865
15924
  }
15866
15925
  },
15867
- attendance: {
15868
- required: ["type"],
15869
- additionalProperties: false,
15870
- properties: {
15871
- type: {
15872
- enum: ["attendance"]
15873
- },
15874
- members: {
15875
- type: "array",
15876
- items: {
15877
- type: "string"
15878
- }
15879
- }
15880
- }
15881
- },
15882
- presence: {
15883
- required: ["type"],
15884
- additionalProperties: false,
15885
- properties: {
15886
- type: {
15887
- enum: ["presence"]
15888
- },
15889
- presence: {
15890
- enum: ["away", "chat", "dnd", "xa", "offline", "online"]
15891
- },
15892
- role: {
15893
- enum: ["owner", "member", "participant", "admin"]
15894
- },
15895
- content: {
15896
- type: "string"
15897
- }
15898
- }
15899
- },
15900
- relationship: {
15901
- required: ["type", "relationship"],
15902
- additionalProperties: false,
15903
- properties: {
15904
- type: {
15905
- enum: ["relationship"]
15906
- },
15907
- relationship: {
15908
- enum: ["role"]
15909
- },
15910
- subject: {
15911
- type: "object",
15912
- oneOf: [{ $ref: "#/definitions/type/presence" }]
15913
- },
15914
- object: {
15915
- type: "object",
15916
- oneOf: validObjectRefs
15917
- }
15918
- }
15919
- },
15920
- topic: {
15921
- required: ["type"],
15922
- additionalProperties: false,
15923
- properties: {
15924
- type: {
15925
- enum: ["topic"]
15926
- },
15927
- content: {
15928
- type: "string"
15929
- }
15930
- }
15931
- },
15932
15926
  address: {
15933
15927
  required: ["type"],
15934
15928
  additionalProperties: false,
@@ -15939,41 +15933,52 @@ var ObjectTypesSchema = {
15939
15933
  }
15940
15934
  }
15941
15935
  };
15936
+ var InternalObjectTypesList = ["platform", "heartbeat"];
15942
15937
  var ObjectTypesList = Object.keys(ObjectTypesSchema);
15943
- for (const type of ObjectTypesList) {
15944
- if (type === "credentials") {
15945
- continue;
15946
- }
15947
- validObjectRefs.push({ $ref: `#/definitions/type/${type}` });
15948
- validObjectDefs[type] = ObjectTypesSchema[type];
15949
- }
15950
-
15951
- // src/schemas/activity-object.ts
15952
- var ActivityObjectSchema = {
15953
- $id: "https://sockethub.org/schemas/v/activity-object.json",
15954
- description: "Schema for Sockethub Activity Objects",
15955
- type: "object",
15956
- required: ["object"],
15957
- properties: {
15958
- object: {
15959
- type: "object",
15960
- oneOf: validObjectRefs
15961
- }
15962
- },
15963
- definitions: {
15964
- type: validObjectDefs
15965
- }
15966
- };
15938
+ var ActorTypesList = [
15939
+ "person",
15940
+ "room",
15941
+ "service",
15942
+ "feed",
15943
+ "website",
15944
+ "platform"
15945
+ ];
15946
+ var TargetTypesList = [
15947
+ "person",
15948
+ "room",
15949
+ "service",
15950
+ "feed",
15951
+ "website",
15952
+ "platform",
15953
+ "address"
15954
+ ];
15955
+ var validActorRefs = ActorTypesList.map((type) => ({
15956
+ $ref: `#/definitions/type/${type}`
15957
+ }));
15958
+ var validTargetRefs = TargetTypesList.map((type) => ({
15959
+ $ref: `#/definitions/type/${type}`
15960
+ }));
15967
15961
 
15968
15962
  // src/schemas/activity-stream.ts
15969
- var validActorRefs = ActivityObjectSchema.properties.object.oneOf;
15970
- var validTargetRefs = ActivityObjectSchema.properties.object.oneOf;
15971
- var validObjectRefs2 = [];
15972
- for (const type of ObjectTypesList) {
15973
- validObjectRefs2.push({ $ref: `#/definitions/type/${type}` });
15974
- }
15975
15963
  var contextSchema = {
15976
- type: "string"
15964
+ type: "array",
15965
+ minItems: 3,
15966
+ maxItems: 3,
15967
+ items: {
15968
+ type: "string"
15969
+ },
15970
+ allOf: [
15971
+ {
15972
+ contains: {
15973
+ const: AS2_BASE_CONTEXT_URL
15974
+ }
15975
+ },
15976
+ {
15977
+ contains: {
15978
+ const: SOCKETHUB_BASE_CONTEXT_URL
15979
+ }
15980
+ }
15981
+ ]
15977
15982
  };
15978
15983
  var typeSchema = {
15979
15984
  type: "string"
@@ -15982,13 +15987,14 @@ var ActivityStreamSchema = {
15982
15987
  $id: "https://sockethub.org/schemas/v/activity-stream.json",
15983
15988
  description: "Schema for Sockethub Activity Streams",
15984
15989
  type: "object",
15985
- required: ["context", "type", "actor"],
15990
+ required: ["@context", "type", "actor"],
15991
+ additionalProperties: false,
15986
15992
  properties: {
15993
+ "@context": contextSchema,
15987
15994
  id: {
15988
15995
  type: "string"
15989
15996
  },
15990
15997
  type: typeSchema,
15991
- context: contextSchema,
15992
15998
  actor: {
15993
15999
  type: "object",
15994
16000
  oneOf: validActorRefs
@@ -15998,8 +16004,7 @@ var ActivityStreamSchema = {
15998
16004
  oneOf: validTargetRefs
15999
16005
  },
16000
16006
  object: {
16001
- type: "object",
16002
- oneOf: validObjectRefs2
16007
+ type: "object"
16003
16008
  },
16004
16009
  published: {
16005
16010
  type: "string",
@@ -16015,9 +16020,33 @@ var ActivityStreamSchema = {
16015
16020
  var PlatformSchema = {
16016
16021
  $id: "https://sockethub.org/schemas/v/platform.json",
16017
16022
  type: "object",
16018
- required: ["name", "version", "messages"],
16023
+ required: [
16024
+ "name",
16025
+ "version",
16026
+ "messages",
16027
+ "contextUrl",
16028
+ "contextVersion",
16029
+ "schemaVersion"
16030
+ ],
16019
16031
  additionalProperties: false,
16020
16032
  properties: {
16033
+ contextUrl: {
16034
+ title: "contextUrl",
16035
+ type: "string",
16036
+ format: "uri"
16037
+ },
16038
+ contextVersion: {
16039
+ title: "contextVersion",
16040
+ type: "string"
16041
+ },
16042
+ schemaVersion: {
16043
+ title: "schemaVersion",
16044
+ type: "string"
16045
+ },
16046
+ messageConstraints: {
16047
+ title: "messageConstraints",
16048
+ type: "object"
16049
+ },
16021
16050
  credentials: {
16022
16051
  title: "credentials",
16023
16052
  type: "object"
@@ -16026,6 +16055,10 @@ var PlatformSchema = {
16026
16055
  title: "messages",
16027
16056
  type: "object"
16028
16057
  },
16058
+ responses: {
16059
+ title: "responses",
16060
+ type: "object"
16061
+ },
16029
16062
  name: {
16030
16063
  title: "name",
16031
16064
  type: "string"
@@ -16038,11 +16071,6 @@ var PlatformSchema = {
16038
16071
  };
16039
16072
 
16040
16073
  // src/schemas/sockethub-config.ts
16041
- var connectConfigPlatforms = {
16042
- connectTimeoutMs: {
16043
- type: "number"
16044
- }
16045
- };
16046
16074
  var SockethubConfigSchema = {
16047
16075
  $id: "https://sockethub.org/schemas/v/sockethub-config.json",
16048
16076
  description: "Sockethub Config Schema",
@@ -16057,6 +16085,10 @@ var SockethubConfigSchema = {
16057
16085
  type: "boolean",
16058
16086
  default: true
16059
16087
  },
16088
+ info: {
16089
+ type: "boolean",
16090
+ default: false
16091
+ },
16060
16092
  logging: {
16061
16093
  type: "object",
16062
16094
  additionalProperties: false,
@@ -16077,71 +16109,76 @@ var SockethubConfigSchema = {
16077
16109
  }
16078
16110
  }
16079
16111
  },
16112
+ platforms: {
16113
+ type: "array",
16114
+ items: {
16115
+ type: "string"
16116
+ },
16117
+ default: [
16118
+ "@sockethub/platform-dummy",
16119
+ "@sockethub/platform-feeds",
16120
+ "@sockethub/platform-irc",
16121
+ "@sockethub/platform-metadata",
16122
+ "@sockethub/platform-xmpp"
16123
+ ]
16124
+ },
16080
16125
  packageConfig: {
16081
16126
  type: "object",
16082
16127
  properties: {
16083
- "@sockethub/activity-streams": {
16128
+ "@sockethub/platform-dummy": {
16084
16129
  type: "object",
16085
16130
  additionalProperties: false,
16086
16131
  properties: {
16087
- specialObjs: {
16088
- type: "array",
16089
- items: {
16090
- type: "string"
16091
- },
16092
- default: ["credentials"]
16093
- },
16094
- failOnUnknownObjectProperties: {
16095
- type: "boolean",
16096
- default: true
16097
- }
16132
+ greeting: { type: "string", default: "Hello" }
16098
16133
  }
16099
16134
  },
16100
- "@sockethub/platform-dummy": {
16135
+ "@sockethub/platform-feeds": {
16101
16136
  type: "object",
16102
16137
  additionalProperties: false,
16103
16138
  properties: {
16104
- greeting: {
16105
- type: "string",
16106
- default: "Hello"
16107
- }
16139
+ connectTimeoutMs: { type: "number" },
16140
+ allowPrivateAddresses: { type: "boolean" },
16141
+ concurrency: { type: "integer", minimum: 1 }
16108
16142
  }
16109
16143
  },
16110
- "@sockethub/platform-feeds": {
16144
+ "@sockethub/platform-irc": {
16111
16145
  type: "object",
16112
16146
  additionalProperties: false,
16113
16147
  properties: {
16114
- ...connectConfigPlatforms
16148
+ connectTimeoutMs: { type: "number" }
16115
16149
  }
16116
16150
  },
16117
- "@sockethub/platform-irc": {
16151
+ "@sockethub/platform-xmpp": {
16118
16152
  type: "object",
16119
16153
  additionalProperties: false,
16120
16154
  properties: {
16121
- ...connectConfigPlatforms
16155
+ connectTimeoutMs: { type: "number" }
16122
16156
  }
16123
16157
  },
16124
- "@sockethub/platform-xmpp": {
16158
+ "@sockethub/platform-metadata": {
16125
16159
  type: "object",
16126
16160
  additionalProperties: false,
16127
16161
  properties: {
16128
- ...connectConfigPlatforms
16162
+ allowPrivateAddresses: { type: "boolean" },
16163
+ concurrency: { type: "integer", minimum: 1 }
16129
16164
  }
16130
16165
  }
16131
16166
  }
16132
16167
  },
16133
- platforms: {
16134
- type: "array",
16135
- items: {
16136
- type: "string"
16137
- },
16138
- default: [
16139
- "@sockethub/platform-dummy",
16140
- "@sockethub/platform-feeds",
16141
- "@sockethub/platform-irc",
16142
- "@sockethub/platform-metadata",
16143
- "@sockethub/platform-xmpp"
16144
- ]
16168
+ credentialCheck: {
16169
+ type: "object",
16170
+ additionalProperties: false,
16171
+ properties: {
16172
+ reconnectIpSource: {
16173
+ type: "string",
16174
+ enum: ["socket", "proxy"],
16175
+ default: "socket"
16176
+ },
16177
+ proxyHeader: {
16178
+ type: "string",
16179
+ default: "x-forwarded-for"
16180
+ }
16181
+ }
16145
16182
  },
16146
16183
  public: {
16147
16184
  type: "object",
@@ -16180,6 +16217,22 @@ var SockethubConfigSchema = {
16180
16217
  blockDurationMs: {
16181
16218
  type: "number",
16182
16219
  default: 5000
16220
+ },
16221
+ maxConnectionsPerIp: {
16222
+ type: "number",
16223
+ minimum: 0,
16224
+ default: 0
16225
+ }
16226
+ }
16227
+ },
16228
+ limits: {
16229
+ type: "object",
16230
+ additionalProperties: false,
16231
+ properties: {
16232
+ maxPlatformInstances: {
16233
+ type: "number",
16234
+ minimum: 0,
16235
+ default: 0
16183
16236
  }
16184
16237
  }
16185
16238
  },
@@ -16237,6 +16290,30 @@ var SockethubConfigSchema = {
16237
16290
  path: {
16238
16291
  type: "string",
16239
16292
  default: "/sockethub"
16293
+ },
16294
+ cors: {
16295
+ type: "object",
16296
+ additionalProperties: false,
16297
+ properties: {
16298
+ origin: {
16299
+ type: "string",
16300
+ default: "*"
16301
+ }
16302
+ }
16303
+ }
16304
+ }
16305
+ },
16306
+ platformHeartbeat: {
16307
+ type: "object",
16308
+ additionalProperties: false,
16309
+ properties: {
16310
+ intervalMs: {
16311
+ type: "number",
16312
+ default: 5000
16313
+ },
16314
+ timeoutMs: {
16315
+ type: "number",
16316
+ default: 15000
16240
16317
  }
16241
16318
  }
16242
16319
  }
@@ -16259,11 +16336,15 @@ function parseMsg(error) {
16259
16336
  return err;
16260
16337
  }
16261
16338
  function getTypeList(msg) {
16262
- let types = [];
16263
- types.push(msg?.type);
16264
- for (const prop in msg) {
16265
- if (msg[prop]?.type) {
16266
- types = [...types, ...getTypeList(msg[prop])];
16339
+ const types = [];
16340
+ if (msg?.type) {
16341
+ types.push(msg.type);
16342
+ }
16343
+ const record = msg;
16344
+ for (const prop in record) {
16345
+ const value = record[prop];
16346
+ if (value && typeof value === "object" && "type" in value) {
16347
+ types.push(...getTypeList(value));
16267
16348
  }
16268
16349
  }
16269
16350
  return types;
@@ -16282,23 +16363,32 @@ function getPartsCount(error, types) {
16282
16363
  if (!errType) {
16283
16364
  return -1;
16284
16365
  }
16285
- if (!types[errType]) {
16366
+ const typeList = types[errType];
16367
+ if (!typeList) {
16286
16368
  return -1;
16287
16369
  }
16288
- if (!types[errType].includes(schemaType)) {
16370
+ if (!schemaType || !typeList.includes(schemaType)) {
16289
16371
  return -1;
16290
16372
  }
16291
16373
  const parts = error.instancePath.split("/");
16292
16374
  return parts.length;
16293
16375
  }
16294
16376
  function getTypes(msg) {
16377
+ if (!Array.isArray(msg["@context"])) {
16378
+ return {
16379
+ actor: [],
16380
+ target: [],
16381
+ object: getTypeList(msg)
16382
+ };
16383
+ }
16384
+ const stream = msg;
16295
16385
  return {
16296
- actor: getTypeList(msg.actor),
16297
- target: getTypeList(msg.target),
16298
- object: getTypeList(msg.context ? msg.object : msg)
16386
+ actor: getTypeList(stream.actor),
16387
+ target: getTypeList(stream.target),
16388
+ object: stream.object ? getTypeList(stream.object) : []
16299
16389
  };
16300
16390
  }
16301
- function getErrorMessage(msg, errors) {
16391
+ function getErrorMessage(msg, errors, options) {
16302
16392
  const types = getTypes(msg);
16303
16393
  let deepest_entry = 0;
16304
16394
  let highest_depth = -1;
@@ -16309,12 +16399,23 @@ function getErrorMessage(msg, errors) {
16309
16399
  deepest_entry = i;
16310
16400
  }
16311
16401
  }
16312
- return highest_depth >= 0 ? parseMsg(errors[deepest_entry]) : composeFinalError(errors[errors.length - 1]);
16402
+ return highest_depth >= 0 ? parseMsg(errors[deepest_entry]) : composeFinalError(errors[errors.length - 1], options);
16403
+ }
16404
+ function filterTypeList(types, options) {
16405
+ if (!options?.excludeTypes || options.excludeTypes.length === 0) {
16406
+ return types;
16407
+ }
16408
+ const exclude = new Set(options.excludeTypes);
16409
+ return types.filter((type) => !exclude.has(type));
16313
16410
  }
16314
- function composeFinalError(error) {
16411
+ function composeFinalError(error, options) {
16315
16412
  let msg;
16316
16413
  if (error.keyword === "oneOf") {
16317
- msg = `${error.instancePath}: ${error.message}: ` + `${ObjectTypesList.join(", ")}`;
16414
+ const instanceRoot = error.instancePath.split("/")[1];
16415
+ const pathScopedTypes = instanceRoot === "actor" ? ActorTypesList : instanceRoot === "target" ? TargetTypesList : ObjectTypesList;
16416
+ const filteredTypes = filterTypeList(pathScopedTypes, options);
16417
+ const typesList = filteredTypes.length > 0 ? filteredTypes : pathScopedTypes;
16418
+ msg = `${error.instancePath}: ${error.message}: ` + `${typesList.join(", ")}`;
16318
16419
  } else {
16319
16420
  msg = `${error.instancePath ? error.instancePath : "activity stream"}: ${error.message}`;
16320
16421
  }
@@ -16330,69 +16431,211 @@ import_ajv_formats.default(ajv);
16330
16431
  import_ajv_formats_draft2019.default(ajv);
16331
16432
  var schemaURL = "https://sockethub.org/schemas/v0";
16332
16433
  var schemas = {};
16434
+ var validationErrorOptions = {};
16435
+ var systemContextsRegistered = false;
16333
16436
  schemas[`${schemaURL}/activity-stream`] = ActivityStreamSchema;
16334
- schemas[`${schemaURL}/activity-object`] = ActivityObjectSchema;
16335
16437
  for (const uri in schemas) {
16336
16438
  ajv.addSchema(schemas[uri], uri);
16337
16439
  }
16338
- function handleValidation(schemaRef, msg, isObject = false) {
16440
+ function registerSystemContext(platformId, contextUrl) {
16441
+ registerPlatformContext(platformId, contextUrl, `${schemaURL}/context/${platformId}/messages`, `${schemaURL}/context/${platformId}/credentials`);
16442
+ const messageSchemaRef = `${schemaURL}/context/${platformId}/messages`;
16443
+ if (!ajv.getSchema(messageSchemaRef)) {
16444
+ ajv.addSchema({}, messageSchemaRef);
16445
+ }
16446
+ const credentialsSchemaRef = `${schemaURL}/context/${platformId}/credentials`;
16447
+ if (!ajv.getSchema(credentialsSchemaRef)) {
16448
+ ajv.addSchema({}, credentialsSchemaRef);
16449
+ }
16450
+ }
16451
+ function registerSystemPlatformContexts() {
16452
+ if (systemContextsRegistered) {
16453
+ return;
16454
+ }
16455
+ registerSystemContext(ERROR_PLATFORM_ID, ERROR_PLATFORM_CONTEXT_URL);
16456
+ registerSystemContext(INTERNAL_PLATFORM_ID, INTERNAL_PLATFORM_CONTEXT_URL);
16457
+ systemContextsRegistered = true;
16458
+ }
16459
+ registerSystemPlatformContexts();
16460
+ function handleValidation(schemaRef, msg) {
16339
16461
  const validator = ajv.getSchema(schemaRef);
16340
- let result;
16341
- if (isObject) {
16342
- result = validator({ object: msg });
16343
- } else {
16344
- result = validator(msg);
16462
+ if (!validator) {
16463
+ return `schema ${schemaRef} not found`;
16345
16464
  }
16465
+ const result = validator(msg);
16346
16466
  if (!result) {
16347
- let errorMessage = getErrorMessage(msg, validator.errors);
16348
- if (msg.context) {
16349
- errorMessage = `[${msg.context}] ${errorMessage}`;
16467
+ let errorMessage = getErrorMessage(msg, validator.errors, validationErrorOptions);
16468
+ if (Array.isArray(msg["@context"])) {
16469
+ const platformContextUrl = resolvePlatformContextUrl(msg);
16470
+ if (platformContextUrl) {
16471
+ const platformId = getPlatformIdByContextUrl(platformContextUrl);
16472
+ if (platformId) {
16473
+ errorMessage = `[${platformId}] ${errorMessage}`;
16474
+ }
16475
+ }
16350
16476
  }
16351
16477
  return errorMessage;
16352
16478
  }
16353
16479
  return "";
16354
16480
  }
16355
- function validateActivityObject(msg) {
16356
- return handleValidation(`${schemaURL}/activity-object`, msg, true);
16481
+ function setValidationErrorOptions(options) {
16482
+ validationErrorOptions = { ...validationErrorOptions, ...options };
16483
+ }
16484
+ var sockethubConfigValidator;
16485
+ function validateSockethubConfig(config) {
16486
+ if (!sockethubConfigValidator) {
16487
+ sockethubConfigValidator = ajv.compile(SockethubConfigSchema);
16488
+ }
16489
+ if (sockethubConfigValidator(config)) {
16490
+ return "";
16491
+ }
16492
+ return ajv.errorsText(sockethubConfigValidator.errors, {
16493
+ dataVar: "config"
16494
+ });
16357
16495
  }
16358
16496
  function validateActivityStream(msg) {
16359
- return handleValidation(`${schemaURL}/activity-stream`, msg);
16497
+ const streamValidationError = handleValidation(`${schemaURL}/activity-stream`, msg);
16498
+ if (streamValidationError) {
16499
+ return streamValidationError;
16500
+ }
16501
+ const platformContextUrl = resolvePlatformContextUrl(msg);
16502
+ if (!platformContextUrl) {
16503
+ return "activity streams must have exactly one registered platform context URL in @context";
16504
+ }
16505
+ const schemaId = getSchemaIdByContextUrl(platformContextUrl);
16506
+ if (!schemaId) {
16507
+ return `platform context URL ${platformContextUrl} does not have a registered message schema`;
16508
+ }
16509
+ return handleValidation(schemaId, msg);
16510
+ }
16511
+ function validateActivityStreamResponse(msg) {
16512
+ const platformContextUrl = resolvePlatformContextUrl(msg);
16513
+ if (!platformContextUrl) {
16514
+ return "";
16515
+ }
16516
+ const platformId = getPlatformIdByContextUrl(platformContextUrl);
16517
+ if (!platformId) {
16518
+ return "";
16519
+ }
16520
+ const responsesSchemaId = `${schemaURL}/context/${platformId}/responses`;
16521
+ if (!ajv.getSchema(responsesSchemaId)) {
16522
+ return "";
16523
+ }
16524
+ return handleValidation(responsesSchemaId, msg);
16360
16525
  }
16361
16526
  function validateCredentials(msg) {
16362
- if (!msg.context) {
16363
- return "credential activity streams must have a context set";
16527
+ if (!Array.isArray(msg["@context"])) {
16528
+ return "credential activity streams must have an @context set";
16364
16529
  }
16365
16530
  if (msg.type !== "credentials") {
16366
16531
  return "credential activity streams must have credentials set as type";
16367
16532
  }
16368
- return handleValidation(`${schemaURL}/context/${msg.context}/credentials`, msg);
16533
+ const streamValidationError = handleValidation(`${schemaURL}/activity-stream`, msg);
16534
+ if (streamValidationError) {
16535
+ return streamValidationError;
16536
+ }
16537
+ const platformContextUrl = resolvePlatformContextUrl(msg);
16538
+ if (!platformContextUrl) {
16539
+ return "credential activity streams must have exactly one registered platform context URL in @context";
16540
+ }
16541
+ const credentialsSchemaId = getCredentialsSchemaIdByContextUrl(platformContextUrl);
16542
+ if (!credentialsSchemaId) {
16543
+ return `platform context URL ${platformContextUrl} does not have a registered credentials schema`;
16544
+ }
16545
+ return handleValidation(credentialsSchemaId, msg);
16369
16546
  }
16370
16547
  function validatePlatformSchema(schema) {
16371
16548
  const validate = ajv.compile(PlatformSchema);
16372
16549
  const err = validate(schema);
16373
16550
  if (!err) {
16374
- return `platform schema failed to validate: ${validate.errors[0].instancePath} ${validate.errors[0].message}`;
16551
+ const validationError = validate.errors[0];
16552
+ let message = `${validationError.instancePath} ${validationError.message}`;
16553
+ if (validationError.keyword === "additionalProperties") {
16554
+ message += `: ${validationError.params.additionalProperty}`;
16555
+ }
16556
+ return `platform schema failed to validate: ${message}`;
16375
16557
  }
16376
16558
  return "";
16377
16559
  }
16378
16560
  function addPlatformSchema(schema, platform_type) {
16379
- ajv.addSchema(schema, `${schemaURL}/context/${platform_type}`);
16561
+ const schemaRef = `${schemaURL}/context/${platform_type}`;
16562
+ if (!ajv.getSchema(schemaRef)) {
16563
+ ajv.addSchema(schema, schemaRef);
16564
+ }
16380
16565
  }
16381
16566
  function getPlatformSchema(platform_type) {
16382
16567
  return ajv.getSchema(`${schemaURL}/context/${platform_type}`);
16383
16568
  }
16569
+ function addPlatformContext(platformId, platformContextUrl) {
16570
+ registerPlatformContext(platformId, platformContextUrl, `${schemaURL}/context/${platformId}/messages`, `${schemaURL}/context/${platformId}/credentials`);
16571
+ }
16572
+ function resolvePlatformId(msg) {
16573
+ const platformContextUrl = resolvePlatformContextUrl(msg);
16574
+ if (!platformContextUrl) {
16575
+ return null;
16576
+ }
16577
+ return getPlatformIdByContextUrl(platformContextUrl) ?? null;
16578
+ }
16579
+
16580
+ // src/activity-stream-helper.ts
16581
+ var stringRefKeys = {
16582
+ actor: "id",
16583
+ target: "id",
16584
+ object: "content"
16585
+ };
16586
+ function normalizeStringRef(value, primaryKey) {
16587
+ if (typeof value === "string") {
16588
+ return { [primaryKey]: value };
16589
+ }
16590
+ if (Array.isArray(value)) {
16591
+ return value.map((entry) => {
16592
+ if (typeof entry === "string") {
16593
+ return { id: entry };
16594
+ }
16595
+ return entry;
16596
+ });
16597
+ }
16598
+ return value;
16599
+ }
16600
+ function normalizeActivityStream(meta) {
16601
+ const stream = {
16602
+ ...meta
16603
+ };
16604
+ for (const key of Object.keys(stringRefKeys)) {
16605
+ if (key in stream) {
16606
+ stream[key] = normalizeStringRef(stream[key], stringRefKeys[key]);
16607
+ }
16608
+ }
16609
+ return stream;
16610
+ }
16384
16611
  export {
16612
+ validateSockethubConfig,
16385
16613
  validatePlatformSchema,
16386
16614
  validateCredentials,
16615
+ validateActivityStreamResponse,
16387
16616
  validateActivityStream,
16388
- validateActivityObject,
16617
+ setValidationErrorOptions,
16618
+ resolvePlatformId,
16619
+ registerSystemPlatformContexts,
16620
+ platformIdFromContext,
16621
+ normalizeActivityStream,
16389
16622
  getPlatformSchema,
16623
+ buildCanonicalContext,
16390
16624
  addPlatformSchema,
16625
+ addPlatformContext,
16391
16626
  SockethubConfigSchema,
16627
+ SOCKETHUB_BASE_CONTEXT_URL,
16392
16628
  PlatformSchema,
16629
+ PLATFORM_CONTEXT_PREFIX,
16630
+ ObjectTypesSchema,
16393
16631
  ObjectTypesList,
16632
+ InternalObjectTypesList,
16633
+ INTERNAL_PLATFORM_ID,
16634
+ INTERNAL_PLATFORM_CONTEXT_URL,
16635
+ ERROR_PLATFORM_ID,
16636
+ ERROR_PLATFORM_CONTEXT_URL,
16394
16637
  ActivityStreamSchema,
16395
- ActivityObjectSchema
16638
+ AS2_BASE_CONTEXT_URL
16396
16639
  };
16397
16640
 
16398
- //# debugId=6F40F71261F1E85264756E2164756E21
16641
+ //# debugId=E0C024B0EB3D053564756E2164756E21