@cratis/chronicle 6.68.0 → 6.69.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.
- package/dist/externalServices/ExternalServiceBuilder.d.ts +1 -1
- package/dist/externalServices/ExternalServiceBuilder.d.ts.map +1 -1
- package/dist/externalServices/ExternalServiceBuilder.js +2 -2
- package/dist/externalServices/ExternalServiceBuilder.js.map +1 -1
- package/dist/externalServices/IExternalServiceBuilder.d.ts +2 -1
- package/dist/externalServices/IExternalServiceBuilder.d.ts.map +1 -1
- package/dist/externalServices/for_ExternalServices/given/an_external_service_registration.d.ts +8 -0
- package/dist/externalServices/for_ExternalServices/given/an_external_service_registration.d.ts.map +1 -0
- package/dist/externalServices/for_ExternalServices/given/an_external_service_registration.js +20 -0
- package/dist/externalServices/for_ExternalServices/given/an_external_service_registration.js.map +1 -0
- package/dist/testing/ConstraintKey.d.ts.map +1 -1
- package/dist/testing/ConstraintKey.js +11 -6
- package/dist/testing/ConstraintKey.js.map +1 -1
- package/dist/testing/MeasuredCaseFolding.d.ts +14 -0
- package/dist/testing/MeasuredCaseFolding.d.ts.map +1 -0
- package/dist/testing/MeasuredCaseFolding.js +17 -0
- package/dist/testing/MeasuredCaseFolding.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webhooks/IWebhookDefinitionBuilder.d.ts +2 -1
- package/dist/webhooks/IWebhookDefinitionBuilder.d.ts.map +1 -1
- package/dist/webhooks/WebhookDefinitionBuilder.d.ts +1 -1
- package/dist/webhooks/WebhookDefinitionBuilder.d.ts.map +1 -1
- package/dist/webhooks/WebhookDefinitionBuilder.js +2 -2
- package/dist/webhooks/WebhookDefinitionBuilder.js.map +1 -1
- package/dist/webhooks/for_Webhooks/given/a_webhook_registration.d.ts +8 -0
- package/dist/webhooks/for_Webhooks/given/a_webhook_registration.d.ts.map +1 -0
- package/dist/webhooks/for_Webhooks/given/a_webhook_registration.js +20 -0
- package/dist/webhooks/for_Webhooks/given/a_webhook_registration.js.map +1 -0
- package/externalServices/ExternalServiceBuilder.ts +2 -2
- package/externalServices/IExternalServiceBuilder.ts +2 -1
- package/externalServices/for_ExternalServices/given/an_external_service_registration.ts +23 -0
- package/externalServices/for_ExternalServices/when_registering_with_an_oauth_scope.spec.ts +42 -0
- package/externalServices/for_ExternalServices/when_registering_without_an_oauth_scope.spec.ts +44 -0
- package/package.json +1 -1
- package/testing/ConstraintKey.ts +11 -7
- package/testing/EventScenario.fixtures.spec.ts +1 -1
- package/testing/MeasuredCaseFolding.ts +22 -0
- package/testing/for_EventScenario/when_appending_case_folded_text/case_folded_text.fixture.ts +160 -0
- package/testing/for_EventScenario/when_appending_case_folded_text/with_case_folded_text.legacy.spec.ts +14 -0
- package/testing/for_EventScenario/when_appending_case_folded_text/with_case_folded_text.standard.spec.ts +13 -0
- package/webhooks/IWebhookDefinitionBuilder.ts +2 -1
- package/webhooks/WebhookDefinitionBuilder.ts +2 -2
- package/webhooks/for_Webhooks/given/a_webhook_registration.ts +25 -0
- package/webhooks/for_Webhooks/when_registering_with_an_oauth_scope.spec.ts +42 -0
- package/webhooks/for_Webhooks/when_registering_without_an_oauth_scope.spec.ts +43 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebhookDefinitionBuilder.d.ts","sourceRoot":"","sources":["../../webhooks/WebhookDefinitionBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAMH,KAAK,iBAAiB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAA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Id, clientSecret) {
|
|
53
|
+
withOAuth(authority, clientId, clientSecret, scope) {
|
|
54
54
|
const value = {
|
|
55
55
|
Authority: authority,
|
|
56
56
|
ClientId: clientId,
|
|
57
57
|
ClientSecret: clientSecret,
|
|
58
|
-
Scope: ''
|
|
58
|
+
Scope: scope ?? ''
|
|
59
59
|
};
|
|
60
60
|
this._authorization = {
|
|
61
61
|
Value0: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebhookDefinitionBuilder.js","sourceRoot":"","sources":["../../webhooks/WebhookDefinitionBuilder.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,OAAO,EACH,uBAAuB,EAM1B,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAKvE;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAYJ,qBAAqB;IAXjC,WAAW,GAAG,IAAI,GAAG,EAAe,CAAC;IACrC,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC9C,gBAAgB,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC;IAClD,cAAc,CAAgF;IAC9F,aAAa,GAAG,IAAI,CAAC;IACrB,SAAS,GAAG,IAAI,CAAC;IAEzB;;;OAGG;IACH,YAA6B,qBAAkC;qCAAlC,qBAAqB;IAAgB,CAAC;IAEnE,kBAAkB;IAClB,eAAe,CAAC,eAAgC;QAC5C,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC,KAAK,CAAC;QAC9C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,kBAAkB;IAClB,aAAa,CAAC,QAAgB,EAAE,QAAgB;QAC5C,MAAM,KAAK,GAAuB;YAC9B,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ;SACrB,CAAC;QACF,IAAI,CAAC,cAAc,GAAG;YAClB,MAAM,E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,CAAC;gBAC1C,eAAe,EAAE,SAAS;aAC7B;YACD,YAAY,EAAE,IAAI,CAAC,aAAa;YAChC,QAAQ,EAAE,IAAI,CAAC,SAAS;YACxB,eAAe,EAAE,CAAC,IAAI,CAAC,aAAa;YACpC,UAAU,EAAE,CAAC,IAAI,CAAC,SAAS;YAC3B,kBAAkB,EAAE,uBAAuB,CAAC,aAAa;SAC5D,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AddWebhooksRequest } from '@cratis/chronicle.contracts';
|
|
2
|
+
import { Webhooks } from '../../Webhooks.js';
|
|
3
|
+
export declare class a_webhook_registration {
|
|
4
|
+
sent: AddWebhooksRequest;
|
|
5
|
+
readonly webhooks: Webhooks;
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=a_webhook_registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a_webhook_registration.d.ts","sourceRoot":"","sources":["../../../../webhooks/for_Webhooks/given/a_webhook_registration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAIjE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,qBAAa,sBAAsB;IAC/B,IAAI,qBAAsC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B,cAUC;CACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
import { AddWebhooksRequest } from '@cratis/chronicle.contracts';
|
|
4
|
+
import { Webhooks } from '../../Webhooks.js';
|
|
5
|
+
export class a_webhook_registration {
|
|
6
|
+
sent = AddWebhooksRequest.fromPartial({});
|
|
7
|
+
webhooks;
|
|
8
|
+
constructor() {
|
|
9
|
+
const connection = {
|
|
10
|
+
webhooks: {
|
|
11
|
+
addWebhooks: async (request) => {
|
|
12
|
+
this.sent = request;
|
|
13
|
+
return { IsAuthorized: true, ValidationResults: [], ExceptionMessages: [] };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
this.webhooks = new Webhooks('store', connection, { all: [] }, {});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=a_webhook_registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a_webhook_registration.js","sourceRoot":"","sources":["../../../../webhooks/for_Webhooks/given/a_webhook_registration.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAIjE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,OAAO,sBAAsB;IAC/B,IAAI,GAAG,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACjC,QAAQ,CAAW;IAE5B;QACI,MAAM,UAAU,GAAG;YACf,QAAQ,EAAE;gBACN,WAAW,EAAE,KAAK,EAAE,OAA2B,EAAE,EAAE;oBAC/C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;oBACpB,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC;gBAChF,CAAC;aACJ;SAC8B,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,EAAE,EAA4B,EAAE,EAA8B,CAAC,CAAC;IAC7H,CAAC;CACJ"}
|
|
@@ -52,11 +52,11 @@ export class ExternalServiceBuilder implements IExternalServiceBuilder {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/** @inheritdoc */
|
|
55
|
-
withOAuth(authority: string, clientId: string, clientSecret: string): IExternalServiceBuilder {
|
|
55
|
+
withOAuth(authority: string, clientId: string, clientSecret: string, scope?: string): IExternalServiceBuilder {
|
|
56
56
|
this._authorization = {
|
|
57
57
|
Value0: undefined,
|
|
58
58
|
Value1: undefined,
|
|
59
|
-
Value2: { Authority: authority, ClientId: clientId, ClientSecret: clientSecret, Scope: '' }
|
|
59
|
+
Value2: { Authority: authority, ClientId: clientId, ClientSecret: clientSecret, Scope: scope ?? '' }
|
|
60
60
|
};
|
|
61
61
|
return this;
|
|
62
62
|
}
|
|
@@ -32,9 +32,10 @@ export interface IExternalServiceBuilder {
|
|
|
32
32
|
* @param authority - The OAuth authority.
|
|
33
33
|
* @param clientId - The OAuth client id.
|
|
34
34
|
* @param clientSecret - The OAuth client secret.
|
|
35
|
+
* @param scope - Optional space-delimited OAuth scope.
|
|
35
36
|
* @returns The builder for chaining.
|
|
36
37
|
*/
|
|
37
|
-
withOAuth(authority: string, clientId: string, clientSecret: string): IExternalServiceBuilder;
|
|
38
|
+
withOAuth(authority: string, clientId: string, clientSecret: string, scope?: string): IExternalServiceBuilder;
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Adds a header to send with every HTTP request.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { AddExternalServicesRequest } from '@cratis/chronicle.contracts';
|
|
5
|
+
import type { ChronicleConnection } from '../../../connection/index.js';
|
|
6
|
+
import { ExternalServices } from '../../ExternalServices.js';
|
|
7
|
+
|
|
8
|
+
export class an_external_service_registration {
|
|
9
|
+
sent = AddExternalServicesRequest.fromPartial({});
|
|
10
|
+
readonly services: ExternalServices;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
const connection = {
|
|
14
|
+
externalServices: {
|
|
15
|
+
addExternalServices: async (request: AddExternalServicesRequest) => {
|
|
16
|
+
this.sent = request;
|
|
17
|
+
return { IsAuthorized: true, ValidationResults: [], ExceptionMessages: [] };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
} as unknown as ChronicleConnection;
|
|
21
|
+
this.services = new ExternalServices('store', connection);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { AddExternalServicesRequest, OAuthAuthorization } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
6
|
+
import type { IExternalServiceBuilder } from '../IExternalServiceBuilder.js';
|
|
7
|
+
import { an_external_service_registration } from './given/an_external_service_registration.js';
|
|
8
|
+
|
|
9
|
+
chai.should();
|
|
10
|
+
|
|
11
|
+
describe.each(['orders.read orders.write', ' orders.read orders.write '])('when registering an external service with OAuth scope "%s"', scope => {
|
|
12
|
+
let context: an_external_service_registration;
|
|
13
|
+
let oauth: OAuthAuthorization;
|
|
14
|
+
let request: AddExternalServicesRequest;
|
|
15
|
+
let builder: IExternalServiceBuilder;
|
|
16
|
+
let returnedBuilder: IExternalServiceBuilder;
|
|
17
|
+
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
context = new an_external_service_registration();
|
|
20
|
+
await context.services.register('OrdersApi', configuration => {
|
|
21
|
+
builder = configuration.http('https://example.test');
|
|
22
|
+
returnedBuilder = builder.withOAuth('https://auth.example.test', 'fake-client', 'fake-secret', scope);
|
|
23
|
+
returnedBuilder.withHeader('x-source', 'fake-app');
|
|
24
|
+
});
|
|
25
|
+
request = AddExternalServicesRequest.decode(AddExternalServicesRequest.encode(context.sent).finish());
|
|
26
|
+
oauth = request.ExternalServices[0].Endpoint!.Http!.Authorization!.Value2!;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return the original builder', () => returnedBuilder.should.equal(builder));
|
|
30
|
+
it('should keep the event store', () => request.EventStore.should.equal('store'));
|
|
31
|
+
it('should select OAuth authorization', () => chai.expect(oauth).not.to.be.undefined);
|
|
32
|
+
it('should leave basic authorization unset', () => chai.expect(request.ExternalServices[0].Endpoint!.Http!.Authorization!.Value0).to.be.undefined);
|
|
33
|
+
it('should leave bearer authorization unset', () => chai.expect(request.ExternalServices[0].Endpoint!.Http!.Authorization!.Value1).to.be.undefined);
|
|
34
|
+
it('should preserve credentials and scope through the request codec', () => oauth.should.deep.equal({
|
|
35
|
+
Authority: 'https://auth.example.test', ClientId: 'fake-client', ClientSecret: 'fake-secret', Scope: scope
|
|
36
|
+
}));
|
|
37
|
+
it('should retain chained headers', () => request.ExternalServices[0].Endpoint!.Http!.Headers['x-source'].should.equal('fake-app'));
|
|
38
|
+
// The pinned 19.153.0 externalservices contract uses length-delimited field 4 (tag 0x22) for Scope.
|
|
39
|
+
it('should encode scope as protobuf field four', () => OAuthAuthorization.encode({
|
|
40
|
+
...oauth, Authority: '', ClientId: '', ClientSecret: ''
|
|
41
|
+
}).finish().should.deep.equal(Uint8Array.from([0x22, scope.length, ...new TextEncoder().encode(scope)])));
|
|
42
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { AddExternalServicesRequest, OAuthAuthorization } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
6
|
+
import { an_external_service_registration } from './given/an_external_service_registration.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
|
|
10
|
+
describe.each([
|
|
11
|
+
{ condition: 'omitted', scope: undefined },
|
|
12
|
+
{ condition: 'empty', scope: '' },
|
|
13
|
+
{ condition: 'undefined', scope: undefined },
|
|
14
|
+
{ condition: 'null at runtime', scope: null as unknown as string }
|
|
15
|
+
])('when registering an external service with $condition OAuth scope', ({ condition, scope }) => {
|
|
16
|
+
let context: an_external_service_registration;
|
|
17
|
+
let oauth: OAuthAuthorization;
|
|
18
|
+
let request: AddExternalServicesRequest;
|
|
19
|
+
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
context = new an_external_service_registration();
|
|
22
|
+
await context.services.register('OrdersApi', builder => {
|
|
23
|
+
builder.http('https://example.test');
|
|
24
|
+
const configured = condition === 'omitted'
|
|
25
|
+
? builder.withOAuth('https://auth.example.test', 'fake-client', 'fake-secret')
|
|
26
|
+
: builder.withOAuth('https://auth.example.test', 'fake-client', 'fake-secret', scope);
|
|
27
|
+
configured.withHeader('x-source', 'fake-app');
|
|
28
|
+
});
|
|
29
|
+
request = AddExternalServicesRequest.decode(AddExternalServicesRequest.encode(context.sent).finish());
|
|
30
|
+
oauth = request.ExternalServices[0].Endpoint!.Http!.Authorization!.Value2!;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should normalize scope before encoding', () => context.sent.ExternalServices[0].Endpoint!.Http!.Authorization!.Value2!.Scope.should.equal(''));
|
|
34
|
+
it('should select OAuth authorization', () => chai.expect(oauth).not.to.be.undefined);
|
|
35
|
+
it('should leave basic authorization unset', () => chai.expect(request.ExternalServices[0].Endpoint!.Http!.Authorization!.Value0).to.be.undefined);
|
|
36
|
+
it('should leave bearer authorization unset', () => chai.expect(request.ExternalServices[0].Endpoint!.Http!.Authorization!.Value1).to.be.undefined);
|
|
37
|
+
it('should preserve credentials and default scope through the request codec', () => oauth.should.deep.equal({
|
|
38
|
+
Authority: 'https://auth.example.test', ClientId: 'fake-client', ClientSecret: 'fake-secret', Scope: ''
|
|
39
|
+
}));
|
|
40
|
+
it('should retain chained headers', () => request.ExternalServices[0].Endpoint!.Http!.Headers['x-source'].should.equal('fake-app'));
|
|
41
|
+
it('should omit the default scope field from the wire', () => OAuthAuthorization.encode({
|
|
42
|
+
...oauth, Authority: '', ClientId: '', ClientSecret: ''
|
|
43
|
+
}).finish().should.deep.equal(new Uint8Array()));
|
|
44
|
+
});
|
package/package.json
CHANGED
package/testing/ConstraintKey.ts
CHANGED
|
@@ -7,8 +7,9 @@ import type { ConstraintCapture } from '../events/constraints/ConstraintBuilder.
|
|
|
7
7
|
import type { JsonSchema } from '../schemas/JsonSchema.js';
|
|
8
8
|
import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
|
|
9
9
|
import { isMeasuredNumericFormat, isMeasuredText, measuredNumericKey } from './MeasuredConstraintKeys.js';
|
|
10
|
+
import { isMeasuredCasingShape, isMeasuredCasingText, measuredLowerInvariant } from './MeasuredCaseFolding.js';
|
|
10
11
|
|
|
11
|
-
type KeyContext = { name: string; fractions: boolean; measured: boolean };
|
|
12
|
+
type KeyContext = { name: string; fractions: boolean; measured: boolean; casing: boolean };
|
|
12
13
|
type Claim = { key: string; parts: Array<{ property: string; raw: string }> };
|
|
13
14
|
|
|
14
15
|
// Only characters captured by the packaged oracle, not every valid event-content character.
|
|
@@ -54,14 +55,14 @@ function schemaNumericKey(value: unknown, context: KeyContext, format: string |
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
function scalarKey(value: unknown, context: KeyContext): string {
|
|
57
|
-
if (typeof value === 'string' && isSupportedString(value, context
|
|
58
|
+
if (typeof value === 'string' && isSupportedString(value, context)) return value;
|
|
58
59
|
if (typeof value === 'boolean') return value ? 'True' : 'False';
|
|
59
60
|
throw new UnsupportedEventSequenceOperation('artifacts.constraints', context.name,
|
|
60
61
|
'Only fixture-backed scalar string and boolean keys are supported.');
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
function isSupportedString(value: string,
|
|
64
|
-
return provenString.test(value) || measured && isMeasuredText(value);
|
|
64
|
+
function isSupportedString(value: string, context: KeyContext): boolean {
|
|
65
|
+
return provenString.test(value) || context.measured && isMeasuredText(value) || context.casing && isMeasuredCasingText(value);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
function supportsFractions(capture: ConstraintCapture): boolean {
|
|
@@ -79,8 +80,10 @@ function hasPropertyRemovals(capture: ConstraintCapture): boolean {
|
|
|
79
80
|
return unique.removedWithEventTypeId !== undefined || !!unique.removedWithEventTypeIds?.length;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
function normalizedKey(joined: string, ignoreCasing: boolean, name: string): string {
|
|
83
|
+
function normalizedKey(joined: string, ignoreCasing: boolean, name: string, casing: boolean): string {
|
|
83
84
|
if (!ignoreCasing) return joined;
|
|
85
|
+
// Scalars were admitted by isMeasuredCasingText, so the measured mapping is total for this text.
|
|
86
|
+
if (casing) return measuredLowerInvariant(joined);
|
|
84
87
|
// The pinned kernel's ToLowerInvariant is proven only for the existing ASCII domain.
|
|
85
88
|
if (!/^[\x20-\x7e]*$/.test(joined)) {
|
|
86
89
|
throw new UnsupportedEventSequenceOperation('artifacts.constraints', name,
|
|
@@ -96,9 +99,10 @@ export function claimOf(name: string, capture: ConstraintCapture, event: Appende
|
|
|
96
99
|
const properties = unique.eventDefinitions.find(entry => entry.eventTypeId === event.eventType.id.value)?.properties;
|
|
97
100
|
if (properties === undefined) return undefined;
|
|
98
101
|
const fractions = options.isolated && supportsFractions(capture);
|
|
99
|
-
const
|
|
102
|
+
const casing = options.isolated && isMeasuredCasingShape(unique, Object.values(capture.scope).some(Boolean), hasPropertyRemovals(capture));
|
|
103
|
+
const context = { name, fractions, measured: fractions && unique.eventDefinitions.length === 1, casing };
|
|
100
104
|
const parts = properties.map(property => ({ property,
|
|
101
105
|
raw: kernelKeyString(event.content[property], context, options.schema?.properties?.[property]) }));
|
|
102
106
|
const joined = parts.map(part => part.raw).join('-');
|
|
103
|
-
return { key: createHash('sha256').update(normalizedKey(joined, unique.ignoreCasing, name)).digest('hex'), parts };
|
|
107
|
+
return { key: createHash('sha256').update(normalizedKey(joined, unique.ignoreCasing, name, casing)).digest('hex'), parts };
|
|
104
108
|
}
|
|
@@ -61,7 +61,7 @@ const fixtures = readdirSync(directory).filter(name => name.endsWith('.json') &&
|
|
|
61
61
|
'constraints-event-type-siblings.json', 'constraints-composite.json',
|
|
62
62
|
'constraints-ignore-casing.json', 'constraints-scopes.json', 'constraints-field-types.json', 'constraints-event-sequences.json',
|
|
63
63
|
'constraints-field-combinations.json', 'constraints-removal-combinations.json', 'constraints-overlapping-definitions.json',
|
|
64
|
-
'constraints-fractional-field-types.json', 'constraints-fractional-collisions.json', 'constraints-field-key-measurements.json'].includes(name)).map(name => ({
|
|
64
|
+
'constraints-fractional-field-types.json', 'constraints-fractional-collisions.json', 'constraints-field-key-measurements.json', 'constraints-ignore-casing-measurements.json'].includes(name)).map(name => ({
|
|
65
65
|
name, fixture: JSON.parse(readFileSync(new URL(name, directory), 'utf8')) as Fixture
|
|
66
66
|
}));
|
|
67
67
|
const artifacts = { eventTypes: [OracleEventRecorded, AlternateRecorded, BoundaryRecorded], constraints: [] };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
// constraints-ignore-casing-measurements.json: the kernel applies string.ToLowerInvariant to the joined key text.
|
|
5
|
+
// Only these five non-ASCII scalars are measured; neighbours such as Ø, È or U+0302 are not admitted by resemblance.
|
|
6
|
+
// The unicode flag matches whole scalars, so a lone or reversed surrogate never matches.
|
|
7
|
+
const measuredCasingText = /^[A-Za-z0-9 .@_:\-|{}$\u00c9\u00df\u00e9\u00f8\u0301]*$/u;
|
|
8
|
+
|
|
9
|
+
/** Text whose .NET lower-invariant mapping was captured by the packaged oracle; no normalization or full folding. */
|
|
10
|
+
export function isMeasuredCasingText(value: string): boolean { return measuredCasingText.test(value); }
|
|
11
|
+
|
|
12
|
+
/** Applies the measured lower-invariant mapping: ASCII letters and U+00C9 only; ß, ø and U+0301 map to themselves. */
|
|
13
|
+
export function measuredLowerInvariant(value: string): string {
|
|
14
|
+
return value.replace(/[A-Z\u00c9]/g, letter => letter === '\u00c9' ? '\u00e9' : String.fromCharCode(letter.charCodeAt(0) + 32));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type CasingDefinition = { ignoreCasing: boolean; eventDefinitions: ReadonlyArray<{ properties: readonly unknown[] }> };
|
|
18
|
+
|
|
19
|
+
/** The isolated, unscoped, single-property, removal-free ignoreCasing definition measured for non-ASCII text. */
|
|
20
|
+
export function isMeasuredCasingShape(unique: CasingDefinition, scoped: boolean, removable: boolean): boolean {
|
|
21
|
+
return unique.ignoreCasing && !scoped && !removable && unique.eventDefinitions.length === 1 && unique.eventDefinitions[0].properties.length === 1;
|
|
22
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import type { Constructor } from '@cratis/fundamentals';
|
|
7
|
+
import { beforeEach, chai, describe, it, vi, type Assertion } from 'vitest';
|
|
8
|
+
import type { AppendResult } from '../../../eventSequences/AppendResult.js';
|
|
9
|
+
import { constraint } from '../../../events/constraints/constraint.js';
|
|
10
|
+
import type { IConstraintBuilder } from '../../../events/constraints/IConstraintBuilder.js';
|
|
11
|
+
import { EventScenario, UnsupportedEventSequenceOperation } from '../../index.js';
|
|
12
|
+
import { InProcessConstraints } from '../../InProcessConstraints.js';
|
|
13
|
+
import { measuredLowerInvariant } from '../../MeasuredCaseFolding.js';
|
|
14
|
+
|
|
15
|
+
chai.should();
|
|
16
|
+
const should = (value: unknown): Assertion => (value as { should: Assertion }).should;
|
|
17
|
+
type TextEvent = { key: string };
|
|
18
|
+
type PairEvent = { key: string; other: string };
|
|
19
|
+
type Types = { text: Constructor<TextEvent>; pair: Constructor<PairEvent> };
|
|
20
|
+
type Operation = { mode: string; events: Array<{ source: string; content: string }> };
|
|
21
|
+
type History = { source: string; sequence: string; content: Record<string, unknown>; hash: string | undefined };
|
|
22
|
+
type WireViolation = { ConstraintName: string; Message: string; Details: Record<string, string> };
|
|
23
|
+
type Outcome = { success: boolean; sequences: string[]; wireViolations: WireViolation[]; history: History[]; next: string };
|
|
24
|
+
type Observation = { input: string; lowered: string; utf8Sha256: string };
|
|
25
|
+
const fixture = JSON.parse(readFileSync(new URL('../../fixtures/constraints-ignore-casing-measurements.json', import.meta.url), 'utf8')) as {
|
|
26
|
+
fieldConstraintCases: Array<{ name: string; localSteps: number; operations: Operation[] }>;
|
|
27
|
+
expected: Array<{ steps: Outcome[]; casingObservations: Observation[] }>;
|
|
28
|
+
};
|
|
29
|
+
const unmeasuredNeighbours = ['\u00c8', '\u00e8', '\u00d8', '\u00de', '\u00e0', '\u0300', '\u0302', '\u0130', '\u0131', '\u03a3', '\u03c3',
|
|
30
|
+
'\u03c2', '\u1e9e', '\u212a', '\u6771', '\u4eac', '\u{10400}', '\u{1f600}', '\ud83d', '\ude00', '\ude00\ud83d', '\u00c9\ud83d', '\u00c9\u6771'];
|
|
31
|
+
|
|
32
|
+
function definition(type: Constructor, mode: 'ignoreCasing' | 'scoped' | 'removable' | 'composite' | 'overlapping', name = 'OracleFieldKey'): Constructor {
|
|
33
|
+
class Definition {
|
|
34
|
+
define(builder: IConstraintBuilder) {
|
|
35
|
+
if (mode === 'scoped') builder.perEventSourceType();
|
|
36
|
+
builder.unique(key => {
|
|
37
|
+
if (mode === 'composite') key.on(type as Constructor<PairEvent>, event => event.key, event => event.other);
|
|
38
|
+
else key.on(type as Constructor<TextEvent>, event => event.key);
|
|
39
|
+
key.ignoreCasing();
|
|
40
|
+
if (mode === 'removable') key.removedWith(type);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
constraint(name)(Definition);
|
|
45
|
+
return Definition;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function scenarioFor(types: Types, mode: Parameters<typeof definition>[1] = 'ignoreCasing'): EventScenario {
|
|
49
|
+
const type = mode === 'composite' ? types.pair : types.text;
|
|
50
|
+
const constraints = mode === 'overlapping' ? [definition(type, 'ignoreCasing'), definition(type, 'ignoreCasing', 'OtherCasedKey')] : [definition(type, mode)];
|
|
51
|
+
return new EventScenario({ artifacts: { eventTypes: [type], constraints } });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function textOf(type: Constructor<TextEvent>, content: string): TextEvent {
|
|
55
|
+
return Object.assign(new type(), JSON.parse(content));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function historyOf(scenario: EventScenario): History[] {
|
|
59
|
+
return scenario.appendedEvents.map(event => ({ source: event.context.eventSourceId,
|
|
60
|
+
sequence: event.context.sequenceNumber.toString(), content: event.content, hash: event.context.hash }));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function append(scenario: EventScenario, type: Constructor<TextEvent>, operation: Operation): Promise<AppendResult[]> {
|
|
64
|
+
const events = operation.events.map(entry => ({ eventSourceId: entry.source, event: textOf(type, entry.content) }));
|
|
65
|
+
return operation.mode === 'single' ? [await scenario.append(events[0].eventSourceId, events[0].event)] : scenario.appendMany(events);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function replay(types: Types, index: number): void {
|
|
69
|
+
const test = fixture.fieldConstraintCases[index];
|
|
70
|
+
it(`should match collision details, sequences, hashes and rollback through the production serializer for ${test.name}`, async () => {
|
|
71
|
+
const validate = vi.spyOn(InProcessConstraints.prototype, 'validate');
|
|
72
|
+
const scenario = scenarioFor(types);
|
|
73
|
+
should(test.localSteps).equal(test.operations.length);
|
|
74
|
+
for (const [step, operation] of test.operations.entries()) {
|
|
75
|
+
const results = await append(scenario, types.text, operation);
|
|
76
|
+
const expected = fixture.expected[index].steps[step];
|
|
77
|
+
should(results.every(result => result.isSuccess === expected.success)).equal(true);
|
|
78
|
+
should(results.map(result => result.sequenceNumber.value.toString())).deep.equal(
|
|
79
|
+
expected.success ? expected.sequences : results.map(() => '0'));
|
|
80
|
+
const raw = validate.mock.results.at(-1)!.value as ReturnType<InProcessConstraints['validate']>;
|
|
81
|
+
should(raw.map(violation => ({ ...violation, SequenceNumber: violation.SequenceNumber.toString() }))).deep.equal(expected.wireViolations);
|
|
82
|
+
should(historyOf(scenario)).deep.equal(expected.history);
|
|
83
|
+
should((await scenario.eventSequence.getNextSequenceNumber()).value.toString()).equal(expected.next);
|
|
84
|
+
}
|
|
85
|
+
validate.mockRestore();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function observe(index: number): void {
|
|
90
|
+
const test = fixture.fieldConstraintCases[index];
|
|
91
|
+
it(`should map every ${test.name} input to the lowered text and hash the oracle observed from the kernel operation`, () => {
|
|
92
|
+
const observations = fixture.expected[index].casingObservations;
|
|
93
|
+
should(observations.length).greaterThan(0);
|
|
94
|
+
for (const observation of observations) {
|
|
95
|
+
should(measuredLowerInvariant(observation.input)).equal(observation.lowered);
|
|
96
|
+
should(createHash('sha256').update(measuredLowerInvariant(observation.input)).digest('hex')).equal(observation.utf8Sha256);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function rejectUnmeasured(types: Types): void {
|
|
102
|
+
for (const value of unmeasuredNeighbours) {
|
|
103
|
+
describe(`when the ignoreCasing key is the unmeasured ${JSON.stringify(value)}`, () => {
|
|
104
|
+
let scenario: EventScenario;
|
|
105
|
+
beforeEach(() => { scenario = scenarioFor(types); });
|
|
106
|
+
const good = (key: string) => Object.assign(new types.text(), { key });
|
|
107
|
+
const invalid = (): TextEvent => Object.assign(new types.text(), { key: value });
|
|
108
|
+
for (const mode of ['single', 'batch']) {
|
|
109
|
+
it(`should keep history, results, the next sequence and claim ownership after a rejected ${mode} append`, async () => {
|
|
110
|
+
await scenario.append('A', good('\u00c9'));
|
|
111
|
+
const history = historyOf(scenario);
|
|
112
|
+
const results = [...scenario.results];
|
|
113
|
+
const pending = mode === 'single' ? scenario.append('B', invalid())
|
|
114
|
+
: scenario.appendMany([{ eventSourceId: 'B', event: good('ok') }, { eventSourceId: 'C', event: invalid() }]);
|
|
115
|
+
should(await pending.then(() => undefined, error => error)).instanceOf(UnsupportedEventSequenceOperation);
|
|
116
|
+
should(historyOf(scenario)).deep.equal(history);
|
|
117
|
+
should(scenario.results).deep.equal(results);
|
|
118
|
+
should((await scenario.eventSequence.getNextSequenceNumber()).value).equal(1n);
|
|
119
|
+
should((await scenario.append('B', good('ok'))).isSuccess).equal(true);
|
|
120
|
+
should((await scenario.append('C', good('\u00e9'))).constraintViolations).have.lengthOf(1);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
it('should reject a failing given atomically and leave its valid key claimable', async () => {
|
|
124
|
+
const error = await scenario.given.forEventSource('A').events(good('\u00c9'), invalid()).then(() => undefined, error => error);
|
|
125
|
+
should(error).instanceOf(UnsupportedEventSequenceOperation);
|
|
126
|
+
should(scenario.appendedEvents).have.lengthOf(0);
|
|
127
|
+
should(scenario.results).have.lengthOf(0);
|
|
128
|
+
should((await scenario.eventSequence.getNextSequenceNumber()).value).equal(0n);
|
|
129
|
+
should((await scenario.append('B', good('\u00e9'))).isSuccess).equal(true);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function rejectShapes(types: Types): void {
|
|
136
|
+
for (const mode of ['scoped', 'removable', 'composite', 'overlapping'] as const) {
|
|
137
|
+
for (const value of ['\u00c9', '\u00df', '\u00f8', '\u0301']) {
|
|
138
|
+
it(`should keep new ${JSON.stringify(value)} rejected for ${mode} ignoreCasing definitions`, async () => {
|
|
139
|
+
const event = mode === 'composite' ? Object.assign(new types.pair(), { key: value, other: 'x' })
|
|
140
|
+
: Object.assign(new types.text(), { key: value });
|
|
141
|
+
const error = await Promise.resolve().then(() => scenarioFor(types, mode))
|
|
142
|
+
.then(scenario => scenario.append('A', event)).then(() => undefined, error => error);
|
|
143
|
+
should(error).instanceOf(UnsupportedEventSequenceOperation);
|
|
144
|
+
should(String(error)).include('artifacts.constraints');
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
it('should keep the ASCII counterpart of the scoped and composite shapes passing, so the rejections are about the key', async () => {
|
|
149
|
+
should((await scenarioFor(types, 'scoped').append('A', Object.assign(new types.text(), { key: 'Ab' }))).isSuccess).equal(true);
|
|
150
|
+
should((await scenarioFor(types, 'composite').append('A', Object.assign(new types.pair(), { key: 'Ab', other: 'x' }))).isSuccess).equal(true);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function caseFoldedText(types: Types): void {
|
|
155
|
+
describe('when replaying the measured ignoreCasing keys', () => {
|
|
156
|
+
for (const index of fixture.fieldConstraintCases.keys()) { replay(types, index); observe(index); }
|
|
157
|
+
});
|
|
158
|
+
rejectUnmeasured(types);
|
|
159
|
+
describe('when the measured keys are used in an unmeasured definition shape', () => rejectShapes(types));
|
|
160
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import 'reflect-metadata';
|
|
5
|
+
import { field } from '@cratis/fundamentals';
|
|
6
|
+
import { eventType } from '../../../events/eventTypeDecorator.js';
|
|
7
|
+
import { caseFoldedText } from './case_folded_text.fixture.js';
|
|
8
|
+
|
|
9
|
+
class TextClaimed { @field(String) key = ''; }
|
|
10
|
+
eventType('OracleFieldText')(TextClaimed);
|
|
11
|
+
class PairClaimed { @field(String) key = ''; @field(String) other = ''; }
|
|
12
|
+
eventType('OracleCasingPair')(PairClaimed);
|
|
13
|
+
|
|
14
|
+
caseFoldedText({ text: TextClaimed, pair: PairClaimed });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { field } from '@cratis/fundamentals';
|
|
5
|
+
import { eventType } from '../../../events/eventTypeDecorator.js';
|
|
6
|
+
import { caseFoldedText } from './case_folded_text.fixture.js';
|
|
7
|
+
|
|
8
|
+
@eventType('OracleFieldText')
|
|
9
|
+
class TextClaimed { @field(String) key = ''; }
|
|
10
|
+
@eventType('OracleCasingPair')
|
|
11
|
+
class PairClaimed { @field(String) key = ''; @field(String) other = ''; }
|
|
12
|
+
|
|
13
|
+
caseFoldedText({ text: TextClaimed, pair: PairClaimed });
|
|
@@ -35,9 +35,10 @@ export interface IWebhookDefinitionBuilder {
|
|
|
35
35
|
* @param authority - OAuth authority.
|
|
36
36
|
* @param clientId - OAuth client id.
|
|
37
37
|
* @param clientSecret - OAuth client secret.
|
|
38
|
+
* @param scope - Optional space-delimited OAuth scope.
|
|
38
39
|
* @returns The builder for chaining.
|
|
39
40
|
*/
|
|
40
|
-
withOAuth(authority: string, clientId: string, clientSecret: string): IWebhookDefinitionBuilder;
|
|
41
|
+
withOAuth(authority: string, clientId: string, clientSecret: string, scope?: string): IWebhookDefinitionBuilder;
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* Adds a target header.
|
|
@@ -66,12 +66,12 @@ export class WebhookDefinitionBuilder implements IWebhookDefinitionBuilder {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/** @inheritdoc */
|
|
69
|
-
withOAuth(authority: string, clientId: string, clientSecret: string): IWebhookDefinitionBuilder {
|
|
69
|
+
withOAuth(authority: string, clientId: string, clientSecret: string, scope?: string): IWebhookDefinitionBuilder {
|
|
70
70
|
const value: OAuthAuthorization = {
|
|
71
71
|
Authority: authority,
|
|
72
72
|
ClientId: clientId,
|
|
73
73
|
ClientSecret: clientSecret,
|
|
74
|
-
Scope: ''
|
|
74
|
+
Scope: scope ?? ''
|
|
75
75
|
};
|
|
76
76
|
this._authorization = {
|
|
77
77
|
Value0: undefined,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { AddWebhooksRequest } from '@cratis/chronicle.contracts';
|
|
5
|
+
import type { IClientArtifactsProvider } from '../../../artifacts/index.js';
|
|
6
|
+
import type { ChronicleConnection } from '../../../connection/index.js';
|
|
7
|
+
import type { IEventTypes } from '../../../events/IEventTypes.js';
|
|
8
|
+
import { Webhooks } from '../../Webhooks.js';
|
|
9
|
+
|
|
10
|
+
export class a_webhook_registration {
|
|
11
|
+
sent = AddWebhooksRequest.fromPartial({});
|
|
12
|
+
readonly webhooks: Webhooks;
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
const connection = {
|
|
16
|
+
webhooks: {
|
|
17
|
+
addWebhooks: async (request: AddWebhooksRequest) => {
|
|
18
|
+
this.sent = request;
|
|
19
|
+
return { IsAuthorized: true, ValidationResults: [], ExceptionMessages: [] };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} as unknown as ChronicleConnection;
|
|
23
|
+
this.webhooks = new Webhooks('store', connection, { all: [] } as unknown as IEventTypes, {} as IClientArtifactsProvider);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { AddWebhooksRequest, OAuthAuthorization } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
6
|
+
import type { IWebhookDefinitionBuilder } from '../IWebhookDefinitionBuilder.js';
|
|
7
|
+
import { a_webhook_registration } from './given/a_webhook_registration.js';
|
|
8
|
+
|
|
9
|
+
chai.should();
|
|
10
|
+
|
|
11
|
+
describe.each(['orders.read orders.write', ' orders.read orders.write '])('when registering a webhook with OAuth scope "%s"', scope => {
|
|
12
|
+
let context: a_webhook_registration;
|
|
13
|
+
let oauth: OAuthAuthorization;
|
|
14
|
+
let request: AddWebhooksRequest;
|
|
15
|
+
let builder: IWebhookDefinitionBuilder;
|
|
16
|
+
let returnedBuilder: IWebhookDefinitionBuilder;
|
|
17
|
+
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
context = new a_webhook_registration();
|
|
20
|
+
await context.webhooks.register('orders', 'https://example.test/webhook', configuration => {
|
|
21
|
+
builder = configuration;
|
|
22
|
+
returnedBuilder = configuration.withOAuth('https://auth.example.test', 'fake-client', 'fake-secret', scope);
|
|
23
|
+
returnedBuilder.withHeader('x-source', 'fake-app');
|
|
24
|
+
});
|
|
25
|
+
request = AddWebhooksRequest.decode(AddWebhooksRequest.encode(context.sent).finish());
|
|
26
|
+
oauth = request.Webhooks[0].Target!.Authorization!.Value2!;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should return the original builder', () => returnedBuilder.should.equal(builder));
|
|
30
|
+
it('should keep the event store', () => request.EventStore.should.equal('store'));
|
|
31
|
+
it('should select OAuth authorization', () => chai.expect(oauth).not.to.be.undefined);
|
|
32
|
+
it('should leave basic authorization unset', () => chai.expect(request.Webhooks[0].Target!.Authorization!.Value0).to.be.undefined);
|
|
33
|
+
it('should leave bearer authorization unset', () => chai.expect(request.Webhooks[0].Target!.Authorization!.Value1).to.be.undefined);
|
|
34
|
+
it('should preserve credentials and scope through the request codec', () => oauth.should.deep.equal({
|
|
35
|
+
Authority: 'https://auth.example.test', ClientId: 'fake-client', ClientSecret: 'fake-secret', Scope: scope
|
|
36
|
+
}));
|
|
37
|
+
it('should retain chained headers', () => request.Webhooks[0].Target!.Headers['x-source'].should.equal('fake-app'));
|
|
38
|
+
// The pinned 19.153.0 observation_webhooks contract uses length-delimited field 4 (tag 0x22) for Scope.
|
|
39
|
+
it('should encode scope as protobuf field four', () => OAuthAuthorization.encode({
|
|
40
|
+
...oauth, Authority: '', ClientId: '', ClientSecret: ''
|
|
41
|
+
}).finish().should.deep.equal(Uint8Array.from([0x22, scope.length, ...new TextEncoder().encode(scope)])));
|
|
42
|
+
});
|