@sockethub/schemas 3.0.0-alpha.12 → 3.0.0-alpha.14

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 (46) 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 +20 -41
  6. package/dist/context.js.map +3 -3
  7. package/dist/helpers/error-parser.d.ts +13 -0
  8. package/dist/helpers/objects.d.ts +122 -0
  9. package/dist/index.d.ts +9 -0
  10. package/dist/index.js +235 -218
  11. package/dist/index.js.map +12 -12
  12. package/dist/maps/context-map.json +2 -2
  13. package/dist/object-types.d.ts +2 -0
  14. package/dist/object-types.js +296 -0
  15. package/dist/object-types.js.map +12 -0
  16. package/dist/schemas/activity-stream.d.ts +161 -0
  17. package/dist/schemas/platform/feeds/v1/messages.schema.json +8 -17
  18. package/dist/schemas/platform/irc/v1/credentials.schema.json +71 -1
  19. package/dist/schemas/platform/irc/v1/messages.schema.json +84 -0
  20. package/dist/schemas/platform/metadata/v1/messages.schema.json +1 -16
  21. package/dist/schemas/platform/xmpp/v1/credentials.schema.json +2 -2
  22. package/dist/schemas/platform/xmpp/v1/messages.schema.json +108 -0
  23. package/dist/schemas/platform.d.ts +62 -0
  24. package/dist/schemas/sockethub-config.d.ts +316 -0
  25. package/{src/types.ts → dist/types.d.ts} +17 -45
  26. package/dist/validator.d.ts +26 -0
  27. package/package.json +13 -8
  28. package/src/context.ts +0 -125
  29. package/src/helpers/error-parser.ts +0 -160
  30. package/src/helpers/objects.ts +0 -283
  31. package/src/index.test.data.credentials.ts +0 -103
  32. package/src/index.test.data.objects.ts +0 -241
  33. package/src/index.test.data.platform.ts +0 -48
  34. package/src/index.test.data.streams.ts +0 -590
  35. package/src/index.test.ts +0 -127
  36. package/src/index.ts +0 -56
  37. package/src/schemas/activity-object.ts +0 -19
  38. package/src/schemas/activity-stream.ts +0 -75
  39. package/src/schemas/json/activity-object.json +0 -405
  40. package/src/schemas/json/activity-stream.json +0 -502
  41. package/src/schemas/json/platform.json +0 -48
  42. package/src/schemas/json/sockethub-config.json +0 -236
  43. package/src/schemas/platform.ts +0 -71
  44. package/src/schemas/sockethub-config.ts +0 -220
  45. package/src/types/ajv-formats-draft2019.d.ts +0 -5
  46. package/src/validator.ts +0 -207
package/dist/index.js CHANGED
@@ -4574,6 +4574,7 @@ var require_limitLength = __commonJS((exports) => {
4574
4574
  var require_pattern = __commonJS((exports) => {
4575
4575
  Object.defineProperty(exports, "__esModule", { value: true });
4576
4576
  var code_1 = require_code2();
4577
+ var util_1 = require_util();
4577
4578
  var codegen_1 = require_codegen();
4578
4579
  var error = {
4579
4580
  message: ({ schemaCode }) => (0, codegen_1.str)`must match pattern "${schemaCode}"`,
@@ -4586,10 +4587,18 @@ var require_pattern = __commonJS((exports) => {
4586
4587
  $data: true,
4587
4588
  error,
4588
4589
  code(cxt) {
4589
- const { data, $data, schema, schemaCode, it } = cxt;
4590
+ const { gen, data, $data, schema, schemaCode, it } = cxt;
4590
4591
  const u = it.opts.unicodeRegExp ? "u" : "";
4591
- const regExp = $data ? (0, codegen_1._)`(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
4592
- 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
+ }
4593
4602
  }
4594
4603
  };
4595
4604
  exports.default = def;
@@ -15760,12 +15769,24 @@ var INTERNAL_PLATFORM_CONTEXT_URL = "https://sockethub.org/ns/context/platform/s
15760
15769
  var platformContextToPlatformId = new Map;
15761
15770
  var platformContextToSchemaId = new Map;
15762
15771
  var platformContextToCredentialsSchemaId = new Map;
15763
- function buildCanonicalContext(platformContextUrl) {
15764
- return [
15765
- AS2_BASE_CONTEXT_URL,
15766
- SOCKETHUB_BASE_CONTEXT_URL,
15767
- platformContextUrl
15768
- ];
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);
15786
+ }
15787
+ }
15788
+ }
15789
+ return;
15769
15790
  }
15770
15791
  function normalizeContextArray(value) {
15771
15792
  if (!Array.isArray(value)) {
@@ -15800,18 +15821,7 @@ function getCredentialsSchemaIdByContextUrl(platformContextUrl) {
15800
15821
  }
15801
15822
 
15802
15823
  // src/helpers/objects.ts
15803
- var validObjectRefs = [];
15804
- var validObjectDefs = {};
15805
15824
  var ObjectTypesSchema = {
15806
- credentials: {
15807
- required: ["type"],
15808
- additionalProperties: true,
15809
- properties: {
15810
- type: {
15811
- enum: ["credentials"]
15812
- }
15813
- }
15814
- },
15815
15825
  feed: {
15816
15826
  required: ["id", "type"],
15817
15827
  additionalProperties: true,
@@ -15837,36 +15847,6 @@ var ObjectTypesSchema = {
15837
15847
  }
15838
15848
  }
15839
15849
  },
15840
- message: {
15841
- required: ["type", "content"],
15842
- additionalProperties: true,
15843
- properties: {
15844
- type: {
15845
- enum: ["message"]
15846
- },
15847
- id: {
15848
- type: "string"
15849
- },
15850
- name: {
15851
- type: "string"
15852
- },
15853
- content: {
15854
- type: "string"
15855
- }
15856
- }
15857
- },
15858
- me: {
15859
- required: ["type", "content"],
15860
- additionalProperties: true,
15861
- properties: {
15862
- type: {
15863
- enum: ["me"]
15864
- },
15865
- content: {
15866
- type: "string"
15867
- }
15868
- }
15869
- },
15870
15850
  person: {
15871
15851
  required: ["id", "type"],
15872
15852
  additionalProperties: true,
@@ -15943,71 +15923,6 @@ var ObjectTypesSchema = {
15943
15923
  }
15944
15924
  }
15945
15925
  },
15946
- attendance: {
15947
- required: ["type"],
15948
- additionalProperties: false,
15949
- properties: {
15950
- type: {
15951
- enum: ["attendance"]
15952
- },
15953
- members: {
15954
- type: "array",
15955
- items: {
15956
- type: "string"
15957
- }
15958
- }
15959
- }
15960
- },
15961
- presence: {
15962
- required: ["type"],
15963
- additionalProperties: false,
15964
- properties: {
15965
- type: {
15966
- enum: ["presence"]
15967
- },
15968
- presence: {
15969
- enum: ["away", "chat", "dnd", "xa", "offline", "online"]
15970
- },
15971
- role: {
15972
- enum: ["owner", "member", "participant", "admin"]
15973
- },
15974
- content: {
15975
- type: "string"
15976
- }
15977
- }
15978
- },
15979
- relationship: {
15980
- required: ["type", "relationship"],
15981
- additionalProperties: false,
15982
- properties: {
15983
- type: {
15984
- enum: ["relationship"]
15985
- },
15986
- relationship: {
15987
- enum: ["role"]
15988
- },
15989
- subject: {
15990
- type: "object",
15991
- oneOf: [{ $ref: "#/definitions/type/presence" }]
15992
- },
15993
- object: {
15994
- type: "object",
15995
- oneOf: validObjectRefs
15996
- }
15997
- }
15998
- },
15999
- topic: {
16000
- required: ["type"],
16001
- additionalProperties: false,
16002
- properties: {
16003
- type: {
16004
- enum: ["topic"]
16005
- },
16006
- content: {
16007
- type: "string"
16008
- }
16009
- }
16010
- },
16011
15926
  address: {
16012
15927
  required: ["type"],
16013
15928
  additionalProperties: false,
@@ -16016,18 +15931,6 @@ var ObjectTypesSchema = {
16016
15931
  enum: ["address"]
16017
15932
  }
16018
15933
  }
16019
- },
16020
- heartbeat: {
16021
- required: ["type", "timestamp"],
16022
- additionalProperties: false,
16023
- properties: {
16024
- type: {
16025
- enum: ["heartbeat"]
16026
- },
16027
- timestamp: {
16028
- type: "number"
16029
- }
16030
- }
16031
15934
  }
16032
15935
  };
16033
15936
  var InternalObjectTypesList = ["platform", "heartbeat"];
@@ -16055,36 +15958,8 @@ var validActorRefs = ActorTypesList.map((type) => ({
16055
15958
  var validTargetRefs = TargetTypesList.map((type) => ({
16056
15959
  $ref: `#/definitions/type/${type}`
16057
15960
  }));
16058
- for (const type of ObjectTypesList) {
16059
- if (type === "credentials") {
16060
- continue;
16061
- }
16062
- validObjectRefs.push({ $ref: `#/definitions/type/${type}` });
16063
- validObjectDefs[type] = ObjectTypesSchema[type];
16064
- }
16065
-
16066
- // src/schemas/activity-object.ts
16067
- var ActivityObjectSchema = {
16068
- $id: "https://sockethub.org/schemas/v/activity-object.json",
16069
- description: "Schema for Sockethub Activity Objects",
16070
- type: "object",
16071
- required: ["object"],
16072
- properties: {
16073
- object: {
16074
- type: "object",
16075
- oneOf: validObjectRefs
16076
- }
16077
- },
16078
- definitions: {
16079
- type: validObjectDefs
16080
- }
16081
- };
16082
15961
 
16083
15962
  // src/schemas/activity-stream.ts
16084
- var validObjectRefs2 = [];
16085
- for (const type of ObjectTypesList) {
16086
- validObjectRefs2.push({ $ref: `#/definitions/type/${type}` });
16087
- }
16088
15963
  var contextSchema = {
16089
15964
  type: "array",
16090
15965
  minItems: 3,
@@ -16113,6 +15988,7 @@ var ActivityStreamSchema = {
16113
15988
  description: "Schema for Sockethub Activity Streams",
16114
15989
  type: "object",
16115
15990
  required: ["@context", "type", "actor"],
15991
+ additionalProperties: false,
16116
15992
  properties: {
16117
15993
  "@context": contextSchema,
16118
15994
  id: {
@@ -16128,8 +16004,7 @@ var ActivityStreamSchema = {
16128
16004
  oneOf: validTargetRefs
16129
16005
  },
16130
16006
  object: {
16131
- type: "object",
16132
- oneOf: validObjectRefs2
16007
+ type: "object"
16133
16008
  },
16134
16009
  published: {
16135
16010
  type: "string",
@@ -16180,6 +16055,10 @@ var PlatformSchema = {
16180
16055
  title: "messages",
16181
16056
  type: "object"
16182
16057
  },
16058
+ responses: {
16059
+ title: "responses",
16060
+ type: "object"
16061
+ },
16183
16062
  name: {
16184
16063
  title: "name",
16185
16064
  type: "string"
@@ -16192,11 +16071,6 @@ var PlatformSchema = {
16192
16071
  };
16193
16072
 
16194
16073
  // src/schemas/sockethub-config.ts
16195
- var connectConfigPlatforms = {
16196
- connectTimeoutMs: {
16197
- type: "number"
16198
- }
16199
- };
16200
16074
  var SockethubConfigSchema = {
16201
16075
  $id: "https://sockethub.org/schemas/v/sockethub-config.json",
16202
16076
  description: "Sockethub Config Schema",
@@ -16211,6 +16085,10 @@ var SockethubConfigSchema = {
16211
16085
  type: "boolean",
16212
16086
  default: true
16213
16087
  },
16088
+ info: {
16089
+ type: "boolean",
16090
+ default: false
16091
+ },
16214
16092
  logging: {
16215
16093
  type: "object",
16216
16094
  additionalProperties: false,
@@ -16231,71 +16109,88 @@ var SockethubConfigSchema = {
16231
16109
  }
16232
16110
  }
16233
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
+ },
16234
16125
  packageConfig: {
16235
16126
  type: "object",
16236
16127
  properties: {
16237
- "@sockethub/activity-streams": {
16128
+ "@sockethub/platform-dummy": {
16238
16129
  type: "object",
16239
16130
  additionalProperties: false,
16240
16131
  properties: {
16241
- specialObjs: {
16242
- type: "array",
16243
- items: {
16244
- type: "string"
16245
- },
16246
- default: ["credentials"]
16247
- },
16248
- failOnUnknownObjectProperties: {
16249
- type: "boolean",
16250
- default: true
16251
- }
16132
+ greeting: { type: "string", default: "Hello" }
16252
16133
  }
16253
16134
  },
16254
- "@sockethub/platform-dummy": {
16135
+ "@sockethub/platform-feeds": {
16255
16136
  type: "object",
16256
16137
  additionalProperties: false,
16257
16138
  properties: {
16258
- greeting: {
16259
- type: "string",
16260
- default: "Hello"
16261
- }
16139
+ connectTimeoutMs: { type: "number" },
16140
+ allowPrivateAddresses: { type: "boolean" },
16141
+ concurrency: { type: "integer", minimum: 1 }
16262
16142
  }
16263
16143
  },
16264
- "@sockethub/platform-feeds": {
16144
+ "@sockethub/platform-irc": {
16265
16145
  type: "object",
16266
16146
  additionalProperties: false,
16267
16147
  properties: {
16268
- ...connectConfigPlatforms
16148
+ connectTimeoutMs: { type: "number" }
16269
16149
  }
16270
16150
  },
16271
- "@sockethub/platform-irc": {
16151
+ "@sockethub/platform-xmpp": {
16272
16152
  type: "object",
16273
16153
  additionalProperties: false,
16274
16154
  properties: {
16275
- ...connectConfigPlatforms
16155
+ connectTimeoutMs: { type: "number" }
16276
16156
  }
16277
16157
  },
16278
- "@sockethub/platform-xmpp": {
16158
+ "@sockethub/platform-metadata": {
16279
16159
  type: "object",
16280
16160
  additionalProperties: false,
16281
16161
  properties: {
16282
- ...connectConfigPlatforms
16162
+ allowPrivateAddresses: { type: "boolean" },
16163
+ concurrency: { type: "integer", minimum: 1 }
16283
16164
  }
16284
16165
  }
16285
16166
  }
16286
16167
  },
16287
- platforms: {
16288
- type: "array",
16289
- items: {
16290
- type: "string"
16291
- },
16292
- default: [
16293
- "@sockethub/platform-dummy",
16294
- "@sockethub/platform-feeds",
16295
- "@sockethub/platform-irc",
16296
- "@sockethub/platform-metadata",
16297
- "@sockethub/platform-xmpp"
16298
- ]
16168
+ credentials: {
16169
+ type: "object",
16170
+ additionalProperties: false,
16171
+ properties: {
16172
+ ttlMs: {
16173
+ type: "number",
16174
+ minimum: 0,
16175
+ default: 604800000,
16176
+ description: "Sliding TTL in milliseconds for per-session encrypted " + "credential keys in Redis, refreshed on every save and " + "read. A backstop against keys orphaned by crashes; " + "sessions normally delete their key on disconnect. " + "Size generously — idle sessions do not refresh it. " + "0 disables expiry."
16177
+ }
16178
+ }
16179
+ },
16180
+ credentialCheck: {
16181
+ type: "object",
16182
+ additionalProperties: false,
16183
+ properties: {
16184
+ reconnectIpSource: {
16185
+ type: "string",
16186
+ enum: ["socket", "proxy"],
16187
+ default: "socket"
16188
+ },
16189
+ proxyHeader: {
16190
+ type: "string",
16191
+ default: "x-forwarded-for"
16192
+ }
16193
+ }
16299
16194
  },
16300
16195
  public: {
16301
16196
  type: "object",
@@ -16334,6 +16229,22 @@ var SockethubConfigSchema = {
16334
16229
  blockDurationMs: {
16335
16230
  type: "number",
16336
16231
  default: 5000
16232
+ },
16233
+ maxConnectionsPerIp: {
16234
+ type: "number",
16235
+ minimum: 0,
16236
+ default: 0
16237
+ }
16238
+ }
16239
+ },
16240
+ limits: {
16241
+ type: "object",
16242
+ additionalProperties: false,
16243
+ properties: {
16244
+ maxPlatformInstances: {
16245
+ type: "number",
16246
+ minimum: 0,
16247
+ default: 0
16337
16248
  }
16338
16249
  }
16339
16250
  },
@@ -16391,6 +16302,59 @@ var SockethubConfigSchema = {
16391
16302
  path: {
16392
16303
  type: "string",
16393
16304
  default: "/sockethub"
16305
+ },
16306
+ cors: {
16307
+ type: "object",
16308
+ additionalProperties: false,
16309
+ properties: {
16310
+ origin: {
16311
+ type: "string",
16312
+ default: "*"
16313
+ }
16314
+ }
16315
+ }
16316
+ }
16317
+ },
16318
+ httpActions: {
16319
+ type: "object",
16320
+ additionalProperties: false,
16321
+ properties: {
16322
+ enabled: {
16323
+ type: "boolean",
16324
+ default: false
16325
+ },
16326
+ path: {
16327
+ type: "string",
16328
+ default: "/sockethub-http"
16329
+ },
16330
+ requireRequestId: {
16331
+ type: "boolean",
16332
+ default: true
16333
+ },
16334
+ maxMessagesPerRequest: {
16335
+ type: "number",
16336
+ minimum: 1,
16337
+ default: 20
16338
+ },
16339
+ maxPayloadBytes: {
16340
+ type: "number",
16341
+ minimum: 1,
16342
+ default: 262144
16343
+ },
16344
+ idempotencyTtlMs: {
16345
+ type: "number",
16346
+ minimum: 0,
16347
+ default: 300000
16348
+ },
16349
+ requestTimeoutMs: {
16350
+ type: "number",
16351
+ minimum: 0,
16352
+ default: 30000
16353
+ },
16354
+ idleTimeoutMs: {
16355
+ type: "number",
16356
+ minimum: 0,
16357
+ default: 15000
16394
16358
  }
16395
16359
  }
16396
16360
  },
@@ -16525,7 +16489,6 @@ var schemas = {};
16525
16489
  var validationErrorOptions = {};
16526
16490
  var systemContextsRegistered = false;
16527
16491
  schemas[`${schemaURL}/activity-stream`] = ActivityStreamSchema;
16528
- schemas[`${schemaURL}/activity-object`] = ActivityObjectSchema;
16529
16492
  for (const uri in schemas) {
16530
16493
  ajv.addSchema(schemas[uri], uri);
16531
16494
  }
@@ -16549,17 +16512,12 @@ function registerSystemPlatformContexts() {
16549
16512
  systemContextsRegistered = true;
16550
16513
  }
16551
16514
  registerSystemPlatformContexts();
16552
- function handleValidation(schemaRef, msg, isObject = false) {
16515
+ function handleValidation(schemaRef, msg) {
16553
16516
  const validator = ajv.getSchema(schemaRef);
16554
16517
  if (!validator) {
16555
16518
  return `schema ${schemaRef} not found`;
16556
16519
  }
16557
- let result;
16558
- if (isObject) {
16559
- result = validator({ object: msg });
16560
- } else {
16561
- result = validator(msg);
16562
- }
16520
+ const result = validator(msg);
16563
16521
  if (!result) {
16564
16522
  let errorMessage = getErrorMessage(msg, validator.errors, validationErrorOptions);
16565
16523
  if (Array.isArray(msg["@context"])) {
@@ -16578,8 +16536,17 @@ function handleValidation(schemaRef, msg, isObject = false) {
16578
16536
  function setValidationErrorOptions(options) {
16579
16537
  validationErrorOptions = { ...validationErrorOptions, ...options };
16580
16538
  }
16581
- function validateActivityObject(msg) {
16582
- return handleValidation(`${schemaURL}/activity-object`, msg, true);
16539
+ var sockethubConfigValidator;
16540
+ function validateSockethubConfig(config) {
16541
+ if (!sockethubConfigValidator) {
16542
+ sockethubConfigValidator = ajv.compile(SockethubConfigSchema);
16543
+ }
16544
+ if (sockethubConfigValidator(config)) {
16545
+ return "";
16546
+ }
16547
+ return ajv.errorsText(sockethubConfigValidator.errors, {
16548
+ dataVar: "config"
16549
+ });
16583
16550
  }
16584
16551
  function validateActivityStream(msg) {
16585
16552
  const streamValidationError = handleValidation(`${schemaURL}/activity-stream`, msg);
@@ -16596,6 +16563,21 @@ function validateActivityStream(msg) {
16596
16563
  }
16597
16564
  return handleValidation(schemaId, msg);
16598
16565
  }
16566
+ function validateActivityStreamResponse(msg) {
16567
+ const platformContextUrl = resolvePlatformContextUrl(msg);
16568
+ if (!platformContextUrl) {
16569
+ return "";
16570
+ }
16571
+ const platformId = getPlatformIdByContextUrl(platformContextUrl);
16572
+ if (!platformId) {
16573
+ return "";
16574
+ }
16575
+ const responsesSchemaId = `${schemaURL}/context/${platformId}/responses`;
16576
+ if (!ajv.getSchema(responsesSchemaId)) {
16577
+ return "";
16578
+ }
16579
+ return handleValidation(responsesSchemaId, msg);
16580
+ }
16599
16581
  function validateCredentials(msg) {
16600
16582
  if (!Array.isArray(msg["@context"])) {
16601
16583
  return "credential activity streams must have an @context set";
@@ -16621,7 +16603,12 @@ function validatePlatformSchema(schema) {
16621
16603
  const validate = ajv.compile(PlatformSchema);
16622
16604
  const err = validate(schema);
16623
16605
  if (!err) {
16624
- return `platform schema failed to validate: ${validate.errors[0].instancePath} ${validate.errors[0].message}`;
16606
+ const validationError = validate.errors[0];
16607
+ let message = `${validationError.instancePath} ${validationError.message}`;
16608
+ if (validationError.keyword === "additionalProperties") {
16609
+ message += `: ${validationError.params.additionalProperty}`;
16610
+ }
16611
+ return `platform schema failed to validate: ${message}`;
16625
16612
  }
16626
16613
  return "";
16627
16614
  }
@@ -16639,24 +16626,54 @@ function addPlatformContext(platformId, platformContextUrl) {
16639
16626
  }
16640
16627
  function resolvePlatformId(msg) {
16641
16628
  const platformContextUrl = resolvePlatformContextUrl(msg);
16642
- if (platformContextUrl) {
16643
- const id = getPlatformIdByContextUrl(platformContextUrl);
16644
- if (id)
16645
- return id;
16629
+ if (!platformContextUrl) {
16630
+ return null;
16631
+ }
16632
+ return getPlatformIdByContextUrl(platformContextUrl) ?? null;
16633
+ }
16634
+
16635
+ // src/activity-stream-helper.ts
16636
+ var stringRefKeys = {
16637
+ actor: "id",
16638
+ target: "id",
16639
+ object: "content"
16640
+ };
16641
+ function normalizeStringRef(value, primaryKey) {
16642
+ if (typeof value === "string") {
16643
+ return { [primaryKey]: value };
16644
+ }
16645
+ if (Array.isArray(value)) {
16646
+ return value.map((entry) => {
16647
+ if (typeof entry === "string") {
16648
+ return { id: entry };
16649
+ }
16650
+ return entry;
16651
+ });
16646
16652
  }
16647
- if (typeof msg.platform === "string" && msg.platform) {
16648
- return msg.platform;
16653
+ return value;
16654
+ }
16655
+ function normalizeActivityStream(meta) {
16656
+ const stream = {
16657
+ ...meta
16658
+ };
16659
+ for (const key of Object.keys(stringRefKeys)) {
16660
+ if (key in stream) {
16661
+ stream[key] = normalizeStringRef(stream[key], stringRefKeys[key]);
16662
+ }
16649
16663
  }
16650
- return null;
16664
+ return stream;
16651
16665
  }
16652
16666
  export {
16667
+ validateSockethubConfig,
16653
16668
  validatePlatformSchema,
16654
16669
  validateCredentials,
16670
+ validateActivityStreamResponse,
16655
16671
  validateActivityStream,
16656
- validateActivityObject,
16657
16672
  setValidationErrorOptions,
16658
16673
  resolvePlatformId,
16659
16674
  registerSystemPlatformContexts,
16675
+ platformIdFromContext,
16676
+ normalizeActivityStream,
16660
16677
  getPlatformSchema,
16661
16678
  buildCanonicalContext,
16662
16679
  addPlatformSchema,
@@ -16665,6 +16682,7 @@ export {
16665
16682
  SOCKETHUB_BASE_CONTEXT_URL,
16666
16683
  PlatformSchema,
16667
16684
  PLATFORM_CONTEXT_PREFIX,
16685
+ ObjectTypesSchema,
16668
16686
  ObjectTypesList,
16669
16687
  InternalObjectTypesList,
16670
16688
  INTERNAL_PLATFORM_ID,
@@ -16672,8 +16690,7 @@ export {
16672
16690
  ERROR_PLATFORM_ID,
16673
16691
  ERROR_PLATFORM_CONTEXT_URL,
16674
16692
  ActivityStreamSchema,
16675
- ActivityObjectSchema,
16676
16693
  AS2_BASE_CONTEXT_URL
16677
16694
  };
16678
16695
 
16679
- //# debugId=6297C1FC6C040BA364756E2164756E21
16696
+ //# debugId=9992B63BF86F71E964756E2164756E21