@fluidframework/azure-service-utils 2.0.0-internal.7.2.2 → 2.0.0-internal.7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.attw.json +3 -0
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +1 -2
  4. package/api-extractor-lint.json +13 -0
  5. package/api-extractor.json +1 -1
  6. package/api-report/azure-service-utils.api.md +1 -1
  7. package/dist/azure-service-utils-alpha.d.ts +21 -0
  8. package/dist/azure-service-utils-beta.d.ts +21 -0
  9. package/dist/azure-service-utils-public.d.ts +21 -0
  10. package/dist/azure-service-utils-untrimmed.d.ts +63 -0
  11. package/dist/{generateToken.js → generateToken.cjs} +2 -3
  12. package/dist/{generateToken.js.map → generateToken.cjs.map} +1 -1
  13. package/dist/generateToken.d.ts +1 -2
  14. package/dist/generateToken.d.ts.map +1 -1
  15. package/dist/{index.js → index.cjs} +2 -2
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/tsdoc-metadata.json +1 -1
  18. package/lib/azure-service-utils-alpha.d.ts +21 -0
  19. package/lib/azure-service-utils-beta.d.ts +21 -0
  20. package/lib/azure-service-utils-public.d.ts +21 -0
  21. package/lib/azure-service-utils-untrimmed.d.ts +63 -0
  22. package/lib/generateToken.d.ts +1 -2
  23. package/lib/generateToken.d.ts.map +1 -1
  24. package/lib/{generateToken.js → generateToken.mjs} +2 -7
  25. package/lib/generateToken.mjs.map +1 -0
  26. package/lib/index.d.ts +1 -12
  27. package/lib/index.d.ts.map +1 -1
  28. package/lib/{index.js → index.mjs} +2 -2
  29. package/lib/index.mjs.map +1 -0
  30. package/package.json +38 -18
  31. package/src/generateToken.ts +1 -2
  32. package/tsc-multi.test.json +4 -0
  33. package/tsconfig.json +5 -4
  34. package/dist/index.js.map +0 -1
  35. package/lib/generateToken.js.map +0 -1
  36. package/lib/index.js.map +0 -1
  37. package/tsconfig.esnext.json +0 -7
package/.attw.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "ignoreRules": ["false-cjs"]
3
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @fluidframework/azure-service-utils
2
2
 
3
+ ## 2.0.0-internal.7.4.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.0.0-internal.7.3.0
8
+
9
+ Dependency updates only.
10
+
3
11
  ## 2.0.0-internal.7.2.0
4
12
 
5
13
  Dependency updates only.
package/README.md CHANGED
@@ -82,8 +82,7 @@ Thank you!
82
82
 
83
83
  This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
84
84
 
85
- Use of these trademarks or logos must follow Microsoft's [Trademark & Brand
86
- Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
85
+ Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
87
86
 
88
87
  Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
89
88
 
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-lint.json",
4
+ "messages": {
5
+ "extractorMessageReporting": {
6
+ // TODO: remove once base config has this enabled as an error
7
+ "ae-incompatible-release-tags": {
8
+ "logLevel": "error",
9
+ "addToApiReportFile": false
10
+ }
11
+ }
12
+ }
13
+ }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-base.json"
3
+ "extends": "../../../common/build/build-common/api-extractor-base.json"
4
4
  }
@@ -7,7 +7,7 @@
7
7
  import { IUser } from '@fluidframework/protocol-definitions';
8
8
  import { ScopeType } from '@fluidframework/protocol-definitions';
9
9
 
10
- // @public
10
+ // @internal
11
11
  export function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
12
12
 
13
13
  export { IUser }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /* Excluded from this release type: generateToken */
17
+ export { IUser }
18
+
19
+ export { ScopeType }
20
+
21
+ export { }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /* Excluded from this release type: generateToken */
17
+ export { IUser }
18
+
19
+ export { ScopeType }
20
+
21
+ export { }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /* Excluded from this release type: generateToken */
17
+ export { IUser }
18
+
19
+ export { ScopeType }
20
+
21
+ export { }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /**
17
+ * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
18
+ * need for different implementations, so they should be kept in sync if changes are needed.
19
+ *
20
+ * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries
21
+ * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which
22
+ * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function
23
+ * exported, so it needs to be sourced from either the package itself or a non-dev dependency.
24
+ *
25
+ * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that
26
+ * no longer works because the azure packages are in a separate release group.
27
+ *
28
+ * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token
29
+ * generation, you should use the function available in the server-services-client package in order to avoid
30
+ * interdependencies between service and client packages.
31
+ */
32
+ /**
33
+ * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
34
+ * to authorize access to a Routerlicious-based Fluid service.
35
+ *
36
+ * @remarks Note: this function uses a browser friendly auth library
37
+ * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
38
+ * It is **not** Node.js-compatible.
39
+ *
40
+ * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
41
+ * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
42
+ * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
43
+ * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
44
+ * If not specified, the token will not be associated with a document, and an empty string will be used.
45
+ * @param user - User with whom generated tokens will be associated.
46
+ * If not specified, the token will not be associated with a user, and a randomly generated mock user will be
47
+ * used instead.
48
+ * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
49
+ * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
50
+ * Expiration = now + lifetime.
51
+ * Expressed in seconds.
52
+ * Default: 3600 (1 hour).
53
+ * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
54
+ * Default: `1.0`.
55
+ * @internal
56
+ */
57
+ export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
58
+
59
+ export { IUser }
60
+
61
+ export { ScopeType }
62
+
63
+ export { }
@@ -46,8 +46,7 @@ const uuid_1 = require("uuid");
46
46
  * Default: 3600 (1 hour).
47
47
  * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
48
48
  * Default: `1.0`.
49
- *
50
- * @public
49
+ * @internal
51
50
  */
52
51
  function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60,
53
52
  // Naming intended to match `ITokenClaims.ver`
@@ -91,4 +90,4 @@ function generateUser() {
91
90
  return randomUser;
92
91
  }
93
92
  exports.generateUser = generateUser;
94
- //# sourceMappingURL=generateToken.js.map
93
+ //# sourceMappingURL=generateToken.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,yCAA8C;AAC9C,+BAAkC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,aAA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(c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n *\n * @public\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\n"]}
1
+ {"version":3,"file":"generateToken.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QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAA,SAAI,GAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC;AATD,oCASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n * @internal\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\n"]}
@@ -38,8 +38,7 @@ import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
38
38
  * Default: 3600 (1 hour).
39
39
  * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
40
40
  * Default: `1.0`.
41
- *
42
- * @public
41
+ * @internal
43
42
  */
44
43
  export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
45
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAE3F;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAG1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
1
+ {"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAE3F;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAG1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
@@ -7,6 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.generateToken = exports.ScopeType = void 0;
8
8
  var protocol_definitions_1 = require("@fluidframework/protocol-definitions");
9
9
  Object.defineProperty(exports, "ScopeType", { enumerable: true, get: function () { return protocol_definitions_1.ScopeType; } });
10
- var generateToken_1 = require("./generateToken");
10
+ var generateToken_1 = require("./generateToken.cjs");
11
11
  Object.defineProperty(exports, "generateToken", { enumerable: true, get: function () { return generateToken_1.generateToken; } });
12
- //# sourceMappingURL=index.js.map
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAeH,6EAAiE;AAAxD,iHAAA,SAAS,OAAA;AAClB,qDAAgD;AAAvC,8GAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.38.0"
8
+ "packageVersion": "7.38.3"
9
9
  }
10
10
  ]
11
11
  }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /* Excluded from this release type: generateToken */
17
+ export { IUser }
18
+
19
+ export { ScopeType }
20
+
21
+ export { }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /* Excluded from this release type: generateToken */
17
+ export { IUser }
18
+
19
+ export { ScopeType }
20
+
21
+ export { }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /* Excluded from this release type: generateToken */
17
+ export { IUser }
18
+
19
+ export { ScopeType }
20
+
21
+ export { }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A set of helper utilities for building backend APIs for use with
3
+ * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
4
+ *
5
+ * @remarks
6
+ * Note that this library's primary entry-point ({@link generateToken}) is only intended
7
+ * to be run in a browser context.
8
+ * It is **not** Node.js-compatible.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ import { IUser } from '@fluidframework/protocol-definitions';
14
+ import { ScopeType } from '@fluidframework/protocol-definitions';
15
+
16
+ /**
17
+ * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no
18
+ * need for different implementations, so they should be kept in sync if changes are needed.
19
+ *
20
+ * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries
21
+ * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which
22
+ * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function
23
+ * exported, so it needs to be sourced from either the package itself or a non-dev dependency.
24
+ *
25
+ * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that
26
+ * no longer works because the azure packages are in a separate release group.
27
+ *
28
+ * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token
29
+ * generation, you should use the function available in the server-services-client package in order to avoid
30
+ * interdependencies between service and client packages.
31
+ */
32
+ /**
33
+ * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)
34
+ * to authorize access to a Routerlicious-based Fluid service.
35
+ *
36
+ * @remarks Note: this function uses a browser friendly auth library
37
+ * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.
38
+ * It is **not** Node.js-compatible.
39
+ *
40
+ * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}
41
+ * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.
42
+ * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}
43
+ * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.
44
+ * If not specified, the token will not be associated with a document, and an empty string will be used.
45
+ * @param user - User with whom generated tokens will be associated.
46
+ * If not specified, the token will not be associated with a user, and a randomly generated mock user will be
47
+ * used instead.
48
+ * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}
49
+ * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.
50
+ * Expiration = now + lifetime.
51
+ * Expressed in seconds.
52
+ * Default: 3600 (1 hour).
53
+ * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
54
+ * Default: `1.0`.
55
+ * @internal
56
+ */
57
+ export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
58
+
59
+ export { IUser }
60
+
61
+ export { ScopeType }
62
+
63
+ export { }
@@ -38,8 +38,7 @@ import type { IUser, ScopeType } from "@fluidframework/protocol-definitions";
38
38
  * Default: 3600 (1 hour).
39
39
  * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
40
40
  * Default: `1.0`.
41
- *
42
- * @public
41
+ * @internal
43
42
  */
44
43
  export declare function generateToken(tenantId: string, key: string, scopes: ScopeType[], documentId?: string, user?: IUser, lifetime?: number, ver?: string): string;
45
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAE3F;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAG1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
1
+ {"version":3,"file":"generateToken.d.ts","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"OAOO,KAAK,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC;AAE1F;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EAAE,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,KAAK,EACZ,QAAQ,GAAE,MAAgB,EAG1B,GAAG,GAAE,MAAc,GACjB,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,KAAK,CASpC"}
@@ -1,7 +1,3 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
1
  import { KJUR as jsrsasign } from "jsrsasign";
6
2
  import { v4 as uuid } from "uuid";
7
3
  /**
@@ -43,8 +39,7 @@ import { v4 as uuid } from "uuid";
43
39
  * Default: 3600 (1 hour).
44
40
  * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
45
41
  * Default: `1.0`.
46
- *
47
- * @public
42
+ * @internal
48
43
  */
49
44
  export function generateToken(tenantId, key, scopes, documentId, user, lifetime = 60 * 60,
50
45
  // Naming intended to match `ITokenClaims.ver`
@@ -86,4 +81,4 @@ export function generateUser() {
86
81
  };
87
82
  return randomUser;
88
83
  }
89
- //# sourceMappingURL=generateToken.js.map
84
+ //# sourceMappingURL=generateToken.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateToken.mjs","sourceRoot":"","sources":["../src/generate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AAU,GAAG;QAClB,sGAAsG;QACtG,EAAE,EAAE,IAAI,EAAE;QACV,sGAAsG;QACtG,IAAI,EAAE,IAAI,EAAE;KACZ,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n * @internal\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -2,18 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- /**
6
- * A set of helper utilities for building backend APIs for use with
7
- * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.
8
- *
9
- * @remarks
10
- * Note that this library's primary entry-point ({@link generateToken}) is only intended
11
- * to be run in a browser context.
12
- * It is **not** Node.js-compatible.
13
- *
14
- * @packageDocumentation
15
- */
16
5
  export type { IUser } from "@fluidframework/protocol-definitions";
17
6
  export { ScopeType } from "@fluidframework/protocol-definitions";
18
- export { generateToken } from "./generateToken";
7
+ export { generateToken } from "./generateToken.mjs";
19
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;YAcS,EAAE,KAAK,EAAE,MAAM,sCAAsC;OAC1D,EAAE,SAAS,EAAE,MAAM,sCAAsC;OACzD,EAAE,aAAa,EAAE"}
@@ -3,5 +3,5 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export { ScopeType } from "@fluidframework/protocol-definitions";
6
- export { generateToken } from "./generateToken";
7
- //# sourceMappingURL=index.js.map
6
+ export { generateToken } from "./generateToken.mjs";
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAeI,EAAE,SAAS,EAAE,MAAM,sCAAsC;OACzD,EAAE,aAAa,EAAE","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/azure-service-utils",
3
- "version": "2.0.0-internal.7.2.2",
3
+ "version": "2.0.0-internal.7.4.0",
4
4
  "description": "Helper service-side utilities for connecting to Azure Fluid Relay service",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -15,16 +15,16 @@
15
15
  ".": {
16
16
  "import": {
17
17
  "types": "./lib/index.d.ts",
18
- "default": "./lib/index.js"
18
+ "default": "./lib/index.mjs"
19
19
  },
20
20
  "require": {
21
21
  "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
22
+ "default": "./dist/index.cjs"
23
23
  }
24
24
  }
25
25
  },
26
- "main": "dist/index.js",
27
- "module": "lib/index.js",
26
+ "main": "dist/index.cjs",
27
+ "module": "lib/index.mjs",
28
28
  "types": "dist/index.d.ts",
29
29
  "dependencies": {
30
30
  "@fluidframework/protocol-definitions": "^3.0.0",
@@ -32,40 +32,60 @@
32
32
  "uuid": "^9.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@fluid-tools/build-cli": "^0.26.1",
36
- "@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils@2.0.0-internal.7.2.1",
35
+ "@arethetypeswrong/cli": "^0.13.3",
36
+ "@fluid-tools/build-cli": "^0.28.0",
37
+ "@fluidframework/azure-service-utils-previous": "npm:@fluidframework/azure-service-utils@2.0.0-internal.7.2.0",
37
38
  "@fluidframework/build-common": "^2.0.3",
38
- "@fluidframework/build-tools": "^0.26.1",
39
- "@fluidframework/eslint-config-fluid": "^3.0.0",
40
- "@microsoft/api-extractor": "^7.37.0",
39
+ "@fluidframework/build-tools": "^0.28.0",
40
+ "@fluidframework/eslint-config-fluid": "^3.1.0",
41
+ "@microsoft/api-extractor": "^7.38.3",
41
42
  "@types/jsrsasign": "^8.0.8",
43
+ "copyfiles": "^2.4.1",
42
44
  "eslint": "~8.50.0",
43
45
  "eslint-config-prettier": "~9.0.0",
44
46
  "prettier": "~3.0.3",
45
47
  "rimraf": "^4.4.0",
48
+ "tsc-multi": "^1.1.0",
46
49
  "typescript": "~5.1.6"
47
50
  },
51
+ "fluidBuild": {
52
+ "tasks": {
53
+ "build:docs": {
54
+ "dependsOn": [
55
+ "...",
56
+ "api-extractor:commonjs",
57
+ "api-extractor:esnext"
58
+ ],
59
+ "script": false
60
+ }
61
+ }
62
+ },
48
63
  "typeValidation": {
49
64
  "broken": {}
50
65
  },
51
66
  "scripts": {
67
+ "api": "fluid-build . --task api",
68
+ "api-extractor:commonjs": "api-extractor run --local",
69
+ "api-extractor:esnext": "copyfiles -u 1 \"dist/**/*-@(alpha|beta|public|untrimmed).d.ts\" lib",
52
70
  "build": "fluid-build . --task build",
53
71
  "build:commonjs": "fluid-build . --task commonjs",
54
72
  "build:compile": "fluid-build . --task compile",
55
- "build:docs": "api-extractor run --local",
56
- "build:esnext": "tsc --project ./tsconfig.esnext.json",
57
- "build:test": "tsc --project ./src/test/tsconfig.json",
73
+ "build:docs": "fluid-build . --task api",
74
+ "build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json",
75
+ "build:test": "tsc-multi --config ./tsc-multi.test.json",
76
+ "check:are-the-types-wrong": "attw --pack",
77
+ "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
58
78
  "ci:build:docs": "api-extractor run",
59
- "clean": "rimraf --glob dist lib \"*.tsbuildinfo\" \"*.build.log\" _api-extractor-temp",
79
+ "clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp",
60
80
  "eslint": "eslint --format stylish src",
61
81
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
62
82
  "format": "npm run prettier:fix",
63
- "lint": "npm run prettier && npm run eslint",
83
+ "lint": "npm run prettier && npm run check:release-tags && npm run eslint",
64
84
  "lint:fix": "npm run prettier:fix && npm run eslint:fix",
65
- "prettier": "prettier --check . --ignore-path ../../../.prettierignore",
66
- "prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
85
+ "prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
86
+ "prettier:fix": "prettier --write . --cache --ignore-path ../../../.prettierignore",
67
87
  "test": "echo \"Error: no test specified\" && exit 1",
68
- "tsc": "tsc",
88
+ "tsc": "tsc-multi --config ../../../common/build/build-common/tsc-multi.cjs.json",
69
89
  "typetests:gen": "fluid-type-test-generator",
70
90
  "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
71
91
  }
@@ -47,8 +47,7 @@ import type { ITokenClaims, IUser, ScopeType } from "@fluidframework/protocol-de
47
47
  * Default: 3600 (1 hour).
48
48
  * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.
49
49
  * Default: `1.0`.
50
- *
51
- * @public
50
+ * @internal
52
51
  */
53
52
  export function generateToken(
54
53
  tenantId: string,
@@ -0,0 +1,4 @@
1
+ {
2
+ "targets": [{ "extname": ".cjs", "module": "CommonJS", "moduleResolution": "Node10" }],
3
+ "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
2
+ "extends": [
3
+ "../../../common/build/build-common/tsconfig.base.json",
4
+ "../../../common/build/build-common/tsconfig.cjs.json",
5
+ ],
6
+ "include": ["src/**/*"],
3
7
  "exclude": ["src/test/**/*"],
4
8
  "compilerOptions": {
5
- "strictNullChecks": true,
6
9
  "rootDir": "./src",
7
10
  "outDir": "./dist",
8
- "composite": true,
9
11
  },
10
- "include": ["src/**/*"],
11
12
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAeH,6EAAiE;AAAxD,iHAAA,SAAS,OAAA;AAClB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateToken.js","sourceRoot":"","sources":["../src/generateToken.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAIlC;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,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License.\n */\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\n\nimport type { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\n\n/**\n * IMPORTANT: This function is duplicated in ./packages/runtime/test-runtime-utils/src/generateToken.ts. There is no\n * need for different implementations, so they should be kept in sync if changes are needed.\n *\n * The reason they are duplicated is because we don't want the core Fluid libraries depending on the Azure libraries\n * (enforced by layer-check), but both need to expose this function. The test-runtime-utils library is a test lib, which\n * layer-check (correctly) reuires only be used as a dev dependency. But in the azure case, we want the function\n * exported, so it needs to be sourced from either the package itself or a non-dev dependency.\n *\n * The previous solution to this was to import the function from azure-service-utils into test-runtime-utils, but that\n * no longer works because the azure packages are in a separate release group.\n *\n * If a token needs to be generated on the client side, you should re-use this function. If you need service-side token\n * generation, you should use the function available in the server-services-client package in order to avoid\n * interdependencies between service and client packages.\n */\n\n/**\n * Generates a {@link https://en.wikipedia.org/wiki/JSON_Web_Token | JSON Web Token} (JWT)\n * to authorize access to a Routerlicious-based Fluid service.\n *\n * @remarks Note: this function uses a browser friendly auth library\n * ({@link https://www.npmjs.com/package/jsrsasign | jsrsasign}) and may only be used in client (browser) context.\n * It is **not** Node.js-compatible.\n *\n * @param tenantId - See {@link @fluidframework/protocol-definitions#ITokenClaims.tenantId}\n * @param key - API key to authenticate user. Must be {@link https://en.wikipedia.org/wiki/UTF-8 | UTF-8}-encoded.\n * @param scopes - See {@link @fluidframework/protocol-definitions#ITokenClaims.scopes}\n * @param documentId - See {@link @fluidframework/protocol-definitions#ITokenClaims.documentId}.\n * If not specified, the token will not be associated with a document, and an empty string will be used.\n * @param user - User with whom generated tokens will be associated.\n * If not specified, the token will not be associated with a user, and a randomly generated mock user will be\n * used instead.\n * See {@link @fluidframework/protocol-definitions#ITokenClaims.user}\n * @param lifetime - Used to generate the {@link @fluidframework/protocol-definitions#ITokenClaims.exp | expiration}.\n * Expiration = now + lifetime.\n * Expressed in seconds.\n * Default: 3600 (1 hour).\n * @param ver - See {@link @fluidframework/protocol-definitions#ITokenClaims.ver}.\n * Default: `1.0`.\n *\n * @public\n */\nexport function generateToken(\n\ttenantId: string,\n\tkey: string,\n\tscopes: ScopeType[],\n\tdocumentId?: string,\n\tuser?: IUser,\n\tlifetime: number = 60 * 60,\n\t// Naming intended to match `ITokenClaims.ver`\n\t// eslint-disable-next-line unicorn/prevent-abbreviations\n\tver: string = \"1.0\",\n): string {\n\tlet userClaim = user ?? generateUser();\n\tif (userClaim.id === \"\" || userClaim.id === undefined) {\n\t\tuserClaim = generateUser();\n\t}\n\n\t// Current time in seconds\n\tconst now = Math.round(Date.now() / 1000);\n\n\tconst claims: ITokenClaims & { jti: string } = {\n\t\tdocumentId: documentId ?? \"\",\n\t\tscopes,\n\t\ttenantId,\n\t\tuser: userClaim,\n\t\tiat: now,\n\t\texp: now + lifetime,\n\t\tver,\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tjti: uuid(),\n\t};\n\n\tconst utf8Key = { utf8: key };\n\n\treturn jsrsasign.jws.JWS.sign(\n\t\t// External API uses null\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tnull,\n\t\tJSON.stringify({ alg: \"HS256\", typ: \"JWT\" }),\n\t\tclaims,\n\t\tutf8Key,\n\t);\n}\n\n/**\n * Generates an arbitrary (\"random\") {@link @fluidframework/protocol-definitions#IUser} by generating a\n * random UUID for its {@link @fluidframework/protocol-definitions#IUser.id} and `name` properties.\n */\nexport function generateUser(): IUser {\n\tconst randomUser = {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tid: uuid(),\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call\n\t\tname: uuid(),\n\t};\n\n\treturn randomUser;\n}\n"]}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A set of helper utilities for building backend APIs for use with\n * {@link https://docs.microsoft.com/en-us/azure/azure-fluid-relay/overview/overview | Azure Fluid Relay}.\n *\n * @remarks\n * Note that this library's primary entry-point ({@link generateToken}) is only intended\n * to be run in a browser context.\n * It is **not** Node.js-compatible.\n *\n * @packageDocumentation\n */\n\nexport type { IUser } from \"@fluidframework/protocol-definitions\";\nexport { ScopeType } from \"@fluidframework/protocol-definitions\";\nexport { generateToken } from \"./generateToken\";\n"]}
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext",
6
- },
7
- }