Skip to content

Commit

Permalink
Merge branch 'main' into feature/debug-api-for-identity-deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 12, 2024
2 parents 08160f7 + f01f59a commit cd972e5
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .dev/compose.backbone.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BACKBONE_VERSION=6.7.1
BACKBONE_VERSION=6.15.2
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export interface ConnectorRelationshipTemplate {
createdAt: string;
content: RelationshipTemplateContentJSON | ArbitraryRelationshipTemplateContentJSON;
expiresAt?: string;
forIdentity?: string;
truncatedReference: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { ArbitraryRelationshipTemplateContentJSON, RelationshipTemplateContentJS
export interface CreateOwnRelationshipTemplateRequest {
maxNumberOfAllocations?: number;
expiresAt: string;
forIdentity?: string;
content: RelationshipTemplateContentJSON | ArbitraryRelationshipTemplateContentJSON;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface CreateTokenForOwnRelationshipTemplateRequest {
expiresAt?: string;
ephemeral?: boolean;
forIdentity?: string;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface CreateTokenQrCodeForOwnRelationshipTemplateRequest {
expiresAt?: string;
forIdentity?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface GetOwnTemplatesRequest {
expiresAt?: string | string[];
createdByDevice?: string | string[];
maxNumberOfAllocations?: number | number[];
forIdentity?: string | string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface GetPeerRelationshipTemplatesRequest {
expiresAt?: string | string[];
createdBy?: string | string[];
maxNumberOfAllocations?: number | number[];
forIdentity?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export interface GetRelationshipTemplatesRequest {
createdBy?: string | string[];
createdByDevice?: string | string[];
maxNumberOfAllocations?: number | number[];
forIdentity?: string | string[];
isOwn?: boolean | boolean[];
}
1 change: 1 addition & 0 deletions packages/sdk/src/types/tokens/ConnectorToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ConnectorToken {
content: unknown;
createdAt: string;
expiresAt: string;
forIdentity?: string;
truncatedReference: string;
isEphemeral: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class RelationshipTemplatesController extends BaseController {
case "image/png":
const qrCodeResult = await this.transportServices.relationshipTemplates.createTokenQRCodeForOwnTemplate({
templateId: id,
expiresAt: request.expiresAt
expiresAt: request.expiresAt,
forIdentity: request.forIdentity
});
return this.file(
qrCodeResult,
Expand All @@ -110,7 +111,8 @@ export class RelationshipTemplatesController extends BaseController {
const jsonResult = await this.transportServices.relationshipTemplates.createTokenForOwnTemplate({
templateId: id,
expiresAt: request.expiresAt,
ephemeral: request.ephemeral
ephemeral: request.ephemeral,
forIdentity: request.forIdentity
});
return this.created(jsonResult);
}
Expand Down
28 changes: 28 additions & 0 deletions src/modules/coreHttpApi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,10 @@ paths:
name: maxNumberOfAllocations
schema:
$ref: "#/components/schemas/NumberFilter"
- in: query
name: forIdentity
schema:
$ref: "#/components/schemas/IdFilter"
- in: query
name: isOwn
schema:
Expand Down Expand Up @@ -3246,6 +3250,10 @@ paths:
format: date-time
example: 2025-01-01
description: A timestamp that describes when this relationship template expires. Expired templates cannot be used to create relationships anymore.
forIdentity:
$ref: "#/components/schemas/Address"
nullable: true
description: The only Identity that may load this RelationshipTemplate.
content:
oneOf:
- $ref: "#/components/schemas/RelationshipTemplateContent"
Expand Down Expand Up @@ -3309,6 +3317,10 @@ paths:
name: maxNumberOfAllocations
schema:
$ref: "#/components/schemas/NumberFilter"
- in: query
name: forIdentity
schema:
$ref: "#/components/schemas/IdFilter"
responses:
200:
description: Success
Expand Down Expand Up @@ -3409,6 +3421,10 @@ paths:
name: maxNumberOfAllocations
schema:
$ref: "#/components/schemas/NumberFilter"
- in: query
name: forIdentity
schema:
$ref: "#/components/schemas/IdFilter"
responses:
200:
description: Success
Expand Down Expand Up @@ -3507,6 +3523,10 @@ paths:
ephemeral:
description: If set to true the token will will not be cached in the database of the connector. Note that you will not be able to fetch this token unless you remember the truncatedReference of the token. Defaults to true. Will be ignored if Accept is set to image/png.
type: boolean
forIdentity:
$ref: "#/components/schemas/Address"
nullable: true
description: The only Identity that may load this Token. If forIdentity is set for the RelationshipTemplate, that Identity must also be given here.
responses:
201:
description: Success
Expand Down Expand Up @@ -5757,6 +5777,10 @@ components:
type: string
format: date-time
description: A timestamp that describes when this relationship template expires. Expired templates cannot be used to create relationship requests anymore.
forIdentity:
$ref: "#/components/schemas/Address"
nullable: true
description: The only Identity that may load this RelationshipTemplate.
content:
oneOf:
- $ref: "#/components/schemas/RelationshipTemplateContent"
Expand Down Expand Up @@ -5913,6 +5937,10 @@ components:
format: date-time
nullable: false
description: A timestamp that describes when this token expires. An expired token cannot be fetched from the platform anymore. However it will still be available for auditing purposes.
forIdentity:
$ref: "#/components/schemas/Address"
nullable: true
description: The only Identity that may load this Token.
truncatedReference:
type: string
format: byte
Expand Down
15 changes: 8 additions & 7 deletions test/lib/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,26 @@ export async function makeUploadRequest(values: Partial<UploadOwnFileRequest> =
};
}

export async function createTemplate(client: ConnectorClient): Promise<ConnectorRelationshipTemplate> {
export async function createTemplate(client: ConnectorClient, forIdentity?: string): Promise<ConnectorRelationshipTemplate> {
const response = await client.relationshipTemplates.createOwnRelationshipTemplate({
maxNumberOfAllocations: 1,
expiresAt: DateTime.utc().plus({ minutes: 10 }).toString(),
content: {
"@type": "ArbitraryRelationshipTemplateContent",
value: { a: "b" }
}
},
forIdentity
});

expect(response).toBeSuccessful(ValidationSchema.RelationshipTemplate);

return response.result;
}

export async function getTemplateToken(client: ConnectorClient): Promise<ConnectorToken> {
const template = await createTemplate(client);
export async function getTemplateToken(client: ConnectorClient, forIdentity?: string): Promise<ConnectorToken> {
const template = await createTemplate(client, forIdentity);

const response = await client.relationshipTemplates.createTokenForOwnRelationshipTemplate(template.id);
const response = await client.relationshipTemplates.createTokenForOwnRelationshipTemplate(template.id, { forIdentity });
expect(response).toBeSuccessful(ValidationSchema.Token);

return response.result;
Expand All @@ -212,8 +213,8 @@ export async function getFileToken(client: ConnectorClient): Promise<ConnectorTo
return response.result;
}

export async function exchangeTemplate(clientCreator: ConnectorClient, clientRecpipient: ConnectorClient): Promise<ConnectorRelationshipTemplate> {
const templateToken = await getTemplateToken(clientCreator);
export async function exchangeTemplate(clientCreator: ConnectorClient, clientRecpipient: ConnectorClient, forIdentity?: string): Promise<ConnectorRelationshipTemplate> {
const templateToken = await getTemplateToken(clientCreator, forIdentity);

const response = await clientRecpipient.relationshipTemplates.loadPeerRelationshipTemplate({
reference: templateToken.truncatedReference
Expand Down
40 changes: 33 additions & 7 deletions test/relationshipTemplates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DateTime } from "luxon";
import { Launcher } from "./lib/Launcher";
import { QueryParamConditions } from "./lib/QueryParamConditions";
import { getTimeout } from "./lib/setTimeout";
import { createTemplate, exchangeTemplate } from "./lib/testUtils";
import { createTemplate, exchangeTemplate, getTemplateToken } from "./lib/testUtils";
import { ValidationSchema } from "./lib/validation";

const launcher = new Launcher();
Expand Down Expand Up @@ -82,6 +82,29 @@ describe("Template Tests", () => {
expect(response.isError).toBeTruthy();
expect(response.error.code).toBe("error.runtime.validation.invalidPropertyValue");
});

test("send and receive a personalized template", async () => {
const client2address = (await client2.account.getIdentityInfo()).result.address;
const template = await createTemplate(client1, client2address);
expect(template.forIdentity).toBe(client2address);

const response = await client2.relationshipTemplates.loadPeerRelationshipTemplate({
reference: template.truncatedReference
});
expect(response).toBeSuccessful(ValidationSchema.RelationshipTemplate);
expect(response.result.forIdentity).toBe(client2address);
});

test("send and receive a personalized template via token", async () => {
const client2address = (await client2.account.getIdentityInfo()).result.address;
const templateToken = await getTemplateToken(client1, client2address);

const response = await client2.relationshipTemplates.loadPeerRelationshipTemplate({
reference: templateToken.truncatedReference
});
expect(response).toBeSuccessful(ValidationSchema.RelationshipTemplate);
expect(response.result.forIdentity).toBe(client2address);
});
});

describe("Serialization Errors", () => {
Expand All @@ -107,37 +130,40 @@ describe("Serialization Errors", () => {

describe("RelationshipTemplates Query", () => {
test("query templates", async () => {
const template = await createTemplate(client1);
const template = await createTemplate(client1, (await client1.account.getIdentityInfo()).result.address);
const conditions = new QueryParamConditions(template, client1)
.addBooleanSet("isOwn")
.addDateSet("createdAt")
.addDateSet("expiresAt")
.addStringSet("createdBy")
.addStringSet("createdByDevice")
.addNumberSet("maxNumberOfAllocations");
.addNumberSet("maxNumberOfAllocations")
.addStringSet("forIdentity");

await conditions.executeTests((c, q) => c.relationshipTemplates.getRelationshipTemplates(q), ValidationSchema.RelationshipTemplates);
});

test("query own templates", async () => {
const template = await createTemplate(client1);
const template = await createTemplate(client1, (await client1.account.getIdentityInfo()).result.address);
const conditions = new QueryParamConditions(template, client1)
.addDateSet("createdAt")
.addDateSet("expiresAt")
.addStringSet("createdBy")
.addStringSet("createdByDevice")
.addNumberSet("maxNumberOfAllocations");
.addNumberSet("maxNumberOfAllocations")
.addStringSet("forIdentity");
await conditions.executeTests((c, q) => c.relationshipTemplates.getOwnRelationshipTemplates(q), ValidationSchema.RelationshipTemplates);
});

test("query peer templates", async () => {
const template = await exchangeTemplate(client1, client2);
const template = await exchangeTemplate(client1, client2, (await client2.account.getIdentityInfo()).result.address);
const conditions = new QueryParamConditions(template, client2)
.addDateSet("createdAt")
.addDateSet("expiresAt")
.addStringSet("createdBy")
.addStringSet("createdByDevice")
.addNumberSet("maxNumberOfAllocations");
.addNumberSet("maxNumberOfAllocations")
.addStringSet("forIdentity");

await conditions.executeTests((c, q) => c.relationshipTemplates.getPeerRelationshipTemplates(q), ValidationSchema.RelationshipTemplates);
});
Expand Down

0 comments on commit cd972e5

Please sign in to comment.