@osdk/oauth 1.1.0-beta.3 → 1.1.0-beta.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @osdk/oauth
2
2
 
3
+ ## 1.1.0-beta.5
4
+
5
+ ### Minor Changes
6
+
7
+ - 9d35a1f: Remove unused imports
8
+
9
+ ## 1.1.0-beta.4
10
+
11
+ ### Minor Changes
12
+
13
+ - e968bc0: Use api:ontologies-X instead of api:X-data
14
+
3
15
  ## 1.1.0-beta.3
4
16
 
5
17
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom"],"sources":["AuthorizationServer.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { describe, expect, it, } from \"vitest\";\nimport { createAuthorizationServer } from \"./common.js\";\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"/multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n const authServerCustom = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com/foo/first/someStuff\");\n expect(authServerCustom).toEqual({\n token_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAS,QAAQ;AAC9C,SAASC,yBAAyB,QAAQ,aAAa;AACvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC1CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,YAAY,EAAE,4BAA4B,CAAC;IACxFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;EACFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,WAAW,EAAE,4BAA4B,CAAC;IACvFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;IACF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAAC,WAAW,EAAE,gDAAgD,CAAC;IACjHF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC7BC,cAAc,EAAE,2EAA2E;MAC3FC,sBAAsB,EAAE,+EAA+E;MACvGC,mBAAmB,EAAE,kFAAkF;MACvGC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom"],"sources":["AuthorizationServer.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { describe, expect, it } from \"vitest\";\nimport { createAuthorizationServer } from \"./common.js\";\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"/multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n const authServerCustom = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com/foo/first/someStuff\");\n expect(authServerCustom).toEqual({\n token_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,yBAAyB,QAAQ,aAAa;AACvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC1CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,YAAY,EAAE,4BAA4B,CAAC;IACxFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;EACFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,WAAW,EAAE,4BAA4B,CAAC;IACvFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;IACF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAAC,WAAW,EAAE,gDAAgD,CAAC;IACjHF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC7BC,cAAc,EAAE,2EAA2E;MAC3FC,sBAAsB,EAAE,+EAA+E;MACvGC,mBAAmB,EAAE,kFAAkF;MACvGC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"createConfidentialOauthClient.d.ts","sourceRoot":"","sources":["../../src/createConfidentialOauthClient.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAG5E;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,EAAwC,EACtD,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,EACnD,OAAO,GAAE,MAAoB,GAC5B,uBAAuB,CAgCzB"}
1
+ {"version":3,"file":"createConfidentialOauthClient.d.ts","sourceRoot":"","sources":["../../src/createConfidentialOauthClient.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAG5E;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,EAAoD,EAClE,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,EACnD,OAAO,GAAE,MAAoB,GAC5B,uBAAuB,CAgCzB"}
@@ -25,7 +25,7 @@ import { throwIfError } from "./throwIfError.js";
25
25
  * @param ctxPath
26
26
  * @returns which can be used as a token provider
27
27
  */
28
- export function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
28
+ export function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:ontologies-read", "api:ontologies-write"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
29
29
  const client = {
30
30
  client_id,
31
31
  client_secret
@@ -1 +1 @@
1
- {"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(client_id, client_secret, url, scopes = [\"api:read-data\", \"api:write-data\"], fetchFn = globalThis.fetch, ctxPath = \"multipass\") {\n const client = { client_id, client_secret };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n const { getToken, makeTokenAndSaveRefresh } = common(client, authServer, _signIn, oauthHttpOptions, undefined);\n async function _signIn() {\n return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({ scope: scopes.join(\" \") }), oauthHttpOptions))), \"signIn\");\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,6BAA6B,EAAEC,WAAW,EAAEC,gCAAgC,QAAS,cAAc;AAC5G,SAASC,MAAM,EAAEC,yBAAyB,QAAQ,aAAa;AAC/D,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACC,SAAS,EAAEC,aAAa,EAAEC,GAAG,EAAEC,MAAM,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,EAAEC,OAAO,GAAGC,UAAU,CAACC,KAAK,EAAEC,OAAO,GAAG,WAAW,EAAE;EAC1K,MAAMC,MAAM,GAAG;IAAER,SAAS;IAAEC;EAAc,CAAC;EAC3C,MAAMQ,UAAU,GAAGZ,yBAAyB,CAACU,OAAO,EAAEL,GAAG,CAAC;EAC1D,MAAMQ,gBAAgB,GAAG;IAAE,CAAChB,WAAW,GAAGU;EAAQ,CAAC;EACnD,MAAM;IAAEO,QAAQ;IAAEC;EAAwB,CAAC,GAAGhB,MAAM,CAACY,MAAM,EAAEC,UAAU,EACvE,kBAAyB;IACrB,OAAOG,uBAAuB,CAACd,YAAY,CAAC,MAAMH,gCAAgC,CAACc,UAAU,EAAED,MAAM,EAAE,MAAMf,6BAA6B,CAACgB,UAAU,EAAED,MAAM,EAAE,IAAIK,eAAe,CAAC;MAAEC,KAAK,EAAEX,MAAM,CAACY,IAAI,CAAC,GAAG;IAAE,CAAC,CAAC,EAAEL,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;EACnP,CAAC,EAHiFA,gBAAgB,EAAEM,SAAS,CAAC;EAI9G,OAAOL,QAAQ;AACnB","ignoreList":[]}
1
+ {"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(client_id, client_secret, url, scopes = [\"api:ontologies-read\", \"api:ontologies-write\"], fetchFn = globalThis.fetch, ctxPath = \"multipass\") {\n const client = { client_id, client_secret };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n const { getToken, makeTokenAndSaveRefresh } = common(client, authServer, _signIn, oauthHttpOptions, undefined);\n async function _signIn() {\n return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({ scope: scopes.join(\" \") }), oauthHttpOptions))), \"signIn\");\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,6BAA6B,EAAEC,WAAW,EAAEC,gCAAgC,QAAS,cAAc;AAC5G,SAASC,MAAM,EAAEC,yBAAyB,QAAQ,aAAa;AAC/D,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACC,SAAS,EAAEC,aAAa,EAAEC,GAAG,EAAEC,MAAM,GAAG,CAAC,qBAAqB,EAAE,sBAAsB,CAAC,EAAEC,OAAO,GAAGC,UAAU,CAACC,KAAK,EAAEC,OAAO,GAAG,WAAW,EAAE;EACtL,MAAMC,MAAM,GAAG;IAAER,SAAS;IAAEC;EAAc,CAAC;EAC3C,MAAMQ,UAAU,GAAGZ,yBAAyB,CAACU,OAAO,EAAEL,GAAG,CAAC;EAC1D,MAAMQ,gBAAgB,GAAG;IAAE,CAAChB,WAAW,GAAGU;EAAQ,CAAC;EACnD,MAAM;IAAEO,QAAQ;IAAEC;EAAwB,CAAC,GAAGhB,MAAM,CAACY,MAAM,EAAEC,UAAU,EACvE,kBAAyB;IACrB,OAAOG,uBAAuB,CAACd,YAAY,CAAC,MAAMH,gCAAgC,CAACc,UAAU,EAAED,MAAM,EAAE,MAAMf,6BAA6B,CAACgB,UAAU,EAAED,MAAM,EAAE,IAAIK,eAAe,CAAC;MAAEC,KAAK,EAAEX,MAAM,CAACY,IAAI,CAAC,GAAG;IAAE,CAAC,CAAC,EAAEL,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;EACnP,CAAC,EAHiFA,gBAAgB,EAAEM,SAAS,CAAC;EAI9G,OAAOL,QAAQ;AACnB","ignoreList":[]}
@@ -13,7 +13,7 @@ export interface PublicOauthClientOptions {
13
13
  */
14
14
  postLoginPage?: string;
15
15
  /**
16
- * * @param {string[]} [scopes=[]] - OAuth scopes to request. If not provided, defaults to `["api:read-data", "api:write-data"]`
16
+ * * @param {string[]} [scopes=[]] - OAuth scopes to request. If not provided, defaults to `["api:ontologies-read", "api:ontologies-write"]`
17
17
  */
18
18
  scopes?: string[];
19
19
  /**
@@ -44,7 +44,7 @@ export declare function createPublicOauthClient(clientId: string, url: string, r
44
44
  * @param {boolean} useHistory - If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)
45
45
  * @param {string} loginPage - Custom landing page URL prior to logging in
46
46
  * @param {string} postLoginPage - URL to return to after completed authentication cycle (defaults to `window.location.toString()`)
47
- * @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `["api:read-data", "api:write-data"]`
47
+ * @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `["api:ontologies-read", "api:ontologies-write"]`
48
48
  * @param {typeof globalThis.fetch} fetchFn - Custom fetch function to use for requests (defaults to `globalThis.fetch`)
49
49
  * @param {string} ctxPath - Context path for the authorization server (defaults to "multipass")
50
50
  * @returns {PublicOauthClient} A client that can be used as a token provider
@@ -210,7 +210,7 @@ describe(createPublicOauthClient, () => {
210
210
  redirect_uri: clientArgs.redirectUrl,
211
211
  response_type: "code",
212
212
  code_challenge_method: "S256",
213
- scope: "offline_access api:read-data api:write-data",
213
+ scope: "offline_access api:ontologies-read api:ontologies-write",
214
214
  state: expect.any(String)
215
215
  }));
216
216
  });
@@ -1 +1 @@
1
- {"version":3,"file":"publicOauth.test.js","names":["afterAll","afterEach","beforeAll","beforeEach","describe","expect","it","vi","commonJs","createPublicOauthClient","hoistedMocks","hoisted","makeTokenAndSaveRefresh","fn","mock","importOriginal","original","default","ms","opts","common","args","result","readLocal","spyOn","DEFAULT_CUR_URL","URL","fetchFn","mockWindow","location","toString","assign","href","pathname","history","replaceState","mockLocalStorage","setItem","getItem","removeItem","restoreAllMocks","mockRestore","clearAllMocks","mockReset","stubGlobal","unstubAllGlobals","BASE_CLIENT_ARGS","clientId","foundryUrl","redirectUrl","fullLoginUrl","each","name","currentUrl","clientArgs","should","redirectToLoginPage","loginPage","client","useHistory","postLoginPage","scopes","ctxPath","mocked","toHaveBeenCalledWith","objectContaining","client_id","token_endpoint_auth_method","createAuthorizationServer","any","Function","anything","refresh_token","codeVerifier","state","oldUrl","initialLocalState","ACCESS_TOKEN","Math","random","substring","mockImplementation","access_token","expires_at","Date","now","expires_in","Object","keys","length","tokenPromise","toBeCalledTimes","resolves","toBeUndefined","toBeCalledWith","JSON","stringify","window","rejects","toThrowError","Error","toHaveBeenCalledOnce","url","calls","origin","toEqual","fromEntries","searchParams","entries","code_challenge","String","redirect_uri","response_type","code_challenge_method","scope","toHaveBeenCalledTimes","undefined"],"sources":["publicOauth.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/* eslint-disable @typescript-eslint/consistent-type-imports */\nimport { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi, } from \"vitest\";\nimport * as commonJs from \"./common.js\";\nimport { createPublicOauthClient } from \"./createPublicOauthClient.js\";\nconst hoistedMocks = vi.hoisted(() => {\n return {\n makeTokenAndSaveRefresh: vi.fn(),\n };\n});\nvi.mock(\"delay\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n default: vi.fn((ms, opts) => {\n // speed up the tests\n return original.default(ms / 100, opts);\n }),\n };\n});\nvi.mock(\"./common.js\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n ...original,\n common: vi.fn((...args) => {\n const result = original.common(...args);\n return {\n ...result,\n makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh,\n };\n }),\n readLocal: vi.spyOn(original, \"readLocal\"),\n // vi.fn(original.readLocal),\n };\n});\nvi.mock(\"oauth4webapi\");\ndescribe(createPublicOauthClient, () => {\n const DEFAULT_CUR_URL = new URL(\"https://fauxurl\");\n const fetchFn = vi.fn();\n const mockWindow = {\n location: {\n toString: vi.fn(() => DEFAULT_CUR_URL),\n assign: vi.fn(),\n href: DEFAULT_CUR_URL.href,\n pathname: DEFAULT_CUR_URL.pathname,\n },\n history: {\n replaceState: vi.fn(),\n },\n };\n const mockLocalStorage = {\n setItem: vi.fn(),\n getItem: vi.fn(),\n removeItem: vi.fn(),\n };\n beforeEach((context) => {\n vi.restoreAllMocks();\n fetchFn.mockRestore();\n });\n afterEach((context) => {\n vi.clearAllMocks();\n fetchFn.mockReset();\n });\n beforeAll(() => {\n vi.stubGlobal(\"window\", mockWindow);\n vi.stubGlobal(\"localStorage\", mockLocalStorage);\n });\n afterAll(() => {\n vi.unstubAllGlobals();\n });\n const BASE_CLIENT_ARGS = {\n clientId: \"this-would-be-client-id\",\n foundryUrl: \"https://a.foundry.url.local\",\n redirectUrl: \"https://my.redirect.url.local\",\n fetchFn,\n };\n const fullLoginUrl = new URL(\"/loginPage\", DEFAULT_CUR_URL);\n describe.each([\n {\n name: \"Basic Usage\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is login page\",\n currentUrl: fullLoginUrl,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is loginPage\",\n currentUrl: new URL(\"/loginPage\", DEFAULT_CUR_URL),\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n ])(\"$name\", ({ clientArgs, currentUrl, should }) => {\n let client;\n beforeEach(() => {\n client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);\n mockWindow.location.href = new URL(currentUrl).href;\n mockWindow.location.pathname = new URL(currentUrl).pathname;\n });\n it(\"calls common with expected values\", () => {\n expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({\n client_id: clientArgs.clientId,\n token_endpoint_auth_method: \"none\",\n }), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? \"/multipass\", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function));\n });\n describe.each([\n {\n refresh_token: \"a-refresh-token\",\n },\n {\n codeVerifier: \"hi\",\n state: \"mom\",\n oldUrl: \"https://someoldurl.local\",\n },\n {},\n ])(\"Initial Local State: %s\", (initialLocalState) => {\n const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);\n beforeEach(() => {\n vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);\n hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({\n access_token: ACCESS_TOKEN,\n expires_at: Date.now(),\n expires_in: 10000,\n }));\n });\n if (Object.keys(initialLocalState).length === 0) {\n if (should.redirectToLoginPage) {\n it(\"redirects to login page\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n });\n }\n else {\n it(\"redirects to multipass\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n // we assume window.location.assign will take you away therefore we\n // also have to expect in this scenario that the thrown error happens\n await expect(tokenPromise)\n .rejects.toThrowError(new Error(\"Unable to redirect\"));\n expect(mockWindow.location.assign).toHaveBeenCalledOnce();\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n expect(url.origin).toEqual(clientArgs.foundryUrl);\n expect(url.pathname).toEqual(\"/multipass/api/oauth2/authorize\");\n expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({\n client_id: clientArgs.clientId,\n code_challenge: expect.any(String),\n redirect_uri: clientArgs.redirectUrl,\n response_type: \"code\",\n code_challenge_method: \"S256\",\n scope: \"offline_access api:read-data api:write-data\",\n state: expect.any(String),\n }));\n });\n }\n }\n if (initialLocalState.codeVerifier) {\n it(\"tries to auth with return results\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"signIn\");\n expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);\n expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialLocalState.oldUrl);\n });\n }\n if (initialLocalState.refresh_token) {\n it(\"refreshes\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"refresh\");\n });\n }\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAS,QAAQ;AAC9F,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,MAAMC,YAAY,GAAGH,EAAE,CAACI,OAAO,CAAC,MAAM;EAClC,OAAO;IACHC,uBAAuB,EAAEL,EAAE,CAACM,EAAE,CAAC;EACnC,CAAC;AACL,CAAC,CAAC;AACFN,EAAE,CAACO,IAAI,CAAC,OAAO,EAAE,MAAOC,cAAc,IAAK;EACvC,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACHE,OAAO,EAAEV,EAAE,CAACM,EAAE,CAAC,CAACK,EAAE,EAAEC,IAAI,KAAK;MACzB;MACA,OAAOH,QAAQ,CAACC,OAAO,CAACC,EAAE,GAAG,GAAG,EAAEC,IAAI,CAAC;IAC3C,CAAC;EACL,CAAC;AACL,CAAC,CAAC;AACFZ,EAAE,CAACO,IAAI,CAAC,aAAa,EAAE,MAAOC,cAAc,IAAK;EAC7C,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACH,GAAGC,QAAQ;I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ACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,QAAQ,CAAC;UACT/G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAACgF,qBAAqB,CAAC,CAAC,CAAC;UAChE9G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAAC2D,cAAc,CAACzF,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAElE,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAEK,iBAAiB,CAACD,MAAM,CAAC;QAC1H,CAAC,CAAC;MACN;MACA,IAAIC,iBAAiB,CAACJ,aAAa,EAAE;QACjClE,EAAE,CAAC,WAAW,EAAE,YAAY;UACxB,MAAMD,MAAM,CAACqD,MAAM,CAAC,CAAC,CAAC,CAACkC,QAAQ,CAACa,OAAO,CAAC5B,YAAY,CAAC;UACrDxE,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACuG,qBAAqB,CAAC,CAAC,CAAC;UACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,SAAS,CAAC;QACd,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"publicOauth.test.js","names":["afterAll","afterEach","beforeAll","beforeEach","describe","expect","it","vi","commonJs","createPublicOauthClient","hoistedMocks","hoisted","makeTokenAndSaveRefresh","fn","mock","importOriginal","original","default","ms","opts","common","args","result","readLocal","spyOn","DEFAULT_CUR_URL","URL","fetchFn","mockWindow","location","toString","assign","href","pathname","history","replaceState","mockLocalStorage","setItem","getItem","removeItem","restoreAllMocks","mockRestore","clearAllMocks","mockReset","stubGlobal","unstubAllGlobals","BASE_CLIENT_ARGS","clientId","foundryUrl","redirectUrl","fullLoginUrl","each","name","currentUrl","clientArgs","should","redirectToLoginPage","loginPage","client","useHistory","postLoginPage","scopes","ctxPath","mocked","toHaveBeenCalledWith","objectContaining","client_id","token_endpoint_auth_method","createAuthorizationServer","any","Function","anything","refresh_token","codeVerifier","state","oldUrl","initialLocalState","ACCESS_TOKEN","Math","random","substring","mockImplementation","access_token","expires_at","Date","now","expires_in","Object","keys","length","tokenPromise","toBeCalledTimes","resolves","toBeUndefined","toBeCalledWith","JSON","stringify","window","rejects","toThrowError","Error","toHaveBeenCalledOnce","url","calls","origin","toEqual","fromEntries","searchParams","entries","code_challenge","String","redirect_uri","response_type","code_challenge_method","scope","toHaveBeenCalledTimes","undefined"],"sources":["publicOauth.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/* eslint-disable @typescript-eslint/consistent-type-imports */\nimport { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi, } from \"vitest\";\nimport * as commonJs from \"./common.js\";\nimport { createPublicOauthClient } from \"./createPublicOauthClient.js\";\nconst hoistedMocks = vi.hoisted(() => {\n return {\n makeTokenAndSaveRefresh: vi.fn(),\n };\n});\nvi.mock(\"delay\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n default: vi.fn((ms, opts) => {\n // speed up the tests\n return original.default(ms / 100, opts);\n }),\n };\n});\nvi.mock(\"./common.js\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n ...original,\n common: vi.fn((...args) => {\n const result = original.common(...args);\n return {\n ...result,\n makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh,\n };\n }),\n readLocal: vi.spyOn(original, \"readLocal\"),\n // vi.fn(original.readLocal),\n };\n});\nvi.mock(\"oauth4webapi\");\ndescribe(createPublicOauthClient, () => {\n const DEFAULT_CUR_URL = new URL(\"https://fauxurl\");\n const fetchFn = vi.fn();\n const mockWindow = {\n location: {\n toString: vi.fn(() => DEFAULT_CUR_URL),\n assign: vi.fn(),\n href: DEFAULT_CUR_URL.href,\n pathname: DEFAULT_CUR_URL.pathname,\n },\n history: {\n replaceState: vi.fn(),\n },\n };\n const mockLocalStorage = {\n setItem: vi.fn(),\n getItem: vi.fn(),\n removeItem: vi.fn(),\n };\n beforeEach((context) => {\n vi.restoreAllMocks();\n fetchFn.mockRestore();\n });\n afterEach((context) => {\n vi.clearAllMocks();\n fetchFn.mockReset();\n });\n beforeAll(() => {\n vi.stubGlobal(\"window\", mockWindow);\n vi.stubGlobal(\"localStorage\", mockLocalStorage);\n });\n afterAll(() => {\n vi.unstubAllGlobals();\n });\n const BASE_CLIENT_ARGS = {\n clientId: \"this-would-be-client-id\",\n foundryUrl: \"https://a.foundry.url.local\",\n redirectUrl: \"https://my.redirect.url.local\",\n fetchFn,\n };\n const fullLoginUrl = new URL(\"/loginPage\", DEFAULT_CUR_URL);\n describe.each([\n {\n name: \"Basic Usage\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is login page\",\n currentUrl: fullLoginUrl,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is loginPage\",\n currentUrl: new URL(\"/loginPage\", DEFAULT_CUR_URL),\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n ])(\"$name\", ({ clientArgs, currentUrl, should }) => {\n let client;\n beforeEach(() => {\n client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);\n mockWindow.location.href = new URL(currentUrl).href;\n mockWindow.location.pathname = new URL(currentUrl).pathname;\n });\n it(\"calls common with expected values\", () => {\n expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({\n client_id: clientArgs.clientId,\n token_endpoint_auth_method: \"none\",\n }), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? \"/multipass\", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function));\n });\n describe.each([\n {\n refresh_token: \"a-refresh-token\",\n },\n {\n codeVerifier: \"hi\",\n state: \"mom\",\n oldUrl: \"https://someoldurl.local\",\n },\n {},\n ])(\"Initial Local State: %s\", (initialLocalState) => {\n const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);\n beforeEach(() => {\n vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);\n hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({\n access_token: ACCESS_TOKEN,\n expires_at: Date.now(),\n expires_in: 10000,\n }));\n });\n if (Object.keys(initialLocalState).length === 0) {\n if (should.redirectToLoginPage) {\n it(\"redirects to login page\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n });\n }\n else {\n it(\"redirects to multipass\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n // we assume window.location.assign will take you away therefore we\n // also have to expect in this scenario that the thrown error happens\n await expect(tokenPromise)\n .rejects.toThrowError(new Error(\"Unable to redirect\"));\n expect(mockWindow.location.assign).toHaveBeenCalledOnce();\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n expect(url.origin).toEqual(clientArgs.foundryUrl);\n expect(url.pathname).toEqual(\"/multipass/api/oauth2/authorize\");\n expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({\n client_id: clientArgs.clientId,\n code_challenge: expect.any(String),\n redirect_uri: clientArgs.redirectUrl,\n response_type: \"code\",\n code_challenge_method: \"S256\",\n scope: \"offline_access api:ontologies-read api:ontologies-write\",\n state: expect.any(String),\n }));\n });\n }\n }\n if (initialLocalState.codeVerifier) {\n it(\"tries to auth with return results\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"signIn\");\n expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);\n expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialLocalState.oldUrl);\n });\n }\n if (initialLocalState.refresh_token) {\n it(\"refreshes\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"refresh\");\n });\n }\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAS,QAAQ;AAC9F,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,MAAMC,YAAY,GAAGH,EAAE,CAACI,OAAO,CAAC,MAAM;EAClC,OAAO;IACHC,uBAAuB,EAAEL,EAAE,CAACM,EAAE,CAAC;EACnC,CAAC;AACL,CAAC,CAAC;AACFN,EAAE,CAACO,IAAI,CAAC,OAAO,EAAE,MAAOC,cAAc,IAAK;EACvC,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACHE,OAAO,EAAEV,EAAE,CAACM,EAAE,CAAC,CAACK,EAAE,EAAEC,IAAI,KAAK;MACzB;MACA,OAAOH,QAAQ,CAACC,OAAO,CAACC,EAAE,GAAG,GAAG,EAAEC,IAAI,CAAC;IAC3C,CAAC;EACL,CAAC;AACL,CAAC,CAAC;AACFZ,EAAE,CAACO,IAAI,CAAC,aAAa,EAAE,MAAOC,cAAc,IAAK;EAC7C,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACH,GAAGC,QAAQ;IACXI,MAAM,EAAEb,EAAE,CAACM,EAAE,CAAC,CAAC,GAAGQ,IAAI,KAAK;MACv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;UAAE;UAC7E,QAAQ,CAAC;UACT/G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAACgF,qBAAqB,CAAC,CAAC,CAAC;UAChE9G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAAC2D,cAAc,CAACzF,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAElE,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAEK,iBAAiB,CAACD,MAAM,CAAC;QAC1H,CAAC,CAAC;MACN;MACA,IAAIC,iBAAiB,CAACJ,aAAa,EAAE;QACjClE,EAAE,CAAC,WAAW,EAAE,YAAY;UACxB,MAAMD,MAAM,CAACqD,MAAM,CAAC,CAAC,CAAC,CAACkC,QAAQ,CAACa,OAAO,CAAC5B,YAAY,CAAC;UACrDxE,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACuG,qBAAqB,CAAC,CAAC,CAAC;UACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,SAAS,CAAC;QACd,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -36,7 +36,7 @@ export function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, l
36
36
  useHistory: options.useHistory ?? true,
37
37
  loginPage: options.loginPage,
38
38
  postLoginPage: options.postLoginPage || window.location.toString(),
39
- scopes: options.scopes ?? ["api:read-data", "api:write-data"],
39
+ scopes: options.scopes ?? ["api:ontologies-read", "api:ontologies-write"],
40
40
  fetchFn: options.fetchFn ?? globalThis.fetch,
41
41
  ctxPath: options.ctxPath ?? "multipass"
42
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","globalThis","fetch"],"sources":["utils.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport invariant from \"tiny-invariant\";\nexport function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n let options = {};\n if (typeof useHistory === \"object\") {\n invariant(!loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath, \"If useHistory is an object, other options should not be provided\");\n options = useHistory;\n }\n else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n scopes: options.scopes ?? [\"api:read-data\", \"api:write-data\"],\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,OAAO,SAASC,+BAA+BA,CAACC,GAAG,EAAEC,YAAY,EAAEC,UAAU,EAAEC,SAAS,EAAEC,aAAa,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE;EAC/H,IAAIC,OAAO,GAAG,CAAC,CAAC;EAChB,IAAI,OAAON,UAAU,KAAK,QAAQ,EAAE;IAChC,EAAU,CAACC,SAAS,IAAI,CAACC,aAAa,IAAI,CAACC,MAAM,IAAI,CAACC,OAAO,IAAI,CAACC,OAAO,IAAAE,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAzEb,SAAS,QAAkE,kEAAkE,IAA7IA,SAAS;IACTU,OAAO,GAAGN,UAAU;EACxB,CAAC,MACI;IACDM,OAAO,GAAG;MACNN,UAAU;MACVC,SAAS;MACTC,aAAa;MACbC,MAAM;MACNC,OAAO;MACPC;IACJ,CAAC;EACL;EACA,CAAUP,GAAG,GAAAS,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAbb,SAAS,QAAM,iBAAiB,IAAhCA,SAAS;EACT,CAAUG,YAAY,GAAAQ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAtBb,SAAS,QAAe,yBAAyB,IAAjDA,SAAS;EACT;EACA,OAAO;IACHI,UAAU,EAAEM,OAAO,CAACN,UAAU,IAAI,IAAI;IACtCC,SAAS,EAAEK,OAAO,CAACL,SAAS;IAC5BC,aAAa,EAAEI,OAAO,CAACJ,aAAa,IAAIQ,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAC;IAClET,MAAM,EAAEG,OAAO,CAACH,MAAM,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAC7DC,OAAO,EAAEE,OAAO,CAACF,OAAO,IAAIS,UAAU,CAACC,KAAK;IAC5CT,OAAO,EAAEC,OAAO,CAACD,OAAO,IAAI;EAChC,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","globalThis","fetch"],"sources":["utils.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport invariant from \"tiny-invariant\";\nexport function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n let options = {};\n if (typeof useHistory === \"object\") {\n invariant(!loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath, \"If useHistory is an object, other options should not be provided\");\n options = useHistory;\n }\n else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n scopes: options.scopes ?? [\"api:ontologies-read\", \"api:ontologies-write\"],\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,OAAO,SAASC,+BAA+BA,CAACC,GAAG,EAAEC,YAAY,EAAEC,UAAU,EAAEC,SAAS,EAAEC,aAAa,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE;EAC/H,IAAIC,OAAO,GAAG,CAAC,CAAC;EAChB,IAAI,OAAON,UAAU,KAAK,QAAQ,EAAE;IAChC,EAAU,CAACC,SAAS,IAAI,CAACC,aAAa,IAAI,CAACC,MAAM,IAAI,CAACC,OAAO,IAAI,CAACC,OAAO,IAAAE,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAzEb,SAAS,QAAkE,kEAAkE,IAA7IA,SAAS;IACTU,OAAO,GAAGN,UAAU;EACxB,CAAC,MACI;IACDM,OAAO,GAAG;MACNN,UAAU;MACVC,SAAS;MACTC,aAAa;MACbC,MAAM;MACNC,OAAO;MACPC;IACJ,CAAC;EACL;EACA,CAAUP,GAAG,GAAAS,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAbb,SAAS,QAAM,iBAAiB,IAAhCA,SAAS;EACT,CAAUG,YAAY,GAAAQ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAtBb,SAAS,QAAe,yBAAyB,IAAjDA,SAAS;EACT;EACA,OAAO;IACHI,UAAU,EAAEM,OAAO,CAACN,UAAU,IAAI,IAAI;IACtCC,SAAS,EAAEK,OAAO,CAACL,SAAS;IAC5BC,aAAa,EAAEI,OAAO,CAACJ,aAAa,IAAIQ,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAC;IAClET,MAAM,EAAEG,OAAO,CAACH,MAAM,IAAI,CAAC,qBAAqB,EAAE,sBAAsB,CAAC;IACzEC,OAAO,EAAEE,OAAO,CAACF,OAAO,IAAIS,UAAU,CAACC,KAAK;IAC5CT,OAAO,EAAEC,OAAO,CAACD,OAAO,IAAI;EAChC,CAAC;AACL","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom"],"sources":["AuthorizationServer.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { describe, expect, it, } from \"vitest\";\nimport { createAuthorizationServer } from \"./common.js\";\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"/multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n const authServerCustom = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com/foo/first/someStuff\");\n expect(authServerCustom).toEqual({\n token_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAS,QAAQ;AAC9C,SAASC,yBAAyB,QAAQ,aAAa;AACvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC1CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,YAAY,EAAE,4BAA4B,CAAC;IACxFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;EACFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,WAAW,EAAE,4BAA4B,CAAC;IACvFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;IACF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAAC,WAAW,EAAE,gDAAgD,CAAC;IACjHF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC7BC,cAAc,EAAE,2EAA2E;MAC3FC,sBAAsB,EAAE,+EAA+E;MACvGC,mBAAmB,EAAE,kFAAkF;MACvGC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"AuthorizationServer.test.js","names":["describe","expect","it","createAuthorizationServer","authServer","toEqual","token_endpoint","authorization_endpoint","revocation_endpoint","issuer","authServerCustom"],"sources":["AuthorizationServer.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { describe, expect, it } from \"vitest\";\nimport { createAuthorizationServer } from \"./common.js\";\ndescribe(\"Create authorization server\", () => {\n it(\"works with old multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"/multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n });\n it(\"works with new multipass ctx path\", () => {\n const authServer = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com\");\n expect(authServer).toEqual({\n token_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/multipass\",\n });\n const authServerCustom = createAuthorizationServer(\"multipass\", \"https://stack.palantir.com/foo/first/someStuff\");\n expect(authServerCustom).toEqual({\n token_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/token\",\n authorization_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/authorize\",\n revocation_endpoint: \"https://stack.palantir.com/foo/first/someStuff/multipass/api/oauth2/revoke_token\",\n issuer: \"https://stack.palantir.com/foo/first/someStuff/multipass\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,yBAAyB,QAAQ,aAAa;AACvDH,QAAQ,CAAC,6BAA6B,EAAE,MAAM;EAC1CE,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,YAAY,EAAE,4BAA4B,CAAC;IACxFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;EACFP,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC1C,MAAME,UAAU,GAAGD,yBAAyB,CAAC,WAAW,EAAE,4BAA4B,CAAC;IACvFF,MAAM,CAACG,UAAU,CAAC,CAACC,OAAO,CAAC;MACvBC,cAAc,EAAE,uDAAuD;MACvEC,sBAAsB,EAAE,2DAA2D;MACnFC,mBAAmB,EAAE,8DAA8D;MACnFC,MAAM,EAAE;IACZ,CAAC,CAAC;IACF,MAAMC,gBAAgB,GAAGP,yBAAyB,CAAC,WAAW,EAAE,gDAAgD,CAAC;IACjHF,MAAM,CAACS,gBAAgB,CAAC,CAACL,OAAO,CAAC;MAC7BC,cAAc,EAAE,2EAA2E;MAC3FC,sBAAsB,EAAE,+EAA+E;MACvGC,mBAAmB,EAAE,kFAAkF;MACvGC,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"createConfidentialOauthClient.d.ts","sourceRoot":"","sources":["../../src/createConfidentialOauthClient.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAG5E;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,EAAwC,EACtD,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,EACnD,OAAO,GAAE,MAAoB,GAC5B,uBAAuB,CAgCzB"}
1
+ {"version":3,"file":"createConfidentialOauthClient.d.ts","sourceRoot":"","sources":["../../src/createConfidentialOauthClient.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAG5E;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,EAAoD,EAClE,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,EACnD,OAAO,GAAE,MAAoB,GAC5B,uBAAuB,CAgCzB"}
@@ -25,7 +25,7 @@ import { throwIfError } from "./throwIfError.js";
25
25
  * @param ctxPath
26
26
  * @returns which can be used as a token provider
27
27
  */
28
- export function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:read-data", "api:write-data"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
28
+ export function createConfidentialOauthClient(client_id, client_secret, url, scopes = ["api:ontologies-read", "api:ontologies-write"], fetchFn = globalThis.fetch, ctxPath = "multipass") {
29
29
  const client = {
30
30
  client_id,
31
31
  client_secret
@@ -1 +1 @@
1
- {"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(client_id, client_secret, url, scopes = [\"api:read-data\", \"api:write-data\"], fetchFn = globalThis.fetch, ctxPath = \"multipass\") {\n const client = { client_id, client_secret };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n const { getToken, makeTokenAndSaveRefresh } = common(client, authServer, _signIn, oauthHttpOptions, undefined);\n async function _signIn() {\n return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({ scope: scopes.join(\" \") }), oauthHttpOptions))), \"signIn\");\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,6BAA6B,EAAEC,WAAW,EAAEC,gCAAgC,QAAS,cAAc;AAC5G,SAASC,MAAM,EAAEC,yBAAyB,QAAQ,aAAa;AAC/D,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACC,SAAS,EAAEC,aAAa,EAAEC,GAAG,EAAEC,MAAM,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,EAAEC,OAAO,GAAGC,UAAU,CAACC,KAAK,EAAEC,OAAO,GAAG,WAAW,EAAE;EAC1K,MAAMC,MAAM,GAAG;IAAER,SAAS;IAAEC;EAAc,CAAC;EAC3C,MAAMQ,UAAU,GAAGZ,yBAAyB,CAACU,OAAO,EAAEL,GAAG,CAAC;EAC1D,MAAMQ,gBAAgB,GAAG;IAAE,CAAChB,WAAW,GAAGU;EAAQ,CAAC;EACnD,MAAM;IAAEO,QAAQ;IAAEC;EAAwB,CAAC,GAAGhB,MAAM,CAACY,MAAM,EAAEC,UAAU,EACvE,kBAAyB;IACrB,OAAOG,uBAAuB,CAACd,YAAY,CAAC,MAAMH,gCAAgC,CAACc,UAAU,EAAED,MAAM,EAAE,MAAMf,6BAA6B,CAACgB,UAAU,EAAED,MAAM,EAAE,IAAIK,eAAe,CAAC;MAAEC,KAAK,EAAEX,MAAM,CAACY,IAAI,CAAC,GAAG;IAAE,CAAC,CAAC,EAAEL,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;EACnP,CAAC,EAHiFA,gBAAgB,EAAEM,SAAS,CAAC;EAI9G,OAAOL,QAAQ;AACnB","ignoreList":[]}
1
+ {"version":3,"file":"createConfidentialOauthClient.js","names":["clientCredentialsGrantRequest","customFetch","processClientCredentialsResponse","common","createAuthorizationServer","throwIfError","createConfidentialOauthClient","client_id","client_secret","url","scopes","fetchFn","globalThis","fetch","ctxPath","client","authServer","oauthHttpOptions","getToken","makeTokenAndSaveRefresh","URLSearchParams","scope","join","undefined"],"sources":["createConfidentialOauthClient.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { clientCredentialsGrantRequest, customFetch, processClientCredentialsResponse, } from \"oauth4webapi\";\nimport { common, createAuthorizationServer } from \"./common.js\";\nimport { throwIfError } from \"./throwIfError.js\";\n/**\n * @param client_id\n * @param client_secret\n * @param url the base url of your foundry server\n * @param scopes\n * @param fetchFn\n * @param ctxPath\n * @returns which can be used as a token provider\n */\nexport function createConfidentialOauthClient(client_id, client_secret, url, scopes = [\"api:ontologies-read\", \"api:ontologies-write\"], fetchFn = globalThis.fetch, ctxPath = \"multipass\") {\n const client = { client_id, client_secret };\n const authServer = createAuthorizationServer(ctxPath, url);\n const oauthHttpOptions = { [customFetch]: fetchFn };\n const { getToken, makeTokenAndSaveRefresh } = common(client, authServer, _signIn, oauthHttpOptions, undefined);\n async function _signIn() {\n return makeTokenAndSaveRefresh(throwIfError(await processClientCredentialsResponse(authServer, client, await clientCredentialsGrantRequest(authServer, client, new URLSearchParams({ scope: scopes.join(\" \") }), oauthHttpOptions))), \"signIn\");\n }\n return getToken;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,6BAA6B,EAAEC,WAAW,EAAEC,gCAAgC,QAAS,cAAc;AAC5G,SAASC,MAAM,EAAEC,yBAAyB,QAAQ,aAAa;AAC/D,SAASC,YAAY,QAAQ,mBAAmB;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAACC,SAAS,EAAEC,aAAa,EAAEC,GAAG,EAAEC,MAAM,GAAG,CAAC,qBAAqB,EAAE,sBAAsB,CAAC,EAAEC,OAAO,GAAGC,UAAU,CAACC,KAAK,EAAEC,OAAO,GAAG,WAAW,EAAE;EACtL,MAAMC,MAAM,GAAG;IAAER,SAAS;IAAEC;EAAc,CAAC;EAC3C,MAAMQ,UAAU,GAAGZ,yBAAyB,CAACU,OAAO,EAAEL,GAAG,CAAC;EAC1D,MAAMQ,gBAAgB,GAAG;IAAE,CAAChB,WAAW,GAAGU;EAAQ,CAAC;EACnD,MAAM;IAAEO,QAAQ;IAAEC;EAAwB,CAAC,GAAGhB,MAAM,CAACY,MAAM,EAAEC,UAAU,EACvE,kBAAyB;IACrB,OAAOG,uBAAuB,CAACd,YAAY,CAAC,MAAMH,gCAAgC,CAACc,UAAU,EAAED,MAAM,EAAE,MAAMf,6BAA6B,CAACgB,UAAU,EAAED,MAAM,EAAE,IAAIK,eAAe,CAAC;MAAEC,KAAK,EAAEX,MAAM,CAACY,IAAI,CAAC,GAAG;IAAE,CAAC,CAAC,EAAEL,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;EACnP,CAAC,EAHiFA,gBAAgB,EAAEM,SAAS,CAAC;EAI9G,OAAOL,QAAQ;AACnB","ignoreList":[]}
@@ -13,7 +13,7 @@ export interface PublicOauthClientOptions {
13
13
  */
14
14
  postLoginPage?: string;
15
15
  /**
16
- * * @param {string[]} [scopes=[]] - OAuth scopes to request. If not provided, defaults to `["api:read-data", "api:write-data"]`
16
+ * * @param {string[]} [scopes=[]] - OAuth scopes to request. If not provided, defaults to `["api:ontologies-read", "api:ontologies-write"]`
17
17
  */
18
18
  scopes?: string[];
19
19
  /**
@@ -44,7 +44,7 @@ export declare function createPublicOauthClient(clientId: string, url: string, r
44
44
  * @param {boolean} useHistory - If true, uses `history.replaceState()`, otherwise uses `window.location.assign()` (defaults to true)
45
45
  * @param {string} loginPage - Custom landing page URL prior to logging in
46
46
  * @param {string} postLoginPage - URL to return to after completed authentication cycle (defaults to `window.location.toString()`)
47
- * @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `["api:read-data", "api:write-data"]`
47
+ * @param {string[]} scopes - OAuth scopes to request. If not provided, defaults to `["api:ontologies-read", "api:ontologies-write"]`
48
48
  * @param {typeof globalThis.fetch} fetchFn - Custom fetch function to use for requests (defaults to `globalThis.fetch`)
49
49
  * @param {string} ctxPath - Context path for the authorization server (defaults to "multipass")
50
50
  * @returns {PublicOauthClient} A client that can be used as a token provider
@@ -210,7 +210,7 @@ describe(createPublicOauthClient, () => {
210
210
  redirect_uri: clientArgs.redirectUrl,
211
211
  response_type: "code",
212
212
  code_challenge_method: "S256",
213
- scope: "offline_access api:read-data api:write-data",
213
+ scope: "offline_access api:ontologies-read api:ontologies-write",
214
214
  state: expect.any(String)
215
215
  }));
216
216
  });
@@ -1 +1 @@
1
- {"version":3,"file":"publicOauth.test.js","names":["afterAll","afterEach","beforeAll","beforeEach","describe","expect","it","vi","commonJs","createPublicOauthClient","hoistedMocks","hoisted","makeTokenAndSaveRefresh","fn","mock","importOriginal","original","default","ms","opts","common","args","result","readLocal","spyOn","DEFAULT_CUR_URL","URL","fetchFn","mockWindow","location","toString","assign","href","pathname","history","replaceState","mockLocalStorage","setItem","getItem","removeItem","restoreAllMocks","mockRestore","clearAllMocks","mockReset","stubGlobal","unstubAllGlobals","BASE_CLIENT_ARGS","clientId","foundryUrl","redirectUrl","fullLoginUrl","each","name","currentUrl","clientArgs","should","redirectToLoginPage","loginPage","client","useHistory","postLoginPage","scopes","ctxPath","mocked","toHaveBeenCalledWith","objectContaining","client_id","token_endpoint_auth_method","createAuthorizationServer","any","Function","anything","refresh_token","codeVerifier","state","oldUrl","initialLocalState","ACCESS_TOKEN","Math","random","substring","mockImplementation","access_token","expires_at","Date","now","expires_in","Object","keys","length","tokenPromise","toBeCalledTimes","resolves","toBeUndefined","toBeCalledWith","JSON","stringify","window","rejects","toThrowError","Error","toHaveBeenCalledOnce","url","calls","origin","toEqual","fromEntries","searchParams","entries","code_challenge","String","redirect_uri","response_type","code_challenge_method","scope","toHaveBeenCalledTimes","undefined"],"sources":["publicOauth.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/* eslint-disable @typescript-eslint/consistent-type-imports */\nimport { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi, } from \"vitest\";\nimport * as commonJs from \"./common.js\";\nimport { createPublicOauthClient } from \"./createPublicOauthClient.js\";\nconst hoistedMocks = vi.hoisted(() => {\n return {\n makeTokenAndSaveRefresh: vi.fn(),\n };\n});\nvi.mock(\"delay\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n default: vi.fn((ms, opts) => {\n // speed up the tests\n return original.default(ms / 100, opts);\n }),\n };\n});\nvi.mock(\"./common.js\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n ...original,\n common: vi.fn((...args) => {\n const result = original.common(...args);\n return {\n ...result,\n makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh,\n };\n }),\n readLocal: vi.spyOn(original, \"readLocal\"),\n // vi.fn(original.readLocal),\n };\n});\nvi.mock(\"oauth4webapi\");\ndescribe(createPublicOauthClient, () => {\n const DEFAULT_CUR_URL = new URL(\"https://fauxurl\");\n const fetchFn = vi.fn();\n const mockWindow = {\n location: {\n toString: vi.fn(() => DEFAULT_CUR_URL),\n assign: vi.fn(),\n href: DEFAULT_CUR_URL.href,\n pathname: DEFAULT_CUR_URL.pathname,\n },\n history: {\n replaceState: vi.fn(),\n },\n };\n const mockLocalStorage = {\n setItem: vi.fn(),\n getItem: vi.fn(),\n removeItem: vi.fn(),\n };\n beforeEach((context) => {\n vi.restoreAllMocks();\n fetchFn.mockRestore();\n });\n afterEach((context) => {\n vi.clearAllMocks();\n fetchFn.mockReset();\n });\n beforeAll(() => {\n vi.stubGlobal(\"window\", mockWindow);\n vi.stubGlobal(\"localStorage\", mockLocalStorage);\n });\n afterAll(() => {\n vi.unstubAllGlobals();\n });\n const BASE_CLIENT_ARGS = {\n clientId: \"this-would-be-client-id\",\n foundryUrl: \"https://a.foundry.url.local\",\n redirectUrl: \"https://my.redirect.url.local\",\n fetchFn,\n };\n const fullLoginUrl = new URL(\"/loginPage\", DEFAULT_CUR_URL);\n describe.each([\n {\n name: \"Basic Usage\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is login page\",\n currentUrl: fullLoginUrl,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is loginPage\",\n currentUrl: new URL(\"/loginPage\", DEFAULT_CUR_URL),\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n ])(\"$name\", ({ clientArgs, currentUrl, should }) => {\n let client;\n beforeEach(() => {\n client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);\n mockWindow.location.href = new URL(currentUrl).href;\n mockWindow.location.pathname = new URL(currentUrl).pathname;\n });\n it(\"calls common with expected values\", () => {\n expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({\n client_id: clientArgs.clientId,\n token_endpoint_auth_method: \"none\",\n }), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? \"/multipass\", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function));\n });\n describe.each([\n {\n refresh_token: \"a-refresh-token\",\n },\n {\n codeVerifier: \"hi\",\n state: \"mom\",\n oldUrl: \"https://someoldurl.local\",\n },\n {},\n ])(\"Initial Local State: %s\", (initialLocalState) => {\n const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);\n beforeEach(() => {\n vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);\n hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({\n access_token: ACCESS_TOKEN,\n expires_at: Date.now(),\n expires_in: 10000,\n }));\n });\n if (Object.keys(initialLocalState).length === 0) {\n if (should.redirectToLoginPage) {\n it(\"redirects to login page\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n });\n }\n else {\n it(\"redirects to multipass\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n // we assume window.location.assign will take you away therefore we\n // also have to expect in this scenario that the thrown error happens\n await expect(tokenPromise)\n .rejects.toThrowError(new Error(\"Unable to redirect\"));\n expect(mockWindow.location.assign).toHaveBeenCalledOnce();\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n expect(url.origin).toEqual(clientArgs.foundryUrl);\n expect(url.pathname).toEqual(\"/multipass/api/oauth2/authorize\");\n expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({\n client_id: clientArgs.clientId,\n code_challenge: expect.any(String),\n redirect_uri: clientArgs.redirectUrl,\n response_type: \"code\",\n code_challenge_method: \"S256\",\n scope: \"offline_access api:read-data api:write-data\",\n state: expect.any(String),\n }));\n });\n }\n }\n if (initialLocalState.codeVerifier) {\n it(\"tries to auth with return results\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"signIn\");\n expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);\n expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialLocalState.oldUrl);\n });\n }\n if (initialLocalState.refresh_token) {\n it(\"refreshes\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"refresh\");\n });\n }\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAS,QAAQ;AAC9F,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,MAAMC,YAAY,GAAGH,EAAE,CAACI,OAAO,CAAC,MAAM;EAClC,OAAO;IACHC,uBAAuB,EAAEL,EAAE,CAACM,EAAE,CAAC;EACnC,CAAC;AACL,CAAC,CAAC;AACFN,EAAE,CAACO,IAAI,CAAC,OAAO,EAAE,MAAOC,cAAc,IAAK;EACvC,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACHE,OAAO,EAAEV,EAAE,CAACM,EA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C5B,CAAC,CAAC,CAAC;UACP,CAAC,CAAC;QACN;MACJ;MACA,IAAIlC,iBAAiB,CAACH,YAAY,EAAE;QAChCnE,EAAE,CAAC,mCAAmC,EAAE,YAAY;UAChD,MAAMD,MAAM,CAACqD,MAAM,CAAC,CAAC,CAAC,CAACkC,QAAQ,CAACa,OAAO,CAAC5B,YAAY,CAAC;UACrDxE,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACuG,qBAAqB,CAAC,CAAC,CAAC;UACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,QAAQ,CAAC;UACT/G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAACgF,qBAAqB,CAAC,CAAC,CAAC;UAChE9G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAAC2D,cAAc,CAACzF,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAElE,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAEK,iBAAiB,CAACD,MAAM,CAAC;QAC1H,CAAC,CAAC;MACN;MACA,IAAIC,iBAAiB,CAACJ,aAAa,EAAE;QACjClE,EAAE,CAAC,WAAW,EAAE,YAAY;UACxB,MAAMD,MAAM,CAACqD,MAAM,CAAC,CAAC,CAAC,CAACkC,QAAQ,CAACa,OAAO,CAAC5B,YAAY,CAAC;UACrDxE,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACuG,qBAAqB,CAAC,CAAC,CAAC;UACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,SAAS,CAAC;QACd,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"publicOauth.test.js","names":["afterAll","afterEach","beforeAll","beforeEach","describe","expect","it","vi","commonJs","createPublicOauthClient","hoistedMocks","hoisted","makeTokenAndSaveRefresh","fn","mock","importOriginal","original","default","ms","opts","common","args","result","readLocal","spyOn","DEFAULT_CUR_URL","URL","fetchFn","mockWindow","location","toString","assign","href","pathname","history","replaceState","mockLocalStorage","setItem","getItem","removeItem","restoreAllMocks","mockRestore","clearAllMocks","mockReset","stubGlobal","unstubAllGlobals","BASE_CLIENT_ARGS","clientId","foundryUrl","redirectUrl","fullLoginUrl","each","name","currentUrl","clientArgs","should","redirectToLoginPage","loginPage","client","useHistory","postLoginPage","scopes","ctxPath","mocked","toHaveBeenCalledWith","objectContaining","client_id","token_endpoint_auth_method","createAuthorizationServer","any","Function","anything","refresh_token","codeVerifier","state","oldUrl","initialLocalState","ACCESS_TOKEN","Math","random","substring","mockImplementation","access_token","expires_at","Date","now","expires_in","Object","keys","length","tokenPromise","toBeCalledTimes","resolves","toBeUndefined","toBeCalledWith","JSON","stringify","window","rejects","toThrowError","Error","toHaveBeenCalledOnce","url","calls","origin","toEqual","fromEntries","searchParams","entries","code_challenge","String","redirect_uri","response_type","code_challenge_method","scope","toHaveBeenCalledTimes","undefined"],"sources":["publicOauth.test.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n/* eslint-disable @typescript-eslint/consistent-type-imports */\nimport { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi, } from \"vitest\";\nimport * as commonJs from \"./common.js\";\nimport { createPublicOauthClient } from \"./createPublicOauthClient.js\";\nconst hoistedMocks = vi.hoisted(() => {\n return {\n makeTokenAndSaveRefresh: vi.fn(),\n };\n});\nvi.mock(\"delay\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n default: vi.fn((ms, opts) => {\n // speed up the tests\n return original.default(ms / 100, opts);\n }),\n };\n});\nvi.mock(\"./common.js\", async (importOriginal) => {\n const original = await importOriginal();\n return {\n ...original,\n common: vi.fn((...args) => {\n const result = original.common(...args);\n return {\n ...result,\n makeTokenAndSaveRefresh: hoistedMocks.makeTokenAndSaveRefresh,\n };\n }),\n readLocal: vi.spyOn(original, \"readLocal\"),\n // vi.fn(original.readLocal),\n };\n});\nvi.mock(\"oauth4webapi\");\ndescribe(createPublicOauthClient, () => {\n const DEFAULT_CUR_URL = new URL(\"https://fauxurl\");\n const fetchFn = vi.fn();\n const mockWindow = {\n location: {\n toString: vi.fn(() => DEFAULT_CUR_URL),\n assign: vi.fn(),\n href: DEFAULT_CUR_URL.href,\n pathname: DEFAULT_CUR_URL.pathname,\n },\n history: {\n replaceState: vi.fn(),\n },\n };\n const mockLocalStorage = {\n setItem: vi.fn(),\n getItem: vi.fn(),\n removeItem: vi.fn(),\n };\n beforeEach((context) => {\n vi.restoreAllMocks();\n fetchFn.mockRestore();\n });\n afterEach((context) => {\n vi.clearAllMocks();\n fetchFn.mockReset();\n });\n beforeAll(() => {\n vi.stubGlobal(\"window\", mockWindow);\n vi.stubGlobal(\"localStorage\", mockLocalStorage);\n });\n afterAll(() => {\n vi.unstubAllGlobals();\n });\n const BASE_CLIENT_ARGS = {\n clientId: \"this-would-be-client-id\",\n foundryUrl: \"https://a.foundry.url.local\",\n redirectUrl: \"https://my.redirect.url.local\",\n fetchFn,\n };\n const fullLoginUrl = new URL(\"/loginPage\", DEFAULT_CUR_URL);\n describe.each([\n {\n name: \"Basic Usage\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ full loginPage and curUrl is login page\",\n currentUrl: fullLoginUrl,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: fullLoginUrl.toString(),\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is root\",\n currentUrl: DEFAULT_CUR_URL,\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: true,\n },\n },\n {\n name: \"Base w/ short loginPage and curUrl is loginPage\",\n currentUrl: new URL(\"/loginPage\", DEFAULT_CUR_URL),\n clientArgs: {\n ...BASE_CLIENT_ARGS,\n loginPage: \"/loginPage\",\n },\n should: {\n redirectToLoginPage: false,\n },\n },\n ])(\"$name\", ({ clientArgs, currentUrl, should }) => {\n let client;\n beforeEach(() => {\n client = createPublicOauthClient(clientArgs.clientId, clientArgs.foundryUrl, clientArgs.redirectUrl, clientArgs.useHistory, clientArgs.loginPage, clientArgs.postLoginPage, clientArgs.scopes, clientArgs.fetchFn, clientArgs.ctxPath);\n mockWindow.location.href = new URL(currentUrl).href;\n mockWindow.location.pathname = new URL(currentUrl).pathname;\n });\n it(\"calls common with expected values\", () => {\n expect(vi.mocked(commonJs.common)).toHaveBeenCalledWith(expect.objectContaining({\n client_id: clientArgs.clientId,\n token_endpoint_auth_method: \"none\",\n }), commonJs.createAuthorizationServer(clientArgs.ctxPath ?? \"/multipass\", clientArgs.foundryUrl), expect.any(Function), expect.anything(), expect.any(Function));\n });\n describe.each([\n {\n refresh_token: \"a-refresh-token\",\n },\n {\n codeVerifier: \"hi\",\n state: \"mom\",\n oldUrl: \"https://someoldurl.local\",\n },\n {},\n ])(\"Initial Local State: %s\", (initialLocalState) => {\n const ACCESS_TOKEN = (Math.random() + 1).toString(36).substring(7);\n beforeEach(() => {\n vi.mocked(commonJs.readLocal).mockImplementation(() => initialLocalState);\n hoistedMocks.makeTokenAndSaveRefresh.mockImplementation(() => ({\n access_token: ACCESS_TOKEN,\n expires_at: Date.now(),\n expires_in: 10000,\n }));\n });\n if (Object.keys(initialLocalState).length === 0) {\n if (should.redirectToLoginPage) {\n it(\"redirects to login page\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n });\n }\n else {\n it(\"redirects to multipass\", async () => {\n const tokenPromise = client();\n expect(vi.mocked(commonJs.common)).toBeCalledTimes(1);\n if (should.redirectToLoginPage) {\n // expect save local\n await expect(tokenPromise).resolves.toBeUndefined();\n expect(mockLocalStorage.setItem).toBeCalledWith(`@osdk/oauth : refresh : ${clientArgs.clientId}`, JSON.stringify({ oldUrl: window.location.toString() }));\n expect(mockWindow.history.replaceState).toHaveBeenCalledWith({}, \"\", clientArgs.loginPage);\n return;\n }\n // we assume window.location.assign will take you away therefore we\n // also have to expect in this scenario that the thrown error happens\n await expect(tokenPromise)\n .rejects.toThrowError(new Error(\"Unable to redirect\"));\n expect(mockWindow.location.assign).toHaveBeenCalledOnce();\n const url = new URL(mockWindow.location.assign.mock.calls[0][0]);\n expect(url.origin).toEqual(clientArgs.foundryUrl);\n expect(url.pathname).toEqual(\"/multipass/api/oauth2/authorize\");\n expect(Object.fromEntries(url.searchParams.entries())).toEqual(expect.objectContaining({\n client_id: clientArgs.clientId,\n code_challenge: expect.any(String),\n redirect_uri: clientArgs.redirectUrl,\n response_type: \"code\",\n code_challenge_method: \"S256\",\n scope: \"offline_access api:ontologies-read api:ontologies-write\",\n state: expect.any(String),\n }));\n });\n }\n }\n if (initialLocalState.codeVerifier) {\n it(\"tries to auth with return results\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"signIn\");\n expect(mockWindow.history.replaceState).toHaveBeenCalledTimes(1);\n expect(mockWindow.history.replaceState).toBeCalledWith(expect.anything(), expect.anything(), initialLocalState.oldUrl);\n });\n }\n if (initialLocalState.refresh_token) {\n it(\"refreshes\", async () => {\n await expect(client()).resolves.toEqual(ACCESS_TOKEN);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledTimes(1);\n expect(hoistedMocks.makeTokenAndSaveRefresh).toHaveBeenCalledWith(undefined, // this is only because we didn't mock out the internals\n \"refresh\");\n });\n }\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAS,QAAQ;AAC9F,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,MAAMC,YAAY,GAAGH,EAAE,CAACI,OAAO,CAAC,MAAM;EAClC,OAAO;IACHC,uBAAuB,EAAEL,EAAE,CAACM,EAAE,CAAC;EACnC,CAAC;AACL,CAAC,CAAC;AACFN,EAAE,CAACO,IAAI,CAAC,OAAO,EAAE,MAAOC,cAAc,IAAK;EACvC,MAAMC,QAAQ,GAAG,MAAMD,cAAc,CAAC,CAAC;EACvC,OAAO;IACHE,OAAO,EAAEV,EAAE,CAACM,EAAE,CAAC,CAACK,EAAE,EAAEC,IAAI,KAAK;MACzB;MACA,OAAOH,QAAQ,CAACC,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AACH,YAAY,EAAE;QAChCnE,EAAE,CAAC,mCAAmC,EAAE,YAAY;UAChD,MAAMD,MAAM,CAACqD,MAAM,CAAC,CAAC,CAAC,CAACkC,QAAQ,CAACa,OAAO,CAAC5B,YAAY,CAAC;UACrDxE,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACuG,qBAAqB,CAAC,CAAC,CAAC;UACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,QAAQ,CAAC;UACT/G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAACgF,qBAAqB,CAAC,CAAC,CAAC;UAChE9G,MAAM,CAACuB,UAAU,CAACM,OAAO,CAACC,YAAY,CAAC,CAAC2D,cAAc,CAACzF,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAElE,MAAM,CAACkE,QAAQ,CAAC,CAAC,EAAEK,iBAAiB,CAACD,MAAM,CAAC;QAC1H,CAAC,CAAC;MACN;MACA,IAAIC,iBAAiB,CAACJ,aAAa,EAAE;QACjClE,EAAE,CAAC,WAAW,EAAE,YAAY;UACxB,MAAMD,MAAM,CAACqD,MAAM,CAAC,CAAC,CAAC,CAACkC,QAAQ,CAACa,OAAO,CAAC5B,YAAY,CAAC;UACrDxE,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACuG,qBAAqB,CAAC,CAAC,CAAC;UACrE9G,MAAM,CAACK,YAAY,CAACE,uBAAuB,CAAC,CAACoD,oBAAoB,CAACoD,SAAS;UAAE;UAC7E,SAAS,CAAC;QACd,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -36,7 +36,7 @@ export function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, l
36
36
  useHistory: options.useHistory ?? true,
37
37
  loginPage: options.loginPage,
38
38
  postLoginPage: options.postLoginPage || window.location.toString(),
39
- scopes: options.scopes ?? ["api:read-data", "api:write-data"],
39
+ scopes: options.scopes ?? ["api:ontologies-read", "api:ontologies-write"],
40
40
  fetchFn: options.fetchFn ?? globalThis.fetch,
41
41
  ctxPath: options.ctxPath ?? "multipass"
42
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","globalThis","fetch"],"sources":["utils.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport invariant from \"tiny-invariant\";\nexport function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n let options = {};\n if (typeof useHistory === \"object\") {\n invariant(!loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath, \"If useHistory is an object, other options should not be provided\");\n options = useHistory;\n }\n else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n scopes: options.scopes ?? [\"api:read-data\", \"api:write-data\"],\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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invariant","processOptionsAndAssignDefaults","url","redirect_uri","useHistory","loginPage","postLoginPage","scopes","fetchFn","ctxPath","options","process","env","NODE_ENV","window","location","toString","globalThis","fetch"],"sources":["utils.js"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport invariant from \"tiny-invariant\";\nexport function processOptionsAndAssignDefaults(url, redirect_uri, useHistory, loginPage, postLoginPage, scopes, fetchFn, ctxPath) {\n let options = {};\n if (typeof useHistory === \"object\") {\n invariant(!loginPage && !postLoginPage && !scopes && !fetchFn && !ctxPath, \"If useHistory is an object, other options should not be provided\");\n options = useHistory;\n }\n else {\n options = {\n useHistory,\n loginPage,\n postLoginPage,\n scopes,\n fetchFn,\n ctxPath,\n };\n }\n invariant(url, \"url is required\");\n invariant(redirect_uri, \"redirectUrl is required\");\n // Assign defaults\n return {\n useHistory: options.useHistory ?? true,\n loginPage: options.loginPage,\n postLoginPage: options.postLoginPage || window.location.toString(),\n scopes: options.scopes ?? [\"api:ontologies-read\", \"api:ontologies-write\"],\n fetchFn: options.fetchFn ?? globalThis.fetch,\n ctxPath: options.ctxPath ?? \"multipass\",\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,OAAO,SAASC,+BAA+BA,CAACC,GAAG,EAAEC,YAAY,EAAEC,UAAU,EAAEC,SAAS,EAAEC,aAAa,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE;EAC/H,IAAIC,OAAO,GAAG,CAAC,CAAC;EAChB,IAAI,OAAON,UAAU,KAAK,QAAQ,EAAE;IAChC,EAAU,CAACC,SAAS,IAAI,CAACC,aAAa,IAAI,CAACC,MAAM,IAAI,CAACC,OAAO,IAAI,CAACC,OAAO,IAAAE,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAzEb,SAAS,QAAkE,kEAAkE,IAA7IA,SAAS;IACTU,OAAO,GAAGN,UAAU;EACxB,CAAC,MACI;IACDM,OAAO,GAAG;MACNN,UAAU;MACVC,SAAS;MACTC,aAAa;MACbC,MAAM;MACNC,OAAO;MACPC;IACJ,CAAC;EACL;EACA,CAAUP,GAAG,GAAAS,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAbb,SAAS,QAAM,iBAAiB,IAAhCA,SAAS;EACT,CAAUG,YAAY,GAAAQ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAtBb,SAAS,QAAe,yBAAyB,IAAjDA,SAAS;EACT;EACA,OAAO;IACHI,UAAU,EAAEM,OAAO,CAACN,UAAU,IAAI,IAAI;IACtCC,SAAS,EAAEK,OAAO,CAACL,SAAS;IAC5BC,aAAa,EAAEI,OAAO,CAACJ,aAAa,IAAIQ,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAC;IAClET,MAAM,EAAEG,OAAO,CAACH,MAAM,IAAI,CAAC,qBAAqB,EAAE,sBAAsB,CAAC;IACzEC,OAAO,EAAEE,OAAO,CAACF,OAAO,IAAIS,UAAU,CAACC,KAAK;IAC5CT,OAAO,EAAEC,OAAO,CAACD,OAAO,IAAI;EAChC,CAAC;AACL","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdk/oauth",
3
- "version": "1.1.0-beta.3",
3
+ "version": "1.1.0-beta.5",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,8 +28,8 @@
28
28
  "jest-extended": "^4.0.2",
29
29
  "typescript": "~5.5.4",
30
30
  "@osdk/monorepo.api-extractor": "~0.0.0",
31
- "@osdk/monorepo.tsconfig": "~0.0.0",
32
- "@osdk/monorepo.tsup": "~0.0.0"
31
+ "@osdk/monorepo.tsup": "~0.0.0",
32
+ "@osdk/monorepo.tsconfig": "~0.0.0"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"