diff --git a/src/model.ts b/src/model.ts index 0101dbc..a5f424f 100644 --- a/src/model.ts +++ b/src/model.ts @@ -168,6 +168,7 @@ export class SpraypaintBase { static strictAttributes: boolean = false static logger: ILogger = defaultLogger static sync: boolean = false + static credentials: "same-origin" | "omit" | "include" | undefined static clientApplication: string | null = null static patchAsPost: boolean = false @@ -756,6 +757,10 @@ export class SpraypaintBase { } as any } + if (this.credentials) { + options.credentials = this.credentials + } + if (this.clientApplication) { options.headers["Client-Application"] = this.clientApplication } diff --git a/test/unit/model.test.ts b/test/unit/model.test.ts index 0e867ad..1e923e8 100644 --- a/test/unit/model.test.ts +++ b/test/unit/model.test.ts @@ -1493,6 +1493,26 @@ describe("Model", () => { }) describe("#fetchOptions", () => { + context("credentials is set", () => { + beforeEach(() => { + Author.credentials = "include" + }) + + afterEach(() => { + Author.credentials = "same-origin" + }) + + it("sets the credentials header", () => { + expect(Author.fetchOptions().credentials).to.eq("include") + }) + }) + + context("credentials is NOT set", () => { + it("sets the credentials header", () => { + expect(Author.fetchOptions().credentials).to.eq("same-origin") + }) + }) + context("clientApplication is set", () => { beforeEach(() => { Author.clientApplication = "test-app"